]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Updated Danish translation for the BFD library.
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
6f2750fe 2 Copyright (C) 1994-2016 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 158static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
160static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 164#ifdef OBJ_ELF
e74cfd16 165static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 166#endif
e74cfd16
PB
167static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
168
169#ifdef CPU_DEFAULT
170static const arm_feature_set cpu_default = CPU_DEFAULT;
171#endif
172
823d2571
TG
173static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
174static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
175static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
176static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
177static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
178static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
179static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
180static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 181static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
182 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
183static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
184static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
185static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
186static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
187static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
188static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
189static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
190static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
191static const arm_feature_set arm_ext_v6_notm =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
193static const arm_feature_set arm_ext_v6_dsp =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
195static const arm_feature_set arm_ext_barrier =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
197static const arm_feature_set arm_ext_msr =
198 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
199static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
200static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
201static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
202static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 203#ifdef OBJ_ELF
823d2571 204static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 205#endif
823d2571 206static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 207static const arm_feature_set arm_ext_m =
16a1fa25
TP
208 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M,
209 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
210static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
211static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
212static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
213static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
214static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 215static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 216static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
217static const arm_feature_set arm_ext_v8m_main =
218 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
219/* Instructions in ARMv8-M only found in M profile architectures. */
220static const arm_feature_set arm_ext_v8m_m_only =
221 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
222static const arm_feature_set arm_ext_v6t2_v8m =
223 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
224/* Instructions shared between ARMv8-A and ARMv8-M. */
225static const arm_feature_set arm_ext_atomics =
226 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 227#ifdef OBJ_ELF
15afaa63
TP
228/* DSP instructions Tag_DSP_extension refers to. */
229static const arm_feature_set arm_ext_dsp =
230 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 231#endif
4d1464f2
MW
232static const arm_feature_set arm_ext_ras =
233 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
234/* FP16 instructions. */
235static const arm_feature_set arm_ext_fp16 =
236 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
e74cfd16
PB
237
238static const arm_feature_set arm_arch_any = ARM_ANY;
f85d59c3 239static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
240static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
241static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
69c9e028 242#ifdef OBJ_ELF
251665fc 243static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
69c9e028 244#endif
e74cfd16 245
2d447fca 246static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 247 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 248static const arm_feature_set arm_cext_iwmmxt =
823d2571 249 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 250static const arm_feature_set arm_cext_xscale =
823d2571 251 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 252static const arm_feature_set arm_cext_maverick =
823d2571
TG
253 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
254static const arm_feature_set fpu_fpa_ext_v1 =
255 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
256static const arm_feature_set fpu_fpa_ext_v2 =
257 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 258static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
259 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
260static const arm_feature_set fpu_vfp_ext_v1 =
261 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
262static const arm_feature_set fpu_vfp_ext_v2 =
263 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
264static const arm_feature_set fpu_vfp_ext_v3xd =
265 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
266static const arm_feature_set fpu_vfp_ext_v3 =
267 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 268static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
269 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
270static const arm_feature_set fpu_neon_ext_v1 =
271 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 272static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 273 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 274#ifdef OBJ_ELF
823d2571
TG
275static const arm_feature_set fpu_vfp_fp16 =
276 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
277static const arm_feature_set fpu_neon_ext_fma =
278 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 279#endif
823d2571
TG
280static const arm_feature_set fpu_vfp_ext_fma =
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 282static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 283 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 284static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 285 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 286static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 287 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 288static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 289 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 290static const arm_feature_set crc_ext_armv8 =
823d2571 291 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 292static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 293 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 294
33a392fb 295static int mfloat_abi_opt = -1;
e74cfd16
PB
296/* Record user cpu selection for object attributes. */
297static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 298/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 299static char selected_cpu_name[20];
8d67f500 300
aacf0b33
KT
301extern FLONUM_TYPE generic_floating_point_number;
302
8d67f500
NC
303/* Return if no cpu was selected on command-line. */
304static bfd_boolean
305no_cpu_selected (void)
306{
823d2571 307 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
308}
309
7cc69913 310#ifdef OBJ_ELF
deeaaff8
DJ
311# ifdef EABI_DEFAULT
312static int meabi_flags = EABI_DEFAULT;
313# else
d507cf36 314static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 315# endif
e1da3f5b 316
ee3c0378
AS
317static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
318
e1da3f5b 319bfd_boolean
5f4273c7 320arm_is_eabi (void)
e1da3f5b
PB
321{
322 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
323}
7cc69913 324#endif
b99bd4ef 325
b99bd4ef 326#ifdef OBJ_ELF
c19d1205 327/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
328symbolS * GOT_symbol;
329#endif
330
b99bd4ef
NC
331/* 0: assemble for ARM,
332 1: assemble for Thumb,
333 2: assemble for Thumb even though target CPU does not support thumb
334 instructions. */
335static int thumb_mode = 0;
8dc2430f
NC
336/* A value distinct from the possible values for thumb_mode that we
337 can use to record whether thumb_mode has been copied into the
338 tc_frag_data field of a frag. */
339#define MODE_RECORDED (1 << 4)
b99bd4ef 340
e07e6e58
NC
341/* Specifies the intrinsic IT insn behavior mode. */
342enum implicit_it_mode
343{
344 IMPLICIT_IT_MODE_NEVER = 0x00,
345 IMPLICIT_IT_MODE_ARM = 0x01,
346 IMPLICIT_IT_MODE_THUMB = 0x02,
347 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
348};
349static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
350
c19d1205
ZW
351/* If unified_syntax is true, we are processing the new unified
352 ARM/Thumb syntax. Important differences from the old ARM mode:
353
354 - Immediate operands do not require a # prefix.
355 - Conditional affixes always appear at the end of the
356 instruction. (For backward compatibility, those instructions
357 that formerly had them in the middle, continue to accept them
358 there.)
359 - The IT instruction may appear, and if it does is validated
360 against subsequent conditional affixes. It does not generate
361 machine code.
362
363 Important differences from the old Thumb mode:
364
365 - Immediate operands do not require a # prefix.
366 - Most of the V6T2 instructions are only available in unified mode.
367 - The .N and .W suffixes are recognized and honored (it is an error
368 if they cannot be honored).
369 - All instructions set the flags if and only if they have an 's' affix.
370 - Conditional affixes may be used. They are validated against
371 preceding IT instructions. Unlike ARM mode, you cannot use a
372 conditional affix except in the scope of an IT instruction. */
373
374static bfd_boolean unified_syntax = FALSE;
b99bd4ef 375
bacebabc
RM
376/* An immediate operand can start with #, and ld*, st*, pld operands
377 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
378 before a [, which can appear as the first operand for pld.
379 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
380const char arm_symbol_chars[] = "#[]{}";
bacebabc 381
5287ad62
JB
382enum neon_el_type
383{
dcbf9037 384 NT_invtype,
5287ad62
JB
385 NT_untyped,
386 NT_integer,
387 NT_float,
388 NT_poly,
389 NT_signed,
dcbf9037 390 NT_unsigned
5287ad62
JB
391};
392
393struct neon_type_el
394{
395 enum neon_el_type type;
396 unsigned size;
397};
398
399#define NEON_MAX_TYPE_ELS 4
400
401struct neon_type
402{
403 struct neon_type_el el[NEON_MAX_TYPE_ELS];
404 unsigned elems;
405};
406
e07e6e58
NC
407enum it_instruction_type
408{
409 OUTSIDE_IT_INSN,
410 INSIDE_IT_INSN,
411 INSIDE_IT_LAST_INSN,
412 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 413 if inside, should be the last one. */
e07e6e58 414 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 415 i.e. BKPT and NOP. */
e07e6e58
NC
416 IT_INSN /* The IT insn has been parsed. */
417};
418
ad6cec43
MGD
419/* The maximum number of operands we need. */
420#define ARM_IT_MAX_OPERANDS 6
421
b99bd4ef
NC
422struct arm_it
423{
c19d1205 424 const char * error;
b99bd4ef 425 unsigned long instruction;
c19d1205
ZW
426 int size;
427 int size_req;
428 int cond;
037e8744
JB
429 /* "uncond_value" is set to the value in place of the conditional field in
430 unconditional versions of the instruction, or -1 if nothing is
431 appropriate. */
432 int uncond_value;
5287ad62 433 struct neon_type vectype;
88714cb8
DG
434 /* This does not indicate an actual NEON instruction, only that
435 the mnemonic accepts neon-style type suffixes. */
436 int is_neon;
0110f2b8
PB
437 /* Set to the opcode if the instruction needs relaxation.
438 Zero if the instruction is not relaxed. */
439 unsigned long relax;
b99bd4ef
NC
440 struct
441 {
442 bfd_reloc_code_real_type type;
c19d1205
ZW
443 expressionS exp;
444 int pc_rel;
b99bd4ef 445 } reloc;
b99bd4ef 446
e07e6e58
NC
447 enum it_instruction_type it_insn_type;
448
c19d1205
ZW
449 struct
450 {
451 unsigned reg;
ca3f61f7 452 signed int imm;
dcbf9037 453 struct neon_type_el vectype;
ca3f61f7
NC
454 unsigned present : 1; /* Operand present. */
455 unsigned isreg : 1; /* Operand was a register. */
456 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
457 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
458 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 459 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
460 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
461 instructions. This allows us to disambiguate ARM <-> vector insns. */
462 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 463 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 464 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 465 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
466 unsigned hasreloc : 1; /* Operand has relocation suffix. */
467 unsigned writeback : 1; /* Operand has trailing ! */
468 unsigned preind : 1; /* Preindexed address. */
469 unsigned postind : 1; /* Postindexed address. */
470 unsigned negative : 1; /* Index register was negated. */
471 unsigned shifted : 1; /* Shift applied to operation. */
472 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 473 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
474};
475
c19d1205 476static struct arm_it inst;
b99bd4ef
NC
477
478#define NUM_FLOAT_VALS 8
479
05d2d07e 480const char * fp_const[] =
b99bd4ef
NC
481{
482 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
483};
484
c19d1205 485/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
486#define MAX_LITTLENUMS 6
487
488LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
489
490#define FAIL (-1)
491#define SUCCESS (0)
492
493#define SUFF_S 1
494#define SUFF_D 2
495#define SUFF_E 3
496#define SUFF_P 4
497
c19d1205
ZW
498#define CP_T_X 0x00008000
499#define CP_T_Y 0x00400000
b99bd4ef 500
c19d1205
ZW
501#define CONDS_BIT 0x00100000
502#define LOAD_BIT 0x00100000
b99bd4ef
NC
503
504#define DOUBLE_LOAD_FLAG 0x00000001
505
506struct asm_cond
507{
d3ce72d0 508 const char * template_name;
c921be7d 509 unsigned long value;
b99bd4ef
NC
510};
511
c19d1205 512#define COND_ALWAYS 0xE
b99bd4ef 513
b99bd4ef
NC
514struct asm_psr
515{
d3ce72d0 516 const char * template_name;
c921be7d 517 unsigned long field;
b99bd4ef
NC
518};
519
62b3e311
PB
520struct asm_barrier_opt
521{
e797f7e0
MGD
522 const char * template_name;
523 unsigned long value;
524 const arm_feature_set arch;
62b3e311
PB
525};
526
2d2255b5 527/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
528#define SPSR_BIT (1 << 22)
529
c19d1205
ZW
530/* The individual PSR flag bits. */
531#define PSR_c (1 << 16)
532#define PSR_x (1 << 17)
533#define PSR_s (1 << 18)
534#define PSR_f (1 << 19)
b99bd4ef 535
c19d1205 536struct reloc_entry
bfae80f2 537{
e0471c16 538 const char * name;
c921be7d 539 bfd_reloc_code_real_type reloc;
bfae80f2
RE
540};
541
5287ad62 542enum vfp_reg_pos
bfae80f2 543{
5287ad62
JB
544 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
545 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
546};
547
548enum vfp_ldstm_type
549{
550 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
551};
552
dcbf9037
JB
553/* Bits for DEFINED field in neon_typed_alias. */
554#define NTA_HASTYPE 1
555#define NTA_HASINDEX 2
556
557struct neon_typed_alias
558{
c921be7d
NC
559 unsigned char defined;
560 unsigned char index;
561 struct neon_type_el eltype;
dcbf9037
JB
562};
563
c19d1205
ZW
564/* ARM register categories. This includes coprocessor numbers and various
565 architecture extensions' registers. */
566enum arm_reg_type
bfae80f2 567{
c19d1205
ZW
568 REG_TYPE_RN,
569 REG_TYPE_CP,
570 REG_TYPE_CN,
571 REG_TYPE_FN,
572 REG_TYPE_VFS,
573 REG_TYPE_VFD,
5287ad62 574 REG_TYPE_NQ,
037e8744 575 REG_TYPE_VFSD,
5287ad62 576 REG_TYPE_NDQ,
037e8744 577 REG_TYPE_NSDQ,
c19d1205
ZW
578 REG_TYPE_VFC,
579 REG_TYPE_MVF,
580 REG_TYPE_MVD,
581 REG_TYPE_MVFX,
582 REG_TYPE_MVDX,
583 REG_TYPE_MVAX,
584 REG_TYPE_DSPSC,
585 REG_TYPE_MMXWR,
586 REG_TYPE_MMXWC,
587 REG_TYPE_MMXWCG,
588 REG_TYPE_XSCALE,
90ec0d68 589 REG_TYPE_RNB
bfae80f2
RE
590};
591
dcbf9037
JB
592/* Structure for a hash table entry for a register.
593 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
594 information which states whether a vector type or index is specified (for a
595 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
596struct reg_entry
597{
c921be7d 598 const char * name;
90ec0d68 599 unsigned int number;
c921be7d
NC
600 unsigned char type;
601 unsigned char builtin;
602 struct neon_typed_alias * neon;
6c43fab6
RE
603};
604
c19d1205 605/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 606const char * const reg_expected_msgs[] =
c19d1205
ZW
607{
608 N_("ARM register expected"),
609 N_("bad or missing co-processor number"),
610 N_("co-processor register expected"),
611 N_("FPA register expected"),
612 N_("VFP single precision register expected"),
5287ad62
JB
613 N_("VFP/Neon double precision register expected"),
614 N_("Neon quad precision register expected"),
037e8744 615 N_("VFP single or double precision register expected"),
5287ad62 616 N_("Neon double or quad precision register expected"),
037e8744 617 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
618 N_("VFP system register expected"),
619 N_("Maverick MVF register expected"),
620 N_("Maverick MVD register expected"),
621 N_("Maverick MVFX register expected"),
622 N_("Maverick MVDX register expected"),
623 N_("Maverick MVAX register expected"),
624 N_("Maverick DSPSC register expected"),
625 N_("iWMMXt data register expected"),
626 N_("iWMMXt control register expected"),
627 N_("iWMMXt scalar register expected"),
628 N_("XScale accumulator register expected"),
6c43fab6
RE
629};
630
c19d1205 631/* Some well known registers that we refer to directly elsewhere. */
bd340a04 632#define REG_R12 12
c19d1205
ZW
633#define REG_SP 13
634#define REG_LR 14
635#define REG_PC 15
404ff6b5 636
b99bd4ef
NC
637/* ARM instructions take 4bytes in the object file, Thumb instructions
638 take 2: */
c19d1205 639#define INSN_SIZE 4
b99bd4ef
NC
640
641struct asm_opcode
642{
643 /* Basic string to match. */
d3ce72d0 644 const char * template_name;
c19d1205
ZW
645
646 /* Parameters to instruction. */
5be8be5d 647 unsigned int operands[8];
c19d1205
ZW
648
649 /* Conditional tag - see opcode_lookup. */
650 unsigned int tag : 4;
b99bd4ef
NC
651
652 /* Basic instruction code. */
c19d1205 653 unsigned int avalue : 28;
b99bd4ef 654
c19d1205
ZW
655 /* Thumb-format instruction code. */
656 unsigned int tvalue;
b99bd4ef 657
90e4755a 658 /* Which architecture variant provides this instruction. */
c921be7d
NC
659 const arm_feature_set * avariant;
660 const arm_feature_set * tvariant;
c19d1205
ZW
661
662 /* Function to call to encode instruction in ARM format. */
663 void (* aencode) (void);
b99bd4ef 664
c19d1205
ZW
665 /* Function to call to encode instruction in Thumb format. */
666 void (* tencode) (void);
b99bd4ef
NC
667};
668
a737bd4d
NC
669/* Defines for various bits that we will want to toggle. */
670#define INST_IMMEDIATE 0x02000000
671#define OFFSET_REG 0x02000000
c19d1205 672#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
673#define SHIFT_BY_REG 0x00000010
674#define PRE_INDEX 0x01000000
675#define INDEX_UP 0x00800000
676#define WRITE_BACK 0x00200000
677#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 678#define CPSI_MMOD 0x00020000
90e4755a 679
a737bd4d
NC
680#define LITERAL_MASK 0xf000f000
681#define OPCODE_MASK 0xfe1fffff
682#define V4_STR_BIT 0x00000020
8335d6aa 683#define VLDR_VMOV_SAME 0x0040f000
90e4755a 684
efd81785
PB
685#define T2_SUBS_PC_LR 0xf3de8f00
686
a737bd4d 687#define DATA_OP_SHIFT 21
90e4755a 688
ef8d22e6
PB
689#define T2_OPCODE_MASK 0xfe1fffff
690#define T2_DATA_OP_SHIFT 21
691
6530b175
NC
692#define A_COND_MASK 0xf0000000
693#define A_PUSH_POP_OP_MASK 0x0fff0000
694
695/* Opcodes for pushing/poping registers to/from the stack. */
696#define A1_OPCODE_PUSH 0x092d0000
697#define A2_OPCODE_PUSH 0x052d0004
698#define A2_OPCODE_POP 0x049d0004
699
a737bd4d
NC
700/* Codes to distinguish the arithmetic instructions. */
701#define OPCODE_AND 0
702#define OPCODE_EOR 1
703#define OPCODE_SUB 2
704#define OPCODE_RSB 3
705#define OPCODE_ADD 4
706#define OPCODE_ADC 5
707#define OPCODE_SBC 6
708#define OPCODE_RSC 7
709#define OPCODE_TST 8
710#define OPCODE_TEQ 9
711#define OPCODE_CMP 10
712#define OPCODE_CMN 11
713#define OPCODE_ORR 12
714#define OPCODE_MOV 13
715#define OPCODE_BIC 14
716#define OPCODE_MVN 15
90e4755a 717
ef8d22e6
PB
718#define T2_OPCODE_AND 0
719#define T2_OPCODE_BIC 1
720#define T2_OPCODE_ORR 2
721#define T2_OPCODE_ORN 3
722#define T2_OPCODE_EOR 4
723#define T2_OPCODE_ADD 8
724#define T2_OPCODE_ADC 10
725#define T2_OPCODE_SBC 11
726#define T2_OPCODE_SUB 13
727#define T2_OPCODE_RSB 14
728
a737bd4d
NC
729#define T_OPCODE_MUL 0x4340
730#define T_OPCODE_TST 0x4200
731#define T_OPCODE_CMN 0x42c0
732#define T_OPCODE_NEG 0x4240
733#define T_OPCODE_MVN 0x43c0
90e4755a 734
a737bd4d
NC
735#define T_OPCODE_ADD_R3 0x1800
736#define T_OPCODE_SUB_R3 0x1a00
737#define T_OPCODE_ADD_HI 0x4400
738#define T_OPCODE_ADD_ST 0xb000
739#define T_OPCODE_SUB_ST 0xb080
740#define T_OPCODE_ADD_SP 0xa800
741#define T_OPCODE_ADD_PC 0xa000
742#define T_OPCODE_ADD_I8 0x3000
743#define T_OPCODE_SUB_I8 0x3800
744#define T_OPCODE_ADD_I3 0x1c00
745#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 746
a737bd4d
NC
747#define T_OPCODE_ASR_R 0x4100
748#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
749#define T_OPCODE_LSR_R 0x40c0
750#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
751#define T_OPCODE_ASR_I 0x1000
752#define T_OPCODE_LSL_I 0x0000
753#define T_OPCODE_LSR_I 0x0800
b99bd4ef 754
a737bd4d
NC
755#define T_OPCODE_MOV_I8 0x2000
756#define T_OPCODE_CMP_I8 0x2800
757#define T_OPCODE_CMP_LR 0x4280
758#define T_OPCODE_MOV_HR 0x4600
759#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 760
a737bd4d
NC
761#define T_OPCODE_LDR_PC 0x4800
762#define T_OPCODE_LDR_SP 0x9800
763#define T_OPCODE_STR_SP 0x9000
764#define T_OPCODE_LDR_IW 0x6800
765#define T_OPCODE_STR_IW 0x6000
766#define T_OPCODE_LDR_IH 0x8800
767#define T_OPCODE_STR_IH 0x8000
768#define T_OPCODE_LDR_IB 0x7800
769#define T_OPCODE_STR_IB 0x7000
770#define T_OPCODE_LDR_RW 0x5800
771#define T_OPCODE_STR_RW 0x5000
772#define T_OPCODE_LDR_RH 0x5a00
773#define T_OPCODE_STR_RH 0x5200
774#define T_OPCODE_LDR_RB 0x5c00
775#define T_OPCODE_STR_RB 0x5400
c9b604bd 776
a737bd4d
NC
777#define T_OPCODE_PUSH 0xb400
778#define T_OPCODE_POP 0xbc00
b99bd4ef 779
2fc8bdac 780#define T_OPCODE_BRANCH 0xe000
b99bd4ef 781
a737bd4d 782#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 783#define THUMB_PP_PC_LR 0x0100
c19d1205 784#define THUMB_LOAD_BIT 0x0800
53365c0d 785#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
786
787#define BAD_ARGS _("bad arguments to instruction")
fdfde340 788#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
789#define BAD_PC _("r15 not allowed here")
790#define BAD_COND _("instruction cannot be conditional")
791#define BAD_OVERLAP _("registers may not be the same")
792#define BAD_HIREG _("lo register required")
793#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 794#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
795#define BAD_BRANCH _("branch must be last instruction in IT block")
796#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 797#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
798#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
799#define BAD_IT_COND _("incorrect condition in IT block")
800#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 801#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
802#define BAD_PC_ADDRESSING \
803 _("cannot use register index with PC-relative addressing")
804#define BAD_PC_WRITEBACK \
805 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
806#define BAD_RANGE _("branch out of range")
807#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 808#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 809#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 810
c921be7d
NC
811static struct hash_control * arm_ops_hsh;
812static struct hash_control * arm_cond_hsh;
813static struct hash_control * arm_shift_hsh;
814static struct hash_control * arm_psr_hsh;
815static struct hash_control * arm_v7m_psr_hsh;
816static struct hash_control * arm_reg_hsh;
817static struct hash_control * arm_reloc_hsh;
818static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 819
b99bd4ef
NC
820/* Stuff needed to resolve the label ambiguity
821 As:
822 ...
823 label: <insn>
824 may differ from:
825 ...
826 label:
5f4273c7 827 <insn> */
b99bd4ef
NC
828
829symbolS * last_label_seen;
b34976b6 830static int label_is_thumb_function_name = FALSE;
e07e6e58 831
3d0c9500
NC
832/* Literal pool structure. Held on a per-section
833 and per-sub-section basis. */
a737bd4d 834
c19d1205 835#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 836typedef struct literal_pool
b99bd4ef 837{
c921be7d
NC
838 expressionS literals [MAX_LITERAL_POOL_SIZE];
839 unsigned int next_free_entry;
840 unsigned int id;
841 symbolS * symbol;
842 segT section;
843 subsegT sub_section;
a8040cf2
NC
844#ifdef OBJ_ELF
845 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
846#endif
c921be7d 847 struct literal_pool * next;
8335d6aa 848 unsigned int alignment;
3d0c9500 849} literal_pool;
b99bd4ef 850
3d0c9500
NC
851/* Pointer to a linked list of literal pools. */
852literal_pool * list_of_pools = NULL;
e27ec89e 853
2e6976a8
DG
854typedef enum asmfunc_states
855{
856 OUTSIDE_ASMFUNC,
857 WAITING_ASMFUNC_NAME,
858 WAITING_ENDASMFUNC
859} asmfunc_states;
860
861static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
862
e07e6e58
NC
863#ifdef OBJ_ELF
864# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
865#else
866static struct current_it now_it;
867#endif
868
869static inline int
870now_it_compatible (int cond)
871{
872 return (cond & ~1) == (now_it.cc & ~1);
873}
874
875static inline int
876conditional_insn (void)
877{
878 return inst.cond != COND_ALWAYS;
879}
880
881static int in_it_block (void);
882
883static int handle_it_state (void);
884
885static void force_automatic_it_block_close (void);
886
c921be7d
NC
887static void it_fsm_post_encode (void);
888
e07e6e58
NC
889#define set_it_insn_type(type) \
890 do \
891 { \
892 inst.it_insn_type = type; \
893 if (handle_it_state () == FAIL) \
477330fc 894 return; \
e07e6e58
NC
895 } \
896 while (0)
897
c921be7d
NC
898#define set_it_insn_type_nonvoid(type, failret) \
899 do \
900 { \
901 inst.it_insn_type = type; \
902 if (handle_it_state () == FAIL) \
477330fc 903 return failret; \
c921be7d
NC
904 } \
905 while(0)
906
e07e6e58
NC
907#define set_it_insn_type_last() \
908 do \
909 { \
910 if (inst.cond == COND_ALWAYS) \
477330fc 911 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 912 else \
477330fc 913 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
914 } \
915 while (0)
916
c19d1205 917/* Pure syntax. */
b99bd4ef 918
c19d1205
ZW
919/* This array holds the chars that always start a comment. If the
920 pre-processor is disabled, these aren't very useful. */
2e6976a8 921char arm_comment_chars[] = "@";
3d0c9500 922
c19d1205
ZW
923/* This array holds the chars that only start a comment at the beginning of
924 a line. If the line seems to have the form '# 123 filename'
925 .line and .file directives will appear in the pre-processed output. */
926/* Note that input_file.c hand checks for '#' at the beginning of the
927 first line of the input file. This is because the compiler outputs
928 #NO_APP at the beginning of its output. */
929/* Also note that comments like this one will always work. */
930const char line_comment_chars[] = "#";
3d0c9500 931
2e6976a8 932char arm_line_separator_chars[] = ";";
b99bd4ef 933
c19d1205
ZW
934/* Chars that can be used to separate mant
935 from exp in floating point numbers. */
936const char EXP_CHARS[] = "eE";
3d0c9500 937
c19d1205
ZW
938/* Chars that mean this number is a floating point constant. */
939/* As in 0f12.456 */
940/* or 0d1.2345e12 */
b99bd4ef 941
c19d1205 942const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 943
c19d1205
ZW
944/* Prefix characters that indicate the start of an immediate
945 value. */
946#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 947
c19d1205
ZW
948/* Separator character handling. */
949
950#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
951
952static inline int
953skip_past_char (char ** str, char c)
954{
8ab8155f
NC
955 /* PR gas/14987: Allow for whitespace before the expected character. */
956 skip_whitespace (*str);
427d0db6 957
c19d1205
ZW
958 if (**str == c)
959 {
960 (*str)++;
961 return SUCCESS;
3d0c9500 962 }
c19d1205
ZW
963 else
964 return FAIL;
965}
c921be7d 966
c19d1205 967#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 968
c19d1205
ZW
969/* Arithmetic expressions (possibly involving symbols). */
970
971/* Return TRUE if anything in the expression is a bignum. */
972
973static int
974walk_no_bignums (symbolS * sp)
975{
976 if (symbol_get_value_expression (sp)->X_op == O_big)
977 return 1;
978
979 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 980 {
c19d1205
ZW
981 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
982 || (symbol_get_value_expression (sp)->X_op_symbol
983 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
984 }
985
c19d1205 986 return 0;
3d0c9500
NC
987}
988
c19d1205
ZW
989static int in_my_get_expression = 0;
990
991/* Third argument to my_get_expression. */
992#define GE_NO_PREFIX 0
993#define GE_IMM_PREFIX 1
994#define GE_OPT_PREFIX 2
5287ad62
JB
995/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
996 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
997#define GE_OPT_PREFIX_BIG 3
a737bd4d 998
b99bd4ef 999static int
c19d1205 1000my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1001{
c19d1205
ZW
1002 char * save_in;
1003 segT seg;
b99bd4ef 1004
c19d1205
ZW
1005 /* In unified syntax, all prefixes are optional. */
1006 if (unified_syntax)
5287ad62 1007 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1008 : GE_OPT_PREFIX;
b99bd4ef 1009
c19d1205 1010 switch (prefix_mode)
b99bd4ef 1011 {
c19d1205
ZW
1012 case GE_NO_PREFIX: break;
1013 case GE_IMM_PREFIX:
1014 if (!is_immediate_prefix (**str))
1015 {
1016 inst.error = _("immediate expression requires a # prefix");
1017 return FAIL;
1018 }
1019 (*str)++;
1020 break;
1021 case GE_OPT_PREFIX:
5287ad62 1022 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1023 if (is_immediate_prefix (**str))
1024 (*str)++;
1025 break;
1026 default: abort ();
1027 }
b99bd4ef 1028
c19d1205 1029 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1030
c19d1205
ZW
1031 save_in = input_line_pointer;
1032 input_line_pointer = *str;
1033 in_my_get_expression = 1;
1034 seg = expression (ep);
1035 in_my_get_expression = 0;
1036
f86adc07 1037 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1038 {
f86adc07 1039 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1040 *str = input_line_pointer;
1041 input_line_pointer = save_in;
1042 if (inst.error == NULL)
f86adc07
NS
1043 inst.error = (ep->X_op == O_absent
1044 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1045 return 1;
1046 }
b99bd4ef 1047
c19d1205
ZW
1048#ifdef OBJ_AOUT
1049 if (seg != absolute_section
1050 && seg != text_section
1051 && seg != data_section
1052 && seg != bss_section
1053 && seg != undefined_section)
1054 {
1055 inst.error = _("bad segment");
1056 *str = input_line_pointer;
1057 input_line_pointer = save_in;
1058 return 1;
b99bd4ef 1059 }
87975d2a
AM
1060#else
1061 (void) seg;
c19d1205 1062#endif
b99bd4ef 1063
c19d1205
ZW
1064 /* Get rid of any bignums now, so that we don't generate an error for which
1065 we can't establish a line number later on. Big numbers are never valid
1066 in instructions, which is where this routine is always called. */
5287ad62
JB
1067 if (prefix_mode != GE_OPT_PREFIX_BIG
1068 && (ep->X_op == O_big
477330fc 1069 || (ep->X_add_symbol
5287ad62 1070 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1071 || (ep->X_op_symbol
5287ad62 1072 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1073 {
1074 inst.error = _("invalid constant");
1075 *str = input_line_pointer;
1076 input_line_pointer = save_in;
1077 return 1;
1078 }
b99bd4ef 1079
c19d1205
ZW
1080 *str = input_line_pointer;
1081 input_line_pointer = save_in;
1082 return 0;
b99bd4ef
NC
1083}
1084
c19d1205
ZW
1085/* Turn a string in input_line_pointer into a floating point constant
1086 of type TYPE, and store the appropriate bytes in *LITP. The number
1087 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1088 returned, or NULL on OK.
b99bd4ef 1089
c19d1205
ZW
1090 Note that fp constants aren't represent in the normal way on the ARM.
1091 In big endian mode, things are as expected. However, in little endian
1092 mode fp constants are big-endian word-wise, and little-endian byte-wise
1093 within the words. For example, (double) 1.1 in big endian mode is
1094 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1095 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1096
c19d1205 1097 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1098
6d4af3c2 1099const char *
c19d1205
ZW
1100md_atof (int type, char * litP, int * sizeP)
1101{
1102 int prec;
1103 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1104 char *t;
1105 int i;
b99bd4ef 1106
c19d1205
ZW
1107 switch (type)
1108 {
1109 case 'f':
1110 case 'F':
1111 case 's':
1112 case 'S':
1113 prec = 2;
1114 break;
b99bd4ef 1115
c19d1205
ZW
1116 case 'd':
1117 case 'D':
1118 case 'r':
1119 case 'R':
1120 prec = 4;
1121 break;
b99bd4ef 1122
c19d1205
ZW
1123 case 'x':
1124 case 'X':
499ac353 1125 prec = 5;
c19d1205 1126 break;
b99bd4ef 1127
c19d1205
ZW
1128 case 'p':
1129 case 'P':
499ac353 1130 prec = 5;
c19d1205 1131 break;
a737bd4d 1132
c19d1205
ZW
1133 default:
1134 *sizeP = 0;
499ac353 1135 return _("Unrecognized or unsupported floating point constant");
c19d1205 1136 }
b99bd4ef 1137
c19d1205
ZW
1138 t = atof_ieee (input_line_pointer, type, words);
1139 if (t)
1140 input_line_pointer = t;
499ac353 1141 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1142
c19d1205
ZW
1143 if (target_big_endian)
1144 {
1145 for (i = 0; i < prec; i++)
1146 {
499ac353
NC
1147 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1148 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1149 }
1150 }
1151 else
1152 {
e74cfd16 1153 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1154 for (i = prec - 1; i >= 0; i--)
1155 {
499ac353
NC
1156 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1157 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1158 }
1159 else
1160 /* For a 4 byte float the order of elements in `words' is 1 0.
1161 For an 8 byte float the order is 1 0 3 2. */
1162 for (i = 0; i < prec; i += 2)
1163 {
499ac353
NC
1164 md_number_to_chars (litP, (valueT) words[i + 1],
1165 sizeof (LITTLENUM_TYPE));
1166 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1167 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1168 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1169 }
1170 }
b99bd4ef 1171
499ac353 1172 return NULL;
c19d1205 1173}
b99bd4ef 1174
c19d1205
ZW
1175/* We handle all bad expressions here, so that we can report the faulty
1176 instruction in the error message. */
1177void
91d6fa6a 1178md_operand (expressionS * exp)
c19d1205
ZW
1179{
1180 if (in_my_get_expression)
91d6fa6a 1181 exp->X_op = O_illegal;
b99bd4ef
NC
1182}
1183
c19d1205 1184/* Immediate values. */
b99bd4ef 1185
c19d1205
ZW
1186/* Generic immediate-value read function for use in directives.
1187 Accepts anything that 'expression' can fold to a constant.
1188 *val receives the number. */
1189#ifdef OBJ_ELF
1190static int
1191immediate_for_directive (int *val)
b99bd4ef 1192{
c19d1205
ZW
1193 expressionS exp;
1194 exp.X_op = O_illegal;
b99bd4ef 1195
c19d1205
ZW
1196 if (is_immediate_prefix (*input_line_pointer))
1197 {
1198 input_line_pointer++;
1199 expression (&exp);
1200 }
b99bd4ef 1201
c19d1205
ZW
1202 if (exp.X_op != O_constant)
1203 {
1204 as_bad (_("expected #constant"));
1205 ignore_rest_of_line ();
1206 return FAIL;
1207 }
1208 *val = exp.X_add_number;
1209 return SUCCESS;
b99bd4ef 1210}
c19d1205 1211#endif
b99bd4ef 1212
c19d1205 1213/* Register parsing. */
b99bd4ef 1214
c19d1205
ZW
1215/* Generic register parser. CCP points to what should be the
1216 beginning of a register name. If it is indeed a valid register
1217 name, advance CCP over it and return the reg_entry structure;
1218 otherwise return NULL. Does not issue diagnostics. */
1219
1220static struct reg_entry *
1221arm_reg_parse_multi (char **ccp)
b99bd4ef 1222{
c19d1205
ZW
1223 char *start = *ccp;
1224 char *p;
1225 struct reg_entry *reg;
b99bd4ef 1226
477330fc
RM
1227 skip_whitespace (start);
1228
c19d1205
ZW
1229#ifdef REGISTER_PREFIX
1230 if (*start != REGISTER_PREFIX)
01cfc07f 1231 return NULL;
c19d1205
ZW
1232 start++;
1233#endif
1234#ifdef OPTIONAL_REGISTER_PREFIX
1235 if (*start == OPTIONAL_REGISTER_PREFIX)
1236 start++;
1237#endif
b99bd4ef 1238
c19d1205
ZW
1239 p = start;
1240 if (!ISALPHA (*p) || !is_name_beginner (*p))
1241 return NULL;
b99bd4ef 1242
c19d1205
ZW
1243 do
1244 p++;
1245 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1246
1247 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1248
1249 if (!reg)
1250 return NULL;
1251
1252 *ccp = p;
1253 return reg;
b99bd4ef
NC
1254}
1255
1256static int
dcbf9037 1257arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1258 enum arm_reg_type type)
b99bd4ef 1259{
c19d1205
ZW
1260 /* Alternative syntaxes are accepted for a few register classes. */
1261 switch (type)
1262 {
1263 case REG_TYPE_MVF:
1264 case REG_TYPE_MVD:
1265 case REG_TYPE_MVFX:
1266 case REG_TYPE_MVDX:
1267 /* Generic coprocessor register names are allowed for these. */
79134647 1268 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1269 return reg->number;
1270 break;
69b97547 1271
c19d1205
ZW
1272 case REG_TYPE_CP:
1273 /* For backward compatibility, a bare number is valid here. */
1274 {
1275 unsigned long processor = strtoul (start, ccp, 10);
1276 if (*ccp != start && processor <= 15)
1277 return processor;
1278 }
1a0670f3 1279 /* Fall through. */
6057a28f 1280
c19d1205
ZW
1281 case REG_TYPE_MMXWC:
1282 /* WC includes WCG. ??? I'm not sure this is true for all
1283 instructions that take WC registers. */
79134647 1284 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1285 return reg->number;
6057a28f 1286 break;
c19d1205 1287
6057a28f 1288 default:
c19d1205 1289 break;
6057a28f
NC
1290 }
1291
dcbf9037
JB
1292 return FAIL;
1293}
1294
1295/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1296 return value is the register number or FAIL. */
1297
1298static int
1299arm_reg_parse (char **ccp, enum arm_reg_type type)
1300{
1301 char *start = *ccp;
1302 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1303 int ret;
1304
1305 /* Do not allow a scalar (reg+index) to parse as a register. */
1306 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1307 return FAIL;
1308
1309 if (reg && reg->type == type)
1310 return reg->number;
1311
1312 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1313 return ret;
1314
c19d1205
ZW
1315 *ccp = start;
1316 return FAIL;
1317}
69b97547 1318
dcbf9037
JB
1319/* Parse a Neon type specifier. *STR should point at the leading '.'
1320 character. Does no verification at this stage that the type fits the opcode
1321 properly. E.g.,
1322
1323 .i32.i32.s16
1324 .s32.f32
1325 .u16
1326
1327 Can all be legally parsed by this function.
1328
1329 Fills in neon_type struct pointer with parsed information, and updates STR
1330 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1331 type, FAIL if not. */
1332
1333static int
1334parse_neon_type (struct neon_type *type, char **str)
1335{
1336 char *ptr = *str;
1337
1338 if (type)
1339 type->elems = 0;
1340
1341 while (type->elems < NEON_MAX_TYPE_ELS)
1342 {
1343 enum neon_el_type thistype = NT_untyped;
1344 unsigned thissize = -1u;
1345
1346 if (*ptr != '.')
1347 break;
1348
1349 ptr++;
1350
1351 /* Just a size without an explicit type. */
1352 if (ISDIGIT (*ptr))
1353 goto parsesize;
1354
1355 switch (TOLOWER (*ptr))
1356 {
1357 case 'i': thistype = NT_integer; break;
1358 case 'f': thistype = NT_float; break;
1359 case 'p': thistype = NT_poly; break;
1360 case 's': thistype = NT_signed; break;
1361 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1362 case 'd':
1363 thistype = NT_float;
1364 thissize = 64;
1365 ptr++;
1366 goto done;
dcbf9037
JB
1367 default:
1368 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1369 return FAIL;
1370 }
1371
1372 ptr++;
1373
1374 /* .f is an abbreviation for .f32. */
1375 if (thistype == NT_float && !ISDIGIT (*ptr))
1376 thissize = 32;
1377 else
1378 {
1379 parsesize:
1380 thissize = strtoul (ptr, &ptr, 10);
1381
1382 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1383 && thissize != 64)
1384 {
1385 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1386 return FAIL;
1387 }
1388 }
1389
037e8744 1390 done:
dcbf9037 1391 if (type)
477330fc
RM
1392 {
1393 type->el[type->elems].type = thistype;
dcbf9037
JB
1394 type->el[type->elems].size = thissize;
1395 type->elems++;
1396 }
1397 }
1398
1399 /* Empty/missing type is not a successful parse. */
1400 if (type->elems == 0)
1401 return FAIL;
1402
1403 *str = ptr;
1404
1405 return SUCCESS;
1406}
1407
1408/* Errors may be set multiple times during parsing or bit encoding
1409 (particularly in the Neon bits), but usually the earliest error which is set
1410 will be the most meaningful. Avoid overwriting it with later (cascading)
1411 errors by calling this function. */
1412
1413static void
1414first_error (const char *err)
1415{
1416 if (!inst.error)
1417 inst.error = err;
1418}
1419
1420/* Parse a single type, e.g. ".s32", leading period included. */
1421static int
1422parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1423{
1424 char *str = *ccp;
1425 struct neon_type optype;
1426
1427 if (*str == '.')
1428 {
1429 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1430 {
1431 if (optype.elems == 1)
1432 *vectype = optype.el[0];
1433 else
1434 {
1435 first_error (_("only one type should be specified for operand"));
1436 return FAIL;
1437 }
1438 }
dcbf9037 1439 else
477330fc
RM
1440 {
1441 first_error (_("vector type expected"));
1442 return FAIL;
1443 }
dcbf9037
JB
1444 }
1445 else
1446 return FAIL;
5f4273c7 1447
dcbf9037 1448 *ccp = str;
5f4273c7 1449
dcbf9037
JB
1450 return SUCCESS;
1451}
1452
1453/* Special meanings for indices (which have a range of 0-7), which will fit into
1454 a 4-bit integer. */
1455
1456#define NEON_ALL_LANES 15
1457#define NEON_INTERLEAVE_LANES 14
1458
1459/* Parse either a register or a scalar, with an optional type. Return the
1460 register number, and optionally fill in the actual type of the register
1461 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1462 type/index information in *TYPEINFO. */
1463
1464static int
1465parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1466 enum arm_reg_type *rtype,
1467 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1468{
1469 char *str = *ccp;
1470 struct reg_entry *reg = arm_reg_parse_multi (&str);
1471 struct neon_typed_alias atype;
1472 struct neon_type_el parsetype;
1473
1474 atype.defined = 0;
1475 atype.index = -1;
1476 atype.eltype.type = NT_invtype;
1477 atype.eltype.size = -1;
1478
1479 /* Try alternate syntax for some types of register. Note these are mutually
1480 exclusive with the Neon syntax extensions. */
1481 if (reg == NULL)
1482 {
1483 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1484 if (altreg != FAIL)
477330fc 1485 *ccp = str;
dcbf9037 1486 if (typeinfo)
477330fc 1487 *typeinfo = atype;
dcbf9037
JB
1488 return altreg;
1489 }
1490
037e8744
JB
1491 /* Undo polymorphism when a set of register types may be accepted. */
1492 if ((type == REG_TYPE_NDQ
1493 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1494 || (type == REG_TYPE_VFSD
477330fc 1495 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1496 || (type == REG_TYPE_NSDQ
477330fc
RM
1497 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1498 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1499 || (type == REG_TYPE_MMXWC
1500 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1501 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1502
1503 if (type != reg->type)
1504 return FAIL;
1505
1506 if (reg->neon)
1507 atype = *reg->neon;
5f4273c7 1508
dcbf9037
JB
1509 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1510 {
1511 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1512 {
1513 first_error (_("can't redefine type for operand"));
1514 return FAIL;
1515 }
dcbf9037
JB
1516 atype.defined |= NTA_HASTYPE;
1517 atype.eltype = parsetype;
1518 }
5f4273c7 1519
dcbf9037
JB
1520 if (skip_past_char (&str, '[') == SUCCESS)
1521 {
1522 if (type != REG_TYPE_VFD)
477330fc
RM
1523 {
1524 first_error (_("only D registers may be indexed"));
1525 return FAIL;
1526 }
5f4273c7 1527
dcbf9037 1528 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1529 {
1530 first_error (_("can't change index for operand"));
1531 return FAIL;
1532 }
dcbf9037
JB
1533
1534 atype.defined |= NTA_HASINDEX;
1535
1536 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1537 atype.index = NEON_ALL_LANES;
dcbf9037 1538 else
477330fc
RM
1539 {
1540 expressionS exp;
dcbf9037 1541
477330fc 1542 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1543
477330fc
RM
1544 if (exp.X_op != O_constant)
1545 {
1546 first_error (_("constant expression required"));
1547 return FAIL;
1548 }
dcbf9037 1549
477330fc
RM
1550 if (skip_past_char (&str, ']') == FAIL)
1551 return FAIL;
dcbf9037 1552
477330fc
RM
1553 atype.index = exp.X_add_number;
1554 }
dcbf9037 1555 }
5f4273c7 1556
dcbf9037
JB
1557 if (typeinfo)
1558 *typeinfo = atype;
5f4273c7 1559
dcbf9037
JB
1560 if (rtype)
1561 *rtype = type;
5f4273c7 1562
dcbf9037 1563 *ccp = str;
5f4273c7 1564
dcbf9037
JB
1565 return reg->number;
1566}
1567
1568/* Like arm_reg_parse, but allow allow the following extra features:
1569 - If RTYPE is non-zero, return the (possibly restricted) type of the
1570 register (e.g. Neon double or quad reg when either has been requested).
1571 - If this is a Neon vector type with additional type information, fill
1572 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1573 This function will fault on encountering a scalar. */
dcbf9037
JB
1574
1575static int
1576arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1577 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1578{
1579 struct neon_typed_alias atype;
1580 char *str = *ccp;
1581 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1582
1583 if (reg == FAIL)
1584 return FAIL;
1585
0855e32b
NS
1586 /* Do not allow regname(... to parse as a register. */
1587 if (*str == '(')
1588 return FAIL;
1589
dcbf9037
JB
1590 /* Do not allow a scalar (reg+index) to parse as a register. */
1591 if ((atype.defined & NTA_HASINDEX) != 0)
1592 {
1593 first_error (_("register operand expected, but got scalar"));
1594 return FAIL;
1595 }
1596
1597 if (vectype)
1598 *vectype = atype.eltype;
1599
1600 *ccp = str;
1601
1602 return reg;
1603}
1604
1605#define NEON_SCALAR_REG(X) ((X) >> 4)
1606#define NEON_SCALAR_INDEX(X) ((X) & 15)
1607
5287ad62
JB
1608/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1609 have enough information to be able to do a good job bounds-checking. So, we
1610 just do easy checks here, and do further checks later. */
1611
1612static int
dcbf9037 1613parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1614{
dcbf9037 1615 int reg;
5287ad62 1616 char *str = *ccp;
dcbf9037 1617 struct neon_typed_alias atype;
5f4273c7 1618
dcbf9037 1619 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1620
dcbf9037 1621 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1622 return FAIL;
5f4273c7 1623
dcbf9037 1624 if (atype.index == NEON_ALL_LANES)
5287ad62 1625 {
dcbf9037 1626 first_error (_("scalar must have an index"));
5287ad62
JB
1627 return FAIL;
1628 }
dcbf9037 1629 else if (atype.index >= 64 / elsize)
5287ad62 1630 {
dcbf9037 1631 first_error (_("scalar index out of range"));
5287ad62
JB
1632 return FAIL;
1633 }
5f4273c7 1634
dcbf9037
JB
1635 if (type)
1636 *type = atype.eltype;
5f4273c7 1637
5287ad62 1638 *ccp = str;
5f4273c7 1639
dcbf9037 1640 return reg * 16 + atype.index;
5287ad62
JB
1641}
1642
c19d1205 1643/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1644
c19d1205
ZW
1645static long
1646parse_reg_list (char ** strp)
1647{
1648 char * str = * strp;
1649 long range = 0;
1650 int another_range;
a737bd4d 1651
c19d1205
ZW
1652 /* We come back here if we get ranges concatenated by '+' or '|'. */
1653 do
6057a28f 1654 {
477330fc
RM
1655 skip_whitespace (str);
1656
c19d1205 1657 another_range = 0;
a737bd4d 1658
c19d1205
ZW
1659 if (*str == '{')
1660 {
1661 int in_range = 0;
1662 int cur_reg = -1;
a737bd4d 1663
c19d1205
ZW
1664 str++;
1665 do
1666 {
1667 int reg;
6057a28f 1668
dcbf9037 1669 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1670 {
dcbf9037 1671 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1672 return FAIL;
1673 }
a737bd4d 1674
c19d1205
ZW
1675 if (in_range)
1676 {
1677 int i;
a737bd4d 1678
c19d1205
ZW
1679 if (reg <= cur_reg)
1680 {
dcbf9037 1681 first_error (_("bad range in register list"));
c19d1205
ZW
1682 return FAIL;
1683 }
40a18ebd 1684
c19d1205
ZW
1685 for (i = cur_reg + 1; i < reg; i++)
1686 {
1687 if (range & (1 << i))
1688 as_tsktsk
1689 (_("Warning: duplicated register (r%d) in register list"),
1690 i);
1691 else
1692 range |= 1 << i;
1693 }
1694 in_range = 0;
1695 }
a737bd4d 1696
c19d1205
ZW
1697 if (range & (1 << reg))
1698 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1699 reg);
1700 else if (reg <= cur_reg)
1701 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1702
c19d1205
ZW
1703 range |= 1 << reg;
1704 cur_reg = reg;
1705 }
1706 while (skip_past_comma (&str) != FAIL
1707 || (in_range = 1, *str++ == '-'));
1708 str--;
a737bd4d 1709
d996d970 1710 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1711 {
dcbf9037 1712 first_error (_("missing `}'"));
c19d1205
ZW
1713 return FAIL;
1714 }
1715 }
1716 else
1717 {
91d6fa6a 1718 expressionS exp;
40a18ebd 1719
91d6fa6a 1720 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1721 return FAIL;
40a18ebd 1722
91d6fa6a 1723 if (exp.X_op == O_constant)
c19d1205 1724 {
91d6fa6a
NC
1725 if (exp.X_add_number
1726 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1727 {
1728 inst.error = _("invalid register mask");
1729 return FAIL;
1730 }
a737bd4d 1731
91d6fa6a 1732 if ((range & exp.X_add_number) != 0)
c19d1205 1733 {
91d6fa6a 1734 int regno = range & exp.X_add_number;
a737bd4d 1735
c19d1205
ZW
1736 regno &= -regno;
1737 regno = (1 << regno) - 1;
1738 as_tsktsk
1739 (_("Warning: duplicated register (r%d) in register list"),
1740 regno);
1741 }
a737bd4d 1742
91d6fa6a 1743 range |= exp.X_add_number;
c19d1205
ZW
1744 }
1745 else
1746 {
1747 if (inst.reloc.type != 0)
1748 {
1749 inst.error = _("expression too complex");
1750 return FAIL;
1751 }
a737bd4d 1752
91d6fa6a 1753 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1754 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1755 inst.reloc.pc_rel = 0;
1756 }
1757 }
a737bd4d 1758
c19d1205
ZW
1759 if (*str == '|' || *str == '+')
1760 {
1761 str++;
1762 another_range = 1;
1763 }
a737bd4d 1764 }
c19d1205 1765 while (another_range);
a737bd4d 1766
c19d1205
ZW
1767 *strp = str;
1768 return range;
a737bd4d
NC
1769}
1770
5287ad62
JB
1771/* Types of registers in a list. */
1772
1773enum reg_list_els
1774{
1775 REGLIST_VFP_S,
1776 REGLIST_VFP_D,
1777 REGLIST_NEON_D
1778};
1779
c19d1205
ZW
1780/* Parse a VFP register list. If the string is invalid return FAIL.
1781 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1782 register. Parses registers of type ETYPE.
1783 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1784 - Q registers can be used to specify pairs of D registers
1785 - { } can be omitted from around a singleton register list
477330fc
RM
1786 FIXME: This is not implemented, as it would require backtracking in
1787 some cases, e.g.:
1788 vtbl.8 d3,d4,d5
1789 This could be done (the meaning isn't really ambiguous), but doesn't
1790 fit in well with the current parsing framework.
dcbf9037
JB
1791 - 32 D registers may be used (also true for VFPv3).
1792 FIXME: Types are ignored in these register lists, which is probably a
1793 bug. */
6057a28f 1794
c19d1205 1795static int
037e8744 1796parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1797{
037e8744 1798 char *str = *ccp;
c19d1205
ZW
1799 int base_reg;
1800 int new_base;
21d799b5 1801 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1802 int max_regs = 0;
c19d1205
ZW
1803 int count = 0;
1804 int warned = 0;
1805 unsigned long mask = 0;
a737bd4d 1806 int i;
6057a28f 1807
477330fc 1808 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1809 {
1810 inst.error = _("expecting {");
1811 return FAIL;
1812 }
6057a28f 1813
5287ad62 1814 switch (etype)
c19d1205 1815 {
5287ad62 1816 case REGLIST_VFP_S:
c19d1205
ZW
1817 regtype = REG_TYPE_VFS;
1818 max_regs = 32;
5287ad62 1819 break;
5f4273c7 1820
5287ad62
JB
1821 case REGLIST_VFP_D:
1822 regtype = REG_TYPE_VFD;
b7fc2769 1823 break;
5f4273c7 1824
b7fc2769
JB
1825 case REGLIST_NEON_D:
1826 regtype = REG_TYPE_NDQ;
1827 break;
1828 }
1829
1830 if (etype != REGLIST_VFP_S)
1831 {
b1cc4aeb
PB
1832 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1833 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1834 {
1835 max_regs = 32;
1836 if (thumb_mode)
1837 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1838 fpu_vfp_ext_d32);
1839 else
1840 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1841 fpu_vfp_ext_d32);
1842 }
5287ad62 1843 else
477330fc 1844 max_regs = 16;
c19d1205 1845 }
6057a28f 1846
c19d1205 1847 base_reg = max_regs;
a737bd4d 1848
c19d1205
ZW
1849 do
1850 {
5287ad62 1851 int setmask = 1, addregs = 1;
dcbf9037 1852
037e8744 1853 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1854
c19d1205 1855 if (new_base == FAIL)
a737bd4d 1856 {
dcbf9037 1857 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1858 return FAIL;
1859 }
5f4273c7 1860
b7fc2769 1861 if (new_base >= max_regs)
477330fc
RM
1862 {
1863 first_error (_("register out of range in list"));
1864 return FAIL;
1865 }
5f4273c7 1866
5287ad62
JB
1867 /* Note: a value of 2 * n is returned for the register Q<n>. */
1868 if (regtype == REG_TYPE_NQ)
477330fc
RM
1869 {
1870 setmask = 3;
1871 addregs = 2;
1872 }
5287ad62 1873
c19d1205
ZW
1874 if (new_base < base_reg)
1875 base_reg = new_base;
a737bd4d 1876
5287ad62 1877 if (mask & (setmask << new_base))
c19d1205 1878 {
dcbf9037 1879 first_error (_("invalid register list"));
c19d1205 1880 return FAIL;
a737bd4d 1881 }
a737bd4d 1882
c19d1205
ZW
1883 if ((mask >> new_base) != 0 && ! warned)
1884 {
1885 as_tsktsk (_("register list not in ascending order"));
1886 warned = 1;
1887 }
0bbf2aa4 1888
5287ad62
JB
1889 mask |= setmask << new_base;
1890 count += addregs;
0bbf2aa4 1891
037e8744 1892 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1893 {
1894 int high_range;
0bbf2aa4 1895
037e8744 1896 str++;
0bbf2aa4 1897
037e8744 1898 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1899 == FAIL)
c19d1205
ZW
1900 {
1901 inst.error = gettext (reg_expected_msgs[regtype]);
1902 return FAIL;
1903 }
0bbf2aa4 1904
477330fc
RM
1905 if (high_range >= max_regs)
1906 {
1907 first_error (_("register out of range in list"));
1908 return FAIL;
1909 }
b7fc2769 1910
477330fc
RM
1911 if (regtype == REG_TYPE_NQ)
1912 high_range = high_range + 1;
5287ad62 1913
c19d1205
ZW
1914 if (high_range <= new_base)
1915 {
1916 inst.error = _("register range not in ascending order");
1917 return FAIL;
1918 }
0bbf2aa4 1919
5287ad62 1920 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1921 {
5287ad62 1922 if (mask & (setmask << new_base))
0bbf2aa4 1923 {
c19d1205
ZW
1924 inst.error = _("invalid register list");
1925 return FAIL;
0bbf2aa4 1926 }
c19d1205 1927
5287ad62
JB
1928 mask |= setmask << new_base;
1929 count += addregs;
0bbf2aa4 1930 }
0bbf2aa4 1931 }
0bbf2aa4 1932 }
037e8744 1933 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1934
037e8744 1935 str++;
0bbf2aa4 1936
c19d1205
ZW
1937 /* Sanity check -- should have raised a parse error above. */
1938 if (count == 0 || count > max_regs)
1939 abort ();
1940
1941 *pbase = base_reg;
1942
1943 /* Final test -- the registers must be consecutive. */
1944 mask >>= base_reg;
1945 for (i = 0; i < count; i++)
1946 {
1947 if ((mask & (1u << i)) == 0)
1948 {
1949 inst.error = _("non-contiguous register range");
1950 return FAIL;
1951 }
1952 }
1953
037e8744
JB
1954 *ccp = str;
1955
c19d1205 1956 return count;
b99bd4ef
NC
1957}
1958
dcbf9037
JB
1959/* True if two alias types are the same. */
1960
c921be7d 1961static bfd_boolean
dcbf9037
JB
1962neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1963{
1964 if (!a && !b)
c921be7d 1965 return TRUE;
5f4273c7 1966
dcbf9037 1967 if (!a || !b)
c921be7d 1968 return FALSE;
dcbf9037
JB
1969
1970 if (a->defined != b->defined)
c921be7d 1971 return FALSE;
5f4273c7 1972
dcbf9037
JB
1973 if ((a->defined & NTA_HASTYPE) != 0
1974 && (a->eltype.type != b->eltype.type
477330fc 1975 || a->eltype.size != b->eltype.size))
c921be7d 1976 return FALSE;
dcbf9037
JB
1977
1978 if ((a->defined & NTA_HASINDEX) != 0
1979 && (a->index != b->index))
c921be7d 1980 return FALSE;
5f4273c7 1981
c921be7d 1982 return TRUE;
dcbf9037
JB
1983}
1984
5287ad62
JB
1985/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1986 The base register is put in *PBASE.
dcbf9037 1987 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1988 the return value.
1989 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1990 Bits [6:5] encode the list length (minus one).
1991 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1992
5287ad62 1993#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1994#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1995#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1996
1997static int
dcbf9037 1998parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1999 struct neon_type_el *eltype)
5287ad62
JB
2000{
2001 char *ptr = *str;
2002 int base_reg = -1;
2003 int reg_incr = -1;
2004 int count = 0;
2005 int lane = -1;
2006 int leading_brace = 0;
2007 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2008 const char *const incr_error = _("register stride must be 1 or 2");
2009 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2010 struct neon_typed_alias firsttype;
f85d59c3
KT
2011 firsttype.defined = 0;
2012 firsttype.eltype.type = NT_invtype;
2013 firsttype.eltype.size = -1;
2014 firsttype.index = -1;
5f4273c7 2015
5287ad62
JB
2016 if (skip_past_char (&ptr, '{') == SUCCESS)
2017 leading_brace = 1;
5f4273c7 2018
5287ad62
JB
2019 do
2020 {
dcbf9037
JB
2021 struct neon_typed_alias atype;
2022 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2023
5287ad62 2024 if (getreg == FAIL)
477330fc
RM
2025 {
2026 first_error (_(reg_expected_msgs[rtype]));
2027 return FAIL;
2028 }
5f4273c7 2029
5287ad62 2030 if (base_reg == -1)
477330fc
RM
2031 {
2032 base_reg = getreg;
2033 if (rtype == REG_TYPE_NQ)
2034 {
2035 reg_incr = 1;
2036 }
2037 firsttype = atype;
2038 }
5287ad62 2039 else if (reg_incr == -1)
477330fc
RM
2040 {
2041 reg_incr = getreg - base_reg;
2042 if (reg_incr < 1 || reg_incr > 2)
2043 {
2044 first_error (_(incr_error));
2045 return FAIL;
2046 }
2047 }
5287ad62 2048 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2049 {
2050 first_error (_(incr_error));
2051 return FAIL;
2052 }
dcbf9037 2053
c921be7d 2054 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2055 {
2056 first_error (_(type_error));
2057 return FAIL;
2058 }
5f4273c7 2059
5287ad62 2060 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2061 modes. */
5287ad62 2062 if (ptr[0] == '-')
477330fc
RM
2063 {
2064 struct neon_typed_alias htype;
2065 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2066 if (lane == -1)
2067 lane = NEON_INTERLEAVE_LANES;
2068 else if (lane != NEON_INTERLEAVE_LANES)
2069 {
2070 first_error (_(type_error));
2071 return FAIL;
2072 }
2073 if (reg_incr == -1)
2074 reg_incr = 1;
2075 else if (reg_incr != 1)
2076 {
2077 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2078 return FAIL;
2079 }
2080 ptr++;
2081 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2082 if (hireg == FAIL)
2083 {
2084 first_error (_(reg_expected_msgs[rtype]));
2085 return FAIL;
2086 }
2087 if (! neon_alias_types_same (&htype, &firsttype))
2088 {
2089 first_error (_(type_error));
2090 return FAIL;
2091 }
2092 count += hireg + dregs - getreg;
2093 continue;
2094 }
5f4273c7 2095
5287ad62
JB
2096 /* If we're using Q registers, we can't use [] or [n] syntax. */
2097 if (rtype == REG_TYPE_NQ)
477330fc
RM
2098 {
2099 count += 2;
2100 continue;
2101 }
5f4273c7 2102
dcbf9037 2103 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2104 {
2105 if (lane == -1)
2106 lane = atype.index;
2107 else if (lane != atype.index)
2108 {
2109 first_error (_(type_error));
2110 return FAIL;
2111 }
2112 }
5287ad62 2113 else if (lane == -1)
477330fc 2114 lane = NEON_INTERLEAVE_LANES;
5287ad62 2115 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2116 {
2117 first_error (_(type_error));
2118 return FAIL;
2119 }
5287ad62
JB
2120 count++;
2121 }
2122 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2123
5287ad62
JB
2124 /* No lane set by [x]. We must be interleaving structures. */
2125 if (lane == -1)
2126 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2127
5287ad62
JB
2128 /* Sanity check. */
2129 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2130 || (count > 1 && reg_incr == -1))
2131 {
dcbf9037 2132 first_error (_("error parsing element/structure list"));
5287ad62
JB
2133 return FAIL;
2134 }
2135
2136 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2137 {
dcbf9037 2138 first_error (_("expected }"));
5287ad62
JB
2139 return FAIL;
2140 }
5f4273c7 2141
5287ad62
JB
2142 if (reg_incr == -1)
2143 reg_incr = 1;
2144
dcbf9037
JB
2145 if (eltype)
2146 *eltype = firsttype.eltype;
2147
5287ad62
JB
2148 *pbase = base_reg;
2149 *str = ptr;
5f4273c7 2150
5287ad62
JB
2151 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2152}
2153
c19d1205
ZW
2154/* Parse an explicit relocation suffix on an expression. This is
2155 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2156 arm_reloc_hsh contains no entries, so this function can only
2157 succeed if there is no () after the word. Returns -1 on error,
2158 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2159
c19d1205
ZW
2160static int
2161parse_reloc (char **str)
b99bd4ef 2162{
c19d1205
ZW
2163 struct reloc_entry *r;
2164 char *p, *q;
b99bd4ef 2165
c19d1205
ZW
2166 if (**str != '(')
2167 return BFD_RELOC_UNUSED;
b99bd4ef 2168
c19d1205
ZW
2169 p = *str + 1;
2170 q = p;
2171
2172 while (*q && *q != ')' && *q != ',')
2173 q++;
2174 if (*q != ')')
2175 return -1;
2176
21d799b5
NC
2177 if ((r = (struct reloc_entry *)
2178 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2179 return -1;
2180
2181 *str = q + 1;
2182 return r->reloc;
b99bd4ef
NC
2183}
2184
c19d1205
ZW
2185/* Directives: register aliases. */
2186
dcbf9037 2187static struct reg_entry *
90ec0d68 2188insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2189{
d3ce72d0 2190 struct reg_entry *new_reg;
c19d1205 2191 const char *name;
b99bd4ef 2192
d3ce72d0 2193 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2194 {
d3ce72d0 2195 if (new_reg->builtin)
c19d1205 2196 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2197
c19d1205
ZW
2198 /* Only warn about a redefinition if it's not defined as the
2199 same register. */
d3ce72d0 2200 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2201 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2202
d929913e 2203 return NULL;
c19d1205 2204 }
b99bd4ef 2205
c19d1205 2206 name = xstrdup (str);
325801bd 2207 new_reg = XNEW (struct reg_entry);
b99bd4ef 2208
d3ce72d0
NC
2209 new_reg->name = name;
2210 new_reg->number = number;
2211 new_reg->type = type;
2212 new_reg->builtin = FALSE;
2213 new_reg->neon = NULL;
b99bd4ef 2214
d3ce72d0 2215 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2216 abort ();
5f4273c7 2217
d3ce72d0 2218 return new_reg;
dcbf9037
JB
2219}
2220
2221static void
2222insert_neon_reg_alias (char *str, int number, int type,
477330fc 2223 struct neon_typed_alias *atype)
dcbf9037
JB
2224{
2225 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2226
dcbf9037
JB
2227 if (!reg)
2228 {
2229 first_error (_("attempt to redefine typed alias"));
2230 return;
2231 }
5f4273c7 2232
dcbf9037
JB
2233 if (atype)
2234 {
325801bd 2235 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2236 *reg->neon = *atype;
2237 }
c19d1205 2238}
b99bd4ef 2239
c19d1205 2240/* Look for the .req directive. This is of the form:
b99bd4ef 2241
c19d1205 2242 new_register_name .req existing_register_name
b99bd4ef 2243
c19d1205 2244 If we find one, or if it looks sufficiently like one that we want to
d929913e 2245 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2246
d929913e 2247static bfd_boolean
c19d1205
ZW
2248create_register_alias (char * newname, char *p)
2249{
2250 struct reg_entry *old;
2251 char *oldname, *nbuf;
2252 size_t nlen;
b99bd4ef 2253
c19d1205
ZW
2254 /* The input scrubber ensures that whitespace after the mnemonic is
2255 collapsed to single spaces. */
2256 oldname = p;
2257 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2258 return FALSE;
b99bd4ef 2259
c19d1205
ZW
2260 oldname += 6;
2261 if (*oldname == '\0')
d929913e 2262 return FALSE;
b99bd4ef 2263
21d799b5 2264 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2265 if (!old)
b99bd4ef 2266 {
c19d1205 2267 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2268 return TRUE;
b99bd4ef
NC
2269 }
2270
c19d1205
ZW
2271 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2272 the desired alias name, and p points to its end. If not, then
2273 the desired alias name is in the global original_case_string. */
2274#ifdef TC_CASE_SENSITIVE
2275 nlen = p - newname;
2276#else
2277 newname = original_case_string;
2278 nlen = strlen (newname);
2279#endif
b99bd4ef 2280
29a2809e 2281 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2282
c19d1205
ZW
2283 /* Create aliases under the new name as stated; an all-lowercase
2284 version of the new name; and an all-uppercase version of the new
2285 name. */
d929913e
NC
2286 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2287 {
2288 for (p = nbuf; *p; p++)
2289 *p = TOUPPER (*p);
c19d1205 2290
d929913e
NC
2291 if (strncmp (nbuf, newname, nlen))
2292 {
2293 /* If this attempt to create an additional alias fails, do not bother
2294 trying to create the all-lower case alias. We will fail and issue
2295 a second, duplicate error message. This situation arises when the
2296 programmer does something like:
2297 foo .req r0
2298 Foo .req r1
2299 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2300 the artificial FOO alias because it has already been created by the
d929913e
NC
2301 first .req. */
2302 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2303 {
2304 free (nbuf);
2305 return TRUE;
2306 }
d929913e 2307 }
c19d1205 2308
d929913e
NC
2309 for (p = nbuf; *p; p++)
2310 *p = TOLOWER (*p);
c19d1205 2311
d929913e
NC
2312 if (strncmp (nbuf, newname, nlen))
2313 insert_reg_alias (nbuf, old->number, old->type);
2314 }
c19d1205 2315
e1fa0163 2316 free (nbuf);
d929913e 2317 return TRUE;
b99bd4ef
NC
2318}
2319
dcbf9037
JB
2320/* Create a Neon typed/indexed register alias using directives, e.g.:
2321 X .dn d5.s32[1]
2322 Y .qn 6.s16
2323 Z .dn d7
2324 T .dn Z[0]
2325 These typed registers can be used instead of the types specified after the
2326 Neon mnemonic, so long as all operands given have types. Types can also be
2327 specified directly, e.g.:
5f4273c7 2328 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2329
c921be7d 2330static bfd_boolean
dcbf9037
JB
2331create_neon_reg_alias (char *newname, char *p)
2332{
2333 enum arm_reg_type basetype;
2334 struct reg_entry *basereg;
2335 struct reg_entry mybasereg;
2336 struct neon_type ntype;
2337 struct neon_typed_alias typeinfo;
12d6b0b7 2338 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2339 int namelen;
5f4273c7 2340
dcbf9037
JB
2341 typeinfo.defined = 0;
2342 typeinfo.eltype.type = NT_invtype;
2343 typeinfo.eltype.size = -1;
2344 typeinfo.index = -1;
5f4273c7 2345
dcbf9037 2346 nameend = p;
5f4273c7 2347
dcbf9037
JB
2348 if (strncmp (p, " .dn ", 5) == 0)
2349 basetype = REG_TYPE_VFD;
2350 else if (strncmp (p, " .qn ", 5) == 0)
2351 basetype = REG_TYPE_NQ;
2352 else
c921be7d 2353 return FALSE;
5f4273c7 2354
dcbf9037 2355 p += 5;
5f4273c7 2356
dcbf9037 2357 if (*p == '\0')
c921be7d 2358 return FALSE;
5f4273c7 2359
dcbf9037
JB
2360 basereg = arm_reg_parse_multi (&p);
2361
2362 if (basereg && basereg->type != basetype)
2363 {
2364 as_bad (_("bad type for register"));
c921be7d 2365 return FALSE;
dcbf9037
JB
2366 }
2367
2368 if (basereg == NULL)
2369 {
2370 expressionS exp;
2371 /* Try parsing as an integer. */
2372 my_get_expression (&exp, &p, GE_NO_PREFIX);
2373 if (exp.X_op != O_constant)
477330fc
RM
2374 {
2375 as_bad (_("expression must be constant"));
2376 return FALSE;
2377 }
dcbf9037
JB
2378 basereg = &mybasereg;
2379 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2380 : exp.X_add_number;
dcbf9037
JB
2381 basereg->neon = 0;
2382 }
2383
2384 if (basereg->neon)
2385 typeinfo = *basereg->neon;
2386
2387 if (parse_neon_type (&ntype, &p) == SUCCESS)
2388 {
2389 /* We got a type. */
2390 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2391 {
2392 as_bad (_("can't redefine the type of a register alias"));
2393 return FALSE;
2394 }
5f4273c7 2395
dcbf9037
JB
2396 typeinfo.defined |= NTA_HASTYPE;
2397 if (ntype.elems != 1)
477330fc
RM
2398 {
2399 as_bad (_("you must specify a single type only"));
2400 return FALSE;
2401 }
dcbf9037
JB
2402 typeinfo.eltype = ntype.el[0];
2403 }
5f4273c7 2404
dcbf9037
JB
2405 if (skip_past_char (&p, '[') == SUCCESS)
2406 {
2407 expressionS exp;
2408 /* We got a scalar index. */
5f4273c7 2409
dcbf9037 2410 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2411 {
2412 as_bad (_("can't redefine the index of a scalar alias"));
2413 return FALSE;
2414 }
5f4273c7 2415
dcbf9037 2416 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2417
dcbf9037 2418 if (exp.X_op != O_constant)
477330fc
RM
2419 {
2420 as_bad (_("scalar index must be constant"));
2421 return FALSE;
2422 }
5f4273c7 2423
dcbf9037
JB
2424 typeinfo.defined |= NTA_HASINDEX;
2425 typeinfo.index = exp.X_add_number;
5f4273c7 2426
dcbf9037 2427 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2428 {
2429 as_bad (_("expecting ]"));
2430 return FALSE;
2431 }
dcbf9037
JB
2432 }
2433
15735687
NS
2434 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2435 the desired alias name, and p points to its end. If not, then
2436 the desired alias name is in the global original_case_string. */
2437#ifdef TC_CASE_SENSITIVE
dcbf9037 2438 namelen = nameend - newname;
15735687
NS
2439#else
2440 newname = original_case_string;
2441 namelen = strlen (newname);
2442#endif
2443
29a2809e 2444 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2445
dcbf9037 2446 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2447 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2448
dcbf9037
JB
2449 /* Insert name in all uppercase. */
2450 for (p = namebuf; *p; p++)
2451 *p = TOUPPER (*p);
5f4273c7 2452
dcbf9037
JB
2453 if (strncmp (namebuf, newname, namelen))
2454 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2455 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2456
dcbf9037
JB
2457 /* Insert name in all lowercase. */
2458 for (p = namebuf; *p; p++)
2459 *p = TOLOWER (*p);
5f4273c7 2460
dcbf9037
JB
2461 if (strncmp (namebuf, newname, namelen))
2462 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2463 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2464
e1fa0163 2465 free (namebuf);
c921be7d 2466 return TRUE;
dcbf9037
JB
2467}
2468
c19d1205
ZW
2469/* Should never be called, as .req goes between the alias and the
2470 register name, not at the beginning of the line. */
c921be7d 2471
b99bd4ef 2472static void
c19d1205 2473s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2474{
c19d1205
ZW
2475 as_bad (_("invalid syntax for .req directive"));
2476}
b99bd4ef 2477
dcbf9037
JB
2478static void
2479s_dn (int a ATTRIBUTE_UNUSED)
2480{
2481 as_bad (_("invalid syntax for .dn directive"));
2482}
2483
2484static void
2485s_qn (int a ATTRIBUTE_UNUSED)
2486{
2487 as_bad (_("invalid syntax for .qn directive"));
2488}
2489
c19d1205
ZW
2490/* The .unreq directive deletes an alias which was previously defined
2491 by .req. For example:
b99bd4ef 2492
c19d1205
ZW
2493 my_alias .req r11
2494 .unreq my_alias */
b99bd4ef
NC
2495
2496static void
c19d1205 2497s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2498{
c19d1205
ZW
2499 char * name;
2500 char saved_char;
b99bd4ef 2501
c19d1205
ZW
2502 name = input_line_pointer;
2503
2504 while (*input_line_pointer != 0
2505 && *input_line_pointer != ' '
2506 && *input_line_pointer != '\n')
2507 ++input_line_pointer;
2508
2509 saved_char = *input_line_pointer;
2510 *input_line_pointer = 0;
2511
2512 if (!*name)
2513 as_bad (_("invalid syntax for .unreq directive"));
2514 else
2515 {
21d799b5 2516 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2517 name);
c19d1205
ZW
2518
2519 if (!reg)
2520 as_bad (_("unknown register alias '%s'"), name);
2521 else if (reg->builtin)
a1727c1a 2522 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2523 name);
2524 else
2525 {
d929913e
NC
2526 char * p;
2527 char * nbuf;
2528
db0bc284 2529 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2530 free ((char *) reg->name);
477330fc
RM
2531 if (reg->neon)
2532 free (reg->neon);
c19d1205 2533 free (reg);
d929913e
NC
2534
2535 /* Also locate the all upper case and all lower case versions.
2536 Do not complain if we cannot find one or the other as it
2537 was probably deleted above. */
5f4273c7 2538
d929913e
NC
2539 nbuf = strdup (name);
2540 for (p = nbuf; *p; p++)
2541 *p = TOUPPER (*p);
21d799b5 2542 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2543 if (reg)
2544 {
db0bc284 2545 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2546 free ((char *) reg->name);
2547 if (reg->neon)
2548 free (reg->neon);
2549 free (reg);
2550 }
2551
2552 for (p = nbuf; *p; p++)
2553 *p = TOLOWER (*p);
21d799b5 2554 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2555 if (reg)
2556 {
db0bc284 2557 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2558 free ((char *) reg->name);
2559 if (reg->neon)
2560 free (reg->neon);
2561 free (reg);
2562 }
2563
2564 free (nbuf);
c19d1205
ZW
2565 }
2566 }
b99bd4ef 2567
c19d1205 2568 *input_line_pointer = saved_char;
b99bd4ef
NC
2569 demand_empty_rest_of_line ();
2570}
2571
c19d1205
ZW
2572/* Directives: Instruction set selection. */
2573
2574#ifdef OBJ_ELF
2575/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2576 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2577 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2578 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2579
cd000bff
DJ
2580/* Create a new mapping symbol for the transition to STATE. */
2581
2582static void
2583make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2584{
a737bd4d 2585 symbolS * symbolP;
c19d1205
ZW
2586 const char * symname;
2587 int type;
b99bd4ef 2588
c19d1205 2589 switch (state)
b99bd4ef 2590 {
c19d1205
ZW
2591 case MAP_DATA:
2592 symname = "$d";
2593 type = BSF_NO_FLAGS;
2594 break;
2595 case MAP_ARM:
2596 symname = "$a";
2597 type = BSF_NO_FLAGS;
2598 break;
2599 case MAP_THUMB:
2600 symname = "$t";
2601 type = BSF_NO_FLAGS;
2602 break;
c19d1205
ZW
2603 default:
2604 abort ();
2605 }
2606
cd000bff 2607 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2608 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2609
2610 switch (state)
2611 {
2612 case MAP_ARM:
2613 THUMB_SET_FUNC (symbolP, 0);
2614 ARM_SET_THUMB (symbolP, 0);
2615 ARM_SET_INTERWORK (symbolP, support_interwork);
2616 break;
2617
2618 case MAP_THUMB:
2619 THUMB_SET_FUNC (symbolP, 1);
2620 ARM_SET_THUMB (symbolP, 1);
2621 ARM_SET_INTERWORK (symbolP, support_interwork);
2622 break;
2623
2624 case MAP_DATA:
2625 default:
cd000bff
DJ
2626 break;
2627 }
2628
2629 /* Save the mapping symbols for future reference. Also check that
2630 we do not place two mapping symbols at the same offset within a
2631 frag. We'll handle overlap between frags in
2de7820f
JZ
2632 check_mapping_symbols.
2633
2634 If .fill or other data filling directive generates zero sized data,
2635 the mapping symbol for the following code will have the same value
2636 as the one generated for the data filling directive. In this case,
2637 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2638 if (value == 0)
2639 {
2de7820f
JZ
2640 if (frag->tc_frag_data.first_map != NULL)
2641 {
2642 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2643 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2644 }
cd000bff
DJ
2645 frag->tc_frag_data.first_map = symbolP;
2646 }
2647 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2648 {
2649 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2650 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2651 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2652 }
cd000bff
DJ
2653 frag->tc_frag_data.last_map = symbolP;
2654}
2655
2656/* We must sometimes convert a region marked as code to data during
2657 code alignment, if an odd number of bytes have to be padded. The
2658 code mapping symbol is pushed to an aligned address. */
2659
2660static void
2661insert_data_mapping_symbol (enum mstate state,
2662 valueT value, fragS *frag, offsetT bytes)
2663{
2664 /* If there was already a mapping symbol, remove it. */
2665 if (frag->tc_frag_data.last_map != NULL
2666 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2667 {
2668 symbolS *symp = frag->tc_frag_data.last_map;
2669
2670 if (value == 0)
2671 {
2672 know (frag->tc_frag_data.first_map == symp);
2673 frag->tc_frag_data.first_map = NULL;
2674 }
2675 frag->tc_frag_data.last_map = NULL;
2676 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2677 }
cd000bff
DJ
2678
2679 make_mapping_symbol (MAP_DATA, value, frag);
2680 make_mapping_symbol (state, value + bytes, frag);
2681}
2682
2683static void mapping_state_2 (enum mstate state, int max_chars);
2684
2685/* Set the mapping state to STATE. Only call this when about to
2686 emit some STATE bytes to the file. */
2687
4e9aaefb 2688#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2689void
2690mapping_state (enum mstate state)
2691{
940b5ce0
DJ
2692 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2693
cd000bff
DJ
2694 if (mapstate == state)
2695 /* The mapping symbol has already been emitted.
2696 There is nothing else to do. */
2697 return;
49c62a33
NC
2698
2699 if (state == MAP_ARM || state == MAP_THUMB)
2700 /* PR gas/12931
2701 All ARM instructions require 4-byte alignment.
2702 (Almost) all Thumb instructions require 2-byte alignment.
2703
2704 When emitting instructions into any section, mark the section
2705 appropriately.
2706
2707 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2708 but themselves require 2-byte alignment; this applies to some
2709 PC- relative forms. However, these cases will invovle implicit
2710 literal pool generation or an explicit .align >=2, both of
2711 which will cause the section to me marked with sufficient
2712 alignment. Thus, we don't handle those cases here. */
2713 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2714
2715 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2716 /* This case will be evaluated later. */
cd000bff 2717 return;
cd000bff
DJ
2718
2719 mapping_state_2 (state, 0);
cd000bff
DJ
2720}
2721
2722/* Same as mapping_state, but MAX_CHARS bytes have already been
2723 allocated. Put the mapping symbol that far back. */
2724
2725static void
2726mapping_state_2 (enum mstate state, int max_chars)
2727{
940b5ce0
DJ
2728 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2729
2730 if (!SEG_NORMAL (now_seg))
2731 return;
2732
cd000bff
DJ
2733 if (mapstate == state)
2734 /* The mapping symbol has already been emitted.
2735 There is nothing else to do. */
2736 return;
2737
4e9aaefb
SA
2738 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2739 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2740 {
2741 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2742 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2743
2744 if (add_symbol)
2745 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2746 }
2747
cd000bff
DJ
2748 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2749 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2750}
4e9aaefb 2751#undef TRANSITION
c19d1205 2752#else
d3106081
NS
2753#define mapping_state(x) ((void)0)
2754#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2755#endif
2756
2757/* Find the real, Thumb encoded start of a Thumb function. */
2758
4343666d 2759#ifdef OBJ_COFF
c19d1205
ZW
2760static symbolS *
2761find_real_start (symbolS * symbolP)
2762{
2763 char * real_start;
2764 const char * name = S_GET_NAME (symbolP);
2765 symbolS * new_target;
2766
2767 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2768#define STUB_NAME ".real_start_of"
2769
2770 if (name == NULL)
2771 abort ();
2772
37f6032b
ZW
2773 /* The compiler may generate BL instructions to local labels because
2774 it needs to perform a branch to a far away location. These labels
2775 do not have a corresponding ".real_start_of" label. We check
2776 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2777 the ".real_start_of" convention for nonlocal branches. */
2778 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2779 return symbolP;
2780
e1fa0163 2781 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2782 new_target = symbol_find (real_start);
e1fa0163 2783 free (real_start);
c19d1205
ZW
2784
2785 if (new_target == NULL)
2786 {
bd3ba5d1 2787 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2788 new_target = symbolP;
2789 }
2790
c19d1205
ZW
2791 return new_target;
2792}
4343666d 2793#endif
c19d1205
ZW
2794
2795static void
2796opcode_select (int width)
2797{
2798 switch (width)
2799 {
2800 case 16:
2801 if (! thumb_mode)
2802 {
e74cfd16 2803 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2804 as_bad (_("selected processor does not support THUMB opcodes"));
2805
2806 thumb_mode = 1;
2807 /* No need to force the alignment, since we will have been
2808 coming from ARM mode, which is word-aligned. */
2809 record_alignment (now_seg, 1);
2810 }
c19d1205
ZW
2811 break;
2812
2813 case 32:
2814 if (thumb_mode)
2815 {
e74cfd16 2816 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2817 as_bad (_("selected processor does not support ARM opcodes"));
2818
2819 thumb_mode = 0;
2820
2821 if (!need_pass_2)
2822 frag_align (2, 0, 0);
2823
2824 record_alignment (now_seg, 1);
2825 }
c19d1205
ZW
2826 break;
2827
2828 default:
2829 as_bad (_("invalid instruction size selected (%d)"), width);
2830 }
2831}
2832
2833static void
2834s_arm (int ignore ATTRIBUTE_UNUSED)
2835{
2836 opcode_select (32);
2837 demand_empty_rest_of_line ();
2838}
2839
2840static void
2841s_thumb (int ignore ATTRIBUTE_UNUSED)
2842{
2843 opcode_select (16);
2844 demand_empty_rest_of_line ();
2845}
2846
2847static void
2848s_code (int unused ATTRIBUTE_UNUSED)
2849{
2850 int temp;
2851
2852 temp = get_absolute_expression ();
2853 switch (temp)
2854 {
2855 case 16:
2856 case 32:
2857 opcode_select (temp);
2858 break;
2859
2860 default:
2861 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2862 }
2863}
2864
2865static void
2866s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2867{
2868 /* If we are not already in thumb mode go into it, EVEN if
2869 the target processor does not support thumb instructions.
2870 This is used by gcc/config/arm/lib1funcs.asm for example
2871 to compile interworking support functions even if the
2872 target processor should not support interworking. */
2873 if (! thumb_mode)
2874 {
2875 thumb_mode = 2;
2876 record_alignment (now_seg, 1);
2877 }
2878
2879 demand_empty_rest_of_line ();
2880}
2881
2882static void
2883s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2884{
2885 s_thumb (0);
2886
2887 /* The following label is the name/address of the start of a Thumb function.
2888 We need to know this for the interworking support. */
2889 label_is_thumb_function_name = TRUE;
2890}
2891
2892/* Perform a .set directive, but also mark the alias as
2893 being a thumb function. */
2894
2895static void
2896s_thumb_set (int equiv)
2897{
2898 /* XXX the following is a duplicate of the code for s_set() in read.c
2899 We cannot just call that code as we need to get at the symbol that
2900 is created. */
2901 char * name;
2902 char delim;
2903 char * end_name;
2904 symbolS * symbolP;
2905
2906 /* Especial apologies for the random logic:
2907 This just grew, and could be parsed much more simply!
2908 Dean - in haste. */
d02603dc 2909 delim = get_symbol_name (& name);
c19d1205 2910 end_name = input_line_pointer;
d02603dc 2911 (void) restore_line_pointer (delim);
c19d1205
ZW
2912
2913 if (*input_line_pointer != ',')
2914 {
2915 *end_name = 0;
2916 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2917 *end_name = delim;
2918 ignore_rest_of_line ();
2919 return;
2920 }
2921
2922 input_line_pointer++;
2923 *end_name = 0;
2924
2925 if (name[0] == '.' && name[1] == '\0')
2926 {
2927 /* XXX - this should not happen to .thumb_set. */
2928 abort ();
2929 }
2930
2931 if ((symbolP = symbol_find (name)) == NULL
2932 && (symbolP = md_undefined_symbol (name)) == NULL)
2933 {
2934#ifndef NO_LISTING
2935 /* When doing symbol listings, play games with dummy fragments living
2936 outside the normal fragment chain to record the file and line info
c19d1205 2937 for this symbol. */
b99bd4ef
NC
2938 if (listing & LISTING_SYMBOLS)
2939 {
2940 extern struct list_info_struct * listing_tail;
21d799b5 2941 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2942
2943 memset (dummy_frag, 0, sizeof (fragS));
2944 dummy_frag->fr_type = rs_fill;
2945 dummy_frag->line = listing_tail;
2946 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2947 dummy_frag->fr_symbol = symbolP;
2948 }
2949 else
2950#endif
2951 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2952
2953#ifdef OBJ_COFF
2954 /* "set" symbols are local unless otherwise specified. */
2955 SF_SET_LOCAL (symbolP);
2956#endif /* OBJ_COFF */
2957 } /* Make a new symbol. */
2958
2959 symbol_table_insert (symbolP);
2960
2961 * end_name = delim;
2962
2963 if (equiv
2964 && S_IS_DEFINED (symbolP)
2965 && S_GET_SEGMENT (symbolP) != reg_section)
2966 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2967
2968 pseudo_set (symbolP);
2969
2970 demand_empty_rest_of_line ();
2971
c19d1205 2972 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2973
2974 THUMB_SET_FUNC (symbolP, 1);
2975 ARM_SET_THUMB (symbolP, 1);
2976#if defined OBJ_ELF || defined OBJ_COFF
2977 ARM_SET_INTERWORK (symbolP, support_interwork);
2978#endif
2979}
2980
c19d1205 2981/* Directives: Mode selection. */
b99bd4ef 2982
c19d1205
ZW
2983/* .syntax [unified|divided] - choose the new unified syntax
2984 (same for Arm and Thumb encoding, modulo slight differences in what
2985 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2986static void
c19d1205 2987s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2988{
c19d1205
ZW
2989 char *name, delim;
2990
d02603dc 2991 delim = get_symbol_name (& name);
c19d1205
ZW
2992
2993 if (!strcasecmp (name, "unified"))
2994 unified_syntax = TRUE;
2995 else if (!strcasecmp (name, "divided"))
2996 unified_syntax = FALSE;
2997 else
2998 {
2999 as_bad (_("unrecognized syntax mode \"%s\""), name);
3000 return;
3001 }
d02603dc 3002 (void) restore_line_pointer (delim);
b99bd4ef
NC
3003 demand_empty_rest_of_line ();
3004}
3005
c19d1205
ZW
3006/* Directives: sectioning and alignment. */
3007
c19d1205
ZW
3008static void
3009s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3010{
c19d1205
ZW
3011 /* We don't support putting frags in the BSS segment, we fake it by
3012 marking in_bss, then looking at s_skip for clues. */
3013 subseg_set (bss_section, 0);
3014 demand_empty_rest_of_line ();
cd000bff
DJ
3015
3016#ifdef md_elf_section_change_hook
3017 md_elf_section_change_hook ();
3018#endif
c19d1205 3019}
b99bd4ef 3020
c19d1205
ZW
3021static void
3022s_even (int ignore ATTRIBUTE_UNUSED)
3023{
3024 /* Never make frag if expect extra pass. */
3025 if (!need_pass_2)
3026 frag_align (1, 0, 0);
b99bd4ef 3027
c19d1205 3028 record_alignment (now_seg, 1);
b99bd4ef 3029
c19d1205 3030 demand_empty_rest_of_line ();
b99bd4ef
NC
3031}
3032
2e6976a8
DG
3033/* Directives: CodeComposer Studio. */
3034
3035/* .ref (for CodeComposer Studio syntax only). */
3036static void
3037s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3038{
3039 if (codecomposer_syntax)
3040 ignore_rest_of_line ();
3041 else
3042 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3043}
3044
3045/* If name is not NULL, then it is used for marking the beginning of a
3046 function, wherease if it is NULL then it means the function end. */
3047static void
3048asmfunc_debug (const char * name)
3049{
3050 static const char * last_name = NULL;
3051
3052 if (name != NULL)
3053 {
3054 gas_assert (last_name == NULL);
3055 last_name = name;
3056
3057 if (debug_type == DEBUG_STABS)
3058 stabs_generate_asm_func (name, name);
3059 }
3060 else
3061 {
3062 gas_assert (last_name != NULL);
3063
3064 if (debug_type == DEBUG_STABS)
3065 stabs_generate_asm_endfunc (last_name, last_name);
3066
3067 last_name = NULL;
3068 }
3069}
3070
3071static void
3072s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3073{
3074 if (codecomposer_syntax)
3075 {
3076 switch (asmfunc_state)
3077 {
3078 case OUTSIDE_ASMFUNC:
3079 asmfunc_state = WAITING_ASMFUNC_NAME;
3080 break;
3081
3082 case WAITING_ASMFUNC_NAME:
3083 as_bad (_(".asmfunc repeated."));
3084 break;
3085
3086 case WAITING_ENDASMFUNC:
3087 as_bad (_(".asmfunc without function."));
3088 break;
3089 }
3090 demand_empty_rest_of_line ();
3091 }
3092 else
3093 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3094}
3095
3096static void
3097s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3098{
3099 if (codecomposer_syntax)
3100 {
3101 switch (asmfunc_state)
3102 {
3103 case OUTSIDE_ASMFUNC:
3104 as_bad (_(".endasmfunc without a .asmfunc."));
3105 break;
3106
3107 case WAITING_ASMFUNC_NAME:
3108 as_bad (_(".endasmfunc without function."));
3109 break;
3110
3111 case WAITING_ENDASMFUNC:
3112 asmfunc_state = OUTSIDE_ASMFUNC;
3113 asmfunc_debug (NULL);
3114 break;
3115 }
3116 demand_empty_rest_of_line ();
3117 }
3118 else
3119 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3120}
3121
3122static void
3123s_ccs_def (int name)
3124{
3125 if (codecomposer_syntax)
3126 s_globl (name);
3127 else
3128 as_bad (_(".def pseudo-op only available with -mccs flag."));
3129}
3130
c19d1205 3131/* Directives: Literal pools. */
a737bd4d 3132
c19d1205
ZW
3133static literal_pool *
3134find_literal_pool (void)
a737bd4d 3135{
c19d1205 3136 literal_pool * pool;
a737bd4d 3137
c19d1205 3138 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3139 {
c19d1205
ZW
3140 if (pool->section == now_seg
3141 && pool->sub_section == now_subseg)
3142 break;
a737bd4d
NC
3143 }
3144
c19d1205 3145 return pool;
a737bd4d
NC
3146}
3147
c19d1205
ZW
3148static literal_pool *
3149find_or_make_literal_pool (void)
a737bd4d 3150{
c19d1205
ZW
3151 /* Next literal pool ID number. */
3152 static unsigned int latest_pool_num = 1;
3153 literal_pool * pool;
a737bd4d 3154
c19d1205 3155 pool = find_literal_pool ();
a737bd4d 3156
c19d1205 3157 if (pool == NULL)
a737bd4d 3158 {
c19d1205 3159 /* Create a new pool. */
325801bd 3160 pool = XNEW (literal_pool);
c19d1205
ZW
3161 if (! pool)
3162 return NULL;
a737bd4d 3163
c19d1205
ZW
3164 pool->next_free_entry = 0;
3165 pool->section = now_seg;
3166 pool->sub_section = now_subseg;
3167 pool->next = list_of_pools;
3168 pool->symbol = NULL;
8335d6aa 3169 pool->alignment = 2;
c19d1205
ZW
3170
3171 /* Add it to the list. */
3172 list_of_pools = pool;
a737bd4d 3173 }
a737bd4d 3174
c19d1205
ZW
3175 /* New pools, and emptied pools, will have a NULL symbol. */
3176 if (pool->symbol == NULL)
a737bd4d 3177 {
c19d1205
ZW
3178 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3179 (valueT) 0, &zero_address_frag);
3180 pool->id = latest_pool_num ++;
a737bd4d
NC
3181 }
3182
c19d1205
ZW
3183 /* Done. */
3184 return pool;
a737bd4d
NC
3185}
3186
c19d1205 3187/* Add the literal in the global 'inst'
5f4273c7 3188 structure to the relevant literal pool. */
b99bd4ef
NC
3189
3190static int
8335d6aa 3191add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3192{
8335d6aa
JW
3193#define PADDING_SLOT 0x1
3194#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3195 literal_pool * pool;
8335d6aa
JW
3196 unsigned int entry, pool_size = 0;
3197 bfd_boolean padding_slot_p = FALSE;
e56c722b 3198 unsigned imm1 = 0;
8335d6aa
JW
3199 unsigned imm2 = 0;
3200
3201 if (nbytes == 8)
3202 {
3203 imm1 = inst.operands[1].imm;
3204 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3205 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3206 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3207 if (target_big_endian)
3208 {
3209 imm1 = imm2;
3210 imm2 = inst.operands[1].imm;
3211 }
3212 }
b99bd4ef 3213
c19d1205
ZW
3214 pool = find_or_make_literal_pool ();
3215
3216 /* Check if this literal value is already in the pool. */
3217 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3218 {
8335d6aa
JW
3219 if (nbytes == 4)
3220 {
3221 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3222 && (inst.reloc.exp.X_op == O_constant)
3223 && (pool->literals[entry].X_add_number
3224 == inst.reloc.exp.X_add_number)
3225 && (pool->literals[entry].X_md == nbytes)
3226 && (pool->literals[entry].X_unsigned
3227 == inst.reloc.exp.X_unsigned))
3228 break;
3229
3230 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3231 && (inst.reloc.exp.X_op == O_symbol)
3232 && (pool->literals[entry].X_add_number
3233 == inst.reloc.exp.X_add_number)
3234 && (pool->literals[entry].X_add_symbol
3235 == inst.reloc.exp.X_add_symbol)
3236 && (pool->literals[entry].X_op_symbol
3237 == inst.reloc.exp.X_op_symbol)
3238 && (pool->literals[entry].X_md == nbytes))
3239 break;
3240 }
3241 else if ((nbytes == 8)
3242 && !(pool_size & 0x7)
3243 && ((entry + 1) != pool->next_free_entry)
3244 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3245 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3246 && (pool->literals[entry].X_unsigned
3247 == inst.reloc.exp.X_unsigned)
3248 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3249 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3250 && (pool->literals[entry + 1].X_unsigned
3251 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3252 break;
3253
8335d6aa
JW
3254 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3255 if (padding_slot_p && (nbytes == 4))
c19d1205 3256 break;
8335d6aa
JW
3257
3258 pool_size += 4;
b99bd4ef
NC
3259 }
3260
c19d1205
ZW
3261 /* Do we need to create a new entry? */
3262 if (entry == pool->next_free_entry)
3263 {
3264 if (entry >= MAX_LITERAL_POOL_SIZE)
3265 {
3266 inst.error = _("literal pool overflow");
3267 return FAIL;
3268 }
3269
8335d6aa
JW
3270 if (nbytes == 8)
3271 {
3272 /* For 8-byte entries, we align to an 8-byte boundary,
3273 and split it into two 4-byte entries, because on 32-bit
3274 host, 8-byte constants are treated as big num, thus
3275 saved in "generic_bignum" which will be overwritten
3276 by later assignments.
3277
3278 We also need to make sure there is enough space for
3279 the split.
3280
3281 We also check to make sure the literal operand is a
3282 constant number. */
19f2f6a9
JW
3283 if (!(inst.reloc.exp.X_op == O_constant
3284 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3285 {
3286 inst.error = _("invalid type for literal pool");
3287 return FAIL;
3288 }
3289 else if (pool_size & 0x7)
3290 {
3291 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3292 {
3293 inst.error = _("literal pool overflow");
3294 return FAIL;
3295 }
3296
3297 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3298 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3299 pool->literals[entry].X_add_number = 0;
3300 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3301 pool->next_free_entry += 1;
3302 pool_size += 4;
3303 }
3304 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3305 {
3306 inst.error = _("literal pool overflow");
3307 return FAIL;
3308 }
3309
3310 pool->literals[entry] = inst.reloc.exp;
3311 pool->literals[entry].X_op = O_constant;
3312 pool->literals[entry].X_add_number = imm1;
3313 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3314 pool->literals[entry++].X_md = 4;
3315 pool->literals[entry] = inst.reloc.exp;
3316 pool->literals[entry].X_op = O_constant;
3317 pool->literals[entry].X_add_number = imm2;
3318 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3319 pool->literals[entry].X_md = 4;
3320 pool->alignment = 3;
3321 pool->next_free_entry += 1;
3322 }
3323 else
3324 {
3325 pool->literals[entry] = inst.reloc.exp;
3326 pool->literals[entry].X_md = 4;
3327 }
3328
a8040cf2
NC
3329#ifdef OBJ_ELF
3330 /* PR ld/12974: Record the location of the first source line to reference
3331 this entry in the literal pool. If it turns out during linking that the
3332 symbol does not exist we will be able to give an accurate line number for
3333 the (first use of the) missing reference. */
3334 if (debug_type == DEBUG_DWARF2)
3335 dwarf2_where (pool->locs + entry);
3336#endif
c19d1205
ZW
3337 pool->next_free_entry += 1;
3338 }
8335d6aa
JW
3339 else if (padding_slot_p)
3340 {
3341 pool->literals[entry] = inst.reloc.exp;
3342 pool->literals[entry].X_md = nbytes;
3343 }
b99bd4ef 3344
c19d1205 3345 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3346 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3347 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3348
c19d1205 3349 return SUCCESS;
b99bd4ef
NC
3350}
3351
2e6976a8 3352bfd_boolean
2e57ce7b 3353tc_start_label_without_colon (void)
2e6976a8
DG
3354{
3355 bfd_boolean ret = TRUE;
3356
3357 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3358 {
2e57ce7b 3359 const char *label = input_line_pointer;
2e6976a8
DG
3360
3361 while (!is_end_of_line[(int) label[-1]])
3362 --label;
3363
3364 if (*label == '.')
3365 {
3366 as_bad (_("Invalid label '%s'"), label);
3367 ret = FALSE;
3368 }
3369
3370 asmfunc_debug (label);
3371
3372 asmfunc_state = WAITING_ENDASMFUNC;
3373 }
3374
3375 return ret;
3376}
3377
c19d1205
ZW
3378/* Can't use symbol_new here, so have to create a symbol and then at
3379 a later date assign it a value. Thats what these functions do. */
e16bb312 3380
c19d1205
ZW
3381static void
3382symbol_locate (symbolS * symbolP,
3383 const char * name, /* It is copied, the caller can modify. */
3384 segT segment, /* Segment identifier (SEG_<something>). */
3385 valueT valu, /* Symbol value. */
3386 fragS * frag) /* Associated fragment. */
3387{
e57e6ddc 3388 size_t name_length;
c19d1205 3389 char * preserved_copy_of_name;
e16bb312 3390
c19d1205
ZW
3391 name_length = strlen (name) + 1; /* +1 for \0. */
3392 obstack_grow (&notes, name, name_length);
21d799b5 3393 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3394
c19d1205
ZW
3395#ifdef tc_canonicalize_symbol_name
3396 preserved_copy_of_name =
3397 tc_canonicalize_symbol_name (preserved_copy_of_name);
3398#endif
b99bd4ef 3399
c19d1205 3400 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3401
c19d1205
ZW
3402 S_SET_SEGMENT (symbolP, segment);
3403 S_SET_VALUE (symbolP, valu);
3404 symbol_clear_list_pointers (symbolP);
b99bd4ef 3405
c19d1205 3406 symbol_set_frag (symbolP, frag);
b99bd4ef 3407
c19d1205
ZW
3408 /* Link to end of symbol chain. */
3409 {
3410 extern int symbol_table_frozen;
b99bd4ef 3411
c19d1205
ZW
3412 if (symbol_table_frozen)
3413 abort ();
3414 }
b99bd4ef 3415
c19d1205 3416 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3417
c19d1205 3418 obj_symbol_new_hook (symbolP);
b99bd4ef 3419
c19d1205
ZW
3420#ifdef tc_symbol_new_hook
3421 tc_symbol_new_hook (symbolP);
3422#endif
3423
3424#ifdef DEBUG_SYMS
3425 verify_symbol_chain (symbol_rootP, symbol_lastP);
3426#endif /* DEBUG_SYMS */
b99bd4ef
NC
3427}
3428
c19d1205
ZW
3429static void
3430s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3431{
c19d1205
ZW
3432 unsigned int entry;
3433 literal_pool * pool;
3434 char sym_name[20];
b99bd4ef 3435
c19d1205
ZW
3436 pool = find_literal_pool ();
3437 if (pool == NULL
3438 || pool->symbol == NULL
3439 || pool->next_free_entry == 0)
3440 return;
b99bd4ef 3441
c19d1205
ZW
3442 /* Align pool as you have word accesses.
3443 Only make a frag if we have to. */
3444 if (!need_pass_2)
8335d6aa 3445 frag_align (pool->alignment, 0, 0);
b99bd4ef 3446
c19d1205 3447 record_alignment (now_seg, 2);
b99bd4ef 3448
aaca88ef 3449#ifdef OBJ_ELF
47fc6e36
WN
3450 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3451 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3452#endif
c19d1205 3453 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3454
c19d1205
ZW
3455 symbol_locate (pool->symbol, sym_name, now_seg,
3456 (valueT) frag_now_fix (), frag_now);
3457 symbol_table_insert (pool->symbol);
b99bd4ef 3458
c19d1205 3459 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3460
c19d1205
ZW
3461#if defined OBJ_COFF || defined OBJ_ELF
3462 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3463#endif
6c43fab6 3464
c19d1205 3465 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3466 {
3467#ifdef OBJ_ELF
3468 if (debug_type == DEBUG_DWARF2)
3469 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3470#endif
3471 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3472 emit_expr (&(pool->literals[entry]),
3473 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3474 }
b99bd4ef 3475
c19d1205
ZW
3476 /* Mark the pool as empty. */
3477 pool->next_free_entry = 0;
3478 pool->symbol = NULL;
b99bd4ef
NC
3479}
3480
c19d1205
ZW
3481#ifdef OBJ_ELF
3482/* Forward declarations for functions below, in the MD interface
3483 section. */
3484static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3485static valueT create_unwind_entry (int);
3486static void start_unwind_section (const segT, int);
3487static void add_unwind_opcode (valueT, int);
3488static void flush_pending_unwind (void);
b99bd4ef 3489
c19d1205 3490/* Directives: Data. */
b99bd4ef 3491
c19d1205
ZW
3492static void
3493s_arm_elf_cons (int nbytes)
3494{
3495 expressionS exp;
b99bd4ef 3496
c19d1205
ZW
3497#ifdef md_flush_pending_output
3498 md_flush_pending_output ();
3499#endif
b99bd4ef 3500
c19d1205 3501 if (is_it_end_of_statement ())
b99bd4ef 3502 {
c19d1205
ZW
3503 demand_empty_rest_of_line ();
3504 return;
b99bd4ef
NC
3505 }
3506
c19d1205
ZW
3507#ifdef md_cons_align
3508 md_cons_align (nbytes);
3509#endif
b99bd4ef 3510
c19d1205
ZW
3511 mapping_state (MAP_DATA);
3512 do
b99bd4ef 3513 {
c19d1205
ZW
3514 int reloc;
3515 char *base = input_line_pointer;
b99bd4ef 3516
c19d1205 3517 expression (& exp);
b99bd4ef 3518
c19d1205
ZW
3519 if (exp.X_op != O_symbol)
3520 emit_expr (&exp, (unsigned int) nbytes);
3521 else
3522 {
3523 char *before_reloc = input_line_pointer;
3524 reloc = parse_reloc (&input_line_pointer);
3525 if (reloc == -1)
3526 {
3527 as_bad (_("unrecognized relocation suffix"));
3528 ignore_rest_of_line ();
3529 return;
3530 }
3531 else if (reloc == BFD_RELOC_UNUSED)
3532 emit_expr (&exp, (unsigned int) nbytes);
3533 else
3534 {
21d799b5 3535 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3536 bfd_reloc_type_lookup (stdoutput,
3537 (bfd_reloc_code_real_type) reloc);
c19d1205 3538 int size = bfd_get_reloc_size (howto);
b99bd4ef 3539
2fc8bdac
ZW
3540 if (reloc == BFD_RELOC_ARM_PLT32)
3541 {
3542 as_bad (_("(plt) is only valid on branch targets"));
3543 reloc = BFD_RELOC_UNUSED;
3544 size = 0;
3545 }
3546
c19d1205 3547 if (size > nbytes)
2fc8bdac 3548 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3549 howto->name, nbytes);
3550 else
3551 {
3552 /* We've parsed an expression stopping at O_symbol.
3553 But there may be more expression left now that we
3554 have parsed the relocation marker. Parse it again.
3555 XXX Surely there is a cleaner way to do this. */
3556 char *p = input_line_pointer;
3557 int offset;
325801bd 3558 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3559
c19d1205
ZW
3560 memcpy (save_buf, base, input_line_pointer - base);
3561 memmove (base + (input_line_pointer - before_reloc),
3562 base, before_reloc - base);
3563
3564 input_line_pointer = base + (input_line_pointer-before_reloc);
3565 expression (&exp);
3566 memcpy (base, save_buf, p - base);
3567
3568 offset = nbytes - size;
4b1a927e
AM
3569 p = frag_more (nbytes);
3570 memset (p, 0, nbytes);
c19d1205 3571 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3572 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3573 free (save_buf);
c19d1205
ZW
3574 }
3575 }
3576 }
b99bd4ef 3577 }
c19d1205 3578 while (*input_line_pointer++ == ',');
b99bd4ef 3579
c19d1205
ZW
3580 /* Put terminator back into stream. */
3581 input_line_pointer --;
3582 demand_empty_rest_of_line ();
b99bd4ef
NC
3583}
3584
c921be7d
NC
3585/* Emit an expression containing a 32-bit thumb instruction.
3586 Implementation based on put_thumb32_insn. */
3587
3588static void
3589emit_thumb32_expr (expressionS * exp)
3590{
3591 expressionS exp_high = *exp;
3592
3593 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3594 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3595 exp->X_add_number &= 0xffff;
3596 emit_expr (exp, (unsigned int) THUMB_SIZE);
3597}
3598
3599/* Guess the instruction size based on the opcode. */
3600
3601static int
3602thumb_insn_size (int opcode)
3603{
3604 if ((unsigned int) opcode < 0xe800u)
3605 return 2;
3606 else if ((unsigned int) opcode >= 0xe8000000u)
3607 return 4;
3608 else
3609 return 0;
3610}
3611
3612static bfd_boolean
3613emit_insn (expressionS *exp, int nbytes)
3614{
3615 int size = 0;
3616
3617 if (exp->X_op == O_constant)
3618 {
3619 size = nbytes;
3620
3621 if (size == 0)
3622 size = thumb_insn_size (exp->X_add_number);
3623
3624 if (size != 0)
3625 {
3626 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3627 {
3628 as_bad (_(".inst.n operand too big. "\
3629 "Use .inst.w instead"));
3630 size = 0;
3631 }
3632 else
3633 {
3634 if (now_it.state == AUTOMATIC_IT_BLOCK)
3635 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3636 else
3637 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3638
3639 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3640 emit_thumb32_expr (exp);
3641 else
3642 emit_expr (exp, (unsigned int) size);
3643
3644 it_fsm_post_encode ();
3645 }
3646 }
3647 else
3648 as_bad (_("cannot determine Thumb instruction size. " \
3649 "Use .inst.n/.inst.w instead"));
3650 }
3651 else
3652 as_bad (_("constant expression required"));
3653
3654 return (size != 0);
3655}
3656
3657/* Like s_arm_elf_cons but do not use md_cons_align and
3658 set the mapping state to MAP_ARM/MAP_THUMB. */
3659
3660static void
3661s_arm_elf_inst (int nbytes)
3662{
3663 if (is_it_end_of_statement ())
3664 {
3665 demand_empty_rest_of_line ();
3666 return;
3667 }
3668
3669 /* Calling mapping_state () here will not change ARM/THUMB,
3670 but will ensure not to be in DATA state. */
3671
3672 if (thumb_mode)
3673 mapping_state (MAP_THUMB);
3674 else
3675 {
3676 if (nbytes != 0)
3677 {
3678 as_bad (_("width suffixes are invalid in ARM mode"));
3679 ignore_rest_of_line ();
3680 return;
3681 }
3682
3683 nbytes = 4;
3684
3685 mapping_state (MAP_ARM);
3686 }
3687
3688 do
3689 {
3690 expressionS exp;
3691
3692 expression (& exp);
3693
3694 if (! emit_insn (& exp, nbytes))
3695 {
3696 ignore_rest_of_line ();
3697 return;
3698 }
3699 }
3700 while (*input_line_pointer++ == ',');
3701
3702 /* Put terminator back into stream. */
3703 input_line_pointer --;
3704 demand_empty_rest_of_line ();
3705}
b99bd4ef 3706
c19d1205 3707/* Parse a .rel31 directive. */
b99bd4ef 3708
c19d1205
ZW
3709static void
3710s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3711{
3712 expressionS exp;
3713 char *p;
3714 valueT highbit;
b99bd4ef 3715
c19d1205
ZW
3716 highbit = 0;
3717 if (*input_line_pointer == '1')
3718 highbit = 0x80000000;
3719 else if (*input_line_pointer != '0')
3720 as_bad (_("expected 0 or 1"));
b99bd4ef 3721
c19d1205
ZW
3722 input_line_pointer++;
3723 if (*input_line_pointer != ',')
3724 as_bad (_("missing comma"));
3725 input_line_pointer++;
b99bd4ef 3726
c19d1205
ZW
3727#ifdef md_flush_pending_output
3728 md_flush_pending_output ();
3729#endif
b99bd4ef 3730
c19d1205
ZW
3731#ifdef md_cons_align
3732 md_cons_align (4);
3733#endif
b99bd4ef 3734
c19d1205 3735 mapping_state (MAP_DATA);
b99bd4ef 3736
c19d1205 3737 expression (&exp);
b99bd4ef 3738
c19d1205
ZW
3739 p = frag_more (4);
3740 md_number_to_chars (p, highbit, 4);
3741 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3742 BFD_RELOC_ARM_PREL31);
b99bd4ef 3743
c19d1205 3744 demand_empty_rest_of_line ();
b99bd4ef
NC
3745}
3746
c19d1205 3747/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3748
c19d1205 3749/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3750
c19d1205
ZW
3751static void
3752s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3753{
3754 demand_empty_rest_of_line ();
921e5f0a
PB
3755 if (unwind.proc_start)
3756 {
c921be7d 3757 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3758 return;
3759 }
3760
c19d1205
ZW
3761 /* Mark the start of the function. */
3762 unwind.proc_start = expr_build_dot ();
b99bd4ef 3763
c19d1205
ZW
3764 /* Reset the rest of the unwind info. */
3765 unwind.opcode_count = 0;
3766 unwind.table_entry = NULL;
3767 unwind.personality_routine = NULL;
3768 unwind.personality_index = -1;
3769 unwind.frame_size = 0;
3770 unwind.fp_offset = 0;
fdfde340 3771 unwind.fp_reg = REG_SP;
c19d1205
ZW
3772 unwind.fp_used = 0;
3773 unwind.sp_restored = 0;
3774}
b99bd4ef 3775
b99bd4ef 3776
c19d1205
ZW
3777/* Parse a handlerdata directive. Creates the exception handling table entry
3778 for the function. */
b99bd4ef 3779
c19d1205
ZW
3780static void
3781s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3782{
3783 demand_empty_rest_of_line ();
921e5f0a 3784 if (!unwind.proc_start)
c921be7d 3785 as_bad (MISSING_FNSTART);
921e5f0a 3786
c19d1205 3787 if (unwind.table_entry)
6decc662 3788 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3789
c19d1205
ZW
3790 create_unwind_entry (1);
3791}
a737bd4d 3792
c19d1205 3793/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3794
c19d1205
ZW
3795static void
3796s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3797{
3798 long where;
3799 char *ptr;
3800 valueT val;
940b5ce0 3801 unsigned int marked_pr_dependency;
f02232aa 3802
c19d1205 3803 demand_empty_rest_of_line ();
f02232aa 3804
921e5f0a
PB
3805 if (!unwind.proc_start)
3806 {
c921be7d 3807 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3808 return;
3809 }
3810
c19d1205
ZW
3811 /* Add eh table entry. */
3812 if (unwind.table_entry == NULL)
3813 val = create_unwind_entry (0);
3814 else
3815 val = 0;
f02232aa 3816
c19d1205
ZW
3817 /* Add index table entry. This is two words. */
3818 start_unwind_section (unwind.saved_seg, 1);
3819 frag_align (2, 0, 0);
3820 record_alignment (now_seg, 2);
b99bd4ef 3821
c19d1205 3822 ptr = frag_more (8);
5011093d 3823 memset (ptr, 0, 8);
c19d1205 3824 where = frag_now_fix () - 8;
f02232aa 3825
c19d1205
ZW
3826 /* Self relative offset of the function start. */
3827 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3828 BFD_RELOC_ARM_PREL31);
f02232aa 3829
c19d1205
ZW
3830 /* Indicate dependency on EHABI-defined personality routines to the
3831 linker, if it hasn't been done already. */
940b5ce0
DJ
3832 marked_pr_dependency
3833 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3834 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3835 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3836 {
5f4273c7
NC
3837 static const char *const name[] =
3838 {
3839 "__aeabi_unwind_cpp_pr0",
3840 "__aeabi_unwind_cpp_pr1",
3841 "__aeabi_unwind_cpp_pr2"
3842 };
c19d1205
ZW
3843 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3844 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3845 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3846 |= 1 << unwind.personality_index;
c19d1205 3847 }
f02232aa 3848
c19d1205
ZW
3849 if (val)
3850 /* Inline exception table entry. */
3851 md_number_to_chars (ptr + 4, val, 4);
3852 else
3853 /* Self relative offset of the table entry. */
3854 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3855 BFD_RELOC_ARM_PREL31);
f02232aa 3856
c19d1205
ZW
3857 /* Restore the original section. */
3858 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3859
3860 unwind.proc_start = NULL;
c19d1205 3861}
f02232aa 3862
f02232aa 3863
c19d1205 3864/* Parse an unwind_cantunwind directive. */
b99bd4ef 3865
c19d1205
ZW
3866static void
3867s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3868{
3869 demand_empty_rest_of_line ();
921e5f0a 3870 if (!unwind.proc_start)
c921be7d 3871 as_bad (MISSING_FNSTART);
921e5f0a 3872
c19d1205
ZW
3873 if (unwind.personality_routine || unwind.personality_index != -1)
3874 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3875
c19d1205
ZW
3876 unwind.personality_index = -2;
3877}
b99bd4ef 3878
b99bd4ef 3879
c19d1205 3880/* Parse a personalityindex directive. */
b99bd4ef 3881
c19d1205
ZW
3882static void
3883s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3884{
3885 expressionS exp;
b99bd4ef 3886
921e5f0a 3887 if (!unwind.proc_start)
c921be7d 3888 as_bad (MISSING_FNSTART);
921e5f0a 3889
c19d1205
ZW
3890 if (unwind.personality_routine || unwind.personality_index != -1)
3891 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3892
c19d1205 3893 expression (&exp);
b99bd4ef 3894
c19d1205
ZW
3895 if (exp.X_op != O_constant
3896 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3897 {
c19d1205
ZW
3898 as_bad (_("bad personality routine number"));
3899 ignore_rest_of_line ();
3900 return;
b99bd4ef
NC
3901 }
3902
c19d1205 3903 unwind.personality_index = exp.X_add_number;
b99bd4ef 3904
c19d1205
ZW
3905 demand_empty_rest_of_line ();
3906}
e16bb312 3907
e16bb312 3908
c19d1205 3909/* Parse a personality directive. */
e16bb312 3910
c19d1205
ZW
3911static void
3912s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3913{
3914 char *name, *p, c;
a737bd4d 3915
921e5f0a 3916 if (!unwind.proc_start)
c921be7d 3917 as_bad (MISSING_FNSTART);
921e5f0a 3918
c19d1205
ZW
3919 if (unwind.personality_routine || unwind.personality_index != -1)
3920 as_bad (_("duplicate .personality directive"));
a737bd4d 3921
d02603dc 3922 c = get_symbol_name (& name);
c19d1205 3923 p = input_line_pointer;
d02603dc
NC
3924 if (c == '"')
3925 ++ input_line_pointer;
c19d1205
ZW
3926 unwind.personality_routine = symbol_find_or_make (name);
3927 *p = c;
3928 demand_empty_rest_of_line ();
3929}
e16bb312 3930
e16bb312 3931
c19d1205 3932/* Parse a directive saving core registers. */
e16bb312 3933
c19d1205
ZW
3934static void
3935s_arm_unwind_save_core (void)
e16bb312 3936{
c19d1205
ZW
3937 valueT op;
3938 long range;
3939 int n;
e16bb312 3940
c19d1205
ZW
3941 range = parse_reg_list (&input_line_pointer);
3942 if (range == FAIL)
e16bb312 3943 {
c19d1205
ZW
3944 as_bad (_("expected register list"));
3945 ignore_rest_of_line ();
3946 return;
3947 }
e16bb312 3948
c19d1205 3949 demand_empty_rest_of_line ();
e16bb312 3950
c19d1205
ZW
3951 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3952 into .unwind_save {..., sp...}. We aren't bothered about the value of
3953 ip because it is clobbered by calls. */
3954 if (unwind.sp_restored && unwind.fp_reg == 12
3955 && (range & 0x3000) == 0x1000)
3956 {
3957 unwind.opcode_count--;
3958 unwind.sp_restored = 0;
3959 range = (range | 0x2000) & ~0x1000;
3960 unwind.pending_offset = 0;
3961 }
e16bb312 3962
01ae4198
DJ
3963 /* Pop r4-r15. */
3964 if (range & 0xfff0)
c19d1205 3965 {
01ae4198
DJ
3966 /* See if we can use the short opcodes. These pop a block of up to 8
3967 registers starting with r4, plus maybe r14. */
3968 for (n = 0; n < 8; n++)
3969 {
3970 /* Break at the first non-saved register. */
3971 if ((range & (1 << (n + 4))) == 0)
3972 break;
3973 }
3974 /* See if there are any other bits set. */
3975 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3976 {
3977 /* Use the long form. */
3978 op = 0x8000 | ((range >> 4) & 0xfff);
3979 add_unwind_opcode (op, 2);
3980 }
0dd132b6 3981 else
01ae4198
DJ
3982 {
3983 /* Use the short form. */
3984 if (range & 0x4000)
3985 op = 0xa8; /* Pop r14. */
3986 else
3987 op = 0xa0; /* Do not pop r14. */
3988 op |= (n - 1);
3989 add_unwind_opcode (op, 1);
3990 }
c19d1205 3991 }
0dd132b6 3992
c19d1205
ZW
3993 /* Pop r0-r3. */
3994 if (range & 0xf)
3995 {
3996 op = 0xb100 | (range & 0xf);
3997 add_unwind_opcode (op, 2);
0dd132b6
NC
3998 }
3999
c19d1205
ZW
4000 /* Record the number of bytes pushed. */
4001 for (n = 0; n < 16; n++)
4002 {
4003 if (range & (1 << n))
4004 unwind.frame_size += 4;
4005 }
0dd132b6
NC
4006}
4007
c19d1205
ZW
4008
4009/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4010
4011static void
c19d1205 4012s_arm_unwind_save_fpa (int reg)
b99bd4ef 4013{
c19d1205
ZW
4014 expressionS exp;
4015 int num_regs;
4016 valueT op;
b99bd4ef 4017
c19d1205
ZW
4018 /* Get Number of registers to transfer. */
4019 if (skip_past_comma (&input_line_pointer) != FAIL)
4020 expression (&exp);
4021 else
4022 exp.X_op = O_illegal;
b99bd4ef 4023
c19d1205 4024 if (exp.X_op != O_constant)
b99bd4ef 4025 {
c19d1205
ZW
4026 as_bad (_("expected , <constant>"));
4027 ignore_rest_of_line ();
b99bd4ef
NC
4028 return;
4029 }
4030
c19d1205
ZW
4031 num_regs = exp.X_add_number;
4032
4033 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4034 {
c19d1205
ZW
4035 as_bad (_("number of registers must be in the range [1:4]"));
4036 ignore_rest_of_line ();
b99bd4ef
NC
4037 return;
4038 }
4039
c19d1205 4040 demand_empty_rest_of_line ();
b99bd4ef 4041
c19d1205
ZW
4042 if (reg == 4)
4043 {
4044 /* Short form. */
4045 op = 0xb4 | (num_regs - 1);
4046 add_unwind_opcode (op, 1);
4047 }
b99bd4ef
NC
4048 else
4049 {
c19d1205
ZW
4050 /* Long form. */
4051 op = 0xc800 | (reg << 4) | (num_regs - 1);
4052 add_unwind_opcode (op, 2);
b99bd4ef 4053 }
c19d1205 4054 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4055}
4056
c19d1205 4057
fa073d69
MS
4058/* Parse a directive saving VFP registers for ARMv6 and above. */
4059
4060static void
4061s_arm_unwind_save_vfp_armv6 (void)
4062{
4063 int count;
4064 unsigned int start;
4065 valueT op;
4066 int num_vfpv3_regs = 0;
4067 int num_regs_below_16;
4068
4069 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4070 if (count == FAIL)
4071 {
4072 as_bad (_("expected register list"));
4073 ignore_rest_of_line ();
4074 return;
4075 }
4076
4077 demand_empty_rest_of_line ();
4078
4079 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4080 than FSTMX/FLDMX-style ones). */
4081
4082 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4083 if (start >= 16)
4084 num_vfpv3_regs = count;
4085 else if (start + count > 16)
4086 num_vfpv3_regs = start + count - 16;
4087
4088 if (num_vfpv3_regs > 0)
4089 {
4090 int start_offset = start > 16 ? start - 16 : 0;
4091 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4092 add_unwind_opcode (op, 2);
4093 }
4094
4095 /* Generate opcode for registers numbered in the range 0 .. 15. */
4096 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4097 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4098 if (num_regs_below_16 > 0)
4099 {
4100 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4101 add_unwind_opcode (op, 2);
4102 }
4103
4104 unwind.frame_size += count * 8;
4105}
4106
4107
4108/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4109
4110static void
c19d1205 4111s_arm_unwind_save_vfp (void)
b99bd4ef 4112{
c19d1205 4113 int count;
ca3f61f7 4114 unsigned int reg;
c19d1205 4115 valueT op;
b99bd4ef 4116
5287ad62 4117 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4118 if (count == FAIL)
b99bd4ef 4119 {
c19d1205
ZW
4120 as_bad (_("expected register list"));
4121 ignore_rest_of_line ();
b99bd4ef
NC
4122 return;
4123 }
4124
c19d1205 4125 demand_empty_rest_of_line ();
b99bd4ef 4126
c19d1205 4127 if (reg == 8)
b99bd4ef 4128 {
c19d1205
ZW
4129 /* Short form. */
4130 op = 0xb8 | (count - 1);
4131 add_unwind_opcode (op, 1);
b99bd4ef 4132 }
c19d1205 4133 else
b99bd4ef 4134 {
c19d1205
ZW
4135 /* Long form. */
4136 op = 0xb300 | (reg << 4) | (count - 1);
4137 add_unwind_opcode (op, 2);
b99bd4ef 4138 }
c19d1205
ZW
4139 unwind.frame_size += count * 8 + 4;
4140}
b99bd4ef 4141
b99bd4ef 4142
c19d1205
ZW
4143/* Parse a directive saving iWMMXt data registers. */
4144
4145static void
4146s_arm_unwind_save_mmxwr (void)
4147{
4148 int reg;
4149 int hi_reg;
4150 int i;
4151 unsigned mask = 0;
4152 valueT op;
b99bd4ef 4153
c19d1205
ZW
4154 if (*input_line_pointer == '{')
4155 input_line_pointer++;
b99bd4ef 4156
c19d1205 4157 do
b99bd4ef 4158 {
dcbf9037 4159 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4160
c19d1205 4161 if (reg == FAIL)
b99bd4ef 4162 {
9b7132d3 4163 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4164 goto error;
b99bd4ef
NC
4165 }
4166
c19d1205
ZW
4167 if (mask >> reg)
4168 as_tsktsk (_("register list not in ascending order"));
4169 mask |= 1 << reg;
b99bd4ef 4170
c19d1205
ZW
4171 if (*input_line_pointer == '-')
4172 {
4173 input_line_pointer++;
dcbf9037 4174 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4175 if (hi_reg == FAIL)
4176 {
9b7132d3 4177 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4178 goto error;
4179 }
4180 else if (reg >= hi_reg)
4181 {
4182 as_bad (_("bad register range"));
4183 goto error;
4184 }
4185 for (; reg < hi_reg; reg++)
4186 mask |= 1 << reg;
4187 }
4188 }
4189 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4190
d996d970 4191 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4192
c19d1205 4193 demand_empty_rest_of_line ();
b99bd4ef 4194
708587a4 4195 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4196 the list. */
4197 flush_pending_unwind ();
b99bd4ef 4198
c19d1205 4199 for (i = 0; i < 16; i++)
b99bd4ef 4200 {
c19d1205
ZW
4201 if (mask & (1 << i))
4202 unwind.frame_size += 8;
b99bd4ef
NC
4203 }
4204
c19d1205
ZW
4205 /* Attempt to combine with a previous opcode. We do this because gcc
4206 likes to output separate unwind directives for a single block of
4207 registers. */
4208 if (unwind.opcode_count > 0)
b99bd4ef 4209 {
c19d1205
ZW
4210 i = unwind.opcodes[unwind.opcode_count - 1];
4211 if ((i & 0xf8) == 0xc0)
4212 {
4213 i &= 7;
4214 /* Only merge if the blocks are contiguous. */
4215 if (i < 6)
4216 {
4217 if ((mask & 0xfe00) == (1 << 9))
4218 {
4219 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4220 unwind.opcode_count--;
4221 }
4222 }
4223 else if (i == 6 && unwind.opcode_count >= 2)
4224 {
4225 i = unwind.opcodes[unwind.opcode_count - 2];
4226 reg = i >> 4;
4227 i &= 0xf;
b99bd4ef 4228
c19d1205
ZW
4229 op = 0xffff << (reg - 1);
4230 if (reg > 0
87a1fd79 4231 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4232 {
4233 op = (1 << (reg + i + 1)) - 1;
4234 op &= ~((1 << reg) - 1);
4235 mask |= op;
4236 unwind.opcode_count -= 2;
4237 }
4238 }
4239 }
b99bd4ef
NC
4240 }
4241
c19d1205
ZW
4242 hi_reg = 15;
4243 /* We want to generate opcodes in the order the registers have been
4244 saved, ie. descending order. */
4245 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4246 {
c19d1205
ZW
4247 /* Save registers in blocks. */
4248 if (reg < 0
4249 || !(mask & (1 << reg)))
4250 {
4251 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4252 preceding block. */
c19d1205
ZW
4253 if (reg != hi_reg)
4254 {
4255 if (reg == 9)
4256 {
4257 /* Short form. */
4258 op = 0xc0 | (hi_reg - 10);
4259 add_unwind_opcode (op, 1);
4260 }
4261 else
4262 {
4263 /* Long form. */
4264 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4265 add_unwind_opcode (op, 2);
4266 }
4267 }
4268 hi_reg = reg - 1;
4269 }
b99bd4ef
NC
4270 }
4271
c19d1205
ZW
4272 return;
4273error:
4274 ignore_rest_of_line ();
b99bd4ef
NC
4275}
4276
4277static void
c19d1205 4278s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4279{
c19d1205
ZW
4280 int reg;
4281 int hi_reg;
4282 unsigned mask = 0;
4283 valueT op;
b99bd4ef 4284
c19d1205
ZW
4285 if (*input_line_pointer == '{')
4286 input_line_pointer++;
b99bd4ef 4287
477330fc
RM
4288 skip_whitespace (input_line_pointer);
4289
c19d1205 4290 do
b99bd4ef 4291 {
dcbf9037 4292 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4293
c19d1205
ZW
4294 if (reg == FAIL)
4295 {
9b7132d3 4296 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4297 goto error;
4298 }
b99bd4ef 4299
c19d1205
ZW
4300 reg -= 8;
4301 if (mask >> reg)
4302 as_tsktsk (_("register list not in ascending order"));
4303 mask |= 1 << reg;
b99bd4ef 4304
c19d1205
ZW
4305 if (*input_line_pointer == '-')
4306 {
4307 input_line_pointer++;
dcbf9037 4308 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4309 if (hi_reg == FAIL)
4310 {
9b7132d3 4311 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4312 goto error;
4313 }
4314 else if (reg >= hi_reg)
4315 {
4316 as_bad (_("bad register range"));
4317 goto error;
4318 }
4319 for (; reg < hi_reg; reg++)
4320 mask |= 1 << reg;
4321 }
b99bd4ef 4322 }
c19d1205 4323 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4324
d996d970 4325 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4326
c19d1205
ZW
4327 demand_empty_rest_of_line ();
4328
708587a4 4329 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4330 the list. */
4331 flush_pending_unwind ();
b99bd4ef 4332
c19d1205 4333 for (reg = 0; reg < 16; reg++)
b99bd4ef 4334 {
c19d1205
ZW
4335 if (mask & (1 << reg))
4336 unwind.frame_size += 4;
b99bd4ef 4337 }
c19d1205
ZW
4338 op = 0xc700 | mask;
4339 add_unwind_opcode (op, 2);
4340 return;
4341error:
4342 ignore_rest_of_line ();
b99bd4ef
NC
4343}
4344
c19d1205 4345
fa073d69
MS
4346/* Parse an unwind_save directive.
4347 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4348
b99bd4ef 4349static void
fa073d69 4350s_arm_unwind_save (int arch_v6)
b99bd4ef 4351{
c19d1205
ZW
4352 char *peek;
4353 struct reg_entry *reg;
4354 bfd_boolean had_brace = FALSE;
b99bd4ef 4355
921e5f0a 4356 if (!unwind.proc_start)
c921be7d 4357 as_bad (MISSING_FNSTART);
921e5f0a 4358
c19d1205
ZW
4359 /* Figure out what sort of save we have. */
4360 peek = input_line_pointer;
b99bd4ef 4361
c19d1205 4362 if (*peek == '{')
b99bd4ef 4363 {
c19d1205
ZW
4364 had_brace = TRUE;
4365 peek++;
b99bd4ef
NC
4366 }
4367
c19d1205 4368 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4369
c19d1205 4370 if (!reg)
b99bd4ef 4371 {
c19d1205
ZW
4372 as_bad (_("register expected"));
4373 ignore_rest_of_line ();
b99bd4ef
NC
4374 return;
4375 }
4376
c19d1205 4377 switch (reg->type)
b99bd4ef 4378 {
c19d1205
ZW
4379 case REG_TYPE_FN:
4380 if (had_brace)
4381 {
4382 as_bad (_("FPA .unwind_save does not take a register list"));
4383 ignore_rest_of_line ();
4384 return;
4385 }
93ac2687 4386 input_line_pointer = peek;
c19d1205 4387 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4388 return;
c19d1205 4389
1f5afe1c
NC
4390 case REG_TYPE_RN:
4391 s_arm_unwind_save_core ();
4392 return;
4393
fa073d69
MS
4394 case REG_TYPE_VFD:
4395 if (arch_v6)
477330fc 4396 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4397 else
477330fc 4398 s_arm_unwind_save_vfp ();
fa073d69 4399 return;
1f5afe1c
NC
4400
4401 case REG_TYPE_MMXWR:
4402 s_arm_unwind_save_mmxwr ();
4403 return;
4404
4405 case REG_TYPE_MMXWCG:
4406 s_arm_unwind_save_mmxwcg ();
4407 return;
c19d1205
ZW
4408
4409 default:
4410 as_bad (_(".unwind_save does not support this kind of register"));
4411 ignore_rest_of_line ();
b99bd4ef 4412 }
c19d1205 4413}
b99bd4ef 4414
b99bd4ef 4415
c19d1205
ZW
4416/* Parse an unwind_movsp directive. */
4417
4418static void
4419s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4420{
4421 int reg;
4422 valueT op;
4fa3602b 4423 int offset;
c19d1205 4424
921e5f0a 4425 if (!unwind.proc_start)
c921be7d 4426 as_bad (MISSING_FNSTART);
921e5f0a 4427
dcbf9037 4428 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4429 if (reg == FAIL)
b99bd4ef 4430 {
9b7132d3 4431 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4432 ignore_rest_of_line ();
b99bd4ef
NC
4433 return;
4434 }
4fa3602b
PB
4435
4436 /* Optional constant. */
4437 if (skip_past_comma (&input_line_pointer) != FAIL)
4438 {
4439 if (immediate_for_directive (&offset) == FAIL)
4440 return;
4441 }
4442 else
4443 offset = 0;
4444
c19d1205 4445 demand_empty_rest_of_line ();
b99bd4ef 4446
c19d1205 4447 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4448 {
c19d1205 4449 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4450 return;
4451 }
4452
c19d1205
ZW
4453 if (unwind.fp_reg != REG_SP)
4454 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4455
c19d1205
ZW
4456 /* Generate opcode to restore the value. */
4457 op = 0x90 | reg;
4458 add_unwind_opcode (op, 1);
4459
4460 /* Record the information for later. */
4461 unwind.fp_reg = reg;
4fa3602b 4462 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4463 unwind.sp_restored = 1;
b05fe5cf
ZW
4464}
4465
c19d1205
ZW
4466/* Parse an unwind_pad directive. */
4467
b05fe5cf 4468static void
c19d1205 4469s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4470{
c19d1205 4471 int offset;
b05fe5cf 4472
921e5f0a 4473 if (!unwind.proc_start)
c921be7d 4474 as_bad (MISSING_FNSTART);
921e5f0a 4475
c19d1205
ZW
4476 if (immediate_for_directive (&offset) == FAIL)
4477 return;
b99bd4ef 4478
c19d1205
ZW
4479 if (offset & 3)
4480 {
4481 as_bad (_("stack increment must be multiple of 4"));
4482 ignore_rest_of_line ();
4483 return;
4484 }
b99bd4ef 4485
c19d1205
ZW
4486 /* Don't generate any opcodes, just record the details for later. */
4487 unwind.frame_size += offset;
4488 unwind.pending_offset += offset;
4489
4490 demand_empty_rest_of_line ();
4491}
4492
4493/* Parse an unwind_setfp directive. */
4494
4495static void
4496s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4497{
c19d1205
ZW
4498 int sp_reg;
4499 int fp_reg;
4500 int offset;
4501
921e5f0a 4502 if (!unwind.proc_start)
c921be7d 4503 as_bad (MISSING_FNSTART);
921e5f0a 4504
dcbf9037 4505 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4506 if (skip_past_comma (&input_line_pointer) == FAIL)
4507 sp_reg = FAIL;
4508 else
dcbf9037 4509 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4510
c19d1205
ZW
4511 if (fp_reg == FAIL || sp_reg == FAIL)
4512 {
4513 as_bad (_("expected <reg>, <reg>"));
4514 ignore_rest_of_line ();
4515 return;
4516 }
b99bd4ef 4517
c19d1205
ZW
4518 /* Optional constant. */
4519 if (skip_past_comma (&input_line_pointer) != FAIL)
4520 {
4521 if (immediate_for_directive (&offset) == FAIL)
4522 return;
4523 }
4524 else
4525 offset = 0;
a737bd4d 4526
c19d1205 4527 demand_empty_rest_of_line ();
a737bd4d 4528
fdfde340 4529 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4530 {
c19d1205
ZW
4531 as_bad (_("register must be either sp or set by a previous"
4532 "unwind_movsp directive"));
4533 return;
a737bd4d
NC
4534 }
4535
c19d1205
ZW
4536 /* Don't generate any opcodes, just record the information for later. */
4537 unwind.fp_reg = fp_reg;
4538 unwind.fp_used = 1;
fdfde340 4539 if (sp_reg == REG_SP)
c19d1205
ZW
4540 unwind.fp_offset = unwind.frame_size - offset;
4541 else
4542 unwind.fp_offset -= offset;
a737bd4d
NC
4543}
4544
c19d1205
ZW
4545/* Parse an unwind_raw directive. */
4546
4547static void
4548s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4549{
c19d1205 4550 expressionS exp;
708587a4 4551 /* This is an arbitrary limit. */
c19d1205
ZW
4552 unsigned char op[16];
4553 int count;
a737bd4d 4554
921e5f0a 4555 if (!unwind.proc_start)
c921be7d 4556 as_bad (MISSING_FNSTART);
921e5f0a 4557
c19d1205
ZW
4558 expression (&exp);
4559 if (exp.X_op == O_constant
4560 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4561 {
c19d1205
ZW
4562 unwind.frame_size += exp.X_add_number;
4563 expression (&exp);
4564 }
4565 else
4566 exp.X_op = O_illegal;
a737bd4d 4567
c19d1205
ZW
4568 if (exp.X_op != O_constant)
4569 {
4570 as_bad (_("expected <offset>, <opcode>"));
4571 ignore_rest_of_line ();
4572 return;
4573 }
a737bd4d 4574
c19d1205 4575 count = 0;
a737bd4d 4576
c19d1205
ZW
4577 /* Parse the opcode. */
4578 for (;;)
4579 {
4580 if (count >= 16)
4581 {
4582 as_bad (_("unwind opcode too long"));
4583 ignore_rest_of_line ();
a737bd4d 4584 }
c19d1205 4585 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4586 {
c19d1205
ZW
4587 as_bad (_("invalid unwind opcode"));
4588 ignore_rest_of_line ();
4589 return;
a737bd4d 4590 }
c19d1205 4591 op[count++] = exp.X_add_number;
a737bd4d 4592
c19d1205
ZW
4593 /* Parse the next byte. */
4594 if (skip_past_comma (&input_line_pointer) == FAIL)
4595 break;
a737bd4d 4596
c19d1205
ZW
4597 expression (&exp);
4598 }
b99bd4ef 4599
c19d1205
ZW
4600 /* Add the opcode bytes in reverse order. */
4601 while (count--)
4602 add_unwind_opcode (op[count], 1);
b99bd4ef 4603
c19d1205 4604 demand_empty_rest_of_line ();
b99bd4ef 4605}
ee065d83
PB
4606
4607
4608/* Parse a .eabi_attribute directive. */
4609
4610static void
4611s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4612{
0420f52b 4613 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4614
4615 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4616 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4617}
4618
0855e32b
NS
4619/* Emit a tls fix for the symbol. */
4620
4621static void
4622s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4623{
4624 char *p;
4625 expressionS exp;
4626#ifdef md_flush_pending_output
4627 md_flush_pending_output ();
4628#endif
4629
4630#ifdef md_cons_align
4631 md_cons_align (4);
4632#endif
4633
4634 /* Since we're just labelling the code, there's no need to define a
4635 mapping symbol. */
4636 expression (&exp);
4637 p = obstack_next_free (&frchain_now->frch_obstack);
4638 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4639 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4640 : BFD_RELOC_ARM_TLS_DESCSEQ);
4641}
cdf9ccec 4642#endif /* OBJ_ELF */
0855e32b 4643
ee065d83 4644static void s_arm_arch (int);
7a1d4c38 4645static void s_arm_object_arch (int);
ee065d83
PB
4646static void s_arm_cpu (int);
4647static void s_arm_fpu (int);
69133863 4648static void s_arm_arch_extension (int);
b99bd4ef 4649
f0927246
NC
4650#ifdef TE_PE
4651
4652static void
5f4273c7 4653pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4654{
4655 expressionS exp;
4656
4657 do
4658 {
4659 expression (&exp);
4660 if (exp.X_op == O_symbol)
4661 exp.X_op = O_secrel;
4662
4663 emit_expr (&exp, 4);
4664 }
4665 while (*input_line_pointer++ == ',');
4666
4667 input_line_pointer--;
4668 demand_empty_rest_of_line ();
4669}
4670#endif /* TE_PE */
4671
c19d1205
ZW
4672/* This table describes all the machine specific pseudo-ops the assembler
4673 has to support. The fields are:
4674 pseudo-op name without dot
4675 function to call to execute this pseudo-op
4676 Integer arg to pass to the function. */
b99bd4ef 4677
c19d1205 4678const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4679{
c19d1205
ZW
4680 /* Never called because '.req' does not start a line. */
4681 { "req", s_req, 0 },
dcbf9037
JB
4682 /* Following two are likewise never called. */
4683 { "dn", s_dn, 0 },
4684 { "qn", s_qn, 0 },
c19d1205
ZW
4685 { "unreq", s_unreq, 0 },
4686 { "bss", s_bss, 0 },
db2ed2e0 4687 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4688 { "arm", s_arm, 0 },
4689 { "thumb", s_thumb, 0 },
4690 { "code", s_code, 0 },
4691 { "force_thumb", s_force_thumb, 0 },
4692 { "thumb_func", s_thumb_func, 0 },
4693 { "thumb_set", s_thumb_set, 0 },
4694 { "even", s_even, 0 },
4695 { "ltorg", s_ltorg, 0 },
4696 { "pool", s_ltorg, 0 },
4697 { "syntax", s_syntax, 0 },
8463be01
PB
4698 { "cpu", s_arm_cpu, 0 },
4699 { "arch", s_arm_arch, 0 },
7a1d4c38 4700 { "object_arch", s_arm_object_arch, 0 },
8463be01 4701 { "fpu", s_arm_fpu, 0 },
69133863 4702 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4703#ifdef OBJ_ELF
c921be7d
NC
4704 { "word", s_arm_elf_cons, 4 },
4705 { "long", s_arm_elf_cons, 4 },
4706 { "inst.n", s_arm_elf_inst, 2 },
4707 { "inst.w", s_arm_elf_inst, 4 },
4708 { "inst", s_arm_elf_inst, 0 },
4709 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4710 { "fnstart", s_arm_unwind_fnstart, 0 },
4711 { "fnend", s_arm_unwind_fnend, 0 },
4712 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4713 { "personality", s_arm_unwind_personality, 0 },
4714 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4715 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4716 { "save", s_arm_unwind_save, 0 },
fa073d69 4717 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4718 { "movsp", s_arm_unwind_movsp, 0 },
4719 { "pad", s_arm_unwind_pad, 0 },
4720 { "setfp", s_arm_unwind_setfp, 0 },
4721 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4722 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4723 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4724#else
4725 { "word", cons, 4},
f0927246
NC
4726
4727 /* These are used for dwarf. */
4728 {"2byte", cons, 2},
4729 {"4byte", cons, 4},
4730 {"8byte", cons, 8},
4731 /* These are used for dwarf2. */
4732 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4733 { "loc", dwarf2_directive_loc, 0 },
4734 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4735#endif
4736 { "extend", float_cons, 'x' },
4737 { "ldouble", float_cons, 'x' },
4738 { "packed", float_cons, 'p' },
f0927246
NC
4739#ifdef TE_PE
4740 {"secrel32", pe_directive_secrel, 0},
4741#endif
2e6976a8
DG
4742
4743 /* These are for compatibility with CodeComposer Studio. */
4744 {"ref", s_ccs_ref, 0},
4745 {"def", s_ccs_def, 0},
4746 {"asmfunc", s_ccs_asmfunc, 0},
4747 {"endasmfunc", s_ccs_endasmfunc, 0},
4748
c19d1205
ZW
4749 { 0, 0, 0 }
4750};
4751\f
4752/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4753
c19d1205
ZW
4754/* Generic immediate-value read function for use in insn parsing.
4755 STR points to the beginning of the immediate (the leading #);
4756 VAL receives the value; if the value is outside [MIN, MAX]
4757 issue an error. PREFIX_OPT is true if the immediate prefix is
4758 optional. */
b99bd4ef 4759
c19d1205
ZW
4760static int
4761parse_immediate (char **str, int *val, int min, int max,
4762 bfd_boolean prefix_opt)
4763{
4764 expressionS exp;
4765 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4766 if (exp.X_op != O_constant)
b99bd4ef 4767 {
c19d1205
ZW
4768 inst.error = _("constant expression required");
4769 return FAIL;
4770 }
b99bd4ef 4771
c19d1205
ZW
4772 if (exp.X_add_number < min || exp.X_add_number > max)
4773 {
4774 inst.error = _("immediate value out of range");
4775 return FAIL;
4776 }
b99bd4ef 4777
c19d1205
ZW
4778 *val = exp.X_add_number;
4779 return SUCCESS;
4780}
b99bd4ef 4781
5287ad62 4782/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4783 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4784 instructions. Puts the result directly in inst.operands[i]. */
4785
4786static int
8335d6aa
JW
4787parse_big_immediate (char **str, int i, expressionS *in_exp,
4788 bfd_boolean allow_symbol_p)
5287ad62
JB
4789{
4790 expressionS exp;
8335d6aa 4791 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4792 char *ptr = *str;
4793
8335d6aa 4794 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4795
8335d6aa 4796 if (exp_p->X_op == O_constant)
036dc3f7 4797 {
8335d6aa 4798 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4799 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4800 O_constant. We have to be careful not to break compilation for
4801 32-bit X_add_number, though. */
8335d6aa 4802 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4803 {
8335d6aa
JW
4804 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4805 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4806 & 0xffffffff);
036dc3f7
PB
4807 inst.operands[i].regisimm = 1;
4808 }
4809 }
8335d6aa
JW
4810 else if (exp_p->X_op == O_big
4811 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4812 {
4813 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4814
5287ad62 4815 /* Bignums have their least significant bits in
477330fc
RM
4816 generic_bignum[0]. Make sure we put 32 bits in imm and
4817 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4818 gas_assert (parts != 0);
95b75c01
NC
4819
4820 /* Make sure that the number is not too big.
4821 PR 11972: Bignums can now be sign-extended to the
4822 size of a .octa so check that the out of range bits
4823 are all zero or all one. */
8335d6aa 4824 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4825 {
4826 LITTLENUM_TYPE m = -1;
4827
4828 if (generic_bignum[parts * 2] != 0
4829 && generic_bignum[parts * 2] != m)
4830 return FAIL;
4831
8335d6aa 4832 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4833 if (generic_bignum[j] != generic_bignum[j-1])
4834 return FAIL;
4835 }
4836
5287ad62
JB
4837 inst.operands[i].imm = 0;
4838 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4839 inst.operands[i].imm |= generic_bignum[idx]
4840 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4841 inst.operands[i].reg = 0;
4842 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4843 inst.operands[i].reg |= generic_bignum[idx]
4844 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4845 inst.operands[i].regisimm = 1;
4846 }
8335d6aa 4847 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4848 return FAIL;
5f4273c7 4849
5287ad62
JB
4850 *str = ptr;
4851
4852 return SUCCESS;
4853}
4854
c19d1205
ZW
4855/* Returns the pseudo-register number of an FPA immediate constant,
4856 or FAIL if there isn't a valid constant here. */
b99bd4ef 4857
c19d1205
ZW
4858static int
4859parse_fpa_immediate (char ** str)
4860{
4861 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4862 char * save_in;
4863 expressionS exp;
4864 int i;
4865 int j;
b99bd4ef 4866
c19d1205
ZW
4867 /* First try and match exact strings, this is to guarantee
4868 that some formats will work even for cross assembly. */
b99bd4ef 4869
c19d1205
ZW
4870 for (i = 0; fp_const[i]; i++)
4871 {
4872 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4873 {
c19d1205 4874 char *start = *str;
b99bd4ef 4875
c19d1205
ZW
4876 *str += strlen (fp_const[i]);
4877 if (is_end_of_line[(unsigned char) **str])
4878 return i + 8;
4879 *str = start;
4880 }
4881 }
b99bd4ef 4882
c19d1205
ZW
4883 /* Just because we didn't get a match doesn't mean that the constant
4884 isn't valid, just that it is in a format that we don't
4885 automatically recognize. Try parsing it with the standard
4886 expression routines. */
b99bd4ef 4887
c19d1205 4888 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4889
c19d1205
ZW
4890 /* Look for a raw floating point number. */
4891 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4892 && is_end_of_line[(unsigned char) *save_in])
4893 {
4894 for (i = 0; i < NUM_FLOAT_VALS; i++)
4895 {
4896 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4897 {
c19d1205
ZW
4898 if (words[j] != fp_values[i][j])
4899 break;
b99bd4ef
NC
4900 }
4901
c19d1205 4902 if (j == MAX_LITTLENUMS)
b99bd4ef 4903 {
c19d1205
ZW
4904 *str = save_in;
4905 return i + 8;
b99bd4ef
NC
4906 }
4907 }
4908 }
b99bd4ef 4909
c19d1205
ZW
4910 /* Try and parse a more complex expression, this will probably fail
4911 unless the code uses a floating point prefix (eg "0f"). */
4912 save_in = input_line_pointer;
4913 input_line_pointer = *str;
4914 if (expression (&exp) == absolute_section
4915 && exp.X_op == O_big
4916 && exp.X_add_number < 0)
4917 {
4918 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4919 Ditto for 15. */
ba592044
AM
4920#define X_PRECISION 5
4921#define E_PRECISION 15L
4922 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4923 {
4924 for (i = 0; i < NUM_FLOAT_VALS; i++)
4925 {
4926 for (j = 0; j < MAX_LITTLENUMS; j++)
4927 {
4928 if (words[j] != fp_values[i][j])
4929 break;
4930 }
b99bd4ef 4931
c19d1205
ZW
4932 if (j == MAX_LITTLENUMS)
4933 {
4934 *str = input_line_pointer;
4935 input_line_pointer = save_in;
4936 return i + 8;
4937 }
4938 }
4939 }
b99bd4ef
NC
4940 }
4941
c19d1205
ZW
4942 *str = input_line_pointer;
4943 input_line_pointer = save_in;
4944 inst.error = _("invalid FPA immediate expression");
4945 return FAIL;
b99bd4ef
NC
4946}
4947
136da414
JB
4948/* Returns 1 if a number has "quarter-precision" float format
4949 0baBbbbbbc defgh000 00000000 00000000. */
4950
4951static int
4952is_quarter_float (unsigned imm)
4953{
4954 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4955 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4956}
4957
aacf0b33
KT
4958
4959/* Detect the presence of a floating point or integer zero constant,
4960 i.e. #0.0 or #0. */
4961
4962static bfd_boolean
4963parse_ifimm_zero (char **in)
4964{
4965 int error_code;
4966
4967 if (!is_immediate_prefix (**in))
4968 return FALSE;
4969
4970 ++*in;
0900a05b
JW
4971
4972 /* Accept #0x0 as a synonym for #0. */
4973 if (strncmp (*in, "0x", 2) == 0)
4974 {
4975 int val;
4976 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4977 return FALSE;
4978 return TRUE;
4979 }
4980
aacf0b33
KT
4981 error_code = atof_generic (in, ".", EXP_CHARS,
4982 &generic_floating_point_number);
4983
4984 if (!error_code
4985 && generic_floating_point_number.sign == '+'
4986 && (generic_floating_point_number.low
4987 > generic_floating_point_number.leader))
4988 return TRUE;
4989
4990 return FALSE;
4991}
4992
136da414
JB
4993/* Parse an 8-bit "quarter-precision" floating point number of the form:
4994 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4995 The zero and minus-zero cases need special handling, since they can't be
4996 encoded in the "quarter-precision" float format, but can nonetheless be
4997 loaded as integer constants. */
136da414
JB
4998
4999static unsigned
5000parse_qfloat_immediate (char **ccp, int *immed)
5001{
5002 char *str = *ccp;
c96612cc 5003 char *fpnum;
136da414 5004 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5005 int found_fpchar = 0;
5f4273c7 5006
136da414 5007 skip_past_char (&str, '#');
5f4273c7 5008
c96612cc
JB
5009 /* We must not accidentally parse an integer as a floating-point number. Make
5010 sure that the value we parse is not an integer by checking for special
5011 characters '.' or 'e'.
5012 FIXME: This is a horrible hack, but doing better is tricky because type
5013 information isn't in a very usable state at parse time. */
5014 fpnum = str;
5015 skip_whitespace (fpnum);
5016
5017 if (strncmp (fpnum, "0x", 2) == 0)
5018 return FAIL;
5019 else
5020 {
5021 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5022 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5023 {
5024 found_fpchar = 1;
5025 break;
5026 }
c96612cc
JB
5027
5028 if (!found_fpchar)
477330fc 5029 return FAIL;
c96612cc 5030 }
5f4273c7 5031
136da414
JB
5032 if ((str = atof_ieee (str, 's', words)) != NULL)
5033 {
5034 unsigned fpword = 0;
5035 int i;
5f4273c7 5036
136da414
JB
5037 /* Our FP word must be 32 bits (single-precision FP). */
5038 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5039 {
5040 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5041 fpword |= words[i];
5042 }
5f4273c7 5043
c96612cc 5044 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5045 *immed = fpword;
136da414 5046 else
477330fc 5047 return FAIL;
136da414
JB
5048
5049 *ccp = str;
5f4273c7 5050
136da414
JB
5051 return SUCCESS;
5052 }
5f4273c7 5053
136da414
JB
5054 return FAIL;
5055}
5056
c19d1205
ZW
5057/* Shift operands. */
5058enum shift_kind
b99bd4ef 5059{
c19d1205
ZW
5060 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5061};
b99bd4ef 5062
c19d1205
ZW
5063struct asm_shift_name
5064{
5065 const char *name;
5066 enum shift_kind kind;
5067};
b99bd4ef 5068
c19d1205
ZW
5069/* Third argument to parse_shift. */
5070enum parse_shift_mode
5071{
5072 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5073 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5074 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5075 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5076 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5077};
b99bd4ef 5078
c19d1205
ZW
5079/* Parse a <shift> specifier on an ARM data processing instruction.
5080 This has three forms:
b99bd4ef 5081
c19d1205
ZW
5082 (LSL|LSR|ASL|ASR|ROR) Rs
5083 (LSL|LSR|ASL|ASR|ROR) #imm
5084 RRX
b99bd4ef 5085
c19d1205
ZW
5086 Note that ASL is assimilated to LSL in the instruction encoding, and
5087 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5088
c19d1205
ZW
5089static int
5090parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5091{
c19d1205
ZW
5092 const struct asm_shift_name *shift_name;
5093 enum shift_kind shift;
5094 char *s = *str;
5095 char *p = s;
5096 int reg;
b99bd4ef 5097
c19d1205
ZW
5098 for (p = *str; ISALPHA (*p); p++)
5099 ;
b99bd4ef 5100
c19d1205 5101 if (p == *str)
b99bd4ef 5102 {
c19d1205
ZW
5103 inst.error = _("shift expression expected");
5104 return FAIL;
b99bd4ef
NC
5105 }
5106
21d799b5 5107 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5108 p - *str);
c19d1205
ZW
5109
5110 if (shift_name == NULL)
b99bd4ef 5111 {
c19d1205
ZW
5112 inst.error = _("shift expression expected");
5113 return FAIL;
b99bd4ef
NC
5114 }
5115
c19d1205 5116 shift = shift_name->kind;
b99bd4ef 5117
c19d1205
ZW
5118 switch (mode)
5119 {
5120 case NO_SHIFT_RESTRICT:
5121 case SHIFT_IMMEDIATE: break;
b99bd4ef 5122
c19d1205
ZW
5123 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5124 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5125 {
5126 inst.error = _("'LSL' or 'ASR' required");
5127 return FAIL;
5128 }
5129 break;
b99bd4ef 5130
c19d1205
ZW
5131 case SHIFT_LSL_IMMEDIATE:
5132 if (shift != SHIFT_LSL)
5133 {
5134 inst.error = _("'LSL' required");
5135 return FAIL;
5136 }
5137 break;
b99bd4ef 5138
c19d1205
ZW
5139 case SHIFT_ASR_IMMEDIATE:
5140 if (shift != SHIFT_ASR)
5141 {
5142 inst.error = _("'ASR' required");
5143 return FAIL;
5144 }
5145 break;
b99bd4ef 5146
c19d1205
ZW
5147 default: abort ();
5148 }
b99bd4ef 5149
c19d1205
ZW
5150 if (shift != SHIFT_RRX)
5151 {
5152 /* Whitespace can appear here if the next thing is a bare digit. */
5153 skip_whitespace (p);
b99bd4ef 5154
c19d1205 5155 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5156 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5157 {
5158 inst.operands[i].imm = reg;
5159 inst.operands[i].immisreg = 1;
5160 }
5161 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5162 return FAIL;
5163 }
5164 inst.operands[i].shift_kind = shift;
5165 inst.operands[i].shifted = 1;
5166 *str = p;
5167 return SUCCESS;
b99bd4ef
NC
5168}
5169
c19d1205 5170/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5171
c19d1205
ZW
5172 #<immediate>
5173 #<immediate>, <rotate>
5174 <Rm>
5175 <Rm>, <shift>
b99bd4ef 5176
c19d1205
ZW
5177 where <shift> is defined by parse_shift above, and <rotate> is a
5178 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5179 is deferred to md_apply_fix. */
b99bd4ef 5180
c19d1205
ZW
5181static int
5182parse_shifter_operand (char **str, int i)
5183{
5184 int value;
91d6fa6a 5185 expressionS exp;
b99bd4ef 5186
dcbf9037 5187 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5188 {
5189 inst.operands[i].reg = value;
5190 inst.operands[i].isreg = 1;
b99bd4ef 5191
c19d1205
ZW
5192 /* parse_shift will override this if appropriate */
5193 inst.reloc.exp.X_op = O_constant;
5194 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5195
c19d1205
ZW
5196 if (skip_past_comma (str) == FAIL)
5197 return SUCCESS;
b99bd4ef 5198
c19d1205
ZW
5199 /* Shift operation on register. */
5200 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5201 }
5202
c19d1205
ZW
5203 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5204 return FAIL;
b99bd4ef 5205
c19d1205 5206 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5207 {
c19d1205 5208 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5209 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5210 return FAIL;
b99bd4ef 5211
91d6fa6a 5212 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5213 {
5214 inst.error = _("constant expression expected");
5215 return FAIL;
5216 }
b99bd4ef 5217
91d6fa6a 5218 value = exp.X_add_number;
c19d1205
ZW
5219 if (value < 0 || value > 30 || value % 2 != 0)
5220 {
5221 inst.error = _("invalid rotation");
5222 return FAIL;
5223 }
5224 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5225 {
5226 inst.error = _("invalid constant");
5227 return FAIL;
5228 }
09d92015 5229
a415b1cd
JB
5230 /* Encode as specified. */
5231 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5232 return SUCCESS;
09d92015
MM
5233 }
5234
c19d1205
ZW
5235 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5236 inst.reloc.pc_rel = 0;
5237 return SUCCESS;
09d92015
MM
5238}
5239
4962c51a
MS
5240/* Group relocation information. Each entry in the table contains the
5241 textual name of the relocation as may appear in assembler source
5242 and must end with a colon.
5243 Along with this textual name are the relocation codes to be used if
5244 the corresponding instruction is an ALU instruction (ADD or SUB only),
5245 an LDR, an LDRS, or an LDC. */
5246
5247struct group_reloc_table_entry
5248{
5249 const char *name;
5250 int alu_code;
5251 int ldr_code;
5252 int ldrs_code;
5253 int ldc_code;
5254};
5255
5256typedef enum
5257{
5258 /* Varieties of non-ALU group relocation. */
5259
5260 GROUP_LDR,
5261 GROUP_LDRS,
5262 GROUP_LDC
5263} group_reloc_type;
5264
5265static struct group_reloc_table_entry group_reloc_table[] =
5266 { /* Program counter relative: */
5267 { "pc_g0_nc",
5268 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5269 0, /* LDR */
5270 0, /* LDRS */
5271 0 }, /* LDC */
5272 { "pc_g0",
5273 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5274 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5275 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5276 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5277 { "pc_g1_nc",
5278 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5279 0, /* LDR */
5280 0, /* LDRS */
5281 0 }, /* LDC */
5282 { "pc_g1",
5283 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5284 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5285 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5286 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5287 { "pc_g2",
5288 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5289 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5290 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5291 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5292 /* Section base relative */
5293 { "sb_g0_nc",
5294 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5295 0, /* LDR */
5296 0, /* LDRS */
5297 0 }, /* LDC */
5298 { "sb_g0",
5299 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5300 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5301 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5302 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5303 { "sb_g1_nc",
5304 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5305 0, /* LDR */
5306 0, /* LDRS */
5307 0 }, /* LDC */
5308 { "sb_g1",
5309 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5310 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5311 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5312 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5313 { "sb_g2",
5314 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5315 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5316 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5317 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5318 /* Absolute thumb alu relocations. */
5319 { "lower0_7",
5320 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5321 0, /* LDR. */
5322 0, /* LDRS. */
5323 0 }, /* LDC. */
5324 { "lower8_15",
5325 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5326 0, /* LDR. */
5327 0, /* LDRS. */
5328 0 }, /* LDC. */
5329 { "upper0_7",
5330 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5331 0, /* LDR. */
5332 0, /* LDRS. */
5333 0 }, /* LDC. */
5334 { "upper8_15",
5335 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5336 0, /* LDR. */
5337 0, /* LDRS. */
5338 0 } }; /* LDC. */
4962c51a
MS
5339
5340/* Given the address of a pointer pointing to the textual name of a group
5341 relocation as may appear in assembler source, attempt to find its details
5342 in group_reloc_table. The pointer will be updated to the character after
5343 the trailing colon. On failure, FAIL will be returned; SUCCESS
5344 otherwise. On success, *entry will be updated to point at the relevant
5345 group_reloc_table entry. */
5346
5347static int
5348find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5349{
5350 unsigned int i;
5351 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5352 {
5353 int length = strlen (group_reloc_table[i].name);
5354
5f4273c7
NC
5355 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5356 && (*str)[length] == ':')
477330fc
RM
5357 {
5358 *out = &group_reloc_table[i];
5359 *str += (length + 1);
5360 return SUCCESS;
5361 }
4962c51a
MS
5362 }
5363
5364 return FAIL;
5365}
5366
5367/* Parse a <shifter_operand> for an ARM data processing instruction
5368 (as for parse_shifter_operand) where group relocations are allowed:
5369
5370 #<immediate>
5371 #<immediate>, <rotate>
5372 #:<group_reloc>:<expression>
5373 <Rm>
5374 <Rm>, <shift>
5375
5376 where <group_reloc> is one of the strings defined in group_reloc_table.
5377 The hashes are optional.
5378
5379 Everything else is as for parse_shifter_operand. */
5380
5381static parse_operand_result
5382parse_shifter_operand_group_reloc (char **str, int i)
5383{
5384 /* Determine if we have the sequence of characters #: or just :
5385 coming next. If we do, then we check for a group relocation.
5386 If we don't, punt the whole lot to parse_shifter_operand. */
5387
5388 if (((*str)[0] == '#' && (*str)[1] == ':')
5389 || (*str)[0] == ':')
5390 {
5391 struct group_reloc_table_entry *entry;
5392
5393 if ((*str)[0] == '#')
477330fc 5394 (*str) += 2;
4962c51a 5395 else
477330fc 5396 (*str)++;
4962c51a
MS
5397
5398 /* Try to parse a group relocation. Anything else is an error. */
5399 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5400 {
5401 inst.error = _("unknown group relocation");
5402 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5403 }
4962c51a
MS
5404
5405 /* We now have the group relocation table entry corresponding to
477330fc 5406 the name in the assembler source. Next, we parse the expression. */
4962c51a 5407 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5408 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5409
5410 /* Record the relocation type (always the ALU variant here). */
21d799b5 5411 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5412 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5413
5414 return PARSE_OPERAND_SUCCESS;
5415 }
5416 else
5417 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5418 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5419
5420 /* Never reached. */
5421}
5422
8e560766
MGD
5423/* Parse a Neon alignment expression. Information is written to
5424 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5425
8e560766
MGD
5426 align .imm = align << 8, .immisalign=1, .preind=0 */
5427static parse_operand_result
5428parse_neon_alignment (char **str, int i)
5429{
5430 char *p = *str;
5431 expressionS exp;
5432
5433 my_get_expression (&exp, &p, GE_NO_PREFIX);
5434
5435 if (exp.X_op != O_constant)
5436 {
5437 inst.error = _("alignment must be constant");
5438 return PARSE_OPERAND_FAIL;
5439 }
5440
5441 inst.operands[i].imm = exp.X_add_number << 8;
5442 inst.operands[i].immisalign = 1;
5443 /* Alignments are not pre-indexes. */
5444 inst.operands[i].preind = 0;
5445
5446 *str = p;
5447 return PARSE_OPERAND_SUCCESS;
5448}
5449
c19d1205
ZW
5450/* Parse all forms of an ARM address expression. Information is written
5451 to inst.operands[i] and/or inst.reloc.
09d92015 5452
c19d1205 5453 Preindexed addressing (.preind=1):
09d92015 5454
c19d1205
ZW
5455 [Rn, #offset] .reg=Rn .reloc.exp=offset
5456 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5457 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5458 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5459
c19d1205 5460 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5461
c19d1205 5462 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5463
c19d1205
ZW
5464 [Rn], #offset .reg=Rn .reloc.exp=offset
5465 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5466 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5467 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5468
c19d1205 5469 Unindexed addressing (.preind=0, .postind=0):
09d92015 5470
c19d1205 5471 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5472
c19d1205 5473 Other:
09d92015 5474
c19d1205
ZW
5475 [Rn]{!} shorthand for [Rn,#0]{!}
5476 =immediate .isreg=0 .reloc.exp=immediate
5477 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5478
c19d1205
ZW
5479 It is the caller's responsibility to check for addressing modes not
5480 supported by the instruction, and to set inst.reloc.type. */
5481
4962c51a
MS
5482static parse_operand_result
5483parse_address_main (char **str, int i, int group_relocations,
477330fc 5484 group_reloc_type group_type)
09d92015 5485{
c19d1205
ZW
5486 char *p = *str;
5487 int reg;
09d92015 5488
c19d1205 5489 if (skip_past_char (&p, '[') == FAIL)
09d92015 5490 {
c19d1205
ZW
5491 if (skip_past_char (&p, '=') == FAIL)
5492 {
974da60d 5493 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5494 inst.reloc.pc_rel = 1;
5495 inst.operands[i].reg = REG_PC;
5496 inst.operands[i].isreg = 1;
5497 inst.operands[i].preind = 1;
09d92015 5498
8335d6aa
JW
5499 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5500 return PARSE_OPERAND_FAIL;
5501 }
5502 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5503 /*allow_symbol_p=*/TRUE))
4962c51a 5504 return PARSE_OPERAND_FAIL;
09d92015 5505
c19d1205 5506 *str = p;
4962c51a 5507 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5508 }
5509
8ab8155f
NC
5510 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5511 skip_whitespace (p);
5512
dcbf9037 5513 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5514 {
c19d1205 5515 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5516 return PARSE_OPERAND_FAIL;
09d92015 5517 }
c19d1205
ZW
5518 inst.operands[i].reg = reg;
5519 inst.operands[i].isreg = 1;
09d92015 5520
c19d1205 5521 if (skip_past_comma (&p) == SUCCESS)
09d92015 5522 {
c19d1205 5523 inst.operands[i].preind = 1;
09d92015 5524
c19d1205
ZW
5525 if (*p == '+') p++;
5526 else if (*p == '-') p++, inst.operands[i].negative = 1;
5527
dcbf9037 5528 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5529 {
c19d1205
ZW
5530 inst.operands[i].imm = reg;
5531 inst.operands[i].immisreg = 1;
5532
5533 if (skip_past_comma (&p) == SUCCESS)
5534 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5535 return PARSE_OPERAND_FAIL;
c19d1205 5536 }
5287ad62 5537 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5538 {
5539 /* FIXME: '@' should be used here, but it's filtered out by generic
5540 code before we get to see it here. This may be subject to
5541 change. */
5542 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5543
8e560766
MGD
5544 if (result != PARSE_OPERAND_SUCCESS)
5545 return result;
5546 }
c19d1205
ZW
5547 else
5548 {
5549 if (inst.operands[i].negative)
5550 {
5551 inst.operands[i].negative = 0;
5552 p--;
5553 }
4962c51a 5554
5f4273c7
NC
5555 if (group_relocations
5556 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5557 {
5558 struct group_reloc_table_entry *entry;
5559
477330fc
RM
5560 /* Skip over the #: or : sequence. */
5561 if (*p == '#')
5562 p += 2;
5563 else
5564 p++;
4962c51a
MS
5565
5566 /* Try to parse a group relocation. Anything else is an
477330fc 5567 error. */
4962c51a
MS
5568 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5569 {
5570 inst.error = _("unknown group relocation");
5571 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5572 }
5573
5574 /* We now have the group relocation table entry corresponding to
5575 the name in the assembler source. Next, we parse the
477330fc 5576 expression. */
4962c51a
MS
5577 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5578 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5579
5580 /* Record the relocation type. */
477330fc
RM
5581 switch (group_type)
5582 {
5583 case GROUP_LDR:
5584 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5585 break;
4962c51a 5586
477330fc
RM
5587 case GROUP_LDRS:
5588 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5589 break;
4962c51a 5590
477330fc
RM
5591 case GROUP_LDC:
5592 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5593 break;
4962c51a 5594
477330fc
RM
5595 default:
5596 gas_assert (0);
5597 }
4962c51a 5598
477330fc 5599 if (inst.reloc.type == 0)
4962c51a
MS
5600 {
5601 inst.error = _("this group relocation is not allowed on this instruction");
5602 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5603 }
477330fc
RM
5604 }
5605 else
26d97720
NS
5606 {
5607 char *q = p;
5608 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5609 return PARSE_OPERAND_FAIL;
5610 /* If the offset is 0, find out if it's a +0 or -0. */
5611 if (inst.reloc.exp.X_op == O_constant
5612 && inst.reloc.exp.X_add_number == 0)
5613 {
5614 skip_whitespace (q);
5615 if (*q == '#')
5616 {
5617 q++;
5618 skip_whitespace (q);
5619 }
5620 if (*q == '-')
5621 inst.operands[i].negative = 1;
5622 }
5623 }
09d92015
MM
5624 }
5625 }
8e560766
MGD
5626 else if (skip_past_char (&p, ':') == SUCCESS)
5627 {
5628 /* FIXME: '@' should be used here, but it's filtered out by generic code
5629 before we get to see it here. This may be subject to change. */
5630 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5631
8e560766
MGD
5632 if (result != PARSE_OPERAND_SUCCESS)
5633 return result;
5634 }
09d92015 5635
c19d1205 5636 if (skip_past_char (&p, ']') == FAIL)
09d92015 5637 {
c19d1205 5638 inst.error = _("']' expected");
4962c51a 5639 return PARSE_OPERAND_FAIL;
09d92015
MM
5640 }
5641
c19d1205
ZW
5642 if (skip_past_char (&p, '!') == SUCCESS)
5643 inst.operands[i].writeback = 1;
09d92015 5644
c19d1205 5645 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5646 {
c19d1205
ZW
5647 if (skip_past_char (&p, '{') == SUCCESS)
5648 {
5649 /* [Rn], {expr} - unindexed, with option */
5650 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5651 0, 255, TRUE) == FAIL)
4962c51a 5652 return PARSE_OPERAND_FAIL;
09d92015 5653
c19d1205
ZW
5654 if (skip_past_char (&p, '}') == FAIL)
5655 {
5656 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5657 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5658 }
5659 if (inst.operands[i].preind)
5660 {
5661 inst.error = _("cannot combine index with option");
4962c51a 5662 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5663 }
5664 *str = p;
4962c51a 5665 return PARSE_OPERAND_SUCCESS;
09d92015 5666 }
c19d1205
ZW
5667 else
5668 {
5669 inst.operands[i].postind = 1;
5670 inst.operands[i].writeback = 1;
09d92015 5671
c19d1205
ZW
5672 if (inst.operands[i].preind)
5673 {
5674 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5675 return PARSE_OPERAND_FAIL;
c19d1205 5676 }
09d92015 5677
c19d1205
ZW
5678 if (*p == '+') p++;
5679 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5680
dcbf9037 5681 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5682 {
477330fc
RM
5683 /* We might be using the immediate for alignment already. If we
5684 are, OR the register number into the low-order bits. */
5685 if (inst.operands[i].immisalign)
5686 inst.operands[i].imm |= reg;
5687 else
5688 inst.operands[i].imm = reg;
c19d1205 5689 inst.operands[i].immisreg = 1;
a737bd4d 5690
c19d1205
ZW
5691 if (skip_past_comma (&p) == SUCCESS)
5692 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5693 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5694 }
5695 else
5696 {
26d97720 5697 char *q = p;
c19d1205
ZW
5698 if (inst.operands[i].negative)
5699 {
5700 inst.operands[i].negative = 0;
5701 p--;
5702 }
5703 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5704 return PARSE_OPERAND_FAIL;
26d97720
NS
5705 /* If the offset is 0, find out if it's a +0 or -0. */
5706 if (inst.reloc.exp.X_op == O_constant
5707 && inst.reloc.exp.X_add_number == 0)
5708 {
5709 skip_whitespace (q);
5710 if (*q == '#')
5711 {
5712 q++;
5713 skip_whitespace (q);
5714 }
5715 if (*q == '-')
5716 inst.operands[i].negative = 1;
5717 }
c19d1205
ZW
5718 }
5719 }
a737bd4d
NC
5720 }
5721
c19d1205
ZW
5722 /* If at this point neither .preind nor .postind is set, we have a
5723 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5724 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5725 {
5726 inst.operands[i].preind = 1;
5727 inst.reloc.exp.X_op = O_constant;
5728 inst.reloc.exp.X_add_number = 0;
5729 }
5730 *str = p;
4962c51a
MS
5731 return PARSE_OPERAND_SUCCESS;
5732}
5733
5734static int
5735parse_address (char **str, int i)
5736{
21d799b5 5737 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5738 ? SUCCESS : FAIL;
4962c51a
MS
5739}
5740
5741static parse_operand_result
5742parse_address_group_reloc (char **str, int i, group_reloc_type type)
5743{
5744 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5745}
5746
b6895b4f
PB
5747/* Parse an operand for a MOVW or MOVT instruction. */
5748static int
5749parse_half (char **str)
5750{
5751 char * p;
5f4273c7 5752
b6895b4f
PB
5753 p = *str;
5754 skip_past_char (&p, '#');
5f4273c7 5755 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5756 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5757 else if (strncasecmp (p, ":upper16:", 9) == 0)
5758 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5759
5760 if (inst.reloc.type != BFD_RELOC_UNUSED)
5761 {
5762 p += 9;
5f4273c7 5763 skip_whitespace (p);
b6895b4f
PB
5764 }
5765
5766 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5767 return FAIL;
5768
5769 if (inst.reloc.type == BFD_RELOC_UNUSED)
5770 {
5771 if (inst.reloc.exp.X_op != O_constant)
5772 {
5773 inst.error = _("constant expression expected");
5774 return FAIL;
5775 }
5776 if (inst.reloc.exp.X_add_number < 0
5777 || inst.reloc.exp.X_add_number > 0xffff)
5778 {
5779 inst.error = _("immediate value out of range");
5780 return FAIL;
5781 }
5782 }
5783 *str = p;
5784 return SUCCESS;
5785}
5786
c19d1205 5787/* Miscellaneous. */
a737bd4d 5788
c19d1205
ZW
5789/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5790 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5791static int
d2cd1205 5792parse_psr (char **str, bfd_boolean lhs)
09d92015 5793{
c19d1205
ZW
5794 char *p;
5795 unsigned long psr_field;
62b3e311
PB
5796 const struct asm_psr *psr;
5797 char *start;
d2cd1205 5798 bfd_boolean is_apsr = FALSE;
ac7f631b 5799 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5800
a4482bb6
NC
5801 /* PR gas/12698: If the user has specified -march=all then m_profile will
5802 be TRUE, but we want to ignore it in this case as we are building for any
5803 CPU type, including non-m variants. */
823d2571 5804 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5805 m_profile = FALSE;
5806
c19d1205
ZW
5807 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5808 feature for ease of use and backwards compatibility. */
5809 p = *str;
62b3e311 5810 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5811 {
5812 if (m_profile)
5813 goto unsupported_psr;
fa94de6b 5814
d2cd1205
JB
5815 psr_field = SPSR_BIT;
5816 }
5817 else if (strncasecmp (p, "CPSR", 4) == 0)
5818 {
5819 if (m_profile)
5820 goto unsupported_psr;
5821
5822 psr_field = 0;
5823 }
5824 else if (strncasecmp (p, "APSR", 4) == 0)
5825 {
5826 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5827 and ARMv7-R architecture CPUs. */
5828 is_apsr = TRUE;
5829 psr_field = 0;
5830 }
5831 else if (m_profile)
62b3e311
PB
5832 {
5833 start = p;
5834 do
5835 p++;
5836 while (ISALNUM (*p) || *p == '_');
5837
d2cd1205
JB
5838 if (strncasecmp (start, "iapsr", 5) == 0
5839 || strncasecmp (start, "eapsr", 5) == 0
5840 || strncasecmp (start, "xpsr", 4) == 0
5841 || strncasecmp (start, "psr", 3) == 0)
5842 p = start + strcspn (start, "rR") + 1;
5843
21d799b5 5844 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5845 p - start);
d2cd1205 5846
62b3e311
PB
5847 if (!psr)
5848 return FAIL;
09d92015 5849
d2cd1205
JB
5850 /* If APSR is being written, a bitfield may be specified. Note that
5851 APSR itself is handled above. */
5852 if (psr->field <= 3)
5853 {
5854 psr_field = psr->field;
5855 is_apsr = TRUE;
5856 goto check_suffix;
5857 }
5858
62b3e311 5859 *str = p;
d2cd1205
JB
5860 /* M-profile MSR instructions have the mask field set to "10", except
5861 *PSR variants which modify APSR, which may use a different mask (and
5862 have been handled already). Do that by setting the PSR_f field
5863 here. */
5864 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5865 }
d2cd1205
JB
5866 else
5867 goto unsupported_psr;
09d92015 5868
62b3e311 5869 p += 4;
d2cd1205 5870check_suffix:
c19d1205
ZW
5871 if (*p == '_')
5872 {
5873 /* A suffix follows. */
c19d1205
ZW
5874 p++;
5875 start = p;
a737bd4d 5876
c19d1205
ZW
5877 do
5878 p++;
5879 while (ISALNUM (*p) || *p == '_');
a737bd4d 5880
d2cd1205
JB
5881 if (is_apsr)
5882 {
5883 /* APSR uses a notation for bits, rather than fields. */
5884 unsigned int nzcvq_bits = 0;
5885 unsigned int g_bit = 0;
5886 char *bit;
fa94de6b 5887
d2cd1205
JB
5888 for (bit = start; bit != p; bit++)
5889 {
5890 switch (TOLOWER (*bit))
477330fc 5891 {
d2cd1205
JB
5892 case 'n':
5893 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5894 break;
5895
5896 case 'z':
5897 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5898 break;
5899
5900 case 'c':
5901 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5902 break;
5903
5904 case 'v':
5905 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5906 break;
fa94de6b 5907
d2cd1205
JB
5908 case 'q':
5909 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5910 break;
fa94de6b 5911
d2cd1205
JB
5912 case 'g':
5913 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5914 break;
fa94de6b 5915
d2cd1205
JB
5916 default:
5917 inst.error = _("unexpected bit specified after APSR");
5918 return FAIL;
5919 }
5920 }
fa94de6b 5921
d2cd1205
JB
5922 if (nzcvq_bits == 0x1f)
5923 psr_field |= PSR_f;
fa94de6b 5924
d2cd1205
JB
5925 if (g_bit == 0x1)
5926 {
5927 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5928 {
d2cd1205
JB
5929 inst.error = _("selected processor does not "
5930 "support DSP extension");
5931 return FAIL;
5932 }
5933
5934 psr_field |= PSR_s;
5935 }
fa94de6b 5936
d2cd1205
JB
5937 if ((nzcvq_bits & 0x20) != 0
5938 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5939 || (g_bit & 0x2) != 0)
5940 {
5941 inst.error = _("bad bitmask specified after APSR");
5942 return FAIL;
5943 }
5944 }
5945 else
477330fc 5946 {
d2cd1205 5947 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5948 p - start);
d2cd1205 5949 if (!psr)
477330fc 5950 goto error;
a737bd4d 5951
d2cd1205
JB
5952 psr_field |= psr->field;
5953 }
a737bd4d 5954 }
c19d1205 5955 else
a737bd4d 5956 {
c19d1205
ZW
5957 if (ISALNUM (*p))
5958 goto error; /* Garbage after "[CS]PSR". */
5959
d2cd1205 5960 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5961 is deprecated, but allow it anyway. */
d2cd1205
JB
5962 if (is_apsr && lhs)
5963 {
5964 psr_field |= PSR_f;
5965 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5966 "deprecated"));
5967 }
5968 else if (!m_profile)
5969 /* These bits are never right for M-profile devices: don't set them
5970 (only code paths which read/write APSR reach here). */
5971 psr_field |= (PSR_c | PSR_f);
a737bd4d 5972 }
c19d1205
ZW
5973 *str = p;
5974 return psr_field;
a737bd4d 5975
d2cd1205
JB
5976 unsupported_psr:
5977 inst.error = _("selected processor does not support requested special "
5978 "purpose register");
5979 return FAIL;
5980
c19d1205
ZW
5981 error:
5982 inst.error = _("flag for {c}psr instruction expected");
5983 return FAIL;
a737bd4d
NC
5984}
5985
c19d1205
ZW
5986/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5987 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5988
c19d1205
ZW
5989static int
5990parse_cps_flags (char **str)
a737bd4d 5991{
c19d1205
ZW
5992 int val = 0;
5993 int saw_a_flag = 0;
5994 char *s = *str;
a737bd4d 5995
c19d1205
ZW
5996 for (;;)
5997 switch (*s++)
5998 {
5999 case '\0': case ',':
6000 goto done;
a737bd4d 6001
c19d1205
ZW
6002 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6003 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6004 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6005
c19d1205
ZW
6006 default:
6007 inst.error = _("unrecognized CPS flag");
6008 return FAIL;
6009 }
a737bd4d 6010
c19d1205
ZW
6011 done:
6012 if (saw_a_flag == 0)
a737bd4d 6013 {
c19d1205
ZW
6014 inst.error = _("missing CPS flags");
6015 return FAIL;
a737bd4d 6016 }
a737bd4d 6017
c19d1205
ZW
6018 *str = s - 1;
6019 return val;
a737bd4d
NC
6020}
6021
c19d1205
ZW
6022/* Parse an endian specifier ("BE" or "LE", case insensitive);
6023 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6024
6025static int
c19d1205 6026parse_endian_specifier (char **str)
a737bd4d 6027{
c19d1205
ZW
6028 int little_endian;
6029 char *s = *str;
a737bd4d 6030
c19d1205
ZW
6031 if (strncasecmp (s, "BE", 2))
6032 little_endian = 0;
6033 else if (strncasecmp (s, "LE", 2))
6034 little_endian = 1;
6035 else
a737bd4d 6036 {
c19d1205 6037 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6038 return FAIL;
6039 }
6040
c19d1205 6041 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6042 {
c19d1205 6043 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6044 return FAIL;
6045 }
6046
c19d1205
ZW
6047 *str = s + 2;
6048 return little_endian;
6049}
a737bd4d 6050
c19d1205
ZW
6051/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6052 value suitable for poking into the rotate field of an sxt or sxta
6053 instruction, or FAIL on error. */
6054
6055static int
6056parse_ror (char **str)
6057{
6058 int rot;
6059 char *s = *str;
6060
6061 if (strncasecmp (s, "ROR", 3) == 0)
6062 s += 3;
6063 else
a737bd4d 6064 {
c19d1205 6065 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6066 return FAIL;
6067 }
c19d1205
ZW
6068
6069 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6070 return FAIL;
6071
6072 switch (rot)
a737bd4d 6073 {
c19d1205
ZW
6074 case 0: *str = s; return 0x0;
6075 case 8: *str = s; return 0x1;
6076 case 16: *str = s; return 0x2;
6077 case 24: *str = s; return 0x3;
6078
6079 default:
6080 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6081 return FAIL;
6082 }
c19d1205 6083}
a737bd4d 6084
c19d1205
ZW
6085/* Parse a conditional code (from conds[] below). The value returned is in the
6086 range 0 .. 14, or FAIL. */
6087static int
6088parse_cond (char **str)
6089{
c462b453 6090 char *q;
c19d1205 6091 const struct asm_cond *c;
c462b453
PB
6092 int n;
6093 /* Condition codes are always 2 characters, so matching up to
6094 3 characters is sufficient. */
6095 char cond[3];
a737bd4d 6096
c462b453
PB
6097 q = *str;
6098 n = 0;
6099 while (ISALPHA (*q) && n < 3)
6100 {
e07e6e58 6101 cond[n] = TOLOWER (*q);
c462b453
PB
6102 q++;
6103 n++;
6104 }
a737bd4d 6105
21d799b5 6106 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6107 if (!c)
a737bd4d 6108 {
c19d1205 6109 inst.error = _("condition required");
a737bd4d
NC
6110 return FAIL;
6111 }
6112
c19d1205
ZW
6113 *str = q;
6114 return c->value;
6115}
6116
643afb90
MW
6117/* Record a use of the given feature. */
6118static void
6119record_feature_use (const arm_feature_set *feature)
6120{
6121 if (thumb_mode)
6122 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6123 else
6124 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6125}
6126
e797f7e0
MGD
6127/* If the given feature available in the selected CPU, mark it as used.
6128 Returns TRUE iff feature is available. */
6129static bfd_boolean
6130mark_feature_used (const arm_feature_set *feature)
6131{
6132 /* Ensure the option is valid on the current architecture. */
6133 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6134 return FALSE;
6135
6136 /* Add the appropriate architecture feature for the barrier option used.
6137 */
643afb90 6138 record_feature_use (feature);
e797f7e0
MGD
6139
6140 return TRUE;
6141}
6142
62b3e311
PB
6143/* Parse an option for a barrier instruction. Returns the encoding for the
6144 option, or FAIL. */
6145static int
6146parse_barrier (char **str)
6147{
6148 char *p, *q;
6149 const struct asm_barrier_opt *o;
6150
6151 p = q = *str;
6152 while (ISALPHA (*q))
6153 q++;
6154
21d799b5 6155 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6156 q - p);
62b3e311
PB
6157 if (!o)
6158 return FAIL;
6159
e797f7e0
MGD
6160 if (!mark_feature_used (&o->arch))
6161 return FAIL;
6162
62b3e311
PB
6163 *str = q;
6164 return o->value;
6165}
6166
92e90b6e
PB
6167/* Parse the operands of a table branch instruction. Similar to a memory
6168 operand. */
6169static int
6170parse_tb (char **str)
6171{
6172 char * p = *str;
6173 int reg;
6174
6175 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6176 {
6177 inst.error = _("'[' expected");
6178 return FAIL;
6179 }
92e90b6e 6180
dcbf9037 6181 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6182 {
6183 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6184 return FAIL;
6185 }
6186 inst.operands[0].reg = reg;
6187
6188 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6189 {
6190 inst.error = _("',' expected");
6191 return FAIL;
6192 }
5f4273c7 6193
dcbf9037 6194 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6195 {
6196 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6197 return FAIL;
6198 }
6199 inst.operands[0].imm = reg;
6200
6201 if (skip_past_comma (&p) == SUCCESS)
6202 {
6203 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6204 return FAIL;
6205 if (inst.reloc.exp.X_add_number != 1)
6206 {
6207 inst.error = _("invalid shift");
6208 return FAIL;
6209 }
6210 inst.operands[0].shifted = 1;
6211 }
6212
6213 if (skip_past_char (&p, ']') == FAIL)
6214 {
6215 inst.error = _("']' expected");
6216 return FAIL;
6217 }
6218 *str = p;
6219 return SUCCESS;
6220}
6221
5287ad62
JB
6222/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6223 information on the types the operands can take and how they are encoded.
037e8744
JB
6224 Up to four operands may be read; this function handles setting the
6225 ".present" field for each read operand itself.
5287ad62
JB
6226 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6227 else returns FAIL. */
6228
6229static int
6230parse_neon_mov (char **str, int *which_operand)
6231{
6232 int i = *which_operand, val;
6233 enum arm_reg_type rtype;
6234 char *ptr = *str;
dcbf9037 6235 struct neon_type_el optype;
5f4273c7 6236
dcbf9037 6237 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6238 {
6239 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6240 inst.operands[i].reg = val;
6241 inst.operands[i].isscalar = 1;
dcbf9037 6242 inst.operands[i].vectype = optype;
5287ad62
JB
6243 inst.operands[i++].present = 1;
6244
6245 if (skip_past_comma (&ptr) == FAIL)
477330fc 6246 goto wanted_comma;
5f4273c7 6247
dcbf9037 6248 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6249 goto wanted_arm;
5f4273c7 6250
5287ad62
JB
6251 inst.operands[i].reg = val;
6252 inst.operands[i].isreg = 1;
6253 inst.operands[i].present = 1;
6254 }
037e8744 6255 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6256 != FAIL)
5287ad62
JB
6257 {
6258 /* Cases 0, 1, 2, 3, 5 (D only). */
6259 if (skip_past_comma (&ptr) == FAIL)
477330fc 6260 goto wanted_comma;
5f4273c7 6261
5287ad62
JB
6262 inst.operands[i].reg = val;
6263 inst.operands[i].isreg = 1;
6264 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6265 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6266 inst.operands[i].isvec = 1;
dcbf9037 6267 inst.operands[i].vectype = optype;
5287ad62
JB
6268 inst.operands[i++].present = 1;
6269
dcbf9037 6270 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6271 {
6272 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6273 Case 13: VMOV <Sd>, <Rm> */
6274 inst.operands[i].reg = val;
6275 inst.operands[i].isreg = 1;
6276 inst.operands[i].present = 1;
6277
6278 if (rtype == REG_TYPE_NQ)
6279 {
6280 first_error (_("can't use Neon quad register here"));
6281 return FAIL;
6282 }
6283 else if (rtype != REG_TYPE_VFS)
6284 {
6285 i++;
6286 if (skip_past_comma (&ptr) == FAIL)
6287 goto wanted_comma;
6288 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6289 goto wanted_arm;
6290 inst.operands[i].reg = val;
6291 inst.operands[i].isreg = 1;
6292 inst.operands[i].present = 1;
6293 }
6294 }
037e8744 6295 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6296 &optype)) != FAIL)
6297 {
6298 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6299 Case 1: VMOV<c><q> <Dd>, <Dm>
6300 Case 8: VMOV.F32 <Sd>, <Sm>
6301 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6302
6303 inst.operands[i].reg = val;
6304 inst.operands[i].isreg = 1;
6305 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6306 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6307 inst.operands[i].isvec = 1;
6308 inst.operands[i].vectype = optype;
6309 inst.operands[i].present = 1;
6310
6311 if (skip_past_comma (&ptr) == SUCCESS)
6312 {
6313 /* Case 15. */
6314 i++;
6315
6316 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6317 goto wanted_arm;
6318
6319 inst.operands[i].reg = val;
6320 inst.operands[i].isreg = 1;
6321 inst.operands[i++].present = 1;
6322
6323 if (skip_past_comma (&ptr) == FAIL)
6324 goto wanted_comma;
6325
6326 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6327 goto wanted_arm;
6328
6329 inst.operands[i].reg = val;
6330 inst.operands[i].isreg = 1;
6331 inst.operands[i].present = 1;
6332 }
6333 }
4641781c 6334 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6335 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6336 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6337 Case 10: VMOV.F32 <Sd>, #<imm>
6338 Case 11: VMOV.F64 <Dd>, #<imm> */
6339 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6340 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6341 == SUCCESS)
477330fc
RM
6342 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6343 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6344 ;
5287ad62 6345 else
477330fc
RM
6346 {
6347 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6348 return FAIL;
6349 }
5287ad62 6350 }
dcbf9037 6351 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6352 {
6353 /* Cases 6, 7. */
6354 inst.operands[i].reg = val;
6355 inst.operands[i].isreg = 1;
6356 inst.operands[i++].present = 1;
5f4273c7 6357
5287ad62 6358 if (skip_past_comma (&ptr) == FAIL)
477330fc 6359 goto wanted_comma;
5f4273c7 6360
dcbf9037 6361 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6362 {
6363 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6364 inst.operands[i].reg = val;
6365 inst.operands[i].isscalar = 1;
6366 inst.operands[i].present = 1;
6367 inst.operands[i].vectype = optype;
6368 }
dcbf9037 6369 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6370 {
6371 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6372 inst.operands[i].reg = val;
6373 inst.operands[i].isreg = 1;
6374 inst.operands[i++].present = 1;
6375
6376 if (skip_past_comma (&ptr) == FAIL)
6377 goto wanted_comma;
6378
6379 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6380 == FAIL)
6381 {
6382 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6383 return FAIL;
6384 }
6385
6386 inst.operands[i].reg = val;
6387 inst.operands[i].isreg = 1;
6388 inst.operands[i].isvec = 1;
6389 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6390 inst.operands[i].vectype = optype;
6391 inst.operands[i].present = 1;
6392
6393 if (rtype == REG_TYPE_VFS)
6394 {
6395 /* Case 14. */
6396 i++;
6397 if (skip_past_comma (&ptr) == FAIL)
6398 goto wanted_comma;
6399 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6400 &optype)) == FAIL)
6401 {
6402 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6403 return FAIL;
6404 }
6405 inst.operands[i].reg = val;
6406 inst.operands[i].isreg = 1;
6407 inst.operands[i].isvec = 1;
6408 inst.operands[i].issingle = 1;
6409 inst.operands[i].vectype = optype;
6410 inst.operands[i].present = 1;
6411 }
6412 }
037e8744 6413 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6414 != FAIL)
6415 {
6416 /* Case 13. */
6417 inst.operands[i].reg = val;
6418 inst.operands[i].isreg = 1;
6419 inst.operands[i].isvec = 1;
6420 inst.operands[i].issingle = 1;
6421 inst.operands[i].vectype = optype;
6422 inst.operands[i].present = 1;
6423 }
5287ad62
JB
6424 }
6425 else
6426 {
dcbf9037 6427 first_error (_("parse error"));
5287ad62
JB
6428 return FAIL;
6429 }
6430
6431 /* Successfully parsed the operands. Update args. */
6432 *which_operand = i;
6433 *str = ptr;
6434 return SUCCESS;
6435
5f4273c7 6436 wanted_comma:
dcbf9037 6437 first_error (_("expected comma"));
5287ad62 6438 return FAIL;
5f4273c7
NC
6439
6440 wanted_arm:
dcbf9037 6441 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6442 return FAIL;
5287ad62
JB
6443}
6444
5be8be5d
DG
6445/* Use this macro when the operand constraints are different
6446 for ARM and THUMB (e.g. ldrd). */
6447#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6448 ((arm_operand) | ((thumb_operand) << 16))
6449
c19d1205
ZW
6450/* Matcher codes for parse_operands. */
6451enum operand_parse_code
6452{
6453 OP_stop, /* end of line */
6454
6455 OP_RR, /* ARM register */
6456 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6457 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6458 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6459 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6460 optional trailing ! */
c19d1205
ZW
6461 OP_RRw, /* ARM register, not r15, optional trailing ! */
6462 OP_RCP, /* Coprocessor number */
6463 OP_RCN, /* Coprocessor register */
6464 OP_RF, /* FPA register */
6465 OP_RVS, /* VFP single precision register */
5287ad62
JB
6466 OP_RVD, /* VFP double precision register (0..15) */
6467 OP_RND, /* Neon double precision register (0..31) */
6468 OP_RNQ, /* Neon quad precision register */
037e8744 6469 OP_RVSD, /* VFP single or double precision register */
5287ad62 6470 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6471 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6472 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6473 OP_RVC, /* VFP control register */
6474 OP_RMF, /* Maverick F register */
6475 OP_RMD, /* Maverick D register */
6476 OP_RMFX, /* Maverick FX register */
6477 OP_RMDX, /* Maverick DX register */
6478 OP_RMAX, /* Maverick AX register */
6479 OP_RMDS, /* Maverick DSPSC register */
6480 OP_RIWR, /* iWMMXt wR register */
6481 OP_RIWC, /* iWMMXt wC register */
6482 OP_RIWG, /* iWMMXt wCG register */
6483 OP_RXA, /* XScale accumulator register */
6484
6485 OP_REGLST, /* ARM register list */
6486 OP_VRSLST, /* VFP single-precision register list */
6487 OP_VRDLST, /* VFP double-precision register list */
037e8744 6488 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6489 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6490 OP_NSTRLST, /* Neon element/structure list */
6491
5287ad62 6492 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6493 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6494 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6495 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6496 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6497 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6498 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6499 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6500 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6501 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6502 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6503
6504 OP_I0, /* immediate zero */
c19d1205
ZW
6505 OP_I7, /* immediate value 0 .. 7 */
6506 OP_I15, /* 0 .. 15 */
6507 OP_I16, /* 1 .. 16 */
5287ad62 6508 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6509 OP_I31, /* 0 .. 31 */
6510 OP_I31w, /* 0 .. 31, optional trailing ! */
6511 OP_I32, /* 1 .. 32 */
5287ad62
JB
6512 OP_I32z, /* 0 .. 32 */
6513 OP_I63, /* 0 .. 63 */
c19d1205 6514 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6515 OP_I64, /* 1 .. 64 */
6516 OP_I64z, /* 0 .. 64 */
c19d1205 6517 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6518
6519 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6520 OP_I7b, /* 0 .. 7 */
6521 OP_I15b, /* 0 .. 15 */
6522 OP_I31b, /* 0 .. 31 */
6523
6524 OP_SH, /* shifter operand */
4962c51a 6525 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6526 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6527 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6528 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6529 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6530 OP_EXP, /* arbitrary expression */
6531 OP_EXPi, /* same, with optional immediate prefix */
6532 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6533 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6534
6535 OP_CPSF, /* CPS flags */
6536 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6537 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6538 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6539 OP_COND, /* conditional code */
92e90b6e 6540 OP_TB, /* Table branch. */
c19d1205 6541
037e8744
JB
6542 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6543
c19d1205
ZW
6544 OP_RRnpc_I0, /* ARM register or literal 0 */
6545 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6546 OP_RR_EXi, /* ARM register or expression with imm prefix */
6547 OP_RF_IF, /* FPA register or immediate */
6548 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6549 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6550
6551 /* Optional operands. */
6552 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6553 OP_oI31b, /* 0 .. 31 */
5287ad62 6554 OP_oI32b, /* 1 .. 32 */
5f1af56b 6555 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6556 OP_oIffffb, /* 0 .. 65535 */
6557 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6558
6559 OP_oRR, /* ARM register */
6560 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6561 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6562 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6563 OP_oRND, /* Optional Neon double precision register */
6564 OP_oRNQ, /* Optional Neon quad precision register */
6565 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6566 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6567 OP_oSHll, /* LSL immediate */
6568 OP_oSHar, /* ASR immediate */
6569 OP_oSHllar, /* LSL or ASR immediate */
6570 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6571 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6572
5be8be5d
DG
6573 /* Some pre-defined mixed (ARM/THUMB) operands. */
6574 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6575 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6576 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6577
c19d1205
ZW
6578 OP_FIRST_OPTIONAL = OP_oI7b
6579};
a737bd4d 6580
c19d1205
ZW
6581/* Generic instruction operand parser. This does no encoding and no
6582 semantic validation; it merely squirrels values away in the inst
6583 structure. Returns SUCCESS or FAIL depending on whether the
6584 specified grammar matched. */
6585static int
5be8be5d 6586parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6587{
5be8be5d 6588 unsigned const int *upat = pattern;
c19d1205
ZW
6589 char *backtrack_pos = 0;
6590 const char *backtrack_error = 0;
99aad254 6591 int i, val = 0, backtrack_index = 0;
5287ad62 6592 enum arm_reg_type rtype;
4962c51a 6593 parse_operand_result result;
5be8be5d 6594 unsigned int op_parse_code;
c19d1205 6595
e07e6e58
NC
6596#define po_char_or_fail(chr) \
6597 do \
6598 { \
6599 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6600 goto bad_args; \
e07e6e58
NC
6601 } \
6602 while (0)
c19d1205 6603
e07e6e58
NC
6604#define po_reg_or_fail(regtype) \
6605 do \
dcbf9037 6606 { \
e07e6e58 6607 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6608 & inst.operands[i].vectype); \
e07e6e58 6609 if (val == FAIL) \
477330fc
RM
6610 { \
6611 first_error (_(reg_expected_msgs[regtype])); \
6612 goto failure; \
6613 } \
e07e6e58
NC
6614 inst.operands[i].reg = val; \
6615 inst.operands[i].isreg = 1; \
6616 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6617 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6618 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6619 || rtype == REG_TYPE_VFD \
6620 || rtype == REG_TYPE_NQ); \
dcbf9037 6621 } \
e07e6e58
NC
6622 while (0)
6623
6624#define po_reg_or_goto(regtype, label) \
6625 do \
6626 { \
6627 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6628 & inst.operands[i].vectype); \
6629 if (val == FAIL) \
6630 goto label; \
dcbf9037 6631 \
e07e6e58
NC
6632 inst.operands[i].reg = val; \
6633 inst.operands[i].isreg = 1; \
6634 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6635 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6636 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6637 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6638 || rtype == REG_TYPE_NQ); \
6639 } \
6640 while (0)
6641
6642#define po_imm_or_fail(min, max, popt) \
6643 do \
6644 { \
6645 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6646 goto failure; \
6647 inst.operands[i].imm = val; \
6648 } \
6649 while (0)
6650
6651#define po_scalar_or_goto(elsz, label) \
6652 do \
6653 { \
6654 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6655 if (val == FAIL) \
6656 goto label; \
6657 inst.operands[i].reg = val; \
6658 inst.operands[i].isscalar = 1; \
6659 } \
6660 while (0)
6661
6662#define po_misc_or_fail(expr) \
6663 do \
6664 { \
6665 if (expr) \
6666 goto failure; \
6667 } \
6668 while (0)
6669
6670#define po_misc_or_fail_no_backtrack(expr) \
6671 do \
6672 { \
6673 result = expr; \
6674 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6675 backtrack_pos = 0; \
6676 if (result != PARSE_OPERAND_SUCCESS) \
6677 goto failure; \
6678 } \
6679 while (0)
4962c51a 6680
52e7f43d
RE
6681#define po_barrier_or_imm(str) \
6682 do \
6683 { \
6684 val = parse_barrier (&str); \
ccb84d65
JB
6685 if (val == FAIL && ! ISALPHA (*str)) \
6686 goto immediate; \
6687 if (val == FAIL \
6688 /* ISB can only take SY as an option. */ \
6689 || ((inst.instruction & 0xf0) == 0x60 \
6690 && val != 0xf)) \
52e7f43d 6691 { \
ccb84d65
JB
6692 inst.error = _("invalid barrier type"); \
6693 backtrack_pos = 0; \
6694 goto failure; \
52e7f43d
RE
6695 } \
6696 } \
6697 while (0)
6698
c19d1205
ZW
6699 skip_whitespace (str);
6700
6701 for (i = 0; upat[i] != OP_stop; i++)
6702 {
5be8be5d
DG
6703 op_parse_code = upat[i];
6704 if (op_parse_code >= 1<<16)
6705 op_parse_code = thumb ? (op_parse_code >> 16)
6706 : (op_parse_code & ((1<<16)-1));
6707
6708 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6709 {
6710 /* Remember where we are in case we need to backtrack. */
9c2799c2 6711 gas_assert (!backtrack_pos);
c19d1205
ZW
6712 backtrack_pos = str;
6713 backtrack_error = inst.error;
6714 backtrack_index = i;
6715 }
6716
b6702015 6717 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6718 po_char_or_fail (',');
6719
5be8be5d 6720 switch (op_parse_code)
c19d1205
ZW
6721 {
6722 /* Registers */
6723 case OP_oRRnpc:
5be8be5d 6724 case OP_oRRnpcsp:
c19d1205 6725 case OP_RRnpc:
5be8be5d 6726 case OP_RRnpcsp:
c19d1205
ZW
6727 case OP_oRR:
6728 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6729 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6730 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6731 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6732 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6733 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6734 case OP_oRND:
5287ad62 6735 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6736 case OP_RVC:
6737 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6738 break;
6739 /* Also accept generic coprocessor regs for unknown registers. */
6740 coproc_reg:
6741 po_reg_or_fail (REG_TYPE_CN);
6742 break;
c19d1205
ZW
6743 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6744 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6745 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6746 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6747 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6748 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6749 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6750 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6751 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6752 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6753 case OP_oRNQ:
5287ad62 6754 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6755 case OP_oRNDQ:
5287ad62 6756 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6757 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6758 case OP_oRNSDQ:
6759 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6760
6761 /* Neon scalar. Using an element size of 8 means that some invalid
6762 scalars are accepted here, so deal with those in later code. */
6763 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6764
6765 case OP_RNDQ_I0:
6766 {
6767 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6768 break;
6769 try_imm0:
6770 po_imm_or_fail (0, 0, TRUE);
6771 }
6772 break;
6773
6774 case OP_RVSD_I0:
6775 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6776 break;
6777
aacf0b33
KT
6778 case OP_RSVD_FI0:
6779 {
6780 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6781 break;
6782 try_ifimm0:
6783 if (parse_ifimm_zero (&str))
6784 inst.operands[i].imm = 0;
6785 else
6786 {
6787 inst.error
6788 = _("only floating point zero is allowed as immediate value");
6789 goto failure;
6790 }
6791 }
6792 break;
6793
477330fc
RM
6794 case OP_RR_RNSC:
6795 {
6796 po_scalar_or_goto (8, try_rr);
6797 break;
6798 try_rr:
6799 po_reg_or_fail (REG_TYPE_RN);
6800 }
6801 break;
6802
6803 case OP_RNSDQ_RNSC:
6804 {
6805 po_scalar_or_goto (8, try_nsdq);
6806 break;
6807 try_nsdq:
6808 po_reg_or_fail (REG_TYPE_NSDQ);
6809 }
6810 break;
6811
6812 case OP_RNDQ_RNSC:
6813 {
6814 po_scalar_or_goto (8, try_ndq);
6815 break;
6816 try_ndq:
6817 po_reg_or_fail (REG_TYPE_NDQ);
6818 }
6819 break;
6820
6821 case OP_RND_RNSC:
6822 {
6823 po_scalar_or_goto (8, try_vfd);
6824 break;
6825 try_vfd:
6826 po_reg_or_fail (REG_TYPE_VFD);
6827 }
6828 break;
6829
6830 case OP_VMOV:
6831 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6832 not careful then bad things might happen. */
6833 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6834 break;
6835
6836 case OP_RNDQ_Ibig:
6837 {
6838 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6839 break;
6840 try_immbig:
6841 /* There's a possibility of getting a 64-bit immediate here, so
6842 we need special handling. */
8335d6aa
JW
6843 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6844 == FAIL)
477330fc
RM
6845 {
6846 inst.error = _("immediate value is out of range");
6847 goto failure;
6848 }
6849 }
6850 break;
6851
6852 case OP_RNDQ_I63b:
6853 {
6854 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6855 break;
6856 try_shimm:
6857 po_imm_or_fail (0, 63, TRUE);
6858 }
6859 break;
c19d1205
ZW
6860
6861 case OP_RRnpcb:
6862 po_char_or_fail ('[');
6863 po_reg_or_fail (REG_TYPE_RN);
6864 po_char_or_fail (']');
6865 break;
a737bd4d 6866
55881a11 6867 case OP_RRnpctw:
c19d1205 6868 case OP_RRw:
b6702015 6869 case OP_oRRw:
c19d1205
ZW
6870 po_reg_or_fail (REG_TYPE_RN);
6871 if (skip_past_char (&str, '!') == SUCCESS)
6872 inst.operands[i].writeback = 1;
6873 break;
6874
6875 /* Immediates */
6876 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6877 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6878 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6879 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6880 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6881 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6882 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6883 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6884 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6885 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6886 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6887 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6888
6889 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6890 case OP_oI7b:
6891 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6892 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6893 case OP_oI31b:
6894 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6895 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6896 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6897 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6898
6899 /* Immediate variants */
6900 case OP_oI255c:
6901 po_char_or_fail ('{');
6902 po_imm_or_fail (0, 255, TRUE);
6903 po_char_or_fail ('}');
6904 break;
6905
6906 case OP_I31w:
6907 /* The expression parser chokes on a trailing !, so we have
6908 to find it first and zap it. */
6909 {
6910 char *s = str;
6911 while (*s && *s != ',')
6912 s++;
6913 if (s[-1] == '!')
6914 {
6915 s[-1] = '\0';
6916 inst.operands[i].writeback = 1;
6917 }
6918 po_imm_or_fail (0, 31, TRUE);
6919 if (str == s - 1)
6920 str = s;
6921 }
6922 break;
6923
6924 /* Expressions */
6925 case OP_EXPi: EXPi:
6926 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6927 GE_OPT_PREFIX));
6928 break;
6929
6930 case OP_EXP:
6931 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6932 GE_NO_PREFIX));
6933 break;
6934
6935 case OP_EXPr: EXPr:
6936 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6937 GE_NO_PREFIX));
6938 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6939 {
c19d1205
ZW
6940 val = parse_reloc (&str);
6941 if (val == -1)
6942 {
6943 inst.error = _("unrecognized relocation suffix");
6944 goto failure;
6945 }
6946 else if (val != BFD_RELOC_UNUSED)
6947 {
6948 inst.operands[i].imm = val;
6949 inst.operands[i].hasreloc = 1;
6950 }
a737bd4d 6951 }
c19d1205 6952 break;
a737bd4d 6953
b6895b4f
PB
6954 /* Operand for MOVW or MOVT. */
6955 case OP_HALF:
6956 po_misc_or_fail (parse_half (&str));
6957 break;
6958
e07e6e58 6959 /* Register or expression. */
c19d1205
ZW
6960 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6961 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6962
e07e6e58 6963 /* Register or immediate. */
c19d1205
ZW
6964 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6965 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6966
c19d1205
ZW
6967 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6968 IF:
6969 if (!is_immediate_prefix (*str))
6970 goto bad_args;
6971 str++;
6972 val = parse_fpa_immediate (&str);
6973 if (val == FAIL)
6974 goto failure;
6975 /* FPA immediates are encoded as registers 8-15.
6976 parse_fpa_immediate has already applied the offset. */
6977 inst.operands[i].reg = val;
6978 inst.operands[i].isreg = 1;
6979 break;
09d92015 6980
2d447fca
JM
6981 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6982 I32z: po_imm_or_fail (0, 32, FALSE); break;
6983
e07e6e58 6984 /* Two kinds of register. */
c19d1205
ZW
6985 case OP_RIWR_RIWC:
6986 {
6987 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6988 if (!rege
6989 || (rege->type != REG_TYPE_MMXWR
6990 && rege->type != REG_TYPE_MMXWC
6991 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6992 {
6993 inst.error = _("iWMMXt data or control register expected");
6994 goto failure;
6995 }
6996 inst.operands[i].reg = rege->number;
6997 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6998 }
6999 break;
09d92015 7000
41adaa5c
JM
7001 case OP_RIWC_RIWG:
7002 {
7003 struct reg_entry *rege = arm_reg_parse_multi (&str);
7004 if (!rege
7005 || (rege->type != REG_TYPE_MMXWC
7006 && rege->type != REG_TYPE_MMXWCG))
7007 {
7008 inst.error = _("iWMMXt control register expected");
7009 goto failure;
7010 }
7011 inst.operands[i].reg = rege->number;
7012 inst.operands[i].isreg = 1;
7013 }
7014 break;
7015
c19d1205
ZW
7016 /* Misc */
7017 case OP_CPSF: val = parse_cps_flags (&str); break;
7018 case OP_ENDI: val = parse_endian_specifier (&str); break;
7019 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7020 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7021 case OP_oBARRIER_I15:
7022 po_barrier_or_imm (str); break;
7023 immediate:
7024 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7025 goto failure;
52e7f43d 7026 break;
c19d1205 7027
fa94de6b 7028 case OP_wPSR:
d2cd1205 7029 case OP_rPSR:
90ec0d68
MGD
7030 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7031 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7032 {
7033 inst.error = _("Banked registers are not available with this "
7034 "architecture.");
7035 goto failure;
7036 }
7037 break;
d2cd1205
JB
7038 try_psr:
7039 val = parse_psr (&str, op_parse_code == OP_wPSR);
7040 break;
037e8744 7041
477330fc
RM
7042 case OP_APSR_RR:
7043 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7044 break;
7045 try_apsr:
7046 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7047 instruction). */
7048 if (strncasecmp (str, "APSR_", 5) == 0)
7049 {
7050 unsigned found = 0;
7051 str += 5;
7052 while (found < 15)
7053 switch (*str++)
7054 {
7055 case 'c': found = (found & 1) ? 16 : found | 1; break;
7056 case 'n': found = (found & 2) ? 16 : found | 2; break;
7057 case 'z': found = (found & 4) ? 16 : found | 4; break;
7058 case 'v': found = (found & 8) ? 16 : found | 8; break;
7059 default: found = 16;
7060 }
7061 if (found != 15)
7062 goto failure;
7063 inst.operands[i].isvec = 1;
f7c21dc7
NC
7064 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7065 inst.operands[i].reg = REG_PC;
477330fc
RM
7066 }
7067 else
7068 goto failure;
7069 break;
037e8744 7070
92e90b6e
PB
7071 case OP_TB:
7072 po_misc_or_fail (parse_tb (&str));
7073 break;
7074
e07e6e58 7075 /* Register lists. */
c19d1205
ZW
7076 case OP_REGLST:
7077 val = parse_reg_list (&str);
7078 if (*str == '^')
7079 {
5e0d7f77 7080 inst.operands[i].writeback = 1;
c19d1205
ZW
7081 str++;
7082 }
7083 break;
09d92015 7084
c19d1205 7085 case OP_VRSLST:
5287ad62 7086 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7087 break;
09d92015 7088
c19d1205 7089 case OP_VRDLST:
5287ad62 7090 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7091 break;
a737bd4d 7092
477330fc
RM
7093 case OP_VRSDLST:
7094 /* Allow Q registers too. */
7095 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7096 REGLIST_NEON_D);
7097 if (val == FAIL)
7098 {
7099 inst.error = NULL;
7100 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7101 REGLIST_VFP_S);
7102 inst.operands[i].issingle = 1;
7103 }
7104 break;
7105
7106 case OP_NRDLST:
7107 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7108 REGLIST_NEON_D);
7109 break;
5287ad62
JB
7110
7111 case OP_NSTRLST:
477330fc
RM
7112 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7113 &inst.operands[i].vectype);
7114 break;
5287ad62 7115
c19d1205
ZW
7116 /* Addressing modes */
7117 case OP_ADDR:
7118 po_misc_or_fail (parse_address (&str, i));
7119 break;
09d92015 7120
4962c51a
MS
7121 case OP_ADDRGLDR:
7122 po_misc_or_fail_no_backtrack (
477330fc 7123 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7124 break;
7125
7126 case OP_ADDRGLDRS:
7127 po_misc_or_fail_no_backtrack (
477330fc 7128 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7129 break;
7130
7131 case OP_ADDRGLDC:
7132 po_misc_or_fail_no_backtrack (
477330fc 7133 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7134 break;
7135
c19d1205
ZW
7136 case OP_SH:
7137 po_misc_or_fail (parse_shifter_operand (&str, i));
7138 break;
09d92015 7139
4962c51a
MS
7140 case OP_SHG:
7141 po_misc_or_fail_no_backtrack (
477330fc 7142 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7143 break;
7144
c19d1205
ZW
7145 case OP_oSHll:
7146 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7147 break;
09d92015 7148
c19d1205
ZW
7149 case OP_oSHar:
7150 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7151 break;
09d92015 7152
c19d1205
ZW
7153 case OP_oSHllar:
7154 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7155 break;
09d92015 7156
c19d1205 7157 default:
5be8be5d 7158 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7159 }
09d92015 7160
c19d1205
ZW
7161 /* Various value-based sanity checks and shared operations. We
7162 do not signal immediate failures for the register constraints;
7163 this allows a syntax error to take precedence. */
5be8be5d 7164 switch (op_parse_code)
c19d1205
ZW
7165 {
7166 case OP_oRRnpc:
7167 case OP_RRnpc:
7168 case OP_RRnpcb:
7169 case OP_RRw:
b6702015 7170 case OP_oRRw:
c19d1205
ZW
7171 case OP_RRnpc_I0:
7172 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7173 inst.error = BAD_PC;
7174 break;
09d92015 7175
5be8be5d
DG
7176 case OP_oRRnpcsp:
7177 case OP_RRnpcsp:
7178 if (inst.operands[i].isreg)
7179 {
7180 if (inst.operands[i].reg == REG_PC)
7181 inst.error = BAD_PC;
7182 else if (inst.operands[i].reg == REG_SP)
7183 inst.error = BAD_SP;
7184 }
7185 break;
7186
55881a11 7187 case OP_RRnpctw:
fa94de6b
RM
7188 if (inst.operands[i].isreg
7189 && inst.operands[i].reg == REG_PC
55881a11
MGD
7190 && (inst.operands[i].writeback || thumb))
7191 inst.error = BAD_PC;
7192 break;
7193
c19d1205
ZW
7194 case OP_CPSF:
7195 case OP_ENDI:
7196 case OP_oROR:
d2cd1205
JB
7197 case OP_wPSR:
7198 case OP_rPSR:
c19d1205 7199 case OP_COND:
52e7f43d 7200 case OP_oBARRIER_I15:
c19d1205
ZW
7201 case OP_REGLST:
7202 case OP_VRSLST:
7203 case OP_VRDLST:
477330fc
RM
7204 case OP_VRSDLST:
7205 case OP_NRDLST:
7206 case OP_NSTRLST:
c19d1205
ZW
7207 if (val == FAIL)
7208 goto failure;
7209 inst.operands[i].imm = val;
7210 break;
a737bd4d 7211
c19d1205
ZW
7212 default:
7213 break;
7214 }
09d92015 7215
c19d1205
ZW
7216 /* If we get here, this operand was successfully parsed. */
7217 inst.operands[i].present = 1;
7218 continue;
09d92015 7219
c19d1205 7220 bad_args:
09d92015 7221 inst.error = BAD_ARGS;
c19d1205
ZW
7222
7223 failure:
7224 if (!backtrack_pos)
d252fdde
PB
7225 {
7226 /* The parse routine should already have set inst.error, but set a
5f4273c7 7227 default here just in case. */
d252fdde
PB
7228 if (!inst.error)
7229 inst.error = _("syntax error");
7230 return FAIL;
7231 }
c19d1205
ZW
7232
7233 /* Do not backtrack over a trailing optional argument that
7234 absorbed some text. We will only fail again, with the
7235 'garbage following instruction' error message, which is
7236 probably less helpful than the current one. */
7237 if (backtrack_index == i && backtrack_pos != str
7238 && upat[i+1] == OP_stop)
d252fdde
PB
7239 {
7240 if (!inst.error)
7241 inst.error = _("syntax error");
7242 return FAIL;
7243 }
c19d1205
ZW
7244
7245 /* Try again, skipping the optional argument at backtrack_pos. */
7246 str = backtrack_pos;
7247 inst.error = backtrack_error;
7248 inst.operands[backtrack_index].present = 0;
7249 i = backtrack_index;
7250 backtrack_pos = 0;
09d92015 7251 }
09d92015 7252
c19d1205
ZW
7253 /* Check that we have parsed all the arguments. */
7254 if (*str != '\0' && !inst.error)
7255 inst.error = _("garbage following instruction");
09d92015 7256
c19d1205 7257 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7258}
7259
c19d1205
ZW
7260#undef po_char_or_fail
7261#undef po_reg_or_fail
7262#undef po_reg_or_goto
7263#undef po_imm_or_fail
5287ad62 7264#undef po_scalar_or_fail
52e7f43d 7265#undef po_barrier_or_imm
e07e6e58 7266
c19d1205 7267/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7268#define constraint(expr, err) \
7269 do \
c19d1205 7270 { \
e07e6e58
NC
7271 if (expr) \
7272 { \
7273 inst.error = err; \
7274 return; \
7275 } \
c19d1205 7276 } \
e07e6e58 7277 while (0)
c19d1205 7278
fdfde340
JM
7279/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7280 instructions are unpredictable if these registers are used. This
7281 is the BadReg predicate in ARM's Thumb-2 documentation. */
7282#define reject_bad_reg(reg) \
7283 do \
7284 if (reg == REG_SP || reg == REG_PC) \
7285 { \
7286 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7287 return; \
7288 } \
7289 while (0)
7290
94206790
MM
7291/* If REG is R13 (the stack pointer), warn that its use is
7292 deprecated. */
7293#define warn_deprecated_sp(reg) \
7294 do \
7295 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7296 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7297 while (0)
7298
c19d1205
ZW
7299/* Functions for operand encoding. ARM, then Thumb. */
7300
d840c081 7301#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7302
9db2f6b4
RL
7303/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7304
7305 The only binary encoding difference is the Coprocessor number. Coprocessor
7306 9 is used for half-precision calculations or conversions. The format of the
7307 instruction is the same as the equivalent Coprocessor 10 instuction that
7308 exists for Single-Precision operation. */
7309
7310static void
7311do_scalar_fp16_v82_encode (void)
7312{
7313 if (inst.cond != COND_ALWAYS)
7314 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7315 " the behaviour is UNPREDICTABLE"));
7316 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7317 _(BAD_FP16));
7318
7319 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7320 mark_feature_used (&arm_ext_fp16);
7321}
7322
c19d1205
ZW
7323/* If VAL can be encoded in the immediate field of an ARM instruction,
7324 return the encoded form. Otherwise, return FAIL. */
7325
7326static unsigned int
7327encode_arm_immediate (unsigned int val)
09d92015 7328{
c19d1205
ZW
7329 unsigned int a, i;
7330
4f1d6205
L
7331 if (val <= 0xff)
7332 return val;
7333
7334 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7335 if ((a = rotate_left (val, i)) <= 0xff)
7336 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7337
7338 return FAIL;
09d92015
MM
7339}
7340
c19d1205
ZW
7341/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7342 return the encoded form. Otherwise, return FAIL. */
7343static unsigned int
7344encode_thumb32_immediate (unsigned int val)
09d92015 7345{
c19d1205 7346 unsigned int a, i;
09d92015 7347
9c3c69f2 7348 if (val <= 0xff)
c19d1205 7349 return val;
a737bd4d 7350
9c3c69f2 7351 for (i = 1; i <= 24; i++)
09d92015 7352 {
9c3c69f2
PB
7353 a = val >> i;
7354 if ((val & ~(0xff << i)) == 0)
7355 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7356 }
a737bd4d 7357
c19d1205
ZW
7358 a = val & 0xff;
7359 if (val == ((a << 16) | a))
7360 return 0x100 | a;
7361 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7362 return 0x300 | a;
09d92015 7363
c19d1205
ZW
7364 a = val & 0xff00;
7365 if (val == ((a << 16) | a))
7366 return 0x200 | (a >> 8);
a737bd4d 7367
c19d1205 7368 return FAIL;
09d92015 7369}
5287ad62 7370/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7371
7372static void
5287ad62
JB
7373encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7374{
7375 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7376 && reg > 15)
7377 {
b1cc4aeb 7378 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7379 {
7380 if (thumb_mode)
7381 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7382 fpu_vfp_ext_d32);
7383 else
7384 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7385 fpu_vfp_ext_d32);
7386 }
5287ad62 7387 else
477330fc
RM
7388 {
7389 first_error (_("D register out of range for selected VFP version"));
7390 return;
7391 }
5287ad62
JB
7392 }
7393
c19d1205 7394 switch (pos)
09d92015 7395 {
c19d1205
ZW
7396 case VFP_REG_Sd:
7397 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7398 break;
7399
7400 case VFP_REG_Sn:
7401 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7402 break;
7403
7404 case VFP_REG_Sm:
7405 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7406 break;
7407
5287ad62
JB
7408 case VFP_REG_Dd:
7409 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7410 break;
5f4273c7 7411
5287ad62
JB
7412 case VFP_REG_Dn:
7413 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7414 break;
5f4273c7 7415
5287ad62
JB
7416 case VFP_REG_Dm:
7417 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7418 break;
7419
c19d1205
ZW
7420 default:
7421 abort ();
09d92015 7422 }
09d92015
MM
7423}
7424
c19d1205 7425/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7426 if any, is handled by md_apply_fix. */
09d92015 7427static void
c19d1205 7428encode_arm_shift (int i)
09d92015 7429{
008a97ef
RL
7430 /* register-shifted register. */
7431 if (inst.operands[i].immisreg)
7432 {
7433 int index;
7434 for (index = 0; index <= i; ++index)
7435 {
7436 gas_assert (inst.operands[index].present);
7437 if (inst.operands[index].isreg && inst.operands[index].reg == REG_PC)
7438 as_warn (UNPRED_REG ("r15"));
7439 }
7440
7441 if (inst.operands[i].imm == REG_PC)
7442 as_warn (UNPRED_REG ("r15"));
7443 }
7444
c19d1205
ZW
7445 if (inst.operands[i].shift_kind == SHIFT_RRX)
7446 inst.instruction |= SHIFT_ROR << 5;
7447 else
09d92015 7448 {
c19d1205
ZW
7449 inst.instruction |= inst.operands[i].shift_kind << 5;
7450 if (inst.operands[i].immisreg)
7451 {
7452 inst.instruction |= SHIFT_BY_REG;
7453 inst.instruction |= inst.operands[i].imm << 8;
7454 }
7455 else
7456 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7457 }
c19d1205 7458}
09d92015 7459
c19d1205
ZW
7460static void
7461encode_arm_shifter_operand (int i)
7462{
7463 if (inst.operands[i].isreg)
09d92015 7464 {
c19d1205
ZW
7465 inst.instruction |= inst.operands[i].reg;
7466 encode_arm_shift (i);
09d92015 7467 }
c19d1205 7468 else
a415b1cd
JB
7469 {
7470 inst.instruction |= INST_IMMEDIATE;
7471 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7472 inst.instruction |= inst.operands[i].imm;
7473 }
09d92015
MM
7474}
7475
c19d1205 7476/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7477static void
c19d1205 7478encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7479{
2b2f5df9
NC
7480 /* PR 14260:
7481 Generate an error if the operand is not a register. */
7482 constraint (!inst.operands[i].isreg,
7483 _("Instruction does not support =N addresses"));
7484
c19d1205 7485 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7486
c19d1205 7487 if (inst.operands[i].preind)
09d92015 7488 {
c19d1205
ZW
7489 if (is_t)
7490 {
7491 inst.error = _("instruction does not accept preindexed addressing");
7492 return;
7493 }
7494 inst.instruction |= PRE_INDEX;
7495 if (inst.operands[i].writeback)
7496 inst.instruction |= WRITE_BACK;
09d92015 7497
c19d1205
ZW
7498 }
7499 else if (inst.operands[i].postind)
7500 {
9c2799c2 7501 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7502 if (is_t)
7503 inst.instruction |= WRITE_BACK;
7504 }
7505 else /* unindexed - only for coprocessor */
09d92015 7506 {
c19d1205 7507 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7508 return;
7509 }
7510
c19d1205
ZW
7511 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7512 && (((inst.instruction & 0x000f0000) >> 16)
7513 == ((inst.instruction & 0x0000f000) >> 12)))
7514 as_warn ((inst.instruction & LOAD_BIT)
7515 ? _("destination register same as write-back base")
7516 : _("source register same as write-back base"));
09d92015
MM
7517}
7518
c19d1205
ZW
7519/* inst.operands[i] was set up by parse_address. Encode it into an
7520 ARM-format mode 2 load or store instruction. If is_t is true,
7521 reject forms that cannot be used with a T instruction (i.e. not
7522 post-indexed). */
a737bd4d 7523static void
c19d1205 7524encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7525{
5be8be5d
DG
7526 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7527
c19d1205 7528 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7529
c19d1205 7530 if (inst.operands[i].immisreg)
09d92015 7531 {
5be8be5d
DG
7532 constraint ((inst.operands[i].imm == REG_PC
7533 || (is_pc && inst.operands[i].writeback)),
7534 BAD_PC_ADDRESSING);
c19d1205
ZW
7535 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7536 inst.instruction |= inst.operands[i].imm;
7537 if (!inst.operands[i].negative)
7538 inst.instruction |= INDEX_UP;
7539 if (inst.operands[i].shifted)
7540 {
7541 if (inst.operands[i].shift_kind == SHIFT_RRX)
7542 inst.instruction |= SHIFT_ROR << 5;
7543 else
7544 {
7545 inst.instruction |= inst.operands[i].shift_kind << 5;
7546 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7547 }
7548 }
09d92015 7549 }
c19d1205 7550 else /* immediate offset in inst.reloc */
09d92015 7551 {
5be8be5d
DG
7552 if (is_pc && !inst.reloc.pc_rel)
7553 {
7554 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7555
7556 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7557 cannot use PC in addressing.
7558 PC cannot be used in writeback addressing, either. */
7559 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7560 BAD_PC_ADDRESSING);
23a10334 7561
dc5ec521 7562 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7563 if (warn_on_deprecated
7564 && !is_load
7565 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7566 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7567 }
7568
c19d1205 7569 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7570 {
7571 /* Prefer + for zero encoded value. */
7572 if (!inst.operands[i].negative)
7573 inst.instruction |= INDEX_UP;
7574 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7575 }
09d92015 7576 }
09d92015
MM
7577}
7578
c19d1205
ZW
7579/* inst.operands[i] was set up by parse_address. Encode it into an
7580 ARM-format mode 3 load or store instruction. Reject forms that
7581 cannot be used with such instructions. If is_t is true, reject
7582 forms that cannot be used with a T instruction (i.e. not
7583 post-indexed). */
7584static void
7585encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7586{
c19d1205 7587 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7588 {
c19d1205
ZW
7589 inst.error = _("instruction does not accept scaled register index");
7590 return;
09d92015 7591 }
a737bd4d 7592
c19d1205 7593 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7594
c19d1205
ZW
7595 if (inst.operands[i].immisreg)
7596 {
5be8be5d 7597 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7598 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7599 BAD_PC_ADDRESSING);
eb9f3f00
JB
7600 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7601 BAD_PC_WRITEBACK);
c19d1205
ZW
7602 inst.instruction |= inst.operands[i].imm;
7603 if (!inst.operands[i].negative)
7604 inst.instruction |= INDEX_UP;
7605 }
7606 else /* immediate offset in inst.reloc */
7607 {
5be8be5d
DG
7608 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7609 && inst.operands[i].writeback),
7610 BAD_PC_WRITEBACK);
c19d1205
ZW
7611 inst.instruction |= HWOFFSET_IMM;
7612 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7613 {
7614 /* Prefer + for zero encoded value. */
7615 if (!inst.operands[i].negative)
7616 inst.instruction |= INDEX_UP;
7617
7618 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7619 }
c19d1205 7620 }
a737bd4d
NC
7621}
7622
8335d6aa
JW
7623/* Write immediate bits [7:0] to the following locations:
7624
7625 |28/24|23 19|18 16|15 4|3 0|
7626 | 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|
7627
7628 This function is used by VMOV/VMVN/VORR/VBIC. */
7629
7630static void
7631neon_write_immbits (unsigned immbits)
7632{
7633 inst.instruction |= immbits & 0xf;
7634 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7635 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7636}
7637
7638/* Invert low-order SIZE bits of XHI:XLO. */
7639
7640static void
7641neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7642{
7643 unsigned immlo = xlo ? *xlo : 0;
7644 unsigned immhi = xhi ? *xhi : 0;
7645
7646 switch (size)
7647 {
7648 case 8:
7649 immlo = (~immlo) & 0xff;
7650 break;
7651
7652 case 16:
7653 immlo = (~immlo) & 0xffff;
7654 break;
7655
7656 case 64:
7657 immhi = (~immhi) & 0xffffffff;
7658 /* fall through. */
7659
7660 case 32:
7661 immlo = (~immlo) & 0xffffffff;
7662 break;
7663
7664 default:
7665 abort ();
7666 }
7667
7668 if (xlo)
7669 *xlo = immlo;
7670
7671 if (xhi)
7672 *xhi = immhi;
7673}
7674
7675/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7676 A, B, C, D. */
09d92015 7677
c19d1205 7678static int
8335d6aa 7679neon_bits_same_in_bytes (unsigned imm)
09d92015 7680{
8335d6aa
JW
7681 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7682 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7683 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7684 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7685}
a737bd4d 7686
8335d6aa 7687/* For immediate of above form, return 0bABCD. */
09d92015 7688
8335d6aa
JW
7689static unsigned
7690neon_squash_bits (unsigned imm)
7691{
7692 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7693 | ((imm & 0x01000000) >> 21);
7694}
7695
7696/* Compress quarter-float representation to 0b...000 abcdefgh. */
7697
7698static unsigned
7699neon_qfloat_bits (unsigned imm)
7700{
7701 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7702}
7703
7704/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7705 the instruction. *OP is passed as the initial value of the op field, and
7706 may be set to a different value depending on the constant (i.e.
7707 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7708 MVN). If the immediate looks like a repeated pattern then also
7709 try smaller element sizes. */
7710
7711static int
7712neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7713 unsigned *immbits, int *op, int size,
7714 enum neon_el_type type)
7715{
7716 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7717 float. */
7718 if (type == NT_float && !float_p)
7719 return FAIL;
7720
7721 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7722 {
8335d6aa
JW
7723 if (size != 32 || *op == 1)
7724 return FAIL;
7725 *immbits = neon_qfloat_bits (immlo);
7726 return 0xf;
7727 }
7728
7729 if (size == 64)
7730 {
7731 if (neon_bits_same_in_bytes (immhi)
7732 && neon_bits_same_in_bytes (immlo))
c19d1205 7733 {
8335d6aa
JW
7734 if (*op == 1)
7735 return FAIL;
7736 *immbits = (neon_squash_bits (immhi) << 4)
7737 | neon_squash_bits (immlo);
7738 *op = 1;
7739 return 0xe;
c19d1205 7740 }
a737bd4d 7741
8335d6aa
JW
7742 if (immhi != immlo)
7743 return FAIL;
7744 }
a737bd4d 7745
8335d6aa 7746 if (size >= 32)
09d92015 7747 {
8335d6aa 7748 if (immlo == (immlo & 0x000000ff))
c19d1205 7749 {
8335d6aa
JW
7750 *immbits = immlo;
7751 return 0x0;
c19d1205 7752 }
8335d6aa 7753 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7754 {
8335d6aa
JW
7755 *immbits = immlo >> 8;
7756 return 0x2;
c19d1205 7757 }
8335d6aa
JW
7758 else if (immlo == (immlo & 0x00ff0000))
7759 {
7760 *immbits = immlo >> 16;
7761 return 0x4;
7762 }
7763 else if (immlo == (immlo & 0xff000000))
7764 {
7765 *immbits = immlo >> 24;
7766 return 0x6;
7767 }
7768 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7769 {
7770 *immbits = (immlo >> 8) & 0xff;
7771 return 0xc;
7772 }
7773 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7774 {
7775 *immbits = (immlo >> 16) & 0xff;
7776 return 0xd;
7777 }
7778
7779 if ((immlo & 0xffff) != (immlo >> 16))
7780 return FAIL;
7781 immlo &= 0xffff;
09d92015 7782 }
a737bd4d 7783
8335d6aa 7784 if (size >= 16)
4962c51a 7785 {
8335d6aa
JW
7786 if (immlo == (immlo & 0x000000ff))
7787 {
7788 *immbits = immlo;
7789 return 0x8;
7790 }
7791 else if (immlo == (immlo & 0x0000ff00))
7792 {
7793 *immbits = immlo >> 8;
7794 return 0xa;
7795 }
7796
7797 if ((immlo & 0xff) != (immlo >> 8))
7798 return FAIL;
7799 immlo &= 0xff;
4962c51a
MS
7800 }
7801
8335d6aa
JW
7802 if (immlo == (immlo & 0x000000ff))
7803 {
7804 /* Don't allow MVN with 8-bit immediate. */
7805 if (*op == 1)
7806 return FAIL;
7807 *immbits = immlo;
7808 return 0xe;
7809 }
26d97720 7810
8335d6aa 7811 return FAIL;
c19d1205 7812}
a737bd4d 7813
5fc177c8 7814#if defined BFD_HOST_64_BIT
ba592044
AM
7815/* Returns TRUE if double precision value V may be cast
7816 to single precision without loss of accuracy. */
7817
7818static bfd_boolean
5fc177c8 7819is_double_a_single (bfd_int64_t v)
ba592044 7820{
5fc177c8 7821 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7822 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7823
7824 return (exp == 0 || exp == 0x7FF
7825 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7826 && (mantissa & 0x1FFFFFFFl) == 0;
7827}
7828
3739860c 7829/* Returns a double precision value casted to single precision
ba592044
AM
7830 (ignoring the least significant bits in exponent and mantissa). */
7831
7832static int
5fc177c8 7833double_to_single (bfd_int64_t v)
ba592044
AM
7834{
7835 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7836 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7837 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7838
7839 if (exp == 0x7FF)
7840 exp = 0xFF;
7841 else
7842 {
7843 exp = exp - 1023 + 127;
7844 if (exp >= 0xFF)
7845 {
7846 /* Infinity. */
7847 exp = 0x7F;
7848 mantissa = 0;
7849 }
7850 else if (exp < 0)
7851 {
7852 /* No denormalized numbers. */
7853 exp = 0;
7854 mantissa = 0;
7855 }
7856 }
7857 mantissa >>= 29;
7858 return (sign << 31) | (exp << 23) | mantissa;
7859}
5fc177c8 7860#endif /* BFD_HOST_64_BIT */
ba592044 7861
8335d6aa
JW
7862enum lit_type
7863{
7864 CONST_THUMB,
7865 CONST_ARM,
7866 CONST_VEC
7867};
7868
ba592044
AM
7869static void do_vfp_nsyn_opcode (const char *);
7870
c19d1205
ZW
7871/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7872 Determine whether it can be performed with a move instruction; if
7873 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7874 return TRUE; if it can't, convert inst.instruction to a literal-pool
7875 load and return FALSE. If this is not a valid thing to do in the
7876 current context, set inst.error and return TRUE.
a737bd4d 7877
c19d1205
ZW
7878 inst.operands[i] describes the destination register. */
7879
c921be7d 7880static bfd_boolean
8335d6aa 7881move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7882{
53365c0d 7883 unsigned long tbit;
8335d6aa
JW
7884 bfd_boolean thumb_p = (t == CONST_THUMB);
7885 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7886
7887 if (thumb_p)
7888 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7889 else
7890 tbit = LOAD_BIT;
7891
7892 if ((inst.instruction & tbit) == 0)
09d92015 7893 {
c19d1205 7894 inst.error = _("invalid pseudo operation");
c921be7d 7895 return TRUE;
09d92015 7896 }
ba592044 7897
8335d6aa
JW
7898 if (inst.reloc.exp.X_op != O_constant
7899 && inst.reloc.exp.X_op != O_symbol
7900 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7901 {
7902 inst.error = _("constant expression expected");
c921be7d 7903 return TRUE;
09d92015 7904 }
ba592044
AM
7905
7906 if (inst.reloc.exp.X_op == O_constant
7907 || inst.reloc.exp.X_op == O_big)
8335d6aa 7908 {
5fc177c8
NC
7909#if defined BFD_HOST_64_BIT
7910 bfd_int64_t v;
7911#else
ba592044 7912 offsetT v;
5fc177c8 7913#endif
ba592044 7914 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7915 {
ba592044
AM
7916 LITTLENUM_TYPE w[X_PRECISION];
7917 LITTLENUM_TYPE * l;
7918
7919 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7920 {
ba592044
AM
7921 gen_to_words (w, X_PRECISION, E_PRECISION);
7922 l = w;
7923 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7924 }
ba592044
AM
7925 else
7926 l = generic_bignum;
3739860c 7927
5fc177c8
NC
7928#if defined BFD_HOST_64_BIT
7929 v =
7930 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7931 << LITTLENUM_NUMBER_OF_BITS)
7932 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7933 << LITTLENUM_NUMBER_OF_BITS)
7934 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7935 << LITTLENUM_NUMBER_OF_BITS)
7936 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7937#else
ba592044
AM
7938 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7939 | (l[0] & LITTLENUM_MASK);
5fc177c8 7940#endif
8335d6aa 7941 }
ba592044
AM
7942 else
7943 v = inst.reloc.exp.X_add_number;
7944
7945 if (!inst.operands[i].issingle)
8335d6aa 7946 {
12569877 7947 if (thumb_p)
8335d6aa 7948 {
2c32be70
CM
7949 /* This can be encoded only for a low register. */
7950 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7951 {
7952 /* This can be done with a mov(1) instruction. */
7953 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7954 inst.instruction |= v;
7955 return TRUE;
7956 }
12569877 7957
ff8646ee
TP
7958 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7959 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7960 {
fc289b0a
TP
7961 /* Check if on thumb2 it can be done with a mov.w, mvn or
7962 movw instruction. */
12569877
AM
7963 unsigned int newimm;
7964 bfd_boolean isNegated;
7965
7966 newimm = encode_thumb32_immediate (v);
7967 if (newimm != (unsigned int) FAIL)
7968 isNegated = FALSE;
7969 else
7970 {
582cfe03 7971 newimm = encode_thumb32_immediate (~v);
12569877
AM
7972 if (newimm != (unsigned int) FAIL)
7973 isNegated = TRUE;
7974 }
7975
fc289b0a
TP
7976 /* The number can be loaded with a mov.w or mvn
7977 instruction. */
ff8646ee
TP
7978 if (newimm != (unsigned int) FAIL
7979 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7980 {
fc289b0a 7981 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7982 | (inst.operands[i].reg << 8));
fc289b0a 7983 /* Change to MOVN. */
582cfe03 7984 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7985 inst.instruction |= (newimm & 0x800) << 15;
7986 inst.instruction |= (newimm & 0x700) << 4;
7987 inst.instruction |= (newimm & 0x0ff);
7988 return TRUE;
7989 }
fc289b0a 7990 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7991 else if ((v & ~0xFFFF) == 0
7992 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7993 {
582cfe03 7994 int imm = v & 0xFFFF;
12569877 7995
582cfe03 7996 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7997 inst.instruction |= (inst.operands[i].reg << 8);
7998 inst.instruction |= (imm & 0xf000) << 4;
7999 inst.instruction |= (imm & 0x0800) << 15;
8000 inst.instruction |= (imm & 0x0700) << 4;
8001 inst.instruction |= (imm & 0x00ff);
8002 return TRUE;
8003 }
8004 }
8335d6aa 8005 }
12569877 8006 else if (arm_p)
ba592044
AM
8007 {
8008 int value = encode_arm_immediate (v);
12569877 8009
ba592044
AM
8010 if (value != FAIL)
8011 {
8012 /* This can be done with a mov instruction. */
8013 inst.instruction &= LITERAL_MASK;
8014 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8015 inst.instruction |= value & 0xfff;
8016 return TRUE;
8017 }
8335d6aa 8018
ba592044
AM
8019 value = encode_arm_immediate (~ v);
8020 if (value != FAIL)
8021 {
8022 /* This can be done with a mvn instruction. */
8023 inst.instruction &= LITERAL_MASK;
8024 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8025 inst.instruction |= value & 0xfff;
8026 return TRUE;
8027 }
8028 }
934c2632 8029 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8030 {
ba592044
AM
8031 int op = 0;
8032 unsigned immbits = 0;
8033 unsigned immlo = inst.operands[1].imm;
8034 unsigned immhi = inst.operands[1].regisimm
8035 ? inst.operands[1].reg
8036 : inst.reloc.exp.X_unsigned
8037 ? 0
8038 : ((bfd_int64_t)((int) immlo)) >> 32;
8039 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8040 &op, 64, NT_invtype);
8041
8042 if (cmode == FAIL)
8043 {
8044 neon_invert_size (&immlo, &immhi, 64);
8045 op = !op;
8046 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8047 &op, 64, NT_invtype);
8048 }
8049
8050 if (cmode != FAIL)
8051 {
8052 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8053 | (1 << 23)
8054 | (cmode << 8)
8055 | (op << 5)
8056 | (1 << 4);
8057
8058 /* Fill other bits in vmov encoding for both thumb and arm. */
8059 if (thumb_mode)
eff0bc54 8060 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8061 else
eff0bc54 8062 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8063 neon_write_immbits (immbits);
8064 return TRUE;
8065 }
8335d6aa
JW
8066 }
8067 }
8335d6aa 8068
ba592044
AM
8069 if (t == CONST_VEC)
8070 {
8071 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8072 if (inst.operands[i].issingle
8073 && is_quarter_float (inst.operands[1].imm)
8074 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8075 {
ba592044
AM
8076 inst.operands[1].imm =
8077 neon_qfloat_bits (v);
8078 do_vfp_nsyn_opcode ("fconsts");
8079 return TRUE;
8335d6aa 8080 }
5fc177c8
NC
8081
8082 /* If our host does not support a 64-bit type then we cannot perform
8083 the following optimization. This mean that there will be a
8084 discrepancy between the output produced by an assembler built for
8085 a 32-bit-only host and the output produced from a 64-bit host, but
8086 this cannot be helped. */
8087#if defined BFD_HOST_64_BIT
ba592044
AM
8088 else if (!inst.operands[1].issingle
8089 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8090 {
ba592044
AM
8091 if (is_double_a_single (v)
8092 && is_quarter_float (double_to_single (v)))
8093 {
8094 inst.operands[1].imm =
8095 neon_qfloat_bits (double_to_single (v));
8096 do_vfp_nsyn_opcode ("fconstd");
8097 return TRUE;
8098 }
8335d6aa 8099 }
5fc177c8 8100#endif
8335d6aa
JW
8101 }
8102 }
8103
8104 if (add_to_lit_pool ((!inst.operands[i].isvec
8105 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8106 return TRUE;
8107
8108 inst.operands[1].reg = REG_PC;
8109 inst.operands[1].isreg = 1;
8110 inst.operands[1].preind = 1;
8111 inst.reloc.pc_rel = 1;
8112 inst.reloc.type = (thumb_p
8113 ? BFD_RELOC_ARM_THUMB_OFFSET
8114 : (mode_3
8115 ? BFD_RELOC_ARM_HWLITERAL
8116 : BFD_RELOC_ARM_LITERAL));
8117 return FALSE;
8118}
8119
8120/* inst.operands[i] was set up by parse_address. Encode it into an
8121 ARM-format instruction. Reject all forms which cannot be encoded
8122 into a coprocessor load/store instruction. If wb_ok is false,
8123 reject use of writeback; if unind_ok is false, reject use of
8124 unindexed addressing. If reloc_override is not 0, use it instead
8125 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8126 (in which case it is preserved). */
8127
8128static int
8129encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8130{
8131 if (!inst.operands[i].isreg)
8132 {
99b2a2dd
NC
8133 /* PR 18256 */
8134 if (! inst.operands[0].isvec)
8135 {
8136 inst.error = _("invalid co-processor operand");
8137 return FAIL;
8138 }
8335d6aa
JW
8139 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8140 return SUCCESS;
8141 }
8142
8143 inst.instruction |= inst.operands[i].reg << 16;
8144
8145 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8146
8147 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8148 {
8149 gas_assert (!inst.operands[i].writeback);
8150 if (!unind_ok)
8151 {
8152 inst.error = _("instruction does not support unindexed addressing");
8153 return FAIL;
8154 }
8155 inst.instruction |= inst.operands[i].imm;
8156 inst.instruction |= INDEX_UP;
8157 return SUCCESS;
8158 }
8159
8160 if (inst.operands[i].preind)
8161 inst.instruction |= PRE_INDEX;
8162
8163 if (inst.operands[i].writeback)
09d92015 8164 {
8335d6aa 8165 if (inst.operands[i].reg == REG_PC)
c19d1205 8166 {
8335d6aa
JW
8167 inst.error = _("pc may not be used with write-back");
8168 return FAIL;
c19d1205 8169 }
8335d6aa 8170 if (!wb_ok)
c19d1205 8171 {
8335d6aa
JW
8172 inst.error = _("instruction does not support writeback");
8173 return FAIL;
c19d1205 8174 }
8335d6aa 8175 inst.instruction |= WRITE_BACK;
09d92015
MM
8176 }
8177
8335d6aa
JW
8178 if (reloc_override)
8179 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8180 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8181 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8182 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8183 {
8335d6aa
JW
8184 if (thumb_mode)
8185 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8186 else
8187 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8188 }
8335d6aa
JW
8189
8190 /* Prefer + for zero encoded value. */
8191 if (!inst.operands[i].negative)
8192 inst.instruction |= INDEX_UP;
8193
8194 return SUCCESS;
09d92015
MM
8195}
8196
5f4273c7 8197/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8198 First some generics; their names are taken from the conventional
8199 bit positions for register arguments in ARM format instructions. */
09d92015 8200
a737bd4d 8201static void
c19d1205 8202do_noargs (void)
09d92015 8203{
c19d1205 8204}
a737bd4d 8205
c19d1205
ZW
8206static void
8207do_rd (void)
8208{
8209 inst.instruction |= inst.operands[0].reg << 12;
8210}
a737bd4d 8211
16a1fa25
TP
8212static void
8213do_rn (void)
8214{
8215 inst.instruction |= inst.operands[0].reg << 16;
8216}
8217
c19d1205
ZW
8218static void
8219do_rd_rm (void)
8220{
8221 inst.instruction |= inst.operands[0].reg << 12;
8222 inst.instruction |= inst.operands[1].reg;
8223}
09d92015 8224
9eb6c0f1
MGD
8225static void
8226do_rm_rn (void)
8227{
8228 inst.instruction |= inst.operands[0].reg;
8229 inst.instruction |= inst.operands[1].reg << 16;
8230}
8231
c19d1205
ZW
8232static void
8233do_rd_rn (void)
8234{
8235 inst.instruction |= inst.operands[0].reg << 12;
8236 inst.instruction |= inst.operands[1].reg << 16;
8237}
a737bd4d 8238
c19d1205
ZW
8239static void
8240do_rn_rd (void)
8241{
8242 inst.instruction |= inst.operands[0].reg << 16;
8243 inst.instruction |= inst.operands[1].reg << 12;
8244}
09d92015 8245
4ed7ed8d
TP
8246static void
8247do_tt (void)
8248{
8249 inst.instruction |= inst.operands[0].reg << 8;
8250 inst.instruction |= inst.operands[1].reg << 16;
8251}
8252
59d09be6
MGD
8253static bfd_boolean
8254check_obsolete (const arm_feature_set *feature, const char *msg)
8255{
8256 if (ARM_CPU_IS_ANY (cpu_variant))
8257 {
5c3696f8 8258 as_tsktsk ("%s", msg);
59d09be6
MGD
8259 return TRUE;
8260 }
8261 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8262 {
8263 as_bad ("%s", msg);
8264 return TRUE;
8265 }
8266
8267 return FALSE;
8268}
8269
c19d1205
ZW
8270static void
8271do_rd_rm_rn (void)
8272{
9a64e435 8273 unsigned Rn = inst.operands[2].reg;
708587a4 8274 /* Enforce restrictions on SWP instruction. */
9a64e435 8275 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8276 {
8277 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8278 _("Rn must not overlap other operands"));
8279
59d09be6
MGD
8280 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8281 */
8282 if (!check_obsolete (&arm_ext_v8,
8283 _("swp{b} use is obsoleted for ARMv8 and later"))
8284 && warn_on_deprecated
8285 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8286 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8287 }
59d09be6 8288
c19d1205
ZW
8289 inst.instruction |= inst.operands[0].reg << 12;
8290 inst.instruction |= inst.operands[1].reg;
9a64e435 8291 inst.instruction |= Rn << 16;
c19d1205 8292}
09d92015 8293
c19d1205
ZW
8294static void
8295do_rd_rn_rm (void)
8296{
8297 inst.instruction |= inst.operands[0].reg << 12;
8298 inst.instruction |= inst.operands[1].reg << 16;
8299 inst.instruction |= inst.operands[2].reg;
8300}
a737bd4d 8301
c19d1205
ZW
8302static void
8303do_rm_rd_rn (void)
8304{
5be8be5d
DG
8305 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8306 constraint (((inst.reloc.exp.X_op != O_constant
8307 && inst.reloc.exp.X_op != O_illegal)
8308 || inst.reloc.exp.X_add_number != 0),
8309 BAD_ADDR_MODE);
c19d1205
ZW
8310 inst.instruction |= inst.operands[0].reg;
8311 inst.instruction |= inst.operands[1].reg << 12;
8312 inst.instruction |= inst.operands[2].reg << 16;
8313}
09d92015 8314
c19d1205
ZW
8315static void
8316do_imm0 (void)
8317{
8318 inst.instruction |= inst.operands[0].imm;
8319}
09d92015 8320
c19d1205
ZW
8321static void
8322do_rd_cpaddr (void)
8323{
8324 inst.instruction |= inst.operands[0].reg << 12;
8325 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8326}
a737bd4d 8327
c19d1205
ZW
8328/* ARM instructions, in alphabetical order by function name (except
8329 that wrapper functions appear immediately after the function they
8330 wrap). */
09d92015 8331
c19d1205
ZW
8332/* This is a pseudo-op of the form "adr rd, label" to be converted
8333 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8334
8335static void
c19d1205 8336do_adr (void)
09d92015 8337{
c19d1205 8338 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8339
c19d1205
ZW
8340 /* Frag hacking will turn this into a sub instruction if the offset turns
8341 out to be negative. */
8342 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8343 inst.reloc.pc_rel = 1;
2fc8bdac 8344 inst.reloc.exp.X_add_number -= 8;
c19d1205 8345}
b99bd4ef 8346
c19d1205
ZW
8347/* This is a pseudo-op of the form "adrl rd, label" to be converted
8348 into a relative address of the form:
8349 add rd, pc, #low(label-.-8)"
8350 add rd, rd, #high(label-.-8)" */
b99bd4ef 8351
c19d1205
ZW
8352static void
8353do_adrl (void)
8354{
8355 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8356
c19d1205
ZW
8357 /* Frag hacking will turn this into a sub instruction if the offset turns
8358 out to be negative. */
8359 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8360 inst.reloc.pc_rel = 1;
8361 inst.size = INSN_SIZE * 2;
2fc8bdac 8362 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8363}
8364
b99bd4ef 8365static void
c19d1205 8366do_arit (void)
b99bd4ef 8367{
a9f02af8
MG
8368 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8369 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8370 THUMB1_RELOC_ONLY);
c19d1205
ZW
8371 if (!inst.operands[1].present)
8372 inst.operands[1].reg = inst.operands[0].reg;
8373 inst.instruction |= inst.operands[0].reg << 12;
8374 inst.instruction |= inst.operands[1].reg << 16;
8375 encode_arm_shifter_operand (2);
8376}
b99bd4ef 8377
62b3e311
PB
8378static void
8379do_barrier (void)
8380{
8381 if (inst.operands[0].present)
ccb84d65 8382 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8383 else
8384 inst.instruction |= 0xf;
8385}
8386
c19d1205
ZW
8387static void
8388do_bfc (void)
8389{
8390 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8391 constraint (msb > 32, _("bit-field extends past end of register"));
8392 /* The instruction encoding stores the LSB and MSB,
8393 not the LSB and width. */
8394 inst.instruction |= inst.operands[0].reg << 12;
8395 inst.instruction |= inst.operands[1].imm << 7;
8396 inst.instruction |= (msb - 1) << 16;
8397}
b99bd4ef 8398
c19d1205
ZW
8399static void
8400do_bfi (void)
8401{
8402 unsigned int msb;
b99bd4ef 8403
c19d1205
ZW
8404 /* #0 in second position is alternative syntax for bfc, which is
8405 the same instruction but with REG_PC in the Rm field. */
8406 if (!inst.operands[1].isreg)
8407 inst.operands[1].reg = REG_PC;
b99bd4ef 8408
c19d1205
ZW
8409 msb = inst.operands[2].imm + inst.operands[3].imm;
8410 constraint (msb > 32, _("bit-field extends past end of register"));
8411 /* The instruction encoding stores the LSB and MSB,
8412 not the LSB and width. */
8413 inst.instruction |= inst.operands[0].reg << 12;
8414 inst.instruction |= inst.operands[1].reg;
8415 inst.instruction |= inst.operands[2].imm << 7;
8416 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8417}
8418
b99bd4ef 8419static void
c19d1205 8420do_bfx (void)
b99bd4ef 8421{
c19d1205
ZW
8422 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8423 _("bit-field extends past end of register"));
8424 inst.instruction |= inst.operands[0].reg << 12;
8425 inst.instruction |= inst.operands[1].reg;
8426 inst.instruction |= inst.operands[2].imm << 7;
8427 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8428}
09d92015 8429
c19d1205
ZW
8430/* ARM V5 breakpoint instruction (argument parse)
8431 BKPT <16 bit unsigned immediate>
8432 Instruction is not conditional.
8433 The bit pattern given in insns[] has the COND_ALWAYS condition,
8434 and it is an error if the caller tried to override that. */
b99bd4ef 8435
c19d1205
ZW
8436static void
8437do_bkpt (void)
8438{
8439 /* Top 12 of 16 bits to bits 19:8. */
8440 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8441
c19d1205
ZW
8442 /* Bottom 4 of 16 bits to bits 3:0. */
8443 inst.instruction |= inst.operands[0].imm & 0xf;
8444}
09d92015 8445
c19d1205
ZW
8446static void
8447encode_branch (int default_reloc)
8448{
8449 if (inst.operands[0].hasreloc)
8450 {
0855e32b
NS
8451 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8452 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8453 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8454 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8455 ? BFD_RELOC_ARM_PLT32
8456 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8457 }
b99bd4ef 8458 else
9ae92b05 8459 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8460 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8461}
8462
b99bd4ef 8463static void
c19d1205 8464do_branch (void)
b99bd4ef 8465{
39b41c9c
PB
8466#ifdef OBJ_ELF
8467 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8468 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8469 else
8470#endif
8471 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8472}
8473
8474static void
8475do_bl (void)
8476{
8477#ifdef OBJ_ELF
8478 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8479 {
8480 if (inst.cond == COND_ALWAYS)
8481 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8482 else
8483 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8484 }
8485 else
8486#endif
8487 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8488}
b99bd4ef 8489
c19d1205
ZW
8490/* ARM V5 branch-link-exchange instruction (argument parse)
8491 BLX <target_addr> ie BLX(1)
8492 BLX{<condition>} <Rm> ie BLX(2)
8493 Unfortunately, there are two different opcodes for this mnemonic.
8494 So, the insns[].value is not used, and the code here zaps values
8495 into inst.instruction.
8496 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8497
c19d1205
ZW
8498static void
8499do_blx (void)
8500{
8501 if (inst.operands[0].isreg)
b99bd4ef 8502 {
c19d1205
ZW
8503 /* Arg is a register; the opcode provided by insns[] is correct.
8504 It is not illegal to do "blx pc", just useless. */
8505 if (inst.operands[0].reg == REG_PC)
8506 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8507
c19d1205
ZW
8508 inst.instruction |= inst.operands[0].reg;
8509 }
8510 else
b99bd4ef 8511 {
c19d1205 8512 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8513 conditionally, and the opcode must be adjusted.
8514 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8515 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8516 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8517 inst.instruction = 0xfa000000;
267bf995 8518 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8519 }
c19d1205
ZW
8520}
8521
8522static void
8523do_bx (void)
8524{
845b51d6
PB
8525 bfd_boolean want_reloc;
8526
c19d1205
ZW
8527 if (inst.operands[0].reg == REG_PC)
8528 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8529
c19d1205 8530 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8531 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8532 it is for ARMv4t or earlier. */
8533 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8534 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8535 want_reloc = TRUE;
8536
5ad34203 8537#ifdef OBJ_ELF
845b51d6 8538 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8539#endif
584206db 8540 want_reloc = FALSE;
845b51d6
PB
8541
8542 if (want_reloc)
8543 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8544}
8545
c19d1205
ZW
8546
8547/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8548
8549static void
c19d1205 8550do_bxj (void)
a737bd4d 8551{
c19d1205
ZW
8552 if (inst.operands[0].reg == REG_PC)
8553 as_tsktsk (_("use of r15 in bxj is not really useful"));
8554
8555 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8556}
8557
c19d1205
ZW
8558/* Co-processor data operation:
8559 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8560 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8561static void
8562do_cdp (void)
8563{
8564 inst.instruction |= inst.operands[0].reg << 8;
8565 inst.instruction |= inst.operands[1].imm << 20;
8566 inst.instruction |= inst.operands[2].reg << 12;
8567 inst.instruction |= inst.operands[3].reg << 16;
8568 inst.instruction |= inst.operands[4].reg;
8569 inst.instruction |= inst.operands[5].imm << 5;
8570}
a737bd4d
NC
8571
8572static void
c19d1205 8573do_cmp (void)
a737bd4d 8574{
c19d1205
ZW
8575 inst.instruction |= inst.operands[0].reg << 16;
8576 encode_arm_shifter_operand (1);
a737bd4d
NC
8577}
8578
c19d1205
ZW
8579/* Transfer between coprocessor and ARM registers.
8580 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8581 MRC2
8582 MCR{cond}
8583 MCR2
8584
8585 No special properties. */
09d92015 8586
dcbd0d71
MGD
8587struct deprecated_coproc_regs_s
8588{
8589 unsigned cp;
8590 int opc1;
8591 unsigned crn;
8592 unsigned crm;
8593 int opc2;
8594 arm_feature_set deprecated;
8595 arm_feature_set obsoleted;
8596 const char *dep_msg;
8597 const char *obs_msg;
8598};
8599
8600#define DEPR_ACCESS_V8 \
8601 N_("This coprocessor register access is deprecated in ARMv8")
8602
8603/* Table of all deprecated coprocessor registers. */
8604static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8605{
8606 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8607 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8608 DEPR_ACCESS_V8, NULL},
8609 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8610 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8611 DEPR_ACCESS_V8, NULL},
8612 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8613 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8614 DEPR_ACCESS_V8, NULL},
8615 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8616 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8617 DEPR_ACCESS_V8, NULL},
8618 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8619 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8620 DEPR_ACCESS_V8, NULL},
8621};
8622
8623#undef DEPR_ACCESS_V8
8624
8625static const size_t deprecated_coproc_reg_count =
8626 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8627
09d92015 8628static void
c19d1205 8629do_co_reg (void)
09d92015 8630{
fdfde340 8631 unsigned Rd;
dcbd0d71 8632 size_t i;
fdfde340
JM
8633
8634 Rd = inst.operands[2].reg;
8635 if (thumb_mode)
8636 {
8637 if (inst.instruction == 0xee000010
8638 || inst.instruction == 0xfe000010)
8639 /* MCR, MCR2 */
8640 reject_bad_reg (Rd);
8641 else
8642 /* MRC, MRC2 */
8643 constraint (Rd == REG_SP, BAD_SP);
8644 }
8645 else
8646 {
8647 /* MCR */
8648 if (inst.instruction == 0xe000010)
8649 constraint (Rd == REG_PC, BAD_PC);
8650 }
8651
dcbd0d71
MGD
8652 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8653 {
8654 const struct deprecated_coproc_regs_s *r =
8655 deprecated_coproc_regs + i;
8656
8657 if (inst.operands[0].reg == r->cp
8658 && inst.operands[1].imm == r->opc1
8659 && inst.operands[3].reg == r->crn
8660 && inst.operands[4].reg == r->crm
8661 && inst.operands[5].imm == r->opc2)
8662 {
b10bf8c5 8663 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8664 && warn_on_deprecated
dcbd0d71 8665 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8666 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8667 }
8668 }
fdfde340 8669
c19d1205
ZW
8670 inst.instruction |= inst.operands[0].reg << 8;
8671 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8672 inst.instruction |= Rd << 12;
c19d1205
ZW
8673 inst.instruction |= inst.operands[3].reg << 16;
8674 inst.instruction |= inst.operands[4].reg;
8675 inst.instruction |= inst.operands[5].imm << 5;
8676}
09d92015 8677
c19d1205
ZW
8678/* Transfer between coprocessor register and pair of ARM registers.
8679 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8680 MCRR2
8681 MRRC{cond}
8682 MRRC2
b99bd4ef 8683
c19d1205 8684 Two XScale instructions are special cases of these:
09d92015 8685
c19d1205
ZW
8686 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8687 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8688
5f4273c7 8689 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8690
c19d1205
ZW
8691static void
8692do_co_reg2c (void)
8693{
fdfde340
JM
8694 unsigned Rd, Rn;
8695
8696 Rd = inst.operands[2].reg;
8697 Rn = inst.operands[3].reg;
8698
8699 if (thumb_mode)
8700 {
8701 reject_bad_reg (Rd);
8702 reject_bad_reg (Rn);
8703 }
8704 else
8705 {
8706 constraint (Rd == REG_PC, BAD_PC);
8707 constraint (Rn == REG_PC, BAD_PC);
8708 }
8709
873f10f0
TC
8710 /* Only check the MRRC{2} variants. */
8711 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8712 {
8713 /* If Rd == Rn, error that the operation is
8714 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8715 constraint (Rd == Rn, BAD_OVERLAP);
8716 }
8717
c19d1205
ZW
8718 inst.instruction |= inst.operands[0].reg << 8;
8719 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8720 inst.instruction |= Rd << 12;
8721 inst.instruction |= Rn << 16;
c19d1205 8722 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8723}
8724
c19d1205
ZW
8725static void
8726do_cpsi (void)
8727{
8728 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8729 if (inst.operands[1].present)
8730 {
8731 inst.instruction |= CPSI_MMOD;
8732 inst.instruction |= inst.operands[1].imm;
8733 }
c19d1205 8734}
b99bd4ef 8735
62b3e311
PB
8736static void
8737do_dbg (void)
8738{
8739 inst.instruction |= inst.operands[0].imm;
8740}
8741
eea54501
MGD
8742static void
8743do_div (void)
8744{
8745 unsigned Rd, Rn, Rm;
8746
8747 Rd = inst.operands[0].reg;
8748 Rn = (inst.operands[1].present
8749 ? inst.operands[1].reg : Rd);
8750 Rm = inst.operands[2].reg;
8751
8752 constraint ((Rd == REG_PC), BAD_PC);
8753 constraint ((Rn == REG_PC), BAD_PC);
8754 constraint ((Rm == REG_PC), BAD_PC);
8755
8756 inst.instruction |= Rd << 16;
8757 inst.instruction |= Rn << 0;
8758 inst.instruction |= Rm << 8;
8759}
8760
b99bd4ef 8761static void
c19d1205 8762do_it (void)
b99bd4ef 8763{
c19d1205 8764 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8765 process it to do the validation as if in
8766 thumb mode, just in case the code gets
8767 assembled for thumb using the unified syntax. */
8768
c19d1205 8769 inst.size = 0;
e07e6e58
NC
8770 if (unified_syntax)
8771 {
8772 set_it_insn_type (IT_INSN);
8773 now_it.mask = (inst.instruction & 0xf) | 0x10;
8774 now_it.cc = inst.operands[0].imm;
8775 }
09d92015 8776}
b99bd4ef 8777
6530b175
NC
8778/* If there is only one register in the register list,
8779 then return its register number. Otherwise return -1. */
8780static int
8781only_one_reg_in_list (int range)
8782{
8783 int i = ffs (range) - 1;
8784 return (i > 15 || range != (1 << i)) ? -1 : i;
8785}
8786
09d92015 8787static void
6530b175 8788encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8789{
c19d1205
ZW
8790 int base_reg = inst.operands[0].reg;
8791 int range = inst.operands[1].imm;
6530b175 8792 int one_reg;
ea6ef066 8793
c19d1205
ZW
8794 inst.instruction |= base_reg << 16;
8795 inst.instruction |= range;
ea6ef066 8796
c19d1205
ZW
8797 if (inst.operands[1].writeback)
8798 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8799
c19d1205 8800 if (inst.operands[0].writeback)
ea6ef066 8801 {
c19d1205
ZW
8802 inst.instruction |= WRITE_BACK;
8803 /* Check for unpredictable uses of writeback. */
8804 if (inst.instruction & LOAD_BIT)
09d92015 8805 {
c19d1205
ZW
8806 /* Not allowed in LDM type 2. */
8807 if ((inst.instruction & LDM_TYPE_2_OR_3)
8808 && ((range & (1 << REG_PC)) == 0))
8809 as_warn (_("writeback of base register is UNPREDICTABLE"));
8810 /* Only allowed if base reg not in list for other types. */
8811 else if (range & (1 << base_reg))
8812 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8813 }
8814 else /* STM. */
8815 {
8816 /* Not allowed for type 2. */
8817 if (inst.instruction & LDM_TYPE_2_OR_3)
8818 as_warn (_("writeback of base register is UNPREDICTABLE"));
8819 /* Only allowed if base reg not in list, or first in list. */
8820 else if ((range & (1 << base_reg))
8821 && (range & ((1 << base_reg) - 1)))
8822 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8823 }
ea6ef066 8824 }
6530b175
NC
8825
8826 /* If PUSH/POP has only one register, then use the A2 encoding. */
8827 one_reg = only_one_reg_in_list (range);
8828 if (from_push_pop_mnem && one_reg >= 0)
8829 {
8830 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8831
8832 inst.instruction &= A_COND_MASK;
8833 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8834 inst.instruction |= one_reg << 12;
8835 }
8836}
8837
8838static void
8839do_ldmstm (void)
8840{
8841 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8842}
8843
c19d1205
ZW
8844/* ARMv5TE load-consecutive (argument parse)
8845 Mode is like LDRH.
8846
8847 LDRccD R, mode
8848 STRccD R, mode. */
8849
a737bd4d 8850static void
c19d1205 8851do_ldrd (void)
a737bd4d 8852{
c19d1205 8853 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8854 _("first transfer register must be even"));
c19d1205
ZW
8855 constraint (inst.operands[1].present
8856 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8857 _("can only transfer two consecutive registers"));
c19d1205
ZW
8858 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8859 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8860
c19d1205
ZW
8861 if (!inst.operands[1].present)
8862 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8863
c56791bb
RE
8864 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8865 register and the first register written; we have to diagnose
8866 overlap between the base and the second register written here. */
ea6ef066 8867
c56791bb
RE
8868 if (inst.operands[2].reg == inst.operands[1].reg
8869 && (inst.operands[2].writeback || inst.operands[2].postind))
8870 as_warn (_("base register written back, and overlaps "
8871 "second transfer register"));
b05fe5cf 8872
c56791bb
RE
8873 if (!(inst.instruction & V4_STR_BIT))
8874 {
c19d1205 8875 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8876 destination (even if not write-back). */
8877 if (inst.operands[2].immisreg
8878 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8879 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8880 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8881 }
c19d1205
ZW
8882 inst.instruction |= inst.operands[0].reg << 12;
8883 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8884}
8885
8886static void
c19d1205 8887do_ldrex (void)
b05fe5cf 8888{
c19d1205
ZW
8889 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8890 || inst.operands[1].postind || inst.operands[1].writeback
8891 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8892 || inst.operands[1].negative
8893 /* This can arise if the programmer has written
8894 strex rN, rM, foo
8895 or if they have mistakenly used a register name as the last
8896 operand, eg:
8897 strex rN, rM, rX
8898 It is very difficult to distinguish between these two cases
8899 because "rX" might actually be a label. ie the register
8900 name has been occluded by a symbol of the same name. So we
8901 just generate a general 'bad addressing mode' type error
8902 message and leave it up to the programmer to discover the
8903 true cause and fix their mistake. */
8904 || (inst.operands[1].reg == REG_PC),
8905 BAD_ADDR_MODE);
b05fe5cf 8906
c19d1205
ZW
8907 constraint (inst.reloc.exp.X_op != O_constant
8908 || inst.reloc.exp.X_add_number != 0,
8909 _("offset must be zero in ARM encoding"));
b05fe5cf 8910
5be8be5d
DG
8911 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8912
c19d1205
ZW
8913 inst.instruction |= inst.operands[0].reg << 12;
8914 inst.instruction |= inst.operands[1].reg << 16;
8915 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8916}
8917
8918static void
c19d1205 8919do_ldrexd (void)
b05fe5cf 8920{
c19d1205
ZW
8921 constraint (inst.operands[0].reg % 2 != 0,
8922 _("even register required"));
8923 constraint (inst.operands[1].present
8924 && inst.operands[1].reg != inst.operands[0].reg + 1,
8925 _("can only load two consecutive registers"));
8926 /* If op 1 were present and equal to PC, this function wouldn't
8927 have been called in the first place. */
8928 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8929
c19d1205
ZW
8930 inst.instruction |= inst.operands[0].reg << 12;
8931 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8932}
8933
1be5fd2e
NC
8934/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8935 which is not a multiple of four is UNPREDICTABLE. */
8936static void
8937check_ldr_r15_aligned (void)
8938{
8939 constraint (!(inst.operands[1].immisreg)
8940 && (inst.operands[0].reg == REG_PC
8941 && inst.operands[1].reg == REG_PC
8942 && (inst.reloc.exp.X_add_number & 0x3)),
8943 _("ldr to register 15 must be 4-byte alligned"));
8944}
8945
b05fe5cf 8946static void
c19d1205 8947do_ldst (void)
b05fe5cf 8948{
c19d1205
ZW
8949 inst.instruction |= inst.operands[0].reg << 12;
8950 if (!inst.operands[1].isreg)
8335d6aa 8951 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8952 return;
c19d1205 8953 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8954 check_ldr_r15_aligned ();
b05fe5cf
ZW
8955}
8956
8957static void
c19d1205 8958do_ldstt (void)
b05fe5cf 8959{
c19d1205
ZW
8960 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8961 reject [Rn,...]. */
8962 if (inst.operands[1].preind)
b05fe5cf 8963 {
bd3ba5d1
NC
8964 constraint (inst.reloc.exp.X_op != O_constant
8965 || inst.reloc.exp.X_add_number != 0,
c19d1205 8966 _("this instruction requires a post-indexed address"));
b05fe5cf 8967
c19d1205
ZW
8968 inst.operands[1].preind = 0;
8969 inst.operands[1].postind = 1;
8970 inst.operands[1].writeback = 1;
b05fe5cf 8971 }
c19d1205
ZW
8972 inst.instruction |= inst.operands[0].reg << 12;
8973 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8974}
b05fe5cf 8975
c19d1205 8976/* Halfword and signed-byte load/store operations. */
b05fe5cf 8977
c19d1205
ZW
8978static void
8979do_ldstv4 (void)
8980{
ff4a8d2b 8981 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8982 inst.instruction |= inst.operands[0].reg << 12;
8983 if (!inst.operands[1].isreg)
8335d6aa 8984 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8985 return;
c19d1205 8986 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8987}
8988
8989static void
c19d1205 8990do_ldsttv4 (void)
b05fe5cf 8991{
c19d1205
ZW
8992 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8993 reject [Rn,...]. */
8994 if (inst.operands[1].preind)
b05fe5cf 8995 {
bd3ba5d1
NC
8996 constraint (inst.reloc.exp.X_op != O_constant
8997 || inst.reloc.exp.X_add_number != 0,
c19d1205 8998 _("this instruction requires a post-indexed address"));
b05fe5cf 8999
c19d1205
ZW
9000 inst.operands[1].preind = 0;
9001 inst.operands[1].postind = 1;
9002 inst.operands[1].writeback = 1;
b05fe5cf 9003 }
c19d1205
ZW
9004 inst.instruction |= inst.operands[0].reg << 12;
9005 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9006}
b05fe5cf 9007
c19d1205
ZW
9008/* Co-processor register load/store.
9009 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9010static void
9011do_lstc (void)
9012{
9013 inst.instruction |= inst.operands[0].reg << 8;
9014 inst.instruction |= inst.operands[1].reg << 12;
9015 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9016}
9017
b05fe5cf 9018static void
c19d1205 9019do_mlas (void)
b05fe5cf 9020{
8fb9d7b9 9021 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9022 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9023 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9024 && !(inst.instruction & 0x00400000))
8fb9d7b9 9025 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9026
c19d1205
ZW
9027 inst.instruction |= inst.operands[0].reg << 16;
9028 inst.instruction |= inst.operands[1].reg;
9029 inst.instruction |= inst.operands[2].reg << 8;
9030 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9031}
b05fe5cf 9032
c19d1205
ZW
9033static void
9034do_mov (void)
9035{
a9f02af8
MG
9036 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9037 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9038 THUMB1_RELOC_ONLY);
c19d1205
ZW
9039 inst.instruction |= inst.operands[0].reg << 12;
9040 encode_arm_shifter_operand (1);
9041}
b05fe5cf 9042
c19d1205
ZW
9043/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9044static void
9045do_mov16 (void)
9046{
b6895b4f
PB
9047 bfd_vma imm;
9048 bfd_boolean top;
9049
9050 top = (inst.instruction & 0x00400000) != 0;
9051 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
9052 _(":lower16: not allowed this instruction"));
9053 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
9054 _(":upper16: not allowed instruction"));
c19d1205 9055 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9056 if (inst.reloc.type == BFD_RELOC_UNUSED)
9057 {
9058 imm = inst.reloc.exp.X_add_number;
9059 /* The value is in two pieces: 0:11, 16:19. */
9060 inst.instruction |= (imm & 0x00000fff);
9061 inst.instruction |= (imm & 0x0000f000) << 4;
9062 }
b05fe5cf 9063}
b99bd4ef 9064
037e8744
JB
9065static int
9066do_vfp_nsyn_mrs (void)
9067{
9068 if (inst.operands[0].isvec)
9069 {
9070 if (inst.operands[1].reg != 1)
477330fc 9071 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9072 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9073 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9074 do_vfp_nsyn_opcode ("fmstat");
9075 }
9076 else if (inst.operands[1].isvec)
9077 do_vfp_nsyn_opcode ("fmrx");
9078 else
9079 return FAIL;
5f4273c7 9080
037e8744
JB
9081 return SUCCESS;
9082}
9083
9084static int
9085do_vfp_nsyn_msr (void)
9086{
9087 if (inst.operands[0].isvec)
9088 do_vfp_nsyn_opcode ("fmxr");
9089 else
9090 return FAIL;
9091
9092 return SUCCESS;
9093}
9094
f7c21dc7
NC
9095static void
9096do_vmrs (void)
9097{
9098 unsigned Rt = inst.operands[0].reg;
fa94de6b 9099
16d02dc9 9100 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9101 {
9102 inst.error = BAD_SP;
9103 return;
9104 }
9105
9106 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9107 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9108 {
9109 inst.error = BAD_PC;
9110 return;
9111 }
9112
16d02dc9
JB
9113 /* If we get through parsing the register name, we just insert the number
9114 generated into the instruction without further validation. */
9115 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9116 inst.instruction |= (Rt << 12);
9117}
9118
9119static void
9120do_vmsr (void)
9121{
9122 unsigned Rt = inst.operands[1].reg;
fa94de6b 9123
f7c21dc7
NC
9124 if (thumb_mode)
9125 reject_bad_reg (Rt);
9126 else if (Rt == REG_PC)
9127 {
9128 inst.error = BAD_PC;
9129 return;
9130 }
9131
16d02dc9
JB
9132 /* If we get through parsing the register name, we just insert the number
9133 generated into the instruction without further validation. */
9134 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9135 inst.instruction |= (Rt << 12);
9136}
9137
b99bd4ef 9138static void
c19d1205 9139do_mrs (void)
b99bd4ef 9140{
90ec0d68
MGD
9141 unsigned br;
9142
037e8744
JB
9143 if (do_vfp_nsyn_mrs () == SUCCESS)
9144 return;
9145
ff4a8d2b 9146 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9147 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9148
9149 if (inst.operands[1].isreg)
9150 {
9151 br = inst.operands[1].reg;
9152 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9153 as_bad (_("bad register for mrs"));
9154 }
9155 else
9156 {
9157 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9158 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9159 != (PSR_c|PSR_f),
d2cd1205 9160 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9161 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9162 }
9163
9164 inst.instruction |= br;
c19d1205 9165}
b99bd4ef 9166
c19d1205
ZW
9167/* Two possible forms:
9168 "{C|S}PSR_<field>, Rm",
9169 "{C|S}PSR_f, #expression". */
b99bd4ef 9170
c19d1205
ZW
9171static void
9172do_msr (void)
9173{
037e8744
JB
9174 if (do_vfp_nsyn_msr () == SUCCESS)
9175 return;
9176
c19d1205
ZW
9177 inst.instruction |= inst.operands[0].imm;
9178 if (inst.operands[1].isreg)
9179 inst.instruction |= inst.operands[1].reg;
9180 else
b99bd4ef 9181 {
c19d1205
ZW
9182 inst.instruction |= INST_IMMEDIATE;
9183 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9184 inst.reloc.pc_rel = 0;
b99bd4ef 9185 }
b99bd4ef
NC
9186}
9187
c19d1205
ZW
9188static void
9189do_mul (void)
a737bd4d 9190{
ff4a8d2b
NC
9191 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9192
c19d1205
ZW
9193 if (!inst.operands[2].present)
9194 inst.operands[2].reg = inst.operands[0].reg;
9195 inst.instruction |= inst.operands[0].reg << 16;
9196 inst.instruction |= inst.operands[1].reg;
9197 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9198
8fb9d7b9
MS
9199 if (inst.operands[0].reg == inst.operands[1].reg
9200 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9201 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9202}
9203
c19d1205
ZW
9204/* Long Multiply Parser
9205 UMULL RdLo, RdHi, Rm, Rs
9206 SMULL RdLo, RdHi, Rm, Rs
9207 UMLAL RdLo, RdHi, Rm, Rs
9208 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9209
9210static void
c19d1205 9211do_mull (void)
b99bd4ef 9212{
c19d1205
ZW
9213 inst.instruction |= inst.operands[0].reg << 12;
9214 inst.instruction |= inst.operands[1].reg << 16;
9215 inst.instruction |= inst.operands[2].reg;
9216 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9217
682b27ad
PB
9218 /* rdhi and rdlo must be different. */
9219 if (inst.operands[0].reg == inst.operands[1].reg)
9220 as_tsktsk (_("rdhi and rdlo must be different"));
9221
9222 /* rdhi, rdlo and rm must all be different before armv6. */
9223 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9224 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9225 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9226 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9227}
b99bd4ef 9228
c19d1205
ZW
9229static void
9230do_nop (void)
9231{
e7495e45
NS
9232 if (inst.operands[0].present
9233 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9234 {
9235 /* Architectural NOP hints are CPSR sets with no bits selected. */
9236 inst.instruction &= 0xf0000000;
e7495e45
NS
9237 inst.instruction |= 0x0320f000;
9238 if (inst.operands[0].present)
9239 inst.instruction |= inst.operands[0].imm;
c19d1205 9240 }
b99bd4ef
NC
9241}
9242
c19d1205
ZW
9243/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9244 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9245 Condition defaults to COND_ALWAYS.
9246 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9247
9248static void
c19d1205 9249do_pkhbt (void)
b99bd4ef 9250{
c19d1205
ZW
9251 inst.instruction |= inst.operands[0].reg << 12;
9252 inst.instruction |= inst.operands[1].reg << 16;
9253 inst.instruction |= inst.operands[2].reg;
9254 if (inst.operands[3].present)
9255 encode_arm_shift (3);
9256}
b99bd4ef 9257
c19d1205 9258/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9259
c19d1205
ZW
9260static void
9261do_pkhtb (void)
9262{
9263 if (!inst.operands[3].present)
b99bd4ef 9264 {
c19d1205
ZW
9265 /* If the shift specifier is omitted, turn the instruction
9266 into pkhbt rd, rm, rn. */
9267 inst.instruction &= 0xfff00010;
9268 inst.instruction |= inst.operands[0].reg << 12;
9269 inst.instruction |= inst.operands[1].reg;
9270 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9271 }
9272 else
9273 {
c19d1205
ZW
9274 inst.instruction |= inst.operands[0].reg << 12;
9275 inst.instruction |= inst.operands[1].reg << 16;
9276 inst.instruction |= inst.operands[2].reg;
9277 encode_arm_shift (3);
b99bd4ef
NC
9278 }
9279}
9280
c19d1205 9281/* ARMv5TE: Preload-Cache
60e5ef9f 9282 MP Extensions: Preload for write
c19d1205 9283
60e5ef9f 9284 PLD(W) <addr_mode>
c19d1205
ZW
9285
9286 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9287
9288static void
c19d1205 9289do_pld (void)
b99bd4ef 9290{
c19d1205
ZW
9291 constraint (!inst.operands[0].isreg,
9292 _("'[' expected after PLD mnemonic"));
9293 constraint (inst.operands[0].postind,
9294 _("post-indexed expression used in preload instruction"));
9295 constraint (inst.operands[0].writeback,
9296 _("writeback used in preload instruction"));
9297 constraint (!inst.operands[0].preind,
9298 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9299 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9300}
b99bd4ef 9301
62b3e311
PB
9302/* ARMv7: PLI <addr_mode> */
9303static void
9304do_pli (void)
9305{
9306 constraint (!inst.operands[0].isreg,
9307 _("'[' expected after PLI mnemonic"));
9308 constraint (inst.operands[0].postind,
9309 _("post-indexed expression used in preload instruction"));
9310 constraint (inst.operands[0].writeback,
9311 _("writeback used in preload instruction"));
9312 constraint (!inst.operands[0].preind,
9313 _("unindexed addressing used in preload instruction"));
9314 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9315 inst.instruction &= ~PRE_INDEX;
9316}
9317
c19d1205
ZW
9318static void
9319do_push_pop (void)
9320{
5e0d7f77
MP
9321 constraint (inst.operands[0].writeback,
9322 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9323 inst.operands[1] = inst.operands[0];
9324 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9325 inst.operands[0].isreg = 1;
9326 inst.operands[0].writeback = 1;
9327 inst.operands[0].reg = REG_SP;
6530b175 9328 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9329}
b99bd4ef 9330
c19d1205
ZW
9331/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9332 word at the specified address and the following word
9333 respectively.
9334 Unconditionally executed.
9335 Error if Rn is R15. */
b99bd4ef 9336
c19d1205
ZW
9337static void
9338do_rfe (void)
9339{
9340 inst.instruction |= inst.operands[0].reg << 16;
9341 if (inst.operands[0].writeback)
9342 inst.instruction |= WRITE_BACK;
9343}
b99bd4ef 9344
c19d1205 9345/* ARM V6 ssat (argument parse). */
b99bd4ef 9346
c19d1205
ZW
9347static void
9348do_ssat (void)
9349{
9350 inst.instruction |= inst.operands[0].reg << 12;
9351 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9352 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9353
c19d1205
ZW
9354 if (inst.operands[3].present)
9355 encode_arm_shift (3);
b99bd4ef
NC
9356}
9357
c19d1205 9358/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9359
9360static void
c19d1205 9361do_usat (void)
b99bd4ef 9362{
c19d1205
ZW
9363 inst.instruction |= inst.operands[0].reg << 12;
9364 inst.instruction |= inst.operands[1].imm << 16;
9365 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9366
c19d1205
ZW
9367 if (inst.operands[3].present)
9368 encode_arm_shift (3);
b99bd4ef
NC
9369}
9370
c19d1205 9371/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9372
9373static void
c19d1205 9374do_ssat16 (void)
09d92015 9375{
c19d1205
ZW
9376 inst.instruction |= inst.operands[0].reg << 12;
9377 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9378 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9379}
9380
c19d1205
ZW
9381static void
9382do_usat16 (void)
a737bd4d 9383{
c19d1205
ZW
9384 inst.instruction |= inst.operands[0].reg << 12;
9385 inst.instruction |= inst.operands[1].imm << 16;
9386 inst.instruction |= inst.operands[2].reg;
9387}
a737bd4d 9388
c19d1205
ZW
9389/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9390 preserving the other bits.
a737bd4d 9391
c19d1205
ZW
9392 setend <endian_specifier>, where <endian_specifier> is either
9393 BE or LE. */
a737bd4d 9394
c19d1205
ZW
9395static void
9396do_setend (void)
9397{
12e37cbc
MGD
9398 if (warn_on_deprecated
9399 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9400 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9401
c19d1205
ZW
9402 if (inst.operands[0].imm)
9403 inst.instruction |= 0x200;
a737bd4d
NC
9404}
9405
9406static void
c19d1205 9407do_shift (void)
a737bd4d 9408{
c19d1205
ZW
9409 unsigned int Rm = (inst.operands[1].present
9410 ? inst.operands[1].reg
9411 : inst.operands[0].reg);
a737bd4d 9412
c19d1205
ZW
9413 inst.instruction |= inst.operands[0].reg << 12;
9414 inst.instruction |= Rm;
9415 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9416 {
c19d1205
ZW
9417 inst.instruction |= inst.operands[2].reg << 8;
9418 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9419 /* PR 12854: Error on extraneous shifts. */
9420 constraint (inst.operands[2].shifted,
9421 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9422 }
9423 else
c19d1205 9424 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9425}
9426
09d92015 9427static void
3eb17e6b 9428do_smc (void)
09d92015 9429{
3eb17e6b 9430 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9431 inst.reloc.pc_rel = 0;
09d92015
MM
9432}
9433
90ec0d68
MGD
9434static void
9435do_hvc (void)
9436{
9437 inst.reloc.type = BFD_RELOC_ARM_HVC;
9438 inst.reloc.pc_rel = 0;
9439}
9440
09d92015 9441static void
c19d1205 9442do_swi (void)
09d92015 9443{
c19d1205
ZW
9444 inst.reloc.type = BFD_RELOC_ARM_SWI;
9445 inst.reloc.pc_rel = 0;
09d92015
MM
9446}
9447
ddfded2f
MW
9448static void
9449do_setpan (void)
9450{
9451 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9452 _("selected processor does not support SETPAN instruction"));
9453
9454 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9455}
9456
9457static void
9458do_t_setpan (void)
9459{
9460 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9461 _("selected processor does not support SETPAN instruction"));
9462
9463 inst.instruction |= (inst.operands[0].imm << 3);
9464}
9465
c19d1205
ZW
9466/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9467 SMLAxy{cond} Rd,Rm,Rs,Rn
9468 SMLAWy{cond} Rd,Rm,Rs,Rn
9469 Error if any register is R15. */
e16bb312 9470
c19d1205
ZW
9471static void
9472do_smla (void)
e16bb312 9473{
c19d1205
ZW
9474 inst.instruction |= inst.operands[0].reg << 16;
9475 inst.instruction |= inst.operands[1].reg;
9476 inst.instruction |= inst.operands[2].reg << 8;
9477 inst.instruction |= inst.operands[3].reg << 12;
9478}
a737bd4d 9479
c19d1205
ZW
9480/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9481 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9482 Error if any register is R15.
9483 Warning if Rdlo == Rdhi. */
a737bd4d 9484
c19d1205
ZW
9485static void
9486do_smlal (void)
9487{
9488 inst.instruction |= inst.operands[0].reg << 12;
9489 inst.instruction |= inst.operands[1].reg << 16;
9490 inst.instruction |= inst.operands[2].reg;
9491 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9492
c19d1205
ZW
9493 if (inst.operands[0].reg == inst.operands[1].reg)
9494 as_tsktsk (_("rdhi and rdlo must be different"));
9495}
a737bd4d 9496
c19d1205
ZW
9497/* ARM V5E (El Segundo) signed-multiply (argument parse)
9498 SMULxy{cond} Rd,Rm,Rs
9499 Error if any register is R15. */
a737bd4d 9500
c19d1205
ZW
9501static void
9502do_smul (void)
9503{
9504 inst.instruction |= inst.operands[0].reg << 16;
9505 inst.instruction |= inst.operands[1].reg;
9506 inst.instruction |= inst.operands[2].reg << 8;
9507}
a737bd4d 9508
b6702015
PB
9509/* ARM V6 srs (argument parse). The variable fields in the encoding are
9510 the same for both ARM and Thumb-2. */
a737bd4d 9511
c19d1205
ZW
9512static void
9513do_srs (void)
9514{
b6702015
PB
9515 int reg;
9516
9517 if (inst.operands[0].present)
9518 {
9519 reg = inst.operands[0].reg;
fdfde340 9520 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9521 }
9522 else
fdfde340 9523 reg = REG_SP;
b6702015
PB
9524
9525 inst.instruction |= reg << 16;
9526 inst.instruction |= inst.operands[1].imm;
9527 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9528 inst.instruction |= WRITE_BACK;
9529}
a737bd4d 9530
c19d1205 9531/* ARM V6 strex (argument parse). */
a737bd4d 9532
c19d1205
ZW
9533static void
9534do_strex (void)
9535{
9536 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9537 || inst.operands[2].postind || inst.operands[2].writeback
9538 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9539 || inst.operands[2].negative
9540 /* See comment in do_ldrex(). */
9541 || (inst.operands[2].reg == REG_PC),
9542 BAD_ADDR_MODE);
a737bd4d 9543
c19d1205
ZW
9544 constraint (inst.operands[0].reg == inst.operands[1].reg
9545 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9546
c19d1205
ZW
9547 constraint (inst.reloc.exp.X_op != O_constant
9548 || inst.reloc.exp.X_add_number != 0,
9549 _("offset must be zero in ARM encoding"));
a737bd4d 9550
c19d1205
ZW
9551 inst.instruction |= inst.operands[0].reg << 12;
9552 inst.instruction |= inst.operands[1].reg;
9553 inst.instruction |= inst.operands[2].reg << 16;
9554 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9555}
9556
877807f8
NC
9557static void
9558do_t_strexbh (void)
9559{
9560 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9561 || inst.operands[2].postind || inst.operands[2].writeback
9562 || inst.operands[2].immisreg || inst.operands[2].shifted
9563 || inst.operands[2].negative,
9564 BAD_ADDR_MODE);
9565
9566 constraint (inst.operands[0].reg == inst.operands[1].reg
9567 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9568
9569 do_rm_rd_rn ();
9570}
9571
e16bb312 9572static void
c19d1205 9573do_strexd (void)
e16bb312 9574{
c19d1205
ZW
9575 constraint (inst.operands[1].reg % 2 != 0,
9576 _("even register required"));
9577 constraint (inst.operands[2].present
9578 && inst.operands[2].reg != inst.operands[1].reg + 1,
9579 _("can only store two consecutive registers"));
9580 /* If op 2 were present and equal to PC, this function wouldn't
9581 have been called in the first place. */
9582 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9583
c19d1205
ZW
9584 constraint (inst.operands[0].reg == inst.operands[1].reg
9585 || inst.operands[0].reg == inst.operands[1].reg + 1
9586 || inst.operands[0].reg == inst.operands[3].reg,
9587 BAD_OVERLAP);
e16bb312 9588
c19d1205
ZW
9589 inst.instruction |= inst.operands[0].reg << 12;
9590 inst.instruction |= inst.operands[1].reg;
9591 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9592}
9593
9eb6c0f1
MGD
9594/* ARM V8 STRL. */
9595static void
4b8c8c02 9596do_stlex (void)
9eb6c0f1
MGD
9597{
9598 constraint (inst.operands[0].reg == inst.operands[1].reg
9599 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9600
9601 do_rd_rm_rn ();
9602}
9603
9604static void
4b8c8c02 9605do_t_stlex (void)
9eb6c0f1
MGD
9606{
9607 constraint (inst.operands[0].reg == inst.operands[1].reg
9608 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9609
9610 do_rm_rd_rn ();
9611}
9612
c19d1205
ZW
9613/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9614 extends it to 32-bits, and adds the result to a value in another
9615 register. You can specify a rotation by 0, 8, 16, or 24 bits
9616 before extracting the 16-bit value.
9617 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9618 Condition defaults to COND_ALWAYS.
9619 Error if any register uses R15. */
9620
e16bb312 9621static void
c19d1205 9622do_sxtah (void)
e16bb312 9623{
c19d1205
ZW
9624 inst.instruction |= inst.operands[0].reg << 12;
9625 inst.instruction |= inst.operands[1].reg << 16;
9626 inst.instruction |= inst.operands[2].reg;
9627 inst.instruction |= inst.operands[3].imm << 10;
9628}
e16bb312 9629
c19d1205 9630/* ARM V6 SXTH.
e16bb312 9631
c19d1205
ZW
9632 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9633 Condition defaults to COND_ALWAYS.
9634 Error if any register uses R15. */
e16bb312
NC
9635
9636static void
c19d1205 9637do_sxth (void)
e16bb312 9638{
c19d1205
ZW
9639 inst.instruction |= inst.operands[0].reg << 12;
9640 inst.instruction |= inst.operands[1].reg;
9641 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9642}
c19d1205
ZW
9643\f
9644/* VFP instructions. In a logical order: SP variant first, monad
9645 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9646
9647static void
c19d1205 9648do_vfp_sp_monadic (void)
e16bb312 9649{
5287ad62
JB
9650 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9651 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9652}
9653
9654static void
c19d1205 9655do_vfp_sp_dyadic (void)
e16bb312 9656{
5287ad62
JB
9657 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9658 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9659 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9660}
9661
9662static void
c19d1205 9663do_vfp_sp_compare_z (void)
e16bb312 9664{
5287ad62 9665 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9666}
9667
9668static void
c19d1205 9669do_vfp_dp_sp_cvt (void)
e16bb312 9670{
5287ad62
JB
9671 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9672 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9673}
9674
9675static void
c19d1205 9676do_vfp_sp_dp_cvt (void)
e16bb312 9677{
5287ad62
JB
9678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9679 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9680}
9681
9682static void
c19d1205 9683do_vfp_reg_from_sp (void)
e16bb312 9684{
c19d1205 9685 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9686 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9687}
9688
9689static void
c19d1205 9690do_vfp_reg2_from_sp2 (void)
e16bb312 9691{
c19d1205
ZW
9692 constraint (inst.operands[2].imm != 2,
9693 _("only two consecutive VFP SP registers allowed here"));
9694 inst.instruction |= inst.operands[0].reg << 12;
9695 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9696 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9697}
9698
9699static void
c19d1205 9700do_vfp_sp_from_reg (void)
e16bb312 9701{
5287ad62 9702 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9703 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9704}
9705
9706static void
c19d1205 9707do_vfp_sp2_from_reg2 (void)
e16bb312 9708{
c19d1205
ZW
9709 constraint (inst.operands[0].imm != 2,
9710 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9711 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9712 inst.instruction |= inst.operands[1].reg << 12;
9713 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9714}
9715
9716static void
c19d1205 9717do_vfp_sp_ldst (void)
e16bb312 9718{
5287ad62 9719 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9720 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9721}
9722
9723static void
c19d1205 9724do_vfp_dp_ldst (void)
e16bb312 9725{
5287ad62 9726 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9727 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9728}
9729
c19d1205 9730
e16bb312 9731static void
c19d1205 9732vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9733{
c19d1205
ZW
9734 if (inst.operands[0].writeback)
9735 inst.instruction |= WRITE_BACK;
9736 else
9737 constraint (ldstm_type != VFP_LDSTMIA,
9738 _("this addressing mode requires base-register writeback"));
9739 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9740 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9741 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9742}
9743
9744static void
c19d1205 9745vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9746{
c19d1205 9747 int count;
e16bb312 9748
c19d1205
ZW
9749 if (inst.operands[0].writeback)
9750 inst.instruction |= WRITE_BACK;
9751 else
9752 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9753 _("this addressing mode requires base-register writeback"));
e16bb312 9754
c19d1205 9755 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9757
c19d1205
ZW
9758 count = inst.operands[1].imm << 1;
9759 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9760 count += 1;
e16bb312 9761
c19d1205 9762 inst.instruction |= count;
e16bb312
NC
9763}
9764
9765static void
c19d1205 9766do_vfp_sp_ldstmia (void)
e16bb312 9767{
c19d1205 9768 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9769}
9770
9771static void
c19d1205 9772do_vfp_sp_ldstmdb (void)
e16bb312 9773{
c19d1205 9774 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9775}
9776
9777static void
c19d1205 9778do_vfp_dp_ldstmia (void)
e16bb312 9779{
c19d1205 9780 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9781}
9782
9783static void
c19d1205 9784do_vfp_dp_ldstmdb (void)
e16bb312 9785{
c19d1205 9786 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9787}
9788
9789static void
c19d1205 9790do_vfp_xp_ldstmia (void)
e16bb312 9791{
c19d1205
ZW
9792 vfp_dp_ldstm (VFP_LDSTMIAX);
9793}
e16bb312 9794
c19d1205
ZW
9795static void
9796do_vfp_xp_ldstmdb (void)
9797{
9798 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9799}
5287ad62
JB
9800
9801static void
9802do_vfp_dp_rd_rm (void)
9803{
9804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9805 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9806}
9807
9808static void
9809do_vfp_dp_rn_rd (void)
9810{
9811 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9812 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9813}
9814
9815static void
9816do_vfp_dp_rd_rn (void)
9817{
9818 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9819 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9820}
9821
9822static void
9823do_vfp_dp_rd_rn_rm (void)
9824{
9825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9826 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9827 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9828}
9829
9830static void
9831do_vfp_dp_rd (void)
9832{
9833 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9834}
9835
9836static void
9837do_vfp_dp_rm_rd_rn (void)
9838{
9839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9841 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9842}
9843
9844/* VFPv3 instructions. */
9845static void
9846do_vfp_sp_const (void)
9847{
9848 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9849 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9850 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9851}
9852
9853static void
9854do_vfp_dp_const (void)
9855{
9856 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9857 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9858 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9859}
9860
9861static void
9862vfp_conv (int srcsize)
9863{
5f1af56b
MGD
9864 int immbits = srcsize - inst.operands[1].imm;
9865
fa94de6b
RM
9866 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9867 {
5f1af56b 9868 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9869 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9870 inst.error = _("immediate value out of range, expected range [0, 16]");
9871 return;
9872 }
fa94de6b 9873 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9874 {
9875 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9876 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9877 inst.error = _("immediate value out of range, expected range [1, 32]");
9878 return;
9879 }
9880
5287ad62
JB
9881 inst.instruction |= (immbits & 1) << 5;
9882 inst.instruction |= (immbits >> 1);
9883}
9884
9885static void
9886do_vfp_sp_conv_16 (void)
9887{
9888 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9889 vfp_conv (16);
9890}
9891
9892static void
9893do_vfp_dp_conv_16 (void)
9894{
9895 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9896 vfp_conv (16);
9897}
9898
9899static void
9900do_vfp_sp_conv_32 (void)
9901{
9902 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9903 vfp_conv (32);
9904}
9905
9906static void
9907do_vfp_dp_conv_32 (void)
9908{
9909 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9910 vfp_conv (32);
9911}
c19d1205
ZW
9912\f
9913/* FPA instructions. Also in a logical order. */
e16bb312 9914
c19d1205
ZW
9915static void
9916do_fpa_cmp (void)
9917{
9918 inst.instruction |= inst.operands[0].reg << 16;
9919 inst.instruction |= inst.operands[1].reg;
9920}
b99bd4ef
NC
9921
9922static void
c19d1205 9923do_fpa_ldmstm (void)
b99bd4ef 9924{
c19d1205
ZW
9925 inst.instruction |= inst.operands[0].reg << 12;
9926 switch (inst.operands[1].imm)
9927 {
9928 case 1: inst.instruction |= CP_T_X; break;
9929 case 2: inst.instruction |= CP_T_Y; break;
9930 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9931 case 4: break;
9932 default: abort ();
9933 }
b99bd4ef 9934
c19d1205
ZW
9935 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9936 {
9937 /* The instruction specified "ea" or "fd", so we can only accept
9938 [Rn]{!}. The instruction does not really support stacking or
9939 unstacking, so we have to emulate these by setting appropriate
9940 bits and offsets. */
9941 constraint (inst.reloc.exp.X_op != O_constant
9942 || inst.reloc.exp.X_add_number != 0,
9943 _("this instruction does not support indexing"));
b99bd4ef 9944
c19d1205
ZW
9945 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9946 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9947
c19d1205
ZW
9948 if (!(inst.instruction & INDEX_UP))
9949 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9950
c19d1205
ZW
9951 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9952 {
9953 inst.operands[2].preind = 0;
9954 inst.operands[2].postind = 1;
9955 }
9956 }
b99bd4ef 9957
c19d1205 9958 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9959}
c19d1205
ZW
9960\f
9961/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9962
c19d1205
ZW
9963static void
9964do_iwmmxt_tandorc (void)
9965{
9966 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9967}
b99bd4ef 9968
c19d1205
ZW
9969static void
9970do_iwmmxt_textrc (void)
9971{
9972 inst.instruction |= inst.operands[0].reg << 12;
9973 inst.instruction |= inst.operands[1].imm;
9974}
b99bd4ef
NC
9975
9976static void
c19d1205 9977do_iwmmxt_textrm (void)
b99bd4ef 9978{
c19d1205
ZW
9979 inst.instruction |= inst.operands[0].reg << 12;
9980 inst.instruction |= inst.operands[1].reg << 16;
9981 inst.instruction |= inst.operands[2].imm;
9982}
b99bd4ef 9983
c19d1205
ZW
9984static void
9985do_iwmmxt_tinsr (void)
9986{
9987 inst.instruction |= inst.operands[0].reg << 16;
9988 inst.instruction |= inst.operands[1].reg << 12;
9989 inst.instruction |= inst.operands[2].imm;
9990}
b99bd4ef 9991
c19d1205
ZW
9992static void
9993do_iwmmxt_tmia (void)
9994{
9995 inst.instruction |= inst.operands[0].reg << 5;
9996 inst.instruction |= inst.operands[1].reg;
9997 inst.instruction |= inst.operands[2].reg << 12;
9998}
b99bd4ef 9999
c19d1205
ZW
10000static void
10001do_iwmmxt_waligni (void)
10002{
10003 inst.instruction |= inst.operands[0].reg << 12;
10004 inst.instruction |= inst.operands[1].reg << 16;
10005 inst.instruction |= inst.operands[2].reg;
10006 inst.instruction |= inst.operands[3].imm << 20;
10007}
b99bd4ef 10008
2d447fca
JM
10009static void
10010do_iwmmxt_wmerge (void)
10011{
10012 inst.instruction |= inst.operands[0].reg << 12;
10013 inst.instruction |= inst.operands[1].reg << 16;
10014 inst.instruction |= inst.operands[2].reg;
10015 inst.instruction |= inst.operands[3].imm << 21;
10016}
10017
c19d1205
ZW
10018static void
10019do_iwmmxt_wmov (void)
10020{
10021 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10022 inst.instruction |= inst.operands[0].reg << 12;
10023 inst.instruction |= inst.operands[1].reg << 16;
10024 inst.instruction |= inst.operands[1].reg;
10025}
b99bd4ef 10026
c19d1205
ZW
10027static void
10028do_iwmmxt_wldstbh (void)
10029{
8f06b2d8 10030 int reloc;
c19d1205 10031 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10032 if (thumb_mode)
10033 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10034 else
10035 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10036 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10037}
10038
c19d1205
ZW
10039static void
10040do_iwmmxt_wldstw (void)
10041{
10042 /* RIWR_RIWC clears .isreg for a control register. */
10043 if (!inst.operands[0].isreg)
10044 {
10045 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10046 inst.instruction |= 0xf0000000;
10047 }
b99bd4ef 10048
c19d1205
ZW
10049 inst.instruction |= inst.operands[0].reg << 12;
10050 encode_arm_cp_address (1, TRUE, TRUE, 0);
10051}
b99bd4ef
NC
10052
10053static void
c19d1205 10054do_iwmmxt_wldstd (void)
b99bd4ef 10055{
c19d1205 10056 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10057 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10058 && inst.operands[1].immisreg)
10059 {
10060 inst.instruction &= ~0x1a000ff;
eff0bc54 10061 inst.instruction |= (0xfU << 28);
2d447fca
JM
10062 if (inst.operands[1].preind)
10063 inst.instruction |= PRE_INDEX;
10064 if (!inst.operands[1].negative)
10065 inst.instruction |= INDEX_UP;
10066 if (inst.operands[1].writeback)
10067 inst.instruction |= WRITE_BACK;
10068 inst.instruction |= inst.operands[1].reg << 16;
10069 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10070 inst.instruction |= inst.operands[1].imm;
10071 }
10072 else
10073 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10074}
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_iwmmxt_wshufh (void)
10078{
10079 inst.instruction |= inst.operands[0].reg << 12;
10080 inst.instruction |= inst.operands[1].reg << 16;
10081 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10082 inst.instruction |= (inst.operands[2].imm & 0x0f);
10083}
b99bd4ef 10084
c19d1205
ZW
10085static void
10086do_iwmmxt_wzero (void)
10087{
10088 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10089 inst.instruction |= inst.operands[0].reg;
10090 inst.instruction |= inst.operands[0].reg << 12;
10091 inst.instruction |= inst.operands[0].reg << 16;
10092}
2d447fca
JM
10093
10094static void
10095do_iwmmxt_wrwrwr_or_imm5 (void)
10096{
10097 if (inst.operands[2].isreg)
10098 do_rd_rn_rm ();
10099 else {
10100 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10101 _("immediate operand requires iWMMXt2"));
10102 do_rd_rn ();
10103 if (inst.operands[2].imm == 0)
10104 {
10105 switch ((inst.instruction >> 20) & 0xf)
10106 {
10107 case 4:
10108 case 5:
10109 case 6:
5f4273c7 10110 case 7:
2d447fca
JM
10111 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10112 inst.operands[2].imm = 16;
10113 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10114 break;
10115 case 8:
10116 case 9:
10117 case 10:
10118 case 11:
10119 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10120 inst.operands[2].imm = 32;
10121 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10122 break;
10123 case 12:
10124 case 13:
10125 case 14:
10126 case 15:
10127 {
10128 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10129 unsigned long wrn;
10130 wrn = (inst.instruction >> 16) & 0xf;
10131 inst.instruction &= 0xff0fff0f;
10132 inst.instruction |= wrn;
10133 /* Bail out here; the instruction is now assembled. */
10134 return;
10135 }
10136 }
10137 }
10138 /* Map 32 -> 0, etc. */
10139 inst.operands[2].imm &= 0x1f;
eff0bc54 10140 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10141 }
10142}
c19d1205
ZW
10143\f
10144/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10145 operations first, then control, shift, and load/store. */
b99bd4ef 10146
c19d1205 10147/* Insns like "foo X,Y,Z". */
b99bd4ef 10148
c19d1205
ZW
10149static void
10150do_mav_triple (void)
10151{
10152 inst.instruction |= inst.operands[0].reg << 16;
10153 inst.instruction |= inst.operands[1].reg;
10154 inst.instruction |= inst.operands[2].reg << 12;
10155}
b99bd4ef 10156
c19d1205
ZW
10157/* Insns like "foo W,X,Y,Z".
10158 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10159
c19d1205
ZW
10160static void
10161do_mav_quad (void)
10162{
10163 inst.instruction |= inst.operands[0].reg << 5;
10164 inst.instruction |= inst.operands[1].reg << 12;
10165 inst.instruction |= inst.operands[2].reg << 16;
10166 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10167}
10168
c19d1205
ZW
10169/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10170static void
10171do_mav_dspsc (void)
a737bd4d 10172{
c19d1205
ZW
10173 inst.instruction |= inst.operands[1].reg << 12;
10174}
a737bd4d 10175
c19d1205
ZW
10176/* Maverick shift immediate instructions.
10177 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10178 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10179
c19d1205
ZW
10180static void
10181do_mav_shift (void)
10182{
10183 int imm = inst.operands[2].imm;
a737bd4d 10184
c19d1205
ZW
10185 inst.instruction |= inst.operands[0].reg << 12;
10186 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10187
c19d1205
ZW
10188 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10189 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10190 Bit 4 should be 0. */
10191 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10192
c19d1205
ZW
10193 inst.instruction |= imm;
10194}
10195\f
10196/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10197
c19d1205
ZW
10198/* Xscale multiply-accumulate (argument parse)
10199 MIAcc acc0,Rm,Rs
10200 MIAPHcc acc0,Rm,Rs
10201 MIAxycc acc0,Rm,Rs. */
a737bd4d 10202
c19d1205
ZW
10203static void
10204do_xsc_mia (void)
10205{
10206 inst.instruction |= inst.operands[1].reg;
10207 inst.instruction |= inst.operands[2].reg << 12;
10208}
a737bd4d 10209
c19d1205 10210/* Xscale move-accumulator-register (argument parse)
a737bd4d 10211
c19d1205 10212 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10213
c19d1205
ZW
10214static void
10215do_xsc_mar (void)
10216{
10217 inst.instruction |= inst.operands[1].reg << 12;
10218 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10219}
10220
c19d1205 10221/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10222
c19d1205 10223 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10224
10225static void
c19d1205 10226do_xsc_mra (void)
b99bd4ef 10227{
c19d1205
ZW
10228 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10229 inst.instruction |= inst.operands[0].reg << 12;
10230 inst.instruction |= inst.operands[1].reg << 16;
10231}
10232\f
10233/* Encoding functions relevant only to Thumb. */
b99bd4ef 10234
c19d1205
ZW
10235/* inst.operands[i] is a shifted-register operand; encode
10236 it into inst.instruction in the format used by Thumb32. */
10237
10238static void
10239encode_thumb32_shifted_operand (int i)
10240{
10241 unsigned int value = inst.reloc.exp.X_add_number;
10242 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10243
9c3c69f2
PB
10244 constraint (inst.operands[i].immisreg,
10245 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10246 inst.instruction |= inst.operands[i].reg;
10247 if (shift == SHIFT_RRX)
10248 inst.instruction |= SHIFT_ROR << 4;
10249 else
b99bd4ef 10250 {
c19d1205
ZW
10251 constraint (inst.reloc.exp.X_op != O_constant,
10252 _("expression too complex"));
10253
10254 constraint (value > 32
10255 || (value == 32 && (shift == SHIFT_LSL
10256 || shift == SHIFT_ROR)),
10257 _("shift expression is too large"));
10258
10259 if (value == 0)
10260 shift = SHIFT_LSL;
10261 else if (value == 32)
10262 value = 0;
10263
10264 inst.instruction |= shift << 4;
10265 inst.instruction |= (value & 0x1c) << 10;
10266 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10267 }
c19d1205 10268}
b99bd4ef 10269
b99bd4ef 10270
c19d1205
ZW
10271/* inst.operands[i] was set up by parse_address. Encode it into a
10272 Thumb32 format load or store instruction. Reject forms that cannot
10273 be used with such instructions. If is_t is true, reject forms that
10274 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10275 that cannot be used with a D instruction. If it is a store insn,
10276 reject PC in Rn. */
b99bd4ef 10277
c19d1205
ZW
10278static void
10279encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10280{
5be8be5d 10281 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10282
10283 constraint (!inst.operands[i].isreg,
53365c0d 10284 _("Instruction does not support =N addresses"));
b99bd4ef 10285
c19d1205
ZW
10286 inst.instruction |= inst.operands[i].reg << 16;
10287 if (inst.operands[i].immisreg)
b99bd4ef 10288 {
5be8be5d 10289 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10290 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10291 constraint (inst.operands[i].negative,
10292 _("Thumb does not support negative register indexing"));
10293 constraint (inst.operands[i].postind,
10294 _("Thumb does not support register post-indexing"));
10295 constraint (inst.operands[i].writeback,
10296 _("Thumb does not support register indexing with writeback"));
10297 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10298 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10299
f40d1643 10300 inst.instruction |= inst.operands[i].imm;
c19d1205 10301 if (inst.operands[i].shifted)
b99bd4ef 10302 {
c19d1205
ZW
10303 constraint (inst.reloc.exp.X_op != O_constant,
10304 _("expression too complex"));
9c3c69f2
PB
10305 constraint (inst.reloc.exp.X_add_number < 0
10306 || inst.reloc.exp.X_add_number > 3,
c19d1205 10307 _("shift out of range"));
9c3c69f2 10308 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10309 }
10310 inst.reloc.type = BFD_RELOC_UNUSED;
10311 }
10312 else if (inst.operands[i].preind)
10313 {
5be8be5d 10314 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10315 constraint (is_t && inst.operands[i].writeback,
c19d1205 10316 _("cannot use writeback with this instruction"));
4755303e
WN
10317 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10318 BAD_PC_ADDRESSING);
c19d1205
ZW
10319
10320 if (is_d)
10321 {
10322 inst.instruction |= 0x01000000;
10323 if (inst.operands[i].writeback)
10324 inst.instruction |= 0x00200000;
b99bd4ef 10325 }
c19d1205 10326 else
b99bd4ef 10327 {
c19d1205
ZW
10328 inst.instruction |= 0x00000c00;
10329 if (inst.operands[i].writeback)
10330 inst.instruction |= 0x00000100;
b99bd4ef 10331 }
c19d1205 10332 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10333 }
c19d1205 10334 else if (inst.operands[i].postind)
b99bd4ef 10335 {
9c2799c2 10336 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10337 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10338 constraint (is_t, _("cannot use post-indexing with this instruction"));
10339
10340 if (is_d)
10341 inst.instruction |= 0x00200000;
10342 else
10343 inst.instruction |= 0x00000900;
10344 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10345 }
10346 else /* unindexed - only for coprocessor */
10347 inst.error = _("instruction does not accept unindexed addressing");
10348}
10349
10350/* Table of Thumb instructions which exist in both 16- and 32-bit
10351 encodings (the latter only in post-V6T2 cores). The index is the
10352 value used in the insns table below. When there is more than one
10353 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10354 holds variant (1).
10355 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10356#define T16_32_TAB \
21d799b5
NC
10357 X(_adc, 4140, eb400000), \
10358 X(_adcs, 4140, eb500000), \
10359 X(_add, 1c00, eb000000), \
10360 X(_adds, 1c00, eb100000), \
10361 X(_addi, 0000, f1000000), \
10362 X(_addis, 0000, f1100000), \
10363 X(_add_pc,000f, f20f0000), \
10364 X(_add_sp,000d, f10d0000), \
10365 X(_adr, 000f, f20f0000), \
10366 X(_and, 4000, ea000000), \
10367 X(_ands, 4000, ea100000), \
10368 X(_asr, 1000, fa40f000), \
10369 X(_asrs, 1000, fa50f000), \
10370 X(_b, e000, f000b000), \
10371 X(_bcond, d000, f0008000), \
10372 X(_bic, 4380, ea200000), \
10373 X(_bics, 4380, ea300000), \
10374 X(_cmn, 42c0, eb100f00), \
10375 X(_cmp, 2800, ebb00f00), \
10376 X(_cpsie, b660, f3af8400), \
10377 X(_cpsid, b670, f3af8600), \
10378 X(_cpy, 4600, ea4f0000), \
10379 X(_dec_sp,80dd, f1ad0d00), \
10380 X(_eor, 4040, ea800000), \
10381 X(_eors, 4040, ea900000), \
10382 X(_inc_sp,00dd, f10d0d00), \
10383 X(_ldmia, c800, e8900000), \
10384 X(_ldr, 6800, f8500000), \
10385 X(_ldrb, 7800, f8100000), \
10386 X(_ldrh, 8800, f8300000), \
10387 X(_ldrsb, 5600, f9100000), \
10388 X(_ldrsh, 5e00, f9300000), \
10389 X(_ldr_pc,4800, f85f0000), \
10390 X(_ldr_pc2,4800, f85f0000), \
10391 X(_ldr_sp,9800, f85d0000), \
10392 X(_lsl, 0000, fa00f000), \
10393 X(_lsls, 0000, fa10f000), \
10394 X(_lsr, 0800, fa20f000), \
10395 X(_lsrs, 0800, fa30f000), \
10396 X(_mov, 2000, ea4f0000), \
10397 X(_movs, 2000, ea5f0000), \
10398 X(_mul, 4340, fb00f000), \
10399 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10400 X(_mvn, 43c0, ea6f0000), \
10401 X(_mvns, 43c0, ea7f0000), \
10402 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10403 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10404 X(_orr, 4300, ea400000), \
10405 X(_orrs, 4300, ea500000), \
10406 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10407 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10408 X(_rev, ba00, fa90f080), \
10409 X(_rev16, ba40, fa90f090), \
10410 X(_revsh, bac0, fa90f0b0), \
10411 X(_ror, 41c0, fa60f000), \
10412 X(_rors, 41c0, fa70f000), \
10413 X(_sbc, 4180, eb600000), \
10414 X(_sbcs, 4180, eb700000), \
10415 X(_stmia, c000, e8800000), \
10416 X(_str, 6000, f8400000), \
10417 X(_strb, 7000, f8000000), \
10418 X(_strh, 8000, f8200000), \
10419 X(_str_sp,9000, f84d0000), \
10420 X(_sub, 1e00, eba00000), \
10421 X(_subs, 1e00, ebb00000), \
10422 X(_subi, 8000, f1a00000), \
10423 X(_subis, 8000, f1b00000), \
10424 X(_sxtb, b240, fa4ff080), \
10425 X(_sxth, b200, fa0ff080), \
10426 X(_tst, 4200, ea100f00), \
10427 X(_uxtb, b2c0, fa5ff080), \
10428 X(_uxth, b280, fa1ff080), \
10429 X(_nop, bf00, f3af8000), \
10430 X(_yield, bf10, f3af8001), \
10431 X(_wfe, bf20, f3af8002), \
10432 X(_wfi, bf30, f3af8003), \
53c4b28b 10433 X(_sev, bf40, f3af8004), \
74db7efb
NC
10434 X(_sevl, bf50, f3af8005), \
10435 X(_udf, de00, f7f0a000)
c19d1205
ZW
10436
10437/* To catch errors in encoding functions, the codes are all offset by
10438 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10439 as 16-bit instructions. */
21d799b5 10440#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10441enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10442#undef X
10443
10444#define X(a,b,c) 0x##b
10445static const unsigned short thumb_op16[] = { T16_32_TAB };
10446#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10447#undef X
10448
10449#define X(a,b,c) 0x##c
10450static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10451#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10452#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10453#undef X
10454#undef T16_32_TAB
10455
10456/* Thumb instruction encoders, in alphabetical order. */
10457
92e90b6e 10458/* ADDW or SUBW. */
c921be7d 10459
92e90b6e
PB
10460static void
10461do_t_add_sub_w (void)
10462{
10463 int Rd, Rn;
10464
10465 Rd = inst.operands[0].reg;
10466 Rn = inst.operands[1].reg;
10467
539d4391
NC
10468 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10469 is the SP-{plus,minus}-immediate form of the instruction. */
10470 if (Rn == REG_SP)
10471 constraint (Rd == REG_PC, BAD_PC);
10472 else
10473 reject_bad_reg (Rd);
fdfde340 10474
92e90b6e
PB
10475 inst.instruction |= (Rn << 16) | (Rd << 8);
10476 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10477}
10478
c19d1205
ZW
10479/* Parse an add or subtract instruction. We get here with inst.instruction
10480 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10481
10482static void
10483do_t_add_sub (void)
10484{
10485 int Rd, Rs, Rn;
10486
10487 Rd = inst.operands[0].reg;
10488 Rs = (inst.operands[1].present
10489 ? inst.operands[1].reg /* Rd, Rs, foo */
10490 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10491
e07e6e58
NC
10492 if (Rd == REG_PC)
10493 set_it_insn_type_last ();
10494
c19d1205
ZW
10495 if (unified_syntax)
10496 {
0110f2b8
PB
10497 bfd_boolean flags;
10498 bfd_boolean narrow;
10499 int opcode;
10500
10501 flags = (inst.instruction == T_MNEM_adds
10502 || inst.instruction == T_MNEM_subs);
10503 if (flags)
e07e6e58 10504 narrow = !in_it_block ();
0110f2b8 10505 else
e07e6e58 10506 narrow = in_it_block ();
c19d1205 10507 if (!inst.operands[2].isreg)
b99bd4ef 10508 {
16805f35
PB
10509 int add;
10510
fdfde340
JM
10511 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10512
16805f35
PB
10513 add = (inst.instruction == T_MNEM_add
10514 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10515 opcode = 0;
10516 if (inst.size_req != 4)
10517 {
0110f2b8 10518 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10519 appropriate. */
0110f2b8
PB
10520 if (Rd == REG_SP && Rs == REG_SP && !flags)
10521 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10522 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10523 opcode = T_MNEM_add_sp;
10524 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10525 opcode = T_MNEM_add_pc;
10526 else if (Rd <= 7 && Rs <= 7 && narrow)
10527 {
10528 if (flags)
10529 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10530 else
10531 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10532 }
10533 if (opcode)
10534 {
10535 inst.instruction = THUMB_OP16(opcode);
10536 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10537 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10538 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10539 {
10540 if (inst.size_req == 2)
10541 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10542 else
10543 inst.relax = opcode;
10544 }
0110f2b8
PB
10545 }
10546 else
10547 constraint (inst.size_req == 2, BAD_HIREG);
10548 }
10549 if (inst.size_req == 4
10550 || (inst.size_req != 2 && !opcode))
10551 {
a9f02af8
MG
10552 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10553 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10554 THUMB1_RELOC_ONLY);
efd81785
PB
10555 if (Rd == REG_PC)
10556 {
fdfde340 10557 constraint (add, BAD_PC);
efd81785
PB
10558 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10559 _("only SUBS PC, LR, #const allowed"));
10560 constraint (inst.reloc.exp.X_op != O_constant,
10561 _("expression too complex"));
10562 constraint (inst.reloc.exp.X_add_number < 0
10563 || inst.reloc.exp.X_add_number > 0xff,
10564 _("immediate value out of range"));
10565 inst.instruction = T2_SUBS_PC_LR
10566 | inst.reloc.exp.X_add_number;
10567 inst.reloc.type = BFD_RELOC_UNUSED;
10568 return;
10569 }
10570 else if (Rs == REG_PC)
16805f35
PB
10571 {
10572 /* Always use addw/subw. */
10573 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10574 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10575 }
10576 else
10577 {
10578 inst.instruction = THUMB_OP32 (inst.instruction);
10579 inst.instruction = (inst.instruction & 0xe1ffffff)
10580 | 0x10000000;
10581 if (flags)
10582 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10583 else
10584 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10585 }
dc4503c6
PB
10586 inst.instruction |= Rd << 8;
10587 inst.instruction |= Rs << 16;
0110f2b8 10588 }
b99bd4ef 10589 }
c19d1205
ZW
10590 else
10591 {
5f4cb198
NC
10592 unsigned int value = inst.reloc.exp.X_add_number;
10593 unsigned int shift = inst.operands[2].shift_kind;
10594
c19d1205
ZW
10595 Rn = inst.operands[2].reg;
10596 /* See if we can do this with a 16-bit instruction. */
10597 if (!inst.operands[2].shifted && inst.size_req != 4)
10598 {
e27ec89e
PB
10599 if (Rd > 7 || Rs > 7 || Rn > 7)
10600 narrow = FALSE;
10601
10602 if (narrow)
c19d1205 10603 {
e27ec89e
PB
10604 inst.instruction = ((inst.instruction == T_MNEM_adds
10605 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10606 ? T_OPCODE_ADD_R3
10607 : T_OPCODE_SUB_R3);
10608 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10609 return;
10610 }
b99bd4ef 10611
7e806470 10612 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10613 {
7e806470
PB
10614 /* Thumb-1 cores (except v6-M) require at least one high
10615 register in a narrow non flag setting add. */
10616 if (Rd > 7 || Rn > 7
10617 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10618 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10619 {
7e806470
PB
10620 if (Rd == Rn)
10621 {
10622 Rn = Rs;
10623 Rs = Rd;
10624 }
c19d1205
ZW
10625 inst.instruction = T_OPCODE_ADD_HI;
10626 inst.instruction |= (Rd & 8) << 4;
10627 inst.instruction |= (Rd & 7);
10628 inst.instruction |= Rn << 3;
10629 return;
10630 }
c19d1205
ZW
10631 }
10632 }
c921be7d 10633
fdfde340
JM
10634 constraint (Rd == REG_PC, BAD_PC);
10635 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10636 constraint (Rs == REG_PC, BAD_PC);
10637 reject_bad_reg (Rn);
10638
c19d1205
ZW
10639 /* If we get here, it can't be done in 16 bits. */
10640 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10641 _("shift must be constant"));
10642 inst.instruction = THUMB_OP32 (inst.instruction);
10643 inst.instruction |= Rd << 8;
10644 inst.instruction |= Rs << 16;
5f4cb198
NC
10645 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10646 _("shift value over 3 not allowed in thumb mode"));
10647 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10648 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10649 encode_thumb32_shifted_operand (2);
10650 }
10651 }
10652 else
10653 {
10654 constraint (inst.instruction == T_MNEM_adds
10655 || inst.instruction == T_MNEM_subs,
10656 BAD_THUMB32);
b99bd4ef 10657
c19d1205 10658 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10659 {
c19d1205
ZW
10660 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10661 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10662 BAD_HIREG);
10663
10664 inst.instruction = (inst.instruction == T_MNEM_add
10665 ? 0x0000 : 0x8000);
10666 inst.instruction |= (Rd << 4) | Rs;
10667 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10668 return;
10669 }
10670
c19d1205
ZW
10671 Rn = inst.operands[2].reg;
10672 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10673
c19d1205
ZW
10674 /* We now have Rd, Rs, and Rn set to registers. */
10675 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10676 {
c19d1205
ZW
10677 /* Can't do this for SUB. */
10678 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10679 inst.instruction = T_OPCODE_ADD_HI;
10680 inst.instruction |= (Rd & 8) << 4;
10681 inst.instruction |= (Rd & 7);
10682 if (Rs == Rd)
10683 inst.instruction |= Rn << 3;
10684 else if (Rn == Rd)
10685 inst.instruction |= Rs << 3;
10686 else
10687 constraint (1, _("dest must overlap one source register"));
10688 }
10689 else
10690 {
10691 inst.instruction = (inst.instruction == T_MNEM_add
10692 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10693 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10694 }
b99bd4ef 10695 }
b99bd4ef
NC
10696}
10697
c19d1205
ZW
10698static void
10699do_t_adr (void)
10700{
fdfde340
JM
10701 unsigned Rd;
10702
10703 Rd = inst.operands[0].reg;
10704 reject_bad_reg (Rd);
10705
10706 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10707 {
10708 /* Defer to section relaxation. */
10709 inst.relax = inst.instruction;
10710 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10711 inst.instruction |= Rd << 4;
0110f2b8
PB
10712 }
10713 else if (unified_syntax && inst.size_req != 2)
e9f89963 10714 {
0110f2b8 10715 /* Generate a 32-bit opcode. */
e9f89963 10716 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10717 inst.instruction |= Rd << 8;
e9f89963
PB
10718 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10719 inst.reloc.pc_rel = 1;
10720 }
10721 else
10722 {
0110f2b8 10723 /* Generate a 16-bit opcode. */
e9f89963
PB
10724 inst.instruction = THUMB_OP16 (inst.instruction);
10725 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10726 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10727 inst.reloc.pc_rel = 1;
b99bd4ef 10728
fdfde340 10729 inst.instruction |= Rd << 4;
e9f89963 10730 }
c19d1205 10731}
b99bd4ef 10732
c19d1205
ZW
10733/* Arithmetic instructions for which there is just one 16-bit
10734 instruction encoding, and it allows only two low registers.
10735 For maximal compatibility with ARM syntax, we allow three register
10736 operands even when Thumb-32 instructions are not available, as long
10737 as the first two are identical. For instance, both "sbc r0,r1" and
10738 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10739static void
c19d1205 10740do_t_arit3 (void)
b99bd4ef 10741{
c19d1205 10742 int Rd, Rs, Rn;
b99bd4ef 10743
c19d1205
ZW
10744 Rd = inst.operands[0].reg;
10745 Rs = (inst.operands[1].present
10746 ? inst.operands[1].reg /* Rd, Rs, foo */
10747 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10748 Rn = inst.operands[2].reg;
b99bd4ef 10749
fdfde340
JM
10750 reject_bad_reg (Rd);
10751 reject_bad_reg (Rs);
10752 if (inst.operands[2].isreg)
10753 reject_bad_reg (Rn);
10754
c19d1205 10755 if (unified_syntax)
b99bd4ef 10756 {
c19d1205
ZW
10757 if (!inst.operands[2].isreg)
10758 {
10759 /* For an immediate, we always generate a 32-bit opcode;
10760 section relaxation will shrink it later if possible. */
10761 inst.instruction = THUMB_OP32 (inst.instruction);
10762 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10763 inst.instruction |= Rd << 8;
10764 inst.instruction |= Rs << 16;
10765 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10766 }
10767 else
10768 {
e27ec89e
PB
10769 bfd_boolean narrow;
10770
c19d1205 10771 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10772 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10773 narrow = !in_it_block ();
e27ec89e 10774 else
e07e6e58 10775 narrow = in_it_block ();
e27ec89e
PB
10776
10777 if (Rd > 7 || Rn > 7 || Rs > 7)
10778 narrow = FALSE;
10779 if (inst.operands[2].shifted)
10780 narrow = FALSE;
10781 if (inst.size_req == 4)
10782 narrow = FALSE;
10783
10784 if (narrow
c19d1205
ZW
10785 && Rd == Rs)
10786 {
10787 inst.instruction = THUMB_OP16 (inst.instruction);
10788 inst.instruction |= Rd;
10789 inst.instruction |= Rn << 3;
10790 return;
10791 }
b99bd4ef 10792
c19d1205
ZW
10793 /* If we get here, it can't be done in 16 bits. */
10794 constraint (inst.operands[2].shifted
10795 && inst.operands[2].immisreg,
10796 _("shift must be constant"));
10797 inst.instruction = THUMB_OP32 (inst.instruction);
10798 inst.instruction |= Rd << 8;
10799 inst.instruction |= Rs << 16;
10800 encode_thumb32_shifted_operand (2);
10801 }
a737bd4d 10802 }
c19d1205 10803 else
b99bd4ef 10804 {
c19d1205
ZW
10805 /* On its face this is a lie - the instruction does set the
10806 flags. However, the only supported mnemonic in this mode
10807 says it doesn't. */
10808 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10809
c19d1205
ZW
10810 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10811 _("unshifted register required"));
10812 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10813 constraint (Rd != Rs,
10814 _("dest and source1 must be the same register"));
a737bd4d 10815
c19d1205
ZW
10816 inst.instruction = THUMB_OP16 (inst.instruction);
10817 inst.instruction |= Rd;
10818 inst.instruction |= Rn << 3;
b99bd4ef 10819 }
a737bd4d 10820}
b99bd4ef 10821
c19d1205
ZW
10822/* Similarly, but for instructions where the arithmetic operation is
10823 commutative, so we can allow either of them to be different from
10824 the destination operand in a 16-bit instruction. For instance, all
10825 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10826 accepted. */
10827static void
10828do_t_arit3c (void)
a737bd4d 10829{
c19d1205 10830 int Rd, Rs, Rn;
b99bd4ef 10831
c19d1205
ZW
10832 Rd = inst.operands[0].reg;
10833 Rs = (inst.operands[1].present
10834 ? inst.operands[1].reg /* Rd, Rs, foo */
10835 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10836 Rn = inst.operands[2].reg;
c921be7d 10837
fdfde340
JM
10838 reject_bad_reg (Rd);
10839 reject_bad_reg (Rs);
10840 if (inst.operands[2].isreg)
10841 reject_bad_reg (Rn);
a737bd4d 10842
c19d1205 10843 if (unified_syntax)
a737bd4d 10844 {
c19d1205 10845 if (!inst.operands[2].isreg)
b99bd4ef 10846 {
c19d1205
ZW
10847 /* For an immediate, we always generate a 32-bit opcode;
10848 section relaxation will shrink it later if possible. */
10849 inst.instruction = THUMB_OP32 (inst.instruction);
10850 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10851 inst.instruction |= Rd << 8;
10852 inst.instruction |= Rs << 16;
10853 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10854 }
c19d1205 10855 else
a737bd4d 10856 {
e27ec89e
PB
10857 bfd_boolean narrow;
10858
c19d1205 10859 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10860 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10861 narrow = !in_it_block ();
e27ec89e 10862 else
e07e6e58 10863 narrow = in_it_block ();
e27ec89e
PB
10864
10865 if (Rd > 7 || Rn > 7 || Rs > 7)
10866 narrow = FALSE;
10867 if (inst.operands[2].shifted)
10868 narrow = FALSE;
10869 if (inst.size_req == 4)
10870 narrow = FALSE;
10871
10872 if (narrow)
a737bd4d 10873 {
c19d1205 10874 if (Rd == Rs)
a737bd4d 10875 {
c19d1205
ZW
10876 inst.instruction = THUMB_OP16 (inst.instruction);
10877 inst.instruction |= Rd;
10878 inst.instruction |= Rn << 3;
10879 return;
a737bd4d 10880 }
c19d1205 10881 if (Rd == Rn)
a737bd4d 10882 {
c19d1205
ZW
10883 inst.instruction = THUMB_OP16 (inst.instruction);
10884 inst.instruction |= Rd;
10885 inst.instruction |= Rs << 3;
10886 return;
a737bd4d
NC
10887 }
10888 }
c19d1205
ZW
10889
10890 /* If we get here, it can't be done in 16 bits. */
10891 constraint (inst.operands[2].shifted
10892 && inst.operands[2].immisreg,
10893 _("shift must be constant"));
10894 inst.instruction = THUMB_OP32 (inst.instruction);
10895 inst.instruction |= Rd << 8;
10896 inst.instruction |= Rs << 16;
10897 encode_thumb32_shifted_operand (2);
a737bd4d 10898 }
b99bd4ef 10899 }
c19d1205
ZW
10900 else
10901 {
10902 /* On its face this is a lie - the instruction does set the
10903 flags. However, the only supported mnemonic in this mode
10904 says it doesn't. */
10905 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10906
c19d1205
ZW
10907 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10908 _("unshifted register required"));
10909 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10910
10911 inst.instruction = THUMB_OP16 (inst.instruction);
10912 inst.instruction |= Rd;
10913
10914 if (Rd == Rs)
10915 inst.instruction |= Rn << 3;
10916 else if (Rd == Rn)
10917 inst.instruction |= Rs << 3;
10918 else
10919 constraint (1, _("dest must overlap one source register"));
10920 }
a737bd4d
NC
10921}
10922
c19d1205
ZW
10923static void
10924do_t_bfc (void)
a737bd4d 10925{
fdfde340 10926 unsigned Rd;
c19d1205
ZW
10927 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10928 constraint (msb > 32, _("bit-field extends past end of register"));
10929 /* The instruction encoding stores the LSB and MSB,
10930 not the LSB and width. */
fdfde340
JM
10931 Rd = inst.operands[0].reg;
10932 reject_bad_reg (Rd);
10933 inst.instruction |= Rd << 8;
c19d1205
ZW
10934 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10935 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10936 inst.instruction |= msb - 1;
b99bd4ef
NC
10937}
10938
c19d1205
ZW
10939static void
10940do_t_bfi (void)
b99bd4ef 10941{
fdfde340 10942 int Rd, Rn;
c19d1205 10943 unsigned int msb;
b99bd4ef 10944
fdfde340
JM
10945 Rd = inst.operands[0].reg;
10946 reject_bad_reg (Rd);
10947
c19d1205
ZW
10948 /* #0 in second position is alternative syntax for bfc, which is
10949 the same instruction but with REG_PC in the Rm field. */
10950 if (!inst.operands[1].isreg)
fdfde340
JM
10951 Rn = REG_PC;
10952 else
10953 {
10954 Rn = inst.operands[1].reg;
10955 reject_bad_reg (Rn);
10956 }
b99bd4ef 10957
c19d1205
ZW
10958 msb = inst.operands[2].imm + inst.operands[3].imm;
10959 constraint (msb > 32, _("bit-field extends past end of register"));
10960 /* The instruction encoding stores the LSB and MSB,
10961 not the LSB and width. */
fdfde340
JM
10962 inst.instruction |= Rd << 8;
10963 inst.instruction |= Rn << 16;
c19d1205
ZW
10964 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10965 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10966 inst.instruction |= msb - 1;
b99bd4ef
NC
10967}
10968
c19d1205
ZW
10969static void
10970do_t_bfx (void)
b99bd4ef 10971{
fdfde340
JM
10972 unsigned Rd, Rn;
10973
10974 Rd = inst.operands[0].reg;
10975 Rn = inst.operands[1].reg;
10976
10977 reject_bad_reg (Rd);
10978 reject_bad_reg (Rn);
10979
c19d1205
ZW
10980 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10981 _("bit-field extends past end of register"));
fdfde340
JM
10982 inst.instruction |= Rd << 8;
10983 inst.instruction |= Rn << 16;
c19d1205
ZW
10984 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10985 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10986 inst.instruction |= inst.operands[3].imm - 1;
10987}
b99bd4ef 10988
c19d1205
ZW
10989/* ARM V5 Thumb BLX (argument parse)
10990 BLX <target_addr> which is BLX(1)
10991 BLX <Rm> which is BLX(2)
10992 Unfortunately, there are two different opcodes for this mnemonic.
10993 So, the insns[].value is not used, and the code here zaps values
10994 into inst.instruction.
b99bd4ef 10995
c19d1205
ZW
10996 ??? How to take advantage of the additional two bits of displacement
10997 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10998
c19d1205
ZW
10999static void
11000do_t_blx (void)
11001{
e07e6e58
NC
11002 set_it_insn_type_last ();
11003
c19d1205 11004 if (inst.operands[0].isreg)
fdfde340
JM
11005 {
11006 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11007 /* We have a register, so this is BLX(2). */
11008 inst.instruction |= inst.operands[0].reg << 3;
11009 }
b99bd4ef
NC
11010 else
11011 {
c19d1205 11012 /* No register. This must be BLX(1). */
2fc8bdac 11013 inst.instruction = 0xf000e800;
0855e32b 11014 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11015 }
11016}
11017
c19d1205
ZW
11018static void
11019do_t_branch (void)
b99bd4ef 11020{
0110f2b8 11021 int opcode;
dfa9f0d5 11022 int cond;
2fe88214 11023 bfd_reloc_code_real_type reloc;
dfa9f0d5 11024
e07e6e58
NC
11025 cond = inst.cond;
11026 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11027
11028 if (in_it_block ())
dfa9f0d5
PB
11029 {
11030 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11031 branches. */
dfa9f0d5 11032 cond = COND_ALWAYS;
dfa9f0d5
PB
11033 }
11034 else
11035 cond = inst.cond;
11036
11037 if (cond != COND_ALWAYS)
0110f2b8
PB
11038 opcode = T_MNEM_bcond;
11039 else
11040 opcode = inst.instruction;
11041
12d6b0b7
RS
11042 if (unified_syntax
11043 && (inst.size_req == 4
10960bfb
PB
11044 || (inst.size_req != 2
11045 && (inst.operands[0].hasreloc
11046 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11047 {
0110f2b8 11048 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11049 if (cond == COND_ALWAYS)
9ae92b05 11050 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11051 else
11052 {
ff8646ee
TP
11053 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11054 _("selected architecture does not support "
11055 "wide conditional branch instruction"));
11056
9c2799c2 11057 gas_assert (cond != 0xF);
dfa9f0d5 11058 inst.instruction |= cond << 22;
9ae92b05 11059 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11060 }
11061 }
b99bd4ef
NC
11062 else
11063 {
0110f2b8 11064 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11065 if (cond == COND_ALWAYS)
9ae92b05 11066 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11067 else
b99bd4ef 11068 {
dfa9f0d5 11069 inst.instruction |= cond << 8;
9ae92b05 11070 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11071 }
0110f2b8
PB
11072 /* Allow section relaxation. */
11073 if (unified_syntax && inst.size_req != 2)
11074 inst.relax = opcode;
b99bd4ef 11075 }
9ae92b05 11076 inst.reloc.type = reloc;
c19d1205 11077 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11078}
11079
8884b720 11080/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11081 between the two is the maximum immediate allowed - which is passed in
8884b720 11082 RANGE. */
b99bd4ef 11083static void
8884b720 11084do_t_bkpt_hlt1 (int range)
b99bd4ef 11085{
dfa9f0d5
PB
11086 constraint (inst.cond != COND_ALWAYS,
11087 _("instruction is always unconditional"));
c19d1205 11088 if (inst.operands[0].present)
b99bd4ef 11089 {
8884b720 11090 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11091 _("immediate value out of range"));
11092 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11093 }
8884b720
MGD
11094
11095 set_it_insn_type (NEUTRAL_IT_INSN);
11096}
11097
11098static void
11099do_t_hlt (void)
11100{
11101 do_t_bkpt_hlt1 (63);
11102}
11103
11104static void
11105do_t_bkpt (void)
11106{
11107 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11108}
11109
11110static void
c19d1205 11111do_t_branch23 (void)
b99bd4ef 11112{
e07e6e58 11113 set_it_insn_type_last ();
0855e32b 11114 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11115
0855e32b
NS
11116 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11117 this file. We used to simply ignore the PLT reloc type here --
11118 the branch encoding is now needed to deal with TLSCALL relocs.
11119 So if we see a PLT reloc now, put it back to how it used to be to
11120 keep the preexisting behaviour. */
11121 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11122 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11123
4343666d 11124#if defined(OBJ_COFF)
c19d1205
ZW
11125 /* If the destination of the branch is a defined symbol which does not have
11126 the THUMB_FUNC attribute, then we must be calling a function which has
11127 the (interfacearm) attribute. We look for the Thumb entry point to that
11128 function and change the branch to refer to that function instead. */
11129 if ( inst.reloc.exp.X_op == O_symbol
11130 && inst.reloc.exp.X_add_symbol != NULL
11131 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11132 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11133 inst.reloc.exp.X_add_symbol =
11134 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11135#endif
90e4755a
RE
11136}
11137
11138static void
c19d1205 11139do_t_bx (void)
90e4755a 11140{
e07e6e58 11141 set_it_insn_type_last ();
c19d1205
ZW
11142 inst.instruction |= inst.operands[0].reg << 3;
11143 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11144 should cause the alignment to be checked once it is known. This is
11145 because BX PC only works if the instruction is word aligned. */
11146}
90e4755a 11147
c19d1205
ZW
11148static void
11149do_t_bxj (void)
11150{
fdfde340 11151 int Rm;
90e4755a 11152
e07e6e58 11153 set_it_insn_type_last ();
fdfde340
JM
11154 Rm = inst.operands[0].reg;
11155 reject_bad_reg (Rm);
11156 inst.instruction |= Rm << 16;
90e4755a
RE
11157}
11158
11159static void
c19d1205 11160do_t_clz (void)
90e4755a 11161{
fdfde340
JM
11162 unsigned Rd;
11163 unsigned Rm;
11164
11165 Rd = inst.operands[0].reg;
11166 Rm = inst.operands[1].reg;
11167
11168 reject_bad_reg (Rd);
11169 reject_bad_reg (Rm);
11170
11171 inst.instruction |= Rd << 8;
11172 inst.instruction |= Rm << 16;
11173 inst.instruction |= Rm;
c19d1205 11174}
90e4755a 11175
dfa9f0d5
PB
11176static void
11177do_t_cps (void)
11178{
e07e6e58 11179 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11180 inst.instruction |= inst.operands[0].imm;
11181}
11182
c19d1205
ZW
11183static void
11184do_t_cpsi (void)
11185{
e07e6e58 11186 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11187 if (unified_syntax
62b3e311
PB
11188 && (inst.operands[1].present || inst.size_req == 4)
11189 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11190 {
c19d1205
ZW
11191 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11192 inst.instruction = 0xf3af8000;
11193 inst.instruction |= imod << 9;
11194 inst.instruction |= inst.operands[0].imm << 5;
11195 if (inst.operands[1].present)
11196 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11197 }
c19d1205 11198 else
90e4755a 11199 {
62b3e311
PB
11200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11201 && (inst.operands[0].imm & 4),
11202 _("selected processor does not support 'A' form "
11203 "of this instruction"));
11204 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11205 _("Thumb does not support the 2-argument "
11206 "form of this instruction"));
11207 inst.instruction |= inst.operands[0].imm;
90e4755a 11208 }
90e4755a
RE
11209}
11210
c19d1205
ZW
11211/* THUMB CPY instruction (argument parse). */
11212
90e4755a 11213static void
c19d1205 11214do_t_cpy (void)
90e4755a 11215{
c19d1205 11216 if (inst.size_req == 4)
90e4755a 11217 {
c19d1205
ZW
11218 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11219 inst.instruction |= inst.operands[0].reg << 8;
11220 inst.instruction |= inst.operands[1].reg;
90e4755a 11221 }
c19d1205 11222 else
90e4755a 11223 {
c19d1205
ZW
11224 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11225 inst.instruction |= (inst.operands[0].reg & 0x7);
11226 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11227 }
90e4755a
RE
11228}
11229
90e4755a 11230static void
25fe350b 11231do_t_cbz (void)
90e4755a 11232{
e07e6e58 11233 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11234 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11235 inst.instruction |= inst.operands[0].reg;
11236 inst.reloc.pc_rel = 1;
11237 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11238}
90e4755a 11239
62b3e311
PB
11240static void
11241do_t_dbg (void)
11242{
11243 inst.instruction |= inst.operands[0].imm;
11244}
11245
11246static void
11247do_t_div (void)
11248{
fdfde340
JM
11249 unsigned Rd, Rn, Rm;
11250
11251 Rd = inst.operands[0].reg;
11252 Rn = (inst.operands[1].present
11253 ? inst.operands[1].reg : Rd);
11254 Rm = inst.operands[2].reg;
11255
11256 reject_bad_reg (Rd);
11257 reject_bad_reg (Rn);
11258 reject_bad_reg (Rm);
11259
11260 inst.instruction |= Rd << 8;
11261 inst.instruction |= Rn << 16;
11262 inst.instruction |= Rm;
62b3e311
PB
11263}
11264
c19d1205
ZW
11265static void
11266do_t_hint (void)
11267{
11268 if (unified_syntax && inst.size_req == 4)
11269 inst.instruction = THUMB_OP32 (inst.instruction);
11270 else
11271 inst.instruction = THUMB_OP16 (inst.instruction);
11272}
90e4755a 11273
c19d1205
ZW
11274static void
11275do_t_it (void)
11276{
11277 unsigned int cond = inst.operands[0].imm;
e27ec89e 11278
e07e6e58
NC
11279 set_it_insn_type (IT_INSN);
11280 now_it.mask = (inst.instruction & 0xf) | 0x10;
11281 now_it.cc = cond;
5a01bb1d 11282 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11283
11284 /* If the condition is a negative condition, invert the mask. */
c19d1205 11285 if ((cond & 0x1) == 0x0)
90e4755a 11286 {
c19d1205 11287 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11288
c19d1205 11289 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11290 {
11291 /* No conversion needed. */
11292 now_it.block_length = 1;
11293 }
c19d1205 11294 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11295 {
11296 mask ^= 0x8;
11297 now_it.block_length = 2;
11298 }
e27ec89e 11299 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11300 {
11301 mask ^= 0xC;
11302 now_it.block_length = 3;
11303 }
c19d1205 11304 else
5a01bb1d
MGD
11305 {
11306 mask ^= 0xE;
11307 now_it.block_length = 4;
11308 }
90e4755a 11309
e27ec89e
PB
11310 inst.instruction &= 0xfff0;
11311 inst.instruction |= mask;
c19d1205 11312 }
90e4755a 11313
c19d1205
ZW
11314 inst.instruction |= cond << 4;
11315}
90e4755a 11316
3c707909
PB
11317/* Helper function used for both push/pop and ldm/stm. */
11318static void
11319encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11320{
11321 bfd_boolean load;
11322
11323 load = (inst.instruction & (1 << 20)) != 0;
11324
11325 if (mask & (1 << 13))
11326 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11327
11328 if ((mask & (1 << base)) != 0
11329 && writeback)
11330 inst.error = _("having the base register in the register list when "
11331 "using write back is UNPREDICTABLE");
11332
3c707909
PB
11333 if (load)
11334 {
e07e6e58 11335 if (mask & (1 << 15))
477330fc
RM
11336 {
11337 if (mask & (1 << 14))
11338 inst.error = _("LR and PC should not both be in register list");
11339 else
11340 set_it_insn_type_last ();
11341 }
3c707909
PB
11342 }
11343 else
11344 {
11345 if (mask & (1 << 15))
11346 inst.error = _("PC not allowed in register list");
3c707909
PB
11347 }
11348
11349 if ((mask & (mask - 1)) == 0)
11350 {
11351 /* Single register transfers implemented as str/ldr. */
11352 if (writeback)
11353 {
11354 if (inst.instruction & (1 << 23))
11355 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11356 else
11357 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11358 }
11359 else
11360 {
11361 if (inst.instruction & (1 << 23))
11362 inst.instruction = 0x00800000; /* ia -> [base] */
11363 else
11364 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11365 }
11366
11367 inst.instruction |= 0xf8400000;
11368 if (load)
11369 inst.instruction |= 0x00100000;
11370
5f4273c7 11371 mask = ffs (mask) - 1;
3c707909
PB
11372 mask <<= 12;
11373 }
11374 else if (writeback)
11375 inst.instruction |= WRITE_BACK;
11376
11377 inst.instruction |= mask;
11378 inst.instruction |= base << 16;
11379}
11380
c19d1205
ZW
11381static void
11382do_t_ldmstm (void)
11383{
11384 /* This really doesn't seem worth it. */
11385 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11386 _("expression too complex"));
11387 constraint (inst.operands[1].writeback,
11388 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11389
c19d1205
ZW
11390 if (unified_syntax)
11391 {
3c707909
PB
11392 bfd_boolean narrow;
11393 unsigned mask;
11394
11395 narrow = FALSE;
c19d1205
ZW
11396 /* See if we can use a 16-bit instruction. */
11397 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11398 && inst.size_req != 4
3c707909 11399 && !(inst.operands[1].imm & ~0xff))
90e4755a 11400 {
3c707909 11401 mask = 1 << inst.operands[0].reg;
90e4755a 11402
eab4f823 11403 if (inst.operands[0].reg <= 7)
90e4755a 11404 {
3c707909 11405 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11406 ? inst.operands[0].writeback
11407 : (inst.operands[0].writeback
11408 == !(inst.operands[1].imm & mask)))
477330fc 11409 {
eab4f823
MGD
11410 if (inst.instruction == T_MNEM_stmia
11411 && (inst.operands[1].imm & mask)
11412 && (inst.operands[1].imm & (mask - 1)))
11413 as_warn (_("value stored for r%d is UNKNOWN"),
11414 inst.operands[0].reg);
3c707909 11415
eab4f823
MGD
11416 inst.instruction = THUMB_OP16 (inst.instruction);
11417 inst.instruction |= inst.operands[0].reg << 8;
11418 inst.instruction |= inst.operands[1].imm;
11419 narrow = TRUE;
11420 }
11421 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11422 {
11423 /* This means 1 register in reg list one of 3 situations:
11424 1. Instruction is stmia, but without writeback.
11425 2. lmdia without writeback, but with Rn not in
477330fc 11426 reglist.
eab4f823
MGD
11427 3. ldmia with writeback, but with Rn in reglist.
11428 Case 3 is UNPREDICTABLE behaviour, so we handle
11429 case 1 and 2 which can be converted into a 16-bit
11430 str or ldr. The SP cases are handled below. */
11431 unsigned long opcode;
11432 /* First, record an error for Case 3. */
11433 if (inst.operands[1].imm & mask
11434 && inst.operands[0].writeback)
fa94de6b 11435 inst.error =
eab4f823
MGD
11436 _("having the base register in the register list when "
11437 "using write back is UNPREDICTABLE");
fa94de6b
RM
11438
11439 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11440 : T_MNEM_ldr);
11441 inst.instruction = THUMB_OP16 (opcode);
11442 inst.instruction |= inst.operands[0].reg << 3;
11443 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11444 narrow = TRUE;
11445 }
90e4755a 11446 }
eab4f823 11447 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11448 {
eab4f823
MGD
11449 if (inst.operands[0].writeback)
11450 {
fa94de6b 11451 inst.instruction =
eab4f823 11452 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11453 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11454 inst.instruction |= inst.operands[1].imm;
477330fc 11455 narrow = TRUE;
eab4f823
MGD
11456 }
11457 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11458 {
fa94de6b 11459 inst.instruction =
eab4f823 11460 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11461 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11462 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11463 narrow = TRUE;
eab4f823 11464 }
90e4755a 11465 }
3c707909
PB
11466 }
11467
11468 if (!narrow)
11469 {
c19d1205
ZW
11470 if (inst.instruction < 0xffff)
11471 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11472
5f4273c7
NC
11473 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11474 inst.operands[0].writeback);
90e4755a
RE
11475 }
11476 }
c19d1205 11477 else
90e4755a 11478 {
c19d1205
ZW
11479 constraint (inst.operands[0].reg > 7
11480 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11481 constraint (inst.instruction != T_MNEM_ldmia
11482 && inst.instruction != T_MNEM_stmia,
11483 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11484 if (inst.instruction == T_MNEM_stmia)
f03698e6 11485 {
c19d1205
ZW
11486 if (!inst.operands[0].writeback)
11487 as_warn (_("this instruction will write back the base register"));
11488 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11489 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11490 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11491 inst.operands[0].reg);
f03698e6 11492 }
c19d1205 11493 else
90e4755a 11494 {
c19d1205
ZW
11495 if (!inst.operands[0].writeback
11496 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11497 as_warn (_("this instruction will write back the base register"));
11498 else if (inst.operands[0].writeback
11499 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11500 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11501 }
11502
c19d1205
ZW
11503 inst.instruction = THUMB_OP16 (inst.instruction);
11504 inst.instruction |= inst.operands[0].reg << 8;
11505 inst.instruction |= inst.operands[1].imm;
11506 }
11507}
e28cd48c 11508
c19d1205
ZW
11509static void
11510do_t_ldrex (void)
11511{
11512 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11513 || inst.operands[1].postind || inst.operands[1].writeback
11514 || inst.operands[1].immisreg || inst.operands[1].shifted
11515 || inst.operands[1].negative,
01cfc07f 11516 BAD_ADDR_MODE);
e28cd48c 11517
5be8be5d
DG
11518 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11519
c19d1205
ZW
11520 inst.instruction |= inst.operands[0].reg << 12;
11521 inst.instruction |= inst.operands[1].reg << 16;
11522 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11523}
e28cd48c 11524
c19d1205
ZW
11525static void
11526do_t_ldrexd (void)
11527{
11528 if (!inst.operands[1].present)
1cac9012 11529 {
c19d1205
ZW
11530 constraint (inst.operands[0].reg == REG_LR,
11531 _("r14 not allowed as first register "
11532 "when second register is omitted"));
11533 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11534 }
c19d1205
ZW
11535 constraint (inst.operands[0].reg == inst.operands[1].reg,
11536 BAD_OVERLAP);
b99bd4ef 11537
c19d1205
ZW
11538 inst.instruction |= inst.operands[0].reg << 12;
11539 inst.instruction |= inst.operands[1].reg << 8;
11540 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11541}
11542
11543static void
c19d1205 11544do_t_ldst (void)
b99bd4ef 11545{
0110f2b8
PB
11546 unsigned long opcode;
11547 int Rn;
11548
e07e6e58
NC
11549 if (inst.operands[0].isreg
11550 && !inst.operands[0].preind
11551 && inst.operands[0].reg == REG_PC)
11552 set_it_insn_type_last ();
11553
0110f2b8 11554 opcode = inst.instruction;
c19d1205 11555 if (unified_syntax)
b99bd4ef 11556 {
53365c0d
PB
11557 if (!inst.operands[1].isreg)
11558 {
11559 if (opcode <= 0xffff)
11560 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11561 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11562 return;
11563 }
0110f2b8
PB
11564 if (inst.operands[1].isreg
11565 && !inst.operands[1].writeback
c19d1205
ZW
11566 && !inst.operands[1].shifted && !inst.operands[1].postind
11567 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11568 && opcode <= 0xffff
11569 && inst.size_req != 4)
c19d1205 11570 {
0110f2b8
PB
11571 /* Insn may have a 16-bit form. */
11572 Rn = inst.operands[1].reg;
11573 if (inst.operands[1].immisreg)
11574 {
11575 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11576 /* [Rn, Rik] */
0110f2b8
PB
11577 if (Rn <= 7 && inst.operands[1].imm <= 7)
11578 goto op16;
5be8be5d
DG
11579 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11580 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11581 }
11582 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11583 && opcode != T_MNEM_ldrsb)
11584 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11585 || (Rn == REG_SP && opcode == T_MNEM_str))
11586 {
11587 /* [Rn, #const] */
11588 if (Rn > 7)
11589 {
11590 if (Rn == REG_PC)
11591 {
11592 if (inst.reloc.pc_rel)
11593 opcode = T_MNEM_ldr_pc2;
11594 else
11595 opcode = T_MNEM_ldr_pc;
11596 }
11597 else
11598 {
11599 if (opcode == T_MNEM_ldr)
11600 opcode = T_MNEM_ldr_sp;
11601 else
11602 opcode = T_MNEM_str_sp;
11603 }
11604 inst.instruction = inst.operands[0].reg << 8;
11605 }
11606 else
11607 {
11608 inst.instruction = inst.operands[0].reg;
11609 inst.instruction |= inst.operands[1].reg << 3;
11610 }
11611 inst.instruction |= THUMB_OP16 (opcode);
11612 if (inst.size_req == 2)
11613 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11614 else
11615 inst.relax = opcode;
11616 return;
11617 }
c19d1205 11618 }
0110f2b8 11619 /* Definitely a 32-bit variant. */
5be8be5d 11620
8d67f500
NC
11621 /* Warning for Erratum 752419. */
11622 if (opcode == T_MNEM_ldr
11623 && inst.operands[0].reg == REG_SP
11624 && inst.operands[1].writeback == 1
11625 && !inst.operands[1].immisreg)
11626 {
11627 if (no_cpu_selected ()
11628 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11629 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11630 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11631 as_warn (_("This instruction may be unpredictable "
11632 "if executed on M-profile cores "
11633 "with interrupts enabled."));
11634 }
11635
5be8be5d 11636 /* Do some validations regarding addressing modes. */
1be5fd2e 11637 if (inst.operands[1].immisreg)
5be8be5d
DG
11638 reject_bad_reg (inst.operands[1].imm);
11639
1be5fd2e
NC
11640 constraint (inst.operands[1].writeback == 1
11641 && inst.operands[0].reg == inst.operands[1].reg,
11642 BAD_OVERLAP);
11643
0110f2b8 11644 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11645 inst.instruction |= inst.operands[0].reg << 12;
11646 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11647 check_ldr_r15_aligned ();
b99bd4ef
NC
11648 return;
11649 }
11650
c19d1205
ZW
11651 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11652
11653 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11654 {
c19d1205
ZW
11655 /* Only [Rn,Rm] is acceptable. */
11656 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11657 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11658 || inst.operands[1].postind || inst.operands[1].shifted
11659 || inst.operands[1].negative,
11660 _("Thumb does not support this addressing mode"));
11661 inst.instruction = THUMB_OP16 (inst.instruction);
11662 goto op16;
b99bd4ef 11663 }
5f4273c7 11664
c19d1205
ZW
11665 inst.instruction = THUMB_OP16 (inst.instruction);
11666 if (!inst.operands[1].isreg)
8335d6aa 11667 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11668 return;
b99bd4ef 11669
c19d1205
ZW
11670 constraint (!inst.operands[1].preind
11671 || inst.operands[1].shifted
11672 || inst.operands[1].writeback,
11673 _("Thumb does not support this addressing mode"));
11674 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11675 {
c19d1205
ZW
11676 constraint (inst.instruction & 0x0600,
11677 _("byte or halfword not valid for base register"));
11678 constraint (inst.operands[1].reg == REG_PC
11679 && !(inst.instruction & THUMB_LOAD_BIT),
11680 _("r15 based store not allowed"));
11681 constraint (inst.operands[1].immisreg,
11682 _("invalid base register for register offset"));
b99bd4ef 11683
c19d1205
ZW
11684 if (inst.operands[1].reg == REG_PC)
11685 inst.instruction = T_OPCODE_LDR_PC;
11686 else if (inst.instruction & THUMB_LOAD_BIT)
11687 inst.instruction = T_OPCODE_LDR_SP;
11688 else
11689 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11690
c19d1205
ZW
11691 inst.instruction |= inst.operands[0].reg << 8;
11692 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11693 return;
11694 }
90e4755a 11695
c19d1205
ZW
11696 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11697 if (!inst.operands[1].immisreg)
11698 {
11699 /* Immediate offset. */
11700 inst.instruction |= inst.operands[0].reg;
11701 inst.instruction |= inst.operands[1].reg << 3;
11702 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11703 return;
11704 }
90e4755a 11705
c19d1205
ZW
11706 /* Register offset. */
11707 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11708 constraint (inst.operands[1].negative,
11709 _("Thumb does not support this addressing mode"));
90e4755a 11710
c19d1205
ZW
11711 op16:
11712 switch (inst.instruction)
11713 {
11714 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11715 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11716 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11717 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11718 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11719 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11720 case 0x5600 /* ldrsb */:
11721 case 0x5e00 /* ldrsh */: break;
11722 default: abort ();
11723 }
90e4755a 11724
c19d1205
ZW
11725 inst.instruction |= inst.operands[0].reg;
11726 inst.instruction |= inst.operands[1].reg << 3;
11727 inst.instruction |= inst.operands[1].imm << 6;
11728}
90e4755a 11729
c19d1205
ZW
11730static void
11731do_t_ldstd (void)
11732{
11733 if (!inst.operands[1].present)
b99bd4ef 11734 {
c19d1205
ZW
11735 inst.operands[1].reg = inst.operands[0].reg + 1;
11736 constraint (inst.operands[0].reg == REG_LR,
11737 _("r14 not allowed here"));
bd340a04 11738 constraint (inst.operands[0].reg == REG_R12,
477330fc 11739 _("r12 not allowed here"));
b99bd4ef 11740 }
bd340a04
MGD
11741
11742 if (inst.operands[2].writeback
11743 && (inst.operands[0].reg == inst.operands[2].reg
11744 || inst.operands[1].reg == inst.operands[2].reg))
11745 as_warn (_("base register written back, and overlaps "
477330fc 11746 "one of transfer registers"));
bd340a04 11747
c19d1205
ZW
11748 inst.instruction |= inst.operands[0].reg << 12;
11749 inst.instruction |= inst.operands[1].reg << 8;
11750 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11751}
11752
c19d1205
ZW
11753static void
11754do_t_ldstt (void)
11755{
11756 inst.instruction |= inst.operands[0].reg << 12;
11757 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11758}
a737bd4d 11759
b99bd4ef 11760static void
c19d1205 11761do_t_mla (void)
b99bd4ef 11762{
fdfde340 11763 unsigned Rd, Rn, Rm, Ra;
c921be7d 11764
fdfde340
JM
11765 Rd = inst.operands[0].reg;
11766 Rn = inst.operands[1].reg;
11767 Rm = inst.operands[2].reg;
11768 Ra = inst.operands[3].reg;
11769
11770 reject_bad_reg (Rd);
11771 reject_bad_reg (Rn);
11772 reject_bad_reg (Rm);
11773 reject_bad_reg (Ra);
11774
11775 inst.instruction |= Rd << 8;
11776 inst.instruction |= Rn << 16;
11777 inst.instruction |= Rm;
11778 inst.instruction |= Ra << 12;
c19d1205 11779}
b99bd4ef 11780
c19d1205
ZW
11781static void
11782do_t_mlal (void)
11783{
fdfde340
JM
11784 unsigned RdLo, RdHi, Rn, Rm;
11785
11786 RdLo = inst.operands[0].reg;
11787 RdHi = inst.operands[1].reg;
11788 Rn = inst.operands[2].reg;
11789 Rm = inst.operands[3].reg;
11790
11791 reject_bad_reg (RdLo);
11792 reject_bad_reg (RdHi);
11793 reject_bad_reg (Rn);
11794 reject_bad_reg (Rm);
11795
11796 inst.instruction |= RdLo << 12;
11797 inst.instruction |= RdHi << 8;
11798 inst.instruction |= Rn << 16;
11799 inst.instruction |= Rm;
c19d1205 11800}
b99bd4ef 11801
c19d1205
ZW
11802static void
11803do_t_mov_cmp (void)
11804{
fdfde340
JM
11805 unsigned Rn, Rm;
11806
11807 Rn = inst.operands[0].reg;
11808 Rm = inst.operands[1].reg;
11809
e07e6e58
NC
11810 if (Rn == REG_PC)
11811 set_it_insn_type_last ();
11812
c19d1205 11813 if (unified_syntax)
b99bd4ef 11814 {
c19d1205
ZW
11815 int r0off = (inst.instruction == T_MNEM_mov
11816 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11817 unsigned long opcode;
3d388997
PB
11818 bfd_boolean narrow;
11819 bfd_boolean low_regs;
11820
fdfde340 11821 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11822 opcode = inst.instruction;
e07e6e58 11823 if (in_it_block ())
0110f2b8 11824 narrow = opcode != T_MNEM_movs;
3d388997 11825 else
0110f2b8 11826 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11827 if (inst.size_req == 4
11828 || inst.operands[1].shifted)
11829 narrow = FALSE;
11830
efd81785
PB
11831 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11832 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11833 && !inst.operands[1].shifted
fdfde340
JM
11834 && Rn == REG_PC
11835 && Rm == REG_LR)
efd81785
PB
11836 {
11837 inst.instruction = T2_SUBS_PC_LR;
11838 return;
11839 }
11840
fdfde340
JM
11841 if (opcode == T_MNEM_cmp)
11842 {
11843 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11844 if (narrow)
11845 {
11846 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11847 but valid. */
11848 warn_deprecated_sp (Rm);
11849 /* R15 was documented as a valid choice for Rm in ARMv6,
11850 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11851 tools reject R15, so we do too. */
11852 constraint (Rm == REG_PC, BAD_PC);
11853 }
11854 else
11855 reject_bad_reg (Rm);
fdfde340
JM
11856 }
11857 else if (opcode == T_MNEM_mov
11858 || opcode == T_MNEM_movs)
11859 {
11860 if (inst.operands[1].isreg)
11861 {
11862 if (opcode == T_MNEM_movs)
11863 {
11864 reject_bad_reg (Rn);
11865 reject_bad_reg (Rm);
11866 }
76fa04a4
MGD
11867 else if (narrow)
11868 {
11869 /* This is mov.n. */
11870 if ((Rn == REG_SP || Rn == REG_PC)
11871 && (Rm == REG_SP || Rm == REG_PC))
11872 {
5c3696f8 11873 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11874 "deprecated when r%u is the destination "
11875 "register."), Rm, Rn);
11876 }
11877 }
11878 else
11879 {
11880 /* This is mov.w. */
11881 constraint (Rn == REG_PC, BAD_PC);
11882 constraint (Rm == REG_PC, BAD_PC);
11883 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11884 }
fdfde340
JM
11885 }
11886 else
11887 reject_bad_reg (Rn);
11888 }
11889
c19d1205
ZW
11890 if (!inst.operands[1].isreg)
11891 {
0110f2b8 11892 /* Immediate operand. */
e07e6e58 11893 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11894 narrow = 0;
11895 if (low_regs && narrow)
11896 {
11897 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11898 inst.instruction |= Rn << 8;
a9f02af8
MG
11899 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11900 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11901 {
a9f02af8 11902 if (inst.size_req == 2)
72d98d16 11903 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11904 else
11905 inst.relax = opcode;
72d98d16 11906 }
0110f2b8
PB
11907 }
11908 else
11909 {
a9f02af8
MG
11910 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11911 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11912 THUMB1_RELOC_ONLY);
11913
0110f2b8
PB
11914 inst.instruction = THUMB_OP32 (inst.instruction);
11915 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11916 inst.instruction |= Rn << r0off;
0110f2b8
PB
11917 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11918 }
c19d1205 11919 }
728ca7c9
PB
11920 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11921 && (inst.instruction == T_MNEM_mov
11922 || inst.instruction == T_MNEM_movs))
11923 {
11924 /* Register shifts are encoded as separate shift instructions. */
11925 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11926
e07e6e58 11927 if (in_it_block ())
728ca7c9
PB
11928 narrow = !flags;
11929 else
11930 narrow = flags;
11931
11932 if (inst.size_req == 4)
11933 narrow = FALSE;
11934
11935 if (!low_regs || inst.operands[1].imm > 7)
11936 narrow = FALSE;
11937
fdfde340 11938 if (Rn != Rm)
728ca7c9
PB
11939 narrow = FALSE;
11940
11941 switch (inst.operands[1].shift_kind)
11942 {
11943 case SHIFT_LSL:
11944 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11945 break;
11946 case SHIFT_ASR:
11947 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11948 break;
11949 case SHIFT_LSR:
11950 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11951 break;
11952 case SHIFT_ROR:
11953 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11954 break;
11955 default:
5f4273c7 11956 abort ();
728ca7c9
PB
11957 }
11958
11959 inst.instruction = opcode;
11960 if (narrow)
11961 {
fdfde340 11962 inst.instruction |= Rn;
728ca7c9
PB
11963 inst.instruction |= inst.operands[1].imm << 3;
11964 }
11965 else
11966 {
11967 if (flags)
11968 inst.instruction |= CONDS_BIT;
11969
fdfde340
JM
11970 inst.instruction |= Rn << 8;
11971 inst.instruction |= Rm << 16;
728ca7c9
PB
11972 inst.instruction |= inst.operands[1].imm;
11973 }
11974 }
3d388997 11975 else if (!narrow)
c19d1205 11976 {
728ca7c9
PB
11977 /* Some mov with immediate shift have narrow variants.
11978 Register shifts are handled above. */
11979 if (low_regs && inst.operands[1].shifted
11980 && (inst.instruction == T_MNEM_mov
11981 || inst.instruction == T_MNEM_movs))
11982 {
e07e6e58 11983 if (in_it_block ())
728ca7c9
PB
11984 narrow = (inst.instruction == T_MNEM_mov);
11985 else
11986 narrow = (inst.instruction == T_MNEM_movs);
11987 }
11988
11989 if (narrow)
11990 {
11991 switch (inst.operands[1].shift_kind)
11992 {
11993 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11994 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11995 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11996 default: narrow = FALSE; break;
11997 }
11998 }
11999
12000 if (narrow)
12001 {
fdfde340
JM
12002 inst.instruction |= Rn;
12003 inst.instruction |= Rm << 3;
728ca7c9
PB
12004 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12005 }
12006 else
12007 {
12008 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12009 inst.instruction |= Rn << r0off;
728ca7c9
PB
12010 encode_thumb32_shifted_operand (1);
12011 }
c19d1205
ZW
12012 }
12013 else
12014 switch (inst.instruction)
12015 {
12016 case T_MNEM_mov:
837b3435 12017 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12018 results. Don't allow this. */
12019 if (low_regs)
12020 {
12021 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12022 "MOV Rd, Rs with two low registers is not "
12023 "permitted on this architecture");
fa94de6b 12024 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12025 arm_ext_v6);
12026 }
12027
c19d1205 12028 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12029 inst.instruction |= (Rn & 0x8) << 4;
12030 inst.instruction |= (Rn & 0x7);
12031 inst.instruction |= Rm << 3;
c19d1205 12032 break;
b99bd4ef 12033
c19d1205
ZW
12034 case T_MNEM_movs:
12035 /* We know we have low registers at this point.
941a8a52
MGD
12036 Generate LSLS Rd, Rs, #0. */
12037 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12038 inst.instruction |= Rn;
12039 inst.instruction |= Rm << 3;
c19d1205
ZW
12040 break;
12041
12042 case T_MNEM_cmp:
3d388997 12043 if (low_regs)
c19d1205
ZW
12044 {
12045 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12046 inst.instruction |= Rn;
12047 inst.instruction |= Rm << 3;
c19d1205
ZW
12048 }
12049 else
12050 {
12051 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12052 inst.instruction |= (Rn & 0x8) << 4;
12053 inst.instruction |= (Rn & 0x7);
12054 inst.instruction |= Rm << 3;
c19d1205
ZW
12055 }
12056 break;
12057 }
b99bd4ef
NC
12058 return;
12059 }
12060
c19d1205 12061 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12062
12063 /* PR 10443: Do not silently ignore shifted operands. */
12064 constraint (inst.operands[1].shifted,
12065 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12066
c19d1205 12067 if (inst.operands[1].isreg)
b99bd4ef 12068 {
fdfde340 12069 if (Rn < 8 && Rm < 8)
b99bd4ef 12070 {
c19d1205
ZW
12071 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12072 since a MOV instruction produces unpredictable results. */
12073 if (inst.instruction == T_OPCODE_MOV_I8)
12074 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12075 else
c19d1205 12076 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12077
fdfde340
JM
12078 inst.instruction |= Rn;
12079 inst.instruction |= Rm << 3;
b99bd4ef
NC
12080 }
12081 else
12082 {
c19d1205
ZW
12083 if (inst.instruction == T_OPCODE_MOV_I8)
12084 inst.instruction = T_OPCODE_MOV_HR;
12085 else
12086 inst.instruction = T_OPCODE_CMP_HR;
12087 do_t_cpy ();
b99bd4ef
NC
12088 }
12089 }
c19d1205 12090 else
b99bd4ef 12091 {
fdfde340 12092 constraint (Rn > 7,
c19d1205 12093 _("only lo regs allowed with immediate"));
fdfde340 12094 inst.instruction |= Rn << 8;
c19d1205
ZW
12095 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12096 }
12097}
b99bd4ef 12098
c19d1205
ZW
12099static void
12100do_t_mov16 (void)
12101{
fdfde340 12102 unsigned Rd;
b6895b4f
PB
12103 bfd_vma imm;
12104 bfd_boolean top;
12105
12106 top = (inst.instruction & 0x00800000) != 0;
12107 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12108 {
12109 constraint (top, _(":lower16: not allowed this instruction"));
12110 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12111 }
12112 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12113 {
12114 constraint (!top, _(":upper16: not allowed this instruction"));
12115 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12116 }
12117
fdfde340
JM
12118 Rd = inst.operands[0].reg;
12119 reject_bad_reg (Rd);
12120
12121 inst.instruction |= Rd << 8;
b6895b4f
PB
12122 if (inst.reloc.type == BFD_RELOC_UNUSED)
12123 {
12124 imm = inst.reloc.exp.X_add_number;
12125 inst.instruction |= (imm & 0xf000) << 4;
12126 inst.instruction |= (imm & 0x0800) << 15;
12127 inst.instruction |= (imm & 0x0700) << 4;
12128 inst.instruction |= (imm & 0x00ff);
12129 }
c19d1205 12130}
b99bd4ef 12131
c19d1205
ZW
12132static void
12133do_t_mvn_tst (void)
12134{
fdfde340 12135 unsigned Rn, Rm;
c921be7d 12136
fdfde340
JM
12137 Rn = inst.operands[0].reg;
12138 Rm = inst.operands[1].reg;
12139
12140 if (inst.instruction == T_MNEM_cmp
12141 || inst.instruction == T_MNEM_cmn)
12142 constraint (Rn == REG_PC, BAD_PC);
12143 else
12144 reject_bad_reg (Rn);
12145 reject_bad_reg (Rm);
12146
c19d1205
ZW
12147 if (unified_syntax)
12148 {
12149 int r0off = (inst.instruction == T_MNEM_mvn
12150 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12151 bfd_boolean narrow;
12152
12153 if (inst.size_req == 4
12154 || inst.instruction > 0xffff
12155 || inst.operands[1].shifted
fdfde340 12156 || Rn > 7 || Rm > 7)
3d388997 12157 narrow = FALSE;
fe8b4cc3
KT
12158 else if (inst.instruction == T_MNEM_cmn
12159 || inst.instruction == T_MNEM_tst)
3d388997
PB
12160 narrow = TRUE;
12161 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12162 narrow = !in_it_block ();
3d388997 12163 else
e07e6e58 12164 narrow = in_it_block ();
3d388997 12165
c19d1205 12166 if (!inst.operands[1].isreg)
b99bd4ef 12167 {
c19d1205
ZW
12168 /* For an immediate, we always generate a 32-bit opcode;
12169 section relaxation will shrink it later if possible. */
12170 if (inst.instruction < 0xffff)
12171 inst.instruction = THUMB_OP32 (inst.instruction);
12172 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12173 inst.instruction |= Rn << r0off;
c19d1205 12174 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12175 }
c19d1205 12176 else
b99bd4ef 12177 {
c19d1205 12178 /* See if we can do this with a 16-bit instruction. */
3d388997 12179 if (narrow)
b99bd4ef 12180 {
c19d1205 12181 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12182 inst.instruction |= Rn;
12183 inst.instruction |= Rm << 3;
b99bd4ef 12184 }
c19d1205 12185 else
b99bd4ef 12186 {
c19d1205
ZW
12187 constraint (inst.operands[1].shifted
12188 && inst.operands[1].immisreg,
12189 _("shift must be constant"));
12190 if (inst.instruction < 0xffff)
12191 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12192 inst.instruction |= Rn << r0off;
c19d1205 12193 encode_thumb32_shifted_operand (1);
b99bd4ef 12194 }
b99bd4ef
NC
12195 }
12196 }
12197 else
12198 {
c19d1205
ZW
12199 constraint (inst.instruction > 0xffff
12200 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12201 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12202 _("unshifted register required"));
fdfde340 12203 constraint (Rn > 7 || Rm > 7,
c19d1205 12204 BAD_HIREG);
b99bd4ef 12205
c19d1205 12206 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12207 inst.instruction |= Rn;
12208 inst.instruction |= Rm << 3;
b99bd4ef 12209 }
b99bd4ef
NC
12210}
12211
b05fe5cf 12212static void
c19d1205 12213do_t_mrs (void)
b05fe5cf 12214{
fdfde340 12215 unsigned Rd;
037e8744
JB
12216
12217 if (do_vfp_nsyn_mrs () == SUCCESS)
12218 return;
12219
90ec0d68
MGD
12220 Rd = inst.operands[0].reg;
12221 reject_bad_reg (Rd);
12222 inst.instruction |= Rd << 8;
12223
12224 if (inst.operands[1].isreg)
62b3e311 12225 {
90ec0d68
MGD
12226 unsigned br = inst.operands[1].reg;
12227 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12228 as_bad (_("bad register for mrs"));
12229
12230 inst.instruction |= br & (0xf << 16);
12231 inst.instruction |= (br & 0x300) >> 4;
12232 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12233 }
12234 else
12235 {
90ec0d68 12236 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12237
d2cd1205 12238 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12239 {
12240 /* PR gas/12698: The constraint is only applied for m_profile.
12241 If the user has specified -march=all, we want to ignore it as
12242 we are building for any CPU type, including non-m variants. */
823d2571
TG
12243 bfd_boolean m_profile =
12244 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12245 constraint ((flags != 0) && m_profile, _("selected processor does "
12246 "not support requested special purpose register"));
12247 }
90ec0d68 12248 else
d2cd1205
JB
12249 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12250 devices). */
12251 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12252 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12253
90ec0d68
MGD
12254 inst.instruction |= (flags & SPSR_BIT) >> 2;
12255 inst.instruction |= inst.operands[1].imm & 0xff;
12256 inst.instruction |= 0xf0000;
12257 }
c19d1205 12258}
b05fe5cf 12259
c19d1205
ZW
12260static void
12261do_t_msr (void)
12262{
62b3e311 12263 int flags;
fdfde340 12264 unsigned Rn;
62b3e311 12265
037e8744
JB
12266 if (do_vfp_nsyn_msr () == SUCCESS)
12267 return;
12268
c19d1205
ZW
12269 constraint (!inst.operands[1].isreg,
12270 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12271
12272 if (inst.operands[0].isreg)
12273 flags = (int)(inst.operands[0].reg);
12274 else
12275 flags = inst.operands[0].imm;
12276
d2cd1205 12277 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12278 {
d2cd1205
JB
12279 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12280
1a43faaf 12281 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12282 If the user has specified -march=all, we want to ignore it as
12283 we are building for any CPU type, including non-m variants. */
823d2571
TG
12284 bfd_boolean m_profile =
12285 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12286 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12287 && (bits & ~(PSR_s | PSR_f)) != 0)
12288 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12289 && bits != PSR_f)) && m_profile,
12290 _("selected processor does not support requested special "
12291 "purpose register"));
62b3e311
PB
12292 }
12293 else
d2cd1205
JB
12294 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12295 "requested special purpose register"));
c921be7d 12296
fdfde340
JM
12297 Rn = inst.operands[1].reg;
12298 reject_bad_reg (Rn);
12299
62b3e311 12300 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12301 inst.instruction |= (flags & 0xf0000) >> 8;
12302 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12303 inst.instruction |= (flags & 0xff);
fdfde340 12304 inst.instruction |= Rn << 16;
c19d1205 12305}
b05fe5cf 12306
c19d1205
ZW
12307static void
12308do_t_mul (void)
12309{
17828f45 12310 bfd_boolean narrow;
fdfde340 12311 unsigned Rd, Rn, Rm;
17828f45 12312
c19d1205
ZW
12313 if (!inst.operands[2].present)
12314 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12315
fdfde340
JM
12316 Rd = inst.operands[0].reg;
12317 Rn = inst.operands[1].reg;
12318 Rm = inst.operands[2].reg;
12319
17828f45 12320 if (unified_syntax)
b05fe5cf 12321 {
17828f45 12322 if (inst.size_req == 4
fdfde340
JM
12323 || (Rd != Rn
12324 && Rd != Rm)
12325 || Rn > 7
12326 || Rm > 7)
17828f45
JM
12327 narrow = FALSE;
12328 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12329 narrow = !in_it_block ();
17828f45 12330 else
e07e6e58 12331 narrow = in_it_block ();
b05fe5cf 12332 }
c19d1205 12333 else
b05fe5cf 12334 {
17828f45 12335 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12336 constraint (Rn > 7 || Rm > 7,
c19d1205 12337 BAD_HIREG);
17828f45
JM
12338 narrow = TRUE;
12339 }
b05fe5cf 12340
17828f45
JM
12341 if (narrow)
12342 {
12343 /* 16-bit MULS/Conditional MUL. */
c19d1205 12344 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12345 inst.instruction |= Rd;
b05fe5cf 12346
fdfde340
JM
12347 if (Rd == Rn)
12348 inst.instruction |= Rm << 3;
12349 else if (Rd == Rm)
12350 inst.instruction |= Rn << 3;
c19d1205
ZW
12351 else
12352 constraint (1, _("dest must overlap one source register"));
12353 }
17828f45
JM
12354 else
12355 {
e07e6e58
NC
12356 constraint (inst.instruction != T_MNEM_mul,
12357 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12358 /* 32-bit MUL. */
12359 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12360 inst.instruction |= Rd << 8;
12361 inst.instruction |= Rn << 16;
12362 inst.instruction |= Rm << 0;
12363
12364 reject_bad_reg (Rd);
12365 reject_bad_reg (Rn);
12366 reject_bad_reg (Rm);
17828f45 12367 }
c19d1205 12368}
b05fe5cf 12369
c19d1205
ZW
12370static void
12371do_t_mull (void)
12372{
fdfde340 12373 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12374
fdfde340
JM
12375 RdLo = inst.operands[0].reg;
12376 RdHi = inst.operands[1].reg;
12377 Rn = inst.operands[2].reg;
12378 Rm = inst.operands[3].reg;
12379
12380 reject_bad_reg (RdLo);
12381 reject_bad_reg (RdHi);
12382 reject_bad_reg (Rn);
12383 reject_bad_reg (Rm);
12384
12385 inst.instruction |= RdLo << 12;
12386 inst.instruction |= RdHi << 8;
12387 inst.instruction |= Rn << 16;
12388 inst.instruction |= Rm;
12389
12390 if (RdLo == RdHi)
c19d1205
ZW
12391 as_tsktsk (_("rdhi and rdlo must be different"));
12392}
b05fe5cf 12393
c19d1205
ZW
12394static void
12395do_t_nop (void)
12396{
e07e6e58
NC
12397 set_it_insn_type (NEUTRAL_IT_INSN);
12398
c19d1205
ZW
12399 if (unified_syntax)
12400 {
12401 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12402 {
c19d1205
ZW
12403 inst.instruction = THUMB_OP32 (inst.instruction);
12404 inst.instruction |= inst.operands[0].imm;
12405 }
12406 else
12407 {
bc2d1808
NC
12408 /* PR9722: Check for Thumb2 availability before
12409 generating a thumb2 nop instruction. */
afa62d5e 12410 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12411 {
12412 inst.instruction = THUMB_OP16 (inst.instruction);
12413 inst.instruction |= inst.operands[0].imm << 4;
12414 }
12415 else
12416 inst.instruction = 0x46c0;
c19d1205
ZW
12417 }
12418 }
12419 else
12420 {
12421 constraint (inst.operands[0].present,
12422 _("Thumb does not support NOP with hints"));
12423 inst.instruction = 0x46c0;
12424 }
12425}
b05fe5cf 12426
c19d1205
ZW
12427static void
12428do_t_neg (void)
12429{
12430 if (unified_syntax)
12431 {
3d388997
PB
12432 bfd_boolean narrow;
12433
12434 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12435 narrow = !in_it_block ();
3d388997 12436 else
e07e6e58 12437 narrow = in_it_block ();
3d388997
PB
12438 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12439 narrow = FALSE;
12440 if (inst.size_req == 4)
12441 narrow = FALSE;
12442
12443 if (!narrow)
c19d1205
ZW
12444 {
12445 inst.instruction = THUMB_OP32 (inst.instruction);
12446 inst.instruction |= inst.operands[0].reg << 8;
12447 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12448 }
12449 else
12450 {
c19d1205
ZW
12451 inst.instruction = THUMB_OP16 (inst.instruction);
12452 inst.instruction |= inst.operands[0].reg;
12453 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12454 }
12455 }
12456 else
12457 {
c19d1205
ZW
12458 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12459 BAD_HIREG);
12460 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12461
12462 inst.instruction = THUMB_OP16 (inst.instruction);
12463 inst.instruction |= inst.operands[0].reg;
12464 inst.instruction |= inst.operands[1].reg << 3;
12465 }
12466}
12467
1c444d06
JM
12468static void
12469do_t_orn (void)
12470{
12471 unsigned Rd, Rn;
12472
12473 Rd = inst.operands[0].reg;
12474 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12475
fdfde340
JM
12476 reject_bad_reg (Rd);
12477 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12478 reject_bad_reg (Rn);
12479
1c444d06
JM
12480 inst.instruction |= Rd << 8;
12481 inst.instruction |= Rn << 16;
12482
12483 if (!inst.operands[2].isreg)
12484 {
12485 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12486 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12487 }
12488 else
12489 {
12490 unsigned Rm;
12491
12492 Rm = inst.operands[2].reg;
fdfde340 12493 reject_bad_reg (Rm);
1c444d06
JM
12494
12495 constraint (inst.operands[2].shifted
12496 && inst.operands[2].immisreg,
12497 _("shift must be constant"));
12498 encode_thumb32_shifted_operand (2);
12499 }
12500}
12501
c19d1205
ZW
12502static void
12503do_t_pkhbt (void)
12504{
fdfde340
JM
12505 unsigned Rd, Rn, Rm;
12506
12507 Rd = inst.operands[0].reg;
12508 Rn = inst.operands[1].reg;
12509 Rm = inst.operands[2].reg;
12510
12511 reject_bad_reg (Rd);
12512 reject_bad_reg (Rn);
12513 reject_bad_reg (Rm);
12514
12515 inst.instruction |= Rd << 8;
12516 inst.instruction |= Rn << 16;
12517 inst.instruction |= Rm;
c19d1205
ZW
12518 if (inst.operands[3].present)
12519 {
12520 unsigned int val = inst.reloc.exp.X_add_number;
12521 constraint (inst.reloc.exp.X_op != O_constant,
12522 _("expression too complex"));
12523 inst.instruction |= (val & 0x1c) << 10;
12524 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12525 }
c19d1205 12526}
b05fe5cf 12527
c19d1205
ZW
12528static void
12529do_t_pkhtb (void)
12530{
12531 if (!inst.operands[3].present)
1ef52f49
NC
12532 {
12533 unsigned Rtmp;
12534
12535 inst.instruction &= ~0x00000020;
12536
12537 /* PR 10168. Swap the Rm and Rn registers. */
12538 Rtmp = inst.operands[1].reg;
12539 inst.operands[1].reg = inst.operands[2].reg;
12540 inst.operands[2].reg = Rtmp;
12541 }
c19d1205 12542 do_t_pkhbt ();
b05fe5cf
ZW
12543}
12544
c19d1205
ZW
12545static void
12546do_t_pld (void)
12547{
fdfde340
JM
12548 if (inst.operands[0].immisreg)
12549 reject_bad_reg (inst.operands[0].imm);
12550
c19d1205
ZW
12551 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12552}
b05fe5cf 12553
c19d1205
ZW
12554static void
12555do_t_push_pop (void)
b99bd4ef 12556{
e9f89963 12557 unsigned mask;
5f4273c7 12558
c19d1205
ZW
12559 constraint (inst.operands[0].writeback,
12560 _("push/pop do not support {reglist}^"));
12561 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12562 _("expression too complex"));
b99bd4ef 12563
e9f89963 12564 mask = inst.operands[0].imm;
d3bfe16e 12565 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12566 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12567 else if (inst.size_req != 4
c6025a80 12568 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12569 ? REG_LR : REG_PC)))
b99bd4ef 12570 {
c19d1205
ZW
12571 inst.instruction = THUMB_OP16 (inst.instruction);
12572 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12573 inst.instruction |= mask & 0xff;
c19d1205
ZW
12574 }
12575 else if (unified_syntax)
12576 {
3c707909 12577 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12578 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12579 }
12580 else
12581 {
12582 inst.error = _("invalid register list to push/pop instruction");
12583 return;
12584 }
c19d1205 12585}
b99bd4ef 12586
c19d1205
ZW
12587static void
12588do_t_rbit (void)
12589{
fdfde340
JM
12590 unsigned Rd, Rm;
12591
12592 Rd = inst.operands[0].reg;
12593 Rm = inst.operands[1].reg;
12594
12595 reject_bad_reg (Rd);
12596 reject_bad_reg (Rm);
12597
12598 inst.instruction |= Rd << 8;
12599 inst.instruction |= Rm << 16;
12600 inst.instruction |= Rm;
c19d1205 12601}
b99bd4ef 12602
c19d1205
ZW
12603static void
12604do_t_rev (void)
12605{
fdfde340
JM
12606 unsigned Rd, Rm;
12607
12608 Rd = inst.operands[0].reg;
12609 Rm = inst.operands[1].reg;
12610
12611 reject_bad_reg (Rd);
12612 reject_bad_reg (Rm);
12613
12614 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12615 && inst.size_req != 4)
12616 {
12617 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12618 inst.instruction |= Rd;
12619 inst.instruction |= Rm << 3;
c19d1205
ZW
12620 }
12621 else if (unified_syntax)
12622 {
12623 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12624 inst.instruction |= Rd << 8;
12625 inst.instruction |= Rm << 16;
12626 inst.instruction |= Rm;
c19d1205
ZW
12627 }
12628 else
12629 inst.error = BAD_HIREG;
12630}
b99bd4ef 12631
1c444d06
JM
12632static void
12633do_t_rrx (void)
12634{
12635 unsigned Rd, Rm;
12636
12637 Rd = inst.operands[0].reg;
12638 Rm = inst.operands[1].reg;
12639
fdfde340
JM
12640 reject_bad_reg (Rd);
12641 reject_bad_reg (Rm);
c921be7d 12642
1c444d06
JM
12643 inst.instruction |= Rd << 8;
12644 inst.instruction |= Rm;
12645}
12646
c19d1205
ZW
12647static void
12648do_t_rsb (void)
12649{
fdfde340 12650 unsigned Rd, Rs;
b99bd4ef 12651
c19d1205
ZW
12652 Rd = inst.operands[0].reg;
12653 Rs = (inst.operands[1].present
12654 ? inst.operands[1].reg /* Rd, Rs, foo */
12655 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12656
fdfde340
JM
12657 reject_bad_reg (Rd);
12658 reject_bad_reg (Rs);
12659 if (inst.operands[2].isreg)
12660 reject_bad_reg (inst.operands[2].reg);
12661
c19d1205
ZW
12662 inst.instruction |= Rd << 8;
12663 inst.instruction |= Rs << 16;
12664 if (!inst.operands[2].isreg)
12665 {
026d3abb
PB
12666 bfd_boolean narrow;
12667
12668 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12669 narrow = !in_it_block ();
026d3abb 12670 else
e07e6e58 12671 narrow = in_it_block ();
026d3abb
PB
12672
12673 if (Rd > 7 || Rs > 7)
12674 narrow = FALSE;
12675
12676 if (inst.size_req == 4 || !unified_syntax)
12677 narrow = FALSE;
12678
12679 if (inst.reloc.exp.X_op != O_constant
12680 || inst.reloc.exp.X_add_number != 0)
12681 narrow = FALSE;
12682
12683 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12684 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12685 if (narrow)
12686 {
12687 inst.reloc.type = BFD_RELOC_UNUSED;
12688 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12689 inst.instruction |= Rs << 3;
12690 inst.instruction |= Rd;
12691 }
12692 else
12693 {
12694 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12695 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12696 }
c19d1205
ZW
12697 }
12698 else
12699 encode_thumb32_shifted_operand (2);
12700}
b99bd4ef 12701
c19d1205
ZW
12702static void
12703do_t_setend (void)
12704{
12e37cbc
MGD
12705 if (warn_on_deprecated
12706 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12707 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12708
e07e6e58 12709 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12710 if (inst.operands[0].imm)
12711 inst.instruction |= 0x8;
12712}
b99bd4ef 12713
c19d1205
ZW
12714static void
12715do_t_shift (void)
12716{
12717 if (!inst.operands[1].present)
12718 inst.operands[1].reg = inst.operands[0].reg;
12719
12720 if (unified_syntax)
12721 {
3d388997
PB
12722 bfd_boolean narrow;
12723 int shift_kind;
12724
12725 switch (inst.instruction)
12726 {
12727 case T_MNEM_asr:
12728 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12729 case T_MNEM_lsl:
12730 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12731 case T_MNEM_lsr:
12732 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12733 case T_MNEM_ror:
12734 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12735 default: abort ();
12736 }
12737
12738 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12739 narrow = !in_it_block ();
3d388997 12740 else
e07e6e58 12741 narrow = in_it_block ();
3d388997
PB
12742 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12743 narrow = FALSE;
12744 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12745 narrow = FALSE;
12746 if (inst.operands[2].isreg
12747 && (inst.operands[1].reg != inst.operands[0].reg
12748 || inst.operands[2].reg > 7))
12749 narrow = FALSE;
12750 if (inst.size_req == 4)
12751 narrow = FALSE;
12752
fdfde340
JM
12753 reject_bad_reg (inst.operands[0].reg);
12754 reject_bad_reg (inst.operands[1].reg);
c921be7d 12755
3d388997 12756 if (!narrow)
c19d1205
ZW
12757 {
12758 if (inst.operands[2].isreg)
b99bd4ef 12759 {
fdfde340 12760 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12761 inst.instruction = THUMB_OP32 (inst.instruction);
12762 inst.instruction |= inst.operands[0].reg << 8;
12763 inst.instruction |= inst.operands[1].reg << 16;
12764 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12765
12766 /* PR 12854: Error on extraneous shifts. */
12767 constraint (inst.operands[2].shifted,
12768 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12769 }
12770 else
12771 {
12772 inst.operands[1].shifted = 1;
3d388997 12773 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12774 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12775 ? T_MNEM_movs : T_MNEM_mov);
12776 inst.instruction |= inst.operands[0].reg << 8;
12777 encode_thumb32_shifted_operand (1);
12778 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12779 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12780 }
12781 }
12782 else
12783 {
c19d1205 12784 if (inst.operands[2].isreg)
b99bd4ef 12785 {
3d388997 12786 switch (shift_kind)
b99bd4ef 12787 {
3d388997
PB
12788 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12789 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12790 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12791 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12792 default: abort ();
b99bd4ef 12793 }
5f4273c7 12794
c19d1205
ZW
12795 inst.instruction |= inst.operands[0].reg;
12796 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12797
12798 /* PR 12854: Error on extraneous shifts. */
12799 constraint (inst.operands[2].shifted,
12800 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12801 }
12802 else
12803 {
3d388997 12804 switch (shift_kind)
b99bd4ef 12805 {
3d388997
PB
12806 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12807 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12808 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12809 default: abort ();
b99bd4ef 12810 }
c19d1205
ZW
12811 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12812 inst.instruction |= inst.operands[0].reg;
12813 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12814 }
12815 }
c19d1205
ZW
12816 }
12817 else
12818 {
12819 constraint (inst.operands[0].reg > 7
12820 || inst.operands[1].reg > 7, BAD_HIREG);
12821 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12822
c19d1205
ZW
12823 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12824 {
12825 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12826 constraint (inst.operands[0].reg != inst.operands[1].reg,
12827 _("source1 and dest must be same register"));
b99bd4ef 12828
c19d1205
ZW
12829 switch (inst.instruction)
12830 {
12831 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12832 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12833 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12834 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12835 default: abort ();
12836 }
5f4273c7 12837
c19d1205
ZW
12838 inst.instruction |= inst.operands[0].reg;
12839 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12840
12841 /* PR 12854: Error on extraneous shifts. */
12842 constraint (inst.operands[2].shifted,
12843 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12844 }
12845 else
b99bd4ef 12846 {
c19d1205
ZW
12847 switch (inst.instruction)
12848 {
12849 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12850 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12851 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12852 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12853 default: abort ();
12854 }
12855 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12856 inst.instruction |= inst.operands[0].reg;
12857 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12858 }
12859 }
b99bd4ef
NC
12860}
12861
12862static void
c19d1205 12863do_t_simd (void)
b99bd4ef 12864{
fdfde340
JM
12865 unsigned Rd, Rn, Rm;
12866
12867 Rd = inst.operands[0].reg;
12868 Rn = inst.operands[1].reg;
12869 Rm = inst.operands[2].reg;
12870
12871 reject_bad_reg (Rd);
12872 reject_bad_reg (Rn);
12873 reject_bad_reg (Rm);
12874
12875 inst.instruction |= Rd << 8;
12876 inst.instruction |= Rn << 16;
12877 inst.instruction |= Rm;
c19d1205 12878}
b99bd4ef 12879
03ee1b7f
NC
12880static void
12881do_t_simd2 (void)
12882{
12883 unsigned Rd, Rn, Rm;
12884
12885 Rd = inst.operands[0].reg;
12886 Rm = inst.operands[1].reg;
12887 Rn = inst.operands[2].reg;
12888
12889 reject_bad_reg (Rd);
12890 reject_bad_reg (Rn);
12891 reject_bad_reg (Rm);
12892
12893 inst.instruction |= Rd << 8;
12894 inst.instruction |= Rn << 16;
12895 inst.instruction |= Rm;
12896}
12897
c19d1205 12898static void
3eb17e6b 12899do_t_smc (void)
c19d1205
ZW
12900{
12901 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12902 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12903 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12904 constraint (inst.reloc.exp.X_op != O_constant,
12905 _("expression too complex"));
12906 inst.reloc.type = BFD_RELOC_UNUSED;
12907 inst.instruction |= (value & 0xf000) >> 12;
12908 inst.instruction |= (value & 0x0ff0);
12909 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12910 /* PR gas/15623: SMC instructions must be last in an IT block. */
12911 set_it_insn_type_last ();
c19d1205 12912}
b99bd4ef 12913
90ec0d68
MGD
12914static void
12915do_t_hvc (void)
12916{
12917 unsigned int value = inst.reloc.exp.X_add_number;
12918
12919 inst.reloc.type = BFD_RELOC_UNUSED;
12920 inst.instruction |= (value & 0x0fff);
12921 inst.instruction |= (value & 0xf000) << 4;
12922}
12923
c19d1205 12924static void
3a21c15a 12925do_t_ssat_usat (int bias)
c19d1205 12926{
fdfde340
JM
12927 unsigned Rd, Rn;
12928
12929 Rd = inst.operands[0].reg;
12930 Rn = inst.operands[2].reg;
12931
12932 reject_bad_reg (Rd);
12933 reject_bad_reg (Rn);
12934
12935 inst.instruction |= Rd << 8;
3a21c15a 12936 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12937 inst.instruction |= Rn << 16;
b99bd4ef 12938
c19d1205 12939 if (inst.operands[3].present)
b99bd4ef 12940 {
3a21c15a
NC
12941 offsetT shift_amount = inst.reloc.exp.X_add_number;
12942
12943 inst.reloc.type = BFD_RELOC_UNUSED;
12944
c19d1205
ZW
12945 constraint (inst.reloc.exp.X_op != O_constant,
12946 _("expression too complex"));
b99bd4ef 12947
3a21c15a 12948 if (shift_amount != 0)
6189168b 12949 {
3a21c15a
NC
12950 constraint (shift_amount > 31,
12951 _("shift expression is too large"));
12952
c19d1205 12953 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12954 inst.instruction |= 0x00200000; /* sh bit. */
12955
12956 inst.instruction |= (shift_amount & 0x1c) << 10;
12957 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12958 }
12959 }
b99bd4ef 12960}
c921be7d 12961
3a21c15a
NC
12962static void
12963do_t_ssat (void)
12964{
12965 do_t_ssat_usat (1);
12966}
b99bd4ef 12967
0dd132b6 12968static void
c19d1205 12969do_t_ssat16 (void)
0dd132b6 12970{
fdfde340
JM
12971 unsigned Rd, Rn;
12972
12973 Rd = inst.operands[0].reg;
12974 Rn = inst.operands[2].reg;
12975
12976 reject_bad_reg (Rd);
12977 reject_bad_reg (Rn);
12978
12979 inst.instruction |= Rd << 8;
c19d1205 12980 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12981 inst.instruction |= Rn << 16;
c19d1205 12982}
0dd132b6 12983
c19d1205
ZW
12984static void
12985do_t_strex (void)
12986{
12987 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12988 || inst.operands[2].postind || inst.operands[2].writeback
12989 || inst.operands[2].immisreg || inst.operands[2].shifted
12990 || inst.operands[2].negative,
01cfc07f 12991 BAD_ADDR_MODE);
0dd132b6 12992
5be8be5d
DG
12993 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12994
c19d1205
ZW
12995 inst.instruction |= inst.operands[0].reg << 8;
12996 inst.instruction |= inst.operands[1].reg << 12;
12997 inst.instruction |= inst.operands[2].reg << 16;
12998 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12999}
13000
b99bd4ef 13001static void
c19d1205 13002do_t_strexd (void)
b99bd4ef 13003{
c19d1205
ZW
13004 if (!inst.operands[2].present)
13005 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13006
c19d1205
ZW
13007 constraint (inst.operands[0].reg == inst.operands[1].reg
13008 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13009 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13010 BAD_OVERLAP);
b99bd4ef 13011
c19d1205
ZW
13012 inst.instruction |= inst.operands[0].reg;
13013 inst.instruction |= inst.operands[1].reg << 12;
13014 inst.instruction |= inst.operands[2].reg << 8;
13015 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13016}
13017
13018static void
c19d1205 13019do_t_sxtah (void)
b99bd4ef 13020{
fdfde340
JM
13021 unsigned Rd, Rn, Rm;
13022
13023 Rd = inst.operands[0].reg;
13024 Rn = inst.operands[1].reg;
13025 Rm = inst.operands[2].reg;
13026
13027 reject_bad_reg (Rd);
13028 reject_bad_reg (Rn);
13029 reject_bad_reg (Rm);
13030
13031 inst.instruction |= Rd << 8;
13032 inst.instruction |= Rn << 16;
13033 inst.instruction |= Rm;
c19d1205
ZW
13034 inst.instruction |= inst.operands[3].imm << 4;
13035}
b99bd4ef 13036
c19d1205
ZW
13037static void
13038do_t_sxth (void)
13039{
fdfde340
JM
13040 unsigned Rd, Rm;
13041
13042 Rd = inst.operands[0].reg;
13043 Rm = inst.operands[1].reg;
13044
13045 reject_bad_reg (Rd);
13046 reject_bad_reg (Rm);
c921be7d
NC
13047
13048 if (inst.instruction <= 0xffff
13049 && inst.size_req != 4
fdfde340 13050 && Rd <= 7 && Rm <= 7
c19d1205 13051 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13052 {
c19d1205 13053 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13054 inst.instruction |= Rd;
13055 inst.instruction |= Rm << 3;
b99bd4ef 13056 }
c19d1205 13057 else if (unified_syntax)
b99bd4ef 13058 {
c19d1205
ZW
13059 if (inst.instruction <= 0xffff)
13060 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13061 inst.instruction |= Rd << 8;
13062 inst.instruction |= Rm;
c19d1205 13063 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13064 }
c19d1205 13065 else
b99bd4ef 13066 {
c19d1205
ZW
13067 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13068 _("Thumb encoding does not support rotation"));
13069 constraint (1, BAD_HIREG);
b99bd4ef 13070 }
c19d1205 13071}
b99bd4ef 13072
c19d1205
ZW
13073static void
13074do_t_swi (void)
13075{
b2a5fbdc
MGD
13076 /* We have to do the following check manually as ARM_EXT_OS only applies
13077 to ARM_EXT_V6M. */
13078 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13079 {
ac7f631b
NC
13080 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13081 /* This only applies to the v6m howver, not later architectures. */
13082 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13083 as_bad (_("SVC is not permitted on this architecture"));
13084 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13085 }
13086
c19d1205
ZW
13087 inst.reloc.type = BFD_RELOC_ARM_SWI;
13088}
b99bd4ef 13089
92e90b6e
PB
13090static void
13091do_t_tb (void)
13092{
fdfde340 13093 unsigned Rn, Rm;
92e90b6e
PB
13094 int half;
13095
13096 half = (inst.instruction & 0x10) != 0;
e07e6e58 13097 set_it_insn_type_last ();
dfa9f0d5
PB
13098 constraint (inst.operands[0].immisreg,
13099 _("instruction requires register index"));
fdfde340
JM
13100
13101 Rn = inst.operands[0].reg;
13102 Rm = inst.operands[0].imm;
c921be7d 13103
fdfde340
JM
13104 constraint (Rn == REG_SP, BAD_SP);
13105 reject_bad_reg (Rm);
13106
92e90b6e
PB
13107 constraint (!half && inst.operands[0].shifted,
13108 _("instruction does not allow shifted index"));
fdfde340 13109 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13110}
13111
74db7efb
NC
13112static void
13113do_t_udf (void)
13114{
13115 if (!inst.operands[0].present)
13116 inst.operands[0].imm = 0;
13117
13118 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13119 {
13120 constraint (inst.size_req == 2,
13121 _("immediate value out of range"));
13122 inst.instruction = THUMB_OP32 (inst.instruction);
13123 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13124 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13125 }
13126 else
13127 {
13128 inst.instruction = THUMB_OP16 (inst.instruction);
13129 inst.instruction |= inst.operands[0].imm;
13130 }
13131
13132 set_it_insn_type (NEUTRAL_IT_INSN);
13133}
13134
13135
c19d1205
ZW
13136static void
13137do_t_usat (void)
13138{
3a21c15a 13139 do_t_ssat_usat (0);
b99bd4ef
NC
13140}
13141
13142static void
c19d1205 13143do_t_usat16 (void)
b99bd4ef 13144{
fdfde340
JM
13145 unsigned Rd, Rn;
13146
13147 Rd = inst.operands[0].reg;
13148 Rn = inst.operands[2].reg;
13149
13150 reject_bad_reg (Rd);
13151 reject_bad_reg (Rn);
13152
13153 inst.instruction |= Rd << 8;
c19d1205 13154 inst.instruction |= inst.operands[1].imm;
fdfde340 13155 inst.instruction |= Rn << 16;
b99bd4ef 13156}
c19d1205 13157
5287ad62 13158/* Neon instruction encoder helpers. */
5f4273c7 13159
5287ad62 13160/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13161
5287ad62
JB
13162/* An "invalid" code for the following tables. */
13163#define N_INV -1u
13164
13165struct neon_tab_entry
b99bd4ef 13166{
5287ad62
JB
13167 unsigned integer;
13168 unsigned float_or_poly;
13169 unsigned scalar_or_imm;
13170};
5f4273c7 13171
5287ad62
JB
13172/* Map overloaded Neon opcodes to their respective encodings. */
13173#define NEON_ENC_TAB \
13174 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13175 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13176 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13177 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13178 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13179 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13180 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13181 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13182 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13183 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13184 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13185 /* Register variants of the following two instructions are encoded as
e07e6e58 13186 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13187 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13188 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13189 X(vfma, N_INV, 0x0000c10, N_INV), \
13190 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13191 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13192 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13193 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13194 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13195 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13196 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13197 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13198 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13199 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13200 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13201 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13202 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13203 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13204 X(vshl, 0x0000400, N_INV, 0x0800510), \
13205 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13206 X(vand, 0x0000110, N_INV, 0x0800030), \
13207 X(vbic, 0x0100110, N_INV, 0x0800030), \
13208 X(veor, 0x1000110, N_INV, N_INV), \
13209 X(vorn, 0x0300110, N_INV, 0x0800010), \
13210 X(vorr, 0x0200110, N_INV, 0x0800010), \
13211 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13212 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13213 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13214 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13215 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13216 X(vst1, 0x0000000, 0x0800000, N_INV), \
13217 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13218 X(vst2, 0x0000100, 0x0800100, N_INV), \
13219 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13220 X(vst3, 0x0000200, 0x0800200, N_INV), \
13221 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13222 X(vst4, 0x0000300, 0x0800300, N_INV), \
13223 X(vmovn, 0x1b20200, N_INV, N_INV), \
13224 X(vtrn, 0x1b20080, N_INV, N_INV), \
13225 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13226 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13227 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13228 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13229 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13230 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13231 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13232 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13233 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13234 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13235 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13236 X(vseleq, 0xe000a00, N_INV, N_INV), \
13237 X(vselvs, 0xe100a00, N_INV, N_INV), \
13238 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13239 X(vselgt, 0xe300a00, N_INV, N_INV), \
13240 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13241 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13242 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13243 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13244 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13245 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13246 X(sha3op, 0x2000c00, N_INV, N_INV), \
13247 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13248 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13249
13250enum neon_opc
13251{
13252#define X(OPC,I,F,S) N_MNEM_##OPC
13253NEON_ENC_TAB
13254#undef X
13255};
b99bd4ef 13256
5287ad62
JB
13257static const struct neon_tab_entry neon_enc_tab[] =
13258{
13259#define X(OPC,I,F,S) { (I), (F), (S) }
13260NEON_ENC_TAB
13261#undef X
13262};
b99bd4ef 13263
88714cb8
DG
13264/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13265#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13266#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13267#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13268#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13269#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13270#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13271#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13272#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13273#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13274#define NEON_ENC_SINGLE_(X) \
037e8744 13275 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13276#define NEON_ENC_DOUBLE_(X) \
037e8744 13277 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13278#define NEON_ENC_FPV8_(X) \
13279 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13280
88714cb8
DG
13281#define NEON_ENCODE(type, inst) \
13282 do \
13283 { \
13284 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13285 inst.is_neon = 1; \
13286 } \
13287 while (0)
13288
13289#define check_neon_suffixes \
13290 do \
13291 { \
13292 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13293 { \
13294 as_bad (_("invalid neon suffix for non neon instruction")); \
13295 return; \
13296 } \
13297 } \
13298 while (0)
13299
037e8744
JB
13300/* Define shapes for instruction operands. The following mnemonic characters
13301 are used in this table:
5287ad62 13302
037e8744 13303 F - VFP S<n> register
5287ad62
JB
13304 D - Neon D<n> register
13305 Q - Neon Q<n> register
13306 I - Immediate
13307 S - Scalar
13308 R - ARM register
13309 L - D<n> register list
5f4273c7 13310
037e8744
JB
13311 This table is used to generate various data:
13312 - enumerations of the form NS_DDR to be used as arguments to
13313 neon_select_shape.
13314 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13315 - a table used to drive neon_select_shape. */
b99bd4ef 13316
037e8744
JB
13317#define NEON_SHAPE_DEF \
13318 X(3, (D, D, D), DOUBLE), \
13319 X(3, (Q, Q, Q), QUAD), \
13320 X(3, (D, D, I), DOUBLE), \
13321 X(3, (Q, Q, I), QUAD), \
13322 X(3, (D, D, S), DOUBLE), \
13323 X(3, (Q, Q, S), QUAD), \
13324 X(2, (D, D), DOUBLE), \
13325 X(2, (Q, Q), QUAD), \
13326 X(2, (D, S), DOUBLE), \
13327 X(2, (Q, S), QUAD), \
13328 X(2, (D, R), DOUBLE), \
13329 X(2, (Q, R), QUAD), \
13330 X(2, (D, I), DOUBLE), \
13331 X(2, (Q, I), QUAD), \
13332 X(3, (D, L, D), DOUBLE), \
13333 X(2, (D, Q), MIXED), \
13334 X(2, (Q, D), MIXED), \
13335 X(3, (D, Q, I), MIXED), \
13336 X(3, (Q, D, I), MIXED), \
13337 X(3, (Q, D, D), MIXED), \
13338 X(3, (D, Q, Q), MIXED), \
13339 X(3, (Q, Q, D), MIXED), \
13340 X(3, (Q, D, S), MIXED), \
13341 X(3, (D, Q, S), MIXED), \
13342 X(4, (D, D, D, I), DOUBLE), \
13343 X(4, (Q, Q, Q, I), QUAD), \
13344 X(2, (F, F), SINGLE), \
13345 X(3, (F, F, F), SINGLE), \
13346 X(2, (F, I), SINGLE), \
13347 X(2, (F, D), MIXED), \
13348 X(2, (D, F), MIXED), \
13349 X(3, (F, F, I), MIXED), \
13350 X(4, (R, R, F, F), SINGLE), \
13351 X(4, (F, F, R, R), SINGLE), \
13352 X(3, (D, R, R), DOUBLE), \
13353 X(3, (R, R, D), DOUBLE), \
13354 X(2, (S, R), SINGLE), \
13355 X(2, (R, S), SINGLE), \
13356 X(2, (F, R), SINGLE), \
d54af2d0
RL
13357 X(2, (R, F), SINGLE), \
13358/* Half float shape supported so far. */\
13359 X (2, (H, D), MIXED), \
13360 X (2, (D, H), MIXED), \
13361 X (2, (H, F), MIXED), \
13362 X (2, (F, H), MIXED), \
13363 X (2, (H, H), HALF), \
13364 X (2, (H, R), HALF), \
13365 X (2, (R, H), HALF), \
13366 X (2, (H, I), HALF), \
13367 X (3, (H, H, H), HALF), \
13368 X (3, (H, F, I), MIXED), \
13369 X (3, (F, H, I), MIXED)
037e8744
JB
13370
13371#define S2(A,B) NS_##A##B
13372#define S3(A,B,C) NS_##A##B##C
13373#define S4(A,B,C,D) NS_##A##B##C##D
13374
13375#define X(N, L, C) S##N L
13376
5287ad62
JB
13377enum neon_shape
13378{
037e8744
JB
13379 NEON_SHAPE_DEF,
13380 NS_NULL
5287ad62 13381};
b99bd4ef 13382
037e8744
JB
13383#undef X
13384#undef S2
13385#undef S3
13386#undef S4
13387
13388enum neon_shape_class
13389{
d54af2d0 13390 SC_HALF,
037e8744
JB
13391 SC_SINGLE,
13392 SC_DOUBLE,
13393 SC_QUAD,
13394 SC_MIXED
13395};
13396
13397#define X(N, L, C) SC_##C
13398
13399static enum neon_shape_class neon_shape_class[] =
13400{
13401 NEON_SHAPE_DEF
13402};
13403
13404#undef X
13405
13406enum neon_shape_el
13407{
d54af2d0 13408 SE_H,
037e8744
JB
13409 SE_F,
13410 SE_D,
13411 SE_Q,
13412 SE_I,
13413 SE_S,
13414 SE_R,
13415 SE_L
13416};
13417
13418/* Register widths of above. */
13419static unsigned neon_shape_el_size[] =
13420{
d54af2d0 13421 16,
037e8744
JB
13422 32,
13423 64,
13424 128,
13425 0,
13426 32,
13427 32,
13428 0
13429};
13430
13431struct neon_shape_info
13432{
13433 unsigned els;
13434 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13435};
13436
13437#define S2(A,B) { SE_##A, SE_##B }
13438#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13439#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13440
13441#define X(N, L, C) { N, S##N L }
13442
13443static struct neon_shape_info neon_shape_tab[] =
13444{
13445 NEON_SHAPE_DEF
13446};
13447
13448#undef X
13449#undef S2
13450#undef S3
13451#undef S4
13452
5287ad62
JB
13453/* Bit masks used in type checking given instructions.
13454 'N_EQK' means the type must be the same as (or based on in some way) the key
13455 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13456 set, various other bits can be set as well in order to modify the meaning of
13457 the type constraint. */
13458
13459enum neon_type_mask
13460{
8e79c3df
CM
13461 N_S8 = 0x0000001,
13462 N_S16 = 0x0000002,
13463 N_S32 = 0x0000004,
13464 N_S64 = 0x0000008,
13465 N_U8 = 0x0000010,
13466 N_U16 = 0x0000020,
13467 N_U32 = 0x0000040,
13468 N_U64 = 0x0000080,
13469 N_I8 = 0x0000100,
13470 N_I16 = 0x0000200,
13471 N_I32 = 0x0000400,
13472 N_I64 = 0x0000800,
13473 N_8 = 0x0001000,
13474 N_16 = 0x0002000,
13475 N_32 = 0x0004000,
13476 N_64 = 0x0008000,
13477 N_P8 = 0x0010000,
13478 N_P16 = 0x0020000,
13479 N_F16 = 0x0040000,
13480 N_F32 = 0x0080000,
13481 N_F64 = 0x0100000,
4f51b4bd 13482 N_P64 = 0x0200000,
c921be7d
NC
13483 N_KEY = 0x1000000, /* Key element (main type specifier). */
13484 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13485 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13486 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13487 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13488 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13489 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13490 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13491 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13492 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13493 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13494 N_UTYP = 0,
4f51b4bd 13495 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13496};
13497
dcbf9037
JB
13498#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13499
5287ad62
JB
13500#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13501#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13502#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13503#define N_S_32 (N_S8 | N_S16 | N_S32)
13504#define N_F_16_32 (N_F16 | N_F32)
13505#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13506#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13507#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13508#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13509
13510/* Pass this as the first type argument to neon_check_type to ignore types
13511 altogether. */
13512#define N_IGNORE_TYPE (N_KEY | N_EQK)
13513
037e8744
JB
13514/* Select a "shape" for the current instruction (describing register types or
13515 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13516 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13517 function of operand parsing, so this function doesn't need to be called.
13518 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13519
13520static enum neon_shape
037e8744 13521neon_select_shape (enum neon_shape shape, ...)
5287ad62 13522{
037e8744
JB
13523 va_list ap;
13524 enum neon_shape first_shape = shape;
5287ad62
JB
13525
13526 /* Fix missing optional operands. FIXME: we don't know at this point how
13527 many arguments we should have, so this makes the assumption that we have
13528 > 1. This is true of all current Neon opcodes, I think, but may not be
13529 true in the future. */
13530 if (!inst.operands[1].present)
13531 inst.operands[1] = inst.operands[0];
13532
037e8744 13533 va_start (ap, shape);
5f4273c7 13534
21d799b5 13535 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13536 {
13537 unsigned j;
13538 int matches = 1;
13539
13540 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13541 {
13542 if (!inst.operands[j].present)
13543 {
13544 matches = 0;
13545 break;
13546 }
13547
13548 switch (neon_shape_tab[shape].el[j])
13549 {
d54af2d0
RL
13550 /* If a .f16, .16, .u16, .s16 type specifier is given over
13551 a VFP single precision register operand, it's essentially
13552 means only half of the register is used.
13553
13554 If the type specifier is given after the mnemonics, the
13555 information is stored in inst.vectype. If the type specifier
13556 is given after register operand, the information is stored
13557 in inst.operands[].vectype.
13558
13559 When there is only one type specifier, and all the register
13560 operands are the same type of hardware register, the type
13561 specifier applies to all register operands.
13562
13563 If no type specifier is given, the shape is inferred from
13564 operand information.
13565
13566 for example:
13567 vadd.f16 s0, s1, s2: NS_HHH
13568 vabs.f16 s0, s1: NS_HH
13569 vmov.f16 s0, r1: NS_HR
13570 vmov.f16 r0, s1: NS_RH
13571 vcvt.f16 r0, s1: NS_RH
13572 vcvt.f16.s32 s2, s2, #29: NS_HFI
13573 vcvt.f16.s32 s2, s2: NS_HF
13574 */
13575 case SE_H:
13576 if (!(inst.operands[j].isreg
13577 && inst.operands[j].isvec
13578 && inst.operands[j].issingle
13579 && !inst.operands[j].isquad
13580 && ((inst.vectype.elems == 1
13581 && inst.vectype.el[0].size == 16)
13582 || (inst.vectype.elems > 1
13583 && inst.vectype.el[j].size == 16)
13584 || (inst.vectype.elems == 0
13585 && inst.operands[j].vectype.type != NT_invtype
13586 && inst.operands[j].vectype.size == 16))))
13587 matches = 0;
13588 break;
13589
477330fc
RM
13590 case SE_F:
13591 if (!(inst.operands[j].isreg
13592 && inst.operands[j].isvec
13593 && inst.operands[j].issingle
d54af2d0
RL
13594 && !inst.operands[j].isquad
13595 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13596 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13597 || (inst.vectype.elems == 0
13598 && (inst.operands[j].vectype.size == 32
13599 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13600 matches = 0;
13601 break;
13602
13603 case SE_D:
13604 if (!(inst.operands[j].isreg
13605 && inst.operands[j].isvec
13606 && !inst.operands[j].isquad
13607 && !inst.operands[j].issingle))
13608 matches = 0;
13609 break;
13610
13611 case SE_R:
13612 if (!(inst.operands[j].isreg
13613 && !inst.operands[j].isvec))
13614 matches = 0;
13615 break;
13616
13617 case SE_Q:
13618 if (!(inst.operands[j].isreg
13619 && inst.operands[j].isvec
13620 && inst.operands[j].isquad
13621 && !inst.operands[j].issingle))
13622 matches = 0;
13623 break;
13624
13625 case SE_I:
13626 if (!(!inst.operands[j].isreg
13627 && !inst.operands[j].isscalar))
13628 matches = 0;
13629 break;
13630
13631 case SE_S:
13632 if (!(!inst.operands[j].isreg
13633 && inst.operands[j].isscalar))
13634 matches = 0;
13635 break;
13636
13637 case SE_L:
13638 break;
13639 }
3fde54a2
JZ
13640 if (!matches)
13641 break;
477330fc 13642 }
ad6cec43
MGD
13643 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13644 /* We've matched all the entries in the shape table, and we don't
13645 have any left over operands which have not been matched. */
477330fc 13646 break;
037e8744 13647 }
5f4273c7 13648
037e8744 13649 va_end (ap);
5287ad62 13650
037e8744
JB
13651 if (shape == NS_NULL && first_shape != NS_NULL)
13652 first_error (_("invalid instruction shape"));
5287ad62 13653
037e8744
JB
13654 return shape;
13655}
5287ad62 13656
037e8744
JB
13657/* True if SHAPE is predominantly a quadword operation (most of the time, this
13658 means the Q bit should be set). */
13659
13660static int
13661neon_quad (enum neon_shape shape)
13662{
13663 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13664}
037e8744 13665
5287ad62
JB
13666static void
13667neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13668 unsigned *g_size)
5287ad62
JB
13669{
13670 /* Allow modification to be made to types which are constrained to be
13671 based on the key element, based on bits set alongside N_EQK. */
13672 if ((typebits & N_EQK) != 0)
13673 {
13674 if ((typebits & N_HLF) != 0)
13675 *g_size /= 2;
13676 else if ((typebits & N_DBL) != 0)
13677 *g_size *= 2;
13678 if ((typebits & N_SGN) != 0)
13679 *g_type = NT_signed;
13680 else if ((typebits & N_UNS) != 0)
477330fc 13681 *g_type = NT_unsigned;
5287ad62 13682 else if ((typebits & N_INT) != 0)
477330fc 13683 *g_type = NT_integer;
5287ad62 13684 else if ((typebits & N_FLT) != 0)
477330fc 13685 *g_type = NT_float;
dcbf9037 13686 else if ((typebits & N_SIZ) != 0)
477330fc 13687 *g_type = NT_untyped;
5287ad62
JB
13688 }
13689}
5f4273c7 13690
5287ad62
JB
13691/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13692 operand type, i.e. the single type specified in a Neon instruction when it
13693 is the only one given. */
13694
13695static struct neon_type_el
13696neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13697{
13698 struct neon_type_el dest = *key;
5f4273c7 13699
9c2799c2 13700 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13701
5287ad62
JB
13702 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13703
13704 return dest;
13705}
13706
13707/* Convert Neon type and size into compact bitmask representation. */
13708
13709static enum neon_type_mask
13710type_chk_of_el_type (enum neon_el_type type, unsigned size)
13711{
13712 switch (type)
13713 {
13714 case NT_untyped:
13715 switch (size)
477330fc
RM
13716 {
13717 case 8: return N_8;
13718 case 16: return N_16;
13719 case 32: return N_32;
13720 case 64: return N_64;
13721 default: ;
13722 }
5287ad62
JB
13723 break;
13724
13725 case NT_integer:
13726 switch (size)
477330fc
RM
13727 {
13728 case 8: return N_I8;
13729 case 16: return N_I16;
13730 case 32: return N_I32;
13731 case 64: return N_I64;
13732 default: ;
13733 }
5287ad62
JB
13734 break;
13735
13736 case NT_float:
037e8744 13737 switch (size)
477330fc 13738 {
8e79c3df 13739 case 16: return N_F16;
477330fc
RM
13740 case 32: return N_F32;
13741 case 64: return N_F64;
13742 default: ;
13743 }
5287ad62
JB
13744 break;
13745
13746 case NT_poly:
13747 switch (size)
477330fc
RM
13748 {
13749 case 8: return N_P8;
13750 case 16: return N_P16;
4f51b4bd 13751 case 64: return N_P64;
477330fc
RM
13752 default: ;
13753 }
5287ad62
JB
13754 break;
13755
13756 case NT_signed:
13757 switch (size)
477330fc
RM
13758 {
13759 case 8: return N_S8;
13760 case 16: return N_S16;
13761 case 32: return N_S32;
13762 case 64: return N_S64;
13763 default: ;
13764 }
5287ad62
JB
13765 break;
13766
13767 case NT_unsigned:
13768 switch (size)
477330fc
RM
13769 {
13770 case 8: return N_U8;
13771 case 16: return N_U16;
13772 case 32: return N_U32;
13773 case 64: return N_U64;
13774 default: ;
13775 }
5287ad62
JB
13776 break;
13777
13778 default: ;
13779 }
5f4273c7 13780
5287ad62
JB
13781 return N_UTYP;
13782}
13783
13784/* Convert compact Neon bitmask type representation to a type and size. Only
13785 handles the case where a single bit is set in the mask. */
13786
dcbf9037 13787static int
5287ad62 13788el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13789 enum neon_type_mask mask)
5287ad62 13790{
dcbf9037
JB
13791 if ((mask & N_EQK) != 0)
13792 return FAIL;
13793
5287ad62
JB
13794 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13795 *size = 8;
c70a8987 13796 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13797 *size = 16;
dcbf9037 13798 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13799 *size = 32;
4f51b4bd 13800 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13801 *size = 64;
dcbf9037
JB
13802 else
13803 return FAIL;
13804
5287ad62
JB
13805 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13806 *type = NT_signed;
dcbf9037 13807 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13808 *type = NT_unsigned;
dcbf9037 13809 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13810 *type = NT_integer;
dcbf9037 13811 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13812 *type = NT_untyped;
4f51b4bd 13813 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13814 *type = NT_poly;
d54af2d0 13815 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13816 *type = NT_float;
dcbf9037
JB
13817 else
13818 return FAIL;
5f4273c7 13819
dcbf9037 13820 return SUCCESS;
5287ad62
JB
13821}
13822
13823/* Modify a bitmask of allowed types. This is only needed for type
13824 relaxation. */
13825
13826static unsigned
13827modify_types_allowed (unsigned allowed, unsigned mods)
13828{
13829 unsigned size;
13830 enum neon_el_type type;
13831 unsigned destmask;
13832 int i;
5f4273c7 13833
5287ad62 13834 destmask = 0;
5f4273c7 13835
5287ad62
JB
13836 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13837 {
21d799b5 13838 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13839 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13840 {
13841 neon_modify_type_size (mods, &type, &size);
13842 destmask |= type_chk_of_el_type (type, size);
13843 }
5287ad62 13844 }
5f4273c7 13845
5287ad62
JB
13846 return destmask;
13847}
13848
13849/* Check type and return type classification.
13850 The manual states (paraphrase): If one datatype is given, it indicates the
13851 type given in:
13852 - the second operand, if there is one
13853 - the operand, if there is no second operand
13854 - the result, if there are no operands.
13855 This isn't quite good enough though, so we use a concept of a "key" datatype
13856 which is set on a per-instruction basis, which is the one which matters when
13857 only one data type is written.
13858 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13859 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13860
13861static struct neon_type_el
13862neon_check_type (unsigned els, enum neon_shape ns, ...)
13863{
13864 va_list ap;
13865 unsigned i, pass, key_el = 0;
13866 unsigned types[NEON_MAX_TYPE_ELS];
13867 enum neon_el_type k_type = NT_invtype;
13868 unsigned k_size = -1u;
13869 struct neon_type_el badtype = {NT_invtype, -1};
13870 unsigned key_allowed = 0;
13871
13872 /* Optional registers in Neon instructions are always (not) in operand 1.
13873 Fill in the missing operand here, if it was omitted. */
13874 if (els > 1 && !inst.operands[1].present)
13875 inst.operands[1] = inst.operands[0];
13876
13877 /* Suck up all the varargs. */
13878 va_start (ap, ns);
13879 for (i = 0; i < els; i++)
13880 {
13881 unsigned thisarg = va_arg (ap, unsigned);
13882 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13883 {
13884 va_end (ap);
13885 return badtype;
13886 }
5287ad62
JB
13887 types[i] = thisarg;
13888 if ((thisarg & N_KEY) != 0)
477330fc 13889 key_el = i;
5287ad62
JB
13890 }
13891 va_end (ap);
13892
dcbf9037
JB
13893 if (inst.vectype.elems > 0)
13894 for (i = 0; i < els; i++)
13895 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13896 {
13897 first_error (_("types specified in both the mnemonic and operands"));
13898 return badtype;
13899 }
dcbf9037 13900
5287ad62
JB
13901 /* Duplicate inst.vectype elements here as necessary.
13902 FIXME: No idea if this is exactly the same as the ARM assembler,
13903 particularly when an insn takes one register and one non-register
13904 operand. */
13905 if (inst.vectype.elems == 1 && els > 1)
13906 {
13907 unsigned j;
13908 inst.vectype.elems = els;
13909 inst.vectype.el[key_el] = inst.vectype.el[0];
13910 for (j = 0; j < els; j++)
477330fc
RM
13911 if (j != key_el)
13912 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13913 types[j]);
dcbf9037
JB
13914 }
13915 else if (inst.vectype.elems == 0 && els > 0)
13916 {
13917 unsigned j;
13918 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13919 after each operand. We allow some flexibility here; as long as the
13920 "key" operand has a type, we can infer the others. */
dcbf9037 13921 for (j = 0; j < els; j++)
477330fc
RM
13922 if (inst.operands[j].vectype.type != NT_invtype)
13923 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13924
13925 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13926 {
13927 for (j = 0; j < els; j++)
13928 if (inst.operands[j].vectype.type == NT_invtype)
13929 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13930 types[j]);
13931 }
dcbf9037 13932 else
477330fc
RM
13933 {
13934 first_error (_("operand types can't be inferred"));
13935 return badtype;
13936 }
5287ad62
JB
13937 }
13938 else if (inst.vectype.elems != els)
13939 {
dcbf9037 13940 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13941 return badtype;
13942 }
13943
13944 for (pass = 0; pass < 2; pass++)
13945 {
13946 for (i = 0; i < els; i++)
477330fc
RM
13947 {
13948 unsigned thisarg = types[i];
13949 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13950 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13951 enum neon_el_type g_type = inst.vectype.el[i].type;
13952 unsigned g_size = inst.vectype.el[i].size;
13953
13954 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13955 integer types if sign-specific variants are unavailable. */
477330fc 13956 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13957 && (types_allowed & N_SU_ALL) == 0)
13958 g_type = NT_integer;
13959
477330fc 13960 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13961 them. Some instructions only care about signs for some element
13962 sizes, so handle that properly. */
477330fc 13963 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13964 && ((g_size == 8 && (types_allowed & N_8) != 0)
13965 || (g_size == 16 && (types_allowed & N_16) != 0)
13966 || (g_size == 32 && (types_allowed & N_32) != 0)
13967 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13968 g_type = NT_untyped;
13969
477330fc
RM
13970 if (pass == 0)
13971 {
13972 if ((thisarg & N_KEY) != 0)
13973 {
13974 k_type = g_type;
13975 k_size = g_size;
13976 key_allowed = thisarg & ~N_KEY;
cc933301
JW
13977
13978 /* Check architecture constraint on FP16 extension. */
13979 if (k_size == 16
13980 && k_type == NT_float
13981 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13982 {
13983 inst.error = _(BAD_FP16);
13984 return badtype;
13985 }
477330fc
RM
13986 }
13987 }
13988 else
13989 {
13990 if ((thisarg & N_VFP) != 0)
13991 {
13992 enum neon_shape_el regshape;
13993 unsigned regwidth, match;
99b253c5
NC
13994
13995 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13996 if (ns == NS_NULL)
13997 {
13998 first_error (_("invalid instruction shape"));
13999 return badtype;
14000 }
477330fc
RM
14001 regshape = neon_shape_tab[ns].el[i];
14002 regwidth = neon_shape_el_size[regshape];
14003
14004 /* In VFP mode, operands must match register widths. If we
14005 have a key operand, use its width, else use the width of
14006 the current operand. */
14007 if (k_size != -1u)
14008 match = k_size;
14009 else
14010 match = g_size;
14011
9db2f6b4
RL
14012 /* FP16 will use a single precision register. */
14013 if (regwidth == 32 && match == 16)
14014 {
14015 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14016 match = regwidth;
14017 else
14018 {
14019 inst.error = _(BAD_FP16);
14020 return badtype;
14021 }
14022 }
14023
477330fc
RM
14024 if (regwidth != match)
14025 {
14026 first_error (_("operand size must match register width"));
14027 return badtype;
14028 }
14029 }
14030
14031 if ((thisarg & N_EQK) == 0)
14032 {
14033 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14034
14035 if ((given_type & types_allowed) == 0)
14036 {
14037 first_error (_("bad type in Neon instruction"));
14038 return badtype;
14039 }
14040 }
14041 else
14042 {
14043 enum neon_el_type mod_k_type = k_type;
14044 unsigned mod_k_size = k_size;
14045 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14046 if (g_type != mod_k_type || g_size != mod_k_size)
14047 {
14048 first_error (_("inconsistent types in Neon instruction"));
14049 return badtype;
14050 }
14051 }
14052 }
14053 }
5287ad62
JB
14054 }
14055
14056 return inst.vectype.el[key_el];
14057}
14058
037e8744 14059/* Neon-style VFP instruction forwarding. */
5287ad62 14060
037e8744
JB
14061/* Thumb VFP instructions have 0xE in the condition field. */
14062
14063static void
14064do_vfp_cond_or_thumb (void)
5287ad62 14065{
88714cb8
DG
14066 inst.is_neon = 1;
14067
5287ad62 14068 if (thumb_mode)
037e8744 14069 inst.instruction |= 0xe0000000;
5287ad62 14070 else
037e8744 14071 inst.instruction |= inst.cond << 28;
5287ad62
JB
14072}
14073
037e8744
JB
14074/* Look up and encode a simple mnemonic, for use as a helper function for the
14075 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14076 etc. It is assumed that operand parsing has already been done, and that the
14077 operands are in the form expected by the given opcode (this isn't necessarily
14078 the same as the form in which they were parsed, hence some massaging must
14079 take place before this function is called).
14080 Checks current arch version against that in the looked-up opcode. */
5287ad62 14081
037e8744
JB
14082static void
14083do_vfp_nsyn_opcode (const char *opname)
5287ad62 14084{
037e8744 14085 const struct asm_opcode *opcode;
5f4273c7 14086
21d799b5 14087 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14088
037e8744
JB
14089 if (!opcode)
14090 abort ();
5287ad62 14091
037e8744 14092 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14093 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14094 _(BAD_FPU));
5287ad62 14095
88714cb8
DG
14096 inst.is_neon = 1;
14097
037e8744
JB
14098 if (thumb_mode)
14099 {
14100 inst.instruction = opcode->tvalue;
14101 opcode->tencode ();
14102 }
14103 else
14104 {
14105 inst.instruction = (inst.cond << 28) | opcode->avalue;
14106 opcode->aencode ();
14107 }
14108}
5287ad62
JB
14109
14110static void
037e8744 14111do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14112{
037e8744
JB
14113 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14114
9db2f6b4 14115 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14116 {
14117 if (is_add)
477330fc 14118 do_vfp_nsyn_opcode ("fadds");
037e8744 14119 else
477330fc 14120 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14121
14122 /* ARMv8.2 fp16 instruction. */
14123 if (rs == NS_HHH)
14124 do_scalar_fp16_v82_encode ();
037e8744
JB
14125 }
14126 else
14127 {
14128 if (is_add)
477330fc 14129 do_vfp_nsyn_opcode ("faddd");
037e8744 14130 else
477330fc 14131 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14132 }
14133}
14134
14135/* Check operand types to see if this is a VFP instruction, and if so call
14136 PFN (). */
14137
14138static int
14139try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14140{
14141 enum neon_shape rs;
14142 struct neon_type_el et;
14143
14144 switch (args)
14145 {
14146 case 2:
9db2f6b4
RL
14147 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14148 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14149 break;
5f4273c7 14150
037e8744 14151 case 3:
9db2f6b4
RL
14152 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14153 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14154 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14155 break;
14156
14157 default:
14158 abort ();
14159 }
14160
14161 if (et.type != NT_invtype)
14162 {
14163 pfn (rs);
14164 return SUCCESS;
14165 }
037e8744 14166
99b253c5 14167 inst.error = NULL;
037e8744
JB
14168 return FAIL;
14169}
14170
14171static void
14172do_vfp_nsyn_mla_mls (enum neon_shape rs)
14173{
14174 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14175
9db2f6b4 14176 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14177 {
14178 if (is_mla)
477330fc 14179 do_vfp_nsyn_opcode ("fmacs");
037e8744 14180 else
477330fc 14181 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14182
14183 /* ARMv8.2 fp16 instruction. */
14184 if (rs == NS_HHH)
14185 do_scalar_fp16_v82_encode ();
037e8744
JB
14186 }
14187 else
14188 {
14189 if (is_mla)
477330fc 14190 do_vfp_nsyn_opcode ("fmacd");
037e8744 14191 else
477330fc 14192 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14193 }
14194}
14195
62f3b8c8
PB
14196static void
14197do_vfp_nsyn_fma_fms (enum neon_shape rs)
14198{
14199 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14200
9db2f6b4 14201 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14202 {
14203 if (is_fma)
477330fc 14204 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14205 else
477330fc 14206 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14207
14208 /* ARMv8.2 fp16 instruction. */
14209 if (rs == NS_HHH)
14210 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14211 }
14212 else
14213 {
14214 if (is_fma)
477330fc 14215 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14216 else
477330fc 14217 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14218 }
14219}
14220
037e8744
JB
14221static void
14222do_vfp_nsyn_mul (enum neon_shape rs)
14223{
9db2f6b4
RL
14224 if (rs == NS_FFF || rs == NS_HHH)
14225 {
14226 do_vfp_nsyn_opcode ("fmuls");
14227
14228 /* ARMv8.2 fp16 instruction. */
14229 if (rs == NS_HHH)
14230 do_scalar_fp16_v82_encode ();
14231 }
037e8744
JB
14232 else
14233 do_vfp_nsyn_opcode ("fmuld");
14234}
14235
14236static void
14237do_vfp_nsyn_abs_neg (enum neon_shape rs)
14238{
14239 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14240 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14241
9db2f6b4 14242 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14243 {
14244 if (is_neg)
477330fc 14245 do_vfp_nsyn_opcode ("fnegs");
037e8744 14246 else
477330fc 14247 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14248
14249 /* ARMv8.2 fp16 instruction. */
14250 if (rs == NS_HH)
14251 do_scalar_fp16_v82_encode ();
037e8744
JB
14252 }
14253 else
14254 {
14255 if (is_neg)
477330fc 14256 do_vfp_nsyn_opcode ("fnegd");
037e8744 14257 else
477330fc 14258 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14259 }
14260}
14261
14262/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14263 insns belong to Neon, and are handled elsewhere. */
14264
14265static void
14266do_vfp_nsyn_ldm_stm (int is_dbmode)
14267{
14268 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14269 if (is_ldm)
14270 {
14271 if (is_dbmode)
477330fc 14272 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14273 else
477330fc 14274 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14275 }
14276 else
14277 {
14278 if (is_dbmode)
477330fc 14279 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14280 else
477330fc 14281 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14282 }
14283}
14284
037e8744
JB
14285static void
14286do_vfp_nsyn_sqrt (void)
14287{
9db2f6b4
RL
14288 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14289 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14290
9db2f6b4
RL
14291 if (rs == NS_FF || rs == NS_HH)
14292 {
14293 do_vfp_nsyn_opcode ("fsqrts");
14294
14295 /* ARMv8.2 fp16 instruction. */
14296 if (rs == NS_HH)
14297 do_scalar_fp16_v82_encode ();
14298 }
037e8744
JB
14299 else
14300 do_vfp_nsyn_opcode ("fsqrtd");
14301}
14302
14303static void
14304do_vfp_nsyn_div (void)
14305{
9db2f6b4 14306 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14307 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14308 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14309
9db2f6b4
RL
14310 if (rs == NS_FFF || rs == NS_HHH)
14311 {
14312 do_vfp_nsyn_opcode ("fdivs");
14313
14314 /* ARMv8.2 fp16 instruction. */
14315 if (rs == NS_HHH)
14316 do_scalar_fp16_v82_encode ();
14317 }
037e8744
JB
14318 else
14319 do_vfp_nsyn_opcode ("fdivd");
14320}
14321
14322static void
14323do_vfp_nsyn_nmul (void)
14324{
9db2f6b4 14325 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14326 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14327 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14328
9db2f6b4 14329 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14330 {
88714cb8 14331 NEON_ENCODE (SINGLE, inst);
037e8744 14332 do_vfp_sp_dyadic ();
9db2f6b4
RL
14333
14334 /* ARMv8.2 fp16 instruction. */
14335 if (rs == NS_HHH)
14336 do_scalar_fp16_v82_encode ();
037e8744
JB
14337 }
14338 else
14339 {
88714cb8 14340 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14341 do_vfp_dp_rd_rn_rm ();
14342 }
14343 do_vfp_cond_or_thumb ();
9db2f6b4 14344
037e8744
JB
14345}
14346
14347static void
14348do_vfp_nsyn_cmp (void)
14349{
9db2f6b4 14350 enum neon_shape rs;
037e8744
JB
14351 if (inst.operands[1].isreg)
14352 {
9db2f6b4
RL
14353 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14354 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14355
9db2f6b4 14356 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14357 {
14358 NEON_ENCODE (SINGLE, inst);
14359 do_vfp_sp_monadic ();
14360 }
037e8744 14361 else
477330fc
RM
14362 {
14363 NEON_ENCODE (DOUBLE, inst);
14364 do_vfp_dp_rd_rm ();
14365 }
037e8744
JB
14366 }
14367 else
14368 {
9db2f6b4
RL
14369 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14370 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14371
14372 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14373 {
14374 case N_MNEM_vcmp:
14375 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14376 break;
14377 case N_MNEM_vcmpe:
14378 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14379 break;
14380 default:
14381 abort ();
14382 }
5f4273c7 14383
9db2f6b4 14384 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14385 {
14386 NEON_ENCODE (SINGLE, inst);
14387 do_vfp_sp_compare_z ();
14388 }
037e8744 14389 else
477330fc
RM
14390 {
14391 NEON_ENCODE (DOUBLE, inst);
14392 do_vfp_dp_rd ();
14393 }
037e8744
JB
14394 }
14395 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14396
14397 /* ARMv8.2 fp16 instruction. */
14398 if (rs == NS_HI || rs == NS_HH)
14399 do_scalar_fp16_v82_encode ();
037e8744
JB
14400}
14401
14402static void
14403nsyn_insert_sp (void)
14404{
14405 inst.operands[1] = inst.operands[0];
14406 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14407 inst.operands[0].reg = REG_SP;
037e8744
JB
14408 inst.operands[0].isreg = 1;
14409 inst.operands[0].writeback = 1;
14410 inst.operands[0].present = 1;
14411}
14412
14413static void
14414do_vfp_nsyn_push (void)
14415{
14416 nsyn_insert_sp ();
b126985e
NC
14417
14418 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14419 _("register list must contain at least 1 and at most 16 "
14420 "registers"));
14421
037e8744
JB
14422 if (inst.operands[1].issingle)
14423 do_vfp_nsyn_opcode ("fstmdbs");
14424 else
14425 do_vfp_nsyn_opcode ("fstmdbd");
14426}
14427
14428static void
14429do_vfp_nsyn_pop (void)
14430{
14431 nsyn_insert_sp ();
b126985e
NC
14432
14433 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14434 _("register list must contain at least 1 and at most 16 "
14435 "registers"));
14436
037e8744 14437 if (inst.operands[1].issingle)
22b5b651 14438 do_vfp_nsyn_opcode ("fldmias");
037e8744 14439 else
22b5b651 14440 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14441}
14442
14443/* Fix up Neon data-processing instructions, ORing in the correct bits for
14444 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14445
88714cb8
DG
14446static void
14447neon_dp_fixup (struct arm_it* insn)
037e8744 14448{
88714cb8
DG
14449 unsigned int i = insn->instruction;
14450 insn->is_neon = 1;
14451
037e8744
JB
14452 if (thumb_mode)
14453 {
14454 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14455 if (i & (1 << 24))
477330fc 14456 i |= 1 << 28;
5f4273c7 14457
037e8744 14458 i &= ~(1 << 24);
5f4273c7 14459
037e8744
JB
14460 i |= 0xef000000;
14461 }
14462 else
14463 i |= 0xf2000000;
5f4273c7 14464
88714cb8 14465 insn->instruction = i;
037e8744
JB
14466}
14467
14468/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14469 (0, 1, 2, 3). */
14470
14471static unsigned
14472neon_logbits (unsigned x)
14473{
14474 return ffs (x) - 4;
14475}
14476
14477#define LOW4(R) ((R) & 0xf)
14478#define HI1(R) (((R) >> 4) & 1)
14479
14480/* Encode insns with bit pattern:
14481
14482 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14483 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14484
037e8744
JB
14485 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14486 different meaning for some instruction. */
14487
14488static void
14489neon_three_same (int isquad, int ubit, int size)
14490{
14491 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14492 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14493 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14494 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14495 inst.instruction |= LOW4 (inst.operands[2].reg);
14496 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14497 inst.instruction |= (isquad != 0) << 6;
14498 inst.instruction |= (ubit != 0) << 24;
14499 if (size != -1)
14500 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14501
88714cb8 14502 neon_dp_fixup (&inst);
037e8744
JB
14503}
14504
14505/* Encode instructions of the form:
14506
14507 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14508 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14509
14510 Don't write size if SIZE == -1. */
14511
14512static void
14513neon_two_same (int qbit, int ubit, int size)
14514{
14515 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14516 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14517 inst.instruction |= LOW4 (inst.operands[1].reg);
14518 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14519 inst.instruction |= (qbit != 0) << 6;
14520 inst.instruction |= (ubit != 0) << 24;
14521
14522 if (size != -1)
14523 inst.instruction |= neon_logbits (size) << 18;
14524
88714cb8 14525 neon_dp_fixup (&inst);
5287ad62
JB
14526}
14527
14528/* Neon instruction encoders, in approximate order of appearance. */
14529
14530static void
14531do_neon_dyadic_i_su (void)
14532{
037e8744 14533 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14534 struct neon_type_el et = neon_check_type (3, rs,
14535 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14536 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14537}
14538
14539static void
14540do_neon_dyadic_i64_su (void)
14541{
037e8744 14542 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14543 struct neon_type_el et = neon_check_type (3, rs,
14544 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14545 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14546}
14547
14548static void
14549neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14550 unsigned immbits)
5287ad62
JB
14551{
14552 unsigned size = et.size >> 3;
14553 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14554 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14555 inst.instruction |= LOW4 (inst.operands[1].reg);
14556 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14557 inst.instruction |= (isquad != 0) << 6;
14558 inst.instruction |= immbits << 16;
14559 inst.instruction |= (size >> 3) << 7;
14560 inst.instruction |= (size & 0x7) << 19;
14561 if (write_ubit)
14562 inst.instruction |= (uval != 0) << 24;
14563
88714cb8 14564 neon_dp_fixup (&inst);
5287ad62
JB
14565}
14566
14567static void
14568do_neon_shl_imm (void)
14569{
14570 if (!inst.operands[2].isreg)
14571 {
037e8744 14572 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14573 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14574 int imm = inst.operands[2].imm;
14575
14576 constraint (imm < 0 || (unsigned)imm >= et.size,
14577 _("immediate out of range for shift"));
88714cb8 14578 NEON_ENCODE (IMMED, inst);
cb3b1e65 14579 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14580 }
14581 else
14582 {
037e8744 14583 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14584 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14585 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14586 unsigned int tmp;
14587
14588 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14589 vshl.xx Dd, Dm, Dn
14590 whereas other 3-register operations encoded by neon_three_same have
14591 syntax like:
14592 vadd.xx Dd, Dn, Dm
14593 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14594 here. */
627907b7
JB
14595 tmp = inst.operands[2].reg;
14596 inst.operands[2].reg = inst.operands[1].reg;
14597 inst.operands[1].reg = tmp;
88714cb8 14598 NEON_ENCODE (INTEGER, inst);
037e8744 14599 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14600 }
14601}
14602
14603static void
14604do_neon_qshl_imm (void)
14605{
14606 if (!inst.operands[2].isreg)
14607 {
037e8744 14608 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14609 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14610 int imm = inst.operands[2].imm;
627907b7 14611
cb3b1e65
JB
14612 constraint (imm < 0 || (unsigned)imm >= et.size,
14613 _("immediate out of range for shift"));
88714cb8 14614 NEON_ENCODE (IMMED, inst);
cb3b1e65 14615 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14616 }
14617 else
14618 {
037e8744 14619 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14620 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14621 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14622 unsigned int tmp;
14623
14624 /* See note in do_neon_shl_imm. */
14625 tmp = inst.operands[2].reg;
14626 inst.operands[2].reg = inst.operands[1].reg;
14627 inst.operands[1].reg = tmp;
88714cb8 14628 NEON_ENCODE (INTEGER, inst);
037e8744 14629 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14630 }
14631}
14632
627907b7
JB
14633static void
14634do_neon_rshl (void)
14635{
14636 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14637 struct neon_type_el et = neon_check_type (3, rs,
14638 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14639 unsigned int tmp;
14640
14641 tmp = inst.operands[2].reg;
14642 inst.operands[2].reg = inst.operands[1].reg;
14643 inst.operands[1].reg = tmp;
14644 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14645}
14646
5287ad62
JB
14647static int
14648neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14649{
036dc3f7
PB
14650 /* Handle .I8 pseudo-instructions. */
14651 if (size == 8)
5287ad62 14652 {
5287ad62 14653 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14654 FIXME is this the intended semantics? There doesn't seem much point in
14655 accepting .I8 if so. */
5287ad62
JB
14656 immediate |= immediate << 8;
14657 size = 16;
036dc3f7
PB
14658 }
14659
14660 if (size >= 32)
14661 {
14662 if (immediate == (immediate & 0x000000ff))
14663 {
14664 *immbits = immediate;
14665 return 0x1;
14666 }
14667 else if (immediate == (immediate & 0x0000ff00))
14668 {
14669 *immbits = immediate >> 8;
14670 return 0x3;
14671 }
14672 else if (immediate == (immediate & 0x00ff0000))
14673 {
14674 *immbits = immediate >> 16;
14675 return 0x5;
14676 }
14677 else if (immediate == (immediate & 0xff000000))
14678 {
14679 *immbits = immediate >> 24;
14680 return 0x7;
14681 }
14682 if ((immediate & 0xffff) != (immediate >> 16))
14683 goto bad_immediate;
14684 immediate &= 0xffff;
5287ad62
JB
14685 }
14686
14687 if (immediate == (immediate & 0x000000ff))
14688 {
14689 *immbits = immediate;
036dc3f7 14690 return 0x9;
5287ad62
JB
14691 }
14692 else if (immediate == (immediate & 0x0000ff00))
14693 {
14694 *immbits = immediate >> 8;
036dc3f7 14695 return 0xb;
5287ad62
JB
14696 }
14697
14698 bad_immediate:
dcbf9037 14699 first_error (_("immediate value out of range"));
5287ad62
JB
14700 return FAIL;
14701}
14702
5287ad62
JB
14703static void
14704do_neon_logic (void)
14705{
14706 if (inst.operands[2].present && inst.operands[2].isreg)
14707 {
037e8744 14708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14709 neon_check_type (3, rs, N_IGNORE_TYPE);
14710 /* U bit and size field were set as part of the bitmask. */
88714cb8 14711 NEON_ENCODE (INTEGER, inst);
037e8744 14712 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14713 }
14714 else
14715 {
4316f0d2
DG
14716 const int three_ops_form = (inst.operands[2].present
14717 && !inst.operands[2].isreg);
14718 const int immoperand = (three_ops_form ? 2 : 1);
14719 enum neon_shape rs = (three_ops_form
14720 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14721 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14722 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14723 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14724 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14725 unsigned immbits;
14726 int cmode;
5f4273c7 14727
5287ad62 14728 if (et.type == NT_invtype)
477330fc 14729 return;
5f4273c7 14730
4316f0d2
DG
14731 if (three_ops_form)
14732 constraint (inst.operands[0].reg != inst.operands[1].reg,
14733 _("first and second operands shall be the same register"));
14734
88714cb8 14735 NEON_ENCODE (IMMED, inst);
5287ad62 14736
4316f0d2 14737 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14738 if (et.size == 64)
14739 {
14740 /* .i64 is a pseudo-op, so the immediate must be a repeating
14741 pattern. */
4316f0d2
DG
14742 if (immbits != (inst.operands[immoperand].regisimm ?
14743 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14744 {
14745 /* Set immbits to an invalid constant. */
14746 immbits = 0xdeadbeef;
14747 }
14748 }
14749
5287ad62 14750 switch (opcode)
477330fc
RM
14751 {
14752 case N_MNEM_vbic:
14753 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14754 break;
14755
14756 case N_MNEM_vorr:
14757 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14758 break;
14759
14760 case N_MNEM_vand:
14761 /* Pseudo-instruction for VBIC. */
14762 neon_invert_size (&immbits, 0, et.size);
14763 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14764 break;
14765
14766 case N_MNEM_vorn:
14767 /* Pseudo-instruction for VORR. */
14768 neon_invert_size (&immbits, 0, et.size);
14769 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14770 break;
14771
14772 default:
14773 abort ();
14774 }
5287ad62
JB
14775
14776 if (cmode == FAIL)
477330fc 14777 return;
5287ad62 14778
037e8744 14779 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14780 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14781 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14782 inst.instruction |= cmode << 8;
14783 neon_write_immbits (immbits);
5f4273c7 14784
88714cb8 14785 neon_dp_fixup (&inst);
5287ad62
JB
14786 }
14787}
14788
14789static void
14790do_neon_bitfield (void)
14791{
037e8744 14792 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14793 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14794 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14795}
14796
14797static void
dcbf9037 14798neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14799 unsigned destbits)
5287ad62 14800{
037e8744 14801 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14802 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14803 types | N_KEY);
5287ad62
JB
14804 if (et.type == NT_float)
14805 {
88714cb8 14806 NEON_ENCODE (FLOAT, inst);
cc933301 14807 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14808 }
14809 else
14810 {
88714cb8 14811 NEON_ENCODE (INTEGER, inst);
037e8744 14812 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14813 }
14814}
14815
14816static void
14817do_neon_dyadic_if_su (void)
14818{
dcbf9037 14819 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14820}
14821
14822static void
14823do_neon_dyadic_if_su_d (void)
14824{
14825 /* This version only allow D registers, but that constraint is enforced during
14826 operand parsing so we don't need to do anything extra here. */
dcbf9037 14827 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14828}
14829
5287ad62
JB
14830static void
14831do_neon_dyadic_if_i_d (void)
14832{
428e3f1f
PB
14833 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14834 affected if we specify unsigned args. */
14835 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14836}
14837
037e8744
JB
14838enum vfp_or_neon_is_neon_bits
14839{
14840 NEON_CHECK_CC = 1,
73924fbc
MGD
14841 NEON_CHECK_ARCH = 2,
14842 NEON_CHECK_ARCH8 = 4
037e8744
JB
14843};
14844
14845/* Call this function if an instruction which may have belonged to the VFP or
14846 Neon instruction sets, but turned out to be a Neon instruction (due to the
14847 operand types involved, etc.). We have to check and/or fix-up a couple of
14848 things:
14849
14850 - Make sure the user hasn't attempted to make a Neon instruction
14851 conditional.
14852 - Alter the value in the condition code field if necessary.
14853 - Make sure that the arch supports Neon instructions.
14854
14855 Which of these operations take place depends on bits from enum
14856 vfp_or_neon_is_neon_bits.
14857
14858 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14859 current instruction's condition is COND_ALWAYS, the condition field is
14860 changed to inst.uncond_value. This is necessary because instructions shared
14861 between VFP and Neon may be conditional for the VFP variants only, and the
14862 unconditional Neon version must have, e.g., 0xF in the condition field. */
14863
14864static int
14865vfp_or_neon_is_neon (unsigned check)
14866{
14867 /* Conditions are always legal in Thumb mode (IT blocks). */
14868 if (!thumb_mode && (check & NEON_CHECK_CC))
14869 {
14870 if (inst.cond != COND_ALWAYS)
477330fc
RM
14871 {
14872 first_error (_(BAD_COND));
14873 return FAIL;
14874 }
037e8744 14875 if (inst.uncond_value != -1)
477330fc 14876 inst.instruction |= inst.uncond_value << 28;
037e8744 14877 }
5f4273c7 14878
037e8744 14879 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14880 && !mark_feature_used (&fpu_neon_ext_v1))
14881 {
14882 first_error (_(BAD_FPU));
14883 return FAIL;
14884 }
14885
14886 if ((check & NEON_CHECK_ARCH8)
14887 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14888 {
14889 first_error (_(BAD_FPU));
14890 return FAIL;
14891 }
5f4273c7 14892
037e8744
JB
14893 return SUCCESS;
14894}
14895
5287ad62
JB
14896static void
14897do_neon_addsub_if_i (void)
14898{
037e8744
JB
14899 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14900 return;
14901
14902 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14903 return;
14904
5287ad62
JB
14905 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14906 affected if we specify unsigned args. */
dcbf9037 14907 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14908}
14909
14910/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14911 result to be:
14912 V<op> A,B (A is operand 0, B is operand 2)
14913 to mean:
14914 V<op> A,B,A
14915 not:
14916 V<op> A,B,B
14917 so handle that case specially. */
14918
14919static void
14920neon_exchange_operands (void)
14921{
5287ad62
JB
14922 if (inst.operands[1].present)
14923 {
e1fa0163
NC
14924 void *scratch = xmalloc (sizeof (inst.operands[0]));
14925
5287ad62
JB
14926 /* Swap operands[1] and operands[2]. */
14927 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14928 inst.operands[1] = inst.operands[2];
14929 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14930 free (scratch);
5287ad62
JB
14931 }
14932 else
14933 {
14934 inst.operands[1] = inst.operands[2];
14935 inst.operands[2] = inst.operands[0];
14936 }
14937}
14938
14939static void
14940neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14941{
14942 if (inst.operands[2].isreg)
14943 {
14944 if (invert)
477330fc 14945 neon_exchange_operands ();
dcbf9037 14946 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14947 }
14948 else
14949 {
037e8744 14950 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14951 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14952 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14953
88714cb8 14954 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14955 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14956 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14957 inst.instruction |= LOW4 (inst.operands[1].reg);
14958 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14959 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14960 inst.instruction |= (et.type == NT_float) << 10;
14961 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14962
88714cb8 14963 neon_dp_fixup (&inst);
5287ad62
JB
14964 }
14965}
14966
14967static void
14968do_neon_cmp (void)
14969{
cc933301 14970 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14971}
14972
14973static void
14974do_neon_cmp_inv (void)
14975{
cc933301 14976 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
14977}
14978
14979static void
14980do_neon_ceq (void)
14981{
14982 neon_compare (N_IF_32, N_IF_32, FALSE);
14983}
14984
14985/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14986 scalars, which are encoded in 5 bits, M : Rm.
14987 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14988 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14989 index in M. */
14990
14991static unsigned
14992neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14993{
dcbf9037
JB
14994 unsigned regno = NEON_SCALAR_REG (scalar);
14995 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14996
14997 switch (elsize)
14998 {
14999 case 16:
15000 if (regno > 7 || elno > 3)
477330fc 15001 goto bad_scalar;
5287ad62 15002 return regno | (elno << 3);
5f4273c7 15003
5287ad62
JB
15004 case 32:
15005 if (regno > 15 || elno > 1)
477330fc 15006 goto bad_scalar;
5287ad62
JB
15007 return regno | (elno << 4);
15008
15009 default:
15010 bad_scalar:
dcbf9037 15011 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15012 }
15013
15014 return 0;
15015}
15016
15017/* Encode multiply / multiply-accumulate scalar instructions. */
15018
15019static void
15020neon_mul_mac (struct neon_type_el et, int ubit)
15021{
dcbf9037
JB
15022 unsigned scalar;
15023
15024 /* Give a more helpful error message if we have an invalid type. */
15025 if (et.type == NT_invtype)
15026 return;
5f4273c7 15027
dcbf9037 15028 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15029 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15030 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15031 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15032 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15033 inst.instruction |= LOW4 (scalar);
15034 inst.instruction |= HI1 (scalar) << 5;
15035 inst.instruction |= (et.type == NT_float) << 8;
15036 inst.instruction |= neon_logbits (et.size) << 20;
15037 inst.instruction |= (ubit != 0) << 24;
15038
88714cb8 15039 neon_dp_fixup (&inst);
5287ad62
JB
15040}
15041
15042static void
15043do_neon_mac_maybe_scalar (void)
15044{
037e8744
JB
15045 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15046 return;
15047
15048 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15049 return;
15050
5287ad62
JB
15051 if (inst.operands[2].isscalar)
15052 {
037e8744 15053 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15054 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15055 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15056 NEON_ENCODE (SCALAR, inst);
037e8744 15057 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15058 }
15059 else
428e3f1f
PB
15060 {
15061 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15062 affected if we specify unsigned args. */
15063 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15064 }
5287ad62
JB
15065}
15066
62f3b8c8
PB
15067static void
15068do_neon_fmac (void)
15069{
15070 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15071 return;
15072
15073 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15074 return;
15075
15076 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15077}
15078
5287ad62
JB
15079static void
15080do_neon_tst (void)
15081{
037e8744 15082 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15083 struct neon_type_el et = neon_check_type (3, rs,
15084 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15085 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15086}
15087
15088/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15089 same types as the MAC equivalents. The polynomial type for this instruction
15090 is encoded the same as the integer type. */
15091
15092static void
15093do_neon_mul (void)
15094{
037e8744
JB
15095 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == 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 do_neon_mac_maybe_scalar ();
15103 else
cc933301 15104 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15105}
15106
15107static void
15108do_neon_qdmulh (void)
15109{
15110 if (inst.operands[2].isscalar)
15111 {
037e8744 15112 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15113 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15114 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15115 NEON_ENCODE (SCALAR, inst);
037e8744 15116 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15117 }
15118 else
15119 {
037e8744 15120 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15121 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15122 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15123 NEON_ENCODE (INTEGER, inst);
5287ad62 15124 /* The U bit (rounding) comes from bit mask. */
037e8744 15125 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15126 }
15127}
15128
643afb90
MW
15129static void
15130do_neon_qrdmlah (void)
15131{
15132 /* Check we're on the correct architecture. */
15133 if (!mark_feature_used (&fpu_neon_ext_armv8))
15134 inst.error =
15135 _("instruction form not available on this architecture.");
15136 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15137 {
15138 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15139 record_feature_use (&fpu_neon_ext_v8_1);
15140 }
15141
15142 if (inst.operands[2].isscalar)
15143 {
15144 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15145 struct neon_type_el et = neon_check_type (3, rs,
15146 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15147 NEON_ENCODE (SCALAR, inst);
15148 neon_mul_mac (et, neon_quad (rs));
15149 }
15150 else
15151 {
15152 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15153 struct neon_type_el et = neon_check_type (3, rs,
15154 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15155 NEON_ENCODE (INTEGER, inst);
15156 /* The U bit (rounding) comes from bit mask. */
15157 neon_three_same (neon_quad (rs), 0, et.size);
15158 }
15159}
15160
5287ad62
JB
15161static void
15162do_neon_fcmp_absolute (void)
15163{
037e8744 15164 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15165 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15166 N_F_16_32 | N_KEY);
5287ad62 15167 /* Size field comes from bit mask. */
cc933301 15168 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15169}
15170
15171static void
15172do_neon_fcmp_absolute_inv (void)
15173{
15174 neon_exchange_operands ();
15175 do_neon_fcmp_absolute ();
15176}
15177
15178static void
15179do_neon_step (void)
15180{
037e8744 15181 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15182 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15183 N_F_16_32 | N_KEY);
15184 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15185}
15186
15187static void
15188do_neon_abs_neg (void)
15189{
037e8744
JB
15190 enum neon_shape rs;
15191 struct neon_type_el et;
5f4273c7 15192
037e8744
JB
15193 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15194 return;
15195
15196 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15197 return;
15198
15199 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15200 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15201
5287ad62
JB
15202 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15203 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15204 inst.instruction |= LOW4 (inst.operands[1].reg);
15205 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15206 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15207 inst.instruction |= (et.type == NT_float) << 10;
15208 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15209
88714cb8 15210 neon_dp_fixup (&inst);
5287ad62
JB
15211}
15212
15213static void
15214do_neon_sli (void)
15215{
037e8744 15216 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15217 struct neon_type_el et = neon_check_type (2, rs,
15218 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15219 int imm = inst.operands[2].imm;
15220 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15221 _("immediate out of range for insert"));
037e8744 15222 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15223}
15224
15225static void
15226do_neon_sri (void)
15227{
037e8744 15228 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15229 struct neon_type_el et = neon_check_type (2, rs,
15230 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15231 int imm = inst.operands[2].imm;
15232 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15233 _("immediate out of range for insert"));
037e8744 15234 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15235}
15236
15237static void
15238do_neon_qshlu_imm (void)
15239{
037e8744 15240 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15241 struct neon_type_el et = neon_check_type (2, rs,
15242 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15243 int imm = inst.operands[2].imm;
15244 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15245 _("immediate out of range for shift"));
5287ad62
JB
15246 /* Only encodes the 'U present' variant of the instruction.
15247 In this case, signed types have OP (bit 8) set to 0.
15248 Unsigned types have OP set to 1. */
15249 inst.instruction |= (et.type == NT_unsigned) << 8;
15250 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15251 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15252}
15253
15254static void
15255do_neon_qmovn (void)
15256{
15257 struct neon_type_el et = neon_check_type (2, NS_DQ,
15258 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15259 /* Saturating move where operands can be signed or unsigned, and the
15260 destination has the same signedness. */
88714cb8 15261 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15262 if (et.type == NT_unsigned)
15263 inst.instruction |= 0xc0;
15264 else
15265 inst.instruction |= 0x80;
15266 neon_two_same (0, 1, et.size / 2);
15267}
15268
15269static void
15270do_neon_qmovun (void)
15271{
15272 struct neon_type_el et = neon_check_type (2, NS_DQ,
15273 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15274 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15275 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15276 neon_two_same (0, 1, et.size / 2);
15277}
15278
15279static void
15280do_neon_rshift_sat_narrow (void)
15281{
15282 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15283 or unsigned. If operands are unsigned, results must also be unsigned. */
15284 struct neon_type_el et = neon_check_type (2, NS_DQI,
15285 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15286 int imm = inst.operands[2].imm;
15287 /* This gets the bounds check, size encoding and immediate bits calculation
15288 right. */
15289 et.size /= 2;
5f4273c7 15290
5287ad62
JB
15291 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15292 VQMOVN.I<size> <Dd>, <Qm>. */
15293 if (imm == 0)
15294 {
15295 inst.operands[2].present = 0;
15296 inst.instruction = N_MNEM_vqmovn;
15297 do_neon_qmovn ();
15298 return;
15299 }
5f4273c7 15300
5287ad62 15301 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15302 _("immediate out of range"));
5287ad62
JB
15303 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15304}
15305
15306static void
15307do_neon_rshift_sat_narrow_u (void)
15308{
15309 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15310 or unsigned. If operands are unsigned, results must also be unsigned. */
15311 struct neon_type_el et = neon_check_type (2, NS_DQI,
15312 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15313 int imm = inst.operands[2].imm;
15314 /* This gets the bounds check, size encoding and immediate bits calculation
15315 right. */
15316 et.size /= 2;
15317
15318 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15319 VQMOVUN.I<size> <Dd>, <Qm>. */
15320 if (imm == 0)
15321 {
15322 inst.operands[2].present = 0;
15323 inst.instruction = N_MNEM_vqmovun;
15324 do_neon_qmovun ();
15325 return;
15326 }
15327
15328 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15329 _("immediate out of range"));
5287ad62
JB
15330 /* FIXME: The manual is kind of unclear about what value U should have in
15331 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15332 must be 1. */
15333 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15334}
15335
15336static void
15337do_neon_movn (void)
15338{
15339 struct neon_type_el et = neon_check_type (2, NS_DQ,
15340 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15341 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15342 neon_two_same (0, 1, et.size / 2);
15343}
15344
15345static void
15346do_neon_rshift_narrow (void)
15347{
15348 struct neon_type_el et = neon_check_type (2, NS_DQI,
15349 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15350 int imm = inst.operands[2].imm;
15351 /* This gets the bounds check, size encoding and immediate bits calculation
15352 right. */
15353 et.size /= 2;
5f4273c7 15354
5287ad62
JB
15355 /* If immediate is zero then we are a pseudo-instruction for
15356 VMOVN.I<size> <Dd>, <Qm> */
15357 if (imm == 0)
15358 {
15359 inst.operands[2].present = 0;
15360 inst.instruction = N_MNEM_vmovn;
15361 do_neon_movn ();
15362 return;
15363 }
5f4273c7 15364
5287ad62 15365 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15366 _("immediate out of range for narrowing operation"));
5287ad62
JB
15367 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15368}
15369
15370static void
15371do_neon_shll (void)
15372{
15373 /* FIXME: Type checking when lengthening. */
15374 struct neon_type_el et = neon_check_type (2, NS_QDI,
15375 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15376 unsigned imm = inst.operands[2].imm;
15377
15378 if (imm == et.size)
15379 {
15380 /* Maximum shift variant. */
88714cb8 15381 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15382 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15383 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15384 inst.instruction |= LOW4 (inst.operands[1].reg);
15385 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15386 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15387
88714cb8 15388 neon_dp_fixup (&inst);
5287ad62
JB
15389 }
15390 else
15391 {
15392 /* A more-specific type check for non-max versions. */
15393 et = neon_check_type (2, NS_QDI,
477330fc 15394 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15395 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15396 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15397 }
15398}
15399
037e8744 15400/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15401 the current instruction is. */
15402
6b9a8b67
MGD
15403#define CVT_FLAVOUR_VAR \
15404 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15405 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15406 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15407 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15408 /* Half-precision conversions. */ \
cc933301
JW
15409 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15410 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15411 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15412 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15413 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15414 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15415 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15416 Compared with single/double precision variants, only the co-processor \
15417 field is different, so the encoding flow is reused here. */ \
15418 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15419 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15420 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15421 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15422 /* VFP instructions. */ \
15423 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15424 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15425 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15426 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15427 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15428 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15429 /* VFP instructions with bitshift. */ \
15430 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15431 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15432 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15433 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15434 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15435 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15436 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15437 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15438
15439#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15440 neon_cvt_flavour_##C,
15441
15442/* The different types of conversions we can do. */
15443enum neon_cvt_flavour
15444{
15445 CVT_FLAVOUR_VAR
15446 neon_cvt_flavour_invalid,
15447 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15448};
15449
15450#undef CVT_VAR
15451
15452static enum neon_cvt_flavour
15453get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15454{
6b9a8b67
MGD
15455#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15456 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15457 if (et.type != NT_invtype) \
15458 { \
15459 inst.error = NULL; \
15460 return (neon_cvt_flavour_##C); \
5287ad62 15461 }
6b9a8b67 15462
5287ad62 15463 struct neon_type_el et;
037e8744 15464 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15465 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15466 /* The instruction versions which take an immediate take one register
15467 argument, which is extended to the width of the full register. Thus the
15468 "source" and "destination" registers must have the same width. Hack that
15469 here by making the size equal to the key (wider, in this case) operand. */
15470 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15471
6b9a8b67
MGD
15472 CVT_FLAVOUR_VAR;
15473
15474 return neon_cvt_flavour_invalid;
5287ad62
JB
15475#undef CVT_VAR
15476}
15477
7e8e6784
MGD
15478enum neon_cvt_mode
15479{
15480 neon_cvt_mode_a,
15481 neon_cvt_mode_n,
15482 neon_cvt_mode_p,
15483 neon_cvt_mode_m,
15484 neon_cvt_mode_z,
30bdf752
MGD
15485 neon_cvt_mode_x,
15486 neon_cvt_mode_r
7e8e6784
MGD
15487};
15488
037e8744
JB
15489/* Neon-syntax VFP conversions. */
15490
5287ad62 15491static void
6b9a8b67 15492do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15493{
037e8744 15494 const char *opname = 0;
5f4273c7 15495
d54af2d0
RL
15496 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15497 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15498 {
037e8744
JB
15499 /* Conversions with immediate bitshift. */
15500 const char *enc[] =
477330fc 15501 {
6b9a8b67
MGD
15502#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15503 CVT_FLAVOUR_VAR
15504 NULL
15505#undef CVT_VAR
477330fc 15506 };
037e8744 15507
6b9a8b67 15508 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15509 {
15510 opname = enc[flavour];
15511 constraint (inst.operands[0].reg != inst.operands[1].reg,
15512 _("operands 0 and 1 must be the same register"));
15513 inst.operands[1] = inst.operands[2];
15514 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15515 }
5287ad62
JB
15516 }
15517 else
15518 {
037e8744
JB
15519 /* Conversions without bitshift. */
15520 const char *enc[] =
477330fc 15521 {
6b9a8b67
MGD
15522#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15523 CVT_FLAVOUR_VAR
15524 NULL
15525#undef CVT_VAR
477330fc 15526 };
037e8744 15527
6b9a8b67 15528 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15529 opname = enc[flavour];
037e8744
JB
15530 }
15531
15532 if (opname)
15533 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15534
15535 /* ARMv8.2 fp16 VCVT instruction. */
15536 if (flavour == neon_cvt_flavour_s32_f16
15537 || flavour == neon_cvt_flavour_u32_f16
15538 || flavour == neon_cvt_flavour_f16_u32
15539 || flavour == neon_cvt_flavour_f16_s32)
15540 do_scalar_fp16_v82_encode ();
037e8744
JB
15541}
15542
15543static void
15544do_vfp_nsyn_cvtz (void)
15545{
d54af2d0 15546 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15547 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15548 const char *enc[] =
15549 {
6b9a8b67
MGD
15550#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15551 CVT_FLAVOUR_VAR
15552 NULL
15553#undef CVT_VAR
037e8744
JB
15554 };
15555
6b9a8b67 15556 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15557 do_vfp_nsyn_opcode (enc[flavour]);
15558}
f31fef98 15559
037e8744 15560static void
bacebabc 15561do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15562 enum neon_cvt_mode mode)
15563{
15564 int sz, op;
15565 int rm;
15566
a715796b
TG
15567 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15568 D register operands. */
15569 if (flavour == neon_cvt_flavour_s32_f64
15570 || flavour == neon_cvt_flavour_u32_f64)
15571 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15572 _(BAD_FPU));
15573
9db2f6b4
RL
15574 if (flavour == neon_cvt_flavour_s32_f16
15575 || flavour == neon_cvt_flavour_u32_f16)
15576 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15577 _(BAD_FP16));
15578
7e8e6784
MGD
15579 set_it_insn_type (OUTSIDE_IT_INSN);
15580
15581 switch (flavour)
15582 {
15583 case neon_cvt_flavour_s32_f64:
15584 sz = 1;
827f64ff 15585 op = 1;
7e8e6784
MGD
15586 break;
15587 case neon_cvt_flavour_s32_f32:
15588 sz = 0;
15589 op = 1;
15590 break;
9db2f6b4
RL
15591 case neon_cvt_flavour_s32_f16:
15592 sz = 0;
15593 op = 1;
15594 break;
7e8e6784
MGD
15595 case neon_cvt_flavour_u32_f64:
15596 sz = 1;
15597 op = 0;
15598 break;
15599 case neon_cvt_flavour_u32_f32:
15600 sz = 0;
15601 op = 0;
15602 break;
9db2f6b4
RL
15603 case neon_cvt_flavour_u32_f16:
15604 sz = 0;
15605 op = 0;
15606 break;
7e8e6784
MGD
15607 default:
15608 first_error (_("invalid instruction shape"));
15609 return;
15610 }
15611
15612 switch (mode)
15613 {
15614 case neon_cvt_mode_a: rm = 0; break;
15615 case neon_cvt_mode_n: rm = 1; break;
15616 case neon_cvt_mode_p: rm = 2; break;
15617 case neon_cvt_mode_m: rm = 3; break;
15618 default: first_error (_("invalid rounding mode")); return;
15619 }
15620
15621 NEON_ENCODE (FPV8, inst);
15622 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15623 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15624 inst.instruction |= sz << 8;
9db2f6b4
RL
15625
15626 /* ARMv8.2 fp16 VCVT instruction. */
15627 if (flavour == neon_cvt_flavour_s32_f16
15628 ||flavour == neon_cvt_flavour_u32_f16)
15629 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15630 inst.instruction |= op << 7;
15631 inst.instruction |= rm << 16;
15632 inst.instruction |= 0xf0000000;
15633 inst.is_neon = TRUE;
15634}
15635
15636static void
15637do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15638{
15639 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15640 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15641 NS_FH, NS_HF, NS_FHI, NS_HFI,
15642 NS_NULL);
6b9a8b67 15643 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15644
cc933301
JW
15645 if (flavour == neon_cvt_flavour_invalid)
15646 return;
15647
e3e535bc 15648 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15649 if (mode == neon_cvt_mode_z
e3e535bc 15650 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15651 && (flavour == neon_cvt_flavour_s16_f16
15652 || flavour == neon_cvt_flavour_u16_f16
15653 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15654 || flavour == neon_cvt_flavour_u32_f32
15655 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15656 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15657 && (rs == NS_FD || rs == NS_FF))
15658 {
15659 do_vfp_nsyn_cvtz ();
15660 return;
15661 }
15662
9db2f6b4
RL
15663 /* ARMv8.2 fp16 VCVT conversions. */
15664 if (mode == neon_cvt_mode_z
15665 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15666 && (flavour == neon_cvt_flavour_s32_f16
15667 || flavour == neon_cvt_flavour_u32_f16)
15668 && (rs == NS_FH))
15669 {
15670 do_vfp_nsyn_cvtz ();
15671 do_scalar_fp16_v82_encode ();
15672 return;
15673 }
15674
037e8744 15675 /* VFP rather than Neon conversions. */
6b9a8b67 15676 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15677 {
7e8e6784
MGD
15678 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15679 do_vfp_nsyn_cvt (rs, flavour);
15680 else
15681 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15682
037e8744
JB
15683 return;
15684 }
15685
15686 switch (rs)
15687 {
15688 case NS_DDI:
15689 case NS_QQI:
15690 {
477330fc 15691 unsigned immbits;
cc933301
JW
15692 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15693 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15694
477330fc
RM
15695 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15696 return;
037e8744 15697
477330fc
RM
15698 /* Fixed-point conversion with #0 immediate is encoded as an
15699 integer conversion. */
15700 if (inst.operands[2].present && inst.operands[2].imm == 0)
15701 goto int_encode;
477330fc
RM
15702 NEON_ENCODE (IMMED, inst);
15703 if (flavour != neon_cvt_flavour_invalid)
15704 inst.instruction |= enctab[flavour];
15705 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15707 inst.instruction |= LOW4 (inst.operands[1].reg);
15708 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15709 inst.instruction |= neon_quad (rs) << 6;
15710 inst.instruction |= 1 << 21;
cc933301
JW
15711 if (flavour < neon_cvt_flavour_s16_f16)
15712 {
15713 inst.instruction |= 1 << 21;
15714 immbits = 32 - inst.operands[2].imm;
15715 inst.instruction |= immbits << 16;
15716 }
15717 else
15718 {
15719 inst.instruction |= 3 << 20;
15720 immbits = 16 - inst.operands[2].imm;
15721 inst.instruction |= immbits << 16;
15722 inst.instruction &= ~(1 << 9);
15723 }
477330fc
RM
15724
15725 neon_dp_fixup (&inst);
037e8744
JB
15726 }
15727 break;
15728
15729 case NS_DD:
15730 case NS_QQ:
7e8e6784
MGD
15731 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15732 {
15733 NEON_ENCODE (FLOAT, inst);
15734 set_it_insn_type (OUTSIDE_IT_INSN);
15735
15736 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15737 return;
15738
15739 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15740 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15741 inst.instruction |= LOW4 (inst.operands[1].reg);
15742 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15743 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15744 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15745 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15746 inst.instruction |= mode << 8;
cc933301
JW
15747 if (flavour == neon_cvt_flavour_u16_f16
15748 || flavour == neon_cvt_flavour_s16_f16)
15749 /* Mask off the original size bits and reencode them. */
15750 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15751
7e8e6784
MGD
15752 if (thumb_mode)
15753 inst.instruction |= 0xfc000000;
15754 else
15755 inst.instruction |= 0xf0000000;
15756 }
15757 else
15758 {
037e8744 15759 int_encode:
7e8e6784 15760 {
cc933301
JW
15761 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15762 0x100, 0x180, 0x0, 0x080};
037e8744 15763
7e8e6784 15764 NEON_ENCODE (INTEGER, inst);
037e8744 15765
7e8e6784
MGD
15766 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15767 return;
037e8744 15768
7e8e6784
MGD
15769 if (flavour != neon_cvt_flavour_invalid)
15770 inst.instruction |= enctab[flavour];
037e8744 15771
7e8e6784
MGD
15772 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15773 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15774 inst.instruction |= LOW4 (inst.operands[1].reg);
15775 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15776 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15777 if (flavour >= neon_cvt_flavour_s16_f16
15778 && flavour <= neon_cvt_flavour_f16_u16)
15779 /* Half precision. */
15780 inst.instruction |= 1 << 18;
15781 else
15782 inst.instruction |= 2 << 18;
037e8744 15783
7e8e6784
MGD
15784 neon_dp_fixup (&inst);
15785 }
15786 }
15787 break;
037e8744 15788
8e79c3df
CM
15789 /* Half-precision conversions for Advanced SIMD -- neon. */
15790 case NS_QD:
15791 case NS_DQ:
15792
15793 if ((rs == NS_DQ)
15794 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15795 {
15796 as_bad (_("operand size must match register width"));
15797 break;
15798 }
15799
15800 if ((rs == NS_QD)
15801 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15802 {
15803 as_bad (_("operand size must match register width"));
15804 break;
15805 }
15806
15807 if (rs == NS_DQ)
477330fc 15808 inst.instruction = 0x3b60600;
8e79c3df
CM
15809 else
15810 inst.instruction = 0x3b60700;
15811
15812 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15813 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15814 inst.instruction |= LOW4 (inst.operands[1].reg);
15815 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15816 neon_dp_fixup (&inst);
8e79c3df
CM
15817 break;
15818
037e8744
JB
15819 default:
15820 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15821 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15822 do_vfp_nsyn_cvt (rs, flavour);
15823 else
15824 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15825 }
5287ad62
JB
15826}
15827
e3e535bc
NC
15828static void
15829do_neon_cvtr (void)
15830{
7e8e6784 15831 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15832}
15833
15834static void
15835do_neon_cvt (void)
15836{
7e8e6784
MGD
15837 do_neon_cvt_1 (neon_cvt_mode_z);
15838}
15839
15840static void
15841do_neon_cvta (void)
15842{
15843 do_neon_cvt_1 (neon_cvt_mode_a);
15844}
15845
15846static void
15847do_neon_cvtn (void)
15848{
15849 do_neon_cvt_1 (neon_cvt_mode_n);
15850}
15851
15852static void
15853do_neon_cvtp (void)
15854{
15855 do_neon_cvt_1 (neon_cvt_mode_p);
15856}
15857
15858static void
15859do_neon_cvtm (void)
15860{
15861 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15862}
15863
8e79c3df 15864static void
c70a8987 15865do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15866{
c70a8987
MGD
15867 if (is_double)
15868 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15869
c70a8987
MGD
15870 encode_arm_vfp_reg (inst.operands[0].reg,
15871 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15872 encode_arm_vfp_reg (inst.operands[1].reg,
15873 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15874 inst.instruction |= to ? 0x10000 : 0;
15875 inst.instruction |= t ? 0x80 : 0;
15876 inst.instruction |= is_double ? 0x100 : 0;
15877 do_vfp_cond_or_thumb ();
15878}
8e79c3df 15879
c70a8987
MGD
15880static void
15881do_neon_cvttb_1 (bfd_boolean t)
15882{
d54af2d0
RL
15883 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15884 NS_DF, NS_DH, NS_NULL);
8e79c3df 15885
c70a8987
MGD
15886 if (rs == NS_NULL)
15887 return;
15888 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15889 {
15890 inst.error = NULL;
15891 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15892 }
15893 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15894 {
15895 inst.error = NULL;
15896 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15897 }
15898 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15899 {
a715796b
TG
15900 /* The VCVTB and VCVTT instructions with D-register operands
15901 don't work for SP only targets. */
15902 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15903 _(BAD_FPU));
15904
c70a8987
MGD
15905 inst.error = NULL;
15906 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15907 }
15908 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15909 {
a715796b
TG
15910 /* The VCVTB and VCVTT instructions with D-register operands
15911 don't work for SP only targets. */
15912 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15913 _(BAD_FPU));
15914
c70a8987
MGD
15915 inst.error = NULL;
15916 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15917 }
15918 else
15919 return;
15920}
15921
15922static void
15923do_neon_cvtb (void)
15924{
15925 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15926}
15927
15928
15929static void
15930do_neon_cvtt (void)
15931{
c70a8987 15932 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15933}
15934
5287ad62
JB
15935static void
15936neon_move_immediate (void)
15937{
037e8744
JB
15938 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15939 struct neon_type_el et = neon_check_type (2, rs,
15940 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15941 unsigned immlo, immhi = 0, immbits;
c96612cc 15942 int op, cmode, float_p;
5287ad62 15943
037e8744 15944 constraint (et.type == NT_invtype,
477330fc 15945 _("operand size must be specified for immediate VMOV"));
037e8744 15946
5287ad62
JB
15947 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15948 op = (inst.instruction & (1 << 5)) != 0;
15949
15950 immlo = inst.operands[1].imm;
15951 if (inst.operands[1].regisimm)
15952 immhi = inst.operands[1].reg;
15953
15954 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15955 _("immediate has bits set outside the operand size"));
5287ad62 15956
c96612cc
JB
15957 float_p = inst.operands[1].immisfloat;
15958
15959 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15960 et.size, et.type)) == FAIL)
5287ad62
JB
15961 {
15962 /* Invert relevant bits only. */
15963 neon_invert_size (&immlo, &immhi, et.size);
15964 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15965 with one or the other; those cases are caught by
15966 neon_cmode_for_move_imm. */
5287ad62 15967 op = !op;
c96612cc
JB
15968 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15969 &op, et.size, et.type)) == FAIL)
477330fc
RM
15970 {
15971 first_error (_("immediate out of range"));
15972 return;
15973 }
5287ad62
JB
15974 }
15975
15976 inst.instruction &= ~(1 << 5);
15977 inst.instruction |= op << 5;
15978
15979 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15981 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15982 inst.instruction |= cmode << 8;
15983
15984 neon_write_immbits (immbits);
15985}
15986
15987static void
15988do_neon_mvn (void)
15989{
15990 if (inst.operands[1].isreg)
15991 {
037e8744 15992 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15993
88714cb8 15994 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15995 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15996 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15997 inst.instruction |= LOW4 (inst.operands[1].reg);
15998 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15999 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16000 }
16001 else
16002 {
88714cb8 16003 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16004 neon_move_immediate ();
16005 }
16006
88714cb8 16007 neon_dp_fixup (&inst);
5287ad62
JB
16008}
16009
16010/* Encode instructions of form:
16011
16012 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16013 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16014
16015static void
16016neon_mixed_length (struct neon_type_el et, unsigned size)
16017{
16018 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16019 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16020 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16021 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16022 inst.instruction |= LOW4 (inst.operands[2].reg);
16023 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16024 inst.instruction |= (et.type == NT_unsigned) << 24;
16025 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16026
88714cb8 16027 neon_dp_fixup (&inst);
5287ad62
JB
16028}
16029
16030static void
16031do_neon_dyadic_long (void)
16032{
16033 /* FIXME: Type checking for lengthening op. */
16034 struct neon_type_el et = neon_check_type (3, NS_QDD,
16035 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16036 neon_mixed_length (et, et.size);
16037}
16038
16039static void
16040do_neon_abal (void)
16041{
16042 struct neon_type_el et = neon_check_type (3, NS_QDD,
16043 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16044 neon_mixed_length (et, et.size);
16045}
16046
16047static void
16048neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16049{
16050 if (inst.operands[2].isscalar)
16051 {
dcbf9037 16052 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16053 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16054 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16055 neon_mul_mac (et, et.type == NT_unsigned);
16056 }
16057 else
16058 {
16059 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16060 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16061 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16062 neon_mixed_length (et, et.size);
16063 }
16064}
16065
16066static void
16067do_neon_mac_maybe_scalar_long (void)
16068{
16069 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16070}
16071
16072static void
16073do_neon_dyadic_wide (void)
16074{
16075 struct neon_type_el et = neon_check_type (3, NS_QQD,
16076 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16077 neon_mixed_length (et, et.size);
16078}
16079
16080static void
16081do_neon_dyadic_narrow (void)
16082{
16083 struct neon_type_el et = neon_check_type (3, NS_QDD,
16084 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16085 /* Operand sign is unimportant, and the U bit is part of the opcode,
16086 so force the operand type to integer. */
16087 et.type = NT_integer;
5287ad62
JB
16088 neon_mixed_length (et, et.size / 2);
16089}
16090
16091static void
16092do_neon_mul_sat_scalar_long (void)
16093{
16094 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16095}
16096
16097static void
16098do_neon_vmull (void)
16099{
16100 if (inst.operands[2].isscalar)
16101 do_neon_mac_maybe_scalar_long ();
16102 else
16103 {
16104 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16105 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16106
5287ad62 16107 if (et.type == NT_poly)
477330fc 16108 NEON_ENCODE (POLY, inst);
5287ad62 16109 else
477330fc 16110 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16111
16112 /* For polynomial encoding the U bit must be zero, and the size must
16113 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16114 obviously, as 0b10). */
16115 if (et.size == 64)
16116 {
16117 /* Check we're on the correct architecture. */
16118 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16119 inst.error =
16120 _("Instruction form not available on this architecture.");
16121
16122 et.size = 32;
16123 }
16124
5287ad62
JB
16125 neon_mixed_length (et, et.size);
16126 }
16127}
16128
16129static void
16130do_neon_ext (void)
16131{
037e8744 16132 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16133 struct neon_type_el et = neon_check_type (3, rs,
16134 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16135 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16136
16137 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16138 _("shift out of range"));
5287ad62
JB
16139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16141 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16142 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16143 inst.instruction |= LOW4 (inst.operands[2].reg);
16144 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16145 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16146 inst.instruction |= imm << 8;
5f4273c7 16147
88714cb8 16148 neon_dp_fixup (&inst);
5287ad62
JB
16149}
16150
16151static void
16152do_neon_rev (void)
16153{
037e8744 16154 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16155 struct neon_type_el et = neon_check_type (2, rs,
16156 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16157 unsigned op = (inst.instruction >> 7) & 3;
16158 /* N (width of reversed regions) is encoded as part of the bitmask. We
16159 extract it here to check the elements to be reversed are smaller.
16160 Otherwise we'd get a reserved instruction. */
16161 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16162 gas_assert (elsize != 0);
5287ad62 16163 constraint (et.size >= elsize,
477330fc 16164 _("elements must be smaller than reversal region"));
037e8744 16165 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16166}
16167
16168static void
16169do_neon_dup (void)
16170{
16171 if (inst.operands[1].isscalar)
16172 {
037e8744 16173 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16174 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16175 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16176 unsigned sizebits = et.size >> 3;
dcbf9037 16177 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16178 int logsize = neon_logbits (et.size);
dcbf9037 16179 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16180
16181 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16182 return;
037e8744 16183
88714cb8 16184 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16185 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16186 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16187 inst.instruction |= LOW4 (dm);
16188 inst.instruction |= HI1 (dm) << 5;
037e8744 16189 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16190 inst.instruction |= x << 17;
16191 inst.instruction |= sizebits << 16;
5f4273c7 16192
88714cb8 16193 neon_dp_fixup (&inst);
5287ad62
JB
16194 }
16195 else
16196 {
037e8744
JB
16197 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16198 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16199 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16200 /* Duplicate ARM register to lanes of vector. */
88714cb8 16201 NEON_ENCODE (ARMREG, inst);
5287ad62 16202 switch (et.size)
477330fc
RM
16203 {
16204 case 8: inst.instruction |= 0x400000; break;
16205 case 16: inst.instruction |= 0x000020; break;
16206 case 32: inst.instruction |= 0x000000; break;
16207 default: break;
16208 }
5287ad62
JB
16209 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16210 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16211 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16212 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16213 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16214 variants, except for the condition field. */
037e8744 16215 do_vfp_cond_or_thumb ();
5287ad62
JB
16216 }
16217}
16218
16219/* VMOV has particularly many variations. It can be one of:
16220 0. VMOV<c><q> <Qd>, <Qm>
16221 1. VMOV<c><q> <Dd>, <Dm>
16222 (Register operations, which are VORR with Rm = Rn.)
16223 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16224 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16225 (Immediate loads.)
16226 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16227 (ARM register to scalar.)
16228 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16229 (Two ARM registers to vector.)
16230 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16231 (Scalar to ARM register.)
16232 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16233 (Vector to two ARM registers.)
037e8744
JB
16234 8. VMOV.F32 <Sd>, <Sm>
16235 9. VMOV.F64 <Dd>, <Dm>
16236 (VFP register moves.)
16237 10. VMOV.F32 <Sd>, #imm
16238 11. VMOV.F64 <Dd>, #imm
16239 (VFP float immediate load.)
16240 12. VMOV <Rd>, <Sm>
16241 (VFP single to ARM reg.)
16242 13. VMOV <Sd>, <Rm>
16243 (ARM reg to VFP single.)
16244 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16245 (Two ARM regs to two VFP singles.)
16246 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16247 (Two VFP singles to two ARM regs.)
5f4273c7 16248
037e8744
JB
16249 These cases can be disambiguated using neon_select_shape, except cases 1/9
16250 and 3/11 which depend on the operand type too.
5f4273c7 16251
5287ad62 16252 All the encoded bits are hardcoded by this function.
5f4273c7 16253
b7fc2769
JB
16254 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16255 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16256
5287ad62 16257 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16258 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16259
16260static void
16261do_neon_mov (void)
16262{
037e8744 16263 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16264 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16265 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16266 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16267 struct neon_type_el et;
16268 const char *ldconst = 0;
5287ad62 16269
037e8744 16270 switch (rs)
5287ad62 16271 {
037e8744
JB
16272 case NS_DD: /* case 1/9. */
16273 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16274 /* It is not an error here if no type is given. */
16275 inst.error = NULL;
16276 if (et.type == NT_float && et.size == 64)
477330fc
RM
16277 {
16278 do_vfp_nsyn_opcode ("fcpyd");
16279 break;
16280 }
037e8744 16281 /* fall through. */
5287ad62 16282
037e8744
JB
16283 case NS_QQ: /* case 0/1. */
16284 {
477330fc
RM
16285 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16286 return;
16287 /* The architecture manual I have doesn't explicitly state which
16288 value the U bit should have for register->register moves, but
16289 the equivalent VORR instruction has U = 0, so do that. */
16290 inst.instruction = 0x0200110;
16291 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16292 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16293 inst.instruction |= LOW4 (inst.operands[1].reg);
16294 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16295 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16296 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16297 inst.instruction |= neon_quad (rs) << 6;
16298
16299 neon_dp_fixup (&inst);
037e8744
JB
16300 }
16301 break;
5f4273c7 16302
037e8744
JB
16303 case NS_DI: /* case 3/11. */
16304 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16305 inst.error = NULL;
16306 if (et.type == NT_float && et.size == 64)
477330fc
RM
16307 {
16308 /* case 11 (fconstd). */
16309 ldconst = "fconstd";
16310 goto encode_fconstd;
16311 }
037e8744
JB
16312 /* fall through. */
16313
16314 case NS_QI: /* case 2/3. */
16315 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16316 return;
037e8744
JB
16317 inst.instruction = 0x0800010;
16318 neon_move_immediate ();
88714cb8 16319 neon_dp_fixup (&inst);
5287ad62 16320 break;
5f4273c7 16321
037e8744
JB
16322 case NS_SR: /* case 4. */
16323 {
477330fc
RM
16324 unsigned bcdebits = 0;
16325 int logsize;
16326 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16327 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16328
05ac0ffb
JB
16329 /* .<size> is optional here, defaulting to .32. */
16330 if (inst.vectype.elems == 0
16331 && inst.operands[0].vectype.type == NT_invtype
16332 && inst.operands[1].vectype.type == NT_invtype)
16333 {
16334 inst.vectype.el[0].type = NT_untyped;
16335 inst.vectype.el[0].size = 32;
16336 inst.vectype.elems = 1;
16337 }
16338
477330fc
RM
16339 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16340 logsize = neon_logbits (et.size);
16341
16342 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16343 _(BAD_FPU));
16344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16345 && et.size != 32, _(BAD_FPU));
16346 constraint (et.type == NT_invtype, _("bad type for scalar"));
16347 constraint (x >= 64 / et.size, _("scalar index out of range"));
16348
16349 switch (et.size)
16350 {
16351 case 8: bcdebits = 0x8; break;
16352 case 16: bcdebits = 0x1; break;
16353 case 32: bcdebits = 0x0; break;
16354 default: ;
16355 }
16356
16357 bcdebits |= x << logsize;
16358
16359 inst.instruction = 0xe000b10;
16360 do_vfp_cond_or_thumb ();
16361 inst.instruction |= LOW4 (dn) << 16;
16362 inst.instruction |= HI1 (dn) << 7;
16363 inst.instruction |= inst.operands[1].reg << 12;
16364 inst.instruction |= (bcdebits & 3) << 5;
16365 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16366 }
16367 break;
5f4273c7 16368
037e8744 16369 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16370 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16371 _(BAD_FPU));
b7fc2769 16372
037e8744
JB
16373 inst.instruction = 0xc400b10;
16374 do_vfp_cond_or_thumb ();
16375 inst.instruction |= LOW4 (inst.operands[0].reg);
16376 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16377 inst.instruction |= inst.operands[1].reg << 12;
16378 inst.instruction |= inst.operands[2].reg << 16;
16379 break;
5f4273c7 16380
037e8744
JB
16381 case NS_RS: /* case 6. */
16382 {
477330fc
RM
16383 unsigned logsize;
16384 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16385 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16386 unsigned abcdebits = 0;
037e8744 16387
05ac0ffb
JB
16388 /* .<dt> is optional here, defaulting to .32. */
16389 if (inst.vectype.elems == 0
16390 && inst.operands[0].vectype.type == NT_invtype
16391 && inst.operands[1].vectype.type == NT_invtype)
16392 {
16393 inst.vectype.el[0].type = NT_untyped;
16394 inst.vectype.el[0].size = 32;
16395 inst.vectype.elems = 1;
16396 }
16397
91d6fa6a
NC
16398 et = neon_check_type (2, NS_NULL,
16399 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16400 logsize = neon_logbits (et.size);
16401
16402 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16403 _(BAD_FPU));
16404 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16405 && et.size != 32, _(BAD_FPU));
16406 constraint (et.type == NT_invtype, _("bad type for scalar"));
16407 constraint (x >= 64 / et.size, _("scalar index out of range"));
16408
16409 switch (et.size)
16410 {
16411 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16412 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16413 case 32: abcdebits = 0x00; break;
16414 default: ;
16415 }
16416
16417 abcdebits |= x << logsize;
16418 inst.instruction = 0xe100b10;
16419 do_vfp_cond_or_thumb ();
16420 inst.instruction |= LOW4 (dn) << 16;
16421 inst.instruction |= HI1 (dn) << 7;
16422 inst.instruction |= inst.operands[0].reg << 12;
16423 inst.instruction |= (abcdebits & 3) << 5;
16424 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16425 }
16426 break;
5f4273c7 16427
037e8744
JB
16428 case NS_RRD: /* case 7 (fmrrd). */
16429 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16430 _(BAD_FPU));
037e8744
JB
16431
16432 inst.instruction = 0xc500b10;
16433 do_vfp_cond_or_thumb ();
16434 inst.instruction |= inst.operands[0].reg << 12;
16435 inst.instruction |= inst.operands[1].reg << 16;
16436 inst.instruction |= LOW4 (inst.operands[2].reg);
16437 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16438 break;
5f4273c7 16439
037e8744
JB
16440 case NS_FF: /* case 8 (fcpys). */
16441 do_vfp_nsyn_opcode ("fcpys");
16442 break;
5f4273c7 16443
9db2f6b4 16444 case NS_HI:
037e8744
JB
16445 case NS_FI: /* case 10 (fconsts). */
16446 ldconst = "fconsts";
16447 encode_fconstd:
16448 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16449 {
16450 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16451 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16452
16453 /* ARMv8.2 fp16 vmov.f16 instruction. */
16454 if (rs == NS_HI)
16455 do_scalar_fp16_v82_encode ();
477330fc 16456 }
5287ad62 16457 else
477330fc 16458 first_error (_("immediate out of range"));
037e8744 16459 break;
5f4273c7 16460
9db2f6b4 16461 case NS_RH:
037e8744
JB
16462 case NS_RF: /* case 12 (fmrs). */
16463 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16464 /* ARMv8.2 fp16 vmov.f16 instruction. */
16465 if (rs == NS_RH)
16466 do_scalar_fp16_v82_encode ();
037e8744 16467 break;
5f4273c7 16468
9db2f6b4 16469 case NS_HR:
037e8744
JB
16470 case NS_FR: /* case 13 (fmsr). */
16471 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16472 /* ARMv8.2 fp16 vmov.f16 instruction. */
16473 if (rs == NS_HR)
16474 do_scalar_fp16_v82_encode ();
037e8744 16475 break;
5f4273c7 16476
037e8744
JB
16477 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16478 (one of which is a list), but we have parsed four. Do some fiddling to
16479 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16480 expect. */
16481 case NS_RRFF: /* case 14 (fmrrs). */
16482 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16483 _("VFP registers must be adjacent"));
037e8744
JB
16484 inst.operands[2].imm = 2;
16485 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16486 do_vfp_nsyn_opcode ("fmrrs");
16487 break;
5f4273c7 16488
037e8744
JB
16489 case NS_FFRR: /* case 15 (fmsrr). */
16490 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16491 _("VFP registers must be adjacent"));
037e8744
JB
16492 inst.operands[1] = inst.operands[2];
16493 inst.operands[2] = inst.operands[3];
16494 inst.operands[0].imm = 2;
16495 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16496 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16497 break;
5f4273c7 16498
4c261dff
NC
16499 case NS_NULL:
16500 /* neon_select_shape has determined that the instruction
16501 shape is wrong and has already set the error message. */
16502 break;
16503
5287ad62
JB
16504 default:
16505 abort ();
16506 }
16507}
16508
16509static void
16510do_neon_rshift_round_imm (void)
16511{
037e8744 16512 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16513 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16514 int imm = inst.operands[2].imm;
16515
16516 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16517 if (imm == 0)
16518 {
16519 inst.operands[2].present = 0;
16520 do_neon_mov ();
16521 return;
16522 }
16523
16524 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16525 _("immediate out of range for shift"));
037e8744 16526 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16527 et.size - imm);
5287ad62
JB
16528}
16529
9db2f6b4
RL
16530static void
16531do_neon_movhf (void)
16532{
16533 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16534 constraint (rs != NS_HH, _("invalid suffix"));
16535
16536 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16537 _(BAD_FPU));
16538
16539 do_vfp_sp_monadic ();
16540
16541 inst.is_neon = 1;
16542 inst.instruction |= 0xf0000000;
16543}
16544
5287ad62
JB
16545static void
16546do_neon_movl (void)
16547{
16548 struct neon_type_el et = neon_check_type (2, NS_QD,
16549 N_EQK | N_DBL, N_SU_32 | N_KEY);
16550 unsigned sizebits = et.size >> 3;
16551 inst.instruction |= sizebits << 19;
16552 neon_two_same (0, et.type == NT_unsigned, -1);
16553}
16554
16555static void
16556do_neon_trn (void)
16557{
037e8744 16558 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16559 struct neon_type_el et = neon_check_type (2, rs,
16560 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16561 NEON_ENCODE (INTEGER, inst);
037e8744 16562 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16563}
16564
16565static void
16566do_neon_zip_uzp (void)
16567{
037e8744 16568 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16569 struct neon_type_el et = neon_check_type (2, rs,
16570 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16571 if (rs == NS_DD && et.size == 32)
16572 {
16573 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16574 inst.instruction = N_MNEM_vtrn;
16575 do_neon_trn ();
16576 return;
16577 }
037e8744 16578 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16579}
16580
16581static void
16582do_neon_sat_abs_neg (void)
16583{
037e8744 16584 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16585 struct neon_type_el et = neon_check_type (2, rs,
16586 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16587 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16588}
16589
16590static void
16591do_neon_pair_long (void)
16592{
037e8744 16593 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16594 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16595 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16596 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16597 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16598}
16599
16600static void
16601do_neon_recip_est (void)
16602{
037e8744 16603 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16604 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16605 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16606 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16607 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16608}
16609
16610static void
16611do_neon_cls (void)
16612{
037e8744 16613 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16614 struct neon_type_el et = neon_check_type (2, rs,
16615 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16616 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16617}
16618
16619static void
16620do_neon_clz (void)
16621{
037e8744 16622 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16623 struct neon_type_el et = neon_check_type (2, rs,
16624 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16625 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16626}
16627
16628static void
16629do_neon_cnt (void)
16630{
037e8744 16631 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16632 struct neon_type_el et = neon_check_type (2, rs,
16633 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16634 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16635}
16636
16637static void
16638do_neon_swp (void)
16639{
037e8744
JB
16640 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16641 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16642}
16643
16644static void
16645do_neon_tbl_tbx (void)
16646{
16647 unsigned listlenbits;
dcbf9037 16648 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16649
5287ad62
JB
16650 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16651 {
dcbf9037 16652 first_error (_("bad list length for table lookup"));
5287ad62
JB
16653 return;
16654 }
5f4273c7 16655
5287ad62
JB
16656 listlenbits = inst.operands[1].imm - 1;
16657 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16658 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16659 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16660 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16661 inst.instruction |= LOW4 (inst.operands[2].reg);
16662 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16663 inst.instruction |= listlenbits << 8;
5f4273c7 16664
88714cb8 16665 neon_dp_fixup (&inst);
5287ad62
JB
16666}
16667
16668static void
16669do_neon_ldm_stm (void)
16670{
16671 /* P, U and L bits are part of bitmask. */
16672 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16673 unsigned offsetbits = inst.operands[1].imm * 2;
16674
037e8744
JB
16675 if (inst.operands[1].issingle)
16676 {
16677 do_vfp_nsyn_ldm_stm (is_dbmode);
16678 return;
16679 }
16680
5287ad62 16681 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16682 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16683
16684 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16685 _("register list must contain at least 1 and at most 16 "
16686 "registers"));
5287ad62
JB
16687
16688 inst.instruction |= inst.operands[0].reg << 16;
16689 inst.instruction |= inst.operands[0].writeback << 21;
16690 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16691 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16692
16693 inst.instruction |= offsetbits;
5f4273c7 16694
037e8744 16695 do_vfp_cond_or_thumb ();
5287ad62
JB
16696}
16697
16698static void
16699do_neon_ldr_str (void)
16700{
5287ad62 16701 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16702
6844b2c2
MGD
16703 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16704 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16705 if (!is_ldr
6844b2c2 16706 && inst.operands[1].reg == REG_PC
ba86b375 16707 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16708 {
94dcf8bf 16709 if (thumb_mode)
6844b2c2 16710 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16711 else if (warn_on_deprecated)
5c3696f8 16712 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16713 }
16714
037e8744
JB
16715 if (inst.operands[0].issingle)
16716 {
cd2f129f 16717 if (is_ldr)
477330fc 16718 do_vfp_nsyn_opcode ("flds");
cd2f129f 16719 else
477330fc 16720 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16721
16722 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16723 if (inst.vectype.el[0].size == 16)
16724 do_scalar_fp16_v82_encode ();
5287ad62
JB
16725 }
16726 else
5287ad62 16727 {
cd2f129f 16728 if (is_ldr)
477330fc 16729 do_vfp_nsyn_opcode ("fldd");
5287ad62 16730 else
477330fc 16731 do_vfp_nsyn_opcode ("fstd");
5287ad62 16732 }
5287ad62
JB
16733}
16734
16735/* "interleave" version also handles non-interleaving register VLD1/VST1
16736 instructions. */
16737
16738static void
16739do_neon_ld_st_interleave (void)
16740{
037e8744 16741 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16742 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16743 unsigned alignbits = 0;
16744 unsigned idx;
16745 /* The bits in this table go:
16746 0: register stride of one (0) or two (1)
16747 1,2: register list length, minus one (1, 2, 3, 4).
16748 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16749 We use -1 for invalid entries. */
16750 const int typetable[] =
16751 {
16752 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16753 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16754 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16755 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16756 };
16757 int typebits;
16758
dcbf9037
JB
16759 if (et.type == NT_invtype)
16760 return;
16761
5287ad62
JB
16762 if (inst.operands[1].immisalign)
16763 switch (inst.operands[1].imm >> 8)
16764 {
16765 case 64: alignbits = 1; break;
16766 case 128:
477330fc 16767 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16768 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16769 goto bad_alignment;
16770 alignbits = 2;
16771 break;
5287ad62 16772 case 256:
477330fc
RM
16773 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16774 goto bad_alignment;
16775 alignbits = 3;
16776 break;
5287ad62
JB
16777 default:
16778 bad_alignment:
477330fc
RM
16779 first_error (_("bad alignment"));
16780 return;
5287ad62
JB
16781 }
16782
16783 inst.instruction |= alignbits << 4;
16784 inst.instruction |= neon_logbits (et.size) << 6;
16785
16786 /* Bits [4:6] of the immediate in a list specifier encode register stride
16787 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16788 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16789 up the right value for "type" in a table based on this value and the given
16790 list style, then stick it back. */
16791 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16792 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16793
16794 typebits = typetable[idx];
5f4273c7 16795
5287ad62 16796 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16797 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16798 _("bad element type for instruction"));
5287ad62
JB
16799
16800 inst.instruction &= ~0xf00;
16801 inst.instruction |= typebits << 8;
16802}
16803
16804/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16805 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16806 otherwise. The variable arguments are a list of pairs of legal (size, align)
16807 values, terminated with -1. */
16808
16809static int
aa8a0863 16810neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16811{
16812 va_list ap;
16813 int result = FAIL, thissize, thisalign;
5f4273c7 16814
5287ad62
JB
16815 if (!inst.operands[1].immisalign)
16816 {
aa8a0863 16817 *do_alignment = 0;
5287ad62
JB
16818 return SUCCESS;
16819 }
5f4273c7 16820
aa8a0863 16821 va_start (ap, do_alignment);
5287ad62
JB
16822
16823 do
16824 {
16825 thissize = va_arg (ap, int);
16826 if (thissize == -1)
477330fc 16827 break;
5287ad62
JB
16828 thisalign = va_arg (ap, int);
16829
16830 if (size == thissize && align == thisalign)
477330fc 16831 result = SUCCESS;
5287ad62
JB
16832 }
16833 while (result != SUCCESS);
16834
16835 va_end (ap);
16836
16837 if (result == SUCCESS)
aa8a0863 16838 *do_alignment = 1;
5287ad62 16839 else
dcbf9037 16840 first_error (_("unsupported alignment for instruction"));
5f4273c7 16841
5287ad62
JB
16842 return result;
16843}
16844
16845static void
16846do_neon_ld_st_lane (void)
16847{
037e8744 16848 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16849 int align_good, do_alignment = 0;
5287ad62
JB
16850 int logsize = neon_logbits (et.size);
16851 int align = inst.operands[1].imm >> 8;
16852 int n = (inst.instruction >> 8) & 3;
16853 int max_el = 64 / et.size;
5f4273c7 16854
dcbf9037
JB
16855 if (et.type == NT_invtype)
16856 return;
5f4273c7 16857
5287ad62 16858 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16859 _("bad list length"));
5287ad62 16860 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16861 _("scalar index out of range"));
5287ad62 16862 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16863 && et.size == 8,
16864 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16865
5287ad62
JB
16866 switch (n)
16867 {
16868 case 0: /* VLD1 / VST1. */
aa8a0863 16869 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16870 32, 32, -1);
5287ad62 16871 if (align_good == FAIL)
477330fc 16872 return;
aa8a0863 16873 if (do_alignment)
477330fc
RM
16874 {
16875 unsigned alignbits = 0;
16876 switch (et.size)
16877 {
16878 case 16: alignbits = 0x1; break;
16879 case 32: alignbits = 0x3; break;
16880 default: ;
16881 }
16882 inst.instruction |= alignbits << 4;
16883 }
5287ad62
JB
16884 break;
16885
16886 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16887 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16888 16, 32, 32, 64, -1);
5287ad62 16889 if (align_good == FAIL)
477330fc 16890 return;
aa8a0863 16891 if (do_alignment)
477330fc 16892 inst.instruction |= 1 << 4;
5287ad62
JB
16893 break;
16894
16895 case 2: /* VLD3 / VST3. */
16896 constraint (inst.operands[1].immisalign,
477330fc 16897 _("can't use alignment with this instruction"));
5287ad62
JB
16898 break;
16899
16900 case 3: /* VLD4 / VST4. */
aa8a0863 16901 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16902 16, 64, 32, 64, 32, 128, -1);
5287ad62 16903 if (align_good == FAIL)
477330fc 16904 return;
aa8a0863 16905 if (do_alignment)
477330fc
RM
16906 {
16907 unsigned alignbits = 0;
16908 switch (et.size)
16909 {
16910 case 8: alignbits = 0x1; break;
16911 case 16: alignbits = 0x1; break;
16912 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16913 default: ;
16914 }
16915 inst.instruction |= alignbits << 4;
16916 }
5287ad62
JB
16917 break;
16918
16919 default: ;
16920 }
16921
16922 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16923 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16924 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16925
5287ad62
JB
16926 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16927 inst.instruction |= logsize << 10;
16928}
16929
16930/* Encode single n-element structure to all lanes VLD<n> instructions. */
16931
16932static void
16933do_neon_ld_dup (void)
16934{
037e8744 16935 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16936 int align_good, do_alignment = 0;
5287ad62 16937
dcbf9037
JB
16938 if (et.type == NT_invtype)
16939 return;
16940
5287ad62
JB
16941 switch ((inst.instruction >> 8) & 3)
16942 {
16943 case 0: /* VLD1. */
9c2799c2 16944 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16945 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16946 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16947 if (align_good == FAIL)
477330fc 16948 return;
5287ad62 16949 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16950 {
16951 case 1: break;
16952 case 2: inst.instruction |= 1 << 5; break;
16953 default: first_error (_("bad list length")); return;
16954 }
5287ad62
JB
16955 inst.instruction |= neon_logbits (et.size) << 6;
16956 break;
16957
16958 case 1: /* VLD2. */
16959 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16960 &do_alignment, 8, 16, 16, 32, 32, 64,
16961 -1);
5287ad62 16962 if (align_good == FAIL)
477330fc 16963 return;
5287ad62 16964 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16965 _("bad list length"));
5287ad62 16966 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16967 inst.instruction |= 1 << 5;
5287ad62
JB
16968 inst.instruction |= neon_logbits (et.size) << 6;
16969 break;
16970
16971 case 2: /* VLD3. */
16972 constraint (inst.operands[1].immisalign,
477330fc 16973 _("can't use alignment with this instruction"));
5287ad62 16974 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16975 _("bad list length"));
5287ad62 16976 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16977 inst.instruction |= 1 << 5;
5287ad62
JB
16978 inst.instruction |= neon_logbits (et.size) << 6;
16979 break;
16980
16981 case 3: /* VLD4. */
16982 {
477330fc 16983 int align = inst.operands[1].imm >> 8;
aa8a0863 16984 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
16985 16, 64, 32, 64, 32, 128, -1);
16986 if (align_good == FAIL)
16987 return;
16988 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16989 _("bad list length"));
16990 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16991 inst.instruction |= 1 << 5;
16992 if (et.size == 32 && align == 128)
16993 inst.instruction |= 0x3 << 6;
16994 else
16995 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16996 }
16997 break;
16998
16999 default: ;
17000 }
17001
aa8a0863 17002 inst.instruction |= do_alignment << 4;
5287ad62
JB
17003}
17004
17005/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17006 apart from bits [11:4]. */
17007
17008static void
17009do_neon_ldx_stx (void)
17010{
b1a769ed
DG
17011 if (inst.operands[1].isreg)
17012 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17013
5287ad62
JB
17014 switch (NEON_LANE (inst.operands[0].imm))
17015 {
17016 case NEON_INTERLEAVE_LANES:
88714cb8 17017 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17018 do_neon_ld_st_interleave ();
17019 break;
5f4273c7 17020
5287ad62 17021 case NEON_ALL_LANES:
88714cb8 17022 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17023 if (inst.instruction == N_INV)
17024 {
17025 first_error ("only loads support such operands");
17026 break;
17027 }
5287ad62
JB
17028 do_neon_ld_dup ();
17029 break;
5f4273c7 17030
5287ad62 17031 default:
88714cb8 17032 NEON_ENCODE (LANE, inst);
5287ad62
JB
17033 do_neon_ld_st_lane ();
17034 }
17035
17036 /* L bit comes from bit mask. */
17037 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17038 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17039 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17040
5287ad62
JB
17041 if (inst.operands[1].postind)
17042 {
17043 int postreg = inst.operands[1].imm & 0xf;
17044 constraint (!inst.operands[1].immisreg,
477330fc 17045 _("post-index must be a register"));
5287ad62 17046 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17047 _("bad register for post-index"));
5287ad62
JB
17048 inst.instruction |= postreg;
17049 }
4f2374c7 17050 else
5287ad62 17051 {
4f2374c7
WN
17052 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17053 constraint (inst.reloc.exp.X_op != O_constant
17054 || inst.reloc.exp.X_add_number != 0,
17055 BAD_ADDR_MODE);
17056
17057 if (inst.operands[1].writeback)
17058 {
17059 inst.instruction |= 0xd;
17060 }
17061 else
17062 inst.instruction |= 0xf;
5287ad62 17063 }
5f4273c7 17064
5287ad62
JB
17065 if (thumb_mode)
17066 inst.instruction |= 0xf9000000;
17067 else
17068 inst.instruction |= 0xf4000000;
17069}
33399f07
MGD
17070
17071/* FP v8. */
17072static void
17073do_vfp_nsyn_fpv8 (enum neon_shape rs)
17074{
a715796b
TG
17075 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17076 D register operands. */
17077 if (neon_shape_class[rs] == SC_DOUBLE)
17078 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17079 _(BAD_FPU));
17080
33399f07
MGD
17081 NEON_ENCODE (FPV8, inst);
17082
9db2f6b4
RL
17083 if (rs == NS_FFF || rs == NS_HHH)
17084 {
17085 do_vfp_sp_dyadic ();
17086
17087 /* ARMv8.2 fp16 instruction. */
17088 if (rs == NS_HHH)
17089 do_scalar_fp16_v82_encode ();
17090 }
33399f07
MGD
17091 else
17092 do_vfp_dp_rd_rn_rm ();
17093
17094 if (rs == NS_DDD)
17095 inst.instruction |= 0x100;
17096
17097 inst.instruction |= 0xf0000000;
17098}
17099
17100static void
17101do_vsel (void)
17102{
17103 set_it_insn_type (OUTSIDE_IT_INSN);
17104
17105 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17106 first_error (_("invalid instruction shape"));
17107}
17108
73924fbc
MGD
17109static void
17110do_vmaxnm (void)
17111{
17112 set_it_insn_type (OUTSIDE_IT_INSN);
17113
17114 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17115 return;
17116
17117 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17118 return;
17119
cc933301 17120 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17121}
17122
30bdf752
MGD
17123static void
17124do_vrint_1 (enum neon_cvt_mode mode)
17125{
9db2f6b4 17126 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17127 struct neon_type_el et;
17128
17129 if (rs == NS_NULL)
17130 return;
17131
a715796b
TG
17132 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17133 D register operands. */
17134 if (neon_shape_class[rs] == SC_DOUBLE)
17135 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17136 _(BAD_FPU));
17137
9db2f6b4
RL
17138 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17139 | N_VFP);
30bdf752
MGD
17140 if (et.type != NT_invtype)
17141 {
17142 /* VFP encodings. */
17143 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17144 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17145 set_it_insn_type (OUTSIDE_IT_INSN);
17146
17147 NEON_ENCODE (FPV8, inst);
9db2f6b4 17148 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17149 do_vfp_sp_monadic ();
17150 else
17151 do_vfp_dp_rd_rm ();
17152
17153 switch (mode)
17154 {
17155 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17156 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17157 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17158 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17159 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17160 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17161 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17162 default: abort ();
17163 }
17164
17165 inst.instruction |= (rs == NS_DD) << 8;
17166 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17167
17168 /* ARMv8.2 fp16 vrint instruction. */
17169 if (rs == NS_HH)
17170 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17171 }
17172 else
17173 {
17174 /* Neon encodings (or something broken...). */
17175 inst.error = NULL;
cc933301 17176 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17177
17178 if (et.type == NT_invtype)
17179 return;
17180
17181 set_it_insn_type (OUTSIDE_IT_INSN);
17182 NEON_ENCODE (FLOAT, inst);
17183
17184 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17185 return;
17186
17187 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17188 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17189 inst.instruction |= LOW4 (inst.operands[1].reg);
17190 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17191 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17192 /* Mask off the original size bits and reencode them. */
17193 inst.instruction = ((inst.instruction & 0xfff3ffff)
17194 | neon_logbits (et.size) << 18);
17195
30bdf752
MGD
17196 switch (mode)
17197 {
17198 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17199 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17200 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17201 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17202 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17203 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17204 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17205 default: abort ();
17206 }
17207
17208 if (thumb_mode)
17209 inst.instruction |= 0xfc000000;
17210 else
17211 inst.instruction |= 0xf0000000;
17212 }
17213}
17214
17215static void
17216do_vrintx (void)
17217{
17218 do_vrint_1 (neon_cvt_mode_x);
17219}
17220
17221static void
17222do_vrintz (void)
17223{
17224 do_vrint_1 (neon_cvt_mode_z);
17225}
17226
17227static void
17228do_vrintr (void)
17229{
17230 do_vrint_1 (neon_cvt_mode_r);
17231}
17232
17233static void
17234do_vrinta (void)
17235{
17236 do_vrint_1 (neon_cvt_mode_a);
17237}
17238
17239static void
17240do_vrintn (void)
17241{
17242 do_vrint_1 (neon_cvt_mode_n);
17243}
17244
17245static void
17246do_vrintp (void)
17247{
17248 do_vrint_1 (neon_cvt_mode_p);
17249}
17250
17251static void
17252do_vrintm (void)
17253{
17254 do_vrint_1 (neon_cvt_mode_m);
17255}
17256
91ff7894
MGD
17257/* Crypto v1 instructions. */
17258static void
17259do_crypto_2op_1 (unsigned elttype, int op)
17260{
17261 set_it_insn_type (OUTSIDE_IT_INSN);
17262
17263 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17264 == NT_invtype)
17265 return;
17266
17267 inst.error = NULL;
17268
17269 NEON_ENCODE (INTEGER, inst);
17270 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17271 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17272 inst.instruction |= LOW4 (inst.operands[1].reg);
17273 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17274 if (op != -1)
17275 inst.instruction |= op << 6;
17276
17277 if (thumb_mode)
17278 inst.instruction |= 0xfc000000;
17279 else
17280 inst.instruction |= 0xf0000000;
17281}
17282
48adcd8e
MGD
17283static void
17284do_crypto_3op_1 (int u, int op)
17285{
17286 set_it_insn_type (OUTSIDE_IT_INSN);
17287
17288 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17289 N_32 | N_UNT | N_KEY).type == NT_invtype)
17290 return;
17291
17292 inst.error = NULL;
17293
17294 NEON_ENCODE (INTEGER, inst);
17295 neon_three_same (1, u, 8 << op);
17296}
17297
91ff7894
MGD
17298static void
17299do_aese (void)
17300{
17301 do_crypto_2op_1 (N_8, 0);
17302}
17303
17304static void
17305do_aesd (void)
17306{
17307 do_crypto_2op_1 (N_8, 1);
17308}
17309
17310static void
17311do_aesmc (void)
17312{
17313 do_crypto_2op_1 (N_8, 2);
17314}
17315
17316static void
17317do_aesimc (void)
17318{
17319 do_crypto_2op_1 (N_8, 3);
17320}
17321
48adcd8e
MGD
17322static void
17323do_sha1c (void)
17324{
17325 do_crypto_3op_1 (0, 0);
17326}
17327
17328static void
17329do_sha1p (void)
17330{
17331 do_crypto_3op_1 (0, 1);
17332}
17333
17334static void
17335do_sha1m (void)
17336{
17337 do_crypto_3op_1 (0, 2);
17338}
17339
17340static void
17341do_sha1su0 (void)
17342{
17343 do_crypto_3op_1 (0, 3);
17344}
91ff7894 17345
48adcd8e
MGD
17346static void
17347do_sha256h (void)
17348{
17349 do_crypto_3op_1 (1, 0);
17350}
17351
17352static void
17353do_sha256h2 (void)
17354{
17355 do_crypto_3op_1 (1, 1);
17356}
17357
17358static void
17359do_sha256su1 (void)
17360{
17361 do_crypto_3op_1 (1, 2);
17362}
3c9017d2
MGD
17363
17364static void
17365do_sha1h (void)
17366{
17367 do_crypto_2op_1 (N_32, -1);
17368}
17369
17370static void
17371do_sha1su1 (void)
17372{
17373 do_crypto_2op_1 (N_32, 0);
17374}
17375
17376static void
17377do_sha256su0 (void)
17378{
17379 do_crypto_2op_1 (N_32, 1);
17380}
dd5181d5
KT
17381
17382static void
17383do_crc32_1 (unsigned int poly, unsigned int sz)
17384{
17385 unsigned int Rd = inst.operands[0].reg;
17386 unsigned int Rn = inst.operands[1].reg;
17387 unsigned int Rm = inst.operands[2].reg;
17388
17389 set_it_insn_type (OUTSIDE_IT_INSN);
17390 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17391 inst.instruction |= LOW4 (Rn) << 16;
17392 inst.instruction |= LOW4 (Rm);
17393 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17394 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17395
17396 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17397 as_warn (UNPRED_REG ("r15"));
17398 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17399 as_warn (UNPRED_REG ("r13"));
17400}
17401
17402static void
17403do_crc32b (void)
17404{
17405 do_crc32_1 (0, 0);
17406}
17407
17408static void
17409do_crc32h (void)
17410{
17411 do_crc32_1 (0, 1);
17412}
17413
17414static void
17415do_crc32w (void)
17416{
17417 do_crc32_1 (0, 2);
17418}
17419
17420static void
17421do_crc32cb (void)
17422{
17423 do_crc32_1 (1, 0);
17424}
17425
17426static void
17427do_crc32ch (void)
17428{
17429 do_crc32_1 (1, 1);
17430}
17431
17432static void
17433do_crc32cw (void)
17434{
17435 do_crc32_1 (1, 2);
17436}
17437
5287ad62
JB
17438\f
17439/* Overall per-instruction processing. */
17440
17441/* We need to be able to fix up arbitrary expressions in some statements.
17442 This is so that we can handle symbols that are an arbitrary distance from
17443 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17444 which returns part of an address in a form which will be valid for
17445 a data instruction. We do this by pushing the expression into a symbol
17446 in the expr_section, and creating a fix for that. */
17447
17448static void
17449fix_new_arm (fragS * frag,
17450 int where,
17451 short int size,
17452 expressionS * exp,
17453 int pc_rel,
17454 int reloc)
17455{
17456 fixS * new_fix;
17457
17458 switch (exp->X_op)
17459 {
17460 case O_constant:
6e7ce2cd
PB
17461 if (pc_rel)
17462 {
17463 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17464 refer to in the object file. Unfortunately for us, gas's
17465 generic expression parsing will already have folded out
17466 any use of .set foo/.type foo %function that may have
17467 been used to set type information of the target location,
17468 that's being specified symbolically. We have to presume
17469 the user knows what they are doing. */
6e7ce2cd
PB
17470 char name[16 + 8];
17471 symbolS *symbol;
17472
17473 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17474
17475 symbol = symbol_find_or_make (name);
17476 S_SET_SEGMENT (symbol, absolute_section);
17477 symbol_set_frag (symbol, &zero_address_frag);
17478 S_SET_VALUE (symbol, exp->X_add_number);
17479 exp->X_op = O_symbol;
17480 exp->X_add_symbol = symbol;
17481 exp->X_add_number = 0;
17482 }
17483 /* FALLTHROUGH */
5287ad62
JB
17484 case O_symbol:
17485 case O_add:
17486 case O_subtract:
21d799b5 17487 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17488 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17489 break;
17490
17491 default:
21d799b5 17492 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17493 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17494 break;
17495 }
17496
17497 /* Mark whether the fix is to a THUMB instruction, or an ARM
17498 instruction. */
17499 new_fix->tc_fix_data = thumb_mode;
17500}
17501
17502/* Create a frg for an instruction requiring relaxation. */
17503static void
17504output_relax_insn (void)
17505{
17506 char * to;
17507 symbolS *sym;
0110f2b8
PB
17508 int offset;
17509
6e1cb1a6
PB
17510 /* The size of the instruction is unknown, so tie the debug info to the
17511 start of the instruction. */
17512 dwarf2_emit_insn (0);
6e1cb1a6 17513
0110f2b8
PB
17514 switch (inst.reloc.exp.X_op)
17515 {
17516 case O_symbol:
17517 sym = inst.reloc.exp.X_add_symbol;
17518 offset = inst.reloc.exp.X_add_number;
17519 break;
17520 case O_constant:
17521 sym = NULL;
17522 offset = inst.reloc.exp.X_add_number;
17523 break;
17524 default:
17525 sym = make_expr_symbol (&inst.reloc.exp);
17526 offset = 0;
17527 break;
17528 }
17529 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17530 inst.relax, sym, offset, NULL/*offset, opcode*/);
17531 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17532}
17533
17534/* Write a 32-bit thumb instruction to buf. */
17535static void
17536put_thumb32_insn (char * buf, unsigned long insn)
17537{
17538 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17539 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17540}
17541
b99bd4ef 17542static void
c19d1205 17543output_inst (const char * str)
b99bd4ef 17544{
c19d1205 17545 char * to = NULL;
b99bd4ef 17546
c19d1205 17547 if (inst.error)
b99bd4ef 17548 {
c19d1205 17549 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17550 return;
17551 }
5f4273c7
NC
17552 if (inst.relax)
17553 {
17554 output_relax_insn ();
0110f2b8 17555 return;
5f4273c7 17556 }
c19d1205
ZW
17557 if (inst.size == 0)
17558 return;
b99bd4ef 17559
c19d1205 17560 to = frag_more (inst.size);
8dc2430f
NC
17561 /* PR 9814: Record the thumb mode into the current frag so that we know
17562 what type of NOP padding to use, if necessary. We override any previous
17563 setting so that if the mode has changed then the NOPS that we use will
17564 match the encoding of the last instruction in the frag. */
cd000bff 17565 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17566
17567 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17568 {
9c2799c2 17569 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17570 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17571 }
c19d1205 17572 else if (inst.size > INSN_SIZE)
b99bd4ef 17573 {
9c2799c2 17574 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17575 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17576 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17577 }
c19d1205
ZW
17578 else
17579 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17580
c19d1205
ZW
17581 if (inst.reloc.type != BFD_RELOC_UNUSED)
17582 fix_new_arm (frag_now, to - frag_now->fr_literal,
17583 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17584 inst.reloc.type);
b99bd4ef 17585
c19d1205 17586 dwarf2_emit_insn (inst.size);
c19d1205 17587}
b99bd4ef 17588
e07e6e58
NC
17589static char *
17590output_it_inst (int cond, int mask, char * to)
17591{
17592 unsigned long instruction = 0xbf00;
17593
17594 mask &= 0xf;
17595 instruction |= mask;
17596 instruction |= cond << 4;
17597
17598 if (to == NULL)
17599 {
17600 to = frag_more (2);
17601#ifdef OBJ_ELF
17602 dwarf2_emit_insn (2);
17603#endif
17604 }
17605
17606 md_number_to_chars (to, instruction, 2);
17607
17608 return to;
17609}
17610
c19d1205
ZW
17611/* Tag values used in struct asm_opcode's tag field. */
17612enum opcode_tag
17613{
17614 OT_unconditional, /* Instruction cannot be conditionalized.
17615 The ARM condition field is still 0xE. */
17616 OT_unconditionalF, /* Instruction cannot be conditionalized
17617 and carries 0xF in its ARM condition field. */
17618 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17619 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17620 suffix, others place 0xF where the condition field
17621 would be. */
c19d1205
ZW
17622 OT_cinfix3, /* Instruction takes a conditional infix,
17623 beginning at character index 3. (In
17624 unified mode, it becomes a suffix.) */
088fa78e
KH
17625 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17626 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17627 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17628 character index 3, even in unified mode. Used for
17629 legacy instructions where suffix and infix forms
17630 may be ambiguous. */
c19d1205 17631 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17632 suffix or an infix at character index 3. */
c19d1205
ZW
17633 OT_odd_infix_unc, /* This is the unconditional variant of an
17634 instruction that takes a conditional infix
17635 at an unusual position. In unified mode,
17636 this variant will accept a suffix. */
17637 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17638 are the conditional variants of instructions that
17639 take conditional infixes in unusual positions.
17640 The infix appears at character index
17641 (tag - OT_odd_infix_0). These are not accepted
17642 in unified mode. */
17643};
b99bd4ef 17644
c19d1205
ZW
17645/* Subroutine of md_assemble, responsible for looking up the primary
17646 opcode from the mnemonic the user wrote. STR points to the
17647 beginning of the mnemonic.
17648
17649 This is not simply a hash table lookup, because of conditional
17650 variants. Most instructions have conditional variants, which are
17651 expressed with a _conditional affix_ to the mnemonic. If we were
17652 to encode each conditional variant as a literal string in the opcode
17653 table, it would have approximately 20,000 entries.
17654
17655 Most mnemonics take this affix as a suffix, and in unified syntax,
17656 'most' is upgraded to 'all'. However, in the divided syntax, some
17657 instructions take the affix as an infix, notably the s-variants of
17658 the arithmetic instructions. Of those instructions, all but six
17659 have the infix appear after the third character of the mnemonic.
17660
17661 Accordingly, the algorithm for looking up primary opcodes given
17662 an identifier is:
17663
17664 1. Look up the identifier in the opcode table.
17665 If we find a match, go to step U.
17666
17667 2. Look up the last two characters of the identifier in the
17668 conditions table. If we find a match, look up the first N-2
17669 characters of the identifier in the opcode table. If we
17670 find a match, go to step CE.
17671
17672 3. Look up the fourth and fifth characters of the identifier in
17673 the conditions table. If we find a match, extract those
17674 characters from the identifier, and look up the remaining
17675 characters in the opcode table. If we find a match, go
17676 to step CM.
17677
17678 4. Fail.
17679
17680 U. Examine the tag field of the opcode structure, in case this is
17681 one of the six instructions with its conditional infix in an
17682 unusual place. If it is, the tag tells us where to find the
17683 infix; look it up in the conditions table and set inst.cond
17684 accordingly. Otherwise, this is an unconditional instruction.
17685 Again set inst.cond accordingly. Return the opcode structure.
17686
17687 CE. Examine the tag field to make sure this is an instruction that
17688 should receive a conditional suffix. If it is not, fail.
17689 Otherwise, set inst.cond from the suffix we already looked up,
17690 and return the opcode structure.
17691
17692 CM. Examine the tag field to make sure this is an instruction that
17693 should receive a conditional infix after the third character.
17694 If it is not, fail. Otherwise, undo the edits to the current
17695 line of input and proceed as for case CE. */
17696
17697static const struct asm_opcode *
17698opcode_lookup (char **str)
17699{
17700 char *end, *base;
17701 char *affix;
17702 const struct asm_opcode *opcode;
17703 const struct asm_cond *cond;
e3cb604e 17704 char save[2];
c19d1205
ZW
17705
17706 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17707 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17708 for (base = end = *str; *end != '\0'; end++)
721a8186 17709 if (*end == ' ' || *end == '.')
c19d1205 17710 break;
b99bd4ef 17711
c19d1205 17712 if (end == base)
c921be7d 17713 return NULL;
b99bd4ef 17714
5287ad62 17715 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17716 if (end[0] == '.')
b99bd4ef 17717 {
5287ad62 17718 int offset = 2;
5f4273c7 17719
267d2029 17720 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17721 use. */
267d2029 17722 if (unified_syntax && end[1] == 'w')
c19d1205 17723 inst.size_req = 4;
267d2029 17724 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17725 inst.size_req = 2;
17726 else
477330fc 17727 offset = 0;
5287ad62
JB
17728
17729 inst.vectype.elems = 0;
17730
17731 *str = end + offset;
b99bd4ef 17732
5f4273c7 17733 if (end[offset] == '.')
5287ad62 17734 {
267d2029 17735 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17736 non-unified ARM syntax mode). */
17737 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17738 return NULL;
477330fc 17739 }
5287ad62 17740 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17741 return NULL;
b99bd4ef 17742 }
c19d1205
ZW
17743 else
17744 *str = end;
b99bd4ef 17745
c19d1205 17746 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17747 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17748 end - base);
c19d1205 17749 if (opcode)
b99bd4ef 17750 {
c19d1205
ZW
17751 /* step U */
17752 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17753 {
c19d1205
ZW
17754 inst.cond = COND_ALWAYS;
17755 return opcode;
b99bd4ef 17756 }
b99bd4ef 17757
278df34e 17758 if (warn_on_deprecated && unified_syntax)
5c3696f8 17759 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17760 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17761 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17762 gas_assert (cond);
b99bd4ef 17763
c19d1205
ZW
17764 inst.cond = cond->value;
17765 return opcode;
17766 }
b99bd4ef 17767
c19d1205
ZW
17768 /* Cannot have a conditional suffix on a mnemonic of less than two
17769 characters. */
17770 if (end - base < 3)
c921be7d 17771 return NULL;
b99bd4ef 17772
c19d1205
ZW
17773 /* Look for suffixed mnemonic. */
17774 affix = end - 2;
21d799b5
NC
17775 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17776 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17777 affix - base);
c19d1205
ZW
17778 if (opcode && cond)
17779 {
17780 /* step CE */
17781 switch (opcode->tag)
17782 {
e3cb604e
PB
17783 case OT_cinfix3_legacy:
17784 /* Ignore conditional suffixes matched on infix only mnemonics. */
17785 break;
17786
c19d1205 17787 case OT_cinfix3:
088fa78e 17788 case OT_cinfix3_deprecated:
c19d1205
ZW
17789 case OT_odd_infix_unc:
17790 if (!unified_syntax)
e3cb604e 17791 return 0;
1a0670f3 17792 /* Fall through. */
c19d1205
ZW
17793
17794 case OT_csuffix:
477330fc 17795 case OT_csuffixF:
c19d1205
ZW
17796 case OT_csuf_or_in3:
17797 inst.cond = cond->value;
17798 return opcode;
17799
17800 case OT_unconditional:
17801 case OT_unconditionalF:
dfa9f0d5 17802 if (thumb_mode)
c921be7d 17803 inst.cond = cond->value;
dfa9f0d5
PB
17804 else
17805 {
c921be7d 17806 /* Delayed diagnostic. */
dfa9f0d5
PB
17807 inst.error = BAD_COND;
17808 inst.cond = COND_ALWAYS;
17809 }
c19d1205 17810 return opcode;
b99bd4ef 17811
c19d1205 17812 default:
c921be7d 17813 return NULL;
c19d1205
ZW
17814 }
17815 }
b99bd4ef 17816
c19d1205
ZW
17817 /* Cannot have a usual-position infix on a mnemonic of less than
17818 six characters (five would be a suffix). */
17819 if (end - base < 6)
c921be7d 17820 return NULL;
b99bd4ef 17821
c19d1205
ZW
17822 /* Look for infixed mnemonic in the usual position. */
17823 affix = base + 3;
21d799b5 17824 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17825 if (!cond)
c921be7d 17826 return NULL;
e3cb604e
PB
17827
17828 memcpy (save, affix, 2);
17829 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17830 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17831 (end - base) - 2);
e3cb604e
PB
17832 memmove (affix + 2, affix, (end - affix) - 2);
17833 memcpy (affix, save, 2);
17834
088fa78e
KH
17835 if (opcode
17836 && (opcode->tag == OT_cinfix3
17837 || opcode->tag == OT_cinfix3_deprecated
17838 || opcode->tag == OT_csuf_or_in3
17839 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17840 {
c921be7d 17841 /* Step CM. */
278df34e 17842 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17843 && (opcode->tag == OT_cinfix3
17844 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17845 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17846
17847 inst.cond = cond->value;
17848 return opcode;
b99bd4ef
NC
17849 }
17850
c921be7d 17851 return NULL;
b99bd4ef
NC
17852}
17853
e07e6e58
NC
17854/* This function generates an initial IT instruction, leaving its block
17855 virtually open for the new instructions. Eventually,
17856 the mask will be updated by now_it_add_mask () each time
17857 a new instruction needs to be included in the IT block.
17858 Finally, the block is closed with close_automatic_it_block ().
17859 The block closure can be requested either from md_assemble (),
17860 a tencode (), or due to a label hook. */
17861
17862static void
17863new_automatic_it_block (int cond)
17864{
17865 now_it.state = AUTOMATIC_IT_BLOCK;
17866 now_it.mask = 0x18;
17867 now_it.cc = cond;
17868 now_it.block_length = 1;
cd000bff 17869 mapping_state (MAP_THUMB);
e07e6e58 17870 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17871 now_it.warn_deprecated = FALSE;
17872 now_it.insn_cond = TRUE;
e07e6e58
NC
17873}
17874
17875/* Close an automatic IT block.
17876 See comments in new_automatic_it_block (). */
17877
17878static void
17879close_automatic_it_block (void)
17880{
17881 now_it.mask = 0x10;
17882 now_it.block_length = 0;
17883}
17884
17885/* Update the mask of the current automatically-generated IT
17886 instruction. See comments in new_automatic_it_block (). */
17887
17888static void
17889now_it_add_mask (int cond)
17890{
17891#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17892#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17893 | ((bitvalue) << (nbit)))
e07e6e58 17894 const int resulting_bit = (cond & 1);
c921be7d 17895
e07e6e58
NC
17896 now_it.mask &= 0xf;
17897 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17898 resulting_bit,
17899 (5 - now_it.block_length));
e07e6e58 17900 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17901 1,
17902 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17903 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17904
17905#undef CLEAR_BIT
17906#undef SET_BIT_VALUE
e07e6e58
NC
17907}
17908
17909/* The IT blocks handling machinery is accessed through the these functions:
17910 it_fsm_pre_encode () from md_assemble ()
17911 set_it_insn_type () optional, from the tencode functions
17912 set_it_insn_type_last () ditto
17913 in_it_block () ditto
17914 it_fsm_post_encode () from md_assemble ()
17915 force_automatic_it_block_close () from label habdling functions
17916
17917 Rationale:
17918 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17919 initializing the IT insn type with a generic initial value depending
17920 on the inst.condition.
e07e6e58 17921 2) During the tencode function, two things may happen:
477330fc
RM
17922 a) The tencode function overrides the IT insn type by
17923 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17924 b) The tencode function queries the IT block state by
17925 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17926
17927 Both set_it_insn_type and in_it_block run the internal FSM state
17928 handling function (handle_it_state), because: a) setting the IT insn
17929 type may incur in an invalid state (exiting the function),
17930 and b) querying the state requires the FSM to be updated.
17931 Specifically we want to avoid creating an IT block for conditional
17932 branches, so it_fsm_pre_encode is actually a guess and we can't
17933 determine whether an IT block is required until the tencode () routine
17934 has decided what type of instruction this actually it.
17935 Because of this, if set_it_insn_type and in_it_block have to be used,
17936 set_it_insn_type has to be called first.
17937
17938 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17939 determines the insn IT type depending on the inst.cond code.
17940 When a tencode () routine encodes an instruction that can be
17941 either outside an IT block, or, in the case of being inside, has to be
17942 the last one, set_it_insn_type_last () will determine the proper
17943 IT instruction type based on the inst.cond code. Otherwise,
17944 set_it_insn_type can be called for overriding that logic or
17945 for covering other cases.
17946
17947 Calling handle_it_state () may not transition the IT block state to
17948 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17949 still queried. Instead, if the FSM determines that the state should
17950 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17951 after the tencode () function: that's what it_fsm_post_encode () does.
17952
17953 Since in_it_block () calls the state handling function to get an
17954 updated state, an error may occur (due to invalid insns combination).
17955 In that case, inst.error is set.
17956 Therefore, inst.error has to be checked after the execution of
17957 the tencode () routine.
e07e6e58
NC
17958
17959 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17960 any pending state change (if any) that didn't take place in
17961 handle_it_state () as explained above. */
e07e6e58
NC
17962
17963static void
17964it_fsm_pre_encode (void)
17965{
17966 if (inst.cond != COND_ALWAYS)
17967 inst.it_insn_type = INSIDE_IT_INSN;
17968 else
17969 inst.it_insn_type = OUTSIDE_IT_INSN;
17970
17971 now_it.state_handled = 0;
17972}
17973
17974/* IT state FSM handling function. */
17975
17976static int
17977handle_it_state (void)
17978{
17979 now_it.state_handled = 1;
5a01bb1d 17980 now_it.insn_cond = FALSE;
e07e6e58
NC
17981
17982 switch (now_it.state)
17983 {
17984 case OUTSIDE_IT_BLOCK:
17985 switch (inst.it_insn_type)
17986 {
17987 case OUTSIDE_IT_INSN:
17988 break;
17989
17990 case INSIDE_IT_INSN:
17991 case INSIDE_IT_LAST_INSN:
17992 if (thumb_mode == 0)
17993 {
c921be7d 17994 if (unified_syntax
e07e6e58
NC
17995 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17996 as_tsktsk (_("Warning: conditional outside an IT block"\
17997 " for Thumb."));
17998 }
17999 else
18000 {
18001 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18002 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18003 {
18004 /* Automatically generate the IT instruction. */
18005 new_automatic_it_block (inst.cond);
18006 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18007 close_automatic_it_block ();
18008 }
18009 else
18010 {
18011 inst.error = BAD_OUT_IT;
18012 return FAIL;
18013 }
18014 }
18015 break;
18016
18017 case IF_INSIDE_IT_LAST_INSN:
18018 case NEUTRAL_IT_INSN:
18019 break;
18020
18021 case IT_INSN:
18022 now_it.state = MANUAL_IT_BLOCK;
18023 now_it.block_length = 0;
18024 break;
18025 }
18026 break;
18027
18028 case AUTOMATIC_IT_BLOCK:
18029 /* Three things may happen now:
18030 a) We should increment current it block size;
18031 b) We should close current it block (closing insn or 4 insns);
18032 c) We should close current it block and start a new one (due
18033 to incompatible conditions or
18034 4 insns-length block reached). */
18035
18036 switch (inst.it_insn_type)
18037 {
18038 case OUTSIDE_IT_INSN:
18039 /* The closure of the block shall happen immediatelly,
18040 so any in_it_block () call reports the block as closed. */
18041 force_automatic_it_block_close ();
18042 break;
18043
18044 case INSIDE_IT_INSN:
18045 case INSIDE_IT_LAST_INSN:
18046 case IF_INSIDE_IT_LAST_INSN:
18047 now_it.block_length++;
18048
18049 if (now_it.block_length > 4
18050 || !now_it_compatible (inst.cond))
18051 {
18052 force_automatic_it_block_close ();
18053 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18054 new_automatic_it_block (inst.cond);
18055 }
18056 else
18057 {
5a01bb1d 18058 now_it.insn_cond = TRUE;
e07e6e58
NC
18059 now_it_add_mask (inst.cond);
18060 }
18061
18062 if (now_it.state == AUTOMATIC_IT_BLOCK
18063 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18064 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18065 close_automatic_it_block ();
18066 break;
18067
18068 case NEUTRAL_IT_INSN:
18069 now_it.block_length++;
5a01bb1d 18070 now_it.insn_cond = TRUE;
e07e6e58
NC
18071
18072 if (now_it.block_length > 4)
18073 force_automatic_it_block_close ();
18074 else
18075 now_it_add_mask (now_it.cc & 1);
18076 break;
18077
18078 case IT_INSN:
18079 close_automatic_it_block ();
18080 now_it.state = MANUAL_IT_BLOCK;
18081 break;
18082 }
18083 break;
18084
18085 case MANUAL_IT_BLOCK:
18086 {
18087 /* Check conditional suffixes. */
18088 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18089 int is_last;
18090 now_it.mask <<= 1;
18091 now_it.mask &= 0x1f;
18092 is_last = (now_it.mask == 0x10);
5a01bb1d 18093 now_it.insn_cond = TRUE;
e07e6e58
NC
18094
18095 switch (inst.it_insn_type)
18096 {
18097 case OUTSIDE_IT_INSN:
18098 inst.error = BAD_NOT_IT;
18099 return FAIL;
18100
18101 case INSIDE_IT_INSN:
18102 if (cond != inst.cond)
18103 {
18104 inst.error = BAD_IT_COND;
18105 return FAIL;
18106 }
18107 break;
18108
18109 case INSIDE_IT_LAST_INSN:
18110 case IF_INSIDE_IT_LAST_INSN:
18111 if (cond != inst.cond)
18112 {
18113 inst.error = BAD_IT_COND;
18114 return FAIL;
18115 }
18116 if (!is_last)
18117 {
18118 inst.error = BAD_BRANCH;
18119 return FAIL;
18120 }
18121 break;
18122
18123 case NEUTRAL_IT_INSN:
18124 /* The BKPT instruction is unconditional even in an IT block. */
18125 break;
18126
18127 case IT_INSN:
18128 inst.error = BAD_IT_IT;
18129 return FAIL;
18130 }
18131 }
18132 break;
18133 }
18134
18135 return SUCCESS;
18136}
18137
5a01bb1d
MGD
18138struct depr_insn_mask
18139{
18140 unsigned long pattern;
18141 unsigned long mask;
18142 const char* description;
18143};
18144
18145/* List of 16-bit instruction patterns deprecated in an IT block in
18146 ARMv8. */
18147static const struct depr_insn_mask depr_it_insns[] = {
18148 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18149 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18150 { 0xa000, 0xb800, N_("ADR") },
18151 { 0x4800, 0xf800, N_("Literal loads") },
18152 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18153 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18154 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18155 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18156 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18157 { 0, 0, NULL }
18158};
18159
e07e6e58
NC
18160static void
18161it_fsm_post_encode (void)
18162{
18163 int is_last;
18164
18165 if (!now_it.state_handled)
18166 handle_it_state ();
18167
5a01bb1d
MGD
18168 if (now_it.insn_cond
18169 && !now_it.warn_deprecated
18170 && warn_on_deprecated
18171 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18172 {
18173 if (inst.instruction >= 0x10000)
18174 {
5c3696f8 18175 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18176 "deprecated in ARMv8"));
18177 now_it.warn_deprecated = TRUE;
18178 }
18179 else
18180 {
18181 const struct depr_insn_mask *p = depr_it_insns;
18182
18183 while (p->mask != 0)
18184 {
18185 if ((inst.instruction & p->mask) == p->pattern)
18186 {
5c3696f8 18187 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18188 "of the following class are deprecated in ARMv8: "
18189 "%s"), p->description);
18190 now_it.warn_deprecated = TRUE;
18191 break;
18192 }
18193
18194 ++p;
18195 }
18196 }
18197
18198 if (now_it.block_length > 1)
18199 {
5c3696f8 18200 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18201 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18202 now_it.warn_deprecated = TRUE;
18203 }
18204 }
18205
e07e6e58
NC
18206 is_last = (now_it.mask == 0x10);
18207 if (is_last)
18208 {
18209 now_it.state = OUTSIDE_IT_BLOCK;
18210 now_it.mask = 0;
18211 }
18212}
18213
18214static void
18215force_automatic_it_block_close (void)
18216{
18217 if (now_it.state == AUTOMATIC_IT_BLOCK)
18218 {
18219 close_automatic_it_block ();
18220 now_it.state = OUTSIDE_IT_BLOCK;
18221 now_it.mask = 0;
18222 }
18223}
18224
18225static int
18226in_it_block (void)
18227{
18228 if (!now_it.state_handled)
18229 handle_it_state ();
18230
18231 return now_it.state != OUTSIDE_IT_BLOCK;
18232}
18233
ff8646ee
TP
18234/* Whether OPCODE only has T32 encoding. Since this function is only used by
18235 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18236 here, hence the "known" in the function name. */
fc289b0a
TP
18237
18238static bfd_boolean
ff8646ee 18239known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18240{
18241 /* Original Thumb-1 wide instruction. */
18242 if (opcode->tencode == do_t_blx
18243 || opcode->tencode == do_t_branch23
18244 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18245 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18246 return TRUE;
18247
16a1fa25
TP
18248 /* Wide-only instruction added to ARMv8-M Baseline. */
18249 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18250 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18251 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18252 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18253 return TRUE;
18254
18255 return FALSE;
18256}
18257
18258/* Whether wide instruction variant can be used if available for a valid OPCODE
18259 in ARCH. */
18260
18261static bfd_boolean
18262t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18263{
18264 if (known_t32_only_insn (opcode))
18265 return TRUE;
18266
18267 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18268 of variant T3 of B.W is checked in do_t_branch. */
18269 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18270 && opcode->tencode == do_t_branch)
18271 return TRUE;
18272
18273 /* Wide instruction variants of all instructions with narrow *and* wide
18274 variants become available with ARMv6t2. Other opcodes are either
18275 narrow-only or wide-only and are thus available if OPCODE is valid. */
18276 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18277 return TRUE;
18278
18279 /* OPCODE with narrow only instruction variant or wide variant not
18280 available. */
fc289b0a
TP
18281 return FALSE;
18282}
18283
c19d1205
ZW
18284void
18285md_assemble (char *str)
b99bd4ef 18286{
c19d1205
ZW
18287 char *p = str;
18288 const struct asm_opcode * opcode;
b99bd4ef 18289
c19d1205
ZW
18290 /* Align the previous label if needed. */
18291 if (last_label_seen != NULL)
b99bd4ef 18292 {
c19d1205
ZW
18293 symbol_set_frag (last_label_seen, frag_now);
18294 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18295 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18296 }
18297
c19d1205
ZW
18298 memset (&inst, '\0', sizeof (inst));
18299 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18300
c19d1205
ZW
18301 opcode = opcode_lookup (&p);
18302 if (!opcode)
b99bd4ef 18303 {
c19d1205 18304 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18305 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18306 if (! create_register_alias (str, p)
477330fc 18307 && ! create_neon_reg_alias (str, p))
c19d1205 18308 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18309
b99bd4ef
NC
18310 return;
18311 }
18312
278df34e 18313 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18314 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18315
037e8744
JB
18316 /* The value which unconditional instructions should have in place of the
18317 condition field. */
18318 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18319
c19d1205 18320 if (thumb_mode)
b99bd4ef 18321 {
e74cfd16 18322 arm_feature_set variant;
8f06b2d8
PB
18323
18324 variant = cpu_variant;
18325 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18326 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18327 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18328 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18329 if (!opcode->tvariant
18330 || (thumb_mode == 1
18331 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18332 {
84b52b66 18333 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18334 return;
18335 }
c19d1205
ZW
18336 if (inst.cond != COND_ALWAYS && !unified_syntax
18337 && opcode->tencode != do_t_branch)
b99bd4ef 18338 {
c19d1205 18339 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18340 return;
18341 }
18342
fc289b0a
TP
18343 /* Two things are addressed here:
18344 1) Implicit require narrow instructions on Thumb-1.
18345 This avoids relaxation accidentally introducing Thumb-2
18346 instructions.
18347 2) Reject wide instructions in non Thumb-2 cores.
18348
18349 Only instructions with narrow and wide variants need to be handled
18350 but selecting all non wide-only instructions is easier. */
18351 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18352 && !t32_insn_ok (variant, opcode))
076d447c 18353 {
fc289b0a
TP
18354 if (inst.size_req == 0)
18355 inst.size_req = 2;
18356 else if (inst.size_req == 4)
752d5da4 18357 {
ff8646ee
TP
18358 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18359 as_bad (_("selected processor does not support 32bit wide "
18360 "variant of instruction `%s'"), str);
18361 else
18362 as_bad (_("selected processor does not support `%s' in "
18363 "Thumb-2 mode"), str);
fc289b0a 18364 return;
752d5da4 18365 }
076d447c
PB
18366 }
18367
c19d1205
ZW
18368 inst.instruction = opcode->tvalue;
18369
5be8be5d 18370 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18371 {
18372 /* Prepare the it_insn_type for those encodings that don't set
18373 it. */
18374 it_fsm_pre_encode ();
c19d1205 18375
477330fc 18376 opcode->tencode ();
e07e6e58 18377
477330fc
RM
18378 it_fsm_post_encode ();
18379 }
e27ec89e 18380
0110f2b8 18381 if (!(inst.error || inst.relax))
b99bd4ef 18382 {
9c2799c2 18383 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18384 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18385 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18386 {
c19d1205 18387 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18388 return;
18389 }
18390 }
076d447c
PB
18391
18392 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18393 instruction. */
9c2799c2 18394 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18395
e74cfd16
PB
18396 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18397 *opcode->tvariant);
ee065d83 18398 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18399 set those bits when Thumb-2 32-bit instructions are seen. The impact
18400 of relaxable instructions will be considered later after we finish all
18401 relaxation. */
ff8646ee
TP
18402 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18403 variant = arm_arch_none;
18404 else
18405 variant = cpu_variant;
18406 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18407 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18408 arm_ext_v6t2);
cd000bff 18409
88714cb8
DG
18410 check_neon_suffixes;
18411
cd000bff 18412 if (!inst.error)
c877a2f2
NC
18413 {
18414 mapping_state (MAP_THUMB);
18415 }
c19d1205 18416 }
3e9e4fcf 18417 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18418 {
845b51d6
PB
18419 bfd_boolean is_bx;
18420
18421 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18422 is_bx = (opcode->aencode == do_bx);
18423
c19d1205 18424 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18425 if (!(is_bx && fix_v4bx)
18426 && !(opcode->avariant &&
18427 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18428 {
84b52b66 18429 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18430 return;
b99bd4ef 18431 }
c19d1205 18432 if (inst.size_req)
b99bd4ef 18433 {
c19d1205
ZW
18434 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18435 return;
b99bd4ef
NC
18436 }
18437
c19d1205
ZW
18438 inst.instruction = opcode->avalue;
18439 if (opcode->tag == OT_unconditionalF)
eff0bc54 18440 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18441 else
18442 inst.instruction |= inst.cond << 28;
18443 inst.size = INSN_SIZE;
5be8be5d 18444 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18445 {
18446 it_fsm_pre_encode ();
18447 opcode->aencode ();
18448 it_fsm_post_encode ();
18449 }
ee065d83 18450 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18451 on a hypothetical non-thumb v5 core. */
845b51d6 18452 if (is_bx)
e74cfd16 18453 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18454 else
e74cfd16
PB
18455 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18456 *opcode->avariant);
88714cb8
DG
18457
18458 check_neon_suffixes;
18459
cd000bff 18460 if (!inst.error)
c877a2f2
NC
18461 {
18462 mapping_state (MAP_ARM);
18463 }
b99bd4ef 18464 }
3e9e4fcf
JB
18465 else
18466 {
18467 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18468 "-- `%s'"), str);
18469 return;
18470 }
c19d1205
ZW
18471 output_inst (str);
18472}
b99bd4ef 18473
e07e6e58
NC
18474static void
18475check_it_blocks_finished (void)
18476{
18477#ifdef OBJ_ELF
18478 asection *sect;
18479
18480 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18481 if (seg_info (sect)->tc_segment_info_data.current_it.state
18482 == MANUAL_IT_BLOCK)
18483 {
18484 as_warn (_("section '%s' finished with an open IT block."),
18485 sect->name);
18486 }
18487#else
18488 if (now_it.state == MANUAL_IT_BLOCK)
18489 as_warn (_("file finished with an open IT block."));
18490#endif
18491}
18492
c19d1205
ZW
18493/* Various frobbings of labels and their addresses. */
18494
18495void
18496arm_start_line_hook (void)
18497{
18498 last_label_seen = NULL;
b99bd4ef
NC
18499}
18500
c19d1205
ZW
18501void
18502arm_frob_label (symbolS * sym)
b99bd4ef 18503{
c19d1205 18504 last_label_seen = sym;
b99bd4ef 18505
c19d1205 18506 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18507
c19d1205
ZW
18508#if defined OBJ_COFF || defined OBJ_ELF
18509 ARM_SET_INTERWORK (sym, support_interwork);
18510#endif
b99bd4ef 18511
e07e6e58
NC
18512 force_automatic_it_block_close ();
18513
5f4273c7 18514 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18515 as Thumb functions. This is because these labels, whilst
18516 they exist inside Thumb code, are not the entry points for
18517 possible ARM->Thumb calls. Also, these labels can be used
18518 as part of a computed goto or switch statement. eg gcc
18519 can generate code that looks like this:
b99bd4ef 18520
c19d1205
ZW
18521 ldr r2, [pc, .Laaa]
18522 lsl r3, r3, #2
18523 ldr r2, [r3, r2]
18524 mov pc, r2
b99bd4ef 18525
c19d1205
ZW
18526 .Lbbb: .word .Lxxx
18527 .Lccc: .word .Lyyy
18528 ..etc...
18529 .Laaa: .word Lbbb
b99bd4ef 18530
c19d1205
ZW
18531 The first instruction loads the address of the jump table.
18532 The second instruction converts a table index into a byte offset.
18533 The third instruction gets the jump address out of the table.
18534 The fourth instruction performs the jump.
b99bd4ef 18535
c19d1205
ZW
18536 If the address stored at .Laaa is that of a symbol which has the
18537 Thumb_Func bit set, then the linker will arrange for this address
18538 to have the bottom bit set, which in turn would mean that the
18539 address computation performed by the third instruction would end
18540 up with the bottom bit set. Since the ARM is capable of unaligned
18541 word loads, the instruction would then load the incorrect address
18542 out of the jump table, and chaos would ensue. */
18543 if (label_is_thumb_function_name
18544 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18545 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18546 {
c19d1205
ZW
18547 /* When the address of a Thumb function is taken the bottom
18548 bit of that address should be set. This will allow
18549 interworking between Arm and Thumb functions to work
18550 correctly. */
b99bd4ef 18551
c19d1205 18552 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18553
c19d1205 18554 label_is_thumb_function_name = FALSE;
b99bd4ef 18555 }
07a53e5c 18556
07a53e5c 18557 dwarf2_emit_label (sym);
b99bd4ef
NC
18558}
18559
c921be7d 18560bfd_boolean
c19d1205 18561arm_data_in_code (void)
b99bd4ef 18562{
c19d1205 18563 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18564 {
c19d1205
ZW
18565 *input_line_pointer = '/';
18566 input_line_pointer += 5;
18567 *input_line_pointer = 0;
c921be7d 18568 return TRUE;
b99bd4ef
NC
18569 }
18570
c921be7d 18571 return FALSE;
b99bd4ef
NC
18572}
18573
c19d1205
ZW
18574char *
18575arm_canonicalize_symbol_name (char * name)
b99bd4ef 18576{
c19d1205 18577 int len;
b99bd4ef 18578
c19d1205
ZW
18579 if (thumb_mode && (len = strlen (name)) > 5
18580 && streq (name + len - 5, "/data"))
18581 *(name + len - 5) = 0;
b99bd4ef 18582
c19d1205 18583 return name;
b99bd4ef 18584}
c19d1205
ZW
18585\f
18586/* Table of all register names defined by default. The user can
18587 define additional names with .req. Note that all register names
18588 should appear in both upper and lowercase variants. Some registers
18589 also have mixed-case names. */
b99bd4ef 18590
dcbf9037 18591#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18592#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18593#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18594#define REGSET(p,t) \
18595 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18596 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18597 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18598 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18599#define REGSETH(p,t) \
18600 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18601 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18602 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18603 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18604#define REGSET2(p,t) \
18605 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18606 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18607 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18608 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18609#define SPLRBANK(base,bank,t) \
18610 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18611 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18612 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18613 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18614 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18615 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18616
c19d1205 18617static const struct reg_entry reg_names[] =
7ed4c4c5 18618{
c19d1205
ZW
18619 /* ARM integer registers. */
18620 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18621
c19d1205
ZW
18622 /* ATPCS synonyms. */
18623 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18624 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18625 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18626
c19d1205
ZW
18627 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18628 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18629 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18630
c19d1205
ZW
18631 /* Well-known aliases. */
18632 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18633 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18634
18635 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18636 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18637
18638 /* Coprocessor numbers. */
18639 REGSET(p, CP), REGSET(P, CP),
18640
18641 /* Coprocessor register numbers. The "cr" variants are for backward
18642 compatibility. */
18643 REGSET(c, CN), REGSET(C, CN),
18644 REGSET(cr, CN), REGSET(CR, CN),
18645
90ec0d68
MGD
18646 /* ARM banked registers. */
18647 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18648 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18649 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18650 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18651 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18652 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18653 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18654
18655 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18656 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18657 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18658 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18659 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18660 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18661 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18662 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18663
18664 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18665 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18666 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18667 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18668 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18669 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18670 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18671 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18672 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18673
c19d1205
ZW
18674 /* FPA registers. */
18675 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18676 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18677
18678 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18679 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18680
18681 /* VFP SP registers. */
5287ad62
JB
18682 REGSET(s,VFS), REGSET(S,VFS),
18683 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18684
18685 /* VFP DP Registers. */
5287ad62
JB
18686 REGSET(d,VFD), REGSET(D,VFD),
18687 /* Extra Neon DP registers. */
18688 REGSETH(d,VFD), REGSETH(D,VFD),
18689
18690 /* Neon QP registers. */
18691 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18692
18693 /* VFP control registers. */
18694 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18695 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18696 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18697 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18698 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18699 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18700
18701 /* Maverick DSP coprocessor registers. */
18702 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18703 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18704
18705 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18706 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18707 REGDEF(dspsc,0,DSPSC),
18708
18709 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18710 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18711 REGDEF(DSPSC,0,DSPSC),
18712
18713 /* iWMMXt data registers - p0, c0-15. */
18714 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18715
18716 /* iWMMXt control registers - p1, c0-3. */
18717 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18718 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18719 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18720 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18721
18722 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18723 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18724 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18725 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18726 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18727
18728 /* XScale accumulator registers. */
18729 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18730};
18731#undef REGDEF
18732#undef REGNUM
18733#undef REGSET
7ed4c4c5 18734
c19d1205
ZW
18735/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18736 within psr_required_here. */
18737static const struct asm_psr psrs[] =
18738{
18739 /* Backward compatibility notation. Note that "all" is no longer
18740 truly all possible PSR bits. */
18741 {"all", PSR_c | PSR_f},
18742 {"flg", PSR_f},
18743 {"ctl", PSR_c},
18744
18745 /* Individual flags. */
18746 {"f", PSR_f},
18747 {"c", PSR_c},
18748 {"x", PSR_x},
18749 {"s", PSR_s},
59b42a0d 18750
c19d1205
ZW
18751 /* Combinations of flags. */
18752 {"fs", PSR_f | PSR_s},
18753 {"fx", PSR_f | PSR_x},
18754 {"fc", PSR_f | PSR_c},
18755 {"sf", PSR_s | PSR_f},
18756 {"sx", PSR_s | PSR_x},
18757 {"sc", PSR_s | PSR_c},
18758 {"xf", PSR_x | PSR_f},
18759 {"xs", PSR_x | PSR_s},
18760 {"xc", PSR_x | PSR_c},
18761 {"cf", PSR_c | PSR_f},
18762 {"cs", PSR_c | PSR_s},
18763 {"cx", PSR_c | PSR_x},
18764 {"fsx", PSR_f | PSR_s | PSR_x},
18765 {"fsc", PSR_f | PSR_s | PSR_c},
18766 {"fxs", PSR_f | PSR_x | PSR_s},
18767 {"fxc", PSR_f | PSR_x | PSR_c},
18768 {"fcs", PSR_f | PSR_c | PSR_s},
18769 {"fcx", PSR_f | PSR_c | PSR_x},
18770 {"sfx", PSR_s | PSR_f | PSR_x},
18771 {"sfc", PSR_s | PSR_f | PSR_c},
18772 {"sxf", PSR_s | PSR_x | PSR_f},
18773 {"sxc", PSR_s | PSR_x | PSR_c},
18774 {"scf", PSR_s | PSR_c | PSR_f},
18775 {"scx", PSR_s | PSR_c | PSR_x},
18776 {"xfs", PSR_x | PSR_f | PSR_s},
18777 {"xfc", PSR_x | PSR_f | PSR_c},
18778 {"xsf", PSR_x | PSR_s | PSR_f},
18779 {"xsc", PSR_x | PSR_s | PSR_c},
18780 {"xcf", PSR_x | PSR_c | PSR_f},
18781 {"xcs", PSR_x | PSR_c | PSR_s},
18782 {"cfs", PSR_c | PSR_f | PSR_s},
18783 {"cfx", PSR_c | PSR_f | PSR_x},
18784 {"csf", PSR_c | PSR_s | PSR_f},
18785 {"csx", PSR_c | PSR_s | PSR_x},
18786 {"cxf", PSR_c | PSR_x | PSR_f},
18787 {"cxs", PSR_c | PSR_x | PSR_s},
18788 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18789 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18790 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18791 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18792 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18793 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18794 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18795 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18796 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18797 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18798 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18799 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18800 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18801 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18802 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18803 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18804 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18805 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18806 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18807 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18808 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18809 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18810 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18811 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18812};
18813
62b3e311
PB
18814/* Table of V7M psr names. */
18815static const struct asm_psr v7m_psrs[] =
18816{
1a336194
TP
18817 {"apsr", 0x0 }, {"APSR", 0x0 },
18818 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
18819 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
18820 {"psr", 0x3 }, {"PSR", 0x3 },
18821 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
18822 {"ipsr", 0x5 }, {"IPSR", 0x5 },
18823 {"epsr", 0x6 }, {"EPSR", 0x6 },
18824 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
18825 {"msp", 0x8 }, {"MSP", 0x8 },
18826 {"psp", 0x9 }, {"PSP", 0x9 },
18827 {"msplim", 0xa }, {"MSPLIM", 0xa },
18828 {"psplim", 0xb }, {"PSPLIM", 0xb },
18829 {"primask", 0x10}, {"PRIMASK", 0x10},
18830 {"basepri", 0x11}, {"BASEPRI", 0x11},
18831 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
18832 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
18833 {"control", 0x14}, {"CONTROL", 0x14},
18834 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18835 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
18836 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
18837 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
18838 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
18839 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
18840 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
18841 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
18842 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
18843};
18844
c19d1205
ZW
18845/* Table of all shift-in-operand names. */
18846static const struct asm_shift_name shift_names [] =
b99bd4ef 18847{
c19d1205
ZW
18848 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18849 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18850 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18851 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18852 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18853 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18854};
b99bd4ef 18855
c19d1205
ZW
18856/* Table of all explicit relocation names. */
18857#ifdef OBJ_ELF
18858static struct reloc_entry reloc_names[] =
18859{
18860 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18861 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18862 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18863 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18864 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18865 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18866 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18867 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18868 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18869 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18870 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18871 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18872 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18873 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18874 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18875 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18876 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18877 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18878};
18879#endif
b99bd4ef 18880
c19d1205
ZW
18881/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18882static const struct asm_cond conds[] =
18883{
18884 {"eq", 0x0},
18885 {"ne", 0x1},
18886 {"cs", 0x2}, {"hs", 0x2},
18887 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18888 {"mi", 0x4},
18889 {"pl", 0x5},
18890 {"vs", 0x6},
18891 {"vc", 0x7},
18892 {"hi", 0x8},
18893 {"ls", 0x9},
18894 {"ge", 0xa},
18895 {"lt", 0xb},
18896 {"gt", 0xc},
18897 {"le", 0xd},
18898 {"al", 0xe}
18899};
bfae80f2 18900
e797f7e0 18901#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18902 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18903 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18904
62b3e311
PB
18905static struct asm_barrier_opt barrier_opt_names[] =
18906{
e797f7e0
MGD
18907 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18908 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18909 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18910 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18911 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18912 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18913 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18914 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18915 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18916 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18917 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18918 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18919 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18920 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18921 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18922 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18923};
18924
e797f7e0
MGD
18925#undef UL_BARRIER
18926
c19d1205
ZW
18927/* Table of ARM-format instructions. */
18928
18929/* Macros for gluing together operand strings. N.B. In all cases
18930 other than OPS0, the trailing OP_stop comes from default
18931 zero-initialization of the unspecified elements of the array. */
18932#define OPS0() { OP_stop, }
18933#define OPS1(a) { OP_##a, }
18934#define OPS2(a,b) { OP_##a,OP_##b, }
18935#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18936#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18937#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18938#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18939
5be8be5d
DG
18940/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18941 This is useful when mixing operands for ARM and THUMB, i.e. using the
18942 MIX_ARM_THUMB_OPERANDS macro.
18943 In order to use these macros, prefix the number of operands with _
18944 e.g. _3. */
18945#define OPS_1(a) { a, }
18946#define OPS_2(a,b) { a,b, }
18947#define OPS_3(a,b,c) { a,b,c, }
18948#define OPS_4(a,b,c,d) { a,b,c,d, }
18949#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18950#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18951
c19d1205
ZW
18952/* These macros abstract out the exact format of the mnemonic table and
18953 save some repeated characters. */
18954
18955/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18956#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18957 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18958 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18959
18960/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18961 a T_MNEM_xyz enumerator. */
18962#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18963 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18964#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18965 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18966
18967/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18968 infix after the third character. */
18969#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18970 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18971 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18972#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18973 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18974 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18975#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18976 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18977#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18978 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18979#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18980 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18981#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18982 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18983
c19d1205 18984/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18985 field is still 0xE. Many of the Thumb variants can be executed
18986 conditionally, so this is checked separately. */
c19d1205 18987#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18988 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18989 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18990
dd5181d5
KT
18991/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18992 Used by mnemonics that have very minimal differences in the encoding for
18993 ARM and Thumb variants and can be handled in a common function. */
18994#define TUEc(mnem, op, top, nops, ops, en) \
18995 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18996 THUMB_VARIANT, do_##en, do_##en }
18997
c19d1205
ZW
18998/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18999 condition code field. */
19000#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19001 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19002 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19003
19004/* ARM-only variants of all the above. */
6a86118a 19005#define CE(mnem, op, nops, ops, ae) \
21d799b5 19006 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19007
19008#define C3(mnem, op, nops, ops, ae) \
19009 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19010
e3cb604e
PB
19011/* Legacy mnemonics that always have conditional infix after the third
19012 character. */
19013#define CL(mnem, op, nops, ops, ae) \
21d799b5 19014 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19015 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19016
8f06b2d8
PB
19017/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19018#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19019 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19020
e3cb604e
PB
19021/* Legacy coprocessor instructions where conditional infix and conditional
19022 suffix are ambiguous. For consistency this includes all FPA instructions,
19023 not just the potentially ambiguous ones. */
19024#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19025 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19026 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19027
19028/* Coprocessor, takes either a suffix or a position-3 infix
19029 (for an FPA corner case). */
19030#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19031 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19032 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19033
6a86118a 19034#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19035 { m1 #m2 m3, OPS##nops ops, \
19036 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19037 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19038
19039#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19040 xCM_ (m1, , m2, op, nops, ops, ae), \
19041 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19042 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19043 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19044 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19045 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19046 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19047 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19048 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19049 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19050 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19051 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19052 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19053 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19054 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19055 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19056 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19057 xCM_ (m1, le, m2, op, nops, ops, ae), \
19058 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19059
19060#define UE(mnem, op, nops, ops, ae) \
19061 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19062
19063#define UF(mnem, op, nops, ops, ae) \
19064 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19065
5287ad62
JB
19066/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19067 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19068 use the same encoding function for each. */
19069#define NUF(mnem, op, nops, ops, enc) \
19070 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19071 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19072
19073/* Neon data processing, version which indirects through neon_enc_tab for
19074 the various overloaded versions of opcodes. */
19075#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19076 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19077 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19078
19079/* Neon insn with conditional suffix for the ARM version, non-overloaded
19080 version. */
037e8744
JB
19081#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19082 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19083 THUMB_VARIANT, do_##enc, do_##enc }
19084
037e8744 19085#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19086 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19087
19088#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19089 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19090
5287ad62 19091/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19092#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19093 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19094 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19095
037e8744 19096#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19097 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19098
19099#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19100 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19101
c19d1205
ZW
19102#define do_0 0
19103
c19d1205 19104static const struct asm_opcode insns[] =
bfae80f2 19105{
74db7efb
NC
19106#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19107#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19108 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19109 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19110 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19111 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19112 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19113 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19114 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19115 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19116 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19117 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19118 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19119 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19120 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19121 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19122 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19123 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19124
19125 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19126 for setting PSR flag bits. They are obsolete in V6 and do not
19127 have Thumb equivalents. */
21d799b5
NC
19128 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19129 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19130 CL("tstp", 110f000, 2, (RR, SH), cmp),
19131 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19132 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19133 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19134 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19135 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19136 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19137
19138 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19139 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19140 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19141 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19142
19143 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19144 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19145 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19146 OP_RRnpc),
19147 OP_ADDRGLDR),ldst, t_ldst),
19148 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19149
19150 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19151 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19152 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19153 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19154 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19155 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19156
19157 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19158 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19159 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19160 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19161
c19d1205 19162 /* Pseudo ops. */
21d799b5 19163 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19164 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19165 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19166 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19167
19168 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19169 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19170 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19171 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19172 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19173 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19174 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19175 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19176 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19177 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19178 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19179 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19180 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19181
16a4cf17 19182 /* These may simplify to neg. */
21d799b5
NC
19183 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19184 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19185
c921be7d
NC
19186#undef THUMB_VARIANT
19187#define THUMB_VARIANT & arm_ext_v6
19188
21d799b5 19189 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19190
19191 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19192#undef THUMB_VARIANT
19193#define THUMB_VARIANT & arm_ext_v6t2
19194
21d799b5
NC
19195 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19196 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19197 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19198
5be8be5d
DG
19199 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19200 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19201 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19202 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19203
21d799b5
NC
19204 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19205 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19206
21d799b5
NC
19207 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19208 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19209
19210 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19211 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19212 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19213
19214 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19215 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19216 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19217 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19218 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19219 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19220 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19221 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19222
c921be7d
NC
19223#undef ARM_VARIANT
19224#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19225#undef THUMB_VARIANT
19226#define THUMB_VARIANT & arm_ext_v4t
19227
21d799b5
NC
19228 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19229 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19230
c921be7d
NC
19231#undef THUMB_VARIANT
19232#define THUMB_VARIANT & arm_ext_v6t2
19233
21d799b5 19234 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19235 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19236
19237 /* Generic coprocessor instructions. */
21d799b5
NC
19238 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19239 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19240 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19241 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19242 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19243 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19244 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19245
c921be7d
NC
19246#undef ARM_VARIANT
19247#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19248
21d799b5 19249 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19250 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19251
c921be7d
NC
19252#undef ARM_VARIANT
19253#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19254#undef THUMB_VARIANT
19255#define THUMB_VARIANT & arm_ext_msr
19256
d2cd1205
JB
19257 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19258 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19259
c921be7d
NC
19260#undef ARM_VARIANT
19261#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19262#undef THUMB_VARIANT
19263#define THUMB_VARIANT & arm_ext_v6t2
19264
21d799b5
NC
19265 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19266 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19267 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19268 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19269 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19270 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19271 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19272 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19273
c921be7d
NC
19274#undef ARM_VARIANT
19275#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19276#undef THUMB_VARIANT
19277#define THUMB_VARIANT & arm_ext_v4t
19278
5be8be5d
DG
19279 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19280 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19281 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19282 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19283 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19284 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19285
c921be7d
NC
19286#undef ARM_VARIANT
19287#define ARM_VARIANT & arm_ext_v4t_5
19288
c19d1205
ZW
19289 /* ARM Architecture 4T. */
19290 /* Note: bx (and blx) are required on V5, even if the processor does
19291 not support Thumb. */
21d799b5 19292 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19293
c921be7d
NC
19294#undef ARM_VARIANT
19295#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19296#undef THUMB_VARIANT
19297#define THUMB_VARIANT & arm_ext_v5t
19298
c19d1205
ZW
19299 /* Note: blx has 2 variants; the .value coded here is for
19300 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19301 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19302 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19303
c921be7d
NC
19304#undef THUMB_VARIANT
19305#define THUMB_VARIANT & arm_ext_v6t2
19306
21d799b5
NC
19307 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19308 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19309 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19310 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19311 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19312 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19313 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19314 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19315
c921be7d 19316#undef ARM_VARIANT
74db7efb
NC
19317#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19318#undef THUMB_VARIANT
19319#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19320
21d799b5
NC
19321 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19322 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19323 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19324 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19325
21d799b5
NC
19326 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19327 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19328
21d799b5
NC
19329 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19330 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19331 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19332 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19333
21d799b5
NC
19334 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19335 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19336 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19337 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19338
21d799b5
NC
19339 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19340 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19341
03ee1b7f
NC
19342 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19343 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19344 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19345 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19346
c921be7d 19347#undef ARM_VARIANT
74db7efb
NC
19348#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19349#undef THUMB_VARIANT
19350#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19351
21d799b5 19352 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19353 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19354 ldrd, t_ldstd),
19355 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19356 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19357
21d799b5
NC
19358 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19359 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19360
c921be7d
NC
19361#undef ARM_VARIANT
19362#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19363
21d799b5 19364 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19365
c921be7d
NC
19366#undef ARM_VARIANT
19367#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19368#undef THUMB_VARIANT
19369#define THUMB_VARIANT & arm_ext_v6
19370
21d799b5
NC
19371 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19372 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19373 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19374 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19375 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19376 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19377 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19378 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19379 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19380 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19381
c921be7d 19382#undef THUMB_VARIANT
ff8646ee 19383#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19384
5be8be5d
DG
19385 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19386 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19387 strex, t_strex),
ff8646ee
TP
19388#undef THUMB_VARIANT
19389#define THUMB_VARIANT & arm_ext_v6t2
19390
21d799b5
NC
19391 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19392 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19393
21d799b5
NC
19394 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19395 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19396
9e3c6df6 19397/* ARM V6 not included in V7M. */
c921be7d
NC
19398#undef THUMB_VARIANT
19399#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19400 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19401 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19402 UF(rfeib, 9900a00, 1, (RRw), rfe),
19403 UF(rfeda, 8100a00, 1, (RRw), rfe),
19404 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19405 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19406 UF(rfefa, 8100a00, 1, (RRw), rfe),
19407 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19408 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19409 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19410 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19411 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19412 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19413 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19414 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19415 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19416 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19417 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19418 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19419
9e3c6df6
PB
19420/* ARM V6 not included in V7M (eg. integer SIMD). */
19421#undef THUMB_VARIANT
19422#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19423 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19424 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19425 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19426 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19427 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19428 /* Old name for QASX. */
74db7efb 19429 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19430 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19431 /* Old name for QSAX. */
74db7efb 19432 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19433 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19434 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19435 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19436 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19437 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19438 /* Old name for SASX. */
74db7efb 19439 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19440 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19441 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19442 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19443 /* Old name for SHASX. */
21d799b5 19444 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19445 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19446 /* Old name for SHSAX. */
21d799b5
NC
19447 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19448 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19449 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19450 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19451 /* Old name for SSAX. */
74db7efb 19452 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19453 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19454 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19455 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19456 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19457 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19458 /* Old name for UASX. */
74db7efb 19459 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19460 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19461 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19462 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19463 /* Old name for UHASX. */
21d799b5
NC
19464 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19465 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19466 /* Old name for UHSAX. */
21d799b5
NC
19467 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19468 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19469 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19470 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19471 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19472 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19473 /* Old name for UQASX. */
21d799b5
NC
19474 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19475 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19476 /* Old name for UQSAX. */
21d799b5
NC
19477 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19478 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19479 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19480 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19481 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19482 /* Old name for USAX. */
74db7efb 19483 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19484 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19485 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19486 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19487 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19488 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19489 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19490 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19491 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19492 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19493 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19494 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19495 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19496 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19497 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19498 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19499 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19500 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19501 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19502 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19503 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19504 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19505 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19506 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19507 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19508 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19509 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19510 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19511 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19512 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19513 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19514 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19515 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19516 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19517
c921be7d
NC
19518#undef ARM_VARIANT
19519#define ARM_VARIANT & arm_ext_v6k
19520#undef THUMB_VARIANT
19521#define THUMB_VARIANT & arm_ext_v6k
19522
21d799b5
NC
19523 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19524 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19525 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19526 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19527
c921be7d
NC
19528#undef THUMB_VARIANT
19529#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19530 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19531 ldrexd, t_ldrexd),
19532 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19533 RRnpcb), strexd, t_strexd),
ebdca51a 19534
c921be7d 19535#undef THUMB_VARIANT
ff8646ee 19536#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19537 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19538 rd_rn, rd_rn),
19539 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19540 rd_rn, rd_rn),
19541 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19542 strex, t_strexbh),
5be8be5d 19543 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19544 strex, t_strexbh),
21d799b5 19545 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19546
c921be7d 19547#undef ARM_VARIANT
f4c65163 19548#define ARM_VARIANT & arm_ext_sec
74db7efb 19549#undef THUMB_VARIANT
f4c65163 19550#define THUMB_VARIANT & arm_ext_sec
c921be7d 19551
21d799b5 19552 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19553
90ec0d68
MGD
19554#undef ARM_VARIANT
19555#define ARM_VARIANT & arm_ext_virt
19556#undef THUMB_VARIANT
19557#define THUMB_VARIANT & arm_ext_virt
19558
19559 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19560 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19561
ddfded2f
MW
19562#undef ARM_VARIANT
19563#define ARM_VARIANT & arm_ext_pan
19564#undef THUMB_VARIANT
19565#define THUMB_VARIANT & arm_ext_pan
19566
19567 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19568
c921be7d 19569#undef ARM_VARIANT
74db7efb 19570#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19571#undef THUMB_VARIANT
19572#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19573
21d799b5
NC
19574 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19575 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19576 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19577 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19578
21d799b5 19579 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19580 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19581
5be8be5d
DG
19582 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19583 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19584 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19585 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19586
ff8646ee
TP
19587#undef THUMB_VARIANT
19588#define THUMB_VARIANT & arm_ext_v6t2_v8m
19589 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19590 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19591
bf3eeda7 19592 /* Thumb-only instructions. */
74db7efb 19593#undef ARM_VARIANT
bf3eeda7
NS
19594#define ARM_VARIANT NULL
19595 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19596 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19597
19598 /* ARM does not really have an IT instruction, so always allow it.
19599 The opcode is copied from Thumb in order to allow warnings in
19600 -mimplicit-it=[never | arm] modes. */
19601#undef ARM_VARIANT
19602#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19603#undef THUMB_VARIANT
19604#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19605
21d799b5
NC
19606 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19607 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19608 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19609 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19610 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19611 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19612 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19613 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19614 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19615 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19616 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19617 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19618 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19619 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19620 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19621 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19622 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19623 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19624
92e90b6e 19625 /* Thumb2 only instructions. */
c921be7d
NC
19626#undef ARM_VARIANT
19627#define ARM_VARIANT NULL
92e90b6e 19628
21d799b5
NC
19629 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19630 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19631 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19632 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19633 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19634 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19635
eea54501
MGD
19636 /* Hardware division instructions. */
19637#undef ARM_VARIANT
19638#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19639#undef THUMB_VARIANT
19640#define THUMB_VARIANT & arm_ext_div
19641
eea54501
MGD
19642 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19643 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19644
7e806470 19645 /* ARM V6M/V7 instructions. */
c921be7d
NC
19646#undef ARM_VARIANT
19647#define ARM_VARIANT & arm_ext_barrier
19648#undef THUMB_VARIANT
19649#define THUMB_VARIANT & arm_ext_barrier
19650
ccb84d65
JB
19651 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19652 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19653 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19654
62b3e311 19655 /* ARM V7 instructions. */
c921be7d
NC
19656#undef ARM_VARIANT
19657#define ARM_VARIANT & arm_ext_v7
19658#undef THUMB_VARIANT
19659#define THUMB_VARIANT & arm_ext_v7
19660
21d799b5
NC
19661 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19662 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19663
74db7efb 19664#undef ARM_VARIANT
60e5ef9f 19665#define ARM_VARIANT & arm_ext_mp
74db7efb 19666#undef THUMB_VARIANT
60e5ef9f
MGD
19667#define THUMB_VARIANT & arm_ext_mp
19668
19669 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19670
53c4b28b
MGD
19671 /* AArchv8 instructions. */
19672#undef ARM_VARIANT
19673#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19674
19675/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19676#undef THUMB_VARIANT
4ed7ed8d 19677#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19678
4ed7ed8d
TP
19679 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19680 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19681 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19682 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19683 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19684 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19685 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19686 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19687 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19688 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19689 stlex, t_stlex),
4b8c8c02
RE
19690 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19691 stlex, t_stlex),
19692 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19693 stlex, t_stlex),
4ed7ed8d
TP
19694#undef THUMB_VARIANT
19695#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19696
4ed7ed8d
TP
19697 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19698 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19699 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19700 ldrexd, t_ldrexd),
19701 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19702 strexd, t_strexd),
8884b720 19703 /* ARMv8 T32 only. */
74db7efb 19704#undef ARM_VARIANT
b79f7053
MGD
19705#define ARM_VARIANT NULL
19706 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19707 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19708 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19709
33399f07
MGD
19710 /* FP for ARMv8. */
19711#undef ARM_VARIANT
a715796b 19712#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19713#undef THUMB_VARIANT
a715796b 19714#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19715
19716 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19717 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19718 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19719 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19720 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19721 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19722 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19723 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19724 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19725 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19726 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19727 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19728 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19729 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19730 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19731 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19732 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19733
91ff7894
MGD
19734 /* Crypto v1 extensions. */
19735#undef ARM_VARIANT
19736#define ARM_VARIANT & fpu_crypto_ext_armv8
19737#undef THUMB_VARIANT
19738#define THUMB_VARIANT & fpu_crypto_ext_armv8
19739
19740 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19741 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19742 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19743 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19744 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19745 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19746 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19747 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19748 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19749 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19750 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19751 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19752 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19753 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19754
dd5181d5 19755#undef ARM_VARIANT
74db7efb 19756#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19757#undef THUMB_VARIANT
19758#define THUMB_VARIANT & crc_ext_armv8
19759 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19760 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19761 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19762 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19763 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19764 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19765
105bde57
MW
19766 /* ARMv8.2 RAS extension. */
19767#undef ARM_VARIANT
4d1464f2 19768#define ARM_VARIANT & arm_ext_ras
105bde57 19769#undef THUMB_VARIANT
4d1464f2 19770#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19771 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19772
c921be7d
NC
19773#undef ARM_VARIANT
19774#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19775#undef THUMB_VARIANT
19776#define THUMB_VARIANT NULL
c921be7d 19777
21d799b5
NC
19778 cCE("wfs", e200110, 1, (RR), rd),
19779 cCE("rfs", e300110, 1, (RR), rd),
19780 cCE("wfc", e400110, 1, (RR), rd),
19781 cCE("rfc", e500110, 1, (RR), rd),
19782
19783 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19784 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19785 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19786 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19787
19788 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19789 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19790 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19791 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19792
19793 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19794 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19795 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19796 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19797 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19798 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19799 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19800 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19801 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19802 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19803 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19804 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19805
19806 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19807 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19808 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19809 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19810 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19811 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19812 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19813 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19814 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19815 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19816 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19817 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19818
19819 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19820 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19821 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19822 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19823 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19824 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19825 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19826 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19827 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19828 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19829 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19830 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19831
19832 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19833 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19834 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19835 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19836 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19837 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19838 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19839 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19840 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19841 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19842 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19843 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19844
19845 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19846 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19847 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19848 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19849 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19850 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19851 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19852 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19853 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19854 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19855 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19856 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19857
19858 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19859 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19860 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19861 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19862 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19863 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19864 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19865 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19866 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19867 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19868 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19869 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19870
19871 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19872 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19873 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19874 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19875 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19876 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19877 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19878 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19879 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19880 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19881 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19882 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19883
19884 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19885 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19886 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19887 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19888 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19889 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19890 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19891 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19892 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19893 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19894 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19895 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19896
19897 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19898 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19899 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19900 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19901 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19902 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19903 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19904 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19905 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19906 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19907 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19908 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19909
19910 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19911 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19912 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19913 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19914 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19915 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19916 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19917 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19918 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19919 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19920 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19921 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19922
19923 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19924 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19925 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19926 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19927 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19928 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19929 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19930 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19931 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19932 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19933 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19934 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19935
19936 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19937 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19938 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19939 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19940 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19941 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19942 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19943 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19944 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19945 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19946 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19947 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19948
19949 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19950 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19951 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19952 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19953 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19954 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19955 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19956 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19957 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19958 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19959 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19960 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19961
19962 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19963 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19964 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19965 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19966 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19967 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19968 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19969 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19970 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19971 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19972 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19973 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19974
19975 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19976 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19977 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19978 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19979 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19980 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19981 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19982 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19983 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19984 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19985 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19986 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19987
19988 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19989 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19990 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19991 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19992 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19993 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19994 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19995 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19996 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19997 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19998 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19999 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20000
20001 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20002 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20003 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20004 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20005 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20006 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20007 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20008 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20009 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20010 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20011 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20012 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20013
20014 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20015 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20016 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20017 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20018 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20019 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20020 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20021 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20022 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20023 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20024 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20025 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20026
20027 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20028 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20029 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20030 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20031 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20032 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20033 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20034 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20035 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20036 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20037 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20038 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20039
20040 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20041 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20042 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20043 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20044 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20045 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20046 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20047 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20048 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20049 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20050 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20051 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20052
20053 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20054 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20055 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20056 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20057 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20058 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20059 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20060 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20061 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20062 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20063 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20064 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20065
20066 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20067 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20068 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20069 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20070 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20071 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20072 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20073 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20074 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20075 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20076 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20077 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20078
20079 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20080 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20081 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20082 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20083 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20084 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20085 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20086 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20087 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20088 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20089 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20090 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20091
20092 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20093 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20094 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20095 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20096 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20097 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20098 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20099 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20100 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20101 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20102 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20103 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20104
20105 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20106 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20107 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20108 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20109 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20110 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20111 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20112 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20113 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20114 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20115 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20116 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20117
20118 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20119 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20120 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20121 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20122 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20123 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20124 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20125 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20126 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20127 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20128 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20129 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20130
20131 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20132 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20133 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20134 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20135 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20136 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20137 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20138 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20139 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20140 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20141 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20142 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20143
20144 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20145 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20146 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20147 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20148 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20149 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20150 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20151 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20152 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20153 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20154 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20155 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20156
20157 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20158 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20159 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20160 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20161 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20162 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20163 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20164 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20165 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20166 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20167 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20168 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20169
20170 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20171 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20172 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20173 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20174
20175 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20176 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20177 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20178 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20179 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20180 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20181 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20182 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20183 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20184 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20185 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20186 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20187
c19d1205
ZW
20188 /* The implementation of the FIX instruction is broken on some
20189 assemblers, in that it accepts a precision specifier as well as a
20190 rounding specifier, despite the fact that this is meaningless.
20191 To be more compatible, we accept it as well, though of course it
20192 does not set any bits. */
21d799b5
NC
20193 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20194 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20195 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20196 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20197 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20198 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20199 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20200 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20201 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20202 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20203 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20204 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20205 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20206
c19d1205 20207 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20208#undef ARM_VARIANT
20209#define ARM_VARIANT & fpu_fpa_ext_v2
20210
21d799b5
NC
20211 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20212 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20213 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20214 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20215 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20216 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20217
c921be7d
NC
20218#undef ARM_VARIANT
20219#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20220
c19d1205 20221 /* Moves and type conversions. */
21d799b5
NC
20222 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20223 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20224 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20225 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20226 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20227 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20228 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20229 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20230 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20231 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20232 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20233 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20234 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20235 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20236
20237 /* Memory operations. */
21d799b5
NC
20238 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20239 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20240 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20241 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20242 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20243 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20244 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20245 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20246 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20247 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20248 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20249 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20250 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20251 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20252 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20253 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20254 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20255 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20256
c19d1205 20257 /* Monadic operations. */
21d799b5
NC
20258 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20259 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20260 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20261
20262 /* Dyadic operations. */
21d799b5
NC
20263 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20264 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20265 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20266 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20267 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20268 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20269 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20270 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20271 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20272
c19d1205 20273 /* Comparisons. */
21d799b5
NC
20274 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20275 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20276 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20277 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20278
62f3b8c8
PB
20279 /* Double precision load/store are still present on single precision
20280 implementations. */
20281 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20282 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20283 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20284 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20285 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20286 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20287 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20288 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20289 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20290 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20291
c921be7d
NC
20292#undef ARM_VARIANT
20293#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20294
c19d1205 20295 /* Moves and type conversions. */
21d799b5
NC
20296 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20297 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20298 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20299 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20300 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20301 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20302 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20303 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20304 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20305 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20306 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20307 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20308 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20309
c19d1205 20310 /* Monadic operations. */
21d799b5
NC
20311 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20312 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20313 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20314
20315 /* Dyadic operations. */
21d799b5
NC
20316 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20317 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20318 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20319 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20320 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20321 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20322 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20323 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20324 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20325
c19d1205 20326 /* Comparisons. */
21d799b5
NC
20327 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20328 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20329 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20330 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20331
c921be7d
NC
20332#undef ARM_VARIANT
20333#define ARM_VARIANT & fpu_vfp_ext_v2
20334
21d799b5
NC
20335 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20336 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20337 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20338 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20339
037e8744
JB
20340/* Instructions which may belong to either the Neon or VFP instruction sets.
20341 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20342#undef ARM_VARIANT
20343#define ARM_VARIANT & fpu_vfp_ext_v1xd
20344#undef THUMB_VARIANT
20345#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20346
037e8744
JB
20347 /* These mnemonics are unique to VFP. */
20348 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20349 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20350 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20351 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20352 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20353 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20354 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20355 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20356 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20357 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20358
20359 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20360 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20361 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20362 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20363
21d799b5
NC
20364 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20365 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20366
20367 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20368 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20369
55881a11
MGD
20370 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20371 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20372 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20373 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20374 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20375 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20376 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20377 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20378
5f1af56b 20379 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20380 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20381 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20382 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20383
037e8744
JB
20384
20385 /* NOTE: All VMOV encoding is special-cased! */
20386 NCE(vmov, 0, 1, (VMOV), neon_mov),
20387 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20388
9db2f6b4
RL
20389#undef ARM_VARIANT
20390#define ARM_VARIANT & arm_ext_fp16
20391#undef THUMB_VARIANT
20392#define THUMB_VARIANT & arm_ext_fp16
20393 /* New instructions added from v8.2, allowing the extraction and insertion of
20394 the upper 16 bits of a 32-bit vector register. */
20395 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20396 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20397
c921be7d
NC
20398#undef THUMB_VARIANT
20399#define THUMB_VARIANT & fpu_neon_ext_v1
20400#undef ARM_VARIANT
20401#define ARM_VARIANT & fpu_neon_ext_v1
20402
5287ad62
JB
20403 /* Data processing with three registers of the same length. */
20404 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20405 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20406 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20407 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20408 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20409 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20410 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20411 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20412 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20413 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20414 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20415 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20416 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20417 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20418 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20419 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20420 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20421 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20422 /* If not immediate, fall back to neon_dyadic_i64_su.
20423 shl_imm should accept I8 I16 I32 I64,
20424 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20425 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20426 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20427 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20428 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20429 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20430 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20431 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20432 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20433 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20434 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20435 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20436 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20437 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20438 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20439 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20440 /* Bitfield ops, untyped. */
20441 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20442 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20443 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20444 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20445 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20446 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20447 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20448 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20449 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20450 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20451 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20452 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20453 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20454 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20455 back to neon_dyadic_if_su. */
21d799b5
NC
20456 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20457 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20458 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20459 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20460 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20461 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20462 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20463 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20464 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20465 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20466 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20467 /* As above, D registers only. */
21d799b5
NC
20468 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20469 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20470 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20471 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20472 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20473 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20474 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20475 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20476 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20477 /* vtst takes sizes 8, 16, 32. */
20478 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20479 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20480 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20481 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20482 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20483 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20484 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20485 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20486 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20487 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20488 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20489 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20490 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20491 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20492 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20493 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20494 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20495 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20496 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20497 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20498 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20499 /* ARM v8.1 extension. */
643afb90
MW
20500 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20501 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20502 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20503 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20504
20505 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20506 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20507 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20508
20509 /* Data processing with two registers and a shift amount. */
20510 /* Right shifts, and variants with rounding.
20511 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20512 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20513 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20514 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20515 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20516 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20517 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20518 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20519 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20520 /* Shift and insert. Sizes accepted 8 16 32 64. */
20521 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20522 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20523 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20524 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20525 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20526 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20527 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20528 /* Right shift immediate, saturating & narrowing, with rounding variants.
20529 Types accepted S16 S32 S64 U16 U32 U64. */
20530 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20531 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20532 /* As above, unsigned. Types accepted S16 S32 S64. */
20533 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20534 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20535 /* Right shift narrowing. Types accepted I16 I32 I64. */
20536 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20537 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20538 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20539 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20540 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20541 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20542
4316f0d2
DG
20543 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20544 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20545
20546 /* Data processing, three registers of different lengths. */
20547 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20548 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20549 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20550 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20551 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20552 /* If not scalar, fall back to neon_dyadic_long.
20553 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20554 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20555 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20556 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20557 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20558 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20559 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20560 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20561 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20562 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20563 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20564 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20565 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20566 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20567 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20568 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20569 S16 S32 U16 U32. */
21d799b5 20570 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20571
20572 /* Extract. Size 8. */
3b8d421e
PB
20573 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20574 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20575
20576 /* Two registers, miscellaneous. */
20577 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20578 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20579 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20580 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20581 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20582 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20583 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20584 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20585 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20586 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20587 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20588 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20589 /* VMOVN. Types I16 I32 I64. */
21d799b5 20590 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20591 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20592 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20593 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20594 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20595 /* VZIP / VUZP. Sizes 8 16 32. */
20596 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20597 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20598 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20599 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20600 /* VQABS / VQNEG. Types S8 S16 S32. */
20601 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20602 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20603 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20604 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20605 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20606 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20607 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20608 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20609 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20610 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20611 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20612 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20613 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20614 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20615 /* VCLS. Types S8 S16 S32. */
20616 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20617 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20618 /* VCLZ. Types I8 I16 I32. */
20619 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20620 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20621 /* VCNT. Size 8. */
20622 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20623 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20624 /* Two address, untyped. */
20625 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20626 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20627 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20628 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20629 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20630
20631 /* Table lookup. Size 8. */
20632 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20633 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20634
c921be7d
NC
20635#undef THUMB_VARIANT
20636#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20637#undef ARM_VARIANT
20638#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20639
5287ad62 20640 /* Neon element/structure load/store. */
21d799b5
NC
20641 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20642 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20643 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20644 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20645 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20646 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20647 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20648 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20649
c921be7d 20650#undef THUMB_VARIANT
74db7efb
NC
20651#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20652#undef ARM_VARIANT
20653#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20654 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20655 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20656 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20657 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20658 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20659 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20660 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20661 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20662 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20663
74db7efb 20664#undef THUMB_VARIANT
c921be7d
NC
20665#define THUMB_VARIANT & fpu_vfp_ext_v3
20666#undef ARM_VARIANT
20667#define ARM_VARIANT & fpu_vfp_ext_v3
20668
21d799b5 20669 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20670 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20671 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20672 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20673 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20674 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20675 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20676 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20677 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20678
74db7efb
NC
20679#undef ARM_VARIANT
20680#define ARM_VARIANT & fpu_vfp_ext_fma
20681#undef THUMB_VARIANT
20682#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20683 /* Mnemonics shared by Neon and VFP. These are included in the
20684 VFP FMA variant; NEON and VFP FMA always includes the NEON
20685 FMA instructions. */
20686 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20687 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20688 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20689 the v form should always be used. */
20690 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20691 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20692 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20693 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20694 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20695 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20696
5287ad62 20697#undef THUMB_VARIANT
c921be7d
NC
20698#undef ARM_VARIANT
20699#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20700
21d799b5
NC
20701 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20702 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20703 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20704 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20705 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20706 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20707 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20708 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20709
c921be7d
NC
20710#undef ARM_VARIANT
20711#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20712
21d799b5
NC
20713 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20714 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20715 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20716 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20717 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20718 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20719 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20720 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20721 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20722 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20723 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20724 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20725 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20726 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20727 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20728 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20729 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20730 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20731 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20732 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20733 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20734 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20735 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20736 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20737 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20738 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20739 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20740 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20741 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20742 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20743 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20744 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20745 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20746 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20747 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20748 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20749 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20750 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20751 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20752 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20753 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20754 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20755 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20756 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20757 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20758 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20759 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20760 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20761 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20762 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20763 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20764 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20765 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20766 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20767 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20768 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20769 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20770 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20771 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20772 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20773 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20774 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20775 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20776 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20777 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20778 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20779 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20780 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20781 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20782 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20783 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20784 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20785 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20786 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20787 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20788 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20789 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20790 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20791 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20792 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20793 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20794 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20795 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20796 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20797 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20798 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20799 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20800 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20801 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20802 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20803 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20804 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20805 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20806 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20807 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20808 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20809 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20810 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20811 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20812 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20813 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20814 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20815 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20816 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20817 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20818 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20819 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20820 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20821 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20822 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20823 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20824 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20825 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20826 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20827 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20828 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20829 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20830 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20831 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20832 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20833 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20834 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20835 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20836 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20837 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20838 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20839 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20840 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20841 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20842 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20843 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20844 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20845 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20846 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20847 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20848 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20849 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20850 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20851 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20852 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20853 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20854 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20855 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20856 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20857 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20858 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20859 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20860 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20861 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20862 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20863 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20864 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20865 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20866 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20867 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20868 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20869 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20870 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20871 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20872 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20873 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20874 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20875
c921be7d
NC
20876#undef ARM_VARIANT
20877#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20878
21d799b5
NC
20879 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20880 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20881 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20882 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20883 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20884 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20885 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20886 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20887 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20888 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20889 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20890 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20891 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20892 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20893 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20894 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20895 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20896 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20897 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20898 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20899 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20900 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20904 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20905 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20906 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20907 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20908 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20909 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20910 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20911 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20912 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20913 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20914 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20915 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20916 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20917 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20918 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20919 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20920 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20921 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20922 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20923 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20924 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20925 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20926 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20927 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20928 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20929 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20930 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20931 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20932 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20933 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20934 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20935 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20936
c921be7d
NC
20937#undef ARM_VARIANT
20938#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20939
21d799b5
NC
20940 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20941 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20942 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20943 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20944 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20945 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20946 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20947 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20948 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20949 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20950 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20951 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20952 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20953 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20954 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20955 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20956 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20957 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20958 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20959 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20960 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20961 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20962 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20963 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20964 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20965 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20966 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20967 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20968 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20969 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20970 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20971 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20972 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20973 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20974 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20975 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20976 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20977 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20978 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20979 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20980 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20981 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20982 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20983 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20984 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20985 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20986 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20987 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20988 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20989 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20990 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20991 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20992 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20993 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20994 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20995 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20996 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20997 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20998 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20999 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21000 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21001 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21002 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21003 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21004 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21005 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21006 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21007 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21008 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21009 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21010 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21011 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21012 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21013 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21014 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21015 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21016
16a1fa25 21017 /* ARMv8-M instructions. */
4ed7ed8d
TP
21018#undef ARM_VARIANT
21019#define ARM_VARIANT NULL
21020#undef THUMB_VARIANT
21021#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21022 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21023 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21024 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21025 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21026 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21027 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21028 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21029
21030 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21031 instructions behave as nop if no VFP is present. */
21032#undef THUMB_VARIANT
21033#define THUMB_VARIANT & arm_ext_v8m_main
21034 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21035 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21036};
21037#undef ARM_VARIANT
21038#undef THUMB_VARIANT
21039#undef TCE
c19d1205
ZW
21040#undef TUE
21041#undef TUF
21042#undef TCC
8f06b2d8 21043#undef cCE
e3cb604e
PB
21044#undef cCL
21045#undef C3E
c19d1205
ZW
21046#undef CE
21047#undef CM
21048#undef UE
21049#undef UF
21050#undef UT
5287ad62
JB
21051#undef NUF
21052#undef nUF
21053#undef NCE
21054#undef nCE
c19d1205
ZW
21055#undef OPS0
21056#undef OPS1
21057#undef OPS2
21058#undef OPS3
21059#undef OPS4
21060#undef OPS5
21061#undef OPS6
21062#undef do_0
21063\f
21064/* MD interface: bits in the object file. */
bfae80f2 21065
c19d1205
ZW
21066/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21067 for use in the a.out file, and stores them in the array pointed to by buf.
21068 This knows about the endian-ness of the target machine and does
21069 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21070 2 (short) and 4 (long) Floating numbers are put out as a series of
21071 LITTLENUMS (shorts, here at least). */
b99bd4ef 21072
c19d1205
ZW
21073void
21074md_number_to_chars (char * buf, valueT val, int n)
21075{
21076 if (target_big_endian)
21077 number_to_chars_bigendian (buf, val, n);
21078 else
21079 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21080}
21081
c19d1205
ZW
21082static valueT
21083md_chars_to_number (char * buf, int n)
bfae80f2 21084{
c19d1205
ZW
21085 valueT result = 0;
21086 unsigned char * where = (unsigned char *) buf;
bfae80f2 21087
c19d1205 21088 if (target_big_endian)
b99bd4ef 21089 {
c19d1205
ZW
21090 while (n--)
21091 {
21092 result <<= 8;
21093 result |= (*where++ & 255);
21094 }
b99bd4ef 21095 }
c19d1205 21096 else
b99bd4ef 21097 {
c19d1205
ZW
21098 while (n--)
21099 {
21100 result <<= 8;
21101 result |= (where[n] & 255);
21102 }
bfae80f2 21103 }
b99bd4ef 21104
c19d1205 21105 return result;
bfae80f2 21106}
b99bd4ef 21107
c19d1205 21108/* MD interface: Sections. */
b99bd4ef 21109
fa94de6b
RM
21110/* Calculate the maximum variable size (i.e., excluding fr_fix)
21111 that an rs_machine_dependent frag may reach. */
21112
21113unsigned int
21114arm_frag_max_var (fragS *fragp)
21115{
21116 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21117 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21118
21119 Note that we generate relaxable instructions even for cases that don't
21120 really need it, like an immediate that's a trivial constant. So we're
21121 overestimating the instruction size for some of those cases. Rather
21122 than putting more intelligence here, it would probably be better to
21123 avoid generating a relaxation frag in the first place when it can be
21124 determined up front that a short instruction will suffice. */
21125
21126 gas_assert (fragp->fr_type == rs_machine_dependent);
21127 return INSN_SIZE;
21128}
21129
0110f2b8
PB
21130/* Estimate the size of a frag before relaxing. Assume everything fits in
21131 2 bytes. */
21132
c19d1205 21133int
0110f2b8 21134md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21135 segT segtype ATTRIBUTE_UNUSED)
21136{
0110f2b8
PB
21137 fragp->fr_var = 2;
21138 return 2;
21139}
21140
21141/* Convert a machine dependent frag. */
21142
21143void
21144md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21145{
21146 unsigned long insn;
21147 unsigned long old_op;
21148 char *buf;
21149 expressionS exp;
21150 fixS *fixp;
21151 int reloc_type;
21152 int pc_rel;
21153 int opcode;
21154
21155 buf = fragp->fr_literal + fragp->fr_fix;
21156
21157 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21158 if (fragp->fr_symbol)
21159 {
0110f2b8
PB
21160 exp.X_op = O_symbol;
21161 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21162 }
21163 else
21164 {
0110f2b8 21165 exp.X_op = O_constant;
5f4273c7 21166 }
0110f2b8
PB
21167 exp.X_add_number = fragp->fr_offset;
21168 opcode = fragp->fr_subtype;
21169 switch (opcode)
21170 {
21171 case T_MNEM_ldr_pc:
21172 case T_MNEM_ldr_pc2:
21173 case T_MNEM_ldr_sp:
21174 case T_MNEM_str_sp:
21175 case T_MNEM_ldr:
21176 case T_MNEM_ldrb:
21177 case T_MNEM_ldrh:
21178 case T_MNEM_str:
21179 case T_MNEM_strb:
21180 case T_MNEM_strh:
21181 if (fragp->fr_var == 4)
21182 {
5f4273c7 21183 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21184 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21185 {
21186 insn |= (old_op & 0x700) << 4;
21187 }
21188 else
21189 {
21190 insn |= (old_op & 7) << 12;
21191 insn |= (old_op & 0x38) << 13;
21192 }
21193 insn |= 0x00000c00;
21194 put_thumb32_insn (buf, insn);
21195 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21196 }
21197 else
21198 {
21199 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21200 }
21201 pc_rel = (opcode == T_MNEM_ldr_pc2);
21202 break;
21203 case T_MNEM_adr:
21204 if (fragp->fr_var == 4)
21205 {
21206 insn = THUMB_OP32 (opcode);
21207 insn |= (old_op & 0xf0) << 4;
21208 put_thumb32_insn (buf, insn);
21209 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21210 }
21211 else
21212 {
21213 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21214 exp.X_add_number -= 4;
21215 }
21216 pc_rel = 1;
21217 break;
21218 case T_MNEM_mov:
21219 case T_MNEM_movs:
21220 case T_MNEM_cmp:
21221 case T_MNEM_cmn:
21222 if (fragp->fr_var == 4)
21223 {
21224 int r0off = (opcode == T_MNEM_mov
21225 || opcode == T_MNEM_movs) ? 0 : 8;
21226 insn = THUMB_OP32 (opcode);
21227 insn = (insn & 0xe1ffffff) | 0x10000000;
21228 insn |= (old_op & 0x700) << r0off;
21229 put_thumb32_insn (buf, insn);
21230 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21231 }
21232 else
21233 {
21234 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21235 }
21236 pc_rel = 0;
21237 break;
21238 case T_MNEM_b:
21239 if (fragp->fr_var == 4)
21240 {
21241 insn = THUMB_OP32(opcode);
21242 put_thumb32_insn (buf, insn);
21243 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21244 }
21245 else
21246 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21247 pc_rel = 1;
21248 break;
21249 case T_MNEM_bcond:
21250 if (fragp->fr_var == 4)
21251 {
21252 insn = THUMB_OP32(opcode);
21253 insn |= (old_op & 0xf00) << 14;
21254 put_thumb32_insn (buf, insn);
21255 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21256 }
21257 else
21258 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21259 pc_rel = 1;
21260 break;
21261 case T_MNEM_add_sp:
21262 case T_MNEM_add_pc:
21263 case T_MNEM_inc_sp:
21264 case T_MNEM_dec_sp:
21265 if (fragp->fr_var == 4)
21266 {
21267 /* ??? Choose between add and addw. */
21268 insn = THUMB_OP32 (opcode);
21269 insn |= (old_op & 0xf0) << 4;
21270 put_thumb32_insn (buf, insn);
16805f35
PB
21271 if (opcode == T_MNEM_add_pc)
21272 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21273 else
21274 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21275 }
21276 else
21277 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21278 pc_rel = 0;
21279 break;
21280
21281 case T_MNEM_addi:
21282 case T_MNEM_addis:
21283 case T_MNEM_subi:
21284 case T_MNEM_subis:
21285 if (fragp->fr_var == 4)
21286 {
21287 insn = THUMB_OP32 (opcode);
21288 insn |= (old_op & 0xf0) << 4;
21289 insn |= (old_op & 0xf) << 16;
21290 put_thumb32_insn (buf, insn);
16805f35
PB
21291 if (insn & (1 << 20))
21292 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21293 else
21294 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21295 }
21296 else
21297 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21298 pc_rel = 0;
21299 break;
21300 default:
5f4273c7 21301 abort ();
0110f2b8
PB
21302 }
21303 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21304 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21305 fixp->fx_file = fragp->fr_file;
21306 fixp->fx_line = fragp->fr_line;
21307 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21308
21309 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21310 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21311 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21312 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21313}
21314
21315/* Return the size of a relaxable immediate operand instruction.
21316 SHIFT and SIZE specify the form of the allowable immediate. */
21317static int
21318relax_immediate (fragS *fragp, int size, int shift)
21319{
21320 offsetT offset;
21321 offsetT mask;
21322 offsetT low;
21323
21324 /* ??? Should be able to do better than this. */
21325 if (fragp->fr_symbol)
21326 return 4;
21327
21328 low = (1 << shift) - 1;
21329 mask = (1 << (shift + size)) - (1 << shift);
21330 offset = fragp->fr_offset;
21331 /* Force misaligned offsets to 32-bit variant. */
21332 if (offset & low)
5e77afaa 21333 return 4;
0110f2b8
PB
21334 if (offset & ~mask)
21335 return 4;
21336 return 2;
21337}
21338
5e77afaa
PB
21339/* Get the address of a symbol during relaxation. */
21340static addressT
5f4273c7 21341relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21342{
21343 fragS *sym_frag;
21344 addressT addr;
21345 symbolS *sym;
21346
21347 sym = fragp->fr_symbol;
21348 sym_frag = symbol_get_frag (sym);
21349 know (S_GET_SEGMENT (sym) != absolute_section
21350 || sym_frag == &zero_address_frag);
21351 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21352
21353 /* If frag has yet to be reached on this pass, assume it will
21354 move by STRETCH just as we did. If this is not so, it will
21355 be because some frag between grows, and that will force
21356 another pass. */
21357
21358 if (stretch != 0
21359 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21360 {
21361 fragS *f;
21362
21363 /* Adjust stretch for any alignment frag. Note that if have
21364 been expanding the earlier code, the symbol may be
21365 defined in what appears to be an earlier frag. FIXME:
21366 This doesn't handle the fr_subtype field, which specifies
21367 a maximum number of bytes to skip when doing an
21368 alignment. */
21369 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21370 {
21371 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21372 {
21373 if (stretch < 0)
21374 stretch = - ((- stretch)
21375 & ~ ((1 << (int) f->fr_offset) - 1));
21376 else
21377 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21378 if (stretch == 0)
21379 break;
21380 }
21381 }
21382 if (f != NULL)
21383 addr += stretch;
21384 }
5e77afaa
PB
21385
21386 return addr;
21387}
21388
0110f2b8
PB
21389/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21390 load. */
21391static int
5e77afaa 21392relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21393{
21394 addressT addr;
21395 offsetT val;
21396
21397 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21398 if (fragp->fr_symbol == NULL
21399 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21400 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21401 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21402 return 4;
21403
5f4273c7 21404 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21405 addr = fragp->fr_address + fragp->fr_fix;
21406 addr = (addr + 4) & ~3;
5e77afaa 21407 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21408 if (val & 3)
5e77afaa 21409 return 4;
0110f2b8
PB
21410 val -= addr;
21411 if (val < 0 || val > 1020)
21412 return 4;
21413 return 2;
21414}
21415
21416/* Return the size of a relaxable add/sub immediate instruction. */
21417static int
21418relax_addsub (fragS *fragp, asection *sec)
21419{
21420 char *buf;
21421 int op;
21422
21423 buf = fragp->fr_literal + fragp->fr_fix;
21424 op = bfd_get_16(sec->owner, buf);
21425 if ((op & 0xf) == ((op >> 4) & 0xf))
21426 return relax_immediate (fragp, 8, 0);
21427 else
21428 return relax_immediate (fragp, 3, 0);
21429}
21430
e83a675f
RE
21431/* Return TRUE iff the definition of symbol S could be pre-empted
21432 (overridden) at link or load time. */
21433static bfd_boolean
21434symbol_preemptible (symbolS *s)
21435{
21436 /* Weak symbols can always be pre-empted. */
21437 if (S_IS_WEAK (s))
21438 return TRUE;
21439
21440 /* Non-global symbols cannot be pre-empted. */
21441 if (! S_IS_EXTERNAL (s))
21442 return FALSE;
21443
21444#ifdef OBJ_ELF
21445 /* In ELF, a global symbol can be marked protected, or private. In that
21446 case it can't be pre-empted (other definitions in the same link unit
21447 would violate the ODR). */
21448 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21449 return FALSE;
21450#endif
21451
21452 /* Other global symbols might be pre-empted. */
21453 return TRUE;
21454}
0110f2b8
PB
21455
21456/* Return the size of a relaxable branch instruction. BITS is the
21457 size of the offset field in the narrow instruction. */
21458
21459static int
5e77afaa 21460relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21461{
21462 addressT addr;
21463 offsetT val;
21464 offsetT limit;
21465
21466 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21467 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21468 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21469 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21470 return 4;
21471
267bf995 21472#ifdef OBJ_ELF
e83a675f 21473 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21474 if (S_IS_DEFINED (fragp->fr_symbol)
21475 && ARM_IS_FUNC (fragp->fr_symbol))
21476 return 4;
e83a675f 21477#endif
0d9b4b55 21478
e83a675f 21479 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21480 return 4;
267bf995 21481
5f4273c7 21482 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21483 addr = fragp->fr_address + fragp->fr_fix + 4;
21484 val -= addr;
21485
21486 /* Offset is a signed value *2 */
21487 limit = 1 << bits;
21488 if (val >= limit || val < -limit)
21489 return 4;
21490 return 2;
21491}
21492
21493
21494/* Relax a machine dependent frag. This returns the amount by which
21495 the current size of the frag should change. */
21496
21497int
5e77afaa 21498arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21499{
21500 int oldsize;
21501 int newsize;
21502
21503 oldsize = fragp->fr_var;
21504 switch (fragp->fr_subtype)
21505 {
21506 case T_MNEM_ldr_pc2:
5f4273c7 21507 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21508 break;
21509 case T_MNEM_ldr_pc:
21510 case T_MNEM_ldr_sp:
21511 case T_MNEM_str_sp:
5f4273c7 21512 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21513 break;
21514 case T_MNEM_ldr:
21515 case T_MNEM_str:
5f4273c7 21516 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21517 break;
21518 case T_MNEM_ldrh:
21519 case T_MNEM_strh:
5f4273c7 21520 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21521 break;
21522 case T_MNEM_ldrb:
21523 case T_MNEM_strb:
5f4273c7 21524 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21525 break;
21526 case T_MNEM_adr:
5f4273c7 21527 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21528 break;
21529 case T_MNEM_mov:
21530 case T_MNEM_movs:
21531 case T_MNEM_cmp:
21532 case T_MNEM_cmn:
5f4273c7 21533 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21534 break;
21535 case T_MNEM_b:
5f4273c7 21536 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21537 break;
21538 case T_MNEM_bcond:
5f4273c7 21539 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21540 break;
21541 case T_MNEM_add_sp:
21542 case T_MNEM_add_pc:
21543 newsize = relax_immediate (fragp, 8, 2);
21544 break;
21545 case T_MNEM_inc_sp:
21546 case T_MNEM_dec_sp:
21547 newsize = relax_immediate (fragp, 7, 2);
21548 break;
21549 case T_MNEM_addi:
21550 case T_MNEM_addis:
21551 case T_MNEM_subi:
21552 case T_MNEM_subis:
21553 newsize = relax_addsub (fragp, sec);
21554 break;
21555 default:
5f4273c7 21556 abort ();
0110f2b8 21557 }
5e77afaa
PB
21558
21559 fragp->fr_var = newsize;
21560 /* Freeze wide instructions that are at or before the same location as
21561 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21562 Don't freeze them unconditionally because targets may be artificially
21563 misaligned by the expansion of preceding frags. */
5e77afaa 21564 if (stretch <= 0 && newsize > 2)
0110f2b8 21565 {
0110f2b8 21566 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21567 frag_wane (fragp);
0110f2b8 21568 }
5e77afaa 21569
0110f2b8 21570 return newsize - oldsize;
c19d1205 21571}
b99bd4ef 21572
c19d1205 21573/* Round up a section size to the appropriate boundary. */
b99bd4ef 21574
c19d1205
ZW
21575valueT
21576md_section_align (segT segment ATTRIBUTE_UNUSED,
21577 valueT size)
21578{
f0927246
NC
21579#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21580 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21581 {
21582 /* For a.out, force the section size to be aligned. If we don't do
21583 this, BFD will align it for us, but it will not write out the
21584 final bytes of the section. This may be a bug in BFD, but it is
21585 easier to fix it here since that is how the other a.out targets
21586 work. */
21587 int align;
21588
21589 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21590 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21591 }
c19d1205 21592#endif
f0927246 21593
6844c0cc 21594 return size;
bfae80f2 21595}
b99bd4ef 21596
c19d1205
ZW
21597/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21598 of an rs_align_code fragment. */
21599
21600void
21601arm_handle_align (fragS * fragP)
bfae80f2 21602{
d9235011 21603 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21604 {
21605 { /* ARMv1 */
21606 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21607 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21608 },
21609 { /* ARMv6k */
21610 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21611 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21612 },
21613 };
d9235011 21614 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21615 {
21616 { /* Thumb-1 */
21617 {0xc0, 0x46}, /* LE */
21618 {0x46, 0xc0}, /* BE */
21619 },
21620 { /* Thumb-2 */
21621 {0x00, 0xbf}, /* LE */
21622 {0xbf, 0x00} /* BE */
21623 }
21624 };
d9235011 21625 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21626 { /* Wide Thumb-2 */
21627 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21628 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21629 };
c921be7d 21630
e7495e45 21631 unsigned bytes, fix, noop_size;
c19d1205 21632 char * p;
d9235011
TS
21633 const unsigned char * noop;
21634 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21635#ifdef OBJ_ELF
21636 enum mstate state;
21637#endif
bfae80f2 21638
c19d1205 21639 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21640 return;
21641
c19d1205
ZW
21642 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21643 p = fragP->fr_literal + fragP->fr_fix;
21644 fix = 0;
bfae80f2 21645
c19d1205
ZW
21646 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21647 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21648
cd000bff 21649 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21650
cd000bff 21651 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21652 {
7f78eb34
JW
21653 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21654 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21655 {
21656 narrow_noop = thumb_noop[1][target_big_endian];
21657 noop = wide_thumb_noop[target_big_endian];
21658 }
c19d1205 21659 else
e7495e45
NS
21660 noop = thumb_noop[0][target_big_endian];
21661 noop_size = 2;
cd000bff
DJ
21662#ifdef OBJ_ELF
21663 state = MAP_THUMB;
21664#endif
7ed4c4c5
NC
21665 }
21666 else
21667 {
7f78eb34
JW
21668 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21669 ? selected_cpu : arm_arch_none,
21670 arm_ext_v6k) != 0]
e7495e45
NS
21671 [target_big_endian];
21672 noop_size = 4;
cd000bff
DJ
21673#ifdef OBJ_ELF
21674 state = MAP_ARM;
21675#endif
7ed4c4c5 21676 }
c921be7d 21677
e7495e45 21678 fragP->fr_var = noop_size;
c921be7d 21679
c19d1205 21680 if (bytes & (noop_size - 1))
7ed4c4c5 21681 {
c19d1205 21682 fix = bytes & (noop_size - 1);
cd000bff
DJ
21683#ifdef OBJ_ELF
21684 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21685#endif
c19d1205
ZW
21686 memset (p, 0, fix);
21687 p += fix;
21688 bytes -= fix;
a737bd4d 21689 }
a737bd4d 21690
e7495e45
NS
21691 if (narrow_noop)
21692 {
21693 if (bytes & noop_size)
21694 {
21695 /* Insert a narrow noop. */
21696 memcpy (p, narrow_noop, noop_size);
21697 p += noop_size;
21698 bytes -= noop_size;
21699 fix += noop_size;
21700 }
21701
21702 /* Use wide noops for the remainder */
21703 noop_size = 4;
21704 }
21705
c19d1205 21706 while (bytes >= noop_size)
a737bd4d 21707 {
c19d1205
ZW
21708 memcpy (p, noop, noop_size);
21709 p += noop_size;
21710 bytes -= noop_size;
21711 fix += noop_size;
a737bd4d
NC
21712 }
21713
c19d1205 21714 fragP->fr_fix += fix;
a737bd4d
NC
21715}
21716
c19d1205
ZW
21717/* Called from md_do_align. Used to create an alignment
21718 frag in a code section. */
21719
21720void
21721arm_frag_align_code (int n, int max)
bfae80f2 21722{
c19d1205 21723 char * p;
7ed4c4c5 21724
c19d1205 21725 /* We assume that there will never be a requirement
6ec8e702 21726 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21727 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21728 {
21729 char err_msg[128];
21730
fa94de6b 21731 sprintf (err_msg,
477330fc
RM
21732 _("alignments greater than %d bytes not supported in .text sections."),
21733 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21734 as_fatal ("%s", err_msg);
6ec8e702 21735 }
bfae80f2 21736
c19d1205
ZW
21737 p = frag_var (rs_align_code,
21738 MAX_MEM_FOR_RS_ALIGN_CODE,
21739 1,
21740 (relax_substateT) max,
21741 (symbolS *) NULL,
21742 (offsetT) n,
21743 (char *) NULL);
21744 *p = 0;
21745}
bfae80f2 21746
8dc2430f
NC
21747/* Perform target specific initialisation of a frag.
21748 Note - despite the name this initialisation is not done when the frag
21749 is created, but only when its type is assigned. A frag can be created
21750 and used a long time before its type is set, so beware of assuming that
21751 this initialisationis performed first. */
bfae80f2 21752
cd000bff
DJ
21753#ifndef OBJ_ELF
21754void
21755arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21756{
21757 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21758 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21759}
21760
21761#else /* OBJ_ELF is defined. */
c19d1205 21762void
cd000bff 21763arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21764{
b968d18a
JW
21765 int frag_thumb_mode;
21766
8dc2430f
NC
21767 /* If the current ARM vs THUMB mode has not already
21768 been recorded into this frag then do so now. */
cd000bff 21769 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21770 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21771
21772 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21773
f9c1b181
RL
21774 /* Record a mapping symbol for alignment frags. We will delete this
21775 later if the alignment ends up empty. */
21776 switch (fragP->fr_type)
21777 {
21778 case rs_align:
21779 case rs_align_test:
21780 case rs_fill:
21781 mapping_state_2 (MAP_DATA, max_chars);
21782 break;
21783 case rs_align_code:
b968d18a 21784 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21785 break;
21786 default:
21787 break;
cd000bff 21788 }
bfae80f2
RE
21789}
21790
c19d1205
ZW
21791/* When we change sections we need to issue a new mapping symbol. */
21792
21793void
21794arm_elf_change_section (void)
bfae80f2 21795{
c19d1205
ZW
21796 /* Link an unlinked unwind index table section to the .text section. */
21797 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21798 && elf_linked_to_section (now_seg) == NULL)
21799 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21800}
21801
c19d1205
ZW
21802int
21803arm_elf_section_type (const char * str, size_t len)
e45d0630 21804{
c19d1205
ZW
21805 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21806 return SHT_ARM_EXIDX;
e45d0630 21807
c19d1205
ZW
21808 return -1;
21809}
21810\f
21811/* Code to deal with unwinding tables. */
e45d0630 21812
c19d1205 21813static void add_unwind_adjustsp (offsetT);
e45d0630 21814
5f4273c7 21815/* Generate any deferred unwind frame offset. */
e45d0630 21816
bfae80f2 21817static void
c19d1205 21818flush_pending_unwind (void)
bfae80f2 21819{
c19d1205 21820 offsetT offset;
bfae80f2 21821
c19d1205
ZW
21822 offset = unwind.pending_offset;
21823 unwind.pending_offset = 0;
21824 if (offset != 0)
21825 add_unwind_adjustsp (offset);
bfae80f2
RE
21826}
21827
c19d1205
ZW
21828/* Add an opcode to this list for this function. Two-byte opcodes should
21829 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21830 order. */
21831
bfae80f2 21832static void
c19d1205 21833add_unwind_opcode (valueT op, int length)
bfae80f2 21834{
c19d1205
ZW
21835 /* Add any deferred stack adjustment. */
21836 if (unwind.pending_offset)
21837 flush_pending_unwind ();
bfae80f2 21838
c19d1205 21839 unwind.sp_restored = 0;
bfae80f2 21840
c19d1205 21841 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21842 {
c19d1205
ZW
21843 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21844 if (unwind.opcodes)
325801bd
TS
21845 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21846 unwind.opcode_alloc);
c19d1205 21847 else
325801bd 21848 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21849 }
c19d1205 21850 while (length > 0)
bfae80f2 21851 {
c19d1205
ZW
21852 length--;
21853 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21854 op >>= 8;
21855 unwind.opcode_count++;
bfae80f2 21856 }
bfae80f2
RE
21857}
21858
c19d1205
ZW
21859/* Add unwind opcodes to adjust the stack pointer. */
21860
bfae80f2 21861static void
c19d1205 21862add_unwind_adjustsp (offsetT offset)
bfae80f2 21863{
c19d1205 21864 valueT op;
bfae80f2 21865
c19d1205 21866 if (offset > 0x200)
bfae80f2 21867 {
c19d1205
ZW
21868 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21869 char bytes[5];
21870 int n;
21871 valueT o;
bfae80f2 21872
c19d1205
ZW
21873 /* Long form: 0xb2, uleb128. */
21874 /* This might not fit in a word so add the individual bytes,
21875 remembering the list is built in reverse order. */
21876 o = (valueT) ((offset - 0x204) >> 2);
21877 if (o == 0)
21878 add_unwind_opcode (0, 1);
bfae80f2 21879
c19d1205
ZW
21880 /* Calculate the uleb128 encoding of the offset. */
21881 n = 0;
21882 while (o)
21883 {
21884 bytes[n] = o & 0x7f;
21885 o >>= 7;
21886 if (o)
21887 bytes[n] |= 0x80;
21888 n++;
21889 }
21890 /* Add the insn. */
21891 for (; n; n--)
21892 add_unwind_opcode (bytes[n - 1], 1);
21893 add_unwind_opcode (0xb2, 1);
21894 }
21895 else if (offset > 0x100)
bfae80f2 21896 {
c19d1205
ZW
21897 /* Two short opcodes. */
21898 add_unwind_opcode (0x3f, 1);
21899 op = (offset - 0x104) >> 2;
21900 add_unwind_opcode (op, 1);
bfae80f2 21901 }
c19d1205
ZW
21902 else if (offset > 0)
21903 {
21904 /* Short opcode. */
21905 op = (offset - 4) >> 2;
21906 add_unwind_opcode (op, 1);
21907 }
21908 else if (offset < 0)
bfae80f2 21909 {
c19d1205
ZW
21910 offset = -offset;
21911 while (offset > 0x100)
bfae80f2 21912 {
c19d1205
ZW
21913 add_unwind_opcode (0x7f, 1);
21914 offset -= 0x100;
bfae80f2 21915 }
c19d1205
ZW
21916 op = ((offset - 4) >> 2) | 0x40;
21917 add_unwind_opcode (op, 1);
bfae80f2 21918 }
bfae80f2
RE
21919}
21920
c19d1205
ZW
21921/* Finish the list of unwind opcodes for this function. */
21922static void
21923finish_unwind_opcodes (void)
bfae80f2 21924{
c19d1205 21925 valueT op;
bfae80f2 21926
c19d1205 21927 if (unwind.fp_used)
bfae80f2 21928 {
708587a4 21929 /* Adjust sp as necessary. */
c19d1205
ZW
21930 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21931 flush_pending_unwind ();
bfae80f2 21932
c19d1205
ZW
21933 /* After restoring sp from the frame pointer. */
21934 op = 0x90 | unwind.fp_reg;
21935 add_unwind_opcode (op, 1);
21936 }
21937 else
21938 flush_pending_unwind ();
bfae80f2
RE
21939}
21940
bfae80f2 21941
c19d1205
ZW
21942/* Start an exception table entry. If idx is nonzero this is an index table
21943 entry. */
bfae80f2
RE
21944
21945static void
c19d1205 21946start_unwind_section (const segT text_seg, int idx)
bfae80f2 21947{
c19d1205
ZW
21948 const char * text_name;
21949 const char * prefix;
21950 const char * prefix_once;
21951 const char * group_name;
c19d1205 21952 char * sec_name;
c19d1205
ZW
21953 int type;
21954 int flags;
21955 int linkonce;
bfae80f2 21956
c19d1205 21957 if (idx)
bfae80f2 21958 {
c19d1205
ZW
21959 prefix = ELF_STRING_ARM_unwind;
21960 prefix_once = ELF_STRING_ARM_unwind_once;
21961 type = SHT_ARM_EXIDX;
bfae80f2 21962 }
c19d1205 21963 else
bfae80f2 21964 {
c19d1205
ZW
21965 prefix = ELF_STRING_ARM_unwind_info;
21966 prefix_once = ELF_STRING_ARM_unwind_info_once;
21967 type = SHT_PROGBITS;
bfae80f2
RE
21968 }
21969
c19d1205
ZW
21970 text_name = segment_name (text_seg);
21971 if (streq (text_name, ".text"))
21972 text_name = "";
21973
21974 if (strncmp (text_name, ".gnu.linkonce.t.",
21975 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21976 {
c19d1205
ZW
21977 prefix = prefix_once;
21978 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21979 }
21980
29a2809e 21981 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 21982
c19d1205
ZW
21983 flags = SHF_ALLOC;
21984 linkonce = 0;
21985 group_name = 0;
bfae80f2 21986
c19d1205
ZW
21987 /* Handle COMDAT group. */
21988 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21989 {
c19d1205
ZW
21990 group_name = elf_group_name (text_seg);
21991 if (group_name == NULL)
21992 {
bd3ba5d1 21993 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21994 segment_name (text_seg));
21995 ignore_rest_of_line ();
21996 return;
21997 }
21998 flags |= SHF_GROUP;
21999 linkonce = 1;
bfae80f2
RE
22000 }
22001
c19d1205 22002 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 22003
5f4273c7 22004 /* Set the section link for index tables. */
c19d1205
ZW
22005 if (idx)
22006 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22007}
22008
bfae80f2 22009
c19d1205
ZW
22010/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22011 personality routine data. Returns zero, or the index table value for
cad0da33 22012 an inline entry. */
c19d1205
ZW
22013
22014static valueT
22015create_unwind_entry (int have_data)
bfae80f2 22016{
c19d1205
ZW
22017 int size;
22018 addressT where;
22019 char *ptr;
22020 /* The current word of data. */
22021 valueT data;
22022 /* The number of bytes left in this word. */
22023 int n;
bfae80f2 22024
c19d1205 22025 finish_unwind_opcodes ();
bfae80f2 22026
c19d1205
ZW
22027 /* Remember the current text section. */
22028 unwind.saved_seg = now_seg;
22029 unwind.saved_subseg = now_subseg;
bfae80f2 22030
c19d1205 22031 start_unwind_section (now_seg, 0);
bfae80f2 22032
c19d1205 22033 if (unwind.personality_routine == NULL)
bfae80f2 22034 {
c19d1205
ZW
22035 if (unwind.personality_index == -2)
22036 {
22037 if (have_data)
5f4273c7 22038 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22039 return 1; /* EXIDX_CANTUNWIND. */
22040 }
bfae80f2 22041
c19d1205
ZW
22042 /* Use a default personality routine if none is specified. */
22043 if (unwind.personality_index == -1)
22044 {
22045 if (unwind.opcode_count > 3)
22046 unwind.personality_index = 1;
22047 else
22048 unwind.personality_index = 0;
22049 }
bfae80f2 22050
c19d1205
ZW
22051 /* Space for the personality routine entry. */
22052 if (unwind.personality_index == 0)
22053 {
22054 if (unwind.opcode_count > 3)
22055 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22056
c19d1205
ZW
22057 if (!have_data)
22058 {
22059 /* All the data is inline in the index table. */
22060 data = 0x80;
22061 n = 3;
22062 while (unwind.opcode_count > 0)
22063 {
22064 unwind.opcode_count--;
22065 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22066 n--;
22067 }
bfae80f2 22068
c19d1205
ZW
22069 /* Pad with "finish" opcodes. */
22070 while (n--)
22071 data = (data << 8) | 0xb0;
bfae80f2 22072
c19d1205
ZW
22073 return data;
22074 }
22075 size = 0;
22076 }
22077 else
22078 /* We get two opcodes "free" in the first word. */
22079 size = unwind.opcode_count - 2;
22080 }
22081 else
5011093d 22082 {
cad0da33
NC
22083 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22084 if (unwind.personality_index != -1)
22085 {
22086 as_bad (_("attempt to recreate an unwind entry"));
22087 return 1;
22088 }
5011093d
NC
22089
22090 /* An extra byte is required for the opcode count. */
22091 size = unwind.opcode_count + 1;
22092 }
bfae80f2 22093
c19d1205
ZW
22094 size = (size + 3) >> 2;
22095 if (size > 0xff)
22096 as_bad (_("too many unwind opcodes"));
bfae80f2 22097
c19d1205
ZW
22098 frag_align (2, 0, 0);
22099 record_alignment (now_seg, 2);
22100 unwind.table_entry = expr_build_dot ();
22101
22102 /* Allocate the table entry. */
22103 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22104 /* PR 13449: Zero the table entries in case some of them are not used. */
22105 memset (ptr, 0, (size << 2) + 4);
c19d1205 22106 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22107
c19d1205 22108 switch (unwind.personality_index)
bfae80f2 22109 {
c19d1205
ZW
22110 case -1:
22111 /* ??? Should this be a PLT generating relocation? */
22112 /* Custom personality routine. */
22113 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22114 BFD_RELOC_ARM_PREL31);
bfae80f2 22115
c19d1205
ZW
22116 where += 4;
22117 ptr += 4;
bfae80f2 22118
c19d1205 22119 /* Set the first byte to the number of additional words. */
5011093d 22120 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22121 n = 3;
22122 break;
bfae80f2 22123
c19d1205
ZW
22124 /* ABI defined personality routines. */
22125 case 0:
22126 /* Three opcodes bytes are packed into the first word. */
22127 data = 0x80;
22128 n = 3;
22129 break;
bfae80f2 22130
c19d1205
ZW
22131 case 1:
22132 case 2:
22133 /* The size and first two opcode bytes go in the first word. */
22134 data = ((0x80 + unwind.personality_index) << 8) | size;
22135 n = 2;
22136 break;
bfae80f2 22137
c19d1205
ZW
22138 default:
22139 /* Should never happen. */
22140 abort ();
22141 }
bfae80f2 22142
c19d1205
ZW
22143 /* Pack the opcodes into words (MSB first), reversing the list at the same
22144 time. */
22145 while (unwind.opcode_count > 0)
22146 {
22147 if (n == 0)
22148 {
22149 md_number_to_chars (ptr, data, 4);
22150 ptr += 4;
22151 n = 4;
22152 data = 0;
22153 }
22154 unwind.opcode_count--;
22155 n--;
22156 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22157 }
22158
22159 /* Finish off the last word. */
22160 if (n < 4)
22161 {
22162 /* Pad with "finish" opcodes. */
22163 while (n--)
22164 data = (data << 8) | 0xb0;
22165
22166 md_number_to_chars (ptr, data, 4);
22167 }
22168
22169 if (!have_data)
22170 {
22171 /* Add an empty descriptor if there is no user-specified data. */
22172 ptr = frag_more (4);
22173 md_number_to_chars (ptr, 0, 4);
22174 }
22175
22176 return 0;
bfae80f2
RE
22177}
22178
f0927246
NC
22179
22180/* Initialize the DWARF-2 unwind information for this procedure. */
22181
22182void
22183tc_arm_frame_initial_instructions (void)
22184{
22185 cfi_add_CFA_def_cfa (REG_SP, 0);
22186}
22187#endif /* OBJ_ELF */
22188
c19d1205
ZW
22189/* Convert REGNAME to a DWARF-2 register number. */
22190
22191int
1df69f4f 22192tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22193{
1df69f4f 22194 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22195 if (reg != FAIL)
22196 return reg;
c19d1205 22197
1f5afe1c
NC
22198 /* PR 16694: Allow VFP registers as well. */
22199 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22200 if (reg != FAIL)
22201 return 64 + reg;
c19d1205 22202
1f5afe1c
NC
22203 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22204 if (reg != FAIL)
22205 return reg + 256;
22206
22207 return -1;
bfae80f2
RE
22208}
22209
f0927246 22210#ifdef TE_PE
c19d1205 22211void
f0927246 22212tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22213{
91d6fa6a 22214 expressionS exp;
bfae80f2 22215
91d6fa6a
NC
22216 exp.X_op = O_secrel;
22217 exp.X_add_symbol = symbol;
22218 exp.X_add_number = 0;
22219 emit_expr (&exp, size);
f0927246
NC
22220}
22221#endif
bfae80f2 22222
c19d1205 22223/* MD interface: Symbol and relocation handling. */
bfae80f2 22224
2fc8bdac
ZW
22225/* Return the address within the segment that a PC-relative fixup is
22226 relative to. For ARM, PC-relative fixups applied to instructions
22227 are generally relative to the location of the fixup plus 8 bytes.
22228 Thumb branches are offset by 4, and Thumb loads relative to PC
22229 require special handling. */
bfae80f2 22230
c19d1205 22231long
2fc8bdac 22232md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22233{
2fc8bdac
ZW
22234 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22235
22236 /* If this is pc-relative and we are going to emit a relocation
22237 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22238 will need. Otherwise we want to use the calculated base.
22239 For WinCE we skip the bias for externals as well, since this
22240 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22241 if (fixP->fx_pcrel
2fc8bdac 22242 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22243 || (arm_force_relocation (fixP)
22244#ifdef TE_WINCE
22245 && !S_IS_EXTERNAL (fixP->fx_addsy)
22246#endif
22247 )))
2fc8bdac 22248 base = 0;
bfae80f2 22249
267bf995 22250
c19d1205 22251 switch (fixP->fx_r_type)
bfae80f2 22252 {
2fc8bdac
ZW
22253 /* PC relative addressing on the Thumb is slightly odd as the
22254 bottom two bits of the PC are forced to zero for the
22255 calculation. This happens *after* application of the
22256 pipeline offset. However, Thumb adrl already adjusts for
22257 this, so we need not do it again. */
c19d1205 22258 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22259 return base & ~3;
c19d1205
ZW
22260
22261 case BFD_RELOC_ARM_THUMB_OFFSET:
22262 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22263 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22264 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22265 return (base + 4) & ~3;
c19d1205 22266
2fc8bdac
ZW
22267 /* Thumb branches are simply offset by +4. */
22268 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22269 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22270 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22271 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22272 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22273 return base + 4;
bfae80f2 22274
267bf995 22275 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22276 if (fixP->fx_addsy
22277 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22278 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22279 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22280 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22281 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22282 return base + 4;
22283
00adf2d4
JB
22284 /* BLX is like branches above, but forces the low two bits of PC to
22285 zero. */
486499d0
CL
22286 case BFD_RELOC_THUMB_PCREL_BLX:
22287 if (fixP->fx_addsy
22288 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22289 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22290 && THUMB_IS_FUNC (fixP->fx_addsy)
22291 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22292 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22293 return (base + 4) & ~3;
22294
2fc8bdac
ZW
22295 /* ARM mode branches are offset by +8. However, the Windows CE
22296 loader expects the relocation not to take this into account. */
267bf995 22297 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22298 if (fixP->fx_addsy
22299 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22300 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22301 && ARM_IS_FUNC (fixP->fx_addsy)
22302 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22303 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22304 return base + 8;
267bf995 22305
486499d0
CL
22306 case BFD_RELOC_ARM_PCREL_CALL:
22307 if (fixP->fx_addsy
22308 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22309 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22310 && THUMB_IS_FUNC (fixP->fx_addsy)
22311 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22312 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22313 return base + 8;
267bf995 22314
2fc8bdac 22315 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22316 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22317 case BFD_RELOC_ARM_PLT32:
c19d1205 22318#ifdef TE_WINCE
5f4273c7 22319 /* When handling fixups immediately, because we have already
477330fc 22320 discovered the value of a symbol, or the address of the frag involved
53baae48 22321 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22322 see fixup_segment() in write.c
22323 The S_IS_EXTERNAL test handles the case of global symbols.
22324 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22325 if (fixP->fx_pcrel
22326 && fixP->fx_addsy != NULL
22327 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22328 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22329 return base + 8;
2fc8bdac 22330 return base;
c19d1205 22331#else
2fc8bdac 22332 return base + 8;
c19d1205 22333#endif
2fc8bdac 22334
267bf995 22335
2fc8bdac
ZW
22336 /* ARM mode loads relative to PC are also offset by +8. Unlike
22337 branches, the Windows CE loader *does* expect the relocation
22338 to take this into account. */
22339 case BFD_RELOC_ARM_OFFSET_IMM:
22340 case BFD_RELOC_ARM_OFFSET_IMM8:
22341 case BFD_RELOC_ARM_HWLITERAL:
22342 case BFD_RELOC_ARM_LITERAL:
22343 case BFD_RELOC_ARM_CP_OFF_IMM:
22344 return base + 8;
22345
22346
22347 /* Other PC-relative relocations are un-offset. */
22348 default:
22349 return base;
22350 }
bfae80f2
RE
22351}
22352
8b2d793c
NC
22353static bfd_boolean flag_warn_syms = TRUE;
22354
ae8714c2
NC
22355bfd_boolean
22356arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22357{
8b2d793c
NC
22358 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22359 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22360 does mean that the resulting code might be very confusing to the reader.
22361 Also this warning can be triggered if the user omits an operand before
22362 an immediate address, eg:
22363
22364 LDR =foo
22365
22366 GAS treats this as an assignment of the value of the symbol foo to a
22367 symbol LDR, and so (without this code) it will not issue any kind of
22368 warning or error message.
22369
22370 Note - ARM instructions are case-insensitive but the strings in the hash
22371 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22372 lower case too. */
22373 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22374 {
22375 char * nbuf = strdup (name);
22376 char * p;
22377
22378 for (p = nbuf; *p; p++)
22379 *p = TOLOWER (*p);
22380 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22381 {
22382 static struct hash_control * already_warned = NULL;
22383
22384 if (already_warned == NULL)
22385 already_warned = hash_new ();
22386 /* Only warn about the symbol once. To keep the code
22387 simple we let hash_insert do the lookup for us. */
22388 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22389 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22390 }
22391 else
22392 free (nbuf);
22393 }
3739860c 22394
ae8714c2
NC
22395 return FALSE;
22396}
22397
22398/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22399 Otherwise we have no need to default values of symbols. */
22400
22401symbolS *
22402md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22403{
22404#ifdef OBJ_ELF
22405 if (name[0] == '_' && name[1] == 'G'
22406 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22407 {
22408 if (!GOT_symbol)
22409 {
22410 if (symbol_find (name))
22411 as_bad (_("GOT already in the symbol table"));
22412
22413 GOT_symbol = symbol_new (name, undefined_section,
22414 (valueT) 0, & zero_address_frag);
22415 }
22416
22417 return GOT_symbol;
22418 }
22419#endif
22420
c921be7d 22421 return NULL;
bfae80f2
RE
22422}
22423
55cf6793 22424/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22425 computed as two separate immediate values, added together. We
22426 already know that this value cannot be computed by just one ARM
22427 instruction. */
22428
22429static unsigned int
22430validate_immediate_twopart (unsigned int val,
22431 unsigned int * highpart)
bfae80f2 22432{
c19d1205
ZW
22433 unsigned int a;
22434 unsigned int i;
bfae80f2 22435
c19d1205
ZW
22436 for (i = 0; i < 32; i += 2)
22437 if (((a = rotate_left (val, i)) & 0xff) != 0)
22438 {
22439 if (a & 0xff00)
22440 {
22441 if (a & ~ 0xffff)
22442 continue;
22443 * highpart = (a >> 8) | ((i + 24) << 7);
22444 }
22445 else if (a & 0xff0000)
22446 {
22447 if (a & 0xff000000)
22448 continue;
22449 * highpart = (a >> 16) | ((i + 16) << 7);
22450 }
22451 else
22452 {
9c2799c2 22453 gas_assert (a & 0xff000000);
c19d1205
ZW
22454 * highpart = (a >> 24) | ((i + 8) << 7);
22455 }
bfae80f2 22456
c19d1205
ZW
22457 return (a & 0xff) | (i << 7);
22458 }
bfae80f2 22459
c19d1205 22460 return FAIL;
bfae80f2
RE
22461}
22462
c19d1205
ZW
22463static int
22464validate_offset_imm (unsigned int val, int hwse)
22465{
22466 if ((hwse && val > 255) || val > 4095)
22467 return FAIL;
22468 return val;
22469}
bfae80f2 22470
55cf6793 22471/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22472 negative immediate constant by altering the instruction. A bit of
22473 a hack really.
22474 MOV <-> MVN
22475 AND <-> BIC
22476 ADC <-> SBC
22477 by inverting the second operand, and
22478 ADD <-> SUB
22479 CMP <-> CMN
22480 by negating the second operand. */
bfae80f2 22481
c19d1205
ZW
22482static int
22483negate_data_op (unsigned long * instruction,
22484 unsigned long value)
bfae80f2 22485{
c19d1205
ZW
22486 int op, new_inst;
22487 unsigned long negated, inverted;
bfae80f2 22488
c19d1205
ZW
22489 negated = encode_arm_immediate (-value);
22490 inverted = encode_arm_immediate (~value);
bfae80f2 22491
c19d1205
ZW
22492 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22493 switch (op)
bfae80f2 22494 {
c19d1205
ZW
22495 /* First negates. */
22496 case OPCODE_SUB: /* ADD <-> SUB */
22497 new_inst = OPCODE_ADD;
22498 value = negated;
22499 break;
bfae80f2 22500
c19d1205
ZW
22501 case OPCODE_ADD:
22502 new_inst = OPCODE_SUB;
22503 value = negated;
22504 break;
bfae80f2 22505
c19d1205
ZW
22506 case OPCODE_CMP: /* CMP <-> CMN */
22507 new_inst = OPCODE_CMN;
22508 value = negated;
22509 break;
bfae80f2 22510
c19d1205
ZW
22511 case OPCODE_CMN:
22512 new_inst = OPCODE_CMP;
22513 value = negated;
22514 break;
bfae80f2 22515
c19d1205
ZW
22516 /* Now Inverted ops. */
22517 case OPCODE_MOV: /* MOV <-> MVN */
22518 new_inst = OPCODE_MVN;
22519 value = inverted;
22520 break;
bfae80f2 22521
c19d1205
ZW
22522 case OPCODE_MVN:
22523 new_inst = OPCODE_MOV;
22524 value = inverted;
22525 break;
bfae80f2 22526
c19d1205
ZW
22527 case OPCODE_AND: /* AND <-> BIC */
22528 new_inst = OPCODE_BIC;
22529 value = inverted;
22530 break;
bfae80f2 22531
c19d1205
ZW
22532 case OPCODE_BIC:
22533 new_inst = OPCODE_AND;
22534 value = inverted;
22535 break;
bfae80f2 22536
c19d1205
ZW
22537 case OPCODE_ADC: /* ADC <-> SBC */
22538 new_inst = OPCODE_SBC;
22539 value = inverted;
22540 break;
bfae80f2 22541
c19d1205
ZW
22542 case OPCODE_SBC:
22543 new_inst = OPCODE_ADC;
22544 value = inverted;
22545 break;
bfae80f2 22546
c19d1205
ZW
22547 /* We cannot do anything. */
22548 default:
22549 return FAIL;
b99bd4ef
NC
22550 }
22551
c19d1205
ZW
22552 if (value == (unsigned) FAIL)
22553 return FAIL;
22554
22555 *instruction &= OPCODE_MASK;
22556 *instruction |= new_inst << DATA_OP_SHIFT;
22557 return value;
b99bd4ef
NC
22558}
22559
ef8d22e6
PB
22560/* Like negate_data_op, but for Thumb-2. */
22561
22562static unsigned int
16dd5e42 22563thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22564{
22565 int op, new_inst;
22566 int rd;
16dd5e42 22567 unsigned int negated, inverted;
ef8d22e6
PB
22568
22569 negated = encode_thumb32_immediate (-value);
22570 inverted = encode_thumb32_immediate (~value);
22571
22572 rd = (*instruction >> 8) & 0xf;
22573 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22574 switch (op)
22575 {
22576 /* ADD <-> SUB. Includes CMP <-> CMN. */
22577 case T2_OPCODE_SUB:
22578 new_inst = T2_OPCODE_ADD;
22579 value = negated;
22580 break;
22581
22582 case T2_OPCODE_ADD:
22583 new_inst = T2_OPCODE_SUB;
22584 value = negated;
22585 break;
22586
22587 /* ORR <-> ORN. Includes MOV <-> MVN. */
22588 case T2_OPCODE_ORR:
22589 new_inst = T2_OPCODE_ORN;
22590 value = inverted;
22591 break;
22592
22593 case T2_OPCODE_ORN:
22594 new_inst = T2_OPCODE_ORR;
22595 value = inverted;
22596 break;
22597
22598 /* AND <-> BIC. TST has no inverted equivalent. */
22599 case T2_OPCODE_AND:
22600 new_inst = T2_OPCODE_BIC;
22601 if (rd == 15)
22602 value = FAIL;
22603 else
22604 value = inverted;
22605 break;
22606
22607 case T2_OPCODE_BIC:
22608 new_inst = T2_OPCODE_AND;
22609 value = inverted;
22610 break;
22611
22612 /* ADC <-> SBC */
22613 case T2_OPCODE_ADC:
22614 new_inst = T2_OPCODE_SBC;
22615 value = inverted;
22616 break;
22617
22618 case T2_OPCODE_SBC:
22619 new_inst = T2_OPCODE_ADC;
22620 value = inverted;
22621 break;
22622
22623 /* We cannot do anything. */
22624 default:
22625 return FAIL;
22626 }
22627
16dd5e42 22628 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22629 return FAIL;
22630
22631 *instruction &= T2_OPCODE_MASK;
22632 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22633 return value;
22634}
22635
8f06b2d8
PB
22636/* Read a 32-bit thumb instruction from buf. */
22637static unsigned long
22638get_thumb32_insn (char * buf)
22639{
22640 unsigned long insn;
22641 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22642 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22643
22644 return insn;
22645}
22646
a8bc6c78
PB
22647
22648/* We usually want to set the low bit on the address of thumb function
22649 symbols. In particular .word foo - . should have the low bit set.
22650 Generic code tries to fold the difference of two symbols to
22651 a constant. Prevent this and force a relocation when the first symbols
22652 is a thumb function. */
c921be7d
NC
22653
22654bfd_boolean
a8bc6c78
PB
22655arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22656{
22657 if (op == O_subtract
22658 && l->X_op == O_symbol
22659 && r->X_op == O_symbol
22660 && THUMB_IS_FUNC (l->X_add_symbol))
22661 {
22662 l->X_op = O_subtract;
22663 l->X_op_symbol = r->X_add_symbol;
22664 l->X_add_number -= r->X_add_number;
c921be7d 22665 return TRUE;
a8bc6c78 22666 }
c921be7d 22667
a8bc6c78 22668 /* Process as normal. */
c921be7d 22669 return FALSE;
a8bc6c78
PB
22670}
22671
4a42ebbc
RR
22672/* Encode Thumb2 unconditional branches and calls. The encoding
22673 for the 2 are identical for the immediate values. */
22674
22675static void
22676encode_thumb2_b_bl_offset (char * buf, offsetT value)
22677{
22678#define T2I1I2MASK ((1 << 13) | (1 << 11))
22679 offsetT newval;
22680 offsetT newval2;
22681 addressT S, I1, I2, lo, hi;
22682
22683 S = (value >> 24) & 0x01;
22684 I1 = (value >> 23) & 0x01;
22685 I2 = (value >> 22) & 0x01;
22686 hi = (value >> 12) & 0x3ff;
fa94de6b 22687 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22688 newval = md_chars_to_number (buf, THUMB_SIZE);
22689 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22690 newval |= (S << 10) | hi;
22691 newval2 &= ~T2I1I2MASK;
22692 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22693 md_number_to_chars (buf, newval, THUMB_SIZE);
22694 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22695}
22696
c19d1205 22697void
55cf6793 22698md_apply_fix (fixS * fixP,
c19d1205
ZW
22699 valueT * valP,
22700 segT seg)
22701{
22702 offsetT value = * valP;
22703 offsetT newval;
22704 unsigned int newimm;
22705 unsigned long temp;
22706 int sign;
22707 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22708
9c2799c2 22709 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22710
c19d1205 22711 /* Note whether this will delete the relocation. */
4962c51a 22712
c19d1205
ZW
22713 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22714 fixP->fx_done = 1;
b99bd4ef 22715
adbaf948 22716 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22717 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22718 for emit_reloc. */
22719 value &= 0xffffffff;
22720 value ^= 0x80000000;
5f4273c7 22721 value -= 0x80000000;
adbaf948
ZW
22722
22723 *valP = value;
c19d1205 22724 fixP->fx_addnumber = value;
b99bd4ef 22725
adbaf948
ZW
22726 /* Same treatment for fixP->fx_offset. */
22727 fixP->fx_offset &= 0xffffffff;
22728 fixP->fx_offset ^= 0x80000000;
22729 fixP->fx_offset -= 0x80000000;
22730
c19d1205 22731 switch (fixP->fx_r_type)
b99bd4ef 22732 {
c19d1205
ZW
22733 case BFD_RELOC_NONE:
22734 /* This will need to go in the object file. */
22735 fixP->fx_done = 0;
22736 break;
b99bd4ef 22737
c19d1205
ZW
22738 case BFD_RELOC_ARM_IMMEDIATE:
22739 /* We claim that this fixup has been processed here,
22740 even if in fact we generate an error because we do
22741 not have a reloc for it, so tc_gen_reloc will reject it. */
22742 fixP->fx_done = 1;
b99bd4ef 22743
77db8e2e 22744 if (fixP->fx_addsy)
b99bd4ef 22745 {
77db8e2e 22746 const char *msg = 0;
b99bd4ef 22747
77db8e2e
NC
22748 if (! S_IS_DEFINED (fixP->fx_addsy))
22749 msg = _("undefined symbol %s used as an immediate value");
22750 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22751 msg = _("symbol %s is in a different section");
22752 else if (S_IS_WEAK (fixP->fx_addsy))
22753 msg = _("symbol %s is weak and may be overridden later");
22754
22755 if (msg)
22756 {
22757 as_bad_where (fixP->fx_file, fixP->fx_line,
22758 msg, S_GET_NAME (fixP->fx_addsy));
22759 break;
22760 }
42e5fcbf
AS
22761 }
22762
c19d1205
ZW
22763 temp = md_chars_to_number (buf, INSN_SIZE);
22764
5e73442d
SL
22765 /* If the offset is negative, we should use encoding A2 for ADR. */
22766 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22767 newimm = negate_data_op (&temp, value);
22768 else
22769 {
22770 newimm = encode_arm_immediate (value);
22771
22772 /* If the instruction will fail, see if we can fix things up by
22773 changing the opcode. */
22774 if (newimm == (unsigned int) FAIL)
22775 newimm = negate_data_op (&temp, value);
22776 }
22777
22778 if (newimm == (unsigned int) FAIL)
b99bd4ef 22779 {
c19d1205
ZW
22780 as_bad_where (fixP->fx_file, fixP->fx_line,
22781 _("invalid constant (%lx) after fixup"),
22782 (unsigned long) value);
22783 break;
b99bd4ef 22784 }
b99bd4ef 22785
c19d1205
ZW
22786 newimm |= (temp & 0xfffff000);
22787 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22788 break;
b99bd4ef 22789
c19d1205
ZW
22790 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22791 {
22792 unsigned int highpart = 0;
22793 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22794
77db8e2e 22795 if (fixP->fx_addsy)
42e5fcbf 22796 {
77db8e2e 22797 const char *msg = 0;
42e5fcbf 22798
77db8e2e
NC
22799 if (! S_IS_DEFINED (fixP->fx_addsy))
22800 msg = _("undefined symbol %s used as an immediate value");
22801 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22802 msg = _("symbol %s is in a different section");
22803 else if (S_IS_WEAK (fixP->fx_addsy))
22804 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22805
77db8e2e
NC
22806 if (msg)
22807 {
22808 as_bad_where (fixP->fx_file, fixP->fx_line,
22809 msg, S_GET_NAME (fixP->fx_addsy));
22810 break;
22811 }
22812 }
fa94de6b 22813
c19d1205
ZW
22814 newimm = encode_arm_immediate (value);
22815 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22816
c19d1205
ZW
22817 /* If the instruction will fail, see if we can fix things up by
22818 changing the opcode. */
22819 if (newimm == (unsigned int) FAIL
22820 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22821 {
22822 /* No ? OK - try using two ADD instructions to generate
22823 the value. */
22824 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22825
c19d1205
ZW
22826 /* Yes - then make sure that the second instruction is
22827 also an add. */
22828 if (newimm != (unsigned int) FAIL)
22829 newinsn = temp;
22830 /* Still No ? Try using a negated value. */
22831 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22832 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22833 /* Otherwise - give up. */
22834 else
22835 {
22836 as_bad_where (fixP->fx_file, fixP->fx_line,
22837 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22838 (long) value);
22839 break;
22840 }
b99bd4ef 22841
c19d1205
ZW
22842 /* Replace the first operand in the 2nd instruction (which
22843 is the PC) with the destination register. We have
22844 already added in the PC in the first instruction and we
22845 do not want to do it again. */
22846 newinsn &= ~ 0xf0000;
22847 newinsn |= ((newinsn & 0x0f000) << 4);
22848 }
b99bd4ef 22849
c19d1205
ZW
22850 newimm |= (temp & 0xfffff000);
22851 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22852
c19d1205
ZW
22853 highpart |= (newinsn & 0xfffff000);
22854 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22855 }
22856 break;
b99bd4ef 22857
c19d1205 22858 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22859 if (!fixP->fx_done && seg->use_rela_p)
22860 value = 0;
1a0670f3 22861 /* Fall through. */
00a97672 22862
c19d1205 22863 case BFD_RELOC_ARM_LITERAL:
26d97720 22864 sign = value > 0;
b99bd4ef 22865
c19d1205
ZW
22866 if (value < 0)
22867 value = - value;
b99bd4ef 22868
c19d1205 22869 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22870 {
c19d1205
ZW
22871 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22872 as_bad_where (fixP->fx_file, fixP->fx_line,
22873 _("invalid literal constant: pool needs to be closer"));
22874 else
22875 as_bad_where (fixP->fx_file, fixP->fx_line,
22876 _("bad immediate value for offset (%ld)"),
22877 (long) value);
22878 break;
f03698e6
RE
22879 }
22880
c19d1205 22881 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22882 if (value == 0)
22883 newval &= 0xfffff000;
22884 else
22885 {
22886 newval &= 0xff7ff000;
22887 newval |= value | (sign ? INDEX_UP : 0);
22888 }
c19d1205
ZW
22889 md_number_to_chars (buf, newval, INSN_SIZE);
22890 break;
b99bd4ef 22891
c19d1205
ZW
22892 case BFD_RELOC_ARM_OFFSET_IMM8:
22893 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22894 sign = value > 0;
b99bd4ef 22895
c19d1205
ZW
22896 if (value < 0)
22897 value = - value;
b99bd4ef 22898
c19d1205 22899 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22900 {
c19d1205
ZW
22901 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22902 as_bad_where (fixP->fx_file, fixP->fx_line,
22903 _("invalid literal constant: pool needs to be closer"));
22904 else
427d0db6
RM
22905 as_bad_where (fixP->fx_file, fixP->fx_line,
22906 _("bad immediate value for 8-bit offset (%ld)"),
22907 (long) value);
c19d1205 22908 break;
b99bd4ef
NC
22909 }
22910
c19d1205 22911 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22912 if (value == 0)
22913 newval &= 0xfffff0f0;
22914 else
22915 {
22916 newval &= 0xff7ff0f0;
22917 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22918 }
c19d1205
ZW
22919 md_number_to_chars (buf, newval, INSN_SIZE);
22920 break;
b99bd4ef 22921
c19d1205
ZW
22922 case BFD_RELOC_ARM_T32_OFFSET_U8:
22923 if (value < 0 || value > 1020 || value % 4 != 0)
22924 as_bad_where (fixP->fx_file, fixP->fx_line,
22925 _("bad immediate value for offset (%ld)"), (long) value);
22926 value /= 4;
b99bd4ef 22927
c19d1205 22928 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22929 newval |= value;
22930 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22931 break;
b99bd4ef 22932
c19d1205
ZW
22933 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22934 /* This is a complicated relocation used for all varieties of Thumb32
22935 load/store instruction with immediate offset:
22936
22937 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22938 *4, optional writeback(W)
c19d1205
ZW
22939 (doubleword load/store)
22940
22941 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22942 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22943 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22944 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22945 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22946
22947 Uppercase letters indicate bits that are already encoded at
22948 this point. Lowercase letters are our problem. For the
22949 second block of instructions, the secondary opcode nybble
22950 (bits 8..11) is present, and bit 23 is zero, even if this is
22951 a PC-relative operation. */
22952 newval = md_chars_to_number (buf, THUMB_SIZE);
22953 newval <<= 16;
22954 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22955
c19d1205 22956 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22957 {
c19d1205
ZW
22958 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22959 if (value >= 0)
22960 newval |= (1 << 23);
22961 else
22962 value = -value;
22963 if (value % 4 != 0)
22964 {
22965 as_bad_where (fixP->fx_file, fixP->fx_line,
22966 _("offset not a multiple of 4"));
22967 break;
22968 }
22969 value /= 4;
216d22bc 22970 if (value > 0xff)
c19d1205
ZW
22971 {
22972 as_bad_where (fixP->fx_file, fixP->fx_line,
22973 _("offset out of range"));
22974 break;
22975 }
22976 newval &= ~0xff;
b99bd4ef 22977 }
c19d1205 22978 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22979 {
c19d1205
ZW
22980 /* PC-relative, 12-bit offset. */
22981 if (value >= 0)
22982 newval |= (1 << 23);
22983 else
22984 value = -value;
216d22bc 22985 if (value > 0xfff)
c19d1205
ZW
22986 {
22987 as_bad_where (fixP->fx_file, fixP->fx_line,
22988 _("offset out of range"));
22989 break;
22990 }
22991 newval &= ~0xfff;
b99bd4ef 22992 }
c19d1205 22993 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22994 {
c19d1205
ZW
22995 /* Writeback: 8-bit, +/- offset. */
22996 if (value >= 0)
22997 newval |= (1 << 9);
22998 else
22999 value = -value;
216d22bc 23000 if (value > 0xff)
c19d1205
ZW
23001 {
23002 as_bad_where (fixP->fx_file, fixP->fx_line,
23003 _("offset out of range"));
23004 break;
23005 }
23006 newval &= ~0xff;
b99bd4ef 23007 }
c19d1205 23008 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23009 {
c19d1205 23010 /* T-instruction: positive 8-bit offset. */
216d22bc 23011 if (value < 0 || value > 0xff)
b99bd4ef 23012 {
c19d1205
ZW
23013 as_bad_where (fixP->fx_file, fixP->fx_line,
23014 _("offset out of range"));
23015 break;
b99bd4ef 23016 }
c19d1205
ZW
23017 newval &= ~0xff;
23018 newval |= value;
b99bd4ef
NC
23019 }
23020 else
b99bd4ef 23021 {
c19d1205
ZW
23022 /* Positive 12-bit or negative 8-bit offset. */
23023 int limit;
23024 if (value >= 0)
b99bd4ef 23025 {
c19d1205
ZW
23026 newval |= (1 << 23);
23027 limit = 0xfff;
23028 }
23029 else
23030 {
23031 value = -value;
23032 limit = 0xff;
23033 }
23034 if (value > limit)
23035 {
23036 as_bad_where (fixP->fx_file, fixP->fx_line,
23037 _("offset out of range"));
23038 break;
b99bd4ef 23039 }
c19d1205 23040 newval &= ~limit;
b99bd4ef 23041 }
b99bd4ef 23042
c19d1205
ZW
23043 newval |= value;
23044 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23045 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23046 break;
404ff6b5 23047
c19d1205
ZW
23048 case BFD_RELOC_ARM_SHIFT_IMM:
23049 newval = md_chars_to_number (buf, INSN_SIZE);
23050 if (((unsigned long) value) > 32
23051 || (value == 32
23052 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23053 {
23054 as_bad_where (fixP->fx_file, fixP->fx_line,
23055 _("shift expression is too large"));
23056 break;
23057 }
404ff6b5 23058
c19d1205
ZW
23059 if (value == 0)
23060 /* Shifts of zero must be done as lsl. */
23061 newval &= ~0x60;
23062 else if (value == 32)
23063 value = 0;
23064 newval &= 0xfffff07f;
23065 newval |= (value & 0x1f) << 7;
23066 md_number_to_chars (buf, newval, INSN_SIZE);
23067 break;
404ff6b5 23068
c19d1205 23069 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23070 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23071 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23072 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23073 /* We claim that this fixup has been processed here,
23074 even if in fact we generate an error because we do
23075 not have a reloc for it, so tc_gen_reloc will reject it. */
23076 fixP->fx_done = 1;
404ff6b5 23077
c19d1205
ZW
23078 if (fixP->fx_addsy
23079 && ! S_IS_DEFINED (fixP->fx_addsy))
23080 {
23081 as_bad_where (fixP->fx_file, fixP->fx_line,
23082 _("undefined symbol %s used as an immediate value"),
23083 S_GET_NAME (fixP->fx_addsy));
23084 break;
23085 }
404ff6b5 23086
c19d1205
ZW
23087 newval = md_chars_to_number (buf, THUMB_SIZE);
23088 newval <<= 16;
23089 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23090
16805f35
PB
23091 newimm = FAIL;
23092 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23093 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23094 {
23095 newimm = encode_thumb32_immediate (value);
23096 if (newimm == (unsigned int) FAIL)
23097 newimm = thumb32_negate_data_op (&newval, value);
23098 }
16805f35
PB
23099 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
23100 && newimm == (unsigned int) FAIL)
92e90b6e 23101 {
16805f35
PB
23102 /* Turn add/sum into addw/subw. */
23103 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23104 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
23105 /* No flat 12-bit imm encoding for addsw/subsw. */
23106 if ((newval & 0x00100000) == 0)
e9f89963 23107 {
40f246e3
NC
23108 /* 12 bit immediate for addw/subw. */
23109 if (value < 0)
23110 {
23111 value = -value;
23112 newval ^= 0x00a00000;
23113 }
23114 if (value > 0xfff)
23115 newimm = (unsigned int) FAIL;
23116 else
23117 newimm = value;
e9f89963 23118 }
92e90b6e 23119 }
cc8a6dd0 23120
c19d1205 23121 if (newimm == (unsigned int)FAIL)
3631a3c8 23122 {
c19d1205
ZW
23123 as_bad_where (fixP->fx_file, fixP->fx_line,
23124 _("invalid constant (%lx) after fixup"),
23125 (unsigned long) value);
23126 break;
3631a3c8
NC
23127 }
23128
c19d1205
ZW
23129 newval |= (newimm & 0x800) << 15;
23130 newval |= (newimm & 0x700) << 4;
23131 newval |= (newimm & 0x0ff);
cc8a6dd0 23132
c19d1205
ZW
23133 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23134 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23135 break;
a737bd4d 23136
3eb17e6b 23137 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23138 if (((unsigned long) value) > 0xffff)
23139 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23140 _("invalid smc expression"));
2fc8bdac 23141 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23142 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23143 md_number_to_chars (buf, newval, INSN_SIZE);
23144 break;
a737bd4d 23145
90ec0d68
MGD
23146 case BFD_RELOC_ARM_HVC:
23147 if (((unsigned long) value) > 0xffff)
23148 as_bad_where (fixP->fx_file, fixP->fx_line,
23149 _("invalid hvc expression"));
23150 newval = md_chars_to_number (buf, INSN_SIZE);
23151 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23152 md_number_to_chars (buf, newval, INSN_SIZE);
23153 break;
23154
c19d1205 23155 case BFD_RELOC_ARM_SWI:
adbaf948 23156 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23157 {
23158 if (((unsigned long) value) > 0xff)
23159 as_bad_where (fixP->fx_file, fixP->fx_line,
23160 _("invalid swi expression"));
2fc8bdac 23161 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23162 newval |= value;
23163 md_number_to_chars (buf, newval, THUMB_SIZE);
23164 }
23165 else
23166 {
23167 if (((unsigned long) value) > 0x00ffffff)
23168 as_bad_where (fixP->fx_file, fixP->fx_line,
23169 _("invalid swi expression"));
2fc8bdac 23170 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23171 newval |= value;
23172 md_number_to_chars (buf, newval, INSN_SIZE);
23173 }
23174 break;
a737bd4d 23175
c19d1205
ZW
23176 case BFD_RELOC_ARM_MULTI:
23177 if (((unsigned long) value) > 0xffff)
23178 as_bad_where (fixP->fx_file, fixP->fx_line,
23179 _("invalid expression in load/store multiple"));
23180 newval = value | md_chars_to_number (buf, INSN_SIZE);
23181 md_number_to_chars (buf, newval, INSN_SIZE);
23182 break;
a737bd4d 23183
c19d1205 23184#ifdef OBJ_ELF
39b41c9c 23185 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23186
23187 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23188 && fixP->fx_addsy
34e77a92 23189 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23190 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23191 && THUMB_IS_FUNC (fixP->fx_addsy))
23192 /* Flip the bl to blx. This is a simple flip
23193 bit here because we generate PCREL_CALL for
23194 unconditional bls. */
23195 {
23196 newval = md_chars_to_number (buf, INSN_SIZE);
23197 newval = newval | 0x10000000;
23198 md_number_to_chars (buf, newval, INSN_SIZE);
23199 temp = 1;
23200 fixP->fx_done = 1;
23201 }
39b41c9c
PB
23202 else
23203 temp = 3;
23204 goto arm_branch_common;
23205
23206 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23207 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23208 && fixP->fx_addsy
34e77a92 23209 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23210 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23211 && THUMB_IS_FUNC (fixP->fx_addsy))
23212 {
23213 /* This would map to a bl<cond>, b<cond>,
23214 b<always> to a Thumb function. We
23215 need to force a relocation for this particular
23216 case. */
23217 newval = md_chars_to_number (buf, INSN_SIZE);
23218 fixP->fx_done = 0;
23219 }
1a0670f3 23220 /* Fall through. */
267bf995 23221
2fc8bdac 23222 case BFD_RELOC_ARM_PLT32:
c19d1205 23223#endif
39b41c9c
PB
23224 case BFD_RELOC_ARM_PCREL_BRANCH:
23225 temp = 3;
23226 goto arm_branch_common;
a737bd4d 23227
39b41c9c 23228 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23229
39b41c9c 23230 temp = 1;
267bf995
RR
23231 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23232 && fixP->fx_addsy
34e77a92 23233 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23234 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23235 && ARM_IS_FUNC (fixP->fx_addsy))
23236 {
23237 /* Flip the blx to a bl and warn. */
23238 const char *name = S_GET_NAME (fixP->fx_addsy);
23239 newval = 0xeb000000;
23240 as_warn_where (fixP->fx_file, fixP->fx_line,
23241 _("blx to '%s' an ARM ISA state function changed to bl"),
23242 name);
23243 md_number_to_chars (buf, newval, INSN_SIZE);
23244 temp = 3;
23245 fixP->fx_done = 1;
23246 }
23247
23248#ifdef OBJ_ELF
23249 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23250 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23251#endif
23252
39b41c9c 23253 arm_branch_common:
c19d1205 23254 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23255 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23256 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23257 also be be clear. */
23258 if (value & temp)
c19d1205 23259 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23260 _("misaligned branch destination"));
23261 if ((value & (offsetT)0xfe000000) != (offsetT)0
23262 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23263 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23264
2fc8bdac 23265 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23266 {
2fc8bdac
ZW
23267 newval = md_chars_to_number (buf, INSN_SIZE);
23268 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23269 /* Set the H bit on BLX instructions. */
23270 if (temp == 1)
23271 {
23272 if (value & 2)
23273 newval |= 0x01000000;
23274 else
23275 newval &= ~0x01000000;
23276 }
2fc8bdac 23277 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23278 }
c19d1205 23279 break;
a737bd4d 23280
25fe350b
MS
23281 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23282 /* CBZ can only branch forward. */
a737bd4d 23283
738755b0 23284 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23285 (which, strictly speaking, are prohibited) will be turned into
23286 no-ops.
738755b0
MS
23287
23288 FIXME: It may be better to remove the instruction completely and
23289 perform relaxation. */
23290 if (value == -2)
2fc8bdac
ZW
23291 {
23292 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23293 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23294 md_number_to_chars (buf, newval, THUMB_SIZE);
23295 }
738755b0
MS
23296 else
23297 {
23298 if (value & ~0x7e)
08f10d51 23299 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23300
477330fc 23301 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23302 {
23303 newval = md_chars_to_number (buf, THUMB_SIZE);
23304 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23305 md_number_to_chars (buf, newval, THUMB_SIZE);
23306 }
23307 }
c19d1205 23308 break;
a737bd4d 23309
c19d1205 23310 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23311 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23312 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23313
2fc8bdac
ZW
23314 if (fixP->fx_done || !seg->use_rela_p)
23315 {
23316 newval = md_chars_to_number (buf, THUMB_SIZE);
23317 newval |= (value & 0x1ff) >> 1;
23318 md_number_to_chars (buf, newval, THUMB_SIZE);
23319 }
c19d1205 23320 break;
a737bd4d 23321
c19d1205 23322 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23323 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23324 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23325
2fc8bdac
ZW
23326 if (fixP->fx_done || !seg->use_rela_p)
23327 {
23328 newval = md_chars_to_number (buf, THUMB_SIZE);
23329 newval |= (value & 0xfff) >> 1;
23330 md_number_to_chars (buf, newval, THUMB_SIZE);
23331 }
c19d1205 23332 break;
a737bd4d 23333
c19d1205 23334 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23335 if (fixP->fx_addsy
23336 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23337 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23338 && ARM_IS_FUNC (fixP->fx_addsy)
23339 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23340 {
23341 /* Force a relocation for a branch 20 bits wide. */
23342 fixP->fx_done = 0;
23343 }
08f10d51 23344 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23345 as_bad_where (fixP->fx_file, fixP->fx_line,
23346 _("conditional branch out of range"));
404ff6b5 23347
2fc8bdac
ZW
23348 if (fixP->fx_done || !seg->use_rela_p)
23349 {
23350 offsetT newval2;
23351 addressT S, J1, J2, lo, hi;
404ff6b5 23352
2fc8bdac
ZW
23353 S = (value & 0x00100000) >> 20;
23354 J2 = (value & 0x00080000) >> 19;
23355 J1 = (value & 0x00040000) >> 18;
23356 hi = (value & 0x0003f000) >> 12;
23357 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23358
2fc8bdac
ZW
23359 newval = md_chars_to_number (buf, THUMB_SIZE);
23360 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23361 newval |= (S << 10) | hi;
23362 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23363 md_number_to_chars (buf, newval, THUMB_SIZE);
23364 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23365 }
c19d1205 23366 break;
6c43fab6 23367
c19d1205 23368 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23369 /* If there is a blx from a thumb state function to
23370 another thumb function flip this to a bl and warn
23371 about it. */
23372
23373 if (fixP->fx_addsy
34e77a92 23374 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23375 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23376 && THUMB_IS_FUNC (fixP->fx_addsy))
23377 {
23378 const char *name = S_GET_NAME (fixP->fx_addsy);
23379 as_warn_where (fixP->fx_file, fixP->fx_line,
23380 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23381 name);
23382 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23383 newval = newval | 0x1000;
23384 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23385 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23386 fixP->fx_done = 1;
23387 }
23388
23389
23390 goto thumb_bl_common;
23391
c19d1205 23392 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23393 /* A bl from Thumb state ISA to an internal ARM state function
23394 is converted to a blx. */
23395 if (fixP->fx_addsy
23396 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23397 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23398 && ARM_IS_FUNC (fixP->fx_addsy)
23399 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23400 {
23401 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23402 newval = newval & ~0x1000;
23403 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23404 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23405 fixP->fx_done = 1;
23406 }
23407
23408 thumb_bl_common:
23409
2fc8bdac
ZW
23410 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23411 /* For a BLX instruction, make sure that the relocation is rounded up
23412 to a word boundary. This follows the semantics of the instruction
23413 which specifies that bit 1 of the target address will come from bit
23414 1 of the base address. */
d406f3e4
JB
23415 value = (value + 3) & ~ 3;
23416
23417#ifdef OBJ_ELF
23418 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23419 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23420 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23421#endif
404ff6b5 23422
2b2f5df9
NC
23423 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23424 {
fc289b0a 23425 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23426 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23427 else if ((value & ~0x1ffffff)
23428 && ((value & ~0x1ffffff) != ~0x1ffffff))
23429 as_bad_where (fixP->fx_file, fixP->fx_line,
23430 _("Thumb2 branch out of range"));
23431 }
4a42ebbc
RR
23432
23433 if (fixP->fx_done || !seg->use_rela_p)
23434 encode_thumb2_b_bl_offset (buf, value);
23435
c19d1205 23436 break;
404ff6b5 23437
c19d1205 23438 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23439 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23440 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23441
2fc8bdac 23442 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23443 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23444
2fc8bdac 23445 break;
a737bd4d 23446
2fc8bdac
ZW
23447 case BFD_RELOC_8:
23448 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23449 *buf = value;
c19d1205 23450 break;
a737bd4d 23451
c19d1205 23452 case BFD_RELOC_16:
2fc8bdac 23453 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23454 md_number_to_chars (buf, value, 2);
c19d1205 23455 break;
a737bd4d 23456
c19d1205 23457#ifdef OBJ_ELF
0855e32b
NS
23458 case BFD_RELOC_ARM_TLS_CALL:
23459 case BFD_RELOC_ARM_THM_TLS_CALL:
23460 case BFD_RELOC_ARM_TLS_DESCSEQ:
23461 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23462 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23463 case BFD_RELOC_ARM_TLS_GD32:
23464 case BFD_RELOC_ARM_TLS_LE32:
23465 case BFD_RELOC_ARM_TLS_IE32:
23466 case BFD_RELOC_ARM_TLS_LDM32:
23467 case BFD_RELOC_ARM_TLS_LDO32:
23468 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23469 break;
6c43fab6 23470
c19d1205
ZW
23471 case BFD_RELOC_ARM_GOT32:
23472 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23473 break;
b43420e6
NC
23474
23475 case BFD_RELOC_ARM_GOT_PREL:
23476 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23477 md_number_to_chars (buf, value, 4);
b43420e6
NC
23478 break;
23479
9a6f4e97
NS
23480 case BFD_RELOC_ARM_TARGET2:
23481 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23482 addend here for REL targets, because it won't be written out
23483 during reloc processing later. */
9a6f4e97
NS
23484 if (fixP->fx_done || !seg->use_rela_p)
23485 md_number_to_chars (buf, fixP->fx_offset, 4);
23486 break;
c19d1205 23487#endif
6c43fab6 23488
c19d1205
ZW
23489 case BFD_RELOC_RVA:
23490 case BFD_RELOC_32:
23491 case BFD_RELOC_ARM_TARGET1:
23492 case BFD_RELOC_ARM_ROSEGREL32:
23493 case BFD_RELOC_ARM_SBREL32:
23494 case BFD_RELOC_32_PCREL:
f0927246
NC
23495#ifdef TE_PE
23496 case BFD_RELOC_32_SECREL:
23497#endif
2fc8bdac 23498 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23499#ifdef TE_WINCE
23500 /* For WinCE we only do this for pcrel fixups. */
23501 if (fixP->fx_done || fixP->fx_pcrel)
23502#endif
23503 md_number_to_chars (buf, value, 4);
c19d1205 23504 break;
6c43fab6 23505
c19d1205
ZW
23506#ifdef OBJ_ELF
23507 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23508 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23509 {
23510 newval = md_chars_to_number (buf, 4) & 0x80000000;
23511 if ((value ^ (value >> 1)) & 0x40000000)
23512 {
23513 as_bad_where (fixP->fx_file, fixP->fx_line,
23514 _("rel31 relocation overflow"));
23515 }
23516 newval |= value & 0x7fffffff;
23517 md_number_to_chars (buf, newval, 4);
23518 }
23519 break;
c19d1205 23520#endif
a737bd4d 23521
c19d1205 23522 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23523 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23524 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23525 newval = md_chars_to_number (buf, INSN_SIZE);
23526 else
23527 newval = get_thumb32_insn (buf);
23528 if ((newval & 0x0f200f00) == 0x0d000900)
23529 {
23530 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23531 has permitted values that are multiples of 2, in the range 0
23532 to 510. */
23533 if (value < -510 || value > 510 || (value & 1))
23534 as_bad_where (fixP->fx_file, fixP->fx_line,
23535 _("co-processor offset out of range"));
23536 }
23537 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23538 as_bad_where (fixP->fx_file, fixP->fx_line,
23539 _("co-processor offset out of range"));
23540 cp_off_common:
26d97720 23541 sign = value > 0;
c19d1205
ZW
23542 if (value < 0)
23543 value = -value;
8f06b2d8
PB
23544 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23545 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23546 newval = md_chars_to_number (buf, INSN_SIZE);
23547 else
23548 newval = get_thumb32_insn (buf);
26d97720
NS
23549 if (value == 0)
23550 newval &= 0xffffff00;
23551 else
23552 {
23553 newval &= 0xff7fff00;
9db2f6b4
RL
23554 if ((newval & 0x0f200f00) == 0x0d000900)
23555 {
23556 /* This is a fp16 vstr/vldr.
23557
23558 It requires the immediate offset in the instruction is shifted
23559 left by 1 to be a half-word offset.
23560
23561 Here, left shift by 1 first, and later right shift by 2
23562 should get the right offset. */
23563 value <<= 1;
23564 }
26d97720
NS
23565 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23566 }
8f06b2d8
PB
23567 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23568 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23569 md_number_to_chars (buf, newval, INSN_SIZE);
23570 else
23571 put_thumb32_insn (buf, newval);
c19d1205 23572 break;
a737bd4d 23573
c19d1205 23574 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23575 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23576 if (value < -255 || value > 255)
23577 as_bad_where (fixP->fx_file, fixP->fx_line,
23578 _("co-processor offset out of range"));
df7849c5 23579 value *= 4;
c19d1205 23580 goto cp_off_common;
6c43fab6 23581
c19d1205
ZW
23582 case BFD_RELOC_ARM_THUMB_OFFSET:
23583 newval = md_chars_to_number (buf, THUMB_SIZE);
23584 /* Exactly what ranges, and where the offset is inserted depends
23585 on the type of instruction, we can establish this from the
23586 top 4 bits. */
23587 switch (newval >> 12)
23588 {
23589 case 4: /* PC load. */
23590 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23591 forced to zero for these loads; md_pcrel_from has already
23592 compensated for this. */
23593 if (value & 3)
23594 as_bad_where (fixP->fx_file, fixP->fx_line,
23595 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23596 (((unsigned long) fixP->fx_frag->fr_address
23597 + (unsigned long) fixP->fx_where) & ~3)
23598 + (unsigned long) value);
a737bd4d 23599
c19d1205
ZW
23600 if (value & ~0x3fc)
23601 as_bad_where (fixP->fx_file, fixP->fx_line,
23602 _("invalid offset, value too big (0x%08lX)"),
23603 (long) value);
a737bd4d 23604
c19d1205
ZW
23605 newval |= value >> 2;
23606 break;
a737bd4d 23607
c19d1205
ZW
23608 case 9: /* SP load/store. */
23609 if (value & ~0x3fc)
23610 as_bad_where (fixP->fx_file, fixP->fx_line,
23611 _("invalid offset, value too big (0x%08lX)"),
23612 (long) value);
23613 newval |= value >> 2;
23614 break;
6c43fab6 23615
c19d1205
ZW
23616 case 6: /* Word load/store. */
23617 if (value & ~0x7c)
23618 as_bad_where (fixP->fx_file, fixP->fx_line,
23619 _("invalid offset, value too big (0x%08lX)"),
23620 (long) value);
23621 newval |= value << 4; /* 6 - 2. */
23622 break;
a737bd4d 23623
c19d1205
ZW
23624 case 7: /* Byte load/store. */
23625 if (value & ~0x1f)
23626 as_bad_where (fixP->fx_file, fixP->fx_line,
23627 _("invalid offset, value too big (0x%08lX)"),
23628 (long) value);
23629 newval |= value << 6;
23630 break;
a737bd4d 23631
c19d1205
ZW
23632 case 8: /* Halfword load/store. */
23633 if (value & ~0x3e)
23634 as_bad_where (fixP->fx_file, fixP->fx_line,
23635 _("invalid offset, value too big (0x%08lX)"),
23636 (long) value);
23637 newval |= value << 5; /* 6 - 1. */
23638 break;
a737bd4d 23639
c19d1205
ZW
23640 default:
23641 as_bad_where (fixP->fx_file, fixP->fx_line,
23642 "Unable to process relocation for thumb opcode: %lx",
23643 (unsigned long) newval);
23644 break;
23645 }
23646 md_number_to_chars (buf, newval, THUMB_SIZE);
23647 break;
a737bd4d 23648
c19d1205
ZW
23649 case BFD_RELOC_ARM_THUMB_ADD:
23650 /* This is a complicated relocation, since we use it for all of
23651 the following immediate relocations:
a737bd4d 23652
c19d1205
ZW
23653 3bit ADD/SUB
23654 8bit ADD/SUB
23655 9bit ADD/SUB SP word-aligned
23656 10bit ADD PC/SP word-aligned
a737bd4d 23657
c19d1205
ZW
23658 The type of instruction being processed is encoded in the
23659 instruction field:
a737bd4d 23660
c19d1205
ZW
23661 0x8000 SUB
23662 0x00F0 Rd
23663 0x000F Rs
23664 */
23665 newval = md_chars_to_number (buf, THUMB_SIZE);
23666 {
23667 int rd = (newval >> 4) & 0xf;
23668 int rs = newval & 0xf;
23669 int subtract = !!(newval & 0x8000);
a737bd4d 23670
c19d1205
ZW
23671 /* Check for HI regs, only very restricted cases allowed:
23672 Adjusting SP, and using PC or SP to get an address. */
23673 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23674 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23675 as_bad_where (fixP->fx_file, fixP->fx_line,
23676 _("invalid Hi register with immediate"));
a737bd4d 23677
c19d1205
ZW
23678 /* If value is negative, choose the opposite instruction. */
23679 if (value < 0)
23680 {
23681 value = -value;
23682 subtract = !subtract;
23683 if (value < 0)
23684 as_bad_where (fixP->fx_file, fixP->fx_line,
23685 _("immediate value out of range"));
23686 }
a737bd4d 23687
c19d1205
ZW
23688 if (rd == REG_SP)
23689 {
75c11999 23690 if (value & ~0x1fc)
c19d1205
ZW
23691 as_bad_where (fixP->fx_file, fixP->fx_line,
23692 _("invalid immediate for stack address calculation"));
23693 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23694 newval |= value >> 2;
23695 }
23696 else if (rs == REG_PC || rs == REG_SP)
23697 {
c12d2c9d
NC
23698 /* PR gas/18541. If the addition is for a defined symbol
23699 within range of an ADR instruction then accept it. */
23700 if (subtract
23701 && value == 4
23702 && fixP->fx_addsy != NULL)
23703 {
23704 subtract = 0;
23705
23706 if (! S_IS_DEFINED (fixP->fx_addsy)
23707 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23708 || S_IS_WEAK (fixP->fx_addsy))
23709 {
23710 as_bad_where (fixP->fx_file, fixP->fx_line,
23711 _("address calculation needs a strongly defined nearby symbol"));
23712 }
23713 else
23714 {
23715 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23716
23717 /* Round up to the next 4-byte boundary. */
23718 if (v & 3)
23719 v = (v + 3) & ~ 3;
23720 else
23721 v += 4;
23722 v = S_GET_VALUE (fixP->fx_addsy) - v;
23723
23724 if (v & ~0x3fc)
23725 {
23726 as_bad_where (fixP->fx_file, fixP->fx_line,
23727 _("symbol too far away"));
23728 }
23729 else
23730 {
23731 fixP->fx_done = 1;
23732 value = v;
23733 }
23734 }
23735 }
23736
c19d1205
ZW
23737 if (subtract || value & ~0x3fc)
23738 as_bad_where (fixP->fx_file, fixP->fx_line,
23739 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23740 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23741 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23742 newval |= rd << 8;
23743 newval |= value >> 2;
23744 }
23745 else if (rs == rd)
23746 {
23747 if (value & ~0xff)
23748 as_bad_where (fixP->fx_file, fixP->fx_line,
23749 _("immediate value out of range"));
23750 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23751 newval |= (rd << 8) | value;
23752 }
23753 else
23754 {
23755 if (value & ~0x7)
23756 as_bad_where (fixP->fx_file, fixP->fx_line,
23757 _("immediate value out of range"));
23758 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23759 newval |= rd | (rs << 3) | (value << 6);
23760 }
23761 }
23762 md_number_to_chars (buf, newval, THUMB_SIZE);
23763 break;
a737bd4d 23764
c19d1205
ZW
23765 case BFD_RELOC_ARM_THUMB_IMM:
23766 newval = md_chars_to_number (buf, THUMB_SIZE);
23767 if (value < 0 || value > 255)
23768 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23769 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23770 (long) value);
23771 newval |= value;
23772 md_number_to_chars (buf, newval, THUMB_SIZE);
23773 break;
a737bd4d 23774
c19d1205
ZW
23775 case BFD_RELOC_ARM_THUMB_SHIFT:
23776 /* 5bit shift value (0..32). LSL cannot take 32. */
23777 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23778 temp = newval & 0xf800;
23779 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23780 as_bad_where (fixP->fx_file, fixP->fx_line,
23781 _("invalid shift value: %ld"), (long) value);
23782 /* Shifts of zero must be encoded as LSL. */
23783 if (value == 0)
23784 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23785 /* Shifts of 32 are encoded as zero. */
23786 else if (value == 32)
23787 value = 0;
23788 newval |= value << 6;
23789 md_number_to_chars (buf, newval, THUMB_SIZE);
23790 break;
a737bd4d 23791
c19d1205
ZW
23792 case BFD_RELOC_VTABLE_INHERIT:
23793 case BFD_RELOC_VTABLE_ENTRY:
23794 fixP->fx_done = 0;
23795 return;
6c43fab6 23796
b6895b4f
PB
23797 case BFD_RELOC_ARM_MOVW:
23798 case BFD_RELOC_ARM_MOVT:
23799 case BFD_RELOC_ARM_THUMB_MOVW:
23800 case BFD_RELOC_ARM_THUMB_MOVT:
23801 if (fixP->fx_done || !seg->use_rela_p)
23802 {
23803 /* REL format relocations are limited to a 16-bit addend. */
23804 if (!fixP->fx_done)
23805 {
39623e12 23806 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23807 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23808 _("offset out of range"));
b6895b4f
PB
23809 }
23810 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23811 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23812 {
23813 value >>= 16;
23814 }
23815
23816 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23817 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23818 {
23819 newval = get_thumb32_insn (buf);
23820 newval &= 0xfbf08f00;
23821 newval |= (value & 0xf000) << 4;
23822 newval |= (value & 0x0800) << 15;
23823 newval |= (value & 0x0700) << 4;
23824 newval |= (value & 0x00ff);
23825 put_thumb32_insn (buf, newval);
23826 }
23827 else
23828 {
23829 newval = md_chars_to_number (buf, 4);
23830 newval &= 0xfff0f000;
23831 newval |= value & 0x0fff;
23832 newval |= (value & 0xf000) << 4;
23833 md_number_to_chars (buf, newval, 4);
23834 }
23835 }
23836 return;
23837
72d98d16
MG
23838 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23839 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23840 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23841 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23842 gas_assert (!fixP->fx_done);
23843 {
23844 bfd_vma insn;
23845 bfd_boolean is_mov;
23846 bfd_vma encoded_addend = value;
23847
23848 /* Check that addend can be encoded in instruction. */
23849 if (!seg->use_rela_p && (value < 0 || value > 255))
23850 as_bad_where (fixP->fx_file, fixP->fx_line,
23851 _("the offset 0x%08lX is not representable"),
23852 (unsigned long) encoded_addend);
23853
23854 /* Extract the instruction. */
23855 insn = md_chars_to_number (buf, THUMB_SIZE);
23856 is_mov = (insn & 0xf800) == 0x2000;
23857
23858 /* Encode insn. */
23859 if (is_mov)
23860 {
23861 if (!seg->use_rela_p)
23862 insn |= encoded_addend;
23863 }
23864 else
23865 {
23866 int rd, rs;
23867
23868 /* Extract the instruction. */
23869 /* Encoding is the following
23870 0x8000 SUB
23871 0x00F0 Rd
23872 0x000F Rs
23873 */
23874 /* The following conditions must be true :
23875 - ADD
23876 - Rd == Rs
23877 - Rd <= 7
23878 */
23879 rd = (insn >> 4) & 0xf;
23880 rs = insn & 0xf;
23881 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23882 as_bad_where (fixP->fx_file, fixP->fx_line,
23883 _("Unable to process relocation for thumb opcode: %lx"),
23884 (unsigned long) insn);
23885
23886 /* Encode as ADD immediate8 thumb 1 code. */
23887 insn = 0x3000 | (rd << 8);
23888
23889 /* Place the encoded addend into the first 8 bits of the
23890 instruction. */
23891 if (!seg->use_rela_p)
23892 insn |= encoded_addend;
23893 }
23894
23895 /* Update the instruction. */
23896 md_number_to_chars (buf, insn, THUMB_SIZE);
23897 }
23898 break;
23899
4962c51a
MS
23900 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23901 case BFD_RELOC_ARM_ALU_PC_G0:
23902 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23903 case BFD_RELOC_ARM_ALU_PC_G1:
23904 case BFD_RELOC_ARM_ALU_PC_G2:
23905 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23906 case BFD_RELOC_ARM_ALU_SB_G0:
23907 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23908 case BFD_RELOC_ARM_ALU_SB_G1:
23909 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23910 gas_assert (!fixP->fx_done);
4962c51a
MS
23911 if (!seg->use_rela_p)
23912 {
477330fc
RM
23913 bfd_vma insn;
23914 bfd_vma encoded_addend;
23915 bfd_vma addend_abs = abs (value);
23916
23917 /* Check that the absolute value of the addend can be
23918 expressed as an 8-bit constant plus a rotation. */
23919 encoded_addend = encode_arm_immediate (addend_abs);
23920 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23921 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23922 _("the offset 0x%08lX is not representable"),
23923 (unsigned long) addend_abs);
23924
23925 /* Extract the instruction. */
23926 insn = md_chars_to_number (buf, INSN_SIZE);
23927
23928 /* If the addend is positive, use an ADD instruction.
23929 Otherwise use a SUB. Take care not to destroy the S bit. */
23930 insn &= 0xff1fffff;
23931 if (value < 0)
23932 insn |= 1 << 22;
23933 else
23934 insn |= 1 << 23;
23935
23936 /* Place the encoded addend into the first 12 bits of the
23937 instruction. */
23938 insn &= 0xfffff000;
23939 insn |= encoded_addend;
23940
23941 /* Update the instruction. */
23942 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23943 }
23944 break;
23945
23946 case BFD_RELOC_ARM_LDR_PC_G0:
23947 case BFD_RELOC_ARM_LDR_PC_G1:
23948 case BFD_RELOC_ARM_LDR_PC_G2:
23949 case BFD_RELOC_ARM_LDR_SB_G0:
23950 case BFD_RELOC_ARM_LDR_SB_G1:
23951 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23952 gas_assert (!fixP->fx_done);
4962c51a 23953 if (!seg->use_rela_p)
477330fc
RM
23954 {
23955 bfd_vma insn;
23956 bfd_vma addend_abs = abs (value);
4962c51a 23957
477330fc
RM
23958 /* Check that the absolute value of the addend can be
23959 encoded in 12 bits. */
23960 if (addend_abs >= 0x1000)
4962c51a 23961 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23962 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23963 (unsigned long) addend_abs);
23964
23965 /* Extract the instruction. */
23966 insn = md_chars_to_number (buf, INSN_SIZE);
23967
23968 /* If the addend is negative, clear bit 23 of the instruction.
23969 Otherwise set it. */
23970 if (value < 0)
23971 insn &= ~(1 << 23);
23972 else
23973 insn |= 1 << 23;
23974
23975 /* Place the absolute value of the addend into the first 12 bits
23976 of the instruction. */
23977 insn &= 0xfffff000;
23978 insn |= addend_abs;
23979
23980 /* Update the instruction. */
23981 md_number_to_chars (buf, insn, INSN_SIZE);
23982 }
4962c51a
MS
23983 break;
23984
23985 case BFD_RELOC_ARM_LDRS_PC_G0:
23986 case BFD_RELOC_ARM_LDRS_PC_G1:
23987 case BFD_RELOC_ARM_LDRS_PC_G2:
23988 case BFD_RELOC_ARM_LDRS_SB_G0:
23989 case BFD_RELOC_ARM_LDRS_SB_G1:
23990 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23991 gas_assert (!fixP->fx_done);
4962c51a 23992 if (!seg->use_rela_p)
477330fc
RM
23993 {
23994 bfd_vma insn;
23995 bfd_vma addend_abs = abs (value);
4962c51a 23996
477330fc
RM
23997 /* Check that the absolute value of the addend can be
23998 encoded in 8 bits. */
23999 if (addend_abs >= 0x100)
4962c51a 24000 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24001 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24002 (unsigned long) addend_abs);
24003
24004 /* Extract the instruction. */
24005 insn = md_chars_to_number (buf, INSN_SIZE);
24006
24007 /* If the addend is negative, clear bit 23 of the instruction.
24008 Otherwise set it. */
24009 if (value < 0)
24010 insn &= ~(1 << 23);
24011 else
24012 insn |= 1 << 23;
24013
24014 /* Place the first four bits of the absolute value of the addend
24015 into the first 4 bits of the instruction, and the remaining
24016 four into bits 8 .. 11. */
24017 insn &= 0xfffff0f0;
24018 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24019
24020 /* Update the instruction. */
24021 md_number_to_chars (buf, insn, INSN_SIZE);
24022 }
4962c51a
MS
24023 break;
24024
24025 case BFD_RELOC_ARM_LDC_PC_G0:
24026 case BFD_RELOC_ARM_LDC_PC_G1:
24027 case BFD_RELOC_ARM_LDC_PC_G2:
24028 case BFD_RELOC_ARM_LDC_SB_G0:
24029 case BFD_RELOC_ARM_LDC_SB_G1:
24030 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24031 gas_assert (!fixP->fx_done);
4962c51a 24032 if (!seg->use_rela_p)
477330fc
RM
24033 {
24034 bfd_vma insn;
24035 bfd_vma addend_abs = abs (value);
4962c51a 24036
477330fc
RM
24037 /* Check that the absolute value of the addend is a multiple of
24038 four and, when divided by four, fits in 8 bits. */
24039 if (addend_abs & 0x3)
4962c51a 24040 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24041 _("bad offset 0x%08lX (must be word-aligned)"),
24042 (unsigned long) addend_abs);
4962c51a 24043
477330fc 24044 if ((addend_abs >> 2) > 0xff)
4962c51a 24045 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24046 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24047 (unsigned long) addend_abs);
24048
24049 /* Extract the instruction. */
24050 insn = md_chars_to_number (buf, INSN_SIZE);
24051
24052 /* If the addend is negative, clear bit 23 of the instruction.
24053 Otherwise set it. */
24054 if (value < 0)
24055 insn &= ~(1 << 23);
24056 else
24057 insn |= 1 << 23;
24058
24059 /* Place the addend (divided by four) into the first eight
24060 bits of the instruction. */
24061 insn &= 0xfffffff0;
24062 insn |= addend_abs >> 2;
24063
24064 /* Update the instruction. */
24065 md_number_to_chars (buf, insn, INSN_SIZE);
24066 }
4962c51a
MS
24067 break;
24068
845b51d6
PB
24069 case BFD_RELOC_ARM_V4BX:
24070 /* This will need to go in the object file. */
24071 fixP->fx_done = 0;
24072 break;
24073
c19d1205
ZW
24074 case BFD_RELOC_UNUSED:
24075 default:
24076 as_bad_where (fixP->fx_file, fixP->fx_line,
24077 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24078 }
6c43fab6
RE
24079}
24080
c19d1205
ZW
24081/* Translate internal representation of relocation info to BFD target
24082 format. */
a737bd4d 24083
c19d1205 24084arelent *
00a97672 24085tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24086{
c19d1205
ZW
24087 arelent * reloc;
24088 bfd_reloc_code_real_type code;
a737bd4d 24089
325801bd 24090 reloc = XNEW (arelent);
a737bd4d 24091
325801bd 24092 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24093 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24094 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24095
2fc8bdac 24096 if (fixp->fx_pcrel)
00a97672
RS
24097 {
24098 if (section->use_rela_p)
24099 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24100 else
24101 fixp->fx_offset = reloc->address;
24102 }
c19d1205 24103 reloc->addend = fixp->fx_offset;
a737bd4d 24104
c19d1205 24105 switch (fixp->fx_r_type)
a737bd4d 24106 {
c19d1205
ZW
24107 case BFD_RELOC_8:
24108 if (fixp->fx_pcrel)
24109 {
24110 code = BFD_RELOC_8_PCREL;
24111 break;
24112 }
1a0670f3 24113 /* Fall through. */
a737bd4d 24114
c19d1205
ZW
24115 case BFD_RELOC_16:
24116 if (fixp->fx_pcrel)
24117 {
24118 code = BFD_RELOC_16_PCREL;
24119 break;
24120 }
1a0670f3 24121 /* Fall through. */
6c43fab6 24122
c19d1205
ZW
24123 case BFD_RELOC_32:
24124 if (fixp->fx_pcrel)
24125 {
24126 code = BFD_RELOC_32_PCREL;
24127 break;
24128 }
1a0670f3 24129 /* Fall through. */
a737bd4d 24130
b6895b4f
PB
24131 case BFD_RELOC_ARM_MOVW:
24132 if (fixp->fx_pcrel)
24133 {
24134 code = BFD_RELOC_ARM_MOVW_PCREL;
24135 break;
24136 }
1a0670f3 24137 /* Fall through. */
b6895b4f
PB
24138
24139 case BFD_RELOC_ARM_MOVT:
24140 if (fixp->fx_pcrel)
24141 {
24142 code = BFD_RELOC_ARM_MOVT_PCREL;
24143 break;
24144 }
1a0670f3 24145 /* Fall through. */
b6895b4f
PB
24146
24147 case BFD_RELOC_ARM_THUMB_MOVW:
24148 if (fixp->fx_pcrel)
24149 {
24150 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24151 break;
24152 }
1a0670f3 24153 /* Fall through. */
b6895b4f
PB
24154
24155 case BFD_RELOC_ARM_THUMB_MOVT:
24156 if (fixp->fx_pcrel)
24157 {
24158 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24159 break;
24160 }
1a0670f3 24161 /* Fall through. */
b6895b4f 24162
c19d1205
ZW
24163 case BFD_RELOC_NONE:
24164 case BFD_RELOC_ARM_PCREL_BRANCH:
24165 case BFD_RELOC_ARM_PCREL_BLX:
24166 case BFD_RELOC_RVA:
24167 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24168 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24169 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24170 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24171 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24172 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24173 case BFD_RELOC_VTABLE_ENTRY:
24174 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24175#ifdef TE_PE
24176 case BFD_RELOC_32_SECREL:
24177#endif
c19d1205
ZW
24178 code = fixp->fx_r_type;
24179 break;
a737bd4d 24180
00adf2d4
JB
24181 case BFD_RELOC_THUMB_PCREL_BLX:
24182#ifdef OBJ_ELF
24183 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24184 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24185 else
24186#endif
24187 code = BFD_RELOC_THUMB_PCREL_BLX;
24188 break;
24189
c19d1205
ZW
24190 case BFD_RELOC_ARM_LITERAL:
24191 case BFD_RELOC_ARM_HWLITERAL:
24192 /* If this is called then the a literal has
24193 been referenced across a section boundary. */
24194 as_bad_where (fixp->fx_file, fixp->fx_line,
24195 _("literal referenced across section boundary"));
24196 return NULL;
a737bd4d 24197
c19d1205 24198#ifdef OBJ_ELF
0855e32b
NS
24199 case BFD_RELOC_ARM_TLS_CALL:
24200 case BFD_RELOC_ARM_THM_TLS_CALL:
24201 case BFD_RELOC_ARM_TLS_DESCSEQ:
24202 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24203 case BFD_RELOC_ARM_GOT32:
24204 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24205 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24206 case BFD_RELOC_ARM_PLT32:
24207 case BFD_RELOC_ARM_TARGET1:
24208 case BFD_RELOC_ARM_ROSEGREL32:
24209 case BFD_RELOC_ARM_SBREL32:
24210 case BFD_RELOC_ARM_PREL31:
24211 case BFD_RELOC_ARM_TARGET2:
c19d1205 24212 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24213 case BFD_RELOC_ARM_PCREL_CALL:
24214 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24215 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24216 case BFD_RELOC_ARM_ALU_PC_G0:
24217 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24218 case BFD_RELOC_ARM_ALU_PC_G1:
24219 case BFD_RELOC_ARM_ALU_PC_G2:
24220 case BFD_RELOC_ARM_LDR_PC_G0:
24221 case BFD_RELOC_ARM_LDR_PC_G1:
24222 case BFD_RELOC_ARM_LDR_PC_G2:
24223 case BFD_RELOC_ARM_LDRS_PC_G0:
24224 case BFD_RELOC_ARM_LDRS_PC_G1:
24225 case BFD_RELOC_ARM_LDRS_PC_G2:
24226 case BFD_RELOC_ARM_LDC_PC_G0:
24227 case BFD_RELOC_ARM_LDC_PC_G1:
24228 case BFD_RELOC_ARM_LDC_PC_G2:
24229 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24230 case BFD_RELOC_ARM_ALU_SB_G0:
24231 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24232 case BFD_RELOC_ARM_ALU_SB_G1:
24233 case BFD_RELOC_ARM_ALU_SB_G2:
24234 case BFD_RELOC_ARM_LDR_SB_G0:
24235 case BFD_RELOC_ARM_LDR_SB_G1:
24236 case BFD_RELOC_ARM_LDR_SB_G2:
24237 case BFD_RELOC_ARM_LDRS_SB_G0:
24238 case BFD_RELOC_ARM_LDRS_SB_G1:
24239 case BFD_RELOC_ARM_LDRS_SB_G2:
24240 case BFD_RELOC_ARM_LDC_SB_G0:
24241 case BFD_RELOC_ARM_LDC_SB_G1:
24242 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24243 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24244 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24245 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24246 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24247 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24248 code = fixp->fx_r_type;
24249 break;
a737bd4d 24250
0855e32b 24251 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24252 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24253 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24254 case BFD_RELOC_ARM_TLS_IE32:
24255 case BFD_RELOC_ARM_TLS_LDM32:
24256 /* BFD will include the symbol's address in the addend.
24257 But we don't want that, so subtract it out again here. */
24258 if (!S_IS_COMMON (fixp->fx_addsy))
24259 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24260 code = fixp->fx_r_type;
24261 break;
24262#endif
a737bd4d 24263
c19d1205
ZW
24264 case BFD_RELOC_ARM_IMMEDIATE:
24265 as_bad_where (fixp->fx_file, fixp->fx_line,
24266 _("internal relocation (type: IMMEDIATE) not fixed up"));
24267 return NULL;
a737bd4d 24268
c19d1205
ZW
24269 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24270 as_bad_where (fixp->fx_file, fixp->fx_line,
24271 _("ADRL used for a symbol not defined in the same file"));
24272 return NULL;
a737bd4d 24273
c19d1205 24274 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24275 if (section->use_rela_p)
24276 {
24277 code = fixp->fx_r_type;
24278 break;
24279 }
24280
c19d1205
ZW
24281 if (fixp->fx_addsy != NULL
24282 && !S_IS_DEFINED (fixp->fx_addsy)
24283 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24284 {
c19d1205
ZW
24285 as_bad_where (fixp->fx_file, fixp->fx_line,
24286 _("undefined local label `%s'"),
24287 S_GET_NAME (fixp->fx_addsy));
24288 return NULL;
a737bd4d
NC
24289 }
24290
c19d1205
ZW
24291 as_bad_where (fixp->fx_file, fixp->fx_line,
24292 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24293 return NULL;
a737bd4d 24294
c19d1205
ZW
24295 default:
24296 {
e0471c16 24297 const char * type;
6c43fab6 24298
c19d1205
ZW
24299 switch (fixp->fx_r_type)
24300 {
24301 case BFD_RELOC_NONE: type = "NONE"; break;
24302 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24303 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24304 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24305 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24306 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24307 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24308 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24309 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24310 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24311 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24312 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24313 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24314 default: type = _("<unknown>"); break;
24315 }
24316 as_bad_where (fixp->fx_file, fixp->fx_line,
24317 _("cannot represent %s relocation in this object file format"),
24318 type);
24319 return NULL;
24320 }
a737bd4d 24321 }
6c43fab6 24322
c19d1205
ZW
24323#ifdef OBJ_ELF
24324 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24325 && GOT_symbol
24326 && fixp->fx_addsy == GOT_symbol)
24327 {
24328 code = BFD_RELOC_ARM_GOTPC;
24329 reloc->addend = fixp->fx_offset = reloc->address;
24330 }
24331#endif
6c43fab6 24332
c19d1205 24333 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24334
c19d1205
ZW
24335 if (reloc->howto == NULL)
24336 {
24337 as_bad_where (fixp->fx_file, fixp->fx_line,
24338 _("cannot represent %s relocation in this object file format"),
24339 bfd_get_reloc_code_name (code));
24340 return NULL;
24341 }
6c43fab6 24342
c19d1205
ZW
24343 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24344 vtable entry to be used in the relocation's section offset. */
24345 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24346 reloc->address = fixp->fx_offset;
6c43fab6 24347
c19d1205 24348 return reloc;
6c43fab6
RE
24349}
24350
c19d1205 24351/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24352
c19d1205
ZW
24353void
24354cons_fix_new_arm (fragS * frag,
24355 int where,
24356 int size,
62ebcb5c
AM
24357 expressionS * exp,
24358 bfd_reloc_code_real_type reloc)
6c43fab6 24359{
c19d1205 24360 int pcrel = 0;
6c43fab6 24361
c19d1205
ZW
24362 /* Pick a reloc.
24363 FIXME: @@ Should look at CPU word size. */
24364 switch (size)
24365 {
24366 case 1:
62ebcb5c 24367 reloc = BFD_RELOC_8;
c19d1205
ZW
24368 break;
24369 case 2:
62ebcb5c 24370 reloc = BFD_RELOC_16;
c19d1205
ZW
24371 break;
24372 case 4:
24373 default:
62ebcb5c 24374 reloc = BFD_RELOC_32;
c19d1205
ZW
24375 break;
24376 case 8:
62ebcb5c 24377 reloc = BFD_RELOC_64;
c19d1205
ZW
24378 break;
24379 }
6c43fab6 24380
f0927246
NC
24381#ifdef TE_PE
24382 if (exp->X_op == O_secrel)
24383 {
24384 exp->X_op = O_symbol;
62ebcb5c 24385 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24386 }
24387#endif
24388
62ebcb5c 24389 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24390}
6c43fab6 24391
4343666d 24392#if defined (OBJ_COFF)
c19d1205
ZW
24393void
24394arm_validate_fix (fixS * fixP)
6c43fab6 24395{
c19d1205
ZW
24396 /* If the destination of the branch is a defined symbol which does not have
24397 the THUMB_FUNC attribute, then we must be calling a function which has
24398 the (interfacearm) attribute. We look for the Thumb entry point to that
24399 function and change the branch to refer to that function instead. */
24400 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24401 && fixP->fx_addsy != NULL
24402 && S_IS_DEFINED (fixP->fx_addsy)
24403 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24404 {
c19d1205 24405 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24406 }
c19d1205
ZW
24407}
24408#endif
6c43fab6 24409
267bf995 24410
c19d1205
ZW
24411int
24412arm_force_relocation (struct fix * fixp)
24413{
24414#if defined (OBJ_COFF) && defined (TE_PE)
24415 if (fixp->fx_r_type == BFD_RELOC_RVA)
24416 return 1;
24417#endif
6c43fab6 24418
267bf995
RR
24419 /* In case we have a call or a branch to a function in ARM ISA mode from
24420 a thumb function or vice-versa force the relocation. These relocations
24421 are cleared off for some cores that might have blx and simple transformations
24422 are possible. */
24423
24424#ifdef OBJ_ELF
24425 switch (fixp->fx_r_type)
24426 {
24427 case BFD_RELOC_ARM_PCREL_JUMP:
24428 case BFD_RELOC_ARM_PCREL_CALL:
24429 case BFD_RELOC_THUMB_PCREL_BLX:
24430 if (THUMB_IS_FUNC (fixp->fx_addsy))
24431 return 1;
24432 break;
24433
24434 case BFD_RELOC_ARM_PCREL_BLX:
24435 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24436 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24437 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24438 if (ARM_IS_FUNC (fixp->fx_addsy))
24439 return 1;
24440 break;
24441
24442 default:
24443 break;
24444 }
24445#endif
24446
b5884301
PB
24447 /* Resolve these relocations even if the symbol is extern or weak.
24448 Technically this is probably wrong due to symbol preemption.
24449 In practice these relocations do not have enough range to be useful
24450 at dynamic link time, and some code (e.g. in the Linux kernel)
24451 expects these references to be resolved. */
c19d1205
ZW
24452 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24453 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24454 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24455 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24456 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24457 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24458 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24459 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24460 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24461 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24462 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24463 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24464 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24465 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24466 return 0;
a737bd4d 24467
4962c51a
MS
24468 /* Always leave these relocations for the linker. */
24469 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24470 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24471 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24472 return 1;
24473
f0291e4c
PB
24474 /* Always generate relocations against function symbols. */
24475 if (fixp->fx_r_type == BFD_RELOC_32
24476 && fixp->fx_addsy
24477 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24478 return 1;
24479
c19d1205 24480 return generic_force_reloc (fixp);
404ff6b5
AH
24481}
24482
0ffdc86c 24483#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24484/* Relocations against function names must be left unadjusted,
24485 so that the linker can use this information to generate interworking
24486 stubs. The MIPS version of this function
c19d1205
ZW
24487 also prevents relocations that are mips-16 specific, but I do not
24488 know why it does this.
404ff6b5 24489
c19d1205
ZW
24490 FIXME:
24491 There is one other problem that ought to be addressed here, but
24492 which currently is not: Taking the address of a label (rather
24493 than a function) and then later jumping to that address. Such
24494 addresses also ought to have their bottom bit set (assuming that
24495 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24496
c19d1205
ZW
24497bfd_boolean
24498arm_fix_adjustable (fixS * fixP)
404ff6b5 24499{
c19d1205
ZW
24500 if (fixP->fx_addsy == NULL)
24501 return 1;
404ff6b5 24502
e28387c3
PB
24503 /* Preserve relocations against symbols with function type. */
24504 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24505 return FALSE;
e28387c3 24506
c19d1205
ZW
24507 if (THUMB_IS_FUNC (fixP->fx_addsy)
24508 && fixP->fx_subsy == NULL)
c921be7d 24509 return FALSE;
a737bd4d 24510
c19d1205
ZW
24511 /* We need the symbol name for the VTABLE entries. */
24512 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24513 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24514 return FALSE;
404ff6b5 24515
c19d1205
ZW
24516 /* Don't allow symbols to be discarded on GOT related relocs. */
24517 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24518 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24519 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24520 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24521 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24522 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24523 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24524 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24525 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24526 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24527 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24528 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24529 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24530 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24531 return FALSE;
a737bd4d 24532
4962c51a
MS
24533 /* Similarly for group relocations. */
24534 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24535 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24536 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24537 return FALSE;
4962c51a 24538
79947c54
CD
24539 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24540 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24541 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24542 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24543 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24544 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24545 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24546 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24547 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24548 return FALSE;
79947c54 24549
72d98d16
MG
24550 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24551 offsets, so keep these symbols. */
24552 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24553 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24554 return FALSE;
24555
c921be7d 24556 return TRUE;
a737bd4d 24557}
0ffdc86c
NC
24558#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24559
24560#ifdef OBJ_ELF
c19d1205
ZW
24561const char *
24562elf32_arm_target_format (void)
404ff6b5 24563{
c19d1205
ZW
24564#ifdef TE_SYMBIAN
24565 return (target_big_endian
24566 ? "elf32-bigarm-symbian"
24567 : "elf32-littlearm-symbian");
24568#elif defined (TE_VXWORKS)
24569 return (target_big_endian
24570 ? "elf32-bigarm-vxworks"
24571 : "elf32-littlearm-vxworks");
b38cadfb
NC
24572#elif defined (TE_NACL)
24573 return (target_big_endian
24574 ? "elf32-bigarm-nacl"
24575 : "elf32-littlearm-nacl");
c19d1205
ZW
24576#else
24577 if (target_big_endian)
24578 return "elf32-bigarm";
24579 else
24580 return "elf32-littlearm";
24581#endif
404ff6b5
AH
24582}
24583
c19d1205
ZW
24584void
24585armelf_frob_symbol (symbolS * symp,
24586 int * puntp)
404ff6b5 24587{
c19d1205
ZW
24588 elf_frob_symbol (symp, puntp);
24589}
24590#endif
404ff6b5 24591
c19d1205 24592/* MD interface: Finalization. */
a737bd4d 24593
c19d1205
ZW
24594void
24595arm_cleanup (void)
24596{
24597 literal_pool * pool;
a737bd4d 24598
e07e6e58
NC
24599 /* Ensure that all the IT blocks are properly closed. */
24600 check_it_blocks_finished ();
24601
c19d1205
ZW
24602 for (pool = list_of_pools; pool; pool = pool->next)
24603 {
5f4273c7 24604 /* Put it at the end of the relevant section. */
c19d1205
ZW
24605 subseg_set (pool->section, pool->sub_section);
24606#ifdef OBJ_ELF
24607 arm_elf_change_section ();
24608#endif
24609 s_ltorg (0);
24610 }
404ff6b5
AH
24611}
24612
cd000bff
DJ
24613#ifdef OBJ_ELF
24614/* Remove any excess mapping symbols generated for alignment frags in
24615 SEC. We may have created a mapping symbol before a zero byte
24616 alignment; remove it if there's a mapping symbol after the
24617 alignment. */
24618static void
24619check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24620 void *dummy ATTRIBUTE_UNUSED)
24621{
24622 segment_info_type *seginfo = seg_info (sec);
24623 fragS *fragp;
24624
24625 if (seginfo == NULL || seginfo->frchainP == NULL)
24626 return;
24627
24628 for (fragp = seginfo->frchainP->frch_root;
24629 fragp != NULL;
24630 fragp = fragp->fr_next)
24631 {
24632 symbolS *sym = fragp->tc_frag_data.last_map;
24633 fragS *next = fragp->fr_next;
24634
24635 /* Variable-sized frags have been converted to fixed size by
24636 this point. But if this was variable-sized to start with,
24637 there will be a fixed-size frag after it. So don't handle
24638 next == NULL. */
24639 if (sym == NULL || next == NULL)
24640 continue;
24641
24642 if (S_GET_VALUE (sym) < next->fr_address)
24643 /* Not at the end of this frag. */
24644 continue;
24645 know (S_GET_VALUE (sym) == next->fr_address);
24646
24647 do
24648 {
24649 if (next->tc_frag_data.first_map != NULL)
24650 {
24651 /* Next frag starts with a mapping symbol. Discard this
24652 one. */
24653 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24654 break;
24655 }
24656
24657 if (next->fr_next == NULL)
24658 {
24659 /* This mapping symbol is at the end of the section. Discard
24660 it. */
24661 know (next->fr_fix == 0 && next->fr_var == 0);
24662 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24663 break;
24664 }
24665
24666 /* As long as we have empty frags without any mapping symbols,
24667 keep looking. */
24668 /* If the next frag is non-empty and does not start with a
24669 mapping symbol, then this mapping symbol is required. */
24670 if (next->fr_address != next->fr_next->fr_address)
24671 break;
24672
24673 next = next->fr_next;
24674 }
24675 while (next != NULL);
24676 }
24677}
24678#endif
24679
c19d1205
ZW
24680/* Adjust the symbol table. This marks Thumb symbols as distinct from
24681 ARM ones. */
404ff6b5 24682
c19d1205
ZW
24683void
24684arm_adjust_symtab (void)
404ff6b5 24685{
c19d1205
ZW
24686#ifdef OBJ_COFF
24687 symbolS * sym;
404ff6b5 24688
c19d1205
ZW
24689 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24690 {
24691 if (ARM_IS_THUMB (sym))
24692 {
24693 if (THUMB_IS_FUNC (sym))
24694 {
24695 /* Mark the symbol as a Thumb function. */
24696 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24697 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24698 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24699
c19d1205
ZW
24700 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24701 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24702 else
24703 as_bad (_("%s: unexpected function type: %d"),
24704 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24705 }
24706 else switch (S_GET_STORAGE_CLASS (sym))
24707 {
24708 case C_EXT:
24709 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24710 break;
24711 case C_STAT:
24712 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24713 break;
24714 case C_LABEL:
24715 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24716 break;
24717 default:
24718 /* Do nothing. */
24719 break;
24720 }
24721 }
a737bd4d 24722
c19d1205
ZW
24723 if (ARM_IS_INTERWORK (sym))
24724 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24725 }
c19d1205
ZW
24726#endif
24727#ifdef OBJ_ELF
24728 symbolS * sym;
24729 char bind;
404ff6b5 24730
c19d1205 24731 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24732 {
c19d1205
ZW
24733 if (ARM_IS_THUMB (sym))
24734 {
24735 elf_symbol_type * elf_sym;
404ff6b5 24736
c19d1205
ZW
24737 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24738 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24739
b0796911
PB
24740 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24741 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24742 {
24743 /* If it's a .thumb_func, declare it as so,
24744 otherwise tag label as .code 16. */
24745 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24746 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24747 ST_BRANCH_TO_THUMB);
3ba67470 24748 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24749 elf_sym->internal_elf_sym.st_info =
24750 ELF_ST_INFO (bind, STT_ARM_16BIT);
24751 }
24752 }
24753 }
cd000bff
DJ
24754
24755 /* Remove any overlapping mapping symbols generated by alignment frags. */
24756 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24757 /* Now do generic ELF adjustments. */
24758 elf_adjust_symtab ();
c19d1205 24759#endif
404ff6b5
AH
24760}
24761
c19d1205 24762/* MD interface: Initialization. */
404ff6b5 24763
a737bd4d 24764static void
c19d1205 24765set_constant_flonums (void)
a737bd4d 24766{
c19d1205 24767 int i;
404ff6b5 24768
c19d1205
ZW
24769 for (i = 0; i < NUM_FLOAT_VALS; i++)
24770 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24771 abort ();
a737bd4d 24772}
404ff6b5 24773
3e9e4fcf
JB
24774/* Auto-select Thumb mode if it's the only available instruction set for the
24775 given architecture. */
24776
24777static void
24778autoselect_thumb_from_cpu_variant (void)
24779{
24780 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24781 opcode_select (16);
24782}
24783
c19d1205
ZW
24784void
24785md_begin (void)
a737bd4d 24786{
c19d1205
ZW
24787 unsigned mach;
24788 unsigned int i;
404ff6b5 24789
c19d1205
ZW
24790 if ( (arm_ops_hsh = hash_new ()) == NULL
24791 || (arm_cond_hsh = hash_new ()) == NULL
24792 || (arm_shift_hsh = hash_new ()) == NULL
24793 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24794 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24795 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24796 || (arm_reloc_hsh = hash_new ()) == NULL
24797 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24798 as_fatal (_("virtual memory exhausted"));
24799
24800 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24801 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24802 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24803 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24804 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24805 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24806 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24807 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24808 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24809 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24810 (void *) (v7m_psrs + i));
c19d1205 24811 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24812 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24813 for (i = 0;
24814 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24815 i++)
d3ce72d0 24816 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24817 (void *) (barrier_opt_names + i));
c19d1205 24818#ifdef OBJ_ELF
3da1d841
NC
24819 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24820 {
24821 struct reloc_entry * entry = reloc_names + i;
24822
24823 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24824 /* This makes encode_branch() use the EABI versions of this relocation. */
24825 entry->reloc = BFD_RELOC_UNUSED;
24826
24827 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24828 }
c19d1205
ZW
24829#endif
24830
24831 set_constant_flonums ();
404ff6b5 24832
c19d1205
ZW
24833 /* Set the cpu variant based on the command-line options. We prefer
24834 -mcpu= over -march= if both are set (as for GCC); and we prefer
24835 -mfpu= over any other way of setting the floating point unit.
24836 Use of legacy options with new options are faulted. */
e74cfd16 24837 if (legacy_cpu)
404ff6b5 24838 {
e74cfd16 24839 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24840 as_bad (_("use of old and new-style options to set CPU type"));
24841
24842 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24843 }
e74cfd16 24844 else if (!mcpu_cpu_opt)
c19d1205 24845 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24846
e74cfd16 24847 if (legacy_fpu)
c19d1205 24848 {
e74cfd16 24849 if (mfpu_opt)
c19d1205 24850 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24851
24852 mfpu_opt = legacy_fpu;
24853 }
e74cfd16 24854 else if (!mfpu_opt)
03b1477f 24855 {
45eb4c1b
NS
24856#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24857 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24858 /* Some environments specify a default FPU. If they don't, infer it
24859 from the processor. */
e74cfd16 24860 if (mcpu_fpu_opt)
03b1477f
RE
24861 mfpu_opt = mcpu_fpu_opt;
24862 else
24863 mfpu_opt = march_fpu_opt;
39c2da32 24864#else
e74cfd16 24865 mfpu_opt = &fpu_default;
39c2da32 24866#endif
03b1477f
RE
24867 }
24868
e74cfd16 24869 if (!mfpu_opt)
03b1477f 24870 {
493cb6ef 24871 if (mcpu_cpu_opt != NULL)
e74cfd16 24872 mfpu_opt = &fpu_default;
493cb6ef 24873 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24874 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24875 else
e74cfd16 24876 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24877 }
24878
ee065d83 24879#ifdef CPU_DEFAULT
e74cfd16 24880 if (!mcpu_cpu_opt)
ee065d83 24881 {
e74cfd16
PB
24882 mcpu_cpu_opt = &cpu_default;
24883 selected_cpu = cpu_default;
ee065d83 24884 }
73f43896
NC
24885 else if (no_cpu_selected ())
24886 selected_cpu = cpu_default;
e74cfd16
PB
24887#else
24888 if (mcpu_cpu_opt)
24889 selected_cpu = *mcpu_cpu_opt;
ee065d83 24890 else
e74cfd16 24891 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24892#endif
03b1477f 24893
e74cfd16 24894 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24895
3e9e4fcf
JB
24896 autoselect_thumb_from_cpu_variant ();
24897
e74cfd16 24898 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24899
f17c130b 24900#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24901 {
7cc69913
NC
24902 unsigned int flags = 0;
24903
24904#if defined OBJ_ELF
24905 flags = meabi_flags;
d507cf36
PB
24906
24907 switch (meabi_flags)
33a392fb 24908 {
d507cf36 24909 case EF_ARM_EABI_UNKNOWN:
7cc69913 24910#endif
d507cf36
PB
24911 /* Set the flags in the private structure. */
24912 if (uses_apcs_26) flags |= F_APCS26;
24913 if (support_interwork) flags |= F_INTERWORK;
24914 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24915 if (pic_code) flags |= F_PIC;
e74cfd16 24916 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24917 flags |= F_SOFT_FLOAT;
24918
d507cf36
PB
24919 switch (mfloat_abi_opt)
24920 {
24921 case ARM_FLOAT_ABI_SOFT:
24922 case ARM_FLOAT_ABI_SOFTFP:
24923 flags |= F_SOFT_FLOAT;
24924 break;
33a392fb 24925
d507cf36
PB
24926 case ARM_FLOAT_ABI_HARD:
24927 if (flags & F_SOFT_FLOAT)
24928 as_bad (_("hard-float conflicts with specified fpu"));
24929 break;
24930 }
03b1477f 24931
e74cfd16
PB
24932 /* Using pure-endian doubles (even if soft-float). */
24933 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24934 flags |= F_VFP_FLOAT;
f17c130b 24935
fde78edd 24936#if defined OBJ_ELF
e74cfd16 24937 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24938 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24939 break;
24940
8cb51566 24941 case EF_ARM_EABI_VER4:
3a4a14e9 24942 case EF_ARM_EABI_VER5:
c19d1205 24943 /* No additional flags to set. */
d507cf36
PB
24944 break;
24945
24946 default:
24947 abort ();
24948 }
7cc69913 24949#endif
b99bd4ef
NC
24950 bfd_set_private_flags (stdoutput, flags);
24951
24952 /* We have run out flags in the COFF header to encode the
24953 status of ATPCS support, so instead we create a dummy,
c19d1205 24954 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24955 if (atpcs)
24956 {
24957 asection * sec;
24958
24959 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24960
24961 if (sec != NULL)
24962 {
24963 bfd_set_section_flags
24964 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24965 bfd_set_section_size (stdoutput, sec, 0);
24966 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24967 }
24968 }
7cc69913 24969 }
f17c130b 24970#endif
b99bd4ef
NC
24971
24972 /* Record the CPU type as well. */
2d447fca
JM
24973 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24974 mach = bfd_mach_arm_iWMMXt2;
24975 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24976 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24977 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24978 mach = bfd_mach_arm_XScale;
e74cfd16 24979 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24980 mach = bfd_mach_arm_ep9312;
e74cfd16 24981 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24982 mach = bfd_mach_arm_5TE;
e74cfd16 24983 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24984 {
e74cfd16 24985 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24986 mach = bfd_mach_arm_5T;
24987 else
24988 mach = bfd_mach_arm_5;
24989 }
e74cfd16 24990 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24991 {
e74cfd16 24992 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24993 mach = bfd_mach_arm_4T;
24994 else
24995 mach = bfd_mach_arm_4;
24996 }
e74cfd16 24997 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24998 mach = bfd_mach_arm_3M;
e74cfd16
PB
24999 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25000 mach = bfd_mach_arm_3;
25001 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25002 mach = bfd_mach_arm_2a;
25003 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25004 mach = bfd_mach_arm_2;
25005 else
25006 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25007
25008 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25009}
25010
c19d1205 25011/* Command line processing. */
b99bd4ef 25012
c19d1205
ZW
25013/* md_parse_option
25014 Invocation line includes a switch not recognized by the base assembler.
25015 See if it's a processor-specific option.
b99bd4ef 25016
c19d1205
ZW
25017 This routine is somewhat complicated by the need for backwards
25018 compatibility (since older releases of gcc can't be changed).
25019 The new options try to make the interface as compatible as
25020 possible with GCC.
b99bd4ef 25021
c19d1205 25022 New options (supported) are:
b99bd4ef 25023
c19d1205
ZW
25024 -mcpu=<cpu name> Assemble for selected processor
25025 -march=<architecture name> Assemble for selected architecture
25026 -mfpu=<fpu architecture> Assemble for selected FPU.
25027 -EB/-mbig-endian Big-endian
25028 -EL/-mlittle-endian Little-endian
25029 -k Generate PIC code
25030 -mthumb Start in Thumb mode
25031 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25032
278df34e 25033 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25034 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25035
c19d1205 25036 For now we will also provide support for:
b99bd4ef 25037
c19d1205
ZW
25038 -mapcs-32 32-bit Program counter
25039 -mapcs-26 26-bit Program counter
25040 -macps-float Floats passed in FP registers
25041 -mapcs-reentrant Reentrant code
25042 -matpcs
25043 (sometime these will probably be replaced with -mapcs=<list of options>
25044 and -matpcs=<list of options>)
b99bd4ef 25045
c19d1205
ZW
25046 The remaining options are only supported for back-wards compatibility.
25047 Cpu variants, the arm part is optional:
25048 -m[arm]1 Currently not supported.
25049 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25050 -m[arm]3 Arm 3 processor
25051 -m[arm]6[xx], Arm 6 processors
25052 -m[arm]7[xx][t][[d]m] Arm 7 processors
25053 -m[arm]8[10] Arm 8 processors
25054 -m[arm]9[20][tdmi] Arm 9 processors
25055 -mstrongarm[110[0]] StrongARM processors
25056 -mxscale XScale processors
25057 -m[arm]v[2345[t[e]]] Arm architectures
25058 -mall All (except the ARM1)
25059 FP variants:
25060 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25061 -mfpe-old (No float load/store multiples)
25062 -mvfpxd VFP Single precision
25063 -mvfp All VFP
25064 -mno-fpu Disable all floating point instructions
b99bd4ef 25065
c19d1205
ZW
25066 The following CPU names are recognized:
25067 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25068 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25069 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25070 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25071 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25072 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25073 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25074
c19d1205 25075 */
b99bd4ef 25076
c19d1205 25077const char * md_shortopts = "m:k";
b99bd4ef 25078
c19d1205
ZW
25079#ifdef ARM_BI_ENDIAN
25080#define OPTION_EB (OPTION_MD_BASE + 0)
25081#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25082#else
c19d1205
ZW
25083#if TARGET_BYTES_BIG_ENDIAN
25084#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25085#else
c19d1205
ZW
25086#define OPTION_EL (OPTION_MD_BASE + 1)
25087#endif
b99bd4ef 25088#endif
845b51d6 25089#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25090
c19d1205 25091struct option md_longopts[] =
b99bd4ef 25092{
c19d1205
ZW
25093#ifdef OPTION_EB
25094 {"EB", no_argument, NULL, OPTION_EB},
25095#endif
25096#ifdef OPTION_EL
25097 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25098#endif
845b51d6 25099 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25100 {NULL, no_argument, NULL, 0}
25101};
b99bd4ef 25102
8b2d793c 25103
c19d1205 25104size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25105
c19d1205 25106struct arm_option_table
b99bd4ef 25107{
e0471c16
TS
25108 const char *option; /* Option name to match. */
25109 const char *help; /* Help information. */
c19d1205
ZW
25110 int *var; /* Variable to change. */
25111 int value; /* What to change it to. */
e0471c16 25112 const char *deprecated; /* If non-null, print this message. */
c19d1205 25113};
b99bd4ef 25114
c19d1205
ZW
25115struct arm_option_table arm_opts[] =
25116{
25117 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25118 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25119 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25120 &support_interwork, 1, NULL},
25121 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25122 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25123 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25124 1, NULL},
25125 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25126 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25127 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25128 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25129 NULL},
b99bd4ef 25130
c19d1205
ZW
25131 /* These are recognized by the assembler, but have no affect on code. */
25132 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25133 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25134
25135 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25136 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25137 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25138 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25139 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25140 {NULL, NULL, NULL, 0, NULL}
25141};
25142
25143struct arm_legacy_option_table
25144{
e0471c16 25145 const char *option; /* Option name to match. */
e74cfd16
PB
25146 const arm_feature_set **var; /* Variable to change. */
25147 const arm_feature_set value; /* What to change it to. */
e0471c16 25148 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25149};
b99bd4ef 25150
e74cfd16
PB
25151const struct arm_legacy_option_table arm_legacy_opts[] =
25152{
c19d1205
ZW
25153 /* DON'T add any new processors to this list -- we want the whole list
25154 to go away... Add them to the processors table instead. */
e74cfd16
PB
25155 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25156 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25157 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25158 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25159 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25160 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25161 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25162 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25163 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25164 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25165 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25166 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25167 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25168 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25169 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25170 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25171 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25172 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25173 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25174 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25175 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25176 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25177 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25178 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25179 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25180 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25181 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25182 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25183 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25184 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25185 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25186 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25187 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25188 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25189 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25190 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25191 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25192 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25193 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25194 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25195 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25196 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25197 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25198 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25199 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25200 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25201 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25202 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25203 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25204 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25205 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25206 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25207 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25208 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25209 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25210 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25211 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25212 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25213 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25214 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25215 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25216 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25217 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25218 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25219 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25220 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25221 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25222 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25223 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25224 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25225 N_("use -mcpu=strongarm110")},
e74cfd16 25226 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25227 N_("use -mcpu=strongarm1100")},
e74cfd16 25228 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25229 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25230 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25231 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25232 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25233
c19d1205 25234 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25235 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25236 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25237 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25238 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25239 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25240 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25241 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25242 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25243 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25244 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25245 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25246 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25247 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25248 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25249 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25250 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25251 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25252 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25253
c19d1205 25254 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25255 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25256 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25257 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25258 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25259 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25260
e74cfd16 25261 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25262};
7ed4c4c5 25263
c19d1205 25264struct arm_cpu_option_table
7ed4c4c5 25265{
e0471c16 25266 const char *name;
f3bad469 25267 size_t name_len;
e74cfd16 25268 const arm_feature_set value;
c19d1205
ZW
25269 /* For some CPUs we assume an FPU unless the user explicitly sets
25270 -mfpu=... */
e74cfd16 25271 const arm_feature_set default_fpu;
ee065d83
PB
25272 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25273 case. */
25274 const char *canonical_name;
c19d1205 25275};
7ed4c4c5 25276
c19d1205
ZW
25277/* This list should, at a minimum, contain all the cpu names
25278 recognized by GCC. */
f3bad469 25279#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25280static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25281{
f3bad469
MGD
25282 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25283 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25284 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25285 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25286 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25287 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25288 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25289 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25290 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25291 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25292 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25293 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25294 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25295 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25296 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25297 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25298 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25299 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25300 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25301 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25302 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25303 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25304 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25305 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25306 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25307 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25308 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25309 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25310 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25311 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25312 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25313 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25314 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25315 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25316 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25317 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25318 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25319 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25320 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25321 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25322 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25323 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25324 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25325 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25326 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25327 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25328 /* For V5 or later processors we default to using VFP; but the user
25329 should really set the FPU type explicitly. */
f3bad469
MGD
25330 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25331 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25332 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25333 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25334 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25335 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25336 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25337 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25338 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25339 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25340 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25341 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25342 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25343 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25344 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25345 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25346 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25347 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25348 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25349 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25350 "ARM1026EJ-S"),
25351 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25352 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25353 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25354 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25355 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25356 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25357 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25358 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25359 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25360 "ARM1136JF-S"),
25361 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25362 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25363 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25364 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25365 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25366 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25367 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25368 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25369 FPU_NONE, "Cortex-A5"),
c9fb6e58 25370 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25371 "Cortex-A7"),
25372 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25373 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25374 | FPU_NEON_EXT_V1),
f3bad469
MGD
25375 "Cortex-A8"),
25376 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25377 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25378 | FPU_NEON_EXT_V1),
f3bad469 25379 "Cortex-A9"),
c9fb6e58 25380 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25381 "Cortex-A12"),
c9fb6e58 25382 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25383 "Cortex-A15"),
d7adf960
KT
25384 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25385 "Cortex-A17"),
27e5a270 25386 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
6735952f 25387 "Cortex-A32"),
27e5a270 25388 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
43cdc0a8 25389 "Cortex-A35"),
27e5a270 25390 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25391 "Cortex-A53"),
27e5a270 25392 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25393 "Cortex-A57"),
27e5a270 25394 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
b19f47ad 25395 "Cortex-A72"),
27e5a270 25396 ARM_CPU_OPT ("cortex-a73", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
362a3eba 25397 "Cortex-A73"),
f3bad469
MGD
25398 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25399 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25400 "Cortex-R4F"),
25401 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25402 FPU_NONE, "Cortex-R5"),
70a8bc5b 25403 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25404 FPU_ARCH_VFP_V3D16,
25405 "Cortex-R7"),
5f474010
TP
25406 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25407 FPU_ARCH_VFP_V3D16,
25408 "Cortex-R8"),
a715796b 25409 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25410 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25411 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25412 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25413 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25414 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
27e5a270 25415 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
246496bb
EM
25416 "Samsung " \
25417 "Exynos M1"),
27e5a270 25418 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
6b21c2bf
JW
25419 "Qualcomm "
25420 "QDF24XX"),
25421
c19d1205 25422 /* ??? XSCALE is really an architecture. */
f3bad469 25423 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25424 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25425 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25426 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25427 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25428 /* Maverick */
823d2571 25429 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25430 FPU_ARCH_MAVERICK, "ARM920T"),
25431 /* Marvell processors. */
ff8646ee
TP
25432 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25433 | ARM_EXT_SEC,
25434 ARM_EXT2_V6T2_V8M),
477330fc 25435 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25436 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25437 | ARM_EXT_SEC,
25438 ARM_EXT2_V6T2_V8M),
4347085a 25439 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25440 /* APM X-Gene family. */
25441 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25442 "APM X-Gene 1"),
27e5a270 25443 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
ea0d6bb9 25444 "APM X-Gene 2"),
da4339ed 25445
f3bad469 25446 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25447};
f3bad469 25448#undef ARM_CPU_OPT
7ed4c4c5 25449
c19d1205 25450struct arm_arch_option_table
7ed4c4c5 25451{
e0471c16 25452 const char *name;
f3bad469 25453 size_t name_len;
e74cfd16
PB
25454 const arm_feature_set value;
25455 const arm_feature_set default_fpu;
c19d1205 25456};
7ed4c4c5 25457
c19d1205
ZW
25458/* This list should, at a minimum, contain all the architecture names
25459 recognized by GCC. */
f3bad469 25460#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25461static const struct arm_arch_option_table arm_archs[] =
c19d1205 25462{
f3bad469
MGD
25463 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25464 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25465 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25466 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25467 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25468 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25469 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25470 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25471 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25472 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25473 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25474 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25475 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25476 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25477 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25478 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25479 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25480 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25481 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25482 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25483 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25484 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25485 kept to preserve existing behaviour. */
25486 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25487 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25488 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25489 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25490 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25491 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25492 kept to preserve existing behaviour. */
25493 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25494 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25495 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25496 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25497 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25498 /* The official spelling of the ARMv7 profile variants is the dashed form.
25499 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25500 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25501 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25502 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25503 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25504 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25505 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25506 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25507 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25508 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25509 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25510 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25511 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25512 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25513 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25514 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25515 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25516 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25517};
f3bad469 25518#undef ARM_ARCH_OPT
7ed4c4c5 25519
69133863
MGD
25520/* ISA extensions in the co-processor and main instruction set space. */
25521struct arm_option_extension_value_table
c19d1205 25522{
e0471c16 25523 const char *name;
f3bad469 25524 size_t name_len;
5a70a223
JB
25525 const arm_feature_set merge_value;
25526 const arm_feature_set clear_value;
d942732e
TP
25527 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25528 indicates that an extension is available for all architectures while
25529 ARM_ANY marks an empty entry. */
25530 const arm_feature_set allowed_archs[2];
c19d1205 25531};
7ed4c4c5 25532
69133863
MGD
25533/* The following table must be in alphabetical order with a NULL last entry.
25534 */
d942732e
TP
25535#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25536#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25537static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25538{
823d2571
TG
25539 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25540 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25541 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25542 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25543 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25544 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25545 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25546 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25547 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25548 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25549 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25550 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25551 ARM_ARCH_V8_2A),
d942732e 25552 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25553 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25554 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25555 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25556 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25557 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25558 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25559 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25560 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25561 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25562 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25563 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25564 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25565 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25566 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25567 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25568 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25569 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25570 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25571 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25572 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25573 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25574 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25575 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25576 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25577 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25578 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25579 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25580 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25581 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25582 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25583 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25584 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25585 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25586 | ARM_EXT_DIV),
25587 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25588 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25589 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25590 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25591 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25592};
f3bad469 25593#undef ARM_EXT_OPT
69133863
MGD
25594
25595/* ISA floating-point and Advanced SIMD extensions. */
25596struct arm_option_fpu_value_table
25597{
e0471c16 25598 const char *name;
69133863 25599 const arm_feature_set value;
c19d1205 25600};
7ed4c4c5 25601
c19d1205
ZW
25602/* This list should, at a minimum, contain all the fpu names
25603 recognized by GCC. */
69133863 25604static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25605{
25606 {"softfpa", FPU_NONE},
25607 {"fpe", FPU_ARCH_FPE},
25608 {"fpe2", FPU_ARCH_FPE},
25609 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25610 {"fpa", FPU_ARCH_FPA},
25611 {"fpa10", FPU_ARCH_FPA},
25612 {"fpa11", FPU_ARCH_FPA},
25613 {"arm7500fe", FPU_ARCH_FPA},
25614 {"softvfp", FPU_ARCH_VFP},
25615 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25616 {"vfp", FPU_ARCH_VFP_V2},
25617 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25618 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25619 {"vfp10", FPU_ARCH_VFP_V2},
25620 {"vfp10-r0", FPU_ARCH_VFP_V1},
25621 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25622 {"vfpv2", FPU_ARCH_VFP_V2},
25623 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25624 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25625 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25626 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25627 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25628 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25629 {"arm1020t", FPU_ARCH_VFP_V1},
25630 {"arm1020e", FPU_ARCH_VFP_V2},
25631 {"arm1136jfs", FPU_ARCH_VFP_V2},
25632 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25633 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25634 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25635 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25636 {"vfpv4", FPU_ARCH_VFP_V4},
25637 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25638 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25639 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25640 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25641 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25642 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25643 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25644 {"crypto-neon-fp-armv8",
25645 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25646 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25647 {"crypto-neon-fp-armv8.1",
25648 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25649 {NULL, ARM_ARCH_NONE}
25650};
25651
25652struct arm_option_value_table
25653{
e0471c16 25654 const char *name;
e74cfd16 25655 long value;
c19d1205 25656};
7ed4c4c5 25657
e74cfd16 25658static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25659{
25660 {"hard", ARM_FLOAT_ABI_HARD},
25661 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25662 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25663 {NULL, 0}
c19d1205 25664};
7ed4c4c5 25665
c19d1205 25666#ifdef OBJ_ELF
3a4a14e9 25667/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25668static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25669{
25670 {"gnu", EF_ARM_EABI_UNKNOWN},
25671 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25672 {"5", EF_ARM_EABI_VER5},
e74cfd16 25673 {NULL, 0}
c19d1205
ZW
25674};
25675#endif
7ed4c4c5 25676
c19d1205
ZW
25677struct arm_long_option_table
25678{
e0471c16
TS
25679 const char * option; /* Substring to match. */
25680 const char * help; /* Help information. */
17b9d67d 25681 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25682 const char * deprecated; /* If non-null, print this message. */
c19d1205 25683};
7ed4c4c5 25684
c921be7d 25685static bfd_boolean
82b8a785 25686arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25687{
325801bd 25688 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25689
69133863 25690 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25691 extensions being added before being removed. We achieve this by having
25692 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25693 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25694 or removing it (0) and only allowing it to change in the order
69133863
MGD
25695 -1 -> 1 -> 0. */
25696 const struct arm_option_extension_value_table * opt = NULL;
d942732e 25697 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
25698 int adding_value = -1;
25699
e74cfd16
PB
25700 /* Copy the feature set, so that we can modify it. */
25701 *ext_set = **opt_p;
25702 *opt_p = ext_set;
25703
c19d1205 25704 while (str != NULL && *str != 0)
7ed4c4c5 25705 {
82b8a785 25706 const char *ext;
f3bad469 25707 size_t len;
7ed4c4c5 25708
c19d1205
ZW
25709 if (*str != '+')
25710 {
25711 as_bad (_("invalid architectural extension"));
c921be7d 25712 return FALSE;
c19d1205 25713 }
7ed4c4c5 25714
c19d1205
ZW
25715 str++;
25716 ext = strchr (str, '+');
7ed4c4c5 25717
c19d1205 25718 if (ext != NULL)
f3bad469 25719 len = ext - str;
c19d1205 25720 else
f3bad469 25721 len = strlen (str);
7ed4c4c5 25722
f3bad469 25723 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25724 {
25725 if (adding_value != 0)
25726 {
25727 adding_value = 0;
25728 opt = arm_extensions;
25729 }
25730
f3bad469 25731 len -= 2;
69133863
MGD
25732 str += 2;
25733 }
f3bad469 25734 else if (len > 0)
69133863
MGD
25735 {
25736 if (adding_value == -1)
25737 {
25738 adding_value = 1;
25739 opt = arm_extensions;
25740 }
25741 else if (adding_value != 1)
25742 {
25743 as_bad (_("must specify extensions to add before specifying "
25744 "those to remove"));
25745 return FALSE;
25746 }
25747 }
25748
f3bad469 25749 if (len == 0)
c19d1205
ZW
25750 {
25751 as_bad (_("missing architectural extension"));
c921be7d 25752 return FALSE;
c19d1205 25753 }
7ed4c4c5 25754
69133863
MGD
25755 gas_assert (adding_value != -1);
25756 gas_assert (opt != NULL);
25757
25758 /* Scan over the options table trying to find an exact match. */
25759 for (; opt->name != NULL; opt++)
f3bad469 25760 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25761 {
d942732e
TP
25762 int i, nb_allowed_archs =
25763 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 25764 /* Check we can apply the extension to this architecture. */
d942732e
TP
25765 for (i = 0; i < nb_allowed_archs; i++)
25766 {
25767 /* Empty entry. */
25768 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
25769 continue;
25770 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
25771 break;
25772 }
25773 if (i == nb_allowed_archs)
69133863
MGD
25774 {
25775 as_bad (_("extension does not apply to the base architecture"));
25776 return FALSE;
25777 }
25778
25779 /* Add or remove the extension. */
25780 if (adding_value)
5a70a223 25781 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25782 else
5a70a223 25783 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25784
c19d1205
ZW
25785 break;
25786 }
7ed4c4c5 25787
c19d1205
ZW
25788 if (opt->name == NULL)
25789 {
69133863
MGD
25790 /* Did we fail to find an extension because it wasn't specified in
25791 alphabetical order, or because it does not exist? */
25792
25793 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25794 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25795 break;
25796
25797 if (opt->name == NULL)
25798 as_bad (_("unknown architectural extension `%s'"), str);
25799 else
25800 as_bad (_("architectural extensions must be specified in "
25801 "alphabetical order"));
25802
c921be7d 25803 return FALSE;
c19d1205 25804 }
69133863
MGD
25805 else
25806 {
25807 /* We should skip the extension we've just matched the next time
25808 round. */
25809 opt++;
25810 }
7ed4c4c5 25811
c19d1205
ZW
25812 str = ext;
25813 };
7ed4c4c5 25814
c921be7d 25815 return TRUE;
c19d1205 25816}
7ed4c4c5 25817
c921be7d 25818static bfd_boolean
17b9d67d 25819arm_parse_cpu (const char *str)
7ed4c4c5 25820{
f3bad469 25821 const struct arm_cpu_option_table *opt;
82b8a785 25822 const char *ext = strchr (str, '+');
f3bad469 25823 size_t len;
7ed4c4c5 25824
c19d1205 25825 if (ext != NULL)
f3bad469 25826 len = ext - str;
7ed4c4c5 25827 else
f3bad469 25828 len = strlen (str);
7ed4c4c5 25829
f3bad469 25830 if (len == 0)
7ed4c4c5 25831 {
c19d1205 25832 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25833 return FALSE;
7ed4c4c5
NC
25834 }
25835
c19d1205 25836 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25837 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25838 {
e74cfd16
PB
25839 mcpu_cpu_opt = &opt->value;
25840 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25841 if (opt->canonical_name)
ef8e6722
JW
25842 {
25843 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25844 strcpy (selected_cpu_name, opt->canonical_name);
25845 }
ee065d83
PB
25846 else
25847 {
f3bad469 25848 size_t i;
c921be7d 25849
ef8e6722
JW
25850 if (len >= sizeof selected_cpu_name)
25851 len = (sizeof selected_cpu_name) - 1;
25852
f3bad469 25853 for (i = 0; i < len; i++)
ee065d83
PB
25854 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25855 selected_cpu_name[i] = 0;
25856 }
7ed4c4c5 25857
c19d1205
ZW
25858 if (ext != NULL)
25859 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25860
c921be7d 25861 return TRUE;
c19d1205 25862 }
7ed4c4c5 25863
c19d1205 25864 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25865 return FALSE;
7ed4c4c5
NC
25866}
25867
c921be7d 25868static bfd_boolean
17b9d67d 25869arm_parse_arch (const char *str)
7ed4c4c5 25870{
e74cfd16 25871 const struct arm_arch_option_table *opt;
82b8a785 25872 const char *ext = strchr (str, '+');
f3bad469 25873 size_t len;
7ed4c4c5 25874
c19d1205 25875 if (ext != NULL)
f3bad469 25876 len = ext - str;
7ed4c4c5 25877 else
f3bad469 25878 len = strlen (str);
7ed4c4c5 25879
f3bad469 25880 if (len == 0)
7ed4c4c5 25881 {
c19d1205 25882 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25883 return FALSE;
7ed4c4c5
NC
25884 }
25885
c19d1205 25886 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25887 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25888 {
e74cfd16
PB
25889 march_cpu_opt = &opt->value;
25890 march_fpu_opt = &opt->default_fpu;
5f4273c7 25891 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25892
c19d1205
ZW
25893 if (ext != NULL)
25894 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25895
c921be7d 25896 return TRUE;
c19d1205
ZW
25897 }
25898
25899 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25900 return FALSE;
7ed4c4c5 25901}
eb043451 25902
c921be7d 25903static bfd_boolean
17b9d67d 25904arm_parse_fpu (const char * str)
c19d1205 25905{
69133863 25906 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25907
c19d1205
ZW
25908 for (opt = arm_fpus; opt->name != NULL; opt++)
25909 if (streq (opt->name, str))
25910 {
e74cfd16 25911 mfpu_opt = &opt->value;
c921be7d 25912 return TRUE;
c19d1205 25913 }
b99bd4ef 25914
c19d1205 25915 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25916 return FALSE;
c19d1205
ZW
25917}
25918
c921be7d 25919static bfd_boolean
17b9d67d 25920arm_parse_float_abi (const char * str)
b99bd4ef 25921{
e74cfd16 25922 const struct arm_option_value_table * opt;
b99bd4ef 25923
c19d1205
ZW
25924 for (opt = arm_float_abis; opt->name != NULL; opt++)
25925 if (streq (opt->name, str))
25926 {
25927 mfloat_abi_opt = opt->value;
c921be7d 25928 return TRUE;
c19d1205 25929 }
cc8a6dd0 25930
c19d1205 25931 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25932 return FALSE;
c19d1205 25933}
b99bd4ef 25934
c19d1205 25935#ifdef OBJ_ELF
c921be7d 25936static bfd_boolean
17b9d67d 25937arm_parse_eabi (const char * str)
c19d1205 25938{
e74cfd16 25939 const struct arm_option_value_table *opt;
cc8a6dd0 25940
c19d1205
ZW
25941 for (opt = arm_eabis; opt->name != NULL; opt++)
25942 if (streq (opt->name, str))
25943 {
25944 meabi_flags = opt->value;
c921be7d 25945 return TRUE;
c19d1205
ZW
25946 }
25947 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25948 return FALSE;
c19d1205
ZW
25949}
25950#endif
cc8a6dd0 25951
c921be7d 25952static bfd_boolean
17b9d67d 25953arm_parse_it_mode (const char * str)
e07e6e58 25954{
c921be7d 25955 bfd_boolean ret = TRUE;
e07e6e58
NC
25956
25957 if (streq ("arm", str))
25958 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25959 else if (streq ("thumb", str))
25960 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25961 else if (streq ("always", str))
25962 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25963 else if (streq ("never", str))
25964 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25965 else
25966 {
25967 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25968 "arm, thumb, always, or never."), str);
c921be7d 25969 ret = FALSE;
e07e6e58
NC
25970 }
25971
25972 return ret;
25973}
25974
2e6976a8 25975static bfd_boolean
17b9d67d 25976arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
25977{
25978 codecomposer_syntax = TRUE;
25979 arm_comment_chars[0] = ';';
25980 arm_line_separator_chars[0] = 0;
25981 return TRUE;
25982}
25983
c19d1205
ZW
25984struct arm_long_option_table arm_long_opts[] =
25985{
25986 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25987 arm_parse_cpu, NULL},
25988 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25989 arm_parse_arch, NULL},
25990 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25991 arm_parse_fpu, NULL},
25992 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25993 arm_parse_float_abi, NULL},
25994#ifdef OBJ_ELF
7fac0536 25995 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25996 arm_parse_eabi, NULL},
25997#endif
e07e6e58
NC
25998 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25999 arm_parse_it_mode, NULL},
2e6976a8
DG
26000 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26001 arm_ccs_mode, NULL},
c19d1205
ZW
26002 {NULL, NULL, 0, NULL}
26003};
cc8a6dd0 26004
c19d1205 26005int
17b9d67d 26006md_parse_option (int c, const char * arg)
c19d1205
ZW
26007{
26008 struct arm_option_table *opt;
e74cfd16 26009 const struct arm_legacy_option_table *fopt;
c19d1205 26010 struct arm_long_option_table *lopt;
b99bd4ef 26011
c19d1205 26012 switch (c)
b99bd4ef 26013 {
c19d1205
ZW
26014#ifdef OPTION_EB
26015 case OPTION_EB:
26016 target_big_endian = 1;
26017 break;
26018#endif
cc8a6dd0 26019
c19d1205
ZW
26020#ifdef OPTION_EL
26021 case OPTION_EL:
26022 target_big_endian = 0;
26023 break;
26024#endif
b99bd4ef 26025
845b51d6
PB
26026 case OPTION_FIX_V4BX:
26027 fix_v4bx = TRUE;
26028 break;
26029
c19d1205
ZW
26030 case 'a':
26031 /* Listing option. Just ignore these, we don't support additional
26032 ones. */
26033 return 0;
b99bd4ef 26034
c19d1205
ZW
26035 default:
26036 for (opt = arm_opts; opt->option != NULL; opt++)
26037 {
26038 if (c == opt->option[0]
26039 && ((arg == NULL && opt->option[1] == 0)
26040 || streq (arg, opt->option + 1)))
26041 {
c19d1205 26042 /* If the option is deprecated, tell the user. */
278df34e 26043 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26044 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26045 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26046
c19d1205
ZW
26047 if (opt->var != NULL)
26048 *opt->var = opt->value;
cc8a6dd0 26049
c19d1205
ZW
26050 return 1;
26051 }
26052 }
b99bd4ef 26053
e74cfd16
PB
26054 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26055 {
26056 if (c == fopt->option[0]
26057 && ((arg == NULL && fopt->option[1] == 0)
26058 || streq (arg, fopt->option + 1)))
26059 {
e74cfd16 26060 /* If the option is deprecated, tell the user. */
278df34e 26061 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26062 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26063 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26064
26065 if (fopt->var != NULL)
26066 *fopt->var = &fopt->value;
26067
26068 return 1;
26069 }
26070 }
26071
c19d1205
ZW
26072 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26073 {
26074 /* These options are expected to have an argument. */
26075 if (c == lopt->option[0]
26076 && arg != NULL
26077 && strncmp (arg, lopt->option + 1,
26078 strlen (lopt->option + 1)) == 0)
26079 {
c19d1205 26080 /* If the option is deprecated, tell the user. */
278df34e 26081 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26082 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26083 _(lopt->deprecated));
b99bd4ef 26084
c19d1205
ZW
26085 /* Call the sup-option parser. */
26086 return lopt->func (arg + strlen (lopt->option) - 1);
26087 }
26088 }
a737bd4d 26089
c19d1205
ZW
26090 return 0;
26091 }
a394c00f 26092
c19d1205
ZW
26093 return 1;
26094}
a394c00f 26095
c19d1205
ZW
26096void
26097md_show_usage (FILE * fp)
a394c00f 26098{
c19d1205
ZW
26099 struct arm_option_table *opt;
26100 struct arm_long_option_table *lopt;
a394c00f 26101
c19d1205 26102 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26103
c19d1205
ZW
26104 for (opt = arm_opts; opt->option != NULL; opt++)
26105 if (opt->help != NULL)
26106 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26107
c19d1205
ZW
26108 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26109 if (lopt->help != NULL)
26110 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26111
c19d1205
ZW
26112#ifdef OPTION_EB
26113 fprintf (fp, _("\
26114 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26115#endif
26116
c19d1205
ZW
26117#ifdef OPTION_EL
26118 fprintf (fp, _("\
26119 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26120#endif
845b51d6
PB
26121
26122 fprintf (fp, _("\
26123 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26124}
ee065d83
PB
26125
26126
26127#ifdef OBJ_ELF
62b3e311
PB
26128typedef struct
26129{
26130 int val;
26131 arm_feature_set flags;
26132} cpu_arch_ver_table;
26133
4ed7ed8d
TP
26134/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26135 must be sorted least features first but some reordering is needed, eg. for
26136 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26137static const cpu_arch_ver_table cpu_arch_ver[] =
26138{
26139 {1, ARM_ARCH_V4},
26140 {2, ARM_ARCH_V4T},
26141 {3, ARM_ARCH_V5},
ee3c0378 26142 {3, ARM_ARCH_V5T},
62b3e311
PB
26143 {4, ARM_ARCH_V5TE},
26144 {5, ARM_ARCH_V5TEJ},
26145 {6, ARM_ARCH_V6},
7e806470 26146 {9, ARM_ARCH_V6K},
f4c65163 26147 {7, ARM_ARCH_V6Z},
91e22acd 26148 {11, ARM_ARCH_V6M},
b2a5fbdc 26149 {12, ARM_ARCH_V6SM},
7e806470 26150 {8, ARM_ARCH_V6T2},
c9fb6e58 26151 {10, ARM_ARCH_V7VE},
62b3e311
PB
26152 {10, ARM_ARCH_V7R},
26153 {10, ARM_ARCH_V7M},
bca38921 26154 {14, ARM_ARCH_V8A},
ff8646ee 26155 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26156 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26157 {0, ARM_ARCH_NONE}
26158};
26159
ee3c0378
AS
26160/* Set an attribute if it has not already been set by the user. */
26161static void
26162aeabi_set_attribute_int (int tag, int value)
26163{
26164 if (tag < 1
26165 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26166 || !attributes_set_explicitly[tag])
26167 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26168}
26169
26170static void
26171aeabi_set_attribute_string (int tag, const char *value)
26172{
26173 if (tag < 1
26174 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26175 || !attributes_set_explicitly[tag])
26176 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26177}
26178
ee065d83 26179/* Set the public EABI object attributes. */
3cfdb781 26180void
ee065d83
PB
26181aeabi_set_public_attributes (void)
26182{
26183 int arch;
69239280 26184 char profile;
90ec0d68 26185 int virt_sec = 0;
bca38921 26186 int fp16_optional = 0;
15afaa63 26187 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26188 arm_feature_set flags;
62b3e311 26189 arm_feature_set tmp;
ff8646ee 26190 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26191 const cpu_arch_ver_table *p;
ee065d83
PB
26192
26193 /* Choose the architecture based on the capabilities of the requested cpu
26194 (if any) and/or the instructions actually used. */
e74cfd16
PB
26195 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26196 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26197 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26198
26199 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26200 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26201
26202 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26203 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26204
7f78eb34
JW
26205 selected_cpu = flags;
26206
ddd7f988 26207 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26208 if (object_arch)
26209 {
26210 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26211 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26212 }
26213
251665fc
MGD
26214 /* We need to make sure that the attributes do not identify us as v6S-M
26215 when the only v6S-M feature in use is the Operating System Extensions. */
26216 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26217 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26218 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26219
62b3e311
PB
26220 tmp = flags;
26221 arch = 0;
26222 for (p = cpu_arch_ver; p->val; p++)
26223 {
26224 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26225 {
26226 arch = p->val;
15afaa63 26227 arm_arch = p->flags;
62b3e311
PB
26228 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26229 }
26230 }
ee065d83 26231
9e3c6df6
PB
26232 /* The table lookup above finds the last architecture to contribute
26233 a new feature. Unfortunately, Tag13 is a subset of the union of
26234 v6T2 and v7-M, so it is never seen as contributing a new feature.
26235 We can not search for the last entry which is entirely used,
26236 because if no CPU is specified we build up only those flags
26237 actually used. Perhaps we should separate out the specified
26238 and implicit cases. Avoid taking this path for -march=all by
26239 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26240 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26241 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26242 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26243 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26244 {
26245 arch = TAG_CPU_ARCH_V7E_M;
26246 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26247 }
4ed7ed8d 26248
ff8646ee
TP
26249 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26250 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26251 {
26252 arch = TAG_CPU_ARCH_V8M_MAIN;
26253 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26254 }
ff8646ee 26255
4ed7ed8d
TP
26256 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26257 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26258 ARMv8-M, -march=all must be detected as ARMv8-A. */
26259 if (arch == TAG_CPU_ARCH_V8M_MAIN
26260 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26261 {
26262 arch = TAG_CPU_ARCH_V8;
26263 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26264 }
9e3c6df6 26265
ee065d83
PB
26266 /* Tag_CPU_name. */
26267 if (selected_cpu_name[0])
26268 {
91d6fa6a 26269 char *q;
ee065d83 26270
91d6fa6a
NC
26271 q = selected_cpu_name;
26272 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26273 {
26274 int i;
5f4273c7 26275
91d6fa6a
NC
26276 q += 4;
26277 for (i = 0; q[i]; i++)
26278 q[i] = TOUPPER (q[i]);
ee065d83 26279 }
91d6fa6a 26280 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26281 }
62f3b8c8 26282
ee065d83 26283 /* Tag_CPU_arch. */
ee3c0378 26284 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26285
62b3e311 26286 /* Tag_CPU_arch_profile. */
10c9892b 26287 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26288 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26289 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26290 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26291 profile = 'A';
62b3e311 26292 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26293 profile = 'R';
7e806470 26294 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26295 profile = 'M';
26296 else
26297 profile = '\0';
26298
26299 if (profile != '\0')
26300 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26301
15afaa63
TP
26302 /* Tag_DSP_extension. */
26303 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26304 {
26305 arm_feature_set ext;
26306
26307 /* DSP instructions not in architecture. */
26308 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26309 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26310 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26311 }
26312
ee065d83 26313 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26314 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26315 || arch == 0)
26316 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26317
ee065d83 26318 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26319 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26320 || arch == 0)
4ed7ed8d
TP
26321 {
26322 int thumb_isa_use;
26323
26324 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26325 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26326 thumb_isa_use = 3;
26327 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26328 thumb_isa_use = 2;
26329 else
26330 thumb_isa_use = 1;
26331 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26332 }
62f3b8c8 26333
ee065d83 26334 /* Tag_VFP_arch. */
a715796b
TG
26335 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26336 aeabi_set_attribute_int (Tag_VFP_arch,
26337 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26338 ? 7 : 8);
bca38921 26339 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26340 aeabi_set_attribute_int (Tag_VFP_arch,
26341 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26342 ? 5 : 6);
26343 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26344 {
26345 fp16_optional = 1;
26346 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26347 }
ada65aa3 26348 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26349 {
26350 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26351 fp16_optional = 1;
26352 }
ee3c0378
AS
26353 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26354 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26355 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26356 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26357 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26358
4547cb56
NC
26359 /* Tag_ABI_HardFP_use. */
26360 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26361 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26362 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26363
ee065d83 26364 /* Tag_WMMX_arch. */
ee3c0378
AS
26365 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26366 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26367 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26368 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26369
ee3c0378 26370 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26371 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26372 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26373 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26374 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26375 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26376 {
26377 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26378 {
26379 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26380 }
26381 else
26382 {
26383 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26384 fp16_optional = 1;
26385 }
26386 }
fa94de6b 26387
ee3c0378 26388 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26389 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26390 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26391
69239280
MGD
26392 /* Tag_DIV_use.
26393
26394 We set Tag_DIV_use to two when integer divide instructions have been used
26395 in ARM state, or when Thumb integer divide instructions have been used,
26396 but we have no architecture profile set, nor have we any ARM instructions.
26397
4ed7ed8d
TP
26398 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26399 by the base architecture.
bca38921 26400
69239280 26401 For new architectures we will have to check these tests. */
ff8646ee
TP
26402 gas_assert (arch <= TAG_CPU_ARCH_V8
26403 || (arch >= TAG_CPU_ARCH_V8M_BASE
26404 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26405 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26406 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26407 aeabi_set_attribute_int (Tag_DIV_use, 0);
26408 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26409 || (profile == '\0'
26410 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26411 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26412 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26413
26414 /* Tag_MP_extension_use. */
26415 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26416 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26417
26418 /* Tag Virtualization_use. */
26419 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26420 virt_sec |= 1;
26421 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26422 virt_sec |= 2;
26423 if (virt_sec != 0)
26424 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26425}
26426
104d59d1 26427/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26428void
26429arm_md_end (void)
26430{
ee065d83
PB
26431 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26432 return;
26433
26434 aeabi_set_public_attributes ();
ee065d83 26435}
8463be01 26436#endif /* OBJ_ELF */
ee065d83
PB
26437
26438
26439/* Parse a .cpu directive. */
26440
26441static void
26442s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26443{
e74cfd16 26444 const struct arm_cpu_option_table *opt;
ee065d83
PB
26445 char *name;
26446 char saved_char;
26447
26448 name = input_line_pointer;
5f4273c7 26449 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26450 input_line_pointer++;
26451 saved_char = *input_line_pointer;
26452 *input_line_pointer = 0;
26453
26454 /* Skip the first "all" entry. */
26455 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26456 if (streq (opt->name, name))
26457 {
e74cfd16
PB
26458 mcpu_cpu_opt = &opt->value;
26459 selected_cpu = opt->value;
ee065d83 26460 if (opt->canonical_name)
5f4273c7 26461 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26462 else
26463 {
26464 int i;
26465 for (i = 0; opt->name[i]; i++)
26466 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26467
ee065d83
PB
26468 selected_cpu_name[i] = 0;
26469 }
e74cfd16 26470 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26471 *input_line_pointer = saved_char;
26472 demand_empty_rest_of_line ();
26473 return;
26474 }
26475 as_bad (_("unknown cpu `%s'"), name);
26476 *input_line_pointer = saved_char;
26477 ignore_rest_of_line ();
26478}
26479
26480
26481/* Parse a .arch directive. */
26482
26483static void
26484s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26485{
e74cfd16 26486 const struct arm_arch_option_table *opt;
ee065d83
PB
26487 char saved_char;
26488 char *name;
26489
26490 name = input_line_pointer;
5f4273c7 26491 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26492 input_line_pointer++;
26493 saved_char = *input_line_pointer;
26494 *input_line_pointer = 0;
26495
26496 /* Skip the first "all" entry. */
26497 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26498 if (streq (opt->name, name))
26499 {
e74cfd16
PB
26500 mcpu_cpu_opt = &opt->value;
26501 selected_cpu = opt->value;
5f4273c7 26502 strcpy (selected_cpu_name, opt->name);
e74cfd16 26503 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26504 *input_line_pointer = saved_char;
26505 demand_empty_rest_of_line ();
26506 return;
26507 }
26508
26509 as_bad (_("unknown architecture `%s'\n"), name);
26510 *input_line_pointer = saved_char;
26511 ignore_rest_of_line ();
26512}
26513
26514
7a1d4c38
PB
26515/* Parse a .object_arch directive. */
26516
26517static void
26518s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26519{
26520 const struct arm_arch_option_table *opt;
26521 char saved_char;
26522 char *name;
26523
26524 name = input_line_pointer;
5f4273c7 26525 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26526 input_line_pointer++;
26527 saved_char = *input_line_pointer;
26528 *input_line_pointer = 0;
26529
26530 /* Skip the first "all" entry. */
26531 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26532 if (streq (opt->name, name))
26533 {
26534 object_arch = &opt->value;
26535 *input_line_pointer = saved_char;
26536 demand_empty_rest_of_line ();
26537 return;
26538 }
26539
26540 as_bad (_("unknown architecture `%s'\n"), name);
26541 *input_line_pointer = saved_char;
26542 ignore_rest_of_line ();
26543}
26544
69133863
MGD
26545/* Parse a .arch_extension directive. */
26546
26547static void
26548s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26549{
26550 const struct arm_option_extension_value_table *opt;
d942732e 26551 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26552 char saved_char;
26553 char *name;
26554 int adding_value = 1;
26555
26556 name = input_line_pointer;
26557 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26558 input_line_pointer++;
26559 saved_char = *input_line_pointer;
26560 *input_line_pointer = 0;
26561
26562 if (strlen (name) >= 2
26563 && strncmp (name, "no", 2) == 0)
26564 {
26565 adding_value = 0;
26566 name += 2;
26567 }
26568
26569 for (opt = arm_extensions; opt->name != NULL; opt++)
26570 if (streq (opt->name, name))
26571 {
d942732e
TP
26572 int i, nb_allowed_archs =
26573 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26574 for (i = 0; i < nb_allowed_archs; i++)
26575 {
26576 /* Empty entry. */
26577 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26578 continue;
26579 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26580 break;
26581 }
26582
26583 if (i == nb_allowed_archs)
69133863
MGD
26584 {
26585 as_bad (_("architectural extension `%s' is not allowed for the "
26586 "current base architecture"), name);
26587 break;
26588 }
26589
26590 if (adding_value)
5a70a223
JB
26591 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26592 opt->merge_value);
69133863 26593 else
5a70a223 26594 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26595
26596 mcpu_cpu_opt = &selected_cpu;
26597 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26598 *input_line_pointer = saved_char;
26599 demand_empty_rest_of_line ();
26600 return;
26601 }
26602
26603 if (opt->name == NULL)
e673710a 26604 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26605
26606 *input_line_pointer = saved_char;
26607 ignore_rest_of_line ();
26608}
26609
ee065d83
PB
26610/* Parse a .fpu directive. */
26611
26612static void
26613s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26614{
69133863 26615 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26616 char saved_char;
26617 char *name;
26618
26619 name = input_line_pointer;
5f4273c7 26620 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26621 input_line_pointer++;
26622 saved_char = *input_line_pointer;
26623 *input_line_pointer = 0;
5f4273c7 26624
ee065d83
PB
26625 for (opt = arm_fpus; opt->name != NULL; opt++)
26626 if (streq (opt->name, name))
26627 {
e74cfd16
PB
26628 mfpu_opt = &opt->value;
26629 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26630 *input_line_pointer = saved_char;
26631 demand_empty_rest_of_line ();
26632 return;
26633 }
26634
26635 as_bad (_("unknown floating point format `%s'\n"), name);
26636 *input_line_pointer = saved_char;
26637 ignore_rest_of_line ();
26638}
ee065d83 26639
794ba86a 26640/* Copy symbol information. */
f31fef98 26641
794ba86a
DJ
26642void
26643arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26644{
26645 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26646}
e04befd0 26647
f31fef98 26648#ifdef OBJ_ELF
e04befd0
AS
26649/* Given a symbolic attribute NAME, return the proper integer value.
26650 Returns -1 if the attribute is not known. */
f31fef98 26651
e04befd0
AS
26652int
26653arm_convert_symbolic_attribute (const char *name)
26654{
f31fef98
NC
26655 static const struct
26656 {
26657 const char * name;
26658 const int tag;
26659 }
26660 attribute_table[] =
26661 {
26662 /* When you modify this table you should
26663 also modify the list in doc/c-arm.texi. */
e04befd0 26664#define T(tag) {#tag, tag}
f31fef98
NC
26665 T (Tag_CPU_raw_name),
26666 T (Tag_CPU_name),
26667 T (Tag_CPU_arch),
26668 T (Tag_CPU_arch_profile),
26669 T (Tag_ARM_ISA_use),
26670 T (Tag_THUMB_ISA_use),
75375b3e 26671 T (Tag_FP_arch),
f31fef98
NC
26672 T (Tag_VFP_arch),
26673 T (Tag_WMMX_arch),
26674 T (Tag_Advanced_SIMD_arch),
26675 T (Tag_PCS_config),
26676 T (Tag_ABI_PCS_R9_use),
26677 T (Tag_ABI_PCS_RW_data),
26678 T (Tag_ABI_PCS_RO_data),
26679 T (Tag_ABI_PCS_GOT_use),
26680 T (Tag_ABI_PCS_wchar_t),
26681 T (Tag_ABI_FP_rounding),
26682 T (Tag_ABI_FP_denormal),
26683 T (Tag_ABI_FP_exceptions),
26684 T (Tag_ABI_FP_user_exceptions),
26685 T (Tag_ABI_FP_number_model),
75375b3e 26686 T (Tag_ABI_align_needed),
f31fef98 26687 T (Tag_ABI_align8_needed),
75375b3e 26688 T (Tag_ABI_align_preserved),
f31fef98
NC
26689 T (Tag_ABI_align8_preserved),
26690 T (Tag_ABI_enum_size),
26691 T (Tag_ABI_HardFP_use),
26692 T (Tag_ABI_VFP_args),
26693 T (Tag_ABI_WMMX_args),
26694 T (Tag_ABI_optimization_goals),
26695 T (Tag_ABI_FP_optimization_goals),
26696 T (Tag_compatibility),
26697 T (Tag_CPU_unaligned_access),
75375b3e 26698 T (Tag_FP_HP_extension),
f31fef98
NC
26699 T (Tag_VFP_HP_extension),
26700 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26701 T (Tag_MPextension_use),
26702 T (Tag_DIV_use),
f31fef98
NC
26703 T (Tag_nodefaults),
26704 T (Tag_also_compatible_with),
26705 T (Tag_conformance),
26706 T (Tag_T2EE_use),
26707 T (Tag_Virtualization_use),
15afaa63 26708 T (Tag_DSP_extension),
cd21e546 26709 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26710#undef T
f31fef98 26711 };
e04befd0
AS
26712 unsigned int i;
26713
26714 if (name == NULL)
26715 return -1;
26716
f31fef98 26717 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26718 if (streq (name, attribute_table[i].name))
e04befd0
AS
26719 return attribute_table[i].tag;
26720
26721 return -1;
26722}
267bf995
RR
26723
26724
93ef582d
NC
26725/* Apply sym value for relocations only in the case that they are for
26726 local symbols in the same segment as the fixup and you have the
26727 respective architectural feature for blx and simple switches. */
267bf995 26728int
93ef582d 26729arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26730{
26731 if (fixP->fx_addsy
26732 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26733 /* PR 17444: If the local symbol is in a different section then a reloc
26734 will always be generated for it, so applying the symbol value now
26735 will result in a double offset being stored in the relocation. */
26736 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26737 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26738 {
26739 switch (fixP->fx_r_type)
26740 {
26741 case BFD_RELOC_ARM_PCREL_BLX:
26742 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26743 if (ARM_IS_FUNC (fixP->fx_addsy))
26744 return 1;
26745 break;
26746
26747 case BFD_RELOC_ARM_PCREL_CALL:
26748 case BFD_RELOC_THUMB_PCREL_BLX:
26749 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26750 return 1;
267bf995
RR
26751 break;
26752
26753 default:
26754 break;
26755 }
26756
26757 }
26758 return 0;
26759}
f31fef98 26760#endif /* OBJ_ELF */