x86: replace Reg8, Reg16, Reg32, and Reg64
[deliverable/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. */
0198d5e6
TC
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 arm_feature_set * dyn_mcpu_ext_opt = NULL;
151static const arm_feature_set * mcpu_fpu_opt = NULL;
152static const arm_feature_set * march_cpu_opt = NULL;
153static arm_feature_set * dyn_march_ext_opt = NULL;
154static const arm_feature_set * march_fpu_opt = NULL;
155static const arm_feature_set * mfpu_opt = NULL;
156static const arm_feature_set * object_arch = NULL;
e74cfd16
PB
157
158/* Constants for known architecture features. */
159static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 160static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 161static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
162static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
163static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
164static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
165static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 166#ifdef OBJ_ELF
e74cfd16 167static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 168#endif
e74cfd16
PB
169static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171#ifdef CPU_DEFAULT
172static const arm_feature_set cpu_default = CPU_DEFAULT;
173#endif
174
823d2571 175static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 176static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
177static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
178static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
179static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
180static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
181static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
182static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 183static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
184 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
185static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
186static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
187static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
188static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
189static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
190static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
191static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
823d2571
TG
192static const arm_feature_set arm_ext_v6_notm =
193 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
194static const arm_feature_set arm_ext_v6_dsp =
195 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
196static const arm_feature_set arm_ext_barrier =
197 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
198static const arm_feature_set arm_ext_msr =
199 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
200static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
201static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
202static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
203static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 204#ifdef OBJ_ELF
e7d39ed3 205static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 206#endif
823d2571 207static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 208static const arm_feature_set arm_ext_m =
173205ca 209 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 210 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
211static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
212static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
213static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
214static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
215static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 216static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 217static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
218static const arm_feature_set arm_ext_v8m_main =
219 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
220/* Instructions in ARMv8-M only found in M profile architectures. */
221static const arm_feature_set arm_ext_v8m_m_only =
222 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
223static const arm_feature_set arm_ext_v6t2_v8m =
224 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
225/* Instructions shared between ARMv8-A and ARMv8-M. */
226static const arm_feature_set arm_ext_atomics =
227 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 228#ifdef OBJ_ELF
15afaa63
TP
229/* DSP instructions Tag_DSP_extension refers to. */
230static const arm_feature_set arm_ext_dsp =
231 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 232#endif
4d1464f2
MW
233static const arm_feature_set arm_ext_ras =
234 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
235/* FP16 instructions. */
236static const arm_feature_set arm_ext_fp16 =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
238static const arm_feature_set arm_ext_fp16_fml =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
240static const arm_feature_set arm_ext_v8_2 =
241 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
242static const arm_feature_set arm_ext_v8_3 =
243 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
244
245static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 246#ifdef OBJ_ELF
2c6b98ea 247static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 248#endif
f85d59c3 249static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
250static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
251static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
252
2d447fca 253static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 254 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 255static const arm_feature_set arm_cext_iwmmxt =
823d2571 256 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 257static const arm_feature_set arm_cext_xscale =
823d2571 258 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 259static const arm_feature_set arm_cext_maverick =
823d2571
TG
260 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
261static const arm_feature_set fpu_fpa_ext_v1 =
262 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
263static const arm_feature_set fpu_fpa_ext_v2 =
264 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 265static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
266 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
267static const arm_feature_set fpu_vfp_ext_v1 =
268 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
269static const arm_feature_set fpu_vfp_ext_v2 =
270 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
271static const arm_feature_set fpu_vfp_ext_v3xd =
272 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
273static const arm_feature_set fpu_vfp_ext_v3 =
274 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 275static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
276 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
277static const arm_feature_set fpu_neon_ext_v1 =
278 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 279static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 280 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 281#ifdef OBJ_ELF
823d2571
TG
282static const arm_feature_set fpu_vfp_fp16 =
283 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
284static const arm_feature_set fpu_neon_ext_fma =
285 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 286#endif
823d2571
TG
287static const arm_feature_set fpu_vfp_ext_fma =
288 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 289static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 290 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 291static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 292 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 293static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 294 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 295static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 296 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 297static const arm_feature_set crc_ext_armv8 =
823d2571 298 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 299static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 300 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
301static const arm_feature_set fpu_neon_ext_dotprod =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 303
33a392fb 304static int mfloat_abi_opt = -1;
e74cfd16
PB
305/* Record user cpu selection for object attributes. */
306static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 307/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 308static char selected_cpu_name[20];
8d67f500 309
aacf0b33
KT
310extern FLONUM_TYPE generic_floating_point_number;
311
8d67f500
NC
312/* Return if no cpu was selected on command-line. */
313static bfd_boolean
314no_cpu_selected (void)
315{
823d2571 316 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
317}
318
7cc69913 319#ifdef OBJ_ELF
deeaaff8
DJ
320# ifdef EABI_DEFAULT
321static int meabi_flags = EABI_DEFAULT;
322# else
d507cf36 323static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 324# endif
e1da3f5b 325
ee3c0378
AS
326static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
327
e1da3f5b 328bfd_boolean
5f4273c7 329arm_is_eabi (void)
e1da3f5b
PB
330{
331 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
332}
7cc69913 333#endif
b99bd4ef 334
b99bd4ef 335#ifdef OBJ_ELF
c19d1205 336/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
337symbolS * GOT_symbol;
338#endif
339
b99bd4ef
NC
340/* 0: assemble for ARM,
341 1: assemble for Thumb,
342 2: assemble for Thumb even though target CPU does not support thumb
343 instructions. */
344static int thumb_mode = 0;
8dc2430f
NC
345/* A value distinct from the possible values for thumb_mode that we
346 can use to record whether thumb_mode has been copied into the
347 tc_frag_data field of a frag. */
348#define MODE_RECORDED (1 << 4)
b99bd4ef 349
e07e6e58
NC
350/* Specifies the intrinsic IT insn behavior mode. */
351enum implicit_it_mode
352{
353 IMPLICIT_IT_MODE_NEVER = 0x00,
354 IMPLICIT_IT_MODE_ARM = 0x01,
355 IMPLICIT_IT_MODE_THUMB = 0x02,
356 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
357};
358static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
359
c19d1205
ZW
360/* If unified_syntax is true, we are processing the new unified
361 ARM/Thumb syntax. Important differences from the old ARM mode:
362
363 - Immediate operands do not require a # prefix.
364 - Conditional affixes always appear at the end of the
365 instruction. (For backward compatibility, those instructions
366 that formerly had them in the middle, continue to accept them
367 there.)
368 - The IT instruction may appear, and if it does is validated
369 against subsequent conditional affixes. It does not generate
370 machine code.
371
372 Important differences from the old Thumb mode:
373
374 - Immediate operands do not require a # prefix.
375 - Most of the V6T2 instructions are only available in unified mode.
376 - The .N and .W suffixes are recognized and honored (it is an error
377 if they cannot be honored).
378 - All instructions set the flags if and only if they have an 's' affix.
379 - Conditional affixes may be used. They are validated against
380 preceding IT instructions. Unlike ARM mode, you cannot use a
381 conditional affix except in the scope of an IT instruction. */
382
383static bfd_boolean unified_syntax = FALSE;
b99bd4ef 384
bacebabc
RM
385/* An immediate operand can start with #, and ld*, st*, pld operands
386 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
387 before a [, which can appear as the first operand for pld.
388 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
389const char arm_symbol_chars[] = "#[]{}";
bacebabc 390
5287ad62
JB
391enum neon_el_type
392{
dcbf9037 393 NT_invtype,
5287ad62
JB
394 NT_untyped,
395 NT_integer,
396 NT_float,
397 NT_poly,
398 NT_signed,
dcbf9037 399 NT_unsigned
5287ad62
JB
400};
401
402struct neon_type_el
403{
404 enum neon_el_type type;
405 unsigned size;
406};
407
408#define NEON_MAX_TYPE_ELS 4
409
410struct neon_type
411{
412 struct neon_type_el el[NEON_MAX_TYPE_ELS];
413 unsigned elems;
414};
415
e07e6e58
NC
416enum it_instruction_type
417{
418 OUTSIDE_IT_INSN,
419 INSIDE_IT_INSN,
420 INSIDE_IT_LAST_INSN,
421 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 422 if inside, should be the last one. */
e07e6e58 423 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 424 i.e. BKPT and NOP. */
e07e6e58
NC
425 IT_INSN /* The IT insn has been parsed. */
426};
427
ad6cec43
MGD
428/* The maximum number of operands we need. */
429#define ARM_IT_MAX_OPERANDS 6
430
b99bd4ef
NC
431struct arm_it
432{
c19d1205 433 const char * error;
b99bd4ef 434 unsigned long instruction;
c19d1205
ZW
435 int size;
436 int size_req;
437 int cond;
037e8744
JB
438 /* "uncond_value" is set to the value in place of the conditional field in
439 unconditional versions of the instruction, or -1 if nothing is
440 appropriate. */
441 int uncond_value;
5287ad62 442 struct neon_type vectype;
88714cb8
DG
443 /* This does not indicate an actual NEON instruction, only that
444 the mnemonic accepts neon-style type suffixes. */
445 int is_neon;
0110f2b8
PB
446 /* Set to the opcode if the instruction needs relaxation.
447 Zero if the instruction is not relaxed. */
448 unsigned long relax;
b99bd4ef
NC
449 struct
450 {
451 bfd_reloc_code_real_type type;
c19d1205
ZW
452 expressionS exp;
453 int pc_rel;
b99bd4ef 454 } reloc;
b99bd4ef 455
e07e6e58
NC
456 enum it_instruction_type it_insn_type;
457
c19d1205
ZW
458 struct
459 {
460 unsigned reg;
ca3f61f7 461 signed int imm;
dcbf9037 462 struct neon_type_el vectype;
ca3f61f7
NC
463 unsigned present : 1; /* Operand present. */
464 unsigned isreg : 1; /* Operand was a register. */
465 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
466 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
467 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 468 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
469 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
470 instructions. This allows us to disambiguate ARM <-> vector insns. */
471 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 472 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 473 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 474 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
475 unsigned hasreloc : 1; /* Operand has relocation suffix. */
476 unsigned writeback : 1; /* Operand has trailing ! */
477 unsigned preind : 1; /* Preindexed address. */
478 unsigned postind : 1; /* Postindexed address. */
479 unsigned negative : 1; /* Index register was negated. */
480 unsigned shifted : 1; /* Shift applied to operation. */
481 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 482 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
483};
484
c19d1205 485static struct arm_it inst;
b99bd4ef
NC
486
487#define NUM_FLOAT_VALS 8
488
05d2d07e 489const char * fp_const[] =
b99bd4ef
NC
490{
491 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
492};
493
c19d1205 494/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
495#define MAX_LITTLENUMS 6
496
497LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
498
499#define FAIL (-1)
500#define SUCCESS (0)
501
502#define SUFF_S 1
503#define SUFF_D 2
504#define SUFF_E 3
505#define SUFF_P 4
506
c19d1205
ZW
507#define CP_T_X 0x00008000
508#define CP_T_Y 0x00400000
b99bd4ef 509
c19d1205
ZW
510#define CONDS_BIT 0x00100000
511#define LOAD_BIT 0x00100000
b99bd4ef
NC
512
513#define DOUBLE_LOAD_FLAG 0x00000001
514
515struct asm_cond
516{
d3ce72d0 517 const char * template_name;
c921be7d 518 unsigned long value;
b99bd4ef
NC
519};
520
c19d1205 521#define COND_ALWAYS 0xE
b99bd4ef 522
b99bd4ef
NC
523struct asm_psr
524{
d3ce72d0 525 const char * template_name;
c921be7d 526 unsigned long field;
b99bd4ef
NC
527};
528
62b3e311
PB
529struct asm_barrier_opt
530{
e797f7e0
MGD
531 const char * template_name;
532 unsigned long value;
533 const arm_feature_set arch;
62b3e311
PB
534};
535
2d2255b5 536/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
537#define SPSR_BIT (1 << 22)
538
c19d1205
ZW
539/* The individual PSR flag bits. */
540#define PSR_c (1 << 16)
541#define PSR_x (1 << 17)
542#define PSR_s (1 << 18)
543#define PSR_f (1 << 19)
b99bd4ef 544
c19d1205 545struct reloc_entry
bfae80f2 546{
0198d5e6 547 const char * name;
c921be7d 548 bfd_reloc_code_real_type reloc;
bfae80f2
RE
549};
550
5287ad62 551enum vfp_reg_pos
bfae80f2 552{
5287ad62
JB
553 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
554 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
555};
556
557enum vfp_ldstm_type
558{
559 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
560};
561
dcbf9037
JB
562/* Bits for DEFINED field in neon_typed_alias. */
563#define NTA_HASTYPE 1
564#define NTA_HASINDEX 2
565
566struct neon_typed_alias
567{
c921be7d
NC
568 unsigned char defined;
569 unsigned char index;
570 struct neon_type_el eltype;
dcbf9037
JB
571};
572
c19d1205 573/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
574 architecture extensions' registers. Each entry should have an error message
575 in reg_expected_msgs below. */
c19d1205 576enum arm_reg_type
bfae80f2 577{
c19d1205
ZW
578 REG_TYPE_RN,
579 REG_TYPE_CP,
580 REG_TYPE_CN,
581 REG_TYPE_FN,
582 REG_TYPE_VFS,
583 REG_TYPE_VFD,
5287ad62 584 REG_TYPE_NQ,
037e8744 585 REG_TYPE_VFSD,
5287ad62 586 REG_TYPE_NDQ,
dec41383 587 REG_TYPE_NSD,
037e8744 588 REG_TYPE_NSDQ,
c19d1205
ZW
589 REG_TYPE_VFC,
590 REG_TYPE_MVF,
591 REG_TYPE_MVD,
592 REG_TYPE_MVFX,
593 REG_TYPE_MVDX,
594 REG_TYPE_MVAX,
595 REG_TYPE_DSPSC,
596 REG_TYPE_MMXWR,
597 REG_TYPE_MMXWC,
598 REG_TYPE_MMXWCG,
599 REG_TYPE_XSCALE,
90ec0d68 600 REG_TYPE_RNB
bfae80f2
RE
601};
602
dcbf9037
JB
603/* Structure for a hash table entry for a register.
604 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
605 information which states whether a vector type or index is specified (for a
606 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
607struct reg_entry
608{
c921be7d 609 const char * name;
90ec0d68 610 unsigned int number;
c921be7d
NC
611 unsigned char type;
612 unsigned char builtin;
613 struct neon_typed_alias * neon;
6c43fab6
RE
614};
615
c19d1205 616/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 617const char * const reg_expected_msgs[] =
c19d1205 618{
5aa75429
TP
619 [REG_TYPE_RN] = N_("ARM register expected"),
620 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
621 [REG_TYPE_CN] = N_("co-processor register expected"),
622 [REG_TYPE_FN] = N_("FPA register expected"),
623 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
624 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
625 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
626 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
627 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
628 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
629 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
630 " expected"),
631 [REG_TYPE_VFC] = N_("VFP system register expected"),
632 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
633 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
634 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
635 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
636 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
637 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
638 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
639 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
640 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
641 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
642 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
643};
644
c19d1205 645/* Some well known registers that we refer to directly elsewhere. */
bd340a04 646#define REG_R12 12
c19d1205
ZW
647#define REG_SP 13
648#define REG_LR 14
649#define REG_PC 15
404ff6b5 650
b99bd4ef
NC
651/* ARM instructions take 4bytes in the object file, Thumb instructions
652 take 2: */
c19d1205 653#define INSN_SIZE 4
b99bd4ef
NC
654
655struct asm_opcode
656{
657 /* Basic string to match. */
d3ce72d0 658 const char * template_name;
c19d1205
ZW
659
660 /* Parameters to instruction. */
5be8be5d 661 unsigned int operands[8];
c19d1205
ZW
662
663 /* Conditional tag - see opcode_lookup. */
664 unsigned int tag : 4;
b99bd4ef
NC
665
666 /* Basic instruction code. */
c19d1205 667 unsigned int avalue : 28;
b99bd4ef 668
c19d1205
ZW
669 /* Thumb-format instruction code. */
670 unsigned int tvalue;
b99bd4ef 671
90e4755a 672 /* Which architecture variant provides this instruction. */
c921be7d
NC
673 const arm_feature_set * avariant;
674 const arm_feature_set * tvariant;
c19d1205
ZW
675
676 /* Function to call to encode instruction in ARM format. */
677 void (* aencode) (void);
b99bd4ef 678
c19d1205
ZW
679 /* Function to call to encode instruction in Thumb format. */
680 void (* tencode) (void);
b99bd4ef
NC
681};
682
a737bd4d
NC
683/* Defines for various bits that we will want to toggle. */
684#define INST_IMMEDIATE 0x02000000
685#define OFFSET_REG 0x02000000
c19d1205 686#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
687#define SHIFT_BY_REG 0x00000010
688#define PRE_INDEX 0x01000000
689#define INDEX_UP 0x00800000
690#define WRITE_BACK 0x00200000
691#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 692#define CPSI_MMOD 0x00020000
90e4755a 693
a737bd4d
NC
694#define LITERAL_MASK 0xf000f000
695#define OPCODE_MASK 0xfe1fffff
696#define V4_STR_BIT 0x00000020
8335d6aa 697#define VLDR_VMOV_SAME 0x0040f000
90e4755a 698
efd81785
PB
699#define T2_SUBS_PC_LR 0xf3de8f00
700
a737bd4d 701#define DATA_OP_SHIFT 21
bada4342 702#define SBIT_SHIFT 20
90e4755a 703
ef8d22e6
PB
704#define T2_OPCODE_MASK 0xfe1fffff
705#define T2_DATA_OP_SHIFT 21
bada4342 706#define T2_SBIT_SHIFT 20
ef8d22e6 707
6530b175
NC
708#define A_COND_MASK 0xf0000000
709#define A_PUSH_POP_OP_MASK 0x0fff0000
710
711/* Opcodes for pushing/poping registers to/from the stack. */
712#define A1_OPCODE_PUSH 0x092d0000
713#define A2_OPCODE_PUSH 0x052d0004
714#define A2_OPCODE_POP 0x049d0004
715
a737bd4d
NC
716/* Codes to distinguish the arithmetic instructions. */
717#define OPCODE_AND 0
718#define OPCODE_EOR 1
719#define OPCODE_SUB 2
720#define OPCODE_RSB 3
721#define OPCODE_ADD 4
722#define OPCODE_ADC 5
723#define OPCODE_SBC 6
724#define OPCODE_RSC 7
725#define OPCODE_TST 8
726#define OPCODE_TEQ 9
727#define OPCODE_CMP 10
728#define OPCODE_CMN 11
729#define OPCODE_ORR 12
730#define OPCODE_MOV 13
731#define OPCODE_BIC 14
732#define OPCODE_MVN 15
90e4755a 733
ef8d22e6
PB
734#define T2_OPCODE_AND 0
735#define T2_OPCODE_BIC 1
736#define T2_OPCODE_ORR 2
737#define T2_OPCODE_ORN 3
738#define T2_OPCODE_EOR 4
739#define T2_OPCODE_ADD 8
740#define T2_OPCODE_ADC 10
741#define T2_OPCODE_SBC 11
742#define T2_OPCODE_SUB 13
743#define T2_OPCODE_RSB 14
744
a737bd4d
NC
745#define T_OPCODE_MUL 0x4340
746#define T_OPCODE_TST 0x4200
747#define T_OPCODE_CMN 0x42c0
748#define T_OPCODE_NEG 0x4240
749#define T_OPCODE_MVN 0x43c0
90e4755a 750
a737bd4d
NC
751#define T_OPCODE_ADD_R3 0x1800
752#define T_OPCODE_SUB_R3 0x1a00
753#define T_OPCODE_ADD_HI 0x4400
754#define T_OPCODE_ADD_ST 0xb000
755#define T_OPCODE_SUB_ST 0xb080
756#define T_OPCODE_ADD_SP 0xa800
757#define T_OPCODE_ADD_PC 0xa000
758#define T_OPCODE_ADD_I8 0x3000
759#define T_OPCODE_SUB_I8 0x3800
760#define T_OPCODE_ADD_I3 0x1c00
761#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 762
a737bd4d
NC
763#define T_OPCODE_ASR_R 0x4100
764#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
765#define T_OPCODE_LSR_R 0x40c0
766#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
767#define T_OPCODE_ASR_I 0x1000
768#define T_OPCODE_LSL_I 0x0000
769#define T_OPCODE_LSR_I 0x0800
b99bd4ef 770
a737bd4d
NC
771#define T_OPCODE_MOV_I8 0x2000
772#define T_OPCODE_CMP_I8 0x2800
773#define T_OPCODE_CMP_LR 0x4280
774#define T_OPCODE_MOV_HR 0x4600
775#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 776
a737bd4d
NC
777#define T_OPCODE_LDR_PC 0x4800
778#define T_OPCODE_LDR_SP 0x9800
779#define T_OPCODE_STR_SP 0x9000
780#define T_OPCODE_LDR_IW 0x6800
781#define T_OPCODE_STR_IW 0x6000
782#define T_OPCODE_LDR_IH 0x8800
783#define T_OPCODE_STR_IH 0x8000
784#define T_OPCODE_LDR_IB 0x7800
785#define T_OPCODE_STR_IB 0x7000
786#define T_OPCODE_LDR_RW 0x5800
787#define T_OPCODE_STR_RW 0x5000
788#define T_OPCODE_LDR_RH 0x5a00
789#define T_OPCODE_STR_RH 0x5200
790#define T_OPCODE_LDR_RB 0x5c00
791#define T_OPCODE_STR_RB 0x5400
c9b604bd 792
a737bd4d
NC
793#define T_OPCODE_PUSH 0xb400
794#define T_OPCODE_POP 0xbc00
b99bd4ef 795
2fc8bdac 796#define T_OPCODE_BRANCH 0xe000
b99bd4ef 797
a737bd4d 798#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 799#define THUMB_PP_PC_LR 0x0100
c19d1205 800#define THUMB_LOAD_BIT 0x0800
53365c0d 801#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
802
803#define BAD_ARGS _("bad arguments to instruction")
fdfde340 804#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
805#define BAD_PC _("r15 not allowed here")
806#define BAD_COND _("instruction cannot be conditional")
807#define BAD_OVERLAP _("registers may not be the same")
808#define BAD_HIREG _("lo register required")
809#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 810#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
811#define BAD_BRANCH _("branch must be last instruction in IT block")
812#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 813#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
814#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
815#define BAD_IT_COND _("incorrect condition in IT block")
816#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 817#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
818#define BAD_PC_ADDRESSING \
819 _("cannot use register index with PC-relative addressing")
820#define BAD_PC_WRITEBACK \
821 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
822#define BAD_RANGE _("branch out of range")
823#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 824#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 825#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 826
c921be7d
NC
827static struct hash_control * arm_ops_hsh;
828static struct hash_control * arm_cond_hsh;
829static struct hash_control * arm_shift_hsh;
830static struct hash_control * arm_psr_hsh;
831static struct hash_control * arm_v7m_psr_hsh;
832static struct hash_control * arm_reg_hsh;
833static struct hash_control * arm_reloc_hsh;
834static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 835
b99bd4ef
NC
836/* Stuff needed to resolve the label ambiguity
837 As:
838 ...
839 label: <insn>
840 may differ from:
841 ...
842 label:
5f4273c7 843 <insn> */
b99bd4ef
NC
844
845symbolS * last_label_seen;
b34976b6 846static int label_is_thumb_function_name = FALSE;
e07e6e58 847
3d0c9500
NC
848/* Literal pool structure. Held on a per-section
849 and per-sub-section basis. */
a737bd4d 850
c19d1205 851#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 852typedef struct literal_pool
b99bd4ef 853{
c921be7d
NC
854 expressionS literals [MAX_LITERAL_POOL_SIZE];
855 unsigned int next_free_entry;
856 unsigned int id;
857 symbolS * symbol;
858 segT section;
859 subsegT sub_section;
a8040cf2
NC
860#ifdef OBJ_ELF
861 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
862#endif
c921be7d 863 struct literal_pool * next;
8335d6aa 864 unsigned int alignment;
3d0c9500 865} literal_pool;
b99bd4ef 866
3d0c9500
NC
867/* Pointer to a linked list of literal pools. */
868literal_pool * list_of_pools = NULL;
e27ec89e 869
2e6976a8
DG
870typedef enum asmfunc_states
871{
872 OUTSIDE_ASMFUNC,
873 WAITING_ASMFUNC_NAME,
874 WAITING_ENDASMFUNC
875} asmfunc_states;
876
877static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
878
e07e6e58
NC
879#ifdef OBJ_ELF
880# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
881#else
882static struct current_it now_it;
883#endif
884
885static inline int
886now_it_compatible (int cond)
887{
888 return (cond & ~1) == (now_it.cc & ~1);
889}
890
891static inline int
892conditional_insn (void)
893{
894 return inst.cond != COND_ALWAYS;
895}
896
897static int in_it_block (void);
898
899static int handle_it_state (void);
900
901static void force_automatic_it_block_close (void);
902
c921be7d
NC
903static void it_fsm_post_encode (void);
904
e07e6e58
NC
905#define set_it_insn_type(type) \
906 do \
907 { \
908 inst.it_insn_type = type; \
909 if (handle_it_state () == FAIL) \
477330fc 910 return; \
e07e6e58
NC
911 } \
912 while (0)
913
c921be7d
NC
914#define set_it_insn_type_nonvoid(type, failret) \
915 do \
916 { \
917 inst.it_insn_type = type; \
918 if (handle_it_state () == FAIL) \
477330fc 919 return failret; \
c921be7d
NC
920 } \
921 while(0)
922
e07e6e58
NC
923#define set_it_insn_type_last() \
924 do \
925 { \
926 if (inst.cond == COND_ALWAYS) \
477330fc 927 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 928 else \
477330fc 929 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
930 } \
931 while (0)
932
c19d1205 933/* Pure syntax. */
b99bd4ef 934
c19d1205
ZW
935/* This array holds the chars that always start a comment. If the
936 pre-processor is disabled, these aren't very useful. */
2e6976a8 937char arm_comment_chars[] = "@";
3d0c9500 938
c19d1205
ZW
939/* This array holds the chars that only start a comment at the beginning of
940 a line. If the line seems to have the form '# 123 filename'
941 .line and .file directives will appear in the pre-processed output. */
942/* Note that input_file.c hand checks for '#' at the beginning of the
943 first line of the input file. This is because the compiler outputs
944 #NO_APP at the beginning of its output. */
945/* Also note that comments like this one will always work. */
946const char line_comment_chars[] = "#";
3d0c9500 947
2e6976a8 948char arm_line_separator_chars[] = ";";
b99bd4ef 949
c19d1205
ZW
950/* Chars that can be used to separate mant
951 from exp in floating point numbers. */
952const char EXP_CHARS[] = "eE";
3d0c9500 953
c19d1205
ZW
954/* Chars that mean this number is a floating point constant. */
955/* As in 0f12.456 */
956/* or 0d1.2345e12 */
b99bd4ef 957
c19d1205 958const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 959
c19d1205
ZW
960/* Prefix characters that indicate the start of an immediate
961 value. */
962#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 963
c19d1205
ZW
964/* Separator character handling. */
965
966#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
967
968static inline int
969skip_past_char (char ** str, char c)
970{
8ab8155f
NC
971 /* PR gas/14987: Allow for whitespace before the expected character. */
972 skip_whitespace (*str);
427d0db6 973
c19d1205
ZW
974 if (**str == c)
975 {
976 (*str)++;
977 return SUCCESS;
3d0c9500 978 }
c19d1205
ZW
979 else
980 return FAIL;
981}
c921be7d 982
c19d1205 983#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 984
c19d1205
ZW
985/* Arithmetic expressions (possibly involving symbols). */
986
987/* Return TRUE if anything in the expression is a bignum. */
988
0198d5e6 989static bfd_boolean
c19d1205
ZW
990walk_no_bignums (symbolS * sp)
991{
992 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 993 return TRUE;
c19d1205
ZW
994
995 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 996 {
c19d1205
ZW
997 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
998 || (symbol_get_value_expression (sp)->X_op_symbol
999 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1000 }
1001
0198d5e6 1002 return FALSE;
3d0c9500
NC
1003}
1004
0198d5e6 1005static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1006
1007/* Third argument to my_get_expression. */
1008#define GE_NO_PREFIX 0
1009#define GE_IMM_PREFIX 1
1010#define GE_OPT_PREFIX 2
5287ad62
JB
1011/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1012 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1013#define GE_OPT_PREFIX_BIG 3
a737bd4d 1014
b99bd4ef 1015static int
c19d1205 1016my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1017{
c19d1205
ZW
1018 char * save_in;
1019 segT seg;
b99bd4ef 1020
c19d1205
ZW
1021 /* In unified syntax, all prefixes are optional. */
1022 if (unified_syntax)
5287ad62 1023 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1024 : GE_OPT_PREFIX;
b99bd4ef 1025
c19d1205 1026 switch (prefix_mode)
b99bd4ef 1027 {
c19d1205
ZW
1028 case GE_NO_PREFIX: break;
1029 case GE_IMM_PREFIX:
1030 if (!is_immediate_prefix (**str))
1031 {
1032 inst.error = _("immediate expression requires a # prefix");
1033 return FAIL;
1034 }
1035 (*str)++;
1036 break;
1037 case GE_OPT_PREFIX:
5287ad62 1038 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1039 if (is_immediate_prefix (**str))
1040 (*str)++;
1041 break;
0198d5e6
TC
1042 default:
1043 abort ();
c19d1205 1044 }
b99bd4ef 1045
c19d1205 1046 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1047
c19d1205
ZW
1048 save_in = input_line_pointer;
1049 input_line_pointer = *str;
0198d5e6 1050 in_my_get_expression = TRUE;
c19d1205 1051 seg = expression (ep);
0198d5e6 1052 in_my_get_expression = FALSE;
c19d1205 1053
f86adc07 1054 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1055 {
f86adc07 1056 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1057 *str = input_line_pointer;
1058 input_line_pointer = save_in;
1059 if (inst.error == NULL)
f86adc07
NS
1060 inst.error = (ep->X_op == O_absent
1061 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1062 return 1;
1063 }
b99bd4ef 1064
c19d1205
ZW
1065#ifdef OBJ_AOUT
1066 if (seg != absolute_section
1067 && seg != text_section
1068 && seg != data_section
1069 && seg != bss_section
1070 && seg != undefined_section)
1071 {
1072 inst.error = _("bad segment");
1073 *str = input_line_pointer;
1074 input_line_pointer = save_in;
1075 return 1;
b99bd4ef 1076 }
87975d2a
AM
1077#else
1078 (void) seg;
c19d1205 1079#endif
b99bd4ef 1080
c19d1205
ZW
1081 /* Get rid of any bignums now, so that we don't generate an error for which
1082 we can't establish a line number later on. Big numbers are never valid
1083 in instructions, which is where this routine is always called. */
5287ad62
JB
1084 if (prefix_mode != GE_OPT_PREFIX_BIG
1085 && (ep->X_op == O_big
477330fc 1086 || (ep->X_add_symbol
5287ad62 1087 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1088 || (ep->X_op_symbol
5287ad62 1089 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1090 {
1091 inst.error = _("invalid constant");
1092 *str = input_line_pointer;
1093 input_line_pointer = save_in;
1094 return 1;
1095 }
b99bd4ef 1096
c19d1205
ZW
1097 *str = input_line_pointer;
1098 input_line_pointer = save_in;
0198d5e6 1099 return SUCCESS;
b99bd4ef
NC
1100}
1101
c19d1205
ZW
1102/* Turn a string in input_line_pointer into a floating point constant
1103 of type TYPE, and store the appropriate bytes in *LITP. The number
1104 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1105 returned, or NULL on OK.
b99bd4ef 1106
c19d1205
ZW
1107 Note that fp constants aren't represent in the normal way on the ARM.
1108 In big endian mode, things are as expected. However, in little endian
1109 mode fp constants are big-endian word-wise, and little-endian byte-wise
1110 within the words. For example, (double) 1.1 in big endian mode is
1111 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1112 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1113
c19d1205 1114 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1115
6d4af3c2 1116const char *
c19d1205
ZW
1117md_atof (int type, char * litP, int * sizeP)
1118{
1119 int prec;
1120 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1121 char *t;
1122 int i;
b99bd4ef 1123
c19d1205
ZW
1124 switch (type)
1125 {
1126 case 'f':
1127 case 'F':
1128 case 's':
1129 case 'S':
1130 prec = 2;
1131 break;
b99bd4ef 1132
c19d1205
ZW
1133 case 'd':
1134 case 'D':
1135 case 'r':
1136 case 'R':
1137 prec = 4;
1138 break;
b99bd4ef 1139
c19d1205
ZW
1140 case 'x':
1141 case 'X':
499ac353 1142 prec = 5;
c19d1205 1143 break;
b99bd4ef 1144
c19d1205
ZW
1145 case 'p':
1146 case 'P':
499ac353 1147 prec = 5;
c19d1205 1148 break;
a737bd4d 1149
c19d1205
ZW
1150 default:
1151 *sizeP = 0;
499ac353 1152 return _("Unrecognized or unsupported floating point constant");
c19d1205 1153 }
b99bd4ef 1154
c19d1205
ZW
1155 t = atof_ieee (input_line_pointer, type, words);
1156 if (t)
1157 input_line_pointer = t;
499ac353 1158 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1159
c19d1205
ZW
1160 if (target_big_endian)
1161 {
1162 for (i = 0; i < prec; i++)
1163 {
499ac353
NC
1164 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1165 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1166 }
1167 }
1168 else
1169 {
e74cfd16 1170 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1171 for (i = prec - 1; i >= 0; i--)
1172 {
499ac353
NC
1173 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1174 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1175 }
1176 else
1177 /* For a 4 byte float the order of elements in `words' is 1 0.
1178 For an 8 byte float the order is 1 0 3 2. */
1179 for (i = 0; i < prec; i += 2)
1180 {
499ac353
NC
1181 md_number_to_chars (litP, (valueT) words[i + 1],
1182 sizeof (LITTLENUM_TYPE));
1183 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1184 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1185 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1186 }
1187 }
b99bd4ef 1188
499ac353 1189 return NULL;
c19d1205 1190}
b99bd4ef 1191
c19d1205
ZW
1192/* We handle all bad expressions here, so that we can report the faulty
1193 instruction in the error message. */
0198d5e6 1194
c19d1205 1195void
91d6fa6a 1196md_operand (expressionS * exp)
c19d1205
ZW
1197{
1198 if (in_my_get_expression)
91d6fa6a 1199 exp->X_op = O_illegal;
b99bd4ef
NC
1200}
1201
c19d1205 1202/* Immediate values. */
b99bd4ef 1203
0198d5e6 1204#ifdef OBJ_ELF
c19d1205
ZW
1205/* Generic immediate-value read function for use in directives.
1206 Accepts anything that 'expression' can fold to a constant.
1207 *val receives the number. */
0198d5e6 1208
c19d1205
ZW
1209static int
1210immediate_for_directive (int *val)
b99bd4ef 1211{
c19d1205
ZW
1212 expressionS exp;
1213 exp.X_op = O_illegal;
b99bd4ef 1214
c19d1205
ZW
1215 if (is_immediate_prefix (*input_line_pointer))
1216 {
1217 input_line_pointer++;
1218 expression (&exp);
1219 }
b99bd4ef 1220
c19d1205
ZW
1221 if (exp.X_op != O_constant)
1222 {
1223 as_bad (_("expected #constant"));
1224 ignore_rest_of_line ();
1225 return FAIL;
1226 }
1227 *val = exp.X_add_number;
1228 return SUCCESS;
b99bd4ef 1229}
c19d1205 1230#endif
b99bd4ef 1231
c19d1205 1232/* Register parsing. */
b99bd4ef 1233
c19d1205
ZW
1234/* Generic register parser. CCP points to what should be the
1235 beginning of a register name. If it is indeed a valid register
1236 name, advance CCP over it and return the reg_entry structure;
1237 otherwise return NULL. Does not issue diagnostics. */
1238
1239static struct reg_entry *
1240arm_reg_parse_multi (char **ccp)
b99bd4ef 1241{
c19d1205
ZW
1242 char *start = *ccp;
1243 char *p;
1244 struct reg_entry *reg;
b99bd4ef 1245
477330fc
RM
1246 skip_whitespace (start);
1247
c19d1205
ZW
1248#ifdef REGISTER_PREFIX
1249 if (*start != REGISTER_PREFIX)
01cfc07f 1250 return NULL;
c19d1205
ZW
1251 start++;
1252#endif
1253#ifdef OPTIONAL_REGISTER_PREFIX
1254 if (*start == OPTIONAL_REGISTER_PREFIX)
1255 start++;
1256#endif
b99bd4ef 1257
c19d1205
ZW
1258 p = start;
1259 if (!ISALPHA (*p) || !is_name_beginner (*p))
1260 return NULL;
b99bd4ef 1261
c19d1205
ZW
1262 do
1263 p++;
1264 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1265
1266 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1267
1268 if (!reg)
1269 return NULL;
1270
1271 *ccp = p;
1272 return reg;
b99bd4ef
NC
1273}
1274
1275static int
dcbf9037 1276arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1277 enum arm_reg_type type)
b99bd4ef 1278{
c19d1205
ZW
1279 /* Alternative syntaxes are accepted for a few register classes. */
1280 switch (type)
1281 {
1282 case REG_TYPE_MVF:
1283 case REG_TYPE_MVD:
1284 case REG_TYPE_MVFX:
1285 case REG_TYPE_MVDX:
1286 /* Generic coprocessor register names are allowed for these. */
79134647 1287 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1288 return reg->number;
1289 break;
69b97547 1290
c19d1205
ZW
1291 case REG_TYPE_CP:
1292 /* For backward compatibility, a bare number is valid here. */
1293 {
1294 unsigned long processor = strtoul (start, ccp, 10);
1295 if (*ccp != start && processor <= 15)
1296 return processor;
1297 }
1a0670f3 1298 /* Fall through. */
6057a28f 1299
c19d1205
ZW
1300 case REG_TYPE_MMXWC:
1301 /* WC includes WCG. ??? I'm not sure this is true for all
1302 instructions that take WC registers. */
79134647 1303 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1304 return reg->number;
6057a28f 1305 break;
c19d1205 1306
6057a28f 1307 default:
c19d1205 1308 break;
6057a28f
NC
1309 }
1310
dcbf9037
JB
1311 return FAIL;
1312}
1313
1314/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1315 return value is the register number or FAIL. */
1316
1317static int
1318arm_reg_parse (char **ccp, enum arm_reg_type type)
1319{
1320 char *start = *ccp;
1321 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1322 int ret;
1323
1324 /* Do not allow a scalar (reg+index) to parse as a register. */
1325 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1326 return FAIL;
1327
1328 if (reg && reg->type == type)
1329 return reg->number;
1330
1331 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1332 return ret;
1333
c19d1205
ZW
1334 *ccp = start;
1335 return FAIL;
1336}
69b97547 1337
dcbf9037
JB
1338/* Parse a Neon type specifier. *STR should point at the leading '.'
1339 character. Does no verification at this stage that the type fits the opcode
1340 properly. E.g.,
1341
1342 .i32.i32.s16
1343 .s32.f32
1344 .u16
1345
1346 Can all be legally parsed by this function.
1347
1348 Fills in neon_type struct pointer with parsed information, and updates STR
1349 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1350 type, FAIL if not. */
1351
1352static int
1353parse_neon_type (struct neon_type *type, char **str)
1354{
1355 char *ptr = *str;
1356
1357 if (type)
1358 type->elems = 0;
1359
1360 while (type->elems < NEON_MAX_TYPE_ELS)
1361 {
1362 enum neon_el_type thistype = NT_untyped;
1363 unsigned thissize = -1u;
1364
1365 if (*ptr != '.')
1366 break;
1367
1368 ptr++;
1369
1370 /* Just a size without an explicit type. */
1371 if (ISDIGIT (*ptr))
1372 goto parsesize;
1373
1374 switch (TOLOWER (*ptr))
1375 {
1376 case 'i': thistype = NT_integer; break;
1377 case 'f': thistype = NT_float; break;
1378 case 'p': thistype = NT_poly; break;
1379 case 's': thistype = NT_signed; break;
1380 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1381 case 'd':
1382 thistype = NT_float;
1383 thissize = 64;
1384 ptr++;
1385 goto done;
dcbf9037
JB
1386 default:
1387 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1388 return FAIL;
1389 }
1390
1391 ptr++;
1392
1393 /* .f is an abbreviation for .f32. */
1394 if (thistype == NT_float && !ISDIGIT (*ptr))
1395 thissize = 32;
1396 else
1397 {
1398 parsesize:
1399 thissize = strtoul (ptr, &ptr, 10);
1400
1401 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1402 && thissize != 64)
1403 {
1404 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1405 return FAIL;
1406 }
1407 }
1408
037e8744 1409 done:
dcbf9037 1410 if (type)
477330fc
RM
1411 {
1412 type->el[type->elems].type = thistype;
dcbf9037
JB
1413 type->el[type->elems].size = thissize;
1414 type->elems++;
1415 }
1416 }
1417
1418 /* Empty/missing type is not a successful parse. */
1419 if (type->elems == 0)
1420 return FAIL;
1421
1422 *str = ptr;
1423
1424 return SUCCESS;
1425}
1426
1427/* Errors may be set multiple times during parsing or bit encoding
1428 (particularly in the Neon bits), but usually the earliest error which is set
1429 will be the most meaningful. Avoid overwriting it with later (cascading)
1430 errors by calling this function. */
1431
1432static void
1433first_error (const char *err)
1434{
1435 if (!inst.error)
1436 inst.error = err;
1437}
1438
1439/* Parse a single type, e.g. ".s32", leading period included. */
1440static int
1441parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1442{
1443 char *str = *ccp;
1444 struct neon_type optype;
1445
1446 if (*str == '.')
1447 {
1448 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1449 {
1450 if (optype.elems == 1)
1451 *vectype = optype.el[0];
1452 else
1453 {
1454 first_error (_("only one type should be specified for operand"));
1455 return FAIL;
1456 }
1457 }
dcbf9037 1458 else
477330fc
RM
1459 {
1460 first_error (_("vector type expected"));
1461 return FAIL;
1462 }
dcbf9037
JB
1463 }
1464 else
1465 return FAIL;
5f4273c7 1466
dcbf9037 1467 *ccp = str;
5f4273c7 1468
dcbf9037
JB
1469 return SUCCESS;
1470}
1471
1472/* Special meanings for indices (which have a range of 0-7), which will fit into
1473 a 4-bit integer. */
1474
1475#define NEON_ALL_LANES 15
1476#define NEON_INTERLEAVE_LANES 14
1477
1478/* Parse either a register or a scalar, with an optional type. Return the
1479 register number, and optionally fill in the actual type of the register
1480 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1481 type/index information in *TYPEINFO. */
1482
1483static int
1484parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1485 enum arm_reg_type *rtype,
1486 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1487{
1488 char *str = *ccp;
1489 struct reg_entry *reg = arm_reg_parse_multi (&str);
1490 struct neon_typed_alias atype;
1491 struct neon_type_el parsetype;
1492
1493 atype.defined = 0;
1494 atype.index = -1;
1495 atype.eltype.type = NT_invtype;
1496 atype.eltype.size = -1;
1497
1498 /* Try alternate syntax for some types of register. Note these are mutually
1499 exclusive with the Neon syntax extensions. */
1500 if (reg == NULL)
1501 {
1502 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1503 if (altreg != FAIL)
477330fc 1504 *ccp = str;
dcbf9037 1505 if (typeinfo)
477330fc 1506 *typeinfo = atype;
dcbf9037
JB
1507 return altreg;
1508 }
1509
037e8744
JB
1510 /* Undo polymorphism when a set of register types may be accepted. */
1511 if ((type == REG_TYPE_NDQ
1512 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1513 || (type == REG_TYPE_VFSD
477330fc 1514 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1515 || (type == REG_TYPE_NSDQ
477330fc
RM
1516 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1517 || reg->type == REG_TYPE_NQ))
dec41383
JW
1518 || (type == REG_TYPE_NSD
1519 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1520 || (type == REG_TYPE_MMXWC
1521 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1522 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1523
1524 if (type != reg->type)
1525 return FAIL;
1526
1527 if (reg->neon)
1528 atype = *reg->neon;
5f4273c7 1529
dcbf9037
JB
1530 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1531 {
1532 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1533 {
1534 first_error (_("can't redefine type for operand"));
1535 return FAIL;
1536 }
dcbf9037
JB
1537 atype.defined |= NTA_HASTYPE;
1538 atype.eltype = parsetype;
1539 }
5f4273c7 1540
dcbf9037
JB
1541 if (skip_past_char (&str, '[') == SUCCESS)
1542 {
dec41383
JW
1543 if (type != REG_TYPE_VFD
1544 && !(type == REG_TYPE_VFS
1545 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1546 {
1547 first_error (_("only D registers may be indexed"));
1548 return FAIL;
1549 }
5f4273c7 1550
dcbf9037 1551 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1552 {
1553 first_error (_("can't change index for operand"));
1554 return FAIL;
1555 }
dcbf9037
JB
1556
1557 atype.defined |= NTA_HASINDEX;
1558
1559 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1560 atype.index = NEON_ALL_LANES;
dcbf9037 1561 else
477330fc
RM
1562 {
1563 expressionS exp;
dcbf9037 1564
477330fc 1565 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1566
477330fc
RM
1567 if (exp.X_op != O_constant)
1568 {
1569 first_error (_("constant expression required"));
1570 return FAIL;
1571 }
dcbf9037 1572
477330fc
RM
1573 if (skip_past_char (&str, ']') == FAIL)
1574 return FAIL;
dcbf9037 1575
477330fc
RM
1576 atype.index = exp.X_add_number;
1577 }
dcbf9037 1578 }
5f4273c7 1579
dcbf9037
JB
1580 if (typeinfo)
1581 *typeinfo = atype;
5f4273c7 1582
dcbf9037
JB
1583 if (rtype)
1584 *rtype = type;
5f4273c7 1585
dcbf9037 1586 *ccp = str;
5f4273c7 1587
dcbf9037
JB
1588 return reg->number;
1589}
1590
1591/* Like arm_reg_parse, but allow allow the following extra features:
1592 - If RTYPE is non-zero, return the (possibly restricted) type of the
1593 register (e.g. Neon double or quad reg when either has been requested).
1594 - If this is a Neon vector type with additional type information, fill
1595 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1596 This function will fault on encountering a scalar. */
dcbf9037
JB
1597
1598static int
1599arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1600 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1601{
1602 struct neon_typed_alias atype;
1603 char *str = *ccp;
1604 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1605
1606 if (reg == FAIL)
1607 return FAIL;
1608
0855e32b
NS
1609 /* Do not allow regname(... to parse as a register. */
1610 if (*str == '(')
1611 return FAIL;
1612
dcbf9037
JB
1613 /* Do not allow a scalar (reg+index) to parse as a register. */
1614 if ((atype.defined & NTA_HASINDEX) != 0)
1615 {
1616 first_error (_("register operand expected, but got scalar"));
1617 return FAIL;
1618 }
1619
1620 if (vectype)
1621 *vectype = atype.eltype;
1622
1623 *ccp = str;
1624
1625 return reg;
1626}
1627
1628#define NEON_SCALAR_REG(X) ((X) >> 4)
1629#define NEON_SCALAR_INDEX(X) ((X) & 15)
1630
5287ad62
JB
1631/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1632 have enough information to be able to do a good job bounds-checking. So, we
1633 just do easy checks here, and do further checks later. */
1634
1635static int
dcbf9037 1636parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1637{
dcbf9037 1638 int reg;
5287ad62 1639 char *str = *ccp;
dcbf9037 1640 struct neon_typed_alias atype;
dec41383
JW
1641 enum arm_reg_type reg_type = REG_TYPE_VFD;
1642
1643 if (elsize == 4)
1644 reg_type = REG_TYPE_VFS;
5f4273c7 1645
dec41383 1646 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1647
dcbf9037 1648 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1649 return FAIL;
5f4273c7 1650
dcbf9037 1651 if (atype.index == NEON_ALL_LANES)
5287ad62 1652 {
dcbf9037 1653 first_error (_("scalar must have an index"));
5287ad62
JB
1654 return FAIL;
1655 }
dcbf9037 1656 else if (atype.index >= 64 / elsize)
5287ad62 1657 {
dcbf9037 1658 first_error (_("scalar index out of range"));
5287ad62
JB
1659 return FAIL;
1660 }
5f4273c7 1661
dcbf9037
JB
1662 if (type)
1663 *type = atype.eltype;
5f4273c7 1664
5287ad62 1665 *ccp = str;
5f4273c7 1666
dcbf9037 1667 return reg * 16 + atype.index;
5287ad62
JB
1668}
1669
c19d1205 1670/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1671
c19d1205
ZW
1672static long
1673parse_reg_list (char ** strp)
1674{
1675 char * str = * strp;
1676 long range = 0;
1677 int another_range;
a737bd4d 1678
c19d1205
ZW
1679 /* We come back here if we get ranges concatenated by '+' or '|'. */
1680 do
6057a28f 1681 {
477330fc
RM
1682 skip_whitespace (str);
1683
c19d1205 1684 another_range = 0;
a737bd4d 1685
c19d1205
ZW
1686 if (*str == '{')
1687 {
1688 int in_range = 0;
1689 int cur_reg = -1;
a737bd4d 1690
c19d1205
ZW
1691 str++;
1692 do
1693 {
1694 int reg;
6057a28f 1695
dcbf9037 1696 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1697 {
dcbf9037 1698 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1699 return FAIL;
1700 }
a737bd4d 1701
c19d1205
ZW
1702 if (in_range)
1703 {
1704 int i;
a737bd4d 1705
c19d1205
ZW
1706 if (reg <= cur_reg)
1707 {
dcbf9037 1708 first_error (_("bad range in register list"));
c19d1205
ZW
1709 return FAIL;
1710 }
40a18ebd 1711
c19d1205
ZW
1712 for (i = cur_reg + 1; i < reg; i++)
1713 {
1714 if (range & (1 << i))
1715 as_tsktsk
1716 (_("Warning: duplicated register (r%d) in register list"),
1717 i);
1718 else
1719 range |= 1 << i;
1720 }
1721 in_range = 0;
1722 }
a737bd4d 1723
c19d1205
ZW
1724 if (range & (1 << reg))
1725 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1726 reg);
1727 else if (reg <= cur_reg)
1728 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1729
c19d1205
ZW
1730 range |= 1 << reg;
1731 cur_reg = reg;
1732 }
1733 while (skip_past_comma (&str) != FAIL
1734 || (in_range = 1, *str++ == '-'));
1735 str--;
a737bd4d 1736
d996d970 1737 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1738 {
dcbf9037 1739 first_error (_("missing `}'"));
c19d1205
ZW
1740 return FAIL;
1741 }
1742 }
1743 else
1744 {
91d6fa6a 1745 expressionS exp;
40a18ebd 1746
91d6fa6a 1747 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1748 return FAIL;
40a18ebd 1749
91d6fa6a 1750 if (exp.X_op == O_constant)
c19d1205 1751 {
91d6fa6a
NC
1752 if (exp.X_add_number
1753 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1754 {
1755 inst.error = _("invalid register mask");
1756 return FAIL;
1757 }
a737bd4d 1758
91d6fa6a 1759 if ((range & exp.X_add_number) != 0)
c19d1205 1760 {
91d6fa6a 1761 int regno = range & exp.X_add_number;
a737bd4d 1762
c19d1205
ZW
1763 regno &= -regno;
1764 regno = (1 << regno) - 1;
1765 as_tsktsk
1766 (_("Warning: duplicated register (r%d) in register list"),
1767 regno);
1768 }
a737bd4d 1769
91d6fa6a 1770 range |= exp.X_add_number;
c19d1205
ZW
1771 }
1772 else
1773 {
1774 if (inst.reloc.type != 0)
1775 {
1776 inst.error = _("expression too complex");
1777 return FAIL;
1778 }
a737bd4d 1779
91d6fa6a 1780 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1781 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1782 inst.reloc.pc_rel = 0;
1783 }
1784 }
a737bd4d 1785
c19d1205
ZW
1786 if (*str == '|' || *str == '+')
1787 {
1788 str++;
1789 another_range = 1;
1790 }
a737bd4d 1791 }
c19d1205 1792 while (another_range);
a737bd4d 1793
c19d1205
ZW
1794 *strp = str;
1795 return range;
a737bd4d
NC
1796}
1797
5287ad62
JB
1798/* Types of registers in a list. */
1799
1800enum reg_list_els
1801{
1802 REGLIST_VFP_S,
1803 REGLIST_VFP_D,
1804 REGLIST_NEON_D
1805};
1806
c19d1205
ZW
1807/* Parse a VFP register list. If the string is invalid return FAIL.
1808 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1809 register. Parses registers of type ETYPE.
1810 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1811 - Q registers can be used to specify pairs of D registers
1812 - { } can be omitted from around a singleton register list
477330fc
RM
1813 FIXME: This is not implemented, as it would require backtracking in
1814 some cases, e.g.:
1815 vtbl.8 d3,d4,d5
1816 This could be done (the meaning isn't really ambiguous), but doesn't
1817 fit in well with the current parsing framework.
dcbf9037
JB
1818 - 32 D registers may be used (also true for VFPv3).
1819 FIXME: Types are ignored in these register lists, which is probably a
1820 bug. */
6057a28f 1821
c19d1205 1822static int
037e8744 1823parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1824{
037e8744 1825 char *str = *ccp;
c19d1205
ZW
1826 int base_reg;
1827 int new_base;
21d799b5 1828 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1829 int max_regs = 0;
c19d1205
ZW
1830 int count = 0;
1831 int warned = 0;
1832 unsigned long mask = 0;
a737bd4d 1833 int i;
6057a28f 1834
477330fc 1835 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1836 {
1837 inst.error = _("expecting {");
1838 return FAIL;
1839 }
6057a28f 1840
5287ad62 1841 switch (etype)
c19d1205 1842 {
5287ad62 1843 case REGLIST_VFP_S:
c19d1205
ZW
1844 regtype = REG_TYPE_VFS;
1845 max_regs = 32;
5287ad62 1846 break;
5f4273c7 1847
5287ad62
JB
1848 case REGLIST_VFP_D:
1849 regtype = REG_TYPE_VFD;
b7fc2769 1850 break;
5f4273c7 1851
b7fc2769
JB
1852 case REGLIST_NEON_D:
1853 regtype = REG_TYPE_NDQ;
1854 break;
1855 }
1856
1857 if (etype != REGLIST_VFP_S)
1858 {
b1cc4aeb
PB
1859 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1860 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1861 {
1862 max_regs = 32;
1863 if (thumb_mode)
1864 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1865 fpu_vfp_ext_d32);
1866 else
1867 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1868 fpu_vfp_ext_d32);
1869 }
5287ad62 1870 else
477330fc 1871 max_regs = 16;
c19d1205 1872 }
6057a28f 1873
c19d1205 1874 base_reg = max_regs;
a737bd4d 1875
c19d1205
ZW
1876 do
1877 {
5287ad62 1878 int setmask = 1, addregs = 1;
dcbf9037 1879
037e8744 1880 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1881
c19d1205 1882 if (new_base == FAIL)
a737bd4d 1883 {
dcbf9037 1884 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1885 return FAIL;
1886 }
5f4273c7 1887
b7fc2769 1888 if (new_base >= max_regs)
477330fc
RM
1889 {
1890 first_error (_("register out of range in list"));
1891 return FAIL;
1892 }
5f4273c7 1893
5287ad62
JB
1894 /* Note: a value of 2 * n is returned for the register Q<n>. */
1895 if (regtype == REG_TYPE_NQ)
477330fc
RM
1896 {
1897 setmask = 3;
1898 addregs = 2;
1899 }
5287ad62 1900
c19d1205
ZW
1901 if (new_base < base_reg)
1902 base_reg = new_base;
a737bd4d 1903
5287ad62 1904 if (mask & (setmask << new_base))
c19d1205 1905 {
dcbf9037 1906 first_error (_("invalid register list"));
c19d1205 1907 return FAIL;
a737bd4d 1908 }
a737bd4d 1909
c19d1205
ZW
1910 if ((mask >> new_base) != 0 && ! warned)
1911 {
1912 as_tsktsk (_("register list not in ascending order"));
1913 warned = 1;
1914 }
0bbf2aa4 1915
5287ad62
JB
1916 mask |= setmask << new_base;
1917 count += addregs;
0bbf2aa4 1918
037e8744 1919 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1920 {
1921 int high_range;
0bbf2aa4 1922
037e8744 1923 str++;
0bbf2aa4 1924
037e8744 1925 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1926 == FAIL)
c19d1205
ZW
1927 {
1928 inst.error = gettext (reg_expected_msgs[regtype]);
1929 return FAIL;
1930 }
0bbf2aa4 1931
477330fc
RM
1932 if (high_range >= max_regs)
1933 {
1934 first_error (_("register out of range in list"));
1935 return FAIL;
1936 }
b7fc2769 1937
477330fc
RM
1938 if (regtype == REG_TYPE_NQ)
1939 high_range = high_range + 1;
5287ad62 1940
c19d1205
ZW
1941 if (high_range <= new_base)
1942 {
1943 inst.error = _("register range not in ascending order");
1944 return FAIL;
1945 }
0bbf2aa4 1946
5287ad62 1947 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1948 {
5287ad62 1949 if (mask & (setmask << new_base))
0bbf2aa4 1950 {
c19d1205
ZW
1951 inst.error = _("invalid register list");
1952 return FAIL;
0bbf2aa4 1953 }
c19d1205 1954
5287ad62
JB
1955 mask |= setmask << new_base;
1956 count += addregs;
0bbf2aa4 1957 }
0bbf2aa4 1958 }
0bbf2aa4 1959 }
037e8744 1960 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1961
037e8744 1962 str++;
0bbf2aa4 1963
c19d1205
ZW
1964 /* Sanity check -- should have raised a parse error above. */
1965 if (count == 0 || count > max_regs)
1966 abort ();
1967
1968 *pbase = base_reg;
1969
1970 /* Final test -- the registers must be consecutive. */
1971 mask >>= base_reg;
1972 for (i = 0; i < count; i++)
1973 {
1974 if ((mask & (1u << i)) == 0)
1975 {
1976 inst.error = _("non-contiguous register range");
1977 return FAIL;
1978 }
1979 }
1980
037e8744
JB
1981 *ccp = str;
1982
c19d1205 1983 return count;
b99bd4ef
NC
1984}
1985
dcbf9037
JB
1986/* True if two alias types are the same. */
1987
c921be7d 1988static bfd_boolean
dcbf9037
JB
1989neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1990{
1991 if (!a && !b)
c921be7d 1992 return TRUE;
5f4273c7 1993
dcbf9037 1994 if (!a || !b)
c921be7d 1995 return FALSE;
dcbf9037
JB
1996
1997 if (a->defined != b->defined)
c921be7d 1998 return FALSE;
5f4273c7 1999
dcbf9037
JB
2000 if ((a->defined & NTA_HASTYPE) != 0
2001 && (a->eltype.type != b->eltype.type
477330fc 2002 || a->eltype.size != b->eltype.size))
c921be7d 2003 return FALSE;
dcbf9037
JB
2004
2005 if ((a->defined & NTA_HASINDEX) != 0
2006 && (a->index != b->index))
c921be7d 2007 return FALSE;
5f4273c7 2008
c921be7d 2009 return TRUE;
dcbf9037
JB
2010}
2011
5287ad62
JB
2012/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2013 The base register is put in *PBASE.
dcbf9037 2014 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2015 the return value.
2016 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2017 Bits [6:5] encode the list length (minus one).
2018 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2019
5287ad62 2020#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2021#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2022#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2023
2024static int
dcbf9037 2025parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2026 struct neon_type_el *eltype)
5287ad62
JB
2027{
2028 char *ptr = *str;
2029 int base_reg = -1;
2030 int reg_incr = -1;
2031 int count = 0;
2032 int lane = -1;
2033 int leading_brace = 0;
2034 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2035 const char *const incr_error = _("register stride must be 1 or 2");
2036 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2037 struct neon_typed_alias firsttype;
f85d59c3
KT
2038 firsttype.defined = 0;
2039 firsttype.eltype.type = NT_invtype;
2040 firsttype.eltype.size = -1;
2041 firsttype.index = -1;
5f4273c7 2042
5287ad62
JB
2043 if (skip_past_char (&ptr, '{') == SUCCESS)
2044 leading_brace = 1;
5f4273c7 2045
5287ad62
JB
2046 do
2047 {
dcbf9037
JB
2048 struct neon_typed_alias atype;
2049 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2050
5287ad62 2051 if (getreg == FAIL)
477330fc
RM
2052 {
2053 first_error (_(reg_expected_msgs[rtype]));
2054 return FAIL;
2055 }
5f4273c7 2056
5287ad62 2057 if (base_reg == -1)
477330fc
RM
2058 {
2059 base_reg = getreg;
2060 if (rtype == REG_TYPE_NQ)
2061 {
2062 reg_incr = 1;
2063 }
2064 firsttype = atype;
2065 }
5287ad62 2066 else if (reg_incr == -1)
477330fc
RM
2067 {
2068 reg_incr = getreg - base_reg;
2069 if (reg_incr < 1 || reg_incr > 2)
2070 {
2071 first_error (_(incr_error));
2072 return FAIL;
2073 }
2074 }
5287ad62 2075 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2076 {
2077 first_error (_(incr_error));
2078 return FAIL;
2079 }
dcbf9037 2080
c921be7d 2081 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2082 {
2083 first_error (_(type_error));
2084 return FAIL;
2085 }
5f4273c7 2086
5287ad62 2087 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2088 modes. */
5287ad62 2089 if (ptr[0] == '-')
477330fc
RM
2090 {
2091 struct neon_typed_alias htype;
2092 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2093 if (lane == -1)
2094 lane = NEON_INTERLEAVE_LANES;
2095 else if (lane != NEON_INTERLEAVE_LANES)
2096 {
2097 first_error (_(type_error));
2098 return FAIL;
2099 }
2100 if (reg_incr == -1)
2101 reg_incr = 1;
2102 else if (reg_incr != 1)
2103 {
2104 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2105 return FAIL;
2106 }
2107 ptr++;
2108 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2109 if (hireg == FAIL)
2110 {
2111 first_error (_(reg_expected_msgs[rtype]));
2112 return FAIL;
2113 }
2114 if (! neon_alias_types_same (&htype, &firsttype))
2115 {
2116 first_error (_(type_error));
2117 return FAIL;
2118 }
2119 count += hireg + dregs - getreg;
2120 continue;
2121 }
5f4273c7 2122
5287ad62
JB
2123 /* If we're using Q registers, we can't use [] or [n] syntax. */
2124 if (rtype == REG_TYPE_NQ)
477330fc
RM
2125 {
2126 count += 2;
2127 continue;
2128 }
5f4273c7 2129
dcbf9037 2130 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2131 {
2132 if (lane == -1)
2133 lane = atype.index;
2134 else if (lane != atype.index)
2135 {
2136 first_error (_(type_error));
2137 return FAIL;
2138 }
2139 }
5287ad62 2140 else if (lane == -1)
477330fc 2141 lane = NEON_INTERLEAVE_LANES;
5287ad62 2142 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2143 {
2144 first_error (_(type_error));
2145 return FAIL;
2146 }
5287ad62
JB
2147 count++;
2148 }
2149 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2150
5287ad62
JB
2151 /* No lane set by [x]. We must be interleaving structures. */
2152 if (lane == -1)
2153 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2154
5287ad62
JB
2155 /* Sanity check. */
2156 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2157 || (count > 1 && reg_incr == -1))
2158 {
dcbf9037 2159 first_error (_("error parsing element/structure list"));
5287ad62
JB
2160 return FAIL;
2161 }
2162
2163 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2164 {
dcbf9037 2165 first_error (_("expected }"));
5287ad62
JB
2166 return FAIL;
2167 }
5f4273c7 2168
5287ad62
JB
2169 if (reg_incr == -1)
2170 reg_incr = 1;
2171
dcbf9037
JB
2172 if (eltype)
2173 *eltype = firsttype.eltype;
2174
5287ad62
JB
2175 *pbase = base_reg;
2176 *str = ptr;
5f4273c7 2177
5287ad62
JB
2178 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2179}
2180
c19d1205
ZW
2181/* Parse an explicit relocation suffix on an expression. This is
2182 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2183 arm_reloc_hsh contains no entries, so this function can only
2184 succeed if there is no () after the word. Returns -1 on error,
2185 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2186
c19d1205
ZW
2187static int
2188parse_reloc (char **str)
b99bd4ef 2189{
c19d1205
ZW
2190 struct reloc_entry *r;
2191 char *p, *q;
b99bd4ef 2192
c19d1205
ZW
2193 if (**str != '(')
2194 return BFD_RELOC_UNUSED;
b99bd4ef 2195
c19d1205
ZW
2196 p = *str + 1;
2197 q = p;
2198
2199 while (*q && *q != ')' && *q != ',')
2200 q++;
2201 if (*q != ')')
2202 return -1;
2203
21d799b5
NC
2204 if ((r = (struct reloc_entry *)
2205 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2206 return -1;
2207
2208 *str = q + 1;
2209 return r->reloc;
b99bd4ef
NC
2210}
2211
c19d1205
ZW
2212/* Directives: register aliases. */
2213
dcbf9037 2214static struct reg_entry *
90ec0d68 2215insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2216{
d3ce72d0 2217 struct reg_entry *new_reg;
c19d1205 2218 const char *name;
b99bd4ef 2219
d3ce72d0 2220 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2221 {
d3ce72d0 2222 if (new_reg->builtin)
c19d1205 2223 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2224
c19d1205
ZW
2225 /* Only warn about a redefinition if it's not defined as the
2226 same register. */
d3ce72d0 2227 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2228 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2229
d929913e 2230 return NULL;
c19d1205 2231 }
b99bd4ef 2232
c19d1205 2233 name = xstrdup (str);
325801bd 2234 new_reg = XNEW (struct reg_entry);
b99bd4ef 2235
d3ce72d0
NC
2236 new_reg->name = name;
2237 new_reg->number = number;
2238 new_reg->type = type;
2239 new_reg->builtin = FALSE;
2240 new_reg->neon = NULL;
b99bd4ef 2241
d3ce72d0 2242 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2243 abort ();
5f4273c7 2244
d3ce72d0 2245 return new_reg;
dcbf9037
JB
2246}
2247
2248static void
2249insert_neon_reg_alias (char *str, int number, int type,
477330fc 2250 struct neon_typed_alias *atype)
dcbf9037
JB
2251{
2252 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2253
dcbf9037
JB
2254 if (!reg)
2255 {
2256 first_error (_("attempt to redefine typed alias"));
2257 return;
2258 }
5f4273c7 2259
dcbf9037
JB
2260 if (atype)
2261 {
325801bd 2262 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2263 *reg->neon = *atype;
2264 }
c19d1205 2265}
b99bd4ef 2266
c19d1205 2267/* Look for the .req directive. This is of the form:
b99bd4ef 2268
c19d1205 2269 new_register_name .req existing_register_name
b99bd4ef 2270
c19d1205 2271 If we find one, or if it looks sufficiently like one that we want to
d929913e 2272 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2273
d929913e 2274static bfd_boolean
c19d1205
ZW
2275create_register_alias (char * newname, char *p)
2276{
2277 struct reg_entry *old;
2278 char *oldname, *nbuf;
2279 size_t nlen;
b99bd4ef 2280
c19d1205
ZW
2281 /* The input scrubber ensures that whitespace after the mnemonic is
2282 collapsed to single spaces. */
2283 oldname = p;
2284 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2285 return FALSE;
b99bd4ef 2286
c19d1205
ZW
2287 oldname += 6;
2288 if (*oldname == '\0')
d929913e 2289 return FALSE;
b99bd4ef 2290
21d799b5 2291 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2292 if (!old)
b99bd4ef 2293 {
c19d1205 2294 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2295 return TRUE;
b99bd4ef
NC
2296 }
2297
c19d1205
ZW
2298 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2299 the desired alias name, and p points to its end. If not, then
2300 the desired alias name is in the global original_case_string. */
2301#ifdef TC_CASE_SENSITIVE
2302 nlen = p - newname;
2303#else
2304 newname = original_case_string;
2305 nlen = strlen (newname);
2306#endif
b99bd4ef 2307
29a2809e 2308 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2309
c19d1205
ZW
2310 /* Create aliases under the new name as stated; an all-lowercase
2311 version of the new name; and an all-uppercase version of the new
2312 name. */
d929913e
NC
2313 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2314 {
2315 for (p = nbuf; *p; p++)
2316 *p = TOUPPER (*p);
c19d1205 2317
d929913e
NC
2318 if (strncmp (nbuf, newname, nlen))
2319 {
2320 /* If this attempt to create an additional alias fails, do not bother
2321 trying to create the all-lower case alias. We will fail and issue
2322 a second, duplicate error message. This situation arises when the
2323 programmer does something like:
2324 foo .req r0
2325 Foo .req r1
2326 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2327 the artificial FOO alias because it has already been created by the
d929913e
NC
2328 first .req. */
2329 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2330 {
2331 free (nbuf);
2332 return TRUE;
2333 }
d929913e 2334 }
c19d1205 2335
d929913e
NC
2336 for (p = nbuf; *p; p++)
2337 *p = TOLOWER (*p);
c19d1205 2338
d929913e
NC
2339 if (strncmp (nbuf, newname, nlen))
2340 insert_reg_alias (nbuf, old->number, old->type);
2341 }
c19d1205 2342
e1fa0163 2343 free (nbuf);
d929913e 2344 return TRUE;
b99bd4ef
NC
2345}
2346
dcbf9037
JB
2347/* Create a Neon typed/indexed register alias using directives, e.g.:
2348 X .dn d5.s32[1]
2349 Y .qn 6.s16
2350 Z .dn d7
2351 T .dn Z[0]
2352 These typed registers can be used instead of the types specified after the
2353 Neon mnemonic, so long as all operands given have types. Types can also be
2354 specified directly, e.g.:
5f4273c7 2355 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2356
c921be7d 2357static bfd_boolean
dcbf9037
JB
2358create_neon_reg_alias (char *newname, char *p)
2359{
2360 enum arm_reg_type basetype;
2361 struct reg_entry *basereg;
2362 struct reg_entry mybasereg;
2363 struct neon_type ntype;
2364 struct neon_typed_alias typeinfo;
12d6b0b7 2365 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2366 int namelen;
5f4273c7 2367
dcbf9037
JB
2368 typeinfo.defined = 0;
2369 typeinfo.eltype.type = NT_invtype;
2370 typeinfo.eltype.size = -1;
2371 typeinfo.index = -1;
5f4273c7 2372
dcbf9037 2373 nameend = p;
5f4273c7 2374
dcbf9037
JB
2375 if (strncmp (p, " .dn ", 5) == 0)
2376 basetype = REG_TYPE_VFD;
2377 else if (strncmp (p, " .qn ", 5) == 0)
2378 basetype = REG_TYPE_NQ;
2379 else
c921be7d 2380 return FALSE;
5f4273c7 2381
dcbf9037 2382 p += 5;
5f4273c7 2383
dcbf9037 2384 if (*p == '\0')
c921be7d 2385 return FALSE;
5f4273c7 2386
dcbf9037
JB
2387 basereg = arm_reg_parse_multi (&p);
2388
2389 if (basereg && basereg->type != basetype)
2390 {
2391 as_bad (_("bad type for register"));
c921be7d 2392 return FALSE;
dcbf9037
JB
2393 }
2394
2395 if (basereg == NULL)
2396 {
2397 expressionS exp;
2398 /* Try parsing as an integer. */
2399 my_get_expression (&exp, &p, GE_NO_PREFIX);
2400 if (exp.X_op != O_constant)
477330fc
RM
2401 {
2402 as_bad (_("expression must be constant"));
2403 return FALSE;
2404 }
dcbf9037
JB
2405 basereg = &mybasereg;
2406 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2407 : exp.X_add_number;
dcbf9037
JB
2408 basereg->neon = 0;
2409 }
2410
2411 if (basereg->neon)
2412 typeinfo = *basereg->neon;
2413
2414 if (parse_neon_type (&ntype, &p) == SUCCESS)
2415 {
2416 /* We got a type. */
2417 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2418 {
2419 as_bad (_("can't redefine the type of a register alias"));
2420 return FALSE;
2421 }
5f4273c7 2422
dcbf9037
JB
2423 typeinfo.defined |= NTA_HASTYPE;
2424 if (ntype.elems != 1)
477330fc
RM
2425 {
2426 as_bad (_("you must specify a single type only"));
2427 return FALSE;
2428 }
dcbf9037
JB
2429 typeinfo.eltype = ntype.el[0];
2430 }
5f4273c7 2431
dcbf9037
JB
2432 if (skip_past_char (&p, '[') == SUCCESS)
2433 {
2434 expressionS exp;
2435 /* We got a scalar index. */
5f4273c7 2436
dcbf9037 2437 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2438 {
2439 as_bad (_("can't redefine the index of a scalar alias"));
2440 return FALSE;
2441 }
5f4273c7 2442
dcbf9037 2443 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2444
dcbf9037 2445 if (exp.X_op != O_constant)
477330fc
RM
2446 {
2447 as_bad (_("scalar index must be constant"));
2448 return FALSE;
2449 }
5f4273c7 2450
dcbf9037
JB
2451 typeinfo.defined |= NTA_HASINDEX;
2452 typeinfo.index = exp.X_add_number;
5f4273c7 2453
dcbf9037 2454 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2455 {
2456 as_bad (_("expecting ]"));
2457 return FALSE;
2458 }
dcbf9037
JB
2459 }
2460
15735687
NS
2461 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2462 the desired alias name, and p points to its end. If not, then
2463 the desired alias name is in the global original_case_string. */
2464#ifdef TC_CASE_SENSITIVE
dcbf9037 2465 namelen = nameend - newname;
15735687
NS
2466#else
2467 newname = original_case_string;
2468 namelen = strlen (newname);
2469#endif
2470
29a2809e 2471 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2472
dcbf9037 2473 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2474 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2475
dcbf9037
JB
2476 /* Insert name in all uppercase. */
2477 for (p = namebuf; *p; p++)
2478 *p = TOUPPER (*p);
5f4273c7 2479
dcbf9037
JB
2480 if (strncmp (namebuf, newname, namelen))
2481 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2482 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2483
dcbf9037
JB
2484 /* Insert name in all lowercase. */
2485 for (p = namebuf; *p; p++)
2486 *p = TOLOWER (*p);
5f4273c7 2487
dcbf9037
JB
2488 if (strncmp (namebuf, newname, namelen))
2489 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2490 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2491
e1fa0163 2492 free (namebuf);
c921be7d 2493 return TRUE;
dcbf9037
JB
2494}
2495
c19d1205
ZW
2496/* Should never be called, as .req goes between the alias and the
2497 register name, not at the beginning of the line. */
c921be7d 2498
b99bd4ef 2499static void
c19d1205 2500s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2501{
c19d1205
ZW
2502 as_bad (_("invalid syntax for .req directive"));
2503}
b99bd4ef 2504
dcbf9037
JB
2505static void
2506s_dn (int a ATTRIBUTE_UNUSED)
2507{
2508 as_bad (_("invalid syntax for .dn directive"));
2509}
2510
2511static void
2512s_qn (int a ATTRIBUTE_UNUSED)
2513{
2514 as_bad (_("invalid syntax for .qn directive"));
2515}
2516
c19d1205
ZW
2517/* The .unreq directive deletes an alias which was previously defined
2518 by .req. For example:
b99bd4ef 2519
c19d1205
ZW
2520 my_alias .req r11
2521 .unreq my_alias */
b99bd4ef
NC
2522
2523static void
c19d1205 2524s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2525{
c19d1205
ZW
2526 char * name;
2527 char saved_char;
b99bd4ef 2528
c19d1205
ZW
2529 name = input_line_pointer;
2530
2531 while (*input_line_pointer != 0
2532 && *input_line_pointer != ' '
2533 && *input_line_pointer != '\n')
2534 ++input_line_pointer;
2535
2536 saved_char = *input_line_pointer;
2537 *input_line_pointer = 0;
2538
2539 if (!*name)
2540 as_bad (_("invalid syntax for .unreq directive"));
2541 else
2542 {
21d799b5 2543 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2544 name);
c19d1205
ZW
2545
2546 if (!reg)
2547 as_bad (_("unknown register alias '%s'"), name);
2548 else if (reg->builtin)
a1727c1a 2549 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2550 name);
2551 else
2552 {
d929913e
NC
2553 char * p;
2554 char * nbuf;
2555
db0bc284 2556 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2557 free ((char *) reg->name);
477330fc
RM
2558 if (reg->neon)
2559 free (reg->neon);
c19d1205 2560 free (reg);
d929913e
NC
2561
2562 /* Also locate the all upper case and all lower case versions.
2563 Do not complain if we cannot find one or the other as it
2564 was probably deleted above. */
5f4273c7 2565
d929913e
NC
2566 nbuf = strdup (name);
2567 for (p = nbuf; *p; p++)
2568 *p = TOUPPER (*p);
21d799b5 2569 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2570 if (reg)
2571 {
db0bc284 2572 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2573 free ((char *) reg->name);
2574 if (reg->neon)
2575 free (reg->neon);
2576 free (reg);
2577 }
2578
2579 for (p = nbuf; *p; p++)
2580 *p = TOLOWER (*p);
21d799b5 2581 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2582 if (reg)
2583 {
db0bc284 2584 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2585 free ((char *) reg->name);
2586 if (reg->neon)
2587 free (reg->neon);
2588 free (reg);
2589 }
2590
2591 free (nbuf);
c19d1205
ZW
2592 }
2593 }
b99bd4ef 2594
c19d1205 2595 *input_line_pointer = saved_char;
b99bd4ef
NC
2596 demand_empty_rest_of_line ();
2597}
2598
c19d1205
ZW
2599/* Directives: Instruction set selection. */
2600
2601#ifdef OBJ_ELF
2602/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2603 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2604 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2605 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2606
cd000bff
DJ
2607/* Create a new mapping symbol for the transition to STATE. */
2608
2609static void
2610make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2611{
a737bd4d 2612 symbolS * symbolP;
c19d1205
ZW
2613 const char * symname;
2614 int type;
b99bd4ef 2615
c19d1205 2616 switch (state)
b99bd4ef 2617 {
c19d1205
ZW
2618 case MAP_DATA:
2619 symname = "$d";
2620 type = BSF_NO_FLAGS;
2621 break;
2622 case MAP_ARM:
2623 symname = "$a";
2624 type = BSF_NO_FLAGS;
2625 break;
2626 case MAP_THUMB:
2627 symname = "$t";
2628 type = BSF_NO_FLAGS;
2629 break;
c19d1205
ZW
2630 default:
2631 abort ();
2632 }
2633
cd000bff 2634 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2635 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2636
2637 switch (state)
2638 {
2639 case MAP_ARM:
2640 THUMB_SET_FUNC (symbolP, 0);
2641 ARM_SET_THUMB (symbolP, 0);
2642 ARM_SET_INTERWORK (symbolP, support_interwork);
2643 break;
2644
2645 case MAP_THUMB:
2646 THUMB_SET_FUNC (symbolP, 1);
2647 ARM_SET_THUMB (symbolP, 1);
2648 ARM_SET_INTERWORK (symbolP, support_interwork);
2649 break;
2650
2651 case MAP_DATA:
2652 default:
cd000bff
DJ
2653 break;
2654 }
2655
2656 /* Save the mapping symbols for future reference. Also check that
2657 we do not place two mapping symbols at the same offset within a
2658 frag. We'll handle overlap between frags in
2de7820f
JZ
2659 check_mapping_symbols.
2660
2661 If .fill or other data filling directive generates zero sized data,
2662 the mapping symbol for the following code will have the same value
2663 as the one generated for the data filling directive. In this case,
2664 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2665 if (value == 0)
2666 {
2de7820f
JZ
2667 if (frag->tc_frag_data.first_map != NULL)
2668 {
2669 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2670 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2671 }
cd000bff
DJ
2672 frag->tc_frag_data.first_map = symbolP;
2673 }
2674 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2675 {
2676 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2677 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2678 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2679 }
cd000bff
DJ
2680 frag->tc_frag_data.last_map = symbolP;
2681}
2682
2683/* We must sometimes convert a region marked as code to data during
2684 code alignment, if an odd number of bytes have to be padded. The
2685 code mapping symbol is pushed to an aligned address. */
2686
2687static void
2688insert_data_mapping_symbol (enum mstate state,
2689 valueT value, fragS *frag, offsetT bytes)
2690{
2691 /* If there was already a mapping symbol, remove it. */
2692 if (frag->tc_frag_data.last_map != NULL
2693 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2694 {
2695 symbolS *symp = frag->tc_frag_data.last_map;
2696
2697 if (value == 0)
2698 {
2699 know (frag->tc_frag_data.first_map == symp);
2700 frag->tc_frag_data.first_map = NULL;
2701 }
2702 frag->tc_frag_data.last_map = NULL;
2703 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2704 }
cd000bff
DJ
2705
2706 make_mapping_symbol (MAP_DATA, value, frag);
2707 make_mapping_symbol (state, value + bytes, frag);
2708}
2709
2710static void mapping_state_2 (enum mstate state, int max_chars);
2711
2712/* Set the mapping state to STATE. Only call this when about to
2713 emit some STATE bytes to the file. */
2714
4e9aaefb 2715#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2716void
2717mapping_state (enum mstate state)
2718{
940b5ce0
DJ
2719 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2720
cd000bff
DJ
2721 if (mapstate == state)
2722 /* The mapping symbol has already been emitted.
2723 There is nothing else to do. */
2724 return;
49c62a33
NC
2725
2726 if (state == MAP_ARM || state == MAP_THUMB)
2727 /* PR gas/12931
2728 All ARM instructions require 4-byte alignment.
2729 (Almost) all Thumb instructions require 2-byte alignment.
2730
2731 When emitting instructions into any section, mark the section
2732 appropriately.
2733
2734 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2735 but themselves require 2-byte alignment; this applies to some
33eaf5de 2736 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2737 literal pool generation or an explicit .align >=2, both of
2738 which will cause the section to me marked with sufficient
2739 alignment. Thus, we don't handle those cases here. */
2740 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2741
2742 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2743 /* This case will be evaluated later. */
cd000bff 2744 return;
cd000bff
DJ
2745
2746 mapping_state_2 (state, 0);
cd000bff
DJ
2747}
2748
2749/* Same as mapping_state, but MAX_CHARS bytes have already been
2750 allocated. Put the mapping symbol that far back. */
2751
2752static void
2753mapping_state_2 (enum mstate state, int max_chars)
2754{
940b5ce0
DJ
2755 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2756
2757 if (!SEG_NORMAL (now_seg))
2758 return;
2759
cd000bff
DJ
2760 if (mapstate == state)
2761 /* The mapping symbol has already been emitted.
2762 There is nothing else to do. */
2763 return;
2764
4e9aaefb
SA
2765 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2766 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2767 {
2768 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2769 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2770
2771 if (add_symbol)
2772 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2773 }
2774
cd000bff
DJ
2775 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2776 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2777}
4e9aaefb 2778#undef TRANSITION
c19d1205 2779#else
d3106081
NS
2780#define mapping_state(x) ((void)0)
2781#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2782#endif
2783
2784/* Find the real, Thumb encoded start of a Thumb function. */
2785
4343666d 2786#ifdef OBJ_COFF
c19d1205
ZW
2787static symbolS *
2788find_real_start (symbolS * symbolP)
2789{
2790 char * real_start;
2791 const char * name = S_GET_NAME (symbolP);
2792 symbolS * new_target;
2793
2794 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2795#define STUB_NAME ".real_start_of"
2796
2797 if (name == NULL)
2798 abort ();
2799
37f6032b
ZW
2800 /* The compiler may generate BL instructions to local labels because
2801 it needs to perform a branch to a far away location. These labels
2802 do not have a corresponding ".real_start_of" label. We check
2803 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2804 the ".real_start_of" convention for nonlocal branches. */
2805 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2806 return symbolP;
2807
e1fa0163 2808 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2809 new_target = symbol_find (real_start);
e1fa0163 2810 free (real_start);
c19d1205
ZW
2811
2812 if (new_target == NULL)
2813 {
bd3ba5d1 2814 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2815 new_target = symbolP;
2816 }
2817
c19d1205
ZW
2818 return new_target;
2819}
4343666d 2820#endif
c19d1205
ZW
2821
2822static void
2823opcode_select (int width)
2824{
2825 switch (width)
2826 {
2827 case 16:
2828 if (! thumb_mode)
2829 {
e74cfd16 2830 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2831 as_bad (_("selected processor does not support THUMB opcodes"));
2832
2833 thumb_mode = 1;
2834 /* No need to force the alignment, since we will have been
2835 coming from ARM mode, which is word-aligned. */
2836 record_alignment (now_seg, 1);
2837 }
c19d1205
ZW
2838 break;
2839
2840 case 32:
2841 if (thumb_mode)
2842 {
e74cfd16 2843 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2844 as_bad (_("selected processor does not support ARM opcodes"));
2845
2846 thumb_mode = 0;
2847
2848 if (!need_pass_2)
2849 frag_align (2, 0, 0);
2850
2851 record_alignment (now_seg, 1);
2852 }
c19d1205
ZW
2853 break;
2854
2855 default:
2856 as_bad (_("invalid instruction size selected (%d)"), width);
2857 }
2858}
2859
2860static void
2861s_arm (int ignore ATTRIBUTE_UNUSED)
2862{
2863 opcode_select (32);
2864 demand_empty_rest_of_line ();
2865}
2866
2867static void
2868s_thumb (int ignore ATTRIBUTE_UNUSED)
2869{
2870 opcode_select (16);
2871 demand_empty_rest_of_line ();
2872}
2873
2874static void
2875s_code (int unused ATTRIBUTE_UNUSED)
2876{
2877 int temp;
2878
2879 temp = get_absolute_expression ();
2880 switch (temp)
2881 {
2882 case 16:
2883 case 32:
2884 opcode_select (temp);
2885 break;
2886
2887 default:
2888 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2889 }
2890}
2891
2892static void
2893s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2894{
2895 /* If we are not already in thumb mode go into it, EVEN if
2896 the target processor does not support thumb instructions.
2897 This is used by gcc/config/arm/lib1funcs.asm for example
2898 to compile interworking support functions even if the
2899 target processor should not support interworking. */
2900 if (! thumb_mode)
2901 {
2902 thumb_mode = 2;
2903 record_alignment (now_seg, 1);
2904 }
2905
2906 demand_empty_rest_of_line ();
2907}
2908
2909static void
2910s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2911{
2912 s_thumb (0);
2913
2914 /* The following label is the name/address of the start of a Thumb function.
2915 We need to know this for the interworking support. */
2916 label_is_thumb_function_name = TRUE;
2917}
2918
2919/* Perform a .set directive, but also mark the alias as
2920 being a thumb function. */
2921
2922static void
2923s_thumb_set (int equiv)
2924{
2925 /* XXX the following is a duplicate of the code for s_set() in read.c
2926 We cannot just call that code as we need to get at the symbol that
2927 is created. */
2928 char * name;
2929 char delim;
2930 char * end_name;
2931 symbolS * symbolP;
2932
2933 /* Especial apologies for the random logic:
2934 This just grew, and could be parsed much more simply!
2935 Dean - in haste. */
d02603dc 2936 delim = get_symbol_name (& name);
c19d1205 2937 end_name = input_line_pointer;
d02603dc 2938 (void) restore_line_pointer (delim);
c19d1205
ZW
2939
2940 if (*input_line_pointer != ',')
2941 {
2942 *end_name = 0;
2943 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2944 *end_name = delim;
2945 ignore_rest_of_line ();
2946 return;
2947 }
2948
2949 input_line_pointer++;
2950 *end_name = 0;
2951
2952 if (name[0] == '.' && name[1] == '\0')
2953 {
2954 /* XXX - this should not happen to .thumb_set. */
2955 abort ();
2956 }
2957
2958 if ((symbolP = symbol_find (name)) == NULL
2959 && (symbolP = md_undefined_symbol (name)) == NULL)
2960 {
2961#ifndef NO_LISTING
2962 /* When doing symbol listings, play games with dummy fragments living
2963 outside the normal fragment chain to record the file and line info
c19d1205 2964 for this symbol. */
b99bd4ef
NC
2965 if (listing & LISTING_SYMBOLS)
2966 {
2967 extern struct list_info_struct * listing_tail;
21d799b5 2968 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2969
2970 memset (dummy_frag, 0, sizeof (fragS));
2971 dummy_frag->fr_type = rs_fill;
2972 dummy_frag->line = listing_tail;
2973 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2974 dummy_frag->fr_symbol = symbolP;
2975 }
2976 else
2977#endif
2978 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2979
2980#ifdef OBJ_COFF
2981 /* "set" symbols are local unless otherwise specified. */
2982 SF_SET_LOCAL (symbolP);
2983#endif /* OBJ_COFF */
2984 } /* Make a new symbol. */
2985
2986 symbol_table_insert (symbolP);
2987
2988 * end_name = delim;
2989
2990 if (equiv
2991 && S_IS_DEFINED (symbolP)
2992 && S_GET_SEGMENT (symbolP) != reg_section)
2993 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2994
2995 pseudo_set (symbolP);
2996
2997 demand_empty_rest_of_line ();
2998
c19d1205 2999 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3000
3001 THUMB_SET_FUNC (symbolP, 1);
3002 ARM_SET_THUMB (symbolP, 1);
3003#if defined OBJ_ELF || defined OBJ_COFF
3004 ARM_SET_INTERWORK (symbolP, support_interwork);
3005#endif
3006}
3007
c19d1205 3008/* Directives: Mode selection. */
b99bd4ef 3009
c19d1205
ZW
3010/* .syntax [unified|divided] - choose the new unified syntax
3011 (same for Arm and Thumb encoding, modulo slight differences in what
3012 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3013static void
c19d1205 3014s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3015{
c19d1205
ZW
3016 char *name, delim;
3017
d02603dc 3018 delim = get_symbol_name (& name);
c19d1205
ZW
3019
3020 if (!strcasecmp (name, "unified"))
3021 unified_syntax = TRUE;
3022 else if (!strcasecmp (name, "divided"))
3023 unified_syntax = FALSE;
3024 else
3025 {
3026 as_bad (_("unrecognized syntax mode \"%s\""), name);
3027 return;
3028 }
d02603dc 3029 (void) restore_line_pointer (delim);
b99bd4ef
NC
3030 demand_empty_rest_of_line ();
3031}
3032
c19d1205
ZW
3033/* Directives: sectioning and alignment. */
3034
c19d1205
ZW
3035static void
3036s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3037{
c19d1205
ZW
3038 /* We don't support putting frags in the BSS segment, we fake it by
3039 marking in_bss, then looking at s_skip for clues. */
3040 subseg_set (bss_section, 0);
3041 demand_empty_rest_of_line ();
cd000bff
DJ
3042
3043#ifdef md_elf_section_change_hook
3044 md_elf_section_change_hook ();
3045#endif
c19d1205 3046}
b99bd4ef 3047
c19d1205
ZW
3048static void
3049s_even (int ignore ATTRIBUTE_UNUSED)
3050{
3051 /* Never make frag if expect extra pass. */
3052 if (!need_pass_2)
3053 frag_align (1, 0, 0);
b99bd4ef 3054
c19d1205 3055 record_alignment (now_seg, 1);
b99bd4ef 3056
c19d1205 3057 demand_empty_rest_of_line ();
b99bd4ef
NC
3058}
3059
2e6976a8
DG
3060/* Directives: CodeComposer Studio. */
3061
3062/* .ref (for CodeComposer Studio syntax only). */
3063static void
3064s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3065{
3066 if (codecomposer_syntax)
3067 ignore_rest_of_line ();
3068 else
3069 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3070}
3071
3072/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3073 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3074static void
3075asmfunc_debug (const char * name)
3076{
3077 static const char * last_name = NULL;
3078
3079 if (name != NULL)
3080 {
3081 gas_assert (last_name == NULL);
3082 last_name = name;
3083
3084 if (debug_type == DEBUG_STABS)
3085 stabs_generate_asm_func (name, name);
3086 }
3087 else
3088 {
3089 gas_assert (last_name != NULL);
3090
3091 if (debug_type == DEBUG_STABS)
3092 stabs_generate_asm_endfunc (last_name, last_name);
3093
3094 last_name = NULL;
3095 }
3096}
3097
3098static void
3099s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3100{
3101 if (codecomposer_syntax)
3102 {
3103 switch (asmfunc_state)
3104 {
3105 case OUTSIDE_ASMFUNC:
3106 asmfunc_state = WAITING_ASMFUNC_NAME;
3107 break;
3108
3109 case WAITING_ASMFUNC_NAME:
3110 as_bad (_(".asmfunc repeated."));
3111 break;
3112
3113 case WAITING_ENDASMFUNC:
3114 as_bad (_(".asmfunc without function."));
3115 break;
3116 }
3117 demand_empty_rest_of_line ();
3118 }
3119 else
3120 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3121}
3122
3123static void
3124s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3125{
3126 if (codecomposer_syntax)
3127 {
3128 switch (asmfunc_state)
3129 {
3130 case OUTSIDE_ASMFUNC:
3131 as_bad (_(".endasmfunc without a .asmfunc."));
3132 break;
3133
3134 case WAITING_ASMFUNC_NAME:
3135 as_bad (_(".endasmfunc without function."));
3136 break;
3137
3138 case WAITING_ENDASMFUNC:
3139 asmfunc_state = OUTSIDE_ASMFUNC;
3140 asmfunc_debug (NULL);
3141 break;
3142 }
3143 demand_empty_rest_of_line ();
3144 }
3145 else
3146 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3147}
3148
3149static void
3150s_ccs_def (int name)
3151{
3152 if (codecomposer_syntax)
3153 s_globl (name);
3154 else
3155 as_bad (_(".def pseudo-op only available with -mccs flag."));
3156}
3157
c19d1205 3158/* Directives: Literal pools. */
a737bd4d 3159
c19d1205
ZW
3160static literal_pool *
3161find_literal_pool (void)
a737bd4d 3162{
c19d1205 3163 literal_pool * pool;
a737bd4d 3164
c19d1205 3165 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3166 {
c19d1205
ZW
3167 if (pool->section == now_seg
3168 && pool->sub_section == now_subseg)
3169 break;
a737bd4d
NC
3170 }
3171
c19d1205 3172 return pool;
a737bd4d
NC
3173}
3174
c19d1205
ZW
3175static literal_pool *
3176find_or_make_literal_pool (void)
a737bd4d 3177{
c19d1205
ZW
3178 /* Next literal pool ID number. */
3179 static unsigned int latest_pool_num = 1;
3180 literal_pool * pool;
a737bd4d 3181
c19d1205 3182 pool = find_literal_pool ();
a737bd4d 3183
c19d1205 3184 if (pool == NULL)
a737bd4d 3185 {
c19d1205 3186 /* Create a new pool. */
325801bd 3187 pool = XNEW (literal_pool);
c19d1205
ZW
3188 if (! pool)
3189 return NULL;
a737bd4d 3190
c19d1205
ZW
3191 pool->next_free_entry = 0;
3192 pool->section = now_seg;
3193 pool->sub_section = now_subseg;
3194 pool->next = list_of_pools;
3195 pool->symbol = NULL;
8335d6aa 3196 pool->alignment = 2;
c19d1205
ZW
3197
3198 /* Add it to the list. */
3199 list_of_pools = pool;
a737bd4d 3200 }
a737bd4d 3201
c19d1205
ZW
3202 /* New pools, and emptied pools, will have a NULL symbol. */
3203 if (pool->symbol == NULL)
a737bd4d 3204 {
c19d1205
ZW
3205 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3206 (valueT) 0, &zero_address_frag);
3207 pool->id = latest_pool_num ++;
a737bd4d
NC
3208 }
3209
c19d1205
ZW
3210 /* Done. */
3211 return pool;
a737bd4d
NC
3212}
3213
c19d1205 3214/* Add the literal in the global 'inst'
5f4273c7 3215 structure to the relevant literal pool. */
b99bd4ef
NC
3216
3217static int
8335d6aa 3218add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3219{
8335d6aa
JW
3220#define PADDING_SLOT 0x1
3221#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3222 literal_pool * pool;
8335d6aa
JW
3223 unsigned int entry, pool_size = 0;
3224 bfd_boolean padding_slot_p = FALSE;
e56c722b 3225 unsigned imm1 = 0;
8335d6aa
JW
3226 unsigned imm2 = 0;
3227
3228 if (nbytes == 8)
3229 {
3230 imm1 = inst.operands[1].imm;
3231 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3232 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3233 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3234 if (target_big_endian)
3235 {
3236 imm1 = imm2;
3237 imm2 = inst.operands[1].imm;
3238 }
3239 }
b99bd4ef 3240
c19d1205
ZW
3241 pool = find_or_make_literal_pool ();
3242
3243 /* Check if this literal value is already in the pool. */
3244 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3245 {
8335d6aa
JW
3246 if (nbytes == 4)
3247 {
3248 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3249 && (inst.reloc.exp.X_op == O_constant)
3250 && (pool->literals[entry].X_add_number
3251 == inst.reloc.exp.X_add_number)
3252 && (pool->literals[entry].X_md == nbytes)
3253 && (pool->literals[entry].X_unsigned
3254 == inst.reloc.exp.X_unsigned))
3255 break;
3256
3257 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3258 && (inst.reloc.exp.X_op == O_symbol)
3259 && (pool->literals[entry].X_add_number
3260 == inst.reloc.exp.X_add_number)
3261 && (pool->literals[entry].X_add_symbol
3262 == inst.reloc.exp.X_add_symbol)
3263 && (pool->literals[entry].X_op_symbol
3264 == inst.reloc.exp.X_op_symbol)
3265 && (pool->literals[entry].X_md == nbytes))
3266 break;
3267 }
3268 else if ((nbytes == 8)
3269 && !(pool_size & 0x7)
3270 && ((entry + 1) != pool->next_free_entry)
3271 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3272 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3273 && (pool->literals[entry].X_unsigned
3274 == inst.reloc.exp.X_unsigned)
3275 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3276 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3277 && (pool->literals[entry + 1].X_unsigned
3278 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3279 break;
3280
8335d6aa
JW
3281 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3282 if (padding_slot_p && (nbytes == 4))
c19d1205 3283 break;
8335d6aa
JW
3284
3285 pool_size += 4;
b99bd4ef
NC
3286 }
3287
c19d1205
ZW
3288 /* Do we need to create a new entry? */
3289 if (entry == pool->next_free_entry)
3290 {
3291 if (entry >= MAX_LITERAL_POOL_SIZE)
3292 {
3293 inst.error = _("literal pool overflow");
3294 return FAIL;
3295 }
3296
8335d6aa
JW
3297 if (nbytes == 8)
3298 {
3299 /* For 8-byte entries, we align to an 8-byte boundary,
3300 and split it into two 4-byte entries, because on 32-bit
3301 host, 8-byte constants are treated as big num, thus
3302 saved in "generic_bignum" which will be overwritten
3303 by later assignments.
3304
3305 We also need to make sure there is enough space for
3306 the split.
3307
3308 We also check to make sure the literal operand is a
3309 constant number. */
19f2f6a9
JW
3310 if (!(inst.reloc.exp.X_op == O_constant
3311 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3312 {
3313 inst.error = _("invalid type for literal pool");
3314 return FAIL;
3315 }
3316 else if (pool_size & 0x7)
3317 {
3318 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3319 {
3320 inst.error = _("literal pool overflow");
3321 return FAIL;
3322 }
3323
3324 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3325 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3326 pool->literals[entry].X_add_number = 0;
3327 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3328 pool->next_free_entry += 1;
3329 pool_size += 4;
3330 }
3331 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3332 {
3333 inst.error = _("literal pool overflow");
3334 return FAIL;
3335 }
3336
3337 pool->literals[entry] = inst.reloc.exp;
3338 pool->literals[entry].X_op = O_constant;
3339 pool->literals[entry].X_add_number = imm1;
3340 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3341 pool->literals[entry++].X_md = 4;
3342 pool->literals[entry] = inst.reloc.exp;
3343 pool->literals[entry].X_op = O_constant;
3344 pool->literals[entry].X_add_number = imm2;
3345 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3346 pool->literals[entry].X_md = 4;
3347 pool->alignment = 3;
3348 pool->next_free_entry += 1;
3349 }
3350 else
3351 {
3352 pool->literals[entry] = inst.reloc.exp;
3353 pool->literals[entry].X_md = 4;
3354 }
3355
a8040cf2
NC
3356#ifdef OBJ_ELF
3357 /* PR ld/12974: Record the location of the first source line to reference
3358 this entry in the literal pool. If it turns out during linking that the
3359 symbol does not exist we will be able to give an accurate line number for
3360 the (first use of the) missing reference. */
3361 if (debug_type == DEBUG_DWARF2)
3362 dwarf2_where (pool->locs + entry);
3363#endif
c19d1205
ZW
3364 pool->next_free_entry += 1;
3365 }
8335d6aa
JW
3366 else if (padding_slot_p)
3367 {
3368 pool->literals[entry] = inst.reloc.exp;
3369 pool->literals[entry].X_md = nbytes;
3370 }
b99bd4ef 3371
c19d1205 3372 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3373 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3374 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3375
c19d1205 3376 return SUCCESS;
b99bd4ef
NC
3377}
3378
2e6976a8 3379bfd_boolean
2e57ce7b 3380tc_start_label_without_colon (void)
2e6976a8
DG
3381{
3382 bfd_boolean ret = TRUE;
3383
3384 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3385 {
2e57ce7b 3386 const char *label = input_line_pointer;
2e6976a8
DG
3387
3388 while (!is_end_of_line[(int) label[-1]])
3389 --label;
3390
3391 if (*label == '.')
3392 {
3393 as_bad (_("Invalid label '%s'"), label);
3394 ret = FALSE;
3395 }
3396
3397 asmfunc_debug (label);
3398
3399 asmfunc_state = WAITING_ENDASMFUNC;
3400 }
3401
3402 return ret;
3403}
3404
c19d1205 3405/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3406 a later date assign it a value. That's what these functions do. */
e16bb312 3407
c19d1205
ZW
3408static void
3409symbol_locate (symbolS * symbolP,
3410 const char * name, /* It is copied, the caller can modify. */
3411 segT segment, /* Segment identifier (SEG_<something>). */
3412 valueT valu, /* Symbol value. */
3413 fragS * frag) /* Associated fragment. */
3414{
e57e6ddc 3415 size_t name_length;
c19d1205 3416 char * preserved_copy_of_name;
e16bb312 3417
c19d1205
ZW
3418 name_length = strlen (name) + 1; /* +1 for \0. */
3419 obstack_grow (&notes, name, name_length);
21d799b5 3420 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3421
c19d1205
ZW
3422#ifdef tc_canonicalize_symbol_name
3423 preserved_copy_of_name =
3424 tc_canonicalize_symbol_name (preserved_copy_of_name);
3425#endif
b99bd4ef 3426
c19d1205 3427 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3428
c19d1205
ZW
3429 S_SET_SEGMENT (symbolP, segment);
3430 S_SET_VALUE (symbolP, valu);
3431 symbol_clear_list_pointers (symbolP);
b99bd4ef 3432
c19d1205 3433 symbol_set_frag (symbolP, frag);
b99bd4ef 3434
c19d1205
ZW
3435 /* Link to end of symbol chain. */
3436 {
3437 extern int symbol_table_frozen;
b99bd4ef 3438
c19d1205
ZW
3439 if (symbol_table_frozen)
3440 abort ();
3441 }
b99bd4ef 3442
c19d1205 3443 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3444
c19d1205 3445 obj_symbol_new_hook (symbolP);
b99bd4ef 3446
c19d1205
ZW
3447#ifdef tc_symbol_new_hook
3448 tc_symbol_new_hook (symbolP);
3449#endif
3450
3451#ifdef DEBUG_SYMS
3452 verify_symbol_chain (symbol_rootP, symbol_lastP);
3453#endif /* DEBUG_SYMS */
b99bd4ef
NC
3454}
3455
c19d1205
ZW
3456static void
3457s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3458{
c19d1205
ZW
3459 unsigned int entry;
3460 literal_pool * pool;
3461 char sym_name[20];
b99bd4ef 3462
c19d1205
ZW
3463 pool = find_literal_pool ();
3464 if (pool == NULL
3465 || pool->symbol == NULL
3466 || pool->next_free_entry == 0)
3467 return;
b99bd4ef 3468
c19d1205
ZW
3469 /* Align pool as you have word accesses.
3470 Only make a frag if we have to. */
3471 if (!need_pass_2)
8335d6aa 3472 frag_align (pool->alignment, 0, 0);
b99bd4ef 3473
c19d1205 3474 record_alignment (now_seg, 2);
b99bd4ef 3475
aaca88ef 3476#ifdef OBJ_ELF
47fc6e36
WN
3477 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3478 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3479#endif
c19d1205 3480 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3481
c19d1205
ZW
3482 symbol_locate (pool->symbol, sym_name, now_seg,
3483 (valueT) frag_now_fix (), frag_now);
3484 symbol_table_insert (pool->symbol);
b99bd4ef 3485
c19d1205 3486 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3487
c19d1205
ZW
3488#if defined OBJ_COFF || defined OBJ_ELF
3489 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3490#endif
6c43fab6 3491
c19d1205 3492 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3493 {
3494#ifdef OBJ_ELF
3495 if (debug_type == DEBUG_DWARF2)
3496 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3497#endif
3498 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3499 emit_expr (&(pool->literals[entry]),
3500 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3501 }
b99bd4ef 3502
c19d1205
ZW
3503 /* Mark the pool as empty. */
3504 pool->next_free_entry = 0;
3505 pool->symbol = NULL;
b99bd4ef
NC
3506}
3507
c19d1205
ZW
3508#ifdef OBJ_ELF
3509/* Forward declarations for functions below, in the MD interface
3510 section. */
3511static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3512static valueT create_unwind_entry (int);
3513static void start_unwind_section (const segT, int);
3514static void add_unwind_opcode (valueT, int);
3515static void flush_pending_unwind (void);
b99bd4ef 3516
c19d1205 3517/* Directives: Data. */
b99bd4ef 3518
c19d1205
ZW
3519static void
3520s_arm_elf_cons (int nbytes)
3521{
3522 expressionS exp;
b99bd4ef 3523
c19d1205
ZW
3524#ifdef md_flush_pending_output
3525 md_flush_pending_output ();
3526#endif
b99bd4ef 3527
c19d1205 3528 if (is_it_end_of_statement ())
b99bd4ef 3529 {
c19d1205
ZW
3530 demand_empty_rest_of_line ();
3531 return;
b99bd4ef
NC
3532 }
3533
c19d1205
ZW
3534#ifdef md_cons_align
3535 md_cons_align (nbytes);
3536#endif
b99bd4ef 3537
c19d1205
ZW
3538 mapping_state (MAP_DATA);
3539 do
b99bd4ef 3540 {
c19d1205
ZW
3541 int reloc;
3542 char *base = input_line_pointer;
b99bd4ef 3543
c19d1205 3544 expression (& exp);
b99bd4ef 3545
c19d1205
ZW
3546 if (exp.X_op != O_symbol)
3547 emit_expr (&exp, (unsigned int) nbytes);
3548 else
3549 {
3550 char *before_reloc = input_line_pointer;
3551 reloc = parse_reloc (&input_line_pointer);
3552 if (reloc == -1)
3553 {
3554 as_bad (_("unrecognized relocation suffix"));
3555 ignore_rest_of_line ();
3556 return;
3557 }
3558 else if (reloc == BFD_RELOC_UNUSED)
3559 emit_expr (&exp, (unsigned int) nbytes);
3560 else
3561 {
21d799b5 3562 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3563 bfd_reloc_type_lookup (stdoutput,
3564 (bfd_reloc_code_real_type) reloc);
c19d1205 3565 int size = bfd_get_reloc_size (howto);
b99bd4ef 3566
2fc8bdac
ZW
3567 if (reloc == BFD_RELOC_ARM_PLT32)
3568 {
3569 as_bad (_("(plt) is only valid on branch targets"));
3570 reloc = BFD_RELOC_UNUSED;
3571 size = 0;
3572 }
3573
c19d1205 3574 if (size > nbytes)
992a06ee
AM
3575 as_bad (ngettext ("%s relocations do not fit in %d byte",
3576 "%s relocations do not fit in %d bytes",
3577 nbytes),
c19d1205
ZW
3578 howto->name, nbytes);
3579 else
3580 {
3581 /* We've parsed an expression stopping at O_symbol.
3582 But there may be more expression left now that we
3583 have parsed the relocation marker. Parse it again.
3584 XXX Surely there is a cleaner way to do this. */
3585 char *p = input_line_pointer;
3586 int offset;
325801bd 3587 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3588
c19d1205
ZW
3589 memcpy (save_buf, base, input_line_pointer - base);
3590 memmove (base + (input_line_pointer - before_reloc),
3591 base, before_reloc - base);
3592
3593 input_line_pointer = base + (input_line_pointer-before_reloc);
3594 expression (&exp);
3595 memcpy (base, save_buf, p - base);
3596
3597 offset = nbytes - size;
4b1a927e
AM
3598 p = frag_more (nbytes);
3599 memset (p, 0, nbytes);
c19d1205 3600 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3601 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3602 free (save_buf);
c19d1205
ZW
3603 }
3604 }
3605 }
b99bd4ef 3606 }
c19d1205 3607 while (*input_line_pointer++ == ',');
b99bd4ef 3608
c19d1205
ZW
3609 /* Put terminator back into stream. */
3610 input_line_pointer --;
3611 demand_empty_rest_of_line ();
b99bd4ef
NC
3612}
3613
c921be7d
NC
3614/* Emit an expression containing a 32-bit thumb instruction.
3615 Implementation based on put_thumb32_insn. */
3616
3617static void
3618emit_thumb32_expr (expressionS * exp)
3619{
3620 expressionS exp_high = *exp;
3621
3622 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3623 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3624 exp->X_add_number &= 0xffff;
3625 emit_expr (exp, (unsigned int) THUMB_SIZE);
3626}
3627
3628/* Guess the instruction size based on the opcode. */
3629
3630static int
3631thumb_insn_size (int opcode)
3632{
3633 if ((unsigned int) opcode < 0xe800u)
3634 return 2;
3635 else if ((unsigned int) opcode >= 0xe8000000u)
3636 return 4;
3637 else
3638 return 0;
3639}
3640
3641static bfd_boolean
3642emit_insn (expressionS *exp, int nbytes)
3643{
3644 int size = 0;
3645
3646 if (exp->X_op == O_constant)
3647 {
3648 size = nbytes;
3649
3650 if (size == 0)
3651 size = thumb_insn_size (exp->X_add_number);
3652
3653 if (size != 0)
3654 {
3655 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3656 {
3657 as_bad (_(".inst.n operand too big. "\
3658 "Use .inst.w instead"));
3659 size = 0;
3660 }
3661 else
3662 {
3663 if (now_it.state == AUTOMATIC_IT_BLOCK)
3664 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3665 else
3666 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3667
3668 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3669 emit_thumb32_expr (exp);
3670 else
3671 emit_expr (exp, (unsigned int) size);
3672
3673 it_fsm_post_encode ();
3674 }
3675 }
3676 else
3677 as_bad (_("cannot determine Thumb instruction size. " \
3678 "Use .inst.n/.inst.w instead"));
3679 }
3680 else
3681 as_bad (_("constant expression required"));
3682
3683 return (size != 0);
3684}
3685
3686/* Like s_arm_elf_cons but do not use md_cons_align and
3687 set the mapping state to MAP_ARM/MAP_THUMB. */
3688
3689static void
3690s_arm_elf_inst (int nbytes)
3691{
3692 if (is_it_end_of_statement ())
3693 {
3694 demand_empty_rest_of_line ();
3695 return;
3696 }
3697
3698 /* Calling mapping_state () here will not change ARM/THUMB,
3699 but will ensure not to be in DATA state. */
3700
3701 if (thumb_mode)
3702 mapping_state (MAP_THUMB);
3703 else
3704 {
3705 if (nbytes != 0)
3706 {
3707 as_bad (_("width suffixes are invalid in ARM mode"));
3708 ignore_rest_of_line ();
3709 return;
3710 }
3711
3712 nbytes = 4;
3713
3714 mapping_state (MAP_ARM);
3715 }
3716
3717 do
3718 {
3719 expressionS exp;
3720
3721 expression (& exp);
3722
3723 if (! emit_insn (& exp, nbytes))
3724 {
3725 ignore_rest_of_line ();
3726 return;
3727 }
3728 }
3729 while (*input_line_pointer++ == ',');
3730
3731 /* Put terminator back into stream. */
3732 input_line_pointer --;
3733 demand_empty_rest_of_line ();
3734}
b99bd4ef 3735
c19d1205 3736/* Parse a .rel31 directive. */
b99bd4ef 3737
c19d1205
ZW
3738static void
3739s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3740{
3741 expressionS exp;
3742 char *p;
3743 valueT highbit;
b99bd4ef 3744
c19d1205
ZW
3745 highbit = 0;
3746 if (*input_line_pointer == '1')
3747 highbit = 0x80000000;
3748 else if (*input_line_pointer != '0')
3749 as_bad (_("expected 0 or 1"));
b99bd4ef 3750
c19d1205
ZW
3751 input_line_pointer++;
3752 if (*input_line_pointer != ',')
3753 as_bad (_("missing comma"));
3754 input_line_pointer++;
b99bd4ef 3755
c19d1205
ZW
3756#ifdef md_flush_pending_output
3757 md_flush_pending_output ();
3758#endif
b99bd4ef 3759
c19d1205
ZW
3760#ifdef md_cons_align
3761 md_cons_align (4);
3762#endif
b99bd4ef 3763
c19d1205 3764 mapping_state (MAP_DATA);
b99bd4ef 3765
c19d1205 3766 expression (&exp);
b99bd4ef 3767
c19d1205
ZW
3768 p = frag_more (4);
3769 md_number_to_chars (p, highbit, 4);
3770 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3771 BFD_RELOC_ARM_PREL31);
b99bd4ef 3772
c19d1205 3773 demand_empty_rest_of_line ();
b99bd4ef
NC
3774}
3775
c19d1205 3776/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3777
c19d1205 3778/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3779
c19d1205
ZW
3780static void
3781s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3782{
3783 demand_empty_rest_of_line ();
921e5f0a
PB
3784 if (unwind.proc_start)
3785 {
c921be7d 3786 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3787 return;
3788 }
3789
c19d1205
ZW
3790 /* Mark the start of the function. */
3791 unwind.proc_start = expr_build_dot ();
b99bd4ef 3792
c19d1205
ZW
3793 /* Reset the rest of the unwind info. */
3794 unwind.opcode_count = 0;
3795 unwind.table_entry = NULL;
3796 unwind.personality_routine = NULL;
3797 unwind.personality_index = -1;
3798 unwind.frame_size = 0;
3799 unwind.fp_offset = 0;
fdfde340 3800 unwind.fp_reg = REG_SP;
c19d1205
ZW
3801 unwind.fp_used = 0;
3802 unwind.sp_restored = 0;
3803}
b99bd4ef 3804
b99bd4ef 3805
c19d1205
ZW
3806/* Parse a handlerdata directive. Creates the exception handling table entry
3807 for the function. */
b99bd4ef 3808
c19d1205
ZW
3809static void
3810s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3811{
3812 demand_empty_rest_of_line ();
921e5f0a 3813 if (!unwind.proc_start)
c921be7d 3814 as_bad (MISSING_FNSTART);
921e5f0a 3815
c19d1205 3816 if (unwind.table_entry)
6decc662 3817 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3818
c19d1205
ZW
3819 create_unwind_entry (1);
3820}
a737bd4d 3821
c19d1205 3822/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3823
c19d1205
ZW
3824static void
3825s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3826{
3827 long where;
3828 char *ptr;
3829 valueT val;
940b5ce0 3830 unsigned int marked_pr_dependency;
f02232aa 3831
c19d1205 3832 demand_empty_rest_of_line ();
f02232aa 3833
921e5f0a
PB
3834 if (!unwind.proc_start)
3835 {
c921be7d 3836 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3837 return;
3838 }
3839
c19d1205
ZW
3840 /* Add eh table entry. */
3841 if (unwind.table_entry == NULL)
3842 val = create_unwind_entry (0);
3843 else
3844 val = 0;
f02232aa 3845
c19d1205
ZW
3846 /* Add index table entry. This is two words. */
3847 start_unwind_section (unwind.saved_seg, 1);
3848 frag_align (2, 0, 0);
3849 record_alignment (now_seg, 2);
b99bd4ef 3850
c19d1205 3851 ptr = frag_more (8);
5011093d 3852 memset (ptr, 0, 8);
c19d1205 3853 where = frag_now_fix () - 8;
f02232aa 3854
c19d1205
ZW
3855 /* Self relative offset of the function start. */
3856 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3857 BFD_RELOC_ARM_PREL31);
f02232aa 3858
c19d1205
ZW
3859 /* Indicate dependency on EHABI-defined personality routines to the
3860 linker, if it hasn't been done already. */
940b5ce0
DJ
3861 marked_pr_dependency
3862 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3863 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3864 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3865 {
5f4273c7
NC
3866 static const char *const name[] =
3867 {
3868 "__aeabi_unwind_cpp_pr0",
3869 "__aeabi_unwind_cpp_pr1",
3870 "__aeabi_unwind_cpp_pr2"
3871 };
c19d1205
ZW
3872 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3873 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3874 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3875 |= 1 << unwind.personality_index;
c19d1205 3876 }
f02232aa 3877
c19d1205
ZW
3878 if (val)
3879 /* Inline exception table entry. */
3880 md_number_to_chars (ptr + 4, val, 4);
3881 else
3882 /* Self relative offset of the table entry. */
3883 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3884 BFD_RELOC_ARM_PREL31);
f02232aa 3885
c19d1205
ZW
3886 /* Restore the original section. */
3887 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3888
3889 unwind.proc_start = NULL;
c19d1205 3890}
f02232aa 3891
f02232aa 3892
c19d1205 3893/* Parse an unwind_cantunwind directive. */
b99bd4ef 3894
c19d1205
ZW
3895static void
3896s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3897{
3898 demand_empty_rest_of_line ();
921e5f0a 3899 if (!unwind.proc_start)
c921be7d 3900 as_bad (MISSING_FNSTART);
921e5f0a 3901
c19d1205
ZW
3902 if (unwind.personality_routine || unwind.personality_index != -1)
3903 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3904
c19d1205
ZW
3905 unwind.personality_index = -2;
3906}
b99bd4ef 3907
b99bd4ef 3908
c19d1205 3909/* Parse a personalityindex directive. */
b99bd4ef 3910
c19d1205
ZW
3911static void
3912s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3913{
3914 expressionS exp;
b99bd4ef 3915
921e5f0a 3916 if (!unwind.proc_start)
c921be7d 3917 as_bad (MISSING_FNSTART);
921e5f0a 3918
c19d1205
ZW
3919 if (unwind.personality_routine || unwind.personality_index != -1)
3920 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3921
c19d1205 3922 expression (&exp);
b99bd4ef 3923
c19d1205
ZW
3924 if (exp.X_op != O_constant
3925 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3926 {
c19d1205
ZW
3927 as_bad (_("bad personality routine number"));
3928 ignore_rest_of_line ();
3929 return;
b99bd4ef
NC
3930 }
3931
c19d1205 3932 unwind.personality_index = exp.X_add_number;
b99bd4ef 3933
c19d1205
ZW
3934 demand_empty_rest_of_line ();
3935}
e16bb312 3936
e16bb312 3937
c19d1205 3938/* Parse a personality directive. */
e16bb312 3939
c19d1205
ZW
3940static void
3941s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3942{
3943 char *name, *p, c;
a737bd4d 3944
921e5f0a 3945 if (!unwind.proc_start)
c921be7d 3946 as_bad (MISSING_FNSTART);
921e5f0a 3947
c19d1205
ZW
3948 if (unwind.personality_routine || unwind.personality_index != -1)
3949 as_bad (_("duplicate .personality directive"));
a737bd4d 3950
d02603dc 3951 c = get_symbol_name (& name);
c19d1205 3952 p = input_line_pointer;
d02603dc
NC
3953 if (c == '"')
3954 ++ input_line_pointer;
c19d1205
ZW
3955 unwind.personality_routine = symbol_find_or_make (name);
3956 *p = c;
3957 demand_empty_rest_of_line ();
3958}
e16bb312 3959
e16bb312 3960
c19d1205 3961/* Parse a directive saving core registers. */
e16bb312 3962
c19d1205
ZW
3963static void
3964s_arm_unwind_save_core (void)
e16bb312 3965{
c19d1205
ZW
3966 valueT op;
3967 long range;
3968 int n;
e16bb312 3969
c19d1205
ZW
3970 range = parse_reg_list (&input_line_pointer);
3971 if (range == FAIL)
e16bb312 3972 {
c19d1205
ZW
3973 as_bad (_("expected register list"));
3974 ignore_rest_of_line ();
3975 return;
3976 }
e16bb312 3977
c19d1205 3978 demand_empty_rest_of_line ();
e16bb312 3979
c19d1205
ZW
3980 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3981 into .unwind_save {..., sp...}. We aren't bothered about the value of
3982 ip because it is clobbered by calls. */
3983 if (unwind.sp_restored && unwind.fp_reg == 12
3984 && (range & 0x3000) == 0x1000)
3985 {
3986 unwind.opcode_count--;
3987 unwind.sp_restored = 0;
3988 range = (range | 0x2000) & ~0x1000;
3989 unwind.pending_offset = 0;
3990 }
e16bb312 3991
01ae4198
DJ
3992 /* Pop r4-r15. */
3993 if (range & 0xfff0)
c19d1205 3994 {
01ae4198
DJ
3995 /* See if we can use the short opcodes. These pop a block of up to 8
3996 registers starting with r4, plus maybe r14. */
3997 for (n = 0; n < 8; n++)
3998 {
3999 /* Break at the first non-saved register. */
4000 if ((range & (1 << (n + 4))) == 0)
4001 break;
4002 }
4003 /* See if there are any other bits set. */
4004 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4005 {
4006 /* Use the long form. */
4007 op = 0x8000 | ((range >> 4) & 0xfff);
4008 add_unwind_opcode (op, 2);
4009 }
0dd132b6 4010 else
01ae4198
DJ
4011 {
4012 /* Use the short form. */
4013 if (range & 0x4000)
4014 op = 0xa8; /* Pop r14. */
4015 else
4016 op = 0xa0; /* Do not pop r14. */
4017 op |= (n - 1);
4018 add_unwind_opcode (op, 1);
4019 }
c19d1205 4020 }
0dd132b6 4021
c19d1205
ZW
4022 /* Pop r0-r3. */
4023 if (range & 0xf)
4024 {
4025 op = 0xb100 | (range & 0xf);
4026 add_unwind_opcode (op, 2);
0dd132b6
NC
4027 }
4028
c19d1205
ZW
4029 /* Record the number of bytes pushed. */
4030 for (n = 0; n < 16; n++)
4031 {
4032 if (range & (1 << n))
4033 unwind.frame_size += 4;
4034 }
0dd132b6
NC
4035}
4036
c19d1205
ZW
4037
4038/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4039
4040static void
c19d1205 4041s_arm_unwind_save_fpa (int reg)
b99bd4ef 4042{
c19d1205
ZW
4043 expressionS exp;
4044 int num_regs;
4045 valueT op;
b99bd4ef 4046
c19d1205
ZW
4047 /* Get Number of registers to transfer. */
4048 if (skip_past_comma (&input_line_pointer) != FAIL)
4049 expression (&exp);
4050 else
4051 exp.X_op = O_illegal;
b99bd4ef 4052
c19d1205 4053 if (exp.X_op != O_constant)
b99bd4ef 4054 {
c19d1205
ZW
4055 as_bad (_("expected , <constant>"));
4056 ignore_rest_of_line ();
b99bd4ef
NC
4057 return;
4058 }
4059
c19d1205
ZW
4060 num_regs = exp.X_add_number;
4061
4062 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4063 {
c19d1205
ZW
4064 as_bad (_("number of registers must be in the range [1:4]"));
4065 ignore_rest_of_line ();
b99bd4ef
NC
4066 return;
4067 }
4068
c19d1205 4069 demand_empty_rest_of_line ();
b99bd4ef 4070
c19d1205
ZW
4071 if (reg == 4)
4072 {
4073 /* Short form. */
4074 op = 0xb4 | (num_regs - 1);
4075 add_unwind_opcode (op, 1);
4076 }
b99bd4ef
NC
4077 else
4078 {
c19d1205
ZW
4079 /* Long form. */
4080 op = 0xc800 | (reg << 4) | (num_regs - 1);
4081 add_unwind_opcode (op, 2);
b99bd4ef 4082 }
c19d1205 4083 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4084}
4085
c19d1205 4086
fa073d69
MS
4087/* Parse a directive saving VFP registers for ARMv6 and above. */
4088
4089static void
4090s_arm_unwind_save_vfp_armv6 (void)
4091{
4092 int count;
4093 unsigned int start;
4094 valueT op;
4095 int num_vfpv3_regs = 0;
4096 int num_regs_below_16;
4097
4098 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4099 if (count == FAIL)
4100 {
4101 as_bad (_("expected register list"));
4102 ignore_rest_of_line ();
4103 return;
4104 }
4105
4106 demand_empty_rest_of_line ();
4107
4108 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4109 than FSTMX/FLDMX-style ones). */
4110
4111 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4112 if (start >= 16)
4113 num_vfpv3_regs = count;
4114 else if (start + count > 16)
4115 num_vfpv3_regs = start + count - 16;
4116
4117 if (num_vfpv3_regs > 0)
4118 {
4119 int start_offset = start > 16 ? start - 16 : 0;
4120 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4121 add_unwind_opcode (op, 2);
4122 }
4123
4124 /* Generate opcode for registers numbered in the range 0 .. 15. */
4125 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4126 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4127 if (num_regs_below_16 > 0)
4128 {
4129 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4130 add_unwind_opcode (op, 2);
4131 }
4132
4133 unwind.frame_size += count * 8;
4134}
4135
4136
4137/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4138
4139static void
c19d1205 4140s_arm_unwind_save_vfp (void)
b99bd4ef 4141{
c19d1205 4142 int count;
ca3f61f7 4143 unsigned int reg;
c19d1205 4144 valueT op;
b99bd4ef 4145
5287ad62 4146 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4147 if (count == FAIL)
b99bd4ef 4148 {
c19d1205
ZW
4149 as_bad (_("expected register list"));
4150 ignore_rest_of_line ();
b99bd4ef
NC
4151 return;
4152 }
4153
c19d1205 4154 demand_empty_rest_of_line ();
b99bd4ef 4155
c19d1205 4156 if (reg == 8)
b99bd4ef 4157 {
c19d1205
ZW
4158 /* Short form. */
4159 op = 0xb8 | (count - 1);
4160 add_unwind_opcode (op, 1);
b99bd4ef 4161 }
c19d1205 4162 else
b99bd4ef 4163 {
c19d1205
ZW
4164 /* Long form. */
4165 op = 0xb300 | (reg << 4) | (count - 1);
4166 add_unwind_opcode (op, 2);
b99bd4ef 4167 }
c19d1205
ZW
4168 unwind.frame_size += count * 8 + 4;
4169}
b99bd4ef 4170
b99bd4ef 4171
c19d1205
ZW
4172/* Parse a directive saving iWMMXt data registers. */
4173
4174static void
4175s_arm_unwind_save_mmxwr (void)
4176{
4177 int reg;
4178 int hi_reg;
4179 int i;
4180 unsigned mask = 0;
4181 valueT op;
b99bd4ef 4182
c19d1205
ZW
4183 if (*input_line_pointer == '{')
4184 input_line_pointer++;
b99bd4ef 4185
c19d1205 4186 do
b99bd4ef 4187 {
dcbf9037 4188 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4189
c19d1205 4190 if (reg == FAIL)
b99bd4ef 4191 {
9b7132d3 4192 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4193 goto error;
b99bd4ef
NC
4194 }
4195
c19d1205
ZW
4196 if (mask >> reg)
4197 as_tsktsk (_("register list not in ascending order"));
4198 mask |= 1 << reg;
b99bd4ef 4199
c19d1205
ZW
4200 if (*input_line_pointer == '-')
4201 {
4202 input_line_pointer++;
dcbf9037 4203 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4204 if (hi_reg == FAIL)
4205 {
9b7132d3 4206 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4207 goto error;
4208 }
4209 else if (reg >= hi_reg)
4210 {
4211 as_bad (_("bad register range"));
4212 goto error;
4213 }
4214 for (; reg < hi_reg; reg++)
4215 mask |= 1 << reg;
4216 }
4217 }
4218 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4219
d996d970 4220 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4221
c19d1205 4222 demand_empty_rest_of_line ();
b99bd4ef 4223
708587a4 4224 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4225 the list. */
4226 flush_pending_unwind ();
b99bd4ef 4227
c19d1205 4228 for (i = 0; i < 16; i++)
b99bd4ef 4229 {
c19d1205
ZW
4230 if (mask & (1 << i))
4231 unwind.frame_size += 8;
b99bd4ef
NC
4232 }
4233
c19d1205
ZW
4234 /* Attempt to combine with a previous opcode. We do this because gcc
4235 likes to output separate unwind directives for a single block of
4236 registers. */
4237 if (unwind.opcode_count > 0)
b99bd4ef 4238 {
c19d1205
ZW
4239 i = unwind.opcodes[unwind.opcode_count - 1];
4240 if ((i & 0xf8) == 0xc0)
4241 {
4242 i &= 7;
4243 /* Only merge if the blocks are contiguous. */
4244 if (i < 6)
4245 {
4246 if ((mask & 0xfe00) == (1 << 9))
4247 {
4248 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4249 unwind.opcode_count--;
4250 }
4251 }
4252 else if (i == 6 && unwind.opcode_count >= 2)
4253 {
4254 i = unwind.opcodes[unwind.opcode_count - 2];
4255 reg = i >> 4;
4256 i &= 0xf;
b99bd4ef 4257
c19d1205
ZW
4258 op = 0xffff << (reg - 1);
4259 if (reg > 0
87a1fd79 4260 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4261 {
4262 op = (1 << (reg + i + 1)) - 1;
4263 op &= ~((1 << reg) - 1);
4264 mask |= op;
4265 unwind.opcode_count -= 2;
4266 }
4267 }
4268 }
b99bd4ef
NC
4269 }
4270
c19d1205
ZW
4271 hi_reg = 15;
4272 /* We want to generate opcodes in the order the registers have been
4273 saved, ie. descending order. */
4274 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4275 {
c19d1205
ZW
4276 /* Save registers in blocks. */
4277 if (reg < 0
4278 || !(mask & (1 << reg)))
4279 {
4280 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4281 preceding block. */
c19d1205
ZW
4282 if (reg != hi_reg)
4283 {
4284 if (reg == 9)
4285 {
4286 /* Short form. */
4287 op = 0xc0 | (hi_reg - 10);
4288 add_unwind_opcode (op, 1);
4289 }
4290 else
4291 {
4292 /* Long form. */
4293 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4294 add_unwind_opcode (op, 2);
4295 }
4296 }
4297 hi_reg = reg - 1;
4298 }
b99bd4ef
NC
4299 }
4300
c19d1205
ZW
4301 return;
4302error:
4303 ignore_rest_of_line ();
b99bd4ef
NC
4304}
4305
4306static void
c19d1205 4307s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4308{
c19d1205
ZW
4309 int reg;
4310 int hi_reg;
4311 unsigned mask = 0;
4312 valueT op;
b99bd4ef 4313
c19d1205
ZW
4314 if (*input_line_pointer == '{')
4315 input_line_pointer++;
b99bd4ef 4316
477330fc
RM
4317 skip_whitespace (input_line_pointer);
4318
c19d1205 4319 do
b99bd4ef 4320 {
dcbf9037 4321 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4322
c19d1205
ZW
4323 if (reg == FAIL)
4324 {
9b7132d3 4325 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4326 goto error;
4327 }
b99bd4ef 4328
c19d1205
ZW
4329 reg -= 8;
4330 if (mask >> reg)
4331 as_tsktsk (_("register list not in ascending order"));
4332 mask |= 1 << reg;
b99bd4ef 4333
c19d1205
ZW
4334 if (*input_line_pointer == '-')
4335 {
4336 input_line_pointer++;
dcbf9037 4337 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4338 if (hi_reg == FAIL)
4339 {
9b7132d3 4340 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4341 goto error;
4342 }
4343 else if (reg >= hi_reg)
4344 {
4345 as_bad (_("bad register range"));
4346 goto error;
4347 }
4348 for (; reg < hi_reg; reg++)
4349 mask |= 1 << reg;
4350 }
b99bd4ef 4351 }
c19d1205 4352 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4353
d996d970 4354 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4355
c19d1205
ZW
4356 demand_empty_rest_of_line ();
4357
708587a4 4358 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4359 the list. */
4360 flush_pending_unwind ();
b99bd4ef 4361
c19d1205 4362 for (reg = 0; reg < 16; reg++)
b99bd4ef 4363 {
c19d1205
ZW
4364 if (mask & (1 << reg))
4365 unwind.frame_size += 4;
b99bd4ef 4366 }
c19d1205
ZW
4367 op = 0xc700 | mask;
4368 add_unwind_opcode (op, 2);
4369 return;
4370error:
4371 ignore_rest_of_line ();
b99bd4ef
NC
4372}
4373
c19d1205 4374
fa073d69
MS
4375/* Parse an unwind_save directive.
4376 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4377
b99bd4ef 4378static void
fa073d69 4379s_arm_unwind_save (int arch_v6)
b99bd4ef 4380{
c19d1205
ZW
4381 char *peek;
4382 struct reg_entry *reg;
4383 bfd_boolean had_brace = FALSE;
b99bd4ef 4384
921e5f0a 4385 if (!unwind.proc_start)
c921be7d 4386 as_bad (MISSING_FNSTART);
921e5f0a 4387
c19d1205
ZW
4388 /* Figure out what sort of save we have. */
4389 peek = input_line_pointer;
b99bd4ef 4390
c19d1205 4391 if (*peek == '{')
b99bd4ef 4392 {
c19d1205
ZW
4393 had_brace = TRUE;
4394 peek++;
b99bd4ef
NC
4395 }
4396
c19d1205 4397 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4398
c19d1205 4399 if (!reg)
b99bd4ef 4400 {
c19d1205
ZW
4401 as_bad (_("register expected"));
4402 ignore_rest_of_line ();
b99bd4ef
NC
4403 return;
4404 }
4405
c19d1205 4406 switch (reg->type)
b99bd4ef 4407 {
c19d1205
ZW
4408 case REG_TYPE_FN:
4409 if (had_brace)
4410 {
4411 as_bad (_("FPA .unwind_save does not take a register list"));
4412 ignore_rest_of_line ();
4413 return;
4414 }
93ac2687 4415 input_line_pointer = peek;
c19d1205 4416 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4417 return;
c19d1205 4418
1f5afe1c
NC
4419 case REG_TYPE_RN:
4420 s_arm_unwind_save_core ();
4421 return;
4422
fa073d69
MS
4423 case REG_TYPE_VFD:
4424 if (arch_v6)
477330fc 4425 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4426 else
477330fc 4427 s_arm_unwind_save_vfp ();
fa073d69 4428 return;
1f5afe1c
NC
4429
4430 case REG_TYPE_MMXWR:
4431 s_arm_unwind_save_mmxwr ();
4432 return;
4433
4434 case REG_TYPE_MMXWCG:
4435 s_arm_unwind_save_mmxwcg ();
4436 return;
c19d1205
ZW
4437
4438 default:
4439 as_bad (_(".unwind_save does not support this kind of register"));
4440 ignore_rest_of_line ();
b99bd4ef 4441 }
c19d1205 4442}
b99bd4ef 4443
b99bd4ef 4444
c19d1205
ZW
4445/* Parse an unwind_movsp directive. */
4446
4447static void
4448s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4449{
4450 int reg;
4451 valueT op;
4fa3602b 4452 int offset;
c19d1205 4453
921e5f0a 4454 if (!unwind.proc_start)
c921be7d 4455 as_bad (MISSING_FNSTART);
921e5f0a 4456
dcbf9037 4457 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4458 if (reg == FAIL)
b99bd4ef 4459 {
9b7132d3 4460 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4461 ignore_rest_of_line ();
b99bd4ef
NC
4462 return;
4463 }
4fa3602b
PB
4464
4465 /* Optional constant. */
4466 if (skip_past_comma (&input_line_pointer) != FAIL)
4467 {
4468 if (immediate_for_directive (&offset) == FAIL)
4469 return;
4470 }
4471 else
4472 offset = 0;
4473
c19d1205 4474 demand_empty_rest_of_line ();
b99bd4ef 4475
c19d1205 4476 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4477 {
c19d1205 4478 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4479 return;
4480 }
4481
c19d1205
ZW
4482 if (unwind.fp_reg != REG_SP)
4483 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4484
c19d1205
ZW
4485 /* Generate opcode to restore the value. */
4486 op = 0x90 | reg;
4487 add_unwind_opcode (op, 1);
4488
4489 /* Record the information for later. */
4490 unwind.fp_reg = reg;
4fa3602b 4491 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4492 unwind.sp_restored = 1;
b05fe5cf
ZW
4493}
4494
c19d1205
ZW
4495/* Parse an unwind_pad directive. */
4496
b05fe5cf 4497static void
c19d1205 4498s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4499{
c19d1205 4500 int offset;
b05fe5cf 4501
921e5f0a 4502 if (!unwind.proc_start)
c921be7d 4503 as_bad (MISSING_FNSTART);
921e5f0a 4504
c19d1205
ZW
4505 if (immediate_for_directive (&offset) == FAIL)
4506 return;
b99bd4ef 4507
c19d1205
ZW
4508 if (offset & 3)
4509 {
4510 as_bad (_("stack increment must be multiple of 4"));
4511 ignore_rest_of_line ();
4512 return;
4513 }
b99bd4ef 4514
c19d1205
ZW
4515 /* Don't generate any opcodes, just record the details for later. */
4516 unwind.frame_size += offset;
4517 unwind.pending_offset += offset;
4518
4519 demand_empty_rest_of_line ();
4520}
4521
4522/* Parse an unwind_setfp directive. */
4523
4524static void
4525s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4526{
c19d1205
ZW
4527 int sp_reg;
4528 int fp_reg;
4529 int offset;
4530
921e5f0a 4531 if (!unwind.proc_start)
c921be7d 4532 as_bad (MISSING_FNSTART);
921e5f0a 4533
dcbf9037 4534 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4535 if (skip_past_comma (&input_line_pointer) == FAIL)
4536 sp_reg = FAIL;
4537 else
dcbf9037 4538 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4539
c19d1205
ZW
4540 if (fp_reg == FAIL || sp_reg == FAIL)
4541 {
4542 as_bad (_("expected <reg>, <reg>"));
4543 ignore_rest_of_line ();
4544 return;
4545 }
b99bd4ef 4546
c19d1205
ZW
4547 /* Optional constant. */
4548 if (skip_past_comma (&input_line_pointer) != FAIL)
4549 {
4550 if (immediate_for_directive (&offset) == FAIL)
4551 return;
4552 }
4553 else
4554 offset = 0;
a737bd4d 4555
c19d1205 4556 demand_empty_rest_of_line ();
a737bd4d 4557
fdfde340 4558 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4559 {
c19d1205
ZW
4560 as_bad (_("register must be either sp or set by a previous"
4561 "unwind_movsp directive"));
4562 return;
a737bd4d
NC
4563 }
4564
c19d1205
ZW
4565 /* Don't generate any opcodes, just record the information for later. */
4566 unwind.fp_reg = fp_reg;
4567 unwind.fp_used = 1;
fdfde340 4568 if (sp_reg == REG_SP)
c19d1205
ZW
4569 unwind.fp_offset = unwind.frame_size - offset;
4570 else
4571 unwind.fp_offset -= offset;
a737bd4d
NC
4572}
4573
c19d1205
ZW
4574/* Parse an unwind_raw directive. */
4575
4576static void
4577s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4578{
c19d1205 4579 expressionS exp;
708587a4 4580 /* This is an arbitrary limit. */
c19d1205
ZW
4581 unsigned char op[16];
4582 int count;
a737bd4d 4583
921e5f0a 4584 if (!unwind.proc_start)
c921be7d 4585 as_bad (MISSING_FNSTART);
921e5f0a 4586
c19d1205
ZW
4587 expression (&exp);
4588 if (exp.X_op == O_constant
4589 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4590 {
c19d1205
ZW
4591 unwind.frame_size += exp.X_add_number;
4592 expression (&exp);
4593 }
4594 else
4595 exp.X_op = O_illegal;
a737bd4d 4596
c19d1205
ZW
4597 if (exp.X_op != O_constant)
4598 {
4599 as_bad (_("expected <offset>, <opcode>"));
4600 ignore_rest_of_line ();
4601 return;
4602 }
a737bd4d 4603
c19d1205 4604 count = 0;
a737bd4d 4605
c19d1205
ZW
4606 /* Parse the opcode. */
4607 for (;;)
4608 {
4609 if (count >= 16)
4610 {
4611 as_bad (_("unwind opcode too long"));
4612 ignore_rest_of_line ();
a737bd4d 4613 }
c19d1205 4614 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4615 {
c19d1205
ZW
4616 as_bad (_("invalid unwind opcode"));
4617 ignore_rest_of_line ();
4618 return;
a737bd4d 4619 }
c19d1205 4620 op[count++] = exp.X_add_number;
a737bd4d 4621
c19d1205
ZW
4622 /* Parse the next byte. */
4623 if (skip_past_comma (&input_line_pointer) == FAIL)
4624 break;
a737bd4d 4625
c19d1205
ZW
4626 expression (&exp);
4627 }
b99bd4ef 4628
c19d1205
ZW
4629 /* Add the opcode bytes in reverse order. */
4630 while (count--)
4631 add_unwind_opcode (op[count], 1);
b99bd4ef 4632
c19d1205 4633 demand_empty_rest_of_line ();
b99bd4ef 4634}
ee065d83
PB
4635
4636
4637/* Parse a .eabi_attribute directive. */
4638
4639static void
4640s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4641{
0420f52b 4642 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4643
4644 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4645 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4646}
4647
0855e32b
NS
4648/* Emit a tls fix for the symbol. */
4649
4650static void
4651s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4652{
4653 char *p;
4654 expressionS exp;
4655#ifdef md_flush_pending_output
4656 md_flush_pending_output ();
4657#endif
4658
4659#ifdef md_cons_align
4660 md_cons_align (4);
4661#endif
4662
4663 /* Since we're just labelling the code, there's no need to define a
4664 mapping symbol. */
4665 expression (&exp);
4666 p = obstack_next_free (&frchain_now->frch_obstack);
4667 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4668 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4669 : BFD_RELOC_ARM_TLS_DESCSEQ);
4670}
cdf9ccec 4671#endif /* OBJ_ELF */
0855e32b 4672
ee065d83 4673static void s_arm_arch (int);
7a1d4c38 4674static void s_arm_object_arch (int);
ee065d83
PB
4675static void s_arm_cpu (int);
4676static void s_arm_fpu (int);
69133863 4677static void s_arm_arch_extension (int);
b99bd4ef 4678
f0927246
NC
4679#ifdef TE_PE
4680
4681static void
5f4273c7 4682pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4683{
4684 expressionS exp;
4685
4686 do
4687 {
4688 expression (&exp);
4689 if (exp.X_op == O_symbol)
4690 exp.X_op = O_secrel;
4691
4692 emit_expr (&exp, 4);
4693 }
4694 while (*input_line_pointer++ == ',');
4695
4696 input_line_pointer--;
4697 demand_empty_rest_of_line ();
4698}
4699#endif /* TE_PE */
4700
c19d1205
ZW
4701/* This table describes all the machine specific pseudo-ops the assembler
4702 has to support. The fields are:
4703 pseudo-op name without dot
4704 function to call to execute this pseudo-op
4705 Integer arg to pass to the function. */
b99bd4ef 4706
c19d1205 4707const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4708{
c19d1205
ZW
4709 /* Never called because '.req' does not start a line. */
4710 { "req", s_req, 0 },
dcbf9037
JB
4711 /* Following two are likewise never called. */
4712 { "dn", s_dn, 0 },
4713 { "qn", s_qn, 0 },
c19d1205
ZW
4714 { "unreq", s_unreq, 0 },
4715 { "bss", s_bss, 0 },
db2ed2e0 4716 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4717 { "arm", s_arm, 0 },
4718 { "thumb", s_thumb, 0 },
4719 { "code", s_code, 0 },
4720 { "force_thumb", s_force_thumb, 0 },
4721 { "thumb_func", s_thumb_func, 0 },
4722 { "thumb_set", s_thumb_set, 0 },
4723 { "even", s_even, 0 },
4724 { "ltorg", s_ltorg, 0 },
4725 { "pool", s_ltorg, 0 },
4726 { "syntax", s_syntax, 0 },
8463be01
PB
4727 { "cpu", s_arm_cpu, 0 },
4728 { "arch", s_arm_arch, 0 },
7a1d4c38 4729 { "object_arch", s_arm_object_arch, 0 },
8463be01 4730 { "fpu", s_arm_fpu, 0 },
69133863 4731 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4732#ifdef OBJ_ELF
c921be7d
NC
4733 { "word", s_arm_elf_cons, 4 },
4734 { "long", s_arm_elf_cons, 4 },
4735 { "inst.n", s_arm_elf_inst, 2 },
4736 { "inst.w", s_arm_elf_inst, 4 },
4737 { "inst", s_arm_elf_inst, 0 },
4738 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4739 { "fnstart", s_arm_unwind_fnstart, 0 },
4740 { "fnend", s_arm_unwind_fnend, 0 },
4741 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4742 { "personality", s_arm_unwind_personality, 0 },
4743 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4744 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4745 { "save", s_arm_unwind_save, 0 },
fa073d69 4746 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4747 { "movsp", s_arm_unwind_movsp, 0 },
4748 { "pad", s_arm_unwind_pad, 0 },
4749 { "setfp", s_arm_unwind_setfp, 0 },
4750 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4751 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4752 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4753#else
4754 { "word", cons, 4},
f0927246
NC
4755
4756 /* These are used for dwarf. */
4757 {"2byte", cons, 2},
4758 {"4byte", cons, 4},
4759 {"8byte", cons, 8},
4760 /* These are used for dwarf2. */
4761 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4762 { "loc", dwarf2_directive_loc, 0 },
4763 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4764#endif
4765 { "extend", float_cons, 'x' },
4766 { "ldouble", float_cons, 'x' },
4767 { "packed", float_cons, 'p' },
f0927246
NC
4768#ifdef TE_PE
4769 {"secrel32", pe_directive_secrel, 0},
4770#endif
2e6976a8
DG
4771
4772 /* These are for compatibility with CodeComposer Studio. */
4773 {"ref", s_ccs_ref, 0},
4774 {"def", s_ccs_def, 0},
4775 {"asmfunc", s_ccs_asmfunc, 0},
4776 {"endasmfunc", s_ccs_endasmfunc, 0},
4777
c19d1205
ZW
4778 { 0, 0, 0 }
4779};
4780\f
4781/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4782
c19d1205
ZW
4783/* Generic immediate-value read function for use in insn parsing.
4784 STR points to the beginning of the immediate (the leading #);
4785 VAL receives the value; if the value is outside [MIN, MAX]
4786 issue an error. PREFIX_OPT is true if the immediate prefix is
4787 optional. */
b99bd4ef 4788
c19d1205
ZW
4789static int
4790parse_immediate (char **str, int *val, int min, int max,
4791 bfd_boolean prefix_opt)
4792{
4793 expressionS exp;
0198d5e6 4794
c19d1205
ZW
4795 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4796 if (exp.X_op != O_constant)
b99bd4ef 4797 {
c19d1205
ZW
4798 inst.error = _("constant expression required");
4799 return FAIL;
4800 }
b99bd4ef 4801
c19d1205
ZW
4802 if (exp.X_add_number < min || exp.X_add_number > max)
4803 {
4804 inst.error = _("immediate value out of range");
4805 return FAIL;
4806 }
b99bd4ef 4807
c19d1205
ZW
4808 *val = exp.X_add_number;
4809 return SUCCESS;
4810}
b99bd4ef 4811
5287ad62 4812/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4813 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4814 instructions. Puts the result directly in inst.operands[i]. */
4815
4816static int
8335d6aa
JW
4817parse_big_immediate (char **str, int i, expressionS *in_exp,
4818 bfd_boolean allow_symbol_p)
5287ad62
JB
4819{
4820 expressionS exp;
8335d6aa 4821 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4822 char *ptr = *str;
4823
8335d6aa 4824 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4825
8335d6aa 4826 if (exp_p->X_op == O_constant)
036dc3f7 4827 {
8335d6aa 4828 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4829 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4830 O_constant. We have to be careful not to break compilation for
4831 32-bit X_add_number, though. */
8335d6aa 4832 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4833 {
8335d6aa
JW
4834 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4835 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4836 & 0xffffffff);
036dc3f7
PB
4837 inst.operands[i].regisimm = 1;
4838 }
4839 }
8335d6aa
JW
4840 else if (exp_p->X_op == O_big
4841 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4842 {
4843 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4844
5287ad62 4845 /* Bignums have their least significant bits in
477330fc
RM
4846 generic_bignum[0]. Make sure we put 32 bits in imm and
4847 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4848 gas_assert (parts != 0);
95b75c01
NC
4849
4850 /* Make sure that the number is not too big.
4851 PR 11972: Bignums can now be sign-extended to the
4852 size of a .octa so check that the out of range bits
4853 are all zero or all one. */
8335d6aa 4854 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4855 {
4856 LITTLENUM_TYPE m = -1;
4857
4858 if (generic_bignum[parts * 2] != 0
4859 && generic_bignum[parts * 2] != m)
4860 return FAIL;
4861
8335d6aa 4862 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4863 if (generic_bignum[j] != generic_bignum[j-1])
4864 return FAIL;
4865 }
4866
5287ad62
JB
4867 inst.operands[i].imm = 0;
4868 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4869 inst.operands[i].imm |= generic_bignum[idx]
4870 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4871 inst.operands[i].reg = 0;
4872 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4873 inst.operands[i].reg |= generic_bignum[idx]
4874 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4875 inst.operands[i].regisimm = 1;
4876 }
8335d6aa 4877 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4878 return FAIL;
5f4273c7 4879
5287ad62
JB
4880 *str = ptr;
4881
4882 return SUCCESS;
4883}
4884
c19d1205
ZW
4885/* Returns the pseudo-register number of an FPA immediate constant,
4886 or FAIL if there isn't a valid constant here. */
b99bd4ef 4887
c19d1205
ZW
4888static int
4889parse_fpa_immediate (char ** str)
4890{
4891 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4892 char * save_in;
4893 expressionS exp;
4894 int i;
4895 int j;
b99bd4ef 4896
c19d1205
ZW
4897 /* First try and match exact strings, this is to guarantee
4898 that some formats will work even for cross assembly. */
b99bd4ef 4899
c19d1205
ZW
4900 for (i = 0; fp_const[i]; i++)
4901 {
4902 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4903 {
c19d1205 4904 char *start = *str;
b99bd4ef 4905
c19d1205
ZW
4906 *str += strlen (fp_const[i]);
4907 if (is_end_of_line[(unsigned char) **str])
4908 return i + 8;
4909 *str = start;
4910 }
4911 }
b99bd4ef 4912
c19d1205
ZW
4913 /* Just because we didn't get a match doesn't mean that the constant
4914 isn't valid, just that it is in a format that we don't
4915 automatically recognize. Try parsing it with the standard
4916 expression routines. */
b99bd4ef 4917
c19d1205 4918 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4919
c19d1205
ZW
4920 /* Look for a raw floating point number. */
4921 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4922 && is_end_of_line[(unsigned char) *save_in])
4923 {
4924 for (i = 0; i < NUM_FLOAT_VALS; i++)
4925 {
4926 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4927 {
c19d1205
ZW
4928 if (words[j] != fp_values[i][j])
4929 break;
b99bd4ef
NC
4930 }
4931
c19d1205 4932 if (j == MAX_LITTLENUMS)
b99bd4ef 4933 {
c19d1205
ZW
4934 *str = save_in;
4935 return i + 8;
b99bd4ef
NC
4936 }
4937 }
4938 }
b99bd4ef 4939
c19d1205
ZW
4940 /* Try and parse a more complex expression, this will probably fail
4941 unless the code uses a floating point prefix (eg "0f"). */
4942 save_in = input_line_pointer;
4943 input_line_pointer = *str;
4944 if (expression (&exp) == absolute_section
4945 && exp.X_op == O_big
4946 && exp.X_add_number < 0)
4947 {
4948 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4949 Ditto for 15. */
ba592044
AM
4950#define X_PRECISION 5
4951#define E_PRECISION 15L
4952 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4953 {
4954 for (i = 0; i < NUM_FLOAT_VALS; i++)
4955 {
4956 for (j = 0; j < MAX_LITTLENUMS; j++)
4957 {
4958 if (words[j] != fp_values[i][j])
4959 break;
4960 }
b99bd4ef 4961
c19d1205
ZW
4962 if (j == MAX_LITTLENUMS)
4963 {
4964 *str = input_line_pointer;
4965 input_line_pointer = save_in;
4966 return i + 8;
4967 }
4968 }
4969 }
b99bd4ef
NC
4970 }
4971
c19d1205
ZW
4972 *str = input_line_pointer;
4973 input_line_pointer = save_in;
4974 inst.error = _("invalid FPA immediate expression");
4975 return FAIL;
b99bd4ef
NC
4976}
4977
136da414
JB
4978/* Returns 1 if a number has "quarter-precision" float format
4979 0baBbbbbbc defgh000 00000000 00000000. */
4980
4981static int
4982is_quarter_float (unsigned imm)
4983{
4984 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4985 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4986}
4987
aacf0b33
KT
4988
4989/* Detect the presence of a floating point or integer zero constant,
4990 i.e. #0.0 or #0. */
4991
4992static bfd_boolean
4993parse_ifimm_zero (char **in)
4994{
4995 int error_code;
4996
4997 if (!is_immediate_prefix (**in))
3c6452ae
TP
4998 {
4999 /* In unified syntax, all prefixes are optional. */
5000 if (!unified_syntax)
5001 return FALSE;
5002 }
5003 else
5004 ++*in;
0900a05b
JW
5005
5006 /* Accept #0x0 as a synonym for #0. */
5007 if (strncmp (*in, "0x", 2) == 0)
5008 {
5009 int val;
5010 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5011 return FALSE;
5012 return TRUE;
5013 }
5014
aacf0b33
KT
5015 error_code = atof_generic (in, ".", EXP_CHARS,
5016 &generic_floating_point_number);
5017
5018 if (!error_code
5019 && generic_floating_point_number.sign == '+'
5020 && (generic_floating_point_number.low
5021 > generic_floating_point_number.leader))
5022 return TRUE;
5023
5024 return FALSE;
5025}
5026
136da414
JB
5027/* Parse an 8-bit "quarter-precision" floating point number of the form:
5028 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5029 The zero and minus-zero cases need special handling, since they can't be
5030 encoded in the "quarter-precision" float format, but can nonetheless be
5031 loaded as integer constants. */
136da414
JB
5032
5033static unsigned
5034parse_qfloat_immediate (char **ccp, int *immed)
5035{
5036 char *str = *ccp;
c96612cc 5037 char *fpnum;
136da414 5038 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5039 int found_fpchar = 0;
5f4273c7 5040
136da414 5041 skip_past_char (&str, '#');
5f4273c7 5042
c96612cc
JB
5043 /* We must not accidentally parse an integer as a floating-point number. Make
5044 sure that the value we parse is not an integer by checking for special
5045 characters '.' or 'e'.
5046 FIXME: This is a horrible hack, but doing better is tricky because type
5047 information isn't in a very usable state at parse time. */
5048 fpnum = str;
5049 skip_whitespace (fpnum);
5050
5051 if (strncmp (fpnum, "0x", 2) == 0)
5052 return FAIL;
5053 else
5054 {
5055 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5056 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5057 {
5058 found_fpchar = 1;
5059 break;
5060 }
c96612cc
JB
5061
5062 if (!found_fpchar)
477330fc 5063 return FAIL;
c96612cc 5064 }
5f4273c7 5065
136da414
JB
5066 if ((str = atof_ieee (str, 's', words)) != NULL)
5067 {
5068 unsigned fpword = 0;
5069 int i;
5f4273c7 5070
136da414
JB
5071 /* Our FP word must be 32 bits (single-precision FP). */
5072 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5073 {
5074 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5075 fpword |= words[i];
5076 }
5f4273c7 5077
c96612cc 5078 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5079 *immed = fpword;
136da414 5080 else
477330fc 5081 return FAIL;
136da414
JB
5082
5083 *ccp = str;
5f4273c7 5084
136da414
JB
5085 return SUCCESS;
5086 }
5f4273c7 5087
136da414
JB
5088 return FAIL;
5089}
5090
c19d1205
ZW
5091/* Shift operands. */
5092enum shift_kind
b99bd4ef 5093{
c19d1205
ZW
5094 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5095};
b99bd4ef 5096
c19d1205
ZW
5097struct asm_shift_name
5098{
5099 const char *name;
5100 enum shift_kind kind;
5101};
b99bd4ef 5102
c19d1205
ZW
5103/* Third argument to parse_shift. */
5104enum parse_shift_mode
5105{
5106 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5107 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5108 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5109 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5110 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5111};
b99bd4ef 5112
c19d1205
ZW
5113/* Parse a <shift> specifier on an ARM data processing instruction.
5114 This has three forms:
b99bd4ef 5115
c19d1205
ZW
5116 (LSL|LSR|ASL|ASR|ROR) Rs
5117 (LSL|LSR|ASL|ASR|ROR) #imm
5118 RRX
b99bd4ef 5119
c19d1205
ZW
5120 Note that ASL is assimilated to LSL in the instruction encoding, and
5121 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5122
c19d1205
ZW
5123static int
5124parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5125{
c19d1205
ZW
5126 const struct asm_shift_name *shift_name;
5127 enum shift_kind shift;
5128 char *s = *str;
5129 char *p = s;
5130 int reg;
b99bd4ef 5131
c19d1205
ZW
5132 for (p = *str; ISALPHA (*p); p++)
5133 ;
b99bd4ef 5134
c19d1205 5135 if (p == *str)
b99bd4ef 5136 {
c19d1205
ZW
5137 inst.error = _("shift expression expected");
5138 return FAIL;
b99bd4ef
NC
5139 }
5140
21d799b5 5141 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5142 p - *str);
c19d1205
ZW
5143
5144 if (shift_name == NULL)
b99bd4ef 5145 {
c19d1205
ZW
5146 inst.error = _("shift expression expected");
5147 return FAIL;
b99bd4ef
NC
5148 }
5149
c19d1205 5150 shift = shift_name->kind;
b99bd4ef 5151
c19d1205
ZW
5152 switch (mode)
5153 {
5154 case NO_SHIFT_RESTRICT:
5155 case SHIFT_IMMEDIATE: break;
b99bd4ef 5156
c19d1205
ZW
5157 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5158 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5159 {
5160 inst.error = _("'LSL' or 'ASR' required");
5161 return FAIL;
5162 }
5163 break;
b99bd4ef 5164
c19d1205
ZW
5165 case SHIFT_LSL_IMMEDIATE:
5166 if (shift != SHIFT_LSL)
5167 {
5168 inst.error = _("'LSL' required");
5169 return FAIL;
5170 }
5171 break;
b99bd4ef 5172
c19d1205
ZW
5173 case SHIFT_ASR_IMMEDIATE:
5174 if (shift != SHIFT_ASR)
5175 {
5176 inst.error = _("'ASR' required");
5177 return FAIL;
5178 }
5179 break;
b99bd4ef 5180
c19d1205
ZW
5181 default: abort ();
5182 }
b99bd4ef 5183
c19d1205
ZW
5184 if (shift != SHIFT_RRX)
5185 {
5186 /* Whitespace can appear here if the next thing is a bare digit. */
5187 skip_whitespace (p);
b99bd4ef 5188
c19d1205 5189 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5190 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5191 {
5192 inst.operands[i].imm = reg;
5193 inst.operands[i].immisreg = 1;
5194 }
5195 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5196 return FAIL;
5197 }
5198 inst.operands[i].shift_kind = shift;
5199 inst.operands[i].shifted = 1;
5200 *str = p;
5201 return SUCCESS;
b99bd4ef
NC
5202}
5203
c19d1205 5204/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5205
c19d1205
ZW
5206 #<immediate>
5207 #<immediate>, <rotate>
5208 <Rm>
5209 <Rm>, <shift>
b99bd4ef 5210
c19d1205
ZW
5211 where <shift> is defined by parse_shift above, and <rotate> is a
5212 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5213 is deferred to md_apply_fix. */
b99bd4ef 5214
c19d1205
ZW
5215static int
5216parse_shifter_operand (char **str, int i)
5217{
5218 int value;
91d6fa6a 5219 expressionS exp;
b99bd4ef 5220
dcbf9037 5221 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5222 {
5223 inst.operands[i].reg = value;
5224 inst.operands[i].isreg = 1;
b99bd4ef 5225
c19d1205
ZW
5226 /* parse_shift will override this if appropriate */
5227 inst.reloc.exp.X_op = O_constant;
5228 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5229
c19d1205
ZW
5230 if (skip_past_comma (str) == FAIL)
5231 return SUCCESS;
b99bd4ef 5232
c19d1205
ZW
5233 /* Shift operation on register. */
5234 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5235 }
5236
c19d1205
ZW
5237 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5238 return FAIL;
b99bd4ef 5239
c19d1205 5240 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5241 {
c19d1205 5242 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5243 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5244 return FAIL;
b99bd4ef 5245
91d6fa6a 5246 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5247 {
5248 inst.error = _("constant expression expected");
5249 return FAIL;
5250 }
b99bd4ef 5251
91d6fa6a 5252 value = exp.X_add_number;
c19d1205
ZW
5253 if (value < 0 || value > 30 || value % 2 != 0)
5254 {
5255 inst.error = _("invalid rotation");
5256 return FAIL;
5257 }
5258 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5259 {
5260 inst.error = _("invalid constant");
5261 return FAIL;
5262 }
09d92015 5263
a415b1cd
JB
5264 /* Encode as specified. */
5265 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5266 return SUCCESS;
09d92015
MM
5267 }
5268
c19d1205
ZW
5269 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5270 inst.reloc.pc_rel = 0;
5271 return SUCCESS;
09d92015
MM
5272}
5273
4962c51a
MS
5274/* Group relocation information. Each entry in the table contains the
5275 textual name of the relocation as may appear in assembler source
5276 and must end with a colon.
5277 Along with this textual name are the relocation codes to be used if
5278 the corresponding instruction is an ALU instruction (ADD or SUB only),
5279 an LDR, an LDRS, or an LDC. */
5280
5281struct group_reloc_table_entry
5282{
5283 const char *name;
5284 int alu_code;
5285 int ldr_code;
5286 int ldrs_code;
5287 int ldc_code;
5288};
5289
5290typedef enum
5291{
5292 /* Varieties of non-ALU group relocation. */
5293
5294 GROUP_LDR,
5295 GROUP_LDRS,
5296 GROUP_LDC
5297} group_reloc_type;
5298
5299static struct group_reloc_table_entry group_reloc_table[] =
5300 { /* Program counter relative: */
5301 { "pc_g0_nc",
5302 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5303 0, /* LDR */
5304 0, /* LDRS */
5305 0 }, /* LDC */
5306 { "pc_g0",
5307 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5308 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5309 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5310 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5311 { "pc_g1_nc",
5312 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5313 0, /* LDR */
5314 0, /* LDRS */
5315 0 }, /* LDC */
5316 { "pc_g1",
5317 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5318 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5319 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5320 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5321 { "pc_g2",
5322 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5323 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5324 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5325 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5326 /* Section base relative */
5327 { "sb_g0_nc",
5328 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5329 0, /* LDR */
5330 0, /* LDRS */
5331 0 }, /* LDC */
5332 { "sb_g0",
5333 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5334 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5335 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5336 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5337 { "sb_g1_nc",
5338 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5339 0, /* LDR */
5340 0, /* LDRS */
5341 0 }, /* LDC */
5342 { "sb_g1",
5343 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5344 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5345 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5346 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5347 { "sb_g2",
5348 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5349 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5350 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5351 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5352 /* Absolute thumb alu relocations. */
5353 { "lower0_7",
5354 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5355 0, /* LDR. */
5356 0, /* LDRS. */
5357 0 }, /* LDC. */
5358 { "lower8_15",
5359 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5360 0, /* LDR. */
5361 0, /* LDRS. */
5362 0 }, /* LDC. */
5363 { "upper0_7",
5364 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5365 0, /* LDR. */
5366 0, /* LDRS. */
5367 0 }, /* LDC. */
5368 { "upper8_15",
5369 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5370 0, /* LDR. */
5371 0, /* LDRS. */
5372 0 } }; /* LDC. */
4962c51a
MS
5373
5374/* Given the address of a pointer pointing to the textual name of a group
5375 relocation as may appear in assembler source, attempt to find its details
5376 in group_reloc_table. The pointer will be updated to the character after
5377 the trailing colon. On failure, FAIL will be returned; SUCCESS
5378 otherwise. On success, *entry will be updated to point at the relevant
5379 group_reloc_table entry. */
5380
5381static int
5382find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5383{
5384 unsigned int i;
5385 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5386 {
5387 int length = strlen (group_reloc_table[i].name);
5388
5f4273c7
NC
5389 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5390 && (*str)[length] == ':')
477330fc
RM
5391 {
5392 *out = &group_reloc_table[i];
5393 *str += (length + 1);
5394 return SUCCESS;
5395 }
4962c51a
MS
5396 }
5397
5398 return FAIL;
5399}
5400
5401/* Parse a <shifter_operand> for an ARM data processing instruction
5402 (as for parse_shifter_operand) where group relocations are allowed:
5403
5404 #<immediate>
5405 #<immediate>, <rotate>
5406 #:<group_reloc>:<expression>
5407 <Rm>
5408 <Rm>, <shift>
5409
5410 where <group_reloc> is one of the strings defined in group_reloc_table.
5411 The hashes are optional.
5412
5413 Everything else is as for parse_shifter_operand. */
5414
5415static parse_operand_result
5416parse_shifter_operand_group_reloc (char **str, int i)
5417{
5418 /* Determine if we have the sequence of characters #: or just :
5419 coming next. If we do, then we check for a group relocation.
5420 If we don't, punt the whole lot to parse_shifter_operand. */
5421
5422 if (((*str)[0] == '#' && (*str)[1] == ':')
5423 || (*str)[0] == ':')
5424 {
5425 struct group_reloc_table_entry *entry;
5426
5427 if ((*str)[0] == '#')
477330fc 5428 (*str) += 2;
4962c51a 5429 else
477330fc 5430 (*str)++;
4962c51a
MS
5431
5432 /* Try to parse a group relocation. Anything else is an error. */
5433 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5434 {
5435 inst.error = _("unknown group relocation");
5436 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5437 }
4962c51a
MS
5438
5439 /* We now have the group relocation table entry corresponding to
477330fc 5440 the name in the assembler source. Next, we parse the expression. */
4962c51a 5441 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5442 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5443
5444 /* Record the relocation type (always the ALU variant here). */
21d799b5 5445 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5446 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5447
5448 return PARSE_OPERAND_SUCCESS;
5449 }
5450 else
5451 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5452 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5453
5454 /* Never reached. */
5455}
5456
8e560766
MGD
5457/* Parse a Neon alignment expression. Information is written to
5458 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5459
8e560766
MGD
5460 align .imm = align << 8, .immisalign=1, .preind=0 */
5461static parse_operand_result
5462parse_neon_alignment (char **str, int i)
5463{
5464 char *p = *str;
5465 expressionS exp;
5466
5467 my_get_expression (&exp, &p, GE_NO_PREFIX);
5468
5469 if (exp.X_op != O_constant)
5470 {
5471 inst.error = _("alignment must be constant");
5472 return PARSE_OPERAND_FAIL;
5473 }
5474
5475 inst.operands[i].imm = exp.X_add_number << 8;
5476 inst.operands[i].immisalign = 1;
5477 /* Alignments are not pre-indexes. */
5478 inst.operands[i].preind = 0;
5479
5480 *str = p;
5481 return PARSE_OPERAND_SUCCESS;
5482}
5483
c19d1205
ZW
5484/* Parse all forms of an ARM address expression. Information is written
5485 to inst.operands[i] and/or inst.reloc.
09d92015 5486
c19d1205 5487 Preindexed addressing (.preind=1):
09d92015 5488
c19d1205
ZW
5489 [Rn, #offset] .reg=Rn .reloc.exp=offset
5490 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5491 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5492 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5493
c19d1205 5494 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5495
c19d1205 5496 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5497
c19d1205
ZW
5498 [Rn], #offset .reg=Rn .reloc.exp=offset
5499 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5500 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5501 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5502
c19d1205 5503 Unindexed addressing (.preind=0, .postind=0):
09d92015 5504
c19d1205 5505 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5506
c19d1205 5507 Other:
09d92015 5508
c19d1205
ZW
5509 [Rn]{!} shorthand for [Rn,#0]{!}
5510 =immediate .isreg=0 .reloc.exp=immediate
5511 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5512
c19d1205
ZW
5513 It is the caller's responsibility to check for addressing modes not
5514 supported by the instruction, and to set inst.reloc.type. */
5515
4962c51a
MS
5516static parse_operand_result
5517parse_address_main (char **str, int i, int group_relocations,
477330fc 5518 group_reloc_type group_type)
09d92015 5519{
c19d1205
ZW
5520 char *p = *str;
5521 int reg;
09d92015 5522
c19d1205 5523 if (skip_past_char (&p, '[') == FAIL)
09d92015 5524 {
c19d1205
ZW
5525 if (skip_past_char (&p, '=') == FAIL)
5526 {
974da60d 5527 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5528 inst.reloc.pc_rel = 1;
5529 inst.operands[i].reg = REG_PC;
5530 inst.operands[i].isreg = 1;
5531 inst.operands[i].preind = 1;
09d92015 5532
8335d6aa
JW
5533 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5534 return PARSE_OPERAND_FAIL;
5535 }
5536 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5537 /*allow_symbol_p=*/TRUE))
4962c51a 5538 return PARSE_OPERAND_FAIL;
09d92015 5539
c19d1205 5540 *str = p;
4962c51a 5541 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5542 }
5543
8ab8155f
NC
5544 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5545 skip_whitespace (p);
5546
dcbf9037 5547 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5548 {
c19d1205 5549 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5550 return PARSE_OPERAND_FAIL;
09d92015 5551 }
c19d1205
ZW
5552 inst.operands[i].reg = reg;
5553 inst.operands[i].isreg = 1;
09d92015 5554
c19d1205 5555 if (skip_past_comma (&p) == SUCCESS)
09d92015 5556 {
c19d1205 5557 inst.operands[i].preind = 1;
09d92015 5558
c19d1205
ZW
5559 if (*p == '+') p++;
5560 else if (*p == '-') p++, inst.operands[i].negative = 1;
5561
dcbf9037 5562 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5563 {
c19d1205
ZW
5564 inst.operands[i].imm = reg;
5565 inst.operands[i].immisreg = 1;
5566
5567 if (skip_past_comma (&p) == SUCCESS)
5568 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5569 return PARSE_OPERAND_FAIL;
c19d1205 5570 }
5287ad62 5571 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5572 {
5573 /* FIXME: '@' should be used here, but it's filtered out by generic
5574 code before we get to see it here. This may be subject to
5575 change. */
5576 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5577
8e560766
MGD
5578 if (result != PARSE_OPERAND_SUCCESS)
5579 return result;
5580 }
c19d1205
ZW
5581 else
5582 {
5583 if (inst.operands[i].negative)
5584 {
5585 inst.operands[i].negative = 0;
5586 p--;
5587 }
4962c51a 5588
5f4273c7
NC
5589 if (group_relocations
5590 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5591 {
5592 struct group_reloc_table_entry *entry;
5593
477330fc
RM
5594 /* Skip over the #: or : sequence. */
5595 if (*p == '#')
5596 p += 2;
5597 else
5598 p++;
4962c51a
MS
5599
5600 /* Try to parse a group relocation. Anything else is an
477330fc 5601 error. */
4962c51a
MS
5602 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5603 {
5604 inst.error = _("unknown group relocation");
5605 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5606 }
5607
5608 /* We now have the group relocation table entry corresponding to
5609 the name in the assembler source. Next, we parse the
477330fc 5610 expression. */
4962c51a
MS
5611 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5612 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5613
5614 /* Record the relocation type. */
477330fc
RM
5615 switch (group_type)
5616 {
5617 case GROUP_LDR:
5618 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5619 break;
4962c51a 5620
477330fc
RM
5621 case GROUP_LDRS:
5622 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5623 break;
4962c51a 5624
477330fc
RM
5625 case GROUP_LDC:
5626 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5627 break;
4962c51a 5628
477330fc
RM
5629 default:
5630 gas_assert (0);
5631 }
4962c51a 5632
477330fc 5633 if (inst.reloc.type == 0)
4962c51a
MS
5634 {
5635 inst.error = _("this group relocation is not allowed on this instruction");
5636 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5637 }
477330fc
RM
5638 }
5639 else
26d97720
NS
5640 {
5641 char *q = p;
0198d5e6 5642
26d97720
NS
5643 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5644 return PARSE_OPERAND_FAIL;
5645 /* If the offset is 0, find out if it's a +0 or -0. */
5646 if (inst.reloc.exp.X_op == O_constant
5647 && inst.reloc.exp.X_add_number == 0)
5648 {
5649 skip_whitespace (q);
5650 if (*q == '#')
5651 {
5652 q++;
5653 skip_whitespace (q);
5654 }
5655 if (*q == '-')
5656 inst.operands[i].negative = 1;
5657 }
5658 }
09d92015
MM
5659 }
5660 }
8e560766
MGD
5661 else if (skip_past_char (&p, ':') == SUCCESS)
5662 {
5663 /* FIXME: '@' should be used here, but it's filtered out by generic code
5664 before we get to see it here. This may be subject to change. */
5665 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5666
8e560766
MGD
5667 if (result != PARSE_OPERAND_SUCCESS)
5668 return result;
5669 }
09d92015 5670
c19d1205 5671 if (skip_past_char (&p, ']') == FAIL)
09d92015 5672 {
c19d1205 5673 inst.error = _("']' expected");
4962c51a 5674 return PARSE_OPERAND_FAIL;
09d92015
MM
5675 }
5676
c19d1205
ZW
5677 if (skip_past_char (&p, '!') == SUCCESS)
5678 inst.operands[i].writeback = 1;
09d92015 5679
c19d1205 5680 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5681 {
c19d1205
ZW
5682 if (skip_past_char (&p, '{') == SUCCESS)
5683 {
5684 /* [Rn], {expr} - unindexed, with option */
5685 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5686 0, 255, TRUE) == FAIL)
4962c51a 5687 return PARSE_OPERAND_FAIL;
09d92015 5688
c19d1205
ZW
5689 if (skip_past_char (&p, '}') == FAIL)
5690 {
5691 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5692 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5693 }
5694 if (inst.operands[i].preind)
5695 {
5696 inst.error = _("cannot combine index with option");
4962c51a 5697 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5698 }
5699 *str = p;
4962c51a 5700 return PARSE_OPERAND_SUCCESS;
09d92015 5701 }
c19d1205
ZW
5702 else
5703 {
5704 inst.operands[i].postind = 1;
5705 inst.operands[i].writeback = 1;
09d92015 5706
c19d1205
ZW
5707 if (inst.operands[i].preind)
5708 {
5709 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5710 return PARSE_OPERAND_FAIL;
c19d1205 5711 }
09d92015 5712
c19d1205
ZW
5713 if (*p == '+') p++;
5714 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5715
dcbf9037 5716 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5717 {
477330fc
RM
5718 /* We might be using the immediate for alignment already. If we
5719 are, OR the register number into the low-order bits. */
5720 if (inst.operands[i].immisalign)
5721 inst.operands[i].imm |= reg;
5722 else
5723 inst.operands[i].imm = reg;
c19d1205 5724 inst.operands[i].immisreg = 1;
a737bd4d 5725
c19d1205
ZW
5726 if (skip_past_comma (&p) == SUCCESS)
5727 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5728 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5729 }
5730 else
5731 {
26d97720 5732 char *q = p;
0198d5e6 5733
c19d1205
ZW
5734 if (inst.operands[i].negative)
5735 {
5736 inst.operands[i].negative = 0;
5737 p--;
5738 }
5739 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5740 return PARSE_OPERAND_FAIL;
26d97720
NS
5741 /* If the offset is 0, find out if it's a +0 or -0. */
5742 if (inst.reloc.exp.X_op == O_constant
5743 && inst.reloc.exp.X_add_number == 0)
5744 {
5745 skip_whitespace (q);
5746 if (*q == '#')
5747 {
5748 q++;
5749 skip_whitespace (q);
5750 }
5751 if (*q == '-')
5752 inst.operands[i].negative = 1;
5753 }
c19d1205
ZW
5754 }
5755 }
a737bd4d
NC
5756 }
5757
c19d1205
ZW
5758 /* If at this point neither .preind nor .postind is set, we have a
5759 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5760 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5761 {
5762 inst.operands[i].preind = 1;
5763 inst.reloc.exp.X_op = O_constant;
5764 inst.reloc.exp.X_add_number = 0;
5765 }
5766 *str = p;
4962c51a
MS
5767 return PARSE_OPERAND_SUCCESS;
5768}
5769
5770static int
5771parse_address (char **str, int i)
5772{
21d799b5 5773 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5774 ? SUCCESS : FAIL;
4962c51a
MS
5775}
5776
5777static parse_operand_result
5778parse_address_group_reloc (char **str, int i, group_reloc_type type)
5779{
5780 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5781}
5782
b6895b4f
PB
5783/* Parse an operand for a MOVW or MOVT instruction. */
5784static int
5785parse_half (char **str)
5786{
5787 char * p;
5f4273c7 5788
b6895b4f
PB
5789 p = *str;
5790 skip_past_char (&p, '#');
5f4273c7 5791 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5792 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5793 else if (strncasecmp (p, ":upper16:", 9) == 0)
5794 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5795
5796 if (inst.reloc.type != BFD_RELOC_UNUSED)
5797 {
5798 p += 9;
5f4273c7 5799 skip_whitespace (p);
b6895b4f
PB
5800 }
5801
5802 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5803 return FAIL;
5804
5805 if (inst.reloc.type == BFD_RELOC_UNUSED)
5806 {
5807 if (inst.reloc.exp.X_op != O_constant)
5808 {
5809 inst.error = _("constant expression expected");
5810 return FAIL;
5811 }
5812 if (inst.reloc.exp.X_add_number < 0
5813 || inst.reloc.exp.X_add_number > 0xffff)
5814 {
5815 inst.error = _("immediate value out of range");
5816 return FAIL;
5817 }
5818 }
5819 *str = p;
5820 return SUCCESS;
5821}
5822
c19d1205 5823/* Miscellaneous. */
a737bd4d 5824
c19d1205
ZW
5825/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5826 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5827static int
d2cd1205 5828parse_psr (char **str, bfd_boolean lhs)
09d92015 5829{
c19d1205
ZW
5830 char *p;
5831 unsigned long psr_field;
62b3e311
PB
5832 const struct asm_psr *psr;
5833 char *start;
d2cd1205 5834 bfd_boolean is_apsr = FALSE;
ac7f631b 5835 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5836
a4482bb6
NC
5837 /* PR gas/12698: If the user has specified -march=all then m_profile will
5838 be TRUE, but we want to ignore it in this case as we are building for any
5839 CPU type, including non-m variants. */
823d2571 5840 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5841 m_profile = FALSE;
5842
c19d1205
ZW
5843 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5844 feature for ease of use and backwards compatibility. */
5845 p = *str;
62b3e311 5846 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5847 {
5848 if (m_profile)
5849 goto unsupported_psr;
fa94de6b 5850
d2cd1205
JB
5851 psr_field = SPSR_BIT;
5852 }
5853 else if (strncasecmp (p, "CPSR", 4) == 0)
5854 {
5855 if (m_profile)
5856 goto unsupported_psr;
5857
5858 psr_field = 0;
5859 }
5860 else if (strncasecmp (p, "APSR", 4) == 0)
5861 {
5862 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5863 and ARMv7-R architecture CPUs. */
5864 is_apsr = TRUE;
5865 psr_field = 0;
5866 }
5867 else if (m_profile)
62b3e311
PB
5868 {
5869 start = p;
5870 do
5871 p++;
5872 while (ISALNUM (*p) || *p == '_');
5873
d2cd1205
JB
5874 if (strncasecmp (start, "iapsr", 5) == 0
5875 || strncasecmp (start, "eapsr", 5) == 0
5876 || strncasecmp (start, "xpsr", 4) == 0
5877 || strncasecmp (start, "psr", 3) == 0)
5878 p = start + strcspn (start, "rR") + 1;
5879
21d799b5 5880 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5881 p - start);
d2cd1205 5882
62b3e311
PB
5883 if (!psr)
5884 return FAIL;
09d92015 5885
d2cd1205
JB
5886 /* If APSR is being written, a bitfield may be specified. Note that
5887 APSR itself is handled above. */
5888 if (psr->field <= 3)
5889 {
5890 psr_field = psr->field;
5891 is_apsr = TRUE;
5892 goto check_suffix;
5893 }
5894
62b3e311 5895 *str = p;
d2cd1205
JB
5896 /* M-profile MSR instructions have the mask field set to "10", except
5897 *PSR variants which modify APSR, which may use a different mask (and
5898 have been handled already). Do that by setting the PSR_f field
5899 here. */
5900 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5901 }
d2cd1205
JB
5902 else
5903 goto unsupported_psr;
09d92015 5904
62b3e311 5905 p += 4;
d2cd1205 5906check_suffix:
c19d1205
ZW
5907 if (*p == '_')
5908 {
5909 /* A suffix follows. */
c19d1205
ZW
5910 p++;
5911 start = p;
a737bd4d 5912
c19d1205
ZW
5913 do
5914 p++;
5915 while (ISALNUM (*p) || *p == '_');
a737bd4d 5916
d2cd1205
JB
5917 if (is_apsr)
5918 {
5919 /* APSR uses a notation for bits, rather than fields. */
5920 unsigned int nzcvq_bits = 0;
5921 unsigned int g_bit = 0;
5922 char *bit;
fa94de6b 5923
d2cd1205
JB
5924 for (bit = start; bit != p; bit++)
5925 {
5926 switch (TOLOWER (*bit))
477330fc 5927 {
d2cd1205
JB
5928 case 'n':
5929 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5930 break;
5931
5932 case 'z':
5933 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5934 break;
5935
5936 case 'c':
5937 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5938 break;
5939
5940 case 'v':
5941 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5942 break;
fa94de6b 5943
d2cd1205
JB
5944 case 'q':
5945 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5946 break;
fa94de6b 5947
d2cd1205
JB
5948 case 'g':
5949 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5950 break;
fa94de6b 5951
d2cd1205
JB
5952 default:
5953 inst.error = _("unexpected bit specified after APSR");
5954 return FAIL;
5955 }
5956 }
fa94de6b 5957
d2cd1205
JB
5958 if (nzcvq_bits == 0x1f)
5959 psr_field |= PSR_f;
fa94de6b 5960
d2cd1205
JB
5961 if (g_bit == 0x1)
5962 {
5963 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5964 {
d2cd1205
JB
5965 inst.error = _("selected processor does not "
5966 "support DSP extension");
5967 return FAIL;
5968 }
5969
5970 psr_field |= PSR_s;
5971 }
fa94de6b 5972
d2cd1205
JB
5973 if ((nzcvq_bits & 0x20) != 0
5974 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5975 || (g_bit & 0x2) != 0)
5976 {
5977 inst.error = _("bad bitmask specified after APSR");
5978 return FAIL;
5979 }
5980 }
5981 else
477330fc 5982 {
d2cd1205 5983 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5984 p - start);
d2cd1205 5985 if (!psr)
477330fc 5986 goto error;
a737bd4d 5987
d2cd1205
JB
5988 psr_field |= psr->field;
5989 }
a737bd4d 5990 }
c19d1205 5991 else
a737bd4d 5992 {
c19d1205
ZW
5993 if (ISALNUM (*p))
5994 goto error; /* Garbage after "[CS]PSR". */
5995
d2cd1205 5996 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5997 is deprecated, but allow it anyway. */
d2cd1205
JB
5998 if (is_apsr && lhs)
5999 {
6000 psr_field |= PSR_f;
6001 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6002 "deprecated"));
6003 }
6004 else if (!m_profile)
6005 /* These bits are never right for M-profile devices: don't set them
6006 (only code paths which read/write APSR reach here). */
6007 psr_field |= (PSR_c | PSR_f);
a737bd4d 6008 }
c19d1205
ZW
6009 *str = p;
6010 return psr_field;
a737bd4d 6011
d2cd1205
JB
6012 unsupported_psr:
6013 inst.error = _("selected processor does not support requested special "
6014 "purpose register");
6015 return FAIL;
6016
c19d1205
ZW
6017 error:
6018 inst.error = _("flag for {c}psr instruction expected");
6019 return FAIL;
a737bd4d
NC
6020}
6021
c19d1205
ZW
6022/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6023 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6024
c19d1205
ZW
6025static int
6026parse_cps_flags (char **str)
a737bd4d 6027{
c19d1205
ZW
6028 int val = 0;
6029 int saw_a_flag = 0;
6030 char *s = *str;
a737bd4d 6031
c19d1205
ZW
6032 for (;;)
6033 switch (*s++)
6034 {
6035 case '\0': case ',':
6036 goto done;
a737bd4d 6037
c19d1205
ZW
6038 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6039 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6040 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6041
c19d1205
ZW
6042 default:
6043 inst.error = _("unrecognized CPS flag");
6044 return FAIL;
6045 }
a737bd4d 6046
c19d1205
ZW
6047 done:
6048 if (saw_a_flag == 0)
a737bd4d 6049 {
c19d1205
ZW
6050 inst.error = _("missing CPS flags");
6051 return FAIL;
a737bd4d 6052 }
a737bd4d 6053
c19d1205
ZW
6054 *str = s - 1;
6055 return val;
a737bd4d
NC
6056}
6057
c19d1205
ZW
6058/* Parse an endian specifier ("BE" or "LE", case insensitive);
6059 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6060
6061static int
c19d1205 6062parse_endian_specifier (char **str)
a737bd4d 6063{
c19d1205
ZW
6064 int little_endian;
6065 char *s = *str;
a737bd4d 6066
c19d1205
ZW
6067 if (strncasecmp (s, "BE", 2))
6068 little_endian = 0;
6069 else if (strncasecmp (s, "LE", 2))
6070 little_endian = 1;
6071 else
a737bd4d 6072 {
c19d1205 6073 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6074 return FAIL;
6075 }
6076
c19d1205 6077 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6078 {
c19d1205 6079 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6080 return FAIL;
6081 }
6082
c19d1205
ZW
6083 *str = s + 2;
6084 return little_endian;
6085}
a737bd4d 6086
c19d1205
ZW
6087/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6088 value suitable for poking into the rotate field of an sxt or sxta
6089 instruction, or FAIL on error. */
6090
6091static int
6092parse_ror (char **str)
6093{
6094 int rot;
6095 char *s = *str;
6096
6097 if (strncasecmp (s, "ROR", 3) == 0)
6098 s += 3;
6099 else
a737bd4d 6100 {
c19d1205 6101 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6102 return FAIL;
6103 }
c19d1205
ZW
6104
6105 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6106 return FAIL;
6107
6108 switch (rot)
a737bd4d 6109 {
c19d1205
ZW
6110 case 0: *str = s; return 0x0;
6111 case 8: *str = s; return 0x1;
6112 case 16: *str = s; return 0x2;
6113 case 24: *str = s; return 0x3;
6114
6115 default:
6116 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6117 return FAIL;
6118 }
c19d1205 6119}
a737bd4d 6120
c19d1205
ZW
6121/* Parse a conditional code (from conds[] below). The value returned is in the
6122 range 0 .. 14, or FAIL. */
6123static int
6124parse_cond (char **str)
6125{
c462b453 6126 char *q;
c19d1205 6127 const struct asm_cond *c;
c462b453
PB
6128 int n;
6129 /* Condition codes are always 2 characters, so matching up to
6130 3 characters is sufficient. */
6131 char cond[3];
a737bd4d 6132
c462b453
PB
6133 q = *str;
6134 n = 0;
6135 while (ISALPHA (*q) && n < 3)
6136 {
e07e6e58 6137 cond[n] = TOLOWER (*q);
c462b453
PB
6138 q++;
6139 n++;
6140 }
a737bd4d 6141
21d799b5 6142 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6143 if (!c)
a737bd4d 6144 {
c19d1205 6145 inst.error = _("condition required");
a737bd4d
NC
6146 return FAIL;
6147 }
6148
c19d1205
ZW
6149 *str = q;
6150 return c->value;
6151}
6152
643afb90
MW
6153/* Record a use of the given feature. */
6154static void
6155record_feature_use (const arm_feature_set *feature)
6156{
6157 if (thumb_mode)
6158 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6159 else
6160 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6161}
6162
e797f7e0
MGD
6163/* If the given feature available in the selected CPU, mark it as used.
6164 Returns TRUE iff feature is available. */
6165static bfd_boolean
6166mark_feature_used (const arm_feature_set *feature)
6167{
6168 /* Ensure the option is valid on the current architecture. */
6169 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6170 return FALSE;
6171
6172 /* Add the appropriate architecture feature for the barrier option used.
6173 */
643afb90 6174 record_feature_use (feature);
e797f7e0
MGD
6175
6176 return TRUE;
6177}
6178
62b3e311
PB
6179/* Parse an option for a barrier instruction. Returns the encoding for the
6180 option, or FAIL. */
6181static int
6182parse_barrier (char **str)
6183{
6184 char *p, *q;
6185 const struct asm_barrier_opt *o;
6186
6187 p = q = *str;
6188 while (ISALPHA (*q))
6189 q++;
6190
21d799b5 6191 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6192 q - p);
62b3e311
PB
6193 if (!o)
6194 return FAIL;
6195
e797f7e0
MGD
6196 if (!mark_feature_used (&o->arch))
6197 return FAIL;
6198
62b3e311
PB
6199 *str = q;
6200 return o->value;
6201}
6202
92e90b6e
PB
6203/* Parse the operands of a table branch instruction. Similar to a memory
6204 operand. */
6205static int
6206parse_tb (char **str)
6207{
6208 char * p = *str;
6209 int reg;
6210
6211 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6212 {
6213 inst.error = _("'[' expected");
6214 return FAIL;
6215 }
92e90b6e 6216
dcbf9037 6217 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6218 {
6219 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6220 return FAIL;
6221 }
6222 inst.operands[0].reg = reg;
6223
6224 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6225 {
6226 inst.error = _("',' expected");
6227 return FAIL;
6228 }
5f4273c7 6229
dcbf9037 6230 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6231 {
6232 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6233 return FAIL;
6234 }
6235 inst.operands[0].imm = reg;
6236
6237 if (skip_past_comma (&p) == SUCCESS)
6238 {
6239 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6240 return FAIL;
6241 if (inst.reloc.exp.X_add_number != 1)
6242 {
6243 inst.error = _("invalid shift");
6244 return FAIL;
6245 }
6246 inst.operands[0].shifted = 1;
6247 }
6248
6249 if (skip_past_char (&p, ']') == FAIL)
6250 {
6251 inst.error = _("']' expected");
6252 return FAIL;
6253 }
6254 *str = p;
6255 return SUCCESS;
6256}
6257
5287ad62
JB
6258/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6259 information on the types the operands can take and how they are encoded.
037e8744
JB
6260 Up to four operands may be read; this function handles setting the
6261 ".present" field for each read operand itself.
5287ad62
JB
6262 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6263 else returns FAIL. */
6264
6265static int
6266parse_neon_mov (char **str, int *which_operand)
6267{
6268 int i = *which_operand, val;
6269 enum arm_reg_type rtype;
6270 char *ptr = *str;
dcbf9037 6271 struct neon_type_el optype;
5f4273c7 6272
dcbf9037 6273 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6274 {
6275 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6276 inst.operands[i].reg = val;
6277 inst.operands[i].isscalar = 1;
dcbf9037 6278 inst.operands[i].vectype = optype;
5287ad62
JB
6279 inst.operands[i++].present = 1;
6280
6281 if (skip_past_comma (&ptr) == FAIL)
477330fc 6282 goto wanted_comma;
5f4273c7 6283
dcbf9037 6284 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6285 goto wanted_arm;
5f4273c7 6286
5287ad62
JB
6287 inst.operands[i].reg = val;
6288 inst.operands[i].isreg = 1;
6289 inst.operands[i].present = 1;
6290 }
037e8744 6291 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6292 != FAIL)
5287ad62
JB
6293 {
6294 /* Cases 0, 1, 2, 3, 5 (D only). */
6295 if (skip_past_comma (&ptr) == FAIL)
477330fc 6296 goto wanted_comma;
5f4273c7 6297
5287ad62
JB
6298 inst.operands[i].reg = val;
6299 inst.operands[i].isreg = 1;
6300 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6301 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6302 inst.operands[i].isvec = 1;
dcbf9037 6303 inst.operands[i].vectype = optype;
5287ad62
JB
6304 inst.operands[i++].present = 1;
6305
dcbf9037 6306 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6307 {
6308 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6309 Case 13: VMOV <Sd>, <Rm> */
6310 inst.operands[i].reg = val;
6311 inst.operands[i].isreg = 1;
6312 inst.operands[i].present = 1;
6313
6314 if (rtype == REG_TYPE_NQ)
6315 {
6316 first_error (_("can't use Neon quad register here"));
6317 return FAIL;
6318 }
6319 else if (rtype != REG_TYPE_VFS)
6320 {
6321 i++;
6322 if (skip_past_comma (&ptr) == FAIL)
6323 goto wanted_comma;
6324 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6325 goto wanted_arm;
6326 inst.operands[i].reg = val;
6327 inst.operands[i].isreg = 1;
6328 inst.operands[i].present = 1;
6329 }
6330 }
037e8744 6331 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6332 &optype)) != FAIL)
6333 {
6334 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6335 Case 1: VMOV<c><q> <Dd>, <Dm>
6336 Case 8: VMOV.F32 <Sd>, <Sm>
6337 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6338
6339 inst.operands[i].reg = val;
6340 inst.operands[i].isreg = 1;
6341 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6342 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6343 inst.operands[i].isvec = 1;
6344 inst.operands[i].vectype = optype;
6345 inst.operands[i].present = 1;
6346
6347 if (skip_past_comma (&ptr) == SUCCESS)
6348 {
6349 /* Case 15. */
6350 i++;
6351
6352 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6353 goto wanted_arm;
6354
6355 inst.operands[i].reg = val;
6356 inst.operands[i].isreg = 1;
6357 inst.operands[i++].present = 1;
6358
6359 if (skip_past_comma (&ptr) == FAIL)
6360 goto wanted_comma;
6361
6362 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6363 goto wanted_arm;
6364
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i].present = 1;
6368 }
6369 }
4641781c 6370 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6371 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6372 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6373 Case 10: VMOV.F32 <Sd>, #<imm>
6374 Case 11: VMOV.F64 <Dd>, #<imm> */
6375 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6376 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6377 == SUCCESS)
477330fc
RM
6378 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6379 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6380 ;
5287ad62 6381 else
477330fc
RM
6382 {
6383 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6384 return FAIL;
6385 }
5287ad62 6386 }
dcbf9037 6387 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6388 {
6389 /* Cases 6, 7. */
6390 inst.operands[i].reg = val;
6391 inst.operands[i].isreg = 1;
6392 inst.operands[i++].present = 1;
5f4273c7 6393
5287ad62 6394 if (skip_past_comma (&ptr) == FAIL)
477330fc 6395 goto wanted_comma;
5f4273c7 6396
dcbf9037 6397 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6398 {
6399 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6400 inst.operands[i].reg = val;
6401 inst.operands[i].isscalar = 1;
6402 inst.operands[i].present = 1;
6403 inst.operands[i].vectype = optype;
6404 }
dcbf9037 6405 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6406 {
6407 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6408 inst.operands[i].reg = val;
6409 inst.operands[i].isreg = 1;
6410 inst.operands[i++].present = 1;
6411
6412 if (skip_past_comma (&ptr) == FAIL)
6413 goto wanted_comma;
6414
6415 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6416 == FAIL)
6417 {
6418 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6419 return FAIL;
6420 }
6421
6422 inst.operands[i].reg = val;
6423 inst.operands[i].isreg = 1;
6424 inst.operands[i].isvec = 1;
6425 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6426 inst.operands[i].vectype = optype;
6427 inst.operands[i].present = 1;
6428
6429 if (rtype == REG_TYPE_VFS)
6430 {
6431 /* Case 14. */
6432 i++;
6433 if (skip_past_comma (&ptr) == FAIL)
6434 goto wanted_comma;
6435 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6436 &optype)) == FAIL)
6437 {
6438 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6439 return FAIL;
6440 }
6441 inst.operands[i].reg = val;
6442 inst.operands[i].isreg = 1;
6443 inst.operands[i].isvec = 1;
6444 inst.operands[i].issingle = 1;
6445 inst.operands[i].vectype = optype;
6446 inst.operands[i].present = 1;
6447 }
6448 }
037e8744 6449 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6450 != FAIL)
6451 {
6452 /* Case 13. */
6453 inst.operands[i].reg = val;
6454 inst.operands[i].isreg = 1;
6455 inst.operands[i].isvec = 1;
6456 inst.operands[i].issingle = 1;
6457 inst.operands[i].vectype = optype;
6458 inst.operands[i].present = 1;
6459 }
5287ad62
JB
6460 }
6461 else
6462 {
dcbf9037 6463 first_error (_("parse error"));
5287ad62
JB
6464 return FAIL;
6465 }
6466
6467 /* Successfully parsed the operands. Update args. */
6468 *which_operand = i;
6469 *str = ptr;
6470 return SUCCESS;
6471
5f4273c7 6472 wanted_comma:
dcbf9037 6473 first_error (_("expected comma"));
5287ad62 6474 return FAIL;
5f4273c7
NC
6475
6476 wanted_arm:
dcbf9037 6477 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6478 return FAIL;
5287ad62
JB
6479}
6480
5be8be5d
DG
6481/* Use this macro when the operand constraints are different
6482 for ARM and THUMB (e.g. ldrd). */
6483#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6484 ((arm_operand) | ((thumb_operand) << 16))
6485
c19d1205
ZW
6486/* Matcher codes for parse_operands. */
6487enum operand_parse_code
6488{
6489 OP_stop, /* end of line */
6490
6491 OP_RR, /* ARM register */
6492 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6493 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6494 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6495 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6496 optional trailing ! */
c19d1205
ZW
6497 OP_RRw, /* ARM register, not r15, optional trailing ! */
6498 OP_RCP, /* Coprocessor number */
6499 OP_RCN, /* Coprocessor register */
6500 OP_RF, /* FPA register */
6501 OP_RVS, /* VFP single precision register */
5287ad62
JB
6502 OP_RVD, /* VFP double precision register (0..15) */
6503 OP_RND, /* Neon double precision register (0..31) */
6504 OP_RNQ, /* Neon quad precision register */
037e8744 6505 OP_RVSD, /* VFP single or double precision register */
dec41383 6506 OP_RNSD, /* Neon single or double precision register */
5287ad62 6507 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6508 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6509 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6510 OP_RVC, /* VFP control register */
6511 OP_RMF, /* Maverick F register */
6512 OP_RMD, /* Maverick D register */
6513 OP_RMFX, /* Maverick FX register */
6514 OP_RMDX, /* Maverick DX register */
6515 OP_RMAX, /* Maverick AX register */
6516 OP_RMDS, /* Maverick DSPSC register */
6517 OP_RIWR, /* iWMMXt wR register */
6518 OP_RIWC, /* iWMMXt wC register */
6519 OP_RIWG, /* iWMMXt wCG register */
6520 OP_RXA, /* XScale accumulator register */
6521
6522 OP_REGLST, /* ARM register list */
6523 OP_VRSLST, /* VFP single-precision register list */
6524 OP_VRDLST, /* VFP double-precision register list */
037e8744 6525 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6526 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6527 OP_NSTRLST, /* Neon element/structure list */
6528
5287ad62 6529 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6530 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6531 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6532 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6533 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6534 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6535 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6536 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6537 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6538 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6539 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6540 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6541
6542 OP_I0, /* immediate zero */
c19d1205
ZW
6543 OP_I7, /* immediate value 0 .. 7 */
6544 OP_I15, /* 0 .. 15 */
6545 OP_I16, /* 1 .. 16 */
5287ad62 6546 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6547 OP_I31, /* 0 .. 31 */
6548 OP_I31w, /* 0 .. 31, optional trailing ! */
6549 OP_I32, /* 1 .. 32 */
5287ad62
JB
6550 OP_I32z, /* 0 .. 32 */
6551 OP_I63, /* 0 .. 63 */
c19d1205 6552 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6553 OP_I64, /* 1 .. 64 */
6554 OP_I64z, /* 0 .. 64 */
c19d1205 6555 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6556
6557 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6558 OP_I7b, /* 0 .. 7 */
6559 OP_I15b, /* 0 .. 15 */
6560 OP_I31b, /* 0 .. 31 */
6561
6562 OP_SH, /* shifter operand */
4962c51a 6563 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6564 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6565 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6566 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6567 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6568 OP_EXP, /* arbitrary expression */
6569 OP_EXPi, /* same, with optional immediate prefix */
6570 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6571 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6572 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6573 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6574
6575 OP_CPSF, /* CPS flags */
6576 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6577 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6578 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6579 OP_COND, /* conditional code */
92e90b6e 6580 OP_TB, /* Table branch. */
c19d1205 6581
037e8744
JB
6582 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6583
c19d1205 6584 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6585 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6586 OP_RR_EXi, /* ARM register or expression with imm prefix */
6587 OP_RF_IF, /* FPA register or immediate */
6588 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6589 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6590
6591 /* Optional operands. */
6592 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6593 OP_oI31b, /* 0 .. 31 */
5287ad62 6594 OP_oI32b, /* 1 .. 32 */
5f1af56b 6595 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6596 OP_oIffffb, /* 0 .. 65535 */
6597 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6598
6599 OP_oRR, /* ARM register */
6600 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6601 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6602 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6603 OP_oRND, /* Optional Neon double precision register */
6604 OP_oRNQ, /* Optional Neon quad precision register */
6605 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6606 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6607 OP_oSHll, /* LSL immediate */
6608 OP_oSHar, /* ASR immediate */
6609 OP_oSHllar, /* LSL or ASR immediate */
6610 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6611 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6612
5be8be5d
DG
6613 /* Some pre-defined mixed (ARM/THUMB) operands. */
6614 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6615 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6616 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6617
c19d1205
ZW
6618 OP_FIRST_OPTIONAL = OP_oI7b
6619};
a737bd4d 6620
c19d1205
ZW
6621/* Generic instruction operand parser. This does no encoding and no
6622 semantic validation; it merely squirrels values away in the inst
6623 structure. Returns SUCCESS or FAIL depending on whether the
6624 specified grammar matched. */
6625static int
5be8be5d 6626parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6627{
5be8be5d 6628 unsigned const int *upat = pattern;
c19d1205
ZW
6629 char *backtrack_pos = 0;
6630 const char *backtrack_error = 0;
99aad254 6631 int i, val = 0, backtrack_index = 0;
5287ad62 6632 enum arm_reg_type rtype;
4962c51a 6633 parse_operand_result result;
5be8be5d 6634 unsigned int op_parse_code;
c19d1205 6635
e07e6e58
NC
6636#define po_char_or_fail(chr) \
6637 do \
6638 { \
6639 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6640 goto bad_args; \
e07e6e58
NC
6641 } \
6642 while (0)
c19d1205 6643
e07e6e58
NC
6644#define po_reg_or_fail(regtype) \
6645 do \
dcbf9037 6646 { \
e07e6e58 6647 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6648 & inst.operands[i].vectype); \
e07e6e58 6649 if (val == FAIL) \
477330fc
RM
6650 { \
6651 first_error (_(reg_expected_msgs[regtype])); \
6652 goto failure; \
6653 } \
e07e6e58
NC
6654 inst.operands[i].reg = val; \
6655 inst.operands[i].isreg = 1; \
6656 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6657 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6658 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6659 || rtype == REG_TYPE_VFD \
6660 || rtype == REG_TYPE_NQ); \
dcbf9037 6661 } \
e07e6e58
NC
6662 while (0)
6663
6664#define po_reg_or_goto(regtype, label) \
6665 do \
6666 { \
6667 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6668 & inst.operands[i].vectype); \
6669 if (val == FAIL) \
6670 goto label; \
dcbf9037 6671 \
e07e6e58
NC
6672 inst.operands[i].reg = val; \
6673 inst.operands[i].isreg = 1; \
6674 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6675 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6676 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6677 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6678 || rtype == REG_TYPE_NQ); \
6679 } \
6680 while (0)
6681
6682#define po_imm_or_fail(min, max, popt) \
6683 do \
6684 { \
6685 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6686 goto failure; \
6687 inst.operands[i].imm = val; \
6688 } \
6689 while (0)
6690
6691#define po_scalar_or_goto(elsz, label) \
6692 do \
6693 { \
6694 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6695 if (val == FAIL) \
6696 goto label; \
6697 inst.operands[i].reg = val; \
6698 inst.operands[i].isscalar = 1; \
6699 } \
6700 while (0)
6701
6702#define po_misc_or_fail(expr) \
6703 do \
6704 { \
6705 if (expr) \
6706 goto failure; \
6707 } \
6708 while (0)
6709
6710#define po_misc_or_fail_no_backtrack(expr) \
6711 do \
6712 { \
6713 result = expr; \
6714 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6715 backtrack_pos = 0; \
6716 if (result != PARSE_OPERAND_SUCCESS) \
6717 goto failure; \
6718 } \
6719 while (0)
4962c51a 6720
52e7f43d
RE
6721#define po_barrier_or_imm(str) \
6722 do \
6723 { \
6724 val = parse_barrier (&str); \
ccb84d65
JB
6725 if (val == FAIL && ! ISALPHA (*str)) \
6726 goto immediate; \
6727 if (val == FAIL \
6728 /* ISB can only take SY as an option. */ \
6729 || ((inst.instruction & 0xf0) == 0x60 \
6730 && val != 0xf)) \
52e7f43d 6731 { \
ccb84d65
JB
6732 inst.error = _("invalid barrier type"); \
6733 backtrack_pos = 0; \
6734 goto failure; \
52e7f43d
RE
6735 } \
6736 } \
6737 while (0)
6738
c19d1205
ZW
6739 skip_whitespace (str);
6740
6741 for (i = 0; upat[i] != OP_stop; i++)
6742 {
5be8be5d
DG
6743 op_parse_code = upat[i];
6744 if (op_parse_code >= 1<<16)
6745 op_parse_code = thumb ? (op_parse_code >> 16)
6746 : (op_parse_code & ((1<<16)-1));
6747
6748 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6749 {
6750 /* Remember where we are in case we need to backtrack. */
9c2799c2 6751 gas_assert (!backtrack_pos);
c19d1205
ZW
6752 backtrack_pos = str;
6753 backtrack_error = inst.error;
6754 backtrack_index = i;
6755 }
6756
b6702015 6757 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6758 po_char_or_fail (',');
6759
5be8be5d 6760 switch (op_parse_code)
c19d1205
ZW
6761 {
6762 /* Registers */
6763 case OP_oRRnpc:
5be8be5d 6764 case OP_oRRnpcsp:
c19d1205 6765 case OP_RRnpc:
5be8be5d 6766 case OP_RRnpcsp:
c19d1205
ZW
6767 case OP_oRR:
6768 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6769 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6770 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6771 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6772 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6773 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6774 case OP_oRND:
5287ad62 6775 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6776 case OP_RVC:
6777 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6778 break;
6779 /* Also accept generic coprocessor regs for unknown registers. */
6780 coproc_reg:
6781 po_reg_or_fail (REG_TYPE_CN);
6782 break;
c19d1205
ZW
6783 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6784 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6785 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6786 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6787 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6788 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6789 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6790 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6791 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6792 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6793 case OP_oRNQ:
5287ad62 6794 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6795 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6796 case OP_oRNDQ:
5287ad62 6797 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6798 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6799 case OP_oRNSDQ:
6800 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6801
6802 /* Neon scalar. Using an element size of 8 means that some invalid
6803 scalars are accepted here, so deal with those in later code. */
6804 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6805
6806 case OP_RNDQ_I0:
6807 {
6808 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6809 break;
6810 try_imm0:
6811 po_imm_or_fail (0, 0, TRUE);
6812 }
6813 break;
6814
6815 case OP_RVSD_I0:
6816 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6817 break;
6818
aacf0b33
KT
6819 case OP_RSVD_FI0:
6820 {
6821 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6822 break;
6823 try_ifimm0:
6824 if (parse_ifimm_zero (&str))
6825 inst.operands[i].imm = 0;
6826 else
6827 {
6828 inst.error
6829 = _("only floating point zero is allowed as immediate value");
6830 goto failure;
6831 }
6832 }
6833 break;
6834
477330fc
RM
6835 case OP_RR_RNSC:
6836 {
6837 po_scalar_or_goto (8, try_rr);
6838 break;
6839 try_rr:
6840 po_reg_or_fail (REG_TYPE_RN);
6841 }
6842 break;
6843
6844 case OP_RNSDQ_RNSC:
6845 {
6846 po_scalar_or_goto (8, try_nsdq);
6847 break;
6848 try_nsdq:
6849 po_reg_or_fail (REG_TYPE_NSDQ);
6850 }
6851 break;
6852
dec41383
JW
6853 case OP_RNSD_RNSC:
6854 {
6855 po_scalar_or_goto (8, try_s_scalar);
6856 break;
6857 try_s_scalar:
6858 po_scalar_or_goto (4, try_nsd);
6859 break;
6860 try_nsd:
6861 po_reg_or_fail (REG_TYPE_NSD);
6862 }
6863 break;
6864
477330fc
RM
6865 case OP_RNDQ_RNSC:
6866 {
6867 po_scalar_or_goto (8, try_ndq);
6868 break;
6869 try_ndq:
6870 po_reg_or_fail (REG_TYPE_NDQ);
6871 }
6872 break;
6873
6874 case OP_RND_RNSC:
6875 {
6876 po_scalar_or_goto (8, try_vfd);
6877 break;
6878 try_vfd:
6879 po_reg_or_fail (REG_TYPE_VFD);
6880 }
6881 break;
6882
6883 case OP_VMOV:
6884 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6885 not careful then bad things might happen. */
6886 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6887 break;
6888
6889 case OP_RNDQ_Ibig:
6890 {
6891 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6892 break;
6893 try_immbig:
6894 /* There's a possibility of getting a 64-bit immediate here, so
6895 we need special handling. */
8335d6aa
JW
6896 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6897 == FAIL)
477330fc
RM
6898 {
6899 inst.error = _("immediate value is out of range");
6900 goto failure;
6901 }
6902 }
6903 break;
6904
6905 case OP_RNDQ_I63b:
6906 {
6907 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6908 break;
6909 try_shimm:
6910 po_imm_or_fail (0, 63, TRUE);
6911 }
6912 break;
c19d1205
ZW
6913
6914 case OP_RRnpcb:
6915 po_char_or_fail ('[');
6916 po_reg_or_fail (REG_TYPE_RN);
6917 po_char_or_fail (']');
6918 break;
a737bd4d 6919
55881a11 6920 case OP_RRnpctw:
c19d1205 6921 case OP_RRw:
b6702015 6922 case OP_oRRw:
c19d1205
ZW
6923 po_reg_or_fail (REG_TYPE_RN);
6924 if (skip_past_char (&str, '!') == SUCCESS)
6925 inst.operands[i].writeback = 1;
6926 break;
6927
6928 /* Immediates */
6929 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6930 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6931 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6932 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6933 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6934 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6935 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6936 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6937 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6938 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6939 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6940 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6941
6942 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6943 case OP_oI7b:
6944 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6945 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6946 case OP_oI31b:
6947 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6948 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6949 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6950 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6951
6952 /* Immediate variants */
6953 case OP_oI255c:
6954 po_char_or_fail ('{');
6955 po_imm_or_fail (0, 255, TRUE);
6956 po_char_or_fail ('}');
6957 break;
6958
6959 case OP_I31w:
6960 /* The expression parser chokes on a trailing !, so we have
6961 to find it first and zap it. */
6962 {
6963 char *s = str;
6964 while (*s && *s != ',')
6965 s++;
6966 if (s[-1] == '!')
6967 {
6968 s[-1] = '\0';
6969 inst.operands[i].writeback = 1;
6970 }
6971 po_imm_or_fail (0, 31, TRUE);
6972 if (str == s - 1)
6973 str = s;
6974 }
6975 break;
6976
6977 /* Expressions */
6978 case OP_EXPi: EXPi:
6979 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6980 GE_OPT_PREFIX));
6981 break;
6982
6983 case OP_EXP:
6984 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6985 GE_NO_PREFIX));
6986 break;
6987
6988 case OP_EXPr: EXPr:
6989 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6990 GE_NO_PREFIX));
6991 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6992 {
c19d1205
ZW
6993 val = parse_reloc (&str);
6994 if (val == -1)
6995 {
6996 inst.error = _("unrecognized relocation suffix");
6997 goto failure;
6998 }
6999 else if (val != BFD_RELOC_UNUSED)
7000 {
7001 inst.operands[i].imm = val;
7002 inst.operands[i].hasreloc = 1;
7003 }
a737bd4d 7004 }
c19d1205 7005 break;
a737bd4d 7006
b6895b4f
PB
7007 /* Operand for MOVW or MOVT. */
7008 case OP_HALF:
7009 po_misc_or_fail (parse_half (&str));
7010 break;
7011
e07e6e58 7012 /* Register or expression. */
c19d1205
ZW
7013 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7014 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7015
e07e6e58 7016 /* Register or immediate. */
c19d1205
ZW
7017 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7018 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7019
c19d1205
ZW
7020 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7021 IF:
7022 if (!is_immediate_prefix (*str))
7023 goto bad_args;
7024 str++;
7025 val = parse_fpa_immediate (&str);
7026 if (val == FAIL)
7027 goto failure;
7028 /* FPA immediates are encoded as registers 8-15.
7029 parse_fpa_immediate has already applied the offset. */
7030 inst.operands[i].reg = val;
7031 inst.operands[i].isreg = 1;
7032 break;
09d92015 7033
2d447fca
JM
7034 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7035 I32z: po_imm_or_fail (0, 32, FALSE); break;
7036
e07e6e58 7037 /* Two kinds of register. */
c19d1205
ZW
7038 case OP_RIWR_RIWC:
7039 {
7040 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7041 if (!rege
7042 || (rege->type != REG_TYPE_MMXWR
7043 && rege->type != REG_TYPE_MMXWC
7044 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7045 {
7046 inst.error = _("iWMMXt data or control register expected");
7047 goto failure;
7048 }
7049 inst.operands[i].reg = rege->number;
7050 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7051 }
7052 break;
09d92015 7053
41adaa5c
JM
7054 case OP_RIWC_RIWG:
7055 {
7056 struct reg_entry *rege = arm_reg_parse_multi (&str);
7057 if (!rege
7058 || (rege->type != REG_TYPE_MMXWC
7059 && rege->type != REG_TYPE_MMXWCG))
7060 {
7061 inst.error = _("iWMMXt control register expected");
7062 goto failure;
7063 }
7064 inst.operands[i].reg = rege->number;
7065 inst.operands[i].isreg = 1;
7066 }
7067 break;
7068
c19d1205
ZW
7069 /* Misc */
7070 case OP_CPSF: val = parse_cps_flags (&str); break;
7071 case OP_ENDI: val = parse_endian_specifier (&str); break;
7072 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7073 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7074 case OP_oBARRIER_I15:
7075 po_barrier_or_imm (str); break;
7076 immediate:
7077 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7078 goto failure;
52e7f43d 7079 break;
c19d1205 7080
fa94de6b 7081 case OP_wPSR:
d2cd1205 7082 case OP_rPSR:
90ec0d68
MGD
7083 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7084 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7085 {
7086 inst.error = _("Banked registers are not available with this "
7087 "architecture.");
7088 goto failure;
7089 }
7090 break;
d2cd1205
JB
7091 try_psr:
7092 val = parse_psr (&str, op_parse_code == OP_wPSR);
7093 break;
037e8744 7094
477330fc
RM
7095 case OP_APSR_RR:
7096 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7097 break;
7098 try_apsr:
7099 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7100 instruction). */
7101 if (strncasecmp (str, "APSR_", 5) == 0)
7102 {
7103 unsigned found = 0;
7104 str += 5;
7105 while (found < 15)
7106 switch (*str++)
7107 {
7108 case 'c': found = (found & 1) ? 16 : found | 1; break;
7109 case 'n': found = (found & 2) ? 16 : found | 2; break;
7110 case 'z': found = (found & 4) ? 16 : found | 4; break;
7111 case 'v': found = (found & 8) ? 16 : found | 8; break;
7112 default: found = 16;
7113 }
7114 if (found != 15)
7115 goto failure;
7116 inst.operands[i].isvec = 1;
f7c21dc7
NC
7117 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7118 inst.operands[i].reg = REG_PC;
477330fc
RM
7119 }
7120 else
7121 goto failure;
7122 break;
037e8744 7123
92e90b6e
PB
7124 case OP_TB:
7125 po_misc_or_fail (parse_tb (&str));
7126 break;
7127
e07e6e58 7128 /* Register lists. */
c19d1205
ZW
7129 case OP_REGLST:
7130 val = parse_reg_list (&str);
7131 if (*str == '^')
7132 {
5e0d7f77 7133 inst.operands[i].writeback = 1;
c19d1205
ZW
7134 str++;
7135 }
7136 break;
09d92015 7137
c19d1205 7138 case OP_VRSLST:
5287ad62 7139 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7140 break;
09d92015 7141
c19d1205 7142 case OP_VRDLST:
5287ad62 7143 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7144 break;
a737bd4d 7145
477330fc
RM
7146 case OP_VRSDLST:
7147 /* Allow Q registers too. */
7148 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7149 REGLIST_NEON_D);
7150 if (val == FAIL)
7151 {
7152 inst.error = NULL;
7153 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7154 REGLIST_VFP_S);
7155 inst.operands[i].issingle = 1;
7156 }
7157 break;
7158
7159 case OP_NRDLST:
7160 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7161 REGLIST_NEON_D);
7162 break;
5287ad62
JB
7163
7164 case OP_NSTRLST:
477330fc
RM
7165 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7166 &inst.operands[i].vectype);
7167 break;
5287ad62 7168
c19d1205
ZW
7169 /* Addressing modes */
7170 case OP_ADDR:
7171 po_misc_or_fail (parse_address (&str, i));
7172 break;
09d92015 7173
4962c51a
MS
7174 case OP_ADDRGLDR:
7175 po_misc_or_fail_no_backtrack (
477330fc 7176 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7177 break;
7178
7179 case OP_ADDRGLDRS:
7180 po_misc_or_fail_no_backtrack (
477330fc 7181 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7182 break;
7183
7184 case OP_ADDRGLDC:
7185 po_misc_or_fail_no_backtrack (
477330fc 7186 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7187 break;
7188
c19d1205
ZW
7189 case OP_SH:
7190 po_misc_or_fail (parse_shifter_operand (&str, i));
7191 break;
09d92015 7192
4962c51a
MS
7193 case OP_SHG:
7194 po_misc_or_fail_no_backtrack (
477330fc 7195 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7196 break;
7197
c19d1205
ZW
7198 case OP_oSHll:
7199 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7200 break;
09d92015 7201
c19d1205
ZW
7202 case OP_oSHar:
7203 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7204 break;
09d92015 7205
c19d1205
ZW
7206 case OP_oSHllar:
7207 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7208 break;
09d92015 7209
c19d1205 7210 default:
5be8be5d 7211 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7212 }
09d92015 7213
c19d1205
ZW
7214 /* Various value-based sanity checks and shared operations. We
7215 do not signal immediate failures for the register constraints;
7216 this allows a syntax error to take precedence. */
5be8be5d 7217 switch (op_parse_code)
c19d1205
ZW
7218 {
7219 case OP_oRRnpc:
7220 case OP_RRnpc:
7221 case OP_RRnpcb:
7222 case OP_RRw:
b6702015 7223 case OP_oRRw:
c19d1205
ZW
7224 case OP_RRnpc_I0:
7225 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7226 inst.error = BAD_PC;
7227 break;
09d92015 7228
5be8be5d
DG
7229 case OP_oRRnpcsp:
7230 case OP_RRnpcsp:
7231 if (inst.operands[i].isreg)
7232 {
7233 if (inst.operands[i].reg == REG_PC)
7234 inst.error = BAD_PC;
5c8ed6a4
JW
7235 else if (inst.operands[i].reg == REG_SP
7236 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7237 relaxed since ARMv8-A. */
7238 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7239 {
7240 gas_assert (thumb);
7241 inst.error = BAD_SP;
7242 }
5be8be5d
DG
7243 }
7244 break;
7245
55881a11 7246 case OP_RRnpctw:
fa94de6b
RM
7247 if (inst.operands[i].isreg
7248 && inst.operands[i].reg == REG_PC
55881a11
MGD
7249 && (inst.operands[i].writeback || thumb))
7250 inst.error = BAD_PC;
7251 break;
7252
c19d1205
ZW
7253 case OP_CPSF:
7254 case OP_ENDI:
7255 case OP_oROR:
d2cd1205
JB
7256 case OP_wPSR:
7257 case OP_rPSR:
c19d1205 7258 case OP_COND:
52e7f43d 7259 case OP_oBARRIER_I15:
c19d1205
ZW
7260 case OP_REGLST:
7261 case OP_VRSLST:
7262 case OP_VRDLST:
477330fc
RM
7263 case OP_VRSDLST:
7264 case OP_NRDLST:
7265 case OP_NSTRLST:
c19d1205
ZW
7266 if (val == FAIL)
7267 goto failure;
7268 inst.operands[i].imm = val;
7269 break;
a737bd4d 7270
c19d1205
ZW
7271 default:
7272 break;
7273 }
09d92015 7274
c19d1205
ZW
7275 /* If we get here, this operand was successfully parsed. */
7276 inst.operands[i].present = 1;
7277 continue;
09d92015 7278
c19d1205 7279 bad_args:
09d92015 7280 inst.error = BAD_ARGS;
c19d1205
ZW
7281
7282 failure:
7283 if (!backtrack_pos)
d252fdde
PB
7284 {
7285 /* The parse routine should already have set inst.error, but set a
5f4273c7 7286 default here just in case. */
d252fdde
PB
7287 if (!inst.error)
7288 inst.error = _("syntax error");
7289 return FAIL;
7290 }
c19d1205
ZW
7291
7292 /* Do not backtrack over a trailing optional argument that
7293 absorbed some text. We will only fail again, with the
7294 'garbage following instruction' error message, which is
7295 probably less helpful than the current one. */
7296 if (backtrack_index == i && backtrack_pos != str
7297 && upat[i+1] == OP_stop)
d252fdde
PB
7298 {
7299 if (!inst.error)
7300 inst.error = _("syntax error");
7301 return FAIL;
7302 }
c19d1205
ZW
7303
7304 /* Try again, skipping the optional argument at backtrack_pos. */
7305 str = backtrack_pos;
7306 inst.error = backtrack_error;
7307 inst.operands[backtrack_index].present = 0;
7308 i = backtrack_index;
7309 backtrack_pos = 0;
09d92015 7310 }
09d92015 7311
c19d1205
ZW
7312 /* Check that we have parsed all the arguments. */
7313 if (*str != '\0' && !inst.error)
7314 inst.error = _("garbage following instruction");
09d92015 7315
c19d1205 7316 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7317}
7318
c19d1205
ZW
7319#undef po_char_or_fail
7320#undef po_reg_or_fail
7321#undef po_reg_or_goto
7322#undef po_imm_or_fail
5287ad62 7323#undef po_scalar_or_fail
52e7f43d 7324#undef po_barrier_or_imm
e07e6e58 7325
c19d1205 7326/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7327#define constraint(expr, err) \
7328 do \
c19d1205 7329 { \
e07e6e58
NC
7330 if (expr) \
7331 { \
7332 inst.error = err; \
7333 return; \
7334 } \
c19d1205 7335 } \
e07e6e58 7336 while (0)
c19d1205 7337
fdfde340
JM
7338/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7339 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7340 is the BadReg predicate in ARM's Thumb-2 documentation.
7341
7342 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7343 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7344#define reject_bad_reg(reg) \
7345 do \
7346 if (reg == REG_PC) \
7347 { \
7348 inst.error = BAD_PC; \
7349 return; \
7350 } \
7351 else if (reg == REG_SP \
7352 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7353 { \
7354 inst.error = BAD_SP; \
7355 return; \
7356 } \
fdfde340
JM
7357 while (0)
7358
94206790
MM
7359/* If REG is R13 (the stack pointer), warn that its use is
7360 deprecated. */
7361#define warn_deprecated_sp(reg) \
7362 do \
7363 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7364 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7365 while (0)
7366
c19d1205
ZW
7367/* Functions for operand encoding. ARM, then Thumb. */
7368
d840c081 7369#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7370
9db2f6b4
RL
7371/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7372
7373 The only binary encoding difference is the Coprocessor number. Coprocessor
7374 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7375 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7376 exists for Single-Precision operation. */
7377
7378static void
7379do_scalar_fp16_v82_encode (void)
7380{
7381 if (inst.cond != COND_ALWAYS)
7382 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7383 " the behaviour is UNPREDICTABLE"));
7384 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7385 _(BAD_FP16));
7386
7387 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7388 mark_feature_used (&arm_ext_fp16);
7389}
7390
c19d1205
ZW
7391/* If VAL can be encoded in the immediate field of an ARM instruction,
7392 return the encoded form. Otherwise, return FAIL. */
7393
7394static unsigned int
7395encode_arm_immediate (unsigned int val)
09d92015 7396{
c19d1205
ZW
7397 unsigned int a, i;
7398
4f1d6205
L
7399 if (val <= 0xff)
7400 return val;
7401
7402 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7403 if ((a = rotate_left (val, i)) <= 0xff)
7404 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7405
7406 return FAIL;
09d92015
MM
7407}
7408
c19d1205
ZW
7409/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7410 return the encoded form. Otherwise, return FAIL. */
7411static unsigned int
7412encode_thumb32_immediate (unsigned int val)
09d92015 7413{
c19d1205 7414 unsigned int a, i;
09d92015 7415
9c3c69f2 7416 if (val <= 0xff)
c19d1205 7417 return val;
a737bd4d 7418
9c3c69f2 7419 for (i = 1; i <= 24; i++)
09d92015 7420 {
9c3c69f2
PB
7421 a = val >> i;
7422 if ((val & ~(0xff << i)) == 0)
7423 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7424 }
a737bd4d 7425
c19d1205
ZW
7426 a = val & 0xff;
7427 if (val == ((a << 16) | a))
7428 return 0x100 | a;
7429 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7430 return 0x300 | a;
09d92015 7431
c19d1205
ZW
7432 a = val & 0xff00;
7433 if (val == ((a << 16) | a))
7434 return 0x200 | (a >> 8);
a737bd4d 7435
c19d1205 7436 return FAIL;
09d92015 7437}
5287ad62 7438/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7439
7440static void
5287ad62
JB
7441encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7442{
7443 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7444 && reg > 15)
7445 {
b1cc4aeb 7446 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7447 {
7448 if (thumb_mode)
7449 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7450 fpu_vfp_ext_d32);
7451 else
7452 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7453 fpu_vfp_ext_d32);
7454 }
5287ad62 7455 else
477330fc
RM
7456 {
7457 first_error (_("D register out of range for selected VFP version"));
7458 return;
7459 }
5287ad62
JB
7460 }
7461
c19d1205 7462 switch (pos)
09d92015 7463 {
c19d1205
ZW
7464 case VFP_REG_Sd:
7465 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7466 break;
7467
7468 case VFP_REG_Sn:
7469 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7470 break;
7471
7472 case VFP_REG_Sm:
7473 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7474 break;
7475
5287ad62
JB
7476 case VFP_REG_Dd:
7477 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7478 break;
5f4273c7 7479
5287ad62
JB
7480 case VFP_REG_Dn:
7481 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7482 break;
5f4273c7 7483
5287ad62
JB
7484 case VFP_REG_Dm:
7485 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7486 break;
7487
c19d1205
ZW
7488 default:
7489 abort ();
09d92015 7490 }
09d92015
MM
7491}
7492
c19d1205 7493/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7494 if any, is handled by md_apply_fix. */
09d92015 7495static void
c19d1205 7496encode_arm_shift (int i)
09d92015 7497{
008a97ef
RL
7498 /* register-shifted register. */
7499 if (inst.operands[i].immisreg)
7500 {
bf355b69
MR
7501 int op_index;
7502 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7503 {
5689c942
RL
7504 /* Check the operand only when it's presented. In pre-UAL syntax,
7505 if the destination register is the same as the first operand, two
7506 register form of the instruction can be used. */
bf355b69
MR
7507 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7508 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7509 as_warn (UNPRED_REG ("r15"));
7510 }
7511
7512 if (inst.operands[i].imm == REG_PC)
7513 as_warn (UNPRED_REG ("r15"));
7514 }
7515
c19d1205
ZW
7516 if (inst.operands[i].shift_kind == SHIFT_RRX)
7517 inst.instruction |= SHIFT_ROR << 5;
7518 else
09d92015 7519 {
c19d1205
ZW
7520 inst.instruction |= inst.operands[i].shift_kind << 5;
7521 if (inst.operands[i].immisreg)
7522 {
7523 inst.instruction |= SHIFT_BY_REG;
7524 inst.instruction |= inst.operands[i].imm << 8;
7525 }
7526 else
7527 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7528 }
c19d1205 7529}
09d92015 7530
c19d1205
ZW
7531static void
7532encode_arm_shifter_operand (int i)
7533{
7534 if (inst.operands[i].isreg)
09d92015 7535 {
c19d1205
ZW
7536 inst.instruction |= inst.operands[i].reg;
7537 encode_arm_shift (i);
09d92015 7538 }
c19d1205 7539 else
a415b1cd
JB
7540 {
7541 inst.instruction |= INST_IMMEDIATE;
7542 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7543 inst.instruction |= inst.operands[i].imm;
7544 }
09d92015
MM
7545}
7546
c19d1205 7547/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7548static void
c19d1205 7549encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7550{
2b2f5df9
NC
7551 /* PR 14260:
7552 Generate an error if the operand is not a register. */
7553 constraint (!inst.operands[i].isreg,
7554 _("Instruction does not support =N addresses"));
7555
c19d1205 7556 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7557
c19d1205 7558 if (inst.operands[i].preind)
09d92015 7559 {
c19d1205
ZW
7560 if (is_t)
7561 {
7562 inst.error = _("instruction does not accept preindexed addressing");
7563 return;
7564 }
7565 inst.instruction |= PRE_INDEX;
7566 if (inst.operands[i].writeback)
7567 inst.instruction |= WRITE_BACK;
09d92015 7568
c19d1205
ZW
7569 }
7570 else if (inst.operands[i].postind)
7571 {
9c2799c2 7572 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7573 if (is_t)
7574 inst.instruction |= WRITE_BACK;
7575 }
7576 else /* unindexed - only for coprocessor */
09d92015 7577 {
c19d1205 7578 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7579 return;
7580 }
7581
c19d1205
ZW
7582 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7583 && (((inst.instruction & 0x000f0000) >> 16)
7584 == ((inst.instruction & 0x0000f000) >> 12)))
7585 as_warn ((inst.instruction & LOAD_BIT)
7586 ? _("destination register same as write-back base")
7587 : _("source register same as write-back base"));
09d92015
MM
7588}
7589
c19d1205
ZW
7590/* inst.operands[i] was set up by parse_address. Encode it into an
7591 ARM-format mode 2 load or store instruction. If is_t is true,
7592 reject forms that cannot be used with a T instruction (i.e. not
7593 post-indexed). */
a737bd4d 7594static void
c19d1205 7595encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7596{
5be8be5d
DG
7597 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7598
c19d1205 7599 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7600
c19d1205 7601 if (inst.operands[i].immisreg)
09d92015 7602 {
5be8be5d
DG
7603 constraint ((inst.operands[i].imm == REG_PC
7604 || (is_pc && inst.operands[i].writeback)),
7605 BAD_PC_ADDRESSING);
c19d1205
ZW
7606 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7607 inst.instruction |= inst.operands[i].imm;
7608 if (!inst.operands[i].negative)
7609 inst.instruction |= INDEX_UP;
7610 if (inst.operands[i].shifted)
7611 {
7612 if (inst.operands[i].shift_kind == SHIFT_RRX)
7613 inst.instruction |= SHIFT_ROR << 5;
7614 else
7615 {
7616 inst.instruction |= inst.operands[i].shift_kind << 5;
7617 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7618 }
7619 }
09d92015 7620 }
c19d1205 7621 else /* immediate offset in inst.reloc */
09d92015 7622 {
5be8be5d
DG
7623 if (is_pc && !inst.reloc.pc_rel)
7624 {
7625 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7626
7627 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7628 cannot use PC in addressing.
7629 PC cannot be used in writeback addressing, either. */
7630 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7631 BAD_PC_ADDRESSING);
23a10334 7632
dc5ec521 7633 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7634 if (warn_on_deprecated
7635 && !is_load
7636 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7637 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7638 }
7639
c19d1205 7640 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7641 {
7642 /* Prefer + for zero encoded value. */
7643 if (!inst.operands[i].negative)
7644 inst.instruction |= INDEX_UP;
7645 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7646 }
09d92015 7647 }
09d92015
MM
7648}
7649
c19d1205
ZW
7650/* inst.operands[i] was set up by parse_address. Encode it into an
7651 ARM-format mode 3 load or store instruction. Reject forms that
7652 cannot be used with such instructions. If is_t is true, reject
7653 forms that cannot be used with a T instruction (i.e. not
7654 post-indexed). */
7655static void
7656encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7657{
c19d1205 7658 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7659 {
c19d1205
ZW
7660 inst.error = _("instruction does not accept scaled register index");
7661 return;
09d92015 7662 }
a737bd4d 7663
c19d1205 7664 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7665
c19d1205
ZW
7666 if (inst.operands[i].immisreg)
7667 {
5be8be5d 7668 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7669 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7670 BAD_PC_ADDRESSING);
eb9f3f00
JB
7671 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7672 BAD_PC_WRITEBACK);
c19d1205
ZW
7673 inst.instruction |= inst.operands[i].imm;
7674 if (!inst.operands[i].negative)
7675 inst.instruction |= INDEX_UP;
7676 }
7677 else /* immediate offset in inst.reloc */
7678 {
5be8be5d
DG
7679 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7680 && inst.operands[i].writeback),
7681 BAD_PC_WRITEBACK);
c19d1205
ZW
7682 inst.instruction |= HWOFFSET_IMM;
7683 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7684 {
7685 /* Prefer + for zero encoded value. */
7686 if (!inst.operands[i].negative)
7687 inst.instruction |= INDEX_UP;
7688
7689 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7690 }
c19d1205 7691 }
a737bd4d
NC
7692}
7693
8335d6aa
JW
7694/* Write immediate bits [7:0] to the following locations:
7695
7696 |28/24|23 19|18 16|15 4|3 0|
7697 | 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|
7698
7699 This function is used by VMOV/VMVN/VORR/VBIC. */
7700
7701static void
7702neon_write_immbits (unsigned immbits)
7703{
7704 inst.instruction |= immbits & 0xf;
7705 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7706 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7707}
7708
7709/* Invert low-order SIZE bits of XHI:XLO. */
7710
7711static void
7712neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7713{
7714 unsigned immlo = xlo ? *xlo : 0;
7715 unsigned immhi = xhi ? *xhi : 0;
7716
7717 switch (size)
7718 {
7719 case 8:
7720 immlo = (~immlo) & 0xff;
7721 break;
7722
7723 case 16:
7724 immlo = (~immlo) & 0xffff;
7725 break;
7726
7727 case 64:
7728 immhi = (~immhi) & 0xffffffff;
7729 /* fall through. */
7730
7731 case 32:
7732 immlo = (~immlo) & 0xffffffff;
7733 break;
7734
7735 default:
7736 abort ();
7737 }
7738
7739 if (xlo)
7740 *xlo = immlo;
7741
7742 if (xhi)
7743 *xhi = immhi;
7744}
7745
7746/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7747 A, B, C, D. */
09d92015 7748
c19d1205 7749static int
8335d6aa 7750neon_bits_same_in_bytes (unsigned imm)
09d92015 7751{
8335d6aa
JW
7752 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7753 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7754 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7755 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7756}
a737bd4d 7757
8335d6aa 7758/* For immediate of above form, return 0bABCD. */
09d92015 7759
8335d6aa
JW
7760static unsigned
7761neon_squash_bits (unsigned imm)
7762{
7763 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7764 | ((imm & 0x01000000) >> 21);
7765}
7766
7767/* Compress quarter-float representation to 0b...000 abcdefgh. */
7768
7769static unsigned
7770neon_qfloat_bits (unsigned imm)
7771{
7772 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7773}
7774
7775/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7776 the instruction. *OP is passed as the initial value of the op field, and
7777 may be set to a different value depending on the constant (i.e.
7778 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7779 MVN). If the immediate looks like a repeated pattern then also
7780 try smaller element sizes. */
7781
7782static int
7783neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7784 unsigned *immbits, int *op, int size,
7785 enum neon_el_type type)
7786{
7787 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7788 float. */
7789 if (type == NT_float && !float_p)
7790 return FAIL;
7791
7792 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7793 {
8335d6aa
JW
7794 if (size != 32 || *op == 1)
7795 return FAIL;
7796 *immbits = neon_qfloat_bits (immlo);
7797 return 0xf;
7798 }
7799
7800 if (size == 64)
7801 {
7802 if (neon_bits_same_in_bytes (immhi)
7803 && neon_bits_same_in_bytes (immlo))
c19d1205 7804 {
8335d6aa
JW
7805 if (*op == 1)
7806 return FAIL;
7807 *immbits = (neon_squash_bits (immhi) << 4)
7808 | neon_squash_bits (immlo);
7809 *op = 1;
7810 return 0xe;
c19d1205 7811 }
a737bd4d 7812
8335d6aa
JW
7813 if (immhi != immlo)
7814 return FAIL;
7815 }
a737bd4d 7816
8335d6aa 7817 if (size >= 32)
09d92015 7818 {
8335d6aa 7819 if (immlo == (immlo & 0x000000ff))
c19d1205 7820 {
8335d6aa
JW
7821 *immbits = immlo;
7822 return 0x0;
c19d1205 7823 }
8335d6aa 7824 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7825 {
8335d6aa
JW
7826 *immbits = immlo >> 8;
7827 return 0x2;
c19d1205 7828 }
8335d6aa
JW
7829 else if (immlo == (immlo & 0x00ff0000))
7830 {
7831 *immbits = immlo >> 16;
7832 return 0x4;
7833 }
7834 else if (immlo == (immlo & 0xff000000))
7835 {
7836 *immbits = immlo >> 24;
7837 return 0x6;
7838 }
7839 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7840 {
7841 *immbits = (immlo >> 8) & 0xff;
7842 return 0xc;
7843 }
7844 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7845 {
7846 *immbits = (immlo >> 16) & 0xff;
7847 return 0xd;
7848 }
7849
7850 if ((immlo & 0xffff) != (immlo >> 16))
7851 return FAIL;
7852 immlo &= 0xffff;
09d92015 7853 }
a737bd4d 7854
8335d6aa 7855 if (size >= 16)
4962c51a 7856 {
8335d6aa
JW
7857 if (immlo == (immlo & 0x000000ff))
7858 {
7859 *immbits = immlo;
7860 return 0x8;
7861 }
7862 else if (immlo == (immlo & 0x0000ff00))
7863 {
7864 *immbits = immlo >> 8;
7865 return 0xa;
7866 }
7867
7868 if ((immlo & 0xff) != (immlo >> 8))
7869 return FAIL;
7870 immlo &= 0xff;
4962c51a
MS
7871 }
7872
8335d6aa
JW
7873 if (immlo == (immlo & 0x000000ff))
7874 {
7875 /* Don't allow MVN with 8-bit immediate. */
7876 if (*op == 1)
7877 return FAIL;
7878 *immbits = immlo;
7879 return 0xe;
7880 }
26d97720 7881
8335d6aa 7882 return FAIL;
c19d1205 7883}
a737bd4d 7884
5fc177c8 7885#if defined BFD_HOST_64_BIT
ba592044
AM
7886/* Returns TRUE if double precision value V may be cast
7887 to single precision without loss of accuracy. */
7888
7889static bfd_boolean
5fc177c8 7890is_double_a_single (bfd_int64_t v)
ba592044 7891{
5fc177c8 7892 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7893 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7894
7895 return (exp == 0 || exp == 0x7FF
7896 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7897 && (mantissa & 0x1FFFFFFFl) == 0;
7898}
7899
3739860c 7900/* Returns a double precision value casted to single precision
ba592044
AM
7901 (ignoring the least significant bits in exponent and mantissa). */
7902
7903static int
5fc177c8 7904double_to_single (bfd_int64_t v)
ba592044
AM
7905{
7906 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7907 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7908 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7909
7910 if (exp == 0x7FF)
7911 exp = 0xFF;
7912 else
7913 {
7914 exp = exp - 1023 + 127;
7915 if (exp >= 0xFF)
7916 {
7917 /* Infinity. */
7918 exp = 0x7F;
7919 mantissa = 0;
7920 }
7921 else if (exp < 0)
7922 {
7923 /* No denormalized numbers. */
7924 exp = 0;
7925 mantissa = 0;
7926 }
7927 }
7928 mantissa >>= 29;
7929 return (sign << 31) | (exp << 23) | mantissa;
7930}
5fc177c8 7931#endif /* BFD_HOST_64_BIT */
ba592044 7932
8335d6aa
JW
7933enum lit_type
7934{
7935 CONST_THUMB,
7936 CONST_ARM,
7937 CONST_VEC
7938};
7939
ba592044
AM
7940static void do_vfp_nsyn_opcode (const char *);
7941
c19d1205
ZW
7942/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7943 Determine whether it can be performed with a move instruction; if
7944 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7945 return TRUE; if it can't, convert inst.instruction to a literal-pool
7946 load and return FALSE. If this is not a valid thing to do in the
7947 current context, set inst.error and return TRUE.
a737bd4d 7948
c19d1205
ZW
7949 inst.operands[i] describes the destination register. */
7950
c921be7d 7951static bfd_boolean
8335d6aa 7952move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7953{
53365c0d 7954 unsigned long tbit;
8335d6aa
JW
7955 bfd_boolean thumb_p = (t == CONST_THUMB);
7956 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7957
7958 if (thumb_p)
7959 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7960 else
7961 tbit = LOAD_BIT;
7962
7963 if ((inst.instruction & tbit) == 0)
09d92015 7964 {
c19d1205 7965 inst.error = _("invalid pseudo operation");
c921be7d 7966 return TRUE;
09d92015 7967 }
ba592044 7968
8335d6aa
JW
7969 if (inst.reloc.exp.X_op != O_constant
7970 && inst.reloc.exp.X_op != O_symbol
7971 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7972 {
7973 inst.error = _("constant expression expected");
c921be7d 7974 return TRUE;
09d92015 7975 }
ba592044
AM
7976
7977 if (inst.reloc.exp.X_op == O_constant
7978 || inst.reloc.exp.X_op == O_big)
8335d6aa 7979 {
5fc177c8
NC
7980#if defined BFD_HOST_64_BIT
7981 bfd_int64_t v;
7982#else
ba592044 7983 offsetT v;
5fc177c8 7984#endif
ba592044 7985 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7986 {
ba592044
AM
7987 LITTLENUM_TYPE w[X_PRECISION];
7988 LITTLENUM_TYPE * l;
7989
7990 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7991 {
ba592044
AM
7992 gen_to_words (w, X_PRECISION, E_PRECISION);
7993 l = w;
7994 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7995 }
ba592044
AM
7996 else
7997 l = generic_bignum;
3739860c 7998
5fc177c8
NC
7999#if defined BFD_HOST_64_BIT
8000 v =
8001 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8002 << LITTLENUM_NUMBER_OF_BITS)
8003 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8004 << LITTLENUM_NUMBER_OF_BITS)
8005 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8006 << LITTLENUM_NUMBER_OF_BITS)
8007 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8008#else
ba592044
AM
8009 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8010 | (l[0] & LITTLENUM_MASK);
5fc177c8 8011#endif
8335d6aa 8012 }
ba592044
AM
8013 else
8014 v = inst.reloc.exp.X_add_number;
8015
8016 if (!inst.operands[i].issingle)
8335d6aa 8017 {
12569877 8018 if (thumb_p)
8335d6aa 8019 {
53445554
TP
8020 /* LDR should not use lead in a flag-setting instruction being
8021 chosen so we do not check whether movs can be used. */
12569877 8022
53445554 8023 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8024 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8025 && inst.operands[i].reg != 13
8026 && inst.operands[i].reg != 15)
12569877 8027 {
fc289b0a
TP
8028 /* Check if on thumb2 it can be done with a mov.w, mvn or
8029 movw instruction. */
12569877
AM
8030 unsigned int newimm;
8031 bfd_boolean isNegated;
8032
8033 newimm = encode_thumb32_immediate (v);
8034 if (newimm != (unsigned int) FAIL)
8035 isNegated = FALSE;
8036 else
8037 {
582cfe03 8038 newimm = encode_thumb32_immediate (~v);
12569877
AM
8039 if (newimm != (unsigned int) FAIL)
8040 isNegated = TRUE;
8041 }
8042
fc289b0a
TP
8043 /* The number can be loaded with a mov.w or mvn
8044 instruction. */
ff8646ee
TP
8045 if (newimm != (unsigned int) FAIL
8046 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8047 {
fc289b0a 8048 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8049 | (inst.operands[i].reg << 8));
fc289b0a 8050 /* Change to MOVN. */
582cfe03 8051 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8052 inst.instruction |= (newimm & 0x800) << 15;
8053 inst.instruction |= (newimm & 0x700) << 4;
8054 inst.instruction |= (newimm & 0x0ff);
8055 return TRUE;
8056 }
fc289b0a 8057 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8058 else if ((v & ~0xFFFF) == 0
8059 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8060 {
582cfe03 8061 int imm = v & 0xFFFF;
12569877 8062
582cfe03 8063 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8064 inst.instruction |= (inst.operands[i].reg << 8);
8065 inst.instruction |= (imm & 0xf000) << 4;
8066 inst.instruction |= (imm & 0x0800) << 15;
8067 inst.instruction |= (imm & 0x0700) << 4;
8068 inst.instruction |= (imm & 0x00ff);
8069 return TRUE;
8070 }
8071 }
8335d6aa 8072 }
12569877 8073 else if (arm_p)
ba592044
AM
8074 {
8075 int value = encode_arm_immediate (v);
12569877 8076
ba592044
AM
8077 if (value != FAIL)
8078 {
8079 /* This can be done with a mov instruction. */
8080 inst.instruction &= LITERAL_MASK;
8081 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8082 inst.instruction |= value & 0xfff;
8083 return TRUE;
8084 }
8335d6aa 8085
ba592044
AM
8086 value = encode_arm_immediate (~ v);
8087 if (value != FAIL)
8088 {
8089 /* This can be done with a mvn instruction. */
8090 inst.instruction &= LITERAL_MASK;
8091 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8092 inst.instruction |= value & 0xfff;
8093 return TRUE;
8094 }
8095 }
934c2632 8096 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8097 {
ba592044
AM
8098 int op = 0;
8099 unsigned immbits = 0;
8100 unsigned immlo = inst.operands[1].imm;
8101 unsigned immhi = inst.operands[1].regisimm
8102 ? inst.operands[1].reg
8103 : inst.reloc.exp.X_unsigned
8104 ? 0
8105 : ((bfd_int64_t)((int) immlo)) >> 32;
8106 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8107 &op, 64, NT_invtype);
8108
8109 if (cmode == FAIL)
8110 {
8111 neon_invert_size (&immlo, &immhi, 64);
8112 op = !op;
8113 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8114 &op, 64, NT_invtype);
8115 }
8116
8117 if (cmode != FAIL)
8118 {
8119 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8120 | (1 << 23)
8121 | (cmode << 8)
8122 | (op << 5)
8123 | (1 << 4);
8124
8125 /* Fill other bits in vmov encoding for both thumb and arm. */
8126 if (thumb_mode)
eff0bc54 8127 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8128 else
eff0bc54 8129 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8130 neon_write_immbits (immbits);
8131 return TRUE;
8132 }
8335d6aa
JW
8133 }
8134 }
8335d6aa 8135
ba592044
AM
8136 if (t == CONST_VEC)
8137 {
8138 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8139 if (inst.operands[i].issingle
8140 && is_quarter_float (inst.operands[1].imm)
8141 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8142 {
ba592044
AM
8143 inst.operands[1].imm =
8144 neon_qfloat_bits (v);
8145 do_vfp_nsyn_opcode ("fconsts");
8146 return TRUE;
8335d6aa 8147 }
5fc177c8
NC
8148
8149 /* If our host does not support a 64-bit type then we cannot perform
8150 the following optimization. This mean that there will be a
8151 discrepancy between the output produced by an assembler built for
8152 a 32-bit-only host and the output produced from a 64-bit host, but
8153 this cannot be helped. */
8154#if defined BFD_HOST_64_BIT
ba592044
AM
8155 else if (!inst.operands[1].issingle
8156 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8157 {
ba592044
AM
8158 if (is_double_a_single (v)
8159 && is_quarter_float (double_to_single (v)))
8160 {
8161 inst.operands[1].imm =
8162 neon_qfloat_bits (double_to_single (v));
8163 do_vfp_nsyn_opcode ("fconstd");
8164 return TRUE;
8165 }
8335d6aa 8166 }
5fc177c8 8167#endif
8335d6aa
JW
8168 }
8169 }
8170
8171 if (add_to_lit_pool ((!inst.operands[i].isvec
8172 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8173 return TRUE;
8174
8175 inst.operands[1].reg = REG_PC;
8176 inst.operands[1].isreg = 1;
8177 inst.operands[1].preind = 1;
8178 inst.reloc.pc_rel = 1;
8179 inst.reloc.type = (thumb_p
8180 ? BFD_RELOC_ARM_THUMB_OFFSET
8181 : (mode_3
8182 ? BFD_RELOC_ARM_HWLITERAL
8183 : BFD_RELOC_ARM_LITERAL));
8184 return FALSE;
8185}
8186
8187/* inst.operands[i] was set up by parse_address. Encode it into an
8188 ARM-format instruction. Reject all forms which cannot be encoded
8189 into a coprocessor load/store instruction. If wb_ok is false,
8190 reject use of writeback; if unind_ok is false, reject use of
8191 unindexed addressing. If reloc_override is not 0, use it instead
8192 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8193 (in which case it is preserved). */
8194
8195static int
8196encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8197{
8198 if (!inst.operands[i].isreg)
8199 {
99b2a2dd
NC
8200 /* PR 18256 */
8201 if (! inst.operands[0].isvec)
8202 {
8203 inst.error = _("invalid co-processor operand");
8204 return FAIL;
8205 }
8335d6aa
JW
8206 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8207 return SUCCESS;
8208 }
8209
8210 inst.instruction |= inst.operands[i].reg << 16;
8211
8212 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8213
8214 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8215 {
8216 gas_assert (!inst.operands[i].writeback);
8217 if (!unind_ok)
8218 {
8219 inst.error = _("instruction does not support unindexed addressing");
8220 return FAIL;
8221 }
8222 inst.instruction |= inst.operands[i].imm;
8223 inst.instruction |= INDEX_UP;
8224 return SUCCESS;
8225 }
8226
8227 if (inst.operands[i].preind)
8228 inst.instruction |= PRE_INDEX;
8229
8230 if (inst.operands[i].writeback)
09d92015 8231 {
8335d6aa 8232 if (inst.operands[i].reg == REG_PC)
c19d1205 8233 {
8335d6aa
JW
8234 inst.error = _("pc may not be used with write-back");
8235 return FAIL;
c19d1205 8236 }
8335d6aa 8237 if (!wb_ok)
c19d1205 8238 {
8335d6aa
JW
8239 inst.error = _("instruction does not support writeback");
8240 return FAIL;
c19d1205 8241 }
8335d6aa 8242 inst.instruction |= WRITE_BACK;
09d92015
MM
8243 }
8244
8335d6aa
JW
8245 if (reloc_override)
8246 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8247 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8248 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8249 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8250 {
8335d6aa
JW
8251 if (thumb_mode)
8252 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8253 else
8254 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8255 }
8335d6aa
JW
8256
8257 /* Prefer + for zero encoded value. */
8258 if (!inst.operands[i].negative)
8259 inst.instruction |= INDEX_UP;
8260
8261 return SUCCESS;
09d92015
MM
8262}
8263
5f4273c7 8264/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8265 First some generics; their names are taken from the conventional
8266 bit positions for register arguments in ARM format instructions. */
09d92015 8267
a737bd4d 8268static void
c19d1205 8269do_noargs (void)
09d92015 8270{
c19d1205 8271}
a737bd4d 8272
c19d1205
ZW
8273static void
8274do_rd (void)
8275{
8276 inst.instruction |= inst.operands[0].reg << 12;
8277}
a737bd4d 8278
16a1fa25
TP
8279static void
8280do_rn (void)
8281{
8282 inst.instruction |= inst.operands[0].reg << 16;
8283}
8284
c19d1205
ZW
8285static void
8286do_rd_rm (void)
8287{
8288 inst.instruction |= inst.operands[0].reg << 12;
8289 inst.instruction |= inst.operands[1].reg;
8290}
09d92015 8291
9eb6c0f1
MGD
8292static void
8293do_rm_rn (void)
8294{
8295 inst.instruction |= inst.operands[0].reg;
8296 inst.instruction |= inst.operands[1].reg << 16;
8297}
8298
c19d1205
ZW
8299static void
8300do_rd_rn (void)
8301{
8302 inst.instruction |= inst.operands[0].reg << 12;
8303 inst.instruction |= inst.operands[1].reg << 16;
8304}
a737bd4d 8305
c19d1205
ZW
8306static void
8307do_rn_rd (void)
8308{
8309 inst.instruction |= inst.operands[0].reg << 16;
8310 inst.instruction |= inst.operands[1].reg << 12;
8311}
09d92015 8312
4ed7ed8d
TP
8313static void
8314do_tt (void)
8315{
8316 inst.instruction |= inst.operands[0].reg << 8;
8317 inst.instruction |= inst.operands[1].reg << 16;
8318}
8319
59d09be6
MGD
8320static bfd_boolean
8321check_obsolete (const arm_feature_set *feature, const char *msg)
8322{
8323 if (ARM_CPU_IS_ANY (cpu_variant))
8324 {
5c3696f8 8325 as_tsktsk ("%s", msg);
59d09be6
MGD
8326 return TRUE;
8327 }
8328 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8329 {
8330 as_bad ("%s", msg);
8331 return TRUE;
8332 }
8333
8334 return FALSE;
8335}
8336
c19d1205
ZW
8337static void
8338do_rd_rm_rn (void)
8339{
9a64e435 8340 unsigned Rn = inst.operands[2].reg;
708587a4 8341 /* Enforce restrictions on SWP instruction. */
9a64e435 8342 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8343 {
8344 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8345 _("Rn must not overlap other operands"));
8346
59d09be6
MGD
8347 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8348 */
8349 if (!check_obsolete (&arm_ext_v8,
8350 _("swp{b} use is obsoleted for ARMv8 and later"))
8351 && warn_on_deprecated
8352 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8353 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8354 }
59d09be6 8355
c19d1205
ZW
8356 inst.instruction |= inst.operands[0].reg << 12;
8357 inst.instruction |= inst.operands[1].reg;
9a64e435 8358 inst.instruction |= Rn << 16;
c19d1205 8359}
09d92015 8360
c19d1205
ZW
8361static void
8362do_rd_rn_rm (void)
8363{
8364 inst.instruction |= inst.operands[0].reg << 12;
8365 inst.instruction |= inst.operands[1].reg << 16;
8366 inst.instruction |= inst.operands[2].reg;
8367}
a737bd4d 8368
c19d1205
ZW
8369static void
8370do_rm_rd_rn (void)
8371{
5be8be5d
DG
8372 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8373 constraint (((inst.reloc.exp.X_op != O_constant
8374 && inst.reloc.exp.X_op != O_illegal)
8375 || inst.reloc.exp.X_add_number != 0),
8376 BAD_ADDR_MODE);
c19d1205
ZW
8377 inst.instruction |= inst.operands[0].reg;
8378 inst.instruction |= inst.operands[1].reg << 12;
8379 inst.instruction |= inst.operands[2].reg << 16;
8380}
09d92015 8381
c19d1205
ZW
8382static void
8383do_imm0 (void)
8384{
8385 inst.instruction |= inst.operands[0].imm;
8386}
09d92015 8387
c19d1205
ZW
8388static void
8389do_rd_cpaddr (void)
8390{
8391 inst.instruction |= inst.operands[0].reg << 12;
8392 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8393}
a737bd4d 8394
c19d1205
ZW
8395/* ARM instructions, in alphabetical order by function name (except
8396 that wrapper functions appear immediately after the function they
8397 wrap). */
09d92015 8398
c19d1205
ZW
8399/* This is a pseudo-op of the form "adr rd, label" to be converted
8400 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8401
8402static void
c19d1205 8403do_adr (void)
09d92015 8404{
c19d1205 8405 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8406
c19d1205
ZW
8407 /* Frag hacking will turn this into a sub instruction if the offset turns
8408 out to be negative. */
8409 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8410 inst.reloc.pc_rel = 1;
2fc8bdac 8411 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8412
8413 if (inst.reloc.exp.X_op == O_symbol
8414 && inst.reloc.exp.X_add_symbol != NULL
8415 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8416 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8417 inst.reloc.exp.X_add_number += 1;
c19d1205 8418}
b99bd4ef 8419
c19d1205
ZW
8420/* This is a pseudo-op of the form "adrl rd, label" to be converted
8421 into a relative address of the form:
8422 add rd, pc, #low(label-.-8)"
8423 add rd, rd, #high(label-.-8)" */
b99bd4ef 8424
c19d1205
ZW
8425static void
8426do_adrl (void)
8427{
8428 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8429
c19d1205
ZW
8430 /* Frag hacking will turn this into a sub instruction if the offset turns
8431 out to be negative. */
8432 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8433 inst.reloc.pc_rel = 1;
8434 inst.size = INSN_SIZE * 2;
2fc8bdac 8435 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8436
8437 if (inst.reloc.exp.X_op == O_symbol
8438 && inst.reloc.exp.X_add_symbol != NULL
8439 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8440 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8441 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8442}
8443
b99bd4ef 8444static void
c19d1205 8445do_arit (void)
b99bd4ef 8446{
a9f02af8
MG
8447 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8448 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8449 THUMB1_RELOC_ONLY);
c19d1205
ZW
8450 if (!inst.operands[1].present)
8451 inst.operands[1].reg = inst.operands[0].reg;
8452 inst.instruction |= inst.operands[0].reg << 12;
8453 inst.instruction |= inst.operands[1].reg << 16;
8454 encode_arm_shifter_operand (2);
8455}
b99bd4ef 8456
62b3e311
PB
8457static void
8458do_barrier (void)
8459{
8460 if (inst.operands[0].present)
ccb84d65 8461 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8462 else
8463 inst.instruction |= 0xf;
8464}
8465
c19d1205
ZW
8466static void
8467do_bfc (void)
8468{
8469 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8470 constraint (msb > 32, _("bit-field extends past end of register"));
8471 /* The instruction encoding stores the LSB and MSB,
8472 not the LSB and width. */
8473 inst.instruction |= inst.operands[0].reg << 12;
8474 inst.instruction |= inst.operands[1].imm << 7;
8475 inst.instruction |= (msb - 1) << 16;
8476}
b99bd4ef 8477
c19d1205
ZW
8478static void
8479do_bfi (void)
8480{
8481 unsigned int msb;
b99bd4ef 8482
c19d1205
ZW
8483 /* #0 in second position is alternative syntax for bfc, which is
8484 the same instruction but with REG_PC in the Rm field. */
8485 if (!inst.operands[1].isreg)
8486 inst.operands[1].reg = REG_PC;
b99bd4ef 8487
c19d1205
ZW
8488 msb = inst.operands[2].imm + inst.operands[3].imm;
8489 constraint (msb > 32, _("bit-field extends past end of register"));
8490 /* The instruction encoding stores the LSB and MSB,
8491 not the LSB and width. */
8492 inst.instruction |= inst.operands[0].reg << 12;
8493 inst.instruction |= inst.operands[1].reg;
8494 inst.instruction |= inst.operands[2].imm << 7;
8495 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8496}
8497
b99bd4ef 8498static void
c19d1205 8499do_bfx (void)
b99bd4ef 8500{
c19d1205
ZW
8501 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8502 _("bit-field extends past end of register"));
8503 inst.instruction |= inst.operands[0].reg << 12;
8504 inst.instruction |= inst.operands[1].reg;
8505 inst.instruction |= inst.operands[2].imm << 7;
8506 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8507}
09d92015 8508
c19d1205
ZW
8509/* ARM V5 breakpoint instruction (argument parse)
8510 BKPT <16 bit unsigned immediate>
8511 Instruction is not conditional.
8512 The bit pattern given in insns[] has the COND_ALWAYS condition,
8513 and it is an error if the caller tried to override that. */
b99bd4ef 8514
c19d1205
ZW
8515static void
8516do_bkpt (void)
8517{
8518 /* Top 12 of 16 bits to bits 19:8. */
8519 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8520
c19d1205
ZW
8521 /* Bottom 4 of 16 bits to bits 3:0. */
8522 inst.instruction |= inst.operands[0].imm & 0xf;
8523}
09d92015 8524
c19d1205
ZW
8525static void
8526encode_branch (int default_reloc)
8527{
8528 if (inst.operands[0].hasreloc)
8529 {
0855e32b
NS
8530 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8531 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8532 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8533 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8534 ? BFD_RELOC_ARM_PLT32
8535 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8536 }
b99bd4ef 8537 else
9ae92b05 8538 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8539 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8540}
8541
b99bd4ef 8542static void
c19d1205 8543do_branch (void)
b99bd4ef 8544{
39b41c9c
PB
8545#ifdef OBJ_ELF
8546 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8547 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8548 else
8549#endif
8550 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8551}
8552
8553static void
8554do_bl (void)
8555{
8556#ifdef OBJ_ELF
8557 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8558 {
8559 if (inst.cond == COND_ALWAYS)
8560 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8561 else
8562 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8563 }
8564 else
8565#endif
8566 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8567}
b99bd4ef 8568
c19d1205
ZW
8569/* ARM V5 branch-link-exchange instruction (argument parse)
8570 BLX <target_addr> ie BLX(1)
8571 BLX{<condition>} <Rm> ie BLX(2)
8572 Unfortunately, there are two different opcodes for this mnemonic.
8573 So, the insns[].value is not used, and the code here zaps values
8574 into inst.instruction.
8575 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8576
c19d1205
ZW
8577static void
8578do_blx (void)
8579{
8580 if (inst.operands[0].isreg)
b99bd4ef 8581 {
c19d1205
ZW
8582 /* Arg is a register; the opcode provided by insns[] is correct.
8583 It is not illegal to do "blx pc", just useless. */
8584 if (inst.operands[0].reg == REG_PC)
8585 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8586
c19d1205
ZW
8587 inst.instruction |= inst.operands[0].reg;
8588 }
8589 else
b99bd4ef 8590 {
c19d1205 8591 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8592 conditionally, and the opcode must be adjusted.
8593 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8594 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8595 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8596 inst.instruction = 0xfa000000;
267bf995 8597 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8598 }
c19d1205
ZW
8599}
8600
8601static void
8602do_bx (void)
8603{
845b51d6
PB
8604 bfd_boolean want_reloc;
8605
c19d1205
ZW
8606 if (inst.operands[0].reg == REG_PC)
8607 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8608
c19d1205 8609 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8610 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8611 it is for ARMv4t or earlier. */
8612 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8613 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8614 want_reloc = TRUE;
8615
5ad34203 8616#ifdef OBJ_ELF
845b51d6 8617 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8618#endif
584206db 8619 want_reloc = FALSE;
845b51d6
PB
8620
8621 if (want_reloc)
8622 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8623}
8624
c19d1205
ZW
8625
8626/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8627
8628static void
c19d1205 8629do_bxj (void)
a737bd4d 8630{
c19d1205
ZW
8631 if (inst.operands[0].reg == REG_PC)
8632 as_tsktsk (_("use of r15 in bxj is not really useful"));
8633
8634 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8635}
8636
c19d1205
ZW
8637/* Co-processor data operation:
8638 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8639 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8640static void
8641do_cdp (void)
8642{
8643 inst.instruction |= inst.operands[0].reg << 8;
8644 inst.instruction |= inst.operands[1].imm << 20;
8645 inst.instruction |= inst.operands[2].reg << 12;
8646 inst.instruction |= inst.operands[3].reg << 16;
8647 inst.instruction |= inst.operands[4].reg;
8648 inst.instruction |= inst.operands[5].imm << 5;
8649}
a737bd4d
NC
8650
8651static void
c19d1205 8652do_cmp (void)
a737bd4d 8653{
c19d1205
ZW
8654 inst.instruction |= inst.operands[0].reg << 16;
8655 encode_arm_shifter_operand (1);
a737bd4d
NC
8656}
8657
c19d1205
ZW
8658/* Transfer between coprocessor and ARM registers.
8659 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8660 MRC2
8661 MCR{cond}
8662 MCR2
8663
8664 No special properties. */
09d92015 8665
dcbd0d71
MGD
8666struct deprecated_coproc_regs_s
8667{
8668 unsigned cp;
8669 int opc1;
8670 unsigned crn;
8671 unsigned crm;
8672 int opc2;
8673 arm_feature_set deprecated;
8674 arm_feature_set obsoleted;
8675 const char *dep_msg;
8676 const char *obs_msg;
8677};
8678
8679#define DEPR_ACCESS_V8 \
8680 N_("This coprocessor register access is deprecated in ARMv8")
8681
8682/* Table of all deprecated coprocessor registers. */
8683static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8684{
8685 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8686 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8687 DEPR_ACCESS_V8, NULL},
8688 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8689 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8690 DEPR_ACCESS_V8, NULL},
8691 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8692 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8693 DEPR_ACCESS_V8, NULL},
8694 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8695 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8696 DEPR_ACCESS_V8, NULL},
8697 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8698 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8699 DEPR_ACCESS_V8, NULL},
8700};
8701
8702#undef DEPR_ACCESS_V8
8703
8704static const size_t deprecated_coproc_reg_count =
8705 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8706
09d92015 8707static void
c19d1205 8708do_co_reg (void)
09d92015 8709{
fdfde340 8710 unsigned Rd;
dcbd0d71 8711 size_t i;
fdfde340
JM
8712
8713 Rd = inst.operands[2].reg;
8714 if (thumb_mode)
8715 {
8716 if (inst.instruction == 0xee000010
8717 || inst.instruction == 0xfe000010)
8718 /* MCR, MCR2 */
8719 reject_bad_reg (Rd);
5c8ed6a4 8720 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8721 /* MRC, MRC2 */
8722 constraint (Rd == REG_SP, BAD_SP);
8723 }
8724 else
8725 {
8726 /* MCR */
8727 if (inst.instruction == 0xe000010)
8728 constraint (Rd == REG_PC, BAD_PC);
8729 }
8730
dcbd0d71
MGD
8731 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8732 {
8733 const struct deprecated_coproc_regs_s *r =
8734 deprecated_coproc_regs + i;
8735
8736 if (inst.operands[0].reg == r->cp
8737 && inst.operands[1].imm == r->opc1
8738 && inst.operands[3].reg == r->crn
8739 && inst.operands[4].reg == r->crm
8740 && inst.operands[5].imm == r->opc2)
8741 {
b10bf8c5 8742 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8743 && warn_on_deprecated
dcbd0d71 8744 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8745 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8746 }
8747 }
fdfde340 8748
c19d1205
ZW
8749 inst.instruction |= inst.operands[0].reg << 8;
8750 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8751 inst.instruction |= Rd << 12;
c19d1205
ZW
8752 inst.instruction |= inst.operands[3].reg << 16;
8753 inst.instruction |= inst.operands[4].reg;
8754 inst.instruction |= inst.operands[5].imm << 5;
8755}
09d92015 8756
c19d1205
ZW
8757/* Transfer between coprocessor register and pair of ARM registers.
8758 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8759 MCRR2
8760 MRRC{cond}
8761 MRRC2
b99bd4ef 8762
c19d1205 8763 Two XScale instructions are special cases of these:
09d92015 8764
c19d1205
ZW
8765 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8766 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8767
5f4273c7 8768 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8769
c19d1205
ZW
8770static void
8771do_co_reg2c (void)
8772{
fdfde340
JM
8773 unsigned Rd, Rn;
8774
8775 Rd = inst.operands[2].reg;
8776 Rn = inst.operands[3].reg;
8777
8778 if (thumb_mode)
8779 {
8780 reject_bad_reg (Rd);
8781 reject_bad_reg (Rn);
8782 }
8783 else
8784 {
8785 constraint (Rd == REG_PC, BAD_PC);
8786 constraint (Rn == REG_PC, BAD_PC);
8787 }
8788
873f10f0
TC
8789 /* Only check the MRRC{2} variants. */
8790 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8791 {
8792 /* If Rd == Rn, error that the operation is
8793 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8794 constraint (Rd == Rn, BAD_OVERLAP);
8795 }
8796
c19d1205
ZW
8797 inst.instruction |= inst.operands[0].reg << 8;
8798 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8799 inst.instruction |= Rd << 12;
8800 inst.instruction |= Rn << 16;
c19d1205 8801 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8802}
8803
c19d1205
ZW
8804static void
8805do_cpsi (void)
8806{
8807 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8808 if (inst.operands[1].present)
8809 {
8810 inst.instruction |= CPSI_MMOD;
8811 inst.instruction |= inst.operands[1].imm;
8812 }
c19d1205 8813}
b99bd4ef 8814
62b3e311
PB
8815static void
8816do_dbg (void)
8817{
8818 inst.instruction |= inst.operands[0].imm;
8819}
8820
eea54501
MGD
8821static void
8822do_div (void)
8823{
8824 unsigned Rd, Rn, Rm;
8825
8826 Rd = inst.operands[0].reg;
8827 Rn = (inst.operands[1].present
8828 ? inst.operands[1].reg : Rd);
8829 Rm = inst.operands[2].reg;
8830
8831 constraint ((Rd == REG_PC), BAD_PC);
8832 constraint ((Rn == REG_PC), BAD_PC);
8833 constraint ((Rm == REG_PC), BAD_PC);
8834
8835 inst.instruction |= Rd << 16;
8836 inst.instruction |= Rn << 0;
8837 inst.instruction |= Rm << 8;
8838}
8839
b99bd4ef 8840static void
c19d1205 8841do_it (void)
b99bd4ef 8842{
c19d1205 8843 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8844 process it to do the validation as if in
8845 thumb mode, just in case the code gets
8846 assembled for thumb using the unified syntax. */
8847
c19d1205 8848 inst.size = 0;
e07e6e58
NC
8849 if (unified_syntax)
8850 {
8851 set_it_insn_type (IT_INSN);
8852 now_it.mask = (inst.instruction & 0xf) | 0x10;
8853 now_it.cc = inst.operands[0].imm;
8854 }
09d92015 8855}
b99bd4ef 8856
6530b175
NC
8857/* If there is only one register in the register list,
8858 then return its register number. Otherwise return -1. */
8859static int
8860only_one_reg_in_list (int range)
8861{
8862 int i = ffs (range) - 1;
8863 return (i > 15 || range != (1 << i)) ? -1 : i;
8864}
8865
09d92015 8866static void
6530b175 8867encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8868{
c19d1205
ZW
8869 int base_reg = inst.operands[0].reg;
8870 int range = inst.operands[1].imm;
6530b175 8871 int one_reg;
ea6ef066 8872
c19d1205
ZW
8873 inst.instruction |= base_reg << 16;
8874 inst.instruction |= range;
ea6ef066 8875
c19d1205
ZW
8876 if (inst.operands[1].writeback)
8877 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8878
c19d1205 8879 if (inst.operands[0].writeback)
ea6ef066 8880 {
c19d1205
ZW
8881 inst.instruction |= WRITE_BACK;
8882 /* Check for unpredictable uses of writeback. */
8883 if (inst.instruction & LOAD_BIT)
09d92015 8884 {
c19d1205
ZW
8885 /* Not allowed in LDM type 2. */
8886 if ((inst.instruction & LDM_TYPE_2_OR_3)
8887 && ((range & (1 << REG_PC)) == 0))
8888 as_warn (_("writeback of base register is UNPREDICTABLE"));
8889 /* Only allowed if base reg not in list for other types. */
8890 else if (range & (1 << base_reg))
8891 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8892 }
8893 else /* STM. */
8894 {
8895 /* Not allowed for type 2. */
8896 if (inst.instruction & LDM_TYPE_2_OR_3)
8897 as_warn (_("writeback of base register is UNPREDICTABLE"));
8898 /* Only allowed if base reg not in list, or first in list. */
8899 else if ((range & (1 << base_reg))
8900 && (range & ((1 << base_reg) - 1)))
8901 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8902 }
ea6ef066 8903 }
6530b175
NC
8904
8905 /* If PUSH/POP has only one register, then use the A2 encoding. */
8906 one_reg = only_one_reg_in_list (range);
8907 if (from_push_pop_mnem && one_reg >= 0)
8908 {
8909 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8910
8911 inst.instruction &= A_COND_MASK;
8912 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8913 inst.instruction |= one_reg << 12;
8914 }
8915}
8916
8917static void
8918do_ldmstm (void)
8919{
8920 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8921}
8922
c19d1205
ZW
8923/* ARMv5TE load-consecutive (argument parse)
8924 Mode is like LDRH.
8925
8926 LDRccD R, mode
8927 STRccD R, mode. */
8928
a737bd4d 8929static void
c19d1205 8930do_ldrd (void)
a737bd4d 8931{
c19d1205 8932 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8933 _("first transfer register must be even"));
c19d1205
ZW
8934 constraint (inst.operands[1].present
8935 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8936 _("can only transfer two consecutive registers"));
c19d1205
ZW
8937 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8938 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8939
c19d1205
ZW
8940 if (!inst.operands[1].present)
8941 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8942
c56791bb
RE
8943 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8944 register and the first register written; we have to diagnose
8945 overlap between the base and the second register written here. */
ea6ef066 8946
c56791bb
RE
8947 if (inst.operands[2].reg == inst.operands[1].reg
8948 && (inst.operands[2].writeback || inst.operands[2].postind))
8949 as_warn (_("base register written back, and overlaps "
8950 "second transfer register"));
b05fe5cf 8951
c56791bb
RE
8952 if (!(inst.instruction & V4_STR_BIT))
8953 {
c19d1205 8954 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8955 destination (even if not write-back). */
8956 if (inst.operands[2].immisreg
8957 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8958 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8959 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8960 }
c19d1205
ZW
8961 inst.instruction |= inst.operands[0].reg << 12;
8962 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8963}
8964
8965static void
c19d1205 8966do_ldrex (void)
b05fe5cf 8967{
c19d1205
ZW
8968 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8969 || inst.operands[1].postind || inst.operands[1].writeback
8970 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8971 || inst.operands[1].negative
8972 /* This can arise if the programmer has written
8973 strex rN, rM, foo
8974 or if they have mistakenly used a register name as the last
8975 operand, eg:
8976 strex rN, rM, rX
8977 It is very difficult to distinguish between these two cases
8978 because "rX" might actually be a label. ie the register
8979 name has been occluded by a symbol of the same name. So we
8980 just generate a general 'bad addressing mode' type error
8981 message and leave it up to the programmer to discover the
8982 true cause and fix their mistake. */
8983 || (inst.operands[1].reg == REG_PC),
8984 BAD_ADDR_MODE);
b05fe5cf 8985
c19d1205
ZW
8986 constraint (inst.reloc.exp.X_op != O_constant
8987 || inst.reloc.exp.X_add_number != 0,
8988 _("offset must be zero in ARM encoding"));
b05fe5cf 8989
5be8be5d
DG
8990 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8991
c19d1205
ZW
8992 inst.instruction |= inst.operands[0].reg << 12;
8993 inst.instruction |= inst.operands[1].reg << 16;
8994 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8995}
8996
8997static void
c19d1205 8998do_ldrexd (void)
b05fe5cf 8999{
c19d1205
ZW
9000 constraint (inst.operands[0].reg % 2 != 0,
9001 _("even register required"));
9002 constraint (inst.operands[1].present
9003 && inst.operands[1].reg != inst.operands[0].reg + 1,
9004 _("can only load two consecutive registers"));
9005 /* If op 1 were present and equal to PC, this function wouldn't
9006 have been called in the first place. */
9007 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9008
c19d1205
ZW
9009 inst.instruction |= inst.operands[0].reg << 12;
9010 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9011}
9012
1be5fd2e
NC
9013/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9014 which is not a multiple of four is UNPREDICTABLE. */
9015static void
9016check_ldr_r15_aligned (void)
9017{
9018 constraint (!(inst.operands[1].immisreg)
9019 && (inst.operands[0].reg == REG_PC
9020 && inst.operands[1].reg == REG_PC
9021 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 9022 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9023}
9024
b05fe5cf 9025static void
c19d1205 9026do_ldst (void)
b05fe5cf 9027{
c19d1205
ZW
9028 inst.instruction |= inst.operands[0].reg << 12;
9029 if (!inst.operands[1].isreg)
8335d6aa 9030 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9031 return;
c19d1205 9032 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9033 check_ldr_r15_aligned ();
b05fe5cf
ZW
9034}
9035
9036static void
c19d1205 9037do_ldstt (void)
b05fe5cf 9038{
c19d1205
ZW
9039 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9040 reject [Rn,...]. */
9041 if (inst.operands[1].preind)
b05fe5cf 9042 {
bd3ba5d1
NC
9043 constraint (inst.reloc.exp.X_op != O_constant
9044 || inst.reloc.exp.X_add_number != 0,
c19d1205 9045 _("this instruction requires a post-indexed address"));
b05fe5cf 9046
c19d1205
ZW
9047 inst.operands[1].preind = 0;
9048 inst.operands[1].postind = 1;
9049 inst.operands[1].writeback = 1;
b05fe5cf 9050 }
c19d1205
ZW
9051 inst.instruction |= inst.operands[0].reg << 12;
9052 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9053}
b05fe5cf 9054
c19d1205 9055/* Halfword and signed-byte load/store operations. */
b05fe5cf 9056
c19d1205
ZW
9057static void
9058do_ldstv4 (void)
9059{
ff4a8d2b 9060 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9061 inst.instruction |= inst.operands[0].reg << 12;
9062 if (!inst.operands[1].isreg)
8335d6aa 9063 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9064 return;
c19d1205 9065 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9066}
9067
9068static void
c19d1205 9069do_ldsttv4 (void)
b05fe5cf 9070{
c19d1205
ZW
9071 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9072 reject [Rn,...]. */
9073 if (inst.operands[1].preind)
b05fe5cf 9074 {
bd3ba5d1
NC
9075 constraint (inst.reloc.exp.X_op != O_constant
9076 || inst.reloc.exp.X_add_number != 0,
c19d1205 9077 _("this instruction requires a post-indexed address"));
b05fe5cf 9078
c19d1205
ZW
9079 inst.operands[1].preind = 0;
9080 inst.operands[1].postind = 1;
9081 inst.operands[1].writeback = 1;
b05fe5cf 9082 }
c19d1205
ZW
9083 inst.instruction |= inst.operands[0].reg << 12;
9084 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9085}
b05fe5cf 9086
c19d1205
ZW
9087/* Co-processor register load/store.
9088 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9089static void
9090do_lstc (void)
9091{
9092 inst.instruction |= inst.operands[0].reg << 8;
9093 inst.instruction |= inst.operands[1].reg << 12;
9094 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9095}
9096
b05fe5cf 9097static void
c19d1205 9098do_mlas (void)
b05fe5cf 9099{
8fb9d7b9 9100 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9101 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9102 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9103 && !(inst.instruction & 0x00400000))
8fb9d7b9 9104 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9105
c19d1205
ZW
9106 inst.instruction |= inst.operands[0].reg << 16;
9107 inst.instruction |= inst.operands[1].reg;
9108 inst.instruction |= inst.operands[2].reg << 8;
9109 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9110}
b05fe5cf 9111
c19d1205
ZW
9112static void
9113do_mov (void)
9114{
a9f02af8
MG
9115 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9116 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9117 THUMB1_RELOC_ONLY);
c19d1205
ZW
9118 inst.instruction |= inst.operands[0].reg << 12;
9119 encode_arm_shifter_operand (1);
9120}
b05fe5cf 9121
c19d1205
ZW
9122/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9123static void
9124do_mov16 (void)
9125{
b6895b4f
PB
9126 bfd_vma imm;
9127 bfd_boolean top;
9128
9129 top = (inst.instruction & 0x00400000) != 0;
9130 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9131 _(":lower16: not allowed in this instruction"));
b6895b4f 9132 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9133 _(":upper16: not allowed in this instruction"));
c19d1205 9134 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9135 if (inst.reloc.type == BFD_RELOC_UNUSED)
9136 {
9137 imm = inst.reloc.exp.X_add_number;
9138 /* The value is in two pieces: 0:11, 16:19. */
9139 inst.instruction |= (imm & 0x00000fff);
9140 inst.instruction |= (imm & 0x0000f000) << 4;
9141 }
b05fe5cf 9142}
b99bd4ef 9143
037e8744
JB
9144static int
9145do_vfp_nsyn_mrs (void)
9146{
9147 if (inst.operands[0].isvec)
9148 {
9149 if (inst.operands[1].reg != 1)
477330fc 9150 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9151 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9152 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9153 do_vfp_nsyn_opcode ("fmstat");
9154 }
9155 else if (inst.operands[1].isvec)
9156 do_vfp_nsyn_opcode ("fmrx");
9157 else
9158 return FAIL;
5f4273c7 9159
037e8744
JB
9160 return SUCCESS;
9161}
9162
9163static int
9164do_vfp_nsyn_msr (void)
9165{
9166 if (inst.operands[0].isvec)
9167 do_vfp_nsyn_opcode ("fmxr");
9168 else
9169 return FAIL;
9170
9171 return SUCCESS;
9172}
9173
f7c21dc7
NC
9174static void
9175do_vmrs (void)
9176{
9177 unsigned Rt = inst.operands[0].reg;
fa94de6b 9178
16d02dc9 9179 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9180 {
9181 inst.error = BAD_SP;
9182 return;
9183 }
9184
40c7d507
RR
9185 /* MVFR2 is only valid at ARMv8-A. */
9186 if (inst.operands[1].reg == 5)
9187 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9188 _(BAD_FPU));
9189
f7c21dc7 9190 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9191 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9192 {
9193 inst.error = BAD_PC;
9194 return;
9195 }
9196
16d02dc9
JB
9197 /* If we get through parsing the register name, we just insert the number
9198 generated into the instruction without further validation. */
9199 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9200 inst.instruction |= (Rt << 12);
9201}
9202
9203static void
9204do_vmsr (void)
9205{
9206 unsigned Rt = inst.operands[1].reg;
fa94de6b 9207
f7c21dc7
NC
9208 if (thumb_mode)
9209 reject_bad_reg (Rt);
9210 else if (Rt == REG_PC)
9211 {
9212 inst.error = BAD_PC;
9213 return;
9214 }
9215
40c7d507
RR
9216 /* MVFR2 is only valid for ARMv8-A. */
9217 if (inst.operands[0].reg == 5)
9218 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9219 _(BAD_FPU));
9220
16d02dc9
JB
9221 /* If we get through parsing the register name, we just insert the number
9222 generated into the instruction without further validation. */
9223 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9224 inst.instruction |= (Rt << 12);
9225}
9226
b99bd4ef 9227static void
c19d1205 9228do_mrs (void)
b99bd4ef 9229{
90ec0d68
MGD
9230 unsigned br;
9231
037e8744
JB
9232 if (do_vfp_nsyn_mrs () == SUCCESS)
9233 return;
9234
ff4a8d2b 9235 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9236 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9237
9238 if (inst.operands[1].isreg)
9239 {
9240 br = inst.operands[1].reg;
9241 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9242 as_bad (_("bad register for mrs"));
9243 }
9244 else
9245 {
9246 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9247 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9248 != (PSR_c|PSR_f),
d2cd1205 9249 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9250 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9251 }
9252
9253 inst.instruction |= br;
c19d1205 9254}
b99bd4ef 9255
c19d1205
ZW
9256/* Two possible forms:
9257 "{C|S}PSR_<field>, Rm",
9258 "{C|S}PSR_f, #expression". */
b99bd4ef 9259
c19d1205
ZW
9260static void
9261do_msr (void)
9262{
037e8744
JB
9263 if (do_vfp_nsyn_msr () == SUCCESS)
9264 return;
9265
c19d1205
ZW
9266 inst.instruction |= inst.operands[0].imm;
9267 if (inst.operands[1].isreg)
9268 inst.instruction |= inst.operands[1].reg;
9269 else
b99bd4ef 9270 {
c19d1205
ZW
9271 inst.instruction |= INST_IMMEDIATE;
9272 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9273 inst.reloc.pc_rel = 0;
b99bd4ef 9274 }
b99bd4ef
NC
9275}
9276
c19d1205
ZW
9277static void
9278do_mul (void)
a737bd4d 9279{
ff4a8d2b
NC
9280 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9281
c19d1205
ZW
9282 if (!inst.operands[2].present)
9283 inst.operands[2].reg = inst.operands[0].reg;
9284 inst.instruction |= inst.operands[0].reg << 16;
9285 inst.instruction |= inst.operands[1].reg;
9286 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9287
8fb9d7b9
MS
9288 if (inst.operands[0].reg == inst.operands[1].reg
9289 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9290 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9291}
9292
c19d1205
ZW
9293/* Long Multiply Parser
9294 UMULL RdLo, RdHi, Rm, Rs
9295 SMULL RdLo, RdHi, Rm, Rs
9296 UMLAL RdLo, RdHi, Rm, Rs
9297 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9298
9299static void
c19d1205 9300do_mull (void)
b99bd4ef 9301{
c19d1205
ZW
9302 inst.instruction |= inst.operands[0].reg << 12;
9303 inst.instruction |= inst.operands[1].reg << 16;
9304 inst.instruction |= inst.operands[2].reg;
9305 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9306
682b27ad
PB
9307 /* rdhi and rdlo must be different. */
9308 if (inst.operands[0].reg == inst.operands[1].reg)
9309 as_tsktsk (_("rdhi and rdlo must be different"));
9310
9311 /* rdhi, rdlo and rm must all be different before armv6. */
9312 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9313 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9314 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9315 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9316}
b99bd4ef 9317
c19d1205
ZW
9318static void
9319do_nop (void)
9320{
e7495e45
NS
9321 if (inst.operands[0].present
9322 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9323 {
9324 /* Architectural NOP hints are CPSR sets with no bits selected. */
9325 inst.instruction &= 0xf0000000;
e7495e45
NS
9326 inst.instruction |= 0x0320f000;
9327 if (inst.operands[0].present)
9328 inst.instruction |= inst.operands[0].imm;
c19d1205 9329 }
b99bd4ef
NC
9330}
9331
c19d1205
ZW
9332/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9333 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9334 Condition defaults to COND_ALWAYS.
9335 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9336
9337static void
c19d1205 9338do_pkhbt (void)
b99bd4ef 9339{
c19d1205
ZW
9340 inst.instruction |= inst.operands[0].reg << 12;
9341 inst.instruction |= inst.operands[1].reg << 16;
9342 inst.instruction |= inst.operands[2].reg;
9343 if (inst.operands[3].present)
9344 encode_arm_shift (3);
9345}
b99bd4ef 9346
c19d1205 9347/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9348
c19d1205
ZW
9349static void
9350do_pkhtb (void)
9351{
9352 if (!inst.operands[3].present)
b99bd4ef 9353 {
c19d1205
ZW
9354 /* If the shift specifier is omitted, turn the instruction
9355 into pkhbt rd, rm, rn. */
9356 inst.instruction &= 0xfff00010;
9357 inst.instruction |= inst.operands[0].reg << 12;
9358 inst.instruction |= inst.operands[1].reg;
9359 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9360 }
9361 else
9362 {
c19d1205
ZW
9363 inst.instruction |= inst.operands[0].reg << 12;
9364 inst.instruction |= inst.operands[1].reg << 16;
9365 inst.instruction |= inst.operands[2].reg;
9366 encode_arm_shift (3);
b99bd4ef
NC
9367 }
9368}
9369
c19d1205 9370/* ARMv5TE: Preload-Cache
60e5ef9f 9371 MP Extensions: Preload for write
c19d1205 9372
60e5ef9f 9373 PLD(W) <addr_mode>
c19d1205
ZW
9374
9375 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9376
9377static void
c19d1205 9378do_pld (void)
b99bd4ef 9379{
c19d1205
ZW
9380 constraint (!inst.operands[0].isreg,
9381 _("'[' expected after PLD mnemonic"));
9382 constraint (inst.operands[0].postind,
9383 _("post-indexed expression used in preload instruction"));
9384 constraint (inst.operands[0].writeback,
9385 _("writeback used in preload instruction"));
9386 constraint (!inst.operands[0].preind,
9387 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9388 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9389}
b99bd4ef 9390
62b3e311
PB
9391/* ARMv7: PLI <addr_mode> */
9392static void
9393do_pli (void)
9394{
9395 constraint (!inst.operands[0].isreg,
9396 _("'[' expected after PLI mnemonic"));
9397 constraint (inst.operands[0].postind,
9398 _("post-indexed expression used in preload instruction"));
9399 constraint (inst.operands[0].writeback,
9400 _("writeback used in preload instruction"));
9401 constraint (!inst.operands[0].preind,
9402 _("unindexed addressing used in preload instruction"));
9403 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9404 inst.instruction &= ~PRE_INDEX;
9405}
9406
c19d1205
ZW
9407static void
9408do_push_pop (void)
9409{
5e0d7f77
MP
9410 constraint (inst.operands[0].writeback,
9411 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9412 inst.operands[1] = inst.operands[0];
9413 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9414 inst.operands[0].isreg = 1;
9415 inst.operands[0].writeback = 1;
9416 inst.operands[0].reg = REG_SP;
6530b175 9417 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9418}
b99bd4ef 9419
c19d1205
ZW
9420/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9421 word at the specified address and the following word
9422 respectively.
9423 Unconditionally executed.
9424 Error if Rn is R15. */
b99bd4ef 9425
c19d1205
ZW
9426static void
9427do_rfe (void)
9428{
9429 inst.instruction |= inst.operands[0].reg << 16;
9430 if (inst.operands[0].writeback)
9431 inst.instruction |= WRITE_BACK;
9432}
b99bd4ef 9433
c19d1205 9434/* ARM V6 ssat (argument parse). */
b99bd4ef 9435
c19d1205
ZW
9436static void
9437do_ssat (void)
9438{
9439 inst.instruction |= inst.operands[0].reg << 12;
9440 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9441 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9442
c19d1205
ZW
9443 if (inst.operands[3].present)
9444 encode_arm_shift (3);
b99bd4ef
NC
9445}
9446
c19d1205 9447/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9448
9449static void
c19d1205 9450do_usat (void)
b99bd4ef 9451{
c19d1205
ZW
9452 inst.instruction |= inst.operands[0].reg << 12;
9453 inst.instruction |= inst.operands[1].imm << 16;
9454 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9455
c19d1205
ZW
9456 if (inst.operands[3].present)
9457 encode_arm_shift (3);
b99bd4ef
NC
9458}
9459
c19d1205 9460/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9461
9462static void
c19d1205 9463do_ssat16 (void)
09d92015 9464{
c19d1205
ZW
9465 inst.instruction |= inst.operands[0].reg << 12;
9466 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9467 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9468}
9469
c19d1205
ZW
9470static void
9471do_usat16 (void)
a737bd4d 9472{
c19d1205
ZW
9473 inst.instruction |= inst.operands[0].reg << 12;
9474 inst.instruction |= inst.operands[1].imm << 16;
9475 inst.instruction |= inst.operands[2].reg;
9476}
a737bd4d 9477
c19d1205
ZW
9478/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9479 preserving the other bits.
a737bd4d 9480
c19d1205
ZW
9481 setend <endian_specifier>, where <endian_specifier> is either
9482 BE or LE. */
a737bd4d 9483
c19d1205
ZW
9484static void
9485do_setend (void)
9486{
12e37cbc
MGD
9487 if (warn_on_deprecated
9488 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9489 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9490
c19d1205
ZW
9491 if (inst.operands[0].imm)
9492 inst.instruction |= 0x200;
a737bd4d
NC
9493}
9494
9495static void
c19d1205 9496do_shift (void)
a737bd4d 9497{
c19d1205
ZW
9498 unsigned int Rm = (inst.operands[1].present
9499 ? inst.operands[1].reg
9500 : inst.operands[0].reg);
a737bd4d 9501
c19d1205
ZW
9502 inst.instruction |= inst.operands[0].reg << 12;
9503 inst.instruction |= Rm;
9504 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9505 {
c19d1205
ZW
9506 inst.instruction |= inst.operands[2].reg << 8;
9507 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9508 /* PR 12854: Error on extraneous shifts. */
9509 constraint (inst.operands[2].shifted,
9510 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9511 }
9512 else
c19d1205 9513 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9514}
9515
09d92015 9516static void
3eb17e6b 9517do_smc (void)
09d92015 9518{
3eb17e6b 9519 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9520 inst.reloc.pc_rel = 0;
09d92015
MM
9521}
9522
90ec0d68
MGD
9523static void
9524do_hvc (void)
9525{
9526 inst.reloc.type = BFD_RELOC_ARM_HVC;
9527 inst.reloc.pc_rel = 0;
9528}
9529
09d92015 9530static void
c19d1205 9531do_swi (void)
09d92015 9532{
c19d1205
ZW
9533 inst.reloc.type = BFD_RELOC_ARM_SWI;
9534 inst.reloc.pc_rel = 0;
09d92015
MM
9535}
9536
ddfded2f
MW
9537static void
9538do_setpan (void)
9539{
9540 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9541 _("selected processor does not support SETPAN instruction"));
9542
9543 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9544}
9545
9546static void
9547do_t_setpan (void)
9548{
9549 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9550 _("selected processor does not support SETPAN instruction"));
9551
9552 inst.instruction |= (inst.operands[0].imm << 3);
9553}
9554
c19d1205
ZW
9555/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9556 SMLAxy{cond} Rd,Rm,Rs,Rn
9557 SMLAWy{cond} Rd,Rm,Rs,Rn
9558 Error if any register is R15. */
e16bb312 9559
c19d1205
ZW
9560static void
9561do_smla (void)
e16bb312 9562{
c19d1205
ZW
9563 inst.instruction |= inst.operands[0].reg << 16;
9564 inst.instruction |= inst.operands[1].reg;
9565 inst.instruction |= inst.operands[2].reg << 8;
9566 inst.instruction |= inst.operands[3].reg << 12;
9567}
a737bd4d 9568
c19d1205
ZW
9569/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9570 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9571 Error if any register is R15.
9572 Warning if Rdlo == Rdhi. */
a737bd4d 9573
c19d1205
ZW
9574static void
9575do_smlal (void)
9576{
9577 inst.instruction |= inst.operands[0].reg << 12;
9578 inst.instruction |= inst.operands[1].reg << 16;
9579 inst.instruction |= inst.operands[2].reg;
9580 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9581
c19d1205
ZW
9582 if (inst.operands[0].reg == inst.operands[1].reg)
9583 as_tsktsk (_("rdhi and rdlo must be different"));
9584}
a737bd4d 9585
c19d1205
ZW
9586/* ARM V5E (El Segundo) signed-multiply (argument parse)
9587 SMULxy{cond} Rd,Rm,Rs
9588 Error if any register is R15. */
a737bd4d 9589
c19d1205
ZW
9590static void
9591do_smul (void)
9592{
9593 inst.instruction |= inst.operands[0].reg << 16;
9594 inst.instruction |= inst.operands[1].reg;
9595 inst.instruction |= inst.operands[2].reg << 8;
9596}
a737bd4d 9597
b6702015
PB
9598/* ARM V6 srs (argument parse). The variable fields in the encoding are
9599 the same for both ARM and Thumb-2. */
a737bd4d 9600
c19d1205
ZW
9601static void
9602do_srs (void)
9603{
b6702015
PB
9604 int reg;
9605
9606 if (inst.operands[0].present)
9607 {
9608 reg = inst.operands[0].reg;
fdfde340 9609 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9610 }
9611 else
fdfde340 9612 reg = REG_SP;
b6702015
PB
9613
9614 inst.instruction |= reg << 16;
9615 inst.instruction |= inst.operands[1].imm;
9616 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9617 inst.instruction |= WRITE_BACK;
9618}
a737bd4d 9619
c19d1205 9620/* ARM V6 strex (argument parse). */
a737bd4d 9621
c19d1205
ZW
9622static void
9623do_strex (void)
9624{
9625 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9626 || inst.operands[2].postind || inst.operands[2].writeback
9627 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9628 || inst.operands[2].negative
9629 /* See comment in do_ldrex(). */
9630 || (inst.operands[2].reg == REG_PC),
9631 BAD_ADDR_MODE);
a737bd4d 9632
c19d1205
ZW
9633 constraint (inst.operands[0].reg == inst.operands[1].reg
9634 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9635
c19d1205
ZW
9636 constraint (inst.reloc.exp.X_op != O_constant
9637 || inst.reloc.exp.X_add_number != 0,
9638 _("offset must be zero in ARM encoding"));
a737bd4d 9639
c19d1205
ZW
9640 inst.instruction |= inst.operands[0].reg << 12;
9641 inst.instruction |= inst.operands[1].reg;
9642 inst.instruction |= inst.operands[2].reg << 16;
9643 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9644}
9645
877807f8
NC
9646static void
9647do_t_strexbh (void)
9648{
9649 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9650 || inst.operands[2].postind || inst.operands[2].writeback
9651 || inst.operands[2].immisreg || inst.operands[2].shifted
9652 || inst.operands[2].negative,
9653 BAD_ADDR_MODE);
9654
9655 constraint (inst.operands[0].reg == inst.operands[1].reg
9656 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9657
9658 do_rm_rd_rn ();
9659}
9660
e16bb312 9661static void
c19d1205 9662do_strexd (void)
e16bb312 9663{
c19d1205
ZW
9664 constraint (inst.operands[1].reg % 2 != 0,
9665 _("even register required"));
9666 constraint (inst.operands[2].present
9667 && inst.operands[2].reg != inst.operands[1].reg + 1,
9668 _("can only store two consecutive registers"));
9669 /* If op 2 were present and equal to PC, this function wouldn't
9670 have been called in the first place. */
9671 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9672
c19d1205
ZW
9673 constraint (inst.operands[0].reg == inst.operands[1].reg
9674 || inst.operands[0].reg == inst.operands[1].reg + 1
9675 || inst.operands[0].reg == inst.operands[3].reg,
9676 BAD_OVERLAP);
e16bb312 9677
c19d1205
ZW
9678 inst.instruction |= inst.operands[0].reg << 12;
9679 inst.instruction |= inst.operands[1].reg;
9680 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9681}
9682
9eb6c0f1
MGD
9683/* ARM V8 STRL. */
9684static void
4b8c8c02 9685do_stlex (void)
9eb6c0f1
MGD
9686{
9687 constraint (inst.operands[0].reg == inst.operands[1].reg
9688 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9689
9690 do_rd_rm_rn ();
9691}
9692
9693static void
4b8c8c02 9694do_t_stlex (void)
9eb6c0f1
MGD
9695{
9696 constraint (inst.operands[0].reg == inst.operands[1].reg
9697 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9698
9699 do_rm_rd_rn ();
9700}
9701
c19d1205
ZW
9702/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9703 extends it to 32-bits, and adds the result to a value in another
9704 register. You can specify a rotation by 0, 8, 16, or 24 bits
9705 before extracting the 16-bit value.
9706 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9707 Condition defaults to COND_ALWAYS.
9708 Error if any register uses R15. */
9709
e16bb312 9710static void
c19d1205 9711do_sxtah (void)
e16bb312 9712{
c19d1205
ZW
9713 inst.instruction |= inst.operands[0].reg << 12;
9714 inst.instruction |= inst.operands[1].reg << 16;
9715 inst.instruction |= inst.operands[2].reg;
9716 inst.instruction |= inst.operands[3].imm << 10;
9717}
e16bb312 9718
c19d1205 9719/* ARM V6 SXTH.
e16bb312 9720
c19d1205
ZW
9721 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9722 Condition defaults to COND_ALWAYS.
9723 Error if any register uses R15. */
e16bb312
NC
9724
9725static void
c19d1205 9726do_sxth (void)
e16bb312 9727{
c19d1205
ZW
9728 inst.instruction |= inst.operands[0].reg << 12;
9729 inst.instruction |= inst.operands[1].reg;
9730 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9731}
c19d1205
ZW
9732\f
9733/* VFP instructions. In a logical order: SP variant first, monad
9734 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9735
9736static void
c19d1205 9737do_vfp_sp_monadic (void)
e16bb312 9738{
5287ad62
JB
9739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9740 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9741}
9742
9743static void
c19d1205 9744do_vfp_sp_dyadic (void)
e16bb312 9745{
5287ad62
JB
9746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9747 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9748 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9749}
9750
9751static void
c19d1205 9752do_vfp_sp_compare_z (void)
e16bb312 9753{
5287ad62 9754 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9755}
9756
9757static void
c19d1205 9758do_vfp_dp_sp_cvt (void)
e16bb312 9759{
5287ad62
JB
9760 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9761 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9762}
9763
9764static void
c19d1205 9765do_vfp_sp_dp_cvt (void)
e16bb312 9766{
5287ad62
JB
9767 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9768 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9769}
9770
9771static void
c19d1205 9772do_vfp_reg_from_sp (void)
e16bb312 9773{
c19d1205 9774 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9775 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9776}
9777
9778static void
c19d1205 9779do_vfp_reg2_from_sp2 (void)
e16bb312 9780{
c19d1205
ZW
9781 constraint (inst.operands[2].imm != 2,
9782 _("only two consecutive VFP SP registers allowed here"));
9783 inst.instruction |= inst.operands[0].reg << 12;
9784 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9785 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9786}
9787
9788static void
c19d1205 9789do_vfp_sp_from_reg (void)
e16bb312 9790{
5287ad62 9791 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9792 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9793}
9794
9795static void
c19d1205 9796do_vfp_sp2_from_reg2 (void)
e16bb312 9797{
c19d1205
ZW
9798 constraint (inst.operands[0].imm != 2,
9799 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9800 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9801 inst.instruction |= inst.operands[1].reg << 12;
9802 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9803}
9804
9805static void
c19d1205 9806do_vfp_sp_ldst (void)
e16bb312 9807{
5287ad62 9808 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9809 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9810}
9811
9812static void
c19d1205 9813do_vfp_dp_ldst (void)
e16bb312 9814{
5287ad62 9815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9816 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9817}
9818
c19d1205 9819
e16bb312 9820static void
c19d1205 9821vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9822{
c19d1205
ZW
9823 if (inst.operands[0].writeback)
9824 inst.instruction |= WRITE_BACK;
9825 else
9826 constraint (ldstm_type != VFP_LDSTMIA,
9827 _("this addressing mode requires base-register writeback"));
9828 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9829 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9830 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9831}
9832
9833static void
c19d1205 9834vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9835{
c19d1205 9836 int count;
e16bb312 9837
c19d1205
ZW
9838 if (inst.operands[0].writeback)
9839 inst.instruction |= WRITE_BACK;
9840 else
9841 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9842 _("this addressing mode requires base-register writeback"));
e16bb312 9843
c19d1205 9844 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9845 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9846
c19d1205
ZW
9847 count = inst.operands[1].imm << 1;
9848 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9849 count += 1;
e16bb312 9850
c19d1205 9851 inst.instruction |= count;
e16bb312
NC
9852}
9853
9854static void
c19d1205 9855do_vfp_sp_ldstmia (void)
e16bb312 9856{
c19d1205 9857 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9858}
9859
9860static void
c19d1205 9861do_vfp_sp_ldstmdb (void)
e16bb312 9862{
c19d1205 9863 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9864}
9865
9866static void
c19d1205 9867do_vfp_dp_ldstmia (void)
e16bb312 9868{
c19d1205 9869 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9870}
9871
9872static void
c19d1205 9873do_vfp_dp_ldstmdb (void)
e16bb312 9874{
c19d1205 9875 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9876}
9877
9878static void
c19d1205 9879do_vfp_xp_ldstmia (void)
e16bb312 9880{
c19d1205
ZW
9881 vfp_dp_ldstm (VFP_LDSTMIAX);
9882}
e16bb312 9883
c19d1205
ZW
9884static void
9885do_vfp_xp_ldstmdb (void)
9886{
9887 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9888}
5287ad62
JB
9889
9890static void
9891do_vfp_dp_rd_rm (void)
9892{
9893 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9894 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9895}
9896
9897static void
9898do_vfp_dp_rn_rd (void)
9899{
9900 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9901 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9902}
9903
9904static void
9905do_vfp_dp_rd_rn (void)
9906{
9907 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9908 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9909}
9910
9911static void
9912do_vfp_dp_rd_rn_rm (void)
9913{
9914 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9915 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9916 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9917}
9918
9919static void
9920do_vfp_dp_rd (void)
9921{
9922 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9923}
9924
9925static void
9926do_vfp_dp_rm_rd_rn (void)
9927{
9928 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9929 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9930 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9931}
9932
9933/* VFPv3 instructions. */
9934static void
9935do_vfp_sp_const (void)
9936{
9937 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9938 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9939 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9940}
9941
9942static void
9943do_vfp_dp_const (void)
9944{
9945 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9946 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9947 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9948}
9949
9950static void
9951vfp_conv (int srcsize)
9952{
5f1af56b
MGD
9953 int immbits = srcsize - inst.operands[1].imm;
9954
fa94de6b
RM
9955 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9956 {
5f1af56b 9957 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9958 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9959 inst.error = _("immediate value out of range, expected range [0, 16]");
9960 return;
9961 }
fa94de6b 9962 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9963 {
9964 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9965 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9966 inst.error = _("immediate value out of range, expected range [1, 32]");
9967 return;
9968 }
9969
5287ad62
JB
9970 inst.instruction |= (immbits & 1) << 5;
9971 inst.instruction |= (immbits >> 1);
9972}
9973
9974static void
9975do_vfp_sp_conv_16 (void)
9976{
9977 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9978 vfp_conv (16);
9979}
9980
9981static void
9982do_vfp_dp_conv_16 (void)
9983{
9984 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9985 vfp_conv (16);
9986}
9987
9988static void
9989do_vfp_sp_conv_32 (void)
9990{
9991 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9992 vfp_conv (32);
9993}
9994
9995static void
9996do_vfp_dp_conv_32 (void)
9997{
9998 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9999 vfp_conv (32);
10000}
c19d1205
ZW
10001\f
10002/* FPA instructions. Also in a logical order. */
e16bb312 10003
c19d1205
ZW
10004static void
10005do_fpa_cmp (void)
10006{
10007 inst.instruction |= inst.operands[0].reg << 16;
10008 inst.instruction |= inst.operands[1].reg;
10009}
b99bd4ef
NC
10010
10011static void
c19d1205 10012do_fpa_ldmstm (void)
b99bd4ef 10013{
c19d1205
ZW
10014 inst.instruction |= inst.operands[0].reg << 12;
10015 switch (inst.operands[1].imm)
10016 {
10017 case 1: inst.instruction |= CP_T_X; break;
10018 case 2: inst.instruction |= CP_T_Y; break;
10019 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10020 case 4: break;
10021 default: abort ();
10022 }
b99bd4ef 10023
c19d1205
ZW
10024 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10025 {
10026 /* The instruction specified "ea" or "fd", so we can only accept
10027 [Rn]{!}. The instruction does not really support stacking or
10028 unstacking, so we have to emulate these by setting appropriate
10029 bits and offsets. */
10030 constraint (inst.reloc.exp.X_op != O_constant
10031 || inst.reloc.exp.X_add_number != 0,
10032 _("this instruction does not support indexing"));
b99bd4ef 10033
c19d1205
ZW
10034 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10035 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10036
c19d1205
ZW
10037 if (!(inst.instruction & INDEX_UP))
10038 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10039
c19d1205
ZW
10040 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10041 {
10042 inst.operands[2].preind = 0;
10043 inst.operands[2].postind = 1;
10044 }
10045 }
b99bd4ef 10046
c19d1205 10047 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10048}
c19d1205
ZW
10049\f
10050/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10051
c19d1205
ZW
10052static void
10053do_iwmmxt_tandorc (void)
10054{
10055 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10056}
b99bd4ef 10057
c19d1205
ZW
10058static void
10059do_iwmmxt_textrc (void)
10060{
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 inst.instruction |= inst.operands[1].imm;
10063}
b99bd4ef
NC
10064
10065static void
c19d1205 10066do_iwmmxt_textrm (void)
b99bd4ef 10067{
c19d1205
ZW
10068 inst.instruction |= inst.operands[0].reg << 12;
10069 inst.instruction |= inst.operands[1].reg << 16;
10070 inst.instruction |= inst.operands[2].imm;
10071}
b99bd4ef 10072
c19d1205
ZW
10073static void
10074do_iwmmxt_tinsr (void)
10075{
10076 inst.instruction |= inst.operands[0].reg << 16;
10077 inst.instruction |= inst.operands[1].reg << 12;
10078 inst.instruction |= inst.operands[2].imm;
10079}
b99bd4ef 10080
c19d1205
ZW
10081static void
10082do_iwmmxt_tmia (void)
10083{
10084 inst.instruction |= inst.operands[0].reg << 5;
10085 inst.instruction |= inst.operands[1].reg;
10086 inst.instruction |= inst.operands[2].reg << 12;
10087}
b99bd4ef 10088
c19d1205
ZW
10089static void
10090do_iwmmxt_waligni (void)
10091{
10092 inst.instruction |= inst.operands[0].reg << 12;
10093 inst.instruction |= inst.operands[1].reg << 16;
10094 inst.instruction |= inst.operands[2].reg;
10095 inst.instruction |= inst.operands[3].imm << 20;
10096}
b99bd4ef 10097
2d447fca
JM
10098static void
10099do_iwmmxt_wmerge (void)
10100{
10101 inst.instruction |= inst.operands[0].reg << 12;
10102 inst.instruction |= inst.operands[1].reg << 16;
10103 inst.instruction |= inst.operands[2].reg;
10104 inst.instruction |= inst.operands[3].imm << 21;
10105}
10106
c19d1205
ZW
10107static void
10108do_iwmmxt_wmov (void)
10109{
10110 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10111 inst.instruction |= inst.operands[0].reg << 12;
10112 inst.instruction |= inst.operands[1].reg << 16;
10113 inst.instruction |= inst.operands[1].reg;
10114}
b99bd4ef 10115
c19d1205
ZW
10116static void
10117do_iwmmxt_wldstbh (void)
10118{
8f06b2d8 10119 int reloc;
c19d1205 10120 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10121 if (thumb_mode)
10122 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10123 else
10124 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10125 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10126}
10127
c19d1205
ZW
10128static void
10129do_iwmmxt_wldstw (void)
10130{
10131 /* RIWR_RIWC clears .isreg for a control register. */
10132 if (!inst.operands[0].isreg)
10133 {
10134 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10135 inst.instruction |= 0xf0000000;
10136 }
b99bd4ef 10137
c19d1205
ZW
10138 inst.instruction |= inst.operands[0].reg << 12;
10139 encode_arm_cp_address (1, TRUE, TRUE, 0);
10140}
b99bd4ef
NC
10141
10142static void
c19d1205 10143do_iwmmxt_wldstd (void)
b99bd4ef 10144{
c19d1205 10145 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10146 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10147 && inst.operands[1].immisreg)
10148 {
10149 inst.instruction &= ~0x1a000ff;
eff0bc54 10150 inst.instruction |= (0xfU << 28);
2d447fca
JM
10151 if (inst.operands[1].preind)
10152 inst.instruction |= PRE_INDEX;
10153 if (!inst.operands[1].negative)
10154 inst.instruction |= INDEX_UP;
10155 if (inst.operands[1].writeback)
10156 inst.instruction |= WRITE_BACK;
10157 inst.instruction |= inst.operands[1].reg << 16;
10158 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10159 inst.instruction |= inst.operands[1].imm;
10160 }
10161 else
10162 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10163}
b99bd4ef 10164
c19d1205
ZW
10165static void
10166do_iwmmxt_wshufh (void)
10167{
10168 inst.instruction |= inst.operands[0].reg << 12;
10169 inst.instruction |= inst.operands[1].reg << 16;
10170 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10171 inst.instruction |= (inst.operands[2].imm & 0x0f);
10172}
b99bd4ef 10173
c19d1205
ZW
10174static void
10175do_iwmmxt_wzero (void)
10176{
10177 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10178 inst.instruction |= inst.operands[0].reg;
10179 inst.instruction |= inst.operands[0].reg << 12;
10180 inst.instruction |= inst.operands[0].reg << 16;
10181}
2d447fca
JM
10182
10183static void
10184do_iwmmxt_wrwrwr_or_imm5 (void)
10185{
10186 if (inst.operands[2].isreg)
10187 do_rd_rn_rm ();
10188 else {
10189 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10190 _("immediate operand requires iWMMXt2"));
10191 do_rd_rn ();
10192 if (inst.operands[2].imm == 0)
10193 {
10194 switch ((inst.instruction >> 20) & 0xf)
10195 {
10196 case 4:
10197 case 5:
10198 case 6:
5f4273c7 10199 case 7:
2d447fca
JM
10200 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10201 inst.operands[2].imm = 16;
10202 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10203 break;
10204 case 8:
10205 case 9:
10206 case 10:
10207 case 11:
10208 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10209 inst.operands[2].imm = 32;
10210 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10211 break;
10212 case 12:
10213 case 13:
10214 case 14:
10215 case 15:
10216 {
10217 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10218 unsigned long wrn;
10219 wrn = (inst.instruction >> 16) & 0xf;
10220 inst.instruction &= 0xff0fff0f;
10221 inst.instruction |= wrn;
10222 /* Bail out here; the instruction is now assembled. */
10223 return;
10224 }
10225 }
10226 }
10227 /* Map 32 -> 0, etc. */
10228 inst.operands[2].imm &= 0x1f;
eff0bc54 10229 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10230 }
10231}
c19d1205
ZW
10232\f
10233/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10234 operations first, then control, shift, and load/store. */
b99bd4ef 10235
c19d1205 10236/* Insns like "foo X,Y,Z". */
b99bd4ef 10237
c19d1205
ZW
10238static void
10239do_mav_triple (void)
10240{
10241 inst.instruction |= inst.operands[0].reg << 16;
10242 inst.instruction |= inst.operands[1].reg;
10243 inst.instruction |= inst.operands[2].reg << 12;
10244}
b99bd4ef 10245
c19d1205
ZW
10246/* Insns like "foo W,X,Y,Z".
10247 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10248
c19d1205
ZW
10249static void
10250do_mav_quad (void)
10251{
10252 inst.instruction |= inst.operands[0].reg << 5;
10253 inst.instruction |= inst.operands[1].reg << 12;
10254 inst.instruction |= inst.operands[2].reg << 16;
10255 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10256}
10257
c19d1205
ZW
10258/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10259static void
10260do_mav_dspsc (void)
a737bd4d 10261{
c19d1205
ZW
10262 inst.instruction |= inst.operands[1].reg << 12;
10263}
a737bd4d 10264
c19d1205
ZW
10265/* Maverick shift immediate instructions.
10266 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10267 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10268
c19d1205
ZW
10269static void
10270do_mav_shift (void)
10271{
10272 int imm = inst.operands[2].imm;
a737bd4d 10273
c19d1205
ZW
10274 inst.instruction |= inst.operands[0].reg << 12;
10275 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10276
c19d1205
ZW
10277 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10278 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10279 Bit 4 should be 0. */
10280 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10281
c19d1205
ZW
10282 inst.instruction |= imm;
10283}
10284\f
10285/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10286
c19d1205
ZW
10287/* Xscale multiply-accumulate (argument parse)
10288 MIAcc acc0,Rm,Rs
10289 MIAPHcc acc0,Rm,Rs
10290 MIAxycc acc0,Rm,Rs. */
a737bd4d 10291
c19d1205
ZW
10292static void
10293do_xsc_mia (void)
10294{
10295 inst.instruction |= inst.operands[1].reg;
10296 inst.instruction |= inst.operands[2].reg << 12;
10297}
a737bd4d 10298
c19d1205 10299/* Xscale move-accumulator-register (argument parse)
a737bd4d 10300
c19d1205 10301 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10302
c19d1205
ZW
10303static void
10304do_xsc_mar (void)
10305{
10306 inst.instruction |= inst.operands[1].reg << 12;
10307 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10308}
10309
c19d1205 10310/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10311
c19d1205 10312 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10313
10314static void
c19d1205 10315do_xsc_mra (void)
b99bd4ef 10316{
c19d1205
ZW
10317 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10318 inst.instruction |= inst.operands[0].reg << 12;
10319 inst.instruction |= inst.operands[1].reg << 16;
10320}
10321\f
10322/* Encoding functions relevant only to Thumb. */
b99bd4ef 10323
c19d1205
ZW
10324/* inst.operands[i] is a shifted-register operand; encode
10325 it into inst.instruction in the format used by Thumb32. */
10326
10327static void
10328encode_thumb32_shifted_operand (int i)
10329{
10330 unsigned int value = inst.reloc.exp.X_add_number;
10331 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10332
9c3c69f2
PB
10333 constraint (inst.operands[i].immisreg,
10334 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10335 inst.instruction |= inst.operands[i].reg;
10336 if (shift == SHIFT_RRX)
10337 inst.instruction |= SHIFT_ROR << 4;
10338 else
b99bd4ef 10339 {
c19d1205
ZW
10340 constraint (inst.reloc.exp.X_op != O_constant,
10341 _("expression too complex"));
10342
10343 constraint (value > 32
10344 || (value == 32 && (shift == SHIFT_LSL
10345 || shift == SHIFT_ROR)),
10346 _("shift expression is too large"));
10347
10348 if (value == 0)
10349 shift = SHIFT_LSL;
10350 else if (value == 32)
10351 value = 0;
10352
10353 inst.instruction |= shift << 4;
10354 inst.instruction |= (value & 0x1c) << 10;
10355 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10356 }
c19d1205 10357}
b99bd4ef 10358
b99bd4ef 10359
c19d1205
ZW
10360/* inst.operands[i] was set up by parse_address. Encode it into a
10361 Thumb32 format load or store instruction. Reject forms that cannot
10362 be used with such instructions. If is_t is true, reject forms that
10363 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10364 that cannot be used with a D instruction. If it is a store insn,
10365 reject PC in Rn. */
b99bd4ef 10366
c19d1205
ZW
10367static void
10368encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10369{
5be8be5d 10370 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10371
10372 constraint (!inst.operands[i].isreg,
53365c0d 10373 _("Instruction does not support =N addresses"));
b99bd4ef 10374
c19d1205
ZW
10375 inst.instruction |= inst.operands[i].reg << 16;
10376 if (inst.operands[i].immisreg)
b99bd4ef 10377 {
5be8be5d 10378 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10379 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10380 constraint (inst.operands[i].negative,
10381 _("Thumb does not support negative register indexing"));
10382 constraint (inst.operands[i].postind,
10383 _("Thumb does not support register post-indexing"));
10384 constraint (inst.operands[i].writeback,
10385 _("Thumb does not support register indexing with writeback"));
10386 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10387 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10388
f40d1643 10389 inst.instruction |= inst.operands[i].imm;
c19d1205 10390 if (inst.operands[i].shifted)
b99bd4ef 10391 {
c19d1205
ZW
10392 constraint (inst.reloc.exp.X_op != O_constant,
10393 _("expression too complex"));
9c3c69f2
PB
10394 constraint (inst.reloc.exp.X_add_number < 0
10395 || inst.reloc.exp.X_add_number > 3,
c19d1205 10396 _("shift out of range"));
9c3c69f2 10397 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10398 }
10399 inst.reloc.type = BFD_RELOC_UNUSED;
10400 }
10401 else if (inst.operands[i].preind)
10402 {
5be8be5d 10403 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10404 constraint (is_t && inst.operands[i].writeback,
c19d1205 10405 _("cannot use writeback with this instruction"));
4755303e
WN
10406 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10407 BAD_PC_ADDRESSING);
c19d1205
ZW
10408
10409 if (is_d)
10410 {
10411 inst.instruction |= 0x01000000;
10412 if (inst.operands[i].writeback)
10413 inst.instruction |= 0x00200000;
b99bd4ef 10414 }
c19d1205 10415 else
b99bd4ef 10416 {
c19d1205
ZW
10417 inst.instruction |= 0x00000c00;
10418 if (inst.operands[i].writeback)
10419 inst.instruction |= 0x00000100;
b99bd4ef 10420 }
c19d1205 10421 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10422 }
c19d1205 10423 else if (inst.operands[i].postind)
b99bd4ef 10424 {
9c2799c2 10425 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10426 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10427 constraint (is_t, _("cannot use post-indexing with this instruction"));
10428
10429 if (is_d)
10430 inst.instruction |= 0x00200000;
10431 else
10432 inst.instruction |= 0x00000900;
10433 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10434 }
10435 else /* unindexed - only for coprocessor */
10436 inst.error = _("instruction does not accept unindexed addressing");
10437}
10438
10439/* Table of Thumb instructions which exist in both 16- and 32-bit
10440 encodings (the latter only in post-V6T2 cores). The index is the
10441 value used in the insns table below. When there is more than one
10442 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10443 holds variant (1).
10444 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10445#define T16_32_TAB \
21d799b5
NC
10446 X(_adc, 4140, eb400000), \
10447 X(_adcs, 4140, eb500000), \
10448 X(_add, 1c00, eb000000), \
10449 X(_adds, 1c00, eb100000), \
10450 X(_addi, 0000, f1000000), \
10451 X(_addis, 0000, f1100000), \
10452 X(_add_pc,000f, f20f0000), \
10453 X(_add_sp,000d, f10d0000), \
10454 X(_adr, 000f, f20f0000), \
10455 X(_and, 4000, ea000000), \
10456 X(_ands, 4000, ea100000), \
10457 X(_asr, 1000, fa40f000), \
10458 X(_asrs, 1000, fa50f000), \
10459 X(_b, e000, f000b000), \
10460 X(_bcond, d000, f0008000), \
10461 X(_bic, 4380, ea200000), \
10462 X(_bics, 4380, ea300000), \
10463 X(_cmn, 42c0, eb100f00), \
10464 X(_cmp, 2800, ebb00f00), \
10465 X(_cpsie, b660, f3af8400), \
10466 X(_cpsid, b670, f3af8600), \
10467 X(_cpy, 4600, ea4f0000), \
10468 X(_dec_sp,80dd, f1ad0d00), \
10469 X(_eor, 4040, ea800000), \
10470 X(_eors, 4040, ea900000), \
10471 X(_inc_sp,00dd, f10d0d00), \
10472 X(_ldmia, c800, e8900000), \
10473 X(_ldr, 6800, f8500000), \
10474 X(_ldrb, 7800, f8100000), \
10475 X(_ldrh, 8800, f8300000), \
10476 X(_ldrsb, 5600, f9100000), \
10477 X(_ldrsh, 5e00, f9300000), \
10478 X(_ldr_pc,4800, f85f0000), \
10479 X(_ldr_pc2,4800, f85f0000), \
10480 X(_ldr_sp,9800, f85d0000), \
10481 X(_lsl, 0000, fa00f000), \
10482 X(_lsls, 0000, fa10f000), \
10483 X(_lsr, 0800, fa20f000), \
10484 X(_lsrs, 0800, fa30f000), \
10485 X(_mov, 2000, ea4f0000), \
10486 X(_movs, 2000, ea5f0000), \
10487 X(_mul, 4340, fb00f000), \
10488 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10489 X(_mvn, 43c0, ea6f0000), \
10490 X(_mvns, 43c0, ea7f0000), \
10491 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10492 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10493 X(_orr, 4300, ea400000), \
10494 X(_orrs, 4300, ea500000), \
10495 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10496 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10497 X(_rev, ba00, fa90f080), \
10498 X(_rev16, ba40, fa90f090), \
10499 X(_revsh, bac0, fa90f0b0), \
10500 X(_ror, 41c0, fa60f000), \
10501 X(_rors, 41c0, fa70f000), \
10502 X(_sbc, 4180, eb600000), \
10503 X(_sbcs, 4180, eb700000), \
10504 X(_stmia, c000, e8800000), \
10505 X(_str, 6000, f8400000), \
10506 X(_strb, 7000, f8000000), \
10507 X(_strh, 8000, f8200000), \
10508 X(_str_sp,9000, f84d0000), \
10509 X(_sub, 1e00, eba00000), \
10510 X(_subs, 1e00, ebb00000), \
10511 X(_subi, 8000, f1a00000), \
10512 X(_subis, 8000, f1b00000), \
10513 X(_sxtb, b240, fa4ff080), \
10514 X(_sxth, b200, fa0ff080), \
10515 X(_tst, 4200, ea100f00), \
10516 X(_uxtb, b2c0, fa5ff080), \
10517 X(_uxth, b280, fa1ff080), \
10518 X(_nop, bf00, f3af8000), \
10519 X(_yield, bf10, f3af8001), \
10520 X(_wfe, bf20, f3af8002), \
10521 X(_wfi, bf30, f3af8003), \
53c4b28b 10522 X(_sev, bf40, f3af8004), \
74db7efb
NC
10523 X(_sevl, bf50, f3af8005), \
10524 X(_udf, de00, f7f0a000)
c19d1205
ZW
10525
10526/* To catch errors in encoding functions, the codes are all offset by
10527 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10528 as 16-bit instructions. */
21d799b5 10529#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10530enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10531#undef X
10532
10533#define X(a,b,c) 0x##b
10534static const unsigned short thumb_op16[] = { T16_32_TAB };
10535#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10536#undef X
10537
10538#define X(a,b,c) 0x##c
10539static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10540#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10541#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10542#undef X
10543#undef T16_32_TAB
10544
10545/* Thumb instruction encoders, in alphabetical order. */
10546
92e90b6e 10547/* ADDW or SUBW. */
c921be7d 10548
92e90b6e
PB
10549static void
10550do_t_add_sub_w (void)
10551{
10552 int Rd, Rn;
10553
10554 Rd = inst.operands[0].reg;
10555 Rn = inst.operands[1].reg;
10556
539d4391
NC
10557 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10558 is the SP-{plus,minus}-immediate form of the instruction. */
10559 if (Rn == REG_SP)
10560 constraint (Rd == REG_PC, BAD_PC);
10561 else
10562 reject_bad_reg (Rd);
fdfde340 10563
92e90b6e
PB
10564 inst.instruction |= (Rn << 16) | (Rd << 8);
10565 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10566}
10567
c19d1205 10568/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10569 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10570
10571static void
10572do_t_add_sub (void)
10573{
10574 int Rd, Rs, Rn;
10575
10576 Rd = inst.operands[0].reg;
10577 Rs = (inst.operands[1].present
10578 ? inst.operands[1].reg /* Rd, Rs, foo */
10579 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10580
e07e6e58
NC
10581 if (Rd == REG_PC)
10582 set_it_insn_type_last ();
10583
c19d1205
ZW
10584 if (unified_syntax)
10585 {
0110f2b8
PB
10586 bfd_boolean flags;
10587 bfd_boolean narrow;
10588 int opcode;
10589
10590 flags = (inst.instruction == T_MNEM_adds
10591 || inst.instruction == T_MNEM_subs);
10592 if (flags)
e07e6e58 10593 narrow = !in_it_block ();
0110f2b8 10594 else
e07e6e58 10595 narrow = in_it_block ();
c19d1205 10596 if (!inst.operands[2].isreg)
b99bd4ef 10597 {
16805f35
PB
10598 int add;
10599
5c8ed6a4
JW
10600 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10601 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10602
16805f35
PB
10603 add = (inst.instruction == T_MNEM_add
10604 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10605 opcode = 0;
10606 if (inst.size_req != 4)
10607 {
0110f2b8 10608 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10609 appropriate. */
0110f2b8
PB
10610 if (Rd == REG_SP && Rs == REG_SP && !flags)
10611 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10612 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10613 opcode = T_MNEM_add_sp;
10614 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10615 opcode = T_MNEM_add_pc;
10616 else if (Rd <= 7 && Rs <= 7 && narrow)
10617 {
10618 if (flags)
10619 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10620 else
10621 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10622 }
10623 if (opcode)
10624 {
10625 inst.instruction = THUMB_OP16(opcode);
10626 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10627 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10628 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10629 {
10630 if (inst.size_req == 2)
10631 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10632 else
10633 inst.relax = opcode;
10634 }
0110f2b8
PB
10635 }
10636 else
10637 constraint (inst.size_req == 2, BAD_HIREG);
10638 }
10639 if (inst.size_req == 4
10640 || (inst.size_req != 2 && !opcode))
10641 {
a9f02af8
MG
10642 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10643 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10644 THUMB1_RELOC_ONLY);
efd81785
PB
10645 if (Rd == REG_PC)
10646 {
fdfde340 10647 constraint (add, BAD_PC);
efd81785
PB
10648 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10649 _("only SUBS PC, LR, #const allowed"));
10650 constraint (inst.reloc.exp.X_op != O_constant,
10651 _("expression too complex"));
10652 constraint (inst.reloc.exp.X_add_number < 0
10653 || inst.reloc.exp.X_add_number > 0xff,
10654 _("immediate value out of range"));
10655 inst.instruction = T2_SUBS_PC_LR
10656 | inst.reloc.exp.X_add_number;
10657 inst.reloc.type = BFD_RELOC_UNUSED;
10658 return;
10659 }
10660 else if (Rs == REG_PC)
16805f35
PB
10661 {
10662 /* Always use addw/subw. */
10663 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10664 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10665 }
10666 else
10667 {
10668 inst.instruction = THUMB_OP32 (inst.instruction);
10669 inst.instruction = (inst.instruction & 0xe1ffffff)
10670 | 0x10000000;
10671 if (flags)
10672 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10673 else
10674 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10675 }
dc4503c6
PB
10676 inst.instruction |= Rd << 8;
10677 inst.instruction |= Rs << 16;
0110f2b8 10678 }
b99bd4ef 10679 }
c19d1205
ZW
10680 else
10681 {
5f4cb198
NC
10682 unsigned int value = inst.reloc.exp.X_add_number;
10683 unsigned int shift = inst.operands[2].shift_kind;
10684
c19d1205
ZW
10685 Rn = inst.operands[2].reg;
10686 /* See if we can do this with a 16-bit instruction. */
10687 if (!inst.operands[2].shifted && inst.size_req != 4)
10688 {
e27ec89e
PB
10689 if (Rd > 7 || Rs > 7 || Rn > 7)
10690 narrow = FALSE;
10691
10692 if (narrow)
c19d1205 10693 {
e27ec89e
PB
10694 inst.instruction = ((inst.instruction == T_MNEM_adds
10695 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10696 ? T_OPCODE_ADD_R3
10697 : T_OPCODE_SUB_R3);
10698 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10699 return;
10700 }
b99bd4ef 10701
7e806470 10702 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10703 {
7e806470
PB
10704 /* Thumb-1 cores (except v6-M) require at least one high
10705 register in a narrow non flag setting add. */
10706 if (Rd > 7 || Rn > 7
10707 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10708 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10709 {
7e806470
PB
10710 if (Rd == Rn)
10711 {
10712 Rn = Rs;
10713 Rs = Rd;
10714 }
c19d1205
ZW
10715 inst.instruction = T_OPCODE_ADD_HI;
10716 inst.instruction |= (Rd & 8) << 4;
10717 inst.instruction |= (Rd & 7);
10718 inst.instruction |= Rn << 3;
10719 return;
10720 }
c19d1205
ZW
10721 }
10722 }
c921be7d 10723
fdfde340 10724 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10725 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10726 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10727 constraint (Rs == REG_PC, BAD_PC);
10728 reject_bad_reg (Rn);
10729
c19d1205
ZW
10730 /* If we get here, it can't be done in 16 bits. */
10731 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10732 _("shift must be constant"));
10733 inst.instruction = THUMB_OP32 (inst.instruction);
10734 inst.instruction |= Rd << 8;
10735 inst.instruction |= Rs << 16;
5f4cb198
NC
10736 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10737 _("shift value over 3 not allowed in thumb mode"));
10738 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10739 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10740 encode_thumb32_shifted_operand (2);
10741 }
10742 }
10743 else
10744 {
10745 constraint (inst.instruction == T_MNEM_adds
10746 || inst.instruction == T_MNEM_subs,
10747 BAD_THUMB32);
b99bd4ef 10748
c19d1205 10749 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10750 {
c19d1205
ZW
10751 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10752 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10753 BAD_HIREG);
10754
10755 inst.instruction = (inst.instruction == T_MNEM_add
10756 ? 0x0000 : 0x8000);
10757 inst.instruction |= (Rd << 4) | Rs;
10758 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10759 return;
10760 }
10761
c19d1205
ZW
10762 Rn = inst.operands[2].reg;
10763 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10764
c19d1205
ZW
10765 /* We now have Rd, Rs, and Rn set to registers. */
10766 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10767 {
c19d1205
ZW
10768 /* Can't do this for SUB. */
10769 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10770 inst.instruction = T_OPCODE_ADD_HI;
10771 inst.instruction |= (Rd & 8) << 4;
10772 inst.instruction |= (Rd & 7);
10773 if (Rs == Rd)
10774 inst.instruction |= Rn << 3;
10775 else if (Rn == Rd)
10776 inst.instruction |= Rs << 3;
10777 else
10778 constraint (1, _("dest must overlap one source register"));
10779 }
10780 else
10781 {
10782 inst.instruction = (inst.instruction == T_MNEM_add
10783 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10784 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10785 }
b99bd4ef 10786 }
b99bd4ef
NC
10787}
10788
c19d1205
ZW
10789static void
10790do_t_adr (void)
10791{
fdfde340
JM
10792 unsigned Rd;
10793
10794 Rd = inst.operands[0].reg;
10795 reject_bad_reg (Rd);
10796
10797 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10798 {
10799 /* Defer to section relaxation. */
10800 inst.relax = inst.instruction;
10801 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10802 inst.instruction |= Rd << 4;
0110f2b8
PB
10803 }
10804 else if (unified_syntax && inst.size_req != 2)
e9f89963 10805 {
0110f2b8 10806 /* Generate a 32-bit opcode. */
e9f89963 10807 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10808 inst.instruction |= Rd << 8;
e9f89963
PB
10809 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10810 inst.reloc.pc_rel = 1;
10811 }
10812 else
10813 {
0110f2b8 10814 /* Generate a 16-bit opcode. */
e9f89963
PB
10815 inst.instruction = THUMB_OP16 (inst.instruction);
10816 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10817 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10818 inst.reloc.pc_rel = 1;
fdfde340 10819 inst.instruction |= Rd << 4;
e9f89963 10820 }
52a86f84
NC
10821
10822 if (inst.reloc.exp.X_op == O_symbol
10823 && inst.reloc.exp.X_add_symbol != NULL
10824 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10825 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10826 inst.reloc.exp.X_add_number += 1;
c19d1205 10827}
b99bd4ef 10828
c19d1205
ZW
10829/* Arithmetic instructions for which there is just one 16-bit
10830 instruction encoding, and it allows only two low registers.
10831 For maximal compatibility with ARM syntax, we allow three register
10832 operands even when Thumb-32 instructions are not available, as long
10833 as the first two are identical. For instance, both "sbc r0,r1" and
10834 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10835static void
c19d1205 10836do_t_arit3 (void)
b99bd4ef 10837{
c19d1205 10838 int Rd, Rs, Rn;
b99bd4ef 10839
c19d1205
ZW
10840 Rd = inst.operands[0].reg;
10841 Rs = (inst.operands[1].present
10842 ? inst.operands[1].reg /* Rd, Rs, foo */
10843 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10844 Rn = inst.operands[2].reg;
b99bd4ef 10845
fdfde340
JM
10846 reject_bad_reg (Rd);
10847 reject_bad_reg (Rs);
10848 if (inst.operands[2].isreg)
10849 reject_bad_reg (Rn);
10850
c19d1205 10851 if (unified_syntax)
b99bd4ef 10852 {
c19d1205
ZW
10853 if (!inst.operands[2].isreg)
10854 {
10855 /* For an immediate, we always generate a 32-bit opcode;
10856 section relaxation will shrink it later if possible. */
10857 inst.instruction = THUMB_OP32 (inst.instruction);
10858 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10859 inst.instruction |= Rd << 8;
10860 inst.instruction |= Rs << 16;
10861 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10862 }
10863 else
10864 {
e27ec89e
PB
10865 bfd_boolean narrow;
10866
c19d1205 10867 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10868 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10869 narrow = !in_it_block ();
e27ec89e 10870 else
e07e6e58 10871 narrow = in_it_block ();
e27ec89e
PB
10872
10873 if (Rd > 7 || Rn > 7 || Rs > 7)
10874 narrow = FALSE;
10875 if (inst.operands[2].shifted)
10876 narrow = FALSE;
10877 if (inst.size_req == 4)
10878 narrow = FALSE;
10879
10880 if (narrow
c19d1205
ZW
10881 && Rd == Rs)
10882 {
10883 inst.instruction = THUMB_OP16 (inst.instruction);
10884 inst.instruction |= Rd;
10885 inst.instruction |= Rn << 3;
10886 return;
10887 }
b99bd4ef 10888
c19d1205
ZW
10889 /* If we get here, it can't be done in 16 bits. */
10890 constraint (inst.operands[2].shifted
10891 && inst.operands[2].immisreg,
10892 _("shift must be constant"));
10893 inst.instruction = THUMB_OP32 (inst.instruction);
10894 inst.instruction |= Rd << 8;
10895 inst.instruction |= Rs << 16;
10896 encode_thumb32_shifted_operand (2);
10897 }
a737bd4d 10898 }
c19d1205 10899 else
b99bd4ef 10900 {
c19d1205
ZW
10901 /* On its face this is a lie - the instruction does set the
10902 flags. However, the only supported mnemonic in this mode
10903 says it doesn't. */
10904 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10905
c19d1205
ZW
10906 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10907 _("unshifted register required"));
10908 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10909 constraint (Rd != Rs,
10910 _("dest and source1 must be the same register"));
a737bd4d 10911
c19d1205
ZW
10912 inst.instruction = THUMB_OP16 (inst.instruction);
10913 inst.instruction |= Rd;
10914 inst.instruction |= Rn << 3;
b99bd4ef 10915 }
a737bd4d 10916}
b99bd4ef 10917
c19d1205
ZW
10918/* Similarly, but for instructions where the arithmetic operation is
10919 commutative, so we can allow either of them to be different from
10920 the destination operand in a 16-bit instruction. For instance, all
10921 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10922 accepted. */
10923static void
10924do_t_arit3c (void)
a737bd4d 10925{
c19d1205 10926 int Rd, Rs, Rn;
b99bd4ef 10927
c19d1205
ZW
10928 Rd = inst.operands[0].reg;
10929 Rs = (inst.operands[1].present
10930 ? inst.operands[1].reg /* Rd, Rs, foo */
10931 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10932 Rn = inst.operands[2].reg;
c921be7d 10933
fdfde340
JM
10934 reject_bad_reg (Rd);
10935 reject_bad_reg (Rs);
10936 if (inst.operands[2].isreg)
10937 reject_bad_reg (Rn);
a737bd4d 10938
c19d1205 10939 if (unified_syntax)
a737bd4d 10940 {
c19d1205 10941 if (!inst.operands[2].isreg)
b99bd4ef 10942 {
c19d1205
ZW
10943 /* For an immediate, we always generate a 32-bit opcode;
10944 section relaxation will shrink it later if possible. */
10945 inst.instruction = THUMB_OP32 (inst.instruction);
10946 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10947 inst.instruction |= Rd << 8;
10948 inst.instruction |= Rs << 16;
10949 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10950 }
c19d1205 10951 else
a737bd4d 10952 {
e27ec89e
PB
10953 bfd_boolean narrow;
10954
c19d1205 10955 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10956 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10957 narrow = !in_it_block ();
e27ec89e 10958 else
e07e6e58 10959 narrow = in_it_block ();
e27ec89e
PB
10960
10961 if (Rd > 7 || Rn > 7 || Rs > 7)
10962 narrow = FALSE;
10963 if (inst.operands[2].shifted)
10964 narrow = FALSE;
10965 if (inst.size_req == 4)
10966 narrow = FALSE;
10967
10968 if (narrow)
a737bd4d 10969 {
c19d1205 10970 if (Rd == Rs)
a737bd4d 10971 {
c19d1205
ZW
10972 inst.instruction = THUMB_OP16 (inst.instruction);
10973 inst.instruction |= Rd;
10974 inst.instruction |= Rn << 3;
10975 return;
a737bd4d 10976 }
c19d1205 10977 if (Rd == Rn)
a737bd4d 10978 {
c19d1205
ZW
10979 inst.instruction = THUMB_OP16 (inst.instruction);
10980 inst.instruction |= Rd;
10981 inst.instruction |= Rs << 3;
10982 return;
a737bd4d
NC
10983 }
10984 }
c19d1205
ZW
10985
10986 /* If we get here, it can't be done in 16 bits. */
10987 constraint (inst.operands[2].shifted
10988 && inst.operands[2].immisreg,
10989 _("shift must be constant"));
10990 inst.instruction = THUMB_OP32 (inst.instruction);
10991 inst.instruction |= Rd << 8;
10992 inst.instruction |= Rs << 16;
10993 encode_thumb32_shifted_operand (2);
a737bd4d 10994 }
b99bd4ef 10995 }
c19d1205
ZW
10996 else
10997 {
10998 /* On its face this is a lie - the instruction does set the
10999 flags. However, the only supported mnemonic in this mode
11000 says it doesn't. */
11001 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11002
c19d1205
ZW
11003 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11004 _("unshifted register required"));
11005 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11006
11007 inst.instruction = THUMB_OP16 (inst.instruction);
11008 inst.instruction |= Rd;
11009
11010 if (Rd == Rs)
11011 inst.instruction |= Rn << 3;
11012 else if (Rd == Rn)
11013 inst.instruction |= Rs << 3;
11014 else
11015 constraint (1, _("dest must overlap one source register"));
11016 }
a737bd4d
NC
11017}
11018
c19d1205
ZW
11019static void
11020do_t_bfc (void)
a737bd4d 11021{
fdfde340 11022 unsigned Rd;
c19d1205
ZW
11023 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11024 constraint (msb > 32, _("bit-field extends past end of register"));
11025 /* The instruction encoding stores the LSB and MSB,
11026 not the LSB and width. */
fdfde340
JM
11027 Rd = inst.operands[0].reg;
11028 reject_bad_reg (Rd);
11029 inst.instruction |= Rd << 8;
c19d1205
ZW
11030 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11031 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11032 inst.instruction |= msb - 1;
b99bd4ef
NC
11033}
11034
c19d1205
ZW
11035static void
11036do_t_bfi (void)
b99bd4ef 11037{
fdfde340 11038 int Rd, Rn;
c19d1205 11039 unsigned int msb;
b99bd4ef 11040
fdfde340
JM
11041 Rd = inst.operands[0].reg;
11042 reject_bad_reg (Rd);
11043
c19d1205
ZW
11044 /* #0 in second position is alternative syntax for bfc, which is
11045 the same instruction but with REG_PC in the Rm field. */
11046 if (!inst.operands[1].isreg)
fdfde340
JM
11047 Rn = REG_PC;
11048 else
11049 {
11050 Rn = inst.operands[1].reg;
11051 reject_bad_reg (Rn);
11052 }
b99bd4ef 11053
c19d1205
ZW
11054 msb = inst.operands[2].imm + inst.operands[3].imm;
11055 constraint (msb > 32, _("bit-field extends past end of register"));
11056 /* The instruction encoding stores the LSB and MSB,
11057 not the LSB and width. */
fdfde340
JM
11058 inst.instruction |= Rd << 8;
11059 inst.instruction |= Rn << 16;
c19d1205
ZW
11060 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11061 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11062 inst.instruction |= msb - 1;
b99bd4ef
NC
11063}
11064
c19d1205
ZW
11065static void
11066do_t_bfx (void)
b99bd4ef 11067{
fdfde340
JM
11068 unsigned Rd, Rn;
11069
11070 Rd = inst.operands[0].reg;
11071 Rn = inst.operands[1].reg;
11072
11073 reject_bad_reg (Rd);
11074 reject_bad_reg (Rn);
11075
c19d1205
ZW
11076 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11077 _("bit-field extends past end of register"));
fdfde340
JM
11078 inst.instruction |= Rd << 8;
11079 inst.instruction |= Rn << 16;
c19d1205
ZW
11080 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11081 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11082 inst.instruction |= inst.operands[3].imm - 1;
11083}
b99bd4ef 11084
c19d1205
ZW
11085/* ARM V5 Thumb BLX (argument parse)
11086 BLX <target_addr> which is BLX(1)
11087 BLX <Rm> which is BLX(2)
11088 Unfortunately, there are two different opcodes for this mnemonic.
11089 So, the insns[].value is not used, and the code here zaps values
11090 into inst.instruction.
b99bd4ef 11091
c19d1205
ZW
11092 ??? How to take advantage of the additional two bits of displacement
11093 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11094
c19d1205
ZW
11095static void
11096do_t_blx (void)
11097{
e07e6e58
NC
11098 set_it_insn_type_last ();
11099
c19d1205 11100 if (inst.operands[0].isreg)
fdfde340
JM
11101 {
11102 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11103 /* We have a register, so this is BLX(2). */
11104 inst.instruction |= inst.operands[0].reg << 3;
11105 }
b99bd4ef
NC
11106 else
11107 {
c19d1205 11108 /* No register. This must be BLX(1). */
2fc8bdac 11109 inst.instruction = 0xf000e800;
0855e32b 11110 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11111 }
11112}
11113
c19d1205
ZW
11114static void
11115do_t_branch (void)
b99bd4ef 11116{
0110f2b8 11117 int opcode;
dfa9f0d5 11118 int cond;
2fe88214 11119 bfd_reloc_code_real_type reloc;
dfa9f0d5 11120
e07e6e58
NC
11121 cond = inst.cond;
11122 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11123
11124 if (in_it_block ())
dfa9f0d5
PB
11125 {
11126 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11127 branches. */
dfa9f0d5 11128 cond = COND_ALWAYS;
dfa9f0d5
PB
11129 }
11130 else
11131 cond = inst.cond;
11132
11133 if (cond != COND_ALWAYS)
0110f2b8
PB
11134 opcode = T_MNEM_bcond;
11135 else
11136 opcode = inst.instruction;
11137
12d6b0b7
RS
11138 if (unified_syntax
11139 && (inst.size_req == 4
10960bfb
PB
11140 || (inst.size_req != 2
11141 && (inst.operands[0].hasreloc
11142 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11143 {
0110f2b8 11144 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11145 if (cond == COND_ALWAYS)
9ae92b05 11146 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11147 else
11148 {
ff8646ee
TP
11149 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11150 _("selected architecture does not support "
11151 "wide conditional branch instruction"));
11152
9c2799c2 11153 gas_assert (cond != 0xF);
dfa9f0d5 11154 inst.instruction |= cond << 22;
9ae92b05 11155 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11156 }
11157 }
b99bd4ef
NC
11158 else
11159 {
0110f2b8 11160 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11161 if (cond == COND_ALWAYS)
9ae92b05 11162 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11163 else
b99bd4ef 11164 {
dfa9f0d5 11165 inst.instruction |= cond << 8;
9ae92b05 11166 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11167 }
0110f2b8
PB
11168 /* Allow section relaxation. */
11169 if (unified_syntax && inst.size_req != 2)
11170 inst.relax = opcode;
b99bd4ef 11171 }
9ae92b05 11172 inst.reloc.type = reloc;
c19d1205 11173 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11174}
11175
8884b720 11176/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11177 between the two is the maximum immediate allowed - which is passed in
8884b720 11178 RANGE. */
b99bd4ef 11179static void
8884b720 11180do_t_bkpt_hlt1 (int range)
b99bd4ef 11181{
dfa9f0d5
PB
11182 constraint (inst.cond != COND_ALWAYS,
11183 _("instruction is always unconditional"));
c19d1205 11184 if (inst.operands[0].present)
b99bd4ef 11185 {
8884b720 11186 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11187 _("immediate value out of range"));
11188 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11189 }
8884b720
MGD
11190
11191 set_it_insn_type (NEUTRAL_IT_INSN);
11192}
11193
11194static void
11195do_t_hlt (void)
11196{
11197 do_t_bkpt_hlt1 (63);
11198}
11199
11200static void
11201do_t_bkpt (void)
11202{
11203 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11204}
11205
11206static void
c19d1205 11207do_t_branch23 (void)
b99bd4ef 11208{
e07e6e58 11209 set_it_insn_type_last ();
0855e32b 11210 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11211
0855e32b
NS
11212 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11213 this file. We used to simply ignore the PLT reloc type here --
11214 the branch encoding is now needed to deal with TLSCALL relocs.
11215 So if we see a PLT reloc now, put it back to how it used to be to
11216 keep the preexisting behaviour. */
11217 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11218 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11219
4343666d 11220#if defined(OBJ_COFF)
c19d1205
ZW
11221 /* If the destination of the branch is a defined symbol which does not have
11222 the THUMB_FUNC attribute, then we must be calling a function which has
11223 the (interfacearm) attribute. We look for the Thumb entry point to that
11224 function and change the branch to refer to that function instead. */
11225 if ( inst.reloc.exp.X_op == O_symbol
11226 && inst.reloc.exp.X_add_symbol != NULL
11227 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11228 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11229 inst.reloc.exp.X_add_symbol =
11230 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11231#endif
90e4755a
RE
11232}
11233
11234static void
c19d1205 11235do_t_bx (void)
90e4755a 11236{
e07e6e58 11237 set_it_insn_type_last ();
c19d1205
ZW
11238 inst.instruction |= inst.operands[0].reg << 3;
11239 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11240 should cause the alignment to be checked once it is known. This is
11241 because BX PC only works if the instruction is word aligned. */
11242}
90e4755a 11243
c19d1205
ZW
11244static void
11245do_t_bxj (void)
11246{
fdfde340 11247 int Rm;
90e4755a 11248
e07e6e58 11249 set_it_insn_type_last ();
fdfde340
JM
11250 Rm = inst.operands[0].reg;
11251 reject_bad_reg (Rm);
11252 inst.instruction |= Rm << 16;
90e4755a
RE
11253}
11254
11255static void
c19d1205 11256do_t_clz (void)
90e4755a 11257{
fdfde340
JM
11258 unsigned Rd;
11259 unsigned Rm;
11260
11261 Rd = inst.operands[0].reg;
11262 Rm = inst.operands[1].reg;
11263
11264 reject_bad_reg (Rd);
11265 reject_bad_reg (Rm);
11266
11267 inst.instruction |= Rd << 8;
11268 inst.instruction |= Rm << 16;
11269 inst.instruction |= Rm;
c19d1205 11270}
90e4755a 11271
dfa9f0d5
PB
11272static void
11273do_t_cps (void)
11274{
e07e6e58 11275 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11276 inst.instruction |= inst.operands[0].imm;
11277}
11278
c19d1205
ZW
11279static void
11280do_t_cpsi (void)
11281{
e07e6e58 11282 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11283 if (unified_syntax
62b3e311
PB
11284 && (inst.operands[1].present || inst.size_req == 4)
11285 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11286 {
c19d1205
ZW
11287 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11288 inst.instruction = 0xf3af8000;
11289 inst.instruction |= imod << 9;
11290 inst.instruction |= inst.operands[0].imm << 5;
11291 if (inst.operands[1].present)
11292 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11293 }
c19d1205 11294 else
90e4755a 11295 {
62b3e311
PB
11296 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11297 && (inst.operands[0].imm & 4),
11298 _("selected processor does not support 'A' form "
11299 "of this instruction"));
11300 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11301 _("Thumb does not support the 2-argument "
11302 "form of this instruction"));
11303 inst.instruction |= inst.operands[0].imm;
90e4755a 11304 }
90e4755a
RE
11305}
11306
c19d1205
ZW
11307/* THUMB CPY instruction (argument parse). */
11308
90e4755a 11309static void
c19d1205 11310do_t_cpy (void)
90e4755a 11311{
c19d1205 11312 if (inst.size_req == 4)
90e4755a 11313 {
c19d1205
ZW
11314 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11315 inst.instruction |= inst.operands[0].reg << 8;
11316 inst.instruction |= inst.operands[1].reg;
90e4755a 11317 }
c19d1205 11318 else
90e4755a 11319 {
c19d1205
ZW
11320 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11321 inst.instruction |= (inst.operands[0].reg & 0x7);
11322 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11323 }
90e4755a
RE
11324}
11325
90e4755a 11326static void
25fe350b 11327do_t_cbz (void)
90e4755a 11328{
e07e6e58 11329 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11330 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11331 inst.instruction |= inst.operands[0].reg;
11332 inst.reloc.pc_rel = 1;
11333 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11334}
90e4755a 11335
62b3e311
PB
11336static void
11337do_t_dbg (void)
11338{
11339 inst.instruction |= inst.operands[0].imm;
11340}
11341
11342static void
11343do_t_div (void)
11344{
fdfde340
JM
11345 unsigned Rd, Rn, Rm;
11346
11347 Rd = inst.operands[0].reg;
11348 Rn = (inst.operands[1].present
11349 ? inst.operands[1].reg : Rd);
11350 Rm = inst.operands[2].reg;
11351
11352 reject_bad_reg (Rd);
11353 reject_bad_reg (Rn);
11354 reject_bad_reg (Rm);
11355
11356 inst.instruction |= Rd << 8;
11357 inst.instruction |= Rn << 16;
11358 inst.instruction |= Rm;
62b3e311
PB
11359}
11360
c19d1205
ZW
11361static void
11362do_t_hint (void)
11363{
11364 if (unified_syntax && inst.size_req == 4)
11365 inst.instruction = THUMB_OP32 (inst.instruction);
11366 else
11367 inst.instruction = THUMB_OP16 (inst.instruction);
11368}
90e4755a 11369
c19d1205
ZW
11370static void
11371do_t_it (void)
11372{
11373 unsigned int cond = inst.operands[0].imm;
e27ec89e 11374
e07e6e58
NC
11375 set_it_insn_type (IT_INSN);
11376 now_it.mask = (inst.instruction & 0xf) | 0x10;
11377 now_it.cc = cond;
5a01bb1d 11378 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11379
11380 /* If the condition is a negative condition, invert the mask. */
c19d1205 11381 if ((cond & 0x1) == 0x0)
90e4755a 11382 {
c19d1205 11383 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11384
c19d1205 11385 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11386 {
11387 /* No conversion needed. */
11388 now_it.block_length = 1;
11389 }
c19d1205 11390 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11391 {
11392 mask ^= 0x8;
11393 now_it.block_length = 2;
11394 }
e27ec89e 11395 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11396 {
11397 mask ^= 0xC;
11398 now_it.block_length = 3;
11399 }
c19d1205 11400 else
5a01bb1d
MGD
11401 {
11402 mask ^= 0xE;
11403 now_it.block_length = 4;
11404 }
90e4755a 11405
e27ec89e
PB
11406 inst.instruction &= 0xfff0;
11407 inst.instruction |= mask;
c19d1205 11408 }
90e4755a 11409
c19d1205
ZW
11410 inst.instruction |= cond << 4;
11411}
90e4755a 11412
3c707909
PB
11413/* Helper function used for both push/pop and ldm/stm. */
11414static void
11415encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11416{
11417 bfd_boolean load;
11418
11419 load = (inst.instruction & (1 << 20)) != 0;
11420
11421 if (mask & (1 << 13))
11422 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11423
11424 if ((mask & (1 << base)) != 0
11425 && writeback)
11426 inst.error = _("having the base register in the register list when "
11427 "using write back is UNPREDICTABLE");
11428
3c707909
PB
11429 if (load)
11430 {
e07e6e58 11431 if (mask & (1 << 15))
477330fc
RM
11432 {
11433 if (mask & (1 << 14))
11434 inst.error = _("LR and PC should not both be in register list");
11435 else
11436 set_it_insn_type_last ();
11437 }
3c707909
PB
11438 }
11439 else
11440 {
11441 if (mask & (1 << 15))
11442 inst.error = _("PC not allowed in register list");
3c707909
PB
11443 }
11444
11445 if ((mask & (mask - 1)) == 0)
11446 {
11447 /* Single register transfers implemented as str/ldr. */
11448 if (writeback)
11449 {
11450 if (inst.instruction & (1 << 23))
11451 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11452 else
11453 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11454 }
11455 else
11456 {
11457 if (inst.instruction & (1 << 23))
11458 inst.instruction = 0x00800000; /* ia -> [base] */
11459 else
11460 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11461 }
11462
11463 inst.instruction |= 0xf8400000;
11464 if (load)
11465 inst.instruction |= 0x00100000;
11466
5f4273c7 11467 mask = ffs (mask) - 1;
3c707909
PB
11468 mask <<= 12;
11469 }
11470 else if (writeback)
11471 inst.instruction |= WRITE_BACK;
11472
11473 inst.instruction |= mask;
11474 inst.instruction |= base << 16;
11475}
11476
c19d1205
ZW
11477static void
11478do_t_ldmstm (void)
11479{
11480 /* This really doesn't seem worth it. */
11481 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11482 _("expression too complex"));
11483 constraint (inst.operands[1].writeback,
11484 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11485
c19d1205
ZW
11486 if (unified_syntax)
11487 {
3c707909
PB
11488 bfd_boolean narrow;
11489 unsigned mask;
11490
11491 narrow = FALSE;
c19d1205
ZW
11492 /* See if we can use a 16-bit instruction. */
11493 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11494 && inst.size_req != 4
3c707909 11495 && !(inst.operands[1].imm & ~0xff))
90e4755a 11496 {
3c707909 11497 mask = 1 << inst.operands[0].reg;
90e4755a 11498
eab4f823 11499 if (inst.operands[0].reg <= 7)
90e4755a 11500 {
3c707909 11501 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11502 ? inst.operands[0].writeback
11503 : (inst.operands[0].writeback
11504 == !(inst.operands[1].imm & mask)))
477330fc 11505 {
eab4f823
MGD
11506 if (inst.instruction == T_MNEM_stmia
11507 && (inst.operands[1].imm & mask)
11508 && (inst.operands[1].imm & (mask - 1)))
11509 as_warn (_("value stored for r%d is UNKNOWN"),
11510 inst.operands[0].reg);
3c707909 11511
eab4f823
MGD
11512 inst.instruction = THUMB_OP16 (inst.instruction);
11513 inst.instruction |= inst.operands[0].reg << 8;
11514 inst.instruction |= inst.operands[1].imm;
11515 narrow = TRUE;
11516 }
11517 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11518 {
11519 /* This means 1 register in reg list one of 3 situations:
11520 1. Instruction is stmia, but without writeback.
11521 2. lmdia without writeback, but with Rn not in
477330fc 11522 reglist.
eab4f823
MGD
11523 3. ldmia with writeback, but with Rn in reglist.
11524 Case 3 is UNPREDICTABLE behaviour, so we handle
11525 case 1 and 2 which can be converted into a 16-bit
11526 str or ldr. The SP cases are handled below. */
11527 unsigned long opcode;
11528 /* First, record an error for Case 3. */
11529 if (inst.operands[1].imm & mask
11530 && inst.operands[0].writeback)
fa94de6b 11531 inst.error =
eab4f823
MGD
11532 _("having the base register in the register list when "
11533 "using write back is UNPREDICTABLE");
fa94de6b
RM
11534
11535 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11536 : T_MNEM_ldr);
11537 inst.instruction = THUMB_OP16 (opcode);
11538 inst.instruction |= inst.operands[0].reg << 3;
11539 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11540 narrow = TRUE;
11541 }
90e4755a 11542 }
eab4f823 11543 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11544 {
eab4f823
MGD
11545 if (inst.operands[0].writeback)
11546 {
fa94de6b 11547 inst.instruction =
eab4f823 11548 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11549 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11550 inst.instruction |= inst.operands[1].imm;
477330fc 11551 narrow = TRUE;
eab4f823
MGD
11552 }
11553 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11554 {
fa94de6b 11555 inst.instruction =
eab4f823 11556 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11557 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11558 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11559 narrow = TRUE;
eab4f823 11560 }
90e4755a 11561 }
3c707909
PB
11562 }
11563
11564 if (!narrow)
11565 {
c19d1205
ZW
11566 if (inst.instruction < 0xffff)
11567 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11568
5f4273c7
NC
11569 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11570 inst.operands[0].writeback);
90e4755a
RE
11571 }
11572 }
c19d1205 11573 else
90e4755a 11574 {
c19d1205
ZW
11575 constraint (inst.operands[0].reg > 7
11576 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11577 constraint (inst.instruction != T_MNEM_ldmia
11578 && inst.instruction != T_MNEM_stmia,
11579 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11580 if (inst.instruction == T_MNEM_stmia)
f03698e6 11581 {
c19d1205
ZW
11582 if (!inst.operands[0].writeback)
11583 as_warn (_("this instruction will write back the base register"));
11584 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11585 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11586 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11587 inst.operands[0].reg);
f03698e6 11588 }
c19d1205 11589 else
90e4755a 11590 {
c19d1205
ZW
11591 if (!inst.operands[0].writeback
11592 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11593 as_warn (_("this instruction will write back the base register"));
11594 else if (inst.operands[0].writeback
11595 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11596 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11597 }
11598
c19d1205
ZW
11599 inst.instruction = THUMB_OP16 (inst.instruction);
11600 inst.instruction |= inst.operands[0].reg << 8;
11601 inst.instruction |= inst.operands[1].imm;
11602 }
11603}
e28cd48c 11604
c19d1205
ZW
11605static void
11606do_t_ldrex (void)
11607{
11608 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11609 || inst.operands[1].postind || inst.operands[1].writeback
11610 || inst.operands[1].immisreg || inst.operands[1].shifted
11611 || inst.operands[1].negative,
01cfc07f 11612 BAD_ADDR_MODE);
e28cd48c 11613
5be8be5d
DG
11614 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11615
c19d1205
ZW
11616 inst.instruction |= inst.operands[0].reg << 12;
11617 inst.instruction |= inst.operands[1].reg << 16;
11618 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11619}
e28cd48c 11620
c19d1205
ZW
11621static void
11622do_t_ldrexd (void)
11623{
11624 if (!inst.operands[1].present)
1cac9012 11625 {
c19d1205
ZW
11626 constraint (inst.operands[0].reg == REG_LR,
11627 _("r14 not allowed as first register "
11628 "when second register is omitted"));
11629 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11630 }
c19d1205
ZW
11631 constraint (inst.operands[0].reg == inst.operands[1].reg,
11632 BAD_OVERLAP);
b99bd4ef 11633
c19d1205
ZW
11634 inst.instruction |= inst.operands[0].reg << 12;
11635 inst.instruction |= inst.operands[1].reg << 8;
11636 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11637}
11638
11639static void
c19d1205 11640do_t_ldst (void)
b99bd4ef 11641{
0110f2b8
PB
11642 unsigned long opcode;
11643 int Rn;
11644
e07e6e58
NC
11645 if (inst.operands[0].isreg
11646 && !inst.operands[0].preind
11647 && inst.operands[0].reg == REG_PC)
11648 set_it_insn_type_last ();
11649
0110f2b8 11650 opcode = inst.instruction;
c19d1205 11651 if (unified_syntax)
b99bd4ef 11652 {
53365c0d
PB
11653 if (!inst.operands[1].isreg)
11654 {
11655 if (opcode <= 0xffff)
11656 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11657 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11658 return;
11659 }
0110f2b8
PB
11660 if (inst.operands[1].isreg
11661 && !inst.operands[1].writeback
c19d1205
ZW
11662 && !inst.operands[1].shifted && !inst.operands[1].postind
11663 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11664 && opcode <= 0xffff
11665 && inst.size_req != 4)
c19d1205 11666 {
0110f2b8
PB
11667 /* Insn may have a 16-bit form. */
11668 Rn = inst.operands[1].reg;
11669 if (inst.operands[1].immisreg)
11670 {
11671 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11672 /* [Rn, Rik] */
0110f2b8
PB
11673 if (Rn <= 7 && inst.operands[1].imm <= 7)
11674 goto op16;
5be8be5d
DG
11675 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11676 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11677 }
11678 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11679 && opcode != T_MNEM_ldrsb)
11680 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11681 || (Rn == REG_SP && opcode == T_MNEM_str))
11682 {
11683 /* [Rn, #const] */
11684 if (Rn > 7)
11685 {
11686 if (Rn == REG_PC)
11687 {
11688 if (inst.reloc.pc_rel)
11689 opcode = T_MNEM_ldr_pc2;
11690 else
11691 opcode = T_MNEM_ldr_pc;
11692 }
11693 else
11694 {
11695 if (opcode == T_MNEM_ldr)
11696 opcode = T_MNEM_ldr_sp;
11697 else
11698 opcode = T_MNEM_str_sp;
11699 }
11700 inst.instruction = inst.operands[0].reg << 8;
11701 }
11702 else
11703 {
11704 inst.instruction = inst.operands[0].reg;
11705 inst.instruction |= inst.operands[1].reg << 3;
11706 }
11707 inst.instruction |= THUMB_OP16 (opcode);
11708 if (inst.size_req == 2)
11709 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11710 else
11711 inst.relax = opcode;
11712 return;
11713 }
c19d1205 11714 }
0110f2b8 11715 /* Definitely a 32-bit variant. */
5be8be5d 11716
8d67f500
NC
11717 /* Warning for Erratum 752419. */
11718 if (opcode == T_MNEM_ldr
11719 && inst.operands[0].reg == REG_SP
11720 && inst.operands[1].writeback == 1
11721 && !inst.operands[1].immisreg)
11722 {
11723 if (no_cpu_selected ()
11724 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11725 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11726 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11727 as_warn (_("This instruction may be unpredictable "
11728 "if executed on M-profile cores "
11729 "with interrupts enabled."));
11730 }
11731
5be8be5d 11732 /* Do some validations regarding addressing modes. */
1be5fd2e 11733 if (inst.operands[1].immisreg)
5be8be5d
DG
11734 reject_bad_reg (inst.operands[1].imm);
11735
1be5fd2e
NC
11736 constraint (inst.operands[1].writeback == 1
11737 && inst.operands[0].reg == inst.operands[1].reg,
11738 BAD_OVERLAP);
11739
0110f2b8 11740 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11741 inst.instruction |= inst.operands[0].reg << 12;
11742 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11743 check_ldr_r15_aligned ();
b99bd4ef
NC
11744 return;
11745 }
11746
c19d1205
ZW
11747 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11748
11749 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11750 {
c19d1205
ZW
11751 /* Only [Rn,Rm] is acceptable. */
11752 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11753 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11754 || inst.operands[1].postind || inst.operands[1].shifted
11755 || inst.operands[1].negative,
11756 _("Thumb does not support this addressing mode"));
11757 inst.instruction = THUMB_OP16 (inst.instruction);
11758 goto op16;
b99bd4ef 11759 }
5f4273c7 11760
c19d1205
ZW
11761 inst.instruction = THUMB_OP16 (inst.instruction);
11762 if (!inst.operands[1].isreg)
8335d6aa 11763 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11764 return;
b99bd4ef 11765
c19d1205
ZW
11766 constraint (!inst.operands[1].preind
11767 || inst.operands[1].shifted
11768 || inst.operands[1].writeback,
11769 _("Thumb does not support this addressing mode"));
11770 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11771 {
c19d1205
ZW
11772 constraint (inst.instruction & 0x0600,
11773 _("byte or halfword not valid for base register"));
11774 constraint (inst.operands[1].reg == REG_PC
11775 && !(inst.instruction & THUMB_LOAD_BIT),
11776 _("r15 based store not allowed"));
11777 constraint (inst.operands[1].immisreg,
11778 _("invalid base register for register offset"));
b99bd4ef 11779
c19d1205
ZW
11780 if (inst.operands[1].reg == REG_PC)
11781 inst.instruction = T_OPCODE_LDR_PC;
11782 else if (inst.instruction & THUMB_LOAD_BIT)
11783 inst.instruction = T_OPCODE_LDR_SP;
11784 else
11785 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11786
c19d1205
ZW
11787 inst.instruction |= inst.operands[0].reg << 8;
11788 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11789 return;
11790 }
90e4755a 11791
c19d1205
ZW
11792 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11793 if (!inst.operands[1].immisreg)
11794 {
11795 /* Immediate offset. */
11796 inst.instruction |= inst.operands[0].reg;
11797 inst.instruction |= inst.operands[1].reg << 3;
11798 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11799 return;
11800 }
90e4755a 11801
c19d1205
ZW
11802 /* Register offset. */
11803 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11804 constraint (inst.operands[1].negative,
11805 _("Thumb does not support this addressing mode"));
90e4755a 11806
c19d1205
ZW
11807 op16:
11808 switch (inst.instruction)
11809 {
11810 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11811 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11812 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11813 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11814 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11815 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11816 case 0x5600 /* ldrsb */:
11817 case 0x5e00 /* ldrsh */: break;
11818 default: abort ();
11819 }
90e4755a 11820
c19d1205
ZW
11821 inst.instruction |= inst.operands[0].reg;
11822 inst.instruction |= inst.operands[1].reg << 3;
11823 inst.instruction |= inst.operands[1].imm << 6;
11824}
90e4755a 11825
c19d1205
ZW
11826static void
11827do_t_ldstd (void)
11828{
11829 if (!inst.operands[1].present)
b99bd4ef 11830 {
c19d1205
ZW
11831 inst.operands[1].reg = inst.operands[0].reg + 1;
11832 constraint (inst.operands[0].reg == REG_LR,
11833 _("r14 not allowed here"));
bd340a04 11834 constraint (inst.operands[0].reg == REG_R12,
477330fc 11835 _("r12 not allowed here"));
b99bd4ef 11836 }
bd340a04
MGD
11837
11838 if (inst.operands[2].writeback
11839 && (inst.operands[0].reg == inst.operands[2].reg
11840 || inst.operands[1].reg == inst.operands[2].reg))
11841 as_warn (_("base register written back, and overlaps "
477330fc 11842 "one of transfer registers"));
bd340a04 11843
c19d1205
ZW
11844 inst.instruction |= inst.operands[0].reg << 12;
11845 inst.instruction |= inst.operands[1].reg << 8;
11846 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11847}
11848
c19d1205
ZW
11849static void
11850do_t_ldstt (void)
11851{
11852 inst.instruction |= inst.operands[0].reg << 12;
11853 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11854}
a737bd4d 11855
b99bd4ef 11856static void
c19d1205 11857do_t_mla (void)
b99bd4ef 11858{
fdfde340 11859 unsigned Rd, Rn, Rm, Ra;
c921be7d 11860
fdfde340
JM
11861 Rd = inst.operands[0].reg;
11862 Rn = inst.operands[1].reg;
11863 Rm = inst.operands[2].reg;
11864 Ra = inst.operands[3].reg;
11865
11866 reject_bad_reg (Rd);
11867 reject_bad_reg (Rn);
11868 reject_bad_reg (Rm);
11869 reject_bad_reg (Ra);
11870
11871 inst.instruction |= Rd << 8;
11872 inst.instruction |= Rn << 16;
11873 inst.instruction |= Rm;
11874 inst.instruction |= Ra << 12;
c19d1205 11875}
b99bd4ef 11876
c19d1205
ZW
11877static void
11878do_t_mlal (void)
11879{
fdfde340
JM
11880 unsigned RdLo, RdHi, Rn, Rm;
11881
11882 RdLo = inst.operands[0].reg;
11883 RdHi = inst.operands[1].reg;
11884 Rn = inst.operands[2].reg;
11885 Rm = inst.operands[3].reg;
11886
11887 reject_bad_reg (RdLo);
11888 reject_bad_reg (RdHi);
11889 reject_bad_reg (Rn);
11890 reject_bad_reg (Rm);
11891
11892 inst.instruction |= RdLo << 12;
11893 inst.instruction |= RdHi << 8;
11894 inst.instruction |= Rn << 16;
11895 inst.instruction |= Rm;
c19d1205 11896}
b99bd4ef 11897
c19d1205
ZW
11898static void
11899do_t_mov_cmp (void)
11900{
fdfde340
JM
11901 unsigned Rn, Rm;
11902
11903 Rn = inst.operands[0].reg;
11904 Rm = inst.operands[1].reg;
11905
e07e6e58
NC
11906 if (Rn == REG_PC)
11907 set_it_insn_type_last ();
11908
c19d1205 11909 if (unified_syntax)
b99bd4ef 11910 {
c19d1205
ZW
11911 int r0off = (inst.instruction == T_MNEM_mov
11912 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11913 unsigned long opcode;
3d388997
PB
11914 bfd_boolean narrow;
11915 bfd_boolean low_regs;
11916
fdfde340 11917 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11918 opcode = inst.instruction;
e07e6e58 11919 if (in_it_block ())
0110f2b8 11920 narrow = opcode != T_MNEM_movs;
3d388997 11921 else
0110f2b8 11922 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11923 if (inst.size_req == 4
11924 || inst.operands[1].shifted)
11925 narrow = FALSE;
11926
efd81785
PB
11927 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11928 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11929 && !inst.operands[1].shifted
fdfde340
JM
11930 && Rn == REG_PC
11931 && Rm == REG_LR)
efd81785
PB
11932 {
11933 inst.instruction = T2_SUBS_PC_LR;
11934 return;
11935 }
11936
fdfde340
JM
11937 if (opcode == T_MNEM_cmp)
11938 {
11939 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11940 if (narrow)
11941 {
11942 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11943 but valid. */
11944 warn_deprecated_sp (Rm);
11945 /* R15 was documented as a valid choice for Rm in ARMv6,
11946 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11947 tools reject R15, so we do too. */
11948 constraint (Rm == REG_PC, BAD_PC);
11949 }
11950 else
11951 reject_bad_reg (Rm);
fdfde340
JM
11952 }
11953 else if (opcode == T_MNEM_mov
11954 || opcode == T_MNEM_movs)
11955 {
11956 if (inst.operands[1].isreg)
11957 {
11958 if (opcode == T_MNEM_movs)
11959 {
11960 reject_bad_reg (Rn);
11961 reject_bad_reg (Rm);
11962 }
76fa04a4
MGD
11963 else if (narrow)
11964 {
11965 /* This is mov.n. */
11966 if ((Rn == REG_SP || Rn == REG_PC)
11967 && (Rm == REG_SP || Rm == REG_PC))
11968 {
5c3696f8 11969 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11970 "deprecated when r%u is the destination "
11971 "register."), Rm, Rn);
11972 }
11973 }
11974 else
11975 {
11976 /* This is mov.w. */
11977 constraint (Rn == REG_PC, BAD_PC);
11978 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11979 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11980 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11981 }
fdfde340
JM
11982 }
11983 else
11984 reject_bad_reg (Rn);
11985 }
11986
c19d1205
ZW
11987 if (!inst.operands[1].isreg)
11988 {
0110f2b8 11989 /* Immediate operand. */
e07e6e58 11990 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11991 narrow = 0;
11992 if (low_regs && narrow)
11993 {
11994 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11995 inst.instruction |= Rn << 8;
a9f02af8
MG
11996 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11997 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11998 {
a9f02af8 11999 if (inst.size_req == 2)
72d98d16 12000 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12001 else
12002 inst.relax = opcode;
72d98d16 12003 }
0110f2b8
PB
12004 }
12005 else
12006 {
a9f02af8
MG
12007 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12008 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12009 THUMB1_RELOC_ONLY);
12010
0110f2b8
PB
12011 inst.instruction = THUMB_OP32 (inst.instruction);
12012 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12013 inst.instruction |= Rn << r0off;
0110f2b8
PB
12014 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12015 }
c19d1205 12016 }
728ca7c9
PB
12017 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12018 && (inst.instruction == T_MNEM_mov
12019 || inst.instruction == T_MNEM_movs))
12020 {
12021 /* Register shifts are encoded as separate shift instructions. */
12022 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12023
e07e6e58 12024 if (in_it_block ())
728ca7c9
PB
12025 narrow = !flags;
12026 else
12027 narrow = flags;
12028
12029 if (inst.size_req == 4)
12030 narrow = FALSE;
12031
12032 if (!low_regs || inst.operands[1].imm > 7)
12033 narrow = FALSE;
12034
fdfde340 12035 if (Rn != Rm)
728ca7c9
PB
12036 narrow = FALSE;
12037
12038 switch (inst.operands[1].shift_kind)
12039 {
12040 case SHIFT_LSL:
12041 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12042 break;
12043 case SHIFT_ASR:
12044 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12045 break;
12046 case SHIFT_LSR:
12047 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12048 break;
12049 case SHIFT_ROR:
12050 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12051 break;
12052 default:
5f4273c7 12053 abort ();
728ca7c9
PB
12054 }
12055
12056 inst.instruction = opcode;
12057 if (narrow)
12058 {
fdfde340 12059 inst.instruction |= Rn;
728ca7c9
PB
12060 inst.instruction |= inst.operands[1].imm << 3;
12061 }
12062 else
12063 {
12064 if (flags)
12065 inst.instruction |= CONDS_BIT;
12066
fdfde340
JM
12067 inst.instruction |= Rn << 8;
12068 inst.instruction |= Rm << 16;
728ca7c9
PB
12069 inst.instruction |= inst.operands[1].imm;
12070 }
12071 }
3d388997 12072 else if (!narrow)
c19d1205 12073 {
728ca7c9
PB
12074 /* Some mov with immediate shift have narrow variants.
12075 Register shifts are handled above. */
12076 if (low_regs && inst.operands[1].shifted
12077 && (inst.instruction == T_MNEM_mov
12078 || inst.instruction == T_MNEM_movs))
12079 {
e07e6e58 12080 if (in_it_block ())
728ca7c9
PB
12081 narrow = (inst.instruction == T_MNEM_mov);
12082 else
12083 narrow = (inst.instruction == T_MNEM_movs);
12084 }
12085
12086 if (narrow)
12087 {
12088 switch (inst.operands[1].shift_kind)
12089 {
12090 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12091 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12092 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12093 default: narrow = FALSE; break;
12094 }
12095 }
12096
12097 if (narrow)
12098 {
fdfde340
JM
12099 inst.instruction |= Rn;
12100 inst.instruction |= Rm << 3;
728ca7c9
PB
12101 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12102 }
12103 else
12104 {
12105 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12106 inst.instruction |= Rn << r0off;
728ca7c9
PB
12107 encode_thumb32_shifted_operand (1);
12108 }
c19d1205
ZW
12109 }
12110 else
12111 switch (inst.instruction)
12112 {
12113 case T_MNEM_mov:
837b3435 12114 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12115 results. Don't allow this. */
12116 if (low_regs)
12117 {
12118 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12119 "MOV Rd, Rs with two low registers is not "
12120 "permitted on this architecture");
fa94de6b 12121 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12122 arm_ext_v6);
12123 }
12124
c19d1205 12125 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12126 inst.instruction |= (Rn & 0x8) << 4;
12127 inst.instruction |= (Rn & 0x7);
12128 inst.instruction |= Rm << 3;
c19d1205 12129 break;
b99bd4ef 12130
c19d1205
ZW
12131 case T_MNEM_movs:
12132 /* We know we have low registers at this point.
941a8a52
MGD
12133 Generate LSLS Rd, Rs, #0. */
12134 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12135 inst.instruction |= Rn;
12136 inst.instruction |= Rm << 3;
c19d1205
ZW
12137 break;
12138
12139 case T_MNEM_cmp:
3d388997 12140 if (low_regs)
c19d1205
ZW
12141 {
12142 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12143 inst.instruction |= Rn;
12144 inst.instruction |= Rm << 3;
c19d1205
ZW
12145 }
12146 else
12147 {
12148 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12149 inst.instruction |= (Rn & 0x8) << 4;
12150 inst.instruction |= (Rn & 0x7);
12151 inst.instruction |= Rm << 3;
c19d1205
ZW
12152 }
12153 break;
12154 }
b99bd4ef
NC
12155 return;
12156 }
12157
c19d1205 12158 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12159
12160 /* PR 10443: Do not silently ignore shifted operands. */
12161 constraint (inst.operands[1].shifted,
12162 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12163
c19d1205 12164 if (inst.operands[1].isreg)
b99bd4ef 12165 {
fdfde340 12166 if (Rn < 8 && Rm < 8)
b99bd4ef 12167 {
c19d1205
ZW
12168 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12169 since a MOV instruction produces unpredictable results. */
12170 if (inst.instruction == T_OPCODE_MOV_I8)
12171 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12172 else
c19d1205 12173 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12174
fdfde340
JM
12175 inst.instruction |= Rn;
12176 inst.instruction |= Rm << 3;
b99bd4ef
NC
12177 }
12178 else
12179 {
c19d1205
ZW
12180 if (inst.instruction == T_OPCODE_MOV_I8)
12181 inst.instruction = T_OPCODE_MOV_HR;
12182 else
12183 inst.instruction = T_OPCODE_CMP_HR;
12184 do_t_cpy ();
b99bd4ef
NC
12185 }
12186 }
c19d1205 12187 else
b99bd4ef 12188 {
fdfde340 12189 constraint (Rn > 7,
c19d1205 12190 _("only lo regs allowed with immediate"));
fdfde340 12191 inst.instruction |= Rn << 8;
c19d1205
ZW
12192 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12193 }
12194}
b99bd4ef 12195
c19d1205
ZW
12196static void
12197do_t_mov16 (void)
12198{
fdfde340 12199 unsigned Rd;
b6895b4f
PB
12200 bfd_vma imm;
12201 bfd_boolean top;
12202
12203 top = (inst.instruction & 0x00800000) != 0;
12204 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12205 {
33eaf5de 12206 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12207 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12208 }
12209 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12210 {
33eaf5de 12211 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12212 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12213 }
12214
fdfde340
JM
12215 Rd = inst.operands[0].reg;
12216 reject_bad_reg (Rd);
12217
12218 inst.instruction |= Rd << 8;
b6895b4f
PB
12219 if (inst.reloc.type == BFD_RELOC_UNUSED)
12220 {
12221 imm = inst.reloc.exp.X_add_number;
12222 inst.instruction |= (imm & 0xf000) << 4;
12223 inst.instruction |= (imm & 0x0800) << 15;
12224 inst.instruction |= (imm & 0x0700) << 4;
12225 inst.instruction |= (imm & 0x00ff);
12226 }
c19d1205 12227}
b99bd4ef 12228
c19d1205
ZW
12229static void
12230do_t_mvn_tst (void)
12231{
fdfde340 12232 unsigned Rn, Rm;
c921be7d 12233
fdfde340
JM
12234 Rn = inst.operands[0].reg;
12235 Rm = inst.operands[1].reg;
12236
12237 if (inst.instruction == T_MNEM_cmp
12238 || inst.instruction == T_MNEM_cmn)
12239 constraint (Rn == REG_PC, BAD_PC);
12240 else
12241 reject_bad_reg (Rn);
12242 reject_bad_reg (Rm);
12243
c19d1205
ZW
12244 if (unified_syntax)
12245 {
12246 int r0off = (inst.instruction == T_MNEM_mvn
12247 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12248 bfd_boolean narrow;
12249
12250 if (inst.size_req == 4
12251 || inst.instruction > 0xffff
12252 || inst.operands[1].shifted
fdfde340 12253 || Rn > 7 || Rm > 7)
3d388997 12254 narrow = FALSE;
fe8b4cc3
KT
12255 else if (inst.instruction == T_MNEM_cmn
12256 || inst.instruction == T_MNEM_tst)
3d388997
PB
12257 narrow = TRUE;
12258 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12259 narrow = !in_it_block ();
3d388997 12260 else
e07e6e58 12261 narrow = in_it_block ();
3d388997 12262
c19d1205 12263 if (!inst.operands[1].isreg)
b99bd4ef 12264 {
c19d1205
ZW
12265 /* For an immediate, we always generate a 32-bit opcode;
12266 section relaxation will shrink it later if possible. */
12267 if (inst.instruction < 0xffff)
12268 inst.instruction = THUMB_OP32 (inst.instruction);
12269 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12270 inst.instruction |= Rn << r0off;
c19d1205 12271 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12272 }
c19d1205 12273 else
b99bd4ef 12274 {
c19d1205 12275 /* See if we can do this with a 16-bit instruction. */
3d388997 12276 if (narrow)
b99bd4ef 12277 {
c19d1205 12278 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12279 inst.instruction |= Rn;
12280 inst.instruction |= Rm << 3;
b99bd4ef 12281 }
c19d1205 12282 else
b99bd4ef 12283 {
c19d1205
ZW
12284 constraint (inst.operands[1].shifted
12285 && inst.operands[1].immisreg,
12286 _("shift must be constant"));
12287 if (inst.instruction < 0xffff)
12288 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12289 inst.instruction |= Rn << r0off;
c19d1205 12290 encode_thumb32_shifted_operand (1);
b99bd4ef 12291 }
b99bd4ef
NC
12292 }
12293 }
12294 else
12295 {
c19d1205
ZW
12296 constraint (inst.instruction > 0xffff
12297 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12298 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12299 _("unshifted register required"));
fdfde340 12300 constraint (Rn > 7 || Rm > 7,
c19d1205 12301 BAD_HIREG);
b99bd4ef 12302
c19d1205 12303 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12304 inst.instruction |= Rn;
12305 inst.instruction |= Rm << 3;
b99bd4ef 12306 }
b99bd4ef
NC
12307}
12308
b05fe5cf 12309static void
c19d1205 12310do_t_mrs (void)
b05fe5cf 12311{
fdfde340 12312 unsigned Rd;
037e8744
JB
12313
12314 if (do_vfp_nsyn_mrs () == SUCCESS)
12315 return;
12316
90ec0d68
MGD
12317 Rd = inst.operands[0].reg;
12318 reject_bad_reg (Rd);
12319 inst.instruction |= Rd << 8;
12320
12321 if (inst.operands[1].isreg)
62b3e311 12322 {
90ec0d68
MGD
12323 unsigned br = inst.operands[1].reg;
12324 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12325 as_bad (_("bad register for mrs"));
12326
12327 inst.instruction |= br & (0xf << 16);
12328 inst.instruction |= (br & 0x300) >> 4;
12329 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12330 }
12331 else
12332 {
90ec0d68 12333 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12334
d2cd1205 12335 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12336 {
12337 /* PR gas/12698: The constraint is only applied for m_profile.
12338 If the user has specified -march=all, we want to ignore it as
12339 we are building for any CPU type, including non-m variants. */
823d2571
TG
12340 bfd_boolean m_profile =
12341 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12342 constraint ((flags != 0) && m_profile, _("selected processor does "
12343 "not support requested special purpose register"));
12344 }
90ec0d68 12345 else
d2cd1205
JB
12346 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12347 devices). */
12348 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12349 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12350
90ec0d68
MGD
12351 inst.instruction |= (flags & SPSR_BIT) >> 2;
12352 inst.instruction |= inst.operands[1].imm & 0xff;
12353 inst.instruction |= 0xf0000;
12354 }
c19d1205 12355}
b05fe5cf 12356
c19d1205
ZW
12357static void
12358do_t_msr (void)
12359{
62b3e311 12360 int flags;
fdfde340 12361 unsigned Rn;
62b3e311 12362
037e8744
JB
12363 if (do_vfp_nsyn_msr () == SUCCESS)
12364 return;
12365
c19d1205
ZW
12366 constraint (!inst.operands[1].isreg,
12367 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12368
12369 if (inst.operands[0].isreg)
12370 flags = (int)(inst.operands[0].reg);
12371 else
12372 flags = inst.operands[0].imm;
12373
d2cd1205 12374 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12375 {
d2cd1205
JB
12376 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12377
1a43faaf 12378 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12379 If the user has specified -march=all, we want to ignore it as
12380 we are building for any CPU type, including non-m variants. */
823d2571
TG
12381 bfd_boolean m_profile =
12382 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12383 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12384 && (bits & ~(PSR_s | PSR_f)) != 0)
12385 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12386 && bits != PSR_f)) && m_profile,
12387 _("selected processor does not support requested special "
12388 "purpose register"));
62b3e311
PB
12389 }
12390 else
d2cd1205
JB
12391 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12392 "requested special purpose register"));
c921be7d 12393
fdfde340
JM
12394 Rn = inst.operands[1].reg;
12395 reject_bad_reg (Rn);
12396
62b3e311 12397 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12398 inst.instruction |= (flags & 0xf0000) >> 8;
12399 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12400 inst.instruction |= (flags & 0xff);
fdfde340 12401 inst.instruction |= Rn << 16;
c19d1205 12402}
b05fe5cf 12403
c19d1205
ZW
12404static void
12405do_t_mul (void)
12406{
17828f45 12407 bfd_boolean narrow;
fdfde340 12408 unsigned Rd, Rn, Rm;
17828f45 12409
c19d1205
ZW
12410 if (!inst.operands[2].present)
12411 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12412
fdfde340
JM
12413 Rd = inst.operands[0].reg;
12414 Rn = inst.operands[1].reg;
12415 Rm = inst.operands[2].reg;
12416
17828f45 12417 if (unified_syntax)
b05fe5cf 12418 {
17828f45 12419 if (inst.size_req == 4
fdfde340
JM
12420 || (Rd != Rn
12421 && Rd != Rm)
12422 || Rn > 7
12423 || Rm > 7)
17828f45
JM
12424 narrow = FALSE;
12425 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12426 narrow = !in_it_block ();
17828f45 12427 else
e07e6e58 12428 narrow = in_it_block ();
b05fe5cf 12429 }
c19d1205 12430 else
b05fe5cf 12431 {
17828f45 12432 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12433 constraint (Rn > 7 || Rm > 7,
c19d1205 12434 BAD_HIREG);
17828f45
JM
12435 narrow = TRUE;
12436 }
b05fe5cf 12437
17828f45
JM
12438 if (narrow)
12439 {
12440 /* 16-bit MULS/Conditional MUL. */
c19d1205 12441 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12442 inst.instruction |= Rd;
b05fe5cf 12443
fdfde340
JM
12444 if (Rd == Rn)
12445 inst.instruction |= Rm << 3;
12446 else if (Rd == Rm)
12447 inst.instruction |= Rn << 3;
c19d1205
ZW
12448 else
12449 constraint (1, _("dest must overlap one source register"));
12450 }
17828f45
JM
12451 else
12452 {
e07e6e58
NC
12453 constraint (inst.instruction != T_MNEM_mul,
12454 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12455 /* 32-bit MUL. */
12456 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12457 inst.instruction |= Rd << 8;
12458 inst.instruction |= Rn << 16;
12459 inst.instruction |= Rm << 0;
12460
12461 reject_bad_reg (Rd);
12462 reject_bad_reg (Rn);
12463 reject_bad_reg (Rm);
17828f45 12464 }
c19d1205 12465}
b05fe5cf 12466
c19d1205
ZW
12467static void
12468do_t_mull (void)
12469{
fdfde340 12470 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12471
fdfde340
JM
12472 RdLo = inst.operands[0].reg;
12473 RdHi = inst.operands[1].reg;
12474 Rn = inst.operands[2].reg;
12475 Rm = inst.operands[3].reg;
12476
12477 reject_bad_reg (RdLo);
12478 reject_bad_reg (RdHi);
12479 reject_bad_reg (Rn);
12480 reject_bad_reg (Rm);
12481
12482 inst.instruction |= RdLo << 12;
12483 inst.instruction |= RdHi << 8;
12484 inst.instruction |= Rn << 16;
12485 inst.instruction |= Rm;
12486
12487 if (RdLo == RdHi)
c19d1205
ZW
12488 as_tsktsk (_("rdhi and rdlo must be different"));
12489}
b05fe5cf 12490
c19d1205
ZW
12491static void
12492do_t_nop (void)
12493{
e07e6e58
NC
12494 set_it_insn_type (NEUTRAL_IT_INSN);
12495
c19d1205
ZW
12496 if (unified_syntax)
12497 {
12498 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12499 {
c19d1205
ZW
12500 inst.instruction = THUMB_OP32 (inst.instruction);
12501 inst.instruction |= inst.operands[0].imm;
12502 }
12503 else
12504 {
bc2d1808
NC
12505 /* PR9722: Check for Thumb2 availability before
12506 generating a thumb2 nop instruction. */
afa62d5e 12507 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12508 {
12509 inst.instruction = THUMB_OP16 (inst.instruction);
12510 inst.instruction |= inst.operands[0].imm << 4;
12511 }
12512 else
12513 inst.instruction = 0x46c0;
c19d1205
ZW
12514 }
12515 }
12516 else
12517 {
12518 constraint (inst.operands[0].present,
12519 _("Thumb does not support NOP with hints"));
12520 inst.instruction = 0x46c0;
12521 }
12522}
b05fe5cf 12523
c19d1205
ZW
12524static void
12525do_t_neg (void)
12526{
12527 if (unified_syntax)
12528 {
3d388997
PB
12529 bfd_boolean narrow;
12530
12531 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12532 narrow = !in_it_block ();
3d388997 12533 else
e07e6e58 12534 narrow = in_it_block ();
3d388997
PB
12535 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12536 narrow = FALSE;
12537 if (inst.size_req == 4)
12538 narrow = FALSE;
12539
12540 if (!narrow)
c19d1205
ZW
12541 {
12542 inst.instruction = THUMB_OP32 (inst.instruction);
12543 inst.instruction |= inst.operands[0].reg << 8;
12544 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12545 }
12546 else
12547 {
c19d1205
ZW
12548 inst.instruction = THUMB_OP16 (inst.instruction);
12549 inst.instruction |= inst.operands[0].reg;
12550 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12551 }
12552 }
12553 else
12554 {
c19d1205
ZW
12555 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12556 BAD_HIREG);
12557 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12558
12559 inst.instruction = THUMB_OP16 (inst.instruction);
12560 inst.instruction |= inst.operands[0].reg;
12561 inst.instruction |= inst.operands[1].reg << 3;
12562 }
12563}
12564
1c444d06
JM
12565static void
12566do_t_orn (void)
12567{
12568 unsigned Rd, Rn;
12569
12570 Rd = inst.operands[0].reg;
12571 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12572
fdfde340
JM
12573 reject_bad_reg (Rd);
12574 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12575 reject_bad_reg (Rn);
12576
1c444d06
JM
12577 inst.instruction |= Rd << 8;
12578 inst.instruction |= Rn << 16;
12579
12580 if (!inst.operands[2].isreg)
12581 {
12582 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12583 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12584 }
12585 else
12586 {
12587 unsigned Rm;
12588
12589 Rm = inst.operands[2].reg;
fdfde340 12590 reject_bad_reg (Rm);
1c444d06
JM
12591
12592 constraint (inst.operands[2].shifted
12593 && inst.operands[2].immisreg,
12594 _("shift must be constant"));
12595 encode_thumb32_shifted_operand (2);
12596 }
12597}
12598
c19d1205
ZW
12599static void
12600do_t_pkhbt (void)
12601{
fdfde340
JM
12602 unsigned Rd, Rn, Rm;
12603
12604 Rd = inst.operands[0].reg;
12605 Rn = inst.operands[1].reg;
12606 Rm = inst.operands[2].reg;
12607
12608 reject_bad_reg (Rd);
12609 reject_bad_reg (Rn);
12610 reject_bad_reg (Rm);
12611
12612 inst.instruction |= Rd << 8;
12613 inst.instruction |= Rn << 16;
12614 inst.instruction |= Rm;
c19d1205
ZW
12615 if (inst.operands[3].present)
12616 {
12617 unsigned int val = inst.reloc.exp.X_add_number;
12618 constraint (inst.reloc.exp.X_op != O_constant,
12619 _("expression too complex"));
12620 inst.instruction |= (val & 0x1c) << 10;
12621 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12622 }
c19d1205 12623}
b05fe5cf 12624
c19d1205
ZW
12625static void
12626do_t_pkhtb (void)
12627{
12628 if (!inst.operands[3].present)
1ef52f49
NC
12629 {
12630 unsigned Rtmp;
12631
12632 inst.instruction &= ~0x00000020;
12633
12634 /* PR 10168. Swap the Rm and Rn registers. */
12635 Rtmp = inst.operands[1].reg;
12636 inst.operands[1].reg = inst.operands[2].reg;
12637 inst.operands[2].reg = Rtmp;
12638 }
c19d1205 12639 do_t_pkhbt ();
b05fe5cf
ZW
12640}
12641
c19d1205
ZW
12642static void
12643do_t_pld (void)
12644{
fdfde340
JM
12645 if (inst.operands[0].immisreg)
12646 reject_bad_reg (inst.operands[0].imm);
12647
c19d1205
ZW
12648 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12649}
b05fe5cf 12650
c19d1205
ZW
12651static void
12652do_t_push_pop (void)
b99bd4ef 12653{
e9f89963 12654 unsigned mask;
5f4273c7 12655
c19d1205
ZW
12656 constraint (inst.operands[0].writeback,
12657 _("push/pop do not support {reglist}^"));
12658 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12659 _("expression too complex"));
b99bd4ef 12660
e9f89963 12661 mask = inst.operands[0].imm;
d3bfe16e 12662 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12663 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12664 else if (inst.size_req != 4
c6025a80 12665 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12666 ? REG_LR : REG_PC)))
b99bd4ef 12667 {
c19d1205
ZW
12668 inst.instruction = THUMB_OP16 (inst.instruction);
12669 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12670 inst.instruction |= mask & 0xff;
c19d1205
ZW
12671 }
12672 else if (unified_syntax)
12673 {
3c707909 12674 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12675 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12676 }
12677 else
12678 {
12679 inst.error = _("invalid register list to push/pop instruction");
12680 return;
12681 }
c19d1205 12682}
b99bd4ef 12683
c19d1205
ZW
12684static void
12685do_t_rbit (void)
12686{
fdfde340
JM
12687 unsigned Rd, Rm;
12688
12689 Rd = inst.operands[0].reg;
12690 Rm = inst.operands[1].reg;
12691
12692 reject_bad_reg (Rd);
12693 reject_bad_reg (Rm);
12694
12695 inst.instruction |= Rd << 8;
12696 inst.instruction |= Rm << 16;
12697 inst.instruction |= Rm;
c19d1205 12698}
b99bd4ef 12699
c19d1205
ZW
12700static void
12701do_t_rev (void)
12702{
fdfde340
JM
12703 unsigned Rd, Rm;
12704
12705 Rd = inst.operands[0].reg;
12706 Rm = inst.operands[1].reg;
12707
12708 reject_bad_reg (Rd);
12709 reject_bad_reg (Rm);
12710
12711 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12712 && inst.size_req != 4)
12713 {
12714 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12715 inst.instruction |= Rd;
12716 inst.instruction |= Rm << 3;
c19d1205
ZW
12717 }
12718 else if (unified_syntax)
12719 {
12720 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12721 inst.instruction |= Rd << 8;
12722 inst.instruction |= Rm << 16;
12723 inst.instruction |= Rm;
c19d1205
ZW
12724 }
12725 else
12726 inst.error = BAD_HIREG;
12727}
b99bd4ef 12728
1c444d06
JM
12729static void
12730do_t_rrx (void)
12731{
12732 unsigned Rd, Rm;
12733
12734 Rd = inst.operands[0].reg;
12735 Rm = inst.operands[1].reg;
12736
fdfde340
JM
12737 reject_bad_reg (Rd);
12738 reject_bad_reg (Rm);
c921be7d 12739
1c444d06
JM
12740 inst.instruction |= Rd << 8;
12741 inst.instruction |= Rm;
12742}
12743
c19d1205
ZW
12744static void
12745do_t_rsb (void)
12746{
fdfde340 12747 unsigned Rd, Rs;
b99bd4ef 12748
c19d1205
ZW
12749 Rd = inst.operands[0].reg;
12750 Rs = (inst.operands[1].present
12751 ? inst.operands[1].reg /* Rd, Rs, foo */
12752 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12753
fdfde340
JM
12754 reject_bad_reg (Rd);
12755 reject_bad_reg (Rs);
12756 if (inst.operands[2].isreg)
12757 reject_bad_reg (inst.operands[2].reg);
12758
c19d1205
ZW
12759 inst.instruction |= Rd << 8;
12760 inst.instruction |= Rs << 16;
12761 if (!inst.operands[2].isreg)
12762 {
026d3abb
PB
12763 bfd_boolean narrow;
12764
12765 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12766 narrow = !in_it_block ();
026d3abb 12767 else
e07e6e58 12768 narrow = in_it_block ();
026d3abb
PB
12769
12770 if (Rd > 7 || Rs > 7)
12771 narrow = FALSE;
12772
12773 if (inst.size_req == 4 || !unified_syntax)
12774 narrow = FALSE;
12775
12776 if (inst.reloc.exp.X_op != O_constant
12777 || inst.reloc.exp.X_add_number != 0)
12778 narrow = FALSE;
12779
12780 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12781 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12782 if (narrow)
12783 {
12784 inst.reloc.type = BFD_RELOC_UNUSED;
12785 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12786 inst.instruction |= Rs << 3;
12787 inst.instruction |= Rd;
12788 }
12789 else
12790 {
12791 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12792 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12793 }
c19d1205
ZW
12794 }
12795 else
12796 encode_thumb32_shifted_operand (2);
12797}
b99bd4ef 12798
c19d1205
ZW
12799static void
12800do_t_setend (void)
12801{
12e37cbc
MGD
12802 if (warn_on_deprecated
12803 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12804 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12805
e07e6e58 12806 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12807 if (inst.operands[0].imm)
12808 inst.instruction |= 0x8;
12809}
b99bd4ef 12810
c19d1205
ZW
12811static void
12812do_t_shift (void)
12813{
12814 if (!inst.operands[1].present)
12815 inst.operands[1].reg = inst.operands[0].reg;
12816
12817 if (unified_syntax)
12818 {
3d388997
PB
12819 bfd_boolean narrow;
12820 int shift_kind;
12821
12822 switch (inst.instruction)
12823 {
12824 case T_MNEM_asr:
12825 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12826 case T_MNEM_lsl:
12827 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12828 case T_MNEM_lsr:
12829 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12830 case T_MNEM_ror:
12831 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12832 default: abort ();
12833 }
12834
12835 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12836 narrow = !in_it_block ();
3d388997 12837 else
e07e6e58 12838 narrow = in_it_block ();
3d388997
PB
12839 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12840 narrow = FALSE;
12841 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12842 narrow = FALSE;
12843 if (inst.operands[2].isreg
12844 && (inst.operands[1].reg != inst.operands[0].reg
12845 || inst.operands[2].reg > 7))
12846 narrow = FALSE;
12847 if (inst.size_req == 4)
12848 narrow = FALSE;
12849
fdfde340
JM
12850 reject_bad_reg (inst.operands[0].reg);
12851 reject_bad_reg (inst.operands[1].reg);
c921be7d 12852
3d388997 12853 if (!narrow)
c19d1205
ZW
12854 {
12855 if (inst.operands[2].isreg)
b99bd4ef 12856 {
fdfde340 12857 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12858 inst.instruction = THUMB_OP32 (inst.instruction);
12859 inst.instruction |= inst.operands[0].reg << 8;
12860 inst.instruction |= inst.operands[1].reg << 16;
12861 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12862
12863 /* PR 12854: Error on extraneous shifts. */
12864 constraint (inst.operands[2].shifted,
12865 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12866 }
12867 else
12868 {
12869 inst.operands[1].shifted = 1;
3d388997 12870 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12871 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12872 ? T_MNEM_movs : T_MNEM_mov);
12873 inst.instruction |= inst.operands[0].reg << 8;
12874 encode_thumb32_shifted_operand (1);
12875 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12876 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12877 }
12878 }
12879 else
12880 {
c19d1205 12881 if (inst.operands[2].isreg)
b99bd4ef 12882 {
3d388997 12883 switch (shift_kind)
b99bd4ef 12884 {
3d388997
PB
12885 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12886 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12887 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12888 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12889 default: abort ();
b99bd4ef 12890 }
5f4273c7 12891
c19d1205
ZW
12892 inst.instruction |= inst.operands[0].reg;
12893 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12894
12895 /* PR 12854: Error on extraneous shifts. */
12896 constraint (inst.operands[2].shifted,
12897 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12898 }
12899 else
12900 {
3d388997 12901 switch (shift_kind)
b99bd4ef 12902 {
3d388997
PB
12903 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12904 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12905 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12906 default: abort ();
b99bd4ef 12907 }
c19d1205
ZW
12908 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12909 inst.instruction |= inst.operands[0].reg;
12910 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12911 }
12912 }
c19d1205
ZW
12913 }
12914 else
12915 {
12916 constraint (inst.operands[0].reg > 7
12917 || inst.operands[1].reg > 7, BAD_HIREG);
12918 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12919
c19d1205
ZW
12920 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12921 {
12922 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12923 constraint (inst.operands[0].reg != inst.operands[1].reg,
12924 _("source1 and dest must be same register"));
b99bd4ef 12925
c19d1205
ZW
12926 switch (inst.instruction)
12927 {
12928 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12929 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12930 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12931 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12932 default: abort ();
12933 }
5f4273c7 12934
c19d1205
ZW
12935 inst.instruction |= inst.operands[0].reg;
12936 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12937
12938 /* PR 12854: Error on extraneous shifts. */
12939 constraint (inst.operands[2].shifted,
12940 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12941 }
12942 else
b99bd4ef 12943 {
c19d1205
ZW
12944 switch (inst.instruction)
12945 {
12946 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12947 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12948 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12949 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12950 default: abort ();
12951 }
12952 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12953 inst.instruction |= inst.operands[0].reg;
12954 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12955 }
12956 }
b99bd4ef
NC
12957}
12958
12959static void
c19d1205 12960do_t_simd (void)
b99bd4ef 12961{
fdfde340
JM
12962 unsigned Rd, Rn, Rm;
12963
12964 Rd = inst.operands[0].reg;
12965 Rn = inst.operands[1].reg;
12966 Rm = inst.operands[2].reg;
12967
12968 reject_bad_reg (Rd);
12969 reject_bad_reg (Rn);
12970 reject_bad_reg (Rm);
12971
12972 inst.instruction |= Rd << 8;
12973 inst.instruction |= Rn << 16;
12974 inst.instruction |= Rm;
c19d1205 12975}
b99bd4ef 12976
03ee1b7f
NC
12977static void
12978do_t_simd2 (void)
12979{
12980 unsigned Rd, Rn, Rm;
12981
12982 Rd = inst.operands[0].reg;
12983 Rm = inst.operands[1].reg;
12984 Rn = inst.operands[2].reg;
12985
12986 reject_bad_reg (Rd);
12987 reject_bad_reg (Rn);
12988 reject_bad_reg (Rm);
12989
12990 inst.instruction |= Rd << 8;
12991 inst.instruction |= Rn << 16;
12992 inst.instruction |= Rm;
12993}
12994
c19d1205 12995static void
3eb17e6b 12996do_t_smc (void)
c19d1205
ZW
12997{
12998 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12999 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13000 _("SMC is not permitted on this architecture"));
c19d1205
ZW
13001 constraint (inst.reloc.exp.X_op != O_constant,
13002 _("expression too complex"));
13003 inst.reloc.type = BFD_RELOC_UNUSED;
13004 inst.instruction |= (value & 0xf000) >> 12;
13005 inst.instruction |= (value & 0x0ff0);
13006 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13007 /* PR gas/15623: SMC instructions must be last in an IT block. */
13008 set_it_insn_type_last ();
c19d1205 13009}
b99bd4ef 13010
90ec0d68
MGD
13011static void
13012do_t_hvc (void)
13013{
13014 unsigned int value = inst.reloc.exp.X_add_number;
13015
13016 inst.reloc.type = BFD_RELOC_UNUSED;
13017 inst.instruction |= (value & 0x0fff);
13018 inst.instruction |= (value & 0xf000) << 4;
13019}
13020
c19d1205 13021static void
3a21c15a 13022do_t_ssat_usat (int bias)
c19d1205 13023{
fdfde340
JM
13024 unsigned Rd, Rn;
13025
13026 Rd = inst.operands[0].reg;
13027 Rn = inst.operands[2].reg;
13028
13029 reject_bad_reg (Rd);
13030 reject_bad_reg (Rn);
13031
13032 inst.instruction |= Rd << 8;
3a21c15a 13033 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13034 inst.instruction |= Rn << 16;
b99bd4ef 13035
c19d1205 13036 if (inst.operands[3].present)
b99bd4ef 13037 {
3a21c15a
NC
13038 offsetT shift_amount = inst.reloc.exp.X_add_number;
13039
13040 inst.reloc.type = BFD_RELOC_UNUSED;
13041
c19d1205
ZW
13042 constraint (inst.reloc.exp.X_op != O_constant,
13043 _("expression too complex"));
b99bd4ef 13044
3a21c15a 13045 if (shift_amount != 0)
6189168b 13046 {
3a21c15a
NC
13047 constraint (shift_amount > 31,
13048 _("shift expression is too large"));
13049
c19d1205 13050 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13051 inst.instruction |= 0x00200000; /* sh bit. */
13052
13053 inst.instruction |= (shift_amount & 0x1c) << 10;
13054 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13055 }
13056 }
b99bd4ef 13057}
c921be7d 13058
3a21c15a
NC
13059static void
13060do_t_ssat (void)
13061{
13062 do_t_ssat_usat (1);
13063}
b99bd4ef 13064
0dd132b6 13065static void
c19d1205 13066do_t_ssat16 (void)
0dd132b6 13067{
fdfde340
JM
13068 unsigned Rd, Rn;
13069
13070 Rd = inst.operands[0].reg;
13071 Rn = inst.operands[2].reg;
13072
13073 reject_bad_reg (Rd);
13074 reject_bad_reg (Rn);
13075
13076 inst.instruction |= Rd << 8;
c19d1205 13077 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13078 inst.instruction |= Rn << 16;
c19d1205 13079}
0dd132b6 13080
c19d1205
ZW
13081static void
13082do_t_strex (void)
13083{
13084 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13085 || inst.operands[2].postind || inst.operands[2].writeback
13086 || inst.operands[2].immisreg || inst.operands[2].shifted
13087 || inst.operands[2].negative,
01cfc07f 13088 BAD_ADDR_MODE);
0dd132b6 13089
5be8be5d
DG
13090 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13091
c19d1205
ZW
13092 inst.instruction |= inst.operands[0].reg << 8;
13093 inst.instruction |= inst.operands[1].reg << 12;
13094 inst.instruction |= inst.operands[2].reg << 16;
13095 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13096}
13097
b99bd4ef 13098static void
c19d1205 13099do_t_strexd (void)
b99bd4ef 13100{
c19d1205
ZW
13101 if (!inst.operands[2].present)
13102 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13103
c19d1205
ZW
13104 constraint (inst.operands[0].reg == inst.operands[1].reg
13105 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13106 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13107 BAD_OVERLAP);
b99bd4ef 13108
c19d1205
ZW
13109 inst.instruction |= inst.operands[0].reg;
13110 inst.instruction |= inst.operands[1].reg << 12;
13111 inst.instruction |= inst.operands[2].reg << 8;
13112 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13113}
13114
13115static void
c19d1205 13116do_t_sxtah (void)
b99bd4ef 13117{
fdfde340
JM
13118 unsigned Rd, Rn, Rm;
13119
13120 Rd = inst.operands[0].reg;
13121 Rn = inst.operands[1].reg;
13122 Rm = inst.operands[2].reg;
13123
13124 reject_bad_reg (Rd);
13125 reject_bad_reg (Rn);
13126 reject_bad_reg (Rm);
13127
13128 inst.instruction |= Rd << 8;
13129 inst.instruction |= Rn << 16;
13130 inst.instruction |= Rm;
c19d1205
ZW
13131 inst.instruction |= inst.operands[3].imm << 4;
13132}
b99bd4ef 13133
c19d1205
ZW
13134static void
13135do_t_sxth (void)
13136{
fdfde340
JM
13137 unsigned Rd, Rm;
13138
13139 Rd = inst.operands[0].reg;
13140 Rm = inst.operands[1].reg;
13141
13142 reject_bad_reg (Rd);
13143 reject_bad_reg (Rm);
c921be7d
NC
13144
13145 if (inst.instruction <= 0xffff
13146 && inst.size_req != 4
fdfde340 13147 && Rd <= 7 && Rm <= 7
c19d1205 13148 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13149 {
c19d1205 13150 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13151 inst.instruction |= Rd;
13152 inst.instruction |= Rm << 3;
b99bd4ef 13153 }
c19d1205 13154 else if (unified_syntax)
b99bd4ef 13155 {
c19d1205
ZW
13156 if (inst.instruction <= 0xffff)
13157 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13158 inst.instruction |= Rd << 8;
13159 inst.instruction |= Rm;
c19d1205 13160 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13161 }
c19d1205 13162 else
b99bd4ef 13163 {
c19d1205
ZW
13164 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13165 _("Thumb encoding does not support rotation"));
13166 constraint (1, BAD_HIREG);
b99bd4ef 13167 }
c19d1205 13168}
b99bd4ef 13169
c19d1205
ZW
13170static void
13171do_t_swi (void)
13172{
13173 inst.reloc.type = BFD_RELOC_ARM_SWI;
13174}
b99bd4ef 13175
92e90b6e
PB
13176static void
13177do_t_tb (void)
13178{
fdfde340 13179 unsigned Rn, Rm;
92e90b6e
PB
13180 int half;
13181
13182 half = (inst.instruction & 0x10) != 0;
e07e6e58 13183 set_it_insn_type_last ();
dfa9f0d5
PB
13184 constraint (inst.operands[0].immisreg,
13185 _("instruction requires register index"));
fdfde340
JM
13186
13187 Rn = inst.operands[0].reg;
13188 Rm = inst.operands[0].imm;
c921be7d 13189
5c8ed6a4
JW
13190 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13191 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13192 reject_bad_reg (Rm);
13193
92e90b6e
PB
13194 constraint (!half && inst.operands[0].shifted,
13195 _("instruction does not allow shifted index"));
fdfde340 13196 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13197}
13198
74db7efb
NC
13199static void
13200do_t_udf (void)
13201{
13202 if (!inst.operands[0].present)
13203 inst.operands[0].imm = 0;
13204
13205 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13206 {
13207 constraint (inst.size_req == 2,
13208 _("immediate value out of range"));
13209 inst.instruction = THUMB_OP32 (inst.instruction);
13210 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13211 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13212 }
13213 else
13214 {
13215 inst.instruction = THUMB_OP16 (inst.instruction);
13216 inst.instruction |= inst.operands[0].imm;
13217 }
13218
13219 set_it_insn_type (NEUTRAL_IT_INSN);
13220}
13221
13222
c19d1205
ZW
13223static void
13224do_t_usat (void)
13225{
3a21c15a 13226 do_t_ssat_usat (0);
b99bd4ef
NC
13227}
13228
13229static void
c19d1205 13230do_t_usat16 (void)
b99bd4ef 13231{
fdfde340
JM
13232 unsigned Rd, Rn;
13233
13234 Rd = inst.operands[0].reg;
13235 Rn = inst.operands[2].reg;
13236
13237 reject_bad_reg (Rd);
13238 reject_bad_reg (Rn);
13239
13240 inst.instruction |= Rd << 8;
c19d1205 13241 inst.instruction |= inst.operands[1].imm;
fdfde340 13242 inst.instruction |= Rn << 16;
b99bd4ef 13243}
c19d1205 13244
5287ad62 13245/* Neon instruction encoder helpers. */
5f4273c7 13246
5287ad62 13247/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13248
5287ad62
JB
13249/* An "invalid" code for the following tables. */
13250#define N_INV -1u
13251
13252struct neon_tab_entry
b99bd4ef 13253{
5287ad62
JB
13254 unsigned integer;
13255 unsigned float_or_poly;
13256 unsigned scalar_or_imm;
13257};
5f4273c7 13258
5287ad62
JB
13259/* Map overloaded Neon opcodes to their respective encodings. */
13260#define NEON_ENC_TAB \
13261 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13262 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13263 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13264 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13265 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13266 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13267 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13268 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13269 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13270 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13271 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13272 /* Register variants of the following two instructions are encoded as
e07e6e58 13273 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13274 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13275 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13276 X(vfma, N_INV, 0x0000c10, N_INV), \
13277 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13278 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13279 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13280 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13281 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13282 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13283 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13284 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13285 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13286 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13287 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13288 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13289 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13290 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13291 X(vshl, 0x0000400, N_INV, 0x0800510), \
13292 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13293 X(vand, 0x0000110, N_INV, 0x0800030), \
13294 X(vbic, 0x0100110, N_INV, 0x0800030), \
13295 X(veor, 0x1000110, N_INV, N_INV), \
13296 X(vorn, 0x0300110, N_INV, 0x0800010), \
13297 X(vorr, 0x0200110, N_INV, 0x0800010), \
13298 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13299 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13300 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13301 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13302 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13303 X(vst1, 0x0000000, 0x0800000, N_INV), \
13304 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13305 X(vst2, 0x0000100, 0x0800100, N_INV), \
13306 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13307 X(vst3, 0x0000200, 0x0800200, N_INV), \
13308 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13309 X(vst4, 0x0000300, 0x0800300, N_INV), \
13310 X(vmovn, 0x1b20200, N_INV, N_INV), \
13311 X(vtrn, 0x1b20080, N_INV, N_INV), \
13312 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13313 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13314 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13315 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13316 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13317 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13318 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13319 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13320 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13321 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13322 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13323 X(vseleq, 0xe000a00, N_INV, N_INV), \
13324 X(vselvs, 0xe100a00, N_INV, N_INV), \
13325 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13326 X(vselgt, 0xe300a00, N_INV, N_INV), \
13327 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13328 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13329 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13330 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13331 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13332 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13333 X(sha3op, 0x2000c00, N_INV, N_INV), \
13334 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13335 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13336
13337enum neon_opc
13338{
13339#define X(OPC,I,F,S) N_MNEM_##OPC
13340NEON_ENC_TAB
13341#undef X
13342};
b99bd4ef 13343
5287ad62
JB
13344static const struct neon_tab_entry neon_enc_tab[] =
13345{
13346#define X(OPC,I,F,S) { (I), (F), (S) }
13347NEON_ENC_TAB
13348#undef X
13349};
b99bd4ef 13350
88714cb8
DG
13351/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13352#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13353#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13354#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13355#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13356#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13357#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13358#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13359#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13360#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13361#define NEON_ENC_SINGLE_(X) \
037e8744 13362 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13363#define NEON_ENC_DOUBLE_(X) \
037e8744 13364 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13365#define NEON_ENC_FPV8_(X) \
13366 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13367
88714cb8
DG
13368#define NEON_ENCODE(type, inst) \
13369 do \
13370 { \
13371 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13372 inst.is_neon = 1; \
13373 } \
13374 while (0)
13375
13376#define check_neon_suffixes \
13377 do \
13378 { \
13379 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13380 { \
13381 as_bad (_("invalid neon suffix for non neon instruction")); \
13382 return; \
13383 } \
13384 } \
13385 while (0)
13386
037e8744
JB
13387/* Define shapes for instruction operands. The following mnemonic characters
13388 are used in this table:
5287ad62 13389
037e8744 13390 F - VFP S<n> register
5287ad62
JB
13391 D - Neon D<n> register
13392 Q - Neon Q<n> register
13393 I - Immediate
13394 S - Scalar
13395 R - ARM register
13396 L - D<n> register list
5f4273c7 13397
037e8744
JB
13398 This table is used to generate various data:
13399 - enumerations of the form NS_DDR to be used as arguments to
13400 neon_select_shape.
13401 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13402 - a table used to drive neon_select_shape. */
b99bd4ef 13403
037e8744
JB
13404#define NEON_SHAPE_DEF \
13405 X(3, (D, D, D), DOUBLE), \
13406 X(3, (Q, Q, Q), QUAD), \
13407 X(3, (D, D, I), DOUBLE), \
13408 X(3, (Q, Q, I), QUAD), \
13409 X(3, (D, D, S), DOUBLE), \
13410 X(3, (Q, Q, S), QUAD), \
13411 X(2, (D, D), DOUBLE), \
13412 X(2, (Q, Q), QUAD), \
13413 X(2, (D, S), DOUBLE), \
13414 X(2, (Q, S), QUAD), \
13415 X(2, (D, R), DOUBLE), \
13416 X(2, (Q, R), QUAD), \
13417 X(2, (D, I), DOUBLE), \
13418 X(2, (Q, I), QUAD), \
13419 X(3, (D, L, D), DOUBLE), \
13420 X(2, (D, Q), MIXED), \
13421 X(2, (Q, D), MIXED), \
13422 X(3, (D, Q, I), MIXED), \
13423 X(3, (Q, D, I), MIXED), \
13424 X(3, (Q, D, D), MIXED), \
13425 X(3, (D, Q, Q), MIXED), \
13426 X(3, (Q, Q, D), MIXED), \
13427 X(3, (Q, D, S), MIXED), \
13428 X(3, (D, Q, S), MIXED), \
13429 X(4, (D, D, D, I), DOUBLE), \
13430 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13431 X(4, (D, D, S, I), DOUBLE), \
13432 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13433 X(2, (F, F), SINGLE), \
13434 X(3, (F, F, F), SINGLE), \
13435 X(2, (F, I), SINGLE), \
13436 X(2, (F, D), MIXED), \
13437 X(2, (D, F), MIXED), \
13438 X(3, (F, F, I), MIXED), \
13439 X(4, (R, R, F, F), SINGLE), \
13440 X(4, (F, F, R, R), SINGLE), \
13441 X(3, (D, R, R), DOUBLE), \
13442 X(3, (R, R, D), DOUBLE), \
13443 X(2, (S, R), SINGLE), \
13444 X(2, (R, S), SINGLE), \
13445 X(2, (F, R), SINGLE), \
d54af2d0
RL
13446 X(2, (R, F), SINGLE), \
13447/* Half float shape supported so far. */\
13448 X (2, (H, D), MIXED), \
13449 X (2, (D, H), MIXED), \
13450 X (2, (H, F), MIXED), \
13451 X (2, (F, H), MIXED), \
13452 X (2, (H, H), HALF), \
13453 X (2, (H, R), HALF), \
13454 X (2, (R, H), HALF), \
13455 X (2, (H, I), HALF), \
13456 X (3, (H, H, H), HALF), \
13457 X (3, (H, F, I), MIXED), \
dec41383
JW
13458 X (3, (F, H, I), MIXED), \
13459 X (3, (D, H, H), MIXED), \
13460 X (3, (D, H, S), MIXED)
037e8744
JB
13461
13462#define S2(A,B) NS_##A##B
13463#define S3(A,B,C) NS_##A##B##C
13464#define S4(A,B,C,D) NS_##A##B##C##D
13465
13466#define X(N, L, C) S##N L
13467
5287ad62
JB
13468enum neon_shape
13469{
037e8744
JB
13470 NEON_SHAPE_DEF,
13471 NS_NULL
5287ad62 13472};
b99bd4ef 13473
037e8744
JB
13474#undef X
13475#undef S2
13476#undef S3
13477#undef S4
13478
13479enum neon_shape_class
13480{
d54af2d0 13481 SC_HALF,
037e8744
JB
13482 SC_SINGLE,
13483 SC_DOUBLE,
13484 SC_QUAD,
13485 SC_MIXED
13486};
13487
13488#define X(N, L, C) SC_##C
13489
13490static enum neon_shape_class neon_shape_class[] =
13491{
13492 NEON_SHAPE_DEF
13493};
13494
13495#undef X
13496
13497enum neon_shape_el
13498{
d54af2d0 13499 SE_H,
037e8744
JB
13500 SE_F,
13501 SE_D,
13502 SE_Q,
13503 SE_I,
13504 SE_S,
13505 SE_R,
13506 SE_L
13507};
13508
13509/* Register widths of above. */
13510static unsigned neon_shape_el_size[] =
13511{
d54af2d0 13512 16,
037e8744
JB
13513 32,
13514 64,
13515 128,
13516 0,
13517 32,
13518 32,
13519 0
13520};
13521
13522struct neon_shape_info
13523{
13524 unsigned els;
13525 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13526};
13527
13528#define S2(A,B) { SE_##A, SE_##B }
13529#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13530#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13531
13532#define X(N, L, C) { N, S##N L }
13533
13534static struct neon_shape_info neon_shape_tab[] =
13535{
13536 NEON_SHAPE_DEF
13537};
13538
13539#undef X
13540#undef S2
13541#undef S3
13542#undef S4
13543
5287ad62
JB
13544/* Bit masks used in type checking given instructions.
13545 'N_EQK' means the type must be the same as (or based on in some way) the key
13546 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13547 set, various other bits can be set as well in order to modify the meaning of
13548 the type constraint. */
13549
13550enum neon_type_mask
13551{
8e79c3df
CM
13552 N_S8 = 0x0000001,
13553 N_S16 = 0x0000002,
13554 N_S32 = 0x0000004,
13555 N_S64 = 0x0000008,
13556 N_U8 = 0x0000010,
13557 N_U16 = 0x0000020,
13558 N_U32 = 0x0000040,
13559 N_U64 = 0x0000080,
13560 N_I8 = 0x0000100,
13561 N_I16 = 0x0000200,
13562 N_I32 = 0x0000400,
13563 N_I64 = 0x0000800,
13564 N_8 = 0x0001000,
13565 N_16 = 0x0002000,
13566 N_32 = 0x0004000,
13567 N_64 = 0x0008000,
13568 N_P8 = 0x0010000,
13569 N_P16 = 0x0020000,
13570 N_F16 = 0x0040000,
13571 N_F32 = 0x0080000,
13572 N_F64 = 0x0100000,
4f51b4bd 13573 N_P64 = 0x0200000,
c921be7d
NC
13574 N_KEY = 0x1000000, /* Key element (main type specifier). */
13575 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13576 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13577 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13578 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13579 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13580 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13581 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13582 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13583 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13584 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13585 N_UTYP = 0,
4f51b4bd 13586 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13587};
13588
dcbf9037
JB
13589#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13590
5287ad62
JB
13591#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13592#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13593#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13594#define N_S_32 (N_S8 | N_S16 | N_S32)
13595#define N_F_16_32 (N_F16 | N_F32)
13596#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13597#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13598#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13599#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13600
13601/* Pass this as the first type argument to neon_check_type to ignore types
13602 altogether. */
13603#define N_IGNORE_TYPE (N_KEY | N_EQK)
13604
037e8744
JB
13605/* Select a "shape" for the current instruction (describing register types or
13606 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13607 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13608 function of operand parsing, so this function doesn't need to be called.
13609 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13610
13611static enum neon_shape
037e8744 13612neon_select_shape (enum neon_shape shape, ...)
5287ad62 13613{
037e8744
JB
13614 va_list ap;
13615 enum neon_shape first_shape = shape;
5287ad62
JB
13616
13617 /* Fix missing optional operands. FIXME: we don't know at this point how
13618 many arguments we should have, so this makes the assumption that we have
13619 > 1. This is true of all current Neon opcodes, I think, but may not be
13620 true in the future. */
13621 if (!inst.operands[1].present)
13622 inst.operands[1] = inst.operands[0];
13623
037e8744 13624 va_start (ap, shape);
5f4273c7 13625
21d799b5 13626 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13627 {
13628 unsigned j;
13629 int matches = 1;
13630
13631 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13632 {
13633 if (!inst.operands[j].present)
13634 {
13635 matches = 0;
13636 break;
13637 }
13638
13639 switch (neon_shape_tab[shape].el[j])
13640 {
d54af2d0
RL
13641 /* If a .f16, .16, .u16, .s16 type specifier is given over
13642 a VFP single precision register operand, it's essentially
13643 means only half of the register is used.
13644
13645 If the type specifier is given after the mnemonics, the
13646 information is stored in inst.vectype. If the type specifier
13647 is given after register operand, the information is stored
13648 in inst.operands[].vectype.
13649
13650 When there is only one type specifier, and all the register
13651 operands are the same type of hardware register, the type
13652 specifier applies to all register operands.
13653
13654 If no type specifier is given, the shape is inferred from
13655 operand information.
13656
13657 for example:
13658 vadd.f16 s0, s1, s2: NS_HHH
13659 vabs.f16 s0, s1: NS_HH
13660 vmov.f16 s0, r1: NS_HR
13661 vmov.f16 r0, s1: NS_RH
13662 vcvt.f16 r0, s1: NS_RH
13663 vcvt.f16.s32 s2, s2, #29: NS_HFI
13664 vcvt.f16.s32 s2, s2: NS_HF
13665 */
13666 case SE_H:
13667 if (!(inst.operands[j].isreg
13668 && inst.operands[j].isvec
13669 && inst.operands[j].issingle
13670 && !inst.operands[j].isquad
13671 && ((inst.vectype.elems == 1
13672 && inst.vectype.el[0].size == 16)
13673 || (inst.vectype.elems > 1
13674 && inst.vectype.el[j].size == 16)
13675 || (inst.vectype.elems == 0
13676 && inst.operands[j].vectype.type != NT_invtype
13677 && inst.operands[j].vectype.size == 16))))
13678 matches = 0;
13679 break;
13680
477330fc
RM
13681 case SE_F:
13682 if (!(inst.operands[j].isreg
13683 && inst.operands[j].isvec
13684 && inst.operands[j].issingle
d54af2d0
RL
13685 && !inst.operands[j].isquad
13686 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13687 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13688 || (inst.vectype.elems == 0
13689 && (inst.operands[j].vectype.size == 32
13690 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13691 matches = 0;
13692 break;
13693
13694 case SE_D:
13695 if (!(inst.operands[j].isreg
13696 && inst.operands[j].isvec
13697 && !inst.operands[j].isquad
13698 && !inst.operands[j].issingle))
13699 matches = 0;
13700 break;
13701
13702 case SE_R:
13703 if (!(inst.operands[j].isreg
13704 && !inst.operands[j].isvec))
13705 matches = 0;
13706 break;
13707
13708 case SE_Q:
13709 if (!(inst.operands[j].isreg
13710 && inst.operands[j].isvec
13711 && inst.operands[j].isquad
13712 && !inst.operands[j].issingle))
13713 matches = 0;
13714 break;
13715
13716 case SE_I:
13717 if (!(!inst.operands[j].isreg
13718 && !inst.operands[j].isscalar))
13719 matches = 0;
13720 break;
13721
13722 case SE_S:
13723 if (!(!inst.operands[j].isreg
13724 && inst.operands[j].isscalar))
13725 matches = 0;
13726 break;
13727
13728 case SE_L:
13729 break;
13730 }
3fde54a2
JZ
13731 if (!matches)
13732 break;
477330fc 13733 }
ad6cec43
MGD
13734 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13735 /* We've matched all the entries in the shape table, and we don't
13736 have any left over operands which have not been matched. */
477330fc 13737 break;
037e8744 13738 }
5f4273c7 13739
037e8744 13740 va_end (ap);
5287ad62 13741
037e8744
JB
13742 if (shape == NS_NULL && first_shape != NS_NULL)
13743 first_error (_("invalid instruction shape"));
5287ad62 13744
037e8744
JB
13745 return shape;
13746}
5287ad62 13747
037e8744
JB
13748/* True if SHAPE is predominantly a quadword operation (most of the time, this
13749 means the Q bit should be set). */
13750
13751static int
13752neon_quad (enum neon_shape shape)
13753{
13754 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13755}
037e8744 13756
5287ad62
JB
13757static void
13758neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13759 unsigned *g_size)
5287ad62
JB
13760{
13761 /* Allow modification to be made to types which are constrained to be
13762 based on the key element, based on bits set alongside N_EQK. */
13763 if ((typebits & N_EQK) != 0)
13764 {
13765 if ((typebits & N_HLF) != 0)
13766 *g_size /= 2;
13767 else if ((typebits & N_DBL) != 0)
13768 *g_size *= 2;
13769 if ((typebits & N_SGN) != 0)
13770 *g_type = NT_signed;
13771 else if ((typebits & N_UNS) != 0)
477330fc 13772 *g_type = NT_unsigned;
5287ad62 13773 else if ((typebits & N_INT) != 0)
477330fc 13774 *g_type = NT_integer;
5287ad62 13775 else if ((typebits & N_FLT) != 0)
477330fc 13776 *g_type = NT_float;
dcbf9037 13777 else if ((typebits & N_SIZ) != 0)
477330fc 13778 *g_type = NT_untyped;
5287ad62
JB
13779 }
13780}
5f4273c7 13781
5287ad62
JB
13782/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13783 operand type, i.e. the single type specified in a Neon instruction when it
13784 is the only one given. */
13785
13786static struct neon_type_el
13787neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13788{
13789 struct neon_type_el dest = *key;
5f4273c7 13790
9c2799c2 13791 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13792
5287ad62
JB
13793 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13794
13795 return dest;
13796}
13797
13798/* Convert Neon type and size into compact bitmask representation. */
13799
13800static enum neon_type_mask
13801type_chk_of_el_type (enum neon_el_type type, unsigned size)
13802{
13803 switch (type)
13804 {
13805 case NT_untyped:
13806 switch (size)
477330fc
RM
13807 {
13808 case 8: return N_8;
13809 case 16: return N_16;
13810 case 32: return N_32;
13811 case 64: return N_64;
13812 default: ;
13813 }
5287ad62
JB
13814 break;
13815
13816 case NT_integer:
13817 switch (size)
477330fc
RM
13818 {
13819 case 8: return N_I8;
13820 case 16: return N_I16;
13821 case 32: return N_I32;
13822 case 64: return N_I64;
13823 default: ;
13824 }
5287ad62
JB
13825 break;
13826
13827 case NT_float:
037e8744 13828 switch (size)
477330fc 13829 {
8e79c3df 13830 case 16: return N_F16;
477330fc
RM
13831 case 32: return N_F32;
13832 case 64: return N_F64;
13833 default: ;
13834 }
5287ad62
JB
13835 break;
13836
13837 case NT_poly:
13838 switch (size)
477330fc
RM
13839 {
13840 case 8: return N_P8;
13841 case 16: return N_P16;
4f51b4bd 13842 case 64: return N_P64;
477330fc
RM
13843 default: ;
13844 }
5287ad62
JB
13845 break;
13846
13847 case NT_signed:
13848 switch (size)
477330fc
RM
13849 {
13850 case 8: return N_S8;
13851 case 16: return N_S16;
13852 case 32: return N_S32;
13853 case 64: return N_S64;
13854 default: ;
13855 }
5287ad62
JB
13856 break;
13857
13858 case NT_unsigned:
13859 switch (size)
477330fc
RM
13860 {
13861 case 8: return N_U8;
13862 case 16: return N_U16;
13863 case 32: return N_U32;
13864 case 64: return N_U64;
13865 default: ;
13866 }
5287ad62
JB
13867 break;
13868
13869 default: ;
13870 }
5f4273c7 13871
5287ad62
JB
13872 return N_UTYP;
13873}
13874
13875/* Convert compact Neon bitmask type representation to a type and size. Only
13876 handles the case where a single bit is set in the mask. */
13877
dcbf9037 13878static int
5287ad62 13879el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13880 enum neon_type_mask mask)
5287ad62 13881{
dcbf9037
JB
13882 if ((mask & N_EQK) != 0)
13883 return FAIL;
13884
5287ad62
JB
13885 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13886 *size = 8;
c70a8987 13887 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13888 *size = 16;
dcbf9037 13889 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13890 *size = 32;
4f51b4bd 13891 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13892 *size = 64;
dcbf9037
JB
13893 else
13894 return FAIL;
13895
5287ad62
JB
13896 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13897 *type = NT_signed;
dcbf9037 13898 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13899 *type = NT_unsigned;
dcbf9037 13900 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13901 *type = NT_integer;
dcbf9037 13902 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13903 *type = NT_untyped;
4f51b4bd 13904 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13905 *type = NT_poly;
d54af2d0 13906 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13907 *type = NT_float;
dcbf9037
JB
13908 else
13909 return FAIL;
5f4273c7 13910
dcbf9037 13911 return SUCCESS;
5287ad62
JB
13912}
13913
13914/* Modify a bitmask of allowed types. This is only needed for type
13915 relaxation. */
13916
13917static unsigned
13918modify_types_allowed (unsigned allowed, unsigned mods)
13919{
13920 unsigned size;
13921 enum neon_el_type type;
13922 unsigned destmask;
13923 int i;
5f4273c7 13924
5287ad62 13925 destmask = 0;
5f4273c7 13926
5287ad62
JB
13927 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13928 {
21d799b5 13929 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13930 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13931 {
13932 neon_modify_type_size (mods, &type, &size);
13933 destmask |= type_chk_of_el_type (type, size);
13934 }
5287ad62 13935 }
5f4273c7 13936
5287ad62
JB
13937 return destmask;
13938}
13939
13940/* Check type and return type classification.
13941 The manual states (paraphrase): If one datatype is given, it indicates the
13942 type given in:
13943 - the second operand, if there is one
13944 - the operand, if there is no second operand
13945 - the result, if there are no operands.
13946 This isn't quite good enough though, so we use a concept of a "key" datatype
13947 which is set on a per-instruction basis, which is the one which matters when
13948 only one data type is written.
13949 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13950 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13951
13952static struct neon_type_el
13953neon_check_type (unsigned els, enum neon_shape ns, ...)
13954{
13955 va_list ap;
13956 unsigned i, pass, key_el = 0;
13957 unsigned types[NEON_MAX_TYPE_ELS];
13958 enum neon_el_type k_type = NT_invtype;
13959 unsigned k_size = -1u;
13960 struct neon_type_el badtype = {NT_invtype, -1};
13961 unsigned key_allowed = 0;
13962
13963 /* Optional registers in Neon instructions are always (not) in operand 1.
13964 Fill in the missing operand here, if it was omitted. */
13965 if (els > 1 && !inst.operands[1].present)
13966 inst.operands[1] = inst.operands[0];
13967
13968 /* Suck up all the varargs. */
13969 va_start (ap, ns);
13970 for (i = 0; i < els; i++)
13971 {
13972 unsigned thisarg = va_arg (ap, unsigned);
13973 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13974 {
13975 va_end (ap);
13976 return badtype;
13977 }
5287ad62
JB
13978 types[i] = thisarg;
13979 if ((thisarg & N_KEY) != 0)
477330fc 13980 key_el = i;
5287ad62
JB
13981 }
13982 va_end (ap);
13983
dcbf9037
JB
13984 if (inst.vectype.elems > 0)
13985 for (i = 0; i < els; i++)
13986 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13987 {
13988 first_error (_("types specified in both the mnemonic and operands"));
13989 return badtype;
13990 }
dcbf9037 13991
5287ad62
JB
13992 /* Duplicate inst.vectype elements here as necessary.
13993 FIXME: No idea if this is exactly the same as the ARM assembler,
13994 particularly when an insn takes one register and one non-register
13995 operand. */
13996 if (inst.vectype.elems == 1 && els > 1)
13997 {
13998 unsigned j;
13999 inst.vectype.elems = els;
14000 inst.vectype.el[key_el] = inst.vectype.el[0];
14001 for (j = 0; j < els; j++)
477330fc
RM
14002 if (j != key_el)
14003 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14004 types[j]);
dcbf9037
JB
14005 }
14006 else if (inst.vectype.elems == 0 && els > 0)
14007 {
14008 unsigned j;
14009 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14010 after each operand. We allow some flexibility here; as long as the
14011 "key" operand has a type, we can infer the others. */
dcbf9037 14012 for (j = 0; j < els; j++)
477330fc
RM
14013 if (inst.operands[j].vectype.type != NT_invtype)
14014 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14015
14016 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14017 {
14018 for (j = 0; j < els; j++)
14019 if (inst.operands[j].vectype.type == NT_invtype)
14020 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14021 types[j]);
14022 }
dcbf9037 14023 else
477330fc
RM
14024 {
14025 first_error (_("operand types can't be inferred"));
14026 return badtype;
14027 }
5287ad62
JB
14028 }
14029 else if (inst.vectype.elems != els)
14030 {
dcbf9037 14031 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14032 return badtype;
14033 }
14034
14035 for (pass = 0; pass < 2; pass++)
14036 {
14037 for (i = 0; i < els; i++)
477330fc
RM
14038 {
14039 unsigned thisarg = types[i];
14040 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14041 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14042 enum neon_el_type g_type = inst.vectype.el[i].type;
14043 unsigned g_size = inst.vectype.el[i].size;
14044
14045 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14046 integer types if sign-specific variants are unavailable. */
477330fc 14047 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14048 && (types_allowed & N_SU_ALL) == 0)
14049 g_type = NT_integer;
14050
477330fc 14051 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14052 them. Some instructions only care about signs for some element
14053 sizes, so handle that properly. */
477330fc 14054 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14055 && ((g_size == 8 && (types_allowed & N_8) != 0)
14056 || (g_size == 16 && (types_allowed & N_16) != 0)
14057 || (g_size == 32 && (types_allowed & N_32) != 0)
14058 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14059 g_type = NT_untyped;
14060
477330fc
RM
14061 if (pass == 0)
14062 {
14063 if ((thisarg & N_KEY) != 0)
14064 {
14065 k_type = g_type;
14066 k_size = g_size;
14067 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14068
14069 /* Check architecture constraint on FP16 extension. */
14070 if (k_size == 16
14071 && k_type == NT_float
14072 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14073 {
14074 inst.error = _(BAD_FP16);
14075 return badtype;
14076 }
477330fc
RM
14077 }
14078 }
14079 else
14080 {
14081 if ((thisarg & N_VFP) != 0)
14082 {
14083 enum neon_shape_el regshape;
14084 unsigned regwidth, match;
99b253c5
NC
14085
14086 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14087 if (ns == NS_NULL)
14088 {
14089 first_error (_("invalid instruction shape"));
14090 return badtype;
14091 }
477330fc
RM
14092 regshape = neon_shape_tab[ns].el[i];
14093 regwidth = neon_shape_el_size[regshape];
14094
14095 /* In VFP mode, operands must match register widths. If we
14096 have a key operand, use its width, else use the width of
14097 the current operand. */
14098 if (k_size != -1u)
14099 match = k_size;
14100 else
14101 match = g_size;
14102
9db2f6b4
RL
14103 /* FP16 will use a single precision register. */
14104 if (regwidth == 32 && match == 16)
14105 {
14106 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14107 match = regwidth;
14108 else
14109 {
14110 inst.error = _(BAD_FP16);
14111 return badtype;
14112 }
14113 }
14114
477330fc
RM
14115 if (regwidth != match)
14116 {
14117 first_error (_("operand size must match register width"));
14118 return badtype;
14119 }
14120 }
14121
14122 if ((thisarg & N_EQK) == 0)
14123 {
14124 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14125
14126 if ((given_type & types_allowed) == 0)
14127 {
14128 first_error (_("bad type in Neon instruction"));
14129 return badtype;
14130 }
14131 }
14132 else
14133 {
14134 enum neon_el_type mod_k_type = k_type;
14135 unsigned mod_k_size = k_size;
14136 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14137 if (g_type != mod_k_type || g_size != mod_k_size)
14138 {
14139 first_error (_("inconsistent types in Neon instruction"));
14140 return badtype;
14141 }
14142 }
14143 }
14144 }
5287ad62
JB
14145 }
14146
14147 return inst.vectype.el[key_el];
14148}
14149
037e8744 14150/* Neon-style VFP instruction forwarding. */
5287ad62 14151
037e8744
JB
14152/* Thumb VFP instructions have 0xE in the condition field. */
14153
14154static void
14155do_vfp_cond_or_thumb (void)
5287ad62 14156{
88714cb8
DG
14157 inst.is_neon = 1;
14158
5287ad62 14159 if (thumb_mode)
037e8744 14160 inst.instruction |= 0xe0000000;
5287ad62 14161 else
037e8744 14162 inst.instruction |= inst.cond << 28;
5287ad62
JB
14163}
14164
037e8744
JB
14165/* Look up and encode a simple mnemonic, for use as a helper function for the
14166 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14167 etc. It is assumed that operand parsing has already been done, and that the
14168 operands are in the form expected by the given opcode (this isn't necessarily
14169 the same as the form in which they were parsed, hence some massaging must
14170 take place before this function is called).
14171 Checks current arch version against that in the looked-up opcode. */
5287ad62 14172
037e8744
JB
14173static void
14174do_vfp_nsyn_opcode (const char *opname)
5287ad62 14175{
037e8744 14176 const struct asm_opcode *opcode;
5f4273c7 14177
21d799b5 14178 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14179
037e8744
JB
14180 if (!opcode)
14181 abort ();
5287ad62 14182
037e8744 14183 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14184 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14185 _(BAD_FPU));
5287ad62 14186
88714cb8
DG
14187 inst.is_neon = 1;
14188
037e8744
JB
14189 if (thumb_mode)
14190 {
14191 inst.instruction = opcode->tvalue;
14192 opcode->tencode ();
14193 }
14194 else
14195 {
14196 inst.instruction = (inst.cond << 28) | opcode->avalue;
14197 opcode->aencode ();
14198 }
14199}
5287ad62
JB
14200
14201static void
037e8744 14202do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14203{
037e8744
JB
14204 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14205
9db2f6b4 14206 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14207 {
14208 if (is_add)
477330fc 14209 do_vfp_nsyn_opcode ("fadds");
037e8744 14210 else
477330fc 14211 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14212
14213 /* ARMv8.2 fp16 instruction. */
14214 if (rs == NS_HHH)
14215 do_scalar_fp16_v82_encode ();
037e8744
JB
14216 }
14217 else
14218 {
14219 if (is_add)
477330fc 14220 do_vfp_nsyn_opcode ("faddd");
037e8744 14221 else
477330fc 14222 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14223 }
14224}
14225
14226/* Check operand types to see if this is a VFP instruction, and if so call
14227 PFN (). */
14228
14229static int
14230try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14231{
14232 enum neon_shape rs;
14233 struct neon_type_el et;
14234
14235 switch (args)
14236 {
14237 case 2:
9db2f6b4
RL
14238 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14239 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14240 break;
5f4273c7 14241
037e8744 14242 case 3:
9db2f6b4
RL
14243 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14244 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14245 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14246 break;
14247
14248 default:
14249 abort ();
14250 }
14251
14252 if (et.type != NT_invtype)
14253 {
14254 pfn (rs);
14255 return SUCCESS;
14256 }
037e8744 14257
99b253c5 14258 inst.error = NULL;
037e8744
JB
14259 return FAIL;
14260}
14261
14262static void
14263do_vfp_nsyn_mla_mls (enum neon_shape rs)
14264{
14265 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14266
9db2f6b4 14267 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14268 {
14269 if (is_mla)
477330fc 14270 do_vfp_nsyn_opcode ("fmacs");
037e8744 14271 else
477330fc 14272 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14273
14274 /* ARMv8.2 fp16 instruction. */
14275 if (rs == NS_HHH)
14276 do_scalar_fp16_v82_encode ();
037e8744
JB
14277 }
14278 else
14279 {
14280 if (is_mla)
477330fc 14281 do_vfp_nsyn_opcode ("fmacd");
037e8744 14282 else
477330fc 14283 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14284 }
14285}
14286
62f3b8c8
PB
14287static void
14288do_vfp_nsyn_fma_fms (enum neon_shape rs)
14289{
14290 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14291
9db2f6b4 14292 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14293 {
14294 if (is_fma)
477330fc 14295 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14296 else
477330fc 14297 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14298
14299 /* ARMv8.2 fp16 instruction. */
14300 if (rs == NS_HHH)
14301 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14302 }
14303 else
14304 {
14305 if (is_fma)
477330fc 14306 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14307 else
477330fc 14308 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14309 }
14310}
14311
037e8744
JB
14312static void
14313do_vfp_nsyn_mul (enum neon_shape rs)
14314{
9db2f6b4
RL
14315 if (rs == NS_FFF || rs == NS_HHH)
14316 {
14317 do_vfp_nsyn_opcode ("fmuls");
14318
14319 /* ARMv8.2 fp16 instruction. */
14320 if (rs == NS_HHH)
14321 do_scalar_fp16_v82_encode ();
14322 }
037e8744
JB
14323 else
14324 do_vfp_nsyn_opcode ("fmuld");
14325}
14326
14327static void
14328do_vfp_nsyn_abs_neg (enum neon_shape rs)
14329{
14330 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14331 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14332
9db2f6b4 14333 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14334 {
14335 if (is_neg)
477330fc 14336 do_vfp_nsyn_opcode ("fnegs");
037e8744 14337 else
477330fc 14338 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14339
14340 /* ARMv8.2 fp16 instruction. */
14341 if (rs == NS_HH)
14342 do_scalar_fp16_v82_encode ();
037e8744
JB
14343 }
14344 else
14345 {
14346 if (is_neg)
477330fc 14347 do_vfp_nsyn_opcode ("fnegd");
037e8744 14348 else
477330fc 14349 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14350 }
14351}
14352
14353/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14354 insns belong to Neon, and are handled elsewhere. */
14355
14356static void
14357do_vfp_nsyn_ldm_stm (int is_dbmode)
14358{
14359 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14360 if (is_ldm)
14361 {
14362 if (is_dbmode)
477330fc 14363 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14364 else
477330fc 14365 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14366 }
14367 else
14368 {
14369 if (is_dbmode)
477330fc 14370 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14371 else
477330fc 14372 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14373 }
14374}
14375
037e8744
JB
14376static void
14377do_vfp_nsyn_sqrt (void)
14378{
9db2f6b4
RL
14379 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14380 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14381
9db2f6b4
RL
14382 if (rs == NS_FF || rs == NS_HH)
14383 {
14384 do_vfp_nsyn_opcode ("fsqrts");
14385
14386 /* ARMv8.2 fp16 instruction. */
14387 if (rs == NS_HH)
14388 do_scalar_fp16_v82_encode ();
14389 }
037e8744
JB
14390 else
14391 do_vfp_nsyn_opcode ("fsqrtd");
14392}
14393
14394static void
14395do_vfp_nsyn_div (void)
14396{
9db2f6b4 14397 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14398 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14399 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14400
9db2f6b4
RL
14401 if (rs == NS_FFF || rs == NS_HHH)
14402 {
14403 do_vfp_nsyn_opcode ("fdivs");
14404
14405 /* ARMv8.2 fp16 instruction. */
14406 if (rs == NS_HHH)
14407 do_scalar_fp16_v82_encode ();
14408 }
037e8744
JB
14409 else
14410 do_vfp_nsyn_opcode ("fdivd");
14411}
14412
14413static void
14414do_vfp_nsyn_nmul (void)
14415{
9db2f6b4 14416 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14417 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14418 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14419
9db2f6b4 14420 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14421 {
88714cb8 14422 NEON_ENCODE (SINGLE, inst);
037e8744 14423 do_vfp_sp_dyadic ();
9db2f6b4
RL
14424
14425 /* ARMv8.2 fp16 instruction. */
14426 if (rs == NS_HHH)
14427 do_scalar_fp16_v82_encode ();
037e8744
JB
14428 }
14429 else
14430 {
88714cb8 14431 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14432 do_vfp_dp_rd_rn_rm ();
14433 }
14434 do_vfp_cond_or_thumb ();
9db2f6b4 14435
037e8744
JB
14436}
14437
14438static void
14439do_vfp_nsyn_cmp (void)
14440{
9db2f6b4 14441 enum neon_shape rs;
037e8744
JB
14442 if (inst.operands[1].isreg)
14443 {
9db2f6b4
RL
14444 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14445 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14446
9db2f6b4 14447 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14448 {
14449 NEON_ENCODE (SINGLE, inst);
14450 do_vfp_sp_monadic ();
14451 }
037e8744 14452 else
477330fc
RM
14453 {
14454 NEON_ENCODE (DOUBLE, inst);
14455 do_vfp_dp_rd_rm ();
14456 }
037e8744
JB
14457 }
14458 else
14459 {
9db2f6b4
RL
14460 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14461 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14462
14463 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14464 {
14465 case N_MNEM_vcmp:
14466 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14467 break;
14468 case N_MNEM_vcmpe:
14469 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14470 break;
14471 default:
14472 abort ();
14473 }
5f4273c7 14474
9db2f6b4 14475 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14476 {
14477 NEON_ENCODE (SINGLE, inst);
14478 do_vfp_sp_compare_z ();
14479 }
037e8744 14480 else
477330fc
RM
14481 {
14482 NEON_ENCODE (DOUBLE, inst);
14483 do_vfp_dp_rd ();
14484 }
037e8744
JB
14485 }
14486 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14487
14488 /* ARMv8.2 fp16 instruction. */
14489 if (rs == NS_HI || rs == NS_HH)
14490 do_scalar_fp16_v82_encode ();
037e8744
JB
14491}
14492
14493static void
14494nsyn_insert_sp (void)
14495{
14496 inst.operands[1] = inst.operands[0];
14497 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14498 inst.operands[0].reg = REG_SP;
037e8744
JB
14499 inst.operands[0].isreg = 1;
14500 inst.operands[0].writeback = 1;
14501 inst.operands[0].present = 1;
14502}
14503
14504static void
14505do_vfp_nsyn_push (void)
14506{
14507 nsyn_insert_sp ();
b126985e
NC
14508
14509 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14510 _("register list must contain at least 1 and at most 16 "
14511 "registers"));
14512
037e8744
JB
14513 if (inst.operands[1].issingle)
14514 do_vfp_nsyn_opcode ("fstmdbs");
14515 else
14516 do_vfp_nsyn_opcode ("fstmdbd");
14517}
14518
14519static void
14520do_vfp_nsyn_pop (void)
14521{
14522 nsyn_insert_sp ();
b126985e
NC
14523
14524 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14525 _("register list must contain at least 1 and at most 16 "
14526 "registers"));
14527
037e8744 14528 if (inst.operands[1].issingle)
22b5b651 14529 do_vfp_nsyn_opcode ("fldmias");
037e8744 14530 else
22b5b651 14531 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14532}
14533
14534/* Fix up Neon data-processing instructions, ORing in the correct bits for
14535 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14536
88714cb8
DG
14537static void
14538neon_dp_fixup (struct arm_it* insn)
037e8744 14539{
88714cb8
DG
14540 unsigned int i = insn->instruction;
14541 insn->is_neon = 1;
14542
037e8744
JB
14543 if (thumb_mode)
14544 {
14545 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14546 if (i & (1 << 24))
477330fc 14547 i |= 1 << 28;
5f4273c7 14548
037e8744 14549 i &= ~(1 << 24);
5f4273c7 14550
037e8744
JB
14551 i |= 0xef000000;
14552 }
14553 else
14554 i |= 0xf2000000;
5f4273c7 14555
88714cb8 14556 insn->instruction = i;
037e8744
JB
14557}
14558
14559/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14560 (0, 1, 2, 3). */
14561
14562static unsigned
14563neon_logbits (unsigned x)
14564{
14565 return ffs (x) - 4;
14566}
14567
14568#define LOW4(R) ((R) & 0xf)
14569#define HI1(R) (((R) >> 4) & 1)
14570
14571/* Encode insns with bit pattern:
14572
14573 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14574 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14575
037e8744
JB
14576 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14577 different meaning for some instruction. */
14578
14579static void
14580neon_three_same (int isquad, int ubit, int size)
14581{
14582 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14583 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14584 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14585 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14586 inst.instruction |= LOW4 (inst.operands[2].reg);
14587 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14588 inst.instruction |= (isquad != 0) << 6;
14589 inst.instruction |= (ubit != 0) << 24;
14590 if (size != -1)
14591 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14592
88714cb8 14593 neon_dp_fixup (&inst);
037e8744
JB
14594}
14595
14596/* Encode instructions of the form:
14597
14598 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14599 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14600
14601 Don't write size if SIZE == -1. */
14602
14603static void
14604neon_two_same (int qbit, int ubit, int size)
14605{
14606 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14607 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14608 inst.instruction |= LOW4 (inst.operands[1].reg);
14609 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14610 inst.instruction |= (qbit != 0) << 6;
14611 inst.instruction |= (ubit != 0) << 24;
14612
14613 if (size != -1)
14614 inst.instruction |= neon_logbits (size) << 18;
14615
88714cb8 14616 neon_dp_fixup (&inst);
5287ad62
JB
14617}
14618
14619/* Neon instruction encoders, in approximate order of appearance. */
14620
14621static void
14622do_neon_dyadic_i_su (void)
14623{
037e8744 14624 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14625 struct neon_type_el et = neon_check_type (3, rs,
14626 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14627 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14628}
14629
14630static void
14631do_neon_dyadic_i64_su (void)
14632{
037e8744 14633 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14634 struct neon_type_el et = neon_check_type (3, rs,
14635 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14636 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14637}
14638
14639static void
14640neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14641 unsigned immbits)
5287ad62
JB
14642{
14643 unsigned size = et.size >> 3;
14644 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14645 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14646 inst.instruction |= LOW4 (inst.operands[1].reg);
14647 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14648 inst.instruction |= (isquad != 0) << 6;
14649 inst.instruction |= immbits << 16;
14650 inst.instruction |= (size >> 3) << 7;
14651 inst.instruction |= (size & 0x7) << 19;
14652 if (write_ubit)
14653 inst.instruction |= (uval != 0) << 24;
14654
88714cb8 14655 neon_dp_fixup (&inst);
5287ad62
JB
14656}
14657
14658static void
14659do_neon_shl_imm (void)
14660{
14661 if (!inst.operands[2].isreg)
14662 {
037e8744 14663 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14664 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14665 int imm = inst.operands[2].imm;
14666
14667 constraint (imm < 0 || (unsigned)imm >= et.size,
14668 _("immediate out of range for shift"));
88714cb8 14669 NEON_ENCODE (IMMED, inst);
cb3b1e65 14670 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14671 }
14672 else
14673 {
037e8744 14674 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14675 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14676 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14677 unsigned int tmp;
14678
14679 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14680 vshl.xx Dd, Dm, Dn
14681 whereas other 3-register operations encoded by neon_three_same have
14682 syntax like:
14683 vadd.xx Dd, Dn, Dm
14684 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14685 here. */
627907b7
JB
14686 tmp = inst.operands[2].reg;
14687 inst.operands[2].reg = inst.operands[1].reg;
14688 inst.operands[1].reg = tmp;
88714cb8 14689 NEON_ENCODE (INTEGER, inst);
037e8744 14690 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14691 }
14692}
14693
14694static void
14695do_neon_qshl_imm (void)
14696{
14697 if (!inst.operands[2].isreg)
14698 {
037e8744 14699 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14700 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14701 int imm = inst.operands[2].imm;
627907b7 14702
cb3b1e65
JB
14703 constraint (imm < 0 || (unsigned)imm >= et.size,
14704 _("immediate out of range for shift"));
88714cb8 14705 NEON_ENCODE (IMMED, inst);
cb3b1e65 14706 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14707 }
14708 else
14709 {
037e8744 14710 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14711 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14712 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14713 unsigned int tmp;
14714
14715 /* See note in do_neon_shl_imm. */
14716 tmp = inst.operands[2].reg;
14717 inst.operands[2].reg = inst.operands[1].reg;
14718 inst.operands[1].reg = tmp;
88714cb8 14719 NEON_ENCODE (INTEGER, inst);
037e8744 14720 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14721 }
14722}
14723
627907b7
JB
14724static void
14725do_neon_rshl (void)
14726{
14727 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14728 struct neon_type_el et = neon_check_type (3, rs,
14729 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14730 unsigned int tmp;
14731
14732 tmp = inst.operands[2].reg;
14733 inst.operands[2].reg = inst.operands[1].reg;
14734 inst.operands[1].reg = tmp;
14735 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14736}
14737
5287ad62
JB
14738static int
14739neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14740{
036dc3f7
PB
14741 /* Handle .I8 pseudo-instructions. */
14742 if (size == 8)
5287ad62 14743 {
5287ad62 14744 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14745 FIXME is this the intended semantics? There doesn't seem much point in
14746 accepting .I8 if so. */
5287ad62
JB
14747 immediate |= immediate << 8;
14748 size = 16;
036dc3f7
PB
14749 }
14750
14751 if (size >= 32)
14752 {
14753 if (immediate == (immediate & 0x000000ff))
14754 {
14755 *immbits = immediate;
14756 return 0x1;
14757 }
14758 else if (immediate == (immediate & 0x0000ff00))
14759 {
14760 *immbits = immediate >> 8;
14761 return 0x3;
14762 }
14763 else if (immediate == (immediate & 0x00ff0000))
14764 {
14765 *immbits = immediate >> 16;
14766 return 0x5;
14767 }
14768 else if (immediate == (immediate & 0xff000000))
14769 {
14770 *immbits = immediate >> 24;
14771 return 0x7;
14772 }
14773 if ((immediate & 0xffff) != (immediate >> 16))
14774 goto bad_immediate;
14775 immediate &= 0xffff;
5287ad62
JB
14776 }
14777
14778 if (immediate == (immediate & 0x000000ff))
14779 {
14780 *immbits = immediate;
036dc3f7 14781 return 0x9;
5287ad62
JB
14782 }
14783 else if (immediate == (immediate & 0x0000ff00))
14784 {
14785 *immbits = immediate >> 8;
036dc3f7 14786 return 0xb;
5287ad62
JB
14787 }
14788
14789 bad_immediate:
dcbf9037 14790 first_error (_("immediate value out of range"));
5287ad62
JB
14791 return FAIL;
14792}
14793
5287ad62
JB
14794static void
14795do_neon_logic (void)
14796{
14797 if (inst.operands[2].present && inst.operands[2].isreg)
14798 {
037e8744 14799 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14800 neon_check_type (3, rs, N_IGNORE_TYPE);
14801 /* U bit and size field were set as part of the bitmask. */
88714cb8 14802 NEON_ENCODE (INTEGER, inst);
037e8744 14803 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14804 }
14805 else
14806 {
4316f0d2
DG
14807 const int three_ops_form = (inst.operands[2].present
14808 && !inst.operands[2].isreg);
14809 const int immoperand = (three_ops_form ? 2 : 1);
14810 enum neon_shape rs = (three_ops_form
14811 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14812 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14813 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14814 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14815 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14816 unsigned immbits;
14817 int cmode;
5f4273c7 14818
5287ad62 14819 if (et.type == NT_invtype)
477330fc 14820 return;
5f4273c7 14821
4316f0d2
DG
14822 if (three_ops_form)
14823 constraint (inst.operands[0].reg != inst.operands[1].reg,
14824 _("first and second operands shall be the same register"));
14825
88714cb8 14826 NEON_ENCODE (IMMED, inst);
5287ad62 14827
4316f0d2 14828 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14829 if (et.size == 64)
14830 {
14831 /* .i64 is a pseudo-op, so the immediate must be a repeating
14832 pattern. */
4316f0d2
DG
14833 if (immbits != (inst.operands[immoperand].regisimm ?
14834 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14835 {
14836 /* Set immbits to an invalid constant. */
14837 immbits = 0xdeadbeef;
14838 }
14839 }
14840
5287ad62 14841 switch (opcode)
477330fc
RM
14842 {
14843 case N_MNEM_vbic:
14844 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14845 break;
14846
14847 case N_MNEM_vorr:
14848 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14849 break;
14850
14851 case N_MNEM_vand:
14852 /* Pseudo-instruction for VBIC. */
14853 neon_invert_size (&immbits, 0, et.size);
14854 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14855 break;
14856
14857 case N_MNEM_vorn:
14858 /* Pseudo-instruction for VORR. */
14859 neon_invert_size (&immbits, 0, et.size);
14860 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14861 break;
14862
14863 default:
14864 abort ();
14865 }
5287ad62
JB
14866
14867 if (cmode == FAIL)
477330fc 14868 return;
5287ad62 14869
037e8744 14870 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14871 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14872 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14873 inst.instruction |= cmode << 8;
14874 neon_write_immbits (immbits);
5f4273c7 14875
88714cb8 14876 neon_dp_fixup (&inst);
5287ad62
JB
14877 }
14878}
14879
14880static void
14881do_neon_bitfield (void)
14882{
037e8744 14883 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14884 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14885 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14886}
14887
14888static void
dcbf9037 14889neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14890 unsigned destbits)
5287ad62 14891{
037e8744 14892 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14893 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14894 types | N_KEY);
5287ad62
JB
14895 if (et.type == NT_float)
14896 {
88714cb8 14897 NEON_ENCODE (FLOAT, inst);
cc933301 14898 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14899 }
14900 else
14901 {
88714cb8 14902 NEON_ENCODE (INTEGER, inst);
037e8744 14903 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14904 }
14905}
14906
14907static void
14908do_neon_dyadic_if_su (void)
14909{
dcbf9037 14910 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14911}
14912
14913static void
14914do_neon_dyadic_if_su_d (void)
14915{
14916 /* This version only allow D registers, but that constraint is enforced during
14917 operand parsing so we don't need to do anything extra here. */
dcbf9037 14918 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14919}
14920
5287ad62
JB
14921static void
14922do_neon_dyadic_if_i_d (void)
14923{
428e3f1f
PB
14924 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14925 affected if we specify unsigned args. */
14926 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14927}
14928
037e8744
JB
14929enum vfp_or_neon_is_neon_bits
14930{
14931 NEON_CHECK_CC = 1,
73924fbc
MGD
14932 NEON_CHECK_ARCH = 2,
14933 NEON_CHECK_ARCH8 = 4
037e8744
JB
14934};
14935
14936/* Call this function if an instruction which may have belonged to the VFP or
14937 Neon instruction sets, but turned out to be a Neon instruction (due to the
14938 operand types involved, etc.). We have to check and/or fix-up a couple of
14939 things:
14940
14941 - Make sure the user hasn't attempted to make a Neon instruction
14942 conditional.
14943 - Alter the value in the condition code field if necessary.
14944 - Make sure that the arch supports Neon instructions.
14945
14946 Which of these operations take place depends on bits from enum
14947 vfp_or_neon_is_neon_bits.
14948
14949 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14950 current instruction's condition is COND_ALWAYS, the condition field is
14951 changed to inst.uncond_value. This is necessary because instructions shared
14952 between VFP and Neon may be conditional for the VFP variants only, and the
14953 unconditional Neon version must have, e.g., 0xF in the condition field. */
14954
14955static int
14956vfp_or_neon_is_neon (unsigned check)
14957{
14958 /* Conditions are always legal in Thumb mode (IT blocks). */
14959 if (!thumb_mode && (check & NEON_CHECK_CC))
14960 {
14961 if (inst.cond != COND_ALWAYS)
477330fc
RM
14962 {
14963 first_error (_(BAD_COND));
14964 return FAIL;
14965 }
037e8744 14966 if (inst.uncond_value != -1)
477330fc 14967 inst.instruction |= inst.uncond_value << 28;
037e8744 14968 }
5f4273c7 14969
037e8744 14970 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14971 && !mark_feature_used (&fpu_neon_ext_v1))
14972 {
14973 first_error (_(BAD_FPU));
14974 return FAIL;
14975 }
14976
14977 if ((check & NEON_CHECK_ARCH8)
14978 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14979 {
14980 first_error (_(BAD_FPU));
14981 return FAIL;
14982 }
5f4273c7 14983
037e8744
JB
14984 return SUCCESS;
14985}
14986
5287ad62
JB
14987static void
14988do_neon_addsub_if_i (void)
14989{
037e8744
JB
14990 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14991 return;
14992
14993 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14994 return;
14995
5287ad62
JB
14996 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14997 affected if we specify unsigned args. */
dcbf9037 14998 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14999}
15000
15001/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15002 result to be:
15003 V<op> A,B (A is operand 0, B is operand 2)
15004 to mean:
15005 V<op> A,B,A
15006 not:
15007 V<op> A,B,B
15008 so handle that case specially. */
15009
15010static void
15011neon_exchange_operands (void)
15012{
5287ad62
JB
15013 if (inst.operands[1].present)
15014 {
e1fa0163
NC
15015 void *scratch = xmalloc (sizeof (inst.operands[0]));
15016
5287ad62
JB
15017 /* Swap operands[1] and operands[2]. */
15018 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15019 inst.operands[1] = inst.operands[2];
15020 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15021 free (scratch);
5287ad62
JB
15022 }
15023 else
15024 {
15025 inst.operands[1] = inst.operands[2];
15026 inst.operands[2] = inst.operands[0];
15027 }
15028}
15029
15030static void
15031neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15032{
15033 if (inst.operands[2].isreg)
15034 {
15035 if (invert)
477330fc 15036 neon_exchange_operands ();
dcbf9037 15037 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15038 }
15039 else
15040 {
037e8744 15041 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15042 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15043 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15044
88714cb8 15045 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15046 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15047 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15048 inst.instruction |= LOW4 (inst.operands[1].reg);
15049 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15050 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15051 inst.instruction |= (et.type == NT_float) << 10;
15052 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15053
88714cb8 15054 neon_dp_fixup (&inst);
5287ad62
JB
15055 }
15056}
15057
15058static void
15059do_neon_cmp (void)
15060{
cc933301 15061 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15062}
15063
15064static void
15065do_neon_cmp_inv (void)
15066{
cc933301 15067 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15068}
15069
15070static void
15071do_neon_ceq (void)
15072{
15073 neon_compare (N_IF_32, N_IF_32, FALSE);
15074}
15075
15076/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15077 scalars, which are encoded in 5 bits, M : Rm.
15078 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15079 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15080 index in M.
15081
15082 Dot Product instructions are similar to multiply instructions except elsize
15083 should always be 32.
15084
15085 This function translates SCALAR, which is GAS's internal encoding of indexed
15086 scalar register, to raw encoding. There is also register and index range
15087 check based on ELSIZE. */
5287ad62
JB
15088
15089static unsigned
15090neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15091{
dcbf9037
JB
15092 unsigned regno = NEON_SCALAR_REG (scalar);
15093 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15094
15095 switch (elsize)
15096 {
15097 case 16:
15098 if (regno > 7 || elno > 3)
477330fc 15099 goto bad_scalar;
5287ad62 15100 return regno | (elno << 3);
5f4273c7 15101
5287ad62
JB
15102 case 32:
15103 if (regno > 15 || elno > 1)
477330fc 15104 goto bad_scalar;
5287ad62
JB
15105 return regno | (elno << 4);
15106
15107 default:
15108 bad_scalar:
dcbf9037 15109 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15110 }
15111
15112 return 0;
15113}
15114
15115/* Encode multiply / multiply-accumulate scalar instructions. */
15116
15117static void
15118neon_mul_mac (struct neon_type_el et, int ubit)
15119{
dcbf9037
JB
15120 unsigned scalar;
15121
15122 /* Give a more helpful error message if we have an invalid type. */
15123 if (et.type == NT_invtype)
15124 return;
5f4273c7 15125
dcbf9037 15126 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15127 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15128 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15129 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15130 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15131 inst.instruction |= LOW4 (scalar);
15132 inst.instruction |= HI1 (scalar) << 5;
15133 inst.instruction |= (et.type == NT_float) << 8;
15134 inst.instruction |= neon_logbits (et.size) << 20;
15135 inst.instruction |= (ubit != 0) << 24;
15136
88714cb8 15137 neon_dp_fixup (&inst);
5287ad62
JB
15138}
15139
15140static void
15141do_neon_mac_maybe_scalar (void)
15142{
037e8744
JB
15143 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15144 return;
15145
15146 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15147 return;
15148
5287ad62
JB
15149 if (inst.operands[2].isscalar)
15150 {
037e8744 15151 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15152 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15153 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15154 NEON_ENCODE (SCALAR, inst);
037e8744 15155 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15156 }
15157 else
428e3f1f
PB
15158 {
15159 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15160 affected if we specify unsigned args. */
15161 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15162 }
5287ad62
JB
15163}
15164
62f3b8c8
PB
15165static void
15166do_neon_fmac (void)
15167{
15168 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15169 return;
15170
15171 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15172 return;
15173
15174 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15175}
15176
5287ad62
JB
15177static void
15178do_neon_tst (void)
15179{
037e8744 15180 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15181 struct neon_type_el et = neon_check_type (3, rs,
15182 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15183 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15184}
15185
15186/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15187 same types as the MAC equivalents. The polynomial type for this instruction
15188 is encoded the same as the integer type. */
15189
15190static void
15191do_neon_mul (void)
15192{
037e8744
JB
15193 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15194 return;
15195
15196 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15197 return;
15198
5287ad62
JB
15199 if (inst.operands[2].isscalar)
15200 do_neon_mac_maybe_scalar ();
15201 else
cc933301 15202 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15203}
15204
15205static void
15206do_neon_qdmulh (void)
15207{
15208 if (inst.operands[2].isscalar)
15209 {
037e8744 15210 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15211 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15212 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15213 NEON_ENCODE (SCALAR, inst);
037e8744 15214 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15215 }
15216 else
15217 {
037e8744 15218 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15219 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15220 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15221 NEON_ENCODE (INTEGER, inst);
5287ad62 15222 /* The U bit (rounding) comes from bit mask. */
037e8744 15223 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15224 }
15225}
15226
643afb90
MW
15227static void
15228do_neon_qrdmlah (void)
15229{
15230 /* Check we're on the correct architecture. */
15231 if (!mark_feature_used (&fpu_neon_ext_armv8))
15232 inst.error =
15233 _("instruction form not available on this architecture.");
15234 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15235 {
15236 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15237 record_feature_use (&fpu_neon_ext_v8_1);
15238 }
15239
15240 if (inst.operands[2].isscalar)
15241 {
15242 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15243 struct neon_type_el et = neon_check_type (3, rs,
15244 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15245 NEON_ENCODE (SCALAR, inst);
15246 neon_mul_mac (et, neon_quad (rs));
15247 }
15248 else
15249 {
15250 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15251 struct neon_type_el et = neon_check_type (3, rs,
15252 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15253 NEON_ENCODE (INTEGER, inst);
15254 /* The U bit (rounding) comes from bit mask. */
15255 neon_three_same (neon_quad (rs), 0, et.size);
15256 }
15257}
15258
5287ad62
JB
15259static void
15260do_neon_fcmp_absolute (void)
15261{
037e8744 15262 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15263 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15264 N_F_16_32 | N_KEY);
5287ad62 15265 /* Size field comes from bit mask. */
cc933301 15266 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15267}
15268
15269static void
15270do_neon_fcmp_absolute_inv (void)
15271{
15272 neon_exchange_operands ();
15273 do_neon_fcmp_absolute ();
15274}
15275
15276static void
15277do_neon_step (void)
15278{
037e8744 15279 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15280 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15281 N_F_16_32 | N_KEY);
15282 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15283}
15284
15285static void
15286do_neon_abs_neg (void)
15287{
037e8744
JB
15288 enum neon_shape rs;
15289 struct neon_type_el et;
5f4273c7 15290
037e8744
JB
15291 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15292 return;
15293
15294 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15295 return;
15296
15297 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15298 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15299
5287ad62
JB
15300 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15301 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15302 inst.instruction |= LOW4 (inst.operands[1].reg);
15303 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15304 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15305 inst.instruction |= (et.type == NT_float) << 10;
15306 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15307
88714cb8 15308 neon_dp_fixup (&inst);
5287ad62
JB
15309}
15310
15311static void
15312do_neon_sli (void)
15313{
037e8744 15314 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15315 struct neon_type_el et = neon_check_type (2, rs,
15316 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15317 int imm = inst.operands[2].imm;
15318 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15319 _("immediate out of range for insert"));
037e8744 15320 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15321}
15322
15323static void
15324do_neon_sri (void)
15325{
037e8744 15326 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15327 struct neon_type_el et = neon_check_type (2, rs,
15328 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15329 int imm = inst.operands[2].imm;
15330 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15331 _("immediate out of range for insert"));
037e8744 15332 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15333}
15334
15335static void
15336do_neon_qshlu_imm (void)
15337{
037e8744 15338 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15339 struct neon_type_el et = neon_check_type (2, rs,
15340 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15341 int imm = inst.operands[2].imm;
15342 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15343 _("immediate out of range for shift"));
5287ad62
JB
15344 /* Only encodes the 'U present' variant of the instruction.
15345 In this case, signed types have OP (bit 8) set to 0.
15346 Unsigned types have OP set to 1. */
15347 inst.instruction |= (et.type == NT_unsigned) << 8;
15348 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15349 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15350}
15351
15352static void
15353do_neon_qmovn (void)
15354{
15355 struct neon_type_el et = neon_check_type (2, NS_DQ,
15356 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15357 /* Saturating move where operands can be signed or unsigned, and the
15358 destination has the same signedness. */
88714cb8 15359 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15360 if (et.type == NT_unsigned)
15361 inst.instruction |= 0xc0;
15362 else
15363 inst.instruction |= 0x80;
15364 neon_two_same (0, 1, et.size / 2);
15365}
15366
15367static void
15368do_neon_qmovun (void)
15369{
15370 struct neon_type_el et = neon_check_type (2, NS_DQ,
15371 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15372 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15373 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15374 neon_two_same (0, 1, et.size / 2);
15375}
15376
15377static void
15378do_neon_rshift_sat_narrow (void)
15379{
15380 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15381 or unsigned. If operands are unsigned, results must also be unsigned. */
15382 struct neon_type_el et = neon_check_type (2, NS_DQI,
15383 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15384 int imm = inst.operands[2].imm;
15385 /* This gets the bounds check, size encoding and immediate bits calculation
15386 right. */
15387 et.size /= 2;
5f4273c7 15388
5287ad62
JB
15389 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15390 VQMOVN.I<size> <Dd>, <Qm>. */
15391 if (imm == 0)
15392 {
15393 inst.operands[2].present = 0;
15394 inst.instruction = N_MNEM_vqmovn;
15395 do_neon_qmovn ();
15396 return;
15397 }
5f4273c7 15398
5287ad62 15399 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15400 _("immediate out of range"));
5287ad62
JB
15401 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15402}
15403
15404static void
15405do_neon_rshift_sat_narrow_u (void)
15406{
15407 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15408 or unsigned. If operands are unsigned, results must also be unsigned. */
15409 struct neon_type_el et = neon_check_type (2, NS_DQI,
15410 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15411 int imm = inst.operands[2].imm;
15412 /* This gets the bounds check, size encoding and immediate bits calculation
15413 right. */
15414 et.size /= 2;
15415
15416 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15417 VQMOVUN.I<size> <Dd>, <Qm>. */
15418 if (imm == 0)
15419 {
15420 inst.operands[2].present = 0;
15421 inst.instruction = N_MNEM_vqmovun;
15422 do_neon_qmovun ();
15423 return;
15424 }
15425
15426 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15427 _("immediate out of range"));
5287ad62
JB
15428 /* FIXME: The manual is kind of unclear about what value U should have in
15429 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15430 must be 1. */
15431 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15432}
15433
15434static void
15435do_neon_movn (void)
15436{
15437 struct neon_type_el et = neon_check_type (2, NS_DQ,
15438 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15439 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15440 neon_two_same (0, 1, et.size / 2);
15441}
15442
15443static void
15444do_neon_rshift_narrow (void)
15445{
15446 struct neon_type_el et = neon_check_type (2, NS_DQI,
15447 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15448 int imm = inst.operands[2].imm;
15449 /* This gets the bounds check, size encoding and immediate bits calculation
15450 right. */
15451 et.size /= 2;
5f4273c7 15452
5287ad62
JB
15453 /* If immediate is zero then we are a pseudo-instruction for
15454 VMOVN.I<size> <Dd>, <Qm> */
15455 if (imm == 0)
15456 {
15457 inst.operands[2].present = 0;
15458 inst.instruction = N_MNEM_vmovn;
15459 do_neon_movn ();
15460 return;
15461 }
5f4273c7 15462
5287ad62 15463 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15464 _("immediate out of range for narrowing operation"));
5287ad62
JB
15465 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15466}
15467
15468static void
15469do_neon_shll (void)
15470{
15471 /* FIXME: Type checking when lengthening. */
15472 struct neon_type_el et = neon_check_type (2, NS_QDI,
15473 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15474 unsigned imm = inst.operands[2].imm;
15475
15476 if (imm == et.size)
15477 {
15478 /* Maximum shift variant. */
88714cb8 15479 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15480 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15481 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15482 inst.instruction |= LOW4 (inst.operands[1].reg);
15483 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15484 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15485
88714cb8 15486 neon_dp_fixup (&inst);
5287ad62
JB
15487 }
15488 else
15489 {
15490 /* A more-specific type check for non-max versions. */
15491 et = neon_check_type (2, NS_QDI,
477330fc 15492 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15493 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15494 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15495 }
15496}
15497
037e8744 15498/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15499 the current instruction is. */
15500
6b9a8b67
MGD
15501#define CVT_FLAVOUR_VAR \
15502 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15503 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15504 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15505 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15506 /* Half-precision conversions. */ \
cc933301
JW
15507 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15508 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15509 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15510 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15511 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15512 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15513 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15514 Compared with single/double precision variants, only the co-processor \
15515 field is different, so the encoding flow is reused here. */ \
15516 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15517 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15518 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15519 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15520 /* VFP instructions. */ \
15521 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15522 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15523 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15524 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15525 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15526 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15527 /* VFP instructions with bitshift. */ \
15528 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15529 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15530 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15531 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15532 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15533 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15534 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15535 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15536
15537#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15538 neon_cvt_flavour_##C,
15539
15540/* The different types of conversions we can do. */
15541enum neon_cvt_flavour
15542{
15543 CVT_FLAVOUR_VAR
15544 neon_cvt_flavour_invalid,
15545 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15546};
15547
15548#undef CVT_VAR
15549
15550static enum neon_cvt_flavour
15551get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15552{
6b9a8b67
MGD
15553#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15554 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15555 if (et.type != NT_invtype) \
15556 { \
15557 inst.error = NULL; \
15558 return (neon_cvt_flavour_##C); \
5287ad62 15559 }
6b9a8b67 15560
5287ad62 15561 struct neon_type_el et;
037e8744 15562 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15563 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15564 /* The instruction versions which take an immediate take one register
15565 argument, which is extended to the width of the full register. Thus the
15566 "source" and "destination" registers must have the same width. Hack that
15567 here by making the size equal to the key (wider, in this case) operand. */
15568 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15569
6b9a8b67
MGD
15570 CVT_FLAVOUR_VAR;
15571
15572 return neon_cvt_flavour_invalid;
5287ad62
JB
15573#undef CVT_VAR
15574}
15575
7e8e6784
MGD
15576enum neon_cvt_mode
15577{
15578 neon_cvt_mode_a,
15579 neon_cvt_mode_n,
15580 neon_cvt_mode_p,
15581 neon_cvt_mode_m,
15582 neon_cvt_mode_z,
30bdf752
MGD
15583 neon_cvt_mode_x,
15584 neon_cvt_mode_r
7e8e6784
MGD
15585};
15586
037e8744
JB
15587/* Neon-syntax VFP conversions. */
15588
5287ad62 15589static void
6b9a8b67 15590do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15591{
037e8744 15592 const char *opname = 0;
5f4273c7 15593
d54af2d0
RL
15594 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15595 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15596 {
037e8744
JB
15597 /* Conversions with immediate bitshift. */
15598 const char *enc[] =
477330fc 15599 {
6b9a8b67
MGD
15600#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15601 CVT_FLAVOUR_VAR
15602 NULL
15603#undef CVT_VAR
477330fc 15604 };
037e8744 15605
6b9a8b67 15606 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15607 {
15608 opname = enc[flavour];
15609 constraint (inst.operands[0].reg != inst.operands[1].reg,
15610 _("operands 0 and 1 must be the same register"));
15611 inst.operands[1] = inst.operands[2];
15612 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15613 }
5287ad62
JB
15614 }
15615 else
15616 {
037e8744
JB
15617 /* Conversions without bitshift. */
15618 const char *enc[] =
477330fc 15619 {
6b9a8b67
MGD
15620#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15621 CVT_FLAVOUR_VAR
15622 NULL
15623#undef CVT_VAR
477330fc 15624 };
037e8744 15625
6b9a8b67 15626 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15627 opname = enc[flavour];
037e8744
JB
15628 }
15629
15630 if (opname)
15631 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15632
15633 /* ARMv8.2 fp16 VCVT instruction. */
15634 if (flavour == neon_cvt_flavour_s32_f16
15635 || flavour == neon_cvt_flavour_u32_f16
15636 || flavour == neon_cvt_flavour_f16_u32
15637 || flavour == neon_cvt_flavour_f16_s32)
15638 do_scalar_fp16_v82_encode ();
037e8744
JB
15639}
15640
15641static void
15642do_vfp_nsyn_cvtz (void)
15643{
d54af2d0 15644 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15645 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15646 const char *enc[] =
15647 {
6b9a8b67
MGD
15648#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15649 CVT_FLAVOUR_VAR
15650 NULL
15651#undef CVT_VAR
037e8744
JB
15652 };
15653
6b9a8b67 15654 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15655 do_vfp_nsyn_opcode (enc[flavour]);
15656}
f31fef98 15657
037e8744 15658static void
bacebabc 15659do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15660 enum neon_cvt_mode mode)
15661{
15662 int sz, op;
15663 int rm;
15664
a715796b
TG
15665 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15666 D register operands. */
15667 if (flavour == neon_cvt_flavour_s32_f64
15668 || flavour == neon_cvt_flavour_u32_f64)
15669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15670 _(BAD_FPU));
15671
9db2f6b4
RL
15672 if (flavour == neon_cvt_flavour_s32_f16
15673 || flavour == neon_cvt_flavour_u32_f16)
15674 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15675 _(BAD_FP16));
15676
7e8e6784
MGD
15677 set_it_insn_type (OUTSIDE_IT_INSN);
15678
15679 switch (flavour)
15680 {
15681 case neon_cvt_flavour_s32_f64:
15682 sz = 1;
827f64ff 15683 op = 1;
7e8e6784
MGD
15684 break;
15685 case neon_cvt_flavour_s32_f32:
15686 sz = 0;
15687 op = 1;
15688 break;
9db2f6b4
RL
15689 case neon_cvt_flavour_s32_f16:
15690 sz = 0;
15691 op = 1;
15692 break;
7e8e6784
MGD
15693 case neon_cvt_flavour_u32_f64:
15694 sz = 1;
15695 op = 0;
15696 break;
15697 case neon_cvt_flavour_u32_f32:
15698 sz = 0;
15699 op = 0;
15700 break;
9db2f6b4
RL
15701 case neon_cvt_flavour_u32_f16:
15702 sz = 0;
15703 op = 0;
15704 break;
7e8e6784
MGD
15705 default:
15706 first_error (_("invalid instruction shape"));
15707 return;
15708 }
15709
15710 switch (mode)
15711 {
15712 case neon_cvt_mode_a: rm = 0; break;
15713 case neon_cvt_mode_n: rm = 1; break;
15714 case neon_cvt_mode_p: rm = 2; break;
15715 case neon_cvt_mode_m: rm = 3; break;
15716 default: first_error (_("invalid rounding mode")); return;
15717 }
15718
15719 NEON_ENCODE (FPV8, inst);
15720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15721 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15722 inst.instruction |= sz << 8;
9db2f6b4
RL
15723
15724 /* ARMv8.2 fp16 VCVT instruction. */
15725 if (flavour == neon_cvt_flavour_s32_f16
15726 ||flavour == neon_cvt_flavour_u32_f16)
15727 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15728 inst.instruction |= op << 7;
15729 inst.instruction |= rm << 16;
15730 inst.instruction |= 0xf0000000;
15731 inst.is_neon = TRUE;
15732}
15733
15734static void
15735do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15736{
15737 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15738 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15739 NS_FH, NS_HF, NS_FHI, NS_HFI,
15740 NS_NULL);
6b9a8b67 15741 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15742
cc933301
JW
15743 if (flavour == neon_cvt_flavour_invalid)
15744 return;
15745
e3e535bc 15746 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15747 if (mode == neon_cvt_mode_z
e3e535bc 15748 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15749 && (flavour == neon_cvt_flavour_s16_f16
15750 || flavour == neon_cvt_flavour_u16_f16
15751 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15752 || flavour == neon_cvt_flavour_u32_f32
15753 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15754 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15755 && (rs == NS_FD || rs == NS_FF))
15756 {
15757 do_vfp_nsyn_cvtz ();
15758 return;
15759 }
15760
9db2f6b4
RL
15761 /* ARMv8.2 fp16 VCVT conversions. */
15762 if (mode == neon_cvt_mode_z
15763 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15764 && (flavour == neon_cvt_flavour_s32_f16
15765 || flavour == neon_cvt_flavour_u32_f16)
15766 && (rs == NS_FH))
15767 {
15768 do_vfp_nsyn_cvtz ();
15769 do_scalar_fp16_v82_encode ();
15770 return;
15771 }
15772
037e8744 15773 /* VFP rather than Neon conversions. */
6b9a8b67 15774 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15775 {
7e8e6784
MGD
15776 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15777 do_vfp_nsyn_cvt (rs, flavour);
15778 else
15779 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15780
037e8744
JB
15781 return;
15782 }
15783
15784 switch (rs)
15785 {
15786 case NS_DDI:
15787 case NS_QQI:
15788 {
477330fc 15789 unsigned immbits;
cc933301
JW
15790 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15791 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15792
477330fc
RM
15793 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15794 return;
037e8744 15795
477330fc
RM
15796 /* Fixed-point conversion with #0 immediate is encoded as an
15797 integer conversion. */
15798 if (inst.operands[2].present && inst.operands[2].imm == 0)
15799 goto int_encode;
477330fc
RM
15800 NEON_ENCODE (IMMED, inst);
15801 if (flavour != neon_cvt_flavour_invalid)
15802 inst.instruction |= enctab[flavour];
15803 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15804 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15805 inst.instruction |= LOW4 (inst.operands[1].reg);
15806 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15807 inst.instruction |= neon_quad (rs) << 6;
15808 inst.instruction |= 1 << 21;
cc933301
JW
15809 if (flavour < neon_cvt_flavour_s16_f16)
15810 {
15811 inst.instruction |= 1 << 21;
15812 immbits = 32 - inst.operands[2].imm;
15813 inst.instruction |= immbits << 16;
15814 }
15815 else
15816 {
15817 inst.instruction |= 3 << 20;
15818 immbits = 16 - inst.operands[2].imm;
15819 inst.instruction |= immbits << 16;
15820 inst.instruction &= ~(1 << 9);
15821 }
477330fc
RM
15822
15823 neon_dp_fixup (&inst);
037e8744
JB
15824 }
15825 break;
15826
15827 case NS_DD:
15828 case NS_QQ:
7e8e6784
MGD
15829 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15830 {
15831 NEON_ENCODE (FLOAT, inst);
15832 set_it_insn_type (OUTSIDE_IT_INSN);
15833
15834 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15835 return;
15836
15837 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15838 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15839 inst.instruction |= LOW4 (inst.operands[1].reg);
15840 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15841 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15842 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15843 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15844 inst.instruction |= mode << 8;
cc933301
JW
15845 if (flavour == neon_cvt_flavour_u16_f16
15846 || flavour == neon_cvt_flavour_s16_f16)
15847 /* Mask off the original size bits and reencode them. */
15848 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15849
7e8e6784
MGD
15850 if (thumb_mode)
15851 inst.instruction |= 0xfc000000;
15852 else
15853 inst.instruction |= 0xf0000000;
15854 }
15855 else
15856 {
037e8744 15857 int_encode:
7e8e6784 15858 {
cc933301
JW
15859 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15860 0x100, 0x180, 0x0, 0x080};
037e8744 15861
7e8e6784 15862 NEON_ENCODE (INTEGER, inst);
037e8744 15863
7e8e6784
MGD
15864 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15865 return;
037e8744 15866
7e8e6784
MGD
15867 if (flavour != neon_cvt_flavour_invalid)
15868 inst.instruction |= enctab[flavour];
037e8744 15869
7e8e6784
MGD
15870 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15871 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15872 inst.instruction |= LOW4 (inst.operands[1].reg);
15873 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15874 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15875 if (flavour >= neon_cvt_flavour_s16_f16
15876 && flavour <= neon_cvt_flavour_f16_u16)
15877 /* Half precision. */
15878 inst.instruction |= 1 << 18;
15879 else
15880 inst.instruction |= 2 << 18;
037e8744 15881
7e8e6784
MGD
15882 neon_dp_fixup (&inst);
15883 }
15884 }
15885 break;
037e8744 15886
8e79c3df
CM
15887 /* Half-precision conversions for Advanced SIMD -- neon. */
15888 case NS_QD:
15889 case NS_DQ:
15890
15891 if ((rs == NS_DQ)
15892 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15893 {
15894 as_bad (_("operand size must match register width"));
15895 break;
15896 }
15897
15898 if ((rs == NS_QD)
15899 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15900 {
15901 as_bad (_("operand size must match register width"));
15902 break;
15903 }
15904
15905 if (rs == NS_DQ)
477330fc 15906 inst.instruction = 0x3b60600;
8e79c3df
CM
15907 else
15908 inst.instruction = 0x3b60700;
15909
15910 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15911 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15912 inst.instruction |= LOW4 (inst.operands[1].reg);
15913 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15914 neon_dp_fixup (&inst);
8e79c3df
CM
15915 break;
15916
037e8744
JB
15917 default:
15918 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15919 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15920 do_vfp_nsyn_cvt (rs, flavour);
15921 else
15922 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15923 }
5287ad62
JB
15924}
15925
e3e535bc
NC
15926static void
15927do_neon_cvtr (void)
15928{
7e8e6784 15929 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15930}
15931
15932static void
15933do_neon_cvt (void)
15934{
7e8e6784
MGD
15935 do_neon_cvt_1 (neon_cvt_mode_z);
15936}
15937
15938static void
15939do_neon_cvta (void)
15940{
15941 do_neon_cvt_1 (neon_cvt_mode_a);
15942}
15943
15944static void
15945do_neon_cvtn (void)
15946{
15947 do_neon_cvt_1 (neon_cvt_mode_n);
15948}
15949
15950static void
15951do_neon_cvtp (void)
15952{
15953 do_neon_cvt_1 (neon_cvt_mode_p);
15954}
15955
15956static void
15957do_neon_cvtm (void)
15958{
15959 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15960}
15961
8e79c3df 15962static void
c70a8987 15963do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15964{
c70a8987
MGD
15965 if (is_double)
15966 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15967
c70a8987
MGD
15968 encode_arm_vfp_reg (inst.operands[0].reg,
15969 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15970 encode_arm_vfp_reg (inst.operands[1].reg,
15971 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15972 inst.instruction |= to ? 0x10000 : 0;
15973 inst.instruction |= t ? 0x80 : 0;
15974 inst.instruction |= is_double ? 0x100 : 0;
15975 do_vfp_cond_or_thumb ();
15976}
8e79c3df 15977
c70a8987
MGD
15978static void
15979do_neon_cvttb_1 (bfd_boolean t)
15980{
d54af2d0
RL
15981 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15982 NS_DF, NS_DH, NS_NULL);
8e79c3df 15983
c70a8987
MGD
15984 if (rs == NS_NULL)
15985 return;
15986 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15987 {
15988 inst.error = NULL;
15989 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15990 }
15991 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15992 {
15993 inst.error = NULL;
15994 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15995 }
15996 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15997 {
a715796b
TG
15998 /* The VCVTB and VCVTT instructions with D-register operands
15999 don't work for SP only targets. */
16000 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16001 _(BAD_FPU));
16002
c70a8987
MGD
16003 inst.error = NULL;
16004 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16005 }
16006 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16007 {
a715796b
TG
16008 /* The VCVTB and VCVTT instructions with D-register operands
16009 don't work for SP only targets. */
16010 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16011 _(BAD_FPU));
16012
c70a8987
MGD
16013 inst.error = NULL;
16014 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16015 }
16016 else
16017 return;
16018}
16019
16020static void
16021do_neon_cvtb (void)
16022{
16023 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16024}
16025
16026
16027static void
16028do_neon_cvtt (void)
16029{
c70a8987 16030 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16031}
16032
5287ad62
JB
16033static void
16034neon_move_immediate (void)
16035{
037e8744
JB
16036 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16037 struct neon_type_el et = neon_check_type (2, rs,
16038 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16039 unsigned immlo, immhi = 0, immbits;
c96612cc 16040 int op, cmode, float_p;
5287ad62 16041
037e8744 16042 constraint (et.type == NT_invtype,
477330fc 16043 _("operand size must be specified for immediate VMOV"));
037e8744 16044
5287ad62
JB
16045 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16046 op = (inst.instruction & (1 << 5)) != 0;
16047
16048 immlo = inst.operands[1].imm;
16049 if (inst.operands[1].regisimm)
16050 immhi = inst.operands[1].reg;
16051
16052 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16053 _("immediate has bits set outside the operand size"));
5287ad62 16054
c96612cc
JB
16055 float_p = inst.operands[1].immisfloat;
16056
16057 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16058 et.size, et.type)) == FAIL)
5287ad62
JB
16059 {
16060 /* Invert relevant bits only. */
16061 neon_invert_size (&immlo, &immhi, et.size);
16062 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16063 with one or the other; those cases are caught by
16064 neon_cmode_for_move_imm. */
5287ad62 16065 op = !op;
c96612cc
JB
16066 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16067 &op, et.size, et.type)) == FAIL)
477330fc
RM
16068 {
16069 first_error (_("immediate out of range"));
16070 return;
16071 }
5287ad62
JB
16072 }
16073
16074 inst.instruction &= ~(1 << 5);
16075 inst.instruction |= op << 5;
16076
16077 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16078 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16079 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16080 inst.instruction |= cmode << 8;
16081
16082 neon_write_immbits (immbits);
16083}
16084
16085static void
16086do_neon_mvn (void)
16087{
16088 if (inst.operands[1].isreg)
16089 {
037e8744 16090 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16091
88714cb8 16092 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16093 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16094 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16095 inst.instruction |= LOW4 (inst.operands[1].reg);
16096 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16097 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16098 }
16099 else
16100 {
88714cb8 16101 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16102 neon_move_immediate ();
16103 }
16104
88714cb8 16105 neon_dp_fixup (&inst);
5287ad62
JB
16106}
16107
16108/* Encode instructions of form:
16109
16110 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16111 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16112
16113static void
16114neon_mixed_length (struct neon_type_el et, unsigned size)
16115{
16116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16118 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16119 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16120 inst.instruction |= LOW4 (inst.operands[2].reg);
16121 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16122 inst.instruction |= (et.type == NT_unsigned) << 24;
16123 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16124
88714cb8 16125 neon_dp_fixup (&inst);
5287ad62
JB
16126}
16127
16128static void
16129do_neon_dyadic_long (void)
16130{
16131 /* FIXME: Type checking for lengthening op. */
16132 struct neon_type_el et = neon_check_type (3, NS_QDD,
16133 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16134 neon_mixed_length (et, et.size);
16135}
16136
16137static void
16138do_neon_abal (void)
16139{
16140 struct neon_type_el et = neon_check_type (3, NS_QDD,
16141 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16142 neon_mixed_length (et, et.size);
16143}
16144
16145static void
16146neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16147{
16148 if (inst.operands[2].isscalar)
16149 {
dcbf9037 16150 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16151 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16152 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16153 neon_mul_mac (et, et.type == NT_unsigned);
16154 }
16155 else
16156 {
16157 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16158 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16159 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16160 neon_mixed_length (et, et.size);
16161 }
16162}
16163
16164static void
16165do_neon_mac_maybe_scalar_long (void)
16166{
16167 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16168}
16169
dec41383
JW
16170/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16171 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16172
16173static unsigned
16174neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16175{
16176 unsigned regno = NEON_SCALAR_REG (scalar);
16177 unsigned elno = NEON_SCALAR_INDEX (scalar);
16178
16179 if (quad_p)
16180 {
16181 if (regno > 7 || elno > 3)
16182 goto bad_scalar;
16183
16184 return ((regno & 0x7)
16185 | ((elno & 0x1) << 3)
16186 | (((elno >> 1) & 0x1) << 5));
16187 }
16188 else
16189 {
16190 if (regno > 15 || elno > 1)
16191 goto bad_scalar;
16192
16193 return (((regno & 0x1) << 5)
16194 | ((regno >> 1) & 0x7)
16195 | ((elno & 0x1) << 3));
16196 }
16197
16198bad_scalar:
16199 first_error (_("scalar out of range for multiply instruction"));
16200 return 0;
16201}
16202
16203static void
16204do_neon_fmac_maybe_scalar_long (int subtype)
16205{
16206 enum neon_shape rs;
16207 int high8;
16208 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16209 field (bits[21:20]) has different meaning. For scalar index variant, it's
16210 used to differentiate add and subtract, otherwise it's with fixed value
16211 0x2. */
16212 int size = -1;
16213
16214 if (inst.cond != COND_ALWAYS)
16215 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16216 "behaviour is UNPREDICTABLE"));
16217
01f48020 16218 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16219 _(BAD_FP16));
16220
16221 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16222 _(BAD_FPU));
16223
16224 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16225 be a scalar index register. */
16226 if (inst.operands[2].isscalar)
16227 {
16228 high8 = 0xfe000000;
16229 if (subtype)
16230 size = 16;
16231 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16232 }
16233 else
16234 {
16235 high8 = 0xfc000000;
16236 size = 32;
16237 if (subtype)
16238 inst.instruction |= (0x1 << 23);
16239 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16240 }
16241
16242 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16243
16244 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16245 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16246 so we simply pass -1 as size. */
16247 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16248 neon_three_same (quad_p, 0, size);
16249
16250 /* Undo neon_dp_fixup. Redo the high eight bits. */
16251 inst.instruction &= 0x00ffffff;
16252 inst.instruction |= high8;
16253
16254#define LOW1(R) ((R) & 0x1)
16255#define HI4(R) (((R) >> 1) & 0xf)
16256 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16257 whether the instruction is in Q form and whether Vm is a scalar indexed
16258 operand. */
16259 if (inst.operands[2].isscalar)
16260 {
16261 unsigned rm
16262 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16263 inst.instruction &= 0xffffffd0;
16264 inst.instruction |= rm;
16265
16266 if (!quad_p)
16267 {
16268 /* Redo Rn as well. */
16269 inst.instruction &= 0xfff0ff7f;
16270 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16271 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16272 }
16273 }
16274 else if (!quad_p)
16275 {
16276 /* Redo Rn and Rm. */
16277 inst.instruction &= 0xfff0ff50;
16278 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16279 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16280 inst.instruction |= HI4 (inst.operands[2].reg);
16281 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16282 }
16283}
16284
16285static void
16286do_neon_vfmal (void)
16287{
16288 return do_neon_fmac_maybe_scalar_long (0);
16289}
16290
16291static void
16292do_neon_vfmsl (void)
16293{
16294 return do_neon_fmac_maybe_scalar_long (1);
16295}
16296
5287ad62
JB
16297static void
16298do_neon_dyadic_wide (void)
16299{
16300 struct neon_type_el et = neon_check_type (3, NS_QQD,
16301 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16302 neon_mixed_length (et, et.size);
16303}
16304
16305static void
16306do_neon_dyadic_narrow (void)
16307{
16308 struct neon_type_el et = neon_check_type (3, NS_QDD,
16309 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16310 /* Operand sign is unimportant, and the U bit is part of the opcode,
16311 so force the operand type to integer. */
16312 et.type = NT_integer;
5287ad62
JB
16313 neon_mixed_length (et, et.size / 2);
16314}
16315
16316static void
16317do_neon_mul_sat_scalar_long (void)
16318{
16319 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16320}
16321
16322static void
16323do_neon_vmull (void)
16324{
16325 if (inst.operands[2].isscalar)
16326 do_neon_mac_maybe_scalar_long ();
16327 else
16328 {
16329 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16330 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16331
5287ad62 16332 if (et.type == NT_poly)
477330fc 16333 NEON_ENCODE (POLY, inst);
5287ad62 16334 else
477330fc 16335 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16336
16337 /* For polynomial encoding the U bit must be zero, and the size must
16338 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16339 obviously, as 0b10). */
16340 if (et.size == 64)
16341 {
16342 /* Check we're on the correct architecture. */
16343 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16344 inst.error =
16345 _("Instruction form not available on this architecture.");
16346
16347 et.size = 32;
16348 }
16349
5287ad62
JB
16350 neon_mixed_length (et, et.size);
16351 }
16352}
16353
16354static void
16355do_neon_ext (void)
16356{
037e8744 16357 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16358 struct neon_type_el et = neon_check_type (3, rs,
16359 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16360 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16361
16362 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16363 _("shift out of range"));
5287ad62
JB
16364 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16365 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16366 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16367 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16368 inst.instruction |= LOW4 (inst.operands[2].reg);
16369 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16370 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16371 inst.instruction |= imm << 8;
5f4273c7 16372
88714cb8 16373 neon_dp_fixup (&inst);
5287ad62
JB
16374}
16375
16376static void
16377do_neon_rev (void)
16378{
037e8744 16379 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16380 struct neon_type_el et = neon_check_type (2, rs,
16381 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16382 unsigned op = (inst.instruction >> 7) & 3;
16383 /* N (width of reversed regions) is encoded as part of the bitmask. We
16384 extract it here to check the elements to be reversed are smaller.
16385 Otherwise we'd get a reserved instruction. */
16386 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16387 gas_assert (elsize != 0);
5287ad62 16388 constraint (et.size >= elsize,
477330fc 16389 _("elements must be smaller than reversal region"));
037e8744 16390 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16391}
16392
16393static void
16394do_neon_dup (void)
16395{
16396 if (inst.operands[1].isscalar)
16397 {
037e8744 16398 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16399 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16400 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16401 unsigned sizebits = et.size >> 3;
dcbf9037 16402 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16403 int logsize = neon_logbits (et.size);
dcbf9037 16404 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16405
16406 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16407 return;
037e8744 16408
88714cb8 16409 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16410 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16411 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16412 inst.instruction |= LOW4 (dm);
16413 inst.instruction |= HI1 (dm) << 5;
037e8744 16414 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16415 inst.instruction |= x << 17;
16416 inst.instruction |= sizebits << 16;
5f4273c7 16417
88714cb8 16418 neon_dp_fixup (&inst);
5287ad62
JB
16419 }
16420 else
16421 {
037e8744
JB
16422 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16423 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16424 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16425 /* Duplicate ARM register to lanes of vector. */
88714cb8 16426 NEON_ENCODE (ARMREG, inst);
5287ad62 16427 switch (et.size)
477330fc
RM
16428 {
16429 case 8: inst.instruction |= 0x400000; break;
16430 case 16: inst.instruction |= 0x000020; break;
16431 case 32: inst.instruction |= 0x000000; break;
16432 default: break;
16433 }
5287ad62
JB
16434 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16435 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16436 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16437 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16438 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16439 variants, except for the condition field. */
037e8744 16440 do_vfp_cond_or_thumb ();
5287ad62
JB
16441 }
16442}
16443
16444/* VMOV has particularly many variations. It can be one of:
16445 0. VMOV<c><q> <Qd>, <Qm>
16446 1. VMOV<c><q> <Dd>, <Dm>
16447 (Register operations, which are VORR with Rm = Rn.)
16448 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16449 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16450 (Immediate loads.)
16451 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16452 (ARM register to scalar.)
16453 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16454 (Two ARM registers to vector.)
16455 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16456 (Scalar to ARM register.)
16457 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16458 (Vector to two ARM registers.)
037e8744
JB
16459 8. VMOV.F32 <Sd>, <Sm>
16460 9. VMOV.F64 <Dd>, <Dm>
16461 (VFP register moves.)
16462 10. VMOV.F32 <Sd>, #imm
16463 11. VMOV.F64 <Dd>, #imm
16464 (VFP float immediate load.)
16465 12. VMOV <Rd>, <Sm>
16466 (VFP single to ARM reg.)
16467 13. VMOV <Sd>, <Rm>
16468 (ARM reg to VFP single.)
16469 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16470 (Two ARM regs to two VFP singles.)
16471 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16472 (Two VFP singles to two ARM regs.)
5f4273c7 16473
037e8744
JB
16474 These cases can be disambiguated using neon_select_shape, except cases 1/9
16475 and 3/11 which depend on the operand type too.
5f4273c7 16476
5287ad62 16477 All the encoded bits are hardcoded by this function.
5f4273c7 16478
b7fc2769
JB
16479 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16480 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16481
5287ad62 16482 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16483 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16484
16485static void
16486do_neon_mov (void)
16487{
037e8744 16488 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16489 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16490 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16491 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16492 struct neon_type_el et;
16493 const char *ldconst = 0;
5287ad62 16494
037e8744 16495 switch (rs)
5287ad62 16496 {
037e8744
JB
16497 case NS_DD: /* case 1/9. */
16498 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16499 /* It is not an error here if no type is given. */
16500 inst.error = NULL;
16501 if (et.type == NT_float && et.size == 64)
477330fc
RM
16502 {
16503 do_vfp_nsyn_opcode ("fcpyd");
16504 break;
16505 }
037e8744 16506 /* fall through. */
5287ad62 16507
037e8744
JB
16508 case NS_QQ: /* case 0/1. */
16509 {
477330fc
RM
16510 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16511 return;
16512 /* The architecture manual I have doesn't explicitly state which
16513 value the U bit should have for register->register moves, but
16514 the equivalent VORR instruction has U = 0, so do that. */
16515 inst.instruction = 0x0200110;
16516 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16517 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16518 inst.instruction |= LOW4 (inst.operands[1].reg);
16519 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16520 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16521 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16522 inst.instruction |= neon_quad (rs) << 6;
16523
16524 neon_dp_fixup (&inst);
037e8744
JB
16525 }
16526 break;
5f4273c7 16527
037e8744
JB
16528 case NS_DI: /* case 3/11. */
16529 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16530 inst.error = NULL;
16531 if (et.type == NT_float && et.size == 64)
477330fc
RM
16532 {
16533 /* case 11 (fconstd). */
16534 ldconst = "fconstd";
16535 goto encode_fconstd;
16536 }
037e8744
JB
16537 /* fall through. */
16538
16539 case NS_QI: /* case 2/3. */
16540 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16541 return;
037e8744
JB
16542 inst.instruction = 0x0800010;
16543 neon_move_immediate ();
88714cb8 16544 neon_dp_fixup (&inst);
5287ad62 16545 break;
5f4273c7 16546
037e8744
JB
16547 case NS_SR: /* case 4. */
16548 {
477330fc
RM
16549 unsigned bcdebits = 0;
16550 int logsize;
16551 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16552 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16553
05ac0ffb
JB
16554 /* .<size> is optional here, defaulting to .32. */
16555 if (inst.vectype.elems == 0
16556 && inst.operands[0].vectype.type == NT_invtype
16557 && inst.operands[1].vectype.type == NT_invtype)
16558 {
16559 inst.vectype.el[0].type = NT_untyped;
16560 inst.vectype.el[0].size = 32;
16561 inst.vectype.elems = 1;
16562 }
16563
477330fc
RM
16564 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16565 logsize = neon_logbits (et.size);
16566
16567 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16568 _(BAD_FPU));
16569 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16570 && et.size != 32, _(BAD_FPU));
16571 constraint (et.type == NT_invtype, _("bad type for scalar"));
16572 constraint (x >= 64 / et.size, _("scalar index out of range"));
16573
16574 switch (et.size)
16575 {
16576 case 8: bcdebits = 0x8; break;
16577 case 16: bcdebits = 0x1; break;
16578 case 32: bcdebits = 0x0; break;
16579 default: ;
16580 }
16581
16582 bcdebits |= x << logsize;
16583
16584 inst.instruction = 0xe000b10;
16585 do_vfp_cond_or_thumb ();
16586 inst.instruction |= LOW4 (dn) << 16;
16587 inst.instruction |= HI1 (dn) << 7;
16588 inst.instruction |= inst.operands[1].reg << 12;
16589 inst.instruction |= (bcdebits & 3) << 5;
16590 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16591 }
16592 break;
5f4273c7 16593
037e8744 16594 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16595 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16596 _(BAD_FPU));
b7fc2769 16597
037e8744
JB
16598 inst.instruction = 0xc400b10;
16599 do_vfp_cond_or_thumb ();
16600 inst.instruction |= LOW4 (inst.operands[0].reg);
16601 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16602 inst.instruction |= inst.operands[1].reg << 12;
16603 inst.instruction |= inst.operands[2].reg << 16;
16604 break;
5f4273c7 16605
037e8744
JB
16606 case NS_RS: /* case 6. */
16607 {
477330fc
RM
16608 unsigned logsize;
16609 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16610 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16611 unsigned abcdebits = 0;
037e8744 16612
05ac0ffb
JB
16613 /* .<dt> is optional here, defaulting to .32. */
16614 if (inst.vectype.elems == 0
16615 && inst.operands[0].vectype.type == NT_invtype
16616 && inst.operands[1].vectype.type == NT_invtype)
16617 {
16618 inst.vectype.el[0].type = NT_untyped;
16619 inst.vectype.el[0].size = 32;
16620 inst.vectype.elems = 1;
16621 }
16622
91d6fa6a
NC
16623 et = neon_check_type (2, NS_NULL,
16624 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16625 logsize = neon_logbits (et.size);
16626
16627 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16628 _(BAD_FPU));
16629 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16630 && et.size != 32, _(BAD_FPU));
16631 constraint (et.type == NT_invtype, _("bad type for scalar"));
16632 constraint (x >= 64 / et.size, _("scalar index out of range"));
16633
16634 switch (et.size)
16635 {
16636 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16637 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16638 case 32: abcdebits = 0x00; break;
16639 default: ;
16640 }
16641
16642 abcdebits |= x << logsize;
16643 inst.instruction = 0xe100b10;
16644 do_vfp_cond_or_thumb ();
16645 inst.instruction |= LOW4 (dn) << 16;
16646 inst.instruction |= HI1 (dn) << 7;
16647 inst.instruction |= inst.operands[0].reg << 12;
16648 inst.instruction |= (abcdebits & 3) << 5;
16649 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16650 }
16651 break;
5f4273c7 16652
037e8744
JB
16653 case NS_RRD: /* case 7 (fmrrd). */
16654 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16655 _(BAD_FPU));
037e8744
JB
16656
16657 inst.instruction = 0xc500b10;
16658 do_vfp_cond_or_thumb ();
16659 inst.instruction |= inst.operands[0].reg << 12;
16660 inst.instruction |= inst.operands[1].reg << 16;
16661 inst.instruction |= LOW4 (inst.operands[2].reg);
16662 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16663 break;
5f4273c7 16664
037e8744
JB
16665 case NS_FF: /* case 8 (fcpys). */
16666 do_vfp_nsyn_opcode ("fcpys");
16667 break;
5f4273c7 16668
9db2f6b4 16669 case NS_HI:
037e8744
JB
16670 case NS_FI: /* case 10 (fconsts). */
16671 ldconst = "fconsts";
16672 encode_fconstd:
16673 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16674 {
16675 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16676 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16677
16678 /* ARMv8.2 fp16 vmov.f16 instruction. */
16679 if (rs == NS_HI)
16680 do_scalar_fp16_v82_encode ();
477330fc 16681 }
5287ad62 16682 else
477330fc 16683 first_error (_("immediate out of range"));
037e8744 16684 break;
5f4273c7 16685
9db2f6b4 16686 case NS_RH:
037e8744
JB
16687 case NS_RF: /* case 12 (fmrs). */
16688 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16689 /* ARMv8.2 fp16 vmov.f16 instruction. */
16690 if (rs == NS_RH)
16691 do_scalar_fp16_v82_encode ();
037e8744 16692 break;
5f4273c7 16693
9db2f6b4 16694 case NS_HR:
037e8744
JB
16695 case NS_FR: /* case 13 (fmsr). */
16696 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16697 /* ARMv8.2 fp16 vmov.f16 instruction. */
16698 if (rs == NS_HR)
16699 do_scalar_fp16_v82_encode ();
037e8744 16700 break;
5f4273c7 16701
037e8744
JB
16702 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16703 (one of which is a list), but we have parsed four. Do some fiddling to
16704 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16705 expect. */
16706 case NS_RRFF: /* case 14 (fmrrs). */
16707 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16708 _("VFP registers must be adjacent"));
037e8744
JB
16709 inst.operands[2].imm = 2;
16710 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16711 do_vfp_nsyn_opcode ("fmrrs");
16712 break;
5f4273c7 16713
037e8744
JB
16714 case NS_FFRR: /* case 15 (fmsrr). */
16715 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16716 _("VFP registers must be adjacent"));
037e8744
JB
16717 inst.operands[1] = inst.operands[2];
16718 inst.operands[2] = inst.operands[3];
16719 inst.operands[0].imm = 2;
16720 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16721 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16722 break;
5f4273c7 16723
4c261dff
NC
16724 case NS_NULL:
16725 /* neon_select_shape has determined that the instruction
16726 shape is wrong and has already set the error message. */
16727 break;
16728
5287ad62
JB
16729 default:
16730 abort ();
16731 }
16732}
16733
16734static void
16735do_neon_rshift_round_imm (void)
16736{
037e8744 16737 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16738 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16739 int imm = inst.operands[2].imm;
16740
16741 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16742 if (imm == 0)
16743 {
16744 inst.operands[2].present = 0;
16745 do_neon_mov ();
16746 return;
16747 }
16748
16749 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16750 _("immediate out of range for shift"));
037e8744 16751 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16752 et.size - imm);
5287ad62
JB
16753}
16754
9db2f6b4
RL
16755static void
16756do_neon_movhf (void)
16757{
16758 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16759 constraint (rs != NS_HH, _("invalid suffix"));
16760
16761 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16762 _(BAD_FPU));
16763
16764 do_vfp_sp_monadic ();
16765
16766 inst.is_neon = 1;
16767 inst.instruction |= 0xf0000000;
16768}
16769
5287ad62
JB
16770static void
16771do_neon_movl (void)
16772{
16773 struct neon_type_el et = neon_check_type (2, NS_QD,
16774 N_EQK | N_DBL, N_SU_32 | N_KEY);
16775 unsigned sizebits = et.size >> 3;
16776 inst.instruction |= sizebits << 19;
16777 neon_two_same (0, et.type == NT_unsigned, -1);
16778}
16779
16780static void
16781do_neon_trn (void)
16782{
037e8744 16783 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16784 struct neon_type_el et = neon_check_type (2, rs,
16785 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16786 NEON_ENCODE (INTEGER, inst);
037e8744 16787 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16788}
16789
16790static void
16791do_neon_zip_uzp (void)
16792{
037e8744 16793 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16794 struct neon_type_el et = neon_check_type (2, rs,
16795 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16796 if (rs == NS_DD && et.size == 32)
16797 {
16798 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16799 inst.instruction = N_MNEM_vtrn;
16800 do_neon_trn ();
16801 return;
16802 }
037e8744 16803 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16804}
16805
16806static void
16807do_neon_sat_abs_neg (void)
16808{
037e8744 16809 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16810 struct neon_type_el et = neon_check_type (2, rs,
16811 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16812 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16813}
16814
16815static void
16816do_neon_pair_long (void)
16817{
037e8744 16818 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16819 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16820 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16821 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16822 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16823}
16824
16825static void
16826do_neon_recip_est (void)
16827{
037e8744 16828 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16829 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16830 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16831 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16832 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16833}
16834
16835static void
16836do_neon_cls (void)
16837{
037e8744 16838 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16839 struct neon_type_el et = neon_check_type (2, rs,
16840 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16841 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16842}
16843
16844static void
16845do_neon_clz (void)
16846{
037e8744 16847 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16848 struct neon_type_el et = neon_check_type (2, rs,
16849 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16850 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16851}
16852
16853static void
16854do_neon_cnt (void)
16855{
037e8744 16856 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16857 struct neon_type_el et = neon_check_type (2, rs,
16858 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16859 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16860}
16861
16862static void
16863do_neon_swp (void)
16864{
037e8744
JB
16865 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16866 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16867}
16868
16869static void
16870do_neon_tbl_tbx (void)
16871{
16872 unsigned listlenbits;
dcbf9037 16873 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16874
5287ad62
JB
16875 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16876 {
dcbf9037 16877 first_error (_("bad list length for table lookup"));
5287ad62
JB
16878 return;
16879 }
5f4273c7 16880
5287ad62
JB
16881 listlenbits = inst.operands[1].imm - 1;
16882 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16883 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16884 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16885 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16886 inst.instruction |= LOW4 (inst.operands[2].reg);
16887 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16888 inst.instruction |= listlenbits << 8;
5f4273c7 16889
88714cb8 16890 neon_dp_fixup (&inst);
5287ad62
JB
16891}
16892
16893static void
16894do_neon_ldm_stm (void)
16895{
16896 /* P, U and L bits are part of bitmask. */
16897 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16898 unsigned offsetbits = inst.operands[1].imm * 2;
16899
037e8744
JB
16900 if (inst.operands[1].issingle)
16901 {
16902 do_vfp_nsyn_ldm_stm (is_dbmode);
16903 return;
16904 }
16905
5287ad62 16906 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16907 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16908
16909 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16910 _("register list must contain at least 1 and at most 16 "
16911 "registers"));
5287ad62
JB
16912
16913 inst.instruction |= inst.operands[0].reg << 16;
16914 inst.instruction |= inst.operands[0].writeback << 21;
16915 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16916 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16917
16918 inst.instruction |= offsetbits;
5f4273c7 16919
037e8744 16920 do_vfp_cond_or_thumb ();
5287ad62
JB
16921}
16922
16923static void
16924do_neon_ldr_str (void)
16925{
5287ad62 16926 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16927
6844b2c2
MGD
16928 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16929 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16930 if (!is_ldr
6844b2c2 16931 && inst.operands[1].reg == REG_PC
ba86b375 16932 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16933 {
94dcf8bf 16934 if (thumb_mode)
6844b2c2 16935 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16936 else if (warn_on_deprecated)
5c3696f8 16937 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16938 }
16939
037e8744
JB
16940 if (inst.operands[0].issingle)
16941 {
cd2f129f 16942 if (is_ldr)
477330fc 16943 do_vfp_nsyn_opcode ("flds");
cd2f129f 16944 else
477330fc 16945 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16946
16947 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16948 if (inst.vectype.el[0].size == 16)
16949 do_scalar_fp16_v82_encode ();
5287ad62
JB
16950 }
16951 else
5287ad62 16952 {
cd2f129f 16953 if (is_ldr)
477330fc 16954 do_vfp_nsyn_opcode ("fldd");
5287ad62 16955 else
477330fc 16956 do_vfp_nsyn_opcode ("fstd");
5287ad62 16957 }
5287ad62
JB
16958}
16959
16960/* "interleave" version also handles non-interleaving register VLD1/VST1
16961 instructions. */
16962
16963static void
16964do_neon_ld_st_interleave (void)
16965{
037e8744 16966 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16967 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16968 unsigned alignbits = 0;
16969 unsigned idx;
16970 /* The bits in this table go:
16971 0: register stride of one (0) or two (1)
16972 1,2: register list length, minus one (1, 2, 3, 4).
16973 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16974 We use -1 for invalid entries. */
16975 const int typetable[] =
16976 {
16977 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16978 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16979 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16980 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16981 };
16982 int typebits;
16983
dcbf9037
JB
16984 if (et.type == NT_invtype)
16985 return;
16986
5287ad62
JB
16987 if (inst.operands[1].immisalign)
16988 switch (inst.operands[1].imm >> 8)
16989 {
16990 case 64: alignbits = 1; break;
16991 case 128:
477330fc 16992 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16993 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16994 goto bad_alignment;
16995 alignbits = 2;
16996 break;
5287ad62 16997 case 256:
477330fc
RM
16998 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16999 goto bad_alignment;
17000 alignbits = 3;
17001 break;
5287ad62
JB
17002 default:
17003 bad_alignment:
477330fc
RM
17004 first_error (_("bad alignment"));
17005 return;
5287ad62
JB
17006 }
17007
17008 inst.instruction |= alignbits << 4;
17009 inst.instruction |= neon_logbits (et.size) << 6;
17010
17011 /* Bits [4:6] of the immediate in a list specifier encode register stride
17012 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17013 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17014 up the right value for "type" in a table based on this value and the given
17015 list style, then stick it back. */
17016 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17017 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17018
17019 typebits = typetable[idx];
5f4273c7 17020
5287ad62 17021 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17022 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17023 _("bad element type for instruction"));
5287ad62
JB
17024
17025 inst.instruction &= ~0xf00;
17026 inst.instruction |= typebits << 8;
17027}
17028
17029/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17030 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17031 otherwise. The variable arguments are a list of pairs of legal (size, align)
17032 values, terminated with -1. */
17033
17034static int
aa8a0863 17035neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17036{
17037 va_list ap;
17038 int result = FAIL, thissize, thisalign;
5f4273c7 17039
5287ad62
JB
17040 if (!inst.operands[1].immisalign)
17041 {
aa8a0863 17042 *do_alignment = 0;
5287ad62
JB
17043 return SUCCESS;
17044 }
5f4273c7 17045
aa8a0863 17046 va_start (ap, do_alignment);
5287ad62
JB
17047
17048 do
17049 {
17050 thissize = va_arg (ap, int);
17051 if (thissize == -1)
477330fc 17052 break;
5287ad62
JB
17053 thisalign = va_arg (ap, int);
17054
17055 if (size == thissize && align == thisalign)
477330fc 17056 result = SUCCESS;
5287ad62
JB
17057 }
17058 while (result != SUCCESS);
17059
17060 va_end (ap);
17061
17062 if (result == SUCCESS)
aa8a0863 17063 *do_alignment = 1;
5287ad62 17064 else
dcbf9037 17065 first_error (_("unsupported alignment for instruction"));
5f4273c7 17066
5287ad62
JB
17067 return result;
17068}
17069
17070static void
17071do_neon_ld_st_lane (void)
17072{
037e8744 17073 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17074 int align_good, do_alignment = 0;
5287ad62
JB
17075 int logsize = neon_logbits (et.size);
17076 int align = inst.operands[1].imm >> 8;
17077 int n = (inst.instruction >> 8) & 3;
17078 int max_el = 64 / et.size;
5f4273c7 17079
dcbf9037
JB
17080 if (et.type == NT_invtype)
17081 return;
5f4273c7 17082
5287ad62 17083 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17084 _("bad list length"));
5287ad62 17085 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17086 _("scalar index out of range"));
5287ad62 17087 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17088 && et.size == 8,
17089 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17090
5287ad62
JB
17091 switch (n)
17092 {
17093 case 0: /* VLD1 / VST1. */
aa8a0863 17094 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17095 32, 32, -1);
5287ad62 17096 if (align_good == FAIL)
477330fc 17097 return;
aa8a0863 17098 if (do_alignment)
477330fc
RM
17099 {
17100 unsigned alignbits = 0;
17101 switch (et.size)
17102 {
17103 case 16: alignbits = 0x1; break;
17104 case 32: alignbits = 0x3; break;
17105 default: ;
17106 }
17107 inst.instruction |= alignbits << 4;
17108 }
5287ad62
JB
17109 break;
17110
17111 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17112 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17113 16, 32, 32, 64, -1);
5287ad62 17114 if (align_good == FAIL)
477330fc 17115 return;
aa8a0863 17116 if (do_alignment)
477330fc 17117 inst.instruction |= 1 << 4;
5287ad62
JB
17118 break;
17119
17120 case 2: /* VLD3 / VST3. */
17121 constraint (inst.operands[1].immisalign,
477330fc 17122 _("can't use alignment with this instruction"));
5287ad62
JB
17123 break;
17124
17125 case 3: /* VLD4 / VST4. */
aa8a0863 17126 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17127 16, 64, 32, 64, 32, 128, -1);
5287ad62 17128 if (align_good == FAIL)
477330fc 17129 return;
aa8a0863 17130 if (do_alignment)
477330fc
RM
17131 {
17132 unsigned alignbits = 0;
17133 switch (et.size)
17134 {
17135 case 8: alignbits = 0x1; break;
17136 case 16: alignbits = 0x1; break;
17137 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17138 default: ;
17139 }
17140 inst.instruction |= alignbits << 4;
17141 }
5287ad62
JB
17142 break;
17143
17144 default: ;
17145 }
17146
17147 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17148 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17149 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17150
5287ad62
JB
17151 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17152 inst.instruction |= logsize << 10;
17153}
17154
17155/* Encode single n-element structure to all lanes VLD<n> instructions. */
17156
17157static void
17158do_neon_ld_dup (void)
17159{
037e8744 17160 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17161 int align_good, do_alignment = 0;
5287ad62 17162
dcbf9037
JB
17163 if (et.type == NT_invtype)
17164 return;
17165
5287ad62
JB
17166 switch ((inst.instruction >> 8) & 3)
17167 {
17168 case 0: /* VLD1. */
9c2799c2 17169 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17170 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17171 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17172 if (align_good == FAIL)
477330fc 17173 return;
5287ad62 17174 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17175 {
17176 case 1: break;
17177 case 2: inst.instruction |= 1 << 5; break;
17178 default: first_error (_("bad list length")); return;
17179 }
5287ad62
JB
17180 inst.instruction |= neon_logbits (et.size) << 6;
17181 break;
17182
17183 case 1: /* VLD2. */
17184 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17185 &do_alignment, 8, 16, 16, 32, 32, 64,
17186 -1);
5287ad62 17187 if (align_good == FAIL)
477330fc 17188 return;
5287ad62 17189 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17190 _("bad list length"));
5287ad62 17191 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17192 inst.instruction |= 1 << 5;
5287ad62
JB
17193 inst.instruction |= neon_logbits (et.size) << 6;
17194 break;
17195
17196 case 2: /* VLD3. */
17197 constraint (inst.operands[1].immisalign,
477330fc 17198 _("can't use alignment with this instruction"));
5287ad62 17199 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17200 _("bad list length"));
5287ad62 17201 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17202 inst.instruction |= 1 << 5;
5287ad62
JB
17203 inst.instruction |= neon_logbits (et.size) << 6;
17204 break;
17205
17206 case 3: /* VLD4. */
17207 {
477330fc 17208 int align = inst.operands[1].imm >> 8;
aa8a0863 17209 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17210 16, 64, 32, 64, 32, 128, -1);
17211 if (align_good == FAIL)
17212 return;
17213 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17214 _("bad list length"));
17215 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17216 inst.instruction |= 1 << 5;
17217 if (et.size == 32 && align == 128)
17218 inst.instruction |= 0x3 << 6;
17219 else
17220 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17221 }
17222 break;
17223
17224 default: ;
17225 }
17226
aa8a0863 17227 inst.instruction |= do_alignment << 4;
5287ad62
JB
17228}
17229
17230/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17231 apart from bits [11:4]. */
17232
17233static void
17234do_neon_ldx_stx (void)
17235{
b1a769ed
DG
17236 if (inst.operands[1].isreg)
17237 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17238
5287ad62
JB
17239 switch (NEON_LANE (inst.operands[0].imm))
17240 {
17241 case NEON_INTERLEAVE_LANES:
88714cb8 17242 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17243 do_neon_ld_st_interleave ();
17244 break;
5f4273c7 17245
5287ad62 17246 case NEON_ALL_LANES:
88714cb8 17247 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17248 if (inst.instruction == N_INV)
17249 {
17250 first_error ("only loads support such operands");
17251 break;
17252 }
5287ad62
JB
17253 do_neon_ld_dup ();
17254 break;
5f4273c7 17255
5287ad62 17256 default:
88714cb8 17257 NEON_ENCODE (LANE, inst);
5287ad62
JB
17258 do_neon_ld_st_lane ();
17259 }
17260
17261 /* L bit comes from bit mask. */
17262 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17263 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17264 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17265
5287ad62
JB
17266 if (inst.operands[1].postind)
17267 {
17268 int postreg = inst.operands[1].imm & 0xf;
17269 constraint (!inst.operands[1].immisreg,
477330fc 17270 _("post-index must be a register"));
5287ad62 17271 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17272 _("bad register for post-index"));
5287ad62
JB
17273 inst.instruction |= postreg;
17274 }
4f2374c7 17275 else
5287ad62 17276 {
4f2374c7
WN
17277 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17278 constraint (inst.reloc.exp.X_op != O_constant
17279 || inst.reloc.exp.X_add_number != 0,
17280 BAD_ADDR_MODE);
17281
17282 if (inst.operands[1].writeback)
17283 {
17284 inst.instruction |= 0xd;
17285 }
17286 else
17287 inst.instruction |= 0xf;
5287ad62 17288 }
5f4273c7 17289
5287ad62
JB
17290 if (thumb_mode)
17291 inst.instruction |= 0xf9000000;
17292 else
17293 inst.instruction |= 0xf4000000;
17294}
33399f07
MGD
17295
17296/* FP v8. */
17297static void
17298do_vfp_nsyn_fpv8 (enum neon_shape rs)
17299{
a715796b
TG
17300 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17301 D register operands. */
17302 if (neon_shape_class[rs] == SC_DOUBLE)
17303 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17304 _(BAD_FPU));
17305
33399f07
MGD
17306 NEON_ENCODE (FPV8, inst);
17307
9db2f6b4
RL
17308 if (rs == NS_FFF || rs == NS_HHH)
17309 {
17310 do_vfp_sp_dyadic ();
17311
17312 /* ARMv8.2 fp16 instruction. */
17313 if (rs == NS_HHH)
17314 do_scalar_fp16_v82_encode ();
17315 }
33399f07
MGD
17316 else
17317 do_vfp_dp_rd_rn_rm ();
17318
17319 if (rs == NS_DDD)
17320 inst.instruction |= 0x100;
17321
17322 inst.instruction |= 0xf0000000;
17323}
17324
17325static void
17326do_vsel (void)
17327{
17328 set_it_insn_type (OUTSIDE_IT_INSN);
17329
17330 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17331 first_error (_("invalid instruction shape"));
17332}
17333
73924fbc
MGD
17334static void
17335do_vmaxnm (void)
17336{
17337 set_it_insn_type (OUTSIDE_IT_INSN);
17338
17339 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17340 return;
17341
17342 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17343 return;
17344
cc933301 17345 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17346}
17347
30bdf752
MGD
17348static void
17349do_vrint_1 (enum neon_cvt_mode mode)
17350{
9db2f6b4 17351 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17352 struct neon_type_el et;
17353
17354 if (rs == NS_NULL)
17355 return;
17356
a715796b
TG
17357 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17358 D register operands. */
17359 if (neon_shape_class[rs] == SC_DOUBLE)
17360 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17361 _(BAD_FPU));
17362
9db2f6b4
RL
17363 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17364 | N_VFP);
30bdf752
MGD
17365 if (et.type != NT_invtype)
17366 {
17367 /* VFP encodings. */
17368 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17369 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17370 set_it_insn_type (OUTSIDE_IT_INSN);
17371
17372 NEON_ENCODE (FPV8, inst);
9db2f6b4 17373 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17374 do_vfp_sp_monadic ();
17375 else
17376 do_vfp_dp_rd_rm ();
17377
17378 switch (mode)
17379 {
17380 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17381 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17382 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17383 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17384 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17385 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17386 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17387 default: abort ();
17388 }
17389
17390 inst.instruction |= (rs == NS_DD) << 8;
17391 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17392
17393 /* ARMv8.2 fp16 vrint instruction. */
17394 if (rs == NS_HH)
17395 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17396 }
17397 else
17398 {
17399 /* Neon encodings (or something broken...). */
17400 inst.error = NULL;
cc933301 17401 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17402
17403 if (et.type == NT_invtype)
17404 return;
17405
17406 set_it_insn_type (OUTSIDE_IT_INSN);
17407 NEON_ENCODE (FLOAT, inst);
17408
17409 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17410 return;
17411
17412 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17413 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17414 inst.instruction |= LOW4 (inst.operands[1].reg);
17415 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17416 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17417 /* Mask off the original size bits and reencode them. */
17418 inst.instruction = ((inst.instruction & 0xfff3ffff)
17419 | neon_logbits (et.size) << 18);
17420
30bdf752
MGD
17421 switch (mode)
17422 {
17423 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17424 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17425 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17426 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17427 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17428 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17429 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17430 default: abort ();
17431 }
17432
17433 if (thumb_mode)
17434 inst.instruction |= 0xfc000000;
17435 else
17436 inst.instruction |= 0xf0000000;
17437 }
17438}
17439
17440static void
17441do_vrintx (void)
17442{
17443 do_vrint_1 (neon_cvt_mode_x);
17444}
17445
17446static void
17447do_vrintz (void)
17448{
17449 do_vrint_1 (neon_cvt_mode_z);
17450}
17451
17452static void
17453do_vrintr (void)
17454{
17455 do_vrint_1 (neon_cvt_mode_r);
17456}
17457
17458static void
17459do_vrinta (void)
17460{
17461 do_vrint_1 (neon_cvt_mode_a);
17462}
17463
17464static void
17465do_vrintn (void)
17466{
17467 do_vrint_1 (neon_cvt_mode_n);
17468}
17469
17470static void
17471do_vrintp (void)
17472{
17473 do_vrint_1 (neon_cvt_mode_p);
17474}
17475
17476static void
17477do_vrintm (void)
17478{
17479 do_vrint_1 (neon_cvt_mode_m);
17480}
17481
c28eeff2
SN
17482static unsigned
17483neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17484{
17485 unsigned regno = NEON_SCALAR_REG (opnd);
17486 unsigned elno = NEON_SCALAR_INDEX (opnd);
17487
17488 if (elsize == 16 && elno < 2 && regno < 16)
17489 return regno | (elno << 4);
17490 else if (elsize == 32 && elno == 0)
17491 return regno;
17492
17493 first_error (_("scalar out of range"));
17494 return 0;
17495}
17496
17497static void
17498do_vcmla (void)
17499{
17500 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17501 _(BAD_FPU));
17502 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17503 unsigned rot = inst.reloc.exp.X_add_number;
17504 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17505 _("immediate out of range"));
17506 rot /= 90;
17507 if (inst.operands[2].isscalar)
17508 {
17509 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17510 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17511 N_KEY | N_F16 | N_F32).size;
17512 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17513 inst.is_neon = 1;
17514 inst.instruction = 0xfe000800;
17515 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17516 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17517 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17518 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17519 inst.instruction |= LOW4 (m);
17520 inst.instruction |= HI1 (m) << 5;
17521 inst.instruction |= neon_quad (rs) << 6;
17522 inst.instruction |= rot << 20;
17523 inst.instruction |= (size == 32) << 23;
17524 }
17525 else
17526 {
17527 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17528 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17529 N_KEY | N_F16 | N_F32).size;
17530 neon_three_same (neon_quad (rs), 0, -1);
17531 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17532 inst.instruction |= 0xfc200800;
17533 inst.instruction |= rot << 23;
17534 inst.instruction |= (size == 32) << 20;
17535 }
17536}
17537
17538static void
17539do_vcadd (void)
17540{
17541 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17542 _(BAD_FPU));
17543 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17544 unsigned rot = inst.reloc.exp.X_add_number;
17545 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17546 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17547 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17548 N_KEY | N_F16 | N_F32).size;
17549 neon_three_same (neon_quad (rs), 0, -1);
17550 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17551 inst.instruction |= 0xfc800800;
17552 inst.instruction |= (rot == 270) << 24;
17553 inst.instruction |= (size == 32) << 20;
17554}
17555
c604a79a
JW
17556/* Dot Product instructions encoding support. */
17557
17558static void
17559do_neon_dotproduct (int unsigned_p)
17560{
17561 enum neon_shape rs;
17562 unsigned scalar_oprd2 = 0;
17563 int high8;
17564
17565 if (inst.cond != COND_ALWAYS)
17566 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17567 "is UNPREDICTABLE"));
17568
17569 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17570 _(BAD_FPU));
17571
17572 /* Dot Product instructions are in three-same D/Q register format or the third
17573 operand can be a scalar index register. */
17574 if (inst.operands[2].isscalar)
17575 {
17576 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17577 high8 = 0xfe000000;
17578 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17579 }
17580 else
17581 {
17582 high8 = 0xfc000000;
17583 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17584 }
17585
17586 if (unsigned_p)
17587 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17588 else
17589 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17590
17591 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17592 Product instruction, so we pass 0 as the "ubit" parameter. And the
17593 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17594 neon_three_same (neon_quad (rs), 0, 32);
17595
17596 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17597 different NEON three-same encoding. */
17598 inst.instruction &= 0x00ffffff;
17599 inst.instruction |= high8;
17600 /* Encode 'U' bit which indicates signedness. */
17601 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17602 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17603 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17604 the instruction encoding. */
17605 if (inst.operands[2].isscalar)
17606 {
17607 inst.instruction &= 0xffffffd0;
17608 inst.instruction |= LOW4 (scalar_oprd2);
17609 inst.instruction |= HI1 (scalar_oprd2) << 5;
17610 }
17611}
17612
17613/* Dot Product instructions for signed integer. */
17614
17615static void
17616do_neon_dotproduct_s (void)
17617{
17618 return do_neon_dotproduct (0);
17619}
17620
17621/* Dot Product instructions for unsigned integer. */
17622
17623static void
17624do_neon_dotproduct_u (void)
17625{
17626 return do_neon_dotproduct (1);
17627}
17628
91ff7894
MGD
17629/* Crypto v1 instructions. */
17630static void
17631do_crypto_2op_1 (unsigned elttype, int op)
17632{
17633 set_it_insn_type (OUTSIDE_IT_INSN);
17634
17635 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17636 == NT_invtype)
17637 return;
17638
17639 inst.error = NULL;
17640
17641 NEON_ENCODE (INTEGER, inst);
17642 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17643 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17644 inst.instruction |= LOW4 (inst.operands[1].reg);
17645 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17646 if (op != -1)
17647 inst.instruction |= op << 6;
17648
17649 if (thumb_mode)
17650 inst.instruction |= 0xfc000000;
17651 else
17652 inst.instruction |= 0xf0000000;
17653}
17654
48adcd8e
MGD
17655static void
17656do_crypto_3op_1 (int u, int op)
17657{
17658 set_it_insn_type (OUTSIDE_IT_INSN);
17659
17660 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17661 N_32 | N_UNT | N_KEY).type == NT_invtype)
17662 return;
17663
17664 inst.error = NULL;
17665
17666 NEON_ENCODE (INTEGER, inst);
17667 neon_three_same (1, u, 8 << op);
17668}
17669
91ff7894
MGD
17670static void
17671do_aese (void)
17672{
17673 do_crypto_2op_1 (N_8, 0);
17674}
17675
17676static void
17677do_aesd (void)
17678{
17679 do_crypto_2op_1 (N_8, 1);
17680}
17681
17682static void
17683do_aesmc (void)
17684{
17685 do_crypto_2op_1 (N_8, 2);
17686}
17687
17688static void
17689do_aesimc (void)
17690{
17691 do_crypto_2op_1 (N_8, 3);
17692}
17693
48adcd8e
MGD
17694static void
17695do_sha1c (void)
17696{
17697 do_crypto_3op_1 (0, 0);
17698}
17699
17700static void
17701do_sha1p (void)
17702{
17703 do_crypto_3op_1 (0, 1);
17704}
17705
17706static void
17707do_sha1m (void)
17708{
17709 do_crypto_3op_1 (0, 2);
17710}
17711
17712static void
17713do_sha1su0 (void)
17714{
17715 do_crypto_3op_1 (0, 3);
17716}
91ff7894 17717
48adcd8e
MGD
17718static void
17719do_sha256h (void)
17720{
17721 do_crypto_3op_1 (1, 0);
17722}
17723
17724static void
17725do_sha256h2 (void)
17726{
17727 do_crypto_3op_1 (1, 1);
17728}
17729
17730static void
17731do_sha256su1 (void)
17732{
17733 do_crypto_3op_1 (1, 2);
17734}
3c9017d2
MGD
17735
17736static void
17737do_sha1h (void)
17738{
17739 do_crypto_2op_1 (N_32, -1);
17740}
17741
17742static void
17743do_sha1su1 (void)
17744{
17745 do_crypto_2op_1 (N_32, 0);
17746}
17747
17748static void
17749do_sha256su0 (void)
17750{
17751 do_crypto_2op_1 (N_32, 1);
17752}
dd5181d5
KT
17753
17754static void
17755do_crc32_1 (unsigned int poly, unsigned int sz)
17756{
17757 unsigned int Rd = inst.operands[0].reg;
17758 unsigned int Rn = inst.operands[1].reg;
17759 unsigned int Rm = inst.operands[2].reg;
17760
17761 set_it_insn_type (OUTSIDE_IT_INSN);
17762 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17763 inst.instruction |= LOW4 (Rn) << 16;
17764 inst.instruction |= LOW4 (Rm);
17765 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17766 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17767
17768 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17769 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17770}
17771
17772static void
17773do_crc32b (void)
17774{
17775 do_crc32_1 (0, 0);
17776}
17777
17778static void
17779do_crc32h (void)
17780{
17781 do_crc32_1 (0, 1);
17782}
17783
17784static void
17785do_crc32w (void)
17786{
17787 do_crc32_1 (0, 2);
17788}
17789
17790static void
17791do_crc32cb (void)
17792{
17793 do_crc32_1 (1, 0);
17794}
17795
17796static void
17797do_crc32ch (void)
17798{
17799 do_crc32_1 (1, 1);
17800}
17801
17802static void
17803do_crc32cw (void)
17804{
17805 do_crc32_1 (1, 2);
17806}
17807
49e8a725
SN
17808static void
17809do_vjcvt (void)
17810{
17811 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17812 _(BAD_FPU));
17813 neon_check_type (2, NS_FD, N_S32, N_F64);
17814 do_vfp_sp_dp_cvt ();
17815 do_vfp_cond_or_thumb ();
17816}
17817
5287ad62
JB
17818\f
17819/* Overall per-instruction processing. */
17820
17821/* We need to be able to fix up arbitrary expressions in some statements.
17822 This is so that we can handle symbols that are an arbitrary distance from
17823 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17824 which returns part of an address in a form which will be valid for
17825 a data instruction. We do this by pushing the expression into a symbol
17826 in the expr_section, and creating a fix for that. */
17827
17828static void
17829fix_new_arm (fragS * frag,
17830 int where,
17831 short int size,
17832 expressionS * exp,
17833 int pc_rel,
17834 int reloc)
17835{
17836 fixS * new_fix;
17837
17838 switch (exp->X_op)
17839 {
17840 case O_constant:
6e7ce2cd
PB
17841 if (pc_rel)
17842 {
17843 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17844 refer to in the object file. Unfortunately for us, gas's
17845 generic expression parsing will already have folded out
17846 any use of .set foo/.type foo %function that may have
17847 been used to set type information of the target location,
17848 that's being specified symbolically. We have to presume
17849 the user knows what they are doing. */
6e7ce2cd
PB
17850 char name[16 + 8];
17851 symbolS *symbol;
17852
17853 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17854
17855 symbol = symbol_find_or_make (name);
17856 S_SET_SEGMENT (symbol, absolute_section);
17857 symbol_set_frag (symbol, &zero_address_frag);
17858 S_SET_VALUE (symbol, exp->X_add_number);
17859 exp->X_op = O_symbol;
17860 exp->X_add_symbol = symbol;
17861 exp->X_add_number = 0;
17862 }
17863 /* FALLTHROUGH */
5287ad62
JB
17864 case O_symbol:
17865 case O_add:
17866 case O_subtract:
21d799b5 17867 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17868 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17869 break;
17870
17871 default:
21d799b5 17872 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17873 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17874 break;
17875 }
17876
17877 /* Mark whether the fix is to a THUMB instruction, or an ARM
17878 instruction. */
17879 new_fix->tc_fix_data = thumb_mode;
17880}
17881
17882/* Create a frg for an instruction requiring relaxation. */
17883static void
17884output_relax_insn (void)
17885{
17886 char * to;
17887 symbolS *sym;
0110f2b8
PB
17888 int offset;
17889
6e1cb1a6
PB
17890 /* The size of the instruction is unknown, so tie the debug info to the
17891 start of the instruction. */
17892 dwarf2_emit_insn (0);
6e1cb1a6 17893
0110f2b8
PB
17894 switch (inst.reloc.exp.X_op)
17895 {
17896 case O_symbol:
17897 sym = inst.reloc.exp.X_add_symbol;
17898 offset = inst.reloc.exp.X_add_number;
17899 break;
17900 case O_constant:
17901 sym = NULL;
17902 offset = inst.reloc.exp.X_add_number;
17903 break;
17904 default:
17905 sym = make_expr_symbol (&inst.reloc.exp);
17906 offset = 0;
17907 break;
17908 }
17909 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17910 inst.relax, sym, offset, NULL/*offset, opcode*/);
17911 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17912}
17913
17914/* Write a 32-bit thumb instruction to buf. */
17915static void
17916put_thumb32_insn (char * buf, unsigned long insn)
17917{
17918 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17919 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17920}
17921
b99bd4ef 17922static void
c19d1205 17923output_inst (const char * str)
b99bd4ef 17924{
c19d1205 17925 char * to = NULL;
b99bd4ef 17926
c19d1205 17927 if (inst.error)
b99bd4ef 17928 {
c19d1205 17929 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17930 return;
17931 }
5f4273c7
NC
17932 if (inst.relax)
17933 {
17934 output_relax_insn ();
0110f2b8 17935 return;
5f4273c7 17936 }
c19d1205
ZW
17937 if (inst.size == 0)
17938 return;
b99bd4ef 17939
c19d1205 17940 to = frag_more (inst.size);
8dc2430f
NC
17941 /* PR 9814: Record the thumb mode into the current frag so that we know
17942 what type of NOP padding to use, if necessary. We override any previous
17943 setting so that if the mode has changed then the NOPS that we use will
17944 match the encoding of the last instruction in the frag. */
cd000bff 17945 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17946
17947 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17948 {
9c2799c2 17949 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17950 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17951 }
c19d1205 17952 else if (inst.size > INSN_SIZE)
b99bd4ef 17953 {
9c2799c2 17954 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17955 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17956 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17957 }
c19d1205
ZW
17958 else
17959 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17960
c19d1205
ZW
17961 if (inst.reloc.type != BFD_RELOC_UNUSED)
17962 fix_new_arm (frag_now, to - frag_now->fr_literal,
17963 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17964 inst.reloc.type);
b99bd4ef 17965
c19d1205 17966 dwarf2_emit_insn (inst.size);
c19d1205 17967}
b99bd4ef 17968
e07e6e58
NC
17969static char *
17970output_it_inst (int cond, int mask, char * to)
17971{
17972 unsigned long instruction = 0xbf00;
17973
17974 mask &= 0xf;
17975 instruction |= mask;
17976 instruction |= cond << 4;
17977
17978 if (to == NULL)
17979 {
17980 to = frag_more (2);
17981#ifdef OBJ_ELF
17982 dwarf2_emit_insn (2);
17983#endif
17984 }
17985
17986 md_number_to_chars (to, instruction, 2);
17987
17988 return to;
17989}
17990
c19d1205
ZW
17991/* Tag values used in struct asm_opcode's tag field. */
17992enum opcode_tag
17993{
17994 OT_unconditional, /* Instruction cannot be conditionalized.
17995 The ARM condition field is still 0xE. */
17996 OT_unconditionalF, /* Instruction cannot be conditionalized
17997 and carries 0xF in its ARM condition field. */
17998 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17999 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18000 suffix, others place 0xF where the condition field
18001 would be. */
c19d1205
ZW
18002 OT_cinfix3, /* Instruction takes a conditional infix,
18003 beginning at character index 3. (In
18004 unified mode, it becomes a suffix.) */
088fa78e
KH
18005 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18006 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18007 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18008 character index 3, even in unified mode. Used for
18009 legacy instructions where suffix and infix forms
18010 may be ambiguous. */
c19d1205 18011 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18012 suffix or an infix at character index 3. */
c19d1205
ZW
18013 OT_odd_infix_unc, /* This is the unconditional variant of an
18014 instruction that takes a conditional infix
18015 at an unusual position. In unified mode,
18016 this variant will accept a suffix. */
18017 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18018 are the conditional variants of instructions that
18019 take conditional infixes in unusual positions.
18020 The infix appears at character index
18021 (tag - OT_odd_infix_0). These are not accepted
18022 in unified mode. */
18023};
b99bd4ef 18024
c19d1205
ZW
18025/* Subroutine of md_assemble, responsible for looking up the primary
18026 opcode from the mnemonic the user wrote. STR points to the
18027 beginning of the mnemonic.
18028
18029 This is not simply a hash table lookup, because of conditional
18030 variants. Most instructions have conditional variants, which are
18031 expressed with a _conditional affix_ to the mnemonic. If we were
18032 to encode each conditional variant as a literal string in the opcode
18033 table, it would have approximately 20,000 entries.
18034
18035 Most mnemonics take this affix as a suffix, and in unified syntax,
18036 'most' is upgraded to 'all'. However, in the divided syntax, some
18037 instructions take the affix as an infix, notably the s-variants of
18038 the arithmetic instructions. Of those instructions, all but six
18039 have the infix appear after the third character of the mnemonic.
18040
18041 Accordingly, the algorithm for looking up primary opcodes given
18042 an identifier is:
18043
18044 1. Look up the identifier in the opcode table.
18045 If we find a match, go to step U.
18046
18047 2. Look up the last two characters of the identifier in the
18048 conditions table. If we find a match, look up the first N-2
18049 characters of the identifier in the opcode table. If we
18050 find a match, go to step CE.
18051
18052 3. Look up the fourth and fifth characters of the identifier in
18053 the conditions table. If we find a match, extract those
18054 characters from the identifier, and look up the remaining
18055 characters in the opcode table. If we find a match, go
18056 to step CM.
18057
18058 4. Fail.
18059
18060 U. Examine the tag field of the opcode structure, in case this is
18061 one of the six instructions with its conditional infix in an
18062 unusual place. If it is, the tag tells us where to find the
18063 infix; look it up in the conditions table and set inst.cond
18064 accordingly. Otherwise, this is an unconditional instruction.
18065 Again set inst.cond accordingly. Return the opcode structure.
18066
18067 CE. Examine the tag field to make sure this is an instruction that
18068 should receive a conditional suffix. If it is not, fail.
18069 Otherwise, set inst.cond from the suffix we already looked up,
18070 and return the opcode structure.
18071
18072 CM. Examine the tag field to make sure this is an instruction that
18073 should receive a conditional infix after the third character.
18074 If it is not, fail. Otherwise, undo the edits to the current
18075 line of input and proceed as for case CE. */
18076
18077static const struct asm_opcode *
18078opcode_lookup (char **str)
18079{
18080 char *end, *base;
18081 char *affix;
18082 const struct asm_opcode *opcode;
18083 const struct asm_cond *cond;
e3cb604e 18084 char save[2];
c19d1205
ZW
18085
18086 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18087 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18088 for (base = end = *str; *end != '\0'; end++)
721a8186 18089 if (*end == ' ' || *end == '.')
c19d1205 18090 break;
b99bd4ef 18091
c19d1205 18092 if (end == base)
c921be7d 18093 return NULL;
b99bd4ef 18094
5287ad62 18095 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18096 if (end[0] == '.')
b99bd4ef 18097 {
5287ad62 18098 int offset = 2;
5f4273c7 18099
267d2029 18100 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18101 use. */
267d2029 18102 if (unified_syntax && end[1] == 'w')
c19d1205 18103 inst.size_req = 4;
267d2029 18104 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18105 inst.size_req = 2;
18106 else
477330fc 18107 offset = 0;
5287ad62
JB
18108
18109 inst.vectype.elems = 0;
18110
18111 *str = end + offset;
b99bd4ef 18112
5f4273c7 18113 if (end[offset] == '.')
5287ad62 18114 {
267d2029 18115 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18116 non-unified ARM syntax mode). */
18117 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18118 return NULL;
477330fc 18119 }
5287ad62 18120 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18121 return NULL;
b99bd4ef 18122 }
c19d1205
ZW
18123 else
18124 *str = end;
b99bd4ef 18125
c19d1205 18126 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18127 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18128 end - base);
c19d1205 18129 if (opcode)
b99bd4ef 18130 {
c19d1205
ZW
18131 /* step U */
18132 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18133 {
c19d1205
ZW
18134 inst.cond = COND_ALWAYS;
18135 return opcode;
b99bd4ef 18136 }
b99bd4ef 18137
278df34e 18138 if (warn_on_deprecated && unified_syntax)
5c3696f8 18139 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18140 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18141 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18142 gas_assert (cond);
b99bd4ef 18143
c19d1205
ZW
18144 inst.cond = cond->value;
18145 return opcode;
18146 }
b99bd4ef 18147
c19d1205
ZW
18148 /* Cannot have a conditional suffix on a mnemonic of less than two
18149 characters. */
18150 if (end - base < 3)
c921be7d 18151 return NULL;
b99bd4ef 18152
c19d1205
ZW
18153 /* Look for suffixed mnemonic. */
18154 affix = end - 2;
21d799b5
NC
18155 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18156 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18157 affix - base);
c19d1205
ZW
18158 if (opcode && cond)
18159 {
18160 /* step CE */
18161 switch (opcode->tag)
18162 {
e3cb604e
PB
18163 case OT_cinfix3_legacy:
18164 /* Ignore conditional suffixes matched on infix only mnemonics. */
18165 break;
18166
c19d1205 18167 case OT_cinfix3:
088fa78e 18168 case OT_cinfix3_deprecated:
c19d1205
ZW
18169 case OT_odd_infix_unc:
18170 if (!unified_syntax)
0198d5e6 18171 return NULL;
1a0670f3 18172 /* Fall through. */
c19d1205
ZW
18173
18174 case OT_csuffix:
477330fc 18175 case OT_csuffixF:
c19d1205
ZW
18176 case OT_csuf_or_in3:
18177 inst.cond = cond->value;
18178 return opcode;
18179
18180 case OT_unconditional:
18181 case OT_unconditionalF:
dfa9f0d5 18182 if (thumb_mode)
c921be7d 18183 inst.cond = cond->value;
dfa9f0d5
PB
18184 else
18185 {
c921be7d 18186 /* Delayed diagnostic. */
dfa9f0d5
PB
18187 inst.error = BAD_COND;
18188 inst.cond = COND_ALWAYS;
18189 }
c19d1205 18190 return opcode;
b99bd4ef 18191
c19d1205 18192 default:
c921be7d 18193 return NULL;
c19d1205
ZW
18194 }
18195 }
b99bd4ef 18196
c19d1205
ZW
18197 /* Cannot have a usual-position infix on a mnemonic of less than
18198 six characters (five would be a suffix). */
18199 if (end - base < 6)
c921be7d 18200 return NULL;
b99bd4ef 18201
c19d1205
ZW
18202 /* Look for infixed mnemonic in the usual position. */
18203 affix = base + 3;
21d799b5 18204 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18205 if (!cond)
c921be7d 18206 return NULL;
e3cb604e
PB
18207
18208 memcpy (save, affix, 2);
18209 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18210 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18211 (end - base) - 2);
e3cb604e
PB
18212 memmove (affix + 2, affix, (end - affix) - 2);
18213 memcpy (affix, save, 2);
18214
088fa78e
KH
18215 if (opcode
18216 && (opcode->tag == OT_cinfix3
18217 || opcode->tag == OT_cinfix3_deprecated
18218 || opcode->tag == OT_csuf_or_in3
18219 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18220 {
c921be7d 18221 /* Step CM. */
278df34e 18222 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18223 && (opcode->tag == OT_cinfix3
18224 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18225 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18226
18227 inst.cond = cond->value;
18228 return opcode;
b99bd4ef
NC
18229 }
18230
c921be7d 18231 return NULL;
b99bd4ef
NC
18232}
18233
e07e6e58
NC
18234/* This function generates an initial IT instruction, leaving its block
18235 virtually open for the new instructions. Eventually,
18236 the mask will be updated by now_it_add_mask () each time
18237 a new instruction needs to be included in the IT block.
18238 Finally, the block is closed with close_automatic_it_block ().
18239 The block closure can be requested either from md_assemble (),
18240 a tencode (), or due to a label hook. */
18241
18242static void
18243new_automatic_it_block (int cond)
18244{
18245 now_it.state = AUTOMATIC_IT_BLOCK;
18246 now_it.mask = 0x18;
18247 now_it.cc = cond;
18248 now_it.block_length = 1;
cd000bff 18249 mapping_state (MAP_THUMB);
e07e6e58 18250 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18251 now_it.warn_deprecated = FALSE;
18252 now_it.insn_cond = TRUE;
e07e6e58
NC
18253}
18254
18255/* Close an automatic IT block.
18256 See comments in new_automatic_it_block (). */
18257
18258static void
18259close_automatic_it_block (void)
18260{
18261 now_it.mask = 0x10;
18262 now_it.block_length = 0;
18263}
18264
18265/* Update the mask of the current automatically-generated IT
18266 instruction. See comments in new_automatic_it_block (). */
18267
18268static void
18269now_it_add_mask (int cond)
18270{
18271#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18272#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18273 | ((bitvalue) << (nbit)))
e07e6e58 18274 const int resulting_bit = (cond & 1);
c921be7d 18275
e07e6e58
NC
18276 now_it.mask &= 0xf;
18277 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18278 resulting_bit,
18279 (5 - now_it.block_length));
e07e6e58 18280 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18281 1,
18282 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18283 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18284
18285#undef CLEAR_BIT
18286#undef SET_BIT_VALUE
e07e6e58
NC
18287}
18288
18289/* The IT blocks handling machinery is accessed through the these functions:
18290 it_fsm_pre_encode () from md_assemble ()
18291 set_it_insn_type () optional, from the tencode functions
18292 set_it_insn_type_last () ditto
18293 in_it_block () ditto
18294 it_fsm_post_encode () from md_assemble ()
33eaf5de 18295 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18296
18297 Rationale:
18298 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18299 initializing the IT insn type with a generic initial value depending
18300 on the inst.condition.
e07e6e58 18301 2) During the tencode function, two things may happen:
477330fc
RM
18302 a) The tencode function overrides the IT insn type by
18303 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18304 b) The tencode function queries the IT block state by
18305 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18306
18307 Both set_it_insn_type and in_it_block run the internal FSM state
18308 handling function (handle_it_state), because: a) setting the IT insn
18309 type may incur in an invalid state (exiting the function),
18310 and b) querying the state requires the FSM to be updated.
18311 Specifically we want to avoid creating an IT block for conditional
18312 branches, so it_fsm_pre_encode is actually a guess and we can't
18313 determine whether an IT block is required until the tencode () routine
18314 has decided what type of instruction this actually it.
18315 Because of this, if set_it_insn_type and in_it_block have to be used,
18316 set_it_insn_type has to be called first.
18317
18318 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18319 determines the insn IT type depending on the inst.cond code.
18320 When a tencode () routine encodes an instruction that can be
18321 either outside an IT block, or, in the case of being inside, has to be
18322 the last one, set_it_insn_type_last () will determine the proper
18323 IT instruction type based on the inst.cond code. Otherwise,
18324 set_it_insn_type can be called for overriding that logic or
18325 for covering other cases.
18326
18327 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18328 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18329 still queried. Instead, if the FSM determines that the state should
18330 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18331 after the tencode () function: that's what it_fsm_post_encode () does.
18332
18333 Since in_it_block () calls the state handling function to get an
18334 updated state, an error may occur (due to invalid insns combination).
18335 In that case, inst.error is set.
18336 Therefore, inst.error has to be checked after the execution of
18337 the tencode () routine.
e07e6e58
NC
18338
18339 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18340 any pending state change (if any) that didn't take place in
18341 handle_it_state () as explained above. */
e07e6e58
NC
18342
18343static void
18344it_fsm_pre_encode (void)
18345{
18346 if (inst.cond != COND_ALWAYS)
18347 inst.it_insn_type = INSIDE_IT_INSN;
18348 else
18349 inst.it_insn_type = OUTSIDE_IT_INSN;
18350
18351 now_it.state_handled = 0;
18352}
18353
18354/* IT state FSM handling function. */
18355
18356static int
18357handle_it_state (void)
18358{
18359 now_it.state_handled = 1;
5a01bb1d 18360 now_it.insn_cond = FALSE;
e07e6e58
NC
18361
18362 switch (now_it.state)
18363 {
18364 case OUTSIDE_IT_BLOCK:
18365 switch (inst.it_insn_type)
18366 {
18367 case OUTSIDE_IT_INSN:
18368 break;
18369
18370 case INSIDE_IT_INSN:
18371 case INSIDE_IT_LAST_INSN:
18372 if (thumb_mode == 0)
18373 {
c921be7d 18374 if (unified_syntax
e07e6e58
NC
18375 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18376 as_tsktsk (_("Warning: conditional outside an IT block"\
18377 " for Thumb."));
18378 }
18379 else
18380 {
18381 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18382 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18383 {
18384 /* Automatically generate the IT instruction. */
18385 new_automatic_it_block (inst.cond);
18386 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18387 close_automatic_it_block ();
18388 }
18389 else
18390 {
18391 inst.error = BAD_OUT_IT;
18392 return FAIL;
18393 }
18394 }
18395 break;
18396
18397 case IF_INSIDE_IT_LAST_INSN:
18398 case NEUTRAL_IT_INSN:
18399 break;
18400
18401 case IT_INSN:
18402 now_it.state = MANUAL_IT_BLOCK;
18403 now_it.block_length = 0;
18404 break;
18405 }
18406 break;
18407
18408 case AUTOMATIC_IT_BLOCK:
18409 /* Three things may happen now:
18410 a) We should increment current it block size;
18411 b) We should close current it block (closing insn or 4 insns);
18412 c) We should close current it block and start a new one (due
18413 to incompatible conditions or
18414 4 insns-length block reached). */
18415
18416 switch (inst.it_insn_type)
18417 {
18418 case OUTSIDE_IT_INSN:
2b0f3761 18419 /* The closure of the block shall happen immediately,
e07e6e58
NC
18420 so any in_it_block () call reports the block as closed. */
18421 force_automatic_it_block_close ();
18422 break;
18423
18424 case INSIDE_IT_INSN:
18425 case INSIDE_IT_LAST_INSN:
18426 case IF_INSIDE_IT_LAST_INSN:
18427 now_it.block_length++;
18428
18429 if (now_it.block_length > 4
18430 || !now_it_compatible (inst.cond))
18431 {
18432 force_automatic_it_block_close ();
18433 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18434 new_automatic_it_block (inst.cond);
18435 }
18436 else
18437 {
5a01bb1d 18438 now_it.insn_cond = TRUE;
e07e6e58
NC
18439 now_it_add_mask (inst.cond);
18440 }
18441
18442 if (now_it.state == AUTOMATIC_IT_BLOCK
18443 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18444 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18445 close_automatic_it_block ();
18446 break;
18447
18448 case NEUTRAL_IT_INSN:
18449 now_it.block_length++;
5a01bb1d 18450 now_it.insn_cond = TRUE;
e07e6e58
NC
18451
18452 if (now_it.block_length > 4)
18453 force_automatic_it_block_close ();
18454 else
18455 now_it_add_mask (now_it.cc & 1);
18456 break;
18457
18458 case IT_INSN:
18459 close_automatic_it_block ();
18460 now_it.state = MANUAL_IT_BLOCK;
18461 break;
18462 }
18463 break;
18464
18465 case MANUAL_IT_BLOCK:
18466 {
18467 /* Check conditional suffixes. */
18468 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18469 int is_last;
18470 now_it.mask <<= 1;
18471 now_it.mask &= 0x1f;
18472 is_last = (now_it.mask == 0x10);
5a01bb1d 18473 now_it.insn_cond = TRUE;
e07e6e58
NC
18474
18475 switch (inst.it_insn_type)
18476 {
18477 case OUTSIDE_IT_INSN:
18478 inst.error = BAD_NOT_IT;
18479 return FAIL;
18480
18481 case INSIDE_IT_INSN:
18482 if (cond != inst.cond)
18483 {
18484 inst.error = BAD_IT_COND;
18485 return FAIL;
18486 }
18487 break;
18488
18489 case INSIDE_IT_LAST_INSN:
18490 case IF_INSIDE_IT_LAST_INSN:
18491 if (cond != inst.cond)
18492 {
18493 inst.error = BAD_IT_COND;
18494 return FAIL;
18495 }
18496 if (!is_last)
18497 {
18498 inst.error = BAD_BRANCH;
18499 return FAIL;
18500 }
18501 break;
18502
18503 case NEUTRAL_IT_INSN:
18504 /* The BKPT instruction is unconditional even in an IT block. */
18505 break;
18506
18507 case IT_INSN:
18508 inst.error = BAD_IT_IT;
18509 return FAIL;
18510 }
18511 }
18512 break;
18513 }
18514
18515 return SUCCESS;
18516}
18517
5a01bb1d
MGD
18518struct depr_insn_mask
18519{
18520 unsigned long pattern;
18521 unsigned long mask;
18522 const char* description;
18523};
18524
18525/* List of 16-bit instruction patterns deprecated in an IT block in
18526 ARMv8. */
18527static const struct depr_insn_mask depr_it_insns[] = {
18528 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18529 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18530 { 0xa000, 0xb800, N_("ADR") },
18531 { 0x4800, 0xf800, N_("Literal loads") },
18532 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18533 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18534 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18535 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18536 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18537 { 0, 0, NULL }
18538};
18539
e07e6e58
NC
18540static void
18541it_fsm_post_encode (void)
18542{
18543 int is_last;
18544
18545 if (!now_it.state_handled)
18546 handle_it_state ();
18547
5a01bb1d
MGD
18548 if (now_it.insn_cond
18549 && !now_it.warn_deprecated
18550 && warn_on_deprecated
18551 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18552 {
18553 if (inst.instruction >= 0x10000)
18554 {
5c3696f8 18555 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18556 "deprecated in ARMv8"));
18557 now_it.warn_deprecated = TRUE;
18558 }
18559 else
18560 {
18561 const struct depr_insn_mask *p = depr_it_insns;
18562
18563 while (p->mask != 0)
18564 {
18565 if ((inst.instruction & p->mask) == p->pattern)
18566 {
5c3696f8 18567 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18568 "of the following class are deprecated in ARMv8: "
18569 "%s"), p->description);
18570 now_it.warn_deprecated = TRUE;
18571 break;
18572 }
18573
18574 ++p;
18575 }
18576 }
18577
18578 if (now_it.block_length > 1)
18579 {
5c3696f8 18580 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18581 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18582 now_it.warn_deprecated = TRUE;
18583 }
18584 }
18585
e07e6e58
NC
18586 is_last = (now_it.mask == 0x10);
18587 if (is_last)
18588 {
18589 now_it.state = OUTSIDE_IT_BLOCK;
18590 now_it.mask = 0;
18591 }
18592}
18593
18594static void
18595force_automatic_it_block_close (void)
18596{
18597 if (now_it.state == AUTOMATIC_IT_BLOCK)
18598 {
18599 close_automatic_it_block ();
18600 now_it.state = OUTSIDE_IT_BLOCK;
18601 now_it.mask = 0;
18602 }
18603}
18604
18605static int
18606in_it_block (void)
18607{
18608 if (!now_it.state_handled)
18609 handle_it_state ();
18610
18611 return now_it.state != OUTSIDE_IT_BLOCK;
18612}
18613
ff8646ee
TP
18614/* Whether OPCODE only has T32 encoding. Since this function is only used by
18615 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18616 here, hence the "known" in the function name. */
fc289b0a
TP
18617
18618static bfd_boolean
ff8646ee 18619known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18620{
18621 /* Original Thumb-1 wide instruction. */
18622 if (opcode->tencode == do_t_blx
18623 || opcode->tencode == do_t_branch23
18624 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18625 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18626 return TRUE;
18627
16a1fa25
TP
18628 /* Wide-only instruction added to ARMv8-M Baseline. */
18629 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18630 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18631 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18632 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18633 return TRUE;
18634
18635 return FALSE;
18636}
18637
18638/* Whether wide instruction variant can be used if available for a valid OPCODE
18639 in ARCH. */
18640
18641static bfd_boolean
18642t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18643{
18644 if (known_t32_only_insn (opcode))
18645 return TRUE;
18646
18647 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18648 of variant T3 of B.W is checked in do_t_branch. */
18649 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18650 && opcode->tencode == do_t_branch)
18651 return TRUE;
18652
bada4342
JW
18653 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18654 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18655 && opcode->tencode == do_t_mov_cmp
18656 /* Make sure CMP instruction is not affected. */
18657 && opcode->aencode == do_mov)
18658 return TRUE;
18659
ff8646ee
TP
18660 /* Wide instruction variants of all instructions with narrow *and* wide
18661 variants become available with ARMv6t2. Other opcodes are either
18662 narrow-only or wide-only and are thus available if OPCODE is valid. */
18663 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18664 return TRUE;
18665
18666 /* OPCODE with narrow only instruction variant or wide variant not
18667 available. */
fc289b0a
TP
18668 return FALSE;
18669}
18670
c19d1205
ZW
18671void
18672md_assemble (char *str)
b99bd4ef 18673{
c19d1205
ZW
18674 char *p = str;
18675 const struct asm_opcode * opcode;
b99bd4ef 18676
c19d1205
ZW
18677 /* Align the previous label if needed. */
18678 if (last_label_seen != NULL)
b99bd4ef 18679 {
c19d1205
ZW
18680 symbol_set_frag (last_label_seen, frag_now);
18681 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18682 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18683 }
18684
c19d1205
ZW
18685 memset (&inst, '\0', sizeof (inst));
18686 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18687
c19d1205
ZW
18688 opcode = opcode_lookup (&p);
18689 if (!opcode)
b99bd4ef 18690 {
c19d1205 18691 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18692 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18693 if (! create_register_alias (str, p)
477330fc 18694 && ! create_neon_reg_alias (str, p))
c19d1205 18695 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18696
b99bd4ef
NC
18697 return;
18698 }
18699
278df34e 18700 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18701 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18702
037e8744
JB
18703 /* The value which unconditional instructions should have in place of the
18704 condition field. */
18705 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18706
c19d1205 18707 if (thumb_mode)
b99bd4ef 18708 {
e74cfd16 18709 arm_feature_set variant;
8f06b2d8
PB
18710
18711 variant = cpu_variant;
18712 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18713 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18714 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18715 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18716 if (!opcode->tvariant
18717 || (thumb_mode == 1
18718 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18719 {
173205ca
TP
18720 if (opcode->tencode == do_t_swi)
18721 as_bad (_("SVC is not permitted on this architecture"));
18722 else
18723 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18724 return;
18725 }
c19d1205
ZW
18726 if (inst.cond != COND_ALWAYS && !unified_syntax
18727 && opcode->tencode != do_t_branch)
b99bd4ef 18728 {
c19d1205 18729 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18730 return;
18731 }
18732
fc289b0a
TP
18733 /* Two things are addressed here:
18734 1) Implicit require narrow instructions on Thumb-1.
18735 This avoids relaxation accidentally introducing Thumb-2
18736 instructions.
18737 2) Reject wide instructions in non Thumb-2 cores.
18738
18739 Only instructions with narrow and wide variants need to be handled
18740 but selecting all non wide-only instructions is easier. */
18741 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18742 && !t32_insn_ok (variant, opcode))
076d447c 18743 {
fc289b0a
TP
18744 if (inst.size_req == 0)
18745 inst.size_req = 2;
18746 else if (inst.size_req == 4)
752d5da4 18747 {
ff8646ee
TP
18748 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18749 as_bad (_("selected processor does not support 32bit wide "
18750 "variant of instruction `%s'"), str);
18751 else
18752 as_bad (_("selected processor does not support `%s' in "
18753 "Thumb-2 mode"), str);
fc289b0a 18754 return;
752d5da4 18755 }
076d447c
PB
18756 }
18757
c19d1205
ZW
18758 inst.instruction = opcode->tvalue;
18759
5be8be5d 18760 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18761 {
18762 /* Prepare the it_insn_type for those encodings that don't set
18763 it. */
18764 it_fsm_pre_encode ();
c19d1205 18765
477330fc 18766 opcode->tencode ();
e07e6e58 18767
477330fc
RM
18768 it_fsm_post_encode ();
18769 }
e27ec89e 18770
0110f2b8 18771 if (!(inst.error || inst.relax))
b99bd4ef 18772 {
9c2799c2 18773 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18774 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18775 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18776 {
c19d1205 18777 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18778 return;
18779 }
18780 }
076d447c
PB
18781
18782 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18783 instruction. */
9c2799c2 18784 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18785
e74cfd16
PB
18786 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18787 *opcode->tvariant);
ee065d83 18788 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18789 set those bits when Thumb-2 32-bit instructions are seen. The impact
18790 of relaxable instructions will be considered later after we finish all
18791 relaxation. */
ff8646ee
TP
18792 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18793 variant = arm_arch_none;
18794 else
18795 variant = cpu_variant;
18796 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18797 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18798 arm_ext_v6t2);
cd000bff 18799
88714cb8
DG
18800 check_neon_suffixes;
18801
cd000bff 18802 if (!inst.error)
c877a2f2
NC
18803 {
18804 mapping_state (MAP_THUMB);
18805 }
c19d1205 18806 }
3e9e4fcf 18807 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18808 {
845b51d6
PB
18809 bfd_boolean is_bx;
18810
18811 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18812 is_bx = (opcode->aencode == do_bx);
18813
c19d1205 18814 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18815 if (!(is_bx && fix_v4bx)
18816 && !(opcode->avariant &&
18817 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18818 {
84b52b66 18819 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18820 return;
b99bd4ef 18821 }
c19d1205 18822 if (inst.size_req)
b99bd4ef 18823 {
c19d1205
ZW
18824 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18825 return;
b99bd4ef
NC
18826 }
18827
c19d1205
ZW
18828 inst.instruction = opcode->avalue;
18829 if (opcode->tag == OT_unconditionalF)
eff0bc54 18830 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18831 else
18832 inst.instruction |= inst.cond << 28;
18833 inst.size = INSN_SIZE;
5be8be5d 18834 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18835 {
18836 it_fsm_pre_encode ();
18837 opcode->aencode ();
18838 it_fsm_post_encode ();
18839 }
ee065d83 18840 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18841 on a hypothetical non-thumb v5 core. */
845b51d6 18842 if (is_bx)
e74cfd16 18843 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18844 else
e74cfd16
PB
18845 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18846 *opcode->avariant);
88714cb8
DG
18847
18848 check_neon_suffixes;
18849
cd000bff 18850 if (!inst.error)
c877a2f2
NC
18851 {
18852 mapping_state (MAP_ARM);
18853 }
b99bd4ef 18854 }
3e9e4fcf
JB
18855 else
18856 {
18857 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18858 "-- `%s'"), str);
18859 return;
18860 }
c19d1205
ZW
18861 output_inst (str);
18862}
b99bd4ef 18863
e07e6e58
NC
18864static void
18865check_it_blocks_finished (void)
18866{
18867#ifdef OBJ_ELF
18868 asection *sect;
18869
18870 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18871 if (seg_info (sect)->tc_segment_info_data.current_it.state
18872 == MANUAL_IT_BLOCK)
18873 {
18874 as_warn (_("section '%s' finished with an open IT block."),
18875 sect->name);
18876 }
18877#else
18878 if (now_it.state == MANUAL_IT_BLOCK)
18879 as_warn (_("file finished with an open IT block."));
18880#endif
18881}
18882
c19d1205
ZW
18883/* Various frobbings of labels and their addresses. */
18884
18885void
18886arm_start_line_hook (void)
18887{
18888 last_label_seen = NULL;
b99bd4ef
NC
18889}
18890
c19d1205
ZW
18891void
18892arm_frob_label (symbolS * sym)
b99bd4ef 18893{
c19d1205 18894 last_label_seen = sym;
b99bd4ef 18895
c19d1205 18896 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18897
c19d1205
ZW
18898#if defined OBJ_COFF || defined OBJ_ELF
18899 ARM_SET_INTERWORK (sym, support_interwork);
18900#endif
b99bd4ef 18901
e07e6e58
NC
18902 force_automatic_it_block_close ();
18903
5f4273c7 18904 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18905 as Thumb functions. This is because these labels, whilst
18906 they exist inside Thumb code, are not the entry points for
18907 possible ARM->Thumb calls. Also, these labels can be used
18908 as part of a computed goto or switch statement. eg gcc
18909 can generate code that looks like this:
b99bd4ef 18910
c19d1205
ZW
18911 ldr r2, [pc, .Laaa]
18912 lsl r3, r3, #2
18913 ldr r2, [r3, r2]
18914 mov pc, r2
b99bd4ef 18915
c19d1205
ZW
18916 .Lbbb: .word .Lxxx
18917 .Lccc: .word .Lyyy
18918 ..etc...
18919 .Laaa: .word Lbbb
b99bd4ef 18920
c19d1205
ZW
18921 The first instruction loads the address of the jump table.
18922 The second instruction converts a table index into a byte offset.
18923 The third instruction gets the jump address out of the table.
18924 The fourth instruction performs the jump.
b99bd4ef 18925
c19d1205
ZW
18926 If the address stored at .Laaa is that of a symbol which has the
18927 Thumb_Func bit set, then the linker will arrange for this address
18928 to have the bottom bit set, which in turn would mean that the
18929 address computation performed by the third instruction would end
18930 up with the bottom bit set. Since the ARM is capable of unaligned
18931 word loads, the instruction would then load the incorrect address
18932 out of the jump table, and chaos would ensue. */
18933 if (label_is_thumb_function_name
18934 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18935 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18936 {
c19d1205
ZW
18937 /* When the address of a Thumb function is taken the bottom
18938 bit of that address should be set. This will allow
18939 interworking between Arm and Thumb functions to work
18940 correctly. */
b99bd4ef 18941
c19d1205 18942 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18943
c19d1205 18944 label_is_thumb_function_name = FALSE;
b99bd4ef 18945 }
07a53e5c 18946
07a53e5c 18947 dwarf2_emit_label (sym);
b99bd4ef
NC
18948}
18949
c921be7d 18950bfd_boolean
c19d1205 18951arm_data_in_code (void)
b99bd4ef 18952{
c19d1205 18953 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18954 {
c19d1205
ZW
18955 *input_line_pointer = '/';
18956 input_line_pointer += 5;
18957 *input_line_pointer = 0;
c921be7d 18958 return TRUE;
b99bd4ef
NC
18959 }
18960
c921be7d 18961 return FALSE;
b99bd4ef
NC
18962}
18963
c19d1205
ZW
18964char *
18965arm_canonicalize_symbol_name (char * name)
b99bd4ef 18966{
c19d1205 18967 int len;
b99bd4ef 18968
c19d1205
ZW
18969 if (thumb_mode && (len = strlen (name)) > 5
18970 && streq (name + len - 5, "/data"))
18971 *(name + len - 5) = 0;
b99bd4ef 18972
c19d1205 18973 return name;
b99bd4ef 18974}
c19d1205
ZW
18975\f
18976/* Table of all register names defined by default. The user can
18977 define additional names with .req. Note that all register names
18978 should appear in both upper and lowercase variants. Some registers
18979 also have mixed-case names. */
b99bd4ef 18980
dcbf9037 18981#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18982#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18983#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18984#define REGSET(p,t) \
18985 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18986 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18987 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18988 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18989#define REGSETH(p,t) \
18990 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18991 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18992 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18993 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18994#define REGSET2(p,t) \
18995 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18996 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18997 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18998 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18999#define SPLRBANK(base,bank,t) \
19000 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19001 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19002 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19003 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19004 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19005 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19006
c19d1205 19007static const struct reg_entry reg_names[] =
7ed4c4c5 19008{
c19d1205
ZW
19009 /* ARM integer registers. */
19010 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19011
c19d1205
ZW
19012 /* ATPCS synonyms. */
19013 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19014 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19015 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19016
c19d1205
ZW
19017 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19018 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19019 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19020
c19d1205
ZW
19021 /* Well-known aliases. */
19022 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19023 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19024
19025 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19026 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19027
19028 /* Coprocessor numbers. */
19029 REGSET(p, CP), REGSET(P, CP),
19030
19031 /* Coprocessor register numbers. The "cr" variants are for backward
19032 compatibility. */
19033 REGSET(c, CN), REGSET(C, CN),
19034 REGSET(cr, CN), REGSET(CR, CN),
19035
90ec0d68
MGD
19036 /* ARM banked registers. */
19037 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19038 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19039 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19040 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19041 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19042 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19043 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19044
19045 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19046 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19047 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19048 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19049 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19050 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19051 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19052 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19053
19054 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19055 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19056 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19057 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19058 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19059 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19060 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19061 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19062 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19063
c19d1205
ZW
19064 /* FPA registers. */
19065 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19066 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19067
19068 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19069 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19070
19071 /* VFP SP registers. */
5287ad62
JB
19072 REGSET(s,VFS), REGSET(S,VFS),
19073 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19074
19075 /* VFP DP Registers. */
5287ad62
JB
19076 REGSET(d,VFD), REGSET(D,VFD),
19077 /* Extra Neon DP registers. */
19078 REGSETH(d,VFD), REGSETH(D,VFD),
19079
19080 /* Neon QP registers. */
19081 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19082
19083 /* VFP control registers. */
19084 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19085 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19086 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19087 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19088 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19089 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19090 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19091
19092 /* Maverick DSP coprocessor registers. */
19093 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19094 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19095
19096 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19097 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19098 REGDEF(dspsc,0,DSPSC),
19099
19100 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19101 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19102 REGDEF(DSPSC,0,DSPSC),
19103
19104 /* iWMMXt data registers - p0, c0-15. */
19105 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19106
19107 /* iWMMXt control registers - p1, c0-3. */
19108 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19109 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19110 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19111 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19112
19113 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19114 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19115 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19116 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19117 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19118
19119 /* XScale accumulator registers. */
19120 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19121};
19122#undef REGDEF
19123#undef REGNUM
19124#undef REGSET
7ed4c4c5 19125
c19d1205
ZW
19126/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19127 within psr_required_here. */
19128static const struct asm_psr psrs[] =
19129{
19130 /* Backward compatibility notation. Note that "all" is no longer
19131 truly all possible PSR bits. */
19132 {"all", PSR_c | PSR_f},
19133 {"flg", PSR_f},
19134 {"ctl", PSR_c},
19135
19136 /* Individual flags. */
19137 {"f", PSR_f},
19138 {"c", PSR_c},
19139 {"x", PSR_x},
19140 {"s", PSR_s},
59b42a0d 19141
c19d1205
ZW
19142 /* Combinations of flags. */
19143 {"fs", PSR_f | PSR_s},
19144 {"fx", PSR_f | PSR_x},
19145 {"fc", PSR_f | PSR_c},
19146 {"sf", PSR_s | PSR_f},
19147 {"sx", PSR_s | PSR_x},
19148 {"sc", PSR_s | PSR_c},
19149 {"xf", PSR_x | PSR_f},
19150 {"xs", PSR_x | PSR_s},
19151 {"xc", PSR_x | PSR_c},
19152 {"cf", PSR_c | PSR_f},
19153 {"cs", PSR_c | PSR_s},
19154 {"cx", PSR_c | PSR_x},
19155 {"fsx", PSR_f | PSR_s | PSR_x},
19156 {"fsc", PSR_f | PSR_s | PSR_c},
19157 {"fxs", PSR_f | PSR_x | PSR_s},
19158 {"fxc", PSR_f | PSR_x | PSR_c},
19159 {"fcs", PSR_f | PSR_c | PSR_s},
19160 {"fcx", PSR_f | PSR_c | PSR_x},
19161 {"sfx", PSR_s | PSR_f | PSR_x},
19162 {"sfc", PSR_s | PSR_f | PSR_c},
19163 {"sxf", PSR_s | PSR_x | PSR_f},
19164 {"sxc", PSR_s | PSR_x | PSR_c},
19165 {"scf", PSR_s | PSR_c | PSR_f},
19166 {"scx", PSR_s | PSR_c | PSR_x},
19167 {"xfs", PSR_x | PSR_f | PSR_s},
19168 {"xfc", PSR_x | PSR_f | PSR_c},
19169 {"xsf", PSR_x | PSR_s | PSR_f},
19170 {"xsc", PSR_x | PSR_s | PSR_c},
19171 {"xcf", PSR_x | PSR_c | PSR_f},
19172 {"xcs", PSR_x | PSR_c | PSR_s},
19173 {"cfs", PSR_c | PSR_f | PSR_s},
19174 {"cfx", PSR_c | PSR_f | PSR_x},
19175 {"csf", PSR_c | PSR_s | PSR_f},
19176 {"csx", PSR_c | PSR_s | PSR_x},
19177 {"cxf", PSR_c | PSR_x | PSR_f},
19178 {"cxs", PSR_c | PSR_x | PSR_s},
19179 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19180 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19181 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19182 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19183 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19184 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19185 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19186 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19187 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19188 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19189 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19190 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19191 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19192 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19193 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19194 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19195 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19196 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19197 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19198 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19199 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19200 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19201 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19202 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19203};
19204
62b3e311
PB
19205/* Table of V7M psr names. */
19206static const struct asm_psr v7m_psrs[] =
19207{
1a336194
TP
19208 {"apsr", 0x0 }, {"APSR", 0x0 },
19209 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19210 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19211 {"psr", 0x3 }, {"PSR", 0x3 },
19212 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19213 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19214 {"epsr", 0x6 }, {"EPSR", 0x6 },
19215 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19216 {"msp", 0x8 }, {"MSP", 0x8 },
19217 {"psp", 0x9 }, {"PSP", 0x9 },
19218 {"msplim", 0xa }, {"MSPLIM", 0xa },
19219 {"psplim", 0xb }, {"PSPLIM", 0xb },
19220 {"primask", 0x10}, {"PRIMASK", 0x10},
19221 {"basepri", 0x11}, {"BASEPRI", 0x11},
19222 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19223 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19224 {"control", 0x14}, {"CONTROL", 0x14},
19225 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19226 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19227 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19228 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19229 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19230 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19231 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19232 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19233 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19234};
19235
c19d1205
ZW
19236/* Table of all shift-in-operand names. */
19237static const struct asm_shift_name shift_names [] =
b99bd4ef 19238{
c19d1205
ZW
19239 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19240 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19241 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19242 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19243 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19244 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19245};
b99bd4ef 19246
c19d1205
ZW
19247/* Table of all explicit relocation names. */
19248#ifdef OBJ_ELF
19249static struct reloc_entry reloc_names[] =
19250{
19251 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19252 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19253 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19254 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19255 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19256 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19257 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19258 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19259 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19260 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19261 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19262 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19263 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19264 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19265 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19266 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19267 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19268 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19269};
19270#endif
b99bd4ef 19271
c19d1205
ZW
19272/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19273static const struct asm_cond conds[] =
19274{
19275 {"eq", 0x0},
19276 {"ne", 0x1},
19277 {"cs", 0x2}, {"hs", 0x2},
19278 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19279 {"mi", 0x4},
19280 {"pl", 0x5},
19281 {"vs", 0x6},
19282 {"vc", 0x7},
19283 {"hi", 0x8},
19284 {"ls", 0x9},
19285 {"ge", 0xa},
19286 {"lt", 0xb},
19287 {"gt", 0xc},
19288 {"le", 0xd},
19289 {"al", 0xe}
19290};
bfae80f2 19291
e797f7e0 19292#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19293 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19294 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19295
62b3e311
PB
19296static struct asm_barrier_opt barrier_opt_names[] =
19297{
e797f7e0
MGD
19298 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19299 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19300 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19301 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19302 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19303 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19304 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19305 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19306 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19307 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19308 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19309 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19310 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19311 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19312 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19313 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19314};
19315
e797f7e0
MGD
19316#undef UL_BARRIER
19317
c19d1205
ZW
19318/* Table of ARM-format instructions. */
19319
19320/* Macros for gluing together operand strings. N.B. In all cases
19321 other than OPS0, the trailing OP_stop comes from default
19322 zero-initialization of the unspecified elements of the array. */
19323#define OPS0() { OP_stop, }
19324#define OPS1(a) { OP_##a, }
19325#define OPS2(a,b) { OP_##a,OP_##b, }
19326#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19327#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19328#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19329#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19330
5be8be5d
DG
19331/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19332 This is useful when mixing operands for ARM and THUMB, i.e. using the
19333 MIX_ARM_THUMB_OPERANDS macro.
19334 In order to use these macros, prefix the number of operands with _
19335 e.g. _3. */
19336#define OPS_1(a) { a, }
19337#define OPS_2(a,b) { a,b, }
19338#define OPS_3(a,b,c) { a,b,c, }
19339#define OPS_4(a,b,c,d) { a,b,c,d, }
19340#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19341#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19342
c19d1205
ZW
19343/* These macros abstract out the exact format of the mnemonic table and
19344 save some repeated characters. */
19345
19346/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19347#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19348 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19349 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19350
19351/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19352 a T_MNEM_xyz enumerator. */
19353#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19354 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19355#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19356 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19357
19358/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19359 infix after the third character. */
19360#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19361 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19362 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19363#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19364 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19365 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19366#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19367 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19368#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19369 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19370#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19371 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19372#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19373 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19374
c19d1205 19375/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19376 field is still 0xE. Many of the Thumb variants can be executed
19377 conditionally, so this is checked separately. */
c19d1205 19378#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19379 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19380 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19381
dd5181d5
KT
19382/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19383 Used by mnemonics that have very minimal differences in the encoding for
19384 ARM and Thumb variants and can be handled in a common function. */
19385#define TUEc(mnem, op, top, nops, ops, en) \
19386 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19387 THUMB_VARIANT, do_##en, do_##en }
19388
c19d1205
ZW
19389/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19390 condition code field. */
19391#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19392 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19393 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19394
19395/* ARM-only variants of all the above. */
6a86118a 19396#define CE(mnem, op, nops, ops, ae) \
21d799b5 19397 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19398
19399#define C3(mnem, op, nops, ops, ae) \
19400 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19401
e3cb604e
PB
19402/* Legacy mnemonics that always have conditional infix after the third
19403 character. */
19404#define CL(mnem, op, nops, ops, ae) \
21d799b5 19405 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19406 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19407
8f06b2d8
PB
19408/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19409#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19410 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19411
e3cb604e
PB
19412/* Legacy coprocessor instructions where conditional infix and conditional
19413 suffix are ambiguous. For consistency this includes all FPA instructions,
19414 not just the potentially ambiguous ones. */
19415#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19416 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19417 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19418
19419/* Coprocessor, takes either a suffix or a position-3 infix
19420 (for an FPA corner case). */
19421#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19422 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19423 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19424
6a86118a 19425#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19426 { m1 #m2 m3, OPS##nops ops, \
19427 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19428 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19429
19430#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19431 xCM_ (m1, , m2, op, nops, ops, ae), \
19432 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19433 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19434 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19435 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19436 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19437 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19438 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19439 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19440 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19441 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19442 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19443 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19444 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19445 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19446 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19447 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19448 xCM_ (m1, le, m2, op, nops, ops, ae), \
19449 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19450
19451#define UE(mnem, op, nops, ops, ae) \
19452 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19453
19454#define UF(mnem, op, nops, ops, ae) \
19455 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19456
5287ad62
JB
19457/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19458 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19459 use the same encoding function for each. */
19460#define NUF(mnem, op, nops, ops, enc) \
19461 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19462 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19463
19464/* Neon data processing, version which indirects through neon_enc_tab for
19465 the various overloaded versions of opcodes. */
19466#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19467 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19468 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19469
19470/* Neon insn with conditional suffix for the ARM version, non-overloaded
19471 version. */
037e8744
JB
19472#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19473 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19474 THUMB_VARIANT, do_##enc, do_##enc }
19475
037e8744 19476#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19477 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19478
19479#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19480 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19481
5287ad62 19482/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19483#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19484 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19485 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19486
037e8744 19487#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19488 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19489
19490#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19491 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19492
c19d1205
ZW
19493#define do_0 0
19494
c19d1205 19495static const struct asm_opcode insns[] =
bfae80f2 19496{
74db7efb
NC
19497#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19498#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19499 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19500 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19501 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19502 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19503 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19504 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19505 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19506 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19507 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19508 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19509 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19510 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19511 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19512 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19513 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19514 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19515
19516 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19517 for setting PSR flag bits. They are obsolete in V6 and do not
19518 have Thumb equivalents. */
21d799b5
NC
19519 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19520 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19521 CL("tstp", 110f000, 2, (RR, SH), cmp),
19522 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19523 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19524 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19525 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19526 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19527 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19528
19529 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19530 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19531 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19532 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19533
19534 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19535 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19536 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19537 OP_RRnpc),
19538 OP_ADDRGLDR),ldst, t_ldst),
19539 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19540
19541 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19542 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19543 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19544 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19545 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19546 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19547
21d799b5
NC
19548 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19549 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19550
c19d1205 19551 /* Pseudo ops. */
21d799b5 19552 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19553 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19554 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19555 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19556
19557 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19558 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19559 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19560 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19561 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19562 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19563 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19564 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19565 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19566 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19567 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19568 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19569 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19570
16a4cf17 19571 /* These may simplify to neg. */
21d799b5
NC
19572 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19573 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19574
173205ca
TP
19575#undef THUMB_VARIANT
19576#define THUMB_VARIANT & arm_ext_os
19577
19578 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19579 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19580
c921be7d
NC
19581#undef THUMB_VARIANT
19582#define THUMB_VARIANT & arm_ext_v6
19583
21d799b5 19584 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19585
19586 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19587#undef THUMB_VARIANT
19588#define THUMB_VARIANT & arm_ext_v6t2
19589
21d799b5
NC
19590 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19591 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19592 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19593
5be8be5d
DG
19594 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19595 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19596 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19597 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19598
21d799b5
NC
19599 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19600 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19601
21d799b5
NC
19602 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19603 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19604
19605 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19606 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19607 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19608
19609 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19610 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19611 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19612 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19613 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19614 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19615 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19616 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19617
c921be7d
NC
19618#undef ARM_VARIANT
19619#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19620#undef THUMB_VARIANT
19621#define THUMB_VARIANT & arm_ext_v4t
19622
21d799b5
NC
19623 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19624 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19625
c921be7d
NC
19626#undef THUMB_VARIANT
19627#define THUMB_VARIANT & arm_ext_v6t2
19628
21d799b5 19629 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19630 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19631
19632 /* Generic coprocessor instructions. */
21d799b5
NC
19633 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19634 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19635 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19636 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19637 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19638 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19639 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19640
c921be7d
NC
19641#undef ARM_VARIANT
19642#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19643
21d799b5 19644 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19645 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19646
c921be7d
NC
19647#undef ARM_VARIANT
19648#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19649#undef THUMB_VARIANT
19650#define THUMB_VARIANT & arm_ext_msr
19651
d2cd1205
JB
19652 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19653 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19654
c921be7d
NC
19655#undef ARM_VARIANT
19656#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19657#undef THUMB_VARIANT
19658#define THUMB_VARIANT & arm_ext_v6t2
19659
21d799b5
NC
19660 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19661 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19662 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19663 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19664 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19665 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19666 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19667 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19668
c921be7d
NC
19669#undef ARM_VARIANT
19670#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19671#undef THUMB_VARIANT
19672#define THUMB_VARIANT & arm_ext_v4t
19673
5be8be5d
DG
19674 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19675 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19676 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19677 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19678 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19679 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19680
c921be7d
NC
19681#undef ARM_VARIANT
19682#define ARM_VARIANT & arm_ext_v4t_5
19683
c19d1205
ZW
19684 /* ARM Architecture 4T. */
19685 /* Note: bx (and blx) are required on V5, even if the processor does
19686 not support Thumb. */
21d799b5 19687 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19688
c921be7d
NC
19689#undef ARM_VARIANT
19690#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19691#undef THUMB_VARIANT
19692#define THUMB_VARIANT & arm_ext_v5t
19693
c19d1205
ZW
19694 /* Note: blx has 2 variants; the .value coded here is for
19695 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19696 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19697 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19698
c921be7d
NC
19699#undef THUMB_VARIANT
19700#define THUMB_VARIANT & arm_ext_v6t2
19701
21d799b5
NC
19702 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19703 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19704 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19705 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19706 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19707 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19708 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19709 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19710
c921be7d 19711#undef ARM_VARIANT
74db7efb
NC
19712#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19713#undef THUMB_VARIANT
19714#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19715
21d799b5
NC
19716 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19717 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19718 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19719 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19720
21d799b5
NC
19721 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19722 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19723
21d799b5
NC
19724 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19725 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19726 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19727 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19728
21d799b5
NC
19729 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19730 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19731 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19732 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19733
21d799b5
NC
19734 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19735 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19736
03ee1b7f
NC
19737 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19738 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19739 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19740 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19741
c921be7d 19742#undef ARM_VARIANT
74db7efb
NC
19743#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19744#undef THUMB_VARIANT
19745#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19746
21d799b5 19747 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19748 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19749 ldrd, t_ldstd),
19750 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19751 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19752
21d799b5
NC
19753 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19754 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19755
c921be7d
NC
19756#undef ARM_VARIANT
19757#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19758
21d799b5 19759 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19760
c921be7d
NC
19761#undef ARM_VARIANT
19762#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19763#undef THUMB_VARIANT
19764#define THUMB_VARIANT & arm_ext_v6
19765
21d799b5
NC
19766 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19767 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19768 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19769 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19770 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19771 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19772 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19773 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19774 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19775 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19776
c921be7d 19777#undef THUMB_VARIANT
ff8646ee 19778#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19779
5be8be5d
DG
19780 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19781 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19782 strex, t_strex),
ff8646ee
TP
19783#undef THUMB_VARIANT
19784#define THUMB_VARIANT & arm_ext_v6t2
19785
21d799b5
NC
19786 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19787 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19788
21d799b5
NC
19789 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19790 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19791
9e3c6df6 19792/* ARM V6 not included in V7M. */
c921be7d
NC
19793#undef THUMB_VARIANT
19794#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19795 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19796 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19797 UF(rfeib, 9900a00, 1, (RRw), rfe),
19798 UF(rfeda, 8100a00, 1, (RRw), rfe),
19799 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19800 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19801 UF(rfefa, 8100a00, 1, (RRw), rfe),
19802 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19803 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19804 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19805 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19806 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19807 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19808 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19809 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19810 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19811 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19812 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19813 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19814
9e3c6df6
PB
19815/* ARM V6 not included in V7M (eg. integer SIMD). */
19816#undef THUMB_VARIANT
19817#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19818 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19819 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19820 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19821 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19822 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19823 /* Old name for QASX. */
74db7efb 19824 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19825 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19826 /* Old name for QSAX. */
74db7efb 19827 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19828 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19829 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19830 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19831 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19832 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19833 /* Old name for SASX. */
74db7efb 19834 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19835 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19836 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19837 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19838 /* Old name for SHASX. */
21d799b5 19839 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19840 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19841 /* Old name for SHSAX. */
21d799b5
NC
19842 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19843 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19844 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19845 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19846 /* Old name for SSAX. */
74db7efb 19847 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19848 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19849 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19850 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19851 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19852 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19853 /* Old name for UASX. */
74db7efb 19854 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19855 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19856 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19857 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19858 /* Old name for UHASX. */
21d799b5
NC
19859 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19860 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19861 /* Old name for UHSAX. */
21d799b5
NC
19862 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19863 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19864 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19865 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19866 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19867 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19868 /* Old name for UQASX. */
21d799b5
NC
19869 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19870 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19871 /* Old name for UQSAX. */
21d799b5
NC
19872 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19873 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19874 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19875 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19876 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19877 /* Old name for USAX. */
74db7efb 19878 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19879 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19880 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19881 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19882 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19883 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19884 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19885 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19886 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19887 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19888 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19889 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19890 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19891 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19892 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19893 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19894 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19895 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19896 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19897 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19898 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19899 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19900 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19901 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19902 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19903 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19904 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19905 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19906 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19907 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19908 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19909 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19910 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19911 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19912
c921be7d
NC
19913#undef ARM_VARIANT
19914#define ARM_VARIANT & arm_ext_v6k
19915#undef THUMB_VARIANT
19916#define THUMB_VARIANT & arm_ext_v6k
19917
21d799b5
NC
19918 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19919 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19920 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19921 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19922
c921be7d
NC
19923#undef THUMB_VARIANT
19924#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19925 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19926 ldrexd, t_ldrexd),
19927 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19928 RRnpcb), strexd, t_strexd),
ebdca51a 19929
c921be7d 19930#undef THUMB_VARIANT
ff8646ee 19931#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19932 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19933 rd_rn, rd_rn),
19934 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19935 rd_rn, rd_rn),
19936 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19937 strex, t_strexbh),
5be8be5d 19938 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19939 strex, t_strexbh),
21d799b5 19940 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19941
c921be7d 19942#undef ARM_VARIANT
f4c65163 19943#define ARM_VARIANT & arm_ext_sec
74db7efb 19944#undef THUMB_VARIANT
f4c65163 19945#define THUMB_VARIANT & arm_ext_sec
c921be7d 19946
21d799b5 19947 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19948
90ec0d68
MGD
19949#undef ARM_VARIANT
19950#define ARM_VARIANT & arm_ext_virt
19951#undef THUMB_VARIANT
19952#define THUMB_VARIANT & arm_ext_virt
19953
19954 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19955 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19956
ddfded2f
MW
19957#undef ARM_VARIANT
19958#define ARM_VARIANT & arm_ext_pan
19959#undef THUMB_VARIANT
19960#define THUMB_VARIANT & arm_ext_pan
19961
19962 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19963
c921be7d 19964#undef ARM_VARIANT
74db7efb 19965#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19966#undef THUMB_VARIANT
19967#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19968
21d799b5
NC
19969 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19970 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19971 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19972 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19973
21d799b5 19974 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19975 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19976
5be8be5d
DG
19977 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19978 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19979 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19980 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19981
ff8646ee
TP
19982#undef THUMB_VARIANT
19983#define THUMB_VARIANT & arm_ext_v6t2_v8m
19984 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19985 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19986
bf3eeda7 19987 /* Thumb-only instructions. */
74db7efb 19988#undef ARM_VARIANT
bf3eeda7
NS
19989#define ARM_VARIANT NULL
19990 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19991 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19992
19993 /* ARM does not really have an IT instruction, so always allow it.
19994 The opcode is copied from Thumb in order to allow warnings in
19995 -mimplicit-it=[never | arm] modes. */
19996#undef ARM_VARIANT
19997#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19998#undef THUMB_VARIANT
19999#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20000
21d799b5
NC
20001 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20002 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20003 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20004 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20005 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20006 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20007 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20008 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20009 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20010 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20011 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20012 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20013 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20014 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20015 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20016 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20017 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20018 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20019
92e90b6e 20020 /* Thumb2 only instructions. */
c921be7d
NC
20021#undef ARM_VARIANT
20022#define ARM_VARIANT NULL
92e90b6e 20023
21d799b5
NC
20024 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20025 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20026 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20027 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20028 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20029 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20030
eea54501
MGD
20031 /* Hardware division instructions. */
20032#undef ARM_VARIANT
20033#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20034#undef THUMB_VARIANT
20035#define THUMB_VARIANT & arm_ext_div
20036
eea54501
MGD
20037 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20038 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20039
7e806470 20040 /* ARM V6M/V7 instructions. */
c921be7d
NC
20041#undef ARM_VARIANT
20042#define ARM_VARIANT & arm_ext_barrier
20043#undef THUMB_VARIANT
20044#define THUMB_VARIANT & arm_ext_barrier
20045
ccb84d65
JB
20046 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20047 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20048 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20049
62b3e311 20050 /* ARM V7 instructions. */
c921be7d
NC
20051#undef ARM_VARIANT
20052#define ARM_VARIANT & arm_ext_v7
20053#undef THUMB_VARIANT
20054#define THUMB_VARIANT & arm_ext_v7
20055
21d799b5
NC
20056 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20057 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20058
74db7efb 20059#undef ARM_VARIANT
60e5ef9f 20060#define ARM_VARIANT & arm_ext_mp
74db7efb 20061#undef THUMB_VARIANT
60e5ef9f
MGD
20062#define THUMB_VARIANT & arm_ext_mp
20063
20064 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20065
53c4b28b
MGD
20066 /* AArchv8 instructions. */
20067#undef ARM_VARIANT
20068#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20069
20070/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20071#undef THUMB_VARIANT
4ed7ed8d 20072#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20073
4ed7ed8d
TP
20074 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20075 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20076 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20077 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20078 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20079 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20080 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20081 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20082 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20083 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20084 stlex, t_stlex),
4b8c8c02
RE
20085 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20086 stlex, t_stlex),
20087 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20088 stlex, t_stlex),
4ed7ed8d
TP
20089#undef THUMB_VARIANT
20090#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20091
4ed7ed8d
TP
20092 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20093 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20094 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20095 ldrexd, t_ldrexd),
20096 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20097 strexd, t_strexd),
8884b720 20098 /* ARMv8 T32 only. */
74db7efb 20099#undef ARM_VARIANT
b79f7053
MGD
20100#define ARM_VARIANT NULL
20101 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20102 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20103 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20104
33399f07
MGD
20105 /* FP for ARMv8. */
20106#undef ARM_VARIANT
a715796b 20107#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20108#undef THUMB_VARIANT
a715796b 20109#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20110
20111 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20112 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20113 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20114 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20115 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20116 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20117 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20118 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20119 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20120 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20121 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20122 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20123 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20124 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20125 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20126 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20127 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20128
91ff7894
MGD
20129 /* Crypto v1 extensions. */
20130#undef ARM_VARIANT
20131#define ARM_VARIANT & fpu_crypto_ext_armv8
20132#undef THUMB_VARIANT
20133#define THUMB_VARIANT & fpu_crypto_ext_armv8
20134
20135 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20136 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20137 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20138 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20139 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20140 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20141 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20142 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20143 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20144 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20145 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20146 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20147 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20148 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20149
dd5181d5 20150#undef ARM_VARIANT
74db7efb 20151#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20152#undef THUMB_VARIANT
20153#define THUMB_VARIANT & crc_ext_armv8
20154 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20155 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20156 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20157 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20158 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20159 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20160
105bde57
MW
20161 /* ARMv8.2 RAS extension. */
20162#undef ARM_VARIANT
4d1464f2 20163#define ARM_VARIANT & arm_ext_ras
105bde57 20164#undef THUMB_VARIANT
4d1464f2 20165#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20166 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20167
49e8a725
SN
20168#undef ARM_VARIANT
20169#define ARM_VARIANT & arm_ext_v8_3
20170#undef THUMB_VARIANT
20171#define THUMB_VARIANT & arm_ext_v8_3
20172 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20173 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20174 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20175
c604a79a
JW
20176#undef ARM_VARIANT
20177#define ARM_VARIANT & fpu_neon_ext_dotprod
20178#undef THUMB_VARIANT
20179#define THUMB_VARIANT & fpu_neon_ext_dotprod
20180 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20181 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20182
c921be7d
NC
20183#undef ARM_VARIANT
20184#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20185#undef THUMB_VARIANT
20186#define THUMB_VARIANT NULL
c921be7d 20187
21d799b5
NC
20188 cCE("wfs", e200110, 1, (RR), rd),
20189 cCE("rfs", e300110, 1, (RR), rd),
20190 cCE("wfc", e400110, 1, (RR), rd),
20191 cCE("rfc", e500110, 1, (RR), rd),
20192
20193 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20194 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20195 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20196 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20197
20198 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20199 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20200 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20201 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20202
20203 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20204 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20205 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20206 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20207 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20208 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20209 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20210 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20211 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20212 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20213 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20214 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20215
20216 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20217 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20218 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20219 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20220 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20221 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20222 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20223 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20224 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20225 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20226 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20227 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20228
20229 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20230 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20231 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20232 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20233 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20234 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20235 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20236 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20237 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20238 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20239 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20240 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20241
20242 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20243 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20244 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20245 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20246 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20247 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20248 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20249 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20250 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20251 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20252 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20253 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20254
20255 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20256 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20257 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20258 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20259 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20260 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20261 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20262 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20263 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20264 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20265 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20266 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20267
20268 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20269 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20270 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20271 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20272 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20273 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20274 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20275 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20276 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20277 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20278 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20279 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20280
20281 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20282 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20283 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20284 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20285 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20286 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20287 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20288 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20289 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20290 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20291 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20292 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20293
20294 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20295 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20296 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20297 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20298 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20299 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20300 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20301 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20302 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20303 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20304 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20305 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20306
20307 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20308 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20309 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20310 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20311 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20312 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20313 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20314 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20315 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20316 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20317 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20318 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20319
20320 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20321 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20322 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20323 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20324 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20325 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20326 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20327 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20328 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20329 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20330 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20331 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20332
20333 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20334 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20335 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20336 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20337 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20338 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20339 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20340 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20341 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20342 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20343 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20344 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20345
20346 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20347 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20348 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20349 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20350 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20351 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20352 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20353 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20354 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20355 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20356 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20357 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20358
20359 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20360 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20361 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20362 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20363 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20364 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20365 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20366 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20367 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20368 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20369 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20370 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20371
20372 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20373 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20374 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20375 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20376 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20377 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20378 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20379 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20380 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20381 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20382 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20383 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20384
20385 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20386 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20387 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20388 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20389 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20390 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20391 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20392 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20393 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20394 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20395 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20396 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20397
20398 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20399 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20400 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20401 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20402 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20403 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20404 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20405 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20406 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20407 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20408 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20409 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20410
20411 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20412 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20413 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20414 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20415 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20416 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20417 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20418 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20419 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20420 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20421 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20422 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20423
20424 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20425 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20426 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20427 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20428 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20429 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20430 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20431 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20432 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20433 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20434 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20435 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20436
20437 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20438 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20439 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20440 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20441 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20442 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20443 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20444 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20445 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20446 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20447 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20448 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20449
20450 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20451 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20452 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20453 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20454 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20455 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20456 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20457 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20458 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20459 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20460 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20461 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20462
20463 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20464 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20465 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20466 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20467 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20468 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20469 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20470 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20471 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20472 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20473 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20474 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20475
20476 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20477 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20478 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20479 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20480 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20481 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20482 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20483 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20484 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20485 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20486 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20487 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20488
20489 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20490 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20491 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20492 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20493 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20494 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20495 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20496 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20497 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20498 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20499 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20500 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20501
20502 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20503 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20504 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20505 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20506 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20507 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20508 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20509 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20510 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20511 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20512 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20513 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20514
20515 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20516 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20517 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20518 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20519 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20520 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20522 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20523 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20524 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20525 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20527
20528 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20531 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20532 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20533 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20535 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20536 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20537 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20538 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20540
20541 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20544 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20545 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20546 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20548 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20549 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20550 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20551 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20553
20554 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20557 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20558 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20559 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20561 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20562 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20563 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20564 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20566
20567 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20570 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20571 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20572 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20574 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20575 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20576 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20577 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20579
20580 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20581 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20582 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20583 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20584
20585 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20586 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20587 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20588 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20589 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20590 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20591 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20592 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20593 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20594 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20595 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20596 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20597
c19d1205
ZW
20598 /* The implementation of the FIX instruction is broken on some
20599 assemblers, in that it accepts a precision specifier as well as a
20600 rounding specifier, despite the fact that this is meaningless.
20601 To be more compatible, we accept it as well, though of course it
20602 does not set any bits. */
21d799b5
NC
20603 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20604 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20605 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20606 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20607 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20608 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20609 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20610 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20611 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20612 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20613 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20614 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20615 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20616
c19d1205 20617 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20618#undef ARM_VARIANT
20619#define ARM_VARIANT & fpu_fpa_ext_v2
20620
21d799b5
NC
20621 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20622 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20623 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20624 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20625 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20626 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20627
c921be7d
NC
20628#undef ARM_VARIANT
20629#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20630
c19d1205 20631 /* Moves and type conversions. */
21d799b5
NC
20632 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20633 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20634 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20635 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20636 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20637 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20638 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20639 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20640 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20641 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20642 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20643 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20644 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20645 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20646
20647 /* Memory operations. */
21d799b5
NC
20648 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20649 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20650 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20651 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20652 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20653 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20654 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20655 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20656 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20657 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20658 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20659 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20660 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20661 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20662 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20663 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20664 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20665 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20666
c19d1205 20667 /* Monadic operations. */
21d799b5
NC
20668 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20669 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20670 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20671
20672 /* Dyadic operations. */
21d799b5
NC
20673 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20674 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20675 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20676 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20677 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20678 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20679 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20680 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20681 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20682
c19d1205 20683 /* Comparisons. */
21d799b5
NC
20684 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20685 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20686 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20687 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20688
62f3b8c8
PB
20689 /* Double precision load/store are still present on single precision
20690 implementations. */
20691 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20692 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20693 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20694 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20695 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20696 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20697 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20698 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20699 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20700 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20701
c921be7d
NC
20702#undef ARM_VARIANT
20703#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20704
c19d1205 20705 /* Moves and type conversions. */
21d799b5
NC
20706 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20707 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20708 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20709 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20710 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20711 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20712 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20713 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20714 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20715 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20716 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20717 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20718 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20719
c19d1205 20720 /* Monadic operations. */
21d799b5
NC
20721 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20722 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20723 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20724
20725 /* Dyadic operations. */
21d799b5
NC
20726 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20727 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20728 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20729 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20730 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20731 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20732 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20733 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20734 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20735
c19d1205 20736 /* Comparisons. */
21d799b5
NC
20737 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20738 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20739 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20740 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20741
c921be7d
NC
20742#undef ARM_VARIANT
20743#define ARM_VARIANT & fpu_vfp_ext_v2
20744
21d799b5
NC
20745 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20746 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20747 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20748 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20749
037e8744
JB
20750/* Instructions which may belong to either the Neon or VFP instruction sets.
20751 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20752#undef ARM_VARIANT
20753#define ARM_VARIANT & fpu_vfp_ext_v1xd
20754#undef THUMB_VARIANT
20755#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20756
037e8744
JB
20757 /* These mnemonics are unique to VFP. */
20758 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20759 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20760 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20761 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20762 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20763 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20764 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20765 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20766 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20767 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20768
20769 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20770 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20771 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20772 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20773
21d799b5
NC
20774 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20775 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20776
20777 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20778 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20779
55881a11
MGD
20780 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20781 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20782 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20783 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20784 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20785 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20786 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20787 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20788
5f1af56b 20789 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20790 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20791 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20792 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20793
037e8744
JB
20794
20795 /* NOTE: All VMOV encoding is special-cased! */
20796 NCE(vmov, 0, 1, (VMOV), neon_mov),
20797 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20798
9db2f6b4
RL
20799#undef ARM_VARIANT
20800#define ARM_VARIANT & arm_ext_fp16
20801#undef THUMB_VARIANT
20802#define THUMB_VARIANT & arm_ext_fp16
20803 /* New instructions added from v8.2, allowing the extraction and insertion of
20804 the upper 16 bits of a 32-bit vector register. */
20805 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20806 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20807
dec41383
JW
20808 /* New backported fma/fms instructions optional in v8.2. */
20809 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20810 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20811
c921be7d
NC
20812#undef THUMB_VARIANT
20813#define THUMB_VARIANT & fpu_neon_ext_v1
20814#undef ARM_VARIANT
20815#define ARM_VARIANT & fpu_neon_ext_v1
20816
5287ad62
JB
20817 /* Data processing with three registers of the same length. */
20818 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20819 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20820 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20821 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20822 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20823 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20824 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20825 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20826 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20827 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20828 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20829 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20830 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20831 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20832 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20833 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20834 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20835 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20836 /* If not immediate, fall back to neon_dyadic_i64_su.
20837 shl_imm should accept I8 I16 I32 I64,
20838 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20839 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20840 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20841 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20842 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20843 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20844 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20845 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20846 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20847 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20848 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20849 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20850 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20851 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20852 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20853 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20854 /* Bitfield ops, untyped. */
20855 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20856 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20857 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20858 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20859 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20860 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20861 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20862 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20863 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20864 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20865 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20866 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20867 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20868 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20869 back to neon_dyadic_if_su. */
21d799b5
NC
20870 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20871 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20872 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20873 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20874 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20875 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20876 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20877 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20878 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20879 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20880 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20881 /* As above, D registers only. */
21d799b5
NC
20882 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20883 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20884 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20885 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20886 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20887 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20888 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20889 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20890 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20891 /* vtst takes sizes 8, 16, 32. */
20892 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20893 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20894 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20895 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20896 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20897 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20898 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20899 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20900 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20901 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20902 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20903 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20904 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20905 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20906 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20907 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20908 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20909 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20910 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20911 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20912 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20913 /* ARM v8.1 extension. */
643afb90
MW
20914 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20915 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20916 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20917 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20918
20919 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20920 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20921 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20922
20923 /* Data processing with two registers and a shift amount. */
20924 /* Right shifts, and variants with rounding.
20925 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20926 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20927 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20928 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20929 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20930 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20931 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20932 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20933 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20934 /* Shift and insert. Sizes accepted 8 16 32 64. */
20935 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20936 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20937 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20938 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20939 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20940 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20941 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20942 /* Right shift immediate, saturating & narrowing, with rounding variants.
20943 Types accepted S16 S32 S64 U16 U32 U64. */
20944 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20945 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20946 /* As above, unsigned. Types accepted S16 S32 S64. */
20947 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20948 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20949 /* Right shift narrowing. Types accepted I16 I32 I64. */
20950 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20951 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20952 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20953 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20954 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20955 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20956
4316f0d2
DG
20957 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20958 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20959
20960 /* Data processing, three registers of different lengths. */
20961 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20962 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20963 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20964 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20965 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20966 /* If not scalar, fall back to neon_dyadic_long.
20967 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20968 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20969 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20970 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20971 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20972 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20973 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20974 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20975 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20976 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20977 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20978 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20979 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20980 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20981 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20982 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20983 S16 S32 U16 U32. */
21d799b5 20984 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20985
20986 /* Extract. Size 8. */
3b8d421e
PB
20987 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20988 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20989
20990 /* Two registers, miscellaneous. */
20991 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20992 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20993 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20994 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20995 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20996 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20997 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20998 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20999 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21000 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21001 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21002 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21003 /* VMOVN. Types I16 I32 I64. */
21d799b5 21004 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21005 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21006 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21007 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21008 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21009 /* VZIP / VUZP. Sizes 8 16 32. */
21010 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21011 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21012 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21013 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21014 /* VQABS / VQNEG. Types S8 S16 S32. */
21015 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21016 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21017 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21018 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21019 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21020 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21021 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21022 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21023 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21024 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21025 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21026 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21027 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21028 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21029 /* VCLS. Types S8 S16 S32. */
21030 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21031 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21032 /* VCLZ. Types I8 I16 I32. */
21033 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21034 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21035 /* VCNT. Size 8. */
21036 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21037 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21038 /* Two address, untyped. */
21039 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21040 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21041 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21042 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21043 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21044
21045 /* Table lookup. Size 8. */
21046 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21047 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21048
c921be7d
NC
21049#undef THUMB_VARIANT
21050#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21051#undef ARM_VARIANT
21052#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21053
5287ad62 21054 /* Neon element/structure load/store. */
21d799b5
NC
21055 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21056 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21057 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21058 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21059 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21060 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21061 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21062 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21063
c921be7d 21064#undef THUMB_VARIANT
74db7efb
NC
21065#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21066#undef ARM_VARIANT
21067#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21068 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21069 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21070 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21071 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21072 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21073 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21074 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21075 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21076 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21077
74db7efb 21078#undef THUMB_VARIANT
c921be7d
NC
21079#define THUMB_VARIANT & fpu_vfp_ext_v3
21080#undef ARM_VARIANT
21081#define ARM_VARIANT & fpu_vfp_ext_v3
21082
21d799b5 21083 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21084 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21085 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21086 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21087 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21088 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21089 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21090 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21091 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21092
74db7efb
NC
21093#undef ARM_VARIANT
21094#define ARM_VARIANT & fpu_vfp_ext_fma
21095#undef THUMB_VARIANT
21096#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21097 /* Mnemonics shared by Neon and VFP. These are included in the
21098 VFP FMA variant; NEON and VFP FMA always includes the NEON
21099 FMA instructions. */
21100 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21101 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21102 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21103 the v form should always be used. */
21104 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21105 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21106 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21107 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21108 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21109 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21110
5287ad62 21111#undef THUMB_VARIANT
c921be7d
NC
21112#undef ARM_VARIANT
21113#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21114
21d799b5
NC
21115 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21116 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21117 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21118 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21119 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21120 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21121 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21122 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21123
c921be7d
NC
21124#undef ARM_VARIANT
21125#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21126
21d799b5
NC
21127 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21128 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21129 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21130 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21131 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21132 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21133 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21134 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21135 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21136 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21137 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21138 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21139 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21140 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21141 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21142 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21143 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21144 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21145 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21146 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21147 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21148 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21149 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21150 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21151 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21152 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21153 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21154 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21155 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21156 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21157 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21158 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21159 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21160 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21161 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21162 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21163 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21164 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21165 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21166 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21167 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21168 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21169 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21170 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21171 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21172 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21173 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21174 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21175 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21176 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21177 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21178 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21179 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21180 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21181 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21182 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21183 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21184 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21185 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21186 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21187 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21188 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21189 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21190 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21191 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21192 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21193 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21194 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21195 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21196 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21197 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21198 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21199 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21200 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21201 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21202 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21203 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21204 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21205 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21206 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21207 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21208 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21209 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21210 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21211 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21212 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21213 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21214 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21215 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21216 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21217 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21218 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21219 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21220 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21221 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21222 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21223 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21224 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21225 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21226 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21227 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21228 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21229 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21230 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21231 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21232 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21233 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21234 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21235 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21236 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21237 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21238 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21239 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21240 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21241 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21242 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21243 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21244 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21245 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21246 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21247 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21248 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21249 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21250 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21251 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21252 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21253 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21254 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21255 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21256 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21257 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21258 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21259 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21260 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21261 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21262 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21263 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21264 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21265 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21266 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21267 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21268 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21269 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21270 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21271 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21272 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21273 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21274 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21275 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21276 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21277 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21278 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21279 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21280 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21281 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21282 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21283 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21284 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21285 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21286 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21287 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21288 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21289
c921be7d
NC
21290#undef ARM_VARIANT
21291#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21292
21d799b5
NC
21293 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21294 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21295 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21296 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21297 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21298 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21299 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21300 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21301 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21302 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21303 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21304 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21305 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21306 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21307 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21308 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21309 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21310 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21311 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21312 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21313 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21314 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21315 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21316 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21317 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21318 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21319 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21320 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21321 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21322 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21323 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21324 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21325 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21326 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21327 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21328 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21329 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21330 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21331 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21332 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21333 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21335 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21340 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21341 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21343 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21344 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21345 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21346 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21347 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21348 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21349 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21350
c921be7d
NC
21351#undef ARM_VARIANT
21352#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21353
21d799b5
NC
21354 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21355 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21356 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21357 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21358 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21359 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21360 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21361 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21362 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21363 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21364 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21365 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21366 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21367 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21368 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21369 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21370 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21371 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21372 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21373 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21374 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21375 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21376 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21377 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21378 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21379 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21380 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21381 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21382 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21383 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21384 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21385 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21386 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21387 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21388 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21389 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21390 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21391 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21392 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21393 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21394 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21395 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21396 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21397 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21398 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21399 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21400 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21401 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21402 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21403 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21404 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21405 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21406 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21407 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21408 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21409 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21410 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21411 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21412 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21413 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21414 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21415 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21416 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21417 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21418 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21419 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21420 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21421 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21422 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21423 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21424 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21425 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21426 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21427 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21428 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21429 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21430
16a1fa25 21431 /* ARMv8-M instructions. */
4ed7ed8d
TP
21432#undef ARM_VARIANT
21433#define ARM_VARIANT NULL
21434#undef THUMB_VARIANT
21435#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21436 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21437 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21438 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21439 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21440 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21441 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21442 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21443
21444 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21445 instructions behave as nop if no VFP is present. */
21446#undef THUMB_VARIANT
21447#define THUMB_VARIANT & arm_ext_v8m_main
21448 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21449 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21450};
21451#undef ARM_VARIANT
21452#undef THUMB_VARIANT
21453#undef TCE
c19d1205
ZW
21454#undef TUE
21455#undef TUF
21456#undef TCC
8f06b2d8 21457#undef cCE
e3cb604e
PB
21458#undef cCL
21459#undef C3E
c19d1205
ZW
21460#undef CE
21461#undef CM
21462#undef UE
21463#undef UF
21464#undef UT
5287ad62
JB
21465#undef NUF
21466#undef nUF
21467#undef NCE
21468#undef nCE
c19d1205
ZW
21469#undef OPS0
21470#undef OPS1
21471#undef OPS2
21472#undef OPS3
21473#undef OPS4
21474#undef OPS5
21475#undef OPS6
21476#undef do_0
21477\f
21478/* MD interface: bits in the object file. */
bfae80f2 21479
c19d1205
ZW
21480/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21481 for use in the a.out file, and stores them in the array pointed to by buf.
21482 This knows about the endian-ness of the target machine and does
21483 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21484 2 (short) and 4 (long) Floating numbers are put out as a series of
21485 LITTLENUMS (shorts, here at least). */
b99bd4ef 21486
c19d1205
ZW
21487void
21488md_number_to_chars (char * buf, valueT val, int n)
21489{
21490 if (target_big_endian)
21491 number_to_chars_bigendian (buf, val, n);
21492 else
21493 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21494}
21495
c19d1205
ZW
21496static valueT
21497md_chars_to_number (char * buf, int n)
bfae80f2 21498{
c19d1205
ZW
21499 valueT result = 0;
21500 unsigned char * where = (unsigned char *) buf;
bfae80f2 21501
c19d1205 21502 if (target_big_endian)
b99bd4ef 21503 {
c19d1205
ZW
21504 while (n--)
21505 {
21506 result <<= 8;
21507 result |= (*where++ & 255);
21508 }
b99bd4ef 21509 }
c19d1205 21510 else
b99bd4ef 21511 {
c19d1205
ZW
21512 while (n--)
21513 {
21514 result <<= 8;
21515 result |= (where[n] & 255);
21516 }
bfae80f2 21517 }
b99bd4ef 21518
c19d1205 21519 return result;
bfae80f2 21520}
b99bd4ef 21521
c19d1205 21522/* MD interface: Sections. */
b99bd4ef 21523
fa94de6b
RM
21524/* Calculate the maximum variable size (i.e., excluding fr_fix)
21525 that an rs_machine_dependent frag may reach. */
21526
21527unsigned int
21528arm_frag_max_var (fragS *fragp)
21529{
21530 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21531 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21532
21533 Note that we generate relaxable instructions even for cases that don't
21534 really need it, like an immediate that's a trivial constant. So we're
21535 overestimating the instruction size for some of those cases. Rather
21536 than putting more intelligence here, it would probably be better to
21537 avoid generating a relaxation frag in the first place when it can be
21538 determined up front that a short instruction will suffice. */
21539
21540 gas_assert (fragp->fr_type == rs_machine_dependent);
21541 return INSN_SIZE;
21542}
21543
0110f2b8
PB
21544/* Estimate the size of a frag before relaxing. Assume everything fits in
21545 2 bytes. */
21546
c19d1205 21547int
0110f2b8 21548md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21549 segT segtype ATTRIBUTE_UNUSED)
21550{
0110f2b8
PB
21551 fragp->fr_var = 2;
21552 return 2;
21553}
21554
21555/* Convert a machine dependent frag. */
21556
21557void
21558md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21559{
21560 unsigned long insn;
21561 unsigned long old_op;
21562 char *buf;
21563 expressionS exp;
21564 fixS *fixp;
21565 int reloc_type;
21566 int pc_rel;
21567 int opcode;
21568
21569 buf = fragp->fr_literal + fragp->fr_fix;
21570
21571 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21572 if (fragp->fr_symbol)
21573 {
0110f2b8
PB
21574 exp.X_op = O_symbol;
21575 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21576 }
21577 else
21578 {
0110f2b8 21579 exp.X_op = O_constant;
5f4273c7 21580 }
0110f2b8
PB
21581 exp.X_add_number = fragp->fr_offset;
21582 opcode = fragp->fr_subtype;
21583 switch (opcode)
21584 {
21585 case T_MNEM_ldr_pc:
21586 case T_MNEM_ldr_pc2:
21587 case T_MNEM_ldr_sp:
21588 case T_MNEM_str_sp:
21589 case T_MNEM_ldr:
21590 case T_MNEM_ldrb:
21591 case T_MNEM_ldrh:
21592 case T_MNEM_str:
21593 case T_MNEM_strb:
21594 case T_MNEM_strh:
21595 if (fragp->fr_var == 4)
21596 {
5f4273c7 21597 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21598 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21599 {
21600 insn |= (old_op & 0x700) << 4;
21601 }
21602 else
21603 {
21604 insn |= (old_op & 7) << 12;
21605 insn |= (old_op & 0x38) << 13;
21606 }
21607 insn |= 0x00000c00;
21608 put_thumb32_insn (buf, insn);
21609 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21610 }
21611 else
21612 {
21613 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21614 }
21615 pc_rel = (opcode == T_MNEM_ldr_pc2);
21616 break;
21617 case T_MNEM_adr:
21618 if (fragp->fr_var == 4)
21619 {
21620 insn = THUMB_OP32 (opcode);
21621 insn |= (old_op & 0xf0) << 4;
21622 put_thumb32_insn (buf, insn);
21623 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21624 }
21625 else
21626 {
21627 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21628 exp.X_add_number -= 4;
21629 }
21630 pc_rel = 1;
21631 break;
21632 case T_MNEM_mov:
21633 case T_MNEM_movs:
21634 case T_MNEM_cmp:
21635 case T_MNEM_cmn:
21636 if (fragp->fr_var == 4)
21637 {
21638 int r0off = (opcode == T_MNEM_mov
21639 || opcode == T_MNEM_movs) ? 0 : 8;
21640 insn = THUMB_OP32 (opcode);
21641 insn = (insn & 0xe1ffffff) | 0x10000000;
21642 insn |= (old_op & 0x700) << r0off;
21643 put_thumb32_insn (buf, insn);
21644 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21645 }
21646 else
21647 {
21648 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21649 }
21650 pc_rel = 0;
21651 break;
21652 case T_MNEM_b:
21653 if (fragp->fr_var == 4)
21654 {
21655 insn = THUMB_OP32(opcode);
21656 put_thumb32_insn (buf, insn);
21657 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21658 }
21659 else
21660 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21661 pc_rel = 1;
21662 break;
21663 case T_MNEM_bcond:
21664 if (fragp->fr_var == 4)
21665 {
21666 insn = THUMB_OP32(opcode);
21667 insn |= (old_op & 0xf00) << 14;
21668 put_thumb32_insn (buf, insn);
21669 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21670 }
21671 else
21672 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21673 pc_rel = 1;
21674 break;
21675 case T_MNEM_add_sp:
21676 case T_MNEM_add_pc:
21677 case T_MNEM_inc_sp:
21678 case T_MNEM_dec_sp:
21679 if (fragp->fr_var == 4)
21680 {
21681 /* ??? Choose between add and addw. */
21682 insn = THUMB_OP32 (opcode);
21683 insn |= (old_op & 0xf0) << 4;
21684 put_thumb32_insn (buf, insn);
16805f35
PB
21685 if (opcode == T_MNEM_add_pc)
21686 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21687 else
21688 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21689 }
21690 else
21691 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21692 pc_rel = 0;
21693 break;
21694
21695 case T_MNEM_addi:
21696 case T_MNEM_addis:
21697 case T_MNEM_subi:
21698 case T_MNEM_subis:
21699 if (fragp->fr_var == 4)
21700 {
21701 insn = THUMB_OP32 (opcode);
21702 insn |= (old_op & 0xf0) << 4;
21703 insn |= (old_op & 0xf) << 16;
21704 put_thumb32_insn (buf, insn);
16805f35
PB
21705 if (insn & (1 << 20))
21706 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21707 else
21708 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21709 }
21710 else
21711 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21712 pc_rel = 0;
21713 break;
21714 default:
5f4273c7 21715 abort ();
0110f2b8
PB
21716 }
21717 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21718 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21719 fixp->fx_file = fragp->fr_file;
21720 fixp->fx_line = fragp->fr_line;
21721 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21722
21723 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21724 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21725 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21726 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21727}
21728
21729/* Return the size of a relaxable immediate operand instruction.
21730 SHIFT and SIZE specify the form of the allowable immediate. */
21731static int
21732relax_immediate (fragS *fragp, int size, int shift)
21733{
21734 offsetT offset;
21735 offsetT mask;
21736 offsetT low;
21737
21738 /* ??? Should be able to do better than this. */
21739 if (fragp->fr_symbol)
21740 return 4;
21741
21742 low = (1 << shift) - 1;
21743 mask = (1 << (shift + size)) - (1 << shift);
21744 offset = fragp->fr_offset;
21745 /* Force misaligned offsets to 32-bit variant. */
21746 if (offset & low)
5e77afaa 21747 return 4;
0110f2b8
PB
21748 if (offset & ~mask)
21749 return 4;
21750 return 2;
21751}
21752
5e77afaa
PB
21753/* Get the address of a symbol during relaxation. */
21754static addressT
5f4273c7 21755relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21756{
21757 fragS *sym_frag;
21758 addressT addr;
21759 symbolS *sym;
21760
21761 sym = fragp->fr_symbol;
21762 sym_frag = symbol_get_frag (sym);
21763 know (S_GET_SEGMENT (sym) != absolute_section
21764 || sym_frag == &zero_address_frag);
21765 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21766
21767 /* If frag has yet to be reached on this pass, assume it will
21768 move by STRETCH just as we did. If this is not so, it will
21769 be because some frag between grows, and that will force
21770 another pass. */
21771
21772 if (stretch != 0
21773 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21774 {
21775 fragS *f;
21776
21777 /* Adjust stretch for any alignment frag. Note that if have
21778 been expanding the earlier code, the symbol may be
21779 defined in what appears to be an earlier frag. FIXME:
21780 This doesn't handle the fr_subtype field, which specifies
21781 a maximum number of bytes to skip when doing an
21782 alignment. */
21783 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21784 {
21785 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21786 {
21787 if (stretch < 0)
21788 stretch = - ((- stretch)
21789 & ~ ((1 << (int) f->fr_offset) - 1));
21790 else
21791 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21792 if (stretch == 0)
21793 break;
21794 }
21795 }
21796 if (f != NULL)
21797 addr += stretch;
21798 }
5e77afaa
PB
21799
21800 return addr;
21801}
21802
0110f2b8
PB
21803/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21804 load. */
21805static int
5e77afaa 21806relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21807{
21808 addressT addr;
21809 offsetT val;
21810
21811 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21812 if (fragp->fr_symbol == NULL
21813 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21814 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21815 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21816 return 4;
21817
5f4273c7 21818 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21819 addr = fragp->fr_address + fragp->fr_fix;
21820 addr = (addr + 4) & ~3;
5e77afaa 21821 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21822 if (val & 3)
5e77afaa 21823 return 4;
0110f2b8
PB
21824 val -= addr;
21825 if (val < 0 || val > 1020)
21826 return 4;
21827 return 2;
21828}
21829
21830/* Return the size of a relaxable add/sub immediate instruction. */
21831static int
21832relax_addsub (fragS *fragp, asection *sec)
21833{
21834 char *buf;
21835 int op;
21836
21837 buf = fragp->fr_literal + fragp->fr_fix;
21838 op = bfd_get_16(sec->owner, buf);
21839 if ((op & 0xf) == ((op >> 4) & 0xf))
21840 return relax_immediate (fragp, 8, 0);
21841 else
21842 return relax_immediate (fragp, 3, 0);
21843}
21844
e83a675f
RE
21845/* Return TRUE iff the definition of symbol S could be pre-empted
21846 (overridden) at link or load time. */
21847static bfd_boolean
21848symbol_preemptible (symbolS *s)
21849{
21850 /* Weak symbols can always be pre-empted. */
21851 if (S_IS_WEAK (s))
21852 return TRUE;
21853
21854 /* Non-global symbols cannot be pre-empted. */
21855 if (! S_IS_EXTERNAL (s))
21856 return FALSE;
21857
21858#ifdef OBJ_ELF
21859 /* In ELF, a global symbol can be marked protected, or private. In that
21860 case it can't be pre-empted (other definitions in the same link unit
21861 would violate the ODR). */
21862 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21863 return FALSE;
21864#endif
21865
21866 /* Other global symbols might be pre-empted. */
21867 return TRUE;
21868}
0110f2b8
PB
21869
21870/* Return the size of a relaxable branch instruction. BITS is the
21871 size of the offset field in the narrow instruction. */
21872
21873static int
5e77afaa 21874relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21875{
21876 addressT addr;
21877 offsetT val;
21878 offsetT limit;
21879
21880 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21881 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21882 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21883 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21884 return 4;
21885
267bf995 21886#ifdef OBJ_ELF
e83a675f 21887 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21888 if (S_IS_DEFINED (fragp->fr_symbol)
21889 && ARM_IS_FUNC (fragp->fr_symbol))
21890 return 4;
e83a675f 21891#endif
0d9b4b55 21892
e83a675f 21893 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21894 return 4;
267bf995 21895
5f4273c7 21896 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21897 addr = fragp->fr_address + fragp->fr_fix + 4;
21898 val -= addr;
21899
21900 /* Offset is a signed value *2 */
21901 limit = 1 << bits;
21902 if (val >= limit || val < -limit)
21903 return 4;
21904 return 2;
21905}
21906
21907
21908/* Relax a machine dependent frag. This returns the amount by which
21909 the current size of the frag should change. */
21910
21911int
5e77afaa 21912arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21913{
21914 int oldsize;
21915 int newsize;
21916
21917 oldsize = fragp->fr_var;
21918 switch (fragp->fr_subtype)
21919 {
21920 case T_MNEM_ldr_pc2:
5f4273c7 21921 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21922 break;
21923 case T_MNEM_ldr_pc:
21924 case T_MNEM_ldr_sp:
21925 case T_MNEM_str_sp:
5f4273c7 21926 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21927 break;
21928 case T_MNEM_ldr:
21929 case T_MNEM_str:
5f4273c7 21930 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21931 break;
21932 case T_MNEM_ldrh:
21933 case T_MNEM_strh:
5f4273c7 21934 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21935 break;
21936 case T_MNEM_ldrb:
21937 case T_MNEM_strb:
5f4273c7 21938 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21939 break;
21940 case T_MNEM_adr:
5f4273c7 21941 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21942 break;
21943 case T_MNEM_mov:
21944 case T_MNEM_movs:
21945 case T_MNEM_cmp:
21946 case T_MNEM_cmn:
5f4273c7 21947 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21948 break;
21949 case T_MNEM_b:
5f4273c7 21950 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21951 break;
21952 case T_MNEM_bcond:
5f4273c7 21953 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21954 break;
21955 case T_MNEM_add_sp:
21956 case T_MNEM_add_pc:
21957 newsize = relax_immediate (fragp, 8, 2);
21958 break;
21959 case T_MNEM_inc_sp:
21960 case T_MNEM_dec_sp:
21961 newsize = relax_immediate (fragp, 7, 2);
21962 break;
21963 case T_MNEM_addi:
21964 case T_MNEM_addis:
21965 case T_MNEM_subi:
21966 case T_MNEM_subis:
21967 newsize = relax_addsub (fragp, sec);
21968 break;
21969 default:
5f4273c7 21970 abort ();
0110f2b8 21971 }
5e77afaa
PB
21972
21973 fragp->fr_var = newsize;
21974 /* Freeze wide instructions that are at or before the same location as
21975 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21976 Don't freeze them unconditionally because targets may be artificially
21977 misaligned by the expansion of preceding frags. */
5e77afaa 21978 if (stretch <= 0 && newsize > 2)
0110f2b8 21979 {
0110f2b8 21980 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21981 frag_wane (fragp);
0110f2b8 21982 }
5e77afaa 21983
0110f2b8 21984 return newsize - oldsize;
c19d1205 21985}
b99bd4ef 21986
c19d1205 21987/* Round up a section size to the appropriate boundary. */
b99bd4ef 21988
c19d1205
ZW
21989valueT
21990md_section_align (segT segment ATTRIBUTE_UNUSED,
21991 valueT size)
21992{
f0927246
NC
21993#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21994 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21995 {
21996 /* For a.out, force the section size to be aligned. If we don't do
21997 this, BFD will align it for us, but it will not write out the
21998 final bytes of the section. This may be a bug in BFD, but it is
21999 easier to fix it here since that is how the other a.out targets
22000 work. */
22001 int align;
22002
22003 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 22004 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 22005 }
c19d1205 22006#endif
f0927246 22007
6844c0cc 22008 return size;
bfae80f2 22009}
b99bd4ef 22010
c19d1205
ZW
22011/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22012 of an rs_align_code fragment. */
22013
22014void
22015arm_handle_align (fragS * fragP)
bfae80f2 22016{
d9235011 22017 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22018 {
22019 { /* ARMv1 */
22020 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22021 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22022 },
22023 { /* ARMv6k */
22024 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22025 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22026 },
22027 };
d9235011 22028 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22029 {
22030 { /* Thumb-1 */
22031 {0xc0, 0x46}, /* LE */
22032 {0x46, 0xc0}, /* BE */
22033 },
22034 { /* Thumb-2 */
22035 {0x00, 0xbf}, /* LE */
22036 {0xbf, 0x00} /* BE */
22037 }
22038 };
d9235011 22039 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22040 { /* Wide Thumb-2 */
22041 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22042 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22043 };
c921be7d 22044
e7495e45 22045 unsigned bytes, fix, noop_size;
c19d1205 22046 char * p;
d9235011
TS
22047 const unsigned char * noop;
22048 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22049#ifdef OBJ_ELF
22050 enum mstate state;
22051#endif
bfae80f2 22052
c19d1205 22053 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22054 return;
22055
c19d1205
ZW
22056 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22057 p = fragP->fr_literal + fragP->fr_fix;
22058 fix = 0;
bfae80f2 22059
c19d1205
ZW
22060 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22061 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22062
cd000bff 22063 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22064
cd000bff 22065 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22066 {
7f78eb34
JW
22067 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22068 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22069 {
22070 narrow_noop = thumb_noop[1][target_big_endian];
22071 noop = wide_thumb_noop[target_big_endian];
22072 }
c19d1205 22073 else
e7495e45
NS
22074 noop = thumb_noop[0][target_big_endian];
22075 noop_size = 2;
cd000bff
DJ
22076#ifdef OBJ_ELF
22077 state = MAP_THUMB;
22078#endif
7ed4c4c5
NC
22079 }
22080 else
22081 {
7f78eb34
JW
22082 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22083 ? selected_cpu : arm_arch_none,
22084 arm_ext_v6k) != 0]
e7495e45
NS
22085 [target_big_endian];
22086 noop_size = 4;
cd000bff
DJ
22087#ifdef OBJ_ELF
22088 state = MAP_ARM;
22089#endif
7ed4c4c5 22090 }
c921be7d 22091
e7495e45 22092 fragP->fr_var = noop_size;
c921be7d 22093
c19d1205 22094 if (bytes & (noop_size - 1))
7ed4c4c5 22095 {
c19d1205 22096 fix = bytes & (noop_size - 1);
cd000bff
DJ
22097#ifdef OBJ_ELF
22098 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22099#endif
c19d1205
ZW
22100 memset (p, 0, fix);
22101 p += fix;
22102 bytes -= fix;
a737bd4d 22103 }
a737bd4d 22104
e7495e45
NS
22105 if (narrow_noop)
22106 {
22107 if (bytes & noop_size)
22108 {
22109 /* Insert a narrow noop. */
22110 memcpy (p, narrow_noop, noop_size);
22111 p += noop_size;
22112 bytes -= noop_size;
22113 fix += noop_size;
22114 }
22115
22116 /* Use wide noops for the remainder */
22117 noop_size = 4;
22118 }
22119
c19d1205 22120 while (bytes >= noop_size)
a737bd4d 22121 {
c19d1205
ZW
22122 memcpy (p, noop, noop_size);
22123 p += noop_size;
22124 bytes -= noop_size;
22125 fix += noop_size;
a737bd4d
NC
22126 }
22127
c19d1205 22128 fragP->fr_fix += fix;
a737bd4d
NC
22129}
22130
c19d1205
ZW
22131/* Called from md_do_align. Used to create an alignment
22132 frag in a code section. */
22133
22134void
22135arm_frag_align_code (int n, int max)
bfae80f2 22136{
c19d1205 22137 char * p;
7ed4c4c5 22138
c19d1205 22139 /* We assume that there will never be a requirement
6ec8e702 22140 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22141 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22142 {
22143 char err_msg[128];
22144
fa94de6b 22145 sprintf (err_msg,
477330fc
RM
22146 _("alignments greater than %d bytes not supported in .text sections."),
22147 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22148 as_fatal ("%s", err_msg);
6ec8e702 22149 }
bfae80f2 22150
c19d1205
ZW
22151 p = frag_var (rs_align_code,
22152 MAX_MEM_FOR_RS_ALIGN_CODE,
22153 1,
22154 (relax_substateT) max,
22155 (symbolS *) NULL,
22156 (offsetT) n,
22157 (char *) NULL);
22158 *p = 0;
22159}
bfae80f2 22160
8dc2430f
NC
22161/* Perform target specific initialisation of a frag.
22162 Note - despite the name this initialisation is not done when the frag
22163 is created, but only when its type is assigned. A frag can be created
22164 and used a long time before its type is set, so beware of assuming that
33eaf5de 22165 this initialisation is performed first. */
bfae80f2 22166
cd000bff
DJ
22167#ifndef OBJ_ELF
22168void
22169arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22170{
22171 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22172 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22173}
22174
22175#else /* OBJ_ELF is defined. */
c19d1205 22176void
cd000bff 22177arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22178{
e8d84ca1 22179 bfd_boolean frag_thumb_mode;
b968d18a 22180
8dc2430f
NC
22181 /* If the current ARM vs THUMB mode has not already
22182 been recorded into this frag then do so now. */
cd000bff 22183 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22184 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22185
e8d84ca1
NC
22186 /* PR 21809: Do not set a mapping state for debug sections
22187 - it just confuses other tools. */
22188 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22189 return;
22190
b968d18a 22191 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22192
f9c1b181
RL
22193 /* Record a mapping symbol for alignment frags. We will delete this
22194 later if the alignment ends up empty. */
22195 switch (fragP->fr_type)
22196 {
22197 case rs_align:
22198 case rs_align_test:
22199 case rs_fill:
22200 mapping_state_2 (MAP_DATA, max_chars);
22201 break;
22202 case rs_align_code:
b968d18a 22203 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22204 break;
22205 default:
22206 break;
cd000bff 22207 }
bfae80f2
RE
22208}
22209
c19d1205
ZW
22210/* When we change sections we need to issue a new mapping symbol. */
22211
22212void
22213arm_elf_change_section (void)
bfae80f2 22214{
c19d1205
ZW
22215 /* Link an unlinked unwind index table section to the .text section. */
22216 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22217 && elf_linked_to_section (now_seg) == NULL)
22218 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22219}
22220
c19d1205
ZW
22221int
22222arm_elf_section_type (const char * str, size_t len)
e45d0630 22223{
c19d1205
ZW
22224 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22225 return SHT_ARM_EXIDX;
e45d0630 22226
c19d1205
ZW
22227 return -1;
22228}
22229\f
22230/* Code to deal with unwinding tables. */
e45d0630 22231
c19d1205 22232static void add_unwind_adjustsp (offsetT);
e45d0630 22233
5f4273c7 22234/* Generate any deferred unwind frame offset. */
e45d0630 22235
bfae80f2 22236static void
c19d1205 22237flush_pending_unwind (void)
bfae80f2 22238{
c19d1205 22239 offsetT offset;
bfae80f2 22240
c19d1205
ZW
22241 offset = unwind.pending_offset;
22242 unwind.pending_offset = 0;
22243 if (offset != 0)
22244 add_unwind_adjustsp (offset);
bfae80f2
RE
22245}
22246
c19d1205
ZW
22247/* Add an opcode to this list for this function. Two-byte opcodes should
22248 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22249 order. */
22250
bfae80f2 22251static void
c19d1205 22252add_unwind_opcode (valueT op, int length)
bfae80f2 22253{
c19d1205
ZW
22254 /* Add any deferred stack adjustment. */
22255 if (unwind.pending_offset)
22256 flush_pending_unwind ();
bfae80f2 22257
c19d1205 22258 unwind.sp_restored = 0;
bfae80f2 22259
c19d1205 22260 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22261 {
c19d1205
ZW
22262 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22263 if (unwind.opcodes)
325801bd
TS
22264 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22265 unwind.opcode_alloc);
c19d1205 22266 else
325801bd 22267 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22268 }
c19d1205 22269 while (length > 0)
bfae80f2 22270 {
c19d1205
ZW
22271 length--;
22272 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22273 op >>= 8;
22274 unwind.opcode_count++;
bfae80f2 22275 }
bfae80f2
RE
22276}
22277
c19d1205
ZW
22278/* Add unwind opcodes to adjust the stack pointer. */
22279
bfae80f2 22280static void
c19d1205 22281add_unwind_adjustsp (offsetT offset)
bfae80f2 22282{
c19d1205 22283 valueT op;
bfae80f2 22284
c19d1205 22285 if (offset > 0x200)
bfae80f2 22286 {
c19d1205
ZW
22287 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22288 char bytes[5];
22289 int n;
22290 valueT o;
bfae80f2 22291
c19d1205
ZW
22292 /* Long form: 0xb2, uleb128. */
22293 /* This might not fit in a word so add the individual bytes,
22294 remembering the list is built in reverse order. */
22295 o = (valueT) ((offset - 0x204) >> 2);
22296 if (o == 0)
22297 add_unwind_opcode (0, 1);
bfae80f2 22298
c19d1205
ZW
22299 /* Calculate the uleb128 encoding of the offset. */
22300 n = 0;
22301 while (o)
22302 {
22303 bytes[n] = o & 0x7f;
22304 o >>= 7;
22305 if (o)
22306 bytes[n] |= 0x80;
22307 n++;
22308 }
22309 /* Add the insn. */
22310 for (; n; n--)
22311 add_unwind_opcode (bytes[n - 1], 1);
22312 add_unwind_opcode (0xb2, 1);
22313 }
22314 else if (offset > 0x100)
bfae80f2 22315 {
c19d1205
ZW
22316 /* Two short opcodes. */
22317 add_unwind_opcode (0x3f, 1);
22318 op = (offset - 0x104) >> 2;
22319 add_unwind_opcode (op, 1);
bfae80f2 22320 }
c19d1205
ZW
22321 else if (offset > 0)
22322 {
22323 /* Short opcode. */
22324 op = (offset - 4) >> 2;
22325 add_unwind_opcode (op, 1);
22326 }
22327 else if (offset < 0)
bfae80f2 22328 {
c19d1205
ZW
22329 offset = -offset;
22330 while (offset > 0x100)
bfae80f2 22331 {
c19d1205
ZW
22332 add_unwind_opcode (0x7f, 1);
22333 offset -= 0x100;
bfae80f2 22334 }
c19d1205
ZW
22335 op = ((offset - 4) >> 2) | 0x40;
22336 add_unwind_opcode (op, 1);
bfae80f2 22337 }
bfae80f2
RE
22338}
22339
c19d1205 22340/* Finish the list of unwind opcodes for this function. */
0198d5e6 22341
c19d1205
ZW
22342static void
22343finish_unwind_opcodes (void)
bfae80f2 22344{
c19d1205 22345 valueT op;
bfae80f2 22346
c19d1205 22347 if (unwind.fp_used)
bfae80f2 22348 {
708587a4 22349 /* Adjust sp as necessary. */
c19d1205
ZW
22350 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22351 flush_pending_unwind ();
bfae80f2 22352
c19d1205
ZW
22353 /* After restoring sp from the frame pointer. */
22354 op = 0x90 | unwind.fp_reg;
22355 add_unwind_opcode (op, 1);
22356 }
22357 else
22358 flush_pending_unwind ();
bfae80f2
RE
22359}
22360
bfae80f2 22361
c19d1205
ZW
22362/* Start an exception table entry. If idx is nonzero this is an index table
22363 entry. */
bfae80f2
RE
22364
22365static void
c19d1205 22366start_unwind_section (const segT text_seg, int idx)
bfae80f2 22367{
c19d1205
ZW
22368 const char * text_name;
22369 const char * prefix;
22370 const char * prefix_once;
22371 const char * group_name;
c19d1205 22372 char * sec_name;
c19d1205
ZW
22373 int type;
22374 int flags;
22375 int linkonce;
bfae80f2 22376
c19d1205 22377 if (idx)
bfae80f2 22378 {
c19d1205
ZW
22379 prefix = ELF_STRING_ARM_unwind;
22380 prefix_once = ELF_STRING_ARM_unwind_once;
22381 type = SHT_ARM_EXIDX;
bfae80f2 22382 }
c19d1205 22383 else
bfae80f2 22384 {
c19d1205
ZW
22385 prefix = ELF_STRING_ARM_unwind_info;
22386 prefix_once = ELF_STRING_ARM_unwind_info_once;
22387 type = SHT_PROGBITS;
bfae80f2
RE
22388 }
22389
c19d1205
ZW
22390 text_name = segment_name (text_seg);
22391 if (streq (text_name, ".text"))
22392 text_name = "";
22393
22394 if (strncmp (text_name, ".gnu.linkonce.t.",
22395 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22396 {
c19d1205
ZW
22397 prefix = prefix_once;
22398 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22399 }
22400
29a2809e 22401 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22402
c19d1205
ZW
22403 flags = SHF_ALLOC;
22404 linkonce = 0;
22405 group_name = 0;
bfae80f2 22406
c19d1205
ZW
22407 /* Handle COMDAT group. */
22408 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22409 {
c19d1205
ZW
22410 group_name = elf_group_name (text_seg);
22411 if (group_name == NULL)
22412 {
bd3ba5d1 22413 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22414 segment_name (text_seg));
22415 ignore_rest_of_line ();
22416 return;
22417 }
22418 flags |= SHF_GROUP;
22419 linkonce = 1;
bfae80f2
RE
22420 }
22421
a91e1603
L
22422 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22423 linkonce, 0);
bfae80f2 22424
5f4273c7 22425 /* Set the section link for index tables. */
c19d1205
ZW
22426 if (idx)
22427 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22428}
22429
bfae80f2 22430
c19d1205
ZW
22431/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22432 personality routine data. Returns zero, or the index table value for
cad0da33 22433 an inline entry. */
c19d1205
ZW
22434
22435static valueT
22436create_unwind_entry (int have_data)
bfae80f2 22437{
c19d1205
ZW
22438 int size;
22439 addressT where;
22440 char *ptr;
22441 /* The current word of data. */
22442 valueT data;
22443 /* The number of bytes left in this word. */
22444 int n;
bfae80f2 22445
c19d1205 22446 finish_unwind_opcodes ();
bfae80f2 22447
c19d1205
ZW
22448 /* Remember the current text section. */
22449 unwind.saved_seg = now_seg;
22450 unwind.saved_subseg = now_subseg;
bfae80f2 22451
c19d1205 22452 start_unwind_section (now_seg, 0);
bfae80f2 22453
c19d1205 22454 if (unwind.personality_routine == NULL)
bfae80f2 22455 {
c19d1205
ZW
22456 if (unwind.personality_index == -2)
22457 {
22458 if (have_data)
5f4273c7 22459 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22460 return 1; /* EXIDX_CANTUNWIND. */
22461 }
bfae80f2 22462
c19d1205
ZW
22463 /* Use a default personality routine if none is specified. */
22464 if (unwind.personality_index == -1)
22465 {
22466 if (unwind.opcode_count > 3)
22467 unwind.personality_index = 1;
22468 else
22469 unwind.personality_index = 0;
22470 }
bfae80f2 22471
c19d1205
ZW
22472 /* Space for the personality routine entry. */
22473 if (unwind.personality_index == 0)
22474 {
22475 if (unwind.opcode_count > 3)
22476 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22477
c19d1205
ZW
22478 if (!have_data)
22479 {
22480 /* All the data is inline in the index table. */
22481 data = 0x80;
22482 n = 3;
22483 while (unwind.opcode_count > 0)
22484 {
22485 unwind.opcode_count--;
22486 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22487 n--;
22488 }
bfae80f2 22489
c19d1205
ZW
22490 /* Pad with "finish" opcodes. */
22491 while (n--)
22492 data = (data << 8) | 0xb0;
bfae80f2 22493
c19d1205
ZW
22494 return data;
22495 }
22496 size = 0;
22497 }
22498 else
22499 /* We get two opcodes "free" in the first word. */
22500 size = unwind.opcode_count - 2;
22501 }
22502 else
5011093d 22503 {
cad0da33
NC
22504 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22505 if (unwind.personality_index != -1)
22506 {
22507 as_bad (_("attempt to recreate an unwind entry"));
22508 return 1;
22509 }
5011093d
NC
22510
22511 /* An extra byte is required for the opcode count. */
22512 size = unwind.opcode_count + 1;
22513 }
bfae80f2 22514
c19d1205
ZW
22515 size = (size + 3) >> 2;
22516 if (size > 0xff)
22517 as_bad (_("too many unwind opcodes"));
bfae80f2 22518
c19d1205
ZW
22519 frag_align (2, 0, 0);
22520 record_alignment (now_seg, 2);
22521 unwind.table_entry = expr_build_dot ();
22522
22523 /* Allocate the table entry. */
22524 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22525 /* PR 13449: Zero the table entries in case some of them are not used. */
22526 memset (ptr, 0, (size << 2) + 4);
c19d1205 22527 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22528
c19d1205 22529 switch (unwind.personality_index)
bfae80f2 22530 {
c19d1205
ZW
22531 case -1:
22532 /* ??? Should this be a PLT generating relocation? */
22533 /* Custom personality routine. */
22534 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22535 BFD_RELOC_ARM_PREL31);
bfae80f2 22536
c19d1205
ZW
22537 where += 4;
22538 ptr += 4;
bfae80f2 22539
c19d1205 22540 /* Set the first byte to the number of additional words. */
5011093d 22541 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22542 n = 3;
22543 break;
bfae80f2 22544
c19d1205
ZW
22545 /* ABI defined personality routines. */
22546 case 0:
22547 /* Three opcodes bytes are packed into the first word. */
22548 data = 0x80;
22549 n = 3;
22550 break;
bfae80f2 22551
c19d1205
ZW
22552 case 1:
22553 case 2:
22554 /* The size and first two opcode bytes go in the first word. */
22555 data = ((0x80 + unwind.personality_index) << 8) | size;
22556 n = 2;
22557 break;
bfae80f2 22558
c19d1205
ZW
22559 default:
22560 /* Should never happen. */
22561 abort ();
22562 }
bfae80f2 22563
c19d1205
ZW
22564 /* Pack the opcodes into words (MSB first), reversing the list at the same
22565 time. */
22566 while (unwind.opcode_count > 0)
22567 {
22568 if (n == 0)
22569 {
22570 md_number_to_chars (ptr, data, 4);
22571 ptr += 4;
22572 n = 4;
22573 data = 0;
22574 }
22575 unwind.opcode_count--;
22576 n--;
22577 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22578 }
22579
22580 /* Finish off the last word. */
22581 if (n < 4)
22582 {
22583 /* Pad with "finish" opcodes. */
22584 while (n--)
22585 data = (data << 8) | 0xb0;
22586
22587 md_number_to_chars (ptr, data, 4);
22588 }
22589
22590 if (!have_data)
22591 {
22592 /* Add an empty descriptor if there is no user-specified data. */
22593 ptr = frag_more (4);
22594 md_number_to_chars (ptr, 0, 4);
22595 }
22596
22597 return 0;
bfae80f2
RE
22598}
22599
f0927246
NC
22600
22601/* Initialize the DWARF-2 unwind information for this procedure. */
22602
22603void
22604tc_arm_frame_initial_instructions (void)
22605{
22606 cfi_add_CFA_def_cfa (REG_SP, 0);
22607}
22608#endif /* OBJ_ELF */
22609
c19d1205
ZW
22610/* Convert REGNAME to a DWARF-2 register number. */
22611
22612int
1df69f4f 22613tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22614{
1df69f4f 22615 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22616 if (reg != FAIL)
22617 return reg;
c19d1205 22618
1f5afe1c
NC
22619 /* PR 16694: Allow VFP registers as well. */
22620 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22621 if (reg != FAIL)
22622 return 64 + reg;
c19d1205 22623
1f5afe1c
NC
22624 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22625 if (reg != FAIL)
22626 return reg + 256;
22627
0198d5e6 22628 return FAIL;
bfae80f2
RE
22629}
22630
f0927246 22631#ifdef TE_PE
c19d1205 22632void
f0927246 22633tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22634{
91d6fa6a 22635 expressionS exp;
bfae80f2 22636
91d6fa6a
NC
22637 exp.X_op = O_secrel;
22638 exp.X_add_symbol = symbol;
22639 exp.X_add_number = 0;
22640 emit_expr (&exp, size);
f0927246
NC
22641}
22642#endif
bfae80f2 22643
c19d1205 22644/* MD interface: Symbol and relocation handling. */
bfae80f2 22645
2fc8bdac
ZW
22646/* Return the address within the segment that a PC-relative fixup is
22647 relative to. For ARM, PC-relative fixups applied to instructions
22648 are generally relative to the location of the fixup plus 8 bytes.
22649 Thumb branches are offset by 4, and Thumb loads relative to PC
22650 require special handling. */
bfae80f2 22651
c19d1205 22652long
2fc8bdac 22653md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22654{
2fc8bdac
ZW
22655 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22656
22657 /* If this is pc-relative and we are going to emit a relocation
22658 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22659 will need. Otherwise we want to use the calculated base.
22660 For WinCE we skip the bias for externals as well, since this
22661 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22662 if (fixP->fx_pcrel
2fc8bdac 22663 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22664 || (arm_force_relocation (fixP)
22665#ifdef TE_WINCE
22666 && !S_IS_EXTERNAL (fixP->fx_addsy)
22667#endif
22668 )))
2fc8bdac 22669 base = 0;
bfae80f2 22670
267bf995 22671
c19d1205 22672 switch (fixP->fx_r_type)
bfae80f2 22673 {
2fc8bdac
ZW
22674 /* PC relative addressing on the Thumb is slightly odd as the
22675 bottom two bits of the PC are forced to zero for the
22676 calculation. This happens *after* application of the
22677 pipeline offset. However, Thumb adrl already adjusts for
22678 this, so we need not do it again. */
c19d1205 22679 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22680 return base & ~3;
c19d1205
ZW
22681
22682 case BFD_RELOC_ARM_THUMB_OFFSET:
22683 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22684 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22685 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22686 return (base + 4) & ~3;
c19d1205 22687
2fc8bdac
ZW
22688 /* Thumb branches are simply offset by +4. */
22689 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22690 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22691 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22692 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22693 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22694 return base + 4;
bfae80f2 22695
267bf995 22696 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22697 if (fixP->fx_addsy
22698 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22699 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22700 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22701 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22702 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22703 return base + 4;
22704
00adf2d4
JB
22705 /* BLX is like branches above, but forces the low two bits of PC to
22706 zero. */
486499d0
CL
22707 case BFD_RELOC_THUMB_PCREL_BLX:
22708 if (fixP->fx_addsy
22709 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22710 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22711 && THUMB_IS_FUNC (fixP->fx_addsy)
22712 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22713 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22714 return (base + 4) & ~3;
22715
2fc8bdac
ZW
22716 /* ARM mode branches are offset by +8. However, the Windows CE
22717 loader expects the relocation not to take this into account. */
267bf995 22718 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22719 if (fixP->fx_addsy
22720 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22721 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22722 && ARM_IS_FUNC (fixP->fx_addsy)
22723 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22724 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22725 return base + 8;
267bf995 22726
486499d0
CL
22727 case BFD_RELOC_ARM_PCREL_CALL:
22728 if (fixP->fx_addsy
22729 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22730 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22731 && THUMB_IS_FUNC (fixP->fx_addsy)
22732 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22733 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22734 return base + 8;
267bf995 22735
2fc8bdac 22736 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22737 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22738 case BFD_RELOC_ARM_PLT32:
c19d1205 22739#ifdef TE_WINCE
5f4273c7 22740 /* When handling fixups immediately, because we have already
477330fc 22741 discovered the value of a symbol, or the address of the frag involved
53baae48 22742 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22743 see fixup_segment() in write.c
22744 The S_IS_EXTERNAL test handles the case of global symbols.
22745 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22746 if (fixP->fx_pcrel
22747 && fixP->fx_addsy != NULL
22748 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22749 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22750 return base + 8;
2fc8bdac 22751 return base;
c19d1205 22752#else
2fc8bdac 22753 return base + 8;
c19d1205 22754#endif
2fc8bdac 22755
267bf995 22756
2fc8bdac
ZW
22757 /* ARM mode loads relative to PC are also offset by +8. Unlike
22758 branches, the Windows CE loader *does* expect the relocation
22759 to take this into account. */
22760 case BFD_RELOC_ARM_OFFSET_IMM:
22761 case BFD_RELOC_ARM_OFFSET_IMM8:
22762 case BFD_RELOC_ARM_HWLITERAL:
22763 case BFD_RELOC_ARM_LITERAL:
22764 case BFD_RELOC_ARM_CP_OFF_IMM:
22765 return base + 8;
22766
22767
22768 /* Other PC-relative relocations are un-offset. */
22769 default:
22770 return base;
22771 }
bfae80f2
RE
22772}
22773
8b2d793c
NC
22774static bfd_boolean flag_warn_syms = TRUE;
22775
ae8714c2
NC
22776bfd_boolean
22777arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22778{
8b2d793c
NC
22779 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22780 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22781 does mean that the resulting code might be very confusing to the reader.
22782 Also this warning can be triggered if the user omits an operand before
22783 an immediate address, eg:
22784
22785 LDR =foo
22786
22787 GAS treats this as an assignment of the value of the symbol foo to a
22788 symbol LDR, and so (without this code) it will not issue any kind of
22789 warning or error message.
22790
22791 Note - ARM instructions are case-insensitive but the strings in the hash
22792 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22793 lower case too. */
22794 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22795 {
22796 char * nbuf = strdup (name);
22797 char * p;
22798
22799 for (p = nbuf; *p; p++)
22800 *p = TOLOWER (*p);
22801 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22802 {
22803 static struct hash_control * already_warned = NULL;
22804
22805 if (already_warned == NULL)
22806 already_warned = hash_new ();
22807 /* Only warn about the symbol once. To keep the code
22808 simple we let hash_insert do the lookup for us. */
22809 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22810 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22811 }
22812 else
22813 free (nbuf);
22814 }
3739860c 22815
ae8714c2
NC
22816 return FALSE;
22817}
22818
22819/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22820 Otherwise we have no need to default values of symbols. */
22821
22822symbolS *
22823md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22824{
22825#ifdef OBJ_ELF
22826 if (name[0] == '_' && name[1] == 'G'
22827 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22828 {
22829 if (!GOT_symbol)
22830 {
22831 if (symbol_find (name))
22832 as_bad (_("GOT already in the symbol table"));
22833
22834 GOT_symbol = symbol_new (name, undefined_section,
22835 (valueT) 0, & zero_address_frag);
22836 }
22837
22838 return GOT_symbol;
22839 }
22840#endif
22841
c921be7d 22842 return NULL;
bfae80f2
RE
22843}
22844
55cf6793 22845/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22846 computed as two separate immediate values, added together. We
22847 already know that this value cannot be computed by just one ARM
22848 instruction. */
22849
22850static unsigned int
22851validate_immediate_twopart (unsigned int val,
22852 unsigned int * highpart)
bfae80f2 22853{
c19d1205
ZW
22854 unsigned int a;
22855 unsigned int i;
bfae80f2 22856
c19d1205
ZW
22857 for (i = 0; i < 32; i += 2)
22858 if (((a = rotate_left (val, i)) & 0xff) != 0)
22859 {
22860 if (a & 0xff00)
22861 {
22862 if (a & ~ 0xffff)
22863 continue;
22864 * highpart = (a >> 8) | ((i + 24) << 7);
22865 }
22866 else if (a & 0xff0000)
22867 {
22868 if (a & 0xff000000)
22869 continue;
22870 * highpart = (a >> 16) | ((i + 16) << 7);
22871 }
22872 else
22873 {
9c2799c2 22874 gas_assert (a & 0xff000000);
c19d1205
ZW
22875 * highpart = (a >> 24) | ((i + 8) << 7);
22876 }
bfae80f2 22877
c19d1205
ZW
22878 return (a & 0xff) | (i << 7);
22879 }
bfae80f2 22880
c19d1205 22881 return FAIL;
bfae80f2
RE
22882}
22883
c19d1205
ZW
22884static int
22885validate_offset_imm (unsigned int val, int hwse)
22886{
22887 if ((hwse && val > 255) || val > 4095)
22888 return FAIL;
22889 return val;
22890}
bfae80f2 22891
55cf6793 22892/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22893 negative immediate constant by altering the instruction. A bit of
22894 a hack really.
22895 MOV <-> MVN
22896 AND <-> BIC
22897 ADC <-> SBC
22898 by inverting the second operand, and
22899 ADD <-> SUB
22900 CMP <-> CMN
22901 by negating the second operand. */
bfae80f2 22902
c19d1205
ZW
22903static int
22904negate_data_op (unsigned long * instruction,
22905 unsigned long value)
bfae80f2 22906{
c19d1205
ZW
22907 int op, new_inst;
22908 unsigned long negated, inverted;
bfae80f2 22909
c19d1205
ZW
22910 negated = encode_arm_immediate (-value);
22911 inverted = encode_arm_immediate (~value);
bfae80f2 22912
c19d1205
ZW
22913 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22914 switch (op)
bfae80f2 22915 {
c19d1205
ZW
22916 /* First negates. */
22917 case OPCODE_SUB: /* ADD <-> SUB */
22918 new_inst = OPCODE_ADD;
22919 value = negated;
22920 break;
bfae80f2 22921
c19d1205
ZW
22922 case OPCODE_ADD:
22923 new_inst = OPCODE_SUB;
22924 value = negated;
22925 break;
bfae80f2 22926
c19d1205
ZW
22927 case OPCODE_CMP: /* CMP <-> CMN */
22928 new_inst = OPCODE_CMN;
22929 value = negated;
22930 break;
bfae80f2 22931
c19d1205
ZW
22932 case OPCODE_CMN:
22933 new_inst = OPCODE_CMP;
22934 value = negated;
22935 break;
bfae80f2 22936
c19d1205
ZW
22937 /* Now Inverted ops. */
22938 case OPCODE_MOV: /* MOV <-> MVN */
22939 new_inst = OPCODE_MVN;
22940 value = inverted;
22941 break;
bfae80f2 22942
c19d1205
ZW
22943 case OPCODE_MVN:
22944 new_inst = OPCODE_MOV;
22945 value = inverted;
22946 break;
bfae80f2 22947
c19d1205
ZW
22948 case OPCODE_AND: /* AND <-> BIC */
22949 new_inst = OPCODE_BIC;
22950 value = inverted;
22951 break;
bfae80f2 22952
c19d1205
ZW
22953 case OPCODE_BIC:
22954 new_inst = OPCODE_AND;
22955 value = inverted;
22956 break;
bfae80f2 22957
c19d1205
ZW
22958 case OPCODE_ADC: /* ADC <-> SBC */
22959 new_inst = OPCODE_SBC;
22960 value = inverted;
22961 break;
bfae80f2 22962
c19d1205
ZW
22963 case OPCODE_SBC:
22964 new_inst = OPCODE_ADC;
22965 value = inverted;
22966 break;
bfae80f2 22967
c19d1205
ZW
22968 /* We cannot do anything. */
22969 default:
22970 return FAIL;
b99bd4ef
NC
22971 }
22972
c19d1205
ZW
22973 if (value == (unsigned) FAIL)
22974 return FAIL;
22975
22976 *instruction &= OPCODE_MASK;
22977 *instruction |= new_inst << DATA_OP_SHIFT;
22978 return value;
b99bd4ef
NC
22979}
22980
ef8d22e6
PB
22981/* Like negate_data_op, but for Thumb-2. */
22982
22983static unsigned int
16dd5e42 22984thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22985{
22986 int op, new_inst;
22987 int rd;
16dd5e42 22988 unsigned int negated, inverted;
ef8d22e6
PB
22989
22990 negated = encode_thumb32_immediate (-value);
22991 inverted = encode_thumb32_immediate (~value);
22992
22993 rd = (*instruction >> 8) & 0xf;
22994 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22995 switch (op)
22996 {
22997 /* ADD <-> SUB. Includes CMP <-> CMN. */
22998 case T2_OPCODE_SUB:
22999 new_inst = T2_OPCODE_ADD;
23000 value = negated;
23001 break;
23002
23003 case T2_OPCODE_ADD:
23004 new_inst = T2_OPCODE_SUB;
23005 value = negated;
23006 break;
23007
23008 /* ORR <-> ORN. Includes MOV <-> MVN. */
23009 case T2_OPCODE_ORR:
23010 new_inst = T2_OPCODE_ORN;
23011 value = inverted;
23012 break;
23013
23014 case T2_OPCODE_ORN:
23015 new_inst = T2_OPCODE_ORR;
23016 value = inverted;
23017 break;
23018
23019 /* AND <-> BIC. TST has no inverted equivalent. */
23020 case T2_OPCODE_AND:
23021 new_inst = T2_OPCODE_BIC;
23022 if (rd == 15)
23023 value = FAIL;
23024 else
23025 value = inverted;
23026 break;
23027
23028 case T2_OPCODE_BIC:
23029 new_inst = T2_OPCODE_AND;
23030 value = inverted;
23031 break;
23032
23033 /* ADC <-> SBC */
23034 case T2_OPCODE_ADC:
23035 new_inst = T2_OPCODE_SBC;
23036 value = inverted;
23037 break;
23038
23039 case T2_OPCODE_SBC:
23040 new_inst = T2_OPCODE_ADC;
23041 value = inverted;
23042 break;
23043
23044 /* We cannot do anything. */
23045 default:
23046 return FAIL;
23047 }
23048
16dd5e42 23049 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23050 return FAIL;
23051
23052 *instruction &= T2_OPCODE_MASK;
23053 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23054 return value;
23055}
23056
8f06b2d8 23057/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23058
8f06b2d8
PB
23059static unsigned long
23060get_thumb32_insn (char * buf)
23061{
23062 unsigned long insn;
23063 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23064 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23065
23066 return insn;
23067}
23068
a8bc6c78
PB
23069/* We usually want to set the low bit on the address of thumb function
23070 symbols. In particular .word foo - . should have the low bit set.
23071 Generic code tries to fold the difference of two symbols to
23072 a constant. Prevent this and force a relocation when the first symbols
23073 is a thumb function. */
c921be7d
NC
23074
23075bfd_boolean
a8bc6c78
PB
23076arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23077{
23078 if (op == O_subtract
23079 && l->X_op == O_symbol
23080 && r->X_op == O_symbol
23081 && THUMB_IS_FUNC (l->X_add_symbol))
23082 {
23083 l->X_op = O_subtract;
23084 l->X_op_symbol = r->X_add_symbol;
23085 l->X_add_number -= r->X_add_number;
c921be7d 23086 return TRUE;
a8bc6c78 23087 }
c921be7d 23088
a8bc6c78 23089 /* Process as normal. */
c921be7d 23090 return FALSE;
a8bc6c78
PB
23091}
23092
4a42ebbc
RR
23093/* Encode Thumb2 unconditional branches and calls. The encoding
23094 for the 2 are identical for the immediate values. */
23095
23096static void
23097encode_thumb2_b_bl_offset (char * buf, offsetT value)
23098{
23099#define T2I1I2MASK ((1 << 13) | (1 << 11))
23100 offsetT newval;
23101 offsetT newval2;
23102 addressT S, I1, I2, lo, hi;
23103
23104 S = (value >> 24) & 0x01;
23105 I1 = (value >> 23) & 0x01;
23106 I2 = (value >> 22) & 0x01;
23107 hi = (value >> 12) & 0x3ff;
fa94de6b 23108 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23109 newval = md_chars_to_number (buf, THUMB_SIZE);
23110 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23111 newval |= (S << 10) | hi;
23112 newval2 &= ~T2I1I2MASK;
23113 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23114 md_number_to_chars (buf, newval, THUMB_SIZE);
23115 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23116}
23117
c19d1205 23118void
55cf6793 23119md_apply_fix (fixS * fixP,
c19d1205
ZW
23120 valueT * valP,
23121 segT seg)
23122{
23123 offsetT value = * valP;
23124 offsetT newval;
23125 unsigned int newimm;
23126 unsigned long temp;
23127 int sign;
23128 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23129
9c2799c2 23130 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23131
c19d1205 23132 /* Note whether this will delete the relocation. */
4962c51a 23133
c19d1205
ZW
23134 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23135 fixP->fx_done = 1;
b99bd4ef 23136
adbaf948 23137 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23138 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23139 for emit_reloc. */
23140 value &= 0xffffffff;
23141 value ^= 0x80000000;
5f4273c7 23142 value -= 0x80000000;
adbaf948
ZW
23143
23144 *valP = value;
c19d1205 23145 fixP->fx_addnumber = value;
b99bd4ef 23146
adbaf948
ZW
23147 /* Same treatment for fixP->fx_offset. */
23148 fixP->fx_offset &= 0xffffffff;
23149 fixP->fx_offset ^= 0x80000000;
23150 fixP->fx_offset -= 0x80000000;
23151
c19d1205 23152 switch (fixP->fx_r_type)
b99bd4ef 23153 {
c19d1205
ZW
23154 case BFD_RELOC_NONE:
23155 /* This will need to go in the object file. */
23156 fixP->fx_done = 0;
23157 break;
b99bd4ef 23158
c19d1205
ZW
23159 case BFD_RELOC_ARM_IMMEDIATE:
23160 /* We claim that this fixup has been processed here,
23161 even if in fact we generate an error because we do
23162 not have a reloc for it, so tc_gen_reloc will reject it. */
23163 fixP->fx_done = 1;
b99bd4ef 23164
77db8e2e 23165 if (fixP->fx_addsy)
b99bd4ef 23166 {
77db8e2e 23167 const char *msg = 0;
b99bd4ef 23168
77db8e2e
NC
23169 if (! S_IS_DEFINED (fixP->fx_addsy))
23170 msg = _("undefined symbol %s used as an immediate value");
23171 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23172 msg = _("symbol %s is in a different section");
23173 else if (S_IS_WEAK (fixP->fx_addsy))
23174 msg = _("symbol %s is weak and may be overridden later");
23175
23176 if (msg)
23177 {
23178 as_bad_where (fixP->fx_file, fixP->fx_line,
23179 msg, S_GET_NAME (fixP->fx_addsy));
23180 break;
23181 }
42e5fcbf
AS
23182 }
23183
c19d1205
ZW
23184 temp = md_chars_to_number (buf, INSN_SIZE);
23185
5e73442d
SL
23186 /* If the offset is negative, we should use encoding A2 for ADR. */
23187 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23188 newimm = negate_data_op (&temp, value);
23189 else
23190 {
23191 newimm = encode_arm_immediate (value);
23192
23193 /* If the instruction will fail, see if we can fix things up by
23194 changing the opcode. */
23195 if (newimm == (unsigned int) FAIL)
23196 newimm = negate_data_op (&temp, value);
bada4342
JW
23197 /* MOV accepts both ARM modified immediate (A1 encoding) and
23198 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23199 When disassembling, MOV is preferred when there is no encoding
23200 overlap. */
23201 if (newimm == (unsigned int) FAIL
23202 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23203 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23204 && !((temp >> SBIT_SHIFT) & 0x1)
23205 && value >= 0 && value <= 0xffff)
23206 {
23207 /* Clear bits[23:20] to change encoding from A1 to A2. */
23208 temp &= 0xff0fffff;
23209 /* Encoding high 4bits imm. Code below will encode the remaining
23210 low 12bits. */
23211 temp |= (value & 0x0000f000) << 4;
23212 newimm = value & 0x00000fff;
23213 }
5e73442d
SL
23214 }
23215
23216 if (newimm == (unsigned int) FAIL)
b99bd4ef 23217 {
c19d1205
ZW
23218 as_bad_where (fixP->fx_file, fixP->fx_line,
23219 _("invalid constant (%lx) after fixup"),
23220 (unsigned long) value);
23221 break;
b99bd4ef 23222 }
b99bd4ef 23223
c19d1205
ZW
23224 newimm |= (temp & 0xfffff000);
23225 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23226 break;
b99bd4ef 23227
c19d1205
ZW
23228 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23229 {
23230 unsigned int highpart = 0;
23231 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23232
77db8e2e 23233 if (fixP->fx_addsy)
42e5fcbf 23234 {
77db8e2e 23235 const char *msg = 0;
42e5fcbf 23236
77db8e2e
NC
23237 if (! S_IS_DEFINED (fixP->fx_addsy))
23238 msg = _("undefined symbol %s used as an immediate value");
23239 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23240 msg = _("symbol %s is in a different section");
23241 else if (S_IS_WEAK (fixP->fx_addsy))
23242 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23243
77db8e2e
NC
23244 if (msg)
23245 {
23246 as_bad_where (fixP->fx_file, fixP->fx_line,
23247 msg, S_GET_NAME (fixP->fx_addsy));
23248 break;
23249 }
23250 }
fa94de6b 23251
c19d1205
ZW
23252 newimm = encode_arm_immediate (value);
23253 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23254
c19d1205
ZW
23255 /* If the instruction will fail, see if we can fix things up by
23256 changing the opcode. */
23257 if (newimm == (unsigned int) FAIL
23258 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23259 {
23260 /* No ? OK - try using two ADD instructions to generate
23261 the value. */
23262 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23263
c19d1205
ZW
23264 /* Yes - then make sure that the second instruction is
23265 also an add. */
23266 if (newimm != (unsigned int) FAIL)
23267 newinsn = temp;
23268 /* Still No ? Try using a negated value. */
23269 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23270 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23271 /* Otherwise - give up. */
23272 else
23273 {
23274 as_bad_where (fixP->fx_file, fixP->fx_line,
23275 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23276 (long) value);
23277 break;
23278 }
b99bd4ef 23279
c19d1205
ZW
23280 /* Replace the first operand in the 2nd instruction (which
23281 is the PC) with the destination register. We have
23282 already added in the PC in the first instruction and we
23283 do not want to do it again. */
23284 newinsn &= ~ 0xf0000;
23285 newinsn |= ((newinsn & 0x0f000) << 4);
23286 }
b99bd4ef 23287
c19d1205
ZW
23288 newimm |= (temp & 0xfffff000);
23289 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23290
c19d1205
ZW
23291 highpart |= (newinsn & 0xfffff000);
23292 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23293 }
23294 break;
b99bd4ef 23295
c19d1205 23296 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23297 if (!fixP->fx_done && seg->use_rela_p)
23298 value = 0;
1a0670f3 23299 /* Fall through. */
00a97672 23300
c19d1205 23301 case BFD_RELOC_ARM_LITERAL:
26d97720 23302 sign = value > 0;
b99bd4ef 23303
c19d1205
ZW
23304 if (value < 0)
23305 value = - value;
b99bd4ef 23306
c19d1205 23307 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23308 {
c19d1205
ZW
23309 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23310 as_bad_where (fixP->fx_file, fixP->fx_line,
23311 _("invalid literal constant: pool needs to be closer"));
23312 else
23313 as_bad_where (fixP->fx_file, fixP->fx_line,
23314 _("bad immediate value for offset (%ld)"),
23315 (long) value);
23316 break;
f03698e6
RE
23317 }
23318
c19d1205 23319 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23320 if (value == 0)
23321 newval &= 0xfffff000;
23322 else
23323 {
23324 newval &= 0xff7ff000;
23325 newval |= value | (sign ? INDEX_UP : 0);
23326 }
c19d1205
ZW
23327 md_number_to_chars (buf, newval, INSN_SIZE);
23328 break;
b99bd4ef 23329
c19d1205
ZW
23330 case BFD_RELOC_ARM_OFFSET_IMM8:
23331 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23332 sign = value > 0;
b99bd4ef 23333
c19d1205
ZW
23334 if (value < 0)
23335 value = - value;
b99bd4ef 23336
c19d1205 23337 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23338 {
c19d1205
ZW
23339 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23340 as_bad_where (fixP->fx_file, fixP->fx_line,
23341 _("invalid literal constant: pool needs to be closer"));
23342 else
427d0db6
RM
23343 as_bad_where (fixP->fx_file, fixP->fx_line,
23344 _("bad immediate value for 8-bit offset (%ld)"),
23345 (long) value);
c19d1205 23346 break;
b99bd4ef
NC
23347 }
23348
c19d1205 23349 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23350 if (value == 0)
23351 newval &= 0xfffff0f0;
23352 else
23353 {
23354 newval &= 0xff7ff0f0;
23355 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23356 }
c19d1205
ZW
23357 md_number_to_chars (buf, newval, INSN_SIZE);
23358 break;
b99bd4ef 23359
c19d1205
ZW
23360 case BFD_RELOC_ARM_T32_OFFSET_U8:
23361 if (value < 0 || value > 1020 || value % 4 != 0)
23362 as_bad_where (fixP->fx_file, fixP->fx_line,
23363 _("bad immediate value for offset (%ld)"), (long) value);
23364 value /= 4;
b99bd4ef 23365
c19d1205 23366 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23367 newval |= value;
23368 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23369 break;
b99bd4ef 23370
c19d1205
ZW
23371 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23372 /* This is a complicated relocation used for all varieties of Thumb32
23373 load/store instruction with immediate offset:
23374
23375 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23376 *4, optional writeback(W)
c19d1205
ZW
23377 (doubleword load/store)
23378
23379 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23380 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23381 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23382 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23383 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23384
23385 Uppercase letters indicate bits that are already encoded at
23386 this point. Lowercase letters are our problem. For the
23387 second block of instructions, the secondary opcode nybble
23388 (bits 8..11) is present, and bit 23 is zero, even if this is
23389 a PC-relative operation. */
23390 newval = md_chars_to_number (buf, THUMB_SIZE);
23391 newval <<= 16;
23392 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23393
c19d1205 23394 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23395 {
c19d1205
ZW
23396 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23397 if (value >= 0)
23398 newval |= (1 << 23);
23399 else
23400 value = -value;
23401 if (value % 4 != 0)
23402 {
23403 as_bad_where (fixP->fx_file, fixP->fx_line,
23404 _("offset not a multiple of 4"));
23405 break;
23406 }
23407 value /= 4;
216d22bc 23408 if (value > 0xff)
c19d1205
ZW
23409 {
23410 as_bad_where (fixP->fx_file, fixP->fx_line,
23411 _("offset out of range"));
23412 break;
23413 }
23414 newval &= ~0xff;
b99bd4ef 23415 }
c19d1205 23416 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23417 {
c19d1205
ZW
23418 /* PC-relative, 12-bit offset. */
23419 if (value >= 0)
23420 newval |= (1 << 23);
23421 else
23422 value = -value;
216d22bc 23423 if (value > 0xfff)
c19d1205
ZW
23424 {
23425 as_bad_where (fixP->fx_file, fixP->fx_line,
23426 _("offset out of range"));
23427 break;
23428 }
23429 newval &= ~0xfff;
b99bd4ef 23430 }
c19d1205 23431 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23432 {
c19d1205
ZW
23433 /* Writeback: 8-bit, +/- offset. */
23434 if (value >= 0)
23435 newval |= (1 << 9);
23436 else
23437 value = -value;
216d22bc 23438 if (value > 0xff)
c19d1205
ZW
23439 {
23440 as_bad_where (fixP->fx_file, fixP->fx_line,
23441 _("offset out of range"));
23442 break;
23443 }
23444 newval &= ~0xff;
b99bd4ef 23445 }
c19d1205 23446 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23447 {
c19d1205 23448 /* T-instruction: positive 8-bit offset. */
216d22bc 23449 if (value < 0 || value > 0xff)
b99bd4ef 23450 {
c19d1205
ZW
23451 as_bad_where (fixP->fx_file, fixP->fx_line,
23452 _("offset out of range"));
23453 break;
b99bd4ef 23454 }
c19d1205
ZW
23455 newval &= ~0xff;
23456 newval |= value;
b99bd4ef
NC
23457 }
23458 else
b99bd4ef 23459 {
c19d1205
ZW
23460 /* Positive 12-bit or negative 8-bit offset. */
23461 int limit;
23462 if (value >= 0)
b99bd4ef 23463 {
c19d1205
ZW
23464 newval |= (1 << 23);
23465 limit = 0xfff;
23466 }
23467 else
23468 {
23469 value = -value;
23470 limit = 0xff;
23471 }
23472 if (value > limit)
23473 {
23474 as_bad_where (fixP->fx_file, fixP->fx_line,
23475 _("offset out of range"));
23476 break;
b99bd4ef 23477 }
c19d1205 23478 newval &= ~limit;
b99bd4ef 23479 }
b99bd4ef 23480
c19d1205
ZW
23481 newval |= value;
23482 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23483 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23484 break;
404ff6b5 23485
c19d1205
ZW
23486 case BFD_RELOC_ARM_SHIFT_IMM:
23487 newval = md_chars_to_number (buf, INSN_SIZE);
23488 if (((unsigned long) value) > 32
23489 || (value == 32
23490 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23491 {
23492 as_bad_where (fixP->fx_file, fixP->fx_line,
23493 _("shift expression is too large"));
23494 break;
23495 }
404ff6b5 23496
c19d1205
ZW
23497 if (value == 0)
23498 /* Shifts of zero must be done as lsl. */
23499 newval &= ~0x60;
23500 else if (value == 32)
23501 value = 0;
23502 newval &= 0xfffff07f;
23503 newval |= (value & 0x1f) << 7;
23504 md_number_to_chars (buf, newval, INSN_SIZE);
23505 break;
404ff6b5 23506
c19d1205 23507 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23508 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23509 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23510 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23511 /* We claim that this fixup has been processed here,
23512 even if in fact we generate an error because we do
23513 not have a reloc for it, so tc_gen_reloc will reject it. */
23514 fixP->fx_done = 1;
404ff6b5 23515
c19d1205
ZW
23516 if (fixP->fx_addsy
23517 && ! S_IS_DEFINED (fixP->fx_addsy))
23518 {
23519 as_bad_where (fixP->fx_file, fixP->fx_line,
23520 _("undefined symbol %s used as an immediate value"),
23521 S_GET_NAME (fixP->fx_addsy));
23522 break;
23523 }
404ff6b5 23524
c19d1205
ZW
23525 newval = md_chars_to_number (buf, THUMB_SIZE);
23526 newval <<= 16;
23527 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23528
16805f35 23529 newimm = FAIL;
bada4342
JW
23530 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23531 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23532 Thumb2 modified immediate encoding (T2). */
23533 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23534 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23535 {
23536 newimm = encode_thumb32_immediate (value);
23537 if (newimm == (unsigned int) FAIL)
23538 newimm = thumb32_negate_data_op (&newval, value);
23539 }
bada4342 23540 if (newimm == (unsigned int) FAIL)
92e90b6e 23541 {
bada4342 23542 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23543 {
bada4342
JW
23544 /* Turn add/sum into addw/subw. */
23545 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23546 newval = (newval & 0xfeffffff) | 0x02000000;
23547 /* No flat 12-bit imm encoding for addsw/subsw. */
23548 if ((newval & 0x00100000) == 0)
40f246e3 23549 {
bada4342
JW
23550 /* 12 bit immediate for addw/subw. */
23551 if (value < 0)
23552 {
23553 value = -value;
23554 newval ^= 0x00a00000;
23555 }
23556 if (value > 0xfff)
23557 newimm = (unsigned int) FAIL;
23558 else
23559 newimm = value;
23560 }
23561 }
23562 else
23563 {
23564 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23565 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23566 disassembling, MOV is preferred when there is no encoding
23567 overlap.
23568 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23569 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23570 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23571 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23572 && value >= 0 && value <=0xffff)
23573 {
23574 /* Toggle bit[25] to change encoding from T2 to T3. */
23575 newval ^= 1 << 25;
23576 /* Clear bits[19:16]. */
23577 newval &= 0xfff0ffff;
23578 /* Encoding high 4bits imm. Code below will encode the
23579 remaining low 12bits. */
23580 newval |= (value & 0x0000f000) << 4;
23581 newimm = value & 0x00000fff;
40f246e3 23582 }
e9f89963 23583 }
92e90b6e 23584 }
cc8a6dd0 23585
c19d1205 23586 if (newimm == (unsigned int)FAIL)
3631a3c8 23587 {
c19d1205
ZW
23588 as_bad_where (fixP->fx_file, fixP->fx_line,
23589 _("invalid constant (%lx) after fixup"),
23590 (unsigned long) value);
23591 break;
3631a3c8
NC
23592 }
23593
c19d1205
ZW
23594 newval |= (newimm & 0x800) << 15;
23595 newval |= (newimm & 0x700) << 4;
23596 newval |= (newimm & 0x0ff);
cc8a6dd0 23597
c19d1205
ZW
23598 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23599 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23600 break;
a737bd4d 23601
3eb17e6b 23602 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23603 if (((unsigned long) value) > 0xffff)
23604 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23605 _("invalid smc expression"));
2fc8bdac 23606 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23607 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23608 md_number_to_chars (buf, newval, INSN_SIZE);
23609 break;
a737bd4d 23610
90ec0d68
MGD
23611 case BFD_RELOC_ARM_HVC:
23612 if (((unsigned long) value) > 0xffff)
23613 as_bad_where (fixP->fx_file, fixP->fx_line,
23614 _("invalid hvc expression"));
23615 newval = md_chars_to_number (buf, INSN_SIZE);
23616 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23617 md_number_to_chars (buf, newval, INSN_SIZE);
23618 break;
23619
c19d1205 23620 case BFD_RELOC_ARM_SWI:
adbaf948 23621 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23622 {
23623 if (((unsigned long) value) > 0xff)
23624 as_bad_where (fixP->fx_file, fixP->fx_line,
23625 _("invalid swi expression"));
2fc8bdac 23626 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23627 newval |= value;
23628 md_number_to_chars (buf, newval, THUMB_SIZE);
23629 }
23630 else
23631 {
23632 if (((unsigned long) value) > 0x00ffffff)
23633 as_bad_where (fixP->fx_file, fixP->fx_line,
23634 _("invalid swi expression"));
2fc8bdac 23635 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23636 newval |= value;
23637 md_number_to_chars (buf, newval, INSN_SIZE);
23638 }
23639 break;
a737bd4d 23640
c19d1205
ZW
23641 case BFD_RELOC_ARM_MULTI:
23642 if (((unsigned long) value) > 0xffff)
23643 as_bad_where (fixP->fx_file, fixP->fx_line,
23644 _("invalid expression in load/store multiple"));
23645 newval = value | md_chars_to_number (buf, INSN_SIZE);
23646 md_number_to_chars (buf, newval, INSN_SIZE);
23647 break;
a737bd4d 23648
c19d1205 23649#ifdef OBJ_ELF
39b41c9c 23650 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23651
23652 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23653 && fixP->fx_addsy
34e77a92 23654 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23655 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23656 && THUMB_IS_FUNC (fixP->fx_addsy))
23657 /* Flip the bl to blx. This is a simple flip
23658 bit here because we generate PCREL_CALL for
23659 unconditional bls. */
23660 {
23661 newval = md_chars_to_number (buf, INSN_SIZE);
23662 newval = newval | 0x10000000;
23663 md_number_to_chars (buf, newval, INSN_SIZE);
23664 temp = 1;
23665 fixP->fx_done = 1;
23666 }
39b41c9c
PB
23667 else
23668 temp = 3;
23669 goto arm_branch_common;
23670
23671 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23672 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23673 && fixP->fx_addsy
34e77a92 23674 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23675 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23676 && THUMB_IS_FUNC (fixP->fx_addsy))
23677 {
23678 /* This would map to a bl<cond>, b<cond>,
23679 b<always> to a Thumb function. We
23680 need to force a relocation for this particular
23681 case. */
23682 newval = md_chars_to_number (buf, INSN_SIZE);
23683 fixP->fx_done = 0;
23684 }
1a0670f3 23685 /* Fall through. */
267bf995 23686
2fc8bdac 23687 case BFD_RELOC_ARM_PLT32:
c19d1205 23688#endif
39b41c9c
PB
23689 case BFD_RELOC_ARM_PCREL_BRANCH:
23690 temp = 3;
23691 goto arm_branch_common;
a737bd4d 23692
39b41c9c 23693 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23694
39b41c9c 23695 temp = 1;
267bf995
RR
23696 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23697 && fixP->fx_addsy
34e77a92 23698 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23699 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23700 && ARM_IS_FUNC (fixP->fx_addsy))
23701 {
23702 /* Flip the blx to a bl and warn. */
23703 const char *name = S_GET_NAME (fixP->fx_addsy);
23704 newval = 0xeb000000;
23705 as_warn_where (fixP->fx_file, fixP->fx_line,
23706 _("blx to '%s' an ARM ISA state function changed to bl"),
23707 name);
23708 md_number_to_chars (buf, newval, INSN_SIZE);
23709 temp = 3;
23710 fixP->fx_done = 1;
23711 }
23712
23713#ifdef OBJ_ELF
23714 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23715 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23716#endif
23717
39b41c9c 23718 arm_branch_common:
c19d1205 23719 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23720 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23721 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23722 also be clear. */
39b41c9c 23723 if (value & temp)
c19d1205 23724 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23725 _("misaligned branch destination"));
23726 if ((value & (offsetT)0xfe000000) != (offsetT)0
23727 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23728 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23729
2fc8bdac 23730 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23731 {
2fc8bdac
ZW
23732 newval = md_chars_to_number (buf, INSN_SIZE);
23733 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23734 /* Set the H bit on BLX instructions. */
23735 if (temp == 1)
23736 {
23737 if (value & 2)
23738 newval |= 0x01000000;
23739 else
23740 newval &= ~0x01000000;
23741 }
2fc8bdac 23742 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23743 }
c19d1205 23744 break;
a737bd4d 23745
25fe350b
MS
23746 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23747 /* CBZ can only branch forward. */
a737bd4d 23748
738755b0 23749 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23750 (which, strictly speaking, are prohibited) will be turned into
23751 no-ops.
738755b0
MS
23752
23753 FIXME: It may be better to remove the instruction completely and
23754 perform relaxation. */
23755 if (value == -2)
2fc8bdac
ZW
23756 {
23757 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23758 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23759 md_number_to_chars (buf, newval, THUMB_SIZE);
23760 }
738755b0
MS
23761 else
23762 {
23763 if (value & ~0x7e)
08f10d51 23764 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23765
477330fc 23766 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23767 {
23768 newval = md_chars_to_number (buf, THUMB_SIZE);
23769 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23770 md_number_to_chars (buf, newval, THUMB_SIZE);
23771 }
23772 }
c19d1205 23773 break;
a737bd4d 23774
c19d1205 23775 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23776 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23777 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23778
2fc8bdac
ZW
23779 if (fixP->fx_done || !seg->use_rela_p)
23780 {
23781 newval = md_chars_to_number (buf, THUMB_SIZE);
23782 newval |= (value & 0x1ff) >> 1;
23783 md_number_to_chars (buf, newval, THUMB_SIZE);
23784 }
c19d1205 23785 break;
a737bd4d 23786
c19d1205 23787 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23788 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23789 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23790
2fc8bdac
ZW
23791 if (fixP->fx_done || !seg->use_rela_p)
23792 {
23793 newval = md_chars_to_number (buf, THUMB_SIZE);
23794 newval |= (value & 0xfff) >> 1;
23795 md_number_to_chars (buf, newval, THUMB_SIZE);
23796 }
c19d1205 23797 break;
a737bd4d 23798
c19d1205 23799 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23800 if (fixP->fx_addsy
23801 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23802 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23803 && ARM_IS_FUNC (fixP->fx_addsy)
23804 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23805 {
23806 /* Force a relocation for a branch 20 bits wide. */
23807 fixP->fx_done = 0;
23808 }
08f10d51 23809 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23810 as_bad_where (fixP->fx_file, fixP->fx_line,
23811 _("conditional branch out of range"));
404ff6b5 23812
2fc8bdac
ZW
23813 if (fixP->fx_done || !seg->use_rela_p)
23814 {
23815 offsetT newval2;
23816 addressT S, J1, J2, lo, hi;
404ff6b5 23817
2fc8bdac
ZW
23818 S = (value & 0x00100000) >> 20;
23819 J2 = (value & 0x00080000) >> 19;
23820 J1 = (value & 0x00040000) >> 18;
23821 hi = (value & 0x0003f000) >> 12;
23822 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23823
2fc8bdac
ZW
23824 newval = md_chars_to_number (buf, THUMB_SIZE);
23825 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23826 newval |= (S << 10) | hi;
23827 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23828 md_number_to_chars (buf, newval, THUMB_SIZE);
23829 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23830 }
c19d1205 23831 break;
6c43fab6 23832
c19d1205 23833 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23834 /* If there is a blx from a thumb state function to
23835 another thumb function flip this to a bl and warn
23836 about it. */
23837
23838 if (fixP->fx_addsy
34e77a92 23839 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23841 && THUMB_IS_FUNC (fixP->fx_addsy))
23842 {
23843 const char *name = S_GET_NAME (fixP->fx_addsy);
23844 as_warn_where (fixP->fx_file, fixP->fx_line,
23845 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23846 name);
23847 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23848 newval = newval | 0x1000;
23849 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23850 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23851 fixP->fx_done = 1;
23852 }
23853
23854
23855 goto thumb_bl_common;
23856
c19d1205 23857 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23858 /* A bl from Thumb state ISA to an internal ARM state function
23859 is converted to a blx. */
23860 if (fixP->fx_addsy
23861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23862 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23863 && ARM_IS_FUNC (fixP->fx_addsy)
23864 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23865 {
23866 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23867 newval = newval & ~0x1000;
23868 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23869 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23870 fixP->fx_done = 1;
23871 }
23872
23873 thumb_bl_common:
23874
2fc8bdac
ZW
23875 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23876 /* For a BLX instruction, make sure that the relocation is rounded up
23877 to a word boundary. This follows the semantics of the instruction
23878 which specifies that bit 1 of the target address will come from bit
23879 1 of the base address. */
d406f3e4
JB
23880 value = (value + 3) & ~ 3;
23881
23882#ifdef OBJ_ELF
23883 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23884 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23885 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23886#endif
404ff6b5 23887
2b2f5df9
NC
23888 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23889 {
fc289b0a 23890 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23891 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23892 else if ((value & ~0x1ffffff)
23893 && ((value & ~0x1ffffff) != ~0x1ffffff))
23894 as_bad_where (fixP->fx_file, fixP->fx_line,
23895 _("Thumb2 branch out of range"));
23896 }
4a42ebbc
RR
23897
23898 if (fixP->fx_done || !seg->use_rela_p)
23899 encode_thumb2_b_bl_offset (buf, value);
23900
c19d1205 23901 break;
404ff6b5 23902
c19d1205 23903 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23904 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23905 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23906
2fc8bdac 23907 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23908 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23909
2fc8bdac 23910 break;
a737bd4d 23911
2fc8bdac
ZW
23912 case BFD_RELOC_8:
23913 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23914 *buf = value;
c19d1205 23915 break;
a737bd4d 23916
c19d1205 23917 case BFD_RELOC_16:
2fc8bdac 23918 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23919 md_number_to_chars (buf, value, 2);
c19d1205 23920 break;
a737bd4d 23921
c19d1205 23922#ifdef OBJ_ELF
0855e32b
NS
23923 case BFD_RELOC_ARM_TLS_CALL:
23924 case BFD_RELOC_ARM_THM_TLS_CALL:
23925 case BFD_RELOC_ARM_TLS_DESCSEQ:
23926 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23927 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23928 case BFD_RELOC_ARM_TLS_GD32:
23929 case BFD_RELOC_ARM_TLS_LE32:
23930 case BFD_RELOC_ARM_TLS_IE32:
23931 case BFD_RELOC_ARM_TLS_LDM32:
23932 case BFD_RELOC_ARM_TLS_LDO32:
23933 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23934 break;
6c43fab6 23935
c19d1205
ZW
23936 case BFD_RELOC_ARM_GOT32:
23937 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23938 break;
b43420e6
NC
23939
23940 case BFD_RELOC_ARM_GOT_PREL:
23941 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23942 md_number_to_chars (buf, value, 4);
b43420e6
NC
23943 break;
23944
9a6f4e97
NS
23945 case BFD_RELOC_ARM_TARGET2:
23946 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23947 addend here for REL targets, because it won't be written out
23948 during reloc processing later. */
9a6f4e97
NS
23949 if (fixP->fx_done || !seg->use_rela_p)
23950 md_number_to_chars (buf, fixP->fx_offset, 4);
23951 break;
c19d1205 23952#endif
6c43fab6 23953
c19d1205
ZW
23954 case BFD_RELOC_RVA:
23955 case BFD_RELOC_32:
23956 case BFD_RELOC_ARM_TARGET1:
23957 case BFD_RELOC_ARM_ROSEGREL32:
23958 case BFD_RELOC_ARM_SBREL32:
23959 case BFD_RELOC_32_PCREL:
f0927246
NC
23960#ifdef TE_PE
23961 case BFD_RELOC_32_SECREL:
23962#endif
2fc8bdac 23963 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23964#ifdef TE_WINCE
23965 /* For WinCE we only do this for pcrel fixups. */
23966 if (fixP->fx_done || fixP->fx_pcrel)
23967#endif
23968 md_number_to_chars (buf, value, 4);
c19d1205 23969 break;
6c43fab6 23970
c19d1205
ZW
23971#ifdef OBJ_ELF
23972 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23973 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23974 {
23975 newval = md_chars_to_number (buf, 4) & 0x80000000;
23976 if ((value ^ (value >> 1)) & 0x40000000)
23977 {
23978 as_bad_where (fixP->fx_file, fixP->fx_line,
23979 _("rel31 relocation overflow"));
23980 }
23981 newval |= value & 0x7fffffff;
23982 md_number_to_chars (buf, newval, 4);
23983 }
23984 break;
c19d1205 23985#endif
a737bd4d 23986
c19d1205 23987 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23988 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23989 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23990 newval = md_chars_to_number (buf, INSN_SIZE);
23991 else
23992 newval = get_thumb32_insn (buf);
23993 if ((newval & 0x0f200f00) == 0x0d000900)
23994 {
23995 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23996 has permitted values that are multiples of 2, in the range 0
23997 to 510. */
23998 if (value < -510 || value > 510 || (value & 1))
23999 as_bad_where (fixP->fx_file, fixP->fx_line,
24000 _("co-processor offset out of range"));
24001 }
24002 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24003 as_bad_where (fixP->fx_file, fixP->fx_line,
24004 _("co-processor offset out of range"));
24005 cp_off_common:
26d97720 24006 sign = value > 0;
c19d1205
ZW
24007 if (value < 0)
24008 value = -value;
8f06b2d8
PB
24009 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24010 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24011 newval = md_chars_to_number (buf, INSN_SIZE);
24012 else
24013 newval = get_thumb32_insn (buf);
26d97720
NS
24014 if (value == 0)
24015 newval &= 0xffffff00;
24016 else
24017 {
24018 newval &= 0xff7fff00;
9db2f6b4
RL
24019 if ((newval & 0x0f200f00) == 0x0d000900)
24020 {
24021 /* This is a fp16 vstr/vldr.
24022
24023 It requires the immediate offset in the instruction is shifted
24024 left by 1 to be a half-word offset.
24025
24026 Here, left shift by 1 first, and later right shift by 2
24027 should get the right offset. */
24028 value <<= 1;
24029 }
26d97720
NS
24030 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24031 }
8f06b2d8
PB
24032 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24033 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24034 md_number_to_chars (buf, newval, INSN_SIZE);
24035 else
24036 put_thumb32_insn (buf, newval);
c19d1205 24037 break;
a737bd4d 24038
c19d1205 24039 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24040 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24041 if (value < -255 || value > 255)
24042 as_bad_where (fixP->fx_file, fixP->fx_line,
24043 _("co-processor offset out of range"));
df7849c5 24044 value *= 4;
c19d1205 24045 goto cp_off_common;
6c43fab6 24046
c19d1205
ZW
24047 case BFD_RELOC_ARM_THUMB_OFFSET:
24048 newval = md_chars_to_number (buf, THUMB_SIZE);
24049 /* Exactly what ranges, and where the offset is inserted depends
24050 on the type of instruction, we can establish this from the
24051 top 4 bits. */
24052 switch (newval >> 12)
24053 {
24054 case 4: /* PC load. */
24055 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24056 forced to zero for these loads; md_pcrel_from has already
24057 compensated for this. */
24058 if (value & 3)
24059 as_bad_where (fixP->fx_file, fixP->fx_line,
24060 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24061 (((unsigned long) fixP->fx_frag->fr_address
24062 + (unsigned long) fixP->fx_where) & ~3)
24063 + (unsigned long) value);
a737bd4d 24064
c19d1205
ZW
24065 if (value & ~0x3fc)
24066 as_bad_where (fixP->fx_file, fixP->fx_line,
24067 _("invalid offset, value too big (0x%08lX)"),
24068 (long) value);
a737bd4d 24069
c19d1205
ZW
24070 newval |= value >> 2;
24071 break;
a737bd4d 24072
c19d1205
ZW
24073 case 9: /* SP load/store. */
24074 if (value & ~0x3fc)
24075 as_bad_where (fixP->fx_file, fixP->fx_line,
24076 _("invalid offset, value too big (0x%08lX)"),
24077 (long) value);
24078 newval |= value >> 2;
24079 break;
6c43fab6 24080
c19d1205
ZW
24081 case 6: /* Word load/store. */
24082 if (value & ~0x7c)
24083 as_bad_where (fixP->fx_file, fixP->fx_line,
24084 _("invalid offset, value too big (0x%08lX)"),
24085 (long) value);
24086 newval |= value << 4; /* 6 - 2. */
24087 break;
a737bd4d 24088
c19d1205
ZW
24089 case 7: /* Byte load/store. */
24090 if (value & ~0x1f)
24091 as_bad_where (fixP->fx_file, fixP->fx_line,
24092 _("invalid offset, value too big (0x%08lX)"),
24093 (long) value);
24094 newval |= value << 6;
24095 break;
a737bd4d 24096
c19d1205
ZW
24097 case 8: /* Halfword load/store. */
24098 if (value & ~0x3e)
24099 as_bad_where (fixP->fx_file, fixP->fx_line,
24100 _("invalid offset, value too big (0x%08lX)"),
24101 (long) value);
24102 newval |= value << 5; /* 6 - 1. */
24103 break;
a737bd4d 24104
c19d1205
ZW
24105 default:
24106 as_bad_where (fixP->fx_file, fixP->fx_line,
24107 "Unable to process relocation for thumb opcode: %lx",
24108 (unsigned long) newval);
24109 break;
24110 }
24111 md_number_to_chars (buf, newval, THUMB_SIZE);
24112 break;
a737bd4d 24113
c19d1205
ZW
24114 case BFD_RELOC_ARM_THUMB_ADD:
24115 /* This is a complicated relocation, since we use it for all of
24116 the following immediate relocations:
a737bd4d 24117
c19d1205
ZW
24118 3bit ADD/SUB
24119 8bit ADD/SUB
24120 9bit ADD/SUB SP word-aligned
24121 10bit ADD PC/SP word-aligned
a737bd4d 24122
c19d1205
ZW
24123 The type of instruction being processed is encoded in the
24124 instruction field:
a737bd4d 24125
c19d1205
ZW
24126 0x8000 SUB
24127 0x00F0 Rd
24128 0x000F Rs
24129 */
24130 newval = md_chars_to_number (buf, THUMB_SIZE);
24131 {
24132 int rd = (newval >> 4) & 0xf;
24133 int rs = newval & 0xf;
24134 int subtract = !!(newval & 0x8000);
a737bd4d 24135
c19d1205
ZW
24136 /* Check for HI regs, only very restricted cases allowed:
24137 Adjusting SP, and using PC or SP to get an address. */
24138 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24139 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24140 as_bad_where (fixP->fx_file, fixP->fx_line,
24141 _("invalid Hi register with immediate"));
a737bd4d 24142
c19d1205
ZW
24143 /* If value is negative, choose the opposite instruction. */
24144 if (value < 0)
24145 {
24146 value = -value;
24147 subtract = !subtract;
24148 if (value < 0)
24149 as_bad_where (fixP->fx_file, fixP->fx_line,
24150 _("immediate value out of range"));
24151 }
a737bd4d 24152
c19d1205
ZW
24153 if (rd == REG_SP)
24154 {
75c11999 24155 if (value & ~0x1fc)
c19d1205
ZW
24156 as_bad_where (fixP->fx_file, fixP->fx_line,
24157 _("invalid immediate for stack address calculation"));
24158 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24159 newval |= value >> 2;
24160 }
24161 else if (rs == REG_PC || rs == REG_SP)
24162 {
c12d2c9d
NC
24163 /* PR gas/18541. If the addition is for a defined symbol
24164 within range of an ADR instruction then accept it. */
24165 if (subtract
24166 && value == 4
24167 && fixP->fx_addsy != NULL)
24168 {
24169 subtract = 0;
24170
24171 if (! S_IS_DEFINED (fixP->fx_addsy)
24172 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24173 || S_IS_WEAK (fixP->fx_addsy))
24174 {
24175 as_bad_where (fixP->fx_file, fixP->fx_line,
24176 _("address calculation needs a strongly defined nearby symbol"));
24177 }
24178 else
24179 {
24180 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24181
24182 /* Round up to the next 4-byte boundary. */
24183 if (v & 3)
24184 v = (v + 3) & ~ 3;
24185 else
24186 v += 4;
24187 v = S_GET_VALUE (fixP->fx_addsy) - v;
24188
24189 if (v & ~0x3fc)
24190 {
24191 as_bad_where (fixP->fx_file, fixP->fx_line,
24192 _("symbol too far away"));
24193 }
24194 else
24195 {
24196 fixP->fx_done = 1;
24197 value = v;
24198 }
24199 }
24200 }
24201
c19d1205
ZW
24202 if (subtract || value & ~0x3fc)
24203 as_bad_where (fixP->fx_file, fixP->fx_line,
24204 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24205 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24206 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24207 newval |= rd << 8;
24208 newval |= value >> 2;
24209 }
24210 else if (rs == rd)
24211 {
24212 if (value & ~0xff)
24213 as_bad_where (fixP->fx_file, fixP->fx_line,
24214 _("immediate value out of range"));
24215 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24216 newval |= (rd << 8) | value;
24217 }
24218 else
24219 {
24220 if (value & ~0x7)
24221 as_bad_where (fixP->fx_file, fixP->fx_line,
24222 _("immediate value out of range"));
24223 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24224 newval |= rd | (rs << 3) | (value << 6);
24225 }
24226 }
24227 md_number_to_chars (buf, newval, THUMB_SIZE);
24228 break;
a737bd4d 24229
c19d1205
ZW
24230 case BFD_RELOC_ARM_THUMB_IMM:
24231 newval = md_chars_to_number (buf, THUMB_SIZE);
24232 if (value < 0 || value > 255)
24233 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24234 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24235 (long) value);
24236 newval |= value;
24237 md_number_to_chars (buf, newval, THUMB_SIZE);
24238 break;
a737bd4d 24239
c19d1205
ZW
24240 case BFD_RELOC_ARM_THUMB_SHIFT:
24241 /* 5bit shift value (0..32). LSL cannot take 32. */
24242 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24243 temp = newval & 0xf800;
24244 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24245 as_bad_where (fixP->fx_file, fixP->fx_line,
24246 _("invalid shift value: %ld"), (long) value);
24247 /* Shifts of zero must be encoded as LSL. */
24248 if (value == 0)
24249 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24250 /* Shifts of 32 are encoded as zero. */
24251 else if (value == 32)
24252 value = 0;
24253 newval |= value << 6;
24254 md_number_to_chars (buf, newval, THUMB_SIZE);
24255 break;
a737bd4d 24256
c19d1205
ZW
24257 case BFD_RELOC_VTABLE_INHERIT:
24258 case BFD_RELOC_VTABLE_ENTRY:
24259 fixP->fx_done = 0;
24260 return;
6c43fab6 24261
b6895b4f
PB
24262 case BFD_RELOC_ARM_MOVW:
24263 case BFD_RELOC_ARM_MOVT:
24264 case BFD_RELOC_ARM_THUMB_MOVW:
24265 case BFD_RELOC_ARM_THUMB_MOVT:
24266 if (fixP->fx_done || !seg->use_rela_p)
24267 {
24268 /* REL format relocations are limited to a 16-bit addend. */
24269 if (!fixP->fx_done)
24270 {
39623e12 24271 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24272 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24273 _("offset out of range"));
b6895b4f
PB
24274 }
24275 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24276 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24277 {
24278 value >>= 16;
24279 }
24280
24281 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24282 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24283 {
24284 newval = get_thumb32_insn (buf);
24285 newval &= 0xfbf08f00;
24286 newval |= (value & 0xf000) << 4;
24287 newval |= (value & 0x0800) << 15;
24288 newval |= (value & 0x0700) << 4;
24289 newval |= (value & 0x00ff);
24290 put_thumb32_insn (buf, newval);
24291 }
24292 else
24293 {
24294 newval = md_chars_to_number (buf, 4);
24295 newval &= 0xfff0f000;
24296 newval |= value & 0x0fff;
24297 newval |= (value & 0xf000) << 4;
24298 md_number_to_chars (buf, newval, 4);
24299 }
24300 }
24301 return;
24302
72d98d16
MG
24303 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24304 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24305 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24306 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24307 gas_assert (!fixP->fx_done);
24308 {
24309 bfd_vma insn;
24310 bfd_boolean is_mov;
24311 bfd_vma encoded_addend = value;
24312
24313 /* Check that addend can be encoded in instruction. */
24314 if (!seg->use_rela_p && (value < 0 || value > 255))
24315 as_bad_where (fixP->fx_file, fixP->fx_line,
24316 _("the offset 0x%08lX is not representable"),
24317 (unsigned long) encoded_addend);
24318
24319 /* Extract the instruction. */
24320 insn = md_chars_to_number (buf, THUMB_SIZE);
24321 is_mov = (insn & 0xf800) == 0x2000;
24322
24323 /* Encode insn. */
24324 if (is_mov)
24325 {
24326 if (!seg->use_rela_p)
24327 insn |= encoded_addend;
24328 }
24329 else
24330 {
24331 int rd, rs;
24332
24333 /* Extract the instruction. */
24334 /* Encoding is the following
24335 0x8000 SUB
24336 0x00F0 Rd
24337 0x000F Rs
24338 */
24339 /* The following conditions must be true :
24340 - ADD
24341 - Rd == Rs
24342 - Rd <= 7
24343 */
24344 rd = (insn >> 4) & 0xf;
24345 rs = insn & 0xf;
24346 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24347 as_bad_where (fixP->fx_file, fixP->fx_line,
24348 _("Unable to process relocation for thumb opcode: %lx"),
24349 (unsigned long) insn);
24350
24351 /* Encode as ADD immediate8 thumb 1 code. */
24352 insn = 0x3000 | (rd << 8);
24353
24354 /* Place the encoded addend into the first 8 bits of the
24355 instruction. */
24356 if (!seg->use_rela_p)
24357 insn |= encoded_addend;
24358 }
24359
24360 /* Update the instruction. */
24361 md_number_to_chars (buf, insn, THUMB_SIZE);
24362 }
24363 break;
24364
4962c51a
MS
24365 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24366 case BFD_RELOC_ARM_ALU_PC_G0:
24367 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24368 case BFD_RELOC_ARM_ALU_PC_G1:
24369 case BFD_RELOC_ARM_ALU_PC_G2:
24370 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24371 case BFD_RELOC_ARM_ALU_SB_G0:
24372 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24373 case BFD_RELOC_ARM_ALU_SB_G1:
24374 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24375 gas_assert (!fixP->fx_done);
4962c51a
MS
24376 if (!seg->use_rela_p)
24377 {
477330fc
RM
24378 bfd_vma insn;
24379 bfd_vma encoded_addend;
24380 bfd_vma addend_abs = abs (value);
24381
24382 /* Check that the absolute value of the addend can be
24383 expressed as an 8-bit constant plus a rotation. */
24384 encoded_addend = encode_arm_immediate (addend_abs);
24385 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24386 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24387 _("the offset 0x%08lX is not representable"),
24388 (unsigned long) addend_abs);
24389
24390 /* Extract the instruction. */
24391 insn = md_chars_to_number (buf, INSN_SIZE);
24392
24393 /* If the addend is positive, use an ADD instruction.
24394 Otherwise use a SUB. Take care not to destroy the S bit. */
24395 insn &= 0xff1fffff;
24396 if (value < 0)
24397 insn |= 1 << 22;
24398 else
24399 insn |= 1 << 23;
24400
24401 /* Place the encoded addend into the first 12 bits of the
24402 instruction. */
24403 insn &= 0xfffff000;
24404 insn |= encoded_addend;
24405
24406 /* Update the instruction. */
24407 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24408 }
24409 break;
24410
24411 case BFD_RELOC_ARM_LDR_PC_G0:
24412 case BFD_RELOC_ARM_LDR_PC_G1:
24413 case BFD_RELOC_ARM_LDR_PC_G2:
24414 case BFD_RELOC_ARM_LDR_SB_G0:
24415 case BFD_RELOC_ARM_LDR_SB_G1:
24416 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24417 gas_assert (!fixP->fx_done);
4962c51a 24418 if (!seg->use_rela_p)
477330fc
RM
24419 {
24420 bfd_vma insn;
24421 bfd_vma addend_abs = abs (value);
4962c51a 24422
477330fc
RM
24423 /* Check that the absolute value of the addend can be
24424 encoded in 12 bits. */
24425 if (addend_abs >= 0x1000)
4962c51a 24426 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24427 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24428 (unsigned long) addend_abs);
24429
24430 /* Extract the instruction. */
24431 insn = md_chars_to_number (buf, INSN_SIZE);
24432
24433 /* If the addend is negative, clear bit 23 of the instruction.
24434 Otherwise set it. */
24435 if (value < 0)
24436 insn &= ~(1 << 23);
24437 else
24438 insn |= 1 << 23;
24439
24440 /* Place the absolute value of the addend into the first 12 bits
24441 of the instruction. */
24442 insn &= 0xfffff000;
24443 insn |= addend_abs;
24444
24445 /* Update the instruction. */
24446 md_number_to_chars (buf, insn, INSN_SIZE);
24447 }
4962c51a
MS
24448 break;
24449
24450 case BFD_RELOC_ARM_LDRS_PC_G0:
24451 case BFD_RELOC_ARM_LDRS_PC_G1:
24452 case BFD_RELOC_ARM_LDRS_PC_G2:
24453 case BFD_RELOC_ARM_LDRS_SB_G0:
24454 case BFD_RELOC_ARM_LDRS_SB_G1:
24455 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24456 gas_assert (!fixP->fx_done);
4962c51a 24457 if (!seg->use_rela_p)
477330fc
RM
24458 {
24459 bfd_vma insn;
24460 bfd_vma addend_abs = abs (value);
4962c51a 24461
477330fc
RM
24462 /* Check that the absolute value of the addend can be
24463 encoded in 8 bits. */
24464 if (addend_abs >= 0x100)
4962c51a 24465 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24466 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24467 (unsigned long) addend_abs);
24468
24469 /* Extract the instruction. */
24470 insn = md_chars_to_number (buf, INSN_SIZE);
24471
24472 /* If the addend is negative, clear bit 23 of the instruction.
24473 Otherwise set it. */
24474 if (value < 0)
24475 insn &= ~(1 << 23);
24476 else
24477 insn |= 1 << 23;
24478
24479 /* Place the first four bits of the absolute value of the addend
24480 into the first 4 bits of the instruction, and the remaining
24481 four into bits 8 .. 11. */
24482 insn &= 0xfffff0f0;
24483 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24484
24485 /* Update the instruction. */
24486 md_number_to_chars (buf, insn, INSN_SIZE);
24487 }
4962c51a
MS
24488 break;
24489
24490 case BFD_RELOC_ARM_LDC_PC_G0:
24491 case BFD_RELOC_ARM_LDC_PC_G1:
24492 case BFD_RELOC_ARM_LDC_PC_G2:
24493 case BFD_RELOC_ARM_LDC_SB_G0:
24494 case BFD_RELOC_ARM_LDC_SB_G1:
24495 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24496 gas_assert (!fixP->fx_done);
4962c51a 24497 if (!seg->use_rela_p)
477330fc
RM
24498 {
24499 bfd_vma insn;
24500 bfd_vma addend_abs = abs (value);
4962c51a 24501
477330fc
RM
24502 /* Check that the absolute value of the addend is a multiple of
24503 four and, when divided by four, fits in 8 bits. */
24504 if (addend_abs & 0x3)
4962c51a 24505 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24506 _("bad offset 0x%08lX (must be word-aligned)"),
24507 (unsigned long) addend_abs);
4962c51a 24508
477330fc 24509 if ((addend_abs >> 2) > 0xff)
4962c51a 24510 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24511 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24512 (unsigned long) addend_abs);
24513
24514 /* Extract the instruction. */
24515 insn = md_chars_to_number (buf, INSN_SIZE);
24516
24517 /* If the addend is negative, clear bit 23 of the instruction.
24518 Otherwise set it. */
24519 if (value < 0)
24520 insn &= ~(1 << 23);
24521 else
24522 insn |= 1 << 23;
24523
24524 /* Place the addend (divided by four) into the first eight
24525 bits of the instruction. */
24526 insn &= 0xfffffff0;
24527 insn |= addend_abs >> 2;
24528
24529 /* Update the instruction. */
24530 md_number_to_chars (buf, insn, INSN_SIZE);
24531 }
4962c51a
MS
24532 break;
24533
845b51d6
PB
24534 case BFD_RELOC_ARM_V4BX:
24535 /* This will need to go in the object file. */
24536 fixP->fx_done = 0;
24537 break;
24538
c19d1205
ZW
24539 case BFD_RELOC_UNUSED:
24540 default:
24541 as_bad_where (fixP->fx_file, fixP->fx_line,
24542 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24543 }
6c43fab6
RE
24544}
24545
c19d1205
ZW
24546/* Translate internal representation of relocation info to BFD target
24547 format. */
a737bd4d 24548
c19d1205 24549arelent *
00a97672 24550tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24551{
c19d1205
ZW
24552 arelent * reloc;
24553 bfd_reloc_code_real_type code;
a737bd4d 24554
325801bd 24555 reloc = XNEW (arelent);
a737bd4d 24556
325801bd 24557 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24558 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24559 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24560
2fc8bdac 24561 if (fixp->fx_pcrel)
00a97672
RS
24562 {
24563 if (section->use_rela_p)
24564 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24565 else
24566 fixp->fx_offset = reloc->address;
24567 }
c19d1205 24568 reloc->addend = fixp->fx_offset;
a737bd4d 24569
c19d1205 24570 switch (fixp->fx_r_type)
a737bd4d 24571 {
c19d1205
ZW
24572 case BFD_RELOC_8:
24573 if (fixp->fx_pcrel)
24574 {
24575 code = BFD_RELOC_8_PCREL;
24576 break;
24577 }
1a0670f3 24578 /* Fall through. */
a737bd4d 24579
c19d1205
ZW
24580 case BFD_RELOC_16:
24581 if (fixp->fx_pcrel)
24582 {
24583 code = BFD_RELOC_16_PCREL;
24584 break;
24585 }
1a0670f3 24586 /* Fall through. */
6c43fab6 24587
c19d1205
ZW
24588 case BFD_RELOC_32:
24589 if (fixp->fx_pcrel)
24590 {
24591 code = BFD_RELOC_32_PCREL;
24592 break;
24593 }
1a0670f3 24594 /* Fall through. */
a737bd4d 24595
b6895b4f
PB
24596 case BFD_RELOC_ARM_MOVW:
24597 if (fixp->fx_pcrel)
24598 {
24599 code = BFD_RELOC_ARM_MOVW_PCREL;
24600 break;
24601 }
1a0670f3 24602 /* Fall through. */
b6895b4f
PB
24603
24604 case BFD_RELOC_ARM_MOVT:
24605 if (fixp->fx_pcrel)
24606 {
24607 code = BFD_RELOC_ARM_MOVT_PCREL;
24608 break;
24609 }
1a0670f3 24610 /* Fall through. */
b6895b4f
PB
24611
24612 case BFD_RELOC_ARM_THUMB_MOVW:
24613 if (fixp->fx_pcrel)
24614 {
24615 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24616 break;
24617 }
1a0670f3 24618 /* Fall through. */
b6895b4f
PB
24619
24620 case BFD_RELOC_ARM_THUMB_MOVT:
24621 if (fixp->fx_pcrel)
24622 {
24623 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24624 break;
24625 }
1a0670f3 24626 /* Fall through. */
b6895b4f 24627
c19d1205
ZW
24628 case BFD_RELOC_NONE:
24629 case BFD_RELOC_ARM_PCREL_BRANCH:
24630 case BFD_RELOC_ARM_PCREL_BLX:
24631 case BFD_RELOC_RVA:
24632 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24633 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24634 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24635 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24636 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24637 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24638 case BFD_RELOC_VTABLE_ENTRY:
24639 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24640#ifdef TE_PE
24641 case BFD_RELOC_32_SECREL:
24642#endif
c19d1205
ZW
24643 code = fixp->fx_r_type;
24644 break;
a737bd4d 24645
00adf2d4
JB
24646 case BFD_RELOC_THUMB_PCREL_BLX:
24647#ifdef OBJ_ELF
24648 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24649 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24650 else
24651#endif
24652 code = BFD_RELOC_THUMB_PCREL_BLX;
24653 break;
24654
c19d1205
ZW
24655 case BFD_RELOC_ARM_LITERAL:
24656 case BFD_RELOC_ARM_HWLITERAL:
24657 /* If this is called then the a literal has
24658 been referenced across a section boundary. */
24659 as_bad_where (fixp->fx_file, fixp->fx_line,
24660 _("literal referenced across section boundary"));
24661 return NULL;
a737bd4d 24662
c19d1205 24663#ifdef OBJ_ELF
0855e32b
NS
24664 case BFD_RELOC_ARM_TLS_CALL:
24665 case BFD_RELOC_ARM_THM_TLS_CALL:
24666 case BFD_RELOC_ARM_TLS_DESCSEQ:
24667 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24668 case BFD_RELOC_ARM_GOT32:
24669 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24670 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24671 case BFD_RELOC_ARM_PLT32:
24672 case BFD_RELOC_ARM_TARGET1:
24673 case BFD_RELOC_ARM_ROSEGREL32:
24674 case BFD_RELOC_ARM_SBREL32:
24675 case BFD_RELOC_ARM_PREL31:
24676 case BFD_RELOC_ARM_TARGET2:
c19d1205 24677 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24678 case BFD_RELOC_ARM_PCREL_CALL:
24679 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24680 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24681 case BFD_RELOC_ARM_ALU_PC_G0:
24682 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24683 case BFD_RELOC_ARM_ALU_PC_G1:
24684 case BFD_RELOC_ARM_ALU_PC_G2:
24685 case BFD_RELOC_ARM_LDR_PC_G0:
24686 case BFD_RELOC_ARM_LDR_PC_G1:
24687 case BFD_RELOC_ARM_LDR_PC_G2:
24688 case BFD_RELOC_ARM_LDRS_PC_G0:
24689 case BFD_RELOC_ARM_LDRS_PC_G1:
24690 case BFD_RELOC_ARM_LDRS_PC_G2:
24691 case BFD_RELOC_ARM_LDC_PC_G0:
24692 case BFD_RELOC_ARM_LDC_PC_G1:
24693 case BFD_RELOC_ARM_LDC_PC_G2:
24694 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24695 case BFD_RELOC_ARM_ALU_SB_G0:
24696 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24697 case BFD_RELOC_ARM_ALU_SB_G1:
24698 case BFD_RELOC_ARM_ALU_SB_G2:
24699 case BFD_RELOC_ARM_LDR_SB_G0:
24700 case BFD_RELOC_ARM_LDR_SB_G1:
24701 case BFD_RELOC_ARM_LDR_SB_G2:
24702 case BFD_RELOC_ARM_LDRS_SB_G0:
24703 case BFD_RELOC_ARM_LDRS_SB_G1:
24704 case BFD_RELOC_ARM_LDRS_SB_G2:
24705 case BFD_RELOC_ARM_LDC_SB_G0:
24706 case BFD_RELOC_ARM_LDC_SB_G1:
24707 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24708 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24709 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24710 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24711 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24712 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24713 code = fixp->fx_r_type;
24714 break;
a737bd4d 24715
0855e32b 24716 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24717 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24718 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24719 case BFD_RELOC_ARM_TLS_IE32:
24720 case BFD_RELOC_ARM_TLS_LDM32:
24721 /* BFD will include the symbol's address in the addend.
24722 But we don't want that, so subtract it out again here. */
24723 if (!S_IS_COMMON (fixp->fx_addsy))
24724 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24725 code = fixp->fx_r_type;
24726 break;
24727#endif
a737bd4d 24728
c19d1205
ZW
24729 case BFD_RELOC_ARM_IMMEDIATE:
24730 as_bad_where (fixp->fx_file, fixp->fx_line,
24731 _("internal relocation (type: IMMEDIATE) not fixed up"));
24732 return NULL;
a737bd4d 24733
c19d1205
ZW
24734 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24735 as_bad_where (fixp->fx_file, fixp->fx_line,
24736 _("ADRL used for a symbol not defined in the same file"));
24737 return NULL;
a737bd4d 24738
c19d1205 24739 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24740 if (section->use_rela_p)
24741 {
24742 code = fixp->fx_r_type;
24743 break;
24744 }
24745
c19d1205
ZW
24746 if (fixp->fx_addsy != NULL
24747 && !S_IS_DEFINED (fixp->fx_addsy)
24748 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24749 {
c19d1205
ZW
24750 as_bad_where (fixp->fx_file, fixp->fx_line,
24751 _("undefined local label `%s'"),
24752 S_GET_NAME (fixp->fx_addsy));
24753 return NULL;
a737bd4d
NC
24754 }
24755
c19d1205
ZW
24756 as_bad_where (fixp->fx_file, fixp->fx_line,
24757 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24758 return NULL;
a737bd4d 24759
c19d1205
ZW
24760 default:
24761 {
e0471c16 24762 const char * type;
6c43fab6 24763
c19d1205
ZW
24764 switch (fixp->fx_r_type)
24765 {
24766 case BFD_RELOC_NONE: type = "NONE"; break;
24767 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24768 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24769 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24770 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24771 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24772 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24773 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24774 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24775 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24776 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24777 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24778 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24779 default: type = _("<unknown>"); break;
24780 }
24781 as_bad_where (fixp->fx_file, fixp->fx_line,
24782 _("cannot represent %s relocation in this object file format"),
24783 type);
24784 return NULL;
24785 }
a737bd4d 24786 }
6c43fab6 24787
c19d1205
ZW
24788#ifdef OBJ_ELF
24789 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24790 && GOT_symbol
24791 && fixp->fx_addsy == GOT_symbol)
24792 {
24793 code = BFD_RELOC_ARM_GOTPC;
24794 reloc->addend = fixp->fx_offset = reloc->address;
24795 }
24796#endif
6c43fab6 24797
c19d1205 24798 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24799
c19d1205
ZW
24800 if (reloc->howto == NULL)
24801 {
24802 as_bad_where (fixp->fx_file, fixp->fx_line,
24803 _("cannot represent %s relocation in this object file format"),
24804 bfd_get_reloc_code_name (code));
24805 return NULL;
24806 }
6c43fab6 24807
c19d1205
ZW
24808 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24809 vtable entry to be used in the relocation's section offset. */
24810 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24811 reloc->address = fixp->fx_offset;
6c43fab6 24812
c19d1205 24813 return reloc;
6c43fab6
RE
24814}
24815
c19d1205 24816/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24817
c19d1205
ZW
24818void
24819cons_fix_new_arm (fragS * frag,
24820 int where,
24821 int size,
62ebcb5c
AM
24822 expressionS * exp,
24823 bfd_reloc_code_real_type reloc)
6c43fab6 24824{
c19d1205 24825 int pcrel = 0;
6c43fab6 24826
c19d1205
ZW
24827 /* Pick a reloc.
24828 FIXME: @@ Should look at CPU word size. */
24829 switch (size)
24830 {
24831 case 1:
62ebcb5c 24832 reloc = BFD_RELOC_8;
c19d1205
ZW
24833 break;
24834 case 2:
62ebcb5c 24835 reloc = BFD_RELOC_16;
c19d1205
ZW
24836 break;
24837 case 4:
24838 default:
62ebcb5c 24839 reloc = BFD_RELOC_32;
c19d1205
ZW
24840 break;
24841 case 8:
62ebcb5c 24842 reloc = BFD_RELOC_64;
c19d1205
ZW
24843 break;
24844 }
6c43fab6 24845
f0927246
NC
24846#ifdef TE_PE
24847 if (exp->X_op == O_secrel)
24848 {
24849 exp->X_op = O_symbol;
62ebcb5c 24850 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24851 }
24852#endif
24853
62ebcb5c 24854 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24855}
6c43fab6 24856
4343666d 24857#if defined (OBJ_COFF)
c19d1205
ZW
24858void
24859arm_validate_fix (fixS * fixP)
6c43fab6 24860{
c19d1205
ZW
24861 /* If the destination of the branch is a defined symbol which does not have
24862 the THUMB_FUNC attribute, then we must be calling a function which has
24863 the (interfacearm) attribute. We look for the Thumb entry point to that
24864 function and change the branch to refer to that function instead. */
24865 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24866 && fixP->fx_addsy != NULL
24867 && S_IS_DEFINED (fixP->fx_addsy)
24868 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24869 {
c19d1205 24870 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24871 }
c19d1205
ZW
24872}
24873#endif
6c43fab6 24874
267bf995 24875
c19d1205
ZW
24876int
24877arm_force_relocation (struct fix * fixp)
24878{
24879#if defined (OBJ_COFF) && defined (TE_PE)
24880 if (fixp->fx_r_type == BFD_RELOC_RVA)
24881 return 1;
24882#endif
6c43fab6 24883
267bf995
RR
24884 /* In case we have a call or a branch to a function in ARM ISA mode from
24885 a thumb function or vice-versa force the relocation. These relocations
24886 are cleared off for some cores that might have blx and simple transformations
24887 are possible. */
24888
24889#ifdef OBJ_ELF
24890 switch (fixp->fx_r_type)
24891 {
24892 case BFD_RELOC_ARM_PCREL_JUMP:
24893 case BFD_RELOC_ARM_PCREL_CALL:
24894 case BFD_RELOC_THUMB_PCREL_BLX:
24895 if (THUMB_IS_FUNC (fixp->fx_addsy))
24896 return 1;
24897 break;
24898
24899 case BFD_RELOC_ARM_PCREL_BLX:
24900 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24901 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24902 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24903 if (ARM_IS_FUNC (fixp->fx_addsy))
24904 return 1;
24905 break;
24906
24907 default:
24908 break;
24909 }
24910#endif
24911
b5884301
PB
24912 /* Resolve these relocations even if the symbol is extern or weak.
24913 Technically this is probably wrong due to symbol preemption.
24914 In practice these relocations do not have enough range to be useful
24915 at dynamic link time, and some code (e.g. in the Linux kernel)
24916 expects these references to be resolved. */
c19d1205
ZW
24917 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24918 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24919 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24920 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24921 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24922 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24923 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24924 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24925 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24926 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24927 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24928 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24929 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24930 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24931 return 0;
a737bd4d 24932
4962c51a
MS
24933 /* Always leave these relocations for the linker. */
24934 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24935 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24936 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24937 return 1;
24938
f0291e4c
PB
24939 /* Always generate relocations against function symbols. */
24940 if (fixp->fx_r_type == BFD_RELOC_32
24941 && fixp->fx_addsy
24942 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24943 return 1;
24944
c19d1205 24945 return generic_force_reloc (fixp);
404ff6b5
AH
24946}
24947
0ffdc86c 24948#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24949/* Relocations against function names must be left unadjusted,
24950 so that the linker can use this information to generate interworking
24951 stubs. The MIPS version of this function
c19d1205
ZW
24952 also prevents relocations that are mips-16 specific, but I do not
24953 know why it does this.
404ff6b5 24954
c19d1205
ZW
24955 FIXME:
24956 There is one other problem that ought to be addressed here, but
24957 which currently is not: Taking the address of a label (rather
24958 than a function) and then later jumping to that address. Such
24959 addresses also ought to have their bottom bit set (assuming that
24960 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24961
c19d1205
ZW
24962bfd_boolean
24963arm_fix_adjustable (fixS * fixP)
404ff6b5 24964{
c19d1205
ZW
24965 if (fixP->fx_addsy == NULL)
24966 return 1;
404ff6b5 24967
e28387c3
PB
24968 /* Preserve relocations against symbols with function type. */
24969 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24970 return FALSE;
e28387c3 24971
c19d1205
ZW
24972 if (THUMB_IS_FUNC (fixP->fx_addsy)
24973 && fixP->fx_subsy == NULL)
c921be7d 24974 return FALSE;
a737bd4d 24975
c19d1205
ZW
24976 /* We need the symbol name for the VTABLE entries. */
24977 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24978 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24979 return FALSE;
404ff6b5 24980
c19d1205
ZW
24981 /* Don't allow symbols to be discarded on GOT related relocs. */
24982 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24983 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24984 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24985 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24986 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24987 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24988 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24989 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24990 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24991 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24992 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24993 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24994 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24995 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24996 return FALSE;
a737bd4d 24997
4962c51a
MS
24998 /* Similarly for group relocations. */
24999 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25000 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25001 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25002 return FALSE;
4962c51a 25003
79947c54
CD
25004 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25005 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25006 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25007 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25008 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25009 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25010 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25011 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25012 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25013 return FALSE;
79947c54 25014
72d98d16
MG
25015 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25016 offsets, so keep these symbols. */
25017 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25018 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25019 return FALSE;
25020
c921be7d 25021 return TRUE;
a737bd4d 25022}
0ffdc86c
NC
25023#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25024
25025#ifdef OBJ_ELF
c19d1205
ZW
25026const char *
25027elf32_arm_target_format (void)
404ff6b5 25028{
c19d1205
ZW
25029#ifdef TE_SYMBIAN
25030 return (target_big_endian
25031 ? "elf32-bigarm-symbian"
25032 : "elf32-littlearm-symbian");
25033#elif defined (TE_VXWORKS)
25034 return (target_big_endian
25035 ? "elf32-bigarm-vxworks"
25036 : "elf32-littlearm-vxworks");
b38cadfb
NC
25037#elif defined (TE_NACL)
25038 return (target_big_endian
25039 ? "elf32-bigarm-nacl"
25040 : "elf32-littlearm-nacl");
c19d1205
ZW
25041#else
25042 if (target_big_endian)
25043 return "elf32-bigarm";
25044 else
25045 return "elf32-littlearm";
25046#endif
404ff6b5
AH
25047}
25048
c19d1205
ZW
25049void
25050armelf_frob_symbol (symbolS * symp,
25051 int * puntp)
404ff6b5 25052{
c19d1205
ZW
25053 elf_frob_symbol (symp, puntp);
25054}
25055#endif
404ff6b5 25056
c19d1205 25057/* MD interface: Finalization. */
a737bd4d 25058
c19d1205
ZW
25059void
25060arm_cleanup (void)
25061{
25062 literal_pool * pool;
a737bd4d 25063
e07e6e58
NC
25064 /* Ensure that all the IT blocks are properly closed. */
25065 check_it_blocks_finished ();
25066
c19d1205
ZW
25067 for (pool = list_of_pools; pool; pool = pool->next)
25068 {
5f4273c7 25069 /* Put it at the end of the relevant section. */
c19d1205
ZW
25070 subseg_set (pool->section, pool->sub_section);
25071#ifdef OBJ_ELF
25072 arm_elf_change_section ();
25073#endif
25074 s_ltorg (0);
25075 }
404ff6b5
AH
25076}
25077
cd000bff
DJ
25078#ifdef OBJ_ELF
25079/* Remove any excess mapping symbols generated for alignment frags in
25080 SEC. We may have created a mapping symbol before a zero byte
25081 alignment; remove it if there's a mapping symbol after the
25082 alignment. */
25083static void
25084check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25085 void *dummy ATTRIBUTE_UNUSED)
25086{
25087 segment_info_type *seginfo = seg_info (sec);
25088 fragS *fragp;
25089
25090 if (seginfo == NULL || seginfo->frchainP == NULL)
25091 return;
25092
25093 for (fragp = seginfo->frchainP->frch_root;
25094 fragp != NULL;
25095 fragp = fragp->fr_next)
25096 {
25097 symbolS *sym = fragp->tc_frag_data.last_map;
25098 fragS *next = fragp->fr_next;
25099
25100 /* Variable-sized frags have been converted to fixed size by
25101 this point. But if this was variable-sized to start with,
25102 there will be a fixed-size frag after it. So don't handle
25103 next == NULL. */
25104 if (sym == NULL || next == NULL)
25105 continue;
25106
25107 if (S_GET_VALUE (sym) < next->fr_address)
25108 /* Not at the end of this frag. */
25109 continue;
25110 know (S_GET_VALUE (sym) == next->fr_address);
25111
25112 do
25113 {
25114 if (next->tc_frag_data.first_map != NULL)
25115 {
25116 /* Next frag starts with a mapping symbol. Discard this
25117 one. */
25118 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25119 break;
25120 }
25121
25122 if (next->fr_next == NULL)
25123 {
25124 /* This mapping symbol is at the end of the section. Discard
25125 it. */
25126 know (next->fr_fix == 0 && next->fr_var == 0);
25127 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25128 break;
25129 }
25130
25131 /* As long as we have empty frags without any mapping symbols,
25132 keep looking. */
25133 /* If the next frag is non-empty and does not start with a
25134 mapping symbol, then this mapping symbol is required. */
25135 if (next->fr_address != next->fr_next->fr_address)
25136 break;
25137
25138 next = next->fr_next;
25139 }
25140 while (next != NULL);
25141 }
25142}
25143#endif
25144
c19d1205
ZW
25145/* Adjust the symbol table. This marks Thumb symbols as distinct from
25146 ARM ones. */
404ff6b5 25147
c19d1205
ZW
25148void
25149arm_adjust_symtab (void)
404ff6b5 25150{
c19d1205
ZW
25151#ifdef OBJ_COFF
25152 symbolS * sym;
404ff6b5 25153
c19d1205
ZW
25154 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25155 {
25156 if (ARM_IS_THUMB (sym))
25157 {
25158 if (THUMB_IS_FUNC (sym))
25159 {
25160 /* Mark the symbol as a Thumb function. */
25161 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25162 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25163 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25164
c19d1205
ZW
25165 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25166 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25167 else
25168 as_bad (_("%s: unexpected function type: %d"),
25169 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25170 }
25171 else switch (S_GET_STORAGE_CLASS (sym))
25172 {
25173 case C_EXT:
25174 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25175 break;
25176 case C_STAT:
25177 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25178 break;
25179 case C_LABEL:
25180 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25181 break;
25182 default:
25183 /* Do nothing. */
25184 break;
25185 }
25186 }
a737bd4d 25187
c19d1205
ZW
25188 if (ARM_IS_INTERWORK (sym))
25189 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25190 }
c19d1205
ZW
25191#endif
25192#ifdef OBJ_ELF
25193 symbolS * sym;
25194 char bind;
404ff6b5 25195
c19d1205 25196 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25197 {
c19d1205
ZW
25198 if (ARM_IS_THUMB (sym))
25199 {
25200 elf_symbol_type * elf_sym;
404ff6b5 25201
c19d1205
ZW
25202 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25203 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25204
b0796911
PB
25205 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25206 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25207 {
25208 /* If it's a .thumb_func, declare it as so,
25209 otherwise tag label as .code 16. */
25210 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25211 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25212 ST_BRANCH_TO_THUMB);
3ba67470 25213 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25214 elf_sym->internal_elf_sym.st_info =
25215 ELF_ST_INFO (bind, STT_ARM_16BIT);
25216 }
25217 }
25218 }
cd000bff
DJ
25219
25220 /* Remove any overlapping mapping symbols generated by alignment frags. */
25221 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25222 /* Now do generic ELF adjustments. */
25223 elf_adjust_symtab ();
c19d1205 25224#endif
404ff6b5
AH
25225}
25226
c19d1205 25227/* MD interface: Initialization. */
404ff6b5 25228
a737bd4d 25229static void
c19d1205 25230set_constant_flonums (void)
a737bd4d 25231{
c19d1205 25232 int i;
404ff6b5 25233
c19d1205
ZW
25234 for (i = 0; i < NUM_FLOAT_VALS; i++)
25235 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25236 abort ();
a737bd4d 25237}
404ff6b5 25238
3e9e4fcf
JB
25239/* Auto-select Thumb mode if it's the only available instruction set for the
25240 given architecture. */
25241
25242static void
25243autoselect_thumb_from_cpu_variant (void)
25244{
25245 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25246 opcode_select (16);
25247}
25248
c19d1205
ZW
25249void
25250md_begin (void)
a737bd4d 25251{
c19d1205
ZW
25252 unsigned mach;
25253 unsigned int i;
404ff6b5 25254
c19d1205
ZW
25255 if ( (arm_ops_hsh = hash_new ()) == NULL
25256 || (arm_cond_hsh = hash_new ()) == NULL
25257 || (arm_shift_hsh = hash_new ()) == NULL
25258 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25259 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25260 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25261 || (arm_reloc_hsh = hash_new ()) == NULL
25262 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25263 as_fatal (_("virtual memory exhausted"));
25264
25265 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25266 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25267 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25268 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25269 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25270 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25271 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25272 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25273 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25274 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25275 (void *) (v7m_psrs + i));
c19d1205 25276 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25277 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25278 for (i = 0;
25279 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25280 i++)
d3ce72d0 25281 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25282 (void *) (barrier_opt_names + i));
c19d1205 25283#ifdef OBJ_ELF
3da1d841
NC
25284 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25285 {
25286 struct reloc_entry * entry = reloc_names + i;
25287
25288 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25289 /* This makes encode_branch() use the EABI versions of this relocation. */
25290 entry->reloc = BFD_RELOC_UNUSED;
25291
25292 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25293 }
c19d1205
ZW
25294#endif
25295
25296 set_constant_flonums ();
404ff6b5 25297
c19d1205
ZW
25298 /* Set the cpu variant based on the command-line options. We prefer
25299 -mcpu= over -march= if both are set (as for GCC); and we prefer
25300 -mfpu= over any other way of setting the floating point unit.
25301 Use of legacy options with new options are faulted. */
e74cfd16 25302 if (legacy_cpu)
404ff6b5 25303 {
e74cfd16 25304 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25305 as_bad (_("use of old and new-style options to set CPU type"));
25306
25307 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25308 }
e74cfd16 25309 else if (!mcpu_cpu_opt)
c168ce07
TP
25310 {
25311 mcpu_cpu_opt = march_cpu_opt;
25312 dyn_mcpu_ext_opt = dyn_march_ext_opt;
25313 /* Avoid double free in arm_md_end. */
25314 dyn_march_ext_opt = NULL;
25315 }
404ff6b5 25316
e74cfd16 25317 if (legacy_fpu)
c19d1205 25318 {
e74cfd16 25319 if (mfpu_opt)
c19d1205 25320 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25321
25322 mfpu_opt = legacy_fpu;
25323 }
e74cfd16 25324 else if (!mfpu_opt)
03b1477f 25325 {
45eb4c1b
NS
25326#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25327 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25328 /* Some environments specify a default FPU. If they don't, infer it
25329 from the processor. */
e74cfd16 25330 if (mcpu_fpu_opt)
03b1477f
RE
25331 mfpu_opt = mcpu_fpu_opt;
25332 else
25333 mfpu_opt = march_fpu_opt;
39c2da32 25334#else
e74cfd16 25335 mfpu_opt = &fpu_default;
39c2da32 25336#endif
03b1477f
RE
25337 }
25338
e74cfd16 25339 if (!mfpu_opt)
03b1477f 25340 {
493cb6ef 25341 if (mcpu_cpu_opt != NULL)
e74cfd16 25342 mfpu_opt = &fpu_default;
493cb6ef 25343 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25344 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25345 else
e74cfd16 25346 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25347 }
25348
ee065d83 25349#ifdef CPU_DEFAULT
e74cfd16 25350 if (!mcpu_cpu_opt)
ee065d83 25351 {
e74cfd16
PB
25352 mcpu_cpu_opt = &cpu_default;
25353 selected_cpu = cpu_default;
ee065d83 25354 }
c168ce07
TP
25355 else if (dyn_mcpu_ext_opt)
25356 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
62785b09
TP
25357 else
25358 selected_cpu = *mcpu_cpu_opt;
e74cfd16 25359#else
c168ce07
TP
25360 if (mcpu_cpu_opt && dyn_mcpu_ext_opt)
25361 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
25362 else if (mcpu_cpu_opt)
e74cfd16 25363 selected_cpu = *mcpu_cpu_opt;
ee065d83 25364 else
e74cfd16 25365 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25366#endif
03b1477f 25367
e74cfd16 25368 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
25369 if (dyn_mcpu_ext_opt)
25370 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
03b1477f 25371
3e9e4fcf
JB
25372 autoselect_thumb_from_cpu_variant ();
25373
e74cfd16 25374 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25375
f17c130b 25376#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25377 {
7cc69913
NC
25378 unsigned int flags = 0;
25379
25380#if defined OBJ_ELF
25381 flags = meabi_flags;
d507cf36
PB
25382
25383 switch (meabi_flags)
33a392fb 25384 {
d507cf36 25385 case EF_ARM_EABI_UNKNOWN:
7cc69913 25386#endif
d507cf36
PB
25387 /* Set the flags in the private structure. */
25388 if (uses_apcs_26) flags |= F_APCS26;
25389 if (support_interwork) flags |= F_INTERWORK;
25390 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25391 if (pic_code) flags |= F_PIC;
e74cfd16 25392 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25393 flags |= F_SOFT_FLOAT;
25394
d507cf36
PB
25395 switch (mfloat_abi_opt)
25396 {
25397 case ARM_FLOAT_ABI_SOFT:
25398 case ARM_FLOAT_ABI_SOFTFP:
25399 flags |= F_SOFT_FLOAT;
25400 break;
33a392fb 25401
d507cf36
PB
25402 case ARM_FLOAT_ABI_HARD:
25403 if (flags & F_SOFT_FLOAT)
25404 as_bad (_("hard-float conflicts with specified fpu"));
25405 break;
25406 }
03b1477f 25407
e74cfd16
PB
25408 /* Using pure-endian doubles (even if soft-float). */
25409 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25410 flags |= F_VFP_FLOAT;
f17c130b 25411
fde78edd 25412#if defined OBJ_ELF
e74cfd16 25413 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25414 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25415 break;
25416
8cb51566 25417 case EF_ARM_EABI_VER4:
3a4a14e9 25418 case EF_ARM_EABI_VER5:
c19d1205 25419 /* No additional flags to set. */
d507cf36
PB
25420 break;
25421
25422 default:
25423 abort ();
25424 }
7cc69913 25425#endif
b99bd4ef
NC
25426 bfd_set_private_flags (stdoutput, flags);
25427
25428 /* We have run out flags in the COFF header to encode the
25429 status of ATPCS support, so instead we create a dummy,
c19d1205 25430 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25431 if (atpcs)
25432 {
25433 asection * sec;
25434
25435 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25436
25437 if (sec != NULL)
25438 {
25439 bfd_set_section_flags
25440 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25441 bfd_set_section_size (stdoutput, sec, 0);
25442 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25443 }
25444 }
7cc69913 25445 }
f17c130b 25446#endif
b99bd4ef
NC
25447
25448 /* Record the CPU type as well. */
2d447fca
JM
25449 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25450 mach = bfd_mach_arm_iWMMXt2;
25451 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25452 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25453 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25454 mach = bfd_mach_arm_XScale;
e74cfd16 25455 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25456 mach = bfd_mach_arm_ep9312;
e74cfd16 25457 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25458 mach = bfd_mach_arm_5TE;
e74cfd16 25459 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25460 {
e74cfd16 25461 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25462 mach = bfd_mach_arm_5T;
25463 else
25464 mach = bfd_mach_arm_5;
25465 }
e74cfd16 25466 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25467 {
e74cfd16 25468 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25469 mach = bfd_mach_arm_4T;
25470 else
25471 mach = bfd_mach_arm_4;
25472 }
e74cfd16 25473 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25474 mach = bfd_mach_arm_3M;
e74cfd16
PB
25475 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25476 mach = bfd_mach_arm_3;
25477 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25478 mach = bfd_mach_arm_2a;
25479 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25480 mach = bfd_mach_arm_2;
25481 else
25482 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25483
25484 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25485}
25486
c19d1205 25487/* Command line processing. */
b99bd4ef 25488
c19d1205
ZW
25489/* md_parse_option
25490 Invocation line includes a switch not recognized by the base assembler.
25491 See if it's a processor-specific option.
b99bd4ef 25492
c19d1205
ZW
25493 This routine is somewhat complicated by the need for backwards
25494 compatibility (since older releases of gcc can't be changed).
25495 The new options try to make the interface as compatible as
25496 possible with GCC.
b99bd4ef 25497
c19d1205 25498 New options (supported) are:
b99bd4ef 25499
c19d1205
ZW
25500 -mcpu=<cpu name> Assemble for selected processor
25501 -march=<architecture name> Assemble for selected architecture
25502 -mfpu=<fpu architecture> Assemble for selected FPU.
25503 -EB/-mbig-endian Big-endian
25504 -EL/-mlittle-endian Little-endian
25505 -k Generate PIC code
25506 -mthumb Start in Thumb mode
25507 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25508
278df34e 25509 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25510 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25511
c19d1205 25512 For now we will also provide support for:
b99bd4ef 25513
c19d1205
ZW
25514 -mapcs-32 32-bit Program counter
25515 -mapcs-26 26-bit Program counter
25516 -macps-float Floats passed in FP registers
25517 -mapcs-reentrant Reentrant code
25518 -matpcs
25519 (sometime these will probably be replaced with -mapcs=<list of options>
25520 and -matpcs=<list of options>)
b99bd4ef 25521
c19d1205
ZW
25522 The remaining options are only supported for back-wards compatibility.
25523 Cpu variants, the arm part is optional:
25524 -m[arm]1 Currently not supported.
25525 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25526 -m[arm]3 Arm 3 processor
25527 -m[arm]6[xx], Arm 6 processors
25528 -m[arm]7[xx][t][[d]m] Arm 7 processors
25529 -m[arm]8[10] Arm 8 processors
25530 -m[arm]9[20][tdmi] Arm 9 processors
25531 -mstrongarm[110[0]] StrongARM processors
25532 -mxscale XScale processors
25533 -m[arm]v[2345[t[e]]] Arm architectures
25534 -mall All (except the ARM1)
25535 FP variants:
25536 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25537 -mfpe-old (No float load/store multiples)
25538 -mvfpxd VFP Single precision
25539 -mvfp All VFP
25540 -mno-fpu Disable all floating point instructions
b99bd4ef 25541
c19d1205
ZW
25542 The following CPU names are recognized:
25543 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25544 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25545 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25546 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25547 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25548 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25549 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25550
c19d1205 25551 */
b99bd4ef 25552
c19d1205 25553const char * md_shortopts = "m:k";
b99bd4ef 25554
c19d1205
ZW
25555#ifdef ARM_BI_ENDIAN
25556#define OPTION_EB (OPTION_MD_BASE + 0)
25557#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25558#else
c19d1205
ZW
25559#if TARGET_BYTES_BIG_ENDIAN
25560#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25561#else
c19d1205
ZW
25562#define OPTION_EL (OPTION_MD_BASE + 1)
25563#endif
b99bd4ef 25564#endif
845b51d6 25565#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25566
c19d1205 25567struct option md_longopts[] =
b99bd4ef 25568{
c19d1205
ZW
25569#ifdef OPTION_EB
25570 {"EB", no_argument, NULL, OPTION_EB},
25571#endif
25572#ifdef OPTION_EL
25573 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25574#endif
845b51d6 25575 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25576 {NULL, no_argument, NULL, 0}
25577};
b99bd4ef 25578
c19d1205 25579size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25580
c19d1205 25581struct arm_option_table
b99bd4ef 25582{
0198d5e6
TC
25583 const char * option; /* Option name to match. */
25584 const char * help; /* Help information. */
25585 int * var; /* Variable to change. */
25586 int value; /* What to change it to. */
25587 const char * deprecated; /* If non-null, print this message. */
c19d1205 25588};
b99bd4ef 25589
c19d1205
ZW
25590struct arm_option_table arm_opts[] =
25591{
25592 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25593 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25594 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25595 &support_interwork, 1, NULL},
25596 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25597 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25598 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25599 1, NULL},
25600 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25601 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25602 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25603 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25604 NULL},
b99bd4ef 25605
c19d1205
ZW
25606 /* These are recognized by the assembler, but have no affect on code. */
25607 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25608 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25609
25610 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25611 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25612 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25613 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25614 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25615 {NULL, NULL, NULL, 0, NULL}
25616};
25617
25618struct arm_legacy_option_table
25619{
0198d5e6
TC
25620 const char * option; /* Option name to match. */
25621 const arm_feature_set ** var; /* Variable to change. */
25622 const arm_feature_set value; /* What to change it to. */
25623 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25624};
b99bd4ef 25625
e74cfd16
PB
25626const struct arm_legacy_option_table arm_legacy_opts[] =
25627{
c19d1205
ZW
25628 /* DON'T add any new processors to this list -- we want the whole list
25629 to go away... Add them to the processors table instead. */
e74cfd16
PB
25630 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25631 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25632 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25633 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25634 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25635 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25636 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25637 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25638 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25639 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25640 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25641 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25642 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25643 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25644 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25645 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25646 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25647 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25648 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25649 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25650 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25651 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25652 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25653 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25654 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25655 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25656 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25657 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25658 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25659 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25660 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25661 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25662 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25663 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25664 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25665 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25666 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25667 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25668 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25669 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25670 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25671 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25672 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25673 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25674 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25675 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25676 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25677 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25678 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25679 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25680 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25681 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25682 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25683 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25684 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25685 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25686 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25687 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25688 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25689 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25690 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25691 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25692 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25693 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25694 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25695 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25696 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25697 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25698 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25699 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25700 N_("use -mcpu=strongarm110")},
e74cfd16 25701 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25702 N_("use -mcpu=strongarm1100")},
e74cfd16 25703 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25704 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25705 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25706 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25707 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25708
c19d1205 25709 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25710 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25711 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25712 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25713 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25714 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25715 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25716 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25717 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25718 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25719 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25720 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25721 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25722 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25723 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25724 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25725 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25726 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25727 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25728
c19d1205 25729 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25730 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25731 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25732 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25733 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25734 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25735
e74cfd16 25736 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25737};
7ed4c4c5 25738
c19d1205 25739struct arm_cpu_option_table
7ed4c4c5 25740{
0198d5e6
TC
25741 const char * name;
25742 size_t name_len;
25743 const arm_feature_set value;
25744 const arm_feature_set ext;
c19d1205
ZW
25745 /* For some CPUs we assume an FPU unless the user explicitly sets
25746 -mfpu=... */
0198d5e6 25747 const arm_feature_set default_fpu;
ee065d83
PB
25748 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25749 case. */
0198d5e6 25750 const char * canonical_name;
c19d1205 25751};
7ed4c4c5 25752
c19d1205
ZW
25753/* This list should, at a minimum, contain all the cpu names
25754 recognized by GCC. */
996b5569 25755#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25756
e74cfd16 25757static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25758{
996b5569
TP
25759 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25760 ARM_ARCH_NONE,
25761 FPU_ARCH_FPA),
25762 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25763 ARM_ARCH_NONE,
25764 FPU_ARCH_FPA),
25765 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25766 ARM_ARCH_NONE,
25767 FPU_ARCH_FPA),
25768 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25769 ARM_ARCH_NONE,
25770 FPU_ARCH_FPA),
25771 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25772 ARM_ARCH_NONE,
25773 FPU_ARCH_FPA),
25774 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25775 ARM_ARCH_NONE,
25776 FPU_ARCH_FPA),
25777 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25778 ARM_ARCH_NONE,
25779 FPU_ARCH_FPA),
25780 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25781 ARM_ARCH_NONE,
25782 FPU_ARCH_FPA),
25783 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25784 ARM_ARCH_NONE,
25785 FPU_ARCH_FPA),
25786 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25787 ARM_ARCH_NONE,
25788 FPU_ARCH_FPA),
25789 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25790 ARM_ARCH_NONE,
25791 FPU_ARCH_FPA),
25792 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25793 ARM_ARCH_NONE,
25794 FPU_ARCH_FPA),
25795 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25796 ARM_ARCH_NONE,
25797 FPU_ARCH_FPA),
25798 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25799 ARM_ARCH_NONE,
25800 FPU_ARCH_FPA),
25801 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25802 ARM_ARCH_NONE,
25803 FPU_ARCH_FPA),
25804 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25805 ARM_ARCH_NONE,
25806 FPU_ARCH_FPA),
25807 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25808 ARM_ARCH_NONE,
25809 FPU_ARCH_FPA),
25810 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25811 ARM_ARCH_NONE,
25812 FPU_ARCH_FPA),
25813 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25814 ARM_ARCH_NONE,
25815 FPU_ARCH_FPA),
25816 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25817 ARM_ARCH_NONE,
25818 FPU_ARCH_FPA),
25819 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25820 ARM_ARCH_NONE,
25821 FPU_ARCH_FPA),
25822 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25823 ARM_ARCH_NONE,
25824 FPU_ARCH_FPA),
25825 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25826 ARM_ARCH_NONE,
25827 FPU_ARCH_FPA),
25828 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25829 ARM_ARCH_NONE,
25830 FPU_ARCH_FPA),
25831 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25832 ARM_ARCH_NONE,
25833 FPU_ARCH_FPA),
25834 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25835 ARM_ARCH_NONE,
25836 FPU_ARCH_FPA),
25837 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25838 ARM_ARCH_NONE,
25839 FPU_ARCH_FPA),
25840 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25841 ARM_ARCH_NONE,
25842 FPU_ARCH_FPA),
25843 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25844 ARM_ARCH_NONE,
25845 FPU_ARCH_FPA),
25846 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25847 ARM_ARCH_NONE,
25848 FPU_ARCH_FPA),
25849 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25850 ARM_ARCH_NONE,
25851 FPU_ARCH_FPA),
25852 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25853 ARM_ARCH_NONE,
25854 FPU_ARCH_FPA),
25855 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25856 ARM_ARCH_NONE,
25857 FPU_ARCH_FPA),
25858 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25859 ARM_ARCH_NONE,
25860 FPU_ARCH_FPA),
25861 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25862 ARM_ARCH_NONE,
25863 FPU_ARCH_FPA),
25864 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25865 ARM_ARCH_NONE,
25866 FPU_ARCH_FPA),
25867 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25868 ARM_ARCH_NONE,
25869 FPU_ARCH_FPA),
25870 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25871 ARM_ARCH_NONE,
25872 FPU_ARCH_FPA),
25873 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25874 ARM_ARCH_NONE,
25875 FPU_ARCH_FPA),
25876 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25877 ARM_ARCH_NONE,
25878 FPU_ARCH_FPA),
25879 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25880 ARM_ARCH_NONE,
25881 FPU_ARCH_FPA),
25882 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25883 ARM_ARCH_NONE,
25884 FPU_ARCH_FPA),
25885 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25886 ARM_ARCH_NONE,
25887 FPU_ARCH_FPA),
25888 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25889 ARM_ARCH_NONE,
25890 FPU_ARCH_FPA),
25891 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25892 ARM_ARCH_NONE,
25893 FPU_ARCH_FPA),
25894 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25895 ARM_ARCH_NONE,
25896 FPU_ARCH_FPA),
25897
c19d1205
ZW
25898 /* For V5 or later processors we default to using VFP; but the user
25899 should really set the FPU type explicitly. */
996b5569
TP
25900 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25901 ARM_ARCH_NONE,
25902 FPU_ARCH_VFP_V2),
25903 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25904 ARM_ARCH_NONE,
25905 FPU_ARCH_VFP_V2),
25906 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25907 ARM_ARCH_NONE,
25908 FPU_ARCH_VFP_V2),
25909 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25910 ARM_ARCH_NONE,
25911 FPU_ARCH_VFP_V2),
25912 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25913 ARM_ARCH_NONE,
25914 FPU_ARCH_VFP_V2),
25915 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25916 ARM_ARCH_NONE,
25917 FPU_ARCH_VFP_V2),
25918 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25919 ARM_ARCH_NONE,
25920 FPU_ARCH_VFP_V2),
25921 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25922 ARM_ARCH_NONE,
25923 FPU_ARCH_VFP_V2),
25924 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25925 ARM_ARCH_NONE,
25926 FPU_ARCH_VFP_V2),
25927 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25928 ARM_ARCH_NONE,
25929 FPU_ARCH_VFP_V2),
25930 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25931 ARM_ARCH_NONE,
25932 FPU_ARCH_VFP_V2),
25933 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25934 ARM_ARCH_NONE,
25935 FPU_ARCH_VFP_V2),
25936 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25937 ARM_ARCH_NONE,
25938 FPU_ARCH_VFP_V1),
25939 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25940 ARM_ARCH_NONE,
25941 FPU_ARCH_VFP_V1),
25942 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25943 ARM_ARCH_NONE,
25944 FPU_ARCH_VFP_V2),
25945 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25946 ARM_ARCH_NONE,
25947 FPU_ARCH_VFP_V2),
25948 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25949 ARM_ARCH_NONE,
25950 FPU_ARCH_VFP_V1),
25951 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25952 ARM_ARCH_NONE,
25953 FPU_ARCH_VFP_V2),
25954 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25955 ARM_ARCH_NONE,
25956 FPU_ARCH_VFP_V2),
25957 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25958 ARM_ARCH_NONE,
25959 FPU_ARCH_VFP_V2),
25960 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25961 ARM_ARCH_NONE,
25962 FPU_ARCH_VFP_V2),
25963 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25964 ARM_ARCH_NONE,
25965 FPU_ARCH_VFP_V2),
25966 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25967 ARM_ARCH_NONE,
25968 FPU_ARCH_VFP_V2),
25969 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25970 ARM_ARCH_NONE,
25971 FPU_ARCH_VFP_V2),
25972 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25973 ARM_ARCH_NONE,
25974 FPU_ARCH_VFP_V2),
25975 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25976 ARM_ARCH_NONE,
25977 FPU_ARCH_VFP_V2),
25978 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25979 ARM_ARCH_NONE,
25980 FPU_NONE),
25981 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25982 ARM_ARCH_NONE,
25983 FPU_NONE),
25984 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25985 ARM_ARCH_NONE,
25986 FPU_ARCH_VFP_V2),
25987 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25988 ARM_ARCH_NONE,
25989 FPU_ARCH_VFP_V2),
25990 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25991 ARM_ARCH_NONE,
25992 FPU_ARCH_VFP_V2),
25993 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25994 ARM_ARCH_NONE,
25995 FPU_NONE),
25996 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25997 ARM_ARCH_NONE,
25998 FPU_NONE),
25999 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26000 ARM_ARCH_NONE,
26001 FPU_ARCH_VFP_V2),
26002 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26003 ARM_ARCH_NONE,
26004 FPU_NONE),
26005 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26006 ARM_ARCH_NONE,
26007 FPU_ARCH_VFP_V2),
26008 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26009 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26010 FPU_NONE),
26011 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26012 ARM_ARCH_NONE,
26013 FPU_ARCH_NEON_VFP_V4),
26014 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26015 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26016 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26017 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26018 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26019 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26020 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26021 ARM_ARCH_NONE,
26022 FPU_ARCH_NEON_VFP_V4),
26023 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26024 ARM_ARCH_NONE,
26025 FPU_ARCH_NEON_VFP_V4),
26026 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26027 ARM_ARCH_NONE,
26028 FPU_ARCH_NEON_VFP_V4),
26029 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26030 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26031 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26032 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26033 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26034 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26035 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26036 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26037 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26038 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26039 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26040 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26041 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26042 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26043 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26044 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26045 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26046 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26047 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26048 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26049 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26050 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26051 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26052 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26053 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26054 ARM_ARCH_NONE,
26055 FPU_NONE),
26056 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26057 ARM_ARCH_NONE,
26058 FPU_ARCH_VFP_V3D16),
26059 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26060 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26061 FPU_NONE),
26062 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26063 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26064 FPU_ARCH_VFP_V3D16),
26065 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26066 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26067 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26068 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26069 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26070 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26071 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26072 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26073 FPU_NONE),
26074 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26075 ARM_ARCH_NONE,
26076 FPU_NONE),
26077 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26078 ARM_ARCH_NONE,
26079 FPU_NONE),
26080 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26081 ARM_ARCH_NONE,
26082 FPU_NONE),
26083 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26084 ARM_ARCH_NONE,
26085 FPU_NONE),
26086 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26087 ARM_ARCH_NONE,
26088 FPU_NONE),
26089 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26090 ARM_ARCH_NONE,
26091 FPU_NONE),
26092 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26093 ARM_ARCH_NONE,
26094 FPU_NONE),
26095 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26096 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26097 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 26098
c19d1205 26099 /* ??? XSCALE is really an architecture. */
996b5569
TP
26100 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26101 ARM_ARCH_NONE,
26102 FPU_ARCH_VFP_V2),
26103
c19d1205 26104 /* ??? iwmmxt is not a processor. */
996b5569
TP
26105 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26106 ARM_ARCH_NONE,
26107 FPU_ARCH_VFP_V2),
26108 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26109 ARM_ARCH_NONE,
26110 FPU_ARCH_VFP_V2),
26111 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26112 ARM_ARCH_NONE,
26113 FPU_ARCH_VFP_V2),
26114
0198d5e6 26115 /* Maverick. */
996b5569
TP
26116 ARM_CPU_OPT ("ep9312", "ARM920T",
26117 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26118 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26119
da4339ed 26120 /* Marvell processors. */
996b5569
TP
26121 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26122 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26123 FPU_ARCH_VFP_V3D16),
26124 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26125 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26126 FPU_ARCH_NEON_VFP_V4),
da4339ed 26127
996b5569
TP
26128 /* APM X-Gene family. */
26129 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26130 ARM_ARCH_NONE,
26131 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26132 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26133 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26134 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26135
26136 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26137};
f3bad469 26138#undef ARM_CPU_OPT
7ed4c4c5 26139
c19d1205 26140struct arm_arch_option_table
7ed4c4c5 26141{
0198d5e6
TC
26142 const char * name;
26143 size_t name_len;
26144 const arm_feature_set value;
26145 const arm_feature_set default_fpu;
c19d1205 26146};
7ed4c4c5 26147
c19d1205
ZW
26148/* This list should, at a minimum, contain all the architecture names
26149 recognized by GCC. */
f3bad469 26150#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 26151
e74cfd16 26152static const struct arm_arch_option_table arm_archs[] =
c19d1205 26153{
f3bad469
MGD
26154 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26155 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26156 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26157 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26158 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26159 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26160 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26161 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26162 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26163 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26164 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26165 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26166 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26167 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26168 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26169 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26170 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26171 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26172 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26173 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26174 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26175 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26176 kept to preserve existing behaviour. */
26177 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26178 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26179 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26180 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26181 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26182 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26183 kept to preserve existing behaviour. */
26184 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26185 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26186 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26187 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26188 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26189 /* The official spelling of the ARMv7 profile variants is the dashed form.
26190 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26191 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26192 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26193 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26194 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26195 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26196 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26197 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26198 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26199 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26200 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26201 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26202 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26203 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26204 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26205 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
dec41383 26206 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
f3bad469
MGD
26207 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26208 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26209 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26210 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26211};
f3bad469 26212#undef ARM_ARCH_OPT
7ed4c4c5 26213
69133863 26214/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26215
69133863 26216struct arm_option_extension_value_table
c19d1205 26217{
0198d5e6
TC
26218 const char * name;
26219 size_t name_len;
26220 const arm_feature_set merge_value;
26221 const arm_feature_set clear_value;
d942732e
TP
26222 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26223 indicates that an extension is available for all architectures while
26224 ARM_ANY marks an empty entry. */
0198d5e6 26225 const arm_feature_set allowed_archs[2];
c19d1205 26226};
7ed4c4c5 26227
0198d5e6
TC
26228/* The following table must be in alphabetical order with a NULL last entry. */
26229
d942732e
TP
26230#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26231#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26232
69133863 26233static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26234{
823d2571
TG
26235 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26236 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26237 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26238 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26239 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26240 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26241 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26242 ARM_ARCH_V8_2A),
15afaa63
TP
26243 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26244 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26245 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26246 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26247 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26248 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26250 ARM_ARCH_V8_2A),
01f48020
TC
26251 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26252 | ARM_EXT2_FP16_FML),
26253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26254 | ARM_EXT2_FP16_FML),
26255 ARM_ARCH_V8_2A),
d942732e 26256 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26257 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26258 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26259 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26260 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26261 Thumb divide instruction. Due to this having the same name as the
26262 previous entry, this will be ignored when doing command-line parsing and
26263 only considered by build attribute selection code. */
26264 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26265 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26266 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26267 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26268 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26269 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26270 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26271 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26272 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26273 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26274 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26275 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26276 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26277 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26278 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26279 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26280 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26281 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26283 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26284 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26285 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26286 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26287 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26289 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26290 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26291 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26292 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26293 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26294 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26295 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26296 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26297 | ARM_EXT_DIV),
26298 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26299 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26300 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26301 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26302 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26303};
f3bad469 26304#undef ARM_EXT_OPT
69133863
MGD
26305
26306/* ISA floating-point and Advanced SIMD extensions. */
26307struct arm_option_fpu_value_table
26308{
0198d5e6
TC
26309 const char * name;
26310 const arm_feature_set value;
c19d1205 26311};
7ed4c4c5 26312
c19d1205
ZW
26313/* This list should, at a minimum, contain all the fpu names
26314 recognized by GCC. */
69133863 26315static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26316{
26317 {"softfpa", FPU_NONE},
26318 {"fpe", FPU_ARCH_FPE},
26319 {"fpe2", FPU_ARCH_FPE},
26320 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26321 {"fpa", FPU_ARCH_FPA},
26322 {"fpa10", FPU_ARCH_FPA},
26323 {"fpa11", FPU_ARCH_FPA},
26324 {"arm7500fe", FPU_ARCH_FPA},
26325 {"softvfp", FPU_ARCH_VFP},
26326 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26327 {"vfp", FPU_ARCH_VFP_V2},
26328 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26329 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26330 {"vfp10", FPU_ARCH_VFP_V2},
26331 {"vfp10-r0", FPU_ARCH_VFP_V1},
26332 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26333 {"vfpv2", FPU_ARCH_VFP_V2},
26334 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26335 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26336 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26337 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26338 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26339 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26340 {"arm1020t", FPU_ARCH_VFP_V1},
26341 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26342 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26343 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26344 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26345 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26346 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26347 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26348 {"vfpv4", FPU_ARCH_VFP_V4},
26349 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26350 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26351 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26352 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26353 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26354 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26355 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26356 {"crypto-neon-fp-armv8",
26357 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26358 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26359 {"crypto-neon-fp-armv8.1",
26360 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26361 {NULL, ARM_ARCH_NONE}
26362};
26363
26364struct arm_option_value_table
26365{
e0471c16 26366 const char *name;
e74cfd16 26367 long value;
c19d1205 26368};
7ed4c4c5 26369
e74cfd16 26370static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26371{
26372 {"hard", ARM_FLOAT_ABI_HARD},
26373 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26374 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26375 {NULL, 0}
c19d1205 26376};
7ed4c4c5 26377
c19d1205 26378#ifdef OBJ_ELF
3a4a14e9 26379/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26380static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26381{
26382 {"gnu", EF_ARM_EABI_UNKNOWN},
26383 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26384 {"5", EF_ARM_EABI_VER5},
e74cfd16 26385 {NULL, 0}
c19d1205
ZW
26386};
26387#endif
7ed4c4c5 26388
c19d1205
ZW
26389struct arm_long_option_table
26390{
0198d5e6 26391 const char * option; /* Substring to match. */
e0471c16 26392 const char * help; /* Help information. */
17b9d67d 26393 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26394 const char * deprecated; /* If non-null, print this message. */
c19d1205 26395};
7ed4c4c5 26396
c921be7d 26397static bfd_boolean
c168ce07
TP
26398arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26399 arm_feature_set **ext_set_p)
7ed4c4c5 26400{
69133863 26401 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26402 extensions being added before being removed. We achieve this by having
26403 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26404 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26405 or removing it (0) and only allowing it to change in the order
69133863
MGD
26406 -1 -> 1 -> 0. */
26407 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26408 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26409 int adding_value = -1;
26410
c168ce07
TP
26411 if (!*ext_set_p)
26412 {
26413 *ext_set_p = XNEW (arm_feature_set);
26414 **ext_set_p = arm_arch_none;
26415 }
e74cfd16 26416
c19d1205 26417 while (str != NULL && *str != 0)
7ed4c4c5 26418 {
82b8a785 26419 const char *ext;
f3bad469 26420 size_t len;
7ed4c4c5 26421
c19d1205
ZW
26422 if (*str != '+')
26423 {
26424 as_bad (_("invalid architectural extension"));
c921be7d 26425 return FALSE;
c19d1205 26426 }
7ed4c4c5 26427
c19d1205
ZW
26428 str++;
26429 ext = strchr (str, '+');
7ed4c4c5 26430
c19d1205 26431 if (ext != NULL)
f3bad469 26432 len = ext - str;
c19d1205 26433 else
f3bad469 26434 len = strlen (str);
7ed4c4c5 26435
f3bad469 26436 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26437 {
26438 if (adding_value != 0)
26439 {
26440 adding_value = 0;
26441 opt = arm_extensions;
26442 }
26443
f3bad469 26444 len -= 2;
69133863
MGD
26445 str += 2;
26446 }
f3bad469 26447 else if (len > 0)
69133863
MGD
26448 {
26449 if (adding_value == -1)
26450 {
26451 adding_value = 1;
26452 opt = arm_extensions;
26453 }
26454 else if (adding_value != 1)
26455 {
26456 as_bad (_("must specify extensions to add before specifying "
26457 "those to remove"));
26458 return FALSE;
26459 }
26460 }
26461
f3bad469 26462 if (len == 0)
c19d1205
ZW
26463 {
26464 as_bad (_("missing architectural extension"));
c921be7d 26465 return FALSE;
c19d1205 26466 }
7ed4c4c5 26467
69133863
MGD
26468 gas_assert (adding_value != -1);
26469 gas_assert (opt != NULL);
26470
26471 /* Scan over the options table trying to find an exact match. */
26472 for (; opt->name != NULL; opt++)
f3bad469 26473 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26474 {
d942732e
TP
26475 int i, nb_allowed_archs =
26476 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26477 /* Check we can apply the extension to this architecture. */
d942732e
TP
26478 for (i = 0; i < nb_allowed_archs; i++)
26479 {
26480 /* Empty entry. */
26481 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26482 continue;
c168ce07 26483 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26484 break;
26485 }
26486 if (i == nb_allowed_archs)
69133863
MGD
26487 {
26488 as_bad (_("extension does not apply to the base architecture"));
26489 return FALSE;
26490 }
26491
26492 /* Add or remove the extension. */
26493 if (adding_value)
c168ce07
TP
26494 ARM_MERGE_FEATURE_SETS (**ext_set_p, **ext_set_p,
26495 opt->merge_value);
69133863 26496 else
c168ce07 26497 ARM_CLEAR_FEATURE (**ext_set_p, **ext_set_p, opt->clear_value);
69133863 26498
3d030cdb
TP
26499 /* Allowing Thumb division instructions for ARMv7 in autodetection
26500 rely on this break so that duplicate extensions (extensions
26501 with the same name as a previous extension in the list) are not
26502 considered for command-line parsing. */
c19d1205
ZW
26503 break;
26504 }
7ed4c4c5 26505
c19d1205
ZW
26506 if (opt->name == NULL)
26507 {
69133863
MGD
26508 /* Did we fail to find an extension because it wasn't specified in
26509 alphabetical order, or because it does not exist? */
26510
26511 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26512 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26513 break;
26514
26515 if (opt->name == NULL)
26516 as_bad (_("unknown architectural extension `%s'"), str);
26517 else
26518 as_bad (_("architectural extensions must be specified in "
26519 "alphabetical order"));
26520
c921be7d 26521 return FALSE;
c19d1205 26522 }
69133863
MGD
26523 else
26524 {
26525 /* We should skip the extension we've just matched the next time
26526 round. */
26527 opt++;
26528 }
7ed4c4c5 26529
c19d1205
ZW
26530 str = ext;
26531 };
7ed4c4c5 26532
c921be7d 26533 return TRUE;
c19d1205 26534}
7ed4c4c5 26535
c921be7d 26536static bfd_boolean
17b9d67d 26537arm_parse_cpu (const char *str)
7ed4c4c5 26538{
f3bad469 26539 const struct arm_cpu_option_table *opt;
82b8a785 26540 const char *ext = strchr (str, '+');
f3bad469 26541 size_t len;
7ed4c4c5 26542
c19d1205 26543 if (ext != NULL)
f3bad469 26544 len = ext - str;
7ed4c4c5 26545 else
f3bad469 26546 len = strlen (str);
7ed4c4c5 26547
f3bad469 26548 if (len == 0)
7ed4c4c5 26549 {
c19d1205 26550 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26551 return FALSE;
7ed4c4c5
NC
26552 }
26553
c19d1205 26554 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26555 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26556 {
c168ce07
TP
26557 mcpu_cpu_opt = &opt->value;
26558 if (!dyn_mcpu_ext_opt)
26559 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
26560 *dyn_mcpu_ext_opt = opt->ext;
e74cfd16 26561 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26562 if (opt->canonical_name)
ef8e6722
JW
26563 {
26564 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26565 strcpy (selected_cpu_name, opt->canonical_name);
26566 }
ee065d83
PB
26567 else
26568 {
f3bad469 26569 size_t i;
c921be7d 26570
ef8e6722
JW
26571 if (len >= sizeof selected_cpu_name)
26572 len = (sizeof selected_cpu_name) - 1;
26573
f3bad469 26574 for (i = 0; i < len; i++)
ee065d83
PB
26575 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26576 selected_cpu_name[i] = 0;
26577 }
7ed4c4c5 26578
c19d1205 26579 if (ext != NULL)
c168ce07 26580 return arm_parse_extension (ext, mcpu_cpu_opt, &dyn_mcpu_ext_opt);
7ed4c4c5 26581
c921be7d 26582 return TRUE;
c19d1205 26583 }
7ed4c4c5 26584
c19d1205 26585 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26586 return FALSE;
7ed4c4c5
NC
26587}
26588
c921be7d 26589static bfd_boolean
17b9d67d 26590arm_parse_arch (const char *str)
7ed4c4c5 26591{
e74cfd16 26592 const struct arm_arch_option_table *opt;
82b8a785 26593 const char *ext = strchr (str, '+');
f3bad469 26594 size_t len;
7ed4c4c5 26595
c19d1205 26596 if (ext != NULL)
f3bad469 26597 len = ext - str;
7ed4c4c5 26598 else
f3bad469 26599 len = strlen (str);
7ed4c4c5 26600
f3bad469 26601 if (len == 0)
7ed4c4c5 26602 {
c19d1205 26603 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26604 return FALSE;
7ed4c4c5
NC
26605 }
26606
c19d1205 26607 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26608 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26609 {
e74cfd16
PB
26610 march_cpu_opt = &opt->value;
26611 march_fpu_opt = &opt->default_fpu;
5f4273c7 26612 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26613
c19d1205 26614 if (ext != NULL)
c168ce07 26615 return arm_parse_extension (ext, march_cpu_opt, &dyn_march_ext_opt);
7ed4c4c5 26616
c921be7d 26617 return TRUE;
c19d1205
ZW
26618 }
26619
26620 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26621 return FALSE;
7ed4c4c5 26622}
eb043451 26623
c921be7d 26624static bfd_boolean
17b9d67d 26625arm_parse_fpu (const char * str)
c19d1205 26626{
69133863 26627 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26628
c19d1205
ZW
26629 for (opt = arm_fpus; opt->name != NULL; opt++)
26630 if (streq (opt->name, str))
26631 {
e74cfd16 26632 mfpu_opt = &opt->value;
c921be7d 26633 return TRUE;
c19d1205 26634 }
b99bd4ef 26635
c19d1205 26636 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26637 return FALSE;
c19d1205
ZW
26638}
26639
c921be7d 26640static bfd_boolean
17b9d67d 26641arm_parse_float_abi (const char * str)
b99bd4ef 26642{
e74cfd16 26643 const struct arm_option_value_table * opt;
b99bd4ef 26644
c19d1205
ZW
26645 for (opt = arm_float_abis; opt->name != NULL; opt++)
26646 if (streq (opt->name, str))
26647 {
26648 mfloat_abi_opt = opt->value;
c921be7d 26649 return TRUE;
c19d1205 26650 }
cc8a6dd0 26651
c19d1205 26652 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26653 return FALSE;
c19d1205 26654}
b99bd4ef 26655
c19d1205 26656#ifdef OBJ_ELF
c921be7d 26657static bfd_boolean
17b9d67d 26658arm_parse_eabi (const char * str)
c19d1205 26659{
e74cfd16 26660 const struct arm_option_value_table *opt;
cc8a6dd0 26661
c19d1205
ZW
26662 for (opt = arm_eabis; opt->name != NULL; opt++)
26663 if (streq (opt->name, str))
26664 {
26665 meabi_flags = opt->value;
c921be7d 26666 return TRUE;
c19d1205
ZW
26667 }
26668 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26669 return FALSE;
c19d1205
ZW
26670}
26671#endif
cc8a6dd0 26672
c921be7d 26673static bfd_boolean
17b9d67d 26674arm_parse_it_mode (const char * str)
e07e6e58 26675{
c921be7d 26676 bfd_boolean ret = TRUE;
e07e6e58
NC
26677
26678 if (streq ("arm", str))
26679 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26680 else if (streq ("thumb", str))
26681 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26682 else if (streq ("always", str))
26683 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26684 else if (streq ("never", str))
26685 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26686 else
26687 {
26688 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26689 "arm, thumb, always, or never."), str);
c921be7d 26690 ret = FALSE;
e07e6e58
NC
26691 }
26692
26693 return ret;
26694}
26695
2e6976a8 26696static bfd_boolean
17b9d67d 26697arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26698{
26699 codecomposer_syntax = TRUE;
26700 arm_comment_chars[0] = ';';
26701 arm_line_separator_chars[0] = 0;
26702 return TRUE;
26703}
26704
c19d1205
ZW
26705struct arm_long_option_table arm_long_opts[] =
26706{
26707 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26708 arm_parse_cpu, NULL},
26709 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26710 arm_parse_arch, NULL},
26711 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26712 arm_parse_fpu, NULL},
26713 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26714 arm_parse_float_abi, NULL},
26715#ifdef OBJ_ELF
7fac0536 26716 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26717 arm_parse_eabi, NULL},
26718#endif
e07e6e58
NC
26719 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26720 arm_parse_it_mode, NULL},
2e6976a8
DG
26721 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26722 arm_ccs_mode, NULL},
c19d1205
ZW
26723 {NULL, NULL, 0, NULL}
26724};
cc8a6dd0 26725
c19d1205 26726int
17b9d67d 26727md_parse_option (int c, const char * arg)
c19d1205
ZW
26728{
26729 struct arm_option_table *opt;
e74cfd16 26730 const struct arm_legacy_option_table *fopt;
c19d1205 26731 struct arm_long_option_table *lopt;
b99bd4ef 26732
c19d1205 26733 switch (c)
b99bd4ef 26734 {
c19d1205
ZW
26735#ifdef OPTION_EB
26736 case OPTION_EB:
26737 target_big_endian = 1;
26738 break;
26739#endif
cc8a6dd0 26740
c19d1205
ZW
26741#ifdef OPTION_EL
26742 case OPTION_EL:
26743 target_big_endian = 0;
26744 break;
26745#endif
b99bd4ef 26746
845b51d6
PB
26747 case OPTION_FIX_V4BX:
26748 fix_v4bx = TRUE;
26749 break;
26750
c19d1205
ZW
26751 case 'a':
26752 /* Listing option. Just ignore these, we don't support additional
26753 ones. */
26754 return 0;
b99bd4ef 26755
c19d1205
ZW
26756 default:
26757 for (opt = arm_opts; opt->option != NULL; opt++)
26758 {
26759 if (c == opt->option[0]
26760 && ((arg == NULL && opt->option[1] == 0)
26761 || streq (arg, opt->option + 1)))
26762 {
c19d1205 26763 /* If the option is deprecated, tell the user. */
278df34e 26764 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26765 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26766 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26767
c19d1205
ZW
26768 if (opt->var != NULL)
26769 *opt->var = opt->value;
cc8a6dd0 26770
c19d1205
ZW
26771 return 1;
26772 }
26773 }
b99bd4ef 26774
e74cfd16
PB
26775 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26776 {
26777 if (c == fopt->option[0]
26778 && ((arg == NULL && fopt->option[1] == 0)
26779 || streq (arg, fopt->option + 1)))
26780 {
e74cfd16 26781 /* If the option is deprecated, tell the user. */
278df34e 26782 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26783 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26784 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26785
26786 if (fopt->var != NULL)
26787 *fopt->var = &fopt->value;
26788
26789 return 1;
26790 }
26791 }
26792
c19d1205
ZW
26793 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26794 {
26795 /* These options are expected to have an argument. */
26796 if (c == lopt->option[0]
26797 && arg != NULL
26798 && strncmp (arg, lopt->option + 1,
26799 strlen (lopt->option + 1)) == 0)
26800 {
c19d1205 26801 /* If the option is deprecated, tell the user. */
278df34e 26802 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26803 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26804 _(lopt->deprecated));
b99bd4ef 26805
c19d1205
ZW
26806 /* Call the sup-option parser. */
26807 return lopt->func (arg + strlen (lopt->option) - 1);
26808 }
26809 }
a737bd4d 26810
c19d1205
ZW
26811 return 0;
26812 }
a394c00f 26813
c19d1205
ZW
26814 return 1;
26815}
a394c00f 26816
c19d1205
ZW
26817void
26818md_show_usage (FILE * fp)
a394c00f 26819{
c19d1205
ZW
26820 struct arm_option_table *opt;
26821 struct arm_long_option_table *lopt;
a394c00f 26822
c19d1205 26823 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26824
c19d1205
ZW
26825 for (opt = arm_opts; opt->option != NULL; opt++)
26826 if (opt->help != NULL)
26827 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26828
c19d1205
ZW
26829 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26830 if (lopt->help != NULL)
26831 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26832
c19d1205
ZW
26833#ifdef OPTION_EB
26834 fprintf (fp, _("\
26835 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26836#endif
26837
c19d1205
ZW
26838#ifdef OPTION_EL
26839 fprintf (fp, _("\
26840 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26841#endif
845b51d6
PB
26842
26843 fprintf (fp, _("\
26844 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26845}
ee065d83 26846
ee065d83 26847#ifdef OBJ_ELF
0198d5e6 26848
62b3e311
PB
26849typedef struct
26850{
26851 int val;
26852 arm_feature_set flags;
26853} cpu_arch_ver_table;
26854
2c6b98ea
TP
26855/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26856 chronologically for architectures, with an exception for ARMv6-M and
26857 ARMv6S-M due to legacy reasons. No new architecture should have a
26858 special case. This allows for build attribute selection results to be
26859 stable when new architectures are added. */
62b3e311
PB
26860static const cpu_arch_ver_table cpu_arch_ver[] =
26861{
2c6b98ea
TP
26862 {0, ARM_ARCH_V1},
26863 {0, ARM_ARCH_V2},
26864 {0, ARM_ARCH_V2S},
26865 {0, ARM_ARCH_V3},
26866 {0, ARM_ARCH_V3M},
26867 {1, ARM_ARCH_V4xM},
62b3e311 26868 {1, ARM_ARCH_V4},
2c6b98ea 26869 {2, ARM_ARCH_V4TxM},
62b3e311 26870 {2, ARM_ARCH_V4T},
2c6b98ea 26871 {3, ARM_ARCH_V5xM},
62b3e311 26872 {3, ARM_ARCH_V5},
2c6b98ea 26873 {3, ARM_ARCH_V5TxM},
ee3c0378 26874 {3, ARM_ARCH_V5T},
2c6b98ea 26875 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26876 {4, ARM_ARCH_V5TE},
26877 {5, ARM_ARCH_V5TEJ},
26878 {6, ARM_ARCH_V6},
f4c65163 26879 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26880 {7, ARM_ARCH_V6KZ},
26881 {9, ARM_ARCH_V6K},
26882 {8, ARM_ARCH_V6T2},
26883 {8, ARM_ARCH_V6KT2},
26884 {8, ARM_ARCH_V6ZT2},
26885 {8, ARM_ARCH_V6KZT2},
26886
26887 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26888 always selected build attributes to match those of ARMv6-M
26889 (resp. ARMv6S-M). However, due to these architectures being a strict
26890 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26891 would be selected when fully respecting chronology of architectures.
26892 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26893 move them before ARMv7 architectures. */
91e22acd 26894 {11, ARM_ARCH_V6M},
b2a5fbdc 26895 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26896
26897 {10, ARM_ARCH_V7},
26898 {10, ARM_ARCH_V7A},
62b3e311
PB
26899 {10, ARM_ARCH_V7R},
26900 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26901 {10, ARM_ARCH_V7VE},
26902 {13, ARM_ARCH_V7EM},
bca38921 26903 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26904 {14, ARM_ARCH_V8_1A},
26905 {14, ARM_ARCH_V8_2A},
26906 {14, ARM_ARCH_V8_3A},
ff8646ee 26907 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26908 {17, ARM_ARCH_V8M_MAIN},
ced40572 26909 {15, ARM_ARCH_V8R},
dec41383 26910 {16, ARM_ARCH_V8_4A},
2c6b98ea 26911 {-1, ARM_ARCH_NONE}
62b3e311
PB
26912};
26913
ee3c0378 26914/* Set an attribute if it has not already been set by the user. */
0198d5e6 26915
ee3c0378
AS
26916static void
26917aeabi_set_attribute_int (int tag, int value)
26918{
26919 if (tag < 1
26920 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26921 || !attributes_set_explicitly[tag])
26922 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26923}
26924
26925static void
26926aeabi_set_attribute_string (int tag, const char *value)
26927{
26928 if (tag < 1
26929 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26930 || !attributes_set_explicitly[tag])
26931 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26932}
26933
2c6b98ea
TP
26934/* Return whether features in the *NEEDED feature set are available via
26935 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 26936
2c6b98ea
TP
26937static bfd_boolean
26938have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
26939 const arm_feature_set *needed)
26940{
26941 int i, nb_allowed_archs;
26942 arm_feature_set ext_fset;
26943 const struct arm_option_extension_value_table *opt;
26944
26945 ext_fset = arm_arch_none;
26946 for (opt = arm_extensions; opt->name != NULL; opt++)
26947 {
26948 /* Extension does not provide any feature we need. */
26949 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
26950 continue;
26951
26952 nb_allowed_archs =
26953 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26954 for (i = 0; i < nb_allowed_archs; i++)
26955 {
26956 /* Empty entry. */
26957 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
26958 break;
26959
26960 /* Extension is available, add it. */
26961 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
26962 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
26963 }
26964 }
26965
26966 /* Can we enable all features in *needed? */
26967 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
26968}
26969
26970/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
26971 a given architecture feature set *ARCH_EXT_FSET including extension feature
26972 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
26973 - if true, check for an exact match of the architecture modulo extensions;
26974 - otherwise, select build attribute value of the first superset
26975 architecture released so that results remains stable when new architectures
26976 are added.
26977 For -march/-mcpu=all the build attribute value of the most featureful
26978 architecture is returned. Tag_CPU_arch_profile result is returned in
26979 PROFILE. */
0198d5e6 26980
2c6b98ea
TP
26981static int
26982get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
26983 const arm_feature_set *ext_fset,
26984 char *profile, int exact_match)
26985{
26986 arm_feature_set arch_fset;
26987 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
26988
26989 /* Select most featureful architecture with all its extensions if building
26990 for -march=all as the feature sets used to set build attributes. */
26991 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
26992 {
26993 /* Force revisiting of decision for each new architecture. */
26994 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
26995 *profile = 'A';
26996 return TAG_CPU_ARCH_V8;
26997 }
26998
26999 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27000
27001 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27002 {
27003 arm_feature_set known_arch_fset;
27004
27005 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27006 if (exact_match)
27007 {
27008 /* Base architecture match user-specified architecture and
27009 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27010 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27011 {
27012 p_ver_ret = p_ver;
27013 goto found;
27014 }
27015 /* Base architecture match user-specified architecture only
27016 (eg. ARMv6-M in the same case as above). Record it in case we
27017 find a match with above condition. */
27018 else if (p_ver_ret == NULL
27019 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27020 p_ver_ret = p_ver;
27021 }
27022 else
27023 {
27024
27025 /* Architecture has all features wanted. */
27026 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27027 {
27028 arm_feature_set added_fset;
27029
27030 /* Compute features added by this architecture over the one
27031 recorded in p_ver_ret. */
27032 if (p_ver_ret != NULL)
27033 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27034 p_ver_ret->flags);
27035 /* First architecture that match incl. with extensions, or the
27036 only difference in features over the recorded match is
27037 features that were optional and are now mandatory. */
27038 if (p_ver_ret == NULL
27039 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27040 {
27041 p_ver_ret = p_ver;
27042 goto found;
27043 }
27044 }
27045 else if (p_ver_ret == NULL)
27046 {
27047 arm_feature_set needed_ext_fset;
27048
27049 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27050
27051 /* Architecture has all features needed when using some
27052 extensions. Record it and continue searching in case there
27053 exist an architecture providing all needed features without
27054 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27055 OS extension). */
27056 if (have_ext_for_needed_feat_p (&known_arch_fset,
27057 &needed_ext_fset))
27058 p_ver_ret = p_ver;
27059 }
27060 }
27061 }
27062
27063 if (p_ver_ret == NULL)
27064 return -1;
27065
27066found:
27067 /* Tag_CPU_arch_profile. */
27068 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27069 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27070 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27071 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27072 *profile = 'A';
27073 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27074 *profile = 'R';
27075 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27076 *profile = 'M';
27077 else
27078 *profile = '\0';
27079 return p_ver_ret->val;
27080}
27081
ee065d83 27082/* Set the public EABI object attributes. */
0198d5e6 27083
c168ce07 27084static void
ee065d83
PB
27085aeabi_set_public_attributes (void)
27086{
69239280 27087 char profile;
2c6b98ea 27088 int arch = -1;
90ec0d68 27089 int virt_sec = 0;
bca38921 27090 int fp16_optional = 0;
2c6b98ea
TP
27091 int skip_exact_match = 0;
27092 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27093
54bab281
TP
27094 /* Autodetection mode, choose the architecture based the instructions
27095 actually used. */
27096 if (no_cpu_selected ())
27097 {
27098 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27099
54bab281
TP
27100 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27101 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27102
54bab281
TP
27103 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27104 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27105
54bab281
TP
27106 /* Code run during relaxation relies on selected_cpu being set. */
27107 selected_cpu = flags;
27108 }
27109 /* Otherwise, choose the architecture based on the capabilities of the
27110 requested cpu. */
27111 else
27112 flags = selected_cpu;
27113 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
7f78eb34 27114
ddd7f988 27115 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
27116 if (object_arch)
27117 {
2c6b98ea
TP
27118 ARM_CLEAR_FEATURE (flags_arch, *object_arch, fpu_any);
27119 flags_ext = arm_arch_none;
7a1d4c38 27120 }
2c6b98ea 27121 else
62b3e311 27122 {
2c6b98ea
TP
27123 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27124 flags_ext = dyn_mcpu_ext_opt ? *dyn_mcpu_ext_opt : arm_arch_none;
27125 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
27126 }
27127
27128 /* When this function is run again after relaxation has happened there is no
27129 way to determine whether an architecture or CPU was specified by the user:
27130 - selected_cpu is set above for relaxation to work;
27131 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27132 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27133 Therefore, if not in -march=all case we first try an exact match and fall
27134 back to autodetection. */
27135 if (!skip_exact_match)
27136 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27137 if (arch == -1)
27138 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27139 if (arch == -1)
27140 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27141
ee065d83
PB
27142 /* Tag_CPU_name. */
27143 if (selected_cpu_name[0])
27144 {
91d6fa6a 27145 char *q;
ee065d83 27146
91d6fa6a
NC
27147 q = selected_cpu_name;
27148 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27149 {
27150 int i;
5f4273c7 27151
91d6fa6a
NC
27152 q += 4;
27153 for (i = 0; q[i]; i++)
27154 q[i] = TOUPPER (q[i]);
ee065d83 27155 }
91d6fa6a 27156 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27157 }
62f3b8c8 27158
ee065d83 27159 /* Tag_CPU_arch. */
ee3c0378 27160 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27161
62b3e311 27162 /* Tag_CPU_arch_profile. */
69239280
MGD
27163 if (profile != '\0')
27164 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27165
15afaa63 27166 /* Tag_DSP_extension. */
6c290d53
TP
27167 if (dyn_mcpu_ext_opt && ARM_CPU_HAS_FEATURE (*dyn_mcpu_ext_opt, arm_ext_dsp))
27168 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27169
2c6b98ea 27170 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27171 /* Tag_ARM_ISA_use. */
ee3c0378 27172 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27173 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27174 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27175
ee065d83 27176 /* Tag_THUMB_ISA_use. */
ee3c0378 27177 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27178 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27179 {
27180 int thumb_isa_use;
27181
27182 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27183 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27184 thumb_isa_use = 3;
27185 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27186 thumb_isa_use = 2;
27187 else
27188 thumb_isa_use = 1;
27189 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27190 }
62f3b8c8 27191
ee065d83 27192 /* Tag_VFP_arch. */
a715796b
TG
27193 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27194 aeabi_set_attribute_int (Tag_VFP_arch,
27195 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27196 ? 7 : 8);
bca38921 27197 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27198 aeabi_set_attribute_int (Tag_VFP_arch,
27199 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27200 ? 5 : 6);
27201 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27202 {
27203 fp16_optional = 1;
27204 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27205 }
ada65aa3 27206 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27207 {
27208 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27209 fp16_optional = 1;
27210 }
ee3c0378
AS
27211 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27212 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27213 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27214 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27215 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27216
4547cb56
NC
27217 /* Tag_ABI_HardFP_use. */
27218 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27219 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27220 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27221
ee065d83 27222 /* Tag_WMMX_arch. */
ee3c0378
AS
27223 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27224 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27225 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27226 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27227
ee3c0378 27228 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27229 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27230 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27231 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27232 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27233 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27234 {
27235 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27236 {
27237 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27238 }
27239 else
27240 {
27241 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27242 fp16_optional = 1;
27243 }
27244 }
fa94de6b 27245
ee3c0378 27246 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27247 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27248 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27249
69239280
MGD
27250 /* Tag_DIV_use.
27251
27252 We set Tag_DIV_use to two when integer divide instructions have been used
27253 in ARM state, or when Thumb integer divide instructions have been used,
27254 but we have no architecture profile set, nor have we any ARM instructions.
27255
4ed7ed8d
TP
27256 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27257 by the base architecture.
bca38921 27258
69239280 27259 For new architectures we will have to check these tests. */
ced40572 27260 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27261 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27262 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27263 aeabi_set_attribute_int (Tag_DIV_use, 0);
27264 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27265 || (profile == '\0'
27266 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27267 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27268 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27269
27270 /* Tag_MP_extension_use. */
27271 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27272 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27273
27274 /* Tag Virtualization_use. */
27275 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27276 virt_sec |= 1;
27277 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27278 virt_sec |= 2;
27279 if (virt_sec != 0)
27280 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27281}
27282
c168ce07
TP
27283/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27284 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27285
c168ce07
TP
27286void
27287arm_md_post_relax (void)
27288{
27289 aeabi_set_public_attributes ();
27290 XDELETE (dyn_mcpu_ext_opt);
27291 dyn_mcpu_ext_opt = NULL;
27292 XDELETE (dyn_march_ext_opt);
27293 dyn_march_ext_opt = NULL;
27294}
27295
104d59d1 27296/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27297
ee065d83
PB
27298void
27299arm_md_end (void)
27300{
ee065d83
PB
27301 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27302 return;
27303
27304 aeabi_set_public_attributes ();
ee065d83 27305}
8463be01 27306#endif /* OBJ_ELF */
ee065d83 27307
ee065d83
PB
27308/* Parse a .cpu directive. */
27309
27310static void
27311s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27312{
e74cfd16 27313 const struct arm_cpu_option_table *opt;
ee065d83
PB
27314 char *name;
27315 char saved_char;
27316
27317 name = input_line_pointer;
5f4273c7 27318 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27319 input_line_pointer++;
27320 saved_char = *input_line_pointer;
27321 *input_line_pointer = 0;
27322
27323 /* Skip the first "all" entry. */
27324 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27325 if (streq (opt->name, name))
27326 {
c168ce07
TP
27327 mcpu_cpu_opt = &opt->value;
27328 if (!dyn_mcpu_ext_opt)
27329 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27330 *dyn_mcpu_ext_opt = opt->ext;
27331 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
ee065d83 27332 if (opt->canonical_name)
5f4273c7 27333 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27334 else
27335 {
27336 int i;
27337 for (i = 0; opt->name[i]; i++)
27338 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27339
ee065d83
PB
27340 selected_cpu_name[i] = 0;
27341 }
e74cfd16 27342 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27343 if (dyn_mcpu_ext_opt)
27344 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27345 *input_line_pointer = saved_char;
27346 demand_empty_rest_of_line ();
27347 return;
27348 }
27349 as_bad (_("unknown cpu `%s'"), name);
27350 *input_line_pointer = saved_char;
27351 ignore_rest_of_line ();
27352}
27353
ee065d83
PB
27354/* Parse a .arch directive. */
27355
27356static void
27357s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27358{
e74cfd16 27359 const struct arm_arch_option_table *opt;
ee065d83
PB
27360 char saved_char;
27361 char *name;
27362
27363 name = input_line_pointer;
5f4273c7 27364 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27365 input_line_pointer++;
27366 saved_char = *input_line_pointer;
27367 *input_line_pointer = 0;
27368
27369 /* Skip the first "all" entry. */
27370 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27371 if (streq (opt->name, name))
27372 {
e74cfd16 27373 mcpu_cpu_opt = &opt->value;
c168ce07
TP
27374 XDELETE (dyn_mcpu_ext_opt);
27375 dyn_mcpu_ext_opt = NULL;
27376 selected_cpu = *mcpu_cpu_opt;
5f4273c7 27377 strcpy (selected_cpu_name, opt->name);
c168ce07 27378 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
ee065d83
PB
27379 *input_line_pointer = saved_char;
27380 demand_empty_rest_of_line ();
27381 return;
27382 }
27383
27384 as_bad (_("unknown architecture `%s'\n"), name);
27385 *input_line_pointer = saved_char;
27386 ignore_rest_of_line ();
27387}
27388
7a1d4c38
PB
27389/* Parse a .object_arch directive. */
27390
27391static void
27392s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27393{
27394 const struct arm_arch_option_table *opt;
27395 char saved_char;
27396 char *name;
27397
27398 name = input_line_pointer;
5f4273c7 27399 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27400 input_line_pointer++;
27401 saved_char = *input_line_pointer;
27402 *input_line_pointer = 0;
27403
27404 /* Skip the first "all" entry. */
27405 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27406 if (streq (opt->name, name))
27407 {
27408 object_arch = &opt->value;
27409 *input_line_pointer = saved_char;
27410 demand_empty_rest_of_line ();
27411 return;
27412 }
27413
27414 as_bad (_("unknown architecture `%s'\n"), name);
27415 *input_line_pointer = saved_char;
27416 ignore_rest_of_line ();
27417}
27418
69133863
MGD
27419/* Parse a .arch_extension directive. */
27420
27421static void
27422s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27423{
27424 const struct arm_option_extension_value_table *opt;
d942732e 27425 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27426 char saved_char;
27427 char *name;
27428 int adding_value = 1;
27429
27430 name = input_line_pointer;
27431 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27432 input_line_pointer++;
27433 saved_char = *input_line_pointer;
27434 *input_line_pointer = 0;
27435
27436 if (strlen (name) >= 2
27437 && strncmp (name, "no", 2) == 0)
27438 {
27439 adding_value = 0;
27440 name += 2;
27441 }
27442
27443 for (opt = arm_extensions; opt->name != NULL; opt++)
27444 if (streq (opt->name, name))
27445 {
d942732e
TP
27446 int i, nb_allowed_archs =
27447 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27448 for (i = 0; i < nb_allowed_archs; i++)
27449 {
27450 /* Empty entry. */
27451 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27452 continue;
27453 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
27454 break;
27455 }
27456
27457 if (i == nb_allowed_archs)
69133863
MGD
27458 {
27459 as_bad (_("architectural extension `%s' is not allowed for the "
27460 "current base architecture"), name);
27461 break;
27462 }
27463
c168ce07
TP
27464 if (!dyn_mcpu_ext_opt)
27465 {
27466 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27467 *dyn_mcpu_ext_opt = arm_arch_none;
27468 }
69133863 27469 if (adding_value)
c168ce07 27470 ARM_MERGE_FEATURE_SETS (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
5a70a223 27471 opt->merge_value);
69133863 27472 else
c168ce07
TP
27473 ARM_CLEAR_FEATURE (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
27474 opt->clear_value);
69133863 27475
c168ce07
TP
27476 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
27477 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
69133863
MGD
27478 *input_line_pointer = saved_char;
27479 demand_empty_rest_of_line ();
3d030cdb
TP
27480 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27481 on this return so that duplicate extensions (extensions with the
27482 same name as a previous extension in the list) are not considered
27483 for command-line parsing. */
69133863
MGD
27484 return;
27485 }
27486
27487 if (opt->name == NULL)
e673710a 27488 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27489
27490 *input_line_pointer = saved_char;
27491 ignore_rest_of_line ();
27492}
27493
ee065d83
PB
27494/* Parse a .fpu directive. */
27495
27496static void
27497s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27498{
69133863 27499 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27500 char saved_char;
27501 char *name;
27502
27503 name = input_line_pointer;
5f4273c7 27504 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27505 input_line_pointer++;
27506 saved_char = *input_line_pointer;
27507 *input_line_pointer = 0;
5f4273c7 27508
ee065d83
PB
27509 for (opt = arm_fpus; opt->name != NULL; opt++)
27510 if (streq (opt->name, name))
27511 {
e74cfd16
PB
27512 mfpu_opt = &opt->value;
27513 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27514 if (dyn_mcpu_ext_opt)
27515 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27516 *input_line_pointer = saved_char;
27517 demand_empty_rest_of_line ();
27518 return;
27519 }
27520
27521 as_bad (_("unknown floating point format `%s'\n"), name);
27522 *input_line_pointer = saved_char;
27523 ignore_rest_of_line ();
27524}
ee065d83 27525
794ba86a 27526/* Copy symbol information. */
f31fef98 27527
794ba86a
DJ
27528void
27529arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27530{
27531 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27532}
e04befd0 27533
f31fef98 27534#ifdef OBJ_ELF
e04befd0
AS
27535/* Given a symbolic attribute NAME, return the proper integer value.
27536 Returns -1 if the attribute is not known. */
f31fef98 27537
e04befd0
AS
27538int
27539arm_convert_symbolic_attribute (const char *name)
27540{
f31fef98
NC
27541 static const struct
27542 {
27543 const char * name;
27544 const int tag;
27545 }
27546 attribute_table[] =
27547 {
27548 /* When you modify this table you should
27549 also modify the list in doc/c-arm.texi. */
e04befd0 27550#define T(tag) {#tag, tag}
f31fef98
NC
27551 T (Tag_CPU_raw_name),
27552 T (Tag_CPU_name),
27553 T (Tag_CPU_arch),
27554 T (Tag_CPU_arch_profile),
27555 T (Tag_ARM_ISA_use),
27556 T (Tag_THUMB_ISA_use),
75375b3e 27557 T (Tag_FP_arch),
f31fef98
NC
27558 T (Tag_VFP_arch),
27559 T (Tag_WMMX_arch),
27560 T (Tag_Advanced_SIMD_arch),
27561 T (Tag_PCS_config),
27562 T (Tag_ABI_PCS_R9_use),
27563 T (Tag_ABI_PCS_RW_data),
27564 T (Tag_ABI_PCS_RO_data),
27565 T (Tag_ABI_PCS_GOT_use),
27566 T (Tag_ABI_PCS_wchar_t),
27567 T (Tag_ABI_FP_rounding),
27568 T (Tag_ABI_FP_denormal),
27569 T (Tag_ABI_FP_exceptions),
27570 T (Tag_ABI_FP_user_exceptions),
27571 T (Tag_ABI_FP_number_model),
75375b3e 27572 T (Tag_ABI_align_needed),
f31fef98 27573 T (Tag_ABI_align8_needed),
75375b3e 27574 T (Tag_ABI_align_preserved),
f31fef98
NC
27575 T (Tag_ABI_align8_preserved),
27576 T (Tag_ABI_enum_size),
27577 T (Tag_ABI_HardFP_use),
27578 T (Tag_ABI_VFP_args),
27579 T (Tag_ABI_WMMX_args),
27580 T (Tag_ABI_optimization_goals),
27581 T (Tag_ABI_FP_optimization_goals),
27582 T (Tag_compatibility),
27583 T (Tag_CPU_unaligned_access),
75375b3e 27584 T (Tag_FP_HP_extension),
f31fef98
NC
27585 T (Tag_VFP_HP_extension),
27586 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27587 T (Tag_MPextension_use),
27588 T (Tag_DIV_use),
f31fef98
NC
27589 T (Tag_nodefaults),
27590 T (Tag_also_compatible_with),
27591 T (Tag_conformance),
27592 T (Tag_T2EE_use),
27593 T (Tag_Virtualization_use),
15afaa63 27594 T (Tag_DSP_extension),
cd21e546 27595 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27596#undef T
f31fef98 27597 };
e04befd0
AS
27598 unsigned int i;
27599
27600 if (name == NULL)
27601 return -1;
27602
f31fef98 27603 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27604 if (streq (name, attribute_table[i].name))
e04befd0
AS
27605 return attribute_table[i].tag;
27606
27607 return -1;
27608}
267bf995 27609
93ef582d
NC
27610/* Apply sym value for relocations only in the case that they are for
27611 local symbols in the same segment as the fixup and you have the
27612 respective architectural feature for blx and simple switches. */
0198d5e6 27613
267bf995 27614int
93ef582d 27615arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27616{
27617 if (fixP->fx_addsy
27618 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27619 /* PR 17444: If the local symbol is in a different section then a reloc
27620 will always be generated for it, so applying the symbol value now
27621 will result in a double offset being stored in the relocation. */
27622 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27623 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27624 {
27625 switch (fixP->fx_r_type)
27626 {
27627 case BFD_RELOC_ARM_PCREL_BLX:
27628 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27629 if (ARM_IS_FUNC (fixP->fx_addsy))
27630 return 1;
27631 break;
27632
27633 case BFD_RELOC_ARM_PCREL_CALL:
27634 case BFD_RELOC_THUMB_PCREL_BLX:
27635 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27636 return 1;
267bf995
RR
27637 break;
27638
27639 default:
27640 break;
27641 }
27642
27643 }
27644 return 0;
27645}
f31fef98 27646#endif /* OBJ_ELF */
This page took 4.533252 seconds and 4 git commands to generate.