Ensure that padding in the constant pool uses constant values.
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
6f2750fe 2 Copyright (C) 1994-2016 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 158static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
160static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
823d2571
TG
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 179static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
180 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
188static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
189static const arm_feature_set arm_ext_v6_notm =
190 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
191static const arm_feature_set arm_ext_v6_dsp =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
193static const arm_feature_set arm_ext_barrier =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
195static const arm_feature_set arm_ext_msr =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
197static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
201static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
202static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 203static const arm_feature_set arm_ext_m =
16a1fa25
TP
204 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M,
205 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
206static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
207static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
208static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
209static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
210static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 211static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 212static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
213static const arm_feature_set arm_ext_v8m_main =
214 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
215/* Instructions in ARMv8-M only found in M profile architectures. */
216static const arm_feature_set arm_ext_v8m_m_only =
217 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
218static const arm_feature_set arm_ext_v6t2_v8m =
219 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
220/* Instructions shared between ARMv8-A and ARMv8-M. */
221static const arm_feature_set arm_ext_atomics =
222 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
15afaa63
TP
223/* DSP instructions Tag_DSP_extension refers to. */
224static const arm_feature_set arm_ext_dsp =
225 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
105bde57
MW
226static const arm_feature_set arm_ext_v8_2 =
227 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
b8ec4e87
JW
228/* FP16 instructions. */
229static const arm_feature_set arm_ext_fp16 =
230 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
e74cfd16
PB
231
232static const arm_feature_set arm_arch_any = ARM_ANY;
f85d59c3 233static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
234static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
235static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 236static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 237
2d447fca 238static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 239 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 240static const arm_feature_set arm_cext_iwmmxt =
823d2571 241 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 242static const arm_feature_set arm_cext_xscale =
823d2571 243 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 244static const arm_feature_set arm_cext_maverick =
823d2571
TG
245 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
246static const arm_feature_set fpu_fpa_ext_v1 =
247 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
248static const arm_feature_set fpu_fpa_ext_v2 =
249 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 250static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
251 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
252static const arm_feature_set fpu_vfp_ext_v1 =
253 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
254static const arm_feature_set fpu_vfp_ext_v2 =
255 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
256static const arm_feature_set fpu_vfp_ext_v3xd =
257 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
258static const arm_feature_set fpu_vfp_ext_v3 =
259 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 260static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
261 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
262static const arm_feature_set fpu_neon_ext_v1 =
263 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 264static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
265 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
266static const arm_feature_set fpu_vfp_fp16 =
267 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
268static const arm_feature_set fpu_neon_ext_fma =
269 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
270static const arm_feature_set fpu_vfp_ext_fma =
271 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 272static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 273 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 274static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 275 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 276static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 277 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 278static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 279 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 280static const arm_feature_set crc_ext_armv8 =
823d2571 281 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 282static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 283 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 284
33a392fb 285static int mfloat_abi_opt = -1;
e74cfd16
PB
286/* Record user cpu selection for object attributes. */
287static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 288/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 289static char selected_cpu_name[20];
8d67f500 290
aacf0b33
KT
291extern FLONUM_TYPE generic_floating_point_number;
292
8d67f500
NC
293/* Return if no cpu was selected on command-line. */
294static bfd_boolean
295no_cpu_selected (void)
296{
823d2571 297 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
298}
299
7cc69913 300#ifdef OBJ_ELF
deeaaff8
DJ
301# ifdef EABI_DEFAULT
302static int meabi_flags = EABI_DEFAULT;
303# else
d507cf36 304static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 305# endif
e1da3f5b 306
ee3c0378
AS
307static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
308
e1da3f5b 309bfd_boolean
5f4273c7 310arm_is_eabi (void)
e1da3f5b
PB
311{
312 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
313}
7cc69913 314#endif
b99bd4ef 315
b99bd4ef 316#ifdef OBJ_ELF
c19d1205 317/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
318symbolS * GOT_symbol;
319#endif
320
b99bd4ef
NC
321/* 0: assemble for ARM,
322 1: assemble for Thumb,
323 2: assemble for Thumb even though target CPU does not support thumb
324 instructions. */
325static int thumb_mode = 0;
8dc2430f
NC
326/* A value distinct from the possible values for thumb_mode that we
327 can use to record whether thumb_mode has been copied into the
328 tc_frag_data field of a frag. */
329#define MODE_RECORDED (1 << 4)
b99bd4ef 330
e07e6e58
NC
331/* Specifies the intrinsic IT insn behavior mode. */
332enum implicit_it_mode
333{
334 IMPLICIT_IT_MODE_NEVER = 0x00,
335 IMPLICIT_IT_MODE_ARM = 0x01,
336 IMPLICIT_IT_MODE_THUMB = 0x02,
337 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
338};
339static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
340
c19d1205
ZW
341/* If unified_syntax is true, we are processing the new unified
342 ARM/Thumb syntax. Important differences from the old ARM mode:
343
344 - Immediate operands do not require a # prefix.
345 - Conditional affixes always appear at the end of the
346 instruction. (For backward compatibility, those instructions
347 that formerly had them in the middle, continue to accept them
348 there.)
349 - The IT instruction may appear, and if it does is validated
350 against subsequent conditional affixes. It does not generate
351 machine code.
352
353 Important differences from the old Thumb mode:
354
355 - Immediate operands do not require a # prefix.
356 - Most of the V6T2 instructions are only available in unified mode.
357 - The .N and .W suffixes are recognized and honored (it is an error
358 if they cannot be honored).
359 - All instructions set the flags if and only if they have an 's' affix.
360 - Conditional affixes may be used. They are validated against
361 preceding IT instructions. Unlike ARM mode, you cannot use a
362 conditional affix except in the scope of an IT instruction. */
363
364static bfd_boolean unified_syntax = FALSE;
b99bd4ef 365
bacebabc
RM
366/* An immediate operand can start with #, and ld*, st*, pld operands
367 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
368 before a [, which can appear as the first operand for pld.
369 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
370const char arm_symbol_chars[] = "#[]{}";
bacebabc 371
5287ad62
JB
372enum neon_el_type
373{
dcbf9037 374 NT_invtype,
5287ad62
JB
375 NT_untyped,
376 NT_integer,
377 NT_float,
378 NT_poly,
379 NT_signed,
dcbf9037 380 NT_unsigned
5287ad62
JB
381};
382
383struct neon_type_el
384{
385 enum neon_el_type type;
386 unsigned size;
387};
388
389#define NEON_MAX_TYPE_ELS 4
390
391struct neon_type
392{
393 struct neon_type_el el[NEON_MAX_TYPE_ELS];
394 unsigned elems;
395};
396
e07e6e58
NC
397enum it_instruction_type
398{
399 OUTSIDE_IT_INSN,
400 INSIDE_IT_INSN,
401 INSIDE_IT_LAST_INSN,
402 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 403 if inside, should be the last one. */
e07e6e58 404 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 405 i.e. BKPT and NOP. */
e07e6e58
NC
406 IT_INSN /* The IT insn has been parsed. */
407};
408
ad6cec43
MGD
409/* The maximum number of operands we need. */
410#define ARM_IT_MAX_OPERANDS 6
411
b99bd4ef
NC
412struct arm_it
413{
c19d1205 414 const char * error;
b99bd4ef 415 unsigned long instruction;
c19d1205
ZW
416 int size;
417 int size_req;
418 int cond;
037e8744
JB
419 /* "uncond_value" is set to the value in place of the conditional field in
420 unconditional versions of the instruction, or -1 if nothing is
421 appropriate. */
422 int uncond_value;
5287ad62 423 struct neon_type vectype;
88714cb8
DG
424 /* This does not indicate an actual NEON instruction, only that
425 the mnemonic accepts neon-style type suffixes. */
426 int is_neon;
0110f2b8
PB
427 /* Set to the opcode if the instruction needs relaxation.
428 Zero if the instruction is not relaxed. */
429 unsigned long relax;
b99bd4ef
NC
430 struct
431 {
432 bfd_reloc_code_real_type type;
c19d1205
ZW
433 expressionS exp;
434 int pc_rel;
b99bd4ef 435 } reloc;
b99bd4ef 436
e07e6e58
NC
437 enum it_instruction_type it_insn_type;
438
c19d1205
ZW
439 struct
440 {
441 unsigned reg;
ca3f61f7 442 signed int imm;
dcbf9037 443 struct neon_type_el vectype;
ca3f61f7
NC
444 unsigned present : 1; /* Operand present. */
445 unsigned isreg : 1; /* Operand was a register. */
446 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
447 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
448 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 449 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
450 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
451 instructions. This allows us to disambiguate ARM <-> vector insns. */
452 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 453 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 454 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 455 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
456 unsigned hasreloc : 1; /* Operand has relocation suffix. */
457 unsigned writeback : 1; /* Operand has trailing ! */
458 unsigned preind : 1; /* Preindexed address. */
459 unsigned postind : 1; /* Postindexed address. */
460 unsigned negative : 1; /* Index register was negated. */
461 unsigned shifted : 1; /* Shift applied to operation. */
462 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 463 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
464};
465
c19d1205 466static struct arm_it inst;
b99bd4ef
NC
467
468#define NUM_FLOAT_VALS 8
469
05d2d07e 470const char * fp_const[] =
b99bd4ef
NC
471{
472 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
473};
474
c19d1205 475/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
476#define MAX_LITTLENUMS 6
477
478LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
479
480#define FAIL (-1)
481#define SUCCESS (0)
482
483#define SUFF_S 1
484#define SUFF_D 2
485#define SUFF_E 3
486#define SUFF_P 4
487
c19d1205
ZW
488#define CP_T_X 0x00008000
489#define CP_T_Y 0x00400000
b99bd4ef 490
c19d1205
ZW
491#define CONDS_BIT 0x00100000
492#define LOAD_BIT 0x00100000
b99bd4ef
NC
493
494#define DOUBLE_LOAD_FLAG 0x00000001
495
496struct asm_cond
497{
d3ce72d0 498 const char * template_name;
c921be7d 499 unsigned long value;
b99bd4ef
NC
500};
501
c19d1205 502#define COND_ALWAYS 0xE
b99bd4ef 503
b99bd4ef
NC
504struct asm_psr
505{
d3ce72d0 506 const char * template_name;
c921be7d 507 unsigned long field;
b99bd4ef
NC
508};
509
62b3e311
PB
510struct asm_barrier_opt
511{
e797f7e0
MGD
512 const char * template_name;
513 unsigned long value;
514 const arm_feature_set arch;
62b3e311
PB
515};
516
2d2255b5 517/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
518#define SPSR_BIT (1 << 22)
519
c19d1205
ZW
520/* The individual PSR flag bits. */
521#define PSR_c (1 << 16)
522#define PSR_x (1 << 17)
523#define PSR_s (1 << 18)
524#define PSR_f (1 << 19)
b99bd4ef 525
c19d1205 526struct reloc_entry
bfae80f2 527{
e0471c16 528 const char * name;
c921be7d 529 bfd_reloc_code_real_type reloc;
bfae80f2
RE
530};
531
5287ad62 532enum vfp_reg_pos
bfae80f2 533{
5287ad62
JB
534 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
535 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
536};
537
538enum vfp_ldstm_type
539{
540 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
541};
542
dcbf9037
JB
543/* Bits for DEFINED field in neon_typed_alias. */
544#define NTA_HASTYPE 1
545#define NTA_HASINDEX 2
546
547struct neon_typed_alias
548{
c921be7d
NC
549 unsigned char defined;
550 unsigned char index;
551 struct neon_type_el eltype;
dcbf9037
JB
552};
553
c19d1205
ZW
554/* ARM register categories. This includes coprocessor numbers and various
555 architecture extensions' registers. */
556enum arm_reg_type
bfae80f2 557{
c19d1205
ZW
558 REG_TYPE_RN,
559 REG_TYPE_CP,
560 REG_TYPE_CN,
561 REG_TYPE_FN,
562 REG_TYPE_VFS,
563 REG_TYPE_VFD,
5287ad62 564 REG_TYPE_NQ,
037e8744 565 REG_TYPE_VFSD,
5287ad62 566 REG_TYPE_NDQ,
037e8744 567 REG_TYPE_NSDQ,
c19d1205
ZW
568 REG_TYPE_VFC,
569 REG_TYPE_MVF,
570 REG_TYPE_MVD,
571 REG_TYPE_MVFX,
572 REG_TYPE_MVDX,
573 REG_TYPE_MVAX,
574 REG_TYPE_DSPSC,
575 REG_TYPE_MMXWR,
576 REG_TYPE_MMXWC,
577 REG_TYPE_MMXWCG,
578 REG_TYPE_XSCALE,
90ec0d68 579 REG_TYPE_RNB
bfae80f2
RE
580};
581
dcbf9037
JB
582/* Structure for a hash table entry for a register.
583 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
584 information which states whether a vector type or index is specified (for a
585 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
586struct reg_entry
587{
c921be7d 588 const char * name;
90ec0d68 589 unsigned int number;
c921be7d
NC
590 unsigned char type;
591 unsigned char builtin;
592 struct neon_typed_alias * neon;
6c43fab6
RE
593};
594
c19d1205 595/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 596const char * const reg_expected_msgs[] =
c19d1205
ZW
597{
598 N_("ARM register expected"),
599 N_("bad or missing co-processor number"),
600 N_("co-processor register expected"),
601 N_("FPA register expected"),
602 N_("VFP single precision register expected"),
5287ad62
JB
603 N_("VFP/Neon double precision register expected"),
604 N_("Neon quad precision register expected"),
037e8744 605 N_("VFP single or double precision register expected"),
5287ad62 606 N_("Neon double or quad precision register expected"),
037e8744 607 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
608 N_("VFP system register expected"),
609 N_("Maverick MVF register expected"),
610 N_("Maverick MVD register expected"),
611 N_("Maverick MVFX register expected"),
612 N_("Maverick MVDX register expected"),
613 N_("Maverick MVAX register expected"),
614 N_("Maverick DSPSC register expected"),
615 N_("iWMMXt data register expected"),
616 N_("iWMMXt control register expected"),
617 N_("iWMMXt scalar register expected"),
618 N_("XScale accumulator register expected"),
6c43fab6
RE
619};
620
c19d1205 621/* Some well known registers that we refer to directly elsewhere. */
bd340a04 622#define REG_R12 12
c19d1205
ZW
623#define REG_SP 13
624#define REG_LR 14
625#define REG_PC 15
404ff6b5 626
b99bd4ef
NC
627/* ARM instructions take 4bytes in the object file, Thumb instructions
628 take 2: */
c19d1205 629#define INSN_SIZE 4
b99bd4ef
NC
630
631struct asm_opcode
632{
633 /* Basic string to match. */
d3ce72d0 634 const char * template_name;
c19d1205
ZW
635
636 /* Parameters to instruction. */
5be8be5d 637 unsigned int operands[8];
c19d1205
ZW
638
639 /* Conditional tag - see opcode_lookup. */
640 unsigned int tag : 4;
b99bd4ef
NC
641
642 /* Basic instruction code. */
c19d1205 643 unsigned int avalue : 28;
b99bd4ef 644
c19d1205
ZW
645 /* Thumb-format instruction code. */
646 unsigned int tvalue;
b99bd4ef 647
90e4755a 648 /* Which architecture variant provides this instruction. */
c921be7d
NC
649 const arm_feature_set * avariant;
650 const arm_feature_set * tvariant;
c19d1205
ZW
651
652 /* Function to call to encode instruction in ARM format. */
653 void (* aencode) (void);
b99bd4ef 654
c19d1205
ZW
655 /* Function to call to encode instruction in Thumb format. */
656 void (* tencode) (void);
b99bd4ef
NC
657};
658
a737bd4d
NC
659/* Defines for various bits that we will want to toggle. */
660#define INST_IMMEDIATE 0x02000000
661#define OFFSET_REG 0x02000000
c19d1205 662#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
663#define SHIFT_BY_REG 0x00000010
664#define PRE_INDEX 0x01000000
665#define INDEX_UP 0x00800000
666#define WRITE_BACK 0x00200000
667#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 668#define CPSI_MMOD 0x00020000
90e4755a 669
a737bd4d
NC
670#define LITERAL_MASK 0xf000f000
671#define OPCODE_MASK 0xfe1fffff
672#define V4_STR_BIT 0x00000020
8335d6aa 673#define VLDR_VMOV_SAME 0x0040f000
90e4755a 674
efd81785
PB
675#define T2_SUBS_PC_LR 0xf3de8f00
676
a737bd4d 677#define DATA_OP_SHIFT 21
90e4755a 678
ef8d22e6
PB
679#define T2_OPCODE_MASK 0xfe1fffff
680#define T2_DATA_OP_SHIFT 21
681
6530b175
NC
682#define A_COND_MASK 0xf0000000
683#define A_PUSH_POP_OP_MASK 0x0fff0000
684
685/* Opcodes for pushing/poping registers to/from the stack. */
686#define A1_OPCODE_PUSH 0x092d0000
687#define A2_OPCODE_PUSH 0x052d0004
688#define A2_OPCODE_POP 0x049d0004
689
a737bd4d
NC
690/* Codes to distinguish the arithmetic instructions. */
691#define OPCODE_AND 0
692#define OPCODE_EOR 1
693#define OPCODE_SUB 2
694#define OPCODE_RSB 3
695#define OPCODE_ADD 4
696#define OPCODE_ADC 5
697#define OPCODE_SBC 6
698#define OPCODE_RSC 7
699#define OPCODE_TST 8
700#define OPCODE_TEQ 9
701#define OPCODE_CMP 10
702#define OPCODE_CMN 11
703#define OPCODE_ORR 12
704#define OPCODE_MOV 13
705#define OPCODE_BIC 14
706#define OPCODE_MVN 15
90e4755a 707
ef8d22e6
PB
708#define T2_OPCODE_AND 0
709#define T2_OPCODE_BIC 1
710#define T2_OPCODE_ORR 2
711#define T2_OPCODE_ORN 3
712#define T2_OPCODE_EOR 4
713#define T2_OPCODE_ADD 8
714#define T2_OPCODE_ADC 10
715#define T2_OPCODE_SBC 11
716#define T2_OPCODE_SUB 13
717#define T2_OPCODE_RSB 14
718
a737bd4d
NC
719#define T_OPCODE_MUL 0x4340
720#define T_OPCODE_TST 0x4200
721#define T_OPCODE_CMN 0x42c0
722#define T_OPCODE_NEG 0x4240
723#define T_OPCODE_MVN 0x43c0
90e4755a 724
a737bd4d
NC
725#define T_OPCODE_ADD_R3 0x1800
726#define T_OPCODE_SUB_R3 0x1a00
727#define T_OPCODE_ADD_HI 0x4400
728#define T_OPCODE_ADD_ST 0xb000
729#define T_OPCODE_SUB_ST 0xb080
730#define T_OPCODE_ADD_SP 0xa800
731#define T_OPCODE_ADD_PC 0xa000
732#define T_OPCODE_ADD_I8 0x3000
733#define T_OPCODE_SUB_I8 0x3800
734#define T_OPCODE_ADD_I3 0x1c00
735#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 736
a737bd4d
NC
737#define T_OPCODE_ASR_R 0x4100
738#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
739#define T_OPCODE_LSR_R 0x40c0
740#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
741#define T_OPCODE_ASR_I 0x1000
742#define T_OPCODE_LSL_I 0x0000
743#define T_OPCODE_LSR_I 0x0800
b99bd4ef 744
a737bd4d
NC
745#define T_OPCODE_MOV_I8 0x2000
746#define T_OPCODE_CMP_I8 0x2800
747#define T_OPCODE_CMP_LR 0x4280
748#define T_OPCODE_MOV_HR 0x4600
749#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 750
a737bd4d
NC
751#define T_OPCODE_LDR_PC 0x4800
752#define T_OPCODE_LDR_SP 0x9800
753#define T_OPCODE_STR_SP 0x9000
754#define T_OPCODE_LDR_IW 0x6800
755#define T_OPCODE_STR_IW 0x6000
756#define T_OPCODE_LDR_IH 0x8800
757#define T_OPCODE_STR_IH 0x8000
758#define T_OPCODE_LDR_IB 0x7800
759#define T_OPCODE_STR_IB 0x7000
760#define T_OPCODE_LDR_RW 0x5800
761#define T_OPCODE_STR_RW 0x5000
762#define T_OPCODE_LDR_RH 0x5a00
763#define T_OPCODE_STR_RH 0x5200
764#define T_OPCODE_LDR_RB 0x5c00
765#define T_OPCODE_STR_RB 0x5400
c9b604bd 766
a737bd4d
NC
767#define T_OPCODE_PUSH 0xb400
768#define T_OPCODE_POP 0xbc00
b99bd4ef 769
2fc8bdac 770#define T_OPCODE_BRANCH 0xe000
b99bd4ef 771
a737bd4d 772#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 773#define THUMB_PP_PC_LR 0x0100
c19d1205 774#define THUMB_LOAD_BIT 0x0800
53365c0d 775#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
776
777#define BAD_ARGS _("bad arguments to instruction")
fdfde340 778#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
779#define BAD_PC _("r15 not allowed here")
780#define BAD_COND _("instruction cannot be conditional")
781#define BAD_OVERLAP _("registers may not be the same")
782#define BAD_HIREG _("lo register required")
783#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 784#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
785#define BAD_BRANCH _("branch must be last instruction in IT block")
786#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 787#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
788#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
789#define BAD_IT_COND _("incorrect condition in IT block")
790#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 791#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
792#define BAD_PC_ADDRESSING \
793 _("cannot use register index with PC-relative addressing")
794#define BAD_PC_WRITEBACK \
795 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
796#define BAD_RANGE _("branch out of range")
797#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 798#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 799#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 800
c921be7d
NC
801static struct hash_control * arm_ops_hsh;
802static struct hash_control * arm_cond_hsh;
803static struct hash_control * arm_shift_hsh;
804static struct hash_control * arm_psr_hsh;
805static struct hash_control * arm_v7m_psr_hsh;
806static struct hash_control * arm_reg_hsh;
807static struct hash_control * arm_reloc_hsh;
808static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 809
b99bd4ef
NC
810/* Stuff needed to resolve the label ambiguity
811 As:
812 ...
813 label: <insn>
814 may differ from:
815 ...
816 label:
5f4273c7 817 <insn> */
b99bd4ef
NC
818
819symbolS * last_label_seen;
b34976b6 820static int label_is_thumb_function_name = FALSE;
e07e6e58 821
3d0c9500
NC
822/* Literal pool structure. Held on a per-section
823 and per-sub-section basis. */
a737bd4d 824
c19d1205 825#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 826typedef struct literal_pool
b99bd4ef 827{
c921be7d
NC
828 expressionS literals [MAX_LITERAL_POOL_SIZE];
829 unsigned int next_free_entry;
830 unsigned int id;
831 symbolS * symbol;
832 segT section;
833 subsegT sub_section;
a8040cf2
NC
834#ifdef OBJ_ELF
835 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
836#endif
c921be7d 837 struct literal_pool * next;
8335d6aa 838 unsigned int alignment;
3d0c9500 839} literal_pool;
b99bd4ef 840
3d0c9500
NC
841/* Pointer to a linked list of literal pools. */
842literal_pool * list_of_pools = NULL;
e27ec89e 843
2e6976a8
DG
844typedef enum asmfunc_states
845{
846 OUTSIDE_ASMFUNC,
847 WAITING_ASMFUNC_NAME,
848 WAITING_ENDASMFUNC
849} asmfunc_states;
850
851static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
852
e07e6e58
NC
853#ifdef OBJ_ELF
854# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
855#else
856static struct current_it now_it;
857#endif
858
859static inline int
860now_it_compatible (int cond)
861{
862 return (cond & ~1) == (now_it.cc & ~1);
863}
864
865static inline int
866conditional_insn (void)
867{
868 return inst.cond != COND_ALWAYS;
869}
870
871static int in_it_block (void);
872
873static int handle_it_state (void);
874
875static void force_automatic_it_block_close (void);
876
c921be7d
NC
877static void it_fsm_post_encode (void);
878
e07e6e58
NC
879#define set_it_insn_type(type) \
880 do \
881 { \
882 inst.it_insn_type = type; \
883 if (handle_it_state () == FAIL) \
477330fc 884 return; \
e07e6e58
NC
885 } \
886 while (0)
887
c921be7d
NC
888#define set_it_insn_type_nonvoid(type, failret) \
889 do \
890 { \
891 inst.it_insn_type = type; \
892 if (handle_it_state () == FAIL) \
477330fc 893 return failret; \
c921be7d
NC
894 } \
895 while(0)
896
e07e6e58
NC
897#define set_it_insn_type_last() \
898 do \
899 { \
900 if (inst.cond == COND_ALWAYS) \
477330fc 901 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 902 else \
477330fc 903 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
904 } \
905 while (0)
906
c19d1205 907/* Pure syntax. */
b99bd4ef 908
c19d1205
ZW
909/* This array holds the chars that always start a comment. If the
910 pre-processor is disabled, these aren't very useful. */
2e6976a8 911char arm_comment_chars[] = "@";
3d0c9500 912
c19d1205
ZW
913/* This array holds the chars that only start a comment at the beginning of
914 a line. If the line seems to have the form '# 123 filename'
915 .line and .file directives will appear in the pre-processed output. */
916/* Note that input_file.c hand checks for '#' at the beginning of the
917 first line of the input file. This is because the compiler outputs
918 #NO_APP at the beginning of its output. */
919/* Also note that comments like this one will always work. */
920const char line_comment_chars[] = "#";
3d0c9500 921
2e6976a8 922char arm_line_separator_chars[] = ";";
b99bd4ef 923
c19d1205
ZW
924/* Chars that can be used to separate mant
925 from exp in floating point numbers. */
926const char EXP_CHARS[] = "eE";
3d0c9500 927
c19d1205
ZW
928/* Chars that mean this number is a floating point constant. */
929/* As in 0f12.456 */
930/* or 0d1.2345e12 */
b99bd4ef 931
c19d1205 932const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 933
c19d1205
ZW
934/* Prefix characters that indicate the start of an immediate
935 value. */
936#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 937
c19d1205
ZW
938/* Separator character handling. */
939
940#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
941
942static inline int
943skip_past_char (char ** str, char c)
944{
8ab8155f
NC
945 /* PR gas/14987: Allow for whitespace before the expected character. */
946 skip_whitespace (*str);
427d0db6 947
c19d1205
ZW
948 if (**str == c)
949 {
950 (*str)++;
951 return SUCCESS;
3d0c9500 952 }
c19d1205
ZW
953 else
954 return FAIL;
955}
c921be7d 956
c19d1205 957#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 958
c19d1205
ZW
959/* Arithmetic expressions (possibly involving symbols). */
960
961/* Return TRUE if anything in the expression is a bignum. */
962
963static int
964walk_no_bignums (symbolS * sp)
965{
966 if (symbol_get_value_expression (sp)->X_op == O_big)
967 return 1;
968
969 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 970 {
c19d1205
ZW
971 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
972 || (symbol_get_value_expression (sp)->X_op_symbol
973 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
974 }
975
c19d1205 976 return 0;
3d0c9500
NC
977}
978
c19d1205
ZW
979static int in_my_get_expression = 0;
980
981/* Third argument to my_get_expression. */
982#define GE_NO_PREFIX 0
983#define GE_IMM_PREFIX 1
984#define GE_OPT_PREFIX 2
5287ad62
JB
985/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
986 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
987#define GE_OPT_PREFIX_BIG 3
a737bd4d 988
b99bd4ef 989static int
c19d1205 990my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 991{
c19d1205
ZW
992 char * save_in;
993 segT seg;
b99bd4ef 994
c19d1205
ZW
995 /* In unified syntax, all prefixes are optional. */
996 if (unified_syntax)
5287ad62 997 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 998 : GE_OPT_PREFIX;
b99bd4ef 999
c19d1205 1000 switch (prefix_mode)
b99bd4ef 1001 {
c19d1205
ZW
1002 case GE_NO_PREFIX: break;
1003 case GE_IMM_PREFIX:
1004 if (!is_immediate_prefix (**str))
1005 {
1006 inst.error = _("immediate expression requires a # prefix");
1007 return FAIL;
1008 }
1009 (*str)++;
1010 break;
1011 case GE_OPT_PREFIX:
5287ad62 1012 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1013 if (is_immediate_prefix (**str))
1014 (*str)++;
1015 break;
1016 default: abort ();
1017 }
b99bd4ef 1018
c19d1205 1019 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1020
c19d1205
ZW
1021 save_in = input_line_pointer;
1022 input_line_pointer = *str;
1023 in_my_get_expression = 1;
1024 seg = expression (ep);
1025 in_my_get_expression = 0;
1026
f86adc07 1027 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1028 {
f86adc07 1029 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1030 *str = input_line_pointer;
1031 input_line_pointer = save_in;
1032 if (inst.error == NULL)
f86adc07
NS
1033 inst.error = (ep->X_op == O_absent
1034 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1035 return 1;
1036 }
b99bd4ef 1037
c19d1205
ZW
1038#ifdef OBJ_AOUT
1039 if (seg != absolute_section
1040 && seg != text_section
1041 && seg != data_section
1042 && seg != bss_section
1043 && seg != undefined_section)
1044 {
1045 inst.error = _("bad segment");
1046 *str = input_line_pointer;
1047 input_line_pointer = save_in;
1048 return 1;
b99bd4ef 1049 }
87975d2a
AM
1050#else
1051 (void) seg;
c19d1205 1052#endif
b99bd4ef 1053
c19d1205
ZW
1054 /* Get rid of any bignums now, so that we don't generate an error for which
1055 we can't establish a line number later on. Big numbers are never valid
1056 in instructions, which is where this routine is always called. */
5287ad62
JB
1057 if (prefix_mode != GE_OPT_PREFIX_BIG
1058 && (ep->X_op == O_big
477330fc 1059 || (ep->X_add_symbol
5287ad62 1060 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1061 || (ep->X_op_symbol
5287ad62 1062 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1063 {
1064 inst.error = _("invalid constant");
1065 *str = input_line_pointer;
1066 input_line_pointer = save_in;
1067 return 1;
1068 }
b99bd4ef 1069
c19d1205
ZW
1070 *str = input_line_pointer;
1071 input_line_pointer = save_in;
1072 return 0;
b99bd4ef
NC
1073}
1074
c19d1205
ZW
1075/* Turn a string in input_line_pointer into a floating point constant
1076 of type TYPE, and store the appropriate bytes in *LITP. The number
1077 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1078 returned, or NULL on OK.
b99bd4ef 1079
c19d1205
ZW
1080 Note that fp constants aren't represent in the normal way on the ARM.
1081 In big endian mode, things are as expected. However, in little endian
1082 mode fp constants are big-endian word-wise, and little-endian byte-wise
1083 within the words. For example, (double) 1.1 in big endian mode is
1084 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1085 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1086
c19d1205 1087 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1088
6d4af3c2 1089const char *
c19d1205
ZW
1090md_atof (int type, char * litP, int * sizeP)
1091{
1092 int prec;
1093 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1094 char *t;
1095 int i;
b99bd4ef 1096
c19d1205
ZW
1097 switch (type)
1098 {
1099 case 'f':
1100 case 'F':
1101 case 's':
1102 case 'S':
1103 prec = 2;
1104 break;
b99bd4ef 1105
c19d1205
ZW
1106 case 'd':
1107 case 'D':
1108 case 'r':
1109 case 'R':
1110 prec = 4;
1111 break;
b99bd4ef 1112
c19d1205
ZW
1113 case 'x':
1114 case 'X':
499ac353 1115 prec = 5;
c19d1205 1116 break;
b99bd4ef 1117
c19d1205
ZW
1118 case 'p':
1119 case 'P':
499ac353 1120 prec = 5;
c19d1205 1121 break;
a737bd4d 1122
c19d1205
ZW
1123 default:
1124 *sizeP = 0;
499ac353 1125 return _("Unrecognized or unsupported floating point constant");
c19d1205 1126 }
b99bd4ef 1127
c19d1205
ZW
1128 t = atof_ieee (input_line_pointer, type, words);
1129 if (t)
1130 input_line_pointer = t;
499ac353 1131 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1132
c19d1205
ZW
1133 if (target_big_endian)
1134 {
1135 for (i = 0; i < prec; i++)
1136 {
499ac353
NC
1137 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1138 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1139 }
1140 }
1141 else
1142 {
e74cfd16 1143 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1144 for (i = prec - 1; i >= 0; i--)
1145 {
499ac353
NC
1146 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1147 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1148 }
1149 else
1150 /* For a 4 byte float the order of elements in `words' is 1 0.
1151 For an 8 byte float the order is 1 0 3 2. */
1152 for (i = 0; i < prec; i += 2)
1153 {
499ac353
NC
1154 md_number_to_chars (litP, (valueT) words[i + 1],
1155 sizeof (LITTLENUM_TYPE));
1156 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1157 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1158 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1159 }
1160 }
b99bd4ef 1161
499ac353 1162 return NULL;
c19d1205 1163}
b99bd4ef 1164
c19d1205
ZW
1165/* We handle all bad expressions here, so that we can report the faulty
1166 instruction in the error message. */
1167void
91d6fa6a 1168md_operand (expressionS * exp)
c19d1205
ZW
1169{
1170 if (in_my_get_expression)
91d6fa6a 1171 exp->X_op = O_illegal;
b99bd4ef
NC
1172}
1173
c19d1205 1174/* Immediate values. */
b99bd4ef 1175
c19d1205
ZW
1176/* Generic immediate-value read function for use in directives.
1177 Accepts anything that 'expression' can fold to a constant.
1178 *val receives the number. */
1179#ifdef OBJ_ELF
1180static int
1181immediate_for_directive (int *val)
b99bd4ef 1182{
c19d1205
ZW
1183 expressionS exp;
1184 exp.X_op = O_illegal;
b99bd4ef 1185
c19d1205
ZW
1186 if (is_immediate_prefix (*input_line_pointer))
1187 {
1188 input_line_pointer++;
1189 expression (&exp);
1190 }
b99bd4ef 1191
c19d1205
ZW
1192 if (exp.X_op != O_constant)
1193 {
1194 as_bad (_("expected #constant"));
1195 ignore_rest_of_line ();
1196 return FAIL;
1197 }
1198 *val = exp.X_add_number;
1199 return SUCCESS;
b99bd4ef 1200}
c19d1205 1201#endif
b99bd4ef 1202
c19d1205 1203/* Register parsing. */
b99bd4ef 1204
c19d1205
ZW
1205/* Generic register parser. CCP points to what should be the
1206 beginning of a register name. If it is indeed a valid register
1207 name, advance CCP over it and return the reg_entry structure;
1208 otherwise return NULL. Does not issue diagnostics. */
1209
1210static struct reg_entry *
1211arm_reg_parse_multi (char **ccp)
b99bd4ef 1212{
c19d1205
ZW
1213 char *start = *ccp;
1214 char *p;
1215 struct reg_entry *reg;
b99bd4ef 1216
477330fc
RM
1217 skip_whitespace (start);
1218
c19d1205
ZW
1219#ifdef REGISTER_PREFIX
1220 if (*start != REGISTER_PREFIX)
01cfc07f 1221 return NULL;
c19d1205
ZW
1222 start++;
1223#endif
1224#ifdef OPTIONAL_REGISTER_PREFIX
1225 if (*start == OPTIONAL_REGISTER_PREFIX)
1226 start++;
1227#endif
b99bd4ef 1228
c19d1205
ZW
1229 p = start;
1230 if (!ISALPHA (*p) || !is_name_beginner (*p))
1231 return NULL;
b99bd4ef 1232
c19d1205
ZW
1233 do
1234 p++;
1235 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1236
1237 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1238
1239 if (!reg)
1240 return NULL;
1241
1242 *ccp = p;
1243 return reg;
b99bd4ef
NC
1244}
1245
1246static int
dcbf9037 1247arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1248 enum arm_reg_type type)
b99bd4ef 1249{
c19d1205
ZW
1250 /* Alternative syntaxes are accepted for a few register classes. */
1251 switch (type)
1252 {
1253 case REG_TYPE_MVF:
1254 case REG_TYPE_MVD:
1255 case REG_TYPE_MVFX:
1256 case REG_TYPE_MVDX:
1257 /* Generic coprocessor register names are allowed for these. */
79134647 1258 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1259 return reg->number;
1260 break;
69b97547 1261
c19d1205
ZW
1262 case REG_TYPE_CP:
1263 /* For backward compatibility, a bare number is valid here. */
1264 {
1265 unsigned long processor = strtoul (start, ccp, 10);
1266 if (*ccp != start && processor <= 15)
1267 return processor;
1268 }
6057a28f 1269
c19d1205
ZW
1270 case REG_TYPE_MMXWC:
1271 /* WC includes WCG. ??? I'm not sure this is true for all
1272 instructions that take WC registers. */
79134647 1273 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1274 return reg->number;
6057a28f 1275 break;
c19d1205 1276
6057a28f 1277 default:
c19d1205 1278 break;
6057a28f
NC
1279 }
1280
dcbf9037
JB
1281 return FAIL;
1282}
1283
1284/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1285 return value is the register number or FAIL. */
1286
1287static int
1288arm_reg_parse (char **ccp, enum arm_reg_type type)
1289{
1290 char *start = *ccp;
1291 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1292 int ret;
1293
1294 /* Do not allow a scalar (reg+index) to parse as a register. */
1295 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1296 return FAIL;
1297
1298 if (reg && reg->type == type)
1299 return reg->number;
1300
1301 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1302 return ret;
1303
c19d1205
ZW
1304 *ccp = start;
1305 return FAIL;
1306}
69b97547 1307
dcbf9037
JB
1308/* Parse a Neon type specifier. *STR should point at the leading '.'
1309 character. Does no verification at this stage that the type fits the opcode
1310 properly. E.g.,
1311
1312 .i32.i32.s16
1313 .s32.f32
1314 .u16
1315
1316 Can all be legally parsed by this function.
1317
1318 Fills in neon_type struct pointer with parsed information, and updates STR
1319 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1320 type, FAIL if not. */
1321
1322static int
1323parse_neon_type (struct neon_type *type, char **str)
1324{
1325 char *ptr = *str;
1326
1327 if (type)
1328 type->elems = 0;
1329
1330 while (type->elems < NEON_MAX_TYPE_ELS)
1331 {
1332 enum neon_el_type thistype = NT_untyped;
1333 unsigned thissize = -1u;
1334
1335 if (*ptr != '.')
1336 break;
1337
1338 ptr++;
1339
1340 /* Just a size without an explicit type. */
1341 if (ISDIGIT (*ptr))
1342 goto parsesize;
1343
1344 switch (TOLOWER (*ptr))
1345 {
1346 case 'i': thistype = NT_integer; break;
1347 case 'f': thistype = NT_float; break;
1348 case 'p': thistype = NT_poly; break;
1349 case 's': thistype = NT_signed; break;
1350 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1351 case 'd':
1352 thistype = NT_float;
1353 thissize = 64;
1354 ptr++;
1355 goto done;
dcbf9037
JB
1356 default:
1357 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1358 return FAIL;
1359 }
1360
1361 ptr++;
1362
1363 /* .f is an abbreviation for .f32. */
1364 if (thistype == NT_float && !ISDIGIT (*ptr))
1365 thissize = 32;
1366 else
1367 {
1368 parsesize:
1369 thissize = strtoul (ptr, &ptr, 10);
1370
1371 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1372 && thissize != 64)
1373 {
1374 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1375 return FAIL;
1376 }
1377 }
1378
037e8744 1379 done:
dcbf9037 1380 if (type)
477330fc
RM
1381 {
1382 type->el[type->elems].type = thistype;
dcbf9037
JB
1383 type->el[type->elems].size = thissize;
1384 type->elems++;
1385 }
1386 }
1387
1388 /* Empty/missing type is not a successful parse. */
1389 if (type->elems == 0)
1390 return FAIL;
1391
1392 *str = ptr;
1393
1394 return SUCCESS;
1395}
1396
1397/* Errors may be set multiple times during parsing or bit encoding
1398 (particularly in the Neon bits), but usually the earliest error which is set
1399 will be the most meaningful. Avoid overwriting it with later (cascading)
1400 errors by calling this function. */
1401
1402static void
1403first_error (const char *err)
1404{
1405 if (!inst.error)
1406 inst.error = err;
1407}
1408
1409/* Parse a single type, e.g. ".s32", leading period included. */
1410static int
1411parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1412{
1413 char *str = *ccp;
1414 struct neon_type optype;
1415
1416 if (*str == '.')
1417 {
1418 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1419 {
1420 if (optype.elems == 1)
1421 *vectype = optype.el[0];
1422 else
1423 {
1424 first_error (_("only one type should be specified for operand"));
1425 return FAIL;
1426 }
1427 }
dcbf9037 1428 else
477330fc
RM
1429 {
1430 first_error (_("vector type expected"));
1431 return FAIL;
1432 }
dcbf9037
JB
1433 }
1434 else
1435 return FAIL;
5f4273c7 1436
dcbf9037 1437 *ccp = str;
5f4273c7 1438
dcbf9037
JB
1439 return SUCCESS;
1440}
1441
1442/* Special meanings for indices (which have a range of 0-7), which will fit into
1443 a 4-bit integer. */
1444
1445#define NEON_ALL_LANES 15
1446#define NEON_INTERLEAVE_LANES 14
1447
1448/* Parse either a register or a scalar, with an optional type. Return the
1449 register number, and optionally fill in the actual type of the register
1450 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1451 type/index information in *TYPEINFO. */
1452
1453static int
1454parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1455 enum arm_reg_type *rtype,
1456 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1457{
1458 char *str = *ccp;
1459 struct reg_entry *reg = arm_reg_parse_multi (&str);
1460 struct neon_typed_alias atype;
1461 struct neon_type_el parsetype;
1462
1463 atype.defined = 0;
1464 atype.index = -1;
1465 atype.eltype.type = NT_invtype;
1466 atype.eltype.size = -1;
1467
1468 /* Try alternate syntax for some types of register. Note these are mutually
1469 exclusive with the Neon syntax extensions. */
1470 if (reg == NULL)
1471 {
1472 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1473 if (altreg != FAIL)
477330fc 1474 *ccp = str;
dcbf9037 1475 if (typeinfo)
477330fc 1476 *typeinfo = atype;
dcbf9037
JB
1477 return altreg;
1478 }
1479
037e8744
JB
1480 /* Undo polymorphism when a set of register types may be accepted. */
1481 if ((type == REG_TYPE_NDQ
1482 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1483 || (type == REG_TYPE_VFSD
477330fc 1484 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1485 || (type == REG_TYPE_NSDQ
477330fc
RM
1486 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1487 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1488 || (type == REG_TYPE_MMXWC
1489 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1490 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1491
1492 if (type != reg->type)
1493 return FAIL;
1494
1495 if (reg->neon)
1496 atype = *reg->neon;
5f4273c7 1497
dcbf9037
JB
1498 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1499 {
1500 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1501 {
1502 first_error (_("can't redefine type for operand"));
1503 return FAIL;
1504 }
dcbf9037
JB
1505 atype.defined |= NTA_HASTYPE;
1506 atype.eltype = parsetype;
1507 }
5f4273c7 1508
dcbf9037
JB
1509 if (skip_past_char (&str, '[') == SUCCESS)
1510 {
1511 if (type != REG_TYPE_VFD)
477330fc
RM
1512 {
1513 first_error (_("only D registers may be indexed"));
1514 return FAIL;
1515 }
5f4273c7 1516
dcbf9037 1517 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1518 {
1519 first_error (_("can't change index for operand"));
1520 return FAIL;
1521 }
dcbf9037
JB
1522
1523 atype.defined |= NTA_HASINDEX;
1524
1525 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1526 atype.index = NEON_ALL_LANES;
dcbf9037 1527 else
477330fc
RM
1528 {
1529 expressionS exp;
dcbf9037 1530
477330fc 1531 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1532
477330fc
RM
1533 if (exp.X_op != O_constant)
1534 {
1535 first_error (_("constant expression required"));
1536 return FAIL;
1537 }
dcbf9037 1538
477330fc
RM
1539 if (skip_past_char (&str, ']') == FAIL)
1540 return FAIL;
dcbf9037 1541
477330fc
RM
1542 atype.index = exp.X_add_number;
1543 }
dcbf9037 1544 }
5f4273c7 1545
dcbf9037
JB
1546 if (typeinfo)
1547 *typeinfo = atype;
5f4273c7 1548
dcbf9037
JB
1549 if (rtype)
1550 *rtype = type;
5f4273c7 1551
dcbf9037 1552 *ccp = str;
5f4273c7 1553
dcbf9037
JB
1554 return reg->number;
1555}
1556
1557/* Like arm_reg_parse, but allow allow the following extra features:
1558 - If RTYPE is non-zero, return the (possibly restricted) type of the
1559 register (e.g. Neon double or quad reg when either has been requested).
1560 - If this is a Neon vector type with additional type information, fill
1561 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1562 This function will fault on encountering a scalar. */
dcbf9037
JB
1563
1564static int
1565arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1566 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1567{
1568 struct neon_typed_alias atype;
1569 char *str = *ccp;
1570 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1571
1572 if (reg == FAIL)
1573 return FAIL;
1574
0855e32b
NS
1575 /* Do not allow regname(... to parse as a register. */
1576 if (*str == '(')
1577 return FAIL;
1578
dcbf9037
JB
1579 /* Do not allow a scalar (reg+index) to parse as a register. */
1580 if ((atype.defined & NTA_HASINDEX) != 0)
1581 {
1582 first_error (_("register operand expected, but got scalar"));
1583 return FAIL;
1584 }
1585
1586 if (vectype)
1587 *vectype = atype.eltype;
1588
1589 *ccp = str;
1590
1591 return reg;
1592}
1593
1594#define NEON_SCALAR_REG(X) ((X) >> 4)
1595#define NEON_SCALAR_INDEX(X) ((X) & 15)
1596
5287ad62
JB
1597/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1598 have enough information to be able to do a good job bounds-checking. So, we
1599 just do easy checks here, and do further checks later. */
1600
1601static int
dcbf9037 1602parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1603{
dcbf9037 1604 int reg;
5287ad62 1605 char *str = *ccp;
dcbf9037 1606 struct neon_typed_alias atype;
5f4273c7 1607
dcbf9037 1608 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1609
dcbf9037 1610 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1611 return FAIL;
5f4273c7 1612
dcbf9037 1613 if (atype.index == NEON_ALL_LANES)
5287ad62 1614 {
dcbf9037 1615 first_error (_("scalar must have an index"));
5287ad62
JB
1616 return FAIL;
1617 }
dcbf9037 1618 else if (atype.index >= 64 / elsize)
5287ad62 1619 {
dcbf9037 1620 first_error (_("scalar index out of range"));
5287ad62
JB
1621 return FAIL;
1622 }
5f4273c7 1623
dcbf9037
JB
1624 if (type)
1625 *type = atype.eltype;
5f4273c7 1626
5287ad62 1627 *ccp = str;
5f4273c7 1628
dcbf9037 1629 return reg * 16 + atype.index;
5287ad62
JB
1630}
1631
c19d1205 1632/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1633
c19d1205
ZW
1634static long
1635parse_reg_list (char ** strp)
1636{
1637 char * str = * strp;
1638 long range = 0;
1639 int another_range;
a737bd4d 1640
c19d1205
ZW
1641 /* We come back here if we get ranges concatenated by '+' or '|'. */
1642 do
6057a28f 1643 {
477330fc
RM
1644 skip_whitespace (str);
1645
c19d1205 1646 another_range = 0;
a737bd4d 1647
c19d1205
ZW
1648 if (*str == '{')
1649 {
1650 int in_range = 0;
1651 int cur_reg = -1;
a737bd4d 1652
c19d1205
ZW
1653 str++;
1654 do
1655 {
1656 int reg;
6057a28f 1657
dcbf9037 1658 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1659 {
dcbf9037 1660 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1661 return FAIL;
1662 }
a737bd4d 1663
c19d1205
ZW
1664 if (in_range)
1665 {
1666 int i;
a737bd4d 1667
c19d1205
ZW
1668 if (reg <= cur_reg)
1669 {
dcbf9037 1670 first_error (_("bad range in register list"));
c19d1205
ZW
1671 return FAIL;
1672 }
40a18ebd 1673
c19d1205
ZW
1674 for (i = cur_reg + 1; i < reg; i++)
1675 {
1676 if (range & (1 << i))
1677 as_tsktsk
1678 (_("Warning: duplicated register (r%d) in register list"),
1679 i);
1680 else
1681 range |= 1 << i;
1682 }
1683 in_range = 0;
1684 }
a737bd4d 1685
c19d1205
ZW
1686 if (range & (1 << reg))
1687 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1688 reg);
1689 else if (reg <= cur_reg)
1690 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1691
c19d1205
ZW
1692 range |= 1 << reg;
1693 cur_reg = reg;
1694 }
1695 while (skip_past_comma (&str) != FAIL
1696 || (in_range = 1, *str++ == '-'));
1697 str--;
a737bd4d 1698
d996d970 1699 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1700 {
dcbf9037 1701 first_error (_("missing `}'"));
c19d1205
ZW
1702 return FAIL;
1703 }
1704 }
1705 else
1706 {
91d6fa6a 1707 expressionS exp;
40a18ebd 1708
91d6fa6a 1709 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1710 return FAIL;
40a18ebd 1711
91d6fa6a 1712 if (exp.X_op == O_constant)
c19d1205 1713 {
91d6fa6a
NC
1714 if (exp.X_add_number
1715 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1716 {
1717 inst.error = _("invalid register mask");
1718 return FAIL;
1719 }
a737bd4d 1720
91d6fa6a 1721 if ((range & exp.X_add_number) != 0)
c19d1205 1722 {
91d6fa6a 1723 int regno = range & exp.X_add_number;
a737bd4d 1724
c19d1205
ZW
1725 regno &= -regno;
1726 regno = (1 << regno) - 1;
1727 as_tsktsk
1728 (_("Warning: duplicated register (r%d) in register list"),
1729 regno);
1730 }
a737bd4d 1731
91d6fa6a 1732 range |= exp.X_add_number;
c19d1205
ZW
1733 }
1734 else
1735 {
1736 if (inst.reloc.type != 0)
1737 {
1738 inst.error = _("expression too complex");
1739 return FAIL;
1740 }
a737bd4d 1741
91d6fa6a 1742 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1743 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1744 inst.reloc.pc_rel = 0;
1745 }
1746 }
a737bd4d 1747
c19d1205
ZW
1748 if (*str == '|' || *str == '+')
1749 {
1750 str++;
1751 another_range = 1;
1752 }
a737bd4d 1753 }
c19d1205 1754 while (another_range);
a737bd4d 1755
c19d1205
ZW
1756 *strp = str;
1757 return range;
a737bd4d
NC
1758}
1759
5287ad62
JB
1760/* Types of registers in a list. */
1761
1762enum reg_list_els
1763{
1764 REGLIST_VFP_S,
1765 REGLIST_VFP_D,
1766 REGLIST_NEON_D
1767};
1768
c19d1205
ZW
1769/* Parse a VFP register list. If the string is invalid return FAIL.
1770 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1771 register. Parses registers of type ETYPE.
1772 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1773 - Q registers can be used to specify pairs of D registers
1774 - { } can be omitted from around a singleton register list
477330fc
RM
1775 FIXME: This is not implemented, as it would require backtracking in
1776 some cases, e.g.:
1777 vtbl.8 d3,d4,d5
1778 This could be done (the meaning isn't really ambiguous), but doesn't
1779 fit in well with the current parsing framework.
dcbf9037
JB
1780 - 32 D registers may be used (also true for VFPv3).
1781 FIXME: Types are ignored in these register lists, which is probably a
1782 bug. */
6057a28f 1783
c19d1205 1784static int
037e8744 1785parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1786{
037e8744 1787 char *str = *ccp;
c19d1205
ZW
1788 int base_reg;
1789 int new_base;
21d799b5 1790 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1791 int max_regs = 0;
c19d1205
ZW
1792 int count = 0;
1793 int warned = 0;
1794 unsigned long mask = 0;
a737bd4d 1795 int i;
6057a28f 1796
477330fc 1797 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1798 {
1799 inst.error = _("expecting {");
1800 return FAIL;
1801 }
6057a28f 1802
5287ad62 1803 switch (etype)
c19d1205 1804 {
5287ad62 1805 case REGLIST_VFP_S:
c19d1205
ZW
1806 regtype = REG_TYPE_VFS;
1807 max_regs = 32;
5287ad62 1808 break;
5f4273c7 1809
5287ad62
JB
1810 case REGLIST_VFP_D:
1811 regtype = REG_TYPE_VFD;
b7fc2769 1812 break;
5f4273c7 1813
b7fc2769
JB
1814 case REGLIST_NEON_D:
1815 regtype = REG_TYPE_NDQ;
1816 break;
1817 }
1818
1819 if (etype != REGLIST_VFP_S)
1820 {
b1cc4aeb
PB
1821 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1822 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1823 {
1824 max_regs = 32;
1825 if (thumb_mode)
1826 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1827 fpu_vfp_ext_d32);
1828 else
1829 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1830 fpu_vfp_ext_d32);
1831 }
5287ad62 1832 else
477330fc 1833 max_regs = 16;
c19d1205 1834 }
6057a28f 1835
c19d1205 1836 base_reg = max_regs;
a737bd4d 1837
c19d1205
ZW
1838 do
1839 {
5287ad62 1840 int setmask = 1, addregs = 1;
dcbf9037 1841
037e8744 1842 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1843
c19d1205 1844 if (new_base == FAIL)
a737bd4d 1845 {
dcbf9037 1846 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1847 return FAIL;
1848 }
5f4273c7 1849
b7fc2769 1850 if (new_base >= max_regs)
477330fc
RM
1851 {
1852 first_error (_("register out of range in list"));
1853 return FAIL;
1854 }
5f4273c7 1855
5287ad62
JB
1856 /* Note: a value of 2 * n is returned for the register Q<n>. */
1857 if (regtype == REG_TYPE_NQ)
477330fc
RM
1858 {
1859 setmask = 3;
1860 addregs = 2;
1861 }
5287ad62 1862
c19d1205
ZW
1863 if (new_base < base_reg)
1864 base_reg = new_base;
a737bd4d 1865
5287ad62 1866 if (mask & (setmask << new_base))
c19d1205 1867 {
dcbf9037 1868 first_error (_("invalid register list"));
c19d1205 1869 return FAIL;
a737bd4d 1870 }
a737bd4d 1871
c19d1205
ZW
1872 if ((mask >> new_base) != 0 && ! warned)
1873 {
1874 as_tsktsk (_("register list not in ascending order"));
1875 warned = 1;
1876 }
0bbf2aa4 1877
5287ad62
JB
1878 mask |= setmask << new_base;
1879 count += addregs;
0bbf2aa4 1880
037e8744 1881 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1882 {
1883 int high_range;
0bbf2aa4 1884
037e8744 1885 str++;
0bbf2aa4 1886
037e8744 1887 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1888 == FAIL)
c19d1205
ZW
1889 {
1890 inst.error = gettext (reg_expected_msgs[regtype]);
1891 return FAIL;
1892 }
0bbf2aa4 1893
477330fc
RM
1894 if (high_range >= max_regs)
1895 {
1896 first_error (_("register out of range in list"));
1897 return FAIL;
1898 }
b7fc2769 1899
477330fc
RM
1900 if (regtype == REG_TYPE_NQ)
1901 high_range = high_range + 1;
5287ad62 1902
c19d1205
ZW
1903 if (high_range <= new_base)
1904 {
1905 inst.error = _("register range not in ascending order");
1906 return FAIL;
1907 }
0bbf2aa4 1908
5287ad62 1909 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1910 {
5287ad62 1911 if (mask & (setmask << new_base))
0bbf2aa4 1912 {
c19d1205
ZW
1913 inst.error = _("invalid register list");
1914 return FAIL;
0bbf2aa4 1915 }
c19d1205 1916
5287ad62
JB
1917 mask |= setmask << new_base;
1918 count += addregs;
0bbf2aa4 1919 }
0bbf2aa4 1920 }
0bbf2aa4 1921 }
037e8744 1922 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1923
037e8744 1924 str++;
0bbf2aa4 1925
c19d1205
ZW
1926 /* Sanity check -- should have raised a parse error above. */
1927 if (count == 0 || count > max_regs)
1928 abort ();
1929
1930 *pbase = base_reg;
1931
1932 /* Final test -- the registers must be consecutive. */
1933 mask >>= base_reg;
1934 for (i = 0; i < count; i++)
1935 {
1936 if ((mask & (1u << i)) == 0)
1937 {
1938 inst.error = _("non-contiguous register range");
1939 return FAIL;
1940 }
1941 }
1942
037e8744
JB
1943 *ccp = str;
1944
c19d1205 1945 return count;
b99bd4ef
NC
1946}
1947
dcbf9037
JB
1948/* True if two alias types are the same. */
1949
c921be7d 1950static bfd_boolean
dcbf9037
JB
1951neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1952{
1953 if (!a && !b)
c921be7d 1954 return TRUE;
5f4273c7 1955
dcbf9037 1956 if (!a || !b)
c921be7d 1957 return FALSE;
dcbf9037
JB
1958
1959 if (a->defined != b->defined)
c921be7d 1960 return FALSE;
5f4273c7 1961
dcbf9037
JB
1962 if ((a->defined & NTA_HASTYPE) != 0
1963 && (a->eltype.type != b->eltype.type
477330fc 1964 || a->eltype.size != b->eltype.size))
c921be7d 1965 return FALSE;
dcbf9037
JB
1966
1967 if ((a->defined & NTA_HASINDEX) != 0
1968 && (a->index != b->index))
c921be7d 1969 return FALSE;
5f4273c7 1970
c921be7d 1971 return TRUE;
dcbf9037
JB
1972}
1973
5287ad62
JB
1974/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1975 The base register is put in *PBASE.
dcbf9037 1976 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1977 the return value.
1978 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1979 Bits [6:5] encode the list length (minus one).
1980 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1981
5287ad62 1982#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1983#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1984#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1985
1986static int
dcbf9037 1987parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1988 struct neon_type_el *eltype)
5287ad62
JB
1989{
1990 char *ptr = *str;
1991 int base_reg = -1;
1992 int reg_incr = -1;
1993 int count = 0;
1994 int lane = -1;
1995 int leading_brace = 0;
1996 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1997 const char *const incr_error = _("register stride must be 1 or 2");
1998 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1999 struct neon_typed_alias firsttype;
f85d59c3
KT
2000 firsttype.defined = 0;
2001 firsttype.eltype.type = NT_invtype;
2002 firsttype.eltype.size = -1;
2003 firsttype.index = -1;
5f4273c7 2004
5287ad62
JB
2005 if (skip_past_char (&ptr, '{') == SUCCESS)
2006 leading_brace = 1;
5f4273c7 2007
5287ad62
JB
2008 do
2009 {
dcbf9037
JB
2010 struct neon_typed_alias atype;
2011 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2012
5287ad62 2013 if (getreg == FAIL)
477330fc
RM
2014 {
2015 first_error (_(reg_expected_msgs[rtype]));
2016 return FAIL;
2017 }
5f4273c7 2018
5287ad62 2019 if (base_reg == -1)
477330fc
RM
2020 {
2021 base_reg = getreg;
2022 if (rtype == REG_TYPE_NQ)
2023 {
2024 reg_incr = 1;
2025 }
2026 firsttype = atype;
2027 }
5287ad62 2028 else if (reg_incr == -1)
477330fc
RM
2029 {
2030 reg_incr = getreg - base_reg;
2031 if (reg_incr < 1 || reg_incr > 2)
2032 {
2033 first_error (_(incr_error));
2034 return FAIL;
2035 }
2036 }
5287ad62 2037 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2038 {
2039 first_error (_(incr_error));
2040 return FAIL;
2041 }
dcbf9037 2042
c921be7d 2043 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2044 {
2045 first_error (_(type_error));
2046 return FAIL;
2047 }
5f4273c7 2048
5287ad62 2049 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2050 modes. */
5287ad62 2051 if (ptr[0] == '-')
477330fc
RM
2052 {
2053 struct neon_typed_alias htype;
2054 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2055 if (lane == -1)
2056 lane = NEON_INTERLEAVE_LANES;
2057 else if (lane != NEON_INTERLEAVE_LANES)
2058 {
2059 first_error (_(type_error));
2060 return FAIL;
2061 }
2062 if (reg_incr == -1)
2063 reg_incr = 1;
2064 else if (reg_incr != 1)
2065 {
2066 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2067 return FAIL;
2068 }
2069 ptr++;
2070 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2071 if (hireg == FAIL)
2072 {
2073 first_error (_(reg_expected_msgs[rtype]));
2074 return FAIL;
2075 }
2076 if (! neon_alias_types_same (&htype, &firsttype))
2077 {
2078 first_error (_(type_error));
2079 return FAIL;
2080 }
2081 count += hireg + dregs - getreg;
2082 continue;
2083 }
5f4273c7 2084
5287ad62
JB
2085 /* If we're using Q registers, we can't use [] or [n] syntax. */
2086 if (rtype == REG_TYPE_NQ)
477330fc
RM
2087 {
2088 count += 2;
2089 continue;
2090 }
5f4273c7 2091
dcbf9037 2092 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2093 {
2094 if (lane == -1)
2095 lane = atype.index;
2096 else if (lane != atype.index)
2097 {
2098 first_error (_(type_error));
2099 return FAIL;
2100 }
2101 }
5287ad62 2102 else if (lane == -1)
477330fc 2103 lane = NEON_INTERLEAVE_LANES;
5287ad62 2104 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2105 {
2106 first_error (_(type_error));
2107 return FAIL;
2108 }
5287ad62
JB
2109 count++;
2110 }
2111 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2112
5287ad62
JB
2113 /* No lane set by [x]. We must be interleaving structures. */
2114 if (lane == -1)
2115 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2116
5287ad62
JB
2117 /* Sanity check. */
2118 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2119 || (count > 1 && reg_incr == -1))
2120 {
dcbf9037 2121 first_error (_("error parsing element/structure list"));
5287ad62
JB
2122 return FAIL;
2123 }
2124
2125 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2126 {
dcbf9037 2127 first_error (_("expected }"));
5287ad62
JB
2128 return FAIL;
2129 }
5f4273c7 2130
5287ad62
JB
2131 if (reg_incr == -1)
2132 reg_incr = 1;
2133
dcbf9037
JB
2134 if (eltype)
2135 *eltype = firsttype.eltype;
2136
5287ad62
JB
2137 *pbase = base_reg;
2138 *str = ptr;
5f4273c7 2139
5287ad62
JB
2140 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2141}
2142
c19d1205
ZW
2143/* Parse an explicit relocation suffix on an expression. This is
2144 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2145 arm_reloc_hsh contains no entries, so this function can only
2146 succeed if there is no () after the word. Returns -1 on error,
2147 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2148
c19d1205
ZW
2149static int
2150parse_reloc (char **str)
b99bd4ef 2151{
c19d1205
ZW
2152 struct reloc_entry *r;
2153 char *p, *q;
b99bd4ef 2154
c19d1205
ZW
2155 if (**str != '(')
2156 return BFD_RELOC_UNUSED;
b99bd4ef 2157
c19d1205
ZW
2158 p = *str + 1;
2159 q = p;
2160
2161 while (*q && *q != ')' && *q != ',')
2162 q++;
2163 if (*q != ')')
2164 return -1;
2165
21d799b5
NC
2166 if ((r = (struct reloc_entry *)
2167 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2168 return -1;
2169
2170 *str = q + 1;
2171 return r->reloc;
b99bd4ef
NC
2172}
2173
c19d1205
ZW
2174/* Directives: register aliases. */
2175
dcbf9037 2176static struct reg_entry *
90ec0d68 2177insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2178{
d3ce72d0 2179 struct reg_entry *new_reg;
c19d1205 2180 const char *name;
b99bd4ef 2181
d3ce72d0 2182 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2183 {
d3ce72d0 2184 if (new_reg->builtin)
c19d1205 2185 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2186
c19d1205
ZW
2187 /* Only warn about a redefinition if it's not defined as the
2188 same register. */
d3ce72d0 2189 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2190 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2191
d929913e 2192 return NULL;
c19d1205 2193 }
b99bd4ef 2194
c19d1205 2195 name = xstrdup (str);
325801bd 2196 new_reg = XNEW (struct reg_entry);
b99bd4ef 2197
d3ce72d0
NC
2198 new_reg->name = name;
2199 new_reg->number = number;
2200 new_reg->type = type;
2201 new_reg->builtin = FALSE;
2202 new_reg->neon = NULL;
b99bd4ef 2203
d3ce72d0 2204 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2205 abort ();
5f4273c7 2206
d3ce72d0 2207 return new_reg;
dcbf9037
JB
2208}
2209
2210static void
2211insert_neon_reg_alias (char *str, int number, int type,
477330fc 2212 struct neon_typed_alias *atype)
dcbf9037
JB
2213{
2214 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2215
dcbf9037
JB
2216 if (!reg)
2217 {
2218 first_error (_("attempt to redefine typed alias"));
2219 return;
2220 }
5f4273c7 2221
dcbf9037
JB
2222 if (atype)
2223 {
325801bd 2224 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2225 *reg->neon = *atype;
2226 }
c19d1205 2227}
b99bd4ef 2228
c19d1205 2229/* Look for the .req directive. This is of the form:
b99bd4ef 2230
c19d1205 2231 new_register_name .req existing_register_name
b99bd4ef 2232
c19d1205 2233 If we find one, or if it looks sufficiently like one that we want to
d929913e 2234 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2235
d929913e 2236static bfd_boolean
c19d1205
ZW
2237create_register_alias (char * newname, char *p)
2238{
2239 struct reg_entry *old;
2240 char *oldname, *nbuf;
2241 size_t nlen;
b99bd4ef 2242
c19d1205
ZW
2243 /* The input scrubber ensures that whitespace after the mnemonic is
2244 collapsed to single spaces. */
2245 oldname = p;
2246 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2247 return FALSE;
b99bd4ef 2248
c19d1205
ZW
2249 oldname += 6;
2250 if (*oldname == '\0')
d929913e 2251 return FALSE;
b99bd4ef 2252
21d799b5 2253 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2254 if (!old)
b99bd4ef 2255 {
c19d1205 2256 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2257 return TRUE;
b99bd4ef
NC
2258 }
2259
c19d1205
ZW
2260 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2261 the desired alias name, and p points to its end. If not, then
2262 the desired alias name is in the global original_case_string. */
2263#ifdef TC_CASE_SENSITIVE
2264 nlen = p - newname;
2265#else
2266 newname = original_case_string;
2267 nlen = strlen (newname);
2268#endif
b99bd4ef 2269
e1fa0163 2270 nbuf = xmalloc (nlen + 1);
c19d1205
ZW
2271 memcpy (nbuf, newname, nlen);
2272 nbuf[nlen] = '\0';
b99bd4ef 2273
c19d1205
ZW
2274 /* Create aliases under the new name as stated; an all-lowercase
2275 version of the new name; and an all-uppercase version of the new
2276 name. */
d929913e
NC
2277 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2278 {
2279 for (p = nbuf; *p; p++)
2280 *p = TOUPPER (*p);
c19d1205 2281
d929913e
NC
2282 if (strncmp (nbuf, newname, nlen))
2283 {
2284 /* If this attempt to create an additional alias fails, do not bother
2285 trying to create the all-lower case alias. We will fail and issue
2286 a second, duplicate error message. This situation arises when the
2287 programmer does something like:
2288 foo .req r0
2289 Foo .req r1
2290 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2291 the artificial FOO alias because it has already been created by the
d929913e
NC
2292 first .req. */
2293 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2294 {
2295 free (nbuf);
2296 return TRUE;
2297 }
d929913e 2298 }
c19d1205 2299
d929913e
NC
2300 for (p = nbuf; *p; p++)
2301 *p = TOLOWER (*p);
c19d1205 2302
d929913e
NC
2303 if (strncmp (nbuf, newname, nlen))
2304 insert_reg_alias (nbuf, old->number, old->type);
2305 }
c19d1205 2306
e1fa0163 2307 free (nbuf);
d929913e 2308 return TRUE;
b99bd4ef
NC
2309}
2310
dcbf9037
JB
2311/* Create a Neon typed/indexed register alias using directives, e.g.:
2312 X .dn d5.s32[1]
2313 Y .qn 6.s16
2314 Z .dn d7
2315 T .dn Z[0]
2316 These typed registers can be used instead of the types specified after the
2317 Neon mnemonic, so long as all operands given have types. Types can also be
2318 specified directly, e.g.:
5f4273c7 2319 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2320
c921be7d 2321static bfd_boolean
dcbf9037
JB
2322create_neon_reg_alias (char *newname, char *p)
2323{
2324 enum arm_reg_type basetype;
2325 struct reg_entry *basereg;
2326 struct reg_entry mybasereg;
2327 struct neon_type ntype;
2328 struct neon_typed_alias typeinfo;
12d6b0b7 2329 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2330 int namelen;
5f4273c7 2331
dcbf9037
JB
2332 typeinfo.defined = 0;
2333 typeinfo.eltype.type = NT_invtype;
2334 typeinfo.eltype.size = -1;
2335 typeinfo.index = -1;
5f4273c7 2336
dcbf9037 2337 nameend = p;
5f4273c7 2338
dcbf9037
JB
2339 if (strncmp (p, " .dn ", 5) == 0)
2340 basetype = REG_TYPE_VFD;
2341 else if (strncmp (p, " .qn ", 5) == 0)
2342 basetype = REG_TYPE_NQ;
2343 else
c921be7d 2344 return FALSE;
5f4273c7 2345
dcbf9037 2346 p += 5;
5f4273c7 2347
dcbf9037 2348 if (*p == '\0')
c921be7d 2349 return FALSE;
5f4273c7 2350
dcbf9037
JB
2351 basereg = arm_reg_parse_multi (&p);
2352
2353 if (basereg && basereg->type != basetype)
2354 {
2355 as_bad (_("bad type for register"));
c921be7d 2356 return FALSE;
dcbf9037
JB
2357 }
2358
2359 if (basereg == NULL)
2360 {
2361 expressionS exp;
2362 /* Try parsing as an integer. */
2363 my_get_expression (&exp, &p, GE_NO_PREFIX);
2364 if (exp.X_op != O_constant)
477330fc
RM
2365 {
2366 as_bad (_("expression must be constant"));
2367 return FALSE;
2368 }
dcbf9037
JB
2369 basereg = &mybasereg;
2370 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2371 : exp.X_add_number;
dcbf9037
JB
2372 basereg->neon = 0;
2373 }
2374
2375 if (basereg->neon)
2376 typeinfo = *basereg->neon;
2377
2378 if (parse_neon_type (&ntype, &p) == SUCCESS)
2379 {
2380 /* We got a type. */
2381 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2382 {
2383 as_bad (_("can't redefine the type of a register alias"));
2384 return FALSE;
2385 }
5f4273c7 2386
dcbf9037
JB
2387 typeinfo.defined |= NTA_HASTYPE;
2388 if (ntype.elems != 1)
477330fc
RM
2389 {
2390 as_bad (_("you must specify a single type only"));
2391 return FALSE;
2392 }
dcbf9037
JB
2393 typeinfo.eltype = ntype.el[0];
2394 }
5f4273c7 2395
dcbf9037
JB
2396 if (skip_past_char (&p, '[') == SUCCESS)
2397 {
2398 expressionS exp;
2399 /* We got a scalar index. */
5f4273c7 2400
dcbf9037 2401 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2402 {
2403 as_bad (_("can't redefine the index of a scalar alias"));
2404 return FALSE;
2405 }
5f4273c7 2406
dcbf9037 2407 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2408
dcbf9037 2409 if (exp.X_op != O_constant)
477330fc
RM
2410 {
2411 as_bad (_("scalar index must be constant"));
2412 return FALSE;
2413 }
5f4273c7 2414
dcbf9037
JB
2415 typeinfo.defined |= NTA_HASINDEX;
2416 typeinfo.index = exp.X_add_number;
5f4273c7 2417
dcbf9037 2418 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2419 {
2420 as_bad (_("expecting ]"));
2421 return FALSE;
2422 }
dcbf9037
JB
2423 }
2424
15735687
NS
2425 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2426 the desired alias name, and p points to its end. If not, then
2427 the desired alias name is in the global original_case_string. */
2428#ifdef TC_CASE_SENSITIVE
dcbf9037 2429 namelen = nameend - newname;
15735687
NS
2430#else
2431 newname = original_case_string;
2432 namelen = strlen (newname);
2433#endif
2434
e1fa0163 2435 namebuf = xmalloc (namelen + 1);
dcbf9037
JB
2436 strncpy (namebuf, newname, namelen);
2437 namebuf[namelen] = '\0';
5f4273c7 2438
dcbf9037 2439 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2440 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2441
dcbf9037
JB
2442 /* Insert name in all uppercase. */
2443 for (p = namebuf; *p; p++)
2444 *p = TOUPPER (*p);
5f4273c7 2445
dcbf9037
JB
2446 if (strncmp (namebuf, newname, namelen))
2447 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2448 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2449
dcbf9037
JB
2450 /* Insert name in all lowercase. */
2451 for (p = namebuf; *p; p++)
2452 *p = TOLOWER (*p);
5f4273c7 2453
dcbf9037
JB
2454 if (strncmp (namebuf, newname, namelen))
2455 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2456 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2457
e1fa0163 2458 free (namebuf);
c921be7d 2459 return TRUE;
dcbf9037
JB
2460}
2461
c19d1205
ZW
2462/* Should never be called, as .req goes between the alias and the
2463 register name, not at the beginning of the line. */
c921be7d 2464
b99bd4ef 2465static void
c19d1205 2466s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2467{
c19d1205
ZW
2468 as_bad (_("invalid syntax for .req directive"));
2469}
b99bd4ef 2470
dcbf9037
JB
2471static void
2472s_dn (int a ATTRIBUTE_UNUSED)
2473{
2474 as_bad (_("invalid syntax for .dn directive"));
2475}
2476
2477static void
2478s_qn (int a ATTRIBUTE_UNUSED)
2479{
2480 as_bad (_("invalid syntax for .qn directive"));
2481}
2482
c19d1205
ZW
2483/* The .unreq directive deletes an alias which was previously defined
2484 by .req. For example:
b99bd4ef 2485
c19d1205
ZW
2486 my_alias .req r11
2487 .unreq my_alias */
b99bd4ef
NC
2488
2489static void
c19d1205 2490s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2491{
c19d1205
ZW
2492 char * name;
2493 char saved_char;
b99bd4ef 2494
c19d1205
ZW
2495 name = input_line_pointer;
2496
2497 while (*input_line_pointer != 0
2498 && *input_line_pointer != ' '
2499 && *input_line_pointer != '\n')
2500 ++input_line_pointer;
2501
2502 saved_char = *input_line_pointer;
2503 *input_line_pointer = 0;
2504
2505 if (!*name)
2506 as_bad (_("invalid syntax for .unreq directive"));
2507 else
2508 {
21d799b5 2509 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2510 name);
c19d1205
ZW
2511
2512 if (!reg)
2513 as_bad (_("unknown register alias '%s'"), name);
2514 else if (reg->builtin)
a1727c1a 2515 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2516 name);
2517 else
2518 {
d929913e
NC
2519 char * p;
2520 char * nbuf;
2521
db0bc284 2522 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2523 free ((char *) reg->name);
477330fc
RM
2524 if (reg->neon)
2525 free (reg->neon);
c19d1205 2526 free (reg);
d929913e
NC
2527
2528 /* Also locate the all upper case and all lower case versions.
2529 Do not complain if we cannot find one or the other as it
2530 was probably deleted above. */
5f4273c7 2531
d929913e
NC
2532 nbuf = strdup (name);
2533 for (p = nbuf; *p; p++)
2534 *p = TOUPPER (*p);
21d799b5 2535 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2536 if (reg)
2537 {
db0bc284 2538 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2539 free ((char *) reg->name);
2540 if (reg->neon)
2541 free (reg->neon);
2542 free (reg);
2543 }
2544
2545 for (p = nbuf; *p; p++)
2546 *p = TOLOWER (*p);
21d799b5 2547 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2548 if (reg)
2549 {
db0bc284 2550 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2551 free ((char *) reg->name);
2552 if (reg->neon)
2553 free (reg->neon);
2554 free (reg);
2555 }
2556
2557 free (nbuf);
c19d1205
ZW
2558 }
2559 }
b99bd4ef 2560
c19d1205 2561 *input_line_pointer = saved_char;
b99bd4ef
NC
2562 demand_empty_rest_of_line ();
2563}
2564
c19d1205
ZW
2565/* Directives: Instruction set selection. */
2566
2567#ifdef OBJ_ELF
2568/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2569 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2570 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2571 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2572
cd000bff
DJ
2573/* Create a new mapping symbol for the transition to STATE. */
2574
2575static void
2576make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2577{
a737bd4d 2578 symbolS * symbolP;
c19d1205
ZW
2579 const char * symname;
2580 int type;
b99bd4ef 2581
c19d1205 2582 switch (state)
b99bd4ef 2583 {
c19d1205
ZW
2584 case MAP_DATA:
2585 symname = "$d";
2586 type = BSF_NO_FLAGS;
2587 break;
2588 case MAP_ARM:
2589 symname = "$a";
2590 type = BSF_NO_FLAGS;
2591 break;
2592 case MAP_THUMB:
2593 symname = "$t";
2594 type = BSF_NO_FLAGS;
2595 break;
c19d1205
ZW
2596 default:
2597 abort ();
2598 }
2599
cd000bff 2600 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2601 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2602
2603 switch (state)
2604 {
2605 case MAP_ARM:
2606 THUMB_SET_FUNC (symbolP, 0);
2607 ARM_SET_THUMB (symbolP, 0);
2608 ARM_SET_INTERWORK (symbolP, support_interwork);
2609 break;
2610
2611 case MAP_THUMB:
2612 THUMB_SET_FUNC (symbolP, 1);
2613 ARM_SET_THUMB (symbolP, 1);
2614 ARM_SET_INTERWORK (symbolP, support_interwork);
2615 break;
2616
2617 case MAP_DATA:
2618 default:
cd000bff
DJ
2619 break;
2620 }
2621
2622 /* Save the mapping symbols for future reference. Also check that
2623 we do not place two mapping symbols at the same offset within a
2624 frag. We'll handle overlap between frags in
2de7820f
JZ
2625 check_mapping_symbols.
2626
2627 If .fill or other data filling directive generates zero sized data,
2628 the mapping symbol for the following code will have the same value
2629 as the one generated for the data filling directive. In this case,
2630 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2631 if (value == 0)
2632 {
2de7820f
JZ
2633 if (frag->tc_frag_data.first_map != NULL)
2634 {
2635 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2636 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2637 }
cd000bff
DJ
2638 frag->tc_frag_data.first_map = symbolP;
2639 }
2640 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2641 {
2642 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2643 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2644 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2645 }
cd000bff
DJ
2646 frag->tc_frag_data.last_map = symbolP;
2647}
2648
2649/* We must sometimes convert a region marked as code to data during
2650 code alignment, if an odd number of bytes have to be padded. The
2651 code mapping symbol is pushed to an aligned address. */
2652
2653static void
2654insert_data_mapping_symbol (enum mstate state,
2655 valueT value, fragS *frag, offsetT bytes)
2656{
2657 /* If there was already a mapping symbol, remove it. */
2658 if (frag->tc_frag_data.last_map != NULL
2659 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2660 {
2661 symbolS *symp = frag->tc_frag_data.last_map;
2662
2663 if (value == 0)
2664 {
2665 know (frag->tc_frag_data.first_map == symp);
2666 frag->tc_frag_data.first_map = NULL;
2667 }
2668 frag->tc_frag_data.last_map = NULL;
2669 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2670 }
cd000bff
DJ
2671
2672 make_mapping_symbol (MAP_DATA, value, frag);
2673 make_mapping_symbol (state, value + bytes, frag);
2674}
2675
2676static void mapping_state_2 (enum mstate state, int max_chars);
2677
2678/* Set the mapping state to STATE. Only call this when about to
2679 emit some STATE bytes to the file. */
2680
4e9aaefb 2681#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2682void
2683mapping_state (enum mstate state)
2684{
940b5ce0
DJ
2685 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2686
cd000bff
DJ
2687 if (mapstate == state)
2688 /* The mapping symbol has already been emitted.
2689 There is nothing else to do. */
2690 return;
49c62a33
NC
2691
2692 if (state == MAP_ARM || state == MAP_THUMB)
2693 /* PR gas/12931
2694 All ARM instructions require 4-byte alignment.
2695 (Almost) all Thumb instructions require 2-byte alignment.
2696
2697 When emitting instructions into any section, mark the section
2698 appropriately.
2699
2700 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2701 but themselves require 2-byte alignment; this applies to some
2702 PC- relative forms. However, these cases will invovle implicit
2703 literal pool generation or an explicit .align >=2, both of
2704 which will cause the section to me marked with sufficient
2705 alignment. Thus, we don't handle those cases here. */
2706 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2707
2708 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2709 /* This case will be evaluated later. */
cd000bff 2710 return;
cd000bff
DJ
2711
2712 mapping_state_2 (state, 0);
cd000bff
DJ
2713}
2714
2715/* Same as mapping_state, but MAX_CHARS bytes have already been
2716 allocated. Put the mapping symbol that far back. */
2717
2718static void
2719mapping_state_2 (enum mstate state, int max_chars)
2720{
940b5ce0
DJ
2721 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2722
2723 if (!SEG_NORMAL (now_seg))
2724 return;
2725
cd000bff
DJ
2726 if (mapstate == state)
2727 /* The mapping symbol has already been emitted.
2728 There is nothing else to do. */
2729 return;
2730
4e9aaefb
SA
2731 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2732 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2733 {
2734 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2735 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2736
2737 if (add_symbol)
2738 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2739 }
2740
cd000bff
DJ
2741 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2742 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2743}
4e9aaefb 2744#undef TRANSITION
c19d1205 2745#else
d3106081
NS
2746#define mapping_state(x) ((void)0)
2747#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2748#endif
2749
2750/* Find the real, Thumb encoded start of a Thumb function. */
2751
4343666d 2752#ifdef OBJ_COFF
c19d1205
ZW
2753static symbolS *
2754find_real_start (symbolS * symbolP)
2755{
2756 char * real_start;
2757 const char * name = S_GET_NAME (symbolP);
2758 symbolS * new_target;
2759
2760 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2761#define STUB_NAME ".real_start_of"
2762
2763 if (name == NULL)
2764 abort ();
2765
37f6032b
ZW
2766 /* The compiler may generate BL instructions to local labels because
2767 it needs to perform a branch to a far away location. These labels
2768 do not have a corresponding ".real_start_of" label. We check
2769 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2770 the ".real_start_of" convention for nonlocal branches. */
2771 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2772 return symbolP;
2773
e1fa0163 2774 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2775 new_target = symbol_find (real_start);
e1fa0163 2776 free (real_start);
c19d1205
ZW
2777
2778 if (new_target == NULL)
2779 {
bd3ba5d1 2780 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2781 new_target = symbolP;
2782 }
2783
c19d1205
ZW
2784 return new_target;
2785}
4343666d 2786#endif
c19d1205
ZW
2787
2788static void
2789opcode_select (int width)
2790{
2791 switch (width)
2792 {
2793 case 16:
2794 if (! thumb_mode)
2795 {
e74cfd16 2796 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2797 as_bad (_("selected processor does not support THUMB opcodes"));
2798
2799 thumb_mode = 1;
2800 /* No need to force the alignment, since we will have been
2801 coming from ARM mode, which is word-aligned. */
2802 record_alignment (now_seg, 1);
2803 }
c19d1205
ZW
2804 break;
2805
2806 case 32:
2807 if (thumb_mode)
2808 {
e74cfd16 2809 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2810 as_bad (_("selected processor does not support ARM opcodes"));
2811
2812 thumb_mode = 0;
2813
2814 if (!need_pass_2)
2815 frag_align (2, 0, 0);
2816
2817 record_alignment (now_seg, 1);
2818 }
c19d1205
ZW
2819 break;
2820
2821 default:
2822 as_bad (_("invalid instruction size selected (%d)"), width);
2823 }
2824}
2825
2826static void
2827s_arm (int ignore ATTRIBUTE_UNUSED)
2828{
2829 opcode_select (32);
2830 demand_empty_rest_of_line ();
2831}
2832
2833static void
2834s_thumb (int ignore ATTRIBUTE_UNUSED)
2835{
2836 opcode_select (16);
2837 demand_empty_rest_of_line ();
2838}
2839
2840static void
2841s_code (int unused ATTRIBUTE_UNUSED)
2842{
2843 int temp;
2844
2845 temp = get_absolute_expression ();
2846 switch (temp)
2847 {
2848 case 16:
2849 case 32:
2850 opcode_select (temp);
2851 break;
2852
2853 default:
2854 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2855 }
2856}
2857
2858static void
2859s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2860{
2861 /* If we are not already in thumb mode go into it, EVEN if
2862 the target processor does not support thumb instructions.
2863 This is used by gcc/config/arm/lib1funcs.asm for example
2864 to compile interworking support functions even if the
2865 target processor should not support interworking. */
2866 if (! thumb_mode)
2867 {
2868 thumb_mode = 2;
2869 record_alignment (now_seg, 1);
2870 }
2871
2872 demand_empty_rest_of_line ();
2873}
2874
2875static void
2876s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2877{
2878 s_thumb (0);
2879
2880 /* The following label is the name/address of the start of a Thumb function.
2881 We need to know this for the interworking support. */
2882 label_is_thumb_function_name = TRUE;
2883}
2884
2885/* Perform a .set directive, but also mark the alias as
2886 being a thumb function. */
2887
2888static void
2889s_thumb_set (int equiv)
2890{
2891 /* XXX the following is a duplicate of the code for s_set() in read.c
2892 We cannot just call that code as we need to get at the symbol that
2893 is created. */
2894 char * name;
2895 char delim;
2896 char * end_name;
2897 symbolS * symbolP;
2898
2899 /* Especial apologies for the random logic:
2900 This just grew, and could be parsed much more simply!
2901 Dean - in haste. */
d02603dc 2902 delim = get_symbol_name (& name);
c19d1205 2903 end_name = input_line_pointer;
d02603dc 2904 (void) restore_line_pointer (delim);
c19d1205
ZW
2905
2906 if (*input_line_pointer != ',')
2907 {
2908 *end_name = 0;
2909 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2910 *end_name = delim;
2911 ignore_rest_of_line ();
2912 return;
2913 }
2914
2915 input_line_pointer++;
2916 *end_name = 0;
2917
2918 if (name[0] == '.' && name[1] == '\0')
2919 {
2920 /* XXX - this should not happen to .thumb_set. */
2921 abort ();
2922 }
2923
2924 if ((symbolP = symbol_find (name)) == NULL
2925 && (symbolP = md_undefined_symbol (name)) == NULL)
2926 {
2927#ifndef NO_LISTING
2928 /* When doing symbol listings, play games with dummy fragments living
2929 outside the normal fragment chain to record the file and line info
c19d1205 2930 for this symbol. */
b99bd4ef
NC
2931 if (listing & LISTING_SYMBOLS)
2932 {
2933 extern struct list_info_struct * listing_tail;
21d799b5 2934 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2935
2936 memset (dummy_frag, 0, sizeof (fragS));
2937 dummy_frag->fr_type = rs_fill;
2938 dummy_frag->line = listing_tail;
2939 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2940 dummy_frag->fr_symbol = symbolP;
2941 }
2942 else
2943#endif
2944 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2945
2946#ifdef OBJ_COFF
2947 /* "set" symbols are local unless otherwise specified. */
2948 SF_SET_LOCAL (symbolP);
2949#endif /* OBJ_COFF */
2950 } /* Make a new symbol. */
2951
2952 symbol_table_insert (symbolP);
2953
2954 * end_name = delim;
2955
2956 if (equiv
2957 && S_IS_DEFINED (symbolP)
2958 && S_GET_SEGMENT (symbolP) != reg_section)
2959 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2960
2961 pseudo_set (symbolP);
2962
2963 demand_empty_rest_of_line ();
2964
c19d1205 2965 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2966
2967 THUMB_SET_FUNC (symbolP, 1);
2968 ARM_SET_THUMB (symbolP, 1);
2969#if defined OBJ_ELF || defined OBJ_COFF
2970 ARM_SET_INTERWORK (symbolP, support_interwork);
2971#endif
2972}
2973
c19d1205 2974/* Directives: Mode selection. */
b99bd4ef 2975
c19d1205
ZW
2976/* .syntax [unified|divided] - choose the new unified syntax
2977 (same for Arm and Thumb encoding, modulo slight differences in what
2978 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2979static void
c19d1205 2980s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2981{
c19d1205
ZW
2982 char *name, delim;
2983
d02603dc 2984 delim = get_symbol_name (& name);
c19d1205
ZW
2985
2986 if (!strcasecmp (name, "unified"))
2987 unified_syntax = TRUE;
2988 else if (!strcasecmp (name, "divided"))
2989 unified_syntax = FALSE;
2990 else
2991 {
2992 as_bad (_("unrecognized syntax mode \"%s\""), name);
2993 return;
2994 }
d02603dc 2995 (void) restore_line_pointer (delim);
b99bd4ef
NC
2996 demand_empty_rest_of_line ();
2997}
2998
c19d1205
ZW
2999/* Directives: sectioning and alignment. */
3000
c19d1205
ZW
3001static void
3002s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3003{
c19d1205
ZW
3004 /* We don't support putting frags in the BSS segment, we fake it by
3005 marking in_bss, then looking at s_skip for clues. */
3006 subseg_set (bss_section, 0);
3007 demand_empty_rest_of_line ();
cd000bff
DJ
3008
3009#ifdef md_elf_section_change_hook
3010 md_elf_section_change_hook ();
3011#endif
c19d1205 3012}
b99bd4ef 3013
c19d1205
ZW
3014static void
3015s_even (int ignore ATTRIBUTE_UNUSED)
3016{
3017 /* Never make frag if expect extra pass. */
3018 if (!need_pass_2)
3019 frag_align (1, 0, 0);
b99bd4ef 3020
c19d1205 3021 record_alignment (now_seg, 1);
b99bd4ef 3022
c19d1205 3023 demand_empty_rest_of_line ();
b99bd4ef
NC
3024}
3025
2e6976a8
DG
3026/* Directives: CodeComposer Studio. */
3027
3028/* .ref (for CodeComposer Studio syntax only). */
3029static void
3030s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3031{
3032 if (codecomposer_syntax)
3033 ignore_rest_of_line ();
3034 else
3035 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3036}
3037
3038/* If name is not NULL, then it is used for marking the beginning of a
3039 function, wherease if it is NULL then it means the function end. */
3040static void
3041asmfunc_debug (const char * name)
3042{
3043 static const char * last_name = NULL;
3044
3045 if (name != NULL)
3046 {
3047 gas_assert (last_name == NULL);
3048 last_name = name;
3049
3050 if (debug_type == DEBUG_STABS)
3051 stabs_generate_asm_func (name, name);
3052 }
3053 else
3054 {
3055 gas_assert (last_name != NULL);
3056
3057 if (debug_type == DEBUG_STABS)
3058 stabs_generate_asm_endfunc (last_name, last_name);
3059
3060 last_name = NULL;
3061 }
3062}
3063
3064static void
3065s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3066{
3067 if (codecomposer_syntax)
3068 {
3069 switch (asmfunc_state)
3070 {
3071 case OUTSIDE_ASMFUNC:
3072 asmfunc_state = WAITING_ASMFUNC_NAME;
3073 break;
3074
3075 case WAITING_ASMFUNC_NAME:
3076 as_bad (_(".asmfunc repeated."));
3077 break;
3078
3079 case WAITING_ENDASMFUNC:
3080 as_bad (_(".asmfunc without function."));
3081 break;
3082 }
3083 demand_empty_rest_of_line ();
3084 }
3085 else
3086 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3087}
3088
3089static void
3090s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3091{
3092 if (codecomposer_syntax)
3093 {
3094 switch (asmfunc_state)
3095 {
3096 case OUTSIDE_ASMFUNC:
3097 as_bad (_(".endasmfunc without a .asmfunc."));
3098 break;
3099
3100 case WAITING_ASMFUNC_NAME:
3101 as_bad (_(".endasmfunc without function."));
3102 break;
3103
3104 case WAITING_ENDASMFUNC:
3105 asmfunc_state = OUTSIDE_ASMFUNC;
3106 asmfunc_debug (NULL);
3107 break;
3108 }
3109 demand_empty_rest_of_line ();
3110 }
3111 else
3112 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3113}
3114
3115static void
3116s_ccs_def (int name)
3117{
3118 if (codecomposer_syntax)
3119 s_globl (name);
3120 else
3121 as_bad (_(".def pseudo-op only available with -mccs flag."));
3122}
3123
c19d1205 3124/* Directives: Literal pools. */
a737bd4d 3125
c19d1205
ZW
3126static literal_pool *
3127find_literal_pool (void)
a737bd4d 3128{
c19d1205 3129 literal_pool * pool;
a737bd4d 3130
c19d1205 3131 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3132 {
c19d1205
ZW
3133 if (pool->section == now_seg
3134 && pool->sub_section == now_subseg)
3135 break;
a737bd4d
NC
3136 }
3137
c19d1205 3138 return pool;
a737bd4d
NC
3139}
3140
c19d1205
ZW
3141static literal_pool *
3142find_or_make_literal_pool (void)
a737bd4d 3143{
c19d1205
ZW
3144 /* Next literal pool ID number. */
3145 static unsigned int latest_pool_num = 1;
3146 literal_pool * pool;
a737bd4d 3147
c19d1205 3148 pool = find_literal_pool ();
a737bd4d 3149
c19d1205 3150 if (pool == NULL)
a737bd4d 3151 {
c19d1205 3152 /* Create a new pool. */
325801bd 3153 pool = XNEW (literal_pool);
c19d1205
ZW
3154 if (! pool)
3155 return NULL;
a737bd4d 3156
c19d1205
ZW
3157 pool->next_free_entry = 0;
3158 pool->section = now_seg;
3159 pool->sub_section = now_subseg;
3160 pool->next = list_of_pools;
3161 pool->symbol = NULL;
8335d6aa 3162 pool->alignment = 2;
c19d1205
ZW
3163
3164 /* Add it to the list. */
3165 list_of_pools = pool;
a737bd4d 3166 }
a737bd4d 3167
c19d1205
ZW
3168 /* New pools, and emptied pools, will have a NULL symbol. */
3169 if (pool->symbol == NULL)
a737bd4d 3170 {
c19d1205
ZW
3171 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3172 (valueT) 0, &zero_address_frag);
3173 pool->id = latest_pool_num ++;
a737bd4d
NC
3174 }
3175
c19d1205
ZW
3176 /* Done. */
3177 return pool;
a737bd4d
NC
3178}
3179
c19d1205 3180/* Add the literal in the global 'inst'
5f4273c7 3181 structure to the relevant literal pool. */
b99bd4ef
NC
3182
3183static int
8335d6aa 3184add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3185{
8335d6aa
JW
3186#define PADDING_SLOT 0x1
3187#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3188 literal_pool * pool;
8335d6aa
JW
3189 unsigned int entry, pool_size = 0;
3190 bfd_boolean padding_slot_p = FALSE;
e56c722b 3191 unsigned imm1 = 0;
8335d6aa
JW
3192 unsigned imm2 = 0;
3193
3194 if (nbytes == 8)
3195 {
3196 imm1 = inst.operands[1].imm;
3197 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3198 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3199 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3200 if (target_big_endian)
3201 {
3202 imm1 = imm2;
3203 imm2 = inst.operands[1].imm;
3204 }
3205 }
b99bd4ef 3206
c19d1205
ZW
3207 pool = find_or_make_literal_pool ();
3208
3209 /* Check if this literal value is already in the pool. */
3210 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3211 {
8335d6aa
JW
3212 if (nbytes == 4)
3213 {
3214 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3215 && (inst.reloc.exp.X_op == O_constant)
3216 && (pool->literals[entry].X_add_number
3217 == inst.reloc.exp.X_add_number)
3218 && (pool->literals[entry].X_md == nbytes)
3219 && (pool->literals[entry].X_unsigned
3220 == inst.reloc.exp.X_unsigned))
3221 break;
3222
3223 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3224 && (inst.reloc.exp.X_op == O_symbol)
3225 && (pool->literals[entry].X_add_number
3226 == inst.reloc.exp.X_add_number)
3227 && (pool->literals[entry].X_add_symbol
3228 == inst.reloc.exp.X_add_symbol)
3229 && (pool->literals[entry].X_op_symbol
3230 == inst.reloc.exp.X_op_symbol)
3231 && (pool->literals[entry].X_md == nbytes))
3232 break;
3233 }
3234 else if ((nbytes == 8)
3235 && !(pool_size & 0x7)
3236 && ((entry + 1) != pool->next_free_entry)
3237 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3238 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3239 && (pool->literals[entry].X_unsigned
3240 == inst.reloc.exp.X_unsigned)
3241 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3242 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3243 && (pool->literals[entry + 1].X_unsigned
3244 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3245 break;
3246
8335d6aa
JW
3247 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3248 if (padding_slot_p && (nbytes == 4))
c19d1205 3249 break;
8335d6aa
JW
3250
3251 pool_size += 4;
b99bd4ef
NC
3252 }
3253
c19d1205
ZW
3254 /* Do we need to create a new entry? */
3255 if (entry == pool->next_free_entry)
3256 {
3257 if (entry >= MAX_LITERAL_POOL_SIZE)
3258 {
3259 inst.error = _("literal pool overflow");
3260 return FAIL;
3261 }
3262
8335d6aa
JW
3263 if (nbytes == 8)
3264 {
3265 /* For 8-byte entries, we align to an 8-byte boundary,
3266 and split it into two 4-byte entries, because on 32-bit
3267 host, 8-byte constants are treated as big num, thus
3268 saved in "generic_bignum" which will be overwritten
3269 by later assignments.
3270
3271 We also need to make sure there is enough space for
3272 the split.
3273
3274 We also check to make sure the literal operand is a
3275 constant number. */
19f2f6a9
JW
3276 if (!(inst.reloc.exp.X_op == O_constant
3277 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3278 {
3279 inst.error = _("invalid type for literal pool");
3280 return FAIL;
3281 }
3282 else if (pool_size & 0x7)
3283 {
3284 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3285 {
3286 inst.error = _("literal pool overflow");
3287 return FAIL;
3288 }
3289
3290 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3291 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3292 pool->literals[entry].X_add_number = 0;
3293 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3294 pool->next_free_entry += 1;
3295 pool_size += 4;
3296 }
3297 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3298 {
3299 inst.error = _("literal pool overflow");
3300 return FAIL;
3301 }
3302
3303 pool->literals[entry] = inst.reloc.exp;
3304 pool->literals[entry].X_op = O_constant;
3305 pool->literals[entry].X_add_number = imm1;
3306 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3307 pool->literals[entry++].X_md = 4;
3308 pool->literals[entry] = inst.reloc.exp;
3309 pool->literals[entry].X_op = O_constant;
3310 pool->literals[entry].X_add_number = imm2;
3311 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3312 pool->literals[entry].X_md = 4;
3313 pool->alignment = 3;
3314 pool->next_free_entry += 1;
3315 }
3316 else
3317 {
3318 pool->literals[entry] = inst.reloc.exp;
3319 pool->literals[entry].X_md = 4;
3320 }
3321
a8040cf2
NC
3322#ifdef OBJ_ELF
3323 /* PR ld/12974: Record the location of the first source line to reference
3324 this entry in the literal pool. If it turns out during linking that the
3325 symbol does not exist we will be able to give an accurate line number for
3326 the (first use of the) missing reference. */
3327 if (debug_type == DEBUG_DWARF2)
3328 dwarf2_where (pool->locs + entry);
3329#endif
c19d1205
ZW
3330 pool->next_free_entry += 1;
3331 }
8335d6aa
JW
3332 else if (padding_slot_p)
3333 {
3334 pool->literals[entry] = inst.reloc.exp;
3335 pool->literals[entry].X_md = nbytes;
3336 }
b99bd4ef 3337
c19d1205 3338 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3339 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3340 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3341
c19d1205 3342 return SUCCESS;
b99bd4ef
NC
3343}
3344
2e6976a8 3345bfd_boolean
2e57ce7b 3346tc_start_label_without_colon (void)
2e6976a8
DG
3347{
3348 bfd_boolean ret = TRUE;
3349
3350 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3351 {
2e57ce7b 3352 const char *label = input_line_pointer;
2e6976a8
DG
3353
3354 while (!is_end_of_line[(int) label[-1]])
3355 --label;
3356
3357 if (*label == '.')
3358 {
3359 as_bad (_("Invalid label '%s'"), label);
3360 ret = FALSE;
3361 }
3362
3363 asmfunc_debug (label);
3364
3365 asmfunc_state = WAITING_ENDASMFUNC;
3366 }
3367
3368 return ret;
3369}
3370
c19d1205
ZW
3371/* Can't use symbol_new here, so have to create a symbol and then at
3372 a later date assign it a value. Thats what these functions do. */
e16bb312 3373
c19d1205
ZW
3374static void
3375symbol_locate (symbolS * symbolP,
3376 const char * name, /* It is copied, the caller can modify. */
3377 segT segment, /* Segment identifier (SEG_<something>). */
3378 valueT valu, /* Symbol value. */
3379 fragS * frag) /* Associated fragment. */
3380{
e57e6ddc 3381 size_t name_length;
c19d1205 3382 char * preserved_copy_of_name;
e16bb312 3383
c19d1205
ZW
3384 name_length = strlen (name) + 1; /* +1 for \0. */
3385 obstack_grow (&notes, name, name_length);
21d799b5 3386 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3387
c19d1205
ZW
3388#ifdef tc_canonicalize_symbol_name
3389 preserved_copy_of_name =
3390 tc_canonicalize_symbol_name (preserved_copy_of_name);
3391#endif
b99bd4ef 3392
c19d1205 3393 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3394
c19d1205
ZW
3395 S_SET_SEGMENT (symbolP, segment);
3396 S_SET_VALUE (symbolP, valu);
3397 symbol_clear_list_pointers (symbolP);
b99bd4ef 3398
c19d1205 3399 symbol_set_frag (symbolP, frag);
b99bd4ef 3400
c19d1205
ZW
3401 /* Link to end of symbol chain. */
3402 {
3403 extern int symbol_table_frozen;
b99bd4ef 3404
c19d1205
ZW
3405 if (symbol_table_frozen)
3406 abort ();
3407 }
b99bd4ef 3408
c19d1205 3409 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3410
c19d1205 3411 obj_symbol_new_hook (symbolP);
b99bd4ef 3412
c19d1205
ZW
3413#ifdef tc_symbol_new_hook
3414 tc_symbol_new_hook (symbolP);
3415#endif
3416
3417#ifdef DEBUG_SYMS
3418 verify_symbol_chain (symbol_rootP, symbol_lastP);
3419#endif /* DEBUG_SYMS */
b99bd4ef
NC
3420}
3421
c19d1205
ZW
3422static void
3423s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3424{
c19d1205
ZW
3425 unsigned int entry;
3426 literal_pool * pool;
3427 char sym_name[20];
b99bd4ef 3428
c19d1205
ZW
3429 pool = find_literal_pool ();
3430 if (pool == NULL
3431 || pool->symbol == NULL
3432 || pool->next_free_entry == 0)
3433 return;
b99bd4ef 3434
c19d1205
ZW
3435 /* Align pool as you have word accesses.
3436 Only make a frag if we have to. */
3437 if (!need_pass_2)
8335d6aa 3438 frag_align (pool->alignment, 0, 0);
b99bd4ef 3439
c19d1205 3440 record_alignment (now_seg, 2);
b99bd4ef 3441
aaca88ef 3442#ifdef OBJ_ELF
47fc6e36
WN
3443 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3444 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3445#endif
c19d1205 3446 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3447
c19d1205
ZW
3448 symbol_locate (pool->symbol, sym_name, now_seg,
3449 (valueT) frag_now_fix (), frag_now);
3450 symbol_table_insert (pool->symbol);
b99bd4ef 3451
c19d1205 3452 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3453
c19d1205
ZW
3454#if defined OBJ_COFF || defined OBJ_ELF
3455 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3456#endif
6c43fab6 3457
c19d1205 3458 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3459 {
3460#ifdef OBJ_ELF
3461 if (debug_type == DEBUG_DWARF2)
3462 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3463#endif
3464 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3465 emit_expr (&(pool->literals[entry]),
3466 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3467 }
b99bd4ef 3468
c19d1205
ZW
3469 /* Mark the pool as empty. */
3470 pool->next_free_entry = 0;
3471 pool->symbol = NULL;
b99bd4ef
NC
3472}
3473
c19d1205
ZW
3474#ifdef OBJ_ELF
3475/* Forward declarations for functions below, in the MD interface
3476 section. */
3477static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3478static valueT create_unwind_entry (int);
3479static void start_unwind_section (const segT, int);
3480static void add_unwind_opcode (valueT, int);
3481static void flush_pending_unwind (void);
b99bd4ef 3482
c19d1205 3483/* Directives: Data. */
b99bd4ef 3484
c19d1205
ZW
3485static void
3486s_arm_elf_cons (int nbytes)
3487{
3488 expressionS exp;
b99bd4ef 3489
c19d1205
ZW
3490#ifdef md_flush_pending_output
3491 md_flush_pending_output ();
3492#endif
b99bd4ef 3493
c19d1205 3494 if (is_it_end_of_statement ())
b99bd4ef 3495 {
c19d1205
ZW
3496 demand_empty_rest_of_line ();
3497 return;
b99bd4ef
NC
3498 }
3499
c19d1205
ZW
3500#ifdef md_cons_align
3501 md_cons_align (nbytes);
3502#endif
b99bd4ef 3503
c19d1205
ZW
3504 mapping_state (MAP_DATA);
3505 do
b99bd4ef 3506 {
c19d1205
ZW
3507 int reloc;
3508 char *base = input_line_pointer;
b99bd4ef 3509
c19d1205 3510 expression (& exp);
b99bd4ef 3511
c19d1205
ZW
3512 if (exp.X_op != O_symbol)
3513 emit_expr (&exp, (unsigned int) nbytes);
3514 else
3515 {
3516 char *before_reloc = input_line_pointer;
3517 reloc = parse_reloc (&input_line_pointer);
3518 if (reloc == -1)
3519 {
3520 as_bad (_("unrecognized relocation suffix"));
3521 ignore_rest_of_line ();
3522 return;
3523 }
3524 else if (reloc == BFD_RELOC_UNUSED)
3525 emit_expr (&exp, (unsigned int) nbytes);
3526 else
3527 {
21d799b5 3528 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3529 bfd_reloc_type_lookup (stdoutput,
3530 (bfd_reloc_code_real_type) reloc);
c19d1205 3531 int size = bfd_get_reloc_size (howto);
b99bd4ef 3532
2fc8bdac
ZW
3533 if (reloc == BFD_RELOC_ARM_PLT32)
3534 {
3535 as_bad (_("(plt) is only valid on branch targets"));
3536 reloc = BFD_RELOC_UNUSED;
3537 size = 0;
3538 }
3539
c19d1205 3540 if (size > nbytes)
2fc8bdac 3541 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3542 howto->name, nbytes);
3543 else
3544 {
3545 /* We've parsed an expression stopping at O_symbol.
3546 But there may be more expression left now that we
3547 have parsed the relocation marker. Parse it again.
3548 XXX Surely there is a cleaner way to do this. */
3549 char *p = input_line_pointer;
3550 int offset;
325801bd 3551 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3552
c19d1205
ZW
3553 memcpy (save_buf, base, input_line_pointer - base);
3554 memmove (base + (input_line_pointer - before_reloc),
3555 base, before_reloc - base);
3556
3557 input_line_pointer = base + (input_line_pointer-before_reloc);
3558 expression (&exp);
3559 memcpy (base, save_buf, p - base);
3560
3561 offset = nbytes - size;
4b1a927e
AM
3562 p = frag_more (nbytes);
3563 memset (p, 0, nbytes);
c19d1205 3564 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3565 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3566 free (save_buf);
c19d1205
ZW
3567 }
3568 }
3569 }
b99bd4ef 3570 }
c19d1205 3571 while (*input_line_pointer++ == ',');
b99bd4ef 3572
c19d1205
ZW
3573 /* Put terminator back into stream. */
3574 input_line_pointer --;
3575 demand_empty_rest_of_line ();
b99bd4ef
NC
3576}
3577
c921be7d
NC
3578/* Emit an expression containing a 32-bit thumb instruction.
3579 Implementation based on put_thumb32_insn. */
3580
3581static void
3582emit_thumb32_expr (expressionS * exp)
3583{
3584 expressionS exp_high = *exp;
3585
3586 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3587 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3588 exp->X_add_number &= 0xffff;
3589 emit_expr (exp, (unsigned int) THUMB_SIZE);
3590}
3591
3592/* Guess the instruction size based on the opcode. */
3593
3594static int
3595thumb_insn_size (int opcode)
3596{
3597 if ((unsigned int) opcode < 0xe800u)
3598 return 2;
3599 else if ((unsigned int) opcode >= 0xe8000000u)
3600 return 4;
3601 else
3602 return 0;
3603}
3604
3605static bfd_boolean
3606emit_insn (expressionS *exp, int nbytes)
3607{
3608 int size = 0;
3609
3610 if (exp->X_op == O_constant)
3611 {
3612 size = nbytes;
3613
3614 if (size == 0)
3615 size = thumb_insn_size (exp->X_add_number);
3616
3617 if (size != 0)
3618 {
3619 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3620 {
3621 as_bad (_(".inst.n operand too big. "\
3622 "Use .inst.w instead"));
3623 size = 0;
3624 }
3625 else
3626 {
3627 if (now_it.state == AUTOMATIC_IT_BLOCK)
3628 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3629 else
3630 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3631
3632 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3633 emit_thumb32_expr (exp);
3634 else
3635 emit_expr (exp, (unsigned int) size);
3636
3637 it_fsm_post_encode ();
3638 }
3639 }
3640 else
3641 as_bad (_("cannot determine Thumb instruction size. " \
3642 "Use .inst.n/.inst.w instead"));
3643 }
3644 else
3645 as_bad (_("constant expression required"));
3646
3647 return (size != 0);
3648}
3649
3650/* Like s_arm_elf_cons but do not use md_cons_align and
3651 set the mapping state to MAP_ARM/MAP_THUMB. */
3652
3653static void
3654s_arm_elf_inst (int nbytes)
3655{
3656 if (is_it_end_of_statement ())
3657 {
3658 demand_empty_rest_of_line ();
3659 return;
3660 }
3661
3662 /* Calling mapping_state () here will not change ARM/THUMB,
3663 but will ensure not to be in DATA state. */
3664
3665 if (thumb_mode)
3666 mapping_state (MAP_THUMB);
3667 else
3668 {
3669 if (nbytes != 0)
3670 {
3671 as_bad (_("width suffixes are invalid in ARM mode"));
3672 ignore_rest_of_line ();
3673 return;
3674 }
3675
3676 nbytes = 4;
3677
3678 mapping_state (MAP_ARM);
3679 }
3680
3681 do
3682 {
3683 expressionS exp;
3684
3685 expression (& exp);
3686
3687 if (! emit_insn (& exp, nbytes))
3688 {
3689 ignore_rest_of_line ();
3690 return;
3691 }
3692 }
3693 while (*input_line_pointer++ == ',');
3694
3695 /* Put terminator back into stream. */
3696 input_line_pointer --;
3697 demand_empty_rest_of_line ();
3698}
b99bd4ef 3699
c19d1205 3700/* Parse a .rel31 directive. */
b99bd4ef 3701
c19d1205
ZW
3702static void
3703s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3704{
3705 expressionS exp;
3706 char *p;
3707 valueT highbit;
b99bd4ef 3708
c19d1205
ZW
3709 highbit = 0;
3710 if (*input_line_pointer == '1')
3711 highbit = 0x80000000;
3712 else if (*input_line_pointer != '0')
3713 as_bad (_("expected 0 or 1"));
b99bd4ef 3714
c19d1205
ZW
3715 input_line_pointer++;
3716 if (*input_line_pointer != ',')
3717 as_bad (_("missing comma"));
3718 input_line_pointer++;
b99bd4ef 3719
c19d1205
ZW
3720#ifdef md_flush_pending_output
3721 md_flush_pending_output ();
3722#endif
b99bd4ef 3723
c19d1205
ZW
3724#ifdef md_cons_align
3725 md_cons_align (4);
3726#endif
b99bd4ef 3727
c19d1205 3728 mapping_state (MAP_DATA);
b99bd4ef 3729
c19d1205 3730 expression (&exp);
b99bd4ef 3731
c19d1205
ZW
3732 p = frag_more (4);
3733 md_number_to_chars (p, highbit, 4);
3734 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3735 BFD_RELOC_ARM_PREL31);
b99bd4ef 3736
c19d1205 3737 demand_empty_rest_of_line ();
b99bd4ef
NC
3738}
3739
c19d1205 3740/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3741
c19d1205 3742/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3743
c19d1205
ZW
3744static void
3745s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3746{
3747 demand_empty_rest_of_line ();
921e5f0a
PB
3748 if (unwind.proc_start)
3749 {
c921be7d 3750 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3751 return;
3752 }
3753
c19d1205
ZW
3754 /* Mark the start of the function. */
3755 unwind.proc_start = expr_build_dot ();
b99bd4ef 3756
c19d1205
ZW
3757 /* Reset the rest of the unwind info. */
3758 unwind.opcode_count = 0;
3759 unwind.table_entry = NULL;
3760 unwind.personality_routine = NULL;
3761 unwind.personality_index = -1;
3762 unwind.frame_size = 0;
3763 unwind.fp_offset = 0;
fdfde340 3764 unwind.fp_reg = REG_SP;
c19d1205
ZW
3765 unwind.fp_used = 0;
3766 unwind.sp_restored = 0;
3767}
b99bd4ef 3768
b99bd4ef 3769
c19d1205
ZW
3770/* Parse a handlerdata directive. Creates the exception handling table entry
3771 for the function. */
b99bd4ef 3772
c19d1205
ZW
3773static void
3774s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3775{
3776 demand_empty_rest_of_line ();
921e5f0a 3777 if (!unwind.proc_start)
c921be7d 3778 as_bad (MISSING_FNSTART);
921e5f0a 3779
c19d1205 3780 if (unwind.table_entry)
6decc662 3781 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3782
c19d1205
ZW
3783 create_unwind_entry (1);
3784}
a737bd4d 3785
c19d1205 3786/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3787
c19d1205
ZW
3788static void
3789s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3790{
3791 long where;
3792 char *ptr;
3793 valueT val;
940b5ce0 3794 unsigned int marked_pr_dependency;
f02232aa 3795
c19d1205 3796 demand_empty_rest_of_line ();
f02232aa 3797
921e5f0a
PB
3798 if (!unwind.proc_start)
3799 {
c921be7d 3800 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3801 return;
3802 }
3803
c19d1205
ZW
3804 /* Add eh table entry. */
3805 if (unwind.table_entry == NULL)
3806 val = create_unwind_entry (0);
3807 else
3808 val = 0;
f02232aa 3809
c19d1205
ZW
3810 /* Add index table entry. This is two words. */
3811 start_unwind_section (unwind.saved_seg, 1);
3812 frag_align (2, 0, 0);
3813 record_alignment (now_seg, 2);
b99bd4ef 3814
c19d1205 3815 ptr = frag_more (8);
5011093d 3816 memset (ptr, 0, 8);
c19d1205 3817 where = frag_now_fix () - 8;
f02232aa 3818
c19d1205
ZW
3819 /* Self relative offset of the function start. */
3820 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3821 BFD_RELOC_ARM_PREL31);
f02232aa 3822
c19d1205
ZW
3823 /* Indicate dependency on EHABI-defined personality routines to the
3824 linker, if it hasn't been done already. */
940b5ce0
DJ
3825 marked_pr_dependency
3826 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3827 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3828 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3829 {
5f4273c7
NC
3830 static const char *const name[] =
3831 {
3832 "__aeabi_unwind_cpp_pr0",
3833 "__aeabi_unwind_cpp_pr1",
3834 "__aeabi_unwind_cpp_pr2"
3835 };
c19d1205
ZW
3836 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3837 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3838 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3839 |= 1 << unwind.personality_index;
c19d1205 3840 }
f02232aa 3841
c19d1205
ZW
3842 if (val)
3843 /* Inline exception table entry. */
3844 md_number_to_chars (ptr + 4, val, 4);
3845 else
3846 /* Self relative offset of the table entry. */
3847 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3848 BFD_RELOC_ARM_PREL31);
f02232aa 3849
c19d1205
ZW
3850 /* Restore the original section. */
3851 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3852
3853 unwind.proc_start = NULL;
c19d1205 3854}
f02232aa 3855
f02232aa 3856
c19d1205 3857/* Parse an unwind_cantunwind directive. */
b99bd4ef 3858
c19d1205
ZW
3859static void
3860s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3861{
3862 demand_empty_rest_of_line ();
921e5f0a 3863 if (!unwind.proc_start)
c921be7d 3864 as_bad (MISSING_FNSTART);
921e5f0a 3865
c19d1205
ZW
3866 if (unwind.personality_routine || unwind.personality_index != -1)
3867 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3868
c19d1205
ZW
3869 unwind.personality_index = -2;
3870}
b99bd4ef 3871
b99bd4ef 3872
c19d1205 3873/* Parse a personalityindex directive. */
b99bd4ef 3874
c19d1205
ZW
3875static void
3876s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3877{
3878 expressionS exp;
b99bd4ef 3879
921e5f0a 3880 if (!unwind.proc_start)
c921be7d 3881 as_bad (MISSING_FNSTART);
921e5f0a 3882
c19d1205
ZW
3883 if (unwind.personality_routine || unwind.personality_index != -1)
3884 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3885
c19d1205 3886 expression (&exp);
b99bd4ef 3887
c19d1205
ZW
3888 if (exp.X_op != O_constant
3889 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3890 {
c19d1205
ZW
3891 as_bad (_("bad personality routine number"));
3892 ignore_rest_of_line ();
3893 return;
b99bd4ef
NC
3894 }
3895
c19d1205 3896 unwind.personality_index = exp.X_add_number;
b99bd4ef 3897
c19d1205
ZW
3898 demand_empty_rest_of_line ();
3899}
e16bb312 3900
e16bb312 3901
c19d1205 3902/* Parse a personality directive. */
e16bb312 3903
c19d1205
ZW
3904static void
3905s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3906{
3907 char *name, *p, c;
a737bd4d 3908
921e5f0a 3909 if (!unwind.proc_start)
c921be7d 3910 as_bad (MISSING_FNSTART);
921e5f0a 3911
c19d1205
ZW
3912 if (unwind.personality_routine || unwind.personality_index != -1)
3913 as_bad (_("duplicate .personality directive"));
a737bd4d 3914
d02603dc 3915 c = get_symbol_name (& name);
c19d1205 3916 p = input_line_pointer;
d02603dc
NC
3917 if (c == '"')
3918 ++ input_line_pointer;
c19d1205
ZW
3919 unwind.personality_routine = symbol_find_or_make (name);
3920 *p = c;
3921 demand_empty_rest_of_line ();
3922}
e16bb312 3923
e16bb312 3924
c19d1205 3925/* Parse a directive saving core registers. */
e16bb312 3926
c19d1205
ZW
3927static void
3928s_arm_unwind_save_core (void)
e16bb312 3929{
c19d1205
ZW
3930 valueT op;
3931 long range;
3932 int n;
e16bb312 3933
c19d1205
ZW
3934 range = parse_reg_list (&input_line_pointer);
3935 if (range == FAIL)
e16bb312 3936 {
c19d1205
ZW
3937 as_bad (_("expected register list"));
3938 ignore_rest_of_line ();
3939 return;
3940 }
e16bb312 3941
c19d1205 3942 demand_empty_rest_of_line ();
e16bb312 3943
c19d1205
ZW
3944 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3945 into .unwind_save {..., sp...}. We aren't bothered about the value of
3946 ip because it is clobbered by calls. */
3947 if (unwind.sp_restored && unwind.fp_reg == 12
3948 && (range & 0x3000) == 0x1000)
3949 {
3950 unwind.opcode_count--;
3951 unwind.sp_restored = 0;
3952 range = (range | 0x2000) & ~0x1000;
3953 unwind.pending_offset = 0;
3954 }
e16bb312 3955
01ae4198
DJ
3956 /* Pop r4-r15. */
3957 if (range & 0xfff0)
c19d1205 3958 {
01ae4198
DJ
3959 /* See if we can use the short opcodes. These pop a block of up to 8
3960 registers starting with r4, plus maybe r14. */
3961 for (n = 0; n < 8; n++)
3962 {
3963 /* Break at the first non-saved register. */
3964 if ((range & (1 << (n + 4))) == 0)
3965 break;
3966 }
3967 /* See if there are any other bits set. */
3968 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3969 {
3970 /* Use the long form. */
3971 op = 0x8000 | ((range >> 4) & 0xfff);
3972 add_unwind_opcode (op, 2);
3973 }
0dd132b6 3974 else
01ae4198
DJ
3975 {
3976 /* Use the short form. */
3977 if (range & 0x4000)
3978 op = 0xa8; /* Pop r14. */
3979 else
3980 op = 0xa0; /* Do not pop r14. */
3981 op |= (n - 1);
3982 add_unwind_opcode (op, 1);
3983 }
c19d1205 3984 }
0dd132b6 3985
c19d1205
ZW
3986 /* Pop r0-r3. */
3987 if (range & 0xf)
3988 {
3989 op = 0xb100 | (range & 0xf);
3990 add_unwind_opcode (op, 2);
0dd132b6
NC
3991 }
3992
c19d1205
ZW
3993 /* Record the number of bytes pushed. */
3994 for (n = 0; n < 16; n++)
3995 {
3996 if (range & (1 << n))
3997 unwind.frame_size += 4;
3998 }
0dd132b6
NC
3999}
4000
c19d1205
ZW
4001
4002/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4003
4004static void
c19d1205 4005s_arm_unwind_save_fpa (int reg)
b99bd4ef 4006{
c19d1205
ZW
4007 expressionS exp;
4008 int num_regs;
4009 valueT op;
b99bd4ef 4010
c19d1205
ZW
4011 /* Get Number of registers to transfer. */
4012 if (skip_past_comma (&input_line_pointer) != FAIL)
4013 expression (&exp);
4014 else
4015 exp.X_op = O_illegal;
b99bd4ef 4016
c19d1205 4017 if (exp.X_op != O_constant)
b99bd4ef 4018 {
c19d1205
ZW
4019 as_bad (_("expected , <constant>"));
4020 ignore_rest_of_line ();
b99bd4ef
NC
4021 return;
4022 }
4023
c19d1205
ZW
4024 num_regs = exp.X_add_number;
4025
4026 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4027 {
c19d1205
ZW
4028 as_bad (_("number of registers must be in the range [1:4]"));
4029 ignore_rest_of_line ();
b99bd4ef
NC
4030 return;
4031 }
4032
c19d1205 4033 demand_empty_rest_of_line ();
b99bd4ef 4034
c19d1205
ZW
4035 if (reg == 4)
4036 {
4037 /* Short form. */
4038 op = 0xb4 | (num_regs - 1);
4039 add_unwind_opcode (op, 1);
4040 }
b99bd4ef
NC
4041 else
4042 {
c19d1205
ZW
4043 /* Long form. */
4044 op = 0xc800 | (reg << 4) | (num_regs - 1);
4045 add_unwind_opcode (op, 2);
b99bd4ef 4046 }
c19d1205 4047 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4048}
4049
c19d1205 4050
fa073d69
MS
4051/* Parse a directive saving VFP registers for ARMv6 and above. */
4052
4053static void
4054s_arm_unwind_save_vfp_armv6 (void)
4055{
4056 int count;
4057 unsigned int start;
4058 valueT op;
4059 int num_vfpv3_regs = 0;
4060 int num_regs_below_16;
4061
4062 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4063 if (count == FAIL)
4064 {
4065 as_bad (_("expected register list"));
4066 ignore_rest_of_line ();
4067 return;
4068 }
4069
4070 demand_empty_rest_of_line ();
4071
4072 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4073 than FSTMX/FLDMX-style ones). */
4074
4075 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4076 if (start >= 16)
4077 num_vfpv3_regs = count;
4078 else if (start + count > 16)
4079 num_vfpv3_regs = start + count - 16;
4080
4081 if (num_vfpv3_regs > 0)
4082 {
4083 int start_offset = start > 16 ? start - 16 : 0;
4084 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4085 add_unwind_opcode (op, 2);
4086 }
4087
4088 /* Generate opcode for registers numbered in the range 0 .. 15. */
4089 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4090 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4091 if (num_regs_below_16 > 0)
4092 {
4093 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4094 add_unwind_opcode (op, 2);
4095 }
4096
4097 unwind.frame_size += count * 8;
4098}
4099
4100
4101/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4102
4103static void
c19d1205 4104s_arm_unwind_save_vfp (void)
b99bd4ef 4105{
c19d1205 4106 int count;
ca3f61f7 4107 unsigned int reg;
c19d1205 4108 valueT op;
b99bd4ef 4109
5287ad62 4110 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4111 if (count == FAIL)
b99bd4ef 4112 {
c19d1205
ZW
4113 as_bad (_("expected register list"));
4114 ignore_rest_of_line ();
b99bd4ef
NC
4115 return;
4116 }
4117
c19d1205 4118 demand_empty_rest_of_line ();
b99bd4ef 4119
c19d1205 4120 if (reg == 8)
b99bd4ef 4121 {
c19d1205
ZW
4122 /* Short form. */
4123 op = 0xb8 | (count - 1);
4124 add_unwind_opcode (op, 1);
b99bd4ef 4125 }
c19d1205 4126 else
b99bd4ef 4127 {
c19d1205
ZW
4128 /* Long form. */
4129 op = 0xb300 | (reg << 4) | (count - 1);
4130 add_unwind_opcode (op, 2);
b99bd4ef 4131 }
c19d1205
ZW
4132 unwind.frame_size += count * 8 + 4;
4133}
b99bd4ef 4134
b99bd4ef 4135
c19d1205
ZW
4136/* Parse a directive saving iWMMXt data registers. */
4137
4138static void
4139s_arm_unwind_save_mmxwr (void)
4140{
4141 int reg;
4142 int hi_reg;
4143 int i;
4144 unsigned mask = 0;
4145 valueT op;
b99bd4ef 4146
c19d1205
ZW
4147 if (*input_line_pointer == '{')
4148 input_line_pointer++;
b99bd4ef 4149
c19d1205 4150 do
b99bd4ef 4151 {
dcbf9037 4152 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4153
c19d1205 4154 if (reg == FAIL)
b99bd4ef 4155 {
9b7132d3 4156 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4157 goto error;
b99bd4ef
NC
4158 }
4159
c19d1205
ZW
4160 if (mask >> reg)
4161 as_tsktsk (_("register list not in ascending order"));
4162 mask |= 1 << reg;
b99bd4ef 4163
c19d1205
ZW
4164 if (*input_line_pointer == '-')
4165 {
4166 input_line_pointer++;
dcbf9037 4167 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4168 if (hi_reg == FAIL)
4169 {
9b7132d3 4170 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4171 goto error;
4172 }
4173 else if (reg >= hi_reg)
4174 {
4175 as_bad (_("bad register range"));
4176 goto error;
4177 }
4178 for (; reg < hi_reg; reg++)
4179 mask |= 1 << reg;
4180 }
4181 }
4182 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4183
d996d970 4184 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4185
c19d1205 4186 demand_empty_rest_of_line ();
b99bd4ef 4187
708587a4 4188 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4189 the list. */
4190 flush_pending_unwind ();
b99bd4ef 4191
c19d1205 4192 for (i = 0; i < 16; i++)
b99bd4ef 4193 {
c19d1205
ZW
4194 if (mask & (1 << i))
4195 unwind.frame_size += 8;
b99bd4ef
NC
4196 }
4197
c19d1205
ZW
4198 /* Attempt to combine with a previous opcode. We do this because gcc
4199 likes to output separate unwind directives for a single block of
4200 registers. */
4201 if (unwind.opcode_count > 0)
b99bd4ef 4202 {
c19d1205
ZW
4203 i = unwind.opcodes[unwind.opcode_count - 1];
4204 if ((i & 0xf8) == 0xc0)
4205 {
4206 i &= 7;
4207 /* Only merge if the blocks are contiguous. */
4208 if (i < 6)
4209 {
4210 if ((mask & 0xfe00) == (1 << 9))
4211 {
4212 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4213 unwind.opcode_count--;
4214 }
4215 }
4216 else if (i == 6 && unwind.opcode_count >= 2)
4217 {
4218 i = unwind.opcodes[unwind.opcode_count - 2];
4219 reg = i >> 4;
4220 i &= 0xf;
b99bd4ef 4221
c19d1205
ZW
4222 op = 0xffff << (reg - 1);
4223 if (reg > 0
87a1fd79 4224 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4225 {
4226 op = (1 << (reg + i + 1)) - 1;
4227 op &= ~((1 << reg) - 1);
4228 mask |= op;
4229 unwind.opcode_count -= 2;
4230 }
4231 }
4232 }
b99bd4ef
NC
4233 }
4234
c19d1205
ZW
4235 hi_reg = 15;
4236 /* We want to generate opcodes in the order the registers have been
4237 saved, ie. descending order. */
4238 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4239 {
c19d1205
ZW
4240 /* Save registers in blocks. */
4241 if (reg < 0
4242 || !(mask & (1 << reg)))
4243 {
4244 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4245 preceding block. */
c19d1205
ZW
4246 if (reg != hi_reg)
4247 {
4248 if (reg == 9)
4249 {
4250 /* Short form. */
4251 op = 0xc0 | (hi_reg - 10);
4252 add_unwind_opcode (op, 1);
4253 }
4254 else
4255 {
4256 /* Long form. */
4257 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4258 add_unwind_opcode (op, 2);
4259 }
4260 }
4261 hi_reg = reg - 1;
4262 }
b99bd4ef
NC
4263 }
4264
c19d1205
ZW
4265 return;
4266error:
4267 ignore_rest_of_line ();
b99bd4ef
NC
4268}
4269
4270static void
c19d1205 4271s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4272{
c19d1205
ZW
4273 int reg;
4274 int hi_reg;
4275 unsigned mask = 0;
4276 valueT op;
b99bd4ef 4277
c19d1205
ZW
4278 if (*input_line_pointer == '{')
4279 input_line_pointer++;
b99bd4ef 4280
477330fc
RM
4281 skip_whitespace (input_line_pointer);
4282
c19d1205 4283 do
b99bd4ef 4284 {
dcbf9037 4285 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4286
c19d1205
ZW
4287 if (reg == FAIL)
4288 {
9b7132d3 4289 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4290 goto error;
4291 }
b99bd4ef 4292
c19d1205
ZW
4293 reg -= 8;
4294 if (mask >> reg)
4295 as_tsktsk (_("register list not in ascending order"));
4296 mask |= 1 << reg;
b99bd4ef 4297
c19d1205
ZW
4298 if (*input_line_pointer == '-')
4299 {
4300 input_line_pointer++;
dcbf9037 4301 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4302 if (hi_reg == FAIL)
4303 {
9b7132d3 4304 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4305 goto error;
4306 }
4307 else if (reg >= hi_reg)
4308 {
4309 as_bad (_("bad register range"));
4310 goto error;
4311 }
4312 for (; reg < hi_reg; reg++)
4313 mask |= 1 << reg;
4314 }
b99bd4ef 4315 }
c19d1205 4316 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4317
d996d970 4318 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4319
c19d1205
ZW
4320 demand_empty_rest_of_line ();
4321
708587a4 4322 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4323 the list. */
4324 flush_pending_unwind ();
b99bd4ef 4325
c19d1205 4326 for (reg = 0; reg < 16; reg++)
b99bd4ef 4327 {
c19d1205
ZW
4328 if (mask & (1 << reg))
4329 unwind.frame_size += 4;
b99bd4ef 4330 }
c19d1205
ZW
4331 op = 0xc700 | mask;
4332 add_unwind_opcode (op, 2);
4333 return;
4334error:
4335 ignore_rest_of_line ();
b99bd4ef
NC
4336}
4337
c19d1205 4338
fa073d69
MS
4339/* Parse an unwind_save directive.
4340 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4341
b99bd4ef 4342static void
fa073d69 4343s_arm_unwind_save (int arch_v6)
b99bd4ef 4344{
c19d1205
ZW
4345 char *peek;
4346 struct reg_entry *reg;
4347 bfd_boolean had_brace = FALSE;
b99bd4ef 4348
921e5f0a 4349 if (!unwind.proc_start)
c921be7d 4350 as_bad (MISSING_FNSTART);
921e5f0a 4351
c19d1205
ZW
4352 /* Figure out what sort of save we have. */
4353 peek = input_line_pointer;
b99bd4ef 4354
c19d1205 4355 if (*peek == '{')
b99bd4ef 4356 {
c19d1205
ZW
4357 had_brace = TRUE;
4358 peek++;
b99bd4ef
NC
4359 }
4360
c19d1205 4361 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4362
c19d1205 4363 if (!reg)
b99bd4ef 4364 {
c19d1205
ZW
4365 as_bad (_("register expected"));
4366 ignore_rest_of_line ();
b99bd4ef
NC
4367 return;
4368 }
4369
c19d1205 4370 switch (reg->type)
b99bd4ef 4371 {
c19d1205
ZW
4372 case REG_TYPE_FN:
4373 if (had_brace)
4374 {
4375 as_bad (_("FPA .unwind_save does not take a register list"));
4376 ignore_rest_of_line ();
4377 return;
4378 }
93ac2687 4379 input_line_pointer = peek;
c19d1205 4380 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4381 return;
c19d1205 4382
1f5afe1c
NC
4383 case REG_TYPE_RN:
4384 s_arm_unwind_save_core ();
4385 return;
4386
fa073d69
MS
4387 case REG_TYPE_VFD:
4388 if (arch_v6)
477330fc 4389 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4390 else
477330fc 4391 s_arm_unwind_save_vfp ();
fa073d69 4392 return;
1f5afe1c
NC
4393
4394 case REG_TYPE_MMXWR:
4395 s_arm_unwind_save_mmxwr ();
4396 return;
4397
4398 case REG_TYPE_MMXWCG:
4399 s_arm_unwind_save_mmxwcg ();
4400 return;
c19d1205
ZW
4401
4402 default:
4403 as_bad (_(".unwind_save does not support this kind of register"));
4404 ignore_rest_of_line ();
b99bd4ef 4405 }
c19d1205 4406}
b99bd4ef 4407
b99bd4ef 4408
c19d1205
ZW
4409/* Parse an unwind_movsp directive. */
4410
4411static void
4412s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4413{
4414 int reg;
4415 valueT op;
4fa3602b 4416 int offset;
c19d1205 4417
921e5f0a 4418 if (!unwind.proc_start)
c921be7d 4419 as_bad (MISSING_FNSTART);
921e5f0a 4420
dcbf9037 4421 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4422 if (reg == FAIL)
b99bd4ef 4423 {
9b7132d3 4424 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4425 ignore_rest_of_line ();
b99bd4ef
NC
4426 return;
4427 }
4fa3602b
PB
4428
4429 /* Optional constant. */
4430 if (skip_past_comma (&input_line_pointer) != FAIL)
4431 {
4432 if (immediate_for_directive (&offset) == FAIL)
4433 return;
4434 }
4435 else
4436 offset = 0;
4437
c19d1205 4438 demand_empty_rest_of_line ();
b99bd4ef 4439
c19d1205 4440 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4441 {
c19d1205 4442 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4443 return;
4444 }
4445
c19d1205
ZW
4446 if (unwind.fp_reg != REG_SP)
4447 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4448
c19d1205
ZW
4449 /* Generate opcode to restore the value. */
4450 op = 0x90 | reg;
4451 add_unwind_opcode (op, 1);
4452
4453 /* Record the information for later. */
4454 unwind.fp_reg = reg;
4fa3602b 4455 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4456 unwind.sp_restored = 1;
b05fe5cf
ZW
4457}
4458
c19d1205
ZW
4459/* Parse an unwind_pad directive. */
4460
b05fe5cf 4461static void
c19d1205 4462s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4463{
c19d1205 4464 int offset;
b05fe5cf 4465
921e5f0a 4466 if (!unwind.proc_start)
c921be7d 4467 as_bad (MISSING_FNSTART);
921e5f0a 4468
c19d1205
ZW
4469 if (immediate_for_directive (&offset) == FAIL)
4470 return;
b99bd4ef 4471
c19d1205
ZW
4472 if (offset & 3)
4473 {
4474 as_bad (_("stack increment must be multiple of 4"));
4475 ignore_rest_of_line ();
4476 return;
4477 }
b99bd4ef 4478
c19d1205
ZW
4479 /* Don't generate any opcodes, just record the details for later. */
4480 unwind.frame_size += offset;
4481 unwind.pending_offset += offset;
4482
4483 demand_empty_rest_of_line ();
4484}
4485
4486/* Parse an unwind_setfp directive. */
4487
4488static void
4489s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4490{
c19d1205
ZW
4491 int sp_reg;
4492 int fp_reg;
4493 int offset;
4494
921e5f0a 4495 if (!unwind.proc_start)
c921be7d 4496 as_bad (MISSING_FNSTART);
921e5f0a 4497
dcbf9037 4498 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4499 if (skip_past_comma (&input_line_pointer) == FAIL)
4500 sp_reg = FAIL;
4501 else
dcbf9037 4502 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4503
c19d1205
ZW
4504 if (fp_reg == FAIL || sp_reg == FAIL)
4505 {
4506 as_bad (_("expected <reg>, <reg>"));
4507 ignore_rest_of_line ();
4508 return;
4509 }
b99bd4ef 4510
c19d1205
ZW
4511 /* Optional constant. */
4512 if (skip_past_comma (&input_line_pointer) != FAIL)
4513 {
4514 if (immediate_for_directive (&offset) == FAIL)
4515 return;
4516 }
4517 else
4518 offset = 0;
a737bd4d 4519
c19d1205 4520 demand_empty_rest_of_line ();
a737bd4d 4521
fdfde340 4522 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4523 {
c19d1205
ZW
4524 as_bad (_("register must be either sp or set by a previous"
4525 "unwind_movsp directive"));
4526 return;
a737bd4d
NC
4527 }
4528
c19d1205
ZW
4529 /* Don't generate any opcodes, just record the information for later. */
4530 unwind.fp_reg = fp_reg;
4531 unwind.fp_used = 1;
fdfde340 4532 if (sp_reg == REG_SP)
c19d1205
ZW
4533 unwind.fp_offset = unwind.frame_size - offset;
4534 else
4535 unwind.fp_offset -= offset;
a737bd4d
NC
4536}
4537
c19d1205
ZW
4538/* Parse an unwind_raw directive. */
4539
4540static void
4541s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4542{
c19d1205 4543 expressionS exp;
708587a4 4544 /* This is an arbitrary limit. */
c19d1205
ZW
4545 unsigned char op[16];
4546 int count;
a737bd4d 4547
921e5f0a 4548 if (!unwind.proc_start)
c921be7d 4549 as_bad (MISSING_FNSTART);
921e5f0a 4550
c19d1205
ZW
4551 expression (&exp);
4552 if (exp.X_op == O_constant
4553 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4554 {
c19d1205
ZW
4555 unwind.frame_size += exp.X_add_number;
4556 expression (&exp);
4557 }
4558 else
4559 exp.X_op = O_illegal;
a737bd4d 4560
c19d1205
ZW
4561 if (exp.X_op != O_constant)
4562 {
4563 as_bad (_("expected <offset>, <opcode>"));
4564 ignore_rest_of_line ();
4565 return;
4566 }
a737bd4d 4567
c19d1205 4568 count = 0;
a737bd4d 4569
c19d1205
ZW
4570 /* Parse the opcode. */
4571 for (;;)
4572 {
4573 if (count >= 16)
4574 {
4575 as_bad (_("unwind opcode too long"));
4576 ignore_rest_of_line ();
a737bd4d 4577 }
c19d1205 4578 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4579 {
c19d1205
ZW
4580 as_bad (_("invalid unwind opcode"));
4581 ignore_rest_of_line ();
4582 return;
a737bd4d 4583 }
c19d1205 4584 op[count++] = exp.X_add_number;
a737bd4d 4585
c19d1205
ZW
4586 /* Parse the next byte. */
4587 if (skip_past_comma (&input_line_pointer) == FAIL)
4588 break;
a737bd4d 4589
c19d1205
ZW
4590 expression (&exp);
4591 }
b99bd4ef 4592
c19d1205
ZW
4593 /* Add the opcode bytes in reverse order. */
4594 while (count--)
4595 add_unwind_opcode (op[count], 1);
b99bd4ef 4596
c19d1205 4597 demand_empty_rest_of_line ();
b99bd4ef 4598}
ee065d83
PB
4599
4600
4601/* Parse a .eabi_attribute directive. */
4602
4603static void
4604s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4605{
0420f52b 4606 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4607
4608 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4609 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4610}
4611
0855e32b
NS
4612/* Emit a tls fix for the symbol. */
4613
4614static void
4615s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4616{
4617 char *p;
4618 expressionS exp;
4619#ifdef md_flush_pending_output
4620 md_flush_pending_output ();
4621#endif
4622
4623#ifdef md_cons_align
4624 md_cons_align (4);
4625#endif
4626
4627 /* Since we're just labelling the code, there's no need to define a
4628 mapping symbol. */
4629 expression (&exp);
4630 p = obstack_next_free (&frchain_now->frch_obstack);
4631 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4632 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4633 : BFD_RELOC_ARM_TLS_DESCSEQ);
4634}
cdf9ccec 4635#endif /* OBJ_ELF */
0855e32b 4636
ee065d83 4637static void s_arm_arch (int);
7a1d4c38 4638static void s_arm_object_arch (int);
ee065d83
PB
4639static void s_arm_cpu (int);
4640static void s_arm_fpu (int);
69133863 4641static void s_arm_arch_extension (int);
b99bd4ef 4642
f0927246
NC
4643#ifdef TE_PE
4644
4645static void
5f4273c7 4646pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4647{
4648 expressionS exp;
4649
4650 do
4651 {
4652 expression (&exp);
4653 if (exp.X_op == O_symbol)
4654 exp.X_op = O_secrel;
4655
4656 emit_expr (&exp, 4);
4657 }
4658 while (*input_line_pointer++ == ',');
4659
4660 input_line_pointer--;
4661 demand_empty_rest_of_line ();
4662}
4663#endif /* TE_PE */
4664
c19d1205
ZW
4665/* This table describes all the machine specific pseudo-ops the assembler
4666 has to support. The fields are:
4667 pseudo-op name without dot
4668 function to call to execute this pseudo-op
4669 Integer arg to pass to the function. */
b99bd4ef 4670
c19d1205 4671const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4672{
c19d1205
ZW
4673 /* Never called because '.req' does not start a line. */
4674 { "req", s_req, 0 },
dcbf9037
JB
4675 /* Following two are likewise never called. */
4676 { "dn", s_dn, 0 },
4677 { "qn", s_qn, 0 },
c19d1205
ZW
4678 { "unreq", s_unreq, 0 },
4679 { "bss", s_bss, 0 },
db2ed2e0 4680 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4681 { "arm", s_arm, 0 },
4682 { "thumb", s_thumb, 0 },
4683 { "code", s_code, 0 },
4684 { "force_thumb", s_force_thumb, 0 },
4685 { "thumb_func", s_thumb_func, 0 },
4686 { "thumb_set", s_thumb_set, 0 },
4687 { "even", s_even, 0 },
4688 { "ltorg", s_ltorg, 0 },
4689 { "pool", s_ltorg, 0 },
4690 { "syntax", s_syntax, 0 },
8463be01
PB
4691 { "cpu", s_arm_cpu, 0 },
4692 { "arch", s_arm_arch, 0 },
7a1d4c38 4693 { "object_arch", s_arm_object_arch, 0 },
8463be01 4694 { "fpu", s_arm_fpu, 0 },
69133863 4695 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4696#ifdef OBJ_ELF
c921be7d
NC
4697 { "word", s_arm_elf_cons, 4 },
4698 { "long", s_arm_elf_cons, 4 },
4699 { "inst.n", s_arm_elf_inst, 2 },
4700 { "inst.w", s_arm_elf_inst, 4 },
4701 { "inst", s_arm_elf_inst, 0 },
4702 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4703 { "fnstart", s_arm_unwind_fnstart, 0 },
4704 { "fnend", s_arm_unwind_fnend, 0 },
4705 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4706 { "personality", s_arm_unwind_personality, 0 },
4707 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4708 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4709 { "save", s_arm_unwind_save, 0 },
fa073d69 4710 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4711 { "movsp", s_arm_unwind_movsp, 0 },
4712 { "pad", s_arm_unwind_pad, 0 },
4713 { "setfp", s_arm_unwind_setfp, 0 },
4714 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4715 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4716 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4717#else
4718 { "word", cons, 4},
f0927246
NC
4719
4720 /* These are used for dwarf. */
4721 {"2byte", cons, 2},
4722 {"4byte", cons, 4},
4723 {"8byte", cons, 8},
4724 /* These are used for dwarf2. */
4725 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4726 { "loc", dwarf2_directive_loc, 0 },
4727 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4728#endif
4729 { "extend", float_cons, 'x' },
4730 { "ldouble", float_cons, 'x' },
4731 { "packed", float_cons, 'p' },
f0927246
NC
4732#ifdef TE_PE
4733 {"secrel32", pe_directive_secrel, 0},
4734#endif
2e6976a8
DG
4735
4736 /* These are for compatibility with CodeComposer Studio. */
4737 {"ref", s_ccs_ref, 0},
4738 {"def", s_ccs_def, 0},
4739 {"asmfunc", s_ccs_asmfunc, 0},
4740 {"endasmfunc", s_ccs_endasmfunc, 0},
4741
c19d1205
ZW
4742 { 0, 0, 0 }
4743};
4744\f
4745/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4746
c19d1205
ZW
4747/* Generic immediate-value read function for use in insn parsing.
4748 STR points to the beginning of the immediate (the leading #);
4749 VAL receives the value; if the value is outside [MIN, MAX]
4750 issue an error. PREFIX_OPT is true if the immediate prefix is
4751 optional. */
b99bd4ef 4752
c19d1205
ZW
4753static int
4754parse_immediate (char **str, int *val, int min, int max,
4755 bfd_boolean prefix_opt)
4756{
4757 expressionS exp;
4758 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4759 if (exp.X_op != O_constant)
b99bd4ef 4760 {
c19d1205
ZW
4761 inst.error = _("constant expression required");
4762 return FAIL;
4763 }
b99bd4ef 4764
c19d1205
ZW
4765 if (exp.X_add_number < min || exp.X_add_number > max)
4766 {
4767 inst.error = _("immediate value out of range");
4768 return FAIL;
4769 }
b99bd4ef 4770
c19d1205
ZW
4771 *val = exp.X_add_number;
4772 return SUCCESS;
4773}
b99bd4ef 4774
5287ad62 4775/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4776 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4777 instructions. Puts the result directly in inst.operands[i]. */
4778
4779static int
8335d6aa
JW
4780parse_big_immediate (char **str, int i, expressionS *in_exp,
4781 bfd_boolean allow_symbol_p)
5287ad62
JB
4782{
4783 expressionS exp;
8335d6aa 4784 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4785 char *ptr = *str;
4786
8335d6aa 4787 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4788
8335d6aa 4789 if (exp_p->X_op == O_constant)
036dc3f7 4790 {
8335d6aa 4791 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4792 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4793 O_constant. We have to be careful not to break compilation for
4794 32-bit X_add_number, though. */
8335d6aa 4795 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4796 {
8335d6aa
JW
4797 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4798 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4799 & 0xffffffff);
036dc3f7
PB
4800 inst.operands[i].regisimm = 1;
4801 }
4802 }
8335d6aa
JW
4803 else if (exp_p->X_op == O_big
4804 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4805 {
4806 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4807
5287ad62 4808 /* Bignums have their least significant bits in
477330fc
RM
4809 generic_bignum[0]. Make sure we put 32 bits in imm and
4810 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4811 gas_assert (parts != 0);
95b75c01
NC
4812
4813 /* Make sure that the number is not too big.
4814 PR 11972: Bignums can now be sign-extended to the
4815 size of a .octa so check that the out of range bits
4816 are all zero or all one. */
8335d6aa 4817 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4818 {
4819 LITTLENUM_TYPE m = -1;
4820
4821 if (generic_bignum[parts * 2] != 0
4822 && generic_bignum[parts * 2] != m)
4823 return FAIL;
4824
8335d6aa 4825 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4826 if (generic_bignum[j] != generic_bignum[j-1])
4827 return FAIL;
4828 }
4829
5287ad62
JB
4830 inst.operands[i].imm = 0;
4831 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4832 inst.operands[i].imm |= generic_bignum[idx]
4833 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4834 inst.operands[i].reg = 0;
4835 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4836 inst.operands[i].reg |= generic_bignum[idx]
4837 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4838 inst.operands[i].regisimm = 1;
4839 }
8335d6aa 4840 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4841 return FAIL;
5f4273c7 4842
5287ad62
JB
4843 *str = ptr;
4844
4845 return SUCCESS;
4846}
4847
c19d1205
ZW
4848/* Returns the pseudo-register number of an FPA immediate constant,
4849 or FAIL if there isn't a valid constant here. */
b99bd4ef 4850
c19d1205
ZW
4851static int
4852parse_fpa_immediate (char ** str)
4853{
4854 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4855 char * save_in;
4856 expressionS exp;
4857 int i;
4858 int j;
b99bd4ef 4859
c19d1205
ZW
4860 /* First try and match exact strings, this is to guarantee
4861 that some formats will work even for cross assembly. */
b99bd4ef 4862
c19d1205
ZW
4863 for (i = 0; fp_const[i]; i++)
4864 {
4865 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4866 {
c19d1205 4867 char *start = *str;
b99bd4ef 4868
c19d1205
ZW
4869 *str += strlen (fp_const[i]);
4870 if (is_end_of_line[(unsigned char) **str])
4871 return i + 8;
4872 *str = start;
4873 }
4874 }
b99bd4ef 4875
c19d1205
ZW
4876 /* Just because we didn't get a match doesn't mean that the constant
4877 isn't valid, just that it is in a format that we don't
4878 automatically recognize. Try parsing it with the standard
4879 expression routines. */
b99bd4ef 4880
c19d1205 4881 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4882
c19d1205
ZW
4883 /* Look for a raw floating point number. */
4884 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4885 && is_end_of_line[(unsigned char) *save_in])
4886 {
4887 for (i = 0; i < NUM_FLOAT_VALS; i++)
4888 {
4889 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4890 {
c19d1205
ZW
4891 if (words[j] != fp_values[i][j])
4892 break;
b99bd4ef
NC
4893 }
4894
c19d1205 4895 if (j == MAX_LITTLENUMS)
b99bd4ef 4896 {
c19d1205
ZW
4897 *str = save_in;
4898 return i + 8;
b99bd4ef
NC
4899 }
4900 }
4901 }
b99bd4ef 4902
c19d1205
ZW
4903 /* Try and parse a more complex expression, this will probably fail
4904 unless the code uses a floating point prefix (eg "0f"). */
4905 save_in = input_line_pointer;
4906 input_line_pointer = *str;
4907 if (expression (&exp) == absolute_section
4908 && exp.X_op == O_big
4909 && exp.X_add_number < 0)
4910 {
4911 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4912 Ditto for 15. */
ba592044
AM
4913#define X_PRECISION 5
4914#define E_PRECISION 15L
4915 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4916 {
4917 for (i = 0; i < NUM_FLOAT_VALS; i++)
4918 {
4919 for (j = 0; j < MAX_LITTLENUMS; j++)
4920 {
4921 if (words[j] != fp_values[i][j])
4922 break;
4923 }
b99bd4ef 4924
c19d1205
ZW
4925 if (j == MAX_LITTLENUMS)
4926 {
4927 *str = input_line_pointer;
4928 input_line_pointer = save_in;
4929 return i + 8;
4930 }
4931 }
4932 }
b99bd4ef
NC
4933 }
4934
c19d1205
ZW
4935 *str = input_line_pointer;
4936 input_line_pointer = save_in;
4937 inst.error = _("invalid FPA immediate expression");
4938 return FAIL;
b99bd4ef
NC
4939}
4940
136da414
JB
4941/* Returns 1 if a number has "quarter-precision" float format
4942 0baBbbbbbc defgh000 00000000 00000000. */
4943
4944static int
4945is_quarter_float (unsigned imm)
4946{
4947 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4948 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4949}
4950
aacf0b33
KT
4951
4952/* Detect the presence of a floating point or integer zero constant,
4953 i.e. #0.0 or #0. */
4954
4955static bfd_boolean
4956parse_ifimm_zero (char **in)
4957{
4958 int error_code;
4959
4960 if (!is_immediate_prefix (**in))
4961 return FALSE;
4962
4963 ++*in;
0900a05b
JW
4964
4965 /* Accept #0x0 as a synonym for #0. */
4966 if (strncmp (*in, "0x", 2) == 0)
4967 {
4968 int val;
4969 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4970 return FALSE;
4971 return TRUE;
4972 }
4973
aacf0b33
KT
4974 error_code = atof_generic (in, ".", EXP_CHARS,
4975 &generic_floating_point_number);
4976
4977 if (!error_code
4978 && generic_floating_point_number.sign == '+'
4979 && (generic_floating_point_number.low
4980 > generic_floating_point_number.leader))
4981 return TRUE;
4982
4983 return FALSE;
4984}
4985
136da414
JB
4986/* Parse an 8-bit "quarter-precision" floating point number of the form:
4987 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4988 The zero and minus-zero cases need special handling, since they can't be
4989 encoded in the "quarter-precision" float format, but can nonetheless be
4990 loaded as integer constants. */
136da414
JB
4991
4992static unsigned
4993parse_qfloat_immediate (char **ccp, int *immed)
4994{
4995 char *str = *ccp;
c96612cc 4996 char *fpnum;
136da414 4997 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4998 int found_fpchar = 0;
5f4273c7 4999
136da414 5000 skip_past_char (&str, '#');
5f4273c7 5001
c96612cc
JB
5002 /* We must not accidentally parse an integer as a floating-point number. Make
5003 sure that the value we parse is not an integer by checking for special
5004 characters '.' or 'e'.
5005 FIXME: This is a horrible hack, but doing better is tricky because type
5006 information isn't in a very usable state at parse time. */
5007 fpnum = str;
5008 skip_whitespace (fpnum);
5009
5010 if (strncmp (fpnum, "0x", 2) == 0)
5011 return FAIL;
5012 else
5013 {
5014 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5015 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5016 {
5017 found_fpchar = 1;
5018 break;
5019 }
c96612cc
JB
5020
5021 if (!found_fpchar)
477330fc 5022 return FAIL;
c96612cc 5023 }
5f4273c7 5024
136da414
JB
5025 if ((str = atof_ieee (str, 's', words)) != NULL)
5026 {
5027 unsigned fpword = 0;
5028 int i;
5f4273c7 5029
136da414
JB
5030 /* Our FP word must be 32 bits (single-precision FP). */
5031 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5032 {
5033 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5034 fpword |= words[i];
5035 }
5f4273c7 5036
c96612cc 5037 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5038 *immed = fpword;
136da414 5039 else
477330fc 5040 return FAIL;
136da414
JB
5041
5042 *ccp = str;
5f4273c7 5043
136da414
JB
5044 return SUCCESS;
5045 }
5f4273c7 5046
136da414
JB
5047 return FAIL;
5048}
5049
c19d1205
ZW
5050/* Shift operands. */
5051enum shift_kind
b99bd4ef 5052{
c19d1205
ZW
5053 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5054};
b99bd4ef 5055
c19d1205
ZW
5056struct asm_shift_name
5057{
5058 const char *name;
5059 enum shift_kind kind;
5060};
b99bd4ef 5061
c19d1205
ZW
5062/* Third argument to parse_shift. */
5063enum parse_shift_mode
5064{
5065 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5066 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5067 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5068 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5069 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5070};
b99bd4ef 5071
c19d1205
ZW
5072/* Parse a <shift> specifier on an ARM data processing instruction.
5073 This has three forms:
b99bd4ef 5074
c19d1205
ZW
5075 (LSL|LSR|ASL|ASR|ROR) Rs
5076 (LSL|LSR|ASL|ASR|ROR) #imm
5077 RRX
b99bd4ef 5078
c19d1205
ZW
5079 Note that ASL is assimilated to LSL in the instruction encoding, and
5080 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5081
c19d1205
ZW
5082static int
5083parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5084{
c19d1205
ZW
5085 const struct asm_shift_name *shift_name;
5086 enum shift_kind shift;
5087 char *s = *str;
5088 char *p = s;
5089 int reg;
b99bd4ef 5090
c19d1205
ZW
5091 for (p = *str; ISALPHA (*p); p++)
5092 ;
b99bd4ef 5093
c19d1205 5094 if (p == *str)
b99bd4ef 5095 {
c19d1205
ZW
5096 inst.error = _("shift expression expected");
5097 return FAIL;
b99bd4ef
NC
5098 }
5099
21d799b5 5100 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5101 p - *str);
c19d1205
ZW
5102
5103 if (shift_name == NULL)
b99bd4ef 5104 {
c19d1205
ZW
5105 inst.error = _("shift expression expected");
5106 return FAIL;
b99bd4ef
NC
5107 }
5108
c19d1205 5109 shift = shift_name->kind;
b99bd4ef 5110
c19d1205
ZW
5111 switch (mode)
5112 {
5113 case NO_SHIFT_RESTRICT:
5114 case SHIFT_IMMEDIATE: break;
b99bd4ef 5115
c19d1205
ZW
5116 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5117 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5118 {
5119 inst.error = _("'LSL' or 'ASR' required");
5120 return FAIL;
5121 }
5122 break;
b99bd4ef 5123
c19d1205
ZW
5124 case SHIFT_LSL_IMMEDIATE:
5125 if (shift != SHIFT_LSL)
5126 {
5127 inst.error = _("'LSL' required");
5128 return FAIL;
5129 }
5130 break;
b99bd4ef 5131
c19d1205
ZW
5132 case SHIFT_ASR_IMMEDIATE:
5133 if (shift != SHIFT_ASR)
5134 {
5135 inst.error = _("'ASR' required");
5136 return FAIL;
5137 }
5138 break;
b99bd4ef 5139
c19d1205
ZW
5140 default: abort ();
5141 }
b99bd4ef 5142
c19d1205
ZW
5143 if (shift != SHIFT_RRX)
5144 {
5145 /* Whitespace can appear here if the next thing is a bare digit. */
5146 skip_whitespace (p);
b99bd4ef 5147
c19d1205 5148 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5149 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5150 {
5151 inst.operands[i].imm = reg;
5152 inst.operands[i].immisreg = 1;
5153 }
5154 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5155 return FAIL;
5156 }
5157 inst.operands[i].shift_kind = shift;
5158 inst.operands[i].shifted = 1;
5159 *str = p;
5160 return SUCCESS;
b99bd4ef
NC
5161}
5162
c19d1205 5163/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5164
c19d1205
ZW
5165 #<immediate>
5166 #<immediate>, <rotate>
5167 <Rm>
5168 <Rm>, <shift>
b99bd4ef 5169
c19d1205
ZW
5170 where <shift> is defined by parse_shift above, and <rotate> is a
5171 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5172 is deferred to md_apply_fix. */
b99bd4ef 5173
c19d1205
ZW
5174static int
5175parse_shifter_operand (char **str, int i)
5176{
5177 int value;
91d6fa6a 5178 expressionS exp;
b99bd4ef 5179
dcbf9037 5180 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5181 {
5182 inst.operands[i].reg = value;
5183 inst.operands[i].isreg = 1;
b99bd4ef 5184
c19d1205
ZW
5185 /* parse_shift will override this if appropriate */
5186 inst.reloc.exp.X_op = O_constant;
5187 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5188
c19d1205
ZW
5189 if (skip_past_comma (str) == FAIL)
5190 return SUCCESS;
b99bd4ef 5191
c19d1205
ZW
5192 /* Shift operation on register. */
5193 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5194 }
5195
c19d1205
ZW
5196 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5197 return FAIL;
b99bd4ef 5198
c19d1205 5199 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5200 {
c19d1205 5201 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5202 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5203 return FAIL;
b99bd4ef 5204
91d6fa6a 5205 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5206 {
5207 inst.error = _("constant expression expected");
5208 return FAIL;
5209 }
b99bd4ef 5210
91d6fa6a 5211 value = exp.X_add_number;
c19d1205
ZW
5212 if (value < 0 || value > 30 || value % 2 != 0)
5213 {
5214 inst.error = _("invalid rotation");
5215 return FAIL;
5216 }
5217 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5218 {
5219 inst.error = _("invalid constant");
5220 return FAIL;
5221 }
09d92015 5222
a415b1cd
JB
5223 /* Encode as specified. */
5224 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5225 return SUCCESS;
09d92015
MM
5226 }
5227
c19d1205
ZW
5228 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5229 inst.reloc.pc_rel = 0;
5230 return SUCCESS;
09d92015
MM
5231}
5232
4962c51a
MS
5233/* Group relocation information. Each entry in the table contains the
5234 textual name of the relocation as may appear in assembler source
5235 and must end with a colon.
5236 Along with this textual name are the relocation codes to be used if
5237 the corresponding instruction is an ALU instruction (ADD or SUB only),
5238 an LDR, an LDRS, or an LDC. */
5239
5240struct group_reloc_table_entry
5241{
5242 const char *name;
5243 int alu_code;
5244 int ldr_code;
5245 int ldrs_code;
5246 int ldc_code;
5247};
5248
5249typedef enum
5250{
5251 /* Varieties of non-ALU group relocation. */
5252
5253 GROUP_LDR,
5254 GROUP_LDRS,
5255 GROUP_LDC
5256} group_reloc_type;
5257
5258static struct group_reloc_table_entry group_reloc_table[] =
5259 { /* Program counter relative: */
5260 { "pc_g0_nc",
5261 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5262 0, /* LDR */
5263 0, /* LDRS */
5264 0 }, /* LDC */
5265 { "pc_g0",
5266 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5267 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5268 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5269 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5270 { "pc_g1_nc",
5271 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5272 0, /* LDR */
5273 0, /* LDRS */
5274 0 }, /* LDC */
5275 { "pc_g1",
5276 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5277 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5278 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5279 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5280 { "pc_g2",
5281 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5282 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5283 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5284 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5285 /* Section base relative */
5286 { "sb_g0_nc",
5287 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5288 0, /* LDR */
5289 0, /* LDRS */
5290 0 }, /* LDC */
5291 { "sb_g0",
5292 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5293 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5294 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5295 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5296 { "sb_g1_nc",
5297 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5298 0, /* LDR */
5299 0, /* LDRS */
5300 0 }, /* LDC */
5301 { "sb_g1",
5302 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5303 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5304 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5305 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5306 { "sb_g2",
5307 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5308 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5309 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5310 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5311 /* Absolute thumb alu relocations. */
5312 { "lower0_7",
5313 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5314 0, /* LDR. */
5315 0, /* LDRS. */
5316 0 }, /* LDC. */
5317 { "lower8_15",
5318 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5319 0, /* LDR. */
5320 0, /* LDRS. */
5321 0 }, /* LDC. */
5322 { "upper0_7",
5323 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5324 0, /* LDR. */
5325 0, /* LDRS. */
5326 0 }, /* LDC. */
5327 { "upper8_15",
5328 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5329 0, /* LDR. */
5330 0, /* LDRS. */
5331 0 } }; /* LDC. */
4962c51a
MS
5332
5333/* Given the address of a pointer pointing to the textual name of a group
5334 relocation as may appear in assembler source, attempt to find its details
5335 in group_reloc_table. The pointer will be updated to the character after
5336 the trailing colon. On failure, FAIL will be returned; SUCCESS
5337 otherwise. On success, *entry will be updated to point at the relevant
5338 group_reloc_table entry. */
5339
5340static int
5341find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5342{
5343 unsigned int i;
5344 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5345 {
5346 int length = strlen (group_reloc_table[i].name);
5347
5f4273c7
NC
5348 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5349 && (*str)[length] == ':')
477330fc
RM
5350 {
5351 *out = &group_reloc_table[i];
5352 *str += (length + 1);
5353 return SUCCESS;
5354 }
4962c51a
MS
5355 }
5356
5357 return FAIL;
5358}
5359
5360/* Parse a <shifter_operand> for an ARM data processing instruction
5361 (as for parse_shifter_operand) where group relocations are allowed:
5362
5363 #<immediate>
5364 #<immediate>, <rotate>
5365 #:<group_reloc>:<expression>
5366 <Rm>
5367 <Rm>, <shift>
5368
5369 where <group_reloc> is one of the strings defined in group_reloc_table.
5370 The hashes are optional.
5371
5372 Everything else is as for parse_shifter_operand. */
5373
5374static parse_operand_result
5375parse_shifter_operand_group_reloc (char **str, int i)
5376{
5377 /* Determine if we have the sequence of characters #: or just :
5378 coming next. If we do, then we check for a group relocation.
5379 If we don't, punt the whole lot to parse_shifter_operand. */
5380
5381 if (((*str)[0] == '#' && (*str)[1] == ':')
5382 || (*str)[0] == ':')
5383 {
5384 struct group_reloc_table_entry *entry;
5385
5386 if ((*str)[0] == '#')
477330fc 5387 (*str) += 2;
4962c51a 5388 else
477330fc 5389 (*str)++;
4962c51a
MS
5390
5391 /* Try to parse a group relocation. Anything else is an error. */
5392 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5393 {
5394 inst.error = _("unknown group relocation");
5395 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5396 }
4962c51a
MS
5397
5398 /* We now have the group relocation table entry corresponding to
477330fc 5399 the name in the assembler source. Next, we parse the expression. */
4962c51a 5400 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5401 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5402
5403 /* Record the relocation type (always the ALU variant here). */
21d799b5 5404 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5405 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5406
5407 return PARSE_OPERAND_SUCCESS;
5408 }
5409 else
5410 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5411 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5412
5413 /* Never reached. */
5414}
5415
8e560766
MGD
5416/* Parse a Neon alignment expression. Information is written to
5417 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5418
8e560766
MGD
5419 align .imm = align << 8, .immisalign=1, .preind=0 */
5420static parse_operand_result
5421parse_neon_alignment (char **str, int i)
5422{
5423 char *p = *str;
5424 expressionS exp;
5425
5426 my_get_expression (&exp, &p, GE_NO_PREFIX);
5427
5428 if (exp.X_op != O_constant)
5429 {
5430 inst.error = _("alignment must be constant");
5431 return PARSE_OPERAND_FAIL;
5432 }
5433
5434 inst.operands[i].imm = exp.X_add_number << 8;
5435 inst.operands[i].immisalign = 1;
5436 /* Alignments are not pre-indexes. */
5437 inst.operands[i].preind = 0;
5438
5439 *str = p;
5440 return PARSE_OPERAND_SUCCESS;
5441}
5442
c19d1205
ZW
5443/* Parse all forms of an ARM address expression. Information is written
5444 to inst.operands[i] and/or inst.reloc.
09d92015 5445
c19d1205 5446 Preindexed addressing (.preind=1):
09d92015 5447
c19d1205
ZW
5448 [Rn, #offset] .reg=Rn .reloc.exp=offset
5449 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5450 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5451 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5452
c19d1205 5453 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5454
c19d1205 5455 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5456
c19d1205
ZW
5457 [Rn], #offset .reg=Rn .reloc.exp=offset
5458 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5459 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5460 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5461
c19d1205 5462 Unindexed addressing (.preind=0, .postind=0):
09d92015 5463
c19d1205 5464 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5465
c19d1205 5466 Other:
09d92015 5467
c19d1205
ZW
5468 [Rn]{!} shorthand for [Rn,#0]{!}
5469 =immediate .isreg=0 .reloc.exp=immediate
5470 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5471
c19d1205
ZW
5472 It is the caller's responsibility to check for addressing modes not
5473 supported by the instruction, and to set inst.reloc.type. */
5474
4962c51a
MS
5475static parse_operand_result
5476parse_address_main (char **str, int i, int group_relocations,
477330fc 5477 group_reloc_type group_type)
09d92015 5478{
c19d1205
ZW
5479 char *p = *str;
5480 int reg;
09d92015 5481
c19d1205 5482 if (skip_past_char (&p, '[') == FAIL)
09d92015 5483 {
c19d1205
ZW
5484 if (skip_past_char (&p, '=') == FAIL)
5485 {
974da60d 5486 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5487 inst.reloc.pc_rel = 1;
5488 inst.operands[i].reg = REG_PC;
5489 inst.operands[i].isreg = 1;
5490 inst.operands[i].preind = 1;
09d92015 5491
8335d6aa
JW
5492 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5493 return PARSE_OPERAND_FAIL;
5494 }
5495 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5496 /*allow_symbol_p=*/TRUE))
4962c51a 5497 return PARSE_OPERAND_FAIL;
09d92015 5498
c19d1205 5499 *str = p;
4962c51a 5500 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5501 }
5502
8ab8155f
NC
5503 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5504 skip_whitespace (p);
5505
dcbf9037 5506 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5507 {
c19d1205 5508 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5509 return PARSE_OPERAND_FAIL;
09d92015 5510 }
c19d1205
ZW
5511 inst.operands[i].reg = reg;
5512 inst.operands[i].isreg = 1;
09d92015 5513
c19d1205 5514 if (skip_past_comma (&p) == SUCCESS)
09d92015 5515 {
c19d1205 5516 inst.operands[i].preind = 1;
09d92015 5517
c19d1205
ZW
5518 if (*p == '+') p++;
5519 else if (*p == '-') p++, inst.operands[i].negative = 1;
5520
dcbf9037 5521 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5522 {
c19d1205
ZW
5523 inst.operands[i].imm = reg;
5524 inst.operands[i].immisreg = 1;
5525
5526 if (skip_past_comma (&p) == SUCCESS)
5527 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5528 return PARSE_OPERAND_FAIL;
c19d1205 5529 }
5287ad62 5530 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5531 {
5532 /* FIXME: '@' should be used here, but it's filtered out by generic
5533 code before we get to see it here. This may be subject to
5534 change. */
5535 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5536
8e560766
MGD
5537 if (result != PARSE_OPERAND_SUCCESS)
5538 return result;
5539 }
c19d1205
ZW
5540 else
5541 {
5542 if (inst.operands[i].negative)
5543 {
5544 inst.operands[i].negative = 0;
5545 p--;
5546 }
4962c51a 5547
5f4273c7
NC
5548 if (group_relocations
5549 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5550 {
5551 struct group_reloc_table_entry *entry;
5552
477330fc
RM
5553 /* Skip over the #: or : sequence. */
5554 if (*p == '#')
5555 p += 2;
5556 else
5557 p++;
4962c51a
MS
5558
5559 /* Try to parse a group relocation. Anything else is an
477330fc 5560 error. */
4962c51a
MS
5561 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5562 {
5563 inst.error = _("unknown group relocation");
5564 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5565 }
5566
5567 /* We now have the group relocation table entry corresponding to
5568 the name in the assembler source. Next, we parse the
477330fc 5569 expression. */
4962c51a
MS
5570 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5571 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5572
5573 /* Record the relocation type. */
477330fc
RM
5574 switch (group_type)
5575 {
5576 case GROUP_LDR:
5577 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5578 break;
4962c51a 5579
477330fc
RM
5580 case GROUP_LDRS:
5581 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5582 break;
4962c51a 5583
477330fc
RM
5584 case GROUP_LDC:
5585 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5586 break;
4962c51a 5587
477330fc
RM
5588 default:
5589 gas_assert (0);
5590 }
4962c51a 5591
477330fc 5592 if (inst.reloc.type == 0)
4962c51a
MS
5593 {
5594 inst.error = _("this group relocation is not allowed on this instruction");
5595 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5596 }
477330fc
RM
5597 }
5598 else
26d97720
NS
5599 {
5600 char *q = p;
5601 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5602 return PARSE_OPERAND_FAIL;
5603 /* If the offset is 0, find out if it's a +0 or -0. */
5604 if (inst.reloc.exp.X_op == O_constant
5605 && inst.reloc.exp.X_add_number == 0)
5606 {
5607 skip_whitespace (q);
5608 if (*q == '#')
5609 {
5610 q++;
5611 skip_whitespace (q);
5612 }
5613 if (*q == '-')
5614 inst.operands[i].negative = 1;
5615 }
5616 }
09d92015
MM
5617 }
5618 }
8e560766
MGD
5619 else if (skip_past_char (&p, ':') == SUCCESS)
5620 {
5621 /* FIXME: '@' should be used here, but it's filtered out by generic code
5622 before we get to see it here. This may be subject to change. */
5623 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5624
8e560766
MGD
5625 if (result != PARSE_OPERAND_SUCCESS)
5626 return result;
5627 }
09d92015 5628
c19d1205 5629 if (skip_past_char (&p, ']') == FAIL)
09d92015 5630 {
c19d1205 5631 inst.error = _("']' expected");
4962c51a 5632 return PARSE_OPERAND_FAIL;
09d92015
MM
5633 }
5634
c19d1205
ZW
5635 if (skip_past_char (&p, '!') == SUCCESS)
5636 inst.operands[i].writeback = 1;
09d92015 5637
c19d1205 5638 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5639 {
c19d1205
ZW
5640 if (skip_past_char (&p, '{') == SUCCESS)
5641 {
5642 /* [Rn], {expr} - unindexed, with option */
5643 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5644 0, 255, TRUE) == FAIL)
4962c51a 5645 return PARSE_OPERAND_FAIL;
09d92015 5646
c19d1205
ZW
5647 if (skip_past_char (&p, '}') == FAIL)
5648 {
5649 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5650 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5651 }
5652 if (inst.operands[i].preind)
5653 {
5654 inst.error = _("cannot combine index with option");
4962c51a 5655 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5656 }
5657 *str = p;
4962c51a 5658 return PARSE_OPERAND_SUCCESS;
09d92015 5659 }
c19d1205
ZW
5660 else
5661 {
5662 inst.operands[i].postind = 1;
5663 inst.operands[i].writeback = 1;
09d92015 5664
c19d1205
ZW
5665 if (inst.operands[i].preind)
5666 {
5667 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5668 return PARSE_OPERAND_FAIL;
c19d1205 5669 }
09d92015 5670
c19d1205
ZW
5671 if (*p == '+') p++;
5672 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5673
dcbf9037 5674 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5675 {
477330fc
RM
5676 /* We might be using the immediate for alignment already. If we
5677 are, OR the register number into the low-order bits. */
5678 if (inst.operands[i].immisalign)
5679 inst.operands[i].imm |= reg;
5680 else
5681 inst.operands[i].imm = reg;
c19d1205 5682 inst.operands[i].immisreg = 1;
a737bd4d 5683
c19d1205
ZW
5684 if (skip_past_comma (&p) == SUCCESS)
5685 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5686 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5687 }
5688 else
5689 {
26d97720 5690 char *q = p;
c19d1205
ZW
5691 if (inst.operands[i].negative)
5692 {
5693 inst.operands[i].negative = 0;
5694 p--;
5695 }
5696 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5697 return PARSE_OPERAND_FAIL;
26d97720
NS
5698 /* If the offset is 0, find out if it's a +0 or -0. */
5699 if (inst.reloc.exp.X_op == O_constant
5700 && inst.reloc.exp.X_add_number == 0)
5701 {
5702 skip_whitespace (q);
5703 if (*q == '#')
5704 {
5705 q++;
5706 skip_whitespace (q);
5707 }
5708 if (*q == '-')
5709 inst.operands[i].negative = 1;
5710 }
c19d1205
ZW
5711 }
5712 }
a737bd4d
NC
5713 }
5714
c19d1205
ZW
5715 /* If at this point neither .preind nor .postind is set, we have a
5716 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5717 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5718 {
5719 inst.operands[i].preind = 1;
5720 inst.reloc.exp.X_op = O_constant;
5721 inst.reloc.exp.X_add_number = 0;
5722 }
5723 *str = p;
4962c51a
MS
5724 return PARSE_OPERAND_SUCCESS;
5725}
5726
5727static int
5728parse_address (char **str, int i)
5729{
21d799b5 5730 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5731 ? SUCCESS : FAIL;
4962c51a
MS
5732}
5733
5734static parse_operand_result
5735parse_address_group_reloc (char **str, int i, group_reloc_type type)
5736{
5737 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5738}
5739
b6895b4f
PB
5740/* Parse an operand for a MOVW or MOVT instruction. */
5741static int
5742parse_half (char **str)
5743{
5744 char * p;
5f4273c7 5745
b6895b4f
PB
5746 p = *str;
5747 skip_past_char (&p, '#');
5f4273c7 5748 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5749 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5750 else if (strncasecmp (p, ":upper16:", 9) == 0)
5751 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5752
5753 if (inst.reloc.type != BFD_RELOC_UNUSED)
5754 {
5755 p += 9;
5f4273c7 5756 skip_whitespace (p);
b6895b4f
PB
5757 }
5758
5759 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5760 return FAIL;
5761
5762 if (inst.reloc.type == BFD_RELOC_UNUSED)
5763 {
5764 if (inst.reloc.exp.X_op != O_constant)
5765 {
5766 inst.error = _("constant expression expected");
5767 return FAIL;
5768 }
5769 if (inst.reloc.exp.X_add_number < 0
5770 || inst.reloc.exp.X_add_number > 0xffff)
5771 {
5772 inst.error = _("immediate value out of range");
5773 return FAIL;
5774 }
5775 }
5776 *str = p;
5777 return SUCCESS;
5778}
5779
c19d1205 5780/* Miscellaneous. */
a737bd4d 5781
c19d1205
ZW
5782/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5783 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5784static int
d2cd1205 5785parse_psr (char **str, bfd_boolean lhs)
09d92015 5786{
c19d1205
ZW
5787 char *p;
5788 unsigned long psr_field;
62b3e311
PB
5789 const struct asm_psr *psr;
5790 char *start;
d2cd1205 5791 bfd_boolean is_apsr = FALSE;
ac7f631b 5792 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5793
a4482bb6
NC
5794 /* PR gas/12698: If the user has specified -march=all then m_profile will
5795 be TRUE, but we want to ignore it in this case as we are building for any
5796 CPU type, including non-m variants. */
823d2571 5797 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5798 m_profile = FALSE;
5799
c19d1205
ZW
5800 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5801 feature for ease of use and backwards compatibility. */
5802 p = *str;
62b3e311 5803 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5804 {
5805 if (m_profile)
5806 goto unsupported_psr;
fa94de6b 5807
d2cd1205
JB
5808 psr_field = SPSR_BIT;
5809 }
5810 else if (strncasecmp (p, "CPSR", 4) == 0)
5811 {
5812 if (m_profile)
5813 goto unsupported_psr;
5814
5815 psr_field = 0;
5816 }
5817 else if (strncasecmp (p, "APSR", 4) == 0)
5818 {
5819 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5820 and ARMv7-R architecture CPUs. */
5821 is_apsr = TRUE;
5822 psr_field = 0;
5823 }
5824 else if (m_profile)
62b3e311
PB
5825 {
5826 start = p;
5827 do
5828 p++;
5829 while (ISALNUM (*p) || *p == '_');
5830
d2cd1205
JB
5831 if (strncasecmp (start, "iapsr", 5) == 0
5832 || strncasecmp (start, "eapsr", 5) == 0
5833 || strncasecmp (start, "xpsr", 4) == 0
5834 || strncasecmp (start, "psr", 3) == 0)
5835 p = start + strcspn (start, "rR") + 1;
5836
21d799b5 5837 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5838 p - start);
d2cd1205 5839
62b3e311
PB
5840 if (!psr)
5841 return FAIL;
09d92015 5842
d2cd1205
JB
5843 /* If APSR is being written, a bitfield may be specified. Note that
5844 APSR itself is handled above. */
5845 if (psr->field <= 3)
5846 {
5847 psr_field = psr->field;
5848 is_apsr = TRUE;
5849 goto check_suffix;
5850 }
5851
62b3e311 5852 *str = p;
d2cd1205
JB
5853 /* M-profile MSR instructions have the mask field set to "10", except
5854 *PSR variants which modify APSR, which may use a different mask (and
5855 have been handled already). Do that by setting the PSR_f field
5856 here. */
5857 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5858 }
d2cd1205
JB
5859 else
5860 goto unsupported_psr;
09d92015 5861
62b3e311 5862 p += 4;
d2cd1205 5863check_suffix:
c19d1205
ZW
5864 if (*p == '_')
5865 {
5866 /* A suffix follows. */
c19d1205
ZW
5867 p++;
5868 start = p;
a737bd4d 5869
c19d1205
ZW
5870 do
5871 p++;
5872 while (ISALNUM (*p) || *p == '_');
a737bd4d 5873
d2cd1205
JB
5874 if (is_apsr)
5875 {
5876 /* APSR uses a notation for bits, rather than fields. */
5877 unsigned int nzcvq_bits = 0;
5878 unsigned int g_bit = 0;
5879 char *bit;
fa94de6b 5880
d2cd1205
JB
5881 for (bit = start; bit != p; bit++)
5882 {
5883 switch (TOLOWER (*bit))
477330fc 5884 {
d2cd1205
JB
5885 case 'n':
5886 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5887 break;
5888
5889 case 'z':
5890 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5891 break;
5892
5893 case 'c':
5894 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5895 break;
5896
5897 case 'v':
5898 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5899 break;
fa94de6b 5900
d2cd1205
JB
5901 case 'q':
5902 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5903 break;
fa94de6b 5904
d2cd1205
JB
5905 case 'g':
5906 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5907 break;
fa94de6b 5908
d2cd1205
JB
5909 default:
5910 inst.error = _("unexpected bit specified after APSR");
5911 return FAIL;
5912 }
5913 }
fa94de6b 5914
d2cd1205
JB
5915 if (nzcvq_bits == 0x1f)
5916 psr_field |= PSR_f;
fa94de6b 5917
d2cd1205
JB
5918 if (g_bit == 0x1)
5919 {
5920 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5921 {
d2cd1205
JB
5922 inst.error = _("selected processor does not "
5923 "support DSP extension");
5924 return FAIL;
5925 }
5926
5927 psr_field |= PSR_s;
5928 }
fa94de6b 5929
d2cd1205
JB
5930 if ((nzcvq_bits & 0x20) != 0
5931 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5932 || (g_bit & 0x2) != 0)
5933 {
5934 inst.error = _("bad bitmask specified after APSR");
5935 return FAIL;
5936 }
5937 }
5938 else
477330fc 5939 {
d2cd1205 5940 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5941 p - start);
d2cd1205 5942 if (!psr)
477330fc 5943 goto error;
a737bd4d 5944
d2cd1205
JB
5945 psr_field |= psr->field;
5946 }
a737bd4d 5947 }
c19d1205 5948 else
a737bd4d 5949 {
c19d1205
ZW
5950 if (ISALNUM (*p))
5951 goto error; /* Garbage after "[CS]PSR". */
5952
d2cd1205 5953 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5954 is deprecated, but allow it anyway. */
d2cd1205
JB
5955 if (is_apsr && lhs)
5956 {
5957 psr_field |= PSR_f;
5958 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5959 "deprecated"));
5960 }
5961 else if (!m_profile)
5962 /* These bits are never right for M-profile devices: don't set them
5963 (only code paths which read/write APSR reach here). */
5964 psr_field |= (PSR_c | PSR_f);
a737bd4d 5965 }
c19d1205
ZW
5966 *str = p;
5967 return psr_field;
a737bd4d 5968
d2cd1205
JB
5969 unsupported_psr:
5970 inst.error = _("selected processor does not support requested special "
5971 "purpose register");
5972 return FAIL;
5973
c19d1205
ZW
5974 error:
5975 inst.error = _("flag for {c}psr instruction expected");
5976 return FAIL;
a737bd4d
NC
5977}
5978
c19d1205
ZW
5979/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5980 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5981
c19d1205
ZW
5982static int
5983parse_cps_flags (char **str)
a737bd4d 5984{
c19d1205
ZW
5985 int val = 0;
5986 int saw_a_flag = 0;
5987 char *s = *str;
a737bd4d 5988
c19d1205
ZW
5989 for (;;)
5990 switch (*s++)
5991 {
5992 case '\0': case ',':
5993 goto done;
a737bd4d 5994
c19d1205
ZW
5995 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5996 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5997 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5998
c19d1205
ZW
5999 default:
6000 inst.error = _("unrecognized CPS flag");
6001 return FAIL;
6002 }
a737bd4d 6003
c19d1205
ZW
6004 done:
6005 if (saw_a_flag == 0)
a737bd4d 6006 {
c19d1205
ZW
6007 inst.error = _("missing CPS flags");
6008 return FAIL;
a737bd4d 6009 }
a737bd4d 6010
c19d1205
ZW
6011 *str = s - 1;
6012 return val;
a737bd4d
NC
6013}
6014
c19d1205
ZW
6015/* Parse an endian specifier ("BE" or "LE", case insensitive);
6016 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6017
6018static int
c19d1205 6019parse_endian_specifier (char **str)
a737bd4d 6020{
c19d1205
ZW
6021 int little_endian;
6022 char *s = *str;
a737bd4d 6023
c19d1205
ZW
6024 if (strncasecmp (s, "BE", 2))
6025 little_endian = 0;
6026 else if (strncasecmp (s, "LE", 2))
6027 little_endian = 1;
6028 else
a737bd4d 6029 {
c19d1205 6030 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6031 return FAIL;
6032 }
6033
c19d1205 6034 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6035 {
c19d1205 6036 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6037 return FAIL;
6038 }
6039
c19d1205
ZW
6040 *str = s + 2;
6041 return little_endian;
6042}
a737bd4d 6043
c19d1205
ZW
6044/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6045 value suitable for poking into the rotate field of an sxt or sxta
6046 instruction, or FAIL on error. */
6047
6048static int
6049parse_ror (char **str)
6050{
6051 int rot;
6052 char *s = *str;
6053
6054 if (strncasecmp (s, "ROR", 3) == 0)
6055 s += 3;
6056 else
a737bd4d 6057 {
c19d1205 6058 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6059 return FAIL;
6060 }
c19d1205
ZW
6061
6062 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6063 return FAIL;
6064
6065 switch (rot)
a737bd4d 6066 {
c19d1205
ZW
6067 case 0: *str = s; return 0x0;
6068 case 8: *str = s; return 0x1;
6069 case 16: *str = s; return 0x2;
6070 case 24: *str = s; return 0x3;
6071
6072 default:
6073 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6074 return FAIL;
6075 }
c19d1205 6076}
a737bd4d 6077
c19d1205
ZW
6078/* Parse a conditional code (from conds[] below). The value returned is in the
6079 range 0 .. 14, or FAIL. */
6080static int
6081parse_cond (char **str)
6082{
c462b453 6083 char *q;
c19d1205 6084 const struct asm_cond *c;
c462b453
PB
6085 int n;
6086 /* Condition codes are always 2 characters, so matching up to
6087 3 characters is sufficient. */
6088 char cond[3];
a737bd4d 6089
c462b453
PB
6090 q = *str;
6091 n = 0;
6092 while (ISALPHA (*q) && n < 3)
6093 {
e07e6e58 6094 cond[n] = TOLOWER (*q);
c462b453
PB
6095 q++;
6096 n++;
6097 }
a737bd4d 6098
21d799b5 6099 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6100 if (!c)
a737bd4d 6101 {
c19d1205 6102 inst.error = _("condition required");
a737bd4d
NC
6103 return FAIL;
6104 }
6105
c19d1205
ZW
6106 *str = q;
6107 return c->value;
6108}
6109
643afb90
MW
6110/* Record a use of the given feature. */
6111static void
6112record_feature_use (const arm_feature_set *feature)
6113{
6114 if (thumb_mode)
6115 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6116 else
6117 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6118}
6119
e797f7e0
MGD
6120/* If the given feature available in the selected CPU, mark it as used.
6121 Returns TRUE iff feature is available. */
6122static bfd_boolean
6123mark_feature_used (const arm_feature_set *feature)
6124{
6125 /* Ensure the option is valid on the current architecture. */
6126 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6127 return FALSE;
6128
6129 /* Add the appropriate architecture feature for the barrier option used.
6130 */
643afb90 6131 record_feature_use (feature);
e797f7e0
MGD
6132
6133 return TRUE;
6134}
6135
62b3e311
PB
6136/* Parse an option for a barrier instruction. Returns the encoding for the
6137 option, or FAIL. */
6138static int
6139parse_barrier (char **str)
6140{
6141 char *p, *q;
6142 const struct asm_barrier_opt *o;
6143
6144 p = q = *str;
6145 while (ISALPHA (*q))
6146 q++;
6147
21d799b5 6148 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6149 q - p);
62b3e311
PB
6150 if (!o)
6151 return FAIL;
6152
e797f7e0
MGD
6153 if (!mark_feature_used (&o->arch))
6154 return FAIL;
6155
62b3e311
PB
6156 *str = q;
6157 return o->value;
6158}
6159
92e90b6e
PB
6160/* Parse the operands of a table branch instruction. Similar to a memory
6161 operand. */
6162static int
6163parse_tb (char **str)
6164{
6165 char * p = *str;
6166 int reg;
6167
6168 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6169 {
6170 inst.error = _("'[' expected");
6171 return FAIL;
6172 }
92e90b6e 6173
dcbf9037 6174 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6175 {
6176 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6177 return FAIL;
6178 }
6179 inst.operands[0].reg = reg;
6180
6181 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6182 {
6183 inst.error = _("',' expected");
6184 return FAIL;
6185 }
5f4273c7 6186
dcbf9037 6187 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6188 {
6189 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6190 return FAIL;
6191 }
6192 inst.operands[0].imm = reg;
6193
6194 if (skip_past_comma (&p) == SUCCESS)
6195 {
6196 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6197 return FAIL;
6198 if (inst.reloc.exp.X_add_number != 1)
6199 {
6200 inst.error = _("invalid shift");
6201 return FAIL;
6202 }
6203 inst.operands[0].shifted = 1;
6204 }
6205
6206 if (skip_past_char (&p, ']') == FAIL)
6207 {
6208 inst.error = _("']' expected");
6209 return FAIL;
6210 }
6211 *str = p;
6212 return SUCCESS;
6213}
6214
5287ad62
JB
6215/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6216 information on the types the operands can take and how they are encoded.
037e8744
JB
6217 Up to four operands may be read; this function handles setting the
6218 ".present" field for each read operand itself.
5287ad62
JB
6219 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6220 else returns FAIL. */
6221
6222static int
6223parse_neon_mov (char **str, int *which_operand)
6224{
6225 int i = *which_operand, val;
6226 enum arm_reg_type rtype;
6227 char *ptr = *str;
dcbf9037 6228 struct neon_type_el optype;
5f4273c7 6229
dcbf9037 6230 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6231 {
6232 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6233 inst.operands[i].reg = val;
6234 inst.operands[i].isscalar = 1;
dcbf9037 6235 inst.operands[i].vectype = optype;
5287ad62
JB
6236 inst.operands[i++].present = 1;
6237
6238 if (skip_past_comma (&ptr) == FAIL)
477330fc 6239 goto wanted_comma;
5f4273c7 6240
dcbf9037 6241 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6242 goto wanted_arm;
5f4273c7 6243
5287ad62
JB
6244 inst.operands[i].reg = val;
6245 inst.operands[i].isreg = 1;
6246 inst.operands[i].present = 1;
6247 }
037e8744 6248 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6249 != FAIL)
5287ad62
JB
6250 {
6251 /* Cases 0, 1, 2, 3, 5 (D only). */
6252 if (skip_past_comma (&ptr) == FAIL)
477330fc 6253 goto wanted_comma;
5f4273c7 6254
5287ad62
JB
6255 inst.operands[i].reg = val;
6256 inst.operands[i].isreg = 1;
6257 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6258 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6259 inst.operands[i].isvec = 1;
dcbf9037 6260 inst.operands[i].vectype = optype;
5287ad62
JB
6261 inst.operands[i++].present = 1;
6262
dcbf9037 6263 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6264 {
6265 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6266 Case 13: VMOV <Sd>, <Rm> */
6267 inst.operands[i].reg = val;
6268 inst.operands[i].isreg = 1;
6269 inst.operands[i].present = 1;
6270
6271 if (rtype == REG_TYPE_NQ)
6272 {
6273 first_error (_("can't use Neon quad register here"));
6274 return FAIL;
6275 }
6276 else if (rtype != REG_TYPE_VFS)
6277 {
6278 i++;
6279 if (skip_past_comma (&ptr) == FAIL)
6280 goto wanted_comma;
6281 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6282 goto wanted_arm;
6283 inst.operands[i].reg = val;
6284 inst.operands[i].isreg = 1;
6285 inst.operands[i].present = 1;
6286 }
6287 }
037e8744 6288 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6289 &optype)) != FAIL)
6290 {
6291 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6292 Case 1: VMOV<c><q> <Dd>, <Dm>
6293 Case 8: VMOV.F32 <Sd>, <Sm>
6294 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6295
6296 inst.operands[i].reg = val;
6297 inst.operands[i].isreg = 1;
6298 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6299 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6300 inst.operands[i].isvec = 1;
6301 inst.operands[i].vectype = optype;
6302 inst.operands[i].present = 1;
6303
6304 if (skip_past_comma (&ptr) == SUCCESS)
6305 {
6306 /* Case 15. */
6307 i++;
6308
6309 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6310 goto wanted_arm;
6311
6312 inst.operands[i].reg = val;
6313 inst.operands[i].isreg = 1;
6314 inst.operands[i++].present = 1;
6315
6316 if (skip_past_comma (&ptr) == FAIL)
6317 goto wanted_comma;
6318
6319 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6320 goto wanted_arm;
6321
6322 inst.operands[i].reg = val;
6323 inst.operands[i].isreg = 1;
6324 inst.operands[i].present = 1;
6325 }
6326 }
4641781c 6327 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6328 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6329 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6330 Case 10: VMOV.F32 <Sd>, #<imm>
6331 Case 11: VMOV.F64 <Dd>, #<imm> */
6332 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6333 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6334 == SUCCESS)
477330fc
RM
6335 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6336 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6337 ;
5287ad62 6338 else
477330fc
RM
6339 {
6340 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6341 return FAIL;
6342 }
5287ad62 6343 }
dcbf9037 6344 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6345 {
6346 /* Cases 6, 7. */
6347 inst.operands[i].reg = val;
6348 inst.operands[i].isreg = 1;
6349 inst.operands[i++].present = 1;
5f4273c7 6350
5287ad62 6351 if (skip_past_comma (&ptr) == FAIL)
477330fc 6352 goto wanted_comma;
5f4273c7 6353
dcbf9037 6354 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6355 {
6356 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6357 inst.operands[i].reg = val;
6358 inst.operands[i].isscalar = 1;
6359 inst.operands[i].present = 1;
6360 inst.operands[i].vectype = optype;
6361 }
dcbf9037 6362 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6363 {
6364 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i++].present = 1;
6368
6369 if (skip_past_comma (&ptr) == FAIL)
6370 goto wanted_comma;
6371
6372 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6373 == FAIL)
6374 {
6375 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6376 return FAIL;
6377 }
6378
6379 inst.operands[i].reg = val;
6380 inst.operands[i].isreg = 1;
6381 inst.operands[i].isvec = 1;
6382 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6383 inst.operands[i].vectype = optype;
6384 inst.operands[i].present = 1;
6385
6386 if (rtype == REG_TYPE_VFS)
6387 {
6388 /* Case 14. */
6389 i++;
6390 if (skip_past_comma (&ptr) == FAIL)
6391 goto wanted_comma;
6392 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6393 &optype)) == FAIL)
6394 {
6395 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6396 return FAIL;
6397 }
6398 inst.operands[i].reg = val;
6399 inst.operands[i].isreg = 1;
6400 inst.operands[i].isvec = 1;
6401 inst.operands[i].issingle = 1;
6402 inst.operands[i].vectype = optype;
6403 inst.operands[i].present = 1;
6404 }
6405 }
037e8744 6406 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6407 != FAIL)
6408 {
6409 /* Case 13. */
6410 inst.operands[i].reg = val;
6411 inst.operands[i].isreg = 1;
6412 inst.operands[i].isvec = 1;
6413 inst.operands[i].issingle = 1;
6414 inst.operands[i].vectype = optype;
6415 inst.operands[i].present = 1;
6416 }
5287ad62
JB
6417 }
6418 else
6419 {
dcbf9037 6420 first_error (_("parse error"));
5287ad62
JB
6421 return FAIL;
6422 }
6423
6424 /* Successfully parsed the operands. Update args. */
6425 *which_operand = i;
6426 *str = ptr;
6427 return SUCCESS;
6428
5f4273c7 6429 wanted_comma:
dcbf9037 6430 first_error (_("expected comma"));
5287ad62 6431 return FAIL;
5f4273c7
NC
6432
6433 wanted_arm:
dcbf9037 6434 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6435 return FAIL;
5287ad62
JB
6436}
6437
5be8be5d
DG
6438/* Use this macro when the operand constraints are different
6439 for ARM and THUMB (e.g. ldrd). */
6440#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6441 ((arm_operand) | ((thumb_operand) << 16))
6442
c19d1205
ZW
6443/* Matcher codes for parse_operands. */
6444enum operand_parse_code
6445{
6446 OP_stop, /* end of line */
6447
6448 OP_RR, /* ARM register */
6449 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6450 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6451 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6452 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6453 optional trailing ! */
c19d1205
ZW
6454 OP_RRw, /* ARM register, not r15, optional trailing ! */
6455 OP_RCP, /* Coprocessor number */
6456 OP_RCN, /* Coprocessor register */
6457 OP_RF, /* FPA register */
6458 OP_RVS, /* VFP single precision register */
5287ad62
JB
6459 OP_RVD, /* VFP double precision register (0..15) */
6460 OP_RND, /* Neon double precision register (0..31) */
6461 OP_RNQ, /* Neon quad precision register */
037e8744 6462 OP_RVSD, /* VFP single or double precision register */
5287ad62 6463 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6464 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6465 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6466 OP_RVC, /* VFP control register */
6467 OP_RMF, /* Maverick F register */
6468 OP_RMD, /* Maverick D register */
6469 OP_RMFX, /* Maverick FX register */
6470 OP_RMDX, /* Maverick DX register */
6471 OP_RMAX, /* Maverick AX register */
6472 OP_RMDS, /* Maverick DSPSC register */
6473 OP_RIWR, /* iWMMXt wR register */
6474 OP_RIWC, /* iWMMXt wC register */
6475 OP_RIWG, /* iWMMXt wCG register */
6476 OP_RXA, /* XScale accumulator register */
6477
6478 OP_REGLST, /* ARM register list */
6479 OP_VRSLST, /* VFP single-precision register list */
6480 OP_VRDLST, /* VFP double-precision register list */
037e8744 6481 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6482 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6483 OP_NSTRLST, /* Neon element/structure list */
6484
5287ad62 6485 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6486 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6487 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6488 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6489 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6490 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6491 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6492 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6493 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6494 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6495 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6496
6497 OP_I0, /* immediate zero */
c19d1205
ZW
6498 OP_I7, /* immediate value 0 .. 7 */
6499 OP_I15, /* 0 .. 15 */
6500 OP_I16, /* 1 .. 16 */
5287ad62 6501 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6502 OP_I31, /* 0 .. 31 */
6503 OP_I31w, /* 0 .. 31, optional trailing ! */
6504 OP_I32, /* 1 .. 32 */
5287ad62
JB
6505 OP_I32z, /* 0 .. 32 */
6506 OP_I63, /* 0 .. 63 */
c19d1205 6507 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6508 OP_I64, /* 1 .. 64 */
6509 OP_I64z, /* 0 .. 64 */
c19d1205 6510 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6511
6512 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6513 OP_I7b, /* 0 .. 7 */
6514 OP_I15b, /* 0 .. 15 */
6515 OP_I31b, /* 0 .. 31 */
6516
6517 OP_SH, /* shifter operand */
4962c51a 6518 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6519 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6520 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6521 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6522 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6523 OP_EXP, /* arbitrary expression */
6524 OP_EXPi, /* same, with optional immediate prefix */
6525 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6526 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6527
6528 OP_CPSF, /* CPS flags */
6529 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6530 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6531 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6532 OP_COND, /* conditional code */
92e90b6e 6533 OP_TB, /* Table branch. */
c19d1205 6534
037e8744
JB
6535 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6536
c19d1205
ZW
6537 OP_RRnpc_I0, /* ARM register or literal 0 */
6538 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6539 OP_RR_EXi, /* ARM register or expression with imm prefix */
6540 OP_RF_IF, /* FPA register or immediate */
6541 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6542 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6543
6544 /* Optional operands. */
6545 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6546 OP_oI31b, /* 0 .. 31 */
5287ad62 6547 OP_oI32b, /* 1 .. 32 */
5f1af56b 6548 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6549 OP_oIffffb, /* 0 .. 65535 */
6550 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6551
6552 OP_oRR, /* ARM register */
6553 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6554 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6555 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6556 OP_oRND, /* Optional Neon double precision register */
6557 OP_oRNQ, /* Optional Neon quad precision register */
6558 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6559 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6560 OP_oSHll, /* LSL immediate */
6561 OP_oSHar, /* ASR immediate */
6562 OP_oSHllar, /* LSL or ASR immediate */
6563 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6564 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6565
5be8be5d
DG
6566 /* Some pre-defined mixed (ARM/THUMB) operands. */
6567 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6568 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6569 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6570
c19d1205
ZW
6571 OP_FIRST_OPTIONAL = OP_oI7b
6572};
a737bd4d 6573
c19d1205
ZW
6574/* Generic instruction operand parser. This does no encoding and no
6575 semantic validation; it merely squirrels values away in the inst
6576 structure. Returns SUCCESS or FAIL depending on whether the
6577 specified grammar matched. */
6578static int
5be8be5d 6579parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6580{
5be8be5d 6581 unsigned const int *upat = pattern;
c19d1205
ZW
6582 char *backtrack_pos = 0;
6583 const char *backtrack_error = 0;
99aad254 6584 int i, val = 0, backtrack_index = 0;
5287ad62 6585 enum arm_reg_type rtype;
4962c51a 6586 parse_operand_result result;
5be8be5d 6587 unsigned int op_parse_code;
c19d1205 6588
e07e6e58
NC
6589#define po_char_or_fail(chr) \
6590 do \
6591 { \
6592 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6593 goto bad_args; \
e07e6e58
NC
6594 } \
6595 while (0)
c19d1205 6596
e07e6e58
NC
6597#define po_reg_or_fail(regtype) \
6598 do \
dcbf9037 6599 { \
e07e6e58 6600 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6601 & inst.operands[i].vectype); \
e07e6e58 6602 if (val == FAIL) \
477330fc
RM
6603 { \
6604 first_error (_(reg_expected_msgs[regtype])); \
6605 goto failure; \
6606 } \
e07e6e58
NC
6607 inst.operands[i].reg = val; \
6608 inst.operands[i].isreg = 1; \
6609 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6610 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6611 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6612 || rtype == REG_TYPE_VFD \
6613 || rtype == REG_TYPE_NQ); \
dcbf9037 6614 } \
e07e6e58
NC
6615 while (0)
6616
6617#define po_reg_or_goto(regtype, label) \
6618 do \
6619 { \
6620 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6621 & inst.operands[i].vectype); \
6622 if (val == FAIL) \
6623 goto label; \
dcbf9037 6624 \
e07e6e58
NC
6625 inst.operands[i].reg = val; \
6626 inst.operands[i].isreg = 1; \
6627 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6628 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6629 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6630 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6631 || rtype == REG_TYPE_NQ); \
6632 } \
6633 while (0)
6634
6635#define po_imm_or_fail(min, max, popt) \
6636 do \
6637 { \
6638 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6639 goto failure; \
6640 inst.operands[i].imm = val; \
6641 } \
6642 while (0)
6643
6644#define po_scalar_or_goto(elsz, label) \
6645 do \
6646 { \
6647 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6648 if (val == FAIL) \
6649 goto label; \
6650 inst.operands[i].reg = val; \
6651 inst.operands[i].isscalar = 1; \
6652 } \
6653 while (0)
6654
6655#define po_misc_or_fail(expr) \
6656 do \
6657 { \
6658 if (expr) \
6659 goto failure; \
6660 } \
6661 while (0)
6662
6663#define po_misc_or_fail_no_backtrack(expr) \
6664 do \
6665 { \
6666 result = expr; \
6667 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6668 backtrack_pos = 0; \
6669 if (result != PARSE_OPERAND_SUCCESS) \
6670 goto failure; \
6671 } \
6672 while (0)
4962c51a 6673
52e7f43d
RE
6674#define po_barrier_or_imm(str) \
6675 do \
6676 { \
6677 val = parse_barrier (&str); \
ccb84d65
JB
6678 if (val == FAIL && ! ISALPHA (*str)) \
6679 goto immediate; \
6680 if (val == FAIL \
6681 /* ISB can only take SY as an option. */ \
6682 || ((inst.instruction & 0xf0) == 0x60 \
6683 && val != 0xf)) \
52e7f43d 6684 { \
ccb84d65
JB
6685 inst.error = _("invalid barrier type"); \
6686 backtrack_pos = 0; \
6687 goto failure; \
52e7f43d
RE
6688 } \
6689 } \
6690 while (0)
6691
c19d1205
ZW
6692 skip_whitespace (str);
6693
6694 for (i = 0; upat[i] != OP_stop; i++)
6695 {
5be8be5d
DG
6696 op_parse_code = upat[i];
6697 if (op_parse_code >= 1<<16)
6698 op_parse_code = thumb ? (op_parse_code >> 16)
6699 : (op_parse_code & ((1<<16)-1));
6700
6701 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6702 {
6703 /* Remember where we are in case we need to backtrack. */
9c2799c2 6704 gas_assert (!backtrack_pos);
c19d1205
ZW
6705 backtrack_pos = str;
6706 backtrack_error = inst.error;
6707 backtrack_index = i;
6708 }
6709
b6702015 6710 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6711 po_char_or_fail (',');
6712
5be8be5d 6713 switch (op_parse_code)
c19d1205
ZW
6714 {
6715 /* Registers */
6716 case OP_oRRnpc:
5be8be5d 6717 case OP_oRRnpcsp:
c19d1205 6718 case OP_RRnpc:
5be8be5d 6719 case OP_RRnpcsp:
c19d1205
ZW
6720 case OP_oRR:
6721 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6722 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6723 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6724 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6725 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6726 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6727 case OP_oRND:
5287ad62 6728 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6729 case OP_RVC:
6730 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6731 break;
6732 /* Also accept generic coprocessor regs for unknown registers. */
6733 coproc_reg:
6734 po_reg_or_fail (REG_TYPE_CN);
6735 break;
c19d1205
ZW
6736 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6737 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6738 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6739 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6740 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6741 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6742 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6743 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6744 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6745 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6746 case OP_oRNQ:
5287ad62 6747 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6748 case OP_oRNDQ:
5287ad62 6749 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6750 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6751 case OP_oRNSDQ:
6752 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6753
6754 /* Neon scalar. Using an element size of 8 means that some invalid
6755 scalars are accepted here, so deal with those in later code. */
6756 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6757
6758 case OP_RNDQ_I0:
6759 {
6760 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6761 break;
6762 try_imm0:
6763 po_imm_or_fail (0, 0, TRUE);
6764 }
6765 break;
6766
6767 case OP_RVSD_I0:
6768 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6769 break;
6770
aacf0b33
KT
6771 case OP_RSVD_FI0:
6772 {
6773 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6774 break;
6775 try_ifimm0:
6776 if (parse_ifimm_zero (&str))
6777 inst.operands[i].imm = 0;
6778 else
6779 {
6780 inst.error
6781 = _("only floating point zero is allowed as immediate value");
6782 goto failure;
6783 }
6784 }
6785 break;
6786
477330fc
RM
6787 case OP_RR_RNSC:
6788 {
6789 po_scalar_or_goto (8, try_rr);
6790 break;
6791 try_rr:
6792 po_reg_or_fail (REG_TYPE_RN);
6793 }
6794 break;
6795
6796 case OP_RNSDQ_RNSC:
6797 {
6798 po_scalar_or_goto (8, try_nsdq);
6799 break;
6800 try_nsdq:
6801 po_reg_or_fail (REG_TYPE_NSDQ);
6802 }
6803 break;
6804
6805 case OP_RNDQ_RNSC:
6806 {
6807 po_scalar_or_goto (8, try_ndq);
6808 break;
6809 try_ndq:
6810 po_reg_or_fail (REG_TYPE_NDQ);
6811 }
6812 break;
6813
6814 case OP_RND_RNSC:
6815 {
6816 po_scalar_or_goto (8, try_vfd);
6817 break;
6818 try_vfd:
6819 po_reg_or_fail (REG_TYPE_VFD);
6820 }
6821 break;
6822
6823 case OP_VMOV:
6824 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6825 not careful then bad things might happen. */
6826 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6827 break;
6828
6829 case OP_RNDQ_Ibig:
6830 {
6831 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6832 break;
6833 try_immbig:
6834 /* There's a possibility of getting a 64-bit immediate here, so
6835 we need special handling. */
8335d6aa
JW
6836 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6837 == FAIL)
477330fc
RM
6838 {
6839 inst.error = _("immediate value is out of range");
6840 goto failure;
6841 }
6842 }
6843 break;
6844
6845 case OP_RNDQ_I63b:
6846 {
6847 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6848 break;
6849 try_shimm:
6850 po_imm_or_fail (0, 63, TRUE);
6851 }
6852 break;
c19d1205
ZW
6853
6854 case OP_RRnpcb:
6855 po_char_or_fail ('[');
6856 po_reg_or_fail (REG_TYPE_RN);
6857 po_char_or_fail (']');
6858 break;
a737bd4d 6859
55881a11 6860 case OP_RRnpctw:
c19d1205 6861 case OP_RRw:
b6702015 6862 case OP_oRRw:
c19d1205
ZW
6863 po_reg_or_fail (REG_TYPE_RN);
6864 if (skip_past_char (&str, '!') == SUCCESS)
6865 inst.operands[i].writeback = 1;
6866 break;
6867
6868 /* Immediates */
6869 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6870 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6871 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6872 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6873 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6874 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6875 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6876 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6877 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6878 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6879 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6880 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6881
6882 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6883 case OP_oI7b:
6884 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6885 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6886 case OP_oI31b:
6887 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6888 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6889 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6890 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6891
6892 /* Immediate variants */
6893 case OP_oI255c:
6894 po_char_or_fail ('{');
6895 po_imm_or_fail (0, 255, TRUE);
6896 po_char_or_fail ('}');
6897 break;
6898
6899 case OP_I31w:
6900 /* The expression parser chokes on a trailing !, so we have
6901 to find it first and zap it. */
6902 {
6903 char *s = str;
6904 while (*s && *s != ',')
6905 s++;
6906 if (s[-1] == '!')
6907 {
6908 s[-1] = '\0';
6909 inst.operands[i].writeback = 1;
6910 }
6911 po_imm_or_fail (0, 31, TRUE);
6912 if (str == s - 1)
6913 str = s;
6914 }
6915 break;
6916
6917 /* Expressions */
6918 case OP_EXPi: EXPi:
6919 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6920 GE_OPT_PREFIX));
6921 break;
6922
6923 case OP_EXP:
6924 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6925 GE_NO_PREFIX));
6926 break;
6927
6928 case OP_EXPr: EXPr:
6929 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6930 GE_NO_PREFIX));
6931 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6932 {
c19d1205
ZW
6933 val = parse_reloc (&str);
6934 if (val == -1)
6935 {
6936 inst.error = _("unrecognized relocation suffix");
6937 goto failure;
6938 }
6939 else if (val != BFD_RELOC_UNUSED)
6940 {
6941 inst.operands[i].imm = val;
6942 inst.operands[i].hasreloc = 1;
6943 }
a737bd4d 6944 }
c19d1205 6945 break;
a737bd4d 6946
b6895b4f
PB
6947 /* Operand for MOVW or MOVT. */
6948 case OP_HALF:
6949 po_misc_or_fail (parse_half (&str));
6950 break;
6951
e07e6e58 6952 /* Register or expression. */
c19d1205
ZW
6953 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6954 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6955
e07e6e58 6956 /* Register or immediate. */
c19d1205
ZW
6957 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6958 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6959
c19d1205
ZW
6960 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6961 IF:
6962 if (!is_immediate_prefix (*str))
6963 goto bad_args;
6964 str++;
6965 val = parse_fpa_immediate (&str);
6966 if (val == FAIL)
6967 goto failure;
6968 /* FPA immediates are encoded as registers 8-15.
6969 parse_fpa_immediate has already applied the offset. */
6970 inst.operands[i].reg = val;
6971 inst.operands[i].isreg = 1;
6972 break;
09d92015 6973
2d447fca
JM
6974 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6975 I32z: po_imm_or_fail (0, 32, FALSE); break;
6976
e07e6e58 6977 /* Two kinds of register. */
c19d1205
ZW
6978 case OP_RIWR_RIWC:
6979 {
6980 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6981 if (!rege
6982 || (rege->type != REG_TYPE_MMXWR
6983 && rege->type != REG_TYPE_MMXWC
6984 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6985 {
6986 inst.error = _("iWMMXt data or control register expected");
6987 goto failure;
6988 }
6989 inst.operands[i].reg = rege->number;
6990 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6991 }
6992 break;
09d92015 6993
41adaa5c
JM
6994 case OP_RIWC_RIWG:
6995 {
6996 struct reg_entry *rege = arm_reg_parse_multi (&str);
6997 if (!rege
6998 || (rege->type != REG_TYPE_MMXWC
6999 && rege->type != REG_TYPE_MMXWCG))
7000 {
7001 inst.error = _("iWMMXt control register expected");
7002 goto failure;
7003 }
7004 inst.operands[i].reg = rege->number;
7005 inst.operands[i].isreg = 1;
7006 }
7007 break;
7008
c19d1205
ZW
7009 /* Misc */
7010 case OP_CPSF: val = parse_cps_flags (&str); break;
7011 case OP_ENDI: val = parse_endian_specifier (&str); break;
7012 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7013 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7014 case OP_oBARRIER_I15:
7015 po_barrier_or_imm (str); break;
7016 immediate:
7017 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7018 goto failure;
52e7f43d 7019 break;
c19d1205 7020
fa94de6b 7021 case OP_wPSR:
d2cd1205 7022 case OP_rPSR:
90ec0d68
MGD
7023 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7024 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7025 {
7026 inst.error = _("Banked registers are not available with this "
7027 "architecture.");
7028 goto failure;
7029 }
7030 break;
d2cd1205
JB
7031 try_psr:
7032 val = parse_psr (&str, op_parse_code == OP_wPSR);
7033 break;
037e8744 7034
477330fc
RM
7035 case OP_APSR_RR:
7036 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7037 break;
7038 try_apsr:
7039 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7040 instruction). */
7041 if (strncasecmp (str, "APSR_", 5) == 0)
7042 {
7043 unsigned found = 0;
7044 str += 5;
7045 while (found < 15)
7046 switch (*str++)
7047 {
7048 case 'c': found = (found & 1) ? 16 : found | 1; break;
7049 case 'n': found = (found & 2) ? 16 : found | 2; break;
7050 case 'z': found = (found & 4) ? 16 : found | 4; break;
7051 case 'v': found = (found & 8) ? 16 : found | 8; break;
7052 default: found = 16;
7053 }
7054 if (found != 15)
7055 goto failure;
7056 inst.operands[i].isvec = 1;
f7c21dc7
NC
7057 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7058 inst.operands[i].reg = REG_PC;
477330fc
RM
7059 }
7060 else
7061 goto failure;
7062 break;
037e8744 7063
92e90b6e
PB
7064 case OP_TB:
7065 po_misc_or_fail (parse_tb (&str));
7066 break;
7067
e07e6e58 7068 /* Register lists. */
c19d1205
ZW
7069 case OP_REGLST:
7070 val = parse_reg_list (&str);
7071 if (*str == '^')
7072 {
5e0d7f77 7073 inst.operands[i].writeback = 1;
c19d1205
ZW
7074 str++;
7075 }
7076 break;
09d92015 7077
c19d1205 7078 case OP_VRSLST:
5287ad62 7079 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7080 break;
09d92015 7081
c19d1205 7082 case OP_VRDLST:
5287ad62 7083 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7084 break;
a737bd4d 7085
477330fc
RM
7086 case OP_VRSDLST:
7087 /* Allow Q registers too. */
7088 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7089 REGLIST_NEON_D);
7090 if (val == FAIL)
7091 {
7092 inst.error = NULL;
7093 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7094 REGLIST_VFP_S);
7095 inst.operands[i].issingle = 1;
7096 }
7097 break;
7098
7099 case OP_NRDLST:
7100 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7101 REGLIST_NEON_D);
7102 break;
5287ad62
JB
7103
7104 case OP_NSTRLST:
477330fc
RM
7105 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7106 &inst.operands[i].vectype);
7107 break;
5287ad62 7108
c19d1205
ZW
7109 /* Addressing modes */
7110 case OP_ADDR:
7111 po_misc_or_fail (parse_address (&str, i));
7112 break;
09d92015 7113
4962c51a
MS
7114 case OP_ADDRGLDR:
7115 po_misc_or_fail_no_backtrack (
477330fc 7116 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7117 break;
7118
7119 case OP_ADDRGLDRS:
7120 po_misc_or_fail_no_backtrack (
477330fc 7121 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7122 break;
7123
7124 case OP_ADDRGLDC:
7125 po_misc_or_fail_no_backtrack (
477330fc 7126 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7127 break;
7128
c19d1205
ZW
7129 case OP_SH:
7130 po_misc_or_fail (parse_shifter_operand (&str, i));
7131 break;
09d92015 7132
4962c51a
MS
7133 case OP_SHG:
7134 po_misc_or_fail_no_backtrack (
477330fc 7135 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7136 break;
7137
c19d1205
ZW
7138 case OP_oSHll:
7139 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7140 break;
09d92015 7141
c19d1205
ZW
7142 case OP_oSHar:
7143 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7144 break;
09d92015 7145
c19d1205
ZW
7146 case OP_oSHllar:
7147 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7148 break;
09d92015 7149
c19d1205 7150 default:
5be8be5d 7151 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7152 }
09d92015 7153
c19d1205
ZW
7154 /* Various value-based sanity checks and shared operations. We
7155 do not signal immediate failures for the register constraints;
7156 this allows a syntax error to take precedence. */
5be8be5d 7157 switch (op_parse_code)
c19d1205
ZW
7158 {
7159 case OP_oRRnpc:
7160 case OP_RRnpc:
7161 case OP_RRnpcb:
7162 case OP_RRw:
b6702015 7163 case OP_oRRw:
c19d1205
ZW
7164 case OP_RRnpc_I0:
7165 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7166 inst.error = BAD_PC;
7167 break;
09d92015 7168
5be8be5d
DG
7169 case OP_oRRnpcsp:
7170 case OP_RRnpcsp:
7171 if (inst.operands[i].isreg)
7172 {
7173 if (inst.operands[i].reg == REG_PC)
7174 inst.error = BAD_PC;
7175 else if (inst.operands[i].reg == REG_SP)
7176 inst.error = BAD_SP;
7177 }
7178 break;
7179
55881a11 7180 case OP_RRnpctw:
fa94de6b
RM
7181 if (inst.operands[i].isreg
7182 && inst.operands[i].reg == REG_PC
55881a11
MGD
7183 && (inst.operands[i].writeback || thumb))
7184 inst.error = BAD_PC;
7185 break;
7186
c19d1205
ZW
7187 case OP_CPSF:
7188 case OP_ENDI:
7189 case OP_oROR:
d2cd1205
JB
7190 case OP_wPSR:
7191 case OP_rPSR:
c19d1205 7192 case OP_COND:
52e7f43d 7193 case OP_oBARRIER_I15:
c19d1205
ZW
7194 case OP_REGLST:
7195 case OP_VRSLST:
7196 case OP_VRDLST:
477330fc
RM
7197 case OP_VRSDLST:
7198 case OP_NRDLST:
7199 case OP_NSTRLST:
c19d1205
ZW
7200 if (val == FAIL)
7201 goto failure;
7202 inst.operands[i].imm = val;
7203 break;
a737bd4d 7204
c19d1205
ZW
7205 default:
7206 break;
7207 }
09d92015 7208
c19d1205
ZW
7209 /* If we get here, this operand was successfully parsed. */
7210 inst.operands[i].present = 1;
7211 continue;
09d92015 7212
c19d1205 7213 bad_args:
09d92015 7214 inst.error = BAD_ARGS;
c19d1205
ZW
7215
7216 failure:
7217 if (!backtrack_pos)
d252fdde
PB
7218 {
7219 /* The parse routine should already have set inst.error, but set a
5f4273c7 7220 default here just in case. */
d252fdde
PB
7221 if (!inst.error)
7222 inst.error = _("syntax error");
7223 return FAIL;
7224 }
c19d1205
ZW
7225
7226 /* Do not backtrack over a trailing optional argument that
7227 absorbed some text. We will only fail again, with the
7228 'garbage following instruction' error message, which is
7229 probably less helpful than the current one. */
7230 if (backtrack_index == i && backtrack_pos != str
7231 && upat[i+1] == OP_stop)
d252fdde
PB
7232 {
7233 if (!inst.error)
7234 inst.error = _("syntax error");
7235 return FAIL;
7236 }
c19d1205
ZW
7237
7238 /* Try again, skipping the optional argument at backtrack_pos. */
7239 str = backtrack_pos;
7240 inst.error = backtrack_error;
7241 inst.operands[backtrack_index].present = 0;
7242 i = backtrack_index;
7243 backtrack_pos = 0;
09d92015 7244 }
09d92015 7245
c19d1205
ZW
7246 /* Check that we have parsed all the arguments. */
7247 if (*str != '\0' && !inst.error)
7248 inst.error = _("garbage following instruction");
09d92015 7249
c19d1205 7250 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7251}
7252
c19d1205
ZW
7253#undef po_char_or_fail
7254#undef po_reg_or_fail
7255#undef po_reg_or_goto
7256#undef po_imm_or_fail
5287ad62 7257#undef po_scalar_or_fail
52e7f43d 7258#undef po_barrier_or_imm
e07e6e58 7259
c19d1205 7260/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7261#define constraint(expr, err) \
7262 do \
c19d1205 7263 { \
e07e6e58
NC
7264 if (expr) \
7265 { \
7266 inst.error = err; \
7267 return; \
7268 } \
c19d1205 7269 } \
e07e6e58 7270 while (0)
c19d1205 7271
fdfde340
JM
7272/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7273 instructions are unpredictable if these registers are used. This
7274 is the BadReg predicate in ARM's Thumb-2 documentation. */
7275#define reject_bad_reg(reg) \
7276 do \
7277 if (reg == REG_SP || reg == REG_PC) \
7278 { \
7279 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7280 return; \
7281 } \
7282 while (0)
7283
94206790
MM
7284/* If REG is R13 (the stack pointer), warn that its use is
7285 deprecated. */
7286#define warn_deprecated_sp(reg) \
7287 do \
7288 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7289 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7290 while (0)
7291
c19d1205
ZW
7292/* Functions for operand encoding. ARM, then Thumb. */
7293
d840c081 7294#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7295
9db2f6b4
RL
7296/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7297
7298 The only binary encoding difference is the Coprocessor number. Coprocessor
7299 9 is used for half-precision calculations or conversions. The format of the
7300 instruction is the same as the equivalent Coprocessor 10 instuction that
7301 exists for Single-Precision operation. */
7302
7303static void
7304do_scalar_fp16_v82_encode (void)
7305{
7306 if (inst.cond != COND_ALWAYS)
7307 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7308 " the behaviour is UNPREDICTABLE"));
7309 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7310 _(BAD_FP16));
7311
7312 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7313 mark_feature_used (&arm_ext_fp16);
7314}
7315
c19d1205
ZW
7316/* If VAL can be encoded in the immediate field of an ARM instruction,
7317 return the encoded form. Otherwise, return FAIL. */
7318
7319static unsigned int
7320encode_arm_immediate (unsigned int val)
09d92015 7321{
c19d1205
ZW
7322 unsigned int a, i;
7323
4f1d6205
L
7324 if (val <= 0xff)
7325 return val;
7326
7327 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7328 if ((a = rotate_left (val, i)) <= 0xff)
7329 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7330
7331 return FAIL;
09d92015
MM
7332}
7333
c19d1205
ZW
7334/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7335 return the encoded form. Otherwise, return FAIL. */
7336static unsigned int
7337encode_thumb32_immediate (unsigned int val)
09d92015 7338{
c19d1205 7339 unsigned int a, i;
09d92015 7340
9c3c69f2 7341 if (val <= 0xff)
c19d1205 7342 return val;
a737bd4d 7343
9c3c69f2 7344 for (i = 1; i <= 24; i++)
09d92015 7345 {
9c3c69f2
PB
7346 a = val >> i;
7347 if ((val & ~(0xff << i)) == 0)
7348 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7349 }
a737bd4d 7350
c19d1205
ZW
7351 a = val & 0xff;
7352 if (val == ((a << 16) | a))
7353 return 0x100 | a;
7354 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7355 return 0x300 | a;
09d92015 7356
c19d1205
ZW
7357 a = val & 0xff00;
7358 if (val == ((a << 16) | a))
7359 return 0x200 | (a >> 8);
a737bd4d 7360
c19d1205 7361 return FAIL;
09d92015 7362}
5287ad62 7363/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7364
7365static void
5287ad62
JB
7366encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7367{
7368 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7369 && reg > 15)
7370 {
b1cc4aeb 7371 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7372 {
7373 if (thumb_mode)
7374 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7375 fpu_vfp_ext_d32);
7376 else
7377 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7378 fpu_vfp_ext_d32);
7379 }
5287ad62 7380 else
477330fc
RM
7381 {
7382 first_error (_("D register out of range for selected VFP version"));
7383 return;
7384 }
5287ad62
JB
7385 }
7386
c19d1205 7387 switch (pos)
09d92015 7388 {
c19d1205
ZW
7389 case VFP_REG_Sd:
7390 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7391 break;
7392
7393 case VFP_REG_Sn:
7394 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7395 break;
7396
7397 case VFP_REG_Sm:
7398 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7399 break;
7400
5287ad62
JB
7401 case VFP_REG_Dd:
7402 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7403 break;
5f4273c7 7404
5287ad62
JB
7405 case VFP_REG_Dn:
7406 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7407 break;
5f4273c7 7408
5287ad62
JB
7409 case VFP_REG_Dm:
7410 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7411 break;
7412
c19d1205
ZW
7413 default:
7414 abort ();
09d92015 7415 }
09d92015
MM
7416}
7417
c19d1205 7418/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7419 if any, is handled by md_apply_fix. */
09d92015 7420static void
c19d1205 7421encode_arm_shift (int i)
09d92015 7422{
c19d1205
ZW
7423 if (inst.operands[i].shift_kind == SHIFT_RRX)
7424 inst.instruction |= SHIFT_ROR << 5;
7425 else
09d92015 7426 {
c19d1205
ZW
7427 inst.instruction |= inst.operands[i].shift_kind << 5;
7428 if (inst.operands[i].immisreg)
7429 {
7430 inst.instruction |= SHIFT_BY_REG;
7431 inst.instruction |= inst.operands[i].imm << 8;
7432 }
7433 else
7434 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7435 }
c19d1205 7436}
09d92015 7437
c19d1205
ZW
7438static void
7439encode_arm_shifter_operand (int i)
7440{
7441 if (inst.operands[i].isreg)
09d92015 7442 {
c19d1205
ZW
7443 inst.instruction |= inst.operands[i].reg;
7444 encode_arm_shift (i);
09d92015 7445 }
c19d1205 7446 else
a415b1cd
JB
7447 {
7448 inst.instruction |= INST_IMMEDIATE;
7449 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7450 inst.instruction |= inst.operands[i].imm;
7451 }
09d92015
MM
7452}
7453
c19d1205 7454/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7455static void
c19d1205 7456encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7457{
2b2f5df9
NC
7458 /* PR 14260:
7459 Generate an error if the operand is not a register. */
7460 constraint (!inst.operands[i].isreg,
7461 _("Instruction does not support =N addresses"));
7462
c19d1205 7463 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7464
c19d1205 7465 if (inst.operands[i].preind)
09d92015 7466 {
c19d1205
ZW
7467 if (is_t)
7468 {
7469 inst.error = _("instruction does not accept preindexed addressing");
7470 return;
7471 }
7472 inst.instruction |= PRE_INDEX;
7473 if (inst.operands[i].writeback)
7474 inst.instruction |= WRITE_BACK;
09d92015 7475
c19d1205
ZW
7476 }
7477 else if (inst.operands[i].postind)
7478 {
9c2799c2 7479 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7480 if (is_t)
7481 inst.instruction |= WRITE_BACK;
7482 }
7483 else /* unindexed - only for coprocessor */
09d92015 7484 {
c19d1205 7485 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7486 return;
7487 }
7488
c19d1205
ZW
7489 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7490 && (((inst.instruction & 0x000f0000) >> 16)
7491 == ((inst.instruction & 0x0000f000) >> 12)))
7492 as_warn ((inst.instruction & LOAD_BIT)
7493 ? _("destination register same as write-back base")
7494 : _("source register same as write-back base"));
09d92015
MM
7495}
7496
c19d1205
ZW
7497/* inst.operands[i] was set up by parse_address. Encode it into an
7498 ARM-format mode 2 load or store instruction. If is_t is true,
7499 reject forms that cannot be used with a T instruction (i.e. not
7500 post-indexed). */
a737bd4d 7501static void
c19d1205 7502encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7503{
5be8be5d
DG
7504 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7505
c19d1205 7506 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7507
c19d1205 7508 if (inst.operands[i].immisreg)
09d92015 7509 {
5be8be5d
DG
7510 constraint ((inst.operands[i].imm == REG_PC
7511 || (is_pc && inst.operands[i].writeback)),
7512 BAD_PC_ADDRESSING);
c19d1205
ZW
7513 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7514 inst.instruction |= inst.operands[i].imm;
7515 if (!inst.operands[i].negative)
7516 inst.instruction |= INDEX_UP;
7517 if (inst.operands[i].shifted)
7518 {
7519 if (inst.operands[i].shift_kind == SHIFT_RRX)
7520 inst.instruction |= SHIFT_ROR << 5;
7521 else
7522 {
7523 inst.instruction |= inst.operands[i].shift_kind << 5;
7524 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7525 }
7526 }
09d92015 7527 }
c19d1205 7528 else /* immediate offset in inst.reloc */
09d92015 7529 {
5be8be5d
DG
7530 if (is_pc && !inst.reloc.pc_rel)
7531 {
7532 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7533
7534 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7535 cannot use PC in addressing.
7536 PC cannot be used in writeback addressing, either. */
7537 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7538 BAD_PC_ADDRESSING);
23a10334 7539
dc5ec521 7540 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7541 if (warn_on_deprecated
7542 && !is_load
7543 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7544 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7545 }
7546
c19d1205 7547 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7548 {
7549 /* Prefer + for zero encoded value. */
7550 if (!inst.operands[i].negative)
7551 inst.instruction |= INDEX_UP;
7552 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7553 }
09d92015 7554 }
09d92015
MM
7555}
7556
c19d1205
ZW
7557/* inst.operands[i] was set up by parse_address. Encode it into an
7558 ARM-format mode 3 load or store instruction. Reject forms that
7559 cannot be used with such instructions. If is_t is true, reject
7560 forms that cannot be used with a T instruction (i.e. not
7561 post-indexed). */
7562static void
7563encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7564{
c19d1205 7565 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7566 {
c19d1205
ZW
7567 inst.error = _("instruction does not accept scaled register index");
7568 return;
09d92015 7569 }
a737bd4d 7570
c19d1205 7571 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7572
c19d1205
ZW
7573 if (inst.operands[i].immisreg)
7574 {
5be8be5d 7575 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7576 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7577 BAD_PC_ADDRESSING);
eb9f3f00
JB
7578 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7579 BAD_PC_WRITEBACK);
c19d1205
ZW
7580 inst.instruction |= inst.operands[i].imm;
7581 if (!inst.operands[i].negative)
7582 inst.instruction |= INDEX_UP;
7583 }
7584 else /* immediate offset in inst.reloc */
7585 {
5be8be5d
DG
7586 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7587 && inst.operands[i].writeback),
7588 BAD_PC_WRITEBACK);
c19d1205
ZW
7589 inst.instruction |= HWOFFSET_IMM;
7590 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7591 {
7592 /* Prefer + for zero encoded value. */
7593 if (!inst.operands[i].negative)
7594 inst.instruction |= INDEX_UP;
7595
7596 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7597 }
c19d1205 7598 }
a737bd4d
NC
7599}
7600
8335d6aa
JW
7601/* Write immediate bits [7:0] to the following locations:
7602
7603 |28/24|23 19|18 16|15 4|3 0|
7604 | 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|
7605
7606 This function is used by VMOV/VMVN/VORR/VBIC. */
7607
7608static void
7609neon_write_immbits (unsigned immbits)
7610{
7611 inst.instruction |= immbits & 0xf;
7612 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7613 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7614}
7615
7616/* Invert low-order SIZE bits of XHI:XLO. */
7617
7618static void
7619neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7620{
7621 unsigned immlo = xlo ? *xlo : 0;
7622 unsigned immhi = xhi ? *xhi : 0;
7623
7624 switch (size)
7625 {
7626 case 8:
7627 immlo = (~immlo) & 0xff;
7628 break;
7629
7630 case 16:
7631 immlo = (~immlo) & 0xffff;
7632 break;
7633
7634 case 64:
7635 immhi = (~immhi) & 0xffffffff;
7636 /* fall through. */
7637
7638 case 32:
7639 immlo = (~immlo) & 0xffffffff;
7640 break;
7641
7642 default:
7643 abort ();
7644 }
7645
7646 if (xlo)
7647 *xlo = immlo;
7648
7649 if (xhi)
7650 *xhi = immhi;
7651}
7652
7653/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7654 A, B, C, D. */
09d92015 7655
c19d1205 7656static int
8335d6aa 7657neon_bits_same_in_bytes (unsigned imm)
09d92015 7658{
8335d6aa
JW
7659 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7660 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7661 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7662 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7663}
a737bd4d 7664
8335d6aa 7665/* For immediate of above form, return 0bABCD. */
09d92015 7666
8335d6aa
JW
7667static unsigned
7668neon_squash_bits (unsigned imm)
7669{
7670 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7671 | ((imm & 0x01000000) >> 21);
7672}
7673
7674/* Compress quarter-float representation to 0b...000 abcdefgh. */
7675
7676static unsigned
7677neon_qfloat_bits (unsigned imm)
7678{
7679 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7680}
7681
7682/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7683 the instruction. *OP is passed as the initial value of the op field, and
7684 may be set to a different value depending on the constant (i.e.
7685 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7686 MVN). If the immediate looks like a repeated pattern then also
7687 try smaller element sizes. */
7688
7689static int
7690neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7691 unsigned *immbits, int *op, int size,
7692 enum neon_el_type type)
7693{
7694 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7695 float. */
7696 if (type == NT_float && !float_p)
7697 return FAIL;
7698
7699 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7700 {
8335d6aa
JW
7701 if (size != 32 || *op == 1)
7702 return FAIL;
7703 *immbits = neon_qfloat_bits (immlo);
7704 return 0xf;
7705 }
7706
7707 if (size == 64)
7708 {
7709 if (neon_bits_same_in_bytes (immhi)
7710 && neon_bits_same_in_bytes (immlo))
c19d1205 7711 {
8335d6aa
JW
7712 if (*op == 1)
7713 return FAIL;
7714 *immbits = (neon_squash_bits (immhi) << 4)
7715 | neon_squash_bits (immlo);
7716 *op = 1;
7717 return 0xe;
c19d1205 7718 }
a737bd4d 7719
8335d6aa
JW
7720 if (immhi != immlo)
7721 return FAIL;
7722 }
a737bd4d 7723
8335d6aa 7724 if (size >= 32)
09d92015 7725 {
8335d6aa 7726 if (immlo == (immlo & 0x000000ff))
c19d1205 7727 {
8335d6aa
JW
7728 *immbits = immlo;
7729 return 0x0;
c19d1205 7730 }
8335d6aa 7731 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7732 {
8335d6aa
JW
7733 *immbits = immlo >> 8;
7734 return 0x2;
c19d1205 7735 }
8335d6aa
JW
7736 else if (immlo == (immlo & 0x00ff0000))
7737 {
7738 *immbits = immlo >> 16;
7739 return 0x4;
7740 }
7741 else if (immlo == (immlo & 0xff000000))
7742 {
7743 *immbits = immlo >> 24;
7744 return 0x6;
7745 }
7746 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7747 {
7748 *immbits = (immlo >> 8) & 0xff;
7749 return 0xc;
7750 }
7751 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7752 {
7753 *immbits = (immlo >> 16) & 0xff;
7754 return 0xd;
7755 }
7756
7757 if ((immlo & 0xffff) != (immlo >> 16))
7758 return FAIL;
7759 immlo &= 0xffff;
09d92015 7760 }
a737bd4d 7761
8335d6aa 7762 if (size >= 16)
4962c51a 7763 {
8335d6aa
JW
7764 if (immlo == (immlo & 0x000000ff))
7765 {
7766 *immbits = immlo;
7767 return 0x8;
7768 }
7769 else if (immlo == (immlo & 0x0000ff00))
7770 {
7771 *immbits = immlo >> 8;
7772 return 0xa;
7773 }
7774
7775 if ((immlo & 0xff) != (immlo >> 8))
7776 return FAIL;
7777 immlo &= 0xff;
4962c51a
MS
7778 }
7779
8335d6aa
JW
7780 if (immlo == (immlo & 0x000000ff))
7781 {
7782 /* Don't allow MVN with 8-bit immediate. */
7783 if (*op == 1)
7784 return FAIL;
7785 *immbits = immlo;
7786 return 0xe;
7787 }
26d97720 7788
8335d6aa 7789 return FAIL;
c19d1205 7790}
a737bd4d 7791
5fc177c8 7792#if defined BFD_HOST_64_BIT
ba592044
AM
7793/* Returns TRUE if double precision value V may be cast
7794 to single precision without loss of accuracy. */
7795
7796static bfd_boolean
5fc177c8 7797is_double_a_single (bfd_int64_t v)
ba592044 7798{
5fc177c8 7799 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7800 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7801
7802 return (exp == 0 || exp == 0x7FF
7803 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7804 && (mantissa & 0x1FFFFFFFl) == 0;
7805}
7806
3739860c 7807/* Returns a double precision value casted to single precision
ba592044
AM
7808 (ignoring the least significant bits in exponent and mantissa). */
7809
7810static int
5fc177c8 7811double_to_single (bfd_int64_t v)
ba592044
AM
7812{
7813 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7814 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7815 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7816
7817 if (exp == 0x7FF)
7818 exp = 0xFF;
7819 else
7820 {
7821 exp = exp - 1023 + 127;
7822 if (exp >= 0xFF)
7823 {
7824 /* Infinity. */
7825 exp = 0x7F;
7826 mantissa = 0;
7827 }
7828 else if (exp < 0)
7829 {
7830 /* No denormalized numbers. */
7831 exp = 0;
7832 mantissa = 0;
7833 }
7834 }
7835 mantissa >>= 29;
7836 return (sign << 31) | (exp << 23) | mantissa;
7837}
5fc177c8 7838#endif /* BFD_HOST_64_BIT */
ba592044 7839
8335d6aa
JW
7840enum lit_type
7841{
7842 CONST_THUMB,
7843 CONST_ARM,
7844 CONST_VEC
7845};
7846
ba592044
AM
7847static void do_vfp_nsyn_opcode (const char *);
7848
c19d1205
ZW
7849/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7850 Determine whether it can be performed with a move instruction; if
7851 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7852 return TRUE; if it can't, convert inst.instruction to a literal-pool
7853 load and return FALSE. If this is not a valid thing to do in the
7854 current context, set inst.error and return TRUE.
a737bd4d 7855
c19d1205
ZW
7856 inst.operands[i] describes the destination register. */
7857
c921be7d 7858static bfd_boolean
8335d6aa 7859move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7860{
53365c0d 7861 unsigned long tbit;
8335d6aa
JW
7862 bfd_boolean thumb_p = (t == CONST_THUMB);
7863 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7864
7865 if (thumb_p)
7866 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7867 else
7868 tbit = LOAD_BIT;
7869
7870 if ((inst.instruction & tbit) == 0)
09d92015 7871 {
c19d1205 7872 inst.error = _("invalid pseudo operation");
c921be7d 7873 return TRUE;
09d92015 7874 }
ba592044 7875
8335d6aa
JW
7876 if (inst.reloc.exp.X_op != O_constant
7877 && inst.reloc.exp.X_op != O_symbol
7878 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7879 {
7880 inst.error = _("constant expression expected");
c921be7d 7881 return TRUE;
09d92015 7882 }
ba592044
AM
7883
7884 if (inst.reloc.exp.X_op == O_constant
7885 || inst.reloc.exp.X_op == O_big)
8335d6aa 7886 {
5fc177c8
NC
7887#if defined BFD_HOST_64_BIT
7888 bfd_int64_t v;
7889#else
ba592044 7890 offsetT v;
5fc177c8 7891#endif
ba592044 7892 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7893 {
ba592044
AM
7894 LITTLENUM_TYPE w[X_PRECISION];
7895 LITTLENUM_TYPE * l;
7896
7897 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7898 {
ba592044
AM
7899 gen_to_words (w, X_PRECISION, E_PRECISION);
7900 l = w;
7901 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7902 }
ba592044
AM
7903 else
7904 l = generic_bignum;
3739860c 7905
5fc177c8
NC
7906#if defined BFD_HOST_64_BIT
7907 v =
7908 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7909 << LITTLENUM_NUMBER_OF_BITS)
7910 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7911 << LITTLENUM_NUMBER_OF_BITS)
7912 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7913 << LITTLENUM_NUMBER_OF_BITS)
7914 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7915#else
ba592044
AM
7916 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7917 | (l[0] & LITTLENUM_MASK);
5fc177c8 7918#endif
8335d6aa 7919 }
ba592044
AM
7920 else
7921 v = inst.reloc.exp.X_add_number;
7922
7923 if (!inst.operands[i].issingle)
8335d6aa 7924 {
12569877 7925 if (thumb_p)
8335d6aa 7926 {
2c32be70
CM
7927 /* This can be encoded only for a low register. */
7928 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7929 {
7930 /* This can be done with a mov(1) instruction. */
7931 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7932 inst.instruction |= v;
7933 return TRUE;
7934 }
12569877 7935
ff8646ee
TP
7936 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7937 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7938 {
fc289b0a
TP
7939 /* Check if on thumb2 it can be done with a mov.w, mvn or
7940 movw instruction. */
12569877
AM
7941 unsigned int newimm;
7942 bfd_boolean isNegated;
7943
7944 newimm = encode_thumb32_immediate (v);
7945 if (newimm != (unsigned int) FAIL)
7946 isNegated = FALSE;
7947 else
7948 {
582cfe03 7949 newimm = encode_thumb32_immediate (~v);
12569877
AM
7950 if (newimm != (unsigned int) FAIL)
7951 isNegated = TRUE;
7952 }
7953
fc289b0a
TP
7954 /* The number can be loaded with a mov.w or mvn
7955 instruction. */
ff8646ee
TP
7956 if (newimm != (unsigned int) FAIL
7957 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7958 {
fc289b0a 7959 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7960 | (inst.operands[i].reg << 8));
fc289b0a 7961 /* Change to MOVN. */
582cfe03 7962 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7963 inst.instruction |= (newimm & 0x800) << 15;
7964 inst.instruction |= (newimm & 0x700) << 4;
7965 inst.instruction |= (newimm & 0x0ff);
7966 return TRUE;
7967 }
fc289b0a 7968 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7969 else if ((v & ~0xFFFF) == 0
7970 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7971 {
582cfe03 7972 int imm = v & 0xFFFF;
12569877 7973
582cfe03 7974 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7975 inst.instruction |= (inst.operands[i].reg << 8);
7976 inst.instruction |= (imm & 0xf000) << 4;
7977 inst.instruction |= (imm & 0x0800) << 15;
7978 inst.instruction |= (imm & 0x0700) << 4;
7979 inst.instruction |= (imm & 0x00ff);
7980 return TRUE;
7981 }
7982 }
8335d6aa 7983 }
12569877 7984 else if (arm_p)
ba592044
AM
7985 {
7986 int value = encode_arm_immediate (v);
12569877 7987
ba592044
AM
7988 if (value != FAIL)
7989 {
7990 /* This can be done with a mov instruction. */
7991 inst.instruction &= LITERAL_MASK;
7992 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7993 inst.instruction |= value & 0xfff;
7994 return TRUE;
7995 }
8335d6aa 7996
ba592044
AM
7997 value = encode_arm_immediate (~ v);
7998 if (value != FAIL)
7999 {
8000 /* This can be done with a mvn instruction. */
8001 inst.instruction &= LITERAL_MASK;
8002 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8003 inst.instruction |= value & 0xfff;
8004 return TRUE;
8005 }
8006 }
8007 else if (t == CONST_VEC)
8335d6aa 8008 {
ba592044
AM
8009 int op = 0;
8010 unsigned immbits = 0;
8011 unsigned immlo = inst.operands[1].imm;
8012 unsigned immhi = inst.operands[1].regisimm
8013 ? inst.operands[1].reg
8014 : inst.reloc.exp.X_unsigned
8015 ? 0
8016 : ((bfd_int64_t)((int) immlo)) >> 32;
8017 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8018 &op, 64, NT_invtype);
8019
8020 if (cmode == FAIL)
8021 {
8022 neon_invert_size (&immlo, &immhi, 64);
8023 op = !op;
8024 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8025 &op, 64, NT_invtype);
8026 }
8027
8028 if (cmode != FAIL)
8029 {
8030 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8031 | (1 << 23)
8032 | (cmode << 8)
8033 | (op << 5)
8034 | (1 << 4);
8035
8036 /* Fill other bits in vmov encoding for both thumb and arm. */
8037 if (thumb_mode)
eff0bc54 8038 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8039 else
eff0bc54 8040 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8041 neon_write_immbits (immbits);
8042 return TRUE;
8043 }
8335d6aa
JW
8044 }
8045 }
8335d6aa 8046
ba592044
AM
8047 if (t == CONST_VEC)
8048 {
8049 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8050 if (inst.operands[i].issingle
8051 && is_quarter_float (inst.operands[1].imm)
8052 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8053 {
ba592044
AM
8054 inst.operands[1].imm =
8055 neon_qfloat_bits (v);
8056 do_vfp_nsyn_opcode ("fconsts");
8057 return TRUE;
8335d6aa 8058 }
5fc177c8
NC
8059
8060 /* If our host does not support a 64-bit type then we cannot perform
8061 the following optimization. This mean that there will be a
8062 discrepancy between the output produced by an assembler built for
8063 a 32-bit-only host and the output produced from a 64-bit host, but
8064 this cannot be helped. */
8065#if defined BFD_HOST_64_BIT
ba592044
AM
8066 else if (!inst.operands[1].issingle
8067 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8068 {
ba592044
AM
8069 if (is_double_a_single (v)
8070 && is_quarter_float (double_to_single (v)))
8071 {
8072 inst.operands[1].imm =
8073 neon_qfloat_bits (double_to_single (v));
8074 do_vfp_nsyn_opcode ("fconstd");
8075 return TRUE;
8076 }
8335d6aa 8077 }
5fc177c8 8078#endif
8335d6aa
JW
8079 }
8080 }
8081
8082 if (add_to_lit_pool ((!inst.operands[i].isvec
8083 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8084 return TRUE;
8085
8086 inst.operands[1].reg = REG_PC;
8087 inst.operands[1].isreg = 1;
8088 inst.operands[1].preind = 1;
8089 inst.reloc.pc_rel = 1;
8090 inst.reloc.type = (thumb_p
8091 ? BFD_RELOC_ARM_THUMB_OFFSET
8092 : (mode_3
8093 ? BFD_RELOC_ARM_HWLITERAL
8094 : BFD_RELOC_ARM_LITERAL));
8095 return FALSE;
8096}
8097
8098/* inst.operands[i] was set up by parse_address. Encode it into an
8099 ARM-format instruction. Reject all forms which cannot be encoded
8100 into a coprocessor load/store instruction. If wb_ok is false,
8101 reject use of writeback; if unind_ok is false, reject use of
8102 unindexed addressing. If reloc_override is not 0, use it instead
8103 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8104 (in which case it is preserved). */
8105
8106static int
8107encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8108{
8109 if (!inst.operands[i].isreg)
8110 {
99b2a2dd
NC
8111 /* PR 18256 */
8112 if (! inst.operands[0].isvec)
8113 {
8114 inst.error = _("invalid co-processor operand");
8115 return FAIL;
8116 }
8335d6aa
JW
8117 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8118 return SUCCESS;
8119 }
8120
8121 inst.instruction |= inst.operands[i].reg << 16;
8122
8123 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8124
8125 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8126 {
8127 gas_assert (!inst.operands[i].writeback);
8128 if (!unind_ok)
8129 {
8130 inst.error = _("instruction does not support unindexed addressing");
8131 return FAIL;
8132 }
8133 inst.instruction |= inst.operands[i].imm;
8134 inst.instruction |= INDEX_UP;
8135 return SUCCESS;
8136 }
8137
8138 if (inst.operands[i].preind)
8139 inst.instruction |= PRE_INDEX;
8140
8141 if (inst.operands[i].writeback)
09d92015 8142 {
8335d6aa 8143 if (inst.operands[i].reg == REG_PC)
c19d1205 8144 {
8335d6aa
JW
8145 inst.error = _("pc may not be used with write-back");
8146 return FAIL;
c19d1205 8147 }
8335d6aa 8148 if (!wb_ok)
c19d1205 8149 {
8335d6aa
JW
8150 inst.error = _("instruction does not support writeback");
8151 return FAIL;
c19d1205 8152 }
8335d6aa 8153 inst.instruction |= WRITE_BACK;
09d92015
MM
8154 }
8155
8335d6aa
JW
8156 if (reloc_override)
8157 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8158 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8159 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8160 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8161 {
8335d6aa
JW
8162 if (thumb_mode)
8163 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8164 else
8165 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8166 }
8335d6aa
JW
8167
8168 /* Prefer + for zero encoded value. */
8169 if (!inst.operands[i].negative)
8170 inst.instruction |= INDEX_UP;
8171
8172 return SUCCESS;
09d92015
MM
8173}
8174
5f4273c7 8175/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8176 First some generics; their names are taken from the conventional
8177 bit positions for register arguments in ARM format instructions. */
09d92015 8178
a737bd4d 8179static void
c19d1205 8180do_noargs (void)
09d92015 8181{
c19d1205 8182}
a737bd4d 8183
c19d1205
ZW
8184static void
8185do_rd (void)
8186{
8187 inst.instruction |= inst.operands[0].reg << 12;
8188}
a737bd4d 8189
16a1fa25
TP
8190static void
8191do_rn (void)
8192{
8193 inst.instruction |= inst.operands[0].reg << 16;
8194}
8195
c19d1205
ZW
8196static void
8197do_rd_rm (void)
8198{
8199 inst.instruction |= inst.operands[0].reg << 12;
8200 inst.instruction |= inst.operands[1].reg;
8201}
09d92015 8202
9eb6c0f1
MGD
8203static void
8204do_rm_rn (void)
8205{
8206 inst.instruction |= inst.operands[0].reg;
8207 inst.instruction |= inst.operands[1].reg << 16;
8208}
8209
c19d1205
ZW
8210static void
8211do_rd_rn (void)
8212{
8213 inst.instruction |= inst.operands[0].reg << 12;
8214 inst.instruction |= inst.operands[1].reg << 16;
8215}
a737bd4d 8216
c19d1205
ZW
8217static void
8218do_rn_rd (void)
8219{
8220 inst.instruction |= inst.operands[0].reg << 16;
8221 inst.instruction |= inst.operands[1].reg << 12;
8222}
09d92015 8223
4ed7ed8d
TP
8224static void
8225do_tt (void)
8226{
8227 inst.instruction |= inst.operands[0].reg << 8;
8228 inst.instruction |= inst.operands[1].reg << 16;
8229}
8230
59d09be6
MGD
8231static bfd_boolean
8232check_obsolete (const arm_feature_set *feature, const char *msg)
8233{
8234 if (ARM_CPU_IS_ANY (cpu_variant))
8235 {
5c3696f8 8236 as_tsktsk ("%s", msg);
59d09be6
MGD
8237 return TRUE;
8238 }
8239 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8240 {
8241 as_bad ("%s", msg);
8242 return TRUE;
8243 }
8244
8245 return FALSE;
8246}
8247
c19d1205
ZW
8248static void
8249do_rd_rm_rn (void)
8250{
9a64e435 8251 unsigned Rn = inst.operands[2].reg;
708587a4 8252 /* Enforce restrictions on SWP instruction. */
9a64e435 8253 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8254 {
8255 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8256 _("Rn must not overlap other operands"));
8257
59d09be6
MGD
8258 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8259 */
8260 if (!check_obsolete (&arm_ext_v8,
8261 _("swp{b} use is obsoleted for ARMv8 and later"))
8262 && warn_on_deprecated
8263 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8264 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8265 }
59d09be6 8266
c19d1205
ZW
8267 inst.instruction |= inst.operands[0].reg << 12;
8268 inst.instruction |= inst.operands[1].reg;
9a64e435 8269 inst.instruction |= Rn << 16;
c19d1205 8270}
09d92015 8271
c19d1205
ZW
8272static void
8273do_rd_rn_rm (void)
8274{
8275 inst.instruction |= inst.operands[0].reg << 12;
8276 inst.instruction |= inst.operands[1].reg << 16;
8277 inst.instruction |= inst.operands[2].reg;
8278}
a737bd4d 8279
c19d1205
ZW
8280static void
8281do_rm_rd_rn (void)
8282{
5be8be5d
DG
8283 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8284 constraint (((inst.reloc.exp.X_op != O_constant
8285 && inst.reloc.exp.X_op != O_illegal)
8286 || inst.reloc.exp.X_add_number != 0),
8287 BAD_ADDR_MODE);
c19d1205
ZW
8288 inst.instruction |= inst.operands[0].reg;
8289 inst.instruction |= inst.operands[1].reg << 12;
8290 inst.instruction |= inst.operands[2].reg << 16;
8291}
09d92015 8292
c19d1205
ZW
8293static void
8294do_imm0 (void)
8295{
8296 inst.instruction |= inst.operands[0].imm;
8297}
09d92015 8298
c19d1205
ZW
8299static void
8300do_rd_cpaddr (void)
8301{
8302 inst.instruction |= inst.operands[0].reg << 12;
8303 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8304}
a737bd4d 8305
c19d1205
ZW
8306/* ARM instructions, in alphabetical order by function name (except
8307 that wrapper functions appear immediately after the function they
8308 wrap). */
09d92015 8309
c19d1205
ZW
8310/* This is a pseudo-op of the form "adr rd, label" to be converted
8311 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8312
8313static void
c19d1205 8314do_adr (void)
09d92015 8315{
c19d1205 8316 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8317
c19d1205
ZW
8318 /* Frag hacking will turn this into a sub instruction if the offset turns
8319 out to be negative. */
8320 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8321 inst.reloc.pc_rel = 1;
2fc8bdac 8322 inst.reloc.exp.X_add_number -= 8;
c19d1205 8323}
b99bd4ef 8324
c19d1205
ZW
8325/* This is a pseudo-op of the form "adrl rd, label" to be converted
8326 into a relative address of the form:
8327 add rd, pc, #low(label-.-8)"
8328 add rd, rd, #high(label-.-8)" */
b99bd4ef 8329
c19d1205
ZW
8330static void
8331do_adrl (void)
8332{
8333 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8334
c19d1205
ZW
8335 /* Frag hacking will turn this into a sub instruction if the offset turns
8336 out to be negative. */
8337 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8338 inst.reloc.pc_rel = 1;
8339 inst.size = INSN_SIZE * 2;
2fc8bdac 8340 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8341}
8342
b99bd4ef 8343static void
c19d1205 8344do_arit (void)
b99bd4ef 8345{
a9f02af8
MG
8346 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8347 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8348 THUMB1_RELOC_ONLY);
c19d1205
ZW
8349 if (!inst.operands[1].present)
8350 inst.operands[1].reg = inst.operands[0].reg;
8351 inst.instruction |= inst.operands[0].reg << 12;
8352 inst.instruction |= inst.operands[1].reg << 16;
8353 encode_arm_shifter_operand (2);
8354}
b99bd4ef 8355
62b3e311
PB
8356static void
8357do_barrier (void)
8358{
8359 if (inst.operands[0].present)
ccb84d65 8360 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8361 else
8362 inst.instruction |= 0xf;
8363}
8364
c19d1205
ZW
8365static void
8366do_bfc (void)
8367{
8368 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8369 constraint (msb > 32, _("bit-field extends past end of register"));
8370 /* The instruction encoding stores the LSB and MSB,
8371 not the LSB and width. */
8372 inst.instruction |= inst.operands[0].reg << 12;
8373 inst.instruction |= inst.operands[1].imm << 7;
8374 inst.instruction |= (msb - 1) << 16;
8375}
b99bd4ef 8376
c19d1205
ZW
8377static void
8378do_bfi (void)
8379{
8380 unsigned int msb;
b99bd4ef 8381
c19d1205
ZW
8382 /* #0 in second position is alternative syntax for bfc, which is
8383 the same instruction but with REG_PC in the Rm field. */
8384 if (!inst.operands[1].isreg)
8385 inst.operands[1].reg = REG_PC;
b99bd4ef 8386
c19d1205
ZW
8387 msb = inst.operands[2].imm + inst.operands[3].imm;
8388 constraint (msb > 32, _("bit-field extends past end of register"));
8389 /* The instruction encoding stores the LSB and MSB,
8390 not the LSB and width. */
8391 inst.instruction |= inst.operands[0].reg << 12;
8392 inst.instruction |= inst.operands[1].reg;
8393 inst.instruction |= inst.operands[2].imm << 7;
8394 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8395}
8396
b99bd4ef 8397static void
c19d1205 8398do_bfx (void)
b99bd4ef 8399{
c19d1205
ZW
8400 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8401 _("bit-field extends past end of register"));
8402 inst.instruction |= inst.operands[0].reg << 12;
8403 inst.instruction |= inst.operands[1].reg;
8404 inst.instruction |= inst.operands[2].imm << 7;
8405 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8406}
09d92015 8407
c19d1205
ZW
8408/* ARM V5 breakpoint instruction (argument parse)
8409 BKPT <16 bit unsigned immediate>
8410 Instruction is not conditional.
8411 The bit pattern given in insns[] has the COND_ALWAYS condition,
8412 and it is an error if the caller tried to override that. */
b99bd4ef 8413
c19d1205
ZW
8414static void
8415do_bkpt (void)
8416{
8417 /* Top 12 of 16 bits to bits 19:8. */
8418 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8419
c19d1205
ZW
8420 /* Bottom 4 of 16 bits to bits 3:0. */
8421 inst.instruction |= inst.operands[0].imm & 0xf;
8422}
09d92015 8423
c19d1205
ZW
8424static void
8425encode_branch (int default_reloc)
8426{
8427 if (inst.operands[0].hasreloc)
8428 {
0855e32b
NS
8429 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8430 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8431 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8432 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8433 ? BFD_RELOC_ARM_PLT32
8434 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8435 }
b99bd4ef 8436 else
9ae92b05 8437 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8438 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8439}
8440
b99bd4ef 8441static void
c19d1205 8442do_branch (void)
b99bd4ef 8443{
39b41c9c
PB
8444#ifdef OBJ_ELF
8445 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8446 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8447 else
8448#endif
8449 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8450}
8451
8452static void
8453do_bl (void)
8454{
8455#ifdef OBJ_ELF
8456 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8457 {
8458 if (inst.cond == COND_ALWAYS)
8459 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8460 else
8461 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8462 }
8463 else
8464#endif
8465 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8466}
b99bd4ef 8467
c19d1205
ZW
8468/* ARM V5 branch-link-exchange instruction (argument parse)
8469 BLX <target_addr> ie BLX(1)
8470 BLX{<condition>} <Rm> ie BLX(2)
8471 Unfortunately, there are two different opcodes for this mnemonic.
8472 So, the insns[].value is not used, and the code here zaps values
8473 into inst.instruction.
8474 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8475
c19d1205
ZW
8476static void
8477do_blx (void)
8478{
8479 if (inst.operands[0].isreg)
b99bd4ef 8480 {
c19d1205
ZW
8481 /* Arg is a register; the opcode provided by insns[] is correct.
8482 It is not illegal to do "blx pc", just useless. */
8483 if (inst.operands[0].reg == REG_PC)
8484 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8485
c19d1205
ZW
8486 inst.instruction |= inst.operands[0].reg;
8487 }
8488 else
b99bd4ef 8489 {
c19d1205 8490 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8491 conditionally, and the opcode must be adjusted.
8492 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8493 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8494 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8495 inst.instruction = 0xfa000000;
267bf995 8496 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8497 }
c19d1205
ZW
8498}
8499
8500static void
8501do_bx (void)
8502{
845b51d6
PB
8503 bfd_boolean want_reloc;
8504
c19d1205
ZW
8505 if (inst.operands[0].reg == REG_PC)
8506 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8507
c19d1205 8508 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8509 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8510 it is for ARMv4t or earlier. */
8511 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8512 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8513 want_reloc = TRUE;
8514
5ad34203 8515#ifdef OBJ_ELF
845b51d6 8516 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8517#endif
584206db 8518 want_reloc = FALSE;
845b51d6
PB
8519
8520 if (want_reloc)
8521 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8522}
8523
c19d1205
ZW
8524
8525/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8526
8527static void
c19d1205 8528do_bxj (void)
a737bd4d 8529{
c19d1205
ZW
8530 if (inst.operands[0].reg == REG_PC)
8531 as_tsktsk (_("use of r15 in bxj is not really useful"));
8532
8533 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8534}
8535
c19d1205
ZW
8536/* Co-processor data operation:
8537 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8538 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8539static void
8540do_cdp (void)
8541{
8542 inst.instruction |= inst.operands[0].reg << 8;
8543 inst.instruction |= inst.operands[1].imm << 20;
8544 inst.instruction |= inst.operands[2].reg << 12;
8545 inst.instruction |= inst.operands[3].reg << 16;
8546 inst.instruction |= inst.operands[4].reg;
8547 inst.instruction |= inst.operands[5].imm << 5;
8548}
a737bd4d
NC
8549
8550static void
c19d1205 8551do_cmp (void)
a737bd4d 8552{
c19d1205
ZW
8553 inst.instruction |= inst.operands[0].reg << 16;
8554 encode_arm_shifter_operand (1);
a737bd4d
NC
8555}
8556
c19d1205
ZW
8557/* Transfer between coprocessor and ARM registers.
8558 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8559 MRC2
8560 MCR{cond}
8561 MCR2
8562
8563 No special properties. */
09d92015 8564
dcbd0d71
MGD
8565struct deprecated_coproc_regs_s
8566{
8567 unsigned cp;
8568 int opc1;
8569 unsigned crn;
8570 unsigned crm;
8571 int opc2;
8572 arm_feature_set deprecated;
8573 arm_feature_set obsoleted;
8574 const char *dep_msg;
8575 const char *obs_msg;
8576};
8577
8578#define DEPR_ACCESS_V8 \
8579 N_("This coprocessor register access is deprecated in ARMv8")
8580
8581/* Table of all deprecated coprocessor registers. */
8582static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8583{
8584 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8585 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8586 DEPR_ACCESS_V8, NULL},
8587 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8588 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8589 DEPR_ACCESS_V8, NULL},
8590 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8591 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8592 DEPR_ACCESS_V8, NULL},
8593 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8594 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8595 DEPR_ACCESS_V8, NULL},
8596 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8597 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8598 DEPR_ACCESS_V8, NULL},
8599};
8600
8601#undef DEPR_ACCESS_V8
8602
8603static const size_t deprecated_coproc_reg_count =
8604 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8605
09d92015 8606static void
c19d1205 8607do_co_reg (void)
09d92015 8608{
fdfde340 8609 unsigned Rd;
dcbd0d71 8610 size_t i;
fdfde340
JM
8611
8612 Rd = inst.operands[2].reg;
8613 if (thumb_mode)
8614 {
8615 if (inst.instruction == 0xee000010
8616 || inst.instruction == 0xfe000010)
8617 /* MCR, MCR2 */
8618 reject_bad_reg (Rd);
8619 else
8620 /* MRC, MRC2 */
8621 constraint (Rd == REG_SP, BAD_SP);
8622 }
8623 else
8624 {
8625 /* MCR */
8626 if (inst.instruction == 0xe000010)
8627 constraint (Rd == REG_PC, BAD_PC);
8628 }
8629
dcbd0d71
MGD
8630 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8631 {
8632 const struct deprecated_coproc_regs_s *r =
8633 deprecated_coproc_regs + i;
8634
8635 if (inst.operands[0].reg == r->cp
8636 && inst.operands[1].imm == r->opc1
8637 && inst.operands[3].reg == r->crn
8638 && inst.operands[4].reg == r->crm
8639 && inst.operands[5].imm == r->opc2)
8640 {
b10bf8c5 8641 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8642 && warn_on_deprecated
dcbd0d71 8643 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8644 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8645 }
8646 }
fdfde340 8647
c19d1205
ZW
8648 inst.instruction |= inst.operands[0].reg << 8;
8649 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8650 inst.instruction |= Rd << 12;
c19d1205
ZW
8651 inst.instruction |= inst.operands[3].reg << 16;
8652 inst.instruction |= inst.operands[4].reg;
8653 inst.instruction |= inst.operands[5].imm << 5;
8654}
09d92015 8655
c19d1205
ZW
8656/* Transfer between coprocessor register and pair of ARM registers.
8657 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8658 MCRR2
8659 MRRC{cond}
8660 MRRC2
b99bd4ef 8661
c19d1205 8662 Two XScale instructions are special cases of these:
09d92015 8663
c19d1205
ZW
8664 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8665 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8666
5f4273c7 8667 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8668
c19d1205
ZW
8669static void
8670do_co_reg2c (void)
8671{
fdfde340
JM
8672 unsigned Rd, Rn;
8673
8674 Rd = inst.operands[2].reg;
8675 Rn = inst.operands[3].reg;
8676
8677 if (thumb_mode)
8678 {
8679 reject_bad_reg (Rd);
8680 reject_bad_reg (Rn);
8681 }
8682 else
8683 {
8684 constraint (Rd == REG_PC, BAD_PC);
8685 constraint (Rn == REG_PC, BAD_PC);
8686 }
8687
c19d1205
ZW
8688 inst.instruction |= inst.operands[0].reg << 8;
8689 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8690 inst.instruction |= Rd << 12;
8691 inst.instruction |= Rn << 16;
c19d1205 8692 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8693}
8694
c19d1205
ZW
8695static void
8696do_cpsi (void)
8697{
8698 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8699 if (inst.operands[1].present)
8700 {
8701 inst.instruction |= CPSI_MMOD;
8702 inst.instruction |= inst.operands[1].imm;
8703 }
c19d1205 8704}
b99bd4ef 8705
62b3e311
PB
8706static void
8707do_dbg (void)
8708{
8709 inst.instruction |= inst.operands[0].imm;
8710}
8711
eea54501
MGD
8712static void
8713do_div (void)
8714{
8715 unsigned Rd, Rn, Rm;
8716
8717 Rd = inst.operands[0].reg;
8718 Rn = (inst.operands[1].present
8719 ? inst.operands[1].reg : Rd);
8720 Rm = inst.operands[2].reg;
8721
8722 constraint ((Rd == REG_PC), BAD_PC);
8723 constraint ((Rn == REG_PC), BAD_PC);
8724 constraint ((Rm == REG_PC), BAD_PC);
8725
8726 inst.instruction |= Rd << 16;
8727 inst.instruction |= Rn << 0;
8728 inst.instruction |= Rm << 8;
8729}
8730
b99bd4ef 8731static void
c19d1205 8732do_it (void)
b99bd4ef 8733{
c19d1205 8734 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8735 process it to do the validation as if in
8736 thumb mode, just in case the code gets
8737 assembled for thumb using the unified syntax. */
8738
c19d1205 8739 inst.size = 0;
e07e6e58
NC
8740 if (unified_syntax)
8741 {
8742 set_it_insn_type (IT_INSN);
8743 now_it.mask = (inst.instruction & 0xf) | 0x10;
8744 now_it.cc = inst.operands[0].imm;
8745 }
09d92015 8746}
b99bd4ef 8747
6530b175
NC
8748/* If there is only one register in the register list,
8749 then return its register number. Otherwise return -1. */
8750static int
8751only_one_reg_in_list (int range)
8752{
8753 int i = ffs (range) - 1;
8754 return (i > 15 || range != (1 << i)) ? -1 : i;
8755}
8756
09d92015 8757static void
6530b175 8758encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8759{
c19d1205
ZW
8760 int base_reg = inst.operands[0].reg;
8761 int range = inst.operands[1].imm;
6530b175 8762 int one_reg;
ea6ef066 8763
c19d1205
ZW
8764 inst.instruction |= base_reg << 16;
8765 inst.instruction |= range;
ea6ef066 8766
c19d1205
ZW
8767 if (inst.operands[1].writeback)
8768 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8769
c19d1205 8770 if (inst.operands[0].writeback)
ea6ef066 8771 {
c19d1205
ZW
8772 inst.instruction |= WRITE_BACK;
8773 /* Check for unpredictable uses of writeback. */
8774 if (inst.instruction & LOAD_BIT)
09d92015 8775 {
c19d1205
ZW
8776 /* Not allowed in LDM type 2. */
8777 if ((inst.instruction & LDM_TYPE_2_OR_3)
8778 && ((range & (1 << REG_PC)) == 0))
8779 as_warn (_("writeback of base register is UNPREDICTABLE"));
8780 /* Only allowed if base reg not in list for other types. */
8781 else if (range & (1 << base_reg))
8782 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8783 }
8784 else /* STM. */
8785 {
8786 /* Not allowed for type 2. */
8787 if (inst.instruction & LDM_TYPE_2_OR_3)
8788 as_warn (_("writeback of base register is UNPREDICTABLE"));
8789 /* Only allowed if base reg not in list, or first in list. */
8790 else if ((range & (1 << base_reg))
8791 && (range & ((1 << base_reg) - 1)))
8792 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8793 }
ea6ef066 8794 }
6530b175
NC
8795
8796 /* If PUSH/POP has only one register, then use the A2 encoding. */
8797 one_reg = only_one_reg_in_list (range);
8798 if (from_push_pop_mnem && one_reg >= 0)
8799 {
8800 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8801
8802 inst.instruction &= A_COND_MASK;
8803 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8804 inst.instruction |= one_reg << 12;
8805 }
8806}
8807
8808static void
8809do_ldmstm (void)
8810{
8811 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8812}
8813
c19d1205
ZW
8814/* ARMv5TE load-consecutive (argument parse)
8815 Mode is like LDRH.
8816
8817 LDRccD R, mode
8818 STRccD R, mode. */
8819
a737bd4d 8820static void
c19d1205 8821do_ldrd (void)
a737bd4d 8822{
c19d1205 8823 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8824 _("first transfer register must be even"));
c19d1205
ZW
8825 constraint (inst.operands[1].present
8826 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8827 _("can only transfer two consecutive registers"));
c19d1205
ZW
8828 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8829 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8830
c19d1205
ZW
8831 if (!inst.operands[1].present)
8832 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8833
c56791bb
RE
8834 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8835 register and the first register written; we have to diagnose
8836 overlap between the base and the second register written here. */
ea6ef066 8837
c56791bb
RE
8838 if (inst.operands[2].reg == inst.operands[1].reg
8839 && (inst.operands[2].writeback || inst.operands[2].postind))
8840 as_warn (_("base register written back, and overlaps "
8841 "second transfer register"));
b05fe5cf 8842
c56791bb
RE
8843 if (!(inst.instruction & V4_STR_BIT))
8844 {
c19d1205 8845 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8846 destination (even if not write-back). */
8847 if (inst.operands[2].immisreg
8848 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8849 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8850 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8851 }
c19d1205
ZW
8852 inst.instruction |= inst.operands[0].reg << 12;
8853 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8854}
8855
8856static void
c19d1205 8857do_ldrex (void)
b05fe5cf 8858{
c19d1205
ZW
8859 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8860 || inst.operands[1].postind || inst.operands[1].writeback
8861 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8862 || inst.operands[1].negative
8863 /* This can arise if the programmer has written
8864 strex rN, rM, foo
8865 or if they have mistakenly used a register name as the last
8866 operand, eg:
8867 strex rN, rM, rX
8868 It is very difficult to distinguish between these two cases
8869 because "rX" might actually be a label. ie the register
8870 name has been occluded by a symbol of the same name. So we
8871 just generate a general 'bad addressing mode' type error
8872 message and leave it up to the programmer to discover the
8873 true cause and fix their mistake. */
8874 || (inst.operands[1].reg == REG_PC),
8875 BAD_ADDR_MODE);
b05fe5cf 8876
c19d1205
ZW
8877 constraint (inst.reloc.exp.X_op != O_constant
8878 || inst.reloc.exp.X_add_number != 0,
8879 _("offset must be zero in ARM encoding"));
b05fe5cf 8880
5be8be5d
DG
8881 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8882
c19d1205
ZW
8883 inst.instruction |= inst.operands[0].reg << 12;
8884 inst.instruction |= inst.operands[1].reg << 16;
8885 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8886}
8887
8888static void
c19d1205 8889do_ldrexd (void)
b05fe5cf 8890{
c19d1205
ZW
8891 constraint (inst.operands[0].reg % 2 != 0,
8892 _("even register required"));
8893 constraint (inst.operands[1].present
8894 && inst.operands[1].reg != inst.operands[0].reg + 1,
8895 _("can only load two consecutive registers"));
8896 /* If op 1 were present and equal to PC, this function wouldn't
8897 have been called in the first place. */
8898 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8899
c19d1205
ZW
8900 inst.instruction |= inst.operands[0].reg << 12;
8901 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8902}
8903
1be5fd2e
NC
8904/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8905 which is not a multiple of four is UNPREDICTABLE. */
8906static void
8907check_ldr_r15_aligned (void)
8908{
8909 constraint (!(inst.operands[1].immisreg)
8910 && (inst.operands[0].reg == REG_PC
8911 && inst.operands[1].reg == REG_PC
8912 && (inst.reloc.exp.X_add_number & 0x3)),
8913 _("ldr to register 15 must be 4-byte alligned"));
8914}
8915
b05fe5cf 8916static void
c19d1205 8917do_ldst (void)
b05fe5cf 8918{
c19d1205
ZW
8919 inst.instruction |= inst.operands[0].reg << 12;
8920 if (!inst.operands[1].isreg)
8335d6aa 8921 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8922 return;
c19d1205 8923 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8924 check_ldr_r15_aligned ();
b05fe5cf
ZW
8925}
8926
8927static void
c19d1205 8928do_ldstt (void)
b05fe5cf 8929{
c19d1205
ZW
8930 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8931 reject [Rn,...]. */
8932 if (inst.operands[1].preind)
b05fe5cf 8933 {
bd3ba5d1
NC
8934 constraint (inst.reloc.exp.X_op != O_constant
8935 || inst.reloc.exp.X_add_number != 0,
c19d1205 8936 _("this instruction requires a post-indexed address"));
b05fe5cf 8937
c19d1205
ZW
8938 inst.operands[1].preind = 0;
8939 inst.operands[1].postind = 1;
8940 inst.operands[1].writeback = 1;
b05fe5cf 8941 }
c19d1205
ZW
8942 inst.instruction |= inst.operands[0].reg << 12;
8943 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8944}
b05fe5cf 8945
c19d1205 8946/* Halfword and signed-byte load/store operations. */
b05fe5cf 8947
c19d1205
ZW
8948static void
8949do_ldstv4 (void)
8950{
ff4a8d2b 8951 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8952 inst.instruction |= inst.operands[0].reg << 12;
8953 if (!inst.operands[1].isreg)
8335d6aa 8954 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8955 return;
c19d1205 8956 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8957}
8958
8959static void
c19d1205 8960do_ldsttv4 (void)
b05fe5cf 8961{
c19d1205
ZW
8962 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8963 reject [Rn,...]. */
8964 if (inst.operands[1].preind)
b05fe5cf 8965 {
bd3ba5d1
NC
8966 constraint (inst.reloc.exp.X_op != O_constant
8967 || inst.reloc.exp.X_add_number != 0,
c19d1205 8968 _("this instruction requires a post-indexed address"));
b05fe5cf 8969
c19d1205
ZW
8970 inst.operands[1].preind = 0;
8971 inst.operands[1].postind = 1;
8972 inst.operands[1].writeback = 1;
b05fe5cf 8973 }
c19d1205
ZW
8974 inst.instruction |= inst.operands[0].reg << 12;
8975 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8976}
b05fe5cf 8977
c19d1205
ZW
8978/* Co-processor register load/store.
8979 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8980static void
8981do_lstc (void)
8982{
8983 inst.instruction |= inst.operands[0].reg << 8;
8984 inst.instruction |= inst.operands[1].reg << 12;
8985 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8986}
8987
b05fe5cf 8988static void
c19d1205 8989do_mlas (void)
b05fe5cf 8990{
8fb9d7b9 8991 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8992 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8993 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8994 && !(inst.instruction & 0x00400000))
8fb9d7b9 8995 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8996
c19d1205
ZW
8997 inst.instruction |= inst.operands[0].reg << 16;
8998 inst.instruction |= inst.operands[1].reg;
8999 inst.instruction |= inst.operands[2].reg << 8;
9000 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9001}
b05fe5cf 9002
c19d1205
ZW
9003static void
9004do_mov (void)
9005{
a9f02af8
MG
9006 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9007 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9008 THUMB1_RELOC_ONLY);
c19d1205
ZW
9009 inst.instruction |= inst.operands[0].reg << 12;
9010 encode_arm_shifter_operand (1);
9011}
b05fe5cf 9012
c19d1205
ZW
9013/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9014static void
9015do_mov16 (void)
9016{
b6895b4f
PB
9017 bfd_vma imm;
9018 bfd_boolean top;
9019
9020 top = (inst.instruction & 0x00400000) != 0;
9021 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
9022 _(":lower16: not allowed this instruction"));
9023 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
9024 _(":upper16: not allowed instruction"));
c19d1205 9025 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9026 if (inst.reloc.type == BFD_RELOC_UNUSED)
9027 {
9028 imm = inst.reloc.exp.X_add_number;
9029 /* The value is in two pieces: 0:11, 16:19. */
9030 inst.instruction |= (imm & 0x00000fff);
9031 inst.instruction |= (imm & 0x0000f000) << 4;
9032 }
b05fe5cf 9033}
b99bd4ef 9034
037e8744
JB
9035static int
9036do_vfp_nsyn_mrs (void)
9037{
9038 if (inst.operands[0].isvec)
9039 {
9040 if (inst.operands[1].reg != 1)
477330fc 9041 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9042 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9043 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9044 do_vfp_nsyn_opcode ("fmstat");
9045 }
9046 else if (inst.operands[1].isvec)
9047 do_vfp_nsyn_opcode ("fmrx");
9048 else
9049 return FAIL;
5f4273c7 9050
037e8744
JB
9051 return SUCCESS;
9052}
9053
9054static int
9055do_vfp_nsyn_msr (void)
9056{
9057 if (inst.operands[0].isvec)
9058 do_vfp_nsyn_opcode ("fmxr");
9059 else
9060 return FAIL;
9061
9062 return SUCCESS;
9063}
9064
f7c21dc7
NC
9065static void
9066do_vmrs (void)
9067{
9068 unsigned Rt = inst.operands[0].reg;
fa94de6b 9069
16d02dc9 9070 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9071 {
9072 inst.error = BAD_SP;
9073 return;
9074 }
9075
9076 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9077 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9078 {
9079 inst.error = BAD_PC;
9080 return;
9081 }
9082
16d02dc9
JB
9083 /* If we get through parsing the register name, we just insert the number
9084 generated into the instruction without further validation. */
9085 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9086 inst.instruction |= (Rt << 12);
9087}
9088
9089static void
9090do_vmsr (void)
9091{
9092 unsigned Rt = inst.operands[1].reg;
fa94de6b 9093
f7c21dc7
NC
9094 if (thumb_mode)
9095 reject_bad_reg (Rt);
9096 else if (Rt == REG_PC)
9097 {
9098 inst.error = BAD_PC;
9099 return;
9100 }
9101
16d02dc9
JB
9102 /* If we get through parsing the register name, we just insert the number
9103 generated into the instruction without further validation. */
9104 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9105 inst.instruction |= (Rt << 12);
9106}
9107
b99bd4ef 9108static void
c19d1205 9109do_mrs (void)
b99bd4ef 9110{
90ec0d68
MGD
9111 unsigned br;
9112
037e8744
JB
9113 if (do_vfp_nsyn_mrs () == SUCCESS)
9114 return;
9115
ff4a8d2b 9116 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9117 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9118
9119 if (inst.operands[1].isreg)
9120 {
9121 br = inst.operands[1].reg;
9122 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9123 as_bad (_("bad register for mrs"));
9124 }
9125 else
9126 {
9127 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9128 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9129 != (PSR_c|PSR_f),
d2cd1205 9130 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9131 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9132 }
9133
9134 inst.instruction |= br;
c19d1205 9135}
b99bd4ef 9136
c19d1205
ZW
9137/* Two possible forms:
9138 "{C|S}PSR_<field>, Rm",
9139 "{C|S}PSR_f, #expression". */
b99bd4ef 9140
c19d1205
ZW
9141static void
9142do_msr (void)
9143{
037e8744
JB
9144 if (do_vfp_nsyn_msr () == SUCCESS)
9145 return;
9146
c19d1205
ZW
9147 inst.instruction |= inst.operands[0].imm;
9148 if (inst.operands[1].isreg)
9149 inst.instruction |= inst.operands[1].reg;
9150 else
b99bd4ef 9151 {
c19d1205
ZW
9152 inst.instruction |= INST_IMMEDIATE;
9153 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9154 inst.reloc.pc_rel = 0;
b99bd4ef 9155 }
b99bd4ef
NC
9156}
9157
c19d1205
ZW
9158static void
9159do_mul (void)
a737bd4d 9160{
ff4a8d2b
NC
9161 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9162
c19d1205
ZW
9163 if (!inst.operands[2].present)
9164 inst.operands[2].reg = inst.operands[0].reg;
9165 inst.instruction |= inst.operands[0].reg << 16;
9166 inst.instruction |= inst.operands[1].reg;
9167 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9168
8fb9d7b9
MS
9169 if (inst.operands[0].reg == inst.operands[1].reg
9170 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9171 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9172}
9173
c19d1205
ZW
9174/* Long Multiply Parser
9175 UMULL RdLo, RdHi, Rm, Rs
9176 SMULL RdLo, RdHi, Rm, Rs
9177 UMLAL RdLo, RdHi, Rm, Rs
9178 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9179
9180static void
c19d1205 9181do_mull (void)
b99bd4ef 9182{
c19d1205
ZW
9183 inst.instruction |= inst.operands[0].reg << 12;
9184 inst.instruction |= inst.operands[1].reg << 16;
9185 inst.instruction |= inst.operands[2].reg;
9186 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9187
682b27ad
PB
9188 /* rdhi and rdlo must be different. */
9189 if (inst.operands[0].reg == inst.operands[1].reg)
9190 as_tsktsk (_("rdhi and rdlo must be different"));
9191
9192 /* rdhi, rdlo and rm must all be different before armv6. */
9193 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9194 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9195 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9196 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9197}
b99bd4ef 9198
c19d1205
ZW
9199static void
9200do_nop (void)
9201{
e7495e45
NS
9202 if (inst.operands[0].present
9203 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9204 {
9205 /* Architectural NOP hints are CPSR sets with no bits selected. */
9206 inst.instruction &= 0xf0000000;
e7495e45
NS
9207 inst.instruction |= 0x0320f000;
9208 if (inst.operands[0].present)
9209 inst.instruction |= inst.operands[0].imm;
c19d1205 9210 }
b99bd4ef
NC
9211}
9212
c19d1205
ZW
9213/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9214 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9215 Condition defaults to COND_ALWAYS.
9216 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9217
9218static void
c19d1205 9219do_pkhbt (void)
b99bd4ef 9220{
c19d1205
ZW
9221 inst.instruction |= inst.operands[0].reg << 12;
9222 inst.instruction |= inst.operands[1].reg << 16;
9223 inst.instruction |= inst.operands[2].reg;
9224 if (inst.operands[3].present)
9225 encode_arm_shift (3);
9226}
b99bd4ef 9227
c19d1205 9228/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9229
c19d1205
ZW
9230static void
9231do_pkhtb (void)
9232{
9233 if (!inst.operands[3].present)
b99bd4ef 9234 {
c19d1205
ZW
9235 /* If the shift specifier is omitted, turn the instruction
9236 into pkhbt rd, rm, rn. */
9237 inst.instruction &= 0xfff00010;
9238 inst.instruction |= inst.operands[0].reg << 12;
9239 inst.instruction |= inst.operands[1].reg;
9240 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9241 }
9242 else
9243 {
c19d1205
ZW
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[1].reg << 16;
9246 inst.instruction |= inst.operands[2].reg;
9247 encode_arm_shift (3);
b99bd4ef
NC
9248 }
9249}
9250
c19d1205 9251/* ARMv5TE: Preload-Cache
60e5ef9f 9252 MP Extensions: Preload for write
c19d1205 9253
60e5ef9f 9254 PLD(W) <addr_mode>
c19d1205
ZW
9255
9256 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9257
9258static void
c19d1205 9259do_pld (void)
b99bd4ef 9260{
c19d1205
ZW
9261 constraint (!inst.operands[0].isreg,
9262 _("'[' expected after PLD mnemonic"));
9263 constraint (inst.operands[0].postind,
9264 _("post-indexed expression used in preload instruction"));
9265 constraint (inst.operands[0].writeback,
9266 _("writeback used in preload instruction"));
9267 constraint (!inst.operands[0].preind,
9268 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9269 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9270}
b99bd4ef 9271
62b3e311
PB
9272/* ARMv7: PLI <addr_mode> */
9273static void
9274do_pli (void)
9275{
9276 constraint (!inst.operands[0].isreg,
9277 _("'[' expected after PLI mnemonic"));
9278 constraint (inst.operands[0].postind,
9279 _("post-indexed expression used in preload instruction"));
9280 constraint (inst.operands[0].writeback,
9281 _("writeback used in preload instruction"));
9282 constraint (!inst.operands[0].preind,
9283 _("unindexed addressing used in preload instruction"));
9284 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9285 inst.instruction &= ~PRE_INDEX;
9286}
9287
c19d1205
ZW
9288static void
9289do_push_pop (void)
9290{
5e0d7f77
MP
9291 constraint (inst.operands[0].writeback,
9292 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9293 inst.operands[1] = inst.operands[0];
9294 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9295 inst.operands[0].isreg = 1;
9296 inst.operands[0].writeback = 1;
9297 inst.operands[0].reg = REG_SP;
6530b175 9298 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9299}
b99bd4ef 9300
c19d1205
ZW
9301/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9302 word at the specified address and the following word
9303 respectively.
9304 Unconditionally executed.
9305 Error if Rn is R15. */
b99bd4ef 9306
c19d1205
ZW
9307static void
9308do_rfe (void)
9309{
9310 inst.instruction |= inst.operands[0].reg << 16;
9311 if (inst.operands[0].writeback)
9312 inst.instruction |= WRITE_BACK;
9313}
b99bd4ef 9314
c19d1205 9315/* ARM V6 ssat (argument parse). */
b99bd4ef 9316
c19d1205
ZW
9317static void
9318do_ssat (void)
9319{
9320 inst.instruction |= inst.operands[0].reg << 12;
9321 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9322 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9323
c19d1205
ZW
9324 if (inst.operands[3].present)
9325 encode_arm_shift (3);
b99bd4ef
NC
9326}
9327
c19d1205 9328/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9329
9330static void
c19d1205 9331do_usat (void)
b99bd4ef 9332{
c19d1205
ZW
9333 inst.instruction |= inst.operands[0].reg << 12;
9334 inst.instruction |= inst.operands[1].imm << 16;
9335 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9336
c19d1205
ZW
9337 if (inst.operands[3].present)
9338 encode_arm_shift (3);
b99bd4ef
NC
9339}
9340
c19d1205 9341/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9342
9343static void
c19d1205 9344do_ssat16 (void)
09d92015 9345{
c19d1205
ZW
9346 inst.instruction |= inst.operands[0].reg << 12;
9347 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9348 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9349}
9350
c19d1205
ZW
9351static void
9352do_usat16 (void)
a737bd4d 9353{
c19d1205
ZW
9354 inst.instruction |= inst.operands[0].reg << 12;
9355 inst.instruction |= inst.operands[1].imm << 16;
9356 inst.instruction |= inst.operands[2].reg;
9357}
a737bd4d 9358
c19d1205
ZW
9359/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9360 preserving the other bits.
a737bd4d 9361
c19d1205
ZW
9362 setend <endian_specifier>, where <endian_specifier> is either
9363 BE or LE. */
a737bd4d 9364
c19d1205
ZW
9365static void
9366do_setend (void)
9367{
12e37cbc
MGD
9368 if (warn_on_deprecated
9369 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9370 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9371
c19d1205
ZW
9372 if (inst.operands[0].imm)
9373 inst.instruction |= 0x200;
a737bd4d
NC
9374}
9375
9376static void
c19d1205 9377do_shift (void)
a737bd4d 9378{
c19d1205
ZW
9379 unsigned int Rm = (inst.operands[1].present
9380 ? inst.operands[1].reg
9381 : inst.operands[0].reg);
a737bd4d 9382
c19d1205
ZW
9383 inst.instruction |= inst.operands[0].reg << 12;
9384 inst.instruction |= Rm;
9385 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9386 {
c19d1205
ZW
9387 inst.instruction |= inst.operands[2].reg << 8;
9388 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9389 /* PR 12854: Error on extraneous shifts. */
9390 constraint (inst.operands[2].shifted,
9391 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9392 }
9393 else
c19d1205 9394 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9395}
9396
09d92015 9397static void
3eb17e6b 9398do_smc (void)
09d92015 9399{
3eb17e6b 9400 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9401 inst.reloc.pc_rel = 0;
09d92015
MM
9402}
9403
90ec0d68
MGD
9404static void
9405do_hvc (void)
9406{
9407 inst.reloc.type = BFD_RELOC_ARM_HVC;
9408 inst.reloc.pc_rel = 0;
9409}
9410
09d92015 9411static void
c19d1205 9412do_swi (void)
09d92015 9413{
c19d1205
ZW
9414 inst.reloc.type = BFD_RELOC_ARM_SWI;
9415 inst.reloc.pc_rel = 0;
09d92015
MM
9416}
9417
ddfded2f
MW
9418static void
9419do_setpan (void)
9420{
9421 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9422 _("selected processor does not support SETPAN instruction"));
9423
9424 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9425}
9426
9427static void
9428do_t_setpan (void)
9429{
9430 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9431 _("selected processor does not support SETPAN instruction"));
9432
9433 inst.instruction |= (inst.operands[0].imm << 3);
9434}
9435
c19d1205
ZW
9436/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9437 SMLAxy{cond} Rd,Rm,Rs,Rn
9438 SMLAWy{cond} Rd,Rm,Rs,Rn
9439 Error if any register is R15. */
e16bb312 9440
c19d1205
ZW
9441static void
9442do_smla (void)
e16bb312 9443{
c19d1205
ZW
9444 inst.instruction |= inst.operands[0].reg << 16;
9445 inst.instruction |= inst.operands[1].reg;
9446 inst.instruction |= inst.operands[2].reg << 8;
9447 inst.instruction |= inst.operands[3].reg << 12;
9448}
a737bd4d 9449
c19d1205
ZW
9450/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9451 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9452 Error if any register is R15.
9453 Warning if Rdlo == Rdhi. */
a737bd4d 9454
c19d1205
ZW
9455static void
9456do_smlal (void)
9457{
9458 inst.instruction |= inst.operands[0].reg << 12;
9459 inst.instruction |= inst.operands[1].reg << 16;
9460 inst.instruction |= inst.operands[2].reg;
9461 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9462
c19d1205
ZW
9463 if (inst.operands[0].reg == inst.operands[1].reg)
9464 as_tsktsk (_("rdhi and rdlo must be different"));
9465}
a737bd4d 9466
c19d1205
ZW
9467/* ARM V5E (El Segundo) signed-multiply (argument parse)
9468 SMULxy{cond} Rd,Rm,Rs
9469 Error if any register is R15. */
a737bd4d 9470
c19d1205
ZW
9471static void
9472do_smul (void)
9473{
9474 inst.instruction |= inst.operands[0].reg << 16;
9475 inst.instruction |= inst.operands[1].reg;
9476 inst.instruction |= inst.operands[2].reg << 8;
9477}
a737bd4d 9478
b6702015
PB
9479/* ARM V6 srs (argument parse). The variable fields in the encoding are
9480 the same for both ARM and Thumb-2. */
a737bd4d 9481
c19d1205
ZW
9482static void
9483do_srs (void)
9484{
b6702015
PB
9485 int reg;
9486
9487 if (inst.operands[0].present)
9488 {
9489 reg = inst.operands[0].reg;
fdfde340 9490 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9491 }
9492 else
fdfde340 9493 reg = REG_SP;
b6702015
PB
9494
9495 inst.instruction |= reg << 16;
9496 inst.instruction |= inst.operands[1].imm;
9497 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9498 inst.instruction |= WRITE_BACK;
9499}
a737bd4d 9500
c19d1205 9501/* ARM V6 strex (argument parse). */
a737bd4d 9502
c19d1205
ZW
9503static void
9504do_strex (void)
9505{
9506 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9507 || inst.operands[2].postind || inst.operands[2].writeback
9508 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9509 || inst.operands[2].negative
9510 /* See comment in do_ldrex(). */
9511 || (inst.operands[2].reg == REG_PC),
9512 BAD_ADDR_MODE);
a737bd4d 9513
c19d1205
ZW
9514 constraint (inst.operands[0].reg == inst.operands[1].reg
9515 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9516
c19d1205
ZW
9517 constraint (inst.reloc.exp.X_op != O_constant
9518 || inst.reloc.exp.X_add_number != 0,
9519 _("offset must be zero in ARM encoding"));
a737bd4d 9520
c19d1205
ZW
9521 inst.instruction |= inst.operands[0].reg << 12;
9522 inst.instruction |= inst.operands[1].reg;
9523 inst.instruction |= inst.operands[2].reg << 16;
9524 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9525}
9526
877807f8
NC
9527static void
9528do_t_strexbh (void)
9529{
9530 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9531 || inst.operands[2].postind || inst.operands[2].writeback
9532 || inst.operands[2].immisreg || inst.operands[2].shifted
9533 || inst.operands[2].negative,
9534 BAD_ADDR_MODE);
9535
9536 constraint (inst.operands[0].reg == inst.operands[1].reg
9537 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9538
9539 do_rm_rd_rn ();
9540}
9541
e16bb312 9542static void
c19d1205 9543do_strexd (void)
e16bb312 9544{
c19d1205
ZW
9545 constraint (inst.operands[1].reg % 2 != 0,
9546 _("even register required"));
9547 constraint (inst.operands[2].present
9548 && inst.operands[2].reg != inst.operands[1].reg + 1,
9549 _("can only store two consecutive registers"));
9550 /* If op 2 were present and equal to PC, this function wouldn't
9551 have been called in the first place. */
9552 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9553
c19d1205
ZW
9554 constraint (inst.operands[0].reg == inst.operands[1].reg
9555 || inst.operands[0].reg == inst.operands[1].reg + 1
9556 || inst.operands[0].reg == inst.operands[3].reg,
9557 BAD_OVERLAP);
e16bb312 9558
c19d1205
ZW
9559 inst.instruction |= inst.operands[0].reg << 12;
9560 inst.instruction |= inst.operands[1].reg;
9561 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9562}
9563
9eb6c0f1
MGD
9564/* ARM V8 STRL. */
9565static void
4b8c8c02 9566do_stlex (void)
9eb6c0f1
MGD
9567{
9568 constraint (inst.operands[0].reg == inst.operands[1].reg
9569 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9570
9571 do_rd_rm_rn ();
9572}
9573
9574static void
4b8c8c02 9575do_t_stlex (void)
9eb6c0f1
MGD
9576{
9577 constraint (inst.operands[0].reg == inst.operands[1].reg
9578 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9579
9580 do_rm_rd_rn ();
9581}
9582
c19d1205
ZW
9583/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9584 extends it to 32-bits, and adds the result to a value in another
9585 register. You can specify a rotation by 0, 8, 16, or 24 bits
9586 before extracting the 16-bit value.
9587 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9588 Condition defaults to COND_ALWAYS.
9589 Error if any register uses R15. */
9590
e16bb312 9591static void
c19d1205 9592do_sxtah (void)
e16bb312 9593{
c19d1205
ZW
9594 inst.instruction |= inst.operands[0].reg << 12;
9595 inst.instruction |= inst.operands[1].reg << 16;
9596 inst.instruction |= inst.operands[2].reg;
9597 inst.instruction |= inst.operands[3].imm << 10;
9598}
e16bb312 9599
c19d1205 9600/* ARM V6 SXTH.
e16bb312 9601
c19d1205
ZW
9602 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9603 Condition defaults to COND_ALWAYS.
9604 Error if any register uses R15. */
e16bb312
NC
9605
9606static void
c19d1205 9607do_sxth (void)
e16bb312 9608{
c19d1205
ZW
9609 inst.instruction |= inst.operands[0].reg << 12;
9610 inst.instruction |= inst.operands[1].reg;
9611 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9612}
c19d1205
ZW
9613\f
9614/* VFP instructions. In a logical order: SP variant first, monad
9615 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9616
9617static void
c19d1205 9618do_vfp_sp_monadic (void)
e16bb312 9619{
5287ad62
JB
9620 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9621 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9622}
9623
9624static void
c19d1205 9625do_vfp_sp_dyadic (void)
e16bb312 9626{
5287ad62
JB
9627 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9628 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9629 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9630}
9631
9632static void
c19d1205 9633do_vfp_sp_compare_z (void)
e16bb312 9634{
5287ad62 9635 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9636}
9637
9638static void
c19d1205 9639do_vfp_dp_sp_cvt (void)
e16bb312 9640{
5287ad62
JB
9641 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9642 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9643}
9644
9645static void
c19d1205 9646do_vfp_sp_dp_cvt (void)
e16bb312 9647{
5287ad62
JB
9648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9649 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9650}
9651
9652static void
c19d1205 9653do_vfp_reg_from_sp (void)
e16bb312 9654{
c19d1205 9655 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9656 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9657}
9658
9659static void
c19d1205 9660do_vfp_reg2_from_sp2 (void)
e16bb312 9661{
c19d1205
ZW
9662 constraint (inst.operands[2].imm != 2,
9663 _("only two consecutive VFP SP registers allowed here"));
9664 inst.instruction |= inst.operands[0].reg << 12;
9665 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9666 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9667}
9668
9669static void
c19d1205 9670do_vfp_sp_from_reg (void)
e16bb312 9671{
5287ad62 9672 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9673 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9674}
9675
9676static void
c19d1205 9677do_vfp_sp2_from_reg2 (void)
e16bb312 9678{
c19d1205
ZW
9679 constraint (inst.operands[0].imm != 2,
9680 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9681 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9682 inst.instruction |= inst.operands[1].reg << 12;
9683 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9684}
9685
9686static void
c19d1205 9687do_vfp_sp_ldst (void)
e16bb312 9688{
5287ad62 9689 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9690 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9691}
9692
9693static void
c19d1205 9694do_vfp_dp_ldst (void)
e16bb312 9695{
5287ad62 9696 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9697 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9698}
9699
c19d1205 9700
e16bb312 9701static void
c19d1205 9702vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9703{
c19d1205
ZW
9704 if (inst.operands[0].writeback)
9705 inst.instruction |= WRITE_BACK;
9706 else
9707 constraint (ldstm_type != VFP_LDSTMIA,
9708 _("this addressing mode requires base-register writeback"));
9709 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9710 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9711 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9712}
9713
9714static void
c19d1205 9715vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9716{
c19d1205 9717 int count;
e16bb312 9718
c19d1205
ZW
9719 if (inst.operands[0].writeback)
9720 inst.instruction |= WRITE_BACK;
9721 else
9722 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9723 _("this addressing mode requires base-register writeback"));
e16bb312 9724
c19d1205 9725 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9726 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9727
c19d1205
ZW
9728 count = inst.operands[1].imm << 1;
9729 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9730 count += 1;
e16bb312 9731
c19d1205 9732 inst.instruction |= count;
e16bb312
NC
9733}
9734
9735static void
c19d1205 9736do_vfp_sp_ldstmia (void)
e16bb312 9737{
c19d1205 9738 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9739}
9740
9741static void
c19d1205 9742do_vfp_sp_ldstmdb (void)
e16bb312 9743{
c19d1205 9744 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9745}
9746
9747static void
c19d1205 9748do_vfp_dp_ldstmia (void)
e16bb312 9749{
c19d1205 9750 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9751}
9752
9753static void
c19d1205 9754do_vfp_dp_ldstmdb (void)
e16bb312 9755{
c19d1205 9756 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9757}
9758
9759static void
c19d1205 9760do_vfp_xp_ldstmia (void)
e16bb312 9761{
c19d1205
ZW
9762 vfp_dp_ldstm (VFP_LDSTMIAX);
9763}
e16bb312 9764
c19d1205
ZW
9765static void
9766do_vfp_xp_ldstmdb (void)
9767{
9768 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9769}
5287ad62
JB
9770
9771static void
9772do_vfp_dp_rd_rm (void)
9773{
9774 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9775 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9776}
9777
9778static void
9779do_vfp_dp_rn_rd (void)
9780{
9781 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9782 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9783}
9784
9785static void
9786do_vfp_dp_rd_rn (void)
9787{
9788 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9789 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9790}
9791
9792static void
9793do_vfp_dp_rd_rn_rm (void)
9794{
9795 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9796 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9797 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9798}
9799
9800static void
9801do_vfp_dp_rd (void)
9802{
9803 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9804}
9805
9806static void
9807do_vfp_dp_rm_rd_rn (void)
9808{
9809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9810 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9811 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9812}
9813
9814/* VFPv3 instructions. */
9815static void
9816do_vfp_sp_const (void)
9817{
9818 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9819 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9820 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9821}
9822
9823static void
9824do_vfp_dp_const (void)
9825{
9826 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9827 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9828 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9829}
9830
9831static void
9832vfp_conv (int srcsize)
9833{
5f1af56b
MGD
9834 int immbits = srcsize - inst.operands[1].imm;
9835
fa94de6b
RM
9836 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9837 {
5f1af56b 9838 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9839 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9840 inst.error = _("immediate value out of range, expected range [0, 16]");
9841 return;
9842 }
fa94de6b 9843 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9844 {
9845 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9846 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9847 inst.error = _("immediate value out of range, expected range [1, 32]");
9848 return;
9849 }
9850
5287ad62
JB
9851 inst.instruction |= (immbits & 1) << 5;
9852 inst.instruction |= (immbits >> 1);
9853}
9854
9855static void
9856do_vfp_sp_conv_16 (void)
9857{
9858 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9859 vfp_conv (16);
9860}
9861
9862static void
9863do_vfp_dp_conv_16 (void)
9864{
9865 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9866 vfp_conv (16);
9867}
9868
9869static void
9870do_vfp_sp_conv_32 (void)
9871{
9872 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9873 vfp_conv (32);
9874}
9875
9876static void
9877do_vfp_dp_conv_32 (void)
9878{
9879 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9880 vfp_conv (32);
9881}
c19d1205
ZW
9882\f
9883/* FPA instructions. Also in a logical order. */
e16bb312 9884
c19d1205
ZW
9885static void
9886do_fpa_cmp (void)
9887{
9888 inst.instruction |= inst.operands[0].reg << 16;
9889 inst.instruction |= inst.operands[1].reg;
9890}
b99bd4ef
NC
9891
9892static void
c19d1205 9893do_fpa_ldmstm (void)
b99bd4ef 9894{
c19d1205
ZW
9895 inst.instruction |= inst.operands[0].reg << 12;
9896 switch (inst.operands[1].imm)
9897 {
9898 case 1: inst.instruction |= CP_T_X; break;
9899 case 2: inst.instruction |= CP_T_Y; break;
9900 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9901 case 4: break;
9902 default: abort ();
9903 }
b99bd4ef 9904
c19d1205
ZW
9905 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9906 {
9907 /* The instruction specified "ea" or "fd", so we can only accept
9908 [Rn]{!}. The instruction does not really support stacking or
9909 unstacking, so we have to emulate these by setting appropriate
9910 bits and offsets. */
9911 constraint (inst.reloc.exp.X_op != O_constant
9912 || inst.reloc.exp.X_add_number != 0,
9913 _("this instruction does not support indexing"));
b99bd4ef 9914
c19d1205
ZW
9915 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9916 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9917
c19d1205
ZW
9918 if (!(inst.instruction & INDEX_UP))
9919 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9920
c19d1205
ZW
9921 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9922 {
9923 inst.operands[2].preind = 0;
9924 inst.operands[2].postind = 1;
9925 }
9926 }
b99bd4ef 9927
c19d1205 9928 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9929}
c19d1205
ZW
9930\f
9931/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9932
c19d1205
ZW
9933static void
9934do_iwmmxt_tandorc (void)
9935{
9936 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9937}
b99bd4ef 9938
c19d1205
ZW
9939static void
9940do_iwmmxt_textrc (void)
9941{
9942 inst.instruction |= inst.operands[0].reg << 12;
9943 inst.instruction |= inst.operands[1].imm;
9944}
b99bd4ef
NC
9945
9946static void
c19d1205 9947do_iwmmxt_textrm (void)
b99bd4ef 9948{
c19d1205
ZW
9949 inst.instruction |= inst.operands[0].reg << 12;
9950 inst.instruction |= inst.operands[1].reg << 16;
9951 inst.instruction |= inst.operands[2].imm;
9952}
b99bd4ef 9953
c19d1205
ZW
9954static void
9955do_iwmmxt_tinsr (void)
9956{
9957 inst.instruction |= inst.operands[0].reg << 16;
9958 inst.instruction |= inst.operands[1].reg << 12;
9959 inst.instruction |= inst.operands[2].imm;
9960}
b99bd4ef 9961
c19d1205
ZW
9962static void
9963do_iwmmxt_tmia (void)
9964{
9965 inst.instruction |= inst.operands[0].reg << 5;
9966 inst.instruction |= inst.operands[1].reg;
9967 inst.instruction |= inst.operands[2].reg << 12;
9968}
b99bd4ef 9969
c19d1205
ZW
9970static void
9971do_iwmmxt_waligni (void)
9972{
9973 inst.instruction |= inst.operands[0].reg << 12;
9974 inst.instruction |= inst.operands[1].reg << 16;
9975 inst.instruction |= inst.operands[2].reg;
9976 inst.instruction |= inst.operands[3].imm << 20;
9977}
b99bd4ef 9978
2d447fca
JM
9979static void
9980do_iwmmxt_wmerge (void)
9981{
9982 inst.instruction |= inst.operands[0].reg << 12;
9983 inst.instruction |= inst.operands[1].reg << 16;
9984 inst.instruction |= inst.operands[2].reg;
9985 inst.instruction |= inst.operands[3].imm << 21;
9986}
9987
c19d1205
ZW
9988static void
9989do_iwmmxt_wmov (void)
9990{
9991 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9992 inst.instruction |= inst.operands[0].reg << 12;
9993 inst.instruction |= inst.operands[1].reg << 16;
9994 inst.instruction |= inst.operands[1].reg;
9995}
b99bd4ef 9996
c19d1205
ZW
9997static void
9998do_iwmmxt_wldstbh (void)
9999{
8f06b2d8 10000 int reloc;
c19d1205 10001 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10002 if (thumb_mode)
10003 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10004 else
10005 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10006 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10007}
10008
c19d1205
ZW
10009static void
10010do_iwmmxt_wldstw (void)
10011{
10012 /* RIWR_RIWC clears .isreg for a control register. */
10013 if (!inst.operands[0].isreg)
10014 {
10015 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10016 inst.instruction |= 0xf0000000;
10017 }
b99bd4ef 10018
c19d1205
ZW
10019 inst.instruction |= inst.operands[0].reg << 12;
10020 encode_arm_cp_address (1, TRUE, TRUE, 0);
10021}
b99bd4ef
NC
10022
10023static void
c19d1205 10024do_iwmmxt_wldstd (void)
b99bd4ef 10025{
c19d1205 10026 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10027 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10028 && inst.operands[1].immisreg)
10029 {
10030 inst.instruction &= ~0x1a000ff;
eff0bc54 10031 inst.instruction |= (0xfU << 28);
2d447fca
JM
10032 if (inst.operands[1].preind)
10033 inst.instruction |= PRE_INDEX;
10034 if (!inst.operands[1].negative)
10035 inst.instruction |= INDEX_UP;
10036 if (inst.operands[1].writeback)
10037 inst.instruction |= WRITE_BACK;
10038 inst.instruction |= inst.operands[1].reg << 16;
10039 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10040 inst.instruction |= inst.operands[1].imm;
10041 }
10042 else
10043 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10044}
b99bd4ef 10045
c19d1205
ZW
10046static void
10047do_iwmmxt_wshufh (void)
10048{
10049 inst.instruction |= inst.operands[0].reg << 12;
10050 inst.instruction |= inst.operands[1].reg << 16;
10051 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10052 inst.instruction |= (inst.operands[2].imm & 0x0f);
10053}
b99bd4ef 10054
c19d1205
ZW
10055static void
10056do_iwmmxt_wzero (void)
10057{
10058 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10059 inst.instruction |= inst.operands[0].reg;
10060 inst.instruction |= inst.operands[0].reg << 12;
10061 inst.instruction |= inst.operands[0].reg << 16;
10062}
2d447fca
JM
10063
10064static void
10065do_iwmmxt_wrwrwr_or_imm5 (void)
10066{
10067 if (inst.operands[2].isreg)
10068 do_rd_rn_rm ();
10069 else {
10070 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10071 _("immediate operand requires iWMMXt2"));
10072 do_rd_rn ();
10073 if (inst.operands[2].imm == 0)
10074 {
10075 switch ((inst.instruction >> 20) & 0xf)
10076 {
10077 case 4:
10078 case 5:
10079 case 6:
5f4273c7 10080 case 7:
2d447fca
JM
10081 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10082 inst.operands[2].imm = 16;
10083 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10084 break;
10085 case 8:
10086 case 9:
10087 case 10:
10088 case 11:
10089 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10090 inst.operands[2].imm = 32;
10091 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10092 break;
10093 case 12:
10094 case 13:
10095 case 14:
10096 case 15:
10097 {
10098 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10099 unsigned long wrn;
10100 wrn = (inst.instruction >> 16) & 0xf;
10101 inst.instruction &= 0xff0fff0f;
10102 inst.instruction |= wrn;
10103 /* Bail out here; the instruction is now assembled. */
10104 return;
10105 }
10106 }
10107 }
10108 /* Map 32 -> 0, etc. */
10109 inst.operands[2].imm &= 0x1f;
eff0bc54 10110 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10111 }
10112}
c19d1205
ZW
10113\f
10114/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10115 operations first, then control, shift, and load/store. */
b99bd4ef 10116
c19d1205 10117/* Insns like "foo X,Y,Z". */
b99bd4ef 10118
c19d1205
ZW
10119static void
10120do_mav_triple (void)
10121{
10122 inst.instruction |= inst.operands[0].reg << 16;
10123 inst.instruction |= inst.operands[1].reg;
10124 inst.instruction |= inst.operands[2].reg << 12;
10125}
b99bd4ef 10126
c19d1205
ZW
10127/* Insns like "foo W,X,Y,Z".
10128 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10129
c19d1205
ZW
10130static void
10131do_mav_quad (void)
10132{
10133 inst.instruction |= inst.operands[0].reg << 5;
10134 inst.instruction |= inst.operands[1].reg << 12;
10135 inst.instruction |= inst.operands[2].reg << 16;
10136 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10137}
10138
c19d1205
ZW
10139/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10140static void
10141do_mav_dspsc (void)
a737bd4d 10142{
c19d1205
ZW
10143 inst.instruction |= inst.operands[1].reg << 12;
10144}
a737bd4d 10145
c19d1205
ZW
10146/* Maverick shift immediate instructions.
10147 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10148 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10149
c19d1205
ZW
10150static void
10151do_mav_shift (void)
10152{
10153 int imm = inst.operands[2].imm;
a737bd4d 10154
c19d1205
ZW
10155 inst.instruction |= inst.operands[0].reg << 12;
10156 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10157
c19d1205
ZW
10158 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10159 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10160 Bit 4 should be 0. */
10161 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10162
c19d1205
ZW
10163 inst.instruction |= imm;
10164}
10165\f
10166/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10167
c19d1205
ZW
10168/* Xscale multiply-accumulate (argument parse)
10169 MIAcc acc0,Rm,Rs
10170 MIAPHcc acc0,Rm,Rs
10171 MIAxycc acc0,Rm,Rs. */
a737bd4d 10172
c19d1205
ZW
10173static void
10174do_xsc_mia (void)
10175{
10176 inst.instruction |= inst.operands[1].reg;
10177 inst.instruction |= inst.operands[2].reg << 12;
10178}
a737bd4d 10179
c19d1205 10180/* Xscale move-accumulator-register (argument parse)
a737bd4d 10181
c19d1205 10182 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10183
c19d1205
ZW
10184static void
10185do_xsc_mar (void)
10186{
10187 inst.instruction |= inst.operands[1].reg << 12;
10188 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10189}
10190
c19d1205 10191/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10192
c19d1205 10193 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10194
10195static void
c19d1205 10196do_xsc_mra (void)
b99bd4ef 10197{
c19d1205
ZW
10198 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10199 inst.instruction |= inst.operands[0].reg << 12;
10200 inst.instruction |= inst.operands[1].reg << 16;
10201}
10202\f
10203/* Encoding functions relevant only to Thumb. */
b99bd4ef 10204
c19d1205
ZW
10205/* inst.operands[i] is a shifted-register operand; encode
10206 it into inst.instruction in the format used by Thumb32. */
10207
10208static void
10209encode_thumb32_shifted_operand (int i)
10210{
10211 unsigned int value = inst.reloc.exp.X_add_number;
10212 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10213
9c3c69f2
PB
10214 constraint (inst.operands[i].immisreg,
10215 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10216 inst.instruction |= inst.operands[i].reg;
10217 if (shift == SHIFT_RRX)
10218 inst.instruction |= SHIFT_ROR << 4;
10219 else
b99bd4ef 10220 {
c19d1205
ZW
10221 constraint (inst.reloc.exp.X_op != O_constant,
10222 _("expression too complex"));
10223
10224 constraint (value > 32
10225 || (value == 32 && (shift == SHIFT_LSL
10226 || shift == SHIFT_ROR)),
10227 _("shift expression is too large"));
10228
10229 if (value == 0)
10230 shift = SHIFT_LSL;
10231 else if (value == 32)
10232 value = 0;
10233
10234 inst.instruction |= shift << 4;
10235 inst.instruction |= (value & 0x1c) << 10;
10236 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10237 }
c19d1205 10238}
b99bd4ef 10239
b99bd4ef 10240
c19d1205
ZW
10241/* inst.operands[i] was set up by parse_address. Encode it into a
10242 Thumb32 format load or store instruction. Reject forms that cannot
10243 be used with such instructions. If is_t is true, reject forms that
10244 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10245 that cannot be used with a D instruction. If it is a store insn,
10246 reject PC in Rn. */
b99bd4ef 10247
c19d1205
ZW
10248static void
10249encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10250{
5be8be5d 10251 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10252
10253 constraint (!inst.operands[i].isreg,
53365c0d 10254 _("Instruction does not support =N addresses"));
b99bd4ef 10255
c19d1205
ZW
10256 inst.instruction |= inst.operands[i].reg << 16;
10257 if (inst.operands[i].immisreg)
b99bd4ef 10258 {
5be8be5d 10259 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10260 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10261 constraint (inst.operands[i].negative,
10262 _("Thumb does not support negative register indexing"));
10263 constraint (inst.operands[i].postind,
10264 _("Thumb does not support register post-indexing"));
10265 constraint (inst.operands[i].writeback,
10266 _("Thumb does not support register indexing with writeback"));
10267 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10268 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10269
f40d1643 10270 inst.instruction |= inst.operands[i].imm;
c19d1205 10271 if (inst.operands[i].shifted)
b99bd4ef 10272 {
c19d1205
ZW
10273 constraint (inst.reloc.exp.X_op != O_constant,
10274 _("expression too complex"));
9c3c69f2
PB
10275 constraint (inst.reloc.exp.X_add_number < 0
10276 || inst.reloc.exp.X_add_number > 3,
c19d1205 10277 _("shift out of range"));
9c3c69f2 10278 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10279 }
10280 inst.reloc.type = BFD_RELOC_UNUSED;
10281 }
10282 else if (inst.operands[i].preind)
10283 {
5be8be5d 10284 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10285 constraint (is_t && inst.operands[i].writeback,
c19d1205 10286 _("cannot use writeback with this instruction"));
4755303e
WN
10287 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10288 BAD_PC_ADDRESSING);
c19d1205
ZW
10289
10290 if (is_d)
10291 {
10292 inst.instruction |= 0x01000000;
10293 if (inst.operands[i].writeback)
10294 inst.instruction |= 0x00200000;
b99bd4ef 10295 }
c19d1205 10296 else
b99bd4ef 10297 {
c19d1205
ZW
10298 inst.instruction |= 0x00000c00;
10299 if (inst.operands[i].writeback)
10300 inst.instruction |= 0x00000100;
b99bd4ef 10301 }
c19d1205 10302 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10303 }
c19d1205 10304 else if (inst.operands[i].postind)
b99bd4ef 10305 {
9c2799c2 10306 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10307 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10308 constraint (is_t, _("cannot use post-indexing with this instruction"));
10309
10310 if (is_d)
10311 inst.instruction |= 0x00200000;
10312 else
10313 inst.instruction |= 0x00000900;
10314 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10315 }
10316 else /* unindexed - only for coprocessor */
10317 inst.error = _("instruction does not accept unindexed addressing");
10318}
10319
10320/* Table of Thumb instructions which exist in both 16- and 32-bit
10321 encodings (the latter only in post-V6T2 cores). The index is the
10322 value used in the insns table below. When there is more than one
10323 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10324 holds variant (1).
10325 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10326#define T16_32_TAB \
21d799b5
NC
10327 X(_adc, 4140, eb400000), \
10328 X(_adcs, 4140, eb500000), \
10329 X(_add, 1c00, eb000000), \
10330 X(_adds, 1c00, eb100000), \
10331 X(_addi, 0000, f1000000), \
10332 X(_addis, 0000, f1100000), \
10333 X(_add_pc,000f, f20f0000), \
10334 X(_add_sp,000d, f10d0000), \
10335 X(_adr, 000f, f20f0000), \
10336 X(_and, 4000, ea000000), \
10337 X(_ands, 4000, ea100000), \
10338 X(_asr, 1000, fa40f000), \
10339 X(_asrs, 1000, fa50f000), \
10340 X(_b, e000, f000b000), \
10341 X(_bcond, d000, f0008000), \
10342 X(_bic, 4380, ea200000), \
10343 X(_bics, 4380, ea300000), \
10344 X(_cmn, 42c0, eb100f00), \
10345 X(_cmp, 2800, ebb00f00), \
10346 X(_cpsie, b660, f3af8400), \
10347 X(_cpsid, b670, f3af8600), \
10348 X(_cpy, 4600, ea4f0000), \
10349 X(_dec_sp,80dd, f1ad0d00), \
10350 X(_eor, 4040, ea800000), \
10351 X(_eors, 4040, ea900000), \
10352 X(_inc_sp,00dd, f10d0d00), \
10353 X(_ldmia, c800, e8900000), \
10354 X(_ldr, 6800, f8500000), \
10355 X(_ldrb, 7800, f8100000), \
10356 X(_ldrh, 8800, f8300000), \
10357 X(_ldrsb, 5600, f9100000), \
10358 X(_ldrsh, 5e00, f9300000), \
10359 X(_ldr_pc,4800, f85f0000), \
10360 X(_ldr_pc2,4800, f85f0000), \
10361 X(_ldr_sp,9800, f85d0000), \
10362 X(_lsl, 0000, fa00f000), \
10363 X(_lsls, 0000, fa10f000), \
10364 X(_lsr, 0800, fa20f000), \
10365 X(_lsrs, 0800, fa30f000), \
10366 X(_mov, 2000, ea4f0000), \
10367 X(_movs, 2000, ea5f0000), \
10368 X(_mul, 4340, fb00f000), \
10369 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10370 X(_mvn, 43c0, ea6f0000), \
10371 X(_mvns, 43c0, ea7f0000), \
10372 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10373 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10374 X(_orr, 4300, ea400000), \
10375 X(_orrs, 4300, ea500000), \
10376 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10377 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10378 X(_rev, ba00, fa90f080), \
10379 X(_rev16, ba40, fa90f090), \
10380 X(_revsh, bac0, fa90f0b0), \
10381 X(_ror, 41c0, fa60f000), \
10382 X(_rors, 41c0, fa70f000), \
10383 X(_sbc, 4180, eb600000), \
10384 X(_sbcs, 4180, eb700000), \
10385 X(_stmia, c000, e8800000), \
10386 X(_str, 6000, f8400000), \
10387 X(_strb, 7000, f8000000), \
10388 X(_strh, 8000, f8200000), \
10389 X(_str_sp,9000, f84d0000), \
10390 X(_sub, 1e00, eba00000), \
10391 X(_subs, 1e00, ebb00000), \
10392 X(_subi, 8000, f1a00000), \
10393 X(_subis, 8000, f1b00000), \
10394 X(_sxtb, b240, fa4ff080), \
10395 X(_sxth, b200, fa0ff080), \
10396 X(_tst, 4200, ea100f00), \
10397 X(_uxtb, b2c0, fa5ff080), \
10398 X(_uxth, b280, fa1ff080), \
10399 X(_nop, bf00, f3af8000), \
10400 X(_yield, bf10, f3af8001), \
10401 X(_wfe, bf20, f3af8002), \
10402 X(_wfi, bf30, f3af8003), \
53c4b28b 10403 X(_sev, bf40, f3af8004), \
74db7efb
NC
10404 X(_sevl, bf50, f3af8005), \
10405 X(_udf, de00, f7f0a000)
c19d1205
ZW
10406
10407/* To catch errors in encoding functions, the codes are all offset by
10408 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10409 as 16-bit instructions. */
21d799b5 10410#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10411enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10412#undef X
10413
10414#define X(a,b,c) 0x##b
10415static const unsigned short thumb_op16[] = { T16_32_TAB };
10416#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10417#undef X
10418
10419#define X(a,b,c) 0x##c
10420static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10421#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10422#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10423#undef X
10424#undef T16_32_TAB
10425
10426/* Thumb instruction encoders, in alphabetical order. */
10427
92e90b6e 10428/* ADDW or SUBW. */
c921be7d 10429
92e90b6e
PB
10430static void
10431do_t_add_sub_w (void)
10432{
10433 int Rd, Rn;
10434
10435 Rd = inst.operands[0].reg;
10436 Rn = inst.operands[1].reg;
10437
539d4391
NC
10438 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10439 is the SP-{plus,minus}-immediate form of the instruction. */
10440 if (Rn == REG_SP)
10441 constraint (Rd == REG_PC, BAD_PC);
10442 else
10443 reject_bad_reg (Rd);
fdfde340 10444
92e90b6e
PB
10445 inst.instruction |= (Rn << 16) | (Rd << 8);
10446 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10447}
10448
c19d1205
ZW
10449/* Parse an add or subtract instruction. We get here with inst.instruction
10450 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10451
10452static void
10453do_t_add_sub (void)
10454{
10455 int Rd, Rs, Rn;
10456
10457 Rd = inst.operands[0].reg;
10458 Rs = (inst.operands[1].present
10459 ? inst.operands[1].reg /* Rd, Rs, foo */
10460 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10461
e07e6e58
NC
10462 if (Rd == REG_PC)
10463 set_it_insn_type_last ();
10464
c19d1205
ZW
10465 if (unified_syntax)
10466 {
0110f2b8
PB
10467 bfd_boolean flags;
10468 bfd_boolean narrow;
10469 int opcode;
10470
10471 flags = (inst.instruction == T_MNEM_adds
10472 || inst.instruction == T_MNEM_subs);
10473 if (flags)
e07e6e58 10474 narrow = !in_it_block ();
0110f2b8 10475 else
e07e6e58 10476 narrow = in_it_block ();
c19d1205 10477 if (!inst.operands[2].isreg)
b99bd4ef 10478 {
16805f35
PB
10479 int add;
10480
fdfde340
JM
10481 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10482
16805f35
PB
10483 add = (inst.instruction == T_MNEM_add
10484 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10485 opcode = 0;
10486 if (inst.size_req != 4)
10487 {
0110f2b8 10488 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10489 appropriate. */
0110f2b8
PB
10490 if (Rd == REG_SP && Rs == REG_SP && !flags)
10491 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10492 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10493 opcode = T_MNEM_add_sp;
10494 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10495 opcode = T_MNEM_add_pc;
10496 else if (Rd <= 7 && Rs <= 7 && narrow)
10497 {
10498 if (flags)
10499 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10500 else
10501 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10502 }
10503 if (opcode)
10504 {
10505 inst.instruction = THUMB_OP16(opcode);
10506 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10507 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10508 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10509 {
10510 if (inst.size_req == 2)
10511 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10512 else
10513 inst.relax = opcode;
10514 }
0110f2b8
PB
10515 }
10516 else
10517 constraint (inst.size_req == 2, BAD_HIREG);
10518 }
10519 if (inst.size_req == 4
10520 || (inst.size_req != 2 && !opcode))
10521 {
a9f02af8
MG
10522 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10523 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10524 THUMB1_RELOC_ONLY);
efd81785
PB
10525 if (Rd == REG_PC)
10526 {
fdfde340 10527 constraint (add, BAD_PC);
efd81785
PB
10528 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10529 _("only SUBS PC, LR, #const allowed"));
10530 constraint (inst.reloc.exp.X_op != O_constant,
10531 _("expression too complex"));
10532 constraint (inst.reloc.exp.X_add_number < 0
10533 || inst.reloc.exp.X_add_number > 0xff,
10534 _("immediate value out of range"));
10535 inst.instruction = T2_SUBS_PC_LR
10536 | inst.reloc.exp.X_add_number;
10537 inst.reloc.type = BFD_RELOC_UNUSED;
10538 return;
10539 }
10540 else if (Rs == REG_PC)
16805f35
PB
10541 {
10542 /* Always use addw/subw. */
10543 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10544 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10545 }
10546 else
10547 {
10548 inst.instruction = THUMB_OP32 (inst.instruction);
10549 inst.instruction = (inst.instruction & 0xe1ffffff)
10550 | 0x10000000;
10551 if (flags)
10552 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10553 else
10554 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10555 }
dc4503c6
PB
10556 inst.instruction |= Rd << 8;
10557 inst.instruction |= Rs << 16;
0110f2b8 10558 }
b99bd4ef 10559 }
c19d1205
ZW
10560 else
10561 {
5f4cb198
NC
10562 unsigned int value = inst.reloc.exp.X_add_number;
10563 unsigned int shift = inst.operands[2].shift_kind;
10564
c19d1205
ZW
10565 Rn = inst.operands[2].reg;
10566 /* See if we can do this with a 16-bit instruction. */
10567 if (!inst.operands[2].shifted && inst.size_req != 4)
10568 {
e27ec89e
PB
10569 if (Rd > 7 || Rs > 7 || Rn > 7)
10570 narrow = FALSE;
10571
10572 if (narrow)
c19d1205 10573 {
e27ec89e
PB
10574 inst.instruction = ((inst.instruction == T_MNEM_adds
10575 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10576 ? T_OPCODE_ADD_R3
10577 : T_OPCODE_SUB_R3);
10578 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10579 return;
10580 }
b99bd4ef 10581
7e806470 10582 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10583 {
7e806470
PB
10584 /* Thumb-1 cores (except v6-M) require at least one high
10585 register in a narrow non flag setting add. */
10586 if (Rd > 7 || Rn > 7
10587 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10588 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10589 {
7e806470
PB
10590 if (Rd == Rn)
10591 {
10592 Rn = Rs;
10593 Rs = Rd;
10594 }
c19d1205
ZW
10595 inst.instruction = T_OPCODE_ADD_HI;
10596 inst.instruction |= (Rd & 8) << 4;
10597 inst.instruction |= (Rd & 7);
10598 inst.instruction |= Rn << 3;
10599 return;
10600 }
c19d1205
ZW
10601 }
10602 }
c921be7d 10603
fdfde340
JM
10604 constraint (Rd == REG_PC, BAD_PC);
10605 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10606 constraint (Rs == REG_PC, BAD_PC);
10607 reject_bad_reg (Rn);
10608
c19d1205
ZW
10609 /* If we get here, it can't be done in 16 bits. */
10610 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10611 _("shift must be constant"));
10612 inst.instruction = THUMB_OP32 (inst.instruction);
10613 inst.instruction |= Rd << 8;
10614 inst.instruction |= Rs << 16;
5f4cb198
NC
10615 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10616 _("shift value over 3 not allowed in thumb mode"));
10617 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10618 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10619 encode_thumb32_shifted_operand (2);
10620 }
10621 }
10622 else
10623 {
10624 constraint (inst.instruction == T_MNEM_adds
10625 || inst.instruction == T_MNEM_subs,
10626 BAD_THUMB32);
b99bd4ef 10627
c19d1205 10628 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10629 {
c19d1205
ZW
10630 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10631 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10632 BAD_HIREG);
10633
10634 inst.instruction = (inst.instruction == T_MNEM_add
10635 ? 0x0000 : 0x8000);
10636 inst.instruction |= (Rd << 4) | Rs;
10637 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10638 return;
10639 }
10640
c19d1205
ZW
10641 Rn = inst.operands[2].reg;
10642 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10643
c19d1205
ZW
10644 /* We now have Rd, Rs, and Rn set to registers. */
10645 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10646 {
c19d1205
ZW
10647 /* Can't do this for SUB. */
10648 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10649 inst.instruction = T_OPCODE_ADD_HI;
10650 inst.instruction |= (Rd & 8) << 4;
10651 inst.instruction |= (Rd & 7);
10652 if (Rs == Rd)
10653 inst.instruction |= Rn << 3;
10654 else if (Rn == Rd)
10655 inst.instruction |= Rs << 3;
10656 else
10657 constraint (1, _("dest must overlap one source register"));
10658 }
10659 else
10660 {
10661 inst.instruction = (inst.instruction == T_MNEM_add
10662 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10663 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10664 }
b99bd4ef 10665 }
b99bd4ef
NC
10666}
10667
c19d1205
ZW
10668static void
10669do_t_adr (void)
10670{
fdfde340
JM
10671 unsigned Rd;
10672
10673 Rd = inst.operands[0].reg;
10674 reject_bad_reg (Rd);
10675
10676 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10677 {
10678 /* Defer to section relaxation. */
10679 inst.relax = inst.instruction;
10680 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10681 inst.instruction |= Rd << 4;
0110f2b8
PB
10682 }
10683 else if (unified_syntax && inst.size_req != 2)
e9f89963 10684 {
0110f2b8 10685 /* Generate a 32-bit opcode. */
e9f89963 10686 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10687 inst.instruction |= Rd << 8;
e9f89963
PB
10688 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10689 inst.reloc.pc_rel = 1;
10690 }
10691 else
10692 {
0110f2b8 10693 /* Generate a 16-bit opcode. */
e9f89963
PB
10694 inst.instruction = THUMB_OP16 (inst.instruction);
10695 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10696 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10697 inst.reloc.pc_rel = 1;
b99bd4ef 10698
fdfde340 10699 inst.instruction |= Rd << 4;
e9f89963 10700 }
c19d1205 10701}
b99bd4ef 10702
c19d1205
ZW
10703/* Arithmetic instructions for which there is just one 16-bit
10704 instruction encoding, and it allows only two low registers.
10705 For maximal compatibility with ARM syntax, we allow three register
10706 operands even when Thumb-32 instructions are not available, as long
10707 as the first two are identical. For instance, both "sbc r0,r1" and
10708 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10709static void
c19d1205 10710do_t_arit3 (void)
b99bd4ef 10711{
c19d1205 10712 int Rd, Rs, Rn;
b99bd4ef 10713
c19d1205
ZW
10714 Rd = inst.operands[0].reg;
10715 Rs = (inst.operands[1].present
10716 ? inst.operands[1].reg /* Rd, Rs, foo */
10717 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10718 Rn = inst.operands[2].reg;
b99bd4ef 10719
fdfde340
JM
10720 reject_bad_reg (Rd);
10721 reject_bad_reg (Rs);
10722 if (inst.operands[2].isreg)
10723 reject_bad_reg (Rn);
10724
c19d1205 10725 if (unified_syntax)
b99bd4ef 10726 {
c19d1205
ZW
10727 if (!inst.operands[2].isreg)
10728 {
10729 /* For an immediate, we always generate a 32-bit opcode;
10730 section relaxation will shrink it later if possible. */
10731 inst.instruction = THUMB_OP32 (inst.instruction);
10732 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10733 inst.instruction |= Rd << 8;
10734 inst.instruction |= Rs << 16;
10735 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10736 }
10737 else
10738 {
e27ec89e
PB
10739 bfd_boolean narrow;
10740
c19d1205 10741 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10742 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10743 narrow = !in_it_block ();
e27ec89e 10744 else
e07e6e58 10745 narrow = in_it_block ();
e27ec89e
PB
10746
10747 if (Rd > 7 || Rn > 7 || Rs > 7)
10748 narrow = FALSE;
10749 if (inst.operands[2].shifted)
10750 narrow = FALSE;
10751 if (inst.size_req == 4)
10752 narrow = FALSE;
10753
10754 if (narrow
c19d1205
ZW
10755 && Rd == Rs)
10756 {
10757 inst.instruction = THUMB_OP16 (inst.instruction);
10758 inst.instruction |= Rd;
10759 inst.instruction |= Rn << 3;
10760 return;
10761 }
b99bd4ef 10762
c19d1205
ZW
10763 /* If we get here, it can't be done in 16 bits. */
10764 constraint (inst.operands[2].shifted
10765 && inst.operands[2].immisreg,
10766 _("shift must be constant"));
10767 inst.instruction = THUMB_OP32 (inst.instruction);
10768 inst.instruction |= Rd << 8;
10769 inst.instruction |= Rs << 16;
10770 encode_thumb32_shifted_operand (2);
10771 }
a737bd4d 10772 }
c19d1205 10773 else
b99bd4ef 10774 {
c19d1205
ZW
10775 /* On its face this is a lie - the instruction does set the
10776 flags. However, the only supported mnemonic in this mode
10777 says it doesn't. */
10778 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10779
c19d1205
ZW
10780 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10781 _("unshifted register required"));
10782 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10783 constraint (Rd != Rs,
10784 _("dest and source1 must be the same register"));
a737bd4d 10785
c19d1205
ZW
10786 inst.instruction = THUMB_OP16 (inst.instruction);
10787 inst.instruction |= Rd;
10788 inst.instruction |= Rn << 3;
b99bd4ef 10789 }
a737bd4d 10790}
b99bd4ef 10791
c19d1205
ZW
10792/* Similarly, but for instructions where the arithmetic operation is
10793 commutative, so we can allow either of them to be different from
10794 the destination operand in a 16-bit instruction. For instance, all
10795 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10796 accepted. */
10797static void
10798do_t_arit3c (void)
a737bd4d 10799{
c19d1205 10800 int Rd, Rs, Rn;
b99bd4ef 10801
c19d1205
ZW
10802 Rd = inst.operands[0].reg;
10803 Rs = (inst.operands[1].present
10804 ? inst.operands[1].reg /* Rd, Rs, foo */
10805 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10806 Rn = inst.operands[2].reg;
c921be7d 10807
fdfde340
JM
10808 reject_bad_reg (Rd);
10809 reject_bad_reg (Rs);
10810 if (inst.operands[2].isreg)
10811 reject_bad_reg (Rn);
a737bd4d 10812
c19d1205 10813 if (unified_syntax)
a737bd4d 10814 {
c19d1205 10815 if (!inst.operands[2].isreg)
b99bd4ef 10816 {
c19d1205
ZW
10817 /* For an immediate, we always generate a 32-bit opcode;
10818 section relaxation will shrink it later if possible. */
10819 inst.instruction = THUMB_OP32 (inst.instruction);
10820 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10821 inst.instruction |= Rd << 8;
10822 inst.instruction |= Rs << 16;
10823 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10824 }
c19d1205 10825 else
a737bd4d 10826 {
e27ec89e
PB
10827 bfd_boolean narrow;
10828
c19d1205 10829 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10830 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10831 narrow = !in_it_block ();
e27ec89e 10832 else
e07e6e58 10833 narrow = in_it_block ();
e27ec89e
PB
10834
10835 if (Rd > 7 || Rn > 7 || Rs > 7)
10836 narrow = FALSE;
10837 if (inst.operands[2].shifted)
10838 narrow = FALSE;
10839 if (inst.size_req == 4)
10840 narrow = FALSE;
10841
10842 if (narrow)
a737bd4d 10843 {
c19d1205 10844 if (Rd == Rs)
a737bd4d 10845 {
c19d1205
ZW
10846 inst.instruction = THUMB_OP16 (inst.instruction);
10847 inst.instruction |= Rd;
10848 inst.instruction |= Rn << 3;
10849 return;
a737bd4d 10850 }
c19d1205 10851 if (Rd == Rn)
a737bd4d 10852 {
c19d1205
ZW
10853 inst.instruction = THUMB_OP16 (inst.instruction);
10854 inst.instruction |= Rd;
10855 inst.instruction |= Rs << 3;
10856 return;
a737bd4d
NC
10857 }
10858 }
c19d1205
ZW
10859
10860 /* If we get here, it can't be done in 16 bits. */
10861 constraint (inst.operands[2].shifted
10862 && inst.operands[2].immisreg,
10863 _("shift must be constant"));
10864 inst.instruction = THUMB_OP32 (inst.instruction);
10865 inst.instruction |= Rd << 8;
10866 inst.instruction |= Rs << 16;
10867 encode_thumb32_shifted_operand (2);
a737bd4d 10868 }
b99bd4ef 10869 }
c19d1205
ZW
10870 else
10871 {
10872 /* On its face this is a lie - the instruction does set the
10873 flags. However, the only supported mnemonic in this mode
10874 says it doesn't. */
10875 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10876
c19d1205
ZW
10877 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10878 _("unshifted register required"));
10879 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10880
10881 inst.instruction = THUMB_OP16 (inst.instruction);
10882 inst.instruction |= Rd;
10883
10884 if (Rd == Rs)
10885 inst.instruction |= Rn << 3;
10886 else if (Rd == Rn)
10887 inst.instruction |= Rs << 3;
10888 else
10889 constraint (1, _("dest must overlap one source register"));
10890 }
a737bd4d
NC
10891}
10892
c19d1205
ZW
10893static void
10894do_t_bfc (void)
a737bd4d 10895{
fdfde340 10896 unsigned Rd;
c19d1205
ZW
10897 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10898 constraint (msb > 32, _("bit-field extends past end of register"));
10899 /* The instruction encoding stores the LSB and MSB,
10900 not the LSB and width. */
fdfde340
JM
10901 Rd = inst.operands[0].reg;
10902 reject_bad_reg (Rd);
10903 inst.instruction |= Rd << 8;
c19d1205
ZW
10904 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10905 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10906 inst.instruction |= msb - 1;
b99bd4ef
NC
10907}
10908
c19d1205
ZW
10909static void
10910do_t_bfi (void)
b99bd4ef 10911{
fdfde340 10912 int Rd, Rn;
c19d1205 10913 unsigned int msb;
b99bd4ef 10914
fdfde340
JM
10915 Rd = inst.operands[0].reg;
10916 reject_bad_reg (Rd);
10917
c19d1205
ZW
10918 /* #0 in second position is alternative syntax for bfc, which is
10919 the same instruction but with REG_PC in the Rm field. */
10920 if (!inst.operands[1].isreg)
fdfde340
JM
10921 Rn = REG_PC;
10922 else
10923 {
10924 Rn = inst.operands[1].reg;
10925 reject_bad_reg (Rn);
10926 }
b99bd4ef 10927
c19d1205
ZW
10928 msb = inst.operands[2].imm + inst.operands[3].imm;
10929 constraint (msb > 32, _("bit-field extends past end of register"));
10930 /* The instruction encoding stores the LSB and MSB,
10931 not the LSB and width. */
fdfde340
JM
10932 inst.instruction |= Rd << 8;
10933 inst.instruction |= Rn << 16;
c19d1205
ZW
10934 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10935 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10936 inst.instruction |= msb - 1;
b99bd4ef
NC
10937}
10938
c19d1205
ZW
10939static void
10940do_t_bfx (void)
b99bd4ef 10941{
fdfde340
JM
10942 unsigned Rd, Rn;
10943
10944 Rd = inst.operands[0].reg;
10945 Rn = inst.operands[1].reg;
10946
10947 reject_bad_reg (Rd);
10948 reject_bad_reg (Rn);
10949
c19d1205
ZW
10950 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10951 _("bit-field extends past end of register"));
fdfde340
JM
10952 inst.instruction |= Rd << 8;
10953 inst.instruction |= Rn << 16;
c19d1205
ZW
10954 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10955 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10956 inst.instruction |= inst.operands[3].imm - 1;
10957}
b99bd4ef 10958
c19d1205
ZW
10959/* ARM V5 Thumb BLX (argument parse)
10960 BLX <target_addr> which is BLX(1)
10961 BLX <Rm> which is BLX(2)
10962 Unfortunately, there are two different opcodes for this mnemonic.
10963 So, the insns[].value is not used, and the code here zaps values
10964 into inst.instruction.
b99bd4ef 10965
c19d1205
ZW
10966 ??? How to take advantage of the additional two bits of displacement
10967 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10968
c19d1205
ZW
10969static void
10970do_t_blx (void)
10971{
e07e6e58
NC
10972 set_it_insn_type_last ();
10973
c19d1205 10974 if (inst.operands[0].isreg)
fdfde340
JM
10975 {
10976 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10977 /* We have a register, so this is BLX(2). */
10978 inst.instruction |= inst.operands[0].reg << 3;
10979 }
b99bd4ef
NC
10980 else
10981 {
c19d1205 10982 /* No register. This must be BLX(1). */
2fc8bdac 10983 inst.instruction = 0xf000e800;
0855e32b 10984 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10985 }
10986}
10987
c19d1205
ZW
10988static void
10989do_t_branch (void)
b99bd4ef 10990{
0110f2b8 10991 int opcode;
dfa9f0d5 10992 int cond;
2fe88214 10993 bfd_reloc_code_real_type reloc;
dfa9f0d5 10994
e07e6e58
NC
10995 cond = inst.cond;
10996 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10997
10998 if (in_it_block ())
dfa9f0d5
PB
10999 {
11000 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11001 branches. */
dfa9f0d5 11002 cond = COND_ALWAYS;
dfa9f0d5
PB
11003 }
11004 else
11005 cond = inst.cond;
11006
11007 if (cond != COND_ALWAYS)
0110f2b8
PB
11008 opcode = T_MNEM_bcond;
11009 else
11010 opcode = inst.instruction;
11011
12d6b0b7
RS
11012 if (unified_syntax
11013 && (inst.size_req == 4
10960bfb
PB
11014 || (inst.size_req != 2
11015 && (inst.operands[0].hasreloc
11016 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11017 {
0110f2b8 11018 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11019 if (cond == COND_ALWAYS)
9ae92b05 11020 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11021 else
11022 {
ff8646ee
TP
11023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11024 _("selected architecture does not support "
11025 "wide conditional branch instruction"));
11026
9c2799c2 11027 gas_assert (cond != 0xF);
dfa9f0d5 11028 inst.instruction |= cond << 22;
9ae92b05 11029 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11030 }
11031 }
b99bd4ef
NC
11032 else
11033 {
0110f2b8 11034 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11035 if (cond == COND_ALWAYS)
9ae92b05 11036 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11037 else
b99bd4ef 11038 {
dfa9f0d5 11039 inst.instruction |= cond << 8;
9ae92b05 11040 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11041 }
0110f2b8
PB
11042 /* Allow section relaxation. */
11043 if (unified_syntax && inst.size_req != 2)
11044 inst.relax = opcode;
b99bd4ef 11045 }
9ae92b05 11046 inst.reloc.type = reloc;
c19d1205 11047 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11048}
11049
8884b720 11050/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11051 between the two is the maximum immediate allowed - which is passed in
8884b720 11052 RANGE. */
b99bd4ef 11053static void
8884b720 11054do_t_bkpt_hlt1 (int range)
b99bd4ef 11055{
dfa9f0d5
PB
11056 constraint (inst.cond != COND_ALWAYS,
11057 _("instruction is always unconditional"));
c19d1205 11058 if (inst.operands[0].present)
b99bd4ef 11059 {
8884b720 11060 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11061 _("immediate value out of range"));
11062 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11063 }
8884b720
MGD
11064
11065 set_it_insn_type (NEUTRAL_IT_INSN);
11066}
11067
11068static void
11069do_t_hlt (void)
11070{
11071 do_t_bkpt_hlt1 (63);
11072}
11073
11074static void
11075do_t_bkpt (void)
11076{
11077 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11078}
11079
11080static void
c19d1205 11081do_t_branch23 (void)
b99bd4ef 11082{
e07e6e58 11083 set_it_insn_type_last ();
0855e32b 11084 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11085
0855e32b
NS
11086 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11087 this file. We used to simply ignore the PLT reloc type here --
11088 the branch encoding is now needed to deal with TLSCALL relocs.
11089 So if we see a PLT reloc now, put it back to how it used to be to
11090 keep the preexisting behaviour. */
11091 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11092 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11093
4343666d 11094#if defined(OBJ_COFF)
c19d1205
ZW
11095 /* If the destination of the branch is a defined symbol which does not have
11096 the THUMB_FUNC attribute, then we must be calling a function which has
11097 the (interfacearm) attribute. We look for the Thumb entry point to that
11098 function and change the branch to refer to that function instead. */
11099 if ( inst.reloc.exp.X_op == O_symbol
11100 && inst.reloc.exp.X_add_symbol != NULL
11101 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11102 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11103 inst.reloc.exp.X_add_symbol =
11104 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11105#endif
90e4755a
RE
11106}
11107
11108static void
c19d1205 11109do_t_bx (void)
90e4755a 11110{
e07e6e58 11111 set_it_insn_type_last ();
c19d1205
ZW
11112 inst.instruction |= inst.operands[0].reg << 3;
11113 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11114 should cause the alignment to be checked once it is known. This is
11115 because BX PC only works if the instruction is word aligned. */
11116}
90e4755a 11117
c19d1205
ZW
11118static void
11119do_t_bxj (void)
11120{
fdfde340 11121 int Rm;
90e4755a 11122
e07e6e58 11123 set_it_insn_type_last ();
fdfde340
JM
11124 Rm = inst.operands[0].reg;
11125 reject_bad_reg (Rm);
11126 inst.instruction |= Rm << 16;
90e4755a
RE
11127}
11128
11129static void
c19d1205 11130do_t_clz (void)
90e4755a 11131{
fdfde340
JM
11132 unsigned Rd;
11133 unsigned Rm;
11134
11135 Rd = inst.operands[0].reg;
11136 Rm = inst.operands[1].reg;
11137
11138 reject_bad_reg (Rd);
11139 reject_bad_reg (Rm);
11140
11141 inst.instruction |= Rd << 8;
11142 inst.instruction |= Rm << 16;
11143 inst.instruction |= Rm;
c19d1205 11144}
90e4755a 11145
dfa9f0d5
PB
11146static void
11147do_t_cps (void)
11148{
e07e6e58 11149 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11150 inst.instruction |= inst.operands[0].imm;
11151}
11152
c19d1205
ZW
11153static void
11154do_t_cpsi (void)
11155{
e07e6e58 11156 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11157 if (unified_syntax
62b3e311
PB
11158 && (inst.operands[1].present || inst.size_req == 4)
11159 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11160 {
c19d1205
ZW
11161 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11162 inst.instruction = 0xf3af8000;
11163 inst.instruction |= imod << 9;
11164 inst.instruction |= inst.operands[0].imm << 5;
11165 if (inst.operands[1].present)
11166 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11167 }
c19d1205 11168 else
90e4755a 11169 {
62b3e311
PB
11170 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11171 && (inst.operands[0].imm & 4),
11172 _("selected processor does not support 'A' form "
11173 "of this instruction"));
11174 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11175 _("Thumb does not support the 2-argument "
11176 "form of this instruction"));
11177 inst.instruction |= inst.operands[0].imm;
90e4755a 11178 }
90e4755a
RE
11179}
11180
c19d1205
ZW
11181/* THUMB CPY instruction (argument parse). */
11182
90e4755a 11183static void
c19d1205 11184do_t_cpy (void)
90e4755a 11185{
c19d1205 11186 if (inst.size_req == 4)
90e4755a 11187 {
c19d1205
ZW
11188 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11189 inst.instruction |= inst.operands[0].reg << 8;
11190 inst.instruction |= inst.operands[1].reg;
90e4755a 11191 }
c19d1205 11192 else
90e4755a 11193 {
c19d1205
ZW
11194 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11195 inst.instruction |= (inst.operands[0].reg & 0x7);
11196 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11197 }
90e4755a
RE
11198}
11199
90e4755a 11200static void
25fe350b 11201do_t_cbz (void)
90e4755a 11202{
e07e6e58 11203 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11204 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11205 inst.instruction |= inst.operands[0].reg;
11206 inst.reloc.pc_rel = 1;
11207 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11208}
90e4755a 11209
62b3e311
PB
11210static void
11211do_t_dbg (void)
11212{
11213 inst.instruction |= inst.operands[0].imm;
11214}
11215
11216static void
11217do_t_div (void)
11218{
fdfde340
JM
11219 unsigned Rd, Rn, Rm;
11220
11221 Rd = inst.operands[0].reg;
11222 Rn = (inst.operands[1].present
11223 ? inst.operands[1].reg : Rd);
11224 Rm = inst.operands[2].reg;
11225
11226 reject_bad_reg (Rd);
11227 reject_bad_reg (Rn);
11228 reject_bad_reg (Rm);
11229
11230 inst.instruction |= Rd << 8;
11231 inst.instruction |= Rn << 16;
11232 inst.instruction |= Rm;
62b3e311
PB
11233}
11234
c19d1205
ZW
11235static void
11236do_t_hint (void)
11237{
11238 if (unified_syntax && inst.size_req == 4)
11239 inst.instruction = THUMB_OP32 (inst.instruction);
11240 else
11241 inst.instruction = THUMB_OP16 (inst.instruction);
11242}
90e4755a 11243
c19d1205
ZW
11244static void
11245do_t_it (void)
11246{
11247 unsigned int cond = inst.operands[0].imm;
e27ec89e 11248
e07e6e58
NC
11249 set_it_insn_type (IT_INSN);
11250 now_it.mask = (inst.instruction & 0xf) | 0x10;
11251 now_it.cc = cond;
5a01bb1d 11252 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11253
11254 /* If the condition is a negative condition, invert the mask. */
c19d1205 11255 if ((cond & 0x1) == 0x0)
90e4755a 11256 {
c19d1205 11257 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11258
c19d1205 11259 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11260 {
11261 /* No conversion needed. */
11262 now_it.block_length = 1;
11263 }
c19d1205 11264 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11265 {
11266 mask ^= 0x8;
11267 now_it.block_length = 2;
11268 }
e27ec89e 11269 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11270 {
11271 mask ^= 0xC;
11272 now_it.block_length = 3;
11273 }
c19d1205 11274 else
5a01bb1d
MGD
11275 {
11276 mask ^= 0xE;
11277 now_it.block_length = 4;
11278 }
90e4755a 11279
e27ec89e
PB
11280 inst.instruction &= 0xfff0;
11281 inst.instruction |= mask;
c19d1205 11282 }
90e4755a 11283
c19d1205
ZW
11284 inst.instruction |= cond << 4;
11285}
90e4755a 11286
3c707909
PB
11287/* Helper function used for both push/pop and ldm/stm. */
11288static void
11289encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11290{
11291 bfd_boolean load;
11292
11293 load = (inst.instruction & (1 << 20)) != 0;
11294
11295 if (mask & (1 << 13))
11296 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11297
11298 if ((mask & (1 << base)) != 0
11299 && writeback)
11300 inst.error = _("having the base register in the register list when "
11301 "using write back is UNPREDICTABLE");
11302
3c707909
PB
11303 if (load)
11304 {
e07e6e58 11305 if (mask & (1 << 15))
477330fc
RM
11306 {
11307 if (mask & (1 << 14))
11308 inst.error = _("LR and PC should not both be in register list");
11309 else
11310 set_it_insn_type_last ();
11311 }
3c707909
PB
11312 }
11313 else
11314 {
11315 if (mask & (1 << 15))
11316 inst.error = _("PC not allowed in register list");
3c707909
PB
11317 }
11318
11319 if ((mask & (mask - 1)) == 0)
11320 {
11321 /* Single register transfers implemented as str/ldr. */
11322 if (writeback)
11323 {
11324 if (inst.instruction & (1 << 23))
11325 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11326 else
11327 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11328 }
11329 else
11330 {
11331 if (inst.instruction & (1 << 23))
11332 inst.instruction = 0x00800000; /* ia -> [base] */
11333 else
11334 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11335 }
11336
11337 inst.instruction |= 0xf8400000;
11338 if (load)
11339 inst.instruction |= 0x00100000;
11340
5f4273c7 11341 mask = ffs (mask) - 1;
3c707909
PB
11342 mask <<= 12;
11343 }
11344 else if (writeback)
11345 inst.instruction |= WRITE_BACK;
11346
11347 inst.instruction |= mask;
11348 inst.instruction |= base << 16;
11349}
11350
c19d1205
ZW
11351static void
11352do_t_ldmstm (void)
11353{
11354 /* This really doesn't seem worth it. */
11355 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11356 _("expression too complex"));
11357 constraint (inst.operands[1].writeback,
11358 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11359
c19d1205
ZW
11360 if (unified_syntax)
11361 {
3c707909
PB
11362 bfd_boolean narrow;
11363 unsigned mask;
11364
11365 narrow = FALSE;
c19d1205
ZW
11366 /* See if we can use a 16-bit instruction. */
11367 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11368 && inst.size_req != 4
3c707909 11369 && !(inst.operands[1].imm & ~0xff))
90e4755a 11370 {
3c707909 11371 mask = 1 << inst.operands[0].reg;
90e4755a 11372
eab4f823 11373 if (inst.operands[0].reg <= 7)
90e4755a 11374 {
3c707909 11375 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11376 ? inst.operands[0].writeback
11377 : (inst.operands[0].writeback
11378 == !(inst.operands[1].imm & mask)))
477330fc 11379 {
eab4f823
MGD
11380 if (inst.instruction == T_MNEM_stmia
11381 && (inst.operands[1].imm & mask)
11382 && (inst.operands[1].imm & (mask - 1)))
11383 as_warn (_("value stored for r%d is UNKNOWN"),
11384 inst.operands[0].reg);
3c707909 11385
eab4f823
MGD
11386 inst.instruction = THUMB_OP16 (inst.instruction);
11387 inst.instruction |= inst.operands[0].reg << 8;
11388 inst.instruction |= inst.operands[1].imm;
11389 narrow = TRUE;
11390 }
11391 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11392 {
11393 /* This means 1 register in reg list one of 3 situations:
11394 1. Instruction is stmia, but without writeback.
11395 2. lmdia without writeback, but with Rn not in
477330fc 11396 reglist.
eab4f823
MGD
11397 3. ldmia with writeback, but with Rn in reglist.
11398 Case 3 is UNPREDICTABLE behaviour, so we handle
11399 case 1 and 2 which can be converted into a 16-bit
11400 str or ldr. The SP cases are handled below. */
11401 unsigned long opcode;
11402 /* First, record an error for Case 3. */
11403 if (inst.operands[1].imm & mask
11404 && inst.operands[0].writeback)
fa94de6b 11405 inst.error =
eab4f823
MGD
11406 _("having the base register in the register list when "
11407 "using write back is UNPREDICTABLE");
fa94de6b
RM
11408
11409 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11410 : T_MNEM_ldr);
11411 inst.instruction = THUMB_OP16 (opcode);
11412 inst.instruction |= inst.operands[0].reg << 3;
11413 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11414 narrow = TRUE;
11415 }
90e4755a 11416 }
eab4f823 11417 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11418 {
eab4f823
MGD
11419 if (inst.operands[0].writeback)
11420 {
fa94de6b 11421 inst.instruction =
eab4f823 11422 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11423 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11424 inst.instruction |= inst.operands[1].imm;
477330fc 11425 narrow = TRUE;
eab4f823
MGD
11426 }
11427 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11428 {
fa94de6b 11429 inst.instruction =
eab4f823 11430 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11431 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11432 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11433 narrow = TRUE;
eab4f823 11434 }
90e4755a 11435 }
3c707909
PB
11436 }
11437
11438 if (!narrow)
11439 {
c19d1205
ZW
11440 if (inst.instruction < 0xffff)
11441 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11442
5f4273c7
NC
11443 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11444 inst.operands[0].writeback);
90e4755a
RE
11445 }
11446 }
c19d1205 11447 else
90e4755a 11448 {
c19d1205
ZW
11449 constraint (inst.operands[0].reg > 7
11450 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11451 constraint (inst.instruction != T_MNEM_ldmia
11452 && inst.instruction != T_MNEM_stmia,
11453 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11454 if (inst.instruction == T_MNEM_stmia)
f03698e6 11455 {
c19d1205
ZW
11456 if (!inst.operands[0].writeback)
11457 as_warn (_("this instruction will write back the base register"));
11458 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11459 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11460 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11461 inst.operands[0].reg);
f03698e6 11462 }
c19d1205 11463 else
90e4755a 11464 {
c19d1205
ZW
11465 if (!inst.operands[0].writeback
11466 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11467 as_warn (_("this instruction will write back the base register"));
11468 else if (inst.operands[0].writeback
11469 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11470 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11471 }
11472
c19d1205
ZW
11473 inst.instruction = THUMB_OP16 (inst.instruction);
11474 inst.instruction |= inst.operands[0].reg << 8;
11475 inst.instruction |= inst.operands[1].imm;
11476 }
11477}
e28cd48c 11478
c19d1205
ZW
11479static void
11480do_t_ldrex (void)
11481{
11482 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11483 || inst.operands[1].postind || inst.operands[1].writeback
11484 || inst.operands[1].immisreg || inst.operands[1].shifted
11485 || inst.operands[1].negative,
01cfc07f 11486 BAD_ADDR_MODE);
e28cd48c 11487
5be8be5d
DG
11488 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11489
c19d1205
ZW
11490 inst.instruction |= inst.operands[0].reg << 12;
11491 inst.instruction |= inst.operands[1].reg << 16;
11492 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11493}
e28cd48c 11494
c19d1205
ZW
11495static void
11496do_t_ldrexd (void)
11497{
11498 if (!inst.operands[1].present)
1cac9012 11499 {
c19d1205
ZW
11500 constraint (inst.operands[0].reg == REG_LR,
11501 _("r14 not allowed as first register "
11502 "when second register is omitted"));
11503 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11504 }
c19d1205
ZW
11505 constraint (inst.operands[0].reg == inst.operands[1].reg,
11506 BAD_OVERLAP);
b99bd4ef 11507
c19d1205
ZW
11508 inst.instruction |= inst.operands[0].reg << 12;
11509 inst.instruction |= inst.operands[1].reg << 8;
11510 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11511}
11512
11513static void
c19d1205 11514do_t_ldst (void)
b99bd4ef 11515{
0110f2b8
PB
11516 unsigned long opcode;
11517 int Rn;
11518
e07e6e58
NC
11519 if (inst.operands[0].isreg
11520 && !inst.operands[0].preind
11521 && inst.operands[0].reg == REG_PC)
11522 set_it_insn_type_last ();
11523
0110f2b8 11524 opcode = inst.instruction;
c19d1205 11525 if (unified_syntax)
b99bd4ef 11526 {
53365c0d
PB
11527 if (!inst.operands[1].isreg)
11528 {
11529 if (opcode <= 0xffff)
11530 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11531 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11532 return;
11533 }
0110f2b8
PB
11534 if (inst.operands[1].isreg
11535 && !inst.operands[1].writeback
c19d1205
ZW
11536 && !inst.operands[1].shifted && !inst.operands[1].postind
11537 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11538 && opcode <= 0xffff
11539 && inst.size_req != 4)
c19d1205 11540 {
0110f2b8
PB
11541 /* Insn may have a 16-bit form. */
11542 Rn = inst.operands[1].reg;
11543 if (inst.operands[1].immisreg)
11544 {
11545 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11546 /* [Rn, Rik] */
0110f2b8
PB
11547 if (Rn <= 7 && inst.operands[1].imm <= 7)
11548 goto op16;
5be8be5d
DG
11549 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11550 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11551 }
11552 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11553 && opcode != T_MNEM_ldrsb)
11554 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11555 || (Rn == REG_SP && opcode == T_MNEM_str))
11556 {
11557 /* [Rn, #const] */
11558 if (Rn > 7)
11559 {
11560 if (Rn == REG_PC)
11561 {
11562 if (inst.reloc.pc_rel)
11563 opcode = T_MNEM_ldr_pc2;
11564 else
11565 opcode = T_MNEM_ldr_pc;
11566 }
11567 else
11568 {
11569 if (opcode == T_MNEM_ldr)
11570 opcode = T_MNEM_ldr_sp;
11571 else
11572 opcode = T_MNEM_str_sp;
11573 }
11574 inst.instruction = inst.operands[0].reg << 8;
11575 }
11576 else
11577 {
11578 inst.instruction = inst.operands[0].reg;
11579 inst.instruction |= inst.operands[1].reg << 3;
11580 }
11581 inst.instruction |= THUMB_OP16 (opcode);
11582 if (inst.size_req == 2)
11583 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11584 else
11585 inst.relax = opcode;
11586 return;
11587 }
c19d1205 11588 }
0110f2b8 11589 /* Definitely a 32-bit variant. */
5be8be5d 11590
8d67f500
NC
11591 /* Warning for Erratum 752419. */
11592 if (opcode == T_MNEM_ldr
11593 && inst.operands[0].reg == REG_SP
11594 && inst.operands[1].writeback == 1
11595 && !inst.operands[1].immisreg)
11596 {
11597 if (no_cpu_selected ()
11598 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11599 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11600 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11601 as_warn (_("This instruction may be unpredictable "
11602 "if executed on M-profile cores "
11603 "with interrupts enabled."));
11604 }
11605
5be8be5d 11606 /* Do some validations regarding addressing modes. */
1be5fd2e 11607 if (inst.operands[1].immisreg)
5be8be5d
DG
11608 reject_bad_reg (inst.operands[1].imm);
11609
1be5fd2e
NC
11610 constraint (inst.operands[1].writeback == 1
11611 && inst.operands[0].reg == inst.operands[1].reg,
11612 BAD_OVERLAP);
11613
0110f2b8 11614 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11615 inst.instruction |= inst.operands[0].reg << 12;
11616 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11617 check_ldr_r15_aligned ();
b99bd4ef
NC
11618 return;
11619 }
11620
c19d1205
ZW
11621 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11622
11623 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11624 {
c19d1205
ZW
11625 /* Only [Rn,Rm] is acceptable. */
11626 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11627 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11628 || inst.operands[1].postind || inst.operands[1].shifted
11629 || inst.operands[1].negative,
11630 _("Thumb does not support this addressing mode"));
11631 inst.instruction = THUMB_OP16 (inst.instruction);
11632 goto op16;
b99bd4ef 11633 }
5f4273c7 11634
c19d1205
ZW
11635 inst.instruction = THUMB_OP16 (inst.instruction);
11636 if (!inst.operands[1].isreg)
8335d6aa 11637 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11638 return;
b99bd4ef 11639
c19d1205
ZW
11640 constraint (!inst.operands[1].preind
11641 || inst.operands[1].shifted
11642 || inst.operands[1].writeback,
11643 _("Thumb does not support this addressing mode"));
11644 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11645 {
c19d1205
ZW
11646 constraint (inst.instruction & 0x0600,
11647 _("byte or halfword not valid for base register"));
11648 constraint (inst.operands[1].reg == REG_PC
11649 && !(inst.instruction & THUMB_LOAD_BIT),
11650 _("r15 based store not allowed"));
11651 constraint (inst.operands[1].immisreg,
11652 _("invalid base register for register offset"));
b99bd4ef 11653
c19d1205
ZW
11654 if (inst.operands[1].reg == REG_PC)
11655 inst.instruction = T_OPCODE_LDR_PC;
11656 else if (inst.instruction & THUMB_LOAD_BIT)
11657 inst.instruction = T_OPCODE_LDR_SP;
11658 else
11659 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11660
c19d1205
ZW
11661 inst.instruction |= inst.operands[0].reg << 8;
11662 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11663 return;
11664 }
90e4755a 11665
c19d1205
ZW
11666 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11667 if (!inst.operands[1].immisreg)
11668 {
11669 /* Immediate offset. */
11670 inst.instruction |= inst.operands[0].reg;
11671 inst.instruction |= inst.operands[1].reg << 3;
11672 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11673 return;
11674 }
90e4755a 11675
c19d1205
ZW
11676 /* Register offset. */
11677 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11678 constraint (inst.operands[1].negative,
11679 _("Thumb does not support this addressing mode"));
90e4755a 11680
c19d1205
ZW
11681 op16:
11682 switch (inst.instruction)
11683 {
11684 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11685 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11686 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11687 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11688 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11689 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11690 case 0x5600 /* ldrsb */:
11691 case 0x5e00 /* ldrsh */: break;
11692 default: abort ();
11693 }
90e4755a 11694
c19d1205
ZW
11695 inst.instruction |= inst.operands[0].reg;
11696 inst.instruction |= inst.operands[1].reg << 3;
11697 inst.instruction |= inst.operands[1].imm << 6;
11698}
90e4755a 11699
c19d1205
ZW
11700static void
11701do_t_ldstd (void)
11702{
11703 if (!inst.operands[1].present)
b99bd4ef 11704 {
c19d1205
ZW
11705 inst.operands[1].reg = inst.operands[0].reg + 1;
11706 constraint (inst.operands[0].reg == REG_LR,
11707 _("r14 not allowed here"));
bd340a04 11708 constraint (inst.operands[0].reg == REG_R12,
477330fc 11709 _("r12 not allowed here"));
b99bd4ef 11710 }
bd340a04
MGD
11711
11712 if (inst.operands[2].writeback
11713 && (inst.operands[0].reg == inst.operands[2].reg
11714 || inst.operands[1].reg == inst.operands[2].reg))
11715 as_warn (_("base register written back, and overlaps "
477330fc 11716 "one of transfer registers"));
bd340a04 11717
c19d1205
ZW
11718 inst.instruction |= inst.operands[0].reg << 12;
11719 inst.instruction |= inst.operands[1].reg << 8;
11720 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11721}
11722
c19d1205
ZW
11723static void
11724do_t_ldstt (void)
11725{
11726 inst.instruction |= inst.operands[0].reg << 12;
11727 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11728}
a737bd4d 11729
b99bd4ef 11730static void
c19d1205 11731do_t_mla (void)
b99bd4ef 11732{
fdfde340 11733 unsigned Rd, Rn, Rm, Ra;
c921be7d 11734
fdfde340
JM
11735 Rd = inst.operands[0].reg;
11736 Rn = inst.operands[1].reg;
11737 Rm = inst.operands[2].reg;
11738 Ra = inst.operands[3].reg;
11739
11740 reject_bad_reg (Rd);
11741 reject_bad_reg (Rn);
11742 reject_bad_reg (Rm);
11743 reject_bad_reg (Ra);
11744
11745 inst.instruction |= Rd << 8;
11746 inst.instruction |= Rn << 16;
11747 inst.instruction |= Rm;
11748 inst.instruction |= Ra << 12;
c19d1205 11749}
b99bd4ef 11750
c19d1205
ZW
11751static void
11752do_t_mlal (void)
11753{
fdfde340
JM
11754 unsigned RdLo, RdHi, Rn, Rm;
11755
11756 RdLo = inst.operands[0].reg;
11757 RdHi = inst.operands[1].reg;
11758 Rn = inst.operands[2].reg;
11759 Rm = inst.operands[3].reg;
11760
11761 reject_bad_reg (RdLo);
11762 reject_bad_reg (RdHi);
11763 reject_bad_reg (Rn);
11764 reject_bad_reg (Rm);
11765
11766 inst.instruction |= RdLo << 12;
11767 inst.instruction |= RdHi << 8;
11768 inst.instruction |= Rn << 16;
11769 inst.instruction |= Rm;
c19d1205 11770}
b99bd4ef 11771
c19d1205
ZW
11772static void
11773do_t_mov_cmp (void)
11774{
fdfde340
JM
11775 unsigned Rn, Rm;
11776
11777 Rn = inst.operands[0].reg;
11778 Rm = inst.operands[1].reg;
11779
e07e6e58
NC
11780 if (Rn == REG_PC)
11781 set_it_insn_type_last ();
11782
c19d1205 11783 if (unified_syntax)
b99bd4ef 11784 {
c19d1205
ZW
11785 int r0off = (inst.instruction == T_MNEM_mov
11786 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11787 unsigned long opcode;
3d388997
PB
11788 bfd_boolean narrow;
11789 bfd_boolean low_regs;
11790
fdfde340 11791 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11792 opcode = inst.instruction;
e07e6e58 11793 if (in_it_block ())
0110f2b8 11794 narrow = opcode != T_MNEM_movs;
3d388997 11795 else
0110f2b8 11796 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11797 if (inst.size_req == 4
11798 || inst.operands[1].shifted)
11799 narrow = FALSE;
11800
efd81785
PB
11801 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11802 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11803 && !inst.operands[1].shifted
fdfde340
JM
11804 && Rn == REG_PC
11805 && Rm == REG_LR)
efd81785
PB
11806 {
11807 inst.instruction = T2_SUBS_PC_LR;
11808 return;
11809 }
11810
fdfde340
JM
11811 if (opcode == T_MNEM_cmp)
11812 {
11813 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11814 if (narrow)
11815 {
11816 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11817 but valid. */
11818 warn_deprecated_sp (Rm);
11819 /* R15 was documented as a valid choice for Rm in ARMv6,
11820 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11821 tools reject R15, so we do too. */
11822 constraint (Rm == REG_PC, BAD_PC);
11823 }
11824 else
11825 reject_bad_reg (Rm);
fdfde340
JM
11826 }
11827 else if (opcode == T_MNEM_mov
11828 || opcode == T_MNEM_movs)
11829 {
11830 if (inst.operands[1].isreg)
11831 {
11832 if (opcode == T_MNEM_movs)
11833 {
11834 reject_bad_reg (Rn);
11835 reject_bad_reg (Rm);
11836 }
76fa04a4
MGD
11837 else if (narrow)
11838 {
11839 /* This is mov.n. */
11840 if ((Rn == REG_SP || Rn == REG_PC)
11841 && (Rm == REG_SP || Rm == REG_PC))
11842 {
5c3696f8 11843 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11844 "deprecated when r%u is the destination "
11845 "register."), Rm, Rn);
11846 }
11847 }
11848 else
11849 {
11850 /* This is mov.w. */
11851 constraint (Rn == REG_PC, BAD_PC);
11852 constraint (Rm == REG_PC, BAD_PC);
11853 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11854 }
fdfde340
JM
11855 }
11856 else
11857 reject_bad_reg (Rn);
11858 }
11859
c19d1205
ZW
11860 if (!inst.operands[1].isreg)
11861 {
0110f2b8 11862 /* Immediate operand. */
e07e6e58 11863 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11864 narrow = 0;
11865 if (low_regs && narrow)
11866 {
11867 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11868 inst.instruction |= Rn << 8;
a9f02af8
MG
11869 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11870 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11871 {
a9f02af8 11872 if (inst.size_req == 2)
72d98d16 11873 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11874 else
11875 inst.relax = opcode;
72d98d16 11876 }
0110f2b8
PB
11877 }
11878 else
11879 {
a9f02af8
MG
11880 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11881 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11882 THUMB1_RELOC_ONLY);
11883
0110f2b8
PB
11884 inst.instruction = THUMB_OP32 (inst.instruction);
11885 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11886 inst.instruction |= Rn << r0off;
0110f2b8
PB
11887 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11888 }
c19d1205 11889 }
728ca7c9
PB
11890 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11891 && (inst.instruction == T_MNEM_mov
11892 || inst.instruction == T_MNEM_movs))
11893 {
11894 /* Register shifts are encoded as separate shift instructions. */
11895 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11896
e07e6e58 11897 if (in_it_block ())
728ca7c9
PB
11898 narrow = !flags;
11899 else
11900 narrow = flags;
11901
11902 if (inst.size_req == 4)
11903 narrow = FALSE;
11904
11905 if (!low_regs || inst.operands[1].imm > 7)
11906 narrow = FALSE;
11907
fdfde340 11908 if (Rn != Rm)
728ca7c9
PB
11909 narrow = FALSE;
11910
11911 switch (inst.operands[1].shift_kind)
11912 {
11913 case SHIFT_LSL:
11914 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11915 break;
11916 case SHIFT_ASR:
11917 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11918 break;
11919 case SHIFT_LSR:
11920 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11921 break;
11922 case SHIFT_ROR:
11923 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11924 break;
11925 default:
5f4273c7 11926 abort ();
728ca7c9
PB
11927 }
11928
11929 inst.instruction = opcode;
11930 if (narrow)
11931 {
fdfde340 11932 inst.instruction |= Rn;
728ca7c9
PB
11933 inst.instruction |= inst.operands[1].imm << 3;
11934 }
11935 else
11936 {
11937 if (flags)
11938 inst.instruction |= CONDS_BIT;
11939
fdfde340
JM
11940 inst.instruction |= Rn << 8;
11941 inst.instruction |= Rm << 16;
728ca7c9
PB
11942 inst.instruction |= inst.operands[1].imm;
11943 }
11944 }
3d388997 11945 else if (!narrow)
c19d1205 11946 {
728ca7c9
PB
11947 /* Some mov with immediate shift have narrow variants.
11948 Register shifts are handled above. */
11949 if (low_regs && inst.operands[1].shifted
11950 && (inst.instruction == T_MNEM_mov
11951 || inst.instruction == T_MNEM_movs))
11952 {
e07e6e58 11953 if (in_it_block ())
728ca7c9
PB
11954 narrow = (inst.instruction == T_MNEM_mov);
11955 else
11956 narrow = (inst.instruction == T_MNEM_movs);
11957 }
11958
11959 if (narrow)
11960 {
11961 switch (inst.operands[1].shift_kind)
11962 {
11963 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11964 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11965 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11966 default: narrow = FALSE; break;
11967 }
11968 }
11969
11970 if (narrow)
11971 {
fdfde340
JM
11972 inst.instruction |= Rn;
11973 inst.instruction |= Rm << 3;
728ca7c9
PB
11974 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11975 }
11976 else
11977 {
11978 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11979 inst.instruction |= Rn << r0off;
728ca7c9
PB
11980 encode_thumb32_shifted_operand (1);
11981 }
c19d1205
ZW
11982 }
11983 else
11984 switch (inst.instruction)
11985 {
11986 case T_MNEM_mov:
837b3435 11987 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11988 results. Don't allow this. */
11989 if (low_regs)
11990 {
11991 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11992 "MOV Rd, Rs with two low registers is not "
11993 "permitted on this architecture");
fa94de6b 11994 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11995 arm_ext_v6);
11996 }
11997
c19d1205 11998 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11999 inst.instruction |= (Rn & 0x8) << 4;
12000 inst.instruction |= (Rn & 0x7);
12001 inst.instruction |= Rm << 3;
c19d1205 12002 break;
b99bd4ef 12003
c19d1205
ZW
12004 case T_MNEM_movs:
12005 /* We know we have low registers at this point.
941a8a52
MGD
12006 Generate LSLS Rd, Rs, #0. */
12007 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12008 inst.instruction |= Rn;
12009 inst.instruction |= Rm << 3;
c19d1205
ZW
12010 break;
12011
12012 case T_MNEM_cmp:
3d388997 12013 if (low_regs)
c19d1205
ZW
12014 {
12015 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12016 inst.instruction |= Rn;
12017 inst.instruction |= Rm << 3;
c19d1205
ZW
12018 }
12019 else
12020 {
12021 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12022 inst.instruction |= (Rn & 0x8) << 4;
12023 inst.instruction |= (Rn & 0x7);
12024 inst.instruction |= Rm << 3;
c19d1205
ZW
12025 }
12026 break;
12027 }
b99bd4ef
NC
12028 return;
12029 }
12030
c19d1205 12031 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12032
12033 /* PR 10443: Do not silently ignore shifted operands. */
12034 constraint (inst.operands[1].shifted,
12035 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12036
c19d1205 12037 if (inst.operands[1].isreg)
b99bd4ef 12038 {
fdfde340 12039 if (Rn < 8 && Rm < 8)
b99bd4ef 12040 {
c19d1205
ZW
12041 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12042 since a MOV instruction produces unpredictable results. */
12043 if (inst.instruction == T_OPCODE_MOV_I8)
12044 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12045 else
c19d1205 12046 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12047
fdfde340
JM
12048 inst.instruction |= Rn;
12049 inst.instruction |= Rm << 3;
b99bd4ef
NC
12050 }
12051 else
12052 {
c19d1205
ZW
12053 if (inst.instruction == T_OPCODE_MOV_I8)
12054 inst.instruction = T_OPCODE_MOV_HR;
12055 else
12056 inst.instruction = T_OPCODE_CMP_HR;
12057 do_t_cpy ();
b99bd4ef
NC
12058 }
12059 }
c19d1205 12060 else
b99bd4ef 12061 {
fdfde340 12062 constraint (Rn > 7,
c19d1205 12063 _("only lo regs allowed with immediate"));
fdfde340 12064 inst.instruction |= Rn << 8;
c19d1205
ZW
12065 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12066 }
12067}
b99bd4ef 12068
c19d1205
ZW
12069static void
12070do_t_mov16 (void)
12071{
fdfde340 12072 unsigned Rd;
b6895b4f
PB
12073 bfd_vma imm;
12074 bfd_boolean top;
12075
12076 top = (inst.instruction & 0x00800000) != 0;
12077 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12078 {
12079 constraint (top, _(":lower16: not allowed this instruction"));
12080 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12081 }
12082 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12083 {
12084 constraint (!top, _(":upper16: not allowed this instruction"));
12085 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12086 }
12087
fdfde340
JM
12088 Rd = inst.operands[0].reg;
12089 reject_bad_reg (Rd);
12090
12091 inst.instruction |= Rd << 8;
b6895b4f
PB
12092 if (inst.reloc.type == BFD_RELOC_UNUSED)
12093 {
12094 imm = inst.reloc.exp.X_add_number;
12095 inst.instruction |= (imm & 0xf000) << 4;
12096 inst.instruction |= (imm & 0x0800) << 15;
12097 inst.instruction |= (imm & 0x0700) << 4;
12098 inst.instruction |= (imm & 0x00ff);
12099 }
c19d1205 12100}
b99bd4ef 12101
c19d1205
ZW
12102static void
12103do_t_mvn_tst (void)
12104{
fdfde340 12105 unsigned Rn, Rm;
c921be7d 12106
fdfde340
JM
12107 Rn = inst.operands[0].reg;
12108 Rm = inst.operands[1].reg;
12109
12110 if (inst.instruction == T_MNEM_cmp
12111 || inst.instruction == T_MNEM_cmn)
12112 constraint (Rn == REG_PC, BAD_PC);
12113 else
12114 reject_bad_reg (Rn);
12115 reject_bad_reg (Rm);
12116
c19d1205
ZW
12117 if (unified_syntax)
12118 {
12119 int r0off = (inst.instruction == T_MNEM_mvn
12120 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12121 bfd_boolean narrow;
12122
12123 if (inst.size_req == 4
12124 || inst.instruction > 0xffff
12125 || inst.operands[1].shifted
fdfde340 12126 || Rn > 7 || Rm > 7)
3d388997 12127 narrow = FALSE;
fe8b4cc3
KT
12128 else if (inst.instruction == T_MNEM_cmn
12129 || inst.instruction == T_MNEM_tst)
3d388997
PB
12130 narrow = TRUE;
12131 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12132 narrow = !in_it_block ();
3d388997 12133 else
e07e6e58 12134 narrow = in_it_block ();
3d388997 12135
c19d1205 12136 if (!inst.operands[1].isreg)
b99bd4ef 12137 {
c19d1205
ZW
12138 /* For an immediate, we always generate a 32-bit opcode;
12139 section relaxation will shrink it later if possible. */
12140 if (inst.instruction < 0xffff)
12141 inst.instruction = THUMB_OP32 (inst.instruction);
12142 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12143 inst.instruction |= Rn << r0off;
c19d1205 12144 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12145 }
c19d1205 12146 else
b99bd4ef 12147 {
c19d1205 12148 /* See if we can do this with a 16-bit instruction. */
3d388997 12149 if (narrow)
b99bd4ef 12150 {
c19d1205 12151 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12152 inst.instruction |= Rn;
12153 inst.instruction |= Rm << 3;
b99bd4ef 12154 }
c19d1205 12155 else
b99bd4ef 12156 {
c19d1205
ZW
12157 constraint (inst.operands[1].shifted
12158 && inst.operands[1].immisreg,
12159 _("shift must be constant"));
12160 if (inst.instruction < 0xffff)
12161 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12162 inst.instruction |= Rn << r0off;
c19d1205 12163 encode_thumb32_shifted_operand (1);
b99bd4ef 12164 }
b99bd4ef
NC
12165 }
12166 }
12167 else
12168 {
c19d1205
ZW
12169 constraint (inst.instruction > 0xffff
12170 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12171 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12172 _("unshifted register required"));
fdfde340 12173 constraint (Rn > 7 || Rm > 7,
c19d1205 12174 BAD_HIREG);
b99bd4ef 12175
c19d1205 12176 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12177 inst.instruction |= Rn;
12178 inst.instruction |= Rm << 3;
b99bd4ef 12179 }
b99bd4ef
NC
12180}
12181
b05fe5cf 12182static void
c19d1205 12183do_t_mrs (void)
b05fe5cf 12184{
fdfde340 12185 unsigned Rd;
037e8744
JB
12186
12187 if (do_vfp_nsyn_mrs () == SUCCESS)
12188 return;
12189
90ec0d68
MGD
12190 Rd = inst.operands[0].reg;
12191 reject_bad_reg (Rd);
12192 inst.instruction |= Rd << 8;
12193
12194 if (inst.operands[1].isreg)
62b3e311 12195 {
90ec0d68
MGD
12196 unsigned br = inst.operands[1].reg;
12197 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12198 as_bad (_("bad register for mrs"));
12199
12200 inst.instruction |= br & (0xf << 16);
12201 inst.instruction |= (br & 0x300) >> 4;
12202 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12203 }
12204 else
12205 {
90ec0d68 12206 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12207
d2cd1205 12208 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12209 {
12210 /* PR gas/12698: The constraint is only applied for m_profile.
12211 If the user has specified -march=all, we want to ignore it as
12212 we are building for any CPU type, including non-m variants. */
823d2571
TG
12213 bfd_boolean m_profile =
12214 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12215 constraint ((flags != 0) && m_profile, _("selected processor does "
12216 "not support requested special purpose register"));
12217 }
90ec0d68 12218 else
d2cd1205
JB
12219 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12220 devices). */
12221 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12222 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12223
90ec0d68
MGD
12224 inst.instruction |= (flags & SPSR_BIT) >> 2;
12225 inst.instruction |= inst.operands[1].imm & 0xff;
12226 inst.instruction |= 0xf0000;
12227 }
c19d1205 12228}
b05fe5cf 12229
c19d1205
ZW
12230static void
12231do_t_msr (void)
12232{
62b3e311 12233 int flags;
fdfde340 12234 unsigned Rn;
62b3e311 12235
037e8744
JB
12236 if (do_vfp_nsyn_msr () == SUCCESS)
12237 return;
12238
c19d1205
ZW
12239 constraint (!inst.operands[1].isreg,
12240 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12241
12242 if (inst.operands[0].isreg)
12243 flags = (int)(inst.operands[0].reg);
12244 else
12245 flags = inst.operands[0].imm;
12246
d2cd1205 12247 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12248 {
d2cd1205
JB
12249 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12250
1a43faaf 12251 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12252 If the user has specified -march=all, we want to ignore it as
12253 we are building for any CPU type, including non-m variants. */
823d2571
TG
12254 bfd_boolean m_profile =
12255 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12256 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12257 && (bits & ~(PSR_s | PSR_f)) != 0)
12258 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12259 && bits != PSR_f)) && m_profile,
12260 _("selected processor does not support requested special "
12261 "purpose register"));
62b3e311
PB
12262 }
12263 else
d2cd1205
JB
12264 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12265 "requested special purpose register"));
c921be7d 12266
fdfde340
JM
12267 Rn = inst.operands[1].reg;
12268 reject_bad_reg (Rn);
12269
62b3e311 12270 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12271 inst.instruction |= (flags & 0xf0000) >> 8;
12272 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12273 inst.instruction |= (flags & 0xff);
fdfde340 12274 inst.instruction |= Rn << 16;
c19d1205 12275}
b05fe5cf 12276
c19d1205
ZW
12277static void
12278do_t_mul (void)
12279{
17828f45 12280 bfd_boolean narrow;
fdfde340 12281 unsigned Rd, Rn, Rm;
17828f45 12282
c19d1205
ZW
12283 if (!inst.operands[2].present)
12284 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12285
fdfde340
JM
12286 Rd = inst.operands[0].reg;
12287 Rn = inst.operands[1].reg;
12288 Rm = inst.operands[2].reg;
12289
17828f45 12290 if (unified_syntax)
b05fe5cf 12291 {
17828f45 12292 if (inst.size_req == 4
fdfde340
JM
12293 || (Rd != Rn
12294 && Rd != Rm)
12295 || Rn > 7
12296 || Rm > 7)
17828f45
JM
12297 narrow = FALSE;
12298 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12299 narrow = !in_it_block ();
17828f45 12300 else
e07e6e58 12301 narrow = in_it_block ();
b05fe5cf 12302 }
c19d1205 12303 else
b05fe5cf 12304 {
17828f45 12305 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12306 constraint (Rn > 7 || Rm > 7,
c19d1205 12307 BAD_HIREG);
17828f45
JM
12308 narrow = TRUE;
12309 }
b05fe5cf 12310
17828f45
JM
12311 if (narrow)
12312 {
12313 /* 16-bit MULS/Conditional MUL. */
c19d1205 12314 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12315 inst.instruction |= Rd;
b05fe5cf 12316
fdfde340
JM
12317 if (Rd == Rn)
12318 inst.instruction |= Rm << 3;
12319 else if (Rd == Rm)
12320 inst.instruction |= Rn << 3;
c19d1205
ZW
12321 else
12322 constraint (1, _("dest must overlap one source register"));
12323 }
17828f45
JM
12324 else
12325 {
e07e6e58
NC
12326 constraint (inst.instruction != T_MNEM_mul,
12327 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12328 /* 32-bit MUL. */
12329 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12330 inst.instruction |= Rd << 8;
12331 inst.instruction |= Rn << 16;
12332 inst.instruction |= Rm << 0;
12333
12334 reject_bad_reg (Rd);
12335 reject_bad_reg (Rn);
12336 reject_bad_reg (Rm);
17828f45 12337 }
c19d1205 12338}
b05fe5cf 12339
c19d1205
ZW
12340static void
12341do_t_mull (void)
12342{
fdfde340 12343 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12344
fdfde340
JM
12345 RdLo = inst.operands[0].reg;
12346 RdHi = inst.operands[1].reg;
12347 Rn = inst.operands[2].reg;
12348 Rm = inst.operands[3].reg;
12349
12350 reject_bad_reg (RdLo);
12351 reject_bad_reg (RdHi);
12352 reject_bad_reg (Rn);
12353 reject_bad_reg (Rm);
12354
12355 inst.instruction |= RdLo << 12;
12356 inst.instruction |= RdHi << 8;
12357 inst.instruction |= Rn << 16;
12358 inst.instruction |= Rm;
12359
12360 if (RdLo == RdHi)
c19d1205
ZW
12361 as_tsktsk (_("rdhi and rdlo must be different"));
12362}
b05fe5cf 12363
c19d1205
ZW
12364static void
12365do_t_nop (void)
12366{
e07e6e58
NC
12367 set_it_insn_type (NEUTRAL_IT_INSN);
12368
c19d1205
ZW
12369 if (unified_syntax)
12370 {
12371 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12372 {
c19d1205
ZW
12373 inst.instruction = THUMB_OP32 (inst.instruction);
12374 inst.instruction |= inst.operands[0].imm;
12375 }
12376 else
12377 {
bc2d1808
NC
12378 /* PR9722: Check for Thumb2 availability before
12379 generating a thumb2 nop instruction. */
afa62d5e 12380 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12381 {
12382 inst.instruction = THUMB_OP16 (inst.instruction);
12383 inst.instruction |= inst.operands[0].imm << 4;
12384 }
12385 else
12386 inst.instruction = 0x46c0;
c19d1205
ZW
12387 }
12388 }
12389 else
12390 {
12391 constraint (inst.operands[0].present,
12392 _("Thumb does not support NOP with hints"));
12393 inst.instruction = 0x46c0;
12394 }
12395}
b05fe5cf 12396
c19d1205
ZW
12397static void
12398do_t_neg (void)
12399{
12400 if (unified_syntax)
12401 {
3d388997
PB
12402 bfd_boolean narrow;
12403
12404 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12405 narrow = !in_it_block ();
3d388997 12406 else
e07e6e58 12407 narrow = in_it_block ();
3d388997
PB
12408 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12409 narrow = FALSE;
12410 if (inst.size_req == 4)
12411 narrow = FALSE;
12412
12413 if (!narrow)
c19d1205
ZW
12414 {
12415 inst.instruction = THUMB_OP32 (inst.instruction);
12416 inst.instruction |= inst.operands[0].reg << 8;
12417 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12418 }
12419 else
12420 {
c19d1205
ZW
12421 inst.instruction = THUMB_OP16 (inst.instruction);
12422 inst.instruction |= inst.operands[0].reg;
12423 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12424 }
12425 }
12426 else
12427 {
c19d1205
ZW
12428 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12429 BAD_HIREG);
12430 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12431
12432 inst.instruction = THUMB_OP16 (inst.instruction);
12433 inst.instruction |= inst.operands[0].reg;
12434 inst.instruction |= inst.operands[1].reg << 3;
12435 }
12436}
12437
1c444d06
JM
12438static void
12439do_t_orn (void)
12440{
12441 unsigned Rd, Rn;
12442
12443 Rd = inst.operands[0].reg;
12444 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12445
fdfde340
JM
12446 reject_bad_reg (Rd);
12447 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12448 reject_bad_reg (Rn);
12449
1c444d06
JM
12450 inst.instruction |= Rd << 8;
12451 inst.instruction |= Rn << 16;
12452
12453 if (!inst.operands[2].isreg)
12454 {
12455 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12456 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12457 }
12458 else
12459 {
12460 unsigned Rm;
12461
12462 Rm = inst.operands[2].reg;
fdfde340 12463 reject_bad_reg (Rm);
1c444d06
JM
12464
12465 constraint (inst.operands[2].shifted
12466 && inst.operands[2].immisreg,
12467 _("shift must be constant"));
12468 encode_thumb32_shifted_operand (2);
12469 }
12470}
12471
c19d1205
ZW
12472static void
12473do_t_pkhbt (void)
12474{
fdfde340
JM
12475 unsigned Rd, Rn, Rm;
12476
12477 Rd = inst.operands[0].reg;
12478 Rn = inst.operands[1].reg;
12479 Rm = inst.operands[2].reg;
12480
12481 reject_bad_reg (Rd);
12482 reject_bad_reg (Rn);
12483 reject_bad_reg (Rm);
12484
12485 inst.instruction |= Rd << 8;
12486 inst.instruction |= Rn << 16;
12487 inst.instruction |= Rm;
c19d1205
ZW
12488 if (inst.operands[3].present)
12489 {
12490 unsigned int val = inst.reloc.exp.X_add_number;
12491 constraint (inst.reloc.exp.X_op != O_constant,
12492 _("expression too complex"));
12493 inst.instruction |= (val & 0x1c) << 10;
12494 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12495 }
c19d1205 12496}
b05fe5cf 12497
c19d1205
ZW
12498static void
12499do_t_pkhtb (void)
12500{
12501 if (!inst.operands[3].present)
1ef52f49
NC
12502 {
12503 unsigned Rtmp;
12504
12505 inst.instruction &= ~0x00000020;
12506
12507 /* PR 10168. Swap the Rm and Rn registers. */
12508 Rtmp = inst.operands[1].reg;
12509 inst.operands[1].reg = inst.operands[2].reg;
12510 inst.operands[2].reg = Rtmp;
12511 }
c19d1205 12512 do_t_pkhbt ();
b05fe5cf
ZW
12513}
12514
c19d1205
ZW
12515static void
12516do_t_pld (void)
12517{
fdfde340
JM
12518 if (inst.operands[0].immisreg)
12519 reject_bad_reg (inst.operands[0].imm);
12520
c19d1205
ZW
12521 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12522}
b05fe5cf 12523
c19d1205
ZW
12524static void
12525do_t_push_pop (void)
b99bd4ef 12526{
e9f89963 12527 unsigned mask;
5f4273c7 12528
c19d1205
ZW
12529 constraint (inst.operands[0].writeback,
12530 _("push/pop do not support {reglist}^"));
12531 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12532 _("expression too complex"));
b99bd4ef 12533
e9f89963 12534 mask = inst.operands[0].imm;
d3bfe16e 12535 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12536 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12537 else if (inst.size_req != 4
c6025a80 12538 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12539 ? REG_LR : REG_PC)))
b99bd4ef 12540 {
c19d1205
ZW
12541 inst.instruction = THUMB_OP16 (inst.instruction);
12542 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12543 inst.instruction |= mask & 0xff;
c19d1205
ZW
12544 }
12545 else if (unified_syntax)
12546 {
3c707909 12547 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12548 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12549 }
12550 else
12551 {
12552 inst.error = _("invalid register list to push/pop instruction");
12553 return;
12554 }
c19d1205 12555}
b99bd4ef 12556
c19d1205
ZW
12557static void
12558do_t_rbit (void)
12559{
fdfde340
JM
12560 unsigned Rd, Rm;
12561
12562 Rd = inst.operands[0].reg;
12563 Rm = inst.operands[1].reg;
12564
12565 reject_bad_reg (Rd);
12566 reject_bad_reg (Rm);
12567
12568 inst.instruction |= Rd << 8;
12569 inst.instruction |= Rm << 16;
12570 inst.instruction |= Rm;
c19d1205 12571}
b99bd4ef 12572
c19d1205
ZW
12573static void
12574do_t_rev (void)
12575{
fdfde340
JM
12576 unsigned Rd, Rm;
12577
12578 Rd = inst.operands[0].reg;
12579 Rm = inst.operands[1].reg;
12580
12581 reject_bad_reg (Rd);
12582 reject_bad_reg (Rm);
12583
12584 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12585 && inst.size_req != 4)
12586 {
12587 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12588 inst.instruction |= Rd;
12589 inst.instruction |= Rm << 3;
c19d1205
ZW
12590 }
12591 else if (unified_syntax)
12592 {
12593 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12594 inst.instruction |= Rd << 8;
12595 inst.instruction |= Rm << 16;
12596 inst.instruction |= Rm;
c19d1205
ZW
12597 }
12598 else
12599 inst.error = BAD_HIREG;
12600}
b99bd4ef 12601
1c444d06
JM
12602static void
12603do_t_rrx (void)
12604{
12605 unsigned Rd, Rm;
12606
12607 Rd = inst.operands[0].reg;
12608 Rm = inst.operands[1].reg;
12609
fdfde340
JM
12610 reject_bad_reg (Rd);
12611 reject_bad_reg (Rm);
c921be7d 12612
1c444d06
JM
12613 inst.instruction |= Rd << 8;
12614 inst.instruction |= Rm;
12615}
12616
c19d1205
ZW
12617static void
12618do_t_rsb (void)
12619{
fdfde340 12620 unsigned Rd, Rs;
b99bd4ef 12621
c19d1205
ZW
12622 Rd = inst.operands[0].reg;
12623 Rs = (inst.operands[1].present
12624 ? inst.operands[1].reg /* Rd, Rs, foo */
12625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12626
fdfde340
JM
12627 reject_bad_reg (Rd);
12628 reject_bad_reg (Rs);
12629 if (inst.operands[2].isreg)
12630 reject_bad_reg (inst.operands[2].reg);
12631
c19d1205
ZW
12632 inst.instruction |= Rd << 8;
12633 inst.instruction |= Rs << 16;
12634 if (!inst.operands[2].isreg)
12635 {
026d3abb
PB
12636 bfd_boolean narrow;
12637
12638 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12639 narrow = !in_it_block ();
026d3abb 12640 else
e07e6e58 12641 narrow = in_it_block ();
026d3abb
PB
12642
12643 if (Rd > 7 || Rs > 7)
12644 narrow = FALSE;
12645
12646 if (inst.size_req == 4 || !unified_syntax)
12647 narrow = FALSE;
12648
12649 if (inst.reloc.exp.X_op != O_constant
12650 || inst.reloc.exp.X_add_number != 0)
12651 narrow = FALSE;
12652
12653 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12654 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12655 if (narrow)
12656 {
12657 inst.reloc.type = BFD_RELOC_UNUSED;
12658 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12659 inst.instruction |= Rs << 3;
12660 inst.instruction |= Rd;
12661 }
12662 else
12663 {
12664 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12665 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12666 }
c19d1205
ZW
12667 }
12668 else
12669 encode_thumb32_shifted_operand (2);
12670}
b99bd4ef 12671
c19d1205
ZW
12672static void
12673do_t_setend (void)
12674{
12e37cbc
MGD
12675 if (warn_on_deprecated
12676 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12677 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12678
e07e6e58 12679 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12680 if (inst.operands[0].imm)
12681 inst.instruction |= 0x8;
12682}
b99bd4ef 12683
c19d1205
ZW
12684static void
12685do_t_shift (void)
12686{
12687 if (!inst.operands[1].present)
12688 inst.operands[1].reg = inst.operands[0].reg;
12689
12690 if (unified_syntax)
12691 {
3d388997
PB
12692 bfd_boolean narrow;
12693 int shift_kind;
12694
12695 switch (inst.instruction)
12696 {
12697 case T_MNEM_asr:
12698 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12699 case T_MNEM_lsl:
12700 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12701 case T_MNEM_lsr:
12702 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12703 case T_MNEM_ror:
12704 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12705 default: abort ();
12706 }
12707
12708 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12709 narrow = !in_it_block ();
3d388997 12710 else
e07e6e58 12711 narrow = in_it_block ();
3d388997
PB
12712 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12713 narrow = FALSE;
12714 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12715 narrow = FALSE;
12716 if (inst.operands[2].isreg
12717 && (inst.operands[1].reg != inst.operands[0].reg
12718 || inst.operands[2].reg > 7))
12719 narrow = FALSE;
12720 if (inst.size_req == 4)
12721 narrow = FALSE;
12722
fdfde340
JM
12723 reject_bad_reg (inst.operands[0].reg);
12724 reject_bad_reg (inst.operands[1].reg);
c921be7d 12725
3d388997 12726 if (!narrow)
c19d1205
ZW
12727 {
12728 if (inst.operands[2].isreg)
b99bd4ef 12729 {
fdfde340 12730 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12731 inst.instruction = THUMB_OP32 (inst.instruction);
12732 inst.instruction |= inst.operands[0].reg << 8;
12733 inst.instruction |= inst.operands[1].reg << 16;
12734 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12735
12736 /* PR 12854: Error on extraneous shifts. */
12737 constraint (inst.operands[2].shifted,
12738 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12739 }
12740 else
12741 {
12742 inst.operands[1].shifted = 1;
3d388997 12743 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12744 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12745 ? T_MNEM_movs : T_MNEM_mov);
12746 inst.instruction |= inst.operands[0].reg << 8;
12747 encode_thumb32_shifted_operand (1);
12748 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12749 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12750 }
12751 }
12752 else
12753 {
c19d1205 12754 if (inst.operands[2].isreg)
b99bd4ef 12755 {
3d388997 12756 switch (shift_kind)
b99bd4ef 12757 {
3d388997
PB
12758 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12759 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12760 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12761 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12762 default: abort ();
b99bd4ef 12763 }
5f4273c7 12764
c19d1205
ZW
12765 inst.instruction |= inst.operands[0].reg;
12766 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12767
12768 /* PR 12854: Error on extraneous shifts. */
12769 constraint (inst.operands[2].shifted,
12770 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12771 }
12772 else
12773 {
3d388997 12774 switch (shift_kind)
b99bd4ef 12775 {
3d388997
PB
12776 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12777 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12778 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12779 default: abort ();
b99bd4ef 12780 }
c19d1205
ZW
12781 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12782 inst.instruction |= inst.operands[0].reg;
12783 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12784 }
12785 }
c19d1205
ZW
12786 }
12787 else
12788 {
12789 constraint (inst.operands[0].reg > 7
12790 || inst.operands[1].reg > 7, BAD_HIREG);
12791 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12792
c19d1205
ZW
12793 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12794 {
12795 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12796 constraint (inst.operands[0].reg != inst.operands[1].reg,
12797 _("source1 and dest must be same register"));
b99bd4ef 12798
c19d1205
ZW
12799 switch (inst.instruction)
12800 {
12801 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12802 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12803 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12804 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12805 default: abort ();
12806 }
5f4273c7 12807
c19d1205
ZW
12808 inst.instruction |= inst.operands[0].reg;
12809 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12810
12811 /* PR 12854: Error on extraneous shifts. */
12812 constraint (inst.operands[2].shifted,
12813 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12814 }
12815 else
b99bd4ef 12816 {
c19d1205
ZW
12817 switch (inst.instruction)
12818 {
12819 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12820 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12821 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12822 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12823 default: abort ();
12824 }
12825 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12826 inst.instruction |= inst.operands[0].reg;
12827 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12828 }
12829 }
b99bd4ef
NC
12830}
12831
12832static void
c19d1205 12833do_t_simd (void)
b99bd4ef 12834{
fdfde340
JM
12835 unsigned Rd, Rn, Rm;
12836
12837 Rd = inst.operands[0].reg;
12838 Rn = inst.operands[1].reg;
12839 Rm = inst.operands[2].reg;
12840
12841 reject_bad_reg (Rd);
12842 reject_bad_reg (Rn);
12843 reject_bad_reg (Rm);
12844
12845 inst.instruction |= Rd << 8;
12846 inst.instruction |= Rn << 16;
12847 inst.instruction |= Rm;
c19d1205 12848}
b99bd4ef 12849
03ee1b7f
NC
12850static void
12851do_t_simd2 (void)
12852{
12853 unsigned Rd, Rn, Rm;
12854
12855 Rd = inst.operands[0].reg;
12856 Rm = inst.operands[1].reg;
12857 Rn = inst.operands[2].reg;
12858
12859 reject_bad_reg (Rd);
12860 reject_bad_reg (Rn);
12861 reject_bad_reg (Rm);
12862
12863 inst.instruction |= Rd << 8;
12864 inst.instruction |= Rn << 16;
12865 inst.instruction |= Rm;
12866}
12867
c19d1205 12868static void
3eb17e6b 12869do_t_smc (void)
c19d1205
ZW
12870{
12871 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12872 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12873 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12874 constraint (inst.reloc.exp.X_op != O_constant,
12875 _("expression too complex"));
12876 inst.reloc.type = BFD_RELOC_UNUSED;
12877 inst.instruction |= (value & 0xf000) >> 12;
12878 inst.instruction |= (value & 0x0ff0);
12879 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12880 /* PR gas/15623: SMC instructions must be last in an IT block. */
12881 set_it_insn_type_last ();
c19d1205 12882}
b99bd4ef 12883
90ec0d68
MGD
12884static void
12885do_t_hvc (void)
12886{
12887 unsigned int value = inst.reloc.exp.X_add_number;
12888
12889 inst.reloc.type = BFD_RELOC_UNUSED;
12890 inst.instruction |= (value & 0x0fff);
12891 inst.instruction |= (value & 0xf000) << 4;
12892}
12893
c19d1205 12894static void
3a21c15a 12895do_t_ssat_usat (int bias)
c19d1205 12896{
fdfde340
JM
12897 unsigned Rd, Rn;
12898
12899 Rd = inst.operands[0].reg;
12900 Rn = inst.operands[2].reg;
12901
12902 reject_bad_reg (Rd);
12903 reject_bad_reg (Rn);
12904
12905 inst.instruction |= Rd << 8;
3a21c15a 12906 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12907 inst.instruction |= Rn << 16;
b99bd4ef 12908
c19d1205 12909 if (inst.operands[3].present)
b99bd4ef 12910 {
3a21c15a
NC
12911 offsetT shift_amount = inst.reloc.exp.X_add_number;
12912
12913 inst.reloc.type = BFD_RELOC_UNUSED;
12914
c19d1205
ZW
12915 constraint (inst.reloc.exp.X_op != O_constant,
12916 _("expression too complex"));
b99bd4ef 12917
3a21c15a 12918 if (shift_amount != 0)
6189168b 12919 {
3a21c15a
NC
12920 constraint (shift_amount > 31,
12921 _("shift expression is too large"));
12922
c19d1205 12923 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12924 inst.instruction |= 0x00200000; /* sh bit. */
12925
12926 inst.instruction |= (shift_amount & 0x1c) << 10;
12927 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12928 }
12929 }
b99bd4ef 12930}
c921be7d 12931
3a21c15a
NC
12932static void
12933do_t_ssat (void)
12934{
12935 do_t_ssat_usat (1);
12936}
b99bd4ef 12937
0dd132b6 12938static void
c19d1205 12939do_t_ssat16 (void)
0dd132b6 12940{
fdfde340
JM
12941 unsigned Rd, Rn;
12942
12943 Rd = inst.operands[0].reg;
12944 Rn = inst.operands[2].reg;
12945
12946 reject_bad_reg (Rd);
12947 reject_bad_reg (Rn);
12948
12949 inst.instruction |= Rd << 8;
c19d1205 12950 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12951 inst.instruction |= Rn << 16;
c19d1205 12952}
0dd132b6 12953
c19d1205
ZW
12954static void
12955do_t_strex (void)
12956{
12957 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12958 || inst.operands[2].postind || inst.operands[2].writeback
12959 || inst.operands[2].immisreg || inst.operands[2].shifted
12960 || inst.operands[2].negative,
01cfc07f 12961 BAD_ADDR_MODE);
0dd132b6 12962
5be8be5d
DG
12963 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12964
c19d1205
ZW
12965 inst.instruction |= inst.operands[0].reg << 8;
12966 inst.instruction |= inst.operands[1].reg << 12;
12967 inst.instruction |= inst.operands[2].reg << 16;
12968 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12969}
12970
b99bd4ef 12971static void
c19d1205 12972do_t_strexd (void)
b99bd4ef 12973{
c19d1205
ZW
12974 if (!inst.operands[2].present)
12975 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12976
c19d1205
ZW
12977 constraint (inst.operands[0].reg == inst.operands[1].reg
12978 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12979 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12980 BAD_OVERLAP);
b99bd4ef 12981
c19d1205
ZW
12982 inst.instruction |= inst.operands[0].reg;
12983 inst.instruction |= inst.operands[1].reg << 12;
12984 inst.instruction |= inst.operands[2].reg << 8;
12985 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12986}
12987
12988static void
c19d1205 12989do_t_sxtah (void)
b99bd4ef 12990{
fdfde340
JM
12991 unsigned Rd, Rn, Rm;
12992
12993 Rd = inst.operands[0].reg;
12994 Rn = inst.operands[1].reg;
12995 Rm = inst.operands[2].reg;
12996
12997 reject_bad_reg (Rd);
12998 reject_bad_reg (Rn);
12999 reject_bad_reg (Rm);
13000
13001 inst.instruction |= Rd << 8;
13002 inst.instruction |= Rn << 16;
13003 inst.instruction |= Rm;
c19d1205
ZW
13004 inst.instruction |= inst.operands[3].imm << 4;
13005}
b99bd4ef 13006
c19d1205
ZW
13007static void
13008do_t_sxth (void)
13009{
fdfde340
JM
13010 unsigned Rd, Rm;
13011
13012 Rd = inst.operands[0].reg;
13013 Rm = inst.operands[1].reg;
13014
13015 reject_bad_reg (Rd);
13016 reject_bad_reg (Rm);
c921be7d
NC
13017
13018 if (inst.instruction <= 0xffff
13019 && inst.size_req != 4
fdfde340 13020 && Rd <= 7 && Rm <= 7
c19d1205 13021 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13022 {
c19d1205 13023 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13024 inst.instruction |= Rd;
13025 inst.instruction |= Rm << 3;
b99bd4ef 13026 }
c19d1205 13027 else if (unified_syntax)
b99bd4ef 13028 {
c19d1205
ZW
13029 if (inst.instruction <= 0xffff)
13030 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13031 inst.instruction |= Rd << 8;
13032 inst.instruction |= Rm;
c19d1205 13033 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13034 }
c19d1205 13035 else
b99bd4ef 13036 {
c19d1205
ZW
13037 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13038 _("Thumb encoding does not support rotation"));
13039 constraint (1, BAD_HIREG);
b99bd4ef 13040 }
c19d1205 13041}
b99bd4ef 13042
c19d1205
ZW
13043static void
13044do_t_swi (void)
13045{
b2a5fbdc
MGD
13046 /* We have to do the following check manually as ARM_EXT_OS only applies
13047 to ARM_EXT_V6M. */
13048 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13049 {
ac7f631b
NC
13050 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13051 /* This only applies to the v6m howver, not later architectures. */
13052 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13053 as_bad (_("SVC is not permitted on this architecture"));
13054 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13055 }
13056
c19d1205
ZW
13057 inst.reloc.type = BFD_RELOC_ARM_SWI;
13058}
b99bd4ef 13059
92e90b6e
PB
13060static void
13061do_t_tb (void)
13062{
fdfde340 13063 unsigned Rn, Rm;
92e90b6e
PB
13064 int half;
13065
13066 half = (inst.instruction & 0x10) != 0;
e07e6e58 13067 set_it_insn_type_last ();
dfa9f0d5
PB
13068 constraint (inst.operands[0].immisreg,
13069 _("instruction requires register index"));
fdfde340
JM
13070
13071 Rn = inst.operands[0].reg;
13072 Rm = inst.operands[0].imm;
c921be7d 13073
fdfde340
JM
13074 constraint (Rn == REG_SP, BAD_SP);
13075 reject_bad_reg (Rm);
13076
92e90b6e
PB
13077 constraint (!half && inst.operands[0].shifted,
13078 _("instruction does not allow shifted index"));
fdfde340 13079 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13080}
13081
74db7efb
NC
13082static void
13083do_t_udf (void)
13084{
13085 if (!inst.operands[0].present)
13086 inst.operands[0].imm = 0;
13087
13088 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13089 {
13090 constraint (inst.size_req == 2,
13091 _("immediate value out of range"));
13092 inst.instruction = THUMB_OP32 (inst.instruction);
13093 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13094 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13095 }
13096 else
13097 {
13098 inst.instruction = THUMB_OP16 (inst.instruction);
13099 inst.instruction |= inst.operands[0].imm;
13100 }
13101
13102 set_it_insn_type (NEUTRAL_IT_INSN);
13103}
13104
13105
c19d1205
ZW
13106static void
13107do_t_usat (void)
13108{
3a21c15a 13109 do_t_ssat_usat (0);
b99bd4ef
NC
13110}
13111
13112static void
c19d1205 13113do_t_usat16 (void)
b99bd4ef 13114{
fdfde340
JM
13115 unsigned Rd, Rn;
13116
13117 Rd = inst.operands[0].reg;
13118 Rn = inst.operands[2].reg;
13119
13120 reject_bad_reg (Rd);
13121 reject_bad_reg (Rn);
13122
13123 inst.instruction |= Rd << 8;
c19d1205 13124 inst.instruction |= inst.operands[1].imm;
fdfde340 13125 inst.instruction |= Rn << 16;
b99bd4ef 13126}
c19d1205 13127
5287ad62 13128/* Neon instruction encoder helpers. */
5f4273c7 13129
5287ad62 13130/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13131
5287ad62
JB
13132/* An "invalid" code for the following tables. */
13133#define N_INV -1u
13134
13135struct neon_tab_entry
b99bd4ef 13136{
5287ad62
JB
13137 unsigned integer;
13138 unsigned float_or_poly;
13139 unsigned scalar_or_imm;
13140};
5f4273c7 13141
5287ad62
JB
13142/* Map overloaded Neon opcodes to their respective encodings. */
13143#define NEON_ENC_TAB \
13144 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13145 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13146 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13147 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13148 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13149 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13150 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13151 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13152 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13153 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13154 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13155 /* Register variants of the following two instructions are encoded as
e07e6e58 13156 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13157 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13158 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13159 X(vfma, N_INV, 0x0000c10, N_INV), \
13160 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13161 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13162 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13163 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13164 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13165 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13166 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13167 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13168 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13169 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13170 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13171 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13172 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13173 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13174 X(vshl, 0x0000400, N_INV, 0x0800510), \
13175 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13176 X(vand, 0x0000110, N_INV, 0x0800030), \
13177 X(vbic, 0x0100110, N_INV, 0x0800030), \
13178 X(veor, 0x1000110, N_INV, N_INV), \
13179 X(vorn, 0x0300110, N_INV, 0x0800010), \
13180 X(vorr, 0x0200110, N_INV, 0x0800010), \
13181 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13182 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13183 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13184 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13185 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13186 X(vst1, 0x0000000, 0x0800000, N_INV), \
13187 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13188 X(vst2, 0x0000100, 0x0800100, N_INV), \
13189 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13190 X(vst3, 0x0000200, 0x0800200, N_INV), \
13191 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13192 X(vst4, 0x0000300, 0x0800300, N_INV), \
13193 X(vmovn, 0x1b20200, N_INV, N_INV), \
13194 X(vtrn, 0x1b20080, N_INV, N_INV), \
13195 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13196 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13197 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13198 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13199 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13200 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13201 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13202 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13203 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13204 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13205 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13206 X(vseleq, 0xe000a00, N_INV, N_INV), \
13207 X(vselvs, 0xe100a00, N_INV, N_INV), \
13208 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13209 X(vselgt, 0xe300a00, N_INV, N_INV), \
13210 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13211 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13212 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13213 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13214 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13215 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13216 X(sha3op, 0x2000c00, N_INV, N_INV), \
13217 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13218 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13219
13220enum neon_opc
13221{
13222#define X(OPC,I,F,S) N_MNEM_##OPC
13223NEON_ENC_TAB
13224#undef X
13225};
b99bd4ef 13226
5287ad62
JB
13227static const struct neon_tab_entry neon_enc_tab[] =
13228{
13229#define X(OPC,I,F,S) { (I), (F), (S) }
13230NEON_ENC_TAB
13231#undef X
13232};
b99bd4ef 13233
88714cb8
DG
13234/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13235#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13236#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13237#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13238#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13239#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13240#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13241#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13242#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13243#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13244#define NEON_ENC_SINGLE_(X) \
037e8744 13245 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13246#define NEON_ENC_DOUBLE_(X) \
037e8744 13247 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13248#define NEON_ENC_FPV8_(X) \
13249 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13250
88714cb8
DG
13251#define NEON_ENCODE(type, inst) \
13252 do \
13253 { \
13254 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13255 inst.is_neon = 1; \
13256 } \
13257 while (0)
13258
13259#define check_neon_suffixes \
13260 do \
13261 { \
13262 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13263 { \
13264 as_bad (_("invalid neon suffix for non neon instruction")); \
13265 return; \
13266 } \
13267 } \
13268 while (0)
13269
037e8744
JB
13270/* Define shapes for instruction operands. The following mnemonic characters
13271 are used in this table:
5287ad62 13272
037e8744 13273 F - VFP S<n> register
5287ad62
JB
13274 D - Neon D<n> register
13275 Q - Neon Q<n> register
13276 I - Immediate
13277 S - Scalar
13278 R - ARM register
13279 L - D<n> register list
5f4273c7 13280
037e8744
JB
13281 This table is used to generate various data:
13282 - enumerations of the form NS_DDR to be used as arguments to
13283 neon_select_shape.
13284 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13285 - a table used to drive neon_select_shape. */
b99bd4ef 13286
037e8744
JB
13287#define NEON_SHAPE_DEF \
13288 X(3, (D, D, D), DOUBLE), \
13289 X(3, (Q, Q, Q), QUAD), \
13290 X(3, (D, D, I), DOUBLE), \
13291 X(3, (Q, Q, I), QUAD), \
13292 X(3, (D, D, S), DOUBLE), \
13293 X(3, (Q, Q, S), QUAD), \
13294 X(2, (D, D), DOUBLE), \
13295 X(2, (Q, Q), QUAD), \
13296 X(2, (D, S), DOUBLE), \
13297 X(2, (Q, S), QUAD), \
13298 X(2, (D, R), DOUBLE), \
13299 X(2, (Q, R), QUAD), \
13300 X(2, (D, I), DOUBLE), \
13301 X(2, (Q, I), QUAD), \
13302 X(3, (D, L, D), DOUBLE), \
13303 X(2, (D, Q), MIXED), \
13304 X(2, (Q, D), MIXED), \
13305 X(3, (D, Q, I), MIXED), \
13306 X(3, (Q, D, I), MIXED), \
13307 X(3, (Q, D, D), MIXED), \
13308 X(3, (D, Q, Q), MIXED), \
13309 X(3, (Q, Q, D), MIXED), \
13310 X(3, (Q, D, S), MIXED), \
13311 X(3, (D, Q, S), MIXED), \
13312 X(4, (D, D, D, I), DOUBLE), \
13313 X(4, (Q, Q, Q, I), QUAD), \
13314 X(2, (F, F), SINGLE), \
13315 X(3, (F, F, F), SINGLE), \
13316 X(2, (F, I), SINGLE), \
13317 X(2, (F, D), MIXED), \
13318 X(2, (D, F), MIXED), \
13319 X(3, (F, F, I), MIXED), \
13320 X(4, (R, R, F, F), SINGLE), \
13321 X(4, (F, F, R, R), SINGLE), \
13322 X(3, (D, R, R), DOUBLE), \
13323 X(3, (R, R, D), DOUBLE), \
13324 X(2, (S, R), SINGLE), \
13325 X(2, (R, S), SINGLE), \
13326 X(2, (F, R), SINGLE), \
d54af2d0
RL
13327 X(2, (R, F), SINGLE), \
13328/* Half float shape supported so far. */\
13329 X (2, (H, D), MIXED), \
13330 X (2, (D, H), MIXED), \
13331 X (2, (H, F), MIXED), \
13332 X (2, (F, H), MIXED), \
13333 X (2, (H, H), HALF), \
13334 X (2, (H, R), HALF), \
13335 X (2, (R, H), HALF), \
13336 X (2, (H, I), HALF), \
13337 X (3, (H, H, H), HALF), \
13338 X (3, (H, F, I), MIXED), \
13339 X (3, (F, H, I), MIXED)
037e8744
JB
13340
13341#define S2(A,B) NS_##A##B
13342#define S3(A,B,C) NS_##A##B##C
13343#define S4(A,B,C,D) NS_##A##B##C##D
13344
13345#define X(N, L, C) S##N L
13346
5287ad62
JB
13347enum neon_shape
13348{
037e8744
JB
13349 NEON_SHAPE_DEF,
13350 NS_NULL
5287ad62 13351};
b99bd4ef 13352
037e8744
JB
13353#undef X
13354#undef S2
13355#undef S3
13356#undef S4
13357
13358enum neon_shape_class
13359{
d54af2d0 13360 SC_HALF,
037e8744
JB
13361 SC_SINGLE,
13362 SC_DOUBLE,
13363 SC_QUAD,
13364 SC_MIXED
13365};
13366
13367#define X(N, L, C) SC_##C
13368
13369static enum neon_shape_class neon_shape_class[] =
13370{
13371 NEON_SHAPE_DEF
13372};
13373
13374#undef X
13375
13376enum neon_shape_el
13377{
d54af2d0 13378 SE_H,
037e8744
JB
13379 SE_F,
13380 SE_D,
13381 SE_Q,
13382 SE_I,
13383 SE_S,
13384 SE_R,
13385 SE_L
13386};
13387
13388/* Register widths of above. */
13389static unsigned neon_shape_el_size[] =
13390{
d54af2d0 13391 16,
037e8744
JB
13392 32,
13393 64,
13394 128,
13395 0,
13396 32,
13397 32,
13398 0
13399};
13400
13401struct neon_shape_info
13402{
13403 unsigned els;
13404 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13405};
13406
13407#define S2(A,B) { SE_##A, SE_##B }
13408#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13409#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13410
13411#define X(N, L, C) { N, S##N L }
13412
13413static struct neon_shape_info neon_shape_tab[] =
13414{
13415 NEON_SHAPE_DEF
13416};
13417
13418#undef X
13419#undef S2
13420#undef S3
13421#undef S4
13422
5287ad62
JB
13423/* Bit masks used in type checking given instructions.
13424 'N_EQK' means the type must be the same as (or based on in some way) the key
13425 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13426 set, various other bits can be set as well in order to modify the meaning of
13427 the type constraint. */
13428
13429enum neon_type_mask
13430{
8e79c3df
CM
13431 N_S8 = 0x0000001,
13432 N_S16 = 0x0000002,
13433 N_S32 = 0x0000004,
13434 N_S64 = 0x0000008,
13435 N_U8 = 0x0000010,
13436 N_U16 = 0x0000020,
13437 N_U32 = 0x0000040,
13438 N_U64 = 0x0000080,
13439 N_I8 = 0x0000100,
13440 N_I16 = 0x0000200,
13441 N_I32 = 0x0000400,
13442 N_I64 = 0x0000800,
13443 N_8 = 0x0001000,
13444 N_16 = 0x0002000,
13445 N_32 = 0x0004000,
13446 N_64 = 0x0008000,
13447 N_P8 = 0x0010000,
13448 N_P16 = 0x0020000,
13449 N_F16 = 0x0040000,
13450 N_F32 = 0x0080000,
13451 N_F64 = 0x0100000,
4f51b4bd 13452 N_P64 = 0x0200000,
c921be7d
NC
13453 N_KEY = 0x1000000, /* Key element (main type specifier). */
13454 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13455 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13456 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13457 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13458 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13459 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13460 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13461 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13462 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13463 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13464 N_UTYP = 0,
4f51b4bd 13465 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13466};
13467
dcbf9037
JB
13468#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13469
5287ad62
JB
13470#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13471#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13472#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13473#define N_S_32 (N_S8 | N_S16 | N_S32)
13474#define N_F_16_32 (N_F16 | N_F32)
13475#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13476#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13477#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13478#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13479
13480/* Pass this as the first type argument to neon_check_type to ignore types
13481 altogether. */
13482#define N_IGNORE_TYPE (N_KEY | N_EQK)
13483
037e8744
JB
13484/* Select a "shape" for the current instruction (describing register types or
13485 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13486 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13487 function of operand parsing, so this function doesn't need to be called.
13488 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13489
13490static enum neon_shape
037e8744 13491neon_select_shape (enum neon_shape shape, ...)
5287ad62 13492{
037e8744
JB
13493 va_list ap;
13494 enum neon_shape first_shape = shape;
5287ad62
JB
13495
13496 /* Fix missing optional operands. FIXME: we don't know at this point how
13497 many arguments we should have, so this makes the assumption that we have
13498 > 1. This is true of all current Neon opcodes, I think, but may not be
13499 true in the future. */
13500 if (!inst.operands[1].present)
13501 inst.operands[1] = inst.operands[0];
13502
037e8744 13503 va_start (ap, shape);
5f4273c7 13504
21d799b5 13505 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13506 {
13507 unsigned j;
13508 int matches = 1;
13509
13510 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13511 {
13512 if (!inst.operands[j].present)
13513 {
13514 matches = 0;
13515 break;
13516 }
13517
13518 switch (neon_shape_tab[shape].el[j])
13519 {
d54af2d0
RL
13520 /* If a .f16, .16, .u16, .s16 type specifier is given over
13521 a VFP single precision register operand, it's essentially
13522 means only half of the register is used.
13523
13524 If the type specifier is given after the mnemonics, the
13525 information is stored in inst.vectype. If the type specifier
13526 is given after register operand, the information is stored
13527 in inst.operands[].vectype.
13528
13529 When there is only one type specifier, and all the register
13530 operands are the same type of hardware register, the type
13531 specifier applies to all register operands.
13532
13533 If no type specifier is given, the shape is inferred from
13534 operand information.
13535
13536 for example:
13537 vadd.f16 s0, s1, s2: NS_HHH
13538 vabs.f16 s0, s1: NS_HH
13539 vmov.f16 s0, r1: NS_HR
13540 vmov.f16 r0, s1: NS_RH
13541 vcvt.f16 r0, s1: NS_RH
13542 vcvt.f16.s32 s2, s2, #29: NS_HFI
13543 vcvt.f16.s32 s2, s2: NS_HF
13544 */
13545 case SE_H:
13546 if (!(inst.operands[j].isreg
13547 && inst.operands[j].isvec
13548 && inst.operands[j].issingle
13549 && !inst.operands[j].isquad
13550 && ((inst.vectype.elems == 1
13551 && inst.vectype.el[0].size == 16)
13552 || (inst.vectype.elems > 1
13553 && inst.vectype.el[j].size == 16)
13554 || (inst.vectype.elems == 0
13555 && inst.operands[j].vectype.type != NT_invtype
13556 && inst.operands[j].vectype.size == 16))))
13557 matches = 0;
13558 break;
13559
477330fc
RM
13560 case SE_F:
13561 if (!(inst.operands[j].isreg
13562 && inst.operands[j].isvec
13563 && inst.operands[j].issingle
d54af2d0
RL
13564 && !inst.operands[j].isquad
13565 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13566 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13567 || (inst.vectype.elems == 0
13568 && (inst.operands[j].vectype.size == 32
13569 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13570 matches = 0;
13571 break;
13572
13573 case SE_D:
13574 if (!(inst.operands[j].isreg
13575 && inst.operands[j].isvec
13576 && !inst.operands[j].isquad
13577 && !inst.operands[j].issingle))
13578 matches = 0;
13579 break;
13580
13581 case SE_R:
13582 if (!(inst.operands[j].isreg
13583 && !inst.operands[j].isvec))
13584 matches = 0;
13585 break;
13586
13587 case SE_Q:
13588 if (!(inst.operands[j].isreg
13589 && inst.operands[j].isvec
13590 && inst.operands[j].isquad
13591 && !inst.operands[j].issingle))
13592 matches = 0;
13593 break;
13594
13595 case SE_I:
13596 if (!(!inst.operands[j].isreg
13597 && !inst.operands[j].isscalar))
13598 matches = 0;
13599 break;
13600
13601 case SE_S:
13602 if (!(!inst.operands[j].isreg
13603 && inst.operands[j].isscalar))
13604 matches = 0;
13605 break;
13606
13607 case SE_L:
13608 break;
13609 }
3fde54a2
JZ
13610 if (!matches)
13611 break;
477330fc 13612 }
ad6cec43
MGD
13613 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13614 /* We've matched all the entries in the shape table, and we don't
13615 have any left over operands which have not been matched. */
477330fc 13616 break;
037e8744 13617 }
5f4273c7 13618
037e8744 13619 va_end (ap);
5287ad62 13620
037e8744
JB
13621 if (shape == NS_NULL && first_shape != NS_NULL)
13622 first_error (_("invalid instruction shape"));
5287ad62 13623
037e8744
JB
13624 return shape;
13625}
5287ad62 13626
037e8744
JB
13627/* True if SHAPE is predominantly a quadword operation (most of the time, this
13628 means the Q bit should be set). */
13629
13630static int
13631neon_quad (enum neon_shape shape)
13632{
13633 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13634}
037e8744 13635
5287ad62
JB
13636static void
13637neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13638 unsigned *g_size)
5287ad62
JB
13639{
13640 /* Allow modification to be made to types which are constrained to be
13641 based on the key element, based on bits set alongside N_EQK. */
13642 if ((typebits & N_EQK) != 0)
13643 {
13644 if ((typebits & N_HLF) != 0)
13645 *g_size /= 2;
13646 else if ((typebits & N_DBL) != 0)
13647 *g_size *= 2;
13648 if ((typebits & N_SGN) != 0)
13649 *g_type = NT_signed;
13650 else if ((typebits & N_UNS) != 0)
477330fc 13651 *g_type = NT_unsigned;
5287ad62 13652 else if ((typebits & N_INT) != 0)
477330fc 13653 *g_type = NT_integer;
5287ad62 13654 else if ((typebits & N_FLT) != 0)
477330fc 13655 *g_type = NT_float;
dcbf9037 13656 else if ((typebits & N_SIZ) != 0)
477330fc 13657 *g_type = NT_untyped;
5287ad62
JB
13658 }
13659}
5f4273c7 13660
5287ad62
JB
13661/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13662 operand type, i.e. the single type specified in a Neon instruction when it
13663 is the only one given. */
13664
13665static struct neon_type_el
13666neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13667{
13668 struct neon_type_el dest = *key;
5f4273c7 13669
9c2799c2 13670 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13671
5287ad62
JB
13672 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13673
13674 return dest;
13675}
13676
13677/* Convert Neon type and size into compact bitmask representation. */
13678
13679static enum neon_type_mask
13680type_chk_of_el_type (enum neon_el_type type, unsigned size)
13681{
13682 switch (type)
13683 {
13684 case NT_untyped:
13685 switch (size)
477330fc
RM
13686 {
13687 case 8: return N_8;
13688 case 16: return N_16;
13689 case 32: return N_32;
13690 case 64: return N_64;
13691 default: ;
13692 }
5287ad62
JB
13693 break;
13694
13695 case NT_integer:
13696 switch (size)
477330fc
RM
13697 {
13698 case 8: return N_I8;
13699 case 16: return N_I16;
13700 case 32: return N_I32;
13701 case 64: return N_I64;
13702 default: ;
13703 }
5287ad62
JB
13704 break;
13705
13706 case NT_float:
037e8744 13707 switch (size)
477330fc 13708 {
8e79c3df 13709 case 16: return N_F16;
477330fc
RM
13710 case 32: return N_F32;
13711 case 64: return N_F64;
13712 default: ;
13713 }
5287ad62
JB
13714 break;
13715
13716 case NT_poly:
13717 switch (size)
477330fc
RM
13718 {
13719 case 8: return N_P8;
13720 case 16: return N_P16;
4f51b4bd 13721 case 64: return N_P64;
477330fc
RM
13722 default: ;
13723 }
5287ad62
JB
13724 break;
13725
13726 case NT_signed:
13727 switch (size)
477330fc
RM
13728 {
13729 case 8: return N_S8;
13730 case 16: return N_S16;
13731 case 32: return N_S32;
13732 case 64: return N_S64;
13733 default: ;
13734 }
5287ad62
JB
13735 break;
13736
13737 case NT_unsigned:
13738 switch (size)
477330fc
RM
13739 {
13740 case 8: return N_U8;
13741 case 16: return N_U16;
13742 case 32: return N_U32;
13743 case 64: return N_U64;
13744 default: ;
13745 }
5287ad62
JB
13746 break;
13747
13748 default: ;
13749 }
5f4273c7 13750
5287ad62
JB
13751 return N_UTYP;
13752}
13753
13754/* Convert compact Neon bitmask type representation to a type and size. Only
13755 handles the case where a single bit is set in the mask. */
13756
dcbf9037 13757static int
5287ad62 13758el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13759 enum neon_type_mask mask)
5287ad62 13760{
dcbf9037
JB
13761 if ((mask & N_EQK) != 0)
13762 return FAIL;
13763
5287ad62
JB
13764 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13765 *size = 8;
c70a8987 13766 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13767 *size = 16;
dcbf9037 13768 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13769 *size = 32;
4f51b4bd 13770 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13771 *size = 64;
dcbf9037
JB
13772 else
13773 return FAIL;
13774
5287ad62
JB
13775 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13776 *type = NT_signed;
dcbf9037 13777 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13778 *type = NT_unsigned;
dcbf9037 13779 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13780 *type = NT_integer;
dcbf9037 13781 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13782 *type = NT_untyped;
4f51b4bd 13783 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13784 *type = NT_poly;
d54af2d0 13785 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13786 *type = NT_float;
dcbf9037
JB
13787 else
13788 return FAIL;
5f4273c7 13789
dcbf9037 13790 return SUCCESS;
5287ad62
JB
13791}
13792
13793/* Modify a bitmask of allowed types. This is only needed for type
13794 relaxation. */
13795
13796static unsigned
13797modify_types_allowed (unsigned allowed, unsigned mods)
13798{
13799 unsigned size;
13800 enum neon_el_type type;
13801 unsigned destmask;
13802 int i;
5f4273c7 13803
5287ad62 13804 destmask = 0;
5f4273c7 13805
5287ad62
JB
13806 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13807 {
21d799b5 13808 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13809 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13810 {
13811 neon_modify_type_size (mods, &type, &size);
13812 destmask |= type_chk_of_el_type (type, size);
13813 }
5287ad62 13814 }
5f4273c7 13815
5287ad62
JB
13816 return destmask;
13817}
13818
13819/* Check type and return type classification.
13820 The manual states (paraphrase): If one datatype is given, it indicates the
13821 type given in:
13822 - the second operand, if there is one
13823 - the operand, if there is no second operand
13824 - the result, if there are no operands.
13825 This isn't quite good enough though, so we use a concept of a "key" datatype
13826 which is set on a per-instruction basis, which is the one which matters when
13827 only one data type is written.
13828 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13829 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13830
13831static struct neon_type_el
13832neon_check_type (unsigned els, enum neon_shape ns, ...)
13833{
13834 va_list ap;
13835 unsigned i, pass, key_el = 0;
13836 unsigned types[NEON_MAX_TYPE_ELS];
13837 enum neon_el_type k_type = NT_invtype;
13838 unsigned k_size = -1u;
13839 struct neon_type_el badtype = {NT_invtype, -1};
13840 unsigned key_allowed = 0;
13841
13842 /* Optional registers in Neon instructions are always (not) in operand 1.
13843 Fill in the missing operand here, if it was omitted. */
13844 if (els > 1 && !inst.operands[1].present)
13845 inst.operands[1] = inst.operands[0];
13846
13847 /* Suck up all the varargs. */
13848 va_start (ap, ns);
13849 for (i = 0; i < els; i++)
13850 {
13851 unsigned thisarg = va_arg (ap, unsigned);
13852 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13853 {
13854 va_end (ap);
13855 return badtype;
13856 }
5287ad62
JB
13857 types[i] = thisarg;
13858 if ((thisarg & N_KEY) != 0)
477330fc 13859 key_el = i;
5287ad62
JB
13860 }
13861 va_end (ap);
13862
dcbf9037
JB
13863 if (inst.vectype.elems > 0)
13864 for (i = 0; i < els; i++)
13865 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13866 {
13867 first_error (_("types specified in both the mnemonic and operands"));
13868 return badtype;
13869 }
dcbf9037 13870
5287ad62
JB
13871 /* Duplicate inst.vectype elements here as necessary.
13872 FIXME: No idea if this is exactly the same as the ARM assembler,
13873 particularly when an insn takes one register and one non-register
13874 operand. */
13875 if (inst.vectype.elems == 1 && els > 1)
13876 {
13877 unsigned j;
13878 inst.vectype.elems = els;
13879 inst.vectype.el[key_el] = inst.vectype.el[0];
13880 for (j = 0; j < els; j++)
477330fc
RM
13881 if (j != key_el)
13882 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13883 types[j]);
dcbf9037
JB
13884 }
13885 else if (inst.vectype.elems == 0 && els > 0)
13886 {
13887 unsigned j;
13888 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13889 after each operand. We allow some flexibility here; as long as the
13890 "key" operand has a type, we can infer the others. */
dcbf9037 13891 for (j = 0; j < els; j++)
477330fc
RM
13892 if (inst.operands[j].vectype.type != NT_invtype)
13893 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13894
13895 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13896 {
13897 for (j = 0; j < els; j++)
13898 if (inst.operands[j].vectype.type == NT_invtype)
13899 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13900 types[j]);
13901 }
dcbf9037 13902 else
477330fc
RM
13903 {
13904 first_error (_("operand types can't be inferred"));
13905 return badtype;
13906 }
5287ad62
JB
13907 }
13908 else if (inst.vectype.elems != els)
13909 {
dcbf9037 13910 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13911 return badtype;
13912 }
13913
13914 for (pass = 0; pass < 2; pass++)
13915 {
13916 for (i = 0; i < els; i++)
477330fc
RM
13917 {
13918 unsigned thisarg = types[i];
13919 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13920 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13921 enum neon_el_type g_type = inst.vectype.el[i].type;
13922 unsigned g_size = inst.vectype.el[i].size;
13923
13924 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13925 integer types if sign-specific variants are unavailable. */
477330fc 13926 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13927 && (types_allowed & N_SU_ALL) == 0)
13928 g_type = NT_integer;
13929
477330fc 13930 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13931 them. Some instructions only care about signs for some element
13932 sizes, so handle that properly. */
477330fc 13933 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13934 && ((g_size == 8 && (types_allowed & N_8) != 0)
13935 || (g_size == 16 && (types_allowed & N_16) != 0)
13936 || (g_size == 32 && (types_allowed & N_32) != 0)
13937 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13938 g_type = NT_untyped;
13939
477330fc
RM
13940 if (pass == 0)
13941 {
13942 if ((thisarg & N_KEY) != 0)
13943 {
13944 k_type = g_type;
13945 k_size = g_size;
13946 key_allowed = thisarg & ~N_KEY;
cc933301
JW
13947
13948 /* Check architecture constraint on FP16 extension. */
13949 if (k_size == 16
13950 && k_type == NT_float
13951 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13952 {
13953 inst.error = _(BAD_FP16);
13954 return badtype;
13955 }
477330fc
RM
13956 }
13957 }
13958 else
13959 {
13960 if ((thisarg & N_VFP) != 0)
13961 {
13962 enum neon_shape_el regshape;
13963 unsigned regwidth, match;
99b253c5
NC
13964
13965 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13966 if (ns == NS_NULL)
13967 {
13968 first_error (_("invalid instruction shape"));
13969 return badtype;
13970 }
477330fc
RM
13971 regshape = neon_shape_tab[ns].el[i];
13972 regwidth = neon_shape_el_size[regshape];
13973
13974 /* In VFP mode, operands must match register widths. If we
13975 have a key operand, use its width, else use the width of
13976 the current operand. */
13977 if (k_size != -1u)
13978 match = k_size;
13979 else
13980 match = g_size;
13981
9db2f6b4
RL
13982 /* FP16 will use a single precision register. */
13983 if (regwidth == 32 && match == 16)
13984 {
13985 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13986 match = regwidth;
13987 else
13988 {
13989 inst.error = _(BAD_FP16);
13990 return badtype;
13991 }
13992 }
13993
477330fc
RM
13994 if (regwidth != match)
13995 {
13996 first_error (_("operand size must match register width"));
13997 return badtype;
13998 }
13999 }
14000
14001 if ((thisarg & N_EQK) == 0)
14002 {
14003 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14004
14005 if ((given_type & types_allowed) == 0)
14006 {
14007 first_error (_("bad type in Neon instruction"));
14008 return badtype;
14009 }
14010 }
14011 else
14012 {
14013 enum neon_el_type mod_k_type = k_type;
14014 unsigned mod_k_size = k_size;
14015 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14016 if (g_type != mod_k_type || g_size != mod_k_size)
14017 {
14018 first_error (_("inconsistent types in Neon instruction"));
14019 return badtype;
14020 }
14021 }
14022 }
14023 }
5287ad62
JB
14024 }
14025
14026 return inst.vectype.el[key_el];
14027}
14028
037e8744 14029/* Neon-style VFP instruction forwarding. */
5287ad62 14030
037e8744
JB
14031/* Thumb VFP instructions have 0xE in the condition field. */
14032
14033static void
14034do_vfp_cond_or_thumb (void)
5287ad62 14035{
88714cb8
DG
14036 inst.is_neon = 1;
14037
5287ad62 14038 if (thumb_mode)
037e8744 14039 inst.instruction |= 0xe0000000;
5287ad62 14040 else
037e8744 14041 inst.instruction |= inst.cond << 28;
5287ad62
JB
14042}
14043
037e8744
JB
14044/* Look up and encode a simple mnemonic, for use as a helper function for the
14045 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14046 etc. It is assumed that operand parsing has already been done, and that the
14047 operands are in the form expected by the given opcode (this isn't necessarily
14048 the same as the form in which they were parsed, hence some massaging must
14049 take place before this function is called).
14050 Checks current arch version against that in the looked-up opcode. */
5287ad62 14051
037e8744
JB
14052static void
14053do_vfp_nsyn_opcode (const char *opname)
5287ad62 14054{
037e8744 14055 const struct asm_opcode *opcode;
5f4273c7 14056
21d799b5 14057 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14058
037e8744
JB
14059 if (!opcode)
14060 abort ();
5287ad62 14061
037e8744 14062 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14063 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14064 _(BAD_FPU));
5287ad62 14065
88714cb8
DG
14066 inst.is_neon = 1;
14067
037e8744
JB
14068 if (thumb_mode)
14069 {
14070 inst.instruction = opcode->tvalue;
14071 opcode->tencode ();
14072 }
14073 else
14074 {
14075 inst.instruction = (inst.cond << 28) | opcode->avalue;
14076 opcode->aencode ();
14077 }
14078}
5287ad62
JB
14079
14080static void
037e8744 14081do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14082{
037e8744
JB
14083 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14084
9db2f6b4 14085 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14086 {
14087 if (is_add)
477330fc 14088 do_vfp_nsyn_opcode ("fadds");
037e8744 14089 else
477330fc 14090 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14091
14092 /* ARMv8.2 fp16 instruction. */
14093 if (rs == NS_HHH)
14094 do_scalar_fp16_v82_encode ();
037e8744
JB
14095 }
14096 else
14097 {
14098 if (is_add)
477330fc 14099 do_vfp_nsyn_opcode ("faddd");
037e8744 14100 else
477330fc 14101 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14102 }
14103}
14104
14105/* Check operand types to see if this is a VFP instruction, and if so call
14106 PFN (). */
14107
14108static int
14109try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14110{
14111 enum neon_shape rs;
14112 struct neon_type_el et;
14113
14114 switch (args)
14115 {
14116 case 2:
9db2f6b4
RL
14117 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14118 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14119 break;
5f4273c7 14120
037e8744 14121 case 3:
9db2f6b4
RL
14122 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14123 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14124 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14125 break;
14126
14127 default:
14128 abort ();
14129 }
14130
14131 if (et.type != NT_invtype)
14132 {
14133 pfn (rs);
14134 return SUCCESS;
14135 }
037e8744 14136
99b253c5 14137 inst.error = NULL;
037e8744
JB
14138 return FAIL;
14139}
14140
14141static void
14142do_vfp_nsyn_mla_mls (enum neon_shape rs)
14143{
14144 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14145
9db2f6b4 14146 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14147 {
14148 if (is_mla)
477330fc 14149 do_vfp_nsyn_opcode ("fmacs");
037e8744 14150 else
477330fc 14151 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14152
14153 /* ARMv8.2 fp16 instruction. */
14154 if (rs == NS_HHH)
14155 do_scalar_fp16_v82_encode ();
037e8744
JB
14156 }
14157 else
14158 {
14159 if (is_mla)
477330fc 14160 do_vfp_nsyn_opcode ("fmacd");
037e8744 14161 else
477330fc 14162 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14163 }
14164}
14165
62f3b8c8
PB
14166static void
14167do_vfp_nsyn_fma_fms (enum neon_shape rs)
14168{
14169 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14170
9db2f6b4 14171 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14172 {
14173 if (is_fma)
477330fc 14174 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14175 else
477330fc 14176 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14177
14178 /* ARMv8.2 fp16 instruction. */
14179 if (rs == NS_HHH)
14180 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14181 }
14182 else
14183 {
14184 if (is_fma)
477330fc 14185 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14186 else
477330fc 14187 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14188 }
14189}
14190
037e8744
JB
14191static void
14192do_vfp_nsyn_mul (enum neon_shape rs)
14193{
9db2f6b4
RL
14194 if (rs == NS_FFF || rs == NS_HHH)
14195 {
14196 do_vfp_nsyn_opcode ("fmuls");
14197
14198 /* ARMv8.2 fp16 instruction. */
14199 if (rs == NS_HHH)
14200 do_scalar_fp16_v82_encode ();
14201 }
037e8744
JB
14202 else
14203 do_vfp_nsyn_opcode ("fmuld");
14204}
14205
14206static void
14207do_vfp_nsyn_abs_neg (enum neon_shape rs)
14208{
14209 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14210 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14211
9db2f6b4 14212 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14213 {
14214 if (is_neg)
477330fc 14215 do_vfp_nsyn_opcode ("fnegs");
037e8744 14216 else
477330fc 14217 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14218
14219 /* ARMv8.2 fp16 instruction. */
14220 if (rs == NS_HH)
14221 do_scalar_fp16_v82_encode ();
037e8744
JB
14222 }
14223 else
14224 {
14225 if (is_neg)
477330fc 14226 do_vfp_nsyn_opcode ("fnegd");
037e8744 14227 else
477330fc 14228 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14229 }
14230}
14231
14232/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14233 insns belong to Neon, and are handled elsewhere. */
14234
14235static void
14236do_vfp_nsyn_ldm_stm (int is_dbmode)
14237{
14238 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14239 if (is_ldm)
14240 {
14241 if (is_dbmode)
477330fc 14242 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14243 else
477330fc 14244 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14245 }
14246 else
14247 {
14248 if (is_dbmode)
477330fc 14249 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14250 else
477330fc 14251 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14252 }
14253}
14254
037e8744
JB
14255static void
14256do_vfp_nsyn_sqrt (void)
14257{
9db2f6b4
RL
14258 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14259 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14260
9db2f6b4
RL
14261 if (rs == NS_FF || rs == NS_HH)
14262 {
14263 do_vfp_nsyn_opcode ("fsqrts");
14264
14265 /* ARMv8.2 fp16 instruction. */
14266 if (rs == NS_HH)
14267 do_scalar_fp16_v82_encode ();
14268 }
037e8744
JB
14269 else
14270 do_vfp_nsyn_opcode ("fsqrtd");
14271}
14272
14273static void
14274do_vfp_nsyn_div (void)
14275{
9db2f6b4 14276 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14277 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14278 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14279
9db2f6b4
RL
14280 if (rs == NS_FFF || rs == NS_HHH)
14281 {
14282 do_vfp_nsyn_opcode ("fdivs");
14283
14284 /* ARMv8.2 fp16 instruction. */
14285 if (rs == NS_HHH)
14286 do_scalar_fp16_v82_encode ();
14287 }
037e8744
JB
14288 else
14289 do_vfp_nsyn_opcode ("fdivd");
14290}
14291
14292static void
14293do_vfp_nsyn_nmul (void)
14294{
9db2f6b4 14295 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14296 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14297 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14298
9db2f6b4 14299 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14300 {
88714cb8 14301 NEON_ENCODE (SINGLE, inst);
037e8744 14302 do_vfp_sp_dyadic ();
9db2f6b4
RL
14303
14304 /* ARMv8.2 fp16 instruction. */
14305 if (rs == NS_HHH)
14306 do_scalar_fp16_v82_encode ();
037e8744
JB
14307 }
14308 else
14309 {
88714cb8 14310 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14311 do_vfp_dp_rd_rn_rm ();
14312 }
14313 do_vfp_cond_or_thumb ();
9db2f6b4 14314
037e8744
JB
14315}
14316
14317static void
14318do_vfp_nsyn_cmp (void)
14319{
9db2f6b4 14320 enum neon_shape rs;
037e8744
JB
14321 if (inst.operands[1].isreg)
14322 {
9db2f6b4
RL
14323 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14324 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14325
9db2f6b4 14326 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14327 {
14328 NEON_ENCODE (SINGLE, inst);
14329 do_vfp_sp_monadic ();
14330 }
037e8744 14331 else
477330fc
RM
14332 {
14333 NEON_ENCODE (DOUBLE, inst);
14334 do_vfp_dp_rd_rm ();
14335 }
037e8744
JB
14336 }
14337 else
14338 {
9db2f6b4
RL
14339 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14340 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14341
14342 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14343 {
14344 case N_MNEM_vcmp:
14345 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14346 break;
14347 case N_MNEM_vcmpe:
14348 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14349 break;
14350 default:
14351 abort ();
14352 }
5f4273c7 14353
9db2f6b4 14354 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14355 {
14356 NEON_ENCODE (SINGLE, inst);
14357 do_vfp_sp_compare_z ();
14358 }
037e8744 14359 else
477330fc
RM
14360 {
14361 NEON_ENCODE (DOUBLE, inst);
14362 do_vfp_dp_rd ();
14363 }
037e8744
JB
14364 }
14365 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14366
14367 /* ARMv8.2 fp16 instruction. */
14368 if (rs == NS_HI || rs == NS_HH)
14369 do_scalar_fp16_v82_encode ();
037e8744
JB
14370}
14371
14372static void
14373nsyn_insert_sp (void)
14374{
14375 inst.operands[1] = inst.operands[0];
14376 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14377 inst.operands[0].reg = REG_SP;
037e8744
JB
14378 inst.operands[0].isreg = 1;
14379 inst.operands[0].writeback = 1;
14380 inst.operands[0].present = 1;
14381}
14382
14383static void
14384do_vfp_nsyn_push (void)
14385{
14386 nsyn_insert_sp ();
14387 if (inst.operands[1].issingle)
14388 do_vfp_nsyn_opcode ("fstmdbs");
14389 else
14390 do_vfp_nsyn_opcode ("fstmdbd");
14391}
14392
14393static void
14394do_vfp_nsyn_pop (void)
14395{
14396 nsyn_insert_sp ();
14397 if (inst.operands[1].issingle)
22b5b651 14398 do_vfp_nsyn_opcode ("fldmias");
037e8744 14399 else
22b5b651 14400 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14401}
14402
14403/* Fix up Neon data-processing instructions, ORing in the correct bits for
14404 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14405
88714cb8
DG
14406static void
14407neon_dp_fixup (struct arm_it* insn)
037e8744 14408{
88714cb8
DG
14409 unsigned int i = insn->instruction;
14410 insn->is_neon = 1;
14411
037e8744
JB
14412 if (thumb_mode)
14413 {
14414 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14415 if (i & (1 << 24))
477330fc 14416 i |= 1 << 28;
5f4273c7 14417
037e8744 14418 i &= ~(1 << 24);
5f4273c7 14419
037e8744
JB
14420 i |= 0xef000000;
14421 }
14422 else
14423 i |= 0xf2000000;
5f4273c7 14424
88714cb8 14425 insn->instruction = i;
037e8744
JB
14426}
14427
14428/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14429 (0, 1, 2, 3). */
14430
14431static unsigned
14432neon_logbits (unsigned x)
14433{
14434 return ffs (x) - 4;
14435}
14436
14437#define LOW4(R) ((R) & 0xf)
14438#define HI1(R) (((R) >> 4) & 1)
14439
14440/* Encode insns with bit pattern:
14441
14442 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14443 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14444
037e8744
JB
14445 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14446 different meaning for some instruction. */
14447
14448static void
14449neon_three_same (int isquad, int ubit, int size)
14450{
14451 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14452 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14453 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14454 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14455 inst.instruction |= LOW4 (inst.operands[2].reg);
14456 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14457 inst.instruction |= (isquad != 0) << 6;
14458 inst.instruction |= (ubit != 0) << 24;
14459 if (size != -1)
14460 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14461
88714cb8 14462 neon_dp_fixup (&inst);
037e8744
JB
14463}
14464
14465/* Encode instructions of the form:
14466
14467 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14468 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14469
14470 Don't write size if SIZE == -1. */
14471
14472static void
14473neon_two_same (int qbit, int ubit, int size)
14474{
14475 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14476 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14477 inst.instruction |= LOW4 (inst.operands[1].reg);
14478 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14479 inst.instruction |= (qbit != 0) << 6;
14480 inst.instruction |= (ubit != 0) << 24;
14481
14482 if (size != -1)
14483 inst.instruction |= neon_logbits (size) << 18;
14484
88714cb8 14485 neon_dp_fixup (&inst);
5287ad62
JB
14486}
14487
14488/* Neon instruction encoders, in approximate order of appearance. */
14489
14490static void
14491do_neon_dyadic_i_su (void)
14492{
037e8744 14493 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14494 struct neon_type_el et = neon_check_type (3, rs,
14495 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14496 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14497}
14498
14499static void
14500do_neon_dyadic_i64_su (void)
14501{
037e8744 14502 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14503 struct neon_type_el et = neon_check_type (3, rs,
14504 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14505 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14506}
14507
14508static void
14509neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14510 unsigned immbits)
5287ad62
JB
14511{
14512 unsigned size = et.size >> 3;
14513 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14514 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14515 inst.instruction |= LOW4 (inst.operands[1].reg);
14516 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14517 inst.instruction |= (isquad != 0) << 6;
14518 inst.instruction |= immbits << 16;
14519 inst.instruction |= (size >> 3) << 7;
14520 inst.instruction |= (size & 0x7) << 19;
14521 if (write_ubit)
14522 inst.instruction |= (uval != 0) << 24;
14523
88714cb8 14524 neon_dp_fixup (&inst);
5287ad62
JB
14525}
14526
14527static void
14528do_neon_shl_imm (void)
14529{
14530 if (!inst.operands[2].isreg)
14531 {
037e8744 14532 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14533 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14534 int imm = inst.operands[2].imm;
14535
14536 constraint (imm < 0 || (unsigned)imm >= et.size,
14537 _("immediate out of range for shift"));
88714cb8 14538 NEON_ENCODE (IMMED, inst);
cb3b1e65 14539 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14540 }
14541 else
14542 {
037e8744 14543 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14544 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14545 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14546 unsigned int tmp;
14547
14548 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14549 vshl.xx Dd, Dm, Dn
14550 whereas other 3-register operations encoded by neon_three_same have
14551 syntax like:
14552 vadd.xx Dd, Dn, Dm
14553 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14554 here. */
627907b7
JB
14555 tmp = inst.operands[2].reg;
14556 inst.operands[2].reg = inst.operands[1].reg;
14557 inst.operands[1].reg = tmp;
88714cb8 14558 NEON_ENCODE (INTEGER, inst);
037e8744 14559 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14560 }
14561}
14562
14563static void
14564do_neon_qshl_imm (void)
14565{
14566 if (!inst.operands[2].isreg)
14567 {
037e8744 14568 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14569 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14570 int imm = inst.operands[2].imm;
627907b7 14571
cb3b1e65
JB
14572 constraint (imm < 0 || (unsigned)imm >= et.size,
14573 _("immediate out of range for shift"));
88714cb8 14574 NEON_ENCODE (IMMED, inst);
cb3b1e65 14575 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14576 }
14577 else
14578 {
037e8744 14579 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14580 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14581 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14582 unsigned int tmp;
14583
14584 /* See note in do_neon_shl_imm. */
14585 tmp = inst.operands[2].reg;
14586 inst.operands[2].reg = inst.operands[1].reg;
14587 inst.operands[1].reg = tmp;
88714cb8 14588 NEON_ENCODE (INTEGER, inst);
037e8744 14589 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14590 }
14591}
14592
627907b7
JB
14593static void
14594do_neon_rshl (void)
14595{
14596 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14597 struct neon_type_el et = neon_check_type (3, rs,
14598 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14599 unsigned int tmp;
14600
14601 tmp = inst.operands[2].reg;
14602 inst.operands[2].reg = inst.operands[1].reg;
14603 inst.operands[1].reg = tmp;
14604 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14605}
14606
5287ad62
JB
14607static int
14608neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14609{
036dc3f7
PB
14610 /* Handle .I8 pseudo-instructions. */
14611 if (size == 8)
5287ad62 14612 {
5287ad62 14613 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14614 FIXME is this the intended semantics? There doesn't seem much point in
14615 accepting .I8 if so. */
5287ad62
JB
14616 immediate |= immediate << 8;
14617 size = 16;
036dc3f7
PB
14618 }
14619
14620 if (size >= 32)
14621 {
14622 if (immediate == (immediate & 0x000000ff))
14623 {
14624 *immbits = immediate;
14625 return 0x1;
14626 }
14627 else if (immediate == (immediate & 0x0000ff00))
14628 {
14629 *immbits = immediate >> 8;
14630 return 0x3;
14631 }
14632 else if (immediate == (immediate & 0x00ff0000))
14633 {
14634 *immbits = immediate >> 16;
14635 return 0x5;
14636 }
14637 else if (immediate == (immediate & 0xff000000))
14638 {
14639 *immbits = immediate >> 24;
14640 return 0x7;
14641 }
14642 if ((immediate & 0xffff) != (immediate >> 16))
14643 goto bad_immediate;
14644 immediate &= 0xffff;
5287ad62
JB
14645 }
14646
14647 if (immediate == (immediate & 0x000000ff))
14648 {
14649 *immbits = immediate;
036dc3f7 14650 return 0x9;
5287ad62
JB
14651 }
14652 else if (immediate == (immediate & 0x0000ff00))
14653 {
14654 *immbits = immediate >> 8;
036dc3f7 14655 return 0xb;
5287ad62
JB
14656 }
14657
14658 bad_immediate:
dcbf9037 14659 first_error (_("immediate value out of range"));
5287ad62
JB
14660 return FAIL;
14661}
14662
5287ad62
JB
14663static void
14664do_neon_logic (void)
14665{
14666 if (inst.operands[2].present && inst.operands[2].isreg)
14667 {
037e8744 14668 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14669 neon_check_type (3, rs, N_IGNORE_TYPE);
14670 /* U bit and size field were set as part of the bitmask. */
88714cb8 14671 NEON_ENCODE (INTEGER, inst);
037e8744 14672 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14673 }
14674 else
14675 {
4316f0d2
DG
14676 const int three_ops_form = (inst.operands[2].present
14677 && !inst.operands[2].isreg);
14678 const int immoperand = (three_ops_form ? 2 : 1);
14679 enum neon_shape rs = (three_ops_form
14680 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14681 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14682 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14683 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14684 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14685 unsigned immbits;
14686 int cmode;
5f4273c7 14687
5287ad62 14688 if (et.type == NT_invtype)
477330fc 14689 return;
5f4273c7 14690
4316f0d2
DG
14691 if (three_ops_form)
14692 constraint (inst.operands[0].reg != inst.operands[1].reg,
14693 _("first and second operands shall be the same register"));
14694
88714cb8 14695 NEON_ENCODE (IMMED, inst);
5287ad62 14696
4316f0d2 14697 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14698 if (et.size == 64)
14699 {
14700 /* .i64 is a pseudo-op, so the immediate must be a repeating
14701 pattern. */
4316f0d2
DG
14702 if (immbits != (inst.operands[immoperand].regisimm ?
14703 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14704 {
14705 /* Set immbits to an invalid constant. */
14706 immbits = 0xdeadbeef;
14707 }
14708 }
14709
5287ad62 14710 switch (opcode)
477330fc
RM
14711 {
14712 case N_MNEM_vbic:
14713 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14714 break;
14715
14716 case N_MNEM_vorr:
14717 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14718 break;
14719
14720 case N_MNEM_vand:
14721 /* Pseudo-instruction for VBIC. */
14722 neon_invert_size (&immbits, 0, et.size);
14723 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14724 break;
14725
14726 case N_MNEM_vorn:
14727 /* Pseudo-instruction for VORR. */
14728 neon_invert_size (&immbits, 0, et.size);
14729 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14730 break;
14731
14732 default:
14733 abort ();
14734 }
5287ad62
JB
14735
14736 if (cmode == FAIL)
477330fc 14737 return;
5287ad62 14738
037e8744 14739 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14740 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14741 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14742 inst.instruction |= cmode << 8;
14743 neon_write_immbits (immbits);
5f4273c7 14744
88714cb8 14745 neon_dp_fixup (&inst);
5287ad62
JB
14746 }
14747}
14748
14749static void
14750do_neon_bitfield (void)
14751{
037e8744 14752 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14753 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14754 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14755}
14756
14757static void
dcbf9037 14758neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14759 unsigned destbits)
5287ad62 14760{
037e8744 14761 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14762 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14763 types | N_KEY);
5287ad62
JB
14764 if (et.type == NT_float)
14765 {
88714cb8 14766 NEON_ENCODE (FLOAT, inst);
cc933301 14767 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14768 }
14769 else
14770 {
88714cb8 14771 NEON_ENCODE (INTEGER, inst);
037e8744 14772 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14773 }
14774}
14775
14776static void
14777do_neon_dyadic_if_su (void)
14778{
dcbf9037 14779 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14780}
14781
14782static void
14783do_neon_dyadic_if_su_d (void)
14784{
14785 /* This version only allow D registers, but that constraint is enforced during
14786 operand parsing so we don't need to do anything extra here. */
dcbf9037 14787 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14788}
14789
5287ad62
JB
14790static void
14791do_neon_dyadic_if_i_d (void)
14792{
428e3f1f
PB
14793 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14794 affected if we specify unsigned args. */
14795 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14796}
14797
037e8744
JB
14798enum vfp_or_neon_is_neon_bits
14799{
14800 NEON_CHECK_CC = 1,
73924fbc
MGD
14801 NEON_CHECK_ARCH = 2,
14802 NEON_CHECK_ARCH8 = 4
037e8744
JB
14803};
14804
14805/* Call this function if an instruction which may have belonged to the VFP or
14806 Neon instruction sets, but turned out to be a Neon instruction (due to the
14807 operand types involved, etc.). We have to check and/or fix-up a couple of
14808 things:
14809
14810 - Make sure the user hasn't attempted to make a Neon instruction
14811 conditional.
14812 - Alter the value in the condition code field if necessary.
14813 - Make sure that the arch supports Neon instructions.
14814
14815 Which of these operations take place depends on bits from enum
14816 vfp_or_neon_is_neon_bits.
14817
14818 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14819 current instruction's condition is COND_ALWAYS, the condition field is
14820 changed to inst.uncond_value. This is necessary because instructions shared
14821 between VFP and Neon may be conditional for the VFP variants only, and the
14822 unconditional Neon version must have, e.g., 0xF in the condition field. */
14823
14824static int
14825vfp_or_neon_is_neon (unsigned check)
14826{
14827 /* Conditions are always legal in Thumb mode (IT blocks). */
14828 if (!thumb_mode && (check & NEON_CHECK_CC))
14829 {
14830 if (inst.cond != COND_ALWAYS)
477330fc
RM
14831 {
14832 first_error (_(BAD_COND));
14833 return FAIL;
14834 }
037e8744 14835 if (inst.uncond_value != -1)
477330fc 14836 inst.instruction |= inst.uncond_value << 28;
037e8744 14837 }
5f4273c7 14838
037e8744 14839 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14840 && !mark_feature_used (&fpu_neon_ext_v1))
14841 {
14842 first_error (_(BAD_FPU));
14843 return FAIL;
14844 }
14845
14846 if ((check & NEON_CHECK_ARCH8)
14847 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14848 {
14849 first_error (_(BAD_FPU));
14850 return FAIL;
14851 }
5f4273c7 14852
037e8744
JB
14853 return SUCCESS;
14854}
14855
5287ad62
JB
14856static void
14857do_neon_addsub_if_i (void)
14858{
037e8744
JB
14859 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14860 return;
14861
14862 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14863 return;
14864
5287ad62
JB
14865 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14866 affected if we specify unsigned args. */
dcbf9037 14867 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14868}
14869
14870/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14871 result to be:
14872 V<op> A,B (A is operand 0, B is operand 2)
14873 to mean:
14874 V<op> A,B,A
14875 not:
14876 V<op> A,B,B
14877 so handle that case specially. */
14878
14879static void
14880neon_exchange_operands (void)
14881{
5287ad62
JB
14882 if (inst.operands[1].present)
14883 {
e1fa0163
NC
14884 void *scratch = xmalloc (sizeof (inst.operands[0]));
14885
5287ad62
JB
14886 /* Swap operands[1] and operands[2]. */
14887 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14888 inst.operands[1] = inst.operands[2];
14889 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14890 free (scratch);
5287ad62
JB
14891 }
14892 else
14893 {
14894 inst.operands[1] = inst.operands[2];
14895 inst.operands[2] = inst.operands[0];
14896 }
14897}
14898
14899static void
14900neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14901{
14902 if (inst.operands[2].isreg)
14903 {
14904 if (invert)
477330fc 14905 neon_exchange_operands ();
dcbf9037 14906 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14907 }
14908 else
14909 {
037e8744 14910 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14911 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14912 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14913
88714cb8 14914 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14915 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14916 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14917 inst.instruction |= LOW4 (inst.operands[1].reg);
14918 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14919 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14920 inst.instruction |= (et.type == NT_float) << 10;
14921 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14922
88714cb8 14923 neon_dp_fixup (&inst);
5287ad62
JB
14924 }
14925}
14926
14927static void
14928do_neon_cmp (void)
14929{
cc933301 14930 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14931}
14932
14933static void
14934do_neon_cmp_inv (void)
14935{
cc933301 14936 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
14937}
14938
14939static void
14940do_neon_ceq (void)
14941{
14942 neon_compare (N_IF_32, N_IF_32, FALSE);
14943}
14944
14945/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14946 scalars, which are encoded in 5 bits, M : Rm.
14947 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14948 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14949 index in M. */
14950
14951static unsigned
14952neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14953{
dcbf9037
JB
14954 unsigned regno = NEON_SCALAR_REG (scalar);
14955 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14956
14957 switch (elsize)
14958 {
14959 case 16:
14960 if (regno > 7 || elno > 3)
477330fc 14961 goto bad_scalar;
5287ad62 14962 return regno | (elno << 3);
5f4273c7 14963
5287ad62
JB
14964 case 32:
14965 if (regno > 15 || elno > 1)
477330fc 14966 goto bad_scalar;
5287ad62
JB
14967 return regno | (elno << 4);
14968
14969 default:
14970 bad_scalar:
dcbf9037 14971 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14972 }
14973
14974 return 0;
14975}
14976
14977/* Encode multiply / multiply-accumulate scalar instructions. */
14978
14979static void
14980neon_mul_mac (struct neon_type_el et, int ubit)
14981{
dcbf9037
JB
14982 unsigned scalar;
14983
14984 /* Give a more helpful error message if we have an invalid type. */
14985 if (et.type == NT_invtype)
14986 return;
5f4273c7 14987
dcbf9037 14988 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14989 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14990 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14991 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14992 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14993 inst.instruction |= LOW4 (scalar);
14994 inst.instruction |= HI1 (scalar) << 5;
14995 inst.instruction |= (et.type == NT_float) << 8;
14996 inst.instruction |= neon_logbits (et.size) << 20;
14997 inst.instruction |= (ubit != 0) << 24;
14998
88714cb8 14999 neon_dp_fixup (&inst);
5287ad62
JB
15000}
15001
15002static void
15003do_neon_mac_maybe_scalar (void)
15004{
037e8744
JB
15005 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15006 return;
15007
15008 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15009 return;
15010
5287ad62
JB
15011 if (inst.operands[2].isscalar)
15012 {
037e8744 15013 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15014 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15015 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15016 NEON_ENCODE (SCALAR, inst);
037e8744 15017 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15018 }
15019 else
428e3f1f
PB
15020 {
15021 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15022 affected if we specify unsigned args. */
15023 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15024 }
5287ad62
JB
15025}
15026
62f3b8c8
PB
15027static void
15028do_neon_fmac (void)
15029{
15030 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15031 return;
15032
15033 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15034 return;
15035
15036 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15037}
15038
5287ad62
JB
15039static void
15040do_neon_tst (void)
15041{
037e8744 15042 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15043 struct neon_type_el et = neon_check_type (3, rs,
15044 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15045 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15046}
15047
15048/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15049 same types as the MAC equivalents. The polynomial type for this instruction
15050 is encoded the same as the integer type. */
15051
15052static void
15053do_neon_mul (void)
15054{
037e8744
JB
15055 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15056 return;
15057
15058 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15059 return;
15060
5287ad62
JB
15061 if (inst.operands[2].isscalar)
15062 do_neon_mac_maybe_scalar ();
15063 else
cc933301 15064 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15065}
15066
15067static void
15068do_neon_qdmulh (void)
15069{
15070 if (inst.operands[2].isscalar)
15071 {
037e8744 15072 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15073 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15074 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15075 NEON_ENCODE (SCALAR, inst);
037e8744 15076 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15077 }
15078 else
15079 {
037e8744 15080 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15081 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15082 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15083 NEON_ENCODE (INTEGER, inst);
5287ad62 15084 /* The U bit (rounding) comes from bit mask. */
037e8744 15085 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15086 }
15087}
15088
643afb90
MW
15089static void
15090do_neon_qrdmlah (void)
15091{
15092 /* Check we're on the correct architecture. */
15093 if (!mark_feature_used (&fpu_neon_ext_armv8))
15094 inst.error =
15095 _("instruction form not available on this architecture.");
15096 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15097 {
15098 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15099 record_feature_use (&fpu_neon_ext_v8_1);
15100 }
15101
15102 if (inst.operands[2].isscalar)
15103 {
15104 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15105 struct neon_type_el et = neon_check_type (3, rs,
15106 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15107 NEON_ENCODE (SCALAR, inst);
15108 neon_mul_mac (et, neon_quad (rs));
15109 }
15110 else
15111 {
15112 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15113 struct neon_type_el et = neon_check_type (3, rs,
15114 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15115 NEON_ENCODE (INTEGER, inst);
15116 /* The U bit (rounding) comes from bit mask. */
15117 neon_three_same (neon_quad (rs), 0, et.size);
15118 }
15119}
15120
5287ad62
JB
15121static void
15122do_neon_fcmp_absolute (void)
15123{
037e8744 15124 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15125 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15126 N_F_16_32 | N_KEY);
5287ad62 15127 /* Size field comes from bit mask. */
cc933301 15128 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15129}
15130
15131static void
15132do_neon_fcmp_absolute_inv (void)
15133{
15134 neon_exchange_operands ();
15135 do_neon_fcmp_absolute ();
15136}
15137
15138static void
15139do_neon_step (void)
15140{
037e8744 15141 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15142 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15143 N_F_16_32 | N_KEY);
15144 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15145}
15146
15147static void
15148do_neon_abs_neg (void)
15149{
037e8744
JB
15150 enum neon_shape rs;
15151 struct neon_type_el et;
5f4273c7 15152
037e8744
JB
15153 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15154 return;
15155
15156 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15157 return;
15158
15159 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15160 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15161
5287ad62
JB
15162 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15163 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15164 inst.instruction |= LOW4 (inst.operands[1].reg);
15165 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15166 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15167 inst.instruction |= (et.type == NT_float) << 10;
15168 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15169
88714cb8 15170 neon_dp_fixup (&inst);
5287ad62
JB
15171}
15172
15173static void
15174do_neon_sli (void)
15175{
037e8744 15176 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15177 struct neon_type_el et = neon_check_type (2, rs,
15178 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15179 int imm = inst.operands[2].imm;
15180 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15181 _("immediate out of range for insert"));
037e8744 15182 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15183}
15184
15185static void
15186do_neon_sri (void)
15187{
037e8744 15188 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15189 struct neon_type_el et = neon_check_type (2, rs,
15190 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15191 int imm = inst.operands[2].imm;
15192 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15193 _("immediate out of range for insert"));
037e8744 15194 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15195}
15196
15197static void
15198do_neon_qshlu_imm (void)
15199{
037e8744 15200 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15201 struct neon_type_el et = neon_check_type (2, rs,
15202 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15203 int imm = inst.operands[2].imm;
15204 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15205 _("immediate out of range for shift"));
5287ad62
JB
15206 /* Only encodes the 'U present' variant of the instruction.
15207 In this case, signed types have OP (bit 8) set to 0.
15208 Unsigned types have OP set to 1. */
15209 inst.instruction |= (et.type == NT_unsigned) << 8;
15210 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15211 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15212}
15213
15214static void
15215do_neon_qmovn (void)
15216{
15217 struct neon_type_el et = neon_check_type (2, NS_DQ,
15218 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15219 /* Saturating move where operands can be signed or unsigned, and the
15220 destination has the same signedness. */
88714cb8 15221 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15222 if (et.type == NT_unsigned)
15223 inst.instruction |= 0xc0;
15224 else
15225 inst.instruction |= 0x80;
15226 neon_two_same (0, 1, et.size / 2);
15227}
15228
15229static void
15230do_neon_qmovun (void)
15231{
15232 struct neon_type_el et = neon_check_type (2, NS_DQ,
15233 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15234 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15235 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15236 neon_two_same (0, 1, et.size / 2);
15237}
15238
15239static void
15240do_neon_rshift_sat_narrow (void)
15241{
15242 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15243 or unsigned. If operands are unsigned, results must also be unsigned. */
15244 struct neon_type_el et = neon_check_type (2, NS_DQI,
15245 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15246 int imm = inst.operands[2].imm;
15247 /* This gets the bounds check, size encoding and immediate bits calculation
15248 right. */
15249 et.size /= 2;
5f4273c7 15250
5287ad62
JB
15251 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15252 VQMOVN.I<size> <Dd>, <Qm>. */
15253 if (imm == 0)
15254 {
15255 inst.operands[2].present = 0;
15256 inst.instruction = N_MNEM_vqmovn;
15257 do_neon_qmovn ();
15258 return;
15259 }
5f4273c7 15260
5287ad62 15261 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15262 _("immediate out of range"));
5287ad62
JB
15263 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15264}
15265
15266static void
15267do_neon_rshift_sat_narrow_u (void)
15268{
15269 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15270 or unsigned. If operands are unsigned, results must also be unsigned. */
15271 struct neon_type_el et = neon_check_type (2, NS_DQI,
15272 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15273 int imm = inst.operands[2].imm;
15274 /* This gets the bounds check, size encoding and immediate bits calculation
15275 right. */
15276 et.size /= 2;
15277
15278 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15279 VQMOVUN.I<size> <Dd>, <Qm>. */
15280 if (imm == 0)
15281 {
15282 inst.operands[2].present = 0;
15283 inst.instruction = N_MNEM_vqmovun;
15284 do_neon_qmovun ();
15285 return;
15286 }
15287
15288 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15289 _("immediate out of range"));
5287ad62
JB
15290 /* FIXME: The manual is kind of unclear about what value U should have in
15291 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15292 must be 1. */
15293 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15294}
15295
15296static void
15297do_neon_movn (void)
15298{
15299 struct neon_type_el et = neon_check_type (2, NS_DQ,
15300 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15301 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15302 neon_two_same (0, 1, et.size / 2);
15303}
15304
15305static void
15306do_neon_rshift_narrow (void)
15307{
15308 struct neon_type_el et = neon_check_type (2, NS_DQI,
15309 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15310 int imm = inst.operands[2].imm;
15311 /* This gets the bounds check, size encoding and immediate bits calculation
15312 right. */
15313 et.size /= 2;
5f4273c7 15314
5287ad62
JB
15315 /* If immediate is zero then we are a pseudo-instruction for
15316 VMOVN.I<size> <Dd>, <Qm> */
15317 if (imm == 0)
15318 {
15319 inst.operands[2].present = 0;
15320 inst.instruction = N_MNEM_vmovn;
15321 do_neon_movn ();
15322 return;
15323 }
5f4273c7 15324
5287ad62 15325 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15326 _("immediate out of range for narrowing operation"));
5287ad62
JB
15327 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15328}
15329
15330static void
15331do_neon_shll (void)
15332{
15333 /* FIXME: Type checking when lengthening. */
15334 struct neon_type_el et = neon_check_type (2, NS_QDI,
15335 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15336 unsigned imm = inst.operands[2].imm;
15337
15338 if (imm == et.size)
15339 {
15340 /* Maximum shift variant. */
88714cb8 15341 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15342 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15343 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15344 inst.instruction |= LOW4 (inst.operands[1].reg);
15345 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15346 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15347
88714cb8 15348 neon_dp_fixup (&inst);
5287ad62
JB
15349 }
15350 else
15351 {
15352 /* A more-specific type check for non-max versions. */
15353 et = neon_check_type (2, NS_QDI,
477330fc 15354 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15355 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15356 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15357 }
15358}
15359
037e8744 15360/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15361 the current instruction is. */
15362
6b9a8b67
MGD
15363#define CVT_FLAVOUR_VAR \
15364 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15365 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15366 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15367 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15368 /* Half-precision conversions. */ \
cc933301
JW
15369 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15370 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15371 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15372 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15373 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15374 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15375 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15376 Compared with single/double precision variants, only the co-processor \
15377 field is different, so the encoding flow is reused here. */ \
15378 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15379 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15380 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15381 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15382 /* VFP instructions. */ \
15383 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15384 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15385 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15386 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15387 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15388 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15389 /* VFP instructions with bitshift. */ \
15390 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15391 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15392 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15393 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15394 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15395 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15396 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15397 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15398
15399#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15400 neon_cvt_flavour_##C,
15401
15402/* The different types of conversions we can do. */
15403enum neon_cvt_flavour
15404{
15405 CVT_FLAVOUR_VAR
15406 neon_cvt_flavour_invalid,
15407 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15408};
15409
15410#undef CVT_VAR
15411
15412static enum neon_cvt_flavour
15413get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15414{
6b9a8b67
MGD
15415#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15416 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15417 if (et.type != NT_invtype) \
15418 { \
15419 inst.error = NULL; \
15420 return (neon_cvt_flavour_##C); \
5287ad62 15421 }
6b9a8b67 15422
5287ad62 15423 struct neon_type_el et;
037e8744 15424 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15425 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15426 /* The instruction versions which take an immediate take one register
15427 argument, which is extended to the width of the full register. Thus the
15428 "source" and "destination" registers must have the same width. Hack that
15429 here by making the size equal to the key (wider, in this case) operand. */
15430 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15431
6b9a8b67
MGD
15432 CVT_FLAVOUR_VAR;
15433
15434 return neon_cvt_flavour_invalid;
5287ad62
JB
15435#undef CVT_VAR
15436}
15437
7e8e6784
MGD
15438enum neon_cvt_mode
15439{
15440 neon_cvt_mode_a,
15441 neon_cvt_mode_n,
15442 neon_cvt_mode_p,
15443 neon_cvt_mode_m,
15444 neon_cvt_mode_z,
30bdf752
MGD
15445 neon_cvt_mode_x,
15446 neon_cvt_mode_r
7e8e6784
MGD
15447};
15448
037e8744
JB
15449/* Neon-syntax VFP conversions. */
15450
5287ad62 15451static void
6b9a8b67 15452do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15453{
037e8744 15454 const char *opname = 0;
5f4273c7 15455
d54af2d0
RL
15456 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15457 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15458 {
037e8744
JB
15459 /* Conversions with immediate bitshift. */
15460 const char *enc[] =
477330fc 15461 {
6b9a8b67
MGD
15462#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15463 CVT_FLAVOUR_VAR
15464 NULL
15465#undef CVT_VAR
477330fc 15466 };
037e8744 15467
6b9a8b67 15468 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15469 {
15470 opname = enc[flavour];
15471 constraint (inst.operands[0].reg != inst.operands[1].reg,
15472 _("operands 0 and 1 must be the same register"));
15473 inst.operands[1] = inst.operands[2];
15474 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15475 }
5287ad62
JB
15476 }
15477 else
15478 {
037e8744
JB
15479 /* Conversions without bitshift. */
15480 const char *enc[] =
477330fc 15481 {
6b9a8b67
MGD
15482#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15483 CVT_FLAVOUR_VAR
15484 NULL
15485#undef CVT_VAR
477330fc 15486 };
037e8744 15487
6b9a8b67 15488 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15489 opname = enc[flavour];
037e8744
JB
15490 }
15491
15492 if (opname)
15493 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15494
15495 /* ARMv8.2 fp16 VCVT instruction. */
15496 if (flavour == neon_cvt_flavour_s32_f16
15497 || flavour == neon_cvt_flavour_u32_f16
15498 || flavour == neon_cvt_flavour_f16_u32
15499 || flavour == neon_cvt_flavour_f16_s32)
15500 do_scalar_fp16_v82_encode ();
037e8744
JB
15501}
15502
15503static void
15504do_vfp_nsyn_cvtz (void)
15505{
d54af2d0 15506 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15507 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15508 const char *enc[] =
15509 {
6b9a8b67
MGD
15510#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15511 CVT_FLAVOUR_VAR
15512 NULL
15513#undef CVT_VAR
037e8744
JB
15514 };
15515
6b9a8b67 15516 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15517 do_vfp_nsyn_opcode (enc[flavour]);
15518}
f31fef98 15519
037e8744 15520static void
bacebabc 15521do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15522 enum neon_cvt_mode mode)
15523{
15524 int sz, op;
15525 int rm;
15526
a715796b
TG
15527 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15528 D register operands. */
15529 if (flavour == neon_cvt_flavour_s32_f64
15530 || flavour == neon_cvt_flavour_u32_f64)
15531 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15532 _(BAD_FPU));
15533
9db2f6b4
RL
15534 if (flavour == neon_cvt_flavour_s32_f16
15535 || flavour == neon_cvt_flavour_u32_f16)
15536 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15537 _(BAD_FP16));
15538
7e8e6784
MGD
15539 set_it_insn_type (OUTSIDE_IT_INSN);
15540
15541 switch (flavour)
15542 {
15543 case neon_cvt_flavour_s32_f64:
15544 sz = 1;
827f64ff 15545 op = 1;
7e8e6784
MGD
15546 break;
15547 case neon_cvt_flavour_s32_f32:
15548 sz = 0;
15549 op = 1;
15550 break;
9db2f6b4
RL
15551 case neon_cvt_flavour_s32_f16:
15552 sz = 0;
15553 op = 1;
15554 break;
7e8e6784
MGD
15555 case neon_cvt_flavour_u32_f64:
15556 sz = 1;
15557 op = 0;
15558 break;
15559 case neon_cvt_flavour_u32_f32:
15560 sz = 0;
15561 op = 0;
15562 break;
9db2f6b4
RL
15563 case neon_cvt_flavour_u32_f16:
15564 sz = 0;
15565 op = 0;
15566 break;
7e8e6784
MGD
15567 default:
15568 first_error (_("invalid instruction shape"));
15569 return;
15570 }
15571
15572 switch (mode)
15573 {
15574 case neon_cvt_mode_a: rm = 0; break;
15575 case neon_cvt_mode_n: rm = 1; break;
15576 case neon_cvt_mode_p: rm = 2; break;
15577 case neon_cvt_mode_m: rm = 3; break;
15578 default: first_error (_("invalid rounding mode")); return;
15579 }
15580
15581 NEON_ENCODE (FPV8, inst);
15582 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15583 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15584 inst.instruction |= sz << 8;
9db2f6b4
RL
15585
15586 /* ARMv8.2 fp16 VCVT instruction. */
15587 if (flavour == neon_cvt_flavour_s32_f16
15588 ||flavour == neon_cvt_flavour_u32_f16)
15589 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15590 inst.instruction |= op << 7;
15591 inst.instruction |= rm << 16;
15592 inst.instruction |= 0xf0000000;
15593 inst.is_neon = TRUE;
15594}
15595
15596static void
15597do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15598{
15599 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15600 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15601 NS_FH, NS_HF, NS_FHI, NS_HFI,
15602 NS_NULL);
6b9a8b67 15603 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15604
cc933301
JW
15605 if (flavour == neon_cvt_flavour_invalid)
15606 return;
15607
e3e535bc 15608 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15609 if (mode == neon_cvt_mode_z
e3e535bc 15610 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15611 && (flavour == neon_cvt_flavour_s16_f16
15612 || flavour == neon_cvt_flavour_u16_f16
15613 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15614 || flavour == neon_cvt_flavour_u32_f32
15615 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15616 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15617 && (rs == NS_FD || rs == NS_FF))
15618 {
15619 do_vfp_nsyn_cvtz ();
15620 return;
15621 }
15622
9db2f6b4
RL
15623 /* ARMv8.2 fp16 VCVT conversions. */
15624 if (mode == neon_cvt_mode_z
15625 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15626 && (flavour == neon_cvt_flavour_s32_f16
15627 || flavour == neon_cvt_flavour_u32_f16)
15628 && (rs == NS_FH))
15629 {
15630 do_vfp_nsyn_cvtz ();
15631 do_scalar_fp16_v82_encode ();
15632 return;
15633 }
15634
037e8744 15635 /* VFP rather than Neon conversions. */
6b9a8b67 15636 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15637 {
7e8e6784
MGD
15638 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15639 do_vfp_nsyn_cvt (rs, flavour);
15640 else
15641 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15642
037e8744
JB
15643 return;
15644 }
15645
15646 switch (rs)
15647 {
15648 case NS_DDI:
15649 case NS_QQI:
15650 {
477330fc 15651 unsigned immbits;
cc933301
JW
15652 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15653 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15654
477330fc
RM
15655 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15656 return;
037e8744 15657
477330fc
RM
15658 /* Fixed-point conversion with #0 immediate is encoded as an
15659 integer conversion. */
15660 if (inst.operands[2].present && inst.operands[2].imm == 0)
15661 goto int_encode;
477330fc
RM
15662 NEON_ENCODE (IMMED, inst);
15663 if (flavour != neon_cvt_flavour_invalid)
15664 inst.instruction |= enctab[flavour];
15665 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15666 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15667 inst.instruction |= LOW4 (inst.operands[1].reg);
15668 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15669 inst.instruction |= neon_quad (rs) << 6;
15670 inst.instruction |= 1 << 21;
cc933301
JW
15671 if (flavour < neon_cvt_flavour_s16_f16)
15672 {
15673 inst.instruction |= 1 << 21;
15674 immbits = 32 - inst.operands[2].imm;
15675 inst.instruction |= immbits << 16;
15676 }
15677 else
15678 {
15679 inst.instruction |= 3 << 20;
15680 immbits = 16 - inst.operands[2].imm;
15681 inst.instruction |= immbits << 16;
15682 inst.instruction &= ~(1 << 9);
15683 }
477330fc
RM
15684
15685 neon_dp_fixup (&inst);
037e8744
JB
15686 }
15687 break;
15688
15689 case NS_DD:
15690 case NS_QQ:
7e8e6784
MGD
15691 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15692 {
15693 NEON_ENCODE (FLOAT, inst);
15694 set_it_insn_type (OUTSIDE_IT_INSN);
15695
15696 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15697 return;
15698
15699 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15700 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15701 inst.instruction |= LOW4 (inst.operands[1].reg);
15702 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15703 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15704 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15705 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15706 inst.instruction |= mode << 8;
cc933301
JW
15707 if (flavour == neon_cvt_flavour_u16_f16
15708 || flavour == neon_cvt_flavour_s16_f16)
15709 /* Mask off the original size bits and reencode them. */
15710 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15711
7e8e6784
MGD
15712 if (thumb_mode)
15713 inst.instruction |= 0xfc000000;
15714 else
15715 inst.instruction |= 0xf0000000;
15716 }
15717 else
15718 {
037e8744 15719 int_encode:
7e8e6784 15720 {
cc933301
JW
15721 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15722 0x100, 0x180, 0x0, 0x080};
037e8744 15723
7e8e6784 15724 NEON_ENCODE (INTEGER, inst);
037e8744 15725
7e8e6784
MGD
15726 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15727 return;
037e8744 15728
7e8e6784
MGD
15729 if (flavour != neon_cvt_flavour_invalid)
15730 inst.instruction |= enctab[flavour];
037e8744 15731
7e8e6784
MGD
15732 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15733 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15734 inst.instruction |= LOW4 (inst.operands[1].reg);
15735 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15736 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15737 if (flavour >= neon_cvt_flavour_s16_f16
15738 && flavour <= neon_cvt_flavour_f16_u16)
15739 /* Half precision. */
15740 inst.instruction |= 1 << 18;
15741 else
15742 inst.instruction |= 2 << 18;
037e8744 15743
7e8e6784
MGD
15744 neon_dp_fixup (&inst);
15745 }
15746 }
15747 break;
037e8744 15748
8e79c3df
CM
15749 /* Half-precision conversions for Advanced SIMD -- neon. */
15750 case NS_QD:
15751 case NS_DQ:
15752
15753 if ((rs == NS_DQ)
15754 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15755 {
15756 as_bad (_("operand size must match register width"));
15757 break;
15758 }
15759
15760 if ((rs == NS_QD)
15761 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15762 {
15763 as_bad (_("operand size must match register width"));
15764 break;
15765 }
15766
15767 if (rs == NS_DQ)
477330fc 15768 inst.instruction = 0x3b60600;
8e79c3df
CM
15769 else
15770 inst.instruction = 0x3b60700;
15771
15772 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15773 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15774 inst.instruction |= LOW4 (inst.operands[1].reg);
15775 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15776 neon_dp_fixup (&inst);
8e79c3df
CM
15777 break;
15778
037e8744
JB
15779 default:
15780 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15781 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15782 do_vfp_nsyn_cvt (rs, flavour);
15783 else
15784 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15785 }
5287ad62
JB
15786}
15787
e3e535bc
NC
15788static void
15789do_neon_cvtr (void)
15790{
7e8e6784 15791 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15792}
15793
15794static void
15795do_neon_cvt (void)
15796{
7e8e6784
MGD
15797 do_neon_cvt_1 (neon_cvt_mode_z);
15798}
15799
15800static void
15801do_neon_cvta (void)
15802{
15803 do_neon_cvt_1 (neon_cvt_mode_a);
15804}
15805
15806static void
15807do_neon_cvtn (void)
15808{
15809 do_neon_cvt_1 (neon_cvt_mode_n);
15810}
15811
15812static void
15813do_neon_cvtp (void)
15814{
15815 do_neon_cvt_1 (neon_cvt_mode_p);
15816}
15817
15818static void
15819do_neon_cvtm (void)
15820{
15821 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15822}
15823
8e79c3df 15824static void
c70a8987 15825do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15826{
c70a8987
MGD
15827 if (is_double)
15828 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15829
c70a8987
MGD
15830 encode_arm_vfp_reg (inst.operands[0].reg,
15831 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15832 encode_arm_vfp_reg (inst.operands[1].reg,
15833 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15834 inst.instruction |= to ? 0x10000 : 0;
15835 inst.instruction |= t ? 0x80 : 0;
15836 inst.instruction |= is_double ? 0x100 : 0;
15837 do_vfp_cond_or_thumb ();
15838}
8e79c3df 15839
c70a8987
MGD
15840static void
15841do_neon_cvttb_1 (bfd_boolean t)
15842{
d54af2d0
RL
15843 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15844 NS_DF, NS_DH, NS_NULL);
8e79c3df 15845
c70a8987
MGD
15846 if (rs == NS_NULL)
15847 return;
15848 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15849 {
15850 inst.error = NULL;
15851 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15852 }
15853 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15854 {
15855 inst.error = NULL;
15856 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15857 }
15858 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15859 {
a715796b
TG
15860 /* The VCVTB and VCVTT instructions with D-register operands
15861 don't work for SP only targets. */
15862 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15863 _(BAD_FPU));
15864
c70a8987
MGD
15865 inst.error = NULL;
15866 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15867 }
15868 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15869 {
a715796b
TG
15870 /* The VCVTB and VCVTT instructions with D-register operands
15871 don't work for SP only targets. */
15872 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15873 _(BAD_FPU));
15874
c70a8987
MGD
15875 inst.error = NULL;
15876 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15877 }
15878 else
15879 return;
15880}
15881
15882static void
15883do_neon_cvtb (void)
15884{
15885 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15886}
15887
15888
15889static void
15890do_neon_cvtt (void)
15891{
c70a8987 15892 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15893}
15894
5287ad62
JB
15895static void
15896neon_move_immediate (void)
15897{
037e8744
JB
15898 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15899 struct neon_type_el et = neon_check_type (2, rs,
15900 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15901 unsigned immlo, immhi = 0, immbits;
c96612cc 15902 int op, cmode, float_p;
5287ad62 15903
037e8744 15904 constraint (et.type == NT_invtype,
477330fc 15905 _("operand size must be specified for immediate VMOV"));
037e8744 15906
5287ad62
JB
15907 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15908 op = (inst.instruction & (1 << 5)) != 0;
15909
15910 immlo = inst.operands[1].imm;
15911 if (inst.operands[1].regisimm)
15912 immhi = inst.operands[1].reg;
15913
15914 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15915 _("immediate has bits set outside the operand size"));
5287ad62 15916
c96612cc
JB
15917 float_p = inst.operands[1].immisfloat;
15918
15919 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15920 et.size, et.type)) == FAIL)
5287ad62
JB
15921 {
15922 /* Invert relevant bits only. */
15923 neon_invert_size (&immlo, &immhi, et.size);
15924 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15925 with one or the other; those cases are caught by
15926 neon_cmode_for_move_imm. */
5287ad62 15927 op = !op;
c96612cc
JB
15928 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15929 &op, et.size, et.type)) == FAIL)
477330fc
RM
15930 {
15931 first_error (_("immediate out of range"));
15932 return;
15933 }
5287ad62
JB
15934 }
15935
15936 inst.instruction &= ~(1 << 5);
15937 inst.instruction |= op << 5;
15938
15939 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15940 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15941 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15942 inst.instruction |= cmode << 8;
15943
15944 neon_write_immbits (immbits);
15945}
15946
15947static void
15948do_neon_mvn (void)
15949{
15950 if (inst.operands[1].isreg)
15951 {
037e8744 15952 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15953
88714cb8 15954 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15955 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15956 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15957 inst.instruction |= LOW4 (inst.operands[1].reg);
15958 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15959 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15960 }
15961 else
15962 {
88714cb8 15963 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15964 neon_move_immediate ();
15965 }
15966
88714cb8 15967 neon_dp_fixup (&inst);
5287ad62
JB
15968}
15969
15970/* Encode instructions of form:
15971
15972 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15973 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15974
15975static void
15976neon_mixed_length (struct neon_type_el et, unsigned size)
15977{
15978 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15979 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15980 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15981 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15982 inst.instruction |= LOW4 (inst.operands[2].reg);
15983 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15984 inst.instruction |= (et.type == NT_unsigned) << 24;
15985 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15986
88714cb8 15987 neon_dp_fixup (&inst);
5287ad62
JB
15988}
15989
15990static void
15991do_neon_dyadic_long (void)
15992{
15993 /* FIXME: Type checking for lengthening op. */
15994 struct neon_type_el et = neon_check_type (3, NS_QDD,
15995 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15996 neon_mixed_length (et, et.size);
15997}
15998
15999static void
16000do_neon_abal (void)
16001{
16002 struct neon_type_el et = neon_check_type (3, NS_QDD,
16003 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16004 neon_mixed_length (et, et.size);
16005}
16006
16007static void
16008neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16009{
16010 if (inst.operands[2].isscalar)
16011 {
dcbf9037 16012 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16013 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16014 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16015 neon_mul_mac (et, et.type == NT_unsigned);
16016 }
16017 else
16018 {
16019 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16020 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16021 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16022 neon_mixed_length (et, et.size);
16023 }
16024}
16025
16026static void
16027do_neon_mac_maybe_scalar_long (void)
16028{
16029 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16030}
16031
16032static void
16033do_neon_dyadic_wide (void)
16034{
16035 struct neon_type_el et = neon_check_type (3, NS_QQD,
16036 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16037 neon_mixed_length (et, et.size);
16038}
16039
16040static void
16041do_neon_dyadic_narrow (void)
16042{
16043 struct neon_type_el et = neon_check_type (3, NS_QDD,
16044 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16045 /* Operand sign is unimportant, and the U bit is part of the opcode,
16046 so force the operand type to integer. */
16047 et.type = NT_integer;
5287ad62
JB
16048 neon_mixed_length (et, et.size / 2);
16049}
16050
16051static void
16052do_neon_mul_sat_scalar_long (void)
16053{
16054 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16055}
16056
16057static void
16058do_neon_vmull (void)
16059{
16060 if (inst.operands[2].isscalar)
16061 do_neon_mac_maybe_scalar_long ();
16062 else
16063 {
16064 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16065 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16066
5287ad62 16067 if (et.type == NT_poly)
477330fc 16068 NEON_ENCODE (POLY, inst);
5287ad62 16069 else
477330fc 16070 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16071
16072 /* For polynomial encoding the U bit must be zero, and the size must
16073 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16074 obviously, as 0b10). */
16075 if (et.size == 64)
16076 {
16077 /* Check we're on the correct architecture. */
16078 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16079 inst.error =
16080 _("Instruction form not available on this architecture.");
16081
16082 et.size = 32;
16083 }
16084
5287ad62
JB
16085 neon_mixed_length (et, et.size);
16086 }
16087}
16088
16089static void
16090do_neon_ext (void)
16091{
037e8744 16092 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16093 struct neon_type_el et = neon_check_type (3, rs,
16094 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16095 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16096
16097 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16098 _("shift out of range"));
5287ad62
JB
16099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16101 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16102 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16103 inst.instruction |= LOW4 (inst.operands[2].reg);
16104 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16105 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16106 inst.instruction |= imm << 8;
5f4273c7 16107
88714cb8 16108 neon_dp_fixup (&inst);
5287ad62
JB
16109}
16110
16111static void
16112do_neon_rev (void)
16113{
037e8744 16114 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16115 struct neon_type_el et = neon_check_type (2, rs,
16116 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16117 unsigned op = (inst.instruction >> 7) & 3;
16118 /* N (width of reversed regions) is encoded as part of the bitmask. We
16119 extract it here to check the elements to be reversed are smaller.
16120 Otherwise we'd get a reserved instruction. */
16121 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16122 gas_assert (elsize != 0);
5287ad62 16123 constraint (et.size >= elsize,
477330fc 16124 _("elements must be smaller than reversal region"));
037e8744 16125 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16126}
16127
16128static void
16129do_neon_dup (void)
16130{
16131 if (inst.operands[1].isscalar)
16132 {
037e8744 16133 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16134 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16135 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16136 unsigned sizebits = et.size >> 3;
dcbf9037 16137 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16138 int logsize = neon_logbits (et.size);
dcbf9037 16139 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16140
16141 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16142 return;
037e8744 16143
88714cb8 16144 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16145 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16146 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16147 inst.instruction |= LOW4 (dm);
16148 inst.instruction |= HI1 (dm) << 5;
037e8744 16149 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16150 inst.instruction |= x << 17;
16151 inst.instruction |= sizebits << 16;
5f4273c7 16152
88714cb8 16153 neon_dp_fixup (&inst);
5287ad62
JB
16154 }
16155 else
16156 {
037e8744
JB
16157 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16158 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16159 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16160 /* Duplicate ARM register to lanes of vector. */
88714cb8 16161 NEON_ENCODE (ARMREG, inst);
5287ad62 16162 switch (et.size)
477330fc
RM
16163 {
16164 case 8: inst.instruction |= 0x400000; break;
16165 case 16: inst.instruction |= 0x000020; break;
16166 case 32: inst.instruction |= 0x000000; break;
16167 default: break;
16168 }
5287ad62
JB
16169 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16170 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16171 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16172 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16173 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16174 variants, except for the condition field. */
037e8744 16175 do_vfp_cond_or_thumb ();
5287ad62
JB
16176 }
16177}
16178
16179/* VMOV has particularly many variations. It can be one of:
16180 0. VMOV<c><q> <Qd>, <Qm>
16181 1. VMOV<c><q> <Dd>, <Dm>
16182 (Register operations, which are VORR with Rm = Rn.)
16183 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16184 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16185 (Immediate loads.)
16186 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16187 (ARM register to scalar.)
16188 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16189 (Two ARM registers to vector.)
16190 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16191 (Scalar to ARM register.)
16192 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16193 (Vector to two ARM registers.)
037e8744
JB
16194 8. VMOV.F32 <Sd>, <Sm>
16195 9. VMOV.F64 <Dd>, <Dm>
16196 (VFP register moves.)
16197 10. VMOV.F32 <Sd>, #imm
16198 11. VMOV.F64 <Dd>, #imm
16199 (VFP float immediate load.)
16200 12. VMOV <Rd>, <Sm>
16201 (VFP single to ARM reg.)
16202 13. VMOV <Sd>, <Rm>
16203 (ARM reg to VFP single.)
16204 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16205 (Two ARM regs to two VFP singles.)
16206 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16207 (Two VFP singles to two ARM regs.)
5f4273c7 16208
037e8744
JB
16209 These cases can be disambiguated using neon_select_shape, except cases 1/9
16210 and 3/11 which depend on the operand type too.
5f4273c7 16211
5287ad62 16212 All the encoded bits are hardcoded by this function.
5f4273c7 16213
b7fc2769
JB
16214 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16215 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16216
5287ad62 16217 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16218 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16219
16220static void
16221do_neon_mov (void)
16222{
037e8744 16223 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16224 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16225 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16226 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16227 struct neon_type_el et;
16228 const char *ldconst = 0;
5287ad62 16229
037e8744 16230 switch (rs)
5287ad62 16231 {
037e8744
JB
16232 case NS_DD: /* case 1/9. */
16233 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16234 /* It is not an error here if no type is given. */
16235 inst.error = NULL;
16236 if (et.type == NT_float && et.size == 64)
477330fc
RM
16237 {
16238 do_vfp_nsyn_opcode ("fcpyd");
16239 break;
16240 }
037e8744 16241 /* fall through. */
5287ad62 16242
037e8744
JB
16243 case NS_QQ: /* case 0/1. */
16244 {
477330fc
RM
16245 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16246 return;
16247 /* The architecture manual I have doesn't explicitly state which
16248 value the U bit should have for register->register moves, but
16249 the equivalent VORR instruction has U = 0, so do that. */
16250 inst.instruction = 0x0200110;
16251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16253 inst.instruction |= LOW4 (inst.operands[1].reg);
16254 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16255 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16256 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16257 inst.instruction |= neon_quad (rs) << 6;
16258
16259 neon_dp_fixup (&inst);
037e8744
JB
16260 }
16261 break;
5f4273c7 16262
037e8744
JB
16263 case NS_DI: /* case 3/11. */
16264 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16265 inst.error = NULL;
16266 if (et.type == NT_float && et.size == 64)
477330fc
RM
16267 {
16268 /* case 11 (fconstd). */
16269 ldconst = "fconstd";
16270 goto encode_fconstd;
16271 }
037e8744
JB
16272 /* fall through. */
16273
16274 case NS_QI: /* case 2/3. */
16275 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16276 return;
037e8744
JB
16277 inst.instruction = 0x0800010;
16278 neon_move_immediate ();
88714cb8 16279 neon_dp_fixup (&inst);
5287ad62 16280 break;
5f4273c7 16281
037e8744
JB
16282 case NS_SR: /* case 4. */
16283 {
477330fc
RM
16284 unsigned bcdebits = 0;
16285 int logsize;
16286 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16287 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16288
05ac0ffb
JB
16289 /* .<size> is optional here, defaulting to .32. */
16290 if (inst.vectype.elems == 0
16291 && inst.operands[0].vectype.type == NT_invtype
16292 && inst.operands[1].vectype.type == NT_invtype)
16293 {
16294 inst.vectype.el[0].type = NT_untyped;
16295 inst.vectype.el[0].size = 32;
16296 inst.vectype.elems = 1;
16297 }
16298
477330fc
RM
16299 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16300 logsize = neon_logbits (et.size);
16301
16302 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16303 _(BAD_FPU));
16304 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16305 && et.size != 32, _(BAD_FPU));
16306 constraint (et.type == NT_invtype, _("bad type for scalar"));
16307 constraint (x >= 64 / et.size, _("scalar index out of range"));
16308
16309 switch (et.size)
16310 {
16311 case 8: bcdebits = 0x8; break;
16312 case 16: bcdebits = 0x1; break;
16313 case 32: bcdebits = 0x0; break;
16314 default: ;
16315 }
16316
16317 bcdebits |= x << logsize;
16318
16319 inst.instruction = 0xe000b10;
16320 do_vfp_cond_or_thumb ();
16321 inst.instruction |= LOW4 (dn) << 16;
16322 inst.instruction |= HI1 (dn) << 7;
16323 inst.instruction |= inst.operands[1].reg << 12;
16324 inst.instruction |= (bcdebits & 3) << 5;
16325 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16326 }
16327 break;
5f4273c7 16328
037e8744 16329 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16330 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16331 _(BAD_FPU));
b7fc2769 16332
037e8744
JB
16333 inst.instruction = 0xc400b10;
16334 do_vfp_cond_or_thumb ();
16335 inst.instruction |= LOW4 (inst.operands[0].reg);
16336 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16337 inst.instruction |= inst.operands[1].reg << 12;
16338 inst.instruction |= inst.operands[2].reg << 16;
16339 break;
5f4273c7 16340
037e8744
JB
16341 case NS_RS: /* case 6. */
16342 {
477330fc
RM
16343 unsigned logsize;
16344 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16345 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16346 unsigned abcdebits = 0;
037e8744 16347
05ac0ffb
JB
16348 /* .<dt> is optional here, defaulting to .32. */
16349 if (inst.vectype.elems == 0
16350 && inst.operands[0].vectype.type == NT_invtype
16351 && inst.operands[1].vectype.type == NT_invtype)
16352 {
16353 inst.vectype.el[0].type = NT_untyped;
16354 inst.vectype.el[0].size = 32;
16355 inst.vectype.elems = 1;
16356 }
16357
91d6fa6a
NC
16358 et = neon_check_type (2, NS_NULL,
16359 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16360 logsize = neon_logbits (et.size);
16361
16362 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16363 _(BAD_FPU));
16364 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16365 && et.size != 32, _(BAD_FPU));
16366 constraint (et.type == NT_invtype, _("bad type for scalar"));
16367 constraint (x >= 64 / et.size, _("scalar index out of range"));
16368
16369 switch (et.size)
16370 {
16371 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16372 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16373 case 32: abcdebits = 0x00; break;
16374 default: ;
16375 }
16376
16377 abcdebits |= x << logsize;
16378 inst.instruction = 0xe100b10;
16379 do_vfp_cond_or_thumb ();
16380 inst.instruction |= LOW4 (dn) << 16;
16381 inst.instruction |= HI1 (dn) << 7;
16382 inst.instruction |= inst.operands[0].reg << 12;
16383 inst.instruction |= (abcdebits & 3) << 5;
16384 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16385 }
16386 break;
5f4273c7 16387
037e8744
JB
16388 case NS_RRD: /* case 7 (fmrrd). */
16389 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16390 _(BAD_FPU));
037e8744
JB
16391
16392 inst.instruction = 0xc500b10;
16393 do_vfp_cond_or_thumb ();
16394 inst.instruction |= inst.operands[0].reg << 12;
16395 inst.instruction |= inst.operands[1].reg << 16;
16396 inst.instruction |= LOW4 (inst.operands[2].reg);
16397 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16398 break;
5f4273c7 16399
037e8744
JB
16400 case NS_FF: /* case 8 (fcpys). */
16401 do_vfp_nsyn_opcode ("fcpys");
16402 break;
5f4273c7 16403
9db2f6b4 16404 case NS_HI:
037e8744
JB
16405 case NS_FI: /* case 10 (fconsts). */
16406 ldconst = "fconsts";
16407 encode_fconstd:
16408 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16409 {
16410 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16411 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16412
16413 /* ARMv8.2 fp16 vmov.f16 instruction. */
16414 if (rs == NS_HI)
16415 do_scalar_fp16_v82_encode ();
477330fc 16416 }
5287ad62 16417 else
477330fc 16418 first_error (_("immediate out of range"));
037e8744 16419 break;
5f4273c7 16420
9db2f6b4 16421 case NS_RH:
037e8744
JB
16422 case NS_RF: /* case 12 (fmrs). */
16423 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16424 /* ARMv8.2 fp16 vmov.f16 instruction. */
16425 if (rs == NS_RH)
16426 do_scalar_fp16_v82_encode ();
037e8744 16427 break;
5f4273c7 16428
9db2f6b4 16429 case NS_HR:
037e8744
JB
16430 case NS_FR: /* case 13 (fmsr). */
16431 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16432 /* ARMv8.2 fp16 vmov.f16 instruction. */
16433 if (rs == NS_HR)
16434 do_scalar_fp16_v82_encode ();
037e8744 16435 break;
5f4273c7 16436
037e8744
JB
16437 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16438 (one of which is a list), but we have parsed four. Do some fiddling to
16439 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16440 expect. */
16441 case NS_RRFF: /* case 14 (fmrrs). */
16442 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16443 _("VFP registers must be adjacent"));
037e8744
JB
16444 inst.operands[2].imm = 2;
16445 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16446 do_vfp_nsyn_opcode ("fmrrs");
16447 break;
5f4273c7 16448
037e8744
JB
16449 case NS_FFRR: /* case 15 (fmsrr). */
16450 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16451 _("VFP registers must be adjacent"));
037e8744
JB
16452 inst.operands[1] = inst.operands[2];
16453 inst.operands[2] = inst.operands[3];
16454 inst.operands[0].imm = 2;
16455 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16456 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16457 break;
5f4273c7 16458
4c261dff
NC
16459 case NS_NULL:
16460 /* neon_select_shape has determined that the instruction
16461 shape is wrong and has already set the error message. */
16462 break;
16463
5287ad62
JB
16464 default:
16465 abort ();
16466 }
16467}
16468
16469static void
16470do_neon_rshift_round_imm (void)
16471{
037e8744 16472 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16473 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16474 int imm = inst.operands[2].imm;
16475
16476 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16477 if (imm == 0)
16478 {
16479 inst.operands[2].present = 0;
16480 do_neon_mov ();
16481 return;
16482 }
16483
16484 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16485 _("immediate out of range for shift"));
037e8744 16486 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16487 et.size - imm);
5287ad62
JB
16488}
16489
9db2f6b4
RL
16490static void
16491do_neon_movhf (void)
16492{
16493 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16494 constraint (rs != NS_HH, _("invalid suffix"));
16495
16496 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16497 _(BAD_FPU));
16498
16499 do_vfp_sp_monadic ();
16500
16501 inst.is_neon = 1;
16502 inst.instruction |= 0xf0000000;
16503}
16504
5287ad62
JB
16505static void
16506do_neon_movl (void)
16507{
16508 struct neon_type_el et = neon_check_type (2, NS_QD,
16509 N_EQK | N_DBL, N_SU_32 | N_KEY);
16510 unsigned sizebits = et.size >> 3;
16511 inst.instruction |= sizebits << 19;
16512 neon_two_same (0, et.type == NT_unsigned, -1);
16513}
16514
16515static void
16516do_neon_trn (void)
16517{
037e8744 16518 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16519 struct neon_type_el et = neon_check_type (2, rs,
16520 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16521 NEON_ENCODE (INTEGER, inst);
037e8744 16522 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16523}
16524
16525static void
16526do_neon_zip_uzp (void)
16527{
037e8744 16528 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16529 struct neon_type_el et = neon_check_type (2, rs,
16530 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16531 if (rs == NS_DD && et.size == 32)
16532 {
16533 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16534 inst.instruction = N_MNEM_vtrn;
16535 do_neon_trn ();
16536 return;
16537 }
037e8744 16538 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16539}
16540
16541static void
16542do_neon_sat_abs_neg (void)
16543{
037e8744 16544 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16545 struct neon_type_el et = neon_check_type (2, rs,
16546 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16547 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16548}
16549
16550static void
16551do_neon_pair_long (void)
16552{
037e8744 16553 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16554 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16555 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16556 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16557 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16558}
16559
16560static void
16561do_neon_recip_est (void)
16562{
037e8744 16563 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16564 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16565 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16566 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16567 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16568}
16569
16570static void
16571do_neon_cls (void)
16572{
037e8744 16573 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16574 struct neon_type_el et = neon_check_type (2, rs,
16575 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16576 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16577}
16578
16579static void
16580do_neon_clz (void)
16581{
037e8744 16582 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16583 struct neon_type_el et = neon_check_type (2, rs,
16584 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16585 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16586}
16587
16588static void
16589do_neon_cnt (void)
16590{
037e8744 16591 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16592 struct neon_type_el et = neon_check_type (2, rs,
16593 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16594 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16595}
16596
16597static void
16598do_neon_swp (void)
16599{
037e8744
JB
16600 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16601 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16602}
16603
16604static void
16605do_neon_tbl_tbx (void)
16606{
16607 unsigned listlenbits;
dcbf9037 16608 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16609
5287ad62
JB
16610 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16611 {
dcbf9037 16612 first_error (_("bad list length for table lookup"));
5287ad62
JB
16613 return;
16614 }
5f4273c7 16615
5287ad62
JB
16616 listlenbits = inst.operands[1].imm - 1;
16617 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16618 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16619 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16620 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16621 inst.instruction |= LOW4 (inst.operands[2].reg);
16622 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16623 inst.instruction |= listlenbits << 8;
5f4273c7 16624
88714cb8 16625 neon_dp_fixup (&inst);
5287ad62
JB
16626}
16627
16628static void
16629do_neon_ldm_stm (void)
16630{
16631 /* P, U and L bits are part of bitmask. */
16632 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16633 unsigned offsetbits = inst.operands[1].imm * 2;
16634
037e8744
JB
16635 if (inst.operands[1].issingle)
16636 {
16637 do_vfp_nsyn_ldm_stm (is_dbmode);
16638 return;
16639 }
16640
5287ad62 16641 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16642 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16643
16644 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16645 _("register list must contain at least 1 and at most 16 "
16646 "registers"));
5287ad62
JB
16647
16648 inst.instruction |= inst.operands[0].reg << 16;
16649 inst.instruction |= inst.operands[0].writeback << 21;
16650 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16651 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16652
16653 inst.instruction |= offsetbits;
5f4273c7 16654
037e8744 16655 do_vfp_cond_or_thumb ();
5287ad62
JB
16656}
16657
16658static void
16659do_neon_ldr_str (void)
16660{
5287ad62 16661 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16662
6844b2c2
MGD
16663 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16664 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16665 if (!is_ldr
6844b2c2 16666 && inst.operands[1].reg == REG_PC
ba86b375 16667 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16668 {
94dcf8bf 16669 if (thumb_mode)
6844b2c2 16670 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16671 else if (warn_on_deprecated)
5c3696f8 16672 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16673 }
16674
037e8744
JB
16675 if (inst.operands[0].issingle)
16676 {
cd2f129f 16677 if (is_ldr)
477330fc 16678 do_vfp_nsyn_opcode ("flds");
cd2f129f 16679 else
477330fc 16680 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16681
16682 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16683 if (inst.vectype.el[0].size == 16)
16684 do_scalar_fp16_v82_encode ();
5287ad62
JB
16685 }
16686 else
5287ad62 16687 {
cd2f129f 16688 if (is_ldr)
477330fc 16689 do_vfp_nsyn_opcode ("fldd");
5287ad62 16690 else
477330fc 16691 do_vfp_nsyn_opcode ("fstd");
5287ad62 16692 }
5287ad62
JB
16693}
16694
16695/* "interleave" version also handles non-interleaving register VLD1/VST1
16696 instructions. */
16697
16698static void
16699do_neon_ld_st_interleave (void)
16700{
037e8744 16701 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16702 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16703 unsigned alignbits = 0;
16704 unsigned idx;
16705 /* The bits in this table go:
16706 0: register stride of one (0) or two (1)
16707 1,2: register list length, minus one (1, 2, 3, 4).
16708 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16709 We use -1 for invalid entries. */
16710 const int typetable[] =
16711 {
16712 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16713 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16714 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16715 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16716 };
16717 int typebits;
16718
dcbf9037
JB
16719 if (et.type == NT_invtype)
16720 return;
16721
5287ad62
JB
16722 if (inst.operands[1].immisalign)
16723 switch (inst.operands[1].imm >> 8)
16724 {
16725 case 64: alignbits = 1; break;
16726 case 128:
477330fc 16727 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16728 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16729 goto bad_alignment;
16730 alignbits = 2;
16731 break;
5287ad62 16732 case 256:
477330fc
RM
16733 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16734 goto bad_alignment;
16735 alignbits = 3;
16736 break;
5287ad62
JB
16737 default:
16738 bad_alignment:
477330fc
RM
16739 first_error (_("bad alignment"));
16740 return;
5287ad62
JB
16741 }
16742
16743 inst.instruction |= alignbits << 4;
16744 inst.instruction |= neon_logbits (et.size) << 6;
16745
16746 /* Bits [4:6] of the immediate in a list specifier encode register stride
16747 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16748 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16749 up the right value for "type" in a table based on this value and the given
16750 list style, then stick it back. */
16751 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16752 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16753
16754 typebits = typetable[idx];
5f4273c7 16755
5287ad62 16756 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16757 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16758 _("bad element type for instruction"));
5287ad62
JB
16759
16760 inst.instruction &= ~0xf00;
16761 inst.instruction |= typebits << 8;
16762}
16763
16764/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16765 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16766 otherwise. The variable arguments are a list of pairs of legal (size, align)
16767 values, terminated with -1. */
16768
16769static int
aa8a0863 16770neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16771{
16772 va_list ap;
16773 int result = FAIL, thissize, thisalign;
5f4273c7 16774
5287ad62
JB
16775 if (!inst.operands[1].immisalign)
16776 {
aa8a0863 16777 *do_alignment = 0;
5287ad62
JB
16778 return SUCCESS;
16779 }
5f4273c7 16780
aa8a0863 16781 va_start (ap, do_alignment);
5287ad62
JB
16782
16783 do
16784 {
16785 thissize = va_arg (ap, int);
16786 if (thissize == -1)
477330fc 16787 break;
5287ad62
JB
16788 thisalign = va_arg (ap, int);
16789
16790 if (size == thissize && align == thisalign)
477330fc 16791 result = SUCCESS;
5287ad62
JB
16792 }
16793 while (result != SUCCESS);
16794
16795 va_end (ap);
16796
16797 if (result == SUCCESS)
aa8a0863 16798 *do_alignment = 1;
5287ad62 16799 else
dcbf9037 16800 first_error (_("unsupported alignment for instruction"));
5f4273c7 16801
5287ad62
JB
16802 return result;
16803}
16804
16805static void
16806do_neon_ld_st_lane (void)
16807{
037e8744 16808 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16809 int align_good, do_alignment = 0;
5287ad62
JB
16810 int logsize = neon_logbits (et.size);
16811 int align = inst.operands[1].imm >> 8;
16812 int n = (inst.instruction >> 8) & 3;
16813 int max_el = 64 / et.size;
5f4273c7 16814
dcbf9037
JB
16815 if (et.type == NT_invtype)
16816 return;
5f4273c7 16817
5287ad62 16818 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16819 _("bad list length"));
5287ad62 16820 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16821 _("scalar index out of range"));
5287ad62 16822 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16823 && et.size == 8,
16824 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16825
5287ad62
JB
16826 switch (n)
16827 {
16828 case 0: /* VLD1 / VST1. */
aa8a0863 16829 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16830 32, 32, -1);
5287ad62 16831 if (align_good == FAIL)
477330fc 16832 return;
aa8a0863 16833 if (do_alignment)
477330fc
RM
16834 {
16835 unsigned alignbits = 0;
16836 switch (et.size)
16837 {
16838 case 16: alignbits = 0x1; break;
16839 case 32: alignbits = 0x3; break;
16840 default: ;
16841 }
16842 inst.instruction |= alignbits << 4;
16843 }
5287ad62
JB
16844 break;
16845
16846 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16847 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16848 16, 32, 32, 64, -1);
5287ad62 16849 if (align_good == FAIL)
477330fc 16850 return;
aa8a0863 16851 if (do_alignment)
477330fc 16852 inst.instruction |= 1 << 4;
5287ad62
JB
16853 break;
16854
16855 case 2: /* VLD3 / VST3. */
16856 constraint (inst.operands[1].immisalign,
477330fc 16857 _("can't use alignment with this instruction"));
5287ad62
JB
16858 break;
16859
16860 case 3: /* VLD4 / VST4. */
aa8a0863 16861 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16862 16, 64, 32, 64, 32, 128, -1);
5287ad62 16863 if (align_good == FAIL)
477330fc 16864 return;
aa8a0863 16865 if (do_alignment)
477330fc
RM
16866 {
16867 unsigned alignbits = 0;
16868 switch (et.size)
16869 {
16870 case 8: alignbits = 0x1; break;
16871 case 16: alignbits = 0x1; break;
16872 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16873 default: ;
16874 }
16875 inst.instruction |= alignbits << 4;
16876 }
5287ad62
JB
16877 break;
16878
16879 default: ;
16880 }
16881
16882 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16883 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16884 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16885
5287ad62
JB
16886 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16887 inst.instruction |= logsize << 10;
16888}
16889
16890/* Encode single n-element structure to all lanes VLD<n> instructions. */
16891
16892static void
16893do_neon_ld_dup (void)
16894{
037e8744 16895 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16896 int align_good, do_alignment = 0;
5287ad62 16897
dcbf9037
JB
16898 if (et.type == NT_invtype)
16899 return;
16900
5287ad62
JB
16901 switch ((inst.instruction >> 8) & 3)
16902 {
16903 case 0: /* VLD1. */
9c2799c2 16904 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16905 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16906 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16907 if (align_good == FAIL)
477330fc 16908 return;
5287ad62 16909 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16910 {
16911 case 1: break;
16912 case 2: inst.instruction |= 1 << 5; break;
16913 default: first_error (_("bad list length")); return;
16914 }
5287ad62
JB
16915 inst.instruction |= neon_logbits (et.size) << 6;
16916 break;
16917
16918 case 1: /* VLD2. */
16919 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16920 &do_alignment, 8, 16, 16, 32, 32, 64,
16921 -1);
5287ad62 16922 if (align_good == FAIL)
477330fc 16923 return;
5287ad62 16924 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16925 _("bad list length"));
5287ad62 16926 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16927 inst.instruction |= 1 << 5;
5287ad62
JB
16928 inst.instruction |= neon_logbits (et.size) << 6;
16929 break;
16930
16931 case 2: /* VLD3. */
16932 constraint (inst.operands[1].immisalign,
477330fc 16933 _("can't use alignment with this instruction"));
5287ad62 16934 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16935 _("bad list length"));
5287ad62 16936 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16937 inst.instruction |= 1 << 5;
5287ad62
JB
16938 inst.instruction |= neon_logbits (et.size) << 6;
16939 break;
16940
16941 case 3: /* VLD4. */
16942 {
477330fc 16943 int align = inst.operands[1].imm >> 8;
aa8a0863 16944 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
16945 16, 64, 32, 64, 32, 128, -1);
16946 if (align_good == FAIL)
16947 return;
16948 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16949 _("bad list length"));
16950 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16951 inst.instruction |= 1 << 5;
16952 if (et.size == 32 && align == 128)
16953 inst.instruction |= 0x3 << 6;
16954 else
16955 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16956 }
16957 break;
16958
16959 default: ;
16960 }
16961
aa8a0863 16962 inst.instruction |= do_alignment << 4;
5287ad62
JB
16963}
16964
16965/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16966 apart from bits [11:4]. */
16967
16968static void
16969do_neon_ldx_stx (void)
16970{
b1a769ed
DG
16971 if (inst.operands[1].isreg)
16972 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16973
5287ad62
JB
16974 switch (NEON_LANE (inst.operands[0].imm))
16975 {
16976 case NEON_INTERLEAVE_LANES:
88714cb8 16977 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16978 do_neon_ld_st_interleave ();
16979 break;
5f4273c7 16980
5287ad62 16981 case NEON_ALL_LANES:
88714cb8 16982 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16983 if (inst.instruction == N_INV)
16984 {
16985 first_error ("only loads support such operands");
16986 break;
16987 }
5287ad62
JB
16988 do_neon_ld_dup ();
16989 break;
5f4273c7 16990
5287ad62 16991 default:
88714cb8 16992 NEON_ENCODE (LANE, inst);
5287ad62
JB
16993 do_neon_ld_st_lane ();
16994 }
16995
16996 /* L bit comes from bit mask. */
16997 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16998 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16999 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17000
5287ad62
JB
17001 if (inst.operands[1].postind)
17002 {
17003 int postreg = inst.operands[1].imm & 0xf;
17004 constraint (!inst.operands[1].immisreg,
477330fc 17005 _("post-index must be a register"));
5287ad62 17006 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17007 _("bad register for post-index"));
5287ad62
JB
17008 inst.instruction |= postreg;
17009 }
4f2374c7 17010 else
5287ad62 17011 {
4f2374c7
WN
17012 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17013 constraint (inst.reloc.exp.X_op != O_constant
17014 || inst.reloc.exp.X_add_number != 0,
17015 BAD_ADDR_MODE);
17016
17017 if (inst.operands[1].writeback)
17018 {
17019 inst.instruction |= 0xd;
17020 }
17021 else
17022 inst.instruction |= 0xf;
5287ad62 17023 }
5f4273c7 17024
5287ad62
JB
17025 if (thumb_mode)
17026 inst.instruction |= 0xf9000000;
17027 else
17028 inst.instruction |= 0xf4000000;
17029}
33399f07
MGD
17030
17031/* FP v8. */
17032static void
17033do_vfp_nsyn_fpv8 (enum neon_shape rs)
17034{
a715796b
TG
17035 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17036 D register operands. */
17037 if (neon_shape_class[rs] == SC_DOUBLE)
17038 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17039 _(BAD_FPU));
17040
33399f07
MGD
17041 NEON_ENCODE (FPV8, inst);
17042
9db2f6b4
RL
17043 if (rs == NS_FFF || rs == NS_HHH)
17044 {
17045 do_vfp_sp_dyadic ();
17046
17047 /* ARMv8.2 fp16 instruction. */
17048 if (rs == NS_HHH)
17049 do_scalar_fp16_v82_encode ();
17050 }
33399f07
MGD
17051 else
17052 do_vfp_dp_rd_rn_rm ();
17053
17054 if (rs == NS_DDD)
17055 inst.instruction |= 0x100;
17056
17057 inst.instruction |= 0xf0000000;
17058}
17059
17060static void
17061do_vsel (void)
17062{
17063 set_it_insn_type (OUTSIDE_IT_INSN);
17064
17065 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17066 first_error (_("invalid instruction shape"));
17067}
17068
73924fbc
MGD
17069static void
17070do_vmaxnm (void)
17071{
17072 set_it_insn_type (OUTSIDE_IT_INSN);
17073
17074 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17075 return;
17076
17077 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17078 return;
17079
cc933301 17080 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17081}
17082
30bdf752
MGD
17083static void
17084do_vrint_1 (enum neon_cvt_mode mode)
17085{
9db2f6b4 17086 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17087 struct neon_type_el et;
17088
17089 if (rs == NS_NULL)
17090 return;
17091
a715796b
TG
17092 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17093 D register operands. */
17094 if (neon_shape_class[rs] == SC_DOUBLE)
17095 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17096 _(BAD_FPU));
17097
9db2f6b4
RL
17098 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17099 | N_VFP);
30bdf752
MGD
17100 if (et.type != NT_invtype)
17101 {
17102 /* VFP encodings. */
17103 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17104 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17105 set_it_insn_type (OUTSIDE_IT_INSN);
17106
17107 NEON_ENCODE (FPV8, inst);
9db2f6b4 17108 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17109 do_vfp_sp_monadic ();
17110 else
17111 do_vfp_dp_rd_rm ();
17112
17113 switch (mode)
17114 {
17115 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17116 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17117 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17118 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17119 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17120 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17121 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17122 default: abort ();
17123 }
17124
17125 inst.instruction |= (rs == NS_DD) << 8;
17126 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17127
17128 /* ARMv8.2 fp16 vrint instruction. */
17129 if (rs == NS_HH)
17130 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17131 }
17132 else
17133 {
17134 /* Neon encodings (or something broken...). */
17135 inst.error = NULL;
cc933301 17136 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17137
17138 if (et.type == NT_invtype)
17139 return;
17140
17141 set_it_insn_type (OUTSIDE_IT_INSN);
17142 NEON_ENCODE (FLOAT, inst);
17143
17144 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17145 return;
17146
17147 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17148 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17149 inst.instruction |= LOW4 (inst.operands[1].reg);
17150 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17151 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17152 /* Mask off the original size bits and reencode them. */
17153 inst.instruction = ((inst.instruction & 0xfff3ffff)
17154 | neon_logbits (et.size) << 18);
17155
30bdf752
MGD
17156 switch (mode)
17157 {
17158 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17159 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17160 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17161 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17162 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17163 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17164 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17165 default: abort ();
17166 }
17167
17168 if (thumb_mode)
17169 inst.instruction |= 0xfc000000;
17170 else
17171 inst.instruction |= 0xf0000000;
17172 }
17173}
17174
17175static void
17176do_vrintx (void)
17177{
17178 do_vrint_1 (neon_cvt_mode_x);
17179}
17180
17181static void
17182do_vrintz (void)
17183{
17184 do_vrint_1 (neon_cvt_mode_z);
17185}
17186
17187static void
17188do_vrintr (void)
17189{
17190 do_vrint_1 (neon_cvt_mode_r);
17191}
17192
17193static void
17194do_vrinta (void)
17195{
17196 do_vrint_1 (neon_cvt_mode_a);
17197}
17198
17199static void
17200do_vrintn (void)
17201{
17202 do_vrint_1 (neon_cvt_mode_n);
17203}
17204
17205static void
17206do_vrintp (void)
17207{
17208 do_vrint_1 (neon_cvt_mode_p);
17209}
17210
17211static void
17212do_vrintm (void)
17213{
17214 do_vrint_1 (neon_cvt_mode_m);
17215}
17216
91ff7894
MGD
17217/* Crypto v1 instructions. */
17218static void
17219do_crypto_2op_1 (unsigned elttype, int op)
17220{
17221 set_it_insn_type (OUTSIDE_IT_INSN);
17222
17223 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17224 == NT_invtype)
17225 return;
17226
17227 inst.error = NULL;
17228
17229 NEON_ENCODE (INTEGER, inst);
17230 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17231 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17232 inst.instruction |= LOW4 (inst.operands[1].reg);
17233 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17234 if (op != -1)
17235 inst.instruction |= op << 6;
17236
17237 if (thumb_mode)
17238 inst.instruction |= 0xfc000000;
17239 else
17240 inst.instruction |= 0xf0000000;
17241}
17242
48adcd8e
MGD
17243static void
17244do_crypto_3op_1 (int u, int op)
17245{
17246 set_it_insn_type (OUTSIDE_IT_INSN);
17247
17248 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17249 N_32 | N_UNT | N_KEY).type == NT_invtype)
17250 return;
17251
17252 inst.error = NULL;
17253
17254 NEON_ENCODE (INTEGER, inst);
17255 neon_three_same (1, u, 8 << op);
17256}
17257
91ff7894
MGD
17258static void
17259do_aese (void)
17260{
17261 do_crypto_2op_1 (N_8, 0);
17262}
17263
17264static void
17265do_aesd (void)
17266{
17267 do_crypto_2op_1 (N_8, 1);
17268}
17269
17270static void
17271do_aesmc (void)
17272{
17273 do_crypto_2op_1 (N_8, 2);
17274}
17275
17276static void
17277do_aesimc (void)
17278{
17279 do_crypto_2op_1 (N_8, 3);
17280}
17281
48adcd8e
MGD
17282static void
17283do_sha1c (void)
17284{
17285 do_crypto_3op_1 (0, 0);
17286}
17287
17288static void
17289do_sha1p (void)
17290{
17291 do_crypto_3op_1 (0, 1);
17292}
17293
17294static void
17295do_sha1m (void)
17296{
17297 do_crypto_3op_1 (0, 2);
17298}
17299
17300static void
17301do_sha1su0 (void)
17302{
17303 do_crypto_3op_1 (0, 3);
17304}
91ff7894 17305
48adcd8e
MGD
17306static void
17307do_sha256h (void)
17308{
17309 do_crypto_3op_1 (1, 0);
17310}
17311
17312static void
17313do_sha256h2 (void)
17314{
17315 do_crypto_3op_1 (1, 1);
17316}
17317
17318static void
17319do_sha256su1 (void)
17320{
17321 do_crypto_3op_1 (1, 2);
17322}
3c9017d2
MGD
17323
17324static void
17325do_sha1h (void)
17326{
17327 do_crypto_2op_1 (N_32, -1);
17328}
17329
17330static void
17331do_sha1su1 (void)
17332{
17333 do_crypto_2op_1 (N_32, 0);
17334}
17335
17336static void
17337do_sha256su0 (void)
17338{
17339 do_crypto_2op_1 (N_32, 1);
17340}
dd5181d5
KT
17341
17342static void
17343do_crc32_1 (unsigned int poly, unsigned int sz)
17344{
17345 unsigned int Rd = inst.operands[0].reg;
17346 unsigned int Rn = inst.operands[1].reg;
17347 unsigned int Rm = inst.operands[2].reg;
17348
17349 set_it_insn_type (OUTSIDE_IT_INSN);
17350 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17351 inst.instruction |= LOW4 (Rn) << 16;
17352 inst.instruction |= LOW4 (Rm);
17353 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17354 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17355
17356 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17357 as_warn (UNPRED_REG ("r15"));
17358 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17359 as_warn (UNPRED_REG ("r13"));
17360}
17361
17362static void
17363do_crc32b (void)
17364{
17365 do_crc32_1 (0, 0);
17366}
17367
17368static void
17369do_crc32h (void)
17370{
17371 do_crc32_1 (0, 1);
17372}
17373
17374static void
17375do_crc32w (void)
17376{
17377 do_crc32_1 (0, 2);
17378}
17379
17380static void
17381do_crc32cb (void)
17382{
17383 do_crc32_1 (1, 0);
17384}
17385
17386static void
17387do_crc32ch (void)
17388{
17389 do_crc32_1 (1, 1);
17390}
17391
17392static void
17393do_crc32cw (void)
17394{
17395 do_crc32_1 (1, 2);
17396}
17397
5287ad62
JB
17398\f
17399/* Overall per-instruction processing. */
17400
17401/* We need to be able to fix up arbitrary expressions in some statements.
17402 This is so that we can handle symbols that are an arbitrary distance from
17403 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17404 which returns part of an address in a form which will be valid for
17405 a data instruction. We do this by pushing the expression into a symbol
17406 in the expr_section, and creating a fix for that. */
17407
17408static void
17409fix_new_arm (fragS * frag,
17410 int where,
17411 short int size,
17412 expressionS * exp,
17413 int pc_rel,
17414 int reloc)
17415{
17416 fixS * new_fix;
17417
17418 switch (exp->X_op)
17419 {
17420 case O_constant:
6e7ce2cd
PB
17421 if (pc_rel)
17422 {
17423 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17424 refer to in the object file. Unfortunately for us, gas's
17425 generic expression parsing will already have folded out
17426 any use of .set foo/.type foo %function that may have
17427 been used to set type information of the target location,
17428 that's being specified symbolically. We have to presume
17429 the user knows what they are doing. */
6e7ce2cd
PB
17430 char name[16 + 8];
17431 symbolS *symbol;
17432
17433 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17434
17435 symbol = symbol_find_or_make (name);
17436 S_SET_SEGMENT (symbol, absolute_section);
17437 symbol_set_frag (symbol, &zero_address_frag);
17438 S_SET_VALUE (symbol, exp->X_add_number);
17439 exp->X_op = O_symbol;
17440 exp->X_add_symbol = symbol;
17441 exp->X_add_number = 0;
17442 }
17443 /* FALLTHROUGH */
5287ad62
JB
17444 case O_symbol:
17445 case O_add:
17446 case O_subtract:
21d799b5 17447 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17448 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17449 break;
17450
17451 default:
21d799b5 17452 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17453 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17454 break;
17455 }
17456
17457 /* Mark whether the fix is to a THUMB instruction, or an ARM
17458 instruction. */
17459 new_fix->tc_fix_data = thumb_mode;
17460}
17461
17462/* Create a frg for an instruction requiring relaxation. */
17463static void
17464output_relax_insn (void)
17465{
17466 char * to;
17467 symbolS *sym;
0110f2b8
PB
17468 int offset;
17469
6e1cb1a6
PB
17470 /* The size of the instruction is unknown, so tie the debug info to the
17471 start of the instruction. */
17472 dwarf2_emit_insn (0);
6e1cb1a6 17473
0110f2b8
PB
17474 switch (inst.reloc.exp.X_op)
17475 {
17476 case O_symbol:
17477 sym = inst.reloc.exp.X_add_symbol;
17478 offset = inst.reloc.exp.X_add_number;
17479 break;
17480 case O_constant:
17481 sym = NULL;
17482 offset = inst.reloc.exp.X_add_number;
17483 break;
17484 default:
17485 sym = make_expr_symbol (&inst.reloc.exp);
17486 offset = 0;
17487 break;
17488 }
17489 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17490 inst.relax, sym, offset, NULL/*offset, opcode*/);
17491 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17492}
17493
17494/* Write a 32-bit thumb instruction to buf. */
17495static void
17496put_thumb32_insn (char * buf, unsigned long insn)
17497{
17498 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17499 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17500}
17501
b99bd4ef 17502static void
c19d1205 17503output_inst (const char * str)
b99bd4ef 17504{
c19d1205 17505 char * to = NULL;
b99bd4ef 17506
c19d1205 17507 if (inst.error)
b99bd4ef 17508 {
c19d1205 17509 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17510 return;
17511 }
5f4273c7
NC
17512 if (inst.relax)
17513 {
17514 output_relax_insn ();
0110f2b8 17515 return;
5f4273c7 17516 }
c19d1205
ZW
17517 if (inst.size == 0)
17518 return;
b99bd4ef 17519
c19d1205 17520 to = frag_more (inst.size);
8dc2430f
NC
17521 /* PR 9814: Record the thumb mode into the current frag so that we know
17522 what type of NOP padding to use, if necessary. We override any previous
17523 setting so that if the mode has changed then the NOPS that we use will
17524 match the encoding of the last instruction in the frag. */
cd000bff 17525 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17526
17527 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17528 {
9c2799c2 17529 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17530 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17531 }
c19d1205 17532 else if (inst.size > INSN_SIZE)
b99bd4ef 17533 {
9c2799c2 17534 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17535 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17536 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17537 }
c19d1205
ZW
17538 else
17539 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17540
c19d1205
ZW
17541 if (inst.reloc.type != BFD_RELOC_UNUSED)
17542 fix_new_arm (frag_now, to - frag_now->fr_literal,
17543 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17544 inst.reloc.type);
b99bd4ef 17545
c19d1205 17546 dwarf2_emit_insn (inst.size);
c19d1205 17547}
b99bd4ef 17548
e07e6e58
NC
17549static char *
17550output_it_inst (int cond, int mask, char * to)
17551{
17552 unsigned long instruction = 0xbf00;
17553
17554 mask &= 0xf;
17555 instruction |= mask;
17556 instruction |= cond << 4;
17557
17558 if (to == NULL)
17559 {
17560 to = frag_more (2);
17561#ifdef OBJ_ELF
17562 dwarf2_emit_insn (2);
17563#endif
17564 }
17565
17566 md_number_to_chars (to, instruction, 2);
17567
17568 return to;
17569}
17570
c19d1205
ZW
17571/* Tag values used in struct asm_opcode's tag field. */
17572enum opcode_tag
17573{
17574 OT_unconditional, /* Instruction cannot be conditionalized.
17575 The ARM condition field is still 0xE. */
17576 OT_unconditionalF, /* Instruction cannot be conditionalized
17577 and carries 0xF in its ARM condition field. */
17578 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17579 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17580 suffix, others place 0xF where the condition field
17581 would be. */
c19d1205
ZW
17582 OT_cinfix3, /* Instruction takes a conditional infix,
17583 beginning at character index 3. (In
17584 unified mode, it becomes a suffix.) */
088fa78e
KH
17585 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17586 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17587 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17588 character index 3, even in unified mode. Used for
17589 legacy instructions where suffix and infix forms
17590 may be ambiguous. */
c19d1205 17591 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17592 suffix or an infix at character index 3. */
c19d1205
ZW
17593 OT_odd_infix_unc, /* This is the unconditional variant of an
17594 instruction that takes a conditional infix
17595 at an unusual position. In unified mode,
17596 this variant will accept a suffix. */
17597 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17598 are the conditional variants of instructions that
17599 take conditional infixes in unusual positions.
17600 The infix appears at character index
17601 (tag - OT_odd_infix_0). These are not accepted
17602 in unified mode. */
17603};
b99bd4ef 17604
c19d1205
ZW
17605/* Subroutine of md_assemble, responsible for looking up the primary
17606 opcode from the mnemonic the user wrote. STR points to the
17607 beginning of the mnemonic.
17608
17609 This is not simply a hash table lookup, because of conditional
17610 variants. Most instructions have conditional variants, which are
17611 expressed with a _conditional affix_ to the mnemonic. If we were
17612 to encode each conditional variant as a literal string in the opcode
17613 table, it would have approximately 20,000 entries.
17614
17615 Most mnemonics take this affix as a suffix, and in unified syntax,
17616 'most' is upgraded to 'all'. However, in the divided syntax, some
17617 instructions take the affix as an infix, notably the s-variants of
17618 the arithmetic instructions. Of those instructions, all but six
17619 have the infix appear after the third character of the mnemonic.
17620
17621 Accordingly, the algorithm for looking up primary opcodes given
17622 an identifier is:
17623
17624 1. Look up the identifier in the opcode table.
17625 If we find a match, go to step U.
17626
17627 2. Look up the last two characters of the identifier in the
17628 conditions table. If we find a match, look up the first N-2
17629 characters of the identifier in the opcode table. If we
17630 find a match, go to step CE.
17631
17632 3. Look up the fourth and fifth characters of the identifier in
17633 the conditions table. If we find a match, extract those
17634 characters from the identifier, and look up the remaining
17635 characters in the opcode table. If we find a match, go
17636 to step CM.
17637
17638 4. Fail.
17639
17640 U. Examine the tag field of the opcode structure, in case this is
17641 one of the six instructions with its conditional infix in an
17642 unusual place. If it is, the tag tells us where to find the
17643 infix; look it up in the conditions table and set inst.cond
17644 accordingly. Otherwise, this is an unconditional instruction.
17645 Again set inst.cond accordingly. Return the opcode structure.
17646
17647 CE. Examine the tag field to make sure this is an instruction that
17648 should receive a conditional suffix. If it is not, fail.
17649 Otherwise, set inst.cond from the suffix we already looked up,
17650 and return the opcode structure.
17651
17652 CM. Examine the tag field to make sure this is an instruction that
17653 should receive a conditional infix after the third character.
17654 If it is not, fail. Otherwise, undo the edits to the current
17655 line of input and proceed as for case CE. */
17656
17657static const struct asm_opcode *
17658opcode_lookup (char **str)
17659{
17660 char *end, *base;
17661 char *affix;
17662 const struct asm_opcode *opcode;
17663 const struct asm_cond *cond;
e3cb604e 17664 char save[2];
c19d1205
ZW
17665
17666 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17667 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17668 for (base = end = *str; *end != '\0'; end++)
721a8186 17669 if (*end == ' ' || *end == '.')
c19d1205 17670 break;
b99bd4ef 17671
c19d1205 17672 if (end == base)
c921be7d 17673 return NULL;
b99bd4ef 17674
5287ad62 17675 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17676 if (end[0] == '.')
b99bd4ef 17677 {
5287ad62 17678 int offset = 2;
5f4273c7 17679
267d2029 17680 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17681 use. */
267d2029 17682 if (unified_syntax && end[1] == 'w')
c19d1205 17683 inst.size_req = 4;
267d2029 17684 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17685 inst.size_req = 2;
17686 else
477330fc 17687 offset = 0;
5287ad62
JB
17688
17689 inst.vectype.elems = 0;
17690
17691 *str = end + offset;
b99bd4ef 17692
5f4273c7 17693 if (end[offset] == '.')
5287ad62 17694 {
267d2029 17695 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17696 non-unified ARM syntax mode). */
17697 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17698 return NULL;
477330fc 17699 }
5287ad62 17700 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17701 return NULL;
b99bd4ef 17702 }
c19d1205
ZW
17703 else
17704 *str = end;
b99bd4ef 17705
c19d1205 17706 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17707 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17708 end - base);
c19d1205 17709 if (opcode)
b99bd4ef 17710 {
c19d1205
ZW
17711 /* step U */
17712 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17713 {
c19d1205
ZW
17714 inst.cond = COND_ALWAYS;
17715 return opcode;
b99bd4ef 17716 }
b99bd4ef 17717
278df34e 17718 if (warn_on_deprecated && unified_syntax)
5c3696f8 17719 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17720 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17721 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17722 gas_assert (cond);
b99bd4ef 17723
c19d1205
ZW
17724 inst.cond = cond->value;
17725 return opcode;
17726 }
b99bd4ef 17727
c19d1205
ZW
17728 /* Cannot have a conditional suffix on a mnemonic of less than two
17729 characters. */
17730 if (end - base < 3)
c921be7d 17731 return NULL;
b99bd4ef 17732
c19d1205
ZW
17733 /* Look for suffixed mnemonic. */
17734 affix = end - 2;
21d799b5
NC
17735 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17736 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17737 affix - base);
c19d1205
ZW
17738 if (opcode && cond)
17739 {
17740 /* step CE */
17741 switch (opcode->tag)
17742 {
e3cb604e
PB
17743 case OT_cinfix3_legacy:
17744 /* Ignore conditional suffixes matched on infix only mnemonics. */
17745 break;
17746
c19d1205 17747 case OT_cinfix3:
088fa78e 17748 case OT_cinfix3_deprecated:
c19d1205
ZW
17749 case OT_odd_infix_unc:
17750 if (!unified_syntax)
e3cb604e 17751 return 0;
c19d1205
ZW
17752 /* else fall through */
17753
17754 case OT_csuffix:
477330fc 17755 case OT_csuffixF:
c19d1205
ZW
17756 case OT_csuf_or_in3:
17757 inst.cond = cond->value;
17758 return opcode;
17759
17760 case OT_unconditional:
17761 case OT_unconditionalF:
dfa9f0d5 17762 if (thumb_mode)
c921be7d 17763 inst.cond = cond->value;
dfa9f0d5
PB
17764 else
17765 {
c921be7d 17766 /* Delayed diagnostic. */
dfa9f0d5
PB
17767 inst.error = BAD_COND;
17768 inst.cond = COND_ALWAYS;
17769 }
c19d1205 17770 return opcode;
b99bd4ef 17771
c19d1205 17772 default:
c921be7d 17773 return NULL;
c19d1205
ZW
17774 }
17775 }
b99bd4ef 17776
c19d1205
ZW
17777 /* Cannot have a usual-position infix on a mnemonic of less than
17778 six characters (five would be a suffix). */
17779 if (end - base < 6)
c921be7d 17780 return NULL;
b99bd4ef 17781
c19d1205
ZW
17782 /* Look for infixed mnemonic in the usual position. */
17783 affix = base + 3;
21d799b5 17784 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17785 if (!cond)
c921be7d 17786 return NULL;
e3cb604e
PB
17787
17788 memcpy (save, affix, 2);
17789 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17790 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17791 (end - base) - 2);
e3cb604e
PB
17792 memmove (affix + 2, affix, (end - affix) - 2);
17793 memcpy (affix, save, 2);
17794
088fa78e
KH
17795 if (opcode
17796 && (opcode->tag == OT_cinfix3
17797 || opcode->tag == OT_cinfix3_deprecated
17798 || opcode->tag == OT_csuf_or_in3
17799 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17800 {
c921be7d 17801 /* Step CM. */
278df34e 17802 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17803 && (opcode->tag == OT_cinfix3
17804 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17805 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17806
17807 inst.cond = cond->value;
17808 return opcode;
b99bd4ef
NC
17809 }
17810
c921be7d 17811 return NULL;
b99bd4ef
NC
17812}
17813
e07e6e58
NC
17814/* This function generates an initial IT instruction, leaving its block
17815 virtually open for the new instructions. Eventually,
17816 the mask will be updated by now_it_add_mask () each time
17817 a new instruction needs to be included in the IT block.
17818 Finally, the block is closed with close_automatic_it_block ().
17819 The block closure can be requested either from md_assemble (),
17820 a tencode (), or due to a label hook. */
17821
17822static void
17823new_automatic_it_block (int cond)
17824{
17825 now_it.state = AUTOMATIC_IT_BLOCK;
17826 now_it.mask = 0x18;
17827 now_it.cc = cond;
17828 now_it.block_length = 1;
cd000bff 17829 mapping_state (MAP_THUMB);
e07e6e58 17830 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17831 now_it.warn_deprecated = FALSE;
17832 now_it.insn_cond = TRUE;
e07e6e58
NC
17833}
17834
17835/* Close an automatic IT block.
17836 See comments in new_automatic_it_block (). */
17837
17838static void
17839close_automatic_it_block (void)
17840{
17841 now_it.mask = 0x10;
17842 now_it.block_length = 0;
17843}
17844
17845/* Update the mask of the current automatically-generated IT
17846 instruction. See comments in new_automatic_it_block (). */
17847
17848static void
17849now_it_add_mask (int cond)
17850{
17851#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17852#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17853 | ((bitvalue) << (nbit)))
e07e6e58 17854 const int resulting_bit = (cond & 1);
c921be7d 17855
e07e6e58
NC
17856 now_it.mask &= 0xf;
17857 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17858 resulting_bit,
17859 (5 - now_it.block_length));
e07e6e58 17860 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17861 1,
17862 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17863 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17864
17865#undef CLEAR_BIT
17866#undef SET_BIT_VALUE
e07e6e58
NC
17867}
17868
17869/* The IT blocks handling machinery is accessed through the these functions:
17870 it_fsm_pre_encode () from md_assemble ()
17871 set_it_insn_type () optional, from the tencode functions
17872 set_it_insn_type_last () ditto
17873 in_it_block () ditto
17874 it_fsm_post_encode () from md_assemble ()
17875 force_automatic_it_block_close () from label habdling functions
17876
17877 Rationale:
17878 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17879 initializing the IT insn type with a generic initial value depending
17880 on the inst.condition.
e07e6e58 17881 2) During the tencode function, two things may happen:
477330fc
RM
17882 a) The tencode function overrides the IT insn type by
17883 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17884 b) The tencode function queries the IT block state by
17885 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17886
17887 Both set_it_insn_type and in_it_block run the internal FSM state
17888 handling function (handle_it_state), because: a) setting the IT insn
17889 type may incur in an invalid state (exiting the function),
17890 and b) querying the state requires the FSM to be updated.
17891 Specifically we want to avoid creating an IT block for conditional
17892 branches, so it_fsm_pre_encode is actually a guess and we can't
17893 determine whether an IT block is required until the tencode () routine
17894 has decided what type of instruction this actually it.
17895 Because of this, if set_it_insn_type and in_it_block have to be used,
17896 set_it_insn_type has to be called first.
17897
17898 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17899 determines the insn IT type depending on the inst.cond code.
17900 When a tencode () routine encodes an instruction that can be
17901 either outside an IT block, or, in the case of being inside, has to be
17902 the last one, set_it_insn_type_last () will determine the proper
17903 IT instruction type based on the inst.cond code. Otherwise,
17904 set_it_insn_type can be called for overriding that logic or
17905 for covering other cases.
17906
17907 Calling handle_it_state () may not transition the IT block state to
17908 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17909 still queried. Instead, if the FSM determines that the state should
17910 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17911 after the tencode () function: that's what it_fsm_post_encode () does.
17912
17913 Since in_it_block () calls the state handling function to get an
17914 updated state, an error may occur (due to invalid insns combination).
17915 In that case, inst.error is set.
17916 Therefore, inst.error has to be checked after the execution of
17917 the tencode () routine.
e07e6e58
NC
17918
17919 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17920 any pending state change (if any) that didn't take place in
17921 handle_it_state () as explained above. */
e07e6e58
NC
17922
17923static void
17924it_fsm_pre_encode (void)
17925{
17926 if (inst.cond != COND_ALWAYS)
17927 inst.it_insn_type = INSIDE_IT_INSN;
17928 else
17929 inst.it_insn_type = OUTSIDE_IT_INSN;
17930
17931 now_it.state_handled = 0;
17932}
17933
17934/* IT state FSM handling function. */
17935
17936static int
17937handle_it_state (void)
17938{
17939 now_it.state_handled = 1;
5a01bb1d 17940 now_it.insn_cond = FALSE;
e07e6e58
NC
17941
17942 switch (now_it.state)
17943 {
17944 case OUTSIDE_IT_BLOCK:
17945 switch (inst.it_insn_type)
17946 {
17947 case OUTSIDE_IT_INSN:
17948 break;
17949
17950 case INSIDE_IT_INSN:
17951 case INSIDE_IT_LAST_INSN:
17952 if (thumb_mode == 0)
17953 {
c921be7d 17954 if (unified_syntax
e07e6e58
NC
17955 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17956 as_tsktsk (_("Warning: conditional outside an IT block"\
17957 " for Thumb."));
17958 }
17959 else
17960 {
17961 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17962 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17963 {
17964 /* Automatically generate the IT instruction. */
17965 new_automatic_it_block (inst.cond);
17966 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17967 close_automatic_it_block ();
17968 }
17969 else
17970 {
17971 inst.error = BAD_OUT_IT;
17972 return FAIL;
17973 }
17974 }
17975 break;
17976
17977 case IF_INSIDE_IT_LAST_INSN:
17978 case NEUTRAL_IT_INSN:
17979 break;
17980
17981 case IT_INSN:
17982 now_it.state = MANUAL_IT_BLOCK;
17983 now_it.block_length = 0;
17984 break;
17985 }
17986 break;
17987
17988 case AUTOMATIC_IT_BLOCK:
17989 /* Three things may happen now:
17990 a) We should increment current it block size;
17991 b) We should close current it block (closing insn or 4 insns);
17992 c) We should close current it block and start a new one (due
17993 to incompatible conditions or
17994 4 insns-length block reached). */
17995
17996 switch (inst.it_insn_type)
17997 {
17998 case OUTSIDE_IT_INSN:
17999 /* The closure of the block shall happen immediatelly,
18000 so any in_it_block () call reports the block as closed. */
18001 force_automatic_it_block_close ();
18002 break;
18003
18004 case INSIDE_IT_INSN:
18005 case INSIDE_IT_LAST_INSN:
18006 case IF_INSIDE_IT_LAST_INSN:
18007 now_it.block_length++;
18008
18009 if (now_it.block_length > 4
18010 || !now_it_compatible (inst.cond))
18011 {
18012 force_automatic_it_block_close ();
18013 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18014 new_automatic_it_block (inst.cond);
18015 }
18016 else
18017 {
5a01bb1d 18018 now_it.insn_cond = TRUE;
e07e6e58
NC
18019 now_it_add_mask (inst.cond);
18020 }
18021
18022 if (now_it.state == AUTOMATIC_IT_BLOCK
18023 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18024 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18025 close_automatic_it_block ();
18026 break;
18027
18028 case NEUTRAL_IT_INSN:
18029 now_it.block_length++;
5a01bb1d 18030 now_it.insn_cond = TRUE;
e07e6e58
NC
18031
18032 if (now_it.block_length > 4)
18033 force_automatic_it_block_close ();
18034 else
18035 now_it_add_mask (now_it.cc & 1);
18036 break;
18037
18038 case IT_INSN:
18039 close_automatic_it_block ();
18040 now_it.state = MANUAL_IT_BLOCK;
18041 break;
18042 }
18043 break;
18044
18045 case MANUAL_IT_BLOCK:
18046 {
18047 /* Check conditional suffixes. */
18048 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18049 int is_last;
18050 now_it.mask <<= 1;
18051 now_it.mask &= 0x1f;
18052 is_last = (now_it.mask == 0x10);
5a01bb1d 18053 now_it.insn_cond = TRUE;
e07e6e58
NC
18054
18055 switch (inst.it_insn_type)
18056 {
18057 case OUTSIDE_IT_INSN:
18058 inst.error = BAD_NOT_IT;
18059 return FAIL;
18060
18061 case INSIDE_IT_INSN:
18062 if (cond != inst.cond)
18063 {
18064 inst.error = BAD_IT_COND;
18065 return FAIL;
18066 }
18067 break;
18068
18069 case INSIDE_IT_LAST_INSN:
18070 case IF_INSIDE_IT_LAST_INSN:
18071 if (cond != inst.cond)
18072 {
18073 inst.error = BAD_IT_COND;
18074 return FAIL;
18075 }
18076 if (!is_last)
18077 {
18078 inst.error = BAD_BRANCH;
18079 return FAIL;
18080 }
18081 break;
18082
18083 case NEUTRAL_IT_INSN:
18084 /* The BKPT instruction is unconditional even in an IT block. */
18085 break;
18086
18087 case IT_INSN:
18088 inst.error = BAD_IT_IT;
18089 return FAIL;
18090 }
18091 }
18092 break;
18093 }
18094
18095 return SUCCESS;
18096}
18097
5a01bb1d
MGD
18098struct depr_insn_mask
18099{
18100 unsigned long pattern;
18101 unsigned long mask;
18102 const char* description;
18103};
18104
18105/* List of 16-bit instruction patterns deprecated in an IT block in
18106 ARMv8. */
18107static const struct depr_insn_mask depr_it_insns[] = {
18108 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18109 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18110 { 0xa000, 0xb800, N_("ADR") },
18111 { 0x4800, 0xf800, N_("Literal loads") },
18112 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18113 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18114 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18115 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18116 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18117 { 0, 0, NULL }
18118};
18119
e07e6e58
NC
18120static void
18121it_fsm_post_encode (void)
18122{
18123 int is_last;
18124
18125 if (!now_it.state_handled)
18126 handle_it_state ();
18127
5a01bb1d
MGD
18128 if (now_it.insn_cond
18129 && !now_it.warn_deprecated
18130 && warn_on_deprecated
18131 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18132 {
18133 if (inst.instruction >= 0x10000)
18134 {
5c3696f8 18135 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18136 "deprecated in ARMv8"));
18137 now_it.warn_deprecated = TRUE;
18138 }
18139 else
18140 {
18141 const struct depr_insn_mask *p = depr_it_insns;
18142
18143 while (p->mask != 0)
18144 {
18145 if ((inst.instruction & p->mask) == p->pattern)
18146 {
5c3696f8 18147 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18148 "of the following class are deprecated in ARMv8: "
18149 "%s"), p->description);
18150 now_it.warn_deprecated = TRUE;
18151 break;
18152 }
18153
18154 ++p;
18155 }
18156 }
18157
18158 if (now_it.block_length > 1)
18159 {
5c3696f8 18160 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18161 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18162 now_it.warn_deprecated = TRUE;
18163 }
18164 }
18165
e07e6e58
NC
18166 is_last = (now_it.mask == 0x10);
18167 if (is_last)
18168 {
18169 now_it.state = OUTSIDE_IT_BLOCK;
18170 now_it.mask = 0;
18171 }
18172}
18173
18174static void
18175force_automatic_it_block_close (void)
18176{
18177 if (now_it.state == AUTOMATIC_IT_BLOCK)
18178 {
18179 close_automatic_it_block ();
18180 now_it.state = OUTSIDE_IT_BLOCK;
18181 now_it.mask = 0;
18182 }
18183}
18184
18185static int
18186in_it_block (void)
18187{
18188 if (!now_it.state_handled)
18189 handle_it_state ();
18190
18191 return now_it.state != OUTSIDE_IT_BLOCK;
18192}
18193
ff8646ee
TP
18194/* Whether OPCODE only has T32 encoding. Since this function is only used by
18195 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18196 here, hence the "known" in the function name. */
fc289b0a
TP
18197
18198static bfd_boolean
ff8646ee 18199known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18200{
18201 /* Original Thumb-1 wide instruction. */
18202 if (opcode->tencode == do_t_blx
18203 || opcode->tencode == do_t_branch23
18204 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18205 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18206 return TRUE;
18207
16a1fa25
TP
18208 /* Wide-only instruction added to ARMv8-M Baseline. */
18209 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18210 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18211 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18212 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18213 return TRUE;
18214
18215 return FALSE;
18216}
18217
18218/* Whether wide instruction variant can be used if available for a valid OPCODE
18219 in ARCH. */
18220
18221static bfd_boolean
18222t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18223{
18224 if (known_t32_only_insn (opcode))
18225 return TRUE;
18226
18227 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18228 of variant T3 of B.W is checked in do_t_branch. */
18229 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18230 && opcode->tencode == do_t_branch)
18231 return TRUE;
18232
18233 /* Wide instruction variants of all instructions with narrow *and* wide
18234 variants become available with ARMv6t2. Other opcodes are either
18235 narrow-only or wide-only and are thus available if OPCODE is valid. */
18236 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18237 return TRUE;
18238
18239 /* OPCODE with narrow only instruction variant or wide variant not
18240 available. */
fc289b0a
TP
18241 return FALSE;
18242}
18243
c19d1205
ZW
18244void
18245md_assemble (char *str)
b99bd4ef 18246{
c19d1205
ZW
18247 char *p = str;
18248 const struct asm_opcode * opcode;
b99bd4ef 18249
c19d1205
ZW
18250 /* Align the previous label if needed. */
18251 if (last_label_seen != NULL)
b99bd4ef 18252 {
c19d1205
ZW
18253 symbol_set_frag (last_label_seen, frag_now);
18254 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18255 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18256 }
18257
c19d1205
ZW
18258 memset (&inst, '\0', sizeof (inst));
18259 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18260
c19d1205
ZW
18261 opcode = opcode_lookup (&p);
18262 if (!opcode)
b99bd4ef 18263 {
c19d1205 18264 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18265 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18266 if (! create_register_alias (str, p)
477330fc 18267 && ! create_neon_reg_alias (str, p))
c19d1205 18268 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18269
b99bd4ef
NC
18270 return;
18271 }
18272
278df34e 18273 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18274 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18275
037e8744
JB
18276 /* The value which unconditional instructions should have in place of the
18277 condition field. */
18278 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18279
c19d1205 18280 if (thumb_mode)
b99bd4ef 18281 {
e74cfd16 18282 arm_feature_set variant;
8f06b2d8
PB
18283
18284 variant = cpu_variant;
18285 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18286 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18287 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18288 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18289 if (!opcode->tvariant
18290 || (thumb_mode == 1
18291 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18292 {
84b52b66 18293 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18294 return;
18295 }
c19d1205
ZW
18296 if (inst.cond != COND_ALWAYS && !unified_syntax
18297 && opcode->tencode != do_t_branch)
b99bd4ef 18298 {
c19d1205 18299 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18300 return;
18301 }
18302
fc289b0a
TP
18303 /* Two things are addressed here:
18304 1) Implicit require narrow instructions on Thumb-1.
18305 This avoids relaxation accidentally introducing Thumb-2
18306 instructions.
18307 2) Reject wide instructions in non Thumb-2 cores.
18308
18309 Only instructions with narrow and wide variants need to be handled
18310 but selecting all non wide-only instructions is easier. */
18311 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18312 && !t32_insn_ok (variant, opcode))
076d447c 18313 {
fc289b0a
TP
18314 if (inst.size_req == 0)
18315 inst.size_req = 2;
18316 else if (inst.size_req == 4)
752d5da4 18317 {
ff8646ee
TP
18318 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18319 as_bad (_("selected processor does not support 32bit wide "
18320 "variant of instruction `%s'"), str);
18321 else
18322 as_bad (_("selected processor does not support `%s' in "
18323 "Thumb-2 mode"), str);
fc289b0a 18324 return;
752d5da4 18325 }
076d447c
PB
18326 }
18327
c19d1205
ZW
18328 inst.instruction = opcode->tvalue;
18329
5be8be5d 18330 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18331 {
18332 /* Prepare the it_insn_type for those encodings that don't set
18333 it. */
18334 it_fsm_pre_encode ();
c19d1205 18335
477330fc 18336 opcode->tencode ();
e07e6e58 18337
477330fc
RM
18338 it_fsm_post_encode ();
18339 }
e27ec89e 18340
0110f2b8 18341 if (!(inst.error || inst.relax))
b99bd4ef 18342 {
9c2799c2 18343 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18344 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18345 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18346 {
c19d1205 18347 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18348 return;
18349 }
18350 }
076d447c
PB
18351
18352 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18353 instruction. */
9c2799c2 18354 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18355
e74cfd16
PB
18356 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18357 *opcode->tvariant);
ee065d83 18358 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18359 set those bits when Thumb-2 32-bit instructions are seen. The impact
18360 of relaxable instructions will be considered later after we finish all
18361 relaxation. */
ff8646ee
TP
18362 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18363 variant = arm_arch_none;
18364 else
18365 variant = cpu_variant;
18366 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18367 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18368 arm_ext_v6t2);
cd000bff 18369
88714cb8
DG
18370 check_neon_suffixes;
18371
cd000bff 18372 if (!inst.error)
c877a2f2
NC
18373 {
18374 mapping_state (MAP_THUMB);
18375 }
c19d1205 18376 }
3e9e4fcf 18377 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18378 {
845b51d6
PB
18379 bfd_boolean is_bx;
18380
18381 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18382 is_bx = (opcode->aencode == do_bx);
18383
c19d1205 18384 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18385 if (!(is_bx && fix_v4bx)
18386 && !(opcode->avariant &&
18387 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18388 {
84b52b66 18389 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18390 return;
b99bd4ef 18391 }
c19d1205 18392 if (inst.size_req)
b99bd4ef 18393 {
c19d1205
ZW
18394 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18395 return;
b99bd4ef
NC
18396 }
18397
c19d1205
ZW
18398 inst.instruction = opcode->avalue;
18399 if (opcode->tag == OT_unconditionalF)
eff0bc54 18400 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18401 else
18402 inst.instruction |= inst.cond << 28;
18403 inst.size = INSN_SIZE;
5be8be5d 18404 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18405 {
18406 it_fsm_pre_encode ();
18407 opcode->aencode ();
18408 it_fsm_post_encode ();
18409 }
ee065d83 18410 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18411 on a hypothetical non-thumb v5 core. */
845b51d6 18412 if (is_bx)
e74cfd16 18413 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18414 else
e74cfd16
PB
18415 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18416 *opcode->avariant);
88714cb8
DG
18417
18418 check_neon_suffixes;
18419
cd000bff 18420 if (!inst.error)
c877a2f2
NC
18421 {
18422 mapping_state (MAP_ARM);
18423 }
b99bd4ef 18424 }
3e9e4fcf
JB
18425 else
18426 {
18427 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18428 "-- `%s'"), str);
18429 return;
18430 }
c19d1205
ZW
18431 output_inst (str);
18432}
b99bd4ef 18433
e07e6e58
NC
18434static void
18435check_it_blocks_finished (void)
18436{
18437#ifdef OBJ_ELF
18438 asection *sect;
18439
18440 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18441 if (seg_info (sect)->tc_segment_info_data.current_it.state
18442 == MANUAL_IT_BLOCK)
18443 {
18444 as_warn (_("section '%s' finished with an open IT block."),
18445 sect->name);
18446 }
18447#else
18448 if (now_it.state == MANUAL_IT_BLOCK)
18449 as_warn (_("file finished with an open IT block."));
18450#endif
18451}
18452
c19d1205
ZW
18453/* Various frobbings of labels and their addresses. */
18454
18455void
18456arm_start_line_hook (void)
18457{
18458 last_label_seen = NULL;
b99bd4ef
NC
18459}
18460
c19d1205
ZW
18461void
18462arm_frob_label (symbolS * sym)
b99bd4ef 18463{
c19d1205 18464 last_label_seen = sym;
b99bd4ef 18465
c19d1205 18466 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18467
c19d1205
ZW
18468#if defined OBJ_COFF || defined OBJ_ELF
18469 ARM_SET_INTERWORK (sym, support_interwork);
18470#endif
b99bd4ef 18471
e07e6e58
NC
18472 force_automatic_it_block_close ();
18473
5f4273c7 18474 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18475 as Thumb functions. This is because these labels, whilst
18476 they exist inside Thumb code, are not the entry points for
18477 possible ARM->Thumb calls. Also, these labels can be used
18478 as part of a computed goto or switch statement. eg gcc
18479 can generate code that looks like this:
b99bd4ef 18480
c19d1205
ZW
18481 ldr r2, [pc, .Laaa]
18482 lsl r3, r3, #2
18483 ldr r2, [r3, r2]
18484 mov pc, r2
b99bd4ef 18485
c19d1205
ZW
18486 .Lbbb: .word .Lxxx
18487 .Lccc: .word .Lyyy
18488 ..etc...
18489 .Laaa: .word Lbbb
b99bd4ef 18490
c19d1205
ZW
18491 The first instruction loads the address of the jump table.
18492 The second instruction converts a table index into a byte offset.
18493 The third instruction gets the jump address out of the table.
18494 The fourth instruction performs the jump.
b99bd4ef 18495
c19d1205
ZW
18496 If the address stored at .Laaa is that of a symbol which has the
18497 Thumb_Func bit set, then the linker will arrange for this address
18498 to have the bottom bit set, which in turn would mean that the
18499 address computation performed by the third instruction would end
18500 up with the bottom bit set. Since the ARM is capable of unaligned
18501 word loads, the instruction would then load the incorrect address
18502 out of the jump table, and chaos would ensue. */
18503 if (label_is_thumb_function_name
18504 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18505 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18506 {
c19d1205
ZW
18507 /* When the address of a Thumb function is taken the bottom
18508 bit of that address should be set. This will allow
18509 interworking between Arm and Thumb functions to work
18510 correctly. */
b99bd4ef 18511
c19d1205 18512 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18513
c19d1205 18514 label_is_thumb_function_name = FALSE;
b99bd4ef 18515 }
07a53e5c 18516
07a53e5c 18517 dwarf2_emit_label (sym);
b99bd4ef
NC
18518}
18519
c921be7d 18520bfd_boolean
c19d1205 18521arm_data_in_code (void)
b99bd4ef 18522{
c19d1205 18523 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18524 {
c19d1205
ZW
18525 *input_line_pointer = '/';
18526 input_line_pointer += 5;
18527 *input_line_pointer = 0;
c921be7d 18528 return TRUE;
b99bd4ef
NC
18529 }
18530
c921be7d 18531 return FALSE;
b99bd4ef
NC
18532}
18533
c19d1205
ZW
18534char *
18535arm_canonicalize_symbol_name (char * name)
b99bd4ef 18536{
c19d1205 18537 int len;
b99bd4ef 18538
c19d1205
ZW
18539 if (thumb_mode && (len = strlen (name)) > 5
18540 && streq (name + len - 5, "/data"))
18541 *(name + len - 5) = 0;
b99bd4ef 18542
c19d1205 18543 return name;
b99bd4ef 18544}
c19d1205
ZW
18545\f
18546/* Table of all register names defined by default. The user can
18547 define additional names with .req. Note that all register names
18548 should appear in both upper and lowercase variants. Some registers
18549 also have mixed-case names. */
b99bd4ef 18550
dcbf9037 18551#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18552#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18553#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18554#define REGSET(p,t) \
18555 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18556 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18557 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18558 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18559#define REGSETH(p,t) \
18560 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18561 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18562 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18563 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18564#define REGSET2(p,t) \
18565 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18566 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18567 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18568 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18569#define SPLRBANK(base,bank,t) \
18570 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18571 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18572 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18573 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18574 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18575 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18576
c19d1205 18577static const struct reg_entry reg_names[] =
7ed4c4c5 18578{
c19d1205
ZW
18579 /* ARM integer registers. */
18580 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18581
c19d1205
ZW
18582 /* ATPCS synonyms. */
18583 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18584 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18585 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18586
c19d1205
ZW
18587 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18588 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18589 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18590
c19d1205
ZW
18591 /* Well-known aliases. */
18592 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18593 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18594
18595 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18596 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18597
18598 /* Coprocessor numbers. */
18599 REGSET(p, CP), REGSET(P, CP),
18600
18601 /* Coprocessor register numbers. The "cr" variants are for backward
18602 compatibility. */
18603 REGSET(c, CN), REGSET(C, CN),
18604 REGSET(cr, CN), REGSET(CR, CN),
18605
90ec0d68
MGD
18606 /* ARM banked registers. */
18607 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18608 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18609 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18610 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18611 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18612 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18613 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18614
18615 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18616 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18617 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18618 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18619 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18620 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18621 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18622 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18623
18624 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18625 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18626 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18627 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18628 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18629 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18630 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18631 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18632 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18633
c19d1205
ZW
18634 /* FPA registers. */
18635 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18636 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18637
18638 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18639 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18640
18641 /* VFP SP registers. */
5287ad62
JB
18642 REGSET(s,VFS), REGSET(S,VFS),
18643 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18644
18645 /* VFP DP Registers. */
5287ad62
JB
18646 REGSET(d,VFD), REGSET(D,VFD),
18647 /* Extra Neon DP registers. */
18648 REGSETH(d,VFD), REGSETH(D,VFD),
18649
18650 /* Neon QP registers. */
18651 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18652
18653 /* VFP control registers. */
18654 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18655 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18656 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18657 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18658 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18659 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18660
18661 /* Maverick DSP coprocessor registers. */
18662 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18663 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18664
18665 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18666 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18667 REGDEF(dspsc,0,DSPSC),
18668
18669 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18670 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18671 REGDEF(DSPSC,0,DSPSC),
18672
18673 /* iWMMXt data registers - p0, c0-15. */
18674 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18675
18676 /* iWMMXt control registers - p1, c0-3. */
18677 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18678 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18679 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18680 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18681
18682 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18683 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18684 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18685 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18686 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18687
18688 /* XScale accumulator registers. */
18689 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18690};
18691#undef REGDEF
18692#undef REGNUM
18693#undef REGSET
7ed4c4c5 18694
c19d1205
ZW
18695/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18696 within psr_required_here. */
18697static const struct asm_psr psrs[] =
18698{
18699 /* Backward compatibility notation. Note that "all" is no longer
18700 truly all possible PSR bits. */
18701 {"all", PSR_c | PSR_f},
18702 {"flg", PSR_f},
18703 {"ctl", PSR_c},
18704
18705 /* Individual flags. */
18706 {"f", PSR_f},
18707 {"c", PSR_c},
18708 {"x", PSR_x},
18709 {"s", PSR_s},
59b42a0d 18710
c19d1205
ZW
18711 /* Combinations of flags. */
18712 {"fs", PSR_f | PSR_s},
18713 {"fx", PSR_f | PSR_x},
18714 {"fc", PSR_f | PSR_c},
18715 {"sf", PSR_s | PSR_f},
18716 {"sx", PSR_s | PSR_x},
18717 {"sc", PSR_s | PSR_c},
18718 {"xf", PSR_x | PSR_f},
18719 {"xs", PSR_x | PSR_s},
18720 {"xc", PSR_x | PSR_c},
18721 {"cf", PSR_c | PSR_f},
18722 {"cs", PSR_c | PSR_s},
18723 {"cx", PSR_c | PSR_x},
18724 {"fsx", PSR_f | PSR_s | PSR_x},
18725 {"fsc", PSR_f | PSR_s | PSR_c},
18726 {"fxs", PSR_f | PSR_x | PSR_s},
18727 {"fxc", PSR_f | PSR_x | PSR_c},
18728 {"fcs", PSR_f | PSR_c | PSR_s},
18729 {"fcx", PSR_f | PSR_c | PSR_x},
18730 {"sfx", PSR_s | PSR_f | PSR_x},
18731 {"sfc", PSR_s | PSR_f | PSR_c},
18732 {"sxf", PSR_s | PSR_x | PSR_f},
18733 {"sxc", PSR_s | PSR_x | PSR_c},
18734 {"scf", PSR_s | PSR_c | PSR_f},
18735 {"scx", PSR_s | PSR_c | PSR_x},
18736 {"xfs", PSR_x | PSR_f | PSR_s},
18737 {"xfc", PSR_x | PSR_f | PSR_c},
18738 {"xsf", PSR_x | PSR_s | PSR_f},
18739 {"xsc", PSR_x | PSR_s | PSR_c},
18740 {"xcf", PSR_x | PSR_c | PSR_f},
18741 {"xcs", PSR_x | PSR_c | PSR_s},
18742 {"cfs", PSR_c | PSR_f | PSR_s},
18743 {"cfx", PSR_c | PSR_f | PSR_x},
18744 {"csf", PSR_c | PSR_s | PSR_f},
18745 {"csx", PSR_c | PSR_s | PSR_x},
18746 {"cxf", PSR_c | PSR_x | PSR_f},
18747 {"cxs", PSR_c | PSR_x | PSR_s},
18748 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18749 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18750 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18751 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18752 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18753 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18754 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18755 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18756 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18757 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18758 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18759 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18760 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18761 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18762 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18763 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18764 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18765 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18766 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18767 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18768 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18769 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18770 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18771 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18772};
18773
62b3e311
PB
18774/* Table of V7M psr names. */
18775static const struct asm_psr v7m_psrs[] =
18776{
2b744c99
PB
18777 {"apsr", 0 }, {"APSR", 0 },
18778 {"iapsr", 1 }, {"IAPSR", 1 },
18779 {"eapsr", 2 }, {"EAPSR", 2 },
18780 {"psr", 3 }, {"PSR", 3 },
18781 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18782 {"ipsr", 5 }, {"IPSR", 5 },
18783 {"epsr", 6 }, {"EPSR", 6 },
18784 {"iepsr", 7 }, {"IEPSR", 7 },
16a1fa25
TP
18785 {"msp", 8 }, {"MSP", 8 }, {"msp_s", 8 }, {"MSP_S", 8 },
18786 {"psp", 9 }, {"PSP", 9 }, {"psp_s", 9 }, {"PSP_S", 9 },
2b744c99
PB
18787 {"primask", 16}, {"PRIMASK", 16},
18788 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18789 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18790 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99 18791 {"faultmask", 19}, {"FAULTMASK", 19},
16a1fa25
TP
18792 {"control", 20}, {"CONTROL", 20},
18793 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18794 {"psp_ns", 0x89}, {"PSP_NS", 0x89}
62b3e311
PB
18795};
18796
c19d1205
ZW
18797/* Table of all shift-in-operand names. */
18798static const struct asm_shift_name shift_names [] =
b99bd4ef 18799{
c19d1205
ZW
18800 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18801 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18802 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18803 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18804 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18805 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18806};
b99bd4ef 18807
c19d1205
ZW
18808/* Table of all explicit relocation names. */
18809#ifdef OBJ_ELF
18810static struct reloc_entry reloc_names[] =
18811{
18812 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18813 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18814 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18815 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18816 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18817 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18818 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18819 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18820 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18821 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18822 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18823 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18824 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18825 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18826 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18827 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18828 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18829 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18830};
18831#endif
b99bd4ef 18832
c19d1205
ZW
18833/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18834static const struct asm_cond conds[] =
18835{
18836 {"eq", 0x0},
18837 {"ne", 0x1},
18838 {"cs", 0x2}, {"hs", 0x2},
18839 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18840 {"mi", 0x4},
18841 {"pl", 0x5},
18842 {"vs", 0x6},
18843 {"vc", 0x7},
18844 {"hi", 0x8},
18845 {"ls", 0x9},
18846 {"ge", 0xa},
18847 {"lt", 0xb},
18848 {"gt", 0xc},
18849 {"le", 0xd},
18850 {"al", 0xe}
18851};
bfae80f2 18852
e797f7e0 18853#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18854 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18855 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18856
62b3e311
PB
18857static struct asm_barrier_opt barrier_opt_names[] =
18858{
e797f7e0
MGD
18859 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18860 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18861 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18862 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18863 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18864 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18865 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18866 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18867 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18868 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18869 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18870 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18871 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18872 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18873 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18874 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18875};
18876
e797f7e0
MGD
18877#undef UL_BARRIER
18878
c19d1205
ZW
18879/* Table of ARM-format instructions. */
18880
18881/* Macros for gluing together operand strings. N.B. In all cases
18882 other than OPS0, the trailing OP_stop comes from default
18883 zero-initialization of the unspecified elements of the array. */
18884#define OPS0() { OP_stop, }
18885#define OPS1(a) { OP_##a, }
18886#define OPS2(a,b) { OP_##a,OP_##b, }
18887#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18888#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18889#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18890#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18891
5be8be5d
DG
18892/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18893 This is useful when mixing operands for ARM and THUMB, i.e. using the
18894 MIX_ARM_THUMB_OPERANDS macro.
18895 In order to use these macros, prefix the number of operands with _
18896 e.g. _3. */
18897#define OPS_1(a) { a, }
18898#define OPS_2(a,b) { a,b, }
18899#define OPS_3(a,b,c) { a,b,c, }
18900#define OPS_4(a,b,c,d) { a,b,c,d, }
18901#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18902#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18903
c19d1205
ZW
18904/* These macros abstract out the exact format of the mnemonic table and
18905 save some repeated characters. */
18906
18907/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18908#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18909 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18910 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18911
18912/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18913 a T_MNEM_xyz enumerator. */
18914#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18915 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18916#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18917 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18918
18919/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18920 infix after the third character. */
18921#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18922 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18923 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18924#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18925 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18926 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18927#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18928 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18929#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18930 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18931#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18932 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18933#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18934 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18935
c19d1205 18936/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18937 field is still 0xE. Many of the Thumb variants can be executed
18938 conditionally, so this is checked separately. */
c19d1205 18939#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18940 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18941 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18942
dd5181d5
KT
18943/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18944 Used by mnemonics that have very minimal differences in the encoding for
18945 ARM and Thumb variants and can be handled in a common function. */
18946#define TUEc(mnem, op, top, nops, ops, en) \
18947 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18948 THUMB_VARIANT, do_##en, do_##en }
18949
c19d1205
ZW
18950/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18951 condition code field. */
18952#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18953 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18954 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18955
18956/* ARM-only variants of all the above. */
6a86118a 18957#define CE(mnem, op, nops, ops, ae) \
21d799b5 18958 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18959
18960#define C3(mnem, op, nops, ops, ae) \
18961 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18962
e3cb604e
PB
18963/* Legacy mnemonics that always have conditional infix after the third
18964 character. */
18965#define CL(mnem, op, nops, ops, ae) \
21d799b5 18966 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18967 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18968
8f06b2d8
PB
18969/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18970#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18971 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18972
e3cb604e
PB
18973/* Legacy coprocessor instructions where conditional infix and conditional
18974 suffix are ambiguous. For consistency this includes all FPA instructions,
18975 not just the potentially ambiguous ones. */
18976#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18977 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18978 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18979
18980/* Coprocessor, takes either a suffix or a position-3 infix
18981 (for an FPA corner case). */
18982#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18983 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18984 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18985
6a86118a 18986#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18987 { m1 #m2 m3, OPS##nops ops, \
18988 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18989 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18990
18991#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18992 xCM_ (m1, , m2, op, nops, ops, ae), \
18993 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18994 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18995 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18996 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18997 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18998 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18999 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19000 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19001 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19002 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19003 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19004 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19005 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19006 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19007 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19008 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19009 xCM_ (m1, le, m2, op, nops, ops, ae), \
19010 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19011
19012#define UE(mnem, op, nops, ops, ae) \
19013 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19014
19015#define UF(mnem, op, nops, ops, ae) \
19016 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19017
5287ad62
JB
19018/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19019 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19020 use the same encoding function for each. */
19021#define NUF(mnem, op, nops, ops, enc) \
19022 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19023 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19024
19025/* Neon data processing, version which indirects through neon_enc_tab for
19026 the various overloaded versions of opcodes. */
19027#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19028 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19029 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19030
19031/* Neon insn with conditional suffix for the ARM version, non-overloaded
19032 version. */
037e8744
JB
19033#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19034 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19035 THUMB_VARIANT, do_##enc, do_##enc }
19036
037e8744 19037#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19038 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19039
19040#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19041 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19042
5287ad62 19043/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19044#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19045 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19046 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19047
037e8744 19048#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19049 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19050
19051#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19052 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19053
c19d1205
ZW
19054#define do_0 0
19055
c19d1205 19056static const struct asm_opcode insns[] =
bfae80f2 19057{
74db7efb
NC
19058#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19059#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19060 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19061 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19062 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19063 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19064 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19065 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19066 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19067 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19068 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19069 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19070 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19071 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19072 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19073 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19074 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19075 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19076
19077 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19078 for setting PSR flag bits. They are obsolete in V6 and do not
19079 have Thumb equivalents. */
21d799b5
NC
19080 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19081 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19082 CL("tstp", 110f000, 2, (RR, SH), cmp),
19083 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19084 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19085 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19086 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19087 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19088 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19089
19090 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19091 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19092 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19093 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19094
19095 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19096 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19097 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19098 OP_RRnpc),
19099 OP_ADDRGLDR),ldst, t_ldst),
19100 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19101
19102 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19103 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19104 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19105 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19106 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19107 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19108
19109 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19110 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19111 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19112 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19113
c19d1205 19114 /* Pseudo ops. */
21d799b5 19115 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19116 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19117 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19118 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19119
19120 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19121 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19122 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19123 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19124 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19125 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19126 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19127 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19128 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19129 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19130 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19131 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19132 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19133
16a4cf17 19134 /* These may simplify to neg. */
21d799b5
NC
19135 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19136 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19137
c921be7d
NC
19138#undef THUMB_VARIANT
19139#define THUMB_VARIANT & arm_ext_v6
19140
21d799b5 19141 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19142
19143 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19144#undef THUMB_VARIANT
19145#define THUMB_VARIANT & arm_ext_v6t2
19146
21d799b5
NC
19147 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19148 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19149 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19150
5be8be5d
DG
19151 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19152 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19153 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19154 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19155
21d799b5
NC
19156 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19157 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19158
21d799b5
NC
19159 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19160 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19161
19162 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19163 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19164 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19165
19166 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19167 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19168 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19169 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19170 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19171 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19172 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19173 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19174
c921be7d
NC
19175#undef ARM_VARIANT
19176#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19177#undef THUMB_VARIANT
19178#define THUMB_VARIANT & arm_ext_v4t
19179
21d799b5
NC
19180 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19181 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19182
c921be7d
NC
19183#undef THUMB_VARIANT
19184#define THUMB_VARIANT & arm_ext_v6t2
19185
21d799b5 19186 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19187 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19188
19189 /* Generic coprocessor instructions. */
21d799b5
NC
19190 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19191 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19192 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19193 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19194 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19195 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19196 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19197
c921be7d
NC
19198#undef ARM_VARIANT
19199#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19200
21d799b5 19201 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19202 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19203
c921be7d
NC
19204#undef ARM_VARIANT
19205#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19206#undef THUMB_VARIANT
19207#define THUMB_VARIANT & arm_ext_msr
19208
d2cd1205
JB
19209 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19210 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19211
c921be7d
NC
19212#undef ARM_VARIANT
19213#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19214#undef THUMB_VARIANT
19215#define THUMB_VARIANT & arm_ext_v6t2
19216
21d799b5
NC
19217 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19218 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19219 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19220 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19221 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19222 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19223 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19224 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19225
c921be7d
NC
19226#undef ARM_VARIANT
19227#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19228#undef THUMB_VARIANT
19229#define THUMB_VARIANT & arm_ext_v4t
19230
5be8be5d
DG
19231 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19232 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19233 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19234 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19235 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19236 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19237
c921be7d
NC
19238#undef ARM_VARIANT
19239#define ARM_VARIANT & arm_ext_v4t_5
19240
c19d1205
ZW
19241 /* ARM Architecture 4T. */
19242 /* Note: bx (and blx) are required on V5, even if the processor does
19243 not support Thumb. */
21d799b5 19244 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19245
c921be7d
NC
19246#undef ARM_VARIANT
19247#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19248#undef THUMB_VARIANT
19249#define THUMB_VARIANT & arm_ext_v5t
19250
c19d1205
ZW
19251 /* Note: blx has 2 variants; the .value coded here is for
19252 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19253 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19254 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19255
c921be7d
NC
19256#undef THUMB_VARIANT
19257#define THUMB_VARIANT & arm_ext_v6t2
19258
21d799b5
NC
19259 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19260 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19261 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19262 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19263 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19264 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19265 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19266 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19267
c921be7d 19268#undef ARM_VARIANT
74db7efb
NC
19269#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19270#undef THUMB_VARIANT
19271#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19272
21d799b5
NC
19273 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19274 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19275 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19276 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19277
21d799b5
NC
19278 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19279 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19280
21d799b5
NC
19281 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19282 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19283 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19284 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19285
21d799b5
NC
19286 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19287 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19288 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19289 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19290
21d799b5
NC
19291 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19292 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19293
03ee1b7f
NC
19294 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19295 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19296 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19297 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19298
c921be7d 19299#undef ARM_VARIANT
74db7efb
NC
19300#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19301#undef THUMB_VARIANT
19302#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19303
21d799b5 19304 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19305 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19306 ldrd, t_ldstd),
19307 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19308 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19309
21d799b5
NC
19310 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19311 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19312
c921be7d
NC
19313#undef ARM_VARIANT
19314#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19315
21d799b5 19316 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19317
c921be7d
NC
19318#undef ARM_VARIANT
19319#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19320#undef THUMB_VARIANT
19321#define THUMB_VARIANT & arm_ext_v6
19322
21d799b5
NC
19323 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19324 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19325 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19326 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19327 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19328 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19329 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19330 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19331 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19332 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19333
c921be7d 19334#undef THUMB_VARIANT
ff8646ee 19335#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19336
5be8be5d
DG
19337 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19338 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19339 strex, t_strex),
ff8646ee
TP
19340#undef THUMB_VARIANT
19341#define THUMB_VARIANT & arm_ext_v6t2
19342
21d799b5
NC
19343 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19344 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19345
21d799b5
NC
19346 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19347 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19348
9e3c6df6 19349/* ARM V6 not included in V7M. */
c921be7d
NC
19350#undef THUMB_VARIANT
19351#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19352 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19353 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19354 UF(rfeib, 9900a00, 1, (RRw), rfe),
19355 UF(rfeda, 8100a00, 1, (RRw), rfe),
19356 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19357 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19358 UF(rfefa, 8100a00, 1, (RRw), rfe),
19359 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19360 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19361 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19362 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19363 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19364 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19365 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19366 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19367 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19368 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19369 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19370 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19371
9e3c6df6
PB
19372/* ARM V6 not included in V7M (eg. integer SIMD). */
19373#undef THUMB_VARIANT
19374#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19375 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19376 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19377 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19378 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19379 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19380 /* Old name for QASX. */
74db7efb 19381 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19382 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19383 /* Old name for QSAX. */
74db7efb 19384 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19385 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19386 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19387 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19388 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19389 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19390 /* Old name for SASX. */
74db7efb 19391 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19392 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19393 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19394 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19395 /* Old name for SHASX. */
21d799b5 19396 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19397 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19398 /* Old name for SHSAX. */
21d799b5
NC
19399 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19400 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19401 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19402 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19403 /* Old name for SSAX. */
74db7efb 19404 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19405 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19406 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19407 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19408 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19409 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19410 /* Old name for UASX. */
74db7efb 19411 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19412 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19413 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19414 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19415 /* Old name for UHASX. */
21d799b5
NC
19416 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19417 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19418 /* Old name for UHSAX. */
21d799b5
NC
19419 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19420 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19421 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19422 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19423 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19424 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19425 /* Old name for UQASX. */
21d799b5
NC
19426 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19427 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19428 /* Old name for UQSAX. */
21d799b5
NC
19429 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19430 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19431 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19432 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19433 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19434 /* Old name for USAX. */
74db7efb 19435 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19436 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19437 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19438 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19439 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19440 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19441 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19442 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19443 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19444 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19445 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19446 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19447 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19448 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19449 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19450 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19451 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19452 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19453 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19454 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19455 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19456 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19457 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19458 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19459 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19460 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19461 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19462 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19463 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19464 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19465 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19466 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19467 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19468 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19469
c921be7d
NC
19470#undef ARM_VARIANT
19471#define ARM_VARIANT & arm_ext_v6k
19472#undef THUMB_VARIANT
19473#define THUMB_VARIANT & arm_ext_v6k
19474
21d799b5
NC
19475 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19476 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19477 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19478 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19479
c921be7d
NC
19480#undef THUMB_VARIANT
19481#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19482 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19483 ldrexd, t_ldrexd),
19484 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19485 RRnpcb), strexd, t_strexd),
ebdca51a 19486
c921be7d 19487#undef THUMB_VARIANT
ff8646ee 19488#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19489 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19490 rd_rn, rd_rn),
19491 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19492 rd_rn, rd_rn),
19493 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19494 strex, t_strexbh),
5be8be5d 19495 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19496 strex, t_strexbh),
21d799b5 19497 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19498
c921be7d 19499#undef ARM_VARIANT
f4c65163 19500#define ARM_VARIANT & arm_ext_sec
74db7efb 19501#undef THUMB_VARIANT
f4c65163 19502#define THUMB_VARIANT & arm_ext_sec
c921be7d 19503
21d799b5 19504 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19505
90ec0d68
MGD
19506#undef ARM_VARIANT
19507#define ARM_VARIANT & arm_ext_virt
19508#undef THUMB_VARIANT
19509#define THUMB_VARIANT & arm_ext_virt
19510
19511 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19512 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19513
ddfded2f
MW
19514#undef ARM_VARIANT
19515#define ARM_VARIANT & arm_ext_pan
19516#undef THUMB_VARIANT
19517#define THUMB_VARIANT & arm_ext_pan
19518
19519 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19520
c921be7d 19521#undef ARM_VARIANT
74db7efb 19522#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19523#undef THUMB_VARIANT
19524#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19525
21d799b5
NC
19526 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19527 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19528 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19529 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19530
21d799b5 19531 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19532 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19533
5be8be5d
DG
19534 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19535 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19536 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19537 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19538
ff8646ee
TP
19539#undef THUMB_VARIANT
19540#define THUMB_VARIANT & arm_ext_v6t2_v8m
19541 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19542 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19543
bf3eeda7 19544 /* Thumb-only instructions. */
74db7efb 19545#undef ARM_VARIANT
bf3eeda7
NS
19546#define ARM_VARIANT NULL
19547 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19548 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19549
19550 /* ARM does not really have an IT instruction, so always allow it.
19551 The opcode is copied from Thumb in order to allow warnings in
19552 -mimplicit-it=[never | arm] modes. */
19553#undef ARM_VARIANT
19554#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19555#undef THUMB_VARIANT
19556#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19557
21d799b5
NC
19558 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19559 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19560 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19561 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19562 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19563 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19564 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19565 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19566 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19567 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19568 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19569 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19570 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19571 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19572 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19573 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19574 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19575 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19576
92e90b6e 19577 /* Thumb2 only instructions. */
c921be7d
NC
19578#undef ARM_VARIANT
19579#define ARM_VARIANT NULL
92e90b6e 19580
21d799b5
NC
19581 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19582 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19583 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19584 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19585 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19586 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19587
eea54501
MGD
19588 /* Hardware division instructions. */
19589#undef ARM_VARIANT
19590#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19591#undef THUMB_VARIANT
19592#define THUMB_VARIANT & arm_ext_div
19593
eea54501
MGD
19594 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19595 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19596
7e806470 19597 /* ARM V6M/V7 instructions. */
c921be7d
NC
19598#undef ARM_VARIANT
19599#define ARM_VARIANT & arm_ext_barrier
19600#undef THUMB_VARIANT
19601#define THUMB_VARIANT & arm_ext_barrier
19602
ccb84d65
JB
19603 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19604 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19605 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19606
62b3e311 19607 /* ARM V7 instructions. */
c921be7d
NC
19608#undef ARM_VARIANT
19609#define ARM_VARIANT & arm_ext_v7
19610#undef THUMB_VARIANT
19611#define THUMB_VARIANT & arm_ext_v7
19612
21d799b5
NC
19613 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19614 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19615
74db7efb 19616#undef ARM_VARIANT
60e5ef9f 19617#define ARM_VARIANT & arm_ext_mp
74db7efb 19618#undef THUMB_VARIANT
60e5ef9f
MGD
19619#define THUMB_VARIANT & arm_ext_mp
19620
19621 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19622
53c4b28b
MGD
19623 /* AArchv8 instructions. */
19624#undef ARM_VARIANT
19625#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19626
19627/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19628#undef THUMB_VARIANT
4ed7ed8d 19629#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19630
4ed7ed8d
TP
19631 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19632 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19633 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19634 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19635 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19636 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19637 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19638 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19639 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19640 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19641 stlex, t_stlex),
4b8c8c02
RE
19642 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19643 stlex, t_stlex),
19644 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19645 stlex, t_stlex),
4ed7ed8d
TP
19646#undef THUMB_VARIANT
19647#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19648
4ed7ed8d
TP
19649 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19650 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19651 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19652 ldrexd, t_ldrexd),
19653 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19654 strexd, t_strexd),
8884b720 19655 /* ARMv8 T32 only. */
74db7efb 19656#undef ARM_VARIANT
b79f7053
MGD
19657#define ARM_VARIANT NULL
19658 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19659 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19660 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19661
33399f07
MGD
19662 /* FP for ARMv8. */
19663#undef ARM_VARIANT
a715796b 19664#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19665#undef THUMB_VARIANT
a715796b 19666#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19667
19668 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19669 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19670 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19671 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19672 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19673 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19674 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19675 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19676 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19677 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19678 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19679 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19680 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19681 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19682 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19683 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19684 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19685
91ff7894
MGD
19686 /* Crypto v1 extensions. */
19687#undef ARM_VARIANT
19688#define ARM_VARIANT & fpu_crypto_ext_armv8
19689#undef THUMB_VARIANT
19690#define THUMB_VARIANT & fpu_crypto_ext_armv8
19691
19692 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19693 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19694 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19695 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19696 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19697 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19698 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19699 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19700 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19701 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19702 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19703 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19704 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19705 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19706
dd5181d5 19707#undef ARM_VARIANT
74db7efb 19708#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19709#undef THUMB_VARIANT
19710#define THUMB_VARIANT & crc_ext_armv8
19711 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19712 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19713 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19714 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19715 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19716 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19717
105bde57
MW
19718 /* ARMv8.2 RAS extension. */
19719#undef ARM_VARIANT
19720#define ARM_VARIANT & arm_ext_v8_2
19721#undef THUMB_VARIANT
19722#define THUMB_VARIANT & arm_ext_v8_2
19723 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19724
c921be7d
NC
19725#undef ARM_VARIANT
19726#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19727#undef THUMB_VARIANT
19728#define THUMB_VARIANT NULL
c921be7d 19729
21d799b5
NC
19730 cCE("wfs", e200110, 1, (RR), rd),
19731 cCE("rfs", e300110, 1, (RR), rd),
19732 cCE("wfc", e400110, 1, (RR), rd),
19733 cCE("rfc", e500110, 1, (RR), rd),
19734
19735 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19736 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19737 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19738 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19739
19740 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19741 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19742 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19743 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19744
19745 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19746 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19747 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19748 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19749 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19750 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19751 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19752 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19753 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19754 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19755 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19756 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19757
19758 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19759 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19760 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19761 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19762 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19763 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19764 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19765 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19766 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19767 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19768 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19769 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19770
19771 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19772 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19773 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19774 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19775 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19776 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19777 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19778 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19779 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19780 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19781 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19782 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19783
19784 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19785 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19786 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19787 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19788 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19789 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19790 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19791 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19792 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19793 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19794 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19795 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19796
19797 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19798 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19799 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19800 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19801 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19802 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19803 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19804 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19805 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19806 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19807 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19808 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19809
19810 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19811 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19812 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19813 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19814 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19815 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19816 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19817 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19818 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19819 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19820 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19821 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19822
19823 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19824 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19825 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19826 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19827 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19828 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19829 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19830 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19831 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19832 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19833 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19834 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19835
19836 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19837 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19838 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19839 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19840 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19841 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19842 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19843 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19844 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19845 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19846 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19847 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19848
19849 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19850 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19851 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19852 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19853 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19854 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19855 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19856 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19857 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19858 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19859 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19860 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19861
19862 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19863 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19864 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19865 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19866 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19867 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19868 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19869 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19870 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19871 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19872 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19873 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19874
19875 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19876 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19877 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19878 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19879 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19880 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19881 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19882 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19883 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19884 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19885 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19886 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19887
19888 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19889 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19890 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19891 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19892 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19893 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19894 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19895 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19896 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19897 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19898 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19899 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19900
19901 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19902 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19903 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19904 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19905 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19906 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19907 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19908 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19909 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19910 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19911 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19912 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19913
19914 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19915 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19916 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19917 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19918 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19919 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19920 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19921 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19922 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19923 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19924 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19925 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19926
19927 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19928 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19929 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19930 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19931 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19932 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19933 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19934 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19935 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19936 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19937 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19938 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19939
19940 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19941 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19942 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19943 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19944 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19945 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19946 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19947 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19948 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19949 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19950 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19951 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19952
19953 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19954 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19955 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19956 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19957 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19958 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19959 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19960 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19961 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19962 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19963 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19964 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19965
19966 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19967 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19968 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19969 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19970 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19971 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19972 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19973 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19974 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19975 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19976 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19977 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19978
19979 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19980 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19981 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19982 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19983 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19984 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19985 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19986 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19987 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19988 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19989 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19990 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19991
19992 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19993 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19994 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19995 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19996 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19997 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19998 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19999 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20000 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20001 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20002 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20003 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20004
20005 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20006 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20007 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20008 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20009 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20010 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20011 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20012 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20013 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20014 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20015 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20016 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20017
20018 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20019 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20020 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20021 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20022 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20023 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20024 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20025 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20026 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20027 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20028 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20029 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20030
20031 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20032 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20033 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20034 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20035 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20036 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20037 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20038 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20039 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20040 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20041 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20042 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20043
20044 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20045 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20046 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20047 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20048 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20049 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20050 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20051 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20052 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20053 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20054 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20055 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20056
20057 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20058 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20059 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20060 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20061 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20062 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20063 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20064 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20065 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20066 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20067 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20068 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20069
20070 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20071 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20072 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20073 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20074 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20075 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20076 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20077 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20078 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20079 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20080 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20081 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20082
20083 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20084 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20085 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20086 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20087 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20088 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20089 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20090 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20091 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20092 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20093 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20094 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20095
20096 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20097 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20098 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20099 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20100 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20101 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20102 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20103 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20104 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20105 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20106 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20107 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20108
20109 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20110 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20111 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20112 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20113 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20114 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20115 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20116 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20117 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20118 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20119 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20120 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20121
20122 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20123 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20124 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20125 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20126
20127 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20128 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20129 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20130 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20131 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20132 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20133 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20134 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20135 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20136 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20137 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20138 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20139
c19d1205
ZW
20140 /* The implementation of the FIX instruction is broken on some
20141 assemblers, in that it accepts a precision specifier as well as a
20142 rounding specifier, despite the fact that this is meaningless.
20143 To be more compatible, we accept it as well, though of course it
20144 does not set any bits. */
21d799b5
NC
20145 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20146 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20147 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20148 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20149 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20150 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20151 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20152 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20153 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20154 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20155 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20156 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20157 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20158
c19d1205 20159 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20160#undef ARM_VARIANT
20161#define ARM_VARIANT & fpu_fpa_ext_v2
20162
21d799b5
NC
20163 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20164 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20165 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20166 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20167 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20168 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20169
c921be7d
NC
20170#undef ARM_VARIANT
20171#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20172
c19d1205 20173 /* Moves and type conversions. */
21d799b5
NC
20174 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20175 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20176 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20177 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20178 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20179 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20180 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20181 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20182 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20183 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20184 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20185 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20186 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20187 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20188
20189 /* Memory operations. */
21d799b5
NC
20190 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20191 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20192 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20193 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20194 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20195 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20196 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20197 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20198 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20199 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20200 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20201 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20202 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20203 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20204 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20205 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20206 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20207 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20208
c19d1205 20209 /* Monadic operations. */
21d799b5
NC
20210 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20211 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20212 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20213
20214 /* Dyadic operations. */
21d799b5
NC
20215 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20216 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20217 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20218 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20219 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20220 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20221 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20222 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20223 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20224
c19d1205 20225 /* Comparisons. */
21d799b5
NC
20226 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20227 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20228 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20229 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20230
62f3b8c8
PB
20231 /* Double precision load/store are still present on single precision
20232 implementations. */
20233 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20234 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20235 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20236 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20237 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20238 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20239 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20240 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20241 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20242 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20243
c921be7d
NC
20244#undef ARM_VARIANT
20245#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20246
c19d1205 20247 /* Moves and type conversions. */
21d799b5
NC
20248 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20249 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20250 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20251 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20252 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20253 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20254 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20255 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20256 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20257 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20258 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20259 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20260 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20261
c19d1205 20262 /* Monadic operations. */
21d799b5
NC
20263 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20264 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20265 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20266
20267 /* Dyadic operations. */
21d799b5
NC
20268 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20269 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20270 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20271 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20272 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20273 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20274 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20275 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20276 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20277
c19d1205 20278 /* Comparisons. */
21d799b5
NC
20279 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20280 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20281 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20282 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20283
c921be7d
NC
20284#undef ARM_VARIANT
20285#define ARM_VARIANT & fpu_vfp_ext_v2
20286
21d799b5
NC
20287 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20288 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20289 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20290 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20291
037e8744
JB
20292/* Instructions which may belong to either the Neon or VFP instruction sets.
20293 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20294#undef ARM_VARIANT
20295#define ARM_VARIANT & fpu_vfp_ext_v1xd
20296#undef THUMB_VARIANT
20297#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20298
037e8744
JB
20299 /* These mnemonics are unique to VFP. */
20300 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20301 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20302 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20303 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20304 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20305 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20306 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20307 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20308 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20309 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20310
20311 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20312 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20313 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20314 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20315
21d799b5
NC
20316 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20317 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20318
20319 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20320 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20321
55881a11
MGD
20322 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20323 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20324 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20325 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20326 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20327 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20328 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20329 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20330
5f1af56b 20331 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20332 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20333 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20334 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20335
037e8744
JB
20336
20337 /* NOTE: All VMOV encoding is special-cased! */
20338 NCE(vmov, 0, 1, (VMOV), neon_mov),
20339 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20340
9db2f6b4
RL
20341#undef ARM_VARIANT
20342#define ARM_VARIANT & arm_ext_fp16
20343#undef THUMB_VARIANT
20344#define THUMB_VARIANT & arm_ext_fp16
20345 /* New instructions added from v8.2, allowing the extraction and insertion of
20346 the upper 16 bits of a 32-bit vector register. */
20347 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20348 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20349
c921be7d
NC
20350#undef THUMB_VARIANT
20351#define THUMB_VARIANT & fpu_neon_ext_v1
20352#undef ARM_VARIANT
20353#define ARM_VARIANT & fpu_neon_ext_v1
20354
5287ad62
JB
20355 /* Data processing with three registers of the same length. */
20356 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20357 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20358 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20359 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20360 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20361 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20362 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20363 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20364 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20365 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20366 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20367 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20368 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20369 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20370 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20371 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20372 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20373 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20374 /* If not immediate, fall back to neon_dyadic_i64_su.
20375 shl_imm should accept I8 I16 I32 I64,
20376 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20377 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20378 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20379 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20380 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20381 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20382 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20383 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20384 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20385 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20386 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20387 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20388 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20389 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20390 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20391 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20392 /* Bitfield ops, untyped. */
20393 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20394 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20395 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20396 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20397 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20398 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20399 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20400 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20401 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20402 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20403 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20404 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20405 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20406 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20407 back to neon_dyadic_if_su. */
21d799b5
NC
20408 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20409 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20410 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20411 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20412 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20413 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20414 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20415 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20416 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20417 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20418 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20419 /* As above, D registers only. */
21d799b5
NC
20420 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20421 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20422 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20423 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20424 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20425 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20426 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20427 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20428 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20429 /* vtst takes sizes 8, 16, 32. */
20430 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20431 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20432 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20433 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20434 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20435 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20436 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20437 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20438 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20439 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20440 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20441 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20442 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20443 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20444 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20445 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20446 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20447 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20448 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20449 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20450 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20451 /* ARM v8.1 extension. */
643afb90
MW
20452 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20453 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20454 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20455 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20456
20457 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20458 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20459 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20460
20461 /* Data processing with two registers and a shift amount. */
20462 /* Right shifts, and variants with rounding.
20463 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20464 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20465 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20466 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20467 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20468 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20469 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20470 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20471 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20472 /* Shift and insert. Sizes accepted 8 16 32 64. */
20473 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20474 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20475 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20476 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20477 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20478 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20479 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20480 /* Right shift immediate, saturating & narrowing, with rounding variants.
20481 Types accepted S16 S32 S64 U16 U32 U64. */
20482 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20483 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20484 /* As above, unsigned. Types accepted S16 S32 S64. */
20485 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20486 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20487 /* Right shift narrowing. Types accepted I16 I32 I64. */
20488 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20489 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20490 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20491 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20492 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20493 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20494
4316f0d2
DG
20495 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20496 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20497
20498 /* Data processing, three registers of different lengths. */
20499 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20500 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20501 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20502 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20503 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20504 /* If not scalar, fall back to neon_dyadic_long.
20505 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20506 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20507 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20508 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20509 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20510 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20511 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20512 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20513 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20514 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20515 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20516 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20517 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20518 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20519 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20520 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20521 S16 S32 U16 U32. */
21d799b5 20522 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20523
20524 /* Extract. Size 8. */
3b8d421e
PB
20525 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20526 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20527
20528 /* Two registers, miscellaneous. */
20529 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20530 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20531 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20532 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20533 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20534 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20535 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20536 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20537 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20538 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20539 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20540 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20541 /* VMOVN. Types I16 I32 I64. */
21d799b5 20542 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20543 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20544 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20545 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20546 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20547 /* VZIP / VUZP. Sizes 8 16 32. */
20548 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20549 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20550 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20551 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20552 /* VQABS / VQNEG. Types S8 S16 S32. */
20553 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20554 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20555 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20556 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20557 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20558 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20559 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20560 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20561 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20562 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20563 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20564 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20565 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20566 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20567 /* VCLS. Types S8 S16 S32. */
20568 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20569 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20570 /* VCLZ. Types I8 I16 I32. */
20571 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20572 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20573 /* VCNT. Size 8. */
20574 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20575 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20576 /* Two address, untyped. */
20577 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20578 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20579 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20580 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20581 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20582
20583 /* Table lookup. Size 8. */
20584 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20585 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20586
c921be7d
NC
20587#undef THUMB_VARIANT
20588#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20589#undef ARM_VARIANT
20590#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20591
5287ad62 20592 /* Neon element/structure load/store. */
21d799b5
NC
20593 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20594 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20595 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20596 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20597 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20598 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20599 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20600 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20601
c921be7d 20602#undef THUMB_VARIANT
74db7efb
NC
20603#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20604#undef ARM_VARIANT
20605#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20606 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20607 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20608 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20609 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20610 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20611 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20612 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20613 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20614 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20615
74db7efb 20616#undef THUMB_VARIANT
c921be7d
NC
20617#define THUMB_VARIANT & fpu_vfp_ext_v3
20618#undef ARM_VARIANT
20619#define ARM_VARIANT & fpu_vfp_ext_v3
20620
21d799b5 20621 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20622 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20623 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20624 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20625 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20626 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20627 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20628 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20629 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20630
74db7efb
NC
20631#undef ARM_VARIANT
20632#define ARM_VARIANT & fpu_vfp_ext_fma
20633#undef THUMB_VARIANT
20634#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20635 /* Mnemonics shared by Neon and VFP. These are included in the
20636 VFP FMA variant; NEON and VFP FMA always includes the NEON
20637 FMA instructions. */
20638 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20639 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20640 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20641 the v form should always be used. */
20642 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20643 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20644 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20645 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20646 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20647 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20648
5287ad62 20649#undef THUMB_VARIANT
c921be7d
NC
20650#undef ARM_VARIANT
20651#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20652
21d799b5
NC
20653 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20654 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20655 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20656 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20657 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20658 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20659 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20660 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20661
c921be7d
NC
20662#undef ARM_VARIANT
20663#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20664
21d799b5
NC
20665 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20666 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20667 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20668 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20669 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20670 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20671 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20672 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20673 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20674 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20675 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20676 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20677 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20678 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20679 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20680 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20681 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20682 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20683 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20684 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20685 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20686 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20687 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20688 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20689 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20690 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20691 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20692 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20693 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20694 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20695 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20696 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20697 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20698 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20699 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20700 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20701 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20702 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20703 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20704 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20705 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20706 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20707 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20708 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20709 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20710 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20711 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20712 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20713 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20714 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20715 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20716 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20717 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20718 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20719 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20720 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20721 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20722 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20723 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20724 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20725 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20726 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20727 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20728 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20729 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20730 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20731 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20732 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20733 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20734 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20735 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20736 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20737 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20738 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20739 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20740 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20741 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20742 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20743 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20744 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20745 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20746 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20747 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20748 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20749 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20750 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20751 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20752 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20753 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20754 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20755 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20756 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20757 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20758 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20759 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20760 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20761 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20762 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20763 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20764 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20765 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20766 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20767 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20768 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20769 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20770 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20771 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20772 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20773 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20774 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20775 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20776 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20777 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20778 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20779 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20780 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20781 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20782 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20783 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20784 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20785 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20786 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20787 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20788 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20789 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20790 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20791 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20792 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20793 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20794 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20795 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20796 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20797 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20798 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20799 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20800 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20801 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20802 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20803 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20804 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20805 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20806 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20807 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20808 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20809 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20810 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20811 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20812 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20813 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20814 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20815 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20816 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20817 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20818 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20819 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20820 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20821 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20822 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20823 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20824 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20825 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20826 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20827
c921be7d
NC
20828#undef ARM_VARIANT
20829#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20830
21d799b5
NC
20831 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20832 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20833 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20834 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20835 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20836 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20837 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20838 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20839 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20840 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20841 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20842 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20843 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20844 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20845 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20846 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20847 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20848 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20849 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20850 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20851 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20852 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20853 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20854 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20855 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20856 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20857 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20858 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20859 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20860 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20861 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20862 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20863 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20864 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20865 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20866 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20867 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20868 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20869 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20870 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20871 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20872 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20873 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20874 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20875 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20876 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20877 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20878 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20879 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20880 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20881 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20882 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20883 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20884 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20885 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20886 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20887 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20888
c921be7d
NC
20889#undef ARM_VARIANT
20890#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20891
21d799b5
NC
20892 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20893 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20894 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20895 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20896 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20897 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20898 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20899 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20900 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20901 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20902 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20903 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20904 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20905 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20906 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20907 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20908 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20909 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20910 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20911 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20912 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20913 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20914 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20915 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20916 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20917 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20918 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20919 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20920 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20921 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20922 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20923 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20924 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20925 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20926 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20927 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20928 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20929 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20930 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20931 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20932 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20933 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20934 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20935 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20936 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20937 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20938 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20939 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20940 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20941 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20942 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20943 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20944 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20945 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20946 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20947 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20948 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20949 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20950 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20951 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20952 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20953 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20954 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20955 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20956 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20957 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20958 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20959 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20960 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20961 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20962 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20963 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20964 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20965 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20966 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20967 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 20968
16a1fa25 20969 /* ARMv8-M instructions. */
4ed7ed8d
TP
20970#undef ARM_VARIANT
20971#define ARM_VARIANT NULL
20972#undef THUMB_VARIANT
20973#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
20974 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
20975 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
20976 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
20977 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20978 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
20979 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
20980 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
20981
20982 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
20983 instructions behave as nop if no VFP is present. */
20984#undef THUMB_VARIANT
20985#define THUMB_VARIANT & arm_ext_v8m_main
20986 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
20987 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
20988};
20989#undef ARM_VARIANT
20990#undef THUMB_VARIANT
20991#undef TCE
c19d1205
ZW
20992#undef TUE
20993#undef TUF
20994#undef TCC
8f06b2d8 20995#undef cCE
e3cb604e
PB
20996#undef cCL
20997#undef C3E
c19d1205
ZW
20998#undef CE
20999#undef CM
21000#undef UE
21001#undef UF
21002#undef UT
5287ad62
JB
21003#undef NUF
21004#undef nUF
21005#undef NCE
21006#undef nCE
c19d1205
ZW
21007#undef OPS0
21008#undef OPS1
21009#undef OPS2
21010#undef OPS3
21011#undef OPS4
21012#undef OPS5
21013#undef OPS6
21014#undef do_0
21015\f
21016/* MD interface: bits in the object file. */
bfae80f2 21017
c19d1205
ZW
21018/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21019 for use in the a.out file, and stores them in the array pointed to by buf.
21020 This knows about the endian-ness of the target machine and does
21021 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21022 2 (short) and 4 (long) Floating numbers are put out as a series of
21023 LITTLENUMS (shorts, here at least). */
b99bd4ef 21024
c19d1205
ZW
21025void
21026md_number_to_chars (char * buf, valueT val, int n)
21027{
21028 if (target_big_endian)
21029 number_to_chars_bigendian (buf, val, n);
21030 else
21031 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21032}
21033
c19d1205
ZW
21034static valueT
21035md_chars_to_number (char * buf, int n)
bfae80f2 21036{
c19d1205
ZW
21037 valueT result = 0;
21038 unsigned char * where = (unsigned char *) buf;
bfae80f2 21039
c19d1205 21040 if (target_big_endian)
b99bd4ef 21041 {
c19d1205
ZW
21042 while (n--)
21043 {
21044 result <<= 8;
21045 result |= (*where++ & 255);
21046 }
b99bd4ef 21047 }
c19d1205 21048 else
b99bd4ef 21049 {
c19d1205
ZW
21050 while (n--)
21051 {
21052 result <<= 8;
21053 result |= (where[n] & 255);
21054 }
bfae80f2 21055 }
b99bd4ef 21056
c19d1205 21057 return result;
bfae80f2 21058}
b99bd4ef 21059
c19d1205 21060/* MD interface: Sections. */
b99bd4ef 21061
fa94de6b
RM
21062/* Calculate the maximum variable size (i.e., excluding fr_fix)
21063 that an rs_machine_dependent frag may reach. */
21064
21065unsigned int
21066arm_frag_max_var (fragS *fragp)
21067{
21068 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21069 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21070
21071 Note that we generate relaxable instructions even for cases that don't
21072 really need it, like an immediate that's a trivial constant. So we're
21073 overestimating the instruction size for some of those cases. Rather
21074 than putting more intelligence here, it would probably be better to
21075 avoid generating a relaxation frag in the first place when it can be
21076 determined up front that a short instruction will suffice. */
21077
21078 gas_assert (fragp->fr_type == rs_machine_dependent);
21079 return INSN_SIZE;
21080}
21081
0110f2b8
PB
21082/* Estimate the size of a frag before relaxing. Assume everything fits in
21083 2 bytes. */
21084
c19d1205 21085int
0110f2b8 21086md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21087 segT segtype ATTRIBUTE_UNUSED)
21088{
0110f2b8
PB
21089 fragp->fr_var = 2;
21090 return 2;
21091}
21092
21093/* Convert a machine dependent frag. */
21094
21095void
21096md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21097{
21098 unsigned long insn;
21099 unsigned long old_op;
21100 char *buf;
21101 expressionS exp;
21102 fixS *fixp;
21103 int reloc_type;
21104 int pc_rel;
21105 int opcode;
21106
21107 buf = fragp->fr_literal + fragp->fr_fix;
21108
21109 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21110 if (fragp->fr_symbol)
21111 {
0110f2b8
PB
21112 exp.X_op = O_symbol;
21113 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21114 }
21115 else
21116 {
0110f2b8 21117 exp.X_op = O_constant;
5f4273c7 21118 }
0110f2b8
PB
21119 exp.X_add_number = fragp->fr_offset;
21120 opcode = fragp->fr_subtype;
21121 switch (opcode)
21122 {
21123 case T_MNEM_ldr_pc:
21124 case T_MNEM_ldr_pc2:
21125 case T_MNEM_ldr_sp:
21126 case T_MNEM_str_sp:
21127 case T_MNEM_ldr:
21128 case T_MNEM_ldrb:
21129 case T_MNEM_ldrh:
21130 case T_MNEM_str:
21131 case T_MNEM_strb:
21132 case T_MNEM_strh:
21133 if (fragp->fr_var == 4)
21134 {
5f4273c7 21135 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21136 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21137 {
21138 insn |= (old_op & 0x700) << 4;
21139 }
21140 else
21141 {
21142 insn |= (old_op & 7) << 12;
21143 insn |= (old_op & 0x38) << 13;
21144 }
21145 insn |= 0x00000c00;
21146 put_thumb32_insn (buf, insn);
21147 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21148 }
21149 else
21150 {
21151 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21152 }
21153 pc_rel = (opcode == T_MNEM_ldr_pc2);
21154 break;
21155 case T_MNEM_adr:
21156 if (fragp->fr_var == 4)
21157 {
21158 insn = THUMB_OP32 (opcode);
21159 insn |= (old_op & 0xf0) << 4;
21160 put_thumb32_insn (buf, insn);
21161 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21162 }
21163 else
21164 {
21165 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21166 exp.X_add_number -= 4;
21167 }
21168 pc_rel = 1;
21169 break;
21170 case T_MNEM_mov:
21171 case T_MNEM_movs:
21172 case T_MNEM_cmp:
21173 case T_MNEM_cmn:
21174 if (fragp->fr_var == 4)
21175 {
21176 int r0off = (opcode == T_MNEM_mov
21177 || opcode == T_MNEM_movs) ? 0 : 8;
21178 insn = THUMB_OP32 (opcode);
21179 insn = (insn & 0xe1ffffff) | 0x10000000;
21180 insn |= (old_op & 0x700) << r0off;
21181 put_thumb32_insn (buf, insn);
21182 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21183 }
21184 else
21185 {
21186 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21187 }
21188 pc_rel = 0;
21189 break;
21190 case T_MNEM_b:
21191 if (fragp->fr_var == 4)
21192 {
21193 insn = THUMB_OP32(opcode);
21194 put_thumb32_insn (buf, insn);
21195 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21196 }
21197 else
21198 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21199 pc_rel = 1;
21200 break;
21201 case T_MNEM_bcond:
21202 if (fragp->fr_var == 4)
21203 {
21204 insn = THUMB_OP32(opcode);
21205 insn |= (old_op & 0xf00) << 14;
21206 put_thumb32_insn (buf, insn);
21207 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21208 }
21209 else
21210 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21211 pc_rel = 1;
21212 break;
21213 case T_MNEM_add_sp:
21214 case T_MNEM_add_pc:
21215 case T_MNEM_inc_sp:
21216 case T_MNEM_dec_sp:
21217 if (fragp->fr_var == 4)
21218 {
21219 /* ??? Choose between add and addw. */
21220 insn = THUMB_OP32 (opcode);
21221 insn |= (old_op & 0xf0) << 4;
21222 put_thumb32_insn (buf, insn);
16805f35
PB
21223 if (opcode == T_MNEM_add_pc)
21224 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21225 else
21226 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21227 }
21228 else
21229 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21230 pc_rel = 0;
21231 break;
21232
21233 case T_MNEM_addi:
21234 case T_MNEM_addis:
21235 case T_MNEM_subi:
21236 case T_MNEM_subis:
21237 if (fragp->fr_var == 4)
21238 {
21239 insn = THUMB_OP32 (opcode);
21240 insn |= (old_op & 0xf0) << 4;
21241 insn |= (old_op & 0xf) << 16;
21242 put_thumb32_insn (buf, insn);
16805f35
PB
21243 if (insn & (1 << 20))
21244 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21245 else
21246 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21247 }
21248 else
21249 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21250 pc_rel = 0;
21251 break;
21252 default:
5f4273c7 21253 abort ();
0110f2b8
PB
21254 }
21255 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21256 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21257 fixp->fx_file = fragp->fr_file;
21258 fixp->fx_line = fragp->fr_line;
21259 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21260
21261 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21262 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21263 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21264 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21265}
21266
21267/* Return the size of a relaxable immediate operand instruction.
21268 SHIFT and SIZE specify the form of the allowable immediate. */
21269static int
21270relax_immediate (fragS *fragp, int size, int shift)
21271{
21272 offsetT offset;
21273 offsetT mask;
21274 offsetT low;
21275
21276 /* ??? Should be able to do better than this. */
21277 if (fragp->fr_symbol)
21278 return 4;
21279
21280 low = (1 << shift) - 1;
21281 mask = (1 << (shift + size)) - (1 << shift);
21282 offset = fragp->fr_offset;
21283 /* Force misaligned offsets to 32-bit variant. */
21284 if (offset & low)
5e77afaa 21285 return 4;
0110f2b8
PB
21286 if (offset & ~mask)
21287 return 4;
21288 return 2;
21289}
21290
5e77afaa
PB
21291/* Get the address of a symbol during relaxation. */
21292static addressT
5f4273c7 21293relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21294{
21295 fragS *sym_frag;
21296 addressT addr;
21297 symbolS *sym;
21298
21299 sym = fragp->fr_symbol;
21300 sym_frag = symbol_get_frag (sym);
21301 know (S_GET_SEGMENT (sym) != absolute_section
21302 || sym_frag == &zero_address_frag);
21303 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21304
21305 /* If frag has yet to be reached on this pass, assume it will
21306 move by STRETCH just as we did. If this is not so, it will
21307 be because some frag between grows, and that will force
21308 another pass. */
21309
21310 if (stretch != 0
21311 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21312 {
21313 fragS *f;
21314
21315 /* Adjust stretch for any alignment frag. Note that if have
21316 been expanding the earlier code, the symbol may be
21317 defined in what appears to be an earlier frag. FIXME:
21318 This doesn't handle the fr_subtype field, which specifies
21319 a maximum number of bytes to skip when doing an
21320 alignment. */
21321 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21322 {
21323 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21324 {
21325 if (stretch < 0)
21326 stretch = - ((- stretch)
21327 & ~ ((1 << (int) f->fr_offset) - 1));
21328 else
21329 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21330 if (stretch == 0)
21331 break;
21332 }
21333 }
21334 if (f != NULL)
21335 addr += stretch;
21336 }
5e77afaa
PB
21337
21338 return addr;
21339}
21340
0110f2b8
PB
21341/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21342 load. */
21343static int
5e77afaa 21344relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21345{
21346 addressT addr;
21347 offsetT val;
21348
21349 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21350 if (fragp->fr_symbol == NULL
21351 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21352 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21353 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21354 return 4;
21355
5f4273c7 21356 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21357 addr = fragp->fr_address + fragp->fr_fix;
21358 addr = (addr + 4) & ~3;
5e77afaa 21359 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21360 if (val & 3)
5e77afaa 21361 return 4;
0110f2b8
PB
21362 val -= addr;
21363 if (val < 0 || val > 1020)
21364 return 4;
21365 return 2;
21366}
21367
21368/* Return the size of a relaxable add/sub immediate instruction. */
21369static int
21370relax_addsub (fragS *fragp, asection *sec)
21371{
21372 char *buf;
21373 int op;
21374
21375 buf = fragp->fr_literal + fragp->fr_fix;
21376 op = bfd_get_16(sec->owner, buf);
21377 if ((op & 0xf) == ((op >> 4) & 0xf))
21378 return relax_immediate (fragp, 8, 0);
21379 else
21380 return relax_immediate (fragp, 3, 0);
21381}
21382
e83a675f
RE
21383/* Return TRUE iff the definition of symbol S could be pre-empted
21384 (overridden) at link or load time. */
21385static bfd_boolean
21386symbol_preemptible (symbolS *s)
21387{
21388 /* Weak symbols can always be pre-empted. */
21389 if (S_IS_WEAK (s))
21390 return TRUE;
21391
21392 /* Non-global symbols cannot be pre-empted. */
21393 if (! S_IS_EXTERNAL (s))
21394 return FALSE;
21395
21396#ifdef OBJ_ELF
21397 /* In ELF, a global symbol can be marked protected, or private. In that
21398 case it can't be pre-empted (other definitions in the same link unit
21399 would violate the ODR). */
21400 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21401 return FALSE;
21402#endif
21403
21404 /* Other global symbols might be pre-empted. */
21405 return TRUE;
21406}
0110f2b8
PB
21407
21408/* Return the size of a relaxable branch instruction. BITS is the
21409 size of the offset field in the narrow instruction. */
21410
21411static int
5e77afaa 21412relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21413{
21414 addressT addr;
21415 offsetT val;
21416 offsetT limit;
21417
21418 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21419 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21420 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21421 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21422 return 4;
21423
267bf995 21424#ifdef OBJ_ELF
e83a675f 21425 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21426 if (S_IS_DEFINED (fragp->fr_symbol)
21427 && ARM_IS_FUNC (fragp->fr_symbol))
21428 return 4;
e83a675f 21429#endif
0d9b4b55 21430
e83a675f 21431 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21432 return 4;
267bf995 21433
5f4273c7 21434 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21435 addr = fragp->fr_address + fragp->fr_fix + 4;
21436 val -= addr;
21437
21438 /* Offset is a signed value *2 */
21439 limit = 1 << bits;
21440 if (val >= limit || val < -limit)
21441 return 4;
21442 return 2;
21443}
21444
21445
21446/* Relax a machine dependent frag. This returns the amount by which
21447 the current size of the frag should change. */
21448
21449int
5e77afaa 21450arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21451{
21452 int oldsize;
21453 int newsize;
21454
21455 oldsize = fragp->fr_var;
21456 switch (fragp->fr_subtype)
21457 {
21458 case T_MNEM_ldr_pc2:
5f4273c7 21459 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21460 break;
21461 case T_MNEM_ldr_pc:
21462 case T_MNEM_ldr_sp:
21463 case T_MNEM_str_sp:
5f4273c7 21464 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21465 break;
21466 case T_MNEM_ldr:
21467 case T_MNEM_str:
5f4273c7 21468 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21469 break;
21470 case T_MNEM_ldrh:
21471 case T_MNEM_strh:
5f4273c7 21472 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21473 break;
21474 case T_MNEM_ldrb:
21475 case T_MNEM_strb:
5f4273c7 21476 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21477 break;
21478 case T_MNEM_adr:
5f4273c7 21479 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21480 break;
21481 case T_MNEM_mov:
21482 case T_MNEM_movs:
21483 case T_MNEM_cmp:
21484 case T_MNEM_cmn:
5f4273c7 21485 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21486 break;
21487 case T_MNEM_b:
5f4273c7 21488 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21489 break;
21490 case T_MNEM_bcond:
5f4273c7 21491 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21492 break;
21493 case T_MNEM_add_sp:
21494 case T_MNEM_add_pc:
21495 newsize = relax_immediate (fragp, 8, 2);
21496 break;
21497 case T_MNEM_inc_sp:
21498 case T_MNEM_dec_sp:
21499 newsize = relax_immediate (fragp, 7, 2);
21500 break;
21501 case T_MNEM_addi:
21502 case T_MNEM_addis:
21503 case T_MNEM_subi:
21504 case T_MNEM_subis:
21505 newsize = relax_addsub (fragp, sec);
21506 break;
21507 default:
5f4273c7 21508 abort ();
0110f2b8 21509 }
5e77afaa
PB
21510
21511 fragp->fr_var = newsize;
21512 /* Freeze wide instructions that are at or before the same location as
21513 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21514 Don't freeze them unconditionally because targets may be artificially
21515 misaligned by the expansion of preceding frags. */
5e77afaa 21516 if (stretch <= 0 && newsize > 2)
0110f2b8 21517 {
0110f2b8 21518 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21519 frag_wane (fragp);
0110f2b8 21520 }
5e77afaa 21521
0110f2b8 21522 return newsize - oldsize;
c19d1205 21523}
b99bd4ef 21524
c19d1205 21525/* Round up a section size to the appropriate boundary. */
b99bd4ef 21526
c19d1205
ZW
21527valueT
21528md_section_align (segT segment ATTRIBUTE_UNUSED,
21529 valueT size)
21530{
f0927246
NC
21531#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21532 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21533 {
21534 /* For a.out, force the section size to be aligned. If we don't do
21535 this, BFD will align it for us, but it will not write out the
21536 final bytes of the section. This may be a bug in BFD, but it is
21537 easier to fix it here since that is how the other a.out targets
21538 work. */
21539 int align;
21540
21541 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21542 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21543 }
c19d1205 21544#endif
f0927246
NC
21545
21546 return size;
bfae80f2 21547}
b99bd4ef 21548
c19d1205
ZW
21549/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21550 of an rs_align_code fragment. */
21551
21552void
21553arm_handle_align (fragS * fragP)
bfae80f2 21554{
d9235011 21555 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21556 {
21557 { /* ARMv1 */
21558 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21559 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21560 },
21561 { /* ARMv6k */
21562 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21563 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21564 },
21565 };
d9235011 21566 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21567 {
21568 { /* Thumb-1 */
21569 {0xc0, 0x46}, /* LE */
21570 {0x46, 0xc0}, /* BE */
21571 },
21572 { /* Thumb-2 */
21573 {0x00, 0xbf}, /* LE */
21574 {0xbf, 0x00} /* BE */
21575 }
21576 };
d9235011 21577 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21578 { /* Wide Thumb-2 */
21579 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21580 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21581 };
c921be7d 21582
e7495e45 21583 unsigned bytes, fix, noop_size;
c19d1205 21584 char * p;
d9235011
TS
21585 const unsigned char * noop;
21586 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21587#ifdef OBJ_ELF
21588 enum mstate state;
21589#endif
bfae80f2 21590
c19d1205 21591 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21592 return;
21593
c19d1205
ZW
21594 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21595 p = fragP->fr_literal + fragP->fr_fix;
21596 fix = 0;
bfae80f2 21597
c19d1205
ZW
21598 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21599 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21600
cd000bff 21601 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21602
cd000bff 21603 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21604 {
7f78eb34
JW
21605 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21606 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21607 {
21608 narrow_noop = thumb_noop[1][target_big_endian];
21609 noop = wide_thumb_noop[target_big_endian];
21610 }
c19d1205 21611 else
e7495e45
NS
21612 noop = thumb_noop[0][target_big_endian];
21613 noop_size = 2;
cd000bff
DJ
21614#ifdef OBJ_ELF
21615 state = MAP_THUMB;
21616#endif
7ed4c4c5
NC
21617 }
21618 else
21619 {
7f78eb34
JW
21620 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21621 ? selected_cpu : arm_arch_none,
21622 arm_ext_v6k) != 0]
e7495e45
NS
21623 [target_big_endian];
21624 noop_size = 4;
cd000bff
DJ
21625#ifdef OBJ_ELF
21626 state = MAP_ARM;
21627#endif
7ed4c4c5 21628 }
c921be7d 21629
e7495e45 21630 fragP->fr_var = noop_size;
c921be7d 21631
c19d1205 21632 if (bytes & (noop_size - 1))
7ed4c4c5 21633 {
c19d1205 21634 fix = bytes & (noop_size - 1);
cd000bff
DJ
21635#ifdef OBJ_ELF
21636 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21637#endif
c19d1205
ZW
21638 memset (p, 0, fix);
21639 p += fix;
21640 bytes -= fix;
a737bd4d 21641 }
a737bd4d 21642
e7495e45
NS
21643 if (narrow_noop)
21644 {
21645 if (bytes & noop_size)
21646 {
21647 /* Insert a narrow noop. */
21648 memcpy (p, narrow_noop, noop_size);
21649 p += noop_size;
21650 bytes -= noop_size;
21651 fix += noop_size;
21652 }
21653
21654 /* Use wide noops for the remainder */
21655 noop_size = 4;
21656 }
21657
c19d1205 21658 while (bytes >= noop_size)
a737bd4d 21659 {
c19d1205
ZW
21660 memcpy (p, noop, noop_size);
21661 p += noop_size;
21662 bytes -= noop_size;
21663 fix += noop_size;
a737bd4d
NC
21664 }
21665
c19d1205 21666 fragP->fr_fix += fix;
a737bd4d
NC
21667}
21668
c19d1205
ZW
21669/* Called from md_do_align. Used to create an alignment
21670 frag in a code section. */
21671
21672void
21673arm_frag_align_code (int n, int max)
bfae80f2 21674{
c19d1205 21675 char * p;
7ed4c4c5 21676
c19d1205 21677 /* We assume that there will never be a requirement
6ec8e702 21678 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21679 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21680 {
21681 char err_msg[128];
21682
fa94de6b 21683 sprintf (err_msg,
477330fc
RM
21684 _("alignments greater than %d bytes not supported in .text sections."),
21685 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21686 as_fatal ("%s", err_msg);
6ec8e702 21687 }
bfae80f2 21688
c19d1205
ZW
21689 p = frag_var (rs_align_code,
21690 MAX_MEM_FOR_RS_ALIGN_CODE,
21691 1,
21692 (relax_substateT) max,
21693 (symbolS *) NULL,
21694 (offsetT) n,
21695 (char *) NULL);
21696 *p = 0;
21697}
bfae80f2 21698
8dc2430f
NC
21699/* Perform target specific initialisation of a frag.
21700 Note - despite the name this initialisation is not done when the frag
21701 is created, but only when its type is assigned. A frag can be created
21702 and used a long time before its type is set, so beware of assuming that
21703 this initialisationis performed first. */
bfae80f2 21704
cd000bff
DJ
21705#ifndef OBJ_ELF
21706void
21707arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21708{
21709 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21710 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21711}
21712
21713#else /* OBJ_ELF is defined. */
c19d1205 21714void
cd000bff 21715arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21716{
b968d18a
JW
21717 int frag_thumb_mode;
21718
8dc2430f
NC
21719 /* If the current ARM vs THUMB mode has not already
21720 been recorded into this frag then do so now. */
cd000bff 21721 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21722 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21723
21724 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21725
f9c1b181
RL
21726 /* Record a mapping symbol for alignment frags. We will delete this
21727 later if the alignment ends up empty. */
21728 switch (fragP->fr_type)
21729 {
21730 case rs_align:
21731 case rs_align_test:
21732 case rs_fill:
21733 mapping_state_2 (MAP_DATA, max_chars);
21734 break;
21735 case rs_align_code:
b968d18a 21736 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21737 break;
21738 default:
21739 break;
cd000bff 21740 }
bfae80f2
RE
21741}
21742
c19d1205
ZW
21743/* When we change sections we need to issue a new mapping symbol. */
21744
21745void
21746arm_elf_change_section (void)
bfae80f2 21747{
c19d1205
ZW
21748 /* Link an unlinked unwind index table section to the .text section. */
21749 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21750 && elf_linked_to_section (now_seg) == NULL)
21751 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21752}
21753
c19d1205
ZW
21754int
21755arm_elf_section_type (const char * str, size_t len)
e45d0630 21756{
c19d1205
ZW
21757 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21758 return SHT_ARM_EXIDX;
e45d0630 21759
c19d1205
ZW
21760 return -1;
21761}
21762\f
21763/* Code to deal with unwinding tables. */
e45d0630 21764
c19d1205 21765static void add_unwind_adjustsp (offsetT);
e45d0630 21766
5f4273c7 21767/* Generate any deferred unwind frame offset. */
e45d0630 21768
bfae80f2 21769static void
c19d1205 21770flush_pending_unwind (void)
bfae80f2 21771{
c19d1205 21772 offsetT offset;
bfae80f2 21773
c19d1205
ZW
21774 offset = unwind.pending_offset;
21775 unwind.pending_offset = 0;
21776 if (offset != 0)
21777 add_unwind_adjustsp (offset);
bfae80f2
RE
21778}
21779
c19d1205
ZW
21780/* Add an opcode to this list for this function. Two-byte opcodes should
21781 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21782 order. */
21783
bfae80f2 21784static void
c19d1205 21785add_unwind_opcode (valueT op, int length)
bfae80f2 21786{
c19d1205
ZW
21787 /* Add any deferred stack adjustment. */
21788 if (unwind.pending_offset)
21789 flush_pending_unwind ();
bfae80f2 21790
c19d1205 21791 unwind.sp_restored = 0;
bfae80f2 21792
c19d1205 21793 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21794 {
c19d1205
ZW
21795 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21796 if (unwind.opcodes)
325801bd
TS
21797 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21798 unwind.opcode_alloc);
c19d1205 21799 else
325801bd 21800 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21801 }
c19d1205 21802 while (length > 0)
bfae80f2 21803 {
c19d1205
ZW
21804 length--;
21805 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21806 op >>= 8;
21807 unwind.opcode_count++;
bfae80f2 21808 }
bfae80f2
RE
21809}
21810
c19d1205
ZW
21811/* Add unwind opcodes to adjust the stack pointer. */
21812
bfae80f2 21813static void
c19d1205 21814add_unwind_adjustsp (offsetT offset)
bfae80f2 21815{
c19d1205 21816 valueT op;
bfae80f2 21817
c19d1205 21818 if (offset > 0x200)
bfae80f2 21819 {
c19d1205
ZW
21820 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21821 char bytes[5];
21822 int n;
21823 valueT o;
bfae80f2 21824
c19d1205
ZW
21825 /* Long form: 0xb2, uleb128. */
21826 /* This might not fit in a word so add the individual bytes,
21827 remembering the list is built in reverse order. */
21828 o = (valueT) ((offset - 0x204) >> 2);
21829 if (o == 0)
21830 add_unwind_opcode (0, 1);
bfae80f2 21831
c19d1205
ZW
21832 /* Calculate the uleb128 encoding of the offset. */
21833 n = 0;
21834 while (o)
21835 {
21836 bytes[n] = o & 0x7f;
21837 o >>= 7;
21838 if (o)
21839 bytes[n] |= 0x80;
21840 n++;
21841 }
21842 /* Add the insn. */
21843 for (; n; n--)
21844 add_unwind_opcode (bytes[n - 1], 1);
21845 add_unwind_opcode (0xb2, 1);
21846 }
21847 else if (offset > 0x100)
bfae80f2 21848 {
c19d1205
ZW
21849 /* Two short opcodes. */
21850 add_unwind_opcode (0x3f, 1);
21851 op = (offset - 0x104) >> 2;
21852 add_unwind_opcode (op, 1);
bfae80f2 21853 }
c19d1205
ZW
21854 else if (offset > 0)
21855 {
21856 /* Short opcode. */
21857 op = (offset - 4) >> 2;
21858 add_unwind_opcode (op, 1);
21859 }
21860 else if (offset < 0)
bfae80f2 21861 {
c19d1205
ZW
21862 offset = -offset;
21863 while (offset > 0x100)
bfae80f2 21864 {
c19d1205
ZW
21865 add_unwind_opcode (0x7f, 1);
21866 offset -= 0x100;
bfae80f2 21867 }
c19d1205
ZW
21868 op = ((offset - 4) >> 2) | 0x40;
21869 add_unwind_opcode (op, 1);
bfae80f2 21870 }
bfae80f2
RE
21871}
21872
c19d1205
ZW
21873/* Finish the list of unwind opcodes for this function. */
21874static void
21875finish_unwind_opcodes (void)
bfae80f2 21876{
c19d1205 21877 valueT op;
bfae80f2 21878
c19d1205 21879 if (unwind.fp_used)
bfae80f2 21880 {
708587a4 21881 /* Adjust sp as necessary. */
c19d1205
ZW
21882 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21883 flush_pending_unwind ();
bfae80f2 21884
c19d1205
ZW
21885 /* After restoring sp from the frame pointer. */
21886 op = 0x90 | unwind.fp_reg;
21887 add_unwind_opcode (op, 1);
21888 }
21889 else
21890 flush_pending_unwind ();
bfae80f2
RE
21891}
21892
bfae80f2 21893
c19d1205
ZW
21894/* Start an exception table entry. If idx is nonzero this is an index table
21895 entry. */
bfae80f2
RE
21896
21897static void
c19d1205 21898start_unwind_section (const segT text_seg, int idx)
bfae80f2 21899{
c19d1205
ZW
21900 const char * text_name;
21901 const char * prefix;
21902 const char * prefix_once;
21903 const char * group_name;
21904 size_t prefix_len;
21905 size_t text_len;
21906 char * sec_name;
21907 size_t sec_name_len;
21908 int type;
21909 int flags;
21910 int linkonce;
bfae80f2 21911
c19d1205 21912 if (idx)
bfae80f2 21913 {
c19d1205
ZW
21914 prefix = ELF_STRING_ARM_unwind;
21915 prefix_once = ELF_STRING_ARM_unwind_once;
21916 type = SHT_ARM_EXIDX;
bfae80f2 21917 }
c19d1205 21918 else
bfae80f2 21919 {
c19d1205
ZW
21920 prefix = ELF_STRING_ARM_unwind_info;
21921 prefix_once = ELF_STRING_ARM_unwind_info_once;
21922 type = SHT_PROGBITS;
bfae80f2
RE
21923 }
21924
c19d1205
ZW
21925 text_name = segment_name (text_seg);
21926 if (streq (text_name, ".text"))
21927 text_name = "";
21928
21929 if (strncmp (text_name, ".gnu.linkonce.t.",
21930 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21931 {
c19d1205
ZW
21932 prefix = prefix_once;
21933 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21934 }
21935
c19d1205
ZW
21936 prefix_len = strlen (prefix);
21937 text_len = strlen (text_name);
21938 sec_name_len = prefix_len + text_len;
21d799b5 21939 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21940 memcpy (sec_name, prefix, prefix_len);
21941 memcpy (sec_name + prefix_len, text_name, text_len);
21942 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21943
c19d1205
ZW
21944 flags = SHF_ALLOC;
21945 linkonce = 0;
21946 group_name = 0;
bfae80f2 21947
c19d1205
ZW
21948 /* Handle COMDAT group. */
21949 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21950 {
c19d1205
ZW
21951 group_name = elf_group_name (text_seg);
21952 if (group_name == NULL)
21953 {
bd3ba5d1 21954 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21955 segment_name (text_seg));
21956 ignore_rest_of_line ();
21957 return;
21958 }
21959 flags |= SHF_GROUP;
21960 linkonce = 1;
bfae80f2
RE
21961 }
21962
c19d1205 21963 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21964
5f4273c7 21965 /* Set the section link for index tables. */
c19d1205
ZW
21966 if (idx)
21967 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21968}
21969
bfae80f2 21970
c19d1205
ZW
21971/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21972 personality routine data. Returns zero, or the index table value for
cad0da33 21973 an inline entry. */
c19d1205
ZW
21974
21975static valueT
21976create_unwind_entry (int have_data)
bfae80f2 21977{
c19d1205
ZW
21978 int size;
21979 addressT where;
21980 char *ptr;
21981 /* The current word of data. */
21982 valueT data;
21983 /* The number of bytes left in this word. */
21984 int n;
bfae80f2 21985
c19d1205 21986 finish_unwind_opcodes ();
bfae80f2 21987
c19d1205
ZW
21988 /* Remember the current text section. */
21989 unwind.saved_seg = now_seg;
21990 unwind.saved_subseg = now_subseg;
bfae80f2 21991
c19d1205 21992 start_unwind_section (now_seg, 0);
bfae80f2 21993
c19d1205 21994 if (unwind.personality_routine == NULL)
bfae80f2 21995 {
c19d1205
ZW
21996 if (unwind.personality_index == -2)
21997 {
21998 if (have_data)
5f4273c7 21999 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22000 return 1; /* EXIDX_CANTUNWIND. */
22001 }
bfae80f2 22002
c19d1205
ZW
22003 /* Use a default personality routine if none is specified. */
22004 if (unwind.personality_index == -1)
22005 {
22006 if (unwind.opcode_count > 3)
22007 unwind.personality_index = 1;
22008 else
22009 unwind.personality_index = 0;
22010 }
bfae80f2 22011
c19d1205
ZW
22012 /* Space for the personality routine entry. */
22013 if (unwind.personality_index == 0)
22014 {
22015 if (unwind.opcode_count > 3)
22016 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22017
c19d1205
ZW
22018 if (!have_data)
22019 {
22020 /* All the data is inline in the index table. */
22021 data = 0x80;
22022 n = 3;
22023 while (unwind.opcode_count > 0)
22024 {
22025 unwind.opcode_count--;
22026 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22027 n--;
22028 }
bfae80f2 22029
c19d1205
ZW
22030 /* Pad with "finish" opcodes. */
22031 while (n--)
22032 data = (data << 8) | 0xb0;
bfae80f2 22033
c19d1205
ZW
22034 return data;
22035 }
22036 size = 0;
22037 }
22038 else
22039 /* We get two opcodes "free" in the first word. */
22040 size = unwind.opcode_count - 2;
22041 }
22042 else
5011093d 22043 {
cad0da33
NC
22044 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22045 if (unwind.personality_index != -1)
22046 {
22047 as_bad (_("attempt to recreate an unwind entry"));
22048 return 1;
22049 }
5011093d
NC
22050
22051 /* An extra byte is required for the opcode count. */
22052 size = unwind.opcode_count + 1;
22053 }
bfae80f2 22054
c19d1205
ZW
22055 size = (size + 3) >> 2;
22056 if (size > 0xff)
22057 as_bad (_("too many unwind opcodes"));
bfae80f2 22058
c19d1205
ZW
22059 frag_align (2, 0, 0);
22060 record_alignment (now_seg, 2);
22061 unwind.table_entry = expr_build_dot ();
22062
22063 /* Allocate the table entry. */
22064 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22065 /* PR 13449: Zero the table entries in case some of them are not used. */
22066 memset (ptr, 0, (size << 2) + 4);
c19d1205 22067 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22068
c19d1205 22069 switch (unwind.personality_index)
bfae80f2 22070 {
c19d1205
ZW
22071 case -1:
22072 /* ??? Should this be a PLT generating relocation? */
22073 /* Custom personality routine. */
22074 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22075 BFD_RELOC_ARM_PREL31);
bfae80f2 22076
c19d1205
ZW
22077 where += 4;
22078 ptr += 4;
bfae80f2 22079
c19d1205 22080 /* Set the first byte to the number of additional words. */
5011093d 22081 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22082 n = 3;
22083 break;
bfae80f2 22084
c19d1205
ZW
22085 /* ABI defined personality routines. */
22086 case 0:
22087 /* Three opcodes bytes are packed into the first word. */
22088 data = 0x80;
22089 n = 3;
22090 break;
bfae80f2 22091
c19d1205
ZW
22092 case 1:
22093 case 2:
22094 /* The size and first two opcode bytes go in the first word. */
22095 data = ((0x80 + unwind.personality_index) << 8) | size;
22096 n = 2;
22097 break;
bfae80f2 22098
c19d1205
ZW
22099 default:
22100 /* Should never happen. */
22101 abort ();
22102 }
bfae80f2 22103
c19d1205
ZW
22104 /* Pack the opcodes into words (MSB first), reversing the list at the same
22105 time. */
22106 while (unwind.opcode_count > 0)
22107 {
22108 if (n == 0)
22109 {
22110 md_number_to_chars (ptr, data, 4);
22111 ptr += 4;
22112 n = 4;
22113 data = 0;
22114 }
22115 unwind.opcode_count--;
22116 n--;
22117 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22118 }
22119
22120 /* Finish off the last word. */
22121 if (n < 4)
22122 {
22123 /* Pad with "finish" opcodes. */
22124 while (n--)
22125 data = (data << 8) | 0xb0;
22126
22127 md_number_to_chars (ptr, data, 4);
22128 }
22129
22130 if (!have_data)
22131 {
22132 /* Add an empty descriptor if there is no user-specified data. */
22133 ptr = frag_more (4);
22134 md_number_to_chars (ptr, 0, 4);
22135 }
22136
22137 return 0;
bfae80f2
RE
22138}
22139
f0927246
NC
22140
22141/* Initialize the DWARF-2 unwind information for this procedure. */
22142
22143void
22144tc_arm_frame_initial_instructions (void)
22145{
22146 cfi_add_CFA_def_cfa (REG_SP, 0);
22147}
22148#endif /* OBJ_ELF */
22149
c19d1205
ZW
22150/* Convert REGNAME to a DWARF-2 register number. */
22151
22152int
1df69f4f 22153tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22154{
1df69f4f 22155 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22156 if (reg != FAIL)
22157 return reg;
c19d1205 22158
1f5afe1c
NC
22159 /* PR 16694: Allow VFP registers as well. */
22160 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22161 if (reg != FAIL)
22162 return 64 + reg;
c19d1205 22163
1f5afe1c
NC
22164 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22165 if (reg != FAIL)
22166 return reg + 256;
22167
22168 return -1;
bfae80f2
RE
22169}
22170
f0927246 22171#ifdef TE_PE
c19d1205 22172void
f0927246 22173tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22174{
91d6fa6a 22175 expressionS exp;
bfae80f2 22176
91d6fa6a
NC
22177 exp.X_op = O_secrel;
22178 exp.X_add_symbol = symbol;
22179 exp.X_add_number = 0;
22180 emit_expr (&exp, size);
f0927246
NC
22181}
22182#endif
bfae80f2 22183
c19d1205 22184/* MD interface: Symbol and relocation handling. */
bfae80f2 22185
2fc8bdac
ZW
22186/* Return the address within the segment that a PC-relative fixup is
22187 relative to. For ARM, PC-relative fixups applied to instructions
22188 are generally relative to the location of the fixup plus 8 bytes.
22189 Thumb branches are offset by 4, and Thumb loads relative to PC
22190 require special handling. */
bfae80f2 22191
c19d1205 22192long
2fc8bdac 22193md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22194{
2fc8bdac
ZW
22195 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22196
22197 /* If this is pc-relative and we are going to emit a relocation
22198 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22199 will need. Otherwise we want to use the calculated base.
22200 For WinCE we skip the bias for externals as well, since this
22201 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22202 if (fixP->fx_pcrel
2fc8bdac 22203 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22204 || (arm_force_relocation (fixP)
22205#ifdef TE_WINCE
22206 && !S_IS_EXTERNAL (fixP->fx_addsy)
22207#endif
22208 )))
2fc8bdac 22209 base = 0;
bfae80f2 22210
267bf995 22211
c19d1205 22212 switch (fixP->fx_r_type)
bfae80f2 22213 {
2fc8bdac
ZW
22214 /* PC relative addressing on the Thumb is slightly odd as the
22215 bottom two bits of the PC are forced to zero for the
22216 calculation. This happens *after* application of the
22217 pipeline offset. However, Thumb adrl already adjusts for
22218 this, so we need not do it again. */
c19d1205 22219 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22220 return base & ~3;
c19d1205
ZW
22221
22222 case BFD_RELOC_ARM_THUMB_OFFSET:
22223 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22224 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22225 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22226 return (base + 4) & ~3;
c19d1205 22227
2fc8bdac
ZW
22228 /* Thumb branches are simply offset by +4. */
22229 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22230 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22231 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22232 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22233 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22234 return base + 4;
bfae80f2 22235
267bf995 22236 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22237 if (fixP->fx_addsy
22238 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22239 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22240 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22241 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22242 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22243 return base + 4;
22244
00adf2d4
JB
22245 /* BLX is like branches above, but forces the low two bits of PC to
22246 zero. */
486499d0
CL
22247 case BFD_RELOC_THUMB_PCREL_BLX:
22248 if (fixP->fx_addsy
22249 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22250 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22251 && THUMB_IS_FUNC (fixP->fx_addsy)
22252 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22253 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22254 return (base + 4) & ~3;
22255
2fc8bdac
ZW
22256 /* ARM mode branches are offset by +8. However, the Windows CE
22257 loader expects the relocation not to take this into account. */
267bf995 22258 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22259 if (fixP->fx_addsy
22260 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22261 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22262 && ARM_IS_FUNC (fixP->fx_addsy)
22263 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22264 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22265 return base + 8;
267bf995 22266
486499d0
CL
22267 case BFD_RELOC_ARM_PCREL_CALL:
22268 if (fixP->fx_addsy
22269 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22270 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22271 && THUMB_IS_FUNC (fixP->fx_addsy)
22272 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22273 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22274 return base + 8;
267bf995 22275
2fc8bdac 22276 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22277 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22278 case BFD_RELOC_ARM_PLT32:
c19d1205 22279#ifdef TE_WINCE
5f4273c7 22280 /* When handling fixups immediately, because we have already
477330fc 22281 discovered the value of a symbol, or the address of the frag involved
53baae48 22282 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22283 see fixup_segment() in write.c
22284 The S_IS_EXTERNAL test handles the case of global symbols.
22285 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22286 if (fixP->fx_pcrel
22287 && fixP->fx_addsy != NULL
22288 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22289 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22290 return base + 8;
2fc8bdac 22291 return base;
c19d1205 22292#else
2fc8bdac 22293 return base + 8;
c19d1205 22294#endif
2fc8bdac 22295
267bf995 22296
2fc8bdac
ZW
22297 /* ARM mode loads relative to PC are also offset by +8. Unlike
22298 branches, the Windows CE loader *does* expect the relocation
22299 to take this into account. */
22300 case BFD_RELOC_ARM_OFFSET_IMM:
22301 case BFD_RELOC_ARM_OFFSET_IMM8:
22302 case BFD_RELOC_ARM_HWLITERAL:
22303 case BFD_RELOC_ARM_LITERAL:
22304 case BFD_RELOC_ARM_CP_OFF_IMM:
22305 return base + 8;
22306
22307
22308 /* Other PC-relative relocations are un-offset. */
22309 default:
22310 return base;
22311 }
bfae80f2
RE
22312}
22313
8b2d793c
NC
22314static bfd_boolean flag_warn_syms = TRUE;
22315
ae8714c2
NC
22316bfd_boolean
22317arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22318{
8b2d793c
NC
22319 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22320 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22321 does mean that the resulting code might be very confusing to the reader.
22322 Also this warning can be triggered if the user omits an operand before
22323 an immediate address, eg:
22324
22325 LDR =foo
22326
22327 GAS treats this as an assignment of the value of the symbol foo to a
22328 symbol LDR, and so (without this code) it will not issue any kind of
22329 warning or error message.
22330
22331 Note - ARM instructions are case-insensitive but the strings in the hash
22332 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22333 lower case too. */
22334 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22335 {
22336 char * nbuf = strdup (name);
22337 char * p;
22338
22339 for (p = nbuf; *p; p++)
22340 *p = TOLOWER (*p);
22341 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22342 {
22343 static struct hash_control * already_warned = NULL;
22344
22345 if (already_warned == NULL)
22346 already_warned = hash_new ();
22347 /* Only warn about the symbol once. To keep the code
22348 simple we let hash_insert do the lookup for us. */
22349 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22350 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22351 }
22352 else
22353 free (nbuf);
22354 }
3739860c 22355
ae8714c2
NC
22356 return FALSE;
22357}
22358
22359/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22360 Otherwise we have no need to default values of symbols. */
22361
22362symbolS *
22363md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22364{
22365#ifdef OBJ_ELF
22366 if (name[0] == '_' && name[1] == 'G'
22367 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22368 {
22369 if (!GOT_symbol)
22370 {
22371 if (symbol_find (name))
22372 as_bad (_("GOT already in the symbol table"));
22373
22374 GOT_symbol = symbol_new (name, undefined_section,
22375 (valueT) 0, & zero_address_frag);
22376 }
22377
22378 return GOT_symbol;
22379 }
22380#endif
22381
c921be7d 22382 return NULL;
bfae80f2
RE
22383}
22384
55cf6793 22385/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22386 computed as two separate immediate values, added together. We
22387 already know that this value cannot be computed by just one ARM
22388 instruction. */
22389
22390static unsigned int
22391validate_immediate_twopart (unsigned int val,
22392 unsigned int * highpart)
bfae80f2 22393{
c19d1205
ZW
22394 unsigned int a;
22395 unsigned int i;
bfae80f2 22396
c19d1205
ZW
22397 for (i = 0; i < 32; i += 2)
22398 if (((a = rotate_left (val, i)) & 0xff) != 0)
22399 {
22400 if (a & 0xff00)
22401 {
22402 if (a & ~ 0xffff)
22403 continue;
22404 * highpart = (a >> 8) | ((i + 24) << 7);
22405 }
22406 else if (a & 0xff0000)
22407 {
22408 if (a & 0xff000000)
22409 continue;
22410 * highpart = (a >> 16) | ((i + 16) << 7);
22411 }
22412 else
22413 {
9c2799c2 22414 gas_assert (a & 0xff000000);
c19d1205
ZW
22415 * highpart = (a >> 24) | ((i + 8) << 7);
22416 }
bfae80f2 22417
c19d1205
ZW
22418 return (a & 0xff) | (i << 7);
22419 }
bfae80f2 22420
c19d1205 22421 return FAIL;
bfae80f2
RE
22422}
22423
c19d1205
ZW
22424static int
22425validate_offset_imm (unsigned int val, int hwse)
22426{
22427 if ((hwse && val > 255) || val > 4095)
22428 return FAIL;
22429 return val;
22430}
bfae80f2 22431
55cf6793 22432/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22433 negative immediate constant by altering the instruction. A bit of
22434 a hack really.
22435 MOV <-> MVN
22436 AND <-> BIC
22437 ADC <-> SBC
22438 by inverting the second operand, and
22439 ADD <-> SUB
22440 CMP <-> CMN
22441 by negating the second operand. */
bfae80f2 22442
c19d1205
ZW
22443static int
22444negate_data_op (unsigned long * instruction,
22445 unsigned long value)
bfae80f2 22446{
c19d1205
ZW
22447 int op, new_inst;
22448 unsigned long negated, inverted;
bfae80f2 22449
c19d1205
ZW
22450 negated = encode_arm_immediate (-value);
22451 inverted = encode_arm_immediate (~value);
bfae80f2 22452
c19d1205
ZW
22453 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22454 switch (op)
bfae80f2 22455 {
c19d1205
ZW
22456 /* First negates. */
22457 case OPCODE_SUB: /* ADD <-> SUB */
22458 new_inst = OPCODE_ADD;
22459 value = negated;
22460 break;
bfae80f2 22461
c19d1205
ZW
22462 case OPCODE_ADD:
22463 new_inst = OPCODE_SUB;
22464 value = negated;
22465 break;
bfae80f2 22466
c19d1205
ZW
22467 case OPCODE_CMP: /* CMP <-> CMN */
22468 new_inst = OPCODE_CMN;
22469 value = negated;
22470 break;
bfae80f2 22471
c19d1205
ZW
22472 case OPCODE_CMN:
22473 new_inst = OPCODE_CMP;
22474 value = negated;
22475 break;
bfae80f2 22476
c19d1205
ZW
22477 /* Now Inverted ops. */
22478 case OPCODE_MOV: /* MOV <-> MVN */
22479 new_inst = OPCODE_MVN;
22480 value = inverted;
22481 break;
bfae80f2 22482
c19d1205
ZW
22483 case OPCODE_MVN:
22484 new_inst = OPCODE_MOV;
22485 value = inverted;
22486 break;
bfae80f2 22487
c19d1205
ZW
22488 case OPCODE_AND: /* AND <-> BIC */
22489 new_inst = OPCODE_BIC;
22490 value = inverted;
22491 break;
bfae80f2 22492
c19d1205
ZW
22493 case OPCODE_BIC:
22494 new_inst = OPCODE_AND;
22495 value = inverted;
22496 break;
bfae80f2 22497
c19d1205
ZW
22498 case OPCODE_ADC: /* ADC <-> SBC */
22499 new_inst = OPCODE_SBC;
22500 value = inverted;
22501 break;
bfae80f2 22502
c19d1205
ZW
22503 case OPCODE_SBC:
22504 new_inst = OPCODE_ADC;
22505 value = inverted;
22506 break;
bfae80f2 22507
c19d1205
ZW
22508 /* We cannot do anything. */
22509 default:
22510 return FAIL;
b99bd4ef
NC
22511 }
22512
c19d1205
ZW
22513 if (value == (unsigned) FAIL)
22514 return FAIL;
22515
22516 *instruction &= OPCODE_MASK;
22517 *instruction |= new_inst << DATA_OP_SHIFT;
22518 return value;
b99bd4ef
NC
22519}
22520
ef8d22e6
PB
22521/* Like negate_data_op, but for Thumb-2. */
22522
22523static unsigned int
16dd5e42 22524thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22525{
22526 int op, new_inst;
22527 int rd;
16dd5e42 22528 unsigned int negated, inverted;
ef8d22e6
PB
22529
22530 negated = encode_thumb32_immediate (-value);
22531 inverted = encode_thumb32_immediate (~value);
22532
22533 rd = (*instruction >> 8) & 0xf;
22534 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22535 switch (op)
22536 {
22537 /* ADD <-> SUB. Includes CMP <-> CMN. */
22538 case T2_OPCODE_SUB:
22539 new_inst = T2_OPCODE_ADD;
22540 value = negated;
22541 break;
22542
22543 case T2_OPCODE_ADD:
22544 new_inst = T2_OPCODE_SUB;
22545 value = negated;
22546 break;
22547
22548 /* ORR <-> ORN. Includes MOV <-> MVN. */
22549 case T2_OPCODE_ORR:
22550 new_inst = T2_OPCODE_ORN;
22551 value = inverted;
22552 break;
22553
22554 case T2_OPCODE_ORN:
22555 new_inst = T2_OPCODE_ORR;
22556 value = inverted;
22557 break;
22558
22559 /* AND <-> BIC. TST has no inverted equivalent. */
22560 case T2_OPCODE_AND:
22561 new_inst = T2_OPCODE_BIC;
22562 if (rd == 15)
22563 value = FAIL;
22564 else
22565 value = inverted;
22566 break;
22567
22568 case T2_OPCODE_BIC:
22569 new_inst = T2_OPCODE_AND;
22570 value = inverted;
22571 break;
22572
22573 /* ADC <-> SBC */
22574 case T2_OPCODE_ADC:
22575 new_inst = T2_OPCODE_SBC;
22576 value = inverted;
22577 break;
22578
22579 case T2_OPCODE_SBC:
22580 new_inst = T2_OPCODE_ADC;
22581 value = inverted;
22582 break;
22583
22584 /* We cannot do anything. */
22585 default:
22586 return FAIL;
22587 }
22588
16dd5e42 22589 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22590 return FAIL;
22591
22592 *instruction &= T2_OPCODE_MASK;
22593 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22594 return value;
22595}
22596
8f06b2d8
PB
22597/* Read a 32-bit thumb instruction from buf. */
22598static unsigned long
22599get_thumb32_insn (char * buf)
22600{
22601 unsigned long insn;
22602 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22603 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22604
22605 return insn;
22606}
22607
a8bc6c78
PB
22608
22609/* We usually want to set the low bit on the address of thumb function
22610 symbols. In particular .word foo - . should have the low bit set.
22611 Generic code tries to fold the difference of two symbols to
22612 a constant. Prevent this and force a relocation when the first symbols
22613 is a thumb function. */
c921be7d
NC
22614
22615bfd_boolean
a8bc6c78
PB
22616arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22617{
22618 if (op == O_subtract
22619 && l->X_op == O_symbol
22620 && r->X_op == O_symbol
22621 && THUMB_IS_FUNC (l->X_add_symbol))
22622 {
22623 l->X_op = O_subtract;
22624 l->X_op_symbol = r->X_add_symbol;
22625 l->X_add_number -= r->X_add_number;
c921be7d 22626 return TRUE;
a8bc6c78 22627 }
c921be7d 22628
a8bc6c78 22629 /* Process as normal. */
c921be7d 22630 return FALSE;
a8bc6c78
PB
22631}
22632
4a42ebbc
RR
22633/* Encode Thumb2 unconditional branches and calls. The encoding
22634 for the 2 are identical for the immediate values. */
22635
22636static void
22637encode_thumb2_b_bl_offset (char * buf, offsetT value)
22638{
22639#define T2I1I2MASK ((1 << 13) | (1 << 11))
22640 offsetT newval;
22641 offsetT newval2;
22642 addressT S, I1, I2, lo, hi;
22643
22644 S = (value >> 24) & 0x01;
22645 I1 = (value >> 23) & 0x01;
22646 I2 = (value >> 22) & 0x01;
22647 hi = (value >> 12) & 0x3ff;
fa94de6b 22648 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22649 newval = md_chars_to_number (buf, THUMB_SIZE);
22650 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22651 newval |= (S << 10) | hi;
22652 newval2 &= ~T2I1I2MASK;
22653 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22654 md_number_to_chars (buf, newval, THUMB_SIZE);
22655 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22656}
22657
c19d1205 22658void
55cf6793 22659md_apply_fix (fixS * fixP,
c19d1205
ZW
22660 valueT * valP,
22661 segT seg)
22662{
22663 offsetT value = * valP;
22664 offsetT newval;
22665 unsigned int newimm;
22666 unsigned long temp;
22667 int sign;
22668 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22669
9c2799c2 22670 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22671
c19d1205 22672 /* Note whether this will delete the relocation. */
4962c51a 22673
c19d1205
ZW
22674 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22675 fixP->fx_done = 1;
b99bd4ef 22676
adbaf948 22677 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22678 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22679 for emit_reloc. */
22680 value &= 0xffffffff;
22681 value ^= 0x80000000;
5f4273c7 22682 value -= 0x80000000;
adbaf948
ZW
22683
22684 *valP = value;
c19d1205 22685 fixP->fx_addnumber = value;
b99bd4ef 22686
adbaf948
ZW
22687 /* Same treatment for fixP->fx_offset. */
22688 fixP->fx_offset &= 0xffffffff;
22689 fixP->fx_offset ^= 0x80000000;
22690 fixP->fx_offset -= 0x80000000;
22691
c19d1205 22692 switch (fixP->fx_r_type)
b99bd4ef 22693 {
c19d1205
ZW
22694 case BFD_RELOC_NONE:
22695 /* This will need to go in the object file. */
22696 fixP->fx_done = 0;
22697 break;
b99bd4ef 22698
c19d1205
ZW
22699 case BFD_RELOC_ARM_IMMEDIATE:
22700 /* We claim that this fixup has been processed here,
22701 even if in fact we generate an error because we do
22702 not have a reloc for it, so tc_gen_reloc will reject it. */
22703 fixP->fx_done = 1;
b99bd4ef 22704
77db8e2e 22705 if (fixP->fx_addsy)
b99bd4ef 22706 {
77db8e2e 22707 const char *msg = 0;
b99bd4ef 22708
77db8e2e
NC
22709 if (! S_IS_DEFINED (fixP->fx_addsy))
22710 msg = _("undefined symbol %s used as an immediate value");
22711 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22712 msg = _("symbol %s is in a different section");
22713 else if (S_IS_WEAK (fixP->fx_addsy))
22714 msg = _("symbol %s is weak and may be overridden later");
22715
22716 if (msg)
22717 {
22718 as_bad_where (fixP->fx_file, fixP->fx_line,
22719 msg, S_GET_NAME (fixP->fx_addsy));
22720 break;
22721 }
42e5fcbf
AS
22722 }
22723
c19d1205
ZW
22724 temp = md_chars_to_number (buf, INSN_SIZE);
22725
5e73442d
SL
22726 /* If the offset is negative, we should use encoding A2 for ADR. */
22727 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22728 newimm = negate_data_op (&temp, value);
22729 else
22730 {
22731 newimm = encode_arm_immediate (value);
22732
22733 /* If the instruction will fail, see if we can fix things up by
22734 changing the opcode. */
22735 if (newimm == (unsigned int) FAIL)
22736 newimm = negate_data_op (&temp, value);
22737 }
22738
22739 if (newimm == (unsigned int) FAIL)
b99bd4ef 22740 {
c19d1205
ZW
22741 as_bad_where (fixP->fx_file, fixP->fx_line,
22742 _("invalid constant (%lx) after fixup"),
22743 (unsigned long) value);
22744 break;
b99bd4ef 22745 }
b99bd4ef 22746
c19d1205
ZW
22747 newimm |= (temp & 0xfffff000);
22748 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22749 break;
b99bd4ef 22750
c19d1205
ZW
22751 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22752 {
22753 unsigned int highpart = 0;
22754 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22755
77db8e2e 22756 if (fixP->fx_addsy)
42e5fcbf 22757 {
77db8e2e 22758 const char *msg = 0;
42e5fcbf 22759
77db8e2e
NC
22760 if (! S_IS_DEFINED (fixP->fx_addsy))
22761 msg = _("undefined symbol %s used as an immediate value");
22762 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22763 msg = _("symbol %s is in a different section");
22764 else if (S_IS_WEAK (fixP->fx_addsy))
22765 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22766
77db8e2e
NC
22767 if (msg)
22768 {
22769 as_bad_where (fixP->fx_file, fixP->fx_line,
22770 msg, S_GET_NAME (fixP->fx_addsy));
22771 break;
22772 }
22773 }
fa94de6b 22774
c19d1205
ZW
22775 newimm = encode_arm_immediate (value);
22776 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22777
c19d1205
ZW
22778 /* If the instruction will fail, see if we can fix things up by
22779 changing the opcode. */
22780 if (newimm == (unsigned int) FAIL
22781 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22782 {
22783 /* No ? OK - try using two ADD instructions to generate
22784 the value. */
22785 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22786
c19d1205
ZW
22787 /* Yes - then make sure that the second instruction is
22788 also an add. */
22789 if (newimm != (unsigned int) FAIL)
22790 newinsn = temp;
22791 /* Still No ? Try using a negated value. */
22792 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22793 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22794 /* Otherwise - give up. */
22795 else
22796 {
22797 as_bad_where (fixP->fx_file, fixP->fx_line,
22798 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22799 (long) value);
22800 break;
22801 }
b99bd4ef 22802
c19d1205
ZW
22803 /* Replace the first operand in the 2nd instruction (which
22804 is the PC) with the destination register. We have
22805 already added in the PC in the first instruction and we
22806 do not want to do it again. */
22807 newinsn &= ~ 0xf0000;
22808 newinsn |= ((newinsn & 0x0f000) << 4);
22809 }
b99bd4ef 22810
c19d1205
ZW
22811 newimm |= (temp & 0xfffff000);
22812 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22813
c19d1205
ZW
22814 highpart |= (newinsn & 0xfffff000);
22815 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22816 }
22817 break;
b99bd4ef 22818
c19d1205 22819 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22820 if (!fixP->fx_done && seg->use_rela_p)
22821 value = 0;
22822
c19d1205 22823 case BFD_RELOC_ARM_LITERAL:
26d97720 22824 sign = value > 0;
b99bd4ef 22825
c19d1205
ZW
22826 if (value < 0)
22827 value = - value;
b99bd4ef 22828
c19d1205 22829 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22830 {
c19d1205
ZW
22831 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22832 as_bad_where (fixP->fx_file, fixP->fx_line,
22833 _("invalid literal constant: pool needs to be closer"));
22834 else
22835 as_bad_where (fixP->fx_file, fixP->fx_line,
22836 _("bad immediate value for offset (%ld)"),
22837 (long) value);
22838 break;
f03698e6
RE
22839 }
22840
c19d1205 22841 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22842 if (value == 0)
22843 newval &= 0xfffff000;
22844 else
22845 {
22846 newval &= 0xff7ff000;
22847 newval |= value | (sign ? INDEX_UP : 0);
22848 }
c19d1205
ZW
22849 md_number_to_chars (buf, newval, INSN_SIZE);
22850 break;
b99bd4ef 22851
c19d1205
ZW
22852 case BFD_RELOC_ARM_OFFSET_IMM8:
22853 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22854 sign = value > 0;
b99bd4ef 22855
c19d1205
ZW
22856 if (value < 0)
22857 value = - value;
b99bd4ef 22858
c19d1205 22859 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22860 {
c19d1205
ZW
22861 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22862 as_bad_where (fixP->fx_file, fixP->fx_line,
22863 _("invalid literal constant: pool needs to be closer"));
22864 else
427d0db6
RM
22865 as_bad_where (fixP->fx_file, fixP->fx_line,
22866 _("bad immediate value for 8-bit offset (%ld)"),
22867 (long) value);
c19d1205 22868 break;
b99bd4ef
NC
22869 }
22870
c19d1205 22871 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22872 if (value == 0)
22873 newval &= 0xfffff0f0;
22874 else
22875 {
22876 newval &= 0xff7ff0f0;
22877 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22878 }
c19d1205
ZW
22879 md_number_to_chars (buf, newval, INSN_SIZE);
22880 break;
b99bd4ef 22881
c19d1205
ZW
22882 case BFD_RELOC_ARM_T32_OFFSET_U8:
22883 if (value < 0 || value > 1020 || value % 4 != 0)
22884 as_bad_where (fixP->fx_file, fixP->fx_line,
22885 _("bad immediate value for offset (%ld)"), (long) value);
22886 value /= 4;
b99bd4ef 22887
c19d1205 22888 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22889 newval |= value;
22890 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22891 break;
b99bd4ef 22892
c19d1205
ZW
22893 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22894 /* This is a complicated relocation used for all varieties of Thumb32
22895 load/store instruction with immediate offset:
22896
22897 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22898 *4, optional writeback(W)
c19d1205
ZW
22899 (doubleword load/store)
22900
22901 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22902 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22903 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22904 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22905 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22906
22907 Uppercase letters indicate bits that are already encoded at
22908 this point. Lowercase letters are our problem. For the
22909 second block of instructions, the secondary opcode nybble
22910 (bits 8..11) is present, and bit 23 is zero, even if this is
22911 a PC-relative operation. */
22912 newval = md_chars_to_number (buf, THUMB_SIZE);
22913 newval <<= 16;
22914 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22915
c19d1205 22916 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22917 {
c19d1205
ZW
22918 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22919 if (value >= 0)
22920 newval |= (1 << 23);
22921 else
22922 value = -value;
22923 if (value % 4 != 0)
22924 {
22925 as_bad_where (fixP->fx_file, fixP->fx_line,
22926 _("offset not a multiple of 4"));
22927 break;
22928 }
22929 value /= 4;
216d22bc 22930 if (value > 0xff)
c19d1205
ZW
22931 {
22932 as_bad_where (fixP->fx_file, fixP->fx_line,
22933 _("offset out of range"));
22934 break;
22935 }
22936 newval &= ~0xff;
b99bd4ef 22937 }
c19d1205 22938 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22939 {
c19d1205
ZW
22940 /* PC-relative, 12-bit offset. */
22941 if (value >= 0)
22942 newval |= (1 << 23);
22943 else
22944 value = -value;
216d22bc 22945 if (value > 0xfff)
c19d1205
ZW
22946 {
22947 as_bad_where (fixP->fx_file, fixP->fx_line,
22948 _("offset out of range"));
22949 break;
22950 }
22951 newval &= ~0xfff;
b99bd4ef 22952 }
c19d1205 22953 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22954 {
c19d1205
ZW
22955 /* Writeback: 8-bit, +/- offset. */
22956 if (value >= 0)
22957 newval |= (1 << 9);
22958 else
22959 value = -value;
216d22bc 22960 if (value > 0xff)
c19d1205
ZW
22961 {
22962 as_bad_where (fixP->fx_file, fixP->fx_line,
22963 _("offset out of range"));
22964 break;
22965 }
22966 newval &= ~0xff;
b99bd4ef 22967 }
c19d1205 22968 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22969 {
c19d1205 22970 /* T-instruction: positive 8-bit offset. */
216d22bc 22971 if (value < 0 || value > 0xff)
b99bd4ef 22972 {
c19d1205
ZW
22973 as_bad_where (fixP->fx_file, fixP->fx_line,
22974 _("offset out of range"));
22975 break;
b99bd4ef 22976 }
c19d1205
ZW
22977 newval &= ~0xff;
22978 newval |= value;
b99bd4ef
NC
22979 }
22980 else
b99bd4ef 22981 {
c19d1205
ZW
22982 /* Positive 12-bit or negative 8-bit offset. */
22983 int limit;
22984 if (value >= 0)
b99bd4ef 22985 {
c19d1205
ZW
22986 newval |= (1 << 23);
22987 limit = 0xfff;
22988 }
22989 else
22990 {
22991 value = -value;
22992 limit = 0xff;
22993 }
22994 if (value > limit)
22995 {
22996 as_bad_where (fixP->fx_file, fixP->fx_line,
22997 _("offset out of range"));
22998 break;
b99bd4ef 22999 }
c19d1205 23000 newval &= ~limit;
b99bd4ef 23001 }
b99bd4ef 23002
c19d1205
ZW
23003 newval |= value;
23004 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23005 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23006 break;
404ff6b5 23007
c19d1205
ZW
23008 case BFD_RELOC_ARM_SHIFT_IMM:
23009 newval = md_chars_to_number (buf, INSN_SIZE);
23010 if (((unsigned long) value) > 32
23011 || (value == 32
23012 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23013 {
23014 as_bad_where (fixP->fx_file, fixP->fx_line,
23015 _("shift expression is too large"));
23016 break;
23017 }
404ff6b5 23018
c19d1205
ZW
23019 if (value == 0)
23020 /* Shifts of zero must be done as lsl. */
23021 newval &= ~0x60;
23022 else if (value == 32)
23023 value = 0;
23024 newval &= 0xfffff07f;
23025 newval |= (value & 0x1f) << 7;
23026 md_number_to_chars (buf, newval, INSN_SIZE);
23027 break;
404ff6b5 23028
c19d1205 23029 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23030 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23031 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23032 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23033 /* We claim that this fixup has been processed here,
23034 even if in fact we generate an error because we do
23035 not have a reloc for it, so tc_gen_reloc will reject it. */
23036 fixP->fx_done = 1;
404ff6b5 23037
c19d1205
ZW
23038 if (fixP->fx_addsy
23039 && ! S_IS_DEFINED (fixP->fx_addsy))
23040 {
23041 as_bad_where (fixP->fx_file, fixP->fx_line,
23042 _("undefined symbol %s used as an immediate value"),
23043 S_GET_NAME (fixP->fx_addsy));
23044 break;
23045 }
404ff6b5 23046
c19d1205
ZW
23047 newval = md_chars_to_number (buf, THUMB_SIZE);
23048 newval <<= 16;
23049 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23050
16805f35
PB
23051 newimm = FAIL;
23052 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23053 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23054 {
23055 newimm = encode_thumb32_immediate (value);
23056 if (newimm == (unsigned int) FAIL)
23057 newimm = thumb32_negate_data_op (&newval, value);
23058 }
16805f35
PB
23059 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
23060 && newimm == (unsigned int) FAIL)
92e90b6e 23061 {
16805f35
PB
23062 /* Turn add/sum into addw/subw. */
23063 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23064 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
23065 /* No flat 12-bit imm encoding for addsw/subsw. */
23066 if ((newval & 0x00100000) == 0)
e9f89963 23067 {
40f246e3
NC
23068 /* 12 bit immediate for addw/subw. */
23069 if (value < 0)
23070 {
23071 value = -value;
23072 newval ^= 0x00a00000;
23073 }
23074 if (value > 0xfff)
23075 newimm = (unsigned int) FAIL;
23076 else
23077 newimm = value;
e9f89963 23078 }
92e90b6e 23079 }
cc8a6dd0 23080
c19d1205 23081 if (newimm == (unsigned int)FAIL)
3631a3c8 23082 {
c19d1205
ZW
23083 as_bad_where (fixP->fx_file, fixP->fx_line,
23084 _("invalid constant (%lx) after fixup"),
23085 (unsigned long) value);
23086 break;
3631a3c8
NC
23087 }
23088
c19d1205
ZW
23089 newval |= (newimm & 0x800) << 15;
23090 newval |= (newimm & 0x700) << 4;
23091 newval |= (newimm & 0x0ff);
cc8a6dd0 23092
c19d1205
ZW
23093 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23094 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23095 break;
a737bd4d 23096
3eb17e6b 23097 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23098 if (((unsigned long) value) > 0xffff)
23099 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23100 _("invalid smc expression"));
2fc8bdac 23101 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23102 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23103 md_number_to_chars (buf, newval, INSN_SIZE);
23104 break;
a737bd4d 23105
90ec0d68
MGD
23106 case BFD_RELOC_ARM_HVC:
23107 if (((unsigned long) value) > 0xffff)
23108 as_bad_where (fixP->fx_file, fixP->fx_line,
23109 _("invalid hvc expression"));
23110 newval = md_chars_to_number (buf, INSN_SIZE);
23111 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23112 md_number_to_chars (buf, newval, INSN_SIZE);
23113 break;
23114
c19d1205 23115 case BFD_RELOC_ARM_SWI:
adbaf948 23116 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23117 {
23118 if (((unsigned long) value) > 0xff)
23119 as_bad_where (fixP->fx_file, fixP->fx_line,
23120 _("invalid swi expression"));
2fc8bdac 23121 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23122 newval |= value;
23123 md_number_to_chars (buf, newval, THUMB_SIZE);
23124 }
23125 else
23126 {
23127 if (((unsigned long) value) > 0x00ffffff)
23128 as_bad_where (fixP->fx_file, fixP->fx_line,
23129 _("invalid swi expression"));
2fc8bdac 23130 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23131 newval |= value;
23132 md_number_to_chars (buf, newval, INSN_SIZE);
23133 }
23134 break;
a737bd4d 23135
c19d1205
ZW
23136 case BFD_RELOC_ARM_MULTI:
23137 if (((unsigned long) value) > 0xffff)
23138 as_bad_where (fixP->fx_file, fixP->fx_line,
23139 _("invalid expression in load/store multiple"));
23140 newval = value | md_chars_to_number (buf, INSN_SIZE);
23141 md_number_to_chars (buf, newval, INSN_SIZE);
23142 break;
a737bd4d 23143
c19d1205 23144#ifdef OBJ_ELF
39b41c9c 23145 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23146
23147 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23148 && fixP->fx_addsy
34e77a92 23149 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23150 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23151 && THUMB_IS_FUNC (fixP->fx_addsy))
23152 /* Flip the bl to blx. This is a simple flip
23153 bit here because we generate PCREL_CALL for
23154 unconditional bls. */
23155 {
23156 newval = md_chars_to_number (buf, INSN_SIZE);
23157 newval = newval | 0x10000000;
23158 md_number_to_chars (buf, newval, INSN_SIZE);
23159 temp = 1;
23160 fixP->fx_done = 1;
23161 }
39b41c9c
PB
23162 else
23163 temp = 3;
23164 goto arm_branch_common;
23165
23166 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23167 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23168 && fixP->fx_addsy
34e77a92 23169 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23170 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23171 && THUMB_IS_FUNC (fixP->fx_addsy))
23172 {
23173 /* This would map to a bl<cond>, b<cond>,
23174 b<always> to a Thumb function. We
23175 need to force a relocation for this particular
23176 case. */
23177 newval = md_chars_to_number (buf, INSN_SIZE);
23178 fixP->fx_done = 0;
23179 }
23180
2fc8bdac 23181 case BFD_RELOC_ARM_PLT32:
c19d1205 23182#endif
39b41c9c
PB
23183 case BFD_RELOC_ARM_PCREL_BRANCH:
23184 temp = 3;
23185 goto arm_branch_common;
a737bd4d 23186
39b41c9c 23187 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23188
39b41c9c 23189 temp = 1;
267bf995
RR
23190 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23191 && fixP->fx_addsy
34e77a92 23192 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23193 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23194 && ARM_IS_FUNC (fixP->fx_addsy))
23195 {
23196 /* Flip the blx to a bl and warn. */
23197 const char *name = S_GET_NAME (fixP->fx_addsy);
23198 newval = 0xeb000000;
23199 as_warn_where (fixP->fx_file, fixP->fx_line,
23200 _("blx to '%s' an ARM ISA state function changed to bl"),
23201 name);
23202 md_number_to_chars (buf, newval, INSN_SIZE);
23203 temp = 3;
23204 fixP->fx_done = 1;
23205 }
23206
23207#ifdef OBJ_ELF
23208 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23209 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23210#endif
23211
39b41c9c 23212 arm_branch_common:
c19d1205 23213 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23214 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23215 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23216 also be be clear. */
23217 if (value & temp)
c19d1205 23218 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23219 _("misaligned branch destination"));
23220 if ((value & (offsetT)0xfe000000) != (offsetT)0
23221 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23222 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23223
2fc8bdac 23224 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23225 {
2fc8bdac
ZW
23226 newval = md_chars_to_number (buf, INSN_SIZE);
23227 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23228 /* Set the H bit on BLX instructions. */
23229 if (temp == 1)
23230 {
23231 if (value & 2)
23232 newval |= 0x01000000;
23233 else
23234 newval &= ~0x01000000;
23235 }
2fc8bdac 23236 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23237 }
c19d1205 23238 break;
a737bd4d 23239
25fe350b
MS
23240 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23241 /* CBZ can only branch forward. */
a737bd4d 23242
738755b0 23243 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23244 (which, strictly speaking, are prohibited) will be turned into
23245 no-ops.
738755b0
MS
23246
23247 FIXME: It may be better to remove the instruction completely and
23248 perform relaxation. */
23249 if (value == -2)
2fc8bdac
ZW
23250 {
23251 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23252 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23253 md_number_to_chars (buf, newval, THUMB_SIZE);
23254 }
738755b0
MS
23255 else
23256 {
23257 if (value & ~0x7e)
08f10d51 23258 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23259
477330fc 23260 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23261 {
23262 newval = md_chars_to_number (buf, THUMB_SIZE);
23263 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23264 md_number_to_chars (buf, newval, THUMB_SIZE);
23265 }
23266 }
c19d1205 23267 break;
a737bd4d 23268
c19d1205 23269 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23270 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23271 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23272
2fc8bdac
ZW
23273 if (fixP->fx_done || !seg->use_rela_p)
23274 {
23275 newval = md_chars_to_number (buf, THUMB_SIZE);
23276 newval |= (value & 0x1ff) >> 1;
23277 md_number_to_chars (buf, newval, THUMB_SIZE);
23278 }
c19d1205 23279 break;
a737bd4d 23280
c19d1205 23281 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23282 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23283 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23284
2fc8bdac
ZW
23285 if (fixP->fx_done || !seg->use_rela_p)
23286 {
23287 newval = md_chars_to_number (buf, THUMB_SIZE);
23288 newval |= (value & 0xfff) >> 1;
23289 md_number_to_chars (buf, newval, THUMB_SIZE);
23290 }
c19d1205 23291 break;
a737bd4d 23292
c19d1205 23293 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23294 if (fixP->fx_addsy
23295 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23296 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23297 && ARM_IS_FUNC (fixP->fx_addsy)
23298 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23299 {
23300 /* Force a relocation for a branch 20 bits wide. */
23301 fixP->fx_done = 0;
23302 }
08f10d51 23303 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23304 as_bad_where (fixP->fx_file, fixP->fx_line,
23305 _("conditional branch out of range"));
404ff6b5 23306
2fc8bdac
ZW
23307 if (fixP->fx_done || !seg->use_rela_p)
23308 {
23309 offsetT newval2;
23310 addressT S, J1, J2, lo, hi;
404ff6b5 23311
2fc8bdac
ZW
23312 S = (value & 0x00100000) >> 20;
23313 J2 = (value & 0x00080000) >> 19;
23314 J1 = (value & 0x00040000) >> 18;
23315 hi = (value & 0x0003f000) >> 12;
23316 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23317
2fc8bdac
ZW
23318 newval = md_chars_to_number (buf, THUMB_SIZE);
23319 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23320 newval |= (S << 10) | hi;
23321 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23322 md_number_to_chars (buf, newval, THUMB_SIZE);
23323 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23324 }
c19d1205 23325 break;
6c43fab6 23326
c19d1205 23327 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23328 /* If there is a blx from a thumb state function to
23329 another thumb function flip this to a bl and warn
23330 about it. */
23331
23332 if (fixP->fx_addsy
34e77a92 23333 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23334 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23335 && THUMB_IS_FUNC (fixP->fx_addsy))
23336 {
23337 const char *name = S_GET_NAME (fixP->fx_addsy);
23338 as_warn_where (fixP->fx_file, fixP->fx_line,
23339 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23340 name);
23341 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23342 newval = newval | 0x1000;
23343 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23344 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23345 fixP->fx_done = 1;
23346 }
23347
23348
23349 goto thumb_bl_common;
23350
c19d1205 23351 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23352 /* A bl from Thumb state ISA to an internal ARM state function
23353 is converted to a blx. */
23354 if (fixP->fx_addsy
23355 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23356 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23357 && ARM_IS_FUNC (fixP->fx_addsy)
23358 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23359 {
23360 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23361 newval = newval & ~0x1000;
23362 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23363 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23364 fixP->fx_done = 1;
23365 }
23366
23367 thumb_bl_common:
23368
2fc8bdac
ZW
23369 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23370 /* For a BLX instruction, make sure that the relocation is rounded up
23371 to a word boundary. This follows the semantics of the instruction
23372 which specifies that bit 1 of the target address will come from bit
23373 1 of the base address. */
d406f3e4
JB
23374 value = (value + 3) & ~ 3;
23375
23376#ifdef OBJ_ELF
23377 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23378 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23379 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23380#endif
404ff6b5 23381
2b2f5df9
NC
23382 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23383 {
fc289b0a 23384 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23385 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23386 else if ((value & ~0x1ffffff)
23387 && ((value & ~0x1ffffff) != ~0x1ffffff))
23388 as_bad_where (fixP->fx_file, fixP->fx_line,
23389 _("Thumb2 branch out of range"));
23390 }
4a42ebbc
RR
23391
23392 if (fixP->fx_done || !seg->use_rela_p)
23393 encode_thumb2_b_bl_offset (buf, value);
23394
c19d1205 23395 break;
404ff6b5 23396
c19d1205 23397 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23398 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23399 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23400
2fc8bdac 23401 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23402 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23403
2fc8bdac 23404 break;
a737bd4d 23405
2fc8bdac
ZW
23406 case BFD_RELOC_8:
23407 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23408 *buf = value;
c19d1205 23409 break;
a737bd4d 23410
c19d1205 23411 case BFD_RELOC_16:
2fc8bdac 23412 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23413 md_number_to_chars (buf, value, 2);
c19d1205 23414 break;
a737bd4d 23415
c19d1205 23416#ifdef OBJ_ELF
0855e32b
NS
23417 case BFD_RELOC_ARM_TLS_CALL:
23418 case BFD_RELOC_ARM_THM_TLS_CALL:
23419 case BFD_RELOC_ARM_TLS_DESCSEQ:
23420 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23421 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23422 case BFD_RELOC_ARM_TLS_GD32:
23423 case BFD_RELOC_ARM_TLS_LE32:
23424 case BFD_RELOC_ARM_TLS_IE32:
23425 case BFD_RELOC_ARM_TLS_LDM32:
23426 case BFD_RELOC_ARM_TLS_LDO32:
23427 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23428 break;
6c43fab6 23429
c19d1205
ZW
23430 case BFD_RELOC_ARM_GOT32:
23431 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23432 break;
b43420e6
NC
23433
23434 case BFD_RELOC_ARM_GOT_PREL:
23435 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23436 md_number_to_chars (buf, value, 4);
b43420e6
NC
23437 break;
23438
9a6f4e97
NS
23439 case BFD_RELOC_ARM_TARGET2:
23440 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23441 addend here for REL targets, because it won't be written out
23442 during reloc processing later. */
9a6f4e97
NS
23443 if (fixP->fx_done || !seg->use_rela_p)
23444 md_number_to_chars (buf, fixP->fx_offset, 4);
23445 break;
c19d1205 23446#endif
6c43fab6 23447
c19d1205
ZW
23448 case BFD_RELOC_RVA:
23449 case BFD_RELOC_32:
23450 case BFD_RELOC_ARM_TARGET1:
23451 case BFD_RELOC_ARM_ROSEGREL32:
23452 case BFD_RELOC_ARM_SBREL32:
23453 case BFD_RELOC_32_PCREL:
f0927246
NC
23454#ifdef TE_PE
23455 case BFD_RELOC_32_SECREL:
23456#endif
2fc8bdac 23457 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23458#ifdef TE_WINCE
23459 /* For WinCE we only do this for pcrel fixups. */
23460 if (fixP->fx_done || fixP->fx_pcrel)
23461#endif
23462 md_number_to_chars (buf, value, 4);
c19d1205 23463 break;
6c43fab6 23464
c19d1205
ZW
23465#ifdef OBJ_ELF
23466 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23467 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23468 {
23469 newval = md_chars_to_number (buf, 4) & 0x80000000;
23470 if ((value ^ (value >> 1)) & 0x40000000)
23471 {
23472 as_bad_where (fixP->fx_file, fixP->fx_line,
23473 _("rel31 relocation overflow"));
23474 }
23475 newval |= value & 0x7fffffff;
23476 md_number_to_chars (buf, newval, 4);
23477 }
23478 break;
c19d1205 23479#endif
a737bd4d 23480
c19d1205 23481 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23482 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23483 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23484 newval = md_chars_to_number (buf, INSN_SIZE);
23485 else
23486 newval = get_thumb32_insn (buf);
23487 if ((newval & 0x0f200f00) == 0x0d000900)
23488 {
23489 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23490 has permitted values that are multiples of 2, in the range 0
23491 to 510. */
23492 if (value < -510 || value > 510 || (value & 1))
23493 as_bad_where (fixP->fx_file, fixP->fx_line,
23494 _("co-processor offset out of range"));
23495 }
23496 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23497 as_bad_where (fixP->fx_file, fixP->fx_line,
23498 _("co-processor offset out of range"));
23499 cp_off_common:
26d97720 23500 sign = value > 0;
c19d1205
ZW
23501 if (value < 0)
23502 value = -value;
8f06b2d8
PB
23503 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23504 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23505 newval = md_chars_to_number (buf, INSN_SIZE);
23506 else
23507 newval = get_thumb32_insn (buf);
26d97720
NS
23508 if (value == 0)
23509 newval &= 0xffffff00;
23510 else
23511 {
23512 newval &= 0xff7fff00;
9db2f6b4
RL
23513 if ((newval & 0x0f200f00) == 0x0d000900)
23514 {
23515 /* This is a fp16 vstr/vldr.
23516
23517 It requires the immediate offset in the instruction is shifted
23518 left by 1 to be a half-word offset.
23519
23520 Here, left shift by 1 first, and later right shift by 2
23521 should get the right offset. */
23522 value <<= 1;
23523 }
26d97720
NS
23524 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23525 }
8f06b2d8
PB
23526 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23527 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23528 md_number_to_chars (buf, newval, INSN_SIZE);
23529 else
23530 put_thumb32_insn (buf, newval);
c19d1205 23531 break;
a737bd4d 23532
c19d1205 23533 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23534 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23535 if (value < -255 || value > 255)
23536 as_bad_where (fixP->fx_file, fixP->fx_line,
23537 _("co-processor offset out of range"));
df7849c5 23538 value *= 4;
c19d1205 23539 goto cp_off_common;
6c43fab6 23540
c19d1205
ZW
23541 case BFD_RELOC_ARM_THUMB_OFFSET:
23542 newval = md_chars_to_number (buf, THUMB_SIZE);
23543 /* Exactly what ranges, and where the offset is inserted depends
23544 on the type of instruction, we can establish this from the
23545 top 4 bits. */
23546 switch (newval >> 12)
23547 {
23548 case 4: /* PC load. */
23549 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23550 forced to zero for these loads; md_pcrel_from has already
23551 compensated for this. */
23552 if (value & 3)
23553 as_bad_where (fixP->fx_file, fixP->fx_line,
23554 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23555 (((unsigned long) fixP->fx_frag->fr_address
23556 + (unsigned long) fixP->fx_where) & ~3)
23557 + (unsigned long) value);
a737bd4d 23558
c19d1205
ZW
23559 if (value & ~0x3fc)
23560 as_bad_where (fixP->fx_file, fixP->fx_line,
23561 _("invalid offset, value too big (0x%08lX)"),
23562 (long) value);
a737bd4d 23563
c19d1205
ZW
23564 newval |= value >> 2;
23565 break;
a737bd4d 23566
c19d1205
ZW
23567 case 9: /* SP load/store. */
23568 if (value & ~0x3fc)
23569 as_bad_where (fixP->fx_file, fixP->fx_line,
23570 _("invalid offset, value too big (0x%08lX)"),
23571 (long) value);
23572 newval |= value >> 2;
23573 break;
6c43fab6 23574
c19d1205
ZW
23575 case 6: /* Word load/store. */
23576 if (value & ~0x7c)
23577 as_bad_where (fixP->fx_file, fixP->fx_line,
23578 _("invalid offset, value too big (0x%08lX)"),
23579 (long) value);
23580 newval |= value << 4; /* 6 - 2. */
23581 break;
a737bd4d 23582
c19d1205
ZW
23583 case 7: /* Byte load/store. */
23584 if (value & ~0x1f)
23585 as_bad_where (fixP->fx_file, fixP->fx_line,
23586 _("invalid offset, value too big (0x%08lX)"),
23587 (long) value);
23588 newval |= value << 6;
23589 break;
a737bd4d 23590
c19d1205
ZW
23591 case 8: /* Halfword load/store. */
23592 if (value & ~0x3e)
23593 as_bad_where (fixP->fx_file, fixP->fx_line,
23594 _("invalid offset, value too big (0x%08lX)"),
23595 (long) value);
23596 newval |= value << 5; /* 6 - 1. */
23597 break;
a737bd4d 23598
c19d1205
ZW
23599 default:
23600 as_bad_where (fixP->fx_file, fixP->fx_line,
23601 "Unable to process relocation for thumb opcode: %lx",
23602 (unsigned long) newval);
23603 break;
23604 }
23605 md_number_to_chars (buf, newval, THUMB_SIZE);
23606 break;
a737bd4d 23607
c19d1205
ZW
23608 case BFD_RELOC_ARM_THUMB_ADD:
23609 /* This is a complicated relocation, since we use it for all of
23610 the following immediate relocations:
a737bd4d 23611
c19d1205
ZW
23612 3bit ADD/SUB
23613 8bit ADD/SUB
23614 9bit ADD/SUB SP word-aligned
23615 10bit ADD PC/SP word-aligned
a737bd4d 23616
c19d1205
ZW
23617 The type of instruction being processed is encoded in the
23618 instruction field:
a737bd4d 23619
c19d1205
ZW
23620 0x8000 SUB
23621 0x00F0 Rd
23622 0x000F Rs
23623 */
23624 newval = md_chars_to_number (buf, THUMB_SIZE);
23625 {
23626 int rd = (newval >> 4) & 0xf;
23627 int rs = newval & 0xf;
23628 int subtract = !!(newval & 0x8000);
a737bd4d 23629
c19d1205
ZW
23630 /* Check for HI regs, only very restricted cases allowed:
23631 Adjusting SP, and using PC or SP to get an address. */
23632 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23633 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23634 as_bad_where (fixP->fx_file, fixP->fx_line,
23635 _("invalid Hi register with immediate"));
a737bd4d 23636
c19d1205
ZW
23637 /* If value is negative, choose the opposite instruction. */
23638 if (value < 0)
23639 {
23640 value = -value;
23641 subtract = !subtract;
23642 if (value < 0)
23643 as_bad_where (fixP->fx_file, fixP->fx_line,
23644 _("immediate value out of range"));
23645 }
a737bd4d 23646
c19d1205
ZW
23647 if (rd == REG_SP)
23648 {
75c11999 23649 if (value & ~0x1fc)
c19d1205
ZW
23650 as_bad_where (fixP->fx_file, fixP->fx_line,
23651 _("invalid immediate for stack address calculation"));
23652 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23653 newval |= value >> 2;
23654 }
23655 else if (rs == REG_PC || rs == REG_SP)
23656 {
c12d2c9d
NC
23657 /* PR gas/18541. If the addition is for a defined symbol
23658 within range of an ADR instruction then accept it. */
23659 if (subtract
23660 && value == 4
23661 && fixP->fx_addsy != NULL)
23662 {
23663 subtract = 0;
23664
23665 if (! S_IS_DEFINED (fixP->fx_addsy)
23666 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23667 || S_IS_WEAK (fixP->fx_addsy))
23668 {
23669 as_bad_where (fixP->fx_file, fixP->fx_line,
23670 _("address calculation needs a strongly defined nearby symbol"));
23671 }
23672 else
23673 {
23674 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23675
23676 /* Round up to the next 4-byte boundary. */
23677 if (v & 3)
23678 v = (v + 3) & ~ 3;
23679 else
23680 v += 4;
23681 v = S_GET_VALUE (fixP->fx_addsy) - v;
23682
23683 if (v & ~0x3fc)
23684 {
23685 as_bad_where (fixP->fx_file, fixP->fx_line,
23686 _("symbol too far away"));
23687 }
23688 else
23689 {
23690 fixP->fx_done = 1;
23691 value = v;
23692 }
23693 }
23694 }
23695
c19d1205
ZW
23696 if (subtract || value & ~0x3fc)
23697 as_bad_where (fixP->fx_file, fixP->fx_line,
23698 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23699 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23700 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23701 newval |= rd << 8;
23702 newval |= value >> 2;
23703 }
23704 else if (rs == rd)
23705 {
23706 if (value & ~0xff)
23707 as_bad_where (fixP->fx_file, fixP->fx_line,
23708 _("immediate value out of range"));
23709 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23710 newval |= (rd << 8) | value;
23711 }
23712 else
23713 {
23714 if (value & ~0x7)
23715 as_bad_where (fixP->fx_file, fixP->fx_line,
23716 _("immediate value out of range"));
23717 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23718 newval |= rd | (rs << 3) | (value << 6);
23719 }
23720 }
23721 md_number_to_chars (buf, newval, THUMB_SIZE);
23722 break;
a737bd4d 23723
c19d1205
ZW
23724 case BFD_RELOC_ARM_THUMB_IMM:
23725 newval = md_chars_to_number (buf, THUMB_SIZE);
23726 if (value < 0 || value > 255)
23727 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23728 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23729 (long) value);
23730 newval |= value;
23731 md_number_to_chars (buf, newval, THUMB_SIZE);
23732 break;
a737bd4d 23733
c19d1205
ZW
23734 case BFD_RELOC_ARM_THUMB_SHIFT:
23735 /* 5bit shift value (0..32). LSL cannot take 32. */
23736 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23737 temp = newval & 0xf800;
23738 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23739 as_bad_where (fixP->fx_file, fixP->fx_line,
23740 _("invalid shift value: %ld"), (long) value);
23741 /* Shifts of zero must be encoded as LSL. */
23742 if (value == 0)
23743 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23744 /* Shifts of 32 are encoded as zero. */
23745 else if (value == 32)
23746 value = 0;
23747 newval |= value << 6;
23748 md_number_to_chars (buf, newval, THUMB_SIZE);
23749 break;
a737bd4d 23750
c19d1205
ZW
23751 case BFD_RELOC_VTABLE_INHERIT:
23752 case BFD_RELOC_VTABLE_ENTRY:
23753 fixP->fx_done = 0;
23754 return;
6c43fab6 23755
b6895b4f
PB
23756 case BFD_RELOC_ARM_MOVW:
23757 case BFD_RELOC_ARM_MOVT:
23758 case BFD_RELOC_ARM_THUMB_MOVW:
23759 case BFD_RELOC_ARM_THUMB_MOVT:
23760 if (fixP->fx_done || !seg->use_rela_p)
23761 {
23762 /* REL format relocations are limited to a 16-bit addend. */
23763 if (!fixP->fx_done)
23764 {
39623e12 23765 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23766 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23767 _("offset out of range"));
b6895b4f
PB
23768 }
23769 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23770 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23771 {
23772 value >>= 16;
23773 }
23774
23775 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23776 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23777 {
23778 newval = get_thumb32_insn (buf);
23779 newval &= 0xfbf08f00;
23780 newval |= (value & 0xf000) << 4;
23781 newval |= (value & 0x0800) << 15;
23782 newval |= (value & 0x0700) << 4;
23783 newval |= (value & 0x00ff);
23784 put_thumb32_insn (buf, newval);
23785 }
23786 else
23787 {
23788 newval = md_chars_to_number (buf, 4);
23789 newval &= 0xfff0f000;
23790 newval |= value & 0x0fff;
23791 newval |= (value & 0xf000) << 4;
23792 md_number_to_chars (buf, newval, 4);
23793 }
23794 }
23795 return;
23796
72d98d16
MG
23797 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23798 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23799 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23800 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23801 gas_assert (!fixP->fx_done);
23802 {
23803 bfd_vma insn;
23804 bfd_boolean is_mov;
23805 bfd_vma encoded_addend = value;
23806
23807 /* Check that addend can be encoded in instruction. */
23808 if (!seg->use_rela_p && (value < 0 || value > 255))
23809 as_bad_where (fixP->fx_file, fixP->fx_line,
23810 _("the offset 0x%08lX is not representable"),
23811 (unsigned long) encoded_addend);
23812
23813 /* Extract the instruction. */
23814 insn = md_chars_to_number (buf, THUMB_SIZE);
23815 is_mov = (insn & 0xf800) == 0x2000;
23816
23817 /* Encode insn. */
23818 if (is_mov)
23819 {
23820 if (!seg->use_rela_p)
23821 insn |= encoded_addend;
23822 }
23823 else
23824 {
23825 int rd, rs;
23826
23827 /* Extract the instruction. */
23828 /* Encoding is the following
23829 0x8000 SUB
23830 0x00F0 Rd
23831 0x000F Rs
23832 */
23833 /* The following conditions must be true :
23834 - ADD
23835 - Rd == Rs
23836 - Rd <= 7
23837 */
23838 rd = (insn >> 4) & 0xf;
23839 rs = insn & 0xf;
23840 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23841 as_bad_where (fixP->fx_file, fixP->fx_line,
23842 _("Unable to process relocation for thumb opcode: %lx"),
23843 (unsigned long) insn);
23844
23845 /* Encode as ADD immediate8 thumb 1 code. */
23846 insn = 0x3000 | (rd << 8);
23847
23848 /* Place the encoded addend into the first 8 bits of the
23849 instruction. */
23850 if (!seg->use_rela_p)
23851 insn |= encoded_addend;
23852 }
23853
23854 /* Update the instruction. */
23855 md_number_to_chars (buf, insn, THUMB_SIZE);
23856 }
23857 break;
23858
4962c51a
MS
23859 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23860 case BFD_RELOC_ARM_ALU_PC_G0:
23861 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23862 case BFD_RELOC_ARM_ALU_PC_G1:
23863 case BFD_RELOC_ARM_ALU_PC_G2:
23864 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23865 case BFD_RELOC_ARM_ALU_SB_G0:
23866 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23867 case BFD_RELOC_ARM_ALU_SB_G1:
23868 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23869 gas_assert (!fixP->fx_done);
4962c51a
MS
23870 if (!seg->use_rela_p)
23871 {
477330fc
RM
23872 bfd_vma insn;
23873 bfd_vma encoded_addend;
23874 bfd_vma addend_abs = abs (value);
23875
23876 /* Check that the absolute value of the addend can be
23877 expressed as an 8-bit constant plus a rotation. */
23878 encoded_addend = encode_arm_immediate (addend_abs);
23879 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23880 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23881 _("the offset 0x%08lX is not representable"),
23882 (unsigned long) addend_abs);
23883
23884 /* Extract the instruction. */
23885 insn = md_chars_to_number (buf, INSN_SIZE);
23886
23887 /* If the addend is positive, use an ADD instruction.
23888 Otherwise use a SUB. Take care not to destroy the S bit. */
23889 insn &= 0xff1fffff;
23890 if (value < 0)
23891 insn |= 1 << 22;
23892 else
23893 insn |= 1 << 23;
23894
23895 /* Place the encoded addend into the first 12 bits of the
23896 instruction. */
23897 insn &= 0xfffff000;
23898 insn |= encoded_addend;
23899
23900 /* Update the instruction. */
23901 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23902 }
23903 break;
23904
23905 case BFD_RELOC_ARM_LDR_PC_G0:
23906 case BFD_RELOC_ARM_LDR_PC_G1:
23907 case BFD_RELOC_ARM_LDR_PC_G2:
23908 case BFD_RELOC_ARM_LDR_SB_G0:
23909 case BFD_RELOC_ARM_LDR_SB_G1:
23910 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23911 gas_assert (!fixP->fx_done);
4962c51a 23912 if (!seg->use_rela_p)
477330fc
RM
23913 {
23914 bfd_vma insn;
23915 bfd_vma addend_abs = abs (value);
4962c51a 23916
477330fc
RM
23917 /* Check that the absolute value of the addend can be
23918 encoded in 12 bits. */
23919 if (addend_abs >= 0x1000)
4962c51a 23920 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23921 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23922 (unsigned long) addend_abs);
23923
23924 /* Extract the instruction. */
23925 insn = md_chars_to_number (buf, INSN_SIZE);
23926
23927 /* If the addend is negative, clear bit 23 of the instruction.
23928 Otherwise set it. */
23929 if (value < 0)
23930 insn &= ~(1 << 23);
23931 else
23932 insn |= 1 << 23;
23933
23934 /* Place the absolute value of the addend into the first 12 bits
23935 of the instruction. */
23936 insn &= 0xfffff000;
23937 insn |= addend_abs;
23938
23939 /* Update the instruction. */
23940 md_number_to_chars (buf, insn, INSN_SIZE);
23941 }
4962c51a
MS
23942 break;
23943
23944 case BFD_RELOC_ARM_LDRS_PC_G0:
23945 case BFD_RELOC_ARM_LDRS_PC_G1:
23946 case BFD_RELOC_ARM_LDRS_PC_G2:
23947 case BFD_RELOC_ARM_LDRS_SB_G0:
23948 case BFD_RELOC_ARM_LDRS_SB_G1:
23949 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23950 gas_assert (!fixP->fx_done);
4962c51a 23951 if (!seg->use_rela_p)
477330fc
RM
23952 {
23953 bfd_vma insn;
23954 bfd_vma addend_abs = abs (value);
4962c51a 23955
477330fc
RM
23956 /* Check that the absolute value of the addend can be
23957 encoded in 8 bits. */
23958 if (addend_abs >= 0x100)
4962c51a 23959 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23960 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23961 (unsigned long) addend_abs);
23962
23963 /* Extract the instruction. */
23964 insn = md_chars_to_number (buf, INSN_SIZE);
23965
23966 /* If the addend is negative, clear bit 23 of the instruction.
23967 Otherwise set it. */
23968 if (value < 0)
23969 insn &= ~(1 << 23);
23970 else
23971 insn |= 1 << 23;
23972
23973 /* Place the first four bits of the absolute value of the addend
23974 into the first 4 bits of the instruction, and the remaining
23975 four into bits 8 .. 11. */
23976 insn &= 0xfffff0f0;
23977 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23978
23979 /* Update the instruction. */
23980 md_number_to_chars (buf, insn, INSN_SIZE);
23981 }
4962c51a
MS
23982 break;
23983
23984 case BFD_RELOC_ARM_LDC_PC_G0:
23985 case BFD_RELOC_ARM_LDC_PC_G1:
23986 case BFD_RELOC_ARM_LDC_PC_G2:
23987 case BFD_RELOC_ARM_LDC_SB_G0:
23988 case BFD_RELOC_ARM_LDC_SB_G1:
23989 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23990 gas_assert (!fixP->fx_done);
4962c51a 23991 if (!seg->use_rela_p)
477330fc
RM
23992 {
23993 bfd_vma insn;
23994 bfd_vma addend_abs = abs (value);
4962c51a 23995
477330fc
RM
23996 /* Check that the absolute value of the addend is a multiple of
23997 four and, when divided by four, fits in 8 bits. */
23998 if (addend_abs & 0x3)
4962c51a 23999 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24000 _("bad offset 0x%08lX (must be word-aligned)"),
24001 (unsigned long) addend_abs);
4962c51a 24002
477330fc 24003 if ((addend_abs >> 2) > 0xff)
4962c51a 24004 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24005 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24006 (unsigned long) addend_abs);
24007
24008 /* Extract the instruction. */
24009 insn = md_chars_to_number (buf, INSN_SIZE);
24010
24011 /* If the addend is negative, clear bit 23 of the instruction.
24012 Otherwise set it. */
24013 if (value < 0)
24014 insn &= ~(1 << 23);
24015 else
24016 insn |= 1 << 23;
24017
24018 /* Place the addend (divided by four) into the first eight
24019 bits of the instruction. */
24020 insn &= 0xfffffff0;
24021 insn |= addend_abs >> 2;
24022
24023 /* Update the instruction. */
24024 md_number_to_chars (buf, insn, INSN_SIZE);
24025 }
4962c51a
MS
24026 break;
24027
845b51d6
PB
24028 case BFD_RELOC_ARM_V4BX:
24029 /* This will need to go in the object file. */
24030 fixP->fx_done = 0;
24031 break;
24032
c19d1205
ZW
24033 case BFD_RELOC_UNUSED:
24034 default:
24035 as_bad_where (fixP->fx_file, fixP->fx_line,
24036 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24037 }
6c43fab6
RE
24038}
24039
c19d1205
ZW
24040/* Translate internal representation of relocation info to BFD target
24041 format. */
a737bd4d 24042
c19d1205 24043arelent *
00a97672 24044tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24045{
c19d1205
ZW
24046 arelent * reloc;
24047 bfd_reloc_code_real_type code;
a737bd4d 24048
325801bd 24049 reloc = XNEW (arelent);
a737bd4d 24050
325801bd 24051 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24052 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24053 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24054
2fc8bdac 24055 if (fixp->fx_pcrel)
00a97672
RS
24056 {
24057 if (section->use_rela_p)
24058 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24059 else
24060 fixp->fx_offset = reloc->address;
24061 }
c19d1205 24062 reloc->addend = fixp->fx_offset;
a737bd4d 24063
c19d1205 24064 switch (fixp->fx_r_type)
a737bd4d 24065 {
c19d1205
ZW
24066 case BFD_RELOC_8:
24067 if (fixp->fx_pcrel)
24068 {
24069 code = BFD_RELOC_8_PCREL;
24070 break;
24071 }
a737bd4d 24072
c19d1205
ZW
24073 case BFD_RELOC_16:
24074 if (fixp->fx_pcrel)
24075 {
24076 code = BFD_RELOC_16_PCREL;
24077 break;
24078 }
6c43fab6 24079
c19d1205
ZW
24080 case BFD_RELOC_32:
24081 if (fixp->fx_pcrel)
24082 {
24083 code = BFD_RELOC_32_PCREL;
24084 break;
24085 }
a737bd4d 24086
b6895b4f
PB
24087 case BFD_RELOC_ARM_MOVW:
24088 if (fixp->fx_pcrel)
24089 {
24090 code = BFD_RELOC_ARM_MOVW_PCREL;
24091 break;
24092 }
24093
24094 case BFD_RELOC_ARM_MOVT:
24095 if (fixp->fx_pcrel)
24096 {
24097 code = BFD_RELOC_ARM_MOVT_PCREL;
24098 break;
24099 }
24100
24101 case BFD_RELOC_ARM_THUMB_MOVW:
24102 if (fixp->fx_pcrel)
24103 {
24104 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24105 break;
24106 }
24107
24108 case BFD_RELOC_ARM_THUMB_MOVT:
24109 if (fixp->fx_pcrel)
24110 {
24111 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24112 break;
24113 }
24114
c19d1205
ZW
24115 case BFD_RELOC_NONE:
24116 case BFD_RELOC_ARM_PCREL_BRANCH:
24117 case BFD_RELOC_ARM_PCREL_BLX:
24118 case BFD_RELOC_RVA:
24119 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24120 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24121 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24122 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24123 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24124 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24125 case BFD_RELOC_VTABLE_ENTRY:
24126 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24127#ifdef TE_PE
24128 case BFD_RELOC_32_SECREL:
24129#endif
c19d1205
ZW
24130 code = fixp->fx_r_type;
24131 break;
a737bd4d 24132
00adf2d4
JB
24133 case BFD_RELOC_THUMB_PCREL_BLX:
24134#ifdef OBJ_ELF
24135 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24136 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24137 else
24138#endif
24139 code = BFD_RELOC_THUMB_PCREL_BLX;
24140 break;
24141
c19d1205
ZW
24142 case BFD_RELOC_ARM_LITERAL:
24143 case BFD_RELOC_ARM_HWLITERAL:
24144 /* If this is called then the a literal has
24145 been referenced across a section boundary. */
24146 as_bad_where (fixp->fx_file, fixp->fx_line,
24147 _("literal referenced across section boundary"));
24148 return NULL;
a737bd4d 24149
c19d1205 24150#ifdef OBJ_ELF
0855e32b
NS
24151 case BFD_RELOC_ARM_TLS_CALL:
24152 case BFD_RELOC_ARM_THM_TLS_CALL:
24153 case BFD_RELOC_ARM_TLS_DESCSEQ:
24154 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24155 case BFD_RELOC_ARM_GOT32:
24156 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24157 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24158 case BFD_RELOC_ARM_PLT32:
24159 case BFD_RELOC_ARM_TARGET1:
24160 case BFD_RELOC_ARM_ROSEGREL32:
24161 case BFD_RELOC_ARM_SBREL32:
24162 case BFD_RELOC_ARM_PREL31:
24163 case BFD_RELOC_ARM_TARGET2:
c19d1205 24164 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24165 case BFD_RELOC_ARM_PCREL_CALL:
24166 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24167 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24168 case BFD_RELOC_ARM_ALU_PC_G0:
24169 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24170 case BFD_RELOC_ARM_ALU_PC_G1:
24171 case BFD_RELOC_ARM_ALU_PC_G2:
24172 case BFD_RELOC_ARM_LDR_PC_G0:
24173 case BFD_RELOC_ARM_LDR_PC_G1:
24174 case BFD_RELOC_ARM_LDR_PC_G2:
24175 case BFD_RELOC_ARM_LDRS_PC_G0:
24176 case BFD_RELOC_ARM_LDRS_PC_G1:
24177 case BFD_RELOC_ARM_LDRS_PC_G2:
24178 case BFD_RELOC_ARM_LDC_PC_G0:
24179 case BFD_RELOC_ARM_LDC_PC_G1:
24180 case BFD_RELOC_ARM_LDC_PC_G2:
24181 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24182 case BFD_RELOC_ARM_ALU_SB_G0:
24183 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24184 case BFD_RELOC_ARM_ALU_SB_G1:
24185 case BFD_RELOC_ARM_ALU_SB_G2:
24186 case BFD_RELOC_ARM_LDR_SB_G0:
24187 case BFD_RELOC_ARM_LDR_SB_G1:
24188 case BFD_RELOC_ARM_LDR_SB_G2:
24189 case BFD_RELOC_ARM_LDRS_SB_G0:
24190 case BFD_RELOC_ARM_LDRS_SB_G1:
24191 case BFD_RELOC_ARM_LDRS_SB_G2:
24192 case BFD_RELOC_ARM_LDC_SB_G0:
24193 case BFD_RELOC_ARM_LDC_SB_G1:
24194 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24195 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24196 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24197 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24198 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24199 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24200 code = fixp->fx_r_type;
24201 break;
a737bd4d 24202
0855e32b 24203 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24204 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24205 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24206 case BFD_RELOC_ARM_TLS_IE32:
24207 case BFD_RELOC_ARM_TLS_LDM32:
24208 /* BFD will include the symbol's address in the addend.
24209 But we don't want that, so subtract it out again here. */
24210 if (!S_IS_COMMON (fixp->fx_addsy))
24211 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24212 code = fixp->fx_r_type;
24213 break;
24214#endif
a737bd4d 24215
c19d1205
ZW
24216 case BFD_RELOC_ARM_IMMEDIATE:
24217 as_bad_where (fixp->fx_file, fixp->fx_line,
24218 _("internal relocation (type: IMMEDIATE) not fixed up"));
24219 return NULL;
a737bd4d 24220
c19d1205
ZW
24221 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24222 as_bad_where (fixp->fx_file, fixp->fx_line,
24223 _("ADRL used for a symbol not defined in the same file"));
24224 return NULL;
a737bd4d 24225
c19d1205 24226 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24227 if (section->use_rela_p)
24228 {
24229 code = fixp->fx_r_type;
24230 break;
24231 }
24232
c19d1205
ZW
24233 if (fixp->fx_addsy != NULL
24234 && !S_IS_DEFINED (fixp->fx_addsy)
24235 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24236 {
c19d1205
ZW
24237 as_bad_where (fixp->fx_file, fixp->fx_line,
24238 _("undefined local label `%s'"),
24239 S_GET_NAME (fixp->fx_addsy));
24240 return NULL;
a737bd4d
NC
24241 }
24242
c19d1205
ZW
24243 as_bad_where (fixp->fx_file, fixp->fx_line,
24244 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24245 return NULL;
a737bd4d 24246
c19d1205
ZW
24247 default:
24248 {
e0471c16 24249 const char * type;
6c43fab6 24250
c19d1205
ZW
24251 switch (fixp->fx_r_type)
24252 {
24253 case BFD_RELOC_NONE: type = "NONE"; break;
24254 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24255 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24256 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24257 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24258 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24259 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24260 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24261 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24262 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24263 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24264 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24265 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24266 default: type = _("<unknown>"); break;
24267 }
24268 as_bad_where (fixp->fx_file, fixp->fx_line,
24269 _("cannot represent %s relocation in this object file format"),
24270 type);
24271 return NULL;
24272 }
a737bd4d 24273 }
6c43fab6 24274
c19d1205
ZW
24275#ifdef OBJ_ELF
24276 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24277 && GOT_symbol
24278 && fixp->fx_addsy == GOT_symbol)
24279 {
24280 code = BFD_RELOC_ARM_GOTPC;
24281 reloc->addend = fixp->fx_offset = reloc->address;
24282 }
24283#endif
6c43fab6 24284
c19d1205 24285 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24286
c19d1205
ZW
24287 if (reloc->howto == NULL)
24288 {
24289 as_bad_where (fixp->fx_file, fixp->fx_line,
24290 _("cannot represent %s relocation in this object file format"),
24291 bfd_get_reloc_code_name (code));
24292 return NULL;
24293 }
6c43fab6 24294
c19d1205
ZW
24295 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24296 vtable entry to be used in the relocation's section offset. */
24297 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24298 reloc->address = fixp->fx_offset;
6c43fab6 24299
c19d1205 24300 return reloc;
6c43fab6
RE
24301}
24302
c19d1205 24303/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24304
c19d1205
ZW
24305void
24306cons_fix_new_arm (fragS * frag,
24307 int where,
24308 int size,
62ebcb5c
AM
24309 expressionS * exp,
24310 bfd_reloc_code_real_type reloc)
6c43fab6 24311{
c19d1205 24312 int pcrel = 0;
6c43fab6 24313
c19d1205
ZW
24314 /* Pick a reloc.
24315 FIXME: @@ Should look at CPU word size. */
24316 switch (size)
24317 {
24318 case 1:
62ebcb5c 24319 reloc = BFD_RELOC_8;
c19d1205
ZW
24320 break;
24321 case 2:
62ebcb5c 24322 reloc = BFD_RELOC_16;
c19d1205
ZW
24323 break;
24324 case 4:
24325 default:
62ebcb5c 24326 reloc = BFD_RELOC_32;
c19d1205
ZW
24327 break;
24328 case 8:
62ebcb5c 24329 reloc = BFD_RELOC_64;
c19d1205
ZW
24330 break;
24331 }
6c43fab6 24332
f0927246
NC
24333#ifdef TE_PE
24334 if (exp->X_op == O_secrel)
24335 {
24336 exp->X_op = O_symbol;
62ebcb5c 24337 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24338 }
24339#endif
24340
62ebcb5c 24341 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24342}
6c43fab6 24343
4343666d 24344#if defined (OBJ_COFF)
c19d1205
ZW
24345void
24346arm_validate_fix (fixS * fixP)
6c43fab6 24347{
c19d1205
ZW
24348 /* If the destination of the branch is a defined symbol which does not have
24349 the THUMB_FUNC attribute, then we must be calling a function which has
24350 the (interfacearm) attribute. We look for the Thumb entry point to that
24351 function and change the branch to refer to that function instead. */
24352 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24353 && fixP->fx_addsy != NULL
24354 && S_IS_DEFINED (fixP->fx_addsy)
24355 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24356 {
c19d1205 24357 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24358 }
c19d1205
ZW
24359}
24360#endif
6c43fab6 24361
267bf995 24362
c19d1205
ZW
24363int
24364arm_force_relocation (struct fix * fixp)
24365{
24366#if defined (OBJ_COFF) && defined (TE_PE)
24367 if (fixp->fx_r_type == BFD_RELOC_RVA)
24368 return 1;
24369#endif
6c43fab6 24370
267bf995
RR
24371 /* In case we have a call or a branch to a function in ARM ISA mode from
24372 a thumb function or vice-versa force the relocation. These relocations
24373 are cleared off for some cores that might have blx and simple transformations
24374 are possible. */
24375
24376#ifdef OBJ_ELF
24377 switch (fixp->fx_r_type)
24378 {
24379 case BFD_RELOC_ARM_PCREL_JUMP:
24380 case BFD_RELOC_ARM_PCREL_CALL:
24381 case BFD_RELOC_THUMB_PCREL_BLX:
24382 if (THUMB_IS_FUNC (fixp->fx_addsy))
24383 return 1;
24384 break;
24385
24386 case BFD_RELOC_ARM_PCREL_BLX:
24387 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24388 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24389 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24390 if (ARM_IS_FUNC (fixp->fx_addsy))
24391 return 1;
24392 break;
24393
24394 default:
24395 break;
24396 }
24397#endif
24398
b5884301
PB
24399 /* Resolve these relocations even if the symbol is extern or weak.
24400 Technically this is probably wrong due to symbol preemption.
24401 In practice these relocations do not have enough range to be useful
24402 at dynamic link time, and some code (e.g. in the Linux kernel)
24403 expects these references to be resolved. */
c19d1205
ZW
24404 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24405 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24406 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24407 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24408 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24409 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24410 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24411 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24412 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24413 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24414 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24415 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24416 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24417 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24418 return 0;
a737bd4d 24419
4962c51a
MS
24420 /* Always leave these relocations for the linker. */
24421 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24422 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24423 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24424 return 1;
24425
f0291e4c
PB
24426 /* Always generate relocations against function symbols. */
24427 if (fixp->fx_r_type == BFD_RELOC_32
24428 && fixp->fx_addsy
24429 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24430 return 1;
24431
c19d1205 24432 return generic_force_reloc (fixp);
404ff6b5
AH
24433}
24434
0ffdc86c 24435#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24436/* Relocations against function names must be left unadjusted,
24437 so that the linker can use this information to generate interworking
24438 stubs. The MIPS version of this function
c19d1205
ZW
24439 also prevents relocations that are mips-16 specific, but I do not
24440 know why it does this.
404ff6b5 24441
c19d1205
ZW
24442 FIXME:
24443 There is one other problem that ought to be addressed here, but
24444 which currently is not: Taking the address of a label (rather
24445 than a function) and then later jumping to that address. Such
24446 addresses also ought to have their bottom bit set (assuming that
24447 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24448
c19d1205
ZW
24449bfd_boolean
24450arm_fix_adjustable (fixS * fixP)
404ff6b5 24451{
c19d1205
ZW
24452 if (fixP->fx_addsy == NULL)
24453 return 1;
404ff6b5 24454
e28387c3
PB
24455 /* Preserve relocations against symbols with function type. */
24456 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24457 return FALSE;
e28387c3 24458
c19d1205
ZW
24459 if (THUMB_IS_FUNC (fixP->fx_addsy)
24460 && fixP->fx_subsy == NULL)
c921be7d 24461 return FALSE;
a737bd4d 24462
c19d1205
ZW
24463 /* We need the symbol name for the VTABLE entries. */
24464 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24465 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24466 return FALSE;
404ff6b5 24467
c19d1205
ZW
24468 /* Don't allow symbols to be discarded on GOT related relocs. */
24469 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24470 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24471 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24472 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24473 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24474 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24475 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24476 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24477 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24478 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24479 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24480 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24481 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24482 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24483 return FALSE;
a737bd4d 24484
4962c51a
MS
24485 /* Similarly for group relocations. */
24486 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24487 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24488 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24489 return FALSE;
4962c51a 24490
79947c54
CD
24491 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24492 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24493 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24494 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24495 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24496 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24497 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24498 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24499 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24500 return FALSE;
79947c54 24501
72d98d16
MG
24502 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24503 offsets, so keep these symbols. */
24504 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24505 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24506 return FALSE;
24507
c921be7d 24508 return TRUE;
a737bd4d 24509}
0ffdc86c
NC
24510#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24511
24512#ifdef OBJ_ELF
c19d1205
ZW
24513const char *
24514elf32_arm_target_format (void)
404ff6b5 24515{
c19d1205
ZW
24516#ifdef TE_SYMBIAN
24517 return (target_big_endian
24518 ? "elf32-bigarm-symbian"
24519 : "elf32-littlearm-symbian");
24520#elif defined (TE_VXWORKS)
24521 return (target_big_endian
24522 ? "elf32-bigarm-vxworks"
24523 : "elf32-littlearm-vxworks");
b38cadfb
NC
24524#elif defined (TE_NACL)
24525 return (target_big_endian
24526 ? "elf32-bigarm-nacl"
24527 : "elf32-littlearm-nacl");
c19d1205
ZW
24528#else
24529 if (target_big_endian)
24530 return "elf32-bigarm";
24531 else
24532 return "elf32-littlearm";
24533#endif
404ff6b5
AH
24534}
24535
c19d1205
ZW
24536void
24537armelf_frob_symbol (symbolS * symp,
24538 int * puntp)
404ff6b5 24539{
c19d1205
ZW
24540 elf_frob_symbol (symp, puntp);
24541}
24542#endif
404ff6b5 24543
c19d1205 24544/* MD interface: Finalization. */
a737bd4d 24545
c19d1205
ZW
24546void
24547arm_cleanup (void)
24548{
24549 literal_pool * pool;
a737bd4d 24550
e07e6e58
NC
24551 /* Ensure that all the IT blocks are properly closed. */
24552 check_it_blocks_finished ();
24553
c19d1205
ZW
24554 for (pool = list_of_pools; pool; pool = pool->next)
24555 {
5f4273c7 24556 /* Put it at the end of the relevant section. */
c19d1205
ZW
24557 subseg_set (pool->section, pool->sub_section);
24558#ifdef OBJ_ELF
24559 arm_elf_change_section ();
24560#endif
24561 s_ltorg (0);
24562 }
404ff6b5
AH
24563}
24564
cd000bff
DJ
24565#ifdef OBJ_ELF
24566/* Remove any excess mapping symbols generated for alignment frags in
24567 SEC. We may have created a mapping symbol before a zero byte
24568 alignment; remove it if there's a mapping symbol after the
24569 alignment. */
24570static void
24571check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24572 void *dummy ATTRIBUTE_UNUSED)
24573{
24574 segment_info_type *seginfo = seg_info (sec);
24575 fragS *fragp;
24576
24577 if (seginfo == NULL || seginfo->frchainP == NULL)
24578 return;
24579
24580 for (fragp = seginfo->frchainP->frch_root;
24581 fragp != NULL;
24582 fragp = fragp->fr_next)
24583 {
24584 symbolS *sym = fragp->tc_frag_data.last_map;
24585 fragS *next = fragp->fr_next;
24586
24587 /* Variable-sized frags have been converted to fixed size by
24588 this point. But if this was variable-sized to start with,
24589 there will be a fixed-size frag after it. So don't handle
24590 next == NULL. */
24591 if (sym == NULL || next == NULL)
24592 continue;
24593
24594 if (S_GET_VALUE (sym) < next->fr_address)
24595 /* Not at the end of this frag. */
24596 continue;
24597 know (S_GET_VALUE (sym) == next->fr_address);
24598
24599 do
24600 {
24601 if (next->tc_frag_data.first_map != NULL)
24602 {
24603 /* Next frag starts with a mapping symbol. Discard this
24604 one. */
24605 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24606 break;
24607 }
24608
24609 if (next->fr_next == NULL)
24610 {
24611 /* This mapping symbol is at the end of the section. Discard
24612 it. */
24613 know (next->fr_fix == 0 && next->fr_var == 0);
24614 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24615 break;
24616 }
24617
24618 /* As long as we have empty frags without any mapping symbols,
24619 keep looking. */
24620 /* If the next frag is non-empty and does not start with a
24621 mapping symbol, then this mapping symbol is required. */
24622 if (next->fr_address != next->fr_next->fr_address)
24623 break;
24624
24625 next = next->fr_next;
24626 }
24627 while (next != NULL);
24628 }
24629}
24630#endif
24631
c19d1205
ZW
24632/* Adjust the symbol table. This marks Thumb symbols as distinct from
24633 ARM ones. */
404ff6b5 24634
c19d1205
ZW
24635void
24636arm_adjust_symtab (void)
404ff6b5 24637{
c19d1205
ZW
24638#ifdef OBJ_COFF
24639 symbolS * sym;
404ff6b5 24640
c19d1205
ZW
24641 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24642 {
24643 if (ARM_IS_THUMB (sym))
24644 {
24645 if (THUMB_IS_FUNC (sym))
24646 {
24647 /* Mark the symbol as a Thumb function. */
24648 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24649 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24650 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24651
c19d1205
ZW
24652 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24653 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24654 else
24655 as_bad (_("%s: unexpected function type: %d"),
24656 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24657 }
24658 else switch (S_GET_STORAGE_CLASS (sym))
24659 {
24660 case C_EXT:
24661 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24662 break;
24663 case C_STAT:
24664 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24665 break;
24666 case C_LABEL:
24667 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24668 break;
24669 default:
24670 /* Do nothing. */
24671 break;
24672 }
24673 }
a737bd4d 24674
c19d1205
ZW
24675 if (ARM_IS_INTERWORK (sym))
24676 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24677 }
c19d1205
ZW
24678#endif
24679#ifdef OBJ_ELF
24680 symbolS * sym;
24681 char bind;
404ff6b5 24682
c19d1205 24683 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24684 {
c19d1205
ZW
24685 if (ARM_IS_THUMB (sym))
24686 {
24687 elf_symbol_type * elf_sym;
404ff6b5 24688
c19d1205
ZW
24689 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24690 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24691
b0796911
PB
24692 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24693 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24694 {
24695 /* If it's a .thumb_func, declare it as so,
24696 otherwise tag label as .code 16. */
24697 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24698 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24699 ST_BRANCH_TO_THUMB);
3ba67470 24700 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24701 elf_sym->internal_elf_sym.st_info =
24702 ELF_ST_INFO (bind, STT_ARM_16BIT);
24703 }
24704 }
24705 }
cd000bff
DJ
24706
24707 /* Remove any overlapping mapping symbols generated by alignment frags. */
24708 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24709 /* Now do generic ELF adjustments. */
24710 elf_adjust_symtab ();
c19d1205 24711#endif
404ff6b5
AH
24712}
24713
c19d1205 24714/* MD interface: Initialization. */
404ff6b5 24715
a737bd4d 24716static void
c19d1205 24717set_constant_flonums (void)
a737bd4d 24718{
c19d1205 24719 int i;
404ff6b5 24720
c19d1205
ZW
24721 for (i = 0; i < NUM_FLOAT_VALS; i++)
24722 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24723 abort ();
a737bd4d 24724}
404ff6b5 24725
3e9e4fcf
JB
24726/* Auto-select Thumb mode if it's the only available instruction set for the
24727 given architecture. */
24728
24729static void
24730autoselect_thumb_from_cpu_variant (void)
24731{
24732 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24733 opcode_select (16);
24734}
24735
c19d1205
ZW
24736void
24737md_begin (void)
a737bd4d 24738{
c19d1205
ZW
24739 unsigned mach;
24740 unsigned int i;
404ff6b5 24741
c19d1205
ZW
24742 if ( (arm_ops_hsh = hash_new ()) == NULL
24743 || (arm_cond_hsh = hash_new ()) == NULL
24744 || (arm_shift_hsh = hash_new ()) == NULL
24745 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24746 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24747 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24748 || (arm_reloc_hsh = hash_new ()) == NULL
24749 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24750 as_fatal (_("virtual memory exhausted"));
24751
24752 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24753 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24754 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24755 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24756 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24757 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24758 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24759 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24760 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24761 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24762 (void *) (v7m_psrs + i));
c19d1205 24763 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24764 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24765 for (i = 0;
24766 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24767 i++)
d3ce72d0 24768 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24769 (void *) (barrier_opt_names + i));
c19d1205 24770#ifdef OBJ_ELF
3da1d841
NC
24771 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24772 {
24773 struct reloc_entry * entry = reloc_names + i;
24774
24775 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24776 /* This makes encode_branch() use the EABI versions of this relocation. */
24777 entry->reloc = BFD_RELOC_UNUSED;
24778
24779 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24780 }
c19d1205
ZW
24781#endif
24782
24783 set_constant_flonums ();
404ff6b5 24784
c19d1205
ZW
24785 /* Set the cpu variant based on the command-line options. We prefer
24786 -mcpu= over -march= if both are set (as for GCC); and we prefer
24787 -mfpu= over any other way of setting the floating point unit.
24788 Use of legacy options with new options are faulted. */
e74cfd16 24789 if (legacy_cpu)
404ff6b5 24790 {
e74cfd16 24791 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24792 as_bad (_("use of old and new-style options to set CPU type"));
24793
24794 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24795 }
e74cfd16 24796 else if (!mcpu_cpu_opt)
c19d1205 24797 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24798
e74cfd16 24799 if (legacy_fpu)
c19d1205 24800 {
e74cfd16 24801 if (mfpu_opt)
c19d1205 24802 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24803
24804 mfpu_opt = legacy_fpu;
24805 }
e74cfd16 24806 else if (!mfpu_opt)
03b1477f 24807 {
45eb4c1b
NS
24808#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24809 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24810 /* Some environments specify a default FPU. If they don't, infer it
24811 from the processor. */
e74cfd16 24812 if (mcpu_fpu_opt)
03b1477f
RE
24813 mfpu_opt = mcpu_fpu_opt;
24814 else
24815 mfpu_opt = march_fpu_opt;
39c2da32 24816#else
e74cfd16 24817 mfpu_opt = &fpu_default;
39c2da32 24818#endif
03b1477f
RE
24819 }
24820
e74cfd16 24821 if (!mfpu_opt)
03b1477f 24822 {
493cb6ef 24823 if (mcpu_cpu_opt != NULL)
e74cfd16 24824 mfpu_opt = &fpu_default;
493cb6ef 24825 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24826 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24827 else
e74cfd16 24828 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24829 }
24830
ee065d83 24831#ifdef CPU_DEFAULT
e74cfd16 24832 if (!mcpu_cpu_opt)
ee065d83 24833 {
e74cfd16
PB
24834 mcpu_cpu_opt = &cpu_default;
24835 selected_cpu = cpu_default;
ee065d83 24836 }
73f43896
NC
24837 else if (no_cpu_selected ())
24838 selected_cpu = cpu_default;
e74cfd16
PB
24839#else
24840 if (mcpu_cpu_opt)
24841 selected_cpu = *mcpu_cpu_opt;
ee065d83 24842 else
e74cfd16 24843 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24844#endif
03b1477f 24845
e74cfd16 24846 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24847
3e9e4fcf
JB
24848 autoselect_thumb_from_cpu_variant ();
24849
e74cfd16 24850 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24851
f17c130b 24852#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24853 {
7cc69913
NC
24854 unsigned int flags = 0;
24855
24856#if defined OBJ_ELF
24857 flags = meabi_flags;
d507cf36
PB
24858
24859 switch (meabi_flags)
33a392fb 24860 {
d507cf36 24861 case EF_ARM_EABI_UNKNOWN:
7cc69913 24862#endif
d507cf36
PB
24863 /* Set the flags in the private structure. */
24864 if (uses_apcs_26) flags |= F_APCS26;
24865 if (support_interwork) flags |= F_INTERWORK;
24866 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24867 if (pic_code) flags |= F_PIC;
e74cfd16 24868 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24869 flags |= F_SOFT_FLOAT;
24870
d507cf36
PB
24871 switch (mfloat_abi_opt)
24872 {
24873 case ARM_FLOAT_ABI_SOFT:
24874 case ARM_FLOAT_ABI_SOFTFP:
24875 flags |= F_SOFT_FLOAT;
24876 break;
33a392fb 24877
d507cf36
PB
24878 case ARM_FLOAT_ABI_HARD:
24879 if (flags & F_SOFT_FLOAT)
24880 as_bad (_("hard-float conflicts with specified fpu"));
24881 break;
24882 }
03b1477f 24883
e74cfd16
PB
24884 /* Using pure-endian doubles (even if soft-float). */
24885 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24886 flags |= F_VFP_FLOAT;
f17c130b 24887
fde78edd 24888#if defined OBJ_ELF
e74cfd16 24889 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24890 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24891 break;
24892
8cb51566 24893 case EF_ARM_EABI_VER4:
3a4a14e9 24894 case EF_ARM_EABI_VER5:
c19d1205 24895 /* No additional flags to set. */
d507cf36
PB
24896 break;
24897
24898 default:
24899 abort ();
24900 }
7cc69913 24901#endif
b99bd4ef
NC
24902 bfd_set_private_flags (stdoutput, flags);
24903
24904 /* We have run out flags in the COFF header to encode the
24905 status of ATPCS support, so instead we create a dummy,
c19d1205 24906 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24907 if (atpcs)
24908 {
24909 asection * sec;
24910
24911 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24912
24913 if (sec != NULL)
24914 {
24915 bfd_set_section_flags
24916 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24917 bfd_set_section_size (stdoutput, sec, 0);
24918 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24919 }
24920 }
7cc69913 24921 }
f17c130b 24922#endif
b99bd4ef
NC
24923
24924 /* Record the CPU type as well. */
2d447fca
JM
24925 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24926 mach = bfd_mach_arm_iWMMXt2;
24927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24928 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24929 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24930 mach = bfd_mach_arm_XScale;
e74cfd16 24931 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24932 mach = bfd_mach_arm_ep9312;
e74cfd16 24933 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24934 mach = bfd_mach_arm_5TE;
e74cfd16 24935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24936 {
e74cfd16 24937 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24938 mach = bfd_mach_arm_5T;
24939 else
24940 mach = bfd_mach_arm_5;
24941 }
e74cfd16 24942 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24943 {
e74cfd16 24944 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24945 mach = bfd_mach_arm_4T;
24946 else
24947 mach = bfd_mach_arm_4;
24948 }
e74cfd16 24949 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24950 mach = bfd_mach_arm_3M;
e74cfd16
PB
24951 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24952 mach = bfd_mach_arm_3;
24953 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24954 mach = bfd_mach_arm_2a;
24955 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24956 mach = bfd_mach_arm_2;
24957 else
24958 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24959
24960 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24961}
24962
c19d1205 24963/* Command line processing. */
b99bd4ef 24964
c19d1205
ZW
24965/* md_parse_option
24966 Invocation line includes a switch not recognized by the base assembler.
24967 See if it's a processor-specific option.
b99bd4ef 24968
c19d1205
ZW
24969 This routine is somewhat complicated by the need for backwards
24970 compatibility (since older releases of gcc can't be changed).
24971 The new options try to make the interface as compatible as
24972 possible with GCC.
b99bd4ef 24973
c19d1205 24974 New options (supported) are:
b99bd4ef 24975
c19d1205
ZW
24976 -mcpu=<cpu name> Assemble for selected processor
24977 -march=<architecture name> Assemble for selected architecture
24978 -mfpu=<fpu architecture> Assemble for selected FPU.
24979 -EB/-mbig-endian Big-endian
24980 -EL/-mlittle-endian Little-endian
24981 -k Generate PIC code
24982 -mthumb Start in Thumb mode
24983 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24984
278df34e 24985 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24986 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24987
c19d1205 24988 For now we will also provide support for:
b99bd4ef 24989
c19d1205
ZW
24990 -mapcs-32 32-bit Program counter
24991 -mapcs-26 26-bit Program counter
24992 -macps-float Floats passed in FP registers
24993 -mapcs-reentrant Reentrant code
24994 -matpcs
24995 (sometime these will probably be replaced with -mapcs=<list of options>
24996 and -matpcs=<list of options>)
b99bd4ef 24997
c19d1205
ZW
24998 The remaining options are only supported for back-wards compatibility.
24999 Cpu variants, the arm part is optional:
25000 -m[arm]1 Currently not supported.
25001 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25002 -m[arm]3 Arm 3 processor
25003 -m[arm]6[xx], Arm 6 processors
25004 -m[arm]7[xx][t][[d]m] Arm 7 processors
25005 -m[arm]8[10] Arm 8 processors
25006 -m[arm]9[20][tdmi] Arm 9 processors
25007 -mstrongarm[110[0]] StrongARM processors
25008 -mxscale XScale processors
25009 -m[arm]v[2345[t[e]]] Arm architectures
25010 -mall All (except the ARM1)
25011 FP variants:
25012 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25013 -mfpe-old (No float load/store multiples)
25014 -mvfpxd VFP Single precision
25015 -mvfp All VFP
25016 -mno-fpu Disable all floating point instructions
b99bd4ef 25017
c19d1205
ZW
25018 The following CPU names are recognized:
25019 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25020 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25021 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25022 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25023 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25024 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25025 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25026
c19d1205 25027 */
b99bd4ef 25028
c19d1205 25029const char * md_shortopts = "m:k";
b99bd4ef 25030
c19d1205
ZW
25031#ifdef ARM_BI_ENDIAN
25032#define OPTION_EB (OPTION_MD_BASE + 0)
25033#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25034#else
c19d1205
ZW
25035#if TARGET_BYTES_BIG_ENDIAN
25036#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25037#else
c19d1205
ZW
25038#define OPTION_EL (OPTION_MD_BASE + 1)
25039#endif
b99bd4ef 25040#endif
845b51d6 25041#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25042
c19d1205 25043struct option md_longopts[] =
b99bd4ef 25044{
c19d1205
ZW
25045#ifdef OPTION_EB
25046 {"EB", no_argument, NULL, OPTION_EB},
25047#endif
25048#ifdef OPTION_EL
25049 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25050#endif
845b51d6 25051 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25052 {NULL, no_argument, NULL, 0}
25053};
b99bd4ef 25054
8b2d793c 25055
c19d1205 25056size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25057
c19d1205 25058struct arm_option_table
b99bd4ef 25059{
e0471c16
TS
25060 const char *option; /* Option name to match. */
25061 const char *help; /* Help information. */
c19d1205
ZW
25062 int *var; /* Variable to change. */
25063 int value; /* What to change it to. */
e0471c16 25064 const char *deprecated; /* If non-null, print this message. */
c19d1205 25065};
b99bd4ef 25066
c19d1205
ZW
25067struct arm_option_table arm_opts[] =
25068{
25069 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25070 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25071 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25072 &support_interwork, 1, NULL},
25073 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25074 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25075 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25076 1, NULL},
25077 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25078 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25079 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25080 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25081 NULL},
b99bd4ef 25082
c19d1205
ZW
25083 /* These are recognized by the assembler, but have no affect on code. */
25084 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25085 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25086
25087 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25088 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25089 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25090 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25091 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25092 {NULL, NULL, NULL, 0, NULL}
25093};
25094
25095struct arm_legacy_option_table
25096{
e0471c16 25097 const char *option; /* Option name to match. */
e74cfd16
PB
25098 const arm_feature_set **var; /* Variable to change. */
25099 const arm_feature_set value; /* What to change it to. */
e0471c16 25100 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25101};
b99bd4ef 25102
e74cfd16
PB
25103const struct arm_legacy_option_table arm_legacy_opts[] =
25104{
c19d1205
ZW
25105 /* DON'T add any new processors to this list -- we want the whole list
25106 to go away... Add them to the processors table instead. */
e74cfd16
PB
25107 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25108 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25109 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25110 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25111 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25112 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25113 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25114 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25115 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25116 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25117 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25118 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25119 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25120 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25121 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25122 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25123 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25124 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25125 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25126 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25127 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25128 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25129 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25130 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25131 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25132 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25133 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25134 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25135 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25136 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25137 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25138 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25139 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25140 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25141 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25142 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25143 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25144 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25145 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25146 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25147 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25148 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25149 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25150 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25151 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25152 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25153 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25154 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25155 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25156 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25157 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25158 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25159 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25160 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25161 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25162 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25163 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25164 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25165 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25166 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25167 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25168 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25169 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25170 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25171 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25172 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25173 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25174 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25175 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25176 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25177 N_("use -mcpu=strongarm110")},
e74cfd16 25178 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25179 N_("use -mcpu=strongarm1100")},
e74cfd16 25180 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25181 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25182 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25183 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25184 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25185
c19d1205 25186 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25187 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25188 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25189 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25190 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25191 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25192 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25193 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25194 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25195 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25196 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25197 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25198 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25199 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25200 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25201 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25202 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25203 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25204 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25205
c19d1205 25206 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25207 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25208 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25209 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25210 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25211 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25212
e74cfd16 25213 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25214};
7ed4c4c5 25215
c19d1205 25216struct arm_cpu_option_table
7ed4c4c5 25217{
e0471c16 25218 const char *name;
f3bad469 25219 size_t name_len;
e74cfd16 25220 const arm_feature_set value;
c19d1205
ZW
25221 /* For some CPUs we assume an FPU unless the user explicitly sets
25222 -mfpu=... */
e74cfd16 25223 const arm_feature_set default_fpu;
ee065d83
PB
25224 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25225 case. */
25226 const char *canonical_name;
c19d1205 25227};
7ed4c4c5 25228
c19d1205
ZW
25229/* This list should, at a minimum, contain all the cpu names
25230 recognized by GCC. */
f3bad469 25231#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25232static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25233{
f3bad469
MGD
25234 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25235 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25236 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25237 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25238 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25239 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25240 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25241 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25242 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25243 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25244 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25245 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25246 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25247 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25248 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25249 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25250 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25251 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25252 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25253 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25254 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25255 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25256 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25257 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25258 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25259 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25260 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25261 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25262 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25263 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25264 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25265 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25266 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25267 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25268 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25269 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25270 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25271 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25272 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25273 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25274 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25275 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25276 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25277 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25278 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25279 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25280 /* For V5 or later processors we default to using VFP; but the user
25281 should really set the FPU type explicitly. */
f3bad469
MGD
25282 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25283 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25284 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25285 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25286 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25287 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25288 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25289 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25290 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25291 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25292 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25293 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25294 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25295 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25296 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25297 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25298 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25299 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25300 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25301 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25302 "ARM1026EJ-S"),
25303 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25304 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25305 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25306 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25307 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25308 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25309 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25310 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25311 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25312 "ARM1136JF-S"),
25313 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25314 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25315 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25316 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25317 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25318 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25319 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25320 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25321 FPU_NONE, "Cortex-A5"),
c9fb6e58 25322 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25323 "Cortex-A7"),
25324 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25325 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25326 | FPU_NEON_EXT_V1),
f3bad469
MGD
25327 "Cortex-A8"),
25328 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25329 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25330 | FPU_NEON_EXT_V1),
f3bad469 25331 "Cortex-A9"),
c9fb6e58 25332 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25333 "Cortex-A12"),
c9fb6e58 25334 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25335 "Cortex-A15"),
d7adf960
KT
25336 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25337 "Cortex-A17"),
6735952f
KT
25338 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25339 "Cortex-A32"),
43cdc0a8
RR
25340 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25341 "Cortex-A35"),
92eb40d9 25342 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25343 "Cortex-A53"),
92eb40d9 25344 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25345 "Cortex-A57"),
b19f47ad
JW
25346 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25347 "Cortex-A72"),
f3bad469
MGD
25348 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25349 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25350 "Cortex-R4F"),
25351 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25352 FPU_NONE, "Cortex-R5"),
70a8bc5b 25353 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25354 FPU_ARCH_VFP_V3D16,
25355 "Cortex-R7"),
5f474010
TP
25356 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25357 FPU_ARCH_VFP_V3D16,
25358 "Cortex-R8"),
a715796b 25359 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25360 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25361 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25362 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25363 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25364 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
25365 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25366 "Samsung " \
25367 "Exynos M1"),
6b21c2bf
JW
25368 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25369 "Qualcomm "
25370 "QDF24XX"),
25371
c19d1205 25372 /* ??? XSCALE is really an architecture. */
f3bad469 25373 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25374 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25375 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25376 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25377 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25378 /* Maverick */
823d2571 25379 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25380 FPU_ARCH_MAVERICK, "ARM920T"),
25381 /* Marvell processors. */
ff8646ee
TP
25382 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25383 | ARM_EXT_SEC,
25384 ARM_EXT2_V6T2_V8M),
477330fc 25385 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25386 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25387 | ARM_EXT_SEC,
25388 ARM_EXT2_V6T2_V8M),
4347085a 25389 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25390 /* APM X-Gene family. */
25391 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25392 "APM X-Gene 1"),
25393 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25394 "APM X-Gene 2"),
da4339ed 25395
f3bad469 25396 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25397};
f3bad469 25398#undef ARM_CPU_OPT
7ed4c4c5 25399
c19d1205 25400struct arm_arch_option_table
7ed4c4c5 25401{
e0471c16 25402 const char *name;
f3bad469 25403 size_t name_len;
e74cfd16
PB
25404 const arm_feature_set value;
25405 const arm_feature_set default_fpu;
c19d1205 25406};
7ed4c4c5 25407
c19d1205
ZW
25408/* This list should, at a minimum, contain all the architecture names
25409 recognized by GCC. */
f3bad469 25410#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25411static const struct arm_arch_option_table arm_archs[] =
c19d1205 25412{
f3bad469
MGD
25413 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25414 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25415 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25416 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25417 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25418 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25419 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25420 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25421 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25422 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25423 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25424 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25425 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25426 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25427 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25428 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25429 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25430 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25431 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25432 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25433 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25434 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25435 kept to preserve existing behaviour. */
25436 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25437 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25438 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25439 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25440 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25441 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25442 kept to preserve existing behaviour. */
25443 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25444 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25445 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25446 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25447 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25448 /* The official spelling of the ARMv7 profile variants is the dashed form.
25449 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25450 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25451 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25452 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25453 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25454 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25455 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25456 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25457 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25458 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25459 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25460 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25461 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25462 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25463 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25464 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25465 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25466 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25467};
f3bad469 25468#undef ARM_ARCH_OPT
7ed4c4c5 25469
69133863
MGD
25470/* ISA extensions in the co-processor and main instruction set space. */
25471struct arm_option_extension_value_table
c19d1205 25472{
e0471c16 25473 const char *name;
f3bad469 25474 size_t name_len;
5a70a223
JB
25475 const arm_feature_set merge_value;
25476 const arm_feature_set clear_value;
d942732e
TP
25477 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25478 indicates that an extension is available for all architectures while
25479 ARM_ANY marks an empty entry. */
25480 const arm_feature_set allowed_archs[2];
c19d1205 25481};
7ed4c4c5 25482
69133863
MGD
25483/* The following table must be in alphabetical order with a NULL last entry.
25484 */
d942732e
TP
25485#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25486#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25487static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25488{
823d2571
TG
25489 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25490 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25491 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25492 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25493 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25494 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25495 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25496 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25497 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25498 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25499 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25500 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25501 ARM_ARCH_V8_2A),
d942732e 25502 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25503 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25504 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25505 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25506 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25507 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25508 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25509 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25510 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25511 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25512 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25513 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25514 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25515 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25516 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25517 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25518 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25519 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25520 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25521 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25522 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25523 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25524 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25525 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25526 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25527 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25528 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25529 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25530 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25531 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25532 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25533 | ARM_EXT_DIV),
25534 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25535 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25536 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25537 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25538 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25539};
f3bad469 25540#undef ARM_EXT_OPT
69133863
MGD
25541
25542/* ISA floating-point and Advanced SIMD extensions. */
25543struct arm_option_fpu_value_table
25544{
e0471c16 25545 const char *name;
69133863 25546 const arm_feature_set value;
c19d1205 25547};
7ed4c4c5 25548
c19d1205
ZW
25549/* This list should, at a minimum, contain all the fpu names
25550 recognized by GCC. */
69133863 25551static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25552{
25553 {"softfpa", FPU_NONE},
25554 {"fpe", FPU_ARCH_FPE},
25555 {"fpe2", FPU_ARCH_FPE},
25556 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25557 {"fpa", FPU_ARCH_FPA},
25558 {"fpa10", FPU_ARCH_FPA},
25559 {"fpa11", FPU_ARCH_FPA},
25560 {"arm7500fe", FPU_ARCH_FPA},
25561 {"softvfp", FPU_ARCH_VFP},
25562 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25563 {"vfp", FPU_ARCH_VFP_V2},
25564 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25565 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25566 {"vfp10", FPU_ARCH_VFP_V2},
25567 {"vfp10-r0", FPU_ARCH_VFP_V1},
25568 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25569 {"vfpv2", FPU_ARCH_VFP_V2},
25570 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25571 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25572 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25573 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25574 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25575 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25576 {"arm1020t", FPU_ARCH_VFP_V1},
25577 {"arm1020e", FPU_ARCH_VFP_V2},
25578 {"arm1136jfs", FPU_ARCH_VFP_V2},
25579 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25580 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25581 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25582 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25583 {"vfpv4", FPU_ARCH_VFP_V4},
25584 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25585 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25586 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25587 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25588 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25589 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25590 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25591 {"crypto-neon-fp-armv8",
25592 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25593 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25594 {"crypto-neon-fp-armv8.1",
25595 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25596 {NULL, ARM_ARCH_NONE}
25597};
25598
25599struct arm_option_value_table
25600{
e0471c16 25601 const char *name;
e74cfd16 25602 long value;
c19d1205 25603};
7ed4c4c5 25604
e74cfd16 25605static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25606{
25607 {"hard", ARM_FLOAT_ABI_HARD},
25608 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25609 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25610 {NULL, 0}
c19d1205 25611};
7ed4c4c5 25612
c19d1205 25613#ifdef OBJ_ELF
3a4a14e9 25614/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25615static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25616{
25617 {"gnu", EF_ARM_EABI_UNKNOWN},
25618 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25619 {"5", EF_ARM_EABI_VER5},
e74cfd16 25620 {NULL, 0}
c19d1205
ZW
25621};
25622#endif
7ed4c4c5 25623
c19d1205
ZW
25624struct arm_long_option_table
25625{
e0471c16
TS
25626 const char * option; /* Substring to match. */
25627 const char * help; /* Help information. */
17b9d67d 25628 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25629 const char * deprecated; /* If non-null, print this message. */
c19d1205 25630};
7ed4c4c5 25631
c921be7d 25632static bfd_boolean
82b8a785 25633arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25634{
325801bd 25635 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25636
69133863 25637 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25638 extensions being added before being removed. We achieve this by having
25639 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25640 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25641 or removing it (0) and only allowing it to change in the order
69133863
MGD
25642 -1 -> 1 -> 0. */
25643 const struct arm_option_extension_value_table * opt = NULL;
d942732e 25644 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
25645 int adding_value = -1;
25646
e74cfd16
PB
25647 /* Copy the feature set, so that we can modify it. */
25648 *ext_set = **opt_p;
25649 *opt_p = ext_set;
25650
c19d1205 25651 while (str != NULL && *str != 0)
7ed4c4c5 25652 {
82b8a785 25653 const char *ext;
f3bad469 25654 size_t len;
7ed4c4c5 25655
c19d1205
ZW
25656 if (*str != '+')
25657 {
25658 as_bad (_("invalid architectural extension"));
c921be7d 25659 return FALSE;
c19d1205 25660 }
7ed4c4c5 25661
c19d1205
ZW
25662 str++;
25663 ext = strchr (str, '+');
7ed4c4c5 25664
c19d1205 25665 if (ext != NULL)
f3bad469 25666 len = ext - str;
c19d1205 25667 else
f3bad469 25668 len = strlen (str);
7ed4c4c5 25669
f3bad469 25670 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25671 {
25672 if (adding_value != 0)
25673 {
25674 adding_value = 0;
25675 opt = arm_extensions;
25676 }
25677
f3bad469 25678 len -= 2;
69133863
MGD
25679 str += 2;
25680 }
f3bad469 25681 else if (len > 0)
69133863
MGD
25682 {
25683 if (adding_value == -1)
25684 {
25685 adding_value = 1;
25686 opt = arm_extensions;
25687 }
25688 else if (adding_value != 1)
25689 {
25690 as_bad (_("must specify extensions to add before specifying "
25691 "those to remove"));
25692 return FALSE;
25693 }
25694 }
25695
f3bad469 25696 if (len == 0)
c19d1205
ZW
25697 {
25698 as_bad (_("missing architectural extension"));
c921be7d 25699 return FALSE;
c19d1205 25700 }
7ed4c4c5 25701
69133863
MGD
25702 gas_assert (adding_value != -1);
25703 gas_assert (opt != NULL);
25704
25705 /* Scan over the options table trying to find an exact match. */
25706 for (; opt->name != NULL; opt++)
f3bad469 25707 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25708 {
d942732e
TP
25709 int i, nb_allowed_archs =
25710 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 25711 /* Check we can apply the extension to this architecture. */
d942732e
TP
25712 for (i = 0; i < nb_allowed_archs; i++)
25713 {
25714 /* Empty entry. */
25715 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
25716 continue;
25717 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
25718 break;
25719 }
25720 if (i == nb_allowed_archs)
69133863
MGD
25721 {
25722 as_bad (_("extension does not apply to the base architecture"));
25723 return FALSE;
25724 }
25725
25726 /* Add or remove the extension. */
25727 if (adding_value)
5a70a223 25728 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25729 else
5a70a223 25730 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25731
c19d1205
ZW
25732 break;
25733 }
7ed4c4c5 25734
c19d1205
ZW
25735 if (opt->name == NULL)
25736 {
69133863
MGD
25737 /* Did we fail to find an extension because it wasn't specified in
25738 alphabetical order, or because it does not exist? */
25739
25740 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25741 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25742 break;
25743
25744 if (opt->name == NULL)
25745 as_bad (_("unknown architectural extension `%s'"), str);
25746 else
25747 as_bad (_("architectural extensions must be specified in "
25748 "alphabetical order"));
25749
c921be7d 25750 return FALSE;
c19d1205 25751 }
69133863
MGD
25752 else
25753 {
25754 /* We should skip the extension we've just matched the next time
25755 round. */
25756 opt++;
25757 }
7ed4c4c5 25758
c19d1205
ZW
25759 str = ext;
25760 };
7ed4c4c5 25761
c921be7d 25762 return TRUE;
c19d1205 25763}
7ed4c4c5 25764
c921be7d 25765static bfd_boolean
17b9d67d 25766arm_parse_cpu (const char *str)
7ed4c4c5 25767{
f3bad469 25768 const struct arm_cpu_option_table *opt;
82b8a785 25769 const char *ext = strchr (str, '+');
f3bad469 25770 size_t len;
7ed4c4c5 25771
c19d1205 25772 if (ext != NULL)
f3bad469 25773 len = ext - str;
7ed4c4c5 25774 else
f3bad469 25775 len = strlen (str);
7ed4c4c5 25776
f3bad469 25777 if (len == 0)
7ed4c4c5 25778 {
c19d1205 25779 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25780 return FALSE;
7ed4c4c5
NC
25781 }
25782
c19d1205 25783 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25784 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25785 {
e74cfd16
PB
25786 mcpu_cpu_opt = &opt->value;
25787 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25788 if (opt->canonical_name)
ef8e6722
JW
25789 {
25790 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25791 strcpy (selected_cpu_name, opt->canonical_name);
25792 }
ee065d83
PB
25793 else
25794 {
f3bad469 25795 size_t i;
c921be7d 25796
ef8e6722
JW
25797 if (len >= sizeof selected_cpu_name)
25798 len = (sizeof selected_cpu_name) - 1;
25799
f3bad469 25800 for (i = 0; i < len; i++)
ee065d83
PB
25801 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25802 selected_cpu_name[i] = 0;
25803 }
7ed4c4c5 25804
c19d1205
ZW
25805 if (ext != NULL)
25806 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25807
c921be7d 25808 return TRUE;
c19d1205 25809 }
7ed4c4c5 25810
c19d1205 25811 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25812 return FALSE;
7ed4c4c5
NC
25813}
25814
c921be7d 25815static bfd_boolean
17b9d67d 25816arm_parse_arch (const char *str)
7ed4c4c5 25817{
e74cfd16 25818 const struct arm_arch_option_table *opt;
82b8a785 25819 const char *ext = strchr (str, '+');
f3bad469 25820 size_t len;
7ed4c4c5 25821
c19d1205 25822 if (ext != NULL)
f3bad469 25823 len = ext - str;
7ed4c4c5 25824 else
f3bad469 25825 len = strlen (str);
7ed4c4c5 25826
f3bad469 25827 if (len == 0)
7ed4c4c5 25828 {
c19d1205 25829 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25830 return FALSE;
7ed4c4c5
NC
25831 }
25832
c19d1205 25833 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25834 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25835 {
e74cfd16
PB
25836 march_cpu_opt = &opt->value;
25837 march_fpu_opt = &opt->default_fpu;
5f4273c7 25838 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25839
c19d1205
ZW
25840 if (ext != NULL)
25841 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25842
c921be7d 25843 return TRUE;
c19d1205
ZW
25844 }
25845
25846 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25847 return FALSE;
7ed4c4c5 25848}
eb043451 25849
c921be7d 25850static bfd_boolean
17b9d67d 25851arm_parse_fpu (const char * str)
c19d1205 25852{
69133863 25853 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25854
c19d1205
ZW
25855 for (opt = arm_fpus; opt->name != NULL; opt++)
25856 if (streq (opt->name, str))
25857 {
e74cfd16 25858 mfpu_opt = &opt->value;
c921be7d 25859 return TRUE;
c19d1205 25860 }
b99bd4ef 25861
c19d1205 25862 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25863 return FALSE;
c19d1205
ZW
25864}
25865
c921be7d 25866static bfd_boolean
17b9d67d 25867arm_parse_float_abi (const char * str)
b99bd4ef 25868{
e74cfd16 25869 const struct arm_option_value_table * opt;
b99bd4ef 25870
c19d1205
ZW
25871 for (opt = arm_float_abis; opt->name != NULL; opt++)
25872 if (streq (opt->name, str))
25873 {
25874 mfloat_abi_opt = opt->value;
c921be7d 25875 return TRUE;
c19d1205 25876 }
cc8a6dd0 25877
c19d1205 25878 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25879 return FALSE;
c19d1205 25880}
b99bd4ef 25881
c19d1205 25882#ifdef OBJ_ELF
c921be7d 25883static bfd_boolean
17b9d67d 25884arm_parse_eabi (const char * str)
c19d1205 25885{
e74cfd16 25886 const struct arm_option_value_table *opt;
cc8a6dd0 25887
c19d1205
ZW
25888 for (opt = arm_eabis; opt->name != NULL; opt++)
25889 if (streq (opt->name, str))
25890 {
25891 meabi_flags = opt->value;
c921be7d 25892 return TRUE;
c19d1205
ZW
25893 }
25894 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25895 return FALSE;
c19d1205
ZW
25896}
25897#endif
cc8a6dd0 25898
c921be7d 25899static bfd_boolean
17b9d67d 25900arm_parse_it_mode (const char * str)
e07e6e58 25901{
c921be7d 25902 bfd_boolean ret = TRUE;
e07e6e58
NC
25903
25904 if (streq ("arm", str))
25905 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25906 else if (streq ("thumb", str))
25907 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25908 else if (streq ("always", str))
25909 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25910 else if (streq ("never", str))
25911 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25912 else
25913 {
25914 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25915 "arm, thumb, always, or never."), str);
c921be7d 25916 ret = FALSE;
e07e6e58
NC
25917 }
25918
25919 return ret;
25920}
25921
2e6976a8 25922static bfd_boolean
17b9d67d 25923arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
25924{
25925 codecomposer_syntax = TRUE;
25926 arm_comment_chars[0] = ';';
25927 arm_line_separator_chars[0] = 0;
25928 return TRUE;
25929}
25930
c19d1205
ZW
25931struct arm_long_option_table arm_long_opts[] =
25932{
25933 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25934 arm_parse_cpu, NULL},
25935 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25936 arm_parse_arch, NULL},
25937 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25938 arm_parse_fpu, NULL},
25939 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25940 arm_parse_float_abi, NULL},
25941#ifdef OBJ_ELF
7fac0536 25942 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25943 arm_parse_eabi, NULL},
25944#endif
e07e6e58
NC
25945 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25946 arm_parse_it_mode, NULL},
2e6976a8
DG
25947 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25948 arm_ccs_mode, NULL},
c19d1205
ZW
25949 {NULL, NULL, 0, NULL}
25950};
cc8a6dd0 25951
c19d1205 25952int
17b9d67d 25953md_parse_option (int c, const char * arg)
c19d1205
ZW
25954{
25955 struct arm_option_table *opt;
e74cfd16 25956 const struct arm_legacy_option_table *fopt;
c19d1205 25957 struct arm_long_option_table *lopt;
b99bd4ef 25958
c19d1205 25959 switch (c)
b99bd4ef 25960 {
c19d1205
ZW
25961#ifdef OPTION_EB
25962 case OPTION_EB:
25963 target_big_endian = 1;
25964 break;
25965#endif
cc8a6dd0 25966
c19d1205
ZW
25967#ifdef OPTION_EL
25968 case OPTION_EL:
25969 target_big_endian = 0;
25970 break;
25971#endif
b99bd4ef 25972
845b51d6
PB
25973 case OPTION_FIX_V4BX:
25974 fix_v4bx = TRUE;
25975 break;
25976
c19d1205
ZW
25977 case 'a':
25978 /* Listing option. Just ignore these, we don't support additional
25979 ones. */
25980 return 0;
b99bd4ef 25981
c19d1205
ZW
25982 default:
25983 for (opt = arm_opts; opt->option != NULL; opt++)
25984 {
25985 if (c == opt->option[0]
25986 && ((arg == NULL && opt->option[1] == 0)
25987 || streq (arg, opt->option + 1)))
25988 {
c19d1205 25989 /* If the option is deprecated, tell the user. */
278df34e 25990 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25991 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25992 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25993
c19d1205
ZW
25994 if (opt->var != NULL)
25995 *opt->var = opt->value;
cc8a6dd0 25996
c19d1205
ZW
25997 return 1;
25998 }
25999 }
b99bd4ef 26000
e74cfd16
PB
26001 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26002 {
26003 if (c == fopt->option[0]
26004 && ((arg == NULL && fopt->option[1] == 0)
26005 || streq (arg, fopt->option + 1)))
26006 {
e74cfd16 26007 /* If the option is deprecated, tell the user. */
278df34e 26008 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26009 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26010 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26011
26012 if (fopt->var != NULL)
26013 *fopt->var = &fopt->value;
26014
26015 return 1;
26016 }
26017 }
26018
c19d1205
ZW
26019 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26020 {
26021 /* These options are expected to have an argument. */
26022 if (c == lopt->option[0]
26023 && arg != NULL
26024 && strncmp (arg, lopt->option + 1,
26025 strlen (lopt->option + 1)) == 0)
26026 {
c19d1205 26027 /* If the option is deprecated, tell the user. */
278df34e 26028 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26029 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26030 _(lopt->deprecated));
b99bd4ef 26031
c19d1205
ZW
26032 /* Call the sup-option parser. */
26033 return lopt->func (arg + strlen (lopt->option) - 1);
26034 }
26035 }
a737bd4d 26036
c19d1205
ZW
26037 return 0;
26038 }
a394c00f 26039
c19d1205
ZW
26040 return 1;
26041}
a394c00f 26042
c19d1205
ZW
26043void
26044md_show_usage (FILE * fp)
a394c00f 26045{
c19d1205
ZW
26046 struct arm_option_table *opt;
26047 struct arm_long_option_table *lopt;
a394c00f 26048
c19d1205 26049 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26050
c19d1205
ZW
26051 for (opt = arm_opts; opt->option != NULL; opt++)
26052 if (opt->help != NULL)
26053 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26054
c19d1205
ZW
26055 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26056 if (lopt->help != NULL)
26057 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26058
c19d1205
ZW
26059#ifdef OPTION_EB
26060 fprintf (fp, _("\
26061 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26062#endif
26063
c19d1205
ZW
26064#ifdef OPTION_EL
26065 fprintf (fp, _("\
26066 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26067#endif
845b51d6
PB
26068
26069 fprintf (fp, _("\
26070 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26071}
ee065d83
PB
26072
26073
26074#ifdef OBJ_ELF
62b3e311
PB
26075typedef struct
26076{
26077 int val;
26078 arm_feature_set flags;
26079} cpu_arch_ver_table;
26080
4ed7ed8d
TP
26081/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26082 must be sorted least features first but some reordering is needed, eg. for
26083 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26084static const cpu_arch_ver_table cpu_arch_ver[] =
26085{
26086 {1, ARM_ARCH_V4},
26087 {2, ARM_ARCH_V4T},
26088 {3, ARM_ARCH_V5},
ee3c0378 26089 {3, ARM_ARCH_V5T},
62b3e311
PB
26090 {4, ARM_ARCH_V5TE},
26091 {5, ARM_ARCH_V5TEJ},
26092 {6, ARM_ARCH_V6},
7e806470 26093 {9, ARM_ARCH_V6K},
f4c65163 26094 {7, ARM_ARCH_V6Z},
91e22acd 26095 {11, ARM_ARCH_V6M},
b2a5fbdc 26096 {12, ARM_ARCH_V6SM},
7e806470 26097 {8, ARM_ARCH_V6T2},
c9fb6e58 26098 {10, ARM_ARCH_V7VE},
62b3e311
PB
26099 {10, ARM_ARCH_V7R},
26100 {10, ARM_ARCH_V7M},
bca38921 26101 {14, ARM_ARCH_V8A},
ff8646ee 26102 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26103 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26104 {0, ARM_ARCH_NONE}
26105};
26106
ee3c0378
AS
26107/* Set an attribute if it has not already been set by the user. */
26108static void
26109aeabi_set_attribute_int (int tag, int value)
26110{
26111 if (tag < 1
26112 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26113 || !attributes_set_explicitly[tag])
26114 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26115}
26116
26117static void
26118aeabi_set_attribute_string (int tag, const char *value)
26119{
26120 if (tag < 1
26121 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26122 || !attributes_set_explicitly[tag])
26123 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26124}
26125
ee065d83 26126/* Set the public EABI object attributes. */
3cfdb781 26127void
ee065d83
PB
26128aeabi_set_public_attributes (void)
26129{
26130 int arch;
69239280 26131 char profile;
90ec0d68 26132 int virt_sec = 0;
bca38921 26133 int fp16_optional = 0;
15afaa63 26134 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26135 arm_feature_set flags;
62b3e311 26136 arm_feature_set tmp;
ff8646ee 26137 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26138 const cpu_arch_ver_table *p;
ee065d83
PB
26139
26140 /* Choose the architecture based on the capabilities of the requested cpu
26141 (if any) and/or the instructions actually used. */
e74cfd16
PB
26142 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26143 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26144 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26145
26146 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26147 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26148
26149 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26150 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26151
7f78eb34
JW
26152 selected_cpu = flags;
26153
ddd7f988 26154 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26155 if (object_arch)
26156 {
26157 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26158 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26159 }
26160
251665fc
MGD
26161 /* We need to make sure that the attributes do not identify us as v6S-M
26162 when the only v6S-M feature in use is the Operating System Extensions. */
26163 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26164 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26165 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26166
62b3e311
PB
26167 tmp = flags;
26168 arch = 0;
26169 for (p = cpu_arch_ver; p->val; p++)
26170 {
26171 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26172 {
26173 arch = p->val;
15afaa63 26174 arm_arch = p->flags;
62b3e311
PB
26175 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26176 }
26177 }
ee065d83 26178
9e3c6df6
PB
26179 /* The table lookup above finds the last architecture to contribute
26180 a new feature. Unfortunately, Tag13 is a subset of the union of
26181 v6T2 and v7-M, so it is never seen as contributing a new feature.
26182 We can not search for the last entry which is entirely used,
26183 because if no CPU is specified we build up only those flags
26184 actually used. Perhaps we should separate out the specified
26185 and implicit cases. Avoid taking this path for -march=all by
26186 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26187 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26188 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26189 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26190 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26191 {
26192 arch = TAG_CPU_ARCH_V7E_M;
26193 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26194 }
4ed7ed8d 26195
ff8646ee
TP
26196 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26197 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26198 {
26199 arch = TAG_CPU_ARCH_V8M_MAIN;
26200 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26201 }
ff8646ee 26202
4ed7ed8d
TP
26203 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26204 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26205 ARMv8-M, -march=all must be detected as ARMv8-A. */
26206 if (arch == TAG_CPU_ARCH_V8M_MAIN
26207 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26208 {
26209 arch = TAG_CPU_ARCH_V8;
26210 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26211 }
9e3c6df6 26212
ee065d83
PB
26213 /* Tag_CPU_name. */
26214 if (selected_cpu_name[0])
26215 {
91d6fa6a 26216 char *q;
ee065d83 26217
91d6fa6a
NC
26218 q = selected_cpu_name;
26219 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26220 {
26221 int i;
5f4273c7 26222
91d6fa6a
NC
26223 q += 4;
26224 for (i = 0; q[i]; i++)
26225 q[i] = TOUPPER (q[i]);
ee065d83 26226 }
91d6fa6a 26227 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26228 }
62f3b8c8 26229
ee065d83 26230 /* Tag_CPU_arch. */
ee3c0378 26231 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26232
62b3e311 26233 /* Tag_CPU_arch_profile. */
10c9892b 26234 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26235 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26236 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26237 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26238 profile = 'A';
62b3e311 26239 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26240 profile = 'R';
7e806470 26241 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26242 profile = 'M';
26243 else
26244 profile = '\0';
26245
26246 if (profile != '\0')
26247 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26248
15afaa63
TP
26249 /* Tag_DSP_extension. */
26250 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26251 {
26252 arm_feature_set ext;
26253
26254 /* DSP instructions not in architecture. */
26255 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26256 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26257 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26258 }
26259
ee065d83 26260 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26261 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26262 || arch == 0)
26263 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26264
ee065d83 26265 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26266 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26267 || arch == 0)
4ed7ed8d
TP
26268 {
26269 int thumb_isa_use;
26270
26271 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26272 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26273 thumb_isa_use = 3;
26274 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26275 thumb_isa_use = 2;
26276 else
26277 thumb_isa_use = 1;
26278 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26279 }
62f3b8c8 26280
ee065d83 26281 /* Tag_VFP_arch. */
a715796b
TG
26282 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26283 aeabi_set_attribute_int (Tag_VFP_arch,
26284 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26285 ? 7 : 8);
bca38921 26286 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26287 aeabi_set_attribute_int (Tag_VFP_arch,
26288 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26289 ? 5 : 6);
26290 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26291 {
26292 fp16_optional = 1;
26293 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26294 }
ada65aa3 26295 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26296 {
26297 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26298 fp16_optional = 1;
26299 }
ee3c0378
AS
26300 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26301 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26302 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26303 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26304 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26305
4547cb56
NC
26306 /* Tag_ABI_HardFP_use. */
26307 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26308 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26309 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26310
ee065d83 26311 /* Tag_WMMX_arch. */
ee3c0378
AS
26312 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26313 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26314 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26315 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26316
ee3c0378 26317 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26318 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26319 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26320 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26321 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26322 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26323 {
26324 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26325 {
26326 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26327 }
26328 else
26329 {
26330 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26331 fp16_optional = 1;
26332 }
26333 }
fa94de6b 26334
ee3c0378 26335 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26336 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26337 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26338
69239280
MGD
26339 /* Tag_DIV_use.
26340
26341 We set Tag_DIV_use to two when integer divide instructions have been used
26342 in ARM state, or when Thumb integer divide instructions have been used,
26343 but we have no architecture profile set, nor have we any ARM instructions.
26344
4ed7ed8d
TP
26345 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26346 by the base architecture.
bca38921 26347
69239280 26348 For new architectures we will have to check these tests. */
ff8646ee
TP
26349 gas_assert (arch <= TAG_CPU_ARCH_V8
26350 || (arch >= TAG_CPU_ARCH_V8M_BASE
26351 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26352 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26353 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26354 aeabi_set_attribute_int (Tag_DIV_use, 0);
26355 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26356 || (profile == '\0'
26357 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26358 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26359 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26360
26361 /* Tag_MP_extension_use. */
26362 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26363 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26364
26365 /* Tag Virtualization_use. */
26366 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26367 virt_sec |= 1;
26368 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26369 virt_sec |= 2;
26370 if (virt_sec != 0)
26371 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26372}
26373
104d59d1 26374/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26375void
26376arm_md_end (void)
26377{
ee065d83
PB
26378 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26379 return;
26380
26381 aeabi_set_public_attributes ();
ee065d83 26382}
8463be01 26383#endif /* OBJ_ELF */
ee065d83
PB
26384
26385
26386/* Parse a .cpu directive. */
26387
26388static void
26389s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26390{
e74cfd16 26391 const struct arm_cpu_option_table *opt;
ee065d83
PB
26392 char *name;
26393 char saved_char;
26394
26395 name = input_line_pointer;
5f4273c7 26396 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26397 input_line_pointer++;
26398 saved_char = *input_line_pointer;
26399 *input_line_pointer = 0;
26400
26401 /* Skip the first "all" entry. */
26402 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26403 if (streq (opt->name, name))
26404 {
e74cfd16
PB
26405 mcpu_cpu_opt = &opt->value;
26406 selected_cpu = opt->value;
ee065d83 26407 if (opt->canonical_name)
5f4273c7 26408 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26409 else
26410 {
26411 int i;
26412 for (i = 0; opt->name[i]; i++)
26413 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26414
ee065d83
PB
26415 selected_cpu_name[i] = 0;
26416 }
e74cfd16 26417 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26418 *input_line_pointer = saved_char;
26419 demand_empty_rest_of_line ();
26420 return;
26421 }
26422 as_bad (_("unknown cpu `%s'"), name);
26423 *input_line_pointer = saved_char;
26424 ignore_rest_of_line ();
26425}
26426
26427
26428/* Parse a .arch directive. */
26429
26430static void
26431s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26432{
e74cfd16 26433 const struct arm_arch_option_table *opt;
ee065d83
PB
26434 char saved_char;
26435 char *name;
26436
26437 name = input_line_pointer;
5f4273c7 26438 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26439 input_line_pointer++;
26440 saved_char = *input_line_pointer;
26441 *input_line_pointer = 0;
26442
26443 /* Skip the first "all" entry. */
26444 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26445 if (streq (opt->name, name))
26446 {
e74cfd16
PB
26447 mcpu_cpu_opt = &opt->value;
26448 selected_cpu = opt->value;
5f4273c7 26449 strcpy (selected_cpu_name, opt->name);
e74cfd16 26450 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26451 *input_line_pointer = saved_char;
26452 demand_empty_rest_of_line ();
26453 return;
26454 }
26455
26456 as_bad (_("unknown architecture `%s'\n"), name);
26457 *input_line_pointer = saved_char;
26458 ignore_rest_of_line ();
26459}
26460
26461
7a1d4c38
PB
26462/* Parse a .object_arch directive. */
26463
26464static void
26465s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26466{
26467 const struct arm_arch_option_table *opt;
26468 char saved_char;
26469 char *name;
26470
26471 name = input_line_pointer;
5f4273c7 26472 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26473 input_line_pointer++;
26474 saved_char = *input_line_pointer;
26475 *input_line_pointer = 0;
26476
26477 /* Skip the first "all" entry. */
26478 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26479 if (streq (opt->name, name))
26480 {
26481 object_arch = &opt->value;
26482 *input_line_pointer = saved_char;
26483 demand_empty_rest_of_line ();
26484 return;
26485 }
26486
26487 as_bad (_("unknown architecture `%s'\n"), name);
26488 *input_line_pointer = saved_char;
26489 ignore_rest_of_line ();
26490}
26491
69133863
MGD
26492/* Parse a .arch_extension directive. */
26493
26494static void
26495s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26496{
26497 const struct arm_option_extension_value_table *opt;
d942732e 26498 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26499 char saved_char;
26500 char *name;
26501 int adding_value = 1;
26502
26503 name = input_line_pointer;
26504 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26505 input_line_pointer++;
26506 saved_char = *input_line_pointer;
26507 *input_line_pointer = 0;
26508
26509 if (strlen (name) >= 2
26510 && strncmp (name, "no", 2) == 0)
26511 {
26512 adding_value = 0;
26513 name += 2;
26514 }
26515
26516 for (opt = arm_extensions; opt->name != NULL; opt++)
26517 if (streq (opt->name, name))
26518 {
d942732e
TP
26519 int i, nb_allowed_archs =
26520 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26521 for (i = 0; i < nb_allowed_archs; i++)
26522 {
26523 /* Empty entry. */
26524 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26525 continue;
26526 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26527 break;
26528 }
26529
26530 if (i == nb_allowed_archs)
69133863
MGD
26531 {
26532 as_bad (_("architectural extension `%s' is not allowed for the "
26533 "current base architecture"), name);
26534 break;
26535 }
26536
26537 if (adding_value)
5a70a223
JB
26538 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26539 opt->merge_value);
69133863 26540 else
5a70a223 26541 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26542
26543 mcpu_cpu_opt = &selected_cpu;
26544 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26545 *input_line_pointer = saved_char;
26546 demand_empty_rest_of_line ();
26547 return;
26548 }
26549
26550 if (opt->name == NULL)
e673710a 26551 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26552
26553 *input_line_pointer = saved_char;
26554 ignore_rest_of_line ();
26555}
26556
ee065d83
PB
26557/* Parse a .fpu directive. */
26558
26559static void
26560s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26561{
69133863 26562 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26563 char saved_char;
26564 char *name;
26565
26566 name = input_line_pointer;
5f4273c7 26567 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26568 input_line_pointer++;
26569 saved_char = *input_line_pointer;
26570 *input_line_pointer = 0;
5f4273c7 26571
ee065d83
PB
26572 for (opt = arm_fpus; opt->name != NULL; opt++)
26573 if (streq (opt->name, name))
26574 {
e74cfd16
PB
26575 mfpu_opt = &opt->value;
26576 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26577 *input_line_pointer = saved_char;
26578 demand_empty_rest_of_line ();
26579 return;
26580 }
26581
26582 as_bad (_("unknown floating point format `%s'\n"), name);
26583 *input_line_pointer = saved_char;
26584 ignore_rest_of_line ();
26585}
ee065d83 26586
794ba86a 26587/* Copy symbol information. */
f31fef98 26588
794ba86a
DJ
26589void
26590arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26591{
26592 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26593}
e04befd0 26594
f31fef98 26595#ifdef OBJ_ELF
e04befd0
AS
26596/* Given a symbolic attribute NAME, return the proper integer value.
26597 Returns -1 if the attribute is not known. */
f31fef98 26598
e04befd0
AS
26599int
26600arm_convert_symbolic_attribute (const char *name)
26601{
f31fef98
NC
26602 static const struct
26603 {
26604 const char * name;
26605 const int tag;
26606 }
26607 attribute_table[] =
26608 {
26609 /* When you modify this table you should
26610 also modify the list in doc/c-arm.texi. */
e04befd0 26611#define T(tag) {#tag, tag}
f31fef98
NC
26612 T (Tag_CPU_raw_name),
26613 T (Tag_CPU_name),
26614 T (Tag_CPU_arch),
26615 T (Tag_CPU_arch_profile),
26616 T (Tag_ARM_ISA_use),
26617 T (Tag_THUMB_ISA_use),
75375b3e 26618 T (Tag_FP_arch),
f31fef98
NC
26619 T (Tag_VFP_arch),
26620 T (Tag_WMMX_arch),
26621 T (Tag_Advanced_SIMD_arch),
26622 T (Tag_PCS_config),
26623 T (Tag_ABI_PCS_R9_use),
26624 T (Tag_ABI_PCS_RW_data),
26625 T (Tag_ABI_PCS_RO_data),
26626 T (Tag_ABI_PCS_GOT_use),
26627 T (Tag_ABI_PCS_wchar_t),
26628 T (Tag_ABI_FP_rounding),
26629 T (Tag_ABI_FP_denormal),
26630 T (Tag_ABI_FP_exceptions),
26631 T (Tag_ABI_FP_user_exceptions),
26632 T (Tag_ABI_FP_number_model),
75375b3e 26633 T (Tag_ABI_align_needed),
f31fef98 26634 T (Tag_ABI_align8_needed),
75375b3e 26635 T (Tag_ABI_align_preserved),
f31fef98
NC
26636 T (Tag_ABI_align8_preserved),
26637 T (Tag_ABI_enum_size),
26638 T (Tag_ABI_HardFP_use),
26639 T (Tag_ABI_VFP_args),
26640 T (Tag_ABI_WMMX_args),
26641 T (Tag_ABI_optimization_goals),
26642 T (Tag_ABI_FP_optimization_goals),
26643 T (Tag_compatibility),
26644 T (Tag_CPU_unaligned_access),
75375b3e 26645 T (Tag_FP_HP_extension),
f31fef98
NC
26646 T (Tag_VFP_HP_extension),
26647 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26648 T (Tag_MPextension_use),
26649 T (Tag_DIV_use),
f31fef98
NC
26650 T (Tag_nodefaults),
26651 T (Tag_also_compatible_with),
26652 T (Tag_conformance),
26653 T (Tag_T2EE_use),
26654 T (Tag_Virtualization_use),
15afaa63 26655 T (Tag_DSP_extension),
cd21e546 26656 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26657#undef T
f31fef98 26658 };
e04befd0
AS
26659 unsigned int i;
26660
26661 if (name == NULL)
26662 return -1;
26663
f31fef98 26664 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26665 if (streq (name, attribute_table[i].name))
e04befd0
AS
26666 return attribute_table[i].tag;
26667
26668 return -1;
26669}
267bf995
RR
26670
26671
93ef582d
NC
26672/* Apply sym value for relocations only in the case that they are for
26673 local symbols in the same segment as the fixup and you have the
26674 respective architectural feature for blx and simple switches. */
267bf995 26675int
93ef582d 26676arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26677{
26678 if (fixP->fx_addsy
26679 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26680 /* PR 17444: If the local symbol is in a different section then a reloc
26681 will always be generated for it, so applying the symbol value now
26682 will result in a double offset being stored in the relocation. */
26683 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26684 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26685 {
26686 switch (fixP->fx_r_type)
26687 {
26688 case BFD_RELOC_ARM_PCREL_BLX:
26689 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26690 if (ARM_IS_FUNC (fixP->fx_addsy))
26691 return 1;
26692 break;
26693
26694 case BFD_RELOC_ARM_PCREL_CALL:
26695 case BFD_RELOC_THUMB_PCREL_BLX:
26696 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26697 return 1;
267bf995
RR
26698 break;
26699
26700 default:
26701 break;
26702 }
26703
26704 }
26705 return 0;
26706}
f31fef98 26707#endif /* OBJ_ELF */
This page took 3.915048 seconds and 4 git commands to generate.