]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
2571583a 2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
c168ce07 150static arm_feature_set *dyn_mcpu_ext_opt = NULL;
e74cfd16
PB
151static const arm_feature_set *mcpu_fpu_opt = NULL;
152static const arm_feature_set *march_cpu_opt = NULL;
c168ce07 153static arm_feature_set *dyn_march_ext_opt = NULL;
e74cfd16
PB
154static const arm_feature_set *march_fpu_opt = NULL;
155static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 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
TG
175static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
176static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
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);
192static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
193static const arm_feature_set arm_ext_v6_notm =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
195static const arm_feature_set arm_ext_v6_dsp =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
197static const arm_feature_set arm_ext_barrier =
198 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
199static const arm_feature_set arm_ext_msr =
200 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
201static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
202static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
203static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
204static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 205#ifdef OBJ_ELF
e7d39ed3 206static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 207#endif
823d2571 208static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 209static const arm_feature_set arm_ext_m =
16a1fa25
TP
210 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M,
211 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
212static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
213static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
214static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
215static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
216static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 217static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 218static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
219static const arm_feature_set arm_ext_v8m_main =
220 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
221/* Instructions in ARMv8-M only found in M profile architectures. */
222static const arm_feature_set arm_ext_v8m_m_only =
223 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
224static const arm_feature_set arm_ext_v6t2_v8m =
225 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
226/* Instructions shared between ARMv8-A and ARMv8-M. */
227static const arm_feature_set arm_ext_atomics =
228 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 229#ifdef OBJ_ELF
15afaa63
TP
230/* DSP instructions Tag_DSP_extension refers to. */
231static const arm_feature_set arm_ext_dsp =
232 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 233#endif
4d1464f2
MW
234static const arm_feature_set arm_ext_ras =
235 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
236/* FP16 instructions. */
237static const arm_feature_set arm_ext_fp16 =
238 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
49e8a725
SN
239static const arm_feature_set arm_ext_v8_3 =
240 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
241
242static const arm_feature_set arm_arch_any = ARM_ANY;
2c6b98ea 243static const arm_feature_set fpu_any = FPU_ANY;
f85d59c3 244static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
245static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
246static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
69c9e028 247#ifdef OBJ_ELF
251665fc 248static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
69c9e028 249#endif
e74cfd16 250
2d447fca 251static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 252 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 253static const arm_feature_set arm_cext_iwmmxt =
823d2571 254 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 255static const arm_feature_set arm_cext_xscale =
823d2571 256 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 257static const arm_feature_set arm_cext_maverick =
823d2571
TG
258 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
259static const arm_feature_set fpu_fpa_ext_v1 =
260 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
261static const arm_feature_set fpu_fpa_ext_v2 =
262 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 263static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
264 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
265static const arm_feature_set fpu_vfp_ext_v1 =
266 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
267static const arm_feature_set fpu_vfp_ext_v2 =
268 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
269static const arm_feature_set fpu_vfp_ext_v3xd =
270 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
271static const arm_feature_set fpu_vfp_ext_v3 =
272 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 273static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
274 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
275static const arm_feature_set fpu_neon_ext_v1 =
276 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 277static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 278 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 279#ifdef OBJ_ELF
823d2571
TG
280static const arm_feature_set fpu_vfp_fp16 =
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
282static const arm_feature_set fpu_neon_ext_fma =
283 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 284#endif
823d2571
TG
285static const arm_feature_set fpu_vfp_ext_fma =
286 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 287static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 288 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 289static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 290 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 291static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 292 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 293static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 294 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 295static const arm_feature_set crc_ext_armv8 =
823d2571 296 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 297static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 298 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 299
33a392fb 300static int mfloat_abi_opt = -1;
e74cfd16
PB
301/* Record user cpu selection for object attributes. */
302static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 303/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 304static char selected_cpu_name[20];
8d67f500 305
aacf0b33
KT
306extern FLONUM_TYPE generic_floating_point_number;
307
8d67f500
NC
308/* Return if no cpu was selected on command-line. */
309static bfd_boolean
310no_cpu_selected (void)
311{
823d2571 312 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
313}
314
7cc69913 315#ifdef OBJ_ELF
deeaaff8
DJ
316# ifdef EABI_DEFAULT
317static int meabi_flags = EABI_DEFAULT;
318# else
d507cf36 319static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 320# endif
e1da3f5b 321
ee3c0378
AS
322static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
323
e1da3f5b 324bfd_boolean
5f4273c7 325arm_is_eabi (void)
e1da3f5b
PB
326{
327 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
328}
7cc69913 329#endif
b99bd4ef 330
b99bd4ef 331#ifdef OBJ_ELF
c19d1205 332/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
333symbolS * GOT_symbol;
334#endif
335
b99bd4ef
NC
336/* 0: assemble for ARM,
337 1: assemble for Thumb,
338 2: assemble for Thumb even though target CPU does not support thumb
339 instructions. */
340static int thumb_mode = 0;
8dc2430f
NC
341/* A value distinct from the possible values for thumb_mode that we
342 can use to record whether thumb_mode has been copied into the
343 tc_frag_data field of a frag. */
344#define MODE_RECORDED (1 << 4)
b99bd4ef 345
e07e6e58
NC
346/* Specifies the intrinsic IT insn behavior mode. */
347enum implicit_it_mode
348{
349 IMPLICIT_IT_MODE_NEVER = 0x00,
350 IMPLICIT_IT_MODE_ARM = 0x01,
351 IMPLICIT_IT_MODE_THUMB = 0x02,
352 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
353};
354static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
355
c19d1205
ZW
356/* If unified_syntax is true, we are processing the new unified
357 ARM/Thumb syntax. Important differences from the old ARM mode:
358
359 - Immediate operands do not require a # prefix.
360 - Conditional affixes always appear at the end of the
361 instruction. (For backward compatibility, those instructions
362 that formerly had them in the middle, continue to accept them
363 there.)
364 - The IT instruction may appear, and if it does is validated
365 against subsequent conditional affixes. It does not generate
366 machine code.
367
368 Important differences from the old Thumb mode:
369
370 - Immediate operands do not require a # prefix.
371 - Most of the V6T2 instructions are only available in unified mode.
372 - The .N and .W suffixes are recognized and honored (it is an error
373 if they cannot be honored).
374 - All instructions set the flags if and only if they have an 's' affix.
375 - Conditional affixes may be used. They are validated against
376 preceding IT instructions. Unlike ARM mode, you cannot use a
377 conditional affix except in the scope of an IT instruction. */
378
379static bfd_boolean unified_syntax = FALSE;
b99bd4ef 380
bacebabc
RM
381/* An immediate operand can start with #, and ld*, st*, pld operands
382 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
383 before a [, which can appear as the first operand for pld.
384 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
385const char arm_symbol_chars[] = "#[]{}";
bacebabc 386
5287ad62
JB
387enum neon_el_type
388{
dcbf9037 389 NT_invtype,
5287ad62
JB
390 NT_untyped,
391 NT_integer,
392 NT_float,
393 NT_poly,
394 NT_signed,
dcbf9037 395 NT_unsigned
5287ad62
JB
396};
397
398struct neon_type_el
399{
400 enum neon_el_type type;
401 unsigned size;
402};
403
404#define NEON_MAX_TYPE_ELS 4
405
406struct neon_type
407{
408 struct neon_type_el el[NEON_MAX_TYPE_ELS];
409 unsigned elems;
410};
411
e07e6e58
NC
412enum it_instruction_type
413{
414 OUTSIDE_IT_INSN,
415 INSIDE_IT_INSN,
416 INSIDE_IT_LAST_INSN,
417 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 418 if inside, should be the last one. */
e07e6e58 419 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 420 i.e. BKPT and NOP. */
e07e6e58
NC
421 IT_INSN /* The IT insn has been parsed. */
422};
423
ad6cec43
MGD
424/* The maximum number of operands we need. */
425#define ARM_IT_MAX_OPERANDS 6
426
b99bd4ef
NC
427struct arm_it
428{
c19d1205 429 const char * error;
b99bd4ef 430 unsigned long instruction;
c19d1205
ZW
431 int size;
432 int size_req;
433 int cond;
037e8744
JB
434 /* "uncond_value" is set to the value in place of the conditional field in
435 unconditional versions of the instruction, or -1 if nothing is
436 appropriate. */
437 int uncond_value;
5287ad62 438 struct neon_type vectype;
88714cb8
DG
439 /* This does not indicate an actual NEON instruction, only that
440 the mnemonic accepts neon-style type suffixes. */
441 int is_neon;
0110f2b8
PB
442 /* Set to the opcode if the instruction needs relaxation.
443 Zero if the instruction is not relaxed. */
444 unsigned long relax;
b99bd4ef
NC
445 struct
446 {
447 bfd_reloc_code_real_type type;
c19d1205
ZW
448 expressionS exp;
449 int pc_rel;
b99bd4ef 450 } reloc;
b99bd4ef 451
e07e6e58
NC
452 enum it_instruction_type it_insn_type;
453
c19d1205
ZW
454 struct
455 {
456 unsigned reg;
ca3f61f7 457 signed int imm;
dcbf9037 458 struct neon_type_el vectype;
ca3f61f7
NC
459 unsigned present : 1; /* Operand present. */
460 unsigned isreg : 1; /* Operand was a register. */
461 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
462 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
463 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 464 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
465 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
466 instructions. This allows us to disambiguate ARM <-> vector insns. */
467 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 468 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 469 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 470 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
471 unsigned hasreloc : 1; /* Operand has relocation suffix. */
472 unsigned writeback : 1; /* Operand has trailing ! */
473 unsigned preind : 1; /* Preindexed address. */
474 unsigned postind : 1; /* Postindexed address. */
475 unsigned negative : 1; /* Index register was negated. */
476 unsigned shifted : 1; /* Shift applied to operation. */
477 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 478 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
479};
480
c19d1205 481static struct arm_it inst;
b99bd4ef
NC
482
483#define NUM_FLOAT_VALS 8
484
05d2d07e 485const char * fp_const[] =
b99bd4ef
NC
486{
487 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
488};
489
c19d1205 490/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
491#define MAX_LITTLENUMS 6
492
493LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
494
495#define FAIL (-1)
496#define SUCCESS (0)
497
498#define SUFF_S 1
499#define SUFF_D 2
500#define SUFF_E 3
501#define SUFF_P 4
502
c19d1205
ZW
503#define CP_T_X 0x00008000
504#define CP_T_Y 0x00400000
b99bd4ef 505
c19d1205
ZW
506#define CONDS_BIT 0x00100000
507#define LOAD_BIT 0x00100000
b99bd4ef
NC
508
509#define DOUBLE_LOAD_FLAG 0x00000001
510
511struct asm_cond
512{
d3ce72d0 513 const char * template_name;
c921be7d 514 unsigned long value;
b99bd4ef
NC
515};
516
c19d1205 517#define COND_ALWAYS 0xE
b99bd4ef 518
b99bd4ef
NC
519struct asm_psr
520{
d3ce72d0 521 const char * template_name;
c921be7d 522 unsigned long field;
b99bd4ef
NC
523};
524
62b3e311
PB
525struct asm_barrier_opt
526{
e797f7e0
MGD
527 const char * template_name;
528 unsigned long value;
529 const arm_feature_set arch;
62b3e311
PB
530};
531
2d2255b5 532/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
533#define SPSR_BIT (1 << 22)
534
c19d1205
ZW
535/* The individual PSR flag bits. */
536#define PSR_c (1 << 16)
537#define PSR_x (1 << 17)
538#define PSR_s (1 << 18)
539#define PSR_f (1 << 19)
b99bd4ef 540
c19d1205 541struct reloc_entry
bfae80f2 542{
e0471c16 543 const char * name;
c921be7d 544 bfd_reloc_code_real_type reloc;
bfae80f2
RE
545};
546
5287ad62 547enum vfp_reg_pos
bfae80f2 548{
5287ad62
JB
549 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
550 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
551};
552
553enum vfp_ldstm_type
554{
555 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
556};
557
dcbf9037
JB
558/* Bits for DEFINED field in neon_typed_alias. */
559#define NTA_HASTYPE 1
560#define NTA_HASINDEX 2
561
562struct neon_typed_alias
563{
c921be7d
NC
564 unsigned char defined;
565 unsigned char index;
566 struct neon_type_el eltype;
dcbf9037
JB
567};
568
c19d1205
ZW
569/* ARM register categories. This includes coprocessor numbers and various
570 architecture extensions' registers. */
571enum arm_reg_type
bfae80f2 572{
c19d1205
ZW
573 REG_TYPE_RN,
574 REG_TYPE_CP,
575 REG_TYPE_CN,
576 REG_TYPE_FN,
577 REG_TYPE_VFS,
578 REG_TYPE_VFD,
5287ad62 579 REG_TYPE_NQ,
037e8744 580 REG_TYPE_VFSD,
5287ad62 581 REG_TYPE_NDQ,
037e8744 582 REG_TYPE_NSDQ,
c19d1205
ZW
583 REG_TYPE_VFC,
584 REG_TYPE_MVF,
585 REG_TYPE_MVD,
586 REG_TYPE_MVFX,
587 REG_TYPE_MVDX,
588 REG_TYPE_MVAX,
589 REG_TYPE_DSPSC,
590 REG_TYPE_MMXWR,
591 REG_TYPE_MMXWC,
592 REG_TYPE_MMXWCG,
593 REG_TYPE_XSCALE,
90ec0d68 594 REG_TYPE_RNB
bfae80f2
RE
595};
596
dcbf9037
JB
597/* Structure for a hash table entry for a register.
598 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
599 information which states whether a vector type or index is specified (for a
600 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
601struct reg_entry
602{
c921be7d 603 const char * name;
90ec0d68 604 unsigned int number;
c921be7d
NC
605 unsigned char type;
606 unsigned char builtin;
607 struct neon_typed_alias * neon;
6c43fab6
RE
608};
609
c19d1205 610/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 611const char * const reg_expected_msgs[] =
c19d1205
ZW
612{
613 N_("ARM register expected"),
614 N_("bad or missing co-processor number"),
615 N_("co-processor register expected"),
616 N_("FPA register expected"),
617 N_("VFP single precision register expected"),
5287ad62
JB
618 N_("VFP/Neon double precision register expected"),
619 N_("Neon quad precision register expected"),
037e8744 620 N_("VFP single or double precision register expected"),
5287ad62 621 N_("Neon double or quad precision register expected"),
037e8744 622 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
623 N_("VFP system register expected"),
624 N_("Maverick MVF register expected"),
625 N_("Maverick MVD register expected"),
626 N_("Maverick MVFX register expected"),
627 N_("Maverick MVDX register expected"),
628 N_("Maverick MVAX register expected"),
629 N_("Maverick DSPSC register expected"),
630 N_("iWMMXt data register expected"),
631 N_("iWMMXt control register expected"),
632 N_("iWMMXt scalar register expected"),
633 N_("XScale accumulator register expected"),
6c43fab6
RE
634};
635
c19d1205 636/* Some well known registers that we refer to directly elsewhere. */
bd340a04 637#define REG_R12 12
c19d1205
ZW
638#define REG_SP 13
639#define REG_LR 14
640#define REG_PC 15
404ff6b5 641
b99bd4ef
NC
642/* ARM instructions take 4bytes in the object file, Thumb instructions
643 take 2: */
c19d1205 644#define INSN_SIZE 4
b99bd4ef
NC
645
646struct asm_opcode
647{
648 /* Basic string to match. */
d3ce72d0 649 const char * template_name;
c19d1205
ZW
650
651 /* Parameters to instruction. */
5be8be5d 652 unsigned int operands[8];
c19d1205
ZW
653
654 /* Conditional tag - see opcode_lookup. */
655 unsigned int tag : 4;
b99bd4ef
NC
656
657 /* Basic instruction code. */
c19d1205 658 unsigned int avalue : 28;
b99bd4ef 659
c19d1205
ZW
660 /* Thumb-format instruction code. */
661 unsigned int tvalue;
b99bd4ef 662
90e4755a 663 /* Which architecture variant provides this instruction. */
c921be7d
NC
664 const arm_feature_set * avariant;
665 const arm_feature_set * tvariant;
c19d1205
ZW
666
667 /* Function to call to encode instruction in ARM format. */
668 void (* aencode) (void);
b99bd4ef 669
c19d1205
ZW
670 /* Function to call to encode instruction in Thumb format. */
671 void (* tencode) (void);
b99bd4ef
NC
672};
673
a737bd4d
NC
674/* Defines for various bits that we will want to toggle. */
675#define INST_IMMEDIATE 0x02000000
676#define OFFSET_REG 0x02000000
c19d1205 677#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
678#define SHIFT_BY_REG 0x00000010
679#define PRE_INDEX 0x01000000
680#define INDEX_UP 0x00800000
681#define WRITE_BACK 0x00200000
682#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 683#define CPSI_MMOD 0x00020000
90e4755a 684
a737bd4d
NC
685#define LITERAL_MASK 0xf000f000
686#define OPCODE_MASK 0xfe1fffff
687#define V4_STR_BIT 0x00000020
8335d6aa 688#define VLDR_VMOV_SAME 0x0040f000
90e4755a 689
efd81785
PB
690#define T2_SUBS_PC_LR 0xf3de8f00
691
a737bd4d 692#define DATA_OP_SHIFT 21
bada4342 693#define SBIT_SHIFT 20
90e4755a 694
ef8d22e6
PB
695#define T2_OPCODE_MASK 0xfe1fffff
696#define T2_DATA_OP_SHIFT 21
bada4342 697#define T2_SBIT_SHIFT 20
ef8d22e6 698
6530b175
NC
699#define A_COND_MASK 0xf0000000
700#define A_PUSH_POP_OP_MASK 0x0fff0000
701
702/* Opcodes for pushing/poping registers to/from the stack. */
703#define A1_OPCODE_PUSH 0x092d0000
704#define A2_OPCODE_PUSH 0x052d0004
705#define A2_OPCODE_POP 0x049d0004
706
a737bd4d
NC
707/* Codes to distinguish the arithmetic instructions. */
708#define OPCODE_AND 0
709#define OPCODE_EOR 1
710#define OPCODE_SUB 2
711#define OPCODE_RSB 3
712#define OPCODE_ADD 4
713#define OPCODE_ADC 5
714#define OPCODE_SBC 6
715#define OPCODE_RSC 7
716#define OPCODE_TST 8
717#define OPCODE_TEQ 9
718#define OPCODE_CMP 10
719#define OPCODE_CMN 11
720#define OPCODE_ORR 12
721#define OPCODE_MOV 13
722#define OPCODE_BIC 14
723#define OPCODE_MVN 15
90e4755a 724
ef8d22e6
PB
725#define T2_OPCODE_AND 0
726#define T2_OPCODE_BIC 1
727#define T2_OPCODE_ORR 2
728#define T2_OPCODE_ORN 3
729#define T2_OPCODE_EOR 4
730#define T2_OPCODE_ADD 8
731#define T2_OPCODE_ADC 10
732#define T2_OPCODE_SBC 11
733#define T2_OPCODE_SUB 13
734#define T2_OPCODE_RSB 14
735
a737bd4d
NC
736#define T_OPCODE_MUL 0x4340
737#define T_OPCODE_TST 0x4200
738#define T_OPCODE_CMN 0x42c0
739#define T_OPCODE_NEG 0x4240
740#define T_OPCODE_MVN 0x43c0
90e4755a 741
a737bd4d
NC
742#define T_OPCODE_ADD_R3 0x1800
743#define T_OPCODE_SUB_R3 0x1a00
744#define T_OPCODE_ADD_HI 0x4400
745#define T_OPCODE_ADD_ST 0xb000
746#define T_OPCODE_SUB_ST 0xb080
747#define T_OPCODE_ADD_SP 0xa800
748#define T_OPCODE_ADD_PC 0xa000
749#define T_OPCODE_ADD_I8 0x3000
750#define T_OPCODE_SUB_I8 0x3800
751#define T_OPCODE_ADD_I3 0x1c00
752#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 753
a737bd4d
NC
754#define T_OPCODE_ASR_R 0x4100
755#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
756#define T_OPCODE_LSR_R 0x40c0
757#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
758#define T_OPCODE_ASR_I 0x1000
759#define T_OPCODE_LSL_I 0x0000
760#define T_OPCODE_LSR_I 0x0800
b99bd4ef 761
a737bd4d
NC
762#define T_OPCODE_MOV_I8 0x2000
763#define T_OPCODE_CMP_I8 0x2800
764#define T_OPCODE_CMP_LR 0x4280
765#define T_OPCODE_MOV_HR 0x4600
766#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 767
a737bd4d
NC
768#define T_OPCODE_LDR_PC 0x4800
769#define T_OPCODE_LDR_SP 0x9800
770#define T_OPCODE_STR_SP 0x9000
771#define T_OPCODE_LDR_IW 0x6800
772#define T_OPCODE_STR_IW 0x6000
773#define T_OPCODE_LDR_IH 0x8800
774#define T_OPCODE_STR_IH 0x8000
775#define T_OPCODE_LDR_IB 0x7800
776#define T_OPCODE_STR_IB 0x7000
777#define T_OPCODE_LDR_RW 0x5800
778#define T_OPCODE_STR_RW 0x5000
779#define T_OPCODE_LDR_RH 0x5a00
780#define T_OPCODE_STR_RH 0x5200
781#define T_OPCODE_LDR_RB 0x5c00
782#define T_OPCODE_STR_RB 0x5400
c9b604bd 783
a737bd4d
NC
784#define T_OPCODE_PUSH 0xb400
785#define T_OPCODE_POP 0xbc00
b99bd4ef 786
2fc8bdac 787#define T_OPCODE_BRANCH 0xe000
b99bd4ef 788
a737bd4d 789#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 790#define THUMB_PP_PC_LR 0x0100
c19d1205 791#define THUMB_LOAD_BIT 0x0800
53365c0d 792#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
793
794#define BAD_ARGS _("bad arguments to instruction")
fdfde340 795#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
796#define BAD_PC _("r15 not allowed here")
797#define BAD_COND _("instruction cannot be conditional")
798#define BAD_OVERLAP _("registers may not be the same")
799#define BAD_HIREG _("lo register required")
800#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 801#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
802#define BAD_BRANCH _("branch must be last instruction in IT block")
803#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 804#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
805#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
806#define BAD_IT_COND _("incorrect condition in IT block")
807#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 808#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
809#define BAD_PC_ADDRESSING \
810 _("cannot use register index with PC-relative addressing")
811#define BAD_PC_WRITEBACK \
812 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
813#define BAD_RANGE _("branch out of range")
814#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 815#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 816#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 817
c921be7d
NC
818static struct hash_control * arm_ops_hsh;
819static struct hash_control * arm_cond_hsh;
820static struct hash_control * arm_shift_hsh;
821static struct hash_control * arm_psr_hsh;
822static struct hash_control * arm_v7m_psr_hsh;
823static struct hash_control * arm_reg_hsh;
824static struct hash_control * arm_reloc_hsh;
825static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 826
b99bd4ef
NC
827/* Stuff needed to resolve the label ambiguity
828 As:
829 ...
830 label: <insn>
831 may differ from:
832 ...
833 label:
5f4273c7 834 <insn> */
b99bd4ef
NC
835
836symbolS * last_label_seen;
b34976b6 837static int label_is_thumb_function_name = FALSE;
e07e6e58 838
3d0c9500
NC
839/* Literal pool structure. Held on a per-section
840 and per-sub-section basis. */
a737bd4d 841
c19d1205 842#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 843typedef struct literal_pool
b99bd4ef 844{
c921be7d
NC
845 expressionS literals [MAX_LITERAL_POOL_SIZE];
846 unsigned int next_free_entry;
847 unsigned int id;
848 symbolS * symbol;
849 segT section;
850 subsegT sub_section;
a8040cf2
NC
851#ifdef OBJ_ELF
852 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
853#endif
c921be7d 854 struct literal_pool * next;
8335d6aa 855 unsigned int alignment;
3d0c9500 856} literal_pool;
b99bd4ef 857
3d0c9500
NC
858/* Pointer to a linked list of literal pools. */
859literal_pool * list_of_pools = NULL;
e27ec89e 860
2e6976a8
DG
861typedef enum asmfunc_states
862{
863 OUTSIDE_ASMFUNC,
864 WAITING_ASMFUNC_NAME,
865 WAITING_ENDASMFUNC
866} asmfunc_states;
867
868static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
869
e07e6e58
NC
870#ifdef OBJ_ELF
871# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
872#else
873static struct current_it now_it;
874#endif
875
876static inline int
877now_it_compatible (int cond)
878{
879 return (cond & ~1) == (now_it.cc & ~1);
880}
881
882static inline int
883conditional_insn (void)
884{
885 return inst.cond != COND_ALWAYS;
886}
887
888static int in_it_block (void);
889
890static int handle_it_state (void);
891
892static void force_automatic_it_block_close (void);
893
c921be7d
NC
894static void it_fsm_post_encode (void);
895
e07e6e58
NC
896#define set_it_insn_type(type) \
897 do \
898 { \
899 inst.it_insn_type = type; \
900 if (handle_it_state () == FAIL) \
477330fc 901 return; \
e07e6e58
NC
902 } \
903 while (0)
904
c921be7d
NC
905#define set_it_insn_type_nonvoid(type, failret) \
906 do \
907 { \
908 inst.it_insn_type = type; \
909 if (handle_it_state () == FAIL) \
477330fc 910 return failret; \
c921be7d
NC
911 } \
912 while(0)
913
e07e6e58
NC
914#define set_it_insn_type_last() \
915 do \
916 { \
917 if (inst.cond == COND_ALWAYS) \
477330fc 918 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 919 else \
477330fc 920 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
921 } \
922 while (0)
923
c19d1205 924/* Pure syntax. */
b99bd4ef 925
c19d1205
ZW
926/* This array holds the chars that always start a comment. If the
927 pre-processor is disabled, these aren't very useful. */
2e6976a8 928char arm_comment_chars[] = "@";
3d0c9500 929
c19d1205
ZW
930/* This array holds the chars that only start a comment at the beginning of
931 a line. If the line seems to have the form '# 123 filename'
932 .line and .file directives will appear in the pre-processed output. */
933/* Note that input_file.c hand checks for '#' at the beginning of the
934 first line of the input file. This is because the compiler outputs
935 #NO_APP at the beginning of its output. */
936/* Also note that comments like this one will always work. */
937const char line_comment_chars[] = "#";
3d0c9500 938
2e6976a8 939char arm_line_separator_chars[] = ";";
b99bd4ef 940
c19d1205
ZW
941/* Chars that can be used to separate mant
942 from exp in floating point numbers. */
943const char EXP_CHARS[] = "eE";
3d0c9500 944
c19d1205
ZW
945/* Chars that mean this number is a floating point constant. */
946/* As in 0f12.456 */
947/* or 0d1.2345e12 */
b99bd4ef 948
c19d1205 949const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 950
c19d1205
ZW
951/* Prefix characters that indicate the start of an immediate
952 value. */
953#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 954
c19d1205
ZW
955/* Separator character handling. */
956
957#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
958
959static inline int
960skip_past_char (char ** str, char c)
961{
8ab8155f
NC
962 /* PR gas/14987: Allow for whitespace before the expected character. */
963 skip_whitespace (*str);
427d0db6 964
c19d1205
ZW
965 if (**str == c)
966 {
967 (*str)++;
968 return SUCCESS;
3d0c9500 969 }
c19d1205
ZW
970 else
971 return FAIL;
972}
c921be7d 973
c19d1205 974#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 975
c19d1205
ZW
976/* Arithmetic expressions (possibly involving symbols). */
977
978/* Return TRUE if anything in the expression is a bignum. */
979
980static int
981walk_no_bignums (symbolS * sp)
982{
983 if (symbol_get_value_expression (sp)->X_op == O_big)
984 return 1;
985
986 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 987 {
c19d1205
ZW
988 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
989 || (symbol_get_value_expression (sp)->X_op_symbol
990 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
991 }
992
c19d1205 993 return 0;
3d0c9500
NC
994}
995
c19d1205
ZW
996static int in_my_get_expression = 0;
997
998/* Third argument to my_get_expression. */
999#define GE_NO_PREFIX 0
1000#define GE_IMM_PREFIX 1
1001#define GE_OPT_PREFIX 2
5287ad62
JB
1002/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1003 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1004#define GE_OPT_PREFIX_BIG 3
a737bd4d 1005
b99bd4ef 1006static int
c19d1205 1007my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1008{
c19d1205
ZW
1009 char * save_in;
1010 segT seg;
b99bd4ef 1011
c19d1205
ZW
1012 /* In unified syntax, all prefixes are optional. */
1013 if (unified_syntax)
5287ad62 1014 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1015 : GE_OPT_PREFIX;
b99bd4ef 1016
c19d1205 1017 switch (prefix_mode)
b99bd4ef 1018 {
c19d1205
ZW
1019 case GE_NO_PREFIX: break;
1020 case GE_IMM_PREFIX:
1021 if (!is_immediate_prefix (**str))
1022 {
1023 inst.error = _("immediate expression requires a # prefix");
1024 return FAIL;
1025 }
1026 (*str)++;
1027 break;
1028 case GE_OPT_PREFIX:
5287ad62 1029 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1030 if (is_immediate_prefix (**str))
1031 (*str)++;
1032 break;
1033 default: abort ();
1034 }
b99bd4ef 1035
c19d1205 1036 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1037
c19d1205
ZW
1038 save_in = input_line_pointer;
1039 input_line_pointer = *str;
1040 in_my_get_expression = 1;
1041 seg = expression (ep);
1042 in_my_get_expression = 0;
1043
f86adc07 1044 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1045 {
f86adc07 1046 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1047 *str = input_line_pointer;
1048 input_line_pointer = save_in;
1049 if (inst.error == NULL)
f86adc07
NS
1050 inst.error = (ep->X_op == O_absent
1051 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1052 return 1;
1053 }
b99bd4ef 1054
c19d1205
ZW
1055#ifdef OBJ_AOUT
1056 if (seg != absolute_section
1057 && seg != text_section
1058 && seg != data_section
1059 && seg != bss_section
1060 && seg != undefined_section)
1061 {
1062 inst.error = _("bad segment");
1063 *str = input_line_pointer;
1064 input_line_pointer = save_in;
1065 return 1;
b99bd4ef 1066 }
87975d2a
AM
1067#else
1068 (void) seg;
c19d1205 1069#endif
b99bd4ef 1070
c19d1205
ZW
1071 /* Get rid of any bignums now, so that we don't generate an error for which
1072 we can't establish a line number later on. Big numbers are never valid
1073 in instructions, which is where this routine is always called. */
5287ad62
JB
1074 if (prefix_mode != GE_OPT_PREFIX_BIG
1075 && (ep->X_op == O_big
477330fc 1076 || (ep->X_add_symbol
5287ad62 1077 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1078 || (ep->X_op_symbol
5287ad62 1079 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1080 {
1081 inst.error = _("invalid constant");
1082 *str = input_line_pointer;
1083 input_line_pointer = save_in;
1084 return 1;
1085 }
b99bd4ef 1086
c19d1205
ZW
1087 *str = input_line_pointer;
1088 input_line_pointer = save_in;
1089 return 0;
b99bd4ef
NC
1090}
1091
c19d1205
ZW
1092/* Turn a string in input_line_pointer into a floating point constant
1093 of type TYPE, and store the appropriate bytes in *LITP. The number
1094 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1095 returned, or NULL on OK.
b99bd4ef 1096
c19d1205
ZW
1097 Note that fp constants aren't represent in the normal way on the ARM.
1098 In big endian mode, things are as expected. However, in little endian
1099 mode fp constants are big-endian word-wise, and little-endian byte-wise
1100 within the words. For example, (double) 1.1 in big endian mode is
1101 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1102 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1103
c19d1205 1104 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1105
6d4af3c2 1106const char *
c19d1205
ZW
1107md_atof (int type, char * litP, int * sizeP)
1108{
1109 int prec;
1110 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1111 char *t;
1112 int i;
b99bd4ef 1113
c19d1205
ZW
1114 switch (type)
1115 {
1116 case 'f':
1117 case 'F':
1118 case 's':
1119 case 'S':
1120 prec = 2;
1121 break;
b99bd4ef 1122
c19d1205
ZW
1123 case 'd':
1124 case 'D':
1125 case 'r':
1126 case 'R':
1127 prec = 4;
1128 break;
b99bd4ef 1129
c19d1205
ZW
1130 case 'x':
1131 case 'X':
499ac353 1132 prec = 5;
c19d1205 1133 break;
b99bd4ef 1134
c19d1205
ZW
1135 case 'p':
1136 case 'P':
499ac353 1137 prec = 5;
c19d1205 1138 break;
a737bd4d 1139
c19d1205
ZW
1140 default:
1141 *sizeP = 0;
499ac353 1142 return _("Unrecognized or unsupported floating point constant");
c19d1205 1143 }
b99bd4ef 1144
c19d1205
ZW
1145 t = atof_ieee (input_line_pointer, type, words);
1146 if (t)
1147 input_line_pointer = t;
499ac353 1148 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1149
c19d1205
ZW
1150 if (target_big_endian)
1151 {
1152 for (i = 0; i < prec; i++)
1153 {
499ac353
NC
1154 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1155 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1156 }
1157 }
1158 else
1159 {
e74cfd16 1160 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1161 for (i = prec - 1; i >= 0; i--)
1162 {
499ac353
NC
1163 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1164 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1165 }
1166 else
1167 /* For a 4 byte float the order of elements in `words' is 1 0.
1168 For an 8 byte float the order is 1 0 3 2. */
1169 for (i = 0; i < prec; i += 2)
1170 {
499ac353
NC
1171 md_number_to_chars (litP, (valueT) words[i + 1],
1172 sizeof (LITTLENUM_TYPE));
1173 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1174 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1175 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1176 }
1177 }
b99bd4ef 1178
499ac353 1179 return NULL;
c19d1205 1180}
b99bd4ef 1181
c19d1205
ZW
1182/* We handle all bad expressions here, so that we can report the faulty
1183 instruction in the error message. */
1184void
91d6fa6a 1185md_operand (expressionS * exp)
c19d1205
ZW
1186{
1187 if (in_my_get_expression)
91d6fa6a 1188 exp->X_op = O_illegal;
b99bd4ef
NC
1189}
1190
c19d1205 1191/* Immediate values. */
b99bd4ef 1192
c19d1205
ZW
1193/* Generic immediate-value read function for use in directives.
1194 Accepts anything that 'expression' can fold to a constant.
1195 *val receives the number. */
1196#ifdef OBJ_ELF
1197static int
1198immediate_for_directive (int *val)
b99bd4ef 1199{
c19d1205
ZW
1200 expressionS exp;
1201 exp.X_op = O_illegal;
b99bd4ef 1202
c19d1205
ZW
1203 if (is_immediate_prefix (*input_line_pointer))
1204 {
1205 input_line_pointer++;
1206 expression (&exp);
1207 }
b99bd4ef 1208
c19d1205
ZW
1209 if (exp.X_op != O_constant)
1210 {
1211 as_bad (_("expected #constant"));
1212 ignore_rest_of_line ();
1213 return FAIL;
1214 }
1215 *val = exp.X_add_number;
1216 return SUCCESS;
b99bd4ef 1217}
c19d1205 1218#endif
b99bd4ef 1219
c19d1205 1220/* Register parsing. */
b99bd4ef 1221
c19d1205
ZW
1222/* Generic register parser. CCP points to what should be the
1223 beginning of a register name. If it is indeed a valid register
1224 name, advance CCP over it and return the reg_entry structure;
1225 otherwise return NULL. Does not issue diagnostics. */
1226
1227static struct reg_entry *
1228arm_reg_parse_multi (char **ccp)
b99bd4ef 1229{
c19d1205
ZW
1230 char *start = *ccp;
1231 char *p;
1232 struct reg_entry *reg;
b99bd4ef 1233
477330fc
RM
1234 skip_whitespace (start);
1235
c19d1205
ZW
1236#ifdef REGISTER_PREFIX
1237 if (*start != REGISTER_PREFIX)
01cfc07f 1238 return NULL;
c19d1205
ZW
1239 start++;
1240#endif
1241#ifdef OPTIONAL_REGISTER_PREFIX
1242 if (*start == OPTIONAL_REGISTER_PREFIX)
1243 start++;
1244#endif
b99bd4ef 1245
c19d1205
ZW
1246 p = start;
1247 if (!ISALPHA (*p) || !is_name_beginner (*p))
1248 return NULL;
b99bd4ef 1249
c19d1205
ZW
1250 do
1251 p++;
1252 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1253
1254 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1255
1256 if (!reg)
1257 return NULL;
1258
1259 *ccp = p;
1260 return reg;
b99bd4ef
NC
1261}
1262
1263static int
dcbf9037 1264arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1265 enum arm_reg_type type)
b99bd4ef 1266{
c19d1205
ZW
1267 /* Alternative syntaxes are accepted for a few register classes. */
1268 switch (type)
1269 {
1270 case REG_TYPE_MVF:
1271 case REG_TYPE_MVD:
1272 case REG_TYPE_MVFX:
1273 case REG_TYPE_MVDX:
1274 /* Generic coprocessor register names are allowed for these. */
79134647 1275 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1276 return reg->number;
1277 break;
69b97547 1278
c19d1205
ZW
1279 case REG_TYPE_CP:
1280 /* For backward compatibility, a bare number is valid here. */
1281 {
1282 unsigned long processor = strtoul (start, ccp, 10);
1283 if (*ccp != start && processor <= 15)
1284 return processor;
1285 }
1a0670f3 1286 /* Fall through. */
6057a28f 1287
c19d1205
ZW
1288 case REG_TYPE_MMXWC:
1289 /* WC includes WCG. ??? I'm not sure this is true for all
1290 instructions that take WC registers. */
79134647 1291 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1292 return reg->number;
6057a28f 1293 break;
c19d1205 1294
6057a28f 1295 default:
c19d1205 1296 break;
6057a28f
NC
1297 }
1298
dcbf9037
JB
1299 return FAIL;
1300}
1301
1302/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1303 return value is the register number or FAIL. */
1304
1305static int
1306arm_reg_parse (char **ccp, enum arm_reg_type type)
1307{
1308 char *start = *ccp;
1309 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1310 int ret;
1311
1312 /* Do not allow a scalar (reg+index) to parse as a register. */
1313 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1314 return FAIL;
1315
1316 if (reg && reg->type == type)
1317 return reg->number;
1318
1319 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1320 return ret;
1321
c19d1205
ZW
1322 *ccp = start;
1323 return FAIL;
1324}
69b97547 1325
dcbf9037
JB
1326/* Parse a Neon type specifier. *STR should point at the leading '.'
1327 character. Does no verification at this stage that the type fits the opcode
1328 properly. E.g.,
1329
1330 .i32.i32.s16
1331 .s32.f32
1332 .u16
1333
1334 Can all be legally parsed by this function.
1335
1336 Fills in neon_type struct pointer with parsed information, and updates STR
1337 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1338 type, FAIL if not. */
1339
1340static int
1341parse_neon_type (struct neon_type *type, char **str)
1342{
1343 char *ptr = *str;
1344
1345 if (type)
1346 type->elems = 0;
1347
1348 while (type->elems < NEON_MAX_TYPE_ELS)
1349 {
1350 enum neon_el_type thistype = NT_untyped;
1351 unsigned thissize = -1u;
1352
1353 if (*ptr != '.')
1354 break;
1355
1356 ptr++;
1357
1358 /* Just a size without an explicit type. */
1359 if (ISDIGIT (*ptr))
1360 goto parsesize;
1361
1362 switch (TOLOWER (*ptr))
1363 {
1364 case 'i': thistype = NT_integer; break;
1365 case 'f': thistype = NT_float; break;
1366 case 'p': thistype = NT_poly; break;
1367 case 's': thistype = NT_signed; break;
1368 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1369 case 'd':
1370 thistype = NT_float;
1371 thissize = 64;
1372 ptr++;
1373 goto done;
dcbf9037
JB
1374 default:
1375 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1376 return FAIL;
1377 }
1378
1379 ptr++;
1380
1381 /* .f is an abbreviation for .f32. */
1382 if (thistype == NT_float && !ISDIGIT (*ptr))
1383 thissize = 32;
1384 else
1385 {
1386 parsesize:
1387 thissize = strtoul (ptr, &ptr, 10);
1388
1389 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1390 && thissize != 64)
1391 {
1392 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1393 return FAIL;
1394 }
1395 }
1396
037e8744 1397 done:
dcbf9037 1398 if (type)
477330fc
RM
1399 {
1400 type->el[type->elems].type = thistype;
dcbf9037
JB
1401 type->el[type->elems].size = thissize;
1402 type->elems++;
1403 }
1404 }
1405
1406 /* Empty/missing type is not a successful parse. */
1407 if (type->elems == 0)
1408 return FAIL;
1409
1410 *str = ptr;
1411
1412 return SUCCESS;
1413}
1414
1415/* Errors may be set multiple times during parsing or bit encoding
1416 (particularly in the Neon bits), but usually the earliest error which is set
1417 will be the most meaningful. Avoid overwriting it with later (cascading)
1418 errors by calling this function. */
1419
1420static void
1421first_error (const char *err)
1422{
1423 if (!inst.error)
1424 inst.error = err;
1425}
1426
1427/* Parse a single type, e.g. ".s32", leading period included. */
1428static int
1429parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1430{
1431 char *str = *ccp;
1432 struct neon_type optype;
1433
1434 if (*str == '.')
1435 {
1436 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1437 {
1438 if (optype.elems == 1)
1439 *vectype = optype.el[0];
1440 else
1441 {
1442 first_error (_("only one type should be specified for operand"));
1443 return FAIL;
1444 }
1445 }
dcbf9037 1446 else
477330fc
RM
1447 {
1448 first_error (_("vector type expected"));
1449 return FAIL;
1450 }
dcbf9037
JB
1451 }
1452 else
1453 return FAIL;
5f4273c7 1454
dcbf9037 1455 *ccp = str;
5f4273c7 1456
dcbf9037
JB
1457 return SUCCESS;
1458}
1459
1460/* Special meanings for indices (which have a range of 0-7), which will fit into
1461 a 4-bit integer. */
1462
1463#define NEON_ALL_LANES 15
1464#define NEON_INTERLEAVE_LANES 14
1465
1466/* Parse either a register or a scalar, with an optional type. Return the
1467 register number, and optionally fill in the actual type of the register
1468 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1469 type/index information in *TYPEINFO. */
1470
1471static int
1472parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1473 enum arm_reg_type *rtype,
1474 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1475{
1476 char *str = *ccp;
1477 struct reg_entry *reg = arm_reg_parse_multi (&str);
1478 struct neon_typed_alias atype;
1479 struct neon_type_el parsetype;
1480
1481 atype.defined = 0;
1482 atype.index = -1;
1483 atype.eltype.type = NT_invtype;
1484 atype.eltype.size = -1;
1485
1486 /* Try alternate syntax for some types of register. Note these are mutually
1487 exclusive with the Neon syntax extensions. */
1488 if (reg == NULL)
1489 {
1490 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1491 if (altreg != FAIL)
477330fc 1492 *ccp = str;
dcbf9037 1493 if (typeinfo)
477330fc 1494 *typeinfo = atype;
dcbf9037
JB
1495 return altreg;
1496 }
1497
037e8744
JB
1498 /* Undo polymorphism when a set of register types may be accepted. */
1499 if ((type == REG_TYPE_NDQ
1500 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1501 || (type == REG_TYPE_VFSD
477330fc 1502 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1503 || (type == REG_TYPE_NSDQ
477330fc
RM
1504 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1505 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1506 || (type == REG_TYPE_MMXWC
1507 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1508 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1509
1510 if (type != reg->type)
1511 return FAIL;
1512
1513 if (reg->neon)
1514 atype = *reg->neon;
5f4273c7 1515
dcbf9037
JB
1516 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1517 {
1518 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1519 {
1520 first_error (_("can't redefine type for operand"));
1521 return FAIL;
1522 }
dcbf9037
JB
1523 atype.defined |= NTA_HASTYPE;
1524 atype.eltype = parsetype;
1525 }
5f4273c7 1526
dcbf9037
JB
1527 if (skip_past_char (&str, '[') == SUCCESS)
1528 {
1529 if (type != REG_TYPE_VFD)
477330fc
RM
1530 {
1531 first_error (_("only D registers may be indexed"));
1532 return FAIL;
1533 }
5f4273c7 1534
dcbf9037 1535 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1536 {
1537 first_error (_("can't change index for operand"));
1538 return FAIL;
1539 }
dcbf9037
JB
1540
1541 atype.defined |= NTA_HASINDEX;
1542
1543 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1544 atype.index = NEON_ALL_LANES;
dcbf9037 1545 else
477330fc
RM
1546 {
1547 expressionS exp;
dcbf9037 1548
477330fc 1549 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1550
477330fc
RM
1551 if (exp.X_op != O_constant)
1552 {
1553 first_error (_("constant expression required"));
1554 return FAIL;
1555 }
dcbf9037 1556
477330fc
RM
1557 if (skip_past_char (&str, ']') == FAIL)
1558 return FAIL;
dcbf9037 1559
477330fc
RM
1560 atype.index = exp.X_add_number;
1561 }
dcbf9037 1562 }
5f4273c7 1563
dcbf9037
JB
1564 if (typeinfo)
1565 *typeinfo = atype;
5f4273c7 1566
dcbf9037
JB
1567 if (rtype)
1568 *rtype = type;
5f4273c7 1569
dcbf9037 1570 *ccp = str;
5f4273c7 1571
dcbf9037
JB
1572 return reg->number;
1573}
1574
1575/* Like arm_reg_parse, but allow allow the following extra features:
1576 - If RTYPE is non-zero, return the (possibly restricted) type of the
1577 register (e.g. Neon double or quad reg when either has been requested).
1578 - If this is a Neon vector type with additional type information, fill
1579 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1580 This function will fault on encountering a scalar. */
dcbf9037
JB
1581
1582static int
1583arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1584 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1585{
1586 struct neon_typed_alias atype;
1587 char *str = *ccp;
1588 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1589
1590 if (reg == FAIL)
1591 return FAIL;
1592
0855e32b
NS
1593 /* Do not allow regname(... to parse as a register. */
1594 if (*str == '(')
1595 return FAIL;
1596
dcbf9037
JB
1597 /* Do not allow a scalar (reg+index) to parse as a register. */
1598 if ((atype.defined & NTA_HASINDEX) != 0)
1599 {
1600 first_error (_("register operand expected, but got scalar"));
1601 return FAIL;
1602 }
1603
1604 if (vectype)
1605 *vectype = atype.eltype;
1606
1607 *ccp = str;
1608
1609 return reg;
1610}
1611
1612#define NEON_SCALAR_REG(X) ((X) >> 4)
1613#define NEON_SCALAR_INDEX(X) ((X) & 15)
1614
5287ad62
JB
1615/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1616 have enough information to be able to do a good job bounds-checking. So, we
1617 just do easy checks here, and do further checks later. */
1618
1619static int
dcbf9037 1620parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1621{
dcbf9037 1622 int reg;
5287ad62 1623 char *str = *ccp;
dcbf9037 1624 struct neon_typed_alias atype;
5f4273c7 1625
dcbf9037 1626 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1627
dcbf9037 1628 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1629 return FAIL;
5f4273c7 1630
dcbf9037 1631 if (atype.index == NEON_ALL_LANES)
5287ad62 1632 {
dcbf9037 1633 first_error (_("scalar must have an index"));
5287ad62
JB
1634 return FAIL;
1635 }
dcbf9037 1636 else if (atype.index >= 64 / elsize)
5287ad62 1637 {
dcbf9037 1638 first_error (_("scalar index out of range"));
5287ad62
JB
1639 return FAIL;
1640 }
5f4273c7 1641
dcbf9037
JB
1642 if (type)
1643 *type = atype.eltype;
5f4273c7 1644
5287ad62 1645 *ccp = str;
5f4273c7 1646
dcbf9037 1647 return reg * 16 + atype.index;
5287ad62
JB
1648}
1649
c19d1205 1650/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1651
c19d1205
ZW
1652static long
1653parse_reg_list (char ** strp)
1654{
1655 char * str = * strp;
1656 long range = 0;
1657 int another_range;
a737bd4d 1658
c19d1205
ZW
1659 /* We come back here if we get ranges concatenated by '+' or '|'. */
1660 do
6057a28f 1661 {
477330fc
RM
1662 skip_whitespace (str);
1663
c19d1205 1664 another_range = 0;
a737bd4d 1665
c19d1205
ZW
1666 if (*str == '{')
1667 {
1668 int in_range = 0;
1669 int cur_reg = -1;
a737bd4d 1670
c19d1205
ZW
1671 str++;
1672 do
1673 {
1674 int reg;
6057a28f 1675
dcbf9037 1676 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1677 {
dcbf9037 1678 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1679 return FAIL;
1680 }
a737bd4d 1681
c19d1205
ZW
1682 if (in_range)
1683 {
1684 int i;
a737bd4d 1685
c19d1205
ZW
1686 if (reg <= cur_reg)
1687 {
dcbf9037 1688 first_error (_("bad range in register list"));
c19d1205
ZW
1689 return FAIL;
1690 }
40a18ebd 1691
c19d1205
ZW
1692 for (i = cur_reg + 1; i < reg; i++)
1693 {
1694 if (range & (1 << i))
1695 as_tsktsk
1696 (_("Warning: duplicated register (r%d) in register list"),
1697 i);
1698 else
1699 range |= 1 << i;
1700 }
1701 in_range = 0;
1702 }
a737bd4d 1703
c19d1205
ZW
1704 if (range & (1 << reg))
1705 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1706 reg);
1707 else if (reg <= cur_reg)
1708 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1709
c19d1205
ZW
1710 range |= 1 << reg;
1711 cur_reg = reg;
1712 }
1713 while (skip_past_comma (&str) != FAIL
1714 || (in_range = 1, *str++ == '-'));
1715 str--;
a737bd4d 1716
d996d970 1717 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1718 {
dcbf9037 1719 first_error (_("missing `}'"));
c19d1205
ZW
1720 return FAIL;
1721 }
1722 }
1723 else
1724 {
91d6fa6a 1725 expressionS exp;
40a18ebd 1726
91d6fa6a 1727 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1728 return FAIL;
40a18ebd 1729
91d6fa6a 1730 if (exp.X_op == O_constant)
c19d1205 1731 {
91d6fa6a
NC
1732 if (exp.X_add_number
1733 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1734 {
1735 inst.error = _("invalid register mask");
1736 return FAIL;
1737 }
a737bd4d 1738
91d6fa6a 1739 if ((range & exp.X_add_number) != 0)
c19d1205 1740 {
91d6fa6a 1741 int regno = range & exp.X_add_number;
a737bd4d 1742
c19d1205
ZW
1743 regno &= -regno;
1744 regno = (1 << regno) - 1;
1745 as_tsktsk
1746 (_("Warning: duplicated register (r%d) in register list"),
1747 regno);
1748 }
a737bd4d 1749
91d6fa6a 1750 range |= exp.X_add_number;
c19d1205
ZW
1751 }
1752 else
1753 {
1754 if (inst.reloc.type != 0)
1755 {
1756 inst.error = _("expression too complex");
1757 return FAIL;
1758 }
a737bd4d 1759
91d6fa6a 1760 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1761 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1762 inst.reloc.pc_rel = 0;
1763 }
1764 }
a737bd4d 1765
c19d1205
ZW
1766 if (*str == '|' || *str == '+')
1767 {
1768 str++;
1769 another_range = 1;
1770 }
a737bd4d 1771 }
c19d1205 1772 while (another_range);
a737bd4d 1773
c19d1205
ZW
1774 *strp = str;
1775 return range;
a737bd4d
NC
1776}
1777
5287ad62
JB
1778/* Types of registers in a list. */
1779
1780enum reg_list_els
1781{
1782 REGLIST_VFP_S,
1783 REGLIST_VFP_D,
1784 REGLIST_NEON_D
1785};
1786
c19d1205
ZW
1787/* Parse a VFP register list. If the string is invalid return FAIL.
1788 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1789 register. Parses registers of type ETYPE.
1790 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1791 - Q registers can be used to specify pairs of D registers
1792 - { } can be omitted from around a singleton register list
477330fc
RM
1793 FIXME: This is not implemented, as it would require backtracking in
1794 some cases, e.g.:
1795 vtbl.8 d3,d4,d5
1796 This could be done (the meaning isn't really ambiguous), but doesn't
1797 fit in well with the current parsing framework.
dcbf9037
JB
1798 - 32 D registers may be used (also true for VFPv3).
1799 FIXME: Types are ignored in these register lists, which is probably a
1800 bug. */
6057a28f 1801
c19d1205 1802static int
037e8744 1803parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1804{
037e8744 1805 char *str = *ccp;
c19d1205
ZW
1806 int base_reg;
1807 int new_base;
21d799b5 1808 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1809 int max_regs = 0;
c19d1205
ZW
1810 int count = 0;
1811 int warned = 0;
1812 unsigned long mask = 0;
a737bd4d 1813 int i;
6057a28f 1814
477330fc 1815 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1816 {
1817 inst.error = _("expecting {");
1818 return FAIL;
1819 }
6057a28f 1820
5287ad62 1821 switch (etype)
c19d1205 1822 {
5287ad62 1823 case REGLIST_VFP_S:
c19d1205
ZW
1824 regtype = REG_TYPE_VFS;
1825 max_regs = 32;
5287ad62 1826 break;
5f4273c7 1827
5287ad62
JB
1828 case REGLIST_VFP_D:
1829 regtype = REG_TYPE_VFD;
b7fc2769 1830 break;
5f4273c7 1831
b7fc2769
JB
1832 case REGLIST_NEON_D:
1833 regtype = REG_TYPE_NDQ;
1834 break;
1835 }
1836
1837 if (etype != REGLIST_VFP_S)
1838 {
b1cc4aeb
PB
1839 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1840 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1841 {
1842 max_regs = 32;
1843 if (thumb_mode)
1844 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1845 fpu_vfp_ext_d32);
1846 else
1847 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1848 fpu_vfp_ext_d32);
1849 }
5287ad62 1850 else
477330fc 1851 max_regs = 16;
c19d1205 1852 }
6057a28f 1853
c19d1205 1854 base_reg = max_regs;
a737bd4d 1855
c19d1205
ZW
1856 do
1857 {
5287ad62 1858 int setmask = 1, addregs = 1;
dcbf9037 1859
037e8744 1860 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1861
c19d1205 1862 if (new_base == FAIL)
a737bd4d 1863 {
dcbf9037 1864 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1865 return FAIL;
1866 }
5f4273c7 1867
b7fc2769 1868 if (new_base >= max_regs)
477330fc
RM
1869 {
1870 first_error (_("register out of range in list"));
1871 return FAIL;
1872 }
5f4273c7 1873
5287ad62
JB
1874 /* Note: a value of 2 * n is returned for the register Q<n>. */
1875 if (regtype == REG_TYPE_NQ)
477330fc
RM
1876 {
1877 setmask = 3;
1878 addregs = 2;
1879 }
5287ad62 1880
c19d1205
ZW
1881 if (new_base < base_reg)
1882 base_reg = new_base;
a737bd4d 1883
5287ad62 1884 if (mask & (setmask << new_base))
c19d1205 1885 {
dcbf9037 1886 first_error (_("invalid register list"));
c19d1205 1887 return FAIL;
a737bd4d 1888 }
a737bd4d 1889
c19d1205
ZW
1890 if ((mask >> new_base) != 0 && ! warned)
1891 {
1892 as_tsktsk (_("register list not in ascending order"));
1893 warned = 1;
1894 }
0bbf2aa4 1895
5287ad62
JB
1896 mask |= setmask << new_base;
1897 count += addregs;
0bbf2aa4 1898
037e8744 1899 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1900 {
1901 int high_range;
0bbf2aa4 1902
037e8744 1903 str++;
0bbf2aa4 1904
037e8744 1905 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1906 == FAIL)
c19d1205
ZW
1907 {
1908 inst.error = gettext (reg_expected_msgs[regtype]);
1909 return FAIL;
1910 }
0bbf2aa4 1911
477330fc
RM
1912 if (high_range >= max_regs)
1913 {
1914 first_error (_("register out of range in list"));
1915 return FAIL;
1916 }
b7fc2769 1917
477330fc
RM
1918 if (regtype == REG_TYPE_NQ)
1919 high_range = high_range + 1;
5287ad62 1920
c19d1205
ZW
1921 if (high_range <= new_base)
1922 {
1923 inst.error = _("register range not in ascending order");
1924 return FAIL;
1925 }
0bbf2aa4 1926
5287ad62 1927 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1928 {
5287ad62 1929 if (mask & (setmask << new_base))
0bbf2aa4 1930 {
c19d1205
ZW
1931 inst.error = _("invalid register list");
1932 return FAIL;
0bbf2aa4 1933 }
c19d1205 1934
5287ad62
JB
1935 mask |= setmask << new_base;
1936 count += addregs;
0bbf2aa4 1937 }
0bbf2aa4 1938 }
0bbf2aa4 1939 }
037e8744 1940 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1941
037e8744 1942 str++;
0bbf2aa4 1943
c19d1205
ZW
1944 /* Sanity check -- should have raised a parse error above. */
1945 if (count == 0 || count > max_regs)
1946 abort ();
1947
1948 *pbase = base_reg;
1949
1950 /* Final test -- the registers must be consecutive. */
1951 mask >>= base_reg;
1952 for (i = 0; i < count; i++)
1953 {
1954 if ((mask & (1u << i)) == 0)
1955 {
1956 inst.error = _("non-contiguous register range");
1957 return FAIL;
1958 }
1959 }
1960
037e8744
JB
1961 *ccp = str;
1962
c19d1205 1963 return count;
b99bd4ef
NC
1964}
1965
dcbf9037
JB
1966/* True if two alias types are the same. */
1967
c921be7d 1968static bfd_boolean
dcbf9037
JB
1969neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1970{
1971 if (!a && !b)
c921be7d 1972 return TRUE;
5f4273c7 1973
dcbf9037 1974 if (!a || !b)
c921be7d 1975 return FALSE;
dcbf9037
JB
1976
1977 if (a->defined != b->defined)
c921be7d 1978 return FALSE;
5f4273c7 1979
dcbf9037
JB
1980 if ((a->defined & NTA_HASTYPE) != 0
1981 && (a->eltype.type != b->eltype.type
477330fc 1982 || a->eltype.size != b->eltype.size))
c921be7d 1983 return FALSE;
dcbf9037
JB
1984
1985 if ((a->defined & NTA_HASINDEX) != 0
1986 && (a->index != b->index))
c921be7d 1987 return FALSE;
5f4273c7 1988
c921be7d 1989 return TRUE;
dcbf9037
JB
1990}
1991
5287ad62
JB
1992/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1993 The base register is put in *PBASE.
dcbf9037 1994 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1995 the return value.
1996 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1997 Bits [6:5] encode the list length (minus one).
1998 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1999
5287ad62 2000#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2001#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2002#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2003
2004static int
dcbf9037 2005parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2006 struct neon_type_el *eltype)
5287ad62
JB
2007{
2008 char *ptr = *str;
2009 int base_reg = -1;
2010 int reg_incr = -1;
2011 int count = 0;
2012 int lane = -1;
2013 int leading_brace = 0;
2014 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2015 const char *const incr_error = _("register stride must be 1 or 2");
2016 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2017 struct neon_typed_alias firsttype;
f85d59c3
KT
2018 firsttype.defined = 0;
2019 firsttype.eltype.type = NT_invtype;
2020 firsttype.eltype.size = -1;
2021 firsttype.index = -1;
5f4273c7 2022
5287ad62
JB
2023 if (skip_past_char (&ptr, '{') == SUCCESS)
2024 leading_brace = 1;
5f4273c7 2025
5287ad62
JB
2026 do
2027 {
dcbf9037
JB
2028 struct neon_typed_alias atype;
2029 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2030
5287ad62 2031 if (getreg == FAIL)
477330fc
RM
2032 {
2033 first_error (_(reg_expected_msgs[rtype]));
2034 return FAIL;
2035 }
5f4273c7 2036
5287ad62 2037 if (base_reg == -1)
477330fc
RM
2038 {
2039 base_reg = getreg;
2040 if (rtype == REG_TYPE_NQ)
2041 {
2042 reg_incr = 1;
2043 }
2044 firsttype = atype;
2045 }
5287ad62 2046 else if (reg_incr == -1)
477330fc
RM
2047 {
2048 reg_incr = getreg - base_reg;
2049 if (reg_incr < 1 || reg_incr > 2)
2050 {
2051 first_error (_(incr_error));
2052 return FAIL;
2053 }
2054 }
5287ad62 2055 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2056 {
2057 first_error (_(incr_error));
2058 return FAIL;
2059 }
dcbf9037 2060
c921be7d 2061 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2062 {
2063 first_error (_(type_error));
2064 return FAIL;
2065 }
5f4273c7 2066
5287ad62 2067 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2068 modes. */
5287ad62 2069 if (ptr[0] == '-')
477330fc
RM
2070 {
2071 struct neon_typed_alias htype;
2072 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2073 if (lane == -1)
2074 lane = NEON_INTERLEAVE_LANES;
2075 else if (lane != NEON_INTERLEAVE_LANES)
2076 {
2077 first_error (_(type_error));
2078 return FAIL;
2079 }
2080 if (reg_incr == -1)
2081 reg_incr = 1;
2082 else if (reg_incr != 1)
2083 {
2084 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2085 return FAIL;
2086 }
2087 ptr++;
2088 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2089 if (hireg == FAIL)
2090 {
2091 first_error (_(reg_expected_msgs[rtype]));
2092 return FAIL;
2093 }
2094 if (! neon_alias_types_same (&htype, &firsttype))
2095 {
2096 first_error (_(type_error));
2097 return FAIL;
2098 }
2099 count += hireg + dregs - getreg;
2100 continue;
2101 }
5f4273c7 2102
5287ad62
JB
2103 /* If we're using Q registers, we can't use [] or [n] syntax. */
2104 if (rtype == REG_TYPE_NQ)
477330fc
RM
2105 {
2106 count += 2;
2107 continue;
2108 }
5f4273c7 2109
dcbf9037 2110 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2111 {
2112 if (lane == -1)
2113 lane = atype.index;
2114 else if (lane != atype.index)
2115 {
2116 first_error (_(type_error));
2117 return FAIL;
2118 }
2119 }
5287ad62 2120 else if (lane == -1)
477330fc 2121 lane = NEON_INTERLEAVE_LANES;
5287ad62 2122 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2123 {
2124 first_error (_(type_error));
2125 return FAIL;
2126 }
5287ad62
JB
2127 count++;
2128 }
2129 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2130
5287ad62
JB
2131 /* No lane set by [x]. We must be interleaving structures. */
2132 if (lane == -1)
2133 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2134
5287ad62
JB
2135 /* Sanity check. */
2136 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2137 || (count > 1 && reg_incr == -1))
2138 {
dcbf9037 2139 first_error (_("error parsing element/structure list"));
5287ad62
JB
2140 return FAIL;
2141 }
2142
2143 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2144 {
dcbf9037 2145 first_error (_("expected }"));
5287ad62
JB
2146 return FAIL;
2147 }
5f4273c7 2148
5287ad62
JB
2149 if (reg_incr == -1)
2150 reg_incr = 1;
2151
dcbf9037
JB
2152 if (eltype)
2153 *eltype = firsttype.eltype;
2154
5287ad62
JB
2155 *pbase = base_reg;
2156 *str = ptr;
5f4273c7 2157
5287ad62
JB
2158 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2159}
2160
c19d1205
ZW
2161/* Parse an explicit relocation suffix on an expression. This is
2162 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2163 arm_reloc_hsh contains no entries, so this function can only
2164 succeed if there is no () after the word. Returns -1 on error,
2165 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2166
c19d1205
ZW
2167static int
2168parse_reloc (char **str)
b99bd4ef 2169{
c19d1205
ZW
2170 struct reloc_entry *r;
2171 char *p, *q;
b99bd4ef 2172
c19d1205
ZW
2173 if (**str != '(')
2174 return BFD_RELOC_UNUSED;
b99bd4ef 2175
c19d1205
ZW
2176 p = *str + 1;
2177 q = p;
2178
2179 while (*q && *q != ')' && *q != ',')
2180 q++;
2181 if (*q != ')')
2182 return -1;
2183
21d799b5
NC
2184 if ((r = (struct reloc_entry *)
2185 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2186 return -1;
2187
2188 *str = q + 1;
2189 return r->reloc;
b99bd4ef
NC
2190}
2191
c19d1205
ZW
2192/* Directives: register aliases. */
2193
dcbf9037 2194static struct reg_entry *
90ec0d68 2195insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2196{
d3ce72d0 2197 struct reg_entry *new_reg;
c19d1205 2198 const char *name;
b99bd4ef 2199
d3ce72d0 2200 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2201 {
d3ce72d0 2202 if (new_reg->builtin)
c19d1205 2203 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2204
c19d1205
ZW
2205 /* Only warn about a redefinition if it's not defined as the
2206 same register. */
d3ce72d0 2207 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2208 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2209
d929913e 2210 return NULL;
c19d1205 2211 }
b99bd4ef 2212
c19d1205 2213 name = xstrdup (str);
325801bd 2214 new_reg = XNEW (struct reg_entry);
b99bd4ef 2215
d3ce72d0
NC
2216 new_reg->name = name;
2217 new_reg->number = number;
2218 new_reg->type = type;
2219 new_reg->builtin = FALSE;
2220 new_reg->neon = NULL;
b99bd4ef 2221
d3ce72d0 2222 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2223 abort ();
5f4273c7 2224
d3ce72d0 2225 return new_reg;
dcbf9037
JB
2226}
2227
2228static void
2229insert_neon_reg_alias (char *str, int number, int type,
477330fc 2230 struct neon_typed_alias *atype)
dcbf9037
JB
2231{
2232 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2233
dcbf9037
JB
2234 if (!reg)
2235 {
2236 first_error (_("attempt to redefine typed alias"));
2237 return;
2238 }
5f4273c7 2239
dcbf9037
JB
2240 if (atype)
2241 {
325801bd 2242 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2243 *reg->neon = *atype;
2244 }
c19d1205 2245}
b99bd4ef 2246
c19d1205 2247/* Look for the .req directive. This is of the form:
b99bd4ef 2248
c19d1205 2249 new_register_name .req existing_register_name
b99bd4ef 2250
c19d1205 2251 If we find one, or if it looks sufficiently like one that we want to
d929913e 2252 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2253
d929913e 2254static bfd_boolean
c19d1205
ZW
2255create_register_alias (char * newname, char *p)
2256{
2257 struct reg_entry *old;
2258 char *oldname, *nbuf;
2259 size_t nlen;
b99bd4ef 2260
c19d1205
ZW
2261 /* The input scrubber ensures that whitespace after the mnemonic is
2262 collapsed to single spaces. */
2263 oldname = p;
2264 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2265 return FALSE;
b99bd4ef 2266
c19d1205
ZW
2267 oldname += 6;
2268 if (*oldname == '\0')
d929913e 2269 return FALSE;
b99bd4ef 2270
21d799b5 2271 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2272 if (!old)
b99bd4ef 2273 {
c19d1205 2274 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2275 return TRUE;
b99bd4ef
NC
2276 }
2277
c19d1205
ZW
2278 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2279 the desired alias name, and p points to its end. If not, then
2280 the desired alias name is in the global original_case_string. */
2281#ifdef TC_CASE_SENSITIVE
2282 nlen = p - newname;
2283#else
2284 newname = original_case_string;
2285 nlen = strlen (newname);
2286#endif
b99bd4ef 2287
29a2809e 2288 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2289
c19d1205
ZW
2290 /* Create aliases under the new name as stated; an all-lowercase
2291 version of the new name; and an all-uppercase version of the new
2292 name. */
d929913e
NC
2293 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2294 {
2295 for (p = nbuf; *p; p++)
2296 *p = TOUPPER (*p);
c19d1205 2297
d929913e
NC
2298 if (strncmp (nbuf, newname, nlen))
2299 {
2300 /* If this attempt to create an additional alias fails, do not bother
2301 trying to create the all-lower case alias. We will fail and issue
2302 a second, duplicate error message. This situation arises when the
2303 programmer does something like:
2304 foo .req r0
2305 Foo .req r1
2306 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2307 the artificial FOO alias because it has already been created by the
d929913e
NC
2308 first .req. */
2309 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2310 {
2311 free (nbuf);
2312 return TRUE;
2313 }
d929913e 2314 }
c19d1205 2315
d929913e
NC
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
c19d1205 2318
d929913e
NC
2319 if (strncmp (nbuf, newname, nlen))
2320 insert_reg_alias (nbuf, old->number, old->type);
2321 }
c19d1205 2322
e1fa0163 2323 free (nbuf);
d929913e 2324 return TRUE;
b99bd4ef
NC
2325}
2326
dcbf9037
JB
2327/* Create a Neon typed/indexed register alias using directives, e.g.:
2328 X .dn d5.s32[1]
2329 Y .qn 6.s16
2330 Z .dn d7
2331 T .dn Z[0]
2332 These typed registers can be used instead of the types specified after the
2333 Neon mnemonic, so long as all operands given have types. Types can also be
2334 specified directly, e.g.:
5f4273c7 2335 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2336
c921be7d 2337static bfd_boolean
dcbf9037
JB
2338create_neon_reg_alias (char *newname, char *p)
2339{
2340 enum arm_reg_type basetype;
2341 struct reg_entry *basereg;
2342 struct reg_entry mybasereg;
2343 struct neon_type ntype;
2344 struct neon_typed_alias typeinfo;
12d6b0b7 2345 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2346 int namelen;
5f4273c7 2347
dcbf9037
JB
2348 typeinfo.defined = 0;
2349 typeinfo.eltype.type = NT_invtype;
2350 typeinfo.eltype.size = -1;
2351 typeinfo.index = -1;
5f4273c7 2352
dcbf9037 2353 nameend = p;
5f4273c7 2354
dcbf9037
JB
2355 if (strncmp (p, " .dn ", 5) == 0)
2356 basetype = REG_TYPE_VFD;
2357 else if (strncmp (p, " .qn ", 5) == 0)
2358 basetype = REG_TYPE_NQ;
2359 else
c921be7d 2360 return FALSE;
5f4273c7 2361
dcbf9037 2362 p += 5;
5f4273c7 2363
dcbf9037 2364 if (*p == '\0')
c921be7d 2365 return FALSE;
5f4273c7 2366
dcbf9037
JB
2367 basereg = arm_reg_parse_multi (&p);
2368
2369 if (basereg && basereg->type != basetype)
2370 {
2371 as_bad (_("bad type for register"));
c921be7d 2372 return FALSE;
dcbf9037
JB
2373 }
2374
2375 if (basereg == NULL)
2376 {
2377 expressionS exp;
2378 /* Try parsing as an integer. */
2379 my_get_expression (&exp, &p, GE_NO_PREFIX);
2380 if (exp.X_op != O_constant)
477330fc
RM
2381 {
2382 as_bad (_("expression must be constant"));
2383 return FALSE;
2384 }
dcbf9037
JB
2385 basereg = &mybasereg;
2386 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2387 : exp.X_add_number;
dcbf9037
JB
2388 basereg->neon = 0;
2389 }
2390
2391 if (basereg->neon)
2392 typeinfo = *basereg->neon;
2393
2394 if (parse_neon_type (&ntype, &p) == SUCCESS)
2395 {
2396 /* We got a type. */
2397 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2398 {
2399 as_bad (_("can't redefine the type of a register alias"));
2400 return FALSE;
2401 }
5f4273c7 2402
dcbf9037
JB
2403 typeinfo.defined |= NTA_HASTYPE;
2404 if (ntype.elems != 1)
477330fc
RM
2405 {
2406 as_bad (_("you must specify a single type only"));
2407 return FALSE;
2408 }
dcbf9037
JB
2409 typeinfo.eltype = ntype.el[0];
2410 }
5f4273c7 2411
dcbf9037
JB
2412 if (skip_past_char (&p, '[') == SUCCESS)
2413 {
2414 expressionS exp;
2415 /* We got a scalar index. */
5f4273c7 2416
dcbf9037 2417 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2418 {
2419 as_bad (_("can't redefine the index of a scalar alias"));
2420 return FALSE;
2421 }
5f4273c7 2422
dcbf9037 2423 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2424
dcbf9037 2425 if (exp.X_op != O_constant)
477330fc
RM
2426 {
2427 as_bad (_("scalar index must be constant"));
2428 return FALSE;
2429 }
5f4273c7 2430
dcbf9037
JB
2431 typeinfo.defined |= NTA_HASINDEX;
2432 typeinfo.index = exp.X_add_number;
5f4273c7 2433
dcbf9037 2434 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2435 {
2436 as_bad (_("expecting ]"));
2437 return FALSE;
2438 }
dcbf9037
JB
2439 }
2440
15735687
NS
2441 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2442 the desired alias name, and p points to its end. If not, then
2443 the desired alias name is in the global original_case_string. */
2444#ifdef TC_CASE_SENSITIVE
dcbf9037 2445 namelen = nameend - newname;
15735687
NS
2446#else
2447 newname = original_case_string;
2448 namelen = strlen (newname);
2449#endif
2450
29a2809e 2451 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2452
dcbf9037 2453 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2454 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2455
dcbf9037
JB
2456 /* Insert name in all uppercase. */
2457 for (p = namebuf; *p; p++)
2458 *p = TOUPPER (*p);
5f4273c7 2459
dcbf9037
JB
2460 if (strncmp (namebuf, newname, namelen))
2461 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2462 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2463
dcbf9037
JB
2464 /* Insert name in all lowercase. */
2465 for (p = namebuf; *p; p++)
2466 *p = TOLOWER (*p);
5f4273c7 2467
dcbf9037
JB
2468 if (strncmp (namebuf, newname, namelen))
2469 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2470 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2471
e1fa0163 2472 free (namebuf);
c921be7d 2473 return TRUE;
dcbf9037
JB
2474}
2475
c19d1205
ZW
2476/* Should never be called, as .req goes between the alias and the
2477 register name, not at the beginning of the line. */
c921be7d 2478
b99bd4ef 2479static void
c19d1205 2480s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2481{
c19d1205
ZW
2482 as_bad (_("invalid syntax for .req directive"));
2483}
b99bd4ef 2484
dcbf9037
JB
2485static void
2486s_dn (int a ATTRIBUTE_UNUSED)
2487{
2488 as_bad (_("invalid syntax for .dn directive"));
2489}
2490
2491static void
2492s_qn (int a ATTRIBUTE_UNUSED)
2493{
2494 as_bad (_("invalid syntax for .qn directive"));
2495}
2496
c19d1205
ZW
2497/* The .unreq directive deletes an alias which was previously defined
2498 by .req. For example:
b99bd4ef 2499
c19d1205
ZW
2500 my_alias .req r11
2501 .unreq my_alias */
b99bd4ef
NC
2502
2503static void
c19d1205 2504s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2505{
c19d1205
ZW
2506 char * name;
2507 char saved_char;
b99bd4ef 2508
c19d1205
ZW
2509 name = input_line_pointer;
2510
2511 while (*input_line_pointer != 0
2512 && *input_line_pointer != ' '
2513 && *input_line_pointer != '\n')
2514 ++input_line_pointer;
2515
2516 saved_char = *input_line_pointer;
2517 *input_line_pointer = 0;
2518
2519 if (!*name)
2520 as_bad (_("invalid syntax for .unreq directive"));
2521 else
2522 {
21d799b5 2523 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2524 name);
c19d1205
ZW
2525
2526 if (!reg)
2527 as_bad (_("unknown register alias '%s'"), name);
2528 else if (reg->builtin)
a1727c1a 2529 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2530 name);
2531 else
2532 {
d929913e
NC
2533 char * p;
2534 char * nbuf;
2535
db0bc284 2536 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2537 free ((char *) reg->name);
477330fc
RM
2538 if (reg->neon)
2539 free (reg->neon);
c19d1205 2540 free (reg);
d929913e
NC
2541
2542 /* Also locate the all upper case and all lower case versions.
2543 Do not complain if we cannot find one or the other as it
2544 was probably deleted above. */
5f4273c7 2545
d929913e
NC
2546 nbuf = strdup (name);
2547 for (p = nbuf; *p; p++)
2548 *p = TOUPPER (*p);
21d799b5 2549 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2550 if (reg)
2551 {
db0bc284 2552 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2553 free ((char *) reg->name);
2554 if (reg->neon)
2555 free (reg->neon);
2556 free (reg);
2557 }
2558
2559 for (p = nbuf; *p; p++)
2560 *p = TOLOWER (*p);
21d799b5 2561 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2562 if (reg)
2563 {
db0bc284 2564 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2565 free ((char *) reg->name);
2566 if (reg->neon)
2567 free (reg->neon);
2568 free (reg);
2569 }
2570
2571 free (nbuf);
c19d1205
ZW
2572 }
2573 }
b99bd4ef 2574
c19d1205 2575 *input_line_pointer = saved_char;
b99bd4ef
NC
2576 demand_empty_rest_of_line ();
2577}
2578
c19d1205
ZW
2579/* Directives: Instruction set selection. */
2580
2581#ifdef OBJ_ELF
2582/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2583 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2584 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2585 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2586
cd000bff
DJ
2587/* Create a new mapping symbol for the transition to STATE. */
2588
2589static void
2590make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2591{
a737bd4d 2592 symbolS * symbolP;
c19d1205
ZW
2593 const char * symname;
2594 int type;
b99bd4ef 2595
c19d1205 2596 switch (state)
b99bd4ef 2597 {
c19d1205
ZW
2598 case MAP_DATA:
2599 symname = "$d";
2600 type = BSF_NO_FLAGS;
2601 break;
2602 case MAP_ARM:
2603 symname = "$a";
2604 type = BSF_NO_FLAGS;
2605 break;
2606 case MAP_THUMB:
2607 symname = "$t";
2608 type = BSF_NO_FLAGS;
2609 break;
c19d1205
ZW
2610 default:
2611 abort ();
2612 }
2613
cd000bff 2614 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2615 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2616
2617 switch (state)
2618 {
2619 case MAP_ARM:
2620 THUMB_SET_FUNC (symbolP, 0);
2621 ARM_SET_THUMB (symbolP, 0);
2622 ARM_SET_INTERWORK (symbolP, support_interwork);
2623 break;
2624
2625 case MAP_THUMB:
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628 ARM_SET_INTERWORK (symbolP, support_interwork);
2629 break;
2630
2631 case MAP_DATA:
2632 default:
cd000bff
DJ
2633 break;
2634 }
2635
2636 /* Save the mapping symbols for future reference. Also check that
2637 we do not place two mapping symbols at the same offset within a
2638 frag. We'll handle overlap between frags in
2de7820f
JZ
2639 check_mapping_symbols.
2640
2641 If .fill or other data filling directive generates zero sized data,
2642 the mapping symbol for the following code will have the same value
2643 as the one generated for the data filling directive. In this case,
2644 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2645 if (value == 0)
2646 {
2de7820f
JZ
2647 if (frag->tc_frag_data.first_map != NULL)
2648 {
2649 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2650 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2651 }
cd000bff
DJ
2652 frag->tc_frag_data.first_map = symbolP;
2653 }
2654 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2655 {
2656 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2657 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2658 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2659 }
cd000bff
DJ
2660 frag->tc_frag_data.last_map = symbolP;
2661}
2662
2663/* We must sometimes convert a region marked as code to data during
2664 code alignment, if an odd number of bytes have to be padded. The
2665 code mapping symbol is pushed to an aligned address. */
2666
2667static void
2668insert_data_mapping_symbol (enum mstate state,
2669 valueT value, fragS *frag, offsetT bytes)
2670{
2671 /* If there was already a mapping symbol, remove it. */
2672 if (frag->tc_frag_data.last_map != NULL
2673 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2674 {
2675 symbolS *symp = frag->tc_frag_data.last_map;
2676
2677 if (value == 0)
2678 {
2679 know (frag->tc_frag_data.first_map == symp);
2680 frag->tc_frag_data.first_map = NULL;
2681 }
2682 frag->tc_frag_data.last_map = NULL;
2683 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2684 }
cd000bff
DJ
2685
2686 make_mapping_symbol (MAP_DATA, value, frag);
2687 make_mapping_symbol (state, value + bytes, frag);
2688}
2689
2690static void mapping_state_2 (enum mstate state, int max_chars);
2691
2692/* Set the mapping state to STATE. Only call this when about to
2693 emit some STATE bytes to the file. */
2694
4e9aaefb 2695#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2696void
2697mapping_state (enum mstate state)
2698{
940b5ce0
DJ
2699 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2700
cd000bff
DJ
2701 if (mapstate == state)
2702 /* The mapping symbol has already been emitted.
2703 There is nothing else to do. */
2704 return;
49c62a33
NC
2705
2706 if (state == MAP_ARM || state == MAP_THUMB)
2707 /* PR gas/12931
2708 All ARM instructions require 4-byte alignment.
2709 (Almost) all Thumb instructions require 2-byte alignment.
2710
2711 When emitting instructions into any section, mark the section
2712 appropriately.
2713
2714 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2715 but themselves require 2-byte alignment; this applies to some
33eaf5de 2716 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2717 literal pool generation or an explicit .align >=2, both of
2718 which will cause the section to me marked with sufficient
2719 alignment. Thus, we don't handle those cases here. */
2720 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2721
2722 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2723 /* This case will be evaluated later. */
cd000bff 2724 return;
cd000bff
DJ
2725
2726 mapping_state_2 (state, 0);
cd000bff
DJ
2727}
2728
2729/* Same as mapping_state, but MAX_CHARS bytes have already been
2730 allocated. Put the mapping symbol that far back. */
2731
2732static void
2733mapping_state_2 (enum mstate state, int max_chars)
2734{
940b5ce0
DJ
2735 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2736
2737 if (!SEG_NORMAL (now_seg))
2738 return;
2739
cd000bff
DJ
2740 if (mapstate == state)
2741 /* The mapping symbol has already been emitted.
2742 There is nothing else to do. */
2743 return;
2744
4e9aaefb
SA
2745 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2746 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2747 {
2748 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2749 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2750
2751 if (add_symbol)
2752 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2753 }
2754
cd000bff
DJ
2755 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2756 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2757}
4e9aaefb 2758#undef TRANSITION
c19d1205 2759#else
d3106081
NS
2760#define mapping_state(x) ((void)0)
2761#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2762#endif
2763
2764/* Find the real, Thumb encoded start of a Thumb function. */
2765
4343666d 2766#ifdef OBJ_COFF
c19d1205
ZW
2767static symbolS *
2768find_real_start (symbolS * symbolP)
2769{
2770 char * real_start;
2771 const char * name = S_GET_NAME (symbolP);
2772 symbolS * new_target;
2773
2774 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2775#define STUB_NAME ".real_start_of"
2776
2777 if (name == NULL)
2778 abort ();
2779
37f6032b
ZW
2780 /* The compiler may generate BL instructions to local labels because
2781 it needs to perform a branch to a far away location. These labels
2782 do not have a corresponding ".real_start_of" label. We check
2783 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2784 the ".real_start_of" convention for nonlocal branches. */
2785 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2786 return symbolP;
2787
e1fa0163 2788 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2789 new_target = symbol_find (real_start);
e1fa0163 2790 free (real_start);
c19d1205
ZW
2791
2792 if (new_target == NULL)
2793 {
bd3ba5d1 2794 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2795 new_target = symbolP;
2796 }
2797
c19d1205
ZW
2798 return new_target;
2799}
4343666d 2800#endif
c19d1205
ZW
2801
2802static void
2803opcode_select (int width)
2804{
2805 switch (width)
2806 {
2807 case 16:
2808 if (! thumb_mode)
2809 {
e74cfd16 2810 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2811 as_bad (_("selected processor does not support THUMB opcodes"));
2812
2813 thumb_mode = 1;
2814 /* No need to force the alignment, since we will have been
2815 coming from ARM mode, which is word-aligned. */
2816 record_alignment (now_seg, 1);
2817 }
c19d1205
ZW
2818 break;
2819
2820 case 32:
2821 if (thumb_mode)
2822 {
e74cfd16 2823 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2824 as_bad (_("selected processor does not support ARM opcodes"));
2825
2826 thumb_mode = 0;
2827
2828 if (!need_pass_2)
2829 frag_align (2, 0, 0);
2830
2831 record_alignment (now_seg, 1);
2832 }
c19d1205
ZW
2833 break;
2834
2835 default:
2836 as_bad (_("invalid instruction size selected (%d)"), width);
2837 }
2838}
2839
2840static void
2841s_arm (int ignore ATTRIBUTE_UNUSED)
2842{
2843 opcode_select (32);
2844 demand_empty_rest_of_line ();
2845}
2846
2847static void
2848s_thumb (int ignore ATTRIBUTE_UNUSED)
2849{
2850 opcode_select (16);
2851 demand_empty_rest_of_line ();
2852}
2853
2854static void
2855s_code (int unused ATTRIBUTE_UNUSED)
2856{
2857 int temp;
2858
2859 temp = get_absolute_expression ();
2860 switch (temp)
2861 {
2862 case 16:
2863 case 32:
2864 opcode_select (temp);
2865 break;
2866
2867 default:
2868 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2869 }
2870}
2871
2872static void
2873s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2874{
2875 /* If we are not already in thumb mode go into it, EVEN if
2876 the target processor does not support thumb instructions.
2877 This is used by gcc/config/arm/lib1funcs.asm for example
2878 to compile interworking support functions even if the
2879 target processor should not support interworking. */
2880 if (! thumb_mode)
2881 {
2882 thumb_mode = 2;
2883 record_alignment (now_seg, 1);
2884 }
2885
2886 demand_empty_rest_of_line ();
2887}
2888
2889static void
2890s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2891{
2892 s_thumb (0);
2893
2894 /* The following label is the name/address of the start of a Thumb function.
2895 We need to know this for the interworking support. */
2896 label_is_thumb_function_name = TRUE;
2897}
2898
2899/* Perform a .set directive, but also mark the alias as
2900 being a thumb function. */
2901
2902static void
2903s_thumb_set (int equiv)
2904{
2905 /* XXX the following is a duplicate of the code for s_set() in read.c
2906 We cannot just call that code as we need to get at the symbol that
2907 is created. */
2908 char * name;
2909 char delim;
2910 char * end_name;
2911 symbolS * symbolP;
2912
2913 /* Especial apologies for the random logic:
2914 This just grew, and could be parsed much more simply!
2915 Dean - in haste. */
d02603dc 2916 delim = get_symbol_name (& name);
c19d1205 2917 end_name = input_line_pointer;
d02603dc 2918 (void) restore_line_pointer (delim);
c19d1205
ZW
2919
2920 if (*input_line_pointer != ',')
2921 {
2922 *end_name = 0;
2923 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2924 *end_name = delim;
2925 ignore_rest_of_line ();
2926 return;
2927 }
2928
2929 input_line_pointer++;
2930 *end_name = 0;
2931
2932 if (name[0] == '.' && name[1] == '\0')
2933 {
2934 /* XXX - this should not happen to .thumb_set. */
2935 abort ();
2936 }
2937
2938 if ((symbolP = symbol_find (name)) == NULL
2939 && (symbolP = md_undefined_symbol (name)) == NULL)
2940 {
2941#ifndef NO_LISTING
2942 /* When doing symbol listings, play games with dummy fragments living
2943 outside the normal fragment chain to record the file and line info
c19d1205 2944 for this symbol. */
b99bd4ef
NC
2945 if (listing & LISTING_SYMBOLS)
2946 {
2947 extern struct list_info_struct * listing_tail;
21d799b5 2948 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2949
2950 memset (dummy_frag, 0, sizeof (fragS));
2951 dummy_frag->fr_type = rs_fill;
2952 dummy_frag->line = listing_tail;
2953 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2954 dummy_frag->fr_symbol = symbolP;
2955 }
2956 else
2957#endif
2958 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2959
2960#ifdef OBJ_COFF
2961 /* "set" symbols are local unless otherwise specified. */
2962 SF_SET_LOCAL (symbolP);
2963#endif /* OBJ_COFF */
2964 } /* Make a new symbol. */
2965
2966 symbol_table_insert (symbolP);
2967
2968 * end_name = delim;
2969
2970 if (equiv
2971 && S_IS_DEFINED (symbolP)
2972 && S_GET_SEGMENT (symbolP) != reg_section)
2973 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2974
2975 pseudo_set (symbolP);
2976
2977 demand_empty_rest_of_line ();
2978
c19d1205 2979 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2980
2981 THUMB_SET_FUNC (symbolP, 1);
2982 ARM_SET_THUMB (symbolP, 1);
2983#if defined OBJ_ELF || defined OBJ_COFF
2984 ARM_SET_INTERWORK (symbolP, support_interwork);
2985#endif
2986}
2987
c19d1205 2988/* Directives: Mode selection. */
b99bd4ef 2989
c19d1205
ZW
2990/* .syntax [unified|divided] - choose the new unified syntax
2991 (same for Arm and Thumb encoding, modulo slight differences in what
2992 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2993static void
c19d1205 2994s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2995{
c19d1205
ZW
2996 char *name, delim;
2997
d02603dc 2998 delim = get_symbol_name (& name);
c19d1205
ZW
2999
3000 if (!strcasecmp (name, "unified"))
3001 unified_syntax = TRUE;
3002 else if (!strcasecmp (name, "divided"))
3003 unified_syntax = FALSE;
3004 else
3005 {
3006 as_bad (_("unrecognized syntax mode \"%s\""), name);
3007 return;
3008 }
d02603dc 3009 (void) restore_line_pointer (delim);
b99bd4ef
NC
3010 demand_empty_rest_of_line ();
3011}
3012
c19d1205
ZW
3013/* Directives: sectioning and alignment. */
3014
c19d1205
ZW
3015static void
3016s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3017{
c19d1205
ZW
3018 /* We don't support putting frags in the BSS segment, we fake it by
3019 marking in_bss, then looking at s_skip for clues. */
3020 subseg_set (bss_section, 0);
3021 demand_empty_rest_of_line ();
cd000bff
DJ
3022
3023#ifdef md_elf_section_change_hook
3024 md_elf_section_change_hook ();
3025#endif
c19d1205 3026}
b99bd4ef 3027
c19d1205
ZW
3028static void
3029s_even (int ignore ATTRIBUTE_UNUSED)
3030{
3031 /* Never make frag if expect extra pass. */
3032 if (!need_pass_2)
3033 frag_align (1, 0, 0);
b99bd4ef 3034
c19d1205 3035 record_alignment (now_seg, 1);
b99bd4ef 3036
c19d1205 3037 demand_empty_rest_of_line ();
b99bd4ef
NC
3038}
3039
2e6976a8
DG
3040/* Directives: CodeComposer Studio. */
3041
3042/* .ref (for CodeComposer Studio syntax only). */
3043static void
3044s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3045{
3046 if (codecomposer_syntax)
3047 ignore_rest_of_line ();
3048 else
3049 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3050}
3051
3052/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3053 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3054static void
3055asmfunc_debug (const char * name)
3056{
3057 static const char * last_name = NULL;
3058
3059 if (name != NULL)
3060 {
3061 gas_assert (last_name == NULL);
3062 last_name = name;
3063
3064 if (debug_type == DEBUG_STABS)
3065 stabs_generate_asm_func (name, name);
3066 }
3067 else
3068 {
3069 gas_assert (last_name != NULL);
3070
3071 if (debug_type == DEBUG_STABS)
3072 stabs_generate_asm_endfunc (last_name, last_name);
3073
3074 last_name = NULL;
3075 }
3076}
3077
3078static void
3079s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3080{
3081 if (codecomposer_syntax)
3082 {
3083 switch (asmfunc_state)
3084 {
3085 case OUTSIDE_ASMFUNC:
3086 asmfunc_state = WAITING_ASMFUNC_NAME;
3087 break;
3088
3089 case WAITING_ASMFUNC_NAME:
3090 as_bad (_(".asmfunc repeated."));
3091 break;
3092
3093 case WAITING_ENDASMFUNC:
3094 as_bad (_(".asmfunc without function."));
3095 break;
3096 }
3097 demand_empty_rest_of_line ();
3098 }
3099 else
3100 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3101}
3102
3103static void
3104s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3105{
3106 if (codecomposer_syntax)
3107 {
3108 switch (asmfunc_state)
3109 {
3110 case OUTSIDE_ASMFUNC:
3111 as_bad (_(".endasmfunc without a .asmfunc."));
3112 break;
3113
3114 case WAITING_ASMFUNC_NAME:
3115 as_bad (_(".endasmfunc without function."));
3116 break;
3117
3118 case WAITING_ENDASMFUNC:
3119 asmfunc_state = OUTSIDE_ASMFUNC;
3120 asmfunc_debug (NULL);
3121 break;
3122 }
3123 demand_empty_rest_of_line ();
3124 }
3125 else
3126 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3127}
3128
3129static void
3130s_ccs_def (int name)
3131{
3132 if (codecomposer_syntax)
3133 s_globl (name);
3134 else
3135 as_bad (_(".def pseudo-op only available with -mccs flag."));
3136}
3137
c19d1205 3138/* Directives: Literal pools. */
a737bd4d 3139
c19d1205
ZW
3140static literal_pool *
3141find_literal_pool (void)
a737bd4d 3142{
c19d1205 3143 literal_pool * pool;
a737bd4d 3144
c19d1205 3145 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3146 {
c19d1205
ZW
3147 if (pool->section == now_seg
3148 && pool->sub_section == now_subseg)
3149 break;
a737bd4d
NC
3150 }
3151
c19d1205 3152 return pool;
a737bd4d
NC
3153}
3154
c19d1205
ZW
3155static literal_pool *
3156find_or_make_literal_pool (void)
a737bd4d 3157{
c19d1205
ZW
3158 /* Next literal pool ID number. */
3159 static unsigned int latest_pool_num = 1;
3160 literal_pool * pool;
a737bd4d 3161
c19d1205 3162 pool = find_literal_pool ();
a737bd4d 3163
c19d1205 3164 if (pool == NULL)
a737bd4d 3165 {
c19d1205 3166 /* Create a new pool. */
325801bd 3167 pool = XNEW (literal_pool);
c19d1205
ZW
3168 if (! pool)
3169 return NULL;
a737bd4d 3170
c19d1205
ZW
3171 pool->next_free_entry = 0;
3172 pool->section = now_seg;
3173 pool->sub_section = now_subseg;
3174 pool->next = list_of_pools;
3175 pool->symbol = NULL;
8335d6aa 3176 pool->alignment = 2;
c19d1205
ZW
3177
3178 /* Add it to the list. */
3179 list_of_pools = pool;
a737bd4d 3180 }
a737bd4d 3181
c19d1205
ZW
3182 /* New pools, and emptied pools, will have a NULL symbol. */
3183 if (pool->symbol == NULL)
a737bd4d 3184 {
c19d1205
ZW
3185 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3186 (valueT) 0, &zero_address_frag);
3187 pool->id = latest_pool_num ++;
a737bd4d
NC
3188 }
3189
c19d1205
ZW
3190 /* Done. */
3191 return pool;
a737bd4d
NC
3192}
3193
c19d1205 3194/* Add the literal in the global 'inst'
5f4273c7 3195 structure to the relevant literal pool. */
b99bd4ef
NC
3196
3197static int
8335d6aa 3198add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3199{
8335d6aa
JW
3200#define PADDING_SLOT 0x1
3201#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3202 literal_pool * pool;
8335d6aa
JW
3203 unsigned int entry, pool_size = 0;
3204 bfd_boolean padding_slot_p = FALSE;
e56c722b 3205 unsigned imm1 = 0;
8335d6aa
JW
3206 unsigned imm2 = 0;
3207
3208 if (nbytes == 8)
3209 {
3210 imm1 = inst.operands[1].imm;
3211 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3212 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3213 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3214 if (target_big_endian)
3215 {
3216 imm1 = imm2;
3217 imm2 = inst.operands[1].imm;
3218 }
3219 }
b99bd4ef 3220
c19d1205
ZW
3221 pool = find_or_make_literal_pool ();
3222
3223 /* Check if this literal value is already in the pool. */
3224 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3225 {
8335d6aa
JW
3226 if (nbytes == 4)
3227 {
3228 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3229 && (inst.reloc.exp.X_op == O_constant)
3230 && (pool->literals[entry].X_add_number
3231 == inst.reloc.exp.X_add_number)
3232 && (pool->literals[entry].X_md == nbytes)
3233 && (pool->literals[entry].X_unsigned
3234 == inst.reloc.exp.X_unsigned))
3235 break;
3236
3237 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3238 && (inst.reloc.exp.X_op == O_symbol)
3239 && (pool->literals[entry].X_add_number
3240 == inst.reloc.exp.X_add_number)
3241 && (pool->literals[entry].X_add_symbol
3242 == inst.reloc.exp.X_add_symbol)
3243 && (pool->literals[entry].X_op_symbol
3244 == inst.reloc.exp.X_op_symbol)
3245 && (pool->literals[entry].X_md == nbytes))
3246 break;
3247 }
3248 else if ((nbytes == 8)
3249 && !(pool_size & 0x7)
3250 && ((entry + 1) != pool->next_free_entry)
3251 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3252 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3253 && (pool->literals[entry].X_unsigned
3254 == inst.reloc.exp.X_unsigned)
3255 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3256 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3257 && (pool->literals[entry + 1].X_unsigned
3258 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3259 break;
3260
8335d6aa
JW
3261 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3262 if (padding_slot_p && (nbytes == 4))
c19d1205 3263 break;
8335d6aa
JW
3264
3265 pool_size += 4;
b99bd4ef
NC
3266 }
3267
c19d1205
ZW
3268 /* Do we need to create a new entry? */
3269 if (entry == pool->next_free_entry)
3270 {
3271 if (entry >= MAX_LITERAL_POOL_SIZE)
3272 {
3273 inst.error = _("literal pool overflow");
3274 return FAIL;
3275 }
3276
8335d6aa
JW
3277 if (nbytes == 8)
3278 {
3279 /* For 8-byte entries, we align to an 8-byte boundary,
3280 and split it into two 4-byte entries, because on 32-bit
3281 host, 8-byte constants are treated as big num, thus
3282 saved in "generic_bignum" which will be overwritten
3283 by later assignments.
3284
3285 We also need to make sure there is enough space for
3286 the split.
3287
3288 We also check to make sure the literal operand is a
3289 constant number. */
19f2f6a9
JW
3290 if (!(inst.reloc.exp.X_op == O_constant
3291 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3292 {
3293 inst.error = _("invalid type for literal pool");
3294 return FAIL;
3295 }
3296 else if (pool_size & 0x7)
3297 {
3298 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3299 {
3300 inst.error = _("literal pool overflow");
3301 return FAIL;
3302 }
3303
3304 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3305 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3306 pool->literals[entry].X_add_number = 0;
3307 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3308 pool->next_free_entry += 1;
3309 pool_size += 4;
3310 }
3311 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3312 {
3313 inst.error = _("literal pool overflow");
3314 return FAIL;
3315 }
3316
3317 pool->literals[entry] = inst.reloc.exp;
3318 pool->literals[entry].X_op = O_constant;
3319 pool->literals[entry].X_add_number = imm1;
3320 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3321 pool->literals[entry++].X_md = 4;
3322 pool->literals[entry] = inst.reloc.exp;
3323 pool->literals[entry].X_op = O_constant;
3324 pool->literals[entry].X_add_number = imm2;
3325 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3326 pool->literals[entry].X_md = 4;
3327 pool->alignment = 3;
3328 pool->next_free_entry += 1;
3329 }
3330 else
3331 {
3332 pool->literals[entry] = inst.reloc.exp;
3333 pool->literals[entry].X_md = 4;
3334 }
3335
a8040cf2
NC
3336#ifdef OBJ_ELF
3337 /* PR ld/12974: Record the location of the first source line to reference
3338 this entry in the literal pool. If it turns out during linking that the
3339 symbol does not exist we will be able to give an accurate line number for
3340 the (first use of the) missing reference. */
3341 if (debug_type == DEBUG_DWARF2)
3342 dwarf2_where (pool->locs + entry);
3343#endif
c19d1205
ZW
3344 pool->next_free_entry += 1;
3345 }
8335d6aa
JW
3346 else if (padding_slot_p)
3347 {
3348 pool->literals[entry] = inst.reloc.exp;
3349 pool->literals[entry].X_md = nbytes;
3350 }
b99bd4ef 3351
c19d1205 3352 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3353 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3354 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3355
c19d1205 3356 return SUCCESS;
b99bd4ef
NC
3357}
3358
2e6976a8 3359bfd_boolean
2e57ce7b 3360tc_start_label_without_colon (void)
2e6976a8
DG
3361{
3362 bfd_boolean ret = TRUE;
3363
3364 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3365 {
2e57ce7b 3366 const char *label = input_line_pointer;
2e6976a8
DG
3367
3368 while (!is_end_of_line[(int) label[-1]])
3369 --label;
3370
3371 if (*label == '.')
3372 {
3373 as_bad (_("Invalid label '%s'"), label);
3374 ret = FALSE;
3375 }
3376
3377 asmfunc_debug (label);
3378
3379 asmfunc_state = WAITING_ENDASMFUNC;
3380 }
3381
3382 return ret;
3383}
3384
c19d1205 3385/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3386 a later date assign it a value. That's what these functions do. */
e16bb312 3387
c19d1205
ZW
3388static void
3389symbol_locate (symbolS * symbolP,
3390 const char * name, /* It is copied, the caller can modify. */
3391 segT segment, /* Segment identifier (SEG_<something>). */
3392 valueT valu, /* Symbol value. */
3393 fragS * frag) /* Associated fragment. */
3394{
e57e6ddc 3395 size_t name_length;
c19d1205 3396 char * preserved_copy_of_name;
e16bb312 3397
c19d1205
ZW
3398 name_length = strlen (name) + 1; /* +1 for \0. */
3399 obstack_grow (&notes, name, name_length);
21d799b5 3400 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3401
c19d1205
ZW
3402#ifdef tc_canonicalize_symbol_name
3403 preserved_copy_of_name =
3404 tc_canonicalize_symbol_name (preserved_copy_of_name);
3405#endif
b99bd4ef 3406
c19d1205 3407 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3408
c19d1205
ZW
3409 S_SET_SEGMENT (symbolP, segment);
3410 S_SET_VALUE (symbolP, valu);
3411 symbol_clear_list_pointers (symbolP);
b99bd4ef 3412
c19d1205 3413 symbol_set_frag (symbolP, frag);
b99bd4ef 3414
c19d1205
ZW
3415 /* Link to end of symbol chain. */
3416 {
3417 extern int symbol_table_frozen;
b99bd4ef 3418
c19d1205
ZW
3419 if (symbol_table_frozen)
3420 abort ();
3421 }
b99bd4ef 3422
c19d1205 3423 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3424
c19d1205 3425 obj_symbol_new_hook (symbolP);
b99bd4ef 3426
c19d1205
ZW
3427#ifdef tc_symbol_new_hook
3428 tc_symbol_new_hook (symbolP);
3429#endif
3430
3431#ifdef DEBUG_SYMS
3432 verify_symbol_chain (symbol_rootP, symbol_lastP);
3433#endif /* DEBUG_SYMS */
b99bd4ef
NC
3434}
3435
c19d1205
ZW
3436static void
3437s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3438{
c19d1205
ZW
3439 unsigned int entry;
3440 literal_pool * pool;
3441 char sym_name[20];
b99bd4ef 3442
c19d1205
ZW
3443 pool = find_literal_pool ();
3444 if (pool == NULL
3445 || pool->symbol == NULL
3446 || pool->next_free_entry == 0)
3447 return;
b99bd4ef 3448
c19d1205
ZW
3449 /* Align pool as you have word accesses.
3450 Only make a frag if we have to. */
3451 if (!need_pass_2)
8335d6aa 3452 frag_align (pool->alignment, 0, 0);
b99bd4ef 3453
c19d1205 3454 record_alignment (now_seg, 2);
b99bd4ef 3455
aaca88ef 3456#ifdef OBJ_ELF
47fc6e36
WN
3457 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3458 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3459#endif
c19d1205 3460 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3461
c19d1205
ZW
3462 symbol_locate (pool->symbol, sym_name, now_seg,
3463 (valueT) frag_now_fix (), frag_now);
3464 symbol_table_insert (pool->symbol);
b99bd4ef 3465
c19d1205 3466 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3467
c19d1205
ZW
3468#if defined OBJ_COFF || defined OBJ_ELF
3469 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3470#endif
6c43fab6 3471
c19d1205 3472 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3473 {
3474#ifdef OBJ_ELF
3475 if (debug_type == DEBUG_DWARF2)
3476 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3477#endif
3478 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3479 emit_expr (&(pool->literals[entry]),
3480 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3481 }
b99bd4ef 3482
c19d1205
ZW
3483 /* Mark the pool as empty. */
3484 pool->next_free_entry = 0;
3485 pool->symbol = NULL;
b99bd4ef
NC
3486}
3487
c19d1205
ZW
3488#ifdef OBJ_ELF
3489/* Forward declarations for functions below, in the MD interface
3490 section. */
3491static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3492static valueT create_unwind_entry (int);
3493static void start_unwind_section (const segT, int);
3494static void add_unwind_opcode (valueT, int);
3495static void flush_pending_unwind (void);
b99bd4ef 3496
c19d1205 3497/* Directives: Data. */
b99bd4ef 3498
c19d1205
ZW
3499static void
3500s_arm_elf_cons (int nbytes)
3501{
3502 expressionS exp;
b99bd4ef 3503
c19d1205
ZW
3504#ifdef md_flush_pending_output
3505 md_flush_pending_output ();
3506#endif
b99bd4ef 3507
c19d1205 3508 if (is_it_end_of_statement ())
b99bd4ef 3509 {
c19d1205
ZW
3510 demand_empty_rest_of_line ();
3511 return;
b99bd4ef
NC
3512 }
3513
c19d1205
ZW
3514#ifdef md_cons_align
3515 md_cons_align (nbytes);
3516#endif
b99bd4ef 3517
c19d1205
ZW
3518 mapping_state (MAP_DATA);
3519 do
b99bd4ef 3520 {
c19d1205
ZW
3521 int reloc;
3522 char *base = input_line_pointer;
b99bd4ef 3523
c19d1205 3524 expression (& exp);
b99bd4ef 3525
c19d1205
ZW
3526 if (exp.X_op != O_symbol)
3527 emit_expr (&exp, (unsigned int) nbytes);
3528 else
3529 {
3530 char *before_reloc = input_line_pointer;
3531 reloc = parse_reloc (&input_line_pointer);
3532 if (reloc == -1)
3533 {
3534 as_bad (_("unrecognized relocation suffix"));
3535 ignore_rest_of_line ();
3536 return;
3537 }
3538 else if (reloc == BFD_RELOC_UNUSED)
3539 emit_expr (&exp, (unsigned int) nbytes);
3540 else
3541 {
21d799b5 3542 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3543 bfd_reloc_type_lookup (stdoutput,
3544 (bfd_reloc_code_real_type) reloc);
c19d1205 3545 int size = bfd_get_reloc_size (howto);
b99bd4ef 3546
2fc8bdac
ZW
3547 if (reloc == BFD_RELOC_ARM_PLT32)
3548 {
3549 as_bad (_("(plt) is only valid on branch targets"));
3550 reloc = BFD_RELOC_UNUSED;
3551 size = 0;
3552 }
3553
c19d1205 3554 if (size > nbytes)
2fc8bdac 3555 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3556 howto->name, nbytes);
3557 else
3558 {
3559 /* We've parsed an expression stopping at O_symbol.
3560 But there may be more expression left now that we
3561 have parsed the relocation marker. Parse it again.
3562 XXX Surely there is a cleaner way to do this. */
3563 char *p = input_line_pointer;
3564 int offset;
325801bd 3565 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3566
c19d1205
ZW
3567 memcpy (save_buf, base, input_line_pointer - base);
3568 memmove (base + (input_line_pointer - before_reloc),
3569 base, before_reloc - base);
3570
3571 input_line_pointer = base + (input_line_pointer-before_reloc);
3572 expression (&exp);
3573 memcpy (base, save_buf, p - base);
3574
3575 offset = nbytes - size;
4b1a927e
AM
3576 p = frag_more (nbytes);
3577 memset (p, 0, nbytes);
c19d1205 3578 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3579 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3580 free (save_buf);
c19d1205
ZW
3581 }
3582 }
3583 }
b99bd4ef 3584 }
c19d1205 3585 while (*input_line_pointer++ == ',');
b99bd4ef 3586
c19d1205
ZW
3587 /* Put terminator back into stream. */
3588 input_line_pointer --;
3589 demand_empty_rest_of_line ();
b99bd4ef
NC
3590}
3591
c921be7d
NC
3592/* Emit an expression containing a 32-bit thumb instruction.
3593 Implementation based on put_thumb32_insn. */
3594
3595static void
3596emit_thumb32_expr (expressionS * exp)
3597{
3598 expressionS exp_high = *exp;
3599
3600 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3601 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3602 exp->X_add_number &= 0xffff;
3603 emit_expr (exp, (unsigned int) THUMB_SIZE);
3604}
3605
3606/* Guess the instruction size based on the opcode. */
3607
3608static int
3609thumb_insn_size (int opcode)
3610{
3611 if ((unsigned int) opcode < 0xe800u)
3612 return 2;
3613 else if ((unsigned int) opcode >= 0xe8000000u)
3614 return 4;
3615 else
3616 return 0;
3617}
3618
3619static bfd_boolean
3620emit_insn (expressionS *exp, int nbytes)
3621{
3622 int size = 0;
3623
3624 if (exp->X_op == O_constant)
3625 {
3626 size = nbytes;
3627
3628 if (size == 0)
3629 size = thumb_insn_size (exp->X_add_number);
3630
3631 if (size != 0)
3632 {
3633 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3634 {
3635 as_bad (_(".inst.n operand too big. "\
3636 "Use .inst.w instead"));
3637 size = 0;
3638 }
3639 else
3640 {
3641 if (now_it.state == AUTOMATIC_IT_BLOCK)
3642 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3643 else
3644 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3645
3646 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3647 emit_thumb32_expr (exp);
3648 else
3649 emit_expr (exp, (unsigned int) size);
3650
3651 it_fsm_post_encode ();
3652 }
3653 }
3654 else
3655 as_bad (_("cannot determine Thumb instruction size. " \
3656 "Use .inst.n/.inst.w instead"));
3657 }
3658 else
3659 as_bad (_("constant expression required"));
3660
3661 return (size != 0);
3662}
3663
3664/* Like s_arm_elf_cons but do not use md_cons_align and
3665 set the mapping state to MAP_ARM/MAP_THUMB. */
3666
3667static void
3668s_arm_elf_inst (int nbytes)
3669{
3670 if (is_it_end_of_statement ())
3671 {
3672 demand_empty_rest_of_line ();
3673 return;
3674 }
3675
3676 /* Calling mapping_state () here will not change ARM/THUMB,
3677 but will ensure not to be in DATA state. */
3678
3679 if (thumb_mode)
3680 mapping_state (MAP_THUMB);
3681 else
3682 {
3683 if (nbytes != 0)
3684 {
3685 as_bad (_("width suffixes are invalid in ARM mode"));
3686 ignore_rest_of_line ();
3687 return;
3688 }
3689
3690 nbytes = 4;
3691
3692 mapping_state (MAP_ARM);
3693 }
3694
3695 do
3696 {
3697 expressionS exp;
3698
3699 expression (& exp);
3700
3701 if (! emit_insn (& exp, nbytes))
3702 {
3703 ignore_rest_of_line ();
3704 return;
3705 }
3706 }
3707 while (*input_line_pointer++ == ',');
3708
3709 /* Put terminator back into stream. */
3710 input_line_pointer --;
3711 demand_empty_rest_of_line ();
3712}
b99bd4ef 3713
c19d1205 3714/* Parse a .rel31 directive. */
b99bd4ef 3715
c19d1205
ZW
3716static void
3717s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3718{
3719 expressionS exp;
3720 char *p;
3721 valueT highbit;
b99bd4ef 3722
c19d1205
ZW
3723 highbit = 0;
3724 if (*input_line_pointer == '1')
3725 highbit = 0x80000000;
3726 else if (*input_line_pointer != '0')
3727 as_bad (_("expected 0 or 1"));
b99bd4ef 3728
c19d1205
ZW
3729 input_line_pointer++;
3730 if (*input_line_pointer != ',')
3731 as_bad (_("missing comma"));
3732 input_line_pointer++;
b99bd4ef 3733
c19d1205
ZW
3734#ifdef md_flush_pending_output
3735 md_flush_pending_output ();
3736#endif
b99bd4ef 3737
c19d1205
ZW
3738#ifdef md_cons_align
3739 md_cons_align (4);
3740#endif
b99bd4ef 3741
c19d1205 3742 mapping_state (MAP_DATA);
b99bd4ef 3743
c19d1205 3744 expression (&exp);
b99bd4ef 3745
c19d1205
ZW
3746 p = frag_more (4);
3747 md_number_to_chars (p, highbit, 4);
3748 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3749 BFD_RELOC_ARM_PREL31);
b99bd4ef 3750
c19d1205 3751 demand_empty_rest_of_line ();
b99bd4ef
NC
3752}
3753
c19d1205 3754/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3755
c19d1205 3756/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3757
c19d1205
ZW
3758static void
3759s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3760{
3761 demand_empty_rest_of_line ();
921e5f0a
PB
3762 if (unwind.proc_start)
3763 {
c921be7d 3764 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3765 return;
3766 }
3767
c19d1205
ZW
3768 /* Mark the start of the function. */
3769 unwind.proc_start = expr_build_dot ();
b99bd4ef 3770
c19d1205
ZW
3771 /* Reset the rest of the unwind info. */
3772 unwind.opcode_count = 0;
3773 unwind.table_entry = NULL;
3774 unwind.personality_routine = NULL;
3775 unwind.personality_index = -1;
3776 unwind.frame_size = 0;
3777 unwind.fp_offset = 0;
fdfde340 3778 unwind.fp_reg = REG_SP;
c19d1205
ZW
3779 unwind.fp_used = 0;
3780 unwind.sp_restored = 0;
3781}
b99bd4ef 3782
b99bd4ef 3783
c19d1205
ZW
3784/* Parse a handlerdata directive. Creates the exception handling table entry
3785 for the function. */
b99bd4ef 3786
c19d1205
ZW
3787static void
3788s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3789{
3790 demand_empty_rest_of_line ();
921e5f0a 3791 if (!unwind.proc_start)
c921be7d 3792 as_bad (MISSING_FNSTART);
921e5f0a 3793
c19d1205 3794 if (unwind.table_entry)
6decc662 3795 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3796
c19d1205
ZW
3797 create_unwind_entry (1);
3798}
a737bd4d 3799
c19d1205 3800/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3801
c19d1205
ZW
3802static void
3803s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3804{
3805 long where;
3806 char *ptr;
3807 valueT val;
940b5ce0 3808 unsigned int marked_pr_dependency;
f02232aa 3809
c19d1205 3810 demand_empty_rest_of_line ();
f02232aa 3811
921e5f0a
PB
3812 if (!unwind.proc_start)
3813 {
c921be7d 3814 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3815 return;
3816 }
3817
c19d1205
ZW
3818 /* Add eh table entry. */
3819 if (unwind.table_entry == NULL)
3820 val = create_unwind_entry (0);
3821 else
3822 val = 0;
f02232aa 3823
c19d1205
ZW
3824 /* Add index table entry. This is two words. */
3825 start_unwind_section (unwind.saved_seg, 1);
3826 frag_align (2, 0, 0);
3827 record_alignment (now_seg, 2);
b99bd4ef 3828
c19d1205 3829 ptr = frag_more (8);
5011093d 3830 memset (ptr, 0, 8);
c19d1205 3831 where = frag_now_fix () - 8;
f02232aa 3832
c19d1205
ZW
3833 /* Self relative offset of the function start. */
3834 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3835 BFD_RELOC_ARM_PREL31);
f02232aa 3836
c19d1205
ZW
3837 /* Indicate dependency on EHABI-defined personality routines to the
3838 linker, if it hasn't been done already. */
940b5ce0
DJ
3839 marked_pr_dependency
3840 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3841 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3842 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3843 {
5f4273c7
NC
3844 static const char *const name[] =
3845 {
3846 "__aeabi_unwind_cpp_pr0",
3847 "__aeabi_unwind_cpp_pr1",
3848 "__aeabi_unwind_cpp_pr2"
3849 };
c19d1205
ZW
3850 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3851 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3852 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3853 |= 1 << unwind.personality_index;
c19d1205 3854 }
f02232aa 3855
c19d1205
ZW
3856 if (val)
3857 /* Inline exception table entry. */
3858 md_number_to_chars (ptr + 4, val, 4);
3859 else
3860 /* Self relative offset of the table entry. */
3861 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3862 BFD_RELOC_ARM_PREL31);
f02232aa 3863
c19d1205
ZW
3864 /* Restore the original section. */
3865 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3866
3867 unwind.proc_start = NULL;
c19d1205 3868}
f02232aa 3869
f02232aa 3870
c19d1205 3871/* Parse an unwind_cantunwind directive. */
b99bd4ef 3872
c19d1205
ZW
3873static void
3874s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3875{
3876 demand_empty_rest_of_line ();
921e5f0a 3877 if (!unwind.proc_start)
c921be7d 3878 as_bad (MISSING_FNSTART);
921e5f0a 3879
c19d1205
ZW
3880 if (unwind.personality_routine || unwind.personality_index != -1)
3881 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3882
c19d1205
ZW
3883 unwind.personality_index = -2;
3884}
b99bd4ef 3885
b99bd4ef 3886
c19d1205 3887/* Parse a personalityindex directive. */
b99bd4ef 3888
c19d1205
ZW
3889static void
3890s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3891{
3892 expressionS exp;
b99bd4ef 3893
921e5f0a 3894 if (!unwind.proc_start)
c921be7d 3895 as_bad (MISSING_FNSTART);
921e5f0a 3896
c19d1205
ZW
3897 if (unwind.personality_routine || unwind.personality_index != -1)
3898 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3899
c19d1205 3900 expression (&exp);
b99bd4ef 3901
c19d1205
ZW
3902 if (exp.X_op != O_constant
3903 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3904 {
c19d1205
ZW
3905 as_bad (_("bad personality routine number"));
3906 ignore_rest_of_line ();
3907 return;
b99bd4ef
NC
3908 }
3909
c19d1205 3910 unwind.personality_index = exp.X_add_number;
b99bd4ef 3911
c19d1205
ZW
3912 demand_empty_rest_of_line ();
3913}
e16bb312 3914
e16bb312 3915
c19d1205 3916/* Parse a personality directive. */
e16bb312 3917
c19d1205
ZW
3918static void
3919s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3920{
3921 char *name, *p, c;
a737bd4d 3922
921e5f0a 3923 if (!unwind.proc_start)
c921be7d 3924 as_bad (MISSING_FNSTART);
921e5f0a 3925
c19d1205
ZW
3926 if (unwind.personality_routine || unwind.personality_index != -1)
3927 as_bad (_("duplicate .personality directive"));
a737bd4d 3928
d02603dc 3929 c = get_symbol_name (& name);
c19d1205 3930 p = input_line_pointer;
d02603dc
NC
3931 if (c == '"')
3932 ++ input_line_pointer;
c19d1205
ZW
3933 unwind.personality_routine = symbol_find_or_make (name);
3934 *p = c;
3935 demand_empty_rest_of_line ();
3936}
e16bb312 3937
e16bb312 3938
c19d1205 3939/* Parse a directive saving core registers. */
e16bb312 3940
c19d1205
ZW
3941static void
3942s_arm_unwind_save_core (void)
e16bb312 3943{
c19d1205
ZW
3944 valueT op;
3945 long range;
3946 int n;
e16bb312 3947
c19d1205
ZW
3948 range = parse_reg_list (&input_line_pointer);
3949 if (range == FAIL)
e16bb312 3950 {
c19d1205
ZW
3951 as_bad (_("expected register list"));
3952 ignore_rest_of_line ();
3953 return;
3954 }
e16bb312 3955
c19d1205 3956 demand_empty_rest_of_line ();
e16bb312 3957
c19d1205
ZW
3958 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3959 into .unwind_save {..., sp...}. We aren't bothered about the value of
3960 ip because it is clobbered by calls. */
3961 if (unwind.sp_restored && unwind.fp_reg == 12
3962 && (range & 0x3000) == 0x1000)
3963 {
3964 unwind.opcode_count--;
3965 unwind.sp_restored = 0;
3966 range = (range | 0x2000) & ~0x1000;
3967 unwind.pending_offset = 0;
3968 }
e16bb312 3969
01ae4198
DJ
3970 /* Pop r4-r15. */
3971 if (range & 0xfff0)
c19d1205 3972 {
01ae4198
DJ
3973 /* See if we can use the short opcodes. These pop a block of up to 8
3974 registers starting with r4, plus maybe r14. */
3975 for (n = 0; n < 8; n++)
3976 {
3977 /* Break at the first non-saved register. */
3978 if ((range & (1 << (n + 4))) == 0)
3979 break;
3980 }
3981 /* See if there are any other bits set. */
3982 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3983 {
3984 /* Use the long form. */
3985 op = 0x8000 | ((range >> 4) & 0xfff);
3986 add_unwind_opcode (op, 2);
3987 }
0dd132b6 3988 else
01ae4198
DJ
3989 {
3990 /* Use the short form. */
3991 if (range & 0x4000)
3992 op = 0xa8; /* Pop r14. */
3993 else
3994 op = 0xa0; /* Do not pop r14. */
3995 op |= (n - 1);
3996 add_unwind_opcode (op, 1);
3997 }
c19d1205 3998 }
0dd132b6 3999
c19d1205
ZW
4000 /* Pop r0-r3. */
4001 if (range & 0xf)
4002 {
4003 op = 0xb100 | (range & 0xf);
4004 add_unwind_opcode (op, 2);
0dd132b6
NC
4005 }
4006
c19d1205
ZW
4007 /* Record the number of bytes pushed. */
4008 for (n = 0; n < 16; n++)
4009 {
4010 if (range & (1 << n))
4011 unwind.frame_size += 4;
4012 }
0dd132b6
NC
4013}
4014
c19d1205
ZW
4015
4016/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4017
4018static void
c19d1205 4019s_arm_unwind_save_fpa (int reg)
b99bd4ef 4020{
c19d1205
ZW
4021 expressionS exp;
4022 int num_regs;
4023 valueT op;
b99bd4ef 4024
c19d1205
ZW
4025 /* Get Number of registers to transfer. */
4026 if (skip_past_comma (&input_line_pointer) != FAIL)
4027 expression (&exp);
4028 else
4029 exp.X_op = O_illegal;
b99bd4ef 4030
c19d1205 4031 if (exp.X_op != O_constant)
b99bd4ef 4032 {
c19d1205
ZW
4033 as_bad (_("expected , <constant>"));
4034 ignore_rest_of_line ();
b99bd4ef
NC
4035 return;
4036 }
4037
c19d1205
ZW
4038 num_regs = exp.X_add_number;
4039
4040 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4041 {
c19d1205
ZW
4042 as_bad (_("number of registers must be in the range [1:4]"));
4043 ignore_rest_of_line ();
b99bd4ef
NC
4044 return;
4045 }
4046
c19d1205 4047 demand_empty_rest_of_line ();
b99bd4ef 4048
c19d1205
ZW
4049 if (reg == 4)
4050 {
4051 /* Short form. */
4052 op = 0xb4 | (num_regs - 1);
4053 add_unwind_opcode (op, 1);
4054 }
b99bd4ef
NC
4055 else
4056 {
c19d1205
ZW
4057 /* Long form. */
4058 op = 0xc800 | (reg << 4) | (num_regs - 1);
4059 add_unwind_opcode (op, 2);
b99bd4ef 4060 }
c19d1205 4061 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4062}
4063
c19d1205 4064
fa073d69
MS
4065/* Parse a directive saving VFP registers for ARMv6 and above. */
4066
4067static void
4068s_arm_unwind_save_vfp_armv6 (void)
4069{
4070 int count;
4071 unsigned int start;
4072 valueT op;
4073 int num_vfpv3_regs = 0;
4074 int num_regs_below_16;
4075
4076 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4077 if (count == FAIL)
4078 {
4079 as_bad (_("expected register list"));
4080 ignore_rest_of_line ();
4081 return;
4082 }
4083
4084 demand_empty_rest_of_line ();
4085
4086 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4087 than FSTMX/FLDMX-style ones). */
4088
4089 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4090 if (start >= 16)
4091 num_vfpv3_regs = count;
4092 else if (start + count > 16)
4093 num_vfpv3_regs = start + count - 16;
4094
4095 if (num_vfpv3_regs > 0)
4096 {
4097 int start_offset = start > 16 ? start - 16 : 0;
4098 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4099 add_unwind_opcode (op, 2);
4100 }
4101
4102 /* Generate opcode for registers numbered in the range 0 .. 15. */
4103 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4104 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4105 if (num_regs_below_16 > 0)
4106 {
4107 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4108 add_unwind_opcode (op, 2);
4109 }
4110
4111 unwind.frame_size += count * 8;
4112}
4113
4114
4115/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4116
4117static void
c19d1205 4118s_arm_unwind_save_vfp (void)
b99bd4ef 4119{
c19d1205 4120 int count;
ca3f61f7 4121 unsigned int reg;
c19d1205 4122 valueT op;
b99bd4ef 4123
5287ad62 4124 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4125 if (count == FAIL)
b99bd4ef 4126 {
c19d1205
ZW
4127 as_bad (_("expected register list"));
4128 ignore_rest_of_line ();
b99bd4ef
NC
4129 return;
4130 }
4131
c19d1205 4132 demand_empty_rest_of_line ();
b99bd4ef 4133
c19d1205 4134 if (reg == 8)
b99bd4ef 4135 {
c19d1205
ZW
4136 /* Short form. */
4137 op = 0xb8 | (count - 1);
4138 add_unwind_opcode (op, 1);
b99bd4ef 4139 }
c19d1205 4140 else
b99bd4ef 4141 {
c19d1205
ZW
4142 /* Long form. */
4143 op = 0xb300 | (reg << 4) | (count - 1);
4144 add_unwind_opcode (op, 2);
b99bd4ef 4145 }
c19d1205
ZW
4146 unwind.frame_size += count * 8 + 4;
4147}
b99bd4ef 4148
b99bd4ef 4149
c19d1205
ZW
4150/* Parse a directive saving iWMMXt data registers. */
4151
4152static void
4153s_arm_unwind_save_mmxwr (void)
4154{
4155 int reg;
4156 int hi_reg;
4157 int i;
4158 unsigned mask = 0;
4159 valueT op;
b99bd4ef 4160
c19d1205
ZW
4161 if (*input_line_pointer == '{')
4162 input_line_pointer++;
b99bd4ef 4163
c19d1205 4164 do
b99bd4ef 4165 {
dcbf9037 4166 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4167
c19d1205 4168 if (reg == FAIL)
b99bd4ef 4169 {
9b7132d3 4170 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4171 goto error;
b99bd4ef
NC
4172 }
4173
c19d1205
ZW
4174 if (mask >> reg)
4175 as_tsktsk (_("register list not in ascending order"));
4176 mask |= 1 << reg;
b99bd4ef 4177
c19d1205
ZW
4178 if (*input_line_pointer == '-')
4179 {
4180 input_line_pointer++;
dcbf9037 4181 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4182 if (hi_reg == FAIL)
4183 {
9b7132d3 4184 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4185 goto error;
4186 }
4187 else if (reg >= hi_reg)
4188 {
4189 as_bad (_("bad register range"));
4190 goto error;
4191 }
4192 for (; reg < hi_reg; reg++)
4193 mask |= 1 << reg;
4194 }
4195 }
4196 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4197
d996d970 4198 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4199
c19d1205 4200 demand_empty_rest_of_line ();
b99bd4ef 4201
708587a4 4202 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4203 the list. */
4204 flush_pending_unwind ();
b99bd4ef 4205
c19d1205 4206 for (i = 0; i < 16; i++)
b99bd4ef 4207 {
c19d1205
ZW
4208 if (mask & (1 << i))
4209 unwind.frame_size += 8;
b99bd4ef
NC
4210 }
4211
c19d1205
ZW
4212 /* Attempt to combine with a previous opcode. We do this because gcc
4213 likes to output separate unwind directives for a single block of
4214 registers. */
4215 if (unwind.opcode_count > 0)
b99bd4ef 4216 {
c19d1205
ZW
4217 i = unwind.opcodes[unwind.opcode_count - 1];
4218 if ((i & 0xf8) == 0xc0)
4219 {
4220 i &= 7;
4221 /* Only merge if the blocks are contiguous. */
4222 if (i < 6)
4223 {
4224 if ((mask & 0xfe00) == (1 << 9))
4225 {
4226 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4227 unwind.opcode_count--;
4228 }
4229 }
4230 else if (i == 6 && unwind.opcode_count >= 2)
4231 {
4232 i = unwind.opcodes[unwind.opcode_count - 2];
4233 reg = i >> 4;
4234 i &= 0xf;
b99bd4ef 4235
c19d1205
ZW
4236 op = 0xffff << (reg - 1);
4237 if (reg > 0
87a1fd79 4238 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4239 {
4240 op = (1 << (reg + i + 1)) - 1;
4241 op &= ~((1 << reg) - 1);
4242 mask |= op;
4243 unwind.opcode_count -= 2;
4244 }
4245 }
4246 }
b99bd4ef
NC
4247 }
4248
c19d1205
ZW
4249 hi_reg = 15;
4250 /* We want to generate opcodes in the order the registers have been
4251 saved, ie. descending order. */
4252 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4253 {
c19d1205
ZW
4254 /* Save registers in blocks. */
4255 if (reg < 0
4256 || !(mask & (1 << reg)))
4257 {
4258 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4259 preceding block. */
c19d1205
ZW
4260 if (reg != hi_reg)
4261 {
4262 if (reg == 9)
4263 {
4264 /* Short form. */
4265 op = 0xc0 | (hi_reg - 10);
4266 add_unwind_opcode (op, 1);
4267 }
4268 else
4269 {
4270 /* Long form. */
4271 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4272 add_unwind_opcode (op, 2);
4273 }
4274 }
4275 hi_reg = reg - 1;
4276 }
b99bd4ef
NC
4277 }
4278
c19d1205
ZW
4279 return;
4280error:
4281 ignore_rest_of_line ();
b99bd4ef
NC
4282}
4283
4284static void
c19d1205 4285s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4286{
c19d1205
ZW
4287 int reg;
4288 int hi_reg;
4289 unsigned mask = 0;
4290 valueT op;
b99bd4ef 4291
c19d1205
ZW
4292 if (*input_line_pointer == '{')
4293 input_line_pointer++;
b99bd4ef 4294
477330fc
RM
4295 skip_whitespace (input_line_pointer);
4296
c19d1205 4297 do
b99bd4ef 4298 {
dcbf9037 4299 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4300
c19d1205
ZW
4301 if (reg == FAIL)
4302 {
9b7132d3 4303 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4304 goto error;
4305 }
b99bd4ef 4306
c19d1205
ZW
4307 reg -= 8;
4308 if (mask >> reg)
4309 as_tsktsk (_("register list not in ascending order"));
4310 mask |= 1 << reg;
b99bd4ef 4311
c19d1205
ZW
4312 if (*input_line_pointer == '-')
4313 {
4314 input_line_pointer++;
dcbf9037 4315 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4316 if (hi_reg == FAIL)
4317 {
9b7132d3 4318 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4319 goto error;
4320 }
4321 else if (reg >= hi_reg)
4322 {
4323 as_bad (_("bad register range"));
4324 goto error;
4325 }
4326 for (; reg < hi_reg; reg++)
4327 mask |= 1 << reg;
4328 }
b99bd4ef 4329 }
c19d1205 4330 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4331
d996d970 4332 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4333
c19d1205
ZW
4334 demand_empty_rest_of_line ();
4335
708587a4 4336 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4337 the list. */
4338 flush_pending_unwind ();
b99bd4ef 4339
c19d1205 4340 for (reg = 0; reg < 16; reg++)
b99bd4ef 4341 {
c19d1205
ZW
4342 if (mask & (1 << reg))
4343 unwind.frame_size += 4;
b99bd4ef 4344 }
c19d1205
ZW
4345 op = 0xc700 | mask;
4346 add_unwind_opcode (op, 2);
4347 return;
4348error:
4349 ignore_rest_of_line ();
b99bd4ef
NC
4350}
4351
c19d1205 4352
fa073d69
MS
4353/* Parse an unwind_save directive.
4354 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4355
b99bd4ef 4356static void
fa073d69 4357s_arm_unwind_save (int arch_v6)
b99bd4ef 4358{
c19d1205
ZW
4359 char *peek;
4360 struct reg_entry *reg;
4361 bfd_boolean had_brace = FALSE;
b99bd4ef 4362
921e5f0a 4363 if (!unwind.proc_start)
c921be7d 4364 as_bad (MISSING_FNSTART);
921e5f0a 4365
c19d1205
ZW
4366 /* Figure out what sort of save we have. */
4367 peek = input_line_pointer;
b99bd4ef 4368
c19d1205 4369 if (*peek == '{')
b99bd4ef 4370 {
c19d1205
ZW
4371 had_brace = TRUE;
4372 peek++;
b99bd4ef
NC
4373 }
4374
c19d1205 4375 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4376
c19d1205 4377 if (!reg)
b99bd4ef 4378 {
c19d1205
ZW
4379 as_bad (_("register expected"));
4380 ignore_rest_of_line ();
b99bd4ef
NC
4381 return;
4382 }
4383
c19d1205 4384 switch (reg->type)
b99bd4ef 4385 {
c19d1205
ZW
4386 case REG_TYPE_FN:
4387 if (had_brace)
4388 {
4389 as_bad (_("FPA .unwind_save does not take a register list"));
4390 ignore_rest_of_line ();
4391 return;
4392 }
93ac2687 4393 input_line_pointer = peek;
c19d1205 4394 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4395 return;
c19d1205 4396
1f5afe1c
NC
4397 case REG_TYPE_RN:
4398 s_arm_unwind_save_core ();
4399 return;
4400
fa073d69
MS
4401 case REG_TYPE_VFD:
4402 if (arch_v6)
477330fc 4403 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4404 else
477330fc 4405 s_arm_unwind_save_vfp ();
fa073d69 4406 return;
1f5afe1c
NC
4407
4408 case REG_TYPE_MMXWR:
4409 s_arm_unwind_save_mmxwr ();
4410 return;
4411
4412 case REG_TYPE_MMXWCG:
4413 s_arm_unwind_save_mmxwcg ();
4414 return;
c19d1205
ZW
4415
4416 default:
4417 as_bad (_(".unwind_save does not support this kind of register"));
4418 ignore_rest_of_line ();
b99bd4ef 4419 }
c19d1205 4420}
b99bd4ef 4421
b99bd4ef 4422
c19d1205
ZW
4423/* Parse an unwind_movsp directive. */
4424
4425static void
4426s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4427{
4428 int reg;
4429 valueT op;
4fa3602b 4430 int offset;
c19d1205 4431
921e5f0a 4432 if (!unwind.proc_start)
c921be7d 4433 as_bad (MISSING_FNSTART);
921e5f0a 4434
dcbf9037 4435 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4436 if (reg == FAIL)
b99bd4ef 4437 {
9b7132d3 4438 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4439 ignore_rest_of_line ();
b99bd4ef
NC
4440 return;
4441 }
4fa3602b
PB
4442
4443 /* Optional constant. */
4444 if (skip_past_comma (&input_line_pointer) != FAIL)
4445 {
4446 if (immediate_for_directive (&offset) == FAIL)
4447 return;
4448 }
4449 else
4450 offset = 0;
4451
c19d1205 4452 demand_empty_rest_of_line ();
b99bd4ef 4453
c19d1205 4454 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4455 {
c19d1205 4456 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4457 return;
4458 }
4459
c19d1205
ZW
4460 if (unwind.fp_reg != REG_SP)
4461 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4462
c19d1205
ZW
4463 /* Generate opcode to restore the value. */
4464 op = 0x90 | reg;
4465 add_unwind_opcode (op, 1);
4466
4467 /* Record the information for later. */
4468 unwind.fp_reg = reg;
4fa3602b 4469 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4470 unwind.sp_restored = 1;
b05fe5cf
ZW
4471}
4472
c19d1205
ZW
4473/* Parse an unwind_pad directive. */
4474
b05fe5cf 4475static void
c19d1205 4476s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4477{
c19d1205 4478 int offset;
b05fe5cf 4479
921e5f0a 4480 if (!unwind.proc_start)
c921be7d 4481 as_bad (MISSING_FNSTART);
921e5f0a 4482
c19d1205
ZW
4483 if (immediate_for_directive (&offset) == FAIL)
4484 return;
b99bd4ef 4485
c19d1205
ZW
4486 if (offset & 3)
4487 {
4488 as_bad (_("stack increment must be multiple of 4"));
4489 ignore_rest_of_line ();
4490 return;
4491 }
b99bd4ef 4492
c19d1205
ZW
4493 /* Don't generate any opcodes, just record the details for later. */
4494 unwind.frame_size += offset;
4495 unwind.pending_offset += offset;
4496
4497 demand_empty_rest_of_line ();
4498}
4499
4500/* Parse an unwind_setfp directive. */
4501
4502static void
4503s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4504{
c19d1205
ZW
4505 int sp_reg;
4506 int fp_reg;
4507 int offset;
4508
921e5f0a 4509 if (!unwind.proc_start)
c921be7d 4510 as_bad (MISSING_FNSTART);
921e5f0a 4511
dcbf9037 4512 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4513 if (skip_past_comma (&input_line_pointer) == FAIL)
4514 sp_reg = FAIL;
4515 else
dcbf9037 4516 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4517
c19d1205
ZW
4518 if (fp_reg == FAIL || sp_reg == FAIL)
4519 {
4520 as_bad (_("expected <reg>, <reg>"));
4521 ignore_rest_of_line ();
4522 return;
4523 }
b99bd4ef 4524
c19d1205
ZW
4525 /* Optional constant. */
4526 if (skip_past_comma (&input_line_pointer) != FAIL)
4527 {
4528 if (immediate_for_directive (&offset) == FAIL)
4529 return;
4530 }
4531 else
4532 offset = 0;
a737bd4d 4533
c19d1205 4534 demand_empty_rest_of_line ();
a737bd4d 4535
fdfde340 4536 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4537 {
c19d1205
ZW
4538 as_bad (_("register must be either sp or set by a previous"
4539 "unwind_movsp directive"));
4540 return;
a737bd4d
NC
4541 }
4542
c19d1205
ZW
4543 /* Don't generate any opcodes, just record the information for later. */
4544 unwind.fp_reg = fp_reg;
4545 unwind.fp_used = 1;
fdfde340 4546 if (sp_reg == REG_SP)
c19d1205
ZW
4547 unwind.fp_offset = unwind.frame_size - offset;
4548 else
4549 unwind.fp_offset -= offset;
a737bd4d
NC
4550}
4551
c19d1205
ZW
4552/* Parse an unwind_raw directive. */
4553
4554static void
4555s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4556{
c19d1205 4557 expressionS exp;
708587a4 4558 /* This is an arbitrary limit. */
c19d1205
ZW
4559 unsigned char op[16];
4560 int count;
a737bd4d 4561
921e5f0a 4562 if (!unwind.proc_start)
c921be7d 4563 as_bad (MISSING_FNSTART);
921e5f0a 4564
c19d1205
ZW
4565 expression (&exp);
4566 if (exp.X_op == O_constant
4567 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4568 {
c19d1205
ZW
4569 unwind.frame_size += exp.X_add_number;
4570 expression (&exp);
4571 }
4572 else
4573 exp.X_op = O_illegal;
a737bd4d 4574
c19d1205
ZW
4575 if (exp.X_op != O_constant)
4576 {
4577 as_bad (_("expected <offset>, <opcode>"));
4578 ignore_rest_of_line ();
4579 return;
4580 }
a737bd4d 4581
c19d1205 4582 count = 0;
a737bd4d 4583
c19d1205
ZW
4584 /* Parse the opcode. */
4585 for (;;)
4586 {
4587 if (count >= 16)
4588 {
4589 as_bad (_("unwind opcode too long"));
4590 ignore_rest_of_line ();
a737bd4d 4591 }
c19d1205 4592 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4593 {
c19d1205
ZW
4594 as_bad (_("invalid unwind opcode"));
4595 ignore_rest_of_line ();
4596 return;
a737bd4d 4597 }
c19d1205 4598 op[count++] = exp.X_add_number;
a737bd4d 4599
c19d1205
ZW
4600 /* Parse the next byte. */
4601 if (skip_past_comma (&input_line_pointer) == FAIL)
4602 break;
a737bd4d 4603
c19d1205
ZW
4604 expression (&exp);
4605 }
b99bd4ef 4606
c19d1205
ZW
4607 /* Add the opcode bytes in reverse order. */
4608 while (count--)
4609 add_unwind_opcode (op[count], 1);
b99bd4ef 4610
c19d1205 4611 demand_empty_rest_of_line ();
b99bd4ef 4612}
ee065d83
PB
4613
4614
4615/* Parse a .eabi_attribute directive. */
4616
4617static void
4618s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4619{
0420f52b 4620 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4621
4622 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4623 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4624}
4625
0855e32b
NS
4626/* Emit a tls fix for the symbol. */
4627
4628static void
4629s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4630{
4631 char *p;
4632 expressionS exp;
4633#ifdef md_flush_pending_output
4634 md_flush_pending_output ();
4635#endif
4636
4637#ifdef md_cons_align
4638 md_cons_align (4);
4639#endif
4640
4641 /* Since we're just labelling the code, there's no need to define a
4642 mapping symbol. */
4643 expression (&exp);
4644 p = obstack_next_free (&frchain_now->frch_obstack);
4645 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4646 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4647 : BFD_RELOC_ARM_TLS_DESCSEQ);
4648}
cdf9ccec 4649#endif /* OBJ_ELF */
0855e32b 4650
ee065d83 4651static void s_arm_arch (int);
7a1d4c38 4652static void s_arm_object_arch (int);
ee065d83
PB
4653static void s_arm_cpu (int);
4654static void s_arm_fpu (int);
69133863 4655static void s_arm_arch_extension (int);
b99bd4ef 4656
f0927246
NC
4657#ifdef TE_PE
4658
4659static void
5f4273c7 4660pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4661{
4662 expressionS exp;
4663
4664 do
4665 {
4666 expression (&exp);
4667 if (exp.X_op == O_symbol)
4668 exp.X_op = O_secrel;
4669
4670 emit_expr (&exp, 4);
4671 }
4672 while (*input_line_pointer++ == ',');
4673
4674 input_line_pointer--;
4675 demand_empty_rest_of_line ();
4676}
4677#endif /* TE_PE */
4678
c19d1205
ZW
4679/* This table describes all the machine specific pseudo-ops the assembler
4680 has to support. The fields are:
4681 pseudo-op name without dot
4682 function to call to execute this pseudo-op
4683 Integer arg to pass to the function. */
b99bd4ef 4684
c19d1205 4685const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4686{
c19d1205
ZW
4687 /* Never called because '.req' does not start a line. */
4688 { "req", s_req, 0 },
dcbf9037
JB
4689 /* Following two are likewise never called. */
4690 { "dn", s_dn, 0 },
4691 { "qn", s_qn, 0 },
c19d1205
ZW
4692 { "unreq", s_unreq, 0 },
4693 { "bss", s_bss, 0 },
db2ed2e0 4694 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4695 { "arm", s_arm, 0 },
4696 { "thumb", s_thumb, 0 },
4697 { "code", s_code, 0 },
4698 { "force_thumb", s_force_thumb, 0 },
4699 { "thumb_func", s_thumb_func, 0 },
4700 { "thumb_set", s_thumb_set, 0 },
4701 { "even", s_even, 0 },
4702 { "ltorg", s_ltorg, 0 },
4703 { "pool", s_ltorg, 0 },
4704 { "syntax", s_syntax, 0 },
8463be01
PB
4705 { "cpu", s_arm_cpu, 0 },
4706 { "arch", s_arm_arch, 0 },
7a1d4c38 4707 { "object_arch", s_arm_object_arch, 0 },
8463be01 4708 { "fpu", s_arm_fpu, 0 },
69133863 4709 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4710#ifdef OBJ_ELF
c921be7d
NC
4711 { "word", s_arm_elf_cons, 4 },
4712 { "long", s_arm_elf_cons, 4 },
4713 { "inst.n", s_arm_elf_inst, 2 },
4714 { "inst.w", s_arm_elf_inst, 4 },
4715 { "inst", s_arm_elf_inst, 0 },
4716 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4717 { "fnstart", s_arm_unwind_fnstart, 0 },
4718 { "fnend", s_arm_unwind_fnend, 0 },
4719 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4720 { "personality", s_arm_unwind_personality, 0 },
4721 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4722 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4723 { "save", s_arm_unwind_save, 0 },
fa073d69 4724 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4725 { "movsp", s_arm_unwind_movsp, 0 },
4726 { "pad", s_arm_unwind_pad, 0 },
4727 { "setfp", s_arm_unwind_setfp, 0 },
4728 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4729 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4730 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4731#else
4732 { "word", cons, 4},
f0927246
NC
4733
4734 /* These are used for dwarf. */
4735 {"2byte", cons, 2},
4736 {"4byte", cons, 4},
4737 {"8byte", cons, 8},
4738 /* These are used for dwarf2. */
4739 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4740 { "loc", dwarf2_directive_loc, 0 },
4741 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4742#endif
4743 { "extend", float_cons, 'x' },
4744 { "ldouble", float_cons, 'x' },
4745 { "packed", float_cons, 'p' },
f0927246
NC
4746#ifdef TE_PE
4747 {"secrel32", pe_directive_secrel, 0},
4748#endif
2e6976a8
DG
4749
4750 /* These are for compatibility with CodeComposer Studio. */
4751 {"ref", s_ccs_ref, 0},
4752 {"def", s_ccs_def, 0},
4753 {"asmfunc", s_ccs_asmfunc, 0},
4754 {"endasmfunc", s_ccs_endasmfunc, 0},
4755
c19d1205
ZW
4756 { 0, 0, 0 }
4757};
4758\f
4759/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4760
c19d1205
ZW
4761/* Generic immediate-value read function for use in insn parsing.
4762 STR points to the beginning of the immediate (the leading #);
4763 VAL receives the value; if the value is outside [MIN, MAX]
4764 issue an error. PREFIX_OPT is true if the immediate prefix is
4765 optional. */
b99bd4ef 4766
c19d1205
ZW
4767static int
4768parse_immediate (char **str, int *val, int min, int max,
4769 bfd_boolean prefix_opt)
4770{
4771 expressionS exp;
4772 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4773 if (exp.X_op != O_constant)
b99bd4ef 4774 {
c19d1205
ZW
4775 inst.error = _("constant expression required");
4776 return FAIL;
4777 }
b99bd4ef 4778
c19d1205
ZW
4779 if (exp.X_add_number < min || exp.X_add_number > max)
4780 {
4781 inst.error = _("immediate value out of range");
4782 return FAIL;
4783 }
b99bd4ef 4784
c19d1205
ZW
4785 *val = exp.X_add_number;
4786 return SUCCESS;
4787}
b99bd4ef 4788
5287ad62 4789/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4790 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4791 instructions. Puts the result directly in inst.operands[i]. */
4792
4793static int
8335d6aa
JW
4794parse_big_immediate (char **str, int i, expressionS *in_exp,
4795 bfd_boolean allow_symbol_p)
5287ad62
JB
4796{
4797 expressionS exp;
8335d6aa 4798 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4799 char *ptr = *str;
4800
8335d6aa 4801 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4802
8335d6aa 4803 if (exp_p->X_op == O_constant)
036dc3f7 4804 {
8335d6aa 4805 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4806 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4807 O_constant. We have to be careful not to break compilation for
4808 32-bit X_add_number, though. */
8335d6aa 4809 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4810 {
8335d6aa
JW
4811 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4812 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4813 & 0xffffffff);
036dc3f7
PB
4814 inst.operands[i].regisimm = 1;
4815 }
4816 }
8335d6aa
JW
4817 else if (exp_p->X_op == O_big
4818 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4819 {
4820 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4821
5287ad62 4822 /* Bignums have their least significant bits in
477330fc
RM
4823 generic_bignum[0]. Make sure we put 32 bits in imm and
4824 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4825 gas_assert (parts != 0);
95b75c01
NC
4826
4827 /* Make sure that the number is not too big.
4828 PR 11972: Bignums can now be sign-extended to the
4829 size of a .octa so check that the out of range bits
4830 are all zero or all one. */
8335d6aa 4831 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4832 {
4833 LITTLENUM_TYPE m = -1;
4834
4835 if (generic_bignum[parts * 2] != 0
4836 && generic_bignum[parts * 2] != m)
4837 return FAIL;
4838
8335d6aa 4839 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4840 if (generic_bignum[j] != generic_bignum[j-1])
4841 return FAIL;
4842 }
4843
5287ad62
JB
4844 inst.operands[i].imm = 0;
4845 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4846 inst.operands[i].imm |= generic_bignum[idx]
4847 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4848 inst.operands[i].reg = 0;
4849 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4850 inst.operands[i].reg |= generic_bignum[idx]
4851 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4852 inst.operands[i].regisimm = 1;
4853 }
8335d6aa 4854 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4855 return FAIL;
5f4273c7 4856
5287ad62
JB
4857 *str = ptr;
4858
4859 return SUCCESS;
4860}
4861
c19d1205
ZW
4862/* Returns the pseudo-register number of an FPA immediate constant,
4863 or FAIL if there isn't a valid constant here. */
b99bd4ef 4864
c19d1205
ZW
4865static int
4866parse_fpa_immediate (char ** str)
4867{
4868 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4869 char * save_in;
4870 expressionS exp;
4871 int i;
4872 int j;
b99bd4ef 4873
c19d1205
ZW
4874 /* First try and match exact strings, this is to guarantee
4875 that some formats will work even for cross assembly. */
b99bd4ef 4876
c19d1205
ZW
4877 for (i = 0; fp_const[i]; i++)
4878 {
4879 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4880 {
c19d1205 4881 char *start = *str;
b99bd4ef 4882
c19d1205
ZW
4883 *str += strlen (fp_const[i]);
4884 if (is_end_of_line[(unsigned char) **str])
4885 return i + 8;
4886 *str = start;
4887 }
4888 }
b99bd4ef 4889
c19d1205
ZW
4890 /* Just because we didn't get a match doesn't mean that the constant
4891 isn't valid, just that it is in a format that we don't
4892 automatically recognize. Try parsing it with the standard
4893 expression routines. */
b99bd4ef 4894
c19d1205 4895 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4896
c19d1205
ZW
4897 /* Look for a raw floating point number. */
4898 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4899 && is_end_of_line[(unsigned char) *save_in])
4900 {
4901 for (i = 0; i < NUM_FLOAT_VALS; i++)
4902 {
4903 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4904 {
c19d1205
ZW
4905 if (words[j] != fp_values[i][j])
4906 break;
b99bd4ef
NC
4907 }
4908
c19d1205 4909 if (j == MAX_LITTLENUMS)
b99bd4ef 4910 {
c19d1205
ZW
4911 *str = save_in;
4912 return i + 8;
b99bd4ef
NC
4913 }
4914 }
4915 }
b99bd4ef 4916
c19d1205
ZW
4917 /* Try and parse a more complex expression, this will probably fail
4918 unless the code uses a floating point prefix (eg "0f"). */
4919 save_in = input_line_pointer;
4920 input_line_pointer = *str;
4921 if (expression (&exp) == absolute_section
4922 && exp.X_op == O_big
4923 && exp.X_add_number < 0)
4924 {
4925 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4926 Ditto for 15. */
ba592044
AM
4927#define X_PRECISION 5
4928#define E_PRECISION 15L
4929 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4930 {
4931 for (i = 0; i < NUM_FLOAT_VALS; i++)
4932 {
4933 for (j = 0; j < MAX_LITTLENUMS; j++)
4934 {
4935 if (words[j] != fp_values[i][j])
4936 break;
4937 }
b99bd4ef 4938
c19d1205
ZW
4939 if (j == MAX_LITTLENUMS)
4940 {
4941 *str = input_line_pointer;
4942 input_line_pointer = save_in;
4943 return i + 8;
4944 }
4945 }
4946 }
b99bd4ef
NC
4947 }
4948
c19d1205
ZW
4949 *str = input_line_pointer;
4950 input_line_pointer = save_in;
4951 inst.error = _("invalid FPA immediate expression");
4952 return FAIL;
b99bd4ef
NC
4953}
4954
136da414
JB
4955/* Returns 1 if a number has "quarter-precision" float format
4956 0baBbbbbbc defgh000 00000000 00000000. */
4957
4958static int
4959is_quarter_float (unsigned imm)
4960{
4961 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4962 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4963}
4964
aacf0b33
KT
4965
4966/* Detect the presence of a floating point or integer zero constant,
4967 i.e. #0.0 or #0. */
4968
4969static bfd_boolean
4970parse_ifimm_zero (char **in)
4971{
4972 int error_code;
4973
4974 if (!is_immediate_prefix (**in))
3c6452ae
TP
4975 {
4976 /* In unified syntax, all prefixes are optional. */
4977 if (!unified_syntax)
4978 return FALSE;
4979 }
4980 else
4981 ++*in;
0900a05b
JW
4982
4983 /* Accept #0x0 as a synonym for #0. */
4984 if (strncmp (*in, "0x", 2) == 0)
4985 {
4986 int val;
4987 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4988 return FALSE;
4989 return TRUE;
4990 }
4991
aacf0b33
KT
4992 error_code = atof_generic (in, ".", EXP_CHARS,
4993 &generic_floating_point_number);
4994
4995 if (!error_code
4996 && generic_floating_point_number.sign == '+'
4997 && (generic_floating_point_number.low
4998 > generic_floating_point_number.leader))
4999 return TRUE;
5000
5001 return FALSE;
5002}
5003
136da414
JB
5004/* Parse an 8-bit "quarter-precision" floating point number of the form:
5005 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5006 The zero and minus-zero cases need special handling, since they can't be
5007 encoded in the "quarter-precision" float format, but can nonetheless be
5008 loaded as integer constants. */
136da414
JB
5009
5010static unsigned
5011parse_qfloat_immediate (char **ccp, int *immed)
5012{
5013 char *str = *ccp;
c96612cc 5014 char *fpnum;
136da414 5015 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5016 int found_fpchar = 0;
5f4273c7 5017
136da414 5018 skip_past_char (&str, '#');
5f4273c7 5019
c96612cc
JB
5020 /* We must not accidentally parse an integer as a floating-point number. Make
5021 sure that the value we parse is not an integer by checking for special
5022 characters '.' or 'e'.
5023 FIXME: This is a horrible hack, but doing better is tricky because type
5024 information isn't in a very usable state at parse time. */
5025 fpnum = str;
5026 skip_whitespace (fpnum);
5027
5028 if (strncmp (fpnum, "0x", 2) == 0)
5029 return FAIL;
5030 else
5031 {
5032 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5033 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5034 {
5035 found_fpchar = 1;
5036 break;
5037 }
c96612cc
JB
5038
5039 if (!found_fpchar)
477330fc 5040 return FAIL;
c96612cc 5041 }
5f4273c7 5042
136da414
JB
5043 if ((str = atof_ieee (str, 's', words)) != NULL)
5044 {
5045 unsigned fpword = 0;
5046 int i;
5f4273c7 5047
136da414
JB
5048 /* Our FP word must be 32 bits (single-precision FP). */
5049 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5050 {
5051 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5052 fpword |= words[i];
5053 }
5f4273c7 5054
c96612cc 5055 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5056 *immed = fpword;
136da414 5057 else
477330fc 5058 return FAIL;
136da414
JB
5059
5060 *ccp = str;
5f4273c7 5061
136da414
JB
5062 return SUCCESS;
5063 }
5f4273c7 5064
136da414
JB
5065 return FAIL;
5066}
5067
c19d1205
ZW
5068/* Shift operands. */
5069enum shift_kind
b99bd4ef 5070{
c19d1205
ZW
5071 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5072};
b99bd4ef 5073
c19d1205
ZW
5074struct asm_shift_name
5075{
5076 const char *name;
5077 enum shift_kind kind;
5078};
b99bd4ef 5079
c19d1205
ZW
5080/* Third argument to parse_shift. */
5081enum parse_shift_mode
5082{
5083 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5084 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5085 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5086 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5087 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5088};
b99bd4ef 5089
c19d1205
ZW
5090/* Parse a <shift> specifier on an ARM data processing instruction.
5091 This has three forms:
b99bd4ef 5092
c19d1205
ZW
5093 (LSL|LSR|ASL|ASR|ROR) Rs
5094 (LSL|LSR|ASL|ASR|ROR) #imm
5095 RRX
b99bd4ef 5096
c19d1205
ZW
5097 Note that ASL is assimilated to LSL in the instruction encoding, and
5098 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5099
c19d1205
ZW
5100static int
5101parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5102{
c19d1205
ZW
5103 const struct asm_shift_name *shift_name;
5104 enum shift_kind shift;
5105 char *s = *str;
5106 char *p = s;
5107 int reg;
b99bd4ef 5108
c19d1205
ZW
5109 for (p = *str; ISALPHA (*p); p++)
5110 ;
b99bd4ef 5111
c19d1205 5112 if (p == *str)
b99bd4ef 5113 {
c19d1205
ZW
5114 inst.error = _("shift expression expected");
5115 return FAIL;
b99bd4ef
NC
5116 }
5117
21d799b5 5118 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5119 p - *str);
c19d1205
ZW
5120
5121 if (shift_name == NULL)
b99bd4ef 5122 {
c19d1205
ZW
5123 inst.error = _("shift expression expected");
5124 return FAIL;
b99bd4ef
NC
5125 }
5126
c19d1205 5127 shift = shift_name->kind;
b99bd4ef 5128
c19d1205
ZW
5129 switch (mode)
5130 {
5131 case NO_SHIFT_RESTRICT:
5132 case SHIFT_IMMEDIATE: break;
b99bd4ef 5133
c19d1205
ZW
5134 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5135 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5136 {
5137 inst.error = _("'LSL' or 'ASR' required");
5138 return FAIL;
5139 }
5140 break;
b99bd4ef 5141
c19d1205
ZW
5142 case SHIFT_LSL_IMMEDIATE:
5143 if (shift != SHIFT_LSL)
5144 {
5145 inst.error = _("'LSL' required");
5146 return FAIL;
5147 }
5148 break;
b99bd4ef 5149
c19d1205
ZW
5150 case SHIFT_ASR_IMMEDIATE:
5151 if (shift != SHIFT_ASR)
5152 {
5153 inst.error = _("'ASR' required");
5154 return FAIL;
5155 }
5156 break;
b99bd4ef 5157
c19d1205
ZW
5158 default: abort ();
5159 }
b99bd4ef 5160
c19d1205
ZW
5161 if (shift != SHIFT_RRX)
5162 {
5163 /* Whitespace can appear here if the next thing is a bare digit. */
5164 skip_whitespace (p);
b99bd4ef 5165
c19d1205 5166 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5167 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5168 {
5169 inst.operands[i].imm = reg;
5170 inst.operands[i].immisreg = 1;
5171 }
5172 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5173 return FAIL;
5174 }
5175 inst.operands[i].shift_kind = shift;
5176 inst.operands[i].shifted = 1;
5177 *str = p;
5178 return SUCCESS;
b99bd4ef
NC
5179}
5180
c19d1205 5181/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5182
c19d1205
ZW
5183 #<immediate>
5184 #<immediate>, <rotate>
5185 <Rm>
5186 <Rm>, <shift>
b99bd4ef 5187
c19d1205
ZW
5188 where <shift> is defined by parse_shift above, and <rotate> is a
5189 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5190 is deferred to md_apply_fix. */
b99bd4ef 5191
c19d1205
ZW
5192static int
5193parse_shifter_operand (char **str, int i)
5194{
5195 int value;
91d6fa6a 5196 expressionS exp;
b99bd4ef 5197
dcbf9037 5198 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5199 {
5200 inst.operands[i].reg = value;
5201 inst.operands[i].isreg = 1;
b99bd4ef 5202
c19d1205
ZW
5203 /* parse_shift will override this if appropriate */
5204 inst.reloc.exp.X_op = O_constant;
5205 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5206
c19d1205
ZW
5207 if (skip_past_comma (str) == FAIL)
5208 return SUCCESS;
b99bd4ef 5209
c19d1205
ZW
5210 /* Shift operation on register. */
5211 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5212 }
5213
c19d1205
ZW
5214 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5215 return FAIL;
b99bd4ef 5216
c19d1205 5217 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5218 {
c19d1205 5219 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5220 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5221 return FAIL;
b99bd4ef 5222
91d6fa6a 5223 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5224 {
5225 inst.error = _("constant expression expected");
5226 return FAIL;
5227 }
b99bd4ef 5228
91d6fa6a 5229 value = exp.X_add_number;
c19d1205
ZW
5230 if (value < 0 || value > 30 || value % 2 != 0)
5231 {
5232 inst.error = _("invalid rotation");
5233 return FAIL;
5234 }
5235 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5236 {
5237 inst.error = _("invalid constant");
5238 return FAIL;
5239 }
09d92015 5240
a415b1cd
JB
5241 /* Encode as specified. */
5242 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5243 return SUCCESS;
09d92015
MM
5244 }
5245
c19d1205
ZW
5246 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5247 inst.reloc.pc_rel = 0;
5248 return SUCCESS;
09d92015
MM
5249}
5250
4962c51a
MS
5251/* Group relocation information. Each entry in the table contains the
5252 textual name of the relocation as may appear in assembler source
5253 and must end with a colon.
5254 Along with this textual name are the relocation codes to be used if
5255 the corresponding instruction is an ALU instruction (ADD or SUB only),
5256 an LDR, an LDRS, or an LDC. */
5257
5258struct group_reloc_table_entry
5259{
5260 const char *name;
5261 int alu_code;
5262 int ldr_code;
5263 int ldrs_code;
5264 int ldc_code;
5265};
5266
5267typedef enum
5268{
5269 /* Varieties of non-ALU group relocation. */
5270
5271 GROUP_LDR,
5272 GROUP_LDRS,
5273 GROUP_LDC
5274} group_reloc_type;
5275
5276static struct group_reloc_table_entry group_reloc_table[] =
5277 { /* Program counter relative: */
5278 { "pc_g0_nc",
5279 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5280 0, /* LDR */
5281 0, /* LDRS */
5282 0 }, /* LDC */
5283 { "pc_g0",
5284 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5285 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5286 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5287 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5288 { "pc_g1_nc",
5289 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5290 0, /* LDR */
5291 0, /* LDRS */
5292 0 }, /* LDC */
5293 { "pc_g1",
5294 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5295 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5296 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5297 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5298 { "pc_g2",
5299 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5300 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5301 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5302 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5303 /* Section base relative */
5304 { "sb_g0_nc",
5305 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5306 0, /* LDR */
5307 0, /* LDRS */
5308 0 }, /* LDC */
5309 { "sb_g0",
5310 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5311 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5312 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5313 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5314 { "sb_g1_nc",
5315 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5316 0, /* LDR */
5317 0, /* LDRS */
5318 0 }, /* LDC */
5319 { "sb_g1",
5320 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5321 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5322 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5323 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5324 { "sb_g2",
5325 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5326 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5327 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5328 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5329 /* Absolute thumb alu relocations. */
5330 { "lower0_7",
5331 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5332 0, /* LDR. */
5333 0, /* LDRS. */
5334 0 }, /* LDC. */
5335 { "lower8_15",
5336 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5337 0, /* LDR. */
5338 0, /* LDRS. */
5339 0 }, /* LDC. */
5340 { "upper0_7",
5341 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5342 0, /* LDR. */
5343 0, /* LDRS. */
5344 0 }, /* LDC. */
5345 { "upper8_15",
5346 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5347 0, /* LDR. */
5348 0, /* LDRS. */
5349 0 } }; /* LDC. */
4962c51a
MS
5350
5351/* Given the address of a pointer pointing to the textual name of a group
5352 relocation as may appear in assembler source, attempt to find its details
5353 in group_reloc_table. The pointer will be updated to the character after
5354 the trailing colon. On failure, FAIL will be returned; SUCCESS
5355 otherwise. On success, *entry will be updated to point at the relevant
5356 group_reloc_table entry. */
5357
5358static int
5359find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5360{
5361 unsigned int i;
5362 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5363 {
5364 int length = strlen (group_reloc_table[i].name);
5365
5f4273c7
NC
5366 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5367 && (*str)[length] == ':')
477330fc
RM
5368 {
5369 *out = &group_reloc_table[i];
5370 *str += (length + 1);
5371 return SUCCESS;
5372 }
4962c51a
MS
5373 }
5374
5375 return FAIL;
5376}
5377
5378/* Parse a <shifter_operand> for an ARM data processing instruction
5379 (as for parse_shifter_operand) where group relocations are allowed:
5380
5381 #<immediate>
5382 #<immediate>, <rotate>
5383 #:<group_reloc>:<expression>
5384 <Rm>
5385 <Rm>, <shift>
5386
5387 where <group_reloc> is one of the strings defined in group_reloc_table.
5388 The hashes are optional.
5389
5390 Everything else is as for parse_shifter_operand. */
5391
5392static parse_operand_result
5393parse_shifter_operand_group_reloc (char **str, int i)
5394{
5395 /* Determine if we have the sequence of characters #: or just :
5396 coming next. If we do, then we check for a group relocation.
5397 If we don't, punt the whole lot to parse_shifter_operand. */
5398
5399 if (((*str)[0] == '#' && (*str)[1] == ':')
5400 || (*str)[0] == ':')
5401 {
5402 struct group_reloc_table_entry *entry;
5403
5404 if ((*str)[0] == '#')
477330fc 5405 (*str) += 2;
4962c51a 5406 else
477330fc 5407 (*str)++;
4962c51a
MS
5408
5409 /* Try to parse a group relocation. Anything else is an error. */
5410 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5411 {
5412 inst.error = _("unknown group relocation");
5413 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5414 }
4962c51a
MS
5415
5416 /* We now have the group relocation table entry corresponding to
477330fc 5417 the name in the assembler source. Next, we parse the expression. */
4962c51a 5418 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5419 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5420
5421 /* Record the relocation type (always the ALU variant here). */
21d799b5 5422 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5423 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5424
5425 return PARSE_OPERAND_SUCCESS;
5426 }
5427 else
5428 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5429 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5430
5431 /* Never reached. */
5432}
5433
8e560766
MGD
5434/* Parse a Neon alignment expression. Information is written to
5435 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5436
8e560766
MGD
5437 align .imm = align << 8, .immisalign=1, .preind=0 */
5438static parse_operand_result
5439parse_neon_alignment (char **str, int i)
5440{
5441 char *p = *str;
5442 expressionS exp;
5443
5444 my_get_expression (&exp, &p, GE_NO_PREFIX);
5445
5446 if (exp.X_op != O_constant)
5447 {
5448 inst.error = _("alignment must be constant");
5449 return PARSE_OPERAND_FAIL;
5450 }
5451
5452 inst.operands[i].imm = exp.X_add_number << 8;
5453 inst.operands[i].immisalign = 1;
5454 /* Alignments are not pre-indexes. */
5455 inst.operands[i].preind = 0;
5456
5457 *str = p;
5458 return PARSE_OPERAND_SUCCESS;
5459}
5460
c19d1205
ZW
5461/* Parse all forms of an ARM address expression. Information is written
5462 to inst.operands[i] and/or inst.reloc.
09d92015 5463
c19d1205 5464 Preindexed addressing (.preind=1):
09d92015 5465
c19d1205
ZW
5466 [Rn, #offset] .reg=Rn .reloc.exp=offset
5467 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5468 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5469 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5470
c19d1205 5471 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5472
c19d1205 5473 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5474
c19d1205
ZW
5475 [Rn], #offset .reg=Rn .reloc.exp=offset
5476 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5477 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5478 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5479
c19d1205 5480 Unindexed addressing (.preind=0, .postind=0):
09d92015 5481
c19d1205 5482 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5483
c19d1205 5484 Other:
09d92015 5485
c19d1205
ZW
5486 [Rn]{!} shorthand for [Rn,#0]{!}
5487 =immediate .isreg=0 .reloc.exp=immediate
5488 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5489
c19d1205
ZW
5490 It is the caller's responsibility to check for addressing modes not
5491 supported by the instruction, and to set inst.reloc.type. */
5492
4962c51a
MS
5493static parse_operand_result
5494parse_address_main (char **str, int i, int group_relocations,
477330fc 5495 group_reloc_type group_type)
09d92015 5496{
c19d1205
ZW
5497 char *p = *str;
5498 int reg;
09d92015 5499
c19d1205 5500 if (skip_past_char (&p, '[') == FAIL)
09d92015 5501 {
c19d1205
ZW
5502 if (skip_past_char (&p, '=') == FAIL)
5503 {
974da60d 5504 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5505 inst.reloc.pc_rel = 1;
5506 inst.operands[i].reg = REG_PC;
5507 inst.operands[i].isreg = 1;
5508 inst.operands[i].preind = 1;
09d92015 5509
8335d6aa
JW
5510 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5511 return PARSE_OPERAND_FAIL;
5512 }
5513 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5514 /*allow_symbol_p=*/TRUE))
4962c51a 5515 return PARSE_OPERAND_FAIL;
09d92015 5516
c19d1205 5517 *str = p;
4962c51a 5518 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5519 }
5520
8ab8155f
NC
5521 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5522 skip_whitespace (p);
5523
dcbf9037 5524 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5525 {
c19d1205 5526 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5527 return PARSE_OPERAND_FAIL;
09d92015 5528 }
c19d1205
ZW
5529 inst.operands[i].reg = reg;
5530 inst.operands[i].isreg = 1;
09d92015 5531
c19d1205 5532 if (skip_past_comma (&p) == SUCCESS)
09d92015 5533 {
c19d1205 5534 inst.operands[i].preind = 1;
09d92015 5535
c19d1205
ZW
5536 if (*p == '+') p++;
5537 else if (*p == '-') p++, inst.operands[i].negative = 1;
5538
dcbf9037 5539 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5540 {
c19d1205
ZW
5541 inst.operands[i].imm = reg;
5542 inst.operands[i].immisreg = 1;
5543
5544 if (skip_past_comma (&p) == SUCCESS)
5545 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5546 return PARSE_OPERAND_FAIL;
c19d1205 5547 }
5287ad62 5548 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5549 {
5550 /* FIXME: '@' should be used here, but it's filtered out by generic
5551 code before we get to see it here. This may be subject to
5552 change. */
5553 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5554
8e560766
MGD
5555 if (result != PARSE_OPERAND_SUCCESS)
5556 return result;
5557 }
c19d1205
ZW
5558 else
5559 {
5560 if (inst.operands[i].negative)
5561 {
5562 inst.operands[i].negative = 0;
5563 p--;
5564 }
4962c51a 5565
5f4273c7
NC
5566 if (group_relocations
5567 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5568 {
5569 struct group_reloc_table_entry *entry;
5570
477330fc
RM
5571 /* Skip over the #: or : sequence. */
5572 if (*p == '#')
5573 p += 2;
5574 else
5575 p++;
4962c51a
MS
5576
5577 /* Try to parse a group relocation. Anything else is an
477330fc 5578 error. */
4962c51a
MS
5579 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5580 {
5581 inst.error = _("unknown group relocation");
5582 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5583 }
5584
5585 /* We now have the group relocation table entry corresponding to
5586 the name in the assembler source. Next, we parse the
477330fc 5587 expression. */
4962c51a
MS
5588 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5589 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5590
5591 /* Record the relocation type. */
477330fc
RM
5592 switch (group_type)
5593 {
5594 case GROUP_LDR:
5595 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5596 break;
4962c51a 5597
477330fc
RM
5598 case GROUP_LDRS:
5599 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5600 break;
4962c51a 5601
477330fc
RM
5602 case GROUP_LDC:
5603 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5604 break;
4962c51a 5605
477330fc
RM
5606 default:
5607 gas_assert (0);
5608 }
4962c51a 5609
477330fc 5610 if (inst.reloc.type == 0)
4962c51a
MS
5611 {
5612 inst.error = _("this group relocation is not allowed on this instruction");
5613 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5614 }
477330fc
RM
5615 }
5616 else
26d97720
NS
5617 {
5618 char *q = p;
5619 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5620 return PARSE_OPERAND_FAIL;
5621 /* If the offset is 0, find out if it's a +0 or -0. */
5622 if (inst.reloc.exp.X_op == O_constant
5623 && inst.reloc.exp.X_add_number == 0)
5624 {
5625 skip_whitespace (q);
5626 if (*q == '#')
5627 {
5628 q++;
5629 skip_whitespace (q);
5630 }
5631 if (*q == '-')
5632 inst.operands[i].negative = 1;
5633 }
5634 }
09d92015
MM
5635 }
5636 }
8e560766
MGD
5637 else if (skip_past_char (&p, ':') == SUCCESS)
5638 {
5639 /* FIXME: '@' should be used here, but it's filtered out by generic code
5640 before we get to see it here. This may be subject to change. */
5641 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5642
8e560766
MGD
5643 if (result != PARSE_OPERAND_SUCCESS)
5644 return result;
5645 }
09d92015 5646
c19d1205 5647 if (skip_past_char (&p, ']') == FAIL)
09d92015 5648 {
c19d1205 5649 inst.error = _("']' expected");
4962c51a 5650 return PARSE_OPERAND_FAIL;
09d92015
MM
5651 }
5652
c19d1205
ZW
5653 if (skip_past_char (&p, '!') == SUCCESS)
5654 inst.operands[i].writeback = 1;
09d92015 5655
c19d1205 5656 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5657 {
c19d1205
ZW
5658 if (skip_past_char (&p, '{') == SUCCESS)
5659 {
5660 /* [Rn], {expr} - unindexed, with option */
5661 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5662 0, 255, TRUE) == FAIL)
4962c51a 5663 return PARSE_OPERAND_FAIL;
09d92015 5664
c19d1205
ZW
5665 if (skip_past_char (&p, '}') == FAIL)
5666 {
5667 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5668 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5669 }
5670 if (inst.operands[i].preind)
5671 {
5672 inst.error = _("cannot combine index with option");
4962c51a 5673 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5674 }
5675 *str = p;
4962c51a 5676 return PARSE_OPERAND_SUCCESS;
09d92015 5677 }
c19d1205
ZW
5678 else
5679 {
5680 inst.operands[i].postind = 1;
5681 inst.operands[i].writeback = 1;
09d92015 5682
c19d1205
ZW
5683 if (inst.operands[i].preind)
5684 {
5685 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5686 return PARSE_OPERAND_FAIL;
c19d1205 5687 }
09d92015 5688
c19d1205
ZW
5689 if (*p == '+') p++;
5690 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5691
dcbf9037 5692 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5693 {
477330fc
RM
5694 /* We might be using the immediate for alignment already. If we
5695 are, OR the register number into the low-order bits. */
5696 if (inst.operands[i].immisalign)
5697 inst.operands[i].imm |= reg;
5698 else
5699 inst.operands[i].imm = reg;
c19d1205 5700 inst.operands[i].immisreg = 1;
a737bd4d 5701
c19d1205
ZW
5702 if (skip_past_comma (&p) == SUCCESS)
5703 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5704 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5705 }
5706 else
5707 {
26d97720 5708 char *q = p;
c19d1205
ZW
5709 if (inst.operands[i].negative)
5710 {
5711 inst.operands[i].negative = 0;
5712 p--;
5713 }
5714 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5715 return PARSE_OPERAND_FAIL;
26d97720
NS
5716 /* If the offset is 0, find out if it's a +0 or -0. */
5717 if (inst.reloc.exp.X_op == O_constant
5718 && inst.reloc.exp.X_add_number == 0)
5719 {
5720 skip_whitespace (q);
5721 if (*q == '#')
5722 {
5723 q++;
5724 skip_whitespace (q);
5725 }
5726 if (*q == '-')
5727 inst.operands[i].negative = 1;
5728 }
c19d1205
ZW
5729 }
5730 }
a737bd4d
NC
5731 }
5732
c19d1205
ZW
5733 /* If at this point neither .preind nor .postind is set, we have a
5734 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5735 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5736 {
5737 inst.operands[i].preind = 1;
5738 inst.reloc.exp.X_op = O_constant;
5739 inst.reloc.exp.X_add_number = 0;
5740 }
5741 *str = p;
4962c51a
MS
5742 return PARSE_OPERAND_SUCCESS;
5743}
5744
5745static int
5746parse_address (char **str, int i)
5747{
21d799b5 5748 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5749 ? SUCCESS : FAIL;
4962c51a
MS
5750}
5751
5752static parse_operand_result
5753parse_address_group_reloc (char **str, int i, group_reloc_type type)
5754{
5755 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5756}
5757
b6895b4f
PB
5758/* Parse an operand for a MOVW or MOVT instruction. */
5759static int
5760parse_half (char **str)
5761{
5762 char * p;
5f4273c7 5763
b6895b4f
PB
5764 p = *str;
5765 skip_past_char (&p, '#');
5f4273c7 5766 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5767 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5768 else if (strncasecmp (p, ":upper16:", 9) == 0)
5769 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5770
5771 if (inst.reloc.type != BFD_RELOC_UNUSED)
5772 {
5773 p += 9;
5f4273c7 5774 skip_whitespace (p);
b6895b4f
PB
5775 }
5776
5777 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5778 return FAIL;
5779
5780 if (inst.reloc.type == BFD_RELOC_UNUSED)
5781 {
5782 if (inst.reloc.exp.X_op != O_constant)
5783 {
5784 inst.error = _("constant expression expected");
5785 return FAIL;
5786 }
5787 if (inst.reloc.exp.X_add_number < 0
5788 || inst.reloc.exp.X_add_number > 0xffff)
5789 {
5790 inst.error = _("immediate value out of range");
5791 return FAIL;
5792 }
5793 }
5794 *str = p;
5795 return SUCCESS;
5796}
5797
c19d1205 5798/* Miscellaneous. */
a737bd4d 5799
c19d1205
ZW
5800/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5801 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5802static int
d2cd1205 5803parse_psr (char **str, bfd_boolean lhs)
09d92015 5804{
c19d1205
ZW
5805 char *p;
5806 unsigned long psr_field;
62b3e311
PB
5807 const struct asm_psr *psr;
5808 char *start;
d2cd1205 5809 bfd_boolean is_apsr = FALSE;
ac7f631b 5810 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5811
a4482bb6
NC
5812 /* PR gas/12698: If the user has specified -march=all then m_profile will
5813 be TRUE, but we want to ignore it in this case as we are building for any
5814 CPU type, including non-m variants. */
823d2571 5815 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5816 m_profile = FALSE;
5817
c19d1205
ZW
5818 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5819 feature for ease of use and backwards compatibility. */
5820 p = *str;
62b3e311 5821 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5822 {
5823 if (m_profile)
5824 goto unsupported_psr;
fa94de6b 5825
d2cd1205
JB
5826 psr_field = SPSR_BIT;
5827 }
5828 else if (strncasecmp (p, "CPSR", 4) == 0)
5829 {
5830 if (m_profile)
5831 goto unsupported_psr;
5832
5833 psr_field = 0;
5834 }
5835 else if (strncasecmp (p, "APSR", 4) == 0)
5836 {
5837 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5838 and ARMv7-R architecture CPUs. */
5839 is_apsr = TRUE;
5840 psr_field = 0;
5841 }
5842 else if (m_profile)
62b3e311
PB
5843 {
5844 start = p;
5845 do
5846 p++;
5847 while (ISALNUM (*p) || *p == '_');
5848
d2cd1205
JB
5849 if (strncasecmp (start, "iapsr", 5) == 0
5850 || strncasecmp (start, "eapsr", 5) == 0
5851 || strncasecmp (start, "xpsr", 4) == 0
5852 || strncasecmp (start, "psr", 3) == 0)
5853 p = start + strcspn (start, "rR") + 1;
5854
21d799b5 5855 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5856 p - start);
d2cd1205 5857
62b3e311
PB
5858 if (!psr)
5859 return FAIL;
09d92015 5860
d2cd1205
JB
5861 /* If APSR is being written, a bitfield may be specified. Note that
5862 APSR itself is handled above. */
5863 if (psr->field <= 3)
5864 {
5865 psr_field = psr->field;
5866 is_apsr = TRUE;
5867 goto check_suffix;
5868 }
5869
62b3e311 5870 *str = p;
d2cd1205
JB
5871 /* M-profile MSR instructions have the mask field set to "10", except
5872 *PSR variants which modify APSR, which may use a different mask (and
5873 have been handled already). Do that by setting the PSR_f field
5874 here. */
5875 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5876 }
d2cd1205
JB
5877 else
5878 goto unsupported_psr;
09d92015 5879
62b3e311 5880 p += 4;
d2cd1205 5881check_suffix:
c19d1205
ZW
5882 if (*p == '_')
5883 {
5884 /* A suffix follows. */
c19d1205
ZW
5885 p++;
5886 start = p;
a737bd4d 5887
c19d1205
ZW
5888 do
5889 p++;
5890 while (ISALNUM (*p) || *p == '_');
a737bd4d 5891
d2cd1205
JB
5892 if (is_apsr)
5893 {
5894 /* APSR uses a notation for bits, rather than fields. */
5895 unsigned int nzcvq_bits = 0;
5896 unsigned int g_bit = 0;
5897 char *bit;
fa94de6b 5898
d2cd1205
JB
5899 for (bit = start; bit != p; bit++)
5900 {
5901 switch (TOLOWER (*bit))
477330fc 5902 {
d2cd1205
JB
5903 case 'n':
5904 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5905 break;
5906
5907 case 'z':
5908 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5909 break;
5910
5911 case 'c':
5912 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5913 break;
5914
5915 case 'v':
5916 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5917 break;
fa94de6b 5918
d2cd1205
JB
5919 case 'q':
5920 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5921 break;
fa94de6b 5922
d2cd1205
JB
5923 case 'g':
5924 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5925 break;
fa94de6b 5926
d2cd1205
JB
5927 default:
5928 inst.error = _("unexpected bit specified after APSR");
5929 return FAIL;
5930 }
5931 }
fa94de6b 5932
d2cd1205
JB
5933 if (nzcvq_bits == 0x1f)
5934 psr_field |= PSR_f;
fa94de6b 5935
d2cd1205
JB
5936 if (g_bit == 0x1)
5937 {
5938 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5939 {
d2cd1205
JB
5940 inst.error = _("selected processor does not "
5941 "support DSP extension");
5942 return FAIL;
5943 }
5944
5945 psr_field |= PSR_s;
5946 }
fa94de6b 5947
d2cd1205
JB
5948 if ((nzcvq_bits & 0x20) != 0
5949 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5950 || (g_bit & 0x2) != 0)
5951 {
5952 inst.error = _("bad bitmask specified after APSR");
5953 return FAIL;
5954 }
5955 }
5956 else
477330fc 5957 {
d2cd1205 5958 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5959 p - start);
d2cd1205 5960 if (!psr)
477330fc 5961 goto error;
a737bd4d 5962
d2cd1205
JB
5963 psr_field |= psr->field;
5964 }
a737bd4d 5965 }
c19d1205 5966 else
a737bd4d 5967 {
c19d1205
ZW
5968 if (ISALNUM (*p))
5969 goto error; /* Garbage after "[CS]PSR". */
5970
d2cd1205 5971 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5972 is deprecated, but allow it anyway. */
d2cd1205
JB
5973 if (is_apsr && lhs)
5974 {
5975 psr_field |= PSR_f;
5976 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5977 "deprecated"));
5978 }
5979 else if (!m_profile)
5980 /* These bits are never right for M-profile devices: don't set them
5981 (only code paths which read/write APSR reach here). */
5982 psr_field |= (PSR_c | PSR_f);
a737bd4d 5983 }
c19d1205
ZW
5984 *str = p;
5985 return psr_field;
a737bd4d 5986
d2cd1205
JB
5987 unsupported_psr:
5988 inst.error = _("selected processor does not support requested special "
5989 "purpose register");
5990 return FAIL;
5991
c19d1205
ZW
5992 error:
5993 inst.error = _("flag for {c}psr instruction expected");
5994 return FAIL;
a737bd4d
NC
5995}
5996
c19d1205
ZW
5997/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5998 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5999
c19d1205
ZW
6000static int
6001parse_cps_flags (char **str)
a737bd4d 6002{
c19d1205
ZW
6003 int val = 0;
6004 int saw_a_flag = 0;
6005 char *s = *str;
a737bd4d 6006
c19d1205
ZW
6007 for (;;)
6008 switch (*s++)
6009 {
6010 case '\0': case ',':
6011 goto done;
a737bd4d 6012
c19d1205
ZW
6013 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6014 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6015 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6016
c19d1205
ZW
6017 default:
6018 inst.error = _("unrecognized CPS flag");
6019 return FAIL;
6020 }
a737bd4d 6021
c19d1205
ZW
6022 done:
6023 if (saw_a_flag == 0)
a737bd4d 6024 {
c19d1205
ZW
6025 inst.error = _("missing CPS flags");
6026 return FAIL;
a737bd4d 6027 }
a737bd4d 6028
c19d1205
ZW
6029 *str = s - 1;
6030 return val;
a737bd4d
NC
6031}
6032
c19d1205
ZW
6033/* Parse an endian specifier ("BE" or "LE", case insensitive);
6034 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6035
6036static int
c19d1205 6037parse_endian_specifier (char **str)
a737bd4d 6038{
c19d1205
ZW
6039 int little_endian;
6040 char *s = *str;
a737bd4d 6041
c19d1205
ZW
6042 if (strncasecmp (s, "BE", 2))
6043 little_endian = 0;
6044 else if (strncasecmp (s, "LE", 2))
6045 little_endian = 1;
6046 else
a737bd4d 6047 {
c19d1205 6048 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6049 return FAIL;
6050 }
6051
c19d1205 6052 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6053 {
c19d1205 6054 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6055 return FAIL;
6056 }
6057
c19d1205
ZW
6058 *str = s + 2;
6059 return little_endian;
6060}
a737bd4d 6061
c19d1205
ZW
6062/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6063 value suitable for poking into the rotate field of an sxt or sxta
6064 instruction, or FAIL on error. */
6065
6066static int
6067parse_ror (char **str)
6068{
6069 int rot;
6070 char *s = *str;
6071
6072 if (strncasecmp (s, "ROR", 3) == 0)
6073 s += 3;
6074 else
a737bd4d 6075 {
c19d1205 6076 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6077 return FAIL;
6078 }
c19d1205
ZW
6079
6080 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6081 return FAIL;
6082
6083 switch (rot)
a737bd4d 6084 {
c19d1205
ZW
6085 case 0: *str = s; return 0x0;
6086 case 8: *str = s; return 0x1;
6087 case 16: *str = s; return 0x2;
6088 case 24: *str = s; return 0x3;
6089
6090 default:
6091 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6092 return FAIL;
6093 }
c19d1205 6094}
a737bd4d 6095
c19d1205
ZW
6096/* Parse a conditional code (from conds[] below). The value returned is in the
6097 range 0 .. 14, or FAIL. */
6098static int
6099parse_cond (char **str)
6100{
c462b453 6101 char *q;
c19d1205 6102 const struct asm_cond *c;
c462b453
PB
6103 int n;
6104 /* Condition codes are always 2 characters, so matching up to
6105 3 characters is sufficient. */
6106 char cond[3];
a737bd4d 6107
c462b453
PB
6108 q = *str;
6109 n = 0;
6110 while (ISALPHA (*q) && n < 3)
6111 {
e07e6e58 6112 cond[n] = TOLOWER (*q);
c462b453
PB
6113 q++;
6114 n++;
6115 }
a737bd4d 6116
21d799b5 6117 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6118 if (!c)
a737bd4d 6119 {
c19d1205 6120 inst.error = _("condition required");
a737bd4d
NC
6121 return FAIL;
6122 }
6123
c19d1205
ZW
6124 *str = q;
6125 return c->value;
6126}
6127
643afb90
MW
6128/* Record a use of the given feature. */
6129static void
6130record_feature_use (const arm_feature_set *feature)
6131{
6132 if (thumb_mode)
6133 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6134 else
6135 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6136}
6137
e797f7e0
MGD
6138/* If the given feature available in the selected CPU, mark it as used.
6139 Returns TRUE iff feature is available. */
6140static bfd_boolean
6141mark_feature_used (const arm_feature_set *feature)
6142{
6143 /* Ensure the option is valid on the current architecture. */
6144 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6145 return FALSE;
6146
6147 /* Add the appropriate architecture feature for the barrier option used.
6148 */
643afb90 6149 record_feature_use (feature);
e797f7e0
MGD
6150
6151 return TRUE;
6152}
6153
62b3e311
PB
6154/* Parse an option for a barrier instruction. Returns the encoding for the
6155 option, or FAIL. */
6156static int
6157parse_barrier (char **str)
6158{
6159 char *p, *q;
6160 const struct asm_barrier_opt *o;
6161
6162 p = q = *str;
6163 while (ISALPHA (*q))
6164 q++;
6165
21d799b5 6166 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6167 q - p);
62b3e311
PB
6168 if (!o)
6169 return FAIL;
6170
e797f7e0
MGD
6171 if (!mark_feature_used (&o->arch))
6172 return FAIL;
6173
62b3e311
PB
6174 *str = q;
6175 return o->value;
6176}
6177
92e90b6e
PB
6178/* Parse the operands of a table branch instruction. Similar to a memory
6179 operand. */
6180static int
6181parse_tb (char **str)
6182{
6183 char * p = *str;
6184 int reg;
6185
6186 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6187 {
6188 inst.error = _("'[' expected");
6189 return FAIL;
6190 }
92e90b6e 6191
dcbf9037 6192 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6193 {
6194 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6195 return FAIL;
6196 }
6197 inst.operands[0].reg = reg;
6198
6199 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6200 {
6201 inst.error = _("',' expected");
6202 return FAIL;
6203 }
5f4273c7 6204
dcbf9037 6205 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6206 {
6207 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6208 return FAIL;
6209 }
6210 inst.operands[0].imm = reg;
6211
6212 if (skip_past_comma (&p) == SUCCESS)
6213 {
6214 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6215 return FAIL;
6216 if (inst.reloc.exp.X_add_number != 1)
6217 {
6218 inst.error = _("invalid shift");
6219 return FAIL;
6220 }
6221 inst.operands[0].shifted = 1;
6222 }
6223
6224 if (skip_past_char (&p, ']') == FAIL)
6225 {
6226 inst.error = _("']' expected");
6227 return FAIL;
6228 }
6229 *str = p;
6230 return SUCCESS;
6231}
6232
5287ad62
JB
6233/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6234 information on the types the operands can take and how they are encoded.
037e8744
JB
6235 Up to four operands may be read; this function handles setting the
6236 ".present" field for each read operand itself.
5287ad62
JB
6237 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6238 else returns FAIL. */
6239
6240static int
6241parse_neon_mov (char **str, int *which_operand)
6242{
6243 int i = *which_operand, val;
6244 enum arm_reg_type rtype;
6245 char *ptr = *str;
dcbf9037 6246 struct neon_type_el optype;
5f4273c7 6247
dcbf9037 6248 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6249 {
6250 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6251 inst.operands[i].reg = val;
6252 inst.operands[i].isscalar = 1;
dcbf9037 6253 inst.operands[i].vectype = optype;
5287ad62
JB
6254 inst.operands[i++].present = 1;
6255
6256 if (skip_past_comma (&ptr) == FAIL)
477330fc 6257 goto wanted_comma;
5f4273c7 6258
dcbf9037 6259 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6260 goto wanted_arm;
5f4273c7 6261
5287ad62
JB
6262 inst.operands[i].reg = val;
6263 inst.operands[i].isreg = 1;
6264 inst.operands[i].present = 1;
6265 }
037e8744 6266 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6267 != FAIL)
5287ad62
JB
6268 {
6269 /* Cases 0, 1, 2, 3, 5 (D only). */
6270 if (skip_past_comma (&ptr) == FAIL)
477330fc 6271 goto wanted_comma;
5f4273c7 6272
5287ad62
JB
6273 inst.operands[i].reg = val;
6274 inst.operands[i].isreg = 1;
6275 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6276 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6277 inst.operands[i].isvec = 1;
dcbf9037 6278 inst.operands[i].vectype = optype;
5287ad62
JB
6279 inst.operands[i++].present = 1;
6280
dcbf9037 6281 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6282 {
6283 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6284 Case 13: VMOV <Sd>, <Rm> */
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isreg = 1;
6287 inst.operands[i].present = 1;
6288
6289 if (rtype == REG_TYPE_NQ)
6290 {
6291 first_error (_("can't use Neon quad register here"));
6292 return FAIL;
6293 }
6294 else if (rtype != REG_TYPE_VFS)
6295 {
6296 i++;
6297 if (skip_past_comma (&ptr) == FAIL)
6298 goto wanted_comma;
6299 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6300 goto wanted_arm;
6301 inst.operands[i].reg = val;
6302 inst.operands[i].isreg = 1;
6303 inst.operands[i].present = 1;
6304 }
6305 }
037e8744 6306 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6307 &optype)) != FAIL)
6308 {
6309 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6310 Case 1: VMOV<c><q> <Dd>, <Dm>
6311 Case 8: VMOV.F32 <Sd>, <Sm>
6312 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6313
6314 inst.operands[i].reg = val;
6315 inst.operands[i].isreg = 1;
6316 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6317 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6318 inst.operands[i].isvec = 1;
6319 inst.operands[i].vectype = optype;
6320 inst.operands[i].present = 1;
6321
6322 if (skip_past_comma (&ptr) == SUCCESS)
6323 {
6324 /* Case 15. */
6325 i++;
6326
6327 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6328 goto wanted_arm;
6329
6330 inst.operands[i].reg = val;
6331 inst.operands[i].isreg = 1;
6332 inst.operands[i++].present = 1;
6333
6334 if (skip_past_comma (&ptr) == FAIL)
6335 goto wanted_comma;
6336
6337 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6338 goto wanted_arm;
6339
6340 inst.operands[i].reg = val;
6341 inst.operands[i].isreg = 1;
6342 inst.operands[i].present = 1;
6343 }
6344 }
4641781c 6345 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6346 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6347 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6348 Case 10: VMOV.F32 <Sd>, #<imm>
6349 Case 11: VMOV.F64 <Dd>, #<imm> */
6350 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6351 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6352 == SUCCESS)
477330fc
RM
6353 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6354 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6355 ;
5287ad62 6356 else
477330fc
RM
6357 {
6358 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6359 return FAIL;
6360 }
5287ad62 6361 }
dcbf9037 6362 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6363 {
6364 /* Cases 6, 7. */
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i++].present = 1;
5f4273c7 6368
5287ad62 6369 if (skip_past_comma (&ptr) == FAIL)
477330fc 6370 goto wanted_comma;
5f4273c7 6371
dcbf9037 6372 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6373 {
6374 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6375 inst.operands[i].reg = val;
6376 inst.operands[i].isscalar = 1;
6377 inst.operands[i].present = 1;
6378 inst.operands[i].vectype = optype;
6379 }
dcbf9037 6380 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6381 {
6382 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6383 inst.operands[i].reg = val;
6384 inst.operands[i].isreg = 1;
6385 inst.operands[i++].present = 1;
6386
6387 if (skip_past_comma (&ptr) == FAIL)
6388 goto wanted_comma;
6389
6390 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6391 == FAIL)
6392 {
6393 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6394 return FAIL;
6395 }
6396
6397 inst.operands[i].reg = val;
6398 inst.operands[i].isreg = 1;
6399 inst.operands[i].isvec = 1;
6400 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6401 inst.operands[i].vectype = optype;
6402 inst.operands[i].present = 1;
6403
6404 if (rtype == REG_TYPE_VFS)
6405 {
6406 /* Case 14. */
6407 i++;
6408 if (skip_past_comma (&ptr) == FAIL)
6409 goto wanted_comma;
6410 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6411 &optype)) == FAIL)
6412 {
6413 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6414 return FAIL;
6415 }
6416 inst.operands[i].reg = val;
6417 inst.operands[i].isreg = 1;
6418 inst.operands[i].isvec = 1;
6419 inst.operands[i].issingle = 1;
6420 inst.operands[i].vectype = optype;
6421 inst.operands[i].present = 1;
6422 }
6423 }
037e8744 6424 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6425 != FAIL)
6426 {
6427 /* Case 13. */
6428 inst.operands[i].reg = val;
6429 inst.operands[i].isreg = 1;
6430 inst.operands[i].isvec = 1;
6431 inst.operands[i].issingle = 1;
6432 inst.operands[i].vectype = optype;
6433 inst.operands[i].present = 1;
6434 }
5287ad62
JB
6435 }
6436 else
6437 {
dcbf9037 6438 first_error (_("parse error"));
5287ad62
JB
6439 return FAIL;
6440 }
6441
6442 /* Successfully parsed the operands. Update args. */
6443 *which_operand = i;
6444 *str = ptr;
6445 return SUCCESS;
6446
5f4273c7 6447 wanted_comma:
dcbf9037 6448 first_error (_("expected comma"));
5287ad62 6449 return FAIL;
5f4273c7
NC
6450
6451 wanted_arm:
dcbf9037 6452 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6453 return FAIL;
5287ad62
JB
6454}
6455
5be8be5d
DG
6456/* Use this macro when the operand constraints are different
6457 for ARM and THUMB (e.g. ldrd). */
6458#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6459 ((arm_operand) | ((thumb_operand) << 16))
6460
c19d1205
ZW
6461/* Matcher codes for parse_operands. */
6462enum operand_parse_code
6463{
6464 OP_stop, /* end of line */
6465
6466 OP_RR, /* ARM register */
6467 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6468 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6469 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6470 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6471 optional trailing ! */
c19d1205
ZW
6472 OP_RRw, /* ARM register, not r15, optional trailing ! */
6473 OP_RCP, /* Coprocessor number */
6474 OP_RCN, /* Coprocessor register */
6475 OP_RF, /* FPA register */
6476 OP_RVS, /* VFP single precision register */
5287ad62
JB
6477 OP_RVD, /* VFP double precision register (0..15) */
6478 OP_RND, /* Neon double precision register (0..31) */
6479 OP_RNQ, /* Neon quad precision register */
037e8744 6480 OP_RVSD, /* VFP single or double precision register */
5287ad62 6481 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6482 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6483 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6484 OP_RVC, /* VFP control register */
6485 OP_RMF, /* Maverick F register */
6486 OP_RMD, /* Maverick D register */
6487 OP_RMFX, /* Maverick FX register */
6488 OP_RMDX, /* Maverick DX register */
6489 OP_RMAX, /* Maverick AX register */
6490 OP_RMDS, /* Maverick DSPSC register */
6491 OP_RIWR, /* iWMMXt wR register */
6492 OP_RIWC, /* iWMMXt wC register */
6493 OP_RIWG, /* iWMMXt wCG register */
6494 OP_RXA, /* XScale accumulator register */
6495
6496 OP_REGLST, /* ARM register list */
6497 OP_VRSLST, /* VFP single-precision register list */
6498 OP_VRDLST, /* VFP double-precision register list */
037e8744 6499 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6500 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6501 OP_NSTRLST, /* Neon element/structure list */
6502
5287ad62 6503 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6504 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6505 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6506 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6507 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6508 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6509 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6510 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6511 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6512 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6513 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6514
6515 OP_I0, /* immediate zero */
c19d1205
ZW
6516 OP_I7, /* immediate value 0 .. 7 */
6517 OP_I15, /* 0 .. 15 */
6518 OP_I16, /* 1 .. 16 */
5287ad62 6519 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6520 OP_I31, /* 0 .. 31 */
6521 OP_I31w, /* 0 .. 31, optional trailing ! */
6522 OP_I32, /* 1 .. 32 */
5287ad62
JB
6523 OP_I32z, /* 0 .. 32 */
6524 OP_I63, /* 0 .. 63 */
c19d1205 6525 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6526 OP_I64, /* 1 .. 64 */
6527 OP_I64z, /* 0 .. 64 */
c19d1205 6528 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6529
6530 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6531 OP_I7b, /* 0 .. 7 */
6532 OP_I15b, /* 0 .. 15 */
6533 OP_I31b, /* 0 .. 31 */
6534
6535 OP_SH, /* shifter operand */
4962c51a 6536 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6537 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6538 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6539 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6540 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6541 OP_EXP, /* arbitrary expression */
6542 OP_EXPi, /* same, with optional immediate prefix */
6543 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6544 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6545 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6546 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6547
6548 OP_CPSF, /* CPS flags */
6549 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6550 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6551 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6552 OP_COND, /* conditional code */
92e90b6e 6553 OP_TB, /* Table branch. */
c19d1205 6554
037e8744
JB
6555 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6556
c19d1205 6557 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6558 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6559 OP_RR_EXi, /* ARM register or expression with imm prefix */
6560 OP_RF_IF, /* FPA register or immediate */
6561 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6562 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6563
6564 /* Optional operands. */
6565 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6566 OP_oI31b, /* 0 .. 31 */
5287ad62 6567 OP_oI32b, /* 1 .. 32 */
5f1af56b 6568 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6569 OP_oIffffb, /* 0 .. 65535 */
6570 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6571
6572 OP_oRR, /* ARM register */
6573 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6574 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6575 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6576 OP_oRND, /* Optional Neon double precision register */
6577 OP_oRNQ, /* Optional Neon quad precision register */
6578 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6579 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6580 OP_oSHll, /* LSL immediate */
6581 OP_oSHar, /* ASR immediate */
6582 OP_oSHllar, /* LSL or ASR immediate */
6583 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6584 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6585
5be8be5d
DG
6586 /* Some pre-defined mixed (ARM/THUMB) operands. */
6587 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6588 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6589 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6590
c19d1205
ZW
6591 OP_FIRST_OPTIONAL = OP_oI7b
6592};
a737bd4d 6593
c19d1205
ZW
6594/* Generic instruction operand parser. This does no encoding and no
6595 semantic validation; it merely squirrels values away in the inst
6596 structure. Returns SUCCESS or FAIL depending on whether the
6597 specified grammar matched. */
6598static int
5be8be5d 6599parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6600{
5be8be5d 6601 unsigned const int *upat = pattern;
c19d1205
ZW
6602 char *backtrack_pos = 0;
6603 const char *backtrack_error = 0;
99aad254 6604 int i, val = 0, backtrack_index = 0;
5287ad62 6605 enum arm_reg_type rtype;
4962c51a 6606 parse_operand_result result;
5be8be5d 6607 unsigned int op_parse_code;
c19d1205 6608
e07e6e58
NC
6609#define po_char_or_fail(chr) \
6610 do \
6611 { \
6612 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6613 goto bad_args; \
e07e6e58
NC
6614 } \
6615 while (0)
c19d1205 6616
e07e6e58
NC
6617#define po_reg_or_fail(regtype) \
6618 do \
dcbf9037 6619 { \
e07e6e58 6620 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6621 & inst.operands[i].vectype); \
e07e6e58 6622 if (val == FAIL) \
477330fc
RM
6623 { \
6624 first_error (_(reg_expected_msgs[regtype])); \
6625 goto failure; \
6626 } \
e07e6e58
NC
6627 inst.operands[i].reg = val; \
6628 inst.operands[i].isreg = 1; \
6629 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6630 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6631 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6632 || rtype == REG_TYPE_VFD \
6633 || rtype == REG_TYPE_NQ); \
dcbf9037 6634 } \
e07e6e58
NC
6635 while (0)
6636
6637#define po_reg_or_goto(regtype, label) \
6638 do \
6639 { \
6640 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6641 & inst.operands[i].vectype); \
6642 if (val == FAIL) \
6643 goto label; \
dcbf9037 6644 \
e07e6e58
NC
6645 inst.operands[i].reg = val; \
6646 inst.operands[i].isreg = 1; \
6647 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6648 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6649 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6650 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6651 || rtype == REG_TYPE_NQ); \
6652 } \
6653 while (0)
6654
6655#define po_imm_or_fail(min, max, popt) \
6656 do \
6657 { \
6658 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6659 goto failure; \
6660 inst.operands[i].imm = val; \
6661 } \
6662 while (0)
6663
6664#define po_scalar_or_goto(elsz, label) \
6665 do \
6666 { \
6667 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6668 if (val == FAIL) \
6669 goto label; \
6670 inst.operands[i].reg = val; \
6671 inst.operands[i].isscalar = 1; \
6672 } \
6673 while (0)
6674
6675#define po_misc_or_fail(expr) \
6676 do \
6677 { \
6678 if (expr) \
6679 goto failure; \
6680 } \
6681 while (0)
6682
6683#define po_misc_or_fail_no_backtrack(expr) \
6684 do \
6685 { \
6686 result = expr; \
6687 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6688 backtrack_pos = 0; \
6689 if (result != PARSE_OPERAND_SUCCESS) \
6690 goto failure; \
6691 } \
6692 while (0)
4962c51a 6693
52e7f43d
RE
6694#define po_barrier_or_imm(str) \
6695 do \
6696 { \
6697 val = parse_barrier (&str); \
ccb84d65
JB
6698 if (val == FAIL && ! ISALPHA (*str)) \
6699 goto immediate; \
6700 if (val == FAIL \
6701 /* ISB can only take SY as an option. */ \
6702 || ((inst.instruction & 0xf0) == 0x60 \
6703 && val != 0xf)) \
52e7f43d 6704 { \
ccb84d65
JB
6705 inst.error = _("invalid barrier type"); \
6706 backtrack_pos = 0; \
6707 goto failure; \
52e7f43d
RE
6708 } \
6709 } \
6710 while (0)
6711
c19d1205
ZW
6712 skip_whitespace (str);
6713
6714 for (i = 0; upat[i] != OP_stop; i++)
6715 {
5be8be5d
DG
6716 op_parse_code = upat[i];
6717 if (op_parse_code >= 1<<16)
6718 op_parse_code = thumb ? (op_parse_code >> 16)
6719 : (op_parse_code & ((1<<16)-1));
6720
6721 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6722 {
6723 /* Remember where we are in case we need to backtrack. */
9c2799c2 6724 gas_assert (!backtrack_pos);
c19d1205
ZW
6725 backtrack_pos = str;
6726 backtrack_error = inst.error;
6727 backtrack_index = i;
6728 }
6729
b6702015 6730 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6731 po_char_or_fail (',');
6732
5be8be5d 6733 switch (op_parse_code)
c19d1205
ZW
6734 {
6735 /* Registers */
6736 case OP_oRRnpc:
5be8be5d 6737 case OP_oRRnpcsp:
c19d1205 6738 case OP_RRnpc:
5be8be5d 6739 case OP_RRnpcsp:
c19d1205
ZW
6740 case OP_oRR:
6741 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6742 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6743 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6744 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6745 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6746 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6747 case OP_oRND:
5287ad62 6748 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6749 case OP_RVC:
6750 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6751 break;
6752 /* Also accept generic coprocessor regs for unknown registers. */
6753 coproc_reg:
6754 po_reg_or_fail (REG_TYPE_CN);
6755 break;
c19d1205
ZW
6756 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6757 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6758 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6759 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6760 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6761 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6762 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6763 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6764 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6765 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6766 case OP_oRNQ:
5287ad62 6767 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6768 case OP_oRNDQ:
5287ad62 6769 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6770 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6771 case OP_oRNSDQ:
6772 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6773
6774 /* Neon scalar. Using an element size of 8 means that some invalid
6775 scalars are accepted here, so deal with those in later code. */
6776 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6777
6778 case OP_RNDQ_I0:
6779 {
6780 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6781 break;
6782 try_imm0:
6783 po_imm_or_fail (0, 0, TRUE);
6784 }
6785 break;
6786
6787 case OP_RVSD_I0:
6788 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6789 break;
6790
aacf0b33
KT
6791 case OP_RSVD_FI0:
6792 {
6793 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6794 break;
6795 try_ifimm0:
6796 if (parse_ifimm_zero (&str))
6797 inst.operands[i].imm = 0;
6798 else
6799 {
6800 inst.error
6801 = _("only floating point zero is allowed as immediate value");
6802 goto failure;
6803 }
6804 }
6805 break;
6806
477330fc
RM
6807 case OP_RR_RNSC:
6808 {
6809 po_scalar_or_goto (8, try_rr);
6810 break;
6811 try_rr:
6812 po_reg_or_fail (REG_TYPE_RN);
6813 }
6814 break;
6815
6816 case OP_RNSDQ_RNSC:
6817 {
6818 po_scalar_or_goto (8, try_nsdq);
6819 break;
6820 try_nsdq:
6821 po_reg_or_fail (REG_TYPE_NSDQ);
6822 }
6823 break;
6824
6825 case OP_RNDQ_RNSC:
6826 {
6827 po_scalar_or_goto (8, try_ndq);
6828 break;
6829 try_ndq:
6830 po_reg_or_fail (REG_TYPE_NDQ);
6831 }
6832 break;
6833
6834 case OP_RND_RNSC:
6835 {
6836 po_scalar_or_goto (8, try_vfd);
6837 break;
6838 try_vfd:
6839 po_reg_or_fail (REG_TYPE_VFD);
6840 }
6841 break;
6842
6843 case OP_VMOV:
6844 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6845 not careful then bad things might happen. */
6846 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6847 break;
6848
6849 case OP_RNDQ_Ibig:
6850 {
6851 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6852 break;
6853 try_immbig:
6854 /* There's a possibility of getting a 64-bit immediate here, so
6855 we need special handling. */
8335d6aa
JW
6856 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6857 == FAIL)
477330fc
RM
6858 {
6859 inst.error = _("immediate value is out of range");
6860 goto failure;
6861 }
6862 }
6863 break;
6864
6865 case OP_RNDQ_I63b:
6866 {
6867 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6868 break;
6869 try_shimm:
6870 po_imm_or_fail (0, 63, TRUE);
6871 }
6872 break;
c19d1205
ZW
6873
6874 case OP_RRnpcb:
6875 po_char_or_fail ('[');
6876 po_reg_or_fail (REG_TYPE_RN);
6877 po_char_or_fail (']');
6878 break;
a737bd4d 6879
55881a11 6880 case OP_RRnpctw:
c19d1205 6881 case OP_RRw:
b6702015 6882 case OP_oRRw:
c19d1205
ZW
6883 po_reg_or_fail (REG_TYPE_RN);
6884 if (skip_past_char (&str, '!') == SUCCESS)
6885 inst.operands[i].writeback = 1;
6886 break;
6887
6888 /* Immediates */
6889 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6890 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6891 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6892 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6893 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6894 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6895 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6896 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6897 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6898 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6899 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6900 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6901
6902 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6903 case OP_oI7b:
6904 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6905 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6906 case OP_oI31b:
6907 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6908 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6909 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6910 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6911
6912 /* Immediate variants */
6913 case OP_oI255c:
6914 po_char_or_fail ('{');
6915 po_imm_or_fail (0, 255, TRUE);
6916 po_char_or_fail ('}');
6917 break;
6918
6919 case OP_I31w:
6920 /* The expression parser chokes on a trailing !, so we have
6921 to find it first and zap it. */
6922 {
6923 char *s = str;
6924 while (*s && *s != ',')
6925 s++;
6926 if (s[-1] == '!')
6927 {
6928 s[-1] = '\0';
6929 inst.operands[i].writeback = 1;
6930 }
6931 po_imm_or_fail (0, 31, TRUE);
6932 if (str == s - 1)
6933 str = s;
6934 }
6935 break;
6936
6937 /* Expressions */
6938 case OP_EXPi: EXPi:
6939 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6940 GE_OPT_PREFIX));
6941 break;
6942
6943 case OP_EXP:
6944 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6945 GE_NO_PREFIX));
6946 break;
6947
6948 case OP_EXPr: EXPr:
6949 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6950 GE_NO_PREFIX));
6951 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6952 {
c19d1205
ZW
6953 val = parse_reloc (&str);
6954 if (val == -1)
6955 {
6956 inst.error = _("unrecognized relocation suffix");
6957 goto failure;
6958 }
6959 else if (val != BFD_RELOC_UNUSED)
6960 {
6961 inst.operands[i].imm = val;
6962 inst.operands[i].hasreloc = 1;
6963 }
a737bd4d 6964 }
c19d1205 6965 break;
a737bd4d 6966
b6895b4f
PB
6967 /* Operand for MOVW or MOVT. */
6968 case OP_HALF:
6969 po_misc_or_fail (parse_half (&str));
6970 break;
6971
e07e6e58 6972 /* Register or expression. */
c19d1205
ZW
6973 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6974 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6975
e07e6e58 6976 /* Register or immediate. */
c19d1205
ZW
6977 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6978 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6979
c19d1205
ZW
6980 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6981 IF:
6982 if (!is_immediate_prefix (*str))
6983 goto bad_args;
6984 str++;
6985 val = parse_fpa_immediate (&str);
6986 if (val == FAIL)
6987 goto failure;
6988 /* FPA immediates are encoded as registers 8-15.
6989 parse_fpa_immediate has already applied the offset. */
6990 inst.operands[i].reg = val;
6991 inst.operands[i].isreg = 1;
6992 break;
09d92015 6993
2d447fca
JM
6994 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6995 I32z: po_imm_or_fail (0, 32, FALSE); break;
6996
e07e6e58 6997 /* Two kinds of register. */
c19d1205
ZW
6998 case OP_RIWR_RIWC:
6999 {
7000 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7001 if (!rege
7002 || (rege->type != REG_TYPE_MMXWR
7003 && rege->type != REG_TYPE_MMXWC
7004 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7005 {
7006 inst.error = _("iWMMXt data or control register expected");
7007 goto failure;
7008 }
7009 inst.operands[i].reg = rege->number;
7010 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7011 }
7012 break;
09d92015 7013
41adaa5c
JM
7014 case OP_RIWC_RIWG:
7015 {
7016 struct reg_entry *rege = arm_reg_parse_multi (&str);
7017 if (!rege
7018 || (rege->type != REG_TYPE_MMXWC
7019 && rege->type != REG_TYPE_MMXWCG))
7020 {
7021 inst.error = _("iWMMXt control register expected");
7022 goto failure;
7023 }
7024 inst.operands[i].reg = rege->number;
7025 inst.operands[i].isreg = 1;
7026 }
7027 break;
7028
c19d1205
ZW
7029 /* Misc */
7030 case OP_CPSF: val = parse_cps_flags (&str); break;
7031 case OP_ENDI: val = parse_endian_specifier (&str); break;
7032 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7033 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7034 case OP_oBARRIER_I15:
7035 po_barrier_or_imm (str); break;
7036 immediate:
7037 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7038 goto failure;
52e7f43d 7039 break;
c19d1205 7040
fa94de6b 7041 case OP_wPSR:
d2cd1205 7042 case OP_rPSR:
90ec0d68
MGD
7043 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7044 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7045 {
7046 inst.error = _("Banked registers are not available with this "
7047 "architecture.");
7048 goto failure;
7049 }
7050 break;
d2cd1205
JB
7051 try_psr:
7052 val = parse_psr (&str, op_parse_code == OP_wPSR);
7053 break;
037e8744 7054
477330fc
RM
7055 case OP_APSR_RR:
7056 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7057 break;
7058 try_apsr:
7059 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7060 instruction). */
7061 if (strncasecmp (str, "APSR_", 5) == 0)
7062 {
7063 unsigned found = 0;
7064 str += 5;
7065 while (found < 15)
7066 switch (*str++)
7067 {
7068 case 'c': found = (found & 1) ? 16 : found | 1; break;
7069 case 'n': found = (found & 2) ? 16 : found | 2; break;
7070 case 'z': found = (found & 4) ? 16 : found | 4; break;
7071 case 'v': found = (found & 8) ? 16 : found | 8; break;
7072 default: found = 16;
7073 }
7074 if (found != 15)
7075 goto failure;
7076 inst.operands[i].isvec = 1;
f7c21dc7
NC
7077 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7078 inst.operands[i].reg = REG_PC;
477330fc
RM
7079 }
7080 else
7081 goto failure;
7082 break;
037e8744 7083
92e90b6e
PB
7084 case OP_TB:
7085 po_misc_or_fail (parse_tb (&str));
7086 break;
7087
e07e6e58 7088 /* Register lists. */
c19d1205
ZW
7089 case OP_REGLST:
7090 val = parse_reg_list (&str);
7091 if (*str == '^')
7092 {
5e0d7f77 7093 inst.operands[i].writeback = 1;
c19d1205
ZW
7094 str++;
7095 }
7096 break;
09d92015 7097
c19d1205 7098 case OP_VRSLST:
5287ad62 7099 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7100 break;
09d92015 7101
c19d1205 7102 case OP_VRDLST:
5287ad62 7103 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7104 break;
a737bd4d 7105
477330fc
RM
7106 case OP_VRSDLST:
7107 /* Allow Q registers too. */
7108 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7109 REGLIST_NEON_D);
7110 if (val == FAIL)
7111 {
7112 inst.error = NULL;
7113 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7114 REGLIST_VFP_S);
7115 inst.operands[i].issingle = 1;
7116 }
7117 break;
7118
7119 case OP_NRDLST:
7120 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7121 REGLIST_NEON_D);
7122 break;
5287ad62
JB
7123
7124 case OP_NSTRLST:
477330fc
RM
7125 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7126 &inst.operands[i].vectype);
7127 break;
5287ad62 7128
c19d1205
ZW
7129 /* Addressing modes */
7130 case OP_ADDR:
7131 po_misc_or_fail (parse_address (&str, i));
7132 break;
09d92015 7133
4962c51a
MS
7134 case OP_ADDRGLDR:
7135 po_misc_or_fail_no_backtrack (
477330fc 7136 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7137 break;
7138
7139 case OP_ADDRGLDRS:
7140 po_misc_or_fail_no_backtrack (
477330fc 7141 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7142 break;
7143
7144 case OP_ADDRGLDC:
7145 po_misc_or_fail_no_backtrack (
477330fc 7146 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7147 break;
7148
c19d1205
ZW
7149 case OP_SH:
7150 po_misc_or_fail (parse_shifter_operand (&str, i));
7151 break;
09d92015 7152
4962c51a
MS
7153 case OP_SHG:
7154 po_misc_or_fail_no_backtrack (
477330fc 7155 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7156 break;
7157
c19d1205
ZW
7158 case OP_oSHll:
7159 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7160 break;
09d92015 7161
c19d1205
ZW
7162 case OP_oSHar:
7163 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7164 break;
09d92015 7165
c19d1205
ZW
7166 case OP_oSHllar:
7167 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7168 break;
09d92015 7169
c19d1205 7170 default:
5be8be5d 7171 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7172 }
09d92015 7173
c19d1205
ZW
7174 /* Various value-based sanity checks and shared operations. We
7175 do not signal immediate failures for the register constraints;
7176 this allows a syntax error to take precedence. */
5be8be5d 7177 switch (op_parse_code)
c19d1205
ZW
7178 {
7179 case OP_oRRnpc:
7180 case OP_RRnpc:
7181 case OP_RRnpcb:
7182 case OP_RRw:
b6702015 7183 case OP_oRRw:
c19d1205
ZW
7184 case OP_RRnpc_I0:
7185 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7186 inst.error = BAD_PC;
7187 break;
09d92015 7188
5be8be5d
DG
7189 case OP_oRRnpcsp:
7190 case OP_RRnpcsp:
7191 if (inst.operands[i].isreg)
7192 {
7193 if (inst.operands[i].reg == REG_PC)
7194 inst.error = BAD_PC;
5c8ed6a4
JW
7195 else if (inst.operands[i].reg == REG_SP
7196 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7197 relaxed since ARMv8-A. */
7198 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7199 {
7200 gas_assert (thumb);
7201 inst.error = BAD_SP;
7202 }
5be8be5d
DG
7203 }
7204 break;
7205
55881a11 7206 case OP_RRnpctw:
fa94de6b
RM
7207 if (inst.operands[i].isreg
7208 && inst.operands[i].reg == REG_PC
55881a11
MGD
7209 && (inst.operands[i].writeback || thumb))
7210 inst.error = BAD_PC;
7211 break;
7212
c19d1205
ZW
7213 case OP_CPSF:
7214 case OP_ENDI:
7215 case OP_oROR:
d2cd1205
JB
7216 case OP_wPSR:
7217 case OP_rPSR:
c19d1205 7218 case OP_COND:
52e7f43d 7219 case OP_oBARRIER_I15:
c19d1205
ZW
7220 case OP_REGLST:
7221 case OP_VRSLST:
7222 case OP_VRDLST:
477330fc
RM
7223 case OP_VRSDLST:
7224 case OP_NRDLST:
7225 case OP_NSTRLST:
c19d1205
ZW
7226 if (val == FAIL)
7227 goto failure;
7228 inst.operands[i].imm = val;
7229 break;
a737bd4d 7230
c19d1205
ZW
7231 default:
7232 break;
7233 }
09d92015 7234
c19d1205
ZW
7235 /* If we get here, this operand was successfully parsed. */
7236 inst.operands[i].present = 1;
7237 continue;
09d92015 7238
c19d1205 7239 bad_args:
09d92015 7240 inst.error = BAD_ARGS;
c19d1205
ZW
7241
7242 failure:
7243 if (!backtrack_pos)
d252fdde
PB
7244 {
7245 /* The parse routine should already have set inst.error, but set a
5f4273c7 7246 default here just in case. */
d252fdde
PB
7247 if (!inst.error)
7248 inst.error = _("syntax error");
7249 return FAIL;
7250 }
c19d1205
ZW
7251
7252 /* Do not backtrack over a trailing optional argument that
7253 absorbed some text. We will only fail again, with the
7254 'garbage following instruction' error message, which is
7255 probably less helpful than the current one. */
7256 if (backtrack_index == i && backtrack_pos != str
7257 && upat[i+1] == OP_stop)
d252fdde
PB
7258 {
7259 if (!inst.error)
7260 inst.error = _("syntax error");
7261 return FAIL;
7262 }
c19d1205
ZW
7263
7264 /* Try again, skipping the optional argument at backtrack_pos. */
7265 str = backtrack_pos;
7266 inst.error = backtrack_error;
7267 inst.operands[backtrack_index].present = 0;
7268 i = backtrack_index;
7269 backtrack_pos = 0;
09d92015 7270 }
09d92015 7271
c19d1205
ZW
7272 /* Check that we have parsed all the arguments. */
7273 if (*str != '\0' && !inst.error)
7274 inst.error = _("garbage following instruction");
09d92015 7275
c19d1205 7276 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7277}
7278
c19d1205
ZW
7279#undef po_char_or_fail
7280#undef po_reg_or_fail
7281#undef po_reg_or_goto
7282#undef po_imm_or_fail
5287ad62 7283#undef po_scalar_or_fail
52e7f43d 7284#undef po_barrier_or_imm
e07e6e58 7285
c19d1205 7286/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7287#define constraint(expr, err) \
7288 do \
c19d1205 7289 { \
e07e6e58
NC
7290 if (expr) \
7291 { \
7292 inst.error = err; \
7293 return; \
7294 } \
c19d1205 7295 } \
e07e6e58 7296 while (0)
c19d1205 7297
fdfde340
JM
7298/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7299 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7300 is the BadReg predicate in ARM's Thumb-2 documentation.
7301
7302 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7303 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7304#define reject_bad_reg(reg) \
7305 do \
7306 if (reg == REG_PC) \
7307 { \
7308 inst.error = BAD_PC; \
7309 return; \
7310 } \
7311 else if (reg == REG_SP \
7312 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7313 { \
7314 inst.error = BAD_SP; \
7315 return; \
7316 } \
fdfde340
JM
7317 while (0)
7318
94206790
MM
7319/* If REG is R13 (the stack pointer), warn that its use is
7320 deprecated. */
7321#define warn_deprecated_sp(reg) \
7322 do \
7323 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7324 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7325 while (0)
7326
c19d1205
ZW
7327/* Functions for operand encoding. ARM, then Thumb. */
7328
d840c081 7329#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7330
9db2f6b4
RL
7331/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7332
7333 The only binary encoding difference is the Coprocessor number. Coprocessor
7334 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7335 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7336 exists for Single-Precision operation. */
7337
7338static void
7339do_scalar_fp16_v82_encode (void)
7340{
7341 if (inst.cond != COND_ALWAYS)
7342 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7343 " the behaviour is UNPREDICTABLE"));
7344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7345 _(BAD_FP16));
7346
7347 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7348 mark_feature_used (&arm_ext_fp16);
7349}
7350
c19d1205
ZW
7351/* If VAL can be encoded in the immediate field of an ARM instruction,
7352 return the encoded form. Otherwise, return FAIL. */
7353
7354static unsigned int
7355encode_arm_immediate (unsigned int val)
09d92015 7356{
c19d1205
ZW
7357 unsigned int a, i;
7358
4f1d6205
L
7359 if (val <= 0xff)
7360 return val;
7361
7362 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7363 if ((a = rotate_left (val, i)) <= 0xff)
7364 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7365
7366 return FAIL;
09d92015
MM
7367}
7368
c19d1205
ZW
7369/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7370 return the encoded form. Otherwise, return FAIL. */
7371static unsigned int
7372encode_thumb32_immediate (unsigned int val)
09d92015 7373{
c19d1205 7374 unsigned int a, i;
09d92015 7375
9c3c69f2 7376 if (val <= 0xff)
c19d1205 7377 return val;
a737bd4d 7378
9c3c69f2 7379 for (i = 1; i <= 24; i++)
09d92015 7380 {
9c3c69f2
PB
7381 a = val >> i;
7382 if ((val & ~(0xff << i)) == 0)
7383 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7384 }
a737bd4d 7385
c19d1205
ZW
7386 a = val & 0xff;
7387 if (val == ((a << 16) | a))
7388 return 0x100 | a;
7389 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7390 return 0x300 | a;
09d92015 7391
c19d1205
ZW
7392 a = val & 0xff00;
7393 if (val == ((a << 16) | a))
7394 return 0x200 | (a >> 8);
a737bd4d 7395
c19d1205 7396 return FAIL;
09d92015 7397}
5287ad62 7398/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7399
7400static void
5287ad62
JB
7401encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7402{
7403 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7404 && reg > 15)
7405 {
b1cc4aeb 7406 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7407 {
7408 if (thumb_mode)
7409 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7410 fpu_vfp_ext_d32);
7411 else
7412 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7413 fpu_vfp_ext_d32);
7414 }
5287ad62 7415 else
477330fc
RM
7416 {
7417 first_error (_("D register out of range for selected VFP version"));
7418 return;
7419 }
5287ad62
JB
7420 }
7421
c19d1205 7422 switch (pos)
09d92015 7423 {
c19d1205
ZW
7424 case VFP_REG_Sd:
7425 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7426 break;
7427
7428 case VFP_REG_Sn:
7429 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7430 break;
7431
7432 case VFP_REG_Sm:
7433 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7434 break;
7435
5287ad62
JB
7436 case VFP_REG_Dd:
7437 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7438 break;
5f4273c7 7439
5287ad62
JB
7440 case VFP_REG_Dn:
7441 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7442 break;
5f4273c7 7443
5287ad62
JB
7444 case VFP_REG_Dm:
7445 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7446 break;
7447
c19d1205
ZW
7448 default:
7449 abort ();
09d92015 7450 }
09d92015
MM
7451}
7452
c19d1205 7453/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7454 if any, is handled by md_apply_fix. */
09d92015 7455static void
c19d1205 7456encode_arm_shift (int i)
09d92015 7457{
008a97ef
RL
7458 /* register-shifted register. */
7459 if (inst.operands[i].immisreg)
7460 {
bf355b69
MR
7461 int op_index;
7462 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7463 {
5689c942
RL
7464 /* Check the operand only when it's presented. In pre-UAL syntax,
7465 if the destination register is the same as the first operand, two
7466 register form of the instruction can be used. */
bf355b69
MR
7467 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7468 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7469 as_warn (UNPRED_REG ("r15"));
7470 }
7471
7472 if (inst.operands[i].imm == REG_PC)
7473 as_warn (UNPRED_REG ("r15"));
7474 }
7475
c19d1205
ZW
7476 if (inst.operands[i].shift_kind == SHIFT_RRX)
7477 inst.instruction |= SHIFT_ROR << 5;
7478 else
09d92015 7479 {
c19d1205
ZW
7480 inst.instruction |= inst.operands[i].shift_kind << 5;
7481 if (inst.operands[i].immisreg)
7482 {
7483 inst.instruction |= SHIFT_BY_REG;
7484 inst.instruction |= inst.operands[i].imm << 8;
7485 }
7486 else
7487 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7488 }
c19d1205 7489}
09d92015 7490
c19d1205
ZW
7491static void
7492encode_arm_shifter_operand (int i)
7493{
7494 if (inst.operands[i].isreg)
09d92015 7495 {
c19d1205
ZW
7496 inst.instruction |= inst.operands[i].reg;
7497 encode_arm_shift (i);
09d92015 7498 }
c19d1205 7499 else
a415b1cd
JB
7500 {
7501 inst.instruction |= INST_IMMEDIATE;
7502 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7503 inst.instruction |= inst.operands[i].imm;
7504 }
09d92015
MM
7505}
7506
c19d1205 7507/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7508static void
c19d1205 7509encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7510{
2b2f5df9
NC
7511 /* PR 14260:
7512 Generate an error if the operand is not a register. */
7513 constraint (!inst.operands[i].isreg,
7514 _("Instruction does not support =N addresses"));
7515
c19d1205 7516 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7517
c19d1205 7518 if (inst.operands[i].preind)
09d92015 7519 {
c19d1205
ZW
7520 if (is_t)
7521 {
7522 inst.error = _("instruction does not accept preindexed addressing");
7523 return;
7524 }
7525 inst.instruction |= PRE_INDEX;
7526 if (inst.operands[i].writeback)
7527 inst.instruction |= WRITE_BACK;
09d92015 7528
c19d1205
ZW
7529 }
7530 else if (inst.operands[i].postind)
7531 {
9c2799c2 7532 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7533 if (is_t)
7534 inst.instruction |= WRITE_BACK;
7535 }
7536 else /* unindexed - only for coprocessor */
09d92015 7537 {
c19d1205 7538 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7539 return;
7540 }
7541
c19d1205
ZW
7542 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7543 && (((inst.instruction & 0x000f0000) >> 16)
7544 == ((inst.instruction & 0x0000f000) >> 12)))
7545 as_warn ((inst.instruction & LOAD_BIT)
7546 ? _("destination register same as write-back base")
7547 : _("source register same as write-back base"));
09d92015
MM
7548}
7549
c19d1205
ZW
7550/* inst.operands[i] was set up by parse_address. Encode it into an
7551 ARM-format mode 2 load or store instruction. If is_t is true,
7552 reject forms that cannot be used with a T instruction (i.e. not
7553 post-indexed). */
a737bd4d 7554static void
c19d1205 7555encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7556{
5be8be5d
DG
7557 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7558
c19d1205 7559 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7560
c19d1205 7561 if (inst.operands[i].immisreg)
09d92015 7562 {
5be8be5d
DG
7563 constraint ((inst.operands[i].imm == REG_PC
7564 || (is_pc && inst.operands[i].writeback)),
7565 BAD_PC_ADDRESSING);
c19d1205
ZW
7566 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7567 inst.instruction |= inst.operands[i].imm;
7568 if (!inst.operands[i].negative)
7569 inst.instruction |= INDEX_UP;
7570 if (inst.operands[i].shifted)
7571 {
7572 if (inst.operands[i].shift_kind == SHIFT_RRX)
7573 inst.instruction |= SHIFT_ROR << 5;
7574 else
7575 {
7576 inst.instruction |= inst.operands[i].shift_kind << 5;
7577 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7578 }
7579 }
09d92015 7580 }
c19d1205 7581 else /* immediate offset in inst.reloc */
09d92015 7582 {
5be8be5d
DG
7583 if (is_pc && !inst.reloc.pc_rel)
7584 {
7585 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7586
7587 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7588 cannot use PC in addressing.
7589 PC cannot be used in writeback addressing, either. */
7590 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7591 BAD_PC_ADDRESSING);
23a10334 7592
dc5ec521 7593 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7594 if (warn_on_deprecated
7595 && !is_load
7596 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7597 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7598 }
7599
c19d1205 7600 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7601 {
7602 /* Prefer + for zero encoded value. */
7603 if (!inst.operands[i].negative)
7604 inst.instruction |= INDEX_UP;
7605 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7606 }
09d92015 7607 }
09d92015
MM
7608}
7609
c19d1205
ZW
7610/* inst.operands[i] was set up by parse_address. Encode it into an
7611 ARM-format mode 3 load or store instruction. Reject forms that
7612 cannot be used with such instructions. If is_t is true, reject
7613 forms that cannot be used with a T instruction (i.e. not
7614 post-indexed). */
7615static void
7616encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7617{
c19d1205 7618 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7619 {
c19d1205
ZW
7620 inst.error = _("instruction does not accept scaled register index");
7621 return;
09d92015 7622 }
a737bd4d 7623
c19d1205 7624 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7625
c19d1205
ZW
7626 if (inst.operands[i].immisreg)
7627 {
5be8be5d 7628 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7629 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7630 BAD_PC_ADDRESSING);
eb9f3f00
JB
7631 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7632 BAD_PC_WRITEBACK);
c19d1205
ZW
7633 inst.instruction |= inst.operands[i].imm;
7634 if (!inst.operands[i].negative)
7635 inst.instruction |= INDEX_UP;
7636 }
7637 else /* immediate offset in inst.reloc */
7638 {
5be8be5d
DG
7639 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7640 && inst.operands[i].writeback),
7641 BAD_PC_WRITEBACK);
c19d1205
ZW
7642 inst.instruction |= HWOFFSET_IMM;
7643 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7644 {
7645 /* Prefer + for zero encoded value. */
7646 if (!inst.operands[i].negative)
7647 inst.instruction |= INDEX_UP;
7648
7649 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7650 }
c19d1205 7651 }
a737bd4d
NC
7652}
7653
8335d6aa
JW
7654/* Write immediate bits [7:0] to the following locations:
7655
7656 |28/24|23 19|18 16|15 4|3 0|
7657 | 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|
7658
7659 This function is used by VMOV/VMVN/VORR/VBIC. */
7660
7661static void
7662neon_write_immbits (unsigned immbits)
7663{
7664 inst.instruction |= immbits & 0xf;
7665 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7666 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7667}
7668
7669/* Invert low-order SIZE bits of XHI:XLO. */
7670
7671static void
7672neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7673{
7674 unsigned immlo = xlo ? *xlo : 0;
7675 unsigned immhi = xhi ? *xhi : 0;
7676
7677 switch (size)
7678 {
7679 case 8:
7680 immlo = (~immlo) & 0xff;
7681 break;
7682
7683 case 16:
7684 immlo = (~immlo) & 0xffff;
7685 break;
7686
7687 case 64:
7688 immhi = (~immhi) & 0xffffffff;
7689 /* fall through. */
7690
7691 case 32:
7692 immlo = (~immlo) & 0xffffffff;
7693 break;
7694
7695 default:
7696 abort ();
7697 }
7698
7699 if (xlo)
7700 *xlo = immlo;
7701
7702 if (xhi)
7703 *xhi = immhi;
7704}
7705
7706/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7707 A, B, C, D. */
09d92015 7708
c19d1205 7709static int
8335d6aa 7710neon_bits_same_in_bytes (unsigned imm)
09d92015 7711{
8335d6aa
JW
7712 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7713 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7714 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7715 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7716}
a737bd4d 7717
8335d6aa 7718/* For immediate of above form, return 0bABCD. */
09d92015 7719
8335d6aa
JW
7720static unsigned
7721neon_squash_bits (unsigned imm)
7722{
7723 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7724 | ((imm & 0x01000000) >> 21);
7725}
7726
7727/* Compress quarter-float representation to 0b...000 abcdefgh. */
7728
7729static unsigned
7730neon_qfloat_bits (unsigned imm)
7731{
7732 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7733}
7734
7735/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7736 the instruction. *OP is passed as the initial value of the op field, and
7737 may be set to a different value depending on the constant (i.e.
7738 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7739 MVN). If the immediate looks like a repeated pattern then also
7740 try smaller element sizes. */
7741
7742static int
7743neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7744 unsigned *immbits, int *op, int size,
7745 enum neon_el_type type)
7746{
7747 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7748 float. */
7749 if (type == NT_float && !float_p)
7750 return FAIL;
7751
7752 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7753 {
8335d6aa
JW
7754 if (size != 32 || *op == 1)
7755 return FAIL;
7756 *immbits = neon_qfloat_bits (immlo);
7757 return 0xf;
7758 }
7759
7760 if (size == 64)
7761 {
7762 if (neon_bits_same_in_bytes (immhi)
7763 && neon_bits_same_in_bytes (immlo))
c19d1205 7764 {
8335d6aa
JW
7765 if (*op == 1)
7766 return FAIL;
7767 *immbits = (neon_squash_bits (immhi) << 4)
7768 | neon_squash_bits (immlo);
7769 *op = 1;
7770 return 0xe;
c19d1205 7771 }
a737bd4d 7772
8335d6aa
JW
7773 if (immhi != immlo)
7774 return FAIL;
7775 }
a737bd4d 7776
8335d6aa 7777 if (size >= 32)
09d92015 7778 {
8335d6aa 7779 if (immlo == (immlo & 0x000000ff))
c19d1205 7780 {
8335d6aa
JW
7781 *immbits = immlo;
7782 return 0x0;
c19d1205 7783 }
8335d6aa 7784 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7785 {
8335d6aa
JW
7786 *immbits = immlo >> 8;
7787 return 0x2;
c19d1205 7788 }
8335d6aa
JW
7789 else if (immlo == (immlo & 0x00ff0000))
7790 {
7791 *immbits = immlo >> 16;
7792 return 0x4;
7793 }
7794 else if (immlo == (immlo & 0xff000000))
7795 {
7796 *immbits = immlo >> 24;
7797 return 0x6;
7798 }
7799 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7800 {
7801 *immbits = (immlo >> 8) & 0xff;
7802 return 0xc;
7803 }
7804 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7805 {
7806 *immbits = (immlo >> 16) & 0xff;
7807 return 0xd;
7808 }
7809
7810 if ((immlo & 0xffff) != (immlo >> 16))
7811 return FAIL;
7812 immlo &= 0xffff;
09d92015 7813 }
a737bd4d 7814
8335d6aa 7815 if (size >= 16)
4962c51a 7816 {
8335d6aa
JW
7817 if (immlo == (immlo & 0x000000ff))
7818 {
7819 *immbits = immlo;
7820 return 0x8;
7821 }
7822 else if (immlo == (immlo & 0x0000ff00))
7823 {
7824 *immbits = immlo >> 8;
7825 return 0xa;
7826 }
7827
7828 if ((immlo & 0xff) != (immlo >> 8))
7829 return FAIL;
7830 immlo &= 0xff;
4962c51a
MS
7831 }
7832
8335d6aa
JW
7833 if (immlo == (immlo & 0x000000ff))
7834 {
7835 /* Don't allow MVN with 8-bit immediate. */
7836 if (*op == 1)
7837 return FAIL;
7838 *immbits = immlo;
7839 return 0xe;
7840 }
26d97720 7841
8335d6aa 7842 return FAIL;
c19d1205 7843}
a737bd4d 7844
5fc177c8 7845#if defined BFD_HOST_64_BIT
ba592044
AM
7846/* Returns TRUE if double precision value V may be cast
7847 to single precision without loss of accuracy. */
7848
7849static bfd_boolean
5fc177c8 7850is_double_a_single (bfd_int64_t v)
ba592044 7851{
5fc177c8 7852 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7853 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7854
7855 return (exp == 0 || exp == 0x7FF
7856 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7857 && (mantissa & 0x1FFFFFFFl) == 0;
7858}
7859
3739860c 7860/* Returns a double precision value casted to single precision
ba592044
AM
7861 (ignoring the least significant bits in exponent and mantissa). */
7862
7863static int
5fc177c8 7864double_to_single (bfd_int64_t v)
ba592044
AM
7865{
7866 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7867 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7868 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7869
7870 if (exp == 0x7FF)
7871 exp = 0xFF;
7872 else
7873 {
7874 exp = exp - 1023 + 127;
7875 if (exp >= 0xFF)
7876 {
7877 /* Infinity. */
7878 exp = 0x7F;
7879 mantissa = 0;
7880 }
7881 else if (exp < 0)
7882 {
7883 /* No denormalized numbers. */
7884 exp = 0;
7885 mantissa = 0;
7886 }
7887 }
7888 mantissa >>= 29;
7889 return (sign << 31) | (exp << 23) | mantissa;
7890}
5fc177c8 7891#endif /* BFD_HOST_64_BIT */
ba592044 7892
8335d6aa
JW
7893enum lit_type
7894{
7895 CONST_THUMB,
7896 CONST_ARM,
7897 CONST_VEC
7898};
7899
ba592044
AM
7900static void do_vfp_nsyn_opcode (const char *);
7901
c19d1205
ZW
7902/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7903 Determine whether it can be performed with a move instruction; if
7904 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7905 return TRUE; if it can't, convert inst.instruction to a literal-pool
7906 load and return FALSE. If this is not a valid thing to do in the
7907 current context, set inst.error and return TRUE.
a737bd4d 7908
c19d1205
ZW
7909 inst.operands[i] describes the destination register. */
7910
c921be7d 7911static bfd_boolean
8335d6aa 7912move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7913{
53365c0d 7914 unsigned long tbit;
8335d6aa
JW
7915 bfd_boolean thumb_p = (t == CONST_THUMB);
7916 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7917
7918 if (thumb_p)
7919 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7920 else
7921 tbit = LOAD_BIT;
7922
7923 if ((inst.instruction & tbit) == 0)
09d92015 7924 {
c19d1205 7925 inst.error = _("invalid pseudo operation");
c921be7d 7926 return TRUE;
09d92015 7927 }
ba592044 7928
8335d6aa
JW
7929 if (inst.reloc.exp.X_op != O_constant
7930 && inst.reloc.exp.X_op != O_symbol
7931 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7932 {
7933 inst.error = _("constant expression expected");
c921be7d 7934 return TRUE;
09d92015 7935 }
ba592044
AM
7936
7937 if (inst.reloc.exp.X_op == O_constant
7938 || inst.reloc.exp.X_op == O_big)
8335d6aa 7939 {
5fc177c8
NC
7940#if defined BFD_HOST_64_BIT
7941 bfd_int64_t v;
7942#else
ba592044 7943 offsetT v;
5fc177c8 7944#endif
ba592044 7945 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7946 {
ba592044
AM
7947 LITTLENUM_TYPE w[X_PRECISION];
7948 LITTLENUM_TYPE * l;
7949
7950 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7951 {
ba592044
AM
7952 gen_to_words (w, X_PRECISION, E_PRECISION);
7953 l = w;
7954 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7955 }
ba592044
AM
7956 else
7957 l = generic_bignum;
3739860c 7958
5fc177c8
NC
7959#if defined BFD_HOST_64_BIT
7960 v =
7961 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7962 << LITTLENUM_NUMBER_OF_BITS)
7963 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7964 << LITTLENUM_NUMBER_OF_BITS)
7965 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7966 << LITTLENUM_NUMBER_OF_BITS)
7967 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7968#else
ba592044
AM
7969 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7970 | (l[0] & LITTLENUM_MASK);
5fc177c8 7971#endif
8335d6aa 7972 }
ba592044
AM
7973 else
7974 v = inst.reloc.exp.X_add_number;
7975
7976 if (!inst.operands[i].issingle)
8335d6aa 7977 {
12569877 7978 if (thumb_p)
8335d6aa 7979 {
53445554
TP
7980 /* LDR should not use lead in a flag-setting instruction being
7981 chosen so we do not check whether movs can be used. */
12569877 7982
53445554 7983 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 7984 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
7985 && inst.operands[i].reg != 13
7986 && inst.operands[i].reg != 15)
12569877 7987 {
fc289b0a
TP
7988 /* Check if on thumb2 it can be done with a mov.w, mvn or
7989 movw instruction. */
12569877
AM
7990 unsigned int newimm;
7991 bfd_boolean isNegated;
7992
7993 newimm = encode_thumb32_immediate (v);
7994 if (newimm != (unsigned int) FAIL)
7995 isNegated = FALSE;
7996 else
7997 {
582cfe03 7998 newimm = encode_thumb32_immediate (~v);
12569877
AM
7999 if (newimm != (unsigned int) FAIL)
8000 isNegated = TRUE;
8001 }
8002
fc289b0a
TP
8003 /* The number can be loaded with a mov.w or mvn
8004 instruction. */
ff8646ee
TP
8005 if (newimm != (unsigned int) FAIL
8006 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8007 {
fc289b0a 8008 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8009 | (inst.operands[i].reg << 8));
fc289b0a 8010 /* Change to MOVN. */
582cfe03 8011 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8012 inst.instruction |= (newimm & 0x800) << 15;
8013 inst.instruction |= (newimm & 0x700) << 4;
8014 inst.instruction |= (newimm & 0x0ff);
8015 return TRUE;
8016 }
fc289b0a 8017 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8018 else if ((v & ~0xFFFF) == 0
8019 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8020 {
582cfe03 8021 int imm = v & 0xFFFF;
12569877 8022
582cfe03 8023 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8024 inst.instruction |= (inst.operands[i].reg << 8);
8025 inst.instruction |= (imm & 0xf000) << 4;
8026 inst.instruction |= (imm & 0x0800) << 15;
8027 inst.instruction |= (imm & 0x0700) << 4;
8028 inst.instruction |= (imm & 0x00ff);
8029 return TRUE;
8030 }
8031 }
8335d6aa 8032 }
12569877 8033 else if (arm_p)
ba592044
AM
8034 {
8035 int value = encode_arm_immediate (v);
12569877 8036
ba592044
AM
8037 if (value != FAIL)
8038 {
8039 /* This can be done with a mov instruction. */
8040 inst.instruction &= LITERAL_MASK;
8041 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8042 inst.instruction |= value & 0xfff;
8043 return TRUE;
8044 }
8335d6aa 8045
ba592044
AM
8046 value = encode_arm_immediate (~ v);
8047 if (value != FAIL)
8048 {
8049 /* This can be done with a mvn instruction. */
8050 inst.instruction &= LITERAL_MASK;
8051 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8052 inst.instruction |= value & 0xfff;
8053 return TRUE;
8054 }
8055 }
934c2632 8056 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8057 {
ba592044
AM
8058 int op = 0;
8059 unsigned immbits = 0;
8060 unsigned immlo = inst.operands[1].imm;
8061 unsigned immhi = inst.operands[1].regisimm
8062 ? inst.operands[1].reg
8063 : inst.reloc.exp.X_unsigned
8064 ? 0
8065 : ((bfd_int64_t)((int) immlo)) >> 32;
8066 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8067 &op, 64, NT_invtype);
8068
8069 if (cmode == FAIL)
8070 {
8071 neon_invert_size (&immlo, &immhi, 64);
8072 op = !op;
8073 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8074 &op, 64, NT_invtype);
8075 }
8076
8077 if (cmode != FAIL)
8078 {
8079 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8080 | (1 << 23)
8081 | (cmode << 8)
8082 | (op << 5)
8083 | (1 << 4);
8084
8085 /* Fill other bits in vmov encoding for both thumb and arm. */
8086 if (thumb_mode)
eff0bc54 8087 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8088 else
eff0bc54 8089 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8090 neon_write_immbits (immbits);
8091 return TRUE;
8092 }
8335d6aa
JW
8093 }
8094 }
8335d6aa 8095
ba592044
AM
8096 if (t == CONST_VEC)
8097 {
8098 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8099 if (inst.operands[i].issingle
8100 && is_quarter_float (inst.operands[1].imm)
8101 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8102 {
ba592044
AM
8103 inst.operands[1].imm =
8104 neon_qfloat_bits (v);
8105 do_vfp_nsyn_opcode ("fconsts");
8106 return TRUE;
8335d6aa 8107 }
5fc177c8
NC
8108
8109 /* If our host does not support a 64-bit type then we cannot perform
8110 the following optimization. This mean that there will be a
8111 discrepancy between the output produced by an assembler built for
8112 a 32-bit-only host and the output produced from a 64-bit host, but
8113 this cannot be helped. */
8114#if defined BFD_HOST_64_BIT
ba592044
AM
8115 else if (!inst.operands[1].issingle
8116 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8117 {
ba592044
AM
8118 if (is_double_a_single (v)
8119 && is_quarter_float (double_to_single (v)))
8120 {
8121 inst.operands[1].imm =
8122 neon_qfloat_bits (double_to_single (v));
8123 do_vfp_nsyn_opcode ("fconstd");
8124 return TRUE;
8125 }
8335d6aa 8126 }
5fc177c8 8127#endif
8335d6aa
JW
8128 }
8129 }
8130
8131 if (add_to_lit_pool ((!inst.operands[i].isvec
8132 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8133 return TRUE;
8134
8135 inst.operands[1].reg = REG_PC;
8136 inst.operands[1].isreg = 1;
8137 inst.operands[1].preind = 1;
8138 inst.reloc.pc_rel = 1;
8139 inst.reloc.type = (thumb_p
8140 ? BFD_RELOC_ARM_THUMB_OFFSET
8141 : (mode_3
8142 ? BFD_RELOC_ARM_HWLITERAL
8143 : BFD_RELOC_ARM_LITERAL));
8144 return FALSE;
8145}
8146
8147/* inst.operands[i] was set up by parse_address. Encode it into an
8148 ARM-format instruction. Reject all forms which cannot be encoded
8149 into a coprocessor load/store instruction. If wb_ok is false,
8150 reject use of writeback; if unind_ok is false, reject use of
8151 unindexed addressing. If reloc_override is not 0, use it instead
8152 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8153 (in which case it is preserved). */
8154
8155static int
8156encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8157{
8158 if (!inst.operands[i].isreg)
8159 {
99b2a2dd
NC
8160 /* PR 18256 */
8161 if (! inst.operands[0].isvec)
8162 {
8163 inst.error = _("invalid co-processor operand");
8164 return FAIL;
8165 }
8335d6aa
JW
8166 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8167 return SUCCESS;
8168 }
8169
8170 inst.instruction |= inst.operands[i].reg << 16;
8171
8172 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8173
8174 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8175 {
8176 gas_assert (!inst.operands[i].writeback);
8177 if (!unind_ok)
8178 {
8179 inst.error = _("instruction does not support unindexed addressing");
8180 return FAIL;
8181 }
8182 inst.instruction |= inst.operands[i].imm;
8183 inst.instruction |= INDEX_UP;
8184 return SUCCESS;
8185 }
8186
8187 if (inst.operands[i].preind)
8188 inst.instruction |= PRE_INDEX;
8189
8190 if (inst.operands[i].writeback)
09d92015 8191 {
8335d6aa 8192 if (inst.operands[i].reg == REG_PC)
c19d1205 8193 {
8335d6aa
JW
8194 inst.error = _("pc may not be used with write-back");
8195 return FAIL;
c19d1205 8196 }
8335d6aa 8197 if (!wb_ok)
c19d1205 8198 {
8335d6aa
JW
8199 inst.error = _("instruction does not support writeback");
8200 return FAIL;
c19d1205 8201 }
8335d6aa 8202 inst.instruction |= WRITE_BACK;
09d92015
MM
8203 }
8204
8335d6aa
JW
8205 if (reloc_override)
8206 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8207 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8208 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8209 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8210 {
8335d6aa
JW
8211 if (thumb_mode)
8212 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8213 else
8214 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8215 }
8335d6aa
JW
8216
8217 /* Prefer + for zero encoded value. */
8218 if (!inst.operands[i].negative)
8219 inst.instruction |= INDEX_UP;
8220
8221 return SUCCESS;
09d92015
MM
8222}
8223
5f4273c7 8224/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8225 First some generics; their names are taken from the conventional
8226 bit positions for register arguments in ARM format instructions. */
09d92015 8227
a737bd4d 8228static void
c19d1205 8229do_noargs (void)
09d92015 8230{
c19d1205 8231}
a737bd4d 8232
c19d1205
ZW
8233static void
8234do_rd (void)
8235{
8236 inst.instruction |= inst.operands[0].reg << 12;
8237}
a737bd4d 8238
16a1fa25
TP
8239static void
8240do_rn (void)
8241{
8242 inst.instruction |= inst.operands[0].reg << 16;
8243}
8244
c19d1205
ZW
8245static void
8246do_rd_rm (void)
8247{
8248 inst.instruction |= inst.operands[0].reg << 12;
8249 inst.instruction |= inst.operands[1].reg;
8250}
09d92015 8251
9eb6c0f1
MGD
8252static void
8253do_rm_rn (void)
8254{
8255 inst.instruction |= inst.operands[0].reg;
8256 inst.instruction |= inst.operands[1].reg << 16;
8257}
8258
c19d1205
ZW
8259static void
8260do_rd_rn (void)
8261{
8262 inst.instruction |= inst.operands[0].reg << 12;
8263 inst.instruction |= inst.operands[1].reg << 16;
8264}
a737bd4d 8265
c19d1205
ZW
8266static void
8267do_rn_rd (void)
8268{
8269 inst.instruction |= inst.operands[0].reg << 16;
8270 inst.instruction |= inst.operands[1].reg << 12;
8271}
09d92015 8272
4ed7ed8d
TP
8273static void
8274do_tt (void)
8275{
8276 inst.instruction |= inst.operands[0].reg << 8;
8277 inst.instruction |= inst.operands[1].reg << 16;
8278}
8279
59d09be6
MGD
8280static bfd_boolean
8281check_obsolete (const arm_feature_set *feature, const char *msg)
8282{
8283 if (ARM_CPU_IS_ANY (cpu_variant))
8284 {
5c3696f8 8285 as_tsktsk ("%s", msg);
59d09be6
MGD
8286 return TRUE;
8287 }
8288 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8289 {
8290 as_bad ("%s", msg);
8291 return TRUE;
8292 }
8293
8294 return FALSE;
8295}
8296
c19d1205
ZW
8297static void
8298do_rd_rm_rn (void)
8299{
9a64e435 8300 unsigned Rn = inst.operands[2].reg;
708587a4 8301 /* Enforce restrictions on SWP instruction. */
9a64e435 8302 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8303 {
8304 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8305 _("Rn must not overlap other operands"));
8306
59d09be6
MGD
8307 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8308 */
8309 if (!check_obsolete (&arm_ext_v8,
8310 _("swp{b} use is obsoleted for ARMv8 and later"))
8311 && warn_on_deprecated
8312 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8313 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8314 }
59d09be6 8315
c19d1205
ZW
8316 inst.instruction |= inst.operands[0].reg << 12;
8317 inst.instruction |= inst.operands[1].reg;
9a64e435 8318 inst.instruction |= Rn << 16;
c19d1205 8319}
09d92015 8320
c19d1205
ZW
8321static void
8322do_rd_rn_rm (void)
8323{
8324 inst.instruction |= inst.operands[0].reg << 12;
8325 inst.instruction |= inst.operands[1].reg << 16;
8326 inst.instruction |= inst.operands[2].reg;
8327}
a737bd4d 8328
c19d1205
ZW
8329static void
8330do_rm_rd_rn (void)
8331{
5be8be5d
DG
8332 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8333 constraint (((inst.reloc.exp.X_op != O_constant
8334 && inst.reloc.exp.X_op != O_illegal)
8335 || inst.reloc.exp.X_add_number != 0),
8336 BAD_ADDR_MODE);
c19d1205
ZW
8337 inst.instruction |= inst.operands[0].reg;
8338 inst.instruction |= inst.operands[1].reg << 12;
8339 inst.instruction |= inst.operands[2].reg << 16;
8340}
09d92015 8341
c19d1205
ZW
8342static void
8343do_imm0 (void)
8344{
8345 inst.instruction |= inst.operands[0].imm;
8346}
09d92015 8347
c19d1205
ZW
8348static void
8349do_rd_cpaddr (void)
8350{
8351 inst.instruction |= inst.operands[0].reg << 12;
8352 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8353}
a737bd4d 8354
c19d1205
ZW
8355/* ARM instructions, in alphabetical order by function name (except
8356 that wrapper functions appear immediately after the function they
8357 wrap). */
09d92015 8358
c19d1205
ZW
8359/* This is a pseudo-op of the form "adr rd, label" to be converted
8360 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8361
8362static void
c19d1205 8363do_adr (void)
09d92015 8364{
c19d1205 8365 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8366
c19d1205
ZW
8367 /* Frag hacking will turn this into a sub instruction if the offset turns
8368 out to be negative. */
8369 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8370 inst.reloc.pc_rel = 1;
2fc8bdac 8371 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8372
8373 if (inst.reloc.exp.X_op == O_symbol
8374 && inst.reloc.exp.X_add_symbol != NULL
8375 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8376 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8377 inst.reloc.exp.X_add_number += 1;
c19d1205 8378}
b99bd4ef 8379
c19d1205
ZW
8380/* This is a pseudo-op of the form "adrl rd, label" to be converted
8381 into a relative address of the form:
8382 add rd, pc, #low(label-.-8)"
8383 add rd, rd, #high(label-.-8)" */
b99bd4ef 8384
c19d1205
ZW
8385static void
8386do_adrl (void)
8387{
8388 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8389
c19d1205
ZW
8390 /* Frag hacking will turn this into a sub instruction if the offset turns
8391 out to be negative. */
8392 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8393 inst.reloc.pc_rel = 1;
8394 inst.size = INSN_SIZE * 2;
2fc8bdac 8395 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8396
8397 if (inst.reloc.exp.X_op == O_symbol
8398 && inst.reloc.exp.X_add_symbol != NULL
8399 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8400 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8401 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8402}
8403
b99bd4ef 8404static void
c19d1205 8405do_arit (void)
b99bd4ef 8406{
a9f02af8
MG
8407 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8408 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8409 THUMB1_RELOC_ONLY);
c19d1205
ZW
8410 if (!inst.operands[1].present)
8411 inst.operands[1].reg = inst.operands[0].reg;
8412 inst.instruction |= inst.operands[0].reg << 12;
8413 inst.instruction |= inst.operands[1].reg << 16;
8414 encode_arm_shifter_operand (2);
8415}
b99bd4ef 8416
62b3e311
PB
8417static void
8418do_barrier (void)
8419{
8420 if (inst.operands[0].present)
ccb84d65 8421 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8422 else
8423 inst.instruction |= 0xf;
8424}
8425
c19d1205
ZW
8426static void
8427do_bfc (void)
8428{
8429 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8430 constraint (msb > 32, _("bit-field extends past end of register"));
8431 /* The instruction encoding stores the LSB and MSB,
8432 not the LSB and width. */
8433 inst.instruction |= inst.operands[0].reg << 12;
8434 inst.instruction |= inst.operands[1].imm << 7;
8435 inst.instruction |= (msb - 1) << 16;
8436}
b99bd4ef 8437
c19d1205
ZW
8438static void
8439do_bfi (void)
8440{
8441 unsigned int msb;
b99bd4ef 8442
c19d1205
ZW
8443 /* #0 in second position is alternative syntax for bfc, which is
8444 the same instruction but with REG_PC in the Rm field. */
8445 if (!inst.operands[1].isreg)
8446 inst.operands[1].reg = REG_PC;
b99bd4ef 8447
c19d1205
ZW
8448 msb = inst.operands[2].imm + inst.operands[3].imm;
8449 constraint (msb > 32, _("bit-field extends past end of register"));
8450 /* The instruction encoding stores the LSB and MSB,
8451 not the LSB and width. */
8452 inst.instruction |= inst.operands[0].reg << 12;
8453 inst.instruction |= inst.operands[1].reg;
8454 inst.instruction |= inst.operands[2].imm << 7;
8455 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8456}
8457
b99bd4ef 8458static void
c19d1205 8459do_bfx (void)
b99bd4ef 8460{
c19d1205
ZW
8461 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8462 _("bit-field extends past end of register"));
8463 inst.instruction |= inst.operands[0].reg << 12;
8464 inst.instruction |= inst.operands[1].reg;
8465 inst.instruction |= inst.operands[2].imm << 7;
8466 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8467}
09d92015 8468
c19d1205
ZW
8469/* ARM V5 breakpoint instruction (argument parse)
8470 BKPT <16 bit unsigned immediate>
8471 Instruction is not conditional.
8472 The bit pattern given in insns[] has the COND_ALWAYS condition,
8473 and it is an error if the caller tried to override that. */
b99bd4ef 8474
c19d1205
ZW
8475static void
8476do_bkpt (void)
8477{
8478 /* Top 12 of 16 bits to bits 19:8. */
8479 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8480
c19d1205
ZW
8481 /* Bottom 4 of 16 bits to bits 3:0. */
8482 inst.instruction |= inst.operands[0].imm & 0xf;
8483}
09d92015 8484
c19d1205
ZW
8485static void
8486encode_branch (int default_reloc)
8487{
8488 if (inst.operands[0].hasreloc)
8489 {
0855e32b
NS
8490 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8491 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8492 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8493 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8494 ? BFD_RELOC_ARM_PLT32
8495 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8496 }
b99bd4ef 8497 else
9ae92b05 8498 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8499 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8500}
8501
b99bd4ef 8502static void
c19d1205 8503do_branch (void)
b99bd4ef 8504{
39b41c9c
PB
8505#ifdef OBJ_ELF
8506 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8507 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8508 else
8509#endif
8510 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8511}
8512
8513static void
8514do_bl (void)
8515{
8516#ifdef OBJ_ELF
8517 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8518 {
8519 if (inst.cond == COND_ALWAYS)
8520 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8521 else
8522 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8523 }
8524 else
8525#endif
8526 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8527}
b99bd4ef 8528
c19d1205
ZW
8529/* ARM V5 branch-link-exchange instruction (argument parse)
8530 BLX <target_addr> ie BLX(1)
8531 BLX{<condition>} <Rm> ie BLX(2)
8532 Unfortunately, there are two different opcodes for this mnemonic.
8533 So, the insns[].value is not used, and the code here zaps values
8534 into inst.instruction.
8535 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8536
c19d1205
ZW
8537static void
8538do_blx (void)
8539{
8540 if (inst.operands[0].isreg)
b99bd4ef 8541 {
c19d1205
ZW
8542 /* Arg is a register; the opcode provided by insns[] is correct.
8543 It is not illegal to do "blx pc", just useless. */
8544 if (inst.operands[0].reg == REG_PC)
8545 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8546
c19d1205
ZW
8547 inst.instruction |= inst.operands[0].reg;
8548 }
8549 else
b99bd4ef 8550 {
c19d1205 8551 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8552 conditionally, and the opcode must be adjusted.
8553 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8554 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8555 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8556 inst.instruction = 0xfa000000;
267bf995 8557 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8558 }
c19d1205
ZW
8559}
8560
8561static void
8562do_bx (void)
8563{
845b51d6
PB
8564 bfd_boolean want_reloc;
8565
c19d1205
ZW
8566 if (inst.operands[0].reg == REG_PC)
8567 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8568
c19d1205 8569 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8570 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8571 it is for ARMv4t or earlier. */
8572 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8573 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8574 want_reloc = TRUE;
8575
5ad34203 8576#ifdef OBJ_ELF
845b51d6 8577 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8578#endif
584206db 8579 want_reloc = FALSE;
845b51d6
PB
8580
8581 if (want_reloc)
8582 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8583}
8584
c19d1205
ZW
8585
8586/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8587
8588static void
c19d1205 8589do_bxj (void)
a737bd4d 8590{
c19d1205
ZW
8591 if (inst.operands[0].reg == REG_PC)
8592 as_tsktsk (_("use of r15 in bxj is not really useful"));
8593
8594 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8595}
8596
c19d1205
ZW
8597/* Co-processor data operation:
8598 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8599 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8600static void
8601do_cdp (void)
8602{
8603 inst.instruction |= inst.operands[0].reg << 8;
8604 inst.instruction |= inst.operands[1].imm << 20;
8605 inst.instruction |= inst.operands[2].reg << 12;
8606 inst.instruction |= inst.operands[3].reg << 16;
8607 inst.instruction |= inst.operands[4].reg;
8608 inst.instruction |= inst.operands[5].imm << 5;
8609}
a737bd4d
NC
8610
8611static void
c19d1205 8612do_cmp (void)
a737bd4d 8613{
c19d1205
ZW
8614 inst.instruction |= inst.operands[0].reg << 16;
8615 encode_arm_shifter_operand (1);
a737bd4d
NC
8616}
8617
c19d1205
ZW
8618/* Transfer between coprocessor and ARM registers.
8619 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8620 MRC2
8621 MCR{cond}
8622 MCR2
8623
8624 No special properties. */
09d92015 8625
dcbd0d71
MGD
8626struct deprecated_coproc_regs_s
8627{
8628 unsigned cp;
8629 int opc1;
8630 unsigned crn;
8631 unsigned crm;
8632 int opc2;
8633 arm_feature_set deprecated;
8634 arm_feature_set obsoleted;
8635 const char *dep_msg;
8636 const char *obs_msg;
8637};
8638
8639#define DEPR_ACCESS_V8 \
8640 N_("This coprocessor register access is deprecated in ARMv8")
8641
8642/* Table of all deprecated coprocessor registers. */
8643static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8644{
8645 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8646 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8647 DEPR_ACCESS_V8, NULL},
8648 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8649 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8650 DEPR_ACCESS_V8, NULL},
8651 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8652 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8653 DEPR_ACCESS_V8, NULL},
8654 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8655 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8656 DEPR_ACCESS_V8, NULL},
8657 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8658 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8659 DEPR_ACCESS_V8, NULL},
8660};
8661
8662#undef DEPR_ACCESS_V8
8663
8664static const size_t deprecated_coproc_reg_count =
8665 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8666
09d92015 8667static void
c19d1205 8668do_co_reg (void)
09d92015 8669{
fdfde340 8670 unsigned Rd;
dcbd0d71 8671 size_t i;
fdfde340
JM
8672
8673 Rd = inst.operands[2].reg;
8674 if (thumb_mode)
8675 {
8676 if (inst.instruction == 0xee000010
8677 || inst.instruction == 0xfe000010)
8678 /* MCR, MCR2 */
8679 reject_bad_reg (Rd);
5c8ed6a4 8680 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8681 /* MRC, MRC2 */
8682 constraint (Rd == REG_SP, BAD_SP);
8683 }
8684 else
8685 {
8686 /* MCR */
8687 if (inst.instruction == 0xe000010)
8688 constraint (Rd == REG_PC, BAD_PC);
8689 }
8690
dcbd0d71
MGD
8691 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8692 {
8693 const struct deprecated_coproc_regs_s *r =
8694 deprecated_coproc_regs + i;
8695
8696 if (inst.operands[0].reg == r->cp
8697 && inst.operands[1].imm == r->opc1
8698 && inst.operands[3].reg == r->crn
8699 && inst.operands[4].reg == r->crm
8700 && inst.operands[5].imm == r->opc2)
8701 {
b10bf8c5 8702 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8703 && warn_on_deprecated
dcbd0d71 8704 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8705 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8706 }
8707 }
fdfde340 8708
c19d1205
ZW
8709 inst.instruction |= inst.operands[0].reg << 8;
8710 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8711 inst.instruction |= Rd << 12;
c19d1205
ZW
8712 inst.instruction |= inst.operands[3].reg << 16;
8713 inst.instruction |= inst.operands[4].reg;
8714 inst.instruction |= inst.operands[5].imm << 5;
8715}
09d92015 8716
c19d1205
ZW
8717/* Transfer between coprocessor register and pair of ARM registers.
8718 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8719 MCRR2
8720 MRRC{cond}
8721 MRRC2
b99bd4ef 8722
c19d1205 8723 Two XScale instructions are special cases of these:
09d92015 8724
c19d1205
ZW
8725 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8726 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8727
5f4273c7 8728 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8729
c19d1205
ZW
8730static void
8731do_co_reg2c (void)
8732{
fdfde340
JM
8733 unsigned Rd, Rn;
8734
8735 Rd = inst.operands[2].reg;
8736 Rn = inst.operands[3].reg;
8737
8738 if (thumb_mode)
8739 {
8740 reject_bad_reg (Rd);
8741 reject_bad_reg (Rn);
8742 }
8743 else
8744 {
8745 constraint (Rd == REG_PC, BAD_PC);
8746 constraint (Rn == REG_PC, BAD_PC);
8747 }
8748
873f10f0
TC
8749 /* Only check the MRRC{2} variants. */
8750 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8751 {
8752 /* If Rd == Rn, error that the operation is
8753 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8754 constraint (Rd == Rn, BAD_OVERLAP);
8755 }
8756
c19d1205
ZW
8757 inst.instruction |= inst.operands[0].reg << 8;
8758 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8759 inst.instruction |= Rd << 12;
8760 inst.instruction |= Rn << 16;
c19d1205 8761 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8762}
8763
c19d1205
ZW
8764static void
8765do_cpsi (void)
8766{
8767 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8768 if (inst.operands[1].present)
8769 {
8770 inst.instruction |= CPSI_MMOD;
8771 inst.instruction |= inst.operands[1].imm;
8772 }
c19d1205 8773}
b99bd4ef 8774
62b3e311
PB
8775static void
8776do_dbg (void)
8777{
8778 inst.instruction |= inst.operands[0].imm;
8779}
8780
eea54501
MGD
8781static void
8782do_div (void)
8783{
8784 unsigned Rd, Rn, Rm;
8785
8786 Rd = inst.operands[0].reg;
8787 Rn = (inst.operands[1].present
8788 ? inst.operands[1].reg : Rd);
8789 Rm = inst.operands[2].reg;
8790
8791 constraint ((Rd == REG_PC), BAD_PC);
8792 constraint ((Rn == REG_PC), BAD_PC);
8793 constraint ((Rm == REG_PC), BAD_PC);
8794
8795 inst.instruction |= Rd << 16;
8796 inst.instruction |= Rn << 0;
8797 inst.instruction |= Rm << 8;
8798}
8799
b99bd4ef 8800static void
c19d1205 8801do_it (void)
b99bd4ef 8802{
c19d1205 8803 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8804 process it to do the validation as if in
8805 thumb mode, just in case the code gets
8806 assembled for thumb using the unified syntax. */
8807
c19d1205 8808 inst.size = 0;
e07e6e58
NC
8809 if (unified_syntax)
8810 {
8811 set_it_insn_type (IT_INSN);
8812 now_it.mask = (inst.instruction & 0xf) | 0x10;
8813 now_it.cc = inst.operands[0].imm;
8814 }
09d92015 8815}
b99bd4ef 8816
6530b175
NC
8817/* If there is only one register in the register list,
8818 then return its register number. Otherwise return -1. */
8819static int
8820only_one_reg_in_list (int range)
8821{
8822 int i = ffs (range) - 1;
8823 return (i > 15 || range != (1 << i)) ? -1 : i;
8824}
8825
09d92015 8826static void
6530b175 8827encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8828{
c19d1205
ZW
8829 int base_reg = inst.operands[0].reg;
8830 int range = inst.operands[1].imm;
6530b175 8831 int one_reg;
ea6ef066 8832
c19d1205
ZW
8833 inst.instruction |= base_reg << 16;
8834 inst.instruction |= range;
ea6ef066 8835
c19d1205
ZW
8836 if (inst.operands[1].writeback)
8837 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8838
c19d1205 8839 if (inst.operands[0].writeback)
ea6ef066 8840 {
c19d1205
ZW
8841 inst.instruction |= WRITE_BACK;
8842 /* Check for unpredictable uses of writeback. */
8843 if (inst.instruction & LOAD_BIT)
09d92015 8844 {
c19d1205
ZW
8845 /* Not allowed in LDM type 2. */
8846 if ((inst.instruction & LDM_TYPE_2_OR_3)
8847 && ((range & (1 << REG_PC)) == 0))
8848 as_warn (_("writeback of base register is UNPREDICTABLE"));
8849 /* Only allowed if base reg not in list for other types. */
8850 else if (range & (1 << base_reg))
8851 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8852 }
8853 else /* STM. */
8854 {
8855 /* Not allowed for type 2. */
8856 if (inst.instruction & LDM_TYPE_2_OR_3)
8857 as_warn (_("writeback of base register is UNPREDICTABLE"));
8858 /* Only allowed if base reg not in list, or first in list. */
8859 else if ((range & (1 << base_reg))
8860 && (range & ((1 << base_reg) - 1)))
8861 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8862 }
ea6ef066 8863 }
6530b175
NC
8864
8865 /* If PUSH/POP has only one register, then use the A2 encoding. */
8866 one_reg = only_one_reg_in_list (range);
8867 if (from_push_pop_mnem && one_reg >= 0)
8868 {
8869 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8870
8871 inst.instruction &= A_COND_MASK;
8872 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8873 inst.instruction |= one_reg << 12;
8874 }
8875}
8876
8877static void
8878do_ldmstm (void)
8879{
8880 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8881}
8882
c19d1205
ZW
8883/* ARMv5TE load-consecutive (argument parse)
8884 Mode is like LDRH.
8885
8886 LDRccD R, mode
8887 STRccD R, mode. */
8888
a737bd4d 8889static void
c19d1205 8890do_ldrd (void)
a737bd4d 8891{
c19d1205 8892 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8893 _("first transfer register must be even"));
c19d1205
ZW
8894 constraint (inst.operands[1].present
8895 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8896 _("can only transfer two consecutive registers"));
c19d1205
ZW
8897 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8898 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8899
c19d1205
ZW
8900 if (!inst.operands[1].present)
8901 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8902
c56791bb
RE
8903 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8904 register and the first register written; we have to diagnose
8905 overlap between the base and the second register written here. */
ea6ef066 8906
c56791bb
RE
8907 if (inst.operands[2].reg == inst.operands[1].reg
8908 && (inst.operands[2].writeback || inst.operands[2].postind))
8909 as_warn (_("base register written back, and overlaps "
8910 "second transfer register"));
b05fe5cf 8911
c56791bb
RE
8912 if (!(inst.instruction & V4_STR_BIT))
8913 {
c19d1205 8914 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8915 destination (even if not write-back). */
8916 if (inst.operands[2].immisreg
8917 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8918 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8919 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8920 }
c19d1205
ZW
8921 inst.instruction |= inst.operands[0].reg << 12;
8922 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8923}
8924
8925static void
c19d1205 8926do_ldrex (void)
b05fe5cf 8927{
c19d1205
ZW
8928 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8929 || inst.operands[1].postind || inst.operands[1].writeback
8930 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8931 || inst.operands[1].negative
8932 /* This can arise if the programmer has written
8933 strex rN, rM, foo
8934 or if they have mistakenly used a register name as the last
8935 operand, eg:
8936 strex rN, rM, rX
8937 It is very difficult to distinguish between these two cases
8938 because "rX" might actually be a label. ie the register
8939 name has been occluded by a symbol of the same name. So we
8940 just generate a general 'bad addressing mode' type error
8941 message and leave it up to the programmer to discover the
8942 true cause and fix their mistake. */
8943 || (inst.operands[1].reg == REG_PC),
8944 BAD_ADDR_MODE);
b05fe5cf 8945
c19d1205
ZW
8946 constraint (inst.reloc.exp.X_op != O_constant
8947 || inst.reloc.exp.X_add_number != 0,
8948 _("offset must be zero in ARM encoding"));
b05fe5cf 8949
5be8be5d
DG
8950 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8951
c19d1205
ZW
8952 inst.instruction |= inst.operands[0].reg << 12;
8953 inst.instruction |= inst.operands[1].reg << 16;
8954 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8955}
8956
8957static void
c19d1205 8958do_ldrexd (void)
b05fe5cf 8959{
c19d1205
ZW
8960 constraint (inst.operands[0].reg % 2 != 0,
8961 _("even register required"));
8962 constraint (inst.operands[1].present
8963 && inst.operands[1].reg != inst.operands[0].reg + 1,
8964 _("can only load two consecutive registers"));
8965 /* If op 1 were present and equal to PC, this function wouldn't
8966 have been called in the first place. */
8967 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8968
c19d1205
ZW
8969 inst.instruction |= inst.operands[0].reg << 12;
8970 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8971}
8972
1be5fd2e
NC
8973/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8974 which is not a multiple of four is UNPREDICTABLE. */
8975static void
8976check_ldr_r15_aligned (void)
8977{
8978 constraint (!(inst.operands[1].immisreg)
8979 && (inst.operands[0].reg == REG_PC
8980 && inst.operands[1].reg == REG_PC
8981 && (inst.reloc.exp.X_add_number & 0x3)),
8982 _("ldr to register 15 must be 4-byte alligned"));
8983}
8984
b05fe5cf 8985static void
c19d1205 8986do_ldst (void)
b05fe5cf 8987{
c19d1205
ZW
8988 inst.instruction |= inst.operands[0].reg << 12;
8989 if (!inst.operands[1].isreg)
8335d6aa 8990 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8991 return;
c19d1205 8992 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8993 check_ldr_r15_aligned ();
b05fe5cf
ZW
8994}
8995
8996static void
c19d1205 8997do_ldstt (void)
b05fe5cf 8998{
c19d1205
ZW
8999 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9000 reject [Rn,...]. */
9001 if (inst.operands[1].preind)
b05fe5cf 9002 {
bd3ba5d1
NC
9003 constraint (inst.reloc.exp.X_op != O_constant
9004 || inst.reloc.exp.X_add_number != 0,
c19d1205 9005 _("this instruction requires a post-indexed address"));
b05fe5cf 9006
c19d1205
ZW
9007 inst.operands[1].preind = 0;
9008 inst.operands[1].postind = 1;
9009 inst.operands[1].writeback = 1;
b05fe5cf 9010 }
c19d1205
ZW
9011 inst.instruction |= inst.operands[0].reg << 12;
9012 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9013}
b05fe5cf 9014
c19d1205 9015/* Halfword and signed-byte load/store operations. */
b05fe5cf 9016
c19d1205
ZW
9017static void
9018do_ldstv4 (void)
9019{
ff4a8d2b 9020 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9021 inst.instruction |= inst.operands[0].reg << 12;
9022 if (!inst.operands[1].isreg)
8335d6aa 9023 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9024 return;
c19d1205 9025 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9026}
9027
9028static void
c19d1205 9029do_ldsttv4 (void)
b05fe5cf 9030{
c19d1205
ZW
9031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9032 reject [Rn,...]. */
9033 if (inst.operands[1].preind)
b05fe5cf 9034 {
bd3ba5d1
NC
9035 constraint (inst.reloc.exp.X_op != O_constant
9036 || inst.reloc.exp.X_add_number != 0,
c19d1205 9037 _("this instruction requires a post-indexed address"));
b05fe5cf 9038
c19d1205
ZW
9039 inst.operands[1].preind = 0;
9040 inst.operands[1].postind = 1;
9041 inst.operands[1].writeback = 1;
b05fe5cf 9042 }
c19d1205
ZW
9043 inst.instruction |= inst.operands[0].reg << 12;
9044 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9045}
b05fe5cf 9046
c19d1205
ZW
9047/* Co-processor register load/store.
9048 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9049static void
9050do_lstc (void)
9051{
9052 inst.instruction |= inst.operands[0].reg << 8;
9053 inst.instruction |= inst.operands[1].reg << 12;
9054 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9055}
9056
b05fe5cf 9057static void
c19d1205 9058do_mlas (void)
b05fe5cf 9059{
8fb9d7b9 9060 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9061 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9062 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9063 && !(inst.instruction & 0x00400000))
8fb9d7b9 9064 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9065
c19d1205
ZW
9066 inst.instruction |= inst.operands[0].reg << 16;
9067 inst.instruction |= inst.operands[1].reg;
9068 inst.instruction |= inst.operands[2].reg << 8;
9069 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9070}
b05fe5cf 9071
c19d1205
ZW
9072static void
9073do_mov (void)
9074{
a9f02af8
MG
9075 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9076 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9077 THUMB1_RELOC_ONLY);
c19d1205
ZW
9078 inst.instruction |= inst.operands[0].reg << 12;
9079 encode_arm_shifter_operand (1);
9080}
b05fe5cf 9081
c19d1205
ZW
9082/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9083static void
9084do_mov16 (void)
9085{
b6895b4f
PB
9086 bfd_vma imm;
9087 bfd_boolean top;
9088
9089 top = (inst.instruction & 0x00400000) != 0;
9090 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9091 _(":lower16: not allowed in this instruction"));
b6895b4f 9092 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9093 _(":upper16: not allowed in this instruction"));
c19d1205 9094 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9095 if (inst.reloc.type == BFD_RELOC_UNUSED)
9096 {
9097 imm = inst.reloc.exp.X_add_number;
9098 /* The value is in two pieces: 0:11, 16:19. */
9099 inst.instruction |= (imm & 0x00000fff);
9100 inst.instruction |= (imm & 0x0000f000) << 4;
9101 }
b05fe5cf 9102}
b99bd4ef 9103
037e8744
JB
9104static int
9105do_vfp_nsyn_mrs (void)
9106{
9107 if (inst.operands[0].isvec)
9108 {
9109 if (inst.operands[1].reg != 1)
477330fc 9110 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9111 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9112 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9113 do_vfp_nsyn_opcode ("fmstat");
9114 }
9115 else if (inst.operands[1].isvec)
9116 do_vfp_nsyn_opcode ("fmrx");
9117 else
9118 return FAIL;
5f4273c7 9119
037e8744
JB
9120 return SUCCESS;
9121}
9122
9123static int
9124do_vfp_nsyn_msr (void)
9125{
9126 if (inst.operands[0].isvec)
9127 do_vfp_nsyn_opcode ("fmxr");
9128 else
9129 return FAIL;
9130
9131 return SUCCESS;
9132}
9133
f7c21dc7
NC
9134static void
9135do_vmrs (void)
9136{
9137 unsigned Rt = inst.operands[0].reg;
fa94de6b 9138
16d02dc9 9139 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9140 {
9141 inst.error = BAD_SP;
9142 return;
9143 }
9144
9145 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9146 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9147 {
9148 inst.error = BAD_PC;
9149 return;
9150 }
9151
16d02dc9
JB
9152 /* If we get through parsing the register name, we just insert the number
9153 generated into the instruction without further validation. */
9154 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9155 inst.instruction |= (Rt << 12);
9156}
9157
9158static void
9159do_vmsr (void)
9160{
9161 unsigned Rt = inst.operands[1].reg;
fa94de6b 9162
f7c21dc7
NC
9163 if (thumb_mode)
9164 reject_bad_reg (Rt);
9165 else if (Rt == REG_PC)
9166 {
9167 inst.error = BAD_PC;
9168 return;
9169 }
9170
16d02dc9
JB
9171 /* If we get through parsing the register name, we just insert the number
9172 generated into the instruction without further validation. */
9173 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9174 inst.instruction |= (Rt << 12);
9175}
9176
b99bd4ef 9177static void
c19d1205 9178do_mrs (void)
b99bd4ef 9179{
90ec0d68
MGD
9180 unsigned br;
9181
037e8744
JB
9182 if (do_vfp_nsyn_mrs () == SUCCESS)
9183 return;
9184
ff4a8d2b 9185 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9186 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9187
9188 if (inst.operands[1].isreg)
9189 {
9190 br = inst.operands[1].reg;
9191 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9192 as_bad (_("bad register for mrs"));
9193 }
9194 else
9195 {
9196 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9197 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9198 != (PSR_c|PSR_f),
d2cd1205 9199 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9200 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9201 }
9202
9203 inst.instruction |= br;
c19d1205 9204}
b99bd4ef 9205
c19d1205
ZW
9206/* Two possible forms:
9207 "{C|S}PSR_<field>, Rm",
9208 "{C|S}PSR_f, #expression". */
b99bd4ef 9209
c19d1205
ZW
9210static void
9211do_msr (void)
9212{
037e8744
JB
9213 if (do_vfp_nsyn_msr () == SUCCESS)
9214 return;
9215
c19d1205
ZW
9216 inst.instruction |= inst.operands[0].imm;
9217 if (inst.operands[1].isreg)
9218 inst.instruction |= inst.operands[1].reg;
9219 else
b99bd4ef 9220 {
c19d1205
ZW
9221 inst.instruction |= INST_IMMEDIATE;
9222 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9223 inst.reloc.pc_rel = 0;
b99bd4ef 9224 }
b99bd4ef
NC
9225}
9226
c19d1205
ZW
9227static void
9228do_mul (void)
a737bd4d 9229{
ff4a8d2b
NC
9230 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9231
c19d1205
ZW
9232 if (!inst.operands[2].present)
9233 inst.operands[2].reg = inst.operands[0].reg;
9234 inst.instruction |= inst.operands[0].reg << 16;
9235 inst.instruction |= inst.operands[1].reg;
9236 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9237
8fb9d7b9
MS
9238 if (inst.operands[0].reg == inst.operands[1].reg
9239 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9240 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9241}
9242
c19d1205
ZW
9243/* Long Multiply Parser
9244 UMULL RdLo, RdHi, Rm, Rs
9245 SMULL RdLo, RdHi, Rm, Rs
9246 UMLAL RdLo, RdHi, Rm, Rs
9247 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9248
9249static void
c19d1205 9250do_mull (void)
b99bd4ef 9251{
c19d1205
ZW
9252 inst.instruction |= inst.operands[0].reg << 12;
9253 inst.instruction |= inst.operands[1].reg << 16;
9254 inst.instruction |= inst.operands[2].reg;
9255 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9256
682b27ad
PB
9257 /* rdhi and rdlo must be different. */
9258 if (inst.operands[0].reg == inst.operands[1].reg)
9259 as_tsktsk (_("rdhi and rdlo must be different"));
9260
9261 /* rdhi, rdlo and rm must all be different before armv6. */
9262 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9263 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9264 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9265 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9266}
b99bd4ef 9267
c19d1205
ZW
9268static void
9269do_nop (void)
9270{
e7495e45
NS
9271 if (inst.operands[0].present
9272 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9273 {
9274 /* Architectural NOP hints are CPSR sets with no bits selected. */
9275 inst.instruction &= 0xf0000000;
e7495e45
NS
9276 inst.instruction |= 0x0320f000;
9277 if (inst.operands[0].present)
9278 inst.instruction |= inst.operands[0].imm;
c19d1205 9279 }
b99bd4ef
NC
9280}
9281
c19d1205
ZW
9282/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9283 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9284 Condition defaults to COND_ALWAYS.
9285 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9286
9287static void
c19d1205 9288do_pkhbt (void)
b99bd4ef 9289{
c19d1205
ZW
9290 inst.instruction |= inst.operands[0].reg << 12;
9291 inst.instruction |= inst.operands[1].reg << 16;
9292 inst.instruction |= inst.operands[2].reg;
9293 if (inst.operands[3].present)
9294 encode_arm_shift (3);
9295}
b99bd4ef 9296
c19d1205 9297/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9298
c19d1205
ZW
9299static void
9300do_pkhtb (void)
9301{
9302 if (!inst.operands[3].present)
b99bd4ef 9303 {
c19d1205
ZW
9304 /* If the shift specifier is omitted, turn the instruction
9305 into pkhbt rd, rm, rn. */
9306 inst.instruction &= 0xfff00010;
9307 inst.instruction |= inst.operands[0].reg << 12;
9308 inst.instruction |= inst.operands[1].reg;
9309 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9310 }
9311 else
9312 {
c19d1205
ZW
9313 inst.instruction |= inst.operands[0].reg << 12;
9314 inst.instruction |= inst.operands[1].reg << 16;
9315 inst.instruction |= inst.operands[2].reg;
9316 encode_arm_shift (3);
b99bd4ef
NC
9317 }
9318}
9319
c19d1205 9320/* ARMv5TE: Preload-Cache
60e5ef9f 9321 MP Extensions: Preload for write
c19d1205 9322
60e5ef9f 9323 PLD(W) <addr_mode>
c19d1205
ZW
9324
9325 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9326
9327static void
c19d1205 9328do_pld (void)
b99bd4ef 9329{
c19d1205
ZW
9330 constraint (!inst.operands[0].isreg,
9331 _("'[' expected after PLD mnemonic"));
9332 constraint (inst.operands[0].postind,
9333 _("post-indexed expression used in preload instruction"));
9334 constraint (inst.operands[0].writeback,
9335 _("writeback used in preload instruction"));
9336 constraint (!inst.operands[0].preind,
9337 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9338 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9339}
b99bd4ef 9340
62b3e311
PB
9341/* ARMv7: PLI <addr_mode> */
9342static void
9343do_pli (void)
9344{
9345 constraint (!inst.operands[0].isreg,
9346 _("'[' expected after PLI mnemonic"));
9347 constraint (inst.operands[0].postind,
9348 _("post-indexed expression used in preload instruction"));
9349 constraint (inst.operands[0].writeback,
9350 _("writeback used in preload instruction"));
9351 constraint (!inst.operands[0].preind,
9352 _("unindexed addressing used in preload instruction"));
9353 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9354 inst.instruction &= ~PRE_INDEX;
9355}
9356
c19d1205
ZW
9357static void
9358do_push_pop (void)
9359{
5e0d7f77
MP
9360 constraint (inst.operands[0].writeback,
9361 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9362 inst.operands[1] = inst.operands[0];
9363 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9364 inst.operands[0].isreg = 1;
9365 inst.operands[0].writeback = 1;
9366 inst.operands[0].reg = REG_SP;
6530b175 9367 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9368}
b99bd4ef 9369
c19d1205
ZW
9370/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9371 word at the specified address and the following word
9372 respectively.
9373 Unconditionally executed.
9374 Error if Rn is R15. */
b99bd4ef 9375
c19d1205
ZW
9376static void
9377do_rfe (void)
9378{
9379 inst.instruction |= inst.operands[0].reg << 16;
9380 if (inst.operands[0].writeback)
9381 inst.instruction |= WRITE_BACK;
9382}
b99bd4ef 9383
c19d1205 9384/* ARM V6 ssat (argument parse). */
b99bd4ef 9385
c19d1205
ZW
9386static void
9387do_ssat (void)
9388{
9389 inst.instruction |= inst.operands[0].reg << 12;
9390 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9391 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9392
c19d1205
ZW
9393 if (inst.operands[3].present)
9394 encode_arm_shift (3);
b99bd4ef
NC
9395}
9396
c19d1205 9397/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9398
9399static void
c19d1205 9400do_usat (void)
b99bd4ef 9401{
c19d1205
ZW
9402 inst.instruction |= inst.operands[0].reg << 12;
9403 inst.instruction |= inst.operands[1].imm << 16;
9404 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9405
c19d1205
ZW
9406 if (inst.operands[3].present)
9407 encode_arm_shift (3);
b99bd4ef
NC
9408}
9409
c19d1205 9410/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9411
9412static void
c19d1205 9413do_ssat16 (void)
09d92015 9414{
c19d1205
ZW
9415 inst.instruction |= inst.operands[0].reg << 12;
9416 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9417 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9418}
9419
c19d1205
ZW
9420static void
9421do_usat16 (void)
a737bd4d 9422{
c19d1205
ZW
9423 inst.instruction |= inst.operands[0].reg << 12;
9424 inst.instruction |= inst.operands[1].imm << 16;
9425 inst.instruction |= inst.operands[2].reg;
9426}
a737bd4d 9427
c19d1205
ZW
9428/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9429 preserving the other bits.
a737bd4d 9430
c19d1205
ZW
9431 setend <endian_specifier>, where <endian_specifier> is either
9432 BE or LE. */
a737bd4d 9433
c19d1205
ZW
9434static void
9435do_setend (void)
9436{
12e37cbc
MGD
9437 if (warn_on_deprecated
9438 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9439 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9440
c19d1205
ZW
9441 if (inst.operands[0].imm)
9442 inst.instruction |= 0x200;
a737bd4d
NC
9443}
9444
9445static void
c19d1205 9446do_shift (void)
a737bd4d 9447{
c19d1205
ZW
9448 unsigned int Rm = (inst.operands[1].present
9449 ? inst.operands[1].reg
9450 : inst.operands[0].reg);
a737bd4d 9451
c19d1205
ZW
9452 inst.instruction |= inst.operands[0].reg << 12;
9453 inst.instruction |= Rm;
9454 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9455 {
c19d1205
ZW
9456 inst.instruction |= inst.operands[2].reg << 8;
9457 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9458 /* PR 12854: Error on extraneous shifts. */
9459 constraint (inst.operands[2].shifted,
9460 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9461 }
9462 else
c19d1205 9463 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9464}
9465
09d92015 9466static void
3eb17e6b 9467do_smc (void)
09d92015 9468{
3eb17e6b 9469 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9470 inst.reloc.pc_rel = 0;
09d92015
MM
9471}
9472
90ec0d68
MGD
9473static void
9474do_hvc (void)
9475{
9476 inst.reloc.type = BFD_RELOC_ARM_HVC;
9477 inst.reloc.pc_rel = 0;
9478}
9479
09d92015 9480static void
c19d1205 9481do_swi (void)
09d92015 9482{
c19d1205
ZW
9483 inst.reloc.type = BFD_RELOC_ARM_SWI;
9484 inst.reloc.pc_rel = 0;
09d92015
MM
9485}
9486
ddfded2f
MW
9487static void
9488do_setpan (void)
9489{
9490 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9491 _("selected processor does not support SETPAN instruction"));
9492
9493 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9494}
9495
9496static void
9497do_t_setpan (void)
9498{
9499 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9500 _("selected processor does not support SETPAN instruction"));
9501
9502 inst.instruction |= (inst.operands[0].imm << 3);
9503}
9504
c19d1205
ZW
9505/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9506 SMLAxy{cond} Rd,Rm,Rs,Rn
9507 SMLAWy{cond} Rd,Rm,Rs,Rn
9508 Error if any register is R15. */
e16bb312 9509
c19d1205
ZW
9510static void
9511do_smla (void)
e16bb312 9512{
c19d1205
ZW
9513 inst.instruction |= inst.operands[0].reg << 16;
9514 inst.instruction |= inst.operands[1].reg;
9515 inst.instruction |= inst.operands[2].reg << 8;
9516 inst.instruction |= inst.operands[3].reg << 12;
9517}
a737bd4d 9518
c19d1205
ZW
9519/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9520 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9521 Error if any register is R15.
9522 Warning if Rdlo == Rdhi. */
a737bd4d 9523
c19d1205
ZW
9524static void
9525do_smlal (void)
9526{
9527 inst.instruction |= inst.operands[0].reg << 12;
9528 inst.instruction |= inst.operands[1].reg << 16;
9529 inst.instruction |= inst.operands[2].reg;
9530 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9531
c19d1205
ZW
9532 if (inst.operands[0].reg == inst.operands[1].reg)
9533 as_tsktsk (_("rdhi and rdlo must be different"));
9534}
a737bd4d 9535
c19d1205
ZW
9536/* ARM V5E (El Segundo) signed-multiply (argument parse)
9537 SMULxy{cond} Rd,Rm,Rs
9538 Error if any register is R15. */
a737bd4d 9539
c19d1205
ZW
9540static void
9541do_smul (void)
9542{
9543 inst.instruction |= inst.operands[0].reg << 16;
9544 inst.instruction |= inst.operands[1].reg;
9545 inst.instruction |= inst.operands[2].reg << 8;
9546}
a737bd4d 9547
b6702015
PB
9548/* ARM V6 srs (argument parse). The variable fields in the encoding are
9549 the same for both ARM and Thumb-2. */
a737bd4d 9550
c19d1205
ZW
9551static void
9552do_srs (void)
9553{
b6702015
PB
9554 int reg;
9555
9556 if (inst.operands[0].present)
9557 {
9558 reg = inst.operands[0].reg;
fdfde340 9559 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9560 }
9561 else
fdfde340 9562 reg = REG_SP;
b6702015
PB
9563
9564 inst.instruction |= reg << 16;
9565 inst.instruction |= inst.operands[1].imm;
9566 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9567 inst.instruction |= WRITE_BACK;
9568}
a737bd4d 9569
c19d1205 9570/* ARM V6 strex (argument parse). */
a737bd4d 9571
c19d1205
ZW
9572static void
9573do_strex (void)
9574{
9575 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9576 || inst.operands[2].postind || inst.operands[2].writeback
9577 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9578 || inst.operands[2].negative
9579 /* See comment in do_ldrex(). */
9580 || (inst.operands[2].reg == REG_PC),
9581 BAD_ADDR_MODE);
a737bd4d 9582
c19d1205
ZW
9583 constraint (inst.operands[0].reg == inst.operands[1].reg
9584 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9585
c19d1205
ZW
9586 constraint (inst.reloc.exp.X_op != O_constant
9587 || inst.reloc.exp.X_add_number != 0,
9588 _("offset must be zero in ARM encoding"));
a737bd4d 9589
c19d1205
ZW
9590 inst.instruction |= inst.operands[0].reg << 12;
9591 inst.instruction |= inst.operands[1].reg;
9592 inst.instruction |= inst.operands[2].reg << 16;
9593 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9594}
9595
877807f8
NC
9596static void
9597do_t_strexbh (void)
9598{
9599 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9600 || inst.operands[2].postind || inst.operands[2].writeback
9601 || inst.operands[2].immisreg || inst.operands[2].shifted
9602 || inst.operands[2].negative,
9603 BAD_ADDR_MODE);
9604
9605 constraint (inst.operands[0].reg == inst.operands[1].reg
9606 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9607
9608 do_rm_rd_rn ();
9609}
9610
e16bb312 9611static void
c19d1205 9612do_strexd (void)
e16bb312 9613{
c19d1205
ZW
9614 constraint (inst.operands[1].reg % 2 != 0,
9615 _("even register required"));
9616 constraint (inst.operands[2].present
9617 && inst.operands[2].reg != inst.operands[1].reg + 1,
9618 _("can only store two consecutive registers"));
9619 /* If op 2 were present and equal to PC, this function wouldn't
9620 have been called in the first place. */
9621 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9622
c19d1205
ZW
9623 constraint (inst.operands[0].reg == inst.operands[1].reg
9624 || inst.operands[0].reg == inst.operands[1].reg + 1
9625 || inst.operands[0].reg == inst.operands[3].reg,
9626 BAD_OVERLAP);
e16bb312 9627
c19d1205
ZW
9628 inst.instruction |= inst.operands[0].reg << 12;
9629 inst.instruction |= inst.operands[1].reg;
9630 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9631}
9632
9eb6c0f1
MGD
9633/* ARM V8 STRL. */
9634static void
4b8c8c02 9635do_stlex (void)
9eb6c0f1
MGD
9636{
9637 constraint (inst.operands[0].reg == inst.operands[1].reg
9638 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9639
9640 do_rd_rm_rn ();
9641}
9642
9643static void
4b8c8c02 9644do_t_stlex (void)
9eb6c0f1
MGD
9645{
9646 constraint (inst.operands[0].reg == inst.operands[1].reg
9647 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9648
9649 do_rm_rd_rn ();
9650}
9651
c19d1205
ZW
9652/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9653 extends it to 32-bits, and adds the result to a value in another
9654 register. You can specify a rotation by 0, 8, 16, or 24 bits
9655 before extracting the 16-bit value.
9656 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9657 Condition defaults to COND_ALWAYS.
9658 Error if any register uses R15. */
9659
e16bb312 9660static void
c19d1205 9661do_sxtah (void)
e16bb312 9662{
c19d1205
ZW
9663 inst.instruction |= inst.operands[0].reg << 12;
9664 inst.instruction |= inst.operands[1].reg << 16;
9665 inst.instruction |= inst.operands[2].reg;
9666 inst.instruction |= inst.operands[3].imm << 10;
9667}
e16bb312 9668
c19d1205 9669/* ARM V6 SXTH.
e16bb312 9670
c19d1205
ZW
9671 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9672 Condition defaults to COND_ALWAYS.
9673 Error if any register uses R15. */
e16bb312
NC
9674
9675static void
c19d1205 9676do_sxth (void)
e16bb312 9677{
c19d1205
ZW
9678 inst.instruction |= inst.operands[0].reg << 12;
9679 inst.instruction |= inst.operands[1].reg;
9680 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9681}
c19d1205
ZW
9682\f
9683/* VFP instructions. In a logical order: SP variant first, monad
9684 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9685
9686static void
c19d1205 9687do_vfp_sp_monadic (void)
e16bb312 9688{
5287ad62
JB
9689 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9690 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9691}
9692
9693static void
c19d1205 9694do_vfp_sp_dyadic (void)
e16bb312 9695{
5287ad62
JB
9696 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9697 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9698 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9699}
9700
9701static void
c19d1205 9702do_vfp_sp_compare_z (void)
e16bb312 9703{
5287ad62 9704 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9705}
9706
9707static void
c19d1205 9708do_vfp_dp_sp_cvt (void)
e16bb312 9709{
5287ad62
JB
9710 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9711 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9712}
9713
9714static void
c19d1205 9715do_vfp_sp_dp_cvt (void)
e16bb312 9716{
5287ad62
JB
9717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9718 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9719}
9720
9721static void
c19d1205 9722do_vfp_reg_from_sp (void)
e16bb312 9723{
c19d1205 9724 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9725 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9726}
9727
9728static void
c19d1205 9729do_vfp_reg2_from_sp2 (void)
e16bb312 9730{
c19d1205
ZW
9731 constraint (inst.operands[2].imm != 2,
9732 _("only two consecutive VFP SP registers allowed here"));
9733 inst.instruction |= inst.operands[0].reg << 12;
9734 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9735 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9736}
9737
9738static void
c19d1205 9739do_vfp_sp_from_reg (void)
e16bb312 9740{
5287ad62 9741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9742 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9743}
9744
9745static void
c19d1205 9746do_vfp_sp2_from_reg2 (void)
e16bb312 9747{
c19d1205
ZW
9748 constraint (inst.operands[0].imm != 2,
9749 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9750 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9751 inst.instruction |= inst.operands[1].reg << 12;
9752 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9753}
9754
9755static void
c19d1205 9756do_vfp_sp_ldst (void)
e16bb312 9757{
5287ad62 9758 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9759 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9760}
9761
9762static void
c19d1205 9763do_vfp_dp_ldst (void)
e16bb312 9764{
5287ad62 9765 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9766 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9767}
9768
c19d1205 9769
e16bb312 9770static void
c19d1205 9771vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9772{
c19d1205
ZW
9773 if (inst.operands[0].writeback)
9774 inst.instruction |= WRITE_BACK;
9775 else
9776 constraint (ldstm_type != VFP_LDSTMIA,
9777 _("this addressing mode requires base-register writeback"));
9778 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9779 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9780 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9781}
9782
9783static void
c19d1205 9784vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9785{
c19d1205 9786 int count;
e16bb312 9787
c19d1205
ZW
9788 if (inst.operands[0].writeback)
9789 inst.instruction |= WRITE_BACK;
9790 else
9791 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9792 _("this addressing mode requires base-register writeback"));
e16bb312 9793
c19d1205 9794 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9795 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9796
c19d1205
ZW
9797 count = inst.operands[1].imm << 1;
9798 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9799 count += 1;
e16bb312 9800
c19d1205 9801 inst.instruction |= count;
e16bb312
NC
9802}
9803
9804static void
c19d1205 9805do_vfp_sp_ldstmia (void)
e16bb312 9806{
c19d1205 9807 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9808}
9809
9810static void
c19d1205 9811do_vfp_sp_ldstmdb (void)
e16bb312 9812{
c19d1205 9813 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9814}
9815
9816static void
c19d1205 9817do_vfp_dp_ldstmia (void)
e16bb312 9818{
c19d1205 9819 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9820}
9821
9822static void
c19d1205 9823do_vfp_dp_ldstmdb (void)
e16bb312 9824{
c19d1205 9825 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9826}
9827
9828static void
c19d1205 9829do_vfp_xp_ldstmia (void)
e16bb312 9830{
c19d1205
ZW
9831 vfp_dp_ldstm (VFP_LDSTMIAX);
9832}
e16bb312 9833
c19d1205
ZW
9834static void
9835do_vfp_xp_ldstmdb (void)
9836{
9837 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9838}
5287ad62
JB
9839
9840static void
9841do_vfp_dp_rd_rm (void)
9842{
9843 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9844 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9845}
9846
9847static void
9848do_vfp_dp_rn_rd (void)
9849{
9850 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9851 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9852}
9853
9854static void
9855do_vfp_dp_rd_rn (void)
9856{
9857 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9858 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9859}
9860
9861static void
9862do_vfp_dp_rd_rn_rm (void)
9863{
9864 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9865 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9866 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9867}
9868
9869static void
9870do_vfp_dp_rd (void)
9871{
9872 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9873}
9874
9875static void
9876do_vfp_dp_rm_rd_rn (void)
9877{
9878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9879 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9880 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9881}
9882
9883/* VFPv3 instructions. */
9884static void
9885do_vfp_sp_const (void)
9886{
9887 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9888 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9889 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9890}
9891
9892static void
9893do_vfp_dp_const (void)
9894{
9895 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9896 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9897 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9898}
9899
9900static void
9901vfp_conv (int srcsize)
9902{
5f1af56b
MGD
9903 int immbits = srcsize - inst.operands[1].imm;
9904
fa94de6b
RM
9905 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9906 {
5f1af56b 9907 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9908 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9909 inst.error = _("immediate value out of range, expected range [0, 16]");
9910 return;
9911 }
fa94de6b 9912 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9913 {
9914 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9915 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9916 inst.error = _("immediate value out of range, expected range [1, 32]");
9917 return;
9918 }
9919
5287ad62
JB
9920 inst.instruction |= (immbits & 1) << 5;
9921 inst.instruction |= (immbits >> 1);
9922}
9923
9924static void
9925do_vfp_sp_conv_16 (void)
9926{
9927 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9928 vfp_conv (16);
9929}
9930
9931static void
9932do_vfp_dp_conv_16 (void)
9933{
9934 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9935 vfp_conv (16);
9936}
9937
9938static void
9939do_vfp_sp_conv_32 (void)
9940{
9941 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9942 vfp_conv (32);
9943}
9944
9945static void
9946do_vfp_dp_conv_32 (void)
9947{
9948 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9949 vfp_conv (32);
9950}
c19d1205
ZW
9951\f
9952/* FPA instructions. Also in a logical order. */
e16bb312 9953
c19d1205
ZW
9954static void
9955do_fpa_cmp (void)
9956{
9957 inst.instruction |= inst.operands[0].reg << 16;
9958 inst.instruction |= inst.operands[1].reg;
9959}
b99bd4ef
NC
9960
9961static void
c19d1205 9962do_fpa_ldmstm (void)
b99bd4ef 9963{
c19d1205
ZW
9964 inst.instruction |= inst.operands[0].reg << 12;
9965 switch (inst.operands[1].imm)
9966 {
9967 case 1: inst.instruction |= CP_T_X; break;
9968 case 2: inst.instruction |= CP_T_Y; break;
9969 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9970 case 4: break;
9971 default: abort ();
9972 }
b99bd4ef 9973
c19d1205
ZW
9974 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9975 {
9976 /* The instruction specified "ea" or "fd", so we can only accept
9977 [Rn]{!}. The instruction does not really support stacking or
9978 unstacking, so we have to emulate these by setting appropriate
9979 bits and offsets. */
9980 constraint (inst.reloc.exp.X_op != O_constant
9981 || inst.reloc.exp.X_add_number != 0,
9982 _("this instruction does not support indexing"));
b99bd4ef 9983
c19d1205
ZW
9984 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9985 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9986
c19d1205
ZW
9987 if (!(inst.instruction & INDEX_UP))
9988 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9989
c19d1205
ZW
9990 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9991 {
9992 inst.operands[2].preind = 0;
9993 inst.operands[2].postind = 1;
9994 }
9995 }
b99bd4ef 9996
c19d1205 9997 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9998}
c19d1205
ZW
9999\f
10000/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10001
c19d1205
ZW
10002static void
10003do_iwmmxt_tandorc (void)
10004{
10005 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10006}
b99bd4ef 10007
c19d1205
ZW
10008static void
10009do_iwmmxt_textrc (void)
10010{
10011 inst.instruction |= inst.operands[0].reg << 12;
10012 inst.instruction |= inst.operands[1].imm;
10013}
b99bd4ef
NC
10014
10015static void
c19d1205 10016do_iwmmxt_textrm (void)
b99bd4ef 10017{
c19d1205
ZW
10018 inst.instruction |= inst.operands[0].reg << 12;
10019 inst.instruction |= inst.operands[1].reg << 16;
10020 inst.instruction |= inst.operands[2].imm;
10021}
b99bd4ef 10022
c19d1205
ZW
10023static void
10024do_iwmmxt_tinsr (void)
10025{
10026 inst.instruction |= inst.operands[0].reg << 16;
10027 inst.instruction |= inst.operands[1].reg << 12;
10028 inst.instruction |= inst.operands[2].imm;
10029}
b99bd4ef 10030
c19d1205
ZW
10031static void
10032do_iwmmxt_tmia (void)
10033{
10034 inst.instruction |= inst.operands[0].reg << 5;
10035 inst.instruction |= inst.operands[1].reg;
10036 inst.instruction |= inst.operands[2].reg << 12;
10037}
b99bd4ef 10038
c19d1205
ZW
10039static void
10040do_iwmmxt_waligni (void)
10041{
10042 inst.instruction |= inst.operands[0].reg << 12;
10043 inst.instruction |= inst.operands[1].reg << 16;
10044 inst.instruction |= inst.operands[2].reg;
10045 inst.instruction |= inst.operands[3].imm << 20;
10046}
b99bd4ef 10047
2d447fca
JM
10048static void
10049do_iwmmxt_wmerge (void)
10050{
10051 inst.instruction |= inst.operands[0].reg << 12;
10052 inst.instruction |= inst.operands[1].reg << 16;
10053 inst.instruction |= inst.operands[2].reg;
10054 inst.instruction |= inst.operands[3].imm << 21;
10055}
10056
c19d1205
ZW
10057static void
10058do_iwmmxt_wmov (void)
10059{
10060 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 inst.instruction |= inst.operands[1].reg << 16;
10063 inst.instruction |= inst.operands[1].reg;
10064}
b99bd4ef 10065
c19d1205
ZW
10066static void
10067do_iwmmxt_wldstbh (void)
10068{
8f06b2d8 10069 int reloc;
c19d1205 10070 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10071 if (thumb_mode)
10072 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10073 else
10074 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10075 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10076}
10077
c19d1205
ZW
10078static void
10079do_iwmmxt_wldstw (void)
10080{
10081 /* RIWR_RIWC clears .isreg for a control register. */
10082 if (!inst.operands[0].isreg)
10083 {
10084 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10085 inst.instruction |= 0xf0000000;
10086 }
b99bd4ef 10087
c19d1205
ZW
10088 inst.instruction |= inst.operands[0].reg << 12;
10089 encode_arm_cp_address (1, TRUE, TRUE, 0);
10090}
b99bd4ef
NC
10091
10092static void
c19d1205 10093do_iwmmxt_wldstd (void)
b99bd4ef 10094{
c19d1205 10095 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10096 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10097 && inst.operands[1].immisreg)
10098 {
10099 inst.instruction &= ~0x1a000ff;
eff0bc54 10100 inst.instruction |= (0xfU << 28);
2d447fca
JM
10101 if (inst.operands[1].preind)
10102 inst.instruction |= PRE_INDEX;
10103 if (!inst.operands[1].negative)
10104 inst.instruction |= INDEX_UP;
10105 if (inst.operands[1].writeback)
10106 inst.instruction |= WRITE_BACK;
10107 inst.instruction |= inst.operands[1].reg << 16;
10108 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10109 inst.instruction |= inst.operands[1].imm;
10110 }
10111 else
10112 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10113}
b99bd4ef 10114
c19d1205
ZW
10115static void
10116do_iwmmxt_wshufh (void)
10117{
10118 inst.instruction |= inst.operands[0].reg << 12;
10119 inst.instruction |= inst.operands[1].reg << 16;
10120 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10121 inst.instruction |= (inst.operands[2].imm & 0x0f);
10122}
b99bd4ef 10123
c19d1205
ZW
10124static void
10125do_iwmmxt_wzero (void)
10126{
10127 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10128 inst.instruction |= inst.operands[0].reg;
10129 inst.instruction |= inst.operands[0].reg << 12;
10130 inst.instruction |= inst.operands[0].reg << 16;
10131}
2d447fca
JM
10132
10133static void
10134do_iwmmxt_wrwrwr_or_imm5 (void)
10135{
10136 if (inst.operands[2].isreg)
10137 do_rd_rn_rm ();
10138 else {
10139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10140 _("immediate operand requires iWMMXt2"));
10141 do_rd_rn ();
10142 if (inst.operands[2].imm == 0)
10143 {
10144 switch ((inst.instruction >> 20) & 0xf)
10145 {
10146 case 4:
10147 case 5:
10148 case 6:
5f4273c7 10149 case 7:
2d447fca
JM
10150 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10151 inst.operands[2].imm = 16;
10152 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10153 break;
10154 case 8:
10155 case 9:
10156 case 10:
10157 case 11:
10158 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10159 inst.operands[2].imm = 32;
10160 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10161 break;
10162 case 12:
10163 case 13:
10164 case 14:
10165 case 15:
10166 {
10167 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10168 unsigned long wrn;
10169 wrn = (inst.instruction >> 16) & 0xf;
10170 inst.instruction &= 0xff0fff0f;
10171 inst.instruction |= wrn;
10172 /* Bail out here; the instruction is now assembled. */
10173 return;
10174 }
10175 }
10176 }
10177 /* Map 32 -> 0, etc. */
10178 inst.operands[2].imm &= 0x1f;
eff0bc54 10179 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10180 }
10181}
c19d1205
ZW
10182\f
10183/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10184 operations first, then control, shift, and load/store. */
b99bd4ef 10185
c19d1205 10186/* Insns like "foo X,Y,Z". */
b99bd4ef 10187
c19d1205
ZW
10188static void
10189do_mav_triple (void)
10190{
10191 inst.instruction |= inst.operands[0].reg << 16;
10192 inst.instruction |= inst.operands[1].reg;
10193 inst.instruction |= inst.operands[2].reg << 12;
10194}
b99bd4ef 10195
c19d1205
ZW
10196/* Insns like "foo W,X,Y,Z".
10197 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10198
c19d1205
ZW
10199static void
10200do_mav_quad (void)
10201{
10202 inst.instruction |= inst.operands[0].reg << 5;
10203 inst.instruction |= inst.operands[1].reg << 12;
10204 inst.instruction |= inst.operands[2].reg << 16;
10205 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10206}
10207
c19d1205
ZW
10208/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10209static void
10210do_mav_dspsc (void)
a737bd4d 10211{
c19d1205
ZW
10212 inst.instruction |= inst.operands[1].reg << 12;
10213}
a737bd4d 10214
c19d1205
ZW
10215/* Maverick shift immediate instructions.
10216 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10217 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10218
c19d1205
ZW
10219static void
10220do_mav_shift (void)
10221{
10222 int imm = inst.operands[2].imm;
a737bd4d 10223
c19d1205
ZW
10224 inst.instruction |= inst.operands[0].reg << 12;
10225 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10226
c19d1205
ZW
10227 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10228 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10229 Bit 4 should be 0. */
10230 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10231
c19d1205
ZW
10232 inst.instruction |= imm;
10233}
10234\f
10235/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10236
c19d1205
ZW
10237/* Xscale multiply-accumulate (argument parse)
10238 MIAcc acc0,Rm,Rs
10239 MIAPHcc acc0,Rm,Rs
10240 MIAxycc acc0,Rm,Rs. */
a737bd4d 10241
c19d1205
ZW
10242static void
10243do_xsc_mia (void)
10244{
10245 inst.instruction |= inst.operands[1].reg;
10246 inst.instruction |= inst.operands[2].reg << 12;
10247}
a737bd4d 10248
c19d1205 10249/* Xscale move-accumulator-register (argument parse)
a737bd4d 10250
c19d1205 10251 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10252
c19d1205
ZW
10253static void
10254do_xsc_mar (void)
10255{
10256 inst.instruction |= inst.operands[1].reg << 12;
10257 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10258}
10259
c19d1205 10260/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10261
c19d1205 10262 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10263
10264static void
c19d1205 10265do_xsc_mra (void)
b99bd4ef 10266{
c19d1205
ZW
10267 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10268 inst.instruction |= inst.operands[0].reg << 12;
10269 inst.instruction |= inst.operands[1].reg << 16;
10270}
10271\f
10272/* Encoding functions relevant only to Thumb. */
b99bd4ef 10273
c19d1205
ZW
10274/* inst.operands[i] is a shifted-register operand; encode
10275 it into inst.instruction in the format used by Thumb32. */
10276
10277static void
10278encode_thumb32_shifted_operand (int i)
10279{
10280 unsigned int value = inst.reloc.exp.X_add_number;
10281 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10282
9c3c69f2
PB
10283 constraint (inst.operands[i].immisreg,
10284 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10285 inst.instruction |= inst.operands[i].reg;
10286 if (shift == SHIFT_RRX)
10287 inst.instruction |= SHIFT_ROR << 4;
10288 else
b99bd4ef 10289 {
c19d1205
ZW
10290 constraint (inst.reloc.exp.X_op != O_constant,
10291 _("expression too complex"));
10292
10293 constraint (value > 32
10294 || (value == 32 && (shift == SHIFT_LSL
10295 || shift == SHIFT_ROR)),
10296 _("shift expression is too large"));
10297
10298 if (value == 0)
10299 shift = SHIFT_LSL;
10300 else if (value == 32)
10301 value = 0;
10302
10303 inst.instruction |= shift << 4;
10304 inst.instruction |= (value & 0x1c) << 10;
10305 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10306 }
c19d1205 10307}
b99bd4ef 10308
b99bd4ef 10309
c19d1205
ZW
10310/* inst.operands[i] was set up by parse_address. Encode it into a
10311 Thumb32 format load or store instruction. Reject forms that cannot
10312 be used with such instructions. If is_t is true, reject forms that
10313 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10314 that cannot be used with a D instruction. If it is a store insn,
10315 reject PC in Rn. */
b99bd4ef 10316
c19d1205
ZW
10317static void
10318encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10319{
5be8be5d 10320 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10321
10322 constraint (!inst.operands[i].isreg,
53365c0d 10323 _("Instruction does not support =N addresses"));
b99bd4ef 10324
c19d1205
ZW
10325 inst.instruction |= inst.operands[i].reg << 16;
10326 if (inst.operands[i].immisreg)
b99bd4ef 10327 {
5be8be5d 10328 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10329 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10330 constraint (inst.operands[i].negative,
10331 _("Thumb does not support negative register indexing"));
10332 constraint (inst.operands[i].postind,
10333 _("Thumb does not support register post-indexing"));
10334 constraint (inst.operands[i].writeback,
10335 _("Thumb does not support register indexing with writeback"));
10336 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10337 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10338
f40d1643 10339 inst.instruction |= inst.operands[i].imm;
c19d1205 10340 if (inst.operands[i].shifted)
b99bd4ef 10341 {
c19d1205
ZW
10342 constraint (inst.reloc.exp.X_op != O_constant,
10343 _("expression too complex"));
9c3c69f2
PB
10344 constraint (inst.reloc.exp.X_add_number < 0
10345 || inst.reloc.exp.X_add_number > 3,
c19d1205 10346 _("shift out of range"));
9c3c69f2 10347 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10348 }
10349 inst.reloc.type = BFD_RELOC_UNUSED;
10350 }
10351 else if (inst.operands[i].preind)
10352 {
5be8be5d 10353 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10354 constraint (is_t && inst.operands[i].writeback,
c19d1205 10355 _("cannot use writeback with this instruction"));
4755303e
WN
10356 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10357 BAD_PC_ADDRESSING);
c19d1205
ZW
10358
10359 if (is_d)
10360 {
10361 inst.instruction |= 0x01000000;
10362 if (inst.operands[i].writeback)
10363 inst.instruction |= 0x00200000;
b99bd4ef 10364 }
c19d1205 10365 else
b99bd4ef 10366 {
c19d1205
ZW
10367 inst.instruction |= 0x00000c00;
10368 if (inst.operands[i].writeback)
10369 inst.instruction |= 0x00000100;
b99bd4ef 10370 }
c19d1205 10371 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10372 }
c19d1205 10373 else if (inst.operands[i].postind)
b99bd4ef 10374 {
9c2799c2 10375 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10376 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10377 constraint (is_t, _("cannot use post-indexing with this instruction"));
10378
10379 if (is_d)
10380 inst.instruction |= 0x00200000;
10381 else
10382 inst.instruction |= 0x00000900;
10383 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10384 }
10385 else /* unindexed - only for coprocessor */
10386 inst.error = _("instruction does not accept unindexed addressing");
10387}
10388
10389/* Table of Thumb instructions which exist in both 16- and 32-bit
10390 encodings (the latter only in post-V6T2 cores). The index is the
10391 value used in the insns table below. When there is more than one
10392 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10393 holds variant (1).
10394 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10395#define T16_32_TAB \
21d799b5
NC
10396 X(_adc, 4140, eb400000), \
10397 X(_adcs, 4140, eb500000), \
10398 X(_add, 1c00, eb000000), \
10399 X(_adds, 1c00, eb100000), \
10400 X(_addi, 0000, f1000000), \
10401 X(_addis, 0000, f1100000), \
10402 X(_add_pc,000f, f20f0000), \
10403 X(_add_sp,000d, f10d0000), \
10404 X(_adr, 000f, f20f0000), \
10405 X(_and, 4000, ea000000), \
10406 X(_ands, 4000, ea100000), \
10407 X(_asr, 1000, fa40f000), \
10408 X(_asrs, 1000, fa50f000), \
10409 X(_b, e000, f000b000), \
10410 X(_bcond, d000, f0008000), \
10411 X(_bic, 4380, ea200000), \
10412 X(_bics, 4380, ea300000), \
10413 X(_cmn, 42c0, eb100f00), \
10414 X(_cmp, 2800, ebb00f00), \
10415 X(_cpsie, b660, f3af8400), \
10416 X(_cpsid, b670, f3af8600), \
10417 X(_cpy, 4600, ea4f0000), \
10418 X(_dec_sp,80dd, f1ad0d00), \
10419 X(_eor, 4040, ea800000), \
10420 X(_eors, 4040, ea900000), \
10421 X(_inc_sp,00dd, f10d0d00), \
10422 X(_ldmia, c800, e8900000), \
10423 X(_ldr, 6800, f8500000), \
10424 X(_ldrb, 7800, f8100000), \
10425 X(_ldrh, 8800, f8300000), \
10426 X(_ldrsb, 5600, f9100000), \
10427 X(_ldrsh, 5e00, f9300000), \
10428 X(_ldr_pc,4800, f85f0000), \
10429 X(_ldr_pc2,4800, f85f0000), \
10430 X(_ldr_sp,9800, f85d0000), \
10431 X(_lsl, 0000, fa00f000), \
10432 X(_lsls, 0000, fa10f000), \
10433 X(_lsr, 0800, fa20f000), \
10434 X(_lsrs, 0800, fa30f000), \
10435 X(_mov, 2000, ea4f0000), \
10436 X(_movs, 2000, ea5f0000), \
10437 X(_mul, 4340, fb00f000), \
10438 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10439 X(_mvn, 43c0, ea6f0000), \
10440 X(_mvns, 43c0, ea7f0000), \
10441 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10442 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10443 X(_orr, 4300, ea400000), \
10444 X(_orrs, 4300, ea500000), \
10445 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10446 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10447 X(_rev, ba00, fa90f080), \
10448 X(_rev16, ba40, fa90f090), \
10449 X(_revsh, bac0, fa90f0b0), \
10450 X(_ror, 41c0, fa60f000), \
10451 X(_rors, 41c0, fa70f000), \
10452 X(_sbc, 4180, eb600000), \
10453 X(_sbcs, 4180, eb700000), \
10454 X(_stmia, c000, e8800000), \
10455 X(_str, 6000, f8400000), \
10456 X(_strb, 7000, f8000000), \
10457 X(_strh, 8000, f8200000), \
10458 X(_str_sp,9000, f84d0000), \
10459 X(_sub, 1e00, eba00000), \
10460 X(_subs, 1e00, ebb00000), \
10461 X(_subi, 8000, f1a00000), \
10462 X(_subis, 8000, f1b00000), \
10463 X(_sxtb, b240, fa4ff080), \
10464 X(_sxth, b200, fa0ff080), \
10465 X(_tst, 4200, ea100f00), \
10466 X(_uxtb, b2c0, fa5ff080), \
10467 X(_uxth, b280, fa1ff080), \
10468 X(_nop, bf00, f3af8000), \
10469 X(_yield, bf10, f3af8001), \
10470 X(_wfe, bf20, f3af8002), \
10471 X(_wfi, bf30, f3af8003), \
53c4b28b 10472 X(_sev, bf40, f3af8004), \
74db7efb
NC
10473 X(_sevl, bf50, f3af8005), \
10474 X(_udf, de00, f7f0a000)
c19d1205
ZW
10475
10476/* To catch errors in encoding functions, the codes are all offset by
10477 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10478 as 16-bit instructions. */
21d799b5 10479#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10480enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10481#undef X
10482
10483#define X(a,b,c) 0x##b
10484static const unsigned short thumb_op16[] = { T16_32_TAB };
10485#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10486#undef X
10487
10488#define X(a,b,c) 0x##c
10489static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10490#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10491#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10492#undef X
10493#undef T16_32_TAB
10494
10495/* Thumb instruction encoders, in alphabetical order. */
10496
92e90b6e 10497/* ADDW or SUBW. */
c921be7d 10498
92e90b6e
PB
10499static void
10500do_t_add_sub_w (void)
10501{
10502 int Rd, Rn;
10503
10504 Rd = inst.operands[0].reg;
10505 Rn = inst.operands[1].reg;
10506
539d4391
NC
10507 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10508 is the SP-{plus,minus}-immediate form of the instruction. */
10509 if (Rn == REG_SP)
10510 constraint (Rd == REG_PC, BAD_PC);
10511 else
10512 reject_bad_reg (Rd);
fdfde340 10513
92e90b6e
PB
10514 inst.instruction |= (Rn << 16) | (Rd << 8);
10515 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10516}
10517
c19d1205 10518/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10519 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10520
10521static void
10522do_t_add_sub (void)
10523{
10524 int Rd, Rs, Rn;
10525
10526 Rd = inst.operands[0].reg;
10527 Rs = (inst.operands[1].present
10528 ? inst.operands[1].reg /* Rd, Rs, foo */
10529 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10530
e07e6e58
NC
10531 if (Rd == REG_PC)
10532 set_it_insn_type_last ();
10533
c19d1205
ZW
10534 if (unified_syntax)
10535 {
0110f2b8
PB
10536 bfd_boolean flags;
10537 bfd_boolean narrow;
10538 int opcode;
10539
10540 flags = (inst.instruction == T_MNEM_adds
10541 || inst.instruction == T_MNEM_subs);
10542 if (flags)
e07e6e58 10543 narrow = !in_it_block ();
0110f2b8 10544 else
e07e6e58 10545 narrow = in_it_block ();
c19d1205 10546 if (!inst.operands[2].isreg)
b99bd4ef 10547 {
16805f35
PB
10548 int add;
10549
5c8ed6a4
JW
10550 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10551 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10552
16805f35
PB
10553 add = (inst.instruction == T_MNEM_add
10554 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10555 opcode = 0;
10556 if (inst.size_req != 4)
10557 {
0110f2b8 10558 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10559 appropriate. */
0110f2b8
PB
10560 if (Rd == REG_SP && Rs == REG_SP && !flags)
10561 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10562 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10563 opcode = T_MNEM_add_sp;
10564 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10565 opcode = T_MNEM_add_pc;
10566 else if (Rd <= 7 && Rs <= 7 && narrow)
10567 {
10568 if (flags)
10569 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10570 else
10571 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10572 }
10573 if (opcode)
10574 {
10575 inst.instruction = THUMB_OP16(opcode);
10576 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10577 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10578 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10579 {
10580 if (inst.size_req == 2)
10581 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10582 else
10583 inst.relax = opcode;
10584 }
0110f2b8
PB
10585 }
10586 else
10587 constraint (inst.size_req == 2, BAD_HIREG);
10588 }
10589 if (inst.size_req == 4
10590 || (inst.size_req != 2 && !opcode))
10591 {
a9f02af8
MG
10592 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10593 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10594 THUMB1_RELOC_ONLY);
efd81785
PB
10595 if (Rd == REG_PC)
10596 {
fdfde340 10597 constraint (add, BAD_PC);
efd81785
PB
10598 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10599 _("only SUBS PC, LR, #const allowed"));
10600 constraint (inst.reloc.exp.X_op != O_constant,
10601 _("expression too complex"));
10602 constraint (inst.reloc.exp.X_add_number < 0
10603 || inst.reloc.exp.X_add_number > 0xff,
10604 _("immediate value out of range"));
10605 inst.instruction = T2_SUBS_PC_LR
10606 | inst.reloc.exp.X_add_number;
10607 inst.reloc.type = BFD_RELOC_UNUSED;
10608 return;
10609 }
10610 else if (Rs == REG_PC)
16805f35
PB
10611 {
10612 /* Always use addw/subw. */
10613 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10614 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10615 }
10616 else
10617 {
10618 inst.instruction = THUMB_OP32 (inst.instruction);
10619 inst.instruction = (inst.instruction & 0xe1ffffff)
10620 | 0x10000000;
10621 if (flags)
10622 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10623 else
10624 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10625 }
dc4503c6
PB
10626 inst.instruction |= Rd << 8;
10627 inst.instruction |= Rs << 16;
0110f2b8 10628 }
b99bd4ef 10629 }
c19d1205
ZW
10630 else
10631 {
5f4cb198
NC
10632 unsigned int value = inst.reloc.exp.X_add_number;
10633 unsigned int shift = inst.operands[2].shift_kind;
10634
c19d1205
ZW
10635 Rn = inst.operands[2].reg;
10636 /* See if we can do this with a 16-bit instruction. */
10637 if (!inst.operands[2].shifted && inst.size_req != 4)
10638 {
e27ec89e
PB
10639 if (Rd > 7 || Rs > 7 || Rn > 7)
10640 narrow = FALSE;
10641
10642 if (narrow)
c19d1205 10643 {
e27ec89e
PB
10644 inst.instruction = ((inst.instruction == T_MNEM_adds
10645 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10646 ? T_OPCODE_ADD_R3
10647 : T_OPCODE_SUB_R3);
10648 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10649 return;
10650 }
b99bd4ef 10651
7e806470 10652 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10653 {
7e806470
PB
10654 /* Thumb-1 cores (except v6-M) require at least one high
10655 register in a narrow non flag setting add. */
10656 if (Rd > 7 || Rn > 7
10657 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10658 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10659 {
7e806470
PB
10660 if (Rd == Rn)
10661 {
10662 Rn = Rs;
10663 Rs = Rd;
10664 }
c19d1205
ZW
10665 inst.instruction = T_OPCODE_ADD_HI;
10666 inst.instruction |= (Rd & 8) << 4;
10667 inst.instruction |= (Rd & 7);
10668 inst.instruction |= Rn << 3;
10669 return;
10670 }
c19d1205
ZW
10671 }
10672 }
c921be7d 10673
fdfde340 10674 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10675 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10676 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10677 constraint (Rs == REG_PC, BAD_PC);
10678 reject_bad_reg (Rn);
10679
c19d1205
ZW
10680 /* If we get here, it can't be done in 16 bits. */
10681 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10682 _("shift must be constant"));
10683 inst.instruction = THUMB_OP32 (inst.instruction);
10684 inst.instruction |= Rd << 8;
10685 inst.instruction |= Rs << 16;
5f4cb198
NC
10686 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10687 _("shift value over 3 not allowed in thumb mode"));
10688 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10689 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10690 encode_thumb32_shifted_operand (2);
10691 }
10692 }
10693 else
10694 {
10695 constraint (inst.instruction == T_MNEM_adds
10696 || inst.instruction == T_MNEM_subs,
10697 BAD_THUMB32);
b99bd4ef 10698
c19d1205 10699 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10700 {
c19d1205
ZW
10701 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10702 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10703 BAD_HIREG);
10704
10705 inst.instruction = (inst.instruction == T_MNEM_add
10706 ? 0x0000 : 0x8000);
10707 inst.instruction |= (Rd << 4) | Rs;
10708 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10709 return;
10710 }
10711
c19d1205
ZW
10712 Rn = inst.operands[2].reg;
10713 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10714
c19d1205
ZW
10715 /* We now have Rd, Rs, and Rn set to registers. */
10716 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10717 {
c19d1205
ZW
10718 /* Can't do this for SUB. */
10719 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10720 inst.instruction = T_OPCODE_ADD_HI;
10721 inst.instruction |= (Rd & 8) << 4;
10722 inst.instruction |= (Rd & 7);
10723 if (Rs == Rd)
10724 inst.instruction |= Rn << 3;
10725 else if (Rn == Rd)
10726 inst.instruction |= Rs << 3;
10727 else
10728 constraint (1, _("dest must overlap one source register"));
10729 }
10730 else
10731 {
10732 inst.instruction = (inst.instruction == T_MNEM_add
10733 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10734 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10735 }
b99bd4ef 10736 }
b99bd4ef
NC
10737}
10738
c19d1205
ZW
10739static void
10740do_t_adr (void)
10741{
fdfde340
JM
10742 unsigned Rd;
10743
10744 Rd = inst.operands[0].reg;
10745 reject_bad_reg (Rd);
10746
10747 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10748 {
10749 /* Defer to section relaxation. */
10750 inst.relax = inst.instruction;
10751 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10752 inst.instruction |= Rd << 4;
0110f2b8
PB
10753 }
10754 else if (unified_syntax && inst.size_req != 2)
e9f89963 10755 {
0110f2b8 10756 /* Generate a 32-bit opcode. */
e9f89963 10757 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10758 inst.instruction |= Rd << 8;
e9f89963
PB
10759 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10760 inst.reloc.pc_rel = 1;
10761 }
10762 else
10763 {
0110f2b8 10764 /* Generate a 16-bit opcode. */
e9f89963
PB
10765 inst.instruction = THUMB_OP16 (inst.instruction);
10766 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10767 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10768 inst.reloc.pc_rel = 1;
fdfde340 10769 inst.instruction |= Rd << 4;
e9f89963 10770 }
52a86f84
NC
10771
10772 if (inst.reloc.exp.X_op == O_symbol
10773 && inst.reloc.exp.X_add_symbol != NULL
10774 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10775 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10776 inst.reloc.exp.X_add_number += 1;
c19d1205 10777}
b99bd4ef 10778
c19d1205
ZW
10779/* Arithmetic instructions for which there is just one 16-bit
10780 instruction encoding, and it allows only two low registers.
10781 For maximal compatibility with ARM syntax, we allow three register
10782 operands even when Thumb-32 instructions are not available, as long
10783 as the first two are identical. For instance, both "sbc r0,r1" and
10784 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10785static void
c19d1205 10786do_t_arit3 (void)
b99bd4ef 10787{
c19d1205 10788 int Rd, Rs, Rn;
b99bd4ef 10789
c19d1205
ZW
10790 Rd = inst.operands[0].reg;
10791 Rs = (inst.operands[1].present
10792 ? inst.operands[1].reg /* Rd, Rs, foo */
10793 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10794 Rn = inst.operands[2].reg;
b99bd4ef 10795
fdfde340
JM
10796 reject_bad_reg (Rd);
10797 reject_bad_reg (Rs);
10798 if (inst.operands[2].isreg)
10799 reject_bad_reg (Rn);
10800
c19d1205 10801 if (unified_syntax)
b99bd4ef 10802 {
c19d1205
ZW
10803 if (!inst.operands[2].isreg)
10804 {
10805 /* For an immediate, we always generate a 32-bit opcode;
10806 section relaxation will shrink it later if possible. */
10807 inst.instruction = THUMB_OP32 (inst.instruction);
10808 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10809 inst.instruction |= Rd << 8;
10810 inst.instruction |= Rs << 16;
10811 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10812 }
10813 else
10814 {
e27ec89e
PB
10815 bfd_boolean narrow;
10816
c19d1205 10817 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10818 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10819 narrow = !in_it_block ();
e27ec89e 10820 else
e07e6e58 10821 narrow = in_it_block ();
e27ec89e
PB
10822
10823 if (Rd > 7 || Rn > 7 || Rs > 7)
10824 narrow = FALSE;
10825 if (inst.operands[2].shifted)
10826 narrow = FALSE;
10827 if (inst.size_req == 4)
10828 narrow = FALSE;
10829
10830 if (narrow
c19d1205
ZW
10831 && Rd == Rs)
10832 {
10833 inst.instruction = THUMB_OP16 (inst.instruction);
10834 inst.instruction |= Rd;
10835 inst.instruction |= Rn << 3;
10836 return;
10837 }
b99bd4ef 10838
c19d1205
ZW
10839 /* If we get here, it can't be done in 16 bits. */
10840 constraint (inst.operands[2].shifted
10841 && inst.operands[2].immisreg,
10842 _("shift must be constant"));
10843 inst.instruction = THUMB_OP32 (inst.instruction);
10844 inst.instruction |= Rd << 8;
10845 inst.instruction |= Rs << 16;
10846 encode_thumb32_shifted_operand (2);
10847 }
a737bd4d 10848 }
c19d1205 10849 else
b99bd4ef 10850 {
c19d1205
ZW
10851 /* On its face this is a lie - the instruction does set the
10852 flags. However, the only supported mnemonic in this mode
10853 says it doesn't. */
10854 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10855
c19d1205
ZW
10856 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10857 _("unshifted register required"));
10858 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10859 constraint (Rd != Rs,
10860 _("dest and source1 must be the same register"));
a737bd4d 10861
c19d1205
ZW
10862 inst.instruction = THUMB_OP16 (inst.instruction);
10863 inst.instruction |= Rd;
10864 inst.instruction |= Rn << 3;
b99bd4ef 10865 }
a737bd4d 10866}
b99bd4ef 10867
c19d1205
ZW
10868/* Similarly, but for instructions where the arithmetic operation is
10869 commutative, so we can allow either of them to be different from
10870 the destination operand in a 16-bit instruction. For instance, all
10871 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10872 accepted. */
10873static void
10874do_t_arit3c (void)
a737bd4d 10875{
c19d1205 10876 int Rd, Rs, Rn;
b99bd4ef 10877
c19d1205
ZW
10878 Rd = inst.operands[0].reg;
10879 Rs = (inst.operands[1].present
10880 ? inst.operands[1].reg /* Rd, Rs, foo */
10881 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10882 Rn = inst.operands[2].reg;
c921be7d 10883
fdfde340
JM
10884 reject_bad_reg (Rd);
10885 reject_bad_reg (Rs);
10886 if (inst.operands[2].isreg)
10887 reject_bad_reg (Rn);
a737bd4d 10888
c19d1205 10889 if (unified_syntax)
a737bd4d 10890 {
c19d1205 10891 if (!inst.operands[2].isreg)
b99bd4ef 10892 {
c19d1205
ZW
10893 /* For an immediate, we always generate a 32-bit opcode;
10894 section relaxation will shrink it later if possible. */
10895 inst.instruction = THUMB_OP32 (inst.instruction);
10896 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10897 inst.instruction |= Rd << 8;
10898 inst.instruction |= Rs << 16;
10899 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10900 }
c19d1205 10901 else
a737bd4d 10902 {
e27ec89e
PB
10903 bfd_boolean narrow;
10904
c19d1205 10905 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10906 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10907 narrow = !in_it_block ();
e27ec89e 10908 else
e07e6e58 10909 narrow = in_it_block ();
e27ec89e
PB
10910
10911 if (Rd > 7 || Rn > 7 || Rs > 7)
10912 narrow = FALSE;
10913 if (inst.operands[2].shifted)
10914 narrow = FALSE;
10915 if (inst.size_req == 4)
10916 narrow = FALSE;
10917
10918 if (narrow)
a737bd4d 10919 {
c19d1205 10920 if (Rd == Rs)
a737bd4d 10921 {
c19d1205
ZW
10922 inst.instruction = THUMB_OP16 (inst.instruction);
10923 inst.instruction |= Rd;
10924 inst.instruction |= Rn << 3;
10925 return;
a737bd4d 10926 }
c19d1205 10927 if (Rd == Rn)
a737bd4d 10928 {
c19d1205
ZW
10929 inst.instruction = THUMB_OP16 (inst.instruction);
10930 inst.instruction |= Rd;
10931 inst.instruction |= Rs << 3;
10932 return;
a737bd4d
NC
10933 }
10934 }
c19d1205
ZW
10935
10936 /* If we get here, it can't be done in 16 bits. */
10937 constraint (inst.operands[2].shifted
10938 && inst.operands[2].immisreg,
10939 _("shift must be constant"));
10940 inst.instruction = THUMB_OP32 (inst.instruction);
10941 inst.instruction |= Rd << 8;
10942 inst.instruction |= Rs << 16;
10943 encode_thumb32_shifted_operand (2);
a737bd4d 10944 }
b99bd4ef 10945 }
c19d1205
ZW
10946 else
10947 {
10948 /* On its face this is a lie - the instruction does set the
10949 flags. However, the only supported mnemonic in this mode
10950 says it doesn't. */
10951 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10952
c19d1205
ZW
10953 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10954 _("unshifted register required"));
10955 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10956
10957 inst.instruction = THUMB_OP16 (inst.instruction);
10958 inst.instruction |= Rd;
10959
10960 if (Rd == Rs)
10961 inst.instruction |= Rn << 3;
10962 else if (Rd == Rn)
10963 inst.instruction |= Rs << 3;
10964 else
10965 constraint (1, _("dest must overlap one source register"));
10966 }
a737bd4d
NC
10967}
10968
c19d1205
ZW
10969static void
10970do_t_bfc (void)
a737bd4d 10971{
fdfde340 10972 unsigned Rd;
c19d1205
ZW
10973 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10974 constraint (msb > 32, _("bit-field extends past end of register"));
10975 /* The instruction encoding stores the LSB and MSB,
10976 not the LSB and width. */
fdfde340
JM
10977 Rd = inst.operands[0].reg;
10978 reject_bad_reg (Rd);
10979 inst.instruction |= Rd << 8;
c19d1205
ZW
10980 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10981 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10982 inst.instruction |= msb - 1;
b99bd4ef
NC
10983}
10984
c19d1205
ZW
10985static void
10986do_t_bfi (void)
b99bd4ef 10987{
fdfde340 10988 int Rd, Rn;
c19d1205 10989 unsigned int msb;
b99bd4ef 10990
fdfde340
JM
10991 Rd = inst.operands[0].reg;
10992 reject_bad_reg (Rd);
10993
c19d1205
ZW
10994 /* #0 in second position is alternative syntax for bfc, which is
10995 the same instruction but with REG_PC in the Rm field. */
10996 if (!inst.operands[1].isreg)
fdfde340
JM
10997 Rn = REG_PC;
10998 else
10999 {
11000 Rn = inst.operands[1].reg;
11001 reject_bad_reg (Rn);
11002 }
b99bd4ef 11003
c19d1205
ZW
11004 msb = inst.operands[2].imm + inst.operands[3].imm;
11005 constraint (msb > 32, _("bit-field extends past end of register"));
11006 /* The instruction encoding stores the LSB and MSB,
11007 not the LSB and width. */
fdfde340
JM
11008 inst.instruction |= Rd << 8;
11009 inst.instruction |= Rn << 16;
c19d1205
ZW
11010 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11011 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11012 inst.instruction |= msb - 1;
b99bd4ef
NC
11013}
11014
c19d1205
ZW
11015static void
11016do_t_bfx (void)
b99bd4ef 11017{
fdfde340
JM
11018 unsigned Rd, Rn;
11019
11020 Rd = inst.operands[0].reg;
11021 Rn = inst.operands[1].reg;
11022
11023 reject_bad_reg (Rd);
11024 reject_bad_reg (Rn);
11025
c19d1205
ZW
11026 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11027 _("bit-field extends past end of register"));
fdfde340
JM
11028 inst.instruction |= Rd << 8;
11029 inst.instruction |= Rn << 16;
c19d1205
ZW
11030 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11031 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11032 inst.instruction |= inst.operands[3].imm - 1;
11033}
b99bd4ef 11034
c19d1205
ZW
11035/* ARM V5 Thumb BLX (argument parse)
11036 BLX <target_addr> which is BLX(1)
11037 BLX <Rm> which is BLX(2)
11038 Unfortunately, there are two different opcodes for this mnemonic.
11039 So, the insns[].value is not used, and the code here zaps values
11040 into inst.instruction.
b99bd4ef 11041
c19d1205
ZW
11042 ??? How to take advantage of the additional two bits of displacement
11043 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11044
c19d1205
ZW
11045static void
11046do_t_blx (void)
11047{
e07e6e58
NC
11048 set_it_insn_type_last ();
11049
c19d1205 11050 if (inst.operands[0].isreg)
fdfde340
JM
11051 {
11052 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11053 /* We have a register, so this is BLX(2). */
11054 inst.instruction |= inst.operands[0].reg << 3;
11055 }
b99bd4ef
NC
11056 else
11057 {
c19d1205 11058 /* No register. This must be BLX(1). */
2fc8bdac 11059 inst.instruction = 0xf000e800;
0855e32b 11060 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11061 }
11062}
11063
c19d1205
ZW
11064static void
11065do_t_branch (void)
b99bd4ef 11066{
0110f2b8 11067 int opcode;
dfa9f0d5 11068 int cond;
2fe88214 11069 bfd_reloc_code_real_type reloc;
dfa9f0d5 11070
e07e6e58
NC
11071 cond = inst.cond;
11072 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11073
11074 if (in_it_block ())
dfa9f0d5
PB
11075 {
11076 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11077 branches. */
dfa9f0d5 11078 cond = COND_ALWAYS;
dfa9f0d5
PB
11079 }
11080 else
11081 cond = inst.cond;
11082
11083 if (cond != COND_ALWAYS)
0110f2b8
PB
11084 opcode = T_MNEM_bcond;
11085 else
11086 opcode = inst.instruction;
11087
12d6b0b7
RS
11088 if (unified_syntax
11089 && (inst.size_req == 4
10960bfb
PB
11090 || (inst.size_req != 2
11091 && (inst.operands[0].hasreloc
11092 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11093 {
0110f2b8 11094 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11095 if (cond == COND_ALWAYS)
9ae92b05 11096 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11097 else
11098 {
ff8646ee
TP
11099 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11100 _("selected architecture does not support "
11101 "wide conditional branch instruction"));
11102
9c2799c2 11103 gas_assert (cond != 0xF);
dfa9f0d5 11104 inst.instruction |= cond << 22;
9ae92b05 11105 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11106 }
11107 }
b99bd4ef
NC
11108 else
11109 {
0110f2b8 11110 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11111 if (cond == COND_ALWAYS)
9ae92b05 11112 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11113 else
b99bd4ef 11114 {
dfa9f0d5 11115 inst.instruction |= cond << 8;
9ae92b05 11116 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11117 }
0110f2b8
PB
11118 /* Allow section relaxation. */
11119 if (unified_syntax && inst.size_req != 2)
11120 inst.relax = opcode;
b99bd4ef 11121 }
9ae92b05 11122 inst.reloc.type = reloc;
c19d1205 11123 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11124}
11125
8884b720 11126/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11127 between the two is the maximum immediate allowed - which is passed in
8884b720 11128 RANGE. */
b99bd4ef 11129static void
8884b720 11130do_t_bkpt_hlt1 (int range)
b99bd4ef 11131{
dfa9f0d5
PB
11132 constraint (inst.cond != COND_ALWAYS,
11133 _("instruction is always unconditional"));
c19d1205 11134 if (inst.operands[0].present)
b99bd4ef 11135 {
8884b720 11136 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11137 _("immediate value out of range"));
11138 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11139 }
8884b720
MGD
11140
11141 set_it_insn_type (NEUTRAL_IT_INSN);
11142}
11143
11144static void
11145do_t_hlt (void)
11146{
11147 do_t_bkpt_hlt1 (63);
11148}
11149
11150static void
11151do_t_bkpt (void)
11152{
11153 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11154}
11155
11156static void
c19d1205 11157do_t_branch23 (void)
b99bd4ef 11158{
e07e6e58 11159 set_it_insn_type_last ();
0855e32b 11160 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11161
0855e32b
NS
11162 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11163 this file. We used to simply ignore the PLT reloc type here --
11164 the branch encoding is now needed to deal with TLSCALL relocs.
11165 So if we see a PLT reloc now, put it back to how it used to be to
11166 keep the preexisting behaviour. */
11167 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11168 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11169
4343666d 11170#if defined(OBJ_COFF)
c19d1205
ZW
11171 /* If the destination of the branch is a defined symbol which does not have
11172 the THUMB_FUNC attribute, then we must be calling a function which has
11173 the (interfacearm) attribute. We look for the Thumb entry point to that
11174 function and change the branch to refer to that function instead. */
11175 if ( inst.reloc.exp.X_op == O_symbol
11176 && inst.reloc.exp.X_add_symbol != NULL
11177 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11178 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11179 inst.reloc.exp.X_add_symbol =
11180 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11181#endif
90e4755a
RE
11182}
11183
11184static void
c19d1205 11185do_t_bx (void)
90e4755a 11186{
e07e6e58 11187 set_it_insn_type_last ();
c19d1205
ZW
11188 inst.instruction |= inst.operands[0].reg << 3;
11189 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11190 should cause the alignment to be checked once it is known. This is
11191 because BX PC only works if the instruction is word aligned. */
11192}
90e4755a 11193
c19d1205
ZW
11194static void
11195do_t_bxj (void)
11196{
fdfde340 11197 int Rm;
90e4755a 11198
e07e6e58 11199 set_it_insn_type_last ();
fdfde340
JM
11200 Rm = inst.operands[0].reg;
11201 reject_bad_reg (Rm);
11202 inst.instruction |= Rm << 16;
90e4755a
RE
11203}
11204
11205static void
c19d1205 11206do_t_clz (void)
90e4755a 11207{
fdfde340
JM
11208 unsigned Rd;
11209 unsigned Rm;
11210
11211 Rd = inst.operands[0].reg;
11212 Rm = inst.operands[1].reg;
11213
11214 reject_bad_reg (Rd);
11215 reject_bad_reg (Rm);
11216
11217 inst.instruction |= Rd << 8;
11218 inst.instruction |= Rm << 16;
11219 inst.instruction |= Rm;
c19d1205 11220}
90e4755a 11221
dfa9f0d5
PB
11222static void
11223do_t_cps (void)
11224{
e07e6e58 11225 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11226 inst.instruction |= inst.operands[0].imm;
11227}
11228
c19d1205
ZW
11229static void
11230do_t_cpsi (void)
11231{
e07e6e58 11232 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11233 if (unified_syntax
62b3e311
PB
11234 && (inst.operands[1].present || inst.size_req == 4)
11235 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11236 {
c19d1205
ZW
11237 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11238 inst.instruction = 0xf3af8000;
11239 inst.instruction |= imod << 9;
11240 inst.instruction |= inst.operands[0].imm << 5;
11241 if (inst.operands[1].present)
11242 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11243 }
c19d1205 11244 else
90e4755a 11245 {
62b3e311
PB
11246 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11247 && (inst.operands[0].imm & 4),
11248 _("selected processor does not support 'A' form "
11249 "of this instruction"));
11250 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11251 _("Thumb does not support the 2-argument "
11252 "form of this instruction"));
11253 inst.instruction |= inst.operands[0].imm;
90e4755a 11254 }
90e4755a
RE
11255}
11256
c19d1205
ZW
11257/* THUMB CPY instruction (argument parse). */
11258
90e4755a 11259static void
c19d1205 11260do_t_cpy (void)
90e4755a 11261{
c19d1205 11262 if (inst.size_req == 4)
90e4755a 11263 {
c19d1205
ZW
11264 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11265 inst.instruction |= inst.operands[0].reg << 8;
11266 inst.instruction |= inst.operands[1].reg;
90e4755a 11267 }
c19d1205 11268 else
90e4755a 11269 {
c19d1205
ZW
11270 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11271 inst.instruction |= (inst.operands[0].reg & 0x7);
11272 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11273 }
90e4755a
RE
11274}
11275
90e4755a 11276static void
25fe350b 11277do_t_cbz (void)
90e4755a 11278{
e07e6e58 11279 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11280 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11281 inst.instruction |= inst.operands[0].reg;
11282 inst.reloc.pc_rel = 1;
11283 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11284}
90e4755a 11285
62b3e311
PB
11286static void
11287do_t_dbg (void)
11288{
11289 inst.instruction |= inst.operands[0].imm;
11290}
11291
11292static void
11293do_t_div (void)
11294{
fdfde340
JM
11295 unsigned Rd, Rn, Rm;
11296
11297 Rd = inst.operands[0].reg;
11298 Rn = (inst.operands[1].present
11299 ? inst.operands[1].reg : Rd);
11300 Rm = inst.operands[2].reg;
11301
11302 reject_bad_reg (Rd);
11303 reject_bad_reg (Rn);
11304 reject_bad_reg (Rm);
11305
11306 inst.instruction |= Rd << 8;
11307 inst.instruction |= Rn << 16;
11308 inst.instruction |= Rm;
62b3e311
PB
11309}
11310
c19d1205
ZW
11311static void
11312do_t_hint (void)
11313{
11314 if (unified_syntax && inst.size_req == 4)
11315 inst.instruction = THUMB_OP32 (inst.instruction);
11316 else
11317 inst.instruction = THUMB_OP16 (inst.instruction);
11318}
90e4755a 11319
c19d1205
ZW
11320static void
11321do_t_it (void)
11322{
11323 unsigned int cond = inst.operands[0].imm;
e27ec89e 11324
e07e6e58
NC
11325 set_it_insn_type (IT_INSN);
11326 now_it.mask = (inst.instruction & 0xf) | 0x10;
11327 now_it.cc = cond;
5a01bb1d 11328 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11329
11330 /* If the condition is a negative condition, invert the mask. */
c19d1205 11331 if ((cond & 0x1) == 0x0)
90e4755a 11332 {
c19d1205 11333 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11334
c19d1205 11335 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11336 {
11337 /* No conversion needed. */
11338 now_it.block_length = 1;
11339 }
c19d1205 11340 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11341 {
11342 mask ^= 0x8;
11343 now_it.block_length = 2;
11344 }
e27ec89e 11345 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11346 {
11347 mask ^= 0xC;
11348 now_it.block_length = 3;
11349 }
c19d1205 11350 else
5a01bb1d
MGD
11351 {
11352 mask ^= 0xE;
11353 now_it.block_length = 4;
11354 }
90e4755a 11355
e27ec89e
PB
11356 inst.instruction &= 0xfff0;
11357 inst.instruction |= mask;
c19d1205 11358 }
90e4755a 11359
c19d1205
ZW
11360 inst.instruction |= cond << 4;
11361}
90e4755a 11362
3c707909
PB
11363/* Helper function used for both push/pop and ldm/stm. */
11364static void
11365encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11366{
11367 bfd_boolean load;
11368
11369 load = (inst.instruction & (1 << 20)) != 0;
11370
11371 if (mask & (1 << 13))
11372 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11373
11374 if ((mask & (1 << base)) != 0
11375 && writeback)
11376 inst.error = _("having the base register in the register list when "
11377 "using write back is UNPREDICTABLE");
11378
3c707909
PB
11379 if (load)
11380 {
e07e6e58 11381 if (mask & (1 << 15))
477330fc
RM
11382 {
11383 if (mask & (1 << 14))
11384 inst.error = _("LR and PC should not both be in register list");
11385 else
11386 set_it_insn_type_last ();
11387 }
3c707909
PB
11388 }
11389 else
11390 {
11391 if (mask & (1 << 15))
11392 inst.error = _("PC not allowed in register list");
3c707909
PB
11393 }
11394
11395 if ((mask & (mask - 1)) == 0)
11396 {
11397 /* Single register transfers implemented as str/ldr. */
11398 if (writeback)
11399 {
11400 if (inst.instruction & (1 << 23))
11401 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11402 else
11403 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11404 }
11405 else
11406 {
11407 if (inst.instruction & (1 << 23))
11408 inst.instruction = 0x00800000; /* ia -> [base] */
11409 else
11410 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11411 }
11412
11413 inst.instruction |= 0xf8400000;
11414 if (load)
11415 inst.instruction |= 0x00100000;
11416
5f4273c7 11417 mask = ffs (mask) - 1;
3c707909
PB
11418 mask <<= 12;
11419 }
11420 else if (writeback)
11421 inst.instruction |= WRITE_BACK;
11422
11423 inst.instruction |= mask;
11424 inst.instruction |= base << 16;
11425}
11426
c19d1205
ZW
11427static void
11428do_t_ldmstm (void)
11429{
11430 /* This really doesn't seem worth it. */
11431 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11432 _("expression too complex"));
11433 constraint (inst.operands[1].writeback,
11434 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11435
c19d1205
ZW
11436 if (unified_syntax)
11437 {
3c707909
PB
11438 bfd_boolean narrow;
11439 unsigned mask;
11440
11441 narrow = FALSE;
c19d1205
ZW
11442 /* See if we can use a 16-bit instruction. */
11443 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11444 && inst.size_req != 4
3c707909 11445 && !(inst.operands[1].imm & ~0xff))
90e4755a 11446 {
3c707909 11447 mask = 1 << inst.operands[0].reg;
90e4755a 11448
eab4f823 11449 if (inst.operands[0].reg <= 7)
90e4755a 11450 {
3c707909 11451 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11452 ? inst.operands[0].writeback
11453 : (inst.operands[0].writeback
11454 == !(inst.operands[1].imm & mask)))
477330fc 11455 {
eab4f823
MGD
11456 if (inst.instruction == T_MNEM_stmia
11457 && (inst.operands[1].imm & mask)
11458 && (inst.operands[1].imm & (mask - 1)))
11459 as_warn (_("value stored for r%d is UNKNOWN"),
11460 inst.operands[0].reg);
3c707909 11461
eab4f823
MGD
11462 inst.instruction = THUMB_OP16 (inst.instruction);
11463 inst.instruction |= inst.operands[0].reg << 8;
11464 inst.instruction |= inst.operands[1].imm;
11465 narrow = TRUE;
11466 }
11467 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11468 {
11469 /* This means 1 register in reg list one of 3 situations:
11470 1. Instruction is stmia, but without writeback.
11471 2. lmdia without writeback, but with Rn not in
477330fc 11472 reglist.
eab4f823
MGD
11473 3. ldmia with writeback, but with Rn in reglist.
11474 Case 3 is UNPREDICTABLE behaviour, so we handle
11475 case 1 and 2 which can be converted into a 16-bit
11476 str or ldr. The SP cases are handled below. */
11477 unsigned long opcode;
11478 /* First, record an error for Case 3. */
11479 if (inst.operands[1].imm & mask
11480 && inst.operands[0].writeback)
fa94de6b 11481 inst.error =
eab4f823
MGD
11482 _("having the base register in the register list when "
11483 "using write back is UNPREDICTABLE");
fa94de6b
RM
11484
11485 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11486 : T_MNEM_ldr);
11487 inst.instruction = THUMB_OP16 (opcode);
11488 inst.instruction |= inst.operands[0].reg << 3;
11489 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11490 narrow = TRUE;
11491 }
90e4755a 11492 }
eab4f823 11493 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11494 {
eab4f823
MGD
11495 if (inst.operands[0].writeback)
11496 {
fa94de6b 11497 inst.instruction =
eab4f823 11498 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11499 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11500 inst.instruction |= inst.operands[1].imm;
477330fc 11501 narrow = TRUE;
eab4f823
MGD
11502 }
11503 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11504 {
fa94de6b 11505 inst.instruction =
eab4f823 11506 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11507 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11508 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11509 narrow = TRUE;
eab4f823 11510 }
90e4755a 11511 }
3c707909
PB
11512 }
11513
11514 if (!narrow)
11515 {
c19d1205
ZW
11516 if (inst.instruction < 0xffff)
11517 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11518
5f4273c7
NC
11519 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11520 inst.operands[0].writeback);
90e4755a
RE
11521 }
11522 }
c19d1205 11523 else
90e4755a 11524 {
c19d1205
ZW
11525 constraint (inst.operands[0].reg > 7
11526 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11527 constraint (inst.instruction != T_MNEM_ldmia
11528 && inst.instruction != T_MNEM_stmia,
11529 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11530 if (inst.instruction == T_MNEM_stmia)
f03698e6 11531 {
c19d1205
ZW
11532 if (!inst.operands[0].writeback)
11533 as_warn (_("this instruction will write back the base register"));
11534 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11535 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11536 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11537 inst.operands[0].reg);
f03698e6 11538 }
c19d1205 11539 else
90e4755a 11540 {
c19d1205
ZW
11541 if (!inst.operands[0].writeback
11542 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11543 as_warn (_("this instruction will write back the base register"));
11544 else if (inst.operands[0].writeback
11545 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11546 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11547 }
11548
c19d1205
ZW
11549 inst.instruction = THUMB_OP16 (inst.instruction);
11550 inst.instruction |= inst.operands[0].reg << 8;
11551 inst.instruction |= inst.operands[1].imm;
11552 }
11553}
e28cd48c 11554
c19d1205
ZW
11555static void
11556do_t_ldrex (void)
11557{
11558 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11559 || inst.operands[1].postind || inst.operands[1].writeback
11560 || inst.operands[1].immisreg || inst.operands[1].shifted
11561 || inst.operands[1].negative,
01cfc07f 11562 BAD_ADDR_MODE);
e28cd48c 11563
5be8be5d
DG
11564 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11565
c19d1205
ZW
11566 inst.instruction |= inst.operands[0].reg << 12;
11567 inst.instruction |= inst.operands[1].reg << 16;
11568 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11569}
e28cd48c 11570
c19d1205
ZW
11571static void
11572do_t_ldrexd (void)
11573{
11574 if (!inst.operands[1].present)
1cac9012 11575 {
c19d1205
ZW
11576 constraint (inst.operands[0].reg == REG_LR,
11577 _("r14 not allowed as first register "
11578 "when second register is omitted"));
11579 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11580 }
c19d1205
ZW
11581 constraint (inst.operands[0].reg == inst.operands[1].reg,
11582 BAD_OVERLAP);
b99bd4ef 11583
c19d1205
ZW
11584 inst.instruction |= inst.operands[0].reg << 12;
11585 inst.instruction |= inst.operands[1].reg << 8;
11586 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11587}
11588
11589static void
c19d1205 11590do_t_ldst (void)
b99bd4ef 11591{
0110f2b8
PB
11592 unsigned long opcode;
11593 int Rn;
11594
e07e6e58
NC
11595 if (inst.operands[0].isreg
11596 && !inst.operands[0].preind
11597 && inst.operands[0].reg == REG_PC)
11598 set_it_insn_type_last ();
11599
0110f2b8 11600 opcode = inst.instruction;
c19d1205 11601 if (unified_syntax)
b99bd4ef 11602 {
53365c0d
PB
11603 if (!inst.operands[1].isreg)
11604 {
11605 if (opcode <= 0xffff)
11606 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11607 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11608 return;
11609 }
0110f2b8
PB
11610 if (inst.operands[1].isreg
11611 && !inst.operands[1].writeback
c19d1205
ZW
11612 && !inst.operands[1].shifted && !inst.operands[1].postind
11613 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11614 && opcode <= 0xffff
11615 && inst.size_req != 4)
c19d1205 11616 {
0110f2b8
PB
11617 /* Insn may have a 16-bit form. */
11618 Rn = inst.operands[1].reg;
11619 if (inst.operands[1].immisreg)
11620 {
11621 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11622 /* [Rn, Rik] */
0110f2b8
PB
11623 if (Rn <= 7 && inst.operands[1].imm <= 7)
11624 goto op16;
5be8be5d
DG
11625 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11626 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11627 }
11628 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11629 && opcode != T_MNEM_ldrsb)
11630 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11631 || (Rn == REG_SP && opcode == T_MNEM_str))
11632 {
11633 /* [Rn, #const] */
11634 if (Rn > 7)
11635 {
11636 if (Rn == REG_PC)
11637 {
11638 if (inst.reloc.pc_rel)
11639 opcode = T_MNEM_ldr_pc2;
11640 else
11641 opcode = T_MNEM_ldr_pc;
11642 }
11643 else
11644 {
11645 if (opcode == T_MNEM_ldr)
11646 opcode = T_MNEM_ldr_sp;
11647 else
11648 opcode = T_MNEM_str_sp;
11649 }
11650 inst.instruction = inst.operands[0].reg << 8;
11651 }
11652 else
11653 {
11654 inst.instruction = inst.operands[0].reg;
11655 inst.instruction |= inst.operands[1].reg << 3;
11656 }
11657 inst.instruction |= THUMB_OP16 (opcode);
11658 if (inst.size_req == 2)
11659 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11660 else
11661 inst.relax = opcode;
11662 return;
11663 }
c19d1205 11664 }
0110f2b8 11665 /* Definitely a 32-bit variant. */
5be8be5d 11666
8d67f500
NC
11667 /* Warning for Erratum 752419. */
11668 if (opcode == T_MNEM_ldr
11669 && inst.operands[0].reg == REG_SP
11670 && inst.operands[1].writeback == 1
11671 && !inst.operands[1].immisreg)
11672 {
11673 if (no_cpu_selected ()
11674 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11675 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11676 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11677 as_warn (_("This instruction may be unpredictable "
11678 "if executed on M-profile cores "
11679 "with interrupts enabled."));
11680 }
11681
5be8be5d 11682 /* Do some validations regarding addressing modes. */
1be5fd2e 11683 if (inst.operands[1].immisreg)
5be8be5d
DG
11684 reject_bad_reg (inst.operands[1].imm);
11685
1be5fd2e
NC
11686 constraint (inst.operands[1].writeback == 1
11687 && inst.operands[0].reg == inst.operands[1].reg,
11688 BAD_OVERLAP);
11689
0110f2b8 11690 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11691 inst.instruction |= inst.operands[0].reg << 12;
11692 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11693 check_ldr_r15_aligned ();
b99bd4ef
NC
11694 return;
11695 }
11696
c19d1205
ZW
11697 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11698
11699 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11700 {
c19d1205
ZW
11701 /* Only [Rn,Rm] is acceptable. */
11702 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11703 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11704 || inst.operands[1].postind || inst.operands[1].shifted
11705 || inst.operands[1].negative,
11706 _("Thumb does not support this addressing mode"));
11707 inst.instruction = THUMB_OP16 (inst.instruction);
11708 goto op16;
b99bd4ef 11709 }
5f4273c7 11710
c19d1205
ZW
11711 inst.instruction = THUMB_OP16 (inst.instruction);
11712 if (!inst.operands[1].isreg)
8335d6aa 11713 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11714 return;
b99bd4ef 11715
c19d1205
ZW
11716 constraint (!inst.operands[1].preind
11717 || inst.operands[1].shifted
11718 || inst.operands[1].writeback,
11719 _("Thumb does not support this addressing mode"));
11720 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11721 {
c19d1205
ZW
11722 constraint (inst.instruction & 0x0600,
11723 _("byte or halfword not valid for base register"));
11724 constraint (inst.operands[1].reg == REG_PC
11725 && !(inst.instruction & THUMB_LOAD_BIT),
11726 _("r15 based store not allowed"));
11727 constraint (inst.operands[1].immisreg,
11728 _("invalid base register for register offset"));
b99bd4ef 11729
c19d1205
ZW
11730 if (inst.operands[1].reg == REG_PC)
11731 inst.instruction = T_OPCODE_LDR_PC;
11732 else if (inst.instruction & THUMB_LOAD_BIT)
11733 inst.instruction = T_OPCODE_LDR_SP;
11734 else
11735 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11736
c19d1205
ZW
11737 inst.instruction |= inst.operands[0].reg << 8;
11738 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11739 return;
11740 }
90e4755a 11741
c19d1205
ZW
11742 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11743 if (!inst.operands[1].immisreg)
11744 {
11745 /* Immediate offset. */
11746 inst.instruction |= inst.operands[0].reg;
11747 inst.instruction |= inst.operands[1].reg << 3;
11748 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11749 return;
11750 }
90e4755a 11751
c19d1205
ZW
11752 /* Register offset. */
11753 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11754 constraint (inst.operands[1].negative,
11755 _("Thumb does not support this addressing mode"));
90e4755a 11756
c19d1205
ZW
11757 op16:
11758 switch (inst.instruction)
11759 {
11760 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11761 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11762 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11763 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11764 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11765 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11766 case 0x5600 /* ldrsb */:
11767 case 0x5e00 /* ldrsh */: break;
11768 default: abort ();
11769 }
90e4755a 11770
c19d1205
ZW
11771 inst.instruction |= inst.operands[0].reg;
11772 inst.instruction |= inst.operands[1].reg << 3;
11773 inst.instruction |= inst.operands[1].imm << 6;
11774}
90e4755a 11775
c19d1205
ZW
11776static void
11777do_t_ldstd (void)
11778{
11779 if (!inst.operands[1].present)
b99bd4ef 11780 {
c19d1205
ZW
11781 inst.operands[1].reg = inst.operands[0].reg + 1;
11782 constraint (inst.operands[0].reg == REG_LR,
11783 _("r14 not allowed here"));
bd340a04 11784 constraint (inst.operands[0].reg == REG_R12,
477330fc 11785 _("r12 not allowed here"));
b99bd4ef 11786 }
bd340a04
MGD
11787
11788 if (inst.operands[2].writeback
11789 && (inst.operands[0].reg == inst.operands[2].reg
11790 || inst.operands[1].reg == inst.operands[2].reg))
11791 as_warn (_("base register written back, and overlaps "
477330fc 11792 "one of transfer registers"));
bd340a04 11793
c19d1205
ZW
11794 inst.instruction |= inst.operands[0].reg << 12;
11795 inst.instruction |= inst.operands[1].reg << 8;
11796 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11797}
11798
c19d1205
ZW
11799static void
11800do_t_ldstt (void)
11801{
11802 inst.instruction |= inst.operands[0].reg << 12;
11803 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11804}
a737bd4d 11805
b99bd4ef 11806static void
c19d1205 11807do_t_mla (void)
b99bd4ef 11808{
fdfde340 11809 unsigned Rd, Rn, Rm, Ra;
c921be7d 11810
fdfde340
JM
11811 Rd = inst.operands[0].reg;
11812 Rn = inst.operands[1].reg;
11813 Rm = inst.operands[2].reg;
11814 Ra = inst.operands[3].reg;
11815
11816 reject_bad_reg (Rd);
11817 reject_bad_reg (Rn);
11818 reject_bad_reg (Rm);
11819 reject_bad_reg (Ra);
11820
11821 inst.instruction |= Rd << 8;
11822 inst.instruction |= Rn << 16;
11823 inst.instruction |= Rm;
11824 inst.instruction |= Ra << 12;
c19d1205 11825}
b99bd4ef 11826
c19d1205
ZW
11827static void
11828do_t_mlal (void)
11829{
fdfde340
JM
11830 unsigned RdLo, RdHi, Rn, Rm;
11831
11832 RdLo = inst.operands[0].reg;
11833 RdHi = inst.operands[1].reg;
11834 Rn = inst.operands[2].reg;
11835 Rm = inst.operands[3].reg;
11836
11837 reject_bad_reg (RdLo);
11838 reject_bad_reg (RdHi);
11839 reject_bad_reg (Rn);
11840 reject_bad_reg (Rm);
11841
11842 inst.instruction |= RdLo << 12;
11843 inst.instruction |= RdHi << 8;
11844 inst.instruction |= Rn << 16;
11845 inst.instruction |= Rm;
c19d1205 11846}
b99bd4ef 11847
c19d1205
ZW
11848static void
11849do_t_mov_cmp (void)
11850{
fdfde340
JM
11851 unsigned Rn, Rm;
11852
11853 Rn = inst.operands[0].reg;
11854 Rm = inst.operands[1].reg;
11855
e07e6e58
NC
11856 if (Rn == REG_PC)
11857 set_it_insn_type_last ();
11858
c19d1205 11859 if (unified_syntax)
b99bd4ef 11860 {
c19d1205
ZW
11861 int r0off = (inst.instruction == T_MNEM_mov
11862 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11863 unsigned long opcode;
3d388997
PB
11864 bfd_boolean narrow;
11865 bfd_boolean low_regs;
11866
fdfde340 11867 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11868 opcode = inst.instruction;
e07e6e58 11869 if (in_it_block ())
0110f2b8 11870 narrow = opcode != T_MNEM_movs;
3d388997 11871 else
0110f2b8 11872 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11873 if (inst.size_req == 4
11874 || inst.operands[1].shifted)
11875 narrow = FALSE;
11876
efd81785
PB
11877 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11878 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11879 && !inst.operands[1].shifted
fdfde340
JM
11880 && Rn == REG_PC
11881 && Rm == REG_LR)
efd81785
PB
11882 {
11883 inst.instruction = T2_SUBS_PC_LR;
11884 return;
11885 }
11886
fdfde340
JM
11887 if (opcode == T_MNEM_cmp)
11888 {
11889 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11890 if (narrow)
11891 {
11892 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11893 but valid. */
11894 warn_deprecated_sp (Rm);
11895 /* R15 was documented as a valid choice for Rm in ARMv6,
11896 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11897 tools reject R15, so we do too. */
11898 constraint (Rm == REG_PC, BAD_PC);
11899 }
11900 else
11901 reject_bad_reg (Rm);
fdfde340
JM
11902 }
11903 else if (opcode == T_MNEM_mov
11904 || opcode == T_MNEM_movs)
11905 {
11906 if (inst.operands[1].isreg)
11907 {
11908 if (opcode == T_MNEM_movs)
11909 {
11910 reject_bad_reg (Rn);
11911 reject_bad_reg (Rm);
11912 }
76fa04a4
MGD
11913 else if (narrow)
11914 {
11915 /* This is mov.n. */
11916 if ((Rn == REG_SP || Rn == REG_PC)
11917 && (Rm == REG_SP || Rm == REG_PC))
11918 {
5c3696f8 11919 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11920 "deprecated when r%u is the destination "
11921 "register."), Rm, Rn);
11922 }
11923 }
11924 else
11925 {
11926 /* This is mov.w. */
11927 constraint (Rn == REG_PC, BAD_PC);
11928 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11929 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11930 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11931 }
fdfde340
JM
11932 }
11933 else
11934 reject_bad_reg (Rn);
11935 }
11936
c19d1205
ZW
11937 if (!inst.operands[1].isreg)
11938 {
0110f2b8 11939 /* Immediate operand. */
e07e6e58 11940 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11941 narrow = 0;
11942 if (low_regs && narrow)
11943 {
11944 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11945 inst.instruction |= Rn << 8;
a9f02af8
MG
11946 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11947 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11948 {
a9f02af8 11949 if (inst.size_req == 2)
72d98d16 11950 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11951 else
11952 inst.relax = opcode;
72d98d16 11953 }
0110f2b8
PB
11954 }
11955 else
11956 {
a9f02af8
MG
11957 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11958 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11959 THUMB1_RELOC_ONLY);
11960
0110f2b8
PB
11961 inst.instruction = THUMB_OP32 (inst.instruction);
11962 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11963 inst.instruction |= Rn << r0off;
0110f2b8
PB
11964 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11965 }
c19d1205 11966 }
728ca7c9
PB
11967 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11968 && (inst.instruction == T_MNEM_mov
11969 || inst.instruction == T_MNEM_movs))
11970 {
11971 /* Register shifts are encoded as separate shift instructions. */
11972 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11973
e07e6e58 11974 if (in_it_block ())
728ca7c9
PB
11975 narrow = !flags;
11976 else
11977 narrow = flags;
11978
11979 if (inst.size_req == 4)
11980 narrow = FALSE;
11981
11982 if (!low_regs || inst.operands[1].imm > 7)
11983 narrow = FALSE;
11984
fdfde340 11985 if (Rn != Rm)
728ca7c9
PB
11986 narrow = FALSE;
11987
11988 switch (inst.operands[1].shift_kind)
11989 {
11990 case SHIFT_LSL:
11991 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11992 break;
11993 case SHIFT_ASR:
11994 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11995 break;
11996 case SHIFT_LSR:
11997 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11998 break;
11999 case SHIFT_ROR:
12000 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12001 break;
12002 default:
5f4273c7 12003 abort ();
728ca7c9
PB
12004 }
12005
12006 inst.instruction = opcode;
12007 if (narrow)
12008 {
fdfde340 12009 inst.instruction |= Rn;
728ca7c9
PB
12010 inst.instruction |= inst.operands[1].imm << 3;
12011 }
12012 else
12013 {
12014 if (flags)
12015 inst.instruction |= CONDS_BIT;
12016
fdfde340
JM
12017 inst.instruction |= Rn << 8;
12018 inst.instruction |= Rm << 16;
728ca7c9
PB
12019 inst.instruction |= inst.operands[1].imm;
12020 }
12021 }
3d388997 12022 else if (!narrow)
c19d1205 12023 {
728ca7c9
PB
12024 /* Some mov with immediate shift have narrow variants.
12025 Register shifts are handled above. */
12026 if (low_regs && inst.operands[1].shifted
12027 && (inst.instruction == T_MNEM_mov
12028 || inst.instruction == T_MNEM_movs))
12029 {
e07e6e58 12030 if (in_it_block ())
728ca7c9
PB
12031 narrow = (inst.instruction == T_MNEM_mov);
12032 else
12033 narrow = (inst.instruction == T_MNEM_movs);
12034 }
12035
12036 if (narrow)
12037 {
12038 switch (inst.operands[1].shift_kind)
12039 {
12040 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12041 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12042 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12043 default: narrow = FALSE; break;
12044 }
12045 }
12046
12047 if (narrow)
12048 {
fdfde340
JM
12049 inst.instruction |= Rn;
12050 inst.instruction |= Rm << 3;
728ca7c9
PB
12051 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12052 }
12053 else
12054 {
12055 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12056 inst.instruction |= Rn << r0off;
728ca7c9
PB
12057 encode_thumb32_shifted_operand (1);
12058 }
c19d1205
ZW
12059 }
12060 else
12061 switch (inst.instruction)
12062 {
12063 case T_MNEM_mov:
837b3435 12064 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12065 results. Don't allow this. */
12066 if (low_regs)
12067 {
12068 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12069 "MOV Rd, Rs with two low registers is not "
12070 "permitted on this architecture");
fa94de6b 12071 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12072 arm_ext_v6);
12073 }
12074
c19d1205 12075 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12076 inst.instruction |= (Rn & 0x8) << 4;
12077 inst.instruction |= (Rn & 0x7);
12078 inst.instruction |= Rm << 3;
c19d1205 12079 break;
b99bd4ef 12080
c19d1205
ZW
12081 case T_MNEM_movs:
12082 /* We know we have low registers at this point.
941a8a52
MGD
12083 Generate LSLS Rd, Rs, #0. */
12084 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12085 inst.instruction |= Rn;
12086 inst.instruction |= Rm << 3;
c19d1205
ZW
12087 break;
12088
12089 case T_MNEM_cmp:
3d388997 12090 if (low_regs)
c19d1205
ZW
12091 {
12092 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12093 inst.instruction |= Rn;
12094 inst.instruction |= Rm << 3;
c19d1205
ZW
12095 }
12096 else
12097 {
12098 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12099 inst.instruction |= (Rn & 0x8) << 4;
12100 inst.instruction |= (Rn & 0x7);
12101 inst.instruction |= Rm << 3;
c19d1205
ZW
12102 }
12103 break;
12104 }
b99bd4ef
NC
12105 return;
12106 }
12107
c19d1205 12108 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12109
12110 /* PR 10443: Do not silently ignore shifted operands. */
12111 constraint (inst.operands[1].shifted,
12112 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12113
c19d1205 12114 if (inst.operands[1].isreg)
b99bd4ef 12115 {
fdfde340 12116 if (Rn < 8 && Rm < 8)
b99bd4ef 12117 {
c19d1205
ZW
12118 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12119 since a MOV instruction produces unpredictable results. */
12120 if (inst.instruction == T_OPCODE_MOV_I8)
12121 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12122 else
c19d1205 12123 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12124
fdfde340
JM
12125 inst.instruction |= Rn;
12126 inst.instruction |= Rm << 3;
b99bd4ef
NC
12127 }
12128 else
12129 {
c19d1205
ZW
12130 if (inst.instruction == T_OPCODE_MOV_I8)
12131 inst.instruction = T_OPCODE_MOV_HR;
12132 else
12133 inst.instruction = T_OPCODE_CMP_HR;
12134 do_t_cpy ();
b99bd4ef
NC
12135 }
12136 }
c19d1205 12137 else
b99bd4ef 12138 {
fdfde340 12139 constraint (Rn > 7,
c19d1205 12140 _("only lo regs allowed with immediate"));
fdfde340 12141 inst.instruction |= Rn << 8;
c19d1205
ZW
12142 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12143 }
12144}
b99bd4ef 12145
c19d1205
ZW
12146static void
12147do_t_mov16 (void)
12148{
fdfde340 12149 unsigned Rd;
b6895b4f
PB
12150 bfd_vma imm;
12151 bfd_boolean top;
12152
12153 top = (inst.instruction & 0x00800000) != 0;
12154 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12155 {
33eaf5de 12156 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12157 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12158 }
12159 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12160 {
33eaf5de 12161 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12162 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12163 }
12164
fdfde340
JM
12165 Rd = inst.operands[0].reg;
12166 reject_bad_reg (Rd);
12167
12168 inst.instruction |= Rd << 8;
b6895b4f
PB
12169 if (inst.reloc.type == BFD_RELOC_UNUSED)
12170 {
12171 imm = inst.reloc.exp.X_add_number;
12172 inst.instruction |= (imm & 0xf000) << 4;
12173 inst.instruction |= (imm & 0x0800) << 15;
12174 inst.instruction |= (imm & 0x0700) << 4;
12175 inst.instruction |= (imm & 0x00ff);
12176 }
c19d1205 12177}
b99bd4ef 12178
c19d1205
ZW
12179static void
12180do_t_mvn_tst (void)
12181{
fdfde340 12182 unsigned Rn, Rm;
c921be7d 12183
fdfde340
JM
12184 Rn = inst.operands[0].reg;
12185 Rm = inst.operands[1].reg;
12186
12187 if (inst.instruction == T_MNEM_cmp
12188 || inst.instruction == T_MNEM_cmn)
12189 constraint (Rn == REG_PC, BAD_PC);
12190 else
12191 reject_bad_reg (Rn);
12192 reject_bad_reg (Rm);
12193
c19d1205
ZW
12194 if (unified_syntax)
12195 {
12196 int r0off = (inst.instruction == T_MNEM_mvn
12197 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12198 bfd_boolean narrow;
12199
12200 if (inst.size_req == 4
12201 || inst.instruction > 0xffff
12202 || inst.operands[1].shifted
fdfde340 12203 || Rn > 7 || Rm > 7)
3d388997 12204 narrow = FALSE;
fe8b4cc3
KT
12205 else if (inst.instruction == T_MNEM_cmn
12206 || inst.instruction == T_MNEM_tst)
3d388997
PB
12207 narrow = TRUE;
12208 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12209 narrow = !in_it_block ();
3d388997 12210 else
e07e6e58 12211 narrow = in_it_block ();
3d388997 12212
c19d1205 12213 if (!inst.operands[1].isreg)
b99bd4ef 12214 {
c19d1205
ZW
12215 /* For an immediate, we always generate a 32-bit opcode;
12216 section relaxation will shrink it later if possible. */
12217 if (inst.instruction < 0xffff)
12218 inst.instruction = THUMB_OP32 (inst.instruction);
12219 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12220 inst.instruction |= Rn << r0off;
c19d1205 12221 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12222 }
c19d1205 12223 else
b99bd4ef 12224 {
c19d1205 12225 /* See if we can do this with a 16-bit instruction. */
3d388997 12226 if (narrow)
b99bd4ef 12227 {
c19d1205 12228 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12229 inst.instruction |= Rn;
12230 inst.instruction |= Rm << 3;
b99bd4ef 12231 }
c19d1205 12232 else
b99bd4ef 12233 {
c19d1205
ZW
12234 constraint (inst.operands[1].shifted
12235 && inst.operands[1].immisreg,
12236 _("shift must be constant"));
12237 if (inst.instruction < 0xffff)
12238 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12239 inst.instruction |= Rn << r0off;
c19d1205 12240 encode_thumb32_shifted_operand (1);
b99bd4ef 12241 }
b99bd4ef
NC
12242 }
12243 }
12244 else
12245 {
c19d1205
ZW
12246 constraint (inst.instruction > 0xffff
12247 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12248 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12249 _("unshifted register required"));
fdfde340 12250 constraint (Rn > 7 || Rm > 7,
c19d1205 12251 BAD_HIREG);
b99bd4ef 12252
c19d1205 12253 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12254 inst.instruction |= Rn;
12255 inst.instruction |= Rm << 3;
b99bd4ef 12256 }
b99bd4ef
NC
12257}
12258
b05fe5cf 12259static void
c19d1205 12260do_t_mrs (void)
b05fe5cf 12261{
fdfde340 12262 unsigned Rd;
037e8744
JB
12263
12264 if (do_vfp_nsyn_mrs () == SUCCESS)
12265 return;
12266
90ec0d68
MGD
12267 Rd = inst.operands[0].reg;
12268 reject_bad_reg (Rd);
12269 inst.instruction |= Rd << 8;
12270
12271 if (inst.operands[1].isreg)
62b3e311 12272 {
90ec0d68
MGD
12273 unsigned br = inst.operands[1].reg;
12274 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12275 as_bad (_("bad register for mrs"));
12276
12277 inst.instruction |= br & (0xf << 16);
12278 inst.instruction |= (br & 0x300) >> 4;
12279 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12280 }
12281 else
12282 {
90ec0d68 12283 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12284
d2cd1205 12285 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12286 {
12287 /* PR gas/12698: The constraint is only applied for m_profile.
12288 If the user has specified -march=all, we want to ignore it as
12289 we are building for any CPU type, including non-m variants. */
823d2571
TG
12290 bfd_boolean m_profile =
12291 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12292 constraint ((flags != 0) && m_profile, _("selected processor does "
12293 "not support requested special purpose register"));
12294 }
90ec0d68 12295 else
d2cd1205
JB
12296 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12297 devices). */
12298 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12299 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12300
90ec0d68
MGD
12301 inst.instruction |= (flags & SPSR_BIT) >> 2;
12302 inst.instruction |= inst.operands[1].imm & 0xff;
12303 inst.instruction |= 0xf0000;
12304 }
c19d1205 12305}
b05fe5cf 12306
c19d1205
ZW
12307static void
12308do_t_msr (void)
12309{
62b3e311 12310 int flags;
fdfde340 12311 unsigned Rn;
62b3e311 12312
037e8744
JB
12313 if (do_vfp_nsyn_msr () == SUCCESS)
12314 return;
12315
c19d1205
ZW
12316 constraint (!inst.operands[1].isreg,
12317 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12318
12319 if (inst.operands[0].isreg)
12320 flags = (int)(inst.operands[0].reg);
12321 else
12322 flags = inst.operands[0].imm;
12323
d2cd1205 12324 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12325 {
d2cd1205
JB
12326 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12327
1a43faaf 12328 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12329 If the user has specified -march=all, we want to ignore it as
12330 we are building for any CPU type, including non-m variants. */
823d2571
TG
12331 bfd_boolean m_profile =
12332 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12333 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12334 && (bits & ~(PSR_s | PSR_f)) != 0)
12335 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12336 && bits != PSR_f)) && m_profile,
12337 _("selected processor does not support requested special "
12338 "purpose register"));
62b3e311
PB
12339 }
12340 else
d2cd1205
JB
12341 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12342 "requested special purpose register"));
c921be7d 12343
fdfde340
JM
12344 Rn = inst.operands[1].reg;
12345 reject_bad_reg (Rn);
12346
62b3e311 12347 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12348 inst.instruction |= (flags & 0xf0000) >> 8;
12349 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12350 inst.instruction |= (flags & 0xff);
fdfde340 12351 inst.instruction |= Rn << 16;
c19d1205 12352}
b05fe5cf 12353
c19d1205
ZW
12354static void
12355do_t_mul (void)
12356{
17828f45 12357 bfd_boolean narrow;
fdfde340 12358 unsigned Rd, Rn, Rm;
17828f45 12359
c19d1205
ZW
12360 if (!inst.operands[2].present)
12361 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12362
fdfde340
JM
12363 Rd = inst.operands[0].reg;
12364 Rn = inst.operands[1].reg;
12365 Rm = inst.operands[2].reg;
12366
17828f45 12367 if (unified_syntax)
b05fe5cf 12368 {
17828f45 12369 if (inst.size_req == 4
fdfde340
JM
12370 || (Rd != Rn
12371 && Rd != Rm)
12372 || Rn > 7
12373 || Rm > 7)
17828f45
JM
12374 narrow = FALSE;
12375 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12376 narrow = !in_it_block ();
17828f45 12377 else
e07e6e58 12378 narrow = in_it_block ();
b05fe5cf 12379 }
c19d1205 12380 else
b05fe5cf 12381 {
17828f45 12382 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12383 constraint (Rn > 7 || Rm > 7,
c19d1205 12384 BAD_HIREG);
17828f45
JM
12385 narrow = TRUE;
12386 }
b05fe5cf 12387
17828f45
JM
12388 if (narrow)
12389 {
12390 /* 16-bit MULS/Conditional MUL. */
c19d1205 12391 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12392 inst.instruction |= Rd;
b05fe5cf 12393
fdfde340
JM
12394 if (Rd == Rn)
12395 inst.instruction |= Rm << 3;
12396 else if (Rd == Rm)
12397 inst.instruction |= Rn << 3;
c19d1205
ZW
12398 else
12399 constraint (1, _("dest must overlap one source register"));
12400 }
17828f45
JM
12401 else
12402 {
e07e6e58
NC
12403 constraint (inst.instruction != T_MNEM_mul,
12404 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12405 /* 32-bit MUL. */
12406 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12407 inst.instruction |= Rd << 8;
12408 inst.instruction |= Rn << 16;
12409 inst.instruction |= Rm << 0;
12410
12411 reject_bad_reg (Rd);
12412 reject_bad_reg (Rn);
12413 reject_bad_reg (Rm);
17828f45 12414 }
c19d1205 12415}
b05fe5cf 12416
c19d1205
ZW
12417static void
12418do_t_mull (void)
12419{
fdfde340 12420 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12421
fdfde340
JM
12422 RdLo = inst.operands[0].reg;
12423 RdHi = inst.operands[1].reg;
12424 Rn = inst.operands[2].reg;
12425 Rm = inst.operands[3].reg;
12426
12427 reject_bad_reg (RdLo);
12428 reject_bad_reg (RdHi);
12429 reject_bad_reg (Rn);
12430 reject_bad_reg (Rm);
12431
12432 inst.instruction |= RdLo << 12;
12433 inst.instruction |= RdHi << 8;
12434 inst.instruction |= Rn << 16;
12435 inst.instruction |= Rm;
12436
12437 if (RdLo == RdHi)
c19d1205
ZW
12438 as_tsktsk (_("rdhi and rdlo must be different"));
12439}
b05fe5cf 12440
c19d1205
ZW
12441static void
12442do_t_nop (void)
12443{
e07e6e58
NC
12444 set_it_insn_type (NEUTRAL_IT_INSN);
12445
c19d1205
ZW
12446 if (unified_syntax)
12447 {
12448 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12449 {
c19d1205
ZW
12450 inst.instruction = THUMB_OP32 (inst.instruction);
12451 inst.instruction |= inst.operands[0].imm;
12452 }
12453 else
12454 {
bc2d1808
NC
12455 /* PR9722: Check for Thumb2 availability before
12456 generating a thumb2 nop instruction. */
afa62d5e 12457 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12458 {
12459 inst.instruction = THUMB_OP16 (inst.instruction);
12460 inst.instruction |= inst.operands[0].imm << 4;
12461 }
12462 else
12463 inst.instruction = 0x46c0;
c19d1205
ZW
12464 }
12465 }
12466 else
12467 {
12468 constraint (inst.operands[0].present,
12469 _("Thumb does not support NOP with hints"));
12470 inst.instruction = 0x46c0;
12471 }
12472}
b05fe5cf 12473
c19d1205
ZW
12474static void
12475do_t_neg (void)
12476{
12477 if (unified_syntax)
12478 {
3d388997
PB
12479 bfd_boolean narrow;
12480
12481 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12482 narrow = !in_it_block ();
3d388997 12483 else
e07e6e58 12484 narrow = in_it_block ();
3d388997
PB
12485 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12486 narrow = FALSE;
12487 if (inst.size_req == 4)
12488 narrow = FALSE;
12489
12490 if (!narrow)
c19d1205
ZW
12491 {
12492 inst.instruction = THUMB_OP32 (inst.instruction);
12493 inst.instruction |= inst.operands[0].reg << 8;
12494 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12495 }
12496 else
12497 {
c19d1205
ZW
12498 inst.instruction = THUMB_OP16 (inst.instruction);
12499 inst.instruction |= inst.operands[0].reg;
12500 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12501 }
12502 }
12503 else
12504 {
c19d1205
ZW
12505 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12506 BAD_HIREG);
12507 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12508
12509 inst.instruction = THUMB_OP16 (inst.instruction);
12510 inst.instruction |= inst.operands[0].reg;
12511 inst.instruction |= inst.operands[1].reg << 3;
12512 }
12513}
12514
1c444d06
JM
12515static void
12516do_t_orn (void)
12517{
12518 unsigned Rd, Rn;
12519
12520 Rd = inst.operands[0].reg;
12521 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12522
fdfde340
JM
12523 reject_bad_reg (Rd);
12524 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12525 reject_bad_reg (Rn);
12526
1c444d06
JM
12527 inst.instruction |= Rd << 8;
12528 inst.instruction |= Rn << 16;
12529
12530 if (!inst.operands[2].isreg)
12531 {
12532 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12533 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12534 }
12535 else
12536 {
12537 unsigned Rm;
12538
12539 Rm = inst.operands[2].reg;
fdfde340 12540 reject_bad_reg (Rm);
1c444d06
JM
12541
12542 constraint (inst.operands[2].shifted
12543 && inst.operands[2].immisreg,
12544 _("shift must be constant"));
12545 encode_thumb32_shifted_operand (2);
12546 }
12547}
12548
c19d1205
ZW
12549static void
12550do_t_pkhbt (void)
12551{
fdfde340
JM
12552 unsigned Rd, Rn, Rm;
12553
12554 Rd = inst.operands[0].reg;
12555 Rn = inst.operands[1].reg;
12556 Rm = inst.operands[2].reg;
12557
12558 reject_bad_reg (Rd);
12559 reject_bad_reg (Rn);
12560 reject_bad_reg (Rm);
12561
12562 inst.instruction |= Rd << 8;
12563 inst.instruction |= Rn << 16;
12564 inst.instruction |= Rm;
c19d1205
ZW
12565 if (inst.operands[3].present)
12566 {
12567 unsigned int val = inst.reloc.exp.X_add_number;
12568 constraint (inst.reloc.exp.X_op != O_constant,
12569 _("expression too complex"));
12570 inst.instruction |= (val & 0x1c) << 10;
12571 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12572 }
c19d1205 12573}
b05fe5cf 12574
c19d1205
ZW
12575static void
12576do_t_pkhtb (void)
12577{
12578 if (!inst.operands[3].present)
1ef52f49
NC
12579 {
12580 unsigned Rtmp;
12581
12582 inst.instruction &= ~0x00000020;
12583
12584 /* PR 10168. Swap the Rm and Rn registers. */
12585 Rtmp = inst.operands[1].reg;
12586 inst.operands[1].reg = inst.operands[2].reg;
12587 inst.operands[2].reg = Rtmp;
12588 }
c19d1205 12589 do_t_pkhbt ();
b05fe5cf
ZW
12590}
12591
c19d1205
ZW
12592static void
12593do_t_pld (void)
12594{
fdfde340
JM
12595 if (inst.operands[0].immisreg)
12596 reject_bad_reg (inst.operands[0].imm);
12597
c19d1205
ZW
12598 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12599}
b05fe5cf 12600
c19d1205
ZW
12601static void
12602do_t_push_pop (void)
b99bd4ef 12603{
e9f89963 12604 unsigned mask;
5f4273c7 12605
c19d1205
ZW
12606 constraint (inst.operands[0].writeback,
12607 _("push/pop do not support {reglist}^"));
12608 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12609 _("expression too complex"));
b99bd4ef 12610
e9f89963 12611 mask = inst.operands[0].imm;
d3bfe16e 12612 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12613 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12614 else if (inst.size_req != 4
c6025a80 12615 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12616 ? REG_LR : REG_PC)))
b99bd4ef 12617 {
c19d1205
ZW
12618 inst.instruction = THUMB_OP16 (inst.instruction);
12619 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12620 inst.instruction |= mask & 0xff;
c19d1205
ZW
12621 }
12622 else if (unified_syntax)
12623 {
3c707909 12624 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12625 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12626 }
12627 else
12628 {
12629 inst.error = _("invalid register list to push/pop instruction");
12630 return;
12631 }
c19d1205 12632}
b99bd4ef 12633
c19d1205
ZW
12634static void
12635do_t_rbit (void)
12636{
fdfde340
JM
12637 unsigned Rd, Rm;
12638
12639 Rd = inst.operands[0].reg;
12640 Rm = inst.operands[1].reg;
12641
12642 reject_bad_reg (Rd);
12643 reject_bad_reg (Rm);
12644
12645 inst.instruction |= Rd << 8;
12646 inst.instruction |= Rm << 16;
12647 inst.instruction |= Rm;
c19d1205 12648}
b99bd4ef 12649
c19d1205
ZW
12650static void
12651do_t_rev (void)
12652{
fdfde340
JM
12653 unsigned Rd, Rm;
12654
12655 Rd = inst.operands[0].reg;
12656 Rm = inst.operands[1].reg;
12657
12658 reject_bad_reg (Rd);
12659 reject_bad_reg (Rm);
12660
12661 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12662 && inst.size_req != 4)
12663 {
12664 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12665 inst.instruction |= Rd;
12666 inst.instruction |= Rm << 3;
c19d1205
ZW
12667 }
12668 else if (unified_syntax)
12669 {
12670 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12671 inst.instruction |= Rd << 8;
12672 inst.instruction |= Rm << 16;
12673 inst.instruction |= Rm;
c19d1205
ZW
12674 }
12675 else
12676 inst.error = BAD_HIREG;
12677}
b99bd4ef 12678
1c444d06
JM
12679static void
12680do_t_rrx (void)
12681{
12682 unsigned Rd, Rm;
12683
12684 Rd = inst.operands[0].reg;
12685 Rm = inst.operands[1].reg;
12686
fdfde340
JM
12687 reject_bad_reg (Rd);
12688 reject_bad_reg (Rm);
c921be7d 12689
1c444d06
JM
12690 inst.instruction |= Rd << 8;
12691 inst.instruction |= Rm;
12692}
12693
c19d1205
ZW
12694static void
12695do_t_rsb (void)
12696{
fdfde340 12697 unsigned Rd, Rs;
b99bd4ef 12698
c19d1205
ZW
12699 Rd = inst.operands[0].reg;
12700 Rs = (inst.operands[1].present
12701 ? inst.operands[1].reg /* Rd, Rs, foo */
12702 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12703
fdfde340
JM
12704 reject_bad_reg (Rd);
12705 reject_bad_reg (Rs);
12706 if (inst.operands[2].isreg)
12707 reject_bad_reg (inst.operands[2].reg);
12708
c19d1205
ZW
12709 inst.instruction |= Rd << 8;
12710 inst.instruction |= Rs << 16;
12711 if (!inst.operands[2].isreg)
12712 {
026d3abb
PB
12713 bfd_boolean narrow;
12714
12715 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12716 narrow = !in_it_block ();
026d3abb 12717 else
e07e6e58 12718 narrow = in_it_block ();
026d3abb
PB
12719
12720 if (Rd > 7 || Rs > 7)
12721 narrow = FALSE;
12722
12723 if (inst.size_req == 4 || !unified_syntax)
12724 narrow = FALSE;
12725
12726 if (inst.reloc.exp.X_op != O_constant
12727 || inst.reloc.exp.X_add_number != 0)
12728 narrow = FALSE;
12729
12730 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12731 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12732 if (narrow)
12733 {
12734 inst.reloc.type = BFD_RELOC_UNUSED;
12735 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12736 inst.instruction |= Rs << 3;
12737 inst.instruction |= Rd;
12738 }
12739 else
12740 {
12741 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12742 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12743 }
c19d1205
ZW
12744 }
12745 else
12746 encode_thumb32_shifted_operand (2);
12747}
b99bd4ef 12748
c19d1205
ZW
12749static void
12750do_t_setend (void)
12751{
12e37cbc
MGD
12752 if (warn_on_deprecated
12753 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12754 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12755
e07e6e58 12756 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12757 if (inst.operands[0].imm)
12758 inst.instruction |= 0x8;
12759}
b99bd4ef 12760
c19d1205
ZW
12761static void
12762do_t_shift (void)
12763{
12764 if (!inst.operands[1].present)
12765 inst.operands[1].reg = inst.operands[0].reg;
12766
12767 if (unified_syntax)
12768 {
3d388997
PB
12769 bfd_boolean narrow;
12770 int shift_kind;
12771
12772 switch (inst.instruction)
12773 {
12774 case T_MNEM_asr:
12775 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12776 case T_MNEM_lsl:
12777 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12778 case T_MNEM_lsr:
12779 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12780 case T_MNEM_ror:
12781 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12782 default: abort ();
12783 }
12784
12785 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12786 narrow = !in_it_block ();
3d388997 12787 else
e07e6e58 12788 narrow = in_it_block ();
3d388997
PB
12789 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12790 narrow = FALSE;
12791 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12792 narrow = FALSE;
12793 if (inst.operands[2].isreg
12794 && (inst.operands[1].reg != inst.operands[0].reg
12795 || inst.operands[2].reg > 7))
12796 narrow = FALSE;
12797 if (inst.size_req == 4)
12798 narrow = FALSE;
12799
fdfde340
JM
12800 reject_bad_reg (inst.operands[0].reg);
12801 reject_bad_reg (inst.operands[1].reg);
c921be7d 12802
3d388997 12803 if (!narrow)
c19d1205
ZW
12804 {
12805 if (inst.operands[2].isreg)
b99bd4ef 12806 {
fdfde340 12807 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12808 inst.instruction = THUMB_OP32 (inst.instruction);
12809 inst.instruction |= inst.operands[0].reg << 8;
12810 inst.instruction |= inst.operands[1].reg << 16;
12811 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12812
12813 /* PR 12854: Error on extraneous shifts. */
12814 constraint (inst.operands[2].shifted,
12815 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12816 }
12817 else
12818 {
12819 inst.operands[1].shifted = 1;
3d388997 12820 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12821 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12822 ? T_MNEM_movs : T_MNEM_mov);
12823 inst.instruction |= inst.operands[0].reg << 8;
12824 encode_thumb32_shifted_operand (1);
12825 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12826 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12827 }
12828 }
12829 else
12830 {
c19d1205 12831 if (inst.operands[2].isreg)
b99bd4ef 12832 {
3d388997 12833 switch (shift_kind)
b99bd4ef 12834 {
3d388997
PB
12835 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12836 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12837 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12838 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12839 default: abort ();
b99bd4ef 12840 }
5f4273c7 12841
c19d1205
ZW
12842 inst.instruction |= inst.operands[0].reg;
12843 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12844
12845 /* PR 12854: Error on extraneous shifts. */
12846 constraint (inst.operands[2].shifted,
12847 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12848 }
12849 else
12850 {
3d388997 12851 switch (shift_kind)
b99bd4ef 12852 {
3d388997
PB
12853 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12854 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12855 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12856 default: abort ();
b99bd4ef 12857 }
c19d1205
ZW
12858 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12859 inst.instruction |= inst.operands[0].reg;
12860 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12861 }
12862 }
c19d1205
ZW
12863 }
12864 else
12865 {
12866 constraint (inst.operands[0].reg > 7
12867 || inst.operands[1].reg > 7, BAD_HIREG);
12868 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12869
c19d1205
ZW
12870 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12871 {
12872 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12873 constraint (inst.operands[0].reg != inst.operands[1].reg,
12874 _("source1 and dest must be same register"));
b99bd4ef 12875
c19d1205
ZW
12876 switch (inst.instruction)
12877 {
12878 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12879 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12880 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12881 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12882 default: abort ();
12883 }
5f4273c7 12884
c19d1205
ZW
12885 inst.instruction |= inst.operands[0].reg;
12886 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12887
12888 /* PR 12854: Error on extraneous shifts. */
12889 constraint (inst.operands[2].shifted,
12890 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12891 }
12892 else
b99bd4ef 12893 {
c19d1205
ZW
12894 switch (inst.instruction)
12895 {
12896 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12897 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12898 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12899 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12900 default: abort ();
12901 }
12902 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12903 inst.instruction |= inst.operands[0].reg;
12904 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12905 }
12906 }
b99bd4ef
NC
12907}
12908
12909static void
c19d1205 12910do_t_simd (void)
b99bd4ef 12911{
fdfde340
JM
12912 unsigned Rd, Rn, Rm;
12913
12914 Rd = inst.operands[0].reg;
12915 Rn = inst.operands[1].reg;
12916 Rm = inst.operands[2].reg;
12917
12918 reject_bad_reg (Rd);
12919 reject_bad_reg (Rn);
12920 reject_bad_reg (Rm);
12921
12922 inst.instruction |= Rd << 8;
12923 inst.instruction |= Rn << 16;
12924 inst.instruction |= Rm;
c19d1205 12925}
b99bd4ef 12926
03ee1b7f
NC
12927static void
12928do_t_simd2 (void)
12929{
12930 unsigned Rd, Rn, Rm;
12931
12932 Rd = inst.operands[0].reg;
12933 Rm = inst.operands[1].reg;
12934 Rn = inst.operands[2].reg;
12935
12936 reject_bad_reg (Rd);
12937 reject_bad_reg (Rn);
12938 reject_bad_reg (Rm);
12939
12940 inst.instruction |= Rd << 8;
12941 inst.instruction |= Rn << 16;
12942 inst.instruction |= Rm;
12943}
12944
c19d1205 12945static void
3eb17e6b 12946do_t_smc (void)
c19d1205
ZW
12947{
12948 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12949 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12950 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12951 constraint (inst.reloc.exp.X_op != O_constant,
12952 _("expression too complex"));
12953 inst.reloc.type = BFD_RELOC_UNUSED;
12954 inst.instruction |= (value & 0xf000) >> 12;
12955 inst.instruction |= (value & 0x0ff0);
12956 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12957 /* PR gas/15623: SMC instructions must be last in an IT block. */
12958 set_it_insn_type_last ();
c19d1205 12959}
b99bd4ef 12960
90ec0d68
MGD
12961static void
12962do_t_hvc (void)
12963{
12964 unsigned int value = inst.reloc.exp.X_add_number;
12965
12966 inst.reloc.type = BFD_RELOC_UNUSED;
12967 inst.instruction |= (value & 0x0fff);
12968 inst.instruction |= (value & 0xf000) << 4;
12969}
12970
c19d1205 12971static void
3a21c15a 12972do_t_ssat_usat (int bias)
c19d1205 12973{
fdfde340
JM
12974 unsigned Rd, Rn;
12975
12976 Rd = inst.operands[0].reg;
12977 Rn = inst.operands[2].reg;
12978
12979 reject_bad_reg (Rd);
12980 reject_bad_reg (Rn);
12981
12982 inst.instruction |= Rd << 8;
3a21c15a 12983 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12984 inst.instruction |= Rn << 16;
b99bd4ef 12985
c19d1205 12986 if (inst.operands[3].present)
b99bd4ef 12987 {
3a21c15a
NC
12988 offsetT shift_amount = inst.reloc.exp.X_add_number;
12989
12990 inst.reloc.type = BFD_RELOC_UNUSED;
12991
c19d1205
ZW
12992 constraint (inst.reloc.exp.X_op != O_constant,
12993 _("expression too complex"));
b99bd4ef 12994
3a21c15a 12995 if (shift_amount != 0)
6189168b 12996 {
3a21c15a
NC
12997 constraint (shift_amount > 31,
12998 _("shift expression is too large"));
12999
c19d1205 13000 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13001 inst.instruction |= 0x00200000; /* sh bit. */
13002
13003 inst.instruction |= (shift_amount & 0x1c) << 10;
13004 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13005 }
13006 }
b99bd4ef 13007}
c921be7d 13008
3a21c15a
NC
13009static void
13010do_t_ssat (void)
13011{
13012 do_t_ssat_usat (1);
13013}
b99bd4ef 13014
0dd132b6 13015static void
c19d1205 13016do_t_ssat16 (void)
0dd132b6 13017{
fdfde340
JM
13018 unsigned Rd, Rn;
13019
13020 Rd = inst.operands[0].reg;
13021 Rn = inst.operands[2].reg;
13022
13023 reject_bad_reg (Rd);
13024 reject_bad_reg (Rn);
13025
13026 inst.instruction |= Rd << 8;
c19d1205 13027 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13028 inst.instruction |= Rn << 16;
c19d1205 13029}
0dd132b6 13030
c19d1205
ZW
13031static void
13032do_t_strex (void)
13033{
13034 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13035 || inst.operands[2].postind || inst.operands[2].writeback
13036 || inst.operands[2].immisreg || inst.operands[2].shifted
13037 || inst.operands[2].negative,
01cfc07f 13038 BAD_ADDR_MODE);
0dd132b6 13039
5be8be5d
DG
13040 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13041
c19d1205
ZW
13042 inst.instruction |= inst.operands[0].reg << 8;
13043 inst.instruction |= inst.operands[1].reg << 12;
13044 inst.instruction |= inst.operands[2].reg << 16;
13045 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13046}
13047
b99bd4ef 13048static void
c19d1205 13049do_t_strexd (void)
b99bd4ef 13050{
c19d1205
ZW
13051 if (!inst.operands[2].present)
13052 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13053
c19d1205
ZW
13054 constraint (inst.operands[0].reg == inst.operands[1].reg
13055 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13056 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13057 BAD_OVERLAP);
b99bd4ef 13058
c19d1205
ZW
13059 inst.instruction |= inst.operands[0].reg;
13060 inst.instruction |= inst.operands[1].reg << 12;
13061 inst.instruction |= inst.operands[2].reg << 8;
13062 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13063}
13064
13065static void
c19d1205 13066do_t_sxtah (void)
b99bd4ef 13067{
fdfde340
JM
13068 unsigned Rd, Rn, Rm;
13069
13070 Rd = inst.operands[0].reg;
13071 Rn = inst.operands[1].reg;
13072 Rm = inst.operands[2].reg;
13073
13074 reject_bad_reg (Rd);
13075 reject_bad_reg (Rn);
13076 reject_bad_reg (Rm);
13077
13078 inst.instruction |= Rd << 8;
13079 inst.instruction |= Rn << 16;
13080 inst.instruction |= Rm;
c19d1205
ZW
13081 inst.instruction |= inst.operands[3].imm << 4;
13082}
b99bd4ef 13083
c19d1205
ZW
13084static void
13085do_t_sxth (void)
13086{
fdfde340
JM
13087 unsigned Rd, Rm;
13088
13089 Rd = inst.operands[0].reg;
13090 Rm = inst.operands[1].reg;
13091
13092 reject_bad_reg (Rd);
13093 reject_bad_reg (Rm);
c921be7d
NC
13094
13095 if (inst.instruction <= 0xffff
13096 && inst.size_req != 4
fdfde340 13097 && Rd <= 7 && Rm <= 7
c19d1205 13098 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13099 {
c19d1205 13100 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13101 inst.instruction |= Rd;
13102 inst.instruction |= Rm << 3;
b99bd4ef 13103 }
c19d1205 13104 else if (unified_syntax)
b99bd4ef 13105 {
c19d1205
ZW
13106 if (inst.instruction <= 0xffff)
13107 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13108 inst.instruction |= Rd << 8;
13109 inst.instruction |= Rm;
c19d1205 13110 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13111 }
c19d1205 13112 else
b99bd4ef 13113 {
c19d1205
ZW
13114 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13115 _("Thumb encoding does not support rotation"));
13116 constraint (1, BAD_HIREG);
b99bd4ef 13117 }
c19d1205 13118}
b99bd4ef 13119
c19d1205
ZW
13120static void
13121do_t_swi (void)
13122{
b2a5fbdc
MGD
13123 /* We have to do the following check manually as ARM_EXT_OS only applies
13124 to ARM_EXT_V6M. */
13125 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13126 {
ac7f631b 13127 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
2b0f3761 13128 /* This only applies to the v6m however, not later architectures. */
ac7f631b 13129 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13130 as_bad (_("SVC is not permitted on this architecture"));
13131 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13132 }
13133
c19d1205
ZW
13134 inst.reloc.type = BFD_RELOC_ARM_SWI;
13135}
b99bd4ef 13136
92e90b6e
PB
13137static void
13138do_t_tb (void)
13139{
fdfde340 13140 unsigned Rn, Rm;
92e90b6e
PB
13141 int half;
13142
13143 half = (inst.instruction & 0x10) != 0;
e07e6e58 13144 set_it_insn_type_last ();
dfa9f0d5
PB
13145 constraint (inst.operands[0].immisreg,
13146 _("instruction requires register index"));
fdfde340
JM
13147
13148 Rn = inst.operands[0].reg;
13149 Rm = inst.operands[0].imm;
c921be7d 13150
5c8ed6a4
JW
13151 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13152 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13153 reject_bad_reg (Rm);
13154
92e90b6e
PB
13155 constraint (!half && inst.operands[0].shifted,
13156 _("instruction does not allow shifted index"));
fdfde340 13157 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13158}
13159
74db7efb
NC
13160static void
13161do_t_udf (void)
13162{
13163 if (!inst.operands[0].present)
13164 inst.operands[0].imm = 0;
13165
13166 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13167 {
13168 constraint (inst.size_req == 2,
13169 _("immediate value out of range"));
13170 inst.instruction = THUMB_OP32 (inst.instruction);
13171 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13172 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13173 }
13174 else
13175 {
13176 inst.instruction = THUMB_OP16 (inst.instruction);
13177 inst.instruction |= inst.operands[0].imm;
13178 }
13179
13180 set_it_insn_type (NEUTRAL_IT_INSN);
13181}
13182
13183
c19d1205
ZW
13184static void
13185do_t_usat (void)
13186{
3a21c15a 13187 do_t_ssat_usat (0);
b99bd4ef
NC
13188}
13189
13190static void
c19d1205 13191do_t_usat16 (void)
b99bd4ef 13192{
fdfde340
JM
13193 unsigned Rd, Rn;
13194
13195 Rd = inst.operands[0].reg;
13196 Rn = inst.operands[2].reg;
13197
13198 reject_bad_reg (Rd);
13199 reject_bad_reg (Rn);
13200
13201 inst.instruction |= Rd << 8;
c19d1205 13202 inst.instruction |= inst.operands[1].imm;
fdfde340 13203 inst.instruction |= Rn << 16;
b99bd4ef 13204}
c19d1205 13205
5287ad62 13206/* Neon instruction encoder helpers. */
5f4273c7 13207
5287ad62 13208/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13209
5287ad62
JB
13210/* An "invalid" code for the following tables. */
13211#define N_INV -1u
13212
13213struct neon_tab_entry
b99bd4ef 13214{
5287ad62
JB
13215 unsigned integer;
13216 unsigned float_or_poly;
13217 unsigned scalar_or_imm;
13218};
5f4273c7 13219
5287ad62
JB
13220/* Map overloaded Neon opcodes to their respective encodings. */
13221#define NEON_ENC_TAB \
13222 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13223 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13224 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13225 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13226 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13227 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13228 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13229 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13230 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13231 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13232 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13233 /* Register variants of the following two instructions are encoded as
e07e6e58 13234 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13235 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13236 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13237 X(vfma, N_INV, 0x0000c10, N_INV), \
13238 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13239 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13240 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13241 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13242 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13243 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13244 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13245 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13246 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13247 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13248 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13249 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13250 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13251 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13252 X(vshl, 0x0000400, N_INV, 0x0800510), \
13253 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13254 X(vand, 0x0000110, N_INV, 0x0800030), \
13255 X(vbic, 0x0100110, N_INV, 0x0800030), \
13256 X(veor, 0x1000110, N_INV, N_INV), \
13257 X(vorn, 0x0300110, N_INV, 0x0800010), \
13258 X(vorr, 0x0200110, N_INV, 0x0800010), \
13259 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13260 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13261 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13262 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13263 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13264 X(vst1, 0x0000000, 0x0800000, N_INV), \
13265 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13266 X(vst2, 0x0000100, 0x0800100, N_INV), \
13267 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13268 X(vst3, 0x0000200, 0x0800200, N_INV), \
13269 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13270 X(vst4, 0x0000300, 0x0800300, N_INV), \
13271 X(vmovn, 0x1b20200, N_INV, N_INV), \
13272 X(vtrn, 0x1b20080, N_INV, N_INV), \
13273 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13274 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13275 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13276 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13277 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13278 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13279 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13280 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13281 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13282 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13283 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13284 X(vseleq, 0xe000a00, N_INV, N_INV), \
13285 X(vselvs, 0xe100a00, N_INV, N_INV), \
13286 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13287 X(vselgt, 0xe300a00, N_INV, N_INV), \
13288 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13289 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13290 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13291 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13292 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13293 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13294 X(sha3op, 0x2000c00, N_INV, N_INV), \
13295 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13296 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13297
13298enum neon_opc
13299{
13300#define X(OPC,I,F,S) N_MNEM_##OPC
13301NEON_ENC_TAB
13302#undef X
13303};
b99bd4ef 13304
5287ad62
JB
13305static const struct neon_tab_entry neon_enc_tab[] =
13306{
13307#define X(OPC,I,F,S) { (I), (F), (S) }
13308NEON_ENC_TAB
13309#undef X
13310};
b99bd4ef 13311
88714cb8
DG
13312/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13313#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13314#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13315#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13316#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13317#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13318#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13319#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13320#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13321#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13322#define NEON_ENC_SINGLE_(X) \
037e8744 13323 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13324#define NEON_ENC_DOUBLE_(X) \
037e8744 13325 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13326#define NEON_ENC_FPV8_(X) \
13327 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13328
88714cb8
DG
13329#define NEON_ENCODE(type, inst) \
13330 do \
13331 { \
13332 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13333 inst.is_neon = 1; \
13334 } \
13335 while (0)
13336
13337#define check_neon_suffixes \
13338 do \
13339 { \
13340 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13341 { \
13342 as_bad (_("invalid neon suffix for non neon instruction")); \
13343 return; \
13344 } \
13345 } \
13346 while (0)
13347
037e8744
JB
13348/* Define shapes for instruction operands. The following mnemonic characters
13349 are used in this table:
5287ad62 13350
037e8744 13351 F - VFP S<n> register
5287ad62
JB
13352 D - Neon D<n> register
13353 Q - Neon Q<n> register
13354 I - Immediate
13355 S - Scalar
13356 R - ARM register
13357 L - D<n> register list
5f4273c7 13358
037e8744
JB
13359 This table is used to generate various data:
13360 - enumerations of the form NS_DDR to be used as arguments to
13361 neon_select_shape.
13362 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13363 - a table used to drive neon_select_shape. */
b99bd4ef 13364
037e8744
JB
13365#define NEON_SHAPE_DEF \
13366 X(3, (D, D, D), DOUBLE), \
13367 X(3, (Q, Q, Q), QUAD), \
13368 X(3, (D, D, I), DOUBLE), \
13369 X(3, (Q, Q, I), QUAD), \
13370 X(3, (D, D, S), DOUBLE), \
13371 X(3, (Q, Q, S), QUAD), \
13372 X(2, (D, D), DOUBLE), \
13373 X(2, (Q, Q), QUAD), \
13374 X(2, (D, S), DOUBLE), \
13375 X(2, (Q, S), QUAD), \
13376 X(2, (D, R), DOUBLE), \
13377 X(2, (Q, R), QUAD), \
13378 X(2, (D, I), DOUBLE), \
13379 X(2, (Q, I), QUAD), \
13380 X(3, (D, L, D), DOUBLE), \
13381 X(2, (D, Q), MIXED), \
13382 X(2, (Q, D), MIXED), \
13383 X(3, (D, Q, I), MIXED), \
13384 X(3, (Q, D, I), MIXED), \
13385 X(3, (Q, D, D), MIXED), \
13386 X(3, (D, Q, Q), MIXED), \
13387 X(3, (Q, Q, D), MIXED), \
13388 X(3, (Q, D, S), MIXED), \
13389 X(3, (D, Q, S), MIXED), \
13390 X(4, (D, D, D, I), DOUBLE), \
13391 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13392 X(4, (D, D, S, I), DOUBLE), \
13393 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13394 X(2, (F, F), SINGLE), \
13395 X(3, (F, F, F), SINGLE), \
13396 X(2, (F, I), SINGLE), \
13397 X(2, (F, D), MIXED), \
13398 X(2, (D, F), MIXED), \
13399 X(3, (F, F, I), MIXED), \
13400 X(4, (R, R, F, F), SINGLE), \
13401 X(4, (F, F, R, R), SINGLE), \
13402 X(3, (D, R, R), DOUBLE), \
13403 X(3, (R, R, D), DOUBLE), \
13404 X(2, (S, R), SINGLE), \
13405 X(2, (R, S), SINGLE), \
13406 X(2, (F, R), SINGLE), \
d54af2d0
RL
13407 X(2, (R, F), SINGLE), \
13408/* Half float shape supported so far. */\
13409 X (2, (H, D), MIXED), \
13410 X (2, (D, H), MIXED), \
13411 X (2, (H, F), MIXED), \
13412 X (2, (F, H), MIXED), \
13413 X (2, (H, H), HALF), \
13414 X (2, (H, R), HALF), \
13415 X (2, (R, H), HALF), \
13416 X (2, (H, I), HALF), \
13417 X (3, (H, H, H), HALF), \
13418 X (3, (H, F, I), MIXED), \
13419 X (3, (F, H, I), MIXED)
037e8744
JB
13420
13421#define S2(A,B) NS_##A##B
13422#define S3(A,B,C) NS_##A##B##C
13423#define S4(A,B,C,D) NS_##A##B##C##D
13424
13425#define X(N, L, C) S##N L
13426
5287ad62
JB
13427enum neon_shape
13428{
037e8744
JB
13429 NEON_SHAPE_DEF,
13430 NS_NULL
5287ad62 13431};
b99bd4ef 13432
037e8744
JB
13433#undef X
13434#undef S2
13435#undef S3
13436#undef S4
13437
13438enum neon_shape_class
13439{
d54af2d0 13440 SC_HALF,
037e8744
JB
13441 SC_SINGLE,
13442 SC_DOUBLE,
13443 SC_QUAD,
13444 SC_MIXED
13445};
13446
13447#define X(N, L, C) SC_##C
13448
13449static enum neon_shape_class neon_shape_class[] =
13450{
13451 NEON_SHAPE_DEF
13452};
13453
13454#undef X
13455
13456enum neon_shape_el
13457{
d54af2d0 13458 SE_H,
037e8744
JB
13459 SE_F,
13460 SE_D,
13461 SE_Q,
13462 SE_I,
13463 SE_S,
13464 SE_R,
13465 SE_L
13466};
13467
13468/* Register widths of above. */
13469static unsigned neon_shape_el_size[] =
13470{
d54af2d0 13471 16,
037e8744
JB
13472 32,
13473 64,
13474 128,
13475 0,
13476 32,
13477 32,
13478 0
13479};
13480
13481struct neon_shape_info
13482{
13483 unsigned els;
13484 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13485};
13486
13487#define S2(A,B) { SE_##A, SE_##B }
13488#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13489#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13490
13491#define X(N, L, C) { N, S##N L }
13492
13493static struct neon_shape_info neon_shape_tab[] =
13494{
13495 NEON_SHAPE_DEF
13496};
13497
13498#undef X
13499#undef S2
13500#undef S3
13501#undef S4
13502
5287ad62
JB
13503/* Bit masks used in type checking given instructions.
13504 'N_EQK' means the type must be the same as (or based on in some way) the key
13505 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13506 set, various other bits can be set as well in order to modify the meaning of
13507 the type constraint. */
13508
13509enum neon_type_mask
13510{
8e79c3df
CM
13511 N_S8 = 0x0000001,
13512 N_S16 = 0x0000002,
13513 N_S32 = 0x0000004,
13514 N_S64 = 0x0000008,
13515 N_U8 = 0x0000010,
13516 N_U16 = 0x0000020,
13517 N_U32 = 0x0000040,
13518 N_U64 = 0x0000080,
13519 N_I8 = 0x0000100,
13520 N_I16 = 0x0000200,
13521 N_I32 = 0x0000400,
13522 N_I64 = 0x0000800,
13523 N_8 = 0x0001000,
13524 N_16 = 0x0002000,
13525 N_32 = 0x0004000,
13526 N_64 = 0x0008000,
13527 N_P8 = 0x0010000,
13528 N_P16 = 0x0020000,
13529 N_F16 = 0x0040000,
13530 N_F32 = 0x0080000,
13531 N_F64 = 0x0100000,
4f51b4bd 13532 N_P64 = 0x0200000,
c921be7d
NC
13533 N_KEY = 0x1000000, /* Key element (main type specifier). */
13534 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13535 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13536 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13537 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13538 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13539 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13540 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13541 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13542 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13543 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13544 N_UTYP = 0,
4f51b4bd 13545 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13546};
13547
dcbf9037
JB
13548#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13549
5287ad62
JB
13550#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13551#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13552#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13553#define N_S_32 (N_S8 | N_S16 | N_S32)
13554#define N_F_16_32 (N_F16 | N_F32)
13555#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13556#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13557#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13558#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13559
13560/* Pass this as the first type argument to neon_check_type to ignore types
13561 altogether. */
13562#define N_IGNORE_TYPE (N_KEY | N_EQK)
13563
037e8744
JB
13564/* Select a "shape" for the current instruction (describing register types or
13565 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13566 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13567 function of operand parsing, so this function doesn't need to be called.
13568 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13569
13570static enum neon_shape
037e8744 13571neon_select_shape (enum neon_shape shape, ...)
5287ad62 13572{
037e8744
JB
13573 va_list ap;
13574 enum neon_shape first_shape = shape;
5287ad62
JB
13575
13576 /* Fix missing optional operands. FIXME: we don't know at this point how
13577 many arguments we should have, so this makes the assumption that we have
13578 > 1. This is true of all current Neon opcodes, I think, but may not be
13579 true in the future. */
13580 if (!inst.operands[1].present)
13581 inst.operands[1] = inst.operands[0];
13582
037e8744 13583 va_start (ap, shape);
5f4273c7 13584
21d799b5 13585 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13586 {
13587 unsigned j;
13588 int matches = 1;
13589
13590 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13591 {
13592 if (!inst.operands[j].present)
13593 {
13594 matches = 0;
13595 break;
13596 }
13597
13598 switch (neon_shape_tab[shape].el[j])
13599 {
d54af2d0
RL
13600 /* If a .f16, .16, .u16, .s16 type specifier is given over
13601 a VFP single precision register operand, it's essentially
13602 means only half of the register is used.
13603
13604 If the type specifier is given after the mnemonics, the
13605 information is stored in inst.vectype. If the type specifier
13606 is given after register operand, the information is stored
13607 in inst.operands[].vectype.
13608
13609 When there is only one type specifier, and all the register
13610 operands are the same type of hardware register, the type
13611 specifier applies to all register operands.
13612
13613 If no type specifier is given, the shape is inferred from
13614 operand information.
13615
13616 for example:
13617 vadd.f16 s0, s1, s2: NS_HHH
13618 vabs.f16 s0, s1: NS_HH
13619 vmov.f16 s0, r1: NS_HR
13620 vmov.f16 r0, s1: NS_RH
13621 vcvt.f16 r0, s1: NS_RH
13622 vcvt.f16.s32 s2, s2, #29: NS_HFI
13623 vcvt.f16.s32 s2, s2: NS_HF
13624 */
13625 case SE_H:
13626 if (!(inst.operands[j].isreg
13627 && inst.operands[j].isvec
13628 && inst.operands[j].issingle
13629 && !inst.operands[j].isquad
13630 && ((inst.vectype.elems == 1
13631 && inst.vectype.el[0].size == 16)
13632 || (inst.vectype.elems > 1
13633 && inst.vectype.el[j].size == 16)
13634 || (inst.vectype.elems == 0
13635 && inst.operands[j].vectype.type != NT_invtype
13636 && inst.operands[j].vectype.size == 16))))
13637 matches = 0;
13638 break;
13639
477330fc
RM
13640 case SE_F:
13641 if (!(inst.operands[j].isreg
13642 && inst.operands[j].isvec
13643 && inst.operands[j].issingle
d54af2d0
RL
13644 && !inst.operands[j].isquad
13645 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13646 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13647 || (inst.vectype.elems == 0
13648 && (inst.operands[j].vectype.size == 32
13649 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13650 matches = 0;
13651 break;
13652
13653 case SE_D:
13654 if (!(inst.operands[j].isreg
13655 && inst.operands[j].isvec
13656 && !inst.operands[j].isquad
13657 && !inst.operands[j].issingle))
13658 matches = 0;
13659 break;
13660
13661 case SE_R:
13662 if (!(inst.operands[j].isreg
13663 && !inst.operands[j].isvec))
13664 matches = 0;
13665 break;
13666
13667 case SE_Q:
13668 if (!(inst.operands[j].isreg
13669 && inst.operands[j].isvec
13670 && inst.operands[j].isquad
13671 && !inst.operands[j].issingle))
13672 matches = 0;
13673 break;
13674
13675 case SE_I:
13676 if (!(!inst.operands[j].isreg
13677 && !inst.operands[j].isscalar))
13678 matches = 0;
13679 break;
13680
13681 case SE_S:
13682 if (!(!inst.operands[j].isreg
13683 && inst.operands[j].isscalar))
13684 matches = 0;
13685 break;
13686
13687 case SE_L:
13688 break;
13689 }
3fde54a2
JZ
13690 if (!matches)
13691 break;
477330fc 13692 }
ad6cec43
MGD
13693 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13694 /* We've matched all the entries in the shape table, and we don't
13695 have any left over operands which have not been matched. */
477330fc 13696 break;
037e8744 13697 }
5f4273c7 13698
037e8744 13699 va_end (ap);
5287ad62 13700
037e8744
JB
13701 if (shape == NS_NULL && first_shape != NS_NULL)
13702 first_error (_("invalid instruction shape"));
5287ad62 13703
037e8744
JB
13704 return shape;
13705}
5287ad62 13706
037e8744
JB
13707/* True if SHAPE is predominantly a quadword operation (most of the time, this
13708 means the Q bit should be set). */
13709
13710static int
13711neon_quad (enum neon_shape shape)
13712{
13713 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13714}
037e8744 13715
5287ad62
JB
13716static void
13717neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13718 unsigned *g_size)
5287ad62
JB
13719{
13720 /* Allow modification to be made to types which are constrained to be
13721 based on the key element, based on bits set alongside N_EQK. */
13722 if ((typebits & N_EQK) != 0)
13723 {
13724 if ((typebits & N_HLF) != 0)
13725 *g_size /= 2;
13726 else if ((typebits & N_DBL) != 0)
13727 *g_size *= 2;
13728 if ((typebits & N_SGN) != 0)
13729 *g_type = NT_signed;
13730 else if ((typebits & N_UNS) != 0)
477330fc 13731 *g_type = NT_unsigned;
5287ad62 13732 else if ((typebits & N_INT) != 0)
477330fc 13733 *g_type = NT_integer;
5287ad62 13734 else if ((typebits & N_FLT) != 0)
477330fc 13735 *g_type = NT_float;
dcbf9037 13736 else if ((typebits & N_SIZ) != 0)
477330fc 13737 *g_type = NT_untyped;
5287ad62
JB
13738 }
13739}
5f4273c7 13740
5287ad62
JB
13741/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13742 operand type, i.e. the single type specified in a Neon instruction when it
13743 is the only one given. */
13744
13745static struct neon_type_el
13746neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13747{
13748 struct neon_type_el dest = *key;
5f4273c7 13749
9c2799c2 13750 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13751
5287ad62
JB
13752 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13753
13754 return dest;
13755}
13756
13757/* Convert Neon type and size into compact bitmask representation. */
13758
13759static enum neon_type_mask
13760type_chk_of_el_type (enum neon_el_type type, unsigned size)
13761{
13762 switch (type)
13763 {
13764 case NT_untyped:
13765 switch (size)
477330fc
RM
13766 {
13767 case 8: return N_8;
13768 case 16: return N_16;
13769 case 32: return N_32;
13770 case 64: return N_64;
13771 default: ;
13772 }
5287ad62
JB
13773 break;
13774
13775 case NT_integer:
13776 switch (size)
477330fc
RM
13777 {
13778 case 8: return N_I8;
13779 case 16: return N_I16;
13780 case 32: return N_I32;
13781 case 64: return N_I64;
13782 default: ;
13783 }
5287ad62
JB
13784 break;
13785
13786 case NT_float:
037e8744 13787 switch (size)
477330fc 13788 {
8e79c3df 13789 case 16: return N_F16;
477330fc
RM
13790 case 32: return N_F32;
13791 case 64: return N_F64;
13792 default: ;
13793 }
5287ad62
JB
13794 break;
13795
13796 case NT_poly:
13797 switch (size)
477330fc
RM
13798 {
13799 case 8: return N_P8;
13800 case 16: return N_P16;
4f51b4bd 13801 case 64: return N_P64;
477330fc
RM
13802 default: ;
13803 }
5287ad62
JB
13804 break;
13805
13806 case NT_signed:
13807 switch (size)
477330fc
RM
13808 {
13809 case 8: return N_S8;
13810 case 16: return N_S16;
13811 case 32: return N_S32;
13812 case 64: return N_S64;
13813 default: ;
13814 }
5287ad62
JB
13815 break;
13816
13817 case NT_unsigned:
13818 switch (size)
477330fc
RM
13819 {
13820 case 8: return N_U8;
13821 case 16: return N_U16;
13822 case 32: return N_U32;
13823 case 64: return N_U64;
13824 default: ;
13825 }
5287ad62
JB
13826 break;
13827
13828 default: ;
13829 }
5f4273c7 13830
5287ad62
JB
13831 return N_UTYP;
13832}
13833
13834/* Convert compact Neon bitmask type representation to a type and size. Only
13835 handles the case where a single bit is set in the mask. */
13836
dcbf9037 13837static int
5287ad62 13838el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13839 enum neon_type_mask mask)
5287ad62 13840{
dcbf9037
JB
13841 if ((mask & N_EQK) != 0)
13842 return FAIL;
13843
5287ad62
JB
13844 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13845 *size = 8;
c70a8987 13846 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13847 *size = 16;
dcbf9037 13848 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13849 *size = 32;
4f51b4bd 13850 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13851 *size = 64;
dcbf9037
JB
13852 else
13853 return FAIL;
13854
5287ad62
JB
13855 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13856 *type = NT_signed;
dcbf9037 13857 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13858 *type = NT_unsigned;
dcbf9037 13859 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13860 *type = NT_integer;
dcbf9037 13861 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13862 *type = NT_untyped;
4f51b4bd 13863 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13864 *type = NT_poly;
d54af2d0 13865 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13866 *type = NT_float;
dcbf9037
JB
13867 else
13868 return FAIL;
5f4273c7 13869
dcbf9037 13870 return SUCCESS;
5287ad62
JB
13871}
13872
13873/* Modify a bitmask of allowed types. This is only needed for type
13874 relaxation. */
13875
13876static unsigned
13877modify_types_allowed (unsigned allowed, unsigned mods)
13878{
13879 unsigned size;
13880 enum neon_el_type type;
13881 unsigned destmask;
13882 int i;
5f4273c7 13883
5287ad62 13884 destmask = 0;
5f4273c7 13885
5287ad62
JB
13886 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13887 {
21d799b5 13888 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13889 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13890 {
13891 neon_modify_type_size (mods, &type, &size);
13892 destmask |= type_chk_of_el_type (type, size);
13893 }
5287ad62 13894 }
5f4273c7 13895
5287ad62
JB
13896 return destmask;
13897}
13898
13899/* Check type and return type classification.
13900 The manual states (paraphrase): If one datatype is given, it indicates the
13901 type given in:
13902 - the second operand, if there is one
13903 - the operand, if there is no second operand
13904 - the result, if there are no operands.
13905 This isn't quite good enough though, so we use a concept of a "key" datatype
13906 which is set on a per-instruction basis, which is the one which matters when
13907 only one data type is written.
13908 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13909 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13910
13911static struct neon_type_el
13912neon_check_type (unsigned els, enum neon_shape ns, ...)
13913{
13914 va_list ap;
13915 unsigned i, pass, key_el = 0;
13916 unsigned types[NEON_MAX_TYPE_ELS];
13917 enum neon_el_type k_type = NT_invtype;
13918 unsigned k_size = -1u;
13919 struct neon_type_el badtype = {NT_invtype, -1};
13920 unsigned key_allowed = 0;
13921
13922 /* Optional registers in Neon instructions are always (not) in operand 1.
13923 Fill in the missing operand here, if it was omitted. */
13924 if (els > 1 && !inst.operands[1].present)
13925 inst.operands[1] = inst.operands[0];
13926
13927 /* Suck up all the varargs. */
13928 va_start (ap, ns);
13929 for (i = 0; i < els; i++)
13930 {
13931 unsigned thisarg = va_arg (ap, unsigned);
13932 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13933 {
13934 va_end (ap);
13935 return badtype;
13936 }
5287ad62
JB
13937 types[i] = thisarg;
13938 if ((thisarg & N_KEY) != 0)
477330fc 13939 key_el = i;
5287ad62
JB
13940 }
13941 va_end (ap);
13942
dcbf9037
JB
13943 if (inst.vectype.elems > 0)
13944 for (i = 0; i < els; i++)
13945 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13946 {
13947 first_error (_("types specified in both the mnemonic and operands"));
13948 return badtype;
13949 }
dcbf9037 13950
5287ad62
JB
13951 /* Duplicate inst.vectype elements here as necessary.
13952 FIXME: No idea if this is exactly the same as the ARM assembler,
13953 particularly when an insn takes one register and one non-register
13954 operand. */
13955 if (inst.vectype.elems == 1 && els > 1)
13956 {
13957 unsigned j;
13958 inst.vectype.elems = els;
13959 inst.vectype.el[key_el] = inst.vectype.el[0];
13960 for (j = 0; j < els; j++)
477330fc
RM
13961 if (j != key_el)
13962 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13963 types[j]);
dcbf9037
JB
13964 }
13965 else if (inst.vectype.elems == 0 && els > 0)
13966 {
13967 unsigned j;
13968 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13969 after each operand. We allow some flexibility here; as long as the
13970 "key" operand has a type, we can infer the others. */
dcbf9037 13971 for (j = 0; j < els; j++)
477330fc
RM
13972 if (inst.operands[j].vectype.type != NT_invtype)
13973 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13974
13975 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13976 {
13977 for (j = 0; j < els; j++)
13978 if (inst.operands[j].vectype.type == NT_invtype)
13979 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13980 types[j]);
13981 }
dcbf9037 13982 else
477330fc
RM
13983 {
13984 first_error (_("operand types can't be inferred"));
13985 return badtype;
13986 }
5287ad62
JB
13987 }
13988 else if (inst.vectype.elems != els)
13989 {
dcbf9037 13990 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13991 return badtype;
13992 }
13993
13994 for (pass = 0; pass < 2; pass++)
13995 {
13996 for (i = 0; i < els; i++)
477330fc
RM
13997 {
13998 unsigned thisarg = types[i];
13999 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14000 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14001 enum neon_el_type g_type = inst.vectype.el[i].type;
14002 unsigned g_size = inst.vectype.el[i].size;
14003
14004 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14005 integer types if sign-specific variants are unavailable. */
477330fc 14006 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14007 && (types_allowed & N_SU_ALL) == 0)
14008 g_type = NT_integer;
14009
477330fc 14010 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14011 them. Some instructions only care about signs for some element
14012 sizes, so handle that properly. */
477330fc 14013 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14014 && ((g_size == 8 && (types_allowed & N_8) != 0)
14015 || (g_size == 16 && (types_allowed & N_16) != 0)
14016 || (g_size == 32 && (types_allowed & N_32) != 0)
14017 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14018 g_type = NT_untyped;
14019
477330fc
RM
14020 if (pass == 0)
14021 {
14022 if ((thisarg & N_KEY) != 0)
14023 {
14024 k_type = g_type;
14025 k_size = g_size;
14026 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14027
14028 /* Check architecture constraint on FP16 extension. */
14029 if (k_size == 16
14030 && k_type == NT_float
14031 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14032 {
14033 inst.error = _(BAD_FP16);
14034 return badtype;
14035 }
477330fc
RM
14036 }
14037 }
14038 else
14039 {
14040 if ((thisarg & N_VFP) != 0)
14041 {
14042 enum neon_shape_el regshape;
14043 unsigned regwidth, match;
99b253c5
NC
14044
14045 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14046 if (ns == NS_NULL)
14047 {
14048 first_error (_("invalid instruction shape"));
14049 return badtype;
14050 }
477330fc
RM
14051 regshape = neon_shape_tab[ns].el[i];
14052 regwidth = neon_shape_el_size[regshape];
14053
14054 /* In VFP mode, operands must match register widths. If we
14055 have a key operand, use its width, else use the width of
14056 the current operand. */
14057 if (k_size != -1u)
14058 match = k_size;
14059 else
14060 match = g_size;
14061
9db2f6b4
RL
14062 /* FP16 will use a single precision register. */
14063 if (regwidth == 32 && match == 16)
14064 {
14065 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14066 match = regwidth;
14067 else
14068 {
14069 inst.error = _(BAD_FP16);
14070 return badtype;
14071 }
14072 }
14073
477330fc
RM
14074 if (regwidth != match)
14075 {
14076 first_error (_("operand size must match register width"));
14077 return badtype;
14078 }
14079 }
14080
14081 if ((thisarg & N_EQK) == 0)
14082 {
14083 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14084
14085 if ((given_type & types_allowed) == 0)
14086 {
14087 first_error (_("bad type in Neon instruction"));
14088 return badtype;
14089 }
14090 }
14091 else
14092 {
14093 enum neon_el_type mod_k_type = k_type;
14094 unsigned mod_k_size = k_size;
14095 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14096 if (g_type != mod_k_type || g_size != mod_k_size)
14097 {
14098 first_error (_("inconsistent types in Neon instruction"));
14099 return badtype;
14100 }
14101 }
14102 }
14103 }
5287ad62
JB
14104 }
14105
14106 return inst.vectype.el[key_el];
14107}
14108
037e8744 14109/* Neon-style VFP instruction forwarding. */
5287ad62 14110
037e8744
JB
14111/* Thumb VFP instructions have 0xE in the condition field. */
14112
14113static void
14114do_vfp_cond_or_thumb (void)
5287ad62 14115{
88714cb8
DG
14116 inst.is_neon = 1;
14117
5287ad62 14118 if (thumb_mode)
037e8744 14119 inst.instruction |= 0xe0000000;
5287ad62 14120 else
037e8744 14121 inst.instruction |= inst.cond << 28;
5287ad62
JB
14122}
14123
037e8744
JB
14124/* Look up and encode a simple mnemonic, for use as a helper function for the
14125 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14126 etc. It is assumed that operand parsing has already been done, and that the
14127 operands are in the form expected by the given opcode (this isn't necessarily
14128 the same as the form in which they were parsed, hence some massaging must
14129 take place before this function is called).
14130 Checks current arch version against that in the looked-up opcode. */
5287ad62 14131
037e8744
JB
14132static void
14133do_vfp_nsyn_opcode (const char *opname)
5287ad62 14134{
037e8744 14135 const struct asm_opcode *opcode;
5f4273c7 14136
21d799b5 14137 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14138
037e8744
JB
14139 if (!opcode)
14140 abort ();
5287ad62 14141
037e8744 14142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14143 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14144 _(BAD_FPU));
5287ad62 14145
88714cb8
DG
14146 inst.is_neon = 1;
14147
037e8744
JB
14148 if (thumb_mode)
14149 {
14150 inst.instruction = opcode->tvalue;
14151 opcode->tencode ();
14152 }
14153 else
14154 {
14155 inst.instruction = (inst.cond << 28) | opcode->avalue;
14156 opcode->aencode ();
14157 }
14158}
5287ad62
JB
14159
14160static void
037e8744 14161do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14162{
037e8744
JB
14163 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14164
9db2f6b4 14165 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14166 {
14167 if (is_add)
477330fc 14168 do_vfp_nsyn_opcode ("fadds");
037e8744 14169 else
477330fc 14170 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14171
14172 /* ARMv8.2 fp16 instruction. */
14173 if (rs == NS_HHH)
14174 do_scalar_fp16_v82_encode ();
037e8744
JB
14175 }
14176 else
14177 {
14178 if (is_add)
477330fc 14179 do_vfp_nsyn_opcode ("faddd");
037e8744 14180 else
477330fc 14181 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14182 }
14183}
14184
14185/* Check operand types to see if this is a VFP instruction, and if so call
14186 PFN (). */
14187
14188static int
14189try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14190{
14191 enum neon_shape rs;
14192 struct neon_type_el et;
14193
14194 switch (args)
14195 {
14196 case 2:
9db2f6b4
RL
14197 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14198 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14199 break;
5f4273c7 14200
037e8744 14201 case 3:
9db2f6b4
RL
14202 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14203 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14204 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14205 break;
14206
14207 default:
14208 abort ();
14209 }
14210
14211 if (et.type != NT_invtype)
14212 {
14213 pfn (rs);
14214 return SUCCESS;
14215 }
037e8744 14216
99b253c5 14217 inst.error = NULL;
037e8744
JB
14218 return FAIL;
14219}
14220
14221static void
14222do_vfp_nsyn_mla_mls (enum neon_shape rs)
14223{
14224 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14225
9db2f6b4 14226 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14227 {
14228 if (is_mla)
477330fc 14229 do_vfp_nsyn_opcode ("fmacs");
037e8744 14230 else
477330fc 14231 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14232
14233 /* ARMv8.2 fp16 instruction. */
14234 if (rs == NS_HHH)
14235 do_scalar_fp16_v82_encode ();
037e8744
JB
14236 }
14237 else
14238 {
14239 if (is_mla)
477330fc 14240 do_vfp_nsyn_opcode ("fmacd");
037e8744 14241 else
477330fc 14242 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14243 }
14244}
14245
62f3b8c8
PB
14246static void
14247do_vfp_nsyn_fma_fms (enum neon_shape rs)
14248{
14249 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14250
9db2f6b4 14251 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14252 {
14253 if (is_fma)
477330fc 14254 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14255 else
477330fc 14256 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14257
14258 /* ARMv8.2 fp16 instruction. */
14259 if (rs == NS_HHH)
14260 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14261 }
14262 else
14263 {
14264 if (is_fma)
477330fc 14265 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14266 else
477330fc 14267 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14268 }
14269}
14270
037e8744
JB
14271static void
14272do_vfp_nsyn_mul (enum neon_shape rs)
14273{
9db2f6b4
RL
14274 if (rs == NS_FFF || rs == NS_HHH)
14275 {
14276 do_vfp_nsyn_opcode ("fmuls");
14277
14278 /* ARMv8.2 fp16 instruction. */
14279 if (rs == NS_HHH)
14280 do_scalar_fp16_v82_encode ();
14281 }
037e8744
JB
14282 else
14283 do_vfp_nsyn_opcode ("fmuld");
14284}
14285
14286static void
14287do_vfp_nsyn_abs_neg (enum neon_shape rs)
14288{
14289 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14290 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14291
9db2f6b4 14292 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14293 {
14294 if (is_neg)
477330fc 14295 do_vfp_nsyn_opcode ("fnegs");
037e8744 14296 else
477330fc 14297 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14298
14299 /* ARMv8.2 fp16 instruction. */
14300 if (rs == NS_HH)
14301 do_scalar_fp16_v82_encode ();
037e8744
JB
14302 }
14303 else
14304 {
14305 if (is_neg)
477330fc 14306 do_vfp_nsyn_opcode ("fnegd");
037e8744 14307 else
477330fc 14308 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14309 }
14310}
14311
14312/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14313 insns belong to Neon, and are handled elsewhere. */
14314
14315static void
14316do_vfp_nsyn_ldm_stm (int is_dbmode)
14317{
14318 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14319 if (is_ldm)
14320 {
14321 if (is_dbmode)
477330fc 14322 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14323 else
477330fc 14324 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14325 }
14326 else
14327 {
14328 if (is_dbmode)
477330fc 14329 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14330 else
477330fc 14331 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14332 }
14333}
14334
037e8744
JB
14335static void
14336do_vfp_nsyn_sqrt (void)
14337{
9db2f6b4
RL
14338 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14339 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14340
9db2f6b4
RL
14341 if (rs == NS_FF || rs == NS_HH)
14342 {
14343 do_vfp_nsyn_opcode ("fsqrts");
14344
14345 /* ARMv8.2 fp16 instruction. */
14346 if (rs == NS_HH)
14347 do_scalar_fp16_v82_encode ();
14348 }
037e8744
JB
14349 else
14350 do_vfp_nsyn_opcode ("fsqrtd");
14351}
14352
14353static void
14354do_vfp_nsyn_div (void)
14355{
9db2f6b4 14356 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14357 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14358 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14359
9db2f6b4
RL
14360 if (rs == NS_FFF || rs == NS_HHH)
14361 {
14362 do_vfp_nsyn_opcode ("fdivs");
14363
14364 /* ARMv8.2 fp16 instruction. */
14365 if (rs == NS_HHH)
14366 do_scalar_fp16_v82_encode ();
14367 }
037e8744
JB
14368 else
14369 do_vfp_nsyn_opcode ("fdivd");
14370}
14371
14372static void
14373do_vfp_nsyn_nmul (void)
14374{
9db2f6b4 14375 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14376 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14377 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14378
9db2f6b4 14379 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14380 {
88714cb8 14381 NEON_ENCODE (SINGLE, inst);
037e8744 14382 do_vfp_sp_dyadic ();
9db2f6b4
RL
14383
14384 /* ARMv8.2 fp16 instruction. */
14385 if (rs == NS_HHH)
14386 do_scalar_fp16_v82_encode ();
037e8744
JB
14387 }
14388 else
14389 {
88714cb8 14390 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14391 do_vfp_dp_rd_rn_rm ();
14392 }
14393 do_vfp_cond_or_thumb ();
9db2f6b4 14394
037e8744
JB
14395}
14396
14397static void
14398do_vfp_nsyn_cmp (void)
14399{
9db2f6b4 14400 enum neon_shape rs;
037e8744
JB
14401 if (inst.operands[1].isreg)
14402 {
9db2f6b4
RL
14403 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14404 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14405
9db2f6b4 14406 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14407 {
14408 NEON_ENCODE (SINGLE, inst);
14409 do_vfp_sp_monadic ();
14410 }
037e8744 14411 else
477330fc
RM
14412 {
14413 NEON_ENCODE (DOUBLE, inst);
14414 do_vfp_dp_rd_rm ();
14415 }
037e8744
JB
14416 }
14417 else
14418 {
9db2f6b4
RL
14419 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14420 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14421
14422 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14423 {
14424 case N_MNEM_vcmp:
14425 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14426 break;
14427 case N_MNEM_vcmpe:
14428 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14429 break;
14430 default:
14431 abort ();
14432 }
5f4273c7 14433
9db2f6b4 14434 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14435 {
14436 NEON_ENCODE (SINGLE, inst);
14437 do_vfp_sp_compare_z ();
14438 }
037e8744 14439 else
477330fc
RM
14440 {
14441 NEON_ENCODE (DOUBLE, inst);
14442 do_vfp_dp_rd ();
14443 }
037e8744
JB
14444 }
14445 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14446
14447 /* ARMv8.2 fp16 instruction. */
14448 if (rs == NS_HI || rs == NS_HH)
14449 do_scalar_fp16_v82_encode ();
037e8744
JB
14450}
14451
14452static void
14453nsyn_insert_sp (void)
14454{
14455 inst.operands[1] = inst.operands[0];
14456 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14457 inst.operands[0].reg = REG_SP;
037e8744
JB
14458 inst.operands[0].isreg = 1;
14459 inst.operands[0].writeback = 1;
14460 inst.operands[0].present = 1;
14461}
14462
14463static void
14464do_vfp_nsyn_push (void)
14465{
14466 nsyn_insert_sp ();
b126985e
NC
14467
14468 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14469 _("register list must contain at least 1 and at most 16 "
14470 "registers"));
14471
037e8744
JB
14472 if (inst.operands[1].issingle)
14473 do_vfp_nsyn_opcode ("fstmdbs");
14474 else
14475 do_vfp_nsyn_opcode ("fstmdbd");
14476}
14477
14478static void
14479do_vfp_nsyn_pop (void)
14480{
14481 nsyn_insert_sp ();
b126985e
NC
14482
14483 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14484 _("register list must contain at least 1 and at most 16 "
14485 "registers"));
14486
037e8744 14487 if (inst.operands[1].issingle)
22b5b651 14488 do_vfp_nsyn_opcode ("fldmias");
037e8744 14489 else
22b5b651 14490 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14491}
14492
14493/* Fix up Neon data-processing instructions, ORing in the correct bits for
14494 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14495
88714cb8
DG
14496static void
14497neon_dp_fixup (struct arm_it* insn)
037e8744 14498{
88714cb8
DG
14499 unsigned int i = insn->instruction;
14500 insn->is_neon = 1;
14501
037e8744
JB
14502 if (thumb_mode)
14503 {
14504 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14505 if (i & (1 << 24))
477330fc 14506 i |= 1 << 28;
5f4273c7 14507
037e8744 14508 i &= ~(1 << 24);
5f4273c7 14509
037e8744
JB
14510 i |= 0xef000000;
14511 }
14512 else
14513 i |= 0xf2000000;
5f4273c7 14514
88714cb8 14515 insn->instruction = i;
037e8744
JB
14516}
14517
14518/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14519 (0, 1, 2, 3). */
14520
14521static unsigned
14522neon_logbits (unsigned x)
14523{
14524 return ffs (x) - 4;
14525}
14526
14527#define LOW4(R) ((R) & 0xf)
14528#define HI1(R) (((R) >> 4) & 1)
14529
14530/* Encode insns with bit pattern:
14531
14532 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14533 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14534
037e8744
JB
14535 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14536 different meaning for some instruction. */
14537
14538static void
14539neon_three_same (int isquad, int ubit, int size)
14540{
14541 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14542 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14543 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14544 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14545 inst.instruction |= LOW4 (inst.operands[2].reg);
14546 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14547 inst.instruction |= (isquad != 0) << 6;
14548 inst.instruction |= (ubit != 0) << 24;
14549 if (size != -1)
14550 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14551
88714cb8 14552 neon_dp_fixup (&inst);
037e8744
JB
14553}
14554
14555/* Encode instructions of the form:
14556
14557 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14558 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14559
14560 Don't write size if SIZE == -1. */
14561
14562static void
14563neon_two_same (int qbit, int ubit, int size)
14564{
14565 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14566 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14567 inst.instruction |= LOW4 (inst.operands[1].reg);
14568 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14569 inst.instruction |= (qbit != 0) << 6;
14570 inst.instruction |= (ubit != 0) << 24;
14571
14572 if (size != -1)
14573 inst.instruction |= neon_logbits (size) << 18;
14574
88714cb8 14575 neon_dp_fixup (&inst);
5287ad62
JB
14576}
14577
14578/* Neon instruction encoders, in approximate order of appearance. */
14579
14580static void
14581do_neon_dyadic_i_su (void)
14582{
037e8744 14583 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14584 struct neon_type_el et = neon_check_type (3, rs,
14585 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14586 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14587}
14588
14589static void
14590do_neon_dyadic_i64_su (void)
14591{
037e8744 14592 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14593 struct neon_type_el et = neon_check_type (3, rs,
14594 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14595 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14596}
14597
14598static void
14599neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14600 unsigned immbits)
5287ad62
JB
14601{
14602 unsigned size = et.size >> 3;
14603 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14604 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14605 inst.instruction |= LOW4 (inst.operands[1].reg);
14606 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14607 inst.instruction |= (isquad != 0) << 6;
14608 inst.instruction |= immbits << 16;
14609 inst.instruction |= (size >> 3) << 7;
14610 inst.instruction |= (size & 0x7) << 19;
14611 if (write_ubit)
14612 inst.instruction |= (uval != 0) << 24;
14613
88714cb8 14614 neon_dp_fixup (&inst);
5287ad62
JB
14615}
14616
14617static void
14618do_neon_shl_imm (void)
14619{
14620 if (!inst.operands[2].isreg)
14621 {
037e8744 14622 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14623 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14624 int imm = inst.operands[2].imm;
14625
14626 constraint (imm < 0 || (unsigned)imm >= et.size,
14627 _("immediate out of range for shift"));
88714cb8 14628 NEON_ENCODE (IMMED, inst);
cb3b1e65 14629 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14630 }
14631 else
14632 {
037e8744 14633 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14634 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14635 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14636 unsigned int tmp;
14637
14638 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14639 vshl.xx Dd, Dm, Dn
14640 whereas other 3-register operations encoded by neon_three_same have
14641 syntax like:
14642 vadd.xx Dd, Dn, Dm
14643 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14644 here. */
627907b7
JB
14645 tmp = inst.operands[2].reg;
14646 inst.operands[2].reg = inst.operands[1].reg;
14647 inst.operands[1].reg = tmp;
88714cb8 14648 NEON_ENCODE (INTEGER, inst);
037e8744 14649 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14650 }
14651}
14652
14653static void
14654do_neon_qshl_imm (void)
14655{
14656 if (!inst.operands[2].isreg)
14657 {
037e8744 14658 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14659 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14660 int imm = inst.operands[2].imm;
627907b7 14661
cb3b1e65
JB
14662 constraint (imm < 0 || (unsigned)imm >= et.size,
14663 _("immediate out of range for shift"));
88714cb8 14664 NEON_ENCODE (IMMED, inst);
cb3b1e65 14665 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14666 }
14667 else
14668 {
037e8744 14669 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14670 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14671 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14672 unsigned int tmp;
14673
14674 /* See note in do_neon_shl_imm. */
14675 tmp = inst.operands[2].reg;
14676 inst.operands[2].reg = inst.operands[1].reg;
14677 inst.operands[1].reg = tmp;
88714cb8 14678 NEON_ENCODE (INTEGER, inst);
037e8744 14679 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14680 }
14681}
14682
627907b7
JB
14683static void
14684do_neon_rshl (void)
14685{
14686 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14687 struct neon_type_el et = neon_check_type (3, rs,
14688 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14689 unsigned int tmp;
14690
14691 tmp = inst.operands[2].reg;
14692 inst.operands[2].reg = inst.operands[1].reg;
14693 inst.operands[1].reg = tmp;
14694 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14695}
14696
5287ad62
JB
14697static int
14698neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14699{
036dc3f7
PB
14700 /* Handle .I8 pseudo-instructions. */
14701 if (size == 8)
5287ad62 14702 {
5287ad62 14703 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14704 FIXME is this the intended semantics? There doesn't seem much point in
14705 accepting .I8 if so. */
5287ad62
JB
14706 immediate |= immediate << 8;
14707 size = 16;
036dc3f7
PB
14708 }
14709
14710 if (size >= 32)
14711 {
14712 if (immediate == (immediate & 0x000000ff))
14713 {
14714 *immbits = immediate;
14715 return 0x1;
14716 }
14717 else if (immediate == (immediate & 0x0000ff00))
14718 {
14719 *immbits = immediate >> 8;
14720 return 0x3;
14721 }
14722 else if (immediate == (immediate & 0x00ff0000))
14723 {
14724 *immbits = immediate >> 16;
14725 return 0x5;
14726 }
14727 else if (immediate == (immediate & 0xff000000))
14728 {
14729 *immbits = immediate >> 24;
14730 return 0x7;
14731 }
14732 if ((immediate & 0xffff) != (immediate >> 16))
14733 goto bad_immediate;
14734 immediate &= 0xffff;
5287ad62
JB
14735 }
14736
14737 if (immediate == (immediate & 0x000000ff))
14738 {
14739 *immbits = immediate;
036dc3f7 14740 return 0x9;
5287ad62
JB
14741 }
14742 else if (immediate == (immediate & 0x0000ff00))
14743 {
14744 *immbits = immediate >> 8;
036dc3f7 14745 return 0xb;
5287ad62
JB
14746 }
14747
14748 bad_immediate:
dcbf9037 14749 first_error (_("immediate value out of range"));
5287ad62
JB
14750 return FAIL;
14751}
14752
5287ad62
JB
14753static void
14754do_neon_logic (void)
14755{
14756 if (inst.operands[2].present && inst.operands[2].isreg)
14757 {
037e8744 14758 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14759 neon_check_type (3, rs, N_IGNORE_TYPE);
14760 /* U bit and size field were set as part of the bitmask. */
88714cb8 14761 NEON_ENCODE (INTEGER, inst);
037e8744 14762 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14763 }
14764 else
14765 {
4316f0d2
DG
14766 const int three_ops_form = (inst.operands[2].present
14767 && !inst.operands[2].isreg);
14768 const int immoperand = (three_ops_form ? 2 : 1);
14769 enum neon_shape rs = (three_ops_form
14770 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14771 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14772 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14773 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14774 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14775 unsigned immbits;
14776 int cmode;
5f4273c7 14777
5287ad62 14778 if (et.type == NT_invtype)
477330fc 14779 return;
5f4273c7 14780
4316f0d2
DG
14781 if (three_ops_form)
14782 constraint (inst.operands[0].reg != inst.operands[1].reg,
14783 _("first and second operands shall be the same register"));
14784
88714cb8 14785 NEON_ENCODE (IMMED, inst);
5287ad62 14786
4316f0d2 14787 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14788 if (et.size == 64)
14789 {
14790 /* .i64 is a pseudo-op, so the immediate must be a repeating
14791 pattern. */
4316f0d2
DG
14792 if (immbits != (inst.operands[immoperand].regisimm ?
14793 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14794 {
14795 /* Set immbits to an invalid constant. */
14796 immbits = 0xdeadbeef;
14797 }
14798 }
14799
5287ad62 14800 switch (opcode)
477330fc
RM
14801 {
14802 case N_MNEM_vbic:
14803 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14804 break;
14805
14806 case N_MNEM_vorr:
14807 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14808 break;
14809
14810 case N_MNEM_vand:
14811 /* Pseudo-instruction for VBIC. */
14812 neon_invert_size (&immbits, 0, et.size);
14813 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14814 break;
14815
14816 case N_MNEM_vorn:
14817 /* Pseudo-instruction for VORR. */
14818 neon_invert_size (&immbits, 0, et.size);
14819 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14820 break;
14821
14822 default:
14823 abort ();
14824 }
5287ad62
JB
14825
14826 if (cmode == FAIL)
477330fc 14827 return;
5287ad62 14828
037e8744 14829 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14830 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14832 inst.instruction |= cmode << 8;
14833 neon_write_immbits (immbits);
5f4273c7 14834
88714cb8 14835 neon_dp_fixup (&inst);
5287ad62
JB
14836 }
14837}
14838
14839static void
14840do_neon_bitfield (void)
14841{
037e8744 14842 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14843 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14844 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14845}
14846
14847static void
dcbf9037 14848neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14849 unsigned destbits)
5287ad62 14850{
037e8744 14851 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14852 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14853 types | N_KEY);
5287ad62
JB
14854 if (et.type == NT_float)
14855 {
88714cb8 14856 NEON_ENCODE (FLOAT, inst);
cc933301 14857 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14858 }
14859 else
14860 {
88714cb8 14861 NEON_ENCODE (INTEGER, inst);
037e8744 14862 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14863 }
14864}
14865
14866static void
14867do_neon_dyadic_if_su (void)
14868{
dcbf9037 14869 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14870}
14871
14872static void
14873do_neon_dyadic_if_su_d (void)
14874{
14875 /* This version only allow D registers, but that constraint is enforced during
14876 operand parsing so we don't need to do anything extra here. */
dcbf9037 14877 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14878}
14879
5287ad62
JB
14880static void
14881do_neon_dyadic_if_i_d (void)
14882{
428e3f1f
PB
14883 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14884 affected if we specify unsigned args. */
14885 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14886}
14887
037e8744
JB
14888enum vfp_or_neon_is_neon_bits
14889{
14890 NEON_CHECK_CC = 1,
73924fbc
MGD
14891 NEON_CHECK_ARCH = 2,
14892 NEON_CHECK_ARCH8 = 4
037e8744
JB
14893};
14894
14895/* Call this function if an instruction which may have belonged to the VFP or
14896 Neon instruction sets, but turned out to be a Neon instruction (due to the
14897 operand types involved, etc.). We have to check and/or fix-up a couple of
14898 things:
14899
14900 - Make sure the user hasn't attempted to make a Neon instruction
14901 conditional.
14902 - Alter the value in the condition code field if necessary.
14903 - Make sure that the arch supports Neon instructions.
14904
14905 Which of these operations take place depends on bits from enum
14906 vfp_or_neon_is_neon_bits.
14907
14908 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14909 current instruction's condition is COND_ALWAYS, the condition field is
14910 changed to inst.uncond_value. This is necessary because instructions shared
14911 between VFP and Neon may be conditional for the VFP variants only, and the
14912 unconditional Neon version must have, e.g., 0xF in the condition field. */
14913
14914static int
14915vfp_or_neon_is_neon (unsigned check)
14916{
14917 /* Conditions are always legal in Thumb mode (IT blocks). */
14918 if (!thumb_mode && (check & NEON_CHECK_CC))
14919 {
14920 if (inst.cond != COND_ALWAYS)
477330fc
RM
14921 {
14922 first_error (_(BAD_COND));
14923 return FAIL;
14924 }
037e8744 14925 if (inst.uncond_value != -1)
477330fc 14926 inst.instruction |= inst.uncond_value << 28;
037e8744 14927 }
5f4273c7 14928
037e8744 14929 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14930 && !mark_feature_used (&fpu_neon_ext_v1))
14931 {
14932 first_error (_(BAD_FPU));
14933 return FAIL;
14934 }
14935
14936 if ((check & NEON_CHECK_ARCH8)
14937 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14938 {
14939 first_error (_(BAD_FPU));
14940 return FAIL;
14941 }
5f4273c7 14942
037e8744
JB
14943 return SUCCESS;
14944}
14945
5287ad62
JB
14946static void
14947do_neon_addsub_if_i (void)
14948{
037e8744
JB
14949 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14950 return;
14951
14952 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14953 return;
14954
5287ad62
JB
14955 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14956 affected if we specify unsigned args. */
dcbf9037 14957 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14958}
14959
14960/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14961 result to be:
14962 V<op> A,B (A is operand 0, B is operand 2)
14963 to mean:
14964 V<op> A,B,A
14965 not:
14966 V<op> A,B,B
14967 so handle that case specially. */
14968
14969static void
14970neon_exchange_operands (void)
14971{
5287ad62
JB
14972 if (inst.operands[1].present)
14973 {
e1fa0163
NC
14974 void *scratch = xmalloc (sizeof (inst.operands[0]));
14975
5287ad62
JB
14976 /* Swap operands[1] and operands[2]. */
14977 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14978 inst.operands[1] = inst.operands[2];
14979 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14980 free (scratch);
5287ad62
JB
14981 }
14982 else
14983 {
14984 inst.operands[1] = inst.operands[2];
14985 inst.operands[2] = inst.operands[0];
14986 }
14987}
14988
14989static void
14990neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14991{
14992 if (inst.operands[2].isreg)
14993 {
14994 if (invert)
477330fc 14995 neon_exchange_operands ();
dcbf9037 14996 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14997 }
14998 else
14999 {
037e8744 15000 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15001 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15002 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15003
88714cb8 15004 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15005 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15006 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15007 inst.instruction |= LOW4 (inst.operands[1].reg);
15008 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15009 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15010 inst.instruction |= (et.type == NT_float) << 10;
15011 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15012
88714cb8 15013 neon_dp_fixup (&inst);
5287ad62
JB
15014 }
15015}
15016
15017static void
15018do_neon_cmp (void)
15019{
cc933301 15020 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15021}
15022
15023static void
15024do_neon_cmp_inv (void)
15025{
cc933301 15026 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15027}
15028
15029static void
15030do_neon_ceq (void)
15031{
15032 neon_compare (N_IF_32, N_IF_32, FALSE);
15033}
15034
15035/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15036 scalars, which are encoded in 5 bits, M : Rm.
15037 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15038 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15039 index in M. */
15040
15041static unsigned
15042neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15043{
dcbf9037
JB
15044 unsigned regno = NEON_SCALAR_REG (scalar);
15045 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15046
15047 switch (elsize)
15048 {
15049 case 16:
15050 if (regno > 7 || elno > 3)
477330fc 15051 goto bad_scalar;
5287ad62 15052 return regno | (elno << 3);
5f4273c7 15053
5287ad62
JB
15054 case 32:
15055 if (regno > 15 || elno > 1)
477330fc 15056 goto bad_scalar;
5287ad62
JB
15057 return regno | (elno << 4);
15058
15059 default:
15060 bad_scalar:
dcbf9037 15061 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15062 }
15063
15064 return 0;
15065}
15066
15067/* Encode multiply / multiply-accumulate scalar instructions. */
15068
15069static void
15070neon_mul_mac (struct neon_type_el et, int ubit)
15071{
dcbf9037
JB
15072 unsigned scalar;
15073
15074 /* Give a more helpful error message if we have an invalid type. */
15075 if (et.type == NT_invtype)
15076 return;
5f4273c7 15077
dcbf9037 15078 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15079 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15080 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15081 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15082 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15083 inst.instruction |= LOW4 (scalar);
15084 inst.instruction |= HI1 (scalar) << 5;
15085 inst.instruction |= (et.type == NT_float) << 8;
15086 inst.instruction |= neon_logbits (et.size) << 20;
15087 inst.instruction |= (ubit != 0) << 24;
15088
88714cb8 15089 neon_dp_fixup (&inst);
5287ad62
JB
15090}
15091
15092static void
15093do_neon_mac_maybe_scalar (void)
15094{
037e8744
JB
15095 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15096 return;
15097
15098 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15099 return;
15100
5287ad62
JB
15101 if (inst.operands[2].isscalar)
15102 {
037e8744 15103 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15104 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15105 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15106 NEON_ENCODE (SCALAR, inst);
037e8744 15107 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15108 }
15109 else
428e3f1f
PB
15110 {
15111 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15112 affected if we specify unsigned args. */
15113 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15114 }
5287ad62
JB
15115}
15116
62f3b8c8
PB
15117static void
15118do_neon_fmac (void)
15119{
15120 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15121 return;
15122
15123 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15124 return;
15125
15126 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15127}
15128
5287ad62
JB
15129static void
15130do_neon_tst (void)
15131{
037e8744 15132 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15133 struct neon_type_el et = neon_check_type (3, rs,
15134 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15135 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15136}
15137
15138/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15139 same types as the MAC equivalents. The polynomial type for this instruction
15140 is encoded the same as the integer type. */
15141
15142static void
15143do_neon_mul (void)
15144{
037e8744
JB
15145 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15146 return;
15147
15148 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15149 return;
15150
5287ad62
JB
15151 if (inst.operands[2].isscalar)
15152 do_neon_mac_maybe_scalar ();
15153 else
cc933301 15154 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15155}
15156
15157static void
15158do_neon_qdmulh (void)
15159{
15160 if (inst.operands[2].isscalar)
15161 {
037e8744 15162 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15163 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15164 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15165 NEON_ENCODE (SCALAR, inst);
037e8744 15166 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15167 }
15168 else
15169 {
037e8744 15170 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15171 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15172 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15173 NEON_ENCODE (INTEGER, inst);
5287ad62 15174 /* The U bit (rounding) comes from bit mask. */
037e8744 15175 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15176 }
15177}
15178
643afb90
MW
15179static void
15180do_neon_qrdmlah (void)
15181{
15182 /* Check we're on the correct architecture. */
15183 if (!mark_feature_used (&fpu_neon_ext_armv8))
15184 inst.error =
15185 _("instruction form not available on this architecture.");
15186 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15187 {
15188 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15189 record_feature_use (&fpu_neon_ext_v8_1);
15190 }
15191
15192 if (inst.operands[2].isscalar)
15193 {
15194 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15195 struct neon_type_el et = neon_check_type (3, rs,
15196 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15197 NEON_ENCODE (SCALAR, inst);
15198 neon_mul_mac (et, neon_quad (rs));
15199 }
15200 else
15201 {
15202 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15203 struct neon_type_el et = neon_check_type (3, rs,
15204 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15205 NEON_ENCODE (INTEGER, inst);
15206 /* The U bit (rounding) comes from bit mask. */
15207 neon_three_same (neon_quad (rs), 0, et.size);
15208 }
15209}
15210
5287ad62
JB
15211static void
15212do_neon_fcmp_absolute (void)
15213{
037e8744 15214 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15215 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15216 N_F_16_32 | N_KEY);
5287ad62 15217 /* Size field comes from bit mask. */
cc933301 15218 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15219}
15220
15221static void
15222do_neon_fcmp_absolute_inv (void)
15223{
15224 neon_exchange_operands ();
15225 do_neon_fcmp_absolute ();
15226}
15227
15228static void
15229do_neon_step (void)
15230{
037e8744 15231 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15232 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15233 N_F_16_32 | N_KEY);
15234 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15235}
15236
15237static void
15238do_neon_abs_neg (void)
15239{
037e8744
JB
15240 enum neon_shape rs;
15241 struct neon_type_el et;
5f4273c7 15242
037e8744
JB
15243 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15244 return;
15245
15246 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15247 return;
15248
15249 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15250 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15251
5287ad62
JB
15252 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15253 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15254 inst.instruction |= LOW4 (inst.operands[1].reg);
15255 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15256 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15257 inst.instruction |= (et.type == NT_float) << 10;
15258 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15259
88714cb8 15260 neon_dp_fixup (&inst);
5287ad62
JB
15261}
15262
15263static void
15264do_neon_sli (void)
15265{
037e8744 15266 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15267 struct neon_type_el et = neon_check_type (2, rs,
15268 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15269 int imm = inst.operands[2].imm;
15270 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15271 _("immediate out of range for insert"));
037e8744 15272 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15273}
15274
15275static void
15276do_neon_sri (void)
15277{
037e8744 15278 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15279 struct neon_type_el et = neon_check_type (2, rs,
15280 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15281 int imm = inst.operands[2].imm;
15282 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15283 _("immediate out of range for insert"));
037e8744 15284 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15285}
15286
15287static void
15288do_neon_qshlu_imm (void)
15289{
037e8744 15290 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15291 struct neon_type_el et = neon_check_type (2, rs,
15292 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15293 int imm = inst.operands[2].imm;
15294 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15295 _("immediate out of range for shift"));
5287ad62
JB
15296 /* Only encodes the 'U present' variant of the instruction.
15297 In this case, signed types have OP (bit 8) set to 0.
15298 Unsigned types have OP set to 1. */
15299 inst.instruction |= (et.type == NT_unsigned) << 8;
15300 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15301 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15302}
15303
15304static void
15305do_neon_qmovn (void)
15306{
15307 struct neon_type_el et = neon_check_type (2, NS_DQ,
15308 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15309 /* Saturating move where operands can be signed or unsigned, and the
15310 destination has the same signedness. */
88714cb8 15311 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15312 if (et.type == NT_unsigned)
15313 inst.instruction |= 0xc0;
15314 else
15315 inst.instruction |= 0x80;
15316 neon_two_same (0, 1, et.size / 2);
15317}
15318
15319static void
15320do_neon_qmovun (void)
15321{
15322 struct neon_type_el et = neon_check_type (2, NS_DQ,
15323 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15324 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15325 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15326 neon_two_same (0, 1, et.size / 2);
15327}
15328
15329static void
15330do_neon_rshift_sat_narrow (void)
15331{
15332 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15333 or unsigned. If operands are unsigned, results must also be unsigned. */
15334 struct neon_type_el et = neon_check_type (2, NS_DQI,
15335 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15336 int imm = inst.operands[2].imm;
15337 /* This gets the bounds check, size encoding and immediate bits calculation
15338 right. */
15339 et.size /= 2;
5f4273c7 15340
5287ad62
JB
15341 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15342 VQMOVN.I<size> <Dd>, <Qm>. */
15343 if (imm == 0)
15344 {
15345 inst.operands[2].present = 0;
15346 inst.instruction = N_MNEM_vqmovn;
15347 do_neon_qmovn ();
15348 return;
15349 }
5f4273c7 15350
5287ad62 15351 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15352 _("immediate out of range"));
5287ad62
JB
15353 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15354}
15355
15356static void
15357do_neon_rshift_sat_narrow_u (void)
15358{
15359 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15360 or unsigned. If operands are unsigned, results must also be unsigned. */
15361 struct neon_type_el et = neon_check_type (2, NS_DQI,
15362 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15363 int imm = inst.operands[2].imm;
15364 /* This gets the bounds check, size encoding and immediate bits calculation
15365 right. */
15366 et.size /= 2;
15367
15368 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15369 VQMOVUN.I<size> <Dd>, <Qm>. */
15370 if (imm == 0)
15371 {
15372 inst.operands[2].present = 0;
15373 inst.instruction = N_MNEM_vqmovun;
15374 do_neon_qmovun ();
15375 return;
15376 }
15377
15378 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15379 _("immediate out of range"));
5287ad62
JB
15380 /* FIXME: The manual is kind of unclear about what value U should have in
15381 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15382 must be 1. */
15383 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15384}
15385
15386static void
15387do_neon_movn (void)
15388{
15389 struct neon_type_el et = neon_check_type (2, NS_DQ,
15390 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15391 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15392 neon_two_same (0, 1, et.size / 2);
15393}
15394
15395static void
15396do_neon_rshift_narrow (void)
15397{
15398 struct neon_type_el et = neon_check_type (2, NS_DQI,
15399 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15400 int imm = inst.operands[2].imm;
15401 /* This gets the bounds check, size encoding and immediate bits calculation
15402 right. */
15403 et.size /= 2;
5f4273c7 15404
5287ad62
JB
15405 /* If immediate is zero then we are a pseudo-instruction for
15406 VMOVN.I<size> <Dd>, <Qm> */
15407 if (imm == 0)
15408 {
15409 inst.operands[2].present = 0;
15410 inst.instruction = N_MNEM_vmovn;
15411 do_neon_movn ();
15412 return;
15413 }
5f4273c7 15414
5287ad62 15415 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15416 _("immediate out of range for narrowing operation"));
5287ad62
JB
15417 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15418}
15419
15420static void
15421do_neon_shll (void)
15422{
15423 /* FIXME: Type checking when lengthening. */
15424 struct neon_type_el et = neon_check_type (2, NS_QDI,
15425 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15426 unsigned imm = inst.operands[2].imm;
15427
15428 if (imm == et.size)
15429 {
15430 /* Maximum shift variant. */
88714cb8 15431 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15432 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15433 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15434 inst.instruction |= LOW4 (inst.operands[1].reg);
15435 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15436 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15437
88714cb8 15438 neon_dp_fixup (&inst);
5287ad62
JB
15439 }
15440 else
15441 {
15442 /* A more-specific type check for non-max versions. */
15443 et = neon_check_type (2, NS_QDI,
477330fc 15444 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15445 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15446 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15447 }
15448}
15449
037e8744 15450/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15451 the current instruction is. */
15452
6b9a8b67
MGD
15453#define CVT_FLAVOUR_VAR \
15454 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15455 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15456 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15457 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15458 /* Half-precision conversions. */ \
cc933301
JW
15459 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15460 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15461 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15462 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15463 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15464 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15465 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15466 Compared with single/double precision variants, only the co-processor \
15467 field is different, so the encoding flow is reused here. */ \
15468 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15469 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15470 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15471 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15472 /* VFP instructions. */ \
15473 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15474 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15475 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15476 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15477 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15478 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15479 /* VFP instructions with bitshift. */ \
15480 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15481 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15482 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15483 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15484 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15485 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15486 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15487 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15488
15489#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15490 neon_cvt_flavour_##C,
15491
15492/* The different types of conversions we can do. */
15493enum neon_cvt_flavour
15494{
15495 CVT_FLAVOUR_VAR
15496 neon_cvt_flavour_invalid,
15497 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15498};
15499
15500#undef CVT_VAR
15501
15502static enum neon_cvt_flavour
15503get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15504{
6b9a8b67
MGD
15505#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15506 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15507 if (et.type != NT_invtype) \
15508 { \
15509 inst.error = NULL; \
15510 return (neon_cvt_flavour_##C); \
5287ad62 15511 }
6b9a8b67 15512
5287ad62 15513 struct neon_type_el et;
037e8744 15514 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15515 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15516 /* The instruction versions which take an immediate take one register
15517 argument, which is extended to the width of the full register. Thus the
15518 "source" and "destination" registers must have the same width. Hack that
15519 here by making the size equal to the key (wider, in this case) operand. */
15520 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15521
6b9a8b67
MGD
15522 CVT_FLAVOUR_VAR;
15523
15524 return neon_cvt_flavour_invalid;
5287ad62
JB
15525#undef CVT_VAR
15526}
15527
7e8e6784
MGD
15528enum neon_cvt_mode
15529{
15530 neon_cvt_mode_a,
15531 neon_cvt_mode_n,
15532 neon_cvt_mode_p,
15533 neon_cvt_mode_m,
15534 neon_cvt_mode_z,
30bdf752
MGD
15535 neon_cvt_mode_x,
15536 neon_cvt_mode_r
7e8e6784
MGD
15537};
15538
037e8744
JB
15539/* Neon-syntax VFP conversions. */
15540
5287ad62 15541static void
6b9a8b67 15542do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15543{
037e8744 15544 const char *opname = 0;
5f4273c7 15545
d54af2d0
RL
15546 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15547 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15548 {
037e8744
JB
15549 /* Conversions with immediate bitshift. */
15550 const char *enc[] =
477330fc 15551 {
6b9a8b67
MGD
15552#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15553 CVT_FLAVOUR_VAR
15554 NULL
15555#undef CVT_VAR
477330fc 15556 };
037e8744 15557
6b9a8b67 15558 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15559 {
15560 opname = enc[flavour];
15561 constraint (inst.operands[0].reg != inst.operands[1].reg,
15562 _("operands 0 and 1 must be the same register"));
15563 inst.operands[1] = inst.operands[2];
15564 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15565 }
5287ad62
JB
15566 }
15567 else
15568 {
037e8744
JB
15569 /* Conversions without bitshift. */
15570 const char *enc[] =
477330fc 15571 {
6b9a8b67
MGD
15572#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15573 CVT_FLAVOUR_VAR
15574 NULL
15575#undef CVT_VAR
477330fc 15576 };
037e8744 15577
6b9a8b67 15578 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15579 opname = enc[flavour];
037e8744
JB
15580 }
15581
15582 if (opname)
15583 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15584
15585 /* ARMv8.2 fp16 VCVT instruction. */
15586 if (flavour == neon_cvt_flavour_s32_f16
15587 || flavour == neon_cvt_flavour_u32_f16
15588 || flavour == neon_cvt_flavour_f16_u32
15589 || flavour == neon_cvt_flavour_f16_s32)
15590 do_scalar_fp16_v82_encode ();
037e8744
JB
15591}
15592
15593static void
15594do_vfp_nsyn_cvtz (void)
15595{
d54af2d0 15596 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15597 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15598 const char *enc[] =
15599 {
6b9a8b67
MGD
15600#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15601 CVT_FLAVOUR_VAR
15602 NULL
15603#undef CVT_VAR
037e8744
JB
15604 };
15605
6b9a8b67 15606 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15607 do_vfp_nsyn_opcode (enc[flavour]);
15608}
f31fef98 15609
037e8744 15610static void
bacebabc 15611do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15612 enum neon_cvt_mode mode)
15613{
15614 int sz, op;
15615 int rm;
15616
a715796b
TG
15617 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15618 D register operands. */
15619 if (flavour == neon_cvt_flavour_s32_f64
15620 || flavour == neon_cvt_flavour_u32_f64)
15621 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15622 _(BAD_FPU));
15623
9db2f6b4
RL
15624 if (flavour == neon_cvt_flavour_s32_f16
15625 || flavour == neon_cvt_flavour_u32_f16)
15626 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15627 _(BAD_FP16));
15628
7e8e6784
MGD
15629 set_it_insn_type (OUTSIDE_IT_INSN);
15630
15631 switch (flavour)
15632 {
15633 case neon_cvt_flavour_s32_f64:
15634 sz = 1;
827f64ff 15635 op = 1;
7e8e6784
MGD
15636 break;
15637 case neon_cvt_flavour_s32_f32:
15638 sz = 0;
15639 op = 1;
15640 break;
9db2f6b4
RL
15641 case neon_cvt_flavour_s32_f16:
15642 sz = 0;
15643 op = 1;
15644 break;
7e8e6784
MGD
15645 case neon_cvt_flavour_u32_f64:
15646 sz = 1;
15647 op = 0;
15648 break;
15649 case neon_cvt_flavour_u32_f32:
15650 sz = 0;
15651 op = 0;
15652 break;
9db2f6b4
RL
15653 case neon_cvt_flavour_u32_f16:
15654 sz = 0;
15655 op = 0;
15656 break;
7e8e6784
MGD
15657 default:
15658 first_error (_("invalid instruction shape"));
15659 return;
15660 }
15661
15662 switch (mode)
15663 {
15664 case neon_cvt_mode_a: rm = 0; break;
15665 case neon_cvt_mode_n: rm = 1; break;
15666 case neon_cvt_mode_p: rm = 2; break;
15667 case neon_cvt_mode_m: rm = 3; break;
15668 default: first_error (_("invalid rounding mode")); return;
15669 }
15670
15671 NEON_ENCODE (FPV8, inst);
15672 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15673 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15674 inst.instruction |= sz << 8;
9db2f6b4
RL
15675
15676 /* ARMv8.2 fp16 VCVT instruction. */
15677 if (flavour == neon_cvt_flavour_s32_f16
15678 ||flavour == neon_cvt_flavour_u32_f16)
15679 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15680 inst.instruction |= op << 7;
15681 inst.instruction |= rm << 16;
15682 inst.instruction |= 0xf0000000;
15683 inst.is_neon = TRUE;
15684}
15685
15686static void
15687do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15688{
15689 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15690 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15691 NS_FH, NS_HF, NS_FHI, NS_HFI,
15692 NS_NULL);
6b9a8b67 15693 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15694
cc933301
JW
15695 if (flavour == neon_cvt_flavour_invalid)
15696 return;
15697
e3e535bc 15698 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15699 if (mode == neon_cvt_mode_z
e3e535bc 15700 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15701 && (flavour == neon_cvt_flavour_s16_f16
15702 || flavour == neon_cvt_flavour_u16_f16
15703 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15704 || flavour == neon_cvt_flavour_u32_f32
15705 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15706 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15707 && (rs == NS_FD || rs == NS_FF))
15708 {
15709 do_vfp_nsyn_cvtz ();
15710 return;
15711 }
15712
9db2f6b4
RL
15713 /* ARMv8.2 fp16 VCVT conversions. */
15714 if (mode == neon_cvt_mode_z
15715 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15716 && (flavour == neon_cvt_flavour_s32_f16
15717 || flavour == neon_cvt_flavour_u32_f16)
15718 && (rs == NS_FH))
15719 {
15720 do_vfp_nsyn_cvtz ();
15721 do_scalar_fp16_v82_encode ();
15722 return;
15723 }
15724
037e8744 15725 /* VFP rather than Neon conversions. */
6b9a8b67 15726 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15727 {
7e8e6784
MGD
15728 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15729 do_vfp_nsyn_cvt (rs, flavour);
15730 else
15731 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15732
037e8744
JB
15733 return;
15734 }
15735
15736 switch (rs)
15737 {
15738 case NS_DDI:
15739 case NS_QQI:
15740 {
477330fc 15741 unsigned immbits;
cc933301
JW
15742 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15743 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15744
477330fc
RM
15745 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15746 return;
037e8744 15747
477330fc
RM
15748 /* Fixed-point conversion with #0 immediate is encoded as an
15749 integer conversion. */
15750 if (inst.operands[2].present && inst.operands[2].imm == 0)
15751 goto int_encode;
477330fc
RM
15752 NEON_ENCODE (IMMED, inst);
15753 if (flavour != neon_cvt_flavour_invalid)
15754 inst.instruction |= enctab[flavour];
15755 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15756 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15757 inst.instruction |= LOW4 (inst.operands[1].reg);
15758 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15759 inst.instruction |= neon_quad (rs) << 6;
15760 inst.instruction |= 1 << 21;
cc933301
JW
15761 if (flavour < neon_cvt_flavour_s16_f16)
15762 {
15763 inst.instruction |= 1 << 21;
15764 immbits = 32 - inst.operands[2].imm;
15765 inst.instruction |= immbits << 16;
15766 }
15767 else
15768 {
15769 inst.instruction |= 3 << 20;
15770 immbits = 16 - inst.operands[2].imm;
15771 inst.instruction |= immbits << 16;
15772 inst.instruction &= ~(1 << 9);
15773 }
477330fc
RM
15774
15775 neon_dp_fixup (&inst);
037e8744
JB
15776 }
15777 break;
15778
15779 case NS_DD:
15780 case NS_QQ:
7e8e6784
MGD
15781 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15782 {
15783 NEON_ENCODE (FLOAT, inst);
15784 set_it_insn_type (OUTSIDE_IT_INSN);
15785
15786 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15787 return;
15788
15789 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15790 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15791 inst.instruction |= LOW4 (inst.operands[1].reg);
15792 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15793 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15794 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15795 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15796 inst.instruction |= mode << 8;
cc933301
JW
15797 if (flavour == neon_cvt_flavour_u16_f16
15798 || flavour == neon_cvt_flavour_s16_f16)
15799 /* Mask off the original size bits and reencode them. */
15800 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15801
7e8e6784
MGD
15802 if (thumb_mode)
15803 inst.instruction |= 0xfc000000;
15804 else
15805 inst.instruction |= 0xf0000000;
15806 }
15807 else
15808 {
037e8744 15809 int_encode:
7e8e6784 15810 {
cc933301
JW
15811 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15812 0x100, 0x180, 0x0, 0x080};
037e8744 15813
7e8e6784 15814 NEON_ENCODE (INTEGER, inst);
037e8744 15815
7e8e6784
MGD
15816 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15817 return;
037e8744 15818
7e8e6784
MGD
15819 if (flavour != neon_cvt_flavour_invalid)
15820 inst.instruction |= enctab[flavour];
037e8744 15821
7e8e6784
MGD
15822 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15823 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15824 inst.instruction |= LOW4 (inst.operands[1].reg);
15825 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15826 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15827 if (flavour >= neon_cvt_flavour_s16_f16
15828 && flavour <= neon_cvt_flavour_f16_u16)
15829 /* Half precision. */
15830 inst.instruction |= 1 << 18;
15831 else
15832 inst.instruction |= 2 << 18;
037e8744 15833
7e8e6784
MGD
15834 neon_dp_fixup (&inst);
15835 }
15836 }
15837 break;
037e8744 15838
8e79c3df
CM
15839 /* Half-precision conversions for Advanced SIMD -- neon. */
15840 case NS_QD:
15841 case NS_DQ:
15842
15843 if ((rs == NS_DQ)
15844 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15845 {
15846 as_bad (_("operand size must match register width"));
15847 break;
15848 }
15849
15850 if ((rs == NS_QD)
15851 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15852 {
15853 as_bad (_("operand size must match register width"));
15854 break;
15855 }
15856
15857 if (rs == NS_DQ)
477330fc 15858 inst.instruction = 0x3b60600;
8e79c3df
CM
15859 else
15860 inst.instruction = 0x3b60700;
15861
15862 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15863 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15864 inst.instruction |= LOW4 (inst.operands[1].reg);
15865 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15866 neon_dp_fixup (&inst);
8e79c3df
CM
15867 break;
15868
037e8744
JB
15869 default:
15870 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15871 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15872 do_vfp_nsyn_cvt (rs, flavour);
15873 else
15874 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15875 }
5287ad62
JB
15876}
15877
e3e535bc
NC
15878static void
15879do_neon_cvtr (void)
15880{
7e8e6784 15881 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15882}
15883
15884static void
15885do_neon_cvt (void)
15886{
7e8e6784
MGD
15887 do_neon_cvt_1 (neon_cvt_mode_z);
15888}
15889
15890static void
15891do_neon_cvta (void)
15892{
15893 do_neon_cvt_1 (neon_cvt_mode_a);
15894}
15895
15896static void
15897do_neon_cvtn (void)
15898{
15899 do_neon_cvt_1 (neon_cvt_mode_n);
15900}
15901
15902static void
15903do_neon_cvtp (void)
15904{
15905 do_neon_cvt_1 (neon_cvt_mode_p);
15906}
15907
15908static void
15909do_neon_cvtm (void)
15910{
15911 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15912}
15913
8e79c3df 15914static void
c70a8987 15915do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15916{
c70a8987
MGD
15917 if (is_double)
15918 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15919
c70a8987
MGD
15920 encode_arm_vfp_reg (inst.operands[0].reg,
15921 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15922 encode_arm_vfp_reg (inst.operands[1].reg,
15923 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15924 inst.instruction |= to ? 0x10000 : 0;
15925 inst.instruction |= t ? 0x80 : 0;
15926 inst.instruction |= is_double ? 0x100 : 0;
15927 do_vfp_cond_or_thumb ();
15928}
8e79c3df 15929
c70a8987
MGD
15930static void
15931do_neon_cvttb_1 (bfd_boolean t)
15932{
d54af2d0
RL
15933 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15934 NS_DF, NS_DH, NS_NULL);
8e79c3df 15935
c70a8987
MGD
15936 if (rs == NS_NULL)
15937 return;
15938 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15939 {
15940 inst.error = NULL;
15941 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15942 }
15943 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15944 {
15945 inst.error = NULL;
15946 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15947 }
15948 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15949 {
a715796b
TG
15950 /* The VCVTB and VCVTT instructions with D-register operands
15951 don't work for SP only targets. */
15952 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15953 _(BAD_FPU));
15954
c70a8987
MGD
15955 inst.error = NULL;
15956 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15957 }
15958 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15959 {
a715796b
TG
15960 /* The VCVTB and VCVTT instructions with D-register operands
15961 don't work for SP only targets. */
15962 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15963 _(BAD_FPU));
15964
c70a8987
MGD
15965 inst.error = NULL;
15966 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15967 }
15968 else
15969 return;
15970}
15971
15972static void
15973do_neon_cvtb (void)
15974{
15975 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15976}
15977
15978
15979static void
15980do_neon_cvtt (void)
15981{
c70a8987 15982 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15983}
15984
5287ad62
JB
15985static void
15986neon_move_immediate (void)
15987{
037e8744
JB
15988 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15989 struct neon_type_el et = neon_check_type (2, rs,
15990 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15991 unsigned immlo, immhi = 0, immbits;
c96612cc 15992 int op, cmode, float_p;
5287ad62 15993
037e8744 15994 constraint (et.type == NT_invtype,
477330fc 15995 _("operand size must be specified for immediate VMOV"));
037e8744 15996
5287ad62
JB
15997 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15998 op = (inst.instruction & (1 << 5)) != 0;
15999
16000 immlo = inst.operands[1].imm;
16001 if (inst.operands[1].regisimm)
16002 immhi = inst.operands[1].reg;
16003
16004 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16005 _("immediate has bits set outside the operand size"));
5287ad62 16006
c96612cc
JB
16007 float_p = inst.operands[1].immisfloat;
16008
16009 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16010 et.size, et.type)) == FAIL)
5287ad62
JB
16011 {
16012 /* Invert relevant bits only. */
16013 neon_invert_size (&immlo, &immhi, et.size);
16014 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16015 with one or the other; those cases are caught by
16016 neon_cmode_for_move_imm. */
5287ad62 16017 op = !op;
c96612cc
JB
16018 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16019 &op, et.size, et.type)) == FAIL)
477330fc
RM
16020 {
16021 first_error (_("immediate out of range"));
16022 return;
16023 }
5287ad62
JB
16024 }
16025
16026 inst.instruction &= ~(1 << 5);
16027 inst.instruction |= op << 5;
16028
16029 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16030 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16031 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16032 inst.instruction |= cmode << 8;
16033
16034 neon_write_immbits (immbits);
16035}
16036
16037static void
16038do_neon_mvn (void)
16039{
16040 if (inst.operands[1].isreg)
16041 {
037e8744 16042 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16043
88714cb8 16044 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16045 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16046 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16047 inst.instruction |= LOW4 (inst.operands[1].reg);
16048 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16049 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16050 }
16051 else
16052 {
88714cb8 16053 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16054 neon_move_immediate ();
16055 }
16056
88714cb8 16057 neon_dp_fixup (&inst);
5287ad62
JB
16058}
16059
16060/* Encode instructions of form:
16061
16062 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16063 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16064
16065static void
16066neon_mixed_length (struct neon_type_el et, unsigned size)
16067{
16068 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16069 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16070 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16071 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16072 inst.instruction |= LOW4 (inst.operands[2].reg);
16073 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16074 inst.instruction |= (et.type == NT_unsigned) << 24;
16075 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16076
88714cb8 16077 neon_dp_fixup (&inst);
5287ad62
JB
16078}
16079
16080static void
16081do_neon_dyadic_long (void)
16082{
16083 /* FIXME: Type checking for lengthening op. */
16084 struct neon_type_el et = neon_check_type (3, NS_QDD,
16085 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16086 neon_mixed_length (et, et.size);
16087}
16088
16089static void
16090do_neon_abal (void)
16091{
16092 struct neon_type_el et = neon_check_type (3, NS_QDD,
16093 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16094 neon_mixed_length (et, et.size);
16095}
16096
16097static void
16098neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16099{
16100 if (inst.operands[2].isscalar)
16101 {
dcbf9037 16102 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16103 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16104 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16105 neon_mul_mac (et, et.type == NT_unsigned);
16106 }
16107 else
16108 {
16109 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16110 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16111 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16112 neon_mixed_length (et, et.size);
16113 }
16114}
16115
16116static void
16117do_neon_mac_maybe_scalar_long (void)
16118{
16119 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16120}
16121
16122static void
16123do_neon_dyadic_wide (void)
16124{
16125 struct neon_type_el et = neon_check_type (3, NS_QQD,
16126 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16127 neon_mixed_length (et, et.size);
16128}
16129
16130static void
16131do_neon_dyadic_narrow (void)
16132{
16133 struct neon_type_el et = neon_check_type (3, NS_QDD,
16134 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16135 /* Operand sign is unimportant, and the U bit is part of the opcode,
16136 so force the operand type to integer. */
16137 et.type = NT_integer;
5287ad62
JB
16138 neon_mixed_length (et, et.size / 2);
16139}
16140
16141static void
16142do_neon_mul_sat_scalar_long (void)
16143{
16144 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16145}
16146
16147static void
16148do_neon_vmull (void)
16149{
16150 if (inst.operands[2].isscalar)
16151 do_neon_mac_maybe_scalar_long ();
16152 else
16153 {
16154 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16155 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16156
5287ad62 16157 if (et.type == NT_poly)
477330fc 16158 NEON_ENCODE (POLY, inst);
5287ad62 16159 else
477330fc 16160 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16161
16162 /* For polynomial encoding the U bit must be zero, and the size must
16163 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16164 obviously, as 0b10). */
16165 if (et.size == 64)
16166 {
16167 /* Check we're on the correct architecture. */
16168 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16169 inst.error =
16170 _("Instruction form not available on this architecture.");
16171
16172 et.size = 32;
16173 }
16174
5287ad62
JB
16175 neon_mixed_length (et, et.size);
16176 }
16177}
16178
16179static void
16180do_neon_ext (void)
16181{
037e8744 16182 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16183 struct neon_type_el et = neon_check_type (3, rs,
16184 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16185 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16186
16187 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16188 _("shift out of range"));
5287ad62
JB
16189 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16190 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16191 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16192 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16193 inst.instruction |= LOW4 (inst.operands[2].reg);
16194 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16195 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16196 inst.instruction |= imm << 8;
5f4273c7 16197
88714cb8 16198 neon_dp_fixup (&inst);
5287ad62
JB
16199}
16200
16201static void
16202do_neon_rev (void)
16203{
037e8744 16204 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16205 struct neon_type_el et = neon_check_type (2, rs,
16206 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16207 unsigned op = (inst.instruction >> 7) & 3;
16208 /* N (width of reversed regions) is encoded as part of the bitmask. We
16209 extract it here to check the elements to be reversed are smaller.
16210 Otherwise we'd get a reserved instruction. */
16211 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16212 gas_assert (elsize != 0);
5287ad62 16213 constraint (et.size >= elsize,
477330fc 16214 _("elements must be smaller than reversal region"));
037e8744 16215 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16216}
16217
16218static void
16219do_neon_dup (void)
16220{
16221 if (inst.operands[1].isscalar)
16222 {
037e8744 16223 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16224 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16225 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16226 unsigned sizebits = et.size >> 3;
dcbf9037 16227 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16228 int logsize = neon_logbits (et.size);
dcbf9037 16229 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16230
16231 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16232 return;
037e8744 16233
88714cb8 16234 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16235 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16237 inst.instruction |= LOW4 (dm);
16238 inst.instruction |= HI1 (dm) << 5;
037e8744 16239 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16240 inst.instruction |= x << 17;
16241 inst.instruction |= sizebits << 16;
5f4273c7 16242
88714cb8 16243 neon_dp_fixup (&inst);
5287ad62
JB
16244 }
16245 else
16246 {
037e8744
JB
16247 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16248 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16249 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16250 /* Duplicate ARM register to lanes of vector. */
88714cb8 16251 NEON_ENCODE (ARMREG, inst);
5287ad62 16252 switch (et.size)
477330fc
RM
16253 {
16254 case 8: inst.instruction |= 0x400000; break;
16255 case 16: inst.instruction |= 0x000020; break;
16256 case 32: inst.instruction |= 0x000000; break;
16257 default: break;
16258 }
5287ad62
JB
16259 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16260 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16261 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16262 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16263 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16264 variants, except for the condition field. */
037e8744 16265 do_vfp_cond_or_thumb ();
5287ad62
JB
16266 }
16267}
16268
16269/* VMOV has particularly many variations. It can be one of:
16270 0. VMOV<c><q> <Qd>, <Qm>
16271 1. VMOV<c><q> <Dd>, <Dm>
16272 (Register operations, which are VORR with Rm = Rn.)
16273 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16274 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16275 (Immediate loads.)
16276 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16277 (ARM register to scalar.)
16278 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16279 (Two ARM registers to vector.)
16280 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16281 (Scalar to ARM register.)
16282 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16283 (Vector to two ARM registers.)
037e8744
JB
16284 8. VMOV.F32 <Sd>, <Sm>
16285 9. VMOV.F64 <Dd>, <Dm>
16286 (VFP register moves.)
16287 10. VMOV.F32 <Sd>, #imm
16288 11. VMOV.F64 <Dd>, #imm
16289 (VFP float immediate load.)
16290 12. VMOV <Rd>, <Sm>
16291 (VFP single to ARM reg.)
16292 13. VMOV <Sd>, <Rm>
16293 (ARM reg to VFP single.)
16294 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16295 (Two ARM regs to two VFP singles.)
16296 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16297 (Two VFP singles to two ARM regs.)
5f4273c7 16298
037e8744
JB
16299 These cases can be disambiguated using neon_select_shape, except cases 1/9
16300 and 3/11 which depend on the operand type too.
5f4273c7 16301
5287ad62 16302 All the encoded bits are hardcoded by this function.
5f4273c7 16303
b7fc2769
JB
16304 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16305 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16306
5287ad62 16307 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16308 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16309
16310static void
16311do_neon_mov (void)
16312{
037e8744 16313 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16314 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16315 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16316 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16317 struct neon_type_el et;
16318 const char *ldconst = 0;
5287ad62 16319
037e8744 16320 switch (rs)
5287ad62 16321 {
037e8744
JB
16322 case NS_DD: /* case 1/9. */
16323 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16324 /* It is not an error here if no type is given. */
16325 inst.error = NULL;
16326 if (et.type == NT_float && et.size == 64)
477330fc
RM
16327 {
16328 do_vfp_nsyn_opcode ("fcpyd");
16329 break;
16330 }
037e8744 16331 /* fall through. */
5287ad62 16332
037e8744
JB
16333 case NS_QQ: /* case 0/1. */
16334 {
477330fc
RM
16335 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16336 return;
16337 /* The architecture manual I have doesn't explicitly state which
16338 value the U bit should have for register->register moves, but
16339 the equivalent VORR instruction has U = 0, so do that. */
16340 inst.instruction = 0x0200110;
16341 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16342 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16343 inst.instruction |= LOW4 (inst.operands[1].reg);
16344 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16345 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16346 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16347 inst.instruction |= neon_quad (rs) << 6;
16348
16349 neon_dp_fixup (&inst);
037e8744
JB
16350 }
16351 break;
5f4273c7 16352
037e8744
JB
16353 case NS_DI: /* case 3/11. */
16354 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16355 inst.error = NULL;
16356 if (et.type == NT_float && et.size == 64)
477330fc
RM
16357 {
16358 /* case 11 (fconstd). */
16359 ldconst = "fconstd";
16360 goto encode_fconstd;
16361 }
037e8744
JB
16362 /* fall through. */
16363
16364 case NS_QI: /* case 2/3. */
16365 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16366 return;
037e8744
JB
16367 inst.instruction = 0x0800010;
16368 neon_move_immediate ();
88714cb8 16369 neon_dp_fixup (&inst);
5287ad62 16370 break;
5f4273c7 16371
037e8744
JB
16372 case NS_SR: /* case 4. */
16373 {
477330fc
RM
16374 unsigned bcdebits = 0;
16375 int logsize;
16376 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16377 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16378
05ac0ffb
JB
16379 /* .<size> is optional here, defaulting to .32. */
16380 if (inst.vectype.elems == 0
16381 && inst.operands[0].vectype.type == NT_invtype
16382 && inst.operands[1].vectype.type == NT_invtype)
16383 {
16384 inst.vectype.el[0].type = NT_untyped;
16385 inst.vectype.el[0].size = 32;
16386 inst.vectype.elems = 1;
16387 }
16388
477330fc
RM
16389 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16390 logsize = neon_logbits (et.size);
16391
16392 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16393 _(BAD_FPU));
16394 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16395 && et.size != 32, _(BAD_FPU));
16396 constraint (et.type == NT_invtype, _("bad type for scalar"));
16397 constraint (x >= 64 / et.size, _("scalar index out of range"));
16398
16399 switch (et.size)
16400 {
16401 case 8: bcdebits = 0x8; break;
16402 case 16: bcdebits = 0x1; break;
16403 case 32: bcdebits = 0x0; break;
16404 default: ;
16405 }
16406
16407 bcdebits |= x << logsize;
16408
16409 inst.instruction = 0xe000b10;
16410 do_vfp_cond_or_thumb ();
16411 inst.instruction |= LOW4 (dn) << 16;
16412 inst.instruction |= HI1 (dn) << 7;
16413 inst.instruction |= inst.operands[1].reg << 12;
16414 inst.instruction |= (bcdebits & 3) << 5;
16415 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16416 }
16417 break;
5f4273c7 16418
037e8744 16419 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16420 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16421 _(BAD_FPU));
b7fc2769 16422
037e8744
JB
16423 inst.instruction = 0xc400b10;
16424 do_vfp_cond_or_thumb ();
16425 inst.instruction |= LOW4 (inst.operands[0].reg);
16426 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16427 inst.instruction |= inst.operands[1].reg << 12;
16428 inst.instruction |= inst.operands[2].reg << 16;
16429 break;
5f4273c7 16430
037e8744
JB
16431 case NS_RS: /* case 6. */
16432 {
477330fc
RM
16433 unsigned logsize;
16434 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16435 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16436 unsigned abcdebits = 0;
037e8744 16437
05ac0ffb
JB
16438 /* .<dt> is optional here, defaulting to .32. */
16439 if (inst.vectype.elems == 0
16440 && inst.operands[0].vectype.type == NT_invtype
16441 && inst.operands[1].vectype.type == NT_invtype)
16442 {
16443 inst.vectype.el[0].type = NT_untyped;
16444 inst.vectype.el[0].size = 32;
16445 inst.vectype.elems = 1;
16446 }
16447
91d6fa6a
NC
16448 et = neon_check_type (2, NS_NULL,
16449 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16450 logsize = neon_logbits (et.size);
16451
16452 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16453 _(BAD_FPU));
16454 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16455 && et.size != 32, _(BAD_FPU));
16456 constraint (et.type == NT_invtype, _("bad type for scalar"));
16457 constraint (x >= 64 / et.size, _("scalar index out of range"));
16458
16459 switch (et.size)
16460 {
16461 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16462 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16463 case 32: abcdebits = 0x00; break;
16464 default: ;
16465 }
16466
16467 abcdebits |= x << logsize;
16468 inst.instruction = 0xe100b10;
16469 do_vfp_cond_or_thumb ();
16470 inst.instruction |= LOW4 (dn) << 16;
16471 inst.instruction |= HI1 (dn) << 7;
16472 inst.instruction |= inst.operands[0].reg << 12;
16473 inst.instruction |= (abcdebits & 3) << 5;
16474 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16475 }
16476 break;
5f4273c7 16477
037e8744
JB
16478 case NS_RRD: /* case 7 (fmrrd). */
16479 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16480 _(BAD_FPU));
037e8744
JB
16481
16482 inst.instruction = 0xc500b10;
16483 do_vfp_cond_or_thumb ();
16484 inst.instruction |= inst.operands[0].reg << 12;
16485 inst.instruction |= inst.operands[1].reg << 16;
16486 inst.instruction |= LOW4 (inst.operands[2].reg);
16487 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16488 break;
5f4273c7 16489
037e8744
JB
16490 case NS_FF: /* case 8 (fcpys). */
16491 do_vfp_nsyn_opcode ("fcpys");
16492 break;
5f4273c7 16493
9db2f6b4 16494 case NS_HI:
037e8744
JB
16495 case NS_FI: /* case 10 (fconsts). */
16496 ldconst = "fconsts";
16497 encode_fconstd:
16498 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16499 {
16500 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16501 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16502
16503 /* ARMv8.2 fp16 vmov.f16 instruction. */
16504 if (rs == NS_HI)
16505 do_scalar_fp16_v82_encode ();
477330fc 16506 }
5287ad62 16507 else
477330fc 16508 first_error (_("immediate out of range"));
037e8744 16509 break;
5f4273c7 16510
9db2f6b4 16511 case NS_RH:
037e8744
JB
16512 case NS_RF: /* case 12 (fmrs). */
16513 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16514 /* ARMv8.2 fp16 vmov.f16 instruction. */
16515 if (rs == NS_RH)
16516 do_scalar_fp16_v82_encode ();
037e8744 16517 break;
5f4273c7 16518
9db2f6b4 16519 case NS_HR:
037e8744
JB
16520 case NS_FR: /* case 13 (fmsr). */
16521 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16522 /* ARMv8.2 fp16 vmov.f16 instruction. */
16523 if (rs == NS_HR)
16524 do_scalar_fp16_v82_encode ();
037e8744 16525 break;
5f4273c7 16526
037e8744
JB
16527 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16528 (one of which is a list), but we have parsed four. Do some fiddling to
16529 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16530 expect. */
16531 case NS_RRFF: /* case 14 (fmrrs). */
16532 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16533 _("VFP registers must be adjacent"));
037e8744
JB
16534 inst.operands[2].imm = 2;
16535 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16536 do_vfp_nsyn_opcode ("fmrrs");
16537 break;
5f4273c7 16538
037e8744
JB
16539 case NS_FFRR: /* case 15 (fmsrr). */
16540 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16541 _("VFP registers must be adjacent"));
037e8744
JB
16542 inst.operands[1] = inst.operands[2];
16543 inst.operands[2] = inst.operands[3];
16544 inst.operands[0].imm = 2;
16545 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16546 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16547 break;
5f4273c7 16548
4c261dff
NC
16549 case NS_NULL:
16550 /* neon_select_shape has determined that the instruction
16551 shape is wrong and has already set the error message. */
16552 break;
16553
5287ad62
JB
16554 default:
16555 abort ();
16556 }
16557}
16558
16559static void
16560do_neon_rshift_round_imm (void)
16561{
037e8744 16562 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16563 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16564 int imm = inst.operands[2].imm;
16565
16566 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16567 if (imm == 0)
16568 {
16569 inst.operands[2].present = 0;
16570 do_neon_mov ();
16571 return;
16572 }
16573
16574 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16575 _("immediate out of range for shift"));
037e8744 16576 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16577 et.size - imm);
5287ad62
JB
16578}
16579
9db2f6b4
RL
16580static void
16581do_neon_movhf (void)
16582{
16583 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16584 constraint (rs != NS_HH, _("invalid suffix"));
16585
16586 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16587 _(BAD_FPU));
16588
16589 do_vfp_sp_monadic ();
16590
16591 inst.is_neon = 1;
16592 inst.instruction |= 0xf0000000;
16593}
16594
5287ad62
JB
16595static void
16596do_neon_movl (void)
16597{
16598 struct neon_type_el et = neon_check_type (2, NS_QD,
16599 N_EQK | N_DBL, N_SU_32 | N_KEY);
16600 unsigned sizebits = et.size >> 3;
16601 inst.instruction |= sizebits << 19;
16602 neon_two_same (0, et.type == NT_unsigned, -1);
16603}
16604
16605static void
16606do_neon_trn (void)
16607{
037e8744 16608 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16609 struct neon_type_el et = neon_check_type (2, rs,
16610 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16611 NEON_ENCODE (INTEGER, inst);
037e8744 16612 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16613}
16614
16615static void
16616do_neon_zip_uzp (void)
16617{
037e8744 16618 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16619 struct neon_type_el et = neon_check_type (2, rs,
16620 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16621 if (rs == NS_DD && et.size == 32)
16622 {
16623 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16624 inst.instruction = N_MNEM_vtrn;
16625 do_neon_trn ();
16626 return;
16627 }
037e8744 16628 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16629}
16630
16631static void
16632do_neon_sat_abs_neg (void)
16633{
037e8744 16634 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16635 struct neon_type_el et = neon_check_type (2, rs,
16636 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16637 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16638}
16639
16640static void
16641do_neon_pair_long (void)
16642{
037e8744 16643 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16644 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16645 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16646 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16647 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16648}
16649
16650static void
16651do_neon_recip_est (void)
16652{
037e8744 16653 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16654 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16655 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16656 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16657 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16658}
16659
16660static void
16661do_neon_cls (void)
16662{
037e8744 16663 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16664 struct neon_type_el et = neon_check_type (2, rs,
16665 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16666 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16667}
16668
16669static void
16670do_neon_clz (void)
16671{
037e8744 16672 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16673 struct neon_type_el et = neon_check_type (2, rs,
16674 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16675 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16676}
16677
16678static void
16679do_neon_cnt (void)
16680{
037e8744 16681 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16682 struct neon_type_el et = neon_check_type (2, rs,
16683 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16684 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16685}
16686
16687static void
16688do_neon_swp (void)
16689{
037e8744
JB
16690 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16691 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16692}
16693
16694static void
16695do_neon_tbl_tbx (void)
16696{
16697 unsigned listlenbits;
dcbf9037 16698 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16699
5287ad62
JB
16700 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16701 {
dcbf9037 16702 first_error (_("bad list length for table lookup"));
5287ad62
JB
16703 return;
16704 }
5f4273c7 16705
5287ad62
JB
16706 listlenbits = inst.operands[1].imm - 1;
16707 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16708 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16709 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16710 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16711 inst.instruction |= LOW4 (inst.operands[2].reg);
16712 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16713 inst.instruction |= listlenbits << 8;
5f4273c7 16714
88714cb8 16715 neon_dp_fixup (&inst);
5287ad62
JB
16716}
16717
16718static void
16719do_neon_ldm_stm (void)
16720{
16721 /* P, U and L bits are part of bitmask. */
16722 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16723 unsigned offsetbits = inst.operands[1].imm * 2;
16724
037e8744
JB
16725 if (inst.operands[1].issingle)
16726 {
16727 do_vfp_nsyn_ldm_stm (is_dbmode);
16728 return;
16729 }
16730
5287ad62 16731 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16732 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16733
16734 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16735 _("register list must contain at least 1 and at most 16 "
16736 "registers"));
5287ad62
JB
16737
16738 inst.instruction |= inst.operands[0].reg << 16;
16739 inst.instruction |= inst.operands[0].writeback << 21;
16740 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16741 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16742
16743 inst.instruction |= offsetbits;
5f4273c7 16744
037e8744 16745 do_vfp_cond_or_thumb ();
5287ad62
JB
16746}
16747
16748static void
16749do_neon_ldr_str (void)
16750{
5287ad62 16751 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16752
6844b2c2
MGD
16753 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16754 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16755 if (!is_ldr
6844b2c2 16756 && inst.operands[1].reg == REG_PC
ba86b375 16757 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16758 {
94dcf8bf 16759 if (thumb_mode)
6844b2c2 16760 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16761 else if (warn_on_deprecated)
5c3696f8 16762 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16763 }
16764
037e8744
JB
16765 if (inst.operands[0].issingle)
16766 {
cd2f129f 16767 if (is_ldr)
477330fc 16768 do_vfp_nsyn_opcode ("flds");
cd2f129f 16769 else
477330fc 16770 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16771
16772 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16773 if (inst.vectype.el[0].size == 16)
16774 do_scalar_fp16_v82_encode ();
5287ad62
JB
16775 }
16776 else
5287ad62 16777 {
cd2f129f 16778 if (is_ldr)
477330fc 16779 do_vfp_nsyn_opcode ("fldd");
5287ad62 16780 else
477330fc 16781 do_vfp_nsyn_opcode ("fstd");
5287ad62 16782 }
5287ad62
JB
16783}
16784
16785/* "interleave" version also handles non-interleaving register VLD1/VST1
16786 instructions. */
16787
16788static void
16789do_neon_ld_st_interleave (void)
16790{
037e8744 16791 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16792 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16793 unsigned alignbits = 0;
16794 unsigned idx;
16795 /* The bits in this table go:
16796 0: register stride of one (0) or two (1)
16797 1,2: register list length, minus one (1, 2, 3, 4).
16798 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16799 We use -1 for invalid entries. */
16800 const int typetable[] =
16801 {
16802 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16803 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16804 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16805 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16806 };
16807 int typebits;
16808
dcbf9037
JB
16809 if (et.type == NT_invtype)
16810 return;
16811
5287ad62
JB
16812 if (inst.operands[1].immisalign)
16813 switch (inst.operands[1].imm >> 8)
16814 {
16815 case 64: alignbits = 1; break;
16816 case 128:
477330fc 16817 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16818 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16819 goto bad_alignment;
16820 alignbits = 2;
16821 break;
5287ad62 16822 case 256:
477330fc
RM
16823 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16824 goto bad_alignment;
16825 alignbits = 3;
16826 break;
5287ad62
JB
16827 default:
16828 bad_alignment:
477330fc
RM
16829 first_error (_("bad alignment"));
16830 return;
5287ad62
JB
16831 }
16832
16833 inst.instruction |= alignbits << 4;
16834 inst.instruction |= neon_logbits (et.size) << 6;
16835
16836 /* Bits [4:6] of the immediate in a list specifier encode register stride
16837 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16838 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16839 up the right value for "type" in a table based on this value and the given
16840 list style, then stick it back. */
16841 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16842 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16843
16844 typebits = typetable[idx];
5f4273c7 16845
5287ad62 16846 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16847 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16848 _("bad element type for instruction"));
5287ad62
JB
16849
16850 inst.instruction &= ~0xf00;
16851 inst.instruction |= typebits << 8;
16852}
16853
16854/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16855 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16856 otherwise. The variable arguments are a list of pairs of legal (size, align)
16857 values, terminated with -1. */
16858
16859static int
aa8a0863 16860neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16861{
16862 va_list ap;
16863 int result = FAIL, thissize, thisalign;
5f4273c7 16864
5287ad62
JB
16865 if (!inst.operands[1].immisalign)
16866 {
aa8a0863 16867 *do_alignment = 0;
5287ad62
JB
16868 return SUCCESS;
16869 }
5f4273c7 16870
aa8a0863 16871 va_start (ap, do_alignment);
5287ad62
JB
16872
16873 do
16874 {
16875 thissize = va_arg (ap, int);
16876 if (thissize == -1)
477330fc 16877 break;
5287ad62
JB
16878 thisalign = va_arg (ap, int);
16879
16880 if (size == thissize && align == thisalign)
477330fc 16881 result = SUCCESS;
5287ad62
JB
16882 }
16883 while (result != SUCCESS);
16884
16885 va_end (ap);
16886
16887 if (result == SUCCESS)
aa8a0863 16888 *do_alignment = 1;
5287ad62 16889 else
dcbf9037 16890 first_error (_("unsupported alignment for instruction"));
5f4273c7 16891
5287ad62
JB
16892 return result;
16893}
16894
16895static void
16896do_neon_ld_st_lane (void)
16897{
037e8744 16898 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16899 int align_good, do_alignment = 0;
5287ad62
JB
16900 int logsize = neon_logbits (et.size);
16901 int align = inst.operands[1].imm >> 8;
16902 int n = (inst.instruction >> 8) & 3;
16903 int max_el = 64 / et.size;
5f4273c7 16904
dcbf9037
JB
16905 if (et.type == NT_invtype)
16906 return;
5f4273c7 16907
5287ad62 16908 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16909 _("bad list length"));
5287ad62 16910 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16911 _("scalar index out of range"));
5287ad62 16912 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16913 && et.size == 8,
16914 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16915
5287ad62
JB
16916 switch (n)
16917 {
16918 case 0: /* VLD1 / VST1. */
aa8a0863 16919 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16920 32, 32, -1);
5287ad62 16921 if (align_good == FAIL)
477330fc 16922 return;
aa8a0863 16923 if (do_alignment)
477330fc
RM
16924 {
16925 unsigned alignbits = 0;
16926 switch (et.size)
16927 {
16928 case 16: alignbits = 0x1; break;
16929 case 32: alignbits = 0x3; break;
16930 default: ;
16931 }
16932 inst.instruction |= alignbits << 4;
16933 }
5287ad62
JB
16934 break;
16935
16936 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16937 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16938 16, 32, 32, 64, -1);
5287ad62 16939 if (align_good == FAIL)
477330fc 16940 return;
aa8a0863 16941 if (do_alignment)
477330fc 16942 inst.instruction |= 1 << 4;
5287ad62
JB
16943 break;
16944
16945 case 2: /* VLD3 / VST3. */
16946 constraint (inst.operands[1].immisalign,
477330fc 16947 _("can't use alignment with this instruction"));
5287ad62
JB
16948 break;
16949
16950 case 3: /* VLD4 / VST4. */
aa8a0863 16951 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16952 16, 64, 32, 64, 32, 128, -1);
5287ad62 16953 if (align_good == FAIL)
477330fc 16954 return;
aa8a0863 16955 if (do_alignment)
477330fc
RM
16956 {
16957 unsigned alignbits = 0;
16958 switch (et.size)
16959 {
16960 case 8: alignbits = 0x1; break;
16961 case 16: alignbits = 0x1; break;
16962 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16963 default: ;
16964 }
16965 inst.instruction |= alignbits << 4;
16966 }
5287ad62
JB
16967 break;
16968
16969 default: ;
16970 }
16971
16972 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16973 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16974 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16975
5287ad62
JB
16976 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16977 inst.instruction |= logsize << 10;
16978}
16979
16980/* Encode single n-element structure to all lanes VLD<n> instructions. */
16981
16982static void
16983do_neon_ld_dup (void)
16984{
037e8744 16985 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16986 int align_good, do_alignment = 0;
5287ad62 16987
dcbf9037
JB
16988 if (et.type == NT_invtype)
16989 return;
16990
5287ad62
JB
16991 switch ((inst.instruction >> 8) & 3)
16992 {
16993 case 0: /* VLD1. */
9c2799c2 16994 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16995 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16996 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16997 if (align_good == FAIL)
477330fc 16998 return;
5287ad62 16999 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17000 {
17001 case 1: break;
17002 case 2: inst.instruction |= 1 << 5; break;
17003 default: first_error (_("bad list length")); return;
17004 }
5287ad62
JB
17005 inst.instruction |= neon_logbits (et.size) << 6;
17006 break;
17007
17008 case 1: /* VLD2. */
17009 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17010 &do_alignment, 8, 16, 16, 32, 32, 64,
17011 -1);
5287ad62 17012 if (align_good == FAIL)
477330fc 17013 return;
5287ad62 17014 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17015 _("bad list length"));
5287ad62 17016 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17017 inst.instruction |= 1 << 5;
5287ad62
JB
17018 inst.instruction |= neon_logbits (et.size) << 6;
17019 break;
17020
17021 case 2: /* VLD3. */
17022 constraint (inst.operands[1].immisalign,
477330fc 17023 _("can't use alignment with this instruction"));
5287ad62 17024 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17025 _("bad list length"));
5287ad62 17026 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17027 inst.instruction |= 1 << 5;
5287ad62
JB
17028 inst.instruction |= neon_logbits (et.size) << 6;
17029 break;
17030
17031 case 3: /* VLD4. */
17032 {
477330fc 17033 int align = inst.operands[1].imm >> 8;
aa8a0863 17034 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17035 16, 64, 32, 64, 32, 128, -1);
17036 if (align_good == FAIL)
17037 return;
17038 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17039 _("bad list length"));
17040 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17041 inst.instruction |= 1 << 5;
17042 if (et.size == 32 && align == 128)
17043 inst.instruction |= 0x3 << 6;
17044 else
17045 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17046 }
17047 break;
17048
17049 default: ;
17050 }
17051
aa8a0863 17052 inst.instruction |= do_alignment << 4;
5287ad62
JB
17053}
17054
17055/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17056 apart from bits [11:4]. */
17057
17058static void
17059do_neon_ldx_stx (void)
17060{
b1a769ed
DG
17061 if (inst.operands[1].isreg)
17062 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17063
5287ad62
JB
17064 switch (NEON_LANE (inst.operands[0].imm))
17065 {
17066 case NEON_INTERLEAVE_LANES:
88714cb8 17067 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17068 do_neon_ld_st_interleave ();
17069 break;
5f4273c7 17070
5287ad62 17071 case NEON_ALL_LANES:
88714cb8 17072 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17073 if (inst.instruction == N_INV)
17074 {
17075 first_error ("only loads support such operands");
17076 break;
17077 }
5287ad62
JB
17078 do_neon_ld_dup ();
17079 break;
5f4273c7 17080
5287ad62 17081 default:
88714cb8 17082 NEON_ENCODE (LANE, inst);
5287ad62
JB
17083 do_neon_ld_st_lane ();
17084 }
17085
17086 /* L bit comes from bit mask. */
17087 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17088 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17089 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17090
5287ad62
JB
17091 if (inst.operands[1].postind)
17092 {
17093 int postreg = inst.operands[1].imm & 0xf;
17094 constraint (!inst.operands[1].immisreg,
477330fc 17095 _("post-index must be a register"));
5287ad62 17096 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17097 _("bad register for post-index"));
5287ad62
JB
17098 inst.instruction |= postreg;
17099 }
4f2374c7 17100 else
5287ad62 17101 {
4f2374c7
WN
17102 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17103 constraint (inst.reloc.exp.X_op != O_constant
17104 || inst.reloc.exp.X_add_number != 0,
17105 BAD_ADDR_MODE);
17106
17107 if (inst.operands[1].writeback)
17108 {
17109 inst.instruction |= 0xd;
17110 }
17111 else
17112 inst.instruction |= 0xf;
5287ad62 17113 }
5f4273c7 17114
5287ad62
JB
17115 if (thumb_mode)
17116 inst.instruction |= 0xf9000000;
17117 else
17118 inst.instruction |= 0xf4000000;
17119}
33399f07
MGD
17120
17121/* FP v8. */
17122static void
17123do_vfp_nsyn_fpv8 (enum neon_shape rs)
17124{
a715796b
TG
17125 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17126 D register operands. */
17127 if (neon_shape_class[rs] == SC_DOUBLE)
17128 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17129 _(BAD_FPU));
17130
33399f07
MGD
17131 NEON_ENCODE (FPV8, inst);
17132
9db2f6b4
RL
17133 if (rs == NS_FFF || rs == NS_HHH)
17134 {
17135 do_vfp_sp_dyadic ();
17136
17137 /* ARMv8.2 fp16 instruction. */
17138 if (rs == NS_HHH)
17139 do_scalar_fp16_v82_encode ();
17140 }
33399f07
MGD
17141 else
17142 do_vfp_dp_rd_rn_rm ();
17143
17144 if (rs == NS_DDD)
17145 inst.instruction |= 0x100;
17146
17147 inst.instruction |= 0xf0000000;
17148}
17149
17150static void
17151do_vsel (void)
17152{
17153 set_it_insn_type (OUTSIDE_IT_INSN);
17154
17155 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17156 first_error (_("invalid instruction shape"));
17157}
17158
73924fbc
MGD
17159static void
17160do_vmaxnm (void)
17161{
17162 set_it_insn_type (OUTSIDE_IT_INSN);
17163
17164 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17165 return;
17166
17167 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17168 return;
17169
cc933301 17170 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17171}
17172
30bdf752
MGD
17173static void
17174do_vrint_1 (enum neon_cvt_mode mode)
17175{
9db2f6b4 17176 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17177 struct neon_type_el et;
17178
17179 if (rs == NS_NULL)
17180 return;
17181
a715796b
TG
17182 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17183 D register operands. */
17184 if (neon_shape_class[rs] == SC_DOUBLE)
17185 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17186 _(BAD_FPU));
17187
9db2f6b4
RL
17188 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17189 | N_VFP);
30bdf752
MGD
17190 if (et.type != NT_invtype)
17191 {
17192 /* VFP encodings. */
17193 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17194 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17195 set_it_insn_type (OUTSIDE_IT_INSN);
17196
17197 NEON_ENCODE (FPV8, inst);
9db2f6b4 17198 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17199 do_vfp_sp_monadic ();
17200 else
17201 do_vfp_dp_rd_rm ();
17202
17203 switch (mode)
17204 {
17205 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17206 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17207 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17208 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17209 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17210 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17211 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17212 default: abort ();
17213 }
17214
17215 inst.instruction |= (rs == NS_DD) << 8;
17216 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17217
17218 /* ARMv8.2 fp16 vrint instruction. */
17219 if (rs == NS_HH)
17220 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17221 }
17222 else
17223 {
17224 /* Neon encodings (or something broken...). */
17225 inst.error = NULL;
cc933301 17226 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17227
17228 if (et.type == NT_invtype)
17229 return;
17230
17231 set_it_insn_type (OUTSIDE_IT_INSN);
17232 NEON_ENCODE (FLOAT, inst);
17233
17234 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17235 return;
17236
17237 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17238 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17239 inst.instruction |= LOW4 (inst.operands[1].reg);
17240 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17241 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17242 /* Mask off the original size bits and reencode them. */
17243 inst.instruction = ((inst.instruction & 0xfff3ffff)
17244 | neon_logbits (et.size) << 18);
17245
30bdf752
MGD
17246 switch (mode)
17247 {
17248 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17249 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17250 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17251 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17252 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17253 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17254 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17255 default: abort ();
17256 }
17257
17258 if (thumb_mode)
17259 inst.instruction |= 0xfc000000;
17260 else
17261 inst.instruction |= 0xf0000000;
17262 }
17263}
17264
17265static void
17266do_vrintx (void)
17267{
17268 do_vrint_1 (neon_cvt_mode_x);
17269}
17270
17271static void
17272do_vrintz (void)
17273{
17274 do_vrint_1 (neon_cvt_mode_z);
17275}
17276
17277static void
17278do_vrintr (void)
17279{
17280 do_vrint_1 (neon_cvt_mode_r);
17281}
17282
17283static void
17284do_vrinta (void)
17285{
17286 do_vrint_1 (neon_cvt_mode_a);
17287}
17288
17289static void
17290do_vrintn (void)
17291{
17292 do_vrint_1 (neon_cvt_mode_n);
17293}
17294
17295static void
17296do_vrintp (void)
17297{
17298 do_vrint_1 (neon_cvt_mode_p);
17299}
17300
17301static void
17302do_vrintm (void)
17303{
17304 do_vrint_1 (neon_cvt_mode_m);
17305}
17306
c28eeff2
SN
17307static unsigned
17308neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17309{
17310 unsigned regno = NEON_SCALAR_REG (opnd);
17311 unsigned elno = NEON_SCALAR_INDEX (opnd);
17312
17313 if (elsize == 16 && elno < 2 && regno < 16)
17314 return regno | (elno << 4);
17315 else if (elsize == 32 && elno == 0)
17316 return regno;
17317
17318 first_error (_("scalar out of range"));
17319 return 0;
17320}
17321
17322static void
17323do_vcmla (void)
17324{
17325 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17326 _(BAD_FPU));
17327 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17328 unsigned rot = inst.reloc.exp.X_add_number;
17329 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17330 _("immediate out of range"));
17331 rot /= 90;
17332 if (inst.operands[2].isscalar)
17333 {
17334 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17335 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17336 N_KEY | N_F16 | N_F32).size;
17337 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17338 inst.is_neon = 1;
17339 inst.instruction = 0xfe000800;
17340 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17341 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17342 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17343 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17344 inst.instruction |= LOW4 (m);
17345 inst.instruction |= HI1 (m) << 5;
17346 inst.instruction |= neon_quad (rs) << 6;
17347 inst.instruction |= rot << 20;
17348 inst.instruction |= (size == 32) << 23;
17349 }
17350 else
17351 {
17352 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17353 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17354 N_KEY | N_F16 | N_F32).size;
17355 neon_three_same (neon_quad (rs), 0, -1);
17356 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17357 inst.instruction |= 0xfc200800;
17358 inst.instruction |= rot << 23;
17359 inst.instruction |= (size == 32) << 20;
17360 }
17361}
17362
17363static void
17364do_vcadd (void)
17365{
17366 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17367 _(BAD_FPU));
17368 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17369 unsigned rot = inst.reloc.exp.X_add_number;
17370 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17371 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17372 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17373 N_KEY | N_F16 | N_F32).size;
17374 neon_three_same (neon_quad (rs), 0, -1);
17375 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17376 inst.instruction |= 0xfc800800;
17377 inst.instruction |= (rot == 270) << 24;
17378 inst.instruction |= (size == 32) << 20;
17379}
17380
91ff7894
MGD
17381/* Crypto v1 instructions. */
17382static void
17383do_crypto_2op_1 (unsigned elttype, int op)
17384{
17385 set_it_insn_type (OUTSIDE_IT_INSN);
17386
17387 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17388 == NT_invtype)
17389 return;
17390
17391 inst.error = NULL;
17392
17393 NEON_ENCODE (INTEGER, inst);
17394 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17395 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17396 inst.instruction |= LOW4 (inst.operands[1].reg);
17397 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17398 if (op != -1)
17399 inst.instruction |= op << 6;
17400
17401 if (thumb_mode)
17402 inst.instruction |= 0xfc000000;
17403 else
17404 inst.instruction |= 0xf0000000;
17405}
17406
48adcd8e
MGD
17407static void
17408do_crypto_3op_1 (int u, int op)
17409{
17410 set_it_insn_type (OUTSIDE_IT_INSN);
17411
17412 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17413 N_32 | N_UNT | N_KEY).type == NT_invtype)
17414 return;
17415
17416 inst.error = NULL;
17417
17418 NEON_ENCODE (INTEGER, inst);
17419 neon_three_same (1, u, 8 << op);
17420}
17421
91ff7894
MGD
17422static void
17423do_aese (void)
17424{
17425 do_crypto_2op_1 (N_8, 0);
17426}
17427
17428static void
17429do_aesd (void)
17430{
17431 do_crypto_2op_1 (N_8, 1);
17432}
17433
17434static void
17435do_aesmc (void)
17436{
17437 do_crypto_2op_1 (N_8, 2);
17438}
17439
17440static void
17441do_aesimc (void)
17442{
17443 do_crypto_2op_1 (N_8, 3);
17444}
17445
48adcd8e
MGD
17446static void
17447do_sha1c (void)
17448{
17449 do_crypto_3op_1 (0, 0);
17450}
17451
17452static void
17453do_sha1p (void)
17454{
17455 do_crypto_3op_1 (0, 1);
17456}
17457
17458static void
17459do_sha1m (void)
17460{
17461 do_crypto_3op_1 (0, 2);
17462}
17463
17464static void
17465do_sha1su0 (void)
17466{
17467 do_crypto_3op_1 (0, 3);
17468}
91ff7894 17469
48adcd8e
MGD
17470static void
17471do_sha256h (void)
17472{
17473 do_crypto_3op_1 (1, 0);
17474}
17475
17476static void
17477do_sha256h2 (void)
17478{
17479 do_crypto_3op_1 (1, 1);
17480}
17481
17482static void
17483do_sha256su1 (void)
17484{
17485 do_crypto_3op_1 (1, 2);
17486}
3c9017d2
MGD
17487
17488static void
17489do_sha1h (void)
17490{
17491 do_crypto_2op_1 (N_32, -1);
17492}
17493
17494static void
17495do_sha1su1 (void)
17496{
17497 do_crypto_2op_1 (N_32, 0);
17498}
17499
17500static void
17501do_sha256su0 (void)
17502{
17503 do_crypto_2op_1 (N_32, 1);
17504}
dd5181d5
KT
17505
17506static void
17507do_crc32_1 (unsigned int poly, unsigned int sz)
17508{
17509 unsigned int Rd = inst.operands[0].reg;
17510 unsigned int Rn = inst.operands[1].reg;
17511 unsigned int Rm = inst.operands[2].reg;
17512
17513 set_it_insn_type (OUTSIDE_IT_INSN);
17514 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17515 inst.instruction |= LOW4 (Rn) << 16;
17516 inst.instruction |= LOW4 (Rm);
17517 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17518 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17519
17520 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17521 as_warn (UNPRED_REG ("r15"));
17522 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17523 as_warn (UNPRED_REG ("r13"));
17524}
17525
17526static void
17527do_crc32b (void)
17528{
17529 do_crc32_1 (0, 0);
17530}
17531
17532static void
17533do_crc32h (void)
17534{
17535 do_crc32_1 (0, 1);
17536}
17537
17538static void
17539do_crc32w (void)
17540{
17541 do_crc32_1 (0, 2);
17542}
17543
17544static void
17545do_crc32cb (void)
17546{
17547 do_crc32_1 (1, 0);
17548}
17549
17550static void
17551do_crc32ch (void)
17552{
17553 do_crc32_1 (1, 1);
17554}
17555
17556static void
17557do_crc32cw (void)
17558{
17559 do_crc32_1 (1, 2);
17560}
17561
49e8a725
SN
17562static void
17563do_vjcvt (void)
17564{
17565 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17566 _(BAD_FPU));
17567 neon_check_type (2, NS_FD, N_S32, N_F64);
17568 do_vfp_sp_dp_cvt ();
17569 do_vfp_cond_or_thumb ();
17570}
17571
5287ad62
JB
17572\f
17573/* Overall per-instruction processing. */
17574
17575/* We need to be able to fix up arbitrary expressions in some statements.
17576 This is so that we can handle symbols that are an arbitrary distance from
17577 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17578 which returns part of an address in a form which will be valid for
17579 a data instruction. We do this by pushing the expression into a symbol
17580 in the expr_section, and creating a fix for that. */
17581
17582static void
17583fix_new_arm (fragS * frag,
17584 int where,
17585 short int size,
17586 expressionS * exp,
17587 int pc_rel,
17588 int reloc)
17589{
17590 fixS * new_fix;
17591
17592 switch (exp->X_op)
17593 {
17594 case O_constant:
6e7ce2cd
PB
17595 if (pc_rel)
17596 {
17597 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17598 refer to in the object file. Unfortunately for us, gas's
17599 generic expression parsing will already have folded out
17600 any use of .set foo/.type foo %function that may have
17601 been used to set type information of the target location,
17602 that's being specified symbolically. We have to presume
17603 the user knows what they are doing. */
6e7ce2cd
PB
17604 char name[16 + 8];
17605 symbolS *symbol;
17606
17607 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17608
17609 symbol = symbol_find_or_make (name);
17610 S_SET_SEGMENT (symbol, absolute_section);
17611 symbol_set_frag (symbol, &zero_address_frag);
17612 S_SET_VALUE (symbol, exp->X_add_number);
17613 exp->X_op = O_symbol;
17614 exp->X_add_symbol = symbol;
17615 exp->X_add_number = 0;
17616 }
17617 /* FALLTHROUGH */
5287ad62
JB
17618 case O_symbol:
17619 case O_add:
17620 case O_subtract:
21d799b5 17621 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17622 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17623 break;
17624
17625 default:
21d799b5 17626 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17627 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17628 break;
17629 }
17630
17631 /* Mark whether the fix is to a THUMB instruction, or an ARM
17632 instruction. */
17633 new_fix->tc_fix_data = thumb_mode;
17634}
17635
17636/* Create a frg for an instruction requiring relaxation. */
17637static void
17638output_relax_insn (void)
17639{
17640 char * to;
17641 symbolS *sym;
0110f2b8
PB
17642 int offset;
17643
6e1cb1a6
PB
17644 /* The size of the instruction is unknown, so tie the debug info to the
17645 start of the instruction. */
17646 dwarf2_emit_insn (0);
6e1cb1a6 17647
0110f2b8
PB
17648 switch (inst.reloc.exp.X_op)
17649 {
17650 case O_symbol:
17651 sym = inst.reloc.exp.X_add_symbol;
17652 offset = inst.reloc.exp.X_add_number;
17653 break;
17654 case O_constant:
17655 sym = NULL;
17656 offset = inst.reloc.exp.X_add_number;
17657 break;
17658 default:
17659 sym = make_expr_symbol (&inst.reloc.exp);
17660 offset = 0;
17661 break;
17662 }
17663 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17664 inst.relax, sym, offset, NULL/*offset, opcode*/);
17665 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17666}
17667
17668/* Write a 32-bit thumb instruction to buf. */
17669static void
17670put_thumb32_insn (char * buf, unsigned long insn)
17671{
17672 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17673 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17674}
17675
b99bd4ef 17676static void
c19d1205 17677output_inst (const char * str)
b99bd4ef 17678{
c19d1205 17679 char * to = NULL;
b99bd4ef 17680
c19d1205 17681 if (inst.error)
b99bd4ef 17682 {
c19d1205 17683 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17684 return;
17685 }
5f4273c7
NC
17686 if (inst.relax)
17687 {
17688 output_relax_insn ();
0110f2b8 17689 return;
5f4273c7 17690 }
c19d1205
ZW
17691 if (inst.size == 0)
17692 return;
b99bd4ef 17693
c19d1205 17694 to = frag_more (inst.size);
8dc2430f
NC
17695 /* PR 9814: Record the thumb mode into the current frag so that we know
17696 what type of NOP padding to use, if necessary. We override any previous
17697 setting so that if the mode has changed then the NOPS that we use will
17698 match the encoding of the last instruction in the frag. */
cd000bff 17699 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17700
17701 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17702 {
9c2799c2 17703 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17704 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17705 }
c19d1205 17706 else if (inst.size > INSN_SIZE)
b99bd4ef 17707 {
9c2799c2 17708 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17709 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17710 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17711 }
c19d1205
ZW
17712 else
17713 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17714
c19d1205
ZW
17715 if (inst.reloc.type != BFD_RELOC_UNUSED)
17716 fix_new_arm (frag_now, to - frag_now->fr_literal,
17717 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17718 inst.reloc.type);
b99bd4ef 17719
c19d1205 17720 dwarf2_emit_insn (inst.size);
c19d1205 17721}
b99bd4ef 17722
e07e6e58
NC
17723static char *
17724output_it_inst (int cond, int mask, char * to)
17725{
17726 unsigned long instruction = 0xbf00;
17727
17728 mask &= 0xf;
17729 instruction |= mask;
17730 instruction |= cond << 4;
17731
17732 if (to == NULL)
17733 {
17734 to = frag_more (2);
17735#ifdef OBJ_ELF
17736 dwarf2_emit_insn (2);
17737#endif
17738 }
17739
17740 md_number_to_chars (to, instruction, 2);
17741
17742 return to;
17743}
17744
c19d1205
ZW
17745/* Tag values used in struct asm_opcode's tag field. */
17746enum opcode_tag
17747{
17748 OT_unconditional, /* Instruction cannot be conditionalized.
17749 The ARM condition field is still 0xE. */
17750 OT_unconditionalF, /* Instruction cannot be conditionalized
17751 and carries 0xF in its ARM condition field. */
17752 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17753 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17754 suffix, others place 0xF where the condition field
17755 would be. */
c19d1205
ZW
17756 OT_cinfix3, /* Instruction takes a conditional infix,
17757 beginning at character index 3. (In
17758 unified mode, it becomes a suffix.) */
088fa78e
KH
17759 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17760 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17761 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17762 character index 3, even in unified mode. Used for
17763 legacy instructions where suffix and infix forms
17764 may be ambiguous. */
c19d1205 17765 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17766 suffix or an infix at character index 3. */
c19d1205
ZW
17767 OT_odd_infix_unc, /* This is the unconditional variant of an
17768 instruction that takes a conditional infix
17769 at an unusual position. In unified mode,
17770 this variant will accept a suffix. */
17771 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17772 are the conditional variants of instructions that
17773 take conditional infixes in unusual positions.
17774 The infix appears at character index
17775 (tag - OT_odd_infix_0). These are not accepted
17776 in unified mode. */
17777};
b99bd4ef 17778
c19d1205
ZW
17779/* Subroutine of md_assemble, responsible for looking up the primary
17780 opcode from the mnemonic the user wrote. STR points to the
17781 beginning of the mnemonic.
17782
17783 This is not simply a hash table lookup, because of conditional
17784 variants. Most instructions have conditional variants, which are
17785 expressed with a _conditional affix_ to the mnemonic. If we were
17786 to encode each conditional variant as a literal string in the opcode
17787 table, it would have approximately 20,000 entries.
17788
17789 Most mnemonics take this affix as a suffix, and in unified syntax,
17790 'most' is upgraded to 'all'. However, in the divided syntax, some
17791 instructions take the affix as an infix, notably the s-variants of
17792 the arithmetic instructions. Of those instructions, all but six
17793 have the infix appear after the third character of the mnemonic.
17794
17795 Accordingly, the algorithm for looking up primary opcodes given
17796 an identifier is:
17797
17798 1. Look up the identifier in the opcode table.
17799 If we find a match, go to step U.
17800
17801 2. Look up the last two characters of the identifier in the
17802 conditions table. If we find a match, look up the first N-2
17803 characters of the identifier in the opcode table. If we
17804 find a match, go to step CE.
17805
17806 3. Look up the fourth and fifth characters of the identifier in
17807 the conditions table. If we find a match, extract those
17808 characters from the identifier, and look up the remaining
17809 characters in the opcode table. If we find a match, go
17810 to step CM.
17811
17812 4. Fail.
17813
17814 U. Examine the tag field of the opcode structure, in case this is
17815 one of the six instructions with its conditional infix in an
17816 unusual place. If it is, the tag tells us where to find the
17817 infix; look it up in the conditions table and set inst.cond
17818 accordingly. Otherwise, this is an unconditional instruction.
17819 Again set inst.cond accordingly. Return the opcode structure.
17820
17821 CE. Examine the tag field to make sure this is an instruction that
17822 should receive a conditional suffix. If it is not, fail.
17823 Otherwise, set inst.cond from the suffix we already looked up,
17824 and return the opcode structure.
17825
17826 CM. Examine the tag field to make sure this is an instruction that
17827 should receive a conditional infix after the third character.
17828 If it is not, fail. Otherwise, undo the edits to the current
17829 line of input and proceed as for case CE. */
17830
17831static const struct asm_opcode *
17832opcode_lookup (char **str)
17833{
17834 char *end, *base;
17835 char *affix;
17836 const struct asm_opcode *opcode;
17837 const struct asm_cond *cond;
e3cb604e 17838 char save[2];
c19d1205
ZW
17839
17840 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17841 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17842 for (base = end = *str; *end != '\0'; end++)
721a8186 17843 if (*end == ' ' || *end == '.')
c19d1205 17844 break;
b99bd4ef 17845
c19d1205 17846 if (end == base)
c921be7d 17847 return NULL;
b99bd4ef 17848
5287ad62 17849 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17850 if (end[0] == '.')
b99bd4ef 17851 {
5287ad62 17852 int offset = 2;
5f4273c7 17853
267d2029 17854 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17855 use. */
267d2029 17856 if (unified_syntax && end[1] == 'w')
c19d1205 17857 inst.size_req = 4;
267d2029 17858 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17859 inst.size_req = 2;
17860 else
477330fc 17861 offset = 0;
5287ad62
JB
17862
17863 inst.vectype.elems = 0;
17864
17865 *str = end + offset;
b99bd4ef 17866
5f4273c7 17867 if (end[offset] == '.')
5287ad62 17868 {
267d2029 17869 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17870 non-unified ARM syntax mode). */
17871 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17872 return NULL;
477330fc 17873 }
5287ad62 17874 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17875 return NULL;
b99bd4ef 17876 }
c19d1205
ZW
17877 else
17878 *str = end;
b99bd4ef 17879
c19d1205 17880 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17881 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17882 end - base);
c19d1205 17883 if (opcode)
b99bd4ef 17884 {
c19d1205
ZW
17885 /* step U */
17886 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17887 {
c19d1205
ZW
17888 inst.cond = COND_ALWAYS;
17889 return opcode;
b99bd4ef 17890 }
b99bd4ef 17891
278df34e 17892 if (warn_on_deprecated && unified_syntax)
5c3696f8 17893 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17894 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17895 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17896 gas_assert (cond);
b99bd4ef 17897
c19d1205
ZW
17898 inst.cond = cond->value;
17899 return opcode;
17900 }
b99bd4ef 17901
c19d1205
ZW
17902 /* Cannot have a conditional suffix on a mnemonic of less than two
17903 characters. */
17904 if (end - base < 3)
c921be7d 17905 return NULL;
b99bd4ef 17906
c19d1205
ZW
17907 /* Look for suffixed mnemonic. */
17908 affix = end - 2;
21d799b5
NC
17909 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17910 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17911 affix - base);
c19d1205
ZW
17912 if (opcode && cond)
17913 {
17914 /* step CE */
17915 switch (opcode->tag)
17916 {
e3cb604e
PB
17917 case OT_cinfix3_legacy:
17918 /* Ignore conditional suffixes matched on infix only mnemonics. */
17919 break;
17920
c19d1205 17921 case OT_cinfix3:
088fa78e 17922 case OT_cinfix3_deprecated:
c19d1205
ZW
17923 case OT_odd_infix_unc:
17924 if (!unified_syntax)
e3cb604e 17925 return 0;
1a0670f3 17926 /* Fall through. */
c19d1205
ZW
17927
17928 case OT_csuffix:
477330fc 17929 case OT_csuffixF:
c19d1205
ZW
17930 case OT_csuf_or_in3:
17931 inst.cond = cond->value;
17932 return opcode;
17933
17934 case OT_unconditional:
17935 case OT_unconditionalF:
dfa9f0d5 17936 if (thumb_mode)
c921be7d 17937 inst.cond = cond->value;
dfa9f0d5
PB
17938 else
17939 {
c921be7d 17940 /* Delayed diagnostic. */
dfa9f0d5
PB
17941 inst.error = BAD_COND;
17942 inst.cond = COND_ALWAYS;
17943 }
c19d1205 17944 return opcode;
b99bd4ef 17945
c19d1205 17946 default:
c921be7d 17947 return NULL;
c19d1205
ZW
17948 }
17949 }
b99bd4ef 17950
c19d1205
ZW
17951 /* Cannot have a usual-position infix on a mnemonic of less than
17952 six characters (five would be a suffix). */
17953 if (end - base < 6)
c921be7d 17954 return NULL;
b99bd4ef 17955
c19d1205
ZW
17956 /* Look for infixed mnemonic in the usual position. */
17957 affix = base + 3;
21d799b5 17958 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17959 if (!cond)
c921be7d 17960 return NULL;
e3cb604e
PB
17961
17962 memcpy (save, affix, 2);
17963 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17964 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17965 (end - base) - 2);
e3cb604e
PB
17966 memmove (affix + 2, affix, (end - affix) - 2);
17967 memcpy (affix, save, 2);
17968
088fa78e
KH
17969 if (opcode
17970 && (opcode->tag == OT_cinfix3
17971 || opcode->tag == OT_cinfix3_deprecated
17972 || opcode->tag == OT_csuf_or_in3
17973 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17974 {
c921be7d 17975 /* Step CM. */
278df34e 17976 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17977 && (opcode->tag == OT_cinfix3
17978 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17979 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17980
17981 inst.cond = cond->value;
17982 return opcode;
b99bd4ef
NC
17983 }
17984
c921be7d 17985 return NULL;
b99bd4ef
NC
17986}
17987
e07e6e58
NC
17988/* This function generates an initial IT instruction, leaving its block
17989 virtually open for the new instructions. Eventually,
17990 the mask will be updated by now_it_add_mask () each time
17991 a new instruction needs to be included in the IT block.
17992 Finally, the block is closed with close_automatic_it_block ().
17993 The block closure can be requested either from md_assemble (),
17994 a tencode (), or due to a label hook. */
17995
17996static void
17997new_automatic_it_block (int cond)
17998{
17999 now_it.state = AUTOMATIC_IT_BLOCK;
18000 now_it.mask = 0x18;
18001 now_it.cc = cond;
18002 now_it.block_length = 1;
cd000bff 18003 mapping_state (MAP_THUMB);
e07e6e58 18004 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18005 now_it.warn_deprecated = FALSE;
18006 now_it.insn_cond = TRUE;
e07e6e58
NC
18007}
18008
18009/* Close an automatic IT block.
18010 See comments in new_automatic_it_block (). */
18011
18012static void
18013close_automatic_it_block (void)
18014{
18015 now_it.mask = 0x10;
18016 now_it.block_length = 0;
18017}
18018
18019/* Update the mask of the current automatically-generated IT
18020 instruction. See comments in new_automatic_it_block (). */
18021
18022static void
18023now_it_add_mask (int cond)
18024{
18025#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18026#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18027 | ((bitvalue) << (nbit)))
e07e6e58 18028 const int resulting_bit = (cond & 1);
c921be7d 18029
e07e6e58
NC
18030 now_it.mask &= 0xf;
18031 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18032 resulting_bit,
18033 (5 - now_it.block_length));
e07e6e58 18034 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18035 1,
18036 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18037 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18038
18039#undef CLEAR_BIT
18040#undef SET_BIT_VALUE
e07e6e58
NC
18041}
18042
18043/* The IT blocks handling machinery is accessed through the these functions:
18044 it_fsm_pre_encode () from md_assemble ()
18045 set_it_insn_type () optional, from the tencode functions
18046 set_it_insn_type_last () ditto
18047 in_it_block () ditto
18048 it_fsm_post_encode () from md_assemble ()
33eaf5de 18049 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18050
18051 Rationale:
18052 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18053 initializing the IT insn type with a generic initial value depending
18054 on the inst.condition.
e07e6e58 18055 2) During the tencode function, two things may happen:
477330fc
RM
18056 a) The tencode function overrides the IT insn type by
18057 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18058 b) The tencode function queries the IT block state by
18059 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18060
18061 Both set_it_insn_type and in_it_block run the internal FSM state
18062 handling function (handle_it_state), because: a) setting the IT insn
18063 type may incur in an invalid state (exiting the function),
18064 and b) querying the state requires the FSM to be updated.
18065 Specifically we want to avoid creating an IT block for conditional
18066 branches, so it_fsm_pre_encode is actually a guess and we can't
18067 determine whether an IT block is required until the tencode () routine
18068 has decided what type of instruction this actually it.
18069 Because of this, if set_it_insn_type and in_it_block have to be used,
18070 set_it_insn_type has to be called first.
18071
18072 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18073 determines the insn IT type depending on the inst.cond code.
18074 When a tencode () routine encodes an instruction that can be
18075 either outside an IT block, or, in the case of being inside, has to be
18076 the last one, set_it_insn_type_last () will determine the proper
18077 IT instruction type based on the inst.cond code. Otherwise,
18078 set_it_insn_type can be called for overriding that logic or
18079 for covering other cases.
18080
18081 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18082 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18083 still queried. Instead, if the FSM determines that the state should
18084 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18085 after the tencode () function: that's what it_fsm_post_encode () does.
18086
18087 Since in_it_block () calls the state handling function to get an
18088 updated state, an error may occur (due to invalid insns combination).
18089 In that case, inst.error is set.
18090 Therefore, inst.error has to be checked after the execution of
18091 the tencode () routine.
e07e6e58
NC
18092
18093 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18094 any pending state change (if any) that didn't take place in
18095 handle_it_state () as explained above. */
e07e6e58
NC
18096
18097static void
18098it_fsm_pre_encode (void)
18099{
18100 if (inst.cond != COND_ALWAYS)
18101 inst.it_insn_type = INSIDE_IT_INSN;
18102 else
18103 inst.it_insn_type = OUTSIDE_IT_INSN;
18104
18105 now_it.state_handled = 0;
18106}
18107
18108/* IT state FSM handling function. */
18109
18110static int
18111handle_it_state (void)
18112{
18113 now_it.state_handled = 1;
5a01bb1d 18114 now_it.insn_cond = FALSE;
e07e6e58
NC
18115
18116 switch (now_it.state)
18117 {
18118 case OUTSIDE_IT_BLOCK:
18119 switch (inst.it_insn_type)
18120 {
18121 case OUTSIDE_IT_INSN:
18122 break;
18123
18124 case INSIDE_IT_INSN:
18125 case INSIDE_IT_LAST_INSN:
18126 if (thumb_mode == 0)
18127 {
c921be7d 18128 if (unified_syntax
e07e6e58
NC
18129 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18130 as_tsktsk (_("Warning: conditional outside an IT block"\
18131 " for Thumb."));
18132 }
18133 else
18134 {
18135 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18136 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18137 {
18138 /* Automatically generate the IT instruction. */
18139 new_automatic_it_block (inst.cond);
18140 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18141 close_automatic_it_block ();
18142 }
18143 else
18144 {
18145 inst.error = BAD_OUT_IT;
18146 return FAIL;
18147 }
18148 }
18149 break;
18150
18151 case IF_INSIDE_IT_LAST_INSN:
18152 case NEUTRAL_IT_INSN:
18153 break;
18154
18155 case IT_INSN:
18156 now_it.state = MANUAL_IT_BLOCK;
18157 now_it.block_length = 0;
18158 break;
18159 }
18160 break;
18161
18162 case AUTOMATIC_IT_BLOCK:
18163 /* Three things may happen now:
18164 a) We should increment current it block size;
18165 b) We should close current it block (closing insn or 4 insns);
18166 c) We should close current it block and start a new one (due
18167 to incompatible conditions or
18168 4 insns-length block reached). */
18169
18170 switch (inst.it_insn_type)
18171 {
18172 case OUTSIDE_IT_INSN:
2b0f3761 18173 /* The closure of the block shall happen immediately,
e07e6e58
NC
18174 so any in_it_block () call reports the block as closed. */
18175 force_automatic_it_block_close ();
18176 break;
18177
18178 case INSIDE_IT_INSN:
18179 case INSIDE_IT_LAST_INSN:
18180 case IF_INSIDE_IT_LAST_INSN:
18181 now_it.block_length++;
18182
18183 if (now_it.block_length > 4
18184 || !now_it_compatible (inst.cond))
18185 {
18186 force_automatic_it_block_close ();
18187 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18188 new_automatic_it_block (inst.cond);
18189 }
18190 else
18191 {
5a01bb1d 18192 now_it.insn_cond = TRUE;
e07e6e58
NC
18193 now_it_add_mask (inst.cond);
18194 }
18195
18196 if (now_it.state == AUTOMATIC_IT_BLOCK
18197 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18198 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18199 close_automatic_it_block ();
18200 break;
18201
18202 case NEUTRAL_IT_INSN:
18203 now_it.block_length++;
5a01bb1d 18204 now_it.insn_cond = TRUE;
e07e6e58
NC
18205
18206 if (now_it.block_length > 4)
18207 force_automatic_it_block_close ();
18208 else
18209 now_it_add_mask (now_it.cc & 1);
18210 break;
18211
18212 case IT_INSN:
18213 close_automatic_it_block ();
18214 now_it.state = MANUAL_IT_BLOCK;
18215 break;
18216 }
18217 break;
18218
18219 case MANUAL_IT_BLOCK:
18220 {
18221 /* Check conditional suffixes. */
18222 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18223 int is_last;
18224 now_it.mask <<= 1;
18225 now_it.mask &= 0x1f;
18226 is_last = (now_it.mask == 0x10);
5a01bb1d 18227 now_it.insn_cond = TRUE;
e07e6e58
NC
18228
18229 switch (inst.it_insn_type)
18230 {
18231 case OUTSIDE_IT_INSN:
18232 inst.error = BAD_NOT_IT;
18233 return FAIL;
18234
18235 case INSIDE_IT_INSN:
18236 if (cond != inst.cond)
18237 {
18238 inst.error = BAD_IT_COND;
18239 return FAIL;
18240 }
18241 break;
18242
18243 case INSIDE_IT_LAST_INSN:
18244 case IF_INSIDE_IT_LAST_INSN:
18245 if (cond != inst.cond)
18246 {
18247 inst.error = BAD_IT_COND;
18248 return FAIL;
18249 }
18250 if (!is_last)
18251 {
18252 inst.error = BAD_BRANCH;
18253 return FAIL;
18254 }
18255 break;
18256
18257 case NEUTRAL_IT_INSN:
18258 /* The BKPT instruction is unconditional even in an IT block. */
18259 break;
18260
18261 case IT_INSN:
18262 inst.error = BAD_IT_IT;
18263 return FAIL;
18264 }
18265 }
18266 break;
18267 }
18268
18269 return SUCCESS;
18270}
18271
5a01bb1d
MGD
18272struct depr_insn_mask
18273{
18274 unsigned long pattern;
18275 unsigned long mask;
18276 const char* description;
18277};
18278
18279/* List of 16-bit instruction patterns deprecated in an IT block in
18280 ARMv8. */
18281static const struct depr_insn_mask depr_it_insns[] = {
18282 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18283 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18284 { 0xa000, 0xb800, N_("ADR") },
18285 { 0x4800, 0xf800, N_("Literal loads") },
18286 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18287 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18288 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18289 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18290 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18291 { 0, 0, NULL }
18292};
18293
e07e6e58
NC
18294static void
18295it_fsm_post_encode (void)
18296{
18297 int is_last;
18298
18299 if (!now_it.state_handled)
18300 handle_it_state ();
18301
5a01bb1d
MGD
18302 if (now_it.insn_cond
18303 && !now_it.warn_deprecated
18304 && warn_on_deprecated
18305 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18306 {
18307 if (inst.instruction >= 0x10000)
18308 {
5c3696f8 18309 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18310 "deprecated in ARMv8"));
18311 now_it.warn_deprecated = TRUE;
18312 }
18313 else
18314 {
18315 const struct depr_insn_mask *p = depr_it_insns;
18316
18317 while (p->mask != 0)
18318 {
18319 if ((inst.instruction & p->mask) == p->pattern)
18320 {
5c3696f8 18321 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18322 "of the following class are deprecated in ARMv8: "
18323 "%s"), p->description);
18324 now_it.warn_deprecated = TRUE;
18325 break;
18326 }
18327
18328 ++p;
18329 }
18330 }
18331
18332 if (now_it.block_length > 1)
18333 {
5c3696f8 18334 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18335 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18336 now_it.warn_deprecated = TRUE;
18337 }
18338 }
18339
e07e6e58
NC
18340 is_last = (now_it.mask == 0x10);
18341 if (is_last)
18342 {
18343 now_it.state = OUTSIDE_IT_BLOCK;
18344 now_it.mask = 0;
18345 }
18346}
18347
18348static void
18349force_automatic_it_block_close (void)
18350{
18351 if (now_it.state == AUTOMATIC_IT_BLOCK)
18352 {
18353 close_automatic_it_block ();
18354 now_it.state = OUTSIDE_IT_BLOCK;
18355 now_it.mask = 0;
18356 }
18357}
18358
18359static int
18360in_it_block (void)
18361{
18362 if (!now_it.state_handled)
18363 handle_it_state ();
18364
18365 return now_it.state != OUTSIDE_IT_BLOCK;
18366}
18367
ff8646ee
TP
18368/* Whether OPCODE only has T32 encoding. Since this function is only used by
18369 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18370 here, hence the "known" in the function name. */
fc289b0a
TP
18371
18372static bfd_boolean
ff8646ee 18373known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18374{
18375 /* Original Thumb-1 wide instruction. */
18376 if (opcode->tencode == do_t_blx
18377 || opcode->tencode == do_t_branch23
18378 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18379 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18380 return TRUE;
18381
16a1fa25
TP
18382 /* Wide-only instruction added to ARMv8-M Baseline. */
18383 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18384 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18385 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18386 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18387 return TRUE;
18388
18389 return FALSE;
18390}
18391
18392/* Whether wide instruction variant can be used if available for a valid OPCODE
18393 in ARCH. */
18394
18395static bfd_boolean
18396t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18397{
18398 if (known_t32_only_insn (opcode))
18399 return TRUE;
18400
18401 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18402 of variant T3 of B.W is checked in do_t_branch. */
18403 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18404 && opcode->tencode == do_t_branch)
18405 return TRUE;
18406
bada4342
JW
18407 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18408 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18409 && opcode->tencode == do_t_mov_cmp
18410 /* Make sure CMP instruction is not affected. */
18411 && opcode->aencode == do_mov)
18412 return TRUE;
18413
ff8646ee
TP
18414 /* Wide instruction variants of all instructions with narrow *and* wide
18415 variants become available with ARMv6t2. Other opcodes are either
18416 narrow-only or wide-only and are thus available if OPCODE is valid. */
18417 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18418 return TRUE;
18419
18420 /* OPCODE with narrow only instruction variant or wide variant not
18421 available. */
fc289b0a
TP
18422 return FALSE;
18423}
18424
c19d1205
ZW
18425void
18426md_assemble (char *str)
b99bd4ef 18427{
c19d1205
ZW
18428 char *p = str;
18429 const struct asm_opcode * opcode;
b99bd4ef 18430
c19d1205
ZW
18431 /* Align the previous label if needed. */
18432 if (last_label_seen != NULL)
b99bd4ef 18433 {
c19d1205
ZW
18434 symbol_set_frag (last_label_seen, frag_now);
18435 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18436 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18437 }
18438
c19d1205
ZW
18439 memset (&inst, '\0', sizeof (inst));
18440 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18441
c19d1205
ZW
18442 opcode = opcode_lookup (&p);
18443 if (!opcode)
b99bd4ef 18444 {
c19d1205 18445 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18446 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18447 if (! create_register_alias (str, p)
477330fc 18448 && ! create_neon_reg_alias (str, p))
c19d1205 18449 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18450
b99bd4ef
NC
18451 return;
18452 }
18453
278df34e 18454 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18455 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18456
037e8744
JB
18457 /* The value which unconditional instructions should have in place of the
18458 condition field. */
18459 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18460
c19d1205 18461 if (thumb_mode)
b99bd4ef 18462 {
e74cfd16 18463 arm_feature_set variant;
8f06b2d8
PB
18464
18465 variant = cpu_variant;
18466 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18467 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18468 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18469 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18470 if (!opcode->tvariant
18471 || (thumb_mode == 1
18472 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18473 {
84b52b66 18474 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18475 return;
18476 }
c19d1205
ZW
18477 if (inst.cond != COND_ALWAYS && !unified_syntax
18478 && opcode->tencode != do_t_branch)
b99bd4ef 18479 {
c19d1205 18480 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18481 return;
18482 }
18483
fc289b0a
TP
18484 /* Two things are addressed here:
18485 1) Implicit require narrow instructions on Thumb-1.
18486 This avoids relaxation accidentally introducing Thumb-2
18487 instructions.
18488 2) Reject wide instructions in non Thumb-2 cores.
18489
18490 Only instructions with narrow and wide variants need to be handled
18491 but selecting all non wide-only instructions is easier. */
18492 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18493 && !t32_insn_ok (variant, opcode))
076d447c 18494 {
fc289b0a
TP
18495 if (inst.size_req == 0)
18496 inst.size_req = 2;
18497 else if (inst.size_req == 4)
752d5da4 18498 {
ff8646ee
TP
18499 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18500 as_bad (_("selected processor does not support 32bit wide "
18501 "variant of instruction `%s'"), str);
18502 else
18503 as_bad (_("selected processor does not support `%s' in "
18504 "Thumb-2 mode"), str);
fc289b0a 18505 return;
752d5da4 18506 }
076d447c
PB
18507 }
18508
c19d1205
ZW
18509 inst.instruction = opcode->tvalue;
18510
5be8be5d 18511 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18512 {
18513 /* Prepare the it_insn_type for those encodings that don't set
18514 it. */
18515 it_fsm_pre_encode ();
c19d1205 18516
477330fc 18517 opcode->tencode ();
e07e6e58 18518
477330fc
RM
18519 it_fsm_post_encode ();
18520 }
e27ec89e 18521
0110f2b8 18522 if (!(inst.error || inst.relax))
b99bd4ef 18523 {
9c2799c2 18524 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18525 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18526 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18527 {
c19d1205 18528 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18529 return;
18530 }
18531 }
076d447c
PB
18532
18533 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18534 instruction. */
9c2799c2 18535 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18536
e74cfd16
PB
18537 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18538 *opcode->tvariant);
ee065d83 18539 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18540 set those bits when Thumb-2 32-bit instructions are seen. The impact
18541 of relaxable instructions will be considered later after we finish all
18542 relaxation. */
ff8646ee
TP
18543 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18544 variant = arm_arch_none;
18545 else
18546 variant = cpu_variant;
18547 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18548 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18549 arm_ext_v6t2);
cd000bff 18550
88714cb8
DG
18551 check_neon_suffixes;
18552
cd000bff 18553 if (!inst.error)
c877a2f2
NC
18554 {
18555 mapping_state (MAP_THUMB);
18556 }
c19d1205 18557 }
3e9e4fcf 18558 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18559 {
845b51d6
PB
18560 bfd_boolean is_bx;
18561
18562 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18563 is_bx = (opcode->aencode == do_bx);
18564
c19d1205 18565 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18566 if (!(is_bx && fix_v4bx)
18567 && !(opcode->avariant &&
18568 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18569 {
84b52b66 18570 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18571 return;
b99bd4ef 18572 }
c19d1205 18573 if (inst.size_req)
b99bd4ef 18574 {
c19d1205
ZW
18575 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18576 return;
b99bd4ef
NC
18577 }
18578
c19d1205
ZW
18579 inst.instruction = opcode->avalue;
18580 if (opcode->tag == OT_unconditionalF)
eff0bc54 18581 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18582 else
18583 inst.instruction |= inst.cond << 28;
18584 inst.size = INSN_SIZE;
5be8be5d 18585 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18586 {
18587 it_fsm_pre_encode ();
18588 opcode->aencode ();
18589 it_fsm_post_encode ();
18590 }
ee065d83 18591 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18592 on a hypothetical non-thumb v5 core. */
845b51d6 18593 if (is_bx)
e74cfd16 18594 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18595 else
e74cfd16
PB
18596 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18597 *opcode->avariant);
88714cb8
DG
18598
18599 check_neon_suffixes;
18600
cd000bff 18601 if (!inst.error)
c877a2f2
NC
18602 {
18603 mapping_state (MAP_ARM);
18604 }
b99bd4ef 18605 }
3e9e4fcf
JB
18606 else
18607 {
18608 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18609 "-- `%s'"), str);
18610 return;
18611 }
c19d1205
ZW
18612 output_inst (str);
18613}
b99bd4ef 18614
e07e6e58
NC
18615static void
18616check_it_blocks_finished (void)
18617{
18618#ifdef OBJ_ELF
18619 asection *sect;
18620
18621 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18622 if (seg_info (sect)->tc_segment_info_data.current_it.state
18623 == MANUAL_IT_BLOCK)
18624 {
18625 as_warn (_("section '%s' finished with an open IT block."),
18626 sect->name);
18627 }
18628#else
18629 if (now_it.state == MANUAL_IT_BLOCK)
18630 as_warn (_("file finished with an open IT block."));
18631#endif
18632}
18633
c19d1205
ZW
18634/* Various frobbings of labels and their addresses. */
18635
18636void
18637arm_start_line_hook (void)
18638{
18639 last_label_seen = NULL;
b99bd4ef
NC
18640}
18641
c19d1205
ZW
18642void
18643arm_frob_label (symbolS * sym)
b99bd4ef 18644{
c19d1205 18645 last_label_seen = sym;
b99bd4ef 18646
c19d1205 18647 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18648
c19d1205
ZW
18649#if defined OBJ_COFF || defined OBJ_ELF
18650 ARM_SET_INTERWORK (sym, support_interwork);
18651#endif
b99bd4ef 18652
e07e6e58
NC
18653 force_automatic_it_block_close ();
18654
5f4273c7 18655 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18656 as Thumb functions. This is because these labels, whilst
18657 they exist inside Thumb code, are not the entry points for
18658 possible ARM->Thumb calls. Also, these labels can be used
18659 as part of a computed goto or switch statement. eg gcc
18660 can generate code that looks like this:
b99bd4ef 18661
c19d1205
ZW
18662 ldr r2, [pc, .Laaa]
18663 lsl r3, r3, #2
18664 ldr r2, [r3, r2]
18665 mov pc, r2
b99bd4ef 18666
c19d1205
ZW
18667 .Lbbb: .word .Lxxx
18668 .Lccc: .word .Lyyy
18669 ..etc...
18670 .Laaa: .word Lbbb
b99bd4ef 18671
c19d1205
ZW
18672 The first instruction loads the address of the jump table.
18673 The second instruction converts a table index into a byte offset.
18674 The third instruction gets the jump address out of the table.
18675 The fourth instruction performs the jump.
b99bd4ef 18676
c19d1205
ZW
18677 If the address stored at .Laaa is that of a symbol which has the
18678 Thumb_Func bit set, then the linker will arrange for this address
18679 to have the bottom bit set, which in turn would mean that the
18680 address computation performed by the third instruction would end
18681 up with the bottom bit set. Since the ARM is capable of unaligned
18682 word loads, the instruction would then load the incorrect address
18683 out of the jump table, and chaos would ensue. */
18684 if (label_is_thumb_function_name
18685 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18686 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18687 {
c19d1205
ZW
18688 /* When the address of a Thumb function is taken the bottom
18689 bit of that address should be set. This will allow
18690 interworking between Arm and Thumb functions to work
18691 correctly. */
b99bd4ef 18692
c19d1205 18693 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18694
c19d1205 18695 label_is_thumb_function_name = FALSE;
b99bd4ef 18696 }
07a53e5c 18697
07a53e5c 18698 dwarf2_emit_label (sym);
b99bd4ef
NC
18699}
18700
c921be7d 18701bfd_boolean
c19d1205 18702arm_data_in_code (void)
b99bd4ef 18703{
c19d1205 18704 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18705 {
c19d1205
ZW
18706 *input_line_pointer = '/';
18707 input_line_pointer += 5;
18708 *input_line_pointer = 0;
c921be7d 18709 return TRUE;
b99bd4ef
NC
18710 }
18711
c921be7d 18712 return FALSE;
b99bd4ef
NC
18713}
18714
c19d1205
ZW
18715char *
18716arm_canonicalize_symbol_name (char * name)
b99bd4ef 18717{
c19d1205 18718 int len;
b99bd4ef 18719
c19d1205
ZW
18720 if (thumb_mode && (len = strlen (name)) > 5
18721 && streq (name + len - 5, "/data"))
18722 *(name + len - 5) = 0;
b99bd4ef 18723
c19d1205 18724 return name;
b99bd4ef 18725}
c19d1205
ZW
18726\f
18727/* Table of all register names defined by default. The user can
18728 define additional names with .req. Note that all register names
18729 should appear in both upper and lowercase variants. Some registers
18730 also have mixed-case names. */
b99bd4ef 18731
dcbf9037 18732#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18733#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18734#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18735#define REGSET(p,t) \
18736 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18737 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18738 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18739 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18740#define REGSETH(p,t) \
18741 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18742 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18743 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18744 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18745#define REGSET2(p,t) \
18746 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18747 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18748 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18749 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18750#define SPLRBANK(base,bank,t) \
18751 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18752 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18753 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18754 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18755 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18756 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18757
c19d1205 18758static const struct reg_entry reg_names[] =
7ed4c4c5 18759{
c19d1205
ZW
18760 /* ARM integer registers. */
18761 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18762
c19d1205
ZW
18763 /* ATPCS synonyms. */
18764 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18765 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18766 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18767
c19d1205
ZW
18768 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18769 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18770 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18771
c19d1205
ZW
18772 /* Well-known aliases. */
18773 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18774 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18775
18776 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18777 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18778
18779 /* Coprocessor numbers. */
18780 REGSET(p, CP), REGSET(P, CP),
18781
18782 /* Coprocessor register numbers. The "cr" variants are for backward
18783 compatibility. */
18784 REGSET(c, CN), REGSET(C, CN),
18785 REGSET(cr, CN), REGSET(CR, CN),
18786
90ec0d68
MGD
18787 /* ARM banked registers. */
18788 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18789 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18790 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18791 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18792 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18793 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18794 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18795
18796 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18797 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18798 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18799 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18800 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18801 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18802 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18803 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18804
18805 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18806 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18807 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18808 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18809 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18810 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18811 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18812 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18813 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18814
c19d1205
ZW
18815 /* FPA registers. */
18816 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18817 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18818
18819 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18820 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18821
18822 /* VFP SP registers. */
5287ad62
JB
18823 REGSET(s,VFS), REGSET(S,VFS),
18824 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18825
18826 /* VFP DP Registers. */
5287ad62
JB
18827 REGSET(d,VFD), REGSET(D,VFD),
18828 /* Extra Neon DP registers. */
18829 REGSETH(d,VFD), REGSETH(D,VFD),
18830
18831 /* Neon QP registers. */
18832 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18833
18834 /* VFP control registers. */
18835 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18836 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18837 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18838 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18839 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18840 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18841
18842 /* Maverick DSP coprocessor registers. */
18843 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18844 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18845
18846 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18847 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18848 REGDEF(dspsc,0,DSPSC),
18849
18850 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18851 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18852 REGDEF(DSPSC,0,DSPSC),
18853
18854 /* iWMMXt data registers - p0, c0-15. */
18855 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18856
18857 /* iWMMXt control registers - p1, c0-3. */
18858 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18859 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18860 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18861 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18862
18863 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18864 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18865 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18866 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18867 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18868
18869 /* XScale accumulator registers. */
18870 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18871};
18872#undef REGDEF
18873#undef REGNUM
18874#undef REGSET
7ed4c4c5 18875
c19d1205
ZW
18876/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18877 within psr_required_here. */
18878static const struct asm_psr psrs[] =
18879{
18880 /* Backward compatibility notation. Note that "all" is no longer
18881 truly all possible PSR bits. */
18882 {"all", PSR_c | PSR_f},
18883 {"flg", PSR_f},
18884 {"ctl", PSR_c},
18885
18886 /* Individual flags. */
18887 {"f", PSR_f},
18888 {"c", PSR_c},
18889 {"x", PSR_x},
18890 {"s", PSR_s},
59b42a0d 18891
c19d1205
ZW
18892 /* Combinations of flags. */
18893 {"fs", PSR_f | PSR_s},
18894 {"fx", PSR_f | PSR_x},
18895 {"fc", PSR_f | PSR_c},
18896 {"sf", PSR_s | PSR_f},
18897 {"sx", PSR_s | PSR_x},
18898 {"sc", PSR_s | PSR_c},
18899 {"xf", PSR_x | PSR_f},
18900 {"xs", PSR_x | PSR_s},
18901 {"xc", PSR_x | PSR_c},
18902 {"cf", PSR_c | PSR_f},
18903 {"cs", PSR_c | PSR_s},
18904 {"cx", PSR_c | PSR_x},
18905 {"fsx", PSR_f | PSR_s | PSR_x},
18906 {"fsc", PSR_f | PSR_s | PSR_c},
18907 {"fxs", PSR_f | PSR_x | PSR_s},
18908 {"fxc", PSR_f | PSR_x | PSR_c},
18909 {"fcs", PSR_f | PSR_c | PSR_s},
18910 {"fcx", PSR_f | PSR_c | PSR_x},
18911 {"sfx", PSR_s | PSR_f | PSR_x},
18912 {"sfc", PSR_s | PSR_f | PSR_c},
18913 {"sxf", PSR_s | PSR_x | PSR_f},
18914 {"sxc", PSR_s | PSR_x | PSR_c},
18915 {"scf", PSR_s | PSR_c | PSR_f},
18916 {"scx", PSR_s | PSR_c | PSR_x},
18917 {"xfs", PSR_x | PSR_f | PSR_s},
18918 {"xfc", PSR_x | PSR_f | PSR_c},
18919 {"xsf", PSR_x | PSR_s | PSR_f},
18920 {"xsc", PSR_x | PSR_s | PSR_c},
18921 {"xcf", PSR_x | PSR_c | PSR_f},
18922 {"xcs", PSR_x | PSR_c | PSR_s},
18923 {"cfs", PSR_c | PSR_f | PSR_s},
18924 {"cfx", PSR_c | PSR_f | PSR_x},
18925 {"csf", PSR_c | PSR_s | PSR_f},
18926 {"csx", PSR_c | PSR_s | PSR_x},
18927 {"cxf", PSR_c | PSR_x | PSR_f},
18928 {"cxs", PSR_c | PSR_x | PSR_s},
18929 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18930 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18931 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18932 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18933 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18934 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18935 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18936 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18937 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18938 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18939 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18940 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18941 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18942 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18943 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18944 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18945 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18946 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18947 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18948 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18949 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18950 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18951 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18952 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18953};
18954
62b3e311
PB
18955/* Table of V7M psr names. */
18956static const struct asm_psr v7m_psrs[] =
18957{
1a336194
TP
18958 {"apsr", 0x0 }, {"APSR", 0x0 },
18959 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
18960 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
18961 {"psr", 0x3 }, {"PSR", 0x3 },
18962 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
18963 {"ipsr", 0x5 }, {"IPSR", 0x5 },
18964 {"epsr", 0x6 }, {"EPSR", 0x6 },
18965 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
18966 {"msp", 0x8 }, {"MSP", 0x8 },
18967 {"psp", 0x9 }, {"PSP", 0x9 },
18968 {"msplim", 0xa }, {"MSPLIM", 0xa },
18969 {"psplim", 0xb }, {"PSPLIM", 0xb },
18970 {"primask", 0x10}, {"PRIMASK", 0x10},
18971 {"basepri", 0x11}, {"BASEPRI", 0x11},
18972 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
18973 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
18974 {"control", 0x14}, {"CONTROL", 0x14},
18975 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18976 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
18977 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
18978 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
18979 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
18980 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
18981 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
18982 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
18983 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
18984};
18985
c19d1205
ZW
18986/* Table of all shift-in-operand names. */
18987static const struct asm_shift_name shift_names [] =
b99bd4ef 18988{
c19d1205
ZW
18989 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18990 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18991 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18992 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18993 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18994 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18995};
b99bd4ef 18996
c19d1205
ZW
18997/* Table of all explicit relocation names. */
18998#ifdef OBJ_ELF
18999static struct reloc_entry reloc_names[] =
19000{
19001 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19002 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19003 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19004 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19005 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19006 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19007 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19008 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19009 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19010 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19011 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19012 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19013 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19014 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19015 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19016 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19017 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19018 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19019};
19020#endif
b99bd4ef 19021
c19d1205
ZW
19022/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19023static const struct asm_cond conds[] =
19024{
19025 {"eq", 0x0},
19026 {"ne", 0x1},
19027 {"cs", 0x2}, {"hs", 0x2},
19028 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19029 {"mi", 0x4},
19030 {"pl", 0x5},
19031 {"vs", 0x6},
19032 {"vc", 0x7},
19033 {"hi", 0x8},
19034 {"ls", 0x9},
19035 {"ge", 0xa},
19036 {"lt", 0xb},
19037 {"gt", 0xc},
19038 {"le", 0xd},
19039 {"al", 0xe}
19040};
bfae80f2 19041
e797f7e0 19042#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19043 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19044 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19045
62b3e311
PB
19046static struct asm_barrier_opt barrier_opt_names[] =
19047{
e797f7e0
MGD
19048 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19049 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19050 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19051 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19052 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19053 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19054 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19055 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19056 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19057 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19058 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19059 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19060 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19061 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19062 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19063 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19064};
19065
e797f7e0
MGD
19066#undef UL_BARRIER
19067
c19d1205
ZW
19068/* Table of ARM-format instructions. */
19069
19070/* Macros for gluing together operand strings. N.B. In all cases
19071 other than OPS0, the trailing OP_stop comes from default
19072 zero-initialization of the unspecified elements of the array. */
19073#define OPS0() { OP_stop, }
19074#define OPS1(a) { OP_##a, }
19075#define OPS2(a,b) { OP_##a,OP_##b, }
19076#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19077#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19078#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19079#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19080
5be8be5d
DG
19081/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19082 This is useful when mixing operands for ARM and THUMB, i.e. using the
19083 MIX_ARM_THUMB_OPERANDS macro.
19084 In order to use these macros, prefix the number of operands with _
19085 e.g. _3. */
19086#define OPS_1(a) { a, }
19087#define OPS_2(a,b) { a,b, }
19088#define OPS_3(a,b,c) { a,b,c, }
19089#define OPS_4(a,b,c,d) { a,b,c,d, }
19090#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19091#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19092
c19d1205
ZW
19093/* These macros abstract out the exact format of the mnemonic table and
19094 save some repeated characters. */
19095
19096/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19097#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19098 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19099 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19100
19101/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19102 a T_MNEM_xyz enumerator. */
19103#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19104 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19105#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19106 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19107
19108/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19109 infix after the third character. */
19110#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19111 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19112 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19113#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19114 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19115 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19116#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19117 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19118#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19119 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19120#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19121 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19122#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19123 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19124
c19d1205 19125/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19126 field is still 0xE. Many of the Thumb variants can be executed
19127 conditionally, so this is checked separately. */
c19d1205 19128#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19129 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19130 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19131
dd5181d5
KT
19132/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19133 Used by mnemonics that have very minimal differences in the encoding for
19134 ARM and Thumb variants and can be handled in a common function. */
19135#define TUEc(mnem, op, top, nops, ops, en) \
19136 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19137 THUMB_VARIANT, do_##en, do_##en }
19138
c19d1205
ZW
19139/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19140 condition code field. */
19141#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19142 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19143 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19144
19145/* ARM-only variants of all the above. */
6a86118a 19146#define CE(mnem, op, nops, ops, ae) \
21d799b5 19147 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19148
19149#define C3(mnem, op, nops, ops, ae) \
19150 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19151
e3cb604e
PB
19152/* Legacy mnemonics that always have conditional infix after the third
19153 character. */
19154#define CL(mnem, op, nops, ops, ae) \
21d799b5 19155 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19156 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19157
8f06b2d8
PB
19158/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19159#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19160 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19161
e3cb604e
PB
19162/* Legacy coprocessor instructions where conditional infix and conditional
19163 suffix are ambiguous. For consistency this includes all FPA instructions,
19164 not just the potentially ambiguous ones. */
19165#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19166 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19167 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19168
19169/* Coprocessor, takes either a suffix or a position-3 infix
19170 (for an FPA corner case). */
19171#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19172 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19173 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19174
6a86118a 19175#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19176 { m1 #m2 m3, OPS##nops ops, \
19177 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19178 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19179
19180#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19181 xCM_ (m1, , m2, op, nops, ops, ae), \
19182 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19183 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19184 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19185 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19186 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19187 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19188 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19189 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19190 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19191 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19192 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19193 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19194 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19195 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19196 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19197 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19198 xCM_ (m1, le, m2, op, nops, ops, ae), \
19199 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19200
19201#define UE(mnem, op, nops, ops, ae) \
19202 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19203
19204#define UF(mnem, op, nops, ops, ae) \
19205 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19206
5287ad62
JB
19207/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19208 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19209 use the same encoding function for each. */
19210#define NUF(mnem, op, nops, ops, enc) \
19211 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19212 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19213
19214/* Neon data processing, version which indirects through neon_enc_tab for
19215 the various overloaded versions of opcodes. */
19216#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19217 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19218 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19219
19220/* Neon insn with conditional suffix for the ARM version, non-overloaded
19221 version. */
037e8744
JB
19222#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19223 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19224 THUMB_VARIANT, do_##enc, do_##enc }
19225
037e8744 19226#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19227 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19228
19229#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19230 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19231
5287ad62 19232/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19233#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19234 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19235 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19236
037e8744 19237#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19238 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19239
19240#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19241 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19242
c19d1205
ZW
19243#define do_0 0
19244
c19d1205 19245static const struct asm_opcode insns[] =
bfae80f2 19246{
74db7efb
NC
19247#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19248#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19249 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19250 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19251 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19252 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19253 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19254 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19255 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19256 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19257 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19258 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19259 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19260 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19261 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19262 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19263 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19264 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19265
19266 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19267 for setting PSR flag bits. They are obsolete in V6 and do not
19268 have Thumb equivalents. */
21d799b5
NC
19269 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19270 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19271 CL("tstp", 110f000, 2, (RR, SH), cmp),
19272 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19273 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19274 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19275 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19276 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19277 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19278
19279 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19280 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19281 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19282 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19283
19284 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19285 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19286 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19287 OP_RRnpc),
19288 OP_ADDRGLDR),ldst, t_ldst),
19289 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19290
19291 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19292 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19293 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19294 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19295 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19296 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19297
19298 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19299 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19300 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19301 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19302
c19d1205 19303 /* Pseudo ops. */
21d799b5 19304 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19305 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19306 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19307 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19308
19309 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19310 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19311 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19312 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19313 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19314 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19315 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19316 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19317 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19318 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19319 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19320 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19321 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19322
16a4cf17 19323 /* These may simplify to neg. */
21d799b5
NC
19324 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19325 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19326
c921be7d
NC
19327#undef THUMB_VARIANT
19328#define THUMB_VARIANT & arm_ext_v6
19329
21d799b5 19330 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19331
19332 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19333#undef THUMB_VARIANT
19334#define THUMB_VARIANT & arm_ext_v6t2
19335
21d799b5
NC
19336 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19337 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19338 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19339
5be8be5d
DG
19340 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19341 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19342 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19343 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19344
21d799b5
NC
19345 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19346 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19347
21d799b5
NC
19348 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19349 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19350
19351 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19352 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19353 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19354
19355 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19356 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19357 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19358 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19359 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19360 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19361 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19362 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19363
c921be7d
NC
19364#undef ARM_VARIANT
19365#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19366#undef THUMB_VARIANT
19367#define THUMB_VARIANT & arm_ext_v4t
19368
21d799b5
NC
19369 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19370 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19371
c921be7d
NC
19372#undef THUMB_VARIANT
19373#define THUMB_VARIANT & arm_ext_v6t2
19374
21d799b5 19375 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19376 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19377
19378 /* Generic coprocessor instructions. */
21d799b5
NC
19379 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19380 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19381 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19382 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19383 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19384 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19385 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19386
c921be7d
NC
19387#undef ARM_VARIANT
19388#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19389
21d799b5 19390 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19391 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19392
c921be7d
NC
19393#undef ARM_VARIANT
19394#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19395#undef THUMB_VARIANT
19396#define THUMB_VARIANT & arm_ext_msr
19397
d2cd1205
JB
19398 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19399 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19400
c921be7d
NC
19401#undef ARM_VARIANT
19402#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19403#undef THUMB_VARIANT
19404#define THUMB_VARIANT & arm_ext_v6t2
19405
21d799b5
NC
19406 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19407 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19408 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19409 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19410 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19411 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19412 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19413 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19414
c921be7d
NC
19415#undef ARM_VARIANT
19416#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19417#undef THUMB_VARIANT
19418#define THUMB_VARIANT & arm_ext_v4t
19419
5be8be5d
DG
19420 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19421 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19422 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19423 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19424 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19425 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19426
c921be7d
NC
19427#undef ARM_VARIANT
19428#define ARM_VARIANT & arm_ext_v4t_5
19429
c19d1205
ZW
19430 /* ARM Architecture 4T. */
19431 /* Note: bx (and blx) are required on V5, even if the processor does
19432 not support Thumb. */
21d799b5 19433 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19434
c921be7d
NC
19435#undef ARM_VARIANT
19436#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19437#undef THUMB_VARIANT
19438#define THUMB_VARIANT & arm_ext_v5t
19439
c19d1205
ZW
19440 /* Note: blx has 2 variants; the .value coded here is for
19441 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19442 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19443 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19444
c921be7d
NC
19445#undef THUMB_VARIANT
19446#define THUMB_VARIANT & arm_ext_v6t2
19447
21d799b5
NC
19448 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19449 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19450 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19451 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19452 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19453 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19454 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19455 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19456
c921be7d 19457#undef ARM_VARIANT
74db7efb
NC
19458#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19459#undef THUMB_VARIANT
19460#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19461
21d799b5
NC
19462 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19463 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19464 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19465 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19466
21d799b5
NC
19467 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19468 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19469
21d799b5
NC
19470 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19471 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19472 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19473 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19474
21d799b5
NC
19475 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19476 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19477 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19478 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19479
21d799b5
NC
19480 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19481 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19482
03ee1b7f
NC
19483 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19484 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19485 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19486 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19487
c921be7d 19488#undef ARM_VARIANT
74db7efb
NC
19489#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19490#undef THUMB_VARIANT
19491#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19492
21d799b5 19493 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19494 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19495 ldrd, t_ldstd),
19496 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19497 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19498
21d799b5
NC
19499 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19500 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19501
c921be7d
NC
19502#undef ARM_VARIANT
19503#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19504
21d799b5 19505 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19506
c921be7d
NC
19507#undef ARM_VARIANT
19508#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19509#undef THUMB_VARIANT
19510#define THUMB_VARIANT & arm_ext_v6
19511
21d799b5
NC
19512 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19513 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19514 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19515 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19516 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19517 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19518 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19519 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19520 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19521 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19522
c921be7d 19523#undef THUMB_VARIANT
ff8646ee 19524#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19525
5be8be5d
DG
19526 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19527 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19528 strex, t_strex),
ff8646ee
TP
19529#undef THUMB_VARIANT
19530#define THUMB_VARIANT & arm_ext_v6t2
19531
21d799b5
NC
19532 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19533 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19534
21d799b5
NC
19535 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19536 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19537
9e3c6df6 19538/* ARM V6 not included in V7M. */
c921be7d
NC
19539#undef THUMB_VARIANT
19540#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19541 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19542 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19543 UF(rfeib, 9900a00, 1, (RRw), rfe),
19544 UF(rfeda, 8100a00, 1, (RRw), rfe),
19545 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19546 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19547 UF(rfefa, 8100a00, 1, (RRw), rfe),
19548 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19549 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19550 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19551 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19552 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19553 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19554 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19555 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19556 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19557 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19558 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19559 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19560
9e3c6df6
PB
19561/* ARM V6 not included in V7M (eg. integer SIMD). */
19562#undef THUMB_VARIANT
19563#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19564 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19565 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19566 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19567 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19568 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19569 /* Old name for QASX. */
74db7efb 19570 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19571 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19572 /* Old name for QSAX. */
74db7efb 19573 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19574 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19575 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19576 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19577 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19578 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19579 /* Old name for SASX. */
74db7efb 19580 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19581 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19582 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19583 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19584 /* Old name for SHASX. */
21d799b5 19585 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19586 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19587 /* Old name for SHSAX. */
21d799b5
NC
19588 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19589 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19590 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19591 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19592 /* Old name for SSAX. */
74db7efb 19593 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19594 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19595 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19596 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19597 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19598 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19599 /* Old name for UASX. */
74db7efb 19600 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19601 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19602 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19603 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19604 /* Old name for UHASX. */
21d799b5
NC
19605 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19606 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19607 /* Old name for UHSAX. */
21d799b5
NC
19608 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19609 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19610 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19611 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19612 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19613 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19614 /* Old name for UQASX. */
21d799b5
NC
19615 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19616 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19617 /* Old name for UQSAX. */
21d799b5
NC
19618 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19619 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19620 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19621 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19622 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19623 /* Old name for USAX. */
74db7efb 19624 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19625 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19626 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19627 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19628 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19629 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19630 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19631 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19632 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19633 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19634 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19635 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19636 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19637 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19638 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19639 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19640 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19641 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19642 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19643 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19644 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19645 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19646 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19647 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19648 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19649 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19650 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19651 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19652 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19653 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19654 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19655 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19656 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19657 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19658
c921be7d
NC
19659#undef ARM_VARIANT
19660#define ARM_VARIANT & arm_ext_v6k
19661#undef THUMB_VARIANT
19662#define THUMB_VARIANT & arm_ext_v6k
19663
21d799b5
NC
19664 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19665 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19666 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19667 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19668
c921be7d
NC
19669#undef THUMB_VARIANT
19670#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19671 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19672 ldrexd, t_ldrexd),
19673 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19674 RRnpcb), strexd, t_strexd),
ebdca51a 19675
c921be7d 19676#undef THUMB_VARIANT
ff8646ee 19677#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19678 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19679 rd_rn, rd_rn),
19680 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19681 rd_rn, rd_rn),
19682 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19683 strex, t_strexbh),
5be8be5d 19684 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19685 strex, t_strexbh),
21d799b5 19686 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19687
c921be7d 19688#undef ARM_VARIANT
f4c65163 19689#define ARM_VARIANT & arm_ext_sec
74db7efb 19690#undef THUMB_VARIANT
f4c65163 19691#define THUMB_VARIANT & arm_ext_sec
c921be7d 19692
21d799b5 19693 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19694
90ec0d68
MGD
19695#undef ARM_VARIANT
19696#define ARM_VARIANT & arm_ext_virt
19697#undef THUMB_VARIANT
19698#define THUMB_VARIANT & arm_ext_virt
19699
19700 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19701 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19702
ddfded2f
MW
19703#undef ARM_VARIANT
19704#define ARM_VARIANT & arm_ext_pan
19705#undef THUMB_VARIANT
19706#define THUMB_VARIANT & arm_ext_pan
19707
19708 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19709
c921be7d 19710#undef ARM_VARIANT
74db7efb 19711#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19712#undef THUMB_VARIANT
19713#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19714
21d799b5
NC
19715 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19716 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19717 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19718 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19719
21d799b5 19720 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19721 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19722
5be8be5d
DG
19723 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19724 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19725 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19726 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19727
ff8646ee
TP
19728#undef THUMB_VARIANT
19729#define THUMB_VARIANT & arm_ext_v6t2_v8m
19730 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19731 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19732
bf3eeda7 19733 /* Thumb-only instructions. */
74db7efb 19734#undef ARM_VARIANT
bf3eeda7
NS
19735#define ARM_VARIANT NULL
19736 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19737 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19738
19739 /* ARM does not really have an IT instruction, so always allow it.
19740 The opcode is copied from Thumb in order to allow warnings in
19741 -mimplicit-it=[never | arm] modes. */
19742#undef ARM_VARIANT
19743#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19744#undef THUMB_VARIANT
19745#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19746
21d799b5
NC
19747 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19748 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19749 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19750 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19751 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19752 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19753 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19754 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19755 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19756 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19757 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19758 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19759 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19760 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19761 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19762 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19763 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19764 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19765
92e90b6e 19766 /* Thumb2 only instructions. */
c921be7d
NC
19767#undef ARM_VARIANT
19768#define ARM_VARIANT NULL
92e90b6e 19769
21d799b5
NC
19770 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19771 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19772 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19773 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19774 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19775 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19776
eea54501
MGD
19777 /* Hardware division instructions. */
19778#undef ARM_VARIANT
19779#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19780#undef THUMB_VARIANT
19781#define THUMB_VARIANT & arm_ext_div
19782
eea54501
MGD
19783 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19784 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19785
7e806470 19786 /* ARM V6M/V7 instructions. */
c921be7d
NC
19787#undef ARM_VARIANT
19788#define ARM_VARIANT & arm_ext_barrier
19789#undef THUMB_VARIANT
19790#define THUMB_VARIANT & arm_ext_barrier
19791
ccb84d65
JB
19792 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19793 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19794 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19795
62b3e311 19796 /* ARM V7 instructions. */
c921be7d
NC
19797#undef ARM_VARIANT
19798#define ARM_VARIANT & arm_ext_v7
19799#undef THUMB_VARIANT
19800#define THUMB_VARIANT & arm_ext_v7
19801
21d799b5
NC
19802 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19803 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19804
74db7efb 19805#undef ARM_VARIANT
60e5ef9f 19806#define ARM_VARIANT & arm_ext_mp
74db7efb 19807#undef THUMB_VARIANT
60e5ef9f
MGD
19808#define THUMB_VARIANT & arm_ext_mp
19809
19810 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19811
53c4b28b
MGD
19812 /* AArchv8 instructions. */
19813#undef ARM_VARIANT
19814#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19815
19816/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19817#undef THUMB_VARIANT
4ed7ed8d 19818#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19819
4ed7ed8d
TP
19820 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19821 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19822 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19823 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19824 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19825 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19826 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19827 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19828 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19829 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19830 stlex, t_stlex),
4b8c8c02
RE
19831 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19832 stlex, t_stlex),
19833 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19834 stlex, t_stlex),
4ed7ed8d
TP
19835#undef THUMB_VARIANT
19836#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19837
4ed7ed8d
TP
19838 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19839 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19840 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19841 ldrexd, t_ldrexd),
19842 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19843 strexd, t_strexd),
8884b720 19844 /* ARMv8 T32 only. */
74db7efb 19845#undef ARM_VARIANT
b79f7053
MGD
19846#define ARM_VARIANT NULL
19847 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19848 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19849 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19850
33399f07
MGD
19851 /* FP for ARMv8. */
19852#undef ARM_VARIANT
a715796b 19853#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19854#undef THUMB_VARIANT
a715796b 19855#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19856
19857 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19858 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19859 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19860 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19861 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19862 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19863 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19864 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19865 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19866 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19867 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19868 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19869 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19870 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19871 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19872 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19873 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19874
91ff7894
MGD
19875 /* Crypto v1 extensions. */
19876#undef ARM_VARIANT
19877#define ARM_VARIANT & fpu_crypto_ext_armv8
19878#undef THUMB_VARIANT
19879#define THUMB_VARIANT & fpu_crypto_ext_armv8
19880
19881 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19882 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19883 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19884 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19885 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19886 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19887 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19888 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19889 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19890 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19891 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19892 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19893 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19894 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19895
dd5181d5 19896#undef ARM_VARIANT
74db7efb 19897#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19898#undef THUMB_VARIANT
19899#define THUMB_VARIANT & crc_ext_armv8
19900 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19901 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19902 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19903 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19904 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19905 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19906
105bde57
MW
19907 /* ARMv8.2 RAS extension. */
19908#undef ARM_VARIANT
4d1464f2 19909#define ARM_VARIANT & arm_ext_ras
105bde57 19910#undef THUMB_VARIANT
4d1464f2 19911#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19912 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19913
49e8a725
SN
19914#undef ARM_VARIANT
19915#define ARM_VARIANT & arm_ext_v8_3
19916#undef THUMB_VARIANT
19917#define THUMB_VARIANT & arm_ext_v8_3
19918 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
19919 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
19920 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 19921
c921be7d
NC
19922#undef ARM_VARIANT
19923#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19924#undef THUMB_VARIANT
19925#define THUMB_VARIANT NULL
c921be7d 19926
21d799b5
NC
19927 cCE("wfs", e200110, 1, (RR), rd),
19928 cCE("rfs", e300110, 1, (RR), rd),
19929 cCE("wfc", e400110, 1, (RR), rd),
19930 cCE("rfc", e500110, 1, (RR), rd),
19931
19932 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19933 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19934 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19935 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19936
19937 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19938 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19939 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19940 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19941
19942 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19943 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19944 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19945 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19946 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19947 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19948 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19949 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19950 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19951 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19952 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19953 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19954
19955 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19956 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19957 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19958 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19959 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19960 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19961 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19962 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19963 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19964 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19965 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19966 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19967
19968 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19969 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19970 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19971 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19972 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19973 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19974 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19975 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19976 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19977 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19978 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19979 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19980
19981 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19982 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19983 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19984 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19985 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19986 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19987 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19988 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19989 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19990 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19991 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19992 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19993
19994 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19995 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19996 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19997 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19998 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19999 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20000 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20001 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20002 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20003 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20004 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20005 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20006
20007 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20008 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20009 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20010 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20011 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20012 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20013 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20014 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20015 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20016 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20017 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20018 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20019
20020 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20021 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20022 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20023 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20024 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20025 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20026 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20027 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20028 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20029 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20030 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20031 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20032
20033 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20034 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20035 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20036 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20037 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20038 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20039 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20040 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20041 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20042 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20043 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20044 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20045
20046 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20047 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20048 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20049 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20050 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20051 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20052 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20053 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20054 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20055 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20056 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20057 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20058
20059 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20060 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20061 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20062 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20063 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20064 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20065 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20066 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20067 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20068 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20069 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20070 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20071
20072 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20073 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20074 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20075 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20076 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20077 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20078 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20079 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20080 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20081 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20082 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20083 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20084
20085 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20086 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20087 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20088 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20089 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20090 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20091 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20092 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20093 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20094 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20095 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20096 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20097
20098 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20099 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20100 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20101 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20102 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20103 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20104 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20105 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20106 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20107 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20108 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20109 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20110
20111 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20112 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20113 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20114 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20115 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20116 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20117 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20118 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20119 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20120 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20121 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20122 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20123
20124 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20125 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20126 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20127 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20128 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20129 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20130 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20131 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20132 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20133 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20134 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20135 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20136
20137 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20138 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20139 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20140 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20141 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20142 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20143 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20144 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20145 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20146 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20147 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20148 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20149
20150 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20151 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20152 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20153 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20154 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20155 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20156 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20157 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20158 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20159 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20160 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20161 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20162
20163 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20164 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20165 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20166 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20167 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20168 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20169 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20170 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20171 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20172 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20173 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20174 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20175
20176 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20177 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20178 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20179 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20180 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20181 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20182 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20183 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20184 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20185 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20186 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20187 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20188
20189 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20190 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20191 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20192 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20193 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20194 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20195 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20196 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20197 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20198 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20199 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20200 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20201
20202 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20203 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20204 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20205 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20206 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20207 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20208 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20209 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20210 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20211 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20212 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20213 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20214
20215 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20216 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20217 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20218 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20219 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20220 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20221 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20222 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20223 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20224 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20225 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20226 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20227
20228 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20229 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20230 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20231 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20232 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20233 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20234 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20235 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20236 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20237 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20238 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20239 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20240
20241 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20242 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20243 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20244 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20245 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20246 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20247 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20248 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20249 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20250 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20251 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20253
20254 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20255 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20257 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20258 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20262 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20263 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20264 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20266
20267 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20268 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20270 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20271 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20275 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20276 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20277 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20279
20280 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20281 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20283 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20284 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20285 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20286 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20287 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20288 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20289 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20290 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20291 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20292
20293 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20294 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20295 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20296 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20297 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20298 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20299 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20300 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20301 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20302 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20303 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20304 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20305
20306 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20307 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20308 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20309 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20310 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20311 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20312 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20313 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20314 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20315 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20316 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20317 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20318
20319 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20320 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20321 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20322 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20323
20324 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20325 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20326 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20327 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20328 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20329 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20330 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20331 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20332 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20333 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20334 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20335 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20336
c19d1205
ZW
20337 /* The implementation of the FIX instruction is broken on some
20338 assemblers, in that it accepts a precision specifier as well as a
20339 rounding specifier, despite the fact that this is meaningless.
20340 To be more compatible, we accept it as well, though of course it
20341 does not set any bits. */
21d799b5
NC
20342 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20343 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20344 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20345 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20346 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20347 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20348 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20349 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20350 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20351 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20352 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20353 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20354 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20355
c19d1205 20356 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20357#undef ARM_VARIANT
20358#define ARM_VARIANT & fpu_fpa_ext_v2
20359
21d799b5
NC
20360 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20361 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20362 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20363 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20364 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20365 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20366
c921be7d
NC
20367#undef ARM_VARIANT
20368#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20369
c19d1205 20370 /* Moves and type conversions. */
21d799b5
NC
20371 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20372 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20373 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20374 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20375 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20376 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20377 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20378 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20379 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20380 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20381 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20382 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20383 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20384 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20385
20386 /* Memory operations. */
21d799b5
NC
20387 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20388 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20389 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20390 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20391 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20392 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20393 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20394 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20395 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20396 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20397 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20398 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20399 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20400 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20401 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20402 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20403 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20404 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20405
c19d1205 20406 /* Monadic operations. */
21d799b5
NC
20407 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20408 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20409 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20410
20411 /* Dyadic operations. */
21d799b5
NC
20412 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20413 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20414 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20415 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20416 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20417 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20418 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20419 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20420 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20421
c19d1205 20422 /* Comparisons. */
21d799b5
NC
20423 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20424 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20425 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20426 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20427
62f3b8c8
PB
20428 /* Double precision load/store are still present on single precision
20429 implementations. */
20430 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20431 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20432 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20433 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20434 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20435 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20436 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20437 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20438 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20439 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20440
c921be7d
NC
20441#undef ARM_VARIANT
20442#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20443
c19d1205 20444 /* Moves and type conversions. */
21d799b5
NC
20445 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20446 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20447 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20448 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20449 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20450 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20451 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20452 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20453 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20454 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20455 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20456 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20457 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20458
c19d1205 20459 /* Monadic operations. */
21d799b5
NC
20460 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20461 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20462 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20463
20464 /* Dyadic operations. */
21d799b5
NC
20465 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20466 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20467 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20468 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20469 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20470 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20471 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20472 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20473 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20474
c19d1205 20475 /* Comparisons. */
21d799b5
NC
20476 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20477 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20478 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20479 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20480
c921be7d
NC
20481#undef ARM_VARIANT
20482#define ARM_VARIANT & fpu_vfp_ext_v2
20483
21d799b5
NC
20484 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20485 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20486 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20487 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20488
037e8744
JB
20489/* Instructions which may belong to either the Neon or VFP instruction sets.
20490 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20491#undef ARM_VARIANT
20492#define ARM_VARIANT & fpu_vfp_ext_v1xd
20493#undef THUMB_VARIANT
20494#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20495
037e8744
JB
20496 /* These mnemonics are unique to VFP. */
20497 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20498 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20499 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20500 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20501 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20502 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20503 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20504 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20505 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20506 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20507
20508 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20509 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20510 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20511 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20512
21d799b5
NC
20513 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20514 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20515
20516 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20517 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20518
55881a11
MGD
20519 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20520 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20521 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20522 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20523 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20524 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20525 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20526 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20527
5f1af56b 20528 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20529 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20530 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20531 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20532
037e8744
JB
20533
20534 /* NOTE: All VMOV encoding is special-cased! */
20535 NCE(vmov, 0, 1, (VMOV), neon_mov),
20536 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20537
9db2f6b4
RL
20538#undef ARM_VARIANT
20539#define ARM_VARIANT & arm_ext_fp16
20540#undef THUMB_VARIANT
20541#define THUMB_VARIANT & arm_ext_fp16
20542 /* New instructions added from v8.2, allowing the extraction and insertion of
20543 the upper 16 bits of a 32-bit vector register. */
20544 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20545 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20546
c921be7d
NC
20547#undef THUMB_VARIANT
20548#define THUMB_VARIANT & fpu_neon_ext_v1
20549#undef ARM_VARIANT
20550#define ARM_VARIANT & fpu_neon_ext_v1
20551
5287ad62
JB
20552 /* Data processing with three registers of the same length. */
20553 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20554 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20555 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20556 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20557 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20558 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20559 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20560 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20561 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20562 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20563 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20564 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20565 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20566 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20567 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20568 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20569 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20570 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20571 /* If not immediate, fall back to neon_dyadic_i64_su.
20572 shl_imm should accept I8 I16 I32 I64,
20573 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20574 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20575 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20576 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20577 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20578 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20579 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20580 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20581 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20582 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20583 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20584 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20585 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20586 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20587 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20588 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20589 /* Bitfield ops, untyped. */
20590 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20591 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20592 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20593 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20594 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20595 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20596 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20597 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20598 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20599 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20600 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20601 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20602 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20603 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20604 back to neon_dyadic_if_su. */
21d799b5
NC
20605 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20606 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20607 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20608 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20609 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20610 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20611 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20612 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20613 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20614 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20615 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20616 /* As above, D registers only. */
21d799b5
NC
20617 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20618 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20619 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20620 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20621 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20622 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20623 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20624 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20625 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20626 /* vtst takes sizes 8, 16, 32. */
20627 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20628 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20629 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20630 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20631 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20632 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20633 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20634 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20635 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20636 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20637 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20638 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20639 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20640 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20641 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20642 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20643 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20644 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20645 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20646 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20647 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20648 /* ARM v8.1 extension. */
643afb90
MW
20649 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20650 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20651 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20652 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20653
20654 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20655 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20656 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20657
20658 /* Data processing with two registers and a shift amount. */
20659 /* Right shifts, and variants with rounding.
20660 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20661 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20662 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20663 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20664 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20665 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20666 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20667 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20668 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20669 /* Shift and insert. Sizes accepted 8 16 32 64. */
20670 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20671 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20672 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20673 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20674 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20675 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20676 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20677 /* Right shift immediate, saturating & narrowing, with rounding variants.
20678 Types accepted S16 S32 S64 U16 U32 U64. */
20679 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20680 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20681 /* As above, unsigned. Types accepted S16 S32 S64. */
20682 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20683 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20684 /* Right shift narrowing. Types accepted I16 I32 I64. */
20685 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20686 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20687 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20688 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20689 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20690 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20691
4316f0d2
DG
20692 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20693 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20694
20695 /* Data processing, three registers of different lengths. */
20696 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20697 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20698 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20699 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20700 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20701 /* If not scalar, fall back to neon_dyadic_long.
20702 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20703 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20704 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20705 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20706 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20707 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20708 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20709 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20710 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20711 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20712 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20713 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20714 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20715 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20716 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20717 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20718 S16 S32 U16 U32. */
21d799b5 20719 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20720
20721 /* Extract. Size 8. */
3b8d421e
PB
20722 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20723 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20724
20725 /* Two registers, miscellaneous. */
20726 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20727 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20728 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20729 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20730 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20731 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20732 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20733 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20734 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20735 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20736 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20737 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20738 /* VMOVN. Types I16 I32 I64. */
21d799b5 20739 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20740 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20741 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20742 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20743 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20744 /* VZIP / VUZP. Sizes 8 16 32. */
20745 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20746 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20747 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20748 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20749 /* VQABS / VQNEG. Types S8 S16 S32. */
20750 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20751 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20752 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20753 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20754 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20755 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20756 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20757 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20758 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20759 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20760 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20761 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20762 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20763 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20764 /* VCLS. Types S8 S16 S32. */
20765 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20766 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20767 /* VCLZ. Types I8 I16 I32. */
20768 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20769 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20770 /* VCNT. Size 8. */
20771 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20772 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20773 /* Two address, untyped. */
20774 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20775 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20776 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20777 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20778 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20779
20780 /* Table lookup. Size 8. */
20781 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20782 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20783
c921be7d
NC
20784#undef THUMB_VARIANT
20785#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20786#undef ARM_VARIANT
20787#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20788
5287ad62 20789 /* Neon element/structure load/store. */
21d799b5
NC
20790 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20791 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20792 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20793 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20794 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20795 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20796 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20797 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20798
c921be7d 20799#undef THUMB_VARIANT
74db7efb
NC
20800#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20801#undef ARM_VARIANT
20802#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20803 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20804 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20805 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20806 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20807 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20808 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20809 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20810 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20811 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20812
74db7efb 20813#undef THUMB_VARIANT
c921be7d
NC
20814#define THUMB_VARIANT & fpu_vfp_ext_v3
20815#undef ARM_VARIANT
20816#define ARM_VARIANT & fpu_vfp_ext_v3
20817
21d799b5 20818 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20819 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20820 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20821 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20822 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20823 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20824 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20825 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20826 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20827
74db7efb
NC
20828#undef ARM_VARIANT
20829#define ARM_VARIANT & fpu_vfp_ext_fma
20830#undef THUMB_VARIANT
20831#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20832 /* Mnemonics shared by Neon and VFP. These are included in the
20833 VFP FMA variant; NEON and VFP FMA always includes the NEON
20834 FMA instructions. */
20835 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20836 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20837 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20838 the v form should always be used. */
20839 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20840 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20841 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20842 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20843 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20844 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20845
5287ad62 20846#undef THUMB_VARIANT
c921be7d
NC
20847#undef ARM_VARIANT
20848#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20849
21d799b5
NC
20850 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20851 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20852 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20853 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20854 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20855 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20856 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20857 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20858
c921be7d
NC
20859#undef ARM_VARIANT
20860#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20861
21d799b5
NC
20862 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20863 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20864 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20865 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20866 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20867 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20868 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20869 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20870 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20871 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20872 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20873 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20874 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20875 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20876 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20877 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20878 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20879 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20880 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20881 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20882 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20883 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20884 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20885 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20886 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20887 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20888 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20889 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20890 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20891 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20892 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20893 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20894 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20895 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20896 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20897 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20898 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20899 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20900 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20904 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20905 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20906 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20907 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20908 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20909 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20910 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20911 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20912 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20913 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20914 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20915 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20916 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20917 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20918 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20919 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20920 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20921 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20922 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20923 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20924 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20925 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20926 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20927 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20928 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20929 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20930 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20931 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20932 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20933 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20934 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20935 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20936 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20937 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20938 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20939 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20940 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20941 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20942 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20943 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20944 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20945 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20946 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20947 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20948 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20949 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20950 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20951 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20952 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20953 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20954 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20955 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20956 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20957 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20958 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20959 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20960 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20961 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20962 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20963 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20964 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20965 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20966 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20967 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20968 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20969 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20970 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20971 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20972 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20973 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20974 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20975 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20976 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20977 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20978 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20979 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20980 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20981 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20982 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20983 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20984 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20985 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20986 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20987 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20988 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20989 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20990 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20991 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20992 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20993 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20994 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20995 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20996 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20997 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20998 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20999 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21001 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21002 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21003 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21004 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21005 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21006 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21007 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21008 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21009 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21010 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21011 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21012 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21013 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21014 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21015 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21016 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21017 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21018 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21019 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21020 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21021 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21022 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21023 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21024
c921be7d
NC
21025#undef ARM_VARIANT
21026#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21027
21d799b5
NC
21028 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21029 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21030 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21031 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21032 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21033 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21034 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21043 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21046 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21048 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21049 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21050 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21051 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21052 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21053 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21054 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21055 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21056 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21057 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21058 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21059 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21060 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21061 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21062 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21063 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21064 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21065 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21066 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21067 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21068 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21069 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21070 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21071 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21072 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21073 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21074 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21075 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21076 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21077 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21078 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21079 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21080 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21081 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21082 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21083 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21084 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21085
c921be7d
NC
21086#undef ARM_VARIANT
21087#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21088
21d799b5
NC
21089 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21090 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21091 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21092 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21093 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21094 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21095 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21096 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21097 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21098 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21099 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21100 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21101 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21102 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21103 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21104 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21105 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21106 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21107 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21108 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21109 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21110 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21111 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21112 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21113 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21114 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21115 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21116 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21117 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21118 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21119 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21120 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21121 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21122 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21123 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21124 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21125 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21126 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21127 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21128 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21129 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21130 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21131 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21132 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21133 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21134 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21135 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21136 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21137 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21138 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21139 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21140 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21141 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21142 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21143 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21144 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21145 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21146 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21147 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21148 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21149 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21150 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21151 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21152 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21153 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21154 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21155 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21156 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21157 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21158 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21159 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21160 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21161 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21162 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21163 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21164 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21165
16a1fa25 21166 /* ARMv8-M instructions. */
4ed7ed8d
TP
21167#undef ARM_VARIANT
21168#define ARM_VARIANT NULL
21169#undef THUMB_VARIANT
21170#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21171 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21172 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21173 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21174 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21175 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21176 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21177 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21178
21179 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21180 instructions behave as nop if no VFP is present. */
21181#undef THUMB_VARIANT
21182#define THUMB_VARIANT & arm_ext_v8m_main
21183 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21184 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21185};
21186#undef ARM_VARIANT
21187#undef THUMB_VARIANT
21188#undef TCE
c19d1205
ZW
21189#undef TUE
21190#undef TUF
21191#undef TCC
8f06b2d8 21192#undef cCE
e3cb604e
PB
21193#undef cCL
21194#undef C3E
c19d1205
ZW
21195#undef CE
21196#undef CM
21197#undef UE
21198#undef UF
21199#undef UT
5287ad62
JB
21200#undef NUF
21201#undef nUF
21202#undef NCE
21203#undef nCE
c19d1205
ZW
21204#undef OPS0
21205#undef OPS1
21206#undef OPS2
21207#undef OPS3
21208#undef OPS4
21209#undef OPS5
21210#undef OPS6
21211#undef do_0
21212\f
21213/* MD interface: bits in the object file. */
bfae80f2 21214
c19d1205
ZW
21215/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21216 for use in the a.out file, and stores them in the array pointed to by buf.
21217 This knows about the endian-ness of the target machine and does
21218 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21219 2 (short) and 4 (long) Floating numbers are put out as a series of
21220 LITTLENUMS (shorts, here at least). */
b99bd4ef 21221
c19d1205
ZW
21222void
21223md_number_to_chars (char * buf, valueT val, int n)
21224{
21225 if (target_big_endian)
21226 number_to_chars_bigendian (buf, val, n);
21227 else
21228 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21229}
21230
c19d1205
ZW
21231static valueT
21232md_chars_to_number (char * buf, int n)
bfae80f2 21233{
c19d1205
ZW
21234 valueT result = 0;
21235 unsigned char * where = (unsigned char *) buf;
bfae80f2 21236
c19d1205 21237 if (target_big_endian)
b99bd4ef 21238 {
c19d1205
ZW
21239 while (n--)
21240 {
21241 result <<= 8;
21242 result |= (*where++ & 255);
21243 }
b99bd4ef 21244 }
c19d1205 21245 else
b99bd4ef 21246 {
c19d1205
ZW
21247 while (n--)
21248 {
21249 result <<= 8;
21250 result |= (where[n] & 255);
21251 }
bfae80f2 21252 }
b99bd4ef 21253
c19d1205 21254 return result;
bfae80f2 21255}
b99bd4ef 21256
c19d1205 21257/* MD interface: Sections. */
b99bd4ef 21258
fa94de6b
RM
21259/* Calculate the maximum variable size (i.e., excluding fr_fix)
21260 that an rs_machine_dependent frag may reach. */
21261
21262unsigned int
21263arm_frag_max_var (fragS *fragp)
21264{
21265 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21266 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21267
21268 Note that we generate relaxable instructions even for cases that don't
21269 really need it, like an immediate that's a trivial constant. So we're
21270 overestimating the instruction size for some of those cases. Rather
21271 than putting more intelligence here, it would probably be better to
21272 avoid generating a relaxation frag in the first place when it can be
21273 determined up front that a short instruction will suffice. */
21274
21275 gas_assert (fragp->fr_type == rs_machine_dependent);
21276 return INSN_SIZE;
21277}
21278
0110f2b8
PB
21279/* Estimate the size of a frag before relaxing. Assume everything fits in
21280 2 bytes. */
21281
c19d1205 21282int
0110f2b8 21283md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21284 segT segtype ATTRIBUTE_UNUSED)
21285{
0110f2b8
PB
21286 fragp->fr_var = 2;
21287 return 2;
21288}
21289
21290/* Convert a machine dependent frag. */
21291
21292void
21293md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21294{
21295 unsigned long insn;
21296 unsigned long old_op;
21297 char *buf;
21298 expressionS exp;
21299 fixS *fixp;
21300 int reloc_type;
21301 int pc_rel;
21302 int opcode;
21303
21304 buf = fragp->fr_literal + fragp->fr_fix;
21305
21306 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21307 if (fragp->fr_symbol)
21308 {
0110f2b8
PB
21309 exp.X_op = O_symbol;
21310 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21311 }
21312 else
21313 {
0110f2b8 21314 exp.X_op = O_constant;
5f4273c7 21315 }
0110f2b8
PB
21316 exp.X_add_number = fragp->fr_offset;
21317 opcode = fragp->fr_subtype;
21318 switch (opcode)
21319 {
21320 case T_MNEM_ldr_pc:
21321 case T_MNEM_ldr_pc2:
21322 case T_MNEM_ldr_sp:
21323 case T_MNEM_str_sp:
21324 case T_MNEM_ldr:
21325 case T_MNEM_ldrb:
21326 case T_MNEM_ldrh:
21327 case T_MNEM_str:
21328 case T_MNEM_strb:
21329 case T_MNEM_strh:
21330 if (fragp->fr_var == 4)
21331 {
5f4273c7 21332 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21333 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21334 {
21335 insn |= (old_op & 0x700) << 4;
21336 }
21337 else
21338 {
21339 insn |= (old_op & 7) << 12;
21340 insn |= (old_op & 0x38) << 13;
21341 }
21342 insn |= 0x00000c00;
21343 put_thumb32_insn (buf, insn);
21344 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21345 }
21346 else
21347 {
21348 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21349 }
21350 pc_rel = (opcode == T_MNEM_ldr_pc2);
21351 break;
21352 case T_MNEM_adr:
21353 if (fragp->fr_var == 4)
21354 {
21355 insn = THUMB_OP32 (opcode);
21356 insn |= (old_op & 0xf0) << 4;
21357 put_thumb32_insn (buf, insn);
21358 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21359 }
21360 else
21361 {
21362 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21363 exp.X_add_number -= 4;
21364 }
21365 pc_rel = 1;
21366 break;
21367 case T_MNEM_mov:
21368 case T_MNEM_movs:
21369 case T_MNEM_cmp:
21370 case T_MNEM_cmn:
21371 if (fragp->fr_var == 4)
21372 {
21373 int r0off = (opcode == T_MNEM_mov
21374 || opcode == T_MNEM_movs) ? 0 : 8;
21375 insn = THUMB_OP32 (opcode);
21376 insn = (insn & 0xe1ffffff) | 0x10000000;
21377 insn |= (old_op & 0x700) << r0off;
21378 put_thumb32_insn (buf, insn);
21379 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21380 }
21381 else
21382 {
21383 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21384 }
21385 pc_rel = 0;
21386 break;
21387 case T_MNEM_b:
21388 if (fragp->fr_var == 4)
21389 {
21390 insn = THUMB_OP32(opcode);
21391 put_thumb32_insn (buf, insn);
21392 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21393 }
21394 else
21395 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21396 pc_rel = 1;
21397 break;
21398 case T_MNEM_bcond:
21399 if (fragp->fr_var == 4)
21400 {
21401 insn = THUMB_OP32(opcode);
21402 insn |= (old_op & 0xf00) << 14;
21403 put_thumb32_insn (buf, insn);
21404 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21405 }
21406 else
21407 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21408 pc_rel = 1;
21409 break;
21410 case T_MNEM_add_sp:
21411 case T_MNEM_add_pc:
21412 case T_MNEM_inc_sp:
21413 case T_MNEM_dec_sp:
21414 if (fragp->fr_var == 4)
21415 {
21416 /* ??? Choose between add and addw. */
21417 insn = THUMB_OP32 (opcode);
21418 insn |= (old_op & 0xf0) << 4;
21419 put_thumb32_insn (buf, insn);
16805f35
PB
21420 if (opcode == T_MNEM_add_pc)
21421 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21422 else
21423 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21424 }
21425 else
21426 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21427 pc_rel = 0;
21428 break;
21429
21430 case T_MNEM_addi:
21431 case T_MNEM_addis:
21432 case T_MNEM_subi:
21433 case T_MNEM_subis:
21434 if (fragp->fr_var == 4)
21435 {
21436 insn = THUMB_OP32 (opcode);
21437 insn |= (old_op & 0xf0) << 4;
21438 insn |= (old_op & 0xf) << 16;
21439 put_thumb32_insn (buf, insn);
16805f35
PB
21440 if (insn & (1 << 20))
21441 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21442 else
21443 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21444 }
21445 else
21446 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21447 pc_rel = 0;
21448 break;
21449 default:
5f4273c7 21450 abort ();
0110f2b8
PB
21451 }
21452 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21453 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21454 fixp->fx_file = fragp->fr_file;
21455 fixp->fx_line = fragp->fr_line;
21456 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21457
21458 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21459 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21460 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21461 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21462}
21463
21464/* Return the size of a relaxable immediate operand instruction.
21465 SHIFT and SIZE specify the form of the allowable immediate. */
21466static int
21467relax_immediate (fragS *fragp, int size, int shift)
21468{
21469 offsetT offset;
21470 offsetT mask;
21471 offsetT low;
21472
21473 /* ??? Should be able to do better than this. */
21474 if (fragp->fr_symbol)
21475 return 4;
21476
21477 low = (1 << shift) - 1;
21478 mask = (1 << (shift + size)) - (1 << shift);
21479 offset = fragp->fr_offset;
21480 /* Force misaligned offsets to 32-bit variant. */
21481 if (offset & low)
5e77afaa 21482 return 4;
0110f2b8
PB
21483 if (offset & ~mask)
21484 return 4;
21485 return 2;
21486}
21487
5e77afaa
PB
21488/* Get the address of a symbol during relaxation. */
21489static addressT
5f4273c7 21490relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21491{
21492 fragS *sym_frag;
21493 addressT addr;
21494 symbolS *sym;
21495
21496 sym = fragp->fr_symbol;
21497 sym_frag = symbol_get_frag (sym);
21498 know (S_GET_SEGMENT (sym) != absolute_section
21499 || sym_frag == &zero_address_frag);
21500 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21501
21502 /* If frag has yet to be reached on this pass, assume it will
21503 move by STRETCH just as we did. If this is not so, it will
21504 be because some frag between grows, and that will force
21505 another pass. */
21506
21507 if (stretch != 0
21508 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21509 {
21510 fragS *f;
21511
21512 /* Adjust stretch for any alignment frag. Note that if have
21513 been expanding the earlier code, the symbol may be
21514 defined in what appears to be an earlier frag. FIXME:
21515 This doesn't handle the fr_subtype field, which specifies
21516 a maximum number of bytes to skip when doing an
21517 alignment. */
21518 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21519 {
21520 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21521 {
21522 if (stretch < 0)
21523 stretch = - ((- stretch)
21524 & ~ ((1 << (int) f->fr_offset) - 1));
21525 else
21526 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21527 if (stretch == 0)
21528 break;
21529 }
21530 }
21531 if (f != NULL)
21532 addr += stretch;
21533 }
5e77afaa
PB
21534
21535 return addr;
21536}
21537
0110f2b8
PB
21538/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21539 load. */
21540static int
5e77afaa 21541relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21542{
21543 addressT addr;
21544 offsetT val;
21545
21546 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21547 if (fragp->fr_symbol == NULL
21548 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21549 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21550 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21551 return 4;
21552
5f4273c7 21553 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21554 addr = fragp->fr_address + fragp->fr_fix;
21555 addr = (addr + 4) & ~3;
5e77afaa 21556 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21557 if (val & 3)
5e77afaa 21558 return 4;
0110f2b8
PB
21559 val -= addr;
21560 if (val < 0 || val > 1020)
21561 return 4;
21562 return 2;
21563}
21564
21565/* Return the size of a relaxable add/sub immediate instruction. */
21566static int
21567relax_addsub (fragS *fragp, asection *sec)
21568{
21569 char *buf;
21570 int op;
21571
21572 buf = fragp->fr_literal + fragp->fr_fix;
21573 op = bfd_get_16(sec->owner, buf);
21574 if ((op & 0xf) == ((op >> 4) & 0xf))
21575 return relax_immediate (fragp, 8, 0);
21576 else
21577 return relax_immediate (fragp, 3, 0);
21578}
21579
e83a675f
RE
21580/* Return TRUE iff the definition of symbol S could be pre-empted
21581 (overridden) at link or load time. */
21582static bfd_boolean
21583symbol_preemptible (symbolS *s)
21584{
21585 /* Weak symbols can always be pre-empted. */
21586 if (S_IS_WEAK (s))
21587 return TRUE;
21588
21589 /* Non-global symbols cannot be pre-empted. */
21590 if (! S_IS_EXTERNAL (s))
21591 return FALSE;
21592
21593#ifdef OBJ_ELF
21594 /* In ELF, a global symbol can be marked protected, or private. In that
21595 case it can't be pre-empted (other definitions in the same link unit
21596 would violate the ODR). */
21597 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21598 return FALSE;
21599#endif
21600
21601 /* Other global symbols might be pre-empted. */
21602 return TRUE;
21603}
0110f2b8
PB
21604
21605/* Return the size of a relaxable branch instruction. BITS is the
21606 size of the offset field in the narrow instruction. */
21607
21608static int
5e77afaa 21609relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21610{
21611 addressT addr;
21612 offsetT val;
21613 offsetT limit;
21614
21615 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21616 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21617 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21618 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21619 return 4;
21620
267bf995 21621#ifdef OBJ_ELF
e83a675f 21622 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21623 if (S_IS_DEFINED (fragp->fr_symbol)
21624 && ARM_IS_FUNC (fragp->fr_symbol))
21625 return 4;
e83a675f 21626#endif
0d9b4b55 21627
e83a675f 21628 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21629 return 4;
267bf995 21630
5f4273c7 21631 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21632 addr = fragp->fr_address + fragp->fr_fix + 4;
21633 val -= addr;
21634
21635 /* Offset is a signed value *2 */
21636 limit = 1 << bits;
21637 if (val >= limit || val < -limit)
21638 return 4;
21639 return 2;
21640}
21641
21642
21643/* Relax a machine dependent frag. This returns the amount by which
21644 the current size of the frag should change. */
21645
21646int
5e77afaa 21647arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21648{
21649 int oldsize;
21650 int newsize;
21651
21652 oldsize = fragp->fr_var;
21653 switch (fragp->fr_subtype)
21654 {
21655 case T_MNEM_ldr_pc2:
5f4273c7 21656 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21657 break;
21658 case T_MNEM_ldr_pc:
21659 case T_MNEM_ldr_sp:
21660 case T_MNEM_str_sp:
5f4273c7 21661 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21662 break;
21663 case T_MNEM_ldr:
21664 case T_MNEM_str:
5f4273c7 21665 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21666 break;
21667 case T_MNEM_ldrh:
21668 case T_MNEM_strh:
5f4273c7 21669 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21670 break;
21671 case T_MNEM_ldrb:
21672 case T_MNEM_strb:
5f4273c7 21673 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21674 break;
21675 case T_MNEM_adr:
5f4273c7 21676 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21677 break;
21678 case T_MNEM_mov:
21679 case T_MNEM_movs:
21680 case T_MNEM_cmp:
21681 case T_MNEM_cmn:
5f4273c7 21682 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21683 break;
21684 case T_MNEM_b:
5f4273c7 21685 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21686 break;
21687 case T_MNEM_bcond:
5f4273c7 21688 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21689 break;
21690 case T_MNEM_add_sp:
21691 case T_MNEM_add_pc:
21692 newsize = relax_immediate (fragp, 8, 2);
21693 break;
21694 case T_MNEM_inc_sp:
21695 case T_MNEM_dec_sp:
21696 newsize = relax_immediate (fragp, 7, 2);
21697 break;
21698 case T_MNEM_addi:
21699 case T_MNEM_addis:
21700 case T_MNEM_subi:
21701 case T_MNEM_subis:
21702 newsize = relax_addsub (fragp, sec);
21703 break;
21704 default:
5f4273c7 21705 abort ();
0110f2b8 21706 }
5e77afaa
PB
21707
21708 fragp->fr_var = newsize;
21709 /* Freeze wide instructions that are at or before the same location as
21710 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21711 Don't freeze them unconditionally because targets may be artificially
21712 misaligned by the expansion of preceding frags. */
5e77afaa 21713 if (stretch <= 0 && newsize > 2)
0110f2b8 21714 {
0110f2b8 21715 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21716 frag_wane (fragp);
0110f2b8 21717 }
5e77afaa 21718
0110f2b8 21719 return newsize - oldsize;
c19d1205 21720}
b99bd4ef 21721
c19d1205 21722/* Round up a section size to the appropriate boundary. */
b99bd4ef 21723
c19d1205
ZW
21724valueT
21725md_section_align (segT segment ATTRIBUTE_UNUSED,
21726 valueT size)
21727{
f0927246
NC
21728#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21729 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21730 {
21731 /* For a.out, force the section size to be aligned. If we don't do
21732 this, BFD will align it for us, but it will not write out the
21733 final bytes of the section. This may be a bug in BFD, but it is
21734 easier to fix it here since that is how the other a.out targets
21735 work. */
21736 int align;
21737
21738 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21739 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21740 }
c19d1205 21741#endif
f0927246 21742
6844c0cc 21743 return size;
bfae80f2 21744}
b99bd4ef 21745
c19d1205
ZW
21746/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21747 of an rs_align_code fragment. */
21748
21749void
21750arm_handle_align (fragS * fragP)
bfae80f2 21751{
d9235011 21752 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21753 {
21754 { /* ARMv1 */
21755 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21756 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21757 },
21758 { /* ARMv6k */
21759 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21760 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21761 },
21762 };
d9235011 21763 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21764 {
21765 { /* Thumb-1 */
21766 {0xc0, 0x46}, /* LE */
21767 {0x46, 0xc0}, /* BE */
21768 },
21769 { /* Thumb-2 */
21770 {0x00, 0xbf}, /* LE */
21771 {0xbf, 0x00} /* BE */
21772 }
21773 };
d9235011 21774 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21775 { /* Wide Thumb-2 */
21776 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21777 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21778 };
c921be7d 21779
e7495e45 21780 unsigned bytes, fix, noop_size;
c19d1205 21781 char * p;
d9235011
TS
21782 const unsigned char * noop;
21783 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21784#ifdef OBJ_ELF
21785 enum mstate state;
21786#endif
bfae80f2 21787
c19d1205 21788 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21789 return;
21790
c19d1205
ZW
21791 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21792 p = fragP->fr_literal + fragP->fr_fix;
21793 fix = 0;
bfae80f2 21794
c19d1205
ZW
21795 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21796 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21797
cd000bff 21798 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21799
cd000bff 21800 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21801 {
7f78eb34
JW
21802 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21803 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21804 {
21805 narrow_noop = thumb_noop[1][target_big_endian];
21806 noop = wide_thumb_noop[target_big_endian];
21807 }
c19d1205 21808 else
e7495e45
NS
21809 noop = thumb_noop[0][target_big_endian];
21810 noop_size = 2;
cd000bff
DJ
21811#ifdef OBJ_ELF
21812 state = MAP_THUMB;
21813#endif
7ed4c4c5
NC
21814 }
21815 else
21816 {
7f78eb34
JW
21817 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21818 ? selected_cpu : arm_arch_none,
21819 arm_ext_v6k) != 0]
e7495e45
NS
21820 [target_big_endian];
21821 noop_size = 4;
cd000bff
DJ
21822#ifdef OBJ_ELF
21823 state = MAP_ARM;
21824#endif
7ed4c4c5 21825 }
c921be7d 21826
e7495e45 21827 fragP->fr_var = noop_size;
c921be7d 21828
c19d1205 21829 if (bytes & (noop_size - 1))
7ed4c4c5 21830 {
c19d1205 21831 fix = bytes & (noop_size - 1);
cd000bff
DJ
21832#ifdef OBJ_ELF
21833 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21834#endif
c19d1205
ZW
21835 memset (p, 0, fix);
21836 p += fix;
21837 bytes -= fix;
a737bd4d 21838 }
a737bd4d 21839
e7495e45
NS
21840 if (narrow_noop)
21841 {
21842 if (bytes & noop_size)
21843 {
21844 /* Insert a narrow noop. */
21845 memcpy (p, narrow_noop, noop_size);
21846 p += noop_size;
21847 bytes -= noop_size;
21848 fix += noop_size;
21849 }
21850
21851 /* Use wide noops for the remainder */
21852 noop_size = 4;
21853 }
21854
c19d1205 21855 while (bytes >= noop_size)
a737bd4d 21856 {
c19d1205
ZW
21857 memcpy (p, noop, noop_size);
21858 p += noop_size;
21859 bytes -= noop_size;
21860 fix += noop_size;
a737bd4d
NC
21861 }
21862
c19d1205 21863 fragP->fr_fix += fix;
a737bd4d
NC
21864}
21865
c19d1205
ZW
21866/* Called from md_do_align. Used to create an alignment
21867 frag in a code section. */
21868
21869void
21870arm_frag_align_code (int n, int max)
bfae80f2 21871{
c19d1205 21872 char * p;
7ed4c4c5 21873
c19d1205 21874 /* We assume that there will never be a requirement
6ec8e702 21875 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21876 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21877 {
21878 char err_msg[128];
21879
fa94de6b 21880 sprintf (err_msg,
477330fc
RM
21881 _("alignments greater than %d bytes not supported in .text sections."),
21882 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21883 as_fatal ("%s", err_msg);
6ec8e702 21884 }
bfae80f2 21885
c19d1205
ZW
21886 p = frag_var (rs_align_code,
21887 MAX_MEM_FOR_RS_ALIGN_CODE,
21888 1,
21889 (relax_substateT) max,
21890 (symbolS *) NULL,
21891 (offsetT) n,
21892 (char *) NULL);
21893 *p = 0;
21894}
bfae80f2 21895
8dc2430f
NC
21896/* Perform target specific initialisation of a frag.
21897 Note - despite the name this initialisation is not done when the frag
21898 is created, but only when its type is assigned. A frag can be created
21899 and used a long time before its type is set, so beware of assuming that
33eaf5de 21900 this initialisation is performed first. */
bfae80f2 21901
cd000bff
DJ
21902#ifndef OBJ_ELF
21903void
21904arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21905{
21906 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21907 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21908}
21909
21910#else /* OBJ_ELF is defined. */
c19d1205 21911void
cd000bff 21912arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21913{
b968d18a
JW
21914 int frag_thumb_mode;
21915
8dc2430f
NC
21916 /* If the current ARM vs THUMB mode has not already
21917 been recorded into this frag then do so now. */
cd000bff 21918 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21919 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21920
21921 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21922
f9c1b181
RL
21923 /* Record a mapping symbol for alignment frags. We will delete this
21924 later if the alignment ends up empty. */
21925 switch (fragP->fr_type)
21926 {
21927 case rs_align:
21928 case rs_align_test:
21929 case rs_fill:
21930 mapping_state_2 (MAP_DATA, max_chars);
21931 break;
21932 case rs_align_code:
b968d18a 21933 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21934 break;
21935 default:
21936 break;
cd000bff 21937 }
bfae80f2
RE
21938}
21939
c19d1205
ZW
21940/* When we change sections we need to issue a new mapping symbol. */
21941
21942void
21943arm_elf_change_section (void)
bfae80f2 21944{
c19d1205
ZW
21945 /* Link an unlinked unwind index table section to the .text section. */
21946 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21947 && elf_linked_to_section (now_seg) == NULL)
21948 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21949}
21950
c19d1205
ZW
21951int
21952arm_elf_section_type (const char * str, size_t len)
e45d0630 21953{
c19d1205
ZW
21954 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21955 return SHT_ARM_EXIDX;
e45d0630 21956
c19d1205
ZW
21957 return -1;
21958}
21959\f
21960/* Code to deal with unwinding tables. */
e45d0630 21961
c19d1205 21962static void add_unwind_adjustsp (offsetT);
e45d0630 21963
5f4273c7 21964/* Generate any deferred unwind frame offset. */
e45d0630 21965
bfae80f2 21966static void
c19d1205 21967flush_pending_unwind (void)
bfae80f2 21968{
c19d1205 21969 offsetT offset;
bfae80f2 21970
c19d1205
ZW
21971 offset = unwind.pending_offset;
21972 unwind.pending_offset = 0;
21973 if (offset != 0)
21974 add_unwind_adjustsp (offset);
bfae80f2
RE
21975}
21976
c19d1205
ZW
21977/* Add an opcode to this list for this function. Two-byte opcodes should
21978 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21979 order. */
21980
bfae80f2 21981static void
c19d1205 21982add_unwind_opcode (valueT op, int length)
bfae80f2 21983{
c19d1205
ZW
21984 /* Add any deferred stack adjustment. */
21985 if (unwind.pending_offset)
21986 flush_pending_unwind ();
bfae80f2 21987
c19d1205 21988 unwind.sp_restored = 0;
bfae80f2 21989
c19d1205 21990 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21991 {
c19d1205
ZW
21992 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21993 if (unwind.opcodes)
325801bd
TS
21994 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21995 unwind.opcode_alloc);
c19d1205 21996 else
325801bd 21997 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21998 }
c19d1205 21999 while (length > 0)
bfae80f2 22000 {
c19d1205
ZW
22001 length--;
22002 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22003 op >>= 8;
22004 unwind.opcode_count++;
bfae80f2 22005 }
bfae80f2
RE
22006}
22007
c19d1205
ZW
22008/* Add unwind opcodes to adjust the stack pointer. */
22009
bfae80f2 22010static void
c19d1205 22011add_unwind_adjustsp (offsetT offset)
bfae80f2 22012{
c19d1205 22013 valueT op;
bfae80f2 22014
c19d1205 22015 if (offset > 0x200)
bfae80f2 22016 {
c19d1205
ZW
22017 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22018 char bytes[5];
22019 int n;
22020 valueT o;
bfae80f2 22021
c19d1205
ZW
22022 /* Long form: 0xb2, uleb128. */
22023 /* This might not fit in a word so add the individual bytes,
22024 remembering the list is built in reverse order. */
22025 o = (valueT) ((offset - 0x204) >> 2);
22026 if (o == 0)
22027 add_unwind_opcode (0, 1);
bfae80f2 22028
c19d1205
ZW
22029 /* Calculate the uleb128 encoding of the offset. */
22030 n = 0;
22031 while (o)
22032 {
22033 bytes[n] = o & 0x7f;
22034 o >>= 7;
22035 if (o)
22036 bytes[n] |= 0x80;
22037 n++;
22038 }
22039 /* Add the insn. */
22040 for (; n; n--)
22041 add_unwind_opcode (bytes[n - 1], 1);
22042 add_unwind_opcode (0xb2, 1);
22043 }
22044 else if (offset > 0x100)
bfae80f2 22045 {
c19d1205
ZW
22046 /* Two short opcodes. */
22047 add_unwind_opcode (0x3f, 1);
22048 op = (offset - 0x104) >> 2;
22049 add_unwind_opcode (op, 1);
bfae80f2 22050 }
c19d1205
ZW
22051 else if (offset > 0)
22052 {
22053 /* Short opcode. */
22054 op = (offset - 4) >> 2;
22055 add_unwind_opcode (op, 1);
22056 }
22057 else if (offset < 0)
bfae80f2 22058 {
c19d1205
ZW
22059 offset = -offset;
22060 while (offset > 0x100)
bfae80f2 22061 {
c19d1205
ZW
22062 add_unwind_opcode (0x7f, 1);
22063 offset -= 0x100;
bfae80f2 22064 }
c19d1205
ZW
22065 op = ((offset - 4) >> 2) | 0x40;
22066 add_unwind_opcode (op, 1);
bfae80f2 22067 }
bfae80f2
RE
22068}
22069
c19d1205
ZW
22070/* Finish the list of unwind opcodes for this function. */
22071static void
22072finish_unwind_opcodes (void)
bfae80f2 22073{
c19d1205 22074 valueT op;
bfae80f2 22075
c19d1205 22076 if (unwind.fp_used)
bfae80f2 22077 {
708587a4 22078 /* Adjust sp as necessary. */
c19d1205
ZW
22079 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22080 flush_pending_unwind ();
bfae80f2 22081
c19d1205
ZW
22082 /* After restoring sp from the frame pointer. */
22083 op = 0x90 | unwind.fp_reg;
22084 add_unwind_opcode (op, 1);
22085 }
22086 else
22087 flush_pending_unwind ();
bfae80f2
RE
22088}
22089
bfae80f2 22090
c19d1205
ZW
22091/* Start an exception table entry. If idx is nonzero this is an index table
22092 entry. */
bfae80f2
RE
22093
22094static void
c19d1205 22095start_unwind_section (const segT text_seg, int idx)
bfae80f2 22096{
c19d1205
ZW
22097 const char * text_name;
22098 const char * prefix;
22099 const char * prefix_once;
22100 const char * group_name;
c19d1205 22101 char * sec_name;
c19d1205
ZW
22102 int type;
22103 int flags;
22104 int linkonce;
bfae80f2 22105
c19d1205 22106 if (idx)
bfae80f2 22107 {
c19d1205
ZW
22108 prefix = ELF_STRING_ARM_unwind;
22109 prefix_once = ELF_STRING_ARM_unwind_once;
22110 type = SHT_ARM_EXIDX;
bfae80f2 22111 }
c19d1205 22112 else
bfae80f2 22113 {
c19d1205
ZW
22114 prefix = ELF_STRING_ARM_unwind_info;
22115 prefix_once = ELF_STRING_ARM_unwind_info_once;
22116 type = SHT_PROGBITS;
bfae80f2
RE
22117 }
22118
c19d1205
ZW
22119 text_name = segment_name (text_seg);
22120 if (streq (text_name, ".text"))
22121 text_name = "";
22122
22123 if (strncmp (text_name, ".gnu.linkonce.t.",
22124 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22125 {
c19d1205
ZW
22126 prefix = prefix_once;
22127 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22128 }
22129
29a2809e 22130 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22131
c19d1205
ZW
22132 flags = SHF_ALLOC;
22133 linkonce = 0;
22134 group_name = 0;
bfae80f2 22135
c19d1205
ZW
22136 /* Handle COMDAT group. */
22137 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22138 {
c19d1205
ZW
22139 group_name = elf_group_name (text_seg);
22140 if (group_name == NULL)
22141 {
bd3ba5d1 22142 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22143 segment_name (text_seg));
22144 ignore_rest_of_line ();
22145 return;
22146 }
22147 flags |= SHF_GROUP;
22148 linkonce = 1;
bfae80f2
RE
22149 }
22150
a91e1603
L
22151 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22152 linkonce, 0);
bfae80f2 22153
5f4273c7 22154 /* Set the section link for index tables. */
c19d1205
ZW
22155 if (idx)
22156 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22157}
22158
bfae80f2 22159
c19d1205
ZW
22160/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22161 personality routine data. Returns zero, or the index table value for
cad0da33 22162 an inline entry. */
c19d1205
ZW
22163
22164static valueT
22165create_unwind_entry (int have_data)
bfae80f2 22166{
c19d1205
ZW
22167 int size;
22168 addressT where;
22169 char *ptr;
22170 /* The current word of data. */
22171 valueT data;
22172 /* The number of bytes left in this word. */
22173 int n;
bfae80f2 22174
c19d1205 22175 finish_unwind_opcodes ();
bfae80f2 22176
c19d1205
ZW
22177 /* Remember the current text section. */
22178 unwind.saved_seg = now_seg;
22179 unwind.saved_subseg = now_subseg;
bfae80f2 22180
c19d1205 22181 start_unwind_section (now_seg, 0);
bfae80f2 22182
c19d1205 22183 if (unwind.personality_routine == NULL)
bfae80f2 22184 {
c19d1205
ZW
22185 if (unwind.personality_index == -2)
22186 {
22187 if (have_data)
5f4273c7 22188 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22189 return 1; /* EXIDX_CANTUNWIND. */
22190 }
bfae80f2 22191
c19d1205
ZW
22192 /* Use a default personality routine if none is specified. */
22193 if (unwind.personality_index == -1)
22194 {
22195 if (unwind.opcode_count > 3)
22196 unwind.personality_index = 1;
22197 else
22198 unwind.personality_index = 0;
22199 }
bfae80f2 22200
c19d1205
ZW
22201 /* Space for the personality routine entry. */
22202 if (unwind.personality_index == 0)
22203 {
22204 if (unwind.opcode_count > 3)
22205 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22206
c19d1205
ZW
22207 if (!have_data)
22208 {
22209 /* All the data is inline in the index table. */
22210 data = 0x80;
22211 n = 3;
22212 while (unwind.opcode_count > 0)
22213 {
22214 unwind.opcode_count--;
22215 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22216 n--;
22217 }
bfae80f2 22218
c19d1205
ZW
22219 /* Pad with "finish" opcodes. */
22220 while (n--)
22221 data = (data << 8) | 0xb0;
bfae80f2 22222
c19d1205
ZW
22223 return data;
22224 }
22225 size = 0;
22226 }
22227 else
22228 /* We get two opcodes "free" in the first word. */
22229 size = unwind.opcode_count - 2;
22230 }
22231 else
5011093d 22232 {
cad0da33
NC
22233 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22234 if (unwind.personality_index != -1)
22235 {
22236 as_bad (_("attempt to recreate an unwind entry"));
22237 return 1;
22238 }
5011093d
NC
22239
22240 /* An extra byte is required for the opcode count. */
22241 size = unwind.opcode_count + 1;
22242 }
bfae80f2 22243
c19d1205
ZW
22244 size = (size + 3) >> 2;
22245 if (size > 0xff)
22246 as_bad (_("too many unwind opcodes"));
bfae80f2 22247
c19d1205
ZW
22248 frag_align (2, 0, 0);
22249 record_alignment (now_seg, 2);
22250 unwind.table_entry = expr_build_dot ();
22251
22252 /* Allocate the table entry. */
22253 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22254 /* PR 13449: Zero the table entries in case some of them are not used. */
22255 memset (ptr, 0, (size << 2) + 4);
c19d1205 22256 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22257
c19d1205 22258 switch (unwind.personality_index)
bfae80f2 22259 {
c19d1205
ZW
22260 case -1:
22261 /* ??? Should this be a PLT generating relocation? */
22262 /* Custom personality routine. */
22263 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22264 BFD_RELOC_ARM_PREL31);
bfae80f2 22265
c19d1205
ZW
22266 where += 4;
22267 ptr += 4;
bfae80f2 22268
c19d1205 22269 /* Set the first byte to the number of additional words. */
5011093d 22270 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22271 n = 3;
22272 break;
bfae80f2 22273
c19d1205
ZW
22274 /* ABI defined personality routines. */
22275 case 0:
22276 /* Three opcodes bytes are packed into the first word. */
22277 data = 0x80;
22278 n = 3;
22279 break;
bfae80f2 22280
c19d1205
ZW
22281 case 1:
22282 case 2:
22283 /* The size and first two opcode bytes go in the first word. */
22284 data = ((0x80 + unwind.personality_index) << 8) | size;
22285 n = 2;
22286 break;
bfae80f2 22287
c19d1205
ZW
22288 default:
22289 /* Should never happen. */
22290 abort ();
22291 }
bfae80f2 22292
c19d1205
ZW
22293 /* Pack the opcodes into words (MSB first), reversing the list at the same
22294 time. */
22295 while (unwind.opcode_count > 0)
22296 {
22297 if (n == 0)
22298 {
22299 md_number_to_chars (ptr, data, 4);
22300 ptr += 4;
22301 n = 4;
22302 data = 0;
22303 }
22304 unwind.opcode_count--;
22305 n--;
22306 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22307 }
22308
22309 /* Finish off the last word. */
22310 if (n < 4)
22311 {
22312 /* Pad with "finish" opcodes. */
22313 while (n--)
22314 data = (data << 8) | 0xb0;
22315
22316 md_number_to_chars (ptr, data, 4);
22317 }
22318
22319 if (!have_data)
22320 {
22321 /* Add an empty descriptor if there is no user-specified data. */
22322 ptr = frag_more (4);
22323 md_number_to_chars (ptr, 0, 4);
22324 }
22325
22326 return 0;
bfae80f2
RE
22327}
22328
f0927246
NC
22329
22330/* Initialize the DWARF-2 unwind information for this procedure. */
22331
22332void
22333tc_arm_frame_initial_instructions (void)
22334{
22335 cfi_add_CFA_def_cfa (REG_SP, 0);
22336}
22337#endif /* OBJ_ELF */
22338
c19d1205
ZW
22339/* Convert REGNAME to a DWARF-2 register number. */
22340
22341int
1df69f4f 22342tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22343{
1df69f4f 22344 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22345 if (reg != FAIL)
22346 return reg;
c19d1205 22347
1f5afe1c
NC
22348 /* PR 16694: Allow VFP registers as well. */
22349 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22350 if (reg != FAIL)
22351 return 64 + reg;
c19d1205 22352
1f5afe1c
NC
22353 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22354 if (reg != FAIL)
22355 return reg + 256;
22356
22357 return -1;
bfae80f2
RE
22358}
22359
f0927246 22360#ifdef TE_PE
c19d1205 22361void
f0927246 22362tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22363{
91d6fa6a 22364 expressionS exp;
bfae80f2 22365
91d6fa6a
NC
22366 exp.X_op = O_secrel;
22367 exp.X_add_symbol = symbol;
22368 exp.X_add_number = 0;
22369 emit_expr (&exp, size);
f0927246
NC
22370}
22371#endif
bfae80f2 22372
c19d1205 22373/* MD interface: Symbol and relocation handling. */
bfae80f2 22374
2fc8bdac
ZW
22375/* Return the address within the segment that a PC-relative fixup is
22376 relative to. For ARM, PC-relative fixups applied to instructions
22377 are generally relative to the location of the fixup plus 8 bytes.
22378 Thumb branches are offset by 4, and Thumb loads relative to PC
22379 require special handling. */
bfae80f2 22380
c19d1205 22381long
2fc8bdac 22382md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22383{
2fc8bdac
ZW
22384 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22385
22386 /* If this is pc-relative and we are going to emit a relocation
22387 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22388 will need. Otherwise we want to use the calculated base.
22389 For WinCE we skip the bias for externals as well, since this
22390 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22391 if (fixP->fx_pcrel
2fc8bdac 22392 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22393 || (arm_force_relocation (fixP)
22394#ifdef TE_WINCE
22395 && !S_IS_EXTERNAL (fixP->fx_addsy)
22396#endif
22397 )))
2fc8bdac 22398 base = 0;
bfae80f2 22399
267bf995 22400
c19d1205 22401 switch (fixP->fx_r_type)
bfae80f2 22402 {
2fc8bdac
ZW
22403 /* PC relative addressing on the Thumb is slightly odd as the
22404 bottom two bits of the PC are forced to zero for the
22405 calculation. This happens *after* application of the
22406 pipeline offset. However, Thumb adrl already adjusts for
22407 this, so we need not do it again. */
c19d1205 22408 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22409 return base & ~3;
c19d1205
ZW
22410
22411 case BFD_RELOC_ARM_THUMB_OFFSET:
22412 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22413 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22414 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22415 return (base + 4) & ~3;
c19d1205 22416
2fc8bdac
ZW
22417 /* Thumb branches are simply offset by +4. */
22418 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22419 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22420 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22421 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22422 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22423 return base + 4;
bfae80f2 22424
267bf995 22425 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22426 if (fixP->fx_addsy
22427 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22428 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22429 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22430 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22431 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22432 return base + 4;
22433
00adf2d4
JB
22434 /* BLX is like branches above, but forces the low two bits of PC to
22435 zero. */
486499d0
CL
22436 case BFD_RELOC_THUMB_PCREL_BLX:
22437 if (fixP->fx_addsy
22438 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22439 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22440 && THUMB_IS_FUNC (fixP->fx_addsy)
22441 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22442 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22443 return (base + 4) & ~3;
22444
2fc8bdac
ZW
22445 /* ARM mode branches are offset by +8. However, the Windows CE
22446 loader expects the relocation not to take this into account. */
267bf995 22447 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22448 if (fixP->fx_addsy
22449 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22450 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22451 && ARM_IS_FUNC (fixP->fx_addsy)
22452 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22453 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22454 return base + 8;
267bf995 22455
486499d0
CL
22456 case BFD_RELOC_ARM_PCREL_CALL:
22457 if (fixP->fx_addsy
22458 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22459 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22460 && THUMB_IS_FUNC (fixP->fx_addsy)
22461 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22462 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22463 return base + 8;
267bf995 22464
2fc8bdac 22465 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22466 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22467 case BFD_RELOC_ARM_PLT32:
c19d1205 22468#ifdef TE_WINCE
5f4273c7 22469 /* When handling fixups immediately, because we have already
477330fc 22470 discovered the value of a symbol, or the address of the frag involved
53baae48 22471 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22472 see fixup_segment() in write.c
22473 The S_IS_EXTERNAL test handles the case of global symbols.
22474 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22475 if (fixP->fx_pcrel
22476 && fixP->fx_addsy != NULL
22477 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22478 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22479 return base + 8;
2fc8bdac 22480 return base;
c19d1205 22481#else
2fc8bdac 22482 return base + 8;
c19d1205 22483#endif
2fc8bdac 22484
267bf995 22485
2fc8bdac
ZW
22486 /* ARM mode loads relative to PC are also offset by +8. Unlike
22487 branches, the Windows CE loader *does* expect the relocation
22488 to take this into account. */
22489 case BFD_RELOC_ARM_OFFSET_IMM:
22490 case BFD_RELOC_ARM_OFFSET_IMM8:
22491 case BFD_RELOC_ARM_HWLITERAL:
22492 case BFD_RELOC_ARM_LITERAL:
22493 case BFD_RELOC_ARM_CP_OFF_IMM:
22494 return base + 8;
22495
22496
22497 /* Other PC-relative relocations are un-offset. */
22498 default:
22499 return base;
22500 }
bfae80f2
RE
22501}
22502
8b2d793c
NC
22503static bfd_boolean flag_warn_syms = TRUE;
22504
ae8714c2
NC
22505bfd_boolean
22506arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22507{
8b2d793c
NC
22508 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22509 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22510 does mean that the resulting code might be very confusing to the reader.
22511 Also this warning can be triggered if the user omits an operand before
22512 an immediate address, eg:
22513
22514 LDR =foo
22515
22516 GAS treats this as an assignment of the value of the symbol foo to a
22517 symbol LDR, and so (without this code) it will not issue any kind of
22518 warning or error message.
22519
22520 Note - ARM instructions are case-insensitive but the strings in the hash
22521 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22522 lower case too. */
22523 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22524 {
22525 char * nbuf = strdup (name);
22526 char * p;
22527
22528 for (p = nbuf; *p; p++)
22529 *p = TOLOWER (*p);
22530 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22531 {
22532 static struct hash_control * already_warned = NULL;
22533
22534 if (already_warned == NULL)
22535 already_warned = hash_new ();
22536 /* Only warn about the symbol once. To keep the code
22537 simple we let hash_insert do the lookup for us. */
22538 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22539 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22540 }
22541 else
22542 free (nbuf);
22543 }
3739860c 22544
ae8714c2
NC
22545 return FALSE;
22546}
22547
22548/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22549 Otherwise we have no need to default values of symbols. */
22550
22551symbolS *
22552md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22553{
22554#ifdef OBJ_ELF
22555 if (name[0] == '_' && name[1] == 'G'
22556 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22557 {
22558 if (!GOT_symbol)
22559 {
22560 if (symbol_find (name))
22561 as_bad (_("GOT already in the symbol table"));
22562
22563 GOT_symbol = symbol_new (name, undefined_section,
22564 (valueT) 0, & zero_address_frag);
22565 }
22566
22567 return GOT_symbol;
22568 }
22569#endif
22570
c921be7d 22571 return NULL;
bfae80f2
RE
22572}
22573
55cf6793 22574/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22575 computed as two separate immediate values, added together. We
22576 already know that this value cannot be computed by just one ARM
22577 instruction. */
22578
22579static unsigned int
22580validate_immediate_twopart (unsigned int val,
22581 unsigned int * highpart)
bfae80f2 22582{
c19d1205
ZW
22583 unsigned int a;
22584 unsigned int i;
bfae80f2 22585
c19d1205
ZW
22586 for (i = 0; i < 32; i += 2)
22587 if (((a = rotate_left (val, i)) & 0xff) != 0)
22588 {
22589 if (a & 0xff00)
22590 {
22591 if (a & ~ 0xffff)
22592 continue;
22593 * highpart = (a >> 8) | ((i + 24) << 7);
22594 }
22595 else if (a & 0xff0000)
22596 {
22597 if (a & 0xff000000)
22598 continue;
22599 * highpart = (a >> 16) | ((i + 16) << 7);
22600 }
22601 else
22602 {
9c2799c2 22603 gas_assert (a & 0xff000000);
c19d1205
ZW
22604 * highpart = (a >> 24) | ((i + 8) << 7);
22605 }
bfae80f2 22606
c19d1205
ZW
22607 return (a & 0xff) | (i << 7);
22608 }
bfae80f2 22609
c19d1205 22610 return FAIL;
bfae80f2
RE
22611}
22612
c19d1205
ZW
22613static int
22614validate_offset_imm (unsigned int val, int hwse)
22615{
22616 if ((hwse && val > 255) || val > 4095)
22617 return FAIL;
22618 return val;
22619}
bfae80f2 22620
55cf6793 22621/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22622 negative immediate constant by altering the instruction. A bit of
22623 a hack really.
22624 MOV <-> MVN
22625 AND <-> BIC
22626 ADC <-> SBC
22627 by inverting the second operand, and
22628 ADD <-> SUB
22629 CMP <-> CMN
22630 by negating the second operand. */
bfae80f2 22631
c19d1205
ZW
22632static int
22633negate_data_op (unsigned long * instruction,
22634 unsigned long value)
bfae80f2 22635{
c19d1205
ZW
22636 int op, new_inst;
22637 unsigned long negated, inverted;
bfae80f2 22638
c19d1205
ZW
22639 negated = encode_arm_immediate (-value);
22640 inverted = encode_arm_immediate (~value);
bfae80f2 22641
c19d1205
ZW
22642 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22643 switch (op)
bfae80f2 22644 {
c19d1205
ZW
22645 /* First negates. */
22646 case OPCODE_SUB: /* ADD <-> SUB */
22647 new_inst = OPCODE_ADD;
22648 value = negated;
22649 break;
bfae80f2 22650
c19d1205
ZW
22651 case OPCODE_ADD:
22652 new_inst = OPCODE_SUB;
22653 value = negated;
22654 break;
bfae80f2 22655
c19d1205
ZW
22656 case OPCODE_CMP: /* CMP <-> CMN */
22657 new_inst = OPCODE_CMN;
22658 value = negated;
22659 break;
bfae80f2 22660
c19d1205
ZW
22661 case OPCODE_CMN:
22662 new_inst = OPCODE_CMP;
22663 value = negated;
22664 break;
bfae80f2 22665
c19d1205
ZW
22666 /* Now Inverted ops. */
22667 case OPCODE_MOV: /* MOV <-> MVN */
22668 new_inst = OPCODE_MVN;
22669 value = inverted;
22670 break;
bfae80f2 22671
c19d1205
ZW
22672 case OPCODE_MVN:
22673 new_inst = OPCODE_MOV;
22674 value = inverted;
22675 break;
bfae80f2 22676
c19d1205
ZW
22677 case OPCODE_AND: /* AND <-> BIC */
22678 new_inst = OPCODE_BIC;
22679 value = inverted;
22680 break;
bfae80f2 22681
c19d1205
ZW
22682 case OPCODE_BIC:
22683 new_inst = OPCODE_AND;
22684 value = inverted;
22685 break;
bfae80f2 22686
c19d1205
ZW
22687 case OPCODE_ADC: /* ADC <-> SBC */
22688 new_inst = OPCODE_SBC;
22689 value = inverted;
22690 break;
bfae80f2 22691
c19d1205
ZW
22692 case OPCODE_SBC:
22693 new_inst = OPCODE_ADC;
22694 value = inverted;
22695 break;
bfae80f2 22696
c19d1205
ZW
22697 /* We cannot do anything. */
22698 default:
22699 return FAIL;
b99bd4ef
NC
22700 }
22701
c19d1205
ZW
22702 if (value == (unsigned) FAIL)
22703 return FAIL;
22704
22705 *instruction &= OPCODE_MASK;
22706 *instruction |= new_inst << DATA_OP_SHIFT;
22707 return value;
b99bd4ef
NC
22708}
22709
ef8d22e6
PB
22710/* Like negate_data_op, but for Thumb-2. */
22711
22712static unsigned int
16dd5e42 22713thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22714{
22715 int op, new_inst;
22716 int rd;
16dd5e42 22717 unsigned int negated, inverted;
ef8d22e6
PB
22718
22719 negated = encode_thumb32_immediate (-value);
22720 inverted = encode_thumb32_immediate (~value);
22721
22722 rd = (*instruction >> 8) & 0xf;
22723 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22724 switch (op)
22725 {
22726 /* ADD <-> SUB. Includes CMP <-> CMN. */
22727 case T2_OPCODE_SUB:
22728 new_inst = T2_OPCODE_ADD;
22729 value = negated;
22730 break;
22731
22732 case T2_OPCODE_ADD:
22733 new_inst = T2_OPCODE_SUB;
22734 value = negated;
22735 break;
22736
22737 /* ORR <-> ORN. Includes MOV <-> MVN. */
22738 case T2_OPCODE_ORR:
22739 new_inst = T2_OPCODE_ORN;
22740 value = inverted;
22741 break;
22742
22743 case T2_OPCODE_ORN:
22744 new_inst = T2_OPCODE_ORR;
22745 value = inverted;
22746 break;
22747
22748 /* AND <-> BIC. TST has no inverted equivalent. */
22749 case T2_OPCODE_AND:
22750 new_inst = T2_OPCODE_BIC;
22751 if (rd == 15)
22752 value = FAIL;
22753 else
22754 value = inverted;
22755 break;
22756
22757 case T2_OPCODE_BIC:
22758 new_inst = T2_OPCODE_AND;
22759 value = inverted;
22760 break;
22761
22762 /* ADC <-> SBC */
22763 case T2_OPCODE_ADC:
22764 new_inst = T2_OPCODE_SBC;
22765 value = inverted;
22766 break;
22767
22768 case T2_OPCODE_SBC:
22769 new_inst = T2_OPCODE_ADC;
22770 value = inverted;
22771 break;
22772
22773 /* We cannot do anything. */
22774 default:
22775 return FAIL;
22776 }
22777
16dd5e42 22778 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22779 return FAIL;
22780
22781 *instruction &= T2_OPCODE_MASK;
22782 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22783 return value;
22784}
22785
8f06b2d8
PB
22786/* Read a 32-bit thumb instruction from buf. */
22787static unsigned long
22788get_thumb32_insn (char * buf)
22789{
22790 unsigned long insn;
22791 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22792 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22793
22794 return insn;
22795}
22796
a8bc6c78
PB
22797
22798/* We usually want to set the low bit on the address of thumb function
22799 symbols. In particular .word foo - . should have the low bit set.
22800 Generic code tries to fold the difference of two symbols to
22801 a constant. Prevent this and force a relocation when the first symbols
22802 is a thumb function. */
c921be7d
NC
22803
22804bfd_boolean
a8bc6c78
PB
22805arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22806{
22807 if (op == O_subtract
22808 && l->X_op == O_symbol
22809 && r->X_op == O_symbol
22810 && THUMB_IS_FUNC (l->X_add_symbol))
22811 {
22812 l->X_op = O_subtract;
22813 l->X_op_symbol = r->X_add_symbol;
22814 l->X_add_number -= r->X_add_number;
c921be7d 22815 return TRUE;
a8bc6c78 22816 }
c921be7d 22817
a8bc6c78 22818 /* Process as normal. */
c921be7d 22819 return FALSE;
a8bc6c78
PB
22820}
22821
4a42ebbc
RR
22822/* Encode Thumb2 unconditional branches and calls. The encoding
22823 for the 2 are identical for the immediate values. */
22824
22825static void
22826encode_thumb2_b_bl_offset (char * buf, offsetT value)
22827{
22828#define T2I1I2MASK ((1 << 13) | (1 << 11))
22829 offsetT newval;
22830 offsetT newval2;
22831 addressT S, I1, I2, lo, hi;
22832
22833 S = (value >> 24) & 0x01;
22834 I1 = (value >> 23) & 0x01;
22835 I2 = (value >> 22) & 0x01;
22836 hi = (value >> 12) & 0x3ff;
fa94de6b 22837 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22838 newval = md_chars_to_number (buf, THUMB_SIZE);
22839 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22840 newval |= (S << 10) | hi;
22841 newval2 &= ~T2I1I2MASK;
22842 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22843 md_number_to_chars (buf, newval, THUMB_SIZE);
22844 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22845}
22846
c19d1205 22847void
55cf6793 22848md_apply_fix (fixS * fixP,
c19d1205
ZW
22849 valueT * valP,
22850 segT seg)
22851{
22852 offsetT value = * valP;
22853 offsetT newval;
22854 unsigned int newimm;
22855 unsigned long temp;
22856 int sign;
22857 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22858
9c2799c2 22859 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22860
c19d1205 22861 /* Note whether this will delete the relocation. */
4962c51a 22862
c19d1205
ZW
22863 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22864 fixP->fx_done = 1;
b99bd4ef 22865
adbaf948 22866 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22867 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22868 for emit_reloc. */
22869 value &= 0xffffffff;
22870 value ^= 0x80000000;
5f4273c7 22871 value -= 0x80000000;
adbaf948
ZW
22872
22873 *valP = value;
c19d1205 22874 fixP->fx_addnumber = value;
b99bd4ef 22875
adbaf948
ZW
22876 /* Same treatment for fixP->fx_offset. */
22877 fixP->fx_offset &= 0xffffffff;
22878 fixP->fx_offset ^= 0x80000000;
22879 fixP->fx_offset -= 0x80000000;
22880
c19d1205 22881 switch (fixP->fx_r_type)
b99bd4ef 22882 {
c19d1205
ZW
22883 case BFD_RELOC_NONE:
22884 /* This will need to go in the object file. */
22885 fixP->fx_done = 0;
22886 break;
b99bd4ef 22887
c19d1205
ZW
22888 case BFD_RELOC_ARM_IMMEDIATE:
22889 /* We claim that this fixup has been processed here,
22890 even if in fact we generate an error because we do
22891 not have a reloc for it, so tc_gen_reloc will reject it. */
22892 fixP->fx_done = 1;
b99bd4ef 22893
77db8e2e 22894 if (fixP->fx_addsy)
b99bd4ef 22895 {
77db8e2e 22896 const char *msg = 0;
b99bd4ef 22897
77db8e2e
NC
22898 if (! S_IS_DEFINED (fixP->fx_addsy))
22899 msg = _("undefined symbol %s used as an immediate value");
22900 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22901 msg = _("symbol %s is in a different section");
22902 else if (S_IS_WEAK (fixP->fx_addsy))
22903 msg = _("symbol %s is weak and may be overridden later");
22904
22905 if (msg)
22906 {
22907 as_bad_where (fixP->fx_file, fixP->fx_line,
22908 msg, S_GET_NAME (fixP->fx_addsy));
22909 break;
22910 }
42e5fcbf
AS
22911 }
22912
c19d1205
ZW
22913 temp = md_chars_to_number (buf, INSN_SIZE);
22914
5e73442d
SL
22915 /* If the offset is negative, we should use encoding A2 for ADR. */
22916 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22917 newimm = negate_data_op (&temp, value);
22918 else
22919 {
22920 newimm = encode_arm_immediate (value);
22921
22922 /* If the instruction will fail, see if we can fix things up by
22923 changing the opcode. */
22924 if (newimm == (unsigned int) FAIL)
22925 newimm = negate_data_op (&temp, value);
bada4342
JW
22926 /* MOV accepts both ARM modified immediate (A1 encoding) and
22927 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
22928 When disassembling, MOV is preferred when there is no encoding
22929 overlap. */
22930 if (newimm == (unsigned int) FAIL
22931 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
22932 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
22933 && !((temp >> SBIT_SHIFT) & 0x1)
22934 && value >= 0 && value <= 0xffff)
22935 {
22936 /* Clear bits[23:20] to change encoding from A1 to A2. */
22937 temp &= 0xff0fffff;
22938 /* Encoding high 4bits imm. Code below will encode the remaining
22939 low 12bits. */
22940 temp |= (value & 0x0000f000) << 4;
22941 newimm = value & 0x00000fff;
22942 }
5e73442d
SL
22943 }
22944
22945 if (newimm == (unsigned int) FAIL)
b99bd4ef 22946 {
c19d1205
ZW
22947 as_bad_where (fixP->fx_file, fixP->fx_line,
22948 _("invalid constant (%lx) after fixup"),
22949 (unsigned long) value);
22950 break;
b99bd4ef 22951 }
b99bd4ef 22952
c19d1205
ZW
22953 newimm |= (temp & 0xfffff000);
22954 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22955 break;
b99bd4ef 22956
c19d1205
ZW
22957 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22958 {
22959 unsigned int highpart = 0;
22960 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22961
77db8e2e 22962 if (fixP->fx_addsy)
42e5fcbf 22963 {
77db8e2e 22964 const char *msg = 0;
42e5fcbf 22965
77db8e2e
NC
22966 if (! S_IS_DEFINED (fixP->fx_addsy))
22967 msg = _("undefined symbol %s used as an immediate value");
22968 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22969 msg = _("symbol %s is in a different section");
22970 else if (S_IS_WEAK (fixP->fx_addsy))
22971 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22972
77db8e2e
NC
22973 if (msg)
22974 {
22975 as_bad_where (fixP->fx_file, fixP->fx_line,
22976 msg, S_GET_NAME (fixP->fx_addsy));
22977 break;
22978 }
22979 }
fa94de6b 22980
c19d1205
ZW
22981 newimm = encode_arm_immediate (value);
22982 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22983
c19d1205
ZW
22984 /* If the instruction will fail, see if we can fix things up by
22985 changing the opcode. */
22986 if (newimm == (unsigned int) FAIL
22987 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22988 {
22989 /* No ? OK - try using two ADD instructions to generate
22990 the value. */
22991 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22992
c19d1205
ZW
22993 /* Yes - then make sure that the second instruction is
22994 also an add. */
22995 if (newimm != (unsigned int) FAIL)
22996 newinsn = temp;
22997 /* Still No ? Try using a negated value. */
22998 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22999 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23000 /* Otherwise - give up. */
23001 else
23002 {
23003 as_bad_where (fixP->fx_file, fixP->fx_line,
23004 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23005 (long) value);
23006 break;
23007 }
b99bd4ef 23008
c19d1205
ZW
23009 /* Replace the first operand in the 2nd instruction (which
23010 is the PC) with the destination register. We have
23011 already added in the PC in the first instruction and we
23012 do not want to do it again. */
23013 newinsn &= ~ 0xf0000;
23014 newinsn |= ((newinsn & 0x0f000) << 4);
23015 }
b99bd4ef 23016
c19d1205
ZW
23017 newimm |= (temp & 0xfffff000);
23018 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23019
c19d1205
ZW
23020 highpart |= (newinsn & 0xfffff000);
23021 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23022 }
23023 break;
b99bd4ef 23024
c19d1205 23025 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23026 if (!fixP->fx_done && seg->use_rela_p)
23027 value = 0;
1a0670f3 23028 /* Fall through. */
00a97672 23029
c19d1205 23030 case BFD_RELOC_ARM_LITERAL:
26d97720 23031 sign = value > 0;
b99bd4ef 23032
c19d1205
ZW
23033 if (value < 0)
23034 value = - value;
b99bd4ef 23035
c19d1205 23036 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23037 {
c19d1205
ZW
23038 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23039 as_bad_where (fixP->fx_file, fixP->fx_line,
23040 _("invalid literal constant: pool needs to be closer"));
23041 else
23042 as_bad_where (fixP->fx_file, fixP->fx_line,
23043 _("bad immediate value for offset (%ld)"),
23044 (long) value);
23045 break;
f03698e6
RE
23046 }
23047
c19d1205 23048 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23049 if (value == 0)
23050 newval &= 0xfffff000;
23051 else
23052 {
23053 newval &= 0xff7ff000;
23054 newval |= value | (sign ? INDEX_UP : 0);
23055 }
c19d1205
ZW
23056 md_number_to_chars (buf, newval, INSN_SIZE);
23057 break;
b99bd4ef 23058
c19d1205
ZW
23059 case BFD_RELOC_ARM_OFFSET_IMM8:
23060 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23061 sign = value > 0;
b99bd4ef 23062
c19d1205
ZW
23063 if (value < 0)
23064 value = - value;
b99bd4ef 23065
c19d1205 23066 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23067 {
c19d1205
ZW
23068 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23069 as_bad_where (fixP->fx_file, fixP->fx_line,
23070 _("invalid literal constant: pool needs to be closer"));
23071 else
427d0db6
RM
23072 as_bad_where (fixP->fx_file, fixP->fx_line,
23073 _("bad immediate value for 8-bit offset (%ld)"),
23074 (long) value);
c19d1205 23075 break;
b99bd4ef
NC
23076 }
23077
c19d1205 23078 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23079 if (value == 0)
23080 newval &= 0xfffff0f0;
23081 else
23082 {
23083 newval &= 0xff7ff0f0;
23084 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23085 }
c19d1205
ZW
23086 md_number_to_chars (buf, newval, INSN_SIZE);
23087 break;
b99bd4ef 23088
c19d1205
ZW
23089 case BFD_RELOC_ARM_T32_OFFSET_U8:
23090 if (value < 0 || value > 1020 || value % 4 != 0)
23091 as_bad_where (fixP->fx_file, fixP->fx_line,
23092 _("bad immediate value for offset (%ld)"), (long) value);
23093 value /= 4;
b99bd4ef 23094
c19d1205 23095 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23096 newval |= value;
23097 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23098 break;
b99bd4ef 23099
c19d1205
ZW
23100 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23101 /* This is a complicated relocation used for all varieties of Thumb32
23102 load/store instruction with immediate offset:
23103
23104 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23105 *4, optional writeback(W)
c19d1205
ZW
23106 (doubleword load/store)
23107
23108 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23109 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23110 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23111 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23112 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23113
23114 Uppercase letters indicate bits that are already encoded at
23115 this point. Lowercase letters are our problem. For the
23116 second block of instructions, the secondary opcode nybble
23117 (bits 8..11) is present, and bit 23 is zero, even if this is
23118 a PC-relative operation. */
23119 newval = md_chars_to_number (buf, THUMB_SIZE);
23120 newval <<= 16;
23121 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23122
c19d1205 23123 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23124 {
c19d1205
ZW
23125 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23126 if (value >= 0)
23127 newval |= (1 << 23);
23128 else
23129 value = -value;
23130 if (value % 4 != 0)
23131 {
23132 as_bad_where (fixP->fx_file, fixP->fx_line,
23133 _("offset not a multiple of 4"));
23134 break;
23135 }
23136 value /= 4;
216d22bc 23137 if (value > 0xff)
c19d1205
ZW
23138 {
23139 as_bad_where (fixP->fx_file, fixP->fx_line,
23140 _("offset out of range"));
23141 break;
23142 }
23143 newval &= ~0xff;
b99bd4ef 23144 }
c19d1205 23145 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23146 {
c19d1205
ZW
23147 /* PC-relative, 12-bit offset. */
23148 if (value >= 0)
23149 newval |= (1 << 23);
23150 else
23151 value = -value;
216d22bc 23152 if (value > 0xfff)
c19d1205
ZW
23153 {
23154 as_bad_where (fixP->fx_file, fixP->fx_line,
23155 _("offset out of range"));
23156 break;
23157 }
23158 newval &= ~0xfff;
b99bd4ef 23159 }
c19d1205 23160 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23161 {
c19d1205
ZW
23162 /* Writeback: 8-bit, +/- offset. */
23163 if (value >= 0)
23164 newval |= (1 << 9);
23165 else
23166 value = -value;
216d22bc 23167 if (value > 0xff)
c19d1205
ZW
23168 {
23169 as_bad_where (fixP->fx_file, fixP->fx_line,
23170 _("offset out of range"));
23171 break;
23172 }
23173 newval &= ~0xff;
b99bd4ef 23174 }
c19d1205 23175 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23176 {
c19d1205 23177 /* T-instruction: positive 8-bit offset. */
216d22bc 23178 if (value < 0 || value > 0xff)
b99bd4ef 23179 {
c19d1205
ZW
23180 as_bad_where (fixP->fx_file, fixP->fx_line,
23181 _("offset out of range"));
23182 break;
b99bd4ef 23183 }
c19d1205
ZW
23184 newval &= ~0xff;
23185 newval |= value;
b99bd4ef
NC
23186 }
23187 else
b99bd4ef 23188 {
c19d1205
ZW
23189 /* Positive 12-bit or negative 8-bit offset. */
23190 int limit;
23191 if (value >= 0)
b99bd4ef 23192 {
c19d1205
ZW
23193 newval |= (1 << 23);
23194 limit = 0xfff;
23195 }
23196 else
23197 {
23198 value = -value;
23199 limit = 0xff;
23200 }
23201 if (value > limit)
23202 {
23203 as_bad_where (fixP->fx_file, fixP->fx_line,
23204 _("offset out of range"));
23205 break;
b99bd4ef 23206 }
c19d1205 23207 newval &= ~limit;
b99bd4ef 23208 }
b99bd4ef 23209
c19d1205
ZW
23210 newval |= value;
23211 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23212 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23213 break;
404ff6b5 23214
c19d1205
ZW
23215 case BFD_RELOC_ARM_SHIFT_IMM:
23216 newval = md_chars_to_number (buf, INSN_SIZE);
23217 if (((unsigned long) value) > 32
23218 || (value == 32
23219 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23220 {
23221 as_bad_where (fixP->fx_file, fixP->fx_line,
23222 _("shift expression is too large"));
23223 break;
23224 }
404ff6b5 23225
c19d1205
ZW
23226 if (value == 0)
23227 /* Shifts of zero must be done as lsl. */
23228 newval &= ~0x60;
23229 else if (value == 32)
23230 value = 0;
23231 newval &= 0xfffff07f;
23232 newval |= (value & 0x1f) << 7;
23233 md_number_to_chars (buf, newval, INSN_SIZE);
23234 break;
404ff6b5 23235
c19d1205 23236 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23237 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23238 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23239 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23240 /* We claim that this fixup has been processed here,
23241 even if in fact we generate an error because we do
23242 not have a reloc for it, so tc_gen_reloc will reject it. */
23243 fixP->fx_done = 1;
404ff6b5 23244
c19d1205
ZW
23245 if (fixP->fx_addsy
23246 && ! S_IS_DEFINED (fixP->fx_addsy))
23247 {
23248 as_bad_where (fixP->fx_file, fixP->fx_line,
23249 _("undefined symbol %s used as an immediate value"),
23250 S_GET_NAME (fixP->fx_addsy));
23251 break;
23252 }
404ff6b5 23253
c19d1205
ZW
23254 newval = md_chars_to_number (buf, THUMB_SIZE);
23255 newval <<= 16;
23256 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23257
16805f35 23258 newimm = FAIL;
bada4342
JW
23259 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23260 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23261 Thumb2 modified immediate encoding (T2). */
23262 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23263 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23264 {
23265 newimm = encode_thumb32_immediate (value);
23266 if (newimm == (unsigned int) FAIL)
23267 newimm = thumb32_negate_data_op (&newval, value);
23268 }
bada4342 23269 if (newimm == (unsigned int) FAIL)
92e90b6e 23270 {
bada4342 23271 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23272 {
bada4342
JW
23273 /* Turn add/sum into addw/subw. */
23274 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23275 newval = (newval & 0xfeffffff) | 0x02000000;
23276 /* No flat 12-bit imm encoding for addsw/subsw. */
23277 if ((newval & 0x00100000) == 0)
40f246e3 23278 {
bada4342
JW
23279 /* 12 bit immediate for addw/subw. */
23280 if (value < 0)
23281 {
23282 value = -value;
23283 newval ^= 0x00a00000;
23284 }
23285 if (value > 0xfff)
23286 newimm = (unsigned int) FAIL;
23287 else
23288 newimm = value;
23289 }
23290 }
23291 else
23292 {
23293 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23294 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23295 disassembling, MOV is preferred when there is no encoding
23296 overlap.
23297 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23298 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23299 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23300 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23301 && value >= 0 && value <=0xffff)
23302 {
23303 /* Toggle bit[25] to change encoding from T2 to T3. */
23304 newval ^= 1 << 25;
23305 /* Clear bits[19:16]. */
23306 newval &= 0xfff0ffff;
23307 /* Encoding high 4bits imm. Code below will encode the
23308 remaining low 12bits. */
23309 newval |= (value & 0x0000f000) << 4;
23310 newimm = value & 0x00000fff;
40f246e3 23311 }
e9f89963 23312 }
92e90b6e 23313 }
cc8a6dd0 23314
c19d1205 23315 if (newimm == (unsigned int)FAIL)
3631a3c8 23316 {
c19d1205
ZW
23317 as_bad_where (fixP->fx_file, fixP->fx_line,
23318 _("invalid constant (%lx) after fixup"),
23319 (unsigned long) value);
23320 break;
3631a3c8
NC
23321 }
23322
c19d1205
ZW
23323 newval |= (newimm & 0x800) << 15;
23324 newval |= (newimm & 0x700) << 4;
23325 newval |= (newimm & 0x0ff);
cc8a6dd0 23326
c19d1205
ZW
23327 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23328 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23329 break;
a737bd4d 23330
3eb17e6b 23331 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23332 if (((unsigned long) value) > 0xffff)
23333 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23334 _("invalid smc expression"));
2fc8bdac 23335 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23336 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23337 md_number_to_chars (buf, newval, INSN_SIZE);
23338 break;
a737bd4d 23339
90ec0d68
MGD
23340 case BFD_RELOC_ARM_HVC:
23341 if (((unsigned long) value) > 0xffff)
23342 as_bad_where (fixP->fx_file, fixP->fx_line,
23343 _("invalid hvc expression"));
23344 newval = md_chars_to_number (buf, INSN_SIZE);
23345 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23346 md_number_to_chars (buf, newval, INSN_SIZE);
23347 break;
23348
c19d1205 23349 case BFD_RELOC_ARM_SWI:
adbaf948 23350 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23351 {
23352 if (((unsigned long) value) > 0xff)
23353 as_bad_where (fixP->fx_file, fixP->fx_line,
23354 _("invalid swi expression"));
2fc8bdac 23355 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23356 newval |= value;
23357 md_number_to_chars (buf, newval, THUMB_SIZE);
23358 }
23359 else
23360 {
23361 if (((unsigned long) value) > 0x00ffffff)
23362 as_bad_where (fixP->fx_file, fixP->fx_line,
23363 _("invalid swi expression"));
2fc8bdac 23364 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23365 newval |= value;
23366 md_number_to_chars (buf, newval, INSN_SIZE);
23367 }
23368 break;
a737bd4d 23369
c19d1205
ZW
23370 case BFD_RELOC_ARM_MULTI:
23371 if (((unsigned long) value) > 0xffff)
23372 as_bad_where (fixP->fx_file, fixP->fx_line,
23373 _("invalid expression in load/store multiple"));
23374 newval = value | md_chars_to_number (buf, INSN_SIZE);
23375 md_number_to_chars (buf, newval, INSN_SIZE);
23376 break;
a737bd4d 23377
c19d1205 23378#ifdef OBJ_ELF
39b41c9c 23379 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23380
23381 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23382 && fixP->fx_addsy
34e77a92 23383 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23384 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23385 && THUMB_IS_FUNC (fixP->fx_addsy))
23386 /* Flip the bl to blx. This is a simple flip
23387 bit here because we generate PCREL_CALL for
23388 unconditional bls. */
23389 {
23390 newval = md_chars_to_number (buf, INSN_SIZE);
23391 newval = newval | 0x10000000;
23392 md_number_to_chars (buf, newval, INSN_SIZE);
23393 temp = 1;
23394 fixP->fx_done = 1;
23395 }
39b41c9c
PB
23396 else
23397 temp = 3;
23398 goto arm_branch_common;
23399
23400 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23401 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23402 && fixP->fx_addsy
34e77a92 23403 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23404 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23405 && THUMB_IS_FUNC (fixP->fx_addsy))
23406 {
23407 /* This would map to a bl<cond>, b<cond>,
23408 b<always> to a Thumb function. We
23409 need to force a relocation for this particular
23410 case. */
23411 newval = md_chars_to_number (buf, INSN_SIZE);
23412 fixP->fx_done = 0;
23413 }
1a0670f3 23414 /* Fall through. */
267bf995 23415
2fc8bdac 23416 case BFD_RELOC_ARM_PLT32:
c19d1205 23417#endif
39b41c9c
PB
23418 case BFD_RELOC_ARM_PCREL_BRANCH:
23419 temp = 3;
23420 goto arm_branch_common;
a737bd4d 23421
39b41c9c 23422 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23423
39b41c9c 23424 temp = 1;
267bf995
RR
23425 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23426 && fixP->fx_addsy
34e77a92 23427 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23428 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23429 && ARM_IS_FUNC (fixP->fx_addsy))
23430 {
23431 /* Flip the blx to a bl and warn. */
23432 const char *name = S_GET_NAME (fixP->fx_addsy);
23433 newval = 0xeb000000;
23434 as_warn_where (fixP->fx_file, fixP->fx_line,
23435 _("blx to '%s' an ARM ISA state function changed to bl"),
23436 name);
23437 md_number_to_chars (buf, newval, INSN_SIZE);
23438 temp = 3;
23439 fixP->fx_done = 1;
23440 }
23441
23442#ifdef OBJ_ELF
23443 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23444 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23445#endif
23446
39b41c9c 23447 arm_branch_common:
c19d1205 23448 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23449 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23450 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23451 also be be clear. */
23452 if (value & temp)
c19d1205 23453 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23454 _("misaligned branch destination"));
23455 if ((value & (offsetT)0xfe000000) != (offsetT)0
23456 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23457 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23458
2fc8bdac 23459 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23460 {
2fc8bdac
ZW
23461 newval = md_chars_to_number (buf, INSN_SIZE);
23462 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23463 /* Set the H bit on BLX instructions. */
23464 if (temp == 1)
23465 {
23466 if (value & 2)
23467 newval |= 0x01000000;
23468 else
23469 newval &= ~0x01000000;
23470 }
2fc8bdac 23471 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23472 }
c19d1205 23473 break;
a737bd4d 23474
25fe350b
MS
23475 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23476 /* CBZ can only branch forward. */
a737bd4d 23477
738755b0 23478 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23479 (which, strictly speaking, are prohibited) will be turned into
23480 no-ops.
738755b0
MS
23481
23482 FIXME: It may be better to remove the instruction completely and
23483 perform relaxation. */
23484 if (value == -2)
2fc8bdac
ZW
23485 {
23486 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23487 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23488 md_number_to_chars (buf, newval, THUMB_SIZE);
23489 }
738755b0
MS
23490 else
23491 {
23492 if (value & ~0x7e)
08f10d51 23493 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23494
477330fc 23495 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23496 {
23497 newval = md_chars_to_number (buf, THUMB_SIZE);
23498 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23499 md_number_to_chars (buf, newval, THUMB_SIZE);
23500 }
23501 }
c19d1205 23502 break;
a737bd4d 23503
c19d1205 23504 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23505 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23506 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23507
2fc8bdac
ZW
23508 if (fixP->fx_done || !seg->use_rela_p)
23509 {
23510 newval = md_chars_to_number (buf, THUMB_SIZE);
23511 newval |= (value & 0x1ff) >> 1;
23512 md_number_to_chars (buf, newval, THUMB_SIZE);
23513 }
c19d1205 23514 break;
a737bd4d 23515
c19d1205 23516 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23517 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23518 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23519
2fc8bdac
ZW
23520 if (fixP->fx_done || !seg->use_rela_p)
23521 {
23522 newval = md_chars_to_number (buf, THUMB_SIZE);
23523 newval |= (value & 0xfff) >> 1;
23524 md_number_to_chars (buf, newval, THUMB_SIZE);
23525 }
c19d1205 23526 break;
a737bd4d 23527
c19d1205 23528 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23529 if (fixP->fx_addsy
23530 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23531 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23532 && ARM_IS_FUNC (fixP->fx_addsy)
23533 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23534 {
23535 /* Force a relocation for a branch 20 bits wide. */
23536 fixP->fx_done = 0;
23537 }
08f10d51 23538 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23539 as_bad_where (fixP->fx_file, fixP->fx_line,
23540 _("conditional branch out of range"));
404ff6b5 23541
2fc8bdac
ZW
23542 if (fixP->fx_done || !seg->use_rela_p)
23543 {
23544 offsetT newval2;
23545 addressT S, J1, J2, lo, hi;
404ff6b5 23546
2fc8bdac
ZW
23547 S = (value & 0x00100000) >> 20;
23548 J2 = (value & 0x00080000) >> 19;
23549 J1 = (value & 0x00040000) >> 18;
23550 hi = (value & 0x0003f000) >> 12;
23551 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23552
2fc8bdac
ZW
23553 newval = md_chars_to_number (buf, THUMB_SIZE);
23554 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23555 newval |= (S << 10) | hi;
23556 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23557 md_number_to_chars (buf, newval, THUMB_SIZE);
23558 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23559 }
c19d1205 23560 break;
6c43fab6 23561
c19d1205 23562 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23563 /* If there is a blx from a thumb state function to
23564 another thumb function flip this to a bl and warn
23565 about it. */
23566
23567 if (fixP->fx_addsy
34e77a92 23568 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23569 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23570 && THUMB_IS_FUNC (fixP->fx_addsy))
23571 {
23572 const char *name = S_GET_NAME (fixP->fx_addsy);
23573 as_warn_where (fixP->fx_file, fixP->fx_line,
23574 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23575 name);
23576 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23577 newval = newval | 0x1000;
23578 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23579 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23580 fixP->fx_done = 1;
23581 }
23582
23583
23584 goto thumb_bl_common;
23585
c19d1205 23586 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23587 /* A bl from Thumb state ISA to an internal ARM state function
23588 is converted to a blx. */
23589 if (fixP->fx_addsy
23590 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23591 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23592 && ARM_IS_FUNC (fixP->fx_addsy)
23593 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23594 {
23595 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23596 newval = newval & ~0x1000;
23597 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23598 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23599 fixP->fx_done = 1;
23600 }
23601
23602 thumb_bl_common:
23603
2fc8bdac
ZW
23604 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23605 /* For a BLX instruction, make sure that the relocation is rounded up
23606 to a word boundary. This follows the semantics of the instruction
23607 which specifies that bit 1 of the target address will come from bit
23608 1 of the base address. */
d406f3e4
JB
23609 value = (value + 3) & ~ 3;
23610
23611#ifdef OBJ_ELF
23612 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23613 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23614 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23615#endif
404ff6b5 23616
2b2f5df9
NC
23617 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23618 {
fc289b0a 23619 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23620 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23621 else if ((value & ~0x1ffffff)
23622 && ((value & ~0x1ffffff) != ~0x1ffffff))
23623 as_bad_where (fixP->fx_file, fixP->fx_line,
23624 _("Thumb2 branch out of range"));
23625 }
4a42ebbc
RR
23626
23627 if (fixP->fx_done || !seg->use_rela_p)
23628 encode_thumb2_b_bl_offset (buf, value);
23629
c19d1205 23630 break;
404ff6b5 23631
c19d1205 23632 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23633 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23634 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23635
2fc8bdac 23636 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23637 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23638
2fc8bdac 23639 break;
a737bd4d 23640
2fc8bdac
ZW
23641 case BFD_RELOC_8:
23642 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23643 *buf = value;
c19d1205 23644 break;
a737bd4d 23645
c19d1205 23646 case BFD_RELOC_16:
2fc8bdac 23647 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23648 md_number_to_chars (buf, value, 2);
c19d1205 23649 break;
a737bd4d 23650
c19d1205 23651#ifdef OBJ_ELF
0855e32b
NS
23652 case BFD_RELOC_ARM_TLS_CALL:
23653 case BFD_RELOC_ARM_THM_TLS_CALL:
23654 case BFD_RELOC_ARM_TLS_DESCSEQ:
23655 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23656 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23657 case BFD_RELOC_ARM_TLS_GD32:
23658 case BFD_RELOC_ARM_TLS_LE32:
23659 case BFD_RELOC_ARM_TLS_IE32:
23660 case BFD_RELOC_ARM_TLS_LDM32:
23661 case BFD_RELOC_ARM_TLS_LDO32:
23662 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23663 break;
6c43fab6 23664
c19d1205
ZW
23665 case BFD_RELOC_ARM_GOT32:
23666 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23667 break;
b43420e6
NC
23668
23669 case BFD_RELOC_ARM_GOT_PREL:
23670 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23671 md_number_to_chars (buf, value, 4);
b43420e6
NC
23672 break;
23673
9a6f4e97
NS
23674 case BFD_RELOC_ARM_TARGET2:
23675 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23676 addend here for REL targets, because it won't be written out
23677 during reloc processing later. */
9a6f4e97
NS
23678 if (fixP->fx_done || !seg->use_rela_p)
23679 md_number_to_chars (buf, fixP->fx_offset, 4);
23680 break;
c19d1205 23681#endif
6c43fab6 23682
c19d1205
ZW
23683 case BFD_RELOC_RVA:
23684 case BFD_RELOC_32:
23685 case BFD_RELOC_ARM_TARGET1:
23686 case BFD_RELOC_ARM_ROSEGREL32:
23687 case BFD_RELOC_ARM_SBREL32:
23688 case BFD_RELOC_32_PCREL:
f0927246
NC
23689#ifdef TE_PE
23690 case BFD_RELOC_32_SECREL:
23691#endif
2fc8bdac 23692 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23693#ifdef TE_WINCE
23694 /* For WinCE we only do this for pcrel fixups. */
23695 if (fixP->fx_done || fixP->fx_pcrel)
23696#endif
23697 md_number_to_chars (buf, value, 4);
c19d1205 23698 break;
6c43fab6 23699
c19d1205
ZW
23700#ifdef OBJ_ELF
23701 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23702 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23703 {
23704 newval = md_chars_to_number (buf, 4) & 0x80000000;
23705 if ((value ^ (value >> 1)) & 0x40000000)
23706 {
23707 as_bad_where (fixP->fx_file, fixP->fx_line,
23708 _("rel31 relocation overflow"));
23709 }
23710 newval |= value & 0x7fffffff;
23711 md_number_to_chars (buf, newval, 4);
23712 }
23713 break;
c19d1205 23714#endif
a737bd4d 23715
c19d1205 23716 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23717 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23718 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23719 newval = md_chars_to_number (buf, INSN_SIZE);
23720 else
23721 newval = get_thumb32_insn (buf);
23722 if ((newval & 0x0f200f00) == 0x0d000900)
23723 {
23724 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23725 has permitted values that are multiples of 2, in the range 0
23726 to 510. */
23727 if (value < -510 || value > 510 || (value & 1))
23728 as_bad_where (fixP->fx_file, fixP->fx_line,
23729 _("co-processor offset out of range"));
23730 }
23731 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23732 as_bad_where (fixP->fx_file, fixP->fx_line,
23733 _("co-processor offset out of range"));
23734 cp_off_common:
26d97720 23735 sign = value > 0;
c19d1205
ZW
23736 if (value < 0)
23737 value = -value;
8f06b2d8
PB
23738 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23739 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23740 newval = md_chars_to_number (buf, INSN_SIZE);
23741 else
23742 newval = get_thumb32_insn (buf);
26d97720
NS
23743 if (value == 0)
23744 newval &= 0xffffff00;
23745 else
23746 {
23747 newval &= 0xff7fff00;
9db2f6b4
RL
23748 if ((newval & 0x0f200f00) == 0x0d000900)
23749 {
23750 /* This is a fp16 vstr/vldr.
23751
23752 It requires the immediate offset in the instruction is shifted
23753 left by 1 to be a half-word offset.
23754
23755 Here, left shift by 1 first, and later right shift by 2
23756 should get the right offset. */
23757 value <<= 1;
23758 }
26d97720
NS
23759 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23760 }
8f06b2d8
PB
23761 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23762 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23763 md_number_to_chars (buf, newval, INSN_SIZE);
23764 else
23765 put_thumb32_insn (buf, newval);
c19d1205 23766 break;
a737bd4d 23767
c19d1205 23768 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23769 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23770 if (value < -255 || value > 255)
23771 as_bad_where (fixP->fx_file, fixP->fx_line,
23772 _("co-processor offset out of range"));
df7849c5 23773 value *= 4;
c19d1205 23774 goto cp_off_common;
6c43fab6 23775
c19d1205
ZW
23776 case BFD_RELOC_ARM_THUMB_OFFSET:
23777 newval = md_chars_to_number (buf, THUMB_SIZE);
23778 /* Exactly what ranges, and where the offset is inserted depends
23779 on the type of instruction, we can establish this from the
23780 top 4 bits. */
23781 switch (newval >> 12)
23782 {
23783 case 4: /* PC load. */
23784 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23785 forced to zero for these loads; md_pcrel_from has already
23786 compensated for this. */
23787 if (value & 3)
23788 as_bad_where (fixP->fx_file, fixP->fx_line,
23789 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23790 (((unsigned long) fixP->fx_frag->fr_address
23791 + (unsigned long) fixP->fx_where) & ~3)
23792 + (unsigned long) value);
a737bd4d 23793
c19d1205
ZW
23794 if (value & ~0x3fc)
23795 as_bad_where (fixP->fx_file, fixP->fx_line,
23796 _("invalid offset, value too big (0x%08lX)"),
23797 (long) value);
a737bd4d 23798
c19d1205
ZW
23799 newval |= value >> 2;
23800 break;
a737bd4d 23801
c19d1205
ZW
23802 case 9: /* SP load/store. */
23803 if (value & ~0x3fc)
23804 as_bad_where (fixP->fx_file, fixP->fx_line,
23805 _("invalid offset, value too big (0x%08lX)"),
23806 (long) value);
23807 newval |= value >> 2;
23808 break;
6c43fab6 23809
c19d1205
ZW
23810 case 6: /* Word load/store. */
23811 if (value & ~0x7c)
23812 as_bad_where (fixP->fx_file, fixP->fx_line,
23813 _("invalid offset, value too big (0x%08lX)"),
23814 (long) value);
23815 newval |= value << 4; /* 6 - 2. */
23816 break;
a737bd4d 23817
c19d1205
ZW
23818 case 7: /* Byte load/store. */
23819 if (value & ~0x1f)
23820 as_bad_where (fixP->fx_file, fixP->fx_line,
23821 _("invalid offset, value too big (0x%08lX)"),
23822 (long) value);
23823 newval |= value << 6;
23824 break;
a737bd4d 23825
c19d1205
ZW
23826 case 8: /* Halfword load/store. */
23827 if (value & ~0x3e)
23828 as_bad_where (fixP->fx_file, fixP->fx_line,
23829 _("invalid offset, value too big (0x%08lX)"),
23830 (long) value);
23831 newval |= value << 5; /* 6 - 1. */
23832 break;
a737bd4d 23833
c19d1205
ZW
23834 default:
23835 as_bad_where (fixP->fx_file, fixP->fx_line,
23836 "Unable to process relocation for thumb opcode: %lx",
23837 (unsigned long) newval);
23838 break;
23839 }
23840 md_number_to_chars (buf, newval, THUMB_SIZE);
23841 break;
a737bd4d 23842
c19d1205
ZW
23843 case BFD_RELOC_ARM_THUMB_ADD:
23844 /* This is a complicated relocation, since we use it for all of
23845 the following immediate relocations:
a737bd4d 23846
c19d1205
ZW
23847 3bit ADD/SUB
23848 8bit ADD/SUB
23849 9bit ADD/SUB SP word-aligned
23850 10bit ADD PC/SP word-aligned
a737bd4d 23851
c19d1205
ZW
23852 The type of instruction being processed is encoded in the
23853 instruction field:
a737bd4d 23854
c19d1205
ZW
23855 0x8000 SUB
23856 0x00F0 Rd
23857 0x000F Rs
23858 */
23859 newval = md_chars_to_number (buf, THUMB_SIZE);
23860 {
23861 int rd = (newval >> 4) & 0xf;
23862 int rs = newval & 0xf;
23863 int subtract = !!(newval & 0x8000);
a737bd4d 23864
c19d1205
ZW
23865 /* Check for HI regs, only very restricted cases allowed:
23866 Adjusting SP, and using PC or SP to get an address. */
23867 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23868 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23869 as_bad_where (fixP->fx_file, fixP->fx_line,
23870 _("invalid Hi register with immediate"));
a737bd4d 23871
c19d1205
ZW
23872 /* If value is negative, choose the opposite instruction. */
23873 if (value < 0)
23874 {
23875 value = -value;
23876 subtract = !subtract;
23877 if (value < 0)
23878 as_bad_where (fixP->fx_file, fixP->fx_line,
23879 _("immediate value out of range"));
23880 }
a737bd4d 23881
c19d1205
ZW
23882 if (rd == REG_SP)
23883 {
75c11999 23884 if (value & ~0x1fc)
c19d1205
ZW
23885 as_bad_where (fixP->fx_file, fixP->fx_line,
23886 _("invalid immediate for stack address calculation"));
23887 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23888 newval |= value >> 2;
23889 }
23890 else if (rs == REG_PC || rs == REG_SP)
23891 {
c12d2c9d
NC
23892 /* PR gas/18541. If the addition is for a defined symbol
23893 within range of an ADR instruction then accept it. */
23894 if (subtract
23895 && value == 4
23896 && fixP->fx_addsy != NULL)
23897 {
23898 subtract = 0;
23899
23900 if (! S_IS_DEFINED (fixP->fx_addsy)
23901 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23902 || S_IS_WEAK (fixP->fx_addsy))
23903 {
23904 as_bad_where (fixP->fx_file, fixP->fx_line,
23905 _("address calculation needs a strongly defined nearby symbol"));
23906 }
23907 else
23908 {
23909 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23910
23911 /* Round up to the next 4-byte boundary. */
23912 if (v & 3)
23913 v = (v + 3) & ~ 3;
23914 else
23915 v += 4;
23916 v = S_GET_VALUE (fixP->fx_addsy) - v;
23917
23918 if (v & ~0x3fc)
23919 {
23920 as_bad_where (fixP->fx_file, fixP->fx_line,
23921 _("symbol too far away"));
23922 }
23923 else
23924 {
23925 fixP->fx_done = 1;
23926 value = v;
23927 }
23928 }
23929 }
23930
c19d1205
ZW
23931 if (subtract || value & ~0x3fc)
23932 as_bad_where (fixP->fx_file, fixP->fx_line,
23933 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23934 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23935 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23936 newval |= rd << 8;
23937 newval |= value >> 2;
23938 }
23939 else if (rs == rd)
23940 {
23941 if (value & ~0xff)
23942 as_bad_where (fixP->fx_file, fixP->fx_line,
23943 _("immediate value out of range"));
23944 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23945 newval |= (rd << 8) | value;
23946 }
23947 else
23948 {
23949 if (value & ~0x7)
23950 as_bad_where (fixP->fx_file, fixP->fx_line,
23951 _("immediate value out of range"));
23952 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23953 newval |= rd | (rs << 3) | (value << 6);
23954 }
23955 }
23956 md_number_to_chars (buf, newval, THUMB_SIZE);
23957 break;
a737bd4d 23958
c19d1205
ZW
23959 case BFD_RELOC_ARM_THUMB_IMM:
23960 newval = md_chars_to_number (buf, THUMB_SIZE);
23961 if (value < 0 || value > 255)
23962 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23963 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23964 (long) value);
23965 newval |= value;
23966 md_number_to_chars (buf, newval, THUMB_SIZE);
23967 break;
a737bd4d 23968
c19d1205
ZW
23969 case BFD_RELOC_ARM_THUMB_SHIFT:
23970 /* 5bit shift value (0..32). LSL cannot take 32. */
23971 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23972 temp = newval & 0xf800;
23973 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23974 as_bad_where (fixP->fx_file, fixP->fx_line,
23975 _("invalid shift value: %ld"), (long) value);
23976 /* Shifts of zero must be encoded as LSL. */
23977 if (value == 0)
23978 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23979 /* Shifts of 32 are encoded as zero. */
23980 else if (value == 32)
23981 value = 0;
23982 newval |= value << 6;
23983 md_number_to_chars (buf, newval, THUMB_SIZE);
23984 break;
a737bd4d 23985
c19d1205
ZW
23986 case BFD_RELOC_VTABLE_INHERIT:
23987 case BFD_RELOC_VTABLE_ENTRY:
23988 fixP->fx_done = 0;
23989 return;
6c43fab6 23990
b6895b4f
PB
23991 case BFD_RELOC_ARM_MOVW:
23992 case BFD_RELOC_ARM_MOVT:
23993 case BFD_RELOC_ARM_THUMB_MOVW:
23994 case BFD_RELOC_ARM_THUMB_MOVT:
23995 if (fixP->fx_done || !seg->use_rela_p)
23996 {
23997 /* REL format relocations are limited to a 16-bit addend. */
23998 if (!fixP->fx_done)
23999 {
39623e12 24000 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24001 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24002 _("offset out of range"));
b6895b4f
PB
24003 }
24004 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24005 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24006 {
24007 value >>= 16;
24008 }
24009
24010 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24011 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24012 {
24013 newval = get_thumb32_insn (buf);
24014 newval &= 0xfbf08f00;
24015 newval |= (value & 0xf000) << 4;
24016 newval |= (value & 0x0800) << 15;
24017 newval |= (value & 0x0700) << 4;
24018 newval |= (value & 0x00ff);
24019 put_thumb32_insn (buf, newval);
24020 }
24021 else
24022 {
24023 newval = md_chars_to_number (buf, 4);
24024 newval &= 0xfff0f000;
24025 newval |= value & 0x0fff;
24026 newval |= (value & 0xf000) << 4;
24027 md_number_to_chars (buf, newval, 4);
24028 }
24029 }
24030 return;
24031
72d98d16
MG
24032 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24033 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24034 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24035 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24036 gas_assert (!fixP->fx_done);
24037 {
24038 bfd_vma insn;
24039 bfd_boolean is_mov;
24040 bfd_vma encoded_addend = value;
24041
24042 /* Check that addend can be encoded in instruction. */
24043 if (!seg->use_rela_p && (value < 0 || value > 255))
24044 as_bad_where (fixP->fx_file, fixP->fx_line,
24045 _("the offset 0x%08lX is not representable"),
24046 (unsigned long) encoded_addend);
24047
24048 /* Extract the instruction. */
24049 insn = md_chars_to_number (buf, THUMB_SIZE);
24050 is_mov = (insn & 0xf800) == 0x2000;
24051
24052 /* Encode insn. */
24053 if (is_mov)
24054 {
24055 if (!seg->use_rela_p)
24056 insn |= encoded_addend;
24057 }
24058 else
24059 {
24060 int rd, rs;
24061
24062 /* Extract the instruction. */
24063 /* Encoding is the following
24064 0x8000 SUB
24065 0x00F0 Rd
24066 0x000F Rs
24067 */
24068 /* The following conditions must be true :
24069 - ADD
24070 - Rd == Rs
24071 - Rd <= 7
24072 */
24073 rd = (insn >> 4) & 0xf;
24074 rs = insn & 0xf;
24075 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24076 as_bad_where (fixP->fx_file, fixP->fx_line,
24077 _("Unable to process relocation for thumb opcode: %lx"),
24078 (unsigned long) insn);
24079
24080 /* Encode as ADD immediate8 thumb 1 code. */
24081 insn = 0x3000 | (rd << 8);
24082
24083 /* Place the encoded addend into the first 8 bits of the
24084 instruction. */
24085 if (!seg->use_rela_p)
24086 insn |= encoded_addend;
24087 }
24088
24089 /* Update the instruction. */
24090 md_number_to_chars (buf, insn, THUMB_SIZE);
24091 }
24092 break;
24093
4962c51a
MS
24094 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24095 case BFD_RELOC_ARM_ALU_PC_G0:
24096 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24097 case BFD_RELOC_ARM_ALU_PC_G1:
24098 case BFD_RELOC_ARM_ALU_PC_G2:
24099 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24100 case BFD_RELOC_ARM_ALU_SB_G0:
24101 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24102 case BFD_RELOC_ARM_ALU_SB_G1:
24103 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24104 gas_assert (!fixP->fx_done);
4962c51a
MS
24105 if (!seg->use_rela_p)
24106 {
477330fc
RM
24107 bfd_vma insn;
24108 bfd_vma encoded_addend;
24109 bfd_vma addend_abs = abs (value);
24110
24111 /* Check that the absolute value of the addend can be
24112 expressed as an 8-bit constant plus a rotation. */
24113 encoded_addend = encode_arm_immediate (addend_abs);
24114 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24115 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24116 _("the offset 0x%08lX is not representable"),
24117 (unsigned long) addend_abs);
24118
24119 /* Extract the instruction. */
24120 insn = md_chars_to_number (buf, INSN_SIZE);
24121
24122 /* If the addend is positive, use an ADD instruction.
24123 Otherwise use a SUB. Take care not to destroy the S bit. */
24124 insn &= 0xff1fffff;
24125 if (value < 0)
24126 insn |= 1 << 22;
24127 else
24128 insn |= 1 << 23;
24129
24130 /* Place the encoded addend into the first 12 bits of the
24131 instruction. */
24132 insn &= 0xfffff000;
24133 insn |= encoded_addend;
24134
24135 /* Update the instruction. */
24136 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24137 }
24138 break;
24139
24140 case BFD_RELOC_ARM_LDR_PC_G0:
24141 case BFD_RELOC_ARM_LDR_PC_G1:
24142 case BFD_RELOC_ARM_LDR_PC_G2:
24143 case BFD_RELOC_ARM_LDR_SB_G0:
24144 case BFD_RELOC_ARM_LDR_SB_G1:
24145 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24146 gas_assert (!fixP->fx_done);
4962c51a 24147 if (!seg->use_rela_p)
477330fc
RM
24148 {
24149 bfd_vma insn;
24150 bfd_vma addend_abs = abs (value);
4962c51a 24151
477330fc
RM
24152 /* Check that the absolute value of the addend can be
24153 encoded in 12 bits. */
24154 if (addend_abs >= 0x1000)
4962c51a 24155 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24156 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24157 (unsigned long) addend_abs);
24158
24159 /* Extract the instruction. */
24160 insn = md_chars_to_number (buf, INSN_SIZE);
24161
24162 /* If the addend is negative, clear bit 23 of the instruction.
24163 Otherwise set it. */
24164 if (value < 0)
24165 insn &= ~(1 << 23);
24166 else
24167 insn |= 1 << 23;
24168
24169 /* Place the absolute value of the addend into the first 12 bits
24170 of the instruction. */
24171 insn &= 0xfffff000;
24172 insn |= addend_abs;
24173
24174 /* Update the instruction. */
24175 md_number_to_chars (buf, insn, INSN_SIZE);
24176 }
4962c51a
MS
24177 break;
24178
24179 case BFD_RELOC_ARM_LDRS_PC_G0:
24180 case BFD_RELOC_ARM_LDRS_PC_G1:
24181 case BFD_RELOC_ARM_LDRS_PC_G2:
24182 case BFD_RELOC_ARM_LDRS_SB_G0:
24183 case BFD_RELOC_ARM_LDRS_SB_G1:
24184 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24185 gas_assert (!fixP->fx_done);
4962c51a 24186 if (!seg->use_rela_p)
477330fc
RM
24187 {
24188 bfd_vma insn;
24189 bfd_vma addend_abs = abs (value);
4962c51a 24190
477330fc
RM
24191 /* Check that the absolute value of the addend can be
24192 encoded in 8 bits. */
24193 if (addend_abs >= 0x100)
4962c51a 24194 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24195 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24196 (unsigned long) addend_abs);
24197
24198 /* Extract the instruction. */
24199 insn = md_chars_to_number (buf, INSN_SIZE);
24200
24201 /* If the addend is negative, clear bit 23 of the instruction.
24202 Otherwise set it. */
24203 if (value < 0)
24204 insn &= ~(1 << 23);
24205 else
24206 insn |= 1 << 23;
24207
24208 /* Place the first four bits of the absolute value of the addend
24209 into the first 4 bits of the instruction, and the remaining
24210 four into bits 8 .. 11. */
24211 insn &= 0xfffff0f0;
24212 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24213
24214 /* Update the instruction. */
24215 md_number_to_chars (buf, insn, INSN_SIZE);
24216 }
4962c51a
MS
24217 break;
24218
24219 case BFD_RELOC_ARM_LDC_PC_G0:
24220 case BFD_RELOC_ARM_LDC_PC_G1:
24221 case BFD_RELOC_ARM_LDC_PC_G2:
24222 case BFD_RELOC_ARM_LDC_SB_G0:
24223 case BFD_RELOC_ARM_LDC_SB_G1:
24224 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24225 gas_assert (!fixP->fx_done);
4962c51a 24226 if (!seg->use_rela_p)
477330fc
RM
24227 {
24228 bfd_vma insn;
24229 bfd_vma addend_abs = abs (value);
4962c51a 24230
477330fc
RM
24231 /* Check that the absolute value of the addend is a multiple of
24232 four and, when divided by four, fits in 8 bits. */
24233 if (addend_abs & 0x3)
4962c51a 24234 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24235 _("bad offset 0x%08lX (must be word-aligned)"),
24236 (unsigned long) addend_abs);
4962c51a 24237
477330fc 24238 if ((addend_abs >> 2) > 0xff)
4962c51a 24239 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24240 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24241 (unsigned long) addend_abs);
24242
24243 /* Extract the instruction. */
24244 insn = md_chars_to_number (buf, INSN_SIZE);
24245
24246 /* If the addend is negative, clear bit 23 of the instruction.
24247 Otherwise set it. */
24248 if (value < 0)
24249 insn &= ~(1 << 23);
24250 else
24251 insn |= 1 << 23;
24252
24253 /* Place the addend (divided by four) into the first eight
24254 bits of the instruction. */
24255 insn &= 0xfffffff0;
24256 insn |= addend_abs >> 2;
24257
24258 /* Update the instruction. */
24259 md_number_to_chars (buf, insn, INSN_SIZE);
24260 }
4962c51a
MS
24261 break;
24262
845b51d6
PB
24263 case BFD_RELOC_ARM_V4BX:
24264 /* This will need to go in the object file. */
24265 fixP->fx_done = 0;
24266 break;
24267
c19d1205
ZW
24268 case BFD_RELOC_UNUSED:
24269 default:
24270 as_bad_where (fixP->fx_file, fixP->fx_line,
24271 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24272 }
6c43fab6
RE
24273}
24274
c19d1205
ZW
24275/* Translate internal representation of relocation info to BFD target
24276 format. */
a737bd4d 24277
c19d1205 24278arelent *
00a97672 24279tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24280{
c19d1205
ZW
24281 arelent * reloc;
24282 bfd_reloc_code_real_type code;
a737bd4d 24283
325801bd 24284 reloc = XNEW (arelent);
a737bd4d 24285
325801bd 24286 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24287 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24288 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24289
2fc8bdac 24290 if (fixp->fx_pcrel)
00a97672
RS
24291 {
24292 if (section->use_rela_p)
24293 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24294 else
24295 fixp->fx_offset = reloc->address;
24296 }
c19d1205 24297 reloc->addend = fixp->fx_offset;
a737bd4d 24298
c19d1205 24299 switch (fixp->fx_r_type)
a737bd4d 24300 {
c19d1205
ZW
24301 case BFD_RELOC_8:
24302 if (fixp->fx_pcrel)
24303 {
24304 code = BFD_RELOC_8_PCREL;
24305 break;
24306 }
1a0670f3 24307 /* Fall through. */
a737bd4d 24308
c19d1205
ZW
24309 case BFD_RELOC_16:
24310 if (fixp->fx_pcrel)
24311 {
24312 code = BFD_RELOC_16_PCREL;
24313 break;
24314 }
1a0670f3 24315 /* Fall through. */
6c43fab6 24316
c19d1205
ZW
24317 case BFD_RELOC_32:
24318 if (fixp->fx_pcrel)
24319 {
24320 code = BFD_RELOC_32_PCREL;
24321 break;
24322 }
1a0670f3 24323 /* Fall through. */
a737bd4d 24324
b6895b4f
PB
24325 case BFD_RELOC_ARM_MOVW:
24326 if (fixp->fx_pcrel)
24327 {
24328 code = BFD_RELOC_ARM_MOVW_PCREL;
24329 break;
24330 }
1a0670f3 24331 /* Fall through. */
b6895b4f
PB
24332
24333 case BFD_RELOC_ARM_MOVT:
24334 if (fixp->fx_pcrel)
24335 {
24336 code = BFD_RELOC_ARM_MOVT_PCREL;
24337 break;
24338 }
1a0670f3 24339 /* Fall through. */
b6895b4f
PB
24340
24341 case BFD_RELOC_ARM_THUMB_MOVW:
24342 if (fixp->fx_pcrel)
24343 {
24344 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24345 break;
24346 }
1a0670f3 24347 /* Fall through. */
b6895b4f
PB
24348
24349 case BFD_RELOC_ARM_THUMB_MOVT:
24350 if (fixp->fx_pcrel)
24351 {
24352 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24353 break;
24354 }
1a0670f3 24355 /* Fall through. */
b6895b4f 24356
c19d1205
ZW
24357 case BFD_RELOC_NONE:
24358 case BFD_RELOC_ARM_PCREL_BRANCH:
24359 case BFD_RELOC_ARM_PCREL_BLX:
24360 case BFD_RELOC_RVA:
24361 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24362 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24363 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24364 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24365 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24366 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24367 case BFD_RELOC_VTABLE_ENTRY:
24368 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24369#ifdef TE_PE
24370 case BFD_RELOC_32_SECREL:
24371#endif
c19d1205
ZW
24372 code = fixp->fx_r_type;
24373 break;
a737bd4d 24374
00adf2d4
JB
24375 case BFD_RELOC_THUMB_PCREL_BLX:
24376#ifdef OBJ_ELF
24377 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24378 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24379 else
24380#endif
24381 code = BFD_RELOC_THUMB_PCREL_BLX;
24382 break;
24383
c19d1205
ZW
24384 case BFD_RELOC_ARM_LITERAL:
24385 case BFD_RELOC_ARM_HWLITERAL:
24386 /* If this is called then the a literal has
24387 been referenced across a section boundary. */
24388 as_bad_where (fixp->fx_file, fixp->fx_line,
24389 _("literal referenced across section boundary"));
24390 return NULL;
a737bd4d 24391
c19d1205 24392#ifdef OBJ_ELF
0855e32b
NS
24393 case BFD_RELOC_ARM_TLS_CALL:
24394 case BFD_RELOC_ARM_THM_TLS_CALL:
24395 case BFD_RELOC_ARM_TLS_DESCSEQ:
24396 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24397 case BFD_RELOC_ARM_GOT32:
24398 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24399 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24400 case BFD_RELOC_ARM_PLT32:
24401 case BFD_RELOC_ARM_TARGET1:
24402 case BFD_RELOC_ARM_ROSEGREL32:
24403 case BFD_RELOC_ARM_SBREL32:
24404 case BFD_RELOC_ARM_PREL31:
24405 case BFD_RELOC_ARM_TARGET2:
c19d1205 24406 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24407 case BFD_RELOC_ARM_PCREL_CALL:
24408 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24409 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24410 case BFD_RELOC_ARM_ALU_PC_G0:
24411 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24412 case BFD_RELOC_ARM_ALU_PC_G1:
24413 case BFD_RELOC_ARM_ALU_PC_G2:
24414 case BFD_RELOC_ARM_LDR_PC_G0:
24415 case BFD_RELOC_ARM_LDR_PC_G1:
24416 case BFD_RELOC_ARM_LDR_PC_G2:
24417 case BFD_RELOC_ARM_LDRS_PC_G0:
24418 case BFD_RELOC_ARM_LDRS_PC_G1:
24419 case BFD_RELOC_ARM_LDRS_PC_G2:
24420 case BFD_RELOC_ARM_LDC_PC_G0:
24421 case BFD_RELOC_ARM_LDC_PC_G1:
24422 case BFD_RELOC_ARM_LDC_PC_G2:
24423 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24424 case BFD_RELOC_ARM_ALU_SB_G0:
24425 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24426 case BFD_RELOC_ARM_ALU_SB_G1:
24427 case BFD_RELOC_ARM_ALU_SB_G2:
24428 case BFD_RELOC_ARM_LDR_SB_G0:
24429 case BFD_RELOC_ARM_LDR_SB_G1:
24430 case BFD_RELOC_ARM_LDR_SB_G2:
24431 case BFD_RELOC_ARM_LDRS_SB_G0:
24432 case BFD_RELOC_ARM_LDRS_SB_G1:
24433 case BFD_RELOC_ARM_LDRS_SB_G2:
24434 case BFD_RELOC_ARM_LDC_SB_G0:
24435 case BFD_RELOC_ARM_LDC_SB_G1:
24436 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24437 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24438 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24439 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24440 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24441 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24442 code = fixp->fx_r_type;
24443 break;
a737bd4d 24444
0855e32b 24445 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24446 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24447 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24448 case BFD_RELOC_ARM_TLS_IE32:
24449 case BFD_RELOC_ARM_TLS_LDM32:
24450 /* BFD will include the symbol's address in the addend.
24451 But we don't want that, so subtract it out again here. */
24452 if (!S_IS_COMMON (fixp->fx_addsy))
24453 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24454 code = fixp->fx_r_type;
24455 break;
24456#endif
a737bd4d 24457
c19d1205
ZW
24458 case BFD_RELOC_ARM_IMMEDIATE:
24459 as_bad_where (fixp->fx_file, fixp->fx_line,
24460 _("internal relocation (type: IMMEDIATE) not fixed up"));
24461 return NULL;
a737bd4d 24462
c19d1205
ZW
24463 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24464 as_bad_where (fixp->fx_file, fixp->fx_line,
24465 _("ADRL used for a symbol not defined in the same file"));
24466 return NULL;
a737bd4d 24467
c19d1205 24468 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24469 if (section->use_rela_p)
24470 {
24471 code = fixp->fx_r_type;
24472 break;
24473 }
24474
c19d1205
ZW
24475 if (fixp->fx_addsy != NULL
24476 && !S_IS_DEFINED (fixp->fx_addsy)
24477 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24478 {
c19d1205
ZW
24479 as_bad_where (fixp->fx_file, fixp->fx_line,
24480 _("undefined local label `%s'"),
24481 S_GET_NAME (fixp->fx_addsy));
24482 return NULL;
a737bd4d
NC
24483 }
24484
c19d1205
ZW
24485 as_bad_where (fixp->fx_file, fixp->fx_line,
24486 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24487 return NULL;
a737bd4d 24488
c19d1205
ZW
24489 default:
24490 {
e0471c16 24491 const char * type;
6c43fab6 24492
c19d1205
ZW
24493 switch (fixp->fx_r_type)
24494 {
24495 case BFD_RELOC_NONE: type = "NONE"; break;
24496 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24497 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24498 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24499 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24500 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24501 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24502 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24503 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24504 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24505 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24506 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24507 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24508 default: type = _("<unknown>"); break;
24509 }
24510 as_bad_where (fixp->fx_file, fixp->fx_line,
24511 _("cannot represent %s relocation in this object file format"),
24512 type);
24513 return NULL;
24514 }
a737bd4d 24515 }
6c43fab6 24516
c19d1205
ZW
24517#ifdef OBJ_ELF
24518 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24519 && GOT_symbol
24520 && fixp->fx_addsy == GOT_symbol)
24521 {
24522 code = BFD_RELOC_ARM_GOTPC;
24523 reloc->addend = fixp->fx_offset = reloc->address;
24524 }
24525#endif
6c43fab6 24526
c19d1205 24527 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24528
c19d1205
ZW
24529 if (reloc->howto == NULL)
24530 {
24531 as_bad_where (fixp->fx_file, fixp->fx_line,
24532 _("cannot represent %s relocation in this object file format"),
24533 bfd_get_reloc_code_name (code));
24534 return NULL;
24535 }
6c43fab6 24536
c19d1205
ZW
24537 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24538 vtable entry to be used in the relocation's section offset. */
24539 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24540 reloc->address = fixp->fx_offset;
6c43fab6 24541
c19d1205 24542 return reloc;
6c43fab6
RE
24543}
24544
c19d1205 24545/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24546
c19d1205
ZW
24547void
24548cons_fix_new_arm (fragS * frag,
24549 int where,
24550 int size,
62ebcb5c
AM
24551 expressionS * exp,
24552 bfd_reloc_code_real_type reloc)
6c43fab6 24553{
c19d1205 24554 int pcrel = 0;
6c43fab6 24555
c19d1205
ZW
24556 /* Pick a reloc.
24557 FIXME: @@ Should look at CPU word size. */
24558 switch (size)
24559 {
24560 case 1:
62ebcb5c 24561 reloc = BFD_RELOC_8;
c19d1205
ZW
24562 break;
24563 case 2:
62ebcb5c 24564 reloc = BFD_RELOC_16;
c19d1205
ZW
24565 break;
24566 case 4:
24567 default:
62ebcb5c 24568 reloc = BFD_RELOC_32;
c19d1205
ZW
24569 break;
24570 case 8:
62ebcb5c 24571 reloc = BFD_RELOC_64;
c19d1205
ZW
24572 break;
24573 }
6c43fab6 24574
f0927246
NC
24575#ifdef TE_PE
24576 if (exp->X_op == O_secrel)
24577 {
24578 exp->X_op = O_symbol;
62ebcb5c 24579 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24580 }
24581#endif
24582
62ebcb5c 24583 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24584}
6c43fab6 24585
4343666d 24586#if defined (OBJ_COFF)
c19d1205
ZW
24587void
24588arm_validate_fix (fixS * fixP)
6c43fab6 24589{
c19d1205
ZW
24590 /* If the destination of the branch is a defined symbol which does not have
24591 the THUMB_FUNC attribute, then we must be calling a function which has
24592 the (interfacearm) attribute. We look for the Thumb entry point to that
24593 function and change the branch to refer to that function instead. */
24594 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24595 && fixP->fx_addsy != NULL
24596 && S_IS_DEFINED (fixP->fx_addsy)
24597 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24598 {
c19d1205 24599 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24600 }
c19d1205
ZW
24601}
24602#endif
6c43fab6 24603
267bf995 24604
c19d1205
ZW
24605int
24606arm_force_relocation (struct fix * fixp)
24607{
24608#if defined (OBJ_COFF) && defined (TE_PE)
24609 if (fixp->fx_r_type == BFD_RELOC_RVA)
24610 return 1;
24611#endif
6c43fab6 24612
267bf995
RR
24613 /* In case we have a call or a branch to a function in ARM ISA mode from
24614 a thumb function or vice-versa force the relocation. These relocations
24615 are cleared off for some cores that might have blx and simple transformations
24616 are possible. */
24617
24618#ifdef OBJ_ELF
24619 switch (fixp->fx_r_type)
24620 {
24621 case BFD_RELOC_ARM_PCREL_JUMP:
24622 case BFD_RELOC_ARM_PCREL_CALL:
24623 case BFD_RELOC_THUMB_PCREL_BLX:
24624 if (THUMB_IS_FUNC (fixp->fx_addsy))
24625 return 1;
24626 break;
24627
24628 case BFD_RELOC_ARM_PCREL_BLX:
24629 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24630 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24631 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24632 if (ARM_IS_FUNC (fixp->fx_addsy))
24633 return 1;
24634 break;
24635
24636 default:
24637 break;
24638 }
24639#endif
24640
b5884301
PB
24641 /* Resolve these relocations even if the symbol is extern or weak.
24642 Technically this is probably wrong due to symbol preemption.
24643 In practice these relocations do not have enough range to be useful
24644 at dynamic link time, and some code (e.g. in the Linux kernel)
24645 expects these references to be resolved. */
c19d1205
ZW
24646 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24647 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24648 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24649 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24650 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24651 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24652 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24653 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24654 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24655 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24656 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24657 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24658 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24659 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24660 return 0;
a737bd4d 24661
4962c51a
MS
24662 /* Always leave these relocations for the linker. */
24663 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24664 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24665 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24666 return 1;
24667
f0291e4c
PB
24668 /* Always generate relocations against function symbols. */
24669 if (fixp->fx_r_type == BFD_RELOC_32
24670 && fixp->fx_addsy
24671 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24672 return 1;
24673
c19d1205 24674 return generic_force_reloc (fixp);
404ff6b5
AH
24675}
24676
0ffdc86c 24677#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24678/* Relocations against function names must be left unadjusted,
24679 so that the linker can use this information to generate interworking
24680 stubs. The MIPS version of this function
c19d1205
ZW
24681 also prevents relocations that are mips-16 specific, but I do not
24682 know why it does this.
404ff6b5 24683
c19d1205
ZW
24684 FIXME:
24685 There is one other problem that ought to be addressed here, but
24686 which currently is not: Taking the address of a label (rather
24687 than a function) and then later jumping to that address. Such
24688 addresses also ought to have their bottom bit set (assuming that
24689 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24690
c19d1205
ZW
24691bfd_boolean
24692arm_fix_adjustable (fixS * fixP)
404ff6b5 24693{
c19d1205
ZW
24694 if (fixP->fx_addsy == NULL)
24695 return 1;
404ff6b5 24696
e28387c3
PB
24697 /* Preserve relocations against symbols with function type. */
24698 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24699 return FALSE;
e28387c3 24700
c19d1205
ZW
24701 if (THUMB_IS_FUNC (fixP->fx_addsy)
24702 && fixP->fx_subsy == NULL)
c921be7d 24703 return FALSE;
a737bd4d 24704
c19d1205
ZW
24705 /* We need the symbol name for the VTABLE entries. */
24706 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24707 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24708 return FALSE;
404ff6b5 24709
c19d1205
ZW
24710 /* Don't allow symbols to be discarded on GOT related relocs. */
24711 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24712 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24713 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24714 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24715 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24716 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24717 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24718 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24719 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24720 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24721 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24722 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24723 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24724 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24725 return FALSE;
a737bd4d 24726
4962c51a
MS
24727 /* Similarly for group relocations. */
24728 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24729 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24730 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24731 return FALSE;
4962c51a 24732
79947c54
CD
24733 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24734 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24735 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24736 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24737 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24738 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24739 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24740 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24741 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24742 return FALSE;
79947c54 24743
72d98d16
MG
24744 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24745 offsets, so keep these symbols. */
24746 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24747 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24748 return FALSE;
24749
c921be7d 24750 return TRUE;
a737bd4d 24751}
0ffdc86c
NC
24752#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24753
24754#ifdef OBJ_ELF
c19d1205
ZW
24755const char *
24756elf32_arm_target_format (void)
404ff6b5 24757{
c19d1205
ZW
24758#ifdef TE_SYMBIAN
24759 return (target_big_endian
24760 ? "elf32-bigarm-symbian"
24761 : "elf32-littlearm-symbian");
24762#elif defined (TE_VXWORKS)
24763 return (target_big_endian
24764 ? "elf32-bigarm-vxworks"
24765 : "elf32-littlearm-vxworks");
b38cadfb
NC
24766#elif defined (TE_NACL)
24767 return (target_big_endian
24768 ? "elf32-bigarm-nacl"
24769 : "elf32-littlearm-nacl");
c19d1205
ZW
24770#else
24771 if (target_big_endian)
24772 return "elf32-bigarm";
24773 else
24774 return "elf32-littlearm";
24775#endif
404ff6b5
AH
24776}
24777
c19d1205
ZW
24778void
24779armelf_frob_symbol (symbolS * symp,
24780 int * puntp)
404ff6b5 24781{
c19d1205
ZW
24782 elf_frob_symbol (symp, puntp);
24783}
24784#endif
404ff6b5 24785
c19d1205 24786/* MD interface: Finalization. */
a737bd4d 24787
c19d1205
ZW
24788void
24789arm_cleanup (void)
24790{
24791 literal_pool * pool;
a737bd4d 24792
e07e6e58
NC
24793 /* Ensure that all the IT blocks are properly closed. */
24794 check_it_blocks_finished ();
24795
c19d1205
ZW
24796 for (pool = list_of_pools; pool; pool = pool->next)
24797 {
5f4273c7 24798 /* Put it at the end of the relevant section. */
c19d1205
ZW
24799 subseg_set (pool->section, pool->sub_section);
24800#ifdef OBJ_ELF
24801 arm_elf_change_section ();
24802#endif
24803 s_ltorg (0);
24804 }
404ff6b5
AH
24805}
24806
cd000bff
DJ
24807#ifdef OBJ_ELF
24808/* Remove any excess mapping symbols generated for alignment frags in
24809 SEC. We may have created a mapping symbol before a zero byte
24810 alignment; remove it if there's a mapping symbol after the
24811 alignment. */
24812static void
24813check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24814 void *dummy ATTRIBUTE_UNUSED)
24815{
24816 segment_info_type *seginfo = seg_info (sec);
24817 fragS *fragp;
24818
24819 if (seginfo == NULL || seginfo->frchainP == NULL)
24820 return;
24821
24822 for (fragp = seginfo->frchainP->frch_root;
24823 fragp != NULL;
24824 fragp = fragp->fr_next)
24825 {
24826 symbolS *sym = fragp->tc_frag_data.last_map;
24827 fragS *next = fragp->fr_next;
24828
24829 /* Variable-sized frags have been converted to fixed size by
24830 this point. But if this was variable-sized to start with,
24831 there will be a fixed-size frag after it. So don't handle
24832 next == NULL. */
24833 if (sym == NULL || next == NULL)
24834 continue;
24835
24836 if (S_GET_VALUE (sym) < next->fr_address)
24837 /* Not at the end of this frag. */
24838 continue;
24839 know (S_GET_VALUE (sym) == next->fr_address);
24840
24841 do
24842 {
24843 if (next->tc_frag_data.first_map != NULL)
24844 {
24845 /* Next frag starts with a mapping symbol. Discard this
24846 one. */
24847 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24848 break;
24849 }
24850
24851 if (next->fr_next == NULL)
24852 {
24853 /* This mapping symbol is at the end of the section. Discard
24854 it. */
24855 know (next->fr_fix == 0 && next->fr_var == 0);
24856 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24857 break;
24858 }
24859
24860 /* As long as we have empty frags without any mapping symbols,
24861 keep looking. */
24862 /* If the next frag is non-empty and does not start with a
24863 mapping symbol, then this mapping symbol is required. */
24864 if (next->fr_address != next->fr_next->fr_address)
24865 break;
24866
24867 next = next->fr_next;
24868 }
24869 while (next != NULL);
24870 }
24871}
24872#endif
24873
c19d1205
ZW
24874/* Adjust the symbol table. This marks Thumb symbols as distinct from
24875 ARM ones. */
404ff6b5 24876
c19d1205
ZW
24877void
24878arm_adjust_symtab (void)
404ff6b5 24879{
c19d1205
ZW
24880#ifdef OBJ_COFF
24881 symbolS * sym;
404ff6b5 24882
c19d1205
ZW
24883 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24884 {
24885 if (ARM_IS_THUMB (sym))
24886 {
24887 if (THUMB_IS_FUNC (sym))
24888 {
24889 /* Mark the symbol as a Thumb function. */
24890 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24891 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24892 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24893
c19d1205
ZW
24894 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24895 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24896 else
24897 as_bad (_("%s: unexpected function type: %d"),
24898 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24899 }
24900 else switch (S_GET_STORAGE_CLASS (sym))
24901 {
24902 case C_EXT:
24903 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24904 break;
24905 case C_STAT:
24906 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24907 break;
24908 case C_LABEL:
24909 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24910 break;
24911 default:
24912 /* Do nothing. */
24913 break;
24914 }
24915 }
a737bd4d 24916
c19d1205
ZW
24917 if (ARM_IS_INTERWORK (sym))
24918 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24919 }
c19d1205
ZW
24920#endif
24921#ifdef OBJ_ELF
24922 symbolS * sym;
24923 char bind;
404ff6b5 24924
c19d1205 24925 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24926 {
c19d1205
ZW
24927 if (ARM_IS_THUMB (sym))
24928 {
24929 elf_symbol_type * elf_sym;
404ff6b5 24930
c19d1205
ZW
24931 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24932 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24933
b0796911
PB
24934 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24935 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24936 {
24937 /* If it's a .thumb_func, declare it as so,
24938 otherwise tag label as .code 16. */
24939 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24940 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24941 ST_BRANCH_TO_THUMB);
3ba67470 24942 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24943 elf_sym->internal_elf_sym.st_info =
24944 ELF_ST_INFO (bind, STT_ARM_16BIT);
24945 }
24946 }
24947 }
cd000bff
DJ
24948
24949 /* Remove any overlapping mapping symbols generated by alignment frags. */
24950 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24951 /* Now do generic ELF adjustments. */
24952 elf_adjust_symtab ();
c19d1205 24953#endif
404ff6b5
AH
24954}
24955
c19d1205 24956/* MD interface: Initialization. */
404ff6b5 24957
a737bd4d 24958static void
c19d1205 24959set_constant_flonums (void)
a737bd4d 24960{
c19d1205 24961 int i;
404ff6b5 24962
c19d1205
ZW
24963 for (i = 0; i < NUM_FLOAT_VALS; i++)
24964 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24965 abort ();
a737bd4d 24966}
404ff6b5 24967
3e9e4fcf
JB
24968/* Auto-select Thumb mode if it's the only available instruction set for the
24969 given architecture. */
24970
24971static void
24972autoselect_thumb_from_cpu_variant (void)
24973{
24974 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24975 opcode_select (16);
24976}
24977
c19d1205
ZW
24978void
24979md_begin (void)
a737bd4d 24980{
c19d1205
ZW
24981 unsigned mach;
24982 unsigned int i;
404ff6b5 24983
c19d1205
ZW
24984 if ( (arm_ops_hsh = hash_new ()) == NULL
24985 || (arm_cond_hsh = hash_new ()) == NULL
24986 || (arm_shift_hsh = hash_new ()) == NULL
24987 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24988 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24989 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24990 || (arm_reloc_hsh = hash_new ()) == NULL
24991 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24992 as_fatal (_("virtual memory exhausted"));
24993
24994 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24995 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24996 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24997 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24998 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24999 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25000 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25001 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25002 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25003 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25004 (void *) (v7m_psrs + i));
c19d1205 25005 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25006 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25007 for (i = 0;
25008 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25009 i++)
d3ce72d0 25010 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25011 (void *) (barrier_opt_names + i));
c19d1205 25012#ifdef OBJ_ELF
3da1d841
NC
25013 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25014 {
25015 struct reloc_entry * entry = reloc_names + i;
25016
25017 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25018 /* This makes encode_branch() use the EABI versions of this relocation. */
25019 entry->reloc = BFD_RELOC_UNUSED;
25020
25021 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25022 }
c19d1205
ZW
25023#endif
25024
25025 set_constant_flonums ();
404ff6b5 25026
c19d1205
ZW
25027 /* Set the cpu variant based on the command-line options. We prefer
25028 -mcpu= over -march= if both are set (as for GCC); and we prefer
25029 -mfpu= over any other way of setting the floating point unit.
25030 Use of legacy options with new options are faulted. */
e74cfd16 25031 if (legacy_cpu)
404ff6b5 25032 {
e74cfd16 25033 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25034 as_bad (_("use of old and new-style options to set CPU type"));
25035
25036 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25037 }
e74cfd16 25038 else if (!mcpu_cpu_opt)
c168ce07
TP
25039 {
25040 mcpu_cpu_opt = march_cpu_opt;
25041 dyn_mcpu_ext_opt = dyn_march_ext_opt;
25042 /* Avoid double free in arm_md_end. */
25043 dyn_march_ext_opt = NULL;
25044 }
404ff6b5 25045
e74cfd16 25046 if (legacy_fpu)
c19d1205 25047 {
e74cfd16 25048 if (mfpu_opt)
c19d1205 25049 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25050
25051 mfpu_opt = legacy_fpu;
25052 }
e74cfd16 25053 else if (!mfpu_opt)
03b1477f 25054 {
45eb4c1b
NS
25055#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25056 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25057 /* Some environments specify a default FPU. If they don't, infer it
25058 from the processor. */
e74cfd16 25059 if (mcpu_fpu_opt)
03b1477f
RE
25060 mfpu_opt = mcpu_fpu_opt;
25061 else
25062 mfpu_opt = march_fpu_opt;
39c2da32 25063#else
e74cfd16 25064 mfpu_opt = &fpu_default;
39c2da32 25065#endif
03b1477f
RE
25066 }
25067
e74cfd16 25068 if (!mfpu_opt)
03b1477f 25069 {
493cb6ef 25070 if (mcpu_cpu_opt != NULL)
e74cfd16 25071 mfpu_opt = &fpu_default;
493cb6ef 25072 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25073 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25074 else
e74cfd16 25075 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25076 }
25077
ee065d83 25078#ifdef CPU_DEFAULT
e74cfd16 25079 if (!mcpu_cpu_opt)
ee065d83 25080 {
e74cfd16
PB
25081 mcpu_cpu_opt = &cpu_default;
25082 selected_cpu = cpu_default;
ee065d83 25083 }
c168ce07
TP
25084 else if (dyn_mcpu_ext_opt)
25085 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
62785b09
TP
25086 else
25087 selected_cpu = *mcpu_cpu_opt;
e74cfd16 25088#else
c168ce07
TP
25089 if (mcpu_cpu_opt && dyn_mcpu_ext_opt)
25090 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
25091 else if (mcpu_cpu_opt)
e74cfd16 25092 selected_cpu = *mcpu_cpu_opt;
ee065d83 25093 else
e74cfd16 25094 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25095#endif
03b1477f 25096
e74cfd16 25097 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
25098 if (dyn_mcpu_ext_opt)
25099 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
03b1477f 25100
3e9e4fcf
JB
25101 autoselect_thumb_from_cpu_variant ();
25102
e74cfd16 25103 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25104
f17c130b 25105#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25106 {
7cc69913
NC
25107 unsigned int flags = 0;
25108
25109#if defined OBJ_ELF
25110 flags = meabi_flags;
d507cf36
PB
25111
25112 switch (meabi_flags)
33a392fb 25113 {
d507cf36 25114 case EF_ARM_EABI_UNKNOWN:
7cc69913 25115#endif
d507cf36
PB
25116 /* Set the flags in the private structure. */
25117 if (uses_apcs_26) flags |= F_APCS26;
25118 if (support_interwork) flags |= F_INTERWORK;
25119 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25120 if (pic_code) flags |= F_PIC;
e74cfd16 25121 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25122 flags |= F_SOFT_FLOAT;
25123
d507cf36
PB
25124 switch (mfloat_abi_opt)
25125 {
25126 case ARM_FLOAT_ABI_SOFT:
25127 case ARM_FLOAT_ABI_SOFTFP:
25128 flags |= F_SOFT_FLOAT;
25129 break;
33a392fb 25130
d507cf36
PB
25131 case ARM_FLOAT_ABI_HARD:
25132 if (flags & F_SOFT_FLOAT)
25133 as_bad (_("hard-float conflicts with specified fpu"));
25134 break;
25135 }
03b1477f 25136
e74cfd16
PB
25137 /* Using pure-endian doubles (even if soft-float). */
25138 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25139 flags |= F_VFP_FLOAT;
f17c130b 25140
fde78edd 25141#if defined OBJ_ELF
e74cfd16 25142 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25143 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25144 break;
25145
8cb51566 25146 case EF_ARM_EABI_VER4:
3a4a14e9 25147 case EF_ARM_EABI_VER5:
c19d1205 25148 /* No additional flags to set. */
d507cf36
PB
25149 break;
25150
25151 default:
25152 abort ();
25153 }
7cc69913 25154#endif
b99bd4ef
NC
25155 bfd_set_private_flags (stdoutput, flags);
25156
25157 /* We have run out flags in the COFF header to encode the
25158 status of ATPCS support, so instead we create a dummy,
c19d1205 25159 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25160 if (atpcs)
25161 {
25162 asection * sec;
25163
25164 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25165
25166 if (sec != NULL)
25167 {
25168 bfd_set_section_flags
25169 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25170 bfd_set_section_size (stdoutput, sec, 0);
25171 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25172 }
25173 }
7cc69913 25174 }
f17c130b 25175#endif
b99bd4ef
NC
25176
25177 /* Record the CPU type as well. */
2d447fca
JM
25178 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25179 mach = bfd_mach_arm_iWMMXt2;
25180 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25181 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25182 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25183 mach = bfd_mach_arm_XScale;
e74cfd16 25184 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25185 mach = bfd_mach_arm_ep9312;
e74cfd16 25186 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25187 mach = bfd_mach_arm_5TE;
e74cfd16 25188 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25189 {
e74cfd16 25190 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25191 mach = bfd_mach_arm_5T;
25192 else
25193 mach = bfd_mach_arm_5;
25194 }
e74cfd16 25195 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25196 {
e74cfd16 25197 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25198 mach = bfd_mach_arm_4T;
25199 else
25200 mach = bfd_mach_arm_4;
25201 }
e74cfd16 25202 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25203 mach = bfd_mach_arm_3M;
e74cfd16
PB
25204 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25205 mach = bfd_mach_arm_3;
25206 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25207 mach = bfd_mach_arm_2a;
25208 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25209 mach = bfd_mach_arm_2;
25210 else
25211 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25212
25213 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25214}
25215
c19d1205 25216/* Command line processing. */
b99bd4ef 25217
c19d1205
ZW
25218/* md_parse_option
25219 Invocation line includes a switch not recognized by the base assembler.
25220 See if it's a processor-specific option.
b99bd4ef 25221
c19d1205
ZW
25222 This routine is somewhat complicated by the need for backwards
25223 compatibility (since older releases of gcc can't be changed).
25224 The new options try to make the interface as compatible as
25225 possible with GCC.
b99bd4ef 25226
c19d1205 25227 New options (supported) are:
b99bd4ef 25228
c19d1205
ZW
25229 -mcpu=<cpu name> Assemble for selected processor
25230 -march=<architecture name> Assemble for selected architecture
25231 -mfpu=<fpu architecture> Assemble for selected FPU.
25232 -EB/-mbig-endian Big-endian
25233 -EL/-mlittle-endian Little-endian
25234 -k Generate PIC code
25235 -mthumb Start in Thumb mode
25236 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25237
278df34e 25238 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25239 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25240
c19d1205 25241 For now we will also provide support for:
b99bd4ef 25242
c19d1205
ZW
25243 -mapcs-32 32-bit Program counter
25244 -mapcs-26 26-bit Program counter
25245 -macps-float Floats passed in FP registers
25246 -mapcs-reentrant Reentrant code
25247 -matpcs
25248 (sometime these will probably be replaced with -mapcs=<list of options>
25249 and -matpcs=<list of options>)
b99bd4ef 25250
c19d1205
ZW
25251 The remaining options are only supported for back-wards compatibility.
25252 Cpu variants, the arm part is optional:
25253 -m[arm]1 Currently not supported.
25254 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25255 -m[arm]3 Arm 3 processor
25256 -m[arm]6[xx], Arm 6 processors
25257 -m[arm]7[xx][t][[d]m] Arm 7 processors
25258 -m[arm]8[10] Arm 8 processors
25259 -m[arm]9[20][tdmi] Arm 9 processors
25260 -mstrongarm[110[0]] StrongARM processors
25261 -mxscale XScale processors
25262 -m[arm]v[2345[t[e]]] Arm architectures
25263 -mall All (except the ARM1)
25264 FP variants:
25265 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25266 -mfpe-old (No float load/store multiples)
25267 -mvfpxd VFP Single precision
25268 -mvfp All VFP
25269 -mno-fpu Disable all floating point instructions
b99bd4ef 25270
c19d1205
ZW
25271 The following CPU names are recognized:
25272 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25273 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25274 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25275 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25276 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25277 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25278 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25279
c19d1205 25280 */
b99bd4ef 25281
c19d1205 25282const char * md_shortopts = "m:k";
b99bd4ef 25283
c19d1205
ZW
25284#ifdef ARM_BI_ENDIAN
25285#define OPTION_EB (OPTION_MD_BASE + 0)
25286#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25287#else
c19d1205
ZW
25288#if TARGET_BYTES_BIG_ENDIAN
25289#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25290#else
c19d1205
ZW
25291#define OPTION_EL (OPTION_MD_BASE + 1)
25292#endif
b99bd4ef 25293#endif
845b51d6 25294#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25295
c19d1205 25296struct option md_longopts[] =
b99bd4ef 25297{
c19d1205
ZW
25298#ifdef OPTION_EB
25299 {"EB", no_argument, NULL, OPTION_EB},
25300#endif
25301#ifdef OPTION_EL
25302 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25303#endif
845b51d6 25304 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25305 {NULL, no_argument, NULL, 0}
25306};
b99bd4ef 25307
8b2d793c 25308
c19d1205 25309size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25310
c19d1205 25311struct arm_option_table
b99bd4ef 25312{
e0471c16
TS
25313 const char *option; /* Option name to match. */
25314 const char *help; /* Help information. */
c19d1205
ZW
25315 int *var; /* Variable to change. */
25316 int value; /* What to change it to. */
e0471c16 25317 const char *deprecated; /* If non-null, print this message. */
c19d1205 25318};
b99bd4ef 25319
c19d1205
ZW
25320struct arm_option_table arm_opts[] =
25321{
25322 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25323 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25324 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25325 &support_interwork, 1, NULL},
25326 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25327 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25328 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25329 1, NULL},
25330 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25331 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25332 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25333 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25334 NULL},
b99bd4ef 25335
c19d1205
ZW
25336 /* These are recognized by the assembler, but have no affect on code. */
25337 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25338 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25339
25340 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25341 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25342 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25343 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25344 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25345 {NULL, NULL, NULL, 0, NULL}
25346};
25347
25348struct arm_legacy_option_table
25349{
e0471c16 25350 const char *option; /* Option name to match. */
e74cfd16
PB
25351 const arm_feature_set **var; /* Variable to change. */
25352 const arm_feature_set value; /* What to change it to. */
e0471c16 25353 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25354};
b99bd4ef 25355
e74cfd16
PB
25356const struct arm_legacy_option_table arm_legacy_opts[] =
25357{
c19d1205
ZW
25358 /* DON'T add any new processors to this list -- we want the whole list
25359 to go away... Add them to the processors table instead. */
e74cfd16
PB
25360 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25361 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25362 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25363 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25364 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25365 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25366 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25367 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25368 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25369 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25370 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25371 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25372 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25373 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25374 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25375 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25376 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25377 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25378 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25379 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25380 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25381 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25382 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25383 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25384 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25385 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25386 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25387 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25388 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25389 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25390 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25391 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25392 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25393 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25394 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25395 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25396 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25397 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25398 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25399 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25400 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25401 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25402 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25403 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25404 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25405 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25406 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25407 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25408 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25409 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25410 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25411 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25412 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25413 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25414 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25415 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25416 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25417 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25418 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25419 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25420 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25421 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25422 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25423 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25424 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25425 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25426 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25427 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25428 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25429 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25430 N_("use -mcpu=strongarm110")},
e74cfd16 25431 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25432 N_("use -mcpu=strongarm1100")},
e74cfd16 25433 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25434 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25435 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25436 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25437 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25438
c19d1205 25439 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25440 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25441 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25442 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25443 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25444 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25445 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25446 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25447 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25448 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25449 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25450 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25451 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25452 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25453 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25454 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25455 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25456 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25457 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25458
c19d1205 25459 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25460 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25461 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25462 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25463 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25464 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25465
e74cfd16 25466 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25467};
7ed4c4c5 25468
c19d1205 25469struct arm_cpu_option_table
7ed4c4c5 25470{
e0471c16 25471 const char *name;
f3bad469 25472 size_t name_len;
e74cfd16 25473 const arm_feature_set value;
996b5569 25474 const arm_feature_set ext;
c19d1205
ZW
25475 /* For some CPUs we assume an FPU unless the user explicitly sets
25476 -mfpu=... */
e74cfd16 25477 const arm_feature_set default_fpu;
ee065d83
PB
25478 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25479 case. */
25480 const char *canonical_name;
c19d1205 25481};
7ed4c4c5 25482
c19d1205
ZW
25483/* This list should, at a minimum, contain all the cpu names
25484 recognized by GCC. */
996b5569 25485#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
e74cfd16 25486static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25487{
996b5569
TP
25488 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25489 ARM_ARCH_NONE,
25490 FPU_ARCH_FPA),
25491 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25492 ARM_ARCH_NONE,
25493 FPU_ARCH_FPA),
25494 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25495 ARM_ARCH_NONE,
25496 FPU_ARCH_FPA),
25497 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25498 ARM_ARCH_NONE,
25499 FPU_ARCH_FPA),
25500 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25501 ARM_ARCH_NONE,
25502 FPU_ARCH_FPA),
25503 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25504 ARM_ARCH_NONE,
25505 FPU_ARCH_FPA),
25506 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25507 ARM_ARCH_NONE,
25508 FPU_ARCH_FPA),
25509 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25510 ARM_ARCH_NONE,
25511 FPU_ARCH_FPA),
25512 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25513 ARM_ARCH_NONE,
25514 FPU_ARCH_FPA),
25515 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25516 ARM_ARCH_NONE,
25517 FPU_ARCH_FPA),
25518 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25519 ARM_ARCH_NONE,
25520 FPU_ARCH_FPA),
25521 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25522 ARM_ARCH_NONE,
25523 FPU_ARCH_FPA),
25524 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25525 ARM_ARCH_NONE,
25526 FPU_ARCH_FPA),
25527 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25528 ARM_ARCH_NONE,
25529 FPU_ARCH_FPA),
25530 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25531 ARM_ARCH_NONE,
25532 FPU_ARCH_FPA),
25533 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25534 ARM_ARCH_NONE,
25535 FPU_ARCH_FPA),
25536 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25537 ARM_ARCH_NONE,
25538 FPU_ARCH_FPA),
25539 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25540 ARM_ARCH_NONE,
25541 FPU_ARCH_FPA),
25542 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25543 ARM_ARCH_NONE,
25544 FPU_ARCH_FPA),
25545 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25546 ARM_ARCH_NONE,
25547 FPU_ARCH_FPA),
25548 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25549 ARM_ARCH_NONE,
25550 FPU_ARCH_FPA),
25551 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25552 ARM_ARCH_NONE,
25553 FPU_ARCH_FPA),
25554 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25555 ARM_ARCH_NONE,
25556 FPU_ARCH_FPA),
25557 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25558 ARM_ARCH_NONE,
25559 FPU_ARCH_FPA),
25560 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25561 ARM_ARCH_NONE,
25562 FPU_ARCH_FPA),
25563 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25564 ARM_ARCH_NONE,
25565 FPU_ARCH_FPA),
25566 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25567 ARM_ARCH_NONE,
25568 FPU_ARCH_FPA),
25569 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25570 ARM_ARCH_NONE,
25571 FPU_ARCH_FPA),
25572 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25573 ARM_ARCH_NONE,
25574 FPU_ARCH_FPA),
25575 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25576 ARM_ARCH_NONE,
25577 FPU_ARCH_FPA),
25578 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25579 ARM_ARCH_NONE,
25580 FPU_ARCH_FPA),
25581 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25582 ARM_ARCH_NONE,
25583 FPU_ARCH_FPA),
25584 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25585 ARM_ARCH_NONE,
25586 FPU_ARCH_FPA),
25587 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25588 ARM_ARCH_NONE,
25589 FPU_ARCH_FPA),
25590 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25591 ARM_ARCH_NONE,
25592 FPU_ARCH_FPA),
25593 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25594 ARM_ARCH_NONE,
25595 FPU_ARCH_FPA),
25596 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25597 ARM_ARCH_NONE,
25598 FPU_ARCH_FPA),
25599 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25600 ARM_ARCH_NONE,
25601 FPU_ARCH_FPA),
25602 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25603 ARM_ARCH_NONE,
25604 FPU_ARCH_FPA),
25605 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25606 ARM_ARCH_NONE,
25607 FPU_ARCH_FPA),
25608 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25609 ARM_ARCH_NONE,
25610 FPU_ARCH_FPA),
25611 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25612 ARM_ARCH_NONE,
25613 FPU_ARCH_FPA),
25614 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25615 ARM_ARCH_NONE,
25616 FPU_ARCH_FPA),
25617 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25618 ARM_ARCH_NONE,
25619 FPU_ARCH_FPA),
25620 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25621 ARM_ARCH_NONE,
25622 FPU_ARCH_FPA),
25623 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25624 ARM_ARCH_NONE,
25625 FPU_ARCH_FPA),
25626
c19d1205
ZW
25627 /* For V5 or later processors we default to using VFP; but the user
25628 should really set the FPU type explicitly. */
996b5569
TP
25629 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25630 ARM_ARCH_NONE,
25631 FPU_ARCH_VFP_V2),
25632 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25633 ARM_ARCH_NONE,
25634 FPU_ARCH_VFP_V2),
25635 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25636 ARM_ARCH_NONE,
25637 FPU_ARCH_VFP_V2),
25638 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25639 ARM_ARCH_NONE,
25640 FPU_ARCH_VFP_V2),
25641 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25642 ARM_ARCH_NONE,
25643 FPU_ARCH_VFP_V2),
25644 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25645 ARM_ARCH_NONE,
25646 FPU_ARCH_VFP_V2),
25647 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25648 ARM_ARCH_NONE,
25649 FPU_ARCH_VFP_V2),
25650 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25651 ARM_ARCH_NONE,
25652 FPU_ARCH_VFP_V2),
25653 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25654 ARM_ARCH_NONE,
25655 FPU_ARCH_VFP_V2),
25656 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25657 ARM_ARCH_NONE,
25658 FPU_ARCH_VFP_V2),
25659 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25660 ARM_ARCH_NONE,
25661 FPU_ARCH_VFP_V2),
25662 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25663 ARM_ARCH_NONE,
25664 FPU_ARCH_VFP_V2),
25665 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25666 ARM_ARCH_NONE,
25667 FPU_ARCH_VFP_V1),
25668 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25669 ARM_ARCH_NONE,
25670 FPU_ARCH_VFP_V1),
25671 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25672 ARM_ARCH_NONE,
25673 FPU_ARCH_VFP_V2),
25674 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25675 ARM_ARCH_NONE,
25676 FPU_ARCH_VFP_V2),
25677 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25678 ARM_ARCH_NONE,
25679 FPU_ARCH_VFP_V1),
25680 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25681 ARM_ARCH_NONE,
25682 FPU_ARCH_VFP_V2),
25683 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25684 ARM_ARCH_NONE,
25685 FPU_ARCH_VFP_V2),
25686 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25687 ARM_ARCH_NONE,
25688 FPU_ARCH_VFP_V2),
25689 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25690 ARM_ARCH_NONE,
25691 FPU_ARCH_VFP_V2),
25692 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25693 ARM_ARCH_NONE,
25694 FPU_ARCH_VFP_V2),
25695 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25696 ARM_ARCH_NONE,
25697 FPU_ARCH_VFP_V2),
25698 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25699 ARM_ARCH_NONE,
25700 FPU_ARCH_VFP_V2),
25701 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25702 ARM_ARCH_NONE,
25703 FPU_ARCH_VFP_V2),
25704 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25705 ARM_ARCH_NONE,
25706 FPU_ARCH_VFP_V2),
25707 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25708 ARM_ARCH_NONE,
25709 FPU_NONE),
25710 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25711 ARM_ARCH_NONE,
25712 FPU_NONE),
25713 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25714 ARM_ARCH_NONE,
25715 FPU_ARCH_VFP_V2),
25716 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25717 ARM_ARCH_NONE,
25718 FPU_ARCH_VFP_V2),
25719 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25720 ARM_ARCH_NONE,
25721 FPU_ARCH_VFP_V2),
25722 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25723 ARM_ARCH_NONE,
25724 FPU_NONE),
25725 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25726 ARM_ARCH_NONE,
25727 FPU_NONE),
25728 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
25729 ARM_ARCH_NONE,
25730 FPU_ARCH_VFP_V2),
25731 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
25732 ARM_ARCH_NONE,
25733 FPU_NONE),
25734 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
25735 ARM_ARCH_NONE,
25736 FPU_ARCH_VFP_V2),
25737 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
25738 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25739 FPU_NONE),
25740 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
25741 ARM_ARCH_NONE,
25742 FPU_ARCH_NEON_VFP_V4),
25743 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
25744 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25745 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25746 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
25747 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25748 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25749 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
25750 ARM_ARCH_NONE,
25751 FPU_ARCH_NEON_VFP_V4),
25752 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
25753 ARM_ARCH_NONE,
25754 FPU_ARCH_NEON_VFP_V4),
25755 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
25756 ARM_ARCH_NONE,
25757 FPU_ARCH_NEON_VFP_V4),
25758 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
25759 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25760 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25761 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
25762 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25763 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25764 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
25765 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25766 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25767 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
25768 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25769 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25770 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
25771 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25772 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25773 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
25774 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25775 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25776 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
25777 ARM_ARCH_NONE,
25778 FPU_NONE),
25779 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
25780 ARM_ARCH_NONE,
25781 FPU_ARCH_VFP_V3D16),
25782 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
25783 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25784 FPU_NONE),
25785 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
25786 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25787 FPU_ARCH_VFP_V3D16),
25788 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
25789 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25790 FPU_ARCH_VFP_V3D16),
25791 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
25792 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25793 FPU_NONE),
25794 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
25795 ARM_ARCH_NONE,
25796 FPU_NONE),
25797 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
25798 ARM_ARCH_NONE,
25799 FPU_NONE),
25800 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
25801 ARM_ARCH_NONE,
25802 FPU_NONE),
25803 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
25804 ARM_ARCH_NONE,
25805 FPU_NONE),
25806 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
25807 ARM_ARCH_NONE,
25808 FPU_NONE),
25809 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
25810 ARM_ARCH_NONE,
25811 FPU_NONE),
25812 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
25813 ARM_ARCH_NONE,
25814 FPU_NONE),
25815 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
25816 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25817 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 25818
c19d1205 25819 /* ??? XSCALE is really an architecture. */
996b5569
TP
25820 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
25821 ARM_ARCH_NONE,
25822 FPU_ARCH_VFP_V2),
25823
c19d1205 25824 /* ??? iwmmxt is not a processor. */
996b5569
TP
25825 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
25826 ARM_ARCH_NONE,
25827 FPU_ARCH_VFP_V2),
25828 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
25829 ARM_ARCH_NONE,
25830 FPU_ARCH_VFP_V2),
25831 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
25832 ARM_ARCH_NONE,
25833 FPU_ARCH_VFP_V2),
25834
c19d1205 25835 /* Maverick */
996b5569
TP
25836 ARM_CPU_OPT ("ep9312", "ARM920T",
25837 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
25838 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
25839
da4339ed 25840 /* Marvell processors. */
996b5569
TP
25841 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
25842 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25843 FPU_ARCH_VFP_V3D16),
25844 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
25845 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25846 FPU_ARCH_NEON_VFP_V4),
da4339ed 25847
996b5569
TP
25848 /* APM X-Gene family. */
25849 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
25850 ARM_ARCH_NONE,
25851 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25852 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
25853 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25854 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25855
25856 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25857};
f3bad469 25858#undef ARM_CPU_OPT
7ed4c4c5 25859
c19d1205 25860struct arm_arch_option_table
7ed4c4c5 25861{
e0471c16 25862 const char *name;
f3bad469 25863 size_t name_len;
e74cfd16
PB
25864 const arm_feature_set value;
25865 const arm_feature_set default_fpu;
c19d1205 25866};
7ed4c4c5 25867
c19d1205
ZW
25868/* This list should, at a minimum, contain all the architecture names
25869 recognized by GCC. */
f3bad469 25870#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25871static const struct arm_arch_option_table arm_archs[] =
c19d1205 25872{
f3bad469
MGD
25873 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25874 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25875 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25876 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25877 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25878 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25879 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25880 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25881 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25882 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25883 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25884 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25885 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25886 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25887 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25888 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25889 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25890 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25891 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25892 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25893 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25894 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25895 kept to preserve existing behaviour. */
25896 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25897 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25898 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25899 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25900 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25901 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25902 kept to preserve existing behaviour. */
25903 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25904 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25905 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25906 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25907 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25908 /* The official spelling of the ARMv7 profile variants is the dashed form.
25909 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25910 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25911 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25912 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25913 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25914 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25915 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25916 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25917 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25918 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25919 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25920 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25921 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25922 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 25923 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
f3bad469
MGD
25924 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25925 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25926 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25927 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25928};
f3bad469 25929#undef ARM_ARCH_OPT
7ed4c4c5 25930
69133863
MGD
25931/* ISA extensions in the co-processor and main instruction set space. */
25932struct arm_option_extension_value_table
c19d1205 25933{
e0471c16 25934 const char *name;
f3bad469 25935 size_t name_len;
5a70a223
JB
25936 const arm_feature_set merge_value;
25937 const arm_feature_set clear_value;
d942732e
TP
25938 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25939 indicates that an extension is available for all architectures while
25940 ARM_ANY marks an empty entry. */
25941 const arm_feature_set allowed_archs[2];
c19d1205 25942};
7ed4c4c5 25943
69133863
MGD
25944/* The following table must be in alphabetical order with a NULL last entry.
25945 */
d942732e
TP
25946#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25947#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25948static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25949{
823d2571
TG
25950 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25951 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25952 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25953 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25954 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25955 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25956 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25957 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25958 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25959 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25960 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25961 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25962 ARM_ARCH_V8_2A),
d942732e 25963 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25964 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25965 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25966 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
25967 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
25968 Thumb divide instruction. Due to this having the same name as the
25969 previous entry, this will be ignored when doing command-line parsing and
25970 only considered by build attribute selection code. */
25971 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
25972 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
25973 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 25974 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25975 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25976 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25977 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25978 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25979 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25980 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25981 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25982 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25983 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25984 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25985 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25986 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25987 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25988 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25989 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25990 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25991 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25992 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25993 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25994 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25995 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25996 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25997 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25998 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25999 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26000 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26001 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26002 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26003 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26004 | ARM_EXT_DIV),
26005 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26006 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26007 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26008 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26009 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26010};
f3bad469 26011#undef ARM_EXT_OPT
69133863
MGD
26012
26013/* ISA floating-point and Advanced SIMD extensions. */
26014struct arm_option_fpu_value_table
26015{
e0471c16 26016 const char *name;
69133863 26017 const arm_feature_set value;
c19d1205 26018};
7ed4c4c5 26019
c19d1205
ZW
26020/* This list should, at a minimum, contain all the fpu names
26021 recognized by GCC. */
69133863 26022static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26023{
26024 {"softfpa", FPU_NONE},
26025 {"fpe", FPU_ARCH_FPE},
26026 {"fpe2", FPU_ARCH_FPE},
26027 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26028 {"fpa", FPU_ARCH_FPA},
26029 {"fpa10", FPU_ARCH_FPA},
26030 {"fpa11", FPU_ARCH_FPA},
26031 {"arm7500fe", FPU_ARCH_FPA},
26032 {"softvfp", FPU_ARCH_VFP},
26033 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26034 {"vfp", FPU_ARCH_VFP_V2},
26035 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26036 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26037 {"vfp10", FPU_ARCH_VFP_V2},
26038 {"vfp10-r0", FPU_ARCH_VFP_V1},
26039 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26040 {"vfpv2", FPU_ARCH_VFP_V2},
26041 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26042 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26043 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26044 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26045 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26046 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26047 {"arm1020t", FPU_ARCH_VFP_V1},
26048 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26049 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26050 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26051 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26052 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26053 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26054 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26055 {"vfpv4", FPU_ARCH_VFP_V4},
26056 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26057 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26058 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26059 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26060 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26061 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26062 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26063 {"crypto-neon-fp-armv8",
26064 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26065 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26066 {"crypto-neon-fp-armv8.1",
26067 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26068 {NULL, ARM_ARCH_NONE}
26069};
26070
26071struct arm_option_value_table
26072{
e0471c16 26073 const char *name;
e74cfd16 26074 long value;
c19d1205 26075};
7ed4c4c5 26076
e74cfd16 26077static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26078{
26079 {"hard", ARM_FLOAT_ABI_HARD},
26080 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26081 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26082 {NULL, 0}
c19d1205 26083};
7ed4c4c5 26084
c19d1205 26085#ifdef OBJ_ELF
3a4a14e9 26086/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26087static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26088{
26089 {"gnu", EF_ARM_EABI_UNKNOWN},
26090 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26091 {"5", EF_ARM_EABI_VER5},
e74cfd16 26092 {NULL, 0}
c19d1205
ZW
26093};
26094#endif
7ed4c4c5 26095
c19d1205
ZW
26096struct arm_long_option_table
26097{
e0471c16
TS
26098 const char * option; /* Substring to match. */
26099 const char * help; /* Help information. */
17b9d67d 26100 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26101 const char * deprecated; /* If non-null, print this message. */
c19d1205 26102};
7ed4c4c5 26103
c921be7d 26104static bfd_boolean
c168ce07
TP
26105arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26106 arm_feature_set **ext_set_p)
7ed4c4c5 26107{
69133863 26108 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26109 extensions being added before being removed. We achieve this by having
26110 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26111 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26112 or removing it (0) and only allowing it to change in the order
69133863
MGD
26113 -1 -> 1 -> 0. */
26114 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26115 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26116 int adding_value = -1;
26117
c168ce07
TP
26118 if (!*ext_set_p)
26119 {
26120 *ext_set_p = XNEW (arm_feature_set);
26121 **ext_set_p = arm_arch_none;
26122 }
e74cfd16 26123
c19d1205 26124 while (str != NULL && *str != 0)
7ed4c4c5 26125 {
82b8a785 26126 const char *ext;
f3bad469 26127 size_t len;
7ed4c4c5 26128
c19d1205
ZW
26129 if (*str != '+')
26130 {
26131 as_bad (_("invalid architectural extension"));
c921be7d 26132 return FALSE;
c19d1205 26133 }
7ed4c4c5 26134
c19d1205
ZW
26135 str++;
26136 ext = strchr (str, '+');
7ed4c4c5 26137
c19d1205 26138 if (ext != NULL)
f3bad469 26139 len = ext - str;
c19d1205 26140 else
f3bad469 26141 len = strlen (str);
7ed4c4c5 26142
f3bad469 26143 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26144 {
26145 if (adding_value != 0)
26146 {
26147 adding_value = 0;
26148 opt = arm_extensions;
26149 }
26150
f3bad469 26151 len -= 2;
69133863
MGD
26152 str += 2;
26153 }
f3bad469 26154 else if (len > 0)
69133863
MGD
26155 {
26156 if (adding_value == -1)
26157 {
26158 adding_value = 1;
26159 opt = arm_extensions;
26160 }
26161 else if (adding_value != 1)
26162 {
26163 as_bad (_("must specify extensions to add before specifying "
26164 "those to remove"));
26165 return FALSE;
26166 }
26167 }
26168
f3bad469 26169 if (len == 0)
c19d1205
ZW
26170 {
26171 as_bad (_("missing architectural extension"));
c921be7d 26172 return FALSE;
c19d1205 26173 }
7ed4c4c5 26174
69133863
MGD
26175 gas_assert (adding_value != -1);
26176 gas_assert (opt != NULL);
26177
26178 /* Scan over the options table trying to find an exact match. */
26179 for (; opt->name != NULL; opt++)
f3bad469 26180 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26181 {
d942732e
TP
26182 int i, nb_allowed_archs =
26183 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26184 /* Check we can apply the extension to this architecture. */
d942732e
TP
26185 for (i = 0; i < nb_allowed_archs; i++)
26186 {
26187 /* Empty entry. */
26188 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26189 continue;
c168ce07 26190 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26191 break;
26192 }
26193 if (i == nb_allowed_archs)
69133863
MGD
26194 {
26195 as_bad (_("extension does not apply to the base architecture"));
26196 return FALSE;
26197 }
26198
26199 /* Add or remove the extension. */
26200 if (adding_value)
c168ce07
TP
26201 ARM_MERGE_FEATURE_SETS (**ext_set_p, **ext_set_p,
26202 opt->merge_value);
69133863 26203 else
c168ce07 26204 ARM_CLEAR_FEATURE (**ext_set_p, **ext_set_p, opt->clear_value);
69133863 26205
3d030cdb
TP
26206 /* Allowing Thumb division instructions for ARMv7 in autodetection
26207 rely on this break so that duplicate extensions (extensions
26208 with the same name as a previous extension in the list) are not
26209 considered for command-line parsing. */
c19d1205
ZW
26210 break;
26211 }
7ed4c4c5 26212
c19d1205
ZW
26213 if (opt->name == NULL)
26214 {
69133863
MGD
26215 /* Did we fail to find an extension because it wasn't specified in
26216 alphabetical order, or because it does not exist? */
26217
26218 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26219 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26220 break;
26221
26222 if (opt->name == NULL)
26223 as_bad (_("unknown architectural extension `%s'"), str);
26224 else
26225 as_bad (_("architectural extensions must be specified in "
26226 "alphabetical order"));
26227
c921be7d 26228 return FALSE;
c19d1205 26229 }
69133863
MGD
26230 else
26231 {
26232 /* We should skip the extension we've just matched the next time
26233 round. */
26234 opt++;
26235 }
7ed4c4c5 26236
c19d1205
ZW
26237 str = ext;
26238 };
7ed4c4c5 26239
c921be7d 26240 return TRUE;
c19d1205 26241}
7ed4c4c5 26242
c921be7d 26243static bfd_boolean
17b9d67d 26244arm_parse_cpu (const char *str)
7ed4c4c5 26245{
f3bad469 26246 const struct arm_cpu_option_table *opt;
82b8a785 26247 const char *ext = strchr (str, '+');
f3bad469 26248 size_t len;
7ed4c4c5 26249
c19d1205 26250 if (ext != NULL)
f3bad469 26251 len = ext - str;
7ed4c4c5 26252 else
f3bad469 26253 len = strlen (str);
7ed4c4c5 26254
f3bad469 26255 if (len == 0)
7ed4c4c5 26256 {
c19d1205 26257 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26258 return FALSE;
7ed4c4c5
NC
26259 }
26260
c19d1205 26261 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26262 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26263 {
c168ce07
TP
26264 mcpu_cpu_opt = &opt->value;
26265 if (!dyn_mcpu_ext_opt)
26266 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
26267 *dyn_mcpu_ext_opt = opt->ext;
e74cfd16 26268 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26269 if (opt->canonical_name)
ef8e6722
JW
26270 {
26271 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26272 strcpy (selected_cpu_name, opt->canonical_name);
26273 }
ee065d83
PB
26274 else
26275 {
f3bad469 26276 size_t i;
c921be7d 26277
ef8e6722
JW
26278 if (len >= sizeof selected_cpu_name)
26279 len = (sizeof selected_cpu_name) - 1;
26280
f3bad469 26281 for (i = 0; i < len; i++)
ee065d83
PB
26282 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26283 selected_cpu_name[i] = 0;
26284 }
7ed4c4c5 26285
c19d1205 26286 if (ext != NULL)
c168ce07 26287 return arm_parse_extension (ext, mcpu_cpu_opt, &dyn_mcpu_ext_opt);
7ed4c4c5 26288
c921be7d 26289 return TRUE;
c19d1205 26290 }
7ed4c4c5 26291
c19d1205 26292 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26293 return FALSE;
7ed4c4c5
NC
26294}
26295
c921be7d 26296static bfd_boolean
17b9d67d 26297arm_parse_arch (const char *str)
7ed4c4c5 26298{
e74cfd16 26299 const struct arm_arch_option_table *opt;
82b8a785 26300 const char *ext = strchr (str, '+');
f3bad469 26301 size_t len;
7ed4c4c5 26302
c19d1205 26303 if (ext != NULL)
f3bad469 26304 len = ext - str;
7ed4c4c5 26305 else
f3bad469 26306 len = strlen (str);
7ed4c4c5 26307
f3bad469 26308 if (len == 0)
7ed4c4c5 26309 {
c19d1205 26310 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26311 return FALSE;
7ed4c4c5
NC
26312 }
26313
c19d1205 26314 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26315 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26316 {
e74cfd16
PB
26317 march_cpu_opt = &opt->value;
26318 march_fpu_opt = &opt->default_fpu;
5f4273c7 26319 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26320
c19d1205 26321 if (ext != NULL)
c168ce07 26322 return arm_parse_extension (ext, march_cpu_opt, &dyn_march_ext_opt);
7ed4c4c5 26323
c921be7d 26324 return TRUE;
c19d1205
ZW
26325 }
26326
26327 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26328 return FALSE;
7ed4c4c5 26329}
eb043451 26330
c921be7d 26331static bfd_boolean
17b9d67d 26332arm_parse_fpu (const char * str)
c19d1205 26333{
69133863 26334 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26335
c19d1205
ZW
26336 for (opt = arm_fpus; opt->name != NULL; opt++)
26337 if (streq (opt->name, str))
26338 {
e74cfd16 26339 mfpu_opt = &opt->value;
c921be7d 26340 return TRUE;
c19d1205 26341 }
b99bd4ef 26342
c19d1205 26343 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26344 return FALSE;
c19d1205
ZW
26345}
26346
c921be7d 26347static bfd_boolean
17b9d67d 26348arm_parse_float_abi (const char * str)
b99bd4ef 26349{
e74cfd16 26350 const struct arm_option_value_table * opt;
b99bd4ef 26351
c19d1205
ZW
26352 for (opt = arm_float_abis; opt->name != NULL; opt++)
26353 if (streq (opt->name, str))
26354 {
26355 mfloat_abi_opt = opt->value;
c921be7d 26356 return TRUE;
c19d1205 26357 }
cc8a6dd0 26358
c19d1205 26359 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26360 return FALSE;
c19d1205 26361}
b99bd4ef 26362
c19d1205 26363#ifdef OBJ_ELF
c921be7d 26364static bfd_boolean
17b9d67d 26365arm_parse_eabi (const char * str)
c19d1205 26366{
e74cfd16 26367 const struct arm_option_value_table *opt;
cc8a6dd0 26368
c19d1205
ZW
26369 for (opt = arm_eabis; opt->name != NULL; opt++)
26370 if (streq (opt->name, str))
26371 {
26372 meabi_flags = opt->value;
c921be7d 26373 return TRUE;
c19d1205
ZW
26374 }
26375 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26376 return FALSE;
c19d1205
ZW
26377}
26378#endif
cc8a6dd0 26379
c921be7d 26380static bfd_boolean
17b9d67d 26381arm_parse_it_mode (const char * str)
e07e6e58 26382{
c921be7d 26383 bfd_boolean ret = TRUE;
e07e6e58
NC
26384
26385 if (streq ("arm", str))
26386 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26387 else if (streq ("thumb", str))
26388 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26389 else if (streq ("always", str))
26390 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26391 else if (streq ("never", str))
26392 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26393 else
26394 {
26395 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26396 "arm, thumb, always, or never."), str);
c921be7d 26397 ret = FALSE;
e07e6e58
NC
26398 }
26399
26400 return ret;
26401}
26402
2e6976a8 26403static bfd_boolean
17b9d67d 26404arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26405{
26406 codecomposer_syntax = TRUE;
26407 arm_comment_chars[0] = ';';
26408 arm_line_separator_chars[0] = 0;
26409 return TRUE;
26410}
26411
c19d1205
ZW
26412struct arm_long_option_table arm_long_opts[] =
26413{
26414 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26415 arm_parse_cpu, NULL},
26416 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26417 arm_parse_arch, NULL},
26418 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26419 arm_parse_fpu, NULL},
26420 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26421 arm_parse_float_abi, NULL},
26422#ifdef OBJ_ELF
7fac0536 26423 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26424 arm_parse_eabi, NULL},
26425#endif
e07e6e58
NC
26426 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26427 arm_parse_it_mode, NULL},
2e6976a8
DG
26428 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26429 arm_ccs_mode, NULL},
c19d1205
ZW
26430 {NULL, NULL, 0, NULL}
26431};
cc8a6dd0 26432
c19d1205 26433int
17b9d67d 26434md_parse_option (int c, const char * arg)
c19d1205
ZW
26435{
26436 struct arm_option_table *opt;
e74cfd16 26437 const struct arm_legacy_option_table *fopt;
c19d1205 26438 struct arm_long_option_table *lopt;
b99bd4ef 26439
c19d1205 26440 switch (c)
b99bd4ef 26441 {
c19d1205
ZW
26442#ifdef OPTION_EB
26443 case OPTION_EB:
26444 target_big_endian = 1;
26445 break;
26446#endif
cc8a6dd0 26447
c19d1205
ZW
26448#ifdef OPTION_EL
26449 case OPTION_EL:
26450 target_big_endian = 0;
26451 break;
26452#endif
b99bd4ef 26453
845b51d6
PB
26454 case OPTION_FIX_V4BX:
26455 fix_v4bx = TRUE;
26456 break;
26457
c19d1205
ZW
26458 case 'a':
26459 /* Listing option. Just ignore these, we don't support additional
26460 ones. */
26461 return 0;
b99bd4ef 26462
c19d1205
ZW
26463 default:
26464 for (opt = arm_opts; opt->option != NULL; opt++)
26465 {
26466 if (c == opt->option[0]
26467 && ((arg == NULL && opt->option[1] == 0)
26468 || streq (arg, opt->option + 1)))
26469 {
c19d1205 26470 /* If the option is deprecated, tell the user. */
278df34e 26471 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26472 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26473 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26474
c19d1205
ZW
26475 if (opt->var != NULL)
26476 *opt->var = opt->value;
cc8a6dd0 26477
c19d1205
ZW
26478 return 1;
26479 }
26480 }
b99bd4ef 26481
e74cfd16
PB
26482 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26483 {
26484 if (c == fopt->option[0]
26485 && ((arg == NULL && fopt->option[1] == 0)
26486 || streq (arg, fopt->option + 1)))
26487 {
e74cfd16 26488 /* If the option is deprecated, tell the user. */
278df34e 26489 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26490 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26491 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26492
26493 if (fopt->var != NULL)
26494 *fopt->var = &fopt->value;
26495
26496 return 1;
26497 }
26498 }
26499
c19d1205
ZW
26500 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26501 {
26502 /* These options are expected to have an argument. */
26503 if (c == lopt->option[0]
26504 && arg != NULL
26505 && strncmp (arg, lopt->option + 1,
26506 strlen (lopt->option + 1)) == 0)
26507 {
c19d1205 26508 /* If the option is deprecated, tell the user. */
278df34e 26509 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26510 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26511 _(lopt->deprecated));
b99bd4ef 26512
c19d1205
ZW
26513 /* Call the sup-option parser. */
26514 return lopt->func (arg + strlen (lopt->option) - 1);
26515 }
26516 }
a737bd4d 26517
c19d1205
ZW
26518 return 0;
26519 }
a394c00f 26520
c19d1205
ZW
26521 return 1;
26522}
a394c00f 26523
c19d1205
ZW
26524void
26525md_show_usage (FILE * fp)
a394c00f 26526{
c19d1205
ZW
26527 struct arm_option_table *opt;
26528 struct arm_long_option_table *lopt;
a394c00f 26529
c19d1205 26530 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26531
c19d1205
ZW
26532 for (opt = arm_opts; opt->option != NULL; opt++)
26533 if (opt->help != NULL)
26534 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26535
c19d1205
ZW
26536 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26537 if (lopt->help != NULL)
26538 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26539
c19d1205
ZW
26540#ifdef OPTION_EB
26541 fprintf (fp, _("\
26542 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26543#endif
26544
c19d1205
ZW
26545#ifdef OPTION_EL
26546 fprintf (fp, _("\
26547 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26548#endif
845b51d6
PB
26549
26550 fprintf (fp, _("\
26551 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26552}
ee065d83
PB
26553
26554
26555#ifdef OBJ_ELF
62b3e311
PB
26556typedef struct
26557{
26558 int val;
26559 arm_feature_set flags;
26560} cpu_arch_ver_table;
26561
2c6b98ea
TP
26562/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26563 chronologically for architectures, with an exception for ARMv6-M and
26564 ARMv6S-M due to legacy reasons. No new architecture should have a
26565 special case. This allows for build attribute selection results to be
26566 stable when new architectures are added. */
62b3e311
PB
26567static const cpu_arch_ver_table cpu_arch_ver[] =
26568{
2c6b98ea
TP
26569 {0, ARM_ARCH_V1},
26570 {0, ARM_ARCH_V2},
26571 {0, ARM_ARCH_V2S},
26572 {0, ARM_ARCH_V3},
26573 {0, ARM_ARCH_V3M},
26574 {1, ARM_ARCH_V4xM},
62b3e311 26575 {1, ARM_ARCH_V4},
2c6b98ea 26576 {2, ARM_ARCH_V4TxM},
62b3e311 26577 {2, ARM_ARCH_V4T},
2c6b98ea 26578 {3, ARM_ARCH_V5xM},
62b3e311 26579 {3, ARM_ARCH_V5},
2c6b98ea 26580 {3, ARM_ARCH_V5TxM},
ee3c0378 26581 {3, ARM_ARCH_V5T},
2c6b98ea 26582 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26583 {4, ARM_ARCH_V5TE},
26584 {5, ARM_ARCH_V5TEJ},
26585 {6, ARM_ARCH_V6},
f4c65163 26586 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26587 {7, ARM_ARCH_V6KZ},
26588 {9, ARM_ARCH_V6K},
26589 {8, ARM_ARCH_V6T2},
26590 {8, ARM_ARCH_V6KT2},
26591 {8, ARM_ARCH_V6ZT2},
26592 {8, ARM_ARCH_V6KZT2},
26593
26594 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26595 always selected build attributes to match those of ARMv6-M
26596 (resp. ARMv6S-M). However, due to these architectures being a strict
26597 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26598 would be selected when fully respecting chronology of architectures.
26599 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26600 move them before ARMv7 architectures. */
91e22acd 26601 {11, ARM_ARCH_V6M},
b2a5fbdc 26602 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26603
26604 {10, ARM_ARCH_V7},
26605 {10, ARM_ARCH_V7A},
62b3e311
PB
26606 {10, ARM_ARCH_V7R},
26607 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26608 {10, ARM_ARCH_V7VE},
26609 {13, ARM_ARCH_V7EM},
bca38921 26610 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26611 {14, ARM_ARCH_V8_1A},
26612 {14, ARM_ARCH_V8_2A},
26613 {14, ARM_ARCH_V8_3A},
ff8646ee 26614 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26615 {17, ARM_ARCH_V8M_MAIN},
2c6b98ea 26616 {-1, ARM_ARCH_NONE}
62b3e311
PB
26617};
26618
ee3c0378
AS
26619/* Set an attribute if it has not already been set by the user. */
26620static void
26621aeabi_set_attribute_int (int tag, int value)
26622{
26623 if (tag < 1
26624 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26625 || !attributes_set_explicitly[tag])
26626 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26627}
26628
26629static void
26630aeabi_set_attribute_string (int tag, const char *value)
26631{
26632 if (tag < 1
26633 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26634 || !attributes_set_explicitly[tag])
26635 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26636}
26637
2c6b98ea
TP
26638/* Return whether features in the *NEEDED feature set are available via
26639 extensions for the architecture whose feature set is *ARCH_FSET. */
26640static bfd_boolean
26641have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
26642 const arm_feature_set *needed)
26643{
26644 int i, nb_allowed_archs;
26645 arm_feature_set ext_fset;
26646 const struct arm_option_extension_value_table *opt;
26647
26648 ext_fset = arm_arch_none;
26649 for (opt = arm_extensions; opt->name != NULL; opt++)
26650 {
26651 /* Extension does not provide any feature we need. */
26652 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
26653 continue;
26654
26655 nb_allowed_archs =
26656 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26657 for (i = 0; i < nb_allowed_archs; i++)
26658 {
26659 /* Empty entry. */
26660 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
26661 break;
26662
26663 /* Extension is available, add it. */
26664 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
26665 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
26666 }
26667 }
26668
26669 /* Can we enable all features in *needed? */
26670 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
26671}
26672
26673/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
26674 a given architecture feature set *ARCH_EXT_FSET including extension feature
26675 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
26676 - if true, check for an exact match of the architecture modulo extensions;
26677 - otherwise, select build attribute value of the first superset
26678 architecture released so that results remains stable when new architectures
26679 are added.
26680 For -march/-mcpu=all the build attribute value of the most featureful
26681 architecture is returned. Tag_CPU_arch_profile result is returned in
26682 PROFILE. */
26683static int
26684get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
26685 const arm_feature_set *ext_fset,
26686 char *profile, int exact_match)
26687{
26688 arm_feature_set arch_fset;
26689 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
26690
26691 /* Select most featureful architecture with all its extensions if building
26692 for -march=all as the feature sets used to set build attributes. */
26693 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
26694 {
26695 /* Force revisiting of decision for each new architecture. */
26696 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
26697 *profile = 'A';
26698 return TAG_CPU_ARCH_V8;
26699 }
26700
26701 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
26702
26703 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
26704 {
26705 arm_feature_set known_arch_fset;
26706
26707 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
26708 if (exact_match)
26709 {
26710 /* Base architecture match user-specified architecture and
26711 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
26712 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
26713 {
26714 p_ver_ret = p_ver;
26715 goto found;
26716 }
26717 /* Base architecture match user-specified architecture only
26718 (eg. ARMv6-M in the same case as above). Record it in case we
26719 find a match with above condition. */
26720 else if (p_ver_ret == NULL
26721 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
26722 p_ver_ret = p_ver;
26723 }
26724 else
26725 {
26726
26727 /* Architecture has all features wanted. */
26728 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
26729 {
26730 arm_feature_set added_fset;
26731
26732 /* Compute features added by this architecture over the one
26733 recorded in p_ver_ret. */
26734 if (p_ver_ret != NULL)
26735 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
26736 p_ver_ret->flags);
26737 /* First architecture that match incl. with extensions, or the
26738 only difference in features over the recorded match is
26739 features that were optional and are now mandatory. */
26740 if (p_ver_ret == NULL
26741 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
26742 {
26743 p_ver_ret = p_ver;
26744 goto found;
26745 }
26746 }
26747 else if (p_ver_ret == NULL)
26748 {
26749 arm_feature_set needed_ext_fset;
26750
26751 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
26752
26753 /* Architecture has all features needed when using some
26754 extensions. Record it and continue searching in case there
26755 exist an architecture providing all needed features without
26756 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
26757 OS extension). */
26758 if (have_ext_for_needed_feat_p (&known_arch_fset,
26759 &needed_ext_fset))
26760 p_ver_ret = p_ver;
26761 }
26762 }
26763 }
26764
26765 if (p_ver_ret == NULL)
26766 return -1;
26767
26768found:
26769 /* Tag_CPU_arch_profile. */
26770 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
26771 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
26772 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
26773 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
26774 *profile = 'A';
26775 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
26776 *profile = 'R';
26777 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
26778 *profile = 'M';
26779 else
26780 *profile = '\0';
26781 return p_ver_ret->val;
26782}
26783
ee065d83 26784/* Set the public EABI object attributes. */
c168ce07 26785static void
ee065d83
PB
26786aeabi_set_public_attributes (void)
26787{
69239280 26788 char profile;
2c6b98ea 26789 int arch = -1;
90ec0d68 26790 int virt_sec = 0;
bca38921 26791 int fp16_optional = 0;
2c6b98ea
TP
26792 int skip_exact_match = 0;
26793 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 26794
54bab281
TP
26795 /* Autodetection mode, choose the architecture based the instructions
26796 actually used. */
26797 if (no_cpu_selected ())
26798 {
26799 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 26800
54bab281
TP
26801 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26802 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 26803
54bab281
TP
26804 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26805 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 26806
54bab281
TP
26807 /* We need to make sure that the attributes do not identify us as v6S-M
26808 when the only v6S-M feature in use is the Operating System
26809 Extensions. */
26810 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26811 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
26812 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
26813
26814 /* Code run during relaxation relies on selected_cpu being set. */
26815 selected_cpu = flags;
26816 }
26817 /* Otherwise, choose the architecture based on the capabilities of the
26818 requested cpu. */
26819 else
26820 flags = selected_cpu;
26821 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
7f78eb34 26822
ddd7f988 26823 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26824 if (object_arch)
26825 {
2c6b98ea
TP
26826 ARM_CLEAR_FEATURE (flags_arch, *object_arch, fpu_any);
26827 flags_ext = arm_arch_none;
7a1d4c38 26828 }
2c6b98ea 26829 else
62b3e311 26830 {
2c6b98ea
TP
26831 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
26832 flags_ext = dyn_mcpu_ext_opt ? *dyn_mcpu_ext_opt : arm_arch_none;
26833 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
26834 }
26835
26836 /* When this function is run again after relaxation has happened there is no
26837 way to determine whether an architecture or CPU was specified by the user:
26838 - selected_cpu is set above for relaxation to work;
26839 - march_cpu_opt is not set if only -mcpu or .cpu is used;
26840 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
26841 Therefore, if not in -march=all case we first try an exact match and fall
26842 back to autodetection. */
26843 if (!skip_exact_match)
26844 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
26845 if (arch == -1)
26846 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
26847 if (arch == -1)
26848 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 26849
ee065d83
PB
26850 /* Tag_CPU_name. */
26851 if (selected_cpu_name[0])
26852 {
91d6fa6a 26853 char *q;
ee065d83 26854
91d6fa6a
NC
26855 q = selected_cpu_name;
26856 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26857 {
26858 int i;
5f4273c7 26859
91d6fa6a
NC
26860 q += 4;
26861 for (i = 0; q[i]; i++)
26862 q[i] = TOUPPER (q[i]);
ee065d83 26863 }
91d6fa6a 26864 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26865 }
62f3b8c8 26866
ee065d83 26867 /* Tag_CPU_arch. */
ee3c0378 26868 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26869
62b3e311 26870 /* Tag_CPU_arch_profile. */
69239280
MGD
26871 if (profile != '\0')
26872 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26873
15afaa63 26874 /* Tag_DSP_extension. */
6c290d53
TP
26875 if (dyn_mcpu_ext_opt && ARM_CPU_HAS_FEATURE (*dyn_mcpu_ext_opt, arm_ext_dsp))
26876 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 26877
2c6b98ea 26878 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 26879 /* Tag_ARM_ISA_use. */
ee3c0378 26880 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 26881 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 26882 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26883
ee065d83 26884 /* Tag_THUMB_ISA_use. */
ee3c0378 26885 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 26886 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
26887 {
26888 int thumb_isa_use;
26889
26890 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26891 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26892 thumb_isa_use = 3;
26893 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26894 thumb_isa_use = 2;
26895 else
26896 thumb_isa_use = 1;
26897 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26898 }
62f3b8c8 26899
ee065d83 26900 /* Tag_VFP_arch. */
a715796b
TG
26901 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26902 aeabi_set_attribute_int (Tag_VFP_arch,
26903 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26904 ? 7 : 8);
bca38921 26905 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26906 aeabi_set_attribute_int (Tag_VFP_arch,
26907 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26908 ? 5 : 6);
26909 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26910 {
26911 fp16_optional = 1;
26912 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26913 }
ada65aa3 26914 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26915 {
26916 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26917 fp16_optional = 1;
26918 }
ee3c0378
AS
26919 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26920 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26921 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26922 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26923 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26924
4547cb56
NC
26925 /* Tag_ABI_HardFP_use. */
26926 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26927 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26928 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26929
ee065d83 26930 /* Tag_WMMX_arch. */
ee3c0378
AS
26931 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26932 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26933 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26934 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26935
ee3c0378 26936 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26937 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26938 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26939 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26940 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26941 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26942 {
26943 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26944 {
26945 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26946 }
26947 else
26948 {
26949 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26950 fp16_optional = 1;
26951 }
26952 }
fa94de6b 26953
ee3c0378 26954 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26955 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26956 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26957
69239280
MGD
26958 /* Tag_DIV_use.
26959
26960 We set Tag_DIV_use to two when integer divide instructions have been used
26961 in ARM state, or when Thumb integer divide instructions have been used,
26962 but we have no architecture profile set, nor have we any ARM instructions.
26963
4ed7ed8d
TP
26964 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26965 by the base architecture.
bca38921 26966
69239280 26967 For new architectures we will have to check these tests. */
ff8646ee
TP
26968 gas_assert (arch <= TAG_CPU_ARCH_V8
26969 || (arch >= TAG_CPU_ARCH_V8M_BASE
26970 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26971 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26972 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26973 aeabi_set_attribute_int (Tag_DIV_use, 0);
26974 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26975 || (profile == '\0'
26976 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26977 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26978 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26979
26980 /* Tag_MP_extension_use. */
26981 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26982 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26983
26984 /* Tag Virtualization_use. */
26985 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26986 virt_sec |= 1;
26987 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26988 virt_sec |= 2;
26989 if (virt_sec != 0)
26990 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26991}
26992
c168ce07
TP
26993/* Post relaxation hook. Recompute ARM attributes now that relaxation is
26994 finished and free extension feature bits which will not be used anymore. */
26995void
26996arm_md_post_relax (void)
26997{
26998 aeabi_set_public_attributes ();
26999 XDELETE (dyn_mcpu_ext_opt);
27000 dyn_mcpu_ext_opt = NULL;
27001 XDELETE (dyn_march_ext_opt);
27002 dyn_march_ext_opt = NULL;
27003}
27004
104d59d1 27005/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
27006void
27007arm_md_end (void)
27008{
ee065d83
PB
27009 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27010 return;
27011
27012 aeabi_set_public_attributes ();
ee065d83 27013}
8463be01 27014#endif /* OBJ_ELF */
ee065d83
PB
27015
27016
27017/* Parse a .cpu directive. */
27018
27019static void
27020s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27021{
e74cfd16 27022 const struct arm_cpu_option_table *opt;
ee065d83
PB
27023 char *name;
27024 char saved_char;
27025
27026 name = input_line_pointer;
5f4273c7 27027 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27028 input_line_pointer++;
27029 saved_char = *input_line_pointer;
27030 *input_line_pointer = 0;
27031
27032 /* Skip the first "all" entry. */
27033 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27034 if (streq (opt->name, name))
27035 {
c168ce07
TP
27036 mcpu_cpu_opt = &opt->value;
27037 if (!dyn_mcpu_ext_opt)
27038 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27039 *dyn_mcpu_ext_opt = opt->ext;
27040 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
ee065d83 27041 if (opt->canonical_name)
5f4273c7 27042 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27043 else
27044 {
27045 int i;
27046 for (i = 0; opt->name[i]; i++)
27047 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27048
ee065d83
PB
27049 selected_cpu_name[i] = 0;
27050 }
e74cfd16 27051 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27052 if (dyn_mcpu_ext_opt)
27053 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27054 *input_line_pointer = saved_char;
27055 demand_empty_rest_of_line ();
27056 return;
27057 }
27058 as_bad (_("unknown cpu `%s'"), name);
27059 *input_line_pointer = saved_char;
27060 ignore_rest_of_line ();
27061}
27062
27063
27064/* Parse a .arch directive. */
27065
27066static void
27067s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27068{
e74cfd16 27069 const struct arm_arch_option_table *opt;
ee065d83
PB
27070 char saved_char;
27071 char *name;
27072
27073 name = input_line_pointer;
5f4273c7 27074 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27075 input_line_pointer++;
27076 saved_char = *input_line_pointer;
27077 *input_line_pointer = 0;
27078
27079 /* Skip the first "all" entry. */
27080 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27081 if (streq (opt->name, name))
27082 {
e74cfd16 27083 mcpu_cpu_opt = &opt->value;
c168ce07
TP
27084 XDELETE (dyn_mcpu_ext_opt);
27085 dyn_mcpu_ext_opt = NULL;
27086 selected_cpu = *mcpu_cpu_opt;
5f4273c7 27087 strcpy (selected_cpu_name, opt->name);
c168ce07 27088 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
ee065d83
PB
27089 *input_line_pointer = saved_char;
27090 demand_empty_rest_of_line ();
27091 return;
27092 }
27093
27094 as_bad (_("unknown architecture `%s'\n"), name);
27095 *input_line_pointer = saved_char;
27096 ignore_rest_of_line ();
27097}
27098
27099
7a1d4c38
PB
27100/* Parse a .object_arch directive. */
27101
27102static void
27103s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27104{
27105 const struct arm_arch_option_table *opt;
27106 char saved_char;
27107 char *name;
27108
27109 name = input_line_pointer;
5f4273c7 27110 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27111 input_line_pointer++;
27112 saved_char = *input_line_pointer;
27113 *input_line_pointer = 0;
27114
27115 /* Skip the first "all" entry. */
27116 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27117 if (streq (opt->name, name))
27118 {
27119 object_arch = &opt->value;
27120 *input_line_pointer = saved_char;
27121 demand_empty_rest_of_line ();
27122 return;
27123 }
27124
27125 as_bad (_("unknown architecture `%s'\n"), name);
27126 *input_line_pointer = saved_char;
27127 ignore_rest_of_line ();
27128}
27129
69133863
MGD
27130/* Parse a .arch_extension directive. */
27131
27132static void
27133s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27134{
27135 const struct arm_option_extension_value_table *opt;
d942732e 27136 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27137 char saved_char;
27138 char *name;
27139 int adding_value = 1;
27140
27141 name = input_line_pointer;
27142 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27143 input_line_pointer++;
27144 saved_char = *input_line_pointer;
27145 *input_line_pointer = 0;
27146
27147 if (strlen (name) >= 2
27148 && strncmp (name, "no", 2) == 0)
27149 {
27150 adding_value = 0;
27151 name += 2;
27152 }
27153
27154 for (opt = arm_extensions; opt->name != NULL; opt++)
27155 if (streq (opt->name, name))
27156 {
d942732e
TP
27157 int i, nb_allowed_archs =
27158 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27159 for (i = 0; i < nb_allowed_archs; i++)
27160 {
27161 /* Empty entry. */
27162 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27163 continue;
27164 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
27165 break;
27166 }
27167
27168 if (i == nb_allowed_archs)
69133863
MGD
27169 {
27170 as_bad (_("architectural extension `%s' is not allowed for the "
27171 "current base architecture"), name);
27172 break;
27173 }
27174
c168ce07
TP
27175 if (!dyn_mcpu_ext_opt)
27176 {
27177 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27178 *dyn_mcpu_ext_opt = arm_arch_none;
27179 }
69133863 27180 if (adding_value)
c168ce07 27181 ARM_MERGE_FEATURE_SETS (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
5a70a223 27182 opt->merge_value);
69133863 27183 else
c168ce07
TP
27184 ARM_CLEAR_FEATURE (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
27185 opt->clear_value);
69133863 27186
c168ce07
TP
27187 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
27188 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
69133863
MGD
27189 *input_line_pointer = saved_char;
27190 demand_empty_rest_of_line ();
3d030cdb
TP
27191 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27192 on this return so that duplicate extensions (extensions with the
27193 same name as a previous extension in the list) are not considered
27194 for command-line parsing. */
69133863
MGD
27195 return;
27196 }
27197
27198 if (opt->name == NULL)
e673710a 27199 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27200
27201 *input_line_pointer = saved_char;
27202 ignore_rest_of_line ();
27203}
27204
ee065d83
PB
27205/* Parse a .fpu directive. */
27206
27207static void
27208s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27209{
69133863 27210 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27211 char saved_char;
27212 char *name;
27213
27214 name = input_line_pointer;
5f4273c7 27215 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27216 input_line_pointer++;
27217 saved_char = *input_line_pointer;
27218 *input_line_pointer = 0;
5f4273c7 27219
ee065d83
PB
27220 for (opt = arm_fpus; opt->name != NULL; opt++)
27221 if (streq (opt->name, name))
27222 {
e74cfd16
PB
27223 mfpu_opt = &opt->value;
27224 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27225 if (dyn_mcpu_ext_opt)
27226 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27227 *input_line_pointer = saved_char;
27228 demand_empty_rest_of_line ();
27229 return;
27230 }
27231
27232 as_bad (_("unknown floating point format `%s'\n"), name);
27233 *input_line_pointer = saved_char;
27234 ignore_rest_of_line ();
27235}
ee065d83 27236
794ba86a 27237/* Copy symbol information. */
f31fef98 27238
794ba86a
DJ
27239void
27240arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27241{
27242 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27243}
e04befd0 27244
f31fef98 27245#ifdef OBJ_ELF
e04befd0
AS
27246/* Given a symbolic attribute NAME, return the proper integer value.
27247 Returns -1 if the attribute is not known. */
f31fef98 27248
e04befd0
AS
27249int
27250arm_convert_symbolic_attribute (const char *name)
27251{
f31fef98
NC
27252 static const struct
27253 {
27254 const char * name;
27255 const int tag;
27256 }
27257 attribute_table[] =
27258 {
27259 /* When you modify this table you should
27260 also modify the list in doc/c-arm.texi. */
e04befd0 27261#define T(tag) {#tag, tag}
f31fef98
NC
27262 T (Tag_CPU_raw_name),
27263 T (Tag_CPU_name),
27264 T (Tag_CPU_arch),
27265 T (Tag_CPU_arch_profile),
27266 T (Tag_ARM_ISA_use),
27267 T (Tag_THUMB_ISA_use),
75375b3e 27268 T (Tag_FP_arch),
f31fef98
NC
27269 T (Tag_VFP_arch),
27270 T (Tag_WMMX_arch),
27271 T (Tag_Advanced_SIMD_arch),
27272 T (Tag_PCS_config),
27273 T (Tag_ABI_PCS_R9_use),
27274 T (Tag_ABI_PCS_RW_data),
27275 T (Tag_ABI_PCS_RO_data),
27276 T (Tag_ABI_PCS_GOT_use),
27277 T (Tag_ABI_PCS_wchar_t),
27278 T (Tag_ABI_FP_rounding),
27279 T (Tag_ABI_FP_denormal),
27280 T (Tag_ABI_FP_exceptions),
27281 T (Tag_ABI_FP_user_exceptions),
27282 T (Tag_ABI_FP_number_model),
75375b3e 27283 T (Tag_ABI_align_needed),
f31fef98 27284 T (Tag_ABI_align8_needed),
75375b3e 27285 T (Tag_ABI_align_preserved),
f31fef98
NC
27286 T (Tag_ABI_align8_preserved),
27287 T (Tag_ABI_enum_size),
27288 T (Tag_ABI_HardFP_use),
27289 T (Tag_ABI_VFP_args),
27290 T (Tag_ABI_WMMX_args),
27291 T (Tag_ABI_optimization_goals),
27292 T (Tag_ABI_FP_optimization_goals),
27293 T (Tag_compatibility),
27294 T (Tag_CPU_unaligned_access),
75375b3e 27295 T (Tag_FP_HP_extension),
f31fef98
NC
27296 T (Tag_VFP_HP_extension),
27297 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27298 T (Tag_MPextension_use),
27299 T (Tag_DIV_use),
f31fef98
NC
27300 T (Tag_nodefaults),
27301 T (Tag_also_compatible_with),
27302 T (Tag_conformance),
27303 T (Tag_T2EE_use),
27304 T (Tag_Virtualization_use),
15afaa63 27305 T (Tag_DSP_extension),
cd21e546 27306 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27307#undef T
f31fef98 27308 };
e04befd0
AS
27309 unsigned int i;
27310
27311 if (name == NULL)
27312 return -1;
27313
f31fef98 27314 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27315 if (streq (name, attribute_table[i].name))
e04befd0
AS
27316 return attribute_table[i].tag;
27317
27318 return -1;
27319}
267bf995
RR
27320
27321
93ef582d
NC
27322/* Apply sym value for relocations only in the case that they are for
27323 local symbols in the same segment as the fixup and you have the
27324 respective architectural feature for blx and simple switches. */
267bf995 27325int
93ef582d 27326arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27327{
27328 if (fixP->fx_addsy
27329 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27330 /* PR 17444: If the local symbol is in a different section then a reloc
27331 will always be generated for it, so applying the symbol value now
27332 will result in a double offset being stored in the relocation. */
27333 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27334 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27335 {
27336 switch (fixP->fx_r_type)
27337 {
27338 case BFD_RELOC_ARM_PCREL_BLX:
27339 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27340 if (ARM_IS_FUNC (fixP->fx_addsy))
27341 return 1;
27342 break;
27343
27344 case BFD_RELOC_ARM_PCREL_CALL:
27345 case BFD_RELOC_THUMB_PCREL_BLX:
27346 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27347 return 1;
267bf995
RR
27348 break;
27349
27350 default:
27351 break;
27352 }
27353
27354 }
27355 return 0;
27356}
f31fef98 27357#endif /* OBJ_ELF */