Fix memory leaks in the sysinfo program.
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
2571583a 2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 158static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
160static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 164#ifdef OBJ_ELF
e74cfd16 165static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 166#endif
e74cfd16
PB
167static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
168
169#ifdef CPU_DEFAULT
170static const arm_feature_set cpu_default = CPU_DEFAULT;
171#endif
172
823d2571
TG
173static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
174static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
175static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
176static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
177static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
178static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
179static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
180static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 181static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
182 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
183static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
184static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
185static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
186static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
187static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
188static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
189static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
190static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
191static const arm_feature_set arm_ext_v6_notm =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
193static const arm_feature_set arm_ext_v6_dsp =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
195static const arm_feature_set arm_ext_barrier =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
197static const arm_feature_set arm_ext_msr =
198 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
199static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
200static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
201static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
202static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 203#ifdef OBJ_ELF
823d2571 204static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 205#endif
823d2571 206static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 207static const arm_feature_set arm_ext_m =
16a1fa25
TP
208 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M,
209 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
210static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
211static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
212static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
213static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
214static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 215static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 216static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
217static const arm_feature_set arm_ext_v8m_main =
218 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
219/* Instructions in ARMv8-M only found in M profile architectures. */
220static const arm_feature_set arm_ext_v8m_m_only =
221 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
222static const arm_feature_set arm_ext_v6t2_v8m =
223 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
224/* Instructions shared between ARMv8-A and ARMv8-M. */
225static const arm_feature_set arm_ext_atomics =
226 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 227#ifdef OBJ_ELF
15afaa63
TP
228/* DSP instructions Tag_DSP_extension refers to. */
229static const arm_feature_set arm_ext_dsp =
230 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 231#endif
4d1464f2
MW
232static const arm_feature_set arm_ext_ras =
233 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
234/* FP16 instructions. */
235static const arm_feature_set arm_ext_fp16 =
236 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
49e8a725
SN
237static const arm_feature_set arm_ext_v8_3 =
238 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
239
240static const arm_feature_set arm_arch_any = ARM_ANY;
f85d59c3 241static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
242static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
243static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
69c9e028 244#ifdef OBJ_ELF
251665fc 245static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
69c9e028 246#endif
e74cfd16 247
2d447fca 248static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 249 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 250static const arm_feature_set arm_cext_iwmmxt =
823d2571 251 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 252static const arm_feature_set arm_cext_xscale =
823d2571 253 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 254static const arm_feature_set arm_cext_maverick =
823d2571
TG
255 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
256static const arm_feature_set fpu_fpa_ext_v1 =
257 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
258static const arm_feature_set fpu_fpa_ext_v2 =
259 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 260static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
261 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
262static const arm_feature_set fpu_vfp_ext_v1 =
263 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
264static const arm_feature_set fpu_vfp_ext_v2 =
265 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
266static const arm_feature_set fpu_vfp_ext_v3xd =
267 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
268static const arm_feature_set fpu_vfp_ext_v3 =
269 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 270static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
271 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
272static const arm_feature_set fpu_neon_ext_v1 =
273 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 274static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 275 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 276#ifdef OBJ_ELF
823d2571
TG
277static const arm_feature_set fpu_vfp_fp16 =
278 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
279static const arm_feature_set fpu_neon_ext_fma =
280 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 281#endif
823d2571
TG
282static const arm_feature_set fpu_vfp_ext_fma =
283 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 284static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 285 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 286static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 287 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 288static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 289 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 290static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 291 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 292static const arm_feature_set crc_ext_armv8 =
823d2571 293 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 294static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 295 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 296
33a392fb 297static int mfloat_abi_opt = -1;
e74cfd16
PB
298/* Record user cpu selection for object attributes. */
299static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 300/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 301static char selected_cpu_name[20];
8d67f500 302
aacf0b33
KT
303extern FLONUM_TYPE generic_floating_point_number;
304
8d67f500
NC
305/* Return if no cpu was selected on command-line. */
306static bfd_boolean
307no_cpu_selected (void)
308{
823d2571 309 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
310}
311
7cc69913 312#ifdef OBJ_ELF
deeaaff8
DJ
313# ifdef EABI_DEFAULT
314static int meabi_flags = EABI_DEFAULT;
315# else
d507cf36 316static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 317# endif
e1da3f5b 318
ee3c0378
AS
319static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
320
e1da3f5b 321bfd_boolean
5f4273c7 322arm_is_eabi (void)
e1da3f5b
PB
323{
324 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
325}
7cc69913 326#endif
b99bd4ef 327
b99bd4ef 328#ifdef OBJ_ELF
c19d1205 329/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
330symbolS * GOT_symbol;
331#endif
332
b99bd4ef
NC
333/* 0: assemble for ARM,
334 1: assemble for Thumb,
335 2: assemble for Thumb even though target CPU does not support thumb
336 instructions. */
337static int thumb_mode = 0;
8dc2430f
NC
338/* A value distinct from the possible values for thumb_mode that we
339 can use to record whether thumb_mode has been copied into the
340 tc_frag_data field of a frag. */
341#define MODE_RECORDED (1 << 4)
b99bd4ef 342
e07e6e58
NC
343/* Specifies the intrinsic IT insn behavior mode. */
344enum implicit_it_mode
345{
346 IMPLICIT_IT_MODE_NEVER = 0x00,
347 IMPLICIT_IT_MODE_ARM = 0x01,
348 IMPLICIT_IT_MODE_THUMB = 0x02,
349 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
350};
351static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
352
c19d1205
ZW
353/* If unified_syntax is true, we are processing the new unified
354 ARM/Thumb syntax. Important differences from the old ARM mode:
355
356 - Immediate operands do not require a # prefix.
357 - Conditional affixes always appear at the end of the
358 instruction. (For backward compatibility, those instructions
359 that formerly had them in the middle, continue to accept them
360 there.)
361 - The IT instruction may appear, and if it does is validated
362 against subsequent conditional affixes. It does not generate
363 machine code.
364
365 Important differences from the old Thumb mode:
366
367 - Immediate operands do not require a # prefix.
368 - Most of the V6T2 instructions are only available in unified mode.
369 - The .N and .W suffixes are recognized and honored (it is an error
370 if they cannot be honored).
371 - All instructions set the flags if and only if they have an 's' affix.
372 - Conditional affixes may be used. They are validated against
373 preceding IT instructions. Unlike ARM mode, you cannot use a
374 conditional affix except in the scope of an IT instruction. */
375
376static bfd_boolean unified_syntax = FALSE;
b99bd4ef 377
bacebabc
RM
378/* An immediate operand can start with #, and ld*, st*, pld operands
379 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
380 before a [, which can appear as the first operand for pld.
381 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
382const char arm_symbol_chars[] = "#[]{}";
bacebabc 383
5287ad62
JB
384enum neon_el_type
385{
dcbf9037 386 NT_invtype,
5287ad62
JB
387 NT_untyped,
388 NT_integer,
389 NT_float,
390 NT_poly,
391 NT_signed,
dcbf9037 392 NT_unsigned
5287ad62
JB
393};
394
395struct neon_type_el
396{
397 enum neon_el_type type;
398 unsigned size;
399};
400
401#define NEON_MAX_TYPE_ELS 4
402
403struct neon_type
404{
405 struct neon_type_el el[NEON_MAX_TYPE_ELS];
406 unsigned elems;
407};
408
e07e6e58
NC
409enum it_instruction_type
410{
411 OUTSIDE_IT_INSN,
412 INSIDE_IT_INSN,
413 INSIDE_IT_LAST_INSN,
414 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 415 if inside, should be the last one. */
e07e6e58 416 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 417 i.e. BKPT and NOP. */
e07e6e58
NC
418 IT_INSN /* The IT insn has been parsed. */
419};
420
ad6cec43
MGD
421/* The maximum number of operands we need. */
422#define ARM_IT_MAX_OPERANDS 6
423
b99bd4ef
NC
424struct arm_it
425{
c19d1205 426 const char * error;
b99bd4ef 427 unsigned long instruction;
c19d1205
ZW
428 int size;
429 int size_req;
430 int cond;
037e8744
JB
431 /* "uncond_value" is set to the value in place of the conditional field in
432 unconditional versions of the instruction, or -1 if nothing is
433 appropriate. */
434 int uncond_value;
5287ad62 435 struct neon_type vectype;
88714cb8
DG
436 /* This does not indicate an actual NEON instruction, only that
437 the mnemonic accepts neon-style type suffixes. */
438 int is_neon;
0110f2b8
PB
439 /* Set to the opcode if the instruction needs relaxation.
440 Zero if the instruction is not relaxed. */
441 unsigned long relax;
b99bd4ef
NC
442 struct
443 {
444 bfd_reloc_code_real_type type;
c19d1205
ZW
445 expressionS exp;
446 int pc_rel;
b99bd4ef 447 } reloc;
b99bd4ef 448
e07e6e58
NC
449 enum it_instruction_type it_insn_type;
450
c19d1205
ZW
451 struct
452 {
453 unsigned reg;
ca3f61f7 454 signed int imm;
dcbf9037 455 struct neon_type_el vectype;
ca3f61f7
NC
456 unsigned present : 1; /* Operand present. */
457 unsigned isreg : 1; /* Operand was a register. */
458 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
459 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
460 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 461 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
462 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
463 instructions. This allows us to disambiguate ARM <-> vector insns. */
464 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 465 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 466 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 467 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
468 unsigned hasreloc : 1; /* Operand has relocation suffix. */
469 unsigned writeback : 1; /* Operand has trailing ! */
470 unsigned preind : 1; /* Preindexed address. */
471 unsigned postind : 1; /* Postindexed address. */
472 unsigned negative : 1; /* Index register was negated. */
473 unsigned shifted : 1; /* Shift applied to operation. */
474 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 475 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
476};
477
c19d1205 478static struct arm_it inst;
b99bd4ef
NC
479
480#define NUM_FLOAT_VALS 8
481
05d2d07e 482const char * fp_const[] =
b99bd4ef
NC
483{
484 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
485};
486
c19d1205 487/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
488#define MAX_LITTLENUMS 6
489
490LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
491
492#define FAIL (-1)
493#define SUCCESS (0)
494
495#define SUFF_S 1
496#define SUFF_D 2
497#define SUFF_E 3
498#define SUFF_P 4
499
c19d1205
ZW
500#define CP_T_X 0x00008000
501#define CP_T_Y 0x00400000
b99bd4ef 502
c19d1205
ZW
503#define CONDS_BIT 0x00100000
504#define LOAD_BIT 0x00100000
b99bd4ef
NC
505
506#define DOUBLE_LOAD_FLAG 0x00000001
507
508struct asm_cond
509{
d3ce72d0 510 const char * template_name;
c921be7d 511 unsigned long value;
b99bd4ef
NC
512};
513
c19d1205 514#define COND_ALWAYS 0xE
b99bd4ef 515
b99bd4ef
NC
516struct asm_psr
517{
d3ce72d0 518 const char * template_name;
c921be7d 519 unsigned long field;
b99bd4ef
NC
520};
521
62b3e311
PB
522struct asm_barrier_opt
523{
e797f7e0
MGD
524 const char * template_name;
525 unsigned long value;
526 const arm_feature_set arch;
62b3e311
PB
527};
528
2d2255b5 529/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
530#define SPSR_BIT (1 << 22)
531
c19d1205
ZW
532/* The individual PSR flag bits. */
533#define PSR_c (1 << 16)
534#define PSR_x (1 << 17)
535#define PSR_s (1 << 18)
536#define PSR_f (1 << 19)
b99bd4ef 537
c19d1205 538struct reloc_entry
bfae80f2 539{
e0471c16 540 const char * name;
c921be7d 541 bfd_reloc_code_real_type reloc;
bfae80f2
RE
542};
543
5287ad62 544enum vfp_reg_pos
bfae80f2 545{
5287ad62
JB
546 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
547 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
548};
549
550enum vfp_ldstm_type
551{
552 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
553};
554
dcbf9037
JB
555/* Bits for DEFINED field in neon_typed_alias. */
556#define NTA_HASTYPE 1
557#define NTA_HASINDEX 2
558
559struct neon_typed_alias
560{
c921be7d
NC
561 unsigned char defined;
562 unsigned char index;
563 struct neon_type_el eltype;
dcbf9037
JB
564};
565
c19d1205
ZW
566/* ARM register categories. This includes coprocessor numbers and various
567 architecture extensions' registers. */
568enum arm_reg_type
bfae80f2 569{
c19d1205
ZW
570 REG_TYPE_RN,
571 REG_TYPE_CP,
572 REG_TYPE_CN,
573 REG_TYPE_FN,
574 REG_TYPE_VFS,
575 REG_TYPE_VFD,
5287ad62 576 REG_TYPE_NQ,
037e8744 577 REG_TYPE_VFSD,
5287ad62 578 REG_TYPE_NDQ,
037e8744 579 REG_TYPE_NSDQ,
c19d1205
ZW
580 REG_TYPE_VFC,
581 REG_TYPE_MVF,
582 REG_TYPE_MVD,
583 REG_TYPE_MVFX,
584 REG_TYPE_MVDX,
585 REG_TYPE_MVAX,
586 REG_TYPE_DSPSC,
587 REG_TYPE_MMXWR,
588 REG_TYPE_MMXWC,
589 REG_TYPE_MMXWCG,
590 REG_TYPE_XSCALE,
90ec0d68 591 REG_TYPE_RNB
bfae80f2
RE
592};
593
dcbf9037
JB
594/* Structure for a hash table entry for a register.
595 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
596 information which states whether a vector type or index is specified (for a
597 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
598struct reg_entry
599{
c921be7d 600 const char * name;
90ec0d68 601 unsigned int number;
c921be7d
NC
602 unsigned char type;
603 unsigned char builtin;
604 struct neon_typed_alias * neon;
6c43fab6
RE
605};
606
c19d1205 607/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 608const char * const reg_expected_msgs[] =
c19d1205
ZW
609{
610 N_("ARM register expected"),
611 N_("bad or missing co-processor number"),
612 N_("co-processor register expected"),
613 N_("FPA register expected"),
614 N_("VFP single precision register expected"),
5287ad62
JB
615 N_("VFP/Neon double precision register expected"),
616 N_("Neon quad precision register expected"),
037e8744 617 N_("VFP single or double precision register expected"),
5287ad62 618 N_("Neon double or quad precision register expected"),
037e8744 619 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
620 N_("VFP system register expected"),
621 N_("Maverick MVF register expected"),
622 N_("Maverick MVD register expected"),
623 N_("Maverick MVFX register expected"),
624 N_("Maverick MVDX register expected"),
625 N_("Maverick MVAX register expected"),
626 N_("Maverick DSPSC register expected"),
627 N_("iWMMXt data register expected"),
628 N_("iWMMXt control register expected"),
629 N_("iWMMXt scalar register expected"),
630 N_("XScale accumulator register expected"),
6c43fab6
RE
631};
632
c19d1205 633/* Some well known registers that we refer to directly elsewhere. */
bd340a04 634#define REG_R12 12
c19d1205
ZW
635#define REG_SP 13
636#define REG_LR 14
637#define REG_PC 15
404ff6b5 638
b99bd4ef
NC
639/* ARM instructions take 4bytes in the object file, Thumb instructions
640 take 2: */
c19d1205 641#define INSN_SIZE 4
b99bd4ef
NC
642
643struct asm_opcode
644{
645 /* Basic string to match. */
d3ce72d0 646 const char * template_name;
c19d1205
ZW
647
648 /* Parameters to instruction. */
5be8be5d 649 unsigned int operands[8];
c19d1205
ZW
650
651 /* Conditional tag - see opcode_lookup. */
652 unsigned int tag : 4;
b99bd4ef
NC
653
654 /* Basic instruction code. */
c19d1205 655 unsigned int avalue : 28;
b99bd4ef 656
c19d1205
ZW
657 /* Thumb-format instruction code. */
658 unsigned int tvalue;
b99bd4ef 659
90e4755a 660 /* Which architecture variant provides this instruction. */
c921be7d
NC
661 const arm_feature_set * avariant;
662 const arm_feature_set * tvariant;
c19d1205
ZW
663
664 /* Function to call to encode instruction in ARM format. */
665 void (* aencode) (void);
b99bd4ef 666
c19d1205
ZW
667 /* Function to call to encode instruction in Thumb format. */
668 void (* tencode) (void);
b99bd4ef
NC
669};
670
a737bd4d
NC
671/* Defines for various bits that we will want to toggle. */
672#define INST_IMMEDIATE 0x02000000
673#define OFFSET_REG 0x02000000
c19d1205 674#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
675#define SHIFT_BY_REG 0x00000010
676#define PRE_INDEX 0x01000000
677#define INDEX_UP 0x00800000
678#define WRITE_BACK 0x00200000
679#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 680#define CPSI_MMOD 0x00020000
90e4755a 681
a737bd4d
NC
682#define LITERAL_MASK 0xf000f000
683#define OPCODE_MASK 0xfe1fffff
684#define V4_STR_BIT 0x00000020
8335d6aa 685#define VLDR_VMOV_SAME 0x0040f000
90e4755a 686
efd81785
PB
687#define T2_SUBS_PC_LR 0xf3de8f00
688
a737bd4d 689#define DATA_OP_SHIFT 21
bada4342 690#define SBIT_SHIFT 20
90e4755a 691
ef8d22e6
PB
692#define T2_OPCODE_MASK 0xfe1fffff
693#define T2_DATA_OP_SHIFT 21
bada4342 694#define T2_SBIT_SHIFT 20
ef8d22e6 695
6530b175
NC
696#define A_COND_MASK 0xf0000000
697#define A_PUSH_POP_OP_MASK 0x0fff0000
698
699/* Opcodes for pushing/poping registers to/from the stack. */
700#define A1_OPCODE_PUSH 0x092d0000
701#define A2_OPCODE_PUSH 0x052d0004
702#define A2_OPCODE_POP 0x049d0004
703
a737bd4d
NC
704/* Codes to distinguish the arithmetic instructions. */
705#define OPCODE_AND 0
706#define OPCODE_EOR 1
707#define OPCODE_SUB 2
708#define OPCODE_RSB 3
709#define OPCODE_ADD 4
710#define OPCODE_ADC 5
711#define OPCODE_SBC 6
712#define OPCODE_RSC 7
713#define OPCODE_TST 8
714#define OPCODE_TEQ 9
715#define OPCODE_CMP 10
716#define OPCODE_CMN 11
717#define OPCODE_ORR 12
718#define OPCODE_MOV 13
719#define OPCODE_BIC 14
720#define OPCODE_MVN 15
90e4755a 721
ef8d22e6
PB
722#define T2_OPCODE_AND 0
723#define T2_OPCODE_BIC 1
724#define T2_OPCODE_ORR 2
725#define T2_OPCODE_ORN 3
726#define T2_OPCODE_EOR 4
727#define T2_OPCODE_ADD 8
728#define T2_OPCODE_ADC 10
729#define T2_OPCODE_SBC 11
730#define T2_OPCODE_SUB 13
731#define T2_OPCODE_RSB 14
732
a737bd4d
NC
733#define T_OPCODE_MUL 0x4340
734#define T_OPCODE_TST 0x4200
735#define T_OPCODE_CMN 0x42c0
736#define T_OPCODE_NEG 0x4240
737#define T_OPCODE_MVN 0x43c0
90e4755a 738
a737bd4d
NC
739#define T_OPCODE_ADD_R3 0x1800
740#define T_OPCODE_SUB_R3 0x1a00
741#define T_OPCODE_ADD_HI 0x4400
742#define T_OPCODE_ADD_ST 0xb000
743#define T_OPCODE_SUB_ST 0xb080
744#define T_OPCODE_ADD_SP 0xa800
745#define T_OPCODE_ADD_PC 0xa000
746#define T_OPCODE_ADD_I8 0x3000
747#define T_OPCODE_SUB_I8 0x3800
748#define T_OPCODE_ADD_I3 0x1c00
749#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 750
a737bd4d
NC
751#define T_OPCODE_ASR_R 0x4100
752#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
753#define T_OPCODE_LSR_R 0x40c0
754#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
755#define T_OPCODE_ASR_I 0x1000
756#define T_OPCODE_LSL_I 0x0000
757#define T_OPCODE_LSR_I 0x0800
b99bd4ef 758
a737bd4d
NC
759#define T_OPCODE_MOV_I8 0x2000
760#define T_OPCODE_CMP_I8 0x2800
761#define T_OPCODE_CMP_LR 0x4280
762#define T_OPCODE_MOV_HR 0x4600
763#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 764
a737bd4d
NC
765#define T_OPCODE_LDR_PC 0x4800
766#define T_OPCODE_LDR_SP 0x9800
767#define T_OPCODE_STR_SP 0x9000
768#define T_OPCODE_LDR_IW 0x6800
769#define T_OPCODE_STR_IW 0x6000
770#define T_OPCODE_LDR_IH 0x8800
771#define T_OPCODE_STR_IH 0x8000
772#define T_OPCODE_LDR_IB 0x7800
773#define T_OPCODE_STR_IB 0x7000
774#define T_OPCODE_LDR_RW 0x5800
775#define T_OPCODE_STR_RW 0x5000
776#define T_OPCODE_LDR_RH 0x5a00
777#define T_OPCODE_STR_RH 0x5200
778#define T_OPCODE_LDR_RB 0x5c00
779#define T_OPCODE_STR_RB 0x5400
c9b604bd 780
a737bd4d
NC
781#define T_OPCODE_PUSH 0xb400
782#define T_OPCODE_POP 0xbc00
b99bd4ef 783
2fc8bdac 784#define T_OPCODE_BRANCH 0xe000
b99bd4ef 785
a737bd4d 786#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 787#define THUMB_PP_PC_LR 0x0100
c19d1205 788#define THUMB_LOAD_BIT 0x0800
53365c0d 789#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
790
791#define BAD_ARGS _("bad arguments to instruction")
fdfde340 792#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
793#define BAD_PC _("r15 not allowed here")
794#define BAD_COND _("instruction cannot be conditional")
795#define BAD_OVERLAP _("registers may not be the same")
796#define BAD_HIREG _("lo register required")
797#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 798#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
799#define BAD_BRANCH _("branch must be last instruction in IT block")
800#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 801#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
802#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
803#define BAD_IT_COND _("incorrect condition in IT block")
804#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 805#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
806#define BAD_PC_ADDRESSING \
807 _("cannot use register index with PC-relative addressing")
808#define BAD_PC_WRITEBACK \
809 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
810#define BAD_RANGE _("branch out of range")
811#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 812#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 813#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 814
c921be7d
NC
815static struct hash_control * arm_ops_hsh;
816static struct hash_control * arm_cond_hsh;
817static struct hash_control * arm_shift_hsh;
818static struct hash_control * arm_psr_hsh;
819static struct hash_control * arm_v7m_psr_hsh;
820static struct hash_control * arm_reg_hsh;
821static struct hash_control * arm_reloc_hsh;
822static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 823
b99bd4ef
NC
824/* Stuff needed to resolve the label ambiguity
825 As:
826 ...
827 label: <insn>
828 may differ from:
829 ...
830 label:
5f4273c7 831 <insn> */
b99bd4ef
NC
832
833symbolS * last_label_seen;
b34976b6 834static int label_is_thumb_function_name = FALSE;
e07e6e58 835
3d0c9500
NC
836/* Literal pool structure. Held on a per-section
837 and per-sub-section basis. */
a737bd4d 838
c19d1205 839#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 840typedef struct literal_pool
b99bd4ef 841{
c921be7d
NC
842 expressionS literals [MAX_LITERAL_POOL_SIZE];
843 unsigned int next_free_entry;
844 unsigned int id;
845 symbolS * symbol;
846 segT section;
847 subsegT sub_section;
a8040cf2
NC
848#ifdef OBJ_ELF
849 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
850#endif
c921be7d 851 struct literal_pool * next;
8335d6aa 852 unsigned int alignment;
3d0c9500 853} literal_pool;
b99bd4ef 854
3d0c9500
NC
855/* Pointer to a linked list of literal pools. */
856literal_pool * list_of_pools = NULL;
e27ec89e 857
2e6976a8
DG
858typedef enum asmfunc_states
859{
860 OUTSIDE_ASMFUNC,
861 WAITING_ASMFUNC_NAME,
862 WAITING_ENDASMFUNC
863} asmfunc_states;
864
865static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
866
e07e6e58
NC
867#ifdef OBJ_ELF
868# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
869#else
870static struct current_it now_it;
871#endif
872
873static inline int
874now_it_compatible (int cond)
875{
876 return (cond & ~1) == (now_it.cc & ~1);
877}
878
879static inline int
880conditional_insn (void)
881{
882 return inst.cond != COND_ALWAYS;
883}
884
885static int in_it_block (void);
886
887static int handle_it_state (void);
888
889static void force_automatic_it_block_close (void);
890
c921be7d
NC
891static void it_fsm_post_encode (void);
892
e07e6e58
NC
893#define set_it_insn_type(type) \
894 do \
895 { \
896 inst.it_insn_type = type; \
897 if (handle_it_state () == FAIL) \
477330fc 898 return; \
e07e6e58
NC
899 } \
900 while (0)
901
c921be7d
NC
902#define set_it_insn_type_nonvoid(type, failret) \
903 do \
904 { \
905 inst.it_insn_type = type; \
906 if (handle_it_state () == FAIL) \
477330fc 907 return failret; \
c921be7d
NC
908 } \
909 while(0)
910
e07e6e58
NC
911#define set_it_insn_type_last() \
912 do \
913 { \
914 if (inst.cond == COND_ALWAYS) \
477330fc 915 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 916 else \
477330fc 917 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
918 } \
919 while (0)
920
c19d1205 921/* Pure syntax. */
b99bd4ef 922
c19d1205
ZW
923/* This array holds the chars that always start a comment. If the
924 pre-processor is disabled, these aren't very useful. */
2e6976a8 925char arm_comment_chars[] = "@";
3d0c9500 926
c19d1205
ZW
927/* This array holds the chars that only start a comment at the beginning of
928 a line. If the line seems to have the form '# 123 filename'
929 .line and .file directives will appear in the pre-processed output. */
930/* Note that input_file.c hand checks for '#' at the beginning of the
931 first line of the input file. This is because the compiler outputs
932 #NO_APP at the beginning of its output. */
933/* Also note that comments like this one will always work. */
934const char line_comment_chars[] = "#";
3d0c9500 935
2e6976a8 936char arm_line_separator_chars[] = ";";
b99bd4ef 937
c19d1205
ZW
938/* Chars that can be used to separate mant
939 from exp in floating point numbers. */
940const char EXP_CHARS[] = "eE";
3d0c9500 941
c19d1205
ZW
942/* Chars that mean this number is a floating point constant. */
943/* As in 0f12.456 */
944/* or 0d1.2345e12 */
b99bd4ef 945
c19d1205 946const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 947
c19d1205
ZW
948/* Prefix characters that indicate the start of an immediate
949 value. */
950#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 951
c19d1205
ZW
952/* Separator character handling. */
953
954#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
955
956static inline int
957skip_past_char (char ** str, char c)
958{
8ab8155f
NC
959 /* PR gas/14987: Allow for whitespace before the expected character. */
960 skip_whitespace (*str);
427d0db6 961
c19d1205
ZW
962 if (**str == c)
963 {
964 (*str)++;
965 return SUCCESS;
3d0c9500 966 }
c19d1205
ZW
967 else
968 return FAIL;
969}
c921be7d 970
c19d1205 971#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 972
c19d1205
ZW
973/* Arithmetic expressions (possibly involving symbols). */
974
975/* Return TRUE if anything in the expression is a bignum. */
976
977static int
978walk_no_bignums (symbolS * sp)
979{
980 if (symbol_get_value_expression (sp)->X_op == O_big)
981 return 1;
982
983 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 984 {
c19d1205
ZW
985 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
986 || (symbol_get_value_expression (sp)->X_op_symbol
987 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
988 }
989
c19d1205 990 return 0;
3d0c9500
NC
991}
992
c19d1205
ZW
993static int in_my_get_expression = 0;
994
995/* Third argument to my_get_expression. */
996#define GE_NO_PREFIX 0
997#define GE_IMM_PREFIX 1
998#define GE_OPT_PREFIX 2
5287ad62
JB
999/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1000 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1001#define GE_OPT_PREFIX_BIG 3
a737bd4d 1002
b99bd4ef 1003static int
c19d1205 1004my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1005{
c19d1205
ZW
1006 char * save_in;
1007 segT seg;
b99bd4ef 1008
c19d1205
ZW
1009 /* In unified syntax, all prefixes are optional. */
1010 if (unified_syntax)
5287ad62 1011 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1012 : GE_OPT_PREFIX;
b99bd4ef 1013
c19d1205 1014 switch (prefix_mode)
b99bd4ef 1015 {
c19d1205
ZW
1016 case GE_NO_PREFIX: break;
1017 case GE_IMM_PREFIX:
1018 if (!is_immediate_prefix (**str))
1019 {
1020 inst.error = _("immediate expression requires a # prefix");
1021 return FAIL;
1022 }
1023 (*str)++;
1024 break;
1025 case GE_OPT_PREFIX:
5287ad62 1026 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1027 if (is_immediate_prefix (**str))
1028 (*str)++;
1029 break;
1030 default: abort ();
1031 }
b99bd4ef 1032
c19d1205 1033 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1034
c19d1205
ZW
1035 save_in = input_line_pointer;
1036 input_line_pointer = *str;
1037 in_my_get_expression = 1;
1038 seg = expression (ep);
1039 in_my_get_expression = 0;
1040
f86adc07 1041 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1042 {
f86adc07 1043 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1044 *str = input_line_pointer;
1045 input_line_pointer = save_in;
1046 if (inst.error == NULL)
f86adc07
NS
1047 inst.error = (ep->X_op == O_absent
1048 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1049 return 1;
1050 }
b99bd4ef 1051
c19d1205
ZW
1052#ifdef OBJ_AOUT
1053 if (seg != absolute_section
1054 && seg != text_section
1055 && seg != data_section
1056 && seg != bss_section
1057 && seg != undefined_section)
1058 {
1059 inst.error = _("bad segment");
1060 *str = input_line_pointer;
1061 input_line_pointer = save_in;
1062 return 1;
b99bd4ef 1063 }
87975d2a
AM
1064#else
1065 (void) seg;
c19d1205 1066#endif
b99bd4ef 1067
c19d1205
ZW
1068 /* Get rid of any bignums now, so that we don't generate an error for which
1069 we can't establish a line number later on. Big numbers are never valid
1070 in instructions, which is where this routine is always called. */
5287ad62
JB
1071 if (prefix_mode != GE_OPT_PREFIX_BIG
1072 && (ep->X_op == O_big
477330fc 1073 || (ep->X_add_symbol
5287ad62 1074 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1075 || (ep->X_op_symbol
5287ad62 1076 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1077 {
1078 inst.error = _("invalid constant");
1079 *str = input_line_pointer;
1080 input_line_pointer = save_in;
1081 return 1;
1082 }
b99bd4ef 1083
c19d1205
ZW
1084 *str = input_line_pointer;
1085 input_line_pointer = save_in;
1086 return 0;
b99bd4ef
NC
1087}
1088
c19d1205
ZW
1089/* Turn a string in input_line_pointer into a floating point constant
1090 of type TYPE, and store the appropriate bytes in *LITP. The number
1091 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1092 returned, or NULL on OK.
b99bd4ef 1093
c19d1205
ZW
1094 Note that fp constants aren't represent in the normal way on the ARM.
1095 In big endian mode, things are as expected. However, in little endian
1096 mode fp constants are big-endian word-wise, and little-endian byte-wise
1097 within the words. For example, (double) 1.1 in big endian mode is
1098 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1099 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1100
c19d1205 1101 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1102
6d4af3c2 1103const char *
c19d1205
ZW
1104md_atof (int type, char * litP, int * sizeP)
1105{
1106 int prec;
1107 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1108 char *t;
1109 int i;
b99bd4ef 1110
c19d1205
ZW
1111 switch (type)
1112 {
1113 case 'f':
1114 case 'F':
1115 case 's':
1116 case 'S':
1117 prec = 2;
1118 break;
b99bd4ef 1119
c19d1205
ZW
1120 case 'd':
1121 case 'D':
1122 case 'r':
1123 case 'R':
1124 prec = 4;
1125 break;
b99bd4ef 1126
c19d1205
ZW
1127 case 'x':
1128 case 'X':
499ac353 1129 prec = 5;
c19d1205 1130 break;
b99bd4ef 1131
c19d1205
ZW
1132 case 'p':
1133 case 'P':
499ac353 1134 prec = 5;
c19d1205 1135 break;
a737bd4d 1136
c19d1205
ZW
1137 default:
1138 *sizeP = 0;
499ac353 1139 return _("Unrecognized or unsupported floating point constant");
c19d1205 1140 }
b99bd4ef 1141
c19d1205
ZW
1142 t = atof_ieee (input_line_pointer, type, words);
1143 if (t)
1144 input_line_pointer = t;
499ac353 1145 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1146
c19d1205
ZW
1147 if (target_big_endian)
1148 {
1149 for (i = 0; i < prec; i++)
1150 {
499ac353
NC
1151 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1152 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1153 }
1154 }
1155 else
1156 {
e74cfd16 1157 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1158 for (i = prec - 1; i >= 0; i--)
1159 {
499ac353
NC
1160 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1161 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1162 }
1163 else
1164 /* For a 4 byte float the order of elements in `words' is 1 0.
1165 For an 8 byte float the order is 1 0 3 2. */
1166 for (i = 0; i < prec; i += 2)
1167 {
499ac353
NC
1168 md_number_to_chars (litP, (valueT) words[i + 1],
1169 sizeof (LITTLENUM_TYPE));
1170 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1171 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1172 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1173 }
1174 }
b99bd4ef 1175
499ac353 1176 return NULL;
c19d1205 1177}
b99bd4ef 1178
c19d1205
ZW
1179/* We handle all bad expressions here, so that we can report the faulty
1180 instruction in the error message. */
1181void
91d6fa6a 1182md_operand (expressionS * exp)
c19d1205
ZW
1183{
1184 if (in_my_get_expression)
91d6fa6a 1185 exp->X_op = O_illegal;
b99bd4ef
NC
1186}
1187
c19d1205 1188/* Immediate values. */
b99bd4ef 1189
c19d1205
ZW
1190/* Generic immediate-value read function for use in directives.
1191 Accepts anything that 'expression' can fold to a constant.
1192 *val receives the number. */
1193#ifdef OBJ_ELF
1194static int
1195immediate_for_directive (int *val)
b99bd4ef 1196{
c19d1205
ZW
1197 expressionS exp;
1198 exp.X_op = O_illegal;
b99bd4ef 1199
c19d1205
ZW
1200 if (is_immediate_prefix (*input_line_pointer))
1201 {
1202 input_line_pointer++;
1203 expression (&exp);
1204 }
b99bd4ef 1205
c19d1205
ZW
1206 if (exp.X_op != O_constant)
1207 {
1208 as_bad (_("expected #constant"));
1209 ignore_rest_of_line ();
1210 return FAIL;
1211 }
1212 *val = exp.X_add_number;
1213 return SUCCESS;
b99bd4ef 1214}
c19d1205 1215#endif
b99bd4ef 1216
c19d1205 1217/* Register parsing. */
b99bd4ef 1218
c19d1205
ZW
1219/* Generic register parser. CCP points to what should be the
1220 beginning of a register name. If it is indeed a valid register
1221 name, advance CCP over it and return the reg_entry structure;
1222 otherwise return NULL. Does not issue diagnostics. */
1223
1224static struct reg_entry *
1225arm_reg_parse_multi (char **ccp)
b99bd4ef 1226{
c19d1205
ZW
1227 char *start = *ccp;
1228 char *p;
1229 struct reg_entry *reg;
b99bd4ef 1230
477330fc
RM
1231 skip_whitespace (start);
1232
c19d1205
ZW
1233#ifdef REGISTER_PREFIX
1234 if (*start != REGISTER_PREFIX)
01cfc07f 1235 return NULL;
c19d1205
ZW
1236 start++;
1237#endif
1238#ifdef OPTIONAL_REGISTER_PREFIX
1239 if (*start == OPTIONAL_REGISTER_PREFIX)
1240 start++;
1241#endif
b99bd4ef 1242
c19d1205
ZW
1243 p = start;
1244 if (!ISALPHA (*p) || !is_name_beginner (*p))
1245 return NULL;
b99bd4ef 1246
c19d1205
ZW
1247 do
1248 p++;
1249 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1250
1251 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1252
1253 if (!reg)
1254 return NULL;
1255
1256 *ccp = p;
1257 return reg;
b99bd4ef
NC
1258}
1259
1260static int
dcbf9037 1261arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1262 enum arm_reg_type type)
b99bd4ef 1263{
c19d1205
ZW
1264 /* Alternative syntaxes are accepted for a few register classes. */
1265 switch (type)
1266 {
1267 case REG_TYPE_MVF:
1268 case REG_TYPE_MVD:
1269 case REG_TYPE_MVFX:
1270 case REG_TYPE_MVDX:
1271 /* Generic coprocessor register names are allowed for these. */
79134647 1272 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1273 return reg->number;
1274 break;
69b97547 1275
c19d1205
ZW
1276 case REG_TYPE_CP:
1277 /* For backward compatibility, a bare number is valid here. */
1278 {
1279 unsigned long processor = strtoul (start, ccp, 10);
1280 if (*ccp != start && processor <= 15)
1281 return processor;
1282 }
1a0670f3 1283 /* Fall through. */
6057a28f 1284
c19d1205
ZW
1285 case REG_TYPE_MMXWC:
1286 /* WC includes WCG. ??? I'm not sure this is true for all
1287 instructions that take WC registers. */
79134647 1288 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1289 return reg->number;
6057a28f 1290 break;
c19d1205 1291
6057a28f 1292 default:
c19d1205 1293 break;
6057a28f
NC
1294 }
1295
dcbf9037
JB
1296 return FAIL;
1297}
1298
1299/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1300 return value is the register number or FAIL. */
1301
1302static int
1303arm_reg_parse (char **ccp, enum arm_reg_type type)
1304{
1305 char *start = *ccp;
1306 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1307 int ret;
1308
1309 /* Do not allow a scalar (reg+index) to parse as a register. */
1310 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1311 return FAIL;
1312
1313 if (reg && reg->type == type)
1314 return reg->number;
1315
1316 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1317 return ret;
1318
c19d1205
ZW
1319 *ccp = start;
1320 return FAIL;
1321}
69b97547 1322
dcbf9037
JB
1323/* Parse a Neon type specifier. *STR should point at the leading '.'
1324 character. Does no verification at this stage that the type fits the opcode
1325 properly. E.g.,
1326
1327 .i32.i32.s16
1328 .s32.f32
1329 .u16
1330
1331 Can all be legally parsed by this function.
1332
1333 Fills in neon_type struct pointer with parsed information, and updates STR
1334 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1335 type, FAIL if not. */
1336
1337static int
1338parse_neon_type (struct neon_type *type, char **str)
1339{
1340 char *ptr = *str;
1341
1342 if (type)
1343 type->elems = 0;
1344
1345 while (type->elems < NEON_MAX_TYPE_ELS)
1346 {
1347 enum neon_el_type thistype = NT_untyped;
1348 unsigned thissize = -1u;
1349
1350 if (*ptr != '.')
1351 break;
1352
1353 ptr++;
1354
1355 /* Just a size without an explicit type. */
1356 if (ISDIGIT (*ptr))
1357 goto parsesize;
1358
1359 switch (TOLOWER (*ptr))
1360 {
1361 case 'i': thistype = NT_integer; break;
1362 case 'f': thistype = NT_float; break;
1363 case 'p': thistype = NT_poly; break;
1364 case 's': thistype = NT_signed; break;
1365 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1366 case 'd':
1367 thistype = NT_float;
1368 thissize = 64;
1369 ptr++;
1370 goto done;
dcbf9037
JB
1371 default:
1372 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1373 return FAIL;
1374 }
1375
1376 ptr++;
1377
1378 /* .f is an abbreviation for .f32. */
1379 if (thistype == NT_float && !ISDIGIT (*ptr))
1380 thissize = 32;
1381 else
1382 {
1383 parsesize:
1384 thissize = strtoul (ptr, &ptr, 10);
1385
1386 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1387 && thissize != 64)
1388 {
1389 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1390 return FAIL;
1391 }
1392 }
1393
037e8744 1394 done:
dcbf9037 1395 if (type)
477330fc
RM
1396 {
1397 type->el[type->elems].type = thistype;
dcbf9037
JB
1398 type->el[type->elems].size = thissize;
1399 type->elems++;
1400 }
1401 }
1402
1403 /* Empty/missing type is not a successful parse. */
1404 if (type->elems == 0)
1405 return FAIL;
1406
1407 *str = ptr;
1408
1409 return SUCCESS;
1410}
1411
1412/* Errors may be set multiple times during parsing or bit encoding
1413 (particularly in the Neon bits), but usually the earliest error which is set
1414 will be the most meaningful. Avoid overwriting it with later (cascading)
1415 errors by calling this function. */
1416
1417static void
1418first_error (const char *err)
1419{
1420 if (!inst.error)
1421 inst.error = err;
1422}
1423
1424/* Parse a single type, e.g. ".s32", leading period included. */
1425static int
1426parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1427{
1428 char *str = *ccp;
1429 struct neon_type optype;
1430
1431 if (*str == '.')
1432 {
1433 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1434 {
1435 if (optype.elems == 1)
1436 *vectype = optype.el[0];
1437 else
1438 {
1439 first_error (_("only one type should be specified for operand"));
1440 return FAIL;
1441 }
1442 }
dcbf9037 1443 else
477330fc
RM
1444 {
1445 first_error (_("vector type expected"));
1446 return FAIL;
1447 }
dcbf9037
JB
1448 }
1449 else
1450 return FAIL;
5f4273c7 1451
dcbf9037 1452 *ccp = str;
5f4273c7 1453
dcbf9037
JB
1454 return SUCCESS;
1455}
1456
1457/* Special meanings for indices (which have a range of 0-7), which will fit into
1458 a 4-bit integer. */
1459
1460#define NEON_ALL_LANES 15
1461#define NEON_INTERLEAVE_LANES 14
1462
1463/* Parse either a register or a scalar, with an optional type. Return the
1464 register number, and optionally fill in the actual type of the register
1465 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1466 type/index information in *TYPEINFO. */
1467
1468static int
1469parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1470 enum arm_reg_type *rtype,
1471 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1472{
1473 char *str = *ccp;
1474 struct reg_entry *reg = arm_reg_parse_multi (&str);
1475 struct neon_typed_alias atype;
1476 struct neon_type_el parsetype;
1477
1478 atype.defined = 0;
1479 atype.index = -1;
1480 atype.eltype.type = NT_invtype;
1481 atype.eltype.size = -1;
1482
1483 /* Try alternate syntax for some types of register. Note these are mutually
1484 exclusive with the Neon syntax extensions. */
1485 if (reg == NULL)
1486 {
1487 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1488 if (altreg != FAIL)
477330fc 1489 *ccp = str;
dcbf9037 1490 if (typeinfo)
477330fc 1491 *typeinfo = atype;
dcbf9037
JB
1492 return altreg;
1493 }
1494
037e8744
JB
1495 /* Undo polymorphism when a set of register types may be accepted. */
1496 if ((type == REG_TYPE_NDQ
1497 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1498 || (type == REG_TYPE_VFSD
477330fc 1499 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1500 || (type == REG_TYPE_NSDQ
477330fc
RM
1501 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1502 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1503 || (type == REG_TYPE_MMXWC
1504 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1505 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1506
1507 if (type != reg->type)
1508 return FAIL;
1509
1510 if (reg->neon)
1511 atype = *reg->neon;
5f4273c7 1512
dcbf9037
JB
1513 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1514 {
1515 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1516 {
1517 first_error (_("can't redefine type for operand"));
1518 return FAIL;
1519 }
dcbf9037
JB
1520 atype.defined |= NTA_HASTYPE;
1521 atype.eltype = parsetype;
1522 }
5f4273c7 1523
dcbf9037
JB
1524 if (skip_past_char (&str, '[') == SUCCESS)
1525 {
1526 if (type != REG_TYPE_VFD)
477330fc
RM
1527 {
1528 first_error (_("only D registers may be indexed"));
1529 return FAIL;
1530 }
5f4273c7 1531
dcbf9037 1532 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1533 {
1534 first_error (_("can't change index for operand"));
1535 return FAIL;
1536 }
dcbf9037
JB
1537
1538 atype.defined |= NTA_HASINDEX;
1539
1540 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1541 atype.index = NEON_ALL_LANES;
dcbf9037 1542 else
477330fc
RM
1543 {
1544 expressionS exp;
dcbf9037 1545
477330fc 1546 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1547
477330fc
RM
1548 if (exp.X_op != O_constant)
1549 {
1550 first_error (_("constant expression required"));
1551 return FAIL;
1552 }
dcbf9037 1553
477330fc
RM
1554 if (skip_past_char (&str, ']') == FAIL)
1555 return FAIL;
dcbf9037 1556
477330fc
RM
1557 atype.index = exp.X_add_number;
1558 }
dcbf9037 1559 }
5f4273c7 1560
dcbf9037
JB
1561 if (typeinfo)
1562 *typeinfo = atype;
5f4273c7 1563
dcbf9037
JB
1564 if (rtype)
1565 *rtype = type;
5f4273c7 1566
dcbf9037 1567 *ccp = str;
5f4273c7 1568
dcbf9037
JB
1569 return reg->number;
1570}
1571
1572/* Like arm_reg_parse, but allow allow the following extra features:
1573 - If RTYPE is non-zero, return the (possibly restricted) type of the
1574 register (e.g. Neon double or quad reg when either has been requested).
1575 - If this is a Neon vector type with additional type information, fill
1576 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1577 This function will fault on encountering a scalar. */
dcbf9037
JB
1578
1579static int
1580arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1581 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1582{
1583 struct neon_typed_alias atype;
1584 char *str = *ccp;
1585 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1586
1587 if (reg == FAIL)
1588 return FAIL;
1589
0855e32b
NS
1590 /* Do not allow regname(... to parse as a register. */
1591 if (*str == '(')
1592 return FAIL;
1593
dcbf9037
JB
1594 /* Do not allow a scalar (reg+index) to parse as a register. */
1595 if ((atype.defined & NTA_HASINDEX) != 0)
1596 {
1597 first_error (_("register operand expected, but got scalar"));
1598 return FAIL;
1599 }
1600
1601 if (vectype)
1602 *vectype = atype.eltype;
1603
1604 *ccp = str;
1605
1606 return reg;
1607}
1608
1609#define NEON_SCALAR_REG(X) ((X) >> 4)
1610#define NEON_SCALAR_INDEX(X) ((X) & 15)
1611
5287ad62
JB
1612/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1613 have enough information to be able to do a good job bounds-checking. So, we
1614 just do easy checks here, and do further checks later. */
1615
1616static int
dcbf9037 1617parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1618{
dcbf9037 1619 int reg;
5287ad62 1620 char *str = *ccp;
dcbf9037 1621 struct neon_typed_alias atype;
5f4273c7 1622
dcbf9037 1623 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1624
dcbf9037 1625 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1626 return FAIL;
5f4273c7 1627
dcbf9037 1628 if (atype.index == NEON_ALL_LANES)
5287ad62 1629 {
dcbf9037 1630 first_error (_("scalar must have an index"));
5287ad62
JB
1631 return FAIL;
1632 }
dcbf9037 1633 else if (atype.index >= 64 / elsize)
5287ad62 1634 {
dcbf9037 1635 first_error (_("scalar index out of range"));
5287ad62
JB
1636 return FAIL;
1637 }
5f4273c7 1638
dcbf9037
JB
1639 if (type)
1640 *type = atype.eltype;
5f4273c7 1641
5287ad62 1642 *ccp = str;
5f4273c7 1643
dcbf9037 1644 return reg * 16 + atype.index;
5287ad62
JB
1645}
1646
c19d1205 1647/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1648
c19d1205
ZW
1649static long
1650parse_reg_list (char ** strp)
1651{
1652 char * str = * strp;
1653 long range = 0;
1654 int another_range;
a737bd4d 1655
c19d1205
ZW
1656 /* We come back here if we get ranges concatenated by '+' or '|'. */
1657 do
6057a28f 1658 {
477330fc
RM
1659 skip_whitespace (str);
1660
c19d1205 1661 another_range = 0;
a737bd4d 1662
c19d1205
ZW
1663 if (*str == '{')
1664 {
1665 int in_range = 0;
1666 int cur_reg = -1;
a737bd4d 1667
c19d1205
ZW
1668 str++;
1669 do
1670 {
1671 int reg;
6057a28f 1672
dcbf9037 1673 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1674 {
dcbf9037 1675 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1676 return FAIL;
1677 }
a737bd4d 1678
c19d1205
ZW
1679 if (in_range)
1680 {
1681 int i;
a737bd4d 1682
c19d1205
ZW
1683 if (reg <= cur_reg)
1684 {
dcbf9037 1685 first_error (_("bad range in register list"));
c19d1205
ZW
1686 return FAIL;
1687 }
40a18ebd 1688
c19d1205
ZW
1689 for (i = cur_reg + 1; i < reg; i++)
1690 {
1691 if (range & (1 << i))
1692 as_tsktsk
1693 (_("Warning: duplicated register (r%d) in register list"),
1694 i);
1695 else
1696 range |= 1 << i;
1697 }
1698 in_range = 0;
1699 }
a737bd4d 1700
c19d1205
ZW
1701 if (range & (1 << reg))
1702 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1703 reg);
1704 else if (reg <= cur_reg)
1705 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1706
c19d1205
ZW
1707 range |= 1 << reg;
1708 cur_reg = reg;
1709 }
1710 while (skip_past_comma (&str) != FAIL
1711 || (in_range = 1, *str++ == '-'));
1712 str--;
a737bd4d 1713
d996d970 1714 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1715 {
dcbf9037 1716 first_error (_("missing `}'"));
c19d1205
ZW
1717 return FAIL;
1718 }
1719 }
1720 else
1721 {
91d6fa6a 1722 expressionS exp;
40a18ebd 1723
91d6fa6a 1724 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1725 return FAIL;
40a18ebd 1726
91d6fa6a 1727 if (exp.X_op == O_constant)
c19d1205 1728 {
91d6fa6a
NC
1729 if (exp.X_add_number
1730 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1731 {
1732 inst.error = _("invalid register mask");
1733 return FAIL;
1734 }
a737bd4d 1735
91d6fa6a 1736 if ((range & exp.X_add_number) != 0)
c19d1205 1737 {
91d6fa6a 1738 int regno = range & exp.X_add_number;
a737bd4d 1739
c19d1205
ZW
1740 regno &= -regno;
1741 regno = (1 << regno) - 1;
1742 as_tsktsk
1743 (_("Warning: duplicated register (r%d) in register list"),
1744 regno);
1745 }
a737bd4d 1746
91d6fa6a 1747 range |= exp.X_add_number;
c19d1205
ZW
1748 }
1749 else
1750 {
1751 if (inst.reloc.type != 0)
1752 {
1753 inst.error = _("expression too complex");
1754 return FAIL;
1755 }
a737bd4d 1756
91d6fa6a 1757 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1758 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1759 inst.reloc.pc_rel = 0;
1760 }
1761 }
a737bd4d 1762
c19d1205
ZW
1763 if (*str == '|' || *str == '+')
1764 {
1765 str++;
1766 another_range = 1;
1767 }
a737bd4d 1768 }
c19d1205 1769 while (another_range);
a737bd4d 1770
c19d1205
ZW
1771 *strp = str;
1772 return range;
a737bd4d
NC
1773}
1774
5287ad62
JB
1775/* Types of registers in a list. */
1776
1777enum reg_list_els
1778{
1779 REGLIST_VFP_S,
1780 REGLIST_VFP_D,
1781 REGLIST_NEON_D
1782};
1783
c19d1205
ZW
1784/* Parse a VFP register list. If the string is invalid return FAIL.
1785 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1786 register. Parses registers of type ETYPE.
1787 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1788 - Q registers can be used to specify pairs of D registers
1789 - { } can be omitted from around a singleton register list
477330fc
RM
1790 FIXME: This is not implemented, as it would require backtracking in
1791 some cases, e.g.:
1792 vtbl.8 d3,d4,d5
1793 This could be done (the meaning isn't really ambiguous), but doesn't
1794 fit in well with the current parsing framework.
dcbf9037
JB
1795 - 32 D registers may be used (also true for VFPv3).
1796 FIXME: Types are ignored in these register lists, which is probably a
1797 bug. */
6057a28f 1798
c19d1205 1799static int
037e8744 1800parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1801{
037e8744 1802 char *str = *ccp;
c19d1205
ZW
1803 int base_reg;
1804 int new_base;
21d799b5 1805 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1806 int max_regs = 0;
c19d1205
ZW
1807 int count = 0;
1808 int warned = 0;
1809 unsigned long mask = 0;
a737bd4d 1810 int i;
6057a28f 1811
477330fc 1812 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1813 {
1814 inst.error = _("expecting {");
1815 return FAIL;
1816 }
6057a28f 1817
5287ad62 1818 switch (etype)
c19d1205 1819 {
5287ad62 1820 case REGLIST_VFP_S:
c19d1205
ZW
1821 regtype = REG_TYPE_VFS;
1822 max_regs = 32;
5287ad62 1823 break;
5f4273c7 1824
5287ad62
JB
1825 case REGLIST_VFP_D:
1826 regtype = REG_TYPE_VFD;
b7fc2769 1827 break;
5f4273c7 1828
b7fc2769
JB
1829 case REGLIST_NEON_D:
1830 regtype = REG_TYPE_NDQ;
1831 break;
1832 }
1833
1834 if (etype != REGLIST_VFP_S)
1835 {
b1cc4aeb
PB
1836 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1837 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1838 {
1839 max_regs = 32;
1840 if (thumb_mode)
1841 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1842 fpu_vfp_ext_d32);
1843 else
1844 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1845 fpu_vfp_ext_d32);
1846 }
5287ad62 1847 else
477330fc 1848 max_regs = 16;
c19d1205 1849 }
6057a28f 1850
c19d1205 1851 base_reg = max_regs;
a737bd4d 1852
c19d1205
ZW
1853 do
1854 {
5287ad62 1855 int setmask = 1, addregs = 1;
dcbf9037 1856
037e8744 1857 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1858
c19d1205 1859 if (new_base == FAIL)
a737bd4d 1860 {
dcbf9037 1861 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1862 return FAIL;
1863 }
5f4273c7 1864
b7fc2769 1865 if (new_base >= max_regs)
477330fc
RM
1866 {
1867 first_error (_("register out of range in list"));
1868 return FAIL;
1869 }
5f4273c7 1870
5287ad62
JB
1871 /* Note: a value of 2 * n is returned for the register Q<n>. */
1872 if (regtype == REG_TYPE_NQ)
477330fc
RM
1873 {
1874 setmask = 3;
1875 addregs = 2;
1876 }
5287ad62 1877
c19d1205
ZW
1878 if (new_base < base_reg)
1879 base_reg = new_base;
a737bd4d 1880
5287ad62 1881 if (mask & (setmask << new_base))
c19d1205 1882 {
dcbf9037 1883 first_error (_("invalid register list"));
c19d1205 1884 return FAIL;
a737bd4d 1885 }
a737bd4d 1886
c19d1205
ZW
1887 if ((mask >> new_base) != 0 && ! warned)
1888 {
1889 as_tsktsk (_("register list not in ascending order"));
1890 warned = 1;
1891 }
0bbf2aa4 1892
5287ad62
JB
1893 mask |= setmask << new_base;
1894 count += addregs;
0bbf2aa4 1895
037e8744 1896 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1897 {
1898 int high_range;
0bbf2aa4 1899
037e8744 1900 str++;
0bbf2aa4 1901
037e8744 1902 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1903 == FAIL)
c19d1205
ZW
1904 {
1905 inst.error = gettext (reg_expected_msgs[regtype]);
1906 return FAIL;
1907 }
0bbf2aa4 1908
477330fc
RM
1909 if (high_range >= max_regs)
1910 {
1911 first_error (_("register out of range in list"));
1912 return FAIL;
1913 }
b7fc2769 1914
477330fc
RM
1915 if (regtype == REG_TYPE_NQ)
1916 high_range = high_range + 1;
5287ad62 1917
c19d1205
ZW
1918 if (high_range <= new_base)
1919 {
1920 inst.error = _("register range not in ascending order");
1921 return FAIL;
1922 }
0bbf2aa4 1923
5287ad62 1924 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1925 {
5287ad62 1926 if (mask & (setmask << new_base))
0bbf2aa4 1927 {
c19d1205
ZW
1928 inst.error = _("invalid register list");
1929 return FAIL;
0bbf2aa4 1930 }
c19d1205 1931
5287ad62
JB
1932 mask |= setmask << new_base;
1933 count += addregs;
0bbf2aa4 1934 }
0bbf2aa4 1935 }
0bbf2aa4 1936 }
037e8744 1937 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1938
037e8744 1939 str++;
0bbf2aa4 1940
c19d1205
ZW
1941 /* Sanity check -- should have raised a parse error above. */
1942 if (count == 0 || count > max_regs)
1943 abort ();
1944
1945 *pbase = base_reg;
1946
1947 /* Final test -- the registers must be consecutive. */
1948 mask >>= base_reg;
1949 for (i = 0; i < count; i++)
1950 {
1951 if ((mask & (1u << i)) == 0)
1952 {
1953 inst.error = _("non-contiguous register range");
1954 return FAIL;
1955 }
1956 }
1957
037e8744
JB
1958 *ccp = str;
1959
c19d1205 1960 return count;
b99bd4ef
NC
1961}
1962
dcbf9037
JB
1963/* True if two alias types are the same. */
1964
c921be7d 1965static bfd_boolean
dcbf9037
JB
1966neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1967{
1968 if (!a && !b)
c921be7d 1969 return TRUE;
5f4273c7 1970
dcbf9037 1971 if (!a || !b)
c921be7d 1972 return FALSE;
dcbf9037
JB
1973
1974 if (a->defined != b->defined)
c921be7d 1975 return FALSE;
5f4273c7 1976
dcbf9037
JB
1977 if ((a->defined & NTA_HASTYPE) != 0
1978 && (a->eltype.type != b->eltype.type
477330fc 1979 || a->eltype.size != b->eltype.size))
c921be7d 1980 return FALSE;
dcbf9037
JB
1981
1982 if ((a->defined & NTA_HASINDEX) != 0
1983 && (a->index != b->index))
c921be7d 1984 return FALSE;
5f4273c7 1985
c921be7d 1986 return TRUE;
dcbf9037
JB
1987}
1988
5287ad62
JB
1989/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1990 The base register is put in *PBASE.
dcbf9037 1991 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1992 the return value.
1993 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1994 Bits [6:5] encode the list length (minus one).
1995 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1996
5287ad62 1997#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1998#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1999#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2000
2001static int
dcbf9037 2002parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2003 struct neon_type_el *eltype)
5287ad62
JB
2004{
2005 char *ptr = *str;
2006 int base_reg = -1;
2007 int reg_incr = -1;
2008 int count = 0;
2009 int lane = -1;
2010 int leading_brace = 0;
2011 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2012 const char *const incr_error = _("register stride must be 1 or 2");
2013 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2014 struct neon_typed_alias firsttype;
f85d59c3
KT
2015 firsttype.defined = 0;
2016 firsttype.eltype.type = NT_invtype;
2017 firsttype.eltype.size = -1;
2018 firsttype.index = -1;
5f4273c7 2019
5287ad62
JB
2020 if (skip_past_char (&ptr, '{') == SUCCESS)
2021 leading_brace = 1;
5f4273c7 2022
5287ad62
JB
2023 do
2024 {
dcbf9037
JB
2025 struct neon_typed_alias atype;
2026 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2027
5287ad62 2028 if (getreg == FAIL)
477330fc
RM
2029 {
2030 first_error (_(reg_expected_msgs[rtype]));
2031 return FAIL;
2032 }
5f4273c7 2033
5287ad62 2034 if (base_reg == -1)
477330fc
RM
2035 {
2036 base_reg = getreg;
2037 if (rtype == REG_TYPE_NQ)
2038 {
2039 reg_incr = 1;
2040 }
2041 firsttype = atype;
2042 }
5287ad62 2043 else if (reg_incr == -1)
477330fc
RM
2044 {
2045 reg_incr = getreg - base_reg;
2046 if (reg_incr < 1 || reg_incr > 2)
2047 {
2048 first_error (_(incr_error));
2049 return FAIL;
2050 }
2051 }
5287ad62 2052 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2053 {
2054 first_error (_(incr_error));
2055 return FAIL;
2056 }
dcbf9037 2057
c921be7d 2058 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2059 {
2060 first_error (_(type_error));
2061 return FAIL;
2062 }
5f4273c7 2063
5287ad62 2064 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2065 modes. */
5287ad62 2066 if (ptr[0] == '-')
477330fc
RM
2067 {
2068 struct neon_typed_alias htype;
2069 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2070 if (lane == -1)
2071 lane = NEON_INTERLEAVE_LANES;
2072 else if (lane != NEON_INTERLEAVE_LANES)
2073 {
2074 first_error (_(type_error));
2075 return FAIL;
2076 }
2077 if (reg_incr == -1)
2078 reg_incr = 1;
2079 else if (reg_incr != 1)
2080 {
2081 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2082 return FAIL;
2083 }
2084 ptr++;
2085 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2086 if (hireg == FAIL)
2087 {
2088 first_error (_(reg_expected_msgs[rtype]));
2089 return FAIL;
2090 }
2091 if (! neon_alias_types_same (&htype, &firsttype))
2092 {
2093 first_error (_(type_error));
2094 return FAIL;
2095 }
2096 count += hireg + dregs - getreg;
2097 continue;
2098 }
5f4273c7 2099
5287ad62
JB
2100 /* If we're using Q registers, we can't use [] or [n] syntax. */
2101 if (rtype == REG_TYPE_NQ)
477330fc
RM
2102 {
2103 count += 2;
2104 continue;
2105 }
5f4273c7 2106
dcbf9037 2107 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2108 {
2109 if (lane == -1)
2110 lane = atype.index;
2111 else if (lane != atype.index)
2112 {
2113 first_error (_(type_error));
2114 return FAIL;
2115 }
2116 }
5287ad62 2117 else if (lane == -1)
477330fc 2118 lane = NEON_INTERLEAVE_LANES;
5287ad62 2119 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2120 {
2121 first_error (_(type_error));
2122 return FAIL;
2123 }
5287ad62
JB
2124 count++;
2125 }
2126 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2127
5287ad62
JB
2128 /* No lane set by [x]. We must be interleaving structures. */
2129 if (lane == -1)
2130 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2131
5287ad62
JB
2132 /* Sanity check. */
2133 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2134 || (count > 1 && reg_incr == -1))
2135 {
dcbf9037 2136 first_error (_("error parsing element/structure list"));
5287ad62
JB
2137 return FAIL;
2138 }
2139
2140 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2141 {
dcbf9037 2142 first_error (_("expected }"));
5287ad62
JB
2143 return FAIL;
2144 }
5f4273c7 2145
5287ad62
JB
2146 if (reg_incr == -1)
2147 reg_incr = 1;
2148
dcbf9037
JB
2149 if (eltype)
2150 *eltype = firsttype.eltype;
2151
5287ad62
JB
2152 *pbase = base_reg;
2153 *str = ptr;
5f4273c7 2154
5287ad62
JB
2155 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2156}
2157
c19d1205
ZW
2158/* Parse an explicit relocation suffix on an expression. This is
2159 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2160 arm_reloc_hsh contains no entries, so this function can only
2161 succeed if there is no () after the word. Returns -1 on error,
2162 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2163
c19d1205
ZW
2164static int
2165parse_reloc (char **str)
b99bd4ef 2166{
c19d1205
ZW
2167 struct reloc_entry *r;
2168 char *p, *q;
b99bd4ef 2169
c19d1205
ZW
2170 if (**str != '(')
2171 return BFD_RELOC_UNUSED;
b99bd4ef 2172
c19d1205
ZW
2173 p = *str + 1;
2174 q = p;
2175
2176 while (*q && *q != ')' && *q != ',')
2177 q++;
2178 if (*q != ')')
2179 return -1;
2180
21d799b5
NC
2181 if ((r = (struct reloc_entry *)
2182 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2183 return -1;
2184
2185 *str = q + 1;
2186 return r->reloc;
b99bd4ef
NC
2187}
2188
c19d1205
ZW
2189/* Directives: register aliases. */
2190
dcbf9037 2191static struct reg_entry *
90ec0d68 2192insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2193{
d3ce72d0 2194 struct reg_entry *new_reg;
c19d1205 2195 const char *name;
b99bd4ef 2196
d3ce72d0 2197 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2198 {
d3ce72d0 2199 if (new_reg->builtin)
c19d1205 2200 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2201
c19d1205
ZW
2202 /* Only warn about a redefinition if it's not defined as the
2203 same register. */
d3ce72d0 2204 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2205 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2206
d929913e 2207 return NULL;
c19d1205 2208 }
b99bd4ef 2209
c19d1205 2210 name = xstrdup (str);
325801bd 2211 new_reg = XNEW (struct reg_entry);
b99bd4ef 2212
d3ce72d0
NC
2213 new_reg->name = name;
2214 new_reg->number = number;
2215 new_reg->type = type;
2216 new_reg->builtin = FALSE;
2217 new_reg->neon = NULL;
b99bd4ef 2218
d3ce72d0 2219 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2220 abort ();
5f4273c7 2221
d3ce72d0 2222 return new_reg;
dcbf9037
JB
2223}
2224
2225static void
2226insert_neon_reg_alias (char *str, int number, int type,
477330fc 2227 struct neon_typed_alias *atype)
dcbf9037
JB
2228{
2229 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2230
dcbf9037
JB
2231 if (!reg)
2232 {
2233 first_error (_("attempt to redefine typed alias"));
2234 return;
2235 }
5f4273c7 2236
dcbf9037
JB
2237 if (atype)
2238 {
325801bd 2239 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2240 *reg->neon = *atype;
2241 }
c19d1205 2242}
b99bd4ef 2243
c19d1205 2244/* Look for the .req directive. This is of the form:
b99bd4ef 2245
c19d1205 2246 new_register_name .req existing_register_name
b99bd4ef 2247
c19d1205 2248 If we find one, or if it looks sufficiently like one that we want to
d929913e 2249 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2250
d929913e 2251static bfd_boolean
c19d1205
ZW
2252create_register_alias (char * newname, char *p)
2253{
2254 struct reg_entry *old;
2255 char *oldname, *nbuf;
2256 size_t nlen;
b99bd4ef 2257
c19d1205
ZW
2258 /* The input scrubber ensures that whitespace after the mnemonic is
2259 collapsed to single spaces. */
2260 oldname = p;
2261 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2262 return FALSE;
b99bd4ef 2263
c19d1205
ZW
2264 oldname += 6;
2265 if (*oldname == '\0')
d929913e 2266 return FALSE;
b99bd4ef 2267
21d799b5 2268 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2269 if (!old)
b99bd4ef 2270 {
c19d1205 2271 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2272 return TRUE;
b99bd4ef
NC
2273 }
2274
c19d1205
ZW
2275 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2276 the desired alias name, and p points to its end. If not, then
2277 the desired alias name is in the global original_case_string. */
2278#ifdef TC_CASE_SENSITIVE
2279 nlen = p - newname;
2280#else
2281 newname = original_case_string;
2282 nlen = strlen (newname);
2283#endif
b99bd4ef 2284
29a2809e 2285 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2286
c19d1205
ZW
2287 /* Create aliases under the new name as stated; an all-lowercase
2288 version of the new name; and an all-uppercase version of the new
2289 name. */
d929913e
NC
2290 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2291 {
2292 for (p = nbuf; *p; p++)
2293 *p = TOUPPER (*p);
c19d1205 2294
d929913e
NC
2295 if (strncmp (nbuf, newname, nlen))
2296 {
2297 /* If this attempt to create an additional alias fails, do not bother
2298 trying to create the all-lower case alias. We will fail and issue
2299 a second, duplicate error message. This situation arises when the
2300 programmer does something like:
2301 foo .req r0
2302 Foo .req r1
2303 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2304 the artificial FOO alias because it has already been created by the
d929913e
NC
2305 first .req. */
2306 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2307 {
2308 free (nbuf);
2309 return TRUE;
2310 }
d929913e 2311 }
c19d1205 2312
d929913e
NC
2313 for (p = nbuf; *p; p++)
2314 *p = TOLOWER (*p);
c19d1205 2315
d929913e
NC
2316 if (strncmp (nbuf, newname, nlen))
2317 insert_reg_alias (nbuf, old->number, old->type);
2318 }
c19d1205 2319
e1fa0163 2320 free (nbuf);
d929913e 2321 return TRUE;
b99bd4ef
NC
2322}
2323
dcbf9037
JB
2324/* Create a Neon typed/indexed register alias using directives, e.g.:
2325 X .dn d5.s32[1]
2326 Y .qn 6.s16
2327 Z .dn d7
2328 T .dn Z[0]
2329 These typed registers can be used instead of the types specified after the
2330 Neon mnemonic, so long as all operands given have types. Types can also be
2331 specified directly, e.g.:
5f4273c7 2332 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2333
c921be7d 2334static bfd_boolean
dcbf9037
JB
2335create_neon_reg_alias (char *newname, char *p)
2336{
2337 enum arm_reg_type basetype;
2338 struct reg_entry *basereg;
2339 struct reg_entry mybasereg;
2340 struct neon_type ntype;
2341 struct neon_typed_alias typeinfo;
12d6b0b7 2342 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2343 int namelen;
5f4273c7 2344
dcbf9037
JB
2345 typeinfo.defined = 0;
2346 typeinfo.eltype.type = NT_invtype;
2347 typeinfo.eltype.size = -1;
2348 typeinfo.index = -1;
5f4273c7 2349
dcbf9037 2350 nameend = p;
5f4273c7 2351
dcbf9037
JB
2352 if (strncmp (p, " .dn ", 5) == 0)
2353 basetype = REG_TYPE_VFD;
2354 else if (strncmp (p, " .qn ", 5) == 0)
2355 basetype = REG_TYPE_NQ;
2356 else
c921be7d 2357 return FALSE;
5f4273c7 2358
dcbf9037 2359 p += 5;
5f4273c7 2360
dcbf9037 2361 if (*p == '\0')
c921be7d 2362 return FALSE;
5f4273c7 2363
dcbf9037
JB
2364 basereg = arm_reg_parse_multi (&p);
2365
2366 if (basereg && basereg->type != basetype)
2367 {
2368 as_bad (_("bad type for register"));
c921be7d 2369 return FALSE;
dcbf9037
JB
2370 }
2371
2372 if (basereg == NULL)
2373 {
2374 expressionS exp;
2375 /* Try parsing as an integer. */
2376 my_get_expression (&exp, &p, GE_NO_PREFIX);
2377 if (exp.X_op != O_constant)
477330fc
RM
2378 {
2379 as_bad (_("expression must be constant"));
2380 return FALSE;
2381 }
dcbf9037
JB
2382 basereg = &mybasereg;
2383 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2384 : exp.X_add_number;
dcbf9037
JB
2385 basereg->neon = 0;
2386 }
2387
2388 if (basereg->neon)
2389 typeinfo = *basereg->neon;
2390
2391 if (parse_neon_type (&ntype, &p) == SUCCESS)
2392 {
2393 /* We got a type. */
2394 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2395 {
2396 as_bad (_("can't redefine the type of a register alias"));
2397 return FALSE;
2398 }
5f4273c7 2399
dcbf9037
JB
2400 typeinfo.defined |= NTA_HASTYPE;
2401 if (ntype.elems != 1)
477330fc
RM
2402 {
2403 as_bad (_("you must specify a single type only"));
2404 return FALSE;
2405 }
dcbf9037
JB
2406 typeinfo.eltype = ntype.el[0];
2407 }
5f4273c7 2408
dcbf9037
JB
2409 if (skip_past_char (&p, '[') == SUCCESS)
2410 {
2411 expressionS exp;
2412 /* We got a scalar index. */
5f4273c7 2413
dcbf9037 2414 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2415 {
2416 as_bad (_("can't redefine the index of a scalar alias"));
2417 return FALSE;
2418 }
5f4273c7 2419
dcbf9037 2420 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2421
dcbf9037 2422 if (exp.X_op != O_constant)
477330fc
RM
2423 {
2424 as_bad (_("scalar index must be constant"));
2425 return FALSE;
2426 }
5f4273c7 2427
dcbf9037
JB
2428 typeinfo.defined |= NTA_HASINDEX;
2429 typeinfo.index = exp.X_add_number;
5f4273c7 2430
dcbf9037 2431 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2432 {
2433 as_bad (_("expecting ]"));
2434 return FALSE;
2435 }
dcbf9037
JB
2436 }
2437
15735687
NS
2438 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2439 the desired alias name, and p points to its end. If not, then
2440 the desired alias name is in the global original_case_string. */
2441#ifdef TC_CASE_SENSITIVE
dcbf9037 2442 namelen = nameend - newname;
15735687
NS
2443#else
2444 newname = original_case_string;
2445 namelen = strlen (newname);
2446#endif
2447
29a2809e 2448 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2449
dcbf9037 2450 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2451 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2452
dcbf9037
JB
2453 /* Insert name in all uppercase. */
2454 for (p = namebuf; *p; p++)
2455 *p = TOUPPER (*p);
5f4273c7 2456
dcbf9037
JB
2457 if (strncmp (namebuf, newname, namelen))
2458 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2459 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2460
dcbf9037
JB
2461 /* Insert name in all lowercase. */
2462 for (p = namebuf; *p; p++)
2463 *p = TOLOWER (*p);
5f4273c7 2464
dcbf9037
JB
2465 if (strncmp (namebuf, newname, namelen))
2466 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2467 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2468
e1fa0163 2469 free (namebuf);
c921be7d 2470 return TRUE;
dcbf9037
JB
2471}
2472
c19d1205
ZW
2473/* Should never be called, as .req goes between the alias and the
2474 register name, not at the beginning of the line. */
c921be7d 2475
b99bd4ef 2476static void
c19d1205 2477s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2478{
c19d1205
ZW
2479 as_bad (_("invalid syntax for .req directive"));
2480}
b99bd4ef 2481
dcbf9037
JB
2482static void
2483s_dn (int a ATTRIBUTE_UNUSED)
2484{
2485 as_bad (_("invalid syntax for .dn directive"));
2486}
2487
2488static void
2489s_qn (int a ATTRIBUTE_UNUSED)
2490{
2491 as_bad (_("invalid syntax for .qn directive"));
2492}
2493
c19d1205
ZW
2494/* The .unreq directive deletes an alias which was previously defined
2495 by .req. For example:
b99bd4ef 2496
c19d1205
ZW
2497 my_alias .req r11
2498 .unreq my_alias */
b99bd4ef
NC
2499
2500static void
c19d1205 2501s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2502{
c19d1205
ZW
2503 char * name;
2504 char saved_char;
b99bd4ef 2505
c19d1205
ZW
2506 name = input_line_pointer;
2507
2508 while (*input_line_pointer != 0
2509 && *input_line_pointer != ' '
2510 && *input_line_pointer != '\n')
2511 ++input_line_pointer;
2512
2513 saved_char = *input_line_pointer;
2514 *input_line_pointer = 0;
2515
2516 if (!*name)
2517 as_bad (_("invalid syntax for .unreq directive"));
2518 else
2519 {
21d799b5 2520 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2521 name);
c19d1205
ZW
2522
2523 if (!reg)
2524 as_bad (_("unknown register alias '%s'"), name);
2525 else if (reg->builtin)
a1727c1a 2526 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2527 name);
2528 else
2529 {
d929913e
NC
2530 char * p;
2531 char * nbuf;
2532
db0bc284 2533 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2534 free ((char *) reg->name);
477330fc
RM
2535 if (reg->neon)
2536 free (reg->neon);
c19d1205 2537 free (reg);
d929913e
NC
2538
2539 /* Also locate the all upper case and all lower case versions.
2540 Do not complain if we cannot find one or the other as it
2541 was probably deleted above. */
5f4273c7 2542
d929913e
NC
2543 nbuf = strdup (name);
2544 for (p = nbuf; *p; p++)
2545 *p = TOUPPER (*p);
21d799b5 2546 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2547 if (reg)
2548 {
db0bc284 2549 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2550 free ((char *) reg->name);
2551 if (reg->neon)
2552 free (reg->neon);
2553 free (reg);
2554 }
2555
2556 for (p = nbuf; *p; p++)
2557 *p = TOLOWER (*p);
21d799b5 2558 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2559 if (reg)
2560 {
db0bc284 2561 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2562 free ((char *) reg->name);
2563 if (reg->neon)
2564 free (reg->neon);
2565 free (reg);
2566 }
2567
2568 free (nbuf);
c19d1205
ZW
2569 }
2570 }
b99bd4ef 2571
c19d1205 2572 *input_line_pointer = saved_char;
b99bd4ef
NC
2573 demand_empty_rest_of_line ();
2574}
2575
c19d1205
ZW
2576/* Directives: Instruction set selection. */
2577
2578#ifdef OBJ_ELF
2579/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2580 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2581 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2582 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2583
cd000bff
DJ
2584/* Create a new mapping symbol for the transition to STATE. */
2585
2586static void
2587make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2588{
a737bd4d 2589 symbolS * symbolP;
c19d1205
ZW
2590 const char * symname;
2591 int type;
b99bd4ef 2592
c19d1205 2593 switch (state)
b99bd4ef 2594 {
c19d1205
ZW
2595 case MAP_DATA:
2596 symname = "$d";
2597 type = BSF_NO_FLAGS;
2598 break;
2599 case MAP_ARM:
2600 symname = "$a";
2601 type = BSF_NO_FLAGS;
2602 break;
2603 case MAP_THUMB:
2604 symname = "$t";
2605 type = BSF_NO_FLAGS;
2606 break;
c19d1205
ZW
2607 default:
2608 abort ();
2609 }
2610
cd000bff 2611 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2612 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2613
2614 switch (state)
2615 {
2616 case MAP_ARM:
2617 THUMB_SET_FUNC (symbolP, 0);
2618 ARM_SET_THUMB (symbolP, 0);
2619 ARM_SET_INTERWORK (symbolP, support_interwork);
2620 break;
2621
2622 case MAP_THUMB:
2623 THUMB_SET_FUNC (symbolP, 1);
2624 ARM_SET_THUMB (symbolP, 1);
2625 ARM_SET_INTERWORK (symbolP, support_interwork);
2626 break;
2627
2628 case MAP_DATA:
2629 default:
cd000bff
DJ
2630 break;
2631 }
2632
2633 /* Save the mapping symbols for future reference. Also check that
2634 we do not place two mapping symbols at the same offset within a
2635 frag. We'll handle overlap between frags in
2de7820f
JZ
2636 check_mapping_symbols.
2637
2638 If .fill or other data filling directive generates zero sized data,
2639 the mapping symbol for the following code will have the same value
2640 as the one generated for the data filling directive. In this case,
2641 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2642 if (value == 0)
2643 {
2de7820f
JZ
2644 if (frag->tc_frag_data.first_map != NULL)
2645 {
2646 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2647 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2648 }
cd000bff
DJ
2649 frag->tc_frag_data.first_map = symbolP;
2650 }
2651 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2652 {
2653 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2654 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2655 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2656 }
cd000bff
DJ
2657 frag->tc_frag_data.last_map = symbolP;
2658}
2659
2660/* We must sometimes convert a region marked as code to data during
2661 code alignment, if an odd number of bytes have to be padded. The
2662 code mapping symbol is pushed to an aligned address. */
2663
2664static void
2665insert_data_mapping_symbol (enum mstate state,
2666 valueT value, fragS *frag, offsetT bytes)
2667{
2668 /* If there was already a mapping symbol, remove it. */
2669 if (frag->tc_frag_data.last_map != NULL
2670 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2671 {
2672 symbolS *symp = frag->tc_frag_data.last_map;
2673
2674 if (value == 0)
2675 {
2676 know (frag->tc_frag_data.first_map == symp);
2677 frag->tc_frag_data.first_map = NULL;
2678 }
2679 frag->tc_frag_data.last_map = NULL;
2680 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2681 }
cd000bff
DJ
2682
2683 make_mapping_symbol (MAP_DATA, value, frag);
2684 make_mapping_symbol (state, value + bytes, frag);
2685}
2686
2687static void mapping_state_2 (enum mstate state, int max_chars);
2688
2689/* Set the mapping state to STATE. Only call this when about to
2690 emit some STATE bytes to the file. */
2691
4e9aaefb 2692#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2693void
2694mapping_state (enum mstate state)
2695{
940b5ce0
DJ
2696 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2697
cd000bff
DJ
2698 if (mapstate == state)
2699 /* The mapping symbol has already been emitted.
2700 There is nothing else to do. */
2701 return;
49c62a33
NC
2702
2703 if (state == MAP_ARM || state == MAP_THUMB)
2704 /* PR gas/12931
2705 All ARM instructions require 4-byte alignment.
2706 (Almost) all Thumb instructions require 2-byte alignment.
2707
2708 When emitting instructions into any section, mark the section
2709 appropriately.
2710
2711 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2712 but themselves require 2-byte alignment; this applies to some
33eaf5de 2713 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2714 literal pool generation or an explicit .align >=2, both of
2715 which will cause the section to me marked with sufficient
2716 alignment. Thus, we don't handle those cases here. */
2717 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2718
2719 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2720 /* This case will be evaluated later. */
cd000bff 2721 return;
cd000bff
DJ
2722
2723 mapping_state_2 (state, 0);
cd000bff
DJ
2724}
2725
2726/* Same as mapping_state, but MAX_CHARS bytes have already been
2727 allocated. Put the mapping symbol that far back. */
2728
2729static void
2730mapping_state_2 (enum mstate state, int max_chars)
2731{
940b5ce0
DJ
2732 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2733
2734 if (!SEG_NORMAL (now_seg))
2735 return;
2736
cd000bff
DJ
2737 if (mapstate == state)
2738 /* The mapping symbol has already been emitted.
2739 There is nothing else to do. */
2740 return;
2741
4e9aaefb
SA
2742 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2743 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2744 {
2745 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2746 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2747
2748 if (add_symbol)
2749 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2750 }
2751
cd000bff
DJ
2752 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2753 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2754}
4e9aaefb 2755#undef TRANSITION
c19d1205 2756#else
d3106081
NS
2757#define mapping_state(x) ((void)0)
2758#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2759#endif
2760
2761/* Find the real, Thumb encoded start of a Thumb function. */
2762
4343666d 2763#ifdef OBJ_COFF
c19d1205
ZW
2764static symbolS *
2765find_real_start (symbolS * symbolP)
2766{
2767 char * real_start;
2768 const char * name = S_GET_NAME (symbolP);
2769 symbolS * new_target;
2770
2771 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2772#define STUB_NAME ".real_start_of"
2773
2774 if (name == NULL)
2775 abort ();
2776
37f6032b
ZW
2777 /* The compiler may generate BL instructions to local labels because
2778 it needs to perform a branch to a far away location. These labels
2779 do not have a corresponding ".real_start_of" label. We check
2780 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2781 the ".real_start_of" convention for nonlocal branches. */
2782 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2783 return symbolP;
2784
e1fa0163 2785 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2786 new_target = symbol_find (real_start);
e1fa0163 2787 free (real_start);
c19d1205
ZW
2788
2789 if (new_target == NULL)
2790 {
bd3ba5d1 2791 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2792 new_target = symbolP;
2793 }
2794
c19d1205
ZW
2795 return new_target;
2796}
4343666d 2797#endif
c19d1205
ZW
2798
2799static void
2800opcode_select (int width)
2801{
2802 switch (width)
2803 {
2804 case 16:
2805 if (! thumb_mode)
2806 {
e74cfd16 2807 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2808 as_bad (_("selected processor does not support THUMB opcodes"));
2809
2810 thumb_mode = 1;
2811 /* No need to force the alignment, since we will have been
2812 coming from ARM mode, which is word-aligned. */
2813 record_alignment (now_seg, 1);
2814 }
c19d1205
ZW
2815 break;
2816
2817 case 32:
2818 if (thumb_mode)
2819 {
e74cfd16 2820 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2821 as_bad (_("selected processor does not support ARM opcodes"));
2822
2823 thumb_mode = 0;
2824
2825 if (!need_pass_2)
2826 frag_align (2, 0, 0);
2827
2828 record_alignment (now_seg, 1);
2829 }
c19d1205
ZW
2830 break;
2831
2832 default:
2833 as_bad (_("invalid instruction size selected (%d)"), width);
2834 }
2835}
2836
2837static void
2838s_arm (int ignore ATTRIBUTE_UNUSED)
2839{
2840 opcode_select (32);
2841 demand_empty_rest_of_line ();
2842}
2843
2844static void
2845s_thumb (int ignore ATTRIBUTE_UNUSED)
2846{
2847 opcode_select (16);
2848 demand_empty_rest_of_line ();
2849}
2850
2851static void
2852s_code (int unused ATTRIBUTE_UNUSED)
2853{
2854 int temp;
2855
2856 temp = get_absolute_expression ();
2857 switch (temp)
2858 {
2859 case 16:
2860 case 32:
2861 opcode_select (temp);
2862 break;
2863
2864 default:
2865 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2866 }
2867}
2868
2869static void
2870s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2871{
2872 /* If we are not already in thumb mode go into it, EVEN if
2873 the target processor does not support thumb instructions.
2874 This is used by gcc/config/arm/lib1funcs.asm for example
2875 to compile interworking support functions even if the
2876 target processor should not support interworking. */
2877 if (! thumb_mode)
2878 {
2879 thumb_mode = 2;
2880 record_alignment (now_seg, 1);
2881 }
2882
2883 demand_empty_rest_of_line ();
2884}
2885
2886static void
2887s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2888{
2889 s_thumb (0);
2890
2891 /* The following label is the name/address of the start of a Thumb function.
2892 We need to know this for the interworking support. */
2893 label_is_thumb_function_name = TRUE;
2894}
2895
2896/* Perform a .set directive, but also mark the alias as
2897 being a thumb function. */
2898
2899static void
2900s_thumb_set (int equiv)
2901{
2902 /* XXX the following is a duplicate of the code for s_set() in read.c
2903 We cannot just call that code as we need to get at the symbol that
2904 is created. */
2905 char * name;
2906 char delim;
2907 char * end_name;
2908 symbolS * symbolP;
2909
2910 /* Especial apologies for the random logic:
2911 This just grew, and could be parsed much more simply!
2912 Dean - in haste. */
d02603dc 2913 delim = get_symbol_name (& name);
c19d1205 2914 end_name = input_line_pointer;
d02603dc 2915 (void) restore_line_pointer (delim);
c19d1205
ZW
2916
2917 if (*input_line_pointer != ',')
2918 {
2919 *end_name = 0;
2920 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2921 *end_name = delim;
2922 ignore_rest_of_line ();
2923 return;
2924 }
2925
2926 input_line_pointer++;
2927 *end_name = 0;
2928
2929 if (name[0] == '.' && name[1] == '\0')
2930 {
2931 /* XXX - this should not happen to .thumb_set. */
2932 abort ();
2933 }
2934
2935 if ((symbolP = symbol_find (name)) == NULL
2936 && (symbolP = md_undefined_symbol (name)) == NULL)
2937 {
2938#ifndef NO_LISTING
2939 /* When doing symbol listings, play games with dummy fragments living
2940 outside the normal fragment chain to record the file and line info
c19d1205 2941 for this symbol. */
b99bd4ef
NC
2942 if (listing & LISTING_SYMBOLS)
2943 {
2944 extern struct list_info_struct * listing_tail;
21d799b5 2945 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2946
2947 memset (dummy_frag, 0, sizeof (fragS));
2948 dummy_frag->fr_type = rs_fill;
2949 dummy_frag->line = listing_tail;
2950 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2951 dummy_frag->fr_symbol = symbolP;
2952 }
2953 else
2954#endif
2955 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2956
2957#ifdef OBJ_COFF
2958 /* "set" symbols are local unless otherwise specified. */
2959 SF_SET_LOCAL (symbolP);
2960#endif /* OBJ_COFF */
2961 } /* Make a new symbol. */
2962
2963 symbol_table_insert (symbolP);
2964
2965 * end_name = delim;
2966
2967 if (equiv
2968 && S_IS_DEFINED (symbolP)
2969 && S_GET_SEGMENT (symbolP) != reg_section)
2970 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2971
2972 pseudo_set (symbolP);
2973
2974 demand_empty_rest_of_line ();
2975
c19d1205 2976 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2977
2978 THUMB_SET_FUNC (symbolP, 1);
2979 ARM_SET_THUMB (symbolP, 1);
2980#if defined OBJ_ELF || defined OBJ_COFF
2981 ARM_SET_INTERWORK (symbolP, support_interwork);
2982#endif
2983}
2984
c19d1205 2985/* Directives: Mode selection. */
b99bd4ef 2986
c19d1205
ZW
2987/* .syntax [unified|divided] - choose the new unified syntax
2988 (same for Arm and Thumb encoding, modulo slight differences in what
2989 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2990static void
c19d1205 2991s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2992{
c19d1205
ZW
2993 char *name, delim;
2994
d02603dc 2995 delim = get_symbol_name (& name);
c19d1205
ZW
2996
2997 if (!strcasecmp (name, "unified"))
2998 unified_syntax = TRUE;
2999 else if (!strcasecmp (name, "divided"))
3000 unified_syntax = FALSE;
3001 else
3002 {
3003 as_bad (_("unrecognized syntax mode \"%s\""), name);
3004 return;
3005 }
d02603dc 3006 (void) restore_line_pointer (delim);
b99bd4ef
NC
3007 demand_empty_rest_of_line ();
3008}
3009
c19d1205
ZW
3010/* Directives: sectioning and alignment. */
3011
c19d1205
ZW
3012static void
3013s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3014{
c19d1205
ZW
3015 /* We don't support putting frags in the BSS segment, we fake it by
3016 marking in_bss, then looking at s_skip for clues. */
3017 subseg_set (bss_section, 0);
3018 demand_empty_rest_of_line ();
cd000bff
DJ
3019
3020#ifdef md_elf_section_change_hook
3021 md_elf_section_change_hook ();
3022#endif
c19d1205 3023}
b99bd4ef 3024
c19d1205
ZW
3025static void
3026s_even (int ignore ATTRIBUTE_UNUSED)
3027{
3028 /* Never make frag if expect extra pass. */
3029 if (!need_pass_2)
3030 frag_align (1, 0, 0);
b99bd4ef 3031
c19d1205 3032 record_alignment (now_seg, 1);
b99bd4ef 3033
c19d1205 3034 demand_empty_rest_of_line ();
b99bd4ef
NC
3035}
3036
2e6976a8
DG
3037/* Directives: CodeComposer Studio. */
3038
3039/* .ref (for CodeComposer Studio syntax only). */
3040static void
3041s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3042{
3043 if (codecomposer_syntax)
3044 ignore_rest_of_line ();
3045 else
3046 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3047}
3048
3049/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3050 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3051static void
3052asmfunc_debug (const char * name)
3053{
3054 static const char * last_name = NULL;
3055
3056 if (name != NULL)
3057 {
3058 gas_assert (last_name == NULL);
3059 last_name = name;
3060
3061 if (debug_type == DEBUG_STABS)
3062 stabs_generate_asm_func (name, name);
3063 }
3064 else
3065 {
3066 gas_assert (last_name != NULL);
3067
3068 if (debug_type == DEBUG_STABS)
3069 stabs_generate_asm_endfunc (last_name, last_name);
3070
3071 last_name = NULL;
3072 }
3073}
3074
3075static void
3076s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3077{
3078 if (codecomposer_syntax)
3079 {
3080 switch (asmfunc_state)
3081 {
3082 case OUTSIDE_ASMFUNC:
3083 asmfunc_state = WAITING_ASMFUNC_NAME;
3084 break;
3085
3086 case WAITING_ASMFUNC_NAME:
3087 as_bad (_(".asmfunc repeated."));
3088 break;
3089
3090 case WAITING_ENDASMFUNC:
3091 as_bad (_(".asmfunc without function."));
3092 break;
3093 }
3094 demand_empty_rest_of_line ();
3095 }
3096 else
3097 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3098}
3099
3100static void
3101s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3102{
3103 if (codecomposer_syntax)
3104 {
3105 switch (asmfunc_state)
3106 {
3107 case OUTSIDE_ASMFUNC:
3108 as_bad (_(".endasmfunc without a .asmfunc."));
3109 break;
3110
3111 case WAITING_ASMFUNC_NAME:
3112 as_bad (_(".endasmfunc without function."));
3113 break;
3114
3115 case WAITING_ENDASMFUNC:
3116 asmfunc_state = OUTSIDE_ASMFUNC;
3117 asmfunc_debug (NULL);
3118 break;
3119 }
3120 demand_empty_rest_of_line ();
3121 }
3122 else
3123 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3124}
3125
3126static void
3127s_ccs_def (int name)
3128{
3129 if (codecomposer_syntax)
3130 s_globl (name);
3131 else
3132 as_bad (_(".def pseudo-op only available with -mccs flag."));
3133}
3134
c19d1205 3135/* Directives: Literal pools. */
a737bd4d 3136
c19d1205
ZW
3137static literal_pool *
3138find_literal_pool (void)
a737bd4d 3139{
c19d1205 3140 literal_pool * pool;
a737bd4d 3141
c19d1205 3142 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3143 {
c19d1205
ZW
3144 if (pool->section == now_seg
3145 && pool->sub_section == now_subseg)
3146 break;
a737bd4d
NC
3147 }
3148
c19d1205 3149 return pool;
a737bd4d
NC
3150}
3151
c19d1205
ZW
3152static literal_pool *
3153find_or_make_literal_pool (void)
a737bd4d 3154{
c19d1205
ZW
3155 /* Next literal pool ID number. */
3156 static unsigned int latest_pool_num = 1;
3157 literal_pool * pool;
a737bd4d 3158
c19d1205 3159 pool = find_literal_pool ();
a737bd4d 3160
c19d1205 3161 if (pool == NULL)
a737bd4d 3162 {
c19d1205 3163 /* Create a new pool. */
325801bd 3164 pool = XNEW (literal_pool);
c19d1205
ZW
3165 if (! pool)
3166 return NULL;
a737bd4d 3167
c19d1205
ZW
3168 pool->next_free_entry = 0;
3169 pool->section = now_seg;
3170 pool->sub_section = now_subseg;
3171 pool->next = list_of_pools;
3172 pool->symbol = NULL;
8335d6aa 3173 pool->alignment = 2;
c19d1205
ZW
3174
3175 /* Add it to the list. */
3176 list_of_pools = pool;
a737bd4d 3177 }
a737bd4d 3178
c19d1205
ZW
3179 /* New pools, and emptied pools, will have a NULL symbol. */
3180 if (pool->symbol == NULL)
a737bd4d 3181 {
c19d1205
ZW
3182 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3183 (valueT) 0, &zero_address_frag);
3184 pool->id = latest_pool_num ++;
a737bd4d
NC
3185 }
3186
c19d1205
ZW
3187 /* Done. */
3188 return pool;
a737bd4d
NC
3189}
3190
c19d1205 3191/* Add the literal in the global 'inst'
5f4273c7 3192 structure to the relevant literal pool. */
b99bd4ef
NC
3193
3194static int
8335d6aa 3195add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3196{
8335d6aa
JW
3197#define PADDING_SLOT 0x1
3198#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3199 literal_pool * pool;
8335d6aa
JW
3200 unsigned int entry, pool_size = 0;
3201 bfd_boolean padding_slot_p = FALSE;
e56c722b 3202 unsigned imm1 = 0;
8335d6aa
JW
3203 unsigned imm2 = 0;
3204
3205 if (nbytes == 8)
3206 {
3207 imm1 = inst.operands[1].imm;
3208 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3209 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3210 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3211 if (target_big_endian)
3212 {
3213 imm1 = imm2;
3214 imm2 = inst.operands[1].imm;
3215 }
3216 }
b99bd4ef 3217
c19d1205
ZW
3218 pool = find_or_make_literal_pool ();
3219
3220 /* Check if this literal value is already in the pool. */
3221 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3222 {
8335d6aa
JW
3223 if (nbytes == 4)
3224 {
3225 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3226 && (inst.reloc.exp.X_op == O_constant)
3227 && (pool->literals[entry].X_add_number
3228 == inst.reloc.exp.X_add_number)
3229 && (pool->literals[entry].X_md == nbytes)
3230 && (pool->literals[entry].X_unsigned
3231 == inst.reloc.exp.X_unsigned))
3232 break;
3233
3234 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3235 && (inst.reloc.exp.X_op == O_symbol)
3236 && (pool->literals[entry].X_add_number
3237 == inst.reloc.exp.X_add_number)
3238 && (pool->literals[entry].X_add_symbol
3239 == inst.reloc.exp.X_add_symbol)
3240 && (pool->literals[entry].X_op_symbol
3241 == inst.reloc.exp.X_op_symbol)
3242 && (pool->literals[entry].X_md == nbytes))
3243 break;
3244 }
3245 else if ((nbytes == 8)
3246 && !(pool_size & 0x7)
3247 && ((entry + 1) != pool->next_free_entry)
3248 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3249 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3250 && (pool->literals[entry].X_unsigned
3251 == inst.reloc.exp.X_unsigned)
3252 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3253 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3254 && (pool->literals[entry + 1].X_unsigned
3255 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3256 break;
3257
8335d6aa
JW
3258 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3259 if (padding_slot_p && (nbytes == 4))
c19d1205 3260 break;
8335d6aa
JW
3261
3262 pool_size += 4;
b99bd4ef
NC
3263 }
3264
c19d1205
ZW
3265 /* Do we need to create a new entry? */
3266 if (entry == pool->next_free_entry)
3267 {
3268 if (entry >= MAX_LITERAL_POOL_SIZE)
3269 {
3270 inst.error = _("literal pool overflow");
3271 return FAIL;
3272 }
3273
8335d6aa
JW
3274 if (nbytes == 8)
3275 {
3276 /* For 8-byte entries, we align to an 8-byte boundary,
3277 and split it into two 4-byte entries, because on 32-bit
3278 host, 8-byte constants are treated as big num, thus
3279 saved in "generic_bignum" which will be overwritten
3280 by later assignments.
3281
3282 We also need to make sure there is enough space for
3283 the split.
3284
3285 We also check to make sure the literal operand is a
3286 constant number. */
19f2f6a9
JW
3287 if (!(inst.reloc.exp.X_op == O_constant
3288 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3289 {
3290 inst.error = _("invalid type for literal pool");
3291 return FAIL;
3292 }
3293 else if (pool_size & 0x7)
3294 {
3295 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3296 {
3297 inst.error = _("literal pool overflow");
3298 return FAIL;
3299 }
3300
3301 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3302 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3303 pool->literals[entry].X_add_number = 0;
3304 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3305 pool->next_free_entry += 1;
3306 pool_size += 4;
3307 }
3308 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3309 {
3310 inst.error = _("literal pool overflow");
3311 return FAIL;
3312 }
3313
3314 pool->literals[entry] = inst.reloc.exp;
3315 pool->literals[entry].X_op = O_constant;
3316 pool->literals[entry].X_add_number = imm1;
3317 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3318 pool->literals[entry++].X_md = 4;
3319 pool->literals[entry] = inst.reloc.exp;
3320 pool->literals[entry].X_op = O_constant;
3321 pool->literals[entry].X_add_number = imm2;
3322 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3323 pool->literals[entry].X_md = 4;
3324 pool->alignment = 3;
3325 pool->next_free_entry += 1;
3326 }
3327 else
3328 {
3329 pool->literals[entry] = inst.reloc.exp;
3330 pool->literals[entry].X_md = 4;
3331 }
3332
a8040cf2
NC
3333#ifdef OBJ_ELF
3334 /* PR ld/12974: Record the location of the first source line to reference
3335 this entry in the literal pool. If it turns out during linking that the
3336 symbol does not exist we will be able to give an accurate line number for
3337 the (first use of the) missing reference. */
3338 if (debug_type == DEBUG_DWARF2)
3339 dwarf2_where (pool->locs + entry);
3340#endif
c19d1205
ZW
3341 pool->next_free_entry += 1;
3342 }
8335d6aa
JW
3343 else if (padding_slot_p)
3344 {
3345 pool->literals[entry] = inst.reloc.exp;
3346 pool->literals[entry].X_md = nbytes;
3347 }
b99bd4ef 3348
c19d1205 3349 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3350 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3351 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3352
c19d1205 3353 return SUCCESS;
b99bd4ef
NC
3354}
3355
2e6976a8 3356bfd_boolean
2e57ce7b 3357tc_start_label_without_colon (void)
2e6976a8
DG
3358{
3359 bfd_boolean ret = TRUE;
3360
3361 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3362 {
2e57ce7b 3363 const char *label = input_line_pointer;
2e6976a8
DG
3364
3365 while (!is_end_of_line[(int) label[-1]])
3366 --label;
3367
3368 if (*label == '.')
3369 {
3370 as_bad (_("Invalid label '%s'"), label);
3371 ret = FALSE;
3372 }
3373
3374 asmfunc_debug (label);
3375
3376 asmfunc_state = WAITING_ENDASMFUNC;
3377 }
3378
3379 return ret;
3380}
3381
c19d1205 3382/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3383 a later date assign it a value. That's what these functions do. */
e16bb312 3384
c19d1205
ZW
3385static void
3386symbol_locate (symbolS * symbolP,
3387 const char * name, /* It is copied, the caller can modify. */
3388 segT segment, /* Segment identifier (SEG_<something>). */
3389 valueT valu, /* Symbol value. */
3390 fragS * frag) /* Associated fragment. */
3391{
e57e6ddc 3392 size_t name_length;
c19d1205 3393 char * preserved_copy_of_name;
e16bb312 3394
c19d1205
ZW
3395 name_length = strlen (name) + 1; /* +1 for \0. */
3396 obstack_grow (&notes, name, name_length);
21d799b5 3397 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3398
c19d1205
ZW
3399#ifdef tc_canonicalize_symbol_name
3400 preserved_copy_of_name =
3401 tc_canonicalize_symbol_name (preserved_copy_of_name);
3402#endif
b99bd4ef 3403
c19d1205 3404 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3405
c19d1205
ZW
3406 S_SET_SEGMENT (symbolP, segment);
3407 S_SET_VALUE (symbolP, valu);
3408 symbol_clear_list_pointers (symbolP);
b99bd4ef 3409
c19d1205 3410 symbol_set_frag (symbolP, frag);
b99bd4ef 3411
c19d1205
ZW
3412 /* Link to end of symbol chain. */
3413 {
3414 extern int symbol_table_frozen;
b99bd4ef 3415
c19d1205
ZW
3416 if (symbol_table_frozen)
3417 abort ();
3418 }
b99bd4ef 3419
c19d1205 3420 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3421
c19d1205 3422 obj_symbol_new_hook (symbolP);
b99bd4ef 3423
c19d1205
ZW
3424#ifdef tc_symbol_new_hook
3425 tc_symbol_new_hook (symbolP);
3426#endif
3427
3428#ifdef DEBUG_SYMS
3429 verify_symbol_chain (symbol_rootP, symbol_lastP);
3430#endif /* DEBUG_SYMS */
b99bd4ef
NC
3431}
3432
c19d1205
ZW
3433static void
3434s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3435{
c19d1205
ZW
3436 unsigned int entry;
3437 literal_pool * pool;
3438 char sym_name[20];
b99bd4ef 3439
c19d1205
ZW
3440 pool = find_literal_pool ();
3441 if (pool == NULL
3442 || pool->symbol == NULL
3443 || pool->next_free_entry == 0)
3444 return;
b99bd4ef 3445
c19d1205
ZW
3446 /* Align pool as you have word accesses.
3447 Only make a frag if we have to. */
3448 if (!need_pass_2)
8335d6aa 3449 frag_align (pool->alignment, 0, 0);
b99bd4ef 3450
c19d1205 3451 record_alignment (now_seg, 2);
b99bd4ef 3452
aaca88ef 3453#ifdef OBJ_ELF
47fc6e36
WN
3454 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3455 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3456#endif
c19d1205 3457 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3458
c19d1205
ZW
3459 symbol_locate (pool->symbol, sym_name, now_seg,
3460 (valueT) frag_now_fix (), frag_now);
3461 symbol_table_insert (pool->symbol);
b99bd4ef 3462
c19d1205 3463 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3464
c19d1205
ZW
3465#if defined OBJ_COFF || defined OBJ_ELF
3466 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3467#endif
6c43fab6 3468
c19d1205 3469 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3470 {
3471#ifdef OBJ_ELF
3472 if (debug_type == DEBUG_DWARF2)
3473 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3474#endif
3475 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3476 emit_expr (&(pool->literals[entry]),
3477 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3478 }
b99bd4ef 3479
c19d1205
ZW
3480 /* Mark the pool as empty. */
3481 pool->next_free_entry = 0;
3482 pool->symbol = NULL;
b99bd4ef
NC
3483}
3484
c19d1205
ZW
3485#ifdef OBJ_ELF
3486/* Forward declarations for functions below, in the MD interface
3487 section. */
3488static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3489static valueT create_unwind_entry (int);
3490static void start_unwind_section (const segT, int);
3491static void add_unwind_opcode (valueT, int);
3492static void flush_pending_unwind (void);
b99bd4ef 3493
c19d1205 3494/* Directives: Data. */
b99bd4ef 3495
c19d1205
ZW
3496static void
3497s_arm_elf_cons (int nbytes)
3498{
3499 expressionS exp;
b99bd4ef 3500
c19d1205
ZW
3501#ifdef md_flush_pending_output
3502 md_flush_pending_output ();
3503#endif
b99bd4ef 3504
c19d1205 3505 if (is_it_end_of_statement ())
b99bd4ef 3506 {
c19d1205
ZW
3507 demand_empty_rest_of_line ();
3508 return;
b99bd4ef
NC
3509 }
3510
c19d1205
ZW
3511#ifdef md_cons_align
3512 md_cons_align (nbytes);
3513#endif
b99bd4ef 3514
c19d1205
ZW
3515 mapping_state (MAP_DATA);
3516 do
b99bd4ef 3517 {
c19d1205
ZW
3518 int reloc;
3519 char *base = input_line_pointer;
b99bd4ef 3520
c19d1205 3521 expression (& exp);
b99bd4ef 3522
c19d1205
ZW
3523 if (exp.X_op != O_symbol)
3524 emit_expr (&exp, (unsigned int) nbytes);
3525 else
3526 {
3527 char *before_reloc = input_line_pointer;
3528 reloc = parse_reloc (&input_line_pointer);
3529 if (reloc == -1)
3530 {
3531 as_bad (_("unrecognized relocation suffix"));
3532 ignore_rest_of_line ();
3533 return;
3534 }
3535 else if (reloc == BFD_RELOC_UNUSED)
3536 emit_expr (&exp, (unsigned int) nbytes);
3537 else
3538 {
21d799b5 3539 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3540 bfd_reloc_type_lookup (stdoutput,
3541 (bfd_reloc_code_real_type) reloc);
c19d1205 3542 int size = bfd_get_reloc_size (howto);
b99bd4ef 3543
2fc8bdac
ZW
3544 if (reloc == BFD_RELOC_ARM_PLT32)
3545 {
3546 as_bad (_("(plt) is only valid on branch targets"));
3547 reloc = BFD_RELOC_UNUSED;
3548 size = 0;
3549 }
3550
c19d1205 3551 if (size > nbytes)
2fc8bdac 3552 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3553 howto->name, nbytes);
3554 else
3555 {
3556 /* We've parsed an expression stopping at O_symbol.
3557 But there may be more expression left now that we
3558 have parsed the relocation marker. Parse it again.
3559 XXX Surely there is a cleaner way to do this. */
3560 char *p = input_line_pointer;
3561 int offset;
325801bd 3562 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3563
c19d1205
ZW
3564 memcpy (save_buf, base, input_line_pointer - base);
3565 memmove (base + (input_line_pointer - before_reloc),
3566 base, before_reloc - base);
3567
3568 input_line_pointer = base + (input_line_pointer-before_reloc);
3569 expression (&exp);
3570 memcpy (base, save_buf, p - base);
3571
3572 offset = nbytes - size;
4b1a927e
AM
3573 p = frag_more (nbytes);
3574 memset (p, 0, nbytes);
c19d1205 3575 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3576 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3577 free (save_buf);
c19d1205
ZW
3578 }
3579 }
3580 }
b99bd4ef 3581 }
c19d1205 3582 while (*input_line_pointer++ == ',');
b99bd4ef 3583
c19d1205
ZW
3584 /* Put terminator back into stream. */
3585 input_line_pointer --;
3586 demand_empty_rest_of_line ();
b99bd4ef
NC
3587}
3588
c921be7d
NC
3589/* Emit an expression containing a 32-bit thumb instruction.
3590 Implementation based on put_thumb32_insn. */
3591
3592static void
3593emit_thumb32_expr (expressionS * exp)
3594{
3595 expressionS exp_high = *exp;
3596
3597 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3598 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3599 exp->X_add_number &= 0xffff;
3600 emit_expr (exp, (unsigned int) THUMB_SIZE);
3601}
3602
3603/* Guess the instruction size based on the opcode. */
3604
3605static int
3606thumb_insn_size (int opcode)
3607{
3608 if ((unsigned int) opcode < 0xe800u)
3609 return 2;
3610 else if ((unsigned int) opcode >= 0xe8000000u)
3611 return 4;
3612 else
3613 return 0;
3614}
3615
3616static bfd_boolean
3617emit_insn (expressionS *exp, int nbytes)
3618{
3619 int size = 0;
3620
3621 if (exp->X_op == O_constant)
3622 {
3623 size = nbytes;
3624
3625 if (size == 0)
3626 size = thumb_insn_size (exp->X_add_number);
3627
3628 if (size != 0)
3629 {
3630 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3631 {
3632 as_bad (_(".inst.n operand too big. "\
3633 "Use .inst.w instead"));
3634 size = 0;
3635 }
3636 else
3637 {
3638 if (now_it.state == AUTOMATIC_IT_BLOCK)
3639 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3640 else
3641 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3642
3643 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3644 emit_thumb32_expr (exp);
3645 else
3646 emit_expr (exp, (unsigned int) size);
3647
3648 it_fsm_post_encode ();
3649 }
3650 }
3651 else
3652 as_bad (_("cannot determine Thumb instruction size. " \
3653 "Use .inst.n/.inst.w instead"));
3654 }
3655 else
3656 as_bad (_("constant expression required"));
3657
3658 return (size != 0);
3659}
3660
3661/* Like s_arm_elf_cons but do not use md_cons_align and
3662 set the mapping state to MAP_ARM/MAP_THUMB. */
3663
3664static void
3665s_arm_elf_inst (int nbytes)
3666{
3667 if (is_it_end_of_statement ())
3668 {
3669 demand_empty_rest_of_line ();
3670 return;
3671 }
3672
3673 /* Calling mapping_state () here will not change ARM/THUMB,
3674 but will ensure not to be in DATA state. */
3675
3676 if (thumb_mode)
3677 mapping_state (MAP_THUMB);
3678 else
3679 {
3680 if (nbytes != 0)
3681 {
3682 as_bad (_("width suffixes are invalid in ARM mode"));
3683 ignore_rest_of_line ();
3684 return;
3685 }
3686
3687 nbytes = 4;
3688
3689 mapping_state (MAP_ARM);
3690 }
3691
3692 do
3693 {
3694 expressionS exp;
3695
3696 expression (& exp);
3697
3698 if (! emit_insn (& exp, nbytes))
3699 {
3700 ignore_rest_of_line ();
3701 return;
3702 }
3703 }
3704 while (*input_line_pointer++ == ',');
3705
3706 /* Put terminator back into stream. */
3707 input_line_pointer --;
3708 demand_empty_rest_of_line ();
3709}
b99bd4ef 3710
c19d1205 3711/* Parse a .rel31 directive. */
b99bd4ef 3712
c19d1205
ZW
3713static void
3714s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3715{
3716 expressionS exp;
3717 char *p;
3718 valueT highbit;
b99bd4ef 3719
c19d1205
ZW
3720 highbit = 0;
3721 if (*input_line_pointer == '1')
3722 highbit = 0x80000000;
3723 else if (*input_line_pointer != '0')
3724 as_bad (_("expected 0 or 1"));
b99bd4ef 3725
c19d1205
ZW
3726 input_line_pointer++;
3727 if (*input_line_pointer != ',')
3728 as_bad (_("missing comma"));
3729 input_line_pointer++;
b99bd4ef 3730
c19d1205
ZW
3731#ifdef md_flush_pending_output
3732 md_flush_pending_output ();
3733#endif
b99bd4ef 3734
c19d1205
ZW
3735#ifdef md_cons_align
3736 md_cons_align (4);
3737#endif
b99bd4ef 3738
c19d1205 3739 mapping_state (MAP_DATA);
b99bd4ef 3740
c19d1205 3741 expression (&exp);
b99bd4ef 3742
c19d1205
ZW
3743 p = frag_more (4);
3744 md_number_to_chars (p, highbit, 4);
3745 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3746 BFD_RELOC_ARM_PREL31);
b99bd4ef 3747
c19d1205 3748 demand_empty_rest_of_line ();
b99bd4ef
NC
3749}
3750
c19d1205 3751/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3752
c19d1205 3753/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3754
c19d1205
ZW
3755static void
3756s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3757{
3758 demand_empty_rest_of_line ();
921e5f0a
PB
3759 if (unwind.proc_start)
3760 {
c921be7d 3761 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3762 return;
3763 }
3764
c19d1205
ZW
3765 /* Mark the start of the function. */
3766 unwind.proc_start = expr_build_dot ();
b99bd4ef 3767
c19d1205
ZW
3768 /* Reset the rest of the unwind info. */
3769 unwind.opcode_count = 0;
3770 unwind.table_entry = NULL;
3771 unwind.personality_routine = NULL;
3772 unwind.personality_index = -1;
3773 unwind.frame_size = 0;
3774 unwind.fp_offset = 0;
fdfde340 3775 unwind.fp_reg = REG_SP;
c19d1205
ZW
3776 unwind.fp_used = 0;
3777 unwind.sp_restored = 0;
3778}
b99bd4ef 3779
b99bd4ef 3780
c19d1205
ZW
3781/* Parse a handlerdata directive. Creates the exception handling table entry
3782 for the function. */
b99bd4ef 3783
c19d1205
ZW
3784static void
3785s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3786{
3787 demand_empty_rest_of_line ();
921e5f0a 3788 if (!unwind.proc_start)
c921be7d 3789 as_bad (MISSING_FNSTART);
921e5f0a 3790
c19d1205 3791 if (unwind.table_entry)
6decc662 3792 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3793
c19d1205
ZW
3794 create_unwind_entry (1);
3795}
a737bd4d 3796
c19d1205 3797/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3798
c19d1205
ZW
3799static void
3800s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3801{
3802 long where;
3803 char *ptr;
3804 valueT val;
940b5ce0 3805 unsigned int marked_pr_dependency;
f02232aa 3806
c19d1205 3807 demand_empty_rest_of_line ();
f02232aa 3808
921e5f0a
PB
3809 if (!unwind.proc_start)
3810 {
c921be7d 3811 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3812 return;
3813 }
3814
c19d1205
ZW
3815 /* Add eh table entry. */
3816 if (unwind.table_entry == NULL)
3817 val = create_unwind_entry (0);
3818 else
3819 val = 0;
f02232aa 3820
c19d1205
ZW
3821 /* Add index table entry. This is two words. */
3822 start_unwind_section (unwind.saved_seg, 1);
3823 frag_align (2, 0, 0);
3824 record_alignment (now_seg, 2);
b99bd4ef 3825
c19d1205 3826 ptr = frag_more (8);
5011093d 3827 memset (ptr, 0, 8);
c19d1205 3828 where = frag_now_fix () - 8;
f02232aa 3829
c19d1205
ZW
3830 /* Self relative offset of the function start. */
3831 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3832 BFD_RELOC_ARM_PREL31);
f02232aa 3833
c19d1205
ZW
3834 /* Indicate dependency on EHABI-defined personality routines to the
3835 linker, if it hasn't been done already. */
940b5ce0
DJ
3836 marked_pr_dependency
3837 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3838 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3839 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3840 {
5f4273c7
NC
3841 static const char *const name[] =
3842 {
3843 "__aeabi_unwind_cpp_pr0",
3844 "__aeabi_unwind_cpp_pr1",
3845 "__aeabi_unwind_cpp_pr2"
3846 };
c19d1205
ZW
3847 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3848 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3849 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3850 |= 1 << unwind.personality_index;
c19d1205 3851 }
f02232aa 3852
c19d1205
ZW
3853 if (val)
3854 /* Inline exception table entry. */
3855 md_number_to_chars (ptr + 4, val, 4);
3856 else
3857 /* Self relative offset of the table entry. */
3858 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3859 BFD_RELOC_ARM_PREL31);
f02232aa 3860
c19d1205
ZW
3861 /* Restore the original section. */
3862 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3863
3864 unwind.proc_start = NULL;
c19d1205 3865}
f02232aa 3866
f02232aa 3867
c19d1205 3868/* Parse an unwind_cantunwind directive. */
b99bd4ef 3869
c19d1205
ZW
3870static void
3871s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3872{
3873 demand_empty_rest_of_line ();
921e5f0a 3874 if (!unwind.proc_start)
c921be7d 3875 as_bad (MISSING_FNSTART);
921e5f0a 3876
c19d1205
ZW
3877 if (unwind.personality_routine || unwind.personality_index != -1)
3878 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3879
c19d1205
ZW
3880 unwind.personality_index = -2;
3881}
b99bd4ef 3882
b99bd4ef 3883
c19d1205 3884/* Parse a personalityindex directive. */
b99bd4ef 3885
c19d1205
ZW
3886static void
3887s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3888{
3889 expressionS exp;
b99bd4ef 3890
921e5f0a 3891 if (!unwind.proc_start)
c921be7d 3892 as_bad (MISSING_FNSTART);
921e5f0a 3893
c19d1205
ZW
3894 if (unwind.personality_routine || unwind.personality_index != -1)
3895 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3896
c19d1205 3897 expression (&exp);
b99bd4ef 3898
c19d1205
ZW
3899 if (exp.X_op != O_constant
3900 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3901 {
c19d1205
ZW
3902 as_bad (_("bad personality routine number"));
3903 ignore_rest_of_line ();
3904 return;
b99bd4ef
NC
3905 }
3906
c19d1205 3907 unwind.personality_index = exp.X_add_number;
b99bd4ef 3908
c19d1205
ZW
3909 demand_empty_rest_of_line ();
3910}
e16bb312 3911
e16bb312 3912
c19d1205 3913/* Parse a personality directive. */
e16bb312 3914
c19d1205
ZW
3915static void
3916s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3917{
3918 char *name, *p, c;
a737bd4d 3919
921e5f0a 3920 if (!unwind.proc_start)
c921be7d 3921 as_bad (MISSING_FNSTART);
921e5f0a 3922
c19d1205
ZW
3923 if (unwind.personality_routine || unwind.personality_index != -1)
3924 as_bad (_("duplicate .personality directive"));
a737bd4d 3925
d02603dc 3926 c = get_symbol_name (& name);
c19d1205 3927 p = input_line_pointer;
d02603dc
NC
3928 if (c == '"')
3929 ++ input_line_pointer;
c19d1205
ZW
3930 unwind.personality_routine = symbol_find_or_make (name);
3931 *p = c;
3932 demand_empty_rest_of_line ();
3933}
e16bb312 3934
e16bb312 3935
c19d1205 3936/* Parse a directive saving core registers. */
e16bb312 3937
c19d1205
ZW
3938static void
3939s_arm_unwind_save_core (void)
e16bb312 3940{
c19d1205
ZW
3941 valueT op;
3942 long range;
3943 int n;
e16bb312 3944
c19d1205
ZW
3945 range = parse_reg_list (&input_line_pointer);
3946 if (range == FAIL)
e16bb312 3947 {
c19d1205
ZW
3948 as_bad (_("expected register list"));
3949 ignore_rest_of_line ();
3950 return;
3951 }
e16bb312 3952
c19d1205 3953 demand_empty_rest_of_line ();
e16bb312 3954
c19d1205
ZW
3955 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3956 into .unwind_save {..., sp...}. We aren't bothered about the value of
3957 ip because it is clobbered by calls. */
3958 if (unwind.sp_restored && unwind.fp_reg == 12
3959 && (range & 0x3000) == 0x1000)
3960 {
3961 unwind.opcode_count--;
3962 unwind.sp_restored = 0;
3963 range = (range | 0x2000) & ~0x1000;
3964 unwind.pending_offset = 0;
3965 }
e16bb312 3966
01ae4198
DJ
3967 /* Pop r4-r15. */
3968 if (range & 0xfff0)
c19d1205 3969 {
01ae4198
DJ
3970 /* See if we can use the short opcodes. These pop a block of up to 8
3971 registers starting with r4, plus maybe r14. */
3972 for (n = 0; n < 8; n++)
3973 {
3974 /* Break at the first non-saved register. */
3975 if ((range & (1 << (n + 4))) == 0)
3976 break;
3977 }
3978 /* See if there are any other bits set. */
3979 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3980 {
3981 /* Use the long form. */
3982 op = 0x8000 | ((range >> 4) & 0xfff);
3983 add_unwind_opcode (op, 2);
3984 }
0dd132b6 3985 else
01ae4198
DJ
3986 {
3987 /* Use the short form. */
3988 if (range & 0x4000)
3989 op = 0xa8; /* Pop r14. */
3990 else
3991 op = 0xa0; /* Do not pop r14. */
3992 op |= (n - 1);
3993 add_unwind_opcode (op, 1);
3994 }
c19d1205 3995 }
0dd132b6 3996
c19d1205
ZW
3997 /* Pop r0-r3. */
3998 if (range & 0xf)
3999 {
4000 op = 0xb100 | (range & 0xf);
4001 add_unwind_opcode (op, 2);
0dd132b6
NC
4002 }
4003
c19d1205
ZW
4004 /* Record the number of bytes pushed. */
4005 for (n = 0; n < 16; n++)
4006 {
4007 if (range & (1 << n))
4008 unwind.frame_size += 4;
4009 }
0dd132b6
NC
4010}
4011
c19d1205
ZW
4012
4013/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4014
4015static void
c19d1205 4016s_arm_unwind_save_fpa (int reg)
b99bd4ef 4017{
c19d1205
ZW
4018 expressionS exp;
4019 int num_regs;
4020 valueT op;
b99bd4ef 4021
c19d1205
ZW
4022 /* Get Number of registers to transfer. */
4023 if (skip_past_comma (&input_line_pointer) != FAIL)
4024 expression (&exp);
4025 else
4026 exp.X_op = O_illegal;
b99bd4ef 4027
c19d1205 4028 if (exp.X_op != O_constant)
b99bd4ef 4029 {
c19d1205
ZW
4030 as_bad (_("expected , <constant>"));
4031 ignore_rest_of_line ();
b99bd4ef
NC
4032 return;
4033 }
4034
c19d1205
ZW
4035 num_regs = exp.X_add_number;
4036
4037 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4038 {
c19d1205
ZW
4039 as_bad (_("number of registers must be in the range [1:4]"));
4040 ignore_rest_of_line ();
b99bd4ef
NC
4041 return;
4042 }
4043
c19d1205 4044 demand_empty_rest_of_line ();
b99bd4ef 4045
c19d1205
ZW
4046 if (reg == 4)
4047 {
4048 /* Short form. */
4049 op = 0xb4 | (num_regs - 1);
4050 add_unwind_opcode (op, 1);
4051 }
b99bd4ef
NC
4052 else
4053 {
c19d1205
ZW
4054 /* Long form. */
4055 op = 0xc800 | (reg << 4) | (num_regs - 1);
4056 add_unwind_opcode (op, 2);
b99bd4ef 4057 }
c19d1205 4058 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4059}
4060
c19d1205 4061
fa073d69
MS
4062/* Parse a directive saving VFP registers for ARMv6 and above. */
4063
4064static void
4065s_arm_unwind_save_vfp_armv6 (void)
4066{
4067 int count;
4068 unsigned int start;
4069 valueT op;
4070 int num_vfpv3_regs = 0;
4071 int num_regs_below_16;
4072
4073 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4074 if (count == FAIL)
4075 {
4076 as_bad (_("expected register list"));
4077 ignore_rest_of_line ();
4078 return;
4079 }
4080
4081 demand_empty_rest_of_line ();
4082
4083 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4084 than FSTMX/FLDMX-style ones). */
4085
4086 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4087 if (start >= 16)
4088 num_vfpv3_regs = count;
4089 else if (start + count > 16)
4090 num_vfpv3_regs = start + count - 16;
4091
4092 if (num_vfpv3_regs > 0)
4093 {
4094 int start_offset = start > 16 ? start - 16 : 0;
4095 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4096 add_unwind_opcode (op, 2);
4097 }
4098
4099 /* Generate opcode for registers numbered in the range 0 .. 15. */
4100 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4101 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4102 if (num_regs_below_16 > 0)
4103 {
4104 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4105 add_unwind_opcode (op, 2);
4106 }
4107
4108 unwind.frame_size += count * 8;
4109}
4110
4111
4112/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4113
4114static void
c19d1205 4115s_arm_unwind_save_vfp (void)
b99bd4ef 4116{
c19d1205 4117 int count;
ca3f61f7 4118 unsigned int reg;
c19d1205 4119 valueT op;
b99bd4ef 4120
5287ad62 4121 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4122 if (count == FAIL)
b99bd4ef 4123 {
c19d1205
ZW
4124 as_bad (_("expected register list"));
4125 ignore_rest_of_line ();
b99bd4ef
NC
4126 return;
4127 }
4128
c19d1205 4129 demand_empty_rest_of_line ();
b99bd4ef 4130
c19d1205 4131 if (reg == 8)
b99bd4ef 4132 {
c19d1205
ZW
4133 /* Short form. */
4134 op = 0xb8 | (count - 1);
4135 add_unwind_opcode (op, 1);
b99bd4ef 4136 }
c19d1205 4137 else
b99bd4ef 4138 {
c19d1205
ZW
4139 /* Long form. */
4140 op = 0xb300 | (reg << 4) | (count - 1);
4141 add_unwind_opcode (op, 2);
b99bd4ef 4142 }
c19d1205
ZW
4143 unwind.frame_size += count * 8 + 4;
4144}
b99bd4ef 4145
b99bd4ef 4146
c19d1205
ZW
4147/* Parse a directive saving iWMMXt data registers. */
4148
4149static void
4150s_arm_unwind_save_mmxwr (void)
4151{
4152 int reg;
4153 int hi_reg;
4154 int i;
4155 unsigned mask = 0;
4156 valueT op;
b99bd4ef 4157
c19d1205
ZW
4158 if (*input_line_pointer == '{')
4159 input_line_pointer++;
b99bd4ef 4160
c19d1205 4161 do
b99bd4ef 4162 {
dcbf9037 4163 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4164
c19d1205 4165 if (reg == FAIL)
b99bd4ef 4166 {
9b7132d3 4167 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4168 goto error;
b99bd4ef
NC
4169 }
4170
c19d1205
ZW
4171 if (mask >> reg)
4172 as_tsktsk (_("register list not in ascending order"));
4173 mask |= 1 << reg;
b99bd4ef 4174
c19d1205
ZW
4175 if (*input_line_pointer == '-')
4176 {
4177 input_line_pointer++;
dcbf9037 4178 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4179 if (hi_reg == FAIL)
4180 {
9b7132d3 4181 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4182 goto error;
4183 }
4184 else if (reg >= hi_reg)
4185 {
4186 as_bad (_("bad register range"));
4187 goto error;
4188 }
4189 for (; reg < hi_reg; reg++)
4190 mask |= 1 << reg;
4191 }
4192 }
4193 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4194
d996d970 4195 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4196
c19d1205 4197 demand_empty_rest_of_line ();
b99bd4ef 4198
708587a4 4199 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4200 the list. */
4201 flush_pending_unwind ();
b99bd4ef 4202
c19d1205 4203 for (i = 0; i < 16; i++)
b99bd4ef 4204 {
c19d1205
ZW
4205 if (mask & (1 << i))
4206 unwind.frame_size += 8;
b99bd4ef
NC
4207 }
4208
c19d1205
ZW
4209 /* Attempt to combine with a previous opcode. We do this because gcc
4210 likes to output separate unwind directives for a single block of
4211 registers. */
4212 if (unwind.opcode_count > 0)
b99bd4ef 4213 {
c19d1205
ZW
4214 i = unwind.opcodes[unwind.opcode_count - 1];
4215 if ((i & 0xf8) == 0xc0)
4216 {
4217 i &= 7;
4218 /* Only merge if the blocks are contiguous. */
4219 if (i < 6)
4220 {
4221 if ((mask & 0xfe00) == (1 << 9))
4222 {
4223 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4224 unwind.opcode_count--;
4225 }
4226 }
4227 else if (i == 6 && unwind.opcode_count >= 2)
4228 {
4229 i = unwind.opcodes[unwind.opcode_count - 2];
4230 reg = i >> 4;
4231 i &= 0xf;
b99bd4ef 4232
c19d1205
ZW
4233 op = 0xffff << (reg - 1);
4234 if (reg > 0
87a1fd79 4235 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4236 {
4237 op = (1 << (reg + i + 1)) - 1;
4238 op &= ~((1 << reg) - 1);
4239 mask |= op;
4240 unwind.opcode_count -= 2;
4241 }
4242 }
4243 }
b99bd4ef
NC
4244 }
4245
c19d1205
ZW
4246 hi_reg = 15;
4247 /* We want to generate opcodes in the order the registers have been
4248 saved, ie. descending order. */
4249 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4250 {
c19d1205
ZW
4251 /* Save registers in blocks. */
4252 if (reg < 0
4253 || !(mask & (1 << reg)))
4254 {
4255 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4256 preceding block. */
c19d1205
ZW
4257 if (reg != hi_reg)
4258 {
4259 if (reg == 9)
4260 {
4261 /* Short form. */
4262 op = 0xc0 | (hi_reg - 10);
4263 add_unwind_opcode (op, 1);
4264 }
4265 else
4266 {
4267 /* Long form. */
4268 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4269 add_unwind_opcode (op, 2);
4270 }
4271 }
4272 hi_reg = reg - 1;
4273 }
b99bd4ef
NC
4274 }
4275
c19d1205
ZW
4276 return;
4277error:
4278 ignore_rest_of_line ();
b99bd4ef
NC
4279}
4280
4281static void
c19d1205 4282s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4283{
c19d1205
ZW
4284 int reg;
4285 int hi_reg;
4286 unsigned mask = 0;
4287 valueT op;
b99bd4ef 4288
c19d1205
ZW
4289 if (*input_line_pointer == '{')
4290 input_line_pointer++;
b99bd4ef 4291
477330fc
RM
4292 skip_whitespace (input_line_pointer);
4293
c19d1205 4294 do
b99bd4ef 4295 {
dcbf9037 4296 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4297
c19d1205
ZW
4298 if (reg == FAIL)
4299 {
9b7132d3 4300 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4301 goto error;
4302 }
b99bd4ef 4303
c19d1205
ZW
4304 reg -= 8;
4305 if (mask >> reg)
4306 as_tsktsk (_("register list not in ascending order"));
4307 mask |= 1 << reg;
b99bd4ef 4308
c19d1205
ZW
4309 if (*input_line_pointer == '-')
4310 {
4311 input_line_pointer++;
dcbf9037 4312 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4313 if (hi_reg == FAIL)
4314 {
9b7132d3 4315 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4316 goto error;
4317 }
4318 else if (reg >= hi_reg)
4319 {
4320 as_bad (_("bad register range"));
4321 goto error;
4322 }
4323 for (; reg < hi_reg; reg++)
4324 mask |= 1 << reg;
4325 }
b99bd4ef 4326 }
c19d1205 4327 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4328
d996d970 4329 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4330
c19d1205
ZW
4331 demand_empty_rest_of_line ();
4332
708587a4 4333 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4334 the list. */
4335 flush_pending_unwind ();
b99bd4ef 4336
c19d1205 4337 for (reg = 0; reg < 16; reg++)
b99bd4ef 4338 {
c19d1205
ZW
4339 if (mask & (1 << reg))
4340 unwind.frame_size += 4;
b99bd4ef 4341 }
c19d1205
ZW
4342 op = 0xc700 | mask;
4343 add_unwind_opcode (op, 2);
4344 return;
4345error:
4346 ignore_rest_of_line ();
b99bd4ef
NC
4347}
4348
c19d1205 4349
fa073d69
MS
4350/* Parse an unwind_save directive.
4351 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4352
b99bd4ef 4353static void
fa073d69 4354s_arm_unwind_save (int arch_v6)
b99bd4ef 4355{
c19d1205
ZW
4356 char *peek;
4357 struct reg_entry *reg;
4358 bfd_boolean had_brace = FALSE;
b99bd4ef 4359
921e5f0a 4360 if (!unwind.proc_start)
c921be7d 4361 as_bad (MISSING_FNSTART);
921e5f0a 4362
c19d1205
ZW
4363 /* Figure out what sort of save we have. */
4364 peek = input_line_pointer;
b99bd4ef 4365
c19d1205 4366 if (*peek == '{')
b99bd4ef 4367 {
c19d1205
ZW
4368 had_brace = TRUE;
4369 peek++;
b99bd4ef
NC
4370 }
4371
c19d1205 4372 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4373
c19d1205 4374 if (!reg)
b99bd4ef 4375 {
c19d1205
ZW
4376 as_bad (_("register expected"));
4377 ignore_rest_of_line ();
b99bd4ef
NC
4378 return;
4379 }
4380
c19d1205 4381 switch (reg->type)
b99bd4ef 4382 {
c19d1205
ZW
4383 case REG_TYPE_FN:
4384 if (had_brace)
4385 {
4386 as_bad (_("FPA .unwind_save does not take a register list"));
4387 ignore_rest_of_line ();
4388 return;
4389 }
93ac2687 4390 input_line_pointer = peek;
c19d1205 4391 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4392 return;
c19d1205 4393
1f5afe1c
NC
4394 case REG_TYPE_RN:
4395 s_arm_unwind_save_core ();
4396 return;
4397
fa073d69
MS
4398 case REG_TYPE_VFD:
4399 if (arch_v6)
477330fc 4400 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4401 else
477330fc 4402 s_arm_unwind_save_vfp ();
fa073d69 4403 return;
1f5afe1c
NC
4404
4405 case REG_TYPE_MMXWR:
4406 s_arm_unwind_save_mmxwr ();
4407 return;
4408
4409 case REG_TYPE_MMXWCG:
4410 s_arm_unwind_save_mmxwcg ();
4411 return;
c19d1205
ZW
4412
4413 default:
4414 as_bad (_(".unwind_save does not support this kind of register"));
4415 ignore_rest_of_line ();
b99bd4ef 4416 }
c19d1205 4417}
b99bd4ef 4418
b99bd4ef 4419
c19d1205
ZW
4420/* Parse an unwind_movsp directive. */
4421
4422static void
4423s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4424{
4425 int reg;
4426 valueT op;
4fa3602b 4427 int offset;
c19d1205 4428
921e5f0a 4429 if (!unwind.proc_start)
c921be7d 4430 as_bad (MISSING_FNSTART);
921e5f0a 4431
dcbf9037 4432 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4433 if (reg == FAIL)
b99bd4ef 4434 {
9b7132d3 4435 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4436 ignore_rest_of_line ();
b99bd4ef
NC
4437 return;
4438 }
4fa3602b
PB
4439
4440 /* Optional constant. */
4441 if (skip_past_comma (&input_line_pointer) != FAIL)
4442 {
4443 if (immediate_for_directive (&offset) == FAIL)
4444 return;
4445 }
4446 else
4447 offset = 0;
4448
c19d1205 4449 demand_empty_rest_of_line ();
b99bd4ef 4450
c19d1205 4451 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4452 {
c19d1205 4453 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4454 return;
4455 }
4456
c19d1205
ZW
4457 if (unwind.fp_reg != REG_SP)
4458 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4459
c19d1205
ZW
4460 /* Generate opcode to restore the value. */
4461 op = 0x90 | reg;
4462 add_unwind_opcode (op, 1);
4463
4464 /* Record the information for later. */
4465 unwind.fp_reg = reg;
4fa3602b 4466 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4467 unwind.sp_restored = 1;
b05fe5cf
ZW
4468}
4469
c19d1205
ZW
4470/* Parse an unwind_pad directive. */
4471
b05fe5cf 4472static void
c19d1205 4473s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4474{
c19d1205 4475 int offset;
b05fe5cf 4476
921e5f0a 4477 if (!unwind.proc_start)
c921be7d 4478 as_bad (MISSING_FNSTART);
921e5f0a 4479
c19d1205
ZW
4480 if (immediate_for_directive (&offset) == FAIL)
4481 return;
b99bd4ef 4482
c19d1205
ZW
4483 if (offset & 3)
4484 {
4485 as_bad (_("stack increment must be multiple of 4"));
4486 ignore_rest_of_line ();
4487 return;
4488 }
b99bd4ef 4489
c19d1205
ZW
4490 /* Don't generate any opcodes, just record the details for later. */
4491 unwind.frame_size += offset;
4492 unwind.pending_offset += offset;
4493
4494 demand_empty_rest_of_line ();
4495}
4496
4497/* Parse an unwind_setfp directive. */
4498
4499static void
4500s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4501{
c19d1205
ZW
4502 int sp_reg;
4503 int fp_reg;
4504 int offset;
4505
921e5f0a 4506 if (!unwind.proc_start)
c921be7d 4507 as_bad (MISSING_FNSTART);
921e5f0a 4508
dcbf9037 4509 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4510 if (skip_past_comma (&input_line_pointer) == FAIL)
4511 sp_reg = FAIL;
4512 else
dcbf9037 4513 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4514
c19d1205
ZW
4515 if (fp_reg == FAIL || sp_reg == FAIL)
4516 {
4517 as_bad (_("expected <reg>, <reg>"));
4518 ignore_rest_of_line ();
4519 return;
4520 }
b99bd4ef 4521
c19d1205
ZW
4522 /* Optional constant. */
4523 if (skip_past_comma (&input_line_pointer) != FAIL)
4524 {
4525 if (immediate_for_directive (&offset) == FAIL)
4526 return;
4527 }
4528 else
4529 offset = 0;
a737bd4d 4530
c19d1205 4531 demand_empty_rest_of_line ();
a737bd4d 4532
fdfde340 4533 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4534 {
c19d1205
ZW
4535 as_bad (_("register must be either sp or set by a previous"
4536 "unwind_movsp directive"));
4537 return;
a737bd4d
NC
4538 }
4539
c19d1205
ZW
4540 /* Don't generate any opcodes, just record the information for later. */
4541 unwind.fp_reg = fp_reg;
4542 unwind.fp_used = 1;
fdfde340 4543 if (sp_reg == REG_SP)
c19d1205
ZW
4544 unwind.fp_offset = unwind.frame_size - offset;
4545 else
4546 unwind.fp_offset -= offset;
a737bd4d
NC
4547}
4548
c19d1205
ZW
4549/* Parse an unwind_raw directive. */
4550
4551static void
4552s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4553{
c19d1205 4554 expressionS exp;
708587a4 4555 /* This is an arbitrary limit. */
c19d1205
ZW
4556 unsigned char op[16];
4557 int count;
a737bd4d 4558
921e5f0a 4559 if (!unwind.proc_start)
c921be7d 4560 as_bad (MISSING_FNSTART);
921e5f0a 4561
c19d1205
ZW
4562 expression (&exp);
4563 if (exp.X_op == O_constant
4564 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4565 {
c19d1205
ZW
4566 unwind.frame_size += exp.X_add_number;
4567 expression (&exp);
4568 }
4569 else
4570 exp.X_op = O_illegal;
a737bd4d 4571
c19d1205
ZW
4572 if (exp.X_op != O_constant)
4573 {
4574 as_bad (_("expected <offset>, <opcode>"));
4575 ignore_rest_of_line ();
4576 return;
4577 }
a737bd4d 4578
c19d1205 4579 count = 0;
a737bd4d 4580
c19d1205
ZW
4581 /* Parse the opcode. */
4582 for (;;)
4583 {
4584 if (count >= 16)
4585 {
4586 as_bad (_("unwind opcode too long"));
4587 ignore_rest_of_line ();
a737bd4d 4588 }
c19d1205 4589 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4590 {
c19d1205
ZW
4591 as_bad (_("invalid unwind opcode"));
4592 ignore_rest_of_line ();
4593 return;
a737bd4d 4594 }
c19d1205 4595 op[count++] = exp.X_add_number;
a737bd4d 4596
c19d1205
ZW
4597 /* Parse the next byte. */
4598 if (skip_past_comma (&input_line_pointer) == FAIL)
4599 break;
a737bd4d 4600
c19d1205
ZW
4601 expression (&exp);
4602 }
b99bd4ef 4603
c19d1205
ZW
4604 /* Add the opcode bytes in reverse order. */
4605 while (count--)
4606 add_unwind_opcode (op[count], 1);
b99bd4ef 4607
c19d1205 4608 demand_empty_rest_of_line ();
b99bd4ef 4609}
ee065d83
PB
4610
4611
4612/* Parse a .eabi_attribute directive. */
4613
4614static void
4615s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4616{
0420f52b 4617 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4618
4619 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4620 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4621}
4622
0855e32b
NS
4623/* Emit a tls fix for the symbol. */
4624
4625static void
4626s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4627{
4628 char *p;
4629 expressionS exp;
4630#ifdef md_flush_pending_output
4631 md_flush_pending_output ();
4632#endif
4633
4634#ifdef md_cons_align
4635 md_cons_align (4);
4636#endif
4637
4638 /* Since we're just labelling the code, there's no need to define a
4639 mapping symbol. */
4640 expression (&exp);
4641 p = obstack_next_free (&frchain_now->frch_obstack);
4642 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4643 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4644 : BFD_RELOC_ARM_TLS_DESCSEQ);
4645}
cdf9ccec 4646#endif /* OBJ_ELF */
0855e32b 4647
ee065d83 4648static void s_arm_arch (int);
7a1d4c38 4649static void s_arm_object_arch (int);
ee065d83
PB
4650static void s_arm_cpu (int);
4651static void s_arm_fpu (int);
69133863 4652static void s_arm_arch_extension (int);
b99bd4ef 4653
f0927246
NC
4654#ifdef TE_PE
4655
4656static void
5f4273c7 4657pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4658{
4659 expressionS exp;
4660
4661 do
4662 {
4663 expression (&exp);
4664 if (exp.X_op == O_symbol)
4665 exp.X_op = O_secrel;
4666
4667 emit_expr (&exp, 4);
4668 }
4669 while (*input_line_pointer++ == ',');
4670
4671 input_line_pointer--;
4672 demand_empty_rest_of_line ();
4673}
4674#endif /* TE_PE */
4675
c19d1205
ZW
4676/* This table describes all the machine specific pseudo-ops the assembler
4677 has to support. The fields are:
4678 pseudo-op name without dot
4679 function to call to execute this pseudo-op
4680 Integer arg to pass to the function. */
b99bd4ef 4681
c19d1205 4682const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4683{
c19d1205
ZW
4684 /* Never called because '.req' does not start a line. */
4685 { "req", s_req, 0 },
dcbf9037
JB
4686 /* Following two are likewise never called. */
4687 { "dn", s_dn, 0 },
4688 { "qn", s_qn, 0 },
c19d1205
ZW
4689 { "unreq", s_unreq, 0 },
4690 { "bss", s_bss, 0 },
db2ed2e0 4691 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4692 { "arm", s_arm, 0 },
4693 { "thumb", s_thumb, 0 },
4694 { "code", s_code, 0 },
4695 { "force_thumb", s_force_thumb, 0 },
4696 { "thumb_func", s_thumb_func, 0 },
4697 { "thumb_set", s_thumb_set, 0 },
4698 { "even", s_even, 0 },
4699 { "ltorg", s_ltorg, 0 },
4700 { "pool", s_ltorg, 0 },
4701 { "syntax", s_syntax, 0 },
8463be01
PB
4702 { "cpu", s_arm_cpu, 0 },
4703 { "arch", s_arm_arch, 0 },
7a1d4c38 4704 { "object_arch", s_arm_object_arch, 0 },
8463be01 4705 { "fpu", s_arm_fpu, 0 },
69133863 4706 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4707#ifdef OBJ_ELF
c921be7d
NC
4708 { "word", s_arm_elf_cons, 4 },
4709 { "long", s_arm_elf_cons, 4 },
4710 { "inst.n", s_arm_elf_inst, 2 },
4711 { "inst.w", s_arm_elf_inst, 4 },
4712 { "inst", s_arm_elf_inst, 0 },
4713 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4714 { "fnstart", s_arm_unwind_fnstart, 0 },
4715 { "fnend", s_arm_unwind_fnend, 0 },
4716 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4717 { "personality", s_arm_unwind_personality, 0 },
4718 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4719 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4720 { "save", s_arm_unwind_save, 0 },
fa073d69 4721 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4722 { "movsp", s_arm_unwind_movsp, 0 },
4723 { "pad", s_arm_unwind_pad, 0 },
4724 { "setfp", s_arm_unwind_setfp, 0 },
4725 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4726 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4727 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4728#else
4729 { "word", cons, 4},
f0927246
NC
4730
4731 /* These are used for dwarf. */
4732 {"2byte", cons, 2},
4733 {"4byte", cons, 4},
4734 {"8byte", cons, 8},
4735 /* These are used for dwarf2. */
4736 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4737 { "loc", dwarf2_directive_loc, 0 },
4738 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4739#endif
4740 { "extend", float_cons, 'x' },
4741 { "ldouble", float_cons, 'x' },
4742 { "packed", float_cons, 'p' },
f0927246
NC
4743#ifdef TE_PE
4744 {"secrel32", pe_directive_secrel, 0},
4745#endif
2e6976a8
DG
4746
4747 /* These are for compatibility with CodeComposer Studio. */
4748 {"ref", s_ccs_ref, 0},
4749 {"def", s_ccs_def, 0},
4750 {"asmfunc", s_ccs_asmfunc, 0},
4751 {"endasmfunc", s_ccs_endasmfunc, 0},
4752
c19d1205
ZW
4753 { 0, 0, 0 }
4754};
4755\f
4756/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4757
c19d1205
ZW
4758/* Generic immediate-value read function for use in insn parsing.
4759 STR points to the beginning of the immediate (the leading #);
4760 VAL receives the value; if the value is outside [MIN, MAX]
4761 issue an error. PREFIX_OPT is true if the immediate prefix is
4762 optional. */
b99bd4ef 4763
c19d1205
ZW
4764static int
4765parse_immediate (char **str, int *val, int min, int max,
4766 bfd_boolean prefix_opt)
4767{
4768 expressionS exp;
4769 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4770 if (exp.X_op != O_constant)
b99bd4ef 4771 {
c19d1205
ZW
4772 inst.error = _("constant expression required");
4773 return FAIL;
4774 }
b99bd4ef 4775
c19d1205
ZW
4776 if (exp.X_add_number < min || exp.X_add_number > max)
4777 {
4778 inst.error = _("immediate value out of range");
4779 return FAIL;
4780 }
b99bd4ef 4781
c19d1205
ZW
4782 *val = exp.X_add_number;
4783 return SUCCESS;
4784}
b99bd4ef 4785
5287ad62 4786/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4787 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4788 instructions. Puts the result directly in inst.operands[i]. */
4789
4790static int
8335d6aa
JW
4791parse_big_immediate (char **str, int i, expressionS *in_exp,
4792 bfd_boolean allow_symbol_p)
5287ad62
JB
4793{
4794 expressionS exp;
8335d6aa 4795 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4796 char *ptr = *str;
4797
8335d6aa 4798 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4799
8335d6aa 4800 if (exp_p->X_op == O_constant)
036dc3f7 4801 {
8335d6aa 4802 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4803 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4804 O_constant. We have to be careful not to break compilation for
4805 32-bit X_add_number, though. */
8335d6aa 4806 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4807 {
8335d6aa
JW
4808 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4809 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4810 & 0xffffffff);
036dc3f7
PB
4811 inst.operands[i].regisimm = 1;
4812 }
4813 }
8335d6aa
JW
4814 else if (exp_p->X_op == O_big
4815 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4816 {
4817 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4818
5287ad62 4819 /* Bignums have their least significant bits in
477330fc
RM
4820 generic_bignum[0]. Make sure we put 32 bits in imm and
4821 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4822 gas_assert (parts != 0);
95b75c01
NC
4823
4824 /* Make sure that the number is not too big.
4825 PR 11972: Bignums can now be sign-extended to the
4826 size of a .octa so check that the out of range bits
4827 are all zero or all one. */
8335d6aa 4828 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4829 {
4830 LITTLENUM_TYPE m = -1;
4831
4832 if (generic_bignum[parts * 2] != 0
4833 && generic_bignum[parts * 2] != m)
4834 return FAIL;
4835
8335d6aa 4836 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4837 if (generic_bignum[j] != generic_bignum[j-1])
4838 return FAIL;
4839 }
4840
5287ad62
JB
4841 inst.operands[i].imm = 0;
4842 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4843 inst.operands[i].imm |= generic_bignum[idx]
4844 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4845 inst.operands[i].reg = 0;
4846 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4847 inst.operands[i].reg |= generic_bignum[idx]
4848 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4849 inst.operands[i].regisimm = 1;
4850 }
8335d6aa 4851 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4852 return FAIL;
5f4273c7 4853
5287ad62
JB
4854 *str = ptr;
4855
4856 return SUCCESS;
4857}
4858
c19d1205
ZW
4859/* Returns the pseudo-register number of an FPA immediate constant,
4860 or FAIL if there isn't a valid constant here. */
b99bd4ef 4861
c19d1205
ZW
4862static int
4863parse_fpa_immediate (char ** str)
4864{
4865 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4866 char * save_in;
4867 expressionS exp;
4868 int i;
4869 int j;
b99bd4ef 4870
c19d1205
ZW
4871 /* First try and match exact strings, this is to guarantee
4872 that some formats will work even for cross assembly. */
b99bd4ef 4873
c19d1205
ZW
4874 for (i = 0; fp_const[i]; i++)
4875 {
4876 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4877 {
c19d1205 4878 char *start = *str;
b99bd4ef 4879
c19d1205
ZW
4880 *str += strlen (fp_const[i]);
4881 if (is_end_of_line[(unsigned char) **str])
4882 return i + 8;
4883 *str = start;
4884 }
4885 }
b99bd4ef 4886
c19d1205
ZW
4887 /* Just because we didn't get a match doesn't mean that the constant
4888 isn't valid, just that it is in a format that we don't
4889 automatically recognize. Try parsing it with the standard
4890 expression routines. */
b99bd4ef 4891
c19d1205 4892 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4893
c19d1205
ZW
4894 /* Look for a raw floating point number. */
4895 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4896 && is_end_of_line[(unsigned char) *save_in])
4897 {
4898 for (i = 0; i < NUM_FLOAT_VALS; i++)
4899 {
4900 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4901 {
c19d1205
ZW
4902 if (words[j] != fp_values[i][j])
4903 break;
b99bd4ef
NC
4904 }
4905
c19d1205 4906 if (j == MAX_LITTLENUMS)
b99bd4ef 4907 {
c19d1205
ZW
4908 *str = save_in;
4909 return i + 8;
b99bd4ef
NC
4910 }
4911 }
4912 }
b99bd4ef 4913
c19d1205
ZW
4914 /* Try and parse a more complex expression, this will probably fail
4915 unless the code uses a floating point prefix (eg "0f"). */
4916 save_in = input_line_pointer;
4917 input_line_pointer = *str;
4918 if (expression (&exp) == absolute_section
4919 && exp.X_op == O_big
4920 && exp.X_add_number < 0)
4921 {
4922 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4923 Ditto for 15. */
ba592044
AM
4924#define X_PRECISION 5
4925#define E_PRECISION 15L
4926 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4927 {
4928 for (i = 0; i < NUM_FLOAT_VALS; i++)
4929 {
4930 for (j = 0; j < MAX_LITTLENUMS; j++)
4931 {
4932 if (words[j] != fp_values[i][j])
4933 break;
4934 }
b99bd4ef 4935
c19d1205
ZW
4936 if (j == MAX_LITTLENUMS)
4937 {
4938 *str = input_line_pointer;
4939 input_line_pointer = save_in;
4940 return i + 8;
4941 }
4942 }
4943 }
b99bd4ef
NC
4944 }
4945
c19d1205
ZW
4946 *str = input_line_pointer;
4947 input_line_pointer = save_in;
4948 inst.error = _("invalid FPA immediate expression");
4949 return FAIL;
b99bd4ef
NC
4950}
4951
136da414
JB
4952/* Returns 1 if a number has "quarter-precision" float format
4953 0baBbbbbbc defgh000 00000000 00000000. */
4954
4955static int
4956is_quarter_float (unsigned imm)
4957{
4958 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4959 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4960}
4961
aacf0b33
KT
4962
4963/* Detect the presence of a floating point or integer zero constant,
4964 i.e. #0.0 or #0. */
4965
4966static bfd_boolean
4967parse_ifimm_zero (char **in)
4968{
4969 int error_code;
4970
4971 if (!is_immediate_prefix (**in))
3c6452ae
TP
4972 {
4973 /* In unified syntax, all prefixes are optional. */
4974 if (!unified_syntax)
4975 return FALSE;
4976 }
4977 else
4978 ++*in;
0900a05b
JW
4979
4980 /* Accept #0x0 as a synonym for #0. */
4981 if (strncmp (*in, "0x", 2) == 0)
4982 {
4983 int val;
4984 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4985 return FALSE;
4986 return TRUE;
4987 }
4988
aacf0b33
KT
4989 error_code = atof_generic (in, ".", EXP_CHARS,
4990 &generic_floating_point_number);
4991
4992 if (!error_code
4993 && generic_floating_point_number.sign == '+'
4994 && (generic_floating_point_number.low
4995 > generic_floating_point_number.leader))
4996 return TRUE;
4997
4998 return FALSE;
4999}
5000
136da414
JB
5001/* Parse an 8-bit "quarter-precision" floating point number of the form:
5002 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5003 The zero and minus-zero cases need special handling, since they can't be
5004 encoded in the "quarter-precision" float format, but can nonetheless be
5005 loaded as integer constants. */
136da414
JB
5006
5007static unsigned
5008parse_qfloat_immediate (char **ccp, int *immed)
5009{
5010 char *str = *ccp;
c96612cc 5011 char *fpnum;
136da414 5012 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5013 int found_fpchar = 0;
5f4273c7 5014
136da414 5015 skip_past_char (&str, '#');
5f4273c7 5016
c96612cc
JB
5017 /* We must not accidentally parse an integer as a floating-point number. Make
5018 sure that the value we parse is not an integer by checking for special
5019 characters '.' or 'e'.
5020 FIXME: This is a horrible hack, but doing better is tricky because type
5021 information isn't in a very usable state at parse time. */
5022 fpnum = str;
5023 skip_whitespace (fpnum);
5024
5025 if (strncmp (fpnum, "0x", 2) == 0)
5026 return FAIL;
5027 else
5028 {
5029 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5030 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5031 {
5032 found_fpchar = 1;
5033 break;
5034 }
c96612cc
JB
5035
5036 if (!found_fpchar)
477330fc 5037 return FAIL;
c96612cc 5038 }
5f4273c7 5039
136da414
JB
5040 if ((str = atof_ieee (str, 's', words)) != NULL)
5041 {
5042 unsigned fpword = 0;
5043 int i;
5f4273c7 5044
136da414
JB
5045 /* Our FP word must be 32 bits (single-precision FP). */
5046 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5047 {
5048 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5049 fpword |= words[i];
5050 }
5f4273c7 5051
c96612cc 5052 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5053 *immed = fpword;
136da414 5054 else
477330fc 5055 return FAIL;
136da414
JB
5056
5057 *ccp = str;
5f4273c7 5058
136da414
JB
5059 return SUCCESS;
5060 }
5f4273c7 5061
136da414
JB
5062 return FAIL;
5063}
5064
c19d1205
ZW
5065/* Shift operands. */
5066enum shift_kind
b99bd4ef 5067{
c19d1205
ZW
5068 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5069};
b99bd4ef 5070
c19d1205
ZW
5071struct asm_shift_name
5072{
5073 const char *name;
5074 enum shift_kind kind;
5075};
b99bd4ef 5076
c19d1205
ZW
5077/* Third argument to parse_shift. */
5078enum parse_shift_mode
5079{
5080 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5081 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5082 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5083 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5084 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5085};
b99bd4ef 5086
c19d1205
ZW
5087/* Parse a <shift> specifier on an ARM data processing instruction.
5088 This has three forms:
b99bd4ef 5089
c19d1205
ZW
5090 (LSL|LSR|ASL|ASR|ROR) Rs
5091 (LSL|LSR|ASL|ASR|ROR) #imm
5092 RRX
b99bd4ef 5093
c19d1205
ZW
5094 Note that ASL is assimilated to LSL in the instruction encoding, and
5095 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5096
c19d1205
ZW
5097static int
5098parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5099{
c19d1205
ZW
5100 const struct asm_shift_name *shift_name;
5101 enum shift_kind shift;
5102 char *s = *str;
5103 char *p = s;
5104 int reg;
b99bd4ef 5105
c19d1205
ZW
5106 for (p = *str; ISALPHA (*p); p++)
5107 ;
b99bd4ef 5108
c19d1205 5109 if (p == *str)
b99bd4ef 5110 {
c19d1205
ZW
5111 inst.error = _("shift expression expected");
5112 return FAIL;
b99bd4ef
NC
5113 }
5114
21d799b5 5115 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5116 p - *str);
c19d1205
ZW
5117
5118 if (shift_name == NULL)
b99bd4ef 5119 {
c19d1205
ZW
5120 inst.error = _("shift expression expected");
5121 return FAIL;
b99bd4ef
NC
5122 }
5123
c19d1205 5124 shift = shift_name->kind;
b99bd4ef 5125
c19d1205
ZW
5126 switch (mode)
5127 {
5128 case NO_SHIFT_RESTRICT:
5129 case SHIFT_IMMEDIATE: break;
b99bd4ef 5130
c19d1205
ZW
5131 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5132 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5133 {
5134 inst.error = _("'LSL' or 'ASR' required");
5135 return FAIL;
5136 }
5137 break;
b99bd4ef 5138
c19d1205
ZW
5139 case SHIFT_LSL_IMMEDIATE:
5140 if (shift != SHIFT_LSL)
5141 {
5142 inst.error = _("'LSL' required");
5143 return FAIL;
5144 }
5145 break;
b99bd4ef 5146
c19d1205
ZW
5147 case SHIFT_ASR_IMMEDIATE:
5148 if (shift != SHIFT_ASR)
5149 {
5150 inst.error = _("'ASR' required");
5151 return FAIL;
5152 }
5153 break;
b99bd4ef 5154
c19d1205
ZW
5155 default: abort ();
5156 }
b99bd4ef 5157
c19d1205
ZW
5158 if (shift != SHIFT_RRX)
5159 {
5160 /* Whitespace can appear here if the next thing is a bare digit. */
5161 skip_whitespace (p);
b99bd4ef 5162
c19d1205 5163 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5164 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5165 {
5166 inst.operands[i].imm = reg;
5167 inst.operands[i].immisreg = 1;
5168 }
5169 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5170 return FAIL;
5171 }
5172 inst.operands[i].shift_kind = shift;
5173 inst.operands[i].shifted = 1;
5174 *str = p;
5175 return SUCCESS;
b99bd4ef
NC
5176}
5177
c19d1205 5178/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5179
c19d1205
ZW
5180 #<immediate>
5181 #<immediate>, <rotate>
5182 <Rm>
5183 <Rm>, <shift>
b99bd4ef 5184
c19d1205
ZW
5185 where <shift> is defined by parse_shift above, and <rotate> is a
5186 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5187 is deferred to md_apply_fix. */
b99bd4ef 5188
c19d1205
ZW
5189static int
5190parse_shifter_operand (char **str, int i)
5191{
5192 int value;
91d6fa6a 5193 expressionS exp;
b99bd4ef 5194
dcbf9037 5195 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5196 {
5197 inst.operands[i].reg = value;
5198 inst.operands[i].isreg = 1;
b99bd4ef 5199
c19d1205
ZW
5200 /* parse_shift will override this if appropriate */
5201 inst.reloc.exp.X_op = O_constant;
5202 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5203
c19d1205
ZW
5204 if (skip_past_comma (str) == FAIL)
5205 return SUCCESS;
b99bd4ef 5206
c19d1205
ZW
5207 /* Shift operation on register. */
5208 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5209 }
5210
c19d1205
ZW
5211 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5212 return FAIL;
b99bd4ef 5213
c19d1205 5214 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5215 {
c19d1205 5216 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5217 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5218 return FAIL;
b99bd4ef 5219
91d6fa6a 5220 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5221 {
5222 inst.error = _("constant expression expected");
5223 return FAIL;
5224 }
b99bd4ef 5225
91d6fa6a 5226 value = exp.X_add_number;
c19d1205
ZW
5227 if (value < 0 || value > 30 || value % 2 != 0)
5228 {
5229 inst.error = _("invalid rotation");
5230 return FAIL;
5231 }
5232 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5233 {
5234 inst.error = _("invalid constant");
5235 return FAIL;
5236 }
09d92015 5237
a415b1cd
JB
5238 /* Encode as specified. */
5239 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5240 return SUCCESS;
09d92015
MM
5241 }
5242
c19d1205
ZW
5243 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5244 inst.reloc.pc_rel = 0;
5245 return SUCCESS;
09d92015
MM
5246}
5247
4962c51a
MS
5248/* Group relocation information. Each entry in the table contains the
5249 textual name of the relocation as may appear in assembler source
5250 and must end with a colon.
5251 Along with this textual name are the relocation codes to be used if
5252 the corresponding instruction is an ALU instruction (ADD or SUB only),
5253 an LDR, an LDRS, or an LDC. */
5254
5255struct group_reloc_table_entry
5256{
5257 const char *name;
5258 int alu_code;
5259 int ldr_code;
5260 int ldrs_code;
5261 int ldc_code;
5262};
5263
5264typedef enum
5265{
5266 /* Varieties of non-ALU group relocation. */
5267
5268 GROUP_LDR,
5269 GROUP_LDRS,
5270 GROUP_LDC
5271} group_reloc_type;
5272
5273static struct group_reloc_table_entry group_reloc_table[] =
5274 { /* Program counter relative: */
5275 { "pc_g0_nc",
5276 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5277 0, /* LDR */
5278 0, /* LDRS */
5279 0 }, /* LDC */
5280 { "pc_g0",
5281 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5282 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5283 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5284 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5285 { "pc_g1_nc",
5286 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5287 0, /* LDR */
5288 0, /* LDRS */
5289 0 }, /* LDC */
5290 { "pc_g1",
5291 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5292 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5293 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5294 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5295 { "pc_g2",
5296 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5297 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5298 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5299 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5300 /* Section base relative */
5301 { "sb_g0_nc",
5302 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5303 0, /* LDR */
5304 0, /* LDRS */
5305 0 }, /* LDC */
5306 { "sb_g0",
5307 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5308 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5309 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5310 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5311 { "sb_g1_nc",
5312 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5313 0, /* LDR */
5314 0, /* LDRS */
5315 0 }, /* LDC */
5316 { "sb_g1",
5317 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5318 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5319 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5320 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5321 { "sb_g2",
5322 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5323 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5324 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5325 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5326 /* Absolute thumb alu relocations. */
5327 { "lower0_7",
5328 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5329 0, /* LDR. */
5330 0, /* LDRS. */
5331 0 }, /* LDC. */
5332 { "lower8_15",
5333 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5334 0, /* LDR. */
5335 0, /* LDRS. */
5336 0 }, /* LDC. */
5337 { "upper0_7",
5338 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5339 0, /* LDR. */
5340 0, /* LDRS. */
5341 0 }, /* LDC. */
5342 { "upper8_15",
5343 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5344 0, /* LDR. */
5345 0, /* LDRS. */
5346 0 } }; /* LDC. */
4962c51a
MS
5347
5348/* Given the address of a pointer pointing to the textual name of a group
5349 relocation as may appear in assembler source, attempt to find its details
5350 in group_reloc_table. The pointer will be updated to the character after
5351 the trailing colon. On failure, FAIL will be returned; SUCCESS
5352 otherwise. On success, *entry will be updated to point at the relevant
5353 group_reloc_table entry. */
5354
5355static int
5356find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5357{
5358 unsigned int i;
5359 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5360 {
5361 int length = strlen (group_reloc_table[i].name);
5362
5f4273c7
NC
5363 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5364 && (*str)[length] == ':')
477330fc
RM
5365 {
5366 *out = &group_reloc_table[i];
5367 *str += (length + 1);
5368 return SUCCESS;
5369 }
4962c51a
MS
5370 }
5371
5372 return FAIL;
5373}
5374
5375/* Parse a <shifter_operand> for an ARM data processing instruction
5376 (as for parse_shifter_operand) where group relocations are allowed:
5377
5378 #<immediate>
5379 #<immediate>, <rotate>
5380 #:<group_reloc>:<expression>
5381 <Rm>
5382 <Rm>, <shift>
5383
5384 where <group_reloc> is one of the strings defined in group_reloc_table.
5385 The hashes are optional.
5386
5387 Everything else is as for parse_shifter_operand. */
5388
5389static parse_operand_result
5390parse_shifter_operand_group_reloc (char **str, int i)
5391{
5392 /* Determine if we have the sequence of characters #: or just :
5393 coming next. If we do, then we check for a group relocation.
5394 If we don't, punt the whole lot to parse_shifter_operand. */
5395
5396 if (((*str)[0] == '#' && (*str)[1] == ':')
5397 || (*str)[0] == ':')
5398 {
5399 struct group_reloc_table_entry *entry;
5400
5401 if ((*str)[0] == '#')
477330fc 5402 (*str) += 2;
4962c51a 5403 else
477330fc 5404 (*str)++;
4962c51a
MS
5405
5406 /* Try to parse a group relocation. Anything else is an error. */
5407 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5408 {
5409 inst.error = _("unknown group relocation");
5410 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5411 }
4962c51a
MS
5412
5413 /* We now have the group relocation table entry corresponding to
477330fc 5414 the name in the assembler source. Next, we parse the expression. */
4962c51a 5415 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5416 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5417
5418 /* Record the relocation type (always the ALU variant here). */
21d799b5 5419 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5420 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5421
5422 return PARSE_OPERAND_SUCCESS;
5423 }
5424 else
5425 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5426 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5427
5428 /* Never reached. */
5429}
5430
8e560766
MGD
5431/* Parse a Neon alignment expression. Information is written to
5432 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5433
8e560766
MGD
5434 align .imm = align << 8, .immisalign=1, .preind=0 */
5435static parse_operand_result
5436parse_neon_alignment (char **str, int i)
5437{
5438 char *p = *str;
5439 expressionS exp;
5440
5441 my_get_expression (&exp, &p, GE_NO_PREFIX);
5442
5443 if (exp.X_op != O_constant)
5444 {
5445 inst.error = _("alignment must be constant");
5446 return PARSE_OPERAND_FAIL;
5447 }
5448
5449 inst.operands[i].imm = exp.X_add_number << 8;
5450 inst.operands[i].immisalign = 1;
5451 /* Alignments are not pre-indexes. */
5452 inst.operands[i].preind = 0;
5453
5454 *str = p;
5455 return PARSE_OPERAND_SUCCESS;
5456}
5457
c19d1205
ZW
5458/* Parse all forms of an ARM address expression. Information is written
5459 to inst.operands[i] and/or inst.reloc.
09d92015 5460
c19d1205 5461 Preindexed addressing (.preind=1):
09d92015 5462
c19d1205
ZW
5463 [Rn, #offset] .reg=Rn .reloc.exp=offset
5464 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5465 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5466 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5467
c19d1205 5468 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5469
c19d1205 5470 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5471
c19d1205
ZW
5472 [Rn], #offset .reg=Rn .reloc.exp=offset
5473 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5474 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5475 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5476
c19d1205 5477 Unindexed addressing (.preind=0, .postind=0):
09d92015 5478
c19d1205 5479 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5480
c19d1205 5481 Other:
09d92015 5482
c19d1205
ZW
5483 [Rn]{!} shorthand for [Rn,#0]{!}
5484 =immediate .isreg=0 .reloc.exp=immediate
5485 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5486
c19d1205
ZW
5487 It is the caller's responsibility to check for addressing modes not
5488 supported by the instruction, and to set inst.reloc.type. */
5489
4962c51a
MS
5490static parse_operand_result
5491parse_address_main (char **str, int i, int group_relocations,
477330fc 5492 group_reloc_type group_type)
09d92015 5493{
c19d1205
ZW
5494 char *p = *str;
5495 int reg;
09d92015 5496
c19d1205 5497 if (skip_past_char (&p, '[') == FAIL)
09d92015 5498 {
c19d1205
ZW
5499 if (skip_past_char (&p, '=') == FAIL)
5500 {
974da60d 5501 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5502 inst.reloc.pc_rel = 1;
5503 inst.operands[i].reg = REG_PC;
5504 inst.operands[i].isreg = 1;
5505 inst.operands[i].preind = 1;
09d92015 5506
8335d6aa
JW
5507 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5508 return PARSE_OPERAND_FAIL;
5509 }
5510 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5511 /*allow_symbol_p=*/TRUE))
4962c51a 5512 return PARSE_OPERAND_FAIL;
09d92015 5513
c19d1205 5514 *str = p;
4962c51a 5515 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5516 }
5517
8ab8155f
NC
5518 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5519 skip_whitespace (p);
5520
dcbf9037 5521 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5522 {
c19d1205 5523 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5524 return PARSE_OPERAND_FAIL;
09d92015 5525 }
c19d1205
ZW
5526 inst.operands[i].reg = reg;
5527 inst.operands[i].isreg = 1;
09d92015 5528
c19d1205 5529 if (skip_past_comma (&p) == SUCCESS)
09d92015 5530 {
c19d1205 5531 inst.operands[i].preind = 1;
09d92015 5532
c19d1205
ZW
5533 if (*p == '+') p++;
5534 else if (*p == '-') p++, inst.operands[i].negative = 1;
5535
dcbf9037 5536 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5537 {
c19d1205
ZW
5538 inst.operands[i].imm = reg;
5539 inst.operands[i].immisreg = 1;
5540
5541 if (skip_past_comma (&p) == SUCCESS)
5542 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5543 return PARSE_OPERAND_FAIL;
c19d1205 5544 }
5287ad62 5545 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5546 {
5547 /* FIXME: '@' should be used here, but it's filtered out by generic
5548 code before we get to see it here. This may be subject to
5549 change. */
5550 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5551
8e560766
MGD
5552 if (result != PARSE_OPERAND_SUCCESS)
5553 return result;
5554 }
c19d1205
ZW
5555 else
5556 {
5557 if (inst.operands[i].negative)
5558 {
5559 inst.operands[i].negative = 0;
5560 p--;
5561 }
4962c51a 5562
5f4273c7
NC
5563 if (group_relocations
5564 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5565 {
5566 struct group_reloc_table_entry *entry;
5567
477330fc
RM
5568 /* Skip over the #: or : sequence. */
5569 if (*p == '#')
5570 p += 2;
5571 else
5572 p++;
4962c51a
MS
5573
5574 /* Try to parse a group relocation. Anything else is an
477330fc 5575 error. */
4962c51a
MS
5576 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5577 {
5578 inst.error = _("unknown group relocation");
5579 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5580 }
5581
5582 /* We now have the group relocation table entry corresponding to
5583 the name in the assembler source. Next, we parse the
477330fc 5584 expression. */
4962c51a
MS
5585 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5586 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5587
5588 /* Record the relocation type. */
477330fc
RM
5589 switch (group_type)
5590 {
5591 case GROUP_LDR:
5592 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5593 break;
4962c51a 5594
477330fc
RM
5595 case GROUP_LDRS:
5596 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5597 break;
4962c51a 5598
477330fc
RM
5599 case GROUP_LDC:
5600 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5601 break;
4962c51a 5602
477330fc
RM
5603 default:
5604 gas_assert (0);
5605 }
4962c51a 5606
477330fc 5607 if (inst.reloc.type == 0)
4962c51a
MS
5608 {
5609 inst.error = _("this group relocation is not allowed on this instruction");
5610 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5611 }
477330fc
RM
5612 }
5613 else
26d97720
NS
5614 {
5615 char *q = p;
5616 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5617 return PARSE_OPERAND_FAIL;
5618 /* If the offset is 0, find out if it's a +0 or -0. */
5619 if (inst.reloc.exp.X_op == O_constant
5620 && inst.reloc.exp.X_add_number == 0)
5621 {
5622 skip_whitespace (q);
5623 if (*q == '#')
5624 {
5625 q++;
5626 skip_whitespace (q);
5627 }
5628 if (*q == '-')
5629 inst.operands[i].negative = 1;
5630 }
5631 }
09d92015
MM
5632 }
5633 }
8e560766
MGD
5634 else if (skip_past_char (&p, ':') == SUCCESS)
5635 {
5636 /* FIXME: '@' should be used here, but it's filtered out by generic code
5637 before we get to see it here. This may be subject to change. */
5638 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5639
8e560766
MGD
5640 if (result != PARSE_OPERAND_SUCCESS)
5641 return result;
5642 }
09d92015 5643
c19d1205 5644 if (skip_past_char (&p, ']') == FAIL)
09d92015 5645 {
c19d1205 5646 inst.error = _("']' expected");
4962c51a 5647 return PARSE_OPERAND_FAIL;
09d92015
MM
5648 }
5649
c19d1205
ZW
5650 if (skip_past_char (&p, '!') == SUCCESS)
5651 inst.operands[i].writeback = 1;
09d92015 5652
c19d1205 5653 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5654 {
c19d1205
ZW
5655 if (skip_past_char (&p, '{') == SUCCESS)
5656 {
5657 /* [Rn], {expr} - unindexed, with option */
5658 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5659 0, 255, TRUE) == FAIL)
4962c51a 5660 return PARSE_OPERAND_FAIL;
09d92015 5661
c19d1205
ZW
5662 if (skip_past_char (&p, '}') == FAIL)
5663 {
5664 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5665 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5666 }
5667 if (inst.operands[i].preind)
5668 {
5669 inst.error = _("cannot combine index with option");
4962c51a 5670 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5671 }
5672 *str = p;
4962c51a 5673 return PARSE_OPERAND_SUCCESS;
09d92015 5674 }
c19d1205
ZW
5675 else
5676 {
5677 inst.operands[i].postind = 1;
5678 inst.operands[i].writeback = 1;
09d92015 5679
c19d1205
ZW
5680 if (inst.operands[i].preind)
5681 {
5682 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5683 return PARSE_OPERAND_FAIL;
c19d1205 5684 }
09d92015 5685
c19d1205
ZW
5686 if (*p == '+') p++;
5687 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5688
dcbf9037 5689 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5690 {
477330fc
RM
5691 /* We might be using the immediate for alignment already. If we
5692 are, OR the register number into the low-order bits. */
5693 if (inst.operands[i].immisalign)
5694 inst.operands[i].imm |= reg;
5695 else
5696 inst.operands[i].imm = reg;
c19d1205 5697 inst.operands[i].immisreg = 1;
a737bd4d 5698
c19d1205
ZW
5699 if (skip_past_comma (&p) == SUCCESS)
5700 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5701 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5702 }
5703 else
5704 {
26d97720 5705 char *q = p;
c19d1205
ZW
5706 if (inst.operands[i].negative)
5707 {
5708 inst.operands[i].negative = 0;
5709 p--;
5710 }
5711 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5712 return PARSE_OPERAND_FAIL;
26d97720
NS
5713 /* If the offset is 0, find out if it's a +0 or -0. */
5714 if (inst.reloc.exp.X_op == O_constant
5715 && inst.reloc.exp.X_add_number == 0)
5716 {
5717 skip_whitespace (q);
5718 if (*q == '#')
5719 {
5720 q++;
5721 skip_whitespace (q);
5722 }
5723 if (*q == '-')
5724 inst.operands[i].negative = 1;
5725 }
c19d1205
ZW
5726 }
5727 }
a737bd4d
NC
5728 }
5729
c19d1205
ZW
5730 /* If at this point neither .preind nor .postind is set, we have a
5731 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5732 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5733 {
5734 inst.operands[i].preind = 1;
5735 inst.reloc.exp.X_op = O_constant;
5736 inst.reloc.exp.X_add_number = 0;
5737 }
5738 *str = p;
4962c51a
MS
5739 return PARSE_OPERAND_SUCCESS;
5740}
5741
5742static int
5743parse_address (char **str, int i)
5744{
21d799b5 5745 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5746 ? SUCCESS : FAIL;
4962c51a
MS
5747}
5748
5749static parse_operand_result
5750parse_address_group_reloc (char **str, int i, group_reloc_type type)
5751{
5752 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5753}
5754
b6895b4f
PB
5755/* Parse an operand for a MOVW or MOVT instruction. */
5756static int
5757parse_half (char **str)
5758{
5759 char * p;
5f4273c7 5760
b6895b4f
PB
5761 p = *str;
5762 skip_past_char (&p, '#');
5f4273c7 5763 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5764 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5765 else if (strncasecmp (p, ":upper16:", 9) == 0)
5766 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5767
5768 if (inst.reloc.type != BFD_RELOC_UNUSED)
5769 {
5770 p += 9;
5f4273c7 5771 skip_whitespace (p);
b6895b4f
PB
5772 }
5773
5774 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5775 return FAIL;
5776
5777 if (inst.reloc.type == BFD_RELOC_UNUSED)
5778 {
5779 if (inst.reloc.exp.X_op != O_constant)
5780 {
5781 inst.error = _("constant expression expected");
5782 return FAIL;
5783 }
5784 if (inst.reloc.exp.X_add_number < 0
5785 || inst.reloc.exp.X_add_number > 0xffff)
5786 {
5787 inst.error = _("immediate value out of range");
5788 return FAIL;
5789 }
5790 }
5791 *str = p;
5792 return SUCCESS;
5793}
5794
c19d1205 5795/* Miscellaneous. */
a737bd4d 5796
c19d1205
ZW
5797/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5798 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5799static int
d2cd1205 5800parse_psr (char **str, bfd_boolean lhs)
09d92015 5801{
c19d1205
ZW
5802 char *p;
5803 unsigned long psr_field;
62b3e311
PB
5804 const struct asm_psr *psr;
5805 char *start;
d2cd1205 5806 bfd_boolean is_apsr = FALSE;
ac7f631b 5807 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5808
a4482bb6
NC
5809 /* PR gas/12698: If the user has specified -march=all then m_profile will
5810 be TRUE, but we want to ignore it in this case as we are building for any
5811 CPU type, including non-m variants. */
823d2571 5812 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5813 m_profile = FALSE;
5814
c19d1205
ZW
5815 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5816 feature for ease of use and backwards compatibility. */
5817 p = *str;
62b3e311 5818 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5819 {
5820 if (m_profile)
5821 goto unsupported_psr;
fa94de6b 5822
d2cd1205
JB
5823 psr_field = SPSR_BIT;
5824 }
5825 else if (strncasecmp (p, "CPSR", 4) == 0)
5826 {
5827 if (m_profile)
5828 goto unsupported_psr;
5829
5830 psr_field = 0;
5831 }
5832 else if (strncasecmp (p, "APSR", 4) == 0)
5833 {
5834 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5835 and ARMv7-R architecture CPUs. */
5836 is_apsr = TRUE;
5837 psr_field = 0;
5838 }
5839 else if (m_profile)
62b3e311
PB
5840 {
5841 start = p;
5842 do
5843 p++;
5844 while (ISALNUM (*p) || *p == '_');
5845
d2cd1205
JB
5846 if (strncasecmp (start, "iapsr", 5) == 0
5847 || strncasecmp (start, "eapsr", 5) == 0
5848 || strncasecmp (start, "xpsr", 4) == 0
5849 || strncasecmp (start, "psr", 3) == 0)
5850 p = start + strcspn (start, "rR") + 1;
5851
21d799b5 5852 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5853 p - start);
d2cd1205 5854
62b3e311
PB
5855 if (!psr)
5856 return FAIL;
09d92015 5857
d2cd1205
JB
5858 /* If APSR is being written, a bitfield may be specified. Note that
5859 APSR itself is handled above. */
5860 if (psr->field <= 3)
5861 {
5862 psr_field = psr->field;
5863 is_apsr = TRUE;
5864 goto check_suffix;
5865 }
5866
62b3e311 5867 *str = p;
d2cd1205
JB
5868 /* M-profile MSR instructions have the mask field set to "10", except
5869 *PSR variants which modify APSR, which may use a different mask (and
5870 have been handled already). Do that by setting the PSR_f field
5871 here. */
5872 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5873 }
d2cd1205
JB
5874 else
5875 goto unsupported_psr;
09d92015 5876
62b3e311 5877 p += 4;
d2cd1205 5878check_suffix:
c19d1205
ZW
5879 if (*p == '_')
5880 {
5881 /* A suffix follows. */
c19d1205
ZW
5882 p++;
5883 start = p;
a737bd4d 5884
c19d1205
ZW
5885 do
5886 p++;
5887 while (ISALNUM (*p) || *p == '_');
a737bd4d 5888
d2cd1205
JB
5889 if (is_apsr)
5890 {
5891 /* APSR uses a notation for bits, rather than fields. */
5892 unsigned int nzcvq_bits = 0;
5893 unsigned int g_bit = 0;
5894 char *bit;
fa94de6b 5895
d2cd1205
JB
5896 for (bit = start; bit != p; bit++)
5897 {
5898 switch (TOLOWER (*bit))
477330fc 5899 {
d2cd1205
JB
5900 case 'n':
5901 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5902 break;
5903
5904 case 'z':
5905 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5906 break;
5907
5908 case 'c':
5909 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5910 break;
5911
5912 case 'v':
5913 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5914 break;
fa94de6b 5915
d2cd1205
JB
5916 case 'q':
5917 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5918 break;
fa94de6b 5919
d2cd1205
JB
5920 case 'g':
5921 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5922 break;
fa94de6b 5923
d2cd1205
JB
5924 default:
5925 inst.error = _("unexpected bit specified after APSR");
5926 return FAIL;
5927 }
5928 }
fa94de6b 5929
d2cd1205
JB
5930 if (nzcvq_bits == 0x1f)
5931 psr_field |= PSR_f;
fa94de6b 5932
d2cd1205
JB
5933 if (g_bit == 0x1)
5934 {
5935 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5936 {
d2cd1205
JB
5937 inst.error = _("selected processor does not "
5938 "support DSP extension");
5939 return FAIL;
5940 }
5941
5942 psr_field |= PSR_s;
5943 }
fa94de6b 5944
d2cd1205
JB
5945 if ((nzcvq_bits & 0x20) != 0
5946 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5947 || (g_bit & 0x2) != 0)
5948 {
5949 inst.error = _("bad bitmask specified after APSR");
5950 return FAIL;
5951 }
5952 }
5953 else
477330fc 5954 {
d2cd1205 5955 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5956 p - start);
d2cd1205 5957 if (!psr)
477330fc 5958 goto error;
a737bd4d 5959
d2cd1205
JB
5960 psr_field |= psr->field;
5961 }
a737bd4d 5962 }
c19d1205 5963 else
a737bd4d 5964 {
c19d1205
ZW
5965 if (ISALNUM (*p))
5966 goto error; /* Garbage after "[CS]PSR". */
5967
d2cd1205 5968 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5969 is deprecated, but allow it anyway. */
d2cd1205
JB
5970 if (is_apsr && lhs)
5971 {
5972 psr_field |= PSR_f;
5973 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5974 "deprecated"));
5975 }
5976 else if (!m_profile)
5977 /* These bits are never right for M-profile devices: don't set them
5978 (only code paths which read/write APSR reach here). */
5979 psr_field |= (PSR_c | PSR_f);
a737bd4d 5980 }
c19d1205
ZW
5981 *str = p;
5982 return psr_field;
a737bd4d 5983
d2cd1205
JB
5984 unsupported_psr:
5985 inst.error = _("selected processor does not support requested special "
5986 "purpose register");
5987 return FAIL;
5988
c19d1205
ZW
5989 error:
5990 inst.error = _("flag for {c}psr instruction expected");
5991 return FAIL;
a737bd4d
NC
5992}
5993
c19d1205
ZW
5994/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5995 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5996
c19d1205
ZW
5997static int
5998parse_cps_flags (char **str)
a737bd4d 5999{
c19d1205
ZW
6000 int val = 0;
6001 int saw_a_flag = 0;
6002 char *s = *str;
a737bd4d 6003
c19d1205
ZW
6004 for (;;)
6005 switch (*s++)
6006 {
6007 case '\0': case ',':
6008 goto done;
a737bd4d 6009
c19d1205
ZW
6010 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6011 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6012 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6013
c19d1205
ZW
6014 default:
6015 inst.error = _("unrecognized CPS flag");
6016 return FAIL;
6017 }
a737bd4d 6018
c19d1205
ZW
6019 done:
6020 if (saw_a_flag == 0)
a737bd4d 6021 {
c19d1205
ZW
6022 inst.error = _("missing CPS flags");
6023 return FAIL;
a737bd4d 6024 }
a737bd4d 6025
c19d1205
ZW
6026 *str = s - 1;
6027 return val;
a737bd4d
NC
6028}
6029
c19d1205
ZW
6030/* Parse an endian specifier ("BE" or "LE", case insensitive);
6031 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6032
6033static int
c19d1205 6034parse_endian_specifier (char **str)
a737bd4d 6035{
c19d1205
ZW
6036 int little_endian;
6037 char *s = *str;
a737bd4d 6038
c19d1205
ZW
6039 if (strncasecmp (s, "BE", 2))
6040 little_endian = 0;
6041 else if (strncasecmp (s, "LE", 2))
6042 little_endian = 1;
6043 else
a737bd4d 6044 {
c19d1205 6045 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6046 return FAIL;
6047 }
6048
c19d1205 6049 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6050 {
c19d1205 6051 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6052 return FAIL;
6053 }
6054
c19d1205
ZW
6055 *str = s + 2;
6056 return little_endian;
6057}
a737bd4d 6058
c19d1205
ZW
6059/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6060 value suitable for poking into the rotate field of an sxt or sxta
6061 instruction, or FAIL on error. */
6062
6063static int
6064parse_ror (char **str)
6065{
6066 int rot;
6067 char *s = *str;
6068
6069 if (strncasecmp (s, "ROR", 3) == 0)
6070 s += 3;
6071 else
a737bd4d 6072 {
c19d1205 6073 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6074 return FAIL;
6075 }
c19d1205
ZW
6076
6077 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6078 return FAIL;
6079
6080 switch (rot)
a737bd4d 6081 {
c19d1205
ZW
6082 case 0: *str = s; return 0x0;
6083 case 8: *str = s; return 0x1;
6084 case 16: *str = s; return 0x2;
6085 case 24: *str = s; return 0x3;
6086
6087 default:
6088 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6089 return FAIL;
6090 }
c19d1205 6091}
a737bd4d 6092
c19d1205
ZW
6093/* Parse a conditional code (from conds[] below). The value returned is in the
6094 range 0 .. 14, or FAIL. */
6095static int
6096parse_cond (char **str)
6097{
c462b453 6098 char *q;
c19d1205 6099 const struct asm_cond *c;
c462b453
PB
6100 int n;
6101 /* Condition codes are always 2 characters, so matching up to
6102 3 characters is sufficient. */
6103 char cond[3];
a737bd4d 6104
c462b453
PB
6105 q = *str;
6106 n = 0;
6107 while (ISALPHA (*q) && n < 3)
6108 {
e07e6e58 6109 cond[n] = TOLOWER (*q);
c462b453
PB
6110 q++;
6111 n++;
6112 }
a737bd4d 6113
21d799b5 6114 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6115 if (!c)
a737bd4d 6116 {
c19d1205 6117 inst.error = _("condition required");
a737bd4d
NC
6118 return FAIL;
6119 }
6120
c19d1205
ZW
6121 *str = q;
6122 return c->value;
6123}
6124
643afb90
MW
6125/* Record a use of the given feature. */
6126static void
6127record_feature_use (const arm_feature_set *feature)
6128{
6129 if (thumb_mode)
6130 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6131 else
6132 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6133}
6134
e797f7e0
MGD
6135/* If the given feature available in the selected CPU, mark it as used.
6136 Returns TRUE iff feature is available. */
6137static bfd_boolean
6138mark_feature_used (const arm_feature_set *feature)
6139{
6140 /* Ensure the option is valid on the current architecture. */
6141 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6142 return FALSE;
6143
6144 /* Add the appropriate architecture feature for the barrier option used.
6145 */
643afb90 6146 record_feature_use (feature);
e797f7e0
MGD
6147
6148 return TRUE;
6149}
6150
62b3e311
PB
6151/* Parse an option for a barrier instruction. Returns the encoding for the
6152 option, or FAIL. */
6153static int
6154parse_barrier (char **str)
6155{
6156 char *p, *q;
6157 const struct asm_barrier_opt *o;
6158
6159 p = q = *str;
6160 while (ISALPHA (*q))
6161 q++;
6162
21d799b5 6163 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6164 q - p);
62b3e311
PB
6165 if (!o)
6166 return FAIL;
6167
e797f7e0
MGD
6168 if (!mark_feature_used (&o->arch))
6169 return FAIL;
6170
62b3e311
PB
6171 *str = q;
6172 return o->value;
6173}
6174
92e90b6e
PB
6175/* Parse the operands of a table branch instruction. Similar to a memory
6176 operand. */
6177static int
6178parse_tb (char **str)
6179{
6180 char * p = *str;
6181 int reg;
6182
6183 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6184 {
6185 inst.error = _("'[' expected");
6186 return FAIL;
6187 }
92e90b6e 6188
dcbf9037 6189 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6190 {
6191 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6192 return FAIL;
6193 }
6194 inst.operands[0].reg = reg;
6195
6196 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6197 {
6198 inst.error = _("',' expected");
6199 return FAIL;
6200 }
5f4273c7 6201
dcbf9037 6202 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6203 {
6204 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6205 return FAIL;
6206 }
6207 inst.operands[0].imm = reg;
6208
6209 if (skip_past_comma (&p) == SUCCESS)
6210 {
6211 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6212 return FAIL;
6213 if (inst.reloc.exp.X_add_number != 1)
6214 {
6215 inst.error = _("invalid shift");
6216 return FAIL;
6217 }
6218 inst.operands[0].shifted = 1;
6219 }
6220
6221 if (skip_past_char (&p, ']') == FAIL)
6222 {
6223 inst.error = _("']' expected");
6224 return FAIL;
6225 }
6226 *str = p;
6227 return SUCCESS;
6228}
6229
5287ad62
JB
6230/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6231 information on the types the operands can take and how they are encoded.
037e8744
JB
6232 Up to four operands may be read; this function handles setting the
6233 ".present" field for each read operand itself.
5287ad62
JB
6234 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6235 else returns FAIL. */
6236
6237static int
6238parse_neon_mov (char **str, int *which_operand)
6239{
6240 int i = *which_operand, val;
6241 enum arm_reg_type rtype;
6242 char *ptr = *str;
dcbf9037 6243 struct neon_type_el optype;
5f4273c7 6244
dcbf9037 6245 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6246 {
6247 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6248 inst.operands[i].reg = val;
6249 inst.operands[i].isscalar = 1;
dcbf9037 6250 inst.operands[i].vectype = optype;
5287ad62
JB
6251 inst.operands[i++].present = 1;
6252
6253 if (skip_past_comma (&ptr) == FAIL)
477330fc 6254 goto wanted_comma;
5f4273c7 6255
dcbf9037 6256 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6257 goto wanted_arm;
5f4273c7 6258
5287ad62
JB
6259 inst.operands[i].reg = val;
6260 inst.operands[i].isreg = 1;
6261 inst.operands[i].present = 1;
6262 }
037e8744 6263 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6264 != FAIL)
5287ad62
JB
6265 {
6266 /* Cases 0, 1, 2, 3, 5 (D only). */
6267 if (skip_past_comma (&ptr) == FAIL)
477330fc 6268 goto wanted_comma;
5f4273c7 6269
5287ad62
JB
6270 inst.operands[i].reg = val;
6271 inst.operands[i].isreg = 1;
6272 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6273 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6274 inst.operands[i].isvec = 1;
dcbf9037 6275 inst.operands[i].vectype = optype;
5287ad62
JB
6276 inst.operands[i++].present = 1;
6277
dcbf9037 6278 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6279 {
6280 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6281 Case 13: VMOV <Sd>, <Rm> */
6282 inst.operands[i].reg = val;
6283 inst.operands[i].isreg = 1;
6284 inst.operands[i].present = 1;
6285
6286 if (rtype == REG_TYPE_NQ)
6287 {
6288 first_error (_("can't use Neon quad register here"));
6289 return FAIL;
6290 }
6291 else if (rtype != REG_TYPE_VFS)
6292 {
6293 i++;
6294 if (skip_past_comma (&ptr) == FAIL)
6295 goto wanted_comma;
6296 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6297 goto wanted_arm;
6298 inst.operands[i].reg = val;
6299 inst.operands[i].isreg = 1;
6300 inst.operands[i].present = 1;
6301 }
6302 }
037e8744 6303 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6304 &optype)) != FAIL)
6305 {
6306 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6307 Case 1: VMOV<c><q> <Dd>, <Dm>
6308 Case 8: VMOV.F32 <Sd>, <Sm>
6309 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6310
6311 inst.operands[i].reg = val;
6312 inst.operands[i].isreg = 1;
6313 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6315 inst.operands[i].isvec = 1;
6316 inst.operands[i].vectype = optype;
6317 inst.operands[i].present = 1;
6318
6319 if (skip_past_comma (&ptr) == SUCCESS)
6320 {
6321 /* Case 15. */
6322 i++;
6323
6324 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6325 goto wanted_arm;
6326
6327 inst.operands[i].reg = val;
6328 inst.operands[i].isreg = 1;
6329 inst.operands[i++].present = 1;
6330
6331 if (skip_past_comma (&ptr) == FAIL)
6332 goto wanted_comma;
6333
6334 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6335 goto wanted_arm;
6336
6337 inst.operands[i].reg = val;
6338 inst.operands[i].isreg = 1;
6339 inst.operands[i].present = 1;
6340 }
6341 }
4641781c 6342 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6343 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6344 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6345 Case 10: VMOV.F32 <Sd>, #<imm>
6346 Case 11: VMOV.F64 <Dd>, #<imm> */
6347 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6348 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6349 == SUCCESS)
477330fc
RM
6350 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6351 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6352 ;
5287ad62 6353 else
477330fc
RM
6354 {
6355 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6356 return FAIL;
6357 }
5287ad62 6358 }
dcbf9037 6359 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6360 {
6361 /* Cases 6, 7. */
6362 inst.operands[i].reg = val;
6363 inst.operands[i].isreg = 1;
6364 inst.operands[i++].present = 1;
5f4273c7 6365
5287ad62 6366 if (skip_past_comma (&ptr) == FAIL)
477330fc 6367 goto wanted_comma;
5f4273c7 6368
dcbf9037 6369 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6370 {
6371 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6372 inst.operands[i].reg = val;
6373 inst.operands[i].isscalar = 1;
6374 inst.operands[i].present = 1;
6375 inst.operands[i].vectype = optype;
6376 }
dcbf9037 6377 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6378 {
6379 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6380 inst.operands[i].reg = val;
6381 inst.operands[i].isreg = 1;
6382 inst.operands[i++].present = 1;
6383
6384 if (skip_past_comma (&ptr) == FAIL)
6385 goto wanted_comma;
6386
6387 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6388 == FAIL)
6389 {
6390 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6391 return FAIL;
6392 }
6393
6394 inst.operands[i].reg = val;
6395 inst.operands[i].isreg = 1;
6396 inst.operands[i].isvec = 1;
6397 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6398 inst.operands[i].vectype = optype;
6399 inst.operands[i].present = 1;
6400
6401 if (rtype == REG_TYPE_VFS)
6402 {
6403 /* Case 14. */
6404 i++;
6405 if (skip_past_comma (&ptr) == FAIL)
6406 goto wanted_comma;
6407 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6408 &optype)) == FAIL)
6409 {
6410 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6411 return FAIL;
6412 }
6413 inst.operands[i].reg = val;
6414 inst.operands[i].isreg = 1;
6415 inst.operands[i].isvec = 1;
6416 inst.operands[i].issingle = 1;
6417 inst.operands[i].vectype = optype;
6418 inst.operands[i].present = 1;
6419 }
6420 }
037e8744 6421 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6422 != FAIL)
6423 {
6424 /* Case 13. */
6425 inst.operands[i].reg = val;
6426 inst.operands[i].isreg = 1;
6427 inst.operands[i].isvec = 1;
6428 inst.operands[i].issingle = 1;
6429 inst.operands[i].vectype = optype;
6430 inst.operands[i].present = 1;
6431 }
5287ad62
JB
6432 }
6433 else
6434 {
dcbf9037 6435 first_error (_("parse error"));
5287ad62
JB
6436 return FAIL;
6437 }
6438
6439 /* Successfully parsed the operands. Update args. */
6440 *which_operand = i;
6441 *str = ptr;
6442 return SUCCESS;
6443
5f4273c7 6444 wanted_comma:
dcbf9037 6445 first_error (_("expected comma"));
5287ad62 6446 return FAIL;
5f4273c7
NC
6447
6448 wanted_arm:
dcbf9037 6449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6450 return FAIL;
5287ad62
JB
6451}
6452
5be8be5d
DG
6453/* Use this macro when the operand constraints are different
6454 for ARM and THUMB (e.g. ldrd). */
6455#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6456 ((arm_operand) | ((thumb_operand) << 16))
6457
c19d1205
ZW
6458/* Matcher codes for parse_operands. */
6459enum operand_parse_code
6460{
6461 OP_stop, /* end of line */
6462
6463 OP_RR, /* ARM register */
6464 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6465 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6466 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6467 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6468 optional trailing ! */
c19d1205
ZW
6469 OP_RRw, /* ARM register, not r15, optional trailing ! */
6470 OP_RCP, /* Coprocessor number */
6471 OP_RCN, /* Coprocessor register */
6472 OP_RF, /* FPA register */
6473 OP_RVS, /* VFP single precision register */
5287ad62
JB
6474 OP_RVD, /* VFP double precision register (0..15) */
6475 OP_RND, /* Neon double precision register (0..31) */
6476 OP_RNQ, /* Neon quad precision register */
037e8744 6477 OP_RVSD, /* VFP single or double precision register */
5287ad62 6478 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6479 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6480 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6481 OP_RVC, /* VFP control register */
6482 OP_RMF, /* Maverick F register */
6483 OP_RMD, /* Maverick D register */
6484 OP_RMFX, /* Maverick FX register */
6485 OP_RMDX, /* Maverick DX register */
6486 OP_RMAX, /* Maverick AX register */
6487 OP_RMDS, /* Maverick DSPSC register */
6488 OP_RIWR, /* iWMMXt wR register */
6489 OP_RIWC, /* iWMMXt wC register */
6490 OP_RIWG, /* iWMMXt wCG register */
6491 OP_RXA, /* XScale accumulator register */
6492
6493 OP_REGLST, /* ARM register list */
6494 OP_VRSLST, /* VFP single-precision register list */
6495 OP_VRDLST, /* VFP double-precision register list */
037e8744 6496 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6497 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6498 OP_NSTRLST, /* Neon element/structure list */
6499
5287ad62 6500 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6501 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6502 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6503 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6504 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6505 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6506 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6507 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6508 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6509 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6510 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6511
6512 OP_I0, /* immediate zero */
c19d1205
ZW
6513 OP_I7, /* immediate value 0 .. 7 */
6514 OP_I15, /* 0 .. 15 */
6515 OP_I16, /* 1 .. 16 */
5287ad62 6516 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6517 OP_I31, /* 0 .. 31 */
6518 OP_I31w, /* 0 .. 31, optional trailing ! */
6519 OP_I32, /* 1 .. 32 */
5287ad62
JB
6520 OP_I32z, /* 0 .. 32 */
6521 OP_I63, /* 0 .. 63 */
c19d1205 6522 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6523 OP_I64, /* 1 .. 64 */
6524 OP_I64z, /* 0 .. 64 */
c19d1205 6525 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6526
6527 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6528 OP_I7b, /* 0 .. 7 */
6529 OP_I15b, /* 0 .. 15 */
6530 OP_I31b, /* 0 .. 31 */
6531
6532 OP_SH, /* shifter operand */
4962c51a 6533 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6534 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6535 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6536 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6537 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6538 OP_EXP, /* arbitrary expression */
6539 OP_EXPi, /* same, with optional immediate prefix */
6540 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6541 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6542 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6543 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6544
6545 OP_CPSF, /* CPS flags */
6546 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6547 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6548 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6549 OP_COND, /* conditional code */
92e90b6e 6550 OP_TB, /* Table branch. */
c19d1205 6551
037e8744
JB
6552 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6553
c19d1205 6554 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6555 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6556 OP_RR_EXi, /* ARM register or expression with imm prefix */
6557 OP_RF_IF, /* FPA register or immediate */
6558 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6559 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6560
6561 /* Optional operands. */
6562 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6563 OP_oI31b, /* 0 .. 31 */
5287ad62 6564 OP_oI32b, /* 1 .. 32 */
5f1af56b 6565 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6566 OP_oIffffb, /* 0 .. 65535 */
6567 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6568
6569 OP_oRR, /* ARM register */
6570 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6571 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6572 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6573 OP_oRND, /* Optional Neon double precision register */
6574 OP_oRNQ, /* Optional Neon quad precision register */
6575 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6576 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6577 OP_oSHll, /* LSL immediate */
6578 OP_oSHar, /* ASR immediate */
6579 OP_oSHllar, /* LSL or ASR immediate */
6580 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6581 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6582
5be8be5d
DG
6583 /* Some pre-defined mixed (ARM/THUMB) operands. */
6584 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6585 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6586 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6587
c19d1205
ZW
6588 OP_FIRST_OPTIONAL = OP_oI7b
6589};
a737bd4d 6590
c19d1205
ZW
6591/* Generic instruction operand parser. This does no encoding and no
6592 semantic validation; it merely squirrels values away in the inst
6593 structure. Returns SUCCESS or FAIL depending on whether the
6594 specified grammar matched. */
6595static int
5be8be5d 6596parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6597{
5be8be5d 6598 unsigned const int *upat = pattern;
c19d1205
ZW
6599 char *backtrack_pos = 0;
6600 const char *backtrack_error = 0;
99aad254 6601 int i, val = 0, backtrack_index = 0;
5287ad62 6602 enum arm_reg_type rtype;
4962c51a 6603 parse_operand_result result;
5be8be5d 6604 unsigned int op_parse_code;
c19d1205 6605
e07e6e58
NC
6606#define po_char_or_fail(chr) \
6607 do \
6608 { \
6609 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6610 goto bad_args; \
e07e6e58
NC
6611 } \
6612 while (0)
c19d1205 6613
e07e6e58
NC
6614#define po_reg_or_fail(regtype) \
6615 do \
dcbf9037 6616 { \
e07e6e58 6617 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6618 & inst.operands[i].vectype); \
e07e6e58 6619 if (val == FAIL) \
477330fc
RM
6620 { \
6621 first_error (_(reg_expected_msgs[regtype])); \
6622 goto failure; \
6623 } \
e07e6e58
NC
6624 inst.operands[i].reg = val; \
6625 inst.operands[i].isreg = 1; \
6626 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6627 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6628 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6629 || rtype == REG_TYPE_VFD \
6630 || rtype == REG_TYPE_NQ); \
dcbf9037 6631 } \
e07e6e58
NC
6632 while (0)
6633
6634#define po_reg_or_goto(regtype, label) \
6635 do \
6636 { \
6637 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6638 & inst.operands[i].vectype); \
6639 if (val == FAIL) \
6640 goto label; \
dcbf9037 6641 \
e07e6e58
NC
6642 inst.operands[i].reg = val; \
6643 inst.operands[i].isreg = 1; \
6644 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6645 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6646 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6647 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6648 || rtype == REG_TYPE_NQ); \
6649 } \
6650 while (0)
6651
6652#define po_imm_or_fail(min, max, popt) \
6653 do \
6654 { \
6655 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6656 goto failure; \
6657 inst.operands[i].imm = val; \
6658 } \
6659 while (0)
6660
6661#define po_scalar_or_goto(elsz, label) \
6662 do \
6663 { \
6664 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6665 if (val == FAIL) \
6666 goto label; \
6667 inst.operands[i].reg = val; \
6668 inst.operands[i].isscalar = 1; \
6669 } \
6670 while (0)
6671
6672#define po_misc_or_fail(expr) \
6673 do \
6674 { \
6675 if (expr) \
6676 goto failure; \
6677 } \
6678 while (0)
6679
6680#define po_misc_or_fail_no_backtrack(expr) \
6681 do \
6682 { \
6683 result = expr; \
6684 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6685 backtrack_pos = 0; \
6686 if (result != PARSE_OPERAND_SUCCESS) \
6687 goto failure; \
6688 } \
6689 while (0)
4962c51a 6690
52e7f43d
RE
6691#define po_barrier_or_imm(str) \
6692 do \
6693 { \
6694 val = parse_barrier (&str); \
ccb84d65
JB
6695 if (val == FAIL && ! ISALPHA (*str)) \
6696 goto immediate; \
6697 if (val == FAIL \
6698 /* ISB can only take SY as an option. */ \
6699 || ((inst.instruction & 0xf0) == 0x60 \
6700 && val != 0xf)) \
52e7f43d 6701 { \
ccb84d65
JB
6702 inst.error = _("invalid barrier type"); \
6703 backtrack_pos = 0; \
6704 goto failure; \
52e7f43d
RE
6705 } \
6706 } \
6707 while (0)
6708
c19d1205
ZW
6709 skip_whitespace (str);
6710
6711 for (i = 0; upat[i] != OP_stop; i++)
6712 {
5be8be5d
DG
6713 op_parse_code = upat[i];
6714 if (op_parse_code >= 1<<16)
6715 op_parse_code = thumb ? (op_parse_code >> 16)
6716 : (op_parse_code & ((1<<16)-1));
6717
6718 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6719 {
6720 /* Remember where we are in case we need to backtrack. */
9c2799c2 6721 gas_assert (!backtrack_pos);
c19d1205
ZW
6722 backtrack_pos = str;
6723 backtrack_error = inst.error;
6724 backtrack_index = i;
6725 }
6726
b6702015 6727 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6728 po_char_or_fail (',');
6729
5be8be5d 6730 switch (op_parse_code)
c19d1205
ZW
6731 {
6732 /* Registers */
6733 case OP_oRRnpc:
5be8be5d 6734 case OP_oRRnpcsp:
c19d1205 6735 case OP_RRnpc:
5be8be5d 6736 case OP_RRnpcsp:
c19d1205
ZW
6737 case OP_oRR:
6738 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6739 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6740 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6741 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6742 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6743 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6744 case OP_oRND:
5287ad62 6745 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6746 case OP_RVC:
6747 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6748 break;
6749 /* Also accept generic coprocessor regs for unknown registers. */
6750 coproc_reg:
6751 po_reg_or_fail (REG_TYPE_CN);
6752 break;
c19d1205
ZW
6753 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6754 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6755 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6756 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6757 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6758 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6759 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6760 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6761 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6762 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6763 case OP_oRNQ:
5287ad62 6764 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6765 case OP_oRNDQ:
5287ad62 6766 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6767 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6768 case OP_oRNSDQ:
6769 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6770
6771 /* Neon scalar. Using an element size of 8 means that some invalid
6772 scalars are accepted here, so deal with those in later code. */
6773 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6774
6775 case OP_RNDQ_I0:
6776 {
6777 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6778 break;
6779 try_imm0:
6780 po_imm_or_fail (0, 0, TRUE);
6781 }
6782 break;
6783
6784 case OP_RVSD_I0:
6785 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6786 break;
6787
aacf0b33
KT
6788 case OP_RSVD_FI0:
6789 {
6790 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6791 break;
6792 try_ifimm0:
6793 if (parse_ifimm_zero (&str))
6794 inst.operands[i].imm = 0;
6795 else
6796 {
6797 inst.error
6798 = _("only floating point zero is allowed as immediate value");
6799 goto failure;
6800 }
6801 }
6802 break;
6803
477330fc
RM
6804 case OP_RR_RNSC:
6805 {
6806 po_scalar_or_goto (8, try_rr);
6807 break;
6808 try_rr:
6809 po_reg_or_fail (REG_TYPE_RN);
6810 }
6811 break;
6812
6813 case OP_RNSDQ_RNSC:
6814 {
6815 po_scalar_or_goto (8, try_nsdq);
6816 break;
6817 try_nsdq:
6818 po_reg_or_fail (REG_TYPE_NSDQ);
6819 }
6820 break;
6821
6822 case OP_RNDQ_RNSC:
6823 {
6824 po_scalar_or_goto (8, try_ndq);
6825 break;
6826 try_ndq:
6827 po_reg_or_fail (REG_TYPE_NDQ);
6828 }
6829 break;
6830
6831 case OP_RND_RNSC:
6832 {
6833 po_scalar_or_goto (8, try_vfd);
6834 break;
6835 try_vfd:
6836 po_reg_or_fail (REG_TYPE_VFD);
6837 }
6838 break;
6839
6840 case OP_VMOV:
6841 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6842 not careful then bad things might happen. */
6843 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6844 break;
6845
6846 case OP_RNDQ_Ibig:
6847 {
6848 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6849 break;
6850 try_immbig:
6851 /* There's a possibility of getting a 64-bit immediate here, so
6852 we need special handling. */
8335d6aa
JW
6853 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6854 == FAIL)
477330fc
RM
6855 {
6856 inst.error = _("immediate value is out of range");
6857 goto failure;
6858 }
6859 }
6860 break;
6861
6862 case OP_RNDQ_I63b:
6863 {
6864 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6865 break;
6866 try_shimm:
6867 po_imm_or_fail (0, 63, TRUE);
6868 }
6869 break;
c19d1205
ZW
6870
6871 case OP_RRnpcb:
6872 po_char_or_fail ('[');
6873 po_reg_or_fail (REG_TYPE_RN);
6874 po_char_or_fail (']');
6875 break;
a737bd4d 6876
55881a11 6877 case OP_RRnpctw:
c19d1205 6878 case OP_RRw:
b6702015 6879 case OP_oRRw:
c19d1205
ZW
6880 po_reg_or_fail (REG_TYPE_RN);
6881 if (skip_past_char (&str, '!') == SUCCESS)
6882 inst.operands[i].writeback = 1;
6883 break;
6884
6885 /* Immediates */
6886 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6887 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6888 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6889 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6890 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6891 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6892 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6893 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6894 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6895 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6896 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6897 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6898
6899 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6900 case OP_oI7b:
6901 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6902 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6903 case OP_oI31b:
6904 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6905 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6906 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6907 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6908
6909 /* Immediate variants */
6910 case OP_oI255c:
6911 po_char_or_fail ('{');
6912 po_imm_or_fail (0, 255, TRUE);
6913 po_char_or_fail ('}');
6914 break;
6915
6916 case OP_I31w:
6917 /* The expression parser chokes on a trailing !, so we have
6918 to find it first and zap it. */
6919 {
6920 char *s = str;
6921 while (*s && *s != ',')
6922 s++;
6923 if (s[-1] == '!')
6924 {
6925 s[-1] = '\0';
6926 inst.operands[i].writeback = 1;
6927 }
6928 po_imm_or_fail (0, 31, TRUE);
6929 if (str == s - 1)
6930 str = s;
6931 }
6932 break;
6933
6934 /* Expressions */
6935 case OP_EXPi: EXPi:
6936 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6937 GE_OPT_PREFIX));
6938 break;
6939
6940 case OP_EXP:
6941 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6942 GE_NO_PREFIX));
6943 break;
6944
6945 case OP_EXPr: EXPr:
6946 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6947 GE_NO_PREFIX));
6948 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6949 {
c19d1205
ZW
6950 val = parse_reloc (&str);
6951 if (val == -1)
6952 {
6953 inst.error = _("unrecognized relocation suffix");
6954 goto failure;
6955 }
6956 else if (val != BFD_RELOC_UNUSED)
6957 {
6958 inst.operands[i].imm = val;
6959 inst.operands[i].hasreloc = 1;
6960 }
a737bd4d 6961 }
c19d1205 6962 break;
a737bd4d 6963
b6895b4f
PB
6964 /* Operand for MOVW or MOVT. */
6965 case OP_HALF:
6966 po_misc_or_fail (parse_half (&str));
6967 break;
6968
e07e6e58 6969 /* Register or expression. */
c19d1205
ZW
6970 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6971 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6972
e07e6e58 6973 /* Register or immediate. */
c19d1205
ZW
6974 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6975 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6976
c19d1205
ZW
6977 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6978 IF:
6979 if (!is_immediate_prefix (*str))
6980 goto bad_args;
6981 str++;
6982 val = parse_fpa_immediate (&str);
6983 if (val == FAIL)
6984 goto failure;
6985 /* FPA immediates are encoded as registers 8-15.
6986 parse_fpa_immediate has already applied the offset. */
6987 inst.operands[i].reg = val;
6988 inst.operands[i].isreg = 1;
6989 break;
09d92015 6990
2d447fca
JM
6991 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6992 I32z: po_imm_or_fail (0, 32, FALSE); break;
6993
e07e6e58 6994 /* Two kinds of register. */
c19d1205
ZW
6995 case OP_RIWR_RIWC:
6996 {
6997 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6998 if (!rege
6999 || (rege->type != REG_TYPE_MMXWR
7000 && rege->type != REG_TYPE_MMXWC
7001 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7002 {
7003 inst.error = _("iWMMXt data or control register expected");
7004 goto failure;
7005 }
7006 inst.operands[i].reg = rege->number;
7007 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7008 }
7009 break;
09d92015 7010
41adaa5c
JM
7011 case OP_RIWC_RIWG:
7012 {
7013 struct reg_entry *rege = arm_reg_parse_multi (&str);
7014 if (!rege
7015 || (rege->type != REG_TYPE_MMXWC
7016 && rege->type != REG_TYPE_MMXWCG))
7017 {
7018 inst.error = _("iWMMXt control register expected");
7019 goto failure;
7020 }
7021 inst.operands[i].reg = rege->number;
7022 inst.operands[i].isreg = 1;
7023 }
7024 break;
7025
c19d1205
ZW
7026 /* Misc */
7027 case OP_CPSF: val = parse_cps_flags (&str); break;
7028 case OP_ENDI: val = parse_endian_specifier (&str); break;
7029 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7030 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7031 case OP_oBARRIER_I15:
7032 po_barrier_or_imm (str); break;
7033 immediate:
7034 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7035 goto failure;
52e7f43d 7036 break;
c19d1205 7037
fa94de6b 7038 case OP_wPSR:
d2cd1205 7039 case OP_rPSR:
90ec0d68
MGD
7040 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7041 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7042 {
7043 inst.error = _("Banked registers are not available with this "
7044 "architecture.");
7045 goto failure;
7046 }
7047 break;
d2cd1205
JB
7048 try_psr:
7049 val = parse_psr (&str, op_parse_code == OP_wPSR);
7050 break;
037e8744 7051
477330fc
RM
7052 case OP_APSR_RR:
7053 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7054 break;
7055 try_apsr:
7056 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7057 instruction). */
7058 if (strncasecmp (str, "APSR_", 5) == 0)
7059 {
7060 unsigned found = 0;
7061 str += 5;
7062 while (found < 15)
7063 switch (*str++)
7064 {
7065 case 'c': found = (found & 1) ? 16 : found | 1; break;
7066 case 'n': found = (found & 2) ? 16 : found | 2; break;
7067 case 'z': found = (found & 4) ? 16 : found | 4; break;
7068 case 'v': found = (found & 8) ? 16 : found | 8; break;
7069 default: found = 16;
7070 }
7071 if (found != 15)
7072 goto failure;
7073 inst.operands[i].isvec = 1;
f7c21dc7
NC
7074 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7075 inst.operands[i].reg = REG_PC;
477330fc
RM
7076 }
7077 else
7078 goto failure;
7079 break;
037e8744 7080
92e90b6e
PB
7081 case OP_TB:
7082 po_misc_or_fail (parse_tb (&str));
7083 break;
7084
e07e6e58 7085 /* Register lists. */
c19d1205
ZW
7086 case OP_REGLST:
7087 val = parse_reg_list (&str);
7088 if (*str == '^')
7089 {
5e0d7f77 7090 inst.operands[i].writeback = 1;
c19d1205
ZW
7091 str++;
7092 }
7093 break;
09d92015 7094
c19d1205 7095 case OP_VRSLST:
5287ad62 7096 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7097 break;
09d92015 7098
c19d1205 7099 case OP_VRDLST:
5287ad62 7100 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7101 break;
a737bd4d 7102
477330fc
RM
7103 case OP_VRSDLST:
7104 /* Allow Q registers too. */
7105 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7106 REGLIST_NEON_D);
7107 if (val == FAIL)
7108 {
7109 inst.error = NULL;
7110 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7111 REGLIST_VFP_S);
7112 inst.operands[i].issingle = 1;
7113 }
7114 break;
7115
7116 case OP_NRDLST:
7117 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7118 REGLIST_NEON_D);
7119 break;
5287ad62
JB
7120
7121 case OP_NSTRLST:
477330fc
RM
7122 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7123 &inst.operands[i].vectype);
7124 break;
5287ad62 7125
c19d1205
ZW
7126 /* Addressing modes */
7127 case OP_ADDR:
7128 po_misc_or_fail (parse_address (&str, i));
7129 break;
09d92015 7130
4962c51a
MS
7131 case OP_ADDRGLDR:
7132 po_misc_or_fail_no_backtrack (
477330fc 7133 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7134 break;
7135
7136 case OP_ADDRGLDRS:
7137 po_misc_or_fail_no_backtrack (
477330fc 7138 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7139 break;
7140
7141 case OP_ADDRGLDC:
7142 po_misc_or_fail_no_backtrack (
477330fc 7143 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7144 break;
7145
c19d1205
ZW
7146 case OP_SH:
7147 po_misc_or_fail (parse_shifter_operand (&str, i));
7148 break;
09d92015 7149
4962c51a
MS
7150 case OP_SHG:
7151 po_misc_or_fail_no_backtrack (
477330fc 7152 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7153 break;
7154
c19d1205
ZW
7155 case OP_oSHll:
7156 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7157 break;
09d92015 7158
c19d1205
ZW
7159 case OP_oSHar:
7160 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7161 break;
09d92015 7162
c19d1205
ZW
7163 case OP_oSHllar:
7164 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7165 break;
09d92015 7166
c19d1205 7167 default:
5be8be5d 7168 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7169 }
09d92015 7170
c19d1205
ZW
7171 /* Various value-based sanity checks and shared operations. We
7172 do not signal immediate failures for the register constraints;
7173 this allows a syntax error to take precedence. */
5be8be5d 7174 switch (op_parse_code)
c19d1205
ZW
7175 {
7176 case OP_oRRnpc:
7177 case OP_RRnpc:
7178 case OP_RRnpcb:
7179 case OP_RRw:
b6702015 7180 case OP_oRRw:
c19d1205
ZW
7181 case OP_RRnpc_I0:
7182 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7183 inst.error = BAD_PC;
7184 break;
09d92015 7185
5be8be5d
DG
7186 case OP_oRRnpcsp:
7187 case OP_RRnpcsp:
7188 if (inst.operands[i].isreg)
7189 {
7190 if (inst.operands[i].reg == REG_PC)
7191 inst.error = BAD_PC;
7192 else if (inst.operands[i].reg == REG_SP)
7193 inst.error = BAD_SP;
7194 }
7195 break;
7196
55881a11 7197 case OP_RRnpctw:
fa94de6b
RM
7198 if (inst.operands[i].isreg
7199 && inst.operands[i].reg == REG_PC
55881a11
MGD
7200 && (inst.operands[i].writeback || thumb))
7201 inst.error = BAD_PC;
7202 break;
7203
c19d1205
ZW
7204 case OP_CPSF:
7205 case OP_ENDI:
7206 case OP_oROR:
d2cd1205
JB
7207 case OP_wPSR:
7208 case OP_rPSR:
c19d1205 7209 case OP_COND:
52e7f43d 7210 case OP_oBARRIER_I15:
c19d1205
ZW
7211 case OP_REGLST:
7212 case OP_VRSLST:
7213 case OP_VRDLST:
477330fc
RM
7214 case OP_VRSDLST:
7215 case OP_NRDLST:
7216 case OP_NSTRLST:
c19d1205
ZW
7217 if (val == FAIL)
7218 goto failure;
7219 inst.operands[i].imm = val;
7220 break;
a737bd4d 7221
c19d1205
ZW
7222 default:
7223 break;
7224 }
09d92015 7225
c19d1205
ZW
7226 /* If we get here, this operand was successfully parsed. */
7227 inst.operands[i].present = 1;
7228 continue;
09d92015 7229
c19d1205 7230 bad_args:
09d92015 7231 inst.error = BAD_ARGS;
c19d1205
ZW
7232
7233 failure:
7234 if (!backtrack_pos)
d252fdde
PB
7235 {
7236 /* The parse routine should already have set inst.error, but set a
5f4273c7 7237 default here just in case. */
d252fdde
PB
7238 if (!inst.error)
7239 inst.error = _("syntax error");
7240 return FAIL;
7241 }
c19d1205
ZW
7242
7243 /* Do not backtrack over a trailing optional argument that
7244 absorbed some text. We will only fail again, with the
7245 'garbage following instruction' error message, which is
7246 probably less helpful than the current one. */
7247 if (backtrack_index == i && backtrack_pos != str
7248 && upat[i+1] == OP_stop)
d252fdde
PB
7249 {
7250 if (!inst.error)
7251 inst.error = _("syntax error");
7252 return FAIL;
7253 }
c19d1205
ZW
7254
7255 /* Try again, skipping the optional argument at backtrack_pos. */
7256 str = backtrack_pos;
7257 inst.error = backtrack_error;
7258 inst.operands[backtrack_index].present = 0;
7259 i = backtrack_index;
7260 backtrack_pos = 0;
09d92015 7261 }
09d92015 7262
c19d1205
ZW
7263 /* Check that we have parsed all the arguments. */
7264 if (*str != '\0' && !inst.error)
7265 inst.error = _("garbage following instruction");
09d92015 7266
c19d1205 7267 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7268}
7269
c19d1205
ZW
7270#undef po_char_or_fail
7271#undef po_reg_or_fail
7272#undef po_reg_or_goto
7273#undef po_imm_or_fail
5287ad62 7274#undef po_scalar_or_fail
52e7f43d 7275#undef po_barrier_or_imm
e07e6e58 7276
c19d1205 7277/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7278#define constraint(expr, err) \
7279 do \
c19d1205 7280 { \
e07e6e58
NC
7281 if (expr) \
7282 { \
7283 inst.error = err; \
7284 return; \
7285 } \
c19d1205 7286 } \
e07e6e58 7287 while (0)
c19d1205 7288
fdfde340
JM
7289/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7290 instructions are unpredictable if these registers are used. This
7291 is the BadReg predicate in ARM's Thumb-2 documentation. */
7292#define reject_bad_reg(reg) \
7293 do \
7294 if (reg == REG_SP || reg == REG_PC) \
7295 { \
7296 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7297 return; \
7298 } \
7299 while (0)
7300
94206790
MM
7301/* If REG is R13 (the stack pointer), warn that its use is
7302 deprecated. */
7303#define warn_deprecated_sp(reg) \
7304 do \
7305 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7306 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7307 while (0)
7308
c19d1205
ZW
7309/* Functions for operand encoding. ARM, then Thumb. */
7310
d840c081 7311#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7312
9db2f6b4
RL
7313/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7314
7315 The only binary encoding difference is the Coprocessor number. Coprocessor
7316 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7317 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7318 exists for Single-Precision operation. */
7319
7320static void
7321do_scalar_fp16_v82_encode (void)
7322{
7323 if (inst.cond != COND_ALWAYS)
7324 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7325 " the behaviour is UNPREDICTABLE"));
7326 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7327 _(BAD_FP16));
7328
7329 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7330 mark_feature_used (&arm_ext_fp16);
7331}
7332
c19d1205
ZW
7333/* If VAL can be encoded in the immediate field of an ARM instruction,
7334 return the encoded form. Otherwise, return FAIL. */
7335
7336static unsigned int
7337encode_arm_immediate (unsigned int val)
09d92015 7338{
c19d1205
ZW
7339 unsigned int a, i;
7340
4f1d6205
L
7341 if (val <= 0xff)
7342 return val;
7343
7344 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7345 if ((a = rotate_left (val, i)) <= 0xff)
7346 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7347
7348 return FAIL;
09d92015
MM
7349}
7350
c19d1205
ZW
7351/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7352 return the encoded form. Otherwise, return FAIL. */
7353static unsigned int
7354encode_thumb32_immediate (unsigned int val)
09d92015 7355{
c19d1205 7356 unsigned int a, i;
09d92015 7357
9c3c69f2 7358 if (val <= 0xff)
c19d1205 7359 return val;
a737bd4d 7360
9c3c69f2 7361 for (i = 1; i <= 24; i++)
09d92015 7362 {
9c3c69f2
PB
7363 a = val >> i;
7364 if ((val & ~(0xff << i)) == 0)
7365 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7366 }
a737bd4d 7367
c19d1205
ZW
7368 a = val & 0xff;
7369 if (val == ((a << 16) | a))
7370 return 0x100 | a;
7371 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7372 return 0x300 | a;
09d92015 7373
c19d1205
ZW
7374 a = val & 0xff00;
7375 if (val == ((a << 16) | a))
7376 return 0x200 | (a >> 8);
a737bd4d 7377
c19d1205 7378 return FAIL;
09d92015 7379}
5287ad62 7380/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7381
7382static void
5287ad62
JB
7383encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7384{
7385 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7386 && reg > 15)
7387 {
b1cc4aeb 7388 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7389 {
7390 if (thumb_mode)
7391 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7392 fpu_vfp_ext_d32);
7393 else
7394 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7395 fpu_vfp_ext_d32);
7396 }
5287ad62 7397 else
477330fc
RM
7398 {
7399 first_error (_("D register out of range for selected VFP version"));
7400 return;
7401 }
5287ad62
JB
7402 }
7403
c19d1205 7404 switch (pos)
09d92015 7405 {
c19d1205
ZW
7406 case VFP_REG_Sd:
7407 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7408 break;
7409
7410 case VFP_REG_Sn:
7411 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7412 break;
7413
7414 case VFP_REG_Sm:
7415 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7416 break;
7417
5287ad62
JB
7418 case VFP_REG_Dd:
7419 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7420 break;
5f4273c7 7421
5287ad62
JB
7422 case VFP_REG_Dn:
7423 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7424 break;
5f4273c7 7425
5287ad62
JB
7426 case VFP_REG_Dm:
7427 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7428 break;
7429
c19d1205
ZW
7430 default:
7431 abort ();
09d92015 7432 }
09d92015
MM
7433}
7434
c19d1205 7435/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7436 if any, is handled by md_apply_fix. */
09d92015 7437static void
c19d1205 7438encode_arm_shift (int i)
09d92015 7439{
008a97ef
RL
7440 /* register-shifted register. */
7441 if (inst.operands[i].immisreg)
7442 {
bf355b69
MR
7443 int op_index;
7444 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7445 {
5689c942
RL
7446 /* Check the operand only when it's presented. In pre-UAL syntax,
7447 if the destination register is the same as the first operand, two
7448 register form of the instruction can be used. */
bf355b69
MR
7449 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7450 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7451 as_warn (UNPRED_REG ("r15"));
7452 }
7453
7454 if (inst.operands[i].imm == REG_PC)
7455 as_warn (UNPRED_REG ("r15"));
7456 }
7457
c19d1205
ZW
7458 if (inst.operands[i].shift_kind == SHIFT_RRX)
7459 inst.instruction |= SHIFT_ROR << 5;
7460 else
09d92015 7461 {
c19d1205
ZW
7462 inst.instruction |= inst.operands[i].shift_kind << 5;
7463 if (inst.operands[i].immisreg)
7464 {
7465 inst.instruction |= SHIFT_BY_REG;
7466 inst.instruction |= inst.operands[i].imm << 8;
7467 }
7468 else
7469 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7470 }
c19d1205 7471}
09d92015 7472
c19d1205
ZW
7473static void
7474encode_arm_shifter_operand (int i)
7475{
7476 if (inst.operands[i].isreg)
09d92015 7477 {
c19d1205
ZW
7478 inst.instruction |= inst.operands[i].reg;
7479 encode_arm_shift (i);
09d92015 7480 }
c19d1205 7481 else
a415b1cd
JB
7482 {
7483 inst.instruction |= INST_IMMEDIATE;
7484 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7485 inst.instruction |= inst.operands[i].imm;
7486 }
09d92015
MM
7487}
7488
c19d1205 7489/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7490static void
c19d1205 7491encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7492{
2b2f5df9
NC
7493 /* PR 14260:
7494 Generate an error if the operand is not a register. */
7495 constraint (!inst.operands[i].isreg,
7496 _("Instruction does not support =N addresses"));
7497
c19d1205 7498 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7499
c19d1205 7500 if (inst.operands[i].preind)
09d92015 7501 {
c19d1205
ZW
7502 if (is_t)
7503 {
7504 inst.error = _("instruction does not accept preindexed addressing");
7505 return;
7506 }
7507 inst.instruction |= PRE_INDEX;
7508 if (inst.operands[i].writeback)
7509 inst.instruction |= WRITE_BACK;
09d92015 7510
c19d1205
ZW
7511 }
7512 else if (inst.operands[i].postind)
7513 {
9c2799c2 7514 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7515 if (is_t)
7516 inst.instruction |= WRITE_BACK;
7517 }
7518 else /* unindexed - only for coprocessor */
09d92015 7519 {
c19d1205 7520 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7521 return;
7522 }
7523
c19d1205
ZW
7524 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7525 && (((inst.instruction & 0x000f0000) >> 16)
7526 == ((inst.instruction & 0x0000f000) >> 12)))
7527 as_warn ((inst.instruction & LOAD_BIT)
7528 ? _("destination register same as write-back base")
7529 : _("source register same as write-back base"));
09d92015
MM
7530}
7531
c19d1205
ZW
7532/* inst.operands[i] was set up by parse_address. Encode it into an
7533 ARM-format mode 2 load or store instruction. If is_t is true,
7534 reject forms that cannot be used with a T instruction (i.e. not
7535 post-indexed). */
a737bd4d 7536static void
c19d1205 7537encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7538{
5be8be5d
DG
7539 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7540
c19d1205 7541 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7542
c19d1205 7543 if (inst.operands[i].immisreg)
09d92015 7544 {
5be8be5d
DG
7545 constraint ((inst.operands[i].imm == REG_PC
7546 || (is_pc && inst.operands[i].writeback)),
7547 BAD_PC_ADDRESSING);
c19d1205
ZW
7548 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7549 inst.instruction |= inst.operands[i].imm;
7550 if (!inst.operands[i].negative)
7551 inst.instruction |= INDEX_UP;
7552 if (inst.operands[i].shifted)
7553 {
7554 if (inst.operands[i].shift_kind == SHIFT_RRX)
7555 inst.instruction |= SHIFT_ROR << 5;
7556 else
7557 {
7558 inst.instruction |= inst.operands[i].shift_kind << 5;
7559 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7560 }
7561 }
09d92015 7562 }
c19d1205 7563 else /* immediate offset in inst.reloc */
09d92015 7564 {
5be8be5d
DG
7565 if (is_pc && !inst.reloc.pc_rel)
7566 {
7567 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7568
7569 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7570 cannot use PC in addressing.
7571 PC cannot be used in writeback addressing, either. */
7572 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7573 BAD_PC_ADDRESSING);
23a10334 7574
dc5ec521 7575 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7576 if (warn_on_deprecated
7577 && !is_load
7578 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7579 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7580 }
7581
c19d1205 7582 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7583 {
7584 /* Prefer + for zero encoded value. */
7585 if (!inst.operands[i].negative)
7586 inst.instruction |= INDEX_UP;
7587 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7588 }
09d92015 7589 }
09d92015
MM
7590}
7591
c19d1205
ZW
7592/* inst.operands[i] was set up by parse_address. Encode it into an
7593 ARM-format mode 3 load or store instruction. Reject forms that
7594 cannot be used with such instructions. If is_t is true, reject
7595 forms that cannot be used with a T instruction (i.e. not
7596 post-indexed). */
7597static void
7598encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7599{
c19d1205 7600 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7601 {
c19d1205
ZW
7602 inst.error = _("instruction does not accept scaled register index");
7603 return;
09d92015 7604 }
a737bd4d 7605
c19d1205 7606 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7607
c19d1205
ZW
7608 if (inst.operands[i].immisreg)
7609 {
5be8be5d 7610 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7611 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7612 BAD_PC_ADDRESSING);
eb9f3f00
JB
7613 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7614 BAD_PC_WRITEBACK);
c19d1205
ZW
7615 inst.instruction |= inst.operands[i].imm;
7616 if (!inst.operands[i].negative)
7617 inst.instruction |= INDEX_UP;
7618 }
7619 else /* immediate offset in inst.reloc */
7620 {
5be8be5d
DG
7621 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7622 && inst.operands[i].writeback),
7623 BAD_PC_WRITEBACK);
c19d1205
ZW
7624 inst.instruction |= HWOFFSET_IMM;
7625 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7626 {
7627 /* Prefer + for zero encoded value. */
7628 if (!inst.operands[i].negative)
7629 inst.instruction |= INDEX_UP;
7630
7631 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7632 }
c19d1205 7633 }
a737bd4d
NC
7634}
7635
8335d6aa
JW
7636/* Write immediate bits [7:0] to the following locations:
7637
7638 |28/24|23 19|18 16|15 4|3 0|
7639 | a |x x x x x|b c d|x x x x x x x x x x x x|e f g h|
7640
7641 This function is used by VMOV/VMVN/VORR/VBIC. */
7642
7643static void
7644neon_write_immbits (unsigned immbits)
7645{
7646 inst.instruction |= immbits & 0xf;
7647 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7648 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7649}
7650
7651/* Invert low-order SIZE bits of XHI:XLO. */
7652
7653static void
7654neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7655{
7656 unsigned immlo = xlo ? *xlo : 0;
7657 unsigned immhi = xhi ? *xhi : 0;
7658
7659 switch (size)
7660 {
7661 case 8:
7662 immlo = (~immlo) & 0xff;
7663 break;
7664
7665 case 16:
7666 immlo = (~immlo) & 0xffff;
7667 break;
7668
7669 case 64:
7670 immhi = (~immhi) & 0xffffffff;
7671 /* fall through. */
7672
7673 case 32:
7674 immlo = (~immlo) & 0xffffffff;
7675 break;
7676
7677 default:
7678 abort ();
7679 }
7680
7681 if (xlo)
7682 *xlo = immlo;
7683
7684 if (xhi)
7685 *xhi = immhi;
7686}
7687
7688/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7689 A, B, C, D. */
09d92015 7690
c19d1205 7691static int
8335d6aa 7692neon_bits_same_in_bytes (unsigned imm)
09d92015 7693{
8335d6aa
JW
7694 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7695 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7696 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7697 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7698}
a737bd4d 7699
8335d6aa 7700/* For immediate of above form, return 0bABCD. */
09d92015 7701
8335d6aa
JW
7702static unsigned
7703neon_squash_bits (unsigned imm)
7704{
7705 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7706 | ((imm & 0x01000000) >> 21);
7707}
7708
7709/* Compress quarter-float representation to 0b...000 abcdefgh. */
7710
7711static unsigned
7712neon_qfloat_bits (unsigned imm)
7713{
7714 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7715}
7716
7717/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7718 the instruction. *OP is passed as the initial value of the op field, and
7719 may be set to a different value depending on the constant (i.e.
7720 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7721 MVN). If the immediate looks like a repeated pattern then also
7722 try smaller element sizes. */
7723
7724static int
7725neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7726 unsigned *immbits, int *op, int size,
7727 enum neon_el_type type)
7728{
7729 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7730 float. */
7731 if (type == NT_float && !float_p)
7732 return FAIL;
7733
7734 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7735 {
8335d6aa
JW
7736 if (size != 32 || *op == 1)
7737 return FAIL;
7738 *immbits = neon_qfloat_bits (immlo);
7739 return 0xf;
7740 }
7741
7742 if (size == 64)
7743 {
7744 if (neon_bits_same_in_bytes (immhi)
7745 && neon_bits_same_in_bytes (immlo))
c19d1205 7746 {
8335d6aa
JW
7747 if (*op == 1)
7748 return FAIL;
7749 *immbits = (neon_squash_bits (immhi) << 4)
7750 | neon_squash_bits (immlo);
7751 *op = 1;
7752 return 0xe;
c19d1205 7753 }
a737bd4d 7754
8335d6aa
JW
7755 if (immhi != immlo)
7756 return FAIL;
7757 }
a737bd4d 7758
8335d6aa 7759 if (size >= 32)
09d92015 7760 {
8335d6aa 7761 if (immlo == (immlo & 0x000000ff))
c19d1205 7762 {
8335d6aa
JW
7763 *immbits = immlo;
7764 return 0x0;
c19d1205 7765 }
8335d6aa 7766 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7767 {
8335d6aa
JW
7768 *immbits = immlo >> 8;
7769 return 0x2;
c19d1205 7770 }
8335d6aa
JW
7771 else if (immlo == (immlo & 0x00ff0000))
7772 {
7773 *immbits = immlo >> 16;
7774 return 0x4;
7775 }
7776 else if (immlo == (immlo & 0xff000000))
7777 {
7778 *immbits = immlo >> 24;
7779 return 0x6;
7780 }
7781 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7782 {
7783 *immbits = (immlo >> 8) & 0xff;
7784 return 0xc;
7785 }
7786 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7787 {
7788 *immbits = (immlo >> 16) & 0xff;
7789 return 0xd;
7790 }
7791
7792 if ((immlo & 0xffff) != (immlo >> 16))
7793 return FAIL;
7794 immlo &= 0xffff;
09d92015 7795 }
a737bd4d 7796
8335d6aa 7797 if (size >= 16)
4962c51a 7798 {
8335d6aa
JW
7799 if (immlo == (immlo & 0x000000ff))
7800 {
7801 *immbits = immlo;
7802 return 0x8;
7803 }
7804 else if (immlo == (immlo & 0x0000ff00))
7805 {
7806 *immbits = immlo >> 8;
7807 return 0xa;
7808 }
7809
7810 if ((immlo & 0xff) != (immlo >> 8))
7811 return FAIL;
7812 immlo &= 0xff;
4962c51a
MS
7813 }
7814
8335d6aa
JW
7815 if (immlo == (immlo & 0x000000ff))
7816 {
7817 /* Don't allow MVN with 8-bit immediate. */
7818 if (*op == 1)
7819 return FAIL;
7820 *immbits = immlo;
7821 return 0xe;
7822 }
26d97720 7823
8335d6aa 7824 return FAIL;
c19d1205 7825}
a737bd4d 7826
5fc177c8 7827#if defined BFD_HOST_64_BIT
ba592044
AM
7828/* Returns TRUE if double precision value V may be cast
7829 to single precision without loss of accuracy. */
7830
7831static bfd_boolean
5fc177c8 7832is_double_a_single (bfd_int64_t v)
ba592044 7833{
5fc177c8 7834 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7835 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7836
7837 return (exp == 0 || exp == 0x7FF
7838 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7839 && (mantissa & 0x1FFFFFFFl) == 0;
7840}
7841
3739860c 7842/* Returns a double precision value casted to single precision
ba592044
AM
7843 (ignoring the least significant bits in exponent and mantissa). */
7844
7845static int
5fc177c8 7846double_to_single (bfd_int64_t v)
ba592044
AM
7847{
7848 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7849 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7850 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7851
7852 if (exp == 0x7FF)
7853 exp = 0xFF;
7854 else
7855 {
7856 exp = exp - 1023 + 127;
7857 if (exp >= 0xFF)
7858 {
7859 /* Infinity. */
7860 exp = 0x7F;
7861 mantissa = 0;
7862 }
7863 else if (exp < 0)
7864 {
7865 /* No denormalized numbers. */
7866 exp = 0;
7867 mantissa = 0;
7868 }
7869 }
7870 mantissa >>= 29;
7871 return (sign << 31) | (exp << 23) | mantissa;
7872}
5fc177c8 7873#endif /* BFD_HOST_64_BIT */
ba592044 7874
8335d6aa
JW
7875enum lit_type
7876{
7877 CONST_THUMB,
7878 CONST_ARM,
7879 CONST_VEC
7880};
7881
ba592044
AM
7882static void do_vfp_nsyn_opcode (const char *);
7883
c19d1205
ZW
7884/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7885 Determine whether it can be performed with a move instruction; if
7886 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7887 return TRUE; if it can't, convert inst.instruction to a literal-pool
7888 load and return FALSE. If this is not a valid thing to do in the
7889 current context, set inst.error and return TRUE.
a737bd4d 7890
c19d1205
ZW
7891 inst.operands[i] describes the destination register. */
7892
c921be7d 7893static bfd_boolean
8335d6aa 7894move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7895{
53365c0d 7896 unsigned long tbit;
8335d6aa
JW
7897 bfd_boolean thumb_p = (t == CONST_THUMB);
7898 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7899
7900 if (thumb_p)
7901 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7902 else
7903 tbit = LOAD_BIT;
7904
7905 if ((inst.instruction & tbit) == 0)
09d92015 7906 {
c19d1205 7907 inst.error = _("invalid pseudo operation");
c921be7d 7908 return TRUE;
09d92015 7909 }
ba592044 7910
8335d6aa
JW
7911 if (inst.reloc.exp.X_op != O_constant
7912 && inst.reloc.exp.X_op != O_symbol
7913 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7914 {
7915 inst.error = _("constant expression expected");
c921be7d 7916 return TRUE;
09d92015 7917 }
ba592044
AM
7918
7919 if (inst.reloc.exp.X_op == O_constant
7920 || inst.reloc.exp.X_op == O_big)
8335d6aa 7921 {
5fc177c8
NC
7922#if defined BFD_HOST_64_BIT
7923 bfd_int64_t v;
7924#else
ba592044 7925 offsetT v;
5fc177c8 7926#endif
ba592044 7927 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7928 {
ba592044
AM
7929 LITTLENUM_TYPE w[X_PRECISION];
7930 LITTLENUM_TYPE * l;
7931
7932 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7933 {
ba592044
AM
7934 gen_to_words (w, X_PRECISION, E_PRECISION);
7935 l = w;
7936 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7937 }
ba592044
AM
7938 else
7939 l = generic_bignum;
3739860c 7940
5fc177c8
NC
7941#if defined BFD_HOST_64_BIT
7942 v =
7943 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7944 << LITTLENUM_NUMBER_OF_BITS)
7945 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7946 << LITTLENUM_NUMBER_OF_BITS)
7947 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7948 << LITTLENUM_NUMBER_OF_BITS)
7949 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7950#else
ba592044
AM
7951 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7952 | (l[0] & LITTLENUM_MASK);
5fc177c8 7953#endif
8335d6aa 7954 }
ba592044
AM
7955 else
7956 v = inst.reloc.exp.X_add_number;
7957
7958 if (!inst.operands[i].issingle)
8335d6aa 7959 {
12569877 7960 if (thumb_p)
8335d6aa 7961 {
53445554
TP
7962 /* LDR should not use lead in a flag-setting instruction being
7963 chosen so we do not check whether movs can be used. */
12569877 7964
53445554 7965 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 7966 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
7967 && inst.operands[i].reg != 13
7968 && inst.operands[i].reg != 15)
12569877 7969 {
fc289b0a
TP
7970 /* Check if on thumb2 it can be done with a mov.w, mvn or
7971 movw instruction. */
12569877
AM
7972 unsigned int newimm;
7973 bfd_boolean isNegated;
7974
7975 newimm = encode_thumb32_immediate (v);
7976 if (newimm != (unsigned int) FAIL)
7977 isNegated = FALSE;
7978 else
7979 {
582cfe03 7980 newimm = encode_thumb32_immediate (~v);
12569877
AM
7981 if (newimm != (unsigned int) FAIL)
7982 isNegated = TRUE;
7983 }
7984
fc289b0a
TP
7985 /* The number can be loaded with a mov.w or mvn
7986 instruction. */
ff8646ee
TP
7987 if (newimm != (unsigned int) FAIL
7988 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7989 {
fc289b0a 7990 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7991 | (inst.operands[i].reg << 8));
fc289b0a 7992 /* Change to MOVN. */
582cfe03 7993 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7994 inst.instruction |= (newimm & 0x800) << 15;
7995 inst.instruction |= (newimm & 0x700) << 4;
7996 inst.instruction |= (newimm & 0x0ff);
7997 return TRUE;
7998 }
fc289b0a 7999 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8000 else if ((v & ~0xFFFF) == 0
8001 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8002 {
582cfe03 8003 int imm = v & 0xFFFF;
12569877 8004
582cfe03 8005 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8006 inst.instruction |= (inst.operands[i].reg << 8);
8007 inst.instruction |= (imm & 0xf000) << 4;
8008 inst.instruction |= (imm & 0x0800) << 15;
8009 inst.instruction |= (imm & 0x0700) << 4;
8010 inst.instruction |= (imm & 0x00ff);
8011 return TRUE;
8012 }
8013 }
8335d6aa 8014 }
12569877 8015 else if (arm_p)
ba592044
AM
8016 {
8017 int value = encode_arm_immediate (v);
12569877 8018
ba592044
AM
8019 if (value != FAIL)
8020 {
8021 /* This can be done with a mov instruction. */
8022 inst.instruction &= LITERAL_MASK;
8023 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8024 inst.instruction |= value & 0xfff;
8025 return TRUE;
8026 }
8335d6aa 8027
ba592044
AM
8028 value = encode_arm_immediate (~ v);
8029 if (value != FAIL)
8030 {
8031 /* This can be done with a mvn instruction. */
8032 inst.instruction &= LITERAL_MASK;
8033 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8034 inst.instruction |= value & 0xfff;
8035 return TRUE;
8036 }
8037 }
934c2632 8038 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8039 {
ba592044
AM
8040 int op = 0;
8041 unsigned immbits = 0;
8042 unsigned immlo = inst.operands[1].imm;
8043 unsigned immhi = inst.operands[1].regisimm
8044 ? inst.operands[1].reg
8045 : inst.reloc.exp.X_unsigned
8046 ? 0
8047 : ((bfd_int64_t)((int) immlo)) >> 32;
8048 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8049 &op, 64, NT_invtype);
8050
8051 if (cmode == FAIL)
8052 {
8053 neon_invert_size (&immlo, &immhi, 64);
8054 op = !op;
8055 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8056 &op, 64, NT_invtype);
8057 }
8058
8059 if (cmode != FAIL)
8060 {
8061 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8062 | (1 << 23)
8063 | (cmode << 8)
8064 | (op << 5)
8065 | (1 << 4);
8066
8067 /* Fill other bits in vmov encoding for both thumb and arm. */
8068 if (thumb_mode)
eff0bc54 8069 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8070 else
eff0bc54 8071 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8072 neon_write_immbits (immbits);
8073 return TRUE;
8074 }
8335d6aa
JW
8075 }
8076 }
8335d6aa 8077
ba592044
AM
8078 if (t == CONST_VEC)
8079 {
8080 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8081 if (inst.operands[i].issingle
8082 && is_quarter_float (inst.operands[1].imm)
8083 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8084 {
ba592044
AM
8085 inst.operands[1].imm =
8086 neon_qfloat_bits (v);
8087 do_vfp_nsyn_opcode ("fconsts");
8088 return TRUE;
8335d6aa 8089 }
5fc177c8
NC
8090
8091 /* If our host does not support a 64-bit type then we cannot perform
8092 the following optimization. This mean that there will be a
8093 discrepancy between the output produced by an assembler built for
8094 a 32-bit-only host and the output produced from a 64-bit host, but
8095 this cannot be helped. */
8096#if defined BFD_HOST_64_BIT
ba592044
AM
8097 else if (!inst.operands[1].issingle
8098 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8099 {
ba592044
AM
8100 if (is_double_a_single (v)
8101 && is_quarter_float (double_to_single (v)))
8102 {
8103 inst.operands[1].imm =
8104 neon_qfloat_bits (double_to_single (v));
8105 do_vfp_nsyn_opcode ("fconstd");
8106 return TRUE;
8107 }
8335d6aa 8108 }
5fc177c8 8109#endif
8335d6aa
JW
8110 }
8111 }
8112
8113 if (add_to_lit_pool ((!inst.operands[i].isvec
8114 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8115 return TRUE;
8116
8117 inst.operands[1].reg = REG_PC;
8118 inst.operands[1].isreg = 1;
8119 inst.operands[1].preind = 1;
8120 inst.reloc.pc_rel = 1;
8121 inst.reloc.type = (thumb_p
8122 ? BFD_RELOC_ARM_THUMB_OFFSET
8123 : (mode_3
8124 ? BFD_RELOC_ARM_HWLITERAL
8125 : BFD_RELOC_ARM_LITERAL));
8126 return FALSE;
8127}
8128
8129/* inst.operands[i] was set up by parse_address. Encode it into an
8130 ARM-format instruction. Reject all forms which cannot be encoded
8131 into a coprocessor load/store instruction. If wb_ok is false,
8132 reject use of writeback; if unind_ok is false, reject use of
8133 unindexed addressing. If reloc_override is not 0, use it instead
8134 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8135 (in which case it is preserved). */
8136
8137static int
8138encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8139{
8140 if (!inst.operands[i].isreg)
8141 {
99b2a2dd
NC
8142 /* PR 18256 */
8143 if (! inst.operands[0].isvec)
8144 {
8145 inst.error = _("invalid co-processor operand");
8146 return FAIL;
8147 }
8335d6aa
JW
8148 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8149 return SUCCESS;
8150 }
8151
8152 inst.instruction |= inst.operands[i].reg << 16;
8153
8154 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8155
8156 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8157 {
8158 gas_assert (!inst.operands[i].writeback);
8159 if (!unind_ok)
8160 {
8161 inst.error = _("instruction does not support unindexed addressing");
8162 return FAIL;
8163 }
8164 inst.instruction |= inst.operands[i].imm;
8165 inst.instruction |= INDEX_UP;
8166 return SUCCESS;
8167 }
8168
8169 if (inst.operands[i].preind)
8170 inst.instruction |= PRE_INDEX;
8171
8172 if (inst.operands[i].writeback)
09d92015 8173 {
8335d6aa 8174 if (inst.operands[i].reg == REG_PC)
c19d1205 8175 {
8335d6aa
JW
8176 inst.error = _("pc may not be used with write-back");
8177 return FAIL;
c19d1205 8178 }
8335d6aa 8179 if (!wb_ok)
c19d1205 8180 {
8335d6aa
JW
8181 inst.error = _("instruction does not support writeback");
8182 return FAIL;
c19d1205 8183 }
8335d6aa 8184 inst.instruction |= WRITE_BACK;
09d92015
MM
8185 }
8186
8335d6aa
JW
8187 if (reloc_override)
8188 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8189 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8190 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8191 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8192 {
8335d6aa
JW
8193 if (thumb_mode)
8194 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8195 else
8196 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8197 }
8335d6aa
JW
8198
8199 /* Prefer + for zero encoded value. */
8200 if (!inst.operands[i].negative)
8201 inst.instruction |= INDEX_UP;
8202
8203 return SUCCESS;
09d92015
MM
8204}
8205
5f4273c7 8206/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8207 First some generics; their names are taken from the conventional
8208 bit positions for register arguments in ARM format instructions. */
09d92015 8209
a737bd4d 8210static void
c19d1205 8211do_noargs (void)
09d92015 8212{
c19d1205 8213}
a737bd4d 8214
c19d1205
ZW
8215static void
8216do_rd (void)
8217{
8218 inst.instruction |= inst.operands[0].reg << 12;
8219}
a737bd4d 8220
16a1fa25
TP
8221static void
8222do_rn (void)
8223{
8224 inst.instruction |= inst.operands[0].reg << 16;
8225}
8226
c19d1205
ZW
8227static void
8228do_rd_rm (void)
8229{
8230 inst.instruction |= inst.operands[0].reg << 12;
8231 inst.instruction |= inst.operands[1].reg;
8232}
09d92015 8233
9eb6c0f1
MGD
8234static void
8235do_rm_rn (void)
8236{
8237 inst.instruction |= inst.operands[0].reg;
8238 inst.instruction |= inst.operands[1].reg << 16;
8239}
8240
c19d1205
ZW
8241static void
8242do_rd_rn (void)
8243{
8244 inst.instruction |= inst.operands[0].reg << 12;
8245 inst.instruction |= inst.operands[1].reg << 16;
8246}
a737bd4d 8247
c19d1205
ZW
8248static void
8249do_rn_rd (void)
8250{
8251 inst.instruction |= inst.operands[0].reg << 16;
8252 inst.instruction |= inst.operands[1].reg << 12;
8253}
09d92015 8254
4ed7ed8d
TP
8255static void
8256do_tt (void)
8257{
8258 inst.instruction |= inst.operands[0].reg << 8;
8259 inst.instruction |= inst.operands[1].reg << 16;
8260}
8261
59d09be6
MGD
8262static bfd_boolean
8263check_obsolete (const arm_feature_set *feature, const char *msg)
8264{
8265 if (ARM_CPU_IS_ANY (cpu_variant))
8266 {
5c3696f8 8267 as_tsktsk ("%s", msg);
59d09be6
MGD
8268 return TRUE;
8269 }
8270 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8271 {
8272 as_bad ("%s", msg);
8273 return TRUE;
8274 }
8275
8276 return FALSE;
8277}
8278
c19d1205
ZW
8279static void
8280do_rd_rm_rn (void)
8281{
9a64e435 8282 unsigned Rn = inst.operands[2].reg;
708587a4 8283 /* Enforce restrictions on SWP instruction. */
9a64e435 8284 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8285 {
8286 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8287 _("Rn must not overlap other operands"));
8288
59d09be6
MGD
8289 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8290 */
8291 if (!check_obsolete (&arm_ext_v8,
8292 _("swp{b} use is obsoleted for ARMv8 and later"))
8293 && warn_on_deprecated
8294 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8295 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8296 }
59d09be6 8297
c19d1205
ZW
8298 inst.instruction |= inst.operands[0].reg << 12;
8299 inst.instruction |= inst.operands[1].reg;
9a64e435 8300 inst.instruction |= Rn << 16;
c19d1205 8301}
09d92015 8302
c19d1205
ZW
8303static void
8304do_rd_rn_rm (void)
8305{
8306 inst.instruction |= inst.operands[0].reg << 12;
8307 inst.instruction |= inst.operands[1].reg << 16;
8308 inst.instruction |= inst.operands[2].reg;
8309}
a737bd4d 8310
c19d1205
ZW
8311static void
8312do_rm_rd_rn (void)
8313{
5be8be5d
DG
8314 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8315 constraint (((inst.reloc.exp.X_op != O_constant
8316 && inst.reloc.exp.X_op != O_illegal)
8317 || inst.reloc.exp.X_add_number != 0),
8318 BAD_ADDR_MODE);
c19d1205
ZW
8319 inst.instruction |= inst.operands[0].reg;
8320 inst.instruction |= inst.operands[1].reg << 12;
8321 inst.instruction |= inst.operands[2].reg << 16;
8322}
09d92015 8323
c19d1205
ZW
8324static void
8325do_imm0 (void)
8326{
8327 inst.instruction |= inst.operands[0].imm;
8328}
09d92015 8329
c19d1205
ZW
8330static void
8331do_rd_cpaddr (void)
8332{
8333 inst.instruction |= inst.operands[0].reg << 12;
8334 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8335}
a737bd4d 8336
c19d1205
ZW
8337/* ARM instructions, in alphabetical order by function name (except
8338 that wrapper functions appear immediately after the function they
8339 wrap). */
09d92015 8340
c19d1205
ZW
8341/* This is a pseudo-op of the form "adr rd, label" to be converted
8342 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8343
8344static void
c19d1205 8345do_adr (void)
09d92015 8346{
c19d1205 8347 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8348
c19d1205
ZW
8349 /* Frag hacking will turn this into a sub instruction if the offset turns
8350 out to be negative. */
8351 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8352 inst.reloc.pc_rel = 1;
2fc8bdac 8353 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8354
8355 if (inst.reloc.exp.X_op == O_symbol
8356 && inst.reloc.exp.X_add_symbol != NULL
8357 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8358 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8359 inst.reloc.exp.X_add_number += 1;
c19d1205 8360}
b99bd4ef 8361
c19d1205
ZW
8362/* This is a pseudo-op of the form "adrl rd, label" to be converted
8363 into a relative address of the form:
8364 add rd, pc, #low(label-.-8)"
8365 add rd, rd, #high(label-.-8)" */
b99bd4ef 8366
c19d1205
ZW
8367static void
8368do_adrl (void)
8369{
8370 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8371
c19d1205
ZW
8372 /* Frag hacking will turn this into a sub instruction if the offset turns
8373 out to be negative. */
8374 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8375 inst.reloc.pc_rel = 1;
8376 inst.size = INSN_SIZE * 2;
2fc8bdac 8377 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8378
8379 if (inst.reloc.exp.X_op == O_symbol
8380 && inst.reloc.exp.X_add_symbol != NULL
8381 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8382 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8383 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8384}
8385
b99bd4ef 8386static void
c19d1205 8387do_arit (void)
b99bd4ef 8388{
a9f02af8
MG
8389 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8390 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8391 THUMB1_RELOC_ONLY);
c19d1205
ZW
8392 if (!inst.operands[1].present)
8393 inst.operands[1].reg = inst.operands[0].reg;
8394 inst.instruction |= inst.operands[0].reg << 12;
8395 inst.instruction |= inst.operands[1].reg << 16;
8396 encode_arm_shifter_operand (2);
8397}
b99bd4ef 8398
62b3e311
PB
8399static void
8400do_barrier (void)
8401{
8402 if (inst.operands[0].present)
ccb84d65 8403 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8404 else
8405 inst.instruction |= 0xf;
8406}
8407
c19d1205
ZW
8408static void
8409do_bfc (void)
8410{
8411 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8412 constraint (msb > 32, _("bit-field extends past end of register"));
8413 /* The instruction encoding stores the LSB and MSB,
8414 not the LSB and width. */
8415 inst.instruction |= inst.operands[0].reg << 12;
8416 inst.instruction |= inst.operands[1].imm << 7;
8417 inst.instruction |= (msb - 1) << 16;
8418}
b99bd4ef 8419
c19d1205
ZW
8420static void
8421do_bfi (void)
8422{
8423 unsigned int msb;
b99bd4ef 8424
c19d1205
ZW
8425 /* #0 in second position is alternative syntax for bfc, which is
8426 the same instruction but with REG_PC in the Rm field. */
8427 if (!inst.operands[1].isreg)
8428 inst.operands[1].reg = REG_PC;
b99bd4ef 8429
c19d1205
ZW
8430 msb = inst.operands[2].imm + inst.operands[3].imm;
8431 constraint (msb > 32, _("bit-field extends past end of register"));
8432 /* The instruction encoding stores the LSB and MSB,
8433 not the LSB and width. */
8434 inst.instruction |= inst.operands[0].reg << 12;
8435 inst.instruction |= inst.operands[1].reg;
8436 inst.instruction |= inst.operands[2].imm << 7;
8437 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8438}
8439
b99bd4ef 8440static void
c19d1205 8441do_bfx (void)
b99bd4ef 8442{
c19d1205
ZW
8443 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8444 _("bit-field extends past end of register"));
8445 inst.instruction |= inst.operands[0].reg << 12;
8446 inst.instruction |= inst.operands[1].reg;
8447 inst.instruction |= inst.operands[2].imm << 7;
8448 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8449}
09d92015 8450
c19d1205
ZW
8451/* ARM V5 breakpoint instruction (argument parse)
8452 BKPT <16 bit unsigned immediate>
8453 Instruction is not conditional.
8454 The bit pattern given in insns[] has the COND_ALWAYS condition,
8455 and it is an error if the caller tried to override that. */
b99bd4ef 8456
c19d1205
ZW
8457static void
8458do_bkpt (void)
8459{
8460 /* Top 12 of 16 bits to bits 19:8. */
8461 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8462
c19d1205
ZW
8463 /* Bottom 4 of 16 bits to bits 3:0. */
8464 inst.instruction |= inst.operands[0].imm & 0xf;
8465}
09d92015 8466
c19d1205
ZW
8467static void
8468encode_branch (int default_reloc)
8469{
8470 if (inst.operands[0].hasreloc)
8471 {
0855e32b
NS
8472 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8473 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8474 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8475 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8476 ? BFD_RELOC_ARM_PLT32
8477 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8478 }
b99bd4ef 8479 else
9ae92b05 8480 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8481 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8482}
8483
b99bd4ef 8484static void
c19d1205 8485do_branch (void)
b99bd4ef 8486{
39b41c9c
PB
8487#ifdef OBJ_ELF
8488 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8489 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8490 else
8491#endif
8492 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8493}
8494
8495static void
8496do_bl (void)
8497{
8498#ifdef OBJ_ELF
8499 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8500 {
8501 if (inst.cond == COND_ALWAYS)
8502 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8503 else
8504 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8505 }
8506 else
8507#endif
8508 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8509}
b99bd4ef 8510
c19d1205
ZW
8511/* ARM V5 branch-link-exchange instruction (argument parse)
8512 BLX <target_addr> ie BLX(1)
8513 BLX{<condition>} <Rm> ie BLX(2)
8514 Unfortunately, there are two different opcodes for this mnemonic.
8515 So, the insns[].value is not used, and the code here zaps values
8516 into inst.instruction.
8517 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8518
c19d1205
ZW
8519static void
8520do_blx (void)
8521{
8522 if (inst.operands[0].isreg)
b99bd4ef 8523 {
c19d1205
ZW
8524 /* Arg is a register; the opcode provided by insns[] is correct.
8525 It is not illegal to do "blx pc", just useless. */
8526 if (inst.operands[0].reg == REG_PC)
8527 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8528
c19d1205
ZW
8529 inst.instruction |= inst.operands[0].reg;
8530 }
8531 else
b99bd4ef 8532 {
c19d1205 8533 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8534 conditionally, and the opcode must be adjusted.
8535 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8536 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8537 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8538 inst.instruction = 0xfa000000;
267bf995 8539 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8540 }
c19d1205
ZW
8541}
8542
8543static void
8544do_bx (void)
8545{
845b51d6
PB
8546 bfd_boolean want_reloc;
8547
c19d1205
ZW
8548 if (inst.operands[0].reg == REG_PC)
8549 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8550
c19d1205 8551 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8552 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8553 it is for ARMv4t or earlier. */
8554 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8555 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8556 want_reloc = TRUE;
8557
5ad34203 8558#ifdef OBJ_ELF
845b51d6 8559 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8560#endif
584206db 8561 want_reloc = FALSE;
845b51d6
PB
8562
8563 if (want_reloc)
8564 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8565}
8566
c19d1205
ZW
8567
8568/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8569
8570static void
c19d1205 8571do_bxj (void)
a737bd4d 8572{
c19d1205
ZW
8573 if (inst.operands[0].reg == REG_PC)
8574 as_tsktsk (_("use of r15 in bxj is not really useful"));
8575
8576 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8577}
8578
c19d1205
ZW
8579/* Co-processor data operation:
8580 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8581 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8582static void
8583do_cdp (void)
8584{
8585 inst.instruction |= inst.operands[0].reg << 8;
8586 inst.instruction |= inst.operands[1].imm << 20;
8587 inst.instruction |= inst.operands[2].reg << 12;
8588 inst.instruction |= inst.operands[3].reg << 16;
8589 inst.instruction |= inst.operands[4].reg;
8590 inst.instruction |= inst.operands[5].imm << 5;
8591}
a737bd4d
NC
8592
8593static void
c19d1205 8594do_cmp (void)
a737bd4d 8595{
c19d1205
ZW
8596 inst.instruction |= inst.operands[0].reg << 16;
8597 encode_arm_shifter_operand (1);
a737bd4d
NC
8598}
8599
c19d1205
ZW
8600/* Transfer between coprocessor and ARM registers.
8601 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8602 MRC2
8603 MCR{cond}
8604 MCR2
8605
8606 No special properties. */
09d92015 8607
dcbd0d71
MGD
8608struct deprecated_coproc_regs_s
8609{
8610 unsigned cp;
8611 int opc1;
8612 unsigned crn;
8613 unsigned crm;
8614 int opc2;
8615 arm_feature_set deprecated;
8616 arm_feature_set obsoleted;
8617 const char *dep_msg;
8618 const char *obs_msg;
8619};
8620
8621#define DEPR_ACCESS_V8 \
8622 N_("This coprocessor register access is deprecated in ARMv8")
8623
8624/* Table of all deprecated coprocessor registers. */
8625static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8626{
8627 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8628 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8629 DEPR_ACCESS_V8, NULL},
8630 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8631 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8632 DEPR_ACCESS_V8, NULL},
8633 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8634 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8635 DEPR_ACCESS_V8, NULL},
8636 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8637 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8638 DEPR_ACCESS_V8, NULL},
8639 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8640 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8641 DEPR_ACCESS_V8, NULL},
8642};
8643
8644#undef DEPR_ACCESS_V8
8645
8646static const size_t deprecated_coproc_reg_count =
8647 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8648
09d92015 8649static void
c19d1205 8650do_co_reg (void)
09d92015 8651{
fdfde340 8652 unsigned Rd;
dcbd0d71 8653 size_t i;
fdfde340
JM
8654
8655 Rd = inst.operands[2].reg;
8656 if (thumb_mode)
8657 {
8658 if (inst.instruction == 0xee000010
8659 || inst.instruction == 0xfe000010)
8660 /* MCR, MCR2 */
8661 reject_bad_reg (Rd);
8662 else
8663 /* MRC, MRC2 */
8664 constraint (Rd == REG_SP, BAD_SP);
8665 }
8666 else
8667 {
8668 /* MCR */
8669 if (inst.instruction == 0xe000010)
8670 constraint (Rd == REG_PC, BAD_PC);
8671 }
8672
dcbd0d71
MGD
8673 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8674 {
8675 const struct deprecated_coproc_regs_s *r =
8676 deprecated_coproc_regs + i;
8677
8678 if (inst.operands[0].reg == r->cp
8679 && inst.operands[1].imm == r->opc1
8680 && inst.operands[3].reg == r->crn
8681 && inst.operands[4].reg == r->crm
8682 && inst.operands[5].imm == r->opc2)
8683 {
b10bf8c5 8684 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8685 && warn_on_deprecated
dcbd0d71 8686 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8687 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8688 }
8689 }
fdfde340 8690
c19d1205
ZW
8691 inst.instruction |= inst.operands[0].reg << 8;
8692 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8693 inst.instruction |= Rd << 12;
c19d1205
ZW
8694 inst.instruction |= inst.operands[3].reg << 16;
8695 inst.instruction |= inst.operands[4].reg;
8696 inst.instruction |= inst.operands[5].imm << 5;
8697}
09d92015 8698
c19d1205
ZW
8699/* Transfer between coprocessor register and pair of ARM registers.
8700 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8701 MCRR2
8702 MRRC{cond}
8703 MRRC2
b99bd4ef 8704
c19d1205 8705 Two XScale instructions are special cases of these:
09d92015 8706
c19d1205
ZW
8707 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8708 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8709
5f4273c7 8710 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8711
c19d1205
ZW
8712static void
8713do_co_reg2c (void)
8714{
fdfde340
JM
8715 unsigned Rd, Rn;
8716
8717 Rd = inst.operands[2].reg;
8718 Rn = inst.operands[3].reg;
8719
8720 if (thumb_mode)
8721 {
8722 reject_bad_reg (Rd);
8723 reject_bad_reg (Rn);
8724 }
8725 else
8726 {
8727 constraint (Rd == REG_PC, BAD_PC);
8728 constraint (Rn == REG_PC, BAD_PC);
8729 }
8730
873f10f0
TC
8731 /* Only check the MRRC{2} variants. */
8732 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8733 {
8734 /* If Rd == Rn, error that the operation is
8735 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8736 constraint (Rd == Rn, BAD_OVERLAP);
8737 }
8738
c19d1205
ZW
8739 inst.instruction |= inst.operands[0].reg << 8;
8740 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8741 inst.instruction |= Rd << 12;
8742 inst.instruction |= Rn << 16;
c19d1205 8743 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8744}
8745
c19d1205
ZW
8746static void
8747do_cpsi (void)
8748{
8749 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8750 if (inst.operands[1].present)
8751 {
8752 inst.instruction |= CPSI_MMOD;
8753 inst.instruction |= inst.operands[1].imm;
8754 }
c19d1205 8755}
b99bd4ef 8756
62b3e311
PB
8757static void
8758do_dbg (void)
8759{
8760 inst.instruction |= inst.operands[0].imm;
8761}
8762
eea54501
MGD
8763static void
8764do_div (void)
8765{
8766 unsigned Rd, Rn, Rm;
8767
8768 Rd = inst.operands[0].reg;
8769 Rn = (inst.operands[1].present
8770 ? inst.operands[1].reg : Rd);
8771 Rm = inst.operands[2].reg;
8772
8773 constraint ((Rd == REG_PC), BAD_PC);
8774 constraint ((Rn == REG_PC), BAD_PC);
8775 constraint ((Rm == REG_PC), BAD_PC);
8776
8777 inst.instruction |= Rd << 16;
8778 inst.instruction |= Rn << 0;
8779 inst.instruction |= Rm << 8;
8780}
8781
b99bd4ef 8782static void
c19d1205 8783do_it (void)
b99bd4ef 8784{
c19d1205 8785 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8786 process it to do the validation as if in
8787 thumb mode, just in case the code gets
8788 assembled for thumb using the unified syntax. */
8789
c19d1205 8790 inst.size = 0;
e07e6e58
NC
8791 if (unified_syntax)
8792 {
8793 set_it_insn_type (IT_INSN);
8794 now_it.mask = (inst.instruction & 0xf) | 0x10;
8795 now_it.cc = inst.operands[0].imm;
8796 }
09d92015 8797}
b99bd4ef 8798
6530b175
NC
8799/* If there is only one register in the register list,
8800 then return its register number. Otherwise return -1. */
8801static int
8802only_one_reg_in_list (int range)
8803{
8804 int i = ffs (range) - 1;
8805 return (i > 15 || range != (1 << i)) ? -1 : i;
8806}
8807
09d92015 8808static void
6530b175 8809encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8810{
c19d1205
ZW
8811 int base_reg = inst.operands[0].reg;
8812 int range = inst.operands[1].imm;
6530b175 8813 int one_reg;
ea6ef066 8814
c19d1205
ZW
8815 inst.instruction |= base_reg << 16;
8816 inst.instruction |= range;
ea6ef066 8817
c19d1205
ZW
8818 if (inst.operands[1].writeback)
8819 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8820
c19d1205 8821 if (inst.operands[0].writeback)
ea6ef066 8822 {
c19d1205
ZW
8823 inst.instruction |= WRITE_BACK;
8824 /* Check for unpredictable uses of writeback. */
8825 if (inst.instruction & LOAD_BIT)
09d92015 8826 {
c19d1205
ZW
8827 /* Not allowed in LDM type 2. */
8828 if ((inst.instruction & LDM_TYPE_2_OR_3)
8829 && ((range & (1 << REG_PC)) == 0))
8830 as_warn (_("writeback of base register is UNPREDICTABLE"));
8831 /* Only allowed if base reg not in list for other types. */
8832 else if (range & (1 << base_reg))
8833 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8834 }
8835 else /* STM. */
8836 {
8837 /* Not allowed for type 2. */
8838 if (inst.instruction & LDM_TYPE_2_OR_3)
8839 as_warn (_("writeback of base register is UNPREDICTABLE"));
8840 /* Only allowed if base reg not in list, or first in list. */
8841 else if ((range & (1 << base_reg))
8842 && (range & ((1 << base_reg) - 1)))
8843 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8844 }
ea6ef066 8845 }
6530b175
NC
8846
8847 /* If PUSH/POP has only one register, then use the A2 encoding. */
8848 one_reg = only_one_reg_in_list (range);
8849 if (from_push_pop_mnem && one_reg >= 0)
8850 {
8851 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8852
8853 inst.instruction &= A_COND_MASK;
8854 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8855 inst.instruction |= one_reg << 12;
8856 }
8857}
8858
8859static void
8860do_ldmstm (void)
8861{
8862 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8863}
8864
c19d1205
ZW
8865/* ARMv5TE load-consecutive (argument parse)
8866 Mode is like LDRH.
8867
8868 LDRccD R, mode
8869 STRccD R, mode. */
8870
a737bd4d 8871static void
c19d1205 8872do_ldrd (void)
a737bd4d 8873{
c19d1205 8874 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8875 _("first transfer register must be even"));
c19d1205
ZW
8876 constraint (inst.operands[1].present
8877 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8878 _("can only transfer two consecutive registers"));
c19d1205
ZW
8879 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8880 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8881
c19d1205
ZW
8882 if (!inst.operands[1].present)
8883 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8884
c56791bb
RE
8885 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8886 register and the first register written; we have to diagnose
8887 overlap between the base and the second register written here. */
ea6ef066 8888
c56791bb
RE
8889 if (inst.operands[2].reg == inst.operands[1].reg
8890 && (inst.operands[2].writeback || inst.operands[2].postind))
8891 as_warn (_("base register written back, and overlaps "
8892 "second transfer register"));
b05fe5cf 8893
c56791bb
RE
8894 if (!(inst.instruction & V4_STR_BIT))
8895 {
c19d1205 8896 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8897 destination (even if not write-back). */
8898 if (inst.operands[2].immisreg
8899 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8900 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8901 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8902 }
c19d1205
ZW
8903 inst.instruction |= inst.operands[0].reg << 12;
8904 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8905}
8906
8907static void
c19d1205 8908do_ldrex (void)
b05fe5cf 8909{
c19d1205
ZW
8910 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8911 || inst.operands[1].postind || inst.operands[1].writeback
8912 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8913 || inst.operands[1].negative
8914 /* This can arise if the programmer has written
8915 strex rN, rM, foo
8916 or if they have mistakenly used a register name as the last
8917 operand, eg:
8918 strex rN, rM, rX
8919 It is very difficult to distinguish between these two cases
8920 because "rX" might actually be a label. ie the register
8921 name has been occluded by a symbol of the same name. So we
8922 just generate a general 'bad addressing mode' type error
8923 message and leave it up to the programmer to discover the
8924 true cause and fix their mistake. */
8925 || (inst.operands[1].reg == REG_PC),
8926 BAD_ADDR_MODE);
b05fe5cf 8927
c19d1205
ZW
8928 constraint (inst.reloc.exp.X_op != O_constant
8929 || inst.reloc.exp.X_add_number != 0,
8930 _("offset must be zero in ARM encoding"));
b05fe5cf 8931
5be8be5d
DG
8932 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8933
c19d1205
ZW
8934 inst.instruction |= inst.operands[0].reg << 12;
8935 inst.instruction |= inst.operands[1].reg << 16;
8936 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8937}
8938
8939static void
c19d1205 8940do_ldrexd (void)
b05fe5cf 8941{
c19d1205
ZW
8942 constraint (inst.operands[0].reg % 2 != 0,
8943 _("even register required"));
8944 constraint (inst.operands[1].present
8945 && inst.operands[1].reg != inst.operands[0].reg + 1,
8946 _("can only load two consecutive registers"));
8947 /* If op 1 were present and equal to PC, this function wouldn't
8948 have been called in the first place. */
8949 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8950
c19d1205
ZW
8951 inst.instruction |= inst.operands[0].reg << 12;
8952 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8953}
8954
1be5fd2e
NC
8955/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8956 which is not a multiple of four is UNPREDICTABLE. */
8957static void
8958check_ldr_r15_aligned (void)
8959{
8960 constraint (!(inst.operands[1].immisreg)
8961 && (inst.operands[0].reg == REG_PC
8962 && inst.operands[1].reg == REG_PC
8963 && (inst.reloc.exp.X_add_number & 0x3)),
8964 _("ldr to register 15 must be 4-byte alligned"));
8965}
8966
b05fe5cf 8967static void
c19d1205 8968do_ldst (void)
b05fe5cf 8969{
c19d1205
ZW
8970 inst.instruction |= inst.operands[0].reg << 12;
8971 if (!inst.operands[1].isreg)
8335d6aa 8972 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8973 return;
c19d1205 8974 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8975 check_ldr_r15_aligned ();
b05fe5cf
ZW
8976}
8977
8978static void
c19d1205 8979do_ldstt (void)
b05fe5cf 8980{
c19d1205
ZW
8981 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8982 reject [Rn,...]. */
8983 if (inst.operands[1].preind)
b05fe5cf 8984 {
bd3ba5d1
NC
8985 constraint (inst.reloc.exp.X_op != O_constant
8986 || inst.reloc.exp.X_add_number != 0,
c19d1205 8987 _("this instruction requires a post-indexed address"));
b05fe5cf 8988
c19d1205
ZW
8989 inst.operands[1].preind = 0;
8990 inst.operands[1].postind = 1;
8991 inst.operands[1].writeback = 1;
b05fe5cf 8992 }
c19d1205
ZW
8993 inst.instruction |= inst.operands[0].reg << 12;
8994 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8995}
b05fe5cf 8996
c19d1205 8997/* Halfword and signed-byte load/store operations. */
b05fe5cf 8998
c19d1205
ZW
8999static void
9000do_ldstv4 (void)
9001{
ff4a8d2b 9002 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9003 inst.instruction |= inst.operands[0].reg << 12;
9004 if (!inst.operands[1].isreg)
8335d6aa 9005 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9006 return;
c19d1205 9007 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9008}
9009
9010static void
c19d1205 9011do_ldsttv4 (void)
b05fe5cf 9012{
c19d1205
ZW
9013 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9014 reject [Rn,...]. */
9015 if (inst.operands[1].preind)
b05fe5cf 9016 {
bd3ba5d1
NC
9017 constraint (inst.reloc.exp.X_op != O_constant
9018 || inst.reloc.exp.X_add_number != 0,
c19d1205 9019 _("this instruction requires a post-indexed address"));
b05fe5cf 9020
c19d1205
ZW
9021 inst.operands[1].preind = 0;
9022 inst.operands[1].postind = 1;
9023 inst.operands[1].writeback = 1;
b05fe5cf 9024 }
c19d1205
ZW
9025 inst.instruction |= inst.operands[0].reg << 12;
9026 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9027}
b05fe5cf 9028
c19d1205
ZW
9029/* Co-processor register load/store.
9030 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9031static void
9032do_lstc (void)
9033{
9034 inst.instruction |= inst.operands[0].reg << 8;
9035 inst.instruction |= inst.operands[1].reg << 12;
9036 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9037}
9038
b05fe5cf 9039static void
c19d1205 9040do_mlas (void)
b05fe5cf 9041{
8fb9d7b9 9042 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9043 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9044 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9045 && !(inst.instruction & 0x00400000))
8fb9d7b9 9046 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9047
c19d1205
ZW
9048 inst.instruction |= inst.operands[0].reg << 16;
9049 inst.instruction |= inst.operands[1].reg;
9050 inst.instruction |= inst.operands[2].reg << 8;
9051 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9052}
b05fe5cf 9053
c19d1205
ZW
9054static void
9055do_mov (void)
9056{
a9f02af8
MG
9057 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9058 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9059 THUMB1_RELOC_ONLY);
c19d1205
ZW
9060 inst.instruction |= inst.operands[0].reg << 12;
9061 encode_arm_shifter_operand (1);
9062}
b05fe5cf 9063
c19d1205
ZW
9064/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9065static void
9066do_mov16 (void)
9067{
b6895b4f
PB
9068 bfd_vma imm;
9069 bfd_boolean top;
9070
9071 top = (inst.instruction & 0x00400000) != 0;
9072 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9073 _(":lower16: not allowed in this instruction"));
b6895b4f 9074 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9075 _(":upper16: not allowed in this instruction"));
c19d1205 9076 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9077 if (inst.reloc.type == BFD_RELOC_UNUSED)
9078 {
9079 imm = inst.reloc.exp.X_add_number;
9080 /* The value is in two pieces: 0:11, 16:19. */
9081 inst.instruction |= (imm & 0x00000fff);
9082 inst.instruction |= (imm & 0x0000f000) << 4;
9083 }
b05fe5cf 9084}
b99bd4ef 9085
037e8744
JB
9086static int
9087do_vfp_nsyn_mrs (void)
9088{
9089 if (inst.operands[0].isvec)
9090 {
9091 if (inst.operands[1].reg != 1)
477330fc 9092 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9093 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9094 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9095 do_vfp_nsyn_opcode ("fmstat");
9096 }
9097 else if (inst.operands[1].isvec)
9098 do_vfp_nsyn_opcode ("fmrx");
9099 else
9100 return FAIL;
5f4273c7 9101
037e8744
JB
9102 return SUCCESS;
9103}
9104
9105static int
9106do_vfp_nsyn_msr (void)
9107{
9108 if (inst.operands[0].isvec)
9109 do_vfp_nsyn_opcode ("fmxr");
9110 else
9111 return FAIL;
9112
9113 return SUCCESS;
9114}
9115
f7c21dc7
NC
9116static void
9117do_vmrs (void)
9118{
9119 unsigned Rt = inst.operands[0].reg;
fa94de6b 9120
16d02dc9 9121 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9122 {
9123 inst.error = BAD_SP;
9124 return;
9125 }
9126
9127 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9128 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9129 {
9130 inst.error = BAD_PC;
9131 return;
9132 }
9133
16d02dc9
JB
9134 /* If we get through parsing the register name, we just insert the number
9135 generated into the instruction without further validation. */
9136 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9137 inst.instruction |= (Rt << 12);
9138}
9139
9140static void
9141do_vmsr (void)
9142{
9143 unsigned Rt = inst.operands[1].reg;
fa94de6b 9144
f7c21dc7
NC
9145 if (thumb_mode)
9146 reject_bad_reg (Rt);
9147 else if (Rt == REG_PC)
9148 {
9149 inst.error = BAD_PC;
9150 return;
9151 }
9152
16d02dc9
JB
9153 /* If we get through parsing the register name, we just insert the number
9154 generated into the instruction without further validation. */
9155 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9156 inst.instruction |= (Rt << 12);
9157}
9158
b99bd4ef 9159static void
c19d1205 9160do_mrs (void)
b99bd4ef 9161{
90ec0d68
MGD
9162 unsigned br;
9163
037e8744
JB
9164 if (do_vfp_nsyn_mrs () == SUCCESS)
9165 return;
9166
ff4a8d2b 9167 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9168 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9169
9170 if (inst.operands[1].isreg)
9171 {
9172 br = inst.operands[1].reg;
9173 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9174 as_bad (_("bad register for mrs"));
9175 }
9176 else
9177 {
9178 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9179 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9180 != (PSR_c|PSR_f),
d2cd1205 9181 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9182 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9183 }
9184
9185 inst.instruction |= br;
c19d1205 9186}
b99bd4ef 9187
c19d1205
ZW
9188/* Two possible forms:
9189 "{C|S}PSR_<field>, Rm",
9190 "{C|S}PSR_f, #expression". */
b99bd4ef 9191
c19d1205
ZW
9192static void
9193do_msr (void)
9194{
037e8744
JB
9195 if (do_vfp_nsyn_msr () == SUCCESS)
9196 return;
9197
c19d1205
ZW
9198 inst.instruction |= inst.operands[0].imm;
9199 if (inst.operands[1].isreg)
9200 inst.instruction |= inst.operands[1].reg;
9201 else
b99bd4ef 9202 {
c19d1205
ZW
9203 inst.instruction |= INST_IMMEDIATE;
9204 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9205 inst.reloc.pc_rel = 0;
b99bd4ef 9206 }
b99bd4ef
NC
9207}
9208
c19d1205
ZW
9209static void
9210do_mul (void)
a737bd4d 9211{
ff4a8d2b
NC
9212 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9213
c19d1205
ZW
9214 if (!inst.operands[2].present)
9215 inst.operands[2].reg = inst.operands[0].reg;
9216 inst.instruction |= inst.operands[0].reg << 16;
9217 inst.instruction |= inst.operands[1].reg;
9218 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9219
8fb9d7b9
MS
9220 if (inst.operands[0].reg == inst.operands[1].reg
9221 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9222 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9223}
9224
c19d1205
ZW
9225/* Long Multiply Parser
9226 UMULL RdLo, RdHi, Rm, Rs
9227 SMULL RdLo, RdHi, Rm, Rs
9228 UMLAL RdLo, RdHi, Rm, Rs
9229 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9230
9231static void
c19d1205 9232do_mull (void)
b99bd4ef 9233{
c19d1205
ZW
9234 inst.instruction |= inst.operands[0].reg << 12;
9235 inst.instruction |= inst.operands[1].reg << 16;
9236 inst.instruction |= inst.operands[2].reg;
9237 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9238
682b27ad
PB
9239 /* rdhi and rdlo must be different. */
9240 if (inst.operands[0].reg == inst.operands[1].reg)
9241 as_tsktsk (_("rdhi and rdlo must be different"));
9242
9243 /* rdhi, rdlo and rm must all be different before armv6. */
9244 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9245 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9246 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9247 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9248}
b99bd4ef 9249
c19d1205
ZW
9250static void
9251do_nop (void)
9252{
e7495e45
NS
9253 if (inst.operands[0].present
9254 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9255 {
9256 /* Architectural NOP hints are CPSR sets with no bits selected. */
9257 inst.instruction &= 0xf0000000;
e7495e45
NS
9258 inst.instruction |= 0x0320f000;
9259 if (inst.operands[0].present)
9260 inst.instruction |= inst.operands[0].imm;
c19d1205 9261 }
b99bd4ef
NC
9262}
9263
c19d1205
ZW
9264/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9265 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9266 Condition defaults to COND_ALWAYS.
9267 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9268
9269static void
c19d1205 9270do_pkhbt (void)
b99bd4ef 9271{
c19d1205
ZW
9272 inst.instruction |= inst.operands[0].reg << 12;
9273 inst.instruction |= inst.operands[1].reg << 16;
9274 inst.instruction |= inst.operands[2].reg;
9275 if (inst.operands[3].present)
9276 encode_arm_shift (3);
9277}
b99bd4ef 9278
c19d1205 9279/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9280
c19d1205
ZW
9281static void
9282do_pkhtb (void)
9283{
9284 if (!inst.operands[3].present)
b99bd4ef 9285 {
c19d1205
ZW
9286 /* If the shift specifier is omitted, turn the instruction
9287 into pkhbt rd, rm, rn. */
9288 inst.instruction &= 0xfff00010;
9289 inst.instruction |= inst.operands[0].reg << 12;
9290 inst.instruction |= inst.operands[1].reg;
9291 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9292 }
9293 else
9294 {
c19d1205
ZW
9295 inst.instruction |= inst.operands[0].reg << 12;
9296 inst.instruction |= inst.operands[1].reg << 16;
9297 inst.instruction |= inst.operands[2].reg;
9298 encode_arm_shift (3);
b99bd4ef
NC
9299 }
9300}
9301
c19d1205 9302/* ARMv5TE: Preload-Cache
60e5ef9f 9303 MP Extensions: Preload for write
c19d1205 9304
60e5ef9f 9305 PLD(W) <addr_mode>
c19d1205
ZW
9306
9307 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9308
9309static void
c19d1205 9310do_pld (void)
b99bd4ef 9311{
c19d1205
ZW
9312 constraint (!inst.operands[0].isreg,
9313 _("'[' expected after PLD mnemonic"));
9314 constraint (inst.operands[0].postind,
9315 _("post-indexed expression used in preload instruction"));
9316 constraint (inst.operands[0].writeback,
9317 _("writeback used in preload instruction"));
9318 constraint (!inst.operands[0].preind,
9319 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9320 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9321}
b99bd4ef 9322
62b3e311
PB
9323/* ARMv7: PLI <addr_mode> */
9324static void
9325do_pli (void)
9326{
9327 constraint (!inst.operands[0].isreg,
9328 _("'[' expected after PLI mnemonic"));
9329 constraint (inst.operands[0].postind,
9330 _("post-indexed expression used in preload instruction"));
9331 constraint (inst.operands[0].writeback,
9332 _("writeback used in preload instruction"));
9333 constraint (!inst.operands[0].preind,
9334 _("unindexed addressing used in preload instruction"));
9335 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9336 inst.instruction &= ~PRE_INDEX;
9337}
9338
c19d1205
ZW
9339static void
9340do_push_pop (void)
9341{
5e0d7f77
MP
9342 constraint (inst.operands[0].writeback,
9343 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9344 inst.operands[1] = inst.operands[0];
9345 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9346 inst.operands[0].isreg = 1;
9347 inst.operands[0].writeback = 1;
9348 inst.operands[0].reg = REG_SP;
6530b175 9349 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9350}
b99bd4ef 9351
c19d1205
ZW
9352/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9353 word at the specified address and the following word
9354 respectively.
9355 Unconditionally executed.
9356 Error if Rn is R15. */
b99bd4ef 9357
c19d1205
ZW
9358static void
9359do_rfe (void)
9360{
9361 inst.instruction |= inst.operands[0].reg << 16;
9362 if (inst.operands[0].writeback)
9363 inst.instruction |= WRITE_BACK;
9364}
b99bd4ef 9365
c19d1205 9366/* ARM V6 ssat (argument parse). */
b99bd4ef 9367
c19d1205
ZW
9368static void
9369do_ssat (void)
9370{
9371 inst.instruction |= inst.operands[0].reg << 12;
9372 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9373 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9374
c19d1205
ZW
9375 if (inst.operands[3].present)
9376 encode_arm_shift (3);
b99bd4ef
NC
9377}
9378
c19d1205 9379/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9380
9381static void
c19d1205 9382do_usat (void)
b99bd4ef 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;
b99bd4ef 9387
c19d1205
ZW
9388 if (inst.operands[3].present)
9389 encode_arm_shift (3);
b99bd4ef
NC
9390}
9391
c19d1205 9392/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9393
9394static void
c19d1205 9395do_ssat16 (void)
09d92015 9396{
c19d1205
ZW
9397 inst.instruction |= inst.operands[0].reg << 12;
9398 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9399 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9400}
9401
c19d1205
ZW
9402static void
9403do_usat16 (void)
a737bd4d 9404{
c19d1205
ZW
9405 inst.instruction |= inst.operands[0].reg << 12;
9406 inst.instruction |= inst.operands[1].imm << 16;
9407 inst.instruction |= inst.operands[2].reg;
9408}
a737bd4d 9409
c19d1205
ZW
9410/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9411 preserving the other bits.
a737bd4d 9412
c19d1205
ZW
9413 setend <endian_specifier>, where <endian_specifier> is either
9414 BE or LE. */
a737bd4d 9415
c19d1205
ZW
9416static void
9417do_setend (void)
9418{
12e37cbc
MGD
9419 if (warn_on_deprecated
9420 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9421 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9422
c19d1205
ZW
9423 if (inst.operands[0].imm)
9424 inst.instruction |= 0x200;
a737bd4d
NC
9425}
9426
9427static void
c19d1205 9428do_shift (void)
a737bd4d 9429{
c19d1205
ZW
9430 unsigned int Rm = (inst.operands[1].present
9431 ? inst.operands[1].reg
9432 : inst.operands[0].reg);
a737bd4d 9433
c19d1205
ZW
9434 inst.instruction |= inst.operands[0].reg << 12;
9435 inst.instruction |= Rm;
9436 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9437 {
c19d1205
ZW
9438 inst.instruction |= inst.operands[2].reg << 8;
9439 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9440 /* PR 12854: Error on extraneous shifts. */
9441 constraint (inst.operands[2].shifted,
9442 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9443 }
9444 else
c19d1205 9445 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9446}
9447
09d92015 9448static void
3eb17e6b 9449do_smc (void)
09d92015 9450{
3eb17e6b 9451 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9452 inst.reloc.pc_rel = 0;
09d92015
MM
9453}
9454
90ec0d68
MGD
9455static void
9456do_hvc (void)
9457{
9458 inst.reloc.type = BFD_RELOC_ARM_HVC;
9459 inst.reloc.pc_rel = 0;
9460}
9461
09d92015 9462static void
c19d1205 9463do_swi (void)
09d92015 9464{
c19d1205
ZW
9465 inst.reloc.type = BFD_RELOC_ARM_SWI;
9466 inst.reloc.pc_rel = 0;
09d92015
MM
9467}
9468
ddfded2f
MW
9469static void
9470do_setpan (void)
9471{
9472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9473 _("selected processor does not support SETPAN instruction"));
9474
9475 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9476}
9477
9478static void
9479do_t_setpan (void)
9480{
9481 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9482 _("selected processor does not support SETPAN instruction"));
9483
9484 inst.instruction |= (inst.operands[0].imm << 3);
9485}
9486
c19d1205
ZW
9487/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9488 SMLAxy{cond} Rd,Rm,Rs,Rn
9489 SMLAWy{cond} Rd,Rm,Rs,Rn
9490 Error if any register is R15. */
e16bb312 9491
c19d1205
ZW
9492static void
9493do_smla (void)
e16bb312 9494{
c19d1205
ZW
9495 inst.instruction |= inst.operands[0].reg << 16;
9496 inst.instruction |= inst.operands[1].reg;
9497 inst.instruction |= inst.operands[2].reg << 8;
9498 inst.instruction |= inst.operands[3].reg << 12;
9499}
a737bd4d 9500
c19d1205
ZW
9501/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9502 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9503 Error if any register is R15.
9504 Warning if Rdlo == Rdhi. */
a737bd4d 9505
c19d1205
ZW
9506static void
9507do_smlal (void)
9508{
9509 inst.instruction |= inst.operands[0].reg << 12;
9510 inst.instruction |= inst.operands[1].reg << 16;
9511 inst.instruction |= inst.operands[2].reg;
9512 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9513
c19d1205
ZW
9514 if (inst.operands[0].reg == inst.operands[1].reg)
9515 as_tsktsk (_("rdhi and rdlo must be different"));
9516}
a737bd4d 9517
c19d1205
ZW
9518/* ARM V5E (El Segundo) signed-multiply (argument parse)
9519 SMULxy{cond} Rd,Rm,Rs
9520 Error if any register is R15. */
a737bd4d 9521
c19d1205
ZW
9522static void
9523do_smul (void)
9524{
9525 inst.instruction |= inst.operands[0].reg << 16;
9526 inst.instruction |= inst.operands[1].reg;
9527 inst.instruction |= inst.operands[2].reg << 8;
9528}
a737bd4d 9529
b6702015
PB
9530/* ARM V6 srs (argument parse). The variable fields in the encoding are
9531 the same for both ARM and Thumb-2. */
a737bd4d 9532
c19d1205
ZW
9533static void
9534do_srs (void)
9535{
b6702015
PB
9536 int reg;
9537
9538 if (inst.operands[0].present)
9539 {
9540 reg = inst.operands[0].reg;
fdfde340 9541 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9542 }
9543 else
fdfde340 9544 reg = REG_SP;
b6702015
PB
9545
9546 inst.instruction |= reg << 16;
9547 inst.instruction |= inst.operands[1].imm;
9548 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9549 inst.instruction |= WRITE_BACK;
9550}
a737bd4d 9551
c19d1205 9552/* ARM V6 strex (argument parse). */
a737bd4d 9553
c19d1205
ZW
9554static void
9555do_strex (void)
9556{
9557 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9558 || inst.operands[2].postind || inst.operands[2].writeback
9559 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9560 || inst.operands[2].negative
9561 /* See comment in do_ldrex(). */
9562 || (inst.operands[2].reg == REG_PC),
9563 BAD_ADDR_MODE);
a737bd4d 9564
c19d1205
ZW
9565 constraint (inst.operands[0].reg == inst.operands[1].reg
9566 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9567
c19d1205
ZW
9568 constraint (inst.reloc.exp.X_op != O_constant
9569 || inst.reloc.exp.X_add_number != 0,
9570 _("offset must be zero in ARM encoding"));
a737bd4d 9571
c19d1205
ZW
9572 inst.instruction |= inst.operands[0].reg << 12;
9573 inst.instruction |= inst.operands[1].reg;
9574 inst.instruction |= inst.operands[2].reg << 16;
9575 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9576}
9577
877807f8
NC
9578static void
9579do_t_strexbh (void)
9580{
9581 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9582 || inst.operands[2].postind || inst.operands[2].writeback
9583 || inst.operands[2].immisreg || inst.operands[2].shifted
9584 || inst.operands[2].negative,
9585 BAD_ADDR_MODE);
9586
9587 constraint (inst.operands[0].reg == inst.operands[1].reg
9588 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9589
9590 do_rm_rd_rn ();
9591}
9592
e16bb312 9593static void
c19d1205 9594do_strexd (void)
e16bb312 9595{
c19d1205
ZW
9596 constraint (inst.operands[1].reg % 2 != 0,
9597 _("even register required"));
9598 constraint (inst.operands[2].present
9599 && inst.operands[2].reg != inst.operands[1].reg + 1,
9600 _("can only store two consecutive registers"));
9601 /* If op 2 were present and equal to PC, this function wouldn't
9602 have been called in the first place. */
9603 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9604
c19d1205
ZW
9605 constraint (inst.operands[0].reg == inst.operands[1].reg
9606 || inst.operands[0].reg == inst.operands[1].reg + 1
9607 || inst.operands[0].reg == inst.operands[3].reg,
9608 BAD_OVERLAP);
e16bb312 9609
c19d1205
ZW
9610 inst.instruction |= inst.operands[0].reg << 12;
9611 inst.instruction |= inst.operands[1].reg;
9612 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9613}
9614
9eb6c0f1
MGD
9615/* ARM V8 STRL. */
9616static void
4b8c8c02 9617do_stlex (void)
9eb6c0f1
MGD
9618{
9619 constraint (inst.operands[0].reg == inst.operands[1].reg
9620 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9621
9622 do_rd_rm_rn ();
9623}
9624
9625static void
4b8c8c02 9626do_t_stlex (void)
9eb6c0f1
MGD
9627{
9628 constraint (inst.operands[0].reg == inst.operands[1].reg
9629 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9630
9631 do_rm_rd_rn ();
9632}
9633
c19d1205
ZW
9634/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9635 extends it to 32-bits, and adds the result to a value in another
9636 register. You can specify a rotation by 0, 8, 16, or 24 bits
9637 before extracting the 16-bit value.
9638 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9639 Condition defaults to COND_ALWAYS.
9640 Error if any register uses R15. */
9641
e16bb312 9642static void
c19d1205 9643do_sxtah (void)
e16bb312 9644{
c19d1205
ZW
9645 inst.instruction |= inst.operands[0].reg << 12;
9646 inst.instruction |= inst.operands[1].reg << 16;
9647 inst.instruction |= inst.operands[2].reg;
9648 inst.instruction |= inst.operands[3].imm << 10;
9649}
e16bb312 9650
c19d1205 9651/* ARM V6 SXTH.
e16bb312 9652
c19d1205
ZW
9653 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9654 Condition defaults to COND_ALWAYS.
9655 Error if any register uses R15. */
e16bb312
NC
9656
9657static void
c19d1205 9658do_sxth (void)
e16bb312 9659{
c19d1205
ZW
9660 inst.instruction |= inst.operands[0].reg << 12;
9661 inst.instruction |= inst.operands[1].reg;
9662 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9663}
c19d1205
ZW
9664\f
9665/* VFP instructions. In a logical order: SP variant first, monad
9666 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9667
9668static void
c19d1205 9669do_vfp_sp_monadic (void)
e16bb312 9670{
5287ad62
JB
9671 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9672 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9673}
9674
9675static void
c19d1205 9676do_vfp_sp_dyadic (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_Sn);
9680 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9681}
9682
9683static void
c19d1205 9684do_vfp_sp_compare_z (void)
e16bb312 9685{
5287ad62 9686 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9687}
9688
9689static void
c19d1205 9690do_vfp_dp_sp_cvt (void)
e16bb312 9691{
5287ad62
JB
9692 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9694}
9695
9696static void
c19d1205 9697do_vfp_sp_dp_cvt (void)
e16bb312 9698{
5287ad62
JB
9699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9701}
9702
9703static void
c19d1205 9704do_vfp_reg_from_sp (void)
e16bb312 9705{
c19d1205 9706 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9708}
9709
9710static void
c19d1205 9711do_vfp_reg2_from_sp2 (void)
e16bb312 9712{
c19d1205
ZW
9713 constraint (inst.operands[2].imm != 2,
9714 _("only two consecutive VFP SP registers allowed here"));
9715 inst.instruction |= inst.operands[0].reg << 12;
9716 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9717 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9718}
9719
9720static void
c19d1205 9721do_vfp_sp_from_reg (void)
e16bb312 9722{
5287ad62 9723 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9724 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9725}
9726
9727static void
c19d1205 9728do_vfp_sp2_from_reg2 (void)
e16bb312 9729{
c19d1205
ZW
9730 constraint (inst.operands[0].imm != 2,
9731 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9733 inst.instruction |= inst.operands[1].reg << 12;
9734 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9735}
9736
9737static void
c19d1205 9738do_vfp_sp_ldst (void)
e16bb312 9739{
5287ad62 9740 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9741 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9742}
9743
9744static void
c19d1205 9745do_vfp_dp_ldst (void)
e16bb312 9746{
5287ad62 9747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9748 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9749}
9750
c19d1205 9751
e16bb312 9752static void
c19d1205 9753vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9754{
c19d1205
ZW
9755 if (inst.operands[0].writeback)
9756 inst.instruction |= WRITE_BACK;
9757 else
9758 constraint (ldstm_type != VFP_LDSTMIA,
9759 _("this addressing mode requires base-register writeback"));
9760 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9761 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9762 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9763}
9764
9765static void
c19d1205 9766vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9767{
c19d1205 9768 int count;
e16bb312 9769
c19d1205
ZW
9770 if (inst.operands[0].writeback)
9771 inst.instruction |= WRITE_BACK;
9772 else
9773 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9774 _("this addressing mode requires base-register writeback"));
e16bb312 9775
c19d1205 9776 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9777 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9778
c19d1205
ZW
9779 count = inst.operands[1].imm << 1;
9780 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9781 count += 1;
e16bb312 9782
c19d1205 9783 inst.instruction |= count;
e16bb312
NC
9784}
9785
9786static void
c19d1205 9787do_vfp_sp_ldstmia (void)
e16bb312 9788{
c19d1205 9789 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9790}
9791
9792static void
c19d1205 9793do_vfp_sp_ldstmdb (void)
e16bb312 9794{
c19d1205 9795 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9796}
9797
9798static void
c19d1205 9799do_vfp_dp_ldstmia (void)
e16bb312 9800{
c19d1205 9801 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9802}
9803
9804static void
c19d1205 9805do_vfp_dp_ldstmdb (void)
e16bb312 9806{
c19d1205 9807 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9808}
9809
9810static void
c19d1205 9811do_vfp_xp_ldstmia (void)
e16bb312 9812{
c19d1205
ZW
9813 vfp_dp_ldstm (VFP_LDSTMIAX);
9814}
e16bb312 9815
c19d1205
ZW
9816static void
9817do_vfp_xp_ldstmdb (void)
9818{
9819 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9820}
5287ad62
JB
9821
9822static void
9823do_vfp_dp_rd_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_Dm);
9827}
9828
9829static void
9830do_vfp_dp_rn_rd (void)
9831{
9832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9833 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9834}
9835
9836static void
9837do_vfp_dp_rd_rn (void)
9838{
9839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9841}
9842
9843static void
9844do_vfp_dp_rd_rn_rm (void)
9845{
9846 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9847 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9848 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9849}
9850
9851static void
9852do_vfp_dp_rd (void)
9853{
9854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9855}
9856
9857static void
9858do_vfp_dp_rm_rd_rn (void)
9859{
9860 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9861 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9862 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9863}
9864
9865/* VFPv3 instructions. */
9866static void
9867do_vfp_sp_const (void)
9868{
9869 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9870 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9871 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9872}
9873
9874static void
9875do_vfp_dp_const (void)
9876{
9877 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9878 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9879 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9880}
9881
9882static void
9883vfp_conv (int srcsize)
9884{
5f1af56b
MGD
9885 int immbits = srcsize - inst.operands[1].imm;
9886
fa94de6b
RM
9887 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9888 {
5f1af56b 9889 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9890 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9891 inst.error = _("immediate value out of range, expected range [0, 16]");
9892 return;
9893 }
fa94de6b 9894 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9895 {
9896 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9897 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9898 inst.error = _("immediate value out of range, expected range [1, 32]");
9899 return;
9900 }
9901
5287ad62
JB
9902 inst.instruction |= (immbits & 1) << 5;
9903 inst.instruction |= (immbits >> 1);
9904}
9905
9906static void
9907do_vfp_sp_conv_16 (void)
9908{
9909 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9910 vfp_conv (16);
9911}
9912
9913static void
9914do_vfp_dp_conv_16 (void)
9915{
9916 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9917 vfp_conv (16);
9918}
9919
9920static void
9921do_vfp_sp_conv_32 (void)
9922{
9923 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9924 vfp_conv (32);
9925}
9926
9927static void
9928do_vfp_dp_conv_32 (void)
9929{
9930 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9931 vfp_conv (32);
9932}
c19d1205
ZW
9933\f
9934/* FPA instructions. Also in a logical order. */
e16bb312 9935
c19d1205
ZW
9936static void
9937do_fpa_cmp (void)
9938{
9939 inst.instruction |= inst.operands[0].reg << 16;
9940 inst.instruction |= inst.operands[1].reg;
9941}
b99bd4ef
NC
9942
9943static void
c19d1205 9944do_fpa_ldmstm (void)
b99bd4ef 9945{
c19d1205
ZW
9946 inst.instruction |= inst.operands[0].reg << 12;
9947 switch (inst.operands[1].imm)
9948 {
9949 case 1: inst.instruction |= CP_T_X; break;
9950 case 2: inst.instruction |= CP_T_Y; break;
9951 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9952 case 4: break;
9953 default: abort ();
9954 }
b99bd4ef 9955
c19d1205
ZW
9956 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9957 {
9958 /* The instruction specified "ea" or "fd", so we can only accept
9959 [Rn]{!}. The instruction does not really support stacking or
9960 unstacking, so we have to emulate these by setting appropriate
9961 bits and offsets. */
9962 constraint (inst.reloc.exp.X_op != O_constant
9963 || inst.reloc.exp.X_add_number != 0,
9964 _("this instruction does not support indexing"));
b99bd4ef 9965
c19d1205
ZW
9966 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9967 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9968
c19d1205
ZW
9969 if (!(inst.instruction & INDEX_UP))
9970 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9971
c19d1205
ZW
9972 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9973 {
9974 inst.operands[2].preind = 0;
9975 inst.operands[2].postind = 1;
9976 }
9977 }
b99bd4ef 9978
c19d1205 9979 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9980}
c19d1205
ZW
9981\f
9982/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9983
c19d1205
ZW
9984static void
9985do_iwmmxt_tandorc (void)
9986{
9987 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9988}
b99bd4ef 9989
c19d1205
ZW
9990static void
9991do_iwmmxt_textrc (void)
9992{
9993 inst.instruction |= inst.operands[0].reg << 12;
9994 inst.instruction |= inst.operands[1].imm;
9995}
b99bd4ef
NC
9996
9997static void
c19d1205 9998do_iwmmxt_textrm (void)
b99bd4ef 9999{
c19d1205
ZW
10000 inst.instruction |= inst.operands[0].reg << 12;
10001 inst.instruction |= inst.operands[1].reg << 16;
10002 inst.instruction |= inst.operands[2].imm;
10003}
b99bd4ef 10004
c19d1205
ZW
10005static void
10006do_iwmmxt_tinsr (void)
10007{
10008 inst.instruction |= inst.operands[0].reg << 16;
10009 inst.instruction |= inst.operands[1].reg << 12;
10010 inst.instruction |= inst.operands[2].imm;
10011}
b99bd4ef 10012
c19d1205
ZW
10013static void
10014do_iwmmxt_tmia (void)
10015{
10016 inst.instruction |= inst.operands[0].reg << 5;
10017 inst.instruction |= inst.operands[1].reg;
10018 inst.instruction |= inst.operands[2].reg << 12;
10019}
b99bd4ef 10020
c19d1205
ZW
10021static void
10022do_iwmmxt_waligni (void)
10023{
10024 inst.instruction |= inst.operands[0].reg << 12;
10025 inst.instruction |= inst.operands[1].reg << 16;
10026 inst.instruction |= inst.operands[2].reg;
10027 inst.instruction |= inst.operands[3].imm << 20;
10028}
b99bd4ef 10029
2d447fca
JM
10030static void
10031do_iwmmxt_wmerge (void)
10032{
10033 inst.instruction |= inst.operands[0].reg << 12;
10034 inst.instruction |= inst.operands[1].reg << 16;
10035 inst.instruction |= inst.operands[2].reg;
10036 inst.instruction |= inst.operands[3].imm << 21;
10037}
10038
c19d1205
ZW
10039static void
10040do_iwmmxt_wmov (void)
10041{
10042 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10043 inst.instruction |= inst.operands[0].reg << 12;
10044 inst.instruction |= inst.operands[1].reg << 16;
10045 inst.instruction |= inst.operands[1].reg;
10046}
b99bd4ef 10047
c19d1205
ZW
10048static void
10049do_iwmmxt_wldstbh (void)
10050{
8f06b2d8 10051 int reloc;
c19d1205 10052 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10053 if (thumb_mode)
10054 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10055 else
10056 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10057 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10058}
10059
c19d1205
ZW
10060static void
10061do_iwmmxt_wldstw (void)
10062{
10063 /* RIWR_RIWC clears .isreg for a control register. */
10064 if (!inst.operands[0].isreg)
10065 {
10066 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10067 inst.instruction |= 0xf0000000;
10068 }
b99bd4ef 10069
c19d1205
ZW
10070 inst.instruction |= inst.operands[0].reg << 12;
10071 encode_arm_cp_address (1, TRUE, TRUE, 0);
10072}
b99bd4ef
NC
10073
10074static void
c19d1205 10075do_iwmmxt_wldstd (void)
b99bd4ef 10076{
c19d1205 10077 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10078 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10079 && inst.operands[1].immisreg)
10080 {
10081 inst.instruction &= ~0x1a000ff;
eff0bc54 10082 inst.instruction |= (0xfU << 28);
2d447fca
JM
10083 if (inst.operands[1].preind)
10084 inst.instruction |= PRE_INDEX;
10085 if (!inst.operands[1].negative)
10086 inst.instruction |= INDEX_UP;
10087 if (inst.operands[1].writeback)
10088 inst.instruction |= WRITE_BACK;
10089 inst.instruction |= inst.operands[1].reg << 16;
10090 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10091 inst.instruction |= inst.operands[1].imm;
10092 }
10093 else
10094 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10095}
b99bd4ef 10096
c19d1205
ZW
10097static void
10098do_iwmmxt_wshufh (void)
10099{
10100 inst.instruction |= inst.operands[0].reg << 12;
10101 inst.instruction |= inst.operands[1].reg << 16;
10102 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10103 inst.instruction |= (inst.operands[2].imm & 0x0f);
10104}
b99bd4ef 10105
c19d1205
ZW
10106static void
10107do_iwmmxt_wzero (void)
10108{
10109 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10110 inst.instruction |= inst.operands[0].reg;
10111 inst.instruction |= inst.operands[0].reg << 12;
10112 inst.instruction |= inst.operands[0].reg << 16;
10113}
2d447fca
JM
10114
10115static void
10116do_iwmmxt_wrwrwr_or_imm5 (void)
10117{
10118 if (inst.operands[2].isreg)
10119 do_rd_rn_rm ();
10120 else {
10121 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10122 _("immediate operand requires iWMMXt2"));
10123 do_rd_rn ();
10124 if (inst.operands[2].imm == 0)
10125 {
10126 switch ((inst.instruction >> 20) & 0xf)
10127 {
10128 case 4:
10129 case 5:
10130 case 6:
5f4273c7 10131 case 7:
2d447fca
JM
10132 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10133 inst.operands[2].imm = 16;
10134 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10135 break;
10136 case 8:
10137 case 9:
10138 case 10:
10139 case 11:
10140 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10141 inst.operands[2].imm = 32;
10142 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10143 break;
10144 case 12:
10145 case 13:
10146 case 14:
10147 case 15:
10148 {
10149 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10150 unsigned long wrn;
10151 wrn = (inst.instruction >> 16) & 0xf;
10152 inst.instruction &= 0xff0fff0f;
10153 inst.instruction |= wrn;
10154 /* Bail out here; the instruction is now assembled. */
10155 return;
10156 }
10157 }
10158 }
10159 /* Map 32 -> 0, etc. */
10160 inst.operands[2].imm &= 0x1f;
eff0bc54 10161 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10162 }
10163}
c19d1205
ZW
10164\f
10165/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10166 operations first, then control, shift, and load/store. */
b99bd4ef 10167
c19d1205 10168/* Insns like "foo X,Y,Z". */
b99bd4ef 10169
c19d1205
ZW
10170static void
10171do_mav_triple (void)
10172{
10173 inst.instruction |= inst.operands[0].reg << 16;
10174 inst.instruction |= inst.operands[1].reg;
10175 inst.instruction |= inst.operands[2].reg << 12;
10176}
b99bd4ef 10177
c19d1205
ZW
10178/* Insns like "foo W,X,Y,Z".
10179 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10180
c19d1205
ZW
10181static void
10182do_mav_quad (void)
10183{
10184 inst.instruction |= inst.operands[0].reg << 5;
10185 inst.instruction |= inst.operands[1].reg << 12;
10186 inst.instruction |= inst.operands[2].reg << 16;
10187 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10188}
10189
c19d1205
ZW
10190/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10191static void
10192do_mav_dspsc (void)
a737bd4d 10193{
c19d1205
ZW
10194 inst.instruction |= inst.operands[1].reg << 12;
10195}
a737bd4d 10196
c19d1205
ZW
10197/* Maverick shift immediate instructions.
10198 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10199 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10200
c19d1205
ZW
10201static void
10202do_mav_shift (void)
10203{
10204 int imm = inst.operands[2].imm;
a737bd4d 10205
c19d1205
ZW
10206 inst.instruction |= inst.operands[0].reg << 12;
10207 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10208
c19d1205
ZW
10209 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10210 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10211 Bit 4 should be 0. */
10212 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10213
c19d1205
ZW
10214 inst.instruction |= imm;
10215}
10216\f
10217/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10218
c19d1205
ZW
10219/* Xscale multiply-accumulate (argument parse)
10220 MIAcc acc0,Rm,Rs
10221 MIAPHcc acc0,Rm,Rs
10222 MIAxycc acc0,Rm,Rs. */
a737bd4d 10223
c19d1205
ZW
10224static void
10225do_xsc_mia (void)
10226{
10227 inst.instruction |= inst.operands[1].reg;
10228 inst.instruction |= inst.operands[2].reg << 12;
10229}
a737bd4d 10230
c19d1205 10231/* Xscale move-accumulator-register (argument parse)
a737bd4d 10232
c19d1205 10233 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10234
c19d1205
ZW
10235static void
10236do_xsc_mar (void)
10237{
10238 inst.instruction |= inst.operands[1].reg << 12;
10239 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10240}
10241
c19d1205 10242/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10243
c19d1205 10244 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10245
10246static void
c19d1205 10247do_xsc_mra (void)
b99bd4ef 10248{
c19d1205
ZW
10249 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10250 inst.instruction |= inst.operands[0].reg << 12;
10251 inst.instruction |= inst.operands[1].reg << 16;
10252}
10253\f
10254/* Encoding functions relevant only to Thumb. */
b99bd4ef 10255
c19d1205
ZW
10256/* inst.operands[i] is a shifted-register operand; encode
10257 it into inst.instruction in the format used by Thumb32. */
10258
10259static void
10260encode_thumb32_shifted_operand (int i)
10261{
10262 unsigned int value = inst.reloc.exp.X_add_number;
10263 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10264
9c3c69f2
PB
10265 constraint (inst.operands[i].immisreg,
10266 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10267 inst.instruction |= inst.operands[i].reg;
10268 if (shift == SHIFT_RRX)
10269 inst.instruction |= SHIFT_ROR << 4;
10270 else
b99bd4ef 10271 {
c19d1205
ZW
10272 constraint (inst.reloc.exp.X_op != O_constant,
10273 _("expression too complex"));
10274
10275 constraint (value > 32
10276 || (value == 32 && (shift == SHIFT_LSL
10277 || shift == SHIFT_ROR)),
10278 _("shift expression is too large"));
10279
10280 if (value == 0)
10281 shift = SHIFT_LSL;
10282 else if (value == 32)
10283 value = 0;
10284
10285 inst.instruction |= shift << 4;
10286 inst.instruction |= (value & 0x1c) << 10;
10287 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10288 }
c19d1205 10289}
b99bd4ef 10290
b99bd4ef 10291
c19d1205
ZW
10292/* inst.operands[i] was set up by parse_address. Encode it into a
10293 Thumb32 format load or store instruction. Reject forms that cannot
10294 be used with such instructions. If is_t is true, reject forms that
10295 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10296 that cannot be used with a D instruction. If it is a store insn,
10297 reject PC in Rn. */
b99bd4ef 10298
c19d1205
ZW
10299static void
10300encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10301{
5be8be5d 10302 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10303
10304 constraint (!inst.operands[i].isreg,
53365c0d 10305 _("Instruction does not support =N addresses"));
b99bd4ef 10306
c19d1205
ZW
10307 inst.instruction |= inst.operands[i].reg << 16;
10308 if (inst.operands[i].immisreg)
b99bd4ef 10309 {
5be8be5d 10310 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10311 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10312 constraint (inst.operands[i].negative,
10313 _("Thumb does not support negative register indexing"));
10314 constraint (inst.operands[i].postind,
10315 _("Thumb does not support register post-indexing"));
10316 constraint (inst.operands[i].writeback,
10317 _("Thumb does not support register indexing with writeback"));
10318 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10319 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10320
f40d1643 10321 inst.instruction |= inst.operands[i].imm;
c19d1205 10322 if (inst.operands[i].shifted)
b99bd4ef 10323 {
c19d1205
ZW
10324 constraint (inst.reloc.exp.X_op != O_constant,
10325 _("expression too complex"));
9c3c69f2
PB
10326 constraint (inst.reloc.exp.X_add_number < 0
10327 || inst.reloc.exp.X_add_number > 3,
c19d1205 10328 _("shift out of range"));
9c3c69f2 10329 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10330 }
10331 inst.reloc.type = BFD_RELOC_UNUSED;
10332 }
10333 else if (inst.operands[i].preind)
10334 {
5be8be5d 10335 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10336 constraint (is_t && inst.operands[i].writeback,
c19d1205 10337 _("cannot use writeback with this instruction"));
4755303e
WN
10338 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10339 BAD_PC_ADDRESSING);
c19d1205
ZW
10340
10341 if (is_d)
10342 {
10343 inst.instruction |= 0x01000000;
10344 if (inst.operands[i].writeback)
10345 inst.instruction |= 0x00200000;
b99bd4ef 10346 }
c19d1205 10347 else
b99bd4ef 10348 {
c19d1205
ZW
10349 inst.instruction |= 0x00000c00;
10350 if (inst.operands[i].writeback)
10351 inst.instruction |= 0x00000100;
b99bd4ef 10352 }
c19d1205 10353 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10354 }
c19d1205 10355 else if (inst.operands[i].postind)
b99bd4ef 10356 {
9c2799c2 10357 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10358 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10359 constraint (is_t, _("cannot use post-indexing with this instruction"));
10360
10361 if (is_d)
10362 inst.instruction |= 0x00200000;
10363 else
10364 inst.instruction |= 0x00000900;
10365 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10366 }
10367 else /* unindexed - only for coprocessor */
10368 inst.error = _("instruction does not accept unindexed addressing");
10369}
10370
10371/* Table of Thumb instructions which exist in both 16- and 32-bit
10372 encodings (the latter only in post-V6T2 cores). The index is the
10373 value used in the insns table below. When there is more than one
10374 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10375 holds variant (1).
10376 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10377#define T16_32_TAB \
21d799b5
NC
10378 X(_adc, 4140, eb400000), \
10379 X(_adcs, 4140, eb500000), \
10380 X(_add, 1c00, eb000000), \
10381 X(_adds, 1c00, eb100000), \
10382 X(_addi, 0000, f1000000), \
10383 X(_addis, 0000, f1100000), \
10384 X(_add_pc,000f, f20f0000), \
10385 X(_add_sp,000d, f10d0000), \
10386 X(_adr, 000f, f20f0000), \
10387 X(_and, 4000, ea000000), \
10388 X(_ands, 4000, ea100000), \
10389 X(_asr, 1000, fa40f000), \
10390 X(_asrs, 1000, fa50f000), \
10391 X(_b, e000, f000b000), \
10392 X(_bcond, d000, f0008000), \
10393 X(_bic, 4380, ea200000), \
10394 X(_bics, 4380, ea300000), \
10395 X(_cmn, 42c0, eb100f00), \
10396 X(_cmp, 2800, ebb00f00), \
10397 X(_cpsie, b660, f3af8400), \
10398 X(_cpsid, b670, f3af8600), \
10399 X(_cpy, 4600, ea4f0000), \
10400 X(_dec_sp,80dd, f1ad0d00), \
10401 X(_eor, 4040, ea800000), \
10402 X(_eors, 4040, ea900000), \
10403 X(_inc_sp,00dd, f10d0d00), \
10404 X(_ldmia, c800, e8900000), \
10405 X(_ldr, 6800, f8500000), \
10406 X(_ldrb, 7800, f8100000), \
10407 X(_ldrh, 8800, f8300000), \
10408 X(_ldrsb, 5600, f9100000), \
10409 X(_ldrsh, 5e00, f9300000), \
10410 X(_ldr_pc,4800, f85f0000), \
10411 X(_ldr_pc2,4800, f85f0000), \
10412 X(_ldr_sp,9800, f85d0000), \
10413 X(_lsl, 0000, fa00f000), \
10414 X(_lsls, 0000, fa10f000), \
10415 X(_lsr, 0800, fa20f000), \
10416 X(_lsrs, 0800, fa30f000), \
10417 X(_mov, 2000, ea4f0000), \
10418 X(_movs, 2000, ea5f0000), \
10419 X(_mul, 4340, fb00f000), \
10420 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10421 X(_mvn, 43c0, ea6f0000), \
10422 X(_mvns, 43c0, ea7f0000), \
10423 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10424 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10425 X(_orr, 4300, ea400000), \
10426 X(_orrs, 4300, ea500000), \
10427 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10428 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10429 X(_rev, ba00, fa90f080), \
10430 X(_rev16, ba40, fa90f090), \
10431 X(_revsh, bac0, fa90f0b0), \
10432 X(_ror, 41c0, fa60f000), \
10433 X(_rors, 41c0, fa70f000), \
10434 X(_sbc, 4180, eb600000), \
10435 X(_sbcs, 4180, eb700000), \
10436 X(_stmia, c000, e8800000), \
10437 X(_str, 6000, f8400000), \
10438 X(_strb, 7000, f8000000), \
10439 X(_strh, 8000, f8200000), \
10440 X(_str_sp,9000, f84d0000), \
10441 X(_sub, 1e00, eba00000), \
10442 X(_subs, 1e00, ebb00000), \
10443 X(_subi, 8000, f1a00000), \
10444 X(_subis, 8000, f1b00000), \
10445 X(_sxtb, b240, fa4ff080), \
10446 X(_sxth, b200, fa0ff080), \
10447 X(_tst, 4200, ea100f00), \
10448 X(_uxtb, b2c0, fa5ff080), \
10449 X(_uxth, b280, fa1ff080), \
10450 X(_nop, bf00, f3af8000), \
10451 X(_yield, bf10, f3af8001), \
10452 X(_wfe, bf20, f3af8002), \
10453 X(_wfi, bf30, f3af8003), \
53c4b28b 10454 X(_sev, bf40, f3af8004), \
74db7efb
NC
10455 X(_sevl, bf50, f3af8005), \
10456 X(_udf, de00, f7f0a000)
c19d1205
ZW
10457
10458/* To catch errors in encoding functions, the codes are all offset by
10459 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10460 as 16-bit instructions. */
21d799b5 10461#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10462enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10463#undef X
10464
10465#define X(a,b,c) 0x##b
10466static const unsigned short thumb_op16[] = { T16_32_TAB };
10467#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10468#undef X
10469
10470#define X(a,b,c) 0x##c
10471static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10472#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10473#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10474#undef X
10475#undef T16_32_TAB
10476
10477/* Thumb instruction encoders, in alphabetical order. */
10478
92e90b6e 10479/* ADDW or SUBW. */
c921be7d 10480
92e90b6e
PB
10481static void
10482do_t_add_sub_w (void)
10483{
10484 int Rd, Rn;
10485
10486 Rd = inst.operands[0].reg;
10487 Rn = inst.operands[1].reg;
10488
539d4391
NC
10489 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10490 is the SP-{plus,minus}-immediate form of the instruction. */
10491 if (Rn == REG_SP)
10492 constraint (Rd == REG_PC, BAD_PC);
10493 else
10494 reject_bad_reg (Rd);
fdfde340 10495
92e90b6e
PB
10496 inst.instruction |= (Rn << 16) | (Rd << 8);
10497 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10498}
10499
c19d1205 10500/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10501 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10502
10503static void
10504do_t_add_sub (void)
10505{
10506 int Rd, Rs, Rn;
10507
10508 Rd = inst.operands[0].reg;
10509 Rs = (inst.operands[1].present
10510 ? inst.operands[1].reg /* Rd, Rs, foo */
10511 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10512
e07e6e58
NC
10513 if (Rd == REG_PC)
10514 set_it_insn_type_last ();
10515
c19d1205
ZW
10516 if (unified_syntax)
10517 {
0110f2b8
PB
10518 bfd_boolean flags;
10519 bfd_boolean narrow;
10520 int opcode;
10521
10522 flags = (inst.instruction == T_MNEM_adds
10523 || inst.instruction == T_MNEM_subs);
10524 if (flags)
e07e6e58 10525 narrow = !in_it_block ();
0110f2b8 10526 else
e07e6e58 10527 narrow = in_it_block ();
c19d1205 10528 if (!inst.operands[2].isreg)
b99bd4ef 10529 {
16805f35
PB
10530 int add;
10531
fdfde340
JM
10532 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10533
16805f35
PB
10534 add = (inst.instruction == T_MNEM_add
10535 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10536 opcode = 0;
10537 if (inst.size_req != 4)
10538 {
0110f2b8 10539 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10540 appropriate. */
0110f2b8
PB
10541 if (Rd == REG_SP && Rs == REG_SP && !flags)
10542 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10543 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10544 opcode = T_MNEM_add_sp;
10545 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10546 opcode = T_MNEM_add_pc;
10547 else if (Rd <= 7 && Rs <= 7 && narrow)
10548 {
10549 if (flags)
10550 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10551 else
10552 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10553 }
10554 if (opcode)
10555 {
10556 inst.instruction = THUMB_OP16(opcode);
10557 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10558 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10559 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10560 {
10561 if (inst.size_req == 2)
10562 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10563 else
10564 inst.relax = opcode;
10565 }
0110f2b8
PB
10566 }
10567 else
10568 constraint (inst.size_req == 2, BAD_HIREG);
10569 }
10570 if (inst.size_req == 4
10571 || (inst.size_req != 2 && !opcode))
10572 {
a9f02af8
MG
10573 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10574 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10575 THUMB1_RELOC_ONLY);
efd81785
PB
10576 if (Rd == REG_PC)
10577 {
fdfde340 10578 constraint (add, BAD_PC);
efd81785
PB
10579 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10580 _("only SUBS PC, LR, #const allowed"));
10581 constraint (inst.reloc.exp.X_op != O_constant,
10582 _("expression too complex"));
10583 constraint (inst.reloc.exp.X_add_number < 0
10584 || inst.reloc.exp.X_add_number > 0xff,
10585 _("immediate value out of range"));
10586 inst.instruction = T2_SUBS_PC_LR
10587 | inst.reloc.exp.X_add_number;
10588 inst.reloc.type = BFD_RELOC_UNUSED;
10589 return;
10590 }
10591 else if (Rs == REG_PC)
16805f35
PB
10592 {
10593 /* Always use addw/subw. */
10594 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10595 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10596 }
10597 else
10598 {
10599 inst.instruction = THUMB_OP32 (inst.instruction);
10600 inst.instruction = (inst.instruction & 0xe1ffffff)
10601 | 0x10000000;
10602 if (flags)
10603 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10604 else
10605 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10606 }
dc4503c6
PB
10607 inst.instruction |= Rd << 8;
10608 inst.instruction |= Rs << 16;
0110f2b8 10609 }
b99bd4ef 10610 }
c19d1205
ZW
10611 else
10612 {
5f4cb198
NC
10613 unsigned int value = inst.reloc.exp.X_add_number;
10614 unsigned int shift = inst.operands[2].shift_kind;
10615
c19d1205
ZW
10616 Rn = inst.operands[2].reg;
10617 /* See if we can do this with a 16-bit instruction. */
10618 if (!inst.operands[2].shifted && inst.size_req != 4)
10619 {
e27ec89e
PB
10620 if (Rd > 7 || Rs > 7 || Rn > 7)
10621 narrow = FALSE;
10622
10623 if (narrow)
c19d1205 10624 {
e27ec89e
PB
10625 inst.instruction = ((inst.instruction == T_MNEM_adds
10626 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10627 ? T_OPCODE_ADD_R3
10628 : T_OPCODE_SUB_R3);
10629 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10630 return;
10631 }
b99bd4ef 10632
7e806470 10633 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10634 {
7e806470
PB
10635 /* Thumb-1 cores (except v6-M) require at least one high
10636 register in a narrow non flag setting add. */
10637 if (Rd > 7 || Rn > 7
10638 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10639 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10640 {
7e806470
PB
10641 if (Rd == Rn)
10642 {
10643 Rn = Rs;
10644 Rs = Rd;
10645 }
c19d1205
ZW
10646 inst.instruction = T_OPCODE_ADD_HI;
10647 inst.instruction |= (Rd & 8) << 4;
10648 inst.instruction |= (Rd & 7);
10649 inst.instruction |= Rn << 3;
10650 return;
10651 }
c19d1205
ZW
10652 }
10653 }
c921be7d 10654
fdfde340
JM
10655 constraint (Rd == REG_PC, BAD_PC);
10656 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10657 constraint (Rs == REG_PC, BAD_PC);
10658 reject_bad_reg (Rn);
10659
c19d1205
ZW
10660 /* If we get here, it can't be done in 16 bits. */
10661 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10662 _("shift must be constant"));
10663 inst.instruction = THUMB_OP32 (inst.instruction);
10664 inst.instruction |= Rd << 8;
10665 inst.instruction |= Rs << 16;
5f4cb198
NC
10666 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10667 _("shift value over 3 not allowed in thumb mode"));
10668 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10669 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10670 encode_thumb32_shifted_operand (2);
10671 }
10672 }
10673 else
10674 {
10675 constraint (inst.instruction == T_MNEM_adds
10676 || inst.instruction == T_MNEM_subs,
10677 BAD_THUMB32);
b99bd4ef 10678
c19d1205 10679 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10680 {
c19d1205
ZW
10681 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10682 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10683 BAD_HIREG);
10684
10685 inst.instruction = (inst.instruction == T_MNEM_add
10686 ? 0x0000 : 0x8000);
10687 inst.instruction |= (Rd << 4) | Rs;
10688 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10689 return;
10690 }
10691
c19d1205
ZW
10692 Rn = inst.operands[2].reg;
10693 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10694
c19d1205
ZW
10695 /* We now have Rd, Rs, and Rn set to registers. */
10696 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10697 {
c19d1205
ZW
10698 /* Can't do this for SUB. */
10699 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10700 inst.instruction = T_OPCODE_ADD_HI;
10701 inst.instruction |= (Rd & 8) << 4;
10702 inst.instruction |= (Rd & 7);
10703 if (Rs == Rd)
10704 inst.instruction |= Rn << 3;
10705 else if (Rn == Rd)
10706 inst.instruction |= Rs << 3;
10707 else
10708 constraint (1, _("dest must overlap one source register"));
10709 }
10710 else
10711 {
10712 inst.instruction = (inst.instruction == T_MNEM_add
10713 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10714 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10715 }
b99bd4ef 10716 }
b99bd4ef
NC
10717}
10718
c19d1205
ZW
10719static void
10720do_t_adr (void)
10721{
fdfde340
JM
10722 unsigned Rd;
10723
10724 Rd = inst.operands[0].reg;
10725 reject_bad_reg (Rd);
10726
10727 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10728 {
10729 /* Defer to section relaxation. */
10730 inst.relax = inst.instruction;
10731 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10732 inst.instruction |= Rd << 4;
0110f2b8
PB
10733 }
10734 else if (unified_syntax && inst.size_req != 2)
e9f89963 10735 {
0110f2b8 10736 /* Generate a 32-bit opcode. */
e9f89963 10737 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10738 inst.instruction |= Rd << 8;
e9f89963
PB
10739 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10740 inst.reloc.pc_rel = 1;
10741 }
10742 else
10743 {
0110f2b8 10744 /* Generate a 16-bit opcode. */
e9f89963
PB
10745 inst.instruction = THUMB_OP16 (inst.instruction);
10746 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10747 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10748 inst.reloc.pc_rel = 1;
fdfde340 10749 inst.instruction |= Rd << 4;
e9f89963 10750 }
52a86f84
NC
10751
10752 if (inst.reloc.exp.X_op == O_symbol
10753 && inst.reloc.exp.X_add_symbol != NULL
10754 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10755 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10756 inst.reloc.exp.X_add_number += 1;
c19d1205 10757}
b99bd4ef 10758
c19d1205
ZW
10759/* Arithmetic instructions for which there is just one 16-bit
10760 instruction encoding, and it allows only two low registers.
10761 For maximal compatibility with ARM syntax, we allow three register
10762 operands even when Thumb-32 instructions are not available, as long
10763 as the first two are identical. For instance, both "sbc r0,r1" and
10764 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10765static void
c19d1205 10766do_t_arit3 (void)
b99bd4ef 10767{
c19d1205 10768 int Rd, Rs, Rn;
b99bd4ef 10769
c19d1205
ZW
10770 Rd = inst.operands[0].reg;
10771 Rs = (inst.operands[1].present
10772 ? inst.operands[1].reg /* Rd, Rs, foo */
10773 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10774 Rn = inst.operands[2].reg;
b99bd4ef 10775
fdfde340
JM
10776 reject_bad_reg (Rd);
10777 reject_bad_reg (Rs);
10778 if (inst.operands[2].isreg)
10779 reject_bad_reg (Rn);
10780
c19d1205 10781 if (unified_syntax)
b99bd4ef 10782 {
c19d1205
ZW
10783 if (!inst.operands[2].isreg)
10784 {
10785 /* For an immediate, we always generate a 32-bit opcode;
10786 section relaxation will shrink it later if possible. */
10787 inst.instruction = THUMB_OP32 (inst.instruction);
10788 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10789 inst.instruction |= Rd << 8;
10790 inst.instruction |= Rs << 16;
10791 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10792 }
10793 else
10794 {
e27ec89e
PB
10795 bfd_boolean narrow;
10796
c19d1205 10797 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10798 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10799 narrow = !in_it_block ();
e27ec89e 10800 else
e07e6e58 10801 narrow = in_it_block ();
e27ec89e
PB
10802
10803 if (Rd > 7 || Rn > 7 || Rs > 7)
10804 narrow = FALSE;
10805 if (inst.operands[2].shifted)
10806 narrow = FALSE;
10807 if (inst.size_req == 4)
10808 narrow = FALSE;
10809
10810 if (narrow
c19d1205
ZW
10811 && Rd == Rs)
10812 {
10813 inst.instruction = THUMB_OP16 (inst.instruction);
10814 inst.instruction |= Rd;
10815 inst.instruction |= Rn << 3;
10816 return;
10817 }
b99bd4ef 10818
c19d1205
ZW
10819 /* If we get here, it can't be done in 16 bits. */
10820 constraint (inst.operands[2].shifted
10821 && inst.operands[2].immisreg,
10822 _("shift must be constant"));
10823 inst.instruction = THUMB_OP32 (inst.instruction);
10824 inst.instruction |= Rd << 8;
10825 inst.instruction |= Rs << 16;
10826 encode_thumb32_shifted_operand (2);
10827 }
a737bd4d 10828 }
c19d1205 10829 else
b99bd4ef 10830 {
c19d1205
ZW
10831 /* On its face this is a lie - the instruction does set the
10832 flags. However, the only supported mnemonic in this mode
10833 says it doesn't. */
10834 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10835
c19d1205
ZW
10836 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10837 _("unshifted register required"));
10838 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10839 constraint (Rd != Rs,
10840 _("dest and source1 must be the same register"));
a737bd4d 10841
c19d1205
ZW
10842 inst.instruction = THUMB_OP16 (inst.instruction);
10843 inst.instruction |= Rd;
10844 inst.instruction |= Rn << 3;
b99bd4ef 10845 }
a737bd4d 10846}
b99bd4ef 10847
c19d1205
ZW
10848/* Similarly, but for instructions where the arithmetic operation is
10849 commutative, so we can allow either of them to be different from
10850 the destination operand in a 16-bit instruction. For instance, all
10851 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10852 accepted. */
10853static void
10854do_t_arit3c (void)
a737bd4d 10855{
c19d1205 10856 int Rd, Rs, Rn;
b99bd4ef 10857
c19d1205
ZW
10858 Rd = inst.operands[0].reg;
10859 Rs = (inst.operands[1].present
10860 ? inst.operands[1].reg /* Rd, Rs, foo */
10861 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10862 Rn = inst.operands[2].reg;
c921be7d 10863
fdfde340
JM
10864 reject_bad_reg (Rd);
10865 reject_bad_reg (Rs);
10866 if (inst.operands[2].isreg)
10867 reject_bad_reg (Rn);
a737bd4d 10868
c19d1205 10869 if (unified_syntax)
a737bd4d 10870 {
c19d1205 10871 if (!inst.operands[2].isreg)
b99bd4ef 10872 {
c19d1205
ZW
10873 /* For an immediate, we always generate a 32-bit opcode;
10874 section relaxation will shrink it later if possible. */
10875 inst.instruction = THUMB_OP32 (inst.instruction);
10876 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10877 inst.instruction |= Rd << 8;
10878 inst.instruction |= Rs << 16;
10879 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10880 }
c19d1205 10881 else
a737bd4d 10882 {
e27ec89e
PB
10883 bfd_boolean narrow;
10884
c19d1205 10885 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10886 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10887 narrow = !in_it_block ();
e27ec89e 10888 else
e07e6e58 10889 narrow = in_it_block ();
e27ec89e
PB
10890
10891 if (Rd > 7 || Rn > 7 || Rs > 7)
10892 narrow = FALSE;
10893 if (inst.operands[2].shifted)
10894 narrow = FALSE;
10895 if (inst.size_req == 4)
10896 narrow = FALSE;
10897
10898 if (narrow)
a737bd4d 10899 {
c19d1205 10900 if (Rd == Rs)
a737bd4d 10901 {
c19d1205
ZW
10902 inst.instruction = THUMB_OP16 (inst.instruction);
10903 inst.instruction |= Rd;
10904 inst.instruction |= Rn << 3;
10905 return;
a737bd4d 10906 }
c19d1205 10907 if (Rd == Rn)
a737bd4d 10908 {
c19d1205
ZW
10909 inst.instruction = THUMB_OP16 (inst.instruction);
10910 inst.instruction |= Rd;
10911 inst.instruction |= Rs << 3;
10912 return;
a737bd4d
NC
10913 }
10914 }
c19d1205
ZW
10915
10916 /* If we get here, it can't be done in 16 bits. */
10917 constraint (inst.operands[2].shifted
10918 && inst.operands[2].immisreg,
10919 _("shift must be constant"));
10920 inst.instruction = THUMB_OP32 (inst.instruction);
10921 inst.instruction |= Rd << 8;
10922 inst.instruction |= Rs << 16;
10923 encode_thumb32_shifted_operand (2);
a737bd4d 10924 }
b99bd4ef 10925 }
c19d1205
ZW
10926 else
10927 {
10928 /* On its face this is a lie - the instruction does set the
10929 flags. However, the only supported mnemonic in this mode
10930 says it doesn't. */
10931 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10932
c19d1205
ZW
10933 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10934 _("unshifted register required"));
10935 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10936
10937 inst.instruction = THUMB_OP16 (inst.instruction);
10938 inst.instruction |= Rd;
10939
10940 if (Rd == Rs)
10941 inst.instruction |= Rn << 3;
10942 else if (Rd == Rn)
10943 inst.instruction |= Rs << 3;
10944 else
10945 constraint (1, _("dest must overlap one source register"));
10946 }
a737bd4d
NC
10947}
10948
c19d1205
ZW
10949static void
10950do_t_bfc (void)
a737bd4d 10951{
fdfde340 10952 unsigned Rd;
c19d1205
ZW
10953 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10954 constraint (msb > 32, _("bit-field extends past end of register"));
10955 /* The instruction encoding stores the LSB and MSB,
10956 not the LSB and width. */
fdfde340
JM
10957 Rd = inst.operands[0].reg;
10958 reject_bad_reg (Rd);
10959 inst.instruction |= Rd << 8;
c19d1205
ZW
10960 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10961 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10962 inst.instruction |= msb - 1;
b99bd4ef
NC
10963}
10964
c19d1205
ZW
10965static void
10966do_t_bfi (void)
b99bd4ef 10967{
fdfde340 10968 int Rd, Rn;
c19d1205 10969 unsigned int msb;
b99bd4ef 10970
fdfde340
JM
10971 Rd = inst.operands[0].reg;
10972 reject_bad_reg (Rd);
10973
c19d1205
ZW
10974 /* #0 in second position is alternative syntax for bfc, which is
10975 the same instruction but with REG_PC in the Rm field. */
10976 if (!inst.operands[1].isreg)
fdfde340
JM
10977 Rn = REG_PC;
10978 else
10979 {
10980 Rn = inst.operands[1].reg;
10981 reject_bad_reg (Rn);
10982 }
b99bd4ef 10983
c19d1205
ZW
10984 msb = inst.operands[2].imm + inst.operands[3].imm;
10985 constraint (msb > 32, _("bit-field extends past end of register"));
10986 /* The instruction encoding stores the LSB and MSB,
10987 not the LSB and width. */
fdfde340
JM
10988 inst.instruction |= Rd << 8;
10989 inst.instruction |= Rn << 16;
c19d1205
ZW
10990 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10991 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10992 inst.instruction |= msb - 1;
b99bd4ef
NC
10993}
10994
c19d1205
ZW
10995static void
10996do_t_bfx (void)
b99bd4ef 10997{
fdfde340
JM
10998 unsigned Rd, Rn;
10999
11000 Rd = inst.operands[0].reg;
11001 Rn = inst.operands[1].reg;
11002
11003 reject_bad_reg (Rd);
11004 reject_bad_reg (Rn);
11005
c19d1205
ZW
11006 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11007 _("bit-field extends past end of register"));
fdfde340
JM
11008 inst.instruction |= Rd << 8;
11009 inst.instruction |= Rn << 16;
c19d1205
ZW
11010 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11011 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11012 inst.instruction |= inst.operands[3].imm - 1;
11013}
b99bd4ef 11014
c19d1205
ZW
11015/* ARM V5 Thumb BLX (argument parse)
11016 BLX <target_addr> which is BLX(1)
11017 BLX <Rm> which is BLX(2)
11018 Unfortunately, there are two different opcodes for this mnemonic.
11019 So, the insns[].value is not used, and the code here zaps values
11020 into inst.instruction.
b99bd4ef 11021
c19d1205
ZW
11022 ??? How to take advantage of the additional two bits of displacement
11023 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11024
c19d1205
ZW
11025static void
11026do_t_blx (void)
11027{
e07e6e58
NC
11028 set_it_insn_type_last ();
11029
c19d1205 11030 if (inst.operands[0].isreg)
fdfde340
JM
11031 {
11032 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11033 /* We have a register, so this is BLX(2). */
11034 inst.instruction |= inst.operands[0].reg << 3;
11035 }
b99bd4ef
NC
11036 else
11037 {
c19d1205 11038 /* No register. This must be BLX(1). */
2fc8bdac 11039 inst.instruction = 0xf000e800;
0855e32b 11040 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11041 }
11042}
11043
c19d1205
ZW
11044static void
11045do_t_branch (void)
b99bd4ef 11046{
0110f2b8 11047 int opcode;
dfa9f0d5 11048 int cond;
2fe88214 11049 bfd_reloc_code_real_type reloc;
dfa9f0d5 11050
e07e6e58
NC
11051 cond = inst.cond;
11052 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11053
11054 if (in_it_block ())
dfa9f0d5
PB
11055 {
11056 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11057 branches. */
dfa9f0d5 11058 cond = COND_ALWAYS;
dfa9f0d5
PB
11059 }
11060 else
11061 cond = inst.cond;
11062
11063 if (cond != COND_ALWAYS)
0110f2b8
PB
11064 opcode = T_MNEM_bcond;
11065 else
11066 opcode = inst.instruction;
11067
12d6b0b7
RS
11068 if (unified_syntax
11069 && (inst.size_req == 4
10960bfb
PB
11070 || (inst.size_req != 2
11071 && (inst.operands[0].hasreloc
11072 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11073 {
0110f2b8 11074 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11075 if (cond == COND_ALWAYS)
9ae92b05 11076 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11077 else
11078 {
ff8646ee
TP
11079 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11080 _("selected architecture does not support "
11081 "wide conditional branch instruction"));
11082
9c2799c2 11083 gas_assert (cond != 0xF);
dfa9f0d5 11084 inst.instruction |= cond << 22;
9ae92b05 11085 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11086 }
11087 }
b99bd4ef
NC
11088 else
11089 {
0110f2b8 11090 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11091 if (cond == COND_ALWAYS)
9ae92b05 11092 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11093 else
b99bd4ef 11094 {
dfa9f0d5 11095 inst.instruction |= cond << 8;
9ae92b05 11096 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11097 }
0110f2b8
PB
11098 /* Allow section relaxation. */
11099 if (unified_syntax && inst.size_req != 2)
11100 inst.relax = opcode;
b99bd4ef 11101 }
9ae92b05 11102 inst.reloc.type = reloc;
c19d1205 11103 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11104}
11105
8884b720 11106/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11107 between the two is the maximum immediate allowed - which is passed in
8884b720 11108 RANGE. */
b99bd4ef 11109static void
8884b720 11110do_t_bkpt_hlt1 (int range)
b99bd4ef 11111{
dfa9f0d5
PB
11112 constraint (inst.cond != COND_ALWAYS,
11113 _("instruction is always unconditional"));
c19d1205 11114 if (inst.operands[0].present)
b99bd4ef 11115 {
8884b720 11116 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11117 _("immediate value out of range"));
11118 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11119 }
8884b720
MGD
11120
11121 set_it_insn_type (NEUTRAL_IT_INSN);
11122}
11123
11124static void
11125do_t_hlt (void)
11126{
11127 do_t_bkpt_hlt1 (63);
11128}
11129
11130static void
11131do_t_bkpt (void)
11132{
11133 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11134}
11135
11136static void
c19d1205 11137do_t_branch23 (void)
b99bd4ef 11138{
e07e6e58 11139 set_it_insn_type_last ();
0855e32b 11140 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11141
0855e32b
NS
11142 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11143 this file. We used to simply ignore the PLT reloc type here --
11144 the branch encoding is now needed to deal with TLSCALL relocs.
11145 So if we see a PLT reloc now, put it back to how it used to be to
11146 keep the preexisting behaviour. */
11147 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11148 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11149
4343666d 11150#if defined(OBJ_COFF)
c19d1205
ZW
11151 /* If the destination of the branch is a defined symbol which does not have
11152 the THUMB_FUNC attribute, then we must be calling a function which has
11153 the (interfacearm) attribute. We look for the Thumb entry point to that
11154 function and change the branch to refer to that function instead. */
11155 if ( inst.reloc.exp.X_op == O_symbol
11156 && inst.reloc.exp.X_add_symbol != NULL
11157 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11158 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11159 inst.reloc.exp.X_add_symbol =
11160 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11161#endif
90e4755a
RE
11162}
11163
11164static void
c19d1205 11165do_t_bx (void)
90e4755a 11166{
e07e6e58 11167 set_it_insn_type_last ();
c19d1205
ZW
11168 inst.instruction |= inst.operands[0].reg << 3;
11169 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11170 should cause the alignment to be checked once it is known. This is
11171 because BX PC only works if the instruction is word aligned. */
11172}
90e4755a 11173
c19d1205
ZW
11174static void
11175do_t_bxj (void)
11176{
fdfde340 11177 int Rm;
90e4755a 11178
e07e6e58 11179 set_it_insn_type_last ();
fdfde340
JM
11180 Rm = inst.operands[0].reg;
11181 reject_bad_reg (Rm);
11182 inst.instruction |= Rm << 16;
90e4755a
RE
11183}
11184
11185static void
c19d1205 11186do_t_clz (void)
90e4755a 11187{
fdfde340
JM
11188 unsigned Rd;
11189 unsigned Rm;
11190
11191 Rd = inst.operands[0].reg;
11192 Rm = inst.operands[1].reg;
11193
11194 reject_bad_reg (Rd);
11195 reject_bad_reg (Rm);
11196
11197 inst.instruction |= Rd << 8;
11198 inst.instruction |= Rm << 16;
11199 inst.instruction |= Rm;
c19d1205 11200}
90e4755a 11201
dfa9f0d5
PB
11202static void
11203do_t_cps (void)
11204{
e07e6e58 11205 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11206 inst.instruction |= inst.operands[0].imm;
11207}
11208
c19d1205
ZW
11209static void
11210do_t_cpsi (void)
11211{
e07e6e58 11212 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11213 if (unified_syntax
62b3e311
PB
11214 && (inst.operands[1].present || inst.size_req == 4)
11215 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11216 {
c19d1205
ZW
11217 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11218 inst.instruction = 0xf3af8000;
11219 inst.instruction |= imod << 9;
11220 inst.instruction |= inst.operands[0].imm << 5;
11221 if (inst.operands[1].present)
11222 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11223 }
c19d1205 11224 else
90e4755a 11225 {
62b3e311
PB
11226 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11227 && (inst.operands[0].imm & 4),
11228 _("selected processor does not support 'A' form "
11229 "of this instruction"));
11230 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11231 _("Thumb does not support the 2-argument "
11232 "form of this instruction"));
11233 inst.instruction |= inst.operands[0].imm;
90e4755a 11234 }
90e4755a
RE
11235}
11236
c19d1205
ZW
11237/* THUMB CPY instruction (argument parse). */
11238
90e4755a 11239static void
c19d1205 11240do_t_cpy (void)
90e4755a 11241{
c19d1205 11242 if (inst.size_req == 4)
90e4755a 11243 {
c19d1205
ZW
11244 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11245 inst.instruction |= inst.operands[0].reg << 8;
11246 inst.instruction |= inst.operands[1].reg;
90e4755a 11247 }
c19d1205 11248 else
90e4755a 11249 {
c19d1205
ZW
11250 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11251 inst.instruction |= (inst.operands[0].reg & 0x7);
11252 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11253 }
90e4755a
RE
11254}
11255
90e4755a 11256static void
25fe350b 11257do_t_cbz (void)
90e4755a 11258{
e07e6e58 11259 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11260 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11261 inst.instruction |= inst.operands[0].reg;
11262 inst.reloc.pc_rel = 1;
11263 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11264}
90e4755a 11265
62b3e311
PB
11266static void
11267do_t_dbg (void)
11268{
11269 inst.instruction |= inst.operands[0].imm;
11270}
11271
11272static void
11273do_t_div (void)
11274{
fdfde340
JM
11275 unsigned Rd, Rn, Rm;
11276
11277 Rd = inst.operands[0].reg;
11278 Rn = (inst.operands[1].present
11279 ? inst.operands[1].reg : Rd);
11280 Rm = inst.operands[2].reg;
11281
11282 reject_bad_reg (Rd);
11283 reject_bad_reg (Rn);
11284 reject_bad_reg (Rm);
11285
11286 inst.instruction |= Rd << 8;
11287 inst.instruction |= Rn << 16;
11288 inst.instruction |= Rm;
62b3e311
PB
11289}
11290
c19d1205
ZW
11291static void
11292do_t_hint (void)
11293{
11294 if (unified_syntax && inst.size_req == 4)
11295 inst.instruction = THUMB_OP32 (inst.instruction);
11296 else
11297 inst.instruction = THUMB_OP16 (inst.instruction);
11298}
90e4755a 11299
c19d1205
ZW
11300static void
11301do_t_it (void)
11302{
11303 unsigned int cond = inst.operands[0].imm;
e27ec89e 11304
e07e6e58
NC
11305 set_it_insn_type (IT_INSN);
11306 now_it.mask = (inst.instruction & 0xf) | 0x10;
11307 now_it.cc = cond;
5a01bb1d 11308 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11309
11310 /* If the condition is a negative condition, invert the mask. */
c19d1205 11311 if ((cond & 0x1) == 0x0)
90e4755a 11312 {
c19d1205 11313 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11314
c19d1205 11315 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11316 {
11317 /* No conversion needed. */
11318 now_it.block_length = 1;
11319 }
c19d1205 11320 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11321 {
11322 mask ^= 0x8;
11323 now_it.block_length = 2;
11324 }
e27ec89e 11325 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11326 {
11327 mask ^= 0xC;
11328 now_it.block_length = 3;
11329 }
c19d1205 11330 else
5a01bb1d
MGD
11331 {
11332 mask ^= 0xE;
11333 now_it.block_length = 4;
11334 }
90e4755a 11335
e27ec89e
PB
11336 inst.instruction &= 0xfff0;
11337 inst.instruction |= mask;
c19d1205 11338 }
90e4755a 11339
c19d1205
ZW
11340 inst.instruction |= cond << 4;
11341}
90e4755a 11342
3c707909
PB
11343/* Helper function used for both push/pop and ldm/stm. */
11344static void
11345encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11346{
11347 bfd_boolean load;
11348
11349 load = (inst.instruction & (1 << 20)) != 0;
11350
11351 if (mask & (1 << 13))
11352 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11353
11354 if ((mask & (1 << base)) != 0
11355 && writeback)
11356 inst.error = _("having the base register in the register list when "
11357 "using write back is UNPREDICTABLE");
11358
3c707909
PB
11359 if (load)
11360 {
e07e6e58 11361 if (mask & (1 << 15))
477330fc
RM
11362 {
11363 if (mask & (1 << 14))
11364 inst.error = _("LR and PC should not both be in register list");
11365 else
11366 set_it_insn_type_last ();
11367 }
3c707909
PB
11368 }
11369 else
11370 {
11371 if (mask & (1 << 15))
11372 inst.error = _("PC not allowed in register list");
3c707909
PB
11373 }
11374
11375 if ((mask & (mask - 1)) == 0)
11376 {
11377 /* Single register transfers implemented as str/ldr. */
11378 if (writeback)
11379 {
11380 if (inst.instruction & (1 << 23))
11381 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11382 else
11383 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11384 }
11385 else
11386 {
11387 if (inst.instruction & (1 << 23))
11388 inst.instruction = 0x00800000; /* ia -> [base] */
11389 else
11390 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11391 }
11392
11393 inst.instruction |= 0xf8400000;
11394 if (load)
11395 inst.instruction |= 0x00100000;
11396
5f4273c7 11397 mask = ffs (mask) - 1;
3c707909
PB
11398 mask <<= 12;
11399 }
11400 else if (writeback)
11401 inst.instruction |= WRITE_BACK;
11402
11403 inst.instruction |= mask;
11404 inst.instruction |= base << 16;
11405}
11406
c19d1205
ZW
11407static void
11408do_t_ldmstm (void)
11409{
11410 /* This really doesn't seem worth it. */
11411 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11412 _("expression too complex"));
11413 constraint (inst.operands[1].writeback,
11414 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11415
c19d1205
ZW
11416 if (unified_syntax)
11417 {
3c707909
PB
11418 bfd_boolean narrow;
11419 unsigned mask;
11420
11421 narrow = FALSE;
c19d1205
ZW
11422 /* See if we can use a 16-bit instruction. */
11423 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11424 && inst.size_req != 4
3c707909 11425 && !(inst.operands[1].imm & ~0xff))
90e4755a 11426 {
3c707909 11427 mask = 1 << inst.operands[0].reg;
90e4755a 11428
eab4f823 11429 if (inst.operands[0].reg <= 7)
90e4755a 11430 {
3c707909 11431 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11432 ? inst.operands[0].writeback
11433 : (inst.operands[0].writeback
11434 == !(inst.operands[1].imm & mask)))
477330fc 11435 {
eab4f823
MGD
11436 if (inst.instruction == T_MNEM_stmia
11437 && (inst.operands[1].imm & mask)
11438 && (inst.operands[1].imm & (mask - 1)))
11439 as_warn (_("value stored for r%d is UNKNOWN"),
11440 inst.operands[0].reg);
3c707909 11441
eab4f823
MGD
11442 inst.instruction = THUMB_OP16 (inst.instruction);
11443 inst.instruction |= inst.operands[0].reg << 8;
11444 inst.instruction |= inst.operands[1].imm;
11445 narrow = TRUE;
11446 }
11447 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11448 {
11449 /* This means 1 register in reg list one of 3 situations:
11450 1. Instruction is stmia, but without writeback.
11451 2. lmdia without writeback, but with Rn not in
477330fc 11452 reglist.
eab4f823
MGD
11453 3. ldmia with writeback, but with Rn in reglist.
11454 Case 3 is UNPREDICTABLE behaviour, so we handle
11455 case 1 and 2 which can be converted into a 16-bit
11456 str or ldr. The SP cases are handled below. */
11457 unsigned long opcode;
11458 /* First, record an error for Case 3. */
11459 if (inst.operands[1].imm & mask
11460 && inst.operands[0].writeback)
fa94de6b 11461 inst.error =
eab4f823
MGD
11462 _("having the base register in the register list when "
11463 "using write back is UNPREDICTABLE");
fa94de6b
RM
11464
11465 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11466 : T_MNEM_ldr);
11467 inst.instruction = THUMB_OP16 (opcode);
11468 inst.instruction |= inst.operands[0].reg << 3;
11469 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11470 narrow = TRUE;
11471 }
90e4755a 11472 }
eab4f823 11473 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11474 {
eab4f823
MGD
11475 if (inst.operands[0].writeback)
11476 {
fa94de6b 11477 inst.instruction =
eab4f823 11478 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11479 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11480 inst.instruction |= inst.operands[1].imm;
477330fc 11481 narrow = TRUE;
eab4f823
MGD
11482 }
11483 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11484 {
fa94de6b 11485 inst.instruction =
eab4f823 11486 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11487 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11488 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11489 narrow = TRUE;
eab4f823 11490 }
90e4755a 11491 }
3c707909
PB
11492 }
11493
11494 if (!narrow)
11495 {
c19d1205
ZW
11496 if (inst.instruction < 0xffff)
11497 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11498
5f4273c7
NC
11499 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11500 inst.operands[0].writeback);
90e4755a
RE
11501 }
11502 }
c19d1205 11503 else
90e4755a 11504 {
c19d1205
ZW
11505 constraint (inst.operands[0].reg > 7
11506 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11507 constraint (inst.instruction != T_MNEM_ldmia
11508 && inst.instruction != T_MNEM_stmia,
11509 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11510 if (inst.instruction == T_MNEM_stmia)
f03698e6 11511 {
c19d1205
ZW
11512 if (!inst.operands[0].writeback)
11513 as_warn (_("this instruction will write back the base register"));
11514 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11515 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11516 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11517 inst.operands[0].reg);
f03698e6 11518 }
c19d1205 11519 else
90e4755a 11520 {
c19d1205
ZW
11521 if (!inst.operands[0].writeback
11522 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11523 as_warn (_("this instruction will write back the base register"));
11524 else if (inst.operands[0].writeback
11525 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11526 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11527 }
11528
c19d1205
ZW
11529 inst.instruction = THUMB_OP16 (inst.instruction);
11530 inst.instruction |= inst.operands[0].reg << 8;
11531 inst.instruction |= inst.operands[1].imm;
11532 }
11533}
e28cd48c 11534
c19d1205
ZW
11535static void
11536do_t_ldrex (void)
11537{
11538 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11539 || inst.operands[1].postind || inst.operands[1].writeback
11540 || inst.operands[1].immisreg || inst.operands[1].shifted
11541 || inst.operands[1].negative,
01cfc07f 11542 BAD_ADDR_MODE);
e28cd48c 11543
5be8be5d
DG
11544 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11545
c19d1205
ZW
11546 inst.instruction |= inst.operands[0].reg << 12;
11547 inst.instruction |= inst.operands[1].reg << 16;
11548 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11549}
e28cd48c 11550
c19d1205
ZW
11551static void
11552do_t_ldrexd (void)
11553{
11554 if (!inst.operands[1].present)
1cac9012 11555 {
c19d1205
ZW
11556 constraint (inst.operands[0].reg == REG_LR,
11557 _("r14 not allowed as first register "
11558 "when second register is omitted"));
11559 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11560 }
c19d1205
ZW
11561 constraint (inst.operands[0].reg == inst.operands[1].reg,
11562 BAD_OVERLAP);
b99bd4ef 11563
c19d1205
ZW
11564 inst.instruction |= inst.operands[0].reg << 12;
11565 inst.instruction |= inst.operands[1].reg << 8;
11566 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11567}
11568
11569static void
c19d1205 11570do_t_ldst (void)
b99bd4ef 11571{
0110f2b8
PB
11572 unsigned long opcode;
11573 int Rn;
11574
e07e6e58
NC
11575 if (inst.operands[0].isreg
11576 && !inst.operands[0].preind
11577 && inst.operands[0].reg == REG_PC)
11578 set_it_insn_type_last ();
11579
0110f2b8 11580 opcode = inst.instruction;
c19d1205 11581 if (unified_syntax)
b99bd4ef 11582 {
53365c0d
PB
11583 if (!inst.operands[1].isreg)
11584 {
11585 if (opcode <= 0xffff)
11586 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11587 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11588 return;
11589 }
0110f2b8
PB
11590 if (inst.operands[1].isreg
11591 && !inst.operands[1].writeback
c19d1205
ZW
11592 && !inst.operands[1].shifted && !inst.operands[1].postind
11593 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11594 && opcode <= 0xffff
11595 && inst.size_req != 4)
c19d1205 11596 {
0110f2b8
PB
11597 /* Insn may have a 16-bit form. */
11598 Rn = inst.operands[1].reg;
11599 if (inst.operands[1].immisreg)
11600 {
11601 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11602 /* [Rn, Rik] */
0110f2b8
PB
11603 if (Rn <= 7 && inst.operands[1].imm <= 7)
11604 goto op16;
5be8be5d
DG
11605 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11606 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11607 }
11608 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11609 && opcode != T_MNEM_ldrsb)
11610 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11611 || (Rn == REG_SP && opcode == T_MNEM_str))
11612 {
11613 /* [Rn, #const] */
11614 if (Rn > 7)
11615 {
11616 if (Rn == REG_PC)
11617 {
11618 if (inst.reloc.pc_rel)
11619 opcode = T_MNEM_ldr_pc2;
11620 else
11621 opcode = T_MNEM_ldr_pc;
11622 }
11623 else
11624 {
11625 if (opcode == T_MNEM_ldr)
11626 opcode = T_MNEM_ldr_sp;
11627 else
11628 opcode = T_MNEM_str_sp;
11629 }
11630 inst.instruction = inst.operands[0].reg << 8;
11631 }
11632 else
11633 {
11634 inst.instruction = inst.operands[0].reg;
11635 inst.instruction |= inst.operands[1].reg << 3;
11636 }
11637 inst.instruction |= THUMB_OP16 (opcode);
11638 if (inst.size_req == 2)
11639 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11640 else
11641 inst.relax = opcode;
11642 return;
11643 }
c19d1205 11644 }
0110f2b8 11645 /* Definitely a 32-bit variant. */
5be8be5d 11646
8d67f500
NC
11647 /* Warning for Erratum 752419. */
11648 if (opcode == T_MNEM_ldr
11649 && inst.operands[0].reg == REG_SP
11650 && inst.operands[1].writeback == 1
11651 && !inst.operands[1].immisreg)
11652 {
11653 if (no_cpu_selected ()
11654 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11655 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11656 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11657 as_warn (_("This instruction may be unpredictable "
11658 "if executed on M-profile cores "
11659 "with interrupts enabled."));
11660 }
11661
5be8be5d 11662 /* Do some validations regarding addressing modes. */
1be5fd2e 11663 if (inst.operands[1].immisreg)
5be8be5d
DG
11664 reject_bad_reg (inst.operands[1].imm);
11665
1be5fd2e
NC
11666 constraint (inst.operands[1].writeback == 1
11667 && inst.operands[0].reg == inst.operands[1].reg,
11668 BAD_OVERLAP);
11669
0110f2b8 11670 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11671 inst.instruction |= inst.operands[0].reg << 12;
11672 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11673 check_ldr_r15_aligned ();
b99bd4ef
NC
11674 return;
11675 }
11676
c19d1205
ZW
11677 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11678
11679 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11680 {
c19d1205
ZW
11681 /* Only [Rn,Rm] is acceptable. */
11682 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11683 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11684 || inst.operands[1].postind || inst.operands[1].shifted
11685 || inst.operands[1].negative,
11686 _("Thumb does not support this addressing mode"));
11687 inst.instruction = THUMB_OP16 (inst.instruction);
11688 goto op16;
b99bd4ef 11689 }
5f4273c7 11690
c19d1205
ZW
11691 inst.instruction = THUMB_OP16 (inst.instruction);
11692 if (!inst.operands[1].isreg)
8335d6aa 11693 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11694 return;
b99bd4ef 11695
c19d1205
ZW
11696 constraint (!inst.operands[1].preind
11697 || inst.operands[1].shifted
11698 || inst.operands[1].writeback,
11699 _("Thumb does not support this addressing mode"));
11700 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11701 {
c19d1205
ZW
11702 constraint (inst.instruction & 0x0600,
11703 _("byte or halfword not valid for base register"));
11704 constraint (inst.operands[1].reg == REG_PC
11705 && !(inst.instruction & THUMB_LOAD_BIT),
11706 _("r15 based store not allowed"));
11707 constraint (inst.operands[1].immisreg,
11708 _("invalid base register for register offset"));
b99bd4ef 11709
c19d1205
ZW
11710 if (inst.operands[1].reg == REG_PC)
11711 inst.instruction = T_OPCODE_LDR_PC;
11712 else if (inst.instruction & THUMB_LOAD_BIT)
11713 inst.instruction = T_OPCODE_LDR_SP;
11714 else
11715 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11716
c19d1205
ZW
11717 inst.instruction |= inst.operands[0].reg << 8;
11718 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11719 return;
11720 }
90e4755a 11721
c19d1205
ZW
11722 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11723 if (!inst.operands[1].immisreg)
11724 {
11725 /* Immediate offset. */
11726 inst.instruction |= inst.operands[0].reg;
11727 inst.instruction |= inst.operands[1].reg << 3;
11728 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11729 return;
11730 }
90e4755a 11731
c19d1205
ZW
11732 /* Register offset. */
11733 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11734 constraint (inst.operands[1].negative,
11735 _("Thumb does not support this addressing mode"));
90e4755a 11736
c19d1205
ZW
11737 op16:
11738 switch (inst.instruction)
11739 {
11740 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11741 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11742 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11743 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11744 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11745 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11746 case 0x5600 /* ldrsb */:
11747 case 0x5e00 /* ldrsh */: break;
11748 default: abort ();
11749 }
90e4755a 11750
c19d1205
ZW
11751 inst.instruction |= inst.operands[0].reg;
11752 inst.instruction |= inst.operands[1].reg << 3;
11753 inst.instruction |= inst.operands[1].imm << 6;
11754}
90e4755a 11755
c19d1205
ZW
11756static void
11757do_t_ldstd (void)
11758{
11759 if (!inst.operands[1].present)
b99bd4ef 11760 {
c19d1205
ZW
11761 inst.operands[1].reg = inst.operands[0].reg + 1;
11762 constraint (inst.operands[0].reg == REG_LR,
11763 _("r14 not allowed here"));
bd340a04 11764 constraint (inst.operands[0].reg == REG_R12,
477330fc 11765 _("r12 not allowed here"));
b99bd4ef 11766 }
bd340a04
MGD
11767
11768 if (inst.operands[2].writeback
11769 && (inst.operands[0].reg == inst.operands[2].reg
11770 || inst.operands[1].reg == inst.operands[2].reg))
11771 as_warn (_("base register written back, and overlaps "
477330fc 11772 "one of transfer registers"));
bd340a04 11773
c19d1205
ZW
11774 inst.instruction |= inst.operands[0].reg << 12;
11775 inst.instruction |= inst.operands[1].reg << 8;
11776 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11777}
11778
c19d1205
ZW
11779static void
11780do_t_ldstt (void)
11781{
11782 inst.instruction |= inst.operands[0].reg << 12;
11783 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11784}
a737bd4d 11785
b99bd4ef 11786static void
c19d1205 11787do_t_mla (void)
b99bd4ef 11788{
fdfde340 11789 unsigned Rd, Rn, Rm, Ra;
c921be7d 11790
fdfde340
JM
11791 Rd = inst.operands[0].reg;
11792 Rn = inst.operands[1].reg;
11793 Rm = inst.operands[2].reg;
11794 Ra = inst.operands[3].reg;
11795
11796 reject_bad_reg (Rd);
11797 reject_bad_reg (Rn);
11798 reject_bad_reg (Rm);
11799 reject_bad_reg (Ra);
11800
11801 inst.instruction |= Rd << 8;
11802 inst.instruction |= Rn << 16;
11803 inst.instruction |= Rm;
11804 inst.instruction |= Ra << 12;
c19d1205 11805}
b99bd4ef 11806
c19d1205
ZW
11807static void
11808do_t_mlal (void)
11809{
fdfde340
JM
11810 unsigned RdLo, RdHi, Rn, Rm;
11811
11812 RdLo = inst.operands[0].reg;
11813 RdHi = inst.operands[1].reg;
11814 Rn = inst.operands[2].reg;
11815 Rm = inst.operands[3].reg;
11816
11817 reject_bad_reg (RdLo);
11818 reject_bad_reg (RdHi);
11819 reject_bad_reg (Rn);
11820 reject_bad_reg (Rm);
11821
11822 inst.instruction |= RdLo << 12;
11823 inst.instruction |= RdHi << 8;
11824 inst.instruction |= Rn << 16;
11825 inst.instruction |= Rm;
c19d1205 11826}
b99bd4ef 11827
c19d1205
ZW
11828static void
11829do_t_mov_cmp (void)
11830{
fdfde340
JM
11831 unsigned Rn, Rm;
11832
11833 Rn = inst.operands[0].reg;
11834 Rm = inst.operands[1].reg;
11835
e07e6e58
NC
11836 if (Rn == REG_PC)
11837 set_it_insn_type_last ();
11838
c19d1205 11839 if (unified_syntax)
b99bd4ef 11840 {
c19d1205
ZW
11841 int r0off = (inst.instruction == T_MNEM_mov
11842 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11843 unsigned long opcode;
3d388997
PB
11844 bfd_boolean narrow;
11845 bfd_boolean low_regs;
11846
fdfde340 11847 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11848 opcode = inst.instruction;
e07e6e58 11849 if (in_it_block ())
0110f2b8 11850 narrow = opcode != T_MNEM_movs;
3d388997 11851 else
0110f2b8 11852 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11853 if (inst.size_req == 4
11854 || inst.operands[1].shifted)
11855 narrow = FALSE;
11856
efd81785
PB
11857 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11858 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11859 && !inst.operands[1].shifted
fdfde340
JM
11860 && Rn == REG_PC
11861 && Rm == REG_LR)
efd81785
PB
11862 {
11863 inst.instruction = T2_SUBS_PC_LR;
11864 return;
11865 }
11866
fdfde340
JM
11867 if (opcode == T_MNEM_cmp)
11868 {
11869 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11870 if (narrow)
11871 {
11872 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11873 but valid. */
11874 warn_deprecated_sp (Rm);
11875 /* R15 was documented as a valid choice for Rm in ARMv6,
11876 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11877 tools reject R15, so we do too. */
11878 constraint (Rm == REG_PC, BAD_PC);
11879 }
11880 else
11881 reject_bad_reg (Rm);
fdfde340
JM
11882 }
11883 else if (opcode == T_MNEM_mov
11884 || opcode == T_MNEM_movs)
11885 {
11886 if (inst.operands[1].isreg)
11887 {
11888 if (opcode == T_MNEM_movs)
11889 {
11890 reject_bad_reg (Rn);
11891 reject_bad_reg (Rm);
11892 }
76fa04a4
MGD
11893 else if (narrow)
11894 {
11895 /* This is mov.n. */
11896 if ((Rn == REG_SP || Rn == REG_PC)
11897 && (Rm == REG_SP || Rm == REG_PC))
11898 {
5c3696f8 11899 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11900 "deprecated when r%u is the destination "
11901 "register."), Rm, Rn);
11902 }
11903 }
11904 else
11905 {
11906 /* This is mov.w. */
11907 constraint (Rn == REG_PC, BAD_PC);
11908 constraint (Rm == REG_PC, BAD_PC);
11909 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11910 }
fdfde340
JM
11911 }
11912 else
11913 reject_bad_reg (Rn);
11914 }
11915
c19d1205
ZW
11916 if (!inst.operands[1].isreg)
11917 {
0110f2b8 11918 /* Immediate operand. */
e07e6e58 11919 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11920 narrow = 0;
11921 if (low_regs && narrow)
11922 {
11923 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11924 inst.instruction |= Rn << 8;
a9f02af8
MG
11925 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11926 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11927 {
a9f02af8 11928 if (inst.size_req == 2)
72d98d16 11929 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11930 else
11931 inst.relax = opcode;
72d98d16 11932 }
0110f2b8
PB
11933 }
11934 else
11935 {
a9f02af8
MG
11936 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11937 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11938 THUMB1_RELOC_ONLY);
11939
0110f2b8
PB
11940 inst.instruction = THUMB_OP32 (inst.instruction);
11941 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11942 inst.instruction |= Rn << r0off;
0110f2b8
PB
11943 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11944 }
c19d1205 11945 }
728ca7c9
PB
11946 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11947 && (inst.instruction == T_MNEM_mov
11948 || inst.instruction == T_MNEM_movs))
11949 {
11950 /* Register shifts are encoded as separate shift instructions. */
11951 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11952
e07e6e58 11953 if (in_it_block ())
728ca7c9
PB
11954 narrow = !flags;
11955 else
11956 narrow = flags;
11957
11958 if (inst.size_req == 4)
11959 narrow = FALSE;
11960
11961 if (!low_regs || inst.operands[1].imm > 7)
11962 narrow = FALSE;
11963
fdfde340 11964 if (Rn != Rm)
728ca7c9
PB
11965 narrow = FALSE;
11966
11967 switch (inst.operands[1].shift_kind)
11968 {
11969 case SHIFT_LSL:
11970 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11971 break;
11972 case SHIFT_ASR:
11973 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11974 break;
11975 case SHIFT_LSR:
11976 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11977 break;
11978 case SHIFT_ROR:
11979 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11980 break;
11981 default:
5f4273c7 11982 abort ();
728ca7c9
PB
11983 }
11984
11985 inst.instruction = opcode;
11986 if (narrow)
11987 {
fdfde340 11988 inst.instruction |= Rn;
728ca7c9
PB
11989 inst.instruction |= inst.operands[1].imm << 3;
11990 }
11991 else
11992 {
11993 if (flags)
11994 inst.instruction |= CONDS_BIT;
11995
fdfde340
JM
11996 inst.instruction |= Rn << 8;
11997 inst.instruction |= Rm << 16;
728ca7c9
PB
11998 inst.instruction |= inst.operands[1].imm;
11999 }
12000 }
3d388997 12001 else if (!narrow)
c19d1205 12002 {
728ca7c9
PB
12003 /* Some mov with immediate shift have narrow variants.
12004 Register shifts are handled above. */
12005 if (low_regs && inst.operands[1].shifted
12006 && (inst.instruction == T_MNEM_mov
12007 || inst.instruction == T_MNEM_movs))
12008 {
e07e6e58 12009 if (in_it_block ())
728ca7c9
PB
12010 narrow = (inst.instruction == T_MNEM_mov);
12011 else
12012 narrow = (inst.instruction == T_MNEM_movs);
12013 }
12014
12015 if (narrow)
12016 {
12017 switch (inst.operands[1].shift_kind)
12018 {
12019 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12020 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12021 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12022 default: narrow = FALSE; break;
12023 }
12024 }
12025
12026 if (narrow)
12027 {
fdfde340
JM
12028 inst.instruction |= Rn;
12029 inst.instruction |= Rm << 3;
728ca7c9
PB
12030 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12031 }
12032 else
12033 {
12034 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12035 inst.instruction |= Rn << r0off;
728ca7c9
PB
12036 encode_thumb32_shifted_operand (1);
12037 }
c19d1205
ZW
12038 }
12039 else
12040 switch (inst.instruction)
12041 {
12042 case T_MNEM_mov:
837b3435 12043 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12044 results. Don't allow this. */
12045 if (low_regs)
12046 {
12047 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12048 "MOV Rd, Rs with two low registers is not "
12049 "permitted on this architecture");
fa94de6b 12050 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12051 arm_ext_v6);
12052 }
12053
c19d1205 12054 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12055 inst.instruction |= (Rn & 0x8) << 4;
12056 inst.instruction |= (Rn & 0x7);
12057 inst.instruction |= Rm << 3;
c19d1205 12058 break;
b99bd4ef 12059
c19d1205
ZW
12060 case T_MNEM_movs:
12061 /* We know we have low registers at this point.
941a8a52
MGD
12062 Generate LSLS Rd, Rs, #0. */
12063 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12064 inst.instruction |= Rn;
12065 inst.instruction |= Rm << 3;
c19d1205
ZW
12066 break;
12067
12068 case T_MNEM_cmp:
3d388997 12069 if (low_regs)
c19d1205
ZW
12070 {
12071 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12072 inst.instruction |= Rn;
12073 inst.instruction |= Rm << 3;
c19d1205
ZW
12074 }
12075 else
12076 {
12077 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12078 inst.instruction |= (Rn & 0x8) << 4;
12079 inst.instruction |= (Rn & 0x7);
12080 inst.instruction |= Rm << 3;
c19d1205
ZW
12081 }
12082 break;
12083 }
b99bd4ef
NC
12084 return;
12085 }
12086
c19d1205 12087 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12088
12089 /* PR 10443: Do not silently ignore shifted operands. */
12090 constraint (inst.operands[1].shifted,
12091 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12092
c19d1205 12093 if (inst.operands[1].isreg)
b99bd4ef 12094 {
fdfde340 12095 if (Rn < 8 && Rm < 8)
b99bd4ef 12096 {
c19d1205
ZW
12097 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12098 since a MOV instruction produces unpredictable results. */
12099 if (inst.instruction == T_OPCODE_MOV_I8)
12100 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12101 else
c19d1205 12102 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12103
fdfde340
JM
12104 inst.instruction |= Rn;
12105 inst.instruction |= Rm << 3;
b99bd4ef
NC
12106 }
12107 else
12108 {
c19d1205
ZW
12109 if (inst.instruction == T_OPCODE_MOV_I8)
12110 inst.instruction = T_OPCODE_MOV_HR;
12111 else
12112 inst.instruction = T_OPCODE_CMP_HR;
12113 do_t_cpy ();
b99bd4ef
NC
12114 }
12115 }
c19d1205 12116 else
b99bd4ef 12117 {
fdfde340 12118 constraint (Rn > 7,
c19d1205 12119 _("only lo regs allowed with immediate"));
fdfde340 12120 inst.instruction |= Rn << 8;
c19d1205
ZW
12121 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12122 }
12123}
b99bd4ef 12124
c19d1205
ZW
12125static void
12126do_t_mov16 (void)
12127{
fdfde340 12128 unsigned Rd;
b6895b4f
PB
12129 bfd_vma imm;
12130 bfd_boolean top;
12131
12132 top = (inst.instruction & 0x00800000) != 0;
12133 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12134 {
33eaf5de 12135 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12136 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12137 }
12138 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12139 {
33eaf5de 12140 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12141 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12142 }
12143
fdfde340
JM
12144 Rd = inst.operands[0].reg;
12145 reject_bad_reg (Rd);
12146
12147 inst.instruction |= Rd << 8;
b6895b4f
PB
12148 if (inst.reloc.type == BFD_RELOC_UNUSED)
12149 {
12150 imm = inst.reloc.exp.X_add_number;
12151 inst.instruction |= (imm & 0xf000) << 4;
12152 inst.instruction |= (imm & 0x0800) << 15;
12153 inst.instruction |= (imm & 0x0700) << 4;
12154 inst.instruction |= (imm & 0x00ff);
12155 }
c19d1205 12156}
b99bd4ef 12157
c19d1205
ZW
12158static void
12159do_t_mvn_tst (void)
12160{
fdfde340 12161 unsigned Rn, Rm;
c921be7d 12162
fdfde340
JM
12163 Rn = inst.operands[0].reg;
12164 Rm = inst.operands[1].reg;
12165
12166 if (inst.instruction == T_MNEM_cmp
12167 || inst.instruction == T_MNEM_cmn)
12168 constraint (Rn == REG_PC, BAD_PC);
12169 else
12170 reject_bad_reg (Rn);
12171 reject_bad_reg (Rm);
12172
c19d1205
ZW
12173 if (unified_syntax)
12174 {
12175 int r0off = (inst.instruction == T_MNEM_mvn
12176 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12177 bfd_boolean narrow;
12178
12179 if (inst.size_req == 4
12180 || inst.instruction > 0xffff
12181 || inst.operands[1].shifted
fdfde340 12182 || Rn > 7 || Rm > 7)
3d388997 12183 narrow = FALSE;
fe8b4cc3
KT
12184 else if (inst.instruction == T_MNEM_cmn
12185 || inst.instruction == T_MNEM_tst)
3d388997
PB
12186 narrow = TRUE;
12187 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12188 narrow = !in_it_block ();
3d388997 12189 else
e07e6e58 12190 narrow = in_it_block ();
3d388997 12191
c19d1205 12192 if (!inst.operands[1].isreg)
b99bd4ef 12193 {
c19d1205
ZW
12194 /* For an immediate, we always generate a 32-bit opcode;
12195 section relaxation will shrink it later if possible. */
12196 if (inst.instruction < 0xffff)
12197 inst.instruction = THUMB_OP32 (inst.instruction);
12198 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12199 inst.instruction |= Rn << r0off;
c19d1205 12200 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12201 }
c19d1205 12202 else
b99bd4ef 12203 {
c19d1205 12204 /* See if we can do this with a 16-bit instruction. */
3d388997 12205 if (narrow)
b99bd4ef 12206 {
c19d1205 12207 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12208 inst.instruction |= Rn;
12209 inst.instruction |= Rm << 3;
b99bd4ef 12210 }
c19d1205 12211 else
b99bd4ef 12212 {
c19d1205
ZW
12213 constraint (inst.operands[1].shifted
12214 && inst.operands[1].immisreg,
12215 _("shift must be constant"));
12216 if (inst.instruction < 0xffff)
12217 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12218 inst.instruction |= Rn << r0off;
c19d1205 12219 encode_thumb32_shifted_operand (1);
b99bd4ef 12220 }
b99bd4ef
NC
12221 }
12222 }
12223 else
12224 {
c19d1205
ZW
12225 constraint (inst.instruction > 0xffff
12226 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12227 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12228 _("unshifted register required"));
fdfde340 12229 constraint (Rn > 7 || Rm > 7,
c19d1205 12230 BAD_HIREG);
b99bd4ef 12231
c19d1205 12232 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12233 inst.instruction |= Rn;
12234 inst.instruction |= Rm << 3;
b99bd4ef 12235 }
b99bd4ef
NC
12236}
12237
b05fe5cf 12238static void
c19d1205 12239do_t_mrs (void)
b05fe5cf 12240{
fdfde340 12241 unsigned Rd;
037e8744
JB
12242
12243 if (do_vfp_nsyn_mrs () == SUCCESS)
12244 return;
12245
90ec0d68
MGD
12246 Rd = inst.operands[0].reg;
12247 reject_bad_reg (Rd);
12248 inst.instruction |= Rd << 8;
12249
12250 if (inst.operands[1].isreg)
62b3e311 12251 {
90ec0d68
MGD
12252 unsigned br = inst.operands[1].reg;
12253 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12254 as_bad (_("bad register for mrs"));
12255
12256 inst.instruction |= br & (0xf << 16);
12257 inst.instruction |= (br & 0x300) >> 4;
12258 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12259 }
12260 else
12261 {
90ec0d68 12262 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12263
d2cd1205 12264 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12265 {
12266 /* PR gas/12698: The constraint is only applied for m_profile.
12267 If the user has specified -march=all, we want to ignore it as
12268 we are building for any CPU type, including non-m variants. */
823d2571
TG
12269 bfd_boolean m_profile =
12270 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12271 constraint ((flags != 0) && m_profile, _("selected processor does "
12272 "not support requested special purpose register"));
12273 }
90ec0d68 12274 else
d2cd1205
JB
12275 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12276 devices). */
12277 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12278 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12279
90ec0d68
MGD
12280 inst.instruction |= (flags & SPSR_BIT) >> 2;
12281 inst.instruction |= inst.operands[1].imm & 0xff;
12282 inst.instruction |= 0xf0000;
12283 }
c19d1205 12284}
b05fe5cf 12285
c19d1205
ZW
12286static void
12287do_t_msr (void)
12288{
62b3e311 12289 int flags;
fdfde340 12290 unsigned Rn;
62b3e311 12291
037e8744
JB
12292 if (do_vfp_nsyn_msr () == SUCCESS)
12293 return;
12294
c19d1205
ZW
12295 constraint (!inst.operands[1].isreg,
12296 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12297
12298 if (inst.operands[0].isreg)
12299 flags = (int)(inst.operands[0].reg);
12300 else
12301 flags = inst.operands[0].imm;
12302
d2cd1205 12303 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12304 {
d2cd1205
JB
12305 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12306
1a43faaf 12307 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12308 If the user has specified -march=all, we want to ignore it as
12309 we are building for any CPU type, including non-m variants. */
823d2571
TG
12310 bfd_boolean m_profile =
12311 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12312 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12313 && (bits & ~(PSR_s | PSR_f)) != 0)
12314 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12315 && bits != PSR_f)) && m_profile,
12316 _("selected processor does not support requested special "
12317 "purpose register"));
62b3e311
PB
12318 }
12319 else
d2cd1205
JB
12320 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12321 "requested special purpose register"));
c921be7d 12322
fdfde340
JM
12323 Rn = inst.operands[1].reg;
12324 reject_bad_reg (Rn);
12325
62b3e311 12326 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12327 inst.instruction |= (flags & 0xf0000) >> 8;
12328 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12329 inst.instruction |= (flags & 0xff);
fdfde340 12330 inst.instruction |= Rn << 16;
c19d1205 12331}
b05fe5cf 12332
c19d1205
ZW
12333static void
12334do_t_mul (void)
12335{
17828f45 12336 bfd_boolean narrow;
fdfde340 12337 unsigned Rd, Rn, Rm;
17828f45 12338
c19d1205
ZW
12339 if (!inst.operands[2].present)
12340 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12341
fdfde340
JM
12342 Rd = inst.operands[0].reg;
12343 Rn = inst.operands[1].reg;
12344 Rm = inst.operands[2].reg;
12345
17828f45 12346 if (unified_syntax)
b05fe5cf 12347 {
17828f45 12348 if (inst.size_req == 4
fdfde340
JM
12349 || (Rd != Rn
12350 && Rd != Rm)
12351 || Rn > 7
12352 || Rm > 7)
17828f45
JM
12353 narrow = FALSE;
12354 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12355 narrow = !in_it_block ();
17828f45 12356 else
e07e6e58 12357 narrow = in_it_block ();
b05fe5cf 12358 }
c19d1205 12359 else
b05fe5cf 12360 {
17828f45 12361 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12362 constraint (Rn > 7 || Rm > 7,
c19d1205 12363 BAD_HIREG);
17828f45
JM
12364 narrow = TRUE;
12365 }
b05fe5cf 12366
17828f45
JM
12367 if (narrow)
12368 {
12369 /* 16-bit MULS/Conditional MUL. */
c19d1205 12370 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12371 inst.instruction |= Rd;
b05fe5cf 12372
fdfde340
JM
12373 if (Rd == Rn)
12374 inst.instruction |= Rm << 3;
12375 else if (Rd == Rm)
12376 inst.instruction |= Rn << 3;
c19d1205
ZW
12377 else
12378 constraint (1, _("dest must overlap one source register"));
12379 }
17828f45
JM
12380 else
12381 {
e07e6e58
NC
12382 constraint (inst.instruction != T_MNEM_mul,
12383 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12384 /* 32-bit MUL. */
12385 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12386 inst.instruction |= Rd << 8;
12387 inst.instruction |= Rn << 16;
12388 inst.instruction |= Rm << 0;
12389
12390 reject_bad_reg (Rd);
12391 reject_bad_reg (Rn);
12392 reject_bad_reg (Rm);
17828f45 12393 }
c19d1205 12394}
b05fe5cf 12395
c19d1205
ZW
12396static void
12397do_t_mull (void)
12398{
fdfde340 12399 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12400
fdfde340
JM
12401 RdLo = inst.operands[0].reg;
12402 RdHi = inst.operands[1].reg;
12403 Rn = inst.operands[2].reg;
12404 Rm = inst.operands[3].reg;
12405
12406 reject_bad_reg (RdLo);
12407 reject_bad_reg (RdHi);
12408 reject_bad_reg (Rn);
12409 reject_bad_reg (Rm);
12410
12411 inst.instruction |= RdLo << 12;
12412 inst.instruction |= RdHi << 8;
12413 inst.instruction |= Rn << 16;
12414 inst.instruction |= Rm;
12415
12416 if (RdLo == RdHi)
c19d1205
ZW
12417 as_tsktsk (_("rdhi and rdlo must be different"));
12418}
b05fe5cf 12419
c19d1205
ZW
12420static void
12421do_t_nop (void)
12422{
e07e6e58
NC
12423 set_it_insn_type (NEUTRAL_IT_INSN);
12424
c19d1205
ZW
12425 if (unified_syntax)
12426 {
12427 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12428 {
c19d1205
ZW
12429 inst.instruction = THUMB_OP32 (inst.instruction);
12430 inst.instruction |= inst.operands[0].imm;
12431 }
12432 else
12433 {
bc2d1808
NC
12434 /* PR9722: Check for Thumb2 availability before
12435 generating a thumb2 nop instruction. */
afa62d5e 12436 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12437 {
12438 inst.instruction = THUMB_OP16 (inst.instruction);
12439 inst.instruction |= inst.operands[0].imm << 4;
12440 }
12441 else
12442 inst.instruction = 0x46c0;
c19d1205
ZW
12443 }
12444 }
12445 else
12446 {
12447 constraint (inst.operands[0].present,
12448 _("Thumb does not support NOP with hints"));
12449 inst.instruction = 0x46c0;
12450 }
12451}
b05fe5cf 12452
c19d1205
ZW
12453static void
12454do_t_neg (void)
12455{
12456 if (unified_syntax)
12457 {
3d388997
PB
12458 bfd_boolean narrow;
12459
12460 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12461 narrow = !in_it_block ();
3d388997 12462 else
e07e6e58 12463 narrow = in_it_block ();
3d388997
PB
12464 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12465 narrow = FALSE;
12466 if (inst.size_req == 4)
12467 narrow = FALSE;
12468
12469 if (!narrow)
c19d1205
ZW
12470 {
12471 inst.instruction = THUMB_OP32 (inst.instruction);
12472 inst.instruction |= inst.operands[0].reg << 8;
12473 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12474 }
12475 else
12476 {
c19d1205
ZW
12477 inst.instruction = THUMB_OP16 (inst.instruction);
12478 inst.instruction |= inst.operands[0].reg;
12479 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12480 }
12481 }
12482 else
12483 {
c19d1205
ZW
12484 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12485 BAD_HIREG);
12486 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12487
12488 inst.instruction = THUMB_OP16 (inst.instruction);
12489 inst.instruction |= inst.operands[0].reg;
12490 inst.instruction |= inst.operands[1].reg << 3;
12491 }
12492}
12493
1c444d06
JM
12494static void
12495do_t_orn (void)
12496{
12497 unsigned Rd, Rn;
12498
12499 Rd = inst.operands[0].reg;
12500 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12501
fdfde340
JM
12502 reject_bad_reg (Rd);
12503 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12504 reject_bad_reg (Rn);
12505
1c444d06
JM
12506 inst.instruction |= Rd << 8;
12507 inst.instruction |= Rn << 16;
12508
12509 if (!inst.operands[2].isreg)
12510 {
12511 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12512 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12513 }
12514 else
12515 {
12516 unsigned Rm;
12517
12518 Rm = inst.operands[2].reg;
fdfde340 12519 reject_bad_reg (Rm);
1c444d06
JM
12520
12521 constraint (inst.operands[2].shifted
12522 && inst.operands[2].immisreg,
12523 _("shift must be constant"));
12524 encode_thumb32_shifted_operand (2);
12525 }
12526}
12527
c19d1205
ZW
12528static void
12529do_t_pkhbt (void)
12530{
fdfde340
JM
12531 unsigned Rd, Rn, Rm;
12532
12533 Rd = inst.operands[0].reg;
12534 Rn = inst.operands[1].reg;
12535 Rm = inst.operands[2].reg;
12536
12537 reject_bad_reg (Rd);
12538 reject_bad_reg (Rn);
12539 reject_bad_reg (Rm);
12540
12541 inst.instruction |= Rd << 8;
12542 inst.instruction |= Rn << 16;
12543 inst.instruction |= Rm;
c19d1205
ZW
12544 if (inst.operands[3].present)
12545 {
12546 unsigned int val = inst.reloc.exp.X_add_number;
12547 constraint (inst.reloc.exp.X_op != O_constant,
12548 _("expression too complex"));
12549 inst.instruction |= (val & 0x1c) << 10;
12550 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12551 }
c19d1205 12552}
b05fe5cf 12553
c19d1205
ZW
12554static void
12555do_t_pkhtb (void)
12556{
12557 if (!inst.operands[3].present)
1ef52f49
NC
12558 {
12559 unsigned Rtmp;
12560
12561 inst.instruction &= ~0x00000020;
12562
12563 /* PR 10168. Swap the Rm and Rn registers. */
12564 Rtmp = inst.operands[1].reg;
12565 inst.operands[1].reg = inst.operands[2].reg;
12566 inst.operands[2].reg = Rtmp;
12567 }
c19d1205 12568 do_t_pkhbt ();
b05fe5cf
ZW
12569}
12570
c19d1205
ZW
12571static void
12572do_t_pld (void)
12573{
fdfde340
JM
12574 if (inst.operands[0].immisreg)
12575 reject_bad_reg (inst.operands[0].imm);
12576
c19d1205
ZW
12577 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12578}
b05fe5cf 12579
c19d1205
ZW
12580static void
12581do_t_push_pop (void)
b99bd4ef 12582{
e9f89963 12583 unsigned mask;
5f4273c7 12584
c19d1205
ZW
12585 constraint (inst.operands[0].writeback,
12586 _("push/pop do not support {reglist}^"));
12587 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12588 _("expression too complex"));
b99bd4ef 12589
e9f89963 12590 mask = inst.operands[0].imm;
d3bfe16e 12591 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12592 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12593 else if (inst.size_req != 4
c6025a80 12594 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12595 ? REG_LR : REG_PC)))
b99bd4ef 12596 {
c19d1205
ZW
12597 inst.instruction = THUMB_OP16 (inst.instruction);
12598 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12599 inst.instruction |= mask & 0xff;
c19d1205
ZW
12600 }
12601 else if (unified_syntax)
12602 {
3c707909 12603 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12604 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12605 }
12606 else
12607 {
12608 inst.error = _("invalid register list to push/pop instruction");
12609 return;
12610 }
c19d1205 12611}
b99bd4ef 12612
c19d1205
ZW
12613static void
12614do_t_rbit (void)
12615{
fdfde340
JM
12616 unsigned Rd, Rm;
12617
12618 Rd = inst.operands[0].reg;
12619 Rm = inst.operands[1].reg;
12620
12621 reject_bad_reg (Rd);
12622 reject_bad_reg (Rm);
12623
12624 inst.instruction |= Rd << 8;
12625 inst.instruction |= Rm << 16;
12626 inst.instruction |= Rm;
c19d1205 12627}
b99bd4ef 12628
c19d1205
ZW
12629static void
12630do_t_rev (void)
12631{
fdfde340
JM
12632 unsigned Rd, Rm;
12633
12634 Rd = inst.operands[0].reg;
12635 Rm = inst.operands[1].reg;
12636
12637 reject_bad_reg (Rd);
12638 reject_bad_reg (Rm);
12639
12640 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12641 && inst.size_req != 4)
12642 {
12643 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12644 inst.instruction |= Rd;
12645 inst.instruction |= Rm << 3;
c19d1205
ZW
12646 }
12647 else if (unified_syntax)
12648 {
12649 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12650 inst.instruction |= Rd << 8;
12651 inst.instruction |= Rm << 16;
12652 inst.instruction |= Rm;
c19d1205
ZW
12653 }
12654 else
12655 inst.error = BAD_HIREG;
12656}
b99bd4ef 12657
1c444d06
JM
12658static void
12659do_t_rrx (void)
12660{
12661 unsigned Rd, Rm;
12662
12663 Rd = inst.operands[0].reg;
12664 Rm = inst.operands[1].reg;
12665
fdfde340
JM
12666 reject_bad_reg (Rd);
12667 reject_bad_reg (Rm);
c921be7d 12668
1c444d06
JM
12669 inst.instruction |= Rd << 8;
12670 inst.instruction |= Rm;
12671}
12672
c19d1205
ZW
12673static void
12674do_t_rsb (void)
12675{
fdfde340 12676 unsigned Rd, Rs;
b99bd4ef 12677
c19d1205
ZW
12678 Rd = inst.operands[0].reg;
12679 Rs = (inst.operands[1].present
12680 ? inst.operands[1].reg /* Rd, Rs, foo */
12681 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12682
fdfde340
JM
12683 reject_bad_reg (Rd);
12684 reject_bad_reg (Rs);
12685 if (inst.operands[2].isreg)
12686 reject_bad_reg (inst.operands[2].reg);
12687
c19d1205
ZW
12688 inst.instruction |= Rd << 8;
12689 inst.instruction |= Rs << 16;
12690 if (!inst.operands[2].isreg)
12691 {
026d3abb
PB
12692 bfd_boolean narrow;
12693
12694 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12695 narrow = !in_it_block ();
026d3abb 12696 else
e07e6e58 12697 narrow = in_it_block ();
026d3abb
PB
12698
12699 if (Rd > 7 || Rs > 7)
12700 narrow = FALSE;
12701
12702 if (inst.size_req == 4 || !unified_syntax)
12703 narrow = FALSE;
12704
12705 if (inst.reloc.exp.X_op != O_constant
12706 || inst.reloc.exp.X_add_number != 0)
12707 narrow = FALSE;
12708
12709 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12710 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12711 if (narrow)
12712 {
12713 inst.reloc.type = BFD_RELOC_UNUSED;
12714 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12715 inst.instruction |= Rs << 3;
12716 inst.instruction |= Rd;
12717 }
12718 else
12719 {
12720 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12721 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12722 }
c19d1205
ZW
12723 }
12724 else
12725 encode_thumb32_shifted_operand (2);
12726}
b99bd4ef 12727
c19d1205
ZW
12728static void
12729do_t_setend (void)
12730{
12e37cbc
MGD
12731 if (warn_on_deprecated
12732 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12733 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12734
e07e6e58 12735 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12736 if (inst.operands[0].imm)
12737 inst.instruction |= 0x8;
12738}
b99bd4ef 12739
c19d1205
ZW
12740static void
12741do_t_shift (void)
12742{
12743 if (!inst.operands[1].present)
12744 inst.operands[1].reg = inst.operands[0].reg;
12745
12746 if (unified_syntax)
12747 {
3d388997
PB
12748 bfd_boolean narrow;
12749 int shift_kind;
12750
12751 switch (inst.instruction)
12752 {
12753 case T_MNEM_asr:
12754 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12755 case T_MNEM_lsl:
12756 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12757 case T_MNEM_lsr:
12758 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12759 case T_MNEM_ror:
12760 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12761 default: abort ();
12762 }
12763
12764 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12765 narrow = !in_it_block ();
3d388997 12766 else
e07e6e58 12767 narrow = in_it_block ();
3d388997
PB
12768 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12769 narrow = FALSE;
12770 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12771 narrow = FALSE;
12772 if (inst.operands[2].isreg
12773 && (inst.operands[1].reg != inst.operands[0].reg
12774 || inst.operands[2].reg > 7))
12775 narrow = FALSE;
12776 if (inst.size_req == 4)
12777 narrow = FALSE;
12778
fdfde340
JM
12779 reject_bad_reg (inst.operands[0].reg);
12780 reject_bad_reg (inst.operands[1].reg);
c921be7d 12781
3d388997 12782 if (!narrow)
c19d1205
ZW
12783 {
12784 if (inst.operands[2].isreg)
b99bd4ef 12785 {
fdfde340 12786 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12787 inst.instruction = THUMB_OP32 (inst.instruction);
12788 inst.instruction |= inst.operands[0].reg << 8;
12789 inst.instruction |= inst.operands[1].reg << 16;
12790 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12791
12792 /* PR 12854: Error on extraneous shifts. */
12793 constraint (inst.operands[2].shifted,
12794 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12795 }
12796 else
12797 {
12798 inst.operands[1].shifted = 1;
3d388997 12799 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12800 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12801 ? T_MNEM_movs : T_MNEM_mov);
12802 inst.instruction |= inst.operands[0].reg << 8;
12803 encode_thumb32_shifted_operand (1);
12804 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12805 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12806 }
12807 }
12808 else
12809 {
c19d1205 12810 if (inst.operands[2].isreg)
b99bd4ef 12811 {
3d388997 12812 switch (shift_kind)
b99bd4ef 12813 {
3d388997
PB
12814 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12815 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12816 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12817 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12818 default: abort ();
b99bd4ef 12819 }
5f4273c7 12820
c19d1205
ZW
12821 inst.instruction |= inst.operands[0].reg;
12822 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12823
12824 /* PR 12854: Error on extraneous shifts. */
12825 constraint (inst.operands[2].shifted,
12826 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12827 }
12828 else
12829 {
3d388997 12830 switch (shift_kind)
b99bd4ef 12831 {
3d388997
PB
12832 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12833 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12834 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12835 default: abort ();
b99bd4ef 12836 }
c19d1205
ZW
12837 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12838 inst.instruction |= inst.operands[0].reg;
12839 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12840 }
12841 }
c19d1205
ZW
12842 }
12843 else
12844 {
12845 constraint (inst.operands[0].reg > 7
12846 || inst.operands[1].reg > 7, BAD_HIREG);
12847 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12848
c19d1205
ZW
12849 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12850 {
12851 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12852 constraint (inst.operands[0].reg != inst.operands[1].reg,
12853 _("source1 and dest must be same register"));
b99bd4ef 12854
c19d1205
ZW
12855 switch (inst.instruction)
12856 {
12857 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12858 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12859 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12860 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12861 default: abort ();
12862 }
5f4273c7 12863
c19d1205
ZW
12864 inst.instruction |= inst.operands[0].reg;
12865 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12866
12867 /* PR 12854: Error on extraneous shifts. */
12868 constraint (inst.operands[2].shifted,
12869 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12870 }
12871 else
b99bd4ef 12872 {
c19d1205
ZW
12873 switch (inst.instruction)
12874 {
12875 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12876 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12877 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12878 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12879 default: abort ();
12880 }
12881 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12882 inst.instruction |= inst.operands[0].reg;
12883 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12884 }
12885 }
b99bd4ef
NC
12886}
12887
12888static void
c19d1205 12889do_t_simd (void)
b99bd4ef 12890{
fdfde340
JM
12891 unsigned Rd, Rn, Rm;
12892
12893 Rd = inst.operands[0].reg;
12894 Rn = inst.operands[1].reg;
12895 Rm = inst.operands[2].reg;
12896
12897 reject_bad_reg (Rd);
12898 reject_bad_reg (Rn);
12899 reject_bad_reg (Rm);
12900
12901 inst.instruction |= Rd << 8;
12902 inst.instruction |= Rn << 16;
12903 inst.instruction |= Rm;
c19d1205 12904}
b99bd4ef 12905
03ee1b7f
NC
12906static void
12907do_t_simd2 (void)
12908{
12909 unsigned Rd, Rn, Rm;
12910
12911 Rd = inst.operands[0].reg;
12912 Rm = inst.operands[1].reg;
12913 Rn = inst.operands[2].reg;
12914
12915 reject_bad_reg (Rd);
12916 reject_bad_reg (Rn);
12917 reject_bad_reg (Rm);
12918
12919 inst.instruction |= Rd << 8;
12920 inst.instruction |= Rn << 16;
12921 inst.instruction |= Rm;
12922}
12923
c19d1205 12924static void
3eb17e6b 12925do_t_smc (void)
c19d1205
ZW
12926{
12927 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12928 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12929 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12930 constraint (inst.reloc.exp.X_op != O_constant,
12931 _("expression too complex"));
12932 inst.reloc.type = BFD_RELOC_UNUSED;
12933 inst.instruction |= (value & 0xf000) >> 12;
12934 inst.instruction |= (value & 0x0ff0);
12935 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12936 /* PR gas/15623: SMC instructions must be last in an IT block. */
12937 set_it_insn_type_last ();
c19d1205 12938}
b99bd4ef 12939
90ec0d68
MGD
12940static void
12941do_t_hvc (void)
12942{
12943 unsigned int value = inst.reloc.exp.X_add_number;
12944
12945 inst.reloc.type = BFD_RELOC_UNUSED;
12946 inst.instruction |= (value & 0x0fff);
12947 inst.instruction |= (value & 0xf000) << 4;
12948}
12949
c19d1205 12950static void
3a21c15a 12951do_t_ssat_usat (int bias)
c19d1205 12952{
fdfde340
JM
12953 unsigned Rd, Rn;
12954
12955 Rd = inst.operands[0].reg;
12956 Rn = inst.operands[2].reg;
12957
12958 reject_bad_reg (Rd);
12959 reject_bad_reg (Rn);
12960
12961 inst.instruction |= Rd << 8;
3a21c15a 12962 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12963 inst.instruction |= Rn << 16;
b99bd4ef 12964
c19d1205 12965 if (inst.operands[3].present)
b99bd4ef 12966 {
3a21c15a
NC
12967 offsetT shift_amount = inst.reloc.exp.X_add_number;
12968
12969 inst.reloc.type = BFD_RELOC_UNUSED;
12970
c19d1205
ZW
12971 constraint (inst.reloc.exp.X_op != O_constant,
12972 _("expression too complex"));
b99bd4ef 12973
3a21c15a 12974 if (shift_amount != 0)
6189168b 12975 {
3a21c15a
NC
12976 constraint (shift_amount > 31,
12977 _("shift expression is too large"));
12978
c19d1205 12979 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12980 inst.instruction |= 0x00200000; /* sh bit. */
12981
12982 inst.instruction |= (shift_amount & 0x1c) << 10;
12983 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12984 }
12985 }
b99bd4ef 12986}
c921be7d 12987
3a21c15a
NC
12988static void
12989do_t_ssat (void)
12990{
12991 do_t_ssat_usat (1);
12992}
b99bd4ef 12993
0dd132b6 12994static void
c19d1205 12995do_t_ssat16 (void)
0dd132b6 12996{
fdfde340
JM
12997 unsigned Rd, Rn;
12998
12999 Rd = inst.operands[0].reg;
13000 Rn = inst.operands[2].reg;
13001
13002 reject_bad_reg (Rd);
13003 reject_bad_reg (Rn);
13004
13005 inst.instruction |= Rd << 8;
c19d1205 13006 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13007 inst.instruction |= Rn << 16;
c19d1205 13008}
0dd132b6 13009
c19d1205
ZW
13010static void
13011do_t_strex (void)
13012{
13013 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13014 || inst.operands[2].postind || inst.operands[2].writeback
13015 || inst.operands[2].immisreg || inst.operands[2].shifted
13016 || inst.operands[2].negative,
01cfc07f 13017 BAD_ADDR_MODE);
0dd132b6 13018
5be8be5d
DG
13019 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13020
c19d1205
ZW
13021 inst.instruction |= inst.operands[0].reg << 8;
13022 inst.instruction |= inst.operands[1].reg << 12;
13023 inst.instruction |= inst.operands[2].reg << 16;
13024 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13025}
13026
b99bd4ef 13027static void
c19d1205 13028do_t_strexd (void)
b99bd4ef 13029{
c19d1205
ZW
13030 if (!inst.operands[2].present)
13031 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13032
c19d1205
ZW
13033 constraint (inst.operands[0].reg == inst.operands[1].reg
13034 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13035 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13036 BAD_OVERLAP);
b99bd4ef 13037
c19d1205
ZW
13038 inst.instruction |= inst.operands[0].reg;
13039 inst.instruction |= inst.operands[1].reg << 12;
13040 inst.instruction |= inst.operands[2].reg << 8;
13041 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13042}
13043
13044static void
c19d1205 13045do_t_sxtah (void)
b99bd4ef 13046{
fdfde340
JM
13047 unsigned Rd, Rn, Rm;
13048
13049 Rd = inst.operands[0].reg;
13050 Rn = inst.operands[1].reg;
13051 Rm = inst.operands[2].reg;
13052
13053 reject_bad_reg (Rd);
13054 reject_bad_reg (Rn);
13055 reject_bad_reg (Rm);
13056
13057 inst.instruction |= Rd << 8;
13058 inst.instruction |= Rn << 16;
13059 inst.instruction |= Rm;
c19d1205
ZW
13060 inst.instruction |= inst.operands[3].imm << 4;
13061}
b99bd4ef 13062
c19d1205
ZW
13063static void
13064do_t_sxth (void)
13065{
fdfde340
JM
13066 unsigned Rd, Rm;
13067
13068 Rd = inst.operands[0].reg;
13069 Rm = inst.operands[1].reg;
13070
13071 reject_bad_reg (Rd);
13072 reject_bad_reg (Rm);
c921be7d
NC
13073
13074 if (inst.instruction <= 0xffff
13075 && inst.size_req != 4
fdfde340 13076 && Rd <= 7 && Rm <= 7
c19d1205 13077 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13078 {
c19d1205 13079 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13080 inst.instruction |= Rd;
13081 inst.instruction |= Rm << 3;
b99bd4ef 13082 }
c19d1205 13083 else if (unified_syntax)
b99bd4ef 13084 {
c19d1205
ZW
13085 if (inst.instruction <= 0xffff)
13086 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13087 inst.instruction |= Rd << 8;
13088 inst.instruction |= Rm;
c19d1205 13089 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13090 }
c19d1205 13091 else
b99bd4ef 13092 {
c19d1205
ZW
13093 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13094 _("Thumb encoding does not support rotation"));
13095 constraint (1, BAD_HIREG);
b99bd4ef 13096 }
c19d1205 13097}
b99bd4ef 13098
c19d1205
ZW
13099static void
13100do_t_swi (void)
13101{
b2a5fbdc
MGD
13102 /* We have to do the following check manually as ARM_EXT_OS only applies
13103 to ARM_EXT_V6M. */
13104 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13105 {
ac7f631b 13106 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
2b0f3761 13107 /* This only applies to the v6m however, not later architectures. */
ac7f631b 13108 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13109 as_bad (_("SVC is not permitted on this architecture"));
13110 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13111 }
13112
c19d1205
ZW
13113 inst.reloc.type = BFD_RELOC_ARM_SWI;
13114}
b99bd4ef 13115
92e90b6e
PB
13116static void
13117do_t_tb (void)
13118{
fdfde340 13119 unsigned Rn, Rm;
92e90b6e
PB
13120 int half;
13121
13122 half = (inst.instruction & 0x10) != 0;
e07e6e58 13123 set_it_insn_type_last ();
dfa9f0d5
PB
13124 constraint (inst.operands[0].immisreg,
13125 _("instruction requires register index"));
fdfde340
JM
13126
13127 Rn = inst.operands[0].reg;
13128 Rm = inst.operands[0].imm;
c921be7d 13129
fdfde340
JM
13130 constraint (Rn == REG_SP, BAD_SP);
13131 reject_bad_reg (Rm);
13132
92e90b6e
PB
13133 constraint (!half && inst.operands[0].shifted,
13134 _("instruction does not allow shifted index"));
fdfde340 13135 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13136}
13137
74db7efb
NC
13138static void
13139do_t_udf (void)
13140{
13141 if (!inst.operands[0].present)
13142 inst.operands[0].imm = 0;
13143
13144 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13145 {
13146 constraint (inst.size_req == 2,
13147 _("immediate value out of range"));
13148 inst.instruction = THUMB_OP32 (inst.instruction);
13149 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13150 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13151 }
13152 else
13153 {
13154 inst.instruction = THUMB_OP16 (inst.instruction);
13155 inst.instruction |= inst.operands[0].imm;
13156 }
13157
13158 set_it_insn_type (NEUTRAL_IT_INSN);
13159}
13160
13161
c19d1205
ZW
13162static void
13163do_t_usat (void)
13164{
3a21c15a 13165 do_t_ssat_usat (0);
b99bd4ef
NC
13166}
13167
13168static void
c19d1205 13169do_t_usat16 (void)
b99bd4ef 13170{
fdfde340
JM
13171 unsigned Rd, Rn;
13172
13173 Rd = inst.operands[0].reg;
13174 Rn = inst.operands[2].reg;
13175
13176 reject_bad_reg (Rd);
13177 reject_bad_reg (Rn);
13178
13179 inst.instruction |= Rd << 8;
c19d1205 13180 inst.instruction |= inst.operands[1].imm;
fdfde340 13181 inst.instruction |= Rn << 16;
b99bd4ef 13182}
c19d1205 13183
5287ad62 13184/* Neon instruction encoder helpers. */
5f4273c7 13185
5287ad62 13186/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13187
5287ad62
JB
13188/* An "invalid" code for the following tables. */
13189#define N_INV -1u
13190
13191struct neon_tab_entry
b99bd4ef 13192{
5287ad62
JB
13193 unsigned integer;
13194 unsigned float_or_poly;
13195 unsigned scalar_or_imm;
13196};
5f4273c7 13197
5287ad62
JB
13198/* Map overloaded Neon opcodes to their respective encodings. */
13199#define NEON_ENC_TAB \
13200 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13201 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13202 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13203 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13204 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13205 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13206 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13207 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13208 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13209 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13210 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13211 /* Register variants of the following two instructions are encoded as
e07e6e58 13212 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13213 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13214 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13215 X(vfma, N_INV, 0x0000c10, N_INV), \
13216 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13217 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13218 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13219 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13220 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13221 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13222 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13223 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13224 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13225 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13226 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13227 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13228 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13229 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13230 X(vshl, 0x0000400, N_INV, 0x0800510), \
13231 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13232 X(vand, 0x0000110, N_INV, 0x0800030), \
13233 X(vbic, 0x0100110, N_INV, 0x0800030), \
13234 X(veor, 0x1000110, N_INV, N_INV), \
13235 X(vorn, 0x0300110, N_INV, 0x0800010), \
13236 X(vorr, 0x0200110, N_INV, 0x0800010), \
13237 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13238 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13239 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13240 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13241 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13242 X(vst1, 0x0000000, 0x0800000, N_INV), \
13243 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13244 X(vst2, 0x0000100, 0x0800100, N_INV), \
13245 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13246 X(vst3, 0x0000200, 0x0800200, N_INV), \
13247 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13248 X(vst4, 0x0000300, 0x0800300, N_INV), \
13249 X(vmovn, 0x1b20200, N_INV, N_INV), \
13250 X(vtrn, 0x1b20080, N_INV, N_INV), \
13251 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13252 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13253 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13254 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13255 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13256 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13257 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13258 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13259 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13260 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13261 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13262 X(vseleq, 0xe000a00, N_INV, N_INV), \
13263 X(vselvs, 0xe100a00, N_INV, N_INV), \
13264 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13265 X(vselgt, 0xe300a00, N_INV, N_INV), \
13266 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13267 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13268 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13269 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13270 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13271 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13272 X(sha3op, 0x2000c00, N_INV, N_INV), \
13273 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13274 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13275
13276enum neon_opc
13277{
13278#define X(OPC,I,F,S) N_MNEM_##OPC
13279NEON_ENC_TAB
13280#undef X
13281};
b99bd4ef 13282
5287ad62
JB
13283static const struct neon_tab_entry neon_enc_tab[] =
13284{
13285#define X(OPC,I,F,S) { (I), (F), (S) }
13286NEON_ENC_TAB
13287#undef X
13288};
b99bd4ef 13289
88714cb8
DG
13290/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13291#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13292#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13293#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13294#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13295#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13296#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13297#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13298#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13299#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13300#define NEON_ENC_SINGLE_(X) \
037e8744 13301 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13302#define NEON_ENC_DOUBLE_(X) \
037e8744 13303 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13304#define NEON_ENC_FPV8_(X) \
13305 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13306
88714cb8
DG
13307#define NEON_ENCODE(type, inst) \
13308 do \
13309 { \
13310 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13311 inst.is_neon = 1; \
13312 } \
13313 while (0)
13314
13315#define check_neon_suffixes \
13316 do \
13317 { \
13318 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13319 { \
13320 as_bad (_("invalid neon suffix for non neon instruction")); \
13321 return; \
13322 } \
13323 } \
13324 while (0)
13325
037e8744
JB
13326/* Define shapes for instruction operands. The following mnemonic characters
13327 are used in this table:
5287ad62 13328
037e8744 13329 F - VFP S<n> register
5287ad62
JB
13330 D - Neon D<n> register
13331 Q - Neon Q<n> register
13332 I - Immediate
13333 S - Scalar
13334 R - ARM register
13335 L - D<n> register list
5f4273c7 13336
037e8744
JB
13337 This table is used to generate various data:
13338 - enumerations of the form NS_DDR to be used as arguments to
13339 neon_select_shape.
13340 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13341 - a table used to drive neon_select_shape. */
b99bd4ef 13342
037e8744
JB
13343#define NEON_SHAPE_DEF \
13344 X(3, (D, D, D), DOUBLE), \
13345 X(3, (Q, Q, Q), QUAD), \
13346 X(3, (D, D, I), DOUBLE), \
13347 X(3, (Q, Q, I), QUAD), \
13348 X(3, (D, D, S), DOUBLE), \
13349 X(3, (Q, Q, S), QUAD), \
13350 X(2, (D, D), DOUBLE), \
13351 X(2, (Q, Q), QUAD), \
13352 X(2, (D, S), DOUBLE), \
13353 X(2, (Q, S), QUAD), \
13354 X(2, (D, R), DOUBLE), \
13355 X(2, (Q, R), QUAD), \
13356 X(2, (D, I), DOUBLE), \
13357 X(2, (Q, I), QUAD), \
13358 X(3, (D, L, D), DOUBLE), \
13359 X(2, (D, Q), MIXED), \
13360 X(2, (Q, D), MIXED), \
13361 X(3, (D, Q, I), MIXED), \
13362 X(3, (Q, D, I), MIXED), \
13363 X(3, (Q, D, D), MIXED), \
13364 X(3, (D, Q, Q), MIXED), \
13365 X(3, (Q, Q, D), MIXED), \
13366 X(3, (Q, D, S), MIXED), \
13367 X(3, (D, Q, S), MIXED), \
13368 X(4, (D, D, D, I), DOUBLE), \
13369 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13370 X(4, (D, D, S, I), DOUBLE), \
13371 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13372 X(2, (F, F), SINGLE), \
13373 X(3, (F, F, F), SINGLE), \
13374 X(2, (F, I), SINGLE), \
13375 X(2, (F, D), MIXED), \
13376 X(2, (D, F), MIXED), \
13377 X(3, (F, F, I), MIXED), \
13378 X(4, (R, R, F, F), SINGLE), \
13379 X(4, (F, F, R, R), SINGLE), \
13380 X(3, (D, R, R), DOUBLE), \
13381 X(3, (R, R, D), DOUBLE), \
13382 X(2, (S, R), SINGLE), \
13383 X(2, (R, S), SINGLE), \
13384 X(2, (F, R), SINGLE), \
d54af2d0
RL
13385 X(2, (R, F), SINGLE), \
13386/* Half float shape supported so far. */\
13387 X (2, (H, D), MIXED), \
13388 X (2, (D, H), MIXED), \
13389 X (2, (H, F), MIXED), \
13390 X (2, (F, H), MIXED), \
13391 X (2, (H, H), HALF), \
13392 X (2, (H, R), HALF), \
13393 X (2, (R, H), HALF), \
13394 X (2, (H, I), HALF), \
13395 X (3, (H, H, H), HALF), \
13396 X (3, (H, F, I), MIXED), \
13397 X (3, (F, H, I), MIXED)
037e8744
JB
13398
13399#define S2(A,B) NS_##A##B
13400#define S3(A,B,C) NS_##A##B##C
13401#define S4(A,B,C,D) NS_##A##B##C##D
13402
13403#define X(N, L, C) S##N L
13404
5287ad62
JB
13405enum neon_shape
13406{
037e8744
JB
13407 NEON_SHAPE_DEF,
13408 NS_NULL
5287ad62 13409};
b99bd4ef 13410
037e8744
JB
13411#undef X
13412#undef S2
13413#undef S3
13414#undef S4
13415
13416enum neon_shape_class
13417{
d54af2d0 13418 SC_HALF,
037e8744
JB
13419 SC_SINGLE,
13420 SC_DOUBLE,
13421 SC_QUAD,
13422 SC_MIXED
13423};
13424
13425#define X(N, L, C) SC_##C
13426
13427static enum neon_shape_class neon_shape_class[] =
13428{
13429 NEON_SHAPE_DEF
13430};
13431
13432#undef X
13433
13434enum neon_shape_el
13435{
d54af2d0 13436 SE_H,
037e8744
JB
13437 SE_F,
13438 SE_D,
13439 SE_Q,
13440 SE_I,
13441 SE_S,
13442 SE_R,
13443 SE_L
13444};
13445
13446/* Register widths of above. */
13447static unsigned neon_shape_el_size[] =
13448{
d54af2d0 13449 16,
037e8744
JB
13450 32,
13451 64,
13452 128,
13453 0,
13454 32,
13455 32,
13456 0
13457};
13458
13459struct neon_shape_info
13460{
13461 unsigned els;
13462 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13463};
13464
13465#define S2(A,B) { SE_##A, SE_##B }
13466#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13467#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13468
13469#define X(N, L, C) { N, S##N L }
13470
13471static struct neon_shape_info neon_shape_tab[] =
13472{
13473 NEON_SHAPE_DEF
13474};
13475
13476#undef X
13477#undef S2
13478#undef S3
13479#undef S4
13480
5287ad62
JB
13481/* Bit masks used in type checking given instructions.
13482 'N_EQK' means the type must be the same as (or based on in some way) the key
13483 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13484 set, various other bits can be set as well in order to modify the meaning of
13485 the type constraint. */
13486
13487enum neon_type_mask
13488{
8e79c3df
CM
13489 N_S8 = 0x0000001,
13490 N_S16 = 0x0000002,
13491 N_S32 = 0x0000004,
13492 N_S64 = 0x0000008,
13493 N_U8 = 0x0000010,
13494 N_U16 = 0x0000020,
13495 N_U32 = 0x0000040,
13496 N_U64 = 0x0000080,
13497 N_I8 = 0x0000100,
13498 N_I16 = 0x0000200,
13499 N_I32 = 0x0000400,
13500 N_I64 = 0x0000800,
13501 N_8 = 0x0001000,
13502 N_16 = 0x0002000,
13503 N_32 = 0x0004000,
13504 N_64 = 0x0008000,
13505 N_P8 = 0x0010000,
13506 N_P16 = 0x0020000,
13507 N_F16 = 0x0040000,
13508 N_F32 = 0x0080000,
13509 N_F64 = 0x0100000,
4f51b4bd 13510 N_P64 = 0x0200000,
c921be7d
NC
13511 N_KEY = 0x1000000, /* Key element (main type specifier). */
13512 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13513 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13514 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13515 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13516 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13517 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13518 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13519 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13520 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13521 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13522 N_UTYP = 0,
4f51b4bd 13523 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13524};
13525
dcbf9037
JB
13526#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13527
5287ad62
JB
13528#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13529#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13530#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13531#define N_S_32 (N_S8 | N_S16 | N_S32)
13532#define N_F_16_32 (N_F16 | N_F32)
13533#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13534#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13535#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13536#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13537
13538/* Pass this as the first type argument to neon_check_type to ignore types
13539 altogether. */
13540#define N_IGNORE_TYPE (N_KEY | N_EQK)
13541
037e8744
JB
13542/* Select a "shape" for the current instruction (describing register types or
13543 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13544 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13545 function of operand parsing, so this function doesn't need to be called.
13546 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13547
13548static enum neon_shape
037e8744 13549neon_select_shape (enum neon_shape shape, ...)
5287ad62 13550{
037e8744
JB
13551 va_list ap;
13552 enum neon_shape first_shape = shape;
5287ad62
JB
13553
13554 /* Fix missing optional operands. FIXME: we don't know at this point how
13555 many arguments we should have, so this makes the assumption that we have
13556 > 1. This is true of all current Neon opcodes, I think, but may not be
13557 true in the future. */
13558 if (!inst.operands[1].present)
13559 inst.operands[1] = inst.operands[0];
13560
037e8744 13561 va_start (ap, shape);
5f4273c7 13562
21d799b5 13563 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13564 {
13565 unsigned j;
13566 int matches = 1;
13567
13568 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13569 {
13570 if (!inst.operands[j].present)
13571 {
13572 matches = 0;
13573 break;
13574 }
13575
13576 switch (neon_shape_tab[shape].el[j])
13577 {
d54af2d0
RL
13578 /* If a .f16, .16, .u16, .s16 type specifier is given over
13579 a VFP single precision register operand, it's essentially
13580 means only half of the register is used.
13581
13582 If the type specifier is given after the mnemonics, the
13583 information is stored in inst.vectype. If the type specifier
13584 is given after register operand, the information is stored
13585 in inst.operands[].vectype.
13586
13587 When there is only one type specifier, and all the register
13588 operands are the same type of hardware register, the type
13589 specifier applies to all register operands.
13590
13591 If no type specifier is given, the shape is inferred from
13592 operand information.
13593
13594 for example:
13595 vadd.f16 s0, s1, s2: NS_HHH
13596 vabs.f16 s0, s1: NS_HH
13597 vmov.f16 s0, r1: NS_HR
13598 vmov.f16 r0, s1: NS_RH
13599 vcvt.f16 r0, s1: NS_RH
13600 vcvt.f16.s32 s2, s2, #29: NS_HFI
13601 vcvt.f16.s32 s2, s2: NS_HF
13602 */
13603 case SE_H:
13604 if (!(inst.operands[j].isreg
13605 && inst.operands[j].isvec
13606 && inst.operands[j].issingle
13607 && !inst.operands[j].isquad
13608 && ((inst.vectype.elems == 1
13609 && inst.vectype.el[0].size == 16)
13610 || (inst.vectype.elems > 1
13611 && inst.vectype.el[j].size == 16)
13612 || (inst.vectype.elems == 0
13613 && inst.operands[j].vectype.type != NT_invtype
13614 && inst.operands[j].vectype.size == 16))))
13615 matches = 0;
13616 break;
13617
477330fc
RM
13618 case SE_F:
13619 if (!(inst.operands[j].isreg
13620 && inst.operands[j].isvec
13621 && inst.operands[j].issingle
d54af2d0
RL
13622 && !inst.operands[j].isquad
13623 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13624 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13625 || (inst.vectype.elems == 0
13626 && (inst.operands[j].vectype.size == 32
13627 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13628 matches = 0;
13629 break;
13630
13631 case SE_D:
13632 if (!(inst.operands[j].isreg
13633 && inst.operands[j].isvec
13634 && !inst.operands[j].isquad
13635 && !inst.operands[j].issingle))
13636 matches = 0;
13637 break;
13638
13639 case SE_R:
13640 if (!(inst.operands[j].isreg
13641 && !inst.operands[j].isvec))
13642 matches = 0;
13643 break;
13644
13645 case SE_Q:
13646 if (!(inst.operands[j].isreg
13647 && inst.operands[j].isvec
13648 && inst.operands[j].isquad
13649 && !inst.operands[j].issingle))
13650 matches = 0;
13651 break;
13652
13653 case SE_I:
13654 if (!(!inst.operands[j].isreg
13655 && !inst.operands[j].isscalar))
13656 matches = 0;
13657 break;
13658
13659 case SE_S:
13660 if (!(!inst.operands[j].isreg
13661 && inst.operands[j].isscalar))
13662 matches = 0;
13663 break;
13664
13665 case SE_L:
13666 break;
13667 }
3fde54a2
JZ
13668 if (!matches)
13669 break;
477330fc 13670 }
ad6cec43
MGD
13671 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13672 /* We've matched all the entries in the shape table, and we don't
13673 have any left over operands which have not been matched. */
477330fc 13674 break;
037e8744 13675 }
5f4273c7 13676
037e8744 13677 va_end (ap);
5287ad62 13678
037e8744
JB
13679 if (shape == NS_NULL && first_shape != NS_NULL)
13680 first_error (_("invalid instruction shape"));
5287ad62 13681
037e8744
JB
13682 return shape;
13683}
5287ad62 13684
037e8744
JB
13685/* True if SHAPE is predominantly a quadword operation (most of the time, this
13686 means the Q bit should be set). */
13687
13688static int
13689neon_quad (enum neon_shape shape)
13690{
13691 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13692}
037e8744 13693
5287ad62
JB
13694static void
13695neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13696 unsigned *g_size)
5287ad62
JB
13697{
13698 /* Allow modification to be made to types which are constrained to be
13699 based on the key element, based on bits set alongside N_EQK. */
13700 if ((typebits & N_EQK) != 0)
13701 {
13702 if ((typebits & N_HLF) != 0)
13703 *g_size /= 2;
13704 else if ((typebits & N_DBL) != 0)
13705 *g_size *= 2;
13706 if ((typebits & N_SGN) != 0)
13707 *g_type = NT_signed;
13708 else if ((typebits & N_UNS) != 0)
477330fc 13709 *g_type = NT_unsigned;
5287ad62 13710 else if ((typebits & N_INT) != 0)
477330fc 13711 *g_type = NT_integer;
5287ad62 13712 else if ((typebits & N_FLT) != 0)
477330fc 13713 *g_type = NT_float;
dcbf9037 13714 else if ((typebits & N_SIZ) != 0)
477330fc 13715 *g_type = NT_untyped;
5287ad62
JB
13716 }
13717}
5f4273c7 13718
5287ad62
JB
13719/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13720 operand type, i.e. the single type specified in a Neon instruction when it
13721 is the only one given. */
13722
13723static struct neon_type_el
13724neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13725{
13726 struct neon_type_el dest = *key;
5f4273c7 13727
9c2799c2 13728 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13729
5287ad62
JB
13730 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13731
13732 return dest;
13733}
13734
13735/* Convert Neon type and size into compact bitmask representation. */
13736
13737static enum neon_type_mask
13738type_chk_of_el_type (enum neon_el_type type, unsigned size)
13739{
13740 switch (type)
13741 {
13742 case NT_untyped:
13743 switch (size)
477330fc
RM
13744 {
13745 case 8: return N_8;
13746 case 16: return N_16;
13747 case 32: return N_32;
13748 case 64: return N_64;
13749 default: ;
13750 }
5287ad62
JB
13751 break;
13752
13753 case NT_integer:
13754 switch (size)
477330fc
RM
13755 {
13756 case 8: return N_I8;
13757 case 16: return N_I16;
13758 case 32: return N_I32;
13759 case 64: return N_I64;
13760 default: ;
13761 }
5287ad62
JB
13762 break;
13763
13764 case NT_float:
037e8744 13765 switch (size)
477330fc 13766 {
8e79c3df 13767 case 16: return N_F16;
477330fc
RM
13768 case 32: return N_F32;
13769 case 64: return N_F64;
13770 default: ;
13771 }
5287ad62
JB
13772 break;
13773
13774 case NT_poly:
13775 switch (size)
477330fc
RM
13776 {
13777 case 8: return N_P8;
13778 case 16: return N_P16;
4f51b4bd 13779 case 64: return N_P64;
477330fc
RM
13780 default: ;
13781 }
5287ad62
JB
13782 break;
13783
13784 case NT_signed:
13785 switch (size)
477330fc
RM
13786 {
13787 case 8: return N_S8;
13788 case 16: return N_S16;
13789 case 32: return N_S32;
13790 case 64: return N_S64;
13791 default: ;
13792 }
5287ad62
JB
13793 break;
13794
13795 case NT_unsigned:
13796 switch (size)
477330fc
RM
13797 {
13798 case 8: return N_U8;
13799 case 16: return N_U16;
13800 case 32: return N_U32;
13801 case 64: return N_U64;
13802 default: ;
13803 }
5287ad62
JB
13804 break;
13805
13806 default: ;
13807 }
5f4273c7 13808
5287ad62
JB
13809 return N_UTYP;
13810}
13811
13812/* Convert compact Neon bitmask type representation to a type and size. Only
13813 handles the case where a single bit is set in the mask. */
13814
dcbf9037 13815static int
5287ad62 13816el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13817 enum neon_type_mask mask)
5287ad62 13818{
dcbf9037
JB
13819 if ((mask & N_EQK) != 0)
13820 return FAIL;
13821
5287ad62
JB
13822 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13823 *size = 8;
c70a8987 13824 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13825 *size = 16;
dcbf9037 13826 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13827 *size = 32;
4f51b4bd 13828 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13829 *size = 64;
dcbf9037
JB
13830 else
13831 return FAIL;
13832
5287ad62
JB
13833 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13834 *type = NT_signed;
dcbf9037 13835 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13836 *type = NT_unsigned;
dcbf9037 13837 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13838 *type = NT_integer;
dcbf9037 13839 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13840 *type = NT_untyped;
4f51b4bd 13841 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13842 *type = NT_poly;
d54af2d0 13843 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13844 *type = NT_float;
dcbf9037
JB
13845 else
13846 return FAIL;
5f4273c7 13847
dcbf9037 13848 return SUCCESS;
5287ad62
JB
13849}
13850
13851/* Modify a bitmask of allowed types. This is only needed for type
13852 relaxation. */
13853
13854static unsigned
13855modify_types_allowed (unsigned allowed, unsigned mods)
13856{
13857 unsigned size;
13858 enum neon_el_type type;
13859 unsigned destmask;
13860 int i;
5f4273c7 13861
5287ad62 13862 destmask = 0;
5f4273c7 13863
5287ad62
JB
13864 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13865 {
21d799b5 13866 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13867 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13868 {
13869 neon_modify_type_size (mods, &type, &size);
13870 destmask |= type_chk_of_el_type (type, size);
13871 }
5287ad62 13872 }
5f4273c7 13873
5287ad62
JB
13874 return destmask;
13875}
13876
13877/* Check type and return type classification.
13878 The manual states (paraphrase): If one datatype is given, it indicates the
13879 type given in:
13880 - the second operand, if there is one
13881 - the operand, if there is no second operand
13882 - the result, if there are no operands.
13883 This isn't quite good enough though, so we use a concept of a "key" datatype
13884 which is set on a per-instruction basis, which is the one which matters when
13885 only one data type is written.
13886 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13887 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13888
13889static struct neon_type_el
13890neon_check_type (unsigned els, enum neon_shape ns, ...)
13891{
13892 va_list ap;
13893 unsigned i, pass, key_el = 0;
13894 unsigned types[NEON_MAX_TYPE_ELS];
13895 enum neon_el_type k_type = NT_invtype;
13896 unsigned k_size = -1u;
13897 struct neon_type_el badtype = {NT_invtype, -1};
13898 unsigned key_allowed = 0;
13899
13900 /* Optional registers in Neon instructions are always (not) in operand 1.
13901 Fill in the missing operand here, if it was omitted. */
13902 if (els > 1 && !inst.operands[1].present)
13903 inst.operands[1] = inst.operands[0];
13904
13905 /* Suck up all the varargs. */
13906 va_start (ap, ns);
13907 for (i = 0; i < els; i++)
13908 {
13909 unsigned thisarg = va_arg (ap, unsigned);
13910 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13911 {
13912 va_end (ap);
13913 return badtype;
13914 }
5287ad62
JB
13915 types[i] = thisarg;
13916 if ((thisarg & N_KEY) != 0)
477330fc 13917 key_el = i;
5287ad62
JB
13918 }
13919 va_end (ap);
13920
dcbf9037
JB
13921 if (inst.vectype.elems > 0)
13922 for (i = 0; i < els; i++)
13923 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13924 {
13925 first_error (_("types specified in both the mnemonic and operands"));
13926 return badtype;
13927 }
dcbf9037 13928
5287ad62
JB
13929 /* Duplicate inst.vectype elements here as necessary.
13930 FIXME: No idea if this is exactly the same as the ARM assembler,
13931 particularly when an insn takes one register and one non-register
13932 operand. */
13933 if (inst.vectype.elems == 1 && els > 1)
13934 {
13935 unsigned j;
13936 inst.vectype.elems = els;
13937 inst.vectype.el[key_el] = inst.vectype.el[0];
13938 for (j = 0; j < els; j++)
477330fc
RM
13939 if (j != key_el)
13940 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13941 types[j]);
dcbf9037
JB
13942 }
13943 else if (inst.vectype.elems == 0 && els > 0)
13944 {
13945 unsigned j;
13946 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13947 after each operand. We allow some flexibility here; as long as the
13948 "key" operand has a type, we can infer the others. */
dcbf9037 13949 for (j = 0; j < els; j++)
477330fc
RM
13950 if (inst.operands[j].vectype.type != NT_invtype)
13951 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13952
13953 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13954 {
13955 for (j = 0; j < els; j++)
13956 if (inst.operands[j].vectype.type == NT_invtype)
13957 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13958 types[j]);
13959 }
dcbf9037 13960 else
477330fc
RM
13961 {
13962 first_error (_("operand types can't be inferred"));
13963 return badtype;
13964 }
5287ad62
JB
13965 }
13966 else if (inst.vectype.elems != els)
13967 {
dcbf9037 13968 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13969 return badtype;
13970 }
13971
13972 for (pass = 0; pass < 2; pass++)
13973 {
13974 for (i = 0; i < els; i++)
477330fc
RM
13975 {
13976 unsigned thisarg = types[i];
13977 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13978 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13979 enum neon_el_type g_type = inst.vectype.el[i].type;
13980 unsigned g_size = inst.vectype.el[i].size;
13981
13982 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13983 integer types if sign-specific variants are unavailable. */
477330fc 13984 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13985 && (types_allowed & N_SU_ALL) == 0)
13986 g_type = NT_integer;
13987
477330fc 13988 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13989 them. Some instructions only care about signs for some element
13990 sizes, so handle that properly. */
477330fc 13991 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13992 && ((g_size == 8 && (types_allowed & N_8) != 0)
13993 || (g_size == 16 && (types_allowed & N_16) != 0)
13994 || (g_size == 32 && (types_allowed & N_32) != 0)
13995 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13996 g_type = NT_untyped;
13997
477330fc
RM
13998 if (pass == 0)
13999 {
14000 if ((thisarg & N_KEY) != 0)
14001 {
14002 k_type = g_type;
14003 k_size = g_size;
14004 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14005
14006 /* Check architecture constraint on FP16 extension. */
14007 if (k_size == 16
14008 && k_type == NT_float
14009 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14010 {
14011 inst.error = _(BAD_FP16);
14012 return badtype;
14013 }
477330fc
RM
14014 }
14015 }
14016 else
14017 {
14018 if ((thisarg & N_VFP) != 0)
14019 {
14020 enum neon_shape_el regshape;
14021 unsigned regwidth, match;
99b253c5
NC
14022
14023 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14024 if (ns == NS_NULL)
14025 {
14026 first_error (_("invalid instruction shape"));
14027 return badtype;
14028 }
477330fc
RM
14029 regshape = neon_shape_tab[ns].el[i];
14030 regwidth = neon_shape_el_size[regshape];
14031
14032 /* In VFP mode, operands must match register widths. If we
14033 have a key operand, use its width, else use the width of
14034 the current operand. */
14035 if (k_size != -1u)
14036 match = k_size;
14037 else
14038 match = g_size;
14039
9db2f6b4
RL
14040 /* FP16 will use a single precision register. */
14041 if (regwidth == 32 && match == 16)
14042 {
14043 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14044 match = regwidth;
14045 else
14046 {
14047 inst.error = _(BAD_FP16);
14048 return badtype;
14049 }
14050 }
14051
477330fc
RM
14052 if (regwidth != match)
14053 {
14054 first_error (_("operand size must match register width"));
14055 return badtype;
14056 }
14057 }
14058
14059 if ((thisarg & N_EQK) == 0)
14060 {
14061 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14062
14063 if ((given_type & types_allowed) == 0)
14064 {
14065 first_error (_("bad type in Neon instruction"));
14066 return badtype;
14067 }
14068 }
14069 else
14070 {
14071 enum neon_el_type mod_k_type = k_type;
14072 unsigned mod_k_size = k_size;
14073 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14074 if (g_type != mod_k_type || g_size != mod_k_size)
14075 {
14076 first_error (_("inconsistent types in Neon instruction"));
14077 return badtype;
14078 }
14079 }
14080 }
14081 }
5287ad62
JB
14082 }
14083
14084 return inst.vectype.el[key_el];
14085}
14086
037e8744 14087/* Neon-style VFP instruction forwarding. */
5287ad62 14088
037e8744
JB
14089/* Thumb VFP instructions have 0xE in the condition field. */
14090
14091static void
14092do_vfp_cond_or_thumb (void)
5287ad62 14093{
88714cb8
DG
14094 inst.is_neon = 1;
14095
5287ad62 14096 if (thumb_mode)
037e8744 14097 inst.instruction |= 0xe0000000;
5287ad62 14098 else
037e8744 14099 inst.instruction |= inst.cond << 28;
5287ad62
JB
14100}
14101
037e8744
JB
14102/* Look up and encode a simple mnemonic, for use as a helper function for the
14103 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14104 etc. It is assumed that operand parsing has already been done, and that the
14105 operands are in the form expected by the given opcode (this isn't necessarily
14106 the same as the form in which they were parsed, hence some massaging must
14107 take place before this function is called).
14108 Checks current arch version against that in the looked-up opcode. */
5287ad62 14109
037e8744
JB
14110static void
14111do_vfp_nsyn_opcode (const char *opname)
5287ad62 14112{
037e8744 14113 const struct asm_opcode *opcode;
5f4273c7 14114
21d799b5 14115 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14116
037e8744
JB
14117 if (!opcode)
14118 abort ();
5287ad62 14119
037e8744 14120 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14121 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14122 _(BAD_FPU));
5287ad62 14123
88714cb8
DG
14124 inst.is_neon = 1;
14125
037e8744
JB
14126 if (thumb_mode)
14127 {
14128 inst.instruction = opcode->tvalue;
14129 opcode->tencode ();
14130 }
14131 else
14132 {
14133 inst.instruction = (inst.cond << 28) | opcode->avalue;
14134 opcode->aencode ();
14135 }
14136}
5287ad62
JB
14137
14138static void
037e8744 14139do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14140{
037e8744
JB
14141 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14142
9db2f6b4 14143 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14144 {
14145 if (is_add)
477330fc 14146 do_vfp_nsyn_opcode ("fadds");
037e8744 14147 else
477330fc 14148 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14149
14150 /* ARMv8.2 fp16 instruction. */
14151 if (rs == NS_HHH)
14152 do_scalar_fp16_v82_encode ();
037e8744
JB
14153 }
14154 else
14155 {
14156 if (is_add)
477330fc 14157 do_vfp_nsyn_opcode ("faddd");
037e8744 14158 else
477330fc 14159 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14160 }
14161}
14162
14163/* Check operand types to see if this is a VFP instruction, and if so call
14164 PFN (). */
14165
14166static int
14167try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14168{
14169 enum neon_shape rs;
14170 struct neon_type_el et;
14171
14172 switch (args)
14173 {
14174 case 2:
9db2f6b4
RL
14175 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14176 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14177 break;
5f4273c7 14178
037e8744 14179 case 3:
9db2f6b4
RL
14180 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14181 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14182 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14183 break;
14184
14185 default:
14186 abort ();
14187 }
14188
14189 if (et.type != NT_invtype)
14190 {
14191 pfn (rs);
14192 return SUCCESS;
14193 }
037e8744 14194
99b253c5 14195 inst.error = NULL;
037e8744
JB
14196 return FAIL;
14197}
14198
14199static void
14200do_vfp_nsyn_mla_mls (enum neon_shape rs)
14201{
14202 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14203
9db2f6b4 14204 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14205 {
14206 if (is_mla)
477330fc 14207 do_vfp_nsyn_opcode ("fmacs");
037e8744 14208 else
477330fc 14209 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14210
14211 /* ARMv8.2 fp16 instruction. */
14212 if (rs == NS_HHH)
14213 do_scalar_fp16_v82_encode ();
037e8744
JB
14214 }
14215 else
14216 {
14217 if (is_mla)
477330fc 14218 do_vfp_nsyn_opcode ("fmacd");
037e8744 14219 else
477330fc 14220 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14221 }
14222}
14223
62f3b8c8
PB
14224static void
14225do_vfp_nsyn_fma_fms (enum neon_shape rs)
14226{
14227 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14228
9db2f6b4 14229 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14230 {
14231 if (is_fma)
477330fc 14232 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14233 else
477330fc 14234 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14235
14236 /* ARMv8.2 fp16 instruction. */
14237 if (rs == NS_HHH)
14238 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14239 }
14240 else
14241 {
14242 if (is_fma)
477330fc 14243 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14244 else
477330fc 14245 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14246 }
14247}
14248
037e8744
JB
14249static void
14250do_vfp_nsyn_mul (enum neon_shape rs)
14251{
9db2f6b4
RL
14252 if (rs == NS_FFF || rs == NS_HHH)
14253 {
14254 do_vfp_nsyn_opcode ("fmuls");
14255
14256 /* ARMv8.2 fp16 instruction. */
14257 if (rs == NS_HHH)
14258 do_scalar_fp16_v82_encode ();
14259 }
037e8744
JB
14260 else
14261 do_vfp_nsyn_opcode ("fmuld");
14262}
14263
14264static void
14265do_vfp_nsyn_abs_neg (enum neon_shape rs)
14266{
14267 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14268 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14269
9db2f6b4 14270 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14271 {
14272 if (is_neg)
477330fc 14273 do_vfp_nsyn_opcode ("fnegs");
037e8744 14274 else
477330fc 14275 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14276
14277 /* ARMv8.2 fp16 instruction. */
14278 if (rs == NS_HH)
14279 do_scalar_fp16_v82_encode ();
037e8744
JB
14280 }
14281 else
14282 {
14283 if (is_neg)
477330fc 14284 do_vfp_nsyn_opcode ("fnegd");
037e8744 14285 else
477330fc 14286 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14287 }
14288}
14289
14290/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14291 insns belong to Neon, and are handled elsewhere. */
14292
14293static void
14294do_vfp_nsyn_ldm_stm (int is_dbmode)
14295{
14296 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14297 if (is_ldm)
14298 {
14299 if (is_dbmode)
477330fc 14300 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14301 else
477330fc 14302 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14303 }
14304 else
14305 {
14306 if (is_dbmode)
477330fc 14307 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14308 else
477330fc 14309 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14310 }
14311}
14312
037e8744
JB
14313static void
14314do_vfp_nsyn_sqrt (void)
14315{
9db2f6b4
RL
14316 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14317 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14318
9db2f6b4
RL
14319 if (rs == NS_FF || rs == NS_HH)
14320 {
14321 do_vfp_nsyn_opcode ("fsqrts");
14322
14323 /* ARMv8.2 fp16 instruction. */
14324 if (rs == NS_HH)
14325 do_scalar_fp16_v82_encode ();
14326 }
037e8744
JB
14327 else
14328 do_vfp_nsyn_opcode ("fsqrtd");
14329}
14330
14331static void
14332do_vfp_nsyn_div (void)
14333{
9db2f6b4 14334 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14335 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14336 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14337
9db2f6b4
RL
14338 if (rs == NS_FFF || rs == NS_HHH)
14339 {
14340 do_vfp_nsyn_opcode ("fdivs");
14341
14342 /* ARMv8.2 fp16 instruction. */
14343 if (rs == NS_HHH)
14344 do_scalar_fp16_v82_encode ();
14345 }
037e8744
JB
14346 else
14347 do_vfp_nsyn_opcode ("fdivd");
14348}
14349
14350static void
14351do_vfp_nsyn_nmul (void)
14352{
9db2f6b4 14353 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14354 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14355 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14356
9db2f6b4 14357 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14358 {
88714cb8 14359 NEON_ENCODE (SINGLE, inst);
037e8744 14360 do_vfp_sp_dyadic ();
9db2f6b4
RL
14361
14362 /* ARMv8.2 fp16 instruction. */
14363 if (rs == NS_HHH)
14364 do_scalar_fp16_v82_encode ();
037e8744
JB
14365 }
14366 else
14367 {
88714cb8 14368 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14369 do_vfp_dp_rd_rn_rm ();
14370 }
14371 do_vfp_cond_or_thumb ();
9db2f6b4 14372
037e8744
JB
14373}
14374
14375static void
14376do_vfp_nsyn_cmp (void)
14377{
9db2f6b4 14378 enum neon_shape rs;
037e8744
JB
14379 if (inst.operands[1].isreg)
14380 {
9db2f6b4
RL
14381 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14382 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14383
9db2f6b4 14384 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14385 {
14386 NEON_ENCODE (SINGLE, inst);
14387 do_vfp_sp_monadic ();
14388 }
037e8744 14389 else
477330fc
RM
14390 {
14391 NEON_ENCODE (DOUBLE, inst);
14392 do_vfp_dp_rd_rm ();
14393 }
037e8744
JB
14394 }
14395 else
14396 {
9db2f6b4
RL
14397 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14398 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14399
14400 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14401 {
14402 case N_MNEM_vcmp:
14403 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14404 break;
14405 case N_MNEM_vcmpe:
14406 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14407 break;
14408 default:
14409 abort ();
14410 }
5f4273c7 14411
9db2f6b4 14412 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14413 {
14414 NEON_ENCODE (SINGLE, inst);
14415 do_vfp_sp_compare_z ();
14416 }
037e8744 14417 else
477330fc
RM
14418 {
14419 NEON_ENCODE (DOUBLE, inst);
14420 do_vfp_dp_rd ();
14421 }
037e8744
JB
14422 }
14423 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14424
14425 /* ARMv8.2 fp16 instruction. */
14426 if (rs == NS_HI || rs == NS_HH)
14427 do_scalar_fp16_v82_encode ();
037e8744
JB
14428}
14429
14430static void
14431nsyn_insert_sp (void)
14432{
14433 inst.operands[1] = inst.operands[0];
14434 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14435 inst.operands[0].reg = REG_SP;
037e8744
JB
14436 inst.operands[0].isreg = 1;
14437 inst.operands[0].writeback = 1;
14438 inst.operands[0].present = 1;
14439}
14440
14441static void
14442do_vfp_nsyn_push (void)
14443{
14444 nsyn_insert_sp ();
b126985e
NC
14445
14446 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14447 _("register list must contain at least 1 and at most 16 "
14448 "registers"));
14449
037e8744
JB
14450 if (inst.operands[1].issingle)
14451 do_vfp_nsyn_opcode ("fstmdbs");
14452 else
14453 do_vfp_nsyn_opcode ("fstmdbd");
14454}
14455
14456static void
14457do_vfp_nsyn_pop (void)
14458{
14459 nsyn_insert_sp ();
b126985e
NC
14460
14461 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14462 _("register list must contain at least 1 and at most 16 "
14463 "registers"));
14464
037e8744 14465 if (inst.operands[1].issingle)
22b5b651 14466 do_vfp_nsyn_opcode ("fldmias");
037e8744 14467 else
22b5b651 14468 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14469}
14470
14471/* Fix up Neon data-processing instructions, ORing in the correct bits for
14472 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14473
88714cb8
DG
14474static void
14475neon_dp_fixup (struct arm_it* insn)
037e8744 14476{
88714cb8
DG
14477 unsigned int i = insn->instruction;
14478 insn->is_neon = 1;
14479
037e8744
JB
14480 if (thumb_mode)
14481 {
14482 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14483 if (i & (1 << 24))
477330fc 14484 i |= 1 << 28;
5f4273c7 14485
037e8744 14486 i &= ~(1 << 24);
5f4273c7 14487
037e8744
JB
14488 i |= 0xef000000;
14489 }
14490 else
14491 i |= 0xf2000000;
5f4273c7 14492
88714cb8 14493 insn->instruction = i;
037e8744
JB
14494}
14495
14496/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14497 (0, 1, 2, 3). */
14498
14499static unsigned
14500neon_logbits (unsigned x)
14501{
14502 return ffs (x) - 4;
14503}
14504
14505#define LOW4(R) ((R) & 0xf)
14506#define HI1(R) (((R) >> 4) & 1)
14507
14508/* Encode insns with bit pattern:
14509
14510 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14511 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14512
037e8744
JB
14513 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14514 different meaning for some instruction. */
14515
14516static void
14517neon_three_same (int isquad, int ubit, int size)
14518{
14519 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14520 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14521 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14522 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14523 inst.instruction |= LOW4 (inst.operands[2].reg);
14524 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14525 inst.instruction |= (isquad != 0) << 6;
14526 inst.instruction |= (ubit != 0) << 24;
14527 if (size != -1)
14528 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14529
88714cb8 14530 neon_dp_fixup (&inst);
037e8744
JB
14531}
14532
14533/* Encode instructions of the form:
14534
14535 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14536 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14537
14538 Don't write size if SIZE == -1. */
14539
14540static void
14541neon_two_same (int qbit, int ubit, int size)
14542{
14543 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14544 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14545 inst.instruction |= LOW4 (inst.operands[1].reg);
14546 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14547 inst.instruction |= (qbit != 0) << 6;
14548 inst.instruction |= (ubit != 0) << 24;
14549
14550 if (size != -1)
14551 inst.instruction |= neon_logbits (size) << 18;
14552
88714cb8 14553 neon_dp_fixup (&inst);
5287ad62
JB
14554}
14555
14556/* Neon instruction encoders, in approximate order of appearance. */
14557
14558static void
14559do_neon_dyadic_i_su (void)
14560{
037e8744 14561 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14562 struct neon_type_el et = neon_check_type (3, rs,
14563 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14564 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14565}
14566
14567static void
14568do_neon_dyadic_i64_su (void)
14569{
037e8744 14570 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14571 struct neon_type_el et = neon_check_type (3, rs,
14572 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14573 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14574}
14575
14576static void
14577neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14578 unsigned immbits)
5287ad62
JB
14579{
14580 unsigned size = et.size >> 3;
14581 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14582 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14583 inst.instruction |= LOW4 (inst.operands[1].reg);
14584 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14585 inst.instruction |= (isquad != 0) << 6;
14586 inst.instruction |= immbits << 16;
14587 inst.instruction |= (size >> 3) << 7;
14588 inst.instruction |= (size & 0x7) << 19;
14589 if (write_ubit)
14590 inst.instruction |= (uval != 0) << 24;
14591
88714cb8 14592 neon_dp_fixup (&inst);
5287ad62
JB
14593}
14594
14595static void
14596do_neon_shl_imm (void)
14597{
14598 if (!inst.operands[2].isreg)
14599 {
037e8744 14600 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14601 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14602 int imm = inst.operands[2].imm;
14603
14604 constraint (imm < 0 || (unsigned)imm >= et.size,
14605 _("immediate out of range for shift"));
88714cb8 14606 NEON_ENCODE (IMMED, inst);
cb3b1e65 14607 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14608 }
14609 else
14610 {
037e8744 14611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14612 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14613 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14614 unsigned int tmp;
14615
14616 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14617 vshl.xx Dd, Dm, Dn
14618 whereas other 3-register operations encoded by neon_three_same have
14619 syntax like:
14620 vadd.xx Dd, Dn, Dm
14621 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14622 here. */
627907b7
JB
14623 tmp = inst.operands[2].reg;
14624 inst.operands[2].reg = inst.operands[1].reg;
14625 inst.operands[1].reg = tmp;
88714cb8 14626 NEON_ENCODE (INTEGER, inst);
037e8744 14627 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14628 }
14629}
14630
14631static void
14632do_neon_qshl_imm (void)
14633{
14634 if (!inst.operands[2].isreg)
14635 {
037e8744 14636 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14637 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14638 int imm = inst.operands[2].imm;
627907b7 14639
cb3b1e65
JB
14640 constraint (imm < 0 || (unsigned)imm >= et.size,
14641 _("immediate out of range for shift"));
88714cb8 14642 NEON_ENCODE (IMMED, inst);
cb3b1e65 14643 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14644 }
14645 else
14646 {
037e8744 14647 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14648 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14649 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14650 unsigned int tmp;
14651
14652 /* See note in do_neon_shl_imm. */
14653 tmp = inst.operands[2].reg;
14654 inst.operands[2].reg = inst.operands[1].reg;
14655 inst.operands[1].reg = tmp;
88714cb8 14656 NEON_ENCODE (INTEGER, inst);
037e8744 14657 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14658 }
14659}
14660
627907b7
JB
14661static void
14662do_neon_rshl (void)
14663{
14664 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14665 struct neon_type_el et = neon_check_type (3, rs,
14666 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14667 unsigned int tmp;
14668
14669 tmp = inst.operands[2].reg;
14670 inst.operands[2].reg = inst.operands[1].reg;
14671 inst.operands[1].reg = tmp;
14672 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14673}
14674
5287ad62
JB
14675static int
14676neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14677{
036dc3f7
PB
14678 /* Handle .I8 pseudo-instructions. */
14679 if (size == 8)
5287ad62 14680 {
5287ad62 14681 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14682 FIXME is this the intended semantics? There doesn't seem much point in
14683 accepting .I8 if so. */
5287ad62
JB
14684 immediate |= immediate << 8;
14685 size = 16;
036dc3f7
PB
14686 }
14687
14688 if (size >= 32)
14689 {
14690 if (immediate == (immediate & 0x000000ff))
14691 {
14692 *immbits = immediate;
14693 return 0x1;
14694 }
14695 else if (immediate == (immediate & 0x0000ff00))
14696 {
14697 *immbits = immediate >> 8;
14698 return 0x3;
14699 }
14700 else if (immediate == (immediate & 0x00ff0000))
14701 {
14702 *immbits = immediate >> 16;
14703 return 0x5;
14704 }
14705 else if (immediate == (immediate & 0xff000000))
14706 {
14707 *immbits = immediate >> 24;
14708 return 0x7;
14709 }
14710 if ((immediate & 0xffff) != (immediate >> 16))
14711 goto bad_immediate;
14712 immediate &= 0xffff;
5287ad62
JB
14713 }
14714
14715 if (immediate == (immediate & 0x000000ff))
14716 {
14717 *immbits = immediate;
036dc3f7 14718 return 0x9;
5287ad62
JB
14719 }
14720 else if (immediate == (immediate & 0x0000ff00))
14721 {
14722 *immbits = immediate >> 8;
036dc3f7 14723 return 0xb;
5287ad62
JB
14724 }
14725
14726 bad_immediate:
dcbf9037 14727 first_error (_("immediate value out of range"));
5287ad62
JB
14728 return FAIL;
14729}
14730
5287ad62
JB
14731static void
14732do_neon_logic (void)
14733{
14734 if (inst.operands[2].present && inst.operands[2].isreg)
14735 {
037e8744 14736 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14737 neon_check_type (3, rs, N_IGNORE_TYPE);
14738 /* U bit and size field were set as part of the bitmask. */
88714cb8 14739 NEON_ENCODE (INTEGER, inst);
037e8744 14740 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14741 }
14742 else
14743 {
4316f0d2
DG
14744 const int three_ops_form = (inst.operands[2].present
14745 && !inst.operands[2].isreg);
14746 const int immoperand = (three_ops_form ? 2 : 1);
14747 enum neon_shape rs = (three_ops_form
14748 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14749 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14750 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14751 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14752 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14753 unsigned immbits;
14754 int cmode;
5f4273c7 14755
5287ad62 14756 if (et.type == NT_invtype)
477330fc 14757 return;
5f4273c7 14758
4316f0d2
DG
14759 if (three_ops_form)
14760 constraint (inst.operands[0].reg != inst.operands[1].reg,
14761 _("first and second operands shall be the same register"));
14762
88714cb8 14763 NEON_ENCODE (IMMED, inst);
5287ad62 14764
4316f0d2 14765 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14766 if (et.size == 64)
14767 {
14768 /* .i64 is a pseudo-op, so the immediate must be a repeating
14769 pattern. */
4316f0d2
DG
14770 if (immbits != (inst.operands[immoperand].regisimm ?
14771 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14772 {
14773 /* Set immbits to an invalid constant. */
14774 immbits = 0xdeadbeef;
14775 }
14776 }
14777
5287ad62 14778 switch (opcode)
477330fc
RM
14779 {
14780 case N_MNEM_vbic:
14781 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14782 break;
14783
14784 case N_MNEM_vorr:
14785 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14786 break;
14787
14788 case N_MNEM_vand:
14789 /* Pseudo-instruction for VBIC. */
14790 neon_invert_size (&immbits, 0, et.size);
14791 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14792 break;
14793
14794 case N_MNEM_vorn:
14795 /* Pseudo-instruction for VORR. */
14796 neon_invert_size (&immbits, 0, et.size);
14797 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14798 break;
14799
14800 default:
14801 abort ();
14802 }
5287ad62
JB
14803
14804 if (cmode == FAIL)
477330fc 14805 return;
5287ad62 14806
037e8744 14807 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14808 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14809 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14810 inst.instruction |= cmode << 8;
14811 neon_write_immbits (immbits);
5f4273c7 14812
88714cb8 14813 neon_dp_fixup (&inst);
5287ad62
JB
14814 }
14815}
14816
14817static void
14818do_neon_bitfield (void)
14819{
037e8744 14820 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14821 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14822 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14823}
14824
14825static void
dcbf9037 14826neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14827 unsigned destbits)
5287ad62 14828{
037e8744 14829 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14830 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14831 types | N_KEY);
5287ad62
JB
14832 if (et.type == NT_float)
14833 {
88714cb8 14834 NEON_ENCODE (FLOAT, inst);
cc933301 14835 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14836 }
14837 else
14838 {
88714cb8 14839 NEON_ENCODE (INTEGER, inst);
037e8744 14840 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14841 }
14842}
14843
14844static void
14845do_neon_dyadic_if_su (void)
14846{
dcbf9037 14847 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14848}
14849
14850static void
14851do_neon_dyadic_if_su_d (void)
14852{
14853 /* This version only allow D registers, but that constraint is enforced during
14854 operand parsing so we don't need to do anything extra here. */
dcbf9037 14855 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14856}
14857
5287ad62
JB
14858static void
14859do_neon_dyadic_if_i_d (void)
14860{
428e3f1f
PB
14861 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14862 affected if we specify unsigned args. */
14863 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14864}
14865
037e8744
JB
14866enum vfp_or_neon_is_neon_bits
14867{
14868 NEON_CHECK_CC = 1,
73924fbc
MGD
14869 NEON_CHECK_ARCH = 2,
14870 NEON_CHECK_ARCH8 = 4
037e8744
JB
14871};
14872
14873/* Call this function if an instruction which may have belonged to the VFP or
14874 Neon instruction sets, but turned out to be a Neon instruction (due to the
14875 operand types involved, etc.). We have to check and/or fix-up a couple of
14876 things:
14877
14878 - Make sure the user hasn't attempted to make a Neon instruction
14879 conditional.
14880 - Alter the value in the condition code field if necessary.
14881 - Make sure that the arch supports Neon instructions.
14882
14883 Which of these operations take place depends on bits from enum
14884 vfp_or_neon_is_neon_bits.
14885
14886 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14887 current instruction's condition is COND_ALWAYS, the condition field is
14888 changed to inst.uncond_value. This is necessary because instructions shared
14889 between VFP and Neon may be conditional for the VFP variants only, and the
14890 unconditional Neon version must have, e.g., 0xF in the condition field. */
14891
14892static int
14893vfp_or_neon_is_neon (unsigned check)
14894{
14895 /* Conditions are always legal in Thumb mode (IT blocks). */
14896 if (!thumb_mode && (check & NEON_CHECK_CC))
14897 {
14898 if (inst.cond != COND_ALWAYS)
477330fc
RM
14899 {
14900 first_error (_(BAD_COND));
14901 return FAIL;
14902 }
037e8744 14903 if (inst.uncond_value != -1)
477330fc 14904 inst.instruction |= inst.uncond_value << 28;
037e8744 14905 }
5f4273c7 14906
037e8744 14907 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14908 && !mark_feature_used (&fpu_neon_ext_v1))
14909 {
14910 first_error (_(BAD_FPU));
14911 return FAIL;
14912 }
14913
14914 if ((check & NEON_CHECK_ARCH8)
14915 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14916 {
14917 first_error (_(BAD_FPU));
14918 return FAIL;
14919 }
5f4273c7 14920
037e8744
JB
14921 return SUCCESS;
14922}
14923
5287ad62
JB
14924static void
14925do_neon_addsub_if_i (void)
14926{
037e8744
JB
14927 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14928 return;
14929
14930 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14931 return;
14932
5287ad62
JB
14933 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14934 affected if we specify unsigned args. */
dcbf9037 14935 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14936}
14937
14938/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14939 result to be:
14940 V<op> A,B (A is operand 0, B is operand 2)
14941 to mean:
14942 V<op> A,B,A
14943 not:
14944 V<op> A,B,B
14945 so handle that case specially. */
14946
14947static void
14948neon_exchange_operands (void)
14949{
5287ad62
JB
14950 if (inst.operands[1].present)
14951 {
e1fa0163
NC
14952 void *scratch = xmalloc (sizeof (inst.operands[0]));
14953
5287ad62
JB
14954 /* Swap operands[1] and operands[2]. */
14955 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14956 inst.operands[1] = inst.operands[2];
14957 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14958 free (scratch);
5287ad62
JB
14959 }
14960 else
14961 {
14962 inst.operands[1] = inst.operands[2];
14963 inst.operands[2] = inst.operands[0];
14964 }
14965}
14966
14967static void
14968neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14969{
14970 if (inst.operands[2].isreg)
14971 {
14972 if (invert)
477330fc 14973 neon_exchange_operands ();
dcbf9037 14974 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14975 }
14976 else
14977 {
037e8744 14978 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14979 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14980 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14981
88714cb8 14982 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14983 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14984 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14985 inst.instruction |= LOW4 (inst.operands[1].reg);
14986 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14987 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14988 inst.instruction |= (et.type == NT_float) << 10;
14989 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14990
88714cb8 14991 neon_dp_fixup (&inst);
5287ad62
JB
14992 }
14993}
14994
14995static void
14996do_neon_cmp (void)
14997{
cc933301 14998 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14999}
15000
15001static void
15002do_neon_cmp_inv (void)
15003{
cc933301 15004 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15005}
15006
15007static void
15008do_neon_ceq (void)
15009{
15010 neon_compare (N_IF_32, N_IF_32, FALSE);
15011}
15012
15013/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15014 scalars, which are encoded in 5 bits, M : Rm.
15015 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15016 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15017 index in M. */
15018
15019static unsigned
15020neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15021{
dcbf9037
JB
15022 unsigned regno = NEON_SCALAR_REG (scalar);
15023 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15024
15025 switch (elsize)
15026 {
15027 case 16:
15028 if (regno > 7 || elno > 3)
477330fc 15029 goto bad_scalar;
5287ad62 15030 return regno | (elno << 3);
5f4273c7 15031
5287ad62
JB
15032 case 32:
15033 if (regno > 15 || elno > 1)
477330fc 15034 goto bad_scalar;
5287ad62
JB
15035 return regno | (elno << 4);
15036
15037 default:
15038 bad_scalar:
dcbf9037 15039 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15040 }
15041
15042 return 0;
15043}
15044
15045/* Encode multiply / multiply-accumulate scalar instructions. */
15046
15047static void
15048neon_mul_mac (struct neon_type_el et, int ubit)
15049{
dcbf9037
JB
15050 unsigned scalar;
15051
15052 /* Give a more helpful error message if we have an invalid type. */
15053 if (et.type == NT_invtype)
15054 return;
5f4273c7 15055
dcbf9037 15056 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15057 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15058 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15059 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15060 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15061 inst.instruction |= LOW4 (scalar);
15062 inst.instruction |= HI1 (scalar) << 5;
15063 inst.instruction |= (et.type == NT_float) << 8;
15064 inst.instruction |= neon_logbits (et.size) << 20;
15065 inst.instruction |= (ubit != 0) << 24;
15066
88714cb8 15067 neon_dp_fixup (&inst);
5287ad62
JB
15068}
15069
15070static void
15071do_neon_mac_maybe_scalar (void)
15072{
037e8744
JB
15073 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15074 return;
15075
15076 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15077 return;
15078
5287ad62
JB
15079 if (inst.operands[2].isscalar)
15080 {
037e8744 15081 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15082 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15083 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15084 NEON_ENCODE (SCALAR, inst);
037e8744 15085 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15086 }
15087 else
428e3f1f
PB
15088 {
15089 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15090 affected if we specify unsigned args. */
15091 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15092 }
5287ad62
JB
15093}
15094
62f3b8c8
PB
15095static void
15096do_neon_fmac (void)
15097{
15098 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15099 return;
15100
15101 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15102 return;
15103
15104 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15105}
15106
5287ad62
JB
15107static void
15108do_neon_tst (void)
15109{
037e8744 15110 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15111 struct neon_type_el et = neon_check_type (3, rs,
15112 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15113 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15114}
15115
15116/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15117 same types as the MAC equivalents. The polynomial type for this instruction
15118 is encoded the same as the integer type. */
15119
15120static void
15121do_neon_mul (void)
15122{
037e8744
JB
15123 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15124 return;
15125
15126 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15127 return;
15128
5287ad62
JB
15129 if (inst.operands[2].isscalar)
15130 do_neon_mac_maybe_scalar ();
15131 else
cc933301 15132 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15133}
15134
15135static void
15136do_neon_qdmulh (void)
15137{
15138 if (inst.operands[2].isscalar)
15139 {
037e8744 15140 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15141 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15142 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15143 NEON_ENCODE (SCALAR, inst);
037e8744 15144 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15145 }
15146 else
15147 {
037e8744 15148 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15149 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15150 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15151 NEON_ENCODE (INTEGER, inst);
5287ad62 15152 /* The U bit (rounding) comes from bit mask. */
037e8744 15153 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15154 }
15155}
15156
643afb90
MW
15157static void
15158do_neon_qrdmlah (void)
15159{
15160 /* Check we're on the correct architecture. */
15161 if (!mark_feature_used (&fpu_neon_ext_armv8))
15162 inst.error =
15163 _("instruction form not available on this architecture.");
15164 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15165 {
15166 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15167 record_feature_use (&fpu_neon_ext_v8_1);
15168 }
15169
15170 if (inst.operands[2].isscalar)
15171 {
15172 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15173 struct neon_type_el et = neon_check_type (3, rs,
15174 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15175 NEON_ENCODE (SCALAR, inst);
15176 neon_mul_mac (et, neon_quad (rs));
15177 }
15178 else
15179 {
15180 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15181 struct neon_type_el et = neon_check_type (3, rs,
15182 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15183 NEON_ENCODE (INTEGER, inst);
15184 /* The U bit (rounding) comes from bit mask. */
15185 neon_three_same (neon_quad (rs), 0, et.size);
15186 }
15187}
15188
5287ad62
JB
15189static void
15190do_neon_fcmp_absolute (void)
15191{
037e8744 15192 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15193 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15194 N_F_16_32 | N_KEY);
5287ad62 15195 /* Size field comes from bit mask. */
cc933301 15196 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15197}
15198
15199static void
15200do_neon_fcmp_absolute_inv (void)
15201{
15202 neon_exchange_operands ();
15203 do_neon_fcmp_absolute ();
15204}
15205
15206static void
15207do_neon_step (void)
15208{
037e8744 15209 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15210 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15211 N_F_16_32 | N_KEY);
15212 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15213}
15214
15215static void
15216do_neon_abs_neg (void)
15217{
037e8744
JB
15218 enum neon_shape rs;
15219 struct neon_type_el et;
5f4273c7 15220
037e8744
JB
15221 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15222 return;
15223
15224 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15225 return;
15226
15227 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15228 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15229
5287ad62
JB
15230 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15231 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15232 inst.instruction |= LOW4 (inst.operands[1].reg);
15233 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15234 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15235 inst.instruction |= (et.type == NT_float) << 10;
15236 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15237
88714cb8 15238 neon_dp_fixup (&inst);
5287ad62
JB
15239}
15240
15241static void
15242do_neon_sli (void)
15243{
037e8744 15244 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15245 struct neon_type_el et = neon_check_type (2, rs,
15246 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15247 int imm = inst.operands[2].imm;
15248 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15249 _("immediate out of range for insert"));
037e8744 15250 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15251}
15252
15253static void
15254do_neon_sri (void)
15255{
037e8744 15256 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15257 struct neon_type_el et = neon_check_type (2, rs,
15258 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15259 int imm = inst.operands[2].imm;
15260 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15261 _("immediate out of range for insert"));
037e8744 15262 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15263}
15264
15265static void
15266do_neon_qshlu_imm (void)
15267{
037e8744 15268 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15269 struct neon_type_el et = neon_check_type (2, rs,
15270 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15271 int imm = inst.operands[2].imm;
15272 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15273 _("immediate out of range for shift"));
5287ad62
JB
15274 /* Only encodes the 'U present' variant of the instruction.
15275 In this case, signed types have OP (bit 8) set to 0.
15276 Unsigned types have OP set to 1. */
15277 inst.instruction |= (et.type == NT_unsigned) << 8;
15278 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15279 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15280}
15281
15282static void
15283do_neon_qmovn (void)
15284{
15285 struct neon_type_el et = neon_check_type (2, NS_DQ,
15286 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15287 /* Saturating move where operands can be signed or unsigned, and the
15288 destination has the same signedness. */
88714cb8 15289 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15290 if (et.type == NT_unsigned)
15291 inst.instruction |= 0xc0;
15292 else
15293 inst.instruction |= 0x80;
15294 neon_two_same (0, 1, et.size / 2);
15295}
15296
15297static void
15298do_neon_qmovun (void)
15299{
15300 struct neon_type_el et = neon_check_type (2, NS_DQ,
15301 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15302 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15303 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15304 neon_two_same (0, 1, et.size / 2);
15305}
15306
15307static void
15308do_neon_rshift_sat_narrow (void)
15309{
15310 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15311 or unsigned. If operands are unsigned, results must also be unsigned. */
15312 struct neon_type_el et = neon_check_type (2, NS_DQI,
15313 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15314 int imm = inst.operands[2].imm;
15315 /* This gets the bounds check, size encoding and immediate bits calculation
15316 right. */
15317 et.size /= 2;
5f4273c7 15318
5287ad62
JB
15319 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15320 VQMOVN.I<size> <Dd>, <Qm>. */
15321 if (imm == 0)
15322 {
15323 inst.operands[2].present = 0;
15324 inst.instruction = N_MNEM_vqmovn;
15325 do_neon_qmovn ();
15326 return;
15327 }
5f4273c7 15328
5287ad62 15329 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15330 _("immediate out of range"));
5287ad62
JB
15331 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15332}
15333
15334static void
15335do_neon_rshift_sat_narrow_u (void)
15336{
15337 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15338 or unsigned. If operands are unsigned, results must also be unsigned. */
15339 struct neon_type_el et = neon_check_type (2, NS_DQI,
15340 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15341 int imm = inst.operands[2].imm;
15342 /* This gets the bounds check, size encoding and immediate bits calculation
15343 right. */
15344 et.size /= 2;
15345
15346 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15347 VQMOVUN.I<size> <Dd>, <Qm>. */
15348 if (imm == 0)
15349 {
15350 inst.operands[2].present = 0;
15351 inst.instruction = N_MNEM_vqmovun;
15352 do_neon_qmovun ();
15353 return;
15354 }
15355
15356 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15357 _("immediate out of range"));
5287ad62
JB
15358 /* FIXME: The manual is kind of unclear about what value U should have in
15359 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15360 must be 1. */
15361 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15362}
15363
15364static void
15365do_neon_movn (void)
15366{
15367 struct neon_type_el et = neon_check_type (2, NS_DQ,
15368 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15369 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15370 neon_two_same (0, 1, et.size / 2);
15371}
15372
15373static void
15374do_neon_rshift_narrow (void)
15375{
15376 struct neon_type_el et = neon_check_type (2, NS_DQI,
15377 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15378 int imm = inst.operands[2].imm;
15379 /* This gets the bounds check, size encoding and immediate bits calculation
15380 right. */
15381 et.size /= 2;
5f4273c7 15382
5287ad62
JB
15383 /* If immediate is zero then we are a pseudo-instruction for
15384 VMOVN.I<size> <Dd>, <Qm> */
15385 if (imm == 0)
15386 {
15387 inst.operands[2].present = 0;
15388 inst.instruction = N_MNEM_vmovn;
15389 do_neon_movn ();
15390 return;
15391 }
5f4273c7 15392
5287ad62 15393 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15394 _("immediate out of range for narrowing operation"));
5287ad62
JB
15395 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15396}
15397
15398static void
15399do_neon_shll (void)
15400{
15401 /* FIXME: Type checking when lengthening. */
15402 struct neon_type_el et = neon_check_type (2, NS_QDI,
15403 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15404 unsigned imm = inst.operands[2].imm;
15405
15406 if (imm == et.size)
15407 {
15408 /* Maximum shift variant. */
88714cb8 15409 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15410 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15411 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15412 inst.instruction |= LOW4 (inst.operands[1].reg);
15413 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15414 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15415
88714cb8 15416 neon_dp_fixup (&inst);
5287ad62
JB
15417 }
15418 else
15419 {
15420 /* A more-specific type check for non-max versions. */
15421 et = neon_check_type (2, NS_QDI,
477330fc 15422 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15423 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15424 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15425 }
15426}
15427
037e8744 15428/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15429 the current instruction is. */
15430
6b9a8b67
MGD
15431#define CVT_FLAVOUR_VAR \
15432 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15433 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15434 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15435 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15436 /* Half-precision conversions. */ \
cc933301
JW
15437 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15438 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15439 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15440 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15441 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15442 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15443 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15444 Compared with single/double precision variants, only the co-processor \
15445 field is different, so the encoding flow is reused here. */ \
15446 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15447 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15448 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15449 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15450 /* VFP instructions. */ \
15451 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15452 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15453 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15454 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15455 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15456 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15457 /* VFP instructions with bitshift. */ \
15458 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15459 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15460 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15461 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15462 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15463 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15464 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15465 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15466
15467#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15468 neon_cvt_flavour_##C,
15469
15470/* The different types of conversions we can do. */
15471enum neon_cvt_flavour
15472{
15473 CVT_FLAVOUR_VAR
15474 neon_cvt_flavour_invalid,
15475 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15476};
15477
15478#undef CVT_VAR
15479
15480static enum neon_cvt_flavour
15481get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15482{
6b9a8b67
MGD
15483#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15484 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15485 if (et.type != NT_invtype) \
15486 { \
15487 inst.error = NULL; \
15488 return (neon_cvt_flavour_##C); \
5287ad62 15489 }
6b9a8b67 15490
5287ad62 15491 struct neon_type_el et;
037e8744 15492 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15493 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15494 /* The instruction versions which take an immediate take one register
15495 argument, which is extended to the width of the full register. Thus the
15496 "source" and "destination" registers must have the same width. Hack that
15497 here by making the size equal to the key (wider, in this case) operand. */
15498 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15499
6b9a8b67
MGD
15500 CVT_FLAVOUR_VAR;
15501
15502 return neon_cvt_flavour_invalid;
5287ad62
JB
15503#undef CVT_VAR
15504}
15505
7e8e6784
MGD
15506enum neon_cvt_mode
15507{
15508 neon_cvt_mode_a,
15509 neon_cvt_mode_n,
15510 neon_cvt_mode_p,
15511 neon_cvt_mode_m,
15512 neon_cvt_mode_z,
30bdf752
MGD
15513 neon_cvt_mode_x,
15514 neon_cvt_mode_r
7e8e6784
MGD
15515};
15516
037e8744
JB
15517/* Neon-syntax VFP conversions. */
15518
5287ad62 15519static void
6b9a8b67 15520do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15521{
037e8744 15522 const char *opname = 0;
5f4273c7 15523
d54af2d0
RL
15524 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15525 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15526 {
037e8744
JB
15527 /* Conversions with immediate bitshift. */
15528 const char *enc[] =
477330fc 15529 {
6b9a8b67
MGD
15530#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15531 CVT_FLAVOUR_VAR
15532 NULL
15533#undef CVT_VAR
477330fc 15534 };
037e8744 15535
6b9a8b67 15536 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15537 {
15538 opname = enc[flavour];
15539 constraint (inst.operands[0].reg != inst.operands[1].reg,
15540 _("operands 0 and 1 must be the same register"));
15541 inst.operands[1] = inst.operands[2];
15542 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15543 }
5287ad62
JB
15544 }
15545 else
15546 {
037e8744
JB
15547 /* Conversions without bitshift. */
15548 const char *enc[] =
477330fc 15549 {
6b9a8b67
MGD
15550#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15551 CVT_FLAVOUR_VAR
15552 NULL
15553#undef CVT_VAR
477330fc 15554 };
037e8744 15555
6b9a8b67 15556 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15557 opname = enc[flavour];
037e8744
JB
15558 }
15559
15560 if (opname)
15561 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15562
15563 /* ARMv8.2 fp16 VCVT instruction. */
15564 if (flavour == neon_cvt_flavour_s32_f16
15565 || flavour == neon_cvt_flavour_u32_f16
15566 || flavour == neon_cvt_flavour_f16_u32
15567 || flavour == neon_cvt_flavour_f16_s32)
15568 do_scalar_fp16_v82_encode ();
037e8744
JB
15569}
15570
15571static void
15572do_vfp_nsyn_cvtz (void)
15573{
d54af2d0 15574 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15575 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15576 const char *enc[] =
15577 {
6b9a8b67
MGD
15578#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15579 CVT_FLAVOUR_VAR
15580 NULL
15581#undef CVT_VAR
037e8744
JB
15582 };
15583
6b9a8b67 15584 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15585 do_vfp_nsyn_opcode (enc[flavour]);
15586}
f31fef98 15587
037e8744 15588static void
bacebabc 15589do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15590 enum neon_cvt_mode mode)
15591{
15592 int sz, op;
15593 int rm;
15594
a715796b
TG
15595 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15596 D register operands. */
15597 if (flavour == neon_cvt_flavour_s32_f64
15598 || flavour == neon_cvt_flavour_u32_f64)
15599 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15600 _(BAD_FPU));
15601
9db2f6b4
RL
15602 if (flavour == neon_cvt_flavour_s32_f16
15603 || flavour == neon_cvt_flavour_u32_f16)
15604 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15605 _(BAD_FP16));
15606
7e8e6784
MGD
15607 set_it_insn_type (OUTSIDE_IT_INSN);
15608
15609 switch (flavour)
15610 {
15611 case neon_cvt_flavour_s32_f64:
15612 sz = 1;
827f64ff 15613 op = 1;
7e8e6784
MGD
15614 break;
15615 case neon_cvt_flavour_s32_f32:
15616 sz = 0;
15617 op = 1;
15618 break;
9db2f6b4
RL
15619 case neon_cvt_flavour_s32_f16:
15620 sz = 0;
15621 op = 1;
15622 break;
7e8e6784
MGD
15623 case neon_cvt_flavour_u32_f64:
15624 sz = 1;
15625 op = 0;
15626 break;
15627 case neon_cvt_flavour_u32_f32:
15628 sz = 0;
15629 op = 0;
15630 break;
9db2f6b4
RL
15631 case neon_cvt_flavour_u32_f16:
15632 sz = 0;
15633 op = 0;
15634 break;
7e8e6784
MGD
15635 default:
15636 first_error (_("invalid instruction shape"));
15637 return;
15638 }
15639
15640 switch (mode)
15641 {
15642 case neon_cvt_mode_a: rm = 0; break;
15643 case neon_cvt_mode_n: rm = 1; break;
15644 case neon_cvt_mode_p: rm = 2; break;
15645 case neon_cvt_mode_m: rm = 3; break;
15646 default: first_error (_("invalid rounding mode")); return;
15647 }
15648
15649 NEON_ENCODE (FPV8, inst);
15650 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15651 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15652 inst.instruction |= sz << 8;
9db2f6b4
RL
15653
15654 /* ARMv8.2 fp16 VCVT instruction. */
15655 if (flavour == neon_cvt_flavour_s32_f16
15656 ||flavour == neon_cvt_flavour_u32_f16)
15657 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15658 inst.instruction |= op << 7;
15659 inst.instruction |= rm << 16;
15660 inst.instruction |= 0xf0000000;
15661 inst.is_neon = TRUE;
15662}
15663
15664static void
15665do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15666{
15667 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15668 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15669 NS_FH, NS_HF, NS_FHI, NS_HFI,
15670 NS_NULL);
6b9a8b67 15671 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15672
cc933301
JW
15673 if (flavour == neon_cvt_flavour_invalid)
15674 return;
15675
e3e535bc 15676 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15677 if (mode == neon_cvt_mode_z
e3e535bc 15678 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15679 && (flavour == neon_cvt_flavour_s16_f16
15680 || flavour == neon_cvt_flavour_u16_f16
15681 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15682 || flavour == neon_cvt_flavour_u32_f32
15683 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15684 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15685 && (rs == NS_FD || rs == NS_FF))
15686 {
15687 do_vfp_nsyn_cvtz ();
15688 return;
15689 }
15690
9db2f6b4
RL
15691 /* ARMv8.2 fp16 VCVT conversions. */
15692 if (mode == neon_cvt_mode_z
15693 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15694 && (flavour == neon_cvt_flavour_s32_f16
15695 || flavour == neon_cvt_flavour_u32_f16)
15696 && (rs == NS_FH))
15697 {
15698 do_vfp_nsyn_cvtz ();
15699 do_scalar_fp16_v82_encode ();
15700 return;
15701 }
15702
037e8744 15703 /* VFP rather than Neon conversions. */
6b9a8b67 15704 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15705 {
7e8e6784
MGD
15706 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15707 do_vfp_nsyn_cvt (rs, flavour);
15708 else
15709 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15710
037e8744
JB
15711 return;
15712 }
15713
15714 switch (rs)
15715 {
15716 case NS_DDI:
15717 case NS_QQI:
15718 {
477330fc 15719 unsigned immbits;
cc933301
JW
15720 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15721 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15722
477330fc
RM
15723 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15724 return;
037e8744 15725
477330fc
RM
15726 /* Fixed-point conversion with #0 immediate is encoded as an
15727 integer conversion. */
15728 if (inst.operands[2].present && inst.operands[2].imm == 0)
15729 goto int_encode;
477330fc
RM
15730 NEON_ENCODE (IMMED, inst);
15731 if (flavour != neon_cvt_flavour_invalid)
15732 inst.instruction |= enctab[flavour];
15733 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15734 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15735 inst.instruction |= LOW4 (inst.operands[1].reg);
15736 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15737 inst.instruction |= neon_quad (rs) << 6;
15738 inst.instruction |= 1 << 21;
cc933301
JW
15739 if (flavour < neon_cvt_flavour_s16_f16)
15740 {
15741 inst.instruction |= 1 << 21;
15742 immbits = 32 - inst.operands[2].imm;
15743 inst.instruction |= immbits << 16;
15744 }
15745 else
15746 {
15747 inst.instruction |= 3 << 20;
15748 immbits = 16 - inst.operands[2].imm;
15749 inst.instruction |= immbits << 16;
15750 inst.instruction &= ~(1 << 9);
15751 }
477330fc
RM
15752
15753 neon_dp_fixup (&inst);
037e8744
JB
15754 }
15755 break;
15756
15757 case NS_DD:
15758 case NS_QQ:
7e8e6784
MGD
15759 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15760 {
15761 NEON_ENCODE (FLOAT, inst);
15762 set_it_insn_type (OUTSIDE_IT_INSN);
15763
15764 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15765 return;
15766
15767 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15768 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15769 inst.instruction |= LOW4 (inst.operands[1].reg);
15770 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15771 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15772 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15773 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15774 inst.instruction |= mode << 8;
cc933301
JW
15775 if (flavour == neon_cvt_flavour_u16_f16
15776 || flavour == neon_cvt_flavour_s16_f16)
15777 /* Mask off the original size bits and reencode them. */
15778 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15779
7e8e6784
MGD
15780 if (thumb_mode)
15781 inst.instruction |= 0xfc000000;
15782 else
15783 inst.instruction |= 0xf0000000;
15784 }
15785 else
15786 {
037e8744 15787 int_encode:
7e8e6784 15788 {
cc933301
JW
15789 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15790 0x100, 0x180, 0x0, 0x080};
037e8744 15791
7e8e6784 15792 NEON_ENCODE (INTEGER, inst);
037e8744 15793
7e8e6784
MGD
15794 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15795 return;
037e8744 15796
7e8e6784
MGD
15797 if (flavour != neon_cvt_flavour_invalid)
15798 inst.instruction |= enctab[flavour];
037e8744 15799
7e8e6784
MGD
15800 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15801 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15802 inst.instruction |= LOW4 (inst.operands[1].reg);
15803 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15804 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15805 if (flavour >= neon_cvt_flavour_s16_f16
15806 && flavour <= neon_cvt_flavour_f16_u16)
15807 /* Half precision. */
15808 inst.instruction |= 1 << 18;
15809 else
15810 inst.instruction |= 2 << 18;
037e8744 15811
7e8e6784
MGD
15812 neon_dp_fixup (&inst);
15813 }
15814 }
15815 break;
037e8744 15816
8e79c3df
CM
15817 /* Half-precision conversions for Advanced SIMD -- neon. */
15818 case NS_QD:
15819 case NS_DQ:
15820
15821 if ((rs == NS_DQ)
15822 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15823 {
15824 as_bad (_("operand size must match register width"));
15825 break;
15826 }
15827
15828 if ((rs == NS_QD)
15829 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15830 {
15831 as_bad (_("operand size must match register width"));
15832 break;
15833 }
15834
15835 if (rs == NS_DQ)
477330fc 15836 inst.instruction = 0x3b60600;
8e79c3df
CM
15837 else
15838 inst.instruction = 0x3b60700;
15839
15840 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15841 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15842 inst.instruction |= LOW4 (inst.operands[1].reg);
15843 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15844 neon_dp_fixup (&inst);
8e79c3df
CM
15845 break;
15846
037e8744
JB
15847 default:
15848 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15849 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15850 do_vfp_nsyn_cvt (rs, flavour);
15851 else
15852 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15853 }
5287ad62
JB
15854}
15855
e3e535bc
NC
15856static void
15857do_neon_cvtr (void)
15858{
7e8e6784 15859 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15860}
15861
15862static void
15863do_neon_cvt (void)
15864{
7e8e6784
MGD
15865 do_neon_cvt_1 (neon_cvt_mode_z);
15866}
15867
15868static void
15869do_neon_cvta (void)
15870{
15871 do_neon_cvt_1 (neon_cvt_mode_a);
15872}
15873
15874static void
15875do_neon_cvtn (void)
15876{
15877 do_neon_cvt_1 (neon_cvt_mode_n);
15878}
15879
15880static void
15881do_neon_cvtp (void)
15882{
15883 do_neon_cvt_1 (neon_cvt_mode_p);
15884}
15885
15886static void
15887do_neon_cvtm (void)
15888{
15889 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15890}
15891
8e79c3df 15892static void
c70a8987 15893do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15894{
c70a8987
MGD
15895 if (is_double)
15896 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15897
c70a8987
MGD
15898 encode_arm_vfp_reg (inst.operands[0].reg,
15899 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15900 encode_arm_vfp_reg (inst.operands[1].reg,
15901 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15902 inst.instruction |= to ? 0x10000 : 0;
15903 inst.instruction |= t ? 0x80 : 0;
15904 inst.instruction |= is_double ? 0x100 : 0;
15905 do_vfp_cond_or_thumb ();
15906}
8e79c3df 15907
c70a8987
MGD
15908static void
15909do_neon_cvttb_1 (bfd_boolean t)
15910{
d54af2d0
RL
15911 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15912 NS_DF, NS_DH, NS_NULL);
8e79c3df 15913
c70a8987
MGD
15914 if (rs == NS_NULL)
15915 return;
15916 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15917 {
15918 inst.error = NULL;
15919 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15920 }
15921 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15922 {
15923 inst.error = NULL;
15924 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15925 }
15926 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15927 {
a715796b
TG
15928 /* The VCVTB and VCVTT instructions with D-register operands
15929 don't work for SP only targets. */
15930 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15931 _(BAD_FPU));
15932
c70a8987
MGD
15933 inst.error = NULL;
15934 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15935 }
15936 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15937 {
a715796b
TG
15938 /* The VCVTB and VCVTT instructions with D-register operands
15939 don't work for SP only targets. */
15940 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15941 _(BAD_FPU));
15942
c70a8987
MGD
15943 inst.error = NULL;
15944 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15945 }
15946 else
15947 return;
15948}
15949
15950static void
15951do_neon_cvtb (void)
15952{
15953 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15954}
15955
15956
15957static void
15958do_neon_cvtt (void)
15959{
c70a8987 15960 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15961}
15962
5287ad62
JB
15963static void
15964neon_move_immediate (void)
15965{
037e8744
JB
15966 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15967 struct neon_type_el et = neon_check_type (2, rs,
15968 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15969 unsigned immlo, immhi = 0, immbits;
c96612cc 15970 int op, cmode, float_p;
5287ad62 15971
037e8744 15972 constraint (et.type == NT_invtype,
477330fc 15973 _("operand size must be specified for immediate VMOV"));
037e8744 15974
5287ad62
JB
15975 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15976 op = (inst.instruction & (1 << 5)) != 0;
15977
15978 immlo = inst.operands[1].imm;
15979 if (inst.operands[1].regisimm)
15980 immhi = inst.operands[1].reg;
15981
15982 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15983 _("immediate has bits set outside the operand size"));
5287ad62 15984
c96612cc
JB
15985 float_p = inst.operands[1].immisfloat;
15986
15987 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15988 et.size, et.type)) == FAIL)
5287ad62
JB
15989 {
15990 /* Invert relevant bits only. */
15991 neon_invert_size (&immlo, &immhi, et.size);
15992 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15993 with one or the other; those cases are caught by
15994 neon_cmode_for_move_imm. */
5287ad62 15995 op = !op;
c96612cc
JB
15996 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15997 &op, et.size, et.type)) == FAIL)
477330fc
RM
15998 {
15999 first_error (_("immediate out of range"));
16000 return;
16001 }
5287ad62
JB
16002 }
16003
16004 inst.instruction &= ~(1 << 5);
16005 inst.instruction |= op << 5;
16006
16007 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16008 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16009 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16010 inst.instruction |= cmode << 8;
16011
16012 neon_write_immbits (immbits);
16013}
16014
16015static void
16016do_neon_mvn (void)
16017{
16018 if (inst.operands[1].isreg)
16019 {
037e8744 16020 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16021
88714cb8 16022 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16023 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16024 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16025 inst.instruction |= LOW4 (inst.operands[1].reg);
16026 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16027 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16028 }
16029 else
16030 {
88714cb8 16031 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16032 neon_move_immediate ();
16033 }
16034
88714cb8 16035 neon_dp_fixup (&inst);
5287ad62
JB
16036}
16037
16038/* Encode instructions of form:
16039
16040 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16041 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16042
16043static void
16044neon_mixed_length (struct neon_type_el et, unsigned size)
16045{
16046 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16047 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16048 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16049 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16050 inst.instruction |= LOW4 (inst.operands[2].reg);
16051 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16052 inst.instruction |= (et.type == NT_unsigned) << 24;
16053 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16054
88714cb8 16055 neon_dp_fixup (&inst);
5287ad62
JB
16056}
16057
16058static void
16059do_neon_dyadic_long (void)
16060{
16061 /* FIXME: Type checking for lengthening op. */
16062 struct neon_type_el et = neon_check_type (3, NS_QDD,
16063 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16064 neon_mixed_length (et, et.size);
16065}
16066
16067static void
16068do_neon_abal (void)
16069{
16070 struct neon_type_el et = neon_check_type (3, NS_QDD,
16071 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16072 neon_mixed_length (et, et.size);
16073}
16074
16075static void
16076neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16077{
16078 if (inst.operands[2].isscalar)
16079 {
dcbf9037 16080 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16081 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16082 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16083 neon_mul_mac (et, et.type == NT_unsigned);
16084 }
16085 else
16086 {
16087 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16088 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16089 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16090 neon_mixed_length (et, et.size);
16091 }
16092}
16093
16094static void
16095do_neon_mac_maybe_scalar_long (void)
16096{
16097 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16098}
16099
16100static void
16101do_neon_dyadic_wide (void)
16102{
16103 struct neon_type_el et = neon_check_type (3, NS_QQD,
16104 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16105 neon_mixed_length (et, et.size);
16106}
16107
16108static void
16109do_neon_dyadic_narrow (void)
16110{
16111 struct neon_type_el et = neon_check_type (3, NS_QDD,
16112 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16113 /* Operand sign is unimportant, and the U bit is part of the opcode,
16114 so force the operand type to integer. */
16115 et.type = NT_integer;
5287ad62
JB
16116 neon_mixed_length (et, et.size / 2);
16117}
16118
16119static void
16120do_neon_mul_sat_scalar_long (void)
16121{
16122 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16123}
16124
16125static void
16126do_neon_vmull (void)
16127{
16128 if (inst.operands[2].isscalar)
16129 do_neon_mac_maybe_scalar_long ();
16130 else
16131 {
16132 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16133 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16134
5287ad62 16135 if (et.type == NT_poly)
477330fc 16136 NEON_ENCODE (POLY, inst);
5287ad62 16137 else
477330fc 16138 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16139
16140 /* For polynomial encoding the U bit must be zero, and the size must
16141 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16142 obviously, as 0b10). */
16143 if (et.size == 64)
16144 {
16145 /* Check we're on the correct architecture. */
16146 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16147 inst.error =
16148 _("Instruction form not available on this architecture.");
16149
16150 et.size = 32;
16151 }
16152
5287ad62
JB
16153 neon_mixed_length (et, et.size);
16154 }
16155}
16156
16157static void
16158do_neon_ext (void)
16159{
037e8744 16160 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16161 struct neon_type_el et = neon_check_type (3, rs,
16162 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16163 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16164
16165 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16166 _("shift out of range"));
5287ad62
JB
16167 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16168 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16169 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16170 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16171 inst.instruction |= LOW4 (inst.operands[2].reg);
16172 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16173 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16174 inst.instruction |= imm << 8;
5f4273c7 16175
88714cb8 16176 neon_dp_fixup (&inst);
5287ad62
JB
16177}
16178
16179static void
16180do_neon_rev (void)
16181{
037e8744 16182 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16183 struct neon_type_el et = neon_check_type (2, rs,
16184 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16185 unsigned op = (inst.instruction >> 7) & 3;
16186 /* N (width of reversed regions) is encoded as part of the bitmask. We
16187 extract it here to check the elements to be reversed are smaller.
16188 Otherwise we'd get a reserved instruction. */
16189 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16190 gas_assert (elsize != 0);
5287ad62 16191 constraint (et.size >= elsize,
477330fc 16192 _("elements must be smaller than reversal region"));
037e8744 16193 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16194}
16195
16196static void
16197do_neon_dup (void)
16198{
16199 if (inst.operands[1].isscalar)
16200 {
037e8744 16201 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16202 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16203 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16204 unsigned sizebits = et.size >> 3;
dcbf9037 16205 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16206 int logsize = neon_logbits (et.size);
dcbf9037 16207 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16208
16209 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16210 return;
037e8744 16211
88714cb8 16212 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16213 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16214 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16215 inst.instruction |= LOW4 (dm);
16216 inst.instruction |= HI1 (dm) << 5;
037e8744 16217 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16218 inst.instruction |= x << 17;
16219 inst.instruction |= sizebits << 16;
5f4273c7 16220
88714cb8 16221 neon_dp_fixup (&inst);
5287ad62
JB
16222 }
16223 else
16224 {
037e8744
JB
16225 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16226 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16227 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16228 /* Duplicate ARM register to lanes of vector. */
88714cb8 16229 NEON_ENCODE (ARMREG, inst);
5287ad62 16230 switch (et.size)
477330fc
RM
16231 {
16232 case 8: inst.instruction |= 0x400000; break;
16233 case 16: inst.instruction |= 0x000020; break;
16234 case 32: inst.instruction |= 0x000000; break;
16235 default: break;
16236 }
5287ad62
JB
16237 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16238 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16239 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16240 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16241 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16242 variants, except for the condition field. */
037e8744 16243 do_vfp_cond_or_thumb ();
5287ad62
JB
16244 }
16245}
16246
16247/* VMOV has particularly many variations. It can be one of:
16248 0. VMOV<c><q> <Qd>, <Qm>
16249 1. VMOV<c><q> <Dd>, <Dm>
16250 (Register operations, which are VORR with Rm = Rn.)
16251 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16252 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16253 (Immediate loads.)
16254 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16255 (ARM register to scalar.)
16256 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16257 (Two ARM registers to vector.)
16258 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16259 (Scalar to ARM register.)
16260 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16261 (Vector to two ARM registers.)
037e8744
JB
16262 8. VMOV.F32 <Sd>, <Sm>
16263 9. VMOV.F64 <Dd>, <Dm>
16264 (VFP register moves.)
16265 10. VMOV.F32 <Sd>, #imm
16266 11. VMOV.F64 <Dd>, #imm
16267 (VFP float immediate load.)
16268 12. VMOV <Rd>, <Sm>
16269 (VFP single to ARM reg.)
16270 13. VMOV <Sd>, <Rm>
16271 (ARM reg to VFP single.)
16272 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16273 (Two ARM regs to two VFP singles.)
16274 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16275 (Two VFP singles to two ARM regs.)
5f4273c7 16276
037e8744
JB
16277 These cases can be disambiguated using neon_select_shape, except cases 1/9
16278 and 3/11 which depend on the operand type too.
5f4273c7 16279
5287ad62 16280 All the encoded bits are hardcoded by this function.
5f4273c7 16281
b7fc2769
JB
16282 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16283 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16284
5287ad62 16285 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16286 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16287
16288static void
16289do_neon_mov (void)
16290{
037e8744 16291 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16292 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16293 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16294 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16295 struct neon_type_el et;
16296 const char *ldconst = 0;
5287ad62 16297
037e8744 16298 switch (rs)
5287ad62 16299 {
037e8744
JB
16300 case NS_DD: /* case 1/9. */
16301 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16302 /* It is not an error here if no type is given. */
16303 inst.error = NULL;
16304 if (et.type == NT_float && et.size == 64)
477330fc
RM
16305 {
16306 do_vfp_nsyn_opcode ("fcpyd");
16307 break;
16308 }
037e8744 16309 /* fall through. */
5287ad62 16310
037e8744
JB
16311 case NS_QQ: /* case 0/1. */
16312 {
477330fc
RM
16313 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16314 return;
16315 /* The architecture manual I have doesn't explicitly state which
16316 value the U bit should have for register->register moves, but
16317 the equivalent VORR instruction has U = 0, so do that. */
16318 inst.instruction = 0x0200110;
16319 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16320 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16321 inst.instruction |= LOW4 (inst.operands[1].reg);
16322 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16323 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16324 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16325 inst.instruction |= neon_quad (rs) << 6;
16326
16327 neon_dp_fixup (&inst);
037e8744
JB
16328 }
16329 break;
5f4273c7 16330
037e8744
JB
16331 case NS_DI: /* case 3/11. */
16332 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16333 inst.error = NULL;
16334 if (et.type == NT_float && et.size == 64)
477330fc
RM
16335 {
16336 /* case 11 (fconstd). */
16337 ldconst = "fconstd";
16338 goto encode_fconstd;
16339 }
037e8744
JB
16340 /* fall through. */
16341
16342 case NS_QI: /* case 2/3. */
16343 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16344 return;
037e8744
JB
16345 inst.instruction = 0x0800010;
16346 neon_move_immediate ();
88714cb8 16347 neon_dp_fixup (&inst);
5287ad62 16348 break;
5f4273c7 16349
037e8744
JB
16350 case NS_SR: /* case 4. */
16351 {
477330fc
RM
16352 unsigned bcdebits = 0;
16353 int logsize;
16354 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16355 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16356
05ac0ffb
JB
16357 /* .<size> is optional here, defaulting to .32. */
16358 if (inst.vectype.elems == 0
16359 && inst.operands[0].vectype.type == NT_invtype
16360 && inst.operands[1].vectype.type == NT_invtype)
16361 {
16362 inst.vectype.el[0].type = NT_untyped;
16363 inst.vectype.el[0].size = 32;
16364 inst.vectype.elems = 1;
16365 }
16366
477330fc
RM
16367 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16368 logsize = neon_logbits (et.size);
16369
16370 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16371 _(BAD_FPU));
16372 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16373 && et.size != 32, _(BAD_FPU));
16374 constraint (et.type == NT_invtype, _("bad type for scalar"));
16375 constraint (x >= 64 / et.size, _("scalar index out of range"));
16376
16377 switch (et.size)
16378 {
16379 case 8: bcdebits = 0x8; break;
16380 case 16: bcdebits = 0x1; break;
16381 case 32: bcdebits = 0x0; break;
16382 default: ;
16383 }
16384
16385 bcdebits |= x << logsize;
16386
16387 inst.instruction = 0xe000b10;
16388 do_vfp_cond_or_thumb ();
16389 inst.instruction |= LOW4 (dn) << 16;
16390 inst.instruction |= HI1 (dn) << 7;
16391 inst.instruction |= inst.operands[1].reg << 12;
16392 inst.instruction |= (bcdebits & 3) << 5;
16393 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16394 }
16395 break;
5f4273c7 16396
037e8744 16397 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16398 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16399 _(BAD_FPU));
b7fc2769 16400
037e8744
JB
16401 inst.instruction = 0xc400b10;
16402 do_vfp_cond_or_thumb ();
16403 inst.instruction |= LOW4 (inst.operands[0].reg);
16404 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16405 inst.instruction |= inst.operands[1].reg << 12;
16406 inst.instruction |= inst.operands[2].reg << 16;
16407 break;
5f4273c7 16408
037e8744
JB
16409 case NS_RS: /* case 6. */
16410 {
477330fc
RM
16411 unsigned logsize;
16412 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16413 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16414 unsigned abcdebits = 0;
037e8744 16415
05ac0ffb
JB
16416 /* .<dt> is optional here, defaulting to .32. */
16417 if (inst.vectype.elems == 0
16418 && inst.operands[0].vectype.type == NT_invtype
16419 && inst.operands[1].vectype.type == NT_invtype)
16420 {
16421 inst.vectype.el[0].type = NT_untyped;
16422 inst.vectype.el[0].size = 32;
16423 inst.vectype.elems = 1;
16424 }
16425
91d6fa6a
NC
16426 et = neon_check_type (2, NS_NULL,
16427 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16428 logsize = neon_logbits (et.size);
16429
16430 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16431 _(BAD_FPU));
16432 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16433 && et.size != 32, _(BAD_FPU));
16434 constraint (et.type == NT_invtype, _("bad type for scalar"));
16435 constraint (x >= 64 / et.size, _("scalar index out of range"));
16436
16437 switch (et.size)
16438 {
16439 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16440 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16441 case 32: abcdebits = 0x00; break;
16442 default: ;
16443 }
16444
16445 abcdebits |= x << logsize;
16446 inst.instruction = 0xe100b10;
16447 do_vfp_cond_or_thumb ();
16448 inst.instruction |= LOW4 (dn) << 16;
16449 inst.instruction |= HI1 (dn) << 7;
16450 inst.instruction |= inst.operands[0].reg << 12;
16451 inst.instruction |= (abcdebits & 3) << 5;
16452 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16453 }
16454 break;
5f4273c7 16455
037e8744
JB
16456 case NS_RRD: /* case 7 (fmrrd). */
16457 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16458 _(BAD_FPU));
037e8744
JB
16459
16460 inst.instruction = 0xc500b10;
16461 do_vfp_cond_or_thumb ();
16462 inst.instruction |= inst.operands[0].reg << 12;
16463 inst.instruction |= inst.operands[1].reg << 16;
16464 inst.instruction |= LOW4 (inst.operands[2].reg);
16465 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16466 break;
5f4273c7 16467
037e8744
JB
16468 case NS_FF: /* case 8 (fcpys). */
16469 do_vfp_nsyn_opcode ("fcpys");
16470 break;
5f4273c7 16471
9db2f6b4 16472 case NS_HI:
037e8744
JB
16473 case NS_FI: /* case 10 (fconsts). */
16474 ldconst = "fconsts";
16475 encode_fconstd:
16476 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16477 {
16478 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16479 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16480
16481 /* ARMv8.2 fp16 vmov.f16 instruction. */
16482 if (rs == NS_HI)
16483 do_scalar_fp16_v82_encode ();
477330fc 16484 }
5287ad62 16485 else
477330fc 16486 first_error (_("immediate out of range"));
037e8744 16487 break;
5f4273c7 16488
9db2f6b4 16489 case NS_RH:
037e8744
JB
16490 case NS_RF: /* case 12 (fmrs). */
16491 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16492 /* ARMv8.2 fp16 vmov.f16 instruction. */
16493 if (rs == NS_RH)
16494 do_scalar_fp16_v82_encode ();
037e8744 16495 break;
5f4273c7 16496
9db2f6b4 16497 case NS_HR:
037e8744
JB
16498 case NS_FR: /* case 13 (fmsr). */
16499 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16500 /* ARMv8.2 fp16 vmov.f16 instruction. */
16501 if (rs == NS_HR)
16502 do_scalar_fp16_v82_encode ();
037e8744 16503 break;
5f4273c7 16504
037e8744
JB
16505 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16506 (one of which is a list), but we have parsed four. Do some fiddling to
16507 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16508 expect. */
16509 case NS_RRFF: /* case 14 (fmrrs). */
16510 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16511 _("VFP registers must be adjacent"));
037e8744
JB
16512 inst.operands[2].imm = 2;
16513 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16514 do_vfp_nsyn_opcode ("fmrrs");
16515 break;
5f4273c7 16516
037e8744
JB
16517 case NS_FFRR: /* case 15 (fmsrr). */
16518 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16519 _("VFP registers must be adjacent"));
037e8744
JB
16520 inst.operands[1] = inst.operands[2];
16521 inst.operands[2] = inst.operands[3];
16522 inst.operands[0].imm = 2;
16523 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16524 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16525 break;
5f4273c7 16526
4c261dff
NC
16527 case NS_NULL:
16528 /* neon_select_shape has determined that the instruction
16529 shape is wrong and has already set the error message. */
16530 break;
16531
5287ad62
JB
16532 default:
16533 abort ();
16534 }
16535}
16536
16537static void
16538do_neon_rshift_round_imm (void)
16539{
037e8744 16540 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16541 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16542 int imm = inst.operands[2].imm;
16543
16544 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16545 if (imm == 0)
16546 {
16547 inst.operands[2].present = 0;
16548 do_neon_mov ();
16549 return;
16550 }
16551
16552 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16553 _("immediate out of range for shift"));
037e8744 16554 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16555 et.size - imm);
5287ad62
JB
16556}
16557
9db2f6b4
RL
16558static void
16559do_neon_movhf (void)
16560{
16561 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16562 constraint (rs != NS_HH, _("invalid suffix"));
16563
16564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16565 _(BAD_FPU));
16566
16567 do_vfp_sp_monadic ();
16568
16569 inst.is_neon = 1;
16570 inst.instruction |= 0xf0000000;
16571}
16572
5287ad62
JB
16573static void
16574do_neon_movl (void)
16575{
16576 struct neon_type_el et = neon_check_type (2, NS_QD,
16577 N_EQK | N_DBL, N_SU_32 | N_KEY);
16578 unsigned sizebits = et.size >> 3;
16579 inst.instruction |= sizebits << 19;
16580 neon_two_same (0, et.type == NT_unsigned, -1);
16581}
16582
16583static void
16584do_neon_trn (void)
16585{
037e8744 16586 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16587 struct neon_type_el et = neon_check_type (2, rs,
16588 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16589 NEON_ENCODE (INTEGER, inst);
037e8744 16590 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16591}
16592
16593static void
16594do_neon_zip_uzp (void)
16595{
037e8744 16596 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16597 struct neon_type_el et = neon_check_type (2, rs,
16598 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16599 if (rs == NS_DD && et.size == 32)
16600 {
16601 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16602 inst.instruction = N_MNEM_vtrn;
16603 do_neon_trn ();
16604 return;
16605 }
037e8744 16606 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16607}
16608
16609static void
16610do_neon_sat_abs_neg (void)
16611{
037e8744 16612 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16613 struct neon_type_el et = neon_check_type (2, rs,
16614 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16615 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16616}
16617
16618static void
16619do_neon_pair_long (void)
16620{
037e8744 16621 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16622 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16623 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16624 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16625 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16626}
16627
16628static void
16629do_neon_recip_est (void)
16630{
037e8744 16631 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16632 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16633 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16634 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16635 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16636}
16637
16638static void
16639do_neon_cls (void)
16640{
037e8744 16641 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16642 struct neon_type_el et = neon_check_type (2, rs,
16643 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16644 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16645}
16646
16647static void
16648do_neon_clz (void)
16649{
037e8744 16650 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16651 struct neon_type_el et = neon_check_type (2, rs,
16652 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16653 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16654}
16655
16656static void
16657do_neon_cnt (void)
16658{
037e8744 16659 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16660 struct neon_type_el et = neon_check_type (2, rs,
16661 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16662 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16663}
16664
16665static void
16666do_neon_swp (void)
16667{
037e8744
JB
16668 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16669 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16670}
16671
16672static void
16673do_neon_tbl_tbx (void)
16674{
16675 unsigned listlenbits;
dcbf9037 16676 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16677
5287ad62
JB
16678 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16679 {
dcbf9037 16680 first_error (_("bad list length for table lookup"));
5287ad62
JB
16681 return;
16682 }
5f4273c7 16683
5287ad62
JB
16684 listlenbits = inst.operands[1].imm - 1;
16685 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16686 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16687 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16688 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16689 inst.instruction |= LOW4 (inst.operands[2].reg);
16690 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16691 inst.instruction |= listlenbits << 8;
5f4273c7 16692
88714cb8 16693 neon_dp_fixup (&inst);
5287ad62
JB
16694}
16695
16696static void
16697do_neon_ldm_stm (void)
16698{
16699 /* P, U and L bits are part of bitmask. */
16700 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16701 unsigned offsetbits = inst.operands[1].imm * 2;
16702
037e8744
JB
16703 if (inst.operands[1].issingle)
16704 {
16705 do_vfp_nsyn_ldm_stm (is_dbmode);
16706 return;
16707 }
16708
5287ad62 16709 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16710 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16711
16712 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16713 _("register list must contain at least 1 and at most 16 "
16714 "registers"));
5287ad62
JB
16715
16716 inst.instruction |= inst.operands[0].reg << 16;
16717 inst.instruction |= inst.operands[0].writeback << 21;
16718 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16719 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16720
16721 inst.instruction |= offsetbits;
5f4273c7 16722
037e8744 16723 do_vfp_cond_or_thumb ();
5287ad62
JB
16724}
16725
16726static void
16727do_neon_ldr_str (void)
16728{
5287ad62 16729 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16730
6844b2c2
MGD
16731 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16732 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16733 if (!is_ldr
6844b2c2 16734 && inst.operands[1].reg == REG_PC
ba86b375 16735 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16736 {
94dcf8bf 16737 if (thumb_mode)
6844b2c2 16738 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16739 else if (warn_on_deprecated)
5c3696f8 16740 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16741 }
16742
037e8744
JB
16743 if (inst.operands[0].issingle)
16744 {
cd2f129f 16745 if (is_ldr)
477330fc 16746 do_vfp_nsyn_opcode ("flds");
cd2f129f 16747 else
477330fc 16748 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16749
16750 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16751 if (inst.vectype.el[0].size == 16)
16752 do_scalar_fp16_v82_encode ();
5287ad62
JB
16753 }
16754 else
5287ad62 16755 {
cd2f129f 16756 if (is_ldr)
477330fc 16757 do_vfp_nsyn_opcode ("fldd");
5287ad62 16758 else
477330fc 16759 do_vfp_nsyn_opcode ("fstd");
5287ad62 16760 }
5287ad62
JB
16761}
16762
16763/* "interleave" version also handles non-interleaving register VLD1/VST1
16764 instructions. */
16765
16766static void
16767do_neon_ld_st_interleave (void)
16768{
037e8744 16769 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16770 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16771 unsigned alignbits = 0;
16772 unsigned idx;
16773 /* The bits in this table go:
16774 0: register stride of one (0) or two (1)
16775 1,2: register list length, minus one (1, 2, 3, 4).
16776 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16777 We use -1 for invalid entries. */
16778 const int typetable[] =
16779 {
16780 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16781 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16782 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16783 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16784 };
16785 int typebits;
16786
dcbf9037
JB
16787 if (et.type == NT_invtype)
16788 return;
16789
5287ad62
JB
16790 if (inst.operands[1].immisalign)
16791 switch (inst.operands[1].imm >> 8)
16792 {
16793 case 64: alignbits = 1; break;
16794 case 128:
477330fc 16795 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16796 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16797 goto bad_alignment;
16798 alignbits = 2;
16799 break;
5287ad62 16800 case 256:
477330fc
RM
16801 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16802 goto bad_alignment;
16803 alignbits = 3;
16804 break;
5287ad62
JB
16805 default:
16806 bad_alignment:
477330fc
RM
16807 first_error (_("bad alignment"));
16808 return;
5287ad62
JB
16809 }
16810
16811 inst.instruction |= alignbits << 4;
16812 inst.instruction |= neon_logbits (et.size) << 6;
16813
16814 /* Bits [4:6] of the immediate in a list specifier encode register stride
16815 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16816 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16817 up the right value for "type" in a table based on this value and the given
16818 list style, then stick it back. */
16819 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16820 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16821
16822 typebits = typetable[idx];
5f4273c7 16823
5287ad62 16824 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16825 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16826 _("bad element type for instruction"));
5287ad62
JB
16827
16828 inst.instruction &= ~0xf00;
16829 inst.instruction |= typebits << 8;
16830}
16831
16832/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16833 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16834 otherwise. The variable arguments are a list of pairs of legal (size, align)
16835 values, terminated with -1. */
16836
16837static int
aa8a0863 16838neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16839{
16840 va_list ap;
16841 int result = FAIL, thissize, thisalign;
5f4273c7 16842
5287ad62
JB
16843 if (!inst.operands[1].immisalign)
16844 {
aa8a0863 16845 *do_alignment = 0;
5287ad62
JB
16846 return SUCCESS;
16847 }
5f4273c7 16848
aa8a0863 16849 va_start (ap, do_alignment);
5287ad62
JB
16850
16851 do
16852 {
16853 thissize = va_arg (ap, int);
16854 if (thissize == -1)
477330fc 16855 break;
5287ad62
JB
16856 thisalign = va_arg (ap, int);
16857
16858 if (size == thissize && align == thisalign)
477330fc 16859 result = SUCCESS;
5287ad62
JB
16860 }
16861 while (result != SUCCESS);
16862
16863 va_end (ap);
16864
16865 if (result == SUCCESS)
aa8a0863 16866 *do_alignment = 1;
5287ad62 16867 else
dcbf9037 16868 first_error (_("unsupported alignment for instruction"));
5f4273c7 16869
5287ad62
JB
16870 return result;
16871}
16872
16873static void
16874do_neon_ld_st_lane (void)
16875{
037e8744 16876 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16877 int align_good, do_alignment = 0;
5287ad62
JB
16878 int logsize = neon_logbits (et.size);
16879 int align = inst.operands[1].imm >> 8;
16880 int n = (inst.instruction >> 8) & 3;
16881 int max_el = 64 / et.size;
5f4273c7 16882
dcbf9037
JB
16883 if (et.type == NT_invtype)
16884 return;
5f4273c7 16885
5287ad62 16886 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16887 _("bad list length"));
5287ad62 16888 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16889 _("scalar index out of range"));
5287ad62 16890 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16891 && et.size == 8,
16892 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16893
5287ad62
JB
16894 switch (n)
16895 {
16896 case 0: /* VLD1 / VST1. */
aa8a0863 16897 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16898 32, 32, -1);
5287ad62 16899 if (align_good == FAIL)
477330fc 16900 return;
aa8a0863 16901 if (do_alignment)
477330fc
RM
16902 {
16903 unsigned alignbits = 0;
16904 switch (et.size)
16905 {
16906 case 16: alignbits = 0x1; break;
16907 case 32: alignbits = 0x3; break;
16908 default: ;
16909 }
16910 inst.instruction |= alignbits << 4;
16911 }
5287ad62
JB
16912 break;
16913
16914 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16915 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16916 16, 32, 32, 64, -1);
5287ad62 16917 if (align_good == FAIL)
477330fc 16918 return;
aa8a0863 16919 if (do_alignment)
477330fc 16920 inst.instruction |= 1 << 4;
5287ad62
JB
16921 break;
16922
16923 case 2: /* VLD3 / VST3. */
16924 constraint (inst.operands[1].immisalign,
477330fc 16925 _("can't use alignment with this instruction"));
5287ad62
JB
16926 break;
16927
16928 case 3: /* VLD4 / VST4. */
aa8a0863 16929 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16930 16, 64, 32, 64, 32, 128, -1);
5287ad62 16931 if (align_good == FAIL)
477330fc 16932 return;
aa8a0863 16933 if (do_alignment)
477330fc
RM
16934 {
16935 unsigned alignbits = 0;
16936 switch (et.size)
16937 {
16938 case 8: alignbits = 0x1; break;
16939 case 16: alignbits = 0x1; break;
16940 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16941 default: ;
16942 }
16943 inst.instruction |= alignbits << 4;
16944 }
5287ad62
JB
16945 break;
16946
16947 default: ;
16948 }
16949
16950 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16951 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16952 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16953
5287ad62
JB
16954 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16955 inst.instruction |= logsize << 10;
16956}
16957
16958/* Encode single n-element structure to all lanes VLD<n> instructions. */
16959
16960static void
16961do_neon_ld_dup (void)
16962{
037e8744 16963 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16964 int align_good, do_alignment = 0;
5287ad62 16965
dcbf9037
JB
16966 if (et.type == NT_invtype)
16967 return;
16968
5287ad62
JB
16969 switch ((inst.instruction >> 8) & 3)
16970 {
16971 case 0: /* VLD1. */
9c2799c2 16972 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16973 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16974 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16975 if (align_good == FAIL)
477330fc 16976 return;
5287ad62 16977 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16978 {
16979 case 1: break;
16980 case 2: inst.instruction |= 1 << 5; break;
16981 default: first_error (_("bad list length")); return;
16982 }
5287ad62
JB
16983 inst.instruction |= neon_logbits (et.size) << 6;
16984 break;
16985
16986 case 1: /* VLD2. */
16987 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16988 &do_alignment, 8, 16, 16, 32, 32, 64,
16989 -1);
5287ad62 16990 if (align_good == FAIL)
477330fc 16991 return;
5287ad62 16992 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16993 _("bad list length"));
5287ad62 16994 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16995 inst.instruction |= 1 << 5;
5287ad62
JB
16996 inst.instruction |= neon_logbits (et.size) << 6;
16997 break;
16998
16999 case 2: /* VLD3. */
17000 constraint (inst.operands[1].immisalign,
477330fc 17001 _("can't use alignment with this instruction"));
5287ad62 17002 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17003 _("bad list length"));
5287ad62 17004 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17005 inst.instruction |= 1 << 5;
5287ad62
JB
17006 inst.instruction |= neon_logbits (et.size) << 6;
17007 break;
17008
17009 case 3: /* VLD4. */
17010 {
477330fc 17011 int align = inst.operands[1].imm >> 8;
aa8a0863 17012 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17013 16, 64, 32, 64, 32, 128, -1);
17014 if (align_good == FAIL)
17015 return;
17016 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17017 _("bad list length"));
17018 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17019 inst.instruction |= 1 << 5;
17020 if (et.size == 32 && align == 128)
17021 inst.instruction |= 0x3 << 6;
17022 else
17023 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17024 }
17025 break;
17026
17027 default: ;
17028 }
17029
aa8a0863 17030 inst.instruction |= do_alignment << 4;
5287ad62
JB
17031}
17032
17033/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17034 apart from bits [11:4]. */
17035
17036static void
17037do_neon_ldx_stx (void)
17038{
b1a769ed
DG
17039 if (inst.operands[1].isreg)
17040 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17041
5287ad62
JB
17042 switch (NEON_LANE (inst.operands[0].imm))
17043 {
17044 case NEON_INTERLEAVE_LANES:
88714cb8 17045 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17046 do_neon_ld_st_interleave ();
17047 break;
5f4273c7 17048
5287ad62 17049 case NEON_ALL_LANES:
88714cb8 17050 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17051 if (inst.instruction == N_INV)
17052 {
17053 first_error ("only loads support such operands");
17054 break;
17055 }
5287ad62
JB
17056 do_neon_ld_dup ();
17057 break;
5f4273c7 17058
5287ad62 17059 default:
88714cb8 17060 NEON_ENCODE (LANE, inst);
5287ad62
JB
17061 do_neon_ld_st_lane ();
17062 }
17063
17064 /* L bit comes from bit mask. */
17065 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17066 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17067 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17068
5287ad62
JB
17069 if (inst.operands[1].postind)
17070 {
17071 int postreg = inst.operands[1].imm & 0xf;
17072 constraint (!inst.operands[1].immisreg,
477330fc 17073 _("post-index must be a register"));
5287ad62 17074 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17075 _("bad register for post-index"));
5287ad62
JB
17076 inst.instruction |= postreg;
17077 }
4f2374c7 17078 else
5287ad62 17079 {
4f2374c7
WN
17080 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17081 constraint (inst.reloc.exp.X_op != O_constant
17082 || inst.reloc.exp.X_add_number != 0,
17083 BAD_ADDR_MODE);
17084
17085 if (inst.operands[1].writeback)
17086 {
17087 inst.instruction |= 0xd;
17088 }
17089 else
17090 inst.instruction |= 0xf;
5287ad62 17091 }
5f4273c7 17092
5287ad62
JB
17093 if (thumb_mode)
17094 inst.instruction |= 0xf9000000;
17095 else
17096 inst.instruction |= 0xf4000000;
17097}
33399f07
MGD
17098
17099/* FP v8. */
17100static void
17101do_vfp_nsyn_fpv8 (enum neon_shape rs)
17102{
a715796b
TG
17103 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17104 D register operands. */
17105 if (neon_shape_class[rs] == SC_DOUBLE)
17106 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17107 _(BAD_FPU));
17108
33399f07
MGD
17109 NEON_ENCODE (FPV8, inst);
17110
9db2f6b4
RL
17111 if (rs == NS_FFF || rs == NS_HHH)
17112 {
17113 do_vfp_sp_dyadic ();
17114
17115 /* ARMv8.2 fp16 instruction. */
17116 if (rs == NS_HHH)
17117 do_scalar_fp16_v82_encode ();
17118 }
33399f07
MGD
17119 else
17120 do_vfp_dp_rd_rn_rm ();
17121
17122 if (rs == NS_DDD)
17123 inst.instruction |= 0x100;
17124
17125 inst.instruction |= 0xf0000000;
17126}
17127
17128static void
17129do_vsel (void)
17130{
17131 set_it_insn_type (OUTSIDE_IT_INSN);
17132
17133 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17134 first_error (_("invalid instruction shape"));
17135}
17136
73924fbc
MGD
17137static void
17138do_vmaxnm (void)
17139{
17140 set_it_insn_type (OUTSIDE_IT_INSN);
17141
17142 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17143 return;
17144
17145 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17146 return;
17147
cc933301 17148 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17149}
17150
30bdf752
MGD
17151static void
17152do_vrint_1 (enum neon_cvt_mode mode)
17153{
9db2f6b4 17154 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17155 struct neon_type_el et;
17156
17157 if (rs == NS_NULL)
17158 return;
17159
a715796b
TG
17160 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17161 D register operands. */
17162 if (neon_shape_class[rs] == SC_DOUBLE)
17163 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17164 _(BAD_FPU));
17165
9db2f6b4
RL
17166 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17167 | N_VFP);
30bdf752
MGD
17168 if (et.type != NT_invtype)
17169 {
17170 /* VFP encodings. */
17171 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17172 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17173 set_it_insn_type (OUTSIDE_IT_INSN);
17174
17175 NEON_ENCODE (FPV8, inst);
9db2f6b4 17176 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17177 do_vfp_sp_monadic ();
17178 else
17179 do_vfp_dp_rd_rm ();
17180
17181 switch (mode)
17182 {
17183 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17184 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17185 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17186 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17187 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17188 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17189 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17190 default: abort ();
17191 }
17192
17193 inst.instruction |= (rs == NS_DD) << 8;
17194 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17195
17196 /* ARMv8.2 fp16 vrint instruction. */
17197 if (rs == NS_HH)
17198 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17199 }
17200 else
17201 {
17202 /* Neon encodings (or something broken...). */
17203 inst.error = NULL;
cc933301 17204 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17205
17206 if (et.type == NT_invtype)
17207 return;
17208
17209 set_it_insn_type (OUTSIDE_IT_INSN);
17210 NEON_ENCODE (FLOAT, inst);
17211
17212 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17213 return;
17214
17215 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17216 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17217 inst.instruction |= LOW4 (inst.operands[1].reg);
17218 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17219 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17220 /* Mask off the original size bits and reencode them. */
17221 inst.instruction = ((inst.instruction & 0xfff3ffff)
17222 | neon_logbits (et.size) << 18);
17223
30bdf752
MGD
17224 switch (mode)
17225 {
17226 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17227 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17228 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17229 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17230 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17231 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17232 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17233 default: abort ();
17234 }
17235
17236 if (thumb_mode)
17237 inst.instruction |= 0xfc000000;
17238 else
17239 inst.instruction |= 0xf0000000;
17240 }
17241}
17242
17243static void
17244do_vrintx (void)
17245{
17246 do_vrint_1 (neon_cvt_mode_x);
17247}
17248
17249static void
17250do_vrintz (void)
17251{
17252 do_vrint_1 (neon_cvt_mode_z);
17253}
17254
17255static void
17256do_vrintr (void)
17257{
17258 do_vrint_1 (neon_cvt_mode_r);
17259}
17260
17261static void
17262do_vrinta (void)
17263{
17264 do_vrint_1 (neon_cvt_mode_a);
17265}
17266
17267static void
17268do_vrintn (void)
17269{
17270 do_vrint_1 (neon_cvt_mode_n);
17271}
17272
17273static void
17274do_vrintp (void)
17275{
17276 do_vrint_1 (neon_cvt_mode_p);
17277}
17278
17279static void
17280do_vrintm (void)
17281{
17282 do_vrint_1 (neon_cvt_mode_m);
17283}
17284
c28eeff2
SN
17285static unsigned
17286neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17287{
17288 unsigned regno = NEON_SCALAR_REG (opnd);
17289 unsigned elno = NEON_SCALAR_INDEX (opnd);
17290
17291 if (elsize == 16 && elno < 2 && regno < 16)
17292 return regno | (elno << 4);
17293 else if (elsize == 32 && elno == 0)
17294 return regno;
17295
17296 first_error (_("scalar out of range"));
17297 return 0;
17298}
17299
17300static void
17301do_vcmla (void)
17302{
17303 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17304 _(BAD_FPU));
17305 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17306 unsigned rot = inst.reloc.exp.X_add_number;
17307 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17308 _("immediate out of range"));
17309 rot /= 90;
17310 if (inst.operands[2].isscalar)
17311 {
17312 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17313 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17314 N_KEY | N_F16 | N_F32).size;
17315 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17316 inst.is_neon = 1;
17317 inst.instruction = 0xfe000800;
17318 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17319 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17320 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17321 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17322 inst.instruction |= LOW4 (m);
17323 inst.instruction |= HI1 (m) << 5;
17324 inst.instruction |= neon_quad (rs) << 6;
17325 inst.instruction |= rot << 20;
17326 inst.instruction |= (size == 32) << 23;
17327 }
17328 else
17329 {
17330 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17331 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17332 N_KEY | N_F16 | N_F32).size;
17333 neon_three_same (neon_quad (rs), 0, -1);
17334 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17335 inst.instruction |= 0xfc200800;
17336 inst.instruction |= rot << 23;
17337 inst.instruction |= (size == 32) << 20;
17338 }
17339}
17340
17341static void
17342do_vcadd (void)
17343{
17344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17345 _(BAD_FPU));
17346 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17347 unsigned rot = inst.reloc.exp.X_add_number;
17348 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17349 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17350 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17351 N_KEY | N_F16 | N_F32).size;
17352 neon_three_same (neon_quad (rs), 0, -1);
17353 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17354 inst.instruction |= 0xfc800800;
17355 inst.instruction |= (rot == 270) << 24;
17356 inst.instruction |= (size == 32) << 20;
17357}
17358
91ff7894
MGD
17359/* Crypto v1 instructions. */
17360static void
17361do_crypto_2op_1 (unsigned elttype, int op)
17362{
17363 set_it_insn_type (OUTSIDE_IT_INSN);
17364
17365 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17366 == NT_invtype)
17367 return;
17368
17369 inst.error = NULL;
17370
17371 NEON_ENCODE (INTEGER, inst);
17372 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17373 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17374 inst.instruction |= LOW4 (inst.operands[1].reg);
17375 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17376 if (op != -1)
17377 inst.instruction |= op << 6;
17378
17379 if (thumb_mode)
17380 inst.instruction |= 0xfc000000;
17381 else
17382 inst.instruction |= 0xf0000000;
17383}
17384
48adcd8e
MGD
17385static void
17386do_crypto_3op_1 (int u, int op)
17387{
17388 set_it_insn_type (OUTSIDE_IT_INSN);
17389
17390 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17391 N_32 | N_UNT | N_KEY).type == NT_invtype)
17392 return;
17393
17394 inst.error = NULL;
17395
17396 NEON_ENCODE (INTEGER, inst);
17397 neon_three_same (1, u, 8 << op);
17398}
17399
91ff7894
MGD
17400static void
17401do_aese (void)
17402{
17403 do_crypto_2op_1 (N_8, 0);
17404}
17405
17406static void
17407do_aesd (void)
17408{
17409 do_crypto_2op_1 (N_8, 1);
17410}
17411
17412static void
17413do_aesmc (void)
17414{
17415 do_crypto_2op_1 (N_8, 2);
17416}
17417
17418static void
17419do_aesimc (void)
17420{
17421 do_crypto_2op_1 (N_8, 3);
17422}
17423
48adcd8e
MGD
17424static void
17425do_sha1c (void)
17426{
17427 do_crypto_3op_1 (0, 0);
17428}
17429
17430static void
17431do_sha1p (void)
17432{
17433 do_crypto_3op_1 (0, 1);
17434}
17435
17436static void
17437do_sha1m (void)
17438{
17439 do_crypto_3op_1 (0, 2);
17440}
17441
17442static void
17443do_sha1su0 (void)
17444{
17445 do_crypto_3op_1 (0, 3);
17446}
91ff7894 17447
48adcd8e
MGD
17448static void
17449do_sha256h (void)
17450{
17451 do_crypto_3op_1 (1, 0);
17452}
17453
17454static void
17455do_sha256h2 (void)
17456{
17457 do_crypto_3op_1 (1, 1);
17458}
17459
17460static void
17461do_sha256su1 (void)
17462{
17463 do_crypto_3op_1 (1, 2);
17464}
3c9017d2
MGD
17465
17466static void
17467do_sha1h (void)
17468{
17469 do_crypto_2op_1 (N_32, -1);
17470}
17471
17472static void
17473do_sha1su1 (void)
17474{
17475 do_crypto_2op_1 (N_32, 0);
17476}
17477
17478static void
17479do_sha256su0 (void)
17480{
17481 do_crypto_2op_1 (N_32, 1);
17482}
dd5181d5
KT
17483
17484static void
17485do_crc32_1 (unsigned int poly, unsigned int sz)
17486{
17487 unsigned int Rd = inst.operands[0].reg;
17488 unsigned int Rn = inst.operands[1].reg;
17489 unsigned int Rm = inst.operands[2].reg;
17490
17491 set_it_insn_type (OUTSIDE_IT_INSN);
17492 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17493 inst.instruction |= LOW4 (Rn) << 16;
17494 inst.instruction |= LOW4 (Rm);
17495 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17496 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17497
17498 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17499 as_warn (UNPRED_REG ("r15"));
17500 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17501 as_warn (UNPRED_REG ("r13"));
17502}
17503
17504static void
17505do_crc32b (void)
17506{
17507 do_crc32_1 (0, 0);
17508}
17509
17510static void
17511do_crc32h (void)
17512{
17513 do_crc32_1 (0, 1);
17514}
17515
17516static void
17517do_crc32w (void)
17518{
17519 do_crc32_1 (0, 2);
17520}
17521
17522static void
17523do_crc32cb (void)
17524{
17525 do_crc32_1 (1, 0);
17526}
17527
17528static void
17529do_crc32ch (void)
17530{
17531 do_crc32_1 (1, 1);
17532}
17533
17534static void
17535do_crc32cw (void)
17536{
17537 do_crc32_1 (1, 2);
17538}
17539
49e8a725
SN
17540static void
17541do_vjcvt (void)
17542{
17543 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17544 _(BAD_FPU));
17545 neon_check_type (2, NS_FD, N_S32, N_F64);
17546 do_vfp_sp_dp_cvt ();
17547 do_vfp_cond_or_thumb ();
17548}
17549
5287ad62
JB
17550\f
17551/* Overall per-instruction processing. */
17552
17553/* We need to be able to fix up arbitrary expressions in some statements.
17554 This is so that we can handle symbols that are an arbitrary distance from
17555 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17556 which returns part of an address in a form which will be valid for
17557 a data instruction. We do this by pushing the expression into a symbol
17558 in the expr_section, and creating a fix for that. */
17559
17560static void
17561fix_new_arm (fragS * frag,
17562 int where,
17563 short int size,
17564 expressionS * exp,
17565 int pc_rel,
17566 int reloc)
17567{
17568 fixS * new_fix;
17569
17570 switch (exp->X_op)
17571 {
17572 case O_constant:
6e7ce2cd
PB
17573 if (pc_rel)
17574 {
17575 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17576 refer to in the object file. Unfortunately for us, gas's
17577 generic expression parsing will already have folded out
17578 any use of .set foo/.type foo %function that may have
17579 been used to set type information of the target location,
17580 that's being specified symbolically. We have to presume
17581 the user knows what they are doing. */
6e7ce2cd
PB
17582 char name[16 + 8];
17583 symbolS *symbol;
17584
17585 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17586
17587 symbol = symbol_find_or_make (name);
17588 S_SET_SEGMENT (symbol, absolute_section);
17589 symbol_set_frag (symbol, &zero_address_frag);
17590 S_SET_VALUE (symbol, exp->X_add_number);
17591 exp->X_op = O_symbol;
17592 exp->X_add_symbol = symbol;
17593 exp->X_add_number = 0;
17594 }
17595 /* FALLTHROUGH */
5287ad62
JB
17596 case O_symbol:
17597 case O_add:
17598 case O_subtract:
21d799b5 17599 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17600 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17601 break;
17602
17603 default:
21d799b5 17604 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17605 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17606 break;
17607 }
17608
17609 /* Mark whether the fix is to a THUMB instruction, or an ARM
17610 instruction. */
17611 new_fix->tc_fix_data = thumb_mode;
17612}
17613
17614/* Create a frg for an instruction requiring relaxation. */
17615static void
17616output_relax_insn (void)
17617{
17618 char * to;
17619 symbolS *sym;
0110f2b8
PB
17620 int offset;
17621
6e1cb1a6
PB
17622 /* The size of the instruction is unknown, so tie the debug info to the
17623 start of the instruction. */
17624 dwarf2_emit_insn (0);
6e1cb1a6 17625
0110f2b8
PB
17626 switch (inst.reloc.exp.X_op)
17627 {
17628 case O_symbol:
17629 sym = inst.reloc.exp.X_add_symbol;
17630 offset = inst.reloc.exp.X_add_number;
17631 break;
17632 case O_constant:
17633 sym = NULL;
17634 offset = inst.reloc.exp.X_add_number;
17635 break;
17636 default:
17637 sym = make_expr_symbol (&inst.reloc.exp);
17638 offset = 0;
17639 break;
17640 }
17641 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17642 inst.relax, sym, offset, NULL/*offset, opcode*/);
17643 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17644}
17645
17646/* Write a 32-bit thumb instruction to buf. */
17647static void
17648put_thumb32_insn (char * buf, unsigned long insn)
17649{
17650 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17651 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17652}
17653
b99bd4ef 17654static void
c19d1205 17655output_inst (const char * str)
b99bd4ef 17656{
c19d1205 17657 char * to = NULL;
b99bd4ef 17658
c19d1205 17659 if (inst.error)
b99bd4ef 17660 {
c19d1205 17661 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17662 return;
17663 }
5f4273c7
NC
17664 if (inst.relax)
17665 {
17666 output_relax_insn ();
0110f2b8 17667 return;
5f4273c7 17668 }
c19d1205
ZW
17669 if (inst.size == 0)
17670 return;
b99bd4ef 17671
c19d1205 17672 to = frag_more (inst.size);
8dc2430f
NC
17673 /* PR 9814: Record the thumb mode into the current frag so that we know
17674 what type of NOP padding to use, if necessary. We override any previous
17675 setting so that if the mode has changed then the NOPS that we use will
17676 match the encoding of the last instruction in the frag. */
cd000bff 17677 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17678
17679 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17680 {
9c2799c2 17681 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17682 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17683 }
c19d1205 17684 else if (inst.size > INSN_SIZE)
b99bd4ef 17685 {
9c2799c2 17686 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17687 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17688 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17689 }
c19d1205
ZW
17690 else
17691 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17692
c19d1205
ZW
17693 if (inst.reloc.type != BFD_RELOC_UNUSED)
17694 fix_new_arm (frag_now, to - frag_now->fr_literal,
17695 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17696 inst.reloc.type);
b99bd4ef 17697
c19d1205 17698 dwarf2_emit_insn (inst.size);
c19d1205 17699}
b99bd4ef 17700
e07e6e58
NC
17701static char *
17702output_it_inst (int cond, int mask, char * to)
17703{
17704 unsigned long instruction = 0xbf00;
17705
17706 mask &= 0xf;
17707 instruction |= mask;
17708 instruction |= cond << 4;
17709
17710 if (to == NULL)
17711 {
17712 to = frag_more (2);
17713#ifdef OBJ_ELF
17714 dwarf2_emit_insn (2);
17715#endif
17716 }
17717
17718 md_number_to_chars (to, instruction, 2);
17719
17720 return to;
17721}
17722
c19d1205
ZW
17723/* Tag values used in struct asm_opcode's tag field. */
17724enum opcode_tag
17725{
17726 OT_unconditional, /* Instruction cannot be conditionalized.
17727 The ARM condition field is still 0xE. */
17728 OT_unconditionalF, /* Instruction cannot be conditionalized
17729 and carries 0xF in its ARM condition field. */
17730 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17731 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17732 suffix, others place 0xF where the condition field
17733 would be. */
c19d1205
ZW
17734 OT_cinfix3, /* Instruction takes a conditional infix,
17735 beginning at character index 3. (In
17736 unified mode, it becomes a suffix.) */
088fa78e
KH
17737 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17738 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17739 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17740 character index 3, even in unified mode. Used for
17741 legacy instructions where suffix and infix forms
17742 may be ambiguous. */
c19d1205 17743 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17744 suffix or an infix at character index 3. */
c19d1205
ZW
17745 OT_odd_infix_unc, /* This is the unconditional variant of an
17746 instruction that takes a conditional infix
17747 at an unusual position. In unified mode,
17748 this variant will accept a suffix. */
17749 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17750 are the conditional variants of instructions that
17751 take conditional infixes in unusual positions.
17752 The infix appears at character index
17753 (tag - OT_odd_infix_0). These are not accepted
17754 in unified mode. */
17755};
b99bd4ef 17756
c19d1205
ZW
17757/* Subroutine of md_assemble, responsible for looking up the primary
17758 opcode from the mnemonic the user wrote. STR points to the
17759 beginning of the mnemonic.
17760
17761 This is not simply a hash table lookup, because of conditional
17762 variants. Most instructions have conditional variants, which are
17763 expressed with a _conditional affix_ to the mnemonic. If we were
17764 to encode each conditional variant as a literal string in the opcode
17765 table, it would have approximately 20,000 entries.
17766
17767 Most mnemonics take this affix as a suffix, and in unified syntax,
17768 'most' is upgraded to 'all'. However, in the divided syntax, some
17769 instructions take the affix as an infix, notably the s-variants of
17770 the arithmetic instructions. Of those instructions, all but six
17771 have the infix appear after the third character of the mnemonic.
17772
17773 Accordingly, the algorithm for looking up primary opcodes given
17774 an identifier is:
17775
17776 1. Look up the identifier in the opcode table.
17777 If we find a match, go to step U.
17778
17779 2. Look up the last two characters of the identifier in the
17780 conditions table. If we find a match, look up the first N-2
17781 characters of the identifier in the opcode table. If we
17782 find a match, go to step CE.
17783
17784 3. Look up the fourth and fifth characters of the identifier in
17785 the conditions table. If we find a match, extract those
17786 characters from the identifier, and look up the remaining
17787 characters in the opcode table. If we find a match, go
17788 to step CM.
17789
17790 4. Fail.
17791
17792 U. Examine the tag field of the opcode structure, in case this is
17793 one of the six instructions with its conditional infix in an
17794 unusual place. If it is, the tag tells us where to find the
17795 infix; look it up in the conditions table and set inst.cond
17796 accordingly. Otherwise, this is an unconditional instruction.
17797 Again set inst.cond accordingly. Return the opcode structure.
17798
17799 CE. Examine the tag field to make sure this is an instruction that
17800 should receive a conditional suffix. If it is not, fail.
17801 Otherwise, set inst.cond from the suffix we already looked up,
17802 and return the opcode structure.
17803
17804 CM. Examine the tag field to make sure this is an instruction that
17805 should receive a conditional infix after the third character.
17806 If it is not, fail. Otherwise, undo the edits to the current
17807 line of input and proceed as for case CE. */
17808
17809static const struct asm_opcode *
17810opcode_lookup (char **str)
17811{
17812 char *end, *base;
17813 char *affix;
17814 const struct asm_opcode *opcode;
17815 const struct asm_cond *cond;
e3cb604e 17816 char save[2];
c19d1205
ZW
17817
17818 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17819 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17820 for (base = end = *str; *end != '\0'; end++)
721a8186 17821 if (*end == ' ' || *end == '.')
c19d1205 17822 break;
b99bd4ef 17823
c19d1205 17824 if (end == base)
c921be7d 17825 return NULL;
b99bd4ef 17826
5287ad62 17827 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17828 if (end[0] == '.')
b99bd4ef 17829 {
5287ad62 17830 int offset = 2;
5f4273c7 17831
267d2029 17832 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17833 use. */
267d2029 17834 if (unified_syntax && end[1] == 'w')
c19d1205 17835 inst.size_req = 4;
267d2029 17836 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17837 inst.size_req = 2;
17838 else
477330fc 17839 offset = 0;
5287ad62
JB
17840
17841 inst.vectype.elems = 0;
17842
17843 *str = end + offset;
b99bd4ef 17844
5f4273c7 17845 if (end[offset] == '.')
5287ad62 17846 {
267d2029 17847 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17848 non-unified ARM syntax mode). */
17849 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17850 return NULL;
477330fc 17851 }
5287ad62 17852 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17853 return NULL;
b99bd4ef 17854 }
c19d1205
ZW
17855 else
17856 *str = end;
b99bd4ef 17857
c19d1205 17858 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17859 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17860 end - base);
c19d1205 17861 if (opcode)
b99bd4ef 17862 {
c19d1205
ZW
17863 /* step U */
17864 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17865 {
c19d1205
ZW
17866 inst.cond = COND_ALWAYS;
17867 return opcode;
b99bd4ef 17868 }
b99bd4ef 17869
278df34e 17870 if (warn_on_deprecated && unified_syntax)
5c3696f8 17871 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17872 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17873 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17874 gas_assert (cond);
b99bd4ef 17875
c19d1205
ZW
17876 inst.cond = cond->value;
17877 return opcode;
17878 }
b99bd4ef 17879
c19d1205
ZW
17880 /* Cannot have a conditional suffix on a mnemonic of less than two
17881 characters. */
17882 if (end - base < 3)
c921be7d 17883 return NULL;
b99bd4ef 17884
c19d1205
ZW
17885 /* Look for suffixed mnemonic. */
17886 affix = end - 2;
21d799b5
NC
17887 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17888 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17889 affix - base);
c19d1205
ZW
17890 if (opcode && cond)
17891 {
17892 /* step CE */
17893 switch (opcode->tag)
17894 {
e3cb604e
PB
17895 case OT_cinfix3_legacy:
17896 /* Ignore conditional suffixes matched on infix only mnemonics. */
17897 break;
17898
c19d1205 17899 case OT_cinfix3:
088fa78e 17900 case OT_cinfix3_deprecated:
c19d1205
ZW
17901 case OT_odd_infix_unc:
17902 if (!unified_syntax)
e3cb604e 17903 return 0;
1a0670f3 17904 /* Fall through. */
c19d1205
ZW
17905
17906 case OT_csuffix:
477330fc 17907 case OT_csuffixF:
c19d1205
ZW
17908 case OT_csuf_or_in3:
17909 inst.cond = cond->value;
17910 return opcode;
17911
17912 case OT_unconditional:
17913 case OT_unconditionalF:
dfa9f0d5 17914 if (thumb_mode)
c921be7d 17915 inst.cond = cond->value;
dfa9f0d5
PB
17916 else
17917 {
c921be7d 17918 /* Delayed diagnostic. */
dfa9f0d5
PB
17919 inst.error = BAD_COND;
17920 inst.cond = COND_ALWAYS;
17921 }
c19d1205 17922 return opcode;
b99bd4ef 17923
c19d1205 17924 default:
c921be7d 17925 return NULL;
c19d1205
ZW
17926 }
17927 }
b99bd4ef 17928
c19d1205
ZW
17929 /* Cannot have a usual-position infix on a mnemonic of less than
17930 six characters (five would be a suffix). */
17931 if (end - base < 6)
c921be7d 17932 return NULL;
b99bd4ef 17933
c19d1205
ZW
17934 /* Look for infixed mnemonic in the usual position. */
17935 affix = base + 3;
21d799b5 17936 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17937 if (!cond)
c921be7d 17938 return NULL;
e3cb604e
PB
17939
17940 memcpy (save, affix, 2);
17941 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17942 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17943 (end - base) - 2);
e3cb604e
PB
17944 memmove (affix + 2, affix, (end - affix) - 2);
17945 memcpy (affix, save, 2);
17946
088fa78e
KH
17947 if (opcode
17948 && (opcode->tag == OT_cinfix3
17949 || opcode->tag == OT_cinfix3_deprecated
17950 || opcode->tag == OT_csuf_or_in3
17951 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17952 {
c921be7d 17953 /* Step CM. */
278df34e 17954 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17955 && (opcode->tag == OT_cinfix3
17956 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17957 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17958
17959 inst.cond = cond->value;
17960 return opcode;
b99bd4ef
NC
17961 }
17962
c921be7d 17963 return NULL;
b99bd4ef
NC
17964}
17965
e07e6e58
NC
17966/* This function generates an initial IT instruction, leaving its block
17967 virtually open for the new instructions. Eventually,
17968 the mask will be updated by now_it_add_mask () each time
17969 a new instruction needs to be included in the IT block.
17970 Finally, the block is closed with close_automatic_it_block ().
17971 The block closure can be requested either from md_assemble (),
17972 a tencode (), or due to a label hook. */
17973
17974static void
17975new_automatic_it_block (int cond)
17976{
17977 now_it.state = AUTOMATIC_IT_BLOCK;
17978 now_it.mask = 0x18;
17979 now_it.cc = cond;
17980 now_it.block_length = 1;
cd000bff 17981 mapping_state (MAP_THUMB);
e07e6e58 17982 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17983 now_it.warn_deprecated = FALSE;
17984 now_it.insn_cond = TRUE;
e07e6e58
NC
17985}
17986
17987/* Close an automatic IT block.
17988 See comments in new_automatic_it_block (). */
17989
17990static void
17991close_automatic_it_block (void)
17992{
17993 now_it.mask = 0x10;
17994 now_it.block_length = 0;
17995}
17996
17997/* Update the mask of the current automatically-generated IT
17998 instruction. See comments in new_automatic_it_block (). */
17999
18000static void
18001now_it_add_mask (int cond)
18002{
18003#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18004#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18005 | ((bitvalue) << (nbit)))
e07e6e58 18006 const int resulting_bit = (cond & 1);
c921be7d 18007
e07e6e58
NC
18008 now_it.mask &= 0xf;
18009 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18010 resulting_bit,
18011 (5 - now_it.block_length));
e07e6e58 18012 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18013 1,
18014 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18015 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18016
18017#undef CLEAR_BIT
18018#undef SET_BIT_VALUE
e07e6e58
NC
18019}
18020
18021/* The IT blocks handling machinery is accessed through the these functions:
18022 it_fsm_pre_encode () from md_assemble ()
18023 set_it_insn_type () optional, from the tencode functions
18024 set_it_insn_type_last () ditto
18025 in_it_block () ditto
18026 it_fsm_post_encode () from md_assemble ()
33eaf5de 18027 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18028
18029 Rationale:
18030 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18031 initializing the IT insn type with a generic initial value depending
18032 on the inst.condition.
e07e6e58 18033 2) During the tencode function, two things may happen:
477330fc
RM
18034 a) The tencode function overrides the IT insn type by
18035 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18036 b) The tencode function queries the IT block state by
18037 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18038
18039 Both set_it_insn_type and in_it_block run the internal FSM state
18040 handling function (handle_it_state), because: a) setting the IT insn
18041 type may incur in an invalid state (exiting the function),
18042 and b) querying the state requires the FSM to be updated.
18043 Specifically we want to avoid creating an IT block for conditional
18044 branches, so it_fsm_pre_encode is actually a guess and we can't
18045 determine whether an IT block is required until the tencode () routine
18046 has decided what type of instruction this actually it.
18047 Because of this, if set_it_insn_type and in_it_block have to be used,
18048 set_it_insn_type has to be called first.
18049
18050 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18051 determines the insn IT type depending on the inst.cond code.
18052 When a tencode () routine encodes an instruction that can be
18053 either outside an IT block, or, in the case of being inside, has to be
18054 the last one, set_it_insn_type_last () will determine the proper
18055 IT instruction type based on the inst.cond code. Otherwise,
18056 set_it_insn_type can be called for overriding that logic or
18057 for covering other cases.
18058
18059 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18060 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18061 still queried. Instead, if the FSM determines that the state should
18062 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18063 after the tencode () function: that's what it_fsm_post_encode () does.
18064
18065 Since in_it_block () calls the state handling function to get an
18066 updated state, an error may occur (due to invalid insns combination).
18067 In that case, inst.error is set.
18068 Therefore, inst.error has to be checked after the execution of
18069 the tencode () routine.
e07e6e58
NC
18070
18071 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18072 any pending state change (if any) that didn't take place in
18073 handle_it_state () as explained above. */
e07e6e58
NC
18074
18075static void
18076it_fsm_pre_encode (void)
18077{
18078 if (inst.cond != COND_ALWAYS)
18079 inst.it_insn_type = INSIDE_IT_INSN;
18080 else
18081 inst.it_insn_type = OUTSIDE_IT_INSN;
18082
18083 now_it.state_handled = 0;
18084}
18085
18086/* IT state FSM handling function. */
18087
18088static int
18089handle_it_state (void)
18090{
18091 now_it.state_handled = 1;
5a01bb1d 18092 now_it.insn_cond = FALSE;
e07e6e58
NC
18093
18094 switch (now_it.state)
18095 {
18096 case OUTSIDE_IT_BLOCK:
18097 switch (inst.it_insn_type)
18098 {
18099 case OUTSIDE_IT_INSN:
18100 break;
18101
18102 case INSIDE_IT_INSN:
18103 case INSIDE_IT_LAST_INSN:
18104 if (thumb_mode == 0)
18105 {
c921be7d 18106 if (unified_syntax
e07e6e58
NC
18107 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18108 as_tsktsk (_("Warning: conditional outside an IT block"\
18109 " for Thumb."));
18110 }
18111 else
18112 {
18113 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18114 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18115 {
18116 /* Automatically generate the IT instruction. */
18117 new_automatic_it_block (inst.cond);
18118 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18119 close_automatic_it_block ();
18120 }
18121 else
18122 {
18123 inst.error = BAD_OUT_IT;
18124 return FAIL;
18125 }
18126 }
18127 break;
18128
18129 case IF_INSIDE_IT_LAST_INSN:
18130 case NEUTRAL_IT_INSN:
18131 break;
18132
18133 case IT_INSN:
18134 now_it.state = MANUAL_IT_BLOCK;
18135 now_it.block_length = 0;
18136 break;
18137 }
18138 break;
18139
18140 case AUTOMATIC_IT_BLOCK:
18141 /* Three things may happen now:
18142 a) We should increment current it block size;
18143 b) We should close current it block (closing insn or 4 insns);
18144 c) We should close current it block and start a new one (due
18145 to incompatible conditions or
18146 4 insns-length block reached). */
18147
18148 switch (inst.it_insn_type)
18149 {
18150 case OUTSIDE_IT_INSN:
2b0f3761 18151 /* The closure of the block shall happen immediately,
e07e6e58
NC
18152 so any in_it_block () call reports the block as closed. */
18153 force_automatic_it_block_close ();
18154 break;
18155
18156 case INSIDE_IT_INSN:
18157 case INSIDE_IT_LAST_INSN:
18158 case IF_INSIDE_IT_LAST_INSN:
18159 now_it.block_length++;
18160
18161 if (now_it.block_length > 4
18162 || !now_it_compatible (inst.cond))
18163 {
18164 force_automatic_it_block_close ();
18165 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18166 new_automatic_it_block (inst.cond);
18167 }
18168 else
18169 {
5a01bb1d 18170 now_it.insn_cond = TRUE;
e07e6e58
NC
18171 now_it_add_mask (inst.cond);
18172 }
18173
18174 if (now_it.state == AUTOMATIC_IT_BLOCK
18175 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18176 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18177 close_automatic_it_block ();
18178 break;
18179
18180 case NEUTRAL_IT_INSN:
18181 now_it.block_length++;
5a01bb1d 18182 now_it.insn_cond = TRUE;
e07e6e58
NC
18183
18184 if (now_it.block_length > 4)
18185 force_automatic_it_block_close ();
18186 else
18187 now_it_add_mask (now_it.cc & 1);
18188 break;
18189
18190 case IT_INSN:
18191 close_automatic_it_block ();
18192 now_it.state = MANUAL_IT_BLOCK;
18193 break;
18194 }
18195 break;
18196
18197 case MANUAL_IT_BLOCK:
18198 {
18199 /* Check conditional suffixes. */
18200 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18201 int is_last;
18202 now_it.mask <<= 1;
18203 now_it.mask &= 0x1f;
18204 is_last = (now_it.mask == 0x10);
5a01bb1d 18205 now_it.insn_cond = TRUE;
e07e6e58
NC
18206
18207 switch (inst.it_insn_type)
18208 {
18209 case OUTSIDE_IT_INSN:
18210 inst.error = BAD_NOT_IT;
18211 return FAIL;
18212
18213 case INSIDE_IT_INSN:
18214 if (cond != inst.cond)
18215 {
18216 inst.error = BAD_IT_COND;
18217 return FAIL;
18218 }
18219 break;
18220
18221 case INSIDE_IT_LAST_INSN:
18222 case IF_INSIDE_IT_LAST_INSN:
18223 if (cond != inst.cond)
18224 {
18225 inst.error = BAD_IT_COND;
18226 return FAIL;
18227 }
18228 if (!is_last)
18229 {
18230 inst.error = BAD_BRANCH;
18231 return FAIL;
18232 }
18233 break;
18234
18235 case NEUTRAL_IT_INSN:
18236 /* The BKPT instruction is unconditional even in an IT block. */
18237 break;
18238
18239 case IT_INSN:
18240 inst.error = BAD_IT_IT;
18241 return FAIL;
18242 }
18243 }
18244 break;
18245 }
18246
18247 return SUCCESS;
18248}
18249
5a01bb1d
MGD
18250struct depr_insn_mask
18251{
18252 unsigned long pattern;
18253 unsigned long mask;
18254 const char* description;
18255};
18256
18257/* List of 16-bit instruction patterns deprecated in an IT block in
18258 ARMv8. */
18259static const struct depr_insn_mask depr_it_insns[] = {
18260 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18261 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18262 { 0xa000, 0xb800, N_("ADR") },
18263 { 0x4800, 0xf800, N_("Literal loads") },
18264 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18265 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18266 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18267 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18268 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18269 { 0, 0, NULL }
18270};
18271
e07e6e58
NC
18272static void
18273it_fsm_post_encode (void)
18274{
18275 int is_last;
18276
18277 if (!now_it.state_handled)
18278 handle_it_state ();
18279
5a01bb1d
MGD
18280 if (now_it.insn_cond
18281 && !now_it.warn_deprecated
18282 && warn_on_deprecated
18283 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18284 {
18285 if (inst.instruction >= 0x10000)
18286 {
5c3696f8 18287 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18288 "deprecated in ARMv8"));
18289 now_it.warn_deprecated = TRUE;
18290 }
18291 else
18292 {
18293 const struct depr_insn_mask *p = depr_it_insns;
18294
18295 while (p->mask != 0)
18296 {
18297 if ((inst.instruction & p->mask) == p->pattern)
18298 {
5c3696f8 18299 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18300 "of the following class are deprecated in ARMv8: "
18301 "%s"), p->description);
18302 now_it.warn_deprecated = TRUE;
18303 break;
18304 }
18305
18306 ++p;
18307 }
18308 }
18309
18310 if (now_it.block_length > 1)
18311 {
5c3696f8 18312 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18313 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18314 now_it.warn_deprecated = TRUE;
18315 }
18316 }
18317
e07e6e58
NC
18318 is_last = (now_it.mask == 0x10);
18319 if (is_last)
18320 {
18321 now_it.state = OUTSIDE_IT_BLOCK;
18322 now_it.mask = 0;
18323 }
18324}
18325
18326static void
18327force_automatic_it_block_close (void)
18328{
18329 if (now_it.state == AUTOMATIC_IT_BLOCK)
18330 {
18331 close_automatic_it_block ();
18332 now_it.state = OUTSIDE_IT_BLOCK;
18333 now_it.mask = 0;
18334 }
18335}
18336
18337static int
18338in_it_block (void)
18339{
18340 if (!now_it.state_handled)
18341 handle_it_state ();
18342
18343 return now_it.state != OUTSIDE_IT_BLOCK;
18344}
18345
ff8646ee
TP
18346/* Whether OPCODE only has T32 encoding. Since this function is only used by
18347 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18348 here, hence the "known" in the function name. */
fc289b0a
TP
18349
18350static bfd_boolean
ff8646ee 18351known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18352{
18353 /* Original Thumb-1 wide instruction. */
18354 if (opcode->tencode == do_t_blx
18355 || opcode->tencode == do_t_branch23
18356 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18357 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18358 return TRUE;
18359
16a1fa25
TP
18360 /* Wide-only instruction added to ARMv8-M Baseline. */
18361 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18362 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18363 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18364 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18365 return TRUE;
18366
18367 return FALSE;
18368}
18369
18370/* Whether wide instruction variant can be used if available for a valid OPCODE
18371 in ARCH. */
18372
18373static bfd_boolean
18374t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18375{
18376 if (known_t32_only_insn (opcode))
18377 return TRUE;
18378
18379 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18380 of variant T3 of B.W is checked in do_t_branch. */
18381 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18382 && opcode->tencode == do_t_branch)
18383 return TRUE;
18384
bada4342
JW
18385 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18386 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18387 && opcode->tencode == do_t_mov_cmp
18388 /* Make sure CMP instruction is not affected. */
18389 && opcode->aencode == do_mov)
18390 return TRUE;
18391
ff8646ee
TP
18392 /* Wide instruction variants of all instructions with narrow *and* wide
18393 variants become available with ARMv6t2. Other opcodes are either
18394 narrow-only or wide-only and are thus available if OPCODE is valid. */
18395 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18396 return TRUE;
18397
18398 /* OPCODE with narrow only instruction variant or wide variant not
18399 available. */
fc289b0a
TP
18400 return FALSE;
18401}
18402
c19d1205
ZW
18403void
18404md_assemble (char *str)
b99bd4ef 18405{
c19d1205
ZW
18406 char *p = str;
18407 const struct asm_opcode * opcode;
b99bd4ef 18408
c19d1205
ZW
18409 /* Align the previous label if needed. */
18410 if (last_label_seen != NULL)
b99bd4ef 18411 {
c19d1205
ZW
18412 symbol_set_frag (last_label_seen, frag_now);
18413 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18414 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18415 }
18416
c19d1205
ZW
18417 memset (&inst, '\0', sizeof (inst));
18418 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18419
c19d1205
ZW
18420 opcode = opcode_lookup (&p);
18421 if (!opcode)
b99bd4ef 18422 {
c19d1205 18423 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18424 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18425 if (! create_register_alias (str, p)
477330fc 18426 && ! create_neon_reg_alias (str, p))
c19d1205 18427 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18428
b99bd4ef
NC
18429 return;
18430 }
18431
278df34e 18432 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18433 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18434
037e8744
JB
18435 /* The value which unconditional instructions should have in place of the
18436 condition field. */
18437 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18438
c19d1205 18439 if (thumb_mode)
b99bd4ef 18440 {
e74cfd16 18441 arm_feature_set variant;
8f06b2d8
PB
18442
18443 variant = cpu_variant;
18444 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18445 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18446 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18447 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18448 if (!opcode->tvariant
18449 || (thumb_mode == 1
18450 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18451 {
84b52b66 18452 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18453 return;
18454 }
c19d1205
ZW
18455 if (inst.cond != COND_ALWAYS && !unified_syntax
18456 && opcode->tencode != do_t_branch)
b99bd4ef 18457 {
c19d1205 18458 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18459 return;
18460 }
18461
fc289b0a
TP
18462 /* Two things are addressed here:
18463 1) Implicit require narrow instructions on Thumb-1.
18464 This avoids relaxation accidentally introducing Thumb-2
18465 instructions.
18466 2) Reject wide instructions in non Thumb-2 cores.
18467
18468 Only instructions with narrow and wide variants need to be handled
18469 but selecting all non wide-only instructions is easier. */
18470 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18471 && !t32_insn_ok (variant, opcode))
076d447c 18472 {
fc289b0a
TP
18473 if (inst.size_req == 0)
18474 inst.size_req = 2;
18475 else if (inst.size_req == 4)
752d5da4 18476 {
ff8646ee
TP
18477 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18478 as_bad (_("selected processor does not support 32bit wide "
18479 "variant of instruction `%s'"), str);
18480 else
18481 as_bad (_("selected processor does not support `%s' in "
18482 "Thumb-2 mode"), str);
fc289b0a 18483 return;
752d5da4 18484 }
076d447c
PB
18485 }
18486
c19d1205
ZW
18487 inst.instruction = opcode->tvalue;
18488
5be8be5d 18489 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18490 {
18491 /* Prepare the it_insn_type for those encodings that don't set
18492 it. */
18493 it_fsm_pre_encode ();
c19d1205 18494
477330fc 18495 opcode->tencode ();
e07e6e58 18496
477330fc
RM
18497 it_fsm_post_encode ();
18498 }
e27ec89e 18499
0110f2b8 18500 if (!(inst.error || inst.relax))
b99bd4ef 18501 {
9c2799c2 18502 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18503 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18504 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18505 {
c19d1205 18506 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18507 return;
18508 }
18509 }
076d447c
PB
18510
18511 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18512 instruction. */
9c2799c2 18513 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18514
e74cfd16
PB
18515 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18516 *opcode->tvariant);
ee065d83 18517 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18518 set those bits when Thumb-2 32-bit instructions are seen. The impact
18519 of relaxable instructions will be considered later after we finish all
18520 relaxation. */
ff8646ee
TP
18521 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18522 variant = arm_arch_none;
18523 else
18524 variant = cpu_variant;
18525 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18526 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18527 arm_ext_v6t2);
cd000bff 18528
88714cb8
DG
18529 check_neon_suffixes;
18530
cd000bff 18531 if (!inst.error)
c877a2f2
NC
18532 {
18533 mapping_state (MAP_THUMB);
18534 }
c19d1205 18535 }
3e9e4fcf 18536 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18537 {
845b51d6
PB
18538 bfd_boolean is_bx;
18539
18540 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18541 is_bx = (opcode->aencode == do_bx);
18542
c19d1205 18543 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18544 if (!(is_bx && fix_v4bx)
18545 && !(opcode->avariant &&
18546 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18547 {
84b52b66 18548 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18549 return;
b99bd4ef 18550 }
c19d1205 18551 if (inst.size_req)
b99bd4ef 18552 {
c19d1205
ZW
18553 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18554 return;
b99bd4ef
NC
18555 }
18556
c19d1205
ZW
18557 inst.instruction = opcode->avalue;
18558 if (opcode->tag == OT_unconditionalF)
eff0bc54 18559 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18560 else
18561 inst.instruction |= inst.cond << 28;
18562 inst.size = INSN_SIZE;
5be8be5d 18563 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18564 {
18565 it_fsm_pre_encode ();
18566 opcode->aencode ();
18567 it_fsm_post_encode ();
18568 }
ee065d83 18569 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18570 on a hypothetical non-thumb v5 core. */
845b51d6 18571 if (is_bx)
e74cfd16 18572 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18573 else
e74cfd16
PB
18574 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18575 *opcode->avariant);
88714cb8
DG
18576
18577 check_neon_suffixes;
18578
cd000bff 18579 if (!inst.error)
c877a2f2
NC
18580 {
18581 mapping_state (MAP_ARM);
18582 }
b99bd4ef 18583 }
3e9e4fcf
JB
18584 else
18585 {
18586 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18587 "-- `%s'"), str);
18588 return;
18589 }
c19d1205
ZW
18590 output_inst (str);
18591}
b99bd4ef 18592
e07e6e58
NC
18593static void
18594check_it_blocks_finished (void)
18595{
18596#ifdef OBJ_ELF
18597 asection *sect;
18598
18599 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18600 if (seg_info (sect)->tc_segment_info_data.current_it.state
18601 == MANUAL_IT_BLOCK)
18602 {
18603 as_warn (_("section '%s' finished with an open IT block."),
18604 sect->name);
18605 }
18606#else
18607 if (now_it.state == MANUAL_IT_BLOCK)
18608 as_warn (_("file finished with an open IT block."));
18609#endif
18610}
18611
c19d1205
ZW
18612/* Various frobbings of labels and their addresses. */
18613
18614void
18615arm_start_line_hook (void)
18616{
18617 last_label_seen = NULL;
b99bd4ef
NC
18618}
18619
c19d1205
ZW
18620void
18621arm_frob_label (symbolS * sym)
b99bd4ef 18622{
c19d1205 18623 last_label_seen = sym;
b99bd4ef 18624
c19d1205 18625 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18626
c19d1205
ZW
18627#if defined OBJ_COFF || defined OBJ_ELF
18628 ARM_SET_INTERWORK (sym, support_interwork);
18629#endif
b99bd4ef 18630
e07e6e58
NC
18631 force_automatic_it_block_close ();
18632
5f4273c7 18633 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18634 as Thumb functions. This is because these labels, whilst
18635 they exist inside Thumb code, are not the entry points for
18636 possible ARM->Thumb calls. Also, these labels can be used
18637 as part of a computed goto or switch statement. eg gcc
18638 can generate code that looks like this:
b99bd4ef 18639
c19d1205
ZW
18640 ldr r2, [pc, .Laaa]
18641 lsl r3, r3, #2
18642 ldr r2, [r3, r2]
18643 mov pc, r2
b99bd4ef 18644
c19d1205
ZW
18645 .Lbbb: .word .Lxxx
18646 .Lccc: .word .Lyyy
18647 ..etc...
18648 .Laaa: .word Lbbb
b99bd4ef 18649
c19d1205
ZW
18650 The first instruction loads the address of the jump table.
18651 The second instruction converts a table index into a byte offset.
18652 The third instruction gets the jump address out of the table.
18653 The fourth instruction performs the jump.
b99bd4ef 18654
c19d1205
ZW
18655 If the address stored at .Laaa is that of a symbol which has the
18656 Thumb_Func bit set, then the linker will arrange for this address
18657 to have the bottom bit set, which in turn would mean that the
18658 address computation performed by the third instruction would end
18659 up with the bottom bit set. Since the ARM is capable of unaligned
18660 word loads, the instruction would then load the incorrect address
18661 out of the jump table, and chaos would ensue. */
18662 if (label_is_thumb_function_name
18663 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18664 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18665 {
c19d1205
ZW
18666 /* When the address of a Thumb function is taken the bottom
18667 bit of that address should be set. This will allow
18668 interworking between Arm and Thumb functions to work
18669 correctly. */
b99bd4ef 18670
c19d1205 18671 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18672
c19d1205 18673 label_is_thumb_function_name = FALSE;
b99bd4ef 18674 }
07a53e5c 18675
07a53e5c 18676 dwarf2_emit_label (sym);
b99bd4ef
NC
18677}
18678
c921be7d 18679bfd_boolean
c19d1205 18680arm_data_in_code (void)
b99bd4ef 18681{
c19d1205 18682 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18683 {
c19d1205
ZW
18684 *input_line_pointer = '/';
18685 input_line_pointer += 5;
18686 *input_line_pointer = 0;
c921be7d 18687 return TRUE;
b99bd4ef
NC
18688 }
18689
c921be7d 18690 return FALSE;
b99bd4ef
NC
18691}
18692
c19d1205
ZW
18693char *
18694arm_canonicalize_symbol_name (char * name)
b99bd4ef 18695{
c19d1205 18696 int len;
b99bd4ef 18697
c19d1205
ZW
18698 if (thumb_mode && (len = strlen (name)) > 5
18699 && streq (name + len - 5, "/data"))
18700 *(name + len - 5) = 0;
b99bd4ef 18701
c19d1205 18702 return name;
b99bd4ef 18703}
c19d1205
ZW
18704\f
18705/* Table of all register names defined by default. The user can
18706 define additional names with .req. Note that all register names
18707 should appear in both upper and lowercase variants. Some registers
18708 also have mixed-case names. */
b99bd4ef 18709
dcbf9037 18710#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18711#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18712#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18713#define REGSET(p,t) \
18714 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18715 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18716 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18717 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18718#define REGSETH(p,t) \
18719 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18720 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18721 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18722 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18723#define REGSET2(p,t) \
18724 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18725 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18726 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18727 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18728#define SPLRBANK(base,bank,t) \
18729 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18730 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18731 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18732 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18733 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18734 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18735
c19d1205 18736static const struct reg_entry reg_names[] =
7ed4c4c5 18737{
c19d1205
ZW
18738 /* ARM integer registers. */
18739 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18740
c19d1205
ZW
18741 /* ATPCS synonyms. */
18742 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18743 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18744 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18745
c19d1205
ZW
18746 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18747 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18748 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18749
c19d1205
ZW
18750 /* Well-known aliases. */
18751 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18752 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18753
18754 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18755 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18756
18757 /* Coprocessor numbers. */
18758 REGSET(p, CP), REGSET(P, CP),
18759
18760 /* Coprocessor register numbers. The "cr" variants are for backward
18761 compatibility. */
18762 REGSET(c, CN), REGSET(C, CN),
18763 REGSET(cr, CN), REGSET(CR, CN),
18764
90ec0d68
MGD
18765 /* ARM banked registers. */
18766 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18767 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18768 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18769 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18770 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18771 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18772 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18773
18774 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18775 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18776 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18777 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18778 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18779 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18780 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18781 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18782
18783 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18784 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18785 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18786 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18787 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18788 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18789 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18790 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18791 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18792
c19d1205
ZW
18793 /* FPA registers. */
18794 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18795 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18796
18797 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18798 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18799
18800 /* VFP SP registers. */
5287ad62
JB
18801 REGSET(s,VFS), REGSET(S,VFS),
18802 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18803
18804 /* VFP DP Registers. */
5287ad62
JB
18805 REGSET(d,VFD), REGSET(D,VFD),
18806 /* Extra Neon DP registers. */
18807 REGSETH(d,VFD), REGSETH(D,VFD),
18808
18809 /* Neon QP registers. */
18810 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18811
18812 /* VFP control registers. */
18813 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18814 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18815 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18816 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18817 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18818 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18819
18820 /* Maverick DSP coprocessor registers. */
18821 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18822 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18823
18824 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18825 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18826 REGDEF(dspsc,0,DSPSC),
18827
18828 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18829 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18830 REGDEF(DSPSC,0,DSPSC),
18831
18832 /* iWMMXt data registers - p0, c0-15. */
18833 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18834
18835 /* iWMMXt control registers - p1, c0-3. */
18836 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18837 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18838 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18839 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18840
18841 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18842 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18843 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18844 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18845 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18846
18847 /* XScale accumulator registers. */
18848 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18849};
18850#undef REGDEF
18851#undef REGNUM
18852#undef REGSET
7ed4c4c5 18853
c19d1205
ZW
18854/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18855 within psr_required_here. */
18856static const struct asm_psr psrs[] =
18857{
18858 /* Backward compatibility notation. Note that "all" is no longer
18859 truly all possible PSR bits. */
18860 {"all", PSR_c | PSR_f},
18861 {"flg", PSR_f},
18862 {"ctl", PSR_c},
18863
18864 /* Individual flags. */
18865 {"f", PSR_f},
18866 {"c", PSR_c},
18867 {"x", PSR_x},
18868 {"s", PSR_s},
59b42a0d 18869
c19d1205
ZW
18870 /* Combinations of flags. */
18871 {"fs", PSR_f | PSR_s},
18872 {"fx", PSR_f | PSR_x},
18873 {"fc", PSR_f | PSR_c},
18874 {"sf", PSR_s | PSR_f},
18875 {"sx", PSR_s | PSR_x},
18876 {"sc", PSR_s | PSR_c},
18877 {"xf", PSR_x | PSR_f},
18878 {"xs", PSR_x | PSR_s},
18879 {"xc", PSR_x | PSR_c},
18880 {"cf", PSR_c | PSR_f},
18881 {"cs", PSR_c | PSR_s},
18882 {"cx", PSR_c | PSR_x},
18883 {"fsx", PSR_f | PSR_s | PSR_x},
18884 {"fsc", PSR_f | PSR_s | PSR_c},
18885 {"fxs", PSR_f | PSR_x | PSR_s},
18886 {"fxc", PSR_f | PSR_x | PSR_c},
18887 {"fcs", PSR_f | PSR_c | PSR_s},
18888 {"fcx", PSR_f | PSR_c | PSR_x},
18889 {"sfx", PSR_s | PSR_f | PSR_x},
18890 {"sfc", PSR_s | PSR_f | PSR_c},
18891 {"sxf", PSR_s | PSR_x | PSR_f},
18892 {"sxc", PSR_s | PSR_x | PSR_c},
18893 {"scf", PSR_s | PSR_c | PSR_f},
18894 {"scx", PSR_s | PSR_c | PSR_x},
18895 {"xfs", PSR_x | PSR_f | PSR_s},
18896 {"xfc", PSR_x | PSR_f | PSR_c},
18897 {"xsf", PSR_x | PSR_s | PSR_f},
18898 {"xsc", PSR_x | PSR_s | PSR_c},
18899 {"xcf", PSR_x | PSR_c | PSR_f},
18900 {"xcs", PSR_x | PSR_c | PSR_s},
18901 {"cfs", PSR_c | PSR_f | PSR_s},
18902 {"cfx", PSR_c | PSR_f | PSR_x},
18903 {"csf", PSR_c | PSR_s | PSR_f},
18904 {"csx", PSR_c | PSR_s | PSR_x},
18905 {"cxf", PSR_c | PSR_x | PSR_f},
18906 {"cxs", PSR_c | PSR_x | PSR_s},
18907 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18908 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18909 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18910 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18911 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18912 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18913 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18914 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18915 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18916 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18917 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18918 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18919 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18920 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18921 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18922 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18923 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18924 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18925 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18926 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18927 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18928 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18929 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18930 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18931};
18932
62b3e311
PB
18933/* Table of V7M psr names. */
18934static const struct asm_psr v7m_psrs[] =
18935{
1a336194
TP
18936 {"apsr", 0x0 }, {"APSR", 0x0 },
18937 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
18938 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
18939 {"psr", 0x3 }, {"PSR", 0x3 },
18940 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
18941 {"ipsr", 0x5 }, {"IPSR", 0x5 },
18942 {"epsr", 0x6 }, {"EPSR", 0x6 },
18943 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
18944 {"msp", 0x8 }, {"MSP", 0x8 },
18945 {"psp", 0x9 }, {"PSP", 0x9 },
18946 {"msplim", 0xa }, {"MSPLIM", 0xa },
18947 {"psplim", 0xb }, {"PSPLIM", 0xb },
18948 {"primask", 0x10}, {"PRIMASK", 0x10},
18949 {"basepri", 0x11}, {"BASEPRI", 0x11},
18950 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
18951 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
18952 {"control", 0x14}, {"CONTROL", 0x14},
18953 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18954 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
18955 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
18956 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
18957 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
18958 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
18959 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
18960 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
18961 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
18962};
18963
c19d1205
ZW
18964/* Table of all shift-in-operand names. */
18965static const struct asm_shift_name shift_names [] =
b99bd4ef 18966{
c19d1205
ZW
18967 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18968 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18969 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18970 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18971 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18972 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18973};
b99bd4ef 18974
c19d1205
ZW
18975/* Table of all explicit relocation names. */
18976#ifdef OBJ_ELF
18977static struct reloc_entry reloc_names[] =
18978{
18979 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18980 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18981 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18982 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18983 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18984 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18985 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18986 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18987 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18988 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18989 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18990 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18991 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18992 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18993 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18994 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18995 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18996 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18997};
18998#endif
b99bd4ef 18999
c19d1205
ZW
19000/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19001static const struct asm_cond conds[] =
19002{
19003 {"eq", 0x0},
19004 {"ne", 0x1},
19005 {"cs", 0x2}, {"hs", 0x2},
19006 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19007 {"mi", 0x4},
19008 {"pl", 0x5},
19009 {"vs", 0x6},
19010 {"vc", 0x7},
19011 {"hi", 0x8},
19012 {"ls", 0x9},
19013 {"ge", 0xa},
19014 {"lt", 0xb},
19015 {"gt", 0xc},
19016 {"le", 0xd},
19017 {"al", 0xe}
19018};
bfae80f2 19019
e797f7e0 19020#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19021 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19022 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19023
62b3e311
PB
19024static struct asm_barrier_opt barrier_opt_names[] =
19025{
e797f7e0
MGD
19026 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19027 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19028 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19029 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19030 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19031 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19032 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19033 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19034 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19035 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19036 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19037 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19038 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19039 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19040 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19041 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19042};
19043
e797f7e0
MGD
19044#undef UL_BARRIER
19045
c19d1205
ZW
19046/* Table of ARM-format instructions. */
19047
19048/* Macros for gluing together operand strings. N.B. In all cases
19049 other than OPS0, the trailing OP_stop comes from default
19050 zero-initialization of the unspecified elements of the array. */
19051#define OPS0() { OP_stop, }
19052#define OPS1(a) { OP_##a, }
19053#define OPS2(a,b) { OP_##a,OP_##b, }
19054#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19055#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19056#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19057#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19058
5be8be5d
DG
19059/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19060 This is useful when mixing operands for ARM and THUMB, i.e. using the
19061 MIX_ARM_THUMB_OPERANDS macro.
19062 In order to use these macros, prefix the number of operands with _
19063 e.g. _3. */
19064#define OPS_1(a) { a, }
19065#define OPS_2(a,b) { a,b, }
19066#define OPS_3(a,b,c) { a,b,c, }
19067#define OPS_4(a,b,c,d) { a,b,c,d, }
19068#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19069#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19070
c19d1205
ZW
19071/* These macros abstract out the exact format of the mnemonic table and
19072 save some repeated characters. */
19073
19074/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19075#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19076 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19077 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19078
19079/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19080 a T_MNEM_xyz enumerator. */
19081#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19082 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19083#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19084 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19085
19086/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19087 infix after the third character. */
19088#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19089 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19090 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19091#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19092 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19093 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19094#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19095 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19096#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19097 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19098#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19099 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19100#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19101 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19102
c19d1205 19103/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19104 field is still 0xE. Many of the Thumb variants can be executed
19105 conditionally, so this is checked separately. */
c19d1205 19106#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19107 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19108 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19109
dd5181d5
KT
19110/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19111 Used by mnemonics that have very minimal differences in the encoding for
19112 ARM and Thumb variants and can be handled in a common function. */
19113#define TUEc(mnem, op, top, nops, ops, en) \
19114 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19115 THUMB_VARIANT, do_##en, do_##en }
19116
c19d1205
ZW
19117/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19118 condition code field. */
19119#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19120 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19121 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19122
19123/* ARM-only variants of all the above. */
6a86118a 19124#define CE(mnem, op, nops, ops, ae) \
21d799b5 19125 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19126
19127#define C3(mnem, op, nops, ops, ae) \
19128 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19129
e3cb604e
PB
19130/* Legacy mnemonics that always have conditional infix after the third
19131 character. */
19132#define CL(mnem, op, nops, ops, ae) \
21d799b5 19133 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19134 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19135
8f06b2d8
PB
19136/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19137#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19138 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19139
e3cb604e
PB
19140/* Legacy coprocessor instructions where conditional infix and conditional
19141 suffix are ambiguous. For consistency this includes all FPA instructions,
19142 not just the potentially ambiguous ones. */
19143#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19144 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19145 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19146
19147/* Coprocessor, takes either a suffix or a position-3 infix
19148 (for an FPA corner case). */
19149#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19150 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19151 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19152
6a86118a 19153#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19154 { m1 #m2 m3, OPS##nops ops, \
19155 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19156 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19157
19158#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19159 xCM_ (m1, , m2, op, nops, ops, ae), \
19160 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19161 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19162 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19163 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19164 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19165 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19166 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19167 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19168 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19169 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19170 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19171 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19172 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19173 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19174 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19175 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19176 xCM_ (m1, le, m2, op, nops, ops, ae), \
19177 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19178
19179#define UE(mnem, op, nops, ops, ae) \
19180 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19181
19182#define UF(mnem, op, nops, ops, ae) \
19183 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19184
5287ad62
JB
19185/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19186 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19187 use the same encoding function for each. */
19188#define NUF(mnem, op, nops, ops, enc) \
19189 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19190 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19191
19192/* Neon data processing, version which indirects through neon_enc_tab for
19193 the various overloaded versions of opcodes. */
19194#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19195 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19196 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19197
19198/* Neon insn with conditional suffix for the ARM version, non-overloaded
19199 version. */
037e8744
JB
19200#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19201 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19202 THUMB_VARIANT, do_##enc, do_##enc }
19203
037e8744 19204#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19205 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19206
19207#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19208 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19209
5287ad62 19210/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19211#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19212 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19213 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19214
037e8744 19215#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19216 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19217
19218#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19219 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19220
c19d1205
ZW
19221#define do_0 0
19222
c19d1205 19223static const struct asm_opcode insns[] =
bfae80f2 19224{
74db7efb
NC
19225#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19226#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19227 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19228 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19229 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19230 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19231 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19232 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19233 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19234 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19235 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19236 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19237 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19238 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19239 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19240 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19241 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19242 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19243
19244 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19245 for setting PSR flag bits. They are obsolete in V6 and do not
19246 have Thumb equivalents. */
21d799b5
NC
19247 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19248 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19249 CL("tstp", 110f000, 2, (RR, SH), cmp),
19250 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19251 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19252 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19253 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19254 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19255 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19256
19257 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19258 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19259 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19260 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19261
19262 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19263 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19264 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19265 OP_RRnpc),
19266 OP_ADDRGLDR),ldst, t_ldst),
19267 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19268
19269 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19270 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19271 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19272 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19273 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19274 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19275
19276 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19277 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19278 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19279 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19280
c19d1205 19281 /* Pseudo ops. */
21d799b5 19282 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19283 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19284 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19285 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19286
19287 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19288 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19289 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19290 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19291 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19292 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19293 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19294 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19295 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19296 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19297 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19298 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19299 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19300
16a4cf17 19301 /* These may simplify to neg. */
21d799b5
NC
19302 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19303 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19304
c921be7d
NC
19305#undef THUMB_VARIANT
19306#define THUMB_VARIANT & arm_ext_v6
19307
21d799b5 19308 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19309
19310 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19311#undef THUMB_VARIANT
19312#define THUMB_VARIANT & arm_ext_v6t2
19313
21d799b5
NC
19314 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19315 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19316 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19317
5be8be5d
DG
19318 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19319 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19320 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19321 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19322
21d799b5
NC
19323 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19324 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19325
21d799b5
NC
19326 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19327 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19328
19329 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19330 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19331 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19332
19333 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19334 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19335 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19336 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19337 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19338 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19339 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19340 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19341
c921be7d
NC
19342#undef ARM_VARIANT
19343#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19344#undef THUMB_VARIANT
19345#define THUMB_VARIANT & arm_ext_v4t
19346
21d799b5
NC
19347 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19348 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19349
c921be7d
NC
19350#undef THUMB_VARIANT
19351#define THUMB_VARIANT & arm_ext_v6t2
19352
21d799b5 19353 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19354 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19355
19356 /* Generic coprocessor instructions. */
21d799b5
NC
19357 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19358 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19359 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19360 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19361 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19362 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19363 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19364
c921be7d
NC
19365#undef ARM_VARIANT
19366#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19367
21d799b5 19368 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19369 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19370
c921be7d
NC
19371#undef ARM_VARIANT
19372#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19373#undef THUMB_VARIANT
19374#define THUMB_VARIANT & arm_ext_msr
19375
d2cd1205
JB
19376 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19377 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19378
c921be7d
NC
19379#undef ARM_VARIANT
19380#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19381#undef THUMB_VARIANT
19382#define THUMB_VARIANT & arm_ext_v6t2
19383
21d799b5
NC
19384 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19385 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19386 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19387 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19388 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19389 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19390 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19391 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19392
c921be7d
NC
19393#undef ARM_VARIANT
19394#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19395#undef THUMB_VARIANT
19396#define THUMB_VARIANT & arm_ext_v4t
19397
5be8be5d
DG
19398 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19399 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19400 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19401 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19402 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19403 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19404
c921be7d
NC
19405#undef ARM_VARIANT
19406#define ARM_VARIANT & arm_ext_v4t_5
19407
c19d1205
ZW
19408 /* ARM Architecture 4T. */
19409 /* Note: bx (and blx) are required on V5, even if the processor does
19410 not support Thumb. */
21d799b5 19411 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19412
c921be7d
NC
19413#undef ARM_VARIANT
19414#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19415#undef THUMB_VARIANT
19416#define THUMB_VARIANT & arm_ext_v5t
19417
c19d1205
ZW
19418 /* Note: blx has 2 variants; the .value coded here is for
19419 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19420 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19421 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19422
c921be7d
NC
19423#undef THUMB_VARIANT
19424#define THUMB_VARIANT & arm_ext_v6t2
19425
21d799b5
NC
19426 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19427 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19428 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19429 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19430 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19431 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19432 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19433 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19434
c921be7d 19435#undef ARM_VARIANT
74db7efb
NC
19436#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19437#undef THUMB_VARIANT
19438#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19439
21d799b5
NC
19440 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19441 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19442 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19443 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19444
21d799b5
NC
19445 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19446 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19447
21d799b5
NC
19448 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19449 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19450 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19451 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19452
21d799b5
NC
19453 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19454 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19455 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19456 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19457
21d799b5
NC
19458 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19459 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19460
03ee1b7f
NC
19461 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19462 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19463 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19464 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19465
c921be7d 19466#undef ARM_VARIANT
74db7efb
NC
19467#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19468#undef THUMB_VARIANT
19469#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19470
21d799b5 19471 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19472 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19473 ldrd, t_ldstd),
19474 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19475 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19476
21d799b5
NC
19477 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19478 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19479
c921be7d
NC
19480#undef ARM_VARIANT
19481#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19482
21d799b5 19483 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19484
c921be7d
NC
19485#undef ARM_VARIANT
19486#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19487#undef THUMB_VARIANT
19488#define THUMB_VARIANT & arm_ext_v6
19489
21d799b5
NC
19490 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19491 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19492 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19493 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19494 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19495 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19496 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19497 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19498 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19499 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19500
c921be7d 19501#undef THUMB_VARIANT
ff8646ee 19502#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19503
5be8be5d
DG
19504 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19505 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19506 strex, t_strex),
ff8646ee
TP
19507#undef THUMB_VARIANT
19508#define THUMB_VARIANT & arm_ext_v6t2
19509
21d799b5
NC
19510 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19511 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19512
21d799b5
NC
19513 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19514 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19515
9e3c6df6 19516/* ARM V6 not included in V7M. */
c921be7d
NC
19517#undef THUMB_VARIANT
19518#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19519 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19520 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19521 UF(rfeib, 9900a00, 1, (RRw), rfe),
19522 UF(rfeda, 8100a00, 1, (RRw), rfe),
19523 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19524 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19525 UF(rfefa, 8100a00, 1, (RRw), rfe),
19526 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19527 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19528 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19529 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19530 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19531 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19532 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19533 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19534 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19535 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19536 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19537 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19538
9e3c6df6
PB
19539/* ARM V6 not included in V7M (eg. integer SIMD). */
19540#undef THUMB_VARIANT
19541#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19542 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19543 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19544 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19545 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19546 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19547 /* Old name for QASX. */
74db7efb 19548 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19549 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19550 /* Old name for QSAX. */
74db7efb 19551 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19552 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19553 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19554 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19555 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19556 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19557 /* Old name for SASX. */
74db7efb 19558 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19559 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19560 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19561 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19562 /* Old name for SHASX. */
21d799b5 19563 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19564 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19565 /* Old name for SHSAX. */
21d799b5
NC
19566 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19567 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19568 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19569 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19570 /* Old name for SSAX. */
74db7efb 19571 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19572 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19573 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19574 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19575 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19576 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19577 /* Old name for UASX. */
74db7efb 19578 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19579 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19580 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19581 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19582 /* Old name for UHASX. */
21d799b5
NC
19583 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19584 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19585 /* Old name for UHSAX. */
21d799b5
NC
19586 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19587 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19588 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19589 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19590 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19591 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19592 /* Old name for UQASX. */
21d799b5
NC
19593 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19594 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19595 /* Old name for UQSAX. */
21d799b5
NC
19596 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19597 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19598 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19599 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19600 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19601 /* Old name for USAX. */
74db7efb 19602 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19603 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19604 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19605 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19606 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19607 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19608 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19609 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19610 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19611 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19612 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19613 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19614 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19615 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19616 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19617 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19618 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19619 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19620 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19621 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19622 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19623 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19624 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19625 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19626 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19627 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19628 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19629 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19630 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19631 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19632 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19633 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19634 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19635 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19636
c921be7d
NC
19637#undef ARM_VARIANT
19638#define ARM_VARIANT & arm_ext_v6k
19639#undef THUMB_VARIANT
19640#define THUMB_VARIANT & arm_ext_v6k
19641
21d799b5
NC
19642 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19643 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19644 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19645 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19646
c921be7d
NC
19647#undef THUMB_VARIANT
19648#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19649 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19650 ldrexd, t_ldrexd),
19651 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19652 RRnpcb), strexd, t_strexd),
ebdca51a 19653
c921be7d 19654#undef THUMB_VARIANT
ff8646ee 19655#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19656 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19657 rd_rn, rd_rn),
19658 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19659 rd_rn, rd_rn),
19660 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19661 strex, t_strexbh),
5be8be5d 19662 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19663 strex, t_strexbh),
21d799b5 19664 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19665
c921be7d 19666#undef ARM_VARIANT
f4c65163 19667#define ARM_VARIANT & arm_ext_sec
74db7efb 19668#undef THUMB_VARIANT
f4c65163 19669#define THUMB_VARIANT & arm_ext_sec
c921be7d 19670
21d799b5 19671 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19672
90ec0d68
MGD
19673#undef ARM_VARIANT
19674#define ARM_VARIANT & arm_ext_virt
19675#undef THUMB_VARIANT
19676#define THUMB_VARIANT & arm_ext_virt
19677
19678 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19679 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19680
ddfded2f
MW
19681#undef ARM_VARIANT
19682#define ARM_VARIANT & arm_ext_pan
19683#undef THUMB_VARIANT
19684#define THUMB_VARIANT & arm_ext_pan
19685
19686 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19687
c921be7d 19688#undef ARM_VARIANT
74db7efb 19689#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19690#undef THUMB_VARIANT
19691#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19692
21d799b5
NC
19693 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19694 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19695 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19696 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19697
21d799b5 19698 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19699 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19700
5be8be5d
DG
19701 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19702 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19703 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19704 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19705
ff8646ee
TP
19706#undef THUMB_VARIANT
19707#define THUMB_VARIANT & arm_ext_v6t2_v8m
19708 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19709 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19710
bf3eeda7 19711 /* Thumb-only instructions. */
74db7efb 19712#undef ARM_VARIANT
bf3eeda7
NS
19713#define ARM_VARIANT NULL
19714 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19715 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19716
19717 /* ARM does not really have an IT instruction, so always allow it.
19718 The opcode is copied from Thumb in order to allow warnings in
19719 -mimplicit-it=[never | arm] modes. */
19720#undef ARM_VARIANT
19721#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19722#undef THUMB_VARIANT
19723#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19724
21d799b5
NC
19725 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19726 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19727 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19728 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19729 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19730 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19731 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19732 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19733 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19734 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19735 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19736 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19737 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19738 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19739 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19740 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19741 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19742 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19743
92e90b6e 19744 /* Thumb2 only instructions. */
c921be7d
NC
19745#undef ARM_VARIANT
19746#define ARM_VARIANT NULL
92e90b6e 19747
21d799b5
NC
19748 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19749 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19750 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19751 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19752 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19753 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19754
eea54501
MGD
19755 /* Hardware division instructions. */
19756#undef ARM_VARIANT
19757#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19758#undef THUMB_VARIANT
19759#define THUMB_VARIANT & arm_ext_div
19760
eea54501
MGD
19761 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19762 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19763
7e806470 19764 /* ARM V6M/V7 instructions. */
c921be7d
NC
19765#undef ARM_VARIANT
19766#define ARM_VARIANT & arm_ext_barrier
19767#undef THUMB_VARIANT
19768#define THUMB_VARIANT & arm_ext_barrier
19769
ccb84d65
JB
19770 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19771 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19772 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19773
62b3e311 19774 /* ARM V7 instructions. */
c921be7d
NC
19775#undef ARM_VARIANT
19776#define ARM_VARIANT & arm_ext_v7
19777#undef THUMB_VARIANT
19778#define THUMB_VARIANT & arm_ext_v7
19779
21d799b5
NC
19780 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19781 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19782
74db7efb 19783#undef ARM_VARIANT
60e5ef9f 19784#define ARM_VARIANT & arm_ext_mp
74db7efb 19785#undef THUMB_VARIANT
60e5ef9f
MGD
19786#define THUMB_VARIANT & arm_ext_mp
19787
19788 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19789
53c4b28b
MGD
19790 /* AArchv8 instructions. */
19791#undef ARM_VARIANT
19792#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19793
19794/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19795#undef THUMB_VARIANT
4ed7ed8d 19796#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19797
4ed7ed8d
TP
19798 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19799 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19800 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19801 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19802 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19803 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19804 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19805 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19806 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19807 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19808 stlex, t_stlex),
4b8c8c02
RE
19809 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19810 stlex, t_stlex),
19811 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19812 stlex, t_stlex),
4ed7ed8d
TP
19813#undef THUMB_VARIANT
19814#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19815
4ed7ed8d
TP
19816 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19817 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19818 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19819 ldrexd, t_ldrexd),
19820 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19821 strexd, t_strexd),
8884b720 19822 /* ARMv8 T32 only. */
74db7efb 19823#undef ARM_VARIANT
b79f7053
MGD
19824#define ARM_VARIANT NULL
19825 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19826 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19827 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19828
33399f07
MGD
19829 /* FP for ARMv8. */
19830#undef ARM_VARIANT
a715796b 19831#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19832#undef THUMB_VARIANT
a715796b 19833#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19834
19835 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19836 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19837 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19838 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19839 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19840 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19841 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19842 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19843 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19844 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19845 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19846 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19847 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19848 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19849 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19850 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19851 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19852
91ff7894
MGD
19853 /* Crypto v1 extensions. */
19854#undef ARM_VARIANT
19855#define ARM_VARIANT & fpu_crypto_ext_armv8
19856#undef THUMB_VARIANT
19857#define THUMB_VARIANT & fpu_crypto_ext_armv8
19858
19859 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19860 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19861 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19862 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19863 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19864 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19865 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19866 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19867 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19868 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19869 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19870 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19871 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19872 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19873
dd5181d5 19874#undef ARM_VARIANT
74db7efb 19875#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19876#undef THUMB_VARIANT
19877#define THUMB_VARIANT & crc_ext_armv8
19878 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19879 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19880 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19881 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19882 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19883 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19884
105bde57
MW
19885 /* ARMv8.2 RAS extension. */
19886#undef ARM_VARIANT
4d1464f2 19887#define ARM_VARIANT & arm_ext_ras
105bde57 19888#undef THUMB_VARIANT
4d1464f2 19889#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19890 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19891
49e8a725
SN
19892#undef ARM_VARIANT
19893#define ARM_VARIANT & arm_ext_v8_3
19894#undef THUMB_VARIANT
19895#define THUMB_VARIANT & arm_ext_v8_3
19896 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
19897 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
19898 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 19899
c921be7d
NC
19900#undef ARM_VARIANT
19901#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19902#undef THUMB_VARIANT
19903#define THUMB_VARIANT NULL
c921be7d 19904
21d799b5
NC
19905 cCE("wfs", e200110, 1, (RR), rd),
19906 cCE("rfs", e300110, 1, (RR), rd),
19907 cCE("wfc", e400110, 1, (RR), rd),
19908 cCE("rfc", e500110, 1, (RR), rd),
19909
19910 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19911 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19912 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19913 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19914
19915 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19916 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19917 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19918 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19919
19920 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19921 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19922 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19923 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19924 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19925 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19926 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19927 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19928 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19929 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19930 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19931 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19932
19933 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19934 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19935 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19936 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19937 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19938 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19939 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19940 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19941 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19942 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19943 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19944 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19945
19946 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19947 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19948 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19949 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19950 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19951 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19952 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19953 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19954 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19955 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19956 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19957 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19958
19959 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19960 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19961 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19962 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19963 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19964 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19965 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19966 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19967 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19968 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19969 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19970 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19971
19972 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19973 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19974 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19975 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19976 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19977 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19978 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19979 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19980 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19981 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19982 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19983 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19984
19985 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19986 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19987 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19988 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19989 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19990 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19991 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19992 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19993 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19994 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19995 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19996 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19997
19998 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19999 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20000 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20001 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20002 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20003 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20004 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20005 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20006 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20007 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20008 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20009 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20010
20011 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20012 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20013 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20014 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20015 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20016 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20017 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20018 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20019 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20020 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20021 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20022 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20023
20024 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20025 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20026 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20027 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20028 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20029 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20030 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20031 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20032 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20033 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20034 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20035 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20036
20037 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20038 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20039 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20040 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20041 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20042 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20043 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20044 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20045 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20046 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20047 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20048 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20049
20050 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20051 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20052 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20053 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20054 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20055 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20056 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20057 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20058 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20059 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20060 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20061 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20062
20063 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20064 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20065 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20066 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20067 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20068 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20069 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20070 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20071 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20072 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20073 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20074 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20075
20076 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20077 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20078 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20079 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20080 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20081 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20082 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20083 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20084 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20085 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20086 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20087 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20088
20089 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20090 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20091 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20092 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20093 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20094 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20095 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20096 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20097 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20098 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20099 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20100 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20101
20102 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20103 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20104 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20105 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20106 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20107 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20108 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20109 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20110 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20111 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20112 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20113 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20114
20115 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20116 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20117 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20118 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20119 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20120 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20121 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20122 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20123 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20124 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20125 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20126 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20127
20128 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20129 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20130 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20131 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20132 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20133 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20134 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20135 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20136 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20137 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20138 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20139 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20140
20141 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20142 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20143 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20144 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20145 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20146 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20147 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20148 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20149 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20150 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20151 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20152 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20153
20154 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20155 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20156 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20157 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20158 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20159 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20160 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20161 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20162 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20163 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20164 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20165 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20166
20167 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20168 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20169 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20170 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20171 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20172 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20173 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20174 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20175 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20176 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20177 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20178 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20179
20180 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20181 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20182 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20183 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20184 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20185 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20186 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20187 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20188 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20189 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20190 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20191 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20192
20193 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20194 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20195 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20196 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20197 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20198 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20199 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20200 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20201 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20202 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20203 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20204 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20205
20206 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20207 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20208 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20209 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20210 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20211 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20212 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20213 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20214 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20215 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20216 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20217 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20218
20219 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20220 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20221 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20222 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20223 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20224 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20225 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20226 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20227 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20228 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20229 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20230 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20231
20232 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20233 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20234 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20235 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20236 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20237 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20238 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20239 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20240 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20241 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20242 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20243 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20244
20245 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20246 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20247 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20248 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20249 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20250 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20251 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20253 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20254 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20255 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20257
20258 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20262 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20263 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20264 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20266 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20267 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20268 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20270
20271 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20275 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20276 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20277 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20279 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20280 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20281 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20283
20284 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20285 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20286 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20287 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20288 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20289 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20290 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20291 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20292 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20293 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20294 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20295 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20296
20297 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20298 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20299 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20300 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20301
20302 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20303 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20304 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20305 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20306 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20307 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20308 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20309 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20310 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20311 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20312 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20313 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20314
c19d1205
ZW
20315 /* The implementation of the FIX instruction is broken on some
20316 assemblers, in that it accepts a precision specifier as well as a
20317 rounding specifier, despite the fact that this is meaningless.
20318 To be more compatible, we accept it as well, though of course it
20319 does not set any bits. */
21d799b5
NC
20320 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20321 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20322 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20323 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20324 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20325 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20326 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20327 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20328 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20329 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20330 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20331 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20332 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20333
c19d1205 20334 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20335#undef ARM_VARIANT
20336#define ARM_VARIANT & fpu_fpa_ext_v2
20337
21d799b5
NC
20338 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20339 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20340 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20341 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20342 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20343 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20344
c921be7d
NC
20345#undef ARM_VARIANT
20346#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20347
c19d1205 20348 /* Moves and type conversions. */
21d799b5
NC
20349 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20350 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20351 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20352 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20353 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20354 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20355 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20356 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20357 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20358 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20359 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20360 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20361 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20362 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20363
20364 /* Memory operations. */
21d799b5
NC
20365 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20366 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20367 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20368 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20369 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20370 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20371 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20372 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20373 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20374 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20375 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20376 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20377 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20378 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20379 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20380 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20381 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20382 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20383
c19d1205 20384 /* Monadic operations. */
21d799b5
NC
20385 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20386 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20387 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20388
20389 /* Dyadic operations. */
21d799b5
NC
20390 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20391 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20392 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20393 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20394 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20395 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20396 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20397 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20398 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20399
c19d1205 20400 /* Comparisons. */
21d799b5
NC
20401 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20402 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20403 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20404 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20405
62f3b8c8
PB
20406 /* Double precision load/store are still present on single precision
20407 implementations. */
20408 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20409 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20410 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20411 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20412 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20413 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20414 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20415 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20416 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20417 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20418
c921be7d
NC
20419#undef ARM_VARIANT
20420#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20421
c19d1205 20422 /* Moves and type conversions. */
21d799b5
NC
20423 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20424 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20425 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20426 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20427 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20428 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20429 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20430 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20431 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20432 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20433 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20434 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20435 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20436
c19d1205 20437 /* Monadic operations. */
21d799b5
NC
20438 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20439 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20440 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20441
20442 /* Dyadic operations. */
21d799b5
NC
20443 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20444 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20445 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20446 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20447 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20448 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20449 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20450 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20451 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20452
c19d1205 20453 /* Comparisons. */
21d799b5
NC
20454 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20455 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20456 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20457 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20458
c921be7d
NC
20459#undef ARM_VARIANT
20460#define ARM_VARIANT & fpu_vfp_ext_v2
20461
21d799b5
NC
20462 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20463 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20464 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20465 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20466
037e8744
JB
20467/* Instructions which may belong to either the Neon or VFP instruction sets.
20468 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20469#undef ARM_VARIANT
20470#define ARM_VARIANT & fpu_vfp_ext_v1xd
20471#undef THUMB_VARIANT
20472#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20473
037e8744
JB
20474 /* These mnemonics are unique to VFP. */
20475 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20476 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20477 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20478 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20479 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20480 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20481 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20482 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20483 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20484 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20485
20486 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20487 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20488 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20489 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20490
21d799b5
NC
20491 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20492 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20493
20494 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20495 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20496
55881a11
MGD
20497 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20498 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20499 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20500 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20501 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20502 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20503 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20504 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20505
5f1af56b 20506 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20507 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20508 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20509 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20510
037e8744
JB
20511
20512 /* NOTE: All VMOV encoding is special-cased! */
20513 NCE(vmov, 0, 1, (VMOV), neon_mov),
20514 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20515
9db2f6b4
RL
20516#undef ARM_VARIANT
20517#define ARM_VARIANT & arm_ext_fp16
20518#undef THUMB_VARIANT
20519#define THUMB_VARIANT & arm_ext_fp16
20520 /* New instructions added from v8.2, allowing the extraction and insertion of
20521 the upper 16 bits of a 32-bit vector register. */
20522 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20523 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20524
c921be7d
NC
20525#undef THUMB_VARIANT
20526#define THUMB_VARIANT & fpu_neon_ext_v1
20527#undef ARM_VARIANT
20528#define ARM_VARIANT & fpu_neon_ext_v1
20529
5287ad62
JB
20530 /* Data processing with three registers of the same length. */
20531 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20532 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20533 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20534 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20535 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20536 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20537 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20538 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20539 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20540 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20541 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20542 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20543 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20544 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20545 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20546 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20547 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20548 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20549 /* If not immediate, fall back to neon_dyadic_i64_su.
20550 shl_imm should accept I8 I16 I32 I64,
20551 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20552 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20553 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20554 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20555 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20556 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20557 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20558 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20559 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20560 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20561 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20562 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20563 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20564 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20565 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20566 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20567 /* Bitfield ops, untyped. */
20568 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20569 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20570 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20571 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20572 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20573 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20574 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20575 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20576 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20577 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20578 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20579 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20580 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20581 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20582 back to neon_dyadic_if_su. */
21d799b5
NC
20583 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20584 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20585 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20586 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20587 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20588 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20589 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20590 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20591 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20592 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20593 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20594 /* As above, D registers only. */
21d799b5
NC
20595 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20596 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20597 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20598 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20599 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20600 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20601 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20602 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20603 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20604 /* vtst takes sizes 8, 16, 32. */
20605 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20606 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20607 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20608 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20609 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20610 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20611 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20612 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20613 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20614 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20615 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20616 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20617 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20618 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20619 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20620 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20621 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20622 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20623 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20624 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20625 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20626 /* ARM v8.1 extension. */
643afb90
MW
20627 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20628 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20629 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20630 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20631
20632 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20633 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20634 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20635
20636 /* Data processing with two registers and a shift amount. */
20637 /* Right shifts, and variants with rounding.
20638 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20639 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20640 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20641 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20642 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20643 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20644 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20645 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20646 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20647 /* Shift and insert. Sizes accepted 8 16 32 64. */
20648 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20649 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20650 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20651 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20652 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20653 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20654 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20655 /* Right shift immediate, saturating & narrowing, with rounding variants.
20656 Types accepted S16 S32 S64 U16 U32 U64. */
20657 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20658 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20659 /* As above, unsigned. Types accepted S16 S32 S64. */
20660 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20661 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20662 /* Right shift narrowing. Types accepted I16 I32 I64. */
20663 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20664 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20665 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20666 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20667 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20668 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20669
4316f0d2
DG
20670 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20671 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20672
20673 /* Data processing, three registers of different lengths. */
20674 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20675 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20676 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20677 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20678 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20679 /* If not scalar, fall back to neon_dyadic_long.
20680 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20681 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20682 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20683 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20684 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20685 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20686 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20687 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20688 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20689 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20690 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20691 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20692 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20693 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20694 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20695 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20696 S16 S32 U16 U32. */
21d799b5 20697 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20698
20699 /* Extract. Size 8. */
3b8d421e
PB
20700 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20701 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20702
20703 /* Two registers, miscellaneous. */
20704 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20705 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20706 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20707 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20708 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20709 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20710 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20711 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20712 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20713 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20714 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20715 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20716 /* VMOVN. Types I16 I32 I64. */
21d799b5 20717 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20718 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20719 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20720 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20721 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20722 /* VZIP / VUZP. Sizes 8 16 32. */
20723 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20724 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20725 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20726 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20727 /* VQABS / VQNEG. Types S8 S16 S32. */
20728 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20729 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20730 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20731 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20732 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20733 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20734 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20735 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20736 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20737 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20738 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20739 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20740 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20741 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20742 /* VCLS. Types S8 S16 S32. */
20743 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20744 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20745 /* VCLZ. Types I8 I16 I32. */
20746 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20747 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20748 /* VCNT. Size 8. */
20749 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20750 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20751 /* Two address, untyped. */
20752 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20753 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20754 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20755 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20756 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20757
20758 /* Table lookup. Size 8. */
20759 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20760 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20761
c921be7d
NC
20762#undef THUMB_VARIANT
20763#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20764#undef ARM_VARIANT
20765#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20766
5287ad62 20767 /* Neon element/structure load/store. */
21d799b5
NC
20768 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20769 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20770 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20771 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20772 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20773 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20774 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20775 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20776
c921be7d 20777#undef THUMB_VARIANT
74db7efb
NC
20778#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20779#undef ARM_VARIANT
20780#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20781 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20782 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20783 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20784 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20785 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20786 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20787 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20788 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20789 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20790
74db7efb 20791#undef THUMB_VARIANT
c921be7d
NC
20792#define THUMB_VARIANT & fpu_vfp_ext_v3
20793#undef ARM_VARIANT
20794#define ARM_VARIANT & fpu_vfp_ext_v3
20795
21d799b5 20796 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20797 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20798 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20799 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20800 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20801 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20802 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20803 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20804 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20805
74db7efb
NC
20806#undef ARM_VARIANT
20807#define ARM_VARIANT & fpu_vfp_ext_fma
20808#undef THUMB_VARIANT
20809#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20810 /* Mnemonics shared by Neon and VFP. These are included in the
20811 VFP FMA variant; NEON and VFP FMA always includes the NEON
20812 FMA instructions. */
20813 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20814 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20815 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20816 the v form should always be used. */
20817 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20818 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20819 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20820 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20821 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20822 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20823
5287ad62 20824#undef THUMB_VARIANT
c921be7d
NC
20825#undef ARM_VARIANT
20826#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20827
21d799b5
NC
20828 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20829 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20830 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20831 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20832 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20833 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20834 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20835 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20836
c921be7d
NC
20837#undef ARM_VARIANT
20838#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20839
21d799b5
NC
20840 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20841 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20842 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20843 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20844 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20845 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20846 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20847 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20848 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20849 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20850 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20851 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20852 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20853 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20854 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20855 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20856 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20857 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20858 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20859 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20860 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20861 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20862 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20863 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20864 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20865 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20866 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20867 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20868 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20869 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20870 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20871 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20872 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20873 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20874 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20875 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20876 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20877 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20878 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20879 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20880 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20881 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20882 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20883 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20884 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20885 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20886 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20887 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20888 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20889 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20890 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20891 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20892 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20893 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20894 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20895 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20896 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20897 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20898 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20899 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20900 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20904 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20905 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20906 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20907 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20908 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20909 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20910 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20911 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20912 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20913 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20914 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20915 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20916 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20917 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20918 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20919 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20920 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20921 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20922 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20923 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20924 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20925 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20926 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20927 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20928 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20929 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20930 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20931 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20932 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20933 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20934 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20935 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20936 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20937 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20938 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20939 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20940 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20941 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20942 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20943 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20944 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20945 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20946 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20947 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20948 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20949 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20950 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20951 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20952 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20953 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20954 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20955 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20956 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20957 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20958 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20959 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20960 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20961 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20962 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20963 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20964 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20965 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20966 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20967 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20968 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20969 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20970 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20971 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20972 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20973 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20974 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20975 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20976 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20977 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20978 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20979 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20980 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20981 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20982 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20983 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20984 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20985 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20986 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20987 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20988 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20989 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20990 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20991 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20992 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20993 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20994 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20995 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20996 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20997 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20998 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20999 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21001 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21002
c921be7d
NC
21003#undef ARM_VARIANT
21004#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21005
21d799b5
NC
21006 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21007 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21008 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21009 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21010 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21011 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21012 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21013 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21014 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21015 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21016 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21017 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21018 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21019 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21020 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21021 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21022 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21023 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21024 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21025 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21026 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21027 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21028 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21029 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21030 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21031 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21032 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21033 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21034 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21043 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21046 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21048 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21049 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21050 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21051 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21052 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21053 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21054 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21055 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21056 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21057 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21058 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21059 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21060 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21061 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21062 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21063
c921be7d
NC
21064#undef ARM_VARIANT
21065#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21066
21d799b5
NC
21067 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21068 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21069 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21070 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21071 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21072 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21073 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21074 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21075 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21076 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21077 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21078 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21079 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21080 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21081 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21082 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21083 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21084 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21085 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21086 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21087 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21088 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21089 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21090 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21091 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21092 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21093 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21094 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21095 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21096 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21097 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21098 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21099 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21100 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21101 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21102 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21103 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21104 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21105 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21106 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21107 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21108 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21109 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21110 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21111 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21112 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21113 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21114 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21115 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21116 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21117 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21118 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21119 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21120 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21121 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21122 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21123 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21124 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21125 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21126 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21127 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21128 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21129 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21130 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21131 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21132 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21133 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21134 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21135 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21136 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21137 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21138 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21139 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21140 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21141 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21142 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21143
16a1fa25 21144 /* ARMv8-M instructions. */
4ed7ed8d
TP
21145#undef ARM_VARIANT
21146#define ARM_VARIANT NULL
21147#undef THUMB_VARIANT
21148#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21149 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21150 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21151 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21152 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21153 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21154 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21155 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21156
21157 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21158 instructions behave as nop if no VFP is present. */
21159#undef THUMB_VARIANT
21160#define THUMB_VARIANT & arm_ext_v8m_main
21161 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21162 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21163};
21164#undef ARM_VARIANT
21165#undef THUMB_VARIANT
21166#undef TCE
c19d1205
ZW
21167#undef TUE
21168#undef TUF
21169#undef TCC
8f06b2d8 21170#undef cCE
e3cb604e
PB
21171#undef cCL
21172#undef C3E
c19d1205
ZW
21173#undef CE
21174#undef CM
21175#undef UE
21176#undef UF
21177#undef UT
5287ad62
JB
21178#undef NUF
21179#undef nUF
21180#undef NCE
21181#undef nCE
c19d1205
ZW
21182#undef OPS0
21183#undef OPS1
21184#undef OPS2
21185#undef OPS3
21186#undef OPS4
21187#undef OPS5
21188#undef OPS6
21189#undef do_0
21190\f
21191/* MD interface: bits in the object file. */
bfae80f2 21192
c19d1205
ZW
21193/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21194 for use in the a.out file, and stores them in the array pointed to by buf.
21195 This knows about the endian-ness of the target machine and does
21196 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21197 2 (short) and 4 (long) Floating numbers are put out as a series of
21198 LITTLENUMS (shorts, here at least). */
b99bd4ef 21199
c19d1205
ZW
21200void
21201md_number_to_chars (char * buf, valueT val, int n)
21202{
21203 if (target_big_endian)
21204 number_to_chars_bigendian (buf, val, n);
21205 else
21206 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21207}
21208
c19d1205
ZW
21209static valueT
21210md_chars_to_number (char * buf, int n)
bfae80f2 21211{
c19d1205
ZW
21212 valueT result = 0;
21213 unsigned char * where = (unsigned char *) buf;
bfae80f2 21214
c19d1205 21215 if (target_big_endian)
b99bd4ef 21216 {
c19d1205
ZW
21217 while (n--)
21218 {
21219 result <<= 8;
21220 result |= (*where++ & 255);
21221 }
b99bd4ef 21222 }
c19d1205 21223 else
b99bd4ef 21224 {
c19d1205
ZW
21225 while (n--)
21226 {
21227 result <<= 8;
21228 result |= (where[n] & 255);
21229 }
bfae80f2 21230 }
b99bd4ef 21231
c19d1205 21232 return result;
bfae80f2 21233}
b99bd4ef 21234
c19d1205 21235/* MD interface: Sections. */
b99bd4ef 21236
fa94de6b
RM
21237/* Calculate the maximum variable size (i.e., excluding fr_fix)
21238 that an rs_machine_dependent frag may reach. */
21239
21240unsigned int
21241arm_frag_max_var (fragS *fragp)
21242{
21243 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21244 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21245
21246 Note that we generate relaxable instructions even for cases that don't
21247 really need it, like an immediate that's a trivial constant. So we're
21248 overestimating the instruction size for some of those cases. Rather
21249 than putting more intelligence here, it would probably be better to
21250 avoid generating a relaxation frag in the first place when it can be
21251 determined up front that a short instruction will suffice. */
21252
21253 gas_assert (fragp->fr_type == rs_machine_dependent);
21254 return INSN_SIZE;
21255}
21256
0110f2b8
PB
21257/* Estimate the size of a frag before relaxing. Assume everything fits in
21258 2 bytes. */
21259
c19d1205 21260int
0110f2b8 21261md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21262 segT segtype ATTRIBUTE_UNUSED)
21263{
0110f2b8
PB
21264 fragp->fr_var = 2;
21265 return 2;
21266}
21267
21268/* Convert a machine dependent frag. */
21269
21270void
21271md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21272{
21273 unsigned long insn;
21274 unsigned long old_op;
21275 char *buf;
21276 expressionS exp;
21277 fixS *fixp;
21278 int reloc_type;
21279 int pc_rel;
21280 int opcode;
21281
21282 buf = fragp->fr_literal + fragp->fr_fix;
21283
21284 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21285 if (fragp->fr_symbol)
21286 {
0110f2b8
PB
21287 exp.X_op = O_symbol;
21288 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21289 }
21290 else
21291 {
0110f2b8 21292 exp.X_op = O_constant;
5f4273c7 21293 }
0110f2b8
PB
21294 exp.X_add_number = fragp->fr_offset;
21295 opcode = fragp->fr_subtype;
21296 switch (opcode)
21297 {
21298 case T_MNEM_ldr_pc:
21299 case T_MNEM_ldr_pc2:
21300 case T_MNEM_ldr_sp:
21301 case T_MNEM_str_sp:
21302 case T_MNEM_ldr:
21303 case T_MNEM_ldrb:
21304 case T_MNEM_ldrh:
21305 case T_MNEM_str:
21306 case T_MNEM_strb:
21307 case T_MNEM_strh:
21308 if (fragp->fr_var == 4)
21309 {
5f4273c7 21310 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21311 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21312 {
21313 insn |= (old_op & 0x700) << 4;
21314 }
21315 else
21316 {
21317 insn |= (old_op & 7) << 12;
21318 insn |= (old_op & 0x38) << 13;
21319 }
21320 insn |= 0x00000c00;
21321 put_thumb32_insn (buf, insn);
21322 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21323 }
21324 else
21325 {
21326 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21327 }
21328 pc_rel = (opcode == T_MNEM_ldr_pc2);
21329 break;
21330 case T_MNEM_adr:
21331 if (fragp->fr_var == 4)
21332 {
21333 insn = THUMB_OP32 (opcode);
21334 insn |= (old_op & 0xf0) << 4;
21335 put_thumb32_insn (buf, insn);
21336 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21337 }
21338 else
21339 {
21340 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21341 exp.X_add_number -= 4;
21342 }
21343 pc_rel = 1;
21344 break;
21345 case T_MNEM_mov:
21346 case T_MNEM_movs:
21347 case T_MNEM_cmp:
21348 case T_MNEM_cmn:
21349 if (fragp->fr_var == 4)
21350 {
21351 int r0off = (opcode == T_MNEM_mov
21352 || opcode == T_MNEM_movs) ? 0 : 8;
21353 insn = THUMB_OP32 (opcode);
21354 insn = (insn & 0xe1ffffff) | 0x10000000;
21355 insn |= (old_op & 0x700) << r0off;
21356 put_thumb32_insn (buf, insn);
21357 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21358 }
21359 else
21360 {
21361 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21362 }
21363 pc_rel = 0;
21364 break;
21365 case T_MNEM_b:
21366 if (fragp->fr_var == 4)
21367 {
21368 insn = THUMB_OP32(opcode);
21369 put_thumb32_insn (buf, insn);
21370 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21371 }
21372 else
21373 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21374 pc_rel = 1;
21375 break;
21376 case T_MNEM_bcond:
21377 if (fragp->fr_var == 4)
21378 {
21379 insn = THUMB_OP32(opcode);
21380 insn |= (old_op & 0xf00) << 14;
21381 put_thumb32_insn (buf, insn);
21382 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21383 }
21384 else
21385 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21386 pc_rel = 1;
21387 break;
21388 case T_MNEM_add_sp:
21389 case T_MNEM_add_pc:
21390 case T_MNEM_inc_sp:
21391 case T_MNEM_dec_sp:
21392 if (fragp->fr_var == 4)
21393 {
21394 /* ??? Choose between add and addw. */
21395 insn = THUMB_OP32 (opcode);
21396 insn |= (old_op & 0xf0) << 4;
21397 put_thumb32_insn (buf, insn);
16805f35
PB
21398 if (opcode == T_MNEM_add_pc)
21399 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21400 else
21401 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21402 }
21403 else
21404 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21405 pc_rel = 0;
21406 break;
21407
21408 case T_MNEM_addi:
21409 case T_MNEM_addis:
21410 case T_MNEM_subi:
21411 case T_MNEM_subis:
21412 if (fragp->fr_var == 4)
21413 {
21414 insn = THUMB_OP32 (opcode);
21415 insn |= (old_op & 0xf0) << 4;
21416 insn |= (old_op & 0xf) << 16;
21417 put_thumb32_insn (buf, insn);
16805f35
PB
21418 if (insn & (1 << 20))
21419 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21420 else
21421 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21422 }
21423 else
21424 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21425 pc_rel = 0;
21426 break;
21427 default:
5f4273c7 21428 abort ();
0110f2b8
PB
21429 }
21430 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21431 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21432 fixp->fx_file = fragp->fr_file;
21433 fixp->fx_line = fragp->fr_line;
21434 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21435
21436 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21437 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21438 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21439 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21440}
21441
21442/* Return the size of a relaxable immediate operand instruction.
21443 SHIFT and SIZE specify the form of the allowable immediate. */
21444static int
21445relax_immediate (fragS *fragp, int size, int shift)
21446{
21447 offsetT offset;
21448 offsetT mask;
21449 offsetT low;
21450
21451 /* ??? Should be able to do better than this. */
21452 if (fragp->fr_symbol)
21453 return 4;
21454
21455 low = (1 << shift) - 1;
21456 mask = (1 << (shift + size)) - (1 << shift);
21457 offset = fragp->fr_offset;
21458 /* Force misaligned offsets to 32-bit variant. */
21459 if (offset & low)
5e77afaa 21460 return 4;
0110f2b8
PB
21461 if (offset & ~mask)
21462 return 4;
21463 return 2;
21464}
21465
5e77afaa
PB
21466/* Get the address of a symbol during relaxation. */
21467static addressT
5f4273c7 21468relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21469{
21470 fragS *sym_frag;
21471 addressT addr;
21472 symbolS *sym;
21473
21474 sym = fragp->fr_symbol;
21475 sym_frag = symbol_get_frag (sym);
21476 know (S_GET_SEGMENT (sym) != absolute_section
21477 || sym_frag == &zero_address_frag);
21478 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21479
21480 /* If frag has yet to be reached on this pass, assume it will
21481 move by STRETCH just as we did. If this is not so, it will
21482 be because some frag between grows, and that will force
21483 another pass. */
21484
21485 if (stretch != 0
21486 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21487 {
21488 fragS *f;
21489
21490 /* Adjust stretch for any alignment frag. Note that if have
21491 been expanding the earlier code, the symbol may be
21492 defined in what appears to be an earlier frag. FIXME:
21493 This doesn't handle the fr_subtype field, which specifies
21494 a maximum number of bytes to skip when doing an
21495 alignment. */
21496 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21497 {
21498 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21499 {
21500 if (stretch < 0)
21501 stretch = - ((- stretch)
21502 & ~ ((1 << (int) f->fr_offset) - 1));
21503 else
21504 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21505 if (stretch == 0)
21506 break;
21507 }
21508 }
21509 if (f != NULL)
21510 addr += stretch;
21511 }
5e77afaa
PB
21512
21513 return addr;
21514}
21515
0110f2b8
PB
21516/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21517 load. */
21518static int
5e77afaa 21519relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21520{
21521 addressT addr;
21522 offsetT val;
21523
21524 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21525 if (fragp->fr_symbol == NULL
21526 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21527 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21528 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21529 return 4;
21530
5f4273c7 21531 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21532 addr = fragp->fr_address + fragp->fr_fix;
21533 addr = (addr + 4) & ~3;
5e77afaa 21534 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21535 if (val & 3)
5e77afaa 21536 return 4;
0110f2b8
PB
21537 val -= addr;
21538 if (val < 0 || val > 1020)
21539 return 4;
21540 return 2;
21541}
21542
21543/* Return the size of a relaxable add/sub immediate instruction. */
21544static int
21545relax_addsub (fragS *fragp, asection *sec)
21546{
21547 char *buf;
21548 int op;
21549
21550 buf = fragp->fr_literal + fragp->fr_fix;
21551 op = bfd_get_16(sec->owner, buf);
21552 if ((op & 0xf) == ((op >> 4) & 0xf))
21553 return relax_immediate (fragp, 8, 0);
21554 else
21555 return relax_immediate (fragp, 3, 0);
21556}
21557
e83a675f
RE
21558/* Return TRUE iff the definition of symbol S could be pre-empted
21559 (overridden) at link or load time. */
21560static bfd_boolean
21561symbol_preemptible (symbolS *s)
21562{
21563 /* Weak symbols can always be pre-empted. */
21564 if (S_IS_WEAK (s))
21565 return TRUE;
21566
21567 /* Non-global symbols cannot be pre-empted. */
21568 if (! S_IS_EXTERNAL (s))
21569 return FALSE;
21570
21571#ifdef OBJ_ELF
21572 /* In ELF, a global symbol can be marked protected, or private. In that
21573 case it can't be pre-empted (other definitions in the same link unit
21574 would violate the ODR). */
21575 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21576 return FALSE;
21577#endif
21578
21579 /* Other global symbols might be pre-empted. */
21580 return TRUE;
21581}
0110f2b8
PB
21582
21583/* Return the size of a relaxable branch instruction. BITS is the
21584 size of the offset field in the narrow instruction. */
21585
21586static int
5e77afaa 21587relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21588{
21589 addressT addr;
21590 offsetT val;
21591 offsetT limit;
21592
21593 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21594 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21595 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21596 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21597 return 4;
21598
267bf995 21599#ifdef OBJ_ELF
e83a675f 21600 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21601 if (S_IS_DEFINED (fragp->fr_symbol)
21602 && ARM_IS_FUNC (fragp->fr_symbol))
21603 return 4;
e83a675f 21604#endif
0d9b4b55 21605
e83a675f 21606 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21607 return 4;
267bf995 21608
5f4273c7 21609 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21610 addr = fragp->fr_address + fragp->fr_fix + 4;
21611 val -= addr;
21612
21613 /* Offset is a signed value *2 */
21614 limit = 1 << bits;
21615 if (val >= limit || val < -limit)
21616 return 4;
21617 return 2;
21618}
21619
21620
21621/* Relax a machine dependent frag. This returns the amount by which
21622 the current size of the frag should change. */
21623
21624int
5e77afaa 21625arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21626{
21627 int oldsize;
21628 int newsize;
21629
21630 oldsize = fragp->fr_var;
21631 switch (fragp->fr_subtype)
21632 {
21633 case T_MNEM_ldr_pc2:
5f4273c7 21634 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21635 break;
21636 case T_MNEM_ldr_pc:
21637 case T_MNEM_ldr_sp:
21638 case T_MNEM_str_sp:
5f4273c7 21639 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21640 break;
21641 case T_MNEM_ldr:
21642 case T_MNEM_str:
5f4273c7 21643 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21644 break;
21645 case T_MNEM_ldrh:
21646 case T_MNEM_strh:
5f4273c7 21647 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21648 break;
21649 case T_MNEM_ldrb:
21650 case T_MNEM_strb:
5f4273c7 21651 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21652 break;
21653 case T_MNEM_adr:
5f4273c7 21654 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21655 break;
21656 case T_MNEM_mov:
21657 case T_MNEM_movs:
21658 case T_MNEM_cmp:
21659 case T_MNEM_cmn:
5f4273c7 21660 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21661 break;
21662 case T_MNEM_b:
5f4273c7 21663 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21664 break;
21665 case T_MNEM_bcond:
5f4273c7 21666 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21667 break;
21668 case T_MNEM_add_sp:
21669 case T_MNEM_add_pc:
21670 newsize = relax_immediate (fragp, 8, 2);
21671 break;
21672 case T_MNEM_inc_sp:
21673 case T_MNEM_dec_sp:
21674 newsize = relax_immediate (fragp, 7, 2);
21675 break;
21676 case T_MNEM_addi:
21677 case T_MNEM_addis:
21678 case T_MNEM_subi:
21679 case T_MNEM_subis:
21680 newsize = relax_addsub (fragp, sec);
21681 break;
21682 default:
5f4273c7 21683 abort ();
0110f2b8 21684 }
5e77afaa
PB
21685
21686 fragp->fr_var = newsize;
21687 /* Freeze wide instructions that are at or before the same location as
21688 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21689 Don't freeze them unconditionally because targets may be artificially
21690 misaligned by the expansion of preceding frags. */
5e77afaa 21691 if (stretch <= 0 && newsize > 2)
0110f2b8 21692 {
0110f2b8 21693 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21694 frag_wane (fragp);
0110f2b8 21695 }
5e77afaa 21696
0110f2b8 21697 return newsize - oldsize;
c19d1205 21698}
b99bd4ef 21699
c19d1205 21700/* Round up a section size to the appropriate boundary. */
b99bd4ef 21701
c19d1205
ZW
21702valueT
21703md_section_align (segT segment ATTRIBUTE_UNUSED,
21704 valueT size)
21705{
f0927246
NC
21706#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21707 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21708 {
21709 /* For a.out, force the section size to be aligned. If we don't do
21710 this, BFD will align it for us, but it will not write out the
21711 final bytes of the section. This may be a bug in BFD, but it is
21712 easier to fix it here since that is how the other a.out targets
21713 work. */
21714 int align;
21715
21716 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21717 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21718 }
c19d1205 21719#endif
f0927246 21720
6844c0cc 21721 return size;
bfae80f2 21722}
b99bd4ef 21723
c19d1205
ZW
21724/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21725 of an rs_align_code fragment. */
21726
21727void
21728arm_handle_align (fragS * fragP)
bfae80f2 21729{
d9235011 21730 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21731 {
21732 { /* ARMv1 */
21733 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21734 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21735 },
21736 { /* ARMv6k */
21737 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21738 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21739 },
21740 };
d9235011 21741 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21742 {
21743 { /* Thumb-1 */
21744 {0xc0, 0x46}, /* LE */
21745 {0x46, 0xc0}, /* BE */
21746 },
21747 { /* Thumb-2 */
21748 {0x00, 0xbf}, /* LE */
21749 {0xbf, 0x00} /* BE */
21750 }
21751 };
d9235011 21752 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21753 { /* Wide Thumb-2 */
21754 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21755 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21756 };
c921be7d 21757
e7495e45 21758 unsigned bytes, fix, noop_size;
c19d1205 21759 char * p;
d9235011
TS
21760 const unsigned char * noop;
21761 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21762#ifdef OBJ_ELF
21763 enum mstate state;
21764#endif
bfae80f2 21765
c19d1205 21766 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21767 return;
21768
c19d1205
ZW
21769 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21770 p = fragP->fr_literal + fragP->fr_fix;
21771 fix = 0;
bfae80f2 21772
c19d1205
ZW
21773 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21774 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21775
cd000bff 21776 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21777
cd000bff 21778 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21779 {
7f78eb34
JW
21780 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21781 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21782 {
21783 narrow_noop = thumb_noop[1][target_big_endian];
21784 noop = wide_thumb_noop[target_big_endian];
21785 }
c19d1205 21786 else
e7495e45
NS
21787 noop = thumb_noop[0][target_big_endian];
21788 noop_size = 2;
cd000bff
DJ
21789#ifdef OBJ_ELF
21790 state = MAP_THUMB;
21791#endif
7ed4c4c5
NC
21792 }
21793 else
21794 {
7f78eb34
JW
21795 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21796 ? selected_cpu : arm_arch_none,
21797 arm_ext_v6k) != 0]
e7495e45
NS
21798 [target_big_endian];
21799 noop_size = 4;
cd000bff
DJ
21800#ifdef OBJ_ELF
21801 state = MAP_ARM;
21802#endif
7ed4c4c5 21803 }
c921be7d 21804
e7495e45 21805 fragP->fr_var = noop_size;
c921be7d 21806
c19d1205 21807 if (bytes & (noop_size - 1))
7ed4c4c5 21808 {
c19d1205 21809 fix = bytes & (noop_size - 1);
cd000bff
DJ
21810#ifdef OBJ_ELF
21811 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21812#endif
c19d1205
ZW
21813 memset (p, 0, fix);
21814 p += fix;
21815 bytes -= fix;
a737bd4d 21816 }
a737bd4d 21817
e7495e45
NS
21818 if (narrow_noop)
21819 {
21820 if (bytes & noop_size)
21821 {
21822 /* Insert a narrow noop. */
21823 memcpy (p, narrow_noop, noop_size);
21824 p += noop_size;
21825 bytes -= noop_size;
21826 fix += noop_size;
21827 }
21828
21829 /* Use wide noops for the remainder */
21830 noop_size = 4;
21831 }
21832
c19d1205 21833 while (bytes >= noop_size)
a737bd4d 21834 {
c19d1205
ZW
21835 memcpy (p, noop, noop_size);
21836 p += noop_size;
21837 bytes -= noop_size;
21838 fix += noop_size;
a737bd4d
NC
21839 }
21840
c19d1205 21841 fragP->fr_fix += fix;
a737bd4d
NC
21842}
21843
c19d1205
ZW
21844/* Called from md_do_align. Used to create an alignment
21845 frag in a code section. */
21846
21847void
21848arm_frag_align_code (int n, int max)
bfae80f2 21849{
c19d1205 21850 char * p;
7ed4c4c5 21851
c19d1205 21852 /* We assume that there will never be a requirement
6ec8e702 21853 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21854 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21855 {
21856 char err_msg[128];
21857
fa94de6b 21858 sprintf (err_msg,
477330fc
RM
21859 _("alignments greater than %d bytes not supported in .text sections."),
21860 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21861 as_fatal ("%s", err_msg);
6ec8e702 21862 }
bfae80f2 21863
c19d1205
ZW
21864 p = frag_var (rs_align_code,
21865 MAX_MEM_FOR_RS_ALIGN_CODE,
21866 1,
21867 (relax_substateT) max,
21868 (symbolS *) NULL,
21869 (offsetT) n,
21870 (char *) NULL);
21871 *p = 0;
21872}
bfae80f2 21873
8dc2430f
NC
21874/* Perform target specific initialisation of a frag.
21875 Note - despite the name this initialisation is not done when the frag
21876 is created, but only when its type is assigned. A frag can be created
21877 and used a long time before its type is set, so beware of assuming that
33eaf5de 21878 this initialisation is performed first. */
bfae80f2 21879
cd000bff
DJ
21880#ifndef OBJ_ELF
21881void
21882arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21883{
21884 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21885 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21886}
21887
21888#else /* OBJ_ELF is defined. */
c19d1205 21889void
cd000bff 21890arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21891{
b968d18a
JW
21892 int frag_thumb_mode;
21893
8dc2430f
NC
21894 /* If the current ARM vs THUMB mode has not already
21895 been recorded into this frag then do so now. */
cd000bff 21896 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21897 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21898
21899 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21900
f9c1b181
RL
21901 /* Record a mapping symbol for alignment frags. We will delete this
21902 later if the alignment ends up empty. */
21903 switch (fragP->fr_type)
21904 {
21905 case rs_align:
21906 case rs_align_test:
21907 case rs_fill:
21908 mapping_state_2 (MAP_DATA, max_chars);
21909 break;
21910 case rs_align_code:
b968d18a 21911 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21912 break;
21913 default:
21914 break;
cd000bff 21915 }
bfae80f2
RE
21916}
21917
c19d1205
ZW
21918/* When we change sections we need to issue a new mapping symbol. */
21919
21920void
21921arm_elf_change_section (void)
bfae80f2 21922{
c19d1205
ZW
21923 /* Link an unlinked unwind index table section to the .text section. */
21924 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21925 && elf_linked_to_section (now_seg) == NULL)
21926 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21927}
21928
c19d1205
ZW
21929int
21930arm_elf_section_type (const char * str, size_t len)
e45d0630 21931{
c19d1205
ZW
21932 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21933 return SHT_ARM_EXIDX;
e45d0630 21934
c19d1205
ZW
21935 return -1;
21936}
21937\f
21938/* Code to deal with unwinding tables. */
e45d0630 21939
c19d1205 21940static void add_unwind_adjustsp (offsetT);
e45d0630 21941
5f4273c7 21942/* Generate any deferred unwind frame offset. */
e45d0630 21943
bfae80f2 21944static void
c19d1205 21945flush_pending_unwind (void)
bfae80f2 21946{
c19d1205 21947 offsetT offset;
bfae80f2 21948
c19d1205
ZW
21949 offset = unwind.pending_offset;
21950 unwind.pending_offset = 0;
21951 if (offset != 0)
21952 add_unwind_adjustsp (offset);
bfae80f2
RE
21953}
21954
c19d1205
ZW
21955/* Add an opcode to this list for this function. Two-byte opcodes should
21956 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21957 order. */
21958
bfae80f2 21959static void
c19d1205 21960add_unwind_opcode (valueT op, int length)
bfae80f2 21961{
c19d1205
ZW
21962 /* Add any deferred stack adjustment. */
21963 if (unwind.pending_offset)
21964 flush_pending_unwind ();
bfae80f2 21965
c19d1205 21966 unwind.sp_restored = 0;
bfae80f2 21967
c19d1205 21968 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21969 {
c19d1205
ZW
21970 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21971 if (unwind.opcodes)
325801bd
TS
21972 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21973 unwind.opcode_alloc);
c19d1205 21974 else
325801bd 21975 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21976 }
c19d1205 21977 while (length > 0)
bfae80f2 21978 {
c19d1205
ZW
21979 length--;
21980 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21981 op >>= 8;
21982 unwind.opcode_count++;
bfae80f2 21983 }
bfae80f2
RE
21984}
21985
c19d1205
ZW
21986/* Add unwind opcodes to adjust the stack pointer. */
21987
bfae80f2 21988static void
c19d1205 21989add_unwind_adjustsp (offsetT offset)
bfae80f2 21990{
c19d1205 21991 valueT op;
bfae80f2 21992
c19d1205 21993 if (offset > 0x200)
bfae80f2 21994 {
c19d1205
ZW
21995 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21996 char bytes[5];
21997 int n;
21998 valueT o;
bfae80f2 21999
c19d1205
ZW
22000 /* Long form: 0xb2, uleb128. */
22001 /* This might not fit in a word so add the individual bytes,
22002 remembering the list is built in reverse order. */
22003 o = (valueT) ((offset - 0x204) >> 2);
22004 if (o == 0)
22005 add_unwind_opcode (0, 1);
bfae80f2 22006
c19d1205
ZW
22007 /* Calculate the uleb128 encoding of the offset. */
22008 n = 0;
22009 while (o)
22010 {
22011 bytes[n] = o & 0x7f;
22012 o >>= 7;
22013 if (o)
22014 bytes[n] |= 0x80;
22015 n++;
22016 }
22017 /* Add the insn. */
22018 for (; n; n--)
22019 add_unwind_opcode (bytes[n - 1], 1);
22020 add_unwind_opcode (0xb2, 1);
22021 }
22022 else if (offset > 0x100)
bfae80f2 22023 {
c19d1205
ZW
22024 /* Two short opcodes. */
22025 add_unwind_opcode (0x3f, 1);
22026 op = (offset - 0x104) >> 2;
22027 add_unwind_opcode (op, 1);
bfae80f2 22028 }
c19d1205
ZW
22029 else if (offset > 0)
22030 {
22031 /* Short opcode. */
22032 op = (offset - 4) >> 2;
22033 add_unwind_opcode (op, 1);
22034 }
22035 else if (offset < 0)
bfae80f2 22036 {
c19d1205
ZW
22037 offset = -offset;
22038 while (offset > 0x100)
bfae80f2 22039 {
c19d1205
ZW
22040 add_unwind_opcode (0x7f, 1);
22041 offset -= 0x100;
bfae80f2 22042 }
c19d1205
ZW
22043 op = ((offset - 4) >> 2) | 0x40;
22044 add_unwind_opcode (op, 1);
bfae80f2 22045 }
bfae80f2
RE
22046}
22047
c19d1205
ZW
22048/* Finish the list of unwind opcodes for this function. */
22049static void
22050finish_unwind_opcodes (void)
bfae80f2 22051{
c19d1205 22052 valueT op;
bfae80f2 22053
c19d1205 22054 if (unwind.fp_used)
bfae80f2 22055 {
708587a4 22056 /* Adjust sp as necessary. */
c19d1205
ZW
22057 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22058 flush_pending_unwind ();
bfae80f2 22059
c19d1205
ZW
22060 /* After restoring sp from the frame pointer. */
22061 op = 0x90 | unwind.fp_reg;
22062 add_unwind_opcode (op, 1);
22063 }
22064 else
22065 flush_pending_unwind ();
bfae80f2
RE
22066}
22067
bfae80f2 22068
c19d1205
ZW
22069/* Start an exception table entry. If idx is nonzero this is an index table
22070 entry. */
bfae80f2
RE
22071
22072static void
c19d1205 22073start_unwind_section (const segT text_seg, int idx)
bfae80f2 22074{
c19d1205
ZW
22075 const char * text_name;
22076 const char * prefix;
22077 const char * prefix_once;
22078 const char * group_name;
c19d1205 22079 char * sec_name;
c19d1205
ZW
22080 int type;
22081 int flags;
22082 int linkonce;
bfae80f2 22083
c19d1205 22084 if (idx)
bfae80f2 22085 {
c19d1205
ZW
22086 prefix = ELF_STRING_ARM_unwind;
22087 prefix_once = ELF_STRING_ARM_unwind_once;
22088 type = SHT_ARM_EXIDX;
bfae80f2 22089 }
c19d1205 22090 else
bfae80f2 22091 {
c19d1205
ZW
22092 prefix = ELF_STRING_ARM_unwind_info;
22093 prefix_once = ELF_STRING_ARM_unwind_info_once;
22094 type = SHT_PROGBITS;
bfae80f2
RE
22095 }
22096
c19d1205
ZW
22097 text_name = segment_name (text_seg);
22098 if (streq (text_name, ".text"))
22099 text_name = "";
22100
22101 if (strncmp (text_name, ".gnu.linkonce.t.",
22102 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22103 {
c19d1205
ZW
22104 prefix = prefix_once;
22105 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22106 }
22107
29a2809e 22108 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22109
c19d1205
ZW
22110 flags = SHF_ALLOC;
22111 linkonce = 0;
22112 group_name = 0;
bfae80f2 22113
c19d1205
ZW
22114 /* Handle COMDAT group. */
22115 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22116 {
c19d1205
ZW
22117 group_name = elf_group_name (text_seg);
22118 if (group_name == NULL)
22119 {
bd3ba5d1 22120 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22121 segment_name (text_seg));
22122 ignore_rest_of_line ();
22123 return;
22124 }
22125 flags |= SHF_GROUP;
22126 linkonce = 1;
bfae80f2
RE
22127 }
22128
a91e1603
L
22129 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22130 linkonce, 0);
bfae80f2 22131
5f4273c7 22132 /* Set the section link for index tables. */
c19d1205
ZW
22133 if (idx)
22134 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22135}
22136
bfae80f2 22137
c19d1205
ZW
22138/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22139 personality routine data. Returns zero, or the index table value for
cad0da33 22140 an inline entry. */
c19d1205
ZW
22141
22142static valueT
22143create_unwind_entry (int have_data)
bfae80f2 22144{
c19d1205
ZW
22145 int size;
22146 addressT where;
22147 char *ptr;
22148 /* The current word of data. */
22149 valueT data;
22150 /* The number of bytes left in this word. */
22151 int n;
bfae80f2 22152
c19d1205 22153 finish_unwind_opcodes ();
bfae80f2 22154
c19d1205
ZW
22155 /* Remember the current text section. */
22156 unwind.saved_seg = now_seg;
22157 unwind.saved_subseg = now_subseg;
bfae80f2 22158
c19d1205 22159 start_unwind_section (now_seg, 0);
bfae80f2 22160
c19d1205 22161 if (unwind.personality_routine == NULL)
bfae80f2 22162 {
c19d1205
ZW
22163 if (unwind.personality_index == -2)
22164 {
22165 if (have_data)
5f4273c7 22166 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22167 return 1; /* EXIDX_CANTUNWIND. */
22168 }
bfae80f2 22169
c19d1205
ZW
22170 /* Use a default personality routine if none is specified. */
22171 if (unwind.personality_index == -1)
22172 {
22173 if (unwind.opcode_count > 3)
22174 unwind.personality_index = 1;
22175 else
22176 unwind.personality_index = 0;
22177 }
bfae80f2 22178
c19d1205
ZW
22179 /* Space for the personality routine entry. */
22180 if (unwind.personality_index == 0)
22181 {
22182 if (unwind.opcode_count > 3)
22183 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22184
c19d1205
ZW
22185 if (!have_data)
22186 {
22187 /* All the data is inline in the index table. */
22188 data = 0x80;
22189 n = 3;
22190 while (unwind.opcode_count > 0)
22191 {
22192 unwind.opcode_count--;
22193 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22194 n--;
22195 }
bfae80f2 22196
c19d1205
ZW
22197 /* Pad with "finish" opcodes. */
22198 while (n--)
22199 data = (data << 8) | 0xb0;
bfae80f2 22200
c19d1205
ZW
22201 return data;
22202 }
22203 size = 0;
22204 }
22205 else
22206 /* We get two opcodes "free" in the first word. */
22207 size = unwind.opcode_count - 2;
22208 }
22209 else
5011093d 22210 {
cad0da33
NC
22211 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22212 if (unwind.personality_index != -1)
22213 {
22214 as_bad (_("attempt to recreate an unwind entry"));
22215 return 1;
22216 }
5011093d
NC
22217
22218 /* An extra byte is required for the opcode count. */
22219 size = unwind.opcode_count + 1;
22220 }
bfae80f2 22221
c19d1205
ZW
22222 size = (size + 3) >> 2;
22223 if (size > 0xff)
22224 as_bad (_("too many unwind opcodes"));
bfae80f2 22225
c19d1205
ZW
22226 frag_align (2, 0, 0);
22227 record_alignment (now_seg, 2);
22228 unwind.table_entry = expr_build_dot ();
22229
22230 /* Allocate the table entry. */
22231 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22232 /* PR 13449: Zero the table entries in case some of them are not used. */
22233 memset (ptr, 0, (size << 2) + 4);
c19d1205 22234 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22235
c19d1205 22236 switch (unwind.personality_index)
bfae80f2 22237 {
c19d1205
ZW
22238 case -1:
22239 /* ??? Should this be a PLT generating relocation? */
22240 /* Custom personality routine. */
22241 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22242 BFD_RELOC_ARM_PREL31);
bfae80f2 22243
c19d1205
ZW
22244 where += 4;
22245 ptr += 4;
bfae80f2 22246
c19d1205 22247 /* Set the first byte to the number of additional words. */
5011093d 22248 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22249 n = 3;
22250 break;
bfae80f2 22251
c19d1205
ZW
22252 /* ABI defined personality routines. */
22253 case 0:
22254 /* Three opcodes bytes are packed into the first word. */
22255 data = 0x80;
22256 n = 3;
22257 break;
bfae80f2 22258
c19d1205
ZW
22259 case 1:
22260 case 2:
22261 /* The size and first two opcode bytes go in the first word. */
22262 data = ((0x80 + unwind.personality_index) << 8) | size;
22263 n = 2;
22264 break;
bfae80f2 22265
c19d1205
ZW
22266 default:
22267 /* Should never happen. */
22268 abort ();
22269 }
bfae80f2 22270
c19d1205
ZW
22271 /* Pack the opcodes into words (MSB first), reversing the list at the same
22272 time. */
22273 while (unwind.opcode_count > 0)
22274 {
22275 if (n == 0)
22276 {
22277 md_number_to_chars (ptr, data, 4);
22278 ptr += 4;
22279 n = 4;
22280 data = 0;
22281 }
22282 unwind.opcode_count--;
22283 n--;
22284 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22285 }
22286
22287 /* Finish off the last word. */
22288 if (n < 4)
22289 {
22290 /* Pad with "finish" opcodes. */
22291 while (n--)
22292 data = (data << 8) | 0xb0;
22293
22294 md_number_to_chars (ptr, data, 4);
22295 }
22296
22297 if (!have_data)
22298 {
22299 /* Add an empty descriptor if there is no user-specified data. */
22300 ptr = frag_more (4);
22301 md_number_to_chars (ptr, 0, 4);
22302 }
22303
22304 return 0;
bfae80f2
RE
22305}
22306
f0927246
NC
22307
22308/* Initialize the DWARF-2 unwind information for this procedure. */
22309
22310void
22311tc_arm_frame_initial_instructions (void)
22312{
22313 cfi_add_CFA_def_cfa (REG_SP, 0);
22314}
22315#endif /* OBJ_ELF */
22316
c19d1205
ZW
22317/* Convert REGNAME to a DWARF-2 register number. */
22318
22319int
1df69f4f 22320tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22321{
1df69f4f 22322 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22323 if (reg != FAIL)
22324 return reg;
c19d1205 22325
1f5afe1c
NC
22326 /* PR 16694: Allow VFP registers as well. */
22327 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22328 if (reg != FAIL)
22329 return 64 + reg;
c19d1205 22330
1f5afe1c
NC
22331 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22332 if (reg != FAIL)
22333 return reg + 256;
22334
22335 return -1;
bfae80f2
RE
22336}
22337
f0927246 22338#ifdef TE_PE
c19d1205 22339void
f0927246 22340tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22341{
91d6fa6a 22342 expressionS exp;
bfae80f2 22343
91d6fa6a
NC
22344 exp.X_op = O_secrel;
22345 exp.X_add_symbol = symbol;
22346 exp.X_add_number = 0;
22347 emit_expr (&exp, size);
f0927246
NC
22348}
22349#endif
bfae80f2 22350
c19d1205 22351/* MD interface: Symbol and relocation handling. */
bfae80f2 22352
2fc8bdac
ZW
22353/* Return the address within the segment that a PC-relative fixup is
22354 relative to. For ARM, PC-relative fixups applied to instructions
22355 are generally relative to the location of the fixup plus 8 bytes.
22356 Thumb branches are offset by 4, and Thumb loads relative to PC
22357 require special handling. */
bfae80f2 22358
c19d1205 22359long
2fc8bdac 22360md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22361{
2fc8bdac
ZW
22362 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22363
22364 /* If this is pc-relative and we are going to emit a relocation
22365 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22366 will need. Otherwise we want to use the calculated base.
22367 For WinCE we skip the bias for externals as well, since this
22368 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22369 if (fixP->fx_pcrel
2fc8bdac 22370 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22371 || (arm_force_relocation (fixP)
22372#ifdef TE_WINCE
22373 && !S_IS_EXTERNAL (fixP->fx_addsy)
22374#endif
22375 )))
2fc8bdac 22376 base = 0;
bfae80f2 22377
267bf995 22378
c19d1205 22379 switch (fixP->fx_r_type)
bfae80f2 22380 {
2fc8bdac
ZW
22381 /* PC relative addressing on the Thumb is slightly odd as the
22382 bottom two bits of the PC are forced to zero for the
22383 calculation. This happens *after* application of the
22384 pipeline offset. However, Thumb adrl already adjusts for
22385 this, so we need not do it again. */
c19d1205 22386 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22387 return base & ~3;
c19d1205
ZW
22388
22389 case BFD_RELOC_ARM_THUMB_OFFSET:
22390 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22391 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22392 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22393 return (base + 4) & ~3;
c19d1205 22394
2fc8bdac
ZW
22395 /* Thumb branches are simply offset by +4. */
22396 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22397 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22398 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22399 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22400 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22401 return base + 4;
bfae80f2 22402
267bf995 22403 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22404 if (fixP->fx_addsy
22405 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22406 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22407 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22408 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22409 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22410 return base + 4;
22411
00adf2d4
JB
22412 /* BLX is like branches above, but forces the low two bits of PC to
22413 zero. */
486499d0
CL
22414 case BFD_RELOC_THUMB_PCREL_BLX:
22415 if (fixP->fx_addsy
22416 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22417 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22418 && THUMB_IS_FUNC (fixP->fx_addsy)
22419 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22420 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22421 return (base + 4) & ~3;
22422
2fc8bdac
ZW
22423 /* ARM mode branches are offset by +8. However, the Windows CE
22424 loader expects the relocation not to take this into account. */
267bf995 22425 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22426 if (fixP->fx_addsy
22427 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22428 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22429 && ARM_IS_FUNC (fixP->fx_addsy)
22430 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22431 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22432 return base + 8;
267bf995 22433
486499d0
CL
22434 case BFD_RELOC_ARM_PCREL_CALL:
22435 if (fixP->fx_addsy
22436 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22437 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22438 && THUMB_IS_FUNC (fixP->fx_addsy)
22439 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22440 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22441 return base + 8;
267bf995 22442
2fc8bdac 22443 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22444 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22445 case BFD_RELOC_ARM_PLT32:
c19d1205 22446#ifdef TE_WINCE
5f4273c7 22447 /* When handling fixups immediately, because we have already
477330fc 22448 discovered the value of a symbol, or the address of the frag involved
53baae48 22449 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22450 see fixup_segment() in write.c
22451 The S_IS_EXTERNAL test handles the case of global symbols.
22452 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22453 if (fixP->fx_pcrel
22454 && fixP->fx_addsy != NULL
22455 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22456 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22457 return base + 8;
2fc8bdac 22458 return base;
c19d1205 22459#else
2fc8bdac 22460 return base + 8;
c19d1205 22461#endif
2fc8bdac 22462
267bf995 22463
2fc8bdac
ZW
22464 /* ARM mode loads relative to PC are also offset by +8. Unlike
22465 branches, the Windows CE loader *does* expect the relocation
22466 to take this into account. */
22467 case BFD_RELOC_ARM_OFFSET_IMM:
22468 case BFD_RELOC_ARM_OFFSET_IMM8:
22469 case BFD_RELOC_ARM_HWLITERAL:
22470 case BFD_RELOC_ARM_LITERAL:
22471 case BFD_RELOC_ARM_CP_OFF_IMM:
22472 return base + 8;
22473
22474
22475 /* Other PC-relative relocations are un-offset. */
22476 default:
22477 return base;
22478 }
bfae80f2
RE
22479}
22480
8b2d793c
NC
22481static bfd_boolean flag_warn_syms = TRUE;
22482
ae8714c2
NC
22483bfd_boolean
22484arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22485{
8b2d793c
NC
22486 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22487 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22488 does mean that the resulting code might be very confusing to the reader.
22489 Also this warning can be triggered if the user omits an operand before
22490 an immediate address, eg:
22491
22492 LDR =foo
22493
22494 GAS treats this as an assignment of the value of the symbol foo to a
22495 symbol LDR, and so (without this code) it will not issue any kind of
22496 warning or error message.
22497
22498 Note - ARM instructions are case-insensitive but the strings in the hash
22499 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22500 lower case too. */
22501 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22502 {
22503 char * nbuf = strdup (name);
22504 char * p;
22505
22506 for (p = nbuf; *p; p++)
22507 *p = TOLOWER (*p);
22508 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22509 {
22510 static struct hash_control * already_warned = NULL;
22511
22512 if (already_warned == NULL)
22513 already_warned = hash_new ();
22514 /* Only warn about the symbol once. To keep the code
22515 simple we let hash_insert do the lookup for us. */
22516 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22517 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22518 }
22519 else
22520 free (nbuf);
22521 }
3739860c 22522
ae8714c2
NC
22523 return FALSE;
22524}
22525
22526/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22527 Otherwise we have no need to default values of symbols. */
22528
22529symbolS *
22530md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22531{
22532#ifdef OBJ_ELF
22533 if (name[0] == '_' && name[1] == 'G'
22534 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22535 {
22536 if (!GOT_symbol)
22537 {
22538 if (symbol_find (name))
22539 as_bad (_("GOT already in the symbol table"));
22540
22541 GOT_symbol = symbol_new (name, undefined_section,
22542 (valueT) 0, & zero_address_frag);
22543 }
22544
22545 return GOT_symbol;
22546 }
22547#endif
22548
c921be7d 22549 return NULL;
bfae80f2
RE
22550}
22551
55cf6793 22552/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22553 computed as two separate immediate values, added together. We
22554 already know that this value cannot be computed by just one ARM
22555 instruction. */
22556
22557static unsigned int
22558validate_immediate_twopart (unsigned int val,
22559 unsigned int * highpart)
bfae80f2 22560{
c19d1205
ZW
22561 unsigned int a;
22562 unsigned int i;
bfae80f2 22563
c19d1205
ZW
22564 for (i = 0; i < 32; i += 2)
22565 if (((a = rotate_left (val, i)) & 0xff) != 0)
22566 {
22567 if (a & 0xff00)
22568 {
22569 if (a & ~ 0xffff)
22570 continue;
22571 * highpart = (a >> 8) | ((i + 24) << 7);
22572 }
22573 else if (a & 0xff0000)
22574 {
22575 if (a & 0xff000000)
22576 continue;
22577 * highpart = (a >> 16) | ((i + 16) << 7);
22578 }
22579 else
22580 {
9c2799c2 22581 gas_assert (a & 0xff000000);
c19d1205
ZW
22582 * highpart = (a >> 24) | ((i + 8) << 7);
22583 }
bfae80f2 22584
c19d1205
ZW
22585 return (a & 0xff) | (i << 7);
22586 }
bfae80f2 22587
c19d1205 22588 return FAIL;
bfae80f2
RE
22589}
22590
c19d1205
ZW
22591static int
22592validate_offset_imm (unsigned int val, int hwse)
22593{
22594 if ((hwse && val > 255) || val > 4095)
22595 return FAIL;
22596 return val;
22597}
bfae80f2 22598
55cf6793 22599/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22600 negative immediate constant by altering the instruction. A bit of
22601 a hack really.
22602 MOV <-> MVN
22603 AND <-> BIC
22604 ADC <-> SBC
22605 by inverting the second operand, and
22606 ADD <-> SUB
22607 CMP <-> CMN
22608 by negating the second operand. */
bfae80f2 22609
c19d1205
ZW
22610static int
22611negate_data_op (unsigned long * instruction,
22612 unsigned long value)
bfae80f2 22613{
c19d1205
ZW
22614 int op, new_inst;
22615 unsigned long negated, inverted;
bfae80f2 22616
c19d1205
ZW
22617 negated = encode_arm_immediate (-value);
22618 inverted = encode_arm_immediate (~value);
bfae80f2 22619
c19d1205
ZW
22620 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22621 switch (op)
bfae80f2 22622 {
c19d1205
ZW
22623 /* First negates. */
22624 case OPCODE_SUB: /* ADD <-> SUB */
22625 new_inst = OPCODE_ADD;
22626 value = negated;
22627 break;
bfae80f2 22628
c19d1205
ZW
22629 case OPCODE_ADD:
22630 new_inst = OPCODE_SUB;
22631 value = negated;
22632 break;
bfae80f2 22633
c19d1205
ZW
22634 case OPCODE_CMP: /* CMP <-> CMN */
22635 new_inst = OPCODE_CMN;
22636 value = negated;
22637 break;
bfae80f2 22638
c19d1205
ZW
22639 case OPCODE_CMN:
22640 new_inst = OPCODE_CMP;
22641 value = negated;
22642 break;
bfae80f2 22643
c19d1205
ZW
22644 /* Now Inverted ops. */
22645 case OPCODE_MOV: /* MOV <-> MVN */
22646 new_inst = OPCODE_MVN;
22647 value = inverted;
22648 break;
bfae80f2 22649
c19d1205
ZW
22650 case OPCODE_MVN:
22651 new_inst = OPCODE_MOV;
22652 value = inverted;
22653 break;
bfae80f2 22654
c19d1205
ZW
22655 case OPCODE_AND: /* AND <-> BIC */
22656 new_inst = OPCODE_BIC;
22657 value = inverted;
22658 break;
bfae80f2 22659
c19d1205
ZW
22660 case OPCODE_BIC:
22661 new_inst = OPCODE_AND;
22662 value = inverted;
22663 break;
bfae80f2 22664
c19d1205
ZW
22665 case OPCODE_ADC: /* ADC <-> SBC */
22666 new_inst = OPCODE_SBC;
22667 value = inverted;
22668 break;
bfae80f2 22669
c19d1205
ZW
22670 case OPCODE_SBC:
22671 new_inst = OPCODE_ADC;
22672 value = inverted;
22673 break;
bfae80f2 22674
c19d1205
ZW
22675 /* We cannot do anything. */
22676 default:
22677 return FAIL;
b99bd4ef
NC
22678 }
22679
c19d1205
ZW
22680 if (value == (unsigned) FAIL)
22681 return FAIL;
22682
22683 *instruction &= OPCODE_MASK;
22684 *instruction |= new_inst << DATA_OP_SHIFT;
22685 return value;
b99bd4ef
NC
22686}
22687
ef8d22e6
PB
22688/* Like negate_data_op, but for Thumb-2. */
22689
22690static unsigned int
16dd5e42 22691thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22692{
22693 int op, new_inst;
22694 int rd;
16dd5e42 22695 unsigned int negated, inverted;
ef8d22e6
PB
22696
22697 negated = encode_thumb32_immediate (-value);
22698 inverted = encode_thumb32_immediate (~value);
22699
22700 rd = (*instruction >> 8) & 0xf;
22701 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22702 switch (op)
22703 {
22704 /* ADD <-> SUB. Includes CMP <-> CMN. */
22705 case T2_OPCODE_SUB:
22706 new_inst = T2_OPCODE_ADD;
22707 value = negated;
22708 break;
22709
22710 case T2_OPCODE_ADD:
22711 new_inst = T2_OPCODE_SUB;
22712 value = negated;
22713 break;
22714
22715 /* ORR <-> ORN. Includes MOV <-> MVN. */
22716 case T2_OPCODE_ORR:
22717 new_inst = T2_OPCODE_ORN;
22718 value = inverted;
22719 break;
22720
22721 case T2_OPCODE_ORN:
22722 new_inst = T2_OPCODE_ORR;
22723 value = inverted;
22724 break;
22725
22726 /* AND <-> BIC. TST has no inverted equivalent. */
22727 case T2_OPCODE_AND:
22728 new_inst = T2_OPCODE_BIC;
22729 if (rd == 15)
22730 value = FAIL;
22731 else
22732 value = inverted;
22733 break;
22734
22735 case T2_OPCODE_BIC:
22736 new_inst = T2_OPCODE_AND;
22737 value = inverted;
22738 break;
22739
22740 /* ADC <-> SBC */
22741 case T2_OPCODE_ADC:
22742 new_inst = T2_OPCODE_SBC;
22743 value = inverted;
22744 break;
22745
22746 case T2_OPCODE_SBC:
22747 new_inst = T2_OPCODE_ADC;
22748 value = inverted;
22749 break;
22750
22751 /* We cannot do anything. */
22752 default:
22753 return FAIL;
22754 }
22755
16dd5e42 22756 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22757 return FAIL;
22758
22759 *instruction &= T2_OPCODE_MASK;
22760 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22761 return value;
22762}
22763
8f06b2d8
PB
22764/* Read a 32-bit thumb instruction from buf. */
22765static unsigned long
22766get_thumb32_insn (char * buf)
22767{
22768 unsigned long insn;
22769 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22770 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22771
22772 return insn;
22773}
22774
a8bc6c78
PB
22775
22776/* We usually want to set the low bit on the address of thumb function
22777 symbols. In particular .word foo - . should have the low bit set.
22778 Generic code tries to fold the difference of two symbols to
22779 a constant. Prevent this and force a relocation when the first symbols
22780 is a thumb function. */
c921be7d
NC
22781
22782bfd_boolean
a8bc6c78
PB
22783arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22784{
22785 if (op == O_subtract
22786 && l->X_op == O_symbol
22787 && r->X_op == O_symbol
22788 && THUMB_IS_FUNC (l->X_add_symbol))
22789 {
22790 l->X_op = O_subtract;
22791 l->X_op_symbol = r->X_add_symbol;
22792 l->X_add_number -= r->X_add_number;
c921be7d 22793 return TRUE;
a8bc6c78 22794 }
c921be7d 22795
a8bc6c78 22796 /* Process as normal. */
c921be7d 22797 return FALSE;
a8bc6c78
PB
22798}
22799
4a42ebbc
RR
22800/* Encode Thumb2 unconditional branches and calls. The encoding
22801 for the 2 are identical for the immediate values. */
22802
22803static void
22804encode_thumb2_b_bl_offset (char * buf, offsetT value)
22805{
22806#define T2I1I2MASK ((1 << 13) | (1 << 11))
22807 offsetT newval;
22808 offsetT newval2;
22809 addressT S, I1, I2, lo, hi;
22810
22811 S = (value >> 24) & 0x01;
22812 I1 = (value >> 23) & 0x01;
22813 I2 = (value >> 22) & 0x01;
22814 hi = (value >> 12) & 0x3ff;
fa94de6b 22815 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22816 newval = md_chars_to_number (buf, THUMB_SIZE);
22817 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22818 newval |= (S << 10) | hi;
22819 newval2 &= ~T2I1I2MASK;
22820 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22821 md_number_to_chars (buf, newval, THUMB_SIZE);
22822 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22823}
22824
c19d1205 22825void
55cf6793 22826md_apply_fix (fixS * fixP,
c19d1205
ZW
22827 valueT * valP,
22828 segT seg)
22829{
22830 offsetT value = * valP;
22831 offsetT newval;
22832 unsigned int newimm;
22833 unsigned long temp;
22834 int sign;
22835 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22836
9c2799c2 22837 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22838
c19d1205 22839 /* Note whether this will delete the relocation. */
4962c51a 22840
c19d1205
ZW
22841 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22842 fixP->fx_done = 1;
b99bd4ef 22843
adbaf948 22844 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22845 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22846 for emit_reloc. */
22847 value &= 0xffffffff;
22848 value ^= 0x80000000;
5f4273c7 22849 value -= 0x80000000;
adbaf948
ZW
22850
22851 *valP = value;
c19d1205 22852 fixP->fx_addnumber = value;
b99bd4ef 22853
adbaf948
ZW
22854 /* Same treatment for fixP->fx_offset. */
22855 fixP->fx_offset &= 0xffffffff;
22856 fixP->fx_offset ^= 0x80000000;
22857 fixP->fx_offset -= 0x80000000;
22858
c19d1205 22859 switch (fixP->fx_r_type)
b99bd4ef 22860 {
c19d1205
ZW
22861 case BFD_RELOC_NONE:
22862 /* This will need to go in the object file. */
22863 fixP->fx_done = 0;
22864 break;
b99bd4ef 22865
c19d1205
ZW
22866 case BFD_RELOC_ARM_IMMEDIATE:
22867 /* We claim that this fixup has been processed here,
22868 even if in fact we generate an error because we do
22869 not have a reloc for it, so tc_gen_reloc will reject it. */
22870 fixP->fx_done = 1;
b99bd4ef 22871
77db8e2e 22872 if (fixP->fx_addsy)
b99bd4ef 22873 {
77db8e2e 22874 const char *msg = 0;
b99bd4ef 22875
77db8e2e
NC
22876 if (! S_IS_DEFINED (fixP->fx_addsy))
22877 msg = _("undefined symbol %s used as an immediate value");
22878 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22879 msg = _("symbol %s is in a different section");
22880 else if (S_IS_WEAK (fixP->fx_addsy))
22881 msg = _("symbol %s is weak and may be overridden later");
22882
22883 if (msg)
22884 {
22885 as_bad_where (fixP->fx_file, fixP->fx_line,
22886 msg, S_GET_NAME (fixP->fx_addsy));
22887 break;
22888 }
42e5fcbf
AS
22889 }
22890
c19d1205
ZW
22891 temp = md_chars_to_number (buf, INSN_SIZE);
22892
5e73442d
SL
22893 /* If the offset is negative, we should use encoding A2 for ADR. */
22894 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22895 newimm = negate_data_op (&temp, value);
22896 else
22897 {
22898 newimm = encode_arm_immediate (value);
22899
22900 /* If the instruction will fail, see if we can fix things up by
22901 changing the opcode. */
22902 if (newimm == (unsigned int) FAIL)
22903 newimm = negate_data_op (&temp, value);
bada4342
JW
22904 /* MOV accepts both ARM modified immediate (A1 encoding) and
22905 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
22906 When disassembling, MOV is preferred when there is no encoding
22907 overlap. */
22908 if (newimm == (unsigned int) FAIL
22909 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
22910 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
22911 && !((temp >> SBIT_SHIFT) & 0x1)
22912 && value >= 0 && value <= 0xffff)
22913 {
22914 /* Clear bits[23:20] to change encoding from A1 to A2. */
22915 temp &= 0xff0fffff;
22916 /* Encoding high 4bits imm. Code below will encode the remaining
22917 low 12bits. */
22918 temp |= (value & 0x0000f000) << 4;
22919 newimm = value & 0x00000fff;
22920 }
5e73442d
SL
22921 }
22922
22923 if (newimm == (unsigned int) FAIL)
b99bd4ef 22924 {
c19d1205
ZW
22925 as_bad_where (fixP->fx_file, fixP->fx_line,
22926 _("invalid constant (%lx) after fixup"),
22927 (unsigned long) value);
22928 break;
b99bd4ef 22929 }
b99bd4ef 22930
c19d1205
ZW
22931 newimm |= (temp & 0xfffff000);
22932 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22933 break;
b99bd4ef 22934
c19d1205
ZW
22935 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22936 {
22937 unsigned int highpart = 0;
22938 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22939
77db8e2e 22940 if (fixP->fx_addsy)
42e5fcbf 22941 {
77db8e2e 22942 const char *msg = 0;
42e5fcbf 22943
77db8e2e
NC
22944 if (! S_IS_DEFINED (fixP->fx_addsy))
22945 msg = _("undefined symbol %s used as an immediate value");
22946 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22947 msg = _("symbol %s is in a different section");
22948 else if (S_IS_WEAK (fixP->fx_addsy))
22949 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22950
77db8e2e
NC
22951 if (msg)
22952 {
22953 as_bad_where (fixP->fx_file, fixP->fx_line,
22954 msg, S_GET_NAME (fixP->fx_addsy));
22955 break;
22956 }
22957 }
fa94de6b 22958
c19d1205
ZW
22959 newimm = encode_arm_immediate (value);
22960 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22961
c19d1205
ZW
22962 /* If the instruction will fail, see if we can fix things up by
22963 changing the opcode. */
22964 if (newimm == (unsigned int) FAIL
22965 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22966 {
22967 /* No ? OK - try using two ADD instructions to generate
22968 the value. */
22969 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22970
c19d1205
ZW
22971 /* Yes - then make sure that the second instruction is
22972 also an add. */
22973 if (newimm != (unsigned int) FAIL)
22974 newinsn = temp;
22975 /* Still No ? Try using a negated value. */
22976 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22977 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22978 /* Otherwise - give up. */
22979 else
22980 {
22981 as_bad_where (fixP->fx_file, fixP->fx_line,
22982 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22983 (long) value);
22984 break;
22985 }
b99bd4ef 22986
c19d1205
ZW
22987 /* Replace the first operand in the 2nd instruction (which
22988 is the PC) with the destination register. We have
22989 already added in the PC in the first instruction and we
22990 do not want to do it again. */
22991 newinsn &= ~ 0xf0000;
22992 newinsn |= ((newinsn & 0x0f000) << 4);
22993 }
b99bd4ef 22994
c19d1205
ZW
22995 newimm |= (temp & 0xfffff000);
22996 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22997
c19d1205
ZW
22998 highpart |= (newinsn & 0xfffff000);
22999 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23000 }
23001 break;
b99bd4ef 23002
c19d1205 23003 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23004 if (!fixP->fx_done && seg->use_rela_p)
23005 value = 0;
1a0670f3 23006 /* Fall through. */
00a97672 23007
c19d1205 23008 case BFD_RELOC_ARM_LITERAL:
26d97720 23009 sign = value > 0;
b99bd4ef 23010
c19d1205
ZW
23011 if (value < 0)
23012 value = - value;
b99bd4ef 23013
c19d1205 23014 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23015 {
c19d1205
ZW
23016 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23017 as_bad_where (fixP->fx_file, fixP->fx_line,
23018 _("invalid literal constant: pool needs to be closer"));
23019 else
23020 as_bad_where (fixP->fx_file, fixP->fx_line,
23021 _("bad immediate value for offset (%ld)"),
23022 (long) value);
23023 break;
f03698e6
RE
23024 }
23025
c19d1205 23026 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23027 if (value == 0)
23028 newval &= 0xfffff000;
23029 else
23030 {
23031 newval &= 0xff7ff000;
23032 newval |= value | (sign ? INDEX_UP : 0);
23033 }
c19d1205
ZW
23034 md_number_to_chars (buf, newval, INSN_SIZE);
23035 break;
b99bd4ef 23036
c19d1205
ZW
23037 case BFD_RELOC_ARM_OFFSET_IMM8:
23038 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23039 sign = value > 0;
b99bd4ef 23040
c19d1205
ZW
23041 if (value < 0)
23042 value = - value;
b99bd4ef 23043
c19d1205 23044 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23045 {
c19d1205
ZW
23046 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23047 as_bad_where (fixP->fx_file, fixP->fx_line,
23048 _("invalid literal constant: pool needs to be closer"));
23049 else
427d0db6
RM
23050 as_bad_where (fixP->fx_file, fixP->fx_line,
23051 _("bad immediate value for 8-bit offset (%ld)"),
23052 (long) value);
c19d1205 23053 break;
b99bd4ef
NC
23054 }
23055
c19d1205 23056 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23057 if (value == 0)
23058 newval &= 0xfffff0f0;
23059 else
23060 {
23061 newval &= 0xff7ff0f0;
23062 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23063 }
c19d1205
ZW
23064 md_number_to_chars (buf, newval, INSN_SIZE);
23065 break;
b99bd4ef 23066
c19d1205
ZW
23067 case BFD_RELOC_ARM_T32_OFFSET_U8:
23068 if (value < 0 || value > 1020 || value % 4 != 0)
23069 as_bad_where (fixP->fx_file, fixP->fx_line,
23070 _("bad immediate value for offset (%ld)"), (long) value);
23071 value /= 4;
b99bd4ef 23072
c19d1205 23073 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23074 newval |= value;
23075 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23076 break;
b99bd4ef 23077
c19d1205
ZW
23078 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23079 /* This is a complicated relocation used for all varieties of Thumb32
23080 load/store instruction with immediate offset:
23081
23082 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23083 *4, optional writeback(W)
c19d1205
ZW
23084 (doubleword load/store)
23085
23086 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23087 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23088 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23089 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23090 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23091
23092 Uppercase letters indicate bits that are already encoded at
23093 this point. Lowercase letters are our problem. For the
23094 second block of instructions, the secondary opcode nybble
23095 (bits 8..11) is present, and bit 23 is zero, even if this is
23096 a PC-relative operation. */
23097 newval = md_chars_to_number (buf, THUMB_SIZE);
23098 newval <<= 16;
23099 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23100
c19d1205 23101 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23102 {
c19d1205
ZW
23103 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23104 if (value >= 0)
23105 newval |= (1 << 23);
23106 else
23107 value = -value;
23108 if (value % 4 != 0)
23109 {
23110 as_bad_where (fixP->fx_file, fixP->fx_line,
23111 _("offset not a multiple of 4"));
23112 break;
23113 }
23114 value /= 4;
216d22bc 23115 if (value > 0xff)
c19d1205
ZW
23116 {
23117 as_bad_where (fixP->fx_file, fixP->fx_line,
23118 _("offset out of range"));
23119 break;
23120 }
23121 newval &= ~0xff;
b99bd4ef 23122 }
c19d1205 23123 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23124 {
c19d1205
ZW
23125 /* PC-relative, 12-bit offset. */
23126 if (value >= 0)
23127 newval |= (1 << 23);
23128 else
23129 value = -value;
216d22bc 23130 if (value > 0xfff)
c19d1205
ZW
23131 {
23132 as_bad_where (fixP->fx_file, fixP->fx_line,
23133 _("offset out of range"));
23134 break;
23135 }
23136 newval &= ~0xfff;
b99bd4ef 23137 }
c19d1205 23138 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23139 {
c19d1205
ZW
23140 /* Writeback: 8-bit, +/- offset. */
23141 if (value >= 0)
23142 newval |= (1 << 9);
23143 else
23144 value = -value;
216d22bc 23145 if (value > 0xff)
c19d1205
ZW
23146 {
23147 as_bad_where (fixP->fx_file, fixP->fx_line,
23148 _("offset out of range"));
23149 break;
23150 }
23151 newval &= ~0xff;
b99bd4ef 23152 }
c19d1205 23153 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23154 {
c19d1205 23155 /* T-instruction: positive 8-bit offset. */
216d22bc 23156 if (value < 0 || value > 0xff)
b99bd4ef 23157 {
c19d1205
ZW
23158 as_bad_where (fixP->fx_file, fixP->fx_line,
23159 _("offset out of range"));
23160 break;
b99bd4ef 23161 }
c19d1205
ZW
23162 newval &= ~0xff;
23163 newval |= value;
b99bd4ef
NC
23164 }
23165 else
b99bd4ef 23166 {
c19d1205
ZW
23167 /* Positive 12-bit or negative 8-bit offset. */
23168 int limit;
23169 if (value >= 0)
b99bd4ef 23170 {
c19d1205
ZW
23171 newval |= (1 << 23);
23172 limit = 0xfff;
23173 }
23174 else
23175 {
23176 value = -value;
23177 limit = 0xff;
23178 }
23179 if (value > limit)
23180 {
23181 as_bad_where (fixP->fx_file, fixP->fx_line,
23182 _("offset out of range"));
23183 break;
b99bd4ef 23184 }
c19d1205 23185 newval &= ~limit;
b99bd4ef 23186 }
b99bd4ef 23187
c19d1205
ZW
23188 newval |= value;
23189 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23190 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23191 break;
404ff6b5 23192
c19d1205
ZW
23193 case BFD_RELOC_ARM_SHIFT_IMM:
23194 newval = md_chars_to_number (buf, INSN_SIZE);
23195 if (((unsigned long) value) > 32
23196 || (value == 32
23197 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23198 {
23199 as_bad_where (fixP->fx_file, fixP->fx_line,
23200 _("shift expression is too large"));
23201 break;
23202 }
404ff6b5 23203
c19d1205
ZW
23204 if (value == 0)
23205 /* Shifts of zero must be done as lsl. */
23206 newval &= ~0x60;
23207 else if (value == 32)
23208 value = 0;
23209 newval &= 0xfffff07f;
23210 newval |= (value & 0x1f) << 7;
23211 md_number_to_chars (buf, newval, INSN_SIZE);
23212 break;
404ff6b5 23213
c19d1205 23214 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23215 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23216 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23217 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23218 /* We claim that this fixup has been processed here,
23219 even if in fact we generate an error because we do
23220 not have a reloc for it, so tc_gen_reloc will reject it. */
23221 fixP->fx_done = 1;
404ff6b5 23222
c19d1205
ZW
23223 if (fixP->fx_addsy
23224 && ! S_IS_DEFINED (fixP->fx_addsy))
23225 {
23226 as_bad_where (fixP->fx_file, fixP->fx_line,
23227 _("undefined symbol %s used as an immediate value"),
23228 S_GET_NAME (fixP->fx_addsy));
23229 break;
23230 }
404ff6b5 23231
c19d1205
ZW
23232 newval = md_chars_to_number (buf, THUMB_SIZE);
23233 newval <<= 16;
23234 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23235
16805f35 23236 newimm = FAIL;
bada4342
JW
23237 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23238 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23239 Thumb2 modified immediate encoding (T2). */
23240 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23241 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23242 {
23243 newimm = encode_thumb32_immediate (value);
23244 if (newimm == (unsigned int) FAIL)
23245 newimm = thumb32_negate_data_op (&newval, value);
23246 }
bada4342 23247 if (newimm == (unsigned int) FAIL)
92e90b6e 23248 {
bada4342 23249 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23250 {
bada4342
JW
23251 /* Turn add/sum into addw/subw. */
23252 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23253 newval = (newval & 0xfeffffff) | 0x02000000;
23254 /* No flat 12-bit imm encoding for addsw/subsw. */
23255 if ((newval & 0x00100000) == 0)
40f246e3 23256 {
bada4342
JW
23257 /* 12 bit immediate for addw/subw. */
23258 if (value < 0)
23259 {
23260 value = -value;
23261 newval ^= 0x00a00000;
23262 }
23263 if (value > 0xfff)
23264 newimm = (unsigned int) FAIL;
23265 else
23266 newimm = value;
23267 }
23268 }
23269 else
23270 {
23271 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23272 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23273 disassembling, MOV is preferred when there is no encoding
23274 overlap.
23275 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23276 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23277 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23278 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23279 && value >= 0 && value <=0xffff)
23280 {
23281 /* Toggle bit[25] to change encoding from T2 to T3. */
23282 newval ^= 1 << 25;
23283 /* Clear bits[19:16]. */
23284 newval &= 0xfff0ffff;
23285 /* Encoding high 4bits imm. Code below will encode the
23286 remaining low 12bits. */
23287 newval |= (value & 0x0000f000) << 4;
23288 newimm = value & 0x00000fff;
40f246e3 23289 }
e9f89963 23290 }
92e90b6e 23291 }
cc8a6dd0 23292
c19d1205 23293 if (newimm == (unsigned int)FAIL)
3631a3c8 23294 {
c19d1205
ZW
23295 as_bad_where (fixP->fx_file, fixP->fx_line,
23296 _("invalid constant (%lx) after fixup"),
23297 (unsigned long) value);
23298 break;
3631a3c8
NC
23299 }
23300
c19d1205
ZW
23301 newval |= (newimm & 0x800) << 15;
23302 newval |= (newimm & 0x700) << 4;
23303 newval |= (newimm & 0x0ff);
cc8a6dd0 23304
c19d1205
ZW
23305 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23306 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23307 break;
a737bd4d 23308
3eb17e6b 23309 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23310 if (((unsigned long) value) > 0xffff)
23311 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23312 _("invalid smc expression"));
2fc8bdac 23313 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23314 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23315 md_number_to_chars (buf, newval, INSN_SIZE);
23316 break;
a737bd4d 23317
90ec0d68
MGD
23318 case BFD_RELOC_ARM_HVC:
23319 if (((unsigned long) value) > 0xffff)
23320 as_bad_where (fixP->fx_file, fixP->fx_line,
23321 _("invalid hvc expression"));
23322 newval = md_chars_to_number (buf, INSN_SIZE);
23323 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23324 md_number_to_chars (buf, newval, INSN_SIZE);
23325 break;
23326
c19d1205 23327 case BFD_RELOC_ARM_SWI:
adbaf948 23328 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23329 {
23330 if (((unsigned long) value) > 0xff)
23331 as_bad_where (fixP->fx_file, fixP->fx_line,
23332 _("invalid swi expression"));
2fc8bdac 23333 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23334 newval |= value;
23335 md_number_to_chars (buf, newval, THUMB_SIZE);
23336 }
23337 else
23338 {
23339 if (((unsigned long) value) > 0x00ffffff)
23340 as_bad_where (fixP->fx_file, fixP->fx_line,
23341 _("invalid swi expression"));
2fc8bdac 23342 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23343 newval |= value;
23344 md_number_to_chars (buf, newval, INSN_SIZE);
23345 }
23346 break;
a737bd4d 23347
c19d1205
ZW
23348 case BFD_RELOC_ARM_MULTI:
23349 if (((unsigned long) value) > 0xffff)
23350 as_bad_where (fixP->fx_file, fixP->fx_line,
23351 _("invalid expression in load/store multiple"));
23352 newval = value | md_chars_to_number (buf, INSN_SIZE);
23353 md_number_to_chars (buf, newval, INSN_SIZE);
23354 break;
a737bd4d 23355
c19d1205 23356#ifdef OBJ_ELF
39b41c9c 23357 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23358
23359 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23360 && fixP->fx_addsy
34e77a92 23361 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23362 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23363 && THUMB_IS_FUNC (fixP->fx_addsy))
23364 /* Flip the bl to blx. This is a simple flip
23365 bit here because we generate PCREL_CALL for
23366 unconditional bls. */
23367 {
23368 newval = md_chars_to_number (buf, INSN_SIZE);
23369 newval = newval | 0x10000000;
23370 md_number_to_chars (buf, newval, INSN_SIZE);
23371 temp = 1;
23372 fixP->fx_done = 1;
23373 }
39b41c9c
PB
23374 else
23375 temp = 3;
23376 goto arm_branch_common;
23377
23378 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23379 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23380 && fixP->fx_addsy
34e77a92 23381 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23382 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23383 && THUMB_IS_FUNC (fixP->fx_addsy))
23384 {
23385 /* This would map to a bl<cond>, b<cond>,
23386 b<always> to a Thumb function. We
23387 need to force a relocation for this particular
23388 case. */
23389 newval = md_chars_to_number (buf, INSN_SIZE);
23390 fixP->fx_done = 0;
23391 }
1a0670f3 23392 /* Fall through. */
267bf995 23393
2fc8bdac 23394 case BFD_RELOC_ARM_PLT32:
c19d1205 23395#endif
39b41c9c
PB
23396 case BFD_RELOC_ARM_PCREL_BRANCH:
23397 temp = 3;
23398 goto arm_branch_common;
a737bd4d 23399
39b41c9c 23400 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23401
39b41c9c 23402 temp = 1;
267bf995
RR
23403 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23404 && fixP->fx_addsy
34e77a92 23405 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23406 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23407 && ARM_IS_FUNC (fixP->fx_addsy))
23408 {
23409 /* Flip the blx to a bl and warn. */
23410 const char *name = S_GET_NAME (fixP->fx_addsy);
23411 newval = 0xeb000000;
23412 as_warn_where (fixP->fx_file, fixP->fx_line,
23413 _("blx to '%s' an ARM ISA state function changed to bl"),
23414 name);
23415 md_number_to_chars (buf, newval, INSN_SIZE);
23416 temp = 3;
23417 fixP->fx_done = 1;
23418 }
23419
23420#ifdef OBJ_ELF
23421 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23422 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23423#endif
23424
39b41c9c 23425 arm_branch_common:
c19d1205 23426 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23427 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23428 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23429 also be be clear. */
23430 if (value & temp)
c19d1205 23431 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23432 _("misaligned branch destination"));
23433 if ((value & (offsetT)0xfe000000) != (offsetT)0
23434 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23435 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23436
2fc8bdac 23437 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23438 {
2fc8bdac
ZW
23439 newval = md_chars_to_number (buf, INSN_SIZE);
23440 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23441 /* Set the H bit on BLX instructions. */
23442 if (temp == 1)
23443 {
23444 if (value & 2)
23445 newval |= 0x01000000;
23446 else
23447 newval &= ~0x01000000;
23448 }
2fc8bdac 23449 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23450 }
c19d1205 23451 break;
a737bd4d 23452
25fe350b
MS
23453 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23454 /* CBZ can only branch forward. */
a737bd4d 23455
738755b0 23456 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23457 (which, strictly speaking, are prohibited) will be turned into
23458 no-ops.
738755b0
MS
23459
23460 FIXME: It may be better to remove the instruction completely and
23461 perform relaxation. */
23462 if (value == -2)
2fc8bdac
ZW
23463 {
23464 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23465 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23466 md_number_to_chars (buf, newval, THUMB_SIZE);
23467 }
738755b0
MS
23468 else
23469 {
23470 if (value & ~0x7e)
08f10d51 23471 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23472
477330fc 23473 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23474 {
23475 newval = md_chars_to_number (buf, THUMB_SIZE);
23476 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23477 md_number_to_chars (buf, newval, THUMB_SIZE);
23478 }
23479 }
c19d1205 23480 break;
a737bd4d 23481
c19d1205 23482 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23483 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23484 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23485
2fc8bdac
ZW
23486 if (fixP->fx_done || !seg->use_rela_p)
23487 {
23488 newval = md_chars_to_number (buf, THUMB_SIZE);
23489 newval |= (value & 0x1ff) >> 1;
23490 md_number_to_chars (buf, newval, THUMB_SIZE);
23491 }
c19d1205 23492 break;
a737bd4d 23493
c19d1205 23494 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23495 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23496 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23497
2fc8bdac
ZW
23498 if (fixP->fx_done || !seg->use_rela_p)
23499 {
23500 newval = md_chars_to_number (buf, THUMB_SIZE);
23501 newval |= (value & 0xfff) >> 1;
23502 md_number_to_chars (buf, newval, THUMB_SIZE);
23503 }
c19d1205 23504 break;
a737bd4d 23505
c19d1205 23506 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23507 if (fixP->fx_addsy
23508 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23509 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23510 && ARM_IS_FUNC (fixP->fx_addsy)
23511 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23512 {
23513 /* Force a relocation for a branch 20 bits wide. */
23514 fixP->fx_done = 0;
23515 }
08f10d51 23516 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23517 as_bad_where (fixP->fx_file, fixP->fx_line,
23518 _("conditional branch out of range"));
404ff6b5 23519
2fc8bdac
ZW
23520 if (fixP->fx_done || !seg->use_rela_p)
23521 {
23522 offsetT newval2;
23523 addressT S, J1, J2, lo, hi;
404ff6b5 23524
2fc8bdac
ZW
23525 S = (value & 0x00100000) >> 20;
23526 J2 = (value & 0x00080000) >> 19;
23527 J1 = (value & 0x00040000) >> 18;
23528 hi = (value & 0x0003f000) >> 12;
23529 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23530
2fc8bdac
ZW
23531 newval = md_chars_to_number (buf, THUMB_SIZE);
23532 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23533 newval |= (S << 10) | hi;
23534 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23535 md_number_to_chars (buf, newval, THUMB_SIZE);
23536 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23537 }
c19d1205 23538 break;
6c43fab6 23539
c19d1205 23540 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23541 /* If there is a blx from a thumb state function to
23542 another thumb function flip this to a bl and warn
23543 about it. */
23544
23545 if (fixP->fx_addsy
34e77a92 23546 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23547 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23548 && THUMB_IS_FUNC (fixP->fx_addsy))
23549 {
23550 const char *name = S_GET_NAME (fixP->fx_addsy);
23551 as_warn_where (fixP->fx_file, fixP->fx_line,
23552 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23553 name);
23554 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23555 newval = newval | 0x1000;
23556 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23557 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23558 fixP->fx_done = 1;
23559 }
23560
23561
23562 goto thumb_bl_common;
23563
c19d1205 23564 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23565 /* A bl from Thumb state ISA to an internal ARM state function
23566 is converted to a blx. */
23567 if (fixP->fx_addsy
23568 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23569 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23570 && ARM_IS_FUNC (fixP->fx_addsy)
23571 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23572 {
23573 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23574 newval = newval & ~0x1000;
23575 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23576 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23577 fixP->fx_done = 1;
23578 }
23579
23580 thumb_bl_common:
23581
2fc8bdac
ZW
23582 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23583 /* For a BLX instruction, make sure that the relocation is rounded up
23584 to a word boundary. This follows the semantics of the instruction
23585 which specifies that bit 1 of the target address will come from bit
23586 1 of the base address. */
d406f3e4
JB
23587 value = (value + 3) & ~ 3;
23588
23589#ifdef OBJ_ELF
23590 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23591 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23592 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23593#endif
404ff6b5 23594
2b2f5df9
NC
23595 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23596 {
fc289b0a 23597 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23598 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23599 else if ((value & ~0x1ffffff)
23600 && ((value & ~0x1ffffff) != ~0x1ffffff))
23601 as_bad_where (fixP->fx_file, fixP->fx_line,
23602 _("Thumb2 branch out of range"));
23603 }
4a42ebbc
RR
23604
23605 if (fixP->fx_done || !seg->use_rela_p)
23606 encode_thumb2_b_bl_offset (buf, value);
23607
c19d1205 23608 break;
404ff6b5 23609
c19d1205 23610 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23611 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23612 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23613
2fc8bdac 23614 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23615 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23616
2fc8bdac 23617 break;
a737bd4d 23618
2fc8bdac
ZW
23619 case BFD_RELOC_8:
23620 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23621 *buf = value;
c19d1205 23622 break;
a737bd4d 23623
c19d1205 23624 case BFD_RELOC_16:
2fc8bdac 23625 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23626 md_number_to_chars (buf, value, 2);
c19d1205 23627 break;
a737bd4d 23628
c19d1205 23629#ifdef OBJ_ELF
0855e32b
NS
23630 case BFD_RELOC_ARM_TLS_CALL:
23631 case BFD_RELOC_ARM_THM_TLS_CALL:
23632 case BFD_RELOC_ARM_TLS_DESCSEQ:
23633 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23634 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23635 case BFD_RELOC_ARM_TLS_GD32:
23636 case BFD_RELOC_ARM_TLS_LE32:
23637 case BFD_RELOC_ARM_TLS_IE32:
23638 case BFD_RELOC_ARM_TLS_LDM32:
23639 case BFD_RELOC_ARM_TLS_LDO32:
23640 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23641 break;
6c43fab6 23642
c19d1205
ZW
23643 case BFD_RELOC_ARM_GOT32:
23644 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23645 break;
b43420e6
NC
23646
23647 case BFD_RELOC_ARM_GOT_PREL:
23648 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23649 md_number_to_chars (buf, value, 4);
b43420e6
NC
23650 break;
23651
9a6f4e97
NS
23652 case BFD_RELOC_ARM_TARGET2:
23653 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23654 addend here for REL targets, because it won't be written out
23655 during reloc processing later. */
9a6f4e97
NS
23656 if (fixP->fx_done || !seg->use_rela_p)
23657 md_number_to_chars (buf, fixP->fx_offset, 4);
23658 break;
c19d1205 23659#endif
6c43fab6 23660
c19d1205
ZW
23661 case BFD_RELOC_RVA:
23662 case BFD_RELOC_32:
23663 case BFD_RELOC_ARM_TARGET1:
23664 case BFD_RELOC_ARM_ROSEGREL32:
23665 case BFD_RELOC_ARM_SBREL32:
23666 case BFD_RELOC_32_PCREL:
f0927246
NC
23667#ifdef TE_PE
23668 case BFD_RELOC_32_SECREL:
23669#endif
2fc8bdac 23670 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23671#ifdef TE_WINCE
23672 /* For WinCE we only do this for pcrel fixups. */
23673 if (fixP->fx_done || fixP->fx_pcrel)
23674#endif
23675 md_number_to_chars (buf, value, 4);
c19d1205 23676 break;
6c43fab6 23677
c19d1205
ZW
23678#ifdef OBJ_ELF
23679 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23680 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23681 {
23682 newval = md_chars_to_number (buf, 4) & 0x80000000;
23683 if ((value ^ (value >> 1)) & 0x40000000)
23684 {
23685 as_bad_where (fixP->fx_file, fixP->fx_line,
23686 _("rel31 relocation overflow"));
23687 }
23688 newval |= value & 0x7fffffff;
23689 md_number_to_chars (buf, newval, 4);
23690 }
23691 break;
c19d1205 23692#endif
a737bd4d 23693
c19d1205 23694 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23695 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23696 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23697 newval = md_chars_to_number (buf, INSN_SIZE);
23698 else
23699 newval = get_thumb32_insn (buf);
23700 if ((newval & 0x0f200f00) == 0x0d000900)
23701 {
23702 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23703 has permitted values that are multiples of 2, in the range 0
23704 to 510. */
23705 if (value < -510 || value > 510 || (value & 1))
23706 as_bad_where (fixP->fx_file, fixP->fx_line,
23707 _("co-processor offset out of range"));
23708 }
23709 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23710 as_bad_where (fixP->fx_file, fixP->fx_line,
23711 _("co-processor offset out of range"));
23712 cp_off_common:
26d97720 23713 sign = value > 0;
c19d1205
ZW
23714 if (value < 0)
23715 value = -value;
8f06b2d8
PB
23716 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23717 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23718 newval = md_chars_to_number (buf, INSN_SIZE);
23719 else
23720 newval = get_thumb32_insn (buf);
26d97720
NS
23721 if (value == 0)
23722 newval &= 0xffffff00;
23723 else
23724 {
23725 newval &= 0xff7fff00;
9db2f6b4
RL
23726 if ((newval & 0x0f200f00) == 0x0d000900)
23727 {
23728 /* This is a fp16 vstr/vldr.
23729
23730 It requires the immediate offset in the instruction is shifted
23731 left by 1 to be a half-word offset.
23732
23733 Here, left shift by 1 first, and later right shift by 2
23734 should get the right offset. */
23735 value <<= 1;
23736 }
26d97720
NS
23737 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23738 }
8f06b2d8
PB
23739 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23740 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23741 md_number_to_chars (buf, newval, INSN_SIZE);
23742 else
23743 put_thumb32_insn (buf, newval);
c19d1205 23744 break;
a737bd4d 23745
c19d1205 23746 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23747 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23748 if (value < -255 || value > 255)
23749 as_bad_where (fixP->fx_file, fixP->fx_line,
23750 _("co-processor offset out of range"));
df7849c5 23751 value *= 4;
c19d1205 23752 goto cp_off_common;
6c43fab6 23753
c19d1205
ZW
23754 case BFD_RELOC_ARM_THUMB_OFFSET:
23755 newval = md_chars_to_number (buf, THUMB_SIZE);
23756 /* Exactly what ranges, and where the offset is inserted depends
23757 on the type of instruction, we can establish this from the
23758 top 4 bits. */
23759 switch (newval >> 12)
23760 {
23761 case 4: /* PC load. */
23762 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23763 forced to zero for these loads; md_pcrel_from has already
23764 compensated for this. */
23765 if (value & 3)
23766 as_bad_where (fixP->fx_file, fixP->fx_line,
23767 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23768 (((unsigned long) fixP->fx_frag->fr_address
23769 + (unsigned long) fixP->fx_where) & ~3)
23770 + (unsigned long) value);
a737bd4d 23771
c19d1205
ZW
23772 if (value & ~0x3fc)
23773 as_bad_where (fixP->fx_file, fixP->fx_line,
23774 _("invalid offset, value too big (0x%08lX)"),
23775 (long) value);
a737bd4d 23776
c19d1205
ZW
23777 newval |= value >> 2;
23778 break;
a737bd4d 23779
c19d1205
ZW
23780 case 9: /* SP load/store. */
23781 if (value & ~0x3fc)
23782 as_bad_where (fixP->fx_file, fixP->fx_line,
23783 _("invalid offset, value too big (0x%08lX)"),
23784 (long) value);
23785 newval |= value >> 2;
23786 break;
6c43fab6 23787
c19d1205
ZW
23788 case 6: /* Word load/store. */
23789 if (value & ~0x7c)
23790 as_bad_where (fixP->fx_file, fixP->fx_line,
23791 _("invalid offset, value too big (0x%08lX)"),
23792 (long) value);
23793 newval |= value << 4; /* 6 - 2. */
23794 break;
a737bd4d 23795
c19d1205
ZW
23796 case 7: /* Byte load/store. */
23797 if (value & ~0x1f)
23798 as_bad_where (fixP->fx_file, fixP->fx_line,
23799 _("invalid offset, value too big (0x%08lX)"),
23800 (long) value);
23801 newval |= value << 6;
23802 break;
a737bd4d 23803
c19d1205
ZW
23804 case 8: /* Halfword load/store. */
23805 if (value & ~0x3e)
23806 as_bad_where (fixP->fx_file, fixP->fx_line,
23807 _("invalid offset, value too big (0x%08lX)"),
23808 (long) value);
23809 newval |= value << 5; /* 6 - 1. */
23810 break;
a737bd4d 23811
c19d1205
ZW
23812 default:
23813 as_bad_where (fixP->fx_file, fixP->fx_line,
23814 "Unable to process relocation for thumb opcode: %lx",
23815 (unsigned long) newval);
23816 break;
23817 }
23818 md_number_to_chars (buf, newval, THUMB_SIZE);
23819 break;
a737bd4d 23820
c19d1205
ZW
23821 case BFD_RELOC_ARM_THUMB_ADD:
23822 /* This is a complicated relocation, since we use it for all of
23823 the following immediate relocations:
a737bd4d 23824
c19d1205
ZW
23825 3bit ADD/SUB
23826 8bit ADD/SUB
23827 9bit ADD/SUB SP word-aligned
23828 10bit ADD PC/SP word-aligned
a737bd4d 23829
c19d1205
ZW
23830 The type of instruction being processed is encoded in the
23831 instruction field:
a737bd4d 23832
c19d1205
ZW
23833 0x8000 SUB
23834 0x00F0 Rd
23835 0x000F Rs
23836 */
23837 newval = md_chars_to_number (buf, THUMB_SIZE);
23838 {
23839 int rd = (newval >> 4) & 0xf;
23840 int rs = newval & 0xf;
23841 int subtract = !!(newval & 0x8000);
a737bd4d 23842
c19d1205
ZW
23843 /* Check for HI regs, only very restricted cases allowed:
23844 Adjusting SP, and using PC or SP to get an address. */
23845 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23846 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23847 as_bad_where (fixP->fx_file, fixP->fx_line,
23848 _("invalid Hi register with immediate"));
a737bd4d 23849
c19d1205
ZW
23850 /* If value is negative, choose the opposite instruction. */
23851 if (value < 0)
23852 {
23853 value = -value;
23854 subtract = !subtract;
23855 if (value < 0)
23856 as_bad_where (fixP->fx_file, fixP->fx_line,
23857 _("immediate value out of range"));
23858 }
a737bd4d 23859
c19d1205
ZW
23860 if (rd == REG_SP)
23861 {
75c11999 23862 if (value & ~0x1fc)
c19d1205
ZW
23863 as_bad_where (fixP->fx_file, fixP->fx_line,
23864 _("invalid immediate for stack address calculation"));
23865 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23866 newval |= value >> 2;
23867 }
23868 else if (rs == REG_PC || rs == REG_SP)
23869 {
c12d2c9d
NC
23870 /* PR gas/18541. If the addition is for a defined symbol
23871 within range of an ADR instruction then accept it. */
23872 if (subtract
23873 && value == 4
23874 && fixP->fx_addsy != NULL)
23875 {
23876 subtract = 0;
23877
23878 if (! S_IS_DEFINED (fixP->fx_addsy)
23879 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23880 || S_IS_WEAK (fixP->fx_addsy))
23881 {
23882 as_bad_where (fixP->fx_file, fixP->fx_line,
23883 _("address calculation needs a strongly defined nearby symbol"));
23884 }
23885 else
23886 {
23887 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23888
23889 /* Round up to the next 4-byte boundary. */
23890 if (v & 3)
23891 v = (v + 3) & ~ 3;
23892 else
23893 v += 4;
23894 v = S_GET_VALUE (fixP->fx_addsy) - v;
23895
23896 if (v & ~0x3fc)
23897 {
23898 as_bad_where (fixP->fx_file, fixP->fx_line,
23899 _("symbol too far away"));
23900 }
23901 else
23902 {
23903 fixP->fx_done = 1;
23904 value = v;
23905 }
23906 }
23907 }
23908
c19d1205
ZW
23909 if (subtract || value & ~0x3fc)
23910 as_bad_where (fixP->fx_file, fixP->fx_line,
23911 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23912 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23913 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23914 newval |= rd << 8;
23915 newval |= value >> 2;
23916 }
23917 else if (rs == rd)
23918 {
23919 if (value & ~0xff)
23920 as_bad_where (fixP->fx_file, fixP->fx_line,
23921 _("immediate value out of range"));
23922 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23923 newval |= (rd << 8) | value;
23924 }
23925 else
23926 {
23927 if (value & ~0x7)
23928 as_bad_where (fixP->fx_file, fixP->fx_line,
23929 _("immediate value out of range"));
23930 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23931 newval |= rd | (rs << 3) | (value << 6);
23932 }
23933 }
23934 md_number_to_chars (buf, newval, THUMB_SIZE);
23935 break;
a737bd4d 23936
c19d1205
ZW
23937 case BFD_RELOC_ARM_THUMB_IMM:
23938 newval = md_chars_to_number (buf, THUMB_SIZE);
23939 if (value < 0 || value > 255)
23940 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23941 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23942 (long) value);
23943 newval |= value;
23944 md_number_to_chars (buf, newval, THUMB_SIZE);
23945 break;
a737bd4d 23946
c19d1205
ZW
23947 case BFD_RELOC_ARM_THUMB_SHIFT:
23948 /* 5bit shift value (0..32). LSL cannot take 32. */
23949 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23950 temp = newval & 0xf800;
23951 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23952 as_bad_where (fixP->fx_file, fixP->fx_line,
23953 _("invalid shift value: %ld"), (long) value);
23954 /* Shifts of zero must be encoded as LSL. */
23955 if (value == 0)
23956 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23957 /* Shifts of 32 are encoded as zero. */
23958 else if (value == 32)
23959 value = 0;
23960 newval |= value << 6;
23961 md_number_to_chars (buf, newval, THUMB_SIZE);
23962 break;
a737bd4d 23963
c19d1205
ZW
23964 case BFD_RELOC_VTABLE_INHERIT:
23965 case BFD_RELOC_VTABLE_ENTRY:
23966 fixP->fx_done = 0;
23967 return;
6c43fab6 23968
b6895b4f
PB
23969 case BFD_RELOC_ARM_MOVW:
23970 case BFD_RELOC_ARM_MOVT:
23971 case BFD_RELOC_ARM_THUMB_MOVW:
23972 case BFD_RELOC_ARM_THUMB_MOVT:
23973 if (fixP->fx_done || !seg->use_rela_p)
23974 {
23975 /* REL format relocations are limited to a 16-bit addend. */
23976 if (!fixP->fx_done)
23977 {
39623e12 23978 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23979 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23980 _("offset out of range"));
b6895b4f
PB
23981 }
23982 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23983 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23984 {
23985 value >>= 16;
23986 }
23987
23988 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23989 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23990 {
23991 newval = get_thumb32_insn (buf);
23992 newval &= 0xfbf08f00;
23993 newval |= (value & 0xf000) << 4;
23994 newval |= (value & 0x0800) << 15;
23995 newval |= (value & 0x0700) << 4;
23996 newval |= (value & 0x00ff);
23997 put_thumb32_insn (buf, newval);
23998 }
23999 else
24000 {
24001 newval = md_chars_to_number (buf, 4);
24002 newval &= 0xfff0f000;
24003 newval |= value & 0x0fff;
24004 newval |= (value & 0xf000) << 4;
24005 md_number_to_chars (buf, newval, 4);
24006 }
24007 }
24008 return;
24009
72d98d16
MG
24010 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24011 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24012 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24013 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24014 gas_assert (!fixP->fx_done);
24015 {
24016 bfd_vma insn;
24017 bfd_boolean is_mov;
24018 bfd_vma encoded_addend = value;
24019
24020 /* Check that addend can be encoded in instruction. */
24021 if (!seg->use_rela_p && (value < 0 || value > 255))
24022 as_bad_where (fixP->fx_file, fixP->fx_line,
24023 _("the offset 0x%08lX is not representable"),
24024 (unsigned long) encoded_addend);
24025
24026 /* Extract the instruction. */
24027 insn = md_chars_to_number (buf, THUMB_SIZE);
24028 is_mov = (insn & 0xf800) == 0x2000;
24029
24030 /* Encode insn. */
24031 if (is_mov)
24032 {
24033 if (!seg->use_rela_p)
24034 insn |= encoded_addend;
24035 }
24036 else
24037 {
24038 int rd, rs;
24039
24040 /* Extract the instruction. */
24041 /* Encoding is the following
24042 0x8000 SUB
24043 0x00F0 Rd
24044 0x000F Rs
24045 */
24046 /* The following conditions must be true :
24047 - ADD
24048 - Rd == Rs
24049 - Rd <= 7
24050 */
24051 rd = (insn >> 4) & 0xf;
24052 rs = insn & 0xf;
24053 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24054 as_bad_where (fixP->fx_file, fixP->fx_line,
24055 _("Unable to process relocation for thumb opcode: %lx"),
24056 (unsigned long) insn);
24057
24058 /* Encode as ADD immediate8 thumb 1 code. */
24059 insn = 0x3000 | (rd << 8);
24060
24061 /* Place the encoded addend into the first 8 bits of the
24062 instruction. */
24063 if (!seg->use_rela_p)
24064 insn |= encoded_addend;
24065 }
24066
24067 /* Update the instruction. */
24068 md_number_to_chars (buf, insn, THUMB_SIZE);
24069 }
24070 break;
24071
4962c51a
MS
24072 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24073 case BFD_RELOC_ARM_ALU_PC_G0:
24074 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24075 case BFD_RELOC_ARM_ALU_PC_G1:
24076 case BFD_RELOC_ARM_ALU_PC_G2:
24077 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24078 case BFD_RELOC_ARM_ALU_SB_G0:
24079 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24080 case BFD_RELOC_ARM_ALU_SB_G1:
24081 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24082 gas_assert (!fixP->fx_done);
4962c51a
MS
24083 if (!seg->use_rela_p)
24084 {
477330fc
RM
24085 bfd_vma insn;
24086 bfd_vma encoded_addend;
24087 bfd_vma addend_abs = abs (value);
24088
24089 /* Check that the absolute value of the addend can be
24090 expressed as an 8-bit constant plus a rotation. */
24091 encoded_addend = encode_arm_immediate (addend_abs);
24092 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24093 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24094 _("the offset 0x%08lX is not representable"),
24095 (unsigned long) addend_abs);
24096
24097 /* Extract the instruction. */
24098 insn = md_chars_to_number (buf, INSN_SIZE);
24099
24100 /* If the addend is positive, use an ADD instruction.
24101 Otherwise use a SUB. Take care not to destroy the S bit. */
24102 insn &= 0xff1fffff;
24103 if (value < 0)
24104 insn |= 1 << 22;
24105 else
24106 insn |= 1 << 23;
24107
24108 /* Place the encoded addend into the first 12 bits of the
24109 instruction. */
24110 insn &= 0xfffff000;
24111 insn |= encoded_addend;
24112
24113 /* Update the instruction. */
24114 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24115 }
24116 break;
24117
24118 case BFD_RELOC_ARM_LDR_PC_G0:
24119 case BFD_RELOC_ARM_LDR_PC_G1:
24120 case BFD_RELOC_ARM_LDR_PC_G2:
24121 case BFD_RELOC_ARM_LDR_SB_G0:
24122 case BFD_RELOC_ARM_LDR_SB_G1:
24123 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24124 gas_assert (!fixP->fx_done);
4962c51a 24125 if (!seg->use_rela_p)
477330fc
RM
24126 {
24127 bfd_vma insn;
24128 bfd_vma addend_abs = abs (value);
4962c51a 24129
477330fc
RM
24130 /* Check that the absolute value of the addend can be
24131 encoded in 12 bits. */
24132 if (addend_abs >= 0x1000)
4962c51a 24133 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24134 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24135 (unsigned long) addend_abs);
24136
24137 /* Extract the instruction. */
24138 insn = md_chars_to_number (buf, INSN_SIZE);
24139
24140 /* If the addend is negative, clear bit 23 of the instruction.
24141 Otherwise set it. */
24142 if (value < 0)
24143 insn &= ~(1 << 23);
24144 else
24145 insn |= 1 << 23;
24146
24147 /* Place the absolute value of the addend into the first 12 bits
24148 of the instruction. */
24149 insn &= 0xfffff000;
24150 insn |= addend_abs;
24151
24152 /* Update the instruction. */
24153 md_number_to_chars (buf, insn, INSN_SIZE);
24154 }
4962c51a
MS
24155 break;
24156
24157 case BFD_RELOC_ARM_LDRS_PC_G0:
24158 case BFD_RELOC_ARM_LDRS_PC_G1:
24159 case BFD_RELOC_ARM_LDRS_PC_G2:
24160 case BFD_RELOC_ARM_LDRS_SB_G0:
24161 case BFD_RELOC_ARM_LDRS_SB_G1:
24162 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24163 gas_assert (!fixP->fx_done);
4962c51a 24164 if (!seg->use_rela_p)
477330fc
RM
24165 {
24166 bfd_vma insn;
24167 bfd_vma addend_abs = abs (value);
4962c51a 24168
477330fc
RM
24169 /* Check that the absolute value of the addend can be
24170 encoded in 8 bits. */
24171 if (addend_abs >= 0x100)
4962c51a 24172 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24173 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24174 (unsigned long) addend_abs);
24175
24176 /* Extract the instruction. */
24177 insn = md_chars_to_number (buf, INSN_SIZE);
24178
24179 /* If the addend is negative, clear bit 23 of the instruction.
24180 Otherwise set it. */
24181 if (value < 0)
24182 insn &= ~(1 << 23);
24183 else
24184 insn |= 1 << 23;
24185
24186 /* Place the first four bits of the absolute value of the addend
24187 into the first 4 bits of the instruction, and the remaining
24188 four into bits 8 .. 11. */
24189 insn &= 0xfffff0f0;
24190 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24191
24192 /* Update the instruction. */
24193 md_number_to_chars (buf, insn, INSN_SIZE);
24194 }
4962c51a
MS
24195 break;
24196
24197 case BFD_RELOC_ARM_LDC_PC_G0:
24198 case BFD_RELOC_ARM_LDC_PC_G1:
24199 case BFD_RELOC_ARM_LDC_PC_G2:
24200 case BFD_RELOC_ARM_LDC_SB_G0:
24201 case BFD_RELOC_ARM_LDC_SB_G1:
24202 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24203 gas_assert (!fixP->fx_done);
4962c51a 24204 if (!seg->use_rela_p)
477330fc
RM
24205 {
24206 bfd_vma insn;
24207 bfd_vma addend_abs = abs (value);
4962c51a 24208
477330fc
RM
24209 /* Check that the absolute value of the addend is a multiple of
24210 four and, when divided by four, fits in 8 bits. */
24211 if (addend_abs & 0x3)
4962c51a 24212 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24213 _("bad offset 0x%08lX (must be word-aligned)"),
24214 (unsigned long) addend_abs);
4962c51a 24215
477330fc 24216 if ((addend_abs >> 2) > 0xff)
4962c51a 24217 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24218 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24219 (unsigned long) addend_abs);
24220
24221 /* Extract the instruction. */
24222 insn = md_chars_to_number (buf, INSN_SIZE);
24223
24224 /* If the addend is negative, clear bit 23 of the instruction.
24225 Otherwise set it. */
24226 if (value < 0)
24227 insn &= ~(1 << 23);
24228 else
24229 insn |= 1 << 23;
24230
24231 /* Place the addend (divided by four) into the first eight
24232 bits of the instruction. */
24233 insn &= 0xfffffff0;
24234 insn |= addend_abs >> 2;
24235
24236 /* Update the instruction. */
24237 md_number_to_chars (buf, insn, INSN_SIZE);
24238 }
4962c51a
MS
24239 break;
24240
845b51d6
PB
24241 case BFD_RELOC_ARM_V4BX:
24242 /* This will need to go in the object file. */
24243 fixP->fx_done = 0;
24244 break;
24245
c19d1205
ZW
24246 case BFD_RELOC_UNUSED:
24247 default:
24248 as_bad_where (fixP->fx_file, fixP->fx_line,
24249 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24250 }
6c43fab6
RE
24251}
24252
c19d1205
ZW
24253/* Translate internal representation of relocation info to BFD target
24254 format. */
a737bd4d 24255
c19d1205 24256arelent *
00a97672 24257tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24258{
c19d1205
ZW
24259 arelent * reloc;
24260 bfd_reloc_code_real_type code;
a737bd4d 24261
325801bd 24262 reloc = XNEW (arelent);
a737bd4d 24263
325801bd 24264 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24265 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24266 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24267
2fc8bdac 24268 if (fixp->fx_pcrel)
00a97672
RS
24269 {
24270 if (section->use_rela_p)
24271 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24272 else
24273 fixp->fx_offset = reloc->address;
24274 }
c19d1205 24275 reloc->addend = fixp->fx_offset;
a737bd4d 24276
c19d1205 24277 switch (fixp->fx_r_type)
a737bd4d 24278 {
c19d1205
ZW
24279 case BFD_RELOC_8:
24280 if (fixp->fx_pcrel)
24281 {
24282 code = BFD_RELOC_8_PCREL;
24283 break;
24284 }
1a0670f3 24285 /* Fall through. */
a737bd4d 24286
c19d1205
ZW
24287 case BFD_RELOC_16:
24288 if (fixp->fx_pcrel)
24289 {
24290 code = BFD_RELOC_16_PCREL;
24291 break;
24292 }
1a0670f3 24293 /* Fall through. */
6c43fab6 24294
c19d1205
ZW
24295 case BFD_RELOC_32:
24296 if (fixp->fx_pcrel)
24297 {
24298 code = BFD_RELOC_32_PCREL;
24299 break;
24300 }
1a0670f3 24301 /* Fall through. */
a737bd4d 24302
b6895b4f
PB
24303 case BFD_RELOC_ARM_MOVW:
24304 if (fixp->fx_pcrel)
24305 {
24306 code = BFD_RELOC_ARM_MOVW_PCREL;
24307 break;
24308 }
1a0670f3 24309 /* Fall through. */
b6895b4f
PB
24310
24311 case BFD_RELOC_ARM_MOVT:
24312 if (fixp->fx_pcrel)
24313 {
24314 code = BFD_RELOC_ARM_MOVT_PCREL;
24315 break;
24316 }
1a0670f3 24317 /* Fall through. */
b6895b4f
PB
24318
24319 case BFD_RELOC_ARM_THUMB_MOVW:
24320 if (fixp->fx_pcrel)
24321 {
24322 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24323 break;
24324 }
1a0670f3 24325 /* Fall through. */
b6895b4f
PB
24326
24327 case BFD_RELOC_ARM_THUMB_MOVT:
24328 if (fixp->fx_pcrel)
24329 {
24330 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24331 break;
24332 }
1a0670f3 24333 /* Fall through. */
b6895b4f 24334
c19d1205
ZW
24335 case BFD_RELOC_NONE:
24336 case BFD_RELOC_ARM_PCREL_BRANCH:
24337 case BFD_RELOC_ARM_PCREL_BLX:
24338 case BFD_RELOC_RVA:
24339 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24340 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24341 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24342 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24343 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24344 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24345 case BFD_RELOC_VTABLE_ENTRY:
24346 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24347#ifdef TE_PE
24348 case BFD_RELOC_32_SECREL:
24349#endif
c19d1205
ZW
24350 code = fixp->fx_r_type;
24351 break;
a737bd4d 24352
00adf2d4
JB
24353 case BFD_RELOC_THUMB_PCREL_BLX:
24354#ifdef OBJ_ELF
24355 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24356 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24357 else
24358#endif
24359 code = BFD_RELOC_THUMB_PCREL_BLX;
24360 break;
24361
c19d1205
ZW
24362 case BFD_RELOC_ARM_LITERAL:
24363 case BFD_RELOC_ARM_HWLITERAL:
24364 /* If this is called then the a literal has
24365 been referenced across a section boundary. */
24366 as_bad_where (fixp->fx_file, fixp->fx_line,
24367 _("literal referenced across section boundary"));
24368 return NULL;
a737bd4d 24369
c19d1205 24370#ifdef OBJ_ELF
0855e32b
NS
24371 case BFD_RELOC_ARM_TLS_CALL:
24372 case BFD_RELOC_ARM_THM_TLS_CALL:
24373 case BFD_RELOC_ARM_TLS_DESCSEQ:
24374 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24375 case BFD_RELOC_ARM_GOT32:
24376 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24377 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24378 case BFD_RELOC_ARM_PLT32:
24379 case BFD_RELOC_ARM_TARGET1:
24380 case BFD_RELOC_ARM_ROSEGREL32:
24381 case BFD_RELOC_ARM_SBREL32:
24382 case BFD_RELOC_ARM_PREL31:
24383 case BFD_RELOC_ARM_TARGET2:
c19d1205 24384 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24385 case BFD_RELOC_ARM_PCREL_CALL:
24386 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24387 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24388 case BFD_RELOC_ARM_ALU_PC_G0:
24389 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24390 case BFD_RELOC_ARM_ALU_PC_G1:
24391 case BFD_RELOC_ARM_ALU_PC_G2:
24392 case BFD_RELOC_ARM_LDR_PC_G0:
24393 case BFD_RELOC_ARM_LDR_PC_G1:
24394 case BFD_RELOC_ARM_LDR_PC_G2:
24395 case BFD_RELOC_ARM_LDRS_PC_G0:
24396 case BFD_RELOC_ARM_LDRS_PC_G1:
24397 case BFD_RELOC_ARM_LDRS_PC_G2:
24398 case BFD_RELOC_ARM_LDC_PC_G0:
24399 case BFD_RELOC_ARM_LDC_PC_G1:
24400 case BFD_RELOC_ARM_LDC_PC_G2:
24401 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24402 case BFD_RELOC_ARM_ALU_SB_G0:
24403 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24404 case BFD_RELOC_ARM_ALU_SB_G1:
24405 case BFD_RELOC_ARM_ALU_SB_G2:
24406 case BFD_RELOC_ARM_LDR_SB_G0:
24407 case BFD_RELOC_ARM_LDR_SB_G1:
24408 case BFD_RELOC_ARM_LDR_SB_G2:
24409 case BFD_RELOC_ARM_LDRS_SB_G0:
24410 case BFD_RELOC_ARM_LDRS_SB_G1:
24411 case BFD_RELOC_ARM_LDRS_SB_G2:
24412 case BFD_RELOC_ARM_LDC_SB_G0:
24413 case BFD_RELOC_ARM_LDC_SB_G1:
24414 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24415 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24416 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24417 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24418 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24419 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24420 code = fixp->fx_r_type;
24421 break;
a737bd4d 24422
0855e32b 24423 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24424 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24425 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24426 case BFD_RELOC_ARM_TLS_IE32:
24427 case BFD_RELOC_ARM_TLS_LDM32:
24428 /* BFD will include the symbol's address in the addend.
24429 But we don't want that, so subtract it out again here. */
24430 if (!S_IS_COMMON (fixp->fx_addsy))
24431 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24432 code = fixp->fx_r_type;
24433 break;
24434#endif
a737bd4d 24435
c19d1205
ZW
24436 case BFD_RELOC_ARM_IMMEDIATE:
24437 as_bad_where (fixp->fx_file, fixp->fx_line,
24438 _("internal relocation (type: IMMEDIATE) not fixed up"));
24439 return NULL;
a737bd4d 24440
c19d1205
ZW
24441 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24442 as_bad_where (fixp->fx_file, fixp->fx_line,
24443 _("ADRL used for a symbol not defined in the same file"));
24444 return NULL;
a737bd4d 24445
c19d1205 24446 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24447 if (section->use_rela_p)
24448 {
24449 code = fixp->fx_r_type;
24450 break;
24451 }
24452
c19d1205
ZW
24453 if (fixp->fx_addsy != NULL
24454 && !S_IS_DEFINED (fixp->fx_addsy)
24455 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24456 {
c19d1205
ZW
24457 as_bad_where (fixp->fx_file, fixp->fx_line,
24458 _("undefined local label `%s'"),
24459 S_GET_NAME (fixp->fx_addsy));
24460 return NULL;
a737bd4d
NC
24461 }
24462
c19d1205
ZW
24463 as_bad_where (fixp->fx_file, fixp->fx_line,
24464 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24465 return NULL;
a737bd4d 24466
c19d1205
ZW
24467 default:
24468 {
e0471c16 24469 const char * type;
6c43fab6 24470
c19d1205
ZW
24471 switch (fixp->fx_r_type)
24472 {
24473 case BFD_RELOC_NONE: type = "NONE"; break;
24474 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24475 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24476 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24477 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24478 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24479 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24480 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24481 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24482 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24483 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24484 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24485 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24486 default: type = _("<unknown>"); break;
24487 }
24488 as_bad_where (fixp->fx_file, fixp->fx_line,
24489 _("cannot represent %s relocation in this object file format"),
24490 type);
24491 return NULL;
24492 }
a737bd4d 24493 }
6c43fab6 24494
c19d1205
ZW
24495#ifdef OBJ_ELF
24496 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24497 && GOT_symbol
24498 && fixp->fx_addsy == GOT_symbol)
24499 {
24500 code = BFD_RELOC_ARM_GOTPC;
24501 reloc->addend = fixp->fx_offset = reloc->address;
24502 }
24503#endif
6c43fab6 24504
c19d1205 24505 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24506
c19d1205
ZW
24507 if (reloc->howto == NULL)
24508 {
24509 as_bad_where (fixp->fx_file, fixp->fx_line,
24510 _("cannot represent %s relocation in this object file format"),
24511 bfd_get_reloc_code_name (code));
24512 return NULL;
24513 }
6c43fab6 24514
c19d1205
ZW
24515 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24516 vtable entry to be used in the relocation's section offset. */
24517 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24518 reloc->address = fixp->fx_offset;
6c43fab6 24519
c19d1205 24520 return reloc;
6c43fab6
RE
24521}
24522
c19d1205 24523/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24524
c19d1205
ZW
24525void
24526cons_fix_new_arm (fragS * frag,
24527 int where,
24528 int size,
62ebcb5c
AM
24529 expressionS * exp,
24530 bfd_reloc_code_real_type reloc)
6c43fab6 24531{
c19d1205 24532 int pcrel = 0;
6c43fab6 24533
c19d1205
ZW
24534 /* Pick a reloc.
24535 FIXME: @@ Should look at CPU word size. */
24536 switch (size)
24537 {
24538 case 1:
62ebcb5c 24539 reloc = BFD_RELOC_8;
c19d1205
ZW
24540 break;
24541 case 2:
62ebcb5c 24542 reloc = BFD_RELOC_16;
c19d1205
ZW
24543 break;
24544 case 4:
24545 default:
62ebcb5c 24546 reloc = BFD_RELOC_32;
c19d1205
ZW
24547 break;
24548 case 8:
62ebcb5c 24549 reloc = BFD_RELOC_64;
c19d1205
ZW
24550 break;
24551 }
6c43fab6 24552
f0927246
NC
24553#ifdef TE_PE
24554 if (exp->X_op == O_secrel)
24555 {
24556 exp->X_op = O_symbol;
62ebcb5c 24557 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24558 }
24559#endif
24560
62ebcb5c 24561 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24562}
6c43fab6 24563
4343666d 24564#if defined (OBJ_COFF)
c19d1205
ZW
24565void
24566arm_validate_fix (fixS * fixP)
6c43fab6 24567{
c19d1205
ZW
24568 /* If the destination of the branch is a defined symbol which does not have
24569 the THUMB_FUNC attribute, then we must be calling a function which has
24570 the (interfacearm) attribute. We look for the Thumb entry point to that
24571 function and change the branch to refer to that function instead. */
24572 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24573 && fixP->fx_addsy != NULL
24574 && S_IS_DEFINED (fixP->fx_addsy)
24575 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24576 {
c19d1205 24577 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24578 }
c19d1205
ZW
24579}
24580#endif
6c43fab6 24581
267bf995 24582
c19d1205
ZW
24583int
24584arm_force_relocation (struct fix * fixp)
24585{
24586#if defined (OBJ_COFF) && defined (TE_PE)
24587 if (fixp->fx_r_type == BFD_RELOC_RVA)
24588 return 1;
24589#endif
6c43fab6 24590
267bf995
RR
24591 /* In case we have a call or a branch to a function in ARM ISA mode from
24592 a thumb function or vice-versa force the relocation. These relocations
24593 are cleared off for some cores that might have blx and simple transformations
24594 are possible. */
24595
24596#ifdef OBJ_ELF
24597 switch (fixp->fx_r_type)
24598 {
24599 case BFD_RELOC_ARM_PCREL_JUMP:
24600 case BFD_RELOC_ARM_PCREL_CALL:
24601 case BFD_RELOC_THUMB_PCREL_BLX:
24602 if (THUMB_IS_FUNC (fixp->fx_addsy))
24603 return 1;
24604 break;
24605
24606 case BFD_RELOC_ARM_PCREL_BLX:
24607 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24608 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24609 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24610 if (ARM_IS_FUNC (fixp->fx_addsy))
24611 return 1;
24612 break;
24613
24614 default:
24615 break;
24616 }
24617#endif
24618
b5884301
PB
24619 /* Resolve these relocations even if the symbol is extern or weak.
24620 Technically this is probably wrong due to symbol preemption.
24621 In practice these relocations do not have enough range to be useful
24622 at dynamic link time, and some code (e.g. in the Linux kernel)
24623 expects these references to be resolved. */
c19d1205
ZW
24624 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24625 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24626 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24627 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24628 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24629 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24630 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24631 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24632 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24633 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24634 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24635 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24636 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24637 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24638 return 0;
a737bd4d 24639
4962c51a
MS
24640 /* Always leave these relocations for the linker. */
24641 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24642 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24643 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24644 return 1;
24645
f0291e4c
PB
24646 /* Always generate relocations against function symbols. */
24647 if (fixp->fx_r_type == BFD_RELOC_32
24648 && fixp->fx_addsy
24649 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24650 return 1;
24651
c19d1205 24652 return generic_force_reloc (fixp);
404ff6b5
AH
24653}
24654
0ffdc86c 24655#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24656/* Relocations against function names must be left unadjusted,
24657 so that the linker can use this information to generate interworking
24658 stubs. The MIPS version of this function
c19d1205
ZW
24659 also prevents relocations that are mips-16 specific, but I do not
24660 know why it does this.
404ff6b5 24661
c19d1205
ZW
24662 FIXME:
24663 There is one other problem that ought to be addressed here, but
24664 which currently is not: Taking the address of a label (rather
24665 than a function) and then later jumping to that address. Such
24666 addresses also ought to have their bottom bit set (assuming that
24667 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24668
c19d1205
ZW
24669bfd_boolean
24670arm_fix_adjustable (fixS * fixP)
404ff6b5 24671{
c19d1205
ZW
24672 if (fixP->fx_addsy == NULL)
24673 return 1;
404ff6b5 24674
e28387c3
PB
24675 /* Preserve relocations against symbols with function type. */
24676 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24677 return FALSE;
e28387c3 24678
c19d1205
ZW
24679 if (THUMB_IS_FUNC (fixP->fx_addsy)
24680 && fixP->fx_subsy == NULL)
c921be7d 24681 return FALSE;
a737bd4d 24682
c19d1205
ZW
24683 /* We need the symbol name for the VTABLE entries. */
24684 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24685 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24686 return FALSE;
404ff6b5 24687
c19d1205
ZW
24688 /* Don't allow symbols to be discarded on GOT related relocs. */
24689 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24690 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24691 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24692 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24693 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24694 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24695 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24696 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24697 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24698 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24699 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24700 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24701 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24702 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24703 return FALSE;
a737bd4d 24704
4962c51a
MS
24705 /* Similarly for group relocations. */
24706 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24707 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24708 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24709 return FALSE;
4962c51a 24710
79947c54
CD
24711 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24712 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24713 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24714 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24715 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24716 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24717 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24718 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24719 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24720 return FALSE;
79947c54 24721
72d98d16
MG
24722 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24723 offsets, so keep these symbols. */
24724 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24725 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24726 return FALSE;
24727
c921be7d 24728 return TRUE;
a737bd4d 24729}
0ffdc86c
NC
24730#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24731
24732#ifdef OBJ_ELF
c19d1205
ZW
24733const char *
24734elf32_arm_target_format (void)
404ff6b5 24735{
c19d1205
ZW
24736#ifdef TE_SYMBIAN
24737 return (target_big_endian
24738 ? "elf32-bigarm-symbian"
24739 : "elf32-littlearm-symbian");
24740#elif defined (TE_VXWORKS)
24741 return (target_big_endian
24742 ? "elf32-bigarm-vxworks"
24743 : "elf32-littlearm-vxworks");
b38cadfb
NC
24744#elif defined (TE_NACL)
24745 return (target_big_endian
24746 ? "elf32-bigarm-nacl"
24747 : "elf32-littlearm-nacl");
c19d1205
ZW
24748#else
24749 if (target_big_endian)
24750 return "elf32-bigarm";
24751 else
24752 return "elf32-littlearm";
24753#endif
404ff6b5
AH
24754}
24755
c19d1205
ZW
24756void
24757armelf_frob_symbol (symbolS * symp,
24758 int * puntp)
404ff6b5 24759{
c19d1205
ZW
24760 elf_frob_symbol (symp, puntp);
24761}
24762#endif
404ff6b5 24763
c19d1205 24764/* MD interface: Finalization. */
a737bd4d 24765
c19d1205
ZW
24766void
24767arm_cleanup (void)
24768{
24769 literal_pool * pool;
a737bd4d 24770
e07e6e58
NC
24771 /* Ensure that all the IT blocks are properly closed. */
24772 check_it_blocks_finished ();
24773
c19d1205
ZW
24774 for (pool = list_of_pools; pool; pool = pool->next)
24775 {
5f4273c7 24776 /* Put it at the end of the relevant section. */
c19d1205
ZW
24777 subseg_set (pool->section, pool->sub_section);
24778#ifdef OBJ_ELF
24779 arm_elf_change_section ();
24780#endif
24781 s_ltorg (0);
24782 }
404ff6b5
AH
24783}
24784
cd000bff
DJ
24785#ifdef OBJ_ELF
24786/* Remove any excess mapping symbols generated for alignment frags in
24787 SEC. We may have created a mapping symbol before a zero byte
24788 alignment; remove it if there's a mapping symbol after the
24789 alignment. */
24790static void
24791check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24792 void *dummy ATTRIBUTE_UNUSED)
24793{
24794 segment_info_type *seginfo = seg_info (sec);
24795 fragS *fragp;
24796
24797 if (seginfo == NULL || seginfo->frchainP == NULL)
24798 return;
24799
24800 for (fragp = seginfo->frchainP->frch_root;
24801 fragp != NULL;
24802 fragp = fragp->fr_next)
24803 {
24804 symbolS *sym = fragp->tc_frag_data.last_map;
24805 fragS *next = fragp->fr_next;
24806
24807 /* Variable-sized frags have been converted to fixed size by
24808 this point. But if this was variable-sized to start with,
24809 there will be a fixed-size frag after it. So don't handle
24810 next == NULL. */
24811 if (sym == NULL || next == NULL)
24812 continue;
24813
24814 if (S_GET_VALUE (sym) < next->fr_address)
24815 /* Not at the end of this frag. */
24816 continue;
24817 know (S_GET_VALUE (sym) == next->fr_address);
24818
24819 do
24820 {
24821 if (next->tc_frag_data.first_map != NULL)
24822 {
24823 /* Next frag starts with a mapping symbol. Discard this
24824 one. */
24825 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24826 break;
24827 }
24828
24829 if (next->fr_next == NULL)
24830 {
24831 /* This mapping symbol is at the end of the section. Discard
24832 it. */
24833 know (next->fr_fix == 0 && next->fr_var == 0);
24834 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24835 break;
24836 }
24837
24838 /* As long as we have empty frags without any mapping symbols,
24839 keep looking. */
24840 /* If the next frag is non-empty and does not start with a
24841 mapping symbol, then this mapping symbol is required. */
24842 if (next->fr_address != next->fr_next->fr_address)
24843 break;
24844
24845 next = next->fr_next;
24846 }
24847 while (next != NULL);
24848 }
24849}
24850#endif
24851
c19d1205
ZW
24852/* Adjust the symbol table. This marks Thumb symbols as distinct from
24853 ARM ones. */
404ff6b5 24854
c19d1205
ZW
24855void
24856arm_adjust_symtab (void)
404ff6b5 24857{
c19d1205
ZW
24858#ifdef OBJ_COFF
24859 symbolS * sym;
404ff6b5 24860
c19d1205
ZW
24861 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24862 {
24863 if (ARM_IS_THUMB (sym))
24864 {
24865 if (THUMB_IS_FUNC (sym))
24866 {
24867 /* Mark the symbol as a Thumb function. */
24868 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24869 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24870 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24871
c19d1205
ZW
24872 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24873 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24874 else
24875 as_bad (_("%s: unexpected function type: %d"),
24876 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24877 }
24878 else switch (S_GET_STORAGE_CLASS (sym))
24879 {
24880 case C_EXT:
24881 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24882 break;
24883 case C_STAT:
24884 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24885 break;
24886 case C_LABEL:
24887 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24888 break;
24889 default:
24890 /* Do nothing. */
24891 break;
24892 }
24893 }
a737bd4d 24894
c19d1205
ZW
24895 if (ARM_IS_INTERWORK (sym))
24896 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24897 }
c19d1205
ZW
24898#endif
24899#ifdef OBJ_ELF
24900 symbolS * sym;
24901 char bind;
404ff6b5 24902
c19d1205 24903 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24904 {
c19d1205
ZW
24905 if (ARM_IS_THUMB (sym))
24906 {
24907 elf_symbol_type * elf_sym;
404ff6b5 24908
c19d1205
ZW
24909 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24910 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24911
b0796911
PB
24912 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24913 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24914 {
24915 /* If it's a .thumb_func, declare it as so,
24916 otherwise tag label as .code 16. */
24917 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24918 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24919 ST_BRANCH_TO_THUMB);
3ba67470 24920 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24921 elf_sym->internal_elf_sym.st_info =
24922 ELF_ST_INFO (bind, STT_ARM_16BIT);
24923 }
24924 }
24925 }
cd000bff
DJ
24926
24927 /* Remove any overlapping mapping symbols generated by alignment frags. */
24928 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24929 /* Now do generic ELF adjustments. */
24930 elf_adjust_symtab ();
c19d1205 24931#endif
404ff6b5
AH
24932}
24933
c19d1205 24934/* MD interface: Initialization. */
404ff6b5 24935
a737bd4d 24936static void
c19d1205 24937set_constant_flonums (void)
a737bd4d 24938{
c19d1205 24939 int i;
404ff6b5 24940
c19d1205
ZW
24941 for (i = 0; i < NUM_FLOAT_VALS; i++)
24942 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24943 abort ();
a737bd4d 24944}
404ff6b5 24945
3e9e4fcf
JB
24946/* Auto-select Thumb mode if it's the only available instruction set for the
24947 given architecture. */
24948
24949static void
24950autoselect_thumb_from_cpu_variant (void)
24951{
24952 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24953 opcode_select (16);
24954}
24955
c19d1205
ZW
24956void
24957md_begin (void)
a737bd4d 24958{
c19d1205
ZW
24959 unsigned mach;
24960 unsigned int i;
404ff6b5 24961
c19d1205
ZW
24962 if ( (arm_ops_hsh = hash_new ()) == NULL
24963 || (arm_cond_hsh = hash_new ()) == NULL
24964 || (arm_shift_hsh = hash_new ()) == NULL
24965 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24966 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24967 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24968 || (arm_reloc_hsh = hash_new ()) == NULL
24969 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24970 as_fatal (_("virtual memory exhausted"));
24971
24972 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24973 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24974 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24975 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24976 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24977 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24978 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24979 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24980 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24981 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24982 (void *) (v7m_psrs + i));
c19d1205 24983 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24984 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24985 for (i = 0;
24986 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24987 i++)
d3ce72d0 24988 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24989 (void *) (barrier_opt_names + i));
c19d1205 24990#ifdef OBJ_ELF
3da1d841
NC
24991 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24992 {
24993 struct reloc_entry * entry = reloc_names + i;
24994
24995 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24996 /* This makes encode_branch() use the EABI versions of this relocation. */
24997 entry->reloc = BFD_RELOC_UNUSED;
24998
24999 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25000 }
c19d1205
ZW
25001#endif
25002
25003 set_constant_flonums ();
404ff6b5 25004
c19d1205
ZW
25005 /* Set the cpu variant based on the command-line options. We prefer
25006 -mcpu= over -march= if both are set (as for GCC); and we prefer
25007 -mfpu= over any other way of setting the floating point unit.
25008 Use of legacy options with new options are faulted. */
e74cfd16 25009 if (legacy_cpu)
404ff6b5 25010 {
e74cfd16 25011 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25012 as_bad (_("use of old and new-style options to set CPU type"));
25013
25014 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25015 }
e74cfd16 25016 else if (!mcpu_cpu_opt)
c19d1205 25017 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 25018
e74cfd16 25019 if (legacy_fpu)
c19d1205 25020 {
e74cfd16 25021 if (mfpu_opt)
c19d1205 25022 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25023
25024 mfpu_opt = legacy_fpu;
25025 }
e74cfd16 25026 else if (!mfpu_opt)
03b1477f 25027 {
45eb4c1b
NS
25028#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25029 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25030 /* Some environments specify a default FPU. If they don't, infer it
25031 from the processor. */
e74cfd16 25032 if (mcpu_fpu_opt)
03b1477f
RE
25033 mfpu_opt = mcpu_fpu_opt;
25034 else
25035 mfpu_opt = march_fpu_opt;
39c2da32 25036#else
e74cfd16 25037 mfpu_opt = &fpu_default;
39c2da32 25038#endif
03b1477f
RE
25039 }
25040
e74cfd16 25041 if (!mfpu_opt)
03b1477f 25042 {
493cb6ef 25043 if (mcpu_cpu_opt != NULL)
e74cfd16 25044 mfpu_opt = &fpu_default;
493cb6ef 25045 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25046 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25047 else
e74cfd16 25048 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25049 }
25050
ee065d83 25051#ifdef CPU_DEFAULT
e74cfd16 25052 if (!mcpu_cpu_opt)
ee065d83 25053 {
e74cfd16
PB
25054 mcpu_cpu_opt = &cpu_default;
25055 selected_cpu = cpu_default;
ee065d83 25056 }
62785b09
TP
25057 else
25058 selected_cpu = *mcpu_cpu_opt;
e74cfd16
PB
25059#else
25060 if (mcpu_cpu_opt)
25061 selected_cpu = *mcpu_cpu_opt;
ee065d83 25062 else
e74cfd16 25063 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25064#endif
03b1477f 25065
e74cfd16 25066 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 25067
3e9e4fcf
JB
25068 autoselect_thumb_from_cpu_variant ();
25069
e74cfd16 25070 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25071
f17c130b 25072#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25073 {
7cc69913
NC
25074 unsigned int flags = 0;
25075
25076#if defined OBJ_ELF
25077 flags = meabi_flags;
d507cf36
PB
25078
25079 switch (meabi_flags)
33a392fb 25080 {
d507cf36 25081 case EF_ARM_EABI_UNKNOWN:
7cc69913 25082#endif
d507cf36
PB
25083 /* Set the flags in the private structure. */
25084 if (uses_apcs_26) flags |= F_APCS26;
25085 if (support_interwork) flags |= F_INTERWORK;
25086 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25087 if (pic_code) flags |= F_PIC;
e74cfd16 25088 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25089 flags |= F_SOFT_FLOAT;
25090
d507cf36
PB
25091 switch (mfloat_abi_opt)
25092 {
25093 case ARM_FLOAT_ABI_SOFT:
25094 case ARM_FLOAT_ABI_SOFTFP:
25095 flags |= F_SOFT_FLOAT;
25096 break;
33a392fb 25097
d507cf36
PB
25098 case ARM_FLOAT_ABI_HARD:
25099 if (flags & F_SOFT_FLOAT)
25100 as_bad (_("hard-float conflicts with specified fpu"));
25101 break;
25102 }
03b1477f 25103
e74cfd16
PB
25104 /* Using pure-endian doubles (even if soft-float). */
25105 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25106 flags |= F_VFP_FLOAT;
f17c130b 25107
fde78edd 25108#if defined OBJ_ELF
e74cfd16 25109 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25110 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25111 break;
25112
8cb51566 25113 case EF_ARM_EABI_VER4:
3a4a14e9 25114 case EF_ARM_EABI_VER5:
c19d1205 25115 /* No additional flags to set. */
d507cf36
PB
25116 break;
25117
25118 default:
25119 abort ();
25120 }
7cc69913 25121#endif
b99bd4ef
NC
25122 bfd_set_private_flags (stdoutput, flags);
25123
25124 /* We have run out flags in the COFF header to encode the
25125 status of ATPCS support, so instead we create a dummy,
c19d1205 25126 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25127 if (atpcs)
25128 {
25129 asection * sec;
25130
25131 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25132
25133 if (sec != NULL)
25134 {
25135 bfd_set_section_flags
25136 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25137 bfd_set_section_size (stdoutput, sec, 0);
25138 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25139 }
25140 }
7cc69913 25141 }
f17c130b 25142#endif
b99bd4ef
NC
25143
25144 /* Record the CPU type as well. */
2d447fca
JM
25145 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25146 mach = bfd_mach_arm_iWMMXt2;
25147 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25148 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25149 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25150 mach = bfd_mach_arm_XScale;
e74cfd16 25151 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25152 mach = bfd_mach_arm_ep9312;
e74cfd16 25153 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25154 mach = bfd_mach_arm_5TE;
e74cfd16 25155 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25156 {
e74cfd16 25157 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25158 mach = bfd_mach_arm_5T;
25159 else
25160 mach = bfd_mach_arm_5;
25161 }
e74cfd16 25162 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25163 {
e74cfd16 25164 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25165 mach = bfd_mach_arm_4T;
25166 else
25167 mach = bfd_mach_arm_4;
25168 }
e74cfd16 25169 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25170 mach = bfd_mach_arm_3M;
e74cfd16
PB
25171 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25172 mach = bfd_mach_arm_3;
25173 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25174 mach = bfd_mach_arm_2a;
25175 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25176 mach = bfd_mach_arm_2;
25177 else
25178 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25179
25180 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25181}
25182
c19d1205 25183/* Command line processing. */
b99bd4ef 25184
c19d1205
ZW
25185/* md_parse_option
25186 Invocation line includes a switch not recognized by the base assembler.
25187 See if it's a processor-specific option.
b99bd4ef 25188
c19d1205
ZW
25189 This routine is somewhat complicated by the need for backwards
25190 compatibility (since older releases of gcc can't be changed).
25191 The new options try to make the interface as compatible as
25192 possible with GCC.
b99bd4ef 25193
c19d1205 25194 New options (supported) are:
b99bd4ef 25195
c19d1205
ZW
25196 -mcpu=<cpu name> Assemble for selected processor
25197 -march=<architecture name> Assemble for selected architecture
25198 -mfpu=<fpu architecture> Assemble for selected FPU.
25199 -EB/-mbig-endian Big-endian
25200 -EL/-mlittle-endian Little-endian
25201 -k Generate PIC code
25202 -mthumb Start in Thumb mode
25203 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25204
278df34e 25205 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25206 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25207
c19d1205 25208 For now we will also provide support for:
b99bd4ef 25209
c19d1205
ZW
25210 -mapcs-32 32-bit Program counter
25211 -mapcs-26 26-bit Program counter
25212 -macps-float Floats passed in FP registers
25213 -mapcs-reentrant Reentrant code
25214 -matpcs
25215 (sometime these will probably be replaced with -mapcs=<list of options>
25216 and -matpcs=<list of options>)
b99bd4ef 25217
c19d1205
ZW
25218 The remaining options are only supported for back-wards compatibility.
25219 Cpu variants, the arm part is optional:
25220 -m[arm]1 Currently not supported.
25221 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25222 -m[arm]3 Arm 3 processor
25223 -m[arm]6[xx], Arm 6 processors
25224 -m[arm]7[xx][t][[d]m] Arm 7 processors
25225 -m[arm]8[10] Arm 8 processors
25226 -m[arm]9[20][tdmi] Arm 9 processors
25227 -mstrongarm[110[0]] StrongARM processors
25228 -mxscale XScale processors
25229 -m[arm]v[2345[t[e]]] Arm architectures
25230 -mall All (except the ARM1)
25231 FP variants:
25232 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25233 -mfpe-old (No float load/store multiples)
25234 -mvfpxd VFP Single precision
25235 -mvfp All VFP
25236 -mno-fpu Disable all floating point instructions
b99bd4ef 25237
c19d1205
ZW
25238 The following CPU names are recognized:
25239 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25240 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25241 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25242 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25243 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25244 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25245 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25246
c19d1205 25247 */
b99bd4ef 25248
c19d1205 25249const char * md_shortopts = "m:k";
b99bd4ef 25250
c19d1205
ZW
25251#ifdef ARM_BI_ENDIAN
25252#define OPTION_EB (OPTION_MD_BASE + 0)
25253#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25254#else
c19d1205
ZW
25255#if TARGET_BYTES_BIG_ENDIAN
25256#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25257#else
c19d1205
ZW
25258#define OPTION_EL (OPTION_MD_BASE + 1)
25259#endif
b99bd4ef 25260#endif
845b51d6 25261#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25262
c19d1205 25263struct option md_longopts[] =
b99bd4ef 25264{
c19d1205
ZW
25265#ifdef OPTION_EB
25266 {"EB", no_argument, NULL, OPTION_EB},
25267#endif
25268#ifdef OPTION_EL
25269 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25270#endif
845b51d6 25271 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25272 {NULL, no_argument, NULL, 0}
25273};
b99bd4ef 25274
8b2d793c 25275
c19d1205 25276size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25277
c19d1205 25278struct arm_option_table
b99bd4ef 25279{
e0471c16
TS
25280 const char *option; /* Option name to match. */
25281 const char *help; /* Help information. */
c19d1205
ZW
25282 int *var; /* Variable to change. */
25283 int value; /* What to change it to. */
e0471c16 25284 const char *deprecated; /* If non-null, print this message. */
c19d1205 25285};
b99bd4ef 25286
c19d1205
ZW
25287struct arm_option_table arm_opts[] =
25288{
25289 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25290 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25291 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25292 &support_interwork, 1, NULL},
25293 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25294 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25295 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25296 1, NULL},
25297 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25298 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25299 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25300 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25301 NULL},
b99bd4ef 25302
c19d1205
ZW
25303 /* These are recognized by the assembler, but have no affect on code. */
25304 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25305 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25306
25307 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25308 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25309 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25310 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25311 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25312 {NULL, NULL, NULL, 0, NULL}
25313};
25314
25315struct arm_legacy_option_table
25316{
e0471c16 25317 const char *option; /* Option name to match. */
e74cfd16
PB
25318 const arm_feature_set **var; /* Variable to change. */
25319 const arm_feature_set value; /* What to change it to. */
e0471c16 25320 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25321};
b99bd4ef 25322
e74cfd16
PB
25323const struct arm_legacy_option_table arm_legacy_opts[] =
25324{
c19d1205
ZW
25325 /* DON'T add any new processors to this list -- we want the whole list
25326 to go away... Add them to the processors table instead. */
e74cfd16
PB
25327 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25328 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25329 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25330 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25331 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25332 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25333 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25334 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25335 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25336 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25337 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25338 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25339 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25340 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25341 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25342 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25343 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25344 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25345 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25346 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25347 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25348 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25349 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25350 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25351 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25352 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25353 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25354 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25355 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25356 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25357 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25358 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25359 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25360 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25361 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25362 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25363 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25364 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25365 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25366 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25367 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25368 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25369 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25370 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25371 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25372 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25373 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25374 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25375 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25376 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25377 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25378 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25379 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25380 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25381 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25382 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25383 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25384 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25385 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25386 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25387 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25388 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25389 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25390 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25391 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25392 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25393 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25394 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25395 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25396 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25397 N_("use -mcpu=strongarm110")},
e74cfd16 25398 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25399 N_("use -mcpu=strongarm1100")},
e74cfd16 25400 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25401 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25402 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25403 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25404 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25405
c19d1205 25406 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25407 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25408 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25409 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25410 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25411 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25412 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25413 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25414 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25415 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25416 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25417 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25418 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25419 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25420 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25421 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25422 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25423 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25424 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25425
c19d1205 25426 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25427 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25428 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25429 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25430 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25431 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25432
e74cfd16 25433 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25434};
7ed4c4c5 25435
c19d1205 25436struct arm_cpu_option_table
7ed4c4c5 25437{
e0471c16 25438 const char *name;
f3bad469 25439 size_t name_len;
e74cfd16 25440 const arm_feature_set value;
c19d1205
ZW
25441 /* For some CPUs we assume an FPU unless the user explicitly sets
25442 -mfpu=... */
e74cfd16 25443 const arm_feature_set default_fpu;
ee065d83
PB
25444 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25445 case. */
25446 const char *canonical_name;
c19d1205 25447};
7ed4c4c5 25448
c19d1205
ZW
25449/* This list should, at a minimum, contain all the cpu names
25450 recognized by GCC. */
f3bad469 25451#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25452static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25453{
f3bad469
MGD
25454 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25455 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25456 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25457 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25458 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25459 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25460 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25461 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25462 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25463 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25464 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25465 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25466 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25467 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25468 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25469 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25470 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25471 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25472 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25473 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25474 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25475 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25476 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25477 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25478 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25479 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25480 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25481 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25482 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25483 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25484 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25485 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25486 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25487 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25488 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25489 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25490 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25491 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25492 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25493 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25494 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25495 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25496 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25497 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25498 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25499 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25500 /* For V5 or later processors we default to using VFP; but the user
25501 should really set the FPU type explicitly. */
f3bad469
MGD
25502 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25503 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25504 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25505 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25506 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25507 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25508 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25509 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25510 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25511 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25512 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25513 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25514 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25515 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25516 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25517 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25518 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25519 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25520 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25521 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25522 "ARM1026EJ-S"),
25523 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25524 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25525 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25526 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25527 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25528 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25529 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25530 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25531 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25532 "ARM1136JF-S"),
25533 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25534 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25535 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25536 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25537 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25538 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25539 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25540 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25541 FPU_NONE, "Cortex-A5"),
c9fb6e58 25542 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25543 "Cortex-A7"),
25544 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25545 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25546 | FPU_NEON_EXT_V1),
f3bad469
MGD
25547 "Cortex-A8"),
25548 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25549 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25550 | FPU_NEON_EXT_V1),
f3bad469 25551 "Cortex-A9"),
c9fb6e58 25552 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25553 "Cortex-A12"),
c9fb6e58 25554 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25555 "Cortex-A15"),
d7adf960
KT
25556 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25557 "Cortex-A17"),
27e5a270 25558 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
6735952f 25559 "Cortex-A32"),
27e5a270 25560 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
43cdc0a8 25561 "Cortex-A35"),
27e5a270 25562 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25563 "Cortex-A53"),
27e5a270 25564 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25565 "Cortex-A57"),
27e5a270 25566 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
b19f47ad 25567 "Cortex-A72"),
27e5a270 25568 ARM_CPU_OPT ("cortex-a73", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
362a3eba 25569 "Cortex-A73"),
f3bad469
MGD
25570 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25571 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25572 "Cortex-R4F"),
25573 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25574 FPU_NONE, "Cortex-R5"),
70a8bc5b 25575 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25576 FPU_ARCH_VFP_V3D16,
25577 "Cortex-R7"),
5f474010
TP
25578 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25579 FPU_ARCH_VFP_V3D16,
25580 "Cortex-R8"),
b19ea8d2
TP
25581 ARM_CPU_OPT ("cortex-m33", ARM_ARCH_V8M_MAIN_DSP,
25582 FPU_NONE, "Cortex-M33"),
ce1b0a45
TP
25583 ARM_CPU_OPT ("cortex-m23", ARM_ARCH_V8M_BASE,
25584 FPU_NONE, "Cortex-M23"),
a715796b 25585 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25586 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25587 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25588 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25589 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25590 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
27e5a270 25591 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
246496bb
EM
25592 "Samsung " \
25593 "Exynos M1"),
6b21c2bf 25594
c19d1205 25595 /* ??? XSCALE is really an architecture. */
f3bad469 25596 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25597 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25598 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25599 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25600 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25601 /* Maverick */
823d2571 25602 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25603 FPU_ARCH_MAVERICK, "ARM920T"),
25604 /* Marvell processors. */
ff8646ee
TP
25605 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25606 | ARM_EXT_SEC,
25607 ARM_EXT2_V6T2_V8M),
477330fc 25608 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25609 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25610 | ARM_EXT_SEC,
25611 ARM_EXT2_V6T2_V8M),
4347085a 25612 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25613 /* APM X-Gene family. */
25614 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25615 "APM X-Gene 1"),
27e5a270 25616 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
ea0d6bb9 25617 "APM X-Gene 2"),
da4339ed 25618
f3bad469 25619 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25620};
f3bad469 25621#undef ARM_CPU_OPT
7ed4c4c5 25622
c19d1205 25623struct arm_arch_option_table
7ed4c4c5 25624{
e0471c16 25625 const char *name;
f3bad469 25626 size_t name_len;
e74cfd16
PB
25627 const arm_feature_set value;
25628 const arm_feature_set default_fpu;
c19d1205 25629};
7ed4c4c5 25630
c19d1205
ZW
25631/* This list should, at a minimum, contain all the architecture names
25632 recognized by GCC. */
f3bad469 25633#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25634static const struct arm_arch_option_table arm_archs[] =
c19d1205 25635{
f3bad469
MGD
25636 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25637 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25638 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25639 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25640 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25641 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25642 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25643 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25644 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25645 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25646 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25647 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25648 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25649 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25650 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25651 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25652 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25653 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25654 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25655 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25656 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25657 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25658 kept to preserve existing behaviour. */
25659 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25660 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25661 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25662 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25663 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25664 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25665 kept to preserve existing behaviour. */
25666 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25667 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25668 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25669 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25670 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25671 /* The official spelling of the ARMv7 profile variants is the dashed form.
25672 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25673 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25674 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25675 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25676 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25677 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25678 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25679 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25680 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25681 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25682 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25683 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25684 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25685 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 25686 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
f3bad469
MGD
25687 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25688 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25689 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25690 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25691};
f3bad469 25692#undef ARM_ARCH_OPT
7ed4c4c5 25693
69133863
MGD
25694/* ISA extensions in the co-processor and main instruction set space. */
25695struct arm_option_extension_value_table
c19d1205 25696{
e0471c16 25697 const char *name;
f3bad469 25698 size_t name_len;
5a70a223
JB
25699 const arm_feature_set merge_value;
25700 const arm_feature_set clear_value;
d942732e
TP
25701 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25702 indicates that an extension is available for all architectures while
25703 ARM_ANY marks an empty entry. */
25704 const arm_feature_set allowed_archs[2];
c19d1205 25705};
7ed4c4c5 25706
69133863
MGD
25707/* The following table must be in alphabetical order with a NULL last entry.
25708 */
d942732e
TP
25709#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25710#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25711static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25712{
823d2571
TG
25713 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25714 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25715 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25716 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25717 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25718 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25719 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25720 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25721 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25722 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25723 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25724 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25725 ARM_ARCH_V8_2A),
d942732e 25726 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25727 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25728 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25729 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25730 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25731 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25732 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25733 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25734 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25735 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25736 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25737 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25738 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25739 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25740 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25741 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25742 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25743 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25744 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25745 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25746 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25747 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25748 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25749 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25750 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25751 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25752 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25753 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25754 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25755 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25756 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25757 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25758 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25759 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25760 | ARM_EXT_DIV),
25761 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25762 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25763 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25764 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25765 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25766};
f3bad469 25767#undef ARM_EXT_OPT
69133863
MGD
25768
25769/* ISA floating-point and Advanced SIMD extensions. */
25770struct arm_option_fpu_value_table
25771{
e0471c16 25772 const char *name;
69133863 25773 const arm_feature_set value;
c19d1205 25774};
7ed4c4c5 25775
c19d1205
ZW
25776/* This list should, at a minimum, contain all the fpu names
25777 recognized by GCC. */
69133863 25778static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25779{
25780 {"softfpa", FPU_NONE},
25781 {"fpe", FPU_ARCH_FPE},
25782 {"fpe2", FPU_ARCH_FPE},
25783 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25784 {"fpa", FPU_ARCH_FPA},
25785 {"fpa10", FPU_ARCH_FPA},
25786 {"fpa11", FPU_ARCH_FPA},
25787 {"arm7500fe", FPU_ARCH_FPA},
25788 {"softvfp", FPU_ARCH_VFP},
25789 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25790 {"vfp", FPU_ARCH_VFP_V2},
25791 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 25792 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
25793 {"vfp10", FPU_ARCH_VFP_V2},
25794 {"vfp10-r0", FPU_ARCH_VFP_V1},
25795 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25796 {"vfpv2", FPU_ARCH_VFP_V2},
25797 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25798 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25799 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25800 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25801 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25802 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25803 {"arm1020t", FPU_ARCH_VFP_V1},
25804 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 25805 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
25806 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25807 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 25808 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 25809 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25810 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25811 {"vfpv4", FPU_ARCH_VFP_V4},
25812 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25813 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25814 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25815 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25816 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25817 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25818 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25819 {"crypto-neon-fp-armv8",
25820 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25821 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25822 {"crypto-neon-fp-armv8.1",
25823 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25824 {NULL, ARM_ARCH_NONE}
25825};
25826
25827struct arm_option_value_table
25828{
e0471c16 25829 const char *name;
e74cfd16 25830 long value;
c19d1205 25831};
7ed4c4c5 25832
e74cfd16 25833static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25834{
25835 {"hard", ARM_FLOAT_ABI_HARD},
25836 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25837 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25838 {NULL, 0}
c19d1205 25839};
7ed4c4c5 25840
c19d1205 25841#ifdef OBJ_ELF
3a4a14e9 25842/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25843static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25844{
25845 {"gnu", EF_ARM_EABI_UNKNOWN},
25846 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25847 {"5", EF_ARM_EABI_VER5},
e74cfd16 25848 {NULL, 0}
c19d1205
ZW
25849};
25850#endif
7ed4c4c5 25851
c19d1205
ZW
25852struct arm_long_option_table
25853{
e0471c16
TS
25854 const char * option; /* Substring to match. */
25855 const char * help; /* Help information. */
17b9d67d 25856 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25857 const char * deprecated; /* If non-null, print this message. */
c19d1205 25858};
7ed4c4c5 25859
c921be7d 25860static bfd_boolean
82b8a785 25861arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25862{
325801bd 25863 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25864
69133863 25865 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25866 extensions being added before being removed. We achieve this by having
25867 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25868 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25869 or removing it (0) and only allowing it to change in the order
69133863
MGD
25870 -1 -> 1 -> 0. */
25871 const struct arm_option_extension_value_table * opt = NULL;
d942732e 25872 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
25873 int adding_value = -1;
25874
e74cfd16
PB
25875 /* Copy the feature set, so that we can modify it. */
25876 *ext_set = **opt_p;
25877 *opt_p = ext_set;
25878
c19d1205 25879 while (str != NULL && *str != 0)
7ed4c4c5 25880 {
82b8a785 25881 const char *ext;
f3bad469 25882 size_t len;
7ed4c4c5 25883
c19d1205
ZW
25884 if (*str != '+')
25885 {
25886 as_bad (_("invalid architectural extension"));
c921be7d 25887 return FALSE;
c19d1205 25888 }
7ed4c4c5 25889
c19d1205
ZW
25890 str++;
25891 ext = strchr (str, '+');
7ed4c4c5 25892
c19d1205 25893 if (ext != NULL)
f3bad469 25894 len = ext - str;
c19d1205 25895 else
f3bad469 25896 len = strlen (str);
7ed4c4c5 25897
f3bad469 25898 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25899 {
25900 if (adding_value != 0)
25901 {
25902 adding_value = 0;
25903 opt = arm_extensions;
25904 }
25905
f3bad469 25906 len -= 2;
69133863
MGD
25907 str += 2;
25908 }
f3bad469 25909 else if (len > 0)
69133863
MGD
25910 {
25911 if (adding_value == -1)
25912 {
25913 adding_value = 1;
25914 opt = arm_extensions;
25915 }
25916 else if (adding_value != 1)
25917 {
25918 as_bad (_("must specify extensions to add before specifying "
25919 "those to remove"));
25920 return FALSE;
25921 }
25922 }
25923
f3bad469 25924 if (len == 0)
c19d1205
ZW
25925 {
25926 as_bad (_("missing architectural extension"));
c921be7d 25927 return FALSE;
c19d1205 25928 }
7ed4c4c5 25929
69133863
MGD
25930 gas_assert (adding_value != -1);
25931 gas_assert (opt != NULL);
25932
25933 /* Scan over the options table trying to find an exact match. */
25934 for (; opt->name != NULL; opt++)
f3bad469 25935 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25936 {
d942732e
TP
25937 int i, nb_allowed_archs =
25938 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 25939 /* Check we can apply the extension to this architecture. */
d942732e
TP
25940 for (i = 0; i < nb_allowed_archs; i++)
25941 {
25942 /* Empty entry. */
25943 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
25944 continue;
25945 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
25946 break;
25947 }
25948 if (i == nb_allowed_archs)
69133863
MGD
25949 {
25950 as_bad (_("extension does not apply to the base architecture"));
25951 return FALSE;
25952 }
25953
25954 /* Add or remove the extension. */
25955 if (adding_value)
5a70a223 25956 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25957 else
5a70a223 25958 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25959
c19d1205
ZW
25960 break;
25961 }
7ed4c4c5 25962
c19d1205
ZW
25963 if (opt->name == NULL)
25964 {
69133863
MGD
25965 /* Did we fail to find an extension because it wasn't specified in
25966 alphabetical order, or because it does not exist? */
25967
25968 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25969 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25970 break;
25971
25972 if (opt->name == NULL)
25973 as_bad (_("unknown architectural extension `%s'"), str);
25974 else
25975 as_bad (_("architectural extensions must be specified in "
25976 "alphabetical order"));
25977
c921be7d 25978 return FALSE;
c19d1205 25979 }
69133863
MGD
25980 else
25981 {
25982 /* We should skip the extension we've just matched the next time
25983 round. */
25984 opt++;
25985 }
7ed4c4c5 25986
c19d1205
ZW
25987 str = ext;
25988 };
7ed4c4c5 25989
c921be7d 25990 return TRUE;
c19d1205 25991}
7ed4c4c5 25992
c921be7d 25993static bfd_boolean
17b9d67d 25994arm_parse_cpu (const char *str)
7ed4c4c5 25995{
f3bad469 25996 const struct arm_cpu_option_table *opt;
82b8a785 25997 const char *ext = strchr (str, '+');
f3bad469 25998 size_t len;
7ed4c4c5 25999
c19d1205 26000 if (ext != NULL)
f3bad469 26001 len = ext - str;
7ed4c4c5 26002 else
f3bad469 26003 len = strlen (str);
7ed4c4c5 26004
f3bad469 26005 if (len == 0)
7ed4c4c5 26006 {
c19d1205 26007 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26008 return FALSE;
7ed4c4c5
NC
26009 }
26010
c19d1205 26011 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26012 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26013 {
e74cfd16
PB
26014 mcpu_cpu_opt = &opt->value;
26015 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26016 if (opt->canonical_name)
ef8e6722
JW
26017 {
26018 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26019 strcpy (selected_cpu_name, opt->canonical_name);
26020 }
ee065d83
PB
26021 else
26022 {
f3bad469 26023 size_t i;
c921be7d 26024
ef8e6722
JW
26025 if (len >= sizeof selected_cpu_name)
26026 len = (sizeof selected_cpu_name) - 1;
26027
f3bad469 26028 for (i = 0; i < len; i++)
ee065d83
PB
26029 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26030 selected_cpu_name[i] = 0;
26031 }
7ed4c4c5 26032
c19d1205
ZW
26033 if (ext != NULL)
26034 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 26035
c921be7d 26036 return TRUE;
c19d1205 26037 }
7ed4c4c5 26038
c19d1205 26039 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26040 return FALSE;
7ed4c4c5
NC
26041}
26042
c921be7d 26043static bfd_boolean
17b9d67d 26044arm_parse_arch (const char *str)
7ed4c4c5 26045{
e74cfd16 26046 const struct arm_arch_option_table *opt;
82b8a785 26047 const char *ext = strchr (str, '+');
f3bad469 26048 size_t len;
7ed4c4c5 26049
c19d1205 26050 if (ext != NULL)
f3bad469 26051 len = ext - str;
7ed4c4c5 26052 else
f3bad469 26053 len = strlen (str);
7ed4c4c5 26054
f3bad469 26055 if (len == 0)
7ed4c4c5 26056 {
c19d1205 26057 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26058 return FALSE;
7ed4c4c5
NC
26059 }
26060
c19d1205 26061 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26062 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26063 {
e74cfd16
PB
26064 march_cpu_opt = &opt->value;
26065 march_fpu_opt = &opt->default_fpu;
5f4273c7 26066 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26067
c19d1205
ZW
26068 if (ext != NULL)
26069 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 26070
c921be7d 26071 return TRUE;
c19d1205
ZW
26072 }
26073
26074 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26075 return FALSE;
7ed4c4c5 26076}
eb043451 26077
c921be7d 26078static bfd_boolean
17b9d67d 26079arm_parse_fpu (const char * str)
c19d1205 26080{
69133863 26081 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26082
c19d1205
ZW
26083 for (opt = arm_fpus; opt->name != NULL; opt++)
26084 if (streq (opt->name, str))
26085 {
e74cfd16 26086 mfpu_opt = &opt->value;
c921be7d 26087 return TRUE;
c19d1205 26088 }
b99bd4ef 26089
c19d1205 26090 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26091 return FALSE;
c19d1205
ZW
26092}
26093
c921be7d 26094static bfd_boolean
17b9d67d 26095arm_parse_float_abi (const char * str)
b99bd4ef 26096{
e74cfd16 26097 const struct arm_option_value_table * opt;
b99bd4ef 26098
c19d1205
ZW
26099 for (opt = arm_float_abis; opt->name != NULL; opt++)
26100 if (streq (opt->name, str))
26101 {
26102 mfloat_abi_opt = opt->value;
c921be7d 26103 return TRUE;
c19d1205 26104 }
cc8a6dd0 26105
c19d1205 26106 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26107 return FALSE;
c19d1205 26108}
b99bd4ef 26109
c19d1205 26110#ifdef OBJ_ELF
c921be7d 26111static bfd_boolean
17b9d67d 26112arm_parse_eabi (const char * str)
c19d1205 26113{
e74cfd16 26114 const struct arm_option_value_table *opt;
cc8a6dd0 26115
c19d1205
ZW
26116 for (opt = arm_eabis; opt->name != NULL; opt++)
26117 if (streq (opt->name, str))
26118 {
26119 meabi_flags = opt->value;
c921be7d 26120 return TRUE;
c19d1205
ZW
26121 }
26122 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26123 return FALSE;
c19d1205
ZW
26124}
26125#endif
cc8a6dd0 26126
c921be7d 26127static bfd_boolean
17b9d67d 26128arm_parse_it_mode (const char * str)
e07e6e58 26129{
c921be7d 26130 bfd_boolean ret = TRUE;
e07e6e58
NC
26131
26132 if (streq ("arm", str))
26133 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26134 else if (streq ("thumb", str))
26135 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26136 else if (streq ("always", str))
26137 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26138 else if (streq ("never", str))
26139 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26140 else
26141 {
26142 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26143 "arm, thumb, always, or never."), str);
c921be7d 26144 ret = FALSE;
e07e6e58
NC
26145 }
26146
26147 return ret;
26148}
26149
2e6976a8 26150static bfd_boolean
17b9d67d 26151arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26152{
26153 codecomposer_syntax = TRUE;
26154 arm_comment_chars[0] = ';';
26155 arm_line_separator_chars[0] = 0;
26156 return TRUE;
26157}
26158
c19d1205
ZW
26159struct arm_long_option_table arm_long_opts[] =
26160{
26161 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26162 arm_parse_cpu, NULL},
26163 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26164 arm_parse_arch, NULL},
26165 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26166 arm_parse_fpu, NULL},
26167 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26168 arm_parse_float_abi, NULL},
26169#ifdef OBJ_ELF
7fac0536 26170 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26171 arm_parse_eabi, NULL},
26172#endif
e07e6e58
NC
26173 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26174 arm_parse_it_mode, NULL},
2e6976a8
DG
26175 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26176 arm_ccs_mode, NULL},
c19d1205
ZW
26177 {NULL, NULL, 0, NULL}
26178};
cc8a6dd0 26179
c19d1205 26180int
17b9d67d 26181md_parse_option (int c, const char * arg)
c19d1205
ZW
26182{
26183 struct arm_option_table *opt;
e74cfd16 26184 const struct arm_legacy_option_table *fopt;
c19d1205 26185 struct arm_long_option_table *lopt;
b99bd4ef 26186
c19d1205 26187 switch (c)
b99bd4ef 26188 {
c19d1205
ZW
26189#ifdef OPTION_EB
26190 case OPTION_EB:
26191 target_big_endian = 1;
26192 break;
26193#endif
cc8a6dd0 26194
c19d1205
ZW
26195#ifdef OPTION_EL
26196 case OPTION_EL:
26197 target_big_endian = 0;
26198 break;
26199#endif
b99bd4ef 26200
845b51d6
PB
26201 case OPTION_FIX_V4BX:
26202 fix_v4bx = TRUE;
26203 break;
26204
c19d1205
ZW
26205 case 'a':
26206 /* Listing option. Just ignore these, we don't support additional
26207 ones. */
26208 return 0;
b99bd4ef 26209
c19d1205
ZW
26210 default:
26211 for (opt = arm_opts; opt->option != NULL; opt++)
26212 {
26213 if (c == opt->option[0]
26214 && ((arg == NULL && opt->option[1] == 0)
26215 || streq (arg, opt->option + 1)))
26216 {
c19d1205 26217 /* If the option is deprecated, tell the user. */
278df34e 26218 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26219 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26220 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26221
c19d1205
ZW
26222 if (opt->var != NULL)
26223 *opt->var = opt->value;
cc8a6dd0 26224
c19d1205
ZW
26225 return 1;
26226 }
26227 }
b99bd4ef 26228
e74cfd16
PB
26229 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26230 {
26231 if (c == fopt->option[0]
26232 && ((arg == NULL && fopt->option[1] == 0)
26233 || streq (arg, fopt->option + 1)))
26234 {
e74cfd16 26235 /* If the option is deprecated, tell the user. */
278df34e 26236 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26237 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26238 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26239
26240 if (fopt->var != NULL)
26241 *fopt->var = &fopt->value;
26242
26243 return 1;
26244 }
26245 }
26246
c19d1205
ZW
26247 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26248 {
26249 /* These options are expected to have an argument. */
26250 if (c == lopt->option[0]
26251 && arg != NULL
26252 && strncmp (arg, lopt->option + 1,
26253 strlen (lopt->option + 1)) == 0)
26254 {
c19d1205 26255 /* If the option is deprecated, tell the user. */
278df34e 26256 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26257 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26258 _(lopt->deprecated));
b99bd4ef 26259
c19d1205
ZW
26260 /* Call the sup-option parser. */
26261 return lopt->func (arg + strlen (lopt->option) - 1);
26262 }
26263 }
a737bd4d 26264
c19d1205
ZW
26265 return 0;
26266 }
a394c00f 26267
c19d1205
ZW
26268 return 1;
26269}
a394c00f 26270
c19d1205
ZW
26271void
26272md_show_usage (FILE * fp)
a394c00f 26273{
c19d1205
ZW
26274 struct arm_option_table *opt;
26275 struct arm_long_option_table *lopt;
a394c00f 26276
c19d1205 26277 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26278
c19d1205
ZW
26279 for (opt = arm_opts; opt->option != NULL; opt++)
26280 if (opt->help != NULL)
26281 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26282
c19d1205
ZW
26283 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26284 if (lopt->help != NULL)
26285 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26286
c19d1205
ZW
26287#ifdef OPTION_EB
26288 fprintf (fp, _("\
26289 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26290#endif
26291
c19d1205
ZW
26292#ifdef OPTION_EL
26293 fprintf (fp, _("\
26294 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26295#endif
845b51d6
PB
26296
26297 fprintf (fp, _("\
26298 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26299}
ee065d83
PB
26300
26301
26302#ifdef OBJ_ELF
62b3e311
PB
26303typedef struct
26304{
26305 int val;
26306 arm_feature_set flags;
26307} cpu_arch_ver_table;
26308
4ed7ed8d
TP
26309/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26310 must be sorted least features first but some reordering is needed, eg. for
26311 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26312static const cpu_arch_ver_table cpu_arch_ver[] =
26313{
26314 {1, ARM_ARCH_V4},
26315 {2, ARM_ARCH_V4T},
26316 {3, ARM_ARCH_V5},
ee3c0378 26317 {3, ARM_ARCH_V5T},
62b3e311
PB
26318 {4, ARM_ARCH_V5TE},
26319 {5, ARM_ARCH_V5TEJ},
26320 {6, ARM_ARCH_V6},
7e806470 26321 {9, ARM_ARCH_V6K},
f4c65163 26322 {7, ARM_ARCH_V6Z},
91e22acd 26323 {11, ARM_ARCH_V6M},
b2a5fbdc 26324 {12, ARM_ARCH_V6SM},
7e806470 26325 {8, ARM_ARCH_V6T2},
c9fb6e58 26326 {10, ARM_ARCH_V7VE},
62b3e311
PB
26327 {10, ARM_ARCH_V7R},
26328 {10, ARM_ARCH_V7M},
bca38921 26329 {14, ARM_ARCH_V8A},
ff8646ee 26330 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26331 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26332 {0, ARM_ARCH_NONE}
26333};
26334
ee3c0378
AS
26335/* Set an attribute if it has not already been set by the user. */
26336static void
26337aeabi_set_attribute_int (int tag, int value)
26338{
26339 if (tag < 1
26340 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26341 || !attributes_set_explicitly[tag])
26342 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26343}
26344
26345static void
26346aeabi_set_attribute_string (int tag, const char *value)
26347{
26348 if (tag < 1
26349 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26350 || !attributes_set_explicitly[tag])
26351 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26352}
26353
ee065d83 26354/* Set the public EABI object attributes. */
3cfdb781 26355void
ee065d83
PB
26356aeabi_set_public_attributes (void)
26357{
26358 int arch;
69239280 26359 char profile;
90ec0d68 26360 int virt_sec = 0;
bca38921 26361 int fp16_optional = 0;
15afaa63 26362 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26363 arm_feature_set flags;
62b3e311 26364 arm_feature_set tmp;
ff8646ee 26365 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26366 const cpu_arch_ver_table *p;
ee065d83
PB
26367
26368 /* Choose the architecture based on the capabilities of the requested cpu
26369 (if any) and/or the instructions actually used. */
e74cfd16
PB
26370 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26371 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26372 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26373
26374 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26375 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26376
26377 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26378 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26379
7f78eb34
JW
26380 selected_cpu = flags;
26381
ddd7f988 26382 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26383 if (object_arch)
26384 {
26385 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26386 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26387 }
26388
251665fc
MGD
26389 /* We need to make sure that the attributes do not identify us as v6S-M
26390 when the only v6S-M feature in use is the Operating System Extensions. */
26391 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26392 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26393 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26394
62b3e311
PB
26395 tmp = flags;
26396 arch = 0;
26397 for (p = cpu_arch_ver; p->val; p++)
26398 {
26399 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26400 {
26401 arch = p->val;
15afaa63 26402 arm_arch = p->flags;
62b3e311
PB
26403 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26404 }
26405 }
ee065d83 26406
9e3c6df6
PB
26407 /* The table lookup above finds the last architecture to contribute
26408 a new feature. Unfortunately, Tag13 is a subset of the union of
26409 v6T2 and v7-M, so it is never seen as contributing a new feature.
26410 We can not search for the last entry which is entirely used,
26411 because if no CPU is specified we build up only those flags
26412 actually used. Perhaps we should separate out the specified
26413 and implicit cases. Avoid taking this path for -march=all by
26414 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26415 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26416 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26417 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26418 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26419 {
26420 arch = TAG_CPU_ARCH_V7E_M;
26421 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26422 }
4ed7ed8d 26423
ff8646ee
TP
26424 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26425 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26426 {
26427 arch = TAG_CPU_ARCH_V8M_MAIN;
26428 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26429 }
ff8646ee 26430
4ed7ed8d
TP
26431 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26432 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26433 ARMv8-M, -march=all must be detected as ARMv8-A. */
26434 if (arch == TAG_CPU_ARCH_V8M_MAIN
26435 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26436 {
26437 arch = TAG_CPU_ARCH_V8;
26438 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26439 }
9e3c6df6 26440
ee065d83
PB
26441 /* Tag_CPU_name. */
26442 if (selected_cpu_name[0])
26443 {
91d6fa6a 26444 char *q;
ee065d83 26445
91d6fa6a
NC
26446 q = selected_cpu_name;
26447 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26448 {
26449 int i;
5f4273c7 26450
91d6fa6a
NC
26451 q += 4;
26452 for (i = 0; q[i]; i++)
26453 q[i] = TOUPPER (q[i]);
ee065d83 26454 }
91d6fa6a 26455 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26456 }
62f3b8c8 26457
ee065d83 26458 /* Tag_CPU_arch. */
ee3c0378 26459 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26460
62b3e311 26461 /* Tag_CPU_arch_profile. */
10c9892b 26462 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26463 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26464 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26465 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26466 profile = 'A';
62b3e311 26467 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26468 profile = 'R';
7e806470 26469 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26470 profile = 'M';
26471 else
26472 profile = '\0';
26473
26474 if (profile != '\0')
26475 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26476
15afaa63
TP
26477 /* Tag_DSP_extension. */
26478 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26479 {
26480 arm_feature_set ext;
26481
26482 /* DSP instructions not in architecture. */
26483 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26484 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26485 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26486 }
26487
ee065d83 26488 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26489 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26490 || arch == 0)
26491 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26492
ee065d83 26493 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26494 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26495 || arch == 0)
4ed7ed8d
TP
26496 {
26497 int thumb_isa_use;
26498
26499 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26500 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26501 thumb_isa_use = 3;
26502 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26503 thumb_isa_use = 2;
26504 else
26505 thumb_isa_use = 1;
26506 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26507 }
62f3b8c8 26508
ee065d83 26509 /* Tag_VFP_arch. */
a715796b
TG
26510 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26511 aeabi_set_attribute_int (Tag_VFP_arch,
26512 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26513 ? 7 : 8);
bca38921 26514 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26515 aeabi_set_attribute_int (Tag_VFP_arch,
26516 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26517 ? 5 : 6);
26518 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26519 {
26520 fp16_optional = 1;
26521 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26522 }
ada65aa3 26523 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26524 {
26525 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26526 fp16_optional = 1;
26527 }
ee3c0378
AS
26528 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26529 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26530 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26531 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26532 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26533
4547cb56
NC
26534 /* Tag_ABI_HardFP_use. */
26535 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26536 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26537 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26538
ee065d83 26539 /* Tag_WMMX_arch. */
ee3c0378
AS
26540 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26541 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26542 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26543 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26544
ee3c0378 26545 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26546 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26547 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26548 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26549 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26550 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26551 {
26552 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26553 {
26554 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26555 }
26556 else
26557 {
26558 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26559 fp16_optional = 1;
26560 }
26561 }
fa94de6b 26562
ee3c0378 26563 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26564 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26565 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26566
69239280
MGD
26567 /* Tag_DIV_use.
26568
26569 We set Tag_DIV_use to two when integer divide instructions have been used
26570 in ARM state, or when Thumb integer divide instructions have been used,
26571 but we have no architecture profile set, nor have we any ARM instructions.
26572
4ed7ed8d
TP
26573 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26574 by the base architecture.
bca38921 26575
69239280 26576 For new architectures we will have to check these tests. */
ff8646ee
TP
26577 gas_assert (arch <= TAG_CPU_ARCH_V8
26578 || (arch >= TAG_CPU_ARCH_V8M_BASE
26579 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26580 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26581 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26582 aeabi_set_attribute_int (Tag_DIV_use, 0);
26583 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26584 || (profile == '\0'
26585 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26586 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26587 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26588
26589 /* Tag_MP_extension_use. */
26590 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26591 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26592
26593 /* Tag Virtualization_use. */
26594 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26595 virt_sec |= 1;
26596 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26597 virt_sec |= 2;
26598 if (virt_sec != 0)
26599 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26600}
26601
104d59d1 26602/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26603void
26604arm_md_end (void)
26605{
ee065d83
PB
26606 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26607 return;
26608
26609 aeabi_set_public_attributes ();
ee065d83 26610}
8463be01 26611#endif /* OBJ_ELF */
ee065d83
PB
26612
26613
26614/* Parse a .cpu directive. */
26615
26616static void
26617s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26618{
e74cfd16 26619 const struct arm_cpu_option_table *opt;
ee065d83
PB
26620 char *name;
26621 char saved_char;
26622
26623 name = input_line_pointer;
5f4273c7 26624 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26625 input_line_pointer++;
26626 saved_char = *input_line_pointer;
26627 *input_line_pointer = 0;
26628
26629 /* Skip the first "all" entry. */
26630 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26631 if (streq (opt->name, name))
26632 {
e74cfd16
PB
26633 mcpu_cpu_opt = &opt->value;
26634 selected_cpu = opt->value;
ee065d83 26635 if (opt->canonical_name)
5f4273c7 26636 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26637 else
26638 {
26639 int i;
26640 for (i = 0; opt->name[i]; i++)
26641 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26642
ee065d83
PB
26643 selected_cpu_name[i] = 0;
26644 }
e74cfd16 26645 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26646 *input_line_pointer = saved_char;
26647 demand_empty_rest_of_line ();
26648 return;
26649 }
26650 as_bad (_("unknown cpu `%s'"), name);
26651 *input_line_pointer = saved_char;
26652 ignore_rest_of_line ();
26653}
26654
26655
26656/* Parse a .arch directive. */
26657
26658static void
26659s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26660{
e74cfd16 26661 const struct arm_arch_option_table *opt;
ee065d83
PB
26662 char saved_char;
26663 char *name;
26664
26665 name = input_line_pointer;
5f4273c7 26666 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26667 input_line_pointer++;
26668 saved_char = *input_line_pointer;
26669 *input_line_pointer = 0;
26670
26671 /* Skip the first "all" entry. */
26672 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26673 if (streq (opt->name, name))
26674 {
e74cfd16
PB
26675 mcpu_cpu_opt = &opt->value;
26676 selected_cpu = opt->value;
5f4273c7 26677 strcpy (selected_cpu_name, opt->name);
e74cfd16 26678 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26679 *input_line_pointer = saved_char;
26680 demand_empty_rest_of_line ();
26681 return;
26682 }
26683
26684 as_bad (_("unknown architecture `%s'\n"), name);
26685 *input_line_pointer = saved_char;
26686 ignore_rest_of_line ();
26687}
26688
26689
7a1d4c38
PB
26690/* Parse a .object_arch directive. */
26691
26692static void
26693s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26694{
26695 const struct arm_arch_option_table *opt;
26696 char saved_char;
26697 char *name;
26698
26699 name = input_line_pointer;
5f4273c7 26700 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26701 input_line_pointer++;
26702 saved_char = *input_line_pointer;
26703 *input_line_pointer = 0;
26704
26705 /* Skip the first "all" entry. */
26706 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26707 if (streq (opt->name, name))
26708 {
26709 object_arch = &opt->value;
26710 *input_line_pointer = saved_char;
26711 demand_empty_rest_of_line ();
26712 return;
26713 }
26714
26715 as_bad (_("unknown architecture `%s'\n"), name);
26716 *input_line_pointer = saved_char;
26717 ignore_rest_of_line ();
26718}
26719
69133863
MGD
26720/* Parse a .arch_extension directive. */
26721
26722static void
26723s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26724{
26725 const struct arm_option_extension_value_table *opt;
d942732e 26726 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26727 char saved_char;
26728 char *name;
26729 int adding_value = 1;
26730
26731 name = input_line_pointer;
26732 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26733 input_line_pointer++;
26734 saved_char = *input_line_pointer;
26735 *input_line_pointer = 0;
26736
26737 if (strlen (name) >= 2
26738 && strncmp (name, "no", 2) == 0)
26739 {
26740 adding_value = 0;
26741 name += 2;
26742 }
26743
26744 for (opt = arm_extensions; opt->name != NULL; opt++)
26745 if (streq (opt->name, name))
26746 {
d942732e
TP
26747 int i, nb_allowed_archs =
26748 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26749 for (i = 0; i < nb_allowed_archs; i++)
26750 {
26751 /* Empty entry. */
26752 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26753 continue;
26754 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26755 break;
26756 }
26757
26758 if (i == nb_allowed_archs)
69133863
MGD
26759 {
26760 as_bad (_("architectural extension `%s' is not allowed for the "
26761 "current base architecture"), name);
26762 break;
26763 }
26764
26765 if (adding_value)
5a70a223
JB
26766 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26767 opt->merge_value);
69133863 26768 else
5a70a223 26769 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26770
26771 mcpu_cpu_opt = &selected_cpu;
26772 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26773 *input_line_pointer = saved_char;
26774 demand_empty_rest_of_line ();
26775 return;
26776 }
26777
26778 if (opt->name == NULL)
e673710a 26779 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26780
26781 *input_line_pointer = saved_char;
26782 ignore_rest_of_line ();
26783}
26784
ee065d83
PB
26785/* Parse a .fpu directive. */
26786
26787static void
26788s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26789{
69133863 26790 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26791 char saved_char;
26792 char *name;
26793
26794 name = input_line_pointer;
5f4273c7 26795 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26796 input_line_pointer++;
26797 saved_char = *input_line_pointer;
26798 *input_line_pointer = 0;
5f4273c7 26799
ee065d83
PB
26800 for (opt = arm_fpus; opt->name != NULL; opt++)
26801 if (streq (opt->name, name))
26802 {
e74cfd16
PB
26803 mfpu_opt = &opt->value;
26804 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26805 *input_line_pointer = saved_char;
26806 demand_empty_rest_of_line ();
26807 return;
26808 }
26809
26810 as_bad (_("unknown floating point format `%s'\n"), name);
26811 *input_line_pointer = saved_char;
26812 ignore_rest_of_line ();
26813}
ee065d83 26814
794ba86a 26815/* Copy symbol information. */
f31fef98 26816
794ba86a
DJ
26817void
26818arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26819{
26820 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26821}
e04befd0 26822
f31fef98 26823#ifdef OBJ_ELF
e04befd0
AS
26824/* Given a symbolic attribute NAME, return the proper integer value.
26825 Returns -1 if the attribute is not known. */
f31fef98 26826
e04befd0
AS
26827int
26828arm_convert_symbolic_attribute (const char *name)
26829{
f31fef98
NC
26830 static const struct
26831 {
26832 const char * name;
26833 const int tag;
26834 }
26835 attribute_table[] =
26836 {
26837 /* When you modify this table you should
26838 also modify the list in doc/c-arm.texi. */
e04befd0 26839#define T(tag) {#tag, tag}
f31fef98
NC
26840 T (Tag_CPU_raw_name),
26841 T (Tag_CPU_name),
26842 T (Tag_CPU_arch),
26843 T (Tag_CPU_arch_profile),
26844 T (Tag_ARM_ISA_use),
26845 T (Tag_THUMB_ISA_use),
75375b3e 26846 T (Tag_FP_arch),
f31fef98
NC
26847 T (Tag_VFP_arch),
26848 T (Tag_WMMX_arch),
26849 T (Tag_Advanced_SIMD_arch),
26850 T (Tag_PCS_config),
26851 T (Tag_ABI_PCS_R9_use),
26852 T (Tag_ABI_PCS_RW_data),
26853 T (Tag_ABI_PCS_RO_data),
26854 T (Tag_ABI_PCS_GOT_use),
26855 T (Tag_ABI_PCS_wchar_t),
26856 T (Tag_ABI_FP_rounding),
26857 T (Tag_ABI_FP_denormal),
26858 T (Tag_ABI_FP_exceptions),
26859 T (Tag_ABI_FP_user_exceptions),
26860 T (Tag_ABI_FP_number_model),
75375b3e 26861 T (Tag_ABI_align_needed),
f31fef98 26862 T (Tag_ABI_align8_needed),
75375b3e 26863 T (Tag_ABI_align_preserved),
f31fef98
NC
26864 T (Tag_ABI_align8_preserved),
26865 T (Tag_ABI_enum_size),
26866 T (Tag_ABI_HardFP_use),
26867 T (Tag_ABI_VFP_args),
26868 T (Tag_ABI_WMMX_args),
26869 T (Tag_ABI_optimization_goals),
26870 T (Tag_ABI_FP_optimization_goals),
26871 T (Tag_compatibility),
26872 T (Tag_CPU_unaligned_access),
75375b3e 26873 T (Tag_FP_HP_extension),
f31fef98
NC
26874 T (Tag_VFP_HP_extension),
26875 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26876 T (Tag_MPextension_use),
26877 T (Tag_DIV_use),
f31fef98
NC
26878 T (Tag_nodefaults),
26879 T (Tag_also_compatible_with),
26880 T (Tag_conformance),
26881 T (Tag_T2EE_use),
26882 T (Tag_Virtualization_use),
15afaa63 26883 T (Tag_DSP_extension),
cd21e546 26884 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26885#undef T
f31fef98 26886 };
e04befd0
AS
26887 unsigned int i;
26888
26889 if (name == NULL)
26890 return -1;
26891
f31fef98 26892 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26893 if (streq (name, attribute_table[i].name))
e04befd0
AS
26894 return attribute_table[i].tag;
26895
26896 return -1;
26897}
267bf995
RR
26898
26899
93ef582d
NC
26900/* Apply sym value for relocations only in the case that they are for
26901 local symbols in the same segment as the fixup and you have the
26902 respective architectural feature for blx and simple switches. */
267bf995 26903int
93ef582d 26904arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26905{
26906 if (fixP->fx_addsy
26907 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26908 /* PR 17444: If the local symbol is in a different section then a reloc
26909 will always be generated for it, so applying the symbol value now
26910 will result in a double offset being stored in the relocation. */
26911 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26912 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26913 {
26914 switch (fixP->fx_r_type)
26915 {
26916 case BFD_RELOC_ARM_PCREL_BLX:
26917 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26918 if (ARM_IS_FUNC (fixP->fx_addsy))
26919 return 1;
26920 break;
26921
26922 case BFD_RELOC_ARM_PCREL_CALL:
26923 case BFD_RELOC_THUMB_PCREL_BLX:
26924 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26925 return 1;
267bf995
RR
26926 break;
26927
26928 default:
26929 break;
26930 }
26931
26932 }
26933 return 0;
26934}
f31fef98 26935#endif /* OBJ_ELF */
This page took 3.762129 seconds and 4 git commands to generate.