]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
b90efa5b 2 Copyright (C) 1994-2015 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;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = 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 =
823d2571
TG
204 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M);
205static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
206static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
207static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
208static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
209static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 210static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
e74cfd16
PB
211
212static const arm_feature_set arm_arch_any = ARM_ANY;
823d2571 213static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
214static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
215static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 216static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 217
2d447fca 218static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 219 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 220static const arm_feature_set arm_cext_iwmmxt =
823d2571 221 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 222static const arm_feature_set arm_cext_xscale =
823d2571 223 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 224static const arm_feature_set arm_cext_maverick =
823d2571
TG
225 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
226static const arm_feature_set fpu_fpa_ext_v1 =
227 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
228static const arm_feature_set fpu_fpa_ext_v2 =
229 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 230static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
231 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
232static const arm_feature_set fpu_vfp_ext_v1 =
233 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
234static const arm_feature_set fpu_vfp_ext_v2 =
235 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
236static const arm_feature_set fpu_vfp_ext_v3xd =
237 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
238static const arm_feature_set fpu_vfp_ext_v3 =
239 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 240static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
241 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
242static const arm_feature_set fpu_neon_ext_v1 =
243 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 244static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
245 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
246static const arm_feature_set fpu_vfp_fp16 =
247 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
248static const arm_feature_set fpu_neon_ext_fma =
249 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
250static const arm_feature_set fpu_vfp_ext_fma =
251 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 252static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 253 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 254static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 255 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 256static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 257 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 258static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 259 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 260static const arm_feature_set crc_ext_armv8 =
823d2571 261 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e
MW
262static const arm_feature_set fpu_neon_ext_v8_1 =
263 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA);
e74cfd16 264
33a392fb 265static int mfloat_abi_opt = -1;
e74cfd16
PB
266/* Record user cpu selection for object attributes. */
267static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 268/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 269static char selected_cpu_name[20];
8d67f500 270
aacf0b33
KT
271extern FLONUM_TYPE generic_floating_point_number;
272
8d67f500
NC
273/* Return if no cpu was selected on command-line. */
274static bfd_boolean
275no_cpu_selected (void)
276{
823d2571 277 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
278}
279
7cc69913 280#ifdef OBJ_ELF
deeaaff8
DJ
281# ifdef EABI_DEFAULT
282static int meabi_flags = EABI_DEFAULT;
283# else
d507cf36 284static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 285# endif
e1da3f5b 286
ee3c0378
AS
287static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
288
e1da3f5b 289bfd_boolean
5f4273c7 290arm_is_eabi (void)
e1da3f5b
PB
291{
292 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
293}
7cc69913 294#endif
b99bd4ef 295
b99bd4ef 296#ifdef OBJ_ELF
c19d1205 297/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
298symbolS * GOT_symbol;
299#endif
300
b99bd4ef
NC
301/* 0: assemble for ARM,
302 1: assemble for Thumb,
303 2: assemble for Thumb even though target CPU does not support thumb
304 instructions. */
305static int thumb_mode = 0;
8dc2430f
NC
306/* A value distinct from the possible values for thumb_mode that we
307 can use to record whether thumb_mode has been copied into the
308 tc_frag_data field of a frag. */
309#define MODE_RECORDED (1 << 4)
b99bd4ef 310
e07e6e58
NC
311/* Specifies the intrinsic IT insn behavior mode. */
312enum implicit_it_mode
313{
314 IMPLICIT_IT_MODE_NEVER = 0x00,
315 IMPLICIT_IT_MODE_ARM = 0x01,
316 IMPLICIT_IT_MODE_THUMB = 0x02,
317 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
318};
319static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
320
c19d1205
ZW
321/* If unified_syntax is true, we are processing the new unified
322 ARM/Thumb syntax. Important differences from the old ARM mode:
323
324 - Immediate operands do not require a # prefix.
325 - Conditional affixes always appear at the end of the
326 instruction. (For backward compatibility, those instructions
327 that formerly had them in the middle, continue to accept them
328 there.)
329 - The IT instruction may appear, and if it does is validated
330 against subsequent conditional affixes. It does not generate
331 machine code.
332
333 Important differences from the old Thumb mode:
334
335 - Immediate operands do not require a # prefix.
336 - Most of the V6T2 instructions are only available in unified mode.
337 - The .N and .W suffixes are recognized and honored (it is an error
338 if they cannot be honored).
339 - All instructions set the flags if and only if they have an 's' affix.
340 - Conditional affixes may be used. They are validated against
341 preceding IT instructions. Unlike ARM mode, you cannot use a
342 conditional affix except in the scope of an IT instruction. */
343
344static bfd_boolean unified_syntax = FALSE;
b99bd4ef 345
bacebabc
RM
346/* An immediate operand can start with #, and ld*, st*, pld operands
347 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
348 before a [, which can appear as the first operand for pld.
349 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
350const char arm_symbol_chars[] = "#[]{}";
bacebabc 351
5287ad62
JB
352enum neon_el_type
353{
dcbf9037 354 NT_invtype,
5287ad62
JB
355 NT_untyped,
356 NT_integer,
357 NT_float,
358 NT_poly,
359 NT_signed,
dcbf9037 360 NT_unsigned
5287ad62
JB
361};
362
363struct neon_type_el
364{
365 enum neon_el_type type;
366 unsigned size;
367};
368
369#define NEON_MAX_TYPE_ELS 4
370
371struct neon_type
372{
373 struct neon_type_el el[NEON_MAX_TYPE_ELS];
374 unsigned elems;
375};
376
e07e6e58
NC
377enum it_instruction_type
378{
379 OUTSIDE_IT_INSN,
380 INSIDE_IT_INSN,
381 INSIDE_IT_LAST_INSN,
382 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 383 if inside, should be the last one. */
e07e6e58 384 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 385 i.e. BKPT and NOP. */
e07e6e58
NC
386 IT_INSN /* The IT insn has been parsed. */
387};
388
ad6cec43
MGD
389/* The maximum number of operands we need. */
390#define ARM_IT_MAX_OPERANDS 6
391
b99bd4ef
NC
392struct arm_it
393{
c19d1205 394 const char * error;
b99bd4ef 395 unsigned long instruction;
c19d1205
ZW
396 int size;
397 int size_req;
398 int cond;
037e8744
JB
399 /* "uncond_value" is set to the value in place of the conditional field in
400 unconditional versions of the instruction, or -1 if nothing is
401 appropriate. */
402 int uncond_value;
5287ad62 403 struct neon_type vectype;
88714cb8
DG
404 /* This does not indicate an actual NEON instruction, only that
405 the mnemonic accepts neon-style type suffixes. */
406 int is_neon;
0110f2b8
PB
407 /* Set to the opcode if the instruction needs relaxation.
408 Zero if the instruction is not relaxed. */
409 unsigned long relax;
b99bd4ef
NC
410 struct
411 {
412 bfd_reloc_code_real_type type;
c19d1205
ZW
413 expressionS exp;
414 int pc_rel;
b99bd4ef 415 } reloc;
b99bd4ef 416
e07e6e58
NC
417 enum it_instruction_type it_insn_type;
418
c19d1205
ZW
419 struct
420 {
421 unsigned reg;
ca3f61f7 422 signed int imm;
dcbf9037 423 struct neon_type_el vectype;
ca3f61f7
NC
424 unsigned present : 1; /* Operand present. */
425 unsigned isreg : 1; /* Operand was a register. */
426 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
427 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
428 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 429 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
430 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
431 instructions. This allows us to disambiguate ARM <-> vector insns. */
432 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 433 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 434 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 435 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
436 unsigned hasreloc : 1; /* Operand has relocation suffix. */
437 unsigned writeback : 1; /* Operand has trailing ! */
438 unsigned preind : 1; /* Preindexed address. */
439 unsigned postind : 1; /* Postindexed address. */
440 unsigned negative : 1; /* Index register was negated. */
441 unsigned shifted : 1; /* Shift applied to operation. */
442 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 443 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
444};
445
c19d1205 446static struct arm_it inst;
b99bd4ef
NC
447
448#define NUM_FLOAT_VALS 8
449
05d2d07e 450const char * fp_const[] =
b99bd4ef
NC
451{
452 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
453};
454
c19d1205 455/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
456#define MAX_LITTLENUMS 6
457
458LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
459
460#define FAIL (-1)
461#define SUCCESS (0)
462
463#define SUFF_S 1
464#define SUFF_D 2
465#define SUFF_E 3
466#define SUFF_P 4
467
c19d1205
ZW
468#define CP_T_X 0x00008000
469#define CP_T_Y 0x00400000
b99bd4ef 470
c19d1205
ZW
471#define CONDS_BIT 0x00100000
472#define LOAD_BIT 0x00100000
b99bd4ef
NC
473
474#define DOUBLE_LOAD_FLAG 0x00000001
475
476struct asm_cond
477{
d3ce72d0 478 const char * template_name;
c921be7d 479 unsigned long value;
b99bd4ef
NC
480};
481
c19d1205 482#define COND_ALWAYS 0xE
b99bd4ef 483
b99bd4ef
NC
484struct asm_psr
485{
d3ce72d0 486 const char * template_name;
c921be7d 487 unsigned long field;
b99bd4ef
NC
488};
489
62b3e311
PB
490struct asm_barrier_opt
491{
e797f7e0
MGD
492 const char * template_name;
493 unsigned long value;
494 const arm_feature_set arch;
62b3e311
PB
495};
496
2d2255b5 497/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
498#define SPSR_BIT (1 << 22)
499
c19d1205
ZW
500/* The individual PSR flag bits. */
501#define PSR_c (1 << 16)
502#define PSR_x (1 << 17)
503#define PSR_s (1 << 18)
504#define PSR_f (1 << 19)
b99bd4ef 505
c19d1205 506struct reloc_entry
bfae80f2 507{
c921be7d
NC
508 char * name;
509 bfd_reloc_code_real_type reloc;
bfae80f2
RE
510};
511
5287ad62 512enum vfp_reg_pos
bfae80f2 513{
5287ad62
JB
514 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
515 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
516};
517
518enum vfp_ldstm_type
519{
520 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
521};
522
dcbf9037
JB
523/* Bits for DEFINED field in neon_typed_alias. */
524#define NTA_HASTYPE 1
525#define NTA_HASINDEX 2
526
527struct neon_typed_alias
528{
c921be7d
NC
529 unsigned char defined;
530 unsigned char index;
531 struct neon_type_el eltype;
dcbf9037
JB
532};
533
c19d1205
ZW
534/* ARM register categories. This includes coprocessor numbers and various
535 architecture extensions' registers. */
536enum arm_reg_type
bfae80f2 537{
c19d1205
ZW
538 REG_TYPE_RN,
539 REG_TYPE_CP,
540 REG_TYPE_CN,
541 REG_TYPE_FN,
542 REG_TYPE_VFS,
543 REG_TYPE_VFD,
5287ad62 544 REG_TYPE_NQ,
037e8744 545 REG_TYPE_VFSD,
5287ad62 546 REG_TYPE_NDQ,
037e8744 547 REG_TYPE_NSDQ,
c19d1205
ZW
548 REG_TYPE_VFC,
549 REG_TYPE_MVF,
550 REG_TYPE_MVD,
551 REG_TYPE_MVFX,
552 REG_TYPE_MVDX,
553 REG_TYPE_MVAX,
554 REG_TYPE_DSPSC,
555 REG_TYPE_MMXWR,
556 REG_TYPE_MMXWC,
557 REG_TYPE_MMXWCG,
558 REG_TYPE_XSCALE,
90ec0d68 559 REG_TYPE_RNB
bfae80f2
RE
560};
561
dcbf9037
JB
562/* Structure for a hash table entry for a register.
563 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
564 information which states whether a vector type or index is specified (for a
565 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
566struct reg_entry
567{
c921be7d 568 const char * name;
90ec0d68 569 unsigned int number;
c921be7d
NC
570 unsigned char type;
571 unsigned char builtin;
572 struct neon_typed_alias * neon;
6c43fab6
RE
573};
574
c19d1205 575/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 576const char * const reg_expected_msgs[] =
c19d1205
ZW
577{
578 N_("ARM register expected"),
579 N_("bad or missing co-processor number"),
580 N_("co-processor register expected"),
581 N_("FPA register expected"),
582 N_("VFP single precision register expected"),
5287ad62
JB
583 N_("VFP/Neon double precision register expected"),
584 N_("Neon quad precision register expected"),
037e8744 585 N_("VFP single or double precision register expected"),
5287ad62 586 N_("Neon double or quad precision register expected"),
037e8744 587 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
588 N_("VFP system register expected"),
589 N_("Maverick MVF register expected"),
590 N_("Maverick MVD register expected"),
591 N_("Maverick MVFX register expected"),
592 N_("Maverick MVDX register expected"),
593 N_("Maverick MVAX register expected"),
594 N_("Maverick DSPSC register expected"),
595 N_("iWMMXt data register expected"),
596 N_("iWMMXt control register expected"),
597 N_("iWMMXt scalar register expected"),
598 N_("XScale accumulator register expected"),
6c43fab6
RE
599};
600
c19d1205 601/* Some well known registers that we refer to directly elsewhere. */
bd340a04 602#define REG_R12 12
c19d1205
ZW
603#define REG_SP 13
604#define REG_LR 14
605#define REG_PC 15
404ff6b5 606
b99bd4ef
NC
607/* ARM instructions take 4bytes in the object file, Thumb instructions
608 take 2: */
c19d1205 609#define INSN_SIZE 4
b99bd4ef
NC
610
611struct asm_opcode
612{
613 /* Basic string to match. */
d3ce72d0 614 const char * template_name;
c19d1205
ZW
615
616 /* Parameters to instruction. */
5be8be5d 617 unsigned int operands[8];
c19d1205
ZW
618
619 /* Conditional tag - see opcode_lookup. */
620 unsigned int tag : 4;
b99bd4ef
NC
621
622 /* Basic instruction code. */
c19d1205 623 unsigned int avalue : 28;
b99bd4ef 624
c19d1205
ZW
625 /* Thumb-format instruction code. */
626 unsigned int tvalue;
b99bd4ef 627
90e4755a 628 /* Which architecture variant provides this instruction. */
c921be7d
NC
629 const arm_feature_set * avariant;
630 const arm_feature_set * tvariant;
c19d1205
ZW
631
632 /* Function to call to encode instruction in ARM format. */
633 void (* aencode) (void);
b99bd4ef 634
c19d1205
ZW
635 /* Function to call to encode instruction in Thumb format. */
636 void (* tencode) (void);
b99bd4ef
NC
637};
638
a737bd4d
NC
639/* Defines for various bits that we will want to toggle. */
640#define INST_IMMEDIATE 0x02000000
641#define OFFSET_REG 0x02000000
c19d1205 642#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
643#define SHIFT_BY_REG 0x00000010
644#define PRE_INDEX 0x01000000
645#define INDEX_UP 0x00800000
646#define WRITE_BACK 0x00200000
647#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 648#define CPSI_MMOD 0x00020000
90e4755a 649
a737bd4d
NC
650#define LITERAL_MASK 0xf000f000
651#define OPCODE_MASK 0xfe1fffff
652#define V4_STR_BIT 0x00000020
8335d6aa 653#define VLDR_VMOV_SAME 0x0040f000
90e4755a 654
efd81785
PB
655#define T2_SUBS_PC_LR 0xf3de8f00
656
a737bd4d 657#define DATA_OP_SHIFT 21
90e4755a 658
ef8d22e6
PB
659#define T2_OPCODE_MASK 0xfe1fffff
660#define T2_DATA_OP_SHIFT 21
661
6530b175
NC
662#define A_COND_MASK 0xf0000000
663#define A_PUSH_POP_OP_MASK 0x0fff0000
664
665/* Opcodes for pushing/poping registers to/from the stack. */
666#define A1_OPCODE_PUSH 0x092d0000
667#define A2_OPCODE_PUSH 0x052d0004
668#define A2_OPCODE_POP 0x049d0004
669
a737bd4d
NC
670/* Codes to distinguish the arithmetic instructions. */
671#define OPCODE_AND 0
672#define OPCODE_EOR 1
673#define OPCODE_SUB 2
674#define OPCODE_RSB 3
675#define OPCODE_ADD 4
676#define OPCODE_ADC 5
677#define OPCODE_SBC 6
678#define OPCODE_RSC 7
679#define OPCODE_TST 8
680#define OPCODE_TEQ 9
681#define OPCODE_CMP 10
682#define OPCODE_CMN 11
683#define OPCODE_ORR 12
684#define OPCODE_MOV 13
685#define OPCODE_BIC 14
686#define OPCODE_MVN 15
90e4755a 687
ef8d22e6
PB
688#define T2_OPCODE_AND 0
689#define T2_OPCODE_BIC 1
690#define T2_OPCODE_ORR 2
691#define T2_OPCODE_ORN 3
692#define T2_OPCODE_EOR 4
693#define T2_OPCODE_ADD 8
694#define T2_OPCODE_ADC 10
695#define T2_OPCODE_SBC 11
696#define T2_OPCODE_SUB 13
697#define T2_OPCODE_RSB 14
698
a737bd4d
NC
699#define T_OPCODE_MUL 0x4340
700#define T_OPCODE_TST 0x4200
701#define T_OPCODE_CMN 0x42c0
702#define T_OPCODE_NEG 0x4240
703#define T_OPCODE_MVN 0x43c0
90e4755a 704
a737bd4d
NC
705#define T_OPCODE_ADD_R3 0x1800
706#define T_OPCODE_SUB_R3 0x1a00
707#define T_OPCODE_ADD_HI 0x4400
708#define T_OPCODE_ADD_ST 0xb000
709#define T_OPCODE_SUB_ST 0xb080
710#define T_OPCODE_ADD_SP 0xa800
711#define T_OPCODE_ADD_PC 0xa000
712#define T_OPCODE_ADD_I8 0x3000
713#define T_OPCODE_SUB_I8 0x3800
714#define T_OPCODE_ADD_I3 0x1c00
715#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 716
a737bd4d
NC
717#define T_OPCODE_ASR_R 0x4100
718#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
719#define T_OPCODE_LSR_R 0x40c0
720#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
721#define T_OPCODE_ASR_I 0x1000
722#define T_OPCODE_LSL_I 0x0000
723#define T_OPCODE_LSR_I 0x0800
b99bd4ef 724
a737bd4d
NC
725#define T_OPCODE_MOV_I8 0x2000
726#define T_OPCODE_CMP_I8 0x2800
727#define T_OPCODE_CMP_LR 0x4280
728#define T_OPCODE_MOV_HR 0x4600
729#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 730
a737bd4d
NC
731#define T_OPCODE_LDR_PC 0x4800
732#define T_OPCODE_LDR_SP 0x9800
733#define T_OPCODE_STR_SP 0x9000
734#define T_OPCODE_LDR_IW 0x6800
735#define T_OPCODE_STR_IW 0x6000
736#define T_OPCODE_LDR_IH 0x8800
737#define T_OPCODE_STR_IH 0x8000
738#define T_OPCODE_LDR_IB 0x7800
739#define T_OPCODE_STR_IB 0x7000
740#define T_OPCODE_LDR_RW 0x5800
741#define T_OPCODE_STR_RW 0x5000
742#define T_OPCODE_LDR_RH 0x5a00
743#define T_OPCODE_STR_RH 0x5200
744#define T_OPCODE_LDR_RB 0x5c00
745#define T_OPCODE_STR_RB 0x5400
c9b604bd 746
a737bd4d
NC
747#define T_OPCODE_PUSH 0xb400
748#define T_OPCODE_POP 0xbc00
b99bd4ef 749
2fc8bdac 750#define T_OPCODE_BRANCH 0xe000
b99bd4ef 751
a737bd4d 752#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 753#define THUMB_PP_PC_LR 0x0100
c19d1205 754#define THUMB_LOAD_BIT 0x0800
53365c0d 755#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
756
757#define BAD_ARGS _("bad arguments to instruction")
fdfde340 758#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
759#define BAD_PC _("r15 not allowed here")
760#define BAD_COND _("instruction cannot be conditional")
761#define BAD_OVERLAP _("registers may not be the same")
762#define BAD_HIREG _("lo register required")
763#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 764#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
765#define BAD_BRANCH _("branch must be last instruction in IT block")
766#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 767#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
768#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
769#define BAD_IT_COND _("incorrect condition in IT block")
770#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 771#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
772#define BAD_PC_ADDRESSING \
773 _("cannot use register index with PC-relative addressing")
774#define BAD_PC_WRITEBACK \
775 _("cannot use writeback with PC-relative addressing")
08f10d51 776#define BAD_RANGE _("branch out of range")
dd5181d5 777#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 778
c921be7d
NC
779static struct hash_control * arm_ops_hsh;
780static struct hash_control * arm_cond_hsh;
781static struct hash_control * arm_shift_hsh;
782static struct hash_control * arm_psr_hsh;
783static struct hash_control * arm_v7m_psr_hsh;
784static struct hash_control * arm_reg_hsh;
785static struct hash_control * arm_reloc_hsh;
786static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 787
b99bd4ef
NC
788/* Stuff needed to resolve the label ambiguity
789 As:
790 ...
791 label: <insn>
792 may differ from:
793 ...
794 label:
5f4273c7 795 <insn> */
b99bd4ef
NC
796
797symbolS * last_label_seen;
b34976b6 798static int label_is_thumb_function_name = FALSE;
e07e6e58 799
3d0c9500
NC
800/* Literal pool structure. Held on a per-section
801 and per-sub-section basis. */
a737bd4d 802
c19d1205 803#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 804typedef struct literal_pool
b99bd4ef 805{
c921be7d
NC
806 expressionS literals [MAX_LITERAL_POOL_SIZE];
807 unsigned int next_free_entry;
808 unsigned int id;
809 symbolS * symbol;
810 segT section;
811 subsegT sub_section;
a8040cf2
NC
812#ifdef OBJ_ELF
813 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
814#endif
c921be7d 815 struct literal_pool * next;
8335d6aa 816 unsigned int alignment;
3d0c9500 817} literal_pool;
b99bd4ef 818
3d0c9500
NC
819/* Pointer to a linked list of literal pools. */
820literal_pool * list_of_pools = NULL;
e27ec89e 821
2e6976a8
DG
822typedef enum asmfunc_states
823{
824 OUTSIDE_ASMFUNC,
825 WAITING_ASMFUNC_NAME,
826 WAITING_ENDASMFUNC
827} asmfunc_states;
828
829static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
830
e07e6e58
NC
831#ifdef OBJ_ELF
832# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
833#else
834static struct current_it now_it;
835#endif
836
837static inline int
838now_it_compatible (int cond)
839{
840 return (cond & ~1) == (now_it.cc & ~1);
841}
842
843static inline int
844conditional_insn (void)
845{
846 return inst.cond != COND_ALWAYS;
847}
848
849static int in_it_block (void);
850
851static int handle_it_state (void);
852
853static void force_automatic_it_block_close (void);
854
c921be7d
NC
855static void it_fsm_post_encode (void);
856
e07e6e58
NC
857#define set_it_insn_type(type) \
858 do \
859 { \
860 inst.it_insn_type = type; \
861 if (handle_it_state () == FAIL) \
477330fc 862 return; \
e07e6e58
NC
863 } \
864 while (0)
865
c921be7d
NC
866#define set_it_insn_type_nonvoid(type, failret) \
867 do \
868 { \
869 inst.it_insn_type = type; \
870 if (handle_it_state () == FAIL) \
477330fc 871 return failret; \
c921be7d
NC
872 } \
873 while(0)
874
e07e6e58
NC
875#define set_it_insn_type_last() \
876 do \
877 { \
878 if (inst.cond == COND_ALWAYS) \
477330fc 879 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 880 else \
477330fc 881 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
882 } \
883 while (0)
884
c19d1205 885/* Pure syntax. */
b99bd4ef 886
c19d1205
ZW
887/* This array holds the chars that always start a comment. If the
888 pre-processor is disabled, these aren't very useful. */
2e6976a8 889char arm_comment_chars[] = "@";
3d0c9500 890
c19d1205
ZW
891/* This array holds the chars that only start a comment at the beginning of
892 a line. If the line seems to have the form '# 123 filename'
893 .line and .file directives will appear in the pre-processed output. */
894/* Note that input_file.c hand checks for '#' at the beginning of the
895 first line of the input file. This is because the compiler outputs
896 #NO_APP at the beginning of its output. */
897/* Also note that comments like this one will always work. */
898const char line_comment_chars[] = "#";
3d0c9500 899
2e6976a8 900char arm_line_separator_chars[] = ";";
b99bd4ef 901
c19d1205
ZW
902/* Chars that can be used to separate mant
903 from exp in floating point numbers. */
904const char EXP_CHARS[] = "eE";
3d0c9500 905
c19d1205
ZW
906/* Chars that mean this number is a floating point constant. */
907/* As in 0f12.456 */
908/* or 0d1.2345e12 */
b99bd4ef 909
c19d1205 910const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 911
c19d1205
ZW
912/* Prefix characters that indicate the start of an immediate
913 value. */
914#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 915
c19d1205
ZW
916/* Separator character handling. */
917
918#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
919
920static inline int
921skip_past_char (char ** str, char c)
922{
8ab8155f
NC
923 /* PR gas/14987: Allow for whitespace before the expected character. */
924 skip_whitespace (*str);
427d0db6 925
c19d1205
ZW
926 if (**str == c)
927 {
928 (*str)++;
929 return SUCCESS;
3d0c9500 930 }
c19d1205
ZW
931 else
932 return FAIL;
933}
c921be7d 934
c19d1205 935#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 936
c19d1205
ZW
937/* Arithmetic expressions (possibly involving symbols). */
938
939/* Return TRUE if anything in the expression is a bignum. */
940
941static int
942walk_no_bignums (symbolS * sp)
943{
944 if (symbol_get_value_expression (sp)->X_op == O_big)
945 return 1;
946
947 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 948 {
c19d1205
ZW
949 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
950 || (symbol_get_value_expression (sp)->X_op_symbol
951 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
952 }
953
c19d1205 954 return 0;
3d0c9500
NC
955}
956
c19d1205
ZW
957static int in_my_get_expression = 0;
958
959/* Third argument to my_get_expression. */
960#define GE_NO_PREFIX 0
961#define GE_IMM_PREFIX 1
962#define GE_OPT_PREFIX 2
5287ad62
JB
963/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
964 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
965#define GE_OPT_PREFIX_BIG 3
a737bd4d 966
b99bd4ef 967static int
c19d1205 968my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 969{
c19d1205
ZW
970 char * save_in;
971 segT seg;
b99bd4ef 972
c19d1205
ZW
973 /* In unified syntax, all prefixes are optional. */
974 if (unified_syntax)
5287ad62 975 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 976 : GE_OPT_PREFIX;
b99bd4ef 977
c19d1205 978 switch (prefix_mode)
b99bd4ef 979 {
c19d1205
ZW
980 case GE_NO_PREFIX: break;
981 case GE_IMM_PREFIX:
982 if (!is_immediate_prefix (**str))
983 {
984 inst.error = _("immediate expression requires a # prefix");
985 return FAIL;
986 }
987 (*str)++;
988 break;
989 case GE_OPT_PREFIX:
5287ad62 990 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
991 if (is_immediate_prefix (**str))
992 (*str)++;
993 break;
994 default: abort ();
995 }
b99bd4ef 996
c19d1205 997 memset (ep, 0, sizeof (expressionS));
b99bd4ef 998
c19d1205
ZW
999 save_in = input_line_pointer;
1000 input_line_pointer = *str;
1001 in_my_get_expression = 1;
1002 seg = expression (ep);
1003 in_my_get_expression = 0;
1004
f86adc07 1005 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1006 {
f86adc07 1007 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1008 *str = input_line_pointer;
1009 input_line_pointer = save_in;
1010 if (inst.error == NULL)
f86adc07
NS
1011 inst.error = (ep->X_op == O_absent
1012 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1013 return 1;
1014 }
b99bd4ef 1015
c19d1205
ZW
1016#ifdef OBJ_AOUT
1017 if (seg != absolute_section
1018 && seg != text_section
1019 && seg != data_section
1020 && seg != bss_section
1021 && seg != undefined_section)
1022 {
1023 inst.error = _("bad segment");
1024 *str = input_line_pointer;
1025 input_line_pointer = save_in;
1026 return 1;
b99bd4ef 1027 }
87975d2a
AM
1028#else
1029 (void) seg;
c19d1205 1030#endif
b99bd4ef 1031
c19d1205
ZW
1032 /* Get rid of any bignums now, so that we don't generate an error for which
1033 we can't establish a line number later on. Big numbers are never valid
1034 in instructions, which is where this routine is always called. */
5287ad62
JB
1035 if (prefix_mode != GE_OPT_PREFIX_BIG
1036 && (ep->X_op == O_big
477330fc 1037 || (ep->X_add_symbol
5287ad62 1038 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1039 || (ep->X_op_symbol
5287ad62 1040 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1041 {
1042 inst.error = _("invalid constant");
1043 *str = input_line_pointer;
1044 input_line_pointer = save_in;
1045 return 1;
1046 }
b99bd4ef 1047
c19d1205
ZW
1048 *str = input_line_pointer;
1049 input_line_pointer = save_in;
1050 return 0;
b99bd4ef
NC
1051}
1052
c19d1205
ZW
1053/* Turn a string in input_line_pointer into a floating point constant
1054 of type TYPE, and store the appropriate bytes in *LITP. The number
1055 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1056 returned, or NULL on OK.
b99bd4ef 1057
c19d1205
ZW
1058 Note that fp constants aren't represent in the normal way on the ARM.
1059 In big endian mode, things are as expected. However, in little endian
1060 mode fp constants are big-endian word-wise, and little-endian byte-wise
1061 within the words. For example, (double) 1.1 in big endian mode is
1062 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1063 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1064
c19d1205 1065 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1066
c19d1205
ZW
1067char *
1068md_atof (int type, char * litP, int * sizeP)
1069{
1070 int prec;
1071 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1072 char *t;
1073 int i;
b99bd4ef 1074
c19d1205
ZW
1075 switch (type)
1076 {
1077 case 'f':
1078 case 'F':
1079 case 's':
1080 case 'S':
1081 prec = 2;
1082 break;
b99bd4ef 1083
c19d1205
ZW
1084 case 'd':
1085 case 'D':
1086 case 'r':
1087 case 'R':
1088 prec = 4;
1089 break;
b99bd4ef 1090
c19d1205
ZW
1091 case 'x':
1092 case 'X':
499ac353 1093 prec = 5;
c19d1205 1094 break;
b99bd4ef 1095
c19d1205
ZW
1096 case 'p':
1097 case 'P':
499ac353 1098 prec = 5;
c19d1205 1099 break;
a737bd4d 1100
c19d1205
ZW
1101 default:
1102 *sizeP = 0;
499ac353 1103 return _("Unrecognized or unsupported floating point constant");
c19d1205 1104 }
b99bd4ef 1105
c19d1205
ZW
1106 t = atof_ieee (input_line_pointer, type, words);
1107 if (t)
1108 input_line_pointer = t;
499ac353 1109 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1110
c19d1205
ZW
1111 if (target_big_endian)
1112 {
1113 for (i = 0; i < prec; i++)
1114 {
499ac353
NC
1115 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1116 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1117 }
1118 }
1119 else
1120 {
e74cfd16 1121 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1122 for (i = prec - 1; i >= 0; i--)
1123 {
499ac353
NC
1124 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1125 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1126 }
1127 else
1128 /* For a 4 byte float the order of elements in `words' is 1 0.
1129 For an 8 byte float the order is 1 0 3 2. */
1130 for (i = 0; i < prec; i += 2)
1131 {
499ac353
NC
1132 md_number_to_chars (litP, (valueT) words[i + 1],
1133 sizeof (LITTLENUM_TYPE));
1134 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1135 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1136 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1137 }
1138 }
b99bd4ef 1139
499ac353 1140 return NULL;
c19d1205 1141}
b99bd4ef 1142
c19d1205
ZW
1143/* We handle all bad expressions here, so that we can report the faulty
1144 instruction in the error message. */
1145void
91d6fa6a 1146md_operand (expressionS * exp)
c19d1205
ZW
1147{
1148 if (in_my_get_expression)
91d6fa6a 1149 exp->X_op = O_illegal;
b99bd4ef
NC
1150}
1151
c19d1205 1152/* Immediate values. */
b99bd4ef 1153
c19d1205
ZW
1154/* Generic immediate-value read function for use in directives.
1155 Accepts anything that 'expression' can fold to a constant.
1156 *val receives the number. */
1157#ifdef OBJ_ELF
1158static int
1159immediate_for_directive (int *val)
b99bd4ef 1160{
c19d1205
ZW
1161 expressionS exp;
1162 exp.X_op = O_illegal;
b99bd4ef 1163
c19d1205
ZW
1164 if (is_immediate_prefix (*input_line_pointer))
1165 {
1166 input_line_pointer++;
1167 expression (&exp);
1168 }
b99bd4ef 1169
c19d1205
ZW
1170 if (exp.X_op != O_constant)
1171 {
1172 as_bad (_("expected #constant"));
1173 ignore_rest_of_line ();
1174 return FAIL;
1175 }
1176 *val = exp.X_add_number;
1177 return SUCCESS;
b99bd4ef 1178}
c19d1205 1179#endif
b99bd4ef 1180
c19d1205 1181/* Register parsing. */
b99bd4ef 1182
c19d1205
ZW
1183/* Generic register parser. CCP points to what should be the
1184 beginning of a register name. If it is indeed a valid register
1185 name, advance CCP over it and return the reg_entry structure;
1186 otherwise return NULL. Does not issue diagnostics. */
1187
1188static struct reg_entry *
1189arm_reg_parse_multi (char **ccp)
b99bd4ef 1190{
c19d1205
ZW
1191 char *start = *ccp;
1192 char *p;
1193 struct reg_entry *reg;
b99bd4ef 1194
477330fc
RM
1195 skip_whitespace (start);
1196
c19d1205
ZW
1197#ifdef REGISTER_PREFIX
1198 if (*start != REGISTER_PREFIX)
01cfc07f 1199 return NULL;
c19d1205
ZW
1200 start++;
1201#endif
1202#ifdef OPTIONAL_REGISTER_PREFIX
1203 if (*start == OPTIONAL_REGISTER_PREFIX)
1204 start++;
1205#endif
b99bd4ef 1206
c19d1205
ZW
1207 p = start;
1208 if (!ISALPHA (*p) || !is_name_beginner (*p))
1209 return NULL;
b99bd4ef 1210
c19d1205
ZW
1211 do
1212 p++;
1213 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1214
1215 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1216
1217 if (!reg)
1218 return NULL;
1219
1220 *ccp = p;
1221 return reg;
b99bd4ef
NC
1222}
1223
1224static int
dcbf9037 1225arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1226 enum arm_reg_type type)
b99bd4ef 1227{
c19d1205
ZW
1228 /* Alternative syntaxes are accepted for a few register classes. */
1229 switch (type)
1230 {
1231 case REG_TYPE_MVF:
1232 case REG_TYPE_MVD:
1233 case REG_TYPE_MVFX:
1234 case REG_TYPE_MVDX:
1235 /* Generic coprocessor register names are allowed for these. */
79134647 1236 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1237 return reg->number;
1238 break;
69b97547 1239
c19d1205
ZW
1240 case REG_TYPE_CP:
1241 /* For backward compatibility, a bare number is valid here. */
1242 {
1243 unsigned long processor = strtoul (start, ccp, 10);
1244 if (*ccp != start && processor <= 15)
1245 return processor;
1246 }
6057a28f 1247
c19d1205
ZW
1248 case REG_TYPE_MMXWC:
1249 /* WC includes WCG. ??? I'm not sure this is true for all
1250 instructions that take WC registers. */
79134647 1251 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1252 return reg->number;
6057a28f 1253 break;
c19d1205 1254
6057a28f 1255 default:
c19d1205 1256 break;
6057a28f
NC
1257 }
1258
dcbf9037
JB
1259 return FAIL;
1260}
1261
1262/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1263 return value is the register number or FAIL. */
1264
1265static int
1266arm_reg_parse (char **ccp, enum arm_reg_type type)
1267{
1268 char *start = *ccp;
1269 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1270 int ret;
1271
1272 /* Do not allow a scalar (reg+index) to parse as a register. */
1273 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1274 return FAIL;
1275
1276 if (reg && reg->type == type)
1277 return reg->number;
1278
1279 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1280 return ret;
1281
c19d1205
ZW
1282 *ccp = start;
1283 return FAIL;
1284}
69b97547 1285
dcbf9037
JB
1286/* Parse a Neon type specifier. *STR should point at the leading '.'
1287 character. Does no verification at this stage that the type fits the opcode
1288 properly. E.g.,
1289
1290 .i32.i32.s16
1291 .s32.f32
1292 .u16
1293
1294 Can all be legally parsed by this function.
1295
1296 Fills in neon_type struct pointer with parsed information, and updates STR
1297 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1298 type, FAIL if not. */
1299
1300static int
1301parse_neon_type (struct neon_type *type, char **str)
1302{
1303 char *ptr = *str;
1304
1305 if (type)
1306 type->elems = 0;
1307
1308 while (type->elems < NEON_MAX_TYPE_ELS)
1309 {
1310 enum neon_el_type thistype = NT_untyped;
1311 unsigned thissize = -1u;
1312
1313 if (*ptr != '.')
1314 break;
1315
1316 ptr++;
1317
1318 /* Just a size without an explicit type. */
1319 if (ISDIGIT (*ptr))
1320 goto parsesize;
1321
1322 switch (TOLOWER (*ptr))
1323 {
1324 case 'i': thistype = NT_integer; break;
1325 case 'f': thistype = NT_float; break;
1326 case 'p': thistype = NT_poly; break;
1327 case 's': thistype = NT_signed; break;
1328 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1329 case 'd':
1330 thistype = NT_float;
1331 thissize = 64;
1332 ptr++;
1333 goto done;
dcbf9037
JB
1334 default:
1335 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1336 return FAIL;
1337 }
1338
1339 ptr++;
1340
1341 /* .f is an abbreviation for .f32. */
1342 if (thistype == NT_float && !ISDIGIT (*ptr))
1343 thissize = 32;
1344 else
1345 {
1346 parsesize:
1347 thissize = strtoul (ptr, &ptr, 10);
1348
1349 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1350 && thissize != 64)
1351 {
1352 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1353 return FAIL;
1354 }
1355 }
1356
037e8744 1357 done:
dcbf9037 1358 if (type)
477330fc
RM
1359 {
1360 type->el[type->elems].type = thistype;
dcbf9037
JB
1361 type->el[type->elems].size = thissize;
1362 type->elems++;
1363 }
1364 }
1365
1366 /* Empty/missing type is not a successful parse. */
1367 if (type->elems == 0)
1368 return FAIL;
1369
1370 *str = ptr;
1371
1372 return SUCCESS;
1373}
1374
1375/* Errors may be set multiple times during parsing or bit encoding
1376 (particularly in the Neon bits), but usually the earliest error which is set
1377 will be the most meaningful. Avoid overwriting it with later (cascading)
1378 errors by calling this function. */
1379
1380static void
1381first_error (const char *err)
1382{
1383 if (!inst.error)
1384 inst.error = err;
1385}
1386
1387/* Parse a single type, e.g. ".s32", leading period included. */
1388static int
1389parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1390{
1391 char *str = *ccp;
1392 struct neon_type optype;
1393
1394 if (*str == '.')
1395 {
1396 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1397 {
1398 if (optype.elems == 1)
1399 *vectype = optype.el[0];
1400 else
1401 {
1402 first_error (_("only one type should be specified for operand"));
1403 return FAIL;
1404 }
1405 }
dcbf9037 1406 else
477330fc
RM
1407 {
1408 first_error (_("vector type expected"));
1409 return FAIL;
1410 }
dcbf9037
JB
1411 }
1412 else
1413 return FAIL;
5f4273c7 1414
dcbf9037 1415 *ccp = str;
5f4273c7 1416
dcbf9037
JB
1417 return SUCCESS;
1418}
1419
1420/* Special meanings for indices (which have a range of 0-7), which will fit into
1421 a 4-bit integer. */
1422
1423#define NEON_ALL_LANES 15
1424#define NEON_INTERLEAVE_LANES 14
1425
1426/* Parse either a register or a scalar, with an optional type. Return the
1427 register number, and optionally fill in the actual type of the register
1428 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1429 type/index information in *TYPEINFO. */
1430
1431static int
1432parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1433 enum arm_reg_type *rtype,
1434 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1435{
1436 char *str = *ccp;
1437 struct reg_entry *reg = arm_reg_parse_multi (&str);
1438 struct neon_typed_alias atype;
1439 struct neon_type_el parsetype;
1440
1441 atype.defined = 0;
1442 atype.index = -1;
1443 atype.eltype.type = NT_invtype;
1444 atype.eltype.size = -1;
1445
1446 /* Try alternate syntax for some types of register. Note these are mutually
1447 exclusive with the Neon syntax extensions. */
1448 if (reg == NULL)
1449 {
1450 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1451 if (altreg != FAIL)
477330fc 1452 *ccp = str;
dcbf9037 1453 if (typeinfo)
477330fc 1454 *typeinfo = atype;
dcbf9037
JB
1455 return altreg;
1456 }
1457
037e8744
JB
1458 /* Undo polymorphism when a set of register types may be accepted. */
1459 if ((type == REG_TYPE_NDQ
1460 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1461 || (type == REG_TYPE_VFSD
477330fc 1462 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1463 || (type == REG_TYPE_NSDQ
477330fc
RM
1464 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1465 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1466 || (type == REG_TYPE_MMXWC
1467 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1468 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1469
1470 if (type != reg->type)
1471 return FAIL;
1472
1473 if (reg->neon)
1474 atype = *reg->neon;
5f4273c7 1475
dcbf9037
JB
1476 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1477 {
1478 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1479 {
1480 first_error (_("can't redefine type for operand"));
1481 return FAIL;
1482 }
dcbf9037
JB
1483 atype.defined |= NTA_HASTYPE;
1484 atype.eltype = parsetype;
1485 }
5f4273c7 1486
dcbf9037
JB
1487 if (skip_past_char (&str, '[') == SUCCESS)
1488 {
1489 if (type != REG_TYPE_VFD)
477330fc
RM
1490 {
1491 first_error (_("only D registers may be indexed"));
1492 return FAIL;
1493 }
5f4273c7 1494
dcbf9037 1495 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1496 {
1497 first_error (_("can't change index for operand"));
1498 return FAIL;
1499 }
dcbf9037
JB
1500
1501 atype.defined |= NTA_HASINDEX;
1502
1503 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1504 atype.index = NEON_ALL_LANES;
dcbf9037 1505 else
477330fc
RM
1506 {
1507 expressionS exp;
dcbf9037 1508
477330fc 1509 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1510
477330fc
RM
1511 if (exp.X_op != O_constant)
1512 {
1513 first_error (_("constant expression required"));
1514 return FAIL;
1515 }
dcbf9037 1516
477330fc
RM
1517 if (skip_past_char (&str, ']') == FAIL)
1518 return FAIL;
dcbf9037 1519
477330fc
RM
1520 atype.index = exp.X_add_number;
1521 }
dcbf9037 1522 }
5f4273c7 1523
dcbf9037
JB
1524 if (typeinfo)
1525 *typeinfo = atype;
5f4273c7 1526
dcbf9037
JB
1527 if (rtype)
1528 *rtype = type;
5f4273c7 1529
dcbf9037 1530 *ccp = str;
5f4273c7 1531
dcbf9037
JB
1532 return reg->number;
1533}
1534
1535/* Like arm_reg_parse, but allow allow the following extra features:
1536 - If RTYPE is non-zero, return the (possibly restricted) type of the
1537 register (e.g. Neon double or quad reg when either has been requested).
1538 - If this is a Neon vector type with additional type information, fill
1539 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1540 This function will fault on encountering a scalar. */
dcbf9037
JB
1541
1542static int
1543arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1544 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1545{
1546 struct neon_typed_alias atype;
1547 char *str = *ccp;
1548 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1549
1550 if (reg == FAIL)
1551 return FAIL;
1552
0855e32b
NS
1553 /* Do not allow regname(... to parse as a register. */
1554 if (*str == '(')
1555 return FAIL;
1556
dcbf9037
JB
1557 /* Do not allow a scalar (reg+index) to parse as a register. */
1558 if ((atype.defined & NTA_HASINDEX) != 0)
1559 {
1560 first_error (_("register operand expected, but got scalar"));
1561 return FAIL;
1562 }
1563
1564 if (vectype)
1565 *vectype = atype.eltype;
1566
1567 *ccp = str;
1568
1569 return reg;
1570}
1571
1572#define NEON_SCALAR_REG(X) ((X) >> 4)
1573#define NEON_SCALAR_INDEX(X) ((X) & 15)
1574
5287ad62
JB
1575/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1576 have enough information to be able to do a good job bounds-checking. So, we
1577 just do easy checks here, and do further checks later. */
1578
1579static int
dcbf9037 1580parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1581{
dcbf9037 1582 int reg;
5287ad62 1583 char *str = *ccp;
dcbf9037 1584 struct neon_typed_alias atype;
5f4273c7 1585
dcbf9037 1586 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1587
dcbf9037 1588 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1589 return FAIL;
5f4273c7 1590
dcbf9037 1591 if (atype.index == NEON_ALL_LANES)
5287ad62 1592 {
dcbf9037 1593 first_error (_("scalar must have an index"));
5287ad62
JB
1594 return FAIL;
1595 }
dcbf9037 1596 else if (atype.index >= 64 / elsize)
5287ad62 1597 {
dcbf9037 1598 first_error (_("scalar index out of range"));
5287ad62
JB
1599 return FAIL;
1600 }
5f4273c7 1601
dcbf9037
JB
1602 if (type)
1603 *type = atype.eltype;
5f4273c7 1604
5287ad62 1605 *ccp = str;
5f4273c7 1606
dcbf9037 1607 return reg * 16 + atype.index;
5287ad62
JB
1608}
1609
c19d1205 1610/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1611
c19d1205
ZW
1612static long
1613parse_reg_list (char ** strp)
1614{
1615 char * str = * strp;
1616 long range = 0;
1617 int another_range;
a737bd4d 1618
c19d1205
ZW
1619 /* We come back here if we get ranges concatenated by '+' or '|'. */
1620 do
6057a28f 1621 {
477330fc
RM
1622 skip_whitespace (str);
1623
c19d1205 1624 another_range = 0;
a737bd4d 1625
c19d1205
ZW
1626 if (*str == '{')
1627 {
1628 int in_range = 0;
1629 int cur_reg = -1;
a737bd4d 1630
c19d1205
ZW
1631 str++;
1632 do
1633 {
1634 int reg;
6057a28f 1635
dcbf9037 1636 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1637 {
dcbf9037 1638 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1639 return FAIL;
1640 }
a737bd4d 1641
c19d1205
ZW
1642 if (in_range)
1643 {
1644 int i;
a737bd4d 1645
c19d1205
ZW
1646 if (reg <= cur_reg)
1647 {
dcbf9037 1648 first_error (_("bad range in register list"));
c19d1205
ZW
1649 return FAIL;
1650 }
40a18ebd 1651
c19d1205
ZW
1652 for (i = cur_reg + 1; i < reg; i++)
1653 {
1654 if (range & (1 << i))
1655 as_tsktsk
1656 (_("Warning: duplicated register (r%d) in register list"),
1657 i);
1658 else
1659 range |= 1 << i;
1660 }
1661 in_range = 0;
1662 }
a737bd4d 1663
c19d1205
ZW
1664 if (range & (1 << reg))
1665 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1666 reg);
1667 else if (reg <= cur_reg)
1668 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1669
c19d1205
ZW
1670 range |= 1 << reg;
1671 cur_reg = reg;
1672 }
1673 while (skip_past_comma (&str) != FAIL
1674 || (in_range = 1, *str++ == '-'));
1675 str--;
a737bd4d 1676
d996d970 1677 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1678 {
dcbf9037 1679 first_error (_("missing `}'"));
c19d1205
ZW
1680 return FAIL;
1681 }
1682 }
1683 else
1684 {
91d6fa6a 1685 expressionS exp;
40a18ebd 1686
91d6fa6a 1687 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1688 return FAIL;
40a18ebd 1689
91d6fa6a 1690 if (exp.X_op == O_constant)
c19d1205 1691 {
91d6fa6a
NC
1692 if (exp.X_add_number
1693 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1694 {
1695 inst.error = _("invalid register mask");
1696 return FAIL;
1697 }
a737bd4d 1698
91d6fa6a 1699 if ((range & exp.X_add_number) != 0)
c19d1205 1700 {
91d6fa6a 1701 int regno = range & exp.X_add_number;
a737bd4d 1702
c19d1205
ZW
1703 regno &= -regno;
1704 regno = (1 << regno) - 1;
1705 as_tsktsk
1706 (_("Warning: duplicated register (r%d) in register list"),
1707 regno);
1708 }
a737bd4d 1709
91d6fa6a 1710 range |= exp.X_add_number;
c19d1205
ZW
1711 }
1712 else
1713 {
1714 if (inst.reloc.type != 0)
1715 {
1716 inst.error = _("expression too complex");
1717 return FAIL;
1718 }
a737bd4d 1719
91d6fa6a 1720 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1721 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1722 inst.reloc.pc_rel = 0;
1723 }
1724 }
a737bd4d 1725
c19d1205
ZW
1726 if (*str == '|' || *str == '+')
1727 {
1728 str++;
1729 another_range = 1;
1730 }
a737bd4d 1731 }
c19d1205 1732 while (another_range);
a737bd4d 1733
c19d1205
ZW
1734 *strp = str;
1735 return range;
a737bd4d
NC
1736}
1737
5287ad62
JB
1738/* Types of registers in a list. */
1739
1740enum reg_list_els
1741{
1742 REGLIST_VFP_S,
1743 REGLIST_VFP_D,
1744 REGLIST_NEON_D
1745};
1746
c19d1205
ZW
1747/* Parse a VFP register list. If the string is invalid return FAIL.
1748 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1749 register. Parses registers of type ETYPE.
1750 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1751 - Q registers can be used to specify pairs of D registers
1752 - { } can be omitted from around a singleton register list
477330fc
RM
1753 FIXME: This is not implemented, as it would require backtracking in
1754 some cases, e.g.:
1755 vtbl.8 d3,d4,d5
1756 This could be done (the meaning isn't really ambiguous), but doesn't
1757 fit in well with the current parsing framework.
dcbf9037
JB
1758 - 32 D registers may be used (also true for VFPv3).
1759 FIXME: Types are ignored in these register lists, which is probably a
1760 bug. */
6057a28f 1761
c19d1205 1762static int
037e8744 1763parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1764{
037e8744 1765 char *str = *ccp;
c19d1205
ZW
1766 int base_reg;
1767 int new_base;
21d799b5 1768 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1769 int max_regs = 0;
c19d1205
ZW
1770 int count = 0;
1771 int warned = 0;
1772 unsigned long mask = 0;
a737bd4d 1773 int i;
6057a28f 1774
477330fc 1775 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1776 {
1777 inst.error = _("expecting {");
1778 return FAIL;
1779 }
6057a28f 1780
5287ad62 1781 switch (etype)
c19d1205 1782 {
5287ad62 1783 case REGLIST_VFP_S:
c19d1205
ZW
1784 regtype = REG_TYPE_VFS;
1785 max_regs = 32;
5287ad62 1786 break;
5f4273c7 1787
5287ad62
JB
1788 case REGLIST_VFP_D:
1789 regtype = REG_TYPE_VFD;
b7fc2769 1790 break;
5f4273c7 1791
b7fc2769
JB
1792 case REGLIST_NEON_D:
1793 regtype = REG_TYPE_NDQ;
1794 break;
1795 }
1796
1797 if (etype != REGLIST_VFP_S)
1798 {
b1cc4aeb
PB
1799 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1800 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1801 {
1802 max_regs = 32;
1803 if (thumb_mode)
1804 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1805 fpu_vfp_ext_d32);
1806 else
1807 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1808 fpu_vfp_ext_d32);
1809 }
5287ad62 1810 else
477330fc 1811 max_regs = 16;
c19d1205 1812 }
6057a28f 1813
c19d1205 1814 base_reg = max_regs;
a737bd4d 1815
c19d1205
ZW
1816 do
1817 {
5287ad62 1818 int setmask = 1, addregs = 1;
dcbf9037 1819
037e8744 1820 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1821
c19d1205 1822 if (new_base == FAIL)
a737bd4d 1823 {
dcbf9037 1824 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1825 return FAIL;
1826 }
5f4273c7 1827
b7fc2769 1828 if (new_base >= max_regs)
477330fc
RM
1829 {
1830 first_error (_("register out of range in list"));
1831 return FAIL;
1832 }
5f4273c7 1833
5287ad62
JB
1834 /* Note: a value of 2 * n is returned for the register Q<n>. */
1835 if (regtype == REG_TYPE_NQ)
477330fc
RM
1836 {
1837 setmask = 3;
1838 addregs = 2;
1839 }
5287ad62 1840
c19d1205
ZW
1841 if (new_base < base_reg)
1842 base_reg = new_base;
a737bd4d 1843
5287ad62 1844 if (mask & (setmask << new_base))
c19d1205 1845 {
dcbf9037 1846 first_error (_("invalid register list"));
c19d1205 1847 return FAIL;
a737bd4d 1848 }
a737bd4d 1849
c19d1205
ZW
1850 if ((mask >> new_base) != 0 && ! warned)
1851 {
1852 as_tsktsk (_("register list not in ascending order"));
1853 warned = 1;
1854 }
0bbf2aa4 1855
5287ad62
JB
1856 mask |= setmask << new_base;
1857 count += addregs;
0bbf2aa4 1858
037e8744 1859 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1860 {
1861 int high_range;
0bbf2aa4 1862
037e8744 1863 str++;
0bbf2aa4 1864
037e8744 1865 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1866 == FAIL)
c19d1205
ZW
1867 {
1868 inst.error = gettext (reg_expected_msgs[regtype]);
1869 return FAIL;
1870 }
0bbf2aa4 1871
477330fc
RM
1872 if (high_range >= max_regs)
1873 {
1874 first_error (_("register out of range in list"));
1875 return FAIL;
1876 }
b7fc2769 1877
477330fc
RM
1878 if (regtype == REG_TYPE_NQ)
1879 high_range = high_range + 1;
5287ad62 1880
c19d1205
ZW
1881 if (high_range <= new_base)
1882 {
1883 inst.error = _("register range not in ascending order");
1884 return FAIL;
1885 }
0bbf2aa4 1886
5287ad62 1887 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1888 {
5287ad62 1889 if (mask & (setmask << new_base))
0bbf2aa4 1890 {
c19d1205
ZW
1891 inst.error = _("invalid register list");
1892 return FAIL;
0bbf2aa4 1893 }
c19d1205 1894
5287ad62
JB
1895 mask |= setmask << new_base;
1896 count += addregs;
0bbf2aa4 1897 }
0bbf2aa4 1898 }
0bbf2aa4 1899 }
037e8744 1900 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1901
037e8744 1902 str++;
0bbf2aa4 1903
c19d1205
ZW
1904 /* Sanity check -- should have raised a parse error above. */
1905 if (count == 0 || count > max_regs)
1906 abort ();
1907
1908 *pbase = base_reg;
1909
1910 /* Final test -- the registers must be consecutive. */
1911 mask >>= base_reg;
1912 for (i = 0; i < count; i++)
1913 {
1914 if ((mask & (1u << i)) == 0)
1915 {
1916 inst.error = _("non-contiguous register range");
1917 return FAIL;
1918 }
1919 }
1920
037e8744
JB
1921 *ccp = str;
1922
c19d1205 1923 return count;
b99bd4ef
NC
1924}
1925
dcbf9037
JB
1926/* True if two alias types are the same. */
1927
c921be7d 1928static bfd_boolean
dcbf9037
JB
1929neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1930{
1931 if (!a && !b)
c921be7d 1932 return TRUE;
5f4273c7 1933
dcbf9037 1934 if (!a || !b)
c921be7d 1935 return FALSE;
dcbf9037
JB
1936
1937 if (a->defined != b->defined)
c921be7d 1938 return FALSE;
5f4273c7 1939
dcbf9037
JB
1940 if ((a->defined & NTA_HASTYPE) != 0
1941 && (a->eltype.type != b->eltype.type
477330fc 1942 || a->eltype.size != b->eltype.size))
c921be7d 1943 return FALSE;
dcbf9037
JB
1944
1945 if ((a->defined & NTA_HASINDEX) != 0
1946 && (a->index != b->index))
c921be7d 1947 return FALSE;
5f4273c7 1948
c921be7d 1949 return TRUE;
dcbf9037
JB
1950}
1951
5287ad62
JB
1952/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1953 The base register is put in *PBASE.
dcbf9037 1954 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1955 the return value.
1956 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1957 Bits [6:5] encode the list length (minus one).
1958 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1959
5287ad62 1960#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1961#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1962#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1963
1964static int
dcbf9037 1965parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1966 struct neon_type_el *eltype)
5287ad62
JB
1967{
1968 char *ptr = *str;
1969 int base_reg = -1;
1970 int reg_incr = -1;
1971 int count = 0;
1972 int lane = -1;
1973 int leading_brace = 0;
1974 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1975 const char *const incr_error = _("register stride must be 1 or 2");
1976 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1977 struct neon_typed_alias firsttype;
5f4273c7 1978
5287ad62
JB
1979 if (skip_past_char (&ptr, '{') == SUCCESS)
1980 leading_brace = 1;
5f4273c7 1981
5287ad62
JB
1982 do
1983 {
dcbf9037
JB
1984 struct neon_typed_alias atype;
1985 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1986
5287ad62 1987 if (getreg == FAIL)
477330fc
RM
1988 {
1989 first_error (_(reg_expected_msgs[rtype]));
1990 return FAIL;
1991 }
5f4273c7 1992
5287ad62 1993 if (base_reg == -1)
477330fc
RM
1994 {
1995 base_reg = getreg;
1996 if (rtype == REG_TYPE_NQ)
1997 {
1998 reg_incr = 1;
1999 }
2000 firsttype = atype;
2001 }
5287ad62 2002 else if (reg_incr == -1)
477330fc
RM
2003 {
2004 reg_incr = getreg - base_reg;
2005 if (reg_incr < 1 || reg_incr > 2)
2006 {
2007 first_error (_(incr_error));
2008 return FAIL;
2009 }
2010 }
5287ad62 2011 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2012 {
2013 first_error (_(incr_error));
2014 return FAIL;
2015 }
dcbf9037 2016
c921be7d 2017 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2018 {
2019 first_error (_(type_error));
2020 return FAIL;
2021 }
5f4273c7 2022
5287ad62 2023 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2024 modes. */
5287ad62 2025 if (ptr[0] == '-')
477330fc
RM
2026 {
2027 struct neon_typed_alias htype;
2028 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2029 if (lane == -1)
2030 lane = NEON_INTERLEAVE_LANES;
2031 else if (lane != NEON_INTERLEAVE_LANES)
2032 {
2033 first_error (_(type_error));
2034 return FAIL;
2035 }
2036 if (reg_incr == -1)
2037 reg_incr = 1;
2038 else if (reg_incr != 1)
2039 {
2040 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2041 return FAIL;
2042 }
2043 ptr++;
2044 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2045 if (hireg == FAIL)
2046 {
2047 first_error (_(reg_expected_msgs[rtype]));
2048 return FAIL;
2049 }
2050 if (! neon_alias_types_same (&htype, &firsttype))
2051 {
2052 first_error (_(type_error));
2053 return FAIL;
2054 }
2055 count += hireg + dregs - getreg;
2056 continue;
2057 }
5f4273c7 2058
5287ad62
JB
2059 /* If we're using Q registers, we can't use [] or [n] syntax. */
2060 if (rtype == REG_TYPE_NQ)
477330fc
RM
2061 {
2062 count += 2;
2063 continue;
2064 }
5f4273c7 2065
dcbf9037 2066 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2067 {
2068 if (lane == -1)
2069 lane = atype.index;
2070 else if (lane != atype.index)
2071 {
2072 first_error (_(type_error));
2073 return FAIL;
2074 }
2075 }
5287ad62 2076 else if (lane == -1)
477330fc 2077 lane = NEON_INTERLEAVE_LANES;
5287ad62 2078 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2079 {
2080 first_error (_(type_error));
2081 return FAIL;
2082 }
5287ad62
JB
2083 count++;
2084 }
2085 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2086
5287ad62
JB
2087 /* No lane set by [x]. We must be interleaving structures. */
2088 if (lane == -1)
2089 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2090
5287ad62
JB
2091 /* Sanity check. */
2092 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2093 || (count > 1 && reg_incr == -1))
2094 {
dcbf9037 2095 first_error (_("error parsing element/structure list"));
5287ad62
JB
2096 return FAIL;
2097 }
2098
2099 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2100 {
dcbf9037 2101 first_error (_("expected }"));
5287ad62
JB
2102 return FAIL;
2103 }
5f4273c7 2104
5287ad62
JB
2105 if (reg_incr == -1)
2106 reg_incr = 1;
2107
dcbf9037
JB
2108 if (eltype)
2109 *eltype = firsttype.eltype;
2110
5287ad62
JB
2111 *pbase = base_reg;
2112 *str = ptr;
5f4273c7 2113
5287ad62
JB
2114 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2115}
2116
c19d1205
ZW
2117/* Parse an explicit relocation suffix on an expression. This is
2118 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2119 arm_reloc_hsh contains no entries, so this function can only
2120 succeed if there is no () after the word. Returns -1 on error,
2121 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2122
c19d1205
ZW
2123static int
2124parse_reloc (char **str)
b99bd4ef 2125{
c19d1205
ZW
2126 struct reloc_entry *r;
2127 char *p, *q;
b99bd4ef 2128
c19d1205
ZW
2129 if (**str != '(')
2130 return BFD_RELOC_UNUSED;
b99bd4ef 2131
c19d1205
ZW
2132 p = *str + 1;
2133 q = p;
2134
2135 while (*q && *q != ')' && *q != ',')
2136 q++;
2137 if (*q != ')')
2138 return -1;
2139
21d799b5
NC
2140 if ((r = (struct reloc_entry *)
2141 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2142 return -1;
2143
2144 *str = q + 1;
2145 return r->reloc;
b99bd4ef
NC
2146}
2147
c19d1205
ZW
2148/* Directives: register aliases. */
2149
dcbf9037 2150static struct reg_entry *
90ec0d68 2151insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2152{
d3ce72d0 2153 struct reg_entry *new_reg;
c19d1205 2154 const char *name;
b99bd4ef 2155
d3ce72d0 2156 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2157 {
d3ce72d0 2158 if (new_reg->builtin)
c19d1205 2159 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2160
c19d1205
ZW
2161 /* Only warn about a redefinition if it's not defined as the
2162 same register. */
d3ce72d0 2163 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2164 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2165
d929913e 2166 return NULL;
c19d1205 2167 }
b99bd4ef 2168
c19d1205 2169 name = xstrdup (str);
d3ce72d0 2170 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2171
d3ce72d0
NC
2172 new_reg->name = name;
2173 new_reg->number = number;
2174 new_reg->type = type;
2175 new_reg->builtin = FALSE;
2176 new_reg->neon = NULL;
b99bd4ef 2177
d3ce72d0 2178 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2179 abort ();
5f4273c7 2180
d3ce72d0 2181 return new_reg;
dcbf9037
JB
2182}
2183
2184static void
2185insert_neon_reg_alias (char *str, int number, int type,
477330fc 2186 struct neon_typed_alias *atype)
dcbf9037
JB
2187{
2188 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2189
dcbf9037
JB
2190 if (!reg)
2191 {
2192 first_error (_("attempt to redefine typed alias"));
2193 return;
2194 }
5f4273c7 2195
dcbf9037
JB
2196 if (atype)
2197 {
21d799b5 2198 reg->neon = (struct neon_typed_alias *)
477330fc 2199 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2200 *reg->neon = *atype;
2201 }
c19d1205 2202}
b99bd4ef 2203
c19d1205 2204/* Look for the .req directive. This is of the form:
b99bd4ef 2205
c19d1205 2206 new_register_name .req existing_register_name
b99bd4ef 2207
c19d1205 2208 If we find one, or if it looks sufficiently like one that we want to
d929913e 2209 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2210
d929913e 2211static bfd_boolean
c19d1205
ZW
2212create_register_alias (char * newname, char *p)
2213{
2214 struct reg_entry *old;
2215 char *oldname, *nbuf;
2216 size_t nlen;
b99bd4ef 2217
c19d1205
ZW
2218 /* The input scrubber ensures that whitespace after the mnemonic is
2219 collapsed to single spaces. */
2220 oldname = p;
2221 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2222 return FALSE;
b99bd4ef 2223
c19d1205
ZW
2224 oldname += 6;
2225 if (*oldname == '\0')
d929913e 2226 return FALSE;
b99bd4ef 2227
21d799b5 2228 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2229 if (!old)
b99bd4ef 2230 {
c19d1205 2231 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2232 return TRUE;
b99bd4ef
NC
2233 }
2234
c19d1205
ZW
2235 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2236 the desired alias name, and p points to its end. If not, then
2237 the desired alias name is in the global original_case_string. */
2238#ifdef TC_CASE_SENSITIVE
2239 nlen = p - newname;
2240#else
2241 newname = original_case_string;
2242 nlen = strlen (newname);
2243#endif
b99bd4ef 2244
21d799b5 2245 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2246 memcpy (nbuf, newname, nlen);
2247 nbuf[nlen] = '\0';
b99bd4ef 2248
c19d1205
ZW
2249 /* Create aliases under the new name as stated; an all-lowercase
2250 version of the new name; and an all-uppercase version of the new
2251 name. */
d929913e
NC
2252 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2253 {
2254 for (p = nbuf; *p; p++)
2255 *p = TOUPPER (*p);
c19d1205 2256
d929913e
NC
2257 if (strncmp (nbuf, newname, nlen))
2258 {
2259 /* If this attempt to create an additional alias fails, do not bother
2260 trying to create the all-lower case alias. We will fail and issue
2261 a second, duplicate error message. This situation arises when the
2262 programmer does something like:
2263 foo .req r0
2264 Foo .req r1
2265 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2266 the artificial FOO alias because it has already been created by the
d929913e
NC
2267 first .req. */
2268 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2269 return TRUE;
2270 }
c19d1205 2271
d929913e
NC
2272 for (p = nbuf; *p; p++)
2273 *p = TOLOWER (*p);
c19d1205 2274
d929913e
NC
2275 if (strncmp (nbuf, newname, nlen))
2276 insert_reg_alias (nbuf, old->number, old->type);
2277 }
c19d1205 2278
d929913e 2279 return TRUE;
b99bd4ef
NC
2280}
2281
dcbf9037
JB
2282/* Create a Neon typed/indexed register alias using directives, e.g.:
2283 X .dn d5.s32[1]
2284 Y .qn 6.s16
2285 Z .dn d7
2286 T .dn Z[0]
2287 These typed registers can be used instead of the types specified after the
2288 Neon mnemonic, so long as all operands given have types. Types can also be
2289 specified directly, e.g.:
5f4273c7 2290 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2291
c921be7d 2292static bfd_boolean
dcbf9037
JB
2293create_neon_reg_alias (char *newname, char *p)
2294{
2295 enum arm_reg_type basetype;
2296 struct reg_entry *basereg;
2297 struct reg_entry mybasereg;
2298 struct neon_type ntype;
2299 struct neon_typed_alias typeinfo;
12d6b0b7 2300 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2301 int namelen;
5f4273c7 2302
dcbf9037
JB
2303 typeinfo.defined = 0;
2304 typeinfo.eltype.type = NT_invtype;
2305 typeinfo.eltype.size = -1;
2306 typeinfo.index = -1;
5f4273c7 2307
dcbf9037 2308 nameend = p;
5f4273c7 2309
dcbf9037
JB
2310 if (strncmp (p, " .dn ", 5) == 0)
2311 basetype = REG_TYPE_VFD;
2312 else if (strncmp (p, " .qn ", 5) == 0)
2313 basetype = REG_TYPE_NQ;
2314 else
c921be7d 2315 return FALSE;
5f4273c7 2316
dcbf9037 2317 p += 5;
5f4273c7 2318
dcbf9037 2319 if (*p == '\0')
c921be7d 2320 return FALSE;
5f4273c7 2321
dcbf9037
JB
2322 basereg = arm_reg_parse_multi (&p);
2323
2324 if (basereg && basereg->type != basetype)
2325 {
2326 as_bad (_("bad type for register"));
c921be7d 2327 return FALSE;
dcbf9037
JB
2328 }
2329
2330 if (basereg == NULL)
2331 {
2332 expressionS exp;
2333 /* Try parsing as an integer. */
2334 my_get_expression (&exp, &p, GE_NO_PREFIX);
2335 if (exp.X_op != O_constant)
477330fc
RM
2336 {
2337 as_bad (_("expression must be constant"));
2338 return FALSE;
2339 }
dcbf9037
JB
2340 basereg = &mybasereg;
2341 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2342 : exp.X_add_number;
dcbf9037
JB
2343 basereg->neon = 0;
2344 }
2345
2346 if (basereg->neon)
2347 typeinfo = *basereg->neon;
2348
2349 if (parse_neon_type (&ntype, &p) == SUCCESS)
2350 {
2351 /* We got a type. */
2352 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2353 {
2354 as_bad (_("can't redefine the type of a register alias"));
2355 return FALSE;
2356 }
5f4273c7 2357
dcbf9037
JB
2358 typeinfo.defined |= NTA_HASTYPE;
2359 if (ntype.elems != 1)
477330fc
RM
2360 {
2361 as_bad (_("you must specify a single type only"));
2362 return FALSE;
2363 }
dcbf9037
JB
2364 typeinfo.eltype = ntype.el[0];
2365 }
5f4273c7 2366
dcbf9037
JB
2367 if (skip_past_char (&p, '[') == SUCCESS)
2368 {
2369 expressionS exp;
2370 /* We got a scalar index. */
5f4273c7 2371
dcbf9037 2372 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2373 {
2374 as_bad (_("can't redefine the index of a scalar alias"));
2375 return FALSE;
2376 }
5f4273c7 2377
dcbf9037 2378 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2379
dcbf9037 2380 if (exp.X_op != O_constant)
477330fc
RM
2381 {
2382 as_bad (_("scalar index must be constant"));
2383 return FALSE;
2384 }
5f4273c7 2385
dcbf9037
JB
2386 typeinfo.defined |= NTA_HASINDEX;
2387 typeinfo.index = exp.X_add_number;
5f4273c7 2388
dcbf9037 2389 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2390 {
2391 as_bad (_("expecting ]"));
2392 return FALSE;
2393 }
dcbf9037
JB
2394 }
2395
15735687
NS
2396 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2397 the desired alias name, and p points to its end. If not, then
2398 the desired alias name is in the global original_case_string. */
2399#ifdef TC_CASE_SENSITIVE
dcbf9037 2400 namelen = nameend - newname;
15735687
NS
2401#else
2402 newname = original_case_string;
2403 namelen = strlen (newname);
2404#endif
2405
21d799b5 2406 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2407 strncpy (namebuf, newname, namelen);
2408 namebuf[namelen] = '\0';
5f4273c7 2409
dcbf9037 2410 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2411 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2412
dcbf9037
JB
2413 /* Insert name in all uppercase. */
2414 for (p = namebuf; *p; p++)
2415 *p = TOUPPER (*p);
5f4273c7 2416
dcbf9037
JB
2417 if (strncmp (namebuf, newname, namelen))
2418 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2419 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2420
dcbf9037
JB
2421 /* Insert name in all lowercase. */
2422 for (p = namebuf; *p; p++)
2423 *p = TOLOWER (*p);
5f4273c7 2424
dcbf9037
JB
2425 if (strncmp (namebuf, newname, namelen))
2426 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2427 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2428
c921be7d 2429 return TRUE;
dcbf9037
JB
2430}
2431
c19d1205
ZW
2432/* Should never be called, as .req goes between the alias and the
2433 register name, not at the beginning of the line. */
c921be7d 2434
b99bd4ef 2435static void
c19d1205 2436s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2437{
c19d1205
ZW
2438 as_bad (_("invalid syntax for .req directive"));
2439}
b99bd4ef 2440
dcbf9037
JB
2441static void
2442s_dn (int a ATTRIBUTE_UNUSED)
2443{
2444 as_bad (_("invalid syntax for .dn directive"));
2445}
2446
2447static void
2448s_qn (int a ATTRIBUTE_UNUSED)
2449{
2450 as_bad (_("invalid syntax for .qn directive"));
2451}
2452
c19d1205
ZW
2453/* The .unreq directive deletes an alias which was previously defined
2454 by .req. For example:
b99bd4ef 2455
c19d1205
ZW
2456 my_alias .req r11
2457 .unreq my_alias */
b99bd4ef
NC
2458
2459static void
c19d1205 2460s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2461{
c19d1205
ZW
2462 char * name;
2463 char saved_char;
b99bd4ef 2464
c19d1205
ZW
2465 name = input_line_pointer;
2466
2467 while (*input_line_pointer != 0
2468 && *input_line_pointer != ' '
2469 && *input_line_pointer != '\n')
2470 ++input_line_pointer;
2471
2472 saved_char = *input_line_pointer;
2473 *input_line_pointer = 0;
2474
2475 if (!*name)
2476 as_bad (_("invalid syntax for .unreq directive"));
2477 else
2478 {
21d799b5 2479 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2480 name);
c19d1205
ZW
2481
2482 if (!reg)
2483 as_bad (_("unknown register alias '%s'"), name);
2484 else if (reg->builtin)
a1727c1a 2485 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2486 name);
2487 else
2488 {
d929913e
NC
2489 char * p;
2490 char * nbuf;
2491
db0bc284 2492 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2493 free ((char *) reg->name);
477330fc
RM
2494 if (reg->neon)
2495 free (reg->neon);
c19d1205 2496 free (reg);
d929913e
NC
2497
2498 /* Also locate the all upper case and all lower case versions.
2499 Do not complain if we cannot find one or the other as it
2500 was probably deleted above. */
5f4273c7 2501
d929913e
NC
2502 nbuf = strdup (name);
2503 for (p = nbuf; *p; p++)
2504 *p = TOUPPER (*p);
21d799b5 2505 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2506 if (reg)
2507 {
db0bc284 2508 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2509 free ((char *) reg->name);
2510 if (reg->neon)
2511 free (reg->neon);
2512 free (reg);
2513 }
2514
2515 for (p = nbuf; *p; p++)
2516 *p = TOLOWER (*p);
21d799b5 2517 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2518 if (reg)
2519 {
db0bc284 2520 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2521 free ((char *) reg->name);
2522 if (reg->neon)
2523 free (reg->neon);
2524 free (reg);
2525 }
2526
2527 free (nbuf);
c19d1205
ZW
2528 }
2529 }
b99bd4ef 2530
c19d1205 2531 *input_line_pointer = saved_char;
b99bd4ef
NC
2532 demand_empty_rest_of_line ();
2533}
2534
c19d1205
ZW
2535/* Directives: Instruction set selection. */
2536
2537#ifdef OBJ_ELF
2538/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2539 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2540 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2541 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2542
cd000bff
DJ
2543/* Create a new mapping symbol for the transition to STATE. */
2544
2545static void
2546make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2547{
a737bd4d 2548 symbolS * symbolP;
c19d1205
ZW
2549 const char * symname;
2550 int type;
b99bd4ef 2551
c19d1205 2552 switch (state)
b99bd4ef 2553 {
c19d1205
ZW
2554 case MAP_DATA:
2555 symname = "$d";
2556 type = BSF_NO_FLAGS;
2557 break;
2558 case MAP_ARM:
2559 symname = "$a";
2560 type = BSF_NO_FLAGS;
2561 break;
2562 case MAP_THUMB:
2563 symname = "$t";
2564 type = BSF_NO_FLAGS;
2565 break;
c19d1205
ZW
2566 default:
2567 abort ();
2568 }
2569
cd000bff 2570 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2571 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2572
2573 switch (state)
2574 {
2575 case MAP_ARM:
2576 THUMB_SET_FUNC (symbolP, 0);
2577 ARM_SET_THUMB (symbolP, 0);
2578 ARM_SET_INTERWORK (symbolP, support_interwork);
2579 break;
2580
2581 case MAP_THUMB:
2582 THUMB_SET_FUNC (symbolP, 1);
2583 ARM_SET_THUMB (symbolP, 1);
2584 ARM_SET_INTERWORK (symbolP, support_interwork);
2585 break;
2586
2587 case MAP_DATA:
2588 default:
cd000bff
DJ
2589 break;
2590 }
2591
2592 /* Save the mapping symbols for future reference. Also check that
2593 we do not place two mapping symbols at the same offset within a
2594 frag. We'll handle overlap between frags in
2de7820f
JZ
2595 check_mapping_symbols.
2596
2597 If .fill or other data filling directive generates zero sized data,
2598 the mapping symbol for the following code will have the same value
2599 as the one generated for the data filling directive. In this case,
2600 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2601 if (value == 0)
2602 {
2de7820f
JZ
2603 if (frag->tc_frag_data.first_map != NULL)
2604 {
2605 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2606 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2607 }
cd000bff
DJ
2608 frag->tc_frag_data.first_map = symbolP;
2609 }
2610 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2611 {
2612 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2613 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2614 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2615 }
cd000bff
DJ
2616 frag->tc_frag_data.last_map = symbolP;
2617}
2618
2619/* We must sometimes convert a region marked as code to data during
2620 code alignment, if an odd number of bytes have to be padded. The
2621 code mapping symbol is pushed to an aligned address. */
2622
2623static void
2624insert_data_mapping_symbol (enum mstate state,
2625 valueT value, fragS *frag, offsetT bytes)
2626{
2627 /* If there was already a mapping symbol, remove it. */
2628 if (frag->tc_frag_data.last_map != NULL
2629 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2630 {
2631 symbolS *symp = frag->tc_frag_data.last_map;
2632
2633 if (value == 0)
2634 {
2635 know (frag->tc_frag_data.first_map == symp);
2636 frag->tc_frag_data.first_map = NULL;
2637 }
2638 frag->tc_frag_data.last_map = NULL;
2639 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2640 }
cd000bff
DJ
2641
2642 make_mapping_symbol (MAP_DATA, value, frag);
2643 make_mapping_symbol (state, value + bytes, frag);
2644}
2645
2646static void mapping_state_2 (enum mstate state, int max_chars);
2647
2648/* Set the mapping state to STATE. Only call this when about to
2649 emit some STATE bytes to the file. */
2650
4e9aaefb 2651#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2652void
2653mapping_state (enum mstate state)
2654{
940b5ce0
DJ
2655 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2656
cd000bff
DJ
2657 if (mapstate == state)
2658 /* The mapping symbol has already been emitted.
2659 There is nothing else to do. */
2660 return;
49c62a33
NC
2661
2662 if (state == MAP_ARM || state == MAP_THUMB)
2663 /* PR gas/12931
2664 All ARM instructions require 4-byte alignment.
2665 (Almost) all Thumb instructions require 2-byte alignment.
2666
2667 When emitting instructions into any section, mark the section
2668 appropriately.
2669
2670 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2671 but themselves require 2-byte alignment; this applies to some
2672 PC- relative forms. However, these cases will invovle implicit
2673 literal pool generation or an explicit .align >=2, both of
2674 which will cause the section to me marked with sufficient
2675 alignment. Thus, we don't handle those cases here. */
2676 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2677
2678 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2679 /* This case will be evaluated later. */
cd000bff 2680 return;
cd000bff
DJ
2681
2682 mapping_state_2 (state, 0);
cd000bff
DJ
2683}
2684
2685/* Same as mapping_state, but MAX_CHARS bytes have already been
2686 allocated. Put the mapping symbol that far back. */
2687
2688static void
2689mapping_state_2 (enum mstate state, int max_chars)
2690{
940b5ce0
DJ
2691 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2692
2693 if (!SEG_NORMAL (now_seg))
2694 return;
2695
cd000bff
DJ
2696 if (mapstate == state)
2697 /* The mapping symbol has already been emitted.
2698 There is nothing else to do. */
2699 return;
2700
4e9aaefb
SA
2701 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2702 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2703 {
2704 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2705 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2706
2707 if (add_symbol)
2708 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2709 }
2710
cd000bff
DJ
2711 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2712 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2713}
4e9aaefb 2714#undef TRANSITION
c19d1205 2715#else
d3106081
NS
2716#define mapping_state(x) ((void)0)
2717#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2718#endif
2719
2720/* Find the real, Thumb encoded start of a Thumb function. */
2721
4343666d 2722#ifdef OBJ_COFF
c19d1205
ZW
2723static symbolS *
2724find_real_start (symbolS * symbolP)
2725{
2726 char * real_start;
2727 const char * name = S_GET_NAME (symbolP);
2728 symbolS * new_target;
2729
2730 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2731#define STUB_NAME ".real_start_of"
2732
2733 if (name == NULL)
2734 abort ();
2735
37f6032b
ZW
2736 /* The compiler may generate BL instructions to local labels because
2737 it needs to perform a branch to a far away location. These labels
2738 do not have a corresponding ".real_start_of" label. We check
2739 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2740 the ".real_start_of" convention for nonlocal branches. */
2741 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2742 return symbolP;
2743
37f6032b 2744 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2745 new_target = symbol_find (real_start);
2746
2747 if (new_target == NULL)
2748 {
bd3ba5d1 2749 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2750 new_target = symbolP;
2751 }
2752
c19d1205
ZW
2753 return new_target;
2754}
4343666d 2755#endif
c19d1205
ZW
2756
2757static void
2758opcode_select (int width)
2759{
2760 switch (width)
2761 {
2762 case 16:
2763 if (! thumb_mode)
2764 {
e74cfd16 2765 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2766 as_bad (_("selected processor does not support THUMB opcodes"));
2767
2768 thumb_mode = 1;
2769 /* No need to force the alignment, since we will have been
2770 coming from ARM mode, which is word-aligned. */
2771 record_alignment (now_seg, 1);
2772 }
c19d1205
ZW
2773 break;
2774
2775 case 32:
2776 if (thumb_mode)
2777 {
e74cfd16 2778 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2779 as_bad (_("selected processor does not support ARM opcodes"));
2780
2781 thumb_mode = 0;
2782
2783 if (!need_pass_2)
2784 frag_align (2, 0, 0);
2785
2786 record_alignment (now_seg, 1);
2787 }
c19d1205
ZW
2788 break;
2789
2790 default:
2791 as_bad (_("invalid instruction size selected (%d)"), width);
2792 }
2793}
2794
2795static void
2796s_arm (int ignore ATTRIBUTE_UNUSED)
2797{
2798 opcode_select (32);
2799 demand_empty_rest_of_line ();
2800}
2801
2802static void
2803s_thumb (int ignore ATTRIBUTE_UNUSED)
2804{
2805 opcode_select (16);
2806 demand_empty_rest_of_line ();
2807}
2808
2809static void
2810s_code (int unused ATTRIBUTE_UNUSED)
2811{
2812 int temp;
2813
2814 temp = get_absolute_expression ();
2815 switch (temp)
2816 {
2817 case 16:
2818 case 32:
2819 opcode_select (temp);
2820 break;
2821
2822 default:
2823 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2824 }
2825}
2826
2827static void
2828s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2829{
2830 /* If we are not already in thumb mode go into it, EVEN if
2831 the target processor does not support thumb instructions.
2832 This is used by gcc/config/arm/lib1funcs.asm for example
2833 to compile interworking support functions even if the
2834 target processor should not support interworking. */
2835 if (! thumb_mode)
2836 {
2837 thumb_mode = 2;
2838 record_alignment (now_seg, 1);
2839 }
2840
2841 demand_empty_rest_of_line ();
2842}
2843
2844static void
2845s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2846{
2847 s_thumb (0);
2848
2849 /* The following label is the name/address of the start of a Thumb function.
2850 We need to know this for the interworking support. */
2851 label_is_thumb_function_name = TRUE;
2852}
2853
2854/* Perform a .set directive, but also mark the alias as
2855 being a thumb function. */
2856
2857static void
2858s_thumb_set (int equiv)
2859{
2860 /* XXX the following is a duplicate of the code for s_set() in read.c
2861 We cannot just call that code as we need to get at the symbol that
2862 is created. */
2863 char * name;
2864 char delim;
2865 char * end_name;
2866 symbolS * symbolP;
2867
2868 /* Especial apologies for the random logic:
2869 This just grew, and could be parsed much more simply!
2870 Dean - in haste. */
d02603dc 2871 delim = get_symbol_name (& name);
c19d1205 2872 end_name = input_line_pointer;
d02603dc 2873 (void) restore_line_pointer (delim);
c19d1205
ZW
2874
2875 if (*input_line_pointer != ',')
2876 {
2877 *end_name = 0;
2878 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2879 *end_name = delim;
2880 ignore_rest_of_line ();
2881 return;
2882 }
2883
2884 input_line_pointer++;
2885 *end_name = 0;
2886
2887 if (name[0] == '.' && name[1] == '\0')
2888 {
2889 /* XXX - this should not happen to .thumb_set. */
2890 abort ();
2891 }
2892
2893 if ((symbolP = symbol_find (name)) == NULL
2894 && (symbolP = md_undefined_symbol (name)) == NULL)
2895 {
2896#ifndef NO_LISTING
2897 /* When doing symbol listings, play games with dummy fragments living
2898 outside the normal fragment chain to record the file and line info
c19d1205 2899 for this symbol. */
b99bd4ef
NC
2900 if (listing & LISTING_SYMBOLS)
2901 {
2902 extern struct list_info_struct * listing_tail;
21d799b5 2903 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2904
2905 memset (dummy_frag, 0, sizeof (fragS));
2906 dummy_frag->fr_type = rs_fill;
2907 dummy_frag->line = listing_tail;
2908 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2909 dummy_frag->fr_symbol = symbolP;
2910 }
2911 else
2912#endif
2913 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2914
2915#ifdef OBJ_COFF
2916 /* "set" symbols are local unless otherwise specified. */
2917 SF_SET_LOCAL (symbolP);
2918#endif /* OBJ_COFF */
2919 } /* Make a new symbol. */
2920
2921 symbol_table_insert (symbolP);
2922
2923 * end_name = delim;
2924
2925 if (equiv
2926 && S_IS_DEFINED (symbolP)
2927 && S_GET_SEGMENT (symbolP) != reg_section)
2928 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2929
2930 pseudo_set (symbolP);
2931
2932 demand_empty_rest_of_line ();
2933
c19d1205 2934 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2935
2936 THUMB_SET_FUNC (symbolP, 1);
2937 ARM_SET_THUMB (symbolP, 1);
2938#if defined OBJ_ELF || defined OBJ_COFF
2939 ARM_SET_INTERWORK (symbolP, support_interwork);
2940#endif
2941}
2942
c19d1205 2943/* Directives: Mode selection. */
b99bd4ef 2944
c19d1205
ZW
2945/* .syntax [unified|divided] - choose the new unified syntax
2946 (same for Arm and Thumb encoding, modulo slight differences in what
2947 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2948static void
c19d1205 2949s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2950{
c19d1205
ZW
2951 char *name, delim;
2952
d02603dc 2953 delim = get_symbol_name (& name);
c19d1205
ZW
2954
2955 if (!strcasecmp (name, "unified"))
2956 unified_syntax = TRUE;
2957 else if (!strcasecmp (name, "divided"))
2958 unified_syntax = FALSE;
2959 else
2960 {
2961 as_bad (_("unrecognized syntax mode \"%s\""), name);
2962 return;
2963 }
d02603dc 2964 (void) restore_line_pointer (delim);
b99bd4ef
NC
2965 demand_empty_rest_of_line ();
2966}
2967
c19d1205
ZW
2968/* Directives: sectioning and alignment. */
2969
c19d1205
ZW
2970static void
2971s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2972{
c19d1205
ZW
2973 /* We don't support putting frags in the BSS segment, we fake it by
2974 marking in_bss, then looking at s_skip for clues. */
2975 subseg_set (bss_section, 0);
2976 demand_empty_rest_of_line ();
cd000bff
DJ
2977
2978#ifdef md_elf_section_change_hook
2979 md_elf_section_change_hook ();
2980#endif
c19d1205 2981}
b99bd4ef 2982
c19d1205
ZW
2983static void
2984s_even (int ignore ATTRIBUTE_UNUSED)
2985{
2986 /* Never make frag if expect extra pass. */
2987 if (!need_pass_2)
2988 frag_align (1, 0, 0);
b99bd4ef 2989
c19d1205 2990 record_alignment (now_seg, 1);
b99bd4ef 2991
c19d1205 2992 demand_empty_rest_of_line ();
b99bd4ef
NC
2993}
2994
2e6976a8
DG
2995/* Directives: CodeComposer Studio. */
2996
2997/* .ref (for CodeComposer Studio syntax only). */
2998static void
2999s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3000{
3001 if (codecomposer_syntax)
3002 ignore_rest_of_line ();
3003 else
3004 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3005}
3006
3007/* If name is not NULL, then it is used for marking the beginning of a
3008 function, wherease if it is NULL then it means the function end. */
3009static void
3010asmfunc_debug (const char * name)
3011{
3012 static const char * last_name = NULL;
3013
3014 if (name != NULL)
3015 {
3016 gas_assert (last_name == NULL);
3017 last_name = name;
3018
3019 if (debug_type == DEBUG_STABS)
3020 stabs_generate_asm_func (name, name);
3021 }
3022 else
3023 {
3024 gas_assert (last_name != NULL);
3025
3026 if (debug_type == DEBUG_STABS)
3027 stabs_generate_asm_endfunc (last_name, last_name);
3028
3029 last_name = NULL;
3030 }
3031}
3032
3033static void
3034s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3035{
3036 if (codecomposer_syntax)
3037 {
3038 switch (asmfunc_state)
3039 {
3040 case OUTSIDE_ASMFUNC:
3041 asmfunc_state = WAITING_ASMFUNC_NAME;
3042 break;
3043
3044 case WAITING_ASMFUNC_NAME:
3045 as_bad (_(".asmfunc repeated."));
3046 break;
3047
3048 case WAITING_ENDASMFUNC:
3049 as_bad (_(".asmfunc without function."));
3050 break;
3051 }
3052 demand_empty_rest_of_line ();
3053 }
3054 else
3055 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3056}
3057
3058static void
3059s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3060{
3061 if (codecomposer_syntax)
3062 {
3063 switch (asmfunc_state)
3064 {
3065 case OUTSIDE_ASMFUNC:
3066 as_bad (_(".endasmfunc without a .asmfunc."));
3067 break;
3068
3069 case WAITING_ASMFUNC_NAME:
3070 as_bad (_(".endasmfunc without function."));
3071 break;
3072
3073 case WAITING_ENDASMFUNC:
3074 asmfunc_state = OUTSIDE_ASMFUNC;
3075 asmfunc_debug (NULL);
3076 break;
3077 }
3078 demand_empty_rest_of_line ();
3079 }
3080 else
3081 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3082}
3083
3084static void
3085s_ccs_def (int name)
3086{
3087 if (codecomposer_syntax)
3088 s_globl (name);
3089 else
3090 as_bad (_(".def pseudo-op only available with -mccs flag."));
3091}
3092
c19d1205 3093/* Directives: Literal pools. */
a737bd4d 3094
c19d1205
ZW
3095static literal_pool *
3096find_literal_pool (void)
a737bd4d 3097{
c19d1205 3098 literal_pool * pool;
a737bd4d 3099
c19d1205 3100 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3101 {
c19d1205
ZW
3102 if (pool->section == now_seg
3103 && pool->sub_section == now_subseg)
3104 break;
a737bd4d
NC
3105 }
3106
c19d1205 3107 return pool;
a737bd4d
NC
3108}
3109
c19d1205
ZW
3110static literal_pool *
3111find_or_make_literal_pool (void)
a737bd4d 3112{
c19d1205
ZW
3113 /* Next literal pool ID number. */
3114 static unsigned int latest_pool_num = 1;
3115 literal_pool * pool;
a737bd4d 3116
c19d1205 3117 pool = find_literal_pool ();
a737bd4d 3118
c19d1205 3119 if (pool == NULL)
a737bd4d 3120 {
c19d1205 3121 /* Create a new pool. */
21d799b5 3122 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3123 if (! pool)
3124 return NULL;
a737bd4d 3125
c19d1205
ZW
3126 pool->next_free_entry = 0;
3127 pool->section = now_seg;
3128 pool->sub_section = now_subseg;
3129 pool->next = list_of_pools;
3130 pool->symbol = NULL;
8335d6aa 3131 pool->alignment = 2;
c19d1205
ZW
3132
3133 /* Add it to the list. */
3134 list_of_pools = pool;
a737bd4d 3135 }
a737bd4d 3136
c19d1205
ZW
3137 /* New pools, and emptied pools, will have a NULL symbol. */
3138 if (pool->symbol == NULL)
a737bd4d 3139 {
c19d1205
ZW
3140 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3141 (valueT) 0, &zero_address_frag);
3142 pool->id = latest_pool_num ++;
a737bd4d
NC
3143 }
3144
c19d1205
ZW
3145 /* Done. */
3146 return pool;
a737bd4d
NC
3147}
3148
c19d1205 3149/* Add the literal in the global 'inst'
5f4273c7 3150 structure to the relevant literal pool. */
b99bd4ef
NC
3151
3152static int
8335d6aa 3153add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3154{
8335d6aa
JW
3155#define PADDING_SLOT 0x1
3156#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3157 literal_pool * pool;
8335d6aa
JW
3158 unsigned int entry, pool_size = 0;
3159 bfd_boolean padding_slot_p = FALSE;
e56c722b 3160 unsigned imm1 = 0;
8335d6aa
JW
3161 unsigned imm2 = 0;
3162
3163 if (nbytes == 8)
3164 {
3165 imm1 = inst.operands[1].imm;
3166 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3167 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3168 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3169 if (target_big_endian)
3170 {
3171 imm1 = imm2;
3172 imm2 = inst.operands[1].imm;
3173 }
3174 }
b99bd4ef 3175
c19d1205
ZW
3176 pool = find_or_make_literal_pool ();
3177
3178 /* Check if this literal value is already in the pool. */
3179 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3180 {
8335d6aa
JW
3181 if (nbytes == 4)
3182 {
3183 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3184 && (inst.reloc.exp.X_op == O_constant)
3185 && (pool->literals[entry].X_add_number
3186 == inst.reloc.exp.X_add_number)
3187 && (pool->literals[entry].X_md == nbytes)
3188 && (pool->literals[entry].X_unsigned
3189 == inst.reloc.exp.X_unsigned))
3190 break;
3191
3192 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3193 && (inst.reloc.exp.X_op == O_symbol)
3194 && (pool->literals[entry].X_add_number
3195 == inst.reloc.exp.X_add_number)
3196 && (pool->literals[entry].X_add_symbol
3197 == inst.reloc.exp.X_add_symbol)
3198 && (pool->literals[entry].X_op_symbol
3199 == inst.reloc.exp.X_op_symbol)
3200 && (pool->literals[entry].X_md == nbytes))
3201 break;
3202 }
3203 else if ((nbytes == 8)
3204 && !(pool_size & 0x7)
3205 && ((entry + 1) != pool->next_free_entry)
3206 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3207 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3208 && (pool->literals[entry].X_unsigned
3209 == inst.reloc.exp.X_unsigned)
3210 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3211 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3212 && (pool->literals[entry + 1].X_unsigned
3213 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3214 break;
3215
8335d6aa
JW
3216 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3217 if (padding_slot_p && (nbytes == 4))
c19d1205 3218 break;
8335d6aa
JW
3219
3220 pool_size += 4;
b99bd4ef
NC
3221 }
3222
c19d1205
ZW
3223 /* Do we need to create a new entry? */
3224 if (entry == pool->next_free_entry)
3225 {
3226 if (entry >= MAX_LITERAL_POOL_SIZE)
3227 {
3228 inst.error = _("literal pool overflow");
3229 return FAIL;
3230 }
3231
8335d6aa
JW
3232 if (nbytes == 8)
3233 {
3234 /* For 8-byte entries, we align to an 8-byte boundary,
3235 and split it into two 4-byte entries, because on 32-bit
3236 host, 8-byte constants are treated as big num, thus
3237 saved in "generic_bignum" which will be overwritten
3238 by later assignments.
3239
3240 We also need to make sure there is enough space for
3241 the split.
3242
3243 We also check to make sure the literal operand is a
3244 constant number. */
19f2f6a9
JW
3245 if (!(inst.reloc.exp.X_op == O_constant
3246 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3247 {
3248 inst.error = _("invalid type for literal pool");
3249 return FAIL;
3250 }
3251 else if (pool_size & 0x7)
3252 {
3253 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3254 {
3255 inst.error = _("literal pool overflow");
3256 return FAIL;
3257 }
3258
3259 pool->literals[entry] = inst.reloc.exp;
3260 pool->literals[entry].X_add_number = 0;
3261 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3262 pool->next_free_entry += 1;
3263 pool_size += 4;
3264 }
3265 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3266 {
3267 inst.error = _("literal pool overflow");
3268 return FAIL;
3269 }
3270
3271 pool->literals[entry] = inst.reloc.exp;
3272 pool->literals[entry].X_op = O_constant;
3273 pool->literals[entry].X_add_number = imm1;
3274 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3275 pool->literals[entry++].X_md = 4;
3276 pool->literals[entry] = inst.reloc.exp;
3277 pool->literals[entry].X_op = O_constant;
3278 pool->literals[entry].X_add_number = imm2;
3279 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3280 pool->literals[entry].X_md = 4;
3281 pool->alignment = 3;
3282 pool->next_free_entry += 1;
3283 }
3284 else
3285 {
3286 pool->literals[entry] = inst.reloc.exp;
3287 pool->literals[entry].X_md = 4;
3288 }
3289
a8040cf2
NC
3290#ifdef OBJ_ELF
3291 /* PR ld/12974: Record the location of the first source line to reference
3292 this entry in the literal pool. If it turns out during linking that the
3293 symbol does not exist we will be able to give an accurate line number for
3294 the (first use of the) missing reference. */
3295 if (debug_type == DEBUG_DWARF2)
3296 dwarf2_where (pool->locs + entry);
3297#endif
c19d1205
ZW
3298 pool->next_free_entry += 1;
3299 }
8335d6aa
JW
3300 else if (padding_slot_p)
3301 {
3302 pool->literals[entry] = inst.reloc.exp;
3303 pool->literals[entry].X_md = nbytes;
3304 }
b99bd4ef 3305
c19d1205 3306 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3307 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3308 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3309
c19d1205 3310 return SUCCESS;
b99bd4ef
NC
3311}
3312
2e6976a8 3313bfd_boolean
2e57ce7b 3314tc_start_label_without_colon (void)
2e6976a8
DG
3315{
3316 bfd_boolean ret = TRUE;
3317
3318 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3319 {
2e57ce7b 3320 const char *label = input_line_pointer;
2e6976a8
DG
3321
3322 while (!is_end_of_line[(int) label[-1]])
3323 --label;
3324
3325 if (*label == '.')
3326 {
3327 as_bad (_("Invalid label '%s'"), label);
3328 ret = FALSE;
3329 }
3330
3331 asmfunc_debug (label);
3332
3333 asmfunc_state = WAITING_ENDASMFUNC;
3334 }
3335
3336 return ret;
3337}
3338
c19d1205
ZW
3339/* Can't use symbol_new here, so have to create a symbol and then at
3340 a later date assign it a value. Thats what these functions do. */
e16bb312 3341
c19d1205
ZW
3342static void
3343symbol_locate (symbolS * symbolP,
3344 const char * name, /* It is copied, the caller can modify. */
3345 segT segment, /* Segment identifier (SEG_<something>). */
3346 valueT valu, /* Symbol value. */
3347 fragS * frag) /* Associated fragment. */
3348{
e57e6ddc 3349 size_t name_length;
c19d1205 3350 char * preserved_copy_of_name;
e16bb312 3351
c19d1205
ZW
3352 name_length = strlen (name) + 1; /* +1 for \0. */
3353 obstack_grow (&notes, name, name_length);
21d799b5 3354 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3355
c19d1205
ZW
3356#ifdef tc_canonicalize_symbol_name
3357 preserved_copy_of_name =
3358 tc_canonicalize_symbol_name (preserved_copy_of_name);
3359#endif
b99bd4ef 3360
c19d1205 3361 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3362
c19d1205
ZW
3363 S_SET_SEGMENT (symbolP, segment);
3364 S_SET_VALUE (symbolP, valu);
3365 symbol_clear_list_pointers (symbolP);
b99bd4ef 3366
c19d1205 3367 symbol_set_frag (symbolP, frag);
b99bd4ef 3368
c19d1205
ZW
3369 /* Link to end of symbol chain. */
3370 {
3371 extern int symbol_table_frozen;
b99bd4ef 3372
c19d1205
ZW
3373 if (symbol_table_frozen)
3374 abort ();
3375 }
b99bd4ef 3376
c19d1205 3377 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3378
c19d1205 3379 obj_symbol_new_hook (symbolP);
b99bd4ef 3380
c19d1205
ZW
3381#ifdef tc_symbol_new_hook
3382 tc_symbol_new_hook (symbolP);
3383#endif
3384
3385#ifdef DEBUG_SYMS
3386 verify_symbol_chain (symbol_rootP, symbol_lastP);
3387#endif /* DEBUG_SYMS */
b99bd4ef
NC
3388}
3389
c19d1205
ZW
3390static void
3391s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3392{
c19d1205
ZW
3393 unsigned int entry;
3394 literal_pool * pool;
3395 char sym_name[20];
b99bd4ef 3396
c19d1205
ZW
3397 pool = find_literal_pool ();
3398 if (pool == NULL
3399 || pool->symbol == NULL
3400 || pool->next_free_entry == 0)
3401 return;
b99bd4ef 3402
c19d1205
ZW
3403 /* Align pool as you have word accesses.
3404 Only make a frag if we have to. */
3405 if (!need_pass_2)
8335d6aa 3406 frag_align (pool->alignment, 0, 0);
b99bd4ef 3407
c19d1205 3408 record_alignment (now_seg, 2);
b99bd4ef 3409
aaca88ef 3410#ifdef OBJ_ELF
47fc6e36
WN
3411 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3412 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3413#endif
c19d1205 3414 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3415
c19d1205
ZW
3416 symbol_locate (pool->symbol, sym_name, now_seg,
3417 (valueT) frag_now_fix (), frag_now);
3418 symbol_table_insert (pool->symbol);
b99bd4ef 3419
c19d1205 3420 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3421
c19d1205
ZW
3422#if defined OBJ_COFF || defined OBJ_ELF
3423 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3424#endif
6c43fab6 3425
c19d1205 3426 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3427 {
3428#ifdef OBJ_ELF
3429 if (debug_type == DEBUG_DWARF2)
3430 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3431#endif
3432 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3433 emit_expr (&(pool->literals[entry]),
3434 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3435 }
b99bd4ef 3436
c19d1205
ZW
3437 /* Mark the pool as empty. */
3438 pool->next_free_entry = 0;
3439 pool->symbol = NULL;
b99bd4ef
NC
3440}
3441
c19d1205
ZW
3442#ifdef OBJ_ELF
3443/* Forward declarations for functions below, in the MD interface
3444 section. */
3445static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3446static valueT create_unwind_entry (int);
3447static void start_unwind_section (const segT, int);
3448static void add_unwind_opcode (valueT, int);
3449static void flush_pending_unwind (void);
b99bd4ef 3450
c19d1205 3451/* Directives: Data. */
b99bd4ef 3452
c19d1205
ZW
3453static void
3454s_arm_elf_cons (int nbytes)
3455{
3456 expressionS exp;
b99bd4ef 3457
c19d1205
ZW
3458#ifdef md_flush_pending_output
3459 md_flush_pending_output ();
3460#endif
b99bd4ef 3461
c19d1205 3462 if (is_it_end_of_statement ())
b99bd4ef 3463 {
c19d1205
ZW
3464 demand_empty_rest_of_line ();
3465 return;
b99bd4ef
NC
3466 }
3467
c19d1205
ZW
3468#ifdef md_cons_align
3469 md_cons_align (nbytes);
3470#endif
b99bd4ef 3471
c19d1205
ZW
3472 mapping_state (MAP_DATA);
3473 do
b99bd4ef 3474 {
c19d1205
ZW
3475 int reloc;
3476 char *base = input_line_pointer;
b99bd4ef 3477
c19d1205 3478 expression (& exp);
b99bd4ef 3479
c19d1205
ZW
3480 if (exp.X_op != O_symbol)
3481 emit_expr (&exp, (unsigned int) nbytes);
3482 else
3483 {
3484 char *before_reloc = input_line_pointer;
3485 reloc = parse_reloc (&input_line_pointer);
3486 if (reloc == -1)
3487 {
3488 as_bad (_("unrecognized relocation suffix"));
3489 ignore_rest_of_line ();
3490 return;
3491 }
3492 else if (reloc == BFD_RELOC_UNUSED)
3493 emit_expr (&exp, (unsigned int) nbytes);
3494 else
3495 {
21d799b5 3496 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3497 bfd_reloc_type_lookup (stdoutput,
3498 (bfd_reloc_code_real_type) reloc);
c19d1205 3499 int size = bfd_get_reloc_size (howto);
b99bd4ef 3500
2fc8bdac
ZW
3501 if (reloc == BFD_RELOC_ARM_PLT32)
3502 {
3503 as_bad (_("(plt) is only valid on branch targets"));
3504 reloc = BFD_RELOC_UNUSED;
3505 size = 0;
3506 }
3507
c19d1205 3508 if (size > nbytes)
2fc8bdac 3509 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3510 howto->name, nbytes);
3511 else
3512 {
3513 /* We've parsed an expression stopping at O_symbol.
3514 But there may be more expression left now that we
3515 have parsed the relocation marker. Parse it again.
3516 XXX Surely there is a cleaner way to do this. */
3517 char *p = input_line_pointer;
3518 int offset;
21d799b5 3519 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3520 memcpy (save_buf, base, input_line_pointer - base);
3521 memmove (base + (input_line_pointer - before_reloc),
3522 base, before_reloc - base);
3523
3524 input_line_pointer = base + (input_line_pointer-before_reloc);
3525 expression (&exp);
3526 memcpy (base, save_buf, p - base);
3527
3528 offset = nbytes - size;
4b1a927e
AM
3529 p = frag_more (nbytes);
3530 memset (p, 0, nbytes);
c19d1205 3531 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3532 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3533 }
3534 }
3535 }
b99bd4ef 3536 }
c19d1205 3537 while (*input_line_pointer++ == ',');
b99bd4ef 3538
c19d1205
ZW
3539 /* Put terminator back into stream. */
3540 input_line_pointer --;
3541 demand_empty_rest_of_line ();
b99bd4ef
NC
3542}
3543
c921be7d
NC
3544/* Emit an expression containing a 32-bit thumb instruction.
3545 Implementation based on put_thumb32_insn. */
3546
3547static void
3548emit_thumb32_expr (expressionS * exp)
3549{
3550 expressionS exp_high = *exp;
3551
3552 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3553 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3554 exp->X_add_number &= 0xffff;
3555 emit_expr (exp, (unsigned int) THUMB_SIZE);
3556}
3557
3558/* Guess the instruction size based on the opcode. */
3559
3560static int
3561thumb_insn_size (int opcode)
3562{
3563 if ((unsigned int) opcode < 0xe800u)
3564 return 2;
3565 else if ((unsigned int) opcode >= 0xe8000000u)
3566 return 4;
3567 else
3568 return 0;
3569}
3570
3571static bfd_boolean
3572emit_insn (expressionS *exp, int nbytes)
3573{
3574 int size = 0;
3575
3576 if (exp->X_op == O_constant)
3577 {
3578 size = nbytes;
3579
3580 if (size == 0)
3581 size = thumb_insn_size (exp->X_add_number);
3582
3583 if (size != 0)
3584 {
3585 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3586 {
3587 as_bad (_(".inst.n operand too big. "\
3588 "Use .inst.w instead"));
3589 size = 0;
3590 }
3591 else
3592 {
3593 if (now_it.state == AUTOMATIC_IT_BLOCK)
3594 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3595 else
3596 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3597
3598 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3599 emit_thumb32_expr (exp);
3600 else
3601 emit_expr (exp, (unsigned int) size);
3602
3603 it_fsm_post_encode ();
3604 }
3605 }
3606 else
3607 as_bad (_("cannot determine Thumb instruction size. " \
3608 "Use .inst.n/.inst.w instead"));
3609 }
3610 else
3611 as_bad (_("constant expression required"));
3612
3613 return (size != 0);
3614}
3615
3616/* Like s_arm_elf_cons but do not use md_cons_align and
3617 set the mapping state to MAP_ARM/MAP_THUMB. */
3618
3619static void
3620s_arm_elf_inst (int nbytes)
3621{
3622 if (is_it_end_of_statement ())
3623 {
3624 demand_empty_rest_of_line ();
3625 return;
3626 }
3627
3628 /* Calling mapping_state () here will not change ARM/THUMB,
3629 but will ensure not to be in DATA state. */
3630
3631 if (thumb_mode)
3632 mapping_state (MAP_THUMB);
3633 else
3634 {
3635 if (nbytes != 0)
3636 {
3637 as_bad (_("width suffixes are invalid in ARM mode"));
3638 ignore_rest_of_line ();
3639 return;
3640 }
3641
3642 nbytes = 4;
3643
3644 mapping_state (MAP_ARM);
3645 }
3646
3647 do
3648 {
3649 expressionS exp;
3650
3651 expression (& exp);
3652
3653 if (! emit_insn (& exp, nbytes))
3654 {
3655 ignore_rest_of_line ();
3656 return;
3657 }
3658 }
3659 while (*input_line_pointer++ == ',');
3660
3661 /* Put terminator back into stream. */
3662 input_line_pointer --;
3663 demand_empty_rest_of_line ();
3664}
b99bd4ef 3665
c19d1205 3666/* Parse a .rel31 directive. */
b99bd4ef 3667
c19d1205
ZW
3668static void
3669s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3670{
3671 expressionS exp;
3672 char *p;
3673 valueT highbit;
b99bd4ef 3674
c19d1205
ZW
3675 highbit = 0;
3676 if (*input_line_pointer == '1')
3677 highbit = 0x80000000;
3678 else if (*input_line_pointer != '0')
3679 as_bad (_("expected 0 or 1"));
b99bd4ef 3680
c19d1205
ZW
3681 input_line_pointer++;
3682 if (*input_line_pointer != ',')
3683 as_bad (_("missing comma"));
3684 input_line_pointer++;
b99bd4ef 3685
c19d1205
ZW
3686#ifdef md_flush_pending_output
3687 md_flush_pending_output ();
3688#endif
b99bd4ef 3689
c19d1205
ZW
3690#ifdef md_cons_align
3691 md_cons_align (4);
3692#endif
b99bd4ef 3693
c19d1205 3694 mapping_state (MAP_DATA);
b99bd4ef 3695
c19d1205 3696 expression (&exp);
b99bd4ef 3697
c19d1205
ZW
3698 p = frag_more (4);
3699 md_number_to_chars (p, highbit, 4);
3700 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3701 BFD_RELOC_ARM_PREL31);
b99bd4ef 3702
c19d1205 3703 demand_empty_rest_of_line ();
b99bd4ef
NC
3704}
3705
c19d1205 3706/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3707
c19d1205 3708/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3709
c19d1205
ZW
3710static void
3711s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3712{
3713 demand_empty_rest_of_line ();
921e5f0a
PB
3714 if (unwind.proc_start)
3715 {
c921be7d 3716 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3717 return;
3718 }
3719
c19d1205
ZW
3720 /* Mark the start of the function. */
3721 unwind.proc_start = expr_build_dot ();
b99bd4ef 3722
c19d1205
ZW
3723 /* Reset the rest of the unwind info. */
3724 unwind.opcode_count = 0;
3725 unwind.table_entry = NULL;
3726 unwind.personality_routine = NULL;
3727 unwind.personality_index = -1;
3728 unwind.frame_size = 0;
3729 unwind.fp_offset = 0;
fdfde340 3730 unwind.fp_reg = REG_SP;
c19d1205
ZW
3731 unwind.fp_used = 0;
3732 unwind.sp_restored = 0;
3733}
b99bd4ef 3734
b99bd4ef 3735
c19d1205
ZW
3736/* Parse a handlerdata directive. Creates the exception handling table entry
3737 for the function. */
b99bd4ef 3738
c19d1205
ZW
3739static void
3740s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3741{
3742 demand_empty_rest_of_line ();
921e5f0a 3743 if (!unwind.proc_start)
c921be7d 3744 as_bad (MISSING_FNSTART);
921e5f0a 3745
c19d1205 3746 if (unwind.table_entry)
6decc662 3747 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3748
c19d1205
ZW
3749 create_unwind_entry (1);
3750}
a737bd4d 3751
c19d1205 3752/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3753
c19d1205
ZW
3754static void
3755s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3756{
3757 long where;
3758 char *ptr;
3759 valueT val;
940b5ce0 3760 unsigned int marked_pr_dependency;
f02232aa 3761
c19d1205 3762 demand_empty_rest_of_line ();
f02232aa 3763
921e5f0a
PB
3764 if (!unwind.proc_start)
3765 {
c921be7d 3766 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3767 return;
3768 }
3769
c19d1205
ZW
3770 /* Add eh table entry. */
3771 if (unwind.table_entry == NULL)
3772 val = create_unwind_entry (0);
3773 else
3774 val = 0;
f02232aa 3775
c19d1205
ZW
3776 /* Add index table entry. This is two words. */
3777 start_unwind_section (unwind.saved_seg, 1);
3778 frag_align (2, 0, 0);
3779 record_alignment (now_seg, 2);
b99bd4ef 3780
c19d1205 3781 ptr = frag_more (8);
5011093d 3782 memset (ptr, 0, 8);
c19d1205 3783 where = frag_now_fix () - 8;
f02232aa 3784
c19d1205
ZW
3785 /* Self relative offset of the function start. */
3786 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3787 BFD_RELOC_ARM_PREL31);
f02232aa 3788
c19d1205
ZW
3789 /* Indicate dependency on EHABI-defined personality routines to the
3790 linker, if it hasn't been done already. */
940b5ce0
DJ
3791 marked_pr_dependency
3792 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3793 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3794 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3795 {
5f4273c7
NC
3796 static const char *const name[] =
3797 {
3798 "__aeabi_unwind_cpp_pr0",
3799 "__aeabi_unwind_cpp_pr1",
3800 "__aeabi_unwind_cpp_pr2"
3801 };
c19d1205
ZW
3802 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3803 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3804 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3805 |= 1 << unwind.personality_index;
c19d1205 3806 }
f02232aa 3807
c19d1205
ZW
3808 if (val)
3809 /* Inline exception table entry. */
3810 md_number_to_chars (ptr + 4, val, 4);
3811 else
3812 /* Self relative offset of the table entry. */
3813 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3814 BFD_RELOC_ARM_PREL31);
f02232aa 3815
c19d1205
ZW
3816 /* Restore the original section. */
3817 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3818
3819 unwind.proc_start = NULL;
c19d1205 3820}
f02232aa 3821
f02232aa 3822
c19d1205 3823/* Parse an unwind_cantunwind directive. */
b99bd4ef 3824
c19d1205
ZW
3825static void
3826s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3827{
3828 demand_empty_rest_of_line ();
921e5f0a 3829 if (!unwind.proc_start)
c921be7d 3830 as_bad (MISSING_FNSTART);
921e5f0a 3831
c19d1205
ZW
3832 if (unwind.personality_routine || unwind.personality_index != -1)
3833 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3834
c19d1205
ZW
3835 unwind.personality_index = -2;
3836}
b99bd4ef 3837
b99bd4ef 3838
c19d1205 3839/* Parse a personalityindex directive. */
b99bd4ef 3840
c19d1205
ZW
3841static void
3842s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3843{
3844 expressionS exp;
b99bd4ef 3845
921e5f0a 3846 if (!unwind.proc_start)
c921be7d 3847 as_bad (MISSING_FNSTART);
921e5f0a 3848
c19d1205
ZW
3849 if (unwind.personality_routine || unwind.personality_index != -1)
3850 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3851
c19d1205 3852 expression (&exp);
b99bd4ef 3853
c19d1205
ZW
3854 if (exp.X_op != O_constant
3855 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3856 {
c19d1205
ZW
3857 as_bad (_("bad personality routine number"));
3858 ignore_rest_of_line ();
3859 return;
b99bd4ef
NC
3860 }
3861
c19d1205 3862 unwind.personality_index = exp.X_add_number;
b99bd4ef 3863
c19d1205
ZW
3864 demand_empty_rest_of_line ();
3865}
e16bb312 3866
e16bb312 3867
c19d1205 3868/* Parse a personality directive. */
e16bb312 3869
c19d1205
ZW
3870static void
3871s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3872{
3873 char *name, *p, c;
a737bd4d 3874
921e5f0a 3875 if (!unwind.proc_start)
c921be7d 3876 as_bad (MISSING_FNSTART);
921e5f0a 3877
c19d1205
ZW
3878 if (unwind.personality_routine || unwind.personality_index != -1)
3879 as_bad (_("duplicate .personality directive"));
a737bd4d 3880
d02603dc 3881 c = get_symbol_name (& name);
c19d1205 3882 p = input_line_pointer;
d02603dc
NC
3883 if (c == '"')
3884 ++ input_line_pointer;
c19d1205
ZW
3885 unwind.personality_routine = symbol_find_or_make (name);
3886 *p = c;
3887 demand_empty_rest_of_line ();
3888}
e16bb312 3889
e16bb312 3890
c19d1205 3891/* Parse a directive saving core registers. */
e16bb312 3892
c19d1205
ZW
3893static void
3894s_arm_unwind_save_core (void)
e16bb312 3895{
c19d1205
ZW
3896 valueT op;
3897 long range;
3898 int n;
e16bb312 3899
c19d1205
ZW
3900 range = parse_reg_list (&input_line_pointer);
3901 if (range == FAIL)
e16bb312 3902 {
c19d1205
ZW
3903 as_bad (_("expected register list"));
3904 ignore_rest_of_line ();
3905 return;
3906 }
e16bb312 3907
c19d1205 3908 demand_empty_rest_of_line ();
e16bb312 3909
c19d1205
ZW
3910 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3911 into .unwind_save {..., sp...}. We aren't bothered about the value of
3912 ip because it is clobbered by calls. */
3913 if (unwind.sp_restored && unwind.fp_reg == 12
3914 && (range & 0x3000) == 0x1000)
3915 {
3916 unwind.opcode_count--;
3917 unwind.sp_restored = 0;
3918 range = (range | 0x2000) & ~0x1000;
3919 unwind.pending_offset = 0;
3920 }
e16bb312 3921
01ae4198
DJ
3922 /* Pop r4-r15. */
3923 if (range & 0xfff0)
c19d1205 3924 {
01ae4198
DJ
3925 /* See if we can use the short opcodes. These pop a block of up to 8
3926 registers starting with r4, plus maybe r14. */
3927 for (n = 0; n < 8; n++)
3928 {
3929 /* Break at the first non-saved register. */
3930 if ((range & (1 << (n + 4))) == 0)
3931 break;
3932 }
3933 /* See if there are any other bits set. */
3934 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3935 {
3936 /* Use the long form. */
3937 op = 0x8000 | ((range >> 4) & 0xfff);
3938 add_unwind_opcode (op, 2);
3939 }
0dd132b6 3940 else
01ae4198
DJ
3941 {
3942 /* Use the short form. */
3943 if (range & 0x4000)
3944 op = 0xa8; /* Pop r14. */
3945 else
3946 op = 0xa0; /* Do not pop r14. */
3947 op |= (n - 1);
3948 add_unwind_opcode (op, 1);
3949 }
c19d1205 3950 }
0dd132b6 3951
c19d1205
ZW
3952 /* Pop r0-r3. */
3953 if (range & 0xf)
3954 {
3955 op = 0xb100 | (range & 0xf);
3956 add_unwind_opcode (op, 2);
0dd132b6
NC
3957 }
3958
c19d1205
ZW
3959 /* Record the number of bytes pushed. */
3960 for (n = 0; n < 16; n++)
3961 {
3962 if (range & (1 << n))
3963 unwind.frame_size += 4;
3964 }
0dd132b6
NC
3965}
3966
c19d1205
ZW
3967
3968/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3969
3970static void
c19d1205 3971s_arm_unwind_save_fpa (int reg)
b99bd4ef 3972{
c19d1205
ZW
3973 expressionS exp;
3974 int num_regs;
3975 valueT op;
b99bd4ef 3976
c19d1205
ZW
3977 /* Get Number of registers to transfer. */
3978 if (skip_past_comma (&input_line_pointer) != FAIL)
3979 expression (&exp);
3980 else
3981 exp.X_op = O_illegal;
b99bd4ef 3982
c19d1205 3983 if (exp.X_op != O_constant)
b99bd4ef 3984 {
c19d1205
ZW
3985 as_bad (_("expected , <constant>"));
3986 ignore_rest_of_line ();
b99bd4ef
NC
3987 return;
3988 }
3989
c19d1205
ZW
3990 num_regs = exp.X_add_number;
3991
3992 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3993 {
c19d1205
ZW
3994 as_bad (_("number of registers must be in the range [1:4]"));
3995 ignore_rest_of_line ();
b99bd4ef
NC
3996 return;
3997 }
3998
c19d1205 3999 demand_empty_rest_of_line ();
b99bd4ef 4000
c19d1205
ZW
4001 if (reg == 4)
4002 {
4003 /* Short form. */
4004 op = 0xb4 | (num_regs - 1);
4005 add_unwind_opcode (op, 1);
4006 }
b99bd4ef
NC
4007 else
4008 {
c19d1205
ZW
4009 /* Long form. */
4010 op = 0xc800 | (reg << 4) | (num_regs - 1);
4011 add_unwind_opcode (op, 2);
b99bd4ef 4012 }
c19d1205 4013 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4014}
4015
c19d1205 4016
fa073d69
MS
4017/* Parse a directive saving VFP registers for ARMv6 and above. */
4018
4019static void
4020s_arm_unwind_save_vfp_armv6 (void)
4021{
4022 int count;
4023 unsigned int start;
4024 valueT op;
4025 int num_vfpv3_regs = 0;
4026 int num_regs_below_16;
4027
4028 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4029 if (count == FAIL)
4030 {
4031 as_bad (_("expected register list"));
4032 ignore_rest_of_line ();
4033 return;
4034 }
4035
4036 demand_empty_rest_of_line ();
4037
4038 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4039 than FSTMX/FLDMX-style ones). */
4040
4041 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4042 if (start >= 16)
4043 num_vfpv3_regs = count;
4044 else if (start + count > 16)
4045 num_vfpv3_regs = start + count - 16;
4046
4047 if (num_vfpv3_regs > 0)
4048 {
4049 int start_offset = start > 16 ? start - 16 : 0;
4050 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4051 add_unwind_opcode (op, 2);
4052 }
4053
4054 /* Generate opcode for registers numbered in the range 0 .. 15. */
4055 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4056 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4057 if (num_regs_below_16 > 0)
4058 {
4059 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4060 add_unwind_opcode (op, 2);
4061 }
4062
4063 unwind.frame_size += count * 8;
4064}
4065
4066
4067/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4068
4069static void
c19d1205 4070s_arm_unwind_save_vfp (void)
b99bd4ef 4071{
c19d1205 4072 int count;
ca3f61f7 4073 unsigned int reg;
c19d1205 4074 valueT op;
b99bd4ef 4075
5287ad62 4076 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4077 if (count == FAIL)
b99bd4ef 4078 {
c19d1205
ZW
4079 as_bad (_("expected register list"));
4080 ignore_rest_of_line ();
b99bd4ef
NC
4081 return;
4082 }
4083
c19d1205 4084 demand_empty_rest_of_line ();
b99bd4ef 4085
c19d1205 4086 if (reg == 8)
b99bd4ef 4087 {
c19d1205
ZW
4088 /* Short form. */
4089 op = 0xb8 | (count - 1);
4090 add_unwind_opcode (op, 1);
b99bd4ef 4091 }
c19d1205 4092 else
b99bd4ef 4093 {
c19d1205
ZW
4094 /* Long form. */
4095 op = 0xb300 | (reg << 4) | (count - 1);
4096 add_unwind_opcode (op, 2);
b99bd4ef 4097 }
c19d1205
ZW
4098 unwind.frame_size += count * 8 + 4;
4099}
b99bd4ef 4100
b99bd4ef 4101
c19d1205
ZW
4102/* Parse a directive saving iWMMXt data registers. */
4103
4104static void
4105s_arm_unwind_save_mmxwr (void)
4106{
4107 int reg;
4108 int hi_reg;
4109 int i;
4110 unsigned mask = 0;
4111 valueT op;
b99bd4ef 4112
c19d1205
ZW
4113 if (*input_line_pointer == '{')
4114 input_line_pointer++;
b99bd4ef 4115
c19d1205 4116 do
b99bd4ef 4117 {
dcbf9037 4118 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4119
c19d1205 4120 if (reg == FAIL)
b99bd4ef 4121 {
9b7132d3 4122 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4123 goto error;
b99bd4ef
NC
4124 }
4125
c19d1205
ZW
4126 if (mask >> reg)
4127 as_tsktsk (_("register list not in ascending order"));
4128 mask |= 1 << reg;
b99bd4ef 4129
c19d1205
ZW
4130 if (*input_line_pointer == '-')
4131 {
4132 input_line_pointer++;
dcbf9037 4133 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4134 if (hi_reg == FAIL)
4135 {
9b7132d3 4136 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4137 goto error;
4138 }
4139 else if (reg >= hi_reg)
4140 {
4141 as_bad (_("bad register range"));
4142 goto error;
4143 }
4144 for (; reg < hi_reg; reg++)
4145 mask |= 1 << reg;
4146 }
4147 }
4148 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4149
d996d970 4150 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4151
c19d1205 4152 demand_empty_rest_of_line ();
b99bd4ef 4153
708587a4 4154 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4155 the list. */
4156 flush_pending_unwind ();
b99bd4ef 4157
c19d1205 4158 for (i = 0; i < 16; i++)
b99bd4ef 4159 {
c19d1205
ZW
4160 if (mask & (1 << i))
4161 unwind.frame_size += 8;
b99bd4ef
NC
4162 }
4163
c19d1205
ZW
4164 /* Attempt to combine with a previous opcode. We do this because gcc
4165 likes to output separate unwind directives for a single block of
4166 registers. */
4167 if (unwind.opcode_count > 0)
b99bd4ef 4168 {
c19d1205
ZW
4169 i = unwind.opcodes[unwind.opcode_count - 1];
4170 if ((i & 0xf8) == 0xc0)
4171 {
4172 i &= 7;
4173 /* Only merge if the blocks are contiguous. */
4174 if (i < 6)
4175 {
4176 if ((mask & 0xfe00) == (1 << 9))
4177 {
4178 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4179 unwind.opcode_count--;
4180 }
4181 }
4182 else if (i == 6 && unwind.opcode_count >= 2)
4183 {
4184 i = unwind.opcodes[unwind.opcode_count - 2];
4185 reg = i >> 4;
4186 i &= 0xf;
b99bd4ef 4187
c19d1205
ZW
4188 op = 0xffff << (reg - 1);
4189 if (reg > 0
87a1fd79 4190 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4191 {
4192 op = (1 << (reg + i + 1)) - 1;
4193 op &= ~((1 << reg) - 1);
4194 mask |= op;
4195 unwind.opcode_count -= 2;
4196 }
4197 }
4198 }
b99bd4ef
NC
4199 }
4200
c19d1205
ZW
4201 hi_reg = 15;
4202 /* We want to generate opcodes in the order the registers have been
4203 saved, ie. descending order. */
4204 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4205 {
c19d1205
ZW
4206 /* Save registers in blocks. */
4207 if (reg < 0
4208 || !(mask & (1 << reg)))
4209 {
4210 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4211 preceding block. */
c19d1205
ZW
4212 if (reg != hi_reg)
4213 {
4214 if (reg == 9)
4215 {
4216 /* Short form. */
4217 op = 0xc0 | (hi_reg - 10);
4218 add_unwind_opcode (op, 1);
4219 }
4220 else
4221 {
4222 /* Long form. */
4223 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4224 add_unwind_opcode (op, 2);
4225 }
4226 }
4227 hi_reg = reg - 1;
4228 }
b99bd4ef
NC
4229 }
4230
c19d1205
ZW
4231 return;
4232error:
4233 ignore_rest_of_line ();
b99bd4ef
NC
4234}
4235
4236static void
c19d1205 4237s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4238{
c19d1205
ZW
4239 int reg;
4240 int hi_reg;
4241 unsigned mask = 0;
4242 valueT op;
b99bd4ef 4243
c19d1205
ZW
4244 if (*input_line_pointer == '{')
4245 input_line_pointer++;
b99bd4ef 4246
477330fc
RM
4247 skip_whitespace (input_line_pointer);
4248
c19d1205 4249 do
b99bd4ef 4250 {
dcbf9037 4251 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4252
c19d1205
ZW
4253 if (reg == FAIL)
4254 {
9b7132d3 4255 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4256 goto error;
4257 }
b99bd4ef 4258
c19d1205
ZW
4259 reg -= 8;
4260 if (mask >> reg)
4261 as_tsktsk (_("register list not in ascending order"));
4262 mask |= 1 << reg;
b99bd4ef 4263
c19d1205
ZW
4264 if (*input_line_pointer == '-')
4265 {
4266 input_line_pointer++;
dcbf9037 4267 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4268 if (hi_reg == FAIL)
4269 {
9b7132d3 4270 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4271 goto error;
4272 }
4273 else if (reg >= hi_reg)
4274 {
4275 as_bad (_("bad register range"));
4276 goto error;
4277 }
4278 for (; reg < hi_reg; reg++)
4279 mask |= 1 << reg;
4280 }
b99bd4ef 4281 }
c19d1205 4282 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4283
d996d970 4284 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4285
c19d1205
ZW
4286 demand_empty_rest_of_line ();
4287
708587a4 4288 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4289 the list. */
4290 flush_pending_unwind ();
b99bd4ef 4291
c19d1205 4292 for (reg = 0; reg < 16; reg++)
b99bd4ef 4293 {
c19d1205
ZW
4294 if (mask & (1 << reg))
4295 unwind.frame_size += 4;
b99bd4ef 4296 }
c19d1205
ZW
4297 op = 0xc700 | mask;
4298 add_unwind_opcode (op, 2);
4299 return;
4300error:
4301 ignore_rest_of_line ();
b99bd4ef
NC
4302}
4303
c19d1205 4304
fa073d69
MS
4305/* Parse an unwind_save directive.
4306 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4307
b99bd4ef 4308static void
fa073d69 4309s_arm_unwind_save (int arch_v6)
b99bd4ef 4310{
c19d1205
ZW
4311 char *peek;
4312 struct reg_entry *reg;
4313 bfd_boolean had_brace = FALSE;
b99bd4ef 4314
921e5f0a 4315 if (!unwind.proc_start)
c921be7d 4316 as_bad (MISSING_FNSTART);
921e5f0a 4317
c19d1205
ZW
4318 /* Figure out what sort of save we have. */
4319 peek = input_line_pointer;
b99bd4ef 4320
c19d1205 4321 if (*peek == '{')
b99bd4ef 4322 {
c19d1205
ZW
4323 had_brace = TRUE;
4324 peek++;
b99bd4ef
NC
4325 }
4326
c19d1205 4327 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4328
c19d1205 4329 if (!reg)
b99bd4ef 4330 {
c19d1205
ZW
4331 as_bad (_("register expected"));
4332 ignore_rest_of_line ();
b99bd4ef
NC
4333 return;
4334 }
4335
c19d1205 4336 switch (reg->type)
b99bd4ef 4337 {
c19d1205
ZW
4338 case REG_TYPE_FN:
4339 if (had_brace)
4340 {
4341 as_bad (_("FPA .unwind_save does not take a register list"));
4342 ignore_rest_of_line ();
4343 return;
4344 }
93ac2687 4345 input_line_pointer = peek;
c19d1205 4346 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4347 return;
c19d1205 4348
1f5afe1c
NC
4349 case REG_TYPE_RN:
4350 s_arm_unwind_save_core ();
4351 return;
4352
fa073d69
MS
4353 case REG_TYPE_VFD:
4354 if (arch_v6)
477330fc 4355 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4356 else
477330fc 4357 s_arm_unwind_save_vfp ();
fa073d69 4358 return;
1f5afe1c
NC
4359
4360 case REG_TYPE_MMXWR:
4361 s_arm_unwind_save_mmxwr ();
4362 return;
4363
4364 case REG_TYPE_MMXWCG:
4365 s_arm_unwind_save_mmxwcg ();
4366 return;
c19d1205
ZW
4367
4368 default:
4369 as_bad (_(".unwind_save does not support this kind of register"));
4370 ignore_rest_of_line ();
b99bd4ef 4371 }
c19d1205 4372}
b99bd4ef 4373
b99bd4ef 4374
c19d1205
ZW
4375/* Parse an unwind_movsp directive. */
4376
4377static void
4378s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4379{
4380 int reg;
4381 valueT op;
4fa3602b 4382 int offset;
c19d1205 4383
921e5f0a 4384 if (!unwind.proc_start)
c921be7d 4385 as_bad (MISSING_FNSTART);
921e5f0a 4386
dcbf9037 4387 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4388 if (reg == FAIL)
b99bd4ef 4389 {
9b7132d3 4390 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4391 ignore_rest_of_line ();
b99bd4ef
NC
4392 return;
4393 }
4fa3602b
PB
4394
4395 /* Optional constant. */
4396 if (skip_past_comma (&input_line_pointer) != FAIL)
4397 {
4398 if (immediate_for_directive (&offset) == FAIL)
4399 return;
4400 }
4401 else
4402 offset = 0;
4403
c19d1205 4404 demand_empty_rest_of_line ();
b99bd4ef 4405
c19d1205 4406 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4407 {
c19d1205 4408 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4409 return;
4410 }
4411
c19d1205
ZW
4412 if (unwind.fp_reg != REG_SP)
4413 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4414
c19d1205
ZW
4415 /* Generate opcode to restore the value. */
4416 op = 0x90 | reg;
4417 add_unwind_opcode (op, 1);
4418
4419 /* Record the information for later. */
4420 unwind.fp_reg = reg;
4fa3602b 4421 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4422 unwind.sp_restored = 1;
b05fe5cf
ZW
4423}
4424
c19d1205
ZW
4425/* Parse an unwind_pad directive. */
4426
b05fe5cf 4427static void
c19d1205 4428s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4429{
c19d1205 4430 int offset;
b05fe5cf 4431
921e5f0a 4432 if (!unwind.proc_start)
c921be7d 4433 as_bad (MISSING_FNSTART);
921e5f0a 4434
c19d1205
ZW
4435 if (immediate_for_directive (&offset) == FAIL)
4436 return;
b99bd4ef 4437
c19d1205
ZW
4438 if (offset & 3)
4439 {
4440 as_bad (_("stack increment must be multiple of 4"));
4441 ignore_rest_of_line ();
4442 return;
4443 }
b99bd4ef 4444
c19d1205
ZW
4445 /* Don't generate any opcodes, just record the details for later. */
4446 unwind.frame_size += offset;
4447 unwind.pending_offset += offset;
4448
4449 demand_empty_rest_of_line ();
4450}
4451
4452/* Parse an unwind_setfp directive. */
4453
4454static void
4455s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4456{
c19d1205
ZW
4457 int sp_reg;
4458 int fp_reg;
4459 int offset;
4460
921e5f0a 4461 if (!unwind.proc_start)
c921be7d 4462 as_bad (MISSING_FNSTART);
921e5f0a 4463
dcbf9037 4464 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4465 if (skip_past_comma (&input_line_pointer) == FAIL)
4466 sp_reg = FAIL;
4467 else
dcbf9037 4468 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4469
c19d1205
ZW
4470 if (fp_reg == FAIL || sp_reg == FAIL)
4471 {
4472 as_bad (_("expected <reg>, <reg>"));
4473 ignore_rest_of_line ();
4474 return;
4475 }
b99bd4ef 4476
c19d1205
ZW
4477 /* Optional constant. */
4478 if (skip_past_comma (&input_line_pointer) != FAIL)
4479 {
4480 if (immediate_for_directive (&offset) == FAIL)
4481 return;
4482 }
4483 else
4484 offset = 0;
a737bd4d 4485
c19d1205 4486 demand_empty_rest_of_line ();
a737bd4d 4487
fdfde340 4488 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4489 {
c19d1205
ZW
4490 as_bad (_("register must be either sp or set by a previous"
4491 "unwind_movsp directive"));
4492 return;
a737bd4d
NC
4493 }
4494
c19d1205
ZW
4495 /* Don't generate any opcodes, just record the information for later. */
4496 unwind.fp_reg = fp_reg;
4497 unwind.fp_used = 1;
fdfde340 4498 if (sp_reg == REG_SP)
c19d1205
ZW
4499 unwind.fp_offset = unwind.frame_size - offset;
4500 else
4501 unwind.fp_offset -= offset;
a737bd4d
NC
4502}
4503
c19d1205
ZW
4504/* Parse an unwind_raw directive. */
4505
4506static void
4507s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4508{
c19d1205 4509 expressionS exp;
708587a4 4510 /* This is an arbitrary limit. */
c19d1205
ZW
4511 unsigned char op[16];
4512 int count;
a737bd4d 4513
921e5f0a 4514 if (!unwind.proc_start)
c921be7d 4515 as_bad (MISSING_FNSTART);
921e5f0a 4516
c19d1205
ZW
4517 expression (&exp);
4518 if (exp.X_op == O_constant
4519 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4520 {
c19d1205
ZW
4521 unwind.frame_size += exp.X_add_number;
4522 expression (&exp);
4523 }
4524 else
4525 exp.X_op = O_illegal;
a737bd4d 4526
c19d1205
ZW
4527 if (exp.X_op != O_constant)
4528 {
4529 as_bad (_("expected <offset>, <opcode>"));
4530 ignore_rest_of_line ();
4531 return;
4532 }
a737bd4d 4533
c19d1205 4534 count = 0;
a737bd4d 4535
c19d1205
ZW
4536 /* Parse the opcode. */
4537 for (;;)
4538 {
4539 if (count >= 16)
4540 {
4541 as_bad (_("unwind opcode too long"));
4542 ignore_rest_of_line ();
a737bd4d 4543 }
c19d1205 4544 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4545 {
c19d1205
ZW
4546 as_bad (_("invalid unwind opcode"));
4547 ignore_rest_of_line ();
4548 return;
a737bd4d 4549 }
c19d1205 4550 op[count++] = exp.X_add_number;
a737bd4d 4551
c19d1205
ZW
4552 /* Parse the next byte. */
4553 if (skip_past_comma (&input_line_pointer) == FAIL)
4554 break;
a737bd4d 4555
c19d1205
ZW
4556 expression (&exp);
4557 }
b99bd4ef 4558
c19d1205
ZW
4559 /* Add the opcode bytes in reverse order. */
4560 while (count--)
4561 add_unwind_opcode (op[count], 1);
b99bd4ef 4562
c19d1205 4563 demand_empty_rest_of_line ();
b99bd4ef 4564}
ee065d83
PB
4565
4566
4567/* Parse a .eabi_attribute directive. */
4568
4569static void
4570s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4571{
0420f52b 4572 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4573
4574 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4575 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4576}
4577
0855e32b
NS
4578/* Emit a tls fix for the symbol. */
4579
4580static void
4581s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4582{
4583 char *p;
4584 expressionS exp;
4585#ifdef md_flush_pending_output
4586 md_flush_pending_output ();
4587#endif
4588
4589#ifdef md_cons_align
4590 md_cons_align (4);
4591#endif
4592
4593 /* Since we're just labelling the code, there's no need to define a
4594 mapping symbol. */
4595 expression (&exp);
4596 p = obstack_next_free (&frchain_now->frch_obstack);
4597 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4598 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4599 : BFD_RELOC_ARM_TLS_DESCSEQ);
4600}
cdf9ccec 4601#endif /* OBJ_ELF */
0855e32b 4602
ee065d83 4603static void s_arm_arch (int);
7a1d4c38 4604static void s_arm_object_arch (int);
ee065d83
PB
4605static void s_arm_cpu (int);
4606static void s_arm_fpu (int);
69133863 4607static void s_arm_arch_extension (int);
b99bd4ef 4608
f0927246
NC
4609#ifdef TE_PE
4610
4611static void
5f4273c7 4612pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4613{
4614 expressionS exp;
4615
4616 do
4617 {
4618 expression (&exp);
4619 if (exp.X_op == O_symbol)
4620 exp.X_op = O_secrel;
4621
4622 emit_expr (&exp, 4);
4623 }
4624 while (*input_line_pointer++ == ',');
4625
4626 input_line_pointer--;
4627 demand_empty_rest_of_line ();
4628}
4629#endif /* TE_PE */
4630
c19d1205
ZW
4631/* This table describes all the machine specific pseudo-ops the assembler
4632 has to support. The fields are:
4633 pseudo-op name without dot
4634 function to call to execute this pseudo-op
4635 Integer arg to pass to the function. */
b99bd4ef 4636
c19d1205 4637const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4638{
c19d1205
ZW
4639 /* Never called because '.req' does not start a line. */
4640 { "req", s_req, 0 },
dcbf9037
JB
4641 /* Following two are likewise never called. */
4642 { "dn", s_dn, 0 },
4643 { "qn", s_qn, 0 },
c19d1205
ZW
4644 { "unreq", s_unreq, 0 },
4645 { "bss", s_bss, 0 },
db2ed2e0 4646 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4647 { "arm", s_arm, 0 },
4648 { "thumb", s_thumb, 0 },
4649 { "code", s_code, 0 },
4650 { "force_thumb", s_force_thumb, 0 },
4651 { "thumb_func", s_thumb_func, 0 },
4652 { "thumb_set", s_thumb_set, 0 },
4653 { "even", s_even, 0 },
4654 { "ltorg", s_ltorg, 0 },
4655 { "pool", s_ltorg, 0 },
4656 { "syntax", s_syntax, 0 },
8463be01
PB
4657 { "cpu", s_arm_cpu, 0 },
4658 { "arch", s_arm_arch, 0 },
7a1d4c38 4659 { "object_arch", s_arm_object_arch, 0 },
8463be01 4660 { "fpu", s_arm_fpu, 0 },
69133863 4661 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4662#ifdef OBJ_ELF
c921be7d
NC
4663 { "word", s_arm_elf_cons, 4 },
4664 { "long", s_arm_elf_cons, 4 },
4665 { "inst.n", s_arm_elf_inst, 2 },
4666 { "inst.w", s_arm_elf_inst, 4 },
4667 { "inst", s_arm_elf_inst, 0 },
4668 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4669 { "fnstart", s_arm_unwind_fnstart, 0 },
4670 { "fnend", s_arm_unwind_fnend, 0 },
4671 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4672 { "personality", s_arm_unwind_personality, 0 },
4673 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4674 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4675 { "save", s_arm_unwind_save, 0 },
fa073d69 4676 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4677 { "movsp", s_arm_unwind_movsp, 0 },
4678 { "pad", s_arm_unwind_pad, 0 },
4679 { "setfp", s_arm_unwind_setfp, 0 },
4680 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4681 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4682 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4683#else
4684 { "word", cons, 4},
f0927246
NC
4685
4686 /* These are used for dwarf. */
4687 {"2byte", cons, 2},
4688 {"4byte", cons, 4},
4689 {"8byte", cons, 8},
4690 /* These are used for dwarf2. */
4691 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4692 { "loc", dwarf2_directive_loc, 0 },
4693 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4694#endif
4695 { "extend", float_cons, 'x' },
4696 { "ldouble", float_cons, 'x' },
4697 { "packed", float_cons, 'p' },
f0927246
NC
4698#ifdef TE_PE
4699 {"secrel32", pe_directive_secrel, 0},
4700#endif
2e6976a8
DG
4701
4702 /* These are for compatibility with CodeComposer Studio. */
4703 {"ref", s_ccs_ref, 0},
4704 {"def", s_ccs_def, 0},
4705 {"asmfunc", s_ccs_asmfunc, 0},
4706 {"endasmfunc", s_ccs_endasmfunc, 0},
4707
c19d1205
ZW
4708 { 0, 0, 0 }
4709};
4710\f
4711/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4712
c19d1205
ZW
4713/* Generic immediate-value read function for use in insn parsing.
4714 STR points to the beginning of the immediate (the leading #);
4715 VAL receives the value; if the value is outside [MIN, MAX]
4716 issue an error. PREFIX_OPT is true if the immediate prefix is
4717 optional. */
b99bd4ef 4718
c19d1205
ZW
4719static int
4720parse_immediate (char **str, int *val, int min, int max,
4721 bfd_boolean prefix_opt)
4722{
4723 expressionS exp;
4724 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4725 if (exp.X_op != O_constant)
b99bd4ef 4726 {
c19d1205
ZW
4727 inst.error = _("constant expression required");
4728 return FAIL;
4729 }
b99bd4ef 4730
c19d1205
ZW
4731 if (exp.X_add_number < min || exp.X_add_number > max)
4732 {
4733 inst.error = _("immediate value out of range");
4734 return FAIL;
4735 }
b99bd4ef 4736
c19d1205
ZW
4737 *val = exp.X_add_number;
4738 return SUCCESS;
4739}
b99bd4ef 4740
5287ad62 4741/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4742 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4743 instructions. Puts the result directly in inst.operands[i]. */
4744
4745static int
8335d6aa
JW
4746parse_big_immediate (char **str, int i, expressionS *in_exp,
4747 bfd_boolean allow_symbol_p)
5287ad62
JB
4748{
4749 expressionS exp;
8335d6aa 4750 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4751 char *ptr = *str;
4752
8335d6aa 4753 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4754
8335d6aa 4755 if (exp_p->X_op == O_constant)
036dc3f7 4756 {
8335d6aa 4757 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4758 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4759 O_constant. We have to be careful not to break compilation for
4760 32-bit X_add_number, though. */
8335d6aa 4761 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4762 {
8335d6aa
JW
4763 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4764 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4765 & 0xffffffff);
036dc3f7
PB
4766 inst.operands[i].regisimm = 1;
4767 }
4768 }
8335d6aa
JW
4769 else if (exp_p->X_op == O_big
4770 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4771 {
4772 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4773
5287ad62 4774 /* Bignums have their least significant bits in
477330fc
RM
4775 generic_bignum[0]. Make sure we put 32 bits in imm and
4776 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4777 gas_assert (parts != 0);
95b75c01
NC
4778
4779 /* Make sure that the number is not too big.
4780 PR 11972: Bignums can now be sign-extended to the
4781 size of a .octa so check that the out of range bits
4782 are all zero or all one. */
8335d6aa 4783 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4784 {
4785 LITTLENUM_TYPE m = -1;
4786
4787 if (generic_bignum[parts * 2] != 0
4788 && generic_bignum[parts * 2] != m)
4789 return FAIL;
4790
8335d6aa 4791 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4792 if (generic_bignum[j] != generic_bignum[j-1])
4793 return FAIL;
4794 }
4795
5287ad62
JB
4796 inst.operands[i].imm = 0;
4797 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4798 inst.operands[i].imm |= generic_bignum[idx]
4799 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4800 inst.operands[i].reg = 0;
4801 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4802 inst.operands[i].reg |= generic_bignum[idx]
4803 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4804 inst.operands[i].regisimm = 1;
4805 }
8335d6aa 4806 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4807 return FAIL;
5f4273c7 4808
5287ad62
JB
4809 *str = ptr;
4810
4811 return SUCCESS;
4812}
4813
c19d1205
ZW
4814/* Returns the pseudo-register number of an FPA immediate constant,
4815 or FAIL if there isn't a valid constant here. */
b99bd4ef 4816
c19d1205
ZW
4817static int
4818parse_fpa_immediate (char ** str)
4819{
4820 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4821 char * save_in;
4822 expressionS exp;
4823 int i;
4824 int j;
b99bd4ef 4825
c19d1205
ZW
4826 /* First try and match exact strings, this is to guarantee
4827 that some formats will work even for cross assembly. */
b99bd4ef 4828
c19d1205
ZW
4829 for (i = 0; fp_const[i]; i++)
4830 {
4831 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4832 {
c19d1205 4833 char *start = *str;
b99bd4ef 4834
c19d1205
ZW
4835 *str += strlen (fp_const[i]);
4836 if (is_end_of_line[(unsigned char) **str])
4837 return i + 8;
4838 *str = start;
4839 }
4840 }
b99bd4ef 4841
c19d1205
ZW
4842 /* Just because we didn't get a match doesn't mean that the constant
4843 isn't valid, just that it is in a format that we don't
4844 automatically recognize. Try parsing it with the standard
4845 expression routines. */
b99bd4ef 4846
c19d1205 4847 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4848
c19d1205
ZW
4849 /* Look for a raw floating point number. */
4850 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4851 && is_end_of_line[(unsigned char) *save_in])
4852 {
4853 for (i = 0; i < NUM_FLOAT_VALS; i++)
4854 {
4855 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4856 {
c19d1205
ZW
4857 if (words[j] != fp_values[i][j])
4858 break;
b99bd4ef
NC
4859 }
4860
c19d1205 4861 if (j == MAX_LITTLENUMS)
b99bd4ef 4862 {
c19d1205
ZW
4863 *str = save_in;
4864 return i + 8;
b99bd4ef
NC
4865 }
4866 }
4867 }
b99bd4ef 4868
c19d1205
ZW
4869 /* Try and parse a more complex expression, this will probably fail
4870 unless the code uses a floating point prefix (eg "0f"). */
4871 save_in = input_line_pointer;
4872 input_line_pointer = *str;
4873 if (expression (&exp) == absolute_section
4874 && exp.X_op == O_big
4875 && exp.X_add_number < 0)
4876 {
4877 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4878 Ditto for 15. */
ba592044
AM
4879#define X_PRECISION 5
4880#define E_PRECISION 15L
4881 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4882 {
4883 for (i = 0; i < NUM_FLOAT_VALS; i++)
4884 {
4885 for (j = 0; j < MAX_LITTLENUMS; j++)
4886 {
4887 if (words[j] != fp_values[i][j])
4888 break;
4889 }
b99bd4ef 4890
c19d1205
ZW
4891 if (j == MAX_LITTLENUMS)
4892 {
4893 *str = input_line_pointer;
4894 input_line_pointer = save_in;
4895 return i + 8;
4896 }
4897 }
4898 }
b99bd4ef
NC
4899 }
4900
c19d1205
ZW
4901 *str = input_line_pointer;
4902 input_line_pointer = save_in;
4903 inst.error = _("invalid FPA immediate expression");
4904 return FAIL;
b99bd4ef
NC
4905}
4906
136da414
JB
4907/* Returns 1 if a number has "quarter-precision" float format
4908 0baBbbbbbc defgh000 00000000 00000000. */
4909
4910static int
4911is_quarter_float (unsigned imm)
4912{
4913 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4914 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4915}
4916
aacf0b33
KT
4917
4918/* Detect the presence of a floating point or integer zero constant,
4919 i.e. #0.0 or #0. */
4920
4921static bfd_boolean
4922parse_ifimm_zero (char **in)
4923{
4924 int error_code;
4925
4926 if (!is_immediate_prefix (**in))
4927 return FALSE;
4928
4929 ++*in;
0900a05b
JW
4930
4931 /* Accept #0x0 as a synonym for #0. */
4932 if (strncmp (*in, "0x", 2) == 0)
4933 {
4934 int val;
4935 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4936 return FALSE;
4937 return TRUE;
4938 }
4939
aacf0b33
KT
4940 error_code = atof_generic (in, ".", EXP_CHARS,
4941 &generic_floating_point_number);
4942
4943 if (!error_code
4944 && generic_floating_point_number.sign == '+'
4945 && (generic_floating_point_number.low
4946 > generic_floating_point_number.leader))
4947 return TRUE;
4948
4949 return FALSE;
4950}
4951
136da414
JB
4952/* Parse an 8-bit "quarter-precision" floating point number of the form:
4953 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4954 The zero and minus-zero cases need special handling, since they can't be
4955 encoded in the "quarter-precision" float format, but can nonetheless be
4956 loaded as integer constants. */
136da414
JB
4957
4958static unsigned
4959parse_qfloat_immediate (char **ccp, int *immed)
4960{
4961 char *str = *ccp;
c96612cc 4962 char *fpnum;
136da414 4963 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4964 int found_fpchar = 0;
5f4273c7 4965
136da414 4966 skip_past_char (&str, '#');
5f4273c7 4967
c96612cc
JB
4968 /* We must not accidentally parse an integer as a floating-point number. Make
4969 sure that the value we parse is not an integer by checking for special
4970 characters '.' or 'e'.
4971 FIXME: This is a horrible hack, but doing better is tricky because type
4972 information isn't in a very usable state at parse time. */
4973 fpnum = str;
4974 skip_whitespace (fpnum);
4975
4976 if (strncmp (fpnum, "0x", 2) == 0)
4977 return FAIL;
4978 else
4979 {
4980 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
4981 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4982 {
4983 found_fpchar = 1;
4984 break;
4985 }
c96612cc
JB
4986
4987 if (!found_fpchar)
477330fc 4988 return FAIL;
c96612cc 4989 }
5f4273c7 4990
136da414
JB
4991 if ((str = atof_ieee (str, 's', words)) != NULL)
4992 {
4993 unsigned fpword = 0;
4994 int i;
5f4273c7 4995
136da414
JB
4996 /* Our FP word must be 32 bits (single-precision FP). */
4997 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
4998 {
4999 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5000 fpword |= words[i];
5001 }
5f4273c7 5002
c96612cc 5003 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5004 *immed = fpword;
136da414 5005 else
477330fc 5006 return FAIL;
136da414
JB
5007
5008 *ccp = str;
5f4273c7 5009
136da414
JB
5010 return SUCCESS;
5011 }
5f4273c7 5012
136da414
JB
5013 return FAIL;
5014}
5015
c19d1205
ZW
5016/* Shift operands. */
5017enum shift_kind
b99bd4ef 5018{
c19d1205
ZW
5019 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5020};
b99bd4ef 5021
c19d1205
ZW
5022struct asm_shift_name
5023{
5024 const char *name;
5025 enum shift_kind kind;
5026};
b99bd4ef 5027
c19d1205
ZW
5028/* Third argument to parse_shift. */
5029enum parse_shift_mode
5030{
5031 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5032 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5033 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5034 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5035 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5036};
b99bd4ef 5037
c19d1205
ZW
5038/* Parse a <shift> specifier on an ARM data processing instruction.
5039 This has three forms:
b99bd4ef 5040
c19d1205
ZW
5041 (LSL|LSR|ASL|ASR|ROR) Rs
5042 (LSL|LSR|ASL|ASR|ROR) #imm
5043 RRX
b99bd4ef 5044
c19d1205
ZW
5045 Note that ASL is assimilated to LSL in the instruction encoding, and
5046 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5047
c19d1205
ZW
5048static int
5049parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5050{
c19d1205
ZW
5051 const struct asm_shift_name *shift_name;
5052 enum shift_kind shift;
5053 char *s = *str;
5054 char *p = s;
5055 int reg;
b99bd4ef 5056
c19d1205
ZW
5057 for (p = *str; ISALPHA (*p); p++)
5058 ;
b99bd4ef 5059
c19d1205 5060 if (p == *str)
b99bd4ef 5061 {
c19d1205
ZW
5062 inst.error = _("shift expression expected");
5063 return FAIL;
b99bd4ef
NC
5064 }
5065
21d799b5 5066 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5067 p - *str);
c19d1205
ZW
5068
5069 if (shift_name == NULL)
b99bd4ef 5070 {
c19d1205
ZW
5071 inst.error = _("shift expression expected");
5072 return FAIL;
b99bd4ef
NC
5073 }
5074
c19d1205 5075 shift = shift_name->kind;
b99bd4ef 5076
c19d1205
ZW
5077 switch (mode)
5078 {
5079 case NO_SHIFT_RESTRICT:
5080 case SHIFT_IMMEDIATE: break;
b99bd4ef 5081
c19d1205
ZW
5082 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5083 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5084 {
5085 inst.error = _("'LSL' or 'ASR' required");
5086 return FAIL;
5087 }
5088 break;
b99bd4ef 5089
c19d1205
ZW
5090 case SHIFT_LSL_IMMEDIATE:
5091 if (shift != SHIFT_LSL)
5092 {
5093 inst.error = _("'LSL' required");
5094 return FAIL;
5095 }
5096 break;
b99bd4ef 5097
c19d1205
ZW
5098 case SHIFT_ASR_IMMEDIATE:
5099 if (shift != SHIFT_ASR)
5100 {
5101 inst.error = _("'ASR' required");
5102 return FAIL;
5103 }
5104 break;
b99bd4ef 5105
c19d1205
ZW
5106 default: abort ();
5107 }
b99bd4ef 5108
c19d1205
ZW
5109 if (shift != SHIFT_RRX)
5110 {
5111 /* Whitespace can appear here if the next thing is a bare digit. */
5112 skip_whitespace (p);
b99bd4ef 5113
c19d1205 5114 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5115 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5116 {
5117 inst.operands[i].imm = reg;
5118 inst.operands[i].immisreg = 1;
5119 }
5120 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5121 return FAIL;
5122 }
5123 inst.operands[i].shift_kind = shift;
5124 inst.operands[i].shifted = 1;
5125 *str = p;
5126 return SUCCESS;
b99bd4ef
NC
5127}
5128
c19d1205 5129/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5130
c19d1205
ZW
5131 #<immediate>
5132 #<immediate>, <rotate>
5133 <Rm>
5134 <Rm>, <shift>
b99bd4ef 5135
c19d1205
ZW
5136 where <shift> is defined by parse_shift above, and <rotate> is a
5137 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5138 is deferred to md_apply_fix. */
b99bd4ef 5139
c19d1205
ZW
5140static int
5141parse_shifter_operand (char **str, int i)
5142{
5143 int value;
91d6fa6a 5144 expressionS exp;
b99bd4ef 5145
dcbf9037 5146 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5147 {
5148 inst.operands[i].reg = value;
5149 inst.operands[i].isreg = 1;
b99bd4ef 5150
c19d1205
ZW
5151 /* parse_shift will override this if appropriate */
5152 inst.reloc.exp.X_op = O_constant;
5153 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5154
c19d1205
ZW
5155 if (skip_past_comma (str) == FAIL)
5156 return SUCCESS;
b99bd4ef 5157
c19d1205
ZW
5158 /* Shift operation on register. */
5159 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5160 }
5161
c19d1205
ZW
5162 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5163 return FAIL;
b99bd4ef 5164
c19d1205 5165 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5166 {
c19d1205 5167 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5168 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5169 return FAIL;
b99bd4ef 5170
91d6fa6a 5171 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5172 {
5173 inst.error = _("constant expression expected");
5174 return FAIL;
5175 }
b99bd4ef 5176
91d6fa6a 5177 value = exp.X_add_number;
c19d1205
ZW
5178 if (value < 0 || value > 30 || value % 2 != 0)
5179 {
5180 inst.error = _("invalid rotation");
5181 return FAIL;
5182 }
5183 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5184 {
5185 inst.error = _("invalid constant");
5186 return FAIL;
5187 }
09d92015 5188
a415b1cd
JB
5189 /* Encode as specified. */
5190 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5191 return SUCCESS;
09d92015
MM
5192 }
5193
c19d1205
ZW
5194 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5195 inst.reloc.pc_rel = 0;
5196 return SUCCESS;
09d92015
MM
5197}
5198
4962c51a
MS
5199/* Group relocation information. Each entry in the table contains the
5200 textual name of the relocation as may appear in assembler source
5201 and must end with a colon.
5202 Along with this textual name are the relocation codes to be used if
5203 the corresponding instruction is an ALU instruction (ADD or SUB only),
5204 an LDR, an LDRS, or an LDC. */
5205
5206struct group_reloc_table_entry
5207{
5208 const char *name;
5209 int alu_code;
5210 int ldr_code;
5211 int ldrs_code;
5212 int ldc_code;
5213};
5214
5215typedef enum
5216{
5217 /* Varieties of non-ALU group relocation. */
5218
5219 GROUP_LDR,
5220 GROUP_LDRS,
5221 GROUP_LDC
5222} group_reloc_type;
5223
5224static struct group_reloc_table_entry group_reloc_table[] =
5225 { /* Program counter relative: */
5226 { "pc_g0_nc",
5227 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5228 0, /* LDR */
5229 0, /* LDRS */
5230 0 }, /* LDC */
5231 { "pc_g0",
5232 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5233 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5234 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5235 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5236 { "pc_g1_nc",
5237 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5238 0, /* LDR */
5239 0, /* LDRS */
5240 0 }, /* LDC */
5241 { "pc_g1",
5242 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5243 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5244 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5245 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5246 { "pc_g2",
5247 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5248 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5249 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5250 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5251 /* Section base relative */
5252 { "sb_g0_nc",
5253 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5254 0, /* LDR */
5255 0, /* LDRS */
5256 0 }, /* LDC */
5257 { "sb_g0",
5258 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5259 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5260 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5261 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5262 { "sb_g1_nc",
5263 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5264 0, /* LDR */
5265 0, /* LDRS */
5266 0 }, /* LDC */
5267 { "sb_g1",
5268 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5269 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5270 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5271 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5272 { "sb_g2",
5273 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5274 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5275 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5276 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5277
5278/* Given the address of a pointer pointing to the textual name of a group
5279 relocation as may appear in assembler source, attempt to find its details
5280 in group_reloc_table. The pointer will be updated to the character after
5281 the trailing colon. On failure, FAIL will be returned; SUCCESS
5282 otherwise. On success, *entry will be updated to point at the relevant
5283 group_reloc_table entry. */
5284
5285static int
5286find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5287{
5288 unsigned int i;
5289 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5290 {
5291 int length = strlen (group_reloc_table[i].name);
5292
5f4273c7
NC
5293 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5294 && (*str)[length] == ':')
477330fc
RM
5295 {
5296 *out = &group_reloc_table[i];
5297 *str += (length + 1);
5298 return SUCCESS;
5299 }
4962c51a
MS
5300 }
5301
5302 return FAIL;
5303}
5304
5305/* Parse a <shifter_operand> for an ARM data processing instruction
5306 (as for parse_shifter_operand) where group relocations are allowed:
5307
5308 #<immediate>
5309 #<immediate>, <rotate>
5310 #:<group_reloc>:<expression>
5311 <Rm>
5312 <Rm>, <shift>
5313
5314 where <group_reloc> is one of the strings defined in group_reloc_table.
5315 The hashes are optional.
5316
5317 Everything else is as for parse_shifter_operand. */
5318
5319static parse_operand_result
5320parse_shifter_operand_group_reloc (char **str, int i)
5321{
5322 /* Determine if we have the sequence of characters #: or just :
5323 coming next. If we do, then we check for a group relocation.
5324 If we don't, punt the whole lot to parse_shifter_operand. */
5325
5326 if (((*str)[0] == '#' && (*str)[1] == ':')
5327 || (*str)[0] == ':')
5328 {
5329 struct group_reloc_table_entry *entry;
5330
5331 if ((*str)[0] == '#')
477330fc 5332 (*str) += 2;
4962c51a 5333 else
477330fc 5334 (*str)++;
4962c51a
MS
5335
5336 /* Try to parse a group relocation. Anything else is an error. */
5337 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5338 {
5339 inst.error = _("unknown group relocation");
5340 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5341 }
4962c51a
MS
5342
5343 /* We now have the group relocation table entry corresponding to
477330fc 5344 the name in the assembler source. Next, we parse the expression. */
4962c51a 5345 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5346 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5347
5348 /* Record the relocation type (always the ALU variant here). */
21d799b5 5349 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5350 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5351
5352 return PARSE_OPERAND_SUCCESS;
5353 }
5354 else
5355 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5356 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5357
5358 /* Never reached. */
5359}
5360
8e560766
MGD
5361/* Parse a Neon alignment expression. Information is written to
5362 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5363
8e560766
MGD
5364 align .imm = align << 8, .immisalign=1, .preind=0 */
5365static parse_operand_result
5366parse_neon_alignment (char **str, int i)
5367{
5368 char *p = *str;
5369 expressionS exp;
5370
5371 my_get_expression (&exp, &p, GE_NO_PREFIX);
5372
5373 if (exp.X_op != O_constant)
5374 {
5375 inst.error = _("alignment must be constant");
5376 return PARSE_OPERAND_FAIL;
5377 }
5378
5379 inst.operands[i].imm = exp.X_add_number << 8;
5380 inst.operands[i].immisalign = 1;
5381 /* Alignments are not pre-indexes. */
5382 inst.operands[i].preind = 0;
5383
5384 *str = p;
5385 return PARSE_OPERAND_SUCCESS;
5386}
5387
c19d1205
ZW
5388/* Parse all forms of an ARM address expression. Information is written
5389 to inst.operands[i] and/or inst.reloc.
09d92015 5390
c19d1205 5391 Preindexed addressing (.preind=1):
09d92015 5392
c19d1205
ZW
5393 [Rn, #offset] .reg=Rn .reloc.exp=offset
5394 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5395 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5396 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5397
c19d1205 5398 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5399
c19d1205 5400 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5401
c19d1205
ZW
5402 [Rn], #offset .reg=Rn .reloc.exp=offset
5403 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5404 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5405 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5406
c19d1205 5407 Unindexed addressing (.preind=0, .postind=0):
09d92015 5408
c19d1205 5409 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5410
c19d1205 5411 Other:
09d92015 5412
c19d1205
ZW
5413 [Rn]{!} shorthand for [Rn,#0]{!}
5414 =immediate .isreg=0 .reloc.exp=immediate
5415 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5416
c19d1205
ZW
5417 It is the caller's responsibility to check for addressing modes not
5418 supported by the instruction, and to set inst.reloc.type. */
5419
4962c51a
MS
5420static parse_operand_result
5421parse_address_main (char **str, int i, int group_relocations,
477330fc 5422 group_reloc_type group_type)
09d92015 5423{
c19d1205
ZW
5424 char *p = *str;
5425 int reg;
09d92015 5426
c19d1205 5427 if (skip_past_char (&p, '[') == FAIL)
09d92015 5428 {
c19d1205
ZW
5429 if (skip_past_char (&p, '=') == FAIL)
5430 {
974da60d 5431 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5432 inst.reloc.pc_rel = 1;
5433 inst.operands[i].reg = REG_PC;
5434 inst.operands[i].isreg = 1;
5435 inst.operands[i].preind = 1;
09d92015 5436
8335d6aa
JW
5437 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5438 return PARSE_OPERAND_FAIL;
5439 }
5440 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5441 /*allow_symbol_p=*/TRUE))
4962c51a 5442 return PARSE_OPERAND_FAIL;
09d92015 5443
c19d1205 5444 *str = p;
4962c51a 5445 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5446 }
5447
8ab8155f
NC
5448 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5449 skip_whitespace (p);
5450
dcbf9037 5451 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5452 {
c19d1205 5453 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5454 return PARSE_OPERAND_FAIL;
09d92015 5455 }
c19d1205
ZW
5456 inst.operands[i].reg = reg;
5457 inst.operands[i].isreg = 1;
09d92015 5458
c19d1205 5459 if (skip_past_comma (&p) == SUCCESS)
09d92015 5460 {
c19d1205 5461 inst.operands[i].preind = 1;
09d92015 5462
c19d1205
ZW
5463 if (*p == '+') p++;
5464 else if (*p == '-') p++, inst.operands[i].negative = 1;
5465
dcbf9037 5466 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5467 {
c19d1205
ZW
5468 inst.operands[i].imm = reg;
5469 inst.operands[i].immisreg = 1;
5470
5471 if (skip_past_comma (&p) == SUCCESS)
5472 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5473 return PARSE_OPERAND_FAIL;
c19d1205 5474 }
5287ad62 5475 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5476 {
5477 /* FIXME: '@' should be used here, but it's filtered out by generic
5478 code before we get to see it here. This may be subject to
5479 change. */
5480 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5481
8e560766
MGD
5482 if (result != PARSE_OPERAND_SUCCESS)
5483 return result;
5484 }
c19d1205
ZW
5485 else
5486 {
5487 if (inst.operands[i].negative)
5488 {
5489 inst.operands[i].negative = 0;
5490 p--;
5491 }
4962c51a 5492
5f4273c7
NC
5493 if (group_relocations
5494 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5495 {
5496 struct group_reloc_table_entry *entry;
5497
477330fc
RM
5498 /* Skip over the #: or : sequence. */
5499 if (*p == '#')
5500 p += 2;
5501 else
5502 p++;
4962c51a
MS
5503
5504 /* Try to parse a group relocation. Anything else is an
477330fc 5505 error. */
4962c51a
MS
5506 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5507 {
5508 inst.error = _("unknown group relocation");
5509 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5510 }
5511
5512 /* We now have the group relocation table entry corresponding to
5513 the name in the assembler source. Next, we parse the
477330fc 5514 expression. */
4962c51a
MS
5515 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5516 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5517
5518 /* Record the relocation type. */
477330fc
RM
5519 switch (group_type)
5520 {
5521 case GROUP_LDR:
5522 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5523 break;
4962c51a 5524
477330fc
RM
5525 case GROUP_LDRS:
5526 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5527 break;
4962c51a 5528
477330fc
RM
5529 case GROUP_LDC:
5530 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5531 break;
4962c51a 5532
477330fc
RM
5533 default:
5534 gas_assert (0);
5535 }
4962c51a 5536
477330fc 5537 if (inst.reloc.type == 0)
4962c51a
MS
5538 {
5539 inst.error = _("this group relocation is not allowed on this instruction");
5540 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5541 }
477330fc
RM
5542 }
5543 else
26d97720
NS
5544 {
5545 char *q = p;
5546 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5547 return PARSE_OPERAND_FAIL;
5548 /* If the offset is 0, find out if it's a +0 or -0. */
5549 if (inst.reloc.exp.X_op == O_constant
5550 && inst.reloc.exp.X_add_number == 0)
5551 {
5552 skip_whitespace (q);
5553 if (*q == '#')
5554 {
5555 q++;
5556 skip_whitespace (q);
5557 }
5558 if (*q == '-')
5559 inst.operands[i].negative = 1;
5560 }
5561 }
09d92015
MM
5562 }
5563 }
8e560766
MGD
5564 else if (skip_past_char (&p, ':') == SUCCESS)
5565 {
5566 /* FIXME: '@' should be used here, but it's filtered out by generic code
5567 before we get to see it here. This may be subject to change. */
5568 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5569
8e560766
MGD
5570 if (result != PARSE_OPERAND_SUCCESS)
5571 return result;
5572 }
09d92015 5573
c19d1205 5574 if (skip_past_char (&p, ']') == FAIL)
09d92015 5575 {
c19d1205 5576 inst.error = _("']' expected");
4962c51a 5577 return PARSE_OPERAND_FAIL;
09d92015
MM
5578 }
5579
c19d1205
ZW
5580 if (skip_past_char (&p, '!') == SUCCESS)
5581 inst.operands[i].writeback = 1;
09d92015 5582
c19d1205 5583 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5584 {
c19d1205
ZW
5585 if (skip_past_char (&p, '{') == SUCCESS)
5586 {
5587 /* [Rn], {expr} - unindexed, with option */
5588 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5589 0, 255, TRUE) == FAIL)
4962c51a 5590 return PARSE_OPERAND_FAIL;
09d92015 5591
c19d1205
ZW
5592 if (skip_past_char (&p, '}') == FAIL)
5593 {
5594 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5595 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5596 }
5597 if (inst.operands[i].preind)
5598 {
5599 inst.error = _("cannot combine index with option");
4962c51a 5600 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5601 }
5602 *str = p;
4962c51a 5603 return PARSE_OPERAND_SUCCESS;
09d92015 5604 }
c19d1205
ZW
5605 else
5606 {
5607 inst.operands[i].postind = 1;
5608 inst.operands[i].writeback = 1;
09d92015 5609
c19d1205
ZW
5610 if (inst.operands[i].preind)
5611 {
5612 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5613 return PARSE_OPERAND_FAIL;
c19d1205 5614 }
09d92015 5615
c19d1205
ZW
5616 if (*p == '+') p++;
5617 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5618
dcbf9037 5619 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5620 {
477330fc
RM
5621 /* We might be using the immediate for alignment already. If we
5622 are, OR the register number into the low-order bits. */
5623 if (inst.operands[i].immisalign)
5624 inst.operands[i].imm |= reg;
5625 else
5626 inst.operands[i].imm = reg;
c19d1205 5627 inst.operands[i].immisreg = 1;
a737bd4d 5628
c19d1205
ZW
5629 if (skip_past_comma (&p) == SUCCESS)
5630 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5631 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5632 }
5633 else
5634 {
26d97720 5635 char *q = p;
c19d1205
ZW
5636 if (inst.operands[i].negative)
5637 {
5638 inst.operands[i].negative = 0;
5639 p--;
5640 }
5641 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5642 return PARSE_OPERAND_FAIL;
26d97720
NS
5643 /* If the offset is 0, find out if it's a +0 or -0. */
5644 if (inst.reloc.exp.X_op == O_constant
5645 && inst.reloc.exp.X_add_number == 0)
5646 {
5647 skip_whitespace (q);
5648 if (*q == '#')
5649 {
5650 q++;
5651 skip_whitespace (q);
5652 }
5653 if (*q == '-')
5654 inst.operands[i].negative = 1;
5655 }
c19d1205
ZW
5656 }
5657 }
a737bd4d
NC
5658 }
5659
c19d1205
ZW
5660 /* If at this point neither .preind nor .postind is set, we have a
5661 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5662 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5663 {
5664 inst.operands[i].preind = 1;
5665 inst.reloc.exp.X_op = O_constant;
5666 inst.reloc.exp.X_add_number = 0;
5667 }
5668 *str = p;
4962c51a
MS
5669 return PARSE_OPERAND_SUCCESS;
5670}
5671
5672static int
5673parse_address (char **str, int i)
5674{
21d799b5 5675 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5676 ? SUCCESS : FAIL;
4962c51a
MS
5677}
5678
5679static parse_operand_result
5680parse_address_group_reloc (char **str, int i, group_reloc_type type)
5681{
5682 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5683}
5684
b6895b4f
PB
5685/* Parse an operand for a MOVW or MOVT instruction. */
5686static int
5687parse_half (char **str)
5688{
5689 char * p;
5f4273c7 5690
b6895b4f
PB
5691 p = *str;
5692 skip_past_char (&p, '#');
5f4273c7 5693 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5694 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5695 else if (strncasecmp (p, ":upper16:", 9) == 0)
5696 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5697
5698 if (inst.reloc.type != BFD_RELOC_UNUSED)
5699 {
5700 p += 9;
5f4273c7 5701 skip_whitespace (p);
b6895b4f
PB
5702 }
5703
5704 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5705 return FAIL;
5706
5707 if (inst.reloc.type == BFD_RELOC_UNUSED)
5708 {
5709 if (inst.reloc.exp.X_op != O_constant)
5710 {
5711 inst.error = _("constant expression expected");
5712 return FAIL;
5713 }
5714 if (inst.reloc.exp.X_add_number < 0
5715 || inst.reloc.exp.X_add_number > 0xffff)
5716 {
5717 inst.error = _("immediate value out of range");
5718 return FAIL;
5719 }
5720 }
5721 *str = p;
5722 return SUCCESS;
5723}
5724
c19d1205 5725/* Miscellaneous. */
a737bd4d 5726
c19d1205
ZW
5727/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5728 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5729static int
d2cd1205 5730parse_psr (char **str, bfd_boolean lhs)
09d92015 5731{
c19d1205
ZW
5732 char *p;
5733 unsigned long psr_field;
62b3e311
PB
5734 const struct asm_psr *psr;
5735 char *start;
d2cd1205 5736 bfd_boolean is_apsr = FALSE;
ac7f631b 5737 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5738
a4482bb6
NC
5739 /* PR gas/12698: If the user has specified -march=all then m_profile will
5740 be TRUE, but we want to ignore it in this case as we are building for any
5741 CPU type, including non-m variants. */
823d2571 5742 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5743 m_profile = FALSE;
5744
c19d1205
ZW
5745 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5746 feature for ease of use and backwards compatibility. */
5747 p = *str;
62b3e311 5748 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5749 {
5750 if (m_profile)
5751 goto unsupported_psr;
fa94de6b 5752
d2cd1205
JB
5753 psr_field = SPSR_BIT;
5754 }
5755 else if (strncasecmp (p, "CPSR", 4) == 0)
5756 {
5757 if (m_profile)
5758 goto unsupported_psr;
5759
5760 psr_field = 0;
5761 }
5762 else if (strncasecmp (p, "APSR", 4) == 0)
5763 {
5764 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5765 and ARMv7-R architecture CPUs. */
5766 is_apsr = TRUE;
5767 psr_field = 0;
5768 }
5769 else if (m_profile)
62b3e311
PB
5770 {
5771 start = p;
5772 do
5773 p++;
5774 while (ISALNUM (*p) || *p == '_');
5775
d2cd1205
JB
5776 if (strncasecmp (start, "iapsr", 5) == 0
5777 || strncasecmp (start, "eapsr", 5) == 0
5778 || strncasecmp (start, "xpsr", 4) == 0
5779 || strncasecmp (start, "psr", 3) == 0)
5780 p = start + strcspn (start, "rR") + 1;
5781
21d799b5 5782 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5783 p - start);
d2cd1205 5784
62b3e311
PB
5785 if (!psr)
5786 return FAIL;
09d92015 5787
d2cd1205
JB
5788 /* If APSR is being written, a bitfield may be specified. Note that
5789 APSR itself is handled above. */
5790 if (psr->field <= 3)
5791 {
5792 psr_field = psr->field;
5793 is_apsr = TRUE;
5794 goto check_suffix;
5795 }
5796
62b3e311 5797 *str = p;
d2cd1205
JB
5798 /* M-profile MSR instructions have the mask field set to "10", except
5799 *PSR variants which modify APSR, which may use a different mask (and
5800 have been handled already). Do that by setting the PSR_f field
5801 here. */
5802 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5803 }
d2cd1205
JB
5804 else
5805 goto unsupported_psr;
09d92015 5806
62b3e311 5807 p += 4;
d2cd1205 5808check_suffix:
c19d1205
ZW
5809 if (*p == '_')
5810 {
5811 /* A suffix follows. */
c19d1205
ZW
5812 p++;
5813 start = p;
a737bd4d 5814
c19d1205
ZW
5815 do
5816 p++;
5817 while (ISALNUM (*p) || *p == '_');
a737bd4d 5818
d2cd1205
JB
5819 if (is_apsr)
5820 {
5821 /* APSR uses a notation for bits, rather than fields. */
5822 unsigned int nzcvq_bits = 0;
5823 unsigned int g_bit = 0;
5824 char *bit;
fa94de6b 5825
d2cd1205
JB
5826 for (bit = start; bit != p; bit++)
5827 {
5828 switch (TOLOWER (*bit))
477330fc 5829 {
d2cd1205
JB
5830 case 'n':
5831 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5832 break;
5833
5834 case 'z':
5835 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5836 break;
5837
5838 case 'c':
5839 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5840 break;
5841
5842 case 'v':
5843 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5844 break;
fa94de6b 5845
d2cd1205
JB
5846 case 'q':
5847 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5848 break;
fa94de6b 5849
d2cd1205
JB
5850 case 'g':
5851 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5852 break;
fa94de6b 5853
d2cd1205
JB
5854 default:
5855 inst.error = _("unexpected bit specified after APSR");
5856 return FAIL;
5857 }
5858 }
fa94de6b 5859
d2cd1205
JB
5860 if (nzcvq_bits == 0x1f)
5861 psr_field |= PSR_f;
fa94de6b 5862
d2cd1205
JB
5863 if (g_bit == 0x1)
5864 {
5865 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5866 {
d2cd1205
JB
5867 inst.error = _("selected processor does not "
5868 "support DSP extension");
5869 return FAIL;
5870 }
5871
5872 psr_field |= PSR_s;
5873 }
fa94de6b 5874
d2cd1205
JB
5875 if ((nzcvq_bits & 0x20) != 0
5876 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5877 || (g_bit & 0x2) != 0)
5878 {
5879 inst.error = _("bad bitmask specified after APSR");
5880 return FAIL;
5881 }
5882 }
5883 else
477330fc 5884 {
d2cd1205 5885 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5886 p - start);
d2cd1205 5887 if (!psr)
477330fc 5888 goto error;
a737bd4d 5889
d2cd1205
JB
5890 psr_field |= psr->field;
5891 }
a737bd4d 5892 }
c19d1205 5893 else
a737bd4d 5894 {
c19d1205
ZW
5895 if (ISALNUM (*p))
5896 goto error; /* Garbage after "[CS]PSR". */
5897
d2cd1205 5898 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5899 is deprecated, but allow it anyway. */
d2cd1205
JB
5900 if (is_apsr && lhs)
5901 {
5902 psr_field |= PSR_f;
5903 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5904 "deprecated"));
5905 }
5906 else if (!m_profile)
5907 /* These bits are never right for M-profile devices: don't set them
5908 (only code paths which read/write APSR reach here). */
5909 psr_field |= (PSR_c | PSR_f);
a737bd4d 5910 }
c19d1205
ZW
5911 *str = p;
5912 return psr_field;
a737bd4d 5913
d2cd1205
JB
5914 unsupported_psr:
5915 inst.error = _("selected processor does not support requested special "
5916 "purpose register");
5917 return FAIL;
5918
c19d1205
ZW
5919 error:
5920 inst.error = _("flag for {c}psr instruction expected");
5921 return FAIL;
a737bd4d
NC
5922}
5923
c19d1205
ZW
5924/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5925 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5926
c19d1205
ZW
5927static int
5928parse_cps_flags (char **str)
a737bd4d 5929{
c19d1205
ZW
5930 int val = 0;
5931 int saw_a_flag = 0;
5932 char *s = *str;
a737bd4d 5933
c19d1205
ZW
5934 for (;;)
5935 switch (*s++)
5936 {
5937 case '\0': case ',':
5938 goto done;
a737bd4d 5939
c19d1205
ZW
5940 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5941 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5942 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5943
c19d1205
ZW
5944 default:
5945 inst.error = _("unrecognized CPS flag");
5946 return FAIL;
5947 }
a737bd4d 5948
c19d1205
ZW
5949 done:
5950 if (saw_a_flag == 0)
a737bd4d 5951 {
c19d1205
ZW
5952 inst.error = _("missing CPS flags");
5953 return FAIL;
a737bd4d 5954 }
a737bd4d 5955
c19d1205
ZW
5956 *str = s - 1;
5957 return val;
a737bd4d
NC
5958}
5959
c19d1205
ZW
5960/* Parse an endian specifier ("BE" or "LE", case insensitive);
5961 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5962
5963static int
c19d1205 5964parse_endian_specifier (char **str)
a737bd4d 5965{
c19d1205
ZW
5966 int little_endian;
5967 char *s = *str;
a737bd4d 5968
c19d1205
ZW
5969 if (strncasecmp (s, "BE", 2))
5970 little_endian = 0;
5971 else if (strncasecmp (s, "LE", 2))
5972 little_endian = 1;
5973 else
a737bd4d 5974 {
c19d1205 5975 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5976 return FAIL;
5977 }
5978
c19d1205 5979 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5980 {
c19d1205 5981 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5982 return FAIL;
5983 }
5984
c19d1205
ZW
5985 *str = s + 2;
5986 return little_endian;
5987}
a737bd4d 5988
c19d1205
ZW
5989/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5990 value suitable for poking into the rotate field of an sxt or sxta
5991 instruction, or FAIL on error. */
5992
5993static int
5994parse_ror (char **str)
5995{
5996 int rot;
5997 char *s = *str;
5998
5999 if (strncasecmp (s, "ROR", 3) == 0)
6000 s += 3;
6001 else
a737bd4d 6002 {
c19d1205 6003 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6004 return FAIL;
6005 }
c19d1205
ZW
6006
6007 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6008 return FAIL;
6009
6010 switch (rot)
a737bd4d 6011 {
c19d1205
ZW
6012 case 0: *str = s; return 0x0;
6013 case 8: *str = s; return 0x1;
6014 case 16: *str = s; return 0x2;
6015 case 24: *str = s; return 0x3;
6016
6017 default:
6018 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6019 return FAIL;
6020 }
c19d1205 6021}
a737bd4d 6022
c19d1205
ZW
6023/* Parse a conditional code (from conds[] below). The value returned is in the
6024 range 0 .. 14, or FAIL. */
6025static int
6026parse_cond (char **str)
6027{
c462b453 6028 char *q;
c19d1205 6029 const struct asm_cond *c;
c462b453
PB
6030 int n;
6031 /* Condition codes are always 2 characters, so matching up to
6032 3 characters is sufficient. */
6033 char cond[3];
a737bd4d 6034
c462b453
PB
6035 q = *str;
6036 n = 0;
6037 while (ISALPHA (*q) && n < 3)
6038 {
e07e6e58 6039 cond[n] = TOLOWER (*q);
c462b453
PB
6040 q++;
6041 n++;
6042 }
a737bd4d 6043
21d799b5 6044 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6045 if (!c)
a737bd4d 6046 {
c19d1205 6047 inst.error = _("condition required");
a737bd4d
NC
6048 return FAIL;
6049 }
6050
c19d1205
ZW
6051 *str = q;
6052 return c->value;
6053}
6054
e797f7e0
MGD
6055/* If the given feature available in the selected CPU, mark it as used.
6056 Returns TRUE iff feature is available. */
6057static bfd_boolean
6058mark_feature_used (const arm_feature_set *feature)
6059{
6060 /* Ensure the option is valid on the current architecture. */
6061 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6062 return FALSE;
6063
6064 /* Add the appropriate architecture feature for the barrier option used.
6065 */
6066 if (thumb_mode)
6067 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6068 else
6069 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6070
6071 return TRUE;
6072}
6073
62b3e311
PB
6074/* Parse an option for a barrier instruction. Returns the encoding for the
6075 option, or FAIL. */
6076static int
6077parse_barrier (char **str)
6078{
6079 char *p, *q;
6080 const struct asm_barrier_opt *o;
6081
6082 p = q = *str;
6083 while (ISALPHA (*q))
6084 q++;
6085
21d799b5 6086 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6087 q - p);
62b3e311
PB
6088 if (!o)
6089 return FAIL;
6090
e797f7e0
MGD
6091 if (!mark_feature_used (&o->arch))
6092 return FAIL;
6093
62b3e311
PB
6094 *str = q;
6095 return o->value;
6096}
6097
92e90b6e
PB
6098/* Parse the operands of a table branch instruction. Similar to a memory
6099 operand. */
6100static int
6101parse_tb (char **str)
6102{
6103 char * p = *str;
6104 int reg;
6105
6106 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6107 {
6108 inst.error = _("'[' expected");
6109 return FAIL;
6110 }
92e90b6e 6111
dcbf9037 6112 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6113 {
6114 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6115 return FAIL;
6116 }
6117 inst.operands[0].reg = reg;
6118
6119 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6120 {
6121 inst.error = _("',' expected");
6122 return FAIL;
6123 }
5f4273c7 6124
dcbf9037 6125 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6126 {
6127 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6128 return FAIL;
6129 }
6130 inst.operands[0].imm = reg;
6131
6132 if (skip_past_comma (&p) == SUCCESS)
6133 {
6134 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6135 return FAIL;
6136 if (inst.reloc.exp.X_add_number != 1)
6137 {
6138 inst.error = _("invalid shift");
6139 return FAIL;
6140 }
6141 inst.operands[0].shifted = 1;
6142 }
6143
6144 if (skip_past_char (&p, ']') == FAIL)
6145 {
6146 inst.error = _("']' expected");
6147 return FAIL;
6148 }
6149 *str = p;
6150 return SUCCESS;
6151}
6152
5287ad62
JB
6153/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6154 information on the types the operands can take and how they are encoded.
037e8744
JB
6155 Up to four operands may be read; this function handles setting the
6156 ".present" field for each read operand itself.
5287ad62
JB
6157 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6158 else returns FAIL. */
6159
6160static int
6161parse_neon_mov (char **str, int *which_operand)
6162{
6163 int i = *which_operand, val;
6164 enum arm_reg_type rtype;
6165 char *ptr = *str;
dcbf9037 6166 struct neon_type_el optype;
5f4273c7 6167
dcbf9037 6168 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6169 {
6170 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6171 inst.operands[i].reg = val;
6172 inst.operands[i].isscalar = 1;
dcbf9037 6173 inst.operands[i].vectype = optype;
5287ad62
JB
6174 inst.operands[i++].present = 1;
6175
6176 if (skip_past_comma (&ptr) == FAIL)
477330fc 6177 goto wanted_comma;
5f4273c7 6178
dcbf9037 6179 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6180 goto wanted_arm;
5f4273c7 6181
5287ad62
JB
6182 inst.operands[i].reg = val;
6183 inst.operands[i].isreg = 1;
6184 inst.operands[i].present = 1;
6185 }
037e8744 6186 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6187 != FAIL)
5287ad62
JB
6188 {
6189 /* Cases 0, 1, 2, 3, 5 (D only). */
6190 if (skip_past_comma (&ptr) == FAIL)
477330fc 6191 goto wanted_comma;
5f4273c7 6192
5287ad62
JB
6193 inst.operands[i].reg = val;
6194 inst.operands[i].isreg = 1;
6195 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6196 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6197 inst.operands[i].isvec = 1;
dcbf9037 6198 inst.operands[i].vectype = optype;
5287ad62
JB
6199 inst.operands[i++].present = 1;
6200
dcbf9037 6201 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6202 {
6203 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6204 Case 13: VMOV <Sd>, <Rm> */
6205 inst.operands[i].reg = val;
6206 inst.operands[i].isreg = 1;
6207 inst.operands[i].present = 1;
6208
6209 if (rtype == REG_TYPE_NQ)
6210 {
6211 first_error (_("can't use Neon quad register here"));
6212 return FAIL;
6213 }
6214 else if (rtype != REG_TYPE_VFS)
6215 {
6216 i++;
6217 if (skip_past_comma (&ptr) == FAIL)
6218 goto wanted_comma;
6219 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6220 goto wanted_arm;
6221 inst.operands[i].reg = val;
6222 inst.operands[i].isreg = 1;
6223 inst.operands[i].present = 1;
6224 }
6225 }
037e8744 6226 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6227 &optype)) != FAIL)
6228 {
6229 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6230 Case 1: VMOV<c><q> <Dd>, <Dm>
6231 Case 8: VMOV.F32 <Sd>, <Sm>
6232 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6233
6234 inst.operands[i].reg = val;
6235 inst.operands[i].isreg = 1;
6236 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6237 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6238 inst.operands[i].isvec = 1;
6239 inst.operands[i].vectype = optype;
6240 inst.operands[i].present = 1;
6241
6242 if (skip_past_comma (&ptr) == SUCCESS)
6243 {
6244 /* Case 15. */
6245 i++;
6246
6247 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6248 goto wanted_arm;
6249
6250 inst.operands[i].reg = val;
6251 inst.operands[i].isreg = 1;
6252 inst.operands[i++].present = 1;
6253
6254 if (skip_past_comma (&ptr) == FAIL)
6255 goto wanted_comma;
6256
6257 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6258 goto wanted_arm;
6259
6260 inst.operands[i].reg = val;
6261 inst.operands[i].isreg = 1;
6262 inst.operands[i].present = 1;
6263 }
6264 }
4641781c 6265 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6266 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6267 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6268 Case 10: VMOV.F32 <Sd>, #<imm>
6269 Case 11: VMOV.F64 <Dd>, #<imm> */
6270 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6271 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6272 == SUCCESS)
477330fc
RM
6273 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6274 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6275 ;
5287ad62 6276 else
477330fc
RM
6277 {
6278 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6279 return FAIL;
6280 }
5287ad62 6281 }
dcbf9037 6282 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6283 {
6284 /* Cases 6, 7. */
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isreg = 1;
6287 inst.operands[i++].present = 1;
5f4273c7 6288
5287ad62 6289 if (skip_past_comma (&ptr) == FAIL)
477330fc 6290 goto wanted_comma;
5f4273c7 6291
dcbf9037 6292 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6293 {
6294 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6295 inst.operands[i].reg = val;
6296 inst.operands[i].isscalar = 1;
6297 inst.operands[i].present = 1;
6298 inst.operands[i].vectype = optype;
6299 }
dcbf9037 6300 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6301 {
6302 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6303 inst.operands[i].reg = val;
6304 inst.operands[i].isreg = 1;
6305 inst.operands[i++].present = 1;
6306
6307 if (skip_past_comma (&ptr) == FAIL)
6308 goto wanted_comma;
6309
6310 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6311 == FAIL)
6312 {
6313 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6314 return FAIL;
6315 }
6316
6317 inst.operands[i].reg = val;
6318 inst.operands[i].isreg = 1;
6319 inst.operands[i].isvec = 1;
6320 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6321 inst.operands[i].vectype = optype;
6322 inst.operands[i].present = 1;
6323
6324 if (rtype == REG_TYPE_VFS)
6325 {
6326 /* Case 14. */
6327 i++;
6328 if (skip_past_comma (&ptr) == FAIL)
6329 goto wanted_comma;
6330 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6331 &optype)) == FAIL)
6332 {
6333 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6334 return FAIL;
6335 }
6336 inst.operands[i].reg = val;
6337 inst.operands[i].isreg = 1;
6338 inst.operands[i].isvec = 1;
6339 inst.operands[i].issingle = 1;
6340 inst.operands[i].vectype = optype;
6341 inst.operands[i].present = 1;
6342 }
6343 }
037e8744 6344 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6345 != FAIL)
6346 {
6347 /* Case 13. */
6348 inst.operands[i].reg = val;
6349 inst.operands[i].isreg = 1;
6350 inst.operands[i].isvec = 1;
6351 inst.operands[i].issingle = 1;
6352 inst.operands[i].vectype = optype;
6353 inst.operands[i].present = 1;
6354 }
5287ad62
JB
6355 }
6356 else
6357 {
dcbf9037 6358 first_error (_("parse error"));
5287ad62
JB
6359 return FAIL;
6360 }
6361
6362 /* Successfully parsed the operands. Update args. */
6363 *which_operand = i;
6364 *str = ptr;
6365 return SUCCESS;
6366
5f4273c7 6367 wanted_comma:
dcbf9037 6368 first_error (_("expected comma"));
5287ad62 6369 return FAIL;
5f4273c7
NC
6370
6371 wanted_arm:
dcbf9037 6372 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6373 return FAIL;
5287ad62
JB
6374}
6375
5be8be5d
DG
6376/* Use this macro when the operand constraints are different
6377 for ARM and THUMB (e.g. ldrd). */
6378#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6379 ((arm_operand) | ((thumb_operand) << 16))
6380
c19d1205
ZW
6381/* Matcher codes for parse_operands. */
6382enum operand_parse_code
6383{
6384 OP_stop, /* end of line */
6385
6386 OP_RR, /* ARM register */
6387 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6388 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6389 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6390 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6391 optional trailing ! */
c19d1205
ZW
6392 OP_RRw, /* ARM register, not r15, optional trailing ! */
6393 OP_RCP, /* Coprocessor number */
6394 OP_RCN, /* Coprocessor register */
6395 OP_RF, /* FPA register */
6396 OP_RVS, /* VFP single precision register */
5287ad62
JB
6397 OP_RVD, /* VFP double precision register (0..15) */
6398 OP_RND, /* Neon double precision register (0..31) */
6399 OP_RNQ, /* Neon quad precision register */
037e8744 6400 OP_RVSD, /* VFP single or double precision register */
5287ad62 6401 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6402 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6403 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6404 OP_RVC, /* VFP control register */
6405 OP_RMF, /* Maverick F register */
6406 OP_RMD, /* Maverick D register */
6407 OP_RMFX, /* Maverick FX register */
6408 OP_RMDX, /* Maverick DX register */
6409 OP_RMAX, /* Maverick AX register */
6410 OP_RMDS, /* Maverick DSPSC register */
6411 OP_RIWR, /* iWMMXt wR register */
6412 OP_RIWC, /* iWMMXt wC register */
6413 OP_RIWG, /* iWMMXt wCG register */
6414 OP_RXA, /* XScale accumulator register */
6415
6416 OP_REGLST, /* ARM register list */
6417 OP_VRSLST, /* VFP single-precision register list */
6418 OP_VRDLST, /* VFP double-precision register list */
037e8744 6419 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6420 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6421 OP_NSTRLST, /* Neon element/structure list */
6422
5287ad62 6423 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6424 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6425 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6426 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6427 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6428 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6429 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6430 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6431 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6432 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6433 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6434
6435 OP_I0, /* immediate zero */
c19d1205
ZW
6436 OP_I7, /* immediate value 0 .. 7 */
6437 OP_I15, /* 0 .. 15 */
6438 OP_I16, /* 1 .. 16 */
5287ad62 6439 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6440 OP_I31, /* 0 .. 31 */
6441 OP_I31w, /* 0 .. 31, optional trailing ! */
6442 OP_I32, /* 1 .. 32 */
5287ad62
JB
6443 OP_I32z, /* 0 .. 32 */
6444 OP_I63, /* 0 .. 63 */
c19d1205 6445 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6446 OP_I64, /* 1 .. 64 */
6447 OP_I64z, /* 0 .. 64 */
c19d1205 6448 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6449
6450 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6451 OP_I7b, /* 0 .. 7 */
6452 OP_I15b, /* 0 .. 15 */
6453 OP_I31b, /* 0 .. 31 */
6454
6455 OP_SH, /* shifter operand */
4962c51a 6456 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6457 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6458 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6459 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6460 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6461 OP_EXP, /* arbitrary expression */
6462 OP_EXPi, /* same, with optional immediate prefix */
6463 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6464 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6465
6466 OP_CPSF, /* CPS flags */
6467 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6468 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6469 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6470 OP_COND, /* conditional code */
92e90b6e 6471 OP_TB, /* Table branch. */
c19d1205 6472
037e8744
JB
6473 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6474
c19d1205
ZW
6475 OP_RRnpc_I0, /* ARM register or literal 0 */
6476 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6477 OP_RR_EXi, /* ARM register or expression with imm prefix */
6478 OP_RF_IF, /* FPA register or immediate */
6479 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6480 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6481
6482 /* Optional operands. */
6483 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6484 OP_oI31b, /* 0 .. 31 */
5287ad62 6485 OP_oI32b, /* 1 .. 32 */
5f1af56b 6486 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6487 OP_oIffffb, /* 0 .. 65535 */
6488 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6489
6490 OP_oRR, /* ARM register */
6491 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6492 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6493 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6494 OP_oRND, /* Optional Neon double precision register */
6495 OP_oRNQ, /* Optional Neon quad precision register */
6496 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6497 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6498 OP_oSHll, /* LSL immediate */
6499 OP_oSHar, /* ASR immediate */
6500 OP_oSHllar, /* LSL or ASR immediate */
6501 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6502 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6503
5be8be5d
DG
6504 /* Some pre-defined mixed (ARM/THUMB) operands. */
6505 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6506 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6507 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6508
c19d1205
ZW
6509 OP_FIRST_OPTIONAL = OP_oI7b
6510};
a737bd4d 6511
c19d1205
ZW
6512/* Generic instruction operand parser. This does no encoding and no
6513 semantic validation; it merely squirrels values away in the inst
6514 structure. Returns SUCCESS or FAIL depending on whether the
6515 specified grammar matched. */
6516static int
5be8be5d 6517parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6518{
5be8be5d 6519 unsigned const int *upat = pattern;
c19d1205
ZW
6520 char *backtrack_pos = 0;
6521 const char *backtrack_error = 0;
99aad254 6522 int i, val = 0, backtrack_index = 0;
5287ad62 6523 enum arm_reg_type rtype;
4962c51a 6524 parse_operand_result result;
5be8be5d 6525 unsigned int op_parse_code;
c19d1205 6526
e07e6e58
NC
6527#define po_char_or_fail(chr) \
6528 do \
6529 { \
6530 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6531 goto bad_args; \
e07e6e58
NC
6532 } \
6533 while (0)
c19d1205 6534
e07e6e58
NC
6535#define po_reg_or_fail(regtype) \
6536 do \
dcbf9037 6537 { \
e07e6e58 6538 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6539 & inst.operands[i].vectype); \
e07e6e58 6540 if (val == FAIL) \
477330fc
RM
6541 { \
6542 first_error (_(reg_expected_msgs[regtype])); \
6543 goto failure; \
6544 } \
e07e6e58
NC
6545 inst.operands[i].reg = val; \
6546 inst.operands[i].isreg = 1; \
6547 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6548 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6549 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6550 || rtype == REG_TYPE_VFD \
6551 || rtype == REG_TYPE_NQ); \
dcbf9037 6552 } \
e07e6e58
NC
6553 while (0)
6554
6555#define po_reg_or_goto(regtype, label) \
6556 do \
6557 { \
6558 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6559 & inst.operands[i].vectype); \
6560 if (val == FAIL) \
6561 goto label; \
dcbf9037 6562 \
e07e6e58
NC
6563 inst.operands[i].reg = val; \
6564 inst.operands[i].isreg = 1; \
6565 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6566 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6567 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6568 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6569 || rtype == REG_TYPE_NQ); \
6570 } \
6571 while (0)
6572
6573#define po_imm_or_fail(min, max, popt) \
6574 do \
6575 { \
6576 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6577 goto failure; \
6578 inst.operands[i].imm = val; \
6579 } \
6580 while (0)
6581
6582#define po_scalar_or_goto(elsz, label) \
6583 do \
6584 { \
6585 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6586 if (val == FAIL) \
6587 goto label; \
6588 inst.operands[i].reg = val; \
6589 inst.operands[i].isscalar = 1; \
6590 } \
6591 while (0)
6592
6593#define po_misc_or_fail(expr) \
6594 do \
6595 { \
6596 if (expr) \
6597 goto failure; \
6598 } \
6599 while (0)
6600
6601#define po_misc_or_fail_no_backtrack(expr) \
6602 do \
6603 { \
6604 result = expr; \
6605 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6606 backtrack_pos = 0; \
6607 if (result != PARSE_OPERAND_SUCCESS) \
6608 goto failure; \
6609 } \
6610 while (0)
4962c51a 6611
52e7f43d
RE
6612#define po_barrier_or_imm(str) \
6613 do \
6614 { \
6615 val = parse_barrier (&str); \
ccb84d65
JB
6616 if (val == FAIL && ! ISALPHA (*str)) \
6617 goto immediate; \
6618 if (val == FAIL \
6619 /* ISB can only take SY as an option. */ \
6620 || ((inst.instruction & 0xf0) == 0x60 \
6621 && val != 0xf)) \
52e7f43d 6622 { \
ccb84d65
JB
6623 inst.error = _("invalid barrier type"); \
6624 backtrack_pos = 0; \
6625 goto failure; \
52e7f43d
RE
6626 } \
6627 } \
6628 while (0)
6629
c19d1205
ZW
6630 skip_whitespace (str);
6631
6632 for (i = 0; upat[i] != OP_stop; i++)
6633 {
5be8be5d
DG
6634 op_parse_code = upat[i];
6635 if (op_parse_code >= 1<<16)
6636 op_parse_code = thumb ? (op_parse_code >> 16)
6637 : (op_parse_code & ((1<<16)-1));
6638
6639 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6640 {
6641 /* Remember where we are in case we need to backtrack. */
9c2799c2 6642 gas_assert (!backtrack_pos);
c19d1205
ZW
6643 backtrack_pos = str;
6644 backtrack_error = inst.error;
6645 backtrack_index = i;
6646 }
6647
b6702015 6648 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6649 po_char_or_fail (',');
6650
5be8be5d 6651 switch (op_parse_code)
c19d1205
ZW
6652 {
6653 /* Registers */
6654 case OP_oRRnpc:
5be8be5d 6655 case OP_oRRnpcsp:
c19d1205 6656 case OP_RRnpc:
5be8be5d 6657 case OP_RRnpcsp:
c19d1205
ZW
6658 case OP_oRR:
6659 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6660 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6661 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6662 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6663 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6664 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6665 case OP_oRND:
5287ad62 6666 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6667 case OP_RVC:
6668 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6669 break;
6670 /* Also accept generic coprocessor regs for unknown registers. */
6671 coproc_reg:
6672 po_reg_or_fail (REG_TYPE_CN);
6673 break;
c19d1205
ZW
6674 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6675 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6676 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6677 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6678 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6679 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6680 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6681 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6682 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6683 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6684 case OP_oRNQ:
5287ad62 6685 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6686 case OP_oRNDQ:
5287ad62 6687 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6688 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6689 case OP_oRNSDQ:
6690 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6691
6692 /* Neon scalar. Using an element size of 8 means that some invalid
6693 scalars are accepted here, so deal with those in later code. */
6694 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6695
6696 case OP_RNDQ_I0:
6697 {
6698 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6699 break;
6700 try_imm0:
6701 po_imm_or_fail (0, 0, TRUE);
6702 }
6703 break;
6704
6705 case OP_RVSD_I0:
6706 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6707 break;
6708
aacf0b33
KT
6709 case OP_RSVD_FI0:
6710 {
6711 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6712 break;
6713 try_ifimm0:
6714 if (parse_ifimm_zero (&str))
6715 inst.operands[i].imm = 0;
6716 else
6717 {
6718 inst.error
6719 = _("only floating point zero is allowed as immediate value");
6720 goto failure;
6721 }
6722 }
6723 break;
6724
477330fc
RM
6725 case OP_RR_RNSC:
6726 {
6727 po_scalar_or_goto (8, try_rr);
6728 break;
6729 try_rr:
6730 po_reg_or_fail (REG_TYPE_RN);
6731 }
6732 break;
6733
6734 case OP_RNSDQ_RNSC:
6735 {
6736 po_scalar_or_goto (8, try_nsdq);
6737 break;
6738 try_nsdq:
6739 po_reg_or_fail (REG_TYPE_NSDQ);
6740 }
6741 break;
6742
6743 case OP_RNDQ_RNSC:
6744 {
6745 po_scalar_or_goto (8, try_ndq);
6746 break;
6747 try_ndq:
6748 po_reg_or_fail (REG_TYPE_NDQ);
6749 }
6750 break;
6751
6752 case OP_RND_RNSC:
6753 {
6754 po_scalar_or_goto (8, try_vfd);
6755 break;
6756 try_vfd:
6757 po_reg_or_fail (REG_TYPE_VFD);
6758 }
6759 break;
6760
6761 case OP_VMOV:
6762 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6763 not careful then bad things might happen. */
6764 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6765 break;
6766
6767 case OP_RNDQ_Ibig:
6768 {
6769 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6770 break;
6771 try_immbig:
6772 /* There's a possibility of getting a 64-bit immediate here, so
6773 we need special handling. */
8335d6aa
JW
6774 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6775 == FAIL)
477330fc
RM
6776 {
6777 inst.error = _("immediate value is out of range");
6778 goto failure;
6779 }
6780 }
6781 break;
6782
6783 case OP_RNDQ_I63b:
6784 {
6785 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6786 break;
6787 try_shimm:
6788 po_imm_or_fail (0, 63, TRUE);
6789 }
6790 break;
c19d1205
ZW
6791
6792 case OP_RRnpcb:
6793 po_char_or_fail ('[');
6794 po_reg_or_fail (REG_TYPE_RN);
6795 po_char_or_fail (']');
6796 break;
a737bd4d 6797
55881a11 6798 case OP_RRnpctw:
c19d1205 6799 case OP_RRw:
b6702015 6800 case OP_oRRw:
c19d1205
ZW
6801 po_reg_or_fail (REG_TYPE_RN);
6802 if (skip_past_char (&str, '!') == SUCCESS)
6803 inst.operands[i].writeback = 1;
6804 break;
6805
6806 /* Immediates */
6807 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6808 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6809 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6810 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6811 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6812 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6813 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6814 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6815 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6816 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6817 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6818 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6819
6820 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6821 case OP_oI7b:
6822 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6823 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6824 case OP_oI31b:
6825 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6826 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6827 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6828 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6829
6830 /* Immediate variants */
6831 case OP_oI255c:
6832 po_char_or_fail ('{');
6833 po_imm_or_fail (0, 255, TRUE);
6834 po_char_or_fail ('}');
6835 break;
6836
6837 case OP_I31w:
6838 /* The expression parser chokes on a trailing !, so we have
6839 to find it first and zap it. */
6840 {
6841 char *s = str;
6842 while (*s && *s != ',')
6843 s++;
6844 if (s[-1] == '!')
6845 {
6846 s[-1] = '\0';
6847 inst.operands[i].writeback = 1;
6848 }
6849 po_imm_or_fail (0, 31, TRUE);
6850 if (str == s - 1)
6851 str = s;
6852 }
6853 break;
6854
6855 /* Expressions */
6856 case OP_EXPi: EXPi:
6857 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6858 GE_OPT_PREFIX));
6859 break;
6860
6861 case OP_EXP:
6862 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6863 GE_NO_PREFIX));
6864 break;
6865
6866 case OP_EXPr: EXPr:
6867 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6868 GE_NO_PREFIX));
6869 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6870 {
c19d1205
ZW
6871 val = parse_reloc (&str);
6872 if (val == -1)
6873 {
6874 inst.error = _("unrecognized relocation suffix");
6875 goto failure;
6876 }
6877 else if (val != BFD_RELOC_UNUSED)
6878 {
6879 inst.operands[i].imm = val;
6880 inst.operands[i].hasreloc = 1;
6881 }
a737bd4d 6882 }
c19d1205 6883 break;
a737bd4d 6884
b6895b4f
PB
6885 /* Operand for MOVW or MOVT. */
6886 case OP_HALF:
6887 po_misc_or_fail (parse_half (&str));
6888 break;
6889
e07e6e58 6890 /* Register or expression. */
c19d1205
ZW
6891 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6892 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6893
e07e6e58 6894 /* Register or immediate. */
c19d1205
ZW
6895 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6896 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6897
c19d1205
ZW
6898 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6899 IF:
6900 if (!is_immediate_prefix (*str))
6901 goto bad_args;
6902 str++;
6903 val = parse_fpa_immediate (&str);
6904 if (val == FAIL)
6905 goto failure;
6906 /* FPA immediates are encoded as registers 8-15.
6907 parse_fpa_immediate has already applied the offset. */
6908 inst.operands[i].reg = val;
6909 inst.operands[i].isreg = 1;
6910 break;
09d92015 6911
2d447fca
JM
6912 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6913 I32z: po_imm_or_fail (0, 32, FALSE); break;
6914
e07e6e58 6915 /* Two kinds of register. */
c19d1205
ZW
6916 case OP_RIWR_RIWC:
6917 {
6918 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6919 if (!rege
6920 || (rege->type != REG_TYPE_MMXWR
6921 && rege->type != REG_TYPE_MMXWC
6922 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6923 {
6924 inst.error = _("iWMMXt data or control register expected");
6925 goto failure;
6926 }
6927 inst.operands[i].reg = rege->number;
6928 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6929 }
6930 break;
09d92015 6931
41adaa5c
JM
6932 case OP_RIWC_RIWG:
6933 {
6934 struct reg_entry *rege = arm_reg_parse_multi (&str);
6935 if (!rege
6936 || (rege->type != REG_TYPE_MMXWC
6937 && rege->type != REG_TYPE_MMXWCG))
6938 {
6939 inst.error = _("iWMMXt control register expected");
6940 goto failure;
6941 }
6942 inst.operands[i].reg = rege->number;
6943 inst.operands[i].isreg = 1;
6944 }
6945 break;
6946
c19d1205
ZW
6947 /* Misc */
6948 case OP_CPSF: val = parse_cps_flags (&str); break;
6949 case OP_ENDI: val = parse_endian_specifier (&str); break;
6950 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6951 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6952 case OP_oBARRIER_I15:
6953 po_barrier_or_imm (str); break;
6954 immediate:
6955 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 6956 goto failure;
52e7f43d 6957 break;
c19d1205 6958
fa94de6b 6959 case OP_wPSR:
d2cd1205 6960 case OP_rPSR:
90ec0d68
MGD
6961 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6962 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6963 {
6964 inst.error = _("Banked registers are not available with this "
6965 "architecture.");
6966 goto failure;
6967 }
6968 break;
d2cd1205
JB
6969 try_psr:
6970 val = parse_psr (&str, op_parse_code == OP_wPSR);
6971 break;
037e8744 6972
477330fc
RM
6973 case OP_APSR_RR:
6974 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6975 break;
6976 try_apsr:
6977 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6978 instruction). */
6979 if (strncasecmp (str, "APSR_", 5) == 0)
6980 {
6981 unsigned found = 0;
6982 str += 5;
6983 while (found < 15)
6984 switch (*str++)
6985 {
6986 case 'c': found = (found & 1) ? 16 : found | 1; break;
6987 case 'n': found = (found & 2) ? 16 : found | 2; break;
6988 case 'z': found = (found & 4) ? 16 : found | 4; break;
6989 case 'v': found = (found & 8) ? 16 : found | 8; break;
6990 default: found = 16;
6991 }
6992 if (found != 15)
6993 goto failure;
6994 inst.operands[i].isvec = 1;
f7c21dc7
NC
6995 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6996 inst.operands[i].reg = REG_PC;
477330fc
RM
6997 }
6998 else
6999 goto failure;
7000 break;
037e8744 7001
92e90b6e
PB
7002 case OP_TB:
7003 po_misc_or_fail (parse_tb (&str));
7004 break;
7005
e07e6e58 7006 /* Register lists. */
c19d1205
ZW
7007 case OP_REGLST:
7008 val = parse_reg_list (&str);
7009 if (*str == '^')
7010 {
5e0d7f77 7011 inst.operands[i].writeback = 1;
c19d1205
ZW
7012 str++;
7013 }
7014 break;
09d92015 7015
c19d1205 7016 case OP_VRSLST:
5287ad62 7017 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7018 break;
09d92015 7019
c19d1205 7020 case OP_VRDLST:
5287ad62 7021 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7022 break;
a737bd4d 7023
477330fc
RM
7024 case OP_VRSDLST:
7025 /* Allow Q registers too. */
7026 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7027 REGLIST_NEON_D);
7028 if (val == FAIL)
7029 {
7030 inst.error = NULL;
7031 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7032 REGLIST_VFP_S);
7033 inst.operands[i].issingle = 1;
7034 }
7035 break;
7036
7037 case OP_NRDLST:
7038 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7039 REGLIST_NEON_D);
7040 break;
5287ad62
JB
7041
7042 case OP_NSTRLST:
477330fc
RM
7043 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7044 &inst.operands[i].vectype);
7045 break;
5287ad62 7046
c19d1205
ZW
7047 /* Addressing modes */
7048 case OP_ADDR:
7049 po_misc_or_fail (parse_address (&str, i));
7050 break;
09d92015 7051
4962c51a
MS
7052 case OP_ADDRGLDR:
7053 po_misc_or_fail_no_backtrack (
477330fc 7054 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7055 break;
7056
7057 case OP_ADDRGLDRS:
7058 po_misc_or_fail_no_backtrack (
477330fc 7059 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7060 break;
7061
7062 case OP_ADDRGLDC:
7063 po_misc_or_fail_no_backtrack (
477330fc 7064 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7065 break;
7066
c19d1205
ZW
7067 case OP_SH:
7068 po_misc_or_fail (parse_shifter_operand (&str, i));
7069 break;
09d92015 7070
4962c51a
MS
7071 case OP_SHG:
7072 po_misc_or_fail_no_backtrack (
477330fc 7073 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7074 break;
7075
c19d1205
ZW
7076 case OP_oSHll:
7077 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7078 break;
09d92015 7079
c19d1205
ZW
7080 case OP_oSHar:
7081 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7082 break;
09d92015 7083
c19d1205
ZW
7084 case OP_oSHllar:
7085 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7086 break;
09d92015 7087
c19d1205 7088 default:
5be8be5d 7089 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7090 }
09d92015 7091
c19d1205
ZW
7092 /* Various value-based sanity checks and shared operations. We
7093 do not signal immediate failures for the register constraints;
7094 this allows a syntax error to take precedence. */
5be8be5d 7095 switch (op_parse_code)
c19d1205
ZW
7096 {
7097 case OP_oRRnpc:
7098 case OP_RRnpc:
7099 case OP_RRnpcb:
7100 case OP_RRw:
b6702015 7101 case OP_oRRw:
c19d1205
ZW
7102 case OP_RRnpc_I0:
7103 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7104 inst.error = BAD_PC;
7105 break;
09d92015 7106
5be8be5d
DG
7107 case OP_oRRnpcsp:
7108 case OP_RRnpcsp:
7109 if (inst.operands[i].isreg)
7110 {
7111 if (inst.operands[i].reg == REG_PC)
7112 inst.error = BAD_PC;
7113 else if (inst.operands[i].reg == REG_SP)
7114 inst.error = BAD_SP;
7115 }
7116 break;
7117
55881a11 7118 case OP_RRnpctw:
fa94de6b
RM
7119 if (inst.operands[i].isreg
7120 && inst.operands[i].reg == REG_PC
55881a11
MGD
7121 && (inst.operands[i].writeback || thumb))
7122 inst.error = BAD_PC;
7123 break;
7124
c19d1205
ZW
7125 case OP_CPSF:
7126 case OP_ENDI:
7127 case OP_oROR:
d2cd1205
JB
7128 case OP_wPSR:
7129 case OP_rPSR:
c19d1205 7130 case OP_COND:
52e7f43d 7131 case OP_oBARRIER_I15:
c19d1205
ZW
7132 case OP_REGLST:
7133 case OP_VRSLST:
7134 case OP_VRDLST:
477330fc
RM
7135 case OP_VRSDLST:
7136 case OP_NRDLST:
7137 case OP_NSTRLST:
c19d1205
ZW
7138 if (val == FAIL)
7139 goto failure;
7140 inst.operands[i].imm = val;
7141 break;
a737bd4d 7142
c19d1205
ZW
7143 default:
7144 break;
7145 }
09d92015 7146
c19d1205
ZW
7147 /* If we get here, this operand was successfully parsed. */
7148 inst.operands[i].present = 1;
7149 continue;
09d92015 7150
c19d1205 7151 bad_args:
09d92015 7152 inst.error = BAD_ARGS;
c19d1205
ZW
7153
7154 failure:
7155 if (!backtrack_pos)
d252fdde
PB
7156 {
7157 /* The parse routine should already have set inst.error, but set a
5f4273c7 7158 default here just in case. */
d252fdde
PB
7159 if (!inst.error)
7160 inst.error = _("syntax error");
7161 return FAIL;
7162 }
c19d1205
ZW
7163
7164 /* Do not backtrack over a trailing optional argument that
7165 absorbed some text. We will only fail again, with the
7166 'garbage following instruction' error message, which is
7167 probably less helpful than the current one. */
7168 if (backtrack_index == i && backtrack_pos != str
7169 && upat[i+1] == OP_stop)
d252fdde
PB
7170 {
7171 if (!inst.error)
7172 inst.error = _("syntax error");
7173 return FAIL;
7174 }
c19d1205
ZW
7175
7176 /* Try again, skipping the optional argument at backtrack_pos. */
7177 str = backtrack_pos;
7178 inst.error = backtrack_error;
7179 inst.operands[backtrack_index].present = 0;
7180 i = backtrack_index;
7181 backtrack_pos = 0;
09d92015 7182 }
09d92015 7183
c19d1205
ZW
7184 /* Check that we have parsed all the arguments. */
7185 if (*str != '\0' && !inst.error)
7186 inst.error = _("garbage following instruction");
09d92015 7187
c19d1205 7188 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7189}
7190
c19d1205
ZW
7191#undef po_char_or_fail
7192#undef po_reg_or_fail
7193#undef po_reg_or_goto
7194#undef po_imm_or_fail
5287ad62 7195#undef po_scalar_or_fail
52e7f43d 7196#undef po_barrier_or_imm
e07e6e58 7197
c19d1205 7198/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7199#define constraint(expr, err) \
7200 do \
c19d1205 7201 { \
e07e6e58
NC
7202 if (expr) \
7203 { \
7204 inst.error = err; \
7205 return; \
7206 } \
c19d1205 7207 } \
e07e6e58 7208 while (0)
c19d1205 7209
fdfde340
JM
7210/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7211 instructions are unpredictable if these registers are used. This
7212 is the BadReg predicate in ARM's Thumb-2 documentation. */
7213#define reject_bad_reg(reg) \
7214 do \
7215 if (reg == REG_SP || reg == REG_PC) \
7216 { \
7217 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7218 return; \
7219 } \
7220 while (0)
7221
94206790
MM
7222/* If REG is R13 (the stack pointer), warn that its use is
7223 deprecated. */
7224#define warn_deprecated_sp(reg) \
7225 do \
7226 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7227 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7228 while (0)
7229
c19d1205
ZW
7230/* Functions for operand encoding. ARM, then Thumb. */
7231
d840c081 7232#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205
ZW
7233
7234/* If VAL can be encoded in the immediate field of an ARM instruction,
7235 return the encoded form. Otherwise, return FAIL. */
7236
7237static unsigned int
7238encode_arm_immediate (unsigned int val)
09d92015 7239{
c19d1205
ZW
7240 unsigned int a, i;
7241
7242 for (i = 0; i < 32; i += 2)
7243 if ((a = rotate_left (val, i)) <= 0xff)
7244 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7245
7246 return FAIL;
09d92015
MM
7247}
7248
c19d1205
ZW
7249/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7250 return the encoded form. Otherwise, return FAIL. */
7251static unsigned int
7252encode_thumb32_immediate (unsigned int val)
09d92015 7253{
c19d1205 7254 unsigned int a, i;
09d92015 7255
9c3c69f2 7256 if (val <= 0xff)
c19d1205 7257 return val;
a737bd4d 7258
9c3c69f2 7259 for (i = 1; i <= 24; i++)
09d92015 7260 {
9c3c69f2
PB
7261 a = val >> i;
7262 if ((val & ~(0xff << i)) == 0)
7263 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7264 }
a737bd4d 7265
c19d1205
ZW
7266 a = val & 0xff;
7267 if (val == ((a << 16) | a))
7268 return 0x100 | a;
7269 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7270 return 0x300 | a;
09d92015 7271
c19d1205
ZW
7272 a = val & 0xff00;
7273 if (val == ((a << 16) | a))
7274 return 0x200 | (a >> 8);
a737bd4d 7275
c19d1205 7276 return FAIL;
09d92015 7277}
5287ad62 7278/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7279
7280static void
5287ad62
JB
7281encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7282{
7283 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7284 && reg > 15)
7285 {
b1cc4aeb 7286 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7287 {
7288 if (thumb_mode)
7289 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7290 fpu_vfp_ext_d32);
7291 else
7292 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7293 fpu_vfp_ext_d32);
7294 }
5287ad62 7295 else
477330fc
RM
7296 {
7297 first_error (_("D register out of range for selected VFP version"));
7298 return;
7299 }
5287ad62
JB
7300 }
7301
c19d1205 7302 switch (pos)
09d92015 7303 {
c19d1205
ZW
7304 case VFP_REG_Sd:
7305 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7306 break;
7307
7308 case VFP_REG_Sn:
7309 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7310 break;
7311
7312 case VFP_REG_Sm:
7313 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7314 break;
7315
5287ad62
JB
7316 case VFP_REG_Dd:
7317 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7318 break;
5f4273c7 7319
5287ad62
JB
7320 case VFP_REG_Dn:
7321 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7322 break;
5f4273c7 7323
5287ad62
JB
7324 case VFP_REG_Dm:
7325 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7326 break;
7327
c19d1205
ZW
7328 default:
7329 abort ();
09d92015 7330 }
09d92015
MM
7331}
7332
c19d1205 7333/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7334 if any, is handled by md_apply_fix. */
09d92015 7335static void
c19d1205 7336encode_arm_shift (int i)
09d92015 7337{
c19d1205
ZW
7338 if (inst.operands[i].shift_kind == SHIFT_RRX)
7339 inst.instruction |= SHIFT_ROR << 5;
7340 else
09d92015 7341 {
c19d1205
ZW
7342 inst.instruction |= inst.operands[i].shift_kind << 5;
7343 if (inst.operands[i].immisreg)
7344 {
7345 inst.instruction |= SHIFT_BY_REG;
7346 inst.instruction |= inst.operands[i].imm << 8;
7347 }
7348 else
7349 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7350 }
c19d1205 7351}
09d92015 7352
c19d1205
ZW
7353static void
7354encode_arm_shifter_operand (int i)
7355{
7356 if (inst.operands[i].isreg)
09d92015 7357 {
c19d1205
ZW
7358 inst.instruction |= inst.operands[i].reg;
7359 encode_arm_shift (i);
09d92015 7360 }
c19d1205 7361 else
a415b1cd
JB
7362 {
7363 inst.instruction |= INST_IMMEDIATE;
7364 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7365 inst.instruction |= inst.operands[i].imm;
7366 }
09d92015
MM
7367}
7368
c19d1205 7369/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7370static void
c19d1205 7371encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7372{
2b2f5df9
NC
7373 /* PR 14260:
7374 Generate an error if the operand is not a register. */
7375 constraint (!inst.operands[i].isreg,
7376 _("Instruction does not support =N addresses"));
7377
c19d1205 7378 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7379
c19d1205 7380 if (inst.operands[i].preind)
09d92015 7381 {
c19d1205
ZW
7382 if (is_t)
7383 {
7384 inst.error = _("instruction does not accept preindexed addressing");
7385 return;
7386 }
7387 inst.instruction |= PRE_INDEX;
7388 if (inst.operands[i].writeback)
7389 inst.instruction |= WRITE_BACK;
09d92015 7390
c19d1205
ZW
7391 }
7392 else if (inst.operands[i].postind)
7393 {
9c2799c2 7394 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7395 if (is_t)
7396 inst.instruction |= WRITE_BACK;
7397 }
7398 else /* unindexed - only for coprocessor */
09d92015 7399 {
c19d1205 7400 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7401 return;
7402 }
7403
c19d1205
ZW
7404 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7405 && (((inst.instruction & 0x000f0000) >> 16)
7406 == ((inst.instruction & 0x0000f000) >> 12)))
7407 as_warn ((inst.instruction & LOAD_BIT)
7408 ? _("destination register same as write-back base")
7409 : _("source register same as write-back base"));
09d92015
MM
7410}
7411
c19d1205
ZW
7412/* inst.operands[i] was set up by parse_address. Encode it into an
7413 ARM-format mode 2 load or store instruction. If is_t is true,
7414 reject forms that cannot be used with a T instruction (i.e. not
7415 post-indexed). */
a737bd4d 7416static void
c19d1205 7417encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7418{
5be8be5d
DG
7419 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7420
c19d1205 7421 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7422
c19d1205 7423 if (inst.operands[i].immisreg)
09d92015 7424 {
5be8be5d
DG
7425 constraint ((inst.operands[i].imm == REG_PC
7426 || (is_pc && inst.operands[i].writeback)),
7427 BAD_PC_ADDRESSING);
c19d1205
ZW
7428 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7429 inst.instruction |= inst.operands[i].imm;
7430 if (!inst.operands[i].negative)
7431 inst.instruction |= INDEX_UP;
7432 if (inst.operands[i].shifted)
7433 {
7434 if (inst.operands[i].shift_kind == SHIFT_RRX)
7435 inst.instruction |= SHIFT_ROR << 5;
7436 else
7437 {
7438 inst.instruction |= inst.operands[i].shift_kind << 5;
7439 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7440 }
7441 }
09d92015 7442 }
c19d1205 7443 else /* immediate offset in inst.reloc */
09d92015 7444 {
5be8be5d
DG
7445 if (is_pc && !inst.reloc.pc_rel)
7446 {
7447 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7448
7449 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7450 cannot use PC in addressing.
7451 PC cannot be used in writeback addressing, either. */
7452 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7453 BAD_PC_ADDRESSING);
23a10334 7454
dc5ec521 7455 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7456 if (warn_on_deprecated
7457 && !is_load
7458 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7459 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7460 }
7461
c19d1205 7462 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7463 {
7464 /* Prefer + for zero encoded value. */
7465 if (!inst.operands[i].negative)
7466 inst.instruction |= INDEX_UP;
7467 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7468 }
09d92015 7469 }
09d92015
MM
7470}
7471
c19d1205
ZW
7472/* inst.operands[i] was set up by parse_address. Encode it into an
7473 ARM-format mode 3 load or store instruction. Reject forms that
7474 cannot be used with such instructions. If is_t is true, reject
7475 forms that cannot be used with a T instruction (i.e. not
7476 post-indexed). */
7477static void
7478encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7479{
c19d1205 7480 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7481 {
c19d1205
ZW
7482 inst.error = _("instruction does not accept scaled register index");
7483 return;
09d92015 7484 }
a737bd4d 7485
c19d1205 7486 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7487
c19d1205
ZW
7488 if (inst.operands[i].immisreg)
7489 {
5be8be5d 7490 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7491 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7492 BAD_PC_ADDRESSING);
eb9f3f00
JB
7493 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7494 BAD_PC_WRITEBACK);
c19d1205
ZW
7495 inst.instruction |= inst.operands[i].imm;
7496 if (!inst.operands[i].negative)
7497 inst.instruction |= INDEX_UP;
7498 }
7499 else /* immediate offset in inst.reloc */
7500 {
5be8be5d
DG
7501 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7502 && inst.operands[i].writeback),
7503 BAD_PC_WRITEBACK);
c19d1205
ZW
7504 inst.instruction |= HWOFFSET_IMM;
7505 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7506 {
7507 /* Prefer + for zero encoded value. */
7508 if (!inst.operands[i].negative)
7509 inst.instruction |= INDEX_UP;
7510
7511 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7512 }
c19d1205 7513 }
a737bd4d
NC
7514}
7515
8335d6aa
JW
7516/* Write immediate bits [7:0] to the following locations:
7517
7518 |28/24|23 19|18 16|15 4|3 0|
7519 | 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|
7520
7521 This function is used by VMOV/VMVN/VORR/VBIC. */
7522
7523static void
7524neon_write_immbits (unsigned immbits)
7525{
7526 inst.instruction |= immbits & 0xf;
7527 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7528 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7529}
7530
7531/* Invert low-order SIZE bits of XHI:XLO. */
7532
7533static void
7534neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7535{
7536 unsigned immlo = xlo ? *xlo : 0;
7537 unsigned immhi = xhi ? *xhi : 0;
7538
7539 switch (size)
7540 {
7541 case 8:
7542 immlo = (~immlo) & 0xff;
7543 break;
7544
7545 case 16:
7546 immlo = (~immlo) & 0xffff;
7547 break;
7548
7549 case 64:
7550 immhi = (~immhi) & 0xffffffff;
7551 /* fall through. */
7552
7553 case 32:
7554 immlo = (~immlo) & 0xffffffff;
7555 break;
7556
7557 default:
7558 abort ();
7559 }
7560
7561 if (xlo)
7562 *xlo = immlo;
7563
7564 if (xhi)
7565 *xhi = immhi;
7566}
7567
7568/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7569 A, B, C, D. */
09d92015 7570
c19d1205 7571static int
8335d6aa 7572neon_bits_same_in_bytes (unsigned imm)
09d92015 7573{
8335d6aa
JW
7574 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7575 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7576 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7577 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7578}
a737bd4d 7579
8335d6aa 7580/* For immediate of above form, return 0bABCD. */
09d92015 7581
8335d6aa
JW
7582static unsigned
7583neon_squash_bits (unsigned imm)
7584{
7585 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7586 | ((imm & 0x01000000) >> 21);
7587}
7588
7589/* Compress quarter-float representation to 0b...000 abcdefgh. */
7590
7591static unsigned
7592neon_qfloat_bits (unsigned imm)
7593{
7594 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7595}
7596
7597/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7598 the instruction. *OP is passed as the initial value of the op field, and
7599 may be set to a different value depending on the constant (i.e.
7600 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7601 MVN). If the immediate looks like a repeated pattern then also
7602 try smaller element sizes. */
7603
7604static int
7605neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7606 unsigned *immbits, int *op, int size,
7607 enum neon_el_type type)
7608{
7609 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7610 float. */
7611 if (type == NT_float && !float_p)
7612 return FAIL;
7613
7614 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7615 {
8335d6aa
JW
7616 if (size != 32 || *op == 1)
7617 return FAIL;
7618 *immbits = neon_qfloat_bits (immlo);
7619 return 0xf;
7620 }
7621
7622 if (size == 64)
7623 {
7624 if (neon_bits_same_in_bytes (immhi)
7625 && neon_bits_same_in_bytes (immlo))
c19d1205 7626 {
8335d6aa
JW
7627 if (*op == 1)
7628 return FAIL;
7629 *immbits = (neon_squash_bits (immhi) << 4)
7630 | neon_squash_bits (immlo);
7631 *op = 1;
7632 return 0xe;
c19d1205 7633 }
a737bd4d 7634
8335d6aa
JW
7635 if (immhi != immlo)
7636 return FAIL;
7637 }
a737bd4d 7638
8335d6aa 7639 if (size >= 32)
09d92015 7640 {
8335d6aa 7641 if (immlo == (immlo & 0x000000ff))
c19d1205 7642 {
8335d6aa
JW
7643 *immbits = immlo;
7644 return 0x0;
c19d1205 7645 }
8335d6aa 7646 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7647 {
8335d6aa
JW
7648 *immbits = immlo >> 8;
7649 return 0x2;
c19d1205 7650 }
8335d6aa
JW
7651 else if (immlo == (immlo & 0x00ff0000))
7652 {
7653 *immbits = immlo >> 16;
7654 return 0x4;
7655 }
7656 else if (immlo == (immlo & 0xff000000))
7657 {
7658 *immbits = immlo >> 24;
7659 return 0x6;
7660 }
7661 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7662 {
7663 *immbits = (immlo >> 8) & 0xff;
7664 return 0xc;
7665 }
7666 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7667 {
7668 *immbits = (immlo >> 16) & 0xff;
7669 return 0xd;
7670 }
7671
7672 if ((immlo & 0xffff) != (immlo >> 16))
7673 return FAIL;
7674 immlo &= 0xffff;
09d92015 7675 }
a737bd4d 7676
8335d6aa 7677 if (size >= 16)
4962c51a 7678 {
8335d6aa
JW
7679 if (immlo == (immlo & 0x000000ff))
7680 {
7681 *immbits = immlo;
7682 return 0x8;
7683 }
7684 else if (immlo == (immlo & 0x0000ff00))
7685 {
7686 *immbits = immlo >> 8;
7687 return 0xa;
7688 }
7689
7690 if ((immlo & 0xff) != (immlo >> 8))
7691 return FAIL;
7692 immlo &= 0xff;
4962c51a
MS
7693 }
7694
8335d6aa
JW
7695 if (immlo == (immlo & 0x000000ff))
7696 {
7697 /* Don't allow MVN with 8-bit immediate. */
7698 if (*op == 1)
7699 return FAIL;
7700 *immbits = immlo;
7701 return 0xe;
7702 }
26d97720 7703
8335d6aa 7704 return FAIL;
c19d1205 7705}
a737bd4d 7706
5fc177c8 7707#if defined BFD_HOST_64_BIT
ba592044
AM
7708/* Returns TRUE if double precision value V may be cast
7709 to single precision without loss of accuracy. */
7710
7711static bfd_boolean
5fc177c8 7712is_double_a_single (bfd_int64_t v)
ba592044 7713{
5fc177c8 7714 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7715 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7716
7717 return (exp == 0 || exp == 0x7FF
7718 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7719 && (mantissa & 0x1FFFFFFFl) == 0;
7720}
7721
3739860c 7722/* Returns a double precision value casted to single precision
ba592044
AM
7723 (ignoring the least significant bits in exponent and mantissa). */
7724
7725static int
5fc177c8 7726double_to_single (bfd_int64_t v)
ba592044
AM
7727{
7728 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7729 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7730 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7731
7732 if (exp == 0x7FF)
7733 exp = 0xFF;
7734 else
7735 {
7736 exp = exp - 1023 + 127;
7737 if (exp >= 0xFF)
7738 {
7739 /* Infinity. */
7740 exp = 0x7F;
7741 mantissa = 0;
7742 }
7743 else if (exp < 0)
7744 {
7745 /* No denormalized numbers. */
7746 exp = 0;
7747 mantissa = 0;
7748 }
7749 }
7750 mantissa >>= 29;
7751 return (sign << 31) | (exp << 23) | mantissa;
7752}
5fc177c8 7753#endif /* BFD_HOST_64_BIT */
ba592044 7754
8335d6aa
JW
7755enum lit_type
7756{
7757 CONST_THUMB,
7758 CONST_ARM,
7759 CONST_VEC
7760};
7761
ba592044
AM
7762static void do_vfp_nsyn_opcode (const char *);
7763
c19d1205
ZW
7764/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7765 Determine whether it can be performed with a move instruction; if
7766 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7767 return TRUE; if it can't, convert inst.instruction to a literal-pool
7768 load and return FALSE. If this is not a valid thing to do in the
7769 current context, set inst.error and return TRUE.
a737bd4d 7770
c19d1205
ZW
7771 inst.operands[i] describes the destination register. */
7772
c921be7d 7773static bfd_boolean
8335d6aa 7774move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7775{
53365c0d 7776 unsigned long tbit;
8335d6aa
JW
7777 bfd_boolean thumb_p = (t == CONST_THUMB);
7778 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7779
7780 if (thumb_p)
7781 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7782 else
7783 tbit = LOAD_BIT;
7784
7785 if ((inst.instruction & tbit) == 0)
09d92015 7786 {
c19d1205 7787 inst.error = _("invalid pseudo operation");
c921be7d 7788 return TRUE;
09d92015 7789 }
ba592044 7790
8335d6aa
JW
7791 if (inst.reloc.exp.X_op != O_constant
7792 && inst.reloc.exp.X_op != O_symbol
7793 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7794 {
7795 inst.error = _("constant expression expected");
c921be7d 7796 return TRUE;
09d92015 7797 }
ba592044
AM
7798
7799 if (inst.reloc.exp.X_op == O_constant
7800 || inst.reloc.exp.X_op == O_big)
8335d6aa 7801 {
5fc177c8
NC
7802#if defined BFD_HOST_64_BIT
7803 bfd_int64_t v;
7804#else
ba592044 7805 offsetT v;
5fc177c8 7806#endif
ba592044 7807 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7808 {
ba592044
AM
7809 LITTLENUM_TYPE w[X_PRECISION];
7810 LITTLENUM_TYPE * l;
7811
7812 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7813 {
ba592044
AM
7814 gen_to_words (w, X_PRECISION, E_PRECISION);
7815 l = w;
7816 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7817 }
ba592044
AM
7818 else
7819 l = generic_bignum;
3739860c 7820
5fc177c8
NC
7821#if defined BFD_HOST_64_BIT
7822 v =
7823 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7824 << LITTLENUM_NUMBER_OF_BITS)
7825 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7826 << LITTLENUM_NUMBER_OF_BITS)
7827 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7828 << LITTLENUM_NUMBER_OF_BITS)
7829 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7830#else
ba592044
AM
7831 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7832 | (l[0] & LITTLENUM_MASK);
5fc177c8 7833#endif
8335d6aa 7834 }
ba592044
AM
7835 else
7836 v = inst.reloc.exp.X_add_number;
7837
7838 if (!inst.operands[i].issingle)
8335d6aa 7839 {
12569877 7840 if (thumb_p)
8335d6aa 7841 {
2c32be70
CM
7842 /* This can be encoded only for a low register. */
7843 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7844 {
7845 /* This can be done with a mov(1) instruction. */
7846 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7847 inst.instruction |= v;
7848 return TRUE;
7849 }
12569877 7850
582cfe03 7851 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
12569877 7852 {
582cfe03
RR
7853 /* Check if on thumb2 it can be done with a mov.w or mvn.w
7854 instruction. */
12569877
AM
7855 unsigned int newimm;
7856 bfd_boolean isNegated;
7857
7858 newimm = encode_thumb32_immediate (v);
7859 if (newimm != (unsigned int) FAIL)
7860 isNegated = FALSE;
7861 else
7862 {
582cfe03 7863 newimm = encode_thumb32_immediate (~v);
12569877
AM
7864 if (newimm != (unsigned int) FAIL)
7865 isNegated = TRUE;
7866 }
7867
7868 if (newimm != (unsigned int) FAIL)
7869 {
582cfe03
RR
7870 inst.instruction = (0xf04f0000
7871 | (inst.operands[i].reg << 8));
7872 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7873 inst.instruction |= (newimm & 0x800) << 15;
7874 inst.instruction |= (newimm & 0x700) << 4;
7875 inst.instruction |= (newimm & 0x0ff);
7876 return TRUE;
7877 }
582cfe03 7878 else if ((v & ~0xFFFF) == 0)
3739860c 7879 {
582cfe03
RR
7880 /* The number can be loaded with a mov.w instruction. */
7881 int imm = v & 0xFFFF;
12569877 7882
582cfe03 7883 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7884 inst.instruction |= (inst.operands[i].reg << 8);
7885 inst.instruction |= (imm & 0xf000) << 4;
7886 inst.instruction |= (imm & 0x0800) << 15;
7887 inst.instruction |= (imm & 0x0700) << 4;
7888 inst.instruction |= (imm & 0x00ff);
7889 return TRUE;
7890 }
7891 }
8335d6aa 7892 }
12569877 7893 else if (arm_p)
ba592044
AM
7894 {
7895 int value = encode_arm_immediate (v);
12569877 7896
ba592044
AM
7897 if (value != FAIL)
7898 {
7899 /* This can be done with a mov instruction. */
7900 inst.instruction &= LITERAL_MASK;
7901 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7902 inst.instruction |= value & 0xfff;
7903 return TRUE;
7904 }
8335d6aa 7905
ba592044
AM
7906 value = encode_arm_immediate (~ v);
7907 if (value != FAIL)
7908 {
7909 /* This can be done with a mvn instruction. */
7910 inst.instruction &= LITERAL_MASK;
7911 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7912 inst.instruction |= value & 0xfff;
7913 return TRUE;
7914 }
7915 }
7916 else if (t == CONST_VEC)
8335d6aa 7917 {
ba592044
AM
7918 int op = 0;
7919 unsigned immbits = 0;
7920 unsigned immlo = inst.operands[1].imm;
7921 unsigned immhi = inst.operands[1].regisimm
7922 ? inst.operands[1].reg
7923 : inst.reloc.exp.X_unsigned
7924 ? 0
7925 : ((bfd_int64_t)((int) immlo)) >> 32;
7926 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7927 &op, 64, NT_invtype);
7928
7929 if (cmode == FAIL)
7930 {
7931 neon_invert_size (&immlo, &immhi, 64);
7932 op = !op;
7933 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7934 &op, 64, NT_invtype);
7935 }
7936
7937 if (cmode != FAIL)
7938 {
7939 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
7940 | (1 << 23)
7941 | (cmode << 8)
7942 | (op << 5)
7943 | (1 << 4);
7944
7945 /* Fill other bits in vmov encoding for both thumb and arm. */
7946 if (thumb_mode)
eff0bc54 7947 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 7948 else
eff0bc54 7949 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
7950 neon_write_immbits (immbits);
7951 return TRUE;
7952 }
8335d6aa
JW
7953 }
7954 }
8335d6aa 7955
ba592044
AM
7956 if (t == CONST_VEC)
7957 {
7958 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
7959 if (inst.operands[i].issingle
7960 && is_quarter_float (inst.operands[1].imm)
7961 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 7962 {
ba592044
AM
7963 inst.operands[1].imm =
7964 neon_qfloat_bits (v);
7965 do_vfp_nsyn_opcode ("fconsts");
7966 return TRUE;
8335d6aa 7967 }
5fc177c8
NC
7968
7969 /* If our host does not support a 64-bit type then we cannot perform
7970 the following optimization. This mean that there will be a
7971 discrepancy between the output produced by an assembler built for
7972 a 32-bit-only host and the output produced from a 64-bit host, but
7973 this cannot be helped. */
7974#if defined BFD_HOST_64_BIT
ba592044
AM
7975 else if (!inst.operands[1].issingle
7976 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 7977 {
ba592044
AM
7978 if (is_double_a_single (v)
7979 && is_quarter_float (double_to_single (v)))
7980 {
7981 inst.operands[1].imm =
7982 neon_qfloat_bits (double_to_single (v));
7983 do_vfp_nsyn_opcode ("fconstd");
7984 return TRUE;
7985 }
8335d6aa 7986 }
5fc177c8 7987#endif
8335d6aa
JW
7988 }
7989 }
7990
7991 if (add_to_lit_pool ((!inst.operands[i].isvec
7992 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
7993 return TRUE;
7994
7995 inst.operands[1].reg = REG_PC;
7996 inst.operands[1].isreg = 1;
7997 inst.operands[1].preind = 1;
7998 inst.reloc.pc_rel = 1;
7999 inst.reloc.type = (thumb_p
8000 ? BFD_RELOC_ARM_THUMB_OFFSET
8001 : (mode_3
8002 ? BFD_RELOC_ARM_HWLITERAL
8003 : BFD_RELOC_ARM_LITERAL));
8004 return FALSE;
8005}
8006
8007/* inst.operands[i] was set up by parse_address. Encode it into an
8008 ARM-format instruction. Reject all forms which cannot be encoded
8009 into a coprocessor load/store instruction. If wb_ok is false,
8010 reject use of writeback; if unind_ok is false, reject use of
8011 unindexed addressing. If reloc_override is not 0, use it instead
8012 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8013 (in which case it is preserved). */
8014
8015static int
8016encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8017{
8018 if (!inst.operands[i].isreg)
8019 {
99b2a2dd
NC
8020 /* PR 18256 */
8021 if (! inst.operands[0].isvec)
8022 {
8023 inst.error = _("invalid co-processor operand");
8024 return FAIL;
8025 }
8335d6aa
JW
8026 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8027 return SUCCESS;
8028 }
8029
8030 inst.instruction |= inst.operands[i].reg << 16;
8031
8032 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8033
8034 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8035 {
8036 gas_assert (!inst.operands[i].writeback);
8037 if (!unind_ok)
8038 {
8039 inst.error = _("instruction does not support unindexed addressing");
8040 return FAIL;
8041 }
8042 inst.instruction |= inst.operands[i].imm;
8043 inst.instruction |= INDEX_UP;
8044 return SUCCESS;
8045 }
8046
8047 if (inst.operands[i].preind)
8048 inst.instruction |= PRE_INDEX;
8049
8050 if (inst.operands[i].writeback)
09d92015 8051 {
8335d6aa 8052 if (inst.operands[i].reg == REG_PC)
c19d1205 8053 {
8335d6aa
JW
8054 inst.error = _("pc may not be used with write-back");
8055 return FAIL;
c19d1205 8056 }
8335d6aa 8057 if (!wb_ok)
c19d1205 8058 {
8335d6aa
JW
8059 inst.error = _("instruction does not support writeback");
8060 return FAIL;
c19d1205 8061 }
8335d6aa 8062 inst.instruction |= WRITE_BACK;
09d92015
MM
8063 }
8064
8335d6aa
JW
8065 if (reloc_override)
8066 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8067 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8068 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8069 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8070 {
8335d6aa
JW
8071 if (thumb_mode)
8072 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8073 else
8074 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8075 }
8335d6aa
JW
8076
8077 /* Prefer + for zero encoded value. */
8078 if (!inst.operands[i].negative)
8079 inst.instruction |= INDEX_UP;
8080
8081 return SUCCESS;
09d92015
MM
8082}
8083
5f4273c7 8084/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8085 First some generics; their names are taken from the conventional
8086 bit positions for register arguments in ARM format instructions. */
09d92015 8087
a737bd4d 8088static void
c19d1205 8089do_noargs (void)
09d92015 8090{
c19d1205 8091}
a737bd4d 8092
c19d1205
ZW
8093static void
8094do_rd (void)
8095{
8096 inst.instruction |= inst.operands[0].reg << 12;
8097}
a737bd4d 8098
c19d1205
ZW
8099static void
8100do_rd_rm (void)
8101{
8102 inst.instruction |= inst.operands[0].reg << 12;
8103 inst.instruction |= inst.operands[1].reg;
8104}
09d92015 8105
9eb6c0f1
MGD
8106static void
8107do_rm_rn (void)
8108{
8109 inst.instruction |= inst.operands[0].reg;
8110 inst.instruction |= inst.operands[1].reg << 16;
8111}
8112
c19d1205
ZW
8113static void
8114do_rd_rn (void)
8115{
8116 inst.instruction |= inst.operands[0].reg << 12;
8117 inst.instruction |= inst.operands[1].reg << 16;
8118}
a737bd4d 8119
c19d1205
ZW
8120static void
8121do_rn_rd (void)
8122{
8123 inst.instruction |= inst.operands[0].reg << 16;
8124 inst.instruction |= inst.operands[1].reg << 12;
8125}
09d92015 8126
59d09be6
MGD
8127static bfd_boolean
8128check_obsolete (const arm_feature_set *feature, const char *msg)
8129{
8130 if (ARM_CPU_IS_ANY (cpu_variant))
8131 {
5c3696f8 8132 as_tsktsk ("%s", msg);
59d09be6
MGD
8133 return TRUE;
8134 }
8135 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8136 {
8137 as_bad ("%s", msg);
8138 return TRUE;
8139 }
8140
8141 return FALSE;
8142}
8143
c19d1205
ZW
8144static void
8145do_rd_rm_rn (void)
8146{
9a64e435 8147 unsigned Rn = inst.operands[2].reg;
708587a4 8148 /* Enforce restrictions on SWP instruction. */
9a64e435 8149 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8150 {
8151 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8152 _("Rn must not overlap other operands"));
8153
59d09be6
MGD
8154 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8155 */
8156 if (!check_obsolete (&arm_ext_v8,
8157 _("swp{b} use is obsoleted for ARMv8 and later"))
8158 && warn_on_deprecated
8159 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8160 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8161 }
59d09be6 8162
c19d1205
ZW
8163 inst.instruction |= inst.operands[0].reg << 12;
8164 inst.instruction |= inst.operands[1].reg;
9a64e435 8165 inst.instruction |= Rn << 16;
c19d1205 8166}
09d92015 8167
c19d1205
ZW
8168static void
8169do_rd_rn_rm (void)
8170{
8171 inst.instruction |= inst.operands[0].reg << 12;
8172 inst.instruction |= inst.operands[1].reg << 16;
8173 inst.instruction |= inst.operands[2].reg;
8174}
a737bd4d 8175
c19d1205
ZW
8176static void
8177do_rm_rd_rn (void)
8178{
5be8be5d
DG
8179 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8180 constraint (((inst.reloc.exp.X_op != O_constant
8181 && inst.reloc.exp.X_op != O_illegal)
8182 || inst.reloc.exp.X_add_number != 0),
8183 BAD_ADDR_MODE);
c19d1205
ZW
8184 inst.instruction |= inst.operands[0].reg;
8185 inst.instruction |= inst.operands[1].reg << 12;
8186 inst.instruction |= inst.operands[2].reg << 16;
8187}
09d92015 8188
c19d1205
ZW
8189static void
8190do_imm0 (void)
8191{
8192 inst.instruction |= inst.operands[0].imm;
8193}
09d92015 8194
c19d1205
ZW
8195static void
8196do_rd_cpaddr (void)
8197{
8198 inst.instruction |= inst.operands[0].reg << 12;
8199 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8200}
a737bd4d 8201
c19d1205
ZW
8202/* ARM instructions, in alphabetical order by function name (except
8203 that wrapper functions appear immediately after the function they
8204 wrap). */
09d92015 8205
c19d1205
ZW
8206/* This is a pseudo-op of the form "adr rd, label" to be converted
8207 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8208
8209static void
c19d1205 8210do_adr (void)
09d92015 8211{
c19d1205 8212 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8213
c19d1205
ZW
8214 /* Frag hacking will turn this into a sub instruction if the offset turns
8215 out to be negative. */
8216 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8217 inst.reloc.pc_rel = 1;
2fc8bdac 8218 inst.reloc.exp.X_add_number -= 8;
c19d1205 8219}
b99bd4ef 8220
c19d1205
ZW
8221/* This is a pseudo-op of the form "adrl rd, label" to be converted
8222 into a relative address of the form:
8223 add rd, pc, #low(label-.-8)"
8224 add rd, rd, #high(label-.-8)" */
b99bd4ef 8225
c19d1205
ZW
8226static void
8227do_adrl (void)
8228{
8229 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8230
c19d1205
ZW
8231 /* Frag hacking will turn this into a sub instruction if the offset turns
8232 out to be negative. */
8233 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8234 inst.reloc.pc_rel = 1;
8235 inst.size = INSN_SIZE * 2;
2fc8bdac 8236 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8237}
8238
b99bd4ef 8239static void
c19d1205 8240do_arit (void)
b99bd4ef 8241{
c19d1205
ZW
8242 if (!inst.operands[1].present)
8243 inst.operands[1].reg = inst.operands[0].reg;
8244 inst.instruction |= inst.operands[0].reg << 12;
8245 inst.instruction |= inst.operands[1].reg << 16;
8246 encode_arm_shifter_operand (2);
8247}
b99bd4ef 8248
62b3e311
PB
8249static void
8250do_barrier (void)
8251{
8252 if (inst.operands[0].present)
ccb84d65 8253 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8254 else
8255 inst.instruction |= 0xf;
8256}
8257
c19d1205
ZW
8258static void
8259do_bfc (void)
8260{
8261 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8262 constraint (msb > 32, _("bit-field extends past end of register"));
8263 /* The instruction encoding stores the LSB and MSB,
8264 not the LSB and width. */
8265 inst.instruction |= inst.operands[0].reg << 12;
8266 inst.instruction |= inst.operands[1].imm << 7;
8267 inst.instruction |= (msb - 1) << 16;
8268}
b99bd4ef 8269
c19d1205
ZW
8270static void
8271do_bfi (void)
8272{
8273 unsigned int msb;
b99bd4ef 8274
c19d1205
ZW
8275 /* #0 in second position is alternative syntax for bfc, which is
8276 the same instruction but with REG_PC in the Rm field. */
8277 if (!inst.operands[1].isreg)
8278 inst.operands[1].reg = REG_PC;
b99bd4ef 8279
c19d1205
ZW
8280 msb = inst.operands[2].imm + inst.operands[3].imm;
8281 constraint (msb > 32, _("bit-field extends past end of register"));
8282 /* The instruction encoding stores the LSB and MSB,
8283 not the LSB and width. */
8284 inst.instruction |= inst.operands[0].reg << 12;
8285 inst.instruction |= inst.operands[1].reg;
8286 inst.instruction |= inst.operands[2].imm << 7;
8287 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8288}
8289
b99bd4ef 8290static void
c19d1205 8291do_bfx (void)
b99bd4ef 8292{
c19d1205
ZW
8293 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8294 _("bit-field extends past end of register"));
8295 inst.instruction |= inst.operands[0].reg << 12;
8296 inst.instruction |= inst.operands[1].reg;
8297 inst.instruction |= inst.operands[2].imm << 7;
8298 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8299}
09d92015 8300
c19d1205
ZW
8301/* ARM V5 breakpoint instruction (argument parse)
8302 BKPT <16 bit unsigned immediate>
8303 Instruction is not conditional.
8304 The bit pattern given in insns[] has the COND_ALWAYS condition,
8305 and it is an error if the caller tried to override that. */
b99bd4ef 8306
c19d1205
ZW
8307static void
8308do_bkpt (void)
8309{
8310 /* Top 12 of 16 bits to bits 19:8. */
8311 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8312
c19d1205
ZW
8313 /* Bottom 4 of 16 bits to bits 3:0. */
8314 inst.instruction |= inst.operands[0].imm & 0xf;
8315}
09d92015 8316
c19d1205
ZW
8317static void
8318encode_branch (int default_reloc)
8319{
8320 if (inst.operands[0].hasreloc)
8321 {
0855e32b
NS
8322 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8323 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8324 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8325 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8326 ? BFD_RELOC_ARM_PLT32
8327 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8328 }
b99bd4ef 8329 else
9ae92b05 8330 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8331 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8332}
8333
b99bd4ef 8334static void
c19d1205 8335do_branch (void)
b99bd4ef 8336{
39b41c9c
PB
8337#ifdef OBJ_ELF
8338 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8339 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8340 else
8341#endif
8342 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8343}
8344
8345static void
8346do_bl (void)
8347{
8348#ifdef OBJ_ELF
8349 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8350 {
8351 if (inst.cond == COND_ALWAYS)
8352 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8353 else
8354 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8355 }
8356 else
8357#endif
8358 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8359}
b99bd4ef 8360
c19d1205
ZW
8361/* ARM V5 branch-link-exchange instruction (argument parse)
8362 BLX <target_addr> ie BLX(1)
8363 BLX{<condition>} <Rm> ie BLX(2)
8364 Unfortunately, there are two different opcodes for this mnemonic.
8365 So, the insns[].value is not used, and the code here zaps values
8366 into inst.instruction.
8367 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8368
c19d1205
ZW
8369static void
8370do_blx (void)
8371{
8372 if (inst.operands[0].isreg)
b99bd4ef 8373 {
c19d1205
ZW
8374 /* Arg is a register; the opcode provided by insns[] is correct.
8375 It is not illegal to do "blx pc", just useless. */
8376 if (inst.operands[0].reg == REG_PC)
8377 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8378
c19d1205
ZW
8379 inst.instruction |= inst.operands[0].reg;
8380 }
8381 else
b99bd4ef 8382 {
c19d1205 8383 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8384 conditionally, and the opcode must be adjusted.
8385 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8386 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8387 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8388 inst.instruction = 0xfa000000;
267bf995 8389 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8390 }
c19d1205
ZW
8391}
8392
8393static void
8394do_bx (void)
8395{
845b51d6
PB
8396 bfd_boolean want_reloc;
8397
c19d1205
ZW
8398 if (inst.operands[0].reg == REG_PC)
8399 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8400
c19d1205 8401 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8402 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8403 it is for ARMv4t or earlier. */
8404 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8405 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8406 want_reloc = TRUE;
8407
5ad34203 8408#ifdef OBJ_ELF
845b51d6 8409 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8410#endif
584206db 8411 want_reloc = FALSE;
845b51d6
PB
8412
8413 if (want_reloc)
8414 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8415}
8416
c19d1205
ZW
8417
8418/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8419
8420static void
c19d1205 8421do_bxj (void)
a737bd4d 8422{
c19d1205
ZW
8423 if (inst.operands[0].reg == REG_PC)
8424 as_tsktsk (_("use of r15 in bxj is not really useful"));
8425
8426 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8427}
8428
c19d1205
ZW
8429/* Co-processor data operation:
8430 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8431 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8432static void
8433do_cdp (void)
8434{
8435 inst.instruction |= inst.operands[0].reg << 8;
8436 inst.instruction |= inst.operands[1].imm << 20;
8437 inst.instruction |= inst.operands[2].reg << 12;
8438 inst.instruction |= inst.operands[3].reg << 16;
8439 inst.instruction |= inst.operands[4].reg;
8440 inst.instruction |= inst.operands[5].imm << 5;
8441}
a737bd4d
NC
8442
8443static void
c19d1205 8444do_cmp (void)
a737bd4d 8445{
c19d1205
ZW
8446 inst.instruction |= inst.operands[0].reg << 16;
8447 encode_arm_shifter_operand (1);
a737bd4d
NC
8448}
8449
c19d1205
ZW
8450/* Transfer between coprocessor and ARM registers.
8451 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8452 MRC2
8453 MCR{cond}
8454 MCR2
8455
8456 No special properties. */
09d92015 8457
dcbd0d71
MGD
8458struct deprecated_coproc_regs_s
8459{
8460 unsigned cp;
8461 int opc1;
8462 unsigned crn;
8463 unsigned crm;
8464 int opc2;
8465 arm_feature_set deprecated;
8466 arm_feature_set obsoleted;
8467 const char *dep_msg;
8468 const char *obs_msg;
8469};
8470
8471#define DEPR_ACCESS_V8 \
8472 N_("This coprocessor register access is deprecated in ARMv8")
8473
8474/* Table of all deprecated coprocessor registers. */
8475static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8476{
8477 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8478 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8479 DEPR_ACCESS_V8, NULL},
8480 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8481 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8482 DEPR_ACCESS_V8, NULL},
8483 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8484 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8485 DEPR_ACCESS_V8, NULL},
8486 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8487 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8488 DEPR_ACCESS_V8, NULL},
8489 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8490 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8491 DEPR_ACCESS_V8, NULL},
8492};
8493
8494#undef DEPR_ACCESS_V8
8495
8496static const size_t deprecated_coproc_reg_count =
8497 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8498
09d92015 8499static void
c19d1205 8500do_co_reg (void)
09d92015 8501{
fdfde340 8502 unsigned Rd;
dcbd0d71 8503 size_t i;
fdfde340
JM
8504
8505 Rd = inst.operands[2].reg;
8506 if (thumb_mode)
8507 {
8508 if (inst.instruction == 0xee000010
8509 || inst.instruction == 0xfe000010)
8510 /* MCR, MCR2 */
8511 reject_bad_reg (Rd);
8512 else
8513 /* MRC, MRC2 */
8514 constraint (Rd == REG_SP, BAD_SP);
8515 }
8516 else
8517 {
8518 /* MCR */
8519 if (inst.instruction == 0xe000010)
8520 constraint (Rd == REG_PC, BAD_PC);
8521 }
8522
dcbd0d71
MGD
8523 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8524 {
8525 const struct deprecated_coproc_regs_s *r =
8526 deprecated_coproc_regs + i;
8527
8528 if (inst.operands[0].reg == r->cp
8529 && inst.operands[1].imm == r->opc1
8530 && inst.operands[3].reg == r->crn
8531 && inst.operands[4].reg == r->crm
8532 && inst.operands[5].imm == r->opc2)
8533 {
b10bf8c5 8534 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8535 && warn_on_deprecated
dcbd0d71 8536 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8537 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8538 }
8539 }
fdfde340 8540
c19d1205
ZW
8541 inst.instruction |= inst.operands[0].reg << 8;
8542 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8543 inst.instruction |= Rd << 12;
c19d1205
ZW
8544 inst.instruction |= inst.operands[3].reg << 16;
8545 inst.instruction |= inst.operands[4].reg;
8546 inst.instruction |= inst.operands[5].imm << 5;
8547}
09d92015 8548
c19d1205
ZW
8549/* Transfer between coprocessor register and pair of ARM registers.
8550 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8551 MCRR2
8552 MRRC{cond}
8553 MRRC2
b99bd4ef 8554
c19d1205 8555 Two XScale instructions are special cases of these:
09d92015 8556
c19d1205
ZW
8557 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8558 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8559
5f4273c7 8560 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8561
c19d1205
ZW
8562static void
8563do_co_reg2c (void)
8564{
fdfde340
JM
8565 unsigned Rd, Rn;
8566
8567 Rd = inst.operands[2].reg;
8568 Rn = inst.operands[3].reg;
8569
8570 if (thumb_mode)
8571 {
8572 reject_bad_reg (Rd);
8573 reject_bad_reg (Rn);
8574 }
8575 else
8576 {
8577 constraint (Rd == REG_PC, BAD_PC);
8578 constraint (Rn == REG_PC, BAD_PC);
8579 }
8580
c19d1205
ZW
8581 inst.instruction |= inst.operands[0].reg << 8;
8582 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8583 inst.instruction |= Rd << 12;
8584 inst.instruction |= Rn << 16;
c19d1205 8585 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8586}
8587
c19d1205
ZW
8588static void
8589do_cpsi (void)
8590{
8591 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8592 if (inst.operands[1].present)
8593 {
8594 inst.instruction |= CPSI_MMOD;
8595 inst.instruction |= inst.operands[1].imm;
8596 }
c19d1205 8597}
b99bd4ef 8598
62b3e311
PB
8599static void
8600do_dbg (void)
8601{
8602 inst.instruction |= inst.operands[0].imm;
8603}
8604
eea54501
MGD
8605static void
8606do_div (void)
8607{
8608 unsigned Rd, Rn, Rm;
8609
8610 Rd = inst.operands[0].reg;
8611 Rn = (inst.operands[1].present
8612 ? inst.operands[1].reg : Rd);
8613 Rm = inst.operands[2].reg;
8614
8615 constraint ((Rd == REG_PC), BAD_PC);
8616 constraint ((Rn == REG_PC), BAD_PC);
8617 constraint ((Rm == REG_PC), BAD_PC);
8618
8619 inst.instruction |= Rd << 16;
8620 inst.instruction |= Rn << 0;
8621 inst.instruction |= Rm << 8;
8622}
8623
b99bd4ef 8624static void
c19d1205 8625do_it (void)
b99bd4ef 8626{
c19d1205 8627 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8628 process it to do the validation as if in
8629 thumb mode, just in case the code gets
8630 assembled for thumb using the unified syntax. */
8631
c19d1205 8632 inst.size = 0;
e07e6e58
NC
8633 if (unified_syntax)
8634 {
8635 set_it_insn_type (IT_INSN);
8636 now_it.mask = (inst.instruction & 0xf) | 0x10;
8637 now_it.cc = inst.operands[0].imm;
8638 }
09d92015 8639}
b99bd4ef 8640
6530b175
NC
8641/* If there is only one register in the register list,
8642 then return its register number. Otherwise return -1. */
8643static int
8644only_one_reg_in_list (int range)
8645{
8646 int i = ffs (range) - 1;
8647 return (i > 15 || range != (1 << i)) ? -1 : i;
8648}
8649
09d92015 8650static void
6530b175 8651encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8652{
c19d1205
ZW
8653 int base_reg = inst.operands[0].reg;
8654 int range = inst.operands[1].imm;
6530b175 8655 int one_reg;
ea6ef066 8656
c19d1205
ZW
8657 inst.instruction |= base_reg << 16;
8658 inst.instruction |= range;
ea6ef066 8659
c19d1205
ZW
8660 if (inst.operands[1].writeback)
8661 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8662
c19d1205 8663 if (inst.operands[0].writeback)
ea6ef066 8664 {
c19d1205
ZW
8665 inst.instruction |= WRITE_BACK;
8666 /* Check for unpredictable uses of writeback. */
8667 if (inst.instruction & LOAD_BIT)
09d92015 8668 {
c19d1205
ZW
8669 /* Not allowed in LDM type 2. */
8670 if ((inst.instruction & LDM_TYPE_2_OR_3)
8671 && ((range & (1 << REG_PC)) == 0))
8672 as_warn (_("writeback of base register is UNPREDICTABLE"));
8673 /* Only allowed if base reg not in list for other types. */
8674 else if (range & (1 << base_reg))
8675 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8676 }
8677 else /* STM. */
8678 {
8679 /* Not allowed for type 2. */
8680 if (inst.instruction & LDM_TYPE_2_OR_3)
8681 as_warn (_("writeback of base register is UNPREDICTABLE"));
8682 /* Only allowed if base reg not in list, or first in list. */
8683 else if ((range & (1 << base_reg))
8684 && (range & ((1 << base_reg) - 1)))
8685 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8686 }
ea6ef066 8687 }
6530b175
NC
8688
8689 /* If PUSH/POP has only one register, then use the A2 encoding. */
8690 one_reg = only_one_reg_in_list (range);
8691 if (from_push_pop_mnem && one_reg >= 0)
8692 {
8693 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8694
8695 inst.instruction &= A_COND_MASK;
8696 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8697 inst.instruction |= one_reg << 12;
8698 }
8699}
8700
8701static void
8702do_ldmstm (void)
8703{
8704 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8705}
8706
c19d1205
ZW
8707/* ARMv5TE load-consecutive (argument parse)
8708 Mode is like LDRH.
8709
8710 LDRccD R, mode
8711 STRccD R, mode. */
8712
a737bd4d 8713static void
c19d1205 8714do_ldrd (void)
a737bd4d 8715{
c19d1205 8716 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8717 _("first transfer register must be even"));
c19d1205
ZW
8718 constraint (inst.operands[1].present
8719 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8720 _("can only transfer two consecutive registers"));
c19d1205
ZW
8721 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8722 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8723
c19d1205
ZW
8724 if (!inst.operands[1].present)
8725 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8726
c56791bb
RE
8727 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8728 register and the first register written; we have to diagnose
8729 overlap between the base and the second register written here. */
ea6ef066 8730
c56791bb
RE
8731 if (inst.operands[2].reg == inst.operands[1].reg
8732 && (inst.operands[2].writeback || inst.operands[2].postind))
8733 as_warn (_("base register written back, and overlaps "
8734 "second transfer register"));
b05fe5cf 8735
c56791bb
RE
8736 if (!(inst.instruction & V4_STR_BIT))
8737 {
c19d1205 8738 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8739 destination (even if not write-back). */
8740 if (inst.operands[2].immisreg
8741 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8742 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8743 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8744 }
c19d1205
ZW
8745 inst.instruction |= inst.operands[0].reg << 12;
8746 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8747}
8748
8749static void
c19d1205 8750do_ldrex (void)
b05fe5cf 8751{
c19d1205
ZW
8752 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8753 || inst.operands[1].postind || inst.operands[1].writeback
8754 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8755 || inst.operands[1].negative
8756 /* This can arise if the programmer has written
8757 strex rN, rM, foo
8758 or if they have mistakenly used a register name as the last
8759 operand, eg:
8760 strex rN, rM, rX
8761 It is very difficult to distinguish between these two cases
8762 because "rX" might actually be a label. ie the register
8763 name has been occluded by a symbol of the same name. So we
8764 just generate a general 'bad addressing mode' type error
8765 message and leave it up to the programmer to discover the
8766 true cause and fix their mistake. */
8767 || (inst.operands[1].reg == REG_PC),
8768 BAD_ADDR_MODE);
b05fe5cf 8769
c19d1205
ZW
8770 constraint (inst.reloc.exp.X_op != O_constant
8771 || inst.reloc.exp.X_add_number != 0,
8772 _("offset must be zero in ARM encoding"));
b05fe5cf 8773
5be8be5d
DG
8774 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8775
c19d1205
ZW
8776 inst.instruction |= inst.operands[0].reg << 12;
8777 inst.instruction |= inst.operands[1].reg << 16;
8778 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8779}
8780
8781static void
c19d1205 8782do_ldrexd (void)
b05fe5cf 8783{
c19d1205
ZW
8784 constraint (inst.operands[0].reg % 2 != 0,
8785 _("even register required"));
8786 constraint (inst.operands[1].present
8787 && inst.operands[1].reg != inst.operands[0].reg + 1,
8788 _("can only load two consecutive registers"));
8789 /* If op 1 were present and equal to PC, this function wouldn't
8790 have been called in the first place. */
8791 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8792
c19d1205
ZW
8793 inst.instruction |= inst.operands[0].reg << 12;
8794 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8795}
8796
1be5fd2e
NC
8797/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8798 which is not a multiple of four is UNPREDICTABLE. */
8799static void
8800check_ldr_r15_aligned (void)
8801{
8802 constraint (!(inst.operands[1].immisreg)
8803 && (inst.operands[0].reg == REG_PC
8804 && inst.operands[1].reg == REG_PC
8805 && (inst.reloc.exp.X_add_number & 0x3)),
8806 _("ldr to register 15 must be 4-byte alligned"));
8807}
8808
b05fe5cf 8809static void
c19d1205 8810do_ldst (void)
b05fe5cf 8811{
c19d1205
ZW
8812 inst.instruction |= inst.operands[0].reg << 12;
8813 if (!inst.operands[1].isreg)
8335d6aa 8814 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8815 return;
c19d1205 8816 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8817 check_ldr_r15_aligned ();
b05fe5cf
ZW
8818}
8819
8820static void
c19d1205 8821do_ldstt (void)
b05fe5cf 8822{
c19d1205
ZW
8823 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8824 reject [Rn,...]. */
8825 if (inst.operands[1].preind)
b05fe5cf 8826 {
bd3ba5d1
NC
8827 constraint (inst.reloc.exp.X_op != O_constant
8828 || inst.reloc.exp.X_add_number != 0,
c19d1205 8829 _("this instruction requires a post-indexed address"));
b05fe5cf 8830
c19d1205
ZW
8831 inst.operands[1].preind = 0;
8832 inst.operands[1].postind = 1;
8833 inst.operands[1].writeback = 1;
b05fe5cf 8834 }
c19d1205
ZW
8835 inst.instruction |= inst.operands[0].reg << 12;
8836 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8837}
b05fe5cf 8838
c19d1205 8839/* Halfword and signed-byte load/store operations. */
b05fe5cf 8840
c19d1205
ZW
8841static void
8842do_ldstv4 (void)
8843{
ff4a8d2b 8844 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8845 inst.instruction |= inst.operands[0].reg << 12;
8846 if (!inst.operands[1].isreg)
8335d6aa 8847 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8848 return;
c19d1205 8849 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8850}
8851
8852static void
c19d1205 8853do_ldsttv4 (void)
b05fe5cf 8854{
c19d1205
ZW
8855 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8856 reject [Rn,...]. */
8857 if (inst.operands[1].preind)
b05fe5cf 8858 {
bd3ba5d1
NC
8859 constraint (inst.reloc.exp.X_op != O_constant
8860 || inst.reloc.exp.X_add_number != 0,
c19d1205 8861 _("this instruction requires a post-indexed address"));
b05fe5cf 8862
c19d1205
ZW
8863 inst.operands[1].preind = 0;
8864 inst.operands[1].postind = 1;
8865 inst.operands[1].writeback = 1;
b05fe5cf 8866 }
c19d1205
ZW
8867 inst.instruction |= inst.operands[0].reg << 12;
8868 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8869}
b05fe5cf 8870
c19d1205
ZW
8871/* Co-processor register load/store.
8872 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8873static void
8874do_lstc (void)
8875{
8876 inst.instruction |= inst.operands[0].reg << 8;
8877 inst.instruction |= inst.operands[1].reg << 12;
8878 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8879}
8880
b05fe5cf 8881static void
c19d1205 8882do_mlas (void)
b05fe5cf 8883{
8fb9d7b9 8884 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8885 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8886 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8887 && !(inst.instruction & 0x00400000))
8fb9d7b9 8888 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8889
c19d1205
ZW
8890 inst.instruction |= inst.operands[0].reg << 16;
8891 inst.instruction |= inst.operands[1].reg;
8892 inst.instruction |= inst.operands[2].reg << 8;
8893 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8894}
b05fe5cf 8895
c19d1205
ZW
8896static void
8897do_mov (void)
8898{
8899 inst.instruction |= inst.operands[0].reg << 12;
8900 encode_arm_shifter_operand (1);
8901}
b05fe5cf 8902
c19d1205
ZW
8903/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8904static void
8905do_mov16 (void)
8906{
b6895b4f
PB
8907 bfd_vma imm;
8908 bfd_boolean top;
8909
8910 top = (inst.instruction & 0x00400000) != 0;
8911 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8912 _(":lower16: not allowed this instruction"));
8913 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8914 _(":upper16: not allowed instruction"));
c19d1205 8915 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8916 if (inst.reloc.type == BFD_RELOC_UNUSED)
8917 {
8918 imm = inst.reloc.exp.X_add_number;
8919 /* The value is in two pieces: 0:11, 16:19. */
8920 inst.instruction |= (imm & 0x00000fff);
8921 inst.instruction |= (imm & 0x0000f000) << 4;
8922 }
b05fe5cf 8923}
b99bd4ef 8924
037e8744
JB
8925static int
8926do_vfp_nsyn_mrs (void)
8927{
8928 if (inst.operands[0].isvec)
8929 {
8930 if (inst.operands[1].reg != 1)
477330fc 8931 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
8932 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8933 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8934 do_vfp_nsyn_opcode ("fmstat");
8935 }
8936 else if (inst.operands[1].isvec)
8937 do_vfp_nsyn_opcode ("fmrx");
8938 else
8939 return FAIL;
5f4273c7 8940
037e8744
JB
8941 return SUCCESS;
8942}
8943
8944static int
8945do_vfp_nsyn_msr (void)
8946{
8947 if (inst.operands[0].isvec)
8948 do_vfp_nsyn_opcode ("fmxr");
8949 else
8950 return FAIL;
8951
8952 return SUCCESS;
8953}
8954
f7c21dc7
NC
8955static void
8956do_vmrs (void)
8957{
8958 unsigned Rt = inst.operands[0].reg;
fa94de6b 8959
16d02dc9 8960 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
8961 {
8962 inst.error = BAD_SP;
8963 return;
8964 }
8965
8966 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 8967 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
8968 {
8969 inst.error = BAD_PC;
8970 return;
8971 }
8972
16d02dc9
JB
8973 /* If we get through parsing the register name, we just insert the number
8974 generated into the instruction without further validation. */
8975 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
8976 inst.instruction |= (Rt << 12);
8977}
8978
8979static void
8980do_vmsr (void)
8981{
8982 unsigned Rt = inst.operands[1].reg;
fa94de6b 8983
f7c21dc7
NC
8984 if (thumb_mode)
8985 reject_bad_reg (Rt);
8986 else if (Rt == REG_PC)
8987 {
8988 inst.error = BAD_PC;
8989 return;
8990 }
8991
16d02dc9
JB
8992 /* If we get through parsing the register name, we just insert the number
8993 generated into the instruction without further validation. */
8994 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
8995 inst.instruction |= (Rt << 12);
8996}
8997
b99bd4ef 8998static void
c19d1205 8999do_mrs (void)
b99bd4ef 9000{
90ec0d68
MGD
9001 unsigned br;
9002
037e8744
JB
9003 if (do_vfp_nsyn_mrs () == SUCCESS)
9004 return;
9005
ff4a8d2b 9006 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9007 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9008
9009 if (inst.operands[1].isreg)
9010 {
9011 br = inst.operands[1].reg;
9012 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9013 as_bad (_("bad register for mrs"));
9014 }
9015 else
9016 {
9017 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9018 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9019 != (PSR_c|PSR_f),
d2cd1205 9020 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9021 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9022 }
9023
9024 inst.instruction |= br;
c19d1205 9025}
b99bd4ef 9026
c19d1205
ZW
9027/* Two possible forms:
9028 "{C|S}PSR_<field>, Rm",
9029 "{C|S}PSR_f, #expression". */
b99bd4ef 9030
c19d1205
ZW
9031static void
9032do_msr (void)
9033{
037e8744
JB
9034 if (do_vfp_nsyn_msr () == SUCCESS)
9035 return;
9036
c19d1205
ZW
9037 inst.instruction |= inst.operands[0].imm;
9038 if (inst.operands[1].isreg)
9039 inst.instruction |= inst.operands[1].reg;
9040 else
b99bd4ef 9041 {
c19d1205
ZW
9042 inst.instruction |= INST_IMMEDIATE;
9043 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9044 inst.reloc.pc_rel = 0;
b99bd4ef 9045 }
b99bd4ef
NC
9046}
9047
c19d1205
ZW
9048static void
9049do_mul (void)
a737bd4d 9050{
ff4a8d2b
NC
9051 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9052
c19d1205
ZW
9053 if (!inst.operands[2].present)
9054 inst.operands[2].reg = inst.operands[0].reg;
9055 inst.instruction |= inst.operands[0].reg << 16;
9056 inst.instruction |= inst.operands[1].reg;
9057 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9058
8fb9d7b9
MS
9059 if (inst.operands[0].reg == inst.operands[1].reg
9060 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9061 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9062}
9063
c19d1205
ZW
9064/* Long Multiply Parser
9065 UMULL RdLo, RdHi, Rm, Rs
9066 SMULL RdLo, RdHi, Rm, Rs
9067 UMLAL RdLo, RdHi, Rm, Rs
9068 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9069
9070static void
c19d1205 9071do_mull (void)
b99bd4ef 9072{
c19d1205
ZW
9073 inst.instruction |= inst.operands[0].reg << 12;
9074 inst.instruction |= inst.operands[1].reg << 16;
9075 inst.instruction |= inst.operands[2].reg;
9076 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9077
682b27ad
PB
9078 /* rdhi and rdlo must be different. */
9079 if (inst.operands[0].reg == inst.operands[1].reg)
9080 as_tsktsk (_("rdhi and rdlo must be different"));
9081
9082 /* rdhi, rdlo and rm must all be different before armv6. */
9083 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9084 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9085 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9086 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9087}
b99bd4ef 9088
c19d1205
ZW
9089static void
9090do_nop (void)
9091{
e7495e45
NS
9092 if (inst.operands[0].present
9093 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9094 {
9095 /* Architectural NOP hints are CPSR sets with no bits selected. */
9096 inst.instruction &= 0xf0000000;
e7495e45
NS
9097 inst.instruction |= 0x0320f000;
9098 if (inst.operands[0].present)
9099 inst.instruction |= inst.operands[0].imm;
c19d1205 9100 }
b99bd4ef
NC
9101}
9102
c19d1205
ZW
9103/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9104 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9105 Condition defaults to COND_ALWAYS.
9106 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9107
9108static void
c19d1205 9109do_pkhbt (void)
b99bd4ef 9110{
c19d1205
ZW
9111 inst.instruction |= inst.operands[0].reg << 12;
9112 inst.instruction |= inst.operands[1].reg << 16;
9113 inst.instruction |= inst.operands[2].reg;
9114 if (inst.operands[3].present)
9115 encode_arm_shift (3);
9116}
b99bd4ef 9117
c19d1205 9118/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9119
c19d1205
ZW
9120static void
9121do_pkhtb (void)
9122{
9123 if (!inst.operands[3].present)
b99bd4ef 9124 {
c19d1205
ZW
9125 /* If the shift specifier is omitted, turn the instruction
9126 into pkhbt rd, rm, rn. */
9127 inst.instruction &= 0xfff00010;
9128 inst.instruction |= inst.operands[0].reg << 12;
9129 inst.instruction |= inst.operands[1].reg;
9130 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9131 }
9132 else
9133 {
c19d1205
ZW
9134 inst.instruction |= inst.operands[0].reg << 12;
9135 inst.instruction |= inst.operands[1].reg << 16;
9136 inst.instruction |= inst.operands[2].reg;
9137 encode_arm_shift (3);
b99bd4ef
NC
9138 }
9139}
9140
c19d1205 9141/* ARMv5TE: Preload-Cache
60e5ef9f 9142 MP Extensions: Preload for write
c19d1205 9143
60e5ef9f 9144 PLD(W) <addr_mode>
c19d1205
ZW
9145
9146 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9147
9148static void
c19d1205 9149do_pld (void)
b99bd4ef 9150{
c19d1205
ZW
9151 constraint (!inst.operands[0].isreg,
9152 _("'[' expected after PLD mnemonic"));
9153 constraint (inst.operands[0].postind,
9154 _("post-indexed expression used in preload instruction"));
9155 constraint (inst.operands[0].writeback,
9156 _("writeback used in preload instruction"));
9157 constraint (!inst.operands[0].preind,
9158 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9159 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9160}
b99bd4ef 9161
62b3e311
PB
9162/* ARMv7: PLI <addr_mode> */
9163static void
9164do_pli (void)
9165{
9166 constraint (!inst.operands[0].isreg,
9167 _("'[' expected after PLI mnemonic"));
9168 constraint (inst.operands[0].postind,
9169 _("post-indexed expression used in preload instruction"));
9170 constraint (inst.operands[0].writeback,
9171 _("writeback used in preload instruction"));
9172 constraint (!inst.operands[0].preind,
9173 _("unindexed addressing used in preload instruction"));
9174 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9175 inst.instruction &= ~PRE_INDEX;
9176}
9177
c19d1205
ZW
9178static void
9179do_push_pop (void)
9180{
5e0d7f77
MP
9181 constraint (inst.operands[0].writeback,
9182 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9183 inst.operands[1] = inst.operands[0];
9184 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9185 inst.operands[0].isreg = 1;
9186 inst.operands[0].writeback = 1;
9187 inst.operands[0].reg = REG_SP;
6530b175 9188 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9189}
b99bd4ef 9190
c19d1205
ZW
9191/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9192 word at the specified address and the following word
9193 respectively.
9194 Unconditionally executed.
9195 Error if Rn is R15. */
b99bd4ef 9196
c19d1205
ZW
9197static void
9198do_rfe (void)
9199{
9200 inst.instruction |= inst.operands[0].reg << 16;
9201 if (inst.operands[0].writeback)
9202 inst.instruction |= WRITE_BACK;
9203}
b99bd4ef 9204
c19d1205 9205/* ARM V6 ssat (argument parse). */
b99bd4ef 9206
c19d1205
ZW
9207static void
9208do_ssat (void)
9209{
9210 inst.instruction |= inst.operands[0].reg << 12;
9211 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9212 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9213
c19d1205
ZW
9214 if (inst.operands[3].present)
9215 encode_arm_shift (3);
b99bd4ef
NC
9216}
9217
c19d1205 9218/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9219
9220static void
c19d1205 9221do_usat (void)
b99bd4ef 9222{
c19d1205
ZW
9223 inst.instruction |= inst.operands[0].reg << 12;
9224 inst.instruction |= inst.operands[1].imm << 16;
9225 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9226
c19d1205
ZW
9227 if (inst.operands[3].present)
9228 encode_arm_shift (3);
b99bd4ef
NC
9229}
9230
c19d1205 9231/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9232
9233static void
c19d1205 9234do_ssat16 (void)
09d92015 9235{
c19d1205
ZW
9236 inst.instruction |= inst.operands[0].reg << 12;
9237 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9238 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9239}
9240
c19d1205
ZW
9241static void
9242do_usat16 (void)
a737bd4d 9243{
c19d1205
ZW
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[1].imm << 16;
9246 inst.instruction |= inst.operands[2].reg;
9247}
a737bd4d 9248
c19d1205
ZW
9249/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9250 preserving the other bits.
a737bd4d 9251
c19d1205
ZW
9252 setend <endian_specifier>, where <endian_specifier> is either
9253 BE or LE. */
a737bd4d 9254
c19d1205
ZW
9255static void
9256do_setend (void)
9257{
12e37cbc
MGD
9258 if (warn_on_deprecated
9259 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9260 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9261
c19d1205
ZW
9262 if (inst.operands[0].imm)
9263 inst.instruction |= 0x200;
a737bd4d
NC
9264}
9265
9266static void
c19d1205 9267do_shift (void)
a737bd4d 9268{
c19d1205
ZW
9269 unsigned int Rm = (inst.operands[1].present
9270 ? inst.operands[1].reg
9271 : inst.operands[0].reg);
a737bd4d 9272
c19d1205
ZW
9273 inst.instruction |= inst.operands[0].reg << 12;
9274 inst.instruction |= Rm;
9275 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9276 {
c19d1205
ZW
9277 inst.instruction |= inst.operands[2].reg << 8;
9278 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9279 /* PR 12854: Error on extraneous shifts. */
9280 constraint (inst.operands[2].shifted,
9281 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9282 }
9283 else
c19d1205 9284 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9285}
9286
09d92015 9287static void
3eb17e6b 9288do_smc (void)
09d92015 9289{
3eb17e6b 9290 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9291 inst.reloc.pc_rel = 0;
09d92015
MM
9292}
9293
90ec0d68
MGD
9294static void
9295do_hvc (void)
9296{
9297 inst.reloc.type = BFD_RELOC_ARM_HVC;
9298 inst.reloc.pc_rel = 0;
9299}
9300
09d92015 9301static void
c19d1205 9302do_swi (void)
09d92015 9303{
c19d1205
ZW
9304 inst.reloc.type = BFD_RELOC_ARM_SWI;
9305 inst.reloc.pc_rel = 0;
09d92015
MM
9306}
9307
ddfded2f
MW
9308static void
9309do_setpan (void)
9310{
9311 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9312 _("selected processor does not support SETPAN instruction"));
9313
9314 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9315}
9316
9317static void
9318do_t_setpan (void)
9319{
9320 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9321 _("selected processor does not support SETPAN instruction"));
9322
9323 inst.instruction |= (inst.operands[0].imm << 3);
9324}
9325
c19d1205
ZW
9326/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9327 SMLAxy{cond} Rd,Rm,Rs,Rn
9328 SMLAWy{cond} Rd,Rm,Rs,Rn
9329 Error if any register is R15. */
e16bb312 9330
c19d1205
ZW
9331static void
9332do_smla (void)
e16bb312 9333{
c19d1205
ZW
9334 inst.instruction |= inst.operands[0].reg << 16;
9335 inst.instruction |= inst.operands[1].reg;
9336 inst.instruction |= inst.operands[2].reg << 8;
9337 inst.instruction |= inst.operands[3].reg << 12;
9338}
a737bd4d 9339
c19d1205
ZW
9340/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9341 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9342 Error if any register is R15.
9343 Warning if Rdlo == Rdhi. */
a737bd4d 9344
c19d1205
ZW
9345static void
9346do_smlal (void)
9347{
9348 inst.instruction |= inst.operands[0].reg << 12;
9349 inst.instruction |= inst.operands[1].reg << 16;
9350 inst.instruction |= inst.operands[2].reg;
9351 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9352
c19d1205
ZW
9353 if (inst.operands[0].reg == inst.operands[1].reg)
9354 as_tsktsk (_("rdhi and rdlo must be different"));
9355}
a737bd4d 9356
c19d1205
ZW
9357/* ARM V5E (El Segundo) signed-multiply (argument parse)
9358 SMULxy{cond} Rd,Rm,Rs
9359 Error if any register is R15. */
a737bd4d 9360
c19d1205
ZW
9361static void
9362do_smul (void)
9363{
9364 inst.instruction |= inst.operands[0].reg << 16;
9365 inst.instruction |= inst.operands[1].reg;
9366 inst.instruction |= inst.operands[2].reg << 8;
9367}
a737bd4d 9368
b6702015
PB
9369/* ARM V6 srs (argument parse). The variable fields in the encoding are
9370 the same for both ARM and Thumb-2. */
a737bd4d 9371
c19d1205
ZW
9372static void
9373do_srs (void)
9374{
b6702015
PB
9375 int reg;
9376
9377 if (inst.operands[0].present)
9378 {
9379 reg = inst.operands[0].reg;
fdfde340 9380 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9381 }
9382 else
fdfde340 9383 reg = REG_SP;
b6702015
PB
9384
9385 inst.instruction |= reg << 16;
9386 inst.instruction |= inst.operands[1].imm;
9387 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9388 inst.instruction |= WRITE_BACK;
9389}
a737bd4d 9390
c19d1205 9391/* ARM V6 strex (argument parse). */
a737bd4d 9392
c19d1205
ZW
9393static void
9394do_strex (void)
9395{
9396 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9397 || inst.operands[2].postind || inst.operands[2].writeback
9398 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9399 || inst.operands[2].negative
9400 /* See comment in do_ldrex(). */
9401 || (inst.operands[2].reg == REG_PC),
9402 BAD_ADDR_MODE);
a737bd4d 9403
c19d1205
ZW
9404 constraint (inst.operands[0].reg == inst.operands[1].reg
9405 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9406
c19d1205
ZW
9407 constraint (inst.reloc.exp.X_op != O_constant
9408 || inst.reloc.exp.X_add_number != 0,
9409 _("offset must be zero in ARM encoding"));
a737bd4d 9410
c19d1205
ZW
9411 inst.instruction |= inst.operands[0].reg << 12;
9412 inst.instruction |= inst.operands[1].reg;
9413 inst.instruction |= inst.operands[2].reg << 16;
9414 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9415}
9416
877807f8
NC
9417static void
9418do_t_strexbh (void)
9419{
9420 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9421 || inst.operands[2].postind || inst.operands[2].writeback
9422 || inst.operands[2].immisreg || inst.operands[2].shifted
9423 || inst.operands[2].negative,
9424 BAD_ADDR_MODE);
9425
9426 constraint (inst.operands[0].reg == inst.operands[1].reg
9427 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9428
9429 do_rm_rd_rn ();
9430}
9431
e16bb312 9432static void
c19d1205 9433do_strexd (void)
e16bb312 9434{
c19d1205
ZW
9435 constraint (inst.operands[1].reg % 2 != 0,
9436 _("even register required"));
9437 constraint (inst.operands[2].present
9438 && inst.operands[2].reg != inst.operands[1].reg + 1,
9439 _("can only store two consecutive registers"));
9440 /* If op 2 were present and equal to PC, this function wouldn't
9441 have been called in the first place. */
9442 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9443
c19d1205
ZW
9444 constraint (inst.operands[0].reg == inst.operands[1].reg
9445 || inst.operands[0].reg == inst.operands[1].reg + 1
9446 || inst.operands[0].reg == inst.operands[3].reg,
9447 BAD_OVERLAP);
e16bb312 9448
c19d1205
ZW
9449 inst.instruction |= inst.operands[0].reg << 12;
9450 inst.instruction |= inst.operands[1].reg;
9451 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9452}
9453
9eb6c0f1
MGD
9454/* ARM V8 STRL. */
9455static void
4b8c8c02 9456do_stlex (void)
9eb6c0f1
MGD
9457{
9458 constraint (inst.operands[0].reg == inst.operands[1].reg
9459 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9460
9461 do_rd_rm_rn ();
9462}
9463
9464static void
4b8c8c02 9465do_t_stlex (void)
9eb6c0f1
MGD
9466{
9467 constraint (inst.operands[0].reg == inst.operands[1].reg
9468 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9469
9470 do_rm_rd_rn ();
9471}
9472
c19d1205
ZW
9473/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9474 extends it to 32-bits, and adds the result to a value in another
9475 register. You can specify a rotation by 0, 8, 16, or 24 bits
9476 before extracting the 16-bit value.
9477 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9478 Condition defaults to COND_ALWAYS.
9479 Error if any register uses R15. */
9480
e16bb312 9481static void
c19d1205 9482do_sxtah (void)
e16bb312 9483{
c19d1205
ZW
9484 inst.instruction |= inst.operands[0].reg << 12;
9485 inst.instruction |= inst.operands[1].reg << 16;
9486 inst.instruction |= inst.operands[2].reg;
9487 inst.instruction |= inst.operands[3].imm << 10;
9488}
e16bb312 9489
c19d1205 9490/* ARM V6 SXTH.
e16bb312 9491
c19d1205
ZW
9492 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9493 Condition defaults to COND_ALWAYS.
9494 Error if any register uses R15. */
e16bb312
NC
9495
9496static void
c19d1205 9497do_sxth (void)
e16bb312 9498{
c19d1205
ZW
9499 inst.instruction |= inst.operands[0].reg << 12;
9500 inst.instruction |= inst.operands[1].reg;
9501 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9502}
c19d1205
ZW
9503\f
9504/* VFP instructions. In a logical order: SP variant first, monad
9505 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9506
9507static void
c19d1205 9508do_vfp_sp_monadic (void)
e16bb312 9509{
5287ad62
JB
9510 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9511 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9512}
9513
9514static void
c19d1205 9515do_vfp_sp_dyadic (void)
e16bb312 9516{
5287ad62
JB
9517 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9518 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9519 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9520}
9521
9522static void
c19d1205 9523do_vfp_sp_compare_z (void)
e16bb312 9524{
5287ad62 9525 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9526}
9527
9528static void
c19d1205 9529do_vfp_dp_sp_cvt (void)
e16bb312 9530{
5287ad62
JB
9531 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9532 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9533}
9534
9535static void
c19d1205 9536do_vfp_sp_dp_cvt (void)
e16bb312 9537{
5287ad62
JB
9538 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9539 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9540}
9541
9542static void
c19d1205 9543do_vfp_reg_from_sp (void)
e16bb312 9544{
c19d1205 9545 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9546 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9547}
9548
9549static void
c19d1205 9550do_vfp_reg2_from_sp2 (void)
e16bb312 9551{
c19d1205
ZW
9552 constraint (inst.operands[2].imm != 2,
9553 _("only two consecutive VFP SP registers allowed here"));
9554 inst.instruction |= inst.operands[0].reg << 12;
9555 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9556 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9557}
9558
9559static void
c19d1205 9560do_vfp_sp_from_reg (void)
e16bb312 9561{
5287ad62 9562 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9563 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9564}
9565
9566static void
c19d1205 9567do_vfp_sp2_from_reg2 (void)
e16bb312 9568{
c19d1205
ZW
9569 constraint (inst.operands[0].imm != 2,
9570 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9571 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9572 inst.instruction |= inst.operands[1].reg << 12;
9573 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9574}
9575
9576static void
c19d1205 9577do_vfp_sp_ldst (void)
e16bb312 9578{
5287ad62 9579 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9580 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9581}
9582
9583static void
c19d1205 9584do_vfp_dp_ldst (void)
e16bb312 9585{
5287ad62 9586 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9587 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9588}
9589
c19d1205 9590
e16bb312 9591static void
c19d1205 9592vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9593{
c19d1205
ZW
9594 if (inst.operands[0].writeback)
9595 inst.instruction |= WRITE_BACK;
9596 else
9597 constraint (ldstm_type != VFP_LDSTMIA,
9598 _("this addressing mode requires base-register writeback"));
9599 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9600 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9601 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9602}
9603
9604static void
c19d1205 9605vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9606{
c19d1205 9607 int count;
e16bb312 9608
c19d1205
ZW
9609 if (inst.operands[0].writeback)
9610 inst.instruction |= WRITE_BACK;
9611 else
9612 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9613 _("this addressing mode requires base-register writeback"));
e16bb312 9614
c19d1205 9615 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9616 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9617
c19d1205
ZW
9618 count = inst.operands[1].imm << 1;
9619 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9620 count += 1;
e16bb312 9621
c19d1205 9622 inst.instruction |= count;
e16bb312
NC
9623}
9624
9625static void
c19d1205 9626do_vfp_sp_ldstmia (void)
e16bb312 9627{
c19d1205 9628 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9629}
9630
9631static void
c19d1205 9632do_vfp_sp_ldstmdb (void)
e16bb312 9633{
c19d1205 9634 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9635}
9636
9637static void
c19d1205 9638do_vfp_dp_ldstmia (void)
e16bb312 9639{
c19d1205 9640 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9641}
9642
9643static void
c19d1205 9644do_vfp_dp_ldstmdb (void)
e16bb312 9645{
c19d1205 9646 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9647}
9648
9649static void
c19d1205 9650do_vfp_xp_ldstmia (void)
e16bb312 9651{
c19d1205
ZW
9652 vfp_dp_ldstm (VFP_LDSTMIAX);
9653}
e16bb312 9654
c19d1205
ZW
9655static void
9656do_vfp_xp_ldstmdb (void)
9657{
9658 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9659}
5287ad62
JB
9660
9661static void
9662do_vfp_dp_rd_rm (void)
9663{
9664 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9665 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9666}
9667
9668static void
9669do_vfp_dp_rn_rd (void)
9670{
9671 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9672 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9673}
9674
9675static void
9676do_vfp_dp_rd_rn (void)
9677{
9678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9679 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9680}
9681
9682static void
9683do_vfp_dp_rd_rn_rm (void)
9684{
9685 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9686 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9687 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9688}
9689
9690static void
9691do_vfp_dp_rd (void)
9692{
9693 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9694}
9695
9696static void
9697do_vfp_dp_rm_rd_rn (void)
9698{
9699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9701 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9702}
9703
9704/* VFPv3 instructions. */
9705static void
9706do_vfp_sp_const (void)
9707{
9708 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9709 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9710 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9711}
9712
9713static void
9714do_vfp_dp_const (void)
9715{
9716 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9717 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9718 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9719}
9720
9721static void
9722vfp_conv (int srcsize)
9723{
5f1af56b
MGD
9724 int immbits = srcsize - inst.operands[1].imm;
9725
fa94de6b
RM
9726 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9727 {
5f1af56b 9728 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9729 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9730 inst.error = _("immediate value out of range, expected range [0, 16]");
9731 return;
9732 }
fa94de6b 9733 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9734 {
9735 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9736 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9737 inst.error = _("immediate value out of range, expected range [1, 32]");
9738 return;
9739 }
9740
5287ad62
JB
9741 inst.instruction |= (immbits & 1) << 5;
9742 inst.instruction |= (immbits >> 1);
9743}
9744
9745static void
9746do_vfp_sp_conv_16 (void)
9747{
9748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9749 vfp_conv (16);
9750}
9751
9752static void
9753do_vfp_dp_conv_16 (void)
9754{
9755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9756 vfp_conv (16);
9757}
9758
9759static void
9760do_vfp_sp_conv_32 (void)
9761{
9762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9763 vfp_conv (32);
9764}
9765
9766static void
9767do_vfp_dp_conv_32 (void)
9768{
9769 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9770 vfp_conv (32);
9771}
c19d1205
ZW
9772\f
9773/* FPA instructions. Also in a logical order. */
e16bb312 9774
c19d1205
ZW
9775static void
9776do_fpa_cmp (void)
9777{
9778 inst.instruction |= inst.operands[0].reg << 16;
9779 inst.instruction |= inst.operands[1].reg;
9780}
b99bd4ef
NC
9781
9782static void
c19d1205 9783do_fpa_ldmstm (void)
b99bd4ef 9784{
c19d1205
ZW
9785 inst.instruction |= inst.operands[0].reg << 12;
9786 switch (inst.operands[1].imm)
9787 {
9788 case 1: inst.instruction |= CP_T_X; break;
9789 case 2: inst.instruction |= CP_T_Y; break;
9790 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9791 case 4: break;
9792 default: abort ();
9793 }
b99bd4ef 9794
c19d1205
ZW
9795 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9796 {
9797 /* The instruction specified "ea" or "fd", so we can only accept
9798 [Rn]{!}. The instruction does not really support stacking or
9799 unstacking, so we have to emulate these by setting appropriate
9800 bits and offsets. */
9801 constraint (inst.reloc.exp.X_op != O_constant
9802 || inst.reloc.exp.X_add_number != 0,
9803 _("this instruction does not support indexing"));
b99bd4ef 9804
c19d1205
ZW
9805 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9806 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9807
c19d1205
ZW
9808 if (!(inst.instruction & INDEX_UP))
9809 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9810
c19d1205
ZW
9811 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9812 {
9813 inst.operands[2].preind = 0;
9814 inst.operands[2].postind = 1;
9815 }
9816 }
b99bd4ef 9817
c19d1205 9818 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9819}
c19d1205
ZW
9820\f
9821/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9822
c19d1205
ZW
9823static void
9824do_iwmmxt_tandorc (void)
9825{
9826 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9827}
b99bd4ef 9828
c19d1205
ZW
9829static void
9830do_iwmmxt_textrc (void)
9831{
9832 inst.instruction |= inst.operands[0].reg << 12;
9833 inst.instruction |= inst.operands[1].imm;
9834}
b99bd4ef
NC
9835
9836static void
c19d1205 9837do_iwmmxt_textrm (void)
b99bd4ef 9838{
c19d1205
ZW
9839 inst.instruction |= inst.operands[0].reg << 12;
9840 inst.instruction |= inst.operands[1].reg << 16;
9841 inst.instruction |= inst.operands[2].imm;
9842}
b99bd4ef 9843
c19d1205
ZW
9844static void
9845do_iwmmxt_tinsr (void)
9846{
9847 inst.instruction |= inst.operands[0].reg << 16;
9848 inst.instruction |= inst.operands[1].reg << 12;
9849 inst.instruction |= inst.operands[2].imm;
9850}
b99bd4ef 9851
c19d1205
ZW
9852static void
9853do_iwmmxt_tmia (void)
9854{
9855 inst.instruction |= inst.operands[0].reg << 5;
9856 inst.instruction |= inst.operands[1].reg;
9857 inst.instruction |= inst.operands[2].reg << 12;
9858}
b99bd4ef 9859
c19d1205
ZW
9860static void
9861do_iwmmxt_waligni (void)
9862{
9863 inst.instruction |= inst.operands[0].reg << 12;
9864 inst.instruction |= inst.operands[1].reg << 16;
9865 inst.instruction |= inst.operands[2].reg;
9866 inst.instruction |= inst.operands[3].imm << 20;
9867}
b99bd4ef 9868
2d447fca
JM
9869static void
9870do_iwmmxt_wmerge (void)
9871{
9872 inst.instruction |= inst.operands[0].reg << 12;
9873 inst.instruction |= inst.operands[1].reg << 16;
9874 inst.instruction |= inst.operands[2].reg;
9875 inst.instruction |= inst.operands[3].imm << 21;
9876}
9877
c19d1205
ZW
9878static void
9879do_iwmmxt_wmov (void)
9880{
9881 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9882 inst.instruction |= inst.operands[0].reg << 12;
9883 inst.instruction |= inst.operands[1].reg << 16;
9884 inst.instruction |= inst.operands[1].reg;
9885}
b99bd4ef 9886
c19d1205
ZW
9887static void
9888do_iwmmxt_wldstbh (void)
9889{
8f06b2d8 9890 int reloc;
c19d1205 9891 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9892 if (thumb_mode)
9893 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9894 else
9895 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9896 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9897}
9898
c19d1205
ZW
9899static void
9900do_iwmmxt_wldstw (void)
9901{
9902 /* RIWR_RIWC clears .isreg for a control register. */
9903 if (!inst.operands[0].isreg)
9904 {
9905 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9906 inst.instruction |= 0xf0000000;
9907 }
b99bd4ef 9908
c19d1205
ZW
9909 inst.instruction |= inst.operands[0].reg << 12;
9910 encode_arm_cp_address (1, TRUE, TRUE, 0);
9911}
b99bd4ef
NC
9912
9913static void
c19d1205 9914do_iwmmxt_wldstd (void)
b99bd4ef 9915{
c19d1205 9916 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9918 && inst.operands[1].immisreg)
9919 {
9920 inst.instruction &= ~0x1a000ff;
eff0bc54 9921 inst.instruction |= (0xfU << 28);
2d447fca
JM
9922 if (inst.operands[1].preind)
9923 inst.instruction |= PRE_INDEX;
9924 if (!inst.operands[1].negative)
9925 inst.instruction |= INDEX_UP;
9926 if (inst.operands[1].writeback)
9927 inst.instruction |= WRITE_BACK;
9928 inst.instruction |= inst.operands[1].reg << 16;
9929 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9930 inst.instruction |= inst.operands[1].imm;
9931 }
9932 else
9933 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9934}
b99bd4ef 9935
c19d1205
ZW
9936static void
9937do_iwmmxt_wshufh (void)
9938{
9939 inst.instruction |= inst.operands[0].reg << 12;
9940 inst.instruction |= inst.operands[1].reg << 16;
9941 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9942 inst.instruction |= (inst.operands[2].imm & 0x0f);
9943}
b99bd4ef 9944
c19d1205
ZW
9945static void
9946do_iwmmxt_wzero (void)
9947{
9948 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9949 inst.instruction |= inst.operands[0].reg;
9950 inst.instruction |= inst.operands[0].reg << 12;
9951 inst.instruction |= inst.operands[0].reg << 16;
9952}
2d447fca
JM
9953
9954static void
9955do_iwmmxt_wrwrwr_or_imm5 (void)
9956{
9957 if (inst.operands[2].isreg)
9958 do_rd_rn_rm ();
9959 else {
9960 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9961 _("immediate operand requires iWMMXt2"));
9962 do_rd_rn ();
9963 if (inst.operands[2].imm == 0)
9964 {
9965 switch ((inst.instruction >> 20) & 0xf)
9966 {
9967 case 4:
9968 case 5:
9969 case 6:
5f4273c7 9970 case 7:
2d447fca
JM
9971 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9972 inst.operands[2].imm = 16;
9973 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9974 break;
9975 case 8:
9976 case 9:
9977 case 10:
9978 case 11:
9979 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9980 inst.operands[2].imm = 32;
9981 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9982 break;
9983 case 12:
9984 case 13:
9985 case 14:
9986 case 15:
9987 {
9988 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9989 unsigned long wrn;
9990 wrn = (inst.instruction >> 16) & 0xf;
9991 inst.instruction &= 0xff0fff0f;
9992 inst.instruction |= wrn;
9993 /* Bail out here; the instruction is now assembled. */
9994 return;
9995 }
9996 }
9997 }
9998 /* Map 32 -> 0, etc. */
9999 inst.operands[2].imm &= 0x1f;
eff0bc54 10000 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10001 }
10002}
c19d1205
ZW
10003\f
10004/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10005 operations first, then control, shift, and load/store. */
b99bd4ef 10006
c19d1205 10007/* Insns like "foo X,Y,Z". */
b99bd4ef 10008
c19d1205
ZW
10009static void
10010do_mav_triple (void)
10011{
10012 inst.instruction |= inst.operands[0].reg << 16;
10013 inst.instruction |= inst.operands[1].reg;
10014 inst.instruction |= inst.operands[2].reg << 12;
10015}
b99bd4ef 10016
c19d1205
ZW
10017/* Insns like "foo W,X,Y,Z".
10018 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10019
c19d1205
ZW
10020static void
10021do_mav_quad (void)
10022{
10023 inst.instruction |= inst.operands[0].reg << 5;
10024 inst.instruction |= inst.operands[1].reg << 12;
10025 inst.instruction |= inst.operands[2].reg << 16;
10026 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10027}
10028
c19d1205
ZW
10029/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10030static void
10031do_mav_dspsc (void)
a737bd4d 10032{
c19d1205
ZW
10033 inst.instruction |= inst.operands[1].reg << 12;
10034}
a737bd4d 10035
c19d1205
ZW
10036/* Maverick shift immediate instructions.
10037 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10038 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10039
c19d1205
ZW
10040static void
10041do_mav_shift (void)
10042{
10043 int imm = inst.operands[2].imm;
a737bd4d 10044
c19d1205
ZW
10045 inst.instruction |= inst.operands[0].reg << 12;
10046 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10047
c19d1205
ZW
10048 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10049 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10050 Bit 4 should be 0. */
10051 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10052
c19d1205
ZW
10053 inst.instruction |= imm;
10054}
10055\f
10056/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10057
c19d1205
ZW
10058/* Xscale multiply-accumulate (argument parse)
10059 MIAcc acc0,Rm,Rs
10060 MIAPHcc acc0,Rm,Rs
10061 MIAxycc acc0,Rm,Rs. */
a737bd4d 10062
c19d1205
ZW
10063static void
10064do_xsc_mia (void)
10065{
10066 inst.instruction |= inst.operands[1].reg;
10067 inst.instruction |= inst.operands[2].reg << 12;
10068}
a737bd4d 10069
c19d1205 10070/* Xscale move-accumulator-register (argument parse)
a737bd4d 10071
c19d1205 10072 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10073
c19d1205
ZW
10074static void
10075do_xsc_mar (void)
10076{
10077 inst.instruction |= inst.operands[1].reg << 12;
10078 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10079}
10080
c19d1205 10081/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10082
c19d1205 10083 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10084
10085static void
c19d1205 10086do_xsc_mra (void)
b99bd4ef 10087{
c19d1205
ZW
10088 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10089 inst.instruction |= inst.operands[0].reg << 12;
10090 inst.instruction |= inst.operands[1].reg << 16;
10091}
10092\f
10093/* Encoding functions relevant only to Thumb. */
b99bd4ef 10094
c19d1205
ZW
10095/* inst.operands[i] is a shifted-register operand; encode
10096 it into inst.instruction in the format used by Thumb32. */
10097
10098static void
10099encode_thumb32_shifted_operand (int i)
10100{
10101 unsigned int value = inst.reloc.exp.X_add_number;
10102 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10103
9c3c69f2
PB
10104 constraint (inst.operands[i].immisreg,
10105 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10106 inst.instruction |= inst.operands[i].reg;
10107 if (shift == SHIFT_RRX)
10108 inst.instruction |= SHIFT_ROR << 4;
10109 else
b99bd4ef 10110 {
c19d1205
ZW
10111 constraint (inst.reloc.exp.X_op != O_constant,
10112 _("expression too complex"));
10113
10114 constraint (value > 32
10115 || (value == 32 && (shift == SHIFT_LSL
10116 || shift == SHIFT_ROR)),
10117 _("shift expression is too large"));
10118
10119 if (value == 0)
10120 shift = SHIFT_LSL;
10121 else if (value == 32)
10122 value = 0;
10123
10124 inst.instruction |= shift << 4;
10125 inst.instruction |= (value & 0x1c) << 10;
10126 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10127 }
c19d1205 10128}
b99bd4ef 10129
b99bd4ef 10130
c19d1205
ZW
10131/* inst.operands[i] was set up by parse_address. Encode it into a
10132 Thumb32 format load or store instruction. Reject forms that cannot
10133 be used with such instructions. If is_t is true, reject forms that
10134 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10135 that cannot be used with a D instruction. If it is a store insn,
10136 reject PC in Rn. */
b99bd4ef 10137
c19d1205
ZW
10138static void
10139encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10140{
5be8be5d 10141 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10142
10143 constraint (!inst.operands[i].isreg,
53365c0d 10144 _("Instruction does not support =N addresses"));
b99bd4ef 10145
c19d1205
ZW
10146 inst.instruction |= inst.operands[i].reg << 16;
10147 if (inst.operands[i].immisreg)
b99bd4ef 10148 {
5be8be5d 10149 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10150 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10151 constraint (inst.operands[i].negative,
10152 _("Thumb does not support negative register indexing"));
10153 constraint (inst.operands[i].postind,
10154 _("Thumb does not support register post-indexing"));
10155 constraint (inst.operands[i].writeback,
10156 _("Thumb does not support register indexing with writeback"));
10157 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10158 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10159
f40d1643 10160 inst.instruction |= inst.operands[i].imm;
c19d1205 10161 if (inst.operands[i].shifted)
b99bd4ef 10162 {
c19d1205
ZW
10163 constraint (inst.reloc.exp.X_op != O_constant,
10164 _("expression too complex"));
9c3c69f2
PB
10165 constraint (inst.reloc.exp.X_add_number < 0
10166 || inst.reloc.exp.X_add_number > 3,
c19d1205 10167 _("shift out of range"));
9c3c69f2 10168 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10169 }
10170 inst.reloc.type = BFD_RELOC_UNUSED;
10171 }
10172 else if (inst.operands[i].preind)
10173 {
5be8be5d 10174 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10175 constraint (is_t && inst.operands[i].writeback,
c19d1205 10176 _("cannot use writeback with this instruction"));
4755303e
WN
10177 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10178 BAD_PC_ADDRESSING);
c19d1205
ZW
10179
10180 if (is_d)
10181 {
10182 inst.instruction |= 0x01000000;
10183 if (inst.operands[i].writeback)
10184 inst.instruction |= 0x00200000;
b99bd4ef 10185 }
c19d1205 10186 else
b99bd4ef 10187 {
c19d1205
ZW
10188 inst.instruction |= 0x00000c00;
10189 if (inst.operands[i].writeback)
10190 inst.instruction |= 0x00000100;
b99bd4ef 10191 }
c19d1205 10192 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10193 }
c19d1205 10194 else if (inst.operands[i].postind)
b99bd4ef 10195 {
9c2799c2 10196 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10197 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10198 constraint (is_t, _("cannot use post-indexing with this instruction"));
10199
10200 if (is_d)
10201 inst.instruction |= 0x00200000;
10202 else
10203 inst.instruction |= 0x00000900;
10204 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10205 }
10206 else /* unindexed - only for coprocessor */
10207 inst.error = _("instruction does not accept unindexed addressing");
10208}
10209
10210/* Table of Thumb instructions which exist in both 16- and 32-bit
10211 encodings (the latter only in post-V6T2 cores). The index is the
10212 value used in the insns table below. When there is more than one
10213 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10214 holds variant (1).
10215 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10216#define T16_32_TAB \
21d799b5
NC
10217 X(_adc, 4140, eb400000), \
10218 X(_adcs, 4140, eb500000), \
10219 X(_add, 1c00, eb000000), \
10220 X(_adds, 1c00, eb100000), \
10221 X(_addi, 0000, f1000000), \
10222 X(_addis, 0000, f1100000), \
10223 X(_add_pc,000f, f20f0000), \
10224 X(_add_sp,000d, f10d0000), \
10225 X(_adr, 000f, f20f0000), \
10226 X(_and, 4000, ea000000), \
10227 X(_ands, 4000, ea100000), \
10228 X(_asr, 1000, fa40f000), \
10229 X(_asrs, 1000, fa50f000), \
10230 X(_b, e000, f000b000), \
10231 X(_bcond, d000, f0008000), \
10232 X(_bic, 4380, ea200000), \
10233 X(_bics, 4380, ea300000), \
10234 X(_cmn, 42c0, eb100f00), \
10235 X(_cmp, 2800, ebb00f00), \
10236 X(_cpsie, b660, f3af8400), \
10237 X(_cpsid, b670, f3af8600), \
10238 X(_cpy, 4600, ea4f0000), \
10239 X(_dec_sp,80dd, f1ad0d00), \
10240 X(_eor, 4040, ea800000), \
10241 X(_eors, 4040, ea900000), \
10242 X(_inc_sp,00dd, f10d0d00), \
10243 X(_ldmia, c800, e8900000), \
10244 X(_ldr, 6800, f8500000), \
10245 X(_ldrb, 7800, f8100000), \
10246 X(_ldrh, 8800, f8300000), \
10247 X(_ldrsb, 5600, f9100000), \
10248 X(_ldrsh, 5e00, f9300000), \
10249 X(_ldr_pc,4800, f85f0000), \
10250 X(_ldr_pc2,4800, f85f0000), \
10251 X(_ldr_sp,9800, f85d0000), \
10252 X(_lsl, 0000, fa00f000), \
10253 X(_lsls, 0000, fa10f000), \
10254 X(_lsr, 0800, fa20f000), \
10255 X(_lsrs, 0800, fa30f000), \
10256 X(_mov, 2000, ea4f0000), \
10257 X(_movs, 2000, ea5f0000), \
10258 X(_mul, 4340, fb00f000), \
10259 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10260 X(_mvn, 43c0, ea6f0000), \
10261 X(_mvns, 43c0, ea7f0000), \
10262 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10263 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10264 X(_orr, 4300, ea400000), \
10265 X(_orrs, 4300, ea500000), \
10266 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10267 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10268 X(_rev, ba00, fa90f080), \
10269 X(_rev16, ba40, fa90f090), \
10270 X(_revsh, bac0, fa90f0b0), \
10271 X(_ror, 41c0, fa60f000), \
10272 X(_rors, 41c0, fa70f000), \
10273 X(_sbc, 4180, eb600000), \
10274 X(_sbcs, 4180, eb700000), \
10275 X(_stmia, c000, e8800000), \
10276 X(_str, 6000, f8400000), \
10277 X(_strb, 7000, f8000000), \
10278 X(_strh, 8000, f8200000), \
10279 X(_str_sp,9000, f84d0000), \
10280 X(_sub, 1e00, eba00000), \
10281 X(_subs, 1e00, ebb00000), \
10282 X(_subi, 8000, f1a00000), \
10283 X(_subis, 8000, f1b00000), \
10284 X(_sxtb, b240, fa4ff080), \
10285 X(_sxth, b200, fa0ff080), \
10286 X(_tst, 4200, ea100f00), \
10287 X(_uxtb, b2c0, fa5ff080), \
10288 X(_uxth, b280, fa1ff080), \
10289 X(_nop, bf00, f3af8000), \
10290 X(_yield, bf10, f3af8001), \
10291 X(_wfe, bf20, f3af8002), \
10292 X(_wfi, bf30, f3af8003), \
53c4b28b 10293 X(_sev, bf40, f3af8004), \
74db7efb
NC
10294 X(_sevl, bf50, f3af8005), \
10295 X(_udf, de00, f7f0a000)
c19d1205
ZW
10296
10297/* To catch errors in encoding functions, the codes are all offset by
10298 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10299 as 16-bit instructions. */
21d799b5 10300#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10301enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10302#undef X
10303
10304#define X(a,b,c) 0x##b
10305static const unsigned short thumb_op16[] = { T16_32_TAB };
10306#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10307#undef X
10308
10309#define X(a,b,c) 0x##c
10310static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10311#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10312#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10313#undef X
10314#undef T16_32_TAB
10315
10316/* Thumb instruction encoders, in alphabetical order. */
10317
92e90b6e 10318/* ADDW or SUBW. */
c921be7d 10319
92e90b6e
PB
10320static void
10321do_t_add_sub_w (void)
10322{
10323 int Rd, Rn;
10324
10325 Rd = inst.operands[0].reg;
10326 Rn = inst.operands[1].reg;
10327
539d4391
NC
10328 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10329 is the SP-{plus,minus}-immediate form of the instruction. */
10330 if (Rn == REG_SP)
10331 constraint (Rd == REG_PC, BAD_PC);
10332 else
10333 reject_bad_reg (Rd);
fdfde340 10334
92e90b6e
PB
10335 inst.instruction |= (Rn << 16) | (Rd << 8);
10336 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10337}
10338
c19d1205
ZW
10339/* Parse an add or subtract instruction. We get here with inst.instruction
10340 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10341
10342static void
10343do_t_add_sub (void)
10344{
10345 int Rd, Rs, Rn;
10346
10347 Rd = inst.operands[0].reg;
10348 Rs = (inst.operands[1].present
10349 ? inst.operands[1].reg /* Rd, Rs, foo */
10350 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10351
e07e6e58
NC
10352 if (Rd == REG_PC)
10353 set_it_insn_type_last ();
10354
c19d1205
ZW
10355 if (unified_syntax)
10356 {
0110f2b8
PB
10357 bfd_boolean flags;
10358 bfd_boolean narrow;
10359 int opcode;
10360
10361 flags = (inst.instruction == T_MNEM_adds
10362 || inst.instruction == T_MNEM_subs);
10363 if (flags)
e07e6e58 10364 narrow = !in_it_block ();
0110f2b8 10365 else
e07e6e58 10366 narrow = in_it_block ();
c19d1205 10367 if (!inst.operands[2].isreg)
b99bd4ef 10368 {
16805f35
PB
10369 int add;
10370
fdfde340
JM
10371 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10372
16805f35
PB
10373 add = (inst.instruction == T_MNEM_add
10374 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10375 opcode = 0;
10376 if (inst.size_req != 4)
10377 {
0110f2b8 10378 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10379 appropriate. */
0110f2b8
PB
10380 if (Rd == REG_SP && Rs == REG_SP && !flags)
10381 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10382 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10383 opcode = T_MNEM_add_sp;
10384 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10385 opcode = T_MNEM_add_pc;
10386 else if (Rd <= 7 && Rs <= 7 && narrow)
10387 {
10388 if (flags)
10389 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10390 else
10391 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10392 }
10393 if (opcode)
10394 {
10395 inst.instruction = THUMB_OP16(opcode);
10396 inst.instruction |= (Rd << 4) | Rs;
10397 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10398 if (inst.size_req != 2)
10399 inst.relax = opcode;
10400 }
10401 else
10402 constraint (inst.size_req == 2, BAD_HIREG);
10403 }
10404 if (inst.size_req == 4
10405 || (inst.size_req != 2 && !opcode))
10406 {
efd81785
PB
10407 if (Rd == REG_PC)
10408 {
fdfde340 10409 constraint (add, BAD_PC);
efd81785
PB
10410 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10411 _("only SUBS PC, LR, #const allowed"));
10412 constraint (inst.reloc.exp.X_op != O_constant,
10413 _("expression too complex"));
10414 constraint (inst.reloc.exp.X_add_number < 0
10415 || inst.reloc.exp.X_add_number > 0xff,
10416 _("immediate value out of range"));
10417 inst.instruction = T2_SUBS_PC_LR
10418 | inst.reloc.exp.X_add_number;
10419 inst.reloc.type = BFD_RELOC_UNUSED;
10420 return;
10421 }
10422 else if (Rs == REG_PC)
16805f35
PB
10423 {
10424 /* Always use addw/subw. */
10425 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10426 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10427 }
10428 else
10429 {
10430 inst.instruction = THUMB_OP32 (inst.instruction);
10431 inst.instruction = (inst.instruction & 0xe1ffffff)
10432 | 0x10000000;
10433 if (flags)
10434 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10435 else
10436 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10437 }
dc4503c6
PB
10438 inst.instruction |= Rd << 8;
10439 inst.instruction |= Rs << 16;
0110f2b8 10440 }
b99bd4ef 10441 }
c19d1205
ZW
10442 else
10443 {
5f4cb198
NC
10444 unsigned int value = inst.reloc.exp.X_add_number;
10445 unsigned int shift = inst.operands[2].shift_kind;
10446
c19d1205
ZW
10447 Rn = inst.operands[2].reg;
10448 /* See if we can do this with a 16-bit instruction. */
10449 if (!inst.operands[2].shifted && inst.size_req != 4)
10450 {
e27ec89e
PB
10451 if (Rd > 7 || Rs > 7 || Rn > 7)
10452 narrow = FALSE;
10453
10454 if (narrow)
c19d1205 10455 {
e27ec89e
PB
10456 inst.instruction = ((inst.instruction == T_MNEM_adds
10457 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10458 ? T_OPCODE_ADD_R3
10459 : T_OPCODE_SUB_R3);
10460 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10461 return;
10462 }
b99bd4ef 10463
7e806470 10464 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10465 {
7e806470
PB
10466 /* Thumb-1 cores (except v6-M) require at least one high
10467 register in a narrow non flag setting add. */
10468 if (Rd > 7 || Rn > 7
10469 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10470 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10471 {
7e806470
PB
10472 if (Rd == Rn)
10473 {
10474 Rn = Rs;
10475 Rs = Rd;
10476 }
c19d1205
ZW
10477 inst.instruction = T_OPCODE_ADD_HI;
10478 inst.instruction |= (Rd & 8) << 4;
10479 inst.instruction |= (Rd & 7);
10480 inst.instruction |= Rn << 3;
10481 return;
10482 }
c19d1205
ZW
10483 }
10484 }
c921be7d 10485
fdfde340
JM
10486 constraint (Rd == REG_PC, BAD_PC);
10487 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10488 constraint (Rs == REG_PC, BAD_PC);
10489 reject_bad_reg (Rn);
10490
c19d1205
ZW
10491 /* If we get here, it can't be done in 16 bits. */
10492 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10493 _("shift must be constant"));
10494 inst.instruction = THUMB_OP32 (inst.instruction);
10495 inst.instruction |= Rd << 8;
10496 inst.instruction |= Rs << 16;
5f4cb198
NC
10497 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10498 _("shift value over 3 not allowed in thumb mode"));
10499 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10500 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10501 encode_thumb32_shifted_operand (2);
10502 }
10503 }
10504 else
10505 {
10506 constraint (inst.instruction == T_MNEM_adds
10507 || inst.instruction == T_MNEM_subs,
10508 BAD_THUMB32);
b99bd4ef 10509
c19d1205 10510 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10511 {
c19d1205
ZW
10512 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10513 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10514 BAD_HIREG);
10515
10516 inst.instruction = (inst.instruction == T_MNEM_add
10517 ? 0x0000 : 0x8000);
10518 inst.instruction |= (Rd << 4) | Rs;
10519 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10520 return;
10521 }
10522
c19d1205
ZW
10523 Rn = inst.operands[2].reg;
10524 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10525
c19d1205
ZW
10526 /* We now have Rd, Rs, and Rn set to registers. */
10527 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10528 {
c19d1205
ZW
10529 /* Can't do this for SUB. */
10530 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10531 inst.instruction = T_OPCODE_ADD_HI;
10532 inst.instruction |= (Rd & 8) << 4;
10533 inst.instruction |= (Rd & 7);
10534 if (Rs == Rd)
10535 inst.instruction |= Rn << 3;
10536 else if (Rn == Rd)
10537 inst.instruction |= Rs << 3;
10538 else
10539 constraint (1, _("dest must overlap one source register"));
10540 }
10541 else
10542 {
10543 inst.instruction = (inst.instruction == T_MNEM_add
10544 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10545 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10546 }
b99bd4ef 10547 }
b99bd4ef
NC
10548}
10549
c19d1205
ZW
10550static void
10551do_t_adr (void)
10552{
fdfde340
JM
10553 unsigned Rd;
10554
10555 Rd = inst.operands[0].reg;
10556 reject_bad_reg (Rd);
10557
10558 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10559 {
10560 /* Defer to section relaxation. */
10561 inst.relax = inst.instruction;
10562 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10563 inst.instruction |= Rd << 4;
0110f2b8
PB
10564 }
10565 else if (unified_syntax && inst.size_req != 2)
e9f89963 10566 {
0110f2b8 10567 /* Generate a 32-bit opcode. */
e9f89963 10568 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10569 inst.instruction |= Rd << 8;
e9f89963
PB
10570 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10571 inst.reloc.pc_rel = 1;
10572 }
10573 else
10574 {
0110f2b8 10575 /* Generate a 16-bit opcode. */
e9f89963
PB
10576 inst.instruction = THUMB_OP16 (inst.instruction);
10577 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10578 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10579 inst.reloc.pc_rel = 1;
b99bd4ef 10580
fdfde340 10581 inst.instruction |= Rd << 4;
e9f89963 10582 }
c19d1205 10583}
b99bd4ef 10584
c19d1205
ZW
10585/* Arithmetic instructions for which there is just one 16-bit
10586 instruction encoding, and it allows only two low registers.
10587 For maximal compatibility with ARM syntax, we allow three register
10588 operands even when Thumb-32 instructions are not available, as long
10589 as the first two are identical. For instance, both "sbc r0,r1" and
10590 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10591static void
c19d1205 10592do_t_arit3 (void)
b99bd4ef 10593{
c19d1205 10594 int Rd, Rs, Rn;
b99bd4ef 10595
c19d1205
ZW
10596 Rd = inst.operands[0].reg;
10597 Rs = (inst.operands[1].present
10598 ? inst.operands[1].reg /* Rd, Rs, foo */
10599 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10600 Rn = inst.operands[2].reg;
b99bd4ef 10601
fdfde340
JM
10602 reject_bad_reg (Rd);
10603 reject_bad_reg (Rs);
10604 if (inst.operands[2].isreg)
10605 reject_bad_reg (Rn);
10606
c19d1205 10607 if (unified_syntax)
b99bd4ef 10608 {
c19d1205
ZW
10609 if (!inst.operands[2].isreg)
10610 {
10611 /* For an immediate, we always generate a 32-bit opcode;
10612 section relaxation will shrink it later if possible. */
10613 inst.instruction = THUMB_OP32 (inst.instruction);
10614 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10615 inst.instruction |= Rd << 8;
10616 inst.instruction |= Rs << 16;
10617 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10618 }
10619 else
10620 {
e27ec89e
PB
10621 bfd_boolean narrow;
10622
c19d1205 10623 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10624 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10625 narrow = !in_it_block ();
e27ec89e 10626 else
e07e6e58 10627 narrow = in_it_block ();
e27ec89e
PB
10628
10629 if (Rd > 7 || Rn > 7 || Rs > 7)
10630 narrow = FALSE;
10631 if (inst.operands[2].shifted)
10632 narrow = FALSE;
10633 if (inst.size_req == 4)
10634 narrow = FALSE;
10635
10636 if (narrow
c19d1205
ZW
10637 && Rd == Rs)
10638 {
10639 inst.instruction = THUMB_OP16 (inst.instruction);
10640 inst.instruction |= Rd;
10641 inst.instruction |= Rn << 3;
10642 return;
10643 }
b99bd4ef 10644
c19d1205
ZW
10645 /* If we get here, it can't be done in 16 bits. */
10646 constraint (inst.operands[2].shifted
10647 && inst.operands[2].immisreg,
10648 _("shift must be constant"));
10649 inst.instruction = THUMB_OP32 (inst.instruction);
10650 inst.instruction |= Rd << 8;
10651 inst.instruction |= Rs << 16;
10652 encode_thumb32_shifted_operand (2);
10653 }
a737bd4d 10654 }
c19d1205 10655 else
b99bd4ef 10656 {
c19d1205
ZW
10657 /* On its face this is a lie - the instruction does set the
10658 flags. However, the only supported mnemonic in this mode
10659 says it doesn't. */
10660 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10661
c19d1205
ZW
10662 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10663 _("unshifted register required"));
10664 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10665 constraint (Rd != Rs,
10666 _("dest and source1 must be the same register"));
a737bd4d 10667
c19d1205
ZW
10668 inst.instruction = THUMB_OP16 (inst.instruction);
10669 inst.instruction |= Rd;
10670 inst.instruction |= Rn << 3;
b99bd4ef 10671 }
a737bd4d 10672}
b99bd4ef 10673
c19d1205
ZW
10674/* Similarly, but for instructions where the arithmetic operation is
10675 commutative, so we can allow either of them to be different from
10676 the destination operand in a 16-bit instruction. For instance, all
10677 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10678 accepted. */
10679static void
10680do_t_arit3c (void)
a737bd4d 10681{
c19d1205 10682 int Rd, Rs, Rn;
b99bd4ef 10683
c19d1205
ZW
10684 Rd = inst.operands[0].reg;
10685 Rs = (inst.operands[1].present
10686 ? inst.operands[1].reg /* Rd, Rs, foo */
10687 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10688 Rn = inst.operands[2].reg;
c921be7d 10689
fdfde340
JM
10690 reject_bad_reg (Rd);
10691 reject_bad_reg (Rs);
10692 if (inst.operands[2].isreg)
10693 reject_bad_reg (Rn);
a737bd4d 10694
c19d1205 10695 if (unified_syntax)
a737bd4d 10696 {
c19d1205 10697 if (!inst.operands[2].isreg)
b99bd4ef 10698 {
c19d1205
ZW
10699 /* For an immediate, we always generate a 32-bit opcode;
10700 section relaxation will shrink it later if possible. */
10701 inst.instruction = THUMB_OP32 (inst.instruction);
10702 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10703 inst.instruction |= Rd << 8;
10704 inst.instruction |= Rs << 16;
10705 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10706 }
c19d1205 10707 else
a737bd4d 10708 {
e27ec89e
PB
10709 bfd_boolean narrow;
10710
c19d1205 10711 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10712 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10713 narrow = !in_it_block ();
e27ec89e 10714 else
e07e6e58 10715 narrow = in_it_block ();
e27ec89e
PB
10716
10717 if (Rd > 7 || Rn > 7 || Rs > 7)
10718 narrow = FALSE;
10719 if (inst.operands[2].shifted)
10720 narrow = FALSE;
10721 if (inst.size_req == 4)
10722 narrow = FALSE;
10723
10724 if (narrow)
a737bd4d 10725 {
c19d1205 10726 if (Rd == Rs)
a737bd4d 10727 {
c19d1205
ZW
10728 inst.instruction = THUMB_OP16 (inst.instruction);
10729 inst.instruction |= Rd;
10730 inst.instruction |= Rn << 3;
10731 return;
a737bd4d 10732 }
c19d1205 10733 if (Rd == Rn)
a737bd4d 10734 {
c19d1205
ZW
10735 inst.instruction = THUMB_OP16 (inst.instruction);
10736 inst.instruction |= Rd;
10737 inst.instruction |= Rs << 3;
10738 return;
a737bd4d
NC
10739 }
10740 }
c19d1205
ZW
10741
10742 /* If we get here, it can't be done in 16 bits. */
10743 constraint (inst.operands[2].shifted
10744 && inst.operands[2].immisreg,
10745 _("shift must be constant"));
10746 inst.instruction = THUMB_OP32 (inst.instruction);
10747 inst.instruction |= Rd << 8;
10748 inst.instruction |= Rs << 16;
10749 encode_thumb32_shifted_operand (2);
a737bd4d 10750 }
b99bd4ef 10751 }
c19d1205
ZW
10752 else
10753 {
10754 /* On its face this is a lie - the instruction does set the
10755 flags. However, the only supported mnemonic in this mode
10756 says it doesn't. */
10757 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10758
c19d1205
ZW
10759 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10760 _("unshifted register required"));
10761 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10762
10763 inst.instruction = THUMB_OP16 (inst.instruction);
10764 inst.instruction |= Rd;
10765
10766 if (Rd == Rs)
10767 inst.instruction |= Rn << 3;
10768 else if (Rd == Rn)
10769 inst.instruction |= Rs << 3;
10770 else
10771 constraint (1, _("dest must overlap one source register"));
10772 }
a737bd4d
NC
10773}
10774
c19d1205
ZW
10775static void
10776do_t_bfc (void)
a737bd4d 10777{
fdfde340 10778 unsigned Rd;
c19d1205
ZW
10779 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10780 constraint (msb > 32, _("bit-field extends past end of register"));
10781 /* The instruction encoding stores the LSB and MSB,
10782 not the LSB and width. */
fdfde340
JM
10783 Rd = inst.operands[0].reg;
10784 reject_bad_reg (Rd);
10785 inst.instruction |= Rd << 8;
c19d1205
ZW
10786 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10787 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10788 inst.instruction |= msb - 1;
b99bd4ef
NC
10789}
10790
c19d1205
ZW
10791static void
10792do_t_bfi (void)
b99bd4ef 10793{
fdfde340 10794 int Rd, Rn;
c19d1205 10795 unsigned int msb;
b99bd4ef 10796
fdfde340
JM
10797 Rd = inst.operands[0].reg;
10798 reject_bad_reg (Rd);
10799
c19d1205
ZW
10800 /* #0 in second position is alternative syntax for bfc, which is
10801 the same instruction but with REG_PC in the Rm field. */
10802 if (!inst.operands[1].isreg)
fdfde340
JM
10803 Rn = REG_PC;
10804 else
10805 {
10806 Rn = inst.operands[1].reg;
10807 reject_bad_reg (Rn);
10808 }
b99bd4ef 10809
c19d1205
ZW
10810 msb = inst.operands[2].imm + inst.operands[3].imm;
10811 constraint (msb > 32, _("bit-field extends past end of register"));
10812 /* The instruction encoding stores the LSB and MSB,
10813 not the LSB and width. */
fdfde340
JM
10814 inst.instruction |= Rd << 8;
10815 inst.instruction |= Rn << 16;
c19d1205
ZW
10816 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10817 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10818 inst.instruction |= msb - 1;
b99bd4ef
NC
10819}
10820
c19d1205
ZW
10821static void
10822do_t_bfx (void)
b99bd4ef 10823{
fdfde340
JM
10824 unsigned Rd, Rn;
10825
10826 Rd = inst.operands[0].reg;
10827 Rn = inst.operands[1].reg;
10828
10829 reject_bad_reg (Rd);
10830 reject_bad_reg (Rn);
10831
c19d1205
ZW
10832 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10833 _("bit-field extends past end of register"));
fdfde340
JM
10834 inst.instruction |= Rd << 8;
10835 inst.instruction |= Rn << 16;
c19d1205
ZW
10836 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10837 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10838 inst.instruction |= inst.operands[3].imm - 1;
10839}
b99bd4ef 10840
c19d1205
ZW
10841/* ARM V5 Thumb BLX (argument parse)
10842 BLX <target_addr> which is BLX(1)
10843 BLX <Rm> which is BLX(2)
10844 Unfortunately, there are two different opcodes for this mnemonic.
10845 So, the insns[].value is not used, and the code here zaps values
10846 into inst.instruction.
b99bd4ef 10847
c19d1205
ZW
10848 ??? How to take advantage of the additional two bits of displacement
10849 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10850
c19d1205
ZW
10851static void
10852do_t_blx (void)
10853{
e07e6e58
NC
10854 set_it_insn_type_last ();
10855
c19d1205 10856 if (inst.operands[0].isreg)
fdfde340
JM
10857 {
10858 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10859 /* We have a register, so this is BLX(2). */
10860 inst.instruction |= inst.operands[0].reg << 3;
10861 }
b99bd4ef
NC
10862 else
10863 {
c19d1205 10864 /* No register. This must be BLX(1). */
2fc8bdac 10865 inst.instruction = 0xf000e800;
0855e32b 10866 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10867 }
10868}
10869
c19d1205
ZW
10870static void
10871do_t_branch (void)
b99bd4ef 10872{
0110f2b8 10873 int opcode;
dfa9f0d5 10874 int cond;
9ae92b05 10875 int reloc;
dfa9f0d5 10876
e07e6e58
NC
10877 cond = inst.cond;
10878 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10879
10880 if (in_it_block ())
dfa9f0d5
PB
10881 {
10882 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10883 branches. */
dfa9f0d5 10884 cond = COND_ALWAYS;
dfa9f0d5
PB
10885 }
10886 else
10887 cond = inst.cond;
10888
10889 if (cond != COND_ALWAYS)
0110f2b8
PB
10890 opcode = T_MNEM_bcond;
10891 else
10892 opcode = inst.instruction;
10893
12d6b0b7
RS
10894 if (unified_syntax
10895 && (inst.size_req == 4
10960bfb
PB
10896 || (inst.size_req != 2
10897 && (inst.operands[0].hasreloc
10898 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10899 {
0110f2b8 10900 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10901 if (cond == COND_ALWAYS)
9ae92b05 10902 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10903 else
10904 {
9c2799c2 10905 gas_assert (cond != 0xF);
dfa9f0d5 10906 inst.instruction |= cond << 22;
9ae92b05 10907 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10908 }
10909 }
b99bd4ef
NC
10910 else
10911 {
0110f2b8 10912 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10913 if (cond == COND_ALWAYS)
9ae92b05 10914 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10915 else
b99bd4ef 10916 {
dfa9f0d5 10917 inst.instruction |= cond << 8;
9ae92b05 10918 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10919 }
0110f2b8
PB
10920 /* Allow section relaxation. */
10921 if (unified_syntax && inst.size_req != 2)
10922 inst.relax = opcode;
b99bd4ef 10923 }
9ae92b05 10924 inst.reloc.type = reloc;
c19d1205 10925 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10926}
10927
8884b720 10928/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10929 between the two is the maximum immediate allowed - which is passed in
8884b720 10930 RANGE. */
b99bd4ef 10931static void
8884b720 10932do_t_bkpt_hlt1 (int range)
b99bd4ef 10933{
dfa9f0d5
PB
10934 constraint (inst.cond != COND_ALWAYS,
10935 _("instruction is always unconditional"));
c19d1205 10936 if (inst.operands[0].present)
b99bd4ef 10937 {
8884b720 10938 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10939 _("immediate value out of range"));
10940 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10941 }
8884b720
MGD
10942
10943 set_it_insn_type (NEUTRAL_IT_INSN);
10944}
10945
10946static void
10947do_t_hlt (void)
10948{
10949 do_t_bkpt_hlt1 (63);
10950}
10951
10952static void
10953do_t_bkpt (void)
10954{
10955 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10956}
10957
10958static void
c19d1205 10959do_t_branch23 (void)
b99bd4ef 10960{
e07e6e58 10961 set_it_insn_type_last ();
0855e32b 10962 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10963
0855e32b
NS
10964 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10965 this file. We used to simply ignore the PLT reloc type here --
10966 the branch encoding is now needed to deal with TLSCALL relocs.
10967 So if we see a PLT reloc now, put it back to how it used to be to
10968 keep the preexisting behaviour. */
10969 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10970 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10971
4343666d 10972#if defined(OBJ_COFF)
c19d1205
ZW
10973 /* If the destination of the branch is a defined symbol which does not have
10974 the THUMB_FUNC attribute, then we must be calling a function which has
10975 the (interfacearm) attribute. We look for the Thumb entry point to that
10976 function and change the branch to refer to that function instead. */
10977 if ( inst.reloc.exp.X_op == O_symbol
10978 && inst.reloc.exp.X_add_symbol != NULL
10979 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10980 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10981 inst.reloc.exp.X_add_symbol =
10982 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10983#endif
90e4755a
RE
10984}
10985
10986static void
c19d1205 10987do_t_bx (void)
90e4755a 10988{
e07e6e58 10989 set_it_insn_type_last ();
c19d1205
ZW
10990 inst.instruction |= inst.operands[0].reg << 3;
10991 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10992 should cause the alignment to be checked once it is known. This is
10993 because BX PC only works if the instruction is word aligned. */
10994}
90e4755a 10995
c19d1205
ZW
10996static void
10997do_t_bxj (void)
10998{
fdfde340 10999 int Rm;
90e4755a 11000
e07e6e58 11001 set_it_insn_type_last ();
fdfde340
JM
11002 Rm = inst.operands[0].reg;
11003 reject_bad_reg (Rm);
11004 inst.instruction |= Rm << 16;
90e4755a
RE
11005}
11006
11007static void
c19d1205 11008do_t_clz (void)
90e4755a 11009{
fdfde340
JM
11010 unsigned Rd;
11011 unsigned Rm;
11012
11013 Rd = inst.operands[0].reg;
11014 Rm = inst.operands[1].reg;
11015
11016 reject_bad_reg (Rd);
11017 reject_bad_reg (Rm);
11018
11019 inst.instruction |= Rd << 8;
11020 inst.instruction |= Rm << 16;
11021 inst.instruction |= Rm;
c19d1205 11022}
90e4755a 11023
dfa9f0d5
PB
11024static void
11025do_t_cps (void)
11026{
e07e6e58 11027 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11028 inst.instruction |= inst.operands[0].imm;
11029}
11030
c19d1205
ZW
11031static void
11032do_t_cpsi (void)
11033{
e07e6e58 11034 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11035 if (unified_syntax
62b3e311
PB
11036 && (inst.operands[1].present || inst.size_req == 4)
11037 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11038 {
c19d1205
ZW
11039 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11040 inst.instruction = 0xf3af8000;
11041 inst.instruction |= imod << 9;
11042 inst.instruction |= inst.operands[0].imm << 5;
11043 if (inst.operands[1].present)
11044 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11045 }
c19d1205 11046 else
90e4755a 11047 {
62b3e311
PB
11048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11049 && (inst.operands[0].imm & 4),
11050 _("selected processor does not support 'A' form "
11051 "of this instruction"));
11052 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11053 _("Thumb does not support the 2-argument "
11054 "form of this instruction"));
11055 inst.instruction |= inst.operands[0].imm;
90e4755a 11056 }
90e4755a
RE
11057}
11058
c19d1205
ZW
11059/* THUMB CPY instruction (argument parse). */
11060
90e4755a 11061static void
c19d1205 11062do_t_cpy (void)
90e4755a 11063{
c19d1205 11064 if (inst.size_req == 4)
90e4755a 11065 {
c19d1205
ZW
11066 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11067 inst.instruction |= inst.operands[0].reg << 8;
11068 inst.instruction |= inst.operands[1].reg;
90e4755a 11069 }
c19d1205 11070 else
90e4755a 11071 {
c19d1205
ZW
11072 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11073 inst.instruction |= (inst.operands[0].reg & 0x7);
11074 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11075 }
90e4755a
RE
11076}
11077
90e4755a 11078static void
25fe350b 11079do_t_cbz (void)
90e4755a 11080{
e07e6e58 11081 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11082 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11083 inst.instruction |= inst.operands[0].reg;
11084 inst.reloc.pc_rel = 1;
11085 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11086}
90e4755a 11087
62b3e311
PB
11088static void
11089do_t_dbg (void)
11090{
11091 inst.instruction |= inst.operands[0].imm;
11092}
11093
11094static void
11095do_t_div (void)
11096{
fdfde340
JM
11097 unsigned Rd, Rn, Rm;
11098
11099 Rd = inst.operands[0].reg;
11100 Rn = (inst.operands[1].present
11101 ? inst.operands[1].reg : Rd);
11102 Rm = inst.operands[2].reg;
11103
11104 reject_bad_reg (Rd);
11105 reject_bad_reg (Rn);
11106 reject_bad_reg (Rm);
11107
11108 inst.instruction |= Rd << 8;
11109 inst.instruction |= Rn << 16;
11110 inst.instruction |= Rm;
62b3e311
PB
11111}
11112
c19d1205
ZW
11113static void
11114do_t_hint (void)
11115{
11116 if (unified_syntax && inst.size_req == 4)
11117 inst.instruction = THUMB_OP32 (inst.instruction);
11118 else
11119 inst.instruction = THUMB_OP16 (inst.instruction);
11120}
90e4755a 11121
c19d1205
ZW
11122static void
11123do_t_it (void)
11124{
11125 unsigned int cond = inst.operands[0].imm;
e27ec89e 11126
e07e6e58
NC
11127 set_it_insn_type (IT_INSN);
11128 now_it.mask = (inst.instruction & 0xf) | 0x10;
11129 now_it.cc = cond;
5a01bb1d 11130 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11131
11132 /* If the condition is a negative condition, invert the mask. */
c19d1205 11133 if ((cond & 0x1) == 0x0)
90e4755a 11134 {
c19d1205 11135 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11136
c19d1205 11137 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11138 {
11139 /* No conversion needed. */
11140 now_it.block_length = 1;
11141 }
c19d1205 11142 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11143 {
11144 mask ^= 0x8;
11145 now_it.block_length = 2;
11146 }
e27ec89e 11147 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11148 {
11149 mask ^= 0xC;
11150 now_it.block_length = 3;
11151 }
c19d1205 11152 else
5a01bb1d
MGD
11153 {
11154 mask ^= 0xE;
11155 now_it.block_length = 4;
11156 }
90e4755a 11157
e27ec89e
PB
11158 inst.instruction &= 0xfff0;
11159 inst.instruction |= mask;
c19d1205 11160 }
90e4755a 11161
c19d1205
ZW
11162 inst.instruction |= cond << 4;
11163}
90e4755a 11164
3c707909
PB
11165/* Helper function used for both push/pop and ldm/stm. */
11166static void
11167encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11168{
11169 bfd_boolean load;
11170
11171 load = (inst.instruction & (1 << 20)) != 0;
11172
11173 if (mask & (1 << 13))
11174 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11175
11176 if ((mask & (1 << base)) != 0
11177 && writeback)
11178 inst.error = _("having the base register in the register list when "
11179 "using write back is UNPREDICTABLE");
11180
3c707909
PB
11181 if (load)
11182 {
e07e6e58 11183 if (mask & (1 << 15))
477330fc
RM
11184 {
11185 if (mask & (1 << 14))
11186 inst.error = _("LR and PC should not both be in register list");
11187 else
11188 set_it_insn_type_last ();
11189 }
3c707909
PB
11190 }
11191 else
11192 {
11193 if (mask & (1 << 15))
11194 inst.error = _("PC not allowed in register list");
3c707909
PB
11195 }
11196
11197 if ((mask & (mask - 1)) == 0)
11198 {
11199 /* Single register transfers implemented as str/ldr. */
11200 if (writeback)
11201 {
11202 if (inst.instruction & (1 << 23))
11203 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11204 else
11205 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11206 }
11207 else
11208 {
11209 if (inst.instruction & (1 << 23))
11210 inst.instruction = 0x00800000; /* ia -> [base] */
11211 else
11212 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11213 }
11214
11215 inst.instruction |= 0xf8400000;
11216 if (load)
11217 inst.instruction |= 0x00100000;
11218
5f4273c7 11219 mask = ffs (mask) - 1;
3c707909
PB
11220 mask <<= 12;
11221 }
11222 else if (writeback)
11223 inst.instruction |= WRITE_BACK;
11224
11225 inst.instruction |= mask;
11226 inst.instruction |= base << 16;
11227}
11228
c19d1205
ZW
11229static void
11230do_t_ldmstm (void)
11231{
11232 /* This really doesn't seem worth it. */
11233 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11234 _("expression too complex"));
11235 constraint (inst.operands[1].writeback,
11236 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11237
c19d1205
ZW
11238 if (unified_syntax)
11239 {
3c707909
PB
11240 bfd_boolean narrow;
11241 unsigned mask;
11242
11243 narrow = FALSE;
c19d1205
ZW
11244 /* See if we can use a 16-bit instruction. */
11245 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11246 && inst.size_req != 4
3c707909 11247 && !(inst.operands[1].imm & ~0xff))
90e4755a 11248 {
3c707909 11249 mask = 1 << inst.operands[0].reg;
90e4755a 11250
eab4f823 11251 if (inst.operands[0].reg <= 7)
90e4755a 11252 {
3c707909 11253 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11254 ? inst.operands[0].writeback
11255 : (inst.operands[0].writeback
11256 == !(inst.operands[1].imm & mask)))
477330fc 11257 {
eab4f823
MGD
11258 if (inst.instruction == T_MNEM_stmia
11259 && (inst.operands[1].imm & mask)
11260 && (inst.operands[1].imm & (mask - 1)))
11261 as_warn (_("value stored for r%d is UNKNOWN"),
11262 inst.operands[0].reg);
3c707909 11263
eab4f823
MGD
11264 inst.instruction = THUMB_OP16 (inst.instruction);
11265 inst.instruction |= inst.operands[0].reg << 8;
11266 inst.instruction |= inst.operands[1].imm;
11267 narrow = TRUE;
11268 }
11269 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11270 {
11271 /* This means 1 register in reg list one of 3 situations:
11272 1. Instruction is stmia, but without writeback.
11273 2. lmdia without writeback, but with Rn not in
477330fc 11274 reglist.
eab4f823
MGD
11275 3. ldmia with writeback, but with Rn in reglist.
11276 Case 3 is UNPREDICTABLE behaviour, so we handle
11277 case 1 and 2 which can be converted into a 16-bit
11278 str or ldr. The SP cases are handled below. */
11279 unsigned long opcode;
11280 /* First, record an error for Case 3. */
11281 if (inst.operands[1].imm & mask
11282 && inst.operands[0].writeback)
fa94de6b 11283 inst.error =
eab4f823
MGD
11284 _("having the base register in the register list when "
11285 "using write back is UNPREDICTABLE");
fa94de6b
RM
11286
11287 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11288 : T_MNEM_ldr);
11289 inst.instruction = THUMB_OP16 (opcode);
11290 inst.instruction |= inst.operands[0].reg << 3;
11291 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11292 narrow = TRUE;
11293 }
90e4755a 11294 }
eab4f823 11295 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11296 {
eab4f823
MGD
11297 if (inst.operands[0].writeback)
11298 {
fa94de6b 11299 inst.instruction =
eab4f823 11300 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11301 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11302 inst.instruction |= inst.operands[1].imm;
477330fc 11303 narrow = TRUE;
eab4f823
MGD
11304 }
11305 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11306 {
fa94de6b 11307 inst.instruction =
eab4f823 11308 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11309 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11310 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11311 narrow = TRUE;
eab4f823 11312 }
90e4755a 11313 }
3c707909
PB
11314 }
11315
11316 if (!narrow)
11317 {
c19d1205
ZW
11318 if (inst.instruction < 0xffff)
11319 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11320
5f4273c7
NC
11321 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11322 inst.operands[0].writeback);
90e4755a
RE
11323 }
11324 }
c19d1205 11325 else
90e4755a 11326 {
c19d1205
ZW
11327 constraint (inst.operands[0].reg > 7
11328 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11329 constraint (inst.instruction != T_MNEM_ldmia
11330 && inst.instruction != T_MNEM_stmia,
11331 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11332 if (inst.instruction == T_MNEM_stmia)
f03698e6 11333 {
c19d1205
ZW
11334 if (!inst.operands[0].writeback)
11335 as_warn (_("this instruction will write back the base register"));
11336 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11337 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11338 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11339 inst.operands[0].reg);
f03698e6 11340 }
c19d1205 11341 else
90e4755a 11342 {
c19d1205
ZW
11343 if (!inst.operands[0].writeback
11344 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11345 as_warn (_("this instruction will write back the base register"));
11346 else if (inst.operands[0].writeback
11347 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11348 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11349 }
11350
c19d1205
ZW
11351 inst.instruction = THUMB_OP16 (inst.instruction);
11352 inst.instruction |= inst.operands[0].reg << 8;
11353 inst.instruction |= inst.operands[1].imm;
11354 }
11355}
e28cd48c 11356
c19d1205
ZW
11357static void
11358do_t_ldrex (void)
11359{
11360 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11361 || inst.operands[1].postind || inst.operands[1].writeback
11362 || inst.operands[1].immisreg || inst.operands[1].shifted
11363 || inst.operands[1].negative,
01cfc07f 11364 BAD_ADDR_MODE);
e28cd48c 11365
5be8be5d
DG
11366 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11367
c19d1205
ZW
11368 inst.instruction |= inst.operands[0].reg << 12;
11369 inst.instruction |= inst.operands[1].reg << 16;
11370 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11371}
e28cd48c 11372
c19d1205
ZW
11373static void
11374do_t_ldrexd (void)
11375{
11376 if (!inst.operands[1].present)
1cac9012 11377 {
c19d1205
ZW
11378 constraint (inst.operands[0].reg == REG_LR,
11379 _("r14 not allowed as first register "
11380 "when second register is omitted"));
11381 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11382 }
c19d1205
ZW
11383 constraint (inst.operands[0].reg == inst.operands[1].reg,
11384 BAD_OVERLAP);
b99bd4ef 11385
c19d1205
ZW
11386 inst.instruction |= inst.operands[0].reg << 12;
11387 inst.instruction |= inst.operands[1].reg << 8;
11388 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11389}
11390
11391static void
c19d1205 11392do_t_ldst (void)
b99bd4ef 11393{
0110f2b8
PB
11394 unsigned long opcode;
11395 int Rn;
11396
e07e6e58
NC
11397 if (inst.operands[0].isreg
11398 && !inst.operands[0].preind
11399 && inst.operands[0].reg == REG_PC)
11400 set_it_insn_type_last ();
11401
0110f2b8 11402 opcode = inst.instruction;
c19d1205 11403 if (unified_syntax)
b99bd4ef 11404 {
53365c0d
PB
11405 if (!inst.operands[1].isreg)
11406 {
11407 if (opcode <= 0xffff)
11408 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11409 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11410 return;
11411 }
0110f2b8
PB
11412 if (inst.operands[1].isreg
11413 && !inst.operands[1].writeback
c19d1205
ZW
11414 && !inst.operands[1].shifted && !inst.operands[1].postind
11415 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11416 && opcode <= 0xffff
11417 && inst.size_req != 4)
c19d1205 11418 {
0110f2b8
PB
11419 /* Insn may have a 16-bit form. */
11420 Rn = inst.operands[1].reg;
11421 if (inst.operands[1].immisreg)
11422 {
11423 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11424 /* [Rn, Rik] */
0110f2b8
PB
11425 if (Rn <= 7 && inst.operands[1].imm <= 7)
11426 goto op16;
5be8be5d
DG
11427 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11428 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11429 }
11430 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11431 && opcode != T_MNEM_ldrsb)
11432 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11433 || (Rn == REG_SP && opcode == T_MNEM_str))
11434 {
11435 /* [Rn, #const] */
11436 if (Rn > 7)
11437 {
11438 if (Rn == REG_PC)
11439 {
11440 if (inst.reloc.pc_rel)
11441 opcode = T_MNEM_ldr_pc2;
11442 else
11443 opcode = T_MNEM_ldr_pc;
11444 }
11445 else
11446 {
11447 if (opcode == T_MNEM_ldr)
11448 opcode = T_MNEM_ldr_sp;
11449 else
11450 opcode = T_MNEM_str_sp;
11451 }
11452 inst.instruction = inst.operands[0].reg << 8;
11453 }
11454 else
11455 {
11456 inst.instruction = inst.operands[0].reg;
11457 inst.instruction |= inst.operands[1].reg << 3;
11458 }
11459 inst.instruction |= THUMB_OP16 (opcode);
11460 if (inst.size_req == 2)
11461 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11462 else
11463 inst.relax = opcode;
11464 return;
11465 }
c19d1205 11466 }
0110f2b8 11467 /* Definitely a 32-bit variant. */
5be8be5d 11468
8d67f500
NC
11469 /* Warning for Erratum 752419. */
11470 if (opcode == T_MNEM_ldr
11471 && inst.operands[0].reg == REG_SP
11472 && inst.operands[1].writeback == 1
11473 && !inst.operands[1].immisreg)
11474 {
11475 if (no_cpu_selected ()
11476 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11477 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11478 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11479 as_warn (_("This instruction may be unpredictable "
11480 "if executed on M-profile cores "
11481 "with interrupts enabled."));
11482 }
11483
5be8be5d 11484 /* Do some validations regarding addressing modes. */
1be5fd2e 11485 if (inst.operands[1].immisreg)
5be8be5d
DG
11486 reject_bad_reg (inst.operands[1].imm);
11487
1be5fd2e
NC
11488 constraint (inst.operands[1].writeback == 1
11489 && inst.operands[0].reg == inst.operands[1].reg,
11490 BAD_OVERLAP);
11491
0110f2b8 11492 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11493 inst.instruction |= inst.operands[0].reg << 12;
11494 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11495 check_ldr_r15_aligned ();
b99bd4ef
NC
11496 return;
11497 }
11498
c19d1205
ZW
11499 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11500
11501 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11502 {
c19d1205
ZW
11503 /* Only [Rn,Rm] is acceptable. */
11504 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11505 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11506 || inst.operands[1].postind || inst.operands[1].shifted
11507 || inst.operands[1].negative,
11508 _("Thumb does not support this addressing mode"));
11509 inst.instruction = THUMB_OP16 (inst.instruction);
11510 goto op16;
b99bd4ef 11511 }
5f4273c7 11512
c19d1205
ZW
11513 inst.instruction = THUMB_OP16 (inst.instruction);
11514 if (!inst.operands[1].isreg)
8335d6aa 11515 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11516 return;
b99bd4ef 11517
c19d1205
ZW
11518 constraint (!inst.operands[1].preind
11519 || inst.operands[1].shifted
11520 || inst.operands[1].writeback,
11521 _("Thumb does not support this addressing mode"));
11522 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11523 {
c19d1205
ZW
11524 constraint (inst.instruction & 0x0600,
11525 _("byte or halfword not valid for base register"));
11526 constraint (inst.operands[1].reg == REG_PC
11527 && !(inst.instruction & THUMB_LOAD_BIT),
11528 _("r15 based store not allowed"));
11529 constraint (inst.operands[1].immisreg,
11530 _("invalid base register for register offset"));
b99bd4ef 11531
c19d1205
ZW
11532 if (inst.operands[1].reg == REG_PC)
11533 inst.instruction = T_OPCODE_LDR_PC;
11534 else if (inst.instruction & THUMB_LOAD_BIT)
11535 inst.instruction = T_OPCODE_LDR_SP;
11536 else
11537 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11538
c19d1205
ZW
11539 inst.instruction |= inst.operands[0].reg << 8;
11540 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11541 return;
11542 }
90e4755a 11543
c19d1205
ZW
11544 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11545 if (!inst.operands[1].immisreg)
11546 {
11547 /* Immediate offset. */
11548 inst.instruction |= inst.operands[0].reg;
11549 inst.instruction |= inst.operands[1].reg << 3;
11550 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11551 return;
11552 }
90e4755a 11553
c19d1205
ZW
11554 /* Register offset. */
11555 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11556 constraint (inst.operands[1].negative,
11557 _("Thumb does not support this addressing mode"));
90e4755a 11558
c19d1205
ZW
11559 op16:
11560 switch (inst.instruction)
11561 {
11562 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11563 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11564 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11565 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11566 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11567 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11568 case 0x5600 /* ldrsb */:
11569 case 0x5e00 /* ldrsh */: break;
11570 default: abort ();
11571 }
90e4755a 11572
c19d1205
ZW
11573 inst.instruction |= inst.operands[0].reg;
11574 inst.instruction |= inst.operands[1].reg << 3;
11575 inst.instruction |= inst.operands[1].imm << 6;
11576}
90e4755a 11577
c19d1205
ZW
11578static void
11579do_t_ldstd (void)
11580{
11581 if (!inst.operands[1].present)
b99bd4ef 11582 {
c19d1205
ZW
11583 inst.operands[1].reg = inst.operands[0].reg + 1;
11584 constraint (inst.operands[0].reg == REG_LR,
11585 _("r14 not allowed here"));
bd340a04 11586 constraint (inst.operands[0].reg == REG_R12,
477330fc 11587 _("r12 not allowed here"));
b99bd4ef 11588 }
bd340a04
MGD
11589
11590 if (inst.operands[2].writeback
11591 && (inst.operands[0].reg == inst.operands[2].reg
11592 || inst.operands[1].reg == inst.operands[2].reg))
11593 as_warn (_("base register written back, and overlaps "
477330fc 11594 "one of transfer registers"));
bd340a04 11595
c19d1205
ZW
11596 inst.instruction |= inst.operands[0].reg << 12;
11597 inst.instruction |= inst.operands[1].reg << 8;
11598 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11599}
11600
c19d1205
ZW
11601static void
11602do_t_ldstt (void)
11603{
11604 inst.instruction |= inst.operands[0].reg << 12;
11605 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11606}
a737bd4d 11607
b99bd4ef 11608static void
c19d1205 11609do_t_mla (void)
b99bd4ef 11610{
fdfde340 11611 unsigned Rd, Rn, Rm, Ra;
c921be7d 11612
fdfde340
JM
11613 Rd = inst.operands[0].reg;
11614 Rn = inst.operands[1].reg;
11615 Rm = inst.operands[2].reg;
11616 Ra = inst.operands[3].reg;
11617
11618 reject_bad_reg (Rd);
11619 reject_bad_reg (Rn);
11620 reject_bad_reg (Rm);
11621 reject_bad_reg (Ra);
11622
11623 inst.instruction |= Rd << 8;
11624 inst.instruction |= Rn << 16;
11625 inst.instruction |= Rm;
11626 inst.instruction |= Ra << 12;
c19d1205 11627}
b99bd4ef 11628
c19d1205
ZW
11629static void
11630do_t_mlal (void)
11631{
fdfde340
JM
11632 unsigned RdLo, RdHi, Rn, Rm;
11633
11634 RdLo = inst.operands[0].reg;
11635 RdHi = inst.operands[1].reg;
11636 Rn = inst.operands[2].reg;
11637 Rm = inst.operands[3].reg;
11638
11639 reject_bad_reg (RdLo);
11640 reject_bad_reg (RdHi);
11641 reject_bad_reg (Rn);
11642 reject_bad_reg (Rm);
11643
11644 inst.instruction |= RdLo << 12;
11645 inst.instruction |= RdHi << 8;
11646 inst.instruction |= Rn << 16;
11647 inst.instruction |= Rm;
c19d1205 11648}
b99bd4ef 11649
c19d1205
ZW
11650static void
11651do_t_mov_cmp (void)
11652{
fdfde340
JM
11653 unsigned Rn, Rm;
11654
11655 Rn = inst.operands[0].reg;
11656 Rm = inst.operands[1].reg;
11657
e07e6e58
NC
11658 if (Rn == REG_PC)
11659 set_it_insn_type_last ();
11660
c19d1205 11661 if (unified_syntax)
b99bd4ef 11662 {
c19d1205
ZW
11663 int r0off = (inst.instruction == T_MNEM_mov
11664 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11665 unsigned long opcode;
3d388997
PB
11666 bfd_boolean narrow;
11667 bfd_boolean low_regs;
11668
fdfde340 11669 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11670 opcode = inst.instruction;
e07e6e58 11671 if (in_it_block ())
0110f2b8 11672 narrow = opcode != T_MNEM_movs;
3d388997 11673 else
0110f2b8 11674 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11675 if (inst.size_req == 4
11676 || inst.operands[1].shifted)
11677 narrow = FALSE;
11678
efd81785
PB
11679 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11680 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11681 && !inst.operands[1].shifted
fdfde340
JM
11682 && Rn == REG_PC
11683 && Rm == REG_LR)
efd81785
PB
11684 {
11685 inst.instruction = T2_SUBS_PC_LR;
11686 return;
11687 }
11688
fdfde340
JM
11689 if (opcode == T_MNEM_cmp)
11690 {
11691 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11692 if (narrow)
11693 {
11694 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11695 but valid. */
11696 warn_deprecated_sp (Rm);
11697 /* R15 was documented as a valid choice for Rm in ARMv6,
11698 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11699 tools reject R15, so we do too. */
11700 constraint (Rm == REG_PC, BAD_PC);
11701 }
11702 else
11703 reject_bad_reg (Rm);
fdfde340
JM
11704 }
11705 else if (opcode == T_MNEM_mov
11706 || opcode == T_MNEM_movs)
11707 {
11708 if (inst.operands[1].isreg)
11709 {
11710 if (opcode == T_MNEM_movs)
11711 {
11712 reject_bad_reg (Rn);
11713 reject_bad_reg (Rm);
11714 }
76fa04a4
MGD
11715 else if (narrow)
11716 {
11717 /* This is mov.n. */
11718 if ((Rn == REG_SP || Rn == REG_PC)
11719 && (Rm == REG_SP || Rm == REG_PC))
11720 {
5c3696f8 11721 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11722 "deprecated when r%u is the destination "
11723 "register."), Rm, Rn);
11724 }
11725 }
11726 else
11727 {
11728 /* This is mov.w. */
11729 constraint (Rn == REG_PC, BAD_PC);
11730 constraint (Rm == REG_PC, BAD_PC);
11731 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11732 }
fdfde340
JM
11733 }
11734 else
11735 reject_bad_reg (Rn);
11736 }
11737
c19d1205
ZW
11738 if (!inst.operands[1].isreg)
11739 {
0110f2b8 11740 /* Immediate operand. */
e07e6e58 11741 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11742 narrow = 0;
11743 if (low_regs && narrow)
11744 {
11745 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11746 inst.instruction |= Rn << 8;
0110f2b8
PB
11747 if (inst.size_req == 2)
11748 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11749 else
11750 inst.relax = opcode;
11751 }
11752 else
11753 {
11754 inst.instruction = THUMB_OP32 (inst.instruction);
11755 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11756 inst.instruction |= Rn << r0off;
0110f2b8
PB
11757 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11758 }
c19d1205 11759 }
728ca7c9
PB
11760 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11761 && (inst.instruction == T_MNEM_mov
11762 || inst.instruction == T_MNEM_movs))
11763 {
11764 /* Register shifts are encoded as separate shift instructions. */
11765 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11766
e07e6e58 11767 if (in_it_block ())
728ca7c9
PB
11768 narrow = !flags;
11769 else
11770 narrow = flags;
11771
11772 if (inst.size_req == 4)
11773 narrow = FALSE;
11774
11775 if (!low_regs || inst.operands[1].imm > 7)
11776 narrow = FALSE;
11777
fdfde340 11778 if (Rn != Rm)
728ca7c9
PB
11779 narrow = FALSE;
11780
11781 switch (inst.operands[1].shift_kind)
11782 {
11783 case SHIFT_LSL:
11784 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11785 break;
11786 case SHIFT_ASR:
11787 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11788 break;
11789 case SHIFT_LSR:
11790 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11791 break;
11792 case SHIFT_ROR:
11793 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11794 break;
11795 default:
5f4273c7 11796 abort ();
728ca7c9
PB
11797 }
11798
11799 inst.instruction = opcode;
11800 if (narrow)
11801 {
fdfde340 11802 inst.instruction |= Rn;
728ca7c9
PB
11803 inst.instruction |= inst.operands[1].imm << 3;
11804 }
11805 else
11806 {
11807 if (flags)
11808 inst.instruction |= CONDS_BIT;
11809
fdfde340
JM
11810 inst.instruction |= Rn << 8;
11811 inst.instruction |= Rm << 16;
728ca7c9
PB
11812 inst.instruction |= inst.operands[1].imm;
11813 }
11814 }
3d388997 11815 else if (!narrow)
c19d1205 11816 {
728ca7c9
PB
11817 /* Some mov with immediate shift have narrow variants.
11818 Register shifts are handled above. */
11819 if (low_regs && inst.operands[1].shifted
11820 && (inst.instruction == T_MNEM_mov
11821 || inst.instruction == T_MNEM_movs))
11822 {
e07e6e58 11823 if (in_it_block ())
728ca7c9
PB
11824 narrow = (inst.instruction == T_MNEM_mov);
11825 else
11826 narrow = (inst.instruction == T_MNEM_movs);
11827 }
11828
11829 if (narrow)
11830 {
11831 switch (inst.operands[1].shift_kind)
11832 {
11833 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11834 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11835 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11836 default: narrow = FALSE; break;
11837 }
11838 }
11839
11840 if (narrow)
11841 {
fdfde340
JM
11842 inst.instruction |= Rn;
11843 inst.instruction |= Rm << 3;
728ca7c9
PB
11844 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11845 }
11846 else
11847 {
11848 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11849 inst.instruction |= Rn << r0off;
728ca7c9
PB
11850 encode_thumb32_shifted_operand (1);
11851 }
c19d1205
ZW
11852 }
11853 else
11854 switch (inst.instruction)
11855 {
11856 case T_MNEM_mov:
837b3435 11857 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11858 results. Don't allow this. */
11859 if (low_regs)
11860 {
11861 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11862 "MOV Rd, Rs with two low registers is not "
11863 "permitted on this architecture");
fa94de6b 11864 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11865 arm_ext_v6);
11866 }
11867
c19d1205 11868 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11869 inst.instruction |= (Rn & 0x8) << 4;
11870 inst.instruction |= (Rn & 0x7);
11871 inst.instruction |= Rm << 3;
c19d1205 11872 break;
b99bd4ef 11873
c19d1205
ZW
11874 case T_MNEM_movs:
11875 /* We know we have low registers at this point.
941a8a52
MGD
11876 Generate LSLS Rd, Rs, #0. */
11877 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11878 inst.instruction |= Rn;
11879 inst.instruction |= Rm << 3;
c19d1205
ZW
11880 break;
11881
11882 case T_MNEM_cmp:
3d388997 11883 if (low_regs)
c19d1205
ZW
11884 {
11885 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11886 inst.instruction |= Rn;
11887 inst.instruction |= Rm << 3;
c19d1205
ZW
11888 }
11889 else
11890 {
11891 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11892 inst.instruction |= (Rn & 0x8) << 4;
11893 inst.instruction |= (Rn & 0x7);
11894 inst.instruction |= Rm << 3;
c19d1205
ZW
11895 }
11896 break;
11897 }
b99bd4ef
NC
11898 return;
11899 }
11900
c19d1205 11901 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11902
11903 /* PR 10443: Do not silently ignore shifted operands. */
11904 constraint (inst.operands[1].shifted,
11905 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11906
c19d1205 11907 if (inst.operands[1].isreg)
b99bd4ef 11908 {
fdfde340 11909 if (Rn < 8 && Rm < 8)
b99bd4ef 11910 {
c19d1205
ZW
11911 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11912 since a MOV instruction produces unpredictable results. */
11913 if (inst.instruction == T_OPCODE_MOV_I8)
11914 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11915 else
c19d1205 11916 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11917
fdfde340
JM
11918 inst.instruction |= Rn;
11919 inst.instruction |= Rm << 3;
b99bd4ef
NC
11920 }
11921 else
11922 {
c19d1205
ZW
11923 if (inst.instruction == T_OPCODE_MOV_I8)
11924 inst.instruction = T_OPCODE_MOV_HR;
11925 else
11926 inst.instruction = T_OPCODE_CMP_HR;
11927 do_t_cpy ();
b99bd4ef
NC
11928 }
11929 }
c19d1205 11930 else
b99bd4ef 11931 {
fdfde340 11932 constraint (Rn > 7,
c19d1205 11933 _("only lo regs allowed with immediate"));
fdfde340 11934 inst.instruction |= Rn << 8;
c19d1205
ZW
11935 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11936 }
11937}
b99bd4ef 11938
c19d1205
ZW
11939static void
11940do_t_mov16 (void)
11941{
fdfde340 11942 unsigned Rd;
b6895b4f
PB
11943 bfd_vma imm;
11944 bfd_boolean top;
11945
11946 top = (inst.instruction & 0x00800000) != 0;
11947 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11948 {
11949 constraint (top, _(":lower16: not allowed this instruction"));
11950 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11951 }
11952 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11953 {
11954 constraint (!top, _(":upper16: not allowed this instruction"));
11955 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11956 }
11957
fdfde340
JM
11958 Rd = inst.operands[0].reg;
11959 reject_bad_reg (Rd);
11960
11961 inst.instruction |= Rd << 8;
b6895b4f
PB
11962 if (inst.reloc.type == BFD_RELOC_UNUSED)
11963 {
11964 imm = inst.reloc.exp.X_add_number;
11965 inst.instruction |= (imm & 0xf000) << 4;
11966 inst.instruction |= (imm & 0x0800) << 15;
11967 inst.instruction |= (imm & 0x0700) << 4;
11968 inst.instruction |= (imm & 0x00ff);
11969 }
c19d1205 11970}
b99bd4ef 11971
c19d1205
ZW
11972static void
11973do_t_mvn_tst (void)
11974{
fdfde340 11975 unsigned Rn, Rm;
c921be7d 11976
fdfde340
JM
11977 Rn = inst.operands[0].reg;
11978 Rm = inst.operands[1].reg;
11979
11980 if (inst.instruction == T_MNEM_cmp
11981 || inst.instruction == T_MNEM_cmn)
11982 constraint (Rn == REG_PC, BAD_PC);
11983 else
11984 reject_bad_reg (Rn);
11985 reject_bad_reg (Rm);
11986
c19d1205
ZW
11987 if (unified_syntax)
11988 {
11989 int r0off = (inst.instruction == T_MNEM_mvn
11990 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11991 bfd_boolean narrow;
11992
11993 if (inst.size_req == 4
11994 || inst.instruction > 0xffff
11995 || inst.operands[1].shifted
fdfde340 11996 || Rn > 7 || Rm > 7)
3d388997 11997 narrow = FALSE;
fe8b4cc3
KT
11998 else if (inst.instruction == T_MNEM_cmn
11999 || inst.instruction == T_MNEM_tst)
3d388997
PB
12000 narrow = TRUE;
12001 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12002 narrow = !in_it_block ();
3d388997 12003 else
e07e6e58 12004 narrow = in_it_block ();
3d388997 12005
c19d1205 12006 if (!inst.operands[1].isreg)
b99bd4ef 12007 {
c19d1205
ZW
12008 /* For an immediate, we always generate a 32-bit opcode;
12009 section relaxation will shrink it later if possible. */
12010 if (inst.instruction < 0xffff)
12011 inst.instruction = THUMB_OP32 (inst.instruction);
12012 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12013 inst.instruction |= Rn << r0off;
c19d1205 12014 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12015 }
c19d1205 12016 else
b99bd4ef 12017 {
c19d1205 12018 /* See if we can do this with a 16-bit instruction. */
3d388997 12019 if (narrow)
b99bd4ef 12020 {
c19d1205 12021 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12022 inst.instruction |= Rn;
12023 inst.instruction |= Rm << 3;
b99bd4ef 12024 }
c19d1205 12025 else
b99bd4ef 12026 {
c19d1205
ZW
12027 constraint (inst.operands[1].shifted
12028 && inst.operands[1].immisreg,
12029 _("shift must be constant"));
12030 if (inst.instruction < 0xffff)
12031 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12032 inst.instruction |= Rn << r0off;
c19d1205 12033 encode_thumb32_shifted_operand (1);
b99bd4ef 12034 }
b99bd4ef
NC
12035 }
12036 }
12037 else
12038 {
c19d1205
ZW
12039 constraint (inst.instruction > 0xffff
12040 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12041 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12042 _("unshifted register required"));
fdfde340 12043 constraint (Rn > 7 || Rm > 7,
c19d1205 12044 BAD_HIREG);
b99bd4ef 12045
c19d1205 12046 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12047 inst.instruction |= Rn;
12048 inst.instruction |= Rm << 3;
b99bd4ef 12049 }
b99bd4ef
NC
12050}
12051
b05fe5cf 12052static void
c19d1205 12053do_t_mrs (void)
b05fe5cf 12054{
fdfde340 12055 unsigned Rd;
037e8744
JB
12056
12057 if (do_vfp_nsyn_mrs () == SUCCESS)
12058 return;
12059
90ec0d68
MGD
12060 Rd = inst.operands[0].reg;
12061 reject_bad_reg (Rd);
12062 inst.instruction |= Rd << 8;
12063
12064 if (inst.operands[1].isreg)
62b3e311 12065 {
90ec0d68
MGD
12066 unsigned br = inst.operands[1].reg;
12067 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12068 as_bad (_("bad register for mrs"));
12069
12070 inst.instruction |= br & (0xf << 16);
12071 inst.instruction |= (br & 0x300) >> 4;
12072 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12073 }
12074 else
12075 {
90ec0d68 12076 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12077
d2cd1205 12078 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12079 {
12080 /* PR gas/12698: The constraint is only applied for m_profile.
12081 If the user has specified -march=all, we want to ignore it as
12082 we are building for any CPU type, including non-m variants. */
823d2571
TG
12083 bfd_boolean m_profile =
12084 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12085 constraint ((flags != 0) && m_profile, _("selected processor does "
12086 "not support requested special purpose register"));
12087 }
90ec0d68 12088 else
d2cd1205
JB
12089 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12090 devices). */
12091 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12092 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12093
90ec0d68
MGD
12094 inst.instruction |= (flags & SPSR_BIT) >> 2;
12095 inst.instruction |= inst.operands[1].imm & 0xff;
12096 inst.instruction |= 0xf0000;
12097 }
c19d1205 12098}
b05fe5cf 12099
c19d1205
ZW
12100static void
12101do_t_msr (void)
12102{
62b3e311 12103 int flags;
fdfde340 12104 unsigned Rn;
62b3e311 12105
037e8744
JB
12106 if (do_vfp_nsyn_msr () == SUCCESS)
12107 return;
12108
c19d1205
ZW
12109 constraint (!inst.operands[1].isreg,
12110 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12111
12112 if (inst.operands[0].isreg)
12113 flags = (int)(inst.operands[0].reg);
12114 else
12115 flags = inst.operands[0].imm;
12116
d2cd1205 12117 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12118 {
d2cd1205
JB
12119 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12120
1a43faaf 12121 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12122 If the user has specified -march=all, we want to ignore it as
12123 we are building for any CPU type, including non-m variants. */
823d2571
TG
12124 bfd_boolean m_profile =
12125 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12126 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12127 && (bits & ~(PSR_s | PSR_f)) != 0)
12128 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12129 && bits != PSR_f)) && m_profile,
12130 _("selected processor does not support requested special "
12131 "purpose register"));
62b3e311
PB
12132 }
12133 else
d2cd1205
JB
12134 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12135 "requested special purpose register"));
c921be7d 12136
fdfde340
JM
12137 Rn = inst.operands[1].reg;
12138 reject_bad_reg (Rn);
12139
62b3e311 12140 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12141 inst.instruction |= (flags & 0xf0000) >> 8;
12142 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12143 inst.instruction |= (flags & 0xff);
fdfde340 12144 inst.instruction |= Rn << 16;
c19d1205 12145}
b05fe5cf 12146
c19d1205
ZW
12147static void
12148do_t_mul (void)
12149{
17828f45 12150 bfd_boolean narrow;
fdfde340 12151 unsigned Rd, Rn, Rm;
17828f45 12152
c19d1205
ZW
12153 if (!inst.operands[2].present)
12154 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12155
fdfde340
JM
12156 Rd = inst.operands[0].reg;
12157 Rn = inst.operands[1].reg;
12158 Rm = inst.operands[2].reg;
12159
17828f45 12160 if (unified_syntax)
b05fe5cf 12161 {
17828f45 12162 if (inst.size_req == 4
fdfde340
JM
12163 || (Rd != Rn
12164 && Rd != Rm)
12165 || Rn > 7
12166 || Rm > 7)
17828f45
JM
12167 narrow = FALSE;
12168 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12169 narrow = !in_it_block ();
17828f45 12170 else
e07e6e58 12171 narrow = in_it_block ();
b05fe5cf 12172 }
c19d1205 12173 else
b05fe5cf 12174 {
17828f45 12175 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12176 constraint (Rn > 7 || Rm > 7,
c19d1205 12177 BAD_HIREG);
17828f45
JM
12178 narrow = TRUE;
12179 }
b05fe5cf 12180
17828f45
JM
12181 if (narrow)
12182 {
12183 /* 16-bit MULS/Conditional MUL. */
c19d1205 12184 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12185 inst.instruction |= Rd;
b05fe5cf 12186
fdfde340
JM
12187 if (Rd == Rn)
12188 inst.instruction |= Rm << 3;
12189 else if (Rd == Rm)
12190 inst.instruction |= Rn << 3;
c19d1205
ZW
12191 else
12192 constraint (1, _("dest must overlap one source register"));
12193 }
17828f45
JM
12194 else
12195 {
e07e6e58
NC
12196 constraint (inst.instruction != T_MNEM_mul,
12197 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12198 /* 32-bit MUL. */
12199 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12200 inst.instruction |= Rd << 8;
12201 inst.instruction |= Rn << 16;
12202 inst.instruction |= Rm << 0;
12203
12204 reject_bad_reg (Rd);
12205 reject_bad_reg (Rn);
12206 reject_bad_reg (Rm);
17828f45 12207 }
c19d1205 12208}
b05fe5cf 12209
c19d1205
ZW
12210static void
12211do_t_mull (void)
12212{
fdfde340 12213 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12214
fdfde340
JM
12215 RdLo = inst.operands[0].reg;
12216 RdHi = inst.operands[1].reg;
12217 Rn = inst.operands[2].reg;
12218 Rm = inst.operands[3].reg;
12219
12220 reject_bad_reg (RdLo);
12221 reject_bad_reg (RdHi);
12222 reject_bad_reg (Rn);
12223 reject_bad_reg (Rm);
12224
12225 inst.instruction |= RdLo << 12;
12226 inst.instruction |= RdHi << 8;
12227 inst.instruction |= Rn << 16;
12228 inst.instruction |= Rm;
12229
12230 if (RdLo == RdHi)
c19d1205
ZW
12231 as_tsktsk (_("rdhi and rdlo must be different"));
12232}
b05fe5cf 12233
c19d1205
ZW
12234static void
12235do_t_nop (void)
12236{
e07e6e58
NC
12237 set_it_insn_type (NEUTRAL_IT_INSN);
12238
c19d1205
ZW
12239 if (unified_syntax)
12240 {
12241 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12242 {
c19d1205
ZW
12243 inst.instruction = THUMB_OP32 (inst.instruction);
12244 inst.instruction |= inst.operands[0].imm;
12245 }
12246 else
12247 {
bc2d1808
NC
12248 /* PR9722: Check for Thumb2 availability before
12249 generating a thumb2 nop instruction. */
afa62d5e 12250 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12251 {
12252 inst.instruction = THUMB_OP16 (inst.instruction);
12253 inst.instruction |= inst.operands[0].imm << 4;
12254 }
12255 else
12256 inst.instruction = 0x46c0;
c19d1205
ZW
12257 }
12258 }
12259 else
12260 {
12261 constraint (inst.operands[0].present,
12262 _("Thumb does not support NOP with hints"));
12263 inst.instruction = 0x46c0;
12264 }
12265}
b05fe5cf 12266
c19d1205
ZW
12267static void
12268do_t_neg (void)
12269{
12270 if (unified_syntax)
12271 {
3d388997
PB
12272 bfd_boolean narrow;
12273
12274 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12275 narrow = !in_it_block ();
3d388997 12276 else
e07e6e58 12277 narrow = in_it_block ();
3d388997
PB
12278 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12279 narrow = FALSE;
12280 if (inst.size_req == 4)
12281 narrow = FALSE;
12282
12283 if (!narrow)
c19d1205
ZW
12284 {
12285 inst.instruction = THUMB_OP32 (inst.instruction);
12286 inst.instruction |= inst.operands[0].reg << 8;
12287 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12288 }
12289 else
12290 {
c19d1205
ZW
12291 inst.instruction = THUMB_OP16 (inst.instruction);
12292 inst.instruction |= inst.operands[0].reg;
12293 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12294 }
12295 }
12296 else
12297 {
c19d1205
ZW
12298 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12299 BAD_HIREG);
12300 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12301
12302 inst.instruction = THUMB_OP16 (inst.instruction);
12303 inst.instruction |= inst.operands[0].reg;
12304 inst.instruction |= inst.operands[1].reg << 3;
12305 }
12306}
12307
1c444d06
JM
12308static void
12309do_t_orn (void)
12310{
12311 unsigned Rd, Rn;
12312
12313 Rd = inst.operands[0].reg;
12314 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12315
fdfde340
JM
12316 reject_bad_reg (Rd);
12317 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12318 reject_bad_reg (Rn);
12319
1c444d06
JM
12320 inst.instruction |= Rd << 8;
12321 inst.instruction |= Rn << 16;
12322
12323 if (!inst.operands[2].isreg)
12324 {
12325 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12326 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12327 }
12328 else
12329 {
12330 unsigned Rm;
12331
12332 Rm = inst.operands[2].reg;
fdfde340 12333 reject_bad_reg (Rm);
1c444d06
JM
12334
12335 constraint (inst.operands[2].shifted
12336 && inst.operands[2].immisreg,
12337 _("shift must be constant"));
12338 encode_thumb32_shifted_operand (2);
12339 }
12340}
12341
c19d1205
ZW
12342static void
12343do_t_pkhbt (void)
12344{
fdfde340
JM
12345 unsigned Rd, Rn, Rm;
12346
12347 Rd = inst.operands[0].reg;
12348 Rn = inst.operands[1].reg;
12349 Rm = inst.operands[2].reg;
12350
12351 reject_bad_reg (Rd);
12352 reject_bad_reg (Rn);
12353 reject_bad_reg (Rm);
12354
12355 inst.instruction |= Rd << 8;
12356 inst.instruction |= Rn << 16;
12357 inst.instruction |= Rm;
c19d1205
ZW
12358 if (inst.operands[3].present)
12359 {
12360 unsigned int val = inst.reloc.exp.X_add_number;
12361 constraint (inst.reloc.exp.X_op != O_constant,
12362 _("expression too complex"));
12363 inst.instruction |= (val & 0x1c) << 10;
12364 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12365 }
c19d1205 12366}
b05fe5cf 12367
c19d1205
ZW
12368static void
12369do_t_pkhtb (void)
12370{
12371 if (!inst.operands[3].present)
1ef52f49
NC
12372 {
12373 unsigned Rtmp;
12374
12375 inst.instruction &= ~0x00000020;
12376
12377 /* PR 10168. Swap the Rm and Rn registers. */
12378 Rtmp = inst.operands[1].reg;
12379 inst.operands[1].reg = inst.operands[2].reg;
12380 inst.operands[2].reg = Rtmp;
12381 }
c19d1205 12382 do_t_pkhbt ();
b05fe5cf
ZW
12383}
12384
c19d1205
ZW
12385static void
12386do_t_pld (void)
12387{
fdfde340
JM
12388 if (inst.operands[0].immisreg)
12389 reject_bad_reg (inst.operands[0].imm);
12390
c19d1205
ZW
12391 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12392}
b05fe5cf 12393
c19d1205
ZW
12394static void
12395do_t_push_pop (void)
b99bd4ef 12396{
e9f89963 12397 unsigned mask;
5f4273c7 12398
c19d1205
ZW
12399 constraint (inst.operands[0].writeback,
12400 _("push/pop do not support {reglist}^"));
12401 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12402 _("expression too complex"));
b99bd4ef 12403
e9f89963 12404 mask = inst.operands[0].imm;
d3bfe16e 12405 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12406 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12407 else if (inst.size_req != 4
12408 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12409 ? REG_LR : REG_PC)))
b99bd4ef 12410 {
c19d1205
ZW
12411 inst.instruction = THUMB_OP16 (inst.instruction);
12412 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12413 inst.instruction |= mask & 0xff;
c19d1205
ZW
12414 }
12415 else if (unified_syntax)
12416 {
3c707909 12417 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12418 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12419 }
12420 else
12421 {
12422 inst.error = _("invalid register list to push/pop instruction");
12423 return;
12424 }
c19d1205 12425}
b99bd4ef 12426
c19d1205
ZW
12427static void
12428do_t_rbit (void)
12429{
fdfde340
JM
12430 unsigned Rd, Rm;
12431
12432 Rd = inst.operands[0].reg;
12433 Rm = inst.operands[1].reg;
12434
12435 reject_bad_reg (Rd);
12436 reject_bad_reg (Rm);
12437
12438 inst.instruction |= Rd << 8;
12439 inst.instruction |= Rm << 16;
12440 inst.instruction |= Rm;
c19d1205 12441}
b99bd4ef 12442
c19d1205
ZW
12443static void
12444do_t_rev (void)
12445{
fdfde340
JM
12446 unsigned Rd, Rm;
12447
12448 Rd = inst.operands[0].reg;
12449 Rm = inst.operands[1].reg;
12450
12451 reject_bad_reg (Rd);
12452 reject_bad_reg (Rm);
12453
12454 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12455 && inst.size_req != 4)
12456 {
12457 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12458 inst.instruction |= Rd;
12459 inst.instruction |= Rm << 3;
c19d1205
ZW
12460 }
12461 else if (unified_syntax)
12462 {
12463 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12464 inst.instruction |= Rd << 8;
12465 inst.instruction |= Rm << 16;
12466 inst.instruction |= Rm;
c19d1205
ZW
12467 }
12468 else
12469 inst.error = BAD_HIREG;
12470}
b99bd4ef 12471
1c444d06
JM
12472static void
12473do_t_rrx (void)
12474{
12475 unsigned Rd, Rm;
12476
12477 Rd = inst.operands[0].reg;
12478 Rm = inst.operands[1].reg;
12479
fdfde340
JM
12480 reject_bad_reg (Rd);
12481 reject_bad_reg (Rm);
c921be7d 12482
1c444d06
JM
12483 inst.instruction |= Rd << 8;
12484 inst.instruction |= Rm;
12485}
12486
c19d1205
ZW
12487static void
12488do_t_rsb (void)
12489{
fdfde340 12490 unsigned Rd, Rs;
b99bd4ef 12491
c19d1205
ZW
12492 Rd = inst.operands[0].reg;
12493 Rs = (inst.operands[1].present
12494 ? inst.operands[1].reg /* Rd, Rs, foo */
12495 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12496
fdfde340
JM
12497 reject_bad_reg (Rd);
12498 reject_bad_reg (Rs);
12499 if (inst.operands[2].isreg)
12500 reject_bad_reg (inst.operands[2].reg);
12501
c19d1205
ZW
12502 inst.instruction |= Rd << 8;
12503 inst.instruction |= Rs << 16;
12504 if (!inst.operands[2].isreg)
12505 {
026d3abb
PB
12506 bfd_boolean narrow;
12507
12508 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12509 narrow = !in_it_block ();
026d3abb 12510 else
e07e6e58 12511 narrow = in_it_block ();
026d3abb
PB
12512
12513 if (Rd > 7 || Rs > 7)
12514 narrow = FALSE;
12515
12516 if (inst.size_req == 4 || !unified_syntax)
12517 narrow = FALSE;
12518
12519 if (inst.reloc.exp.X_op != O_constant
12520 || inst.reloc.exp.X_add_number != 0)
12521 narrow = FALSE;
12522
12523 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12524 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12525 if (narrow)
12526 {
12527 inst.reloc.type = BFD_RELOC_UNUSED;
12528 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12529 inst.instruction |= Rs << 3;
12530 inst.instruction |= Rd;
12531 }
12532 else
12533 {
12534 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12535 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12536 }
c19d1205
ZW
12537 }
12538 else
12539 encode_thumb32_shifted_operand (2);
12540}
b99bd4ef 12541
c19d1205
ZW
12542static void
12543do_t_setend (void)
12544{
12e37cbc
MGD
12545 if (warn_on_deprecated
12546 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12547 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12548
e07e6e58 12549 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12550 if (inst.operands[0].imm)
12551 inst.instruction |= 0x8;
12552}
b99bd4ef 12553
c19d1205
ZW
12554static void
12555do_t_shift (void)
12556{
12557 if (!inst.operands[1].present)
12558 inst.operands[1].reg = inst.operands[0].reg;
12559
12560 if (unified_syntax)
12561 {
3d388997
PB
12562 bfd_boolean narrow;
12563 int shift_kind;
12564
12565 switch (inst.instruction)
12566 {
12567 case T_MNEM_asr:
12568 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12569 case T_MNEM_lsl:
12570 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12571 case T_MNEM_lsr:
12572 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12573 case T_MNEM_ror:
12574 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12575 default: abort ();
12576 }
12577
12578 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12579 narrow = !in_it_block ();
3d388997 12580 else
e07e6e58 12581 narrow = in_it_block ();
3d388997
PB
12582 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12583 narrow = FALSE;
12584 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12585 narrow = FALSE;
12586 if (inst.operands[2].isreg
12587 && (inst.operands[1].reg != inst.operands[0].reg
12588 || inst.operands[2].reg > 7))
12589 narrow = FALSE;
12590 if (inst.size_req == 4)
12591 narrow = FALSE;
12592
fdfde340
JM
12593 reject_bad_reg (inst.operands[0].reg);
12594 reject_bad_reg (inst.operands[1].reg);
c921be7d 12595
3d388997 12596 if (!narrow)
c19d1205
ZW
12597 {
12598 if (inst.operands[2].isreg)
b99bd4ef 12599 {
fdfde340 12600 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12601 inst.instruction = THUMB_OP32 (inst.instruction);
12602 inst.instruction |= inst.operands[0].reg << 8;
12603 inst.instruction |= inst.operands[1].reg << 16;
12604 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12605
12606 /* PR 12854: Error on extraneous shifts. */
12607 constraint (inst.operands[2].shifted,
12608 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12609 }
12610 else
12611 {
12612 inst.operands[1].shifted = 1;
3d388997 12613 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12614 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12615 ? T_MNEM_movs : T_MNEM_mov);
12616 inst.instruction |= inst.operands[0].reg << 8;
12617 encode_thumb32_shifted_operand (1);
12618 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12619 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12620 }
12621 }
12622 else
12623 {
c19d1205 12624 if (inst.operands[2].isreg)
b99bd4ef 12625 {
3d388997 12626 switch (shift_kind)
b99bd4ef 12627 {
3d388997
PB
12628 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12629 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12630 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12631 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12632 default: abort ();
b99bd4ef 12633 }
5f4273c7 12634
c19d1205
ZW
12635 inst.instruction |= inst.operands[0].reg;
12636 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12637
12638 /* PR 12854: Error on extraneous shifts. */
12639 constraint (inst.operands[2].shifted,
12640 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12641 }
12642 else
12643 {
3d388997 12644 switch (shift_kind)
b99bd4ef 12645 {
3d388997
PB
12646 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12647 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12648 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12649 default: abort ();
b99bd4ef 12650 }
c19d1205
ZW
12651 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12652 inst.instruction |= inst.operands[0].reg;
12653 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12654 }
12655 }
c19d1205
ZW
12656 }
12657 else
12658 {
12659 constraint (inst.operands[0].reg > 7
12660 || inst.operands[1].reg > 7, BAD_HIREG);
12661 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12662
c19d1205
ZW
12663 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12664 {
12665 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12666 constraint (inst.operands[0].reg != inst.operands[1].reg,
12667 _("source1 and dest must be same register"));
b99bd4ef 12668
c19d1205
ZW
12669 switch (inst.instruction)
12670 {
12671 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12672 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12673 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12674 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12675 default: abort ();
12676 }
5f4273c7 12677
c19d1205
ZW
12678 inst.instruction |= inst.operands[0].reg;
12679 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12680
12681 /* PR 12854: Error on extraneous shifts. */
12682 constraint (inst.operands[2].shifted,
12683 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12684 }
12685 else
b99bd4ef 12686 {
c19d1205
ZW
12687 switch (inst.instruction)
12688 {
12689 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12690 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12691 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12692 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12693 default: abort ();
12694 }
12695 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12696 inst.instruction |= inst.operands[0].reg;
12697 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12698 }
12699 }
b99bd4ef
NC
12700}
12701
12702static void
c19d1205 12703do_t_simd (void)
b99bd4ef 12704{
fdfde340
JM
12705 unsigned Rd, Rn, Rm;
12706
12707 Rd = inst.operands[0].reg;
12708 Rn = inst.operands[1].reg;
12709 Rm = inst.operands[2].reg;
12710
12711 reject_bad_reg (Rd);
12712 reject_bad_reg (Rn);
12713 reject_bad_reg (Rm);
12714
12715 inst.instruction |= Rd << 8;
12716 inst.instruction |= Rn << 16;
12717 inst.instruction |= Rm;
c19d1205 12718}
b99bd4ef 12719
03ee1b7f
NC
12720static void
12721do_t_simd2 (void)
12722{
12723 unsigned Rd, Rn, Rm;
12724
12725 Rd = inst.operands[0].reg;
12726 Rm = inst.operands[1].reg;
12727 Rn = inst.operands[2].reg;
12728
12729 reject_bad_reg (Rd);
12730 reject_bad_reg (Rn);
12731 reject_bad_reg (Rm);
12732
12733 inst.instruction |= Rd << 8;
12734 inst.instruction |= Rn << 16;
12735 inst.instruction |= Rm;
12736}
12737
c19d1205 12738static void
3eb17e6b 12739do_t_smc (void)
c19d1205
ZW
12740{
12741 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12742 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12743 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12744 constraint (inst.reloc.exp.X_op != O_constant,
12745 _("expression too complex"));
12746 inst.reloc.type = BFD_RELOC_UNUSED;
12747 inst.instruction |= (value & 0xf000) >> 12;
12748 inst.instruction |= (value & 0x0ff0);
12749 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12750 /* PR gas/15623: SMC instructions must be last in an IT block. */
12751 set_it_insn_type_last ();
c19d1205 12752}
b99bd4ef 12753
90ec0d68
MGD
12754static void
12755do_t_hvc (void)
12756{
12757 unsigned int value = inst.reloc.exp.X_add_number;
12758
12759 inst.reloc.type = BFD_RELOC_UNUSED;
12760 inst.instruction |= (value & 0x0fff);
12761 inst.instruction |= (value & 0xf000) << 4;
12762}
12763
c19d1205 12764static void
3a21c15a 12765do_t_ssat_usat (int bias)
c19d1205 12766{
fdfde340
JM
12767 unsigned Rd, Rn;
12768
12769 Rd = inst.operands[0].reg;
12770 Rn = inst.operands[2].reg;
12771
12772 reject_bad_reg (Rd);
12773 reject_bad_reg (Rn);
12774
12775 inst.instruction |= Rd << 8;
3a21c15a 12776 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12777 inst.instruction |= Rn << 16;
b99bd4ef 12778
c19d1205 12779 if (inst.operands[3].present)
b99bd4ef 12780 {
3a21c15a
NC
12781 offsetT shift_amount = inst.reloc.exp.X_add_number;
12782
12783 inst.reloc.type = BFD_RELOC_UNUSED;
12784
c19d1205
ZW
12785 constraint (inst.reloc.exp.X_op != O_constant,
12786 _("expression too complex"));
b99bd4ef 12787
3a21c15a 12788 if (shift_amount != 0)
6189168b 12789 {
3a21c15a
NC
12790 constraint (shift_amount > 31,
12791 _("shift expression is too large"));
12792
c19d1205 12793 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12794 inst.instruction |= 0x00200000; /* sh bit. */
12795
12796 inst.instruction |= (shift_amount & 0x1c) << 10;
12797 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12798 }
12799 }
b99bd4ef 12800}
c921be7d 12801
3a21c15a
NC
12802static void
12803do_t_ssat (void)
12804{
12805 do_t_ssat_usat (1);
12806}
b99bd4ef 12807
0dd132b6 12808static void
c19d1205 12809do_t_ssat16 (void)
0dd132b6 12810{
fdfde340
JM
12811 unsigned Rd, Rn;
12812
12813 Rd = inst.operands[0].reg;
12814 Rn = inst.operands[2].reg;
12815
12816 reject_bad_reg (Rd);
12817 reject_bad_reg (Rn);
12818
12819 inst.instruction |= Rd << 8;
c19d1205 12820 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12821 inst.instruction |= Rn << 16;
c19d1205 12822}
0dd132b6 12823
c19d1205
ZW
12824static void
12825do_t_strex (void)
12826{
12827 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12828 || inst.operands[2].postind || inst.operands[2].writeback
12829 || inst.operands[2].immisreg || inst.operands[2].shifted
12830 || inst.operands[2].negative,
01cfc07f 12831 BAD_ADDR_MODE);
0dd132b6 12832
5be8be5d
DG
12833 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12834
c19d1205
ZW
12835 inst.instruction |= inst.operands[0].reg << 8;
12836 inst.instruction |= inst.operands[1].reg << 12;
12837 inst.instruction |= inst.operands[2].reg << 16;
12838 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12839}
12840
b99bd4ef 12841static void
c19d1205 12842do_t_strexd (void)
b99bd4ef 12843{
c19d1205
ZW
12844 if (!inst.operands[2].present)
12845 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12846
c19d1205
ZW
12847 constraint (inst.operands[0].reg == inst.operands[1].reg
12848 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12849 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12850 BAD_OVERLAP);
b99bd4ef 12851
c19d1205
ZW
12852 inst.instruction |= inst.operands[0].reg;
12853 inst.instruction |= inst.operands[1].reg << 12;
12854 inst.instruction |= inst.operands[2].reg << 8;
12855 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12856}
12857
12858static void
c19d1205 12859do_t_sxtah (void)
b99bd4ef 12860{
fdfde340
JM
12861 unsigned Rd, Rn, Rm;
12862
12863 Rd = inst.operands[0].reg;
12864 Rn = inst.operands[1].reg;
12865 Rm = inst.operands[2].reg;
12866
12867 reject_bad_reg (Rd);
12868 reject_bad_reg (Rn);
12869 reject_bad_reg (Rm);
12870
12871 inst.instruction |= Rd << 8;
12872 inst.instruction |= Rn << 16;
12873 inst.instruction |= Rm;
c19d1205
ZW
12874 inst.instruction |= inst.operands[3].imm << 4;
12875}
b99bd4ef 12876
c19d1205
ZW
12877static void
12878do_t_sxth (void)
12879{
fdfde340
JM
12880 unsigned Rd, Rm;
12881
12882 Rd = inst.operands[0].reg;
12883 Rm = inst.operands[1].reg;
12884
12885 reject_bad_reg (Rd);
12886 reject_bad_reg (Rm);
c921be7d
NC
12887
12888 if (inst.instruction <= 0xffff
12889 && inst.size_req != 4
fdfde340 12890 && Rd <= 7 && Rm <= 7
c19d1205 12891 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12892 {
c19d1205 12893 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12894 inst.instruction |= Rd;
12895 inst.instruction |= Rm << 3;
b99bd4ef 12896 }
c19d1205 12897 else if (unified_syntax)
b99bd4ef 12898 {
c19d1205
ZW
12899 if (inst.instruction <= 0xffff)
12900 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12901 inst.instruction |= Rd << 8;
12902 inst.instruction |= Rm;
c19d1205 12903 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12904 }
c19d1205 12905 else
b99bd4ef 12906 {
c19d1205
ZW
12907 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12908 _("Thumb encoding does not support rotation"));
12909 constraint (1, BAD_HIREG);
b99bd4ef 12910 }
c19d1205 12911}
b99bd4ef 12912
c19d1205
ZW
12913static void
12914do_t_swi (void)
12915{
b2a5fbdc
MGD
12916 /* We have to do the following check manually as ARM_EXT_OS only applies
12917 to ARM_EXT_V6M. */
12918 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12919 {
ac7f631b
NC
12920 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12921 /* This only applies to the v6m howver, not later architectures. */
12922 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12923 as_bad (_("SVC is not permitted on this architecture"));
12924 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12925 }
12926
c19d1205
ZW
12927 inst.reloc.type = BFD_RELOC_ARM_SWI;
12928}
b99bd4ef 12929
92e90b6e
PB
12930static void
12931do_t_tb (void)
12932{
fdfde340 12933 unsigned Rn, Rm;
92e90b6e
PB
12934 int half;
12935
12936 half = (inst.instruction & 0x10) != 0;
e07e6e58 12937 set_it_insn_type_last ();
dfa9f0d5
PB
12938 constraint (inst.operands[0].immisreg,
12939 _("instruction requires register index"));
fdfde340
JM
12940
12941 Rn = inst.operands[0].reg;
12942 Rm = inst.operands[0].imm;
c921be7d 12943
fdfde340
JM
12944 constraint (Rn == REG_SP, BAD_SP);
12945 reject_bad_reg (Rm);
12946
92e90b6e
PB
12947 constraint (!half && inst.operands[0].shifted,
12948 _("instruction does not allow shifted index"));
fdfde340 12949 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12950}
12951
74db7efb
NC
12952static void
12953do_t_udf (void)
12954{
12955 if (!inst.operands[0].present)
12956 inst.operands[0].imm = 0;
12957
12958 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
12959 {
12960 constraint (inst.size_req == 2,
12961 _("immediate value out of range"));
12962 inst.instruction = THUMB_OP32 (inst.instruction);
12963 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
12964 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
12965 }
12966 else
12967 {
12968 inst.instruction = THUMB_OP16 (inst.instruction);
12969 inst.instruction |= inst.operands[0].imm;
12970 }
12971
12972 set_it_insn_type (NEUTRAL_IT_INSN);
12973}
12974
12975
c19d1205
ZW
12976static void
12977do_t_usat (void)
12978{
3a21c15a 12979 do_t_ssat_usat (0);
b99bd4ef
NC
12980}
12981
12982static void
c19d1205 12983do_t_usat16 (void)
b99bd4ef 12984{
fdfde340
JM
12985 unsigned Rd, Rn;
12986
12987 Rd = inst.operands[0].reg;
12988 Rn = inst.operands[2].reg;
12989
12990 reject_bad_reg (Rd);
12991 reject_bad_reg (Rn);
12992
12993 inst.instruction |= Rd << 8;
c19d1205 12994 inst.instruction |= inst.operands[1].imm;
fdfde340 12995 inst.instruction |= Rn << 16;
b99bd4ef 12996}
c19d1205 12997
5287ad62 12998/* Neon instruction encoder helpers. */
5f4273c7 12999
5287ad62 13000/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13001
5287ad62
JB
13002/* An "invalid" code for the following tables. */
13003#define N_INV -1u
13004
13005struct neon_tab_entry
b99bd4ef 13006{
5287ad62
JB
13007 unsigned integer;
13008 unsigned float_or_poly;
13009 unsigned scalar_or_imm;
13010};
5f4273c7 13011
5287ad62
JB
13012/* Map overloaded Neon opcodes to their respective encodings. */
13013#define NEON_ENC_TAB \
13014 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13015 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13016 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13017 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13018 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13019 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13020 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13021 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13022 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13023 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13024 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13025 /* Register variants of the following two instructions are encoded as
e07e6e58 13026 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13027 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13028 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13029 X(vfma, N_INV, 0x0000c10, N_INV), \
13030 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13031 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13032 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13033 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13034 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13035 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13036 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13037 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13038 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13039 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13040 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13041 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13042 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13043 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13044 X(vshl, 0x0000400, N_INV, 0x0800510), \
13045 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13046 X(vand, 0x0000110, N_INV, 0x0800030), \
13047 X(vbic, 0x0100110, N_INV, 0x0800030), \
13048 X(veor, 0x1000110, N_INV, N_INV), \
13049 X(vorn, 0x0300110, N_INV, 0x0800010), \
13050 X(vorr, 0x0200110, N_INV, 0x0800010), \
13051 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13052 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13053 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13054 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13055 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13056 X(vst1, 0x0000000, 0x0800000, N_INV), \
13057 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13058 X(vst2, 0x0000100, 0x0800100, N_INV), \
13059 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13060 X(vst3, 0x0000200, 0x0800200, N_INV), \
13061 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13062 X(vst4, 0x0000300, 0x0800300, N_INV), \
13063 X(vmovn, 0x1b20200, N_INV, N_INV), \
13064 X(vtrn, 0x1b20080, N_INV, N_INV), \
13065 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13066 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13067 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13068 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13069 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13070 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13071 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13072 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13073 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13074 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13075 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13076 X(vseleq, 0xe000a00, N_INV, N_INV), \
13077 X(vselvs, 0xe100a00, N_INV, N_INV), \
13078 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13079 X(vselgt, 0xe300a00, N_INV, N_INV), \
13080 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13081 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13082 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13083 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13084 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13085 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13086 X(sha3op, 0x2000c00, N_INV, N_INV), \
13087 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13088 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13089
13090enum neon_opc
13091{
13092#define X(OPC,I,F,S) N_MNEM_##OPC
13093NEON_ENC_TAB
13094#undef X
13095};
b99bd4ef 13096
5287ad62
JB
13097static const struct neon_tab_entry neon_enc_tab[] =
13098{
13099#define X(OPC,I,F,S) { (I), (F), (S) }
13100NEON_ENC_TAB
13101#undef X
13102};
b99bd4ef 13103
88714cb8
DG
13104/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13105#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13106#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13107#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13108#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13109#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13110#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13111#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13112#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13113#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13114#define NEON_ENC_SINGLE_(X) \
037e8744 13115 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13116#define NEON_ENC_DOUBLE_(X) \
037e8744 13117 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13118#define NEON_ENC_FPV8_(X) \
13119 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13120
88714cb8
DG
13121#define NEON_ENCODE(type, inst) \
13122 do \
13123 { \
13124 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13125 inst.is_neon = 1; \
13126 } \
13127 while (0)
13128
13129#define check_neon_suffixes \
13130 do \
13131 { \
13132 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13133 { \
13134 as_bad (_("invalid neon suffix for non neon instruction")); \
13135 return; \
13136 } \
13137 } \
13138 while (0)
13139
037e8744
JB
13140/* Define shapes for instruction operands. The following mnemonic characters
13141 are used in this table:
5287ad62 13142
037e8744 13143 F - VFP S<n> register
5287ad62
JB
13144 D - Neon D<n> register
13145 Q - Neon Q<n> register
13146 I - Immediate
13147 S - Scalar
13148 R - ARM register
13149 L - D<n> register list
5f4273c7 13150
037e8744
JB
13151 This table is used to generate various data:
13152 - enumerations of the form NS_DDR to be used as arguments to
13153 neon_select_shape.
13154 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13155 - a table used to drive neon_select_shape. */
b99bd4ef 13156
037e8744
JB
13157#define NEON_SHAPE_DEF \
13158 X(3, (D, D, D), DOUBLE), \
13159 X(3, (Q, Q, Q), QUAD), \
13160 X(3, (D, D, I), DOUBLE), \
13161 X(3, (Q, Q, I), QUAD), \
13162 X(3, (D, D, S), DOUBLE), \
13163 X(3, (Q, Q, S), QUAD), \
13164 X(2, (D, D), DOUBLE), \
13165 X(2, (Q, Q), QUAD), \
13166 X(2, (D, S), DOUBLE), \
13167 X(2, (Q, S), QUAD), \
13168 X(2, (D, R), DOUBLE), \
13169 X(2, (Q, R), QUAD), \
13170 X(2, (D, I), DOUBLE), \
13171 X(2, (Q, I), QUAD), \
13172 X(3, (D, L, D), DOUBLE), \
13173 X(2, (D, Q), MIXED), \
13174 X(2, (Q, D), MIXED), \
13175 X(3, (D, Q, I), MIXED), \
13176 X(3, (Q, D, I), MIXED), \
13177 X(3, (Q, D, D), MIXED), \
13178 X(3, (D, Q, Q), MIXED), \
13179 X(3, (Q, Q, D), MIXED), \
13180 X(3, (Q, D, S), MIXED), \
13181 X(3, (D, Q, S), MIXED), \
13182 X(4, (D, D, D, I), DOUBLE), \
13183 X(4, (Q, Q, Q, I), QUAD), \
13184 X(2, (F, F), SINGLE), \
13185 X(3, (F, F, F), SINGLE), \
13186 X(2, (F, I), SINGLE), \
13187 X(2, (F, D), MIXED), \
13188 X(2, (D, F), MIXED), \
13189 X(3, (F, F, I), MIXED), \
13190 X(4, (R, R, F, F), SINGLE), \
13191 X(4, (F, F, R, R), SINGLE), \
13192 X(3, (D, R, R), DOUBLE), \
13193 X(3, (R, R, D), DOUBLE), \
13194 X(2, (S, R), SINGLE), \
13195 X(2, (R, S), SINGLE), \
13196 X(2, (F, R), SINGLE), \
13197 X(2, (R, F), SINGLE)
13198
13199#define S2(A,B) NS_##A##B
13200#define S3(A,B,C) NS_##A##B##C
13201#define S4(A,B,C,D) NS_##A##B##C##D
13202
13203#define X(N, L, C) S##N L
13204
5287ad62
JB
13205enum neon_shape
13206{
037e8744
JB
13207 NEON_SHAPE_DEF,
13208 NS_NULL
5287ad62 13209};
b99bd4ef 13210
037e8744
JB
13211#undef X
13212#undef S2
13213#undef S3
13214#undef S4
13215
13216enum neon_shape_class
13217{
13218 SC_SINGLE,
13219 SC_DOUBLE,
13220 SC_QUAD,
13221 SC_MIXED
13222};
13223
13224#define X(N, L, C) SC_##C
13225
13226static enum neon_shape_class neon_shape_class[] =
13227{
13228 NEON_SHAPE_DEF
13229};
13230
13231#undef X
13232
13233enum neon_shape_el
13234{
13235 SE_F,
13236 SE_D,
13237 SE_Q,
13238 SE_I,
13239 SE_S,
13240 SE_R,
13241 SE_L
13242};
13243
13244/* Register widths of above. */
13245static unsigned neon_shape_el_size[] =
13246{
13247 32,
13248 64,
13249 128,
13250 0,
13251 32,
13252 32,
13253 0
13254};
13255
13256struct neon_shape_info
13257{
13258 unsigned els;
13259 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13260};
13261
13262#define S2(A,B) { SE_##A, SE_##B }
13263#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13264#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13265
13266#define X(N, L, C) { N, S##N L }
13267
13268static struct neon_shape_info neon_shape_tab[] =
13269{
13270 NEON_SHAPE_DEF
13271};
13272
13273#undef X
13274#undef S2
13275#undef S3
13276#undef S4
13277
5287ad62
JB
13278/* Bit masks used in type checking given instructions.
13279 'N_EQK' means the type must be the same as (or based on in some way) the key
13280 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13281 set, various other bits can be set as well in order to modify the meaning of
13282 the type constraint. */
13283
13284enum neon_type_mask
13285{
8e79c3df
CM
13286 N_S8 = 0x0000001,
13287 N_S16 = 0x0000002,
13288 N_S32 = 0x0000004,
13289 N_S64 = 0x0000008,
13290 N_U8 = 0x0000010,
13291 N_U16 = 0x0000020,
13292 N_U32 = 0x0000040,
13293 N_U64 = 0x0000080,
13294 N_I8 = 0x0000100,
13295 N_I16 = 0x0000200,
13296 N_I32 = 0x0000400,
13297 N_I64 = 0x0000800,
13298 N_8 = 0x0001000,
13299 N_16 = 0x0002000,
13300 N_32 = 0x0004000,
13301 N_64 = 0x0008000,
13302 N_P8 = 0x0010000,
13303 N_P16 = 0x0020000,
13304 N_F16 = 0x0040000,
13305 N_F32 = 0x0080000,
13306 N_F64 = 0x0100000,
4f51b4bd 13307 N_P64 = 0x0200000,
c921be7d
NC
13308 N_KEY = 0x1000000, /* Key element (main type specifier). */
13309 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13310 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13311 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13312 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13313 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13314 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13315 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13316 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13317 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13318 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13319 N_UTYP = 0,
4f51b4bd 13320 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13321};
13322
dcbf9037
JB
13323#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13324
5287ad62
JB
13325#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13326#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13327#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13328#define N_SUF_32 (N_SU_32 | N_F32)
13329#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13330#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
13331
13332/* Pass this as the first type argument to neon_check_type to ignore types
13333 altogether. */
13334#define N_IGNORE_TYPE (N_KEY | N_EQK)
13335
037e8744
JB
13336/* Select a "shape" for the current instruction (describing register types or
13337 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13338 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13339 function of operand parsing, so this function doesn't need to be called.
13340 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13341
13342static enum neon_shape
037e8744 13343neon_select_shape (enum neon_shape shape, ...)
5287ad62 13344{
037e8744
JB
13345 va_list ap;
13346 enum neon_shape first_shape = shape;
5287ad62
JB
13347
13348 /* Fix missing optional operands. FIXME: we don't know at this point how
13349 many arguments we should have, so this makes the assumption that we have
13350 > 1. This is true of all current Neon opcodes, I think, but may not be
13351 true in the future. */
13352 if (!inst.operands[1].present)
13353 inst.operands[1] = inst.operands[0];
13354
037e8744 13355 va_start (ap, shape);
5f4273c7 13356
21d799b5 13357 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13358 {
13359 unsigned j;
13360 int matches = 1;
13361
13362 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13363 {
13364 if (!inst.operands[j].present)
13365 {
13366 matches = 0;
13367 break;
13368 }
13369
13370 switch (neon_shape_tab[shape].el[j])
13371 {
13372 case SE_F:
13373 if (!(inst.operands[j].isreg
13374 && inst.operands[j].isvec
13375 && inst.operands[j].issingle
13376 && !inst.operands[j].isquad))
13377 matches = 0;
13378 break;
13379
13380 case SE_D:
13381 if (!(inst.operands[j].isreg
13382 && inst.operands[j].isvec
13383 && !inst.operands[j].isquad
13384 && !inst.operands[j].issingle))
13385 matches = 0;
13386 break;
13387
13388 case SE_R:
13389 if (!(inst.operands[j].isreg
13390 && !inst.operands[j].isvec))
13391 matches = 0;
13392 break;
13393
13394 case SE_Q:
13395 if (!(inst.operands[j].isreg
13396 && inst.operands[j].isvec
13397 && inst.operands[j].isquad
13398 && !inst.operands[j].issingle))
13399 matches = 0;
13400 break;
13401
13402 case SE_I:
13403 if (!(!inst.operands[j].isreg
13404 && !inst.operands[j].isscalar))
13405 matches = 0;
13406 break;
13407
13408 case SE_S:
13409 if (!(!inst.operands[j].isreg
13410 && inst.operands[j].isscalar))
13411 matches = 0;
13412 break;
13413
13414 case SE_L:
13415 break;
13416 }
3fde54a2
JZ
13417 if (!matches)
13418 break;
477330fc 13419 }
ad6cec43
MGD
13420 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13421 /* We've matched all the entries in the shape table, and we don't
13422 have any left over operands which have not been matched. */
477330fc 13423 break;
037e8744 13424 }
5f4273c7 13425
037e8744 13426 va_end (ap);
5287ad62 13427
037e8744
JB
13428 if (shape == NS_NULL && first_shape != NS_NULL)
13429 first_error (_("invalid instruction shape"));
5287ad62 13430
037e8744
JB
13431 return shape;
13432}
5287ad62 13433
037e8744
JB
13434/* True if SHAPE is predominantly a quadword operation (most of the time, this
13435 means the Q bit should be set). */
13436
13437static int
13438neon_quad (enum neon_shape shape)
13439{
13440 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13441}
037e8744 13442
5287ad62
JB
13443static void
13444neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13445 unsigned *g_size)
5287ad62
JB
13446{
13447 /* Allow modification to be made to types which are constrained to be
13448 based on the key element, based on bits set alongside N_EQK. */
13449 if ((typebits & N_EQK) != 0)
13450 {
13451 if ((typebits & N_HLF) != 0)
13452 *g_size /= 2;
13453 else if ((typebits & N_DBL) != 0)
13454 *g_size *= 2;
13455 if ((typebits & N_SGN) != 0)
13456 *g_type = NT_signed;
13457 else if ((typebits & N_UNS) != 0)
477330fc 13458 *g_type = NT_unsigned;
5287ad62 13459 else if ((typebits & N_INT) != 0)
477330fc 13460 *g_type = NT_integer;
5287ad62 13461 else if ((typebits & N_FLT) != 0)
477330fc 13462 *g_type = NT_float;
dcbf9037 13463 else if ((typebits & N_SIZ) != 0)
477330fc 13464 *g_type = NT_untyped;
5287ad62
JB
13465 }
13466}
5f4273c7 13467
5287ad62
JB
13468/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13469 operand type, i.e. the single type specified in a Neon instruction when it
13470 is the only one given. */
13471
13472static struct neon_type_el
13473neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13474{
13475 struct neon_type_el dest = *key;
5f4273c7 13476
9c2799c2 13477 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13478
5287ad62
JB
13479 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13480
13481 return dest;
13482}
13483
13484/* Convert Neon type and size into compact bitmask representation. */
13485
13486static enum neon_type_mask
13487type_chk_of_el_type (enum neon_el_type type, unsigned size)
13488{
13489 switch (type)
13490 {
13491 case NT_untyped:
13492 switch (size)
477330fc
RM
13493 {
13494 case 8: return N_8;
13495 case 16: return N_16;
13496 case 32: return N_32;
13497 case 64: return N_64;
13498 default: ;
13499 }
5287ad62
JB
13500 break;
13501
13502 case NT_integer:
13503 switch (size)
477330fc
RM
13504 {
13505 case 8: return N_I8;
13506 case 16: return N_I16;
13507 case 32: return N_I32;
13508 case 64: return N_I64;
13509 default: ;
13510 }
5287ad62
JB
13511 break;
13512
13513 case NT_float:
037e8744 13514 switch (size)
477330fc 13515 {
8e79c3df 13516 case 16: return N_F16;
477330fc
RM
13517 case 32: return N_F32;
13518 case 64: return N_F64;
13519 default: ;
13520 }
5287ad62
JB
13521 break;
13522
13523 case NT_poly:
13524 switch (size)
477330fc
RM
13525 {
13526 case 8: return N_P8;
13527 case 16: return N_P16;
4f51b4bd 13528 case 64: return N_P64;
477330fc
RM
13529 default: ;
13530 }
5287ad62
JB
13531 break;
13532
13533 case NT_signed:
13534 switch (size)
477330fc
RM
13535 {
13536 case 8: return N_S8;
13537 case 16: return N_S16;
13538 case 32: return N_S32;
13539 case 64: return N_S64;
13540 default: ;
13541 }
5287ad62
JB
13542 break;
13543
13544 case NT_unsigned:
13545 switch (size)
477330fc
RM
13546 {
13547 case 8: return N_U8;
13548 case 16: return N_U16;
13549 case 32: return N_U32;
13550 case 64: return N_U64;
13551 default: ;
13552 }
5287ad62
JB
13553 break;
13554
13555 default: ;
13556 }
5f4273c7 13557
5287ad62
JB
13558 return N_UTYP;
13559}
13560
13561/* Convert compact Neon bitmask type representation to a type and size. Only
13562 handles the case where a single bit is set in the mask. */
13563
dcbf9037 13564static int
5287ad62 13565el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13566 enum neon_type_mask mask)
5287ad62 13567{
dcbf9037
JB
13568 if ((mask & N_EQK) != 0)
13569 return FAIL;
13570
5287ad62
JB
13571 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13572 *size = 8;
c70a8987 13573 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13574 *size = 16;
dcbf9037 13575 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13576 *size = 32;
4f51b4bd 13577 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13578 *size = 64;
dcbf9037
JB
13579 else
13580 return FAIL;
13581
5287ad62
JB
13582 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13583 *type = NT_signed;
dcbf9037 13584 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13585 *type = NT_unsigned;
dcbf9037 13586 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13587 *type = NT_integer;
dcbf9037 13588 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13589 *type = NT_untyped;
4f51b4bd 13590 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13591 *type = NT_poly;
c70a8987 13592 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 13593 *type = NT_float;
dcbf9037
JB
13594 else
13595 return FAIL;
5f4273c7 13596
dcbf9037 13597 return SUCCESS;
5287ad62
JB
13598}
13599
13600/* Modify a bitmask of allowed types. This is only needed for type
13601 relaxation. */
13602
13603static unsigned
13604modify_types_allowed (unsigned allowed, unsigned mods)
13605{
13606 unsigned size;
13607 enum neon_el_type type;
13608 unsigned destmask;
13609 int i;
5f4273c7 13610
5287ad62 13611 destmask = 0;
5f4273c7 13612
5287ad62
JB
13613 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13614 {
21d799b5 13615 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13616 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13617 {
13618 neon_modify_type_size (mods, &type, &size);
13619 destmask |= type_chk_of_el_type (type, size);
13620 }
5287ad62 13621 }
5f4273c7 13622
5287ad62
JB
13623 return destmask;
13624}
13625
13626/* Check type and return type classification.
13627 The manual states (paraphrase): If one datatype is given, it indicates the
13628 type given in:
13629 - the second operand, if there is one
13630 - the operand, if there is no second operand
13631 - the result, if there are no operands.
13632 This isn't quite good enough though, so we use a concept of a "key" datatype
13633 which is set on a per-instruction basis, which is the one which matters when
13634 only one data type is written.
13635 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13636 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13637
13638static struct neon_type_el
13639neon_check_type (unsigned els, enum neon_shape ns, ...)
13640{
13641 va_list ap;
13642 unsigned i, pass, key_el = 0;
13643 unsigned types[NEON_MAX_TYPE_ELS];
13644 enum neon_el_type k_type = NT_invtype;
13645 unsigned k_size = -1u;
13646 struct neon_type_el badtype = {NT_invtype, -1};
13647 unsigned key_allowed = 0;
13648
13649 /* Optional registers in Neon instructions are always (not) in operand 1.
13650 Fill in the missing operand here, if it was omitted. */
13651 if (els > 1 && !inst.operands[1].present)
13652 inst.operands[1] = inst.operands[0];
13653
13654 /* Suck up all the varargs. */
13655 va_start (ap, ns);
13656 for (i = 0; i < els; i++)
13657 {
13658 unsigned thisarg = va_arg (ap, unsigned);
13659 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13660 {
13661 va_end (ap);
13662 return badtype;
13663 }
5287ad62
JB
13664 types[i] = thisarg;
13665 if ((thisarg & N_KEY) != 0)
477330fc 13666 key_el = i;
5287ad62
JB
13667 }
13668 va_end (ap);
13669
dcbf9037
JB
13670 if (inst.vectype.elems > 0)
13671 for (i = 0; i < els; i++)
13672 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13673 {
13674 first_error (_("types specified in both the mnemonic and operands"));
13675 return badtype;
13676 }
dcbf9037 13677
5287ad62
JB
13678 /* Duplicate inst.vectype elements here as necessary.
13679 FIXME: No idea if this is exactly the same as the ARM assembler,
13680 particularly when an insn takes one register and one non-register
13681 operand. */
13682 if (inst.vectype.elems == 1 && els > 1)
13683 {
13684 unsigned j;
13685 inst.vectype.elems = els;
13686 inst.vectype.el[key_el] = inst.vectype.el[0];
13687 for (j = 0; j < els; j++)
477330fc
RM
13688 if (j != key_el)
13689 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13690 types[j]);
dcbf9037
JB
13691 }
13692 else if (inst.vectype.elems == 0 && els > 0)
13693 {
13694 unsigned j;
13695 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13696 after each operand. We allow some flexibility here; as long as the
13697 "key" operand has a type, we can infer the others. */
dcbf9037 13698 for (j = 0; j < els; j++)
477330fc
RM
13699 if (inst.operands[j].vectype.type != NT_invtype)
13700 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13701
13702 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13703 {
13704 for (j = 0; j < els; j++)
13705 if (inst.operands[j].vectype.type == NT_invtype)
13706 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13707 types[j]);
13708 }
dcbf9037 13709 else
477330fc
RM
13710 {
13711 first_error (_("operand types can't be inferred"));
13712 return badtype;
13713 }
5287ad62
JB
13714 }
13715 else if (inst.vectype.elems != els)
13716 {
dcbf9037 13717 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13718 return badtype;
13719 }
13720
13721 for (pass = 0; pass < 2; pass++)
13722 {
13723 for (i = 0; i < els; i++)
477330fc
RM
13724 {
13725 unsigned thisarg = types[i];
13726 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13727 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13728 enum neon_el_type g_type = inst.vectype.el[i].type;
13729 unsigned g_size = inst.vectype.el[i].size;
13730
13731 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13732 integer types if sign-specific variants are unavailable. */
477330fc 13733 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13734 && (types_allowed & N_SU_ALL) == 0)
13735 g_type = NT_integer;
13736
477330fc 13737 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13738 them. Some instructions only care about signs for some element
13739 sizes, so handle that properly. */
477330fc 13740 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13741 && ((g_size == 8 && (types_allowed & N_8) != 0)
13742 || (g_size == 16 && (types_allowed & N_16) != 0)
13743 || (g_size == 32 && (types_allowed & N_32) != 0)
13744 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13745 g_type = NT_untyped;
13746
477330fc
RM
13747 if (pass == 0)
13748 {
13749 if ((thisarg & N_KEY) != 0)
13750 {
13751 k_type = g_type;
13752 k_size = g_size;
13753 key_allowed = thisarg & ~N_KEY;
13754 }
13755 }
13756 else
13757 {
13758 if ((thisarg & N_VFP) != 0)
13759 {
13760 enum neon_shape_el regshape;
13761 unsigned regwidth, match;
99b253c5
NC
13762
13763 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13764 if (ns == NS_NULL)
13765 {
13766 first_error (_("invalid instruction shape"));
13767 return badtype;
13768 }
477330fc
RM
13769 regshape = neon_shape_tab[ns].el[i];
13770 regwidth = neon_shape_el_size[regshape];
13771
13772 /* In VFP mode, operands must match register widths. If we
13773 have a key operand, use its width, else use the width of
13774 the current operand. */
13775 if (k_size != -1u)
13776 match = k_size;
13777 else
13778 match = g_size;
13779
13780 if (regwidth != match)
13781 {
13782 first_error (_("operand size must match register width"));
13783 return badtype;
13784 }
13785 }
13786
13787 if ((thisarg & N_EQK) == 0)
13788 {
13789 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13790
13791 if ((given_type & types_allowed) == 0)
13792 {
13793 first_error (_("bad type in Neon instruction"));
13794 return badtype;
13795 }
13796 }
13797 else
13798 {
13799 enum neon_el_type mod_k_type = k_type;
13800 unsigned mod_k_size = k_size;
13801 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13802 if (g_type != mod_k_type || g_size != mod_k_size)
13803 {
13804 first_error (_("inconsistent types in Neon instruction"));
13805 return badtype;
13806 }
13807 }
13808 }
13809 }
5287ad62
JB
13810 }
13811
13812 return inst.vectype.el[key_el];
13813}
13814
037e8744 13815/* Neon-style VFP instruction forwarding. */
5287ad62 13816
037e8744
JB
13817/* Thumb VFP instructions have 0xE in the condition field. */
13818
13819static void
13820do_vfp_cond_or_thumb (void)
5287ad62 13821{
88714cb8
DG
13822 inst.is_neon = 1;
13823
5287ad62 13824 if (thumb_mode)
037e8744 13825 inst.instruction |= 0xe0000000;
5287ad62 13826 else
037e8744 13827 inst.instruction |= inst.cond << 28;
5287ad62
JB
13828}
13829
037e8744
JB
13830/* Look up and encode a simple mnemonic, for use as a helper function for the
13831 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13832 etc. It is assumed that operand parsing has already been done, and that the
13833 operands are in the form expected by the given opcode (this isn't necessarily
13834 the same as the form in which they were parsed, hence some massaging must
13835 take place before this function is called).
13836 Checks current arch version against that in the looked-up opcode. */
5287ad62 13837
037e8744
JB
13838static void
13839do_vfp_nsyn_opcode (const char *opname)
5287ad62 13840{
037e8744 13841 const struct asm_opcode *opcode;
5f4273c7 13842
21d799b5 13843 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13844
037e8744
JB
13845 if (!opcode)
13846 abort ();
5287ad62 13847
037e8744 13848 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
13849 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13850 _(BAD_FPU));
5287ad62 13851
88714cb8
DG
13852 inst.is_neon = 1;
13853
037e8744
JB
13854 if (thumb_mode)
13855 {
13856 inst.instruction = opcode->tvalue;
13857 opcode->tencode ();
13858 }
13859 else
13860 {
13861 inst.instruction = (inst.cond << 28) | opcode->avalue;
13862 opcode->aencode ();
13863 }
13864}
5287ad62
JB
13865
13866static void
037e8744 13867do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13868{
037e8744
JB
13869 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13870
13871 if (rs == NS_FFF)
13872 {
13873 if (is_add)
477330fc 13874 do_vfp_nsyn_opcode ("fadds");
037e8744 13875 else
477330fc 13876 do_vfp_nsyn_opcode ("fsubs");
037e8744
JB
13877 }
13878 else
13879 {
13880 if (is_add)
477330fc 13881 do_vfp_nsyn_opcode ("faddd");
037e8744 13882 else
477330fc 13883 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
13884 }
13885}
13886
13887/* Check operand types to see if this is a VFP instruction, and if so call
13888 PFN (). */
13889
13890static int
13891try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13892{
13893 enum neon_shape rs;
13894 struct neon_type_el et;
13895
13896 switch (args)
13897 {
13898 case 2:
13899 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13900 et = neon_check_type (2, rs,
477330fc 13901 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744 13902 break;
5f4273c7 13903
037e8744
JB
13904 case 3:
13905 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13906 et = neon_check_type (3, rs,
477330fc 13907 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744
JB
13908 break;
13909
13910 default:
13911 abort ();
13912 }
13913
13914 if (et.type != NT_invtype)
13915 {
13916 pfn (rs);
13917 return SUCCESS;
13918 }
037e8744 13919
99b253c5 13920 inst.error = NULL;
037e8744
JB
13921 return FAIL;
13922}
13923
13924static void
13925do_vfp_nsyn_mla_mls (enum neon_shape rs)
13926{
13927 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13928
037e8744
JB
13929 if (rs == NS_FFF)
13930 {
13931 if (is_mla)
477330fc 13932 do_vfp_nsyn_opcode ("fmacs");
037e8744 13933 else
477330fc 13934 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13935 }
13936 else
13937 {
13938 if (is_mla)
477330fc 13939 do_vfp_nsyn_opcode ("fmacd");
037e8744 13940 else
477330fc 13941 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13942 }
13943}
13944
62f3b8c8
PB
13945static void
13946do_vfp_nsyn_fma_fms (enum neon_shape rs)
13947{
13948 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13949
13950 if (rs == NS_FFF)
13951 {
13952 if (is_fma)
477330fc 13953 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 13954 else
477330fc 13955 do_vfp_nsyn_opcode ("ffnmas");
62f3b8c8
PB
13956 }
13957 else
13958 {
13959 if (is_fma)
477330fc 13960 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 13961 else
477330fc 13962 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
13963 }
13964}
13965
037e8744
JB
13966static void
13967do_vfp_nsyn_mul (enum neon_shape rs)
13968{
13969 if (rs == NS_FFF)
13970 do_vfp_nsyn_opcode ("fmuls");
13971 else
13972 do_vfp_nsyn_opcode ("fmuld");
13973}
13974
13975static void
13976do_vfp_nsyn_abs_neg (enum neon_shape rs)
13977{
13978 int is_neg = (inst.instruction & 0x80) != 0;
13979 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13980
13981 if (rs == NS_FF)
13982 {
13983 if (is_neg)
477330fc 13984 do_vfp_nsyn_opcode ("fnegs");
037e8744 13985 else
477330fc 13986 do_vfp_nsyn_opcode ("fabss");
037e8744
JB
13987 }
13988 else
13989 {
13990 if (is_neg)
477330fc 13991 do_vfp_nsyn_opcode ("fnegd");
037e8744 13992 else
477330fc 13993 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
13994 }
13995}
13996
13997/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13998 insns belong to Neon, and are handled elsewhere. */
13999
14000static void
14001do_vfp_nsyn_ldm_stm (int is_dbmode)
14002{
14003 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14004 if (is_ldm)
14005 {
14006 if (is_dbmode)
477330fc 14007 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14008 else
477330fc 14009 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14010 }
14011 else
14012 {
14013 if (is_dbmode)
477330fc 14014 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14015 else
477330fc 14016 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14017 }
14018}
14019
037e8744
JB
14020static void
14021do_vfp_nsyn_sqrt (void)
14022{
14023 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14024 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14025
037e8744
JB
14026 if (rs == NS_FF)
14027 do_vfp_nsyn_opcode ("fsqrts");
14028 else
14029 do_vfp_nsyn_opcode ("fsqrtd");
14030}
14031
14032static void
14033do_vfp_nsyn_div (void)
14034{
14035 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14036 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14037 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14038
037e8744
JB
14039 if (rs == NS_FFF)
14040 do_vfp_nsyn_opcode ("fdivs");
14041 else
14042 do_vfp_nsyn_opcode ("fdivd");
14043}
14044
14045static void
14046do_vfp_nsyn_nmul (void)
14047{
14048 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14049 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14050 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14051
037e8744
JB
14052 if (rs == NS_FFF)
14053 {
88714cb8 14054 NEON_ENCODE (SINGLE, inst);
037e8744
JB
14055 do_vfp_sp_dyadic ();
14056 }
14057 else
14058 {
88714cb8 14059 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14060 do_vfp_dp_rd_rn_rm ();
14061 }
14062 do_vfp_cond_or_thumb ();
14063}
14064
14065static void
14066do_vfp_nsyn_cmp (void)
14067{
14068 if (inst.operands[1].isreg)
14069 {
14070 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14071 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14072
037e8744 14073 if (rs == NS_FF)
477330fc
RM
14074 {
14075 NEON_ENCODE (SINGLE, inst);
14076 do_vfp_sp_monadic ();
14077 }
037e8744 14078 else
477330fc
RM
14079 {
14080 NEON_ENCODE (DOUBLE, inst);
14081 do_vfp_dp_rd_rm ();
14082 }
037e8744
JB
14083 }
14084 else
14085 {
14086 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
14087 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
14088
14089 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14090 {
14091 case N_MNEM_vcmp:
14092 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14093 break;
14094 case N_MNEM_vcmpe:
14095 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14096 break;
14097 default:
14098 abort ();
14099 }
5f4273c7 14100
037e8744 14101 if (rs == NS_FI)
477330fc
RM
14102 {
14103 NEON_ENCODE (SINGLE, inst);
14104 do_vfp_sp_compare_z ();
14105 }
037e8744 14106 else
477330fc
RM
14107 {
14108 NEON_ENCODE (DOUBLE, inst);
14109 do_vfp_dp_rd ();
14110 }
037e8744
JB
14111 }
14112 do_vfp_cond_or_thumb ();
14113}
14114
14115static void
14116nsyn_insert_sp (void)
14117{
14118 inst.operands[1] = inst.operands[0];
14119 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14120 inst.operands[0].reg = REG_SP;
037e8744
JB
14121 inst.operands[0].isreg = 1;
14122 inst.operands[0].writeback = 1;
14123 inst.operands[0].present = 1;
14124}
14125
14126static void
14127do_vfp_nsyn_push (void)
14128{
14129 nsyn_insert_sp ();
14130 if (inst.operands[1].issingle)
14131 do_vfp_nsyn_opcode ("fstmdbs");
14132 else
14133 do_vfp_nsyn_opcode ("fstmdbd");
14134}
14135
14136static void
14137do_vfp_nsyn_pop (void)
14138{
14139 nsyn_insert_sp ();
14140 if (inst.operands[1].issingle)
22b5b651 14141 do_vfp_nsyn_opcode ("fldmias");
037e8744 14142 else
22b5b651 14143 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14144}
14145
14146/* Fix up Neon data-processing instructions, ORing in the correct bits for
14147 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14148
88714cb8
DG
14149static void
14150neon_dp_fixup (struct arm_it* insn)
037e8744 14151{
88714cb8
DG
14152 unsigned int i = insn->instruction;
14153 insn->is_neon = 1;
14154
037e8744
JB
14155 if (thumb_mode)
14156 {
14157 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14158 if (i & (1 << 24))
477330fc 14159 i |= 1 << 28;
5f4273c7 14160
037e8744 14161 i &= ~(1 << 24);
5f4273c7 14162
037e8744
JB
14163 i |= 0xef000000;
14164 }
14165 else
14166 i |= 0xf2000000;
5f4273c7 14167
88714cb8 14168 insn->instruction = i;
037e8744
JB
14169}
14170
14171/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14172 (0, 1, 2, 3). */
14173
14174static unsigned
14175neon_logbits (unsigned x)
14176{
14177 return ffs (x) - 4;
14178}
14179
14180#define LOW4(R) ((R) & 0xf)
14181#define HI1(R) (((R) >> 4) & 1)
14182
14183/* Encode insns with bit pattern:
14184
14185 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14186 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14187
037e8744
JB
14188 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14189 different meaning for some instruction. */
14190
14191static void
14192neon_three_same (int isquad, int ubit, int size)
14193{
14194 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14195 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14196 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14197 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14198 inst.instruction |= LOW4 (inst.operands[2].reg);
14199 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14200 inst.instruction |= (isquad != 0) << 6;
14201 inst.instruction |= (ubit != 0) << 24;
14202 if (size != -1)
14203 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14204
88714cb8 14205 neon_dp_fixup (&inst);
037e8744
JB
14206}
14207
14208/* Encode instructions of the form:
14209
14210 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14211 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14212
14213 Don't write size if SIZE == -1. */
14214
14215static void
14216neon_two_same (int qbit, int ubit, int size)
14217{
14218 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14219 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14220 inst.instruction |= LOW4 (inst.operands[1].reg);
14221 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14222 inst.instruction |= (qbit != 0) << 6;
14223 inst.instruction |= (ubit != 0) << 24;
14224
14225 if (size != -1)
14226 inst.instruction |= neon_logbits (size) << 18;
14227
88714cb8 14228 neon_dp_fixup (&inst);
5287ad62
JB
14229}
14230
14231/* Neon instruction encoders, in approximate order of appearance. */
14232
14233static void
14234do_neon_dyadic_i_su (void)
14235{
037e8744 14236 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14237 struct neon_type_el et = neon_check_type (3, rs,
14238 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14239 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14240}
14241
14242static void
14243do_neon_dyadic_i64_su (void)
14244{
037e8744 14245 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14246 struct neon_type_el et = neon_check_type (3, rs,
14247 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14248 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14249}
14250
14251static void
14252neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14253 unsigned immbits)
5287ad62
JB
14254{
14255 unsigned size = et.size >> 3;
14256 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14257 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14258 inst.instruction |= LOW4 (inst.operands[1].reg);
14259 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14260 inst.instruction |= (isquad != 0) << 6;
14261 inst.instruction |= immbits << 16;
14262 inst.instruction |= (size >> 3) << 7;
14263 inst.instruction |= (size & 0x7) << 19;
14264 if (write_ubit)
14265 inst.instruction |= (uval != 0) << 24;
14266
88714cb8 14267 neon_dp_fixup (&inst);
5287ad62
JB
14268}
14269
14270static void
14271do_neon_shl_imm (void)
14272{
14273 if (!inst.operands[2].isreg)
14274 {
037e8744 14275 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14276 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14277 int imm = inst.operands[2].imm;
14278
14279 constraint (imm < 0 || (unsigned)imm >= et.size,
14280 _("immediate out of range for shift"));
88714cb8 14281 NEON_ENCODE (IMMED, inst);
cb3b1e65 14282 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14283 }
14284 else
14285 {
037e8744 14286 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14287 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14288 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14289 unsigned int tmp;
14290
14291 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14292 vshl.xx Dd, Dm, Dn
14293 whereas other 3-register operations encoded by neon_three_same have
14294 syntax like:
14295 vadd.xx Dd, Dn, Dm
14296 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14297 here. */
627907b7
JB
14298 tmp = inst.operands[2].reg;
14299 inst.operands[2].reg = inst.operands[1].reg;
14300 inst.operands[1].reg = tmp;
88714cb8 14301 NEON_ENCODE (INTEGER, inst);
037e8744 14302 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14303 }
14304}
14305
14306static void
14307do_neon_qshl_imm (void)
14308{
14309 if (!inst.operands[2].isreg)
14310 {
037e8744 14311 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14312 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14313 int imm = inst.operands[2].imm;
627907b7 14314
cb3b1e65
JB
14315 constraint (imm < 0 || (unsigned)imm >= et.size,
14316 _("immediate out of range for shift"));
88714cb8 14317 NEON_ENCODE (IMMED, inst);
cb3b1e65 14318 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14319 }
14320 else
14321 {
037e8744 14322 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14323 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14324 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14325 unsigned int tmp;
14326
14327 /* See note in do_neon_shl_imm. */
14328 tmp = inst.operands[2].reg;
14329 inst.operands[2].reg = inst.operands[1].reg;
14330 inst.operands[1].reg = tmp;
88714cb8 14331 NEON_ENCODE (INTEGER, inst);
037e8744 14332 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14333 }
14334}
14335
627907b7
JB
14336static void
14337do_neon_rshl (void)
14338{
14339 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14340 struct neon_type_el et = neon_check_type (3, rs,
14341 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14342 unsigned int tmp;
14343
14344 tmp = inst.operands[2].reg;
14345 inst.operands[2].reg = inst.operands[1].reg;
14346 inst.operands[1].reg = tmp;
14347 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14348}
14349
5287ad62
JB
14350static int
14351neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14352{
036dc3f7
PB
14353 /* Handle .I8 pseudo-instructions. */
14354 if (size == 8)
5287ad62 14355 {
5287ad62 14356 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14357 FIXME is this the intended semantics? There doesn't seem much point in
14358 accepting .I8 if so. */
5287ad62
JB
14359 immediate |= immediate << 8;
14360 size = 16;
036dc3f7
PB
14361 }
14362
14363 if (size >= 32)
14364 {
14365 if (immediate == (immediate & 0x000000ff))
14366 {
14367 *immbits = immediate;
14368 return 0x1;
14369 }
14370 else if (immediate == (immediate & 0x0000ff00))
14371 {
14372 *immbits = immediate >> 8;
14373 return 0x3;
14374 }
14375 else if (immediate == (immediate & 0x00ff0000))
14376 {
14377 *immbits = immediate >> 16;
14378 return 0x5;
14379 }
14380 else if (immediate == (immediate & 0xff000000))
14381 {
14382 *immbits = immediate >> 24;
14383 return 0x7;
14384 }
14385 if ((immediate & 0xffff) != (immediate >> 16))
14386 goto bad_immediate;
14387 immediate &= 0xffff;
5287ad62
JB
14388 }
14389
14390 if (immediate == (immediate & 0x000000ff))
14391 {
14392 *immbits = immediate;
036dc3f7 14393 return 0x9;
5287ad62
JB
14394 }
14395 else if (immediate == (immediate & 0x0000ff00))
14396 {
14397 *immbits = immediate >> 8;
036dc3f7 14398 return 0xb;
5287ad62
JB
14399 }
14400
14401 bad_immediate:
dcbf9037 14402 first_error (_("immediate value out of range"));
5287ad62
JB
14403 return FAIL;
14404}
14405
5287ad62
JB
14406static void
14407do_neon_logic (void)
14408{
14409 if (inst.operands[2].present && inst.operands[2].isreg)
14410 {
037e8744 14411 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14412 neon_check_type (3, rs, N_IGNORE_TYPE);
14413 /* U bit and size field were set as part of the bitmask. */
88714cb8 14414 NEON_ENCODE (INTEGER, inst);
037e8744 14415 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14416 }
14417 else
14418 {
4316f0d2
DG
14419 const int three_ops_form = (inst.operands[2].present
14420 && !inst.operands[2].isreg);
14421 const int immoperand = (three_ops_form ? 2 : 1);
14422 enum neon_shape rs = (three_ops_form
14423 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14424 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14425 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14426 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14427 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14428 unsigned immbits;
14429 int cmode;
5f4273c7 14430
5287ad62 14431 if (et.type == NT_invtype)
477330fc 14432 return;
5f4273c7 14433
4316f0d2
DG
14434 if (three_ops_form)
14435 constraint (inst.operands[0].reg != inst.operands[1].reg,
14436 _("first and second operands shall be the same register"));
14437
88714cb8 14438 NEON_ENCODE (IMMED, inst);
5287ad62 14439
4316f0d2 14440 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14441 if (et.size == 64)
14442 {
14443 /* .i64 is a pseudo-op, so the immediate must be a repeating
14444 pattern. */
4316f0d2
DG
14445 if (immbits != (inst.operands[immoperand].regisimm ?
14446 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14447 {
14448 /* Set immbits to an invalid constant. */
14449 immbits = 0xdeadbeef;
14450 }
14451 }
14452
5287ad62 14453 switch (opcode)
477330fc
RM
14454 {
14455 case N_MNEM_vbic:
14456 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14457 break;
14458
14459 case N_MNEM_vorr:
14460 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14461 break;
14462
14463 case N_MNEM_vand:
14464 /* Pseudo-instruction for VBIC. */
14465 neon_invert_size (&immbits, 0, et.size);
14466 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14467 break;
14468
14469 case N_MNEM_vorn:
14470 /* Pseudo-instruction for VORR. */
14471 neon_invert_size (&immbits, 0, et.size);
14472 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14473 break;
14474
14475 default:
14476 abort ();
14477 }
5287ad62
JB
14478
14479 if (cmode == FAIL)
477330fc 14480 return;
5287ad62 14481
037e8744 14482 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14483 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14484 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14485 inst.instruction |= cmode << 8;
14486 neon_write_immbits (immbits);
5f4273c7 14487
88714cb8 14488 neon_dp_fixup (&inst);
5287ad62
JB
14489 }
14490}
14491
14492static void
14493do_neon_bitfield (void)
14494{
037e8744 14495 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14496 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14497 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14498}
14499
14500static void
dcbf9037 14501neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14502 unsigned destbits)
5287ad62 14503{
037e8744 14504 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14505 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14506 types | N_KEY);
5287ad62
JB
14507 if (et.type == NT_float)
14508 {
88714cb8 14509 NEON_ENCODE (FLOAT, inst);
037e8744 14510 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14511 }
14512 else
14513 {
88714cb8 14514 NEON_ENCODE (INTEGER, inst);
037e8744 14515 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14516 }
14517}
14518
14519static void
14520do_neon_dyadic_if_su (void)
14521{
dcbf9037 14522 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14523}
14524
14525static void
14526do_neon_dyadic_if_su_d (void)
14527{
14528 /* This version only allow D registers, but that constraint is enforced during
14529 operand parsing so we don't need to do anything extra here. */
dcbf9037 14530 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14531}
14532
5287ad62
JB
14533static void
14534do_neon_dyadic_if_i_d (void)
14535{
428e3f1f
PB
14536 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14537 affected if we specify unsigned args. */
14538 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14539}
14540
037e8744
JB
14541enum vfp_or_neon_is_neon_bits
14542{
14543 NEON_CHECK_CC = 1,
73924fbc
MGD
14544 NEON_CHECK_ARCH = 2,
14545 NEON_CHECK_ARCH8 = 4
037e8744
JB
14546};
14547
14548/* Call this function if an instruction which may have belonged to the VFP or
14549 Neon instruction sets, but turned out to be a Neon instruction (due to the
14550 operand types involved, etc.). We have to check and/or fix-up a couple of
14551 things:
14552
14553 - Make sure the user hasn't attempted to make a Neon instruction
14554 conditional.
14555 - Alter the value in the condition code field if necessary.
14556 - Make sure that the arch supports Neon instructions.
14557
14558 Which of these operations take place depends on bits from enum
14559 vfp_or_neon_is_neon_bits.
14560
14561 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14562 current instruction's condition is COND_ALWAYS, the condition field is
14563 changed to inst.uncond_value. This is necessary because instructions shared
14564 between VFP and Neon may be conditional for the VFP variants only, and the
14565 unconditional Neon version must have, e.g., 0xF in the condition field. */
14566
14567static int
14568vfp_or_neon_is_neon (unsigned check)
14569{
14570 /* Conditions are always legal in Thumb mode (IT blocks). */
14571 if (!thumb_mode && (check & NEON_CHECK_CC))
14572 {
14573 if (inst.cond != COND_ALWAYS)
477330fc
RM
14574 {
14575 first_error (_(BAD_COND));
14576 return FAIL;
14577 }
037e8744 14578 if (inst.uncond_value != -1)
477330fc 14579 inst.instruction |= inst.uncond_value << 28;
037e8744 14580 }
5f4273c7 14581
037e8744 14582 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14583 && !mark_feature_used (&fpu_neon_ext_v1))
14584 {
14585 first_error (_(BAD_FPU));
14586 return FAIL;
14587 }
14588
14589 if ((check & NEON_CHECK_ARCH8)
14590 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14591 {
14592 first_error (_(BAD_FPU));
14593 return FAIL;
14594 }
5f4273c7 14595
037e8744
JB
14596 return SUCCESS;
14597}
14598
5287ad62
JB
14599static void
14600do_neon_addsub_if_i (void)
14601{
037e8744
JB
14602 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14603 return;
14604
14605 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14606 return;
14607
5287ad62
JB
14608 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14609 affected if we specify unsigned args. */
dcbf9037 14610 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14611}
14612
14613/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14614 result to be:
14615 V<op> A,B (A is operand 0, B is operand 2)
14616 to mean:
14617 V<op> A,B,A
14618 not:
14619 V<op> A,B,B
14620 so handle that case specially. */
14621
14622static void
14623neon_exchange_operands (void)
14624{
14625 void *scratch = alloca (sizeof (inst.operands[0]));
14626 if (inst.operands[1].present)
14627 {
14628 /* Swap operands[1] and operands[2]. */
14629 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14630 inst.operands[1] = inst.operands[2];
14631 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14632 }
14633 else
14634 {
14635 inst.operands[1] = inst.operands[2];
14636 inst.operands[2] = inst.operands[0];
14637 }
14638}
14639
14640static void
14641neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14642{
14643 if (inst.operands[2].isreg)
14644 {
14645 if (invert)
477330fc 14646 neon_exchange_operands ();
dcbf9037 14647 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14648 }
14649 else
14650 {
037e8744 14651 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14652 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14653 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14654
88714cb8 14655 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14656 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14657 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14658 inst.instruction |= LOW4 (inst.operands[1].reg);
14659 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14660 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14661 inst.instruction |= (et.type == NT_float) << 10;
14662 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14663
88714cb8 14664 neon_dp_fixup (&inst);
5287ad62
JB
14665 }
14666}
14667
14668static void
14669do_neon_cmp (void)
14670{
14671 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14672}
14673
14674static void
14675do_neon_cmp_inv (void)
14676{
14677 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14678}
14679
14680static void
14681do_neon_ceq (void)
14682{
14683 neon_compare (N_IF_32, N_IF_32, FALSE);
14684}
14685
14686/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14687 scalars, which are encoded in 5 bits, M : Rm.
14688 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14689 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14690 index in M. */
14691
14692static unsigned
14693neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14694{
dcbf9037
JB
14695 unsigned regno = NEON_SCALAR_REG (scalar);
14696 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14697
14698 switch (elsize)
14699 {
14700 case 16:
14701 if (regno > 7 || elno > 3)
477330fc 14702 goto bad_scalar;
5287ad62 14703 return regno | (elno << 3);
5f4273c7 14704
5287ad62
JB
14705 case 32:
14706 if (regno > 15 || elno > 1)
477330fc 14707 goto bad_scalar;
5287ad62
JB
14708 return regno | (elno << 4);
14709
14710 default:
14711 bad_scalar:
dcbf9037 14712 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14713 }
14714
14715 return 0;
14716}
14717
14718/* Encode multiply / multiply-accumulate scalar instructions. */
14719
14720static void
14721neon_mul_mac (struct neon_type_el et, int ubit)
14722{
dcbf9037
JB
14723 unsigned scalar;
14724
14725 /* Give a more helpful error message if we have an invalid type. */
14726 if (et.type == NT_invtype)
14727 return;
5f4273c7 14728
dcbf9037 14729 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14730 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14731 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14732 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14733 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14734 inst.instruction |= LOW4 (scalar);
14735 inst.instruction |= HI1 (scalar) << 5;
14736 inst.instruction |= (et.type == NT_float) << 8;
14737 inst.instruction |= neon_logbits (et.size) << 20;
14738 inst.instruction |= (ubit != 0) << 24;
14739
88714cb8 14740 neon_dp_fixup (&inst);
5287ad62
JB
14741}
14742
14743static void
14744do_neon_mac_maybe_scalar (void)
14745{
037e8744
JB
14746 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14747 return;
14748
14749 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14750 return;
14751
5287ad62
JB
14752 if (inst.operands[2].isscalar)
14753 {
037e8744 14754 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14755 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14756 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14757 NEON_ENCODE (SCALAR, inst);
037e8744 14758 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14759 }
14760 else
428e3f1f
PB
14761 {
14762 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14763 affected if we specify unsigned args. */
14764 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14765 }
5287ad62
JB
14766}
14767
62f3b8c8
PB
14768static void
14769do_neon_fmac (void)
14770{
14771 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14772 return;
14773
14774 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14775 return;
14776
14777 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14778}
14779
5287ad62
JB
14780static void
14781do_neon_tst (void)
14782{
037e8744 14783 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14784 struct neon_type_el et = neon_check_type (3, rs,
14785 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14786 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14787}
14788
14789/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14790 same types as the MAC equivalents. The polynomial type for this instruction
14791 is encoded the same as the integer type. */
14792
14793static void
14794do_neon_mul (void)
14795{
037e8744
JB
14796 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14797 return;
14798
14799 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14800 return;
14801
5287ad62
JB
14802 if (inst.operands[2].isscalar)
14803 do_neon_mac_maybe_scalar ();
14804 else
dcbf9037 14805 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14806}
14807
14808static void
14809do_neon_qdmulh (void)
14810{
14811 if (inst.operands[2].isscalar)
14812 {
037e8744 14813 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14814 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14815 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14816 NEON_ENCODE (SCALAR, inst);
037e8744 14817 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14818 }
14819 else
14820 {
037e8744 14821 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14822 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14823 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14824 NEON_ENCODE (INTEGER, inst);
5287ad62 14825 /* The U bit (rounding) comes from bit mask. */
037e8744 14826 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14827 }
14828}
14829
14830static void
14831do_neon_fcmp_absolute (void)
14832{
037e8744 14833 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14834 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14835 /* Size field comes from bit mask. */
037e8744 14836 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14837}
14838
14839static void
14840do_neon_fcmp_absolute_inv (void)
14841{
14842 neon_exchange_operands ();
14843 do_neon_fcmp_absolute ();
14844}
14845
14846static void
14847do_neon_step (void)
14848{
037e8744 14849 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14850 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14851 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14852}
14853
14854static void
14855do_neon_abs_neg (void)
14856{
037e8744
JB
14857 enum neon_shape rs;
14858 struct neon_type_el et;
5f4273c7 14859
037e8744
JB
14860 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14861 return;
14862
14863 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14864 return;
14865
14866 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14867 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14868
5287ad62
JB
14869 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14870 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14871 inst.instruction |= LOW4 (inst.operands[1].reg);
14872 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14873 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14874 inst.instruction |= (et.type == NT_float) << 10;
14875 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14876
88714cb8 14877 neon_dp_fixup (&inst);
5287ad62
JB
14878}
14879
14880static void
14881do_neon_sli (void)
14882{
037e8744 14883 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14884 struct neon_type_el et = neon_check_type (2, rs,
14885 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14886 int imm = inst.operands[2].imm;
14887 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14888 _("immediate out of range for insert"));
037e8744 14889 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14890}
14891
14892static void
14893do_neon_sri (void)
14894{
037e8744 14895 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14896 struct neon_type_el et = neon_check_type (2, rs,
14897 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14898 int imm = inst.operands[2].imm;
14899 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14900 _("immediate out of range for insert"));
037e8744 14901 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14902}
14903
14904static void
14905do_neon_qshlu_imm (void)
14906{
037e8744 14907 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14908 struct neon_type_el et = neon_check_type (2, rs,
14909 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14910 int imm = inst.operands[2].imm;
14911 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14912 _("immediate out of range for shift"));
5287ad62
JB
14913 /* Only encodes the 'U present' variant of the instruction.
14914 In this case, signed types have OP (bit 8) set to 0.
14915 Unsigned types have OP set to 1. */
14916 inst.instruction |= (et.type == NT_unsigned) << 8;
14917 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14918 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14919}
14920
14921static void
14922do_neon_qmovn (void)
14923{
14924 struct neon_type_el et = neon_check_type (2, NS_DQ,
14925 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14926 /* Saturating move where operands can be signed or unsigned, and the
14927 destination has the same signedness. */
88714cb8 14928 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14929 if (et.type == NT_unsigned)
14930 inst.instruction |= 0xc0;
14931 else
14932 inst.instruction |= 0x80;
14933 neon_two_same (0, 1, et.size / 2);
14934}
14935
14936static void
14937do_neon_qmovun (void)
14938{
14939 struct neon_type_el et = neon_check_type (2, NS_DQ,
14940 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14941 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14942 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14943 neon_two_same (0, 1, et.size / 2);
14944}
14945
14946static void
14947do_neon_rshift_sat_narrow (void)
14948{
14949 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14950 or unsigned. If operands are unsigned, results must also be unsigned. */
14951 struct neon_type_el et = neon_check_type (2, NS_DQI,
14952 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14953 int imm = inst.operands[2].imm;
14954 /* This gets the bounds check, size encoding and immediate bits calculation
14955 right. */
14956 et.size /= 2;
5f4273c7 14957
5287ad62
JB
14958 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14959 VQMOVN.I<size> <Dd>, <Qm>. */
14960 if (imm == 0)
14961 {
14962 inst.operands[2].present = 0;
14963 inst.instruction = N_MNEM_vqmovn;
14964 do_neon_qmovn ();
14965 return;
14966 }
5f4273c7 14967
5287ad62 14968 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14969 _("immediate out of range"));
5287ad62
JB
14970 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14971}
14972
14973static void
14974do_neon_rshift_sat_narrow_u (void)
14975{
14976 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14977 or unsigned. If operands are unsigned, results must also be unsigned. */
14978 struct neon_type_el et = neon_check_type (2, NS_DQI,
14979 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14980 int imm = inst.operands[2].imm;
14981 /* This gets the bounds check, size encoding and immediate bits calculation
14982 right. */
14983 et.size /= 2;
14984
14985 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14986 VQMOVUN.I<size> <Dd>, <Qm>. */
14987 if (imm == 0)
14988 {
14989 inst.operands[2].present = 0;
14990 inst.instruction = N_MNEM_vqmovun;
14991 do_neon_qmovun ();
14992 return;
14993 }
14994
14995 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14996 _("immediate out of range"));
5287ad62
JB
14997 /* FIXME: The manual is kind of unclear about what value U should have in
14998 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14999 must be 1. */
15000 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15001}
15002
15003static void
15004do_neon_movn (void)
15005{
15006 struct neon_type_el et = neon_check_type (2, NS_DQ,
15007 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15008 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15009 neon_two_same (0, 1, et.size / 2);
15010}
15011
15012static void
15013do_neon_rshift_narrow (void)
15014{
15015 struct neon_type_el et = neon_check_type (2, NS_DQI,
15016 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15017 int imm = inst.operands[2].imm;
15018 /* This gets the bounds check, size encoding and immediate bits calculation
15019 right. */
15020 et.size /= 2;
5f4273c7 15021
5287ad62
JB
15022 /* If immediate is zero then we are a pseudo-instruction for
15023 VMOVN.I<size> <Dd>, <Qm> */
15024 if (imm == 0)
15025 {
15026 inst.operands[2].present = 0;
15027 inst.instruction = N_MNEM_vmovn;
15028 do_neon_movn ();
15029 return;
15030 }
5f4273c7 15031
5287ad62 15032 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15033 _("immediate out of range for narrowing operation"));
5287ad62
JB
15034 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15035}
15036
15037static void
15038do_neon_shll (void)
15039{
15040 /* FIXME: Type checking when lengthening. */
15041 struct neon_type_el et = neon_check_type (2, NS_QDI,
15042 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15043 unsigned imm = inst.operands[2].imm;
15044
15045 if (imm == et.size)
15046 {
15047 /* Maximum shift variant. */
88714cb8 15048 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15049 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15050 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15051 inst.instruction |= LOW4 (inst.operands[1].reg);
15052 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15053 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15054
88714cb8 15055 neon_dp_fixup (&inst);
5287ad62
JB
15056 }
15057 else
15058 {
15059 /* A more-specific type check for non-max versions. */
15060 et = neon_check_type (2, NS_QDI,
477330fc 15061 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15062 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15063 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15064 }
15065}
15066
037e8744 15067/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15068 the current instruction is. */
15069
6b9a8b67
MGD
15070#define CVT_FLAVOUR_VAR \
15071 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15072 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15073 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15074 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15075 /* Half-precision conversions. */ \
15076 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15077 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15078 /* VFP instructions. */ \
15079 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15080 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15081 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15082 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15083 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15084 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15085 /* VFP instructions with bitshift. */ \
15086 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15087 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15088 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15089 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15090 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15091 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15092 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15093 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15094
15095#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15096 neon_cvt_flavour_##C,
15097
15098/* The different types of conversions we can do. */
15099enum neon_cvt_flavour
15100{
15101 CVT_FLAVOUR_VAR
15102 neon_cvt_flavour_invalid,
15103 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15104};
15105
15106#undef CVT_VAR
15107
15108static enum neon_cvt_flavour
15109get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15110{
6b9a8b67
MGD
15111#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15112 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15113 if (et.type != NT_invtype) \
15114 { \
15115 inst.error = NULL; \
15116 return (neon_cvt_flavour_##C); \
5287ad62 15117 }
6b9a8b67 15118
5287ad62 15119 struct neon_type_el et;
037e8744 15120 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15121 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15122 /* The instruction versions which take an immediate take one register
15123 argument, which is extended to the width of the full register. Thus the
15124 "source" and "destination" registers must have the same width. Hack that
15125 here by making the size equal to the key (wider, in this case) operand. */
15126 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15127
6b9a8b67
MGD
15128 CVT_FLAVOUR_VAR;
15129
15130 return neon_cvt_flavour_invalid;
5287ad62
JB
15131#undef CVT_VAR
15132}
15133
7e8e6784
MGD
15134enum neon_cvt_mode
15135{
15136 neon_cvt_mode_a,
15137 neon_cvt_mode_n,
15138 neon_cvt_mode_p,
15139 neon_cvt_mode_m,
15140 neon_cvt_mode_z,
30bdf752
MGD
15141 neon_cvt_mode_x,
15142 neon_cvt_mode_r
7e8e6784
MGD
15143};
15144
037e8744
JB
15145/* Neon-syntax VFP conversions. */
15146
5287ad62 15147static void
6b9a8b67 15148do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15149{
037e8744 15150 const char *opname = 0;
5f4273c7 15151
037e8744 15152 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 15153 {
037e8744
JB
15154 /* Conversions with immediate bitshift. */
15155 const char *enc[] =
477330fc 15156 {
6b9a8b67
MGD
15157#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15158 CVT_FLAVOUR_VAR
15159 NULL
15160#undef CVT_VAR
477330fc 15161 };
037e8744 15162
6b9a8b67 15163 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15164 {
15165 opname = enc[flavour];
15166 constraint (inst.operands[0].reg != inst.operands[1].reg,
15167 _("operands 0 and 1 must be the same register"));
15168 inst.operands[1] = inst.operands[2];
15169 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15170 }
5287ad62
JB
15171 }
15172 else
15173 {
037e8744
JB
15174 /* Conversions without bitshift. */
15175 const char *enc[] =
477330fc 15176 {
6b9a8b67
MGD
15177#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15178 CVT_FLAVOUR_VAR
15179 NULL
15180#undef CVT_VAR
477330fc 15181 };
037e8744 15182
6b9a8b67 15183 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15184 opname = enc[flavour];
037e8744
JB
15185 }
15186
15187 if (opname)
15188 do_vfp_nsyn_opcode (opname);
15189}
15190
15191static void
15192do_vfp_nsyn_cvtz (void)
15193{
15194 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 15195 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15196 const char *enc[] =
15197 {
6b9a8b67
MGD
15198#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15199 CVT_FLAVOUR_VAR
15200 NULL
15201#undef CVT_VAR
037e8744
JB
15202 };
15203
6b9a8b67 15204 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15205 do_vfp_nsyn_opcode (enc[flavour]);
15206}
f31fef98 15207
037e8744 15208static void
bacebabc 15209do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15210 enum neon_cvt_mode mode)
15211{
15212 int sz, op;
15213 int rm;
15214
a715796b
TG
15215 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15216 D register operands. */
15217 if (flavour == neon_cvt_flavour_s32_f64
15218 || flavour == neon_cvt_flavour_u32_f64)
15219 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15220 _(BAD_FPU));
15221
7e8e6784
MGD
15222 set_it_insn_type (OUTSIDE_IT_INSN);
15223
15224 switch (flavour)
15225 {
15226 case neon_cvt_flavour_s32_f64:
15227 sz = 1;
827f64ff 15228 op = 1;
7e8e6784
MGD
15229 break;
15230 case neon_cvt_flavour_s32_f32:
15231 sz = 0;
15232 op = 1;
15233 break;
15234 case neon_cvt_flavour_u32_f64:
15235 sz = 1;
15236 op = 0;
15237 break;
15238 case neon_cvt_flavour_u32_f32:
15239 sz = 0;
15240 op = 0;
15241 break;
15242 default:
15243 first_error (_("invalid instruction shape"));
15244 return;
15245 }
15246
15247 switch (mode)
15248 {
15249 case neon_cvt_mode_a: rm = 0; break;
15250 case neon_cvt_mode_n: rm = 1; break;
15251 case neon_cvt_mode_p: rm = 2; break;
15252 case neon_cvt_mode_m: rm = 3; break;
15253 default: first_error (_("invalid rounding mode")); return;
15254 }
15255
15256 NEON_ENCODE (FPV8, inst);
15257 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15258 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15259 inst.instruction |= sz << 8;
15260 inst.instruction |= op << 7;
15261 inst.instruction |= rm << 16;
15262 inst.instruction |= 0xf0000000;
15263 inst.is_neon = TRUE;
15264}
15265
15266static void
15267do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15268{
15269 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 15270 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 15271 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15272
e3e535bc 15273 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15274 if (mode == neon_cvt_mode_z
e3e535bc 15275 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15276 && (flavour == neon_cvt_flavour_s32_f32
15277 || flavour == neon_cvt_flavour_u32_f32
15278 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15279 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15280 && (rs == NS_FD || rs == NS_FF))
15281 {
15282 do_vfp_nsyn_cvtz ();
15283 return;
15284 }
15285
037e8744 15286 /* VFP rather than Neon conversions. */
6b9a8b67 15287 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15288 {
7e8e6784
MGD
15289 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15290 do_vfp_nsyn_cvt (rs, flavour);
15291 else
15292 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15293
037e8744
JB
15294 return;
15295 }
15296
15297 switch (rs)
15298 {
15299 case NS_DDI:
15300 case NS_QQI:
15301 {
477330fc
RM
15302 unsigned immbits;
15303 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15304
477330fc
RM
15305 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15306 return;
037e8744 15307
477330fc
RM
15308 /* Fixed-point conversion with #0 immediate is encoded as an
15309 integer conversion. */
15310 if (inst.operands[2].present && inst.operands[2].imm == 0)
15311 goto int_encode;
35997600 15312 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15313 NEON_ENCODE (IMMED, inst);
15314 if (flavour != neon_cvt_flavour_invalid)
15315 inst.instruction |= enctab[flavour];
15316 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15317 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15318 inst.instruction |= LOW4 (inst.operands[1].reg);
15319 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15320 inst.instruction |= neon_quad (rs) << 6;
15321 inst.instruction |= 1 << 21;
15322 inst.instruction |= immbits << 16;
15323
15324 neon_dp_fixup (&inst);
037e8744
JB
15325 }
15326 break;
15327
15328 case NS_DD:
15329 case NS_QQ:
7e8e6784
MGD
15330 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15331 {
15332 NEON_ENCODE (FLOAT, inst);
15333 set_it_insn_type (OUTSIDE_IT_INSN);
15334
15335 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15336 return;
15337
15338 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15339 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15340 inst.instruction |= LOW4 (inst.operands[1].reg);
15341 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15342 inst.instruction |= neon_quad (rs) << 6;
15343 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15344 inst.instruction |= mode << 8;
15345 if (thumb_mode)
15346 inst.instruction |= 0xfc000000;
15347 else
15348 inst.instruction |= 0xf0000000;
15349 }
15350 else
15351 {
037e8744 15352 int_encode:
7e8e6784
MGD
15353 {
15354 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15355
7e8e6784 15356 NEON_ENCODE (INTEGER, inst);
037e8744 15357
7e8e6784
MGD
15358 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15359 return;
037e8744 15360
7e8e6784
MGD
15361 if (flavour != neon_cvt_flavour_invalid)
15362 inst.instruction |= enctab[flavour];
037e8744 15363
7e8e6784
MGD
15364 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15365 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15366 inst.instruction |= LOW4 (inst.operands[1].reg);
15367 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15368 inst.instruction |= neon_quad (rs) << 6;
15369 inst.instruction |= 2 << 18;
037e8744 15370
7e8e6784
MGD
15371 neon_dp_fixup (&inst);
15372 }
15373 }
15374 break;
037e8744 15375
8e79c3df
CM
15376 /* Half-precision conversions for Advanced SIMD -- neon. */
15377 case NS_QD:
15378 case NS_DQ:
15379
15380 if ((rs == NS_DQ)
15381 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15382 {
15383 as_bad (_("operand size must match register width"));
15384 break;
15385 }
15386
15387 if ((rs == NS_QD)
15388 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15389 {
15390 as_bad (_("operand size must match register width"));
15391 break;
15392 }
15393
15394 if (rs == NS_DQ)
477330fc 15395 inst.instruction = 0x3b60600;
8e79c3df
CM
15396 else
15397 inst.instruction = 0x3b60700;
15398
15399 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15400 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15401 inst.instruction |= LOW4 (inst.operands[1].reg);
15402 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15403 neon_dp_fixup (&inst);
8e79c3df
CM
15404 break;
15405
037e8744
JB
15406 default:
15407 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15408 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15409 do_vfp_nsyn_cvt (rs, flavour);
15410 else
15411 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15412 }
5287ad62
JB
15413}
15414
e3e535bc
NC
15415static void
15416do_neon_cvtr (void)
15417{
7e8e6784 15418 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15419}
15420
15421static void
15422do_neon_cvt (void)
15423{
7e8e6784
MGD
15424 do_neon_cvt_1 (neon_cvt_mode_z);
15425}
15426
15427static void
15428do_neon_cvta (void)
15429{
15430 do_neon_cvt_1 (neon_cvt_mode_a);
15431}
15432
15433static void
15434do_neon_cvtn (void)
15435{
15436 do_neon_cvt_1 (neon_cvt_mode_n);
15437}
15438
15439static void
15440do_neon_cvtp (void)
15441{
15442 do_neon_cvt_1 (neon_cvt_mode_p);
15443}
15444
15445static void
15446do_neon_cvtm (void)
15447{
15448 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15449}
15450
8e79c3df 15451static void
c70a8987 15452do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15453{
c70a8987
MGD
15454 if (is_double)
15455 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15456
c70a8987
MGD
15457 encode_arm_vfp_reg (inst.operands[0].reg,
15458 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15459 encode_arm_vfp_reg (inst.operands[1].reg,
15460 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15461 inst.instruction |= to ? 0x10000 : 0;
15462 inst.instruction |= t ? 0x80 : 0;
15463 inst.instruction |= is_double ? 0x100 : 0;
15464 do_vfp_cond_or_thumb ();
15465}
8e79c3df 15466
c70a8987
MGD
15467static void
15468do_neon_cvttb_1 (bfd_boolean t)
15469{
15470 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 15471
c70a8987
MGD
15472 if (rs == NS_NULL)
15473 return;
15474 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15475 {
15476 inst.error = NULL;
15477 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15478 }
15479 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15480 {
15481 inst.error = NULL;
15482 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15483 }
15484 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15485 {
a715796b
TG
15486 /* The VCVTB and VCVTT instructions with D-register operands
15487 don't work for SP only targets. */
15488 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15489 _(BAD_FPU));
15490
c70a8987
MGD
15491 inst.error = NULL;
15492 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15493 }
15494 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15495 {
a715796b
TG
15496 /* The VCVTB and VCVTT instructions with D-register operands
15497 don't work for SP only targets. */
15498 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15499 _(BAD_FPU));
15500
c70a8987
MGD
15501 inst.error = NULL;
15502 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15503 }
15504 else
15505 return;
15506}
15507
15508static void
15509do_neon_cvtb (void)
15510{
15511 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15512}
15513
15514
15515static void
15516do_neon_cvtt (void)
15517{
c70a8987 15518 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15519}
15520
5287ad62
JB
15521static void
15522neon_move_immediate (void)
15523{
037e8744
JB
15524 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15525 struct neon_type_el et = neon_check_type (2, rs,
15526 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15527 unsigned immlo, immhi = 0, immbits;
c96612cc 15528 int op, cmode, float_p;
5287ad62 15529
037e8744 15530 constraint (et.type == NT_invtype,
477330fc 15531 _("operand size must be specified for immediate VMOV"));
037e8744 15532
5287ad62
JB
15533 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15534 op = (inst.instruction & (1 << 5)) != 0;
15535
15536 immlo = inst.operands[1].imm;
15537 if (inst.operands[1].regisimm)
15538 immhi = inst.operands[1].reg;
15539
15540 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15541 _("immediate has bits set outside the operand size"));
5287ad62 15542
c96612cc
JB
15543 float_p = inst.operands[1].immisfloat;
15544
15545 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15546 et.size, et.type)) == FAIL)
5287ad62
JB
15547 {
15548 /* Invert relevant bits only. */
15549 neon_invert_size (&immlo, &immhi, et.size);
15550 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15551 with one or the other; those cases are caught by
15552 neon_cmode_for_move_imm. */
5287ad62 15553 op = !op;
c96612cc
JB
15554 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15555 &op, et.size, et.type)) == FAIL)
477330fc
RM
15556 {
15557 first_error (_("immediate out of range"));
15558 return;
15559 }
5287ad62
JB
15560 }
15561
15562 inst.instruction &= ~(1 << 5);
15563 inst.instruction |= op << 5;
15564
15565 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15566 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15567 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15568 inst.instruction |= cmode << 8;
15569
15570 neon_write_immbits (immbits);
15571}
15572
15573static void
15574do_neon_mvn (void)
15575{
15576 if (inst.operands[1].isreg)
15577 {
037e8744 15578 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15579
88714cb8 15580 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15581 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15582 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15583 inst.instruction |= LOW4 (inst.operands[1].reg);
15584 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15585 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15586 }
15587 else
15588 {
88714cb8 15589 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15590 neon_move_immediate ();
15591 }
15592
88714cb8 15593 neon_dp_fixup (&inst);
5287ad62
JB
15594}
15595
15596/* Encode instructions of form:
15597
15598 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15599 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15600
15601static void
15602neon_mixed_length (struct neon_type_el et, unsigned size)
15603{
15604 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15605 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15606 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15607 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15608 inst.instruction |= LOW4 (inst.operands[2].reg);
15609 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15610 inst.instruction |= (et.type == NT_unsigned) << 24;
15611 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15612
88714cb8 15613 neon_dp_fixup (&inst);
5287ad62
JB
15614}
15615
15616static void
15617do_neon_dyadic_long (void)
15618{
15619 /* FIXME: Type checking for lengthening op. */
15620 struct neon_type_el et = neon_check_type (3, NS_QDD,
15621 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15622 neon_mixed_length (et, et.size);
15623}
15624
15625static void
15626do_neon_abal (void)
15627{
15628 struct neon_type_el et = neon_check_type (3, NS_QDD,
15629 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15630 neon_mixed_length (et, et.size);
15631}
15632
15633static void
15634neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15635{
15636 if (inst.operands[2].isscalar)
15637 {
dcbf9037 15638 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15639 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15640 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15641 neon_mul_mac (et, et.type == NT_unsigned);
15642 }
15643 else
15644 {
15645 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15646 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15647 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15648 neon_mixed_length (et, et.size);
15649 }
15650}
15651
15652static void
15653do_neon_mac_maybe_scalar_long (void)
15654{
15655 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15656}
15657
15658static void
15659do_neon_dyadic_wide (void)
15660{
15661 struct neon_type_el et = neon_check_type (3, NS_QQD,
15662 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15663 neon_mixed_length (et, et.size);
15664}
15665
15666static void
15667do_neon_dyadic_narrow (void)
15668{
15669 struct neon_type_el et = neon_check_type (3, NS_QDD,
15670 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15671 /* Operand sign is unimportant, and the U bit is part of the opcode,
15672 so force the operand type to integer. */
15673 et.type = NT_integer;
5287ad62
JB
15674 neon_mixed_length (et, et.size / 2);
15675}
15676
15677static void
15678do_neon_mul_sat_scalar_long (void)
15679{
15680 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15681}
15682
15683static void
15684do_neon_vmull (void)
15685{
15686 if (inst.operands[2].isscalar)
15687 do_neon_mac_maybe_scalar_long ();
15688 else
15689 {
15690 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15691 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15692
5287ad62 15693 if (et.type == NT_poly)
477330fc 15694 NEON_ENCODE (POLY, inst);
5287ad62 15695 else
477330fc 15696 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15697
15698 /* For polynomial encoding the U bit must be zero, and the size must
15699 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15700 obviously, as 0b10). */
15701 if (et.size == 64)
15702 {
15703 /* Check we're on the correct architecture. */
15704 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15705 inst.error =
15706 _("Instruction form not available on this architecture.");
15707
15708 et.size = 32;
15709 }
15710
5287ad62
JB
15711 neon_mixed_length (et, et.size);
15712 }
15713}
15714
15715static void
15716do_neon_ext (void)
15717{
037e8744 15718 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15719 struct neon_type_el et = neon_check_type (3, rs,
15720 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15721 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15722
15723 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15724 _("shift out of range"));
5287ad62
JB
15725 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15726 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15727 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15728 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15729 inst.instruction |= LOW4 (inst.operands[2].reg);
15730 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15731 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15732 inst.instruction |= imm << 8;
5f4273c7 15733
88714cb8 15734 neon_dp_fixup (&inst);
5287ad62
JB
15735}
15736
15737static void
15738do_neon_rev (void)
15739{
037e8744 15740 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15741 struct neon_type_el et = neon_check_type (2, rs,
15742 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15743 unsigned op = (inst.instruction >> 7) & 3;
15744 /* N (width of reversed regions) is encoded as part of the bitmask. We
15745 extract it here to check the elements to be reversed are smaller.
15746 Otherwise we'd get a reserved instruction. */
15747 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15748 gas_assert (elsize != 0);
5287ad62 15749 constraint (et.size >= elsize,
477330fc 15750 _("elements must be smaller than reversal region"));
037e8744 15751 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15752}
15753
15754static void
15755do_neon_dup (void)
15756{
15757 if (inst.operands[1].isscalar)
15758 {
037e8744 15759 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 15760 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15761 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15762 unsigned sizebits = et.size >> 3;
dcbf9037 15763 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15764 int logsize = neon_logbits (et.size);
dcbf9037 15765 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15766
15767 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 15768 return;
037e8744 15769
88714cb8 15770 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15771 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15772 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15773 inst.instruction |= LOW4 (dm);
15774 inst.instruction |= HI1 (dm) << 5;
037e8744 15775 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15776 inst.instruction |= x << 17;
15777 inst.instruction |= sizebits << 16;
5f4273c7 15778
88714cb8 15779 neon_dp_fixup (&inst);
5287ad62
JB
15780 }
15781 else
15782 {
037e8744
JB
15783 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15784 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15785 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15786 /* Duplicate ARM register to lanes of vector. */
88714cb8 15787 NEON_ENCODE (ARMREG, inst);
5287ad62 15788 switch (et.size)
477330fc
RM
15789 {
15790 case 8: inst.instruction |= 0x400000; break;
15791 case 16: inst.instruction |= 0x000020; break;
15792 case 32: inst.instruction |= 0x000000; break;
15793 default: break;
15794 }
5287ad62
JB
15795 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15796 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15797 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15798 inst.instruction |= neon_quad (rs) << 21;
5287ad62 15799 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 15800 variants, except for the condition field. */
037e8744 15801 do_vfp_cond_or_thumb ();
5287ad62
JB
15802 }
15803}
15804
15805/* VMOV has particularly many variations. It can be one of:
15806 0. VMOV<c><q> <Qd>, <Qm>
15807 1. VMOV<c><q> <Dd>, <Dm>
15808 (Register operations, which are VORR with Rm = Rn.)
15809 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15810 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15811 (Immediate loads.)
15812 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15813 (ARM register to scalar.)
15814 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15815 (Two ARM registers to vector.)
15816 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15817 (Scalar to ARM register.)
15818 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15819 (Vector to two ARM registers.)
037e8744
JB
15820 8. VMOV.F32 <Sd>, <Sm>
15821 9. VMOV.F64 <Dd>, <Dm>
15822 (VFP register moves.)
15823 10. VMOV.F32 <Sd>, #imm
15824 11. VMOV.F64 <Dd>, #imm
15825 (VFP float immediate load.)
15826 12. VMOV <Rd>, <Sm>
15827 (VFP single to ARM reg.)
15828 13. VMOV <Sd>, <Rm>
15829 (ARM reg to VFP single.)
15830 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15831 (Two ARM regs to two VFP singles.)
15832 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15833 (Two VFP singles to two ARM regs.)
5f4273c7 15834
037e8744
JB
15835 These cases can be disambiguated using neon_select_shape, except cases 1/9
15836 and 3/11 which depend on the operand type too.
5f4273c7 15837
5287ad62 15838 All the encoded bits are hardcoded by this function.
5f4273c7 15839
b7fc2769
JB
15840 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15841 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15842
5287ad62 15843 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15844 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15845
15846static void
15847do_neon_mov (void)
15848{
037e8744
JB
15849 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15850 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15851 NS_NULL);
15852 struct neon_type_el et;
15853 const char *ldconst = 0;
5287ad62 15854
037e8744 15855 switch (rs)
5287ad62 15856 {
037e8744
JB
15857 case NS_DD: /* case 1/9. */
15858 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15859 /* It is not an error here if no type is given. */
15860 inst.error = NULL;
15861 if (et.type == NT_float && et.size == 64)
477330fc
RM
15862 {
15863 do_vfp_nsyn_opcode ("fcpyd");
15864 break;
15865 }
037e8744 15866 /* fall through. */
5287ad62 15867
037e8744
JB
15868 case NS_QQ: /* case 0/1. */
15869 {
477330fc
RM
15870 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15871 return;
15872 /* The architecture manual I have doesn't explicitly state which
15873 value the U bit should have for register->register moves, but
15874 the equivalent VORR instruction has U = 0, so do that. */
15875 inst.instruction = 0x0200110;
15876 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15877 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15878 inst.instruction |= LOW4 (inst.operands[1].reg);
15879 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15880 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15881 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15882 inst.instruction |= neon_quad (rs) << 6;
15883
15884 neon_dp_fixup (&inst);
037e8744
JB
15885 }
15886 break;
5f4273c7 15887
037e8744
JB
15888 case NS_DI: /* case 3/11. */
15889 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15890 inst.error = NULL;
15891 if (et.type == NT_float && et.size == 64)
477330fc
RM
15892 {
15893 /* case 11 (fconstd). */
15894 ldconst = "fconstd";
15895 goto encode_fconstd;
15896 }
037e8744
JB
15897 /* fall through. */
15898
15899 case NS_QI: /* case 2/3. */
15900 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 15901 return;
037e8744
JB
15902 inst.instruction = 0x0800010;
15903 neon_move_immediate ();
88714cb8 15904 neon_dp_fixup (&inst);
5287ad62 15905 break;
5f4273c7 15906
037e8744
JB
15907 case NS_SR: /* case 4. */
15908 {
477330fc
RM
15909 unsigned bcdebits = 0;
15910 int logsize;
15911 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15912 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 15913
05ac0ffb
JB
15914 /* .<size> is optional here, defaulting to .32. */
15915 if (inst.vectype.elems == 0
15916 && inst.operands[0].vectype.type == NT_invtype
15917 && inst.operands[1].vectype.type == NT_invtype)
15918 {
15919 inst.vectype.el[0].type = NT_untyped;
15920 inst.vectype.el[0].size = 32;
15921 inst.vectype.elems = 1;
15922 }
15923
477330fc
RM
15924 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15925 logsize = neon_logbits (et.size);
15926
15927 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15928 _(BAD_FPU));
15929 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15930 && et.size != 32, _(BAD_FPU));
15931 constraint (et.type == NT_invtype, _("bad type for scalar"));
15932 constraint (x >= 64 / et.size, _("scalar index out of range"));
15933
15934 switch (et.size)
15935 {
15936 case 8: bcdebits = 0x8; break;
15937 case 16: bcdebits = 0x1; break;
15938 case 32: bcdebits = 0x0; break;
15939 default: ;
15940 }
15941
15942 bcdebits |= x << logsize;
15943
15944 inst.instruction = 0xe000b10;
15945 do_vfp_cond_or_thumb ();
15946 inst.instruction |= LOW4 (dn) << 16;
15947 inst.instruction |= HI1 (dn) << 7;
15948 inst.instruction |= inst.operands[1].reg << 12;
15949 inst.instruction |= (bcdebits & 3) << 5;
15950 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
15951 }
15952 break;
5f4273c7 15953
037e8744 15954 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15955 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15956 _(BAD_FPU));
b7fc2769 15957
037e8744
JB
15958 inst.instruction = 0xc400b10;
15959 do_vfp_cond_or_thumb ();
15960 inst.instruction |= LOW4 (inst.operands[0].reg);
15961 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15962 inst.instruction |= inst.operands[1].reg << 12;
15963 inst.instruction |= inst.operands[2].reg << 16;
15964 break;
5f4273c7 15965
037e8744
JB
15966 case NS_RS: /* case 6. */
15967 {
477330fc
RM
15968 unsigned logsize;
15969 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15970 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15971 unsigned abcdebits = 0;
037e8744 15972
05ac0ffb
JB
15973 /* .<dt> is optional here, defaulting to .32. */
15974 if (inst.vectype.elems == 0
15975 && inst.operands[0].vectype.type == NT_invtype
15976 && inst.operands[1].vectype.type == NT_invtype)
15977 {
15978 inst.vectype.el[0].type = NT_untyped;
15979 inst.vectype.el[0].size = 32;
15980 inst.vectype.elems = 1;
15981 }
15982
91d6fa6a
NC
15983 et = neon_check_type (2, NS_NULL,
15984 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
15985 logsize = neon_logbits (et.size);
15986
15987 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15988 _(BAD_FPU));
15989 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15990 && et.size != 32, _(BAD_FPU));
15991 constraint (et.type == NT_invtype, _("bad type for scalar"));
15992 constraint (x >= 64 / et.size, _("scalar index out of range"));
15993
15994 switch (et.size)
15995 {
15996 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15997 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15998 case 32: abcdebits = 0x00; break;
15999 default: ;
16000 }
16001
16002 abcdebits |= x << logsize;
16003 inst.instruction = 0xe100b10;
16004 do_vfp_cond_or_thumb ();
16005 inst.instruction |= LOW4 (dn) << 16;
16006 inst.instruction |= HI1 (dn) << 7;
16007 inst.instruction |= inst.operands[0].reg << 12;
16008 inst.instruction |= (abcdebits & 3) << 5;
16009 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16010 }
16011 break;
5f4273c7 16012
037e8744
JB
16013 case NS_RRD: /* case 7 (fmrrd). */
16014 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16015 _(BAD_FPU));
037e8744
JB
16016
16017 inst.instruction = 0xc500b10;
16018 do_vfp_cond_or_thumb ();
16019 inst.instruction |= inst.operands[0].reg << 12;
16020 inst.instruction |= inst.operands[1].reg << 16;
16021 inst.instruction |= LOW4 (inst.operands[2].reg);
16022 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16023 break;
5f4273c7 16024
037e8744
JB
16025 case NS_FF: /* case 8 (fcpys). */
16026 do_vfp_nsyn_opcode ("fcpys");
16027 break;
5f4273c7 16028
037e8744
JB
16029 case NS_FI: /* case 10 (fconsts). */
16030 ldconst = "fconsts";
16031 encode_fconstd:
16032 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16033 {
16034 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16035 do_vfp_nsyn_opcode (ldconst);
16036 }
5287ad62 16037 else
477330fc 16038 first_error (_("immediate out of range"));
037e8744 16039 break;
5f4273c7 16040
037e8744
JB
16041 case NS_RF: /* case 12 (fmrs). */
16042 do_vfp_nsyn_opcode ("fmrs");
16043 break;
5f4273c7 16044
037e8744
JB
16045 case NS_FR: /* case 13 (fmsr). */
16046 do_vfp_nsyn_opcode ("fmsr");
16047 break;
5f4273c7 16048
037e8744
JB
16049 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16050 (one of which is a list), but we have parsed four. Do some fiddling to
16051 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16052 expect. */
16053 case NS_RRFF: /* case 14 (fmrrs). */
16054 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16055 _("VFP registers must be adjacent"));
037e8744
JB
16056 inst.operands[2].imm = 2;
16057 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16058 do_vfp_nsyn_opcode ("fmrrs");
16059 break;
5f4273c7 16060
037e8744
JB
16061 case NS_FFRR: /* case 15 (fmsrr). */
16062 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16063 _("VFP registers must be adjacent"));
037e8744
JB
16064 inst.operands[1] = inst.operands[2];
16065 inst.operands[2] = inst.operands[3];
16066 inst.operands[0].imm = 2;
16067 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16068 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16069 break;
5f4273c7 16070
4c261dff
NC
16071 case NS_NULL:
16072 /* neon_select_shape has determined that the instruction
16073 shape is wrong and has already set the error message. */
16074 break;
16075
5287ad62
JB
16076 default:
16077 abort ();
16078 }
16079}
16080
16081static void
16082do_neon_rshift_round_imm (void)
16083{
037e8744 16084 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16085 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16086 int imm = inst.operands[2].imm;
16087
16088 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16089 if (imm == 0)
16090 {
16091 inst.operands[2].present = 0;
16092 do_neon_mov ();
16093 return;
16094 }
16095
16096 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16097 _("immediate out of range for shift"));
037e8744 16098 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16099 et.size - imm);
5287ad62
JB
16100}
16101
16102static void
16103do_neon_movl (void)
16104{
16105 struct neon_type_el et = neon_check_type (2, NS_QD,
16106 N_EQK | N_DBL, N_SU_32 | N_KEY);
16107 unsigned sizebits = et.size >> 3;
16108 inst.instruction |= sizebits << 19;
16109 neon_two_same (0, et.type == NT_unsigned, -1);
16110}
16111
16112static void
16113do_neon_trn (void)
16114{
037e8744 16115 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16116 struct neon_type_el et = neon_check_type (2, rs,
16117 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16118 NEON_ENCODE (INTEGER, inst);
037e8744 16119 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16120}
16121
16122static void
16123do_neon_zip_uzp (void)
16124{
037e8744 16125 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16126 struct neon_type_el et = neon_check_type (2, rs,
16127 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16128 if (rs == NS_DD && et.size == 32)
16129 {
16130 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16131 inst.instruction = N_MNEM_vtrn;
16132 do_neon_trn ();
16133 return;
16134 }
037e8744 16135 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16136}
16137
16138static void
16139do_neon_sat_abs_neg (void)
16140{
037e8744 16141 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16142 struct neon_type_el et = neon_check_type (2, rs,
16143 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16144 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16145}
16146
16147static void
16148do_neon_pair_long (void)
16149{
037e8744 16150 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16151 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16152 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16153 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16154 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16155}
16156
16157static void
16158do_neon_recip_est (void)
16159{
037e8744 16160 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16161 struct neon_type_el et = neon_check_type (2, rs,
16162 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16163 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16164 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16165}
16166
16167static void
16168do_neon_cls (void)
16169{
037e8744 16170 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16171 struct neon_type_el et = neon_check_type (2, rs,
16172 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16173 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16174}
16175
16176static void
16177do_neon_clz (void)
16178{
037e8744 16179 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16180 struct neon_type_el et = neon_check_type (2, rs,
16181 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16182 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16183}
16184
16185static void
16186do_neon_cnt (void)
16187{
037e8744 16188 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16189 struct neon_type_el et = neon_check_type (2, rs,
16190 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16191 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16192}
16193
16194static void
16195do_neon_swp (void)
16196{
037e8744
JB
16197 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16198 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16199}
16200
16201static void
16202do_neon_tbl_tbx (void)
16203{
16204 unsigned listlenbits;
dcbf9037 16205 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16206
5287ad62
JB
16207 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16208 {
dcbf9037 16209 first_error (_("bad list length for table lookup"));
5287ad62
JB
16210 return;
16211 }
5f4273c7 16212
5287ad62
JB
16213 listlenbits = inst.operands[1].imm - 1;
16214 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16215 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16216 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16217 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16218 inst.instruction |= LOW4 (inst.operands[2].reg);
16219 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16220 inst.instruction |= listlenbits << 8;
5f4273c7 16221
88714cb8 16222 neon_dp_fixup (&inst);
5287ad62
JB
16223}
16224
16225static void
16226do_neon_ldm_stm (void)
16227{
16228 /* P, U and L bits are part of bitmask. */
16229 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16230 unsigned offsetbits = inst.operands[1].imm * 2;
16231
037e8744
JB
16232 if (inst.operands[1].issingle)
16233 {
16234 do_vfp_nsyn_ldm_stm (is_dbmode);
16235 return;
16236 }
16237
5287ad62 16238 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16239 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16240
16241 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16242 _("register list must contain at least 1 and at most 16 "
16243 "registers"));
5287ad62
JB
16244
16245 inst.instruction |= inst.operands[0].reg << 16;
16246 inst.instruction |= inst.operands[0].writeback << 21;
16247 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16248 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16249
16250 inst.instruction |= offsetbits;
5f4273c7 16251
037e8744 16252 do_vfp_cond_or_thumb ();
5287ad62
JB
16253}
16254
16255static void
16256do_neon_ldr_str (void)
16257{
5287ad62 16258 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16259
6844b2c2
MGD
16260 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16261 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16262 if (!is_ldr
6844b2c2 16263 && inst.operands[1].reg == REG_PC
ba86b375 16264 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16265 {
94dcf8bf 16266 if (thumb_mode)
6844b2c2 16267 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16268 else if (warn_on_deprecated)
5c3696f8 16269 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16270 }
16271
037e8744
JB
16272 if (inst.operands[0].issingle)
16273 {
cd2f129f 16274 if (is_ldr)
477330fc 16275 do_vfp_nsyn_opcode ("flds");
cd2f129f 16276 else
477330fc 16277 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
16278 }
16279 else
5287ad62 16280 {
cd2f129f 16281 if (is_ldr)
477330fc 16282 do_vfp_nsyn_opcode ("fldd");
5287ad62 16283 else
477330fc 16284 do_vfp_nsyn_opcode ("fstd");
5287ad62 16285 }
5287ad62
JB
16286}
16287
16288/* "interleave" version also handles non-interleaving register VLD1/VST1
16289 instructions. */
16290
16291static void
16292do_neon_ld_st_interleave (void)
16293{
037e8744 16294 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16295 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16296 unsigned alignbits = 0;
16297 unsigned idx;
16298 /* The bits in this table go:
16299 0: register stride of one (0) or two (1)
16300 1,2: register list length, minus one (1, 2, 3, 4).
16301 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16302 We use -1 for invalid entries. */
16303 const int typetable[] =
16304 {
16305 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16306 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16307 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16308 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16309 };
16310 int typebits;
16311
dcbf9037
JB
16312 if (et.type == NT_invtype)
16313 return;
16314
5287ad62
JB
16315 if (inst.operands[1].immisalign)
16316 switch (inst.operands[1].imm >> 8)
16317 {
16318 case 64: alignbits = 1; break;
16319 case 128:
477330fc 16320 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16321 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16322 goto bad_alignment;
16323 alignbits = 2;
16324 break;
5287ad62 16325 case 256:
477330fc
RM
16326 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16327 goto bad_alignment;
16328 alignbits = 3;
16329 break;
5287ad62
JB
16330 default:
16331 bad_alignment:
477330fc
RM
16332 first_error (_("bad alignment"));
16333 return;
5287ad62
JB
16334 }
16335
16336 inst.instruction |= alignbits << 4;
16337 inst.instruction |= neon_logbits (et.size) << 6;
16338
16339 /* Bits [4:6] of the immediate in a list specifier encode register stride
16340 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16341 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16342 up the right value for "type" in a table based on this value and the given
16343 list style, then stick it back. */
16344 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16345 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16346
16347 typebits = typetable[idx];
5f4273c7 16348
5287ad62 16349 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16350 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16351 _("bad element type for instruction"));
5287ad62
JB
16352
16353 inst.instruction &= ~0xf00;
16354 inst.instruction |= typebits << 8;
16355}
16356
16357/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16358 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16359 otherwise. The variable arguments are a list of pairs of legal (size, align)
16360 values, terminated with -1. */
16361
16362static int
16363neon_alignment_bit (int size, int align, int *do_align, ...)
16364{
16365 va_list ap;
16366 int result = FAIL, thissize, thisalign;
5f4273c7 16367
5287ad62
JB
16368 if (!inst.operands[1].immisalign)
16369 {
16370 *do_align = 0;
16371 return SUCCESS;
16372 }
5f4273c7 16373
5287ad62
JB
16374 va_start (ap, do_align);
16375
16376 do
16377 {
16378 thissize = va_arg (ap, int);
16379 if (thissize == -1)
477330fc 16380 break;
5287ad62
JB
16381 thisalign = va_arg (ap, int);
16382
16383 if (size == thissize && align == thisalign)
477330fc 16384 result = SUCCESS;
5287ad62
JB
16385 }
16386 while (result != SUCCESS);
16387
16388 va_end (ap);
16389
16390 if (result == SUCCESS)
16391 *do_align = 1;
16392 else
dcbf9037 16393 first_error (_("unsupported alignment for instruction"));
5f4273c7 16394
5287ad62
JB
16395 return result;
16396}
16397
16398static void
16399do_neon_ld_st_lane (void)
16400{
037e8744 16401 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16402 int align_good, do_align = 0;
16403 int logsize = neon_logbits (et.size);
16404 int align = inst.operands[1].imm >> 8;
16405 int n = (inst.instruction >> 8) & 3;
16406 int max_el = 64 / et.size;
5f4273c7 16407
dcbf9037
JB
16408 if (et.type == NT_invtype)
16409 return;
5f4273c7 16410
5287ad62 16411 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16412 _("bad list length"));
5287ad62 16413 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16414 _("scalar index out of range"));
5287ad62 16415 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16416 && et.size == 8,
16417 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16418
5287ad62
JB
16419 switch (n)
16420 {
16421 case 0: /* VLD1 / VST1. */
16422 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16423 32, 32, -1);
5287ad62 16424 if (align_good == FAIL)
477330fc 16425 return;
5287ad62 16426 if (do_align)
477330fc
RM
16427 {
16428 unsigned alignbits = 0;
16429 switch (et.size)
16430 {
16431 case 16: alignbits = 0x1; break;
16432 case 32: alignbits = 0x3; break;
16433 default: ;
16434 }
16435 inst.instruction |= alignbits << 4;
16436 }
5287ad62
JB
16437 break;
16438
16439 case 1: /* VLD2 / VST2. */
16440 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16441 32, 64, -1);
5287ad62 16442 if (align_good == FAIL)
477330fc 16443 return;
5287ad62 16444 if (do_align)
477330fc 16445 inst.instruction |= 1 << 4;
5287ad62
JB
16446 break;
16447
16448 case 2: /* VLD3 / VST3. */
16449 constraint (inst.operands[1].immisalign,
477330fc 16450 _("can't use alignment with this instruction"));
5287ad62
JB
16451 break;
16452
16453 case 3: /* VLD4 / VST4. */
16454 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16455 16, 64, 32, 64, 32, 128, -1);
5287ad62 16456 if (align_good == FAIL)
477330fc 16457 return;
5287ad62 16458 if (do_align)
477330fc
RM
16459 {
16460 unsigned alignbits = 0;
16461 switch (et.size)
16462 {
16463 case 8: alignbits = 0x1; break;
16464 case 16: alignbits = 0x1; break;
16465 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16466 default: ;
16467 }
16468 inst.instruction |= alignbits << 4;
16469 }
5287ad62
JB
16470 break;
16471
16472 default: ;
16473 }
16474
16475 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16476 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16477 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16478
5287ad62
JB
16479 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16480 inst.instruction |= logsize << 10;
16481}
16482
16483/* Encode single n-element structure to all lanes VLD<n> instructions. */
16484
16485static void
16486do_neon_ld_dup (void)
16487{
037e8744 16488 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16489 int align_good, do_align = 0;
16490
dcbf9037
JB
16491 if (et.type == NT_invtype)
16492 return;
16493
5287ad62
JB
16494 switch ((inst.instruction >> 8) & 3)
16495 {
16496 case 0: /* VLD1. */
9c2799c2 16497 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16498 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16499 &do_align, 16, 16, 32, 32, -1);
5287ad62 16500 if (align_good == FAIL)
477330fc 16501 return;
5287ad62 16502 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16503 {
16504 case 1: break;
16505 case 2: inst.instruction |= 1 << 5; break;
16506 default: first_error (_("bad list length")); return;
16507 }
5287ad62
JB
16508 inst.instruction |= neon_logbits (et.size) << 6;
16509 break;
16510
16511 case 1: /* VLD2. */
16512 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16513 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16514 if (align_good == FAIL)
477330fc 16515 return;
5287ad62 16516 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16517 _("bad list length"));
5287ad62 16518 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16519 inst.instruction |= 1 << 5;
5287ad62
JB
16520 inst.instruction |= neon_logbits (et.size) << 6;
16521 break;
16522
16523 case 2: /* VLD3. */
16524 constraint (inst.operands[1].immisalign,
477330fc 16525 _("can't use alignment with this instruction"));
5287ad62 16526 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16527 _("bad list length"));
5287ad62 16528 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16529 inst.instruction |= 1 << 5;
5287ad62
JB
16530 inst.instruction |= neon_logbits (et.size) << 6;
16531 break;
16532
16533 case 3: /* VLD4. */
16534 {
477330fc
RM
16535 int align = inst.operands[1].imm >> 8;
16536 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16537 16, 64, 32, 64, 32, 128, -1);
16538 if (align_good == FAIL)
16539 return;
16540 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16541 _("bad list length"));
16542 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16543 inst.instruction |= 1 << 5;
16544 if (et.size == 32 && align == 128)
16545 inst.instruction |= 0x3 << 6;
16546 else
16547 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16548 }
16549 break;
16550
16551 default: ;
16552 }
16553
16554 inst.instruction |= do_align << 4;
16555}
16556
16557/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16558 apart from bits [11:4]. */
16559
16560static void
16561do_neon_ldx_stx (void)
16562{
b1a769ed
DG
16563 if (inst.operands[1].isreg)
16564 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16565
5287ad62
JB
16566 switch (NEON_LANE (inst.operands[0].imm))
16567 {
16568 case NEON_INTERLEAVE_LANES:
88714cb8 16569 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16570 do_neon_ld_st_interleave ();
16571 break;
5f4273c7 16572
5287ad62 16573 case NEON_ALL_LANES:
88714cb8 16574 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16575 if (inst.instruction == N_INV)
16576 {
16577 first_error ("only loads support such operands");
16578 break;
16579 }
5287ad62
JB
16580 do_neon_ld_dup ();
16581 break;
5f4273c7 16582
5287ad62 16583 default:
88714cb8 16584 NEON_ENCODE (LANE, inst);
5287ad62
JB
16585 do_neon_ld_st_lane ();
16586 }
16587
16588 /* L bit comes from bit mask. */
16589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16591 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16592
5287ad62
JB
16593 if (inst.operands[1].postind)
16594 {
16595 int postreg = inst.operands[1].imm & 0xf;
16596 constraint (!inst.operands[1].immisreg,
477330fc 16597 _("post-index must be a register"));
5287ad62 16598 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16599 _("bad register for post-index"));
5287ad62
JB
16600 inst.instruction |= postreg;
16601 }
4f2374c7 16602 else
5287ad62 16603 {
4f2374c7
WN
16604 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16605 constraint (inst.reloc.exp.X_op != O_constant
16606 || inst.reloc.exp.X_add_number != 0,
16607 BAD_ADDR_MODE);
16608
16609 if (inst.operands[1].writeback)
16610 {
16611 inst.instruction |= 0xd;
16612 }
16613 else
16614 inst.instruction |= 0xf;
5287ad62 16615 }
5f4273c7 16616
5287ad62
JB
16617 if (thumb_mode)
16618 inst.instruction |= 0xf9000000;
16619 else
16620 inst.instruction |= 0xf4000000;
16621}
33399f07
MGD
16622
16623/* FP v8. */
16624static void
16625do_vfp_nsyn_fpv8 (enum neon_shape rs)
16626{
a715796b
TG
16627 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16628 D register operands. */
16629 if (neon_shape_class[rs] == SC_DOUBLE)
16630 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16631 _(BAD_FPU));
16632
33399f07
MGD
16633 NEON_ENCODE (FPV8, inst);
16634
16635 if (rs == NS_FFF)
16636 do_vfp_sp_dyadic ();
16637 else
16638 do_vfp_dp_rd_rn_rm ();
16639
16640 if (rs == NS_DDD)
16641 inst.instruction |= 0x100;
16642
16643 inst.instruction |= 0xf0000000;
16644}
16645
16646static void
16647do_vsel (void)
16648{
16649 set_it_insn_type (OUTSIDE_IT_INSN);
16650
16651 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16652 first_error (_("invalid instruction shape"));
16653}
16654
73924fbc
MGD
16655static void
16656do_vmaxnm (void)
16657{
16658 set_it_insn_type (OUTSIDE_IT_INSN);
16659
16660 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16661 return;
16662
16663 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16664 return;
16665
16666 neon_dyadic_misc (NT_untyped, N_F32, 0);
16667}
16668
30bdf752
MGD
16669static void
16670do_vrint_1 (enum neon_cvt_mode mode)
16671{
16672 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16673 struct neon_type_el et;
16674
16675 if (rs == NS_NULL)
16676 return;
16677
a715796b
TG
16678 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16679 D register operands. */
16680 if (neon_shape_class[rs] == SC_DOUBLE)
16681 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16682 _(BAD_FPU));
16683
30bdf752
MGD
16684 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16685 if (et.type != NT_invtype)
16686 {
16687 /* VFP encodings. */
16688 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16689 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16690 set_it_insn_type (OUTSIDE_IT_INSN);
16691
16692 NEON_ENCODE (FPV8, inst);
16693 if (rs == NS_FF)
16694 do_vfp_sp_monadic ();
16695 else
16696 do_vfp_dp_rd_rm ();
16697
16698 switch (mode)
16699 {
16700 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16701 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16702 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16703 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16704 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16705 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16706 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16707 default: abort ();
16708 }
16709
16710 inst.instruction |= (rs == NS_DD) << 8;
16711 do_vfp_cond_or_thumb ();
16712 }
16713 else
16714 {
16715 /* Neon encodings (or something broken...). */
16716 inst.error = NULL;
16717 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16718
16719 if (et.type == NT_invtype)
16720 return;
16721
16722 set_it_insn_type (OUTSIDE_IT_INSN);
16723 NEON_ENCODE (FLOAT, inst);
16724
16725 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16726 return;
16727
16728 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16729 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16730 inst.instruction |= LOW4 (inst.operands[1].reg);
16731 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16732 inst.instruction |= neon_quad (rs) << 6;
16733 switch (mode)
16734 {
16735 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16736 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16737 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16738 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16739 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16740 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16741 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16742 default: abort ();
16743 }
16744
16745 if (thumb_mode)
16746 inst.instruction |= 0xfc000000;
16747 else
16748 inst.instruction |= 0xf0000000;
16749 }
16750}
16751
16752static void
16753do_vrintx (void)
16754{
16755 do_vrint_1 (neon_cvt_mode_x);
16756}
16757
16758static void
16759do_vrintz (void)
16760{
16761 do_vrint_1 (neon_cvt_mode_z);
16762}
16763
16764static void
16765do_vrintr (void)
16766{
16767 do_vrint_1 (neon_cvt_mode_r);
16768}
16769
16770static void
16771do_vrinta (void)
16772{
16773 do_vrint_1 (neon_cvt_mode_a);
16774}
16775
16776static void
16777do_vrintn (void)
16778{
16779 do_vrint_1 (neon_cvt_mode_n);
16780}
16781
16782static void
16783do_vrintp (void)
16784{
16785 do_vrint_1 (neon_cvt_mode_p);
16786}
16787
16788static void
16789do_vrintm (void)
16790{
16791 do_vrint_1 (neon_cvt_mode_m);
16792}
16793
91ff7894
MGD
16794/* Crypto v1 instructions. */
16795static void
16796do_crypto_2op_1 (unsigned elttype, int op)
16797{
16798 set_it_insn_type (OUTSIDE_IT_INSN);
16799
16800 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16801 == NT_invtype)
16802 return;
16803
16804 inst.error = NULL;
16805
16806 NEON_ENCODE (INTEGER, inst);
16807 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16808 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16809 inst.instruction |= LOW4 (inst.operands[1].reg);
16810 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16811 if (op != -1)
16812 inst.instruction |= op << 6;
16813
16814 if (thumb_mode)
16815 inst.instruction |= 0xfc000000;
16816 else
16817 inst.instruction |= 0xf0000000;
16818}
16819
48adcd8e
MGD
16820static void
16821do_crypto_3op_1 (int u, int op)
16822{
16823 set_it_insn_type (OUTSIDE_IT_INSN);
16824
16825 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16826 N_32 | N_UNT | N_KEY).type == NT_invtype)
16827 return;
16828
16829 inst.error = NULL;
16830
16831 NEON_ENCODE (INTEGER, inst);
16832 neon_three_same (1, u, 8 << op);
16833}
16834
91ff7894
MGD
16835static void
16836do_aese (void)
16837{
16838 do_crypto_2op_1 (N_8, 0);
16839}
16840
16841static void
16842do_aesd (void)
16843{
16844 do_crypto_2op_1 (N_8, 1);
16845}
16846
16847static void
16848do_aesmc (void)
16849{
16850 do_crypto_2op_1 (N_8, 2);
16851}
16852
16853static void
16854do_aesimc (void)
16855{
16856 do_crypto_2op_1 (N_8, 3);
16857}
16858
48adcd8e
MGD
16859static void
16860do_sha1c (void)
16861{
16862 do_crypto_3op_1 (0, 0);
16863}
16864
16865static void
16866do_sha1p (void)
16867{
16868 do_crypto_3op_1 (0, 1);
16869}
16870
16871static void
16872do_sha1m (void)
16873{
16874 do_crypto_3op_1 (0, 2);
16875}
16876
16877static void
16878do_sha1su0 (void)
16879{
16880 do_crypto_3op_1 (0, 3);
16881}
91ff7894 16882
48adcd8e
MGD
16883static void
16884do_sha256h (void)
16885{
16886 do_crypto_3op_1 (1, 0);
16887}
16888
16889static void
16890do_sha256h2 (void)
16891{
16892 do_crypto_3op_1 (1, 1);
16893}
16894
16895static void
16896do_sha256su1 (void)
16897{
16898 do_crypto_3op_1 (1, 2);
16899}
3c9017d2
MGD
16900
16901static void
16902do_sha1h (void)
16903{
16904 do_crypto_2op_1 (N_32, -1);
16905}
16906
16907static void
16908do_sha1su1 (void)
16909{
16910 do_crypto_2op_1 (N_32, 0);
16911}
16912
16913static void
16914do_sha256su0 (void)
16915{
16916 do_crypto_2op_1 (N_32, 1);
16917}
dd5181d5
KT
16918
16919static void
16920do_crc32_1 (unsigned int poly, unsigned int sz)
16921{
16922 unsigned int Rd = inst.operands[0].reg;
16923 unsigned int Rn = inst.operands[1].reg;
16924 unsigned int Rm = inst.operands[2].reg;
16925
16926 set_it_insn_type (OUTSIDE_IT_INSN);
16927 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16928 inst.instruction |= LOW4 (Rn) << 16;
16929 inst.instruction |= LOW4 (Rm);
16930 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16931 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16932
16933 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16934 as_warn (UNPRED_REG ("r15"));
16935 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16936 as_warn (UNPRED_REG ("r13"));
16937}
16938
16939static void
16940do_crc32b (void)
16941{
16942 do_crc32_1 (0, 0);
16943}
16944
16945static void
16946do_crc32h (void)
16947{
16948 do_crc32_1 (0, 1);
16949}
16950
16951static void
16952do_crc32w (void)
16953{
16954 do_crc32_1 (0, 2);
16955}
16956
16957static void
16958do_crc32cb (void)
16959{
16960 do_crc32_1 (1, 0);
16961}
16962
16963static void
16964do_crc32ch (void)
16965{
16966 do_crc32_1 (1, 1);
16967}
16968
16969static void
16970do_crc32cw (void)
16971{
16972 do_crc32_1 (1, 2);
16973}
16974
5287ad62
JB
16975\f
16976/* Overall per-instruction processing. */
16977
16978/* We need to be able to fix up arbitrary expressions in some statements.
16979 This is so that we can handle symbols that are an arbitrary distance from
16980 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16981 which returns part of an address in a form which will be valid for
16982 a data instruction. We do this by pushing the expression into a symbol
16983 in the expr_section, and creating a fix for that. */
16984
16985static void
16986fix_new_arm (fragS * frag,
16987 int where,
16988 short int size,
16989 expressionS * exp,
16990 int pc_rel,
16991 int reloc)
16992{
16993 fixS * new_fix;
16994
16995 switch (exp->X_op)
16996 {
16997 case O_constant:
6e7ce2cd
PB
16998 if (pc_rel)
16999 {
17000 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17001 refer to in the object file. Unfortunately for us, gas's
17002 generic expression parsing will already have folded out
17003 any use of .set foo/.type foo %function that may have
17004 been used to set type information of the target location,
17005 that's being specified symbolically. We have to presume
17006 the user knows what they are doing. */
6e7ce2cd
PB
17007 char name[16 + 8];
17008 symbolS *symbol;
17009
17010 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17011
17012 symbol = symbol_find_or_make (name);
17013 S_SET_SEGMENT (symbol, absolute_section);
17014 symbol_set_frag (symbol, &zero_address_frag);
17015 S_SET_VALUE (symbol, exp->X_add_number);
17016 exp->X_op = O_symbol;
17017 exp->X_add_symbol = symbol;
17018 exp->X_add_number = 0;
17019 }
17020 /* FALLTHROUGH */
5287ad62
JB
17021 case O_symbol:
17022 case O_add:
17023 case O_subtract:
21d799b5 17024 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17025 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17026 break;
17027
17028 default:
21d799b5 17029 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17030 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17031 break;
17032 }
17033
17034 /* Mark whether the fix is to a THUMB instruction, or an ARM
17035 instruction. */
17036 new_fix->tc_fix_data = thumb_mode;
17037}
17038
17039/* Create a frg for an instruction requiring relaxation. */
17040static void
17041output_relax_insn (void)
17042{
17043 char * to;
17044 symbolS *sym;
0110f2b8
PB
17045 int offset;
17046
6e1cb1a6
PB
17047 /* The size of the instruction is unknown, so tie the debug info to the
17048 start of the instruction. */
17049 dwarf2_emit_insn (0);
6e1cb1a6 17050
0110f2b8
PB
17051 switch (inst.reloc.exp.X_op)
17052 {
17053 case O_symbol:
17054 sym = inst.reloc.exp.X_add_symbol;
17055 offset = inst.reloc.exp.X_add_number;
17056 break;
17057 case O_constant:
17058 sym = NULL;
17059 offset = inst.reloc.exp.X_add_number;
17060 break;
17061 default:
17062 sym = make_expr_symbol (&inst.reloc.exp);
17063 offset = 0;
17064 break;
17065 }
17066 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17067 inst.relax, sym, offset, NULL/*offset, opcode*/);
17068 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17069}
17070
17071/* Write a 32-bit thumb instruction to buf. */
17072static void
17073put_thumb32_insn (char * buf, unsigned long insn)
17074{
17075 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17076 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17077}
17078
b99bd4ef 17079static void
c19d1205 17080output_inst (const char * str)
b99bd4ef 17081{
c19d1205 17082 char * to = NULL;
b99bd4ef 17083
c19d1205 17084 if (inst.error)
b99bd4ef 17085 {
c19d1205 17086 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17087 return;
17088 }
5f4273c7
NC
17089 if (inst.relax)
17090 {
17091 output_relax_insn ();
0110f2b8 17092 return;
5f4273c7 17093 }
c19d1205
ZW
17094 if (inst.size == 0)
17095 return;
b99bd4ef 17096
c19d1205 17097 to = frag_more (inst.size);
8dc2430f
NC
17098 /* PR 9814: Record the thumb mode into the current frag so that we know
17099 what type of NOP padding to use, if necessary. We override any previous
17100 setting so that if the mode has changed then the NOPS that we use will
17101 match the encoding of the last instruction in the frag. */
cd000bff 17102 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17103
17104 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17105 {
9c2799c2 17106 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17107 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17108 }
c19d1205 17109 else if (inst.size > INSN_SIZE)
b99bd4ef 17110 {
9c2799c2 17111 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17112 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17113 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17114 }
c19d1205
ZW
17115 else
17116 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17117
c19d1205
ZW
17118 if (inst.reloc.type != BFD_RELOC_UNUSED)
17119 fix_new_arm (frag_now, to - frag_now->fr_literal,
17120 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17121 inst.reloc.type);
b99bd4ef 17122
c19d1205 17123 dwarf2_emit_insn (inst.size);
c19d1205 17124}
b99bd4ef 17125
e07e6e58
NC
17126static char *
17127output_it_inst (int cond, int mask, char * to)
17128{
17129 unsigned long instruction = 0xbf00;
17130
17131 mask &= 0xf;
17132 instruction |= mask;
17133 instruction |= cond << 4;
17134
17135 if (to == NULL)
17136 {
17137 to = frag_more (2);
17138#ifdef OBJ_ELF
17139 dwarf2_emit_insn (2);
17140#endif
17141 }
17142
17143 md_number_to_chars (to, instruction, 2);
17144
17145 return to;
17146}
17147
c19d1205
ZW
17148/* Tag values used in struct asm_opcode's tag field. */
17149enum opcode_tag
17150{
17151 OT_unconditional, /* Instruction cannot be conditionalized.
17152 The ARM condition field is still 0xE. */
17153 OT_unconditionalF, /* Instruction cannot be conditionalized
17154 and carries 0xF in its ARM condition field. */
17155 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17156 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17157 suffix, others place 0xF where the condition field
17158 would be. */
c19d1205
ZW
17159 OT_cinfix3, /* Instruction takes a conditional infix,
17160 beginning at character index 3. (In
17161 unified mode, it becomes a suffix.) */
088fa78e
KH
17162 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17163 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17164 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17165 character index 3, even in unified mode. Used for
17166 legacy instructions where suffix and infix forms
17167 may be ambiguous. */
c19d1205 17168 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17169 suffix or an infix at character index 3. */
c19d1205
ZW
17170 OT_odd_infix_unc, /* This is the unconditional variant of an
17171 instruction that takes a conditional infix
17172 at an unusual position. In unified mode,
17173 this variant will accept a suffix. */
17174 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17175 are the conditional variants of instructions that
17176 take conditional infixes in unusual positions.
17177 The infix appears at character index
17178 (tag - OT_odd_infix_0). These are not accepted
17179 in unified mode. */
17180};
b99bd4ef 17181
c19d1205
ZW
17182/* Subroutine of md_assemble, responsible for looking up the primary
17183 opcode from the mnemonic the user wrote. STR points to the
17184 beginning of the mnemonic.
17185
17186 This is not simply a hash table lookup, because of conditional
17187 variants. Most instructions have conditional variants, which are
17188 expressed with a _conditional affix_ to the mnemonic. If we were
17189 to encode each conditional variant as a literal string in the opcode
17190 table, it would have approximately 20,000 entries.
17191
17192 Most mnemonics take this affix as a suffix, and in unified syntax,
17193 'most' is upgraded to 'all'. However, in the divided syntax, some
17194 instructions take the affix as an infix, notably the s-variants of
17195 the arithmetic instructions. Of those instructions, all but six
17196 have the infix appear after the third character of the mnemonic.
17197
17198 Accordingly, the algorithm for looking up primary opcodes given
17199 an identifier is:
17200
17201 1. Look up the identifier in the opcode table.
17202 If we find a match, go to step U.
17203
17204 2. Look up the last two characters of the identifier in the
17205 conditions table. If we find a match, look up the first N-2
17206 characters of the identifier in the opcode table. If we
17207 find a match, go to step CE.
17208
17209 3. Look up the fourth and fifth characters of the identifier in
17210 the conditions table. If we find a match, extract those
17211 characters from the identifier, and look up the remaining
17212 characters in the opcode table. If we find a match, go
17213 to step CM.
17214
17215 4. Fail.
17216
17217 U. Examine the tag field of the opcode structure, in case this is
17218 one of the six instructions with its conditional infix in an
17219 unusual place. If it is, the tag tells us where to find the
17220 infix; look it up in the conditions table and set inst.cond
17221 accordingly. Otherwise, this is an unconditional instruction.
17222 Again set inst.cond accordingly. Return the opcode structure.
17223
17224 CE. Examine the tag field to make sure this is an instruction that
17225 should receive a conditional suffix. If it is not, fail.
17226 Otherwise, set inst.cond from the suffix we already looked up,
17227 and return the opcode structure.
17228
17229 CM. Examine the tag field to make sure this is an instruction that
17230 should receive a conditional infix after the third character.
17231 If it is not, fail. Otherwise, undo the edits to the current
17232 line of input and proceed as for case CE. */
17233
17234static const struct asm_opcode *
17235opcode_lookup (char **str)
17236{
17237 char *end, *base;
17238 char *affix;
17239 const struct asm_opcode *opcode;
17240 const struct asm_cond *cond;
e3cb604e 17241 char save[2];
c19d1205
ZW
17242
17243 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17244 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17245 for (base = end = *str; *end != '\0'; end++)
721a8186 17246 if (*end == ' ' || *end == '.')
c19d1205 17247 break;
b99bd4ef 17248
c19d1205 17249 if (end == base)
c921be7d 17250 return NULL;
b99bd4ef 17251
5287ad62 17252 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17253 if (end[0] == '.')
b99bd4ef 17254 {
5287ad62 17255 int offset = 2;
5f4273c7 17256
267d2029 17257 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17258 use. */
267d2029 17259 if (unified_syntax && end[1] == 'w')
c19d1205 17260 inst.size_req = 4;
267d2029 17261 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17262 inst.size_req = 2;
17263 else
477330fc 17264 offset = 0;
5287ad62
JB
17265
17266 inst.vectype.elems = 0;
17267
17268 *str = end + offset;
b99bd4ef 17269
5f4273c7 17270 if (end[offset] == '.')
5287ad62 17271 {
267d2029 17272 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17273 non-unified ARM syntax mode). */
17274 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17275 return NULL;
477330fc 17276 }
5287ad62 17277 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17278 return NULL;
b99bd4ef 17279 }
c19d1205
ZW
17280 else
17281 *str = end;
b99bd4ef 17282
c19d1205 17283 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17284 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17285 end - base);
c19d1205 17286 if (opcode)
b99bd4ef 17287 {
c19d1205
ZW
17288 /* step U */
17289 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17290 {
c19d1205
ZW
17291 inst.cond = COND_ALWAYS;
17292 return opcode;
b99bd4ef 17293 }
b99bd4ef 17294
278df34e 17295 if (warn_on_deprecated && unified_syntax)
5c3696f8 17296 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17297 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17298 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17299 gas_assert (cond);
b99bd4ef 17300
c19d1205
ZW
17301 inst.cond = cond->value;
17302 return opcode;
17303 }
b99bd4ef 17304
c19d1205
ZW
17305 /* Cannot have a conditional suffix on a mnemonic of less than two
17306 characters. */
17307 if (end - base < 3)
c921be7d 17308 return NULL;
b99bd4ef 17309
c19d1205
ZW
17310 /* Look for suffixed mnemonic. */
17311 affix = end - 2;
21d799b5
NC
17312 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17313 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17314 affix - base);
c19d1205
ZW
17315 if (opcode && cond)
17316 {
17317 /* step CE */
17318 switch (opcode->tag)
17319 {
e3cb604e
PB
17320 case OT_cinfix3_legacy:
17321 /* Ignore conditional suffixes matched on infix only mnemonics. */
17322 break;
17323
c19d1205 17324 case OT_cinfix3:
088fa78e 17325 case OT_cinfix3_deprecated:
c19d1205
ZW
17326 case OT_odd_infix_unc:
17327 if (!unified_syntax)
e3cb604e 17328 return 0;
c19d1205
ZW
17329 /* else fall through */
17330
17331 case OT_csuffix:
477330fc 17332 case OT_csuffixF:
c19d1205
ZW
17333 case OT_csuf_or_in3:
17334 inst.cond = cond->value;
17335 return opcode;
17336
17337 case OT_unconditional:
17338 case OT_unconditionalF:
dfa9f0d5 17339 if (thumb_mode)
c921be7d 17340 inst.cond = cond->value;
dfa9f0d5
PB
17341 else
17342 {
c921be7d 17343 /* Delayed diagnostic. */
dfa9f0d5
PB
17344 inst.error = BAD_COND;
17345 inst.cond = COND_ALWAYS;
17346 }
c19d1205 17347 return opcode;
b99bd4ef 17348
c19d1205 17349 default:
c921be7d 17350 return NULL;
c19d1205
ZW
17351 }
17352 }
b99bd4ef 17353
c19d1205
ZW
17354 /* Cannot have a usual-position infix on a mnemonic of less than
17355 six characters (five would be a suffix). */
17356 if (end - base < 6)
c921be7d 17357 return NULL;
b99bd4ef 17358
c19d1205
ZW
17359 /* Look for infixed mnemonic in the usual position. */
17360 affix = base + 3;
21d799b5 17361 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17362 if (!cond)
c921be7d 17363 return NULL;
e3cb604e
PB
17364
17365 memcpy (save, affix, 2);
17366 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17367 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17368 (end - base) - 2);
e3cb604e
PB
17369 memmove (affix + 2, affix, (end - affix) - 2);
17370 memcpy (affix, save, 2);
17371
088fa78e
KH
17372 if (opcode
17373 && (opcode->tag == OT_cinfix3
17374 || opcode->tag == OT_cinfix3_deprecated
17375 || opcode->tag == OT_csuf_or_in3
17376 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17377 {
c921be7d 17378 /* Step CM. */
278df34e 17379 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17380 && (opcode->tag == OT_cinfix3
17381 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17382 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17383
17384 inst.cond = cond->value;
17385 return opcode;
b99bd4ef
NC
17386 }
17387
c921be7d 17388 return NULL;
b99bd4ef
NC
17389}
17390
e07e6e58
NC
17391/* This function generates an initial IT instruction, leaving its block
17392 virtually open for the new instructions. Eventually,
17393 the mask will be updated by now_it_add_mask () each time
17394 a new instruction needs to be included in the IT block.
17395 Finally, the block is closed with close_automatic_it_block ().
17396 The block closure can be requested either from md_assemble (),
17397 a tencode (), or due to a label hook. */
17398
17399static void
17400new_automatic_it_block (int cond)
17401{
17402 now_it.state = AUTOMATIC_IT_BLOCK;
17403 now_it.mask = 0x18;
17404 now_it.cc = cond;
17405 now_it.block_length = 1;
cd000bff 17406 mapping_state (MAP_THUMB);
e07e6e58 17407 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17408 now_it.warn_deprecated = FALSE;
17409 now_it.insn_cond = TRUE;
e07e6e58
NC
17410}
17411
17412/* Close an automatic IT block.
17413 See comments in new_automatic_it_block (). */
17414
17415static void
17416close_automatic_it_block (void)
17417{
17418 now_it.mask = 0x10;
17419 now_it.block_length = 0;
17420}
17421
17422/* Update the mask of the current automatically-generated IT
17423 instruction. See comments in new_automatic_it_block (). */
17424
17425static void
17426now_it_add_mask (int cond)
17427{
17428#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17429#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17430 | ((bitvalue) << (nbit)))
e07e6e58 17431 const int resulting_bit = (cond & 1);
c921be7d 17432
e07e6e58
NC
17433 now_it.mask &= 0xf;
17434 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17435 resulting_bit,
17436 (5 - now_it.block_length));
e07e6e58 17437 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17438 1,
17439 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17440 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17441
17442#undef CLEAR_BIT
17443#undef SET_BIT_VALUE
e07e6e58
NC
17444}
17445
17446/* The IT blocks handling machinery is accessed through the these functions:
17447 it_fsm_pre_encode () from md_assemble ()
17448 set_it_insn_type () optional, from the tencode functions
17449 set_it_insn_type_last () ditto
17450 in_it_block () ditto
17451 it_fsm_post_encode () from md_assemble ()
17452 force_automatic_it_block_close () from label habdling functions
17453
17454 Rationale:
17455 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17456 initializing the IT insn type with a generic initial value depending
17457 on the inst.condition.
e07e6e58 17458 2) During the tencode function, two things may happen:
477330fc
RM
17459 a) The tencode function overrides the IT insn type by
17460 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17461 b) The tencode function queries the IT block state by
17462 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17463
17464 Both set_it_insn_type and in_it_block run the internal FSM state
17465 handling function (handle_it_state), because: a) setting the IT insn
17466 type may incur in an invalid state (exiting the function),
17467 and b) querying the state requires the FSM to be updated.
17468 Specifically we want to avoid creating an IT block for conditional
17469 branches, so it_fsm_pre_encode is actually a guess and we can't
17470 determine whether an IT block is required until the tencode () routine
17471 has decided what type of instruction this actually it.
17472 Because of this, if set_it_insn_type and in_it_block have to be used,
17473 set_it_insn_type has to be called first.
17474
17475 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17476 determines the insn IT type depending on the inst.cond code.
17477 When a tencode () routine encodes an instruction that can be
17478 either outside an IT block, or, in the case of being inside, has to be
17479 the last one, set_it_insn_type_last () will determine the proper
17480 IT instruction type based on the inst.cond code. Otherwise,
17481 set_it_insn_type can be called for overriding that logic or
17482 for covering other cases.
17483
17484 Calling handle_it_state () may not transition the IT block state to
17485 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17486 still queried. Instead, if the FSM determines that the state should
17487 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17488 after the tencode () function: that's what it_fsm_post_encode () does.
17489
17490 Since in_it_block () calls the state handling function to get an
17491 updated state, an error may occur (due to invalid insns combination).
17492 In that case, inst.error is set.
17493 Therefore, inst.error has to be checked after the execution of
17494 the tencode () routine.
e07e6e58
NC
17495
17496 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17497 any pending state change (if any) that didn't take place in
17498 handle_it_state () as explained above. */
e07e6e58
NC
17499
17500static void
17501it_fsm_pre_encode (void)
17502{
17503 if (inst.cond != COND_ALWAYS)
17504 inst.it_insn_type = INSIDE_IT_INSN;
17505 else
17506 inst.it_insn_type = OUTSIDE_IT_INSN;
17507
17508 now_it.state_handled = 0;
17509}
17510
17511/* IT state FSM handling function. */
17512
17513static int
17514handle_it_state (void)
17515{
17516 now_it.state_handled = 1;
5a01bb1d 17517 now_it.insn_cond = FALSE;
e07e6e58
NC
17518
17519 switch (now_it.state)
17520 {
17521 case OUTSIDE_IT_BLOCK:
17522 switch (inst.it_insn_type)
17523 {
17524 case OUTSIDE_IT_INSN:
17525 break;
17526
17527 case INSIDE_IT_INSN:
17528 case INSIDE_IT_LAST_INSN:
17529 if (thumb_mode == 0)
17530 {
c921be7d 17531 if (unified_syntax
e07e6e58
NC
17532 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17533 as_tsktsk (_("Warning: conditional outside an IT block"\
17534 " for Thumb."));
17535 }
17536 else
17537 {
17538 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
17539 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
17540 {
17541 /* Automatically generate the IT instruction. */
17542 new_automatic_it_block (inst.cond);
17543 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17544 close_automatic_it_block ();
17545 }
17546 else
17547 {
17548 inst.error = BAD_OUT_IT;
17549 return FAIL;
17550 }
17551 }
17552 break;
17553
17554 case IF_INSIDE_IT_LAST_INSN:
17555 case NEUTRAL_IT_INSN:
17556 break;
17557
17558 case IT_INSN:
17559 now_it.state = MANUAL_IT_BLOCK;
17560 now_it.block_length = 0;
17561 break;
17562 }
17563 break;
17564
17565 case AUTOMATIC_IT_BLOCK:
17566 /* Three things may happen now:
17567 a) We should increment current it block size;
17568 b) We should close current it block (closing insn or 4 insns);
17569 c) We should close current it block and start a new one (due
17570 to incompatible conditions or
17571 4 insns-length block reached). */
17572
17573 switch (inst.it_insn_type)
17574 {
17575 case OUTSIDE_IT_INSN:
17576 /* The closure of the block shall happen immediatelly,
17577 so any in_it_block () call reports the block as closed. */
17578 force_automatic_it_block_close ();
17579 break;
17580
17581 case INSIDE_IT_INSN:
17582 case INSIDE_IT_LAST_INSN:
17583 case IF_INSIDE_IT_LAST_INSN:
17584 now_it.block_length++;
17585
17586 if (now_it.block_length > 4
17587 || !now_it_compatible (inst.cond))
17588 {
17589 force_automatic_it_block_close ();
17590 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17591 new_automatic_it_block (inst.cond);
17592 }
17593 else
17594 {
5a01bb1d 17595 now_it.insn_cond = TRUE;
e07e6e58
NC
17596 now_it_add_mask (inst.cond);
17597 }
17598
17599 if (now_it.state == AUTOMATIC_IT_BLOCK
17600 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17601 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17602 close_automatic_it_block ();
17603 break;
17604
17605 case NEUTRAL_IT_INSN:
17606 now_it.block_length++;
5a01bb1d 17607 now_it.insn_cond = TRUE;
e07e6e58
NC
17608
17609 if (now_it.block_length > 4)
17610 force_automatic_it_block_close ();
17611 else
17612 now_it_add_mask (now_it.cc & 1);
17613 break;
17614
17615 case IT_INSN:
17616 close_automatic_it_block ();
17617 now_it.state = MANUAL_IT_BLOCK;
17618 break;
17619 }
17620 break;
17621
17622 case MANUAL_IT_BLOCK:
17623 {
17624 /* Check conditional suffixes. */
17625 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17626 int is_last;
17627 now_it.mask <<= 1;
17628 now_it.mask &= 0x1f;
17629 is_last = (now_it.mask == 0x10);
5a01bb1d 17630 now_it.insn_cond = TRUE;
e07e6e58
NC
17631
17632 switch (inst.it_insn_type)
17633 {
17634 case OUTSIDE_IT_INSN:
17635 inst.error = BAD_NOT_IT;
17636 return FAIL;
17637
17638 case INSIDE_IT_INSN:
17639 if (cond != inst.cond)
17640 {
17641 inst.error = BAD_IT_COND;
17642 return FAIL;
17643 }
17644 break;
17645
17646 case INSIDE_IT_LAST_INSN:
17647 case IF_INSIDE_IT_LAST_INSN:
17648 if (cond != inst.cond)
17649 {
17650 inst.error = BAD_IT_COND;
17651 return FAIL;
17652 }
17653 if (!is_last)
17654 {
17655 inst.error = BAD_BRANCH;
17656 return FAIL;
17657 }
17658 break;
17659
17660 case NEUTRAL_IT_INSN:
17661 /* The BKPT instruction is unconditional even in an IT block. */
17662 break;
17663
17664 case IT_INSN:
17665 inst.error = BAD_IT_IT;
17666 return FAIL;
17667 }
17668 }
17669 break;
17670 }
17671
17672 return SUCCESS;
17673}
17674
5a01bb1d
MGD
17675struct depr_insn_mask
17676{
17677 unsigned long pattern;
17678 unsigned long mask;
17679 const char* description;
17680};
17681
17682/* List of 16-bit instruction patterns deprecated in an IT block in
17683 ARMv8. */
17684static const struct depr_insn_mask depr_it_insns[] = {
17685 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17686 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17687 { 0xa000, 0xb800, N_("ADR") },
17688 { 0x4800, 0xf800, N_("Literal loads") },
17689 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17690 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
17691 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17692 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17693 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
17694 { 0, 0, NULL }
17695};
17696
e07e6e58
NC
17697static void
17698it_fsm_post_encode (void)
17699{
17700 int is_last;
17701
17702 if (!now_it.state_handled)
17703 handle_it_state ();
17704
5a01bb1d
MGD
17705 if (now_it.insn_cond
17706 && !now_it.warn_deprecated
17707 && warn_on_deprecated
17708 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17709 {
17710 if (inst.instruction >= 0x10000)
17711 {
5c3696f8 17712 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
17713 "deprecated in ARMv8"));
17714 now_it.warn_deprecated = TRUE;
17715 }
17716 else
17717 {
17718 const struct depr_insn_mask *p = depr_it_insns;
17719
17720 while (p->mask != 0)
17721 {
17722 if ((inst.instruction & p->mask) == p->pattern)
17723 {
5c3696f8 17724 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
17725 "of the following class are deprecated in ARMv8: "
17726 "%s"), p->description);
17727 now_it.warn_deprecated = TRUE;
17728 break;
17729 }
17730
17731 ++p;
17732 }
17733 }
17734
17735 if (now_it.block_length > 1)
17736 {
5c3696f8 17737 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 17738 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
17739 now_it.warn_deprecated = TRUE;
17740 }
17741 }
17742
e07e6e58
NC
17743 is_last = (now_it.mask == 0x10);
17744 if (is_last)
17745 {
17746 now_it.state = OUTSIDE_IT_BLOCK;
17747 now_it.mask = 0;
17748 }
17749}
17750
17751static void
17752force_automatic_it_block_close (void)
17753{
17754 if (now_it.state == AUTOMATIC_IT_BLOCK)
17755 {
17756 close_automatic_it_block ();
17757 now_it.state = OUTSIDE_IT_BLOCK;
17758 now_it.mask = 0;
17759 }
17760}
17761
17762static int
17763in_it_block (void)
17764{
17765 if (!now_it.state_handled)
17766 handle_it_state ();
17767
17768 return now_it.state != OUTSIDE_IT_BLOCK;
17769}
17770
c19d1205
ZW
17771void
17772md_assemble (char *str)
b99bd4ef 17773{
c19d1205
ZW
17774 char *p = str;
17775 const struct asm_opcode * opcode;
b99bd4ef 17776
c19d1205
ZW
17777 /* Align the previous label if needed. */
17778 if (last_label_seen != NULL)
b99bd4ef 17779 {
c19d1205
ZW
17780 symbol_set_frag (last_label_seen, frag_now);
17781 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17782 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17783 }
17784
c19d1205
ZW
17785 memset (&inst, '\0', sizeof (inst));
17786 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17787
c19d1205
ZW
17788 opcode = opcode_lookup (&p);
17789 if (!opcode)
b99bd4ef 17790 {
c19d1205 17791 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17792 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 17793 if (! create_register_alias (str, p)
477330fc 17794 && ! create_neon_reg_alias (str, p))
c19d1205 17795 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17796
b99bd4ef
NC
17797 return;
17798 }
17799
278df34e 17800 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 17801 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 17802
037e8744
JB
17803 /* The value which unconditional instructions should have in place of the
17804 condition field. */
17805 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17806
c19d1205 17807 if (thumb_mode)
b99bd4ef 17808 {
e74cfd16 17809 arm_feature_set variant;
8f06b2d8
PB
17810
17811 variant = cpu_variant;
17812 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17813 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17814 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17815 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17816 if (!opcode->tvariant
17817 || (thumb_mode == 1
17818 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17819 {
84b52b66 17820 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
17821 return;
17822 }
c19d1205
ZW
17823 if (inst.cond != COND_ALWAYS && !unified_syntax
17824 && opcode->tencode != do_t_branch)
b99bd4ef 17825 {
c19d1205 17826 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17827 return;
17828 }
17829
752d5da4 17830 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 17831 {
7e806470 17832 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
17833 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17834 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17835 {
17836 /* Two things are addressed here.
17837 1) Implicit require narrow instructions on Thumb-1.
17838 This avoids relaxation accidentally introducing Thumb-2
17839 instructions.
17840 2) Reject wide instructions in non Thumb-2 cores. */
17841 if (inst.size_req == 0)
17842 inst.size_req = 2;
17843 else if (inst.size_req == 4)
17844 {
84b52b66 17845 as_bad (_("selected processor does not support `%s' in Thumb-2 mode"), str);
752d5da4
NC
17846 return;
17847 }
17848 }
076d447c
PB
17849 }
17850
c19d1205
ZW
17851 inst.instruction = opcode->tvalue;
17852
5be8be5d 17853 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
17854 {
17855 /* Prepare the it_insn_type for those encodings that don't set
17856 it. */
17857 it_fsm_pre_encode ();
c19d1205 17858
477330fc 17859 opcode->tencode ();
e07e6e58 17860
477330fc
RM
17861 it_fsm_post_encode ();
17862 }
e27ec89e 17863
0110f2b8 17864 if (!(inst.error || inst.relax))
b99bd4ef 17865 {
9c2799c2 17866 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17867 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17868 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17869 {
c19d1205 17870 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17871 return;
17872 }
17873 }
076d447c
PB
17874
17875 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 17876 instruction. */
9c2799c2 17877 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17878
e74cfd16
PB
17879 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17880 *opcode->tvariant);
ee065d83 17881 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 17882 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 17883 anything other than bl/blx and v6-M instructions.
3cfdb781
TG
17884 The impact of relaxable instructions will be considered later after we
17885 finish all relaxation. */
17886 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
e07e6e58
NC
17887 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17888 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
17889 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17890 arm_ext_v6t2);
cd000bff 17891
88714cb8
DG
17892 check_neon_suffixes;
17893
cd000bff 17894 if (!inst.error)
c877a2f2
NC
17895 {
17896 mapping_state (MAP_THUMB);
17897 }
c19d1205 17898 }
3e9e4fcf 17899 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17900 {
845b51d6
PB
17901 bfd_boolean is_bx;
17902
17903 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17904 is_bx = (opcode->aencode == do_bx);
17905
c19d1205 17906 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17907 if (!(is_bx && fix_v4bx)
17908 && !(opcode->avariant &&
17909 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17910 {
84b52b66 17911 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 17912 return;
b99bd4ef 17913 }
c19d1205 17914 if (inst.size_req)
b99bd4ef 17915 {
c19d1205
ZW
17916 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17917 return;
b99bd4ef
NC
17918 }
17919
c19d1205
ZW
17920 inst.instruction = opcode->avalue;
17921 if (opcode->tag == OT_unconditionalF)
eff0bc54 17922 inst.instruction |= 0xFU << 28;
c19d1205
ZW
17923 else
17924 inst.instruction |= inst.cond << 28;
17925 inst.size = INSN_SIZE;
5be8be5d 17926 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
17927 {
17928 it_fsm_pre_encode ();
17929 opcode->aencode ();
17930 it_fsm_post_encode ();
17931 }
ee065d83 17932 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 17933 on a hypothetical non-thumb v5 core. */
845b51d6 17934 if (is_bx)
e74cfd16 17935 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17936 else
e74cfd16
PB
17937 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17938 *opcode->avariant);
88714cb8
DG
17939
17940 check_neon_suffixes;
17941
cd000bff 17942 if (!inst.error)
c877a2f2
NC
17943 {
17944 mapping_state (MAP_ARM);
17945 }
b99bd4ef 17946 }
3e9e4fcf
JB
17947 else
17948 {
17949 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17950 "-- `%s'"), str);
17951 return;
17952 }
c19d1205
ZW
17953 output_inst (str);
17954}
b99bd4ef 17955
e07e6e58
NC
17956static void
17957check_it_blocks_finished (void)
17958{
17959#ifdef OBJ_ELF
17960 asection *sect;
17961
17962 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17963 if (seg_info (sect)->tc_segment_info_data.current_it.state
17964 == MANUAL_IT_BLOCK)
17965 {
17966 as_warn (_("section '%s' finished with an open IT block."),
17967 sect->name);
17968 }
17969#else
17970 if (now_it.state == MANUAL_IT_BLOCK)
17971 as_warn (_("file finished with an open IT block."));
17972#endif
17973}
17974
c19d1205
ZW
17975/* Various frobbings of labels and their addresses. */
17976
17977void
17978arm_start_line_hook (void)
17979{
17980 last_label_seen = NULL;
b99bd4ef
NC
17981}
17982
c19d1205
ZW
17983void
17984arm_frob_label (symbolS * sym)
b99bd4ef 17985{
c19d1205 17986 last_label_seen = sym;
b99bd4ef 17987
c19d1205 17988 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 17989
c19d1205
ZW
17990#if defined OBJ_COFF || defined OBJ_ELF
17991 ARM_SET_INTERWORK (sym, support_interwork);
17992#endif
b99bd4ef 17993
e07e6e58
NC
17994 force_automatic_it_block_close ();
17995
5f4273c7 17996 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
17997 as Thumb functions. This is because these labels, whilst
17998 they exist inside Thumb code, are not the entry points for
17999 possible ARM->Thumb calls. Also, these labels can be used
18000 as part of a computed goto or switch statement. eg gcc
18001 can generate code that looks like this:
b99bd4ef 18002
c19d1205
ZW
18003 ldr r2, [pc, .Laaa]
18004 lsl r3, r3, #2
18005 ldr r2, [r3, r2]
18006 mov pc, r2
b99bd4ef 18007
c19d1205
ZW
18008 .Lbbb: .word .Lxxx
18009 .Lccc: .word .Lyyy
18010 ..etc...
18011 .Laaa: .word Lbbb
b99bd4ef 18012
c19d1205
ZW
18013 The first instruction loads the address of the jump table.
18014 The second instruction converts a table index into a byte offset.
18015 The third instruction gets the jump address out of the table.
18016 The fourth instruction performs the jump.
b99bd4ef 18017
c19d1205
ZW
18018 If the address stored at .Laaa is that of a symbol which has the
18019 Thumb_Func bit set, then the linker will arrange for this address
18020 to have the bottom bit set, which in turn would mean that the
18021 address computation performed by the third instruction would end
18022 up with the bottom bit set. Since the ARM is capable of unaligned
18023 word loads, the instruction would then load the incorrect address
18024 out of the jump table, and chaos would ensue. */
18025 if (label_is_thumb_function_name
18026 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18027 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18028 {
c19d1205
ZW
18029 /* When the address of a Thumb function is taken the bottom
18030 bit of that address should be set. This will allow
18031 interworking between Arm and Thumb functions to work
18032 correctly. */
b99bd4ef 18033
c19d1205 18034 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18035
c19d1205 18036 label_is_thumb_function_name = FALSE;
b99bd4ef 18037 }
07a53e5c 18038
07a53e5c 18039 dwarf2_emit_label (sym);
b99bd4ef
NC
18040}
18041
c921be7d 18042bfd_boolean
c19d1205 18043arm_data_in_code (void)
b99bd4ef 18044{
c19d1205 18045 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18046 {
c19d1205
ZW
18047 *input_line_pointer = '/';
18048 input_line_pointer += 5;
18049 *input_line_pointer = 0;
c921be7d 18050 return TRUE;
b99bd4ef
NC
18051 }
18052
c921be7d 18053 return FALSE;
b99bd4ef
NC
18054}
18055
c19d1205
ZW
18056char *
18057arm_canonicalize_symbol_name (char * name)
b99bd4ef 18058{
c19d1205 18059 int len;
b99bd4ef 18060
c19d1205
ZW
18061 if (thumb_mode && (len = strlen (name)) > 5
18062 && streq (name + len - 5, "/data"))
18063 *(name + len - 5) = 0;
b99bd4ef 18064
c19d1205 18065 return name;
b99bd4ef 18066}
c19d1205
ZW
18067\f
18068/* Table of all register names defined by default. The user can
18069 define additional names with .req. Note that all register names
18070 should appear in both upper and lowercase variants. Some registers
18071 also have mixed-case names. */
b99bd4ef 18072
dcbf9037 18073#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18074#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18075#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18076#define REGSET(p,t) \
18077 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18078 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18079 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18080 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18081#define REGSETH(p,t) \
18082 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18083 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18084 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18085 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18086#define REGSET2(p,t) \
18087 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18088 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18089 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18090 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18091#define SPLRBANK(base,bank,t) \
18092 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18093 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18094 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18095 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18096 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18097 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18098
c19d1205 18099static const struct reg_entry reg_names[] =
7ed4c4c5 18100{
c19d1205
ZW
18101 /* ARM integer registers. */
18102 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18103
c19d1205
ZW
18104 /* ATPCS synonyms. */
18105 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18106 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18107 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18108
c19d1205
ZW
18109 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18110 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18111 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18112
c19d1205
ZW
18113 /* Well-known aliases. */
18114 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18115 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18116
18117 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18118 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18119
18120 /* Coprocessor numbers. */
18121 REGSET(p, CP), REGSET(P, CP),
18122
18123 /* Coprocessor register numbers. The "cr" variants are for backward
18124 compatibility. */
18125 REGSET(c, CN), REGSET(C, CN),
18126 REGSET(cr, CN), REGSET(CR, CN),
18127
90ec0d68
MGD
18128 /* ARM banked registers. */
18129 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18130 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18131 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18132 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18133 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18134 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18135 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18136
18137 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18138 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18139 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18140 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18141 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18142 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18143 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18144 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18145
18146 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18147 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18148 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18149 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18150 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18151 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18152 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18153 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18154 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18155
c19d1205
ZW
18156 /* FPA registers. */
18157 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18158 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18159
18160 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18161 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18162
18163 /* VFP SP registers. */
5287ad62
JB
18164 REGSET(s,VFS), REGSET(S,VFS),
18165 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18166
18167 /* VFP DP Registers. */
5287ad62
JB
18168 REGSET(d,VFD), REGSET(D,VFD),
18169 /* Extra Neon DP registers. */
18170 REGSETH(d,VFD), REGSETH(D,VFD),
18171
18172 /* Neon QP registers. */
18173 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18174
18175 /* VFP control registers. */
18176 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18177 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18178 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18179 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18180 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18181 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18182
18183 /* Maverick DSP coprocessor registers. */
18184 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18185 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18186
18187 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18188 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18189 REGDEF(dspsc,0,DSPSC),
18190
18191 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18192 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18193 REGDEF(DSPSC,0,DSPSC),
18194
18195 /* iWMMXt data registers - p0, c0-15. */
18196 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18197
18198 /* iWMMXt control registers - p1, c0-3. */
18199 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18200 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18201 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18202 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18203
18204 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18205 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18206 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18207 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18208 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18209
18210 /* XScale accumulator registers. */
18211 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18212};
18213#undef REGDEF
18214#undef REGNUM
18215#undef REGSET
7ed4c4c5 18216
c19d1205
ZW
18217/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18218 within psr_required_here. */
18219static const struct asm_psr psrs[] =
18220{
18221 /* Backward compatibility notation. Note that "all" is no longer
18222 truly all possible PSR bits. */
18223 {"all", PSR_c | PSR_f},
18224 {"flg", PSR_f},
18225 {"ctl", PSR_c},
18226
18227 /* Individual flags. */
18228 {"f", PSR_f},
18229 {"c", PSR_c},
18230 {"x", PSR_x},
18231 {"s", PSR_s},
59b42a0d 18232
c19d1205
ZW
18233 /* Combinations of flags. */
18234 {"fs", PSR_f | PSR_s},
18235 {"fx", PSR_f | PSR_x},
18236 {"fc", PSR_f | PSR_c},
18237 {"sf", PSR_s | PSR_f},
18238 {"sx", PSR_s | PSR_x},
18239 {"sc", PSR_s | PSR_c},
18240 {"xf", PSR_x | PSR_f},
18241 {"xs", PSR_x | PSR_s},
18242 {"xc", PSR_x | PSR_c},
18243 {"cf", PSR_c | PSR_f},
18244 {"cs", PSR_c | PSR_s},
18245 {"cx", PSR_c | PSR_x},
18246 {"fsx", PSR_f | PSR_s | PSR_x},
18247 {"fsc", PSR_f | PSR_s | PSR_c},
18248 {"fxs", PSR_f | PSR_x | PSR_s},
18249 {"fxc", PSR_f | PSR_x | PSR_c},
18250 {"fcs", PSR_f | PSR_c | PSR_s},
18251 {"fcx", PSR_f | PSR_c | PSR_x},
18252 {"sfx", PSR_s | PSR_f | PSR_x},
18253 {"sfc", PSR_s | PSR_f | PSR_c},
18254 {"sxf", PSR_s | PSR_x | PSR_f},
18255 {"sxc", PSR_s | PSR_x | PSR_c},
18256 {"scf", PSR_s | PSR_c | PSR_f},
18257 {"scx", PSR_s | PSR_c | PSR_x},
18258 {"xfs", PSR_x | PSR_f | PSR_s},
18259 {"xfc", PSR_x | PSR_f | PSR_c},
18260 {"xsf", PSR_x | PSR_s | PSR_f},
18261 {"xsc", PSR_x | PSR_s | PSR_c},
18262 {"xcf", PSR_x | PSR_c | PSR_f},
18263 {"xcs", PSR_x | PSR_c | PSR_s},
18264 {"cfs", PSR_c | PSR_f | PSR_s},
18265 {"cfx", PSR_c | PSR_f | PSR_x},
18266 {"csf", PSR_c | PSR_s | PSR_f},
18267 {"csx", PSR_c | PSR_s | PSR_x},
18268 {"cxf", PSR_c | PSR_x | PSR_f},
18269 {"cxs", PSR_c | PSR_x | PSR_s},
18270 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18271 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18272 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18273 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18274 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18275 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18276 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18277 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18278 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18279 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18280 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18281 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18282 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18283 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18284 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18285 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18286 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18287 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18288 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18289 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18290 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18291 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18292 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18293 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18294};
18295
62b3e311
PB
18296/* Table of V7M psr names. */
18297static const struct asm_psr v7m_psrs[] =
18298{
2b744c99
PB
18299 {"apsr", 0 }, {"APSR", 0 },
18300 {"iapsr", 1 }, {"IAPSR", 1 },
18301 {"eapsr", 2 }, {"EAPSR", 2 },
18302 {"psr", 3 }, {"PSR", 3 },
18303 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18304 {"ipsr", 5 }, {"IPSR", 5 },
18305 {"epsr", 6 }, {"EPSR", 6 },
18306 {"iepsr", 7 }, {"IEPSR", 7 },
18307 {"msp", 8 }, {"MSP", 8 },
18308 {"psp", 9 }, {"PSP", 9 },
18309 {"primask", 16}, {"PRIMASK", 16},
18310 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18311 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18312 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18313 {"faultmask", 19}, {"FAULTMASK", 19},
18314 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18315};
18316
c19d1205
ZW
18317/* Table of all shift-in-operand names. */
18318static const struct asm_shift_name shift_names [] =
b99bd4ef 18319{
c19d1205
ZW
18320 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18321 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18322 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18323 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18324 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18325 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18326};
b99bd4ef 18327
c19d1205
ZW
18328/* Table of all explicit relocation names. */
18329#ifdef OBJ_ELF
18330static struct reloc_entry reloc_names[] =
18331{
18332 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18333 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18334 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18335 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18336 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18337 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18338 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18339 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18340 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18341 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18342 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18343 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18344 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18345 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18346 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18347 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18348 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18349 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18350};
18351#endif
b99bd4ef 18352
c19d1205
ZW
18353/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18354static const struct asm_cond conds[] =
18355{
18356 {"eq", 0x0},
18357 {"ne", 0x1},
18358 {"cs", 0x2}, {"hs", 0x2},
18359 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18360 {"mi", 0x4},
18361 {"pl", 0x5},
18362 {"vs", 0x6},
18363 {"vc", 0x7},
18364 {"hi", 0x8},
18365 {"ls", 0x9},
18366 {"ge", 0xa},
18367 {"lt", 0xb},
18368 {"gt", 0xc},
18369 {"le", 0xd},
18370 {"al", 0xe}
18371};
bfae80f2 18372
e797f7e0 18373#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18374 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18375 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18376
62b3e311
PB
18377static struct asm_barrier_opt barrier_opt_names[] =
18378{
e797f7e0
MGD
18379 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18380 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18381 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18382 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18383 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18384 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18385 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18386 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18387 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18388 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18389 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18390 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18391 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18392 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18393 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18394 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18395};
18396
e797f7e0
MGD
18397#undef UL_BARRIER
18398
c19d1205
ZW
18399/* Table of ARM-format instructions. */
18400
18401/* Macros for gluing together operand strings. N.B. In all cases
18402 other than OPS0, the trailing OP_stop comes from default
18403 zero-initialization of the unspecified elements of the array. */
18404#define OPS0() { OP_stop, }
18405#define OPS1(a) { OP_##a, }
18406#define OPS2(a,b) { OP_##a,OP_##b, }
18407#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18408#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18409#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18410#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18411
5be8be5d
DG
18412/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18413 This is useful when mixing operands for ARM and THUMB, i.e. using the
18414 MIX_ARM_THUMB_OPERANDS macro.
18415 In order to use these macros, prefix the number of operands with _
18416 e.g. _3. */
18417#define OPS_1(a) { a, }
18418#define OPS_2(a,b) { a,b, }
18419#define OPS_3(a,b,c) { a,b,c, }
18420#define OPS_4(a,b,c,d) { a,b,c,d, }
18421#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18422#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18423
c19d1205
ZW
18424/* These macros abstract out the exact format of the mnemonic table and
18425 save some repeated characters. */
18426
18427/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18428#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18429 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18430 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18431
18432/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18433 a T_MNEM_xyz enumerator. */
18434#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18435 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18436#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18437 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18438
18439/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18440 infix after the third character. */
18441#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18442 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18443 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18444#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18445 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18446 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18447#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18448 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18449#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18450 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18451#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18452 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18453#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18454 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18455
c19d1205 18456/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18457 field is still 0xE. Many of the Thumb variants can be executed
18458 conditionally, so this is checked separately. */
c19d1205 18459#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18460 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18461 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18462
dd5181d5
KT
18463/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18464 Used by mnemonics that have very minimal differences in the encoding for
18465 ARM and Thumb variants and can be handled in a common function. */
18466#define TUEc(mnem, op, top, nops, ops, en) \
18467 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18468 THUMB_VARIANT, do_##en, do_##en }
18469
c19d1205
ZW
18470/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18471 condition code field. */
18472#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18473 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18474 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18475
18476/* ARM-only variants of all the above. */
6a86118a 18477#define CE(mnem, op, nops, ops, ae) \
21d799b5 18478 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18479
18480#define C3(mnem, op, nops, ops, ae) \
18481 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18482
e3cb604e
PB
18483/* Legacy mnemonics that always have conditional infix after the third
18484 character. */
18485#define CL(mnem, op, nops, ops, ae) \
21d799b5 18486 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18487 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18488
8f06b2d8
PB
18489/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18490#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18491 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18492
e3cb604e
PB
18493/* Legacy coprocessor instructions where conditional infix and conditional
18494 suffix are ambiguous. For consistency this includes all FPA instructions,
18495 not just the potentially ambiguous ones. */
18496#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18497 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18498 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18499
18500/* Coprocessor, takes either a suffix or a position-3 infix
18501 (for an FPA corner case). */
18502#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18503 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18504 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18505
6a86118a 18506#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18507 { m1 #m2 m3, OPS##nops ops, \
18508 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18509 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18510
18511#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18512 xCM_ (m1, , m2, op, nops, ops, ae), \
18513 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18514 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18515 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18516 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18517 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18518 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18519 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18520 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18521 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18522 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18523 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18524 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18525 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18526 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18527 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18528 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18529 xCM_ (m1, le, m2, op, nops, ops, ae), \
18530 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18531
18532#define UE(mnem, op, nops, ops, ae) \
18533 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18534
18535#define UF(mnem, op, nops, ops, ae) \
18536 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18537
5287ad62
JB
18538/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18539 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18540 use the same encoding function for each. */
18541#define NUF(mnem, op, nops, ops, enc) \
18542 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18543 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18544
18545/* Neon data processing, version which indirects through neon_enc_tab for
18546 the various overloaded versions of opcodes. */
18547#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18548 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18549 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18550
18551/* Neon insn with conditional suffix for the ARM version, non-overloaded
18552 version. */
037e8744
JB
18553#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18554 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18555 THUMB_VARIANT, do_##enc, do_##enc }
18556
037e8744 18557#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18558 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18559
18560#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18561 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18562
5287ad62 18563/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18564#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18565 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18566 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18567
037e8744 18568#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18569 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18570
18571#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18572 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18573
c19d1205
ZW
18574#define do_0 0
18575
c19d1205 18576static const struct asm_opcode insns[] =
bfae80f2 18577{
74db7efb
NC
18578#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18579#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18580 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18581 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18582 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18583 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18584 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18585 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18586 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18587 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18588 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18589 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18590 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18591 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18592 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18593 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18594 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18595 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18596
18597 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18598 for setting PSR flag bits. They are obsolete in V6 and do not
18599 have Thumb equivalents. */
21d799b5
NC
18600 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18601 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18602 CL("tstp", 110f000, 2, (RR, SH), cmp),
18603 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18604 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18605 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18606 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18607 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18608 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18609
18610 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
18611 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
18612 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18613 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18614
18615 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18616 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18617 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18618 OP_RRnpc),
18619 OP_ADDRGLDR),ldst, t_ldst),
18620 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18621
18622 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18623 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18624 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18625 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18626 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18627 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18628
18629 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18630 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18631 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18632 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18633
c19d1205 18634 /* Pseudo ops. */
21d799b5 18635 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18636 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18637 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18638 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18639
18640 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18641 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18642 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18643 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18644 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18645 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18646 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18647 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18648 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18649 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18650 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18651 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18652 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18653
16a4cf17 18654 /* These may simplify to neg. */
21d799b5
NC
18655 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18656 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18657
c921be7d
NC
18658#undef THUMB_VARIANT
18659#define THUMB_VARIANT & arm_ext_v6
18660
21d799b5 18661 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
18662
18663 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
18664#undef THUMB_VARIANT
18665#define THUMB_VARIANT & arm_ext_v6t2
18666
21d799b5
NC
18667 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18668 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18669 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 18670
5be8be5d
DG
18671 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18672 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18673 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18674 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18675
21d799b5
NC
18676 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18677 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18678
21d799b5
NC
18679 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18680 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18681
18682 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18683 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18684 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18685
18686 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18687 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18688 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18689 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18690 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18691 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18692 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18693 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18694
c921be7d
NC
18695#undef ARM_VARIANT
18696#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18697#undef THUMB_VARIANT
18698#define THUMB_VARIANT & arm_ext_v4t
18699
21d799b5
NC
18700 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18701 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18702
c921be7d
NC
18703#undef THUMB_VARIANT
18704#define THUMB_VARIANT & arm_ext_v6t2
18705
21d799b5 18706 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18707 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18708
18709 /* Generic coprocessor instructions. */
21d799b5
NC
18710 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18711 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18712 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18713 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18714 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18715 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18716 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18717
c921be7d
NC
18718#undef ARM_VARIANT
18719#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18720
21d799b5 18721 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18722 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18723
c921be7d
NC
18724#undef ARM_VARIANT
18725#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18726#undef THUMB_VARIANT
18727#define THUMB_VARIANT & arm_ext_msr
18728
d2cd1205
JB
18729 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18730 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18731
c921be7d
NC
18732#undef ARM_VARIANT
18733#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18734#undef THUMB_VARIANT
18735#define THUMB_VARIANT & arm_ext_v6t2
18736
21d799b5
NC
18737 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18738 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18739 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18740 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18741 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18742 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18743 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18744 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18745
c921be7d
NC
18746#undef ARM_VARIANT
18747#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18748#undef THUMB_VARIANT
18749#define THUMB_VARIANT & arm_ext_v4t
18750
5be8be5d
DG
18751 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18752 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18753 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18754 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18755 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18756 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18757
c921be7d
NC
18758#undef ARM_VARIANT
18759#define ARM_VARIANT & arm_ext_v4t_5
18760
c19d1205
ZW
18761 /* ARM Architecture 4T. */
18762 /* Note: bx (and blx) are required on V5, even if the processor does
18763 not support Thumb. */
21d799b5 18764 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18765
c921be7d
NC
18766#undef ARM_VARIANT
18767#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18768#undef THUMB_VARIANT
18769#define THUMB_VARIANT & arm_ext_v5t
18770
c19d1205
ZW
18771 /* Note: blx has 2 variants; the .value coded here is for
18772 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18773 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18774 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18775
c921be7d
NC
18776#undef THUMB_VARIANT
18777#define THUMB_VARIANT & arm_ext_v6t2
18778
21d799b5
NC
18779 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18780 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18781 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18782 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18783 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18784 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18785 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18786 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18787
c921be7d 18788#undef ARM_VARIANT
74db7efb
NC
18789#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18790#undef THUMB_VARIANT
18791#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 18792
21d799b5
NC
18793 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18794 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18795 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18796 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18797
21d799b5
NC
18798 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18799 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18800
21d799b5
NC
18801 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18802 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18803 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18804 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18805
21d799b5
NC
18806 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18807 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18808 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18809 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18810
21d799b5
NC
18811 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18812 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18813
03ee1b7f
NC
18814 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18815 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18816 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18817 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18818
c921be7d 18819#undef ARM_VARIANT
74db7efb
NC
18820#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18821#undef THUMB_VARIANT
18822#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18823
21d799b5 18824 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18825 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18826 ldrd, t_ldstd),
18827 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18828 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18829
21d799b5
NC
18830 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18831 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18832
c921be7d
NC
18833#undef ARM_VARIANT
18834#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18835
21d799b5 18836 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18837
c921be7d
NC
18838#undef ARM_VARIANT
18839#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18840#undef THUMB_VARIANT
18841#define THUMB_VARIANT & arm_ext_v6
18842
21d799b5
NC
18843 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18844 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18845 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18846 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18847 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18848 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18849 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18850 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18851 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18852 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18853
c921be7d
NC
18854#undef THUMB_VARIANT
18855#define THUMB_VARIANT & arm_ext_v6t2
18856
5be8be5d
DG
18857 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18858 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18859 strex, t_strex),
21d799b5
NC
18860 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18861 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18862
21d799b5
NC
18863 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18864 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18865
9e3c6df6 18866/* ARM V6 not included in V7M. */
c921be7d
NC
18867#undef THUMB_VARIANT
18868#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18869 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18870 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18871 UF(rfeib, 9900a00, 1, (RRw), rfe),
18872 UF(rfeda, 8100a00, 1, (RRw), rfe),
18873 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18874 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18875 UF(rfefa, 8100a00, 1, (RRw), rfe),
18876 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18877 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18878 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18879 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18880 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18881 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18882 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18883 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18884 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18885 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18886 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 18887 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 18888
9e3c6df6
PB
18889/* ARM V6 not included in V7M (eg. integer SIMD). */
18890#undef THUMB_VARIANT
18891#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18892 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18893 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18894 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18895 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18896 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18897 /* Old name for QASX. */
74db7efb 18898 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18899 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18900 /* Old name for QSAX. */
74db7efb 18901 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18902 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18903 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18904 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18905 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18906 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18907 /* Old name for SASX. */
74db7efb 18908 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18909 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18910 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18911 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18912 /* Old name for SHASX. */
21d799b5 18913 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18914 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18915 /* Old name for SHSAX. */
21d799b5
NC
18916 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18917 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18918 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18919 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18920 /* Old name for SSAX. */
74db7efb 18921 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18922 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18923 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18924 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18925 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18926 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18927 /* Old name for UASX. */
74db7efb 18928 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18929 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18930 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18931 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18932 /* Old name for UHASX. */
21d799b5
NC
18933 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18934 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18935 /* Old name for UHSAX. */
21d799b5
NC
18936 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18937 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18938 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18939 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18940 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18941 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18942 /* Old name for UQASX. */
21d799b5
NC
18943 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18944 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18945 /* Old name for UQSAX. */
21d799b5
NC
18946 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18947 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18948 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18949 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18950 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18951 /* Old name for USAX. */
74db7efb 18952 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18953 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18954 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18955 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18956 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18957 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18958 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18959 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18960 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18961 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18962 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18963 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18964 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18965 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18966 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18967 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18968 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18969 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18970 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18971 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18972 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18973 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18974 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18975 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18976 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18977 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18978 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18979 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18980 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
18981 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18982 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18983 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18984 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18985 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 18986
c921be7d
NC
18987#undef ARM_VARIANT
18988#define ARM_VARIANT & arm_ext_v6k
18989#undef THUMB_VARIANT
18990#define THUMB_VARIANT & arm_ext_v6k
18991
21d799b5
NC
18992 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18993 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18994 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18995 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 18996
c921be7d
NC
18997#undef THUMB_VARIANT
18998#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
18999 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19000 ldrexd, t_ldrexd),
19001 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19002 RRnpcb), strexd, t_strexd),
ebdca51a 19003
c921be7d
NC
19004#undef THUMB_VARIANT
19005#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
19006 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19007 rd_rn, rd_rn),
19008 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19009 rd_rn, rd_rn),
19010 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19011 strex, t_strexbh),
5be8be5d 19012 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19013 strex, t_strexbh),
21d799b5 19014 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19015
c921be7d 19016#undef ARM_VARIANT
f4c65163 19017#define ARM_VARIANT & arm_ext_sec
74db7efb 19018#undef THUMB_VARIANT
f4c65163 19019#define THUMB_VARIANT & arm_ext_sec
c921be7d 19020
21d799b5 19021 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19022
90ec0d68
MGD
19023#undef ARM_VARIANT
19024#define ARM_VARIANT & arm_ext_virt
19025#undef THUMB_VARIANT
19026#define THUMB_VARIANT & arm_ext_virt
19027
19028 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19029 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19030
ddfded2f
MW
19031#undef ARM_VARIANT
19032#define ARM_VARIANT & arm_ext_pan
19033#undef THUMB_VARIANT
19034#define THUMB_VARIANT & arm_ext_pan
19035
19036 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19037
c921be7d 19038#undef ARM_VARIANT
74db7efb 19039#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19040#undef THUMB_VARIANT
19041#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19042
21d799b5
NC
19043 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19044 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19045 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19046 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19047
21d799b5
NC
19048 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19049 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19050 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19051 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19052
5be8be5d
DG
19053 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19054 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19055 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19056 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19057
bf3eeda7 19058 /* Thumb-only instructions. */
74db7efb 19059#undef ARM_VARIANT
bf3eeda7
NS
19060#define ARM_VARIANT NULL
19061 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19062 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19063
19064 /* ARM does not really have an IT instruction, so always allow it.
19065 The opcode is copied from Thumb in order to allow warnings in
19066 -mimplicit-it=[never | arm] modes. */
19067#undef ARM_VARIANT
19068#define ARM_VARIANT & arm_ext_v1
19069
21d799b5
NC
19070 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19071 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19072 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19073 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19074 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19075 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19076 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19077 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19078 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19079 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19080 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19081 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19082 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19083 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19084 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19085 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19086 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19087 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19088
92e90b6e 19089 /* Thumb2 only instructions. */
c921be7d
NC
19090#undef ARM_VARIANT
19091#define ARM_VARIANT NULL
92e90b6e 19092
21d799b5
NC
19093 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19094 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19095 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19096 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19097 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19098 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19099
eea54501
MGD
19100 /* Hardware division instructions. */
19101#undef ARM_VARIANT
19102#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19103#undef THUMB_VARIANT
19104#define THUMB_VARIANT & arm_ext_div
19105
eea54501
MGD
19106 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19107 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19108
7e806470 19109 /* ARM V6M/V7 instructions. */
c921be7d
NC
19110#undef ARM_VARIANT
19111#define ARM_VARIANT & arm_ext_barrier
19112#undef THUMB_VARIANT
19113#define THUMB_VARIANT & arm_ext_barrier
19114
ccb84d65
JB
19115 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19116 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19117 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19118
62b3e311 19119 /* ARM V7 instructions. */
c921be7d
NC
19120#undef ARM_VARIANT
19121#define ARM_VARIANT & arm_ext_v7
19122#undef THUMB_VARIANT
19123#define THUMB_VARIANT & arm_ext_v7
19124
21d799b5
NC
19125 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19126 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19127
74db7efb 19128#undef ARM_VARIANT
60e5ef9f 19129#define ARM_VARIANT & arm_ext_mp
74db7efb 19130#undef THUMB_VARIANT
60e5ef9f
MGD
19131#define THUMB_VARIANT & arm_ext_mp
19132
19133 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19134
53c4b28b
MGD
19135 /* AArchv8 instructions. */
19136#undef ARM_VARIANT
19137#define ARM_VARIANT & arm_ext_v8
19138#undef THUMB_VARIANT
19139#define THUMB_VARIANT & arm_ext_v8
19140
19141 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
8884b720 19142 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
4b8c8c02
RE
19143 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19144 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19145 ldrexd, t_ldrexd),
4b8c8c02
RE
19146 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19147 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19148 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19149 stlex, t_stlex),
19150 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19151 strexd, t_strexd),
4b8c8c02
RE
19152 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19153 stlex, t_stlex),
19154 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19155 stlex, t_stlex),
19156 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19157 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19158 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19159 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19160 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19161 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
53c4b28b 19162
8884b720 19163 /* ARMv8 T32 only. */
74db7efb 19164#undef ARM_VARIANT
b79f7053
MGD
19165#define ARM_VARIANT NULL
19166 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19167 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19168 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19169
33399f07
MGD
19170 /* FP for ARMv8. */
19171#undef ARM_VARIANT
a715796b 19172#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19173#undef THUMB_VARIANT
a715796b 19174#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19175
19176 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19177 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19178 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19179 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19180 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19181 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19182 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19183 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19184 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19185 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19186 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19187 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19188 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19189 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19190 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19191 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19192 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19193
91ff7894
MGD
19194 /* Crypto v1 extensions. */
19195#undef ARM_VARIANT
19196#define ARM_VARIANT & fpu_crypto_ext_armv8
19197#undef THUMB_VARIANT
19198#define THUMB_VARIANT & fpu_crypto_ext_armv8
19199
19200 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19201 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19202 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19203 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19204 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19205 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19206 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19207 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19208 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19209 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19210 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19211 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19212 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19213 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19214
dd5181d5 19215#undef ARM_VARIANT
74db7efb 19216#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19217#undef THUMB_VARIANT
19218#define THUMB_VARIANT & crc_ext_armv8
19219 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19220 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19221 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19222 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19223 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19224 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19225
c921be7d
NC
19226#undef ARM_VARIANT
19227#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19228#undef THUMB_VARIANT
19229#define THUMB_VARIANT NULL
c921be7d 19230
21d799b5
NC
19231 cCE("wfs", e200110, 1, (RR), rd),
19232 cCE("rfs", e300110, 1, (RR), rd),
19233 cCE("wfc", e400110, 1, (RR), rd),
19234 cCE("rfc", e500110, 1, (RR), rd),
19235
19236 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19237 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19238 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19239 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19240
19241 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19242 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19243 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19244 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19245
19246 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19247 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19248 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19249 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19250 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19251 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19252 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19253 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19254 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19255 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19256 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19257 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19258
19259 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19260 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19261 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19262 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19263 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19264 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19265 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19266 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19267 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19268 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19269 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19270 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19271
19272 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19273 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19274 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19275 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19276 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19277 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19278 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19279 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19280 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19281 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19282 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19283 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19284
19285 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19286 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19287 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19288 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19289 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19290 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19291 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19292 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19293 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19294 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19295 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19296 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19297
19298 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19299 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19300 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19301 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19302 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19303 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19304 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19305 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19306 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19307 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19308 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19309 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19310
19311 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19312 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19313 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19314 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19315 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19316 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19317 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19318 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19319 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19320 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19321 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19322 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19323
19324 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19325 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19326 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19327 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19328 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19329 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19330 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19331 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19332 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19333 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19334 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19335 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19336
19337 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19338 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19339 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19340 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19341 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19342 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19343 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19344 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19345 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19346 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19347 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19348 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19349
19350 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19351 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19352 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19353 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19354 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19355 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19356 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19357 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19358 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19359 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19360 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19361 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19362
19363 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19364 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19365 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19366 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19367 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19368 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19369 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19370 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19371 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19372 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19373 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19374 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19375
19376 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19377 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19378 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19379 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19380 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19381 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19382 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19383 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19384 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19385 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19386 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19387 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19388
19389 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19390 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19391 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19392 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19393 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19394 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19395 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19396 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19397 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19398 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19399 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19400 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19401
19402 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19403 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19404 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19405 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19406 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19407 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19408 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19409 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19410 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19411 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19412 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19413 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19414
19415 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19416 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19417 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19418 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19419 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19420 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19421 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19422 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19423 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19424 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19425 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19426 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19427
19428 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19429 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19430 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19431 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19432 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19433 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19434 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19435 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19436 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19437 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19438 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19439 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19440
19441 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19442 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19443 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19444 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19445 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19446 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19447 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19448 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19449 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19450 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19451 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19452 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19453
19454 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19455 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19456 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19457 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19458 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19459 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19460 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19461 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19462 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19463 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19464 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19465 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19466
19467 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19468 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19469 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19470 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19471 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19472 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19473 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19474 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19475 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19476 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19477 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19478 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19479
19480 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19481 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19482 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19483 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19484 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19485 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19486 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19487 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19488 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19489 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19490 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19491 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19492
19493 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19494 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19495 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19496 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19497 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19498 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19499 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19500 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19501 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19502 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19503 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19504 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19505
19506 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19507 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19508 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19509 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19510 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19511 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19512 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19513 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19514 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19515 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19516 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19517 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19518
19519 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19520 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19521 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19522 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19523 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19524 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19525 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19526 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19527 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19528 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19529 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19530 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19531
19532 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19533 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19534 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19535 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19536 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19537 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19538 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19539 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19540 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19541 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19542 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19543 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19544
19545 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19546 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19547 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19548 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19549 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19550 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19551 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19552 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19553 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19554 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19555 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19556 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19557
19558 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19559 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19560 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19561 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19562 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19563 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19564 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19565 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19566 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19567 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19568 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19569 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19570
19571 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19572 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19573 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19574 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19575 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19576 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19577 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19578 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19579 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19580 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19581 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19582 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19583
19584 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19585 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19586 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19587 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19588 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19589 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19590 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19591 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19592 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19593 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19594 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19595 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19596
19597 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19598 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19599 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19600 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19601 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19602 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19603 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19604 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19605 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19606 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19607 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19608 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19609
19610 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19611 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19612 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19613 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19614 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19615 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19616 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19617 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19618 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19619 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19620 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19621 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19622
19623 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19624 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19625 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19626 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19627
19628 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19629 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19630 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19631 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19632 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19633 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19634 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19635 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19636 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19637 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19638 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19639 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 19640
c19d1205
ZW
19641 /* The implementation of the FIX instruction is broken on some
19642 assemblers, in that it accepts a precision specifier as well as a
19643 rounding specifier, despite the fact that this is meaningless.
19644 To be more compatible, we accept it as well, though of course it
19645 does not set any bits. */
21d799b5
NC
19646 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19647 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19648 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19649 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19650 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19651 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19652 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19653 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19654 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19655 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19656 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19657 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19658 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 19659
c19d1205 19660 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
19661#undef ARM_VARIANT
19662#define ARM_VARIANT & fpu_fpa_ext_v2
19663
21d799b5
NC
19664 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19665 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19666 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19667 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19668 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19669 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 19670
c921be7d
NC
19671#undef ARM_VARIANT
19672#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19673
c19d1205 19674 /* Moves and type conversions. */
21d799b5
NC
19675 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19676 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19677 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19678 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
19679 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19680 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
19681 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19682 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19683 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19684 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19685 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19686 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19687 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19688 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
19689
19690 /* Memory operations. */
21d799b5
NC
19691 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19692 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19693 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19694 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19695 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19696 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19697 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19698 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19699 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19700 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19701 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19702 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19703 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19704 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19705 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19706 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19707 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19708 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19709
c19d1205 19710 /* Monadic operations. */
21d799b5
NC
19711 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19712 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19713 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19714
19715 /* Dyadic operations. */
21d799b5
NC
19716 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19717 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19718 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19719 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19720 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19721 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19722 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19723 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19724 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19725
c19d1205 19726 /* Comparisons. */
21d799b5
NC
19727 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19728 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19729 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19730 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19731
62f3b8c8
PB
19732 /* Double precision load/store are still present on single precision
19733 implementations. */
19734 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19735 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19736 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19737 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19738 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19739 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19740 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19741 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19742 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19743 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19744
c921be7d
NC
19745#undef ARM_VARIANT
19746#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19747
c19d1205 19748 /* Moves and type conversions. */
21d799b5
NC
19749 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19750 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19751 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19752 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19753 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19754 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19755 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19756 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19757 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19758 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19759 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19760 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19761 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19762
c19d1205 19763 /* Monadic operations. */
21d799b5
NC
19764 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19765 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19766 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19767
19768 /* Dyadic operations. */
21d799b5
NC
19769 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19770 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19771 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19772 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19773 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19774 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19775 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19776 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19777 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19778
c19d1205 19779 /* Comparisons. */
21d799b5
NC
19780 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19781 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19782 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19783 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19784
c921be7d
NC
19785#undef ARM_VARIANT
19786#define ARM_VARIANT & fpu_vfp_ext_v2
19787
21d799b5
NC
19788 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19789 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19790 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19791 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19792
037e8744
JB
19793/* Instructions which may belong to either the Neon or VFP instruction sets.
19794 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19795#undef ARM_VARIANT
19796#define ARM_VARIANT & fpu_vfp_ext_v1xd
19797#undef THUMB_VARIANT
19798#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19799
037e8744
JB
19800 /* These mnemonics are unique to VFP. */
19801 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19802 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19803 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19804 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19805 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
19806 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19807 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
19808 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19809 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19810 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19811
19812 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19813 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19814 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19815 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19816
21d799b5
NC
19817 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19818 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19819
19820 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19821 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19822
55881a11
MGD
19823 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19824 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19825 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19826 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19827 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19828 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19829 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19830 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19831
5f1af56b 19832 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19833 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19834 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19835 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19836
037e8744
JB
19837
19838 /* NOTE: All VMOV encoding is special-cased! */
19839 NCE(vmov, 0, 1, (VMOV), neon_mov),
19840 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19841
c921be7d
NC
19842#undef THUMB_VARIANT
19843#define THUMB_VARIANT & fpu_neon_ext_v1
19844#undef ARM_VARIANT
19845#define ARM_VARIANT & fpu_neon_ext_v1
19846
5287ad62
JB
19847 /* Data processing with three registers of the same length. */
19848 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19849 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19850 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19851 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19852 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19853 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19854 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19855 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19856 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19857 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19858 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19859 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19860 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19861 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19862 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19863 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19864 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19865 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19866 /* If not immediate, fall back to neon_dyadic_i64_su.
19867 shl_imm should accept I8 I16 I32 I64,
19868 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19869 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19870 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19871 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19872 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19873 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19874 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19875 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19876 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19877 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19878 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19879 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19880 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19881 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19882 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19883 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19884 /* Bitfield ops, untyped. */
19885 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19886 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19887 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19888 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19889 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19890 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19891 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19892 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19893 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19894 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19895 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19896 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19897 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19898 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19899 back to neon_dyadic_if_su. */
21d799b5
NC
19900 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19901 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19902 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19903 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19904 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19905 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19906 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19907 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19908 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19909 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19910 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19911 /* As above, D registers only. */
21d799b5
NC
19912 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19913 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19914 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19915 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19916 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19917 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19918 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19919 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19920 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19921 /* vtst takes sizes 8, 16, 32. */
19922 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19923 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19924 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19925 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19926 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19927 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19928 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19929 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19930 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19931 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19932 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19933 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19934 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19935 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19936 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19937 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19938 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19939 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19940 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19941 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19942 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e
MW
19943 /* ARM v8.1 extension. */
19944 nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19945 nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19946 nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19947 nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19948
19949 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 19950 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
19951 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19952
19953 /* Data processing with two registers and a shift amount. */
19954 /* Right shifts, and variants with rounding.
19955 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19956 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19957 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19958 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19959 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19960 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19961 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19962 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19963 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19964 /* Shift and insert. Sizes accepted 8 16 32 64. */
19965 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19966 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19967 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19968 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19969 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19970 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19971 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19972 /* Right shift immediate, saturating & narrowing, with rounding variants.
19973 Types accepted S16 S32 S64 U16 U32 U64. */
19974 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19975 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19976 /* As above, unsigned. Types accepted S16 S32 S64. */
19977 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19978 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19979 /* Right shift narrowing. Types accepted I16 I32 I64. */
19980 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19981 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19982 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 19983 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 19984 /* CVT with optional immediate for fixed-point variant. */
21d799b5 19985 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 19986
4316f0d2
DG
19987 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19988 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
19989
19990 /* Data processing, three registers of different lengths. */
19991 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19992 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19993 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19994 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19995 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19996 /* If not scalar, fall back to neon_dyadic_long.
19997 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
19998 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19999 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20000 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20001 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20002 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20003 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20004 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20005 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20006 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20007 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20008 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20009 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20010 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20011 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20012 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20013 S16 S32 U16 U32. */
21d799b5 20014 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20015
20016 /* Extract. Size 8. */
3b8d421e
PB
20017 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20018 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20019
20020 /* Two registers, miscellaneous. */
20021 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20022 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20023 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20024 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20025 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20026 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20027 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20028 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20029 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20030 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20031 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20032 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20033 /* VMOVN. Types I16 I32 I64. */
21d799b5 20034 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20035 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20036 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20037 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20038 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20039 /* VZIP / VUZP. Sizes 8 16 32. */
20040 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20041 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20042 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20043 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20044 /* VQABS / VQNEG. Types S8 S16 S32. */
20045 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20046 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20047 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20048 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20049 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20050 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20051 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20052 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20053 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20054 /* Reciprocal estimates. Types U32 F32. */
20055 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20056 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20057 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20058 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20059 /* VCLS. Types S8 S16 S32. */
20060 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20061 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20062 /* VCLZ. Types I8 I16 I32. */
20063 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20064 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20065 /* VCNT. Size 8. */
20066 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20067 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20068 /* Two address, untyped. */
20069 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20070 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20071 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20072 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20073 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20074
20075 /* Table lookup. Size 8. */
20076 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20077 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20078
c921be7d
NC
20079#undef THUMB_VARIANT
20080#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20081#undef ARM_VARIANT
20082#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20083
5287ad62 20084 /* Neon element/structure load/store. */
21d799b5
NC
20085 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20086 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20087 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20088 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20089 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20090 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20091 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20092 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20093
c921be7d 20094#undef THUMB_VARIANT
74db7efb
NC
20095#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20096#undef ARM_VARIANT
20097#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20098 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20099 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20100 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20101 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20102 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20103 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20104 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20105 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20106 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20107
74db7efb 20108#undef THUMB_VARIANT
c921be7d
NC
20109#define THUMB_VARIANT & fpu_vfp_ext_v3
20110#undef ARM_VARIANT
20111#define ARM_VARIANT & fpu_vfp_ext_v3
20112
21d799b5 20113 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20114 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20115 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20116 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20117 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20118 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20119 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20120 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20121 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20122
74db7efb
NC
20123#undef ARM_VARIANT
20124#define ARM_VARIANT & fpu_vfp_ext_fma
20125#undef THUMB_VARIANT
20126#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20127 /* Mnemonics shared by Neon and VFP. These are included in the
20128 VFP FMA variant; NEON and VFP FMA always includes the NEON
20129 FMA instructions. */
20130 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20131 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20132 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20133 the v form should always be used. */
20134 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20135 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20136 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20137 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20138 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20139 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20140
5287ad62 20141#undef THUMB_VARIANT
c921be7d
NC
20142#undef ARM_VARIANT
20143#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20144
21d799b5
NC
20145 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20146 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20147 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20148 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20149 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20150 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20151 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20152 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20153
c921be7d
NC
20154#undef ARM_VARIANT
20155#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20156
21d799b5
NC
20157 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20158 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20159 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20160 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20161 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20162 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20163 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20164 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20165 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20166 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20167 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20168 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20169 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20170 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20171 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20172 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20173 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20174 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20175 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20176 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20177 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20178 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20179 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20180 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20181 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20182 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20183 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20184 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20185 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20186 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20187 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20188 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20189 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20190 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20191 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20192 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20193 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20194 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20195 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20196 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20197 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20198 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20199 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20200 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20201 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20202 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20203 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20204 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20205 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20206 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20207 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20208 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20209 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20210 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20211 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20212 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20213 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20214 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20215 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20216 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20217 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20218 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20219 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20220 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20221 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20222 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20223 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20224 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20225 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20226 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20227 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20228 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20229 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20230 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20231 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20232 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20233 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20234 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20235 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20236 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20237 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20238 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20239 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20240 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20241 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20242 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20243 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20244 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20245 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20246 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20247 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20248 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20249 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20250 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20251 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20252 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20253 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20254 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20255 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20256 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20257 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20258 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20259 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20260 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20261 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20262 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20263 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20264 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20265 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20266 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20267 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20268 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20269 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20270 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20271 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20272 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20273 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20274 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20275 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20276 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20277 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20278 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20279 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20280 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20281 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20282 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20283 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20284 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20285 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20286 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20287 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20288 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20289 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20290 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20291 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20292 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20293 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20294 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20295 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20296 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20297 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20298 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20299 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20300 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20301 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20302 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20303 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20304 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20305 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20306 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20307 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20308 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20309 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20310 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20311 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20312 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20313 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20314 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20315 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20316 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20317 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20318 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20319
c921be7d
NC
20320#undef ARM_VARIANT
20321#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20322
21d799b5
NC
20323 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20324 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20325 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20326 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20327 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20328 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20329 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20330 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20331 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20332 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20333 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20334 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20335 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20336 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20337 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20338 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20339 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20340 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20341 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20342 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20343 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20344 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20345 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20346 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20347 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20348 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20349 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20350 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20351 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20352 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20353 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20354 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20355 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20356 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20357 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20358 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20359 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20360 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20361 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20362 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20363 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20364 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20365 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20366 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20367 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20368 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20369 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20370 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20371 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20372 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20373 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20374 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20375 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20376 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20377 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20378 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20379 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20380
c921be7d
NC
20381#undef ARM_VARIANT
20382#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20383
21d799b5
NC
20384 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20385 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20386 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20387 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20388 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20389 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20390 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20391 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20392 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20393 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20394 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20395 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20396 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20397 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20398 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20399 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20400 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20401 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20402 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20403 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20404 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20405 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20406 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20407 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20408 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20409 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20410 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20411 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20412 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20413 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20414 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20415 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20416 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20417 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20418 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20419 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20420 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20421 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20422 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20423 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20424 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20425 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20426 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20427 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20428 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20429 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20430 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20431 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20432 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20433 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20434 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20435 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20436 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20437 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20438 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20439 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20440 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20441 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20442 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20443 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20444 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20445 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20446 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20447 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20448 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20449 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20450 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20451 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20452 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20453 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20454 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20455 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20456 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20457 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20458 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20459 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
20460};
20461#undef ARM_VARIANT
20462#undef THUMB_VARIANT
20463#undef TCE
c19d1205
ZW
20464#undef TUE
20465#undef TUF
20466#undef TCC
8f06b2d8 20467#undef cCE
e3cb604e
PB
20468#undef cCL
20469#undef C3E
c19d1205
ZW
20470#undef CE
20471#undef CM
20472#undef UE
20473#undef UF
20474#undef UT
5287ad62
JB
20475#undef NUF
20476#undef nUF
20477#undef NCE
20478#undef nCE
c19d1205
ZW
20479#undef OPS0
20480#undef OPS1
20481#undef OPS2
20482#undef OPS3
20483#undef OPS4
20484#undef OPS5
20485#undef OPS6
20486#undef do_0
20487\f
20488/* MD interface: bits in the object file. */
bfae80f2 20489
c19d1205
ZW
20490/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20491 for use in the a.out file, and stores them in the array pointed to by buf.
20492 This knows about the endian-ness of the target machine and does
20493 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20494 2 (short) and 4 (long) Floating numbers are put out as a series of
20495 LITTLENUMS (shorts, here at least). */
b99bd4ef 20496
c19d1205
ZW
20497void
20498md_number_to_chars (char * buf, valueT val, int n)
20499{
20500 if (target_big_endian)
20501 number_to_chars_bigendian (buf, val, n);
20502 else
20503 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20504}
20505
c19d1205
ZW
20506static valueT
20507md_chars_to_number (char * buf, int n)
bfae80f2 20508{
c19d1205
ZW
20509 valueT result = 0;
20510 unsigned char * where = (unsigned char *) buf;
bfae80f2 20511
c19d1205 20512 if (target_big_endian)
b99bd4ef 20513 {
c19d1205
ZW
20514 while (n--)
20515 {
20516 result <<= 8;
20517 result |= (*where++ & 255);
20518 }
b99bd4ef 20519 }
c19d1205 20520 else
b99bd4ef 20521 {
c19d1205
ZW
20522 while (n--)
20523 {
20524 result <<= 8;
20525 result |= (where[n] & 255);
20526 }
bfae80f2 20527 }
b99bd4ef 20528
c19d1205 20529 return result;
bfae80f2 20530}
b99bd4ef 20531
c19d1205 20532/* MD interface: Sections. */
b99bd4ef 20533
fa94de6b
RM
20534/* Calculate the maximum variable size (i.e., excluding fr_fix)
20535 that an rs_machine_dependent frag may reach. */
20536
20537unsigned int
20538arm_frag_max_var (fragS *fragp)
20539{
20540 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20541 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20542
20543 Note that we generate relaxable instructions even for cases that don't
20544 really need it, like an immediate that's a trivial constant. So we're
20545 overestimating the instruction size for some of those cases. Rather
20546 than putting more intelligence here, it would probably be better to
20547 avoid generating a relaxation frag in the first place when it can be
20548 determined up front that a short instruction will suffice. */
20549
20550 gas_assert (fragp->fr_type == rs_machine_dependent);
20551 return INSN_SIZE;
20552}
20553
0110f2b8
PB
20554/* Estimate the size of a frag before relaxing. Assume everything fits in
20555 2 bytes. */
20556
c19d1205 20557int
0110f2b8 20558md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20559 segT segtype ATTRIBUTE_UNUSED)
20560{
0110f2b8
PB
20561 fragp->fr_var = 2;
20562 return 2;
20563}
20564
20565/* Convert a machine dependent frag. */
20566
20567void
20568md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20569{
20570 unsigned long insn;
20571 unsigned long old_op;
20572 char *buf;
20573 expressionS exp;
20574 fixS *fixp;
20575 int reloc_type;
20576 int pc_rel;
20577 int opcode;
20578
20579 buf = fragp->fr_literal + fragp->fr_fix;
20580
20581 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20582 if (fragp->fr_symbol)
20583 {
0110f2b8
PB
20584 exp.X_op = O_symbol;
20585 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20586 }
20587 else
20588 {
0110f2b8 20589 exp.X_op = O_constant;
5f4273c7 20590 }
0110f2b8
PB
20591 exp.X_add_number = fragp->fr_offset;
20592 opcode = fragp->fr_subtype;
20593 switch (opcode)
20594 {
20595 case T_MNEM_ldr_pc:
20596 case T_MNEM_ldr_pc2:
20597 case T_MNEM_ldr_sp:
20598 case T_MNEM_str_sp:
20599 case T_MNEM_ldr:
20600 case T_MNEM_ldrb:
20601 case T_MNEM_ldrh:
20602 case T_MNEM_str:
20603 case T_MNEM_strb:
20604 case T_MNEM_strh:
20605 if (fragp->fr_var == 4)
20606 {
5f4273c7 20607 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20608 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20609 {
20610 insn |= (old_op & 0x700) << 4;
20611 }
20612 else
20613 {
20614 insn |= (old_op & 7) << 12;
20615 insn |= (old_op & 0x38) << 13;
20616 }
20617 insn |= 0x00000c00;
20618 put_thumb32_insn (buf, insn);
20619 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20620 }
20621 else
20622 {
20623 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20624 }
20625 pc_rel = (opcode == T_MNEM_ldr_pc2);
20626 break;
20627 case T_MNEM_adr:
20628 if (fragp->fr_var == 4)
20629 {
20630 insn = THUMB_OP32 (opcode);
20631 insn |= (old_op & 0xf0) << 4;
20632 put_thumb32_insn (buf, insn);
20633 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20634 }
20635 else
20636 {
20637 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20638 exp.X_add_number -= 4;
20639 }
20640 pc_rel = 1;
20641 break;
20642 case T_MNEM_mov:
20643 case T_MNEM_movs:
20644 case T_MNEM_cmp:
20645 case T_MNEM_cmn:
20646 if (fragp->fr_var == 4)
20647 {
20648 int r0off = (opcode == T_MNEM_mov
20649 || opcode == T_MNEM_movs) ? 0 : 8;
20650 insn = THUMB_OP32 (opcode);
20651 insn = (insn & 0xe1ffffff) | 0x10000000;
20652 insn |= (old_op & 0x700) << r0off;
20653 put_thumb32_insn (buf, insn);
20654 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20655 }
20656 else
20657 {
20658 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20659 }
20660 pc_rel = 0;
20661 break;
20662 case T_MNEM_b:
20663 if (fragp->fr_var == 4)
20664 {
20665 insn = THUMB_OP32(opcode);
20666 put_thumb32_insn (buf, insn);
20667 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20668 }
20669 else
20670 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20671 pc_rel = 1;
20672 break;
20673 case T_MNEM_bcond:
20674 if (fragp->fr_var == 4)
20675 {
20676 insn = THUMB_OP32(opcode);
20677 insn |= (old_op & 0xf00) << 14;
20678 put_thumb32_insn (buf, insn);
20679 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20680 }
20681 else
20682 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20683 pc_rel = 1;
20684 break;
20685 case T_MNEM_add_sp:
20686 case T_MNEM_add_pc:
20687 case T_MNEM_inc_sp:
20688 case T_MNEM_dec_sp:
20689 if (fragp->fr_var == 4)
20690 {
20691 /* ??? Choose between add and addw. */
20692 insn = THUMB_OP32 (opcode);
20693 insn |= (old_op & 0xf0) << 4;
20694 put_thumb32_insn (buf, insn);
16805f35
PB
20695 if (opcode == T_MNEM_add_pc)
20696 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20697 else
20698 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20699 }
20700 else
20701 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20702 pc_rel = 0;
20703 break;
20704
20705 case T_MNEM_addi:
20706 case T_MNEM_addis:
20707 case T_MNEM_subi:
20708 case T_MNEM_subis:
20709 if (fragp->fr_var == 4)
20710 {
20711 insn = THUMB_OP32 (opcode);
20712 insn |= (old_op & 0xf0) << 4;
20713 insn |= (old_op & 0xf) << 16;
20714 put_thumb32_insn (buf, insn);
16805f35
PB
20715 if (insn & (1 << 20))
20716 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20717 else
20718 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20719 }
20720 else
20721 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20722 pc_rel = 0;
20723 break;
20724 default:
5f4273c7 20725 abort ();
0110f2b8
PB
20726 }
20727 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20728 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20729 fixp->fx_file = fragp->fr_file;
20730 fixp->fx_line = fragp->fr_line;
20731 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
20732
20733 /* Set whether we use thumb-2 ISA based on final relaxation results. */
20734 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
20735 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
20736 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
20737}
20738
20739/* Return the size of a relaxable immediate operand instruction.
20740 SHIFT and SIZE specify the form of the allowable immediate. */
20741static int
20742relax_immediate (fragS *fragp, int size, int shift)
20743{
20744 offsetT offset;
20745 offsetT mask;
20746 offsetT low;
20747
20748 /* ??? Should be able to do better than this. */
20749 if (fragp->fr_symbol)
20750 return 4;
20751
20752 low = (1 << shift) - 1;
20753 mask = (1 << (shift + size)) - (1 << shift);
20754 offset = fragp->fr_offset;
20755 /* Force misaligned offsets to 32-bit variant. */
20756 if (offset & low)
5e77afaa 20757 return 4;
0110f2b8
PB
20758 if (offset & ~mask)
20759 return 4;
20760 return 2;
20761}
20762
5e77afaa
PB
20763/* Get the address of a symbol during relaxation. */
20764static addressT
5f4273c7 20765relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20766{
20767 fragS *sym_frag;
20768 addressT addr;
20769 symbolS *sym;
20770
20771 sym = fragp->fr_symbol;
20772 sym_frag = symbol_get_frag (sym);
20773 know (S_GET_SEGMENT (sym) != absolute_section
20774 || sym_frag == &zero_address_frag);
20775 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20776
20777 /* If frag has yet to be reached on this pass, assume it will
20778 move by STRETCH just as we did. If this is not so, it will
20779 be because some frag between grows, and that will force
20780 another pass. */
20781
20782 if (stretch != 0
20783 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20784 {
20785 fragS *f;
20786
20787 /* Adjust stretch for any alignment frag. Note that if have
20788 been expanding the earlier code, the symbol may be
20789 defined in what appears to be an earlier frag. FIXME:
20790 This doesn't handle the fr_subtype field, which specifies
20791 a maximum number of bytes to skip when doing an
20792 alignment. */
20793 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20794 {
20795 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20796 {
20797 if (stretch < 0)
20798 stretch = - ((- stretch)
20799 & ~ ((1 << (int) f->fr_offset) - 1));
20800 else
20801 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20802 if (stretch == 0)
20803 break;
20804 }
20805 }
20806 if (f != NULL)
20807 addr += stretch;
20808 }
5e77afaa
PB
20809
20810 return addr;
20811}
20812
0110f2b8
PB
20813/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20814 load. */
20815static int
5e77afaa 20816relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20817{
20818 addressT addr;
20819 offsetT val;
20820
20821 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20822 if (fragp->fr_symbol == NULL
20823 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20824 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20825 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20826 return 4;
20827
5f4273c7 20828 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20829 addr = fragp->fr_address + fragp->fr_fix;
20830 addr = (addr + 4) & ~3;
5e77afaa 20831 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20832 if (val & 3)
5e77afaa 20833 return 4;
0110f2b8
PB
20834 val -= addr;
20835 if (val < 0 || val > 1020)
20836 return 4;
20837 return 2;
20838}
20839
20840/* Return the size of a relaxable add/sub immediate instruction. */
20841static int
20842relax_addsub (fragS *fragp, asection *sec)
20843{
20844 char *buf;
20845 int op;
20846
20847 buf = fragp->fr_literal + fragp->fr_fix;
20848 op = bfd_get_16(sec->owner, buf);
20849 if ((op & 0xf) == ((op >> 4) & 0xf))
20850 return relax_immediate (fragp, 8, 0);
20851 else
20852 return relax_immediate (fragp, 3, 0);
20853}
20854
e83a675f
RE
20855/* Return TRUE iff the definition of symbol S could be pre-empted
20856 (overridden) at link or load time. */
20857static bfd_boolean
20858symbol_preemptible (symbolS *s)
20859{
20860 /* Weak symbols can always be pre-empted. */
20861 if (S_IS_WEAK (s))
20862 return TRUE;
20863
20864 /* Non-global symbols cannot be pre-empted. */
20865 if (! S_IS_EXTERNAL (s))
20866 return FALSE;
20867
20868#ifdef OBJ_ELF
20869 /* In ELF, a global symbol can be marked protected, or private. In that
20870 case it can't be pre-empted (other definitions in the same link unit
20871 would violate the ODR). */
20872 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20873 return FALSE;
20874#endif
20875
20876 /* Other global symbols might be pre-empted. */
20877 return TRUE;
20878}
0110f2b8
PB
20879
20880/* Return the size of a relaxable branch instruction. BITS is the
20881 size of the offset field in the narrow instruction. */
20882
20883static int
5e77afaa 20884relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20885{
20886 addressT addr;
20887 offsetT val;
20888 offsetT limit;
20889
20890 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20891 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20892 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20893 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20894 return 4;
20895
267bf995 20896#ifdef OBJ_ELF
e83a675f 20897 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
20898 if (S_IS_DEFINED (fragp->fr_symbol)
20899 && ARM_IS_FUNC (fragp->fr_symbol))
20900 return 4;
e83a675f 20901#endif
0d9b4b55 20902
e83a675f 20903 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 20904 return 4;
267bf995 20905
5f4273c7 20906 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20907 addr = fragp->fr_address + fragp->fr_fix + 4;
20908 val -= addr;
20909
20910 /* Offset is a signed value *2 */
20911 limit = 1 << bits;
20912 if (val >= limit || val < -limit)
20913 return 4;
20914 return 2;
20915}
20916
20917
20918/* Relax a machine dependent frag. This returns the amount by which
20919 the current size of the frag should change. */
20920
20921int
5e77afaa 20922arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20923{
20924 int oldsize;
20925 int newsize;
20926
20927 oldsize = fragp->fr_var;
20928 switch (fragp->fr_subtype)
20929 {
20930 case T_MNEM_ldr_pc2:
5f4273c7 20931 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20932 break;
20933 case T_MNEM_ldr_pc:
20934 case T_MNEM_ldr_sp:
20935 case T_MNEM_str_sp:
5f4273c7 20936 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
20937 break;
20938 case T_MNEM_ldr:
20939 case T_MNEM_str:
5f4273c7 20940 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
20941 break;
20942 case T_MNEM_ldrh:
20943 case T_MNEM_strh:
5f4273c7 20944 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
20945 break;
20946 case T_MNEM_ldrb:
20947 case T_MNEM_strb:
5f4273c7 20948 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
20949 break;
20950 case T_MNEM_adr:
5f4273c7 20951 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20952 break;
20953 case T_MNEM_mov:
20954 case T_MNEM_movs:
20955 case T_MNEM_cmp:
20956 case T_MNEM_cmn:
5f4273c7 20957 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
20958 break;
20959 case T_MNEM_b:
5f4273c7 20960 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
20961 break;
20962 case T_MNEM_bcond:
5f4273c7 20963 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
20964 break;
20965 case T_MNEM_add_sp:
20966 case T_MNEM_add_pc:
20967 newsize = relax_immediate (fragp, 8, 2);
20968 break;
20969 case T_MNEM_inc_sp:
20970 case T_MNEM_dec_sp:
20971 newsize = relax_immediate (fragp, 7, 2);
20972 break;
20973 case T_MNEM_addi:
20974 case T_MNEM_addis:
20975 case T_MNEM_subi:
20976 case T_MNEM_subis:
20977 newsize = relax_addsub (fragp, sec);
20978 break;
20979 default:
5f4273c7 20980 abort ();
0110f2b8 20981 }
5e77afaa
PB
20982
20983 fragp->fr_var = newsize;
20984 /* Freeze wide instructions that are at or before the same location as
20985 in the previous pass. This avoids infinite loops.
5f4273c7
NC
20986 Don't freeze them unconditionally because targets may be artificially
20987 misaligned by the expansion of preceding frags. */
5e77afaa 20988 if (stretch <= 0 && newsize > 2)
0110f2b8 20989 {
0110f2b8 20990 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 20991 frag_wane (fragp);
0110f2b8 20992 }
5e77afaa 20993
0110f2b8 20994 return newsize - oldsize;
c19d1205 20995}
b99bd4ef 20996
c19d1205 20997/* Round up a section size to the appropriate boundary. */
b99bd4ef 20998
c19d1205
ZW
20999valueT
21000md_section_align (segT segment ATTRIBUTE_UNUSED,
21001 valueT size)
21002{
f0927246
NC
21003#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21004 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21005 {
21006 /* For a.out, force the section size to be aligned. If we don't do
21007 this, BFD will align it for us, but it will not write out the
21008 final bytes of the section. This may be a bug in BFD, but it is
21009 easier to fix it here since that is how the other a.out targets
21010 work. */
21011 int align;
21012
21013 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21014 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21015 }
c19d1205 21016#endif
f0927246
NC
21017
21018 return size;
bfae80f2 21019}
b99bd4ef 21020
c19d1205
ZW
21021/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21022 of an rs_align_code fragment. */
21023
21024void
21025arm_handle_align (fragS * fragP)
bfae80f2 21026{
e7495e45
NS
21027 static char const arm_noop[2][2][4] =
21028 {
21029 { /* ARMv1 */
21030 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21031 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21032 },
21033 { /* ARMv6k */
21034 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21035 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21036 },
21037 };
21038 static char const thumb_noop[2][2][2] =
21039 {
21040 { /* Thumb-1 */
21041 {0xc0, 0x46}, /* LE */
21042 {0x46, 0xc0}, /* BE */
21043 },
21044 { /* Thumb-2 */
21045 {0x00, 0xbf}, /* LE */
21046 {0xbf, 0x00} /* BE */
21047 }
21048 };
21049 static char const wide_thumb_noop[2][4] =
21050 { /* Wide Thumb-2 */
21051 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21052 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21053 };
c921be7d 21054
e7495e45 21055 unsigned bytes, fix, noop_size;
c19d1205
ZW
21056 char * p;
21057 const char * noop;
e7495e45 21058 const char *narrow_noop = NULL;
cd000bff
DJ
21059#ifdef OBJ_ELF
21060 enum mstate state;
21061#endif
bfae80f2 21062
c19d1205 21063 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21064 return;
21065
c19d1205
ZW
21066 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21067 p = fragP->fr_literal + fragP->fr_fix;
21068 fix = 0;
bfae80f2 21069
c19d1205
ZW
21070 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21071 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21072
cd000bff 21073 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21074
cd000bff 21075 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21076 {
7f78eb34
JW
21077 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21078 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21079 {
21080 narrow_noop = thumb_noop[1][target_big_endian];
21081 noop = wide_thumb_noop[target_big_endian];
21082 }
c19d1205 21083 else
e7495e45
NS
21084 noop = thumb_noop[0][target_big_endian];
21085 noop_size = 2;
cd000bff
DJ
21086#ifdef OBJ_ELF
21087 state = MAP_THUMB;
21088#endif
7ed4c4c5
NC
21089 }
21090 else
21091 {
7f78eb34
JW
21092 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21093 ? selected_cpu : arm_arch_none,
21094 arm_ext_v6k) != 0]
e7495e45
NS
21095 [target_big_endian];
21096 noop_size = 4;
cd000bff
DJ
21097#ifdef OBJ_ELF
21098 state = MAP_ARM;
21099#endif
7ed4c4c5 21100 }
c921be7d 21101
e7495e45 21102 fragP->fr_var = noop_size;
c921be7d 21103
c19d1205 21104 if (bytes & (noop_size - 1))
7ed4c4c5 21105 {
c19d1205 21106 fix = bytes & (noop_size - 1);
cd000bff
DJ
21107#ifdef OBJ_ELF
21108 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21109#endif
c19d1205
ZW
21110 memset (p, 0, fix);
21111 p += fix;
21112 bytes -= fix;
a737bd4d 21113 }
a737bd4d 21114
e7495e45
NS
21115 if (narrow_noop)
21116 {
21117 if (bytes & noop_size)
21118 {
21119 /* Insert a narrow noop. */
21120 memcpy (p, narrow_noop, noop_size);
21121 p += noop_size;
21122 bytes -= noop_size;
21123 fix += noop_size;
21124 }
21125
21126 /* Use wide noops for the remainder */
21127 noop_size = 4;
21128 }
21129
c19d1205 21130 while (bytes >= noop_size)
a737bd4d 21131 {
c19d1205
ZW
21132 memcpy (p, noop, noop_size);
21133 p += noop_size;
21134 bytes -= noop_size;
21135 fix += noop_size;
a737bd4d
NC
21136 }
21137
c19d1205 21138 fragP->fr_fix += fix;
a737bd4d
NC
21139}
21140
c19d1205
ZW
21141/* Called from md_do_align. Used to create an alignment
21142 frag in a code section. */
21143
21144void
21145arm_frag_align_code (int n, int max)
bfae80f2 21146{
c19d1205 21147 char * p;
7ed4c4c5 21148
c19d1205 21149 /* We assume that there will never be a requirement
6ec8e702 21150 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21151 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21152 {
21153 char err_msg[128];
21154
fa94de6b 21155 sprintf (err_msg,
477330fc
RM
21156 _("alignments greater than %d bytes not supported in .text sections."),
21157 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21158 as_fatal ("%s", err_msg);
6ec8e702 21159 }
bfae80f2 21160
c19d1205
ZW
21161 p = frag_var (rs_align_code,
21162 MAX_MEM_FOR_RS_ALIGN_CODE,
21163 1,
21164 (relax_substateT) max,
21165 (symbolS *) NULL,
21166 (offsetT) n,
21167 (char *) NULL);
21168 *p = 0;
21169}
bfae80f2 21170
8dc2430f
NC
21171/* Perform target specific initialisation of a frag.
21172 Note - despite the name this initialisation is not done when the frag
21173 is created, but only when its type is assigned. A frag can be created
21174 and used a long time before its type is set, so beware of assuming that
21175 this initialisationis performed first. */
bfae80f2 21176
cd000bff
DJ
21177#ifndef OBJ_ELF
21178void
21179arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21180{
21181 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21182 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21183}
21184
21185#else /* OBJ_ELF is defined. */
c19d1205 21186void
cd000bff 21187arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21188{
b968d18a
JW
21189 int frag_thumb_mode;
21190
8dc2430f
NC
21191 /* If the current ARM vs THUMB mode has not already
21192 been recorded into this frag then do so now. */
cd000bff 21193 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21194 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21195
21196 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21197
f9c1b181
RL
21198 /* Record a mapping symbol for alignment frags. We will delete this
21199 later if the alignment ends up empty. */
21200 switch (fragP->fr_type)
21201 {
21202 case rs_align:
21203 case rs_align_test:
21204 case rs_fill:
21205 mapping_state_2 (MAP_DATA, max_chars);
21206 break;
21207 case rs_align_code:
b968d18a 21208 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21209 break;
21210 default:
21211 break;
cd000bff 21212 }
bfae80f2
RE
21213}
21214
c19d1205
ZW
21215/* When we change sections we need to issue a new mapping symbol. */
21216
21217void
21218arm_elf_change_section (void)
bfae80f2 21219{
c19d1205
ZW
21220 /* Link an unlinked unwind index table section to the .text section. */
21221 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21222 && elf_linked_to_section (now_seg) == NULL)
21223 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21224}
21225
c19d1205
ZW
21226int
21227arm_elf_section_type (const char * str, size_t len)
e45d0630 21228{
c19d1205
ZW
21229 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21230 return SHT_ARM_EXIDX;
e45d0630 21231
c19d1205
ZW
21232 return -1;
21233}
21234\f
21235/* Code to deal with unwinding tables. */
e45d0630 21236
c19d1205 21237static void add_unwind_adjustsp (offsetT);
e45d0630 21238
5f4273c7 21239/* Generate any deferred unwind frame offset. */
e45d0630 21240
bfae80f2 21241static void
c19d1205 21242flush_pending_unwind (void)
bfae80f2 21243{
c19d1205 21244 offsetT offset;
bfae80f2 21245
c19d1205
ZW
21246 offset = unwind.pending_offset;
21247 unwind.pending_offset = 0;
21248 if (offset != 0)
21249 add_unwind_adjustsp (offset);
bfae80f2
RE
21250}
21251
c19d1205
ZW
21252/* Add an opcode to this list for this function. Two-byte opcodes should
21253 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21254 order. */
21255
bfae80f2 21256static void
c19d1205 21257add_unwind_opcode (valueT op, int length)
bfae80f2 21258{
c19d1205
ZW
21259 /* Add any deferred stack adjustment. */
21260 if (unwind.pending_offset)
21261 flush_pending_unwind ();
bfae80f2 21262
c19d1205 21263 unwind.sp_restored = 0;
bfae80f2 21264
c19d1205 21265 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21266 {
c19d1205
ZW
21267 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21268 if (unwind.opcodes)
21d799b5 21269 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21270 unwind.opcode_alloc);
c19d1205 21271 else
21d799b5 21272 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21273 }
c19d1205 21274 while (length > 0)
bfae80f2 21275 {
c19d1205
ZW
21276 length--;
21277 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21278 op >>= 8;
21279 unwind.opcode_count++;
bfae80f2 21280 }
bfae80f2
RE
21281}
21282
c19d1205
ZW
21283/* Add unwind opcodes to adjust the stack pointer. */
21284
bfae80f2 21285static void
c19d1205 21286add_unwind_adjustsp (offsetT offset)
bfae80f2 21287{
c19d1205 21288 valueT op;
bfae80f2 21289
c19d1205 21290 if (offset > 0x200)
bfae80f2 21291 {
c19d1205
ZW
21292 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21293 char bytes[5];
21294 int n;
21295 valueT o;
bfae80f2 21296
c19d1205
ZW
21297 /* Long form: 0xb2, uleb128. */
21298 /* This might not fit in a word so add the individual bytes,
21299 remembering the list is built in reverse order. */
21300 o = (valueT) ((offset - 0x204) >> 2);
21301 if (o == 0)
21302 add_unwind_opcode (0, 1);
bfae80f2 21303
c19d1205
ZW
21304 /* Calculate the uleb128 encoding of the offset. */
21305 n = 0;
21306 while (o)
21307 {
21308 bytes[n] = o & 0x7f;
21309 o >>= 7;
21310 if (o)
21311 bytes[n] |= 0x80;
21312 n++;
21313 }
21314 /* Add the insn. */
21315 for (; n; n--)
21316 add_unwind_opcode (bytes[n - 1], 1);
21317 add_unwind_opcode (0xb2, 1);
21318 }
21319 else if (offset > 0x100)
bfae80f2 21320 {
c19d1205
ZW
21321 /* Two short opcodes. */
21322 add_unwind_opcode (0x3f, 1);
21323 op = (offset - 0x104) >> 2;
21324 add_unwind_opcode (op, 1);
bfae80f2 21325 }
c19d1205
ZW
21326 else if (offset > 0)
21327 {
21328 /* Short opcode. */
21329 op = (offset - 4) >> 2;
21330 add_unwind_opcode (op, 1);
21331 }
21332 else if (offset < 0)
bfae80f2 21333 {
c19d1205
ZW
21334 offset = -offset;
21335 while (offset > 0x100)
bfae80f2 21336 {
c19d1205
ZW
21337 add_unwind_opcode (0x7f, 1);
21338 offset -= 0x100;
bfae80f2 21339 }
c19d1205
ZW
21340 op = ((offset - 4) >> 2) | 0x40;
21341 add_unwind_opcode (op, 1);
bfae80f2 21342 }
bfae80f2
RE
21343}
21344
c19d1205
ZW
21345/* Finish the list of unwind opcodes for this function. */
21346static void
21347finish_unwind_opcodes (void)
bfae80f2 21348{
c19d1205 21349 valueT op;
bfae80f2 21350
c19d1205 21351 if (unwind.fp_used)
bfae80f2 21352 {
708587a4 21353 /* Adjust sp as necessary. */
c19d1205
ZW
21354 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21355 flush_pending_unwind ();
bfae80f2 21356
c19d1205
ZW
21357 /* After restoring sp from the frame pointer. */
21358 op = 0x90 | unwind.fp_reg;
21359 add_unwind_opcode (op, 1);
21360 }
21361 else
21362 flush_pending_unwind ();
bfae80f2
RE
21363}
21364
bfae80f2 21365
c19d1205
ZW
21366/* Start an exception table entry. If idx is nonzero this is an index table
21367 entry. */
bfae80f2
RE
21368
21369static void
c19d1205 21370start_unwind_section (const segT text_seg, int idx)
bfae80f2 21371{
c19d1205
ZW
21372 const char * text_name;
21373 const char * prefix;
21374 const char * prefix_once;
21375 const char * group_name;
21376 size_t prefix_len;
21377 size_t text_len;
21378 char * sec_name;
21379 size_t sec_name_len;
21380 int type;
21381 int flags;
21382 int linkonce;
bfae80f2 21383
c19d1205 21384 if (idx)
bfae80f2 21385 {
c19d1205
ZW
21386 prefix = ELF_STRING_ARM_unwind;
21387 prefix_once = ELF_STRING_ARM_unwind_once;
21388 type = SHT_ARM_EXIDX;
bfae80f2 21389 }
c19d1205 21390 else
bfae80f2 21391 {
c19d1205
ZW
21392 prefix = ELF_STRING_ARM_unwind_info;
21393 prefix_once = ELF_STRING_ARM_unwind_info_once;
21394 type = SHT_PROGBITS;
bfae80f2
RE
21395 }
21396
c19d1205
ZW
21397 text_name = segment_name (text_seg);
21398 if (streq (text_name, ".text"))
21399 text_name = "";
21400
21401 if (strncmp (text_name, ".gnu.linkonce.t.",
21402 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21403 {
c19d1205
ZW
21404 prefix = prefix_once;
21405 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21406 }
21407
c19d1205
ZW
21408 prefix_len = strlen (prefix);
21409 text_len = strlen (text_name);
21410 sec_name_len = prefix_len + text_len;
21d799b5 21411 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21412 memcpy (sec_name, prefix, prefix_len);
21413 memcpy (sec_name + prefix_len, text_name, text_len);
21414 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21415
c19d1205
ZW
21416 flags = SHF_ALLOC;
21417 linkonce = 0;
21418 group_name = 0;
bfae80f2 21419
c19d1205
ZW
21420 /* Handle COMDAT group. */
21421 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21422 {
c19d1205
ZW
21423 group_name = elf_group_name (text_seg);
21424 if (group_name == NULL)
21425 {
bd3ba5d1 21426 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21427 segment_name (text_seg));
21428 ignore_rest_of_line ();
21429 return;
21430 }
21431 flags |= SHF_GROUP;
21432 linkonce = 1;
bfae80f2
RE
21433 }
21434
c19d1205 21435 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21436
5f4273c7 21437 /* Set the section link for index tables. */
c19d1205
ZW
21438 if (idx)
21439 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21440}
21441
bfae80f2 21442
c19d1205
ZW
21443/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21444 personality routine data. Returns zero, or the index table value for
cad0da33 21445 an inline entry. */
c19d1205
ZW
21446
21447static valueT
21448create_unwind_entry (int have_data)
bfae80f2 21449{
c19d1205
ZW
21450 int size;
21451 addressT where;
21452 char *ptr;
21453 /* The current word of data. */
21454 valueT data;
21455 /* The number of bytes left in this word. */
21456 int n;
bfae80f2 21457
c19d1205 21458 finish_unwind_opcodes ();
bfae80f2 21459
c19d1205
ZW
21460 /* Remember the current text section. */
21461 unwind.saved_seg = now_seg;
21462 unwind.saved_subseg = now_subseg;
bfae80f2 21463
c19d1205 21464 start_unwind_section (now_seg, 0);
bfae80f2 21465
c19d1205 21466 if (unwind.personality_routine == NULL)
bfae80f2 21467 {
c19d1205
ZW
21468 if (unwind.personality_index == -2)
21469 {
21470 if (have_data)
5f4273c7 21471 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21472 return 1; /* EXIDX_CANTUNWIND. */
21473 }
bfae80f2 21474
c19d1205
ZW
21475 /* Use a default personality routine if none is specified. */
21476 if (unwind.personality_index == -1)
21477 {
21478 if (unwind.opcode_count > 3)
21479 unwind.personality_index = 1;
21480 else
21481 unwind.personality_index = 0;
21482 }
bfae80f2 21483
c19d1205
ZW
21484 /* Space for the personality routine entry. */
21485 if (unwind.personality_index == 0)
21486 {
21487 if (unwind.opcode_count > 3)
21488 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21489
c19d1205
ZW
21490 if (!have_data)
21491 {
21492 /* All the data is inline in the index table. */
21493 data = 0x80;
21494 n = 3;
21495 while (unwind.opcode_count > 0)
21496 {
21497 unwind.opcode_count--;
21498 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21499 n--;
21500 }
bfae80f2 21501
c19d1205
ZW
21502 /* Pad with "finish" opcodes. */
21503 while (n--)
21504 data = (data << 8) | 0xb0;
bfae80f2 21505
c19d1205
ZW
21506 return data;
21507 }
21508 size = 0;
21509 }
21510 else
21511 /* We get two opcodes "free" in the first word. */
21512 size = unwind.opcode_count - 2;
21513 }
21514 else
5011093d 21515 {
cad0da33
NC
21516 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21517 if (unwind.personality_index != -1)
21518 {
21519 as_bad (_("attempt to recreate an unwind entry"));
21520 return 1;
21521 }
5011093d
NC
21522
21523 /* An extra byte is required for the opcode count. */
21524 size = unwind.opcode_count + 1;
21525 }
bfae80f2 21526
c19d1205
ZW
21527 size = (size + 3) >> 2;
21528 if (size > 0xff)
21529 as_bad (_("too many unwind opcodes"));
bfae80f2 21530
c19d1205
ZW
21531 frag_align (2, 0, 0);
21532 record_alignment (now_seg, 2);
21533 unwind.table_entry = expr_build_dot ();
21534
21535 /* Allocate the table entry. */
21536 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21537 /* PR 13449: Zero the table entries in case some of them are not used. */
21538 memset (ptr, 0, (size << 2) + 4);
c19d1205 21539 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21540
c19d1205 21541 switch (unwind.personality_index)
bfae80f2 21542 {
c19d1205
ZW
21543 case -1:
21544 /* ??? Should this be a PLT generating relocation? */
21545 /* Custom personality routine. */
21546 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21547 BFD_RELOC_ARM_PREL31);
bfae80f2 21548
c19d1205
ZW
21549 where += 4;
21550 ptr += 4;
bfae80f2 21551
c19d1205 21552 /* Set the first byte to the number of additional words. */
5011093d 21553 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21554 n = 3;
21555 break;
bfae80f2 21556
c19d1205
ZW
21557 /* ABI defined personality routines. */
21558 case 0:
21559 /* Three opcodes bytes are packed into the first word. */
21560 data = 0x80;
21561 n = 3;
21562 break;
bfae80f2 21563
c19d1205
ZW
21564 case 1:
21565 case 2:
21566 /* The size and first two opcode bytes go in the first word. */
21567 data = ((0x80 + unwind.personality_index) << 8) | size;
21568 n = 2;
21569 break;
bfae80f2 21570
c19d1205
ZW
21571 default:
21572 /* Should never happen. */
21573 abort ();
21574 }
bfae80f2 21575
c19d1205
ZW
21576 /* Pack the opcodes into words (MSB first), reversing the list at the same
21577 time. */
21578 while (unwind.opcode_count > 0)
21579 {
21580 if (n == 0)
21581 {
21582 md_number_to_chars (ptr, data, 4);
21583 ptr += 4;
21584 n = 4;
21585 data = 0;
21586 }
21587 unwind.opcode_count--;
21588 n--;
21589 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21590 }
21591
21592 /* Finish off the last word. */
21593 if (n < 4)
21594 {
21595 /* Pad with "finish" opcodes. */
21596 while (n--)
21597 data = (data << 8) | 0xb0;
21598
21599 md_number_to_chars (ptr, data, 4);
21600 }
21601
21602 if (!have_data)
21603 {
21604 /* Add an empty descriptor if there is no user-specified data. */
21605 ptr = frag_more (4);
21606 md_number_to_chars (ptr, 0, 4);
21607 }
21608
21609 return 0;
bfae80f2
RE
21610}
21611
f0927246
NC
21612
21613/* Initialize the DWARF-2 unwind information for this procedure. */
21614
21615void
21616tc_arm_frame_initial_instructions (void)
21617{
21618 cfi_add_CFA_def_cfa (REG_SP, 0);
21619}
21620#endif /* OBJ_ELF */
21621
c19d1205
ZW
21622/* Convert REGNAME to a DWARF-2 register number. */
21623
21624int
1df69f4f 21625tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 21626{
1df69f4f 21627 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
21628 if (reg != FAIL)
21629 return reg;
c19d1205 21630
1f5afe1c
NC
21631 /* PR 16694: Allow VFP registers as well. */
21632 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21633 if (reg != FAIL)
21634 return 64 + reg;
c19d1205 21635
1f5afe1c
NC
21636 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21637 if (reg != FAIL)
21638 return reg + 256;
21639
21640 return -1;
bfae80f2
RE
21641}
21642
f0927246 21643#ifdef TE_PE
c19d1205 21644void
f0927246 21645tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 21646{
91d6fa6a 21647 expressionS exp;
bfae80f2 21648
91d6fa6a
NC
21649 exp.X_op = O_secrel;
21650 exp.X_add_symbol = symbol;
21651 exp.X_add_number = 0;
21652 emit_expr (&exp, size);
f0927246
NC
21653}
21654#endif
bfae80f2 21655
c19d1205 21656/* MD interface: Symbol and relocation handling. */
bfae80f2 21657
2fc8bdac
ZW
21658/* Return the address within the segment that a PC-relative fixup is
21659 relative to. For ARM, PC-relative fixups applied to instructions
21660 are generally relative to the location of the fixup plus 8 bytes.
21661 Thumb branches are offset by 4, and Thumb loads relative to PC
21662 require special handling. */
bfae80f2 21663
c19d1205 21664long
2fc8bdac 21665md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 21666{
2fc8bdac
ZW
21667 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21668
21669 /* If this is pc-relative and we are going to emit a relocation
21670 then we just want to put out any pipeline compensation that the linker
53baae48
NC
21671 will need. Otherwise we want to use the calculated base.
21672 For WinCE we skip the bias for externals as well, since this
21673 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 21674 if (fixP->fx_pcrel
2fc8bdac 21675 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
21676 || (arm_force_relocation (fixP)
21677#ifdef TE_WINCE
21678 && !S_IS_EXTERNAL (fixP->fx_addsy)
21679#endif
21680 )))
2fc8bdac 21681 base = 0;
bfae80f2 21682
267bf995 21683
c19d1205 21684 switch (fixP->fx_r_type)
bfae80f2 21685 {
2fc8bdac
ZW
21686 /* PC relative addressing on the Thumb is slightly odd as the
21687 bottom two bits of the PC are forced to zero for the
21688 calculation. This happens *after* application of the
21689 pipeline offset. However, Thumb adrl already adjusts for
21690 this, so we need not do it again. */
c19d1205 21691 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 21692 return base & ~3;
c19d1205
ZW
21693
21694 case BFD_RELOC_ARM_THUMB_OFFSET:
21695 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 21696 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 21697 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 21698 return (base + 4) & ~3;
c19d1205 21699
2fc8bdac
ZW
21700 /* Thumb branches are simply offset by +4. */
21701 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21702 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21703 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21704 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 21705 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 21706 return base + 4;
bfae80f2 21707
267bf995 21708 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
21709 if (fixP->fx_addsy
21710 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21711 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 21712 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
21713 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21714 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
21715 return base + 4;
21716
00adf2d4
JB
21717 /* BLX is like branches above, but forces the low two bits of PC to
21718 zero. */
486499d0
CL
21719 case BFD_RELOC_THUMB_PCREL_BLX:
21720 if (fixP->fx_addsy
21721 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21722 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21723 && THUMB_IS_FUNC (fixP->fx_addsy)
21724 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21725 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
21726 return (base + 4) & ~3;
21727
2fc8bdac
ZW
21728 /* ARM mode branches are offset by +8. However, the Windows CE
21729 loader expects the relocation not to take this into account. */
267bf995 21730 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
21731 if (fixP->fx_addsy
21732 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21733 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21734 && ARM_IS_FUNC (fixP->fx_addsy)
21735 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21736 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21737 return base + 8;
267bf995 21738
486499d0
CL
21739 case BFD_RELOC_ARM_PCREL_CALL:
21740 if (fixP->fx_addsy
21741 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21742 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21743 && THUMB_IS_FUNC (fixP->fx_addsy)
21744 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21745 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21746 return base + 8;
267bf995 21747
2fc8bdac 21748 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21749 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21750 case BFD_RELOC_ARM_PLT32:
c19d1205 21751#ifdef TE_WINCE
5f4273c7 21752 /* When handling fixups immediately, because we have already
477330fc 21753 discovered the value of a symbol, or the address of the frag involved
53baae48 21754 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
21755 see fixup_segment() in write.c
21756 The S_IS_EXTERNAL test handles the case of global symbols.
21757 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
21758 if (fixP->fx_pcrel
21759 && fixP->fx_addsy != NULL
21760 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21761 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21762 return base + 8;
2fc8bdac 21763 return base;
c19d1205 21764#else
2fc8bdac 21765 return base + 8;
c19d1205 21766#endif
2fc8bdac 21767
267bf995 21768
2fc8bdac
ZW
21769 /* ARM mode loads relative to PC are also offset by +8. Unlike
21770 branches, the Windows CE loader *does* expect the relocation
21771 to take this into account. */
21772 case BFD_RELOC_ARM_OFFSET_IMM:
21773 case BFD_RELOC_ARM_OFFSET_IMM8:
21774 case BFD_RELOC_ARM_HWLITERAL:
21775 case BFD_RELOC_ARM_LITERAL:
21776 case BFD_RELOC_ARM_CP_OFF_IMM:
21777 return base + 8;
21778
21779
21780 /* Other PC-relative relocations are un-offset. */
21781 default:
21782 return base;
21783 }
bfae80f2
RE
21784}
21785
8b2d793c
NC
21786static bfd_boolean flag_warn_syms = TRUE;
21787
ae8714c2
NC
21788bfd_boolean
21789arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 21790{
8b2d793c
NC
21791 /* PR 18347 - Warn if the user attempts to create a symbol with the same
21792 name as an ARM instruction. Whilst strictly speaking it is allowed, it
21793 does mean that the resulting code might be very confusing to the reader.
21794 Also this warning can be triggered if the user omits an operand before
21795 an immediate address, eg:
21796
21797 LDR =foo
21798
21799 GAS treats this as an assignment of the value of the symbol foo to a
21800 symbol LDR, and so (without this code) it will not issue any kind of
21801 warning or error message.
21802
21803 Note - ARM instructions are case-insensitive but the strings in the hash
21804 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
21805 lower case too. */
21806 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
21807 {
21808 char * nbuf = strdup (name);
21809 char * p;
21810
21811 for (p = nbuf; *p; p++)
21812 *p = TOLOWER (*p);
21813 if (hash_find (arm_ops_hsh, nbuf) != NULL)
21814 {
21815 static struct hash_control * already_warned = NULL;
21816
21817 if (already_warned == NULL)
21818 already_warned = hash_new ();
21819 /* Only warn about the symbol once. To keep the code
21820 simple we let hash_insert do the lookup for us. */
21821 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 21822 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
21823 }
21824 else
21825 free (nbuf);
21826 }
3739860c 21827
ae8714c2
NC
21828 return FALSE;
21829}
21830
21831/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21832 Otherwise we have no need to default values of symbols. */
21833
21834symbolS *
21835md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21836{
21837#ifdef OBJ_ELF
21838 if (name[0] == '_' && name[1] == 'G'
21839 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21840 {
21841 if (!GOT_symbol)
21842 {
21843 if (symbol_find (name))
21844 as_bad (_("GOT already in the symbol table"));
21845
21846 GOT_symbol = symbol_new (name, undefined_section,
21847 (valueT) 0, & zero_address_frag);
21848 }
21849
21850 return GOT_symbol;
21851 }
21852#endif
21853
c921be7d 21854 return NULL;
bfae80f2
RE
21855}
21856
55cf6793 21857/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21858 computed as two separate immediate values, added together. We
21859 already know that this value cannot be computed by just one ARM
21860 instruction. */
21861
21862static unsigned int
21863validate_immediate_twopart (unsigned int val,
21864 unsigned int * highpart)
bfae80f2 21865{
c19d1205
ZW
21866 unsigned int a;
21867 unsigned int i;
bfae80f2 21868
c19d1205
ZW
21869 for (i = 0; i < 32; i += 2)
21870 if (((a = rotate_left (val, i)) & 0xff) != 0)
21871 {
21872 if (a & 0xff00)
21873 {
21874 if (a & ~ 0xffff)
21875 continue;
21876 * highpart = (a >> 8) | ((i + 24) << 7);
21877 }
21878 else if (a & 0xff0000)
21879 {
21880 if (a & 0xff000000)
21881 continue;
21882 * highpart = (a >> 16) | ((i + 16) << 7);
21883 }
21884 else
21885 {
9c2799c2 21886 gas_assert (a & 0xff000000);
c19d1205
ZW
21887 * highpart = (a >> 24) | ((i + 8) << 7);
21888 }
bfae80f2 21889
c19d1205
ZW
21890 return (a & 0xff) | (i << 7);
21891 }
bfae80f2 21892
c19d1205 21893 return FAIL;
bfae80f2
RE
21894}
21895
c19d1205
ZW
21896static int
21897validate_offset_imm (unsigned int val, int hwse)
21898{
21899 if ((hwse && val > 255) || val > 4095)
21900 return FAIL;
21901 return val;
21902}
bfae80f2 21903
55cf6793 21904/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21905 negative immediate constant by altering the instruction. A bit of
21906 a hack really.
21907 MOV <-> MVN
21908 AND <-> BIC
21909 ADC <-> SBC
21910 by inverting the second operand, and
21911 ADD <-> SUB
21912 CMP <-> CMN
21913 by negating the second operand. */
bfae80f2 21914
c19d1205
ZW
21915static int
21916negate_data_op (unsigned long * instruction,
21917 unsigned long value)
bfae80f2 21918{
c19d1205
ZW
21919 int op, new_inst;
21920 unsigned long negated, inverted;
bfae80f2 21921
c19d1205
ZW
21922 negated = encode_arm_immediate (-value);
21923 inverted = encode_arm_immediate (~value);
bfae80f2 21924
c19d1205
ZW
21925 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21926 switch (op)
bfae80f2 21927 {
c19d1205
ZW
21928 /* First negates. */
21929 case OPCODE_SUB: /* ADD <-> SUB */
21930 new_inst = OPCODE_ADD;
21931 value = negated;
21932 break;
bfae80f2 21933
c19d1205
ZW
21934 case OPCODE_ADD:
21935 new_inst = OPCODE_SUB;
21936 value = negated;
21937 break;
bfae80f2 21938
c19d1205
ZW
21939 case OPCODE_CMP: /* CMP <-> CMN */
21940 new_inst = OPCODE_CMN;
21941 value = negated;
21942 break;
bfae80f2 21943
c19d1205
ZW
21944 case OPCODE_CMN:
21945 new_inst = OPCODE_CMP;
21946 value = negated;
21947 break;
bfae80f2 21948
c19d1205
ZW
21949 /* Now Inverted ops. */
21950 case OPCODE_MOV: /* MOV <-> MVN */
21951 new_inst = OPCODE_MVN;
21952 value = inverted;
21953 break;
bfae80f2 21954
c19d1205
ZW
21955 case OPCODE_MVN:
21956 new_inst = OPCODE_MOV;
21957 value = inverted;
21958 break;
bfae80f2 21959
c19d1205
ZW
21960 case OPCODE_AND: /* AND <-> BIC */
21961 new_inst = OPCODE_BIC;
21962 value = inverted;
21963 break;
bfae80f2 21964
c19d1205
ZW
21965 case OPCODE_BIC:
21966 new_inst = OPCODE_AND;
21967 value = inverted;
21968 break;
bfae80f2 21969
c19d1205
ZW
21970 case OPCODE_ADC: /* ADC <-> SBC */
21971 new_inst = OPCODE_SBC;
21972 value = inverted;
21973 break;
bfae80f2 21974
c19d1205
ZW
21975 case OPCODE_SBC:
21976 new_inst = OPCODE_ADC;
21977 value = inverted;
21978 break;
bfae80f2 21979
c19d1205
ZW
21980 /* We cannot do anything. */
21981 default:
21982 return FAIL;
b99bd4ef
NC
21983 }
21984
c19d1205
ZW
21985 if (value == (unsigned) FAIL)
21986 return FAIL;
21987
21988 *instruction &= OPCODE_MASK;
21989 *instruction |= new_inst << DATA_OP_SHIFT;
21990 return value;
b99bd4ef
NC
21991}
21992
ef8d22e6
PB
21993/* Like negate_data_op, but for Thumb-2. */
21994
21995static unsigned int
16dd5e42 21996thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
21997{
21998 int op, new_inst;
21999 int rd;
16dd5e42 22000 unsigned int negated, inverted;
ef8d22e6
PB
22001
22002 negated = encode_thumb32_immediate (-value);
22003 inverted = encode_thumb32_immediate (~value);
22004
22005 rd = (*instruction >> 8) & 0xf;
22006 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22007 switch (op)
22008 {
22009 /* ADD <-> SUB. Includes CMP <-> CMN. */
22010 case T2_OPCODE_SUB:
22011 new_inst = T2_OPCODE_ADD;
22012 value = negated;
22013 break;
22014
22015 case T2_OPCODE_ADD:
22016 new_inst = T2_OPCODE_SUB;
22017 value = negated;
22018 break;
22019
22020 /* ORR <-> ORN. Includes MOV <-> MVN. */
22021 case T2_OPCODE_ORR:
22022 new_inst = T2_OPCODE_ORN;
22023 value = inverted;
22024 break;
22025
22026 case T2_OPCODE_ORN:
22027 new_inst = T2_OPCODE_ORR;
22028 value = inverted;
22029 break;
22030
22031 /* AND <-> BIC. TST has no inverted equivalent. */
22032 case T2_OPCODE_AND:
22033 new_inst = T2_OPCODE_BIC;
22034 if (rd == 15)
22035 value = FAIL;
22036 else
22037 value = inverted;
22038 break;
22039
22040 case T2_OPCODE_BIC:
22041 new_inst = T2_OPCODE_AND;
22042 value = inverted;
22043 break;
22044
22045 /* ADC <-> SBC */
22046 case T2_OPCODE_ADC:
22047 new_inst = T2_OPCODE_SBC;
22048 value = inverted;
22049 break;
22050
22051 case T2_OPCODE_SBC:
22052 new_inst = T2_OPCODE_ADC;
22053 value = inverted;
22054 break;
22055
22056 /* We cannot do anything. */
22057 default:
22058 return FAIL;
22059 }
22060
16dd5e42 22061 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22062 return FAIL;
22063
22064 *instruction &= T2_OPCODE_MASK;
22065 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22066 return value;
22067}
22068
8f06b2d8
PB
22069/* Read a 32-bit thumb instruction from buf. */
22070static unsigned long
22071get_thumb32_insn (char * buf)
22072{
22073 unsigned long insn;
22074 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22075 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22076
22077 return insn;
22078}
22079
a8bc6c78
PB
22080
22081/* We usually want to set the low bit on the address of thumb function
22082 symbols. In particular .word foo - . should have the low bit set.
22083 Generic code tries to fold the difference of two symbols to
22084 a constant. Prevent this and force a relocation when the first symbols
22085 is a thumb function. */
c921be7d
NC
22086
22087bfd_boolean
a8bc6c78
PB
22088arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22089{
22090 if (op == O_subtract
22091 && l->X_op == O_symbol
22092 && r->X_op == O_symbol
22093 && THUMB_IS_FUNC (l->X_add_symbol))
22094 {
22095 l->X_op = O_subtract;
22096 l->X_op_symbol = r->X_add_symbol;
22097 l->X_add_number -= r->X_add_number;
c921be7d 22098 return TRUE;
a8bc6c78 22099 }
c921be7d 22100
a8bc6c78 22101 /* Process as normal. */
c921be7d 22102 return FALSE;
a8bc6c78
PB
22103}
22104
4a42ebbc
RR
22105/* Encode Thumb2 unconditional branches and calls. The encoding
22106 for the 2 are identical for the immediate values. */
22107
22108static void
22109encode_thumb2_b_bl_offset (char * buf, offsetT value)
22110{
22111#define T2I1I2MASK ((1 << 13) | (1 << 11))
22112 offsetT newval;
22113 offsetT newval2;
22114 addressT S, I1, I2, lo, hi;
22115
22116 S = (value >> 24) & 0x01;
22117 I1 = (value >> 23) & 0x01;
22118 I2 = (value >> 22) & 0x01;
22119 hi = (value >> 12) & 0x3ff;
fa94de6b 22120 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22121 newval = md_chars_to_number (buf, THUMB_SIZE);
22122 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22123 newval |= (S << 10) | hi;
22124 newval2 &= ~T2I1I2MASK;
22125 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22126 md_number_to_chars (buf, newval, THUMB_SIZE);
22127 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22128}
22129
c19d1205 22130void
55cf6793 22131md_apply_fix (fixS * fixP,
c19d1205
ZW
22132 valueT * valP,
22133 segT seg)
22134{
22135 offsetT value = * valP;
22136 offsetT newval;
22137 unsigned int newimm;
22138 unsigned long temp;
22139 int sign;
22140 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22141
9c2799c2 22142 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22143
c19d1205 22144 /* Note whether this will delete the relocation. */
4962c51a 22145
c19d1205
ZW
22146 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22147 fixP->fx_done = 1;
b99bd4ef 22148
adbaf948 22149 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22150 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22151 for emit_reloc. */
22152 value &= 0xffffffff;
22153 value ^= 0x80000000;
5f4273c7 22154 value -= 0x80000000;
adbaf948
ZW
22155
22156 *valP = value;
c19d1205 22157 fixP->fx_addnumber = value;
b99bd4ef 22158
adbaf948
ZW
22159 /* Same treatment for fixP->fx_offset. */
22160 fixP->fx_offset &= 0xffffffff;
22161 fixP->fx_offset ^= 0x80000000;
22162 fixP->fx_offset -= 0x80000000;
22163
c19d1205 22164 switch (fixP->fx_r_type)
b99bd4ef 22165 {
c19d1205
ZW
22166 case BFD_RELOC_NONE:
22167 /* This will need to go in the object file. */
22168 fixP->fx_done = 0;
22169 break;
b99bd4ef 22170
c19d1205
ZW
22171 case BFD_RELOC_ARM_IMMEDIATE:
22172 /* We claim that this fixup has been processed here,
22173 even if in fact we generate an error because we do
22174 not have a reloc for it, so tc_gen_reloc will reject it. */
22175 fixP->fx_done = 1;
b99bd4ef 22176
77db8e2e 22177 if (fixP->fx_addsy)
b99bd4ef 22178 {
77db8e2e 22179 const char *msg = 0;
b99bd4ef 22180
77db8e2e
NC
22181 if (! S_IS_DEFINED (fixP->fx_addsy))
22182 msg = _("undefined symbol %s used as an immediate value");
22183 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22184 msg = _("symbol %s is in a different section");
22185 else if (S_IS_WEAK (fixP->fx_addsy))
22186 msg = _("symbol %s is weak and may be overridden later");
22187
22188 if (msg)
22189 {
22190 as_bad_where (fixP->fx_file, fixP->fx_line,
22191 msg, S_GET_NAME (fixP->fx_addsy));
22192 break;
22193 }
42e5fcbf
AS
22194 }
22195
c19d1205
ZW
22196 temp = md_chars_to_number (buf, INSN_SIZE);
22197
5e73442d
SL
22198 /* If the offset is negative, we should use encoding A2 for ADR. */
22199 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22200 newimm = negate_data_op (&temp, value);
22201 else
22202 {
22203 newimm = encode_arm_immediate (value);
22204
22205 /* If the instruction will fail, see if we can fix things up by
22206 changing the opcode. */
22207 if (newimm == (unsigned int) FAIL)
22208 newimm = negate_data_op (&temp, value);
22209 }
22210
22211 if (newimm == (unsigned int) FAIL)
b99bd4ef 22212 {
c19d1205
ZW
22213 as_bad_where (fixP->fx_file, fixP->fx_line,
22214 _("invalid constant (%lx) after fixup"),
22215 (unsigned long) value);
22216 break;
b99bd4ef 22217 }
b99bd4ef 22218
c19d1205
ZW
22219 newimm |= (temp & 0xfffff000);
22220 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22221 break;
b99bd4ef 22222
c19d1205
ZW
22223 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22224 {
22225 unsigned int highpart = 0;
22226 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22227
77db8e2e 22228 if (fixP->fx_addsy)
42e5fcbf 22229 {
77db8e2e 22230 const char *msg = 0;
42e5fcbf 22231
77db8e2e
NC
22232 if (! S_IS_DEFINED (fixP->fx_addsy))
22233 msg = _("undefined symbol %s used as an immediate value");
22234 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22235 msg = _("symbol %s is in a different section");
22236 else if (S_IS_WEAK (fixP->fx_addsy))
22237 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22238
77db8e2e
NC
22239 if (msg)
22240 {
22241 as_bad_where (fixP->fx_file, fixP->fx_line,
22242 msg, S_GET_NAME (fixP->fx_addsy));
22243 break;
22244 }
22245 }
fa94de6b 22246
c19d1205
ZW
22247 newimm = encode_arm_immediate (value);
22248 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22249
c19d1205
ZW
22250 /* If the instruction will fail, see if we can fix things up by
22251 changing the opcode. */
22252 if (newimm == (unsigned int) FAIL
22253 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22254 {
22255 /* No ? OK - try using two ADD instructions to generate
22256 the value. */
22257 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22258
c19d1205
ZW
22259 /* Yes - then make sure that the second instruction is
22260 also an add. */
22261 if (newimm != (unsigned int) FAIL)
22262 newinsn = temp;
22263 /* Still No ? Try using a negated value. */
22264 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22265 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22266 /* Otherwise - give up. */
22267 else
22268 {
22269 as_bad_where (fixP->fx_file, fixP->fx_line,
22270 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22271 (long) value);
22272 break;
22273 }
b99bd4ef 22274
c19d1205
ZW
22275 /* Replace the first operand in the 2nd instruction (which
22276 is the PC) with the destination register. We have
22277 already added in the PC in the first instruction and we
22278 do not want to do it again. */
22279 newinsn &= ~ 0xf0000;
22280 newinsn |= ((newinsn & 0x0f000) << 4);
22281 }
b99bd4ef 22282
c19d1205
ZW
22283 newimm |= (temp & 0xfffff000);
22284 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22285
c19d1205
ZW
22286 highpart |= (newinsn & 0xfffff000);
22287 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22288 }
22289 break;
b99bd4ef 22290
c19d1205 22291 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22292 if (!fixP->fx_done && seg->use_rela_p)
22293 value = 0;
22294
c19d1205 22295 case BFD_RELOC_ARM_LITERAL:
26d97720 22296 sign = value > 0;
b99bd4ef 22297
c19d1205
ZW
22298 if (value < 0)
22299 value = - value;
b99bd4ef 22300
c19d1205 22301 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22302 {
c19d1205
ZW
22303 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22304 as_bad_where (fixP->fx_file, fixP->fx_line,
22305 _("invalid literal constant: pool needs to be closer"));
22306 else
22307 as_bad_where (fixP->fx_file, fixP->fx_line,
22308 _("bad immediate value for offset (%ld)"),
22309 (long) value);
22310 break;
f03698e6
RE
22311 }
22312
c19d1205 22313 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22314 if (value == 0)
22315 newval &= 0xfffff000;
22316 else
22317 {
22318 newval &= 0xff7ff000;
22319 newval |= value | (sign ? INDEX_UP : 0);
22320 }
c19d1205
ZW
22321 md_number_to_chars (buf, newval, INSN_SIZE);
22322 break;
b99bd4ef 22323
c19d1205
ZW
22324 case BFD_RELOC_ARM_OFFSET_IMM8:
22325 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22326 sign = value > 0;
b99bd4ef 22327
c19d1205
ZW
22328 if (value < 0)
22329 value = - value;
b99bd4ef 22330
c19d1205 22331 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22332 {
c19d1205
ZW
22333 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22334 as_bad_where (fixP->fx_file, fixP->fx_line,
22335 _("invalid literal constant: pool needs to be closer"));
22336 else
427d0db6
RM
22337 as_bad_where (fixP->fx_file, fixP->fx_line,
22338 _("bad immediate value for 8-bit offset (%ld)"),
22339 (long) value);
c19d1205 22340 break;
b99bd4ef
NC
22341 }
22342
c19d1205 22343 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22344 if (value == 0)
22345 newval &= 0xfffff0f0;
22346 else
22347 {
22348 newval &= 0xff7ff0f0;
22349 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22350 }
c19d1205
ZW
22351 md_number_to_chars (buf, newval, INSN_SIZE);
22352 break;
b99bd4ef 22353
c19d1205
ZW
22354 case BFD_RELOC_ARM_T32_OFFSET_U8:
22355 if (value < 0 || value > 1020 || value % 4 != 0)
22356 as_bad_where (fixP->fx_file, fixP->fx_line,
22357 _("bad immediate value for offset (%ld)"), (long) value);
22358 value /= 4;
b99bd4ef 22359
c19d1205 22360 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22361 newval |= value;
22362 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22363 break;
b99bd4ef 22364
c19d1205
ZW
22365 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22366 /* This is a complicated relocation used for all varieties of Thumb32
22367 load/store instruction with immediate offset:
22368
22369 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22370 *4, optional writeback(W)
c19d1205
ZW
22371 (doubleword load/store)
22372
22373 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22374 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22375 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22376 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22377 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22378
22379 Uppercase letters indicate bits that are already encoded at
22380 this point. Lowercase letters are our problem. For the
22381 second block of instructions, the secondary opcode nybble
22382 (bits 8..11) is present, and bit 23 is zero, even if this is
22383 a PC-relative operation. */
22384 newval = md_chars_to_number (buf, THUMB_SIZE);
22385 newval <<= 16;
22386 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22387
c19d1205 22388 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22389 {
c19d1205
ZW
22390 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22391 if (value >= 0)
22392 newval |= (1 << 23);
22393 else
22394 value = -value;
22395 if (value % 4 != 0)
22396 {
22397 as_bad_where (fixP->fx_file, fixP->fx_line,
22398 _("offset not a multiple of 4"));
22399 break;
22400 }
22401 value /= 4;
216d22bc 22402 if (value > 0xff)
c19d1205
ZW
22403 {
22404 as_bad_where (fixP->fx_file, fixP->fx_line,
22405 _("offset out of range"));
22406 break;
22407 }
22408 newval &= ~0xff;
b99bd4ef 22409 }
c19d1205 22410 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22411 {
c19d1205
ZW
22412 /* PC-relative, 12-bit offset. */
22413 if (value >= 0)
22414 newval |= (1 << 23);
22415 else
22416 value = -value;
216d22bc 22417 if (value > 0xfff)
c19d1205
ZW
22418 {
22419 as_bad_where (fixP->fx_file, fixP->fx_line,
22420 _("offset out of range"));
22421 break;
22422 }
22423 newval &= ~0xfff;
b99bd4ef 22424 }
c19d1205 22425 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22426 {
c19d1205
ZW
22427 /* Writeback: 8-bit, +/- offset. */
22428 if (value >= 0)
22429 newval |= (1 << 9);
22430 else
22431 value = -value;
216d22bc 22432 if (value > 0xff)
c19d1205
ZW
22433 {
22434 as_bad_where (fixP->fx_file, fixP->fx_line,
22435 _("offset out of range"));
22436 break;
22437 }
22438 newval &= ~0xff;
b99bd4ef 22439 }
c19d1205 22440 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22441 {
c19d1205 22442 /* T-instruction: positive 8-bit offset. */
216d22bc 22443 if (value < 0 || value > 0xff)
b99bd4ef 22444 {
c19d1205
ZW
22445 as_bad_where (fixP->fx_file, fixP->fx_line,
22446 _("offset out of range"));
22447 break;
b99bd4ef 22448 }
c19d1205
ZW
22449 newval &= ~0xff;
22450 newval |= value;
b99bd4ef
NC
22451 }
22452 else
b99bd4ef 22453 {
c19d1205
ZW
22454 /* Positive 12-bit or negative 8-bit offset. */
22455 int limit;
22456 if (value >= 0)
b99bd4ef 22457 {
c19d1205
ZW
22458 newval |= (1 << 23);
22459 limit = 0xfff;
22460 }
22461 else
22462 {
22463 value = -value;
22464 limit = 0xff;
22465 }
22466 if (value > limit)
22467 {
22468 as_bad_where (fixP->fx_file, fixP->fx_line,
22469 _("offset out of range"));
22470 break;
b99bd4ef 22471 }
c19d1205 22472 newval &= ~limit;
b99bd4ef 22473 }
b99bd4ef 22474
c19d1205
ZW
22475 newval |= value;
22476 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22477 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22478 break;
404ff6b5 22479
c19d1205
ZW
22480 case BFD_RELOC_ARM_SHIFT_IMM:
22481 newval = md_chars_to_number (buf, INSN_SIZE);
22482 if (((unsigned long) value) > 32
22483 || (value == 32
22484 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22485 {
22486 as_bad_where (fixP->fx_file, fixP->fx_line,
22487 _("shift expression is too large"));
22488 break;
22489 }
404ff6b5 22490
c19d1205
ZW
22491 if (value == 0)
22492 /* Shifts of zero must be done as lsl. */
22493 newval &= ~0x60;
22494 else if (value == 32)
22495 value = 0;
22496 newval &= 0xfffff07f;
22497 newval |= (value & 0x1f) << 7;
22498 md_number_to_chars (buf, newval, INSN_SIZE);
22499 break;
404ff6b5 22500
c19d1205 22501 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22502 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22503 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22504 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22505 /* We claim that this fixup has been processed here,
22506 even if in fact we generate an error because we do
22507 not have a reloc for it, so tc_gen_reloc will reject it. */
22508 fixP->fx_done = 1;
404ff6b5 22509
c19d1205
ZW
22510 if (fixP->fx_addsy
22511 && ! S_IS_DEFINED (fixP->fx_addsy))
22512 {
22513 as_bad_where (fixP->fx_file, fixP->fx_line,
22514 _("undefined symbol %s used as an immediate value"),
22515 S_GET_NAME (fixP->fx_addsy));
22516 break;
22517 }
404ff6b5 22518
c19d1205
ZW
22519 newval = md_chars_to_number (buf, THUMB_SIZE);
22520 newval <<= 16;
22521 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22522
16805f35
PB
22523 newimm = FAIL;
22524 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22525 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22526 {
22527 newimm = encode_thumb32_immediate (value);
22528 if (newimm == (unsigned int) FAIL)
22529 newimm = thumb32_negate_data_op (&newval, value);
22530 }
16805f35
PB
22531 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22532 && newimm == (unsigned int) FAIL)
92e90b6e 22533 {
16805f35
PB
22534 /* Turn add/sum into addw/subw. */
22535 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22536 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22537 /* No flat 12-bit imm encoding for addsw/subsw. */
22538 if ((newval & 0x00100000) == 0)
e9f89963 22539 {
40f246e3
NC
22540 /* 12 bit immediate for addw/subw. */
22541 if (value < 0)
22542 {
22543 value = -value;
22544 newval ^= 0x00a00000;
22545 }
22546 if (value > 0xfff)
22547 newimm = (unsigned int) FAIL;
22548 else
22549 newimm = value;
e9f89963 22550 }
92e90b6e 22551 }
cc8a6dd0 22552
c19d1205 22553 if (newimm == (unsigned int)FAIL)
3631a3c8 22554 {
c19d1205
ZW
22555 as_bad_where (fixP->fx_file, fixP->fx_line,
22556 _("invalid constant (%lx) after fixup"),
22557 (unsigned long) value);
22558 break;
3631a3c8
NC
22559 }
22560
c19d1205
ZW
22561 newval |= (newimm & 0x800) << 15;
22562 newval |= (newimm & 0x700) << 4;
22563 newval |= (newimm & 0x0ff);
cc8a6dd0 22564
c19d1205
ZW
22565 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22566 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22567 break;
a737bd4d 22568
3eb17e6b 22569 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22570 if (((unsigned long) value) > 0xffff)
22571 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22572 _("invalid smc expression"));
2fc8bdac 22573 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22574 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22575 md_number_to_chars (buf, newval, INSN_SIZE);
22576 break;
a737bd4d 22577
90ec0d68
MGD
22578 case BFD_RELOC_ARM_HVC:
22579 if (((unsigned long) value) > 0xffff)
22580 as_bad_where (fixP->fx_file, fixP->fx_line,
22581 _("invalid hvc expression"));
22582 newval = md_chars_to_number (buf, INSN_SIZE);
22583 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22584 md_number_to_chars (buf, newval, INSN_SIZE);
22585 break;
22586
c19d1205 22587 case BFD_RELOC_ARM_SWI:
adbaf948 22588 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22589 {
22590 if (((unsigned long) value) > 0xff)
22591 as_bad_where (fixP->fx_file, fixP->fx_line,
22592 _("invalid swi expression"));
2fc8bdac 22593 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22594 newval |= value;
22595 md_number_to_chars (buf, newval, THUMB_SIZE);
22596 }
22597 else
22598 {
22599 if (((unsigned long) value) > 0x00ffffff)
22600 as_bad_where (fixP->fx_file, fixP->fx_line,
22601 _("invalid swi expression"));
2fc8bdac 22602 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22603 newval |= value;
22604 md_number_to_chars (buf, newval, INSN_SIZE);
22605 }
22606 break;
a737bd4d 22607
c19d1205
ZW
22608 case BFD_RELOC_ARM_MULTI:
22609 if (((unsigned long) value) > 0xffff)
22610 as_bad_where (fixP->fx_file, fixP->fx_line,
22611 _("invalid expression in load/store multiple"));
22612 newval = value | md_chars_to_number (buf, INSN_SIZE);
22613 md_number_to_chars (buf, newval, INSN_SIZE);
22614 break;
a737bd4d 22615
c19d1205 22616#ifdef OBJ_ELF
39b41c9c 22617 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22618
22619 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22620 && fixP->fx_addsy
34e77a92 22621 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22622 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22623 && THUMB_IS_FUNC (fixP->fx_addsy))
22624 /* Flip the bl to blx. This is a simple flip
22625 bit here because we generate PCREL_CALL for
22626 unconditional bls. */
22627 {
22628 newval = md_chars_to_number (buf, INSN_SIZE);
22629 newval = newval | 0x10000000;
22630 md_number_to_chars (buf, newval, INSN_SIZE);
22631 temp = 1;
22632 fixP->fx_done = 1;
22633 }
39b41c9c
PB
22634 else
22635 temp = 3;
22636 goto arm_branch_common;
22637
22638 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
22639 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22640 && fixP->fx_addsy
34e77a92 22641 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22642 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22643 && THUMB_IS_FUNC (fixP->fx_addsy))
22644 {
22645 /* This would map to a bl<cond>, b<cond>,
22646 b<always> to a Thumb function. We
22647 need to force a relocation for this particular
22648 case. */
22649 newval = md_chars_to_number (buf, INSN_SIZE);
22650 fixP->fx_done = 0;
22651 }
22652
2fc8bdac 22653 case BFD_RELOC_ARM_PLT32:
c19d1205 22654#endif
39b41c9c
PB
22655 case BFD_RELOC_ARM_PCREL_BRANCH:
22656 temp = 3;
22657 goto arm_branch_common;
a737bd4d 22658
39b41c9c 22659 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 22660
39b41c9c 22661 temp = 1;
267bf995
RR
22662 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22663 && fixP->fx_addsy
34e77a92 22664 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22665 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22666 && ARM_IS_FUNC (fixP->fx_addsy))
22667 {
22668 /* Flip the blx to a bl and warn. */
22669 const char *name = S_GET_NAME (fixP->fx_addsy);
22670 newval = 0xeb000000;
22671 as_warn_where (fixP->fx_file, fixP->fx_line,
22672 _("blx to '%s' an ARM ISA state function changed to bl"),
22673 name);
22674 md_number_to_chars (buf, newval, INSN_SIZE);
22675 temp = 3;
22676 fixP->fx_done = 1;
22677 }
22678
22679#ifdef OBJ_ELF
22680 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 22681 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
22682#endif
22683
39b41c9c 22684 arm_branch_common:
c19d1205 22685 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
22686 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22687 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22688 also be be clear. */
22689 if (value & temp)
c19d1205 22690 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
22691 _("misaligned branch destination"));
22692 if ((value & (offsetT)0xfe000000) != (offsetT)0
22693 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 22694 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22695
2fc8bdac 22696 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22697 {
2fc8bdac
ZW
22698 newval = md_chars_to_number (buf, INSN_SIZE);
22699 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
22700 /* Set the H bit on BLX instructions. */
22701 if (temp == 1)
22702 {
22703 if (value & 2)
22704 newval |= 0x01000000;
22705 else
22706 newval &= ~0x01000000;
22707 }
2fc8bdac 22708 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 22709 }
c19d1205 22710 break;
a737bd4d 22711
25fe350b
MS
22712 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22713 /* CBZ can only branch forward. */
a737bd4d 22714
738755b0 22715 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
22716 (which, strictly speaking, are prohibited) will be turned into
22717 no-ops.
738755b0
MS
22718
22719 FIXME: It may be better to remove the instruction completely and
22720 perform relaxation. */
22721 if (value == -2)
2fc8bdac
ZW
22722 {
22723 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 22724 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
22725 md_number_to_chars (buf, newval, THUMB_SIZE);
22726 }
738755b0
MS
22727 else
22728 {
22729 if (value & ~0x7e)
08f10d51 22730 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 22731
477330fc 22732 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
22733 {
22734 newval = md_chars_to_number (buf, THUMB_SIZE);
22735 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22736 md_number_to_chars (buf, newval, THUMB_SIZE);
22737 }
22738 }
c19d1205 22739 break;
a737bd4d 22740
c19d1205 22741 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 22742 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 22743 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22744
2fc8bdac
ZW
22745 if (fixP->fx_done || !seg->use_rela_p)
22746 {
22747 newval = md_chars_to_number (buf, THUMB_SIZE);
22748 newval |= (value & 0x1ff) >> 1;
22749 md_number_to_chars (buf, newval, THUMB_SIZE);
22750 }
c19d1205 22751 break;
a737bd4d 22752
c19d1205 22753 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 22754 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 22755 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22756
2fc8bdac
ZW
22757 if (fixP->fx_done || !seg->use_rela_p)
22758 {
22759 newval = md_chars_to_number (buf, THUMB_SIZE);
22760 newval |= (value & 0xfff) >> 1;
22761 md_number_to_chars (buf, newval, THUMB_SIZE);
22762 }
c19d1205 22763 break;
a737bd4d 22764
c19d1205 22765 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
22766 if (fixP->fx_addsy
22767 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22768 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22769 && ARM_IS_FUNC (fixP->fx_addsy)
22770 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22771 {
22772 /* Force a relocation for a branch 20 bits wide. */
22773 fixP->fx_done = 0;
22774 }
08f10d51 22775 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
22776 as_bad_where (fixP->fx_file, fixP->fx_line,
22777 _("conditional branch out of range"));
404ff6b5 22778
2fc8bdac
ZW
22779 if (fixP->fx_done || !seg->use_rela_p)
22780 {
22781 offsetT newval2;
22782 addressT S, J1, J2, lo, hi;
404ff6b5 22783
2fc8bdac
ZW
22784 S = (value & 0x00100000) >> 20;
22785 J2 = (value & 0x00080000) >> 19;
22786 J1 = (value & 0x00040000) >> 18;
22787 hi = (value & 0x0003f000) >> 12;
22788 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22789
2fc8bdac
ZW
22790 newval = md_chars_to_number (buf, THUMB_SIZE);
22791 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22792 newval |= (S << 10) | hi;
22793 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22794 md_number_to_chars (buf, newval, THUMB_SIZE);
22795 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22796 }
c19d1205 22797 break;
6c43fab6 22798
c19d1205 22799 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22800 /* If there is a blx from a thumb state function to
22801 another thumb function flip this to a bl and warn
22802 about it. */
22803
22804 if (fixP->fx_addsy
34e77a92 22805 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22806 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22807 && THUMB_IS_FUNC (fixP->fx_addsy))
22808 {
22809 const char *name = S_GET_NAME (fixP->fx_addsy);
22810 as_warn_where (fixP->fx_file, fixP->fx_line,
22811 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22812 name);
22813 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22814 newval = newval | 0x1000;
22815 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22816 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22817 fixP->fx_done = 1;
22818 }
22819
22820
22821 goto thumb_bl_common;
22822
c19d1205 22823 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22824 /* A bl from Thumb state ISA to an internal ARM state function
22825 is converted to a blx. */
22826 if (fixP->fx_addsy
22827 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22828 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22829 && ARM_IS_FUNC (fixP->fx_addsy)
22830 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22831 {
22832 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22833 newval = newval & ~0x1000;
22834 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22835 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22836 fixP->fx_done = 1;
22837 }
22838
22839 thumb_bl_common:
22840
2fc8bdac
ZW
22841 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22842 /* For a BLX instruction, make sure that the relocation is rounded up
22843 to a word boundary. This follows the semantics of the instruction
22844 which specifies that bit 1 of the target address will come from bit
22845 1 of the base address. */
d406f3e4
JB
22846 value = (value + 3) & ~ 3;
22847
22848#ifdef OBJ_ELF
22849 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22850 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22851 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22852#endif
404ff6b5 22853
2b2f5df9
NC
22854 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22855 {
22856 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22857 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22858 else if ((value & ~0x1ffffff)
22859 && ((value & ~0x1ffffff) != ~0x1ffffff))
22860 as_bad_where (fixP->fx_file, fixP->fx_line,
22861 _("Thumb2 branch out of range"));
22862 }
4a42ebbc
RR
22863
22864 if (fixP->fx_done || !seg->use_rela_p)
22865 encode_thumb2_b_bl_offset (buf, value);
22866
c19d1205 22867 break;
404ff6b5 22868
c19d1205 22869 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22870 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22871 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22872
2fc8bdac 22873 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22874 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22875
2fc8bdac 22876 break;
a737bd4d 22877
2fc8bdac
ZW
22878 case BFD_RELOC_8:
22879 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 22880 *buf = value;
c19d1205 22881 break;
a737bd4d 22882
c19d1205 22883 case BFD_RELOC_16:
2fc8bdac 22884 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22885 md_number_to_chars (buf, value, 2);
c19d1205 22886 break;
a737bd4d 22887
c19d1205 22888#ifdef OBJ_ELF
0855e32b
NS
22889 case BFD_RELOC_ARM_TLS_CALL:
22890 case BFD_RELOC_ARM_THM_TLS_CALL:
22891 case BFD_RELOC_ARM_TLS_DESCSEQ:
22892 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 22893 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22894 case BFD_RELOC_ARM_TLS_GD32:
22895 case BFD_RELOC_ARM_TLS_LE32:
22896 case BFD_RELOC_ARM_TLS_IE32:
22897 case BFD_RELOC_ARM_TLS_LDM32:
22898 case BFD_RELOC_ARM_TLS_LDO32:
22899 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 22900 break;
6c43fab6 22901
c19d1205
ZW
22902 case BFD_RELOC_ARM_GOT32:
22903 case BFD_RELOC_ARM_GOTOFF:
c19d1205 22904 break;
b43420e6
NC
22905
22906 case BFD_RELOC_ARM_GOT_PREL:
22907 if (fixP->fx_done || !seg->use_rela_p)
477330fc 22908 md_number_to_chars (buf, value, 4);
b43420e6
NC
22909 break;
22910
9a6f4e97
NS
22911 case BFD_RELOC_ARM_TARGET2:
22912 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
22913 addend here for REL targets, because it won't be written out
22914 during reloc processing later. */
9a6f4e97
NS
22915 if (fixP->fx_done || !seg->use_rela_p)
22916 md_number_to_chars (buf, fixP->fx_offset, 4);
22917 break;
c19d1205 22918#endif
6c43fab6 22919
c19d1205
ZW
22920 case BFD_RELOC_RVA:
22921 case BFD_RELOC_32:
22922 case BFD_RELOC_ARM_TARGET1:
22923 case BFD_RELOC_ARM_ROSEGREL32:
22924 case BFD_RELOC_ARM_SBREL32:
22925 case BFD_RELOC_32_PCREL:
f0927246
NC
22926#ifdef TE_PE
22927 case BFD_RELOC_32_SECREL:
22928#endif
2fc8bdac 22929 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22930#ifdef TE_WINCE
22931 /* For WinCE we only do this for pcrel fixups. */
22932 if (fixP->fx_done || fixP->fx_pcrel)
22933#endif
22934 md_number_to_chars (buf, value, 4);
c19d1205 22935 break;
6c43fab6 22936
c19d1205
ZW
22937#ifdef OBJ_ELF
22938 case BFD_RELOC_ARM_PREL31:
2fc8bdac 22939 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
22940 {
22941 newval = md_chars_to_number (buf, 4) & 0x80000000;
22942 if ((value ^ (value >> 1)) & 0x40000000)
22943 {
22944 as_bad_where (fixP->fx_file, fixP->fx_line,
22945 _("rel31 relocation overflow"));
22946 }
22947 newval |= value & 0x7fffffff;
22948 md_number_to_chars (buf, newval, 4);
22949 }
22950 break;
c19d1205 22951#endif
a737bd4d 22952
c19d1205 22953 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 22954 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
22955 if (value < -1023 || value > 1023 || (value & 3))
22956 as_bad_where (fixP->fx_file, fixP->fx_line,
22957 _("co-processor offset out of range"));
22958 cp_off_common:
26d97720 22959 sign = value > 0;
c19d1205
ZW
22960 if (value < 0)
22961 value = -value;
8f06b2d8
PB
22962 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22963 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22964 newval = md_chars_to_number (buf, INSN_SIZE);
22965 else
22966 newval = get_thumb32_insn (buf);
26d97720
NS
22967 if (value == 0)
22968 newval &= 0xffffff00;
22969 else
22970 {
22971 newval &= 0xff7fff00;
22972 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22973 }
8f06b2d8
PB
22974 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22975 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22976 md_number_to_chars (buf, newval, INSN_SIZE);
22977 else
22978 put_thumb32_insn (buf, newval);
c19d1205 22979 break;
a737bd4d 22980
c19d1205 22981 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 22982 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
22983 if (value < -255 || value > 255)
22984 as_bad_where (fixP->fx_file, fixP->fx_line,
22985 _("co-processor offset out of range"));
df7849c5 22986 value *= 4;
c19d1205 22987 goto cp_off_common;
6c43fab6 22988
c19d1205
ZW
22989 case BFD_RELOC_ARM_THUMB_OFFSET:
22990 newval = md_chars_to_number (buf, THUMB_SIZE);
22991 /* Exactly what ranges, and where the offset is inserted depends
22992 on the type of instruction, we can establish this from the
22993 top 4 bits. */
22994 switch (newval >> 12)
22995 {
22996 case 4: /* PC load. */
22997 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22998 forced to zero for these loads; md_pcrel_from has already
22999 compensated for this. */
23000 if (value & 3)
23001 as_bad_where (fixP->fx_file, fixP->fx_line,
23002 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23003 (((unsigned long) fixP->fx_frag->fr_address
23004 + (unsigned long) fixP->fx_where) & ~3)
23005 + (unsigned long) value);
a737bd4d 23006
c19d1205
ZW
23007 if (value & ~0x3fc)
23008 as_bad_where (fixP->fx_file, fixP->fx_line,
23009 _("invalid offset, value too big (0x%08lX)"),
23010 (long) value);
a737bd4d 23011
c19d1205
ZW
23012 newval |= value >> 2;
23013 break;
a737bd4d 23014
c19d1205
ZW
23015 case 9: /* SP load/store. */
23016 if (value & ~0x3fc)
23017 as_bad_where (fixP->fx_file, fixP->fx_line,
23018 _("invalid offset, value too big (0x%08lX)"),
23019 (long) value);
23020 newval |= value >> 2;
23021 break;
6c43fab6 23022
c19d1205
ZW
23023 case 6: /* Word load/store. */
23024 if (value & ~0x7c)
23025 as_bad_where (fixP->fx_file, fixP->fx_line,
23026 _("invalid offset, value too big (0x%08lX)"),
23027 (long) value);
23028 newval |= value << 4; /* 6 - 2. */
23029 break;
a737bd4d 23030
c19d1205
ZW
23031 case 7: /* Byte load/store. */
23032 if (value & ~0x1f)
23033 as_bad_where (fixP->fx_file, fixP->fx_line,
23034 _("invalid offset, value too big (0x%08lX)"),
23035 (long) value);
23036 newval |= value << 6;
23037 break;
a737bd4d 23038
c19d1205
ZW
23039 case 8: /* Halfword load/store. */
23040 if (value & ~0x3e)
23041 as_bad_where (fixP->fx_file, fixP->fx_line,
23042 _("invalid offset, value too big (0x%08lX)"),
23043 (long) value);
23044 newval |= value << 5; /* 6 - 1. */
23045 break;
a737bd4d 23046
c19d1205
ZW
23047 default:
23048 as_bad_where (fixP->fx_file, fixP->fx_line,
23049 "Unable to process relocation for thumb opcode: %lx",
23050 (unsigned long) newval);
23051 break;
23052 }
23053 md_number_to_chars (buf, newval, THUMB_SIZE);
23054 break;
a737bd4d 23055
c19d1205
ZW
23056 case BFD_RELOC_ARM_THUMB_ADD:
23057 /* This is a complicated relocation, since we use it for all of
23058 the following immediate relocations:
a737bd4d 23059
c19d1205
ZW
23060 3bit ADD/SUB
23061 8bit ADD/SUB
23062 9bit ADD/SUB SP word-aligned
23063 10bit ADD PC/SP word-aligned
a737bd4d 23064
c19d1205
ZW
23065 The type of instruction being processed is encoded in the
23066 instruction field:
a737bd4d 23067
c19d1205
ZW
23068 0x8000 SUB
23069 0x00F0 Rd
23070 0x000F Rs
23071 */
23072 newval = md_chars_to_number (buf, THUMB_SIZE);
23073 {
23074 int rd = (newval >> 4) & 0xf;
23075 int rs = newval & 0xf;
23076 int subtract = !!(newval & 0x8000);
a737bd4d 23077
c19d1205
ZW
23078 /* Check for HI regs, only very restricted cases allowed:
23079 Adjusting SP, and using PC or SP to get an address. */
23080 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23081 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23082 as_bad_where (fixP->fx_file, fixP->fx_line,
23083 _("invalid Hi register with immediate"));
a737bd4d 23084
c19d1205
ZW
23085 /* If value is negative, choose the opposite instruction. */
23086 if (value < 0)
23087 {
23088 value = -value;
23089 subtract = !subtract;
23090 if (value < 0)
23091 as_bad_where (fixP->fx_file, fixP->fx_line,
23092 _("immediate value out of range"));
23093 }
a737bd4d 23094
c19d1205
ZW
23095 if (rd == REG_SP)
23096 {
75c11999 23097 if (value & ~0x1fc)
c19d1205
ZW
23098 as_bad_where (fixP->fx_file, fixP->fx_line,
23099 _("invalid immediate for stack address calculation"));
23100 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23101 newval |= value >> 2;
23102 }
23103 else if (rs == REG_PC || rs == REG_SP)
23104 {
c12d2c9d
NC
23105 /* PR gas/18541. If the addition is for a defined symbol
23106 within range of an ADR instruction then accept it. */
23107 if (subtract
23108 && value == 4
23109 && fixP->fx_addsy != NULL)
23110 {
23111 subtract = 0;
23112
23113 if (! S_IS_DEFINED (fixP->fx_addsy)
23114 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23115 || S_IS_WEAK (fixP->fx_addsy))
23116 {
23117 as_bad_where (fixP->fx_file, fixP->fx_line,
23118 _("address calculation needs a strongly defined nearby symbol"));
23119 }
23120 else
23121 {
23122 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23123
23124 /* Round up to the next 4-byte boundary. */
23125 if (v & 3)
23126 v = (v + 3) & ~ 3;
23127 else
23128 v += 4;
23129 v = S_GET_VALUE (fixP->fx_addsy) - v;
23130
23131 if (v & ~0x3fc)
23132 {
23133 as_bad_where (fixP->fx_file, fixP->fx_line,
23134 _("symbol too far away"));
23135 }
23136 else
23137 {
23138 fixP->fx_done = 1;
23139 value = v;
23140 }
23141 }
23142 }
23143
c19d1205
ZW
23144 if (subtract || value & ~0x3fc)
23145 as_bad_where (fixP->fx_file, fixP->fx_line,
23146 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23147 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23148 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23149 newval |= rd << 8;
23150 newval |= value >> 2;
23151 }
23152 else if (rs == rd)
23153 {
23154 if (value & ~0xff)
23155 as_bad_where (fixP->fx_file, fixP->fx_line,
23156 _("immediate value out of range"));
23157 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23158 newval |= (rd << 8) | value;
23159 }
23160 else
23161 {
23162 if (value & ~0x7)
23163 as_bad_where (fixP->fx_file, fixP->fx_line,
23164 _("immediate value out of range"));
23165 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23166 newval |= rd | (rs << 3) | (value << 6);
23167 }
23168 }
23169 md_number_to_chars (buf, newval, THUMB_SIZE);
23170 break;
a737bd4d 23171
c19d1205
ZW
23172 case BFD_RELOC_ARM_THUMB_IMM:
23173 newval = md_chars_to_number (buf, THUMB_SIZE);
23174 if (value < 0 || value > 255)
23175 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23176 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23177 (long) value);
23178 newval |= value;
23179 md_number_to_chars (buf, newval, THUMB_SIZE);
23180 break;
a737bd4d 23181
c19d1205
ZW
23182 case BFD_RELOC_ARM_THUMB_SHIFT:
23183 /* 5bit shift value (0..32). LSL cannot take 32. */
23184 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23185 temp = newval & 0xf800;
23186 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23187 as_bad_where (fixP->fx_file, fixP->fx_line,
23188 _("invalid shift value: %ld"), (long) value);
23189 /* Shifts of zero must be encoded as LSL. */
23190 if (value == 0)
23191 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23192 /* Shifts of 32 are encoded as zero. */
23193 else if (value == 32)
23194 value = 0;
23195 newval |= value << 6;
23196 md_number_to_chars (buf, newval, THUMB_SIZE);
23197 break;
a737bd4d 23198
c19d1205
ZW
23199 case BFD_RELOC_VTABLE_INHERIT:
23200 case BFD_RELOC_VTABLE_ENTRY:
23201 fixP->fx_done = 0;
23202 return;
6c43fab6 23203
b6895b4f
PB
23204 case BFD_RELOC_ARM_MOVW:
23205 case BFD_RELOC_ARM_MOVT:
23206 case BFD_RELOC_ARM_THUMB_MOVW:
23207 case BFD_RELOC_ARM_THUMB_MOVT:
23208 if (fixP->fx_done || !seg->use_rela_p)
23209 {
23210 /* REL format relocations are limited to a 16-bit addend. */
23211 if (!fixP->fx_done)
23212 {
39623e12 23213 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23214 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23215 _("offset out of range"));
b6895b4f
PB
23216 }
23217 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23218 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23219 {
23220 value >>= 16;
23221 }
23222
23223 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23224 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23225 {
23226 newval = get_thumb32_insn (buf);
23227 newval &= 0xfbf08f00;
23228 newval |= (value & 0xf000) << 4;
23229 newval |= (value & 0x0800) << 15;
23230 newval |= (value & 0x0700) << 4;
23231 newval |= (value & 0x00ff);
23232 put_thumb32_insn (buf, newval);
23233 }
23234 else
23235 {
23236 newval = md_chars_to_number (buf, 4);
23237 newval &= 0xfff0f000;
23238 newval |= value & 0x0fff;
23239 newval |= (value & 0xf000) << 4;
23240 md_number_to_chars (buf, newval, 4);
23241 }
23242 }
23243 return;
23244
4962c51a
MS
23245 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23246 case BFD_RELOC_ARM_ALU_PC_G0:
23247 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23248 case BFD_RELOC_ARM_ALU_PC_G1:
23249 case BFD_RELOC_ARM_ALU_PC_G2:
23250 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23251 case BFD_RELOC_ARM_ALU_SB_G0:
23252 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23253 case BFD_RELOC_ARM_ALU_SB_G1:
23254 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23255 gas_assert (!fixP->fx_done);
4962c51a
MS
23256 if (!seg->use_rela_p)
23257 {
477330fc
RM
23258 bfd_vma insn;
23259 bfd_vma encoded_addend;
23260 bfd_vma addend_abs = abs (value);
23261
23262 /* Check that the absolute value of the addend can be
23263 expressed as an 8-bit constant plus a rotation. */
23264 encoded_addend = encode_arm_immediate (addend_abs);
23265 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23266 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23267 _("the offset 0x%08lX is not representable"),
23268 (unsigned long) addend_abs);
23269
23270 /* Extract the instruction. */
23271 insn = md_chars_to_number (buf, INSN_SIZE);
23272
23273 /* If the addend is positive, use an ADD instruction.
23274 Otherwise use a SUB. Take care not to destroy the S bit. */
23275 insn &= 0xff1fffff;
23276 if (value < 0)
23277 insn |= 1 << 22;
23278 else
23279 insn |= 1 << 23;
23280
23281 /* Place the encoded addend into the first 12 bits of the
23282 instruction. */
23283 insn &= 0xfffff000;
23284 insn |= encoded_addend;
23285
23286 /* Update the instruction. */
23287 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23288 }
23289 break;
23290
23291 case BFD_RELOC_ARM_LDR_PC_G0:
23292 case BFD_RELOC_ARM_LDR_PC_G1:
23293 case BFD_RELOC_ARM_LDR_PC_G2:
23294 case BFD_RELOC_ARM_LDR_SB_G0:
23295 case BFD_RELOC_ARM_LDR_SB_G1:
23296 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23297 gas_assert (!fixP->fx_done);
4962c51a 23298 if (!seg->use_rela_p)
477330fc
RM
23299 {
23300 bfd_vma insn;
23301 bfd_vma addend_abs = abs (value);
4962c51a 23302
477330fc
RM
23303 /* Check that the absolute value of the addend can be
23304 encoded in 12 bits. */
23305 if (addend_abs >= 0x1000)
4962c51a 23306 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23307 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23308 (unsigned long) addend_abs);
23309
23310 /* Extract the instruction. */
23311 insn = md_chars_to_number (buf, INSN_SIZE);
23312
23313 /* If the addend is negative, clear bit 23 of the instruction.
23314 Otherwise set it. */
23315 if (value < 0)
23316 insn &= ~(1 << 23);
23317 else
23318 insn |= 1 << 23;
23319
23320 /* Place the absolute value of the addend into the first 12 bits
23321 of the instruction. */
23322 insn &= 0xfffff000;
23323 insn |= addend_abs;
23324
23325 /* Update the instruction. */
23326 md_number_to_chars (buf, insn, INSN_SIZE);
23327 }
4962c51a
MS
23328 break;
23329
23330 case BFD_RELOC_ARM_LDRS_PC_G0:
23331 case BFD_RELOC_ARM_LDRS_PC_G1:
23332 case BFD_RELOC_ARM_LDRS_PC_G2:
23333 case BFD_RELOC_ARM_LDRS_SB_G0:
23334 case BFD_RELOC_ARM_LDRS_SB_G1:
23335 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23336 gas_assert (!fixP->fx_done);
4962c51a 23337 if (!seg->use_rela_p)
477330fc
RM
23338 {
23339 bfd_vma insn;
23340 bfd_vma addend_abs = abs (value);
4962c51a 23341
477330fc
RM
23342 /* Check that the absolute value of the addend can be
23343 encoded in 8 bits. */
23344 if (addend_abs >= 0x100)
4962c51a 23345 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23346 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23347 (unsigned long) addend_abs);
23348
23349 /* Extract the instruction. */
23350 insn = md_chars_to_number (buf, INSN_SIZE);
23351
23352 /* If the addend is negative, clear bit 23 of the instruction.
23353 Otherwise set it. */
23354 if (value < 0)
23355 insn &= ~(1 << 23);
23356 else
23357 insn |= 1 << 23;
23358
23359 /* Place the first four bits of the absolute value of the addend
23360 into the first 4 bits of the instruction, and the remaining
23361 four into bits 8 .. 11. */
23362 insn &= 0xfffff0f0;
23363 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23364
23365 /* Update the instruction. */
23366 md_number_to_chars (buf, insn, INSN_SIZE);
23367 }
4962c51a
MS
23368 break;
23369
23370 case BFD_RELOC_ARM_LDC_PC_G0:
23371 case BFD_RELOC_ARM_LDC_PC_G1:
23372 case BFD_RELOC_ARM_LDC_PC_G2:
23373 case BFD_RELOC_ARM_LDC_SB_G0:
23374 case BFD_RELOC_ARM_LDC_SB_G1:
23375 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23376 gas_assert (!fixP->fx_done);
4962c51a 23377 if (!seg->use_rela_p)
477330fc
RM
23378 {
23379 bfd_vma insn;
23380 bfd_vma addend_abs = abs (value);
4962c51a 23381
477330fc
RM
23382 /* Check that the absolute value of the addend is a multiple of
23383 four and, when divided by four, fits in 8 bits. */
23384 if (addend_abs & 0x3)
4962c51a 23385 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23386 _("bad offset 0x%08lX (must be word-aligned)"),
23387 (unsigned long) addend_abs);
4962c51a 23388
477330fc 23389 if ((addend_abs >> 2) > 0xff)
4962c51a 23390 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23391 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23392 (unsigned long) addend_abs);
23393
23394 /* Extract the instruction. */
23395 insn = md_chars_to_number (buf, INSN_SIZE);
23396
23397 /* If the addend is negative, clear bit 23 of the instruction.
23398 Otherwise set it. */
23399 if (value < 0)
23400 insn &= ~(1 << 23);
23401 else
23402 insn |= 1 << 23;
23403
23404 /* Place the addend (divided by four) into the first eight
23405 bits of the instruction. */
23406 insn &= 0xfffffff0;
23407 insn |= addend_abs >> 2;
23408
23409 /* Update the instruction. */
23410 md_number_to_chars (buf, insn, INSN_SIZE);
23411 }
4962c51a
MS
23412 break;
23413
845b51d6
PB
23414 case BFD_RELOC_ARM_V4BX:
23415 /* This will need to go in the object file. */
23416 fixP->fx_done = 0;
23417 break;
23418
c19d1205
ZW
23419 case BFD_RELOC_UNUSED:
23420 default:
23421 as_bad_where (fixP->fx_file, fixP->fx_line,
23422 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23423 }
6c43fab6
RE
23424}
23425
c19d1205
ZW
23426/* Translate internal representation of relocation info to BFD target
23427 format. */
a737bd4d 23428
c19d1205 23429arelent *
00a97672 23430tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23431{
c19d1205
ZW
23432 arelent * reloc;
23433 bfd_reloc_code_real_type code;
a737bd4d 23434
21d799b5 23435 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23436
21d799b5 23437 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23438 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23439 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23440
2fc8bdac 23441 if (fixp->fx_pcrel)
00a97672
RS
23442 {
23443 if (section->use_rela_p)
23444 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23445 else
23446 fixp->fx_offset = reloc->address;
23447 }
c19d1205 23448 reloc->addend = fixp->fx_offset;
a737bd4d 23449
c19d1205 23450 switch (fixp->fx_r_type)
a737bd4d 23451 {
c19d1205
ZW
23452 case BFD_RELOC_8:
23453 if (fixp->fx_pcrel)
23454 {
23455 code = BFD_RELOC_8_PCREL;
23456 break;
23457 }
a737bd4d 23458
c19d1205
ZW
23459 case BFD_RELOC_16:
23460 if (fixp->fx_pcrel)
23461 {
23462 code = BFD_RELOC_16_PCREL;
23463 break;
23464 }
6c43fab6 23465
c19d1205
ZW
23466 case BFD_RELOC_32:
23467 if (fixp->fx_pcrel)
23468 {
23469 code = BFD_RELOC_32_PCREL;
23470 break;
23471 }
a737bd4d 23472
b6895b4f
PB
23473 case BFD_RELOC_ARM_MOVW:
23474 if (fixp->fx_pcrel)
23475 {
23476 code = BFD_RELOC_ARM_MOVW_PCREL;
23477 break;
23478 }
23479
23480 case BFD_RELOC_ARM_MOVT:
23481 if (fixp->fx_pcrel)
23482 {
23483 code = BFD_RELOC_ARM_MOVT_PCREL;
23484 break;
23485 }
23486
23487 case BFD_RELOC_ARM_THUMB_MOVW:
23488 if (fixp->fx_pcrel)
23489 {
23490 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23491 break;
23492 }
23493
23494 case BFD_RELOC_ARM_THUMB_MOVT:
23495 if (fixp->fx_pcrel)
23496 {
23497 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23498 break;
23499 }
23500
c19d1205
ZW
23501 case BFD_RELOC_NONE:
23502 case BFD_RELOC_ARM_PCREL_BRANCH:
23503 case BFD_RELOC_ARM_PCREL_BLX:
23504 case BFD_RELOC_RVA:
23505 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23506 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23507 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23508 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23509 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23510 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
23511 case BFD_RELOC_VTABLE_ENTRY:
23512 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
23513#ifdef TE_PE
23514 case BFD_RELOC_32_SECREL:
23515#endif
c19d1205
ZW
23516 code = fixp->fx_r_type;
23517 break;
a737bd4d 23518
00adf2d4
JB
23519 case BFD_RELOC_THUMB_PCREL_BLX:
23520#ifdef OBJ_ELF
23521 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23522 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23523 else
23524#endif
23525 code = BFD_RELOC_THUMB_PCREL_BLX;
23526 break;
23527
c19d1205
ZW
23528 case BFD_RELOC_ARM_LITERAL:
23529 case BFD_RELOC_ARM_HWLITERAL:
23530 /* If this is called then the a literal has
23531 been referenced across a section boundary. */
23532 as_bad_where (fixp->fx_file, fixp->fx_line,
23533 _("literal referenced across section boundary"));
23534 return NULL;
a737bd4d 23535
c19d1205 23536#ifdef OBJ_ELF
0855e32b
NS
23537 case BFD_RELOC_ARM_TLS_CALL:
23538 case BFD_RELOC_ARM_THM_TLS_CALL:
23539 case BFD_RELOC_ARM_TLS_DESCSEQ:
23540 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
23541 case BFD_RELOC_ARM_GOT32:
23542 case BFD_RELOC_ARM_GOTOFF:
b43420e6 23543 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
23544 case BFD_RELOC_ARM_PLT32:
23545 case BFD_RELOC_ARM_TARGET1:
23546 case BFD_RELOC_ARM_ROSEGREL32:
23547 case BFD_RELOC_ARM_SBREL32:
23548 case BFD_RELOC_ARM_PREL31:
23549 case BFD_RELOC_ARM_TARGET2:
c19d1205 23550 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
23551 case BFD_RELOC_ARM_PCREL_CALL:
23552 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
23553 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23554 case BFD_RELOC_ARM_ALU_PC_G0:
23555 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23556 case BFD_RELOC_ARM_ALU_PC_G1:
23557 case BFD_RELOC_ARM_ALU_PC_G2:
23558 case BFD_RELOC_ARM_LDR_PC_G0:
23559 case BFD_RELOC_ARM_LDR_PC_G1:
23560 case BFD_RELOC_ARM_LDR_PC_G2:
23561 case BFD_RELOC_ARM_LDRS_PC_G0:
23562 case BFD_RELOC_ARM_LDRS_PC_G1:
23563 case BFD_RELOC_ARM_LDRS_PC_G2:
23564 case BFD_RELOC_ARM_LDC_PC_G0:
23565 case BFD_RELOC_ARM_LDC_PC_G1:
23566 case BFD_RELOC_ARM_LDC_PC_G2:
23567 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23568 case BFD_RELOC_ARM_ALU_SB_G0:
23569 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23570 case BFD_RELOC_ARM_ALU_SB_G1:
23571 case BFD_RELOC_ARM_ALU_SB_G2:
23572 case BFD_RELOC_ARM_LDR_SB_G0:
23573 case BFD_RELOC_ARM_LDR_SB_G1:
23574 case BFD_RELOC_ARM_LDR_SB_G2:
23575 case BFD_RELOC_ARM_LDRS_SB_G0:
23576 case BFD_RELOC_ARM_LDRS_SB_G1:
23577 case BFD_RELOC_ARM_LDRS_SB_G2:
23578 case BFD_RELOC_ARM_LDC_SB_G0:
23579 case BFD_RELOC_ARM_LDC_SB_G1:
23580 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 23581 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
23582 code = fixp->fx_r_type;
23583 break;
a737bd4d 23584
0855e32b 23585 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 23586 case BFD_RELOC_ARM_TLS_GD32:
75c11999 23587 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
23588 case BFD_RELOC_ARM_TLS_IE32:
23589 case BFD_RELOC_ARM_TLS_LDM32:
23590 /* BFD will include the symbol's address in the addend.
23591 But we don't want that, so subtract it out again here. */
23592 if (!S_IS_COMMON (fixp->fx_addsy))
23593 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23594 code = fixp->fx_r_type;
23595 break;
23596#endif
a737bd4d 23597
c19d1205
ZW
23598 case BFD_RELOC_ARM_IMMEDIATE:
23599 as_bad_where (fixp->fx_file, fixp->fx_line,
23600 _("internal relocation (type: IMMEDIATE) not fixed up"));
23601 return NULL;
a737bd4d 23602
c19d1205
ZW
23603 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23604 as_bad_where (fixp->fx_file, fixp->fx_line,
23605 _("ADRL used for a symbol not defined in the same file"));
23606 return NULL;
a737bd4d 23607
c19d1205 23608 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23609 if (section->use_rela_p)
23610 {
23611 code = fixp->fx_r_type;
23612 break;
23613 }
23614
c19d1205
ZW
23615 if (fixp->fx_addsy != NULL
23616 && !S_IS_DEFINED (fixp->fx_addsy)
23617 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 23618 {
c19d1205
ZW
23619 as_bad_where (fixp->fx_file, fixp->fx_line,
23620 _("undefined local label `%s'"),
23621 S_GET_NAME (fixp->fx_addsy));
23622 return NULL;
a737bd4d
NC
23623 }
23624
c19d1205
ZW
23625 as_bad_where (fixp->fx_file, fixp->fx_line,
23626 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23627 return NULL;
a737bd4d 23628
c19d1205
ZW
23629 default:
23630 {
23631 char * type;
6c43fab6 23632
c19d1205
ZW
23633 switch (fixp->fx_r_type)
23634 {
23635 case BFD_RELOC_NONE: type = "NONE"; break;
23636 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23637 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 23638 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
23639 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23640 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23641 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 23642 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 23643 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
23644 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23645 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23646 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23647 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23648 default: type = _("<unknown>"); break;
23649 }
23650 as_bad_where (fixp->fx_file, fixp->fx_line,
23651 _("cannot represent %s relocation in this object file format"),
23652 type);
23653 return NULL;
23654 }
a737bd4d 23655 }
6c43fab6 23656
c19d1205
ZW
23657#ifdef OBJ_ELF
23658 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23659 && GOT_symbol
23660 && fixp->fx_addsy == GOT_symbol)
23661 {
23662 code = BFD_RELOC_ARM_GOTPC;
23663 reloc->addend = fixp->fx_offset = reloc->address;
23664 }
23665#endif
6c43fab6 23666
c19d1205 23667 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 23668
c19d1205
ZW
23669 if (reloc->howto == NULL)
23670 {
23671 as_bad_where (fixp->fx_file, fixp->fx_line,
23672 _("cannot represent %s relocation in this object file format"),
23673 bfd_get_reloc_code_name (code));
23674 return NULL;
23675 }
6c43fab6 23676
c19d1205
ZW
23677 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23678 vtable entry to be used in the relocation's section offset. */
23679 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23680 reloc->address = fixp->fx_offset;
6c43fab6 23681
c19d1205 23682 return reloc;
6c43fab6
RE
23683}
23684
c19d1205 23685/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 23686
c19d1205
ZW
23687void
23688cons_fix_new_arm (fragS * frag,
23689 int where,
23690 int size,
62ebcb5c
AM
23691 expressionS * exp,
23692 bfd_reloc_code_real_type reloc)
6c43fab6 23693{
c19d1205 23694 int pcrel = 0;
6c43fab6 23695
c19d1205
ZW
23696 /* Pick a reloc.
23697 FIXME: @@ Should look at CPU word size. */
23698 switch (size)
23699 {
23700 case 1:
62ebcb5c 23701 reloc = BFD_RELOC_8;
c19d1205
ZW
23702 break;
23703 case 2:
62ebcb5c 23704 reloc = BFD_RELOC_16;
c19d1205
ZW
23705 break;
23706 case 4:
23707 default:
62ebcb5c 23708 reloc = BFD_RELOC_32;
c19d1205
ZW
23709 break;
23710 case 8:
62ebcb5c 23711 reloc = BFD_RELOC_64;
c19d1205
ZW
23712 break;
23713 }
6c43fab6 23714
f0927246
NC
23715#ifdef TE_PE
23716 if (exp->X_op == O_secrel)
23717 {
23718 exp->X_op = O_symbol;
62ebcb5c 23719 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
23720 }
23721#endif
23722
62ebcb5c 23723 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 23724}
6c43fab6 23725
4343666d 23726#if defined (OBJ_COFF)
c19d1205
ZW
23727void
23728arm_validate_fix (fixS * fixP)
6c43fab6 23729{
c19d1205
ZW
23730 /* If the destination of the branch is a defined symbol which does not have
23731 the THUMB_FUNC attribute, then we must be calling a function which has
23732 the (interfacearm) attribute. We look for the Thumb entry point to that
23733 function and change the branch to refer to that function instead. */
23734 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23735 && fixP->fx_addsy != NULL
23736 && S_IS_DEFINED (fixP->fx_addsy)
23737 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 23738 {
c19d1205 23739 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 23740 }
c19d1205
ZW
23741}
23742#endif
6c43fab6 23743
267bf995 23744
c19d1205
ZW
23745int
23746arm_force_relocation (struct fix * fixp)
23747{
23748#if defined (OBJ_COFF) && defined (TE_PE)
23749 if (fixp->fx_r_type == BFD_RELOC_RVA)
23750 return 1;
23751#endif
6c43fab6 23752
267bf995
RR
23753 /* In case we have a call or a branch to a function in ARM ISA mode from
23754 a thumb function or vice-versa force the relocation. These relocations
23755 are cleared off for some cores that might have blx and simple transformations
23756 are possible. */
23757
23758#ifdef OBJ_ELF
23759 switch (fixp->fx_r_type)
23760 {
23761 case BFD_RELOC_ARM_PCREL_JUMP:
23762 case BFD_RELOC_ARM_PCREL_CALL:
23763 case BFD_RELOC_THUMB_PCREL_BLX:
23764 if (THUMB_IS_FUNC (fixp->fx_addsy))
23765 return 1;
23766 break;
23767
23768 case BFD_RELOC_ARM_PCREL_BLX:
23769 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23770 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23771 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23772 if (ARM_IS_FUNC (fixp->fx_addsy))
23773 return 1;
23774 break;
23775
23776 default:
23777 break;
23778 }
23779#endif
23780
b5884301
PB
23781 /* Resolve these relocations even if the symbol is extern or weak.
23782 Technically this is probably wrong due to symbol preemption.
23783 In practice these relocations do not have enough range to be useful
23784 at dynamic link time, and some code (e.g. in the Linux kernel)
23785 expects these references to be resolved. */
c19d1205
ZW
23786 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23787 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 23788 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 23789 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
23790 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23791 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23792 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 23793 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
23794 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23795 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
23796 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23797 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23798 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23799 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 23800 return 0;
a737bd4d 23801
4962c51a
MS
23802 /* Always leave these relocations for the linker. */
23803 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23804 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23805 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23806 return 1;
23807
f0291e4c
PB
23808 /* Always generate relocations against function symbols. */
23809 if (fixp->fx_r_type == BFD_RELOC_32
23810 && fixp->fx_addsy
23811 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23812 return 1;
23813
c19d1205 23814 return generic_force_reloc (fixp);
404ff6b5
AH
23815}
23816
0ffdc86c 23817#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
23818/* Relocations against function names must be left unadjusted,
23819 so that the linker can use this information to generate interworking
23820 stubs. The MIPS version of this function
c19d1205
ZW
23821 also prevents relocations that are mips-16 specific, but I do not
23822 know why it does this.
404ff6b5 23823
c19d1205
ZW
23824 FIXME:
23825 There is one other problem that ought to be addressed here, but
23826 which currently is not: Taking the address of a label (rather
23827 than a function) and then later jumping to that address. Such
23828 addresses also ought to have their bottom bit set (assuming that
23829 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23830
c19d1205
ZW
23831bfd_boolean
23832arm_fix_adjustable (fixS * fixP)
404ff6b5 23833{
c19d1205
ZW
23834 if (fixP->fx_addsy == NULL)
23835 return 1;
404ff6b5 23836
e28387c3
PB
23837 /* Preserve relocations against symbols with function type. */
23838 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23839 return FALSE;
e28387c3 23840
c19d1205
ZW
23841 if (THUMB_IS_FUNC (fixP->fx_addsy)
23842 && fixP->fx_subsy == NULL)
c921be7d 23843 return FALSE;
a737bd4d 23844
c19d1205
ZW
23845 /* We need the symbol name for the VTABLE entries. */
23846 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23847 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23848 return FALSE;
404ff6b5 23849
c19d1205
ZW
23850 /* Don't allow symbols to be discarded on GOT related relocs. */
23851 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23852 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23853 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23854 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23855 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23856 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23857 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23858 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23859 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23860 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23861 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23862 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23863 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23864 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23865 return FALSE;
a737bd4d 23866
4962c51a
MS
23867 /* Similarly for group relocations. */
23868 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23869 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23870 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 23871 return FALSE;
4962c51a 23872
79947c54
CD
23873 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23874 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23875 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23876 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23877 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23878 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23879 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23880 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23881 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 23882 return FALSE;
79947c54 23883
c921be7d 23884 return TRUE;
a737bd4d 23885}
0ffdc86c
NC
23886#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23887
23888#ifdef OBJ_ELF
404ff6b5 23889
c19d1205
ZW
23890const char *
23891elf32_arm_target_format (void)
404ff6b5 23892{
c19d1205
ZW
23893#ifdef TE_SYMBIAN
23894 return (target_big_endian
23895 ? "elf32-bigarm-symbian"
23896 : "elf32-littlearm-symbian");
23897#elif defined (TE_VXWORKS)
23898 return (target_big_endian
23899 ? "elf32-bigarm-vxworks"
23900 : "elf32-littlearm-vxworks");
b38cadfb
NC
23901#elif defined (TE_NACL)
23902 return (target_big_endian
23903 ? "elf32-bigarm-nacl"
23904 : "elf32-littlearm-nacl");
c19d1205
ZW
23905#else
23906 if (target_big_endian)
23907 return "elf32-bigarm";
23908 else
23909 return "elf32-littlearm";
23910#endif
404ff6b5
AH
23911}
23912
c19d1205
ZW
23913void
23914armelf_frob_symbol (symbolS * symp,
23915 int * puntp)
404ff6b5 23916{
c19d1205
ZW
23917 elf_frob_symbol (symp, puntp);
23918}
23919#endif
404ff6b5 23920
c19d1205 23921/* MD interface: Finalization. */
a737bd4d 23922
c19d1205
ZW
23923void
23924arm_cleanup (void)
23925{
23926 literal_pool * pool;
a737bd4d 23927
e07e6e58
NC
23928 /* Ensure that all the IT blocks are properly closed. */
23929 check_it_blocks_finished ();
23930
c19d1205
ZW
23931 for (pool = list_of_pools; pool; pool = pool->next)
23932 {
5f4273c7 23933 /* Put it at the end of the relevant section. */
c19d1205
ZW
23934 subseg_set (pool->section, pool->sub_section);
23935#ifdef OBJ_ELF
23936 arm_elf_change_section ();
23937#endif
23938 s_ltorg (0);
23939 }
404ff6b5
AH
23940}
23941
cd000bff
DJ
23942#ifdef OBJ_ELF
23943/* Remove any excess mapping symbols generated for alignment frags in
23944 SEC. We may have created a mapping symbol before a zero byte
23945 alignment; remove it if there's a mapping symbol after the
23946 alignment. */
23947static void
23948check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23949 void *dummy ATTRIBUTE_UNUSED)
23950{
23951 segment_info_type *seginfo = seg_info (sec);
23952 fragS *fragp;
23953
23954 if (seginfo == NULL || seginfo->frchainP == NULL)
23955 return;
23956
23957 for (fragp = seginfo->frchainP->frch_root;
23958 fragp != NULL;
23959 fragp = fragp->fr_next)
23960 {
23961 symbolS *sym = fragp->tc_frag_data.last_map;
23962 fragS *next = fragp->fr_next;
23963
23964 /* Variable-sized frags have been converted to fixed size by
23965 this point. But if this was variable-sized to start with,
23966 there will be a fixed-size frag after it. So don't handle
23967 next == NULL. */
23968 if (sym == NULL || next == NULL)
23969 continue;
23970
23971 if (S_GET_VALUE (sym) < next->fr_address)
23972 /* Not at the end of this frag. */
23973 continue;
23974 know (S_GET_VALUE (sym) == next->fr_address);
23975
23976 do
23977 {
23978 if (next->tc_frag_data.first_map != NULL)
23979 {
23980 /* Next frag starts with a mapping symbol. Discard this
23981 one. */
23982 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23983 break;
23984 }
23985
23986 if (next->fr_next == NULL)
23987 {
23988 /* This mapping symbol is at the end of the section. Discard
23989 it. */
23990 know (next->fr_fix == 0 && next->fr_var == 0);
23991 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23992 break;
23993 }
23994
23995 /* As long as we have empty frags without any mapping symbols,
23996 keep looking. */
23997 /* If the next frag is non-empty and does not start with a
23998 mapping symbol, then this mapping symbol is required. */
23999 if (next->fr_address != next->fr_next->fr_address)
24000 break;
24001
24002 next = next->fr_next;
24003 }
24004 while (next != NULL);
24005 }
24006}
24007#endif
24008
c19d1205
ZW
24009/* Adjust the symbol table. This marks Thumb symbols as distinct from
24010 ARM ones. */
404ff6b5 24011
c19d1205
ZW
24012void
24013arm_adjust_symtab (void)
404ff6b5 24014{
c19d1205
ZW
24015#ifdef OBJ_COFF
24016 symbolS * sym;
404ff6b5 24017
c19d1205
ZW
24018 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24019 {
24020 if (ARM_IS_THUMB (sym))
24021 {
24022 if (THUMB_IS_FUNC (sym))
24023 {
24024 /* Mark the symbol as a Thumb function. */
24025 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24026 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24027 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24028
c19d1205
ZW
24029 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24030 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24031 else
24032 as_bad (_("%s: unexpected function type: %d"),
24033 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24034 }
24035 else switch (S_GET_STORAGE_CLASS (sym))
24036 {
24037 case C_EXT:
24038 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24039 break;
24040 case C_STAT:
24041 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24042 break;
24043 case C_LABEL:
24044 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24045 break;
24046 default:
24047 /* Do nothing. */
24048 break;
24049 }
24050 }
a737bd4d 24051
c19d1205
ZW
24052 if (ARM_IS_INTERWORK (sym))
24053 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24054 }
c19d1205
ZW
24055#endif
24056#ifdef OBJ_ELF
24057 symbolS * sym;
24058 char bind;
404ff6b5 24059
c19d1205 24060 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24061 {
c19d1205
ZW
24062 if (ARM_IS_THUMB (sym))
24063 {
24064 elf_symbol_type * elf_sym;
404ff6b5 24065
c19d1205
ZW
24066 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24067 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24068
b0796911
PB
24069 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24070 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24071 {
24072 /* If it's a .thumb_func, declare it as so,
24073 otherwise tag label as .code 16. */
24074 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24075 elf_sym->internal_elf_sym.st_target_internal
24076 = ST_BRANCH_TO_THUMB;
3ba67470 24077 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24078 elf_sym->internal_elf_sym.st_info =
24079 ELF_ST_INFO (bind, STT_ARM_16BIT);
24080 }
24081 }
24082 }
cd000bff
DJ
24083
24084 /* Remove any overlapping mapping symbols generated by alignment frags. */
24085 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24086 /* Now do generic ELF adjustments. */
24087 elf_adjust_symtab ();
c19d1205 24088#endif
404ff6b5
AH
24089}
24090
c19d1205 24091/* MD interface: Initialization. */
404ff6b5 24092
a737bd4d 24093static void
c19d1205 24094set_constant_flonums (void)
a737bd4d 24095{
c19d1205 24096 int i;
404ff6b5 24097
c19d1205
ZW
24098 for (i = 0; i < NUM_FLOAT_VALS; i++)
24099 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24100 abort ();
a737bd4d 24101}
404ff6b5 24102
3e9e4fcf
JB
24103/* Auto-select Thumb mode if it's the only available instruction set for the
24104 given architecture. */
24105
24106static void
24107autoselect_thumb_from_cpu_variant (void)
24108{
24109 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24110 opcode_select (16);
24111}
24112
c19d1205
ZW
24113void
24114md_begin (void)
a737bd4d 24115{
c19d1205
ZW
24116 unsigned mach;
24117 unsigned int i;
404ff6b5 24118
c19d1205
ZW
24119 if ( (arm_ops_hsh = hash_new ()) == NULL
24120 || (arm_cond_hsh = hash_new ()) == NULL
24121 || (arm_shift_hsh = hash_new ()) == NULL
24122 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24123 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24124 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24125 || (arm_reloc_hsh = hash_new ()) == NULL
24126 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24127 as_fatal (_("virtual memory exhausted"));
24128
24129 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24130 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24131 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24132 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24133 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24134 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24135 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24136 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24137 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24138 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24139 (void *) (v7m_psrs + i));
c19d1205 24140 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24141 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24142 for (i = 0;
24143 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24144 i++)
d3ce72d0 24145 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24146 (void *) (barrier_opt_names + i));
c19d1205 24147#ifdef OBJ_ELF
3da1d841
NC
24148 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24149 {
24150 struct reloc_entry * entry = reloc_names + i;
24151
24152 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24153 /* This makes encode_branch() use the EABI versions of this relocation. */
24154 entry->reloc = BFD_RELOC_UNUSED;
24155
24156 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24157 }
c19d1205
ZW
24158#endif
24159
24160 set_constant_flonums ();
404ff6b5 24161
c19d1205
ZW
24162 /* Set the cpu variant based on the command-line options. We prefer
24163 -mcpu= over -march= if both are set (as for GCC); and we prefer
24164 -mfpu= over any other way of setting the floating point unit.
24165 Use of legacy options with new options are faulted. */
e74cfd16 24166 if (legacy_cpu)
404ff6b5 24167 {
e74cfd16 24168 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24169 as_bad (_("use of old and new-style options to set CPU type"));
24170
24171 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24172 }
e74cfd16 24173 else if (!mcpu_cpu_opt)
c19d1205 24174 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24175
e74cfd16 24176 if (legacy_fpu)
c19d1205 24177 {
e74cfd16 24178 if (mfpu_opt)
c19d1205 24179 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24180
24181 mfpu_opt = legacy_fpu;
24182 }
e74cfd16 24183 else if (!mfpu_opt)
03b1477f 24184 {
45eb4c1b
NS
24185#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24186 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24187 /* Some environments specify a default FPU. If they don't, infer it
24188 from the processor. */
e74cfd16 24189 if (mcpu_fpu_opt)
03b1477f
RE
24190 mfpu_opt = mcpu_fpu_opt;
24191 else
24192 mfpu_opt = march_fpu_opt;
39c2da32 24193#else
e74cfd16 24194 mfpu_opt = &fpu_default;
39c2da32 24195#endif
03b1477f
RE
24196 }
24197
e74cfd16 24198 if (!mfpu_opt)
03b1477f 24199 {
493cb6ef 24200 if (mcpu_cpu_opt != NULL)
e74cfd16 24201 mfpu_opt = &fpu_default;
493cb6ef 24202 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24203 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24204 else
e74cfd16 24205 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24206 }
24207
ee065d83 24208#ifdef CPU_DEFAULT
e74cfd16 24209 if (!mcpu_cpu_opt)
ee065d83 24210 {
e74cfd16
PB
24211 mcpu_cpu_opt = &cpu_default;
24212 selected_cpu = cpu_default;
ee065d83 24213 }
73f43896
NC
24214 else if (no_cpu_selected ())
24215 selected_cpu = cpu_default;
e74cfd16
PB
24216#else
24217 if (mcpu_cpu_opt)
24218 selected_cpu = *mcpu_cpu_opt;
ee065d83 24219 else
e74cfd16 24220 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24221#endif
03b1477f 24222
e74cfd16 24223 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24224
3e9e4fcf
JB
24225 autoselect_thumb_from_cpu_variant ();
24226
e74cfd16 24227 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24228
f17c130b 24229#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24230 {
7cc69913
NC
24231 unsigned int flags = 0;
24232
24233#if defined OBJ_ELF
24234 flags = meabi_flags;
d507cf36
PB
24235
24236 switch (meabi_flags)
33a392fb 24237 {
d507cf36 24238 case EF_ARM_EABI_UNKNOWN:
7cc69913 24239#endif
d507cf36
PB
24240 /* Set the flags in the private structure. */
24241 if (uses_apcs_26) flags |= F_APCS26;
24242 if (support_interwork) flags |= F_INTERWORK;
24243 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24244 if (pic_code) flags |= F_PIC;
e74cfd16 24245 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24246 flags |= F_SOFT_FLOAT;
24247
d507cf36
PB
24248 switch (mfloat_abi_opt)
24249 {
24250 case ARM_FLOAT_ABI_SOFT:
24251 case ARM_FLOAT_ABI_SOFTFP:
24252 flags |= F_SOFT_FLOAT;
24253 break;
33a392fb 24254
d507cf36
PB
24255 case ARM_FLOAT_ABI_HARD:
24256 if (flags & F_SOFT_FLOAT)
24257 as_bad (_("hard-float conflicts with specified fpu"));
24258 break;
24259 }
03b1477f 24260
e74cfd16
PB
24261 /* Using pure-endian doubles (even if soft-float). */
24262 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24263 flags |= F_VFP_FLOAT;
f17c130b 24264
fde78edd 24265#if defined OBJ_ELF
e74cfd16 24266 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24267 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24268 break;
24269
8cb51566 24270 case EF_ARM_EABI_VER4:
3a4a14e9 24271 case EF_ARM_EABI_VER5:
c19d1205 24272 /* No additional flags to set. */
d507cf36
PB
24273 break;
24274
24275 default:
24276 abort ();
24277 }
7cc69913 24278#endif
b99bd4ef
NC
24279 bfd_set_private_flags (stdoutput, flags);
24280
24281 /* We have run out flags in the COFF header to encode the
24282 status of ATPCS support, so instead we create a dummy,
c19d1205 24283 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24284 if (atpcs)
24285 {
24286 asection * sec;
24287
24288 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24289
24290 if (sec != NULL)
24291 {
24292 bfd_set_section_flags
24293 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24294 bfd_set_section_size (stdoutput, sec, 0);
24295 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24296 }
24297 }
7cc69913 24298 }
f17c130b 24299#endif
b99bd4ef
NC
24300
24301 /* Record the CPU type as well. */
2d447fca
JM
24302 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24303 mach = bfd_mach_arm_iWMMXt2;
24304 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24305 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24306 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24307 mach = bfd_mach_arm_XScale;
e74cfd16 24308 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24309 mach = bfd_mach_arm_ep9312;
e74cfd16 24310 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24311 mach = bfd_mach_arm_5TE;
e74cfd16 24312 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24313 {
e74cfd16 24314 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24315 mach = bfd_mach_arm_5T;
24316 else
24317 mach = bfd_mach_arm_5;
24318 }
e74cfd16 24319 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24320 {
e74cfd16 24321 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24322 mach = bfd_mach_arm_4T;
24323 else
24324 mach = bfd_mach_arm_4;
24325 }
e74cfd16 24326 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24327 mach = bfd_mach_arm_3M;
e74cfd16
PB
24328 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24329 mach = bfd_mach_arm_3;
24330 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24331 mach = bfd_mach_arm_2a;
24332 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24333 mach = bfd_mach_arm_2;
24334 else
24335 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24336
24337 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24338}
24339
c19d1205 24340/* Command line processing. */
b99bd4ef 24341
c19d1205
ZW
24342/* md_parse_option
24343 Invocation line includes a switch not recognized by the base assembler.
24344 See if it's a processor-specific option.
b99bd4ef 24345
c19d1205
ZW
24346 This routine is somewhat complicated by the need for backwards
24347 compatibility (since older releases of gcc can't be changed).
24348 The new options try to make the interface as compatible as
24349 possible with GCC.
b99bd4ef 24350
c19d1205 24351 New options (supported) are:
b99bd4ef 24352
c19d1205
ZW
24353 -mcpu=<cpu name> Assemble for selected processor
24354 -march=<architecture name> Assemble for selected architecture
24355 -mfpu=<fpu architecture> Assemble for selected FPU.
24356 -EB/-mbig-endian Big-endian
24357 -EL/-mlittle-endian Little-endian
24358 -k Generate PIC code
24359 -mthumb Start in Thumb mode
24360 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24361
278df34e 24362 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24363 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24364
c19d1205 24365 For now we will also provide support for:
b99bd4ef 24366
c19d1205
ZW
24367 -mapcs-32 32-bit Program counter
24368 -mapcs-26 26-bit Program counter
24369 -macps-float Floats passed in FP registers
24370 -mapcs-reentrant Reentrant code
24371 -matpcs
24372 (sometime these will probably be replaced with -mapcs=<list of options>
24373 and -matpcs=<list of options>)
b99bd4ef 24374
c19d1205
ZW
24375 The remaining options are only supported for back-wards compatibility.
24376 Cpu variants, the arm part is optional:
24377 -m[arm]1 Currently not supported.
24378 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24379 -m[arm]3 Arm 3 processor
24380 -m[arm]6[xx], Arm 6 processors
24381 -m[arm]7[xx][t][[d]m] Arm 7 processors
24382 -m[arm]8[10] Arm 8 processors
24383 -m[arm]9[20][tdmi] Arm 9 processors
24384 -mstrongarm[110[0]] StrongARM processors
24385 -mxscale XScale processors
24386 -m[arm]v[2345[t[e]]] Arm architectures
24387 -mall All (except the ARM1)
24388 FP variants:
24389 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24390 -mfpe-old (No float load/store multiples)
24391 -mvfpxd VFP Single precision
24392 -mvfp All VFP
24393 -mno-fpu Disable all floating point instructions
b99bd4ef 24394
c19d1205
ZW
24395 The following CPU names are recognized:
24396 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24397 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24398 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24399 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24400 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24401 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24402 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24403
c19d1205 24404 */
b99bd4ef 24405
c19d1205 24406const char * md_shortopts = "m:k";
b99bd4ef 24407
c19d1205
ZW
24408#ifdef ARM_BI_ENDIAN
24409#define OPTION_EB (OPTION_MD_BASE + 0)
24410#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24411#else
c19d1205
ZW
24412#if TARGET_BYTES_BIG_ENDIAN
24413#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24414#else
c19d1205
ZW
24415#define OPTION_EL (OPTION_MD_BASE + 1)
24416#endif
b99bd4ef 24417#endif
845b51d6 24418#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24419
c19d1205 24420struct option md_longopts[] =
b99bd4ef 24421{
c19d1205
ZW
24422#ifdef OPTION_EB
24423 {"EB", no_argument, NULL, OPTION_EB},
24424#endif
24425#ifdef OPTION_EL
24426 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24427#endif
845b51d6 24428 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24429 {NULL, no_argument, NULL, 0}
24430};
b99bd4ef 24431
8b2d793c 24432
c19d1205 24433size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24434
c19d1205 24435struct arm_option_table
b99bd4ef 24436{
c19d1205
ZW
24437 char *option; /* Option name to match. */
24438 char *help; /* Help information. */
24439 int *var; /* Variable to change. */
24440 int value; /* What to change it to. */
24441 char *deprecated; /* If non-null, print this message. */
24442};
b99bd4ef 24443
c19d1205
ZW
24444struct arm_option_table arm_opts[] =
24445{
24446 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24447 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24448 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24449 &support_interwork, 1, NULL},
24450 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24451 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24452 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24453 1, NULL},
24454 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24455 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24456 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24457 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24458 NULL},
b99bd4ef 24459
c19d1205
ZW
24460 /* These are recognized by the assembler, but have no affect on code. */
24461 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24462 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24463
24464 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24465 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24466 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24467 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24468 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24469 {NULL, NULL, NULL, 0, NULL}
24470};
24471
24472struct arm_legacy_option_table
24473{
24474 char *option; /* Option name to match. */
24475 const arm_feature_set **var; /* Variable to change. */
24476 const arm_feature_set value; /* What to change it to. */
24477 char *deprecated; /* If non-null, print this message. */
24478};
b99bd4ef 24479
e74cfd16
PB
24480const struct arm_legacy_option_table arm_legacy_opts[] =
24481{
c19d1205
ZW
24482 /* DON'T add any new processors to this list -- we want the whole list
24483 to go away... Add them to the processors table instead. */
e74cfd16
PB
24484 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24485 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24486 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24487 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24488 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24489 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24490 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24491 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24492 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24493 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24494 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24495 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24496 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24497 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24498 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24499 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24500 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24501 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24502 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24503 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24504 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24505 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24506 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24507 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24508 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24509 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24510 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24511 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24512 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24513 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24514 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24515 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24516 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24517 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24518 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24519 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24520 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24521 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24522 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24523 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24524 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24525 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24526 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24527 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24528 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24529 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24530 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24531 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24532 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24533 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24534 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24535 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24536 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24537 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24538 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24539 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24540 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24541 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24542 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24543 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24544 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24545 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24546 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24547 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24548 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24549 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24550 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24551 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24552 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24553 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24554 N_("use -mcpu=strongarm110")},
e74cfd16 24555 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24556 N_("use -mcpu=strongarm1100")},
e74cfd16 24557 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24558 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
24559 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24560 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24561 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 24562
c19d1205 24563 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
24564 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24565 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24566 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24567 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24568 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24569 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24570 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24571 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24572 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24573 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24574 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24575 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24576 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24577 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24578 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24579 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24580 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24581 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 24582
c19d1205 24583 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
24584 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24585 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24586 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24587 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 24588 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 24589
e74cfd16 24590 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 24591};
7ed4c4c5 24592
c19d1205 24593struct arm_cpu_option_table
7ed4c4c5 24594{
c19d1205 24595 char *name;
f3bad469 24596 size_t name_len;
e74cfd16 24597 const arm_feature_set value;
c19d1205
ZW
24598 /* For some CPUs we assume an FPU unless the user explicitly sets
24599 -mfpu=... */
e74cfd16 24600 const arm_feature_set default_fpu;
ee065d83
PB
24601 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24602 case. */
24603 const char *canonical_name;
c19d1205 24604};
7ed4c4c5 24605
c19d1205
ZW
24606/* This list should, at a minimum, contain all the cpu names
24607 recognized by GCC. */
f3bad469 24608#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 24609static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 24610{
f3bad469
MGD
24611 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24612 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24613 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24614 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24615 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24616 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24617 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24618 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24619 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24620 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24621 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24622 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24623 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24624 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24625 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24626 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24627 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24628 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24629 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24630 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24631 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24632 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24633 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24634 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24635 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24636 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24637 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24638 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24639 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24640 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24641 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24642 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24643 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24644 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24645 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24646 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24647 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24648 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24649 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24650 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24651 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24652 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24653 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24654 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24655 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24656 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
24657 /* For V5 or later processors we default to using VFP; but the user
24658 should really set the FPU type explicitly. */
f3bad469
MGD
24659 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24660 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24661 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24662 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24663 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24664 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24665 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24666 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24667 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24668 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24669 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24670 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24671 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24672 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24673 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24674 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24675 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24676 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24677 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24678 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24679 "ARM1026EJ-S"),
24680 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24681 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24682 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24683 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24684 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24685 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24686 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24687 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24688 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24689 "ARM1136JF-S"),
24690 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24691 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24692 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24693 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24694 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
24695 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
24696 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
24697 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24698 FPU_NONE, "Cortex-A5"),
c9fb6e58 24699 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
24700 "Cortex-A7"),
24701 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 24702 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24703 | FPU_NEON_EXT_V1),
f3bad469
MGD
24704 "Cortex-A8"),
24705 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 24706 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24707 | FPU_NEON_EXT_V1),
f3bad469 24708 "Cortex-A9"),
c9fb6e58 24709 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 24710 "Cortex-A12"),
c9fb6e58 24711 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 24712 "Cortex-A15"),
d7adf960
KT
24713 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24714 "Cortex-A17"),
43cdc0a8
RR
24715 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24716 "Cortex-A35"),
92eb40d9 24717 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24718 "Cortex-A53"),
92eb40d9 24719 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24720 "Cortex-A57"),
b19f47ad
JW
24721 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24722 "Cortex-A72"),
f3bad469
MGD
24723 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24724 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24725 "Cortex-R4F"),
24726 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24727 FPU_NONE, "Cortex-R5"),
70a8bc5b 24728 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24729 FPU_ARCH_VFP_V3D16,
24730 "Cortex-R7"),
a715796b 24731 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
24732 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24733 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24734 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24735 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 24736 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
24737 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24738 "Samsung " \
24739 "Exynos M1"),
6b21c2bf
JW
24740 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24741 "Qualcomm "
24742 "QDF24XX"),
24743
c19d1205 24744 /* ??? XSCALE is really an architecture. */
f3bad469 24745 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24746 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
24747 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24748 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24749 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24750 /* Maverick */
823d2571 24751 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
24752 FPU_ARCH_MAVERICK, "ARM920T"),
24753 /* Marvell processors. */
823d2571
TG
24754 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24755 | ARM_EXT_SEC),
477330fc 24756 FPU_ARCH_VFP_V3D16, NULL),
823d2571
TG
24757 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24758 | ARM_EXT_SEC),
4347085a 24759 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
24760 /* APM X-Gene family. */
24761 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24762 "APM X-Gene 1"),
24763 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24764 "APM X-Gene 2"),
da4339ed 24765
f3bad469 24766 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 24767};
f3bad469 24768#undef ARM_CPU_OPT
7ed4c4c5 24769
c19d1205 24770struct arm_arch_option_table
7ed4c4c5 24771{
c19d1205 24772 char *name;
f3bad469 24773 size_t name_len;
e74cfd16
PB
24774 const arm_feature_set value;
24775 const arm_feature_set default_fpu;
c19d1205 24776};
7ed4c4c5 24777
c19d1205
ZW
24778/* This list should, at a minimum, contain all the architecture names
24779 recognized by GCC. */
f3bad469 24780#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 24781static const struct arm_arch_option_table arm_archs[] =
c19d1205 24782{
f3bad469
MGD
24783 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24784 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24785 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24786 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24787 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24788 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24789 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24790 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24791 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24792 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24793 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24794 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24795 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24796 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24797 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24798 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24799 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24800 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24801 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24802 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24803 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
24804 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
24805 kept to preserve existing behaviour. */
24806 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
24807 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
24808 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24809 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24810 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
24811 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
24812 kept to preserve existing behaviour. */
24813 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
24814 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
24815 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24816 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24817 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
24818 /* The official spelling of the ARMv7 profile variants is the dashed form.
24819 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 24820 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 24821 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
24822 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24823 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24824 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24825 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24826 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24827 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 24828 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 24829 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 24830 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
24831 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24832 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24833 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24834 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 24835};
f3bad469 24836#undef ARM_ARCH_OPT
7ed4c4c5 24837
69133863
MGD
24838/* ISA extensions in the co-processor and main instruction set space. */
24839struct arm_option_extension_value_table
c19d1205
ZW
24840{
24841 char *name;
f3bad469 24842 size_t name_len;
5a70a223
JB
24843 const arm_feature_set merge_value;
24844 const arm_feature_set clear_value;
69133863 24845 const arm_feature_set allowed_archs;
c19d1205 24846};
7ed4c4c5 24847
69133863
MGD
24848/* The following table must be in alphabetical order with a NULL last entry.
24849 */
5a70a223 24850#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 24851static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 24852{
823d2571
TG
24853 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
24854 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 24855 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
24856 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
24857 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24858 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
24859 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24860 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24861 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24862 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
24863 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
24864 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
24865 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
24866 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
24867 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
24868 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
24869 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24870 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24871 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
bca38921 24872 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
823d2571
TG
24873 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
24874 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24875 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24876 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24877 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
24878 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
24879 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
24880 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
24881 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24882 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24883 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
24884 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
24885 | ARM_EXT_DIV),
24886 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
24887 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
d6b4b13e
MW
24888 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8,
24889 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
24890 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
24891 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
24892 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 24893 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 24894};
f3bad469 24895#undef ARM_EXT_OPT
69133863
MGD
24896
24897/* ISA floating-point and Advanced SIMD extensions. */
24898struct arm_option_fpu_value_table
24899{
24900 char *name;
24901 const arm_feature_set value;
c19d1205 24902};
7ed4c4c5 24903
c19d1205
ZW
24904/* This list should, at a minimum, contain all the fpu names
24905 recognized by GCC. */
69133863 24906static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
24907{
24908 {"softfpa", FPU_NONE},
24909 {"fpe", FPU_ARCH_FPE},
24910 {"fpe2", FPU_ARCH_FPE},
24911 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24912 {"fpa", FPU_ARCH_FPA},
24913 {"fpa10", FPU_ARCH_FPA},
24914 {"fpa11", FPU_ARCH_FPA},
24915 {"arm7500fe", FPU_ARCH_FPA},
24916 {"softvfp", FPU_ARCH_VFP},
24917 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24918 {"vfp", FPU_ARCH_VFP_V2},
24919 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 24920 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
24921 {"vfp10", FPU_ARCH_VFP_V2},
24922 {"vfp10-r0", FPU_ARCH_VFP_V1},
24923 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
24924 {"vfpv2", FPU_ARCH_VFP_V2},
24925 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 24926 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 24927 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
24928 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24929 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24930 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
24931 {"arm1020t", FPU_ARCH_VFP_V1},
24932 {"arm1020e", FPU_ARCH_VFP_V2},
24933 {"arm1136jfs", FPU_ARCH_VFP_V2},
24934 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24935 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 24936 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 24937 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
24938 {"vfpv4", FPU_ARCH_VFP_V4},
24939 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 24940 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
24941 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
24942 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 24943 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
24944 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24945 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24946 {"crypto-neon-fp-armv8",
24947 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 24948 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
24949 {"crypto-neon-fp-armv8.1",
24950 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
24951 {NULL, ARM_ARCH_NONE}
24952};
24953
24954struct arm_option_value_table
24955{
24956 char *name;
24957 long value;
c19d1205 24958};
7ed4c4c5 24959
e74cfd16 24960static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
24961{
24962 {"hard", ARM_FLOAT_ABI_HARD},
24963 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24964 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 24965 {NULL, 0}
c19d1205 24966};
7ed4c4c5 24967
c19d1205 24968#ifdef OBJ_ELF
3a4a14e9 24969/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 24970static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
24971{
24972 {"gnu", EF_ARM_EABI_UNKNOWN},
24973 {"4", EF_ARM_EABI_VER4},
3a4a14e9 24974 {"5", EF_ARM_EABI_VER5},
e74cfd16 24975 {NULL, 0}
c19d1205
ZW
24976};
24977#endif
7ed4c4c5 24978
c19d1205
ZW
24979struct arm_long_option_table
24980{
24981 char * option; /* Substring to match. */
24982 char * help; /* Help information. */
24983 int (* func) (char * subopt); /* Function to decode sub-option. */
24984 char * deprecated; /* If non-null, print this message. */
24985};
7ed4c4c5 24986
c921be7d 24987static bfd_boolean
f3bad469 24988arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 24989{
21d799b5
NC
24990 arm_feature_set *ext_set = (arm_feature_set *)
24991 xmalloc (sizeof (arm_feature_set));
e74cfd16 24992
69133863 24993 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
24994 extensions being added before being removed. We achieve this by having
24995 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 24996 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 24997 or removing it (0) and only allowing it to change in the order
69133863
MGD
24998 -1 -> 1 -> 0. */
24999 const struct arm_option_extension_value_table * opt = NULL;
25000 int adding_value = -1;
25001
e74cfd16
PB
25002 /* Copy the feature set, so that we can modify it. */
25003 *ext_set = **opt_p;
25004 *opt_p = ext_set;
25005
c19d1205 25006 while (str != NULL && *str != 0)
7ed4c4c5 25007 {
f3bad469
MGD
25008 char *ext;
25009 size_t len;
7ed4c4c5 25010
c19d1205
ZW
25011 if (*str != '+')
25012 {
25013 as_bad (_("invalid architectural extension"));
c921be7d 25014 return FALSE;
c19d1205 25015 }
7ed4c4c5 25016
c19d1205
ZW
25017 str++;
25018 ext = strchr (str, '+');
7ed4c4c5 25019
c19d1205 25020 if (ext != NULL)
f3bad469 25021 len = ext - str;
c19d1205 25022 else
f3bad469 25023 len = strlen (str);
7ed4c4c5 25024
f3bad469 25025 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25026 {
25027 if (adding_value != 0)
25028 {
25029 adding_value = 0;
25030 opt = arm_extensions;
25031 }
25032
f3bad469 25033 len -= 2;
69133863
MGD
25034 str += 2;
25035 }
f3bad469 25036 else if (len > 0)
69133863
MGD
25037 {
25038 if (adding_value == -1)
25039 {
25040 adding_value = 1;
25041 opt = arm_extensions;
25042 }
25043 else if (adding_value != 1)
25044 {
25045 as_bad (_("must specify extensions to add before specifying "
25046 "those to remove"));
25047 return FALSE;
25048 }
25049 }
25050
f3bad469 25051 if (len == 0)
c19d1205
ZW
25052 {
25053 as_bad (_("missing architectural extension"));
c921be7d 25054 return FALSE;
c19d1205 25055 }
7ed4c4c5 25056
69133863
MGD
25057 gas_assert (adding_value != -1);
25058 gas_assert (opt != NULL);
25059
25060 /* Scan over the options table trying to find an exact match. */
25061 for (; opt->name != NULL; opt++)
f3bad469 25062 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25063 {
69133863
MGD
25064 /* Check we can apply the extension to this architecture. */
25065 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25066 {
25067 as_bad (_("extension does not apply to the base architecture"));
25068 return FALSE;
25069 }
25070
25071 /* Add or remove the extension. */
25072 if (adding_value)
5a70a223 25073 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25074 else
5a70a223 25075 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25076
c19d1205
ZW
25077 break;
25078 }
7ed4c4c5 25079
c19d1205
ZW
25080 if (opt->name == NULL)
25081 {
69133863
MGD
25082 /* Did we fail to find an extension because it wasn't specified in
25083 alphabetical order, or because it does not exist? */
25084
25085 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25086 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25087 break;
25088
25089 if (opt->name == NULL)
25090 as_bad (_("unknown architectural extension `%s'"), str);
25091 else
25092 as_bad (_("architectural extensions must be specified in "
25093 "alphabetical order"));
25094
c921be7d 25095 return FALSE;
c19d1205 25096 }
69133863
MGD
25097 else
25098 {
25099 /* We should skip the extension we've just matched the next time
25100 round. */
25101 opt++;
25102 }
7ed4c4c5 25103
c19d1205
ZW
25104 str = ext;
25105 };
7ed4c4c5 25106
c921be7d 25107 return TRUE;
c19d1205 25108}
7ed4c4c5 25109
c921be7d 25110static bfd_boolean
f3bad469 25111arm_parse_cpu (char *str)
7ed4c4c5 25112{
f3bad469
MGD
25113 const struct arm_cpu_option_table *opt;
25114 char *ext = strchr (str, '+');
25115 size_t len;
7ed4c4c5 25116
c19d1205 25117 if (ext != NULL)
f3bad469 25118 len = ext - str;
7ed4c4c5 25119 else
f3bad469 25120 len = strlen (str);
7ed4c4c5 25121
f3bad469 25122 if (len == 0)
7ed4c4c5 25123 {
c19d1205 25124 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25125 return FALSE;
7ed4c4c5
NC
25126 }
25127
c19d1205 25128 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25129 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25130 {
e74cfd16
PB
25131 mcpu_cpu_opt = &opt->value;
25132 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25133 if (opt->canonical_name)
ef8e6722
JW
25134 {
25135 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25136 strcpy (selected_cpu_name, opt->canonical_name);
25137 }
ee065d83
PB
25138 else
25139 {
f3bad469 25140 size_t i;
c921be7d 25141
ef8e6722
JW
25142 if (len >= sizeof selected_cpu_name)
25143 len = (sizeof selected_cpu_name) - 1;
25144
f3bad469 25145 for (i = 0; i < len; i++)
ee065d83
PB
25146 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25147 selected_cpu_name[i] = 0;
25148 }
7ed4c4c5 25149
c19d1205
ZW
25150 if (ext != NULL)
25151 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25152
c921be7d 25153 return TRUE;
c19d1205 25154 }
7ed4c4c5 25155
c19d1205 25156 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25157 return FALSE;
7ed4c4c5
NC
25158}
25159
c921be7d 25160static bfd_boolean
f3bad469 25161arm_parse_arch (char *str)
7ed4c4c5 25162{
e74cfd16 25163 const struct arm_arch_option_table *opt;
c19d1205 25164 char *ext = strchr (str, '+');
f3bad469 25165 size_t len;
7ed4c4c5 25166
c19d1205 25167 if (ext != NULL)
f3bad469 25168 len = ext - str;
7ed4c4c5 25169 else
f3bad469 25170 len = strlen (str);
7ed4c4c5 25171
f3bad469 25172 if (len == 0)
7ed4c4c5 25173 {
c19d1205 25174 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25175 return FALSE;
7ed4c4c5
NC
25176 }
25177
c19d1205 25178 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25179 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25180 {
e74cfd16
PB
25181 march_cpu_opt = &opt->value;
25182 march_fpu_opt = &opt->default_fpu;
5f4273c7 25183 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25184
c19d1205
ZW
25185 if (ext != NULL)
25186 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25187
c921be7d 25188 return TRUE;
c19d1205
ZW
25189 }
25190
25191 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25192 return FALSE;
7ed4c4c5 25193}
eb043451 25194
c921be7d 25195static bfd_boolean
c19d1205
ZW
25196arm_parse_fpu (char * str)
25197{
69133863 25198 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25199
c19d1205
ZW
25200 for (opt = arm_fpus; opt->name != NULL; opt++)
25201 if (streq (opt->name, str))
25202 {
e74cfd16 25203 mfpu_opt = &opt->value;
c921be7d 25204 return TRUE;
c19d1205 25205 }
b99bd4ef 25206
c19d1205 25207 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25208 return FALSE;
c19d1205
ZW
25209}
25210
c921be7d 25211static bfd_boolean
c19d1205 25212arm_parse_float_abi (char * str)
b99bd4ef 25213{
e74cfd16 25214 const struct arm_option_value_table * opt;
b99bd4ef 25215
c19d1205
ZW
25216 for (opt = arm_float_abis; opt->name != NULL; opt++)
25217 if (streq (opt->name, str))
25218 {
25219 mfloat_abi_opt = opt->value;
c921be7d 25220 return TRUE;
c19d1205 25221 }
cc8a6dd0 25222
c19d1205 25223 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25224 return FALSE;
c19d1205 25225}
b99bd4ef 25226
c19d1205 25227#ifdef OBJ_ELF
c921be7d 25228static bfd_boolean
c19d1205
ZW
25229arm_parse_eabi (char * str)
25230{
e74cfd16 25231 const struct arm_option_value_table *opt;
cc8a6dd0 25232
c19d1205
ZW
25233 for (opt = arm_eabis; opt->name != NULL; opt++)
25234 if (streq (opt->name, str))
25235 {
25236 meabi_flags = opt->value;
c921be7d 25237 return TRUE;
c19d1205
ZW
25238 }
25239 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25240 return FALSE;
c19d1205
ZW
25241}
25242#endif
cc8a6dd0 25243
c921be7d 25244static bfd_boolean
e07e6e58
NC
25245arm_parse_it_mode (char * str)
25246{
c921be7d 25247 bfd_boolean ret = TRUE;
e07e6e58
NC
25248
25249 if (streq ("arm", str))
25250 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25251 else if (streq ("thumb", str))
25252 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25253 else if (streq ("always", str))
25254 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25255 else if (streq ("never", str))
25256 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25257 else
25258 {
25259 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25260 "arm, thumb, always, or never."), str);
c921be7d 25261 ret = FALSE;
e07e6e58
NC
25262 }
25263
25264 return ret;
25265}
25266
2e6976a8
DG
25267static bfd_boolean
25268arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25269{
25270 codecomposer_syntax = TRUE;
25271 arm_comment_chars[0] = ';';
25272 arm_line_separator_chars[0] = 0;
25273 return TRUE;
25274}
25275
c19d1205
ZW
25276struct arm_long_option_table arm_long_opts[] =
25277{
25278 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25279 arm_parse_cpu, NULL},
25280 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25281 arm_parse_arch, NULL},
25282 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25283 arm_parse_fpu, NULL},
25284 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25285 arm_parse_float_abi, NULL},
25286#ifdef OBJ_ELF
7fac0536 25287 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25288 arm_parse_eabi, NULL},
25289#endif
e07e6e58
NC
25290 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25291 arm_parse_it_mode, NULL},
2e6976a8
DG
25292 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25293 arm_ccs_mode, NULL},
c19d1205
ZW
25294 {NULL, NULL, 0, NULL}
25295};
cc8a6dd0 25296
c19d1205
ZW
25297int
25298md_parse_option (int c, char * arg)
25299{
25300 struct arm_option_table *opt;
e74cfd16 25301 const struct arm_legacy_option_table *fopt;
c19d1205 25302 struct arm_long_option_table *lopt;
b99bd4ef 25303
c19d1205 25304 switch (c)
b99bd4ef 25305 {
c19d1205
ZW
25306#ifdef OPTION_EB
25307 case OPTION_EB:
25308 target_big_endian = 1;
25309 break;
25310#endif
cc8a6dd0 25311
c19d1205
ZW
25312#ifdef OPTION_EL
25313 case OPTION_EL:
25314 target_big_endian = 0;
25315 break;
25316#endif
b99bd4ef 25317
845b51d6
PB
25318 case OPTION_FIX_V4BX:
25319 fix_v4bx = TRUE;
25320 break;
25321
c19d1205
ZW
25322 case 'a':
25323 /* Listing option. Just ignore these, we don't support additional
25324 ones. */
25325 return 0;
b99bd4ef 25326
c19d1205
ZW
25327 default:
25328 for (opt = arm_opts; opt->option != NULL; opt++)
25329 {
25330 if (c == opt->option[0]
25331 && ((arg == NULL && opt->option[1] == 0)
25332 || streq (arg, opt->option + 1)))
25333 {
c19d1205 25334 /* If the option is deprecated, tell the user. */
278df34e 25335 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25336 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25337 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25338
c19d1205
ZW
25339 if (opt->var != NULL)
25340 *opt->var = opt->value;
cc8a6dd0 25341
c19d1205
ZW
25342 return 1;
25343 }
25344 }
b99bd4ef 25345
e74cfd16
PB
25346 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25347 {
25348 if (c == fopt->option[0]
25349 && ((arg == NULL && fopt->option[1] == 0)
25350 || streq (arg, fopt->option + 1)))
25351 {
e74cfd16 25352 /* If the option is deprecated, tell the user. */
278df34e 25353 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25354 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25355 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25356
25357 if (fopt->var != NULL)
25358 *fopt->var = &fopt->value;
25359
25360 return 1;
25361 }
25362 }
25363
c19d1205
ZW
25364 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25365 {
25366 /* These options are expected to have an argument. */
25367 if (c == lopt->option[0]
25368 && arg != NULL
25369 && strncmp (arg, lopt->option + 1,
25370 strlen (lopt->option + 1)) == 0)
25371 {
c19d1205 25372 /* If the option is deprecated, tell the user. */
278df34e 25373 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25374 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25375 _(lopt->deprecated));
b99bd4ef 25376
c19d1205
ZW
25377 /* Call the sup-option parser. */
25378 return lopt->func (arg + strlen (lopt->option) - 1);
25379 }
25380 }
a737bd4d 25381
c19d1205
ZW
25382 return 0;
25383 }
a394c00f 25384
c19d1205
ZW
25385 return 1;
25386}
a394c00f 25387
c19d1205
ZW
25388void
25389md_show_usage (FILE * fp)
a394c00f 25390{
c19d1205
ZW
25391 struct arm_option_table *opt;
25392 struct arm_long_option_table *lopt;
a394c00f 25393
c19d1205 25394 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25395
c19d1205
ZW
25396 for (opt = arm_opts; opt->option != NULL; opt++)
25397 if (opt->help != NULL)
25398 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25399
c19d1205
ZW
25400 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25401 if (lopt->help != NULL)
25402 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25403
c19d1205
ZW
25404#ifdef OPTION_EB
25405 fprintf (fp, _("\
25406 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25407#endif
25408
c19d1205
ZW
25409#ifdef OPTION_EL
25410 fprintf (fp, _("\
25411 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25412#endif
845b51d6
PB
25413
25414 fprintf (fp, _("\
25415 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25416}
ee065d83
PB
25417
25418
25419#ifdef OBJ_ELF
62b3e311
PB
25420typedef struct
25421{
25422 int val;
25423 arm_feature_set flags;
25424} cpu_arch_ver_table;
25425
25426/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
25427 least features first. */
25428static const cpu_arch_ver_table cpu_arch_ver[] =
25429{
25430 {1, ARM_ARCH_V4},
25431 {2, ARM_ARCH_V4T},
25432 {3, ARM_ARCH_V5},
ee3c0378 25433 {3, ARM_ARCH_V5T},
62b3e311
PB
25434 {4, ARM_ARCH_V5TE},
25435 {5, ARM_ARCH_V5TEJ},
25436 {6, ARM_ARCH_V6},
7e806470 25437 {9, ARM_ARCH_V6K},
f4c65163 25438 {7, ARM_ARCH_V6Z},
91e22acd 25439 {11, ARM_ARCH_V6M},
b2a5fbdc 25440 {12, ARM_ARCH_V6SM},
7e806470 25441 {8, ARM_ARCH_V6T2},
c9fb6e58 25442 {10, ARM_ARCH_V7VE},
62b3e311
PB
25443 {10, ARM_ARCH_V7R},
25444 {10, ARM_ARCH_V7M},
bca38921 25445 {14, ARM_ARCH_V8A},
62b3e311
PB
25446 {0, ARM_ARCH_NONE}
25447};
25448
ee3c0378
AS
25449/* Set an attribute if it has not already been set by the user. */
25450static void
25451aeabi_set_attribute_int (int tag, int value)
25452{
25453 if (tag < 1
25454 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25455 || !attributes_set_explicitly[tag])
25456 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25457}
25458
25459static void
25460aeabi_set_attribute_string (int tag, const char *value)
25461{
25462 if (tag < 1
25463 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25464 || !attributes_set_explicitly[tag])
25465 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25466}
25467
ee065d83 25468/* Set the public EABI object attributes. */
3cfdb781 25469void
ee065d83
PB
25470aeabi_set_public_attributes (void)
25471{
25472 int arch;
69239280 25473 char profile;
90ec0d68 25474 int virt_sec = 0;
bca38921 25475 int fp16_optional = 0;
e74cfd16 25476 arm_feature_set flags;
62b3e311
PB
25477 arm_feature_set tmp;
25478 const cpu_arch_ver_table *p;
ee065d83
PB
25479
25480 /* Choose the architecture based on the capabilities of the requested cpu
25481 (if any) and/or the instructions actually used. */
e74cfd16
PB
25482 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25483 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25484 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
25485
25486 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25487 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25488
25489 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25490 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25491
7f78eb34
JW
25492 selected_cpu = flags;
25493
ddd7f988 25494 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
25495 if (object_arch)
25496 {
25497 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25498 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25499 }
25500
251665fc
MGD
25501 /* We need to make sure that the attributes do not identify us as v6S-M
25502 when the only v6S-M feature in use is the Operating System Extensions. */
25503 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25504 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 25505 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 25506
62b3e311
PB
25507 tmp = flags;
25508 arch = 0;
25509 for (p = cpu_arch_ver; p->val; p++)
25510 {
25511 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25512 {
25513 arch = p->val;
25514 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
25515 }
25516 }
ee065d83 25517
9e3c6df6
PB
25518 /* The table lookup above finds the last architecture to contribute
25519 a new feature. Unfortunately, Tag13 is a subset of the union of
25520 v6T2 and v7-M, so it is never seen as contributing a new feature.
25521 We can not search for the last entry which is entirely used,
25522 because if no CPU is specified we build up only those flags
25523 actually used. Perhaps we should separate out the specified
25524 and implicit cases. Avoid taking this path for -march=all by
25525 checking for contradictory v7-A / v7-M features. */
25526 if (arch == 10
25527 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
25528 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
25529 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
25530 arch = 13;
25531
ee065d83
PB
25532 /* Tag_CPU_name. */
25533 if (selected_cpu_name[0])
25534 {
91d6fa6a 25535 char *q;
ee065d83 25536
91d6fa6a
NC
25537 q = selected_cpu_name;
25538 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
25539 {
25540 int i;
5f4273c7 25541
91d6fa6a
NC
25542 q += 4;
25543 for (i = 0; q[i]; i++)
25544 q[i] = TOUPPER (q[i]);
ee065d83 25545 }
91d6fa6a 25546 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 25547 }
62f3b8c8 25548
ee065d83 25549 /* Tag_CPU_arch. */
ee3c0378 25550 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 25551
62b3e311
PB
25552 /* Tag_CPU_arch_profile. */
25553 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 25554 profile = 'A';
62b3e311 25555 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 25556 profile = 'R';
7e806470 25557 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
25558 profile = 'M';
25559 else
25560 profile = '\0';
25561
25562 if (profile != '\0')
25563 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 25564
ee065d83 25565 /* Tag_ARM_ISA_use. */
ee3c0378
AS
25566 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
25567 || arch == 0)
25568 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 25569
ee065d83 25570 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
25571 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
25572 || arch == 0)
25573 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
25574 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 25575
ee065d83 25576 /* Tag_VFP_arch. */
a715796b
TG
25577 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
25578 aeabi_set_attribute_int (Tag_VFP_arch,
25579 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25580 ? 7 : 8);
bca38921 25581 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
25582 aeabi_set_attribute_int (Tag_VFP_arch,
25583 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25584 ? 5 : 6);
25585 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
25586 {
25587 fp16_optional = 1;
25588 aeabi_set_attribute_int (Tag_VFP_arch, 3);
25589 }
ada65aa3 25590 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
25591 {
25592 aeabi_set_attribute_int (Tag_VFP_arch, 4);
25593 fp16_optional = 1;
25594 }
ee3c0378
AS
25595 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
25596 aeabi_set_attribute_int (Tag_VFP_arch, 2);
25597 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 25598 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 25599 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 25600
4547cb56
NC
25601 /* Tag_ABI_HardFP_use. */
25602 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25603 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25604 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25605
ee065d83 25606 /* Tag_WMMX_arch. */
ee3c0378
AS
25607 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25608 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25609 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25610 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 25611
ee3c0378 25612 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
25613 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25614 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25615 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25616 {
25617 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25618 {
25619 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25620 }
25621 else
25622 {
25623 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25624 fp16_optional = 1;
25625 }
25626 }
fa94de6b 25627
ee3c0378 25628 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 25629 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 25630 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 25631
69239280
MGD
25632 /* Tag_DIV_use.
25633
25634 We set Tag_DIV_use to two when integer divide instructions have been used
25635 in ARM state, or when Thumb integer divide instructions have been used,
25636 but we have no architecture profile set, nor have we any ARM instructions.
25637
bca38921
MGD
25638 For ARMv8 we set the tag to 0 as integer divide is implied by the base
25639 architecture.
25640
69239280 25641 For new architectures we will have to check these tests. */
bca38921
MGD
25642 gas_assert (arch <= TAG_CPU_ARCH_V8);
25643 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
25644 aeabi_set_attribute_int (Tag_DIV_use, 0);
25645 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25646 || (profile == '\0'
25647 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25648 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 25649 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
25650
25651 /* Tag_MP_extension_use. */
25652 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25653 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
25654
25655 /* Tag Virtualization_use. */
25656 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
25657 virt_sec |= 1;
25658 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25659 virt_sec |= 2;
25660 if (virt_sec != 0)
25661 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
25662}
25663
104d59d1 25664/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
25665void
25666arm_md_end (void)
25667{
ee065d83
PB
25668 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25669 return;
25670
25671 aeabi_set_public_attributes ();
ee065d83 25672}
8463be01 25673#endif /* OBJ_ELF */
ee065d83
PB
25674
25675
25676/* Parse a .cpu directive. */
25677
25678static void
25679s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25680{
e74cfd16 25681 const struct arm_cpu_option_table *opt;
ee065d83
PB
25682 char *name;
25683 char saved_char;
25684
25685 name = input_line_pointer;
5f4273c7 25686 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25687 input_line_pointer++;
25688 saved_char = *input_line_pointer;
25689 *input_line_pointer = 0;
25690
25691 /* Skip the first "all" entry. */
25692 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25693 if (streq (opt->name, name))
25694 {
e74cfd16
PB
25695 mcpu_cpu_opt = &opt->value;
25696 selected_cpu = opt->value;
ee065d83 25697 if (opt->canonical_name)
5f4273c7 25698 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25699 else
25700 {
25701 int i;
25702 for (i = 0; opt->name[i]; i++)
25703 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 25704
ee065d83
PB
25705 selected_cpu_name[i] = 0;
25706 }
e74cfd16 25707 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25708 *input_line_pointer = saved_char;
25709 demand_empty_rest_of_line ();
25710 return;
25711 }
25712 as_bad (_("unknown cpu `%s'"), name);
25713 *input_line_pointer = saved_char;
25714 ignore_rest_of_line ();
25715}
25716
25717
25718/* Parse a .arch directive. */
25719
25720static void
25721s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25722{
e74cfd16 25723 const struct arm_arch_option_table *opt;
ee065d83
PB
25724 char saved_char;
25725 char *name;
25726
25727 name = input_line_pointer;
5f4273c7 25728 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25729 input_line_pointer++;
25730 saved_char = *input_line_pointer;
25731 *input_line_pointer = 0;
25732
25733 /* Skip the first "all" entry. */
25734 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25735 if (streq (opt->name, name))
25736 {
e74cfd16
PB
25737 mcpu_cpu_opt = &opt->value;
25738 selected_cpu = opt->value;
5f4273c7 25739 strcpy (selected_cpu_name, opt->name);
e74cfd16 25740 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25741 *input_line_pointer = saved_char;
25742 demand_empty_rest_of_line ();
25743 return;
25744 }
25745
25746 as_bad (_("unknown architecture `%s'\n"), name);
25747 *input_line_pointer = saved_char;
25748 ignore_rest_of_line ();
25749}
25750
25751
7a1d4c38
PB
25752/* Parse a .object_arch directive. */
25753
25754static void
25755s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25756{
25757 const struct arm_arch_option_table *opt;
25758 char saved_char;
25759 char *name;
25760
25761 name = input_line_pointer;
5f4273c7 25762 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
25763 input_line_pointer++;
25764 saved_char = *input_line_pointer;
25765 *input_line_pointer = 0;
25766
25767 /* Skip the first "all" entry. */
25768 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25769 if (streq (opt->name, name))
25770 {
25771 object_arch = &opt->value;
25772 *input_line_pointer = saved_char;
25773 demand_empty_rest_of_line ();
25774 return;
25775 }
25776
25777 as_bad (_("unknown architecture `%s'\n"), name);
25778 *input_line_pointer = saved_char;
25779 ignore_rest_of_line ();
25780}
25781
69133863
MGD
25782/* Parse a .arch_extension directive. */
25783
25784static void
25785s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25786{
25787 const struct arm_option_extension_value_table *opt;
25788 char saved_char;
25789 char *name;
25790 int adding_value = 1;
25791
25792 name = input_line_pointer;
25793 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25794 input_line_pointer++;
25795 saved_char = *input_line_pointer;
25796 *input_line_pointer = 0;
25797
25798 if (strlen (name) >= 2
25799 && strncmp (name, "no", 2) == 0)
25800 {
25801 adding_value = 0;
25802 name += 2;
25803 }
25804
25805 for (opt = arm_extensions; opt->name != NULL; opt++)
25806 if (streq (opt->name, name))
25807 {
25808 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25809 {
25810 as_bad (_("architectural extension `%s' is not allowed for the "
25811 "current base architecture"), name);
25812 break;
25813 }
25814
25815 if (adding_value)
5a70a223
JB
25816 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
25817 opt->merge_value);
69133863 25818 else
5a70a223 25819 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
25820
25821 mcpu_cpu_opt = &selected_cpu;
25822 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25823 *input_line_pointer = saved_char;
25824 demand_empty_rest_of_line ();
25825 return;
25826 }
25827
25828 if (opt->name == NULL)
e673710a 25829 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
25830
25831 *input_line_pointer = saved_char;
25832 ignore_rest_of_line ();
25833}
25834
ee065d83
PB
25835/* Parse a .fpu directive. */
25836
25837static void
25838s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
25839{
69133863 25840 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
25841 char saved_char;
25842 char *name;
25843
25844 name = input_line_pointer;
5f4273c7 25845 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25846 input_line_pointer++;
25847 saved_char = *input_line_pointer;
25848 *input_line_pointer = 0;
5f4273c7 25849
ee065d83
PB
25850 for (opt = arm_fpus; opt->name != NULL; opt++)
25851 if (streq (opt->name, name))
25852 {
e74cfd16
PB
25853 mfpu_opt = &opt->value;
25854 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25855 *input_line_pointer = saved_char;
25856 demand_empty_rest_of_line ();
25857 return;
25858 }
25859
25860 as_bad (_("unknown floating point format `%s'\n"), name);
25861 *input_line_pointer = saved_char;
25862 ignore_rest_of_line ();
25863}
ee065d83 25864
794ba86a 25865/* Copy symbol information. */
f31fef98 25866
794ba86a
DJ
25867void
25868arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
25869{
25870 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
25871}
e04befd0 25872
f31fef98 25873#ifdef OBJ_ELF
e04befd0
AS
25874/* Given a symbolic attribute NAME, return the proper integer value.
25875 Returns -1 if the attribute is not known. */
f31fef98 25876
e04befd0
AS
25877int
25878arm_convert_symbolic_attribute (const char *name)
25879{
f31fef98
NC
25880 static const struct
25881 {
25882 const char * name;
25883 const int tag;
25884 }
25885 attribute_table[] =
25886 {
25887 /* When you modify this table you should
25888 also modify the list in doc/c-arm.texi. */
e04befd0 25889#define T(tag) {#tag, tag}
f31fef98
NC
25890 T (Tag_CPU_raw_name),
25891 T (Tag_CPU_name),
25892 T (Tag_CPU_arch),
25893 T (Tag_CPU_arch_profile),
25894 T (Tag_ARM_ISA_use),
25895 T (Tag_THUMB_ISA_use),
75375b3e 25896 T (Tag_FP_arch),
f31fef98
NC
25897 T (Tag_VFP_arch),
25898 T (Tag_WMMX_arch),
25899 T (Tag_Advanced_SIMD_arch),
25900 T (Tag_PCS_config),
25901 T (Tag_ABI_PCS_R9_use),
25902 T (Tag_ABI_PCS_RW_data),
25903 T (Tag_ABI_PCS_RO_data),
25904 T (Tag_ABI_PCS_GOT_use),
25905 T (Tag_ABI_PCS_wchar_t),
25906 T (Tag_ABI_FP_rounding),
25907 T (Tag_ABI_FP_denormal),
25908 T (Tag_ABI_FP_exceptions),
25909 T (Tag_ABI_FP_user_exceptions),
25910 T (Tag_ABI_FP_number_model),
75375b3e 25911 T (Tag_ABI_align_needed),
f31fef98 25912 T (Tag_ABI_align8_needed),
75375b3e 25913 T (Tag_ABI_align_preserved),
f31fef98
NC
25914 T (Tag_ABI_align8_preserved),
25915 T (Tag_ABI_enum_size),
25916 T (Tag_ABI_HardFP_use),
25917 T (Tag_ABI_VFP_args),
25918 T (Tag_ABI_WMMX_args),
25919 T (Tag_ABI_optimization_goals),
25920 T (Tag_ABI_FP_optimization_goals),
25921 T (Tag_compatibility),
25922 T (Tag_CPU_unaligned_access),
75375b3e 25923 T (Tag_FP_HP_extension),
f31fef98
NC
25924 T (Tag_VFP_HP_extension),
25925 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
25926 T (Tag_MPextension_use),
25927 T (Tag_DIV_use),
f31fef98
NC
25928 T (Tag_nodefaults),
25929 T (Tag_also_compatible_with),
25930 T (Tag_conformance),
25931 T (Tag_T2EE_use),
25932 T (Tag_Virtualization_use),
cd21e546 25933 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 25934#undef T
f31fef98 25935 };
e04befd0
AS
25936 unsigned int i;
25937
25938 if (name == NULL)
25939 return -1;
25940
f31fef98 25941 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 25942 if (streq (name, attribute_table[i].name))
e04befd0
AS
25943 return attribute_table[i].tag;
25944
25945 return -1;
25946}
267bf995
RR
25947
25948
93ef582d
NC
25949/* Apply sym value for relocations only in the case that they are for
25950 local symbols in the same segment as the fixup and you have the
25951 respective architectural feature for blx and simple switches. */
267bf995 25952int
93ef582d 25953arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
25954{
25955 if (fixP->fx_addsy
25956 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
25957 /* PR 17444: If the local symbol is in a different section then a reloc
25958 will always be generated for it, so applying the symbol value now
25959 will result in a double offset being stored in the relocation. */
25960 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 25961 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
25962 {
25963 switch (fixP->fx_r_type)
25964 {
25965 case BFD_RELOC_ARM_PCREL_BLX:
25966 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25967 if (ARM_IS_FUNC (fixP->fx_addsy))
25968 return 1;
25969 break;
25970
25971 case BFD_RELOC_ARM_PCREL_CALL:
25972 case BFD_RELOC_THUMB_PCREL_BLX:
25973 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 25974 return 1;
267bf995
RR
25975 break;
25976
25977 default:
25978 break;
25979 }
25980
25981 }
25982 return 0;
25983}
f31fef98 25984#endif /* OBJ_ELF */