]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* gas/config/tc-arm.c (check_obsolete): New function.
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
fa94de6b 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
3da1d841 35#include "libiberty.h"
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3 100/* The code that was here used to select a default CPU depending on compiler
fa94de6b 101 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
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
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
e74cfd16 187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
b2a5fbdc 188static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
bca38921 198static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0);
7e806470 199static const arm_feature_set arm_ext_m =
b2a5fbdc 200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
60e5ef9f 201static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
f4c65163 202static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
b2a5fbdc 203static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
eea54501 204static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
90ec0d68 205static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
e74cfd16
PB
206
207static const arm_feature_set arm_arch_any = ARM_ANY;
208static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
209static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
210static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 211static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 212
2d447fca
JM
213static const arm_feature_set arm_cext_iwmmxt2 =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
215static const arm_feature_set arm_cext_iwmmxt =
216 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
217static const arm_feature_set arm_cext_xscale =
218 ARM_FEATURE (0, ARM_CEXT_XSCALE);
219static const arm_feature_set arm_cext_maverick =
220 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
221static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
222static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
223static const arm_feature_set fpu_vfp_ext_v1xd =
224 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
225static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
226static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 227static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 228static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
229static const arm_feature_set fpu_vfp_ext_d32 =
230 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
231static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
232static const arm_feature_set fpu_vfp_v3_or_neon_ext =
233 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
234static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
235static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
236static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
bca38921
MGD
237static const arm_feature_set fpu_vfp_ext_armv8 =
238 ARM_FEATURE (0, FPU_VFP_EXT_ARMV8);
239static const arm_feature_set fpu_neon_ext_armv8 =
240 ARM_FEATURE (0, FPU_NEON_EXT_ARMV8);
241static const arm_feature_set fpu_crypto_ext_armv8 =
242 ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8);
e74cfd16 243
33a392fb 244static int mfloat_abi_opt = -1;
e74cfd16
PB
245/* Record user cpu selection for object attributes. */
246static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
247/* Must be long enough to hold any of the names in arm_cpus. */
248static char selected_cpu_name[16];
8d67f500
NC
249
250/* Return if no cpu was selected on command-line. */
251static bfd_boolean
252no_cpu_selected (void)
253{
254 return selected_cpu.core == arm_arch_none.core
255 && selected_cpu.coproc == arm_arch_none.coproc;
256}
257
7cc69913 258#ifdef OBJ_ELF
deeaaff8
DJ
259# ifdef EABI_DEFAULT
260static int meabi_flags = EABI_DEFAULT;
261# else
d507cf36 262static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 263# endif
e1da3f5b 264
ee3c0378
AS
265static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
266
e1da3f5b 267bfd_boolean
5f4273c7 268arm_is_eabi (void)
e1da3f5b
PB
269{
270 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
271}
7cc69913 272#endif
b99bd4ef 273
b99bd4ef 274#ifdef OBJ_ELF
c19d1205 275/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
276symbolS * GOT_symbol;
277#endif
278
b99bd4ef
NC
279/* 0: assemble for ARM,
280 1: assemble for Thumb,
281 2: assemble for Thumb even though target CPU does not support thumb
282 instructions. */
283static int thumb_mode = 0;
8dc2430f
NC
284/* A value distinct from the possible values for thumb_mode that we
285 can use to record whether thumb_mode has been copied into the
286 tc_frag_data field of a frag. */
287#define MODE_RECORDED (1 << 4)
b99bd4ef 288
e07e6e58
NC
289/* Specifies the intrinsic IT insn behavior mode. */
290enum implicit_it_mode
291{
292 IMPLICIT_IT_MODE_NEVER = 0x00,
293 IMPLICIT_IT_MODE_ARM = 0x01,
294 IMPLICIT_IT_MODE_THUMB = 0x02,
295 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
296};
297static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
298
c19d1205
ZW
299/* If unified_syntax is true, we are processing the new unified
300 ARM/Thumb syntax. Important differences from the old ARM mode:
301
302 - Immediate operands do not require a # prefix.
303 - Conditional affixes always appear at the end of the
304 instruction. (For backward compatibility, those instructions
305 that formerly had them in the middle, continue to accept them
306 there.)
307 - The IT instruction may appear, and if it does is validated
308 against subsequent conditional affixes. It does not generate
309 machine code.
310
311 Important differences from the old Thumb mode:
312
313 - Immediate operands do not require a # prefix.
314 - Most of the V6T2 instructions are only available in unified mode.
315 - The .N and .W suffixes are recognized and honored (it is an error
316 if they cannot be honored).
317 - All instructions set the flags if and only if they have an 's' affix.
318 - Conditional affixes may be used. They are validated against
319 preceding IT instructions. Unlike ARM mode, you cannot use a
320 conditional affix except in the scope of an IT instruction. */
321
322static bfd_boolean unified_syntax = FALSE;
b99bd4ef 323
5287ad62
JB
324enum neon_el_type
325{
dcbf9037 326 NT_invtype,
5287ad62
JB
327 NT_untyped,
328 NT_integer,
329 NT_float,
330 NT_poly,
331 NT_signed,
dcbf9037 332 NT_unsigned
5287ad62
JB
333};
334
335struct neon_type_el
336{
337 enum neon_el_type type;
338 unsigned size;
339};
340
341#define NEON_MAX_TYPE_ELS 4
342
343struct neon_type
344{
345 struct neon_type_el el[NEON_MAX_TYPE_ELS];
346 unsigned elems;
347};
348
e07e6e58
NC
349enum it_instruction_type
350{
351 OUTSIDE_IT_INSN,
352 INSIDE_IT_INSN,
353 INSIDE_IT_LAST_INSN,
354 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
355 if inside, should be the last one. */
356 NEUTRAL_IT_INSN, /* This could be either inside or outside,
357 i.e. BKPT and NOP. */
358 IT_INSN /* The IT insn has been parsed. */
359};
360
ad6cec43
MGD
361/* The maximum number of operands we need. */
362#define ARM_IT_MAX_OPERANDS 6
363
b99bd4ef
NC
364struct arm_it
365{
c19d1205 366 const char * error;
b99bd4ef 367 unsigned long instruction;
c19d1205
ZW
368 int size;
369 int size_req;
370 int cond;
037e8744
JB
371 /* "uncond_value" is set to the value in place of the conditional field in
372 unconditional versions of the instruction, or -1 if nothing is
373 appropriate. */
374 int uncond_value;
5287ad62 375 struct neon_type vectype;
88714cb8
DG
376 /* This does not indicate an actual NEON instruction, only that
377 the mnemonic accepts neon-style type suffixes. */
378 int is_neon;
0110f2b8
PB
379 /* Set to the opcode if the instruction needs relaxation.
380 Zero if the instruction is not relaxed. */
381 unsigned long relax;
b99bd4ef
NC
382 struct
383 {
384 bfd_reloc_code_real_type type;
c19d1205
ZW
385 expressionS exp;
386 int pc_rel;
b99bd4ef 387 } reloc;
b99bd4ef 388
e07e6e58
NC
389 enum it_instruction_type it_insn_type;
390
c19d1205
ZW
391 struct
392 {
393 unsigned reg;
ca3f61f7 394 signed int imm;
dcbf9037 395 struct neon_type_el vectype;
ca3f61f7
NC
396 unsigned present : 1; /* Operand present. */
397 unsigned isreg : 1; /* Operand was a register. */
398 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
399 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
400 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 401 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
402 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
403 instructions. This allows us to disambiguate ARM <-> vector insns. */
404 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 405 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 406 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 407 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
408 unsigned hasreloc : 1; /* Operand has relocation suffix. */
409 unsigned writeback : 1; /* Operand has trailing ! */
410 unsigned preind : 1; /* Preindexed address. */
411 unsigned postind : 1; /* Postindexed address. */
412 unsigned negative : 1; /* Index register was negated. */
413 unsigned shifted : 1; /* Shift applied to operation. */
414 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 415 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
416};
417
c19d1205 418static struct arm_it inst;
b99bd4ef
NC
419
420#define NUM_FLOAT_VALS 8
421
05d2d07e 422const char * fp_const[] =
b99bd4ef
NC
423{
424 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
425};
426
c19d1205 427/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
428#define MAX_LITTLENUMS 6
429
430LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
431
432#define FAIL (-1)
433#define SUCCESS (0)
434
435#define SUFF_S 1
436#define SUFF_D 2
437#define SUFF_E 3
438#define SUFF_P 4
439
c19d1205
ZW
440#define CP_T_X 0x00008000
441#define CP_T_Y 0x00400000
b99bd4ef 442
c19d1205
ZW
443#define CONDS_BIT 0x00100000
444#define LOAD_BIT 0x00100000
b99bd4ef
NC
445
446#define DOUBLE_LOAD_FLAG 0x00000001
447
448struct asm_cond
449{
d3ce72d0 450 const char * template_name;
c921be7d 451 unsigned long value;
b99bd4ef
NC
452};
453
c19d1205 454#define COND_ALWAYS 0xE
b99bd4ef 455
b99bd4ef
NC
456struct asm_psr
457{
d3ce72d0 458 const char * template_name;
c921be7d 459 unsigned long field;
b99bd4ef
NC
460};
461
62b3e311
PB
462struct asm_barrier_opt
463{
d3ce72d0 464 const char * template_name;
c921be7d 465 unsigned long value;
62b3e311
PB
466};
467
2d2255b5 468/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
469#define SPSR_BIT (1 << 22)
470
c19d1205
ZW
471/* The individual PSR flag bits. */
472#define PSR_c (1 << 16)
473#define PSR_x (1 << 17)
474#define PSR_s (1 << 18)
475#define PSR_f (1 << 19)
b99bd4ef 476
c19d1205 477struct reloc_entry
bfae80f2 478{
c921be7d
NC
479 char * name;
480 bfd_reloc_code_real_type reloc;
bfae80f2
RE
481};
482
5287ad62 483enum vfp_reg_pos
bfae80f2 484{
5287ad62
JB
485 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
486 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
487};
488
489enum vfp_ldstm_type
490{
491 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
492};
493
dcbf9037
JB
494/* Bits for DEFINED field in neon_typed_alias. */
495#define NTA_HASTYPE 1
496#define NTA_HASINDEX 2
497
498struct neon_typed_alias
499{
c921be7d
NC
500 unsigned char defined;
501 unsigned char index;
502 struct neon_type_el eltype;
dcbf9037
JB
503};
504
c19d1205
ZW
505/* ARM register categories. This includes coprocessor numbers and various
506 architecture extensions' registers. */
507enum arm_reg_type
bfae80f2 508{
c19d1205
ZW
509 REG_TYPE_RN,
510 REG_TYPE_CP,
511 REG_TYPE_CN,
512 REG_TYPE_FN,
513 REG_TYPE_VFS,
514 REG_TYPE_VFD,
5287ad62 515 REG_TYPE_NQ,
037e8744 516 REG_TYPE_VFSD,
5287ad62 517 REG_TYPE_NDQ,
037e8744 518 REG_TYPE_NSDQ,
c19d1205
ZW
519 REG_TYPE_VFC,
520 REG_TYPE_MVF,
521 REG_TYPE_MVD,
522 REG_TYPE_MVFX,
523 REG_TYPE_MVDX,
524 REG_TYPE_MVAX,
525 REG_TYPE_DSPSC,
526 REG_TYPE_MMXWR,
527 REG_TYPE_MMXWC,
528 REG_TYPE_MMXWCG,
529 REG_TYPE_XSCALE,
90ec0d68 530 REG_TYPE_RNB
bfae80f2
RE
531};
532
dcbf9037
JB
533/* Structure for a hash table entry for a register.
534 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
535 information which states whether a vector type or index is specified (for a
536 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
537struct reg_entry
538{
c921be7d 539 const char * name;
90ec0d68 540 unsigned int number;
c921be7d
NC
541 unsigned char type;
542 unsigned char builtin;
543 struct neon_typed_alias * neon;
6c43fab6
RE
544};
545
c19d1205 546/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 547const char * const reg_expected_msgs[] =
c19d1205
ZW
548{
549 N_("ARM register expected"),
550 N_("bad or missing co-processor number"),
551 N_("co-processor register expected"),
552 N_("FPA register expected"),
553 N_("VFP single precision register expected"),
5287ad62
JB
554 N_("VFP/Neon double precision register expected"),
555 N_("Neon quad precision register expected"),
037e8744 556 N_("VFP single or double precision register expected"),
5287ad62 557 N_("Neon double or quad precision register expected"),
037e8744 558 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
559 N_("VFP system register expected"),
560 N_("Maverick MVF register expected"),
561 N_("Maverick MVD register expected"),
562 N_("Maverick MVFX register expected"),
563 N_("Maverick MVDX register expected"),
564 N_("Maverick MVAX register expected"),
565 N_("Maverick DSPSC register expected"),
566 N_("iWMMXt data register expected"),
567 N_("iWMMXt control register expected"),
568 N_("iWMMXt scalar register expected"),
569 N_("XScale accumulator register expected"),
6c43fab6
RE
570};
571
c19d1205 572/* Some well known registers that we refer to directly elsewhere. */
bd340a04 573#define REG_R12 12
c19d1205
ZW
574#define REG_SP 13
575#define REG_LR 14
576#define REG_PC 15
404ff6b5 577
b99bd4ef
NC
578/* ARM instructions take 4bytes in the object file, Thumb instructions
579 take 2: */
c19d1205 580#define INSN_SIZE 4
b99bd4ef
NC
581
582struct asm_opcode
583{
584 /* Basic string to match. */
d3ce72d0 585 const char * template_name;
c19d1205
ZW
586
587 /* Parameters to instruction. */
5be8be5d 588 unsigned int operands[8];
c19d1205
ZW
589
590 /* Conditional tag - see opcode_lookup. */
591 unsigned int tag : 4;
b99bd4ef
NC
592
593 /* Basic instruction code. */
c19d1205 594 unsigned int avalue : 28;
b99bd4ef 595
c19d1205
ZW
596 /* Thumb-format instruction code. */
597 unsigned int tvalue;
b99bd4ef 598
90e4755a 599 /* Which architecture variant provides this instruction. */
c921be7d
NC
600 const arm_feature_set * avariant;
601 const arm_feature_set * tvariant;
c19d1205
ZW
602
603 /* Function to call to encode instruction in ARM format. */
604 void (* aencode) (void);
b99bd4ef 605
c19d1205
ZW
606 /* Function to call to encode instruction in Thumb format. */
607 void (* tencode) (void);
b99bd4ef
NC
608};
609
a737bd4d
NC
610/* Defines for various bits that we will want to toggle. */
611#define INST_IMMEDIATE 0x02000000
612#define OFFSET_REG 0x02000000
c19d1205 613#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
614#define SHIFT_BY_REG 0x00000010
615#define PRE_INDEX 0x01000000
616#define INDEX_UP 0x00800000
617#define WRITE_BACK 0x00200000
618#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 619#define CPSI_MMOD 0x00020000
90e4755a 620
a737bd4d
NC
621#define LITERAL_MASK 0xf000f000
622#define OPCODE_MASK 0xfe1fffff
623#define V4_STR_BIT 0x00000020
90e4755a 624
efd81785
PB
625#define T2_SUBS_PC_LR 0xf3de8f00
626
a737bd4d 627#define DATA_OP_SHIFT 21
90e4755a 628
ef8d22e6
PB
629#define T2_OPCODE_MASK 0xfe1fffff
630#define T2_DATA_OP_SHIFT 21
631
6530b175
NC
632#define A_COND_MASK 0xf0000000
633#define A_PUSH_POP_OP_MASK 0x0fff0000
634
635/* Opcodes for pushing/poping registers to/from the stack. */
636#define A1_OPCODE_PUSH 0x092d0000
637#define A2_OPCODE_PUSH 0x052d0004
638#define A2_OPCODE_POP 0x049d0004
639
a737bd4d
NC
640/* Codes to distinguish the arithmetic instructions. */
641#define OPCODE_AND 0
642#define OPCODE_EOR 1
643#define OPCODE_SUB 2
644#define OPCODE_RSB 3
645#define OPCODE_ADD 4
646#define OPCODE_ADC 5
647#define OPCODE_SBC 6
648#define OPCODE_RSC 7
649#define OPCODE_TST 8
650#define OPCODE_TEQ 9
651#define OPCODE_CMP 10
652#define OPCODE_CMN 11
653#define OPCODE_ORR 12
654#define OPCODE_MOV 13
655#define OPCODE_BIC 14
656#define OPCODE_MVN 15
90e4755a 657
ef8d22e6
PB
658#define T2_OPCODE_AND 0
659#define T2_OPCODE_BIC 1
660#define T2_OPCODE_ORR 2
661#define T2_OPCODE_ORN 3
662#define T2_OPCODE_EOR 4
663#define T2_OPCODE_ADD 8
664#define T2_OPCODE_ADC 10
665#define T2_OPCODE_SBC 11
666#define T2_OPCODE_SUB 13
667#define T2_OPCODE_RSB 14
668
a737bd4d
NC
669#define T_OPCODE_MUL 0x4340
670#define T_OPCODE_TST 0x4200
671#define T_OPCODE_CMN 0x42c0
672#define T_OPCODE_NEG 0x4240
673#define T_OPCODE_MVN 0x43c0
90e4755a 674
a737bd4d
NC
675#define T_OPCODE_ADD_R3 0x1800
676#define T_OPCODE_SUB_R3 0x1a00
677#define T_OPCODE_ADD_HI 0x4400
678#define T_OPCODE_ADD_ST 0xb000
679#define T_OPCODE_SUB_ST 0xb080
680#define T_OPCODE_ADD_SP 0xa800
681#define T_OPCODE_ADD_PC 0xa000
682#define T_OPCODE_ADD_I8 0x3000
683#define T_OPCODE_SUB_I8 0x3800
684#define T_OPCODE_ADD_I3 0x1c00
685#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 686
a737bd4d
NC
687#define T_OPCODE_ASR_R 0x4100
688#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
689#define T_OPCODE_LSR_R 0x40c0
690#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
691#define T_OPCODE_ASR_I 0x1000
692#define T_OPCODE_LSL_I 0x0000
693#define T_OPCODE_LSR_I 0x0800
b99bd4ef 694
a737bd4d
NC
695#define T_OPCODE_MOV_I8 0x2000
696#define T_OPCODE_CMP_I8 0x2800
697#define T_OPCODE_CMP_LR 0x4280
698#define T_OPCODE_MOV_HR 0x4600
699#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 700
a737bd4d
NC
701#define T_OPCODE_LDR_PC 0x4800
702#define T_OPCODE_LDR_SP 0x9800
703#define T_OPCODE_STR_SP 0x9000
704#define T_OPCODE_LDR_IW 0x6800
705#define T_OPCODE_STR_IW 0x6000
706#define T_OPCODE_LDR_IH 0x8800
707#define T_OPCODE_STR_IH 0x8000
708#define T_OPCODE_LDR_IB 0x7800
709#define T_OPCODE_STR_IB 0x7000
710#define T_OPCODE_LDR_RW 0x5800
711#define T_OPCODE_STR_RW 0x5000
712#define T_OPCODE_LDR_RH 0x5a00
713#define T_OPCODE_STR_RH 0x5200
714#define T_OPCODE_LDR_RB 0x5c00
715#define T_OPCODE_STR_RB 0x5400
c9b604bd 716
a737bd4d
NC
717#define T_OPCODE_PUSH 0xb400
718#define T_OPCODE_POP 0xbc00
b99bd4ef 719
2fc8bdac 720#define T_OPCODE_BRANCH 0xe000
b99bd4ef 721
a737bd4d 722#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 723#define THUMB_PP_PC_LR 0x0100
c19d1205 724#define THUMB_LOAD_BIT 0x0800
53365c0d 725#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
726
727#define BAD_ARGS _("bad arguments to instruction")
fdfde340 728#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
729#define BAD_PC _("r15 not allowed here")
730#define BAD_COND _("instruction cannot be conditional")
731#define BAD_OVERLAP _("registers may not be the same")
732#define BAD_HIREG _("lo register required")
733#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 734#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
735#define BAD_BRANCH _("branch must be last instruction in IT block")
736#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 737#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
738#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
739#define BAD_IT_COND _("incorrect condition in IT block")
740#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 741#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
742#define BAD_PC_ADDRESSING \
743 _("cannot use register index with PC-relative addressing")
744#define BAD_PC_WRITEBACK \
745 _("cannot use writeback with PC-relative addressing")
08f10d51 746#define BAD_RANGE _("branch out of range")
c19d1205 747
c921be7d
NC
748static struct hash_control * arm_ops_hsh;
749static struct hash_control * arm_cond_hsh;
750static struct hash_control * arm_shift_hsh;
751static struct hash_control * arm_psr_hsh;
752static struct hash_control * arm_v7m_psr_hsh;
753static struct hash_control * arm_reg_hsh;
754static struct hash_control * arm_reloc_hsh;
755static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 756
b99bd4ef
NC
757/* Stuff needed to resolve the label ambiguity
758 As:
759 ...
760 label: <insn>
761 may differ from:
762 ...
763 label:
5f4273c7 764 <insn> */
b99bd4ef
NC
765
766symbolS * last_label_seen;
b34976b6 767static int label_is_thumb_function_name = FALSE;
e07e6e58 768
3d0c9500
NC
769/* Literal pool structure. Held on a per-section
770 and per-sub-section basis. */
a737bd4d 771
c19d1205 772#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 773typedef struct literal_pool
b99bd4ef 774{
c921be7d
NC
775 expressionS literals [MAX_LITERAL_POOL_SIZE];
776 unsigned int next_free_entry;
777 unsigned int id;
778 symbolS * symbol;
779 segT section;
780 subsegT sub_section;
a8040cf2
NC
781#ifdef OBJ_ELF
782 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
783#endif
c921be7d 784 struct literal_pool * next;
3d0c9500 785} literal_pool;
b99bd4ef 786
3d0c9500
NC
787/* Pointer to a linked list of literal pools. */
788literal_pool * list_of_pools = NULL;
e27ec89e 789
e07e6e58
NC
790#ifdef OBJ_ELF
791# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
792#else
793static struct current_it now_it;
794#endif
795
796static inline int
797now_it_compatible (int cond)
798{
799 return (cond & ~1) == (now_it.cc & ~1);
800}
801
802static inline int
803conditional_insn (void)
804{
805 return inst.cond != COND_ALWAYS;
806}
807
808static int in_it_block (void);
809
810static int handle_it_state (void);
811
812static void force_automatic_it_block_close (void);
813
c921be7d
NC
814static void it_fsm_post_encode (void);
815
e07e6e58
NC
816#define set_it_insn_type(type) \
817 do \
818 { \
819 inst.it_insn_type = type; \
820 if (handle_it_state () == FAIL) \
821 return; \
822 } \
823 while (0)
824
c921be7d
NC
825#define set_it_insn_type_nonvoid(type, failret) \
826 do \
827 { \
828 inst.it_insn_type = type; \
829 if (handle_it_state () == FAIL) \
830 return failret; \
831 } \
832 while(0)
833
e07e6e58
NC
834#define set_it_insn_type_last() \
835 do \
836 { \
837 if (inst.cond == COND_ALWAYS) \
838 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
839 else \
840 set_it_insn_type (INSIDE_IT_LAST_INSN); \
841 } \
842 while (0)
843
c19d1205 844/* Pure syntax. */
b99bd4ef 845
c19d1205
ZW
846/* This array holds the chars that always start a comment. If the
847 pre-processor is disabled, these aren't very useful. */
848const char comment_chars[] = "@";
3d0c9500 849
c19d1205
ZW
850/* This array holds the chars that only start a comment at the beginning of
851 a line. If the line seems to have the form '# 123 filename'
852 .line and .file directives will appear in the pre-processed output. */
853/* Note that input_file.c hand checks for '#' at the beginning of the
854 first line of the input file. This is because the compiler outputs
855 #NO_APP at the beginning of its output. */
856/* Also note that comments like this one will always work. */
857const char line_comment_chars[] = "#";
3d0c9500 858
c19d1205 859const char line_separator_chars[] = ";";
b99bd4ef 860
c19d1205
ZW
861/* Chars that can be used to separate mant
862 from exp in floating point numbers. */
863const char EXP_CHARS[] = "eE";
3d0c9500 864
c19d1205
ZW
865/* Chars that mean this number is a floating point constant. */
866/* As in 0f12.456 */
867/* or 0d1.2345e12 */
b99bd4ef 868
c19d1205 869const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 870
c19d1205
ZW
871/* Prefix characters that indicate the start of an immediate
872 value. */
873#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 874
c19d1205
ZW
875/* Separator character handling. */
876
877#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
878
879static inline int
880skip_past_char (char ** str, char c)
881{
882 if (**str == c)
883 {
884 (*str)++;
885 return SUCCESS;
3d0c9500 886 }
c19d1205
ZW
887 else
888 return FAIL;
889}
c921be7d 890
c19d1205 891#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 892
c19d1205
ZW
893/* Arithmetic expressions (possibly involving symbols). */
894
895/* Return TRUE if anything in the expression is a bignum. */
896
897static int
898walk_no_bignums (symbolS * sp)
899{
900 if (symbol_get_value_expression (sp)->X_op == O_big)
901 return 1;
902
903 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 904 {
c19d1205
ZW
905 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
906 || (symbol_get_value_expression (sp)->X_op_symbol
907 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
908 }
909
c19d1205 910 return 0;
3d0c9500
NC
911}
912
c19d1205
ZW
913static int in_my_get_expression = 0;
914
915/* Third argument to my_get_expression. */
916#define GE_NO_PREFIX 0
917#define GE_IMM_PREFIX 1
918#define GE_OPT_PREFIX 2
5287ad62
JB
919/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
920 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
921#define GE_OPT_PREFIX_BIG 3
a737bd4d 922
b99bd4ef 923static int
c19d1205 924my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 925{
c19d1205
ZW
926 char * save_in;
927 segT seg;
b99bd4ef 928
c19d1205
ZW
929 /* In unified syntax, all prefixes are optional. */
930 if (unified_syntax)
5287ad62
JB
931 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
932 : GE_OPT_PREFIX;
b99bd4ef 933
c19d1205 934 switch (prefix_mode)
b99bd4ef 935 {
c19d1205
ZW
936 case GE_NO_PREFIX: break;
937 case GE_IMM_PREFIX:
938 if (!is_immediate_prefix (**str))
939 {
940 inst.error = _("immediate expression requires a # prefix");
941 return FAIL;
942 }
943 (*str)++;
944 break;
945 case GE_OPT_PREFIX:
5287ad62 946 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
947 if (is_immediate_prefix (**str))
948 (*str)++;
949 break;
950 default: abort ();
951 }
b99bd4ef 952
c19d1205 953 memset (ep, 0, sizeof (expressionS));
b99bd4ef 954
c19d1205
ZW
955 save_in = input_line_pointer;
956 input_line_pointer = *str;
957 in_my_get_expression = 1;
958 seg = expression (ep);
959 in_my_get_expression = 0;
960
f86adc07 961 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 962 {
f86adc07 963 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
964 *str = input_line_pointer;
965 input_line_pointer = save_in;
966 if (inst.error == NULL)
f86adc07
NS
967 inst.error = (ep->X_op == O_absent
968 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
969 return 1;
970 }
b99bd4ef 971
c19d1205
ZW
972#ifdef OBJ_AOUT
973 if (seg != absolute_section
974 && seg != text_section
975 && seg != data_section
976 && seg != bss_section
977 && seg != undefined_section)
978 {
979 inst.error = _("bad segment");
980 *str = input_line_pointer;
981 input_line_pointer = save_in;
982 return 1;
b99bd4ef 983 }
87975d2a
AM
984#else
985 (void) seg;
c19d1205 986#endif
b99bd4ef 987
c19d1205
ZW
988 /* Get rid of any bignums now, so that we don't generate an error for which
989 we can't establish a line number later on. Big numbers are never valid
990 in instructions, which is where this routine is always called. */
5287ad62
JB
991 if (prefix_mode != GE_OPT_PREFIX_BIG
992 && (ep->X_op == O_big
993 || (ep->X_add_symbol
994 && (walk_no_bignums (ep->X_add_symbol)
995 || (ep->X_op_symbol
996 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
997 {
998 inst.error = _("invalid constant");
999 *str = input_line_pointer;
1000 input_line_pointer = save_in;
1001 return 1;
1002 }
b99bd4ef 1003
c19d1205
ZW
1004 *str = input_line_pointer;
1005 input_line_pointer = save_in;
1006 return 0;
b99bd4ef
NC
1007}
1008
c19d1205
ZW
1009/* Turn a string in input_line_pointer into a floating point constant
1010 of type TYPE, and store the appropriate bytes in *LITP. The number
1011 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1012 returned, or NULL on OK.
b99bd4ef 1013
c19d1205
ZW
1014 Note that fp constants aren't represent in the normal way on the ARM.
1015 In big endian mode, things are as expected. However, in little endian
1016 mode fp constants are big-endian word-wise, and little-endian byte-wise
1017 within the words. For example, (double) 1.1 in big endian mode is
1018 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1019 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1020
c19d1205 1021 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1022
c19d1205
ZW
1023char *
1024md_atof (int type, char * litP, int * sizeP)
1025{
1026 int prec;
1027 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1028 char *t;
1029 int i;
b99bd4ef 1030
c19d1205
ZW
1031 switch (type)
1032 {
1033 case 'f':
1034 case 'F':
1035 case 's':
1036 case 'S':
1037 prec = 2;
1038 break;
b99bd4ef 1039
c19d1205
ZW
1040 case 'd':
1041 case 'D':
1042 case 'r':
1043 case 'R':
1044 prec = 4;
1045 break;
b99bd4ef 1046
c19d1205
ZW
1047 case 'x':
1048 case 'X':
499ac353 1049 prec = 5;
c19d1205 1050 break;
b99bd4ef 1051
c19d1205
ZW
1052 case 'p':
1053 case 'P':
499ac353 1054 prec = 5;
c19d1205 1055 break;
a737bd4d 1056
c19d1205
ZW
1057 default:
1058 *sizeP = 0;
499ac353 1059 return _("Unrecognized or unsupported floating point constant");
c19d1205 1060 }
b99bd4ef 1061
c19d1205
ZW
1062 t = atof_ieee (input_line_pointer, type, words);
1063 if (t)
1064 input_line_pointer = t;
499ac353 1065 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1066
c19d1205
ZW
1067 if (target_big_endian)
1068 {
1069 for (i = 0; i < prec; i++)
1070 {
499ac353
NC
1071 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1072 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1073 }
1074 }
1075 else
1076 {
e74cfd16 1077 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1078 for (i = prec - 1; i >= 0; i--)
1079 {
499ac353
NC
1080 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1081 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1082 }
1083 else
1084 /* For a 4 byte float the order of elements in `words' is 1 0.
1085 For an 8 byte float the order is 1 0 3 2. */
1086 for (i = 0; i < prec; i += 2)
1087 {
499ac353
NC
1088 md_number_to_chars (litP, (valueT) words[i + 1],
1089 sizeof (LITTLENUM_TYPE));
1090 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1091 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1092 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1093 }
1094 }
b99bd4ef 1095
499ac353 1096 return NULL;
c19d1205 1097}
b99bd4ef 1098
c19d1205
ZW
1099/* We handle all bad expressions here, so that we can report the faulty
1100 instruction in the error message. */
1101void
91d6fa6a 1102md_operand (expressionS * exp)
c19d1205
ZW
1103{
1104 if (in_my_get_expression)
91d6fa6a 1105 exp->X_op = O_illegal;
b99bd4ef
NC
1106}
1107
c19d1205 1108/* Immediate values. */
b99bd4ef 1109
c19d1205
ZW
1110/* Generic immediate-value read function for use in directives.
1111 Accepts anything that 'expression' can fold to a constant.
1112 *val receives the number. */
1113#ifdef OBJ_ELF
1114static int
1115immediate_for_directive (int *val)
b99bd4ef 1116{
c19d1205
ZW
1117 expressionS exp;
1118 exp.X_op = O_illegal;
b99bd4ef 1119
c19d1205
ZW
1120 if (is_immediate_prefix (*input_line_pointer))
1121 {
1122 input_line_pointer++;
1123 expression (&exp);
1124 }
b99bd4ef 1125
c19d1205
ZW
1126 if (exp.X_op != O_constant)
1127 {
1128 as_bad (_("expected #constant"));
1129 ignore_rest_of_line ();
1130 return FAIL;
1131 }
1132 *val = exp.X_add_number;
1133 return SUCCESS;
b99bd4ef 1134}
c19d1205 1135#endif
b99bd4ef 1136
c19d1205 1137/* Register parsing. */
b99bd4ef 1138
c19d1205
ZW
1139/* Generic register parser. CCP points to what should be the
1140 beginning of a register name. If it is indeed a valid register
1141 name, advance CCP over it and return the reg_entry structure;
1142 otherwise return NULL. Does not issue diagnostics. */
1143
1144static struct reg_entry *
1145arm_reg_parse_multi (char **ccp)
b99bd4ef 1146{
c19d1205
ZW
1147 char *start = *ccp;
1148 char *p;
1149 struct reg_entry *reg;
b99bd4ef 1150
c19d1205
ZW
1151#ifdef REGISTER_PREFIX
1152 if (*start != REGISTER_PREFIX)
01cfc07f 1153 return NULL;
c19d1205
ZW
1154 start++;
1155#endif
1156#ifdef OPTIONAL_REGISTER_PREFIX
1157 if (*start == OPTIONAL_REGISTER_PREFIX)
1158 start++;
1159#endif
b99bd4ef 1160
c19d1205
ZW
1161 p = start;
1162 if (!ISALPHA (*p) || !is_name_beginner (*p))
1163 return NULL;
b99bd4ef 1164
c19d1205
ZW
1165 do
1166 p++;
1167 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1168
1169 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1170
1171 if (!reg)
1172 return NULL;
1173
1174 *ccp = p;
1175 return reg;
b99bd4ef
NC
1176}
1177
1178static int
dcbf9037
JB
1179arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1180 enum arm_reg_type type)
b99bd4ef 1181{
c19d1205
ZW
1182 /* Alternative syntaxes are accepted for a few register classes. */
1183 switch (type)
1184 {
1185 case REG_TYPE_MVF:
1186 case REG_TYPE_MVD:
1187 case REG_TYPE_MVFX:
1188 case REG_TYPE_MVDX:
1189 /* Generic coprocessor register names are allowed for these. */
79134647 1190 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1191 return reg->number;
1192 break;
69b97547 1193
c19d1205
ZW
1194 case REG_TYPE_CP:
1195 /* For backward compatibility, a bare number is valid here. */
1196 {
1197 unsigned long processor = strtoul (start, ccp, 10);
1198 if (*ccp != start && processor <= 15)
1199 return processor;
1200 }
6057a28f 1201
c19d1205
ZW
1202 case REG_TYPE_MMXWC:
1203 /* WC includes WCG. ??? I'm not sure this is true for all
1204 instructions that take WC registers. */
79134647 1205 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1206 return reg->number;
6057a28f 1207 break;
c19d1205 1208
6057a28f 1209 default:
c19d1205 1210 break;
6057a28f
NC
1211 }
1212
dcbf9037
JB
1213 return FAIL;
1214}
1215
1216/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1217 return value is the register number or FAIL. */
1218
1219static int
1220arm_reg_parse (char **ccp, enum arm_reg_type type)
1221{
1222 char *start = *ccp;
1223 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1224 int ret;
1225
1226 /* Do not allow a scalar (reg+index) to parse as a register. */
1227 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1228 return FAIL;
1229
1230 if (reg && reg->type == type)
1231 return reg->number;
1232
1233 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1234 return ret;
1235
c19d1205
ZW
1236 *ccp = start;
1237 return FAIL;
1238}
69b97547 1239
dcbf9037
JB
1240/* Parse a Neon type specifier. *STR should point at the leading '.'
1241 character. Does no verification at this stage that the type fits the opcode
1242 properly. E.g.,
1243
1244 .i32.i32.s16
1245 .s32.f32
1246 .u16
1247
1248 Can all be legally parsed by this function.
1249
1250 Fills in neon_type struct pointer with parsed information, and updates STR
1251 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1252 type, FAIL if not. */
1253
1254static int
1255parse_neon_type (struct neon_type *type, char **str)
1256{
1257 char *ptr = *str;
1258
1259 if (type)
1260 type->elems = 0;
1261
1262 while (type->elems < NEON_MAX_TYPE_ELS)
1263 {
1264 enum neon_el_type thistype = NT_untyped;
1265 unsigned thissize = -1u;
1266
1267 if (*ptr != '.')
1268 break;
1269
1270 ptr++;
1271
1272 /* Just a size without an explicit type. */
1273 if (ISDIGIT (*ptr))
1274 goto parsesize;
1275
1276 switch (TOLOWER (*ptr))
1277 {
1278 case 'i': thistype = NT_integer; break;
1279 case 'f': thistype = NT_float; break;
1280 case 'p': thistype = NT_poly; break;
1281 case 's': thistype = NT_signed; break;
1282 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1283 case 'd':
1284 thistype = NT_float;
1285 thissize = 64;
1286 ptr++;
1287 goto done;
dcbf9037
JB
1288 default:
1289 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1290 return FAIL;
1291 }
1292
1293 ptr++;
1294
1295 /* .f is an abbreviation for .f32. */
1296 if (thistype == NT_float && !ISDIGIT (*ptr))
1297 thissize = 32;
1298 else
1299 {
1300 parsesize:
1301 thissize = strtoul (ptr, &ptr, 10);
1302
1303 if (thissize != 8 && thissize != 16 && thissize != 32
1304 && thissize != 64)
1305 {
1306 as_bad (_("bad size %d in type specifier"), thissize);
1307 return FAIL;
1308 }
1309 }
1310
037e8744 1311 done:
dcbf9037
JB
1312 if (type)
1313 {
1314 type->el[type->elems].type = thistype;
1315 type->el[type->elems].size = thissize;
1316 type->elems++;
1317 }
1318 }
1319
1320 /* Empty/missing type is not a successful parse. */
1321 if (type->elems == 0)
1322 return FAIL;
1323
1324 *str = ptr;
1325
1326 return SUCCESS;
1327}
1328
1329/* Errors may be set multiple times during parsing or bit encoding
1330 (particularly in the Neon bits), but usually the earliest error which is set
1331 will be the most meaningful. Avoid overwriting it with later (cascading)
1332 errors by calling this function. */
1333
1334static void
1335first_error (const char *err)
1336{
1337 if (!inst.error)
1338 inst.error = err;
1339}
1340
1341/* Parse a single type, e.g. ".s32", leading period included. */
1342static int
1343parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1344{
1345 char *str = *ccp;
1346 struct neon_type optype;
1347
1348 if (*str == '.')
1349 {
1350 if (parse_neon_type (&optype, &str) == SUCCESS)
1351 {
1352 if (optype.elems == 1)
1353 *vectype = optype.el[0];
1354 else
1355 {
1356 first_error (_("only one type should be specified for operand"));
1357 return FAIL;
1358 }
1359 }
1360 else
1361 {
1362 first_error (_("vector type expected"));
1363 return FAIL;
1364 }
1365 }
1366 else
1367 return FAIL;
5f4273c7 1368
dcbf9037 1369 *ccp = str;
5f4273c7 1370
dcbf9037
JB
1371 return SUCCESS;
1372}
1373
1374/* Special meanings for indices (which have a range of 0-7), which will fit into
1375 a 4-bit integer. */
1376
1377#define NEON_ALL_LANES 15
1378#define NEON_INTERLEAVE_LANES 14
1379
1380/* Parse either a register or a scalar, with an optional type. Return the
1381 register number, and optionally fill in the actual type of the register
1382 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1383 type/index information in *TYPEINFO. */
1384
1385static int
1386parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1387 enum arm_reg_type *rtype,
1388 struct neon_typed_alias *typeinfo)
1389{
1390 char *str = *ccp;
1391 struct reg_entry *reg = arm_reg_parse_multi (&str);
1392 struct neon_typed_alias atype;
1393 struct neon_type_el parsetype;
1394
1395 atype.defined = 0;
1396 atype.index = -1;
1397 atype.eltype.type = NT_invtype;
1398 atype.eltype.size = -1;
1399
1400 /* Try alternate syntax for some types of register. Note these are mutually
1401 exclusive with the Neon syntax extensions. */
1402 if (reg == NULL)
1403 {
1404 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1405 if (altreg != FAIL)
1406 *ccp = str;
1407 if (typeinfo)
1408 *typeinfo = atype;
1409 return altreg;
1410 }
1411
037e8744
JB
1412 /* Undo polymorphism when a set of register types may be accepted. */
1413 if ((type == REG_TYPE_NDQ
1414 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1415 || (type == REG_TYPE_VFSD
1416 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1417 || (type == REG_TYPE_NSDQ
1418 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1419 || reg->type == REG_TYPE_NQ))
1420 || (type == REG_TYPE_MMXWC
1421 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1422 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1423
1424 if (type != reg->type)
1425 return FAIL;
1426
1427 if (reg->neon)
1428 atype = *reg->neon;
5f4273c7 1429
dcbf9037
JB
1430 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1431 {
1432 if ((atype.defined & NTA_HASTYPE) != 0)
1433 {
1434 first_error (_("can't redefine type for operand"));
1435 return FAIL;
1436 }
1437 atype.defined |= NTA_HASTYPE;
1438 atype.eltype = parsetype;
1439 }
5f4273c7 1440
dcbf9037
JB
1441 if (skip_past_char (&str, '[') == SUCCESS)
1442 {
1443 if (type != REG_TYPE_VFD)
1444 {
1445 first_error (_("only D registers may be indexed"));
1446 return FAIL;
1447 }
5f4273c7 1448
dcbf9037
JB
1449 if ((atype.defined & NTA_HASINDEX) != 0)
1450 {
1451 first_error (_("can't change index for operand"));
1452 return FAIL;
1453 }
1454
1455 atype.defined |= NTA_HASINDEX;
1456
1457 if (skip_past_char (&str, ']') == SUCCESS)
1458 atype.index = NEON_ALL_LANES;
1459 else
1460 {
1461 expressionS exp;
1462
1463 my_get_expression (&exp, &str, GE_NO_PREFIX);
1464
1465 if (exp.X_op != O_constant)
1466 {
1467 first_error (_("constant expression required"));
1468 return FAIL;
1469 }
1470
1471 if (skip_past_char (&str, ']') == FAIL)
1472 return FAIL;
1473
1474 atype.index = exp.X_add_number;
1475 }
1476 }
5f4273c7 1477
dcbf9037
JB
1478 if (typeinfo)
1479 *typeinfo = atype;
5f4273c7 1480
dcbf9037
JB
1481 if (rtype)
1482 *rtype = type;
5f4273c7 1483
dcbf9037 1484 *ccp = str;
5f4273c7 1485
dcbf9037
JB
1486 return reg->number;
1487}
1488
1489/* Like arm_reg_parse, but allow allow the following extra features:
1490 - If RTYPE is non-zero, return the (possibly restricted) type of the
1491 register (e.g. Neon double or quad reg when either has been requested).
1492 - If this is a Neon vector type with additional type information, fill
1493 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1494 This function will fault on encountering a scalar. */
dcbf9037
JB
1495
1496static int
1497arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1498 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1499{
1500 struct neon_typed_alias atype;
1501 char *str = *ccp;
1502 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1503
1504 if (reg == FAIL)
1505 return FAIL;
1506
0855e32b
NS
1507 /* Do not allow regname(... to parse as a register. */
1508 if (*str == '(')
1509 return FAIL;
1510
dcbf9037
JB
1511 /* Do not allow a scalar (reg+index) to parse as a register. */
1512 if ((atype.defined & NTA_HASINDEX) != 0)
1513 {
1514 first_error (_("register operand expected, but got scalar"));
1515 return FAIL;
1516 }
1517
1518 if (vectype)
1519 *vectype = atype.eltype;
1520
1521 *ccp = str;
1522
1523 return reg;
1524}
1525
1526#define NEON_SCALAR_REG(X) ((X) >> 4)
1527#define NEON_SCALAR_INDEX(X) ((X) & 15)
1528
5287ad62
JB
1529/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1530 have enough information to be able to do a good job bounds-checking. So, we
1531 just do easy checks here, and do further checks later. */
1532
1533static int
dcbf9037 1534parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1535{
dcbf9037 1536 int reg;
5287ad62 1537 char *str = *ccp;
dcbf9037 1538 struct neon_typed_alias atype;
5f4273c7 1539
dcbf9037 1540 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1541
dcbf9037 1542 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1543 return FAIL;
5f4273c7 1544
dcbf9037 1545 if (atype.index == NEON_ALL_LANES)
5287ad62 1546 {
dcbf9037 1547 first_error (_("scalar must have an index"));
5287ad62
JB
1548 return FAIL;
1549 }
dcbf9037 1550 else if (atype.index >= 64 / elsize)
5287ad62 1551 {
dcbf9037 1552 first_error (_("scalar index out of range"));
5287ad62
JB
1553 return FAIL;
1554 }
5f4273c7 1555
dcbf9037
JB
1556 if (type)
1557 *type = atype.eltype;
5f4273c7 1558
5287ad62 1559 *ccp = str;
5f4273c7 1560
dcbf9037 1561 return reg * 16 + atype.index;
5287ad62
JB
1562}
1563
c19d1205 1564/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1565
c19d1205
ZW
1566static long
1567parse_reg_list (char ** strp)
1568{
1569 char * str = * strp;
1570 long range = 0;
1571 int another_range;
a737bd4d 1572
c19d1205
ZW
1573 /* We come back here if we get ranges concatenated by '+' or '|'. */
1574 do
6057a28f 1575 {
c19d1205 1576 another_range = 0;
a737bd4d 1577
c19d1205
ZW
1578 if (*str == '{')
1579 {
1580 int in_range = 0;
1581 int cur_reg = -1;
a737bd4d 1582
c19d1205
ZW
1583 str++;
1584 do
1585 {
1586 int reg;
6057a28f 1587
dcbf9037 1588 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1589 {
dcbf9037 1590 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1591 return FAIL;
1592 }
a737bd4d 1593
c19d1205
ZW
1594 if (in_range)
1595 {
1596 int i;
a737bd4d 1597
c19d1205
ZW
1598 if (reg <= cur_reg)
1599 {
dcbf9037 1600 first_error (_("bad range in register list"));
c19d1205
ZW
1601 return FAIL;
1602 }
40a18ebd 1603
c19d1205
ZW
1604 for (i = cur_reg + 1; i < reg; i++)
1605 {
1606 if (range & (1 << i))
1607 as_tsktsk
1608 (_("Warning: duplicated register (r%d) in register list"),
1609 i);
1610 else
1611 range |= 1 << i;
1612 }
1613 in_range = 0;
1614 }
a737bd4d 1615
c19d1205
ZW
1616 if (range & (1 << reg))
1617 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1618 reg);
1619 else if (reg <= cur_reg)
1620 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1621
c19d1205
ZW
1622 range |= 1 << reg;
1623 cur_reg = reg;
1624 }
1625 while (skip_past_comma (&str) != FAIL
1626 || (in_range = 1, *str++ == '-'));
1627 str--;
a737bd4d 1628
c19d1205
ZW
1629 if (*str++ != '}')
1630 {
dcbf9037 1631 first_error (_("missing `}'"));
c19d1205
ZW
1632 return FAIL;
1633 }
1634 }
1635 else
1636 {
91d6fa6a 1637 expressionS exp;
40a18ebd 1638
91d6fa6a 1639 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1640 return FAIL;
40a18ebd 1641
91d6fa6a 1642 if (exp.X_op == O_constant)
c19d1205 1643 {
91d6fa6a
NC
1644 if (exp.X_add_number
1645 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1646 {
1647 inst.error = _("invalid register mask");
1648 return FAIL;
1649 }
a737bd4d 1650
91d6fa6a 1651 if ((range & exp.X_add_number) != 0)
c19d1205 1652 {
91d6fa6a 1653 int regno = range & exp.X_add_number;
a737bd4d 1654
c19d1205
ZW
1655 regno &= -regno;
1656 regno = (1 << regno) - 1;
1657 as_tsktsk
1658 (_("Warning: duplicated register (r%d) in register list"),
1659 regno);
1660 }
a737bd4d 1661
91d6fa6a 1662 range |= exp.X_add_number;
c19d1205
ZW
1663 }
1664 else
1665 {
1666 if (inst.reloc.type != 0)
1667 {
1668 inst.error = _("expression too complex");
1669 return FAIL;
1670 }
a737bd4d 1671
91d6fa6a 1672 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1673 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1674 inst.reloc.pc_rel = 0;
1675 }
1676 }
a737bd4d 1677
c19d1205
ZW
1678 if (*str == '|' || *str == '+')
1679 {
1680 str++;
1681 another_range = 1;
1682 }
a737bd4d 1683 }
c19d1205 1684 while (another_range);
a737bd4d 1685
c19d1205
ZW
1686 *strp = str;
1687 return range;
a737bd4d
NC
1688}
1689
5287ad62
JB
1690/* Types of registers in a list. */
1691
1692enum reg_list_els
1693{
1694 REGLIST_VFP_S,
1695 REGLIST_VFP_D,
1696 REGLIST_NEON_D
1697};
1698
c19d1205
ZW
1699/* Parse a VFP register list. If the string is invalid return FAIL.
1700 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1701 register. Parses registers of type ETYPE.
1702 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1703 - Q registers can be used to specify pairs of D registers
1704 - { } can be omitted from around a singleton register list
1705 FIXME: This is not implemented, as it would require backtracking in
1706 some cases, e.g.:
1707 vtbl.8 d3,d4,d5
1708 This could be done (the meaning isn't really ambiguous), but doesn't
1709 fit in well with the current parsing framework.
dcbf9037
JB
1710 - 32 D registers may be used (also true for VFPv3).
1711 FIXME: Types are ignored in these register lists, which is probably a
1712 bug. */
6057a28f 1713
c19d1205 1714static int
037e8744 1715parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1716{
037e8744 1717 char *str = *ccp;
c19d1205
ZW
1718 int base_reg;
1719 int new_base;
21d799b5 1720 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1721 int max_regs = 0;
c19d1205
ZW
1722 int count = 0;
1723 int warned = 0;
1724 unsigned long mask = 0;
a737bd4d 1725 int i;
6057a28f 1726
037e8744 1727 if (*str != '{')
5287ad62
JB
1728 {
1729 inst.error = _("expecting {");
1730 return FAIL;
1731 }
6057a28f 1732
037e8744 1733 str++;
6057a28f 1734
5287ad62 1735 switch (etype)
c19d1205 1736 {
5287ad62 1737 case REGLIST_VFP_S:
c19d1205
ZW
1738 regtype = REG_TYPE_VFS;
1739 max_regs = 32;
5287ad62 1740 break;
5f4273c7 1741
5287ad62
JB
1742 case REGLIST_VFP_D:
1743 regtype = REG_TYPE_VFD;
b7fc2769 1744 break;
5f4273c7 1745
b7fc2769
JB
1746 case REGLIST_NEON_D:
1747 regtype = REG_TYPE_NDQ;
1748 break;
1749 }
1750
1751 if (etype != REGLIST_VFP_S)
1752 {
b1cc4aeb
PB
1753 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1754 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1755 {
1756 max_regs = 32;
1757 if (thumb_mode)
1758 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1759 fpu_vfp_ext_d32);
5287ad62
JB
1760 else
1761 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1762 fpu_vfp_ext_d32);
5287ad62
JB
1763 }
1764 else
1765 max_regs = 16;
c19d1205 1766 }
6057a28f 1767
c19d1205 1768 base_reg = max_regs;
a737bd4d 1769
c19d1205
ZW
1770 do
1771 {
5287ad62 1772 int setmask = 1, addregs = 1;
dcbf9037 1773
037e8744 1774 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1775
c19d1205 1776 if (new_base == FAIL)
a737bd4d 1777 {
dcbf9037 1778 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1779 return FAIL;
1780 }
5f4273c7 1781
b7fc2769
JB
1782 if (new_base >= max_regs)
1783 {
1784 first_error (_("register out of range in list"));
1785 return FAIL;
1786 }
5f4273c7 1787
5287ad62
JB
1788 /* Note: a value of 2 * n is returned for the register Q<n>. */
1789 if (regtype == REG_TYPE_NQ)
1790 {
1791 setmask = 3;
1792 addregs = 2;
1793 }
1794
c19d1205
ZW
1795 if (new_base < base_reg)
1796 base_reg = new_base;
a737bd4d 1797
5287ad62 1798 if (mask & (setmask << new_base))
c19d1205 1799 {
dcbf9037 1800 first_error (_("invalid register list"));
c19d1205 1801 return FAIL;
a737bd4d 1802 }
a737bd4d 1803
c19d1205
ZW
1804 if ((mask >> new_base) != 0 && ! warned)
1805 {
1806 as_tsktsk (_("register list not in ascending order"));
1807 warned = 1;
1808 }
0bbf2aa4 1809
5287ad62
JB
1810 mask |= setmask << new_base;
1811 count += addregs;
0bbf2aa4 1812
037e8744 1813 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1814 {
1815 int high_range;
0bbf2aa4 1816
037e8744 1817 str++;
0bbf2aa4 1818
037e8744 1819 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1820 == FAIL)
c19d1205
ZW
1821 {
1822 inst.error = gettext (reg_expected_msgs[regtype]);
1823 return FAIL;
1824 }
0bbf2aa4 1825
b7fc2769
JB
1826 if (high_range >= max_regs)
1827 {
1828 first_error (_("register out of range in list"));
1829 return FAIL;
1830 }
1831
5287ad62
JB
1832 if (regtype == REG_TYPE_NQ)
1833 high_range = high_range + 1;
1834
c19d1205
ZW
1835 if (high_range <= new_base)
1836 {
1837 inst.error = _("register range not in ascending order");
1838 return FAIL;
1839 }
0bbf2aa4 1840
5287ad62 1841 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1842 {
5287ad62 1843 if (mask & (setmask << new_base))
0bbf2aa4 1844 {
c19d1205
ZW
1845 inst.error = _("invalid register list");
1846 return FAIL;
0bbf2aa4 1847 }
c19d1205 1848
5287ad62
JB
1849 mask |= setmask << new_base;
1850 count += addregs;
0bbf2aa4 1851 }
0bbf2aa4 1852 }
0bbf2aa4 1853 }
037e8744 1854 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1855
037e8744 1856 str++;
0bbf2aa4 1857
c19d1205
ZW
1858 /* Sanity check -- should have raised a parse error above. */
1859 if (count == 0 || count > max_regs)
1860 abort ();
1861
1862 *pbase = base_reg;
1863
1864 /* Final test -- the registers must be consecutive. */
1865 mask >>= base_reg;
1866 for (i = 0; i < count; i++)
1867 {
1868 if ((mask & (1u << i)) == 0)
1869 {
1870 inst.error = _("non-contiguous register range");
1871 return FAIL;
1872 }
1873 }
1874
037e8744
JB
1875 *ccp = str;
1876
c19d1205 1877 return count;
b99bd4ef
NC
1878}
1879
dcbf9037
JB
1880/* True if two alias types are the same. */
1881
c921be7d 1882static bfd_boolean
dcbf9037
JB
1883neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1884{
1885 if (!a && !b)
c921be7d 1886 return TRUE;
5f4273c7 1887
dcbf9037 1888 if (!a || !b)
c921be7d 1889 return FALSE;
dcbf9037
JB
1890
1891 if (a->defined != b->defined)
c921be7d 1892 return FALSE;
5f4273c7 1893
dcbf9037
JB
1894 if ((a->defined & NTA_HASTYPE) != 0
1895 && (a->eltype.type != b->eltype.type
1896 || a->eltype.size != b->eltype.size))
c921be7d 1897 return FALSE;
dcbf9037
JB
1898
1899 if ((a->defined & NTA_HASINDEX) != 0
1900 && (a->index != b->index))
c921be7d 1901 return FALSE;
5f4273c7 1902
c921be7d 1903 return TRUE;
dcbf9037
JB
1904}
1905
5287ad62
JB
1906/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1907 The base register is put in *PBASE.
dcbf9037 1908 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1909 the return value.
1910 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1911 Bits [6:5] encode the list length (minus one).
1912 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1913
5287ad62 1914#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1915#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1916#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1917
1918static int
dcbf9037
JB
1919parse_neon_el_struct_list (char **str, unsigned *pbase,
1920 struct neon_type_el *eltype)
5287ad62
JB
1921{
1922 char *ptr = *str;
1923 int base_reg = -1;
1924 int reg_incr = -1;
1925 int count = 0;
1926 int lane = -1;
1927 int leading_brace = 0;
1928 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1929 const char *const incr_error = _("register stride must be 1 or 2");
1930 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1931 struct neon_typed_alias firsttype;
5f4273c7 1932
5287ad62
JB
1933 if (skip_past_char (&ptr, '{') == SUCCESS)
1934 leading_brace = 1;
5f4273c7 1935
5287ad62
JB
1936 do
1937 {
dcbf9037
JB
1938 struct neon_typed_alias atype;
1939 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1940
5287ad62
JB
1941 if (getreg == FAIL)
1942 {
dcbf9037 1943 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1944 return FAIL;
1945 }
5f4273c7 1946
5287ad62
JB
1947 if (base_reg == -1)
1948 {
1949 base_reg = getreg;
1950 if (rtype == REG_TYPE_NQ)
1951 {
1952 reg_incr = 1;
5287ad62 1953 }
dcbf9037 1954 firsttype = atype;
5287ad62
JB
1955 }
1956 else if (reg_incr == -1)
1957 {
1958 reg_incr = getreg - base_reg;
1959 if (reg_incr < 1 || reg_incr > 2)
1960 {
dcbf9037 1961 first_error (_(incr_error));
5287ad62
JB
1962 return FAIL;
1963 }
1964 }
1965 else if (getreg != base_reg + reg_incr * count)
1966 {
dcbf9037
JB
1967 first_error (_(incr_error));
1968 return FAIL;
1969 }
1970
c921be7d 1971 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1972 {
1973 first_error (_(type_error));
5287ad62
JB
1974 return FAIL;
1975 }
5f4273c7 1976
5287ad62
JB
1977 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1978 modes. */
1979 if (ptr[0] == '-')
1980 {
dcbf9037 1981 struct neon_typed_alias htype;
5287ad62
JB
1982 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1983 if (lane == -1)
1984 lane = NEON_INTERLEAVE_LANES;
1985 else if (lane != NEON_INTERLEAVE_LANES)
1986 {
dcbf9037 1987 first_error (_(type_error));
5287ad62
JB
1988 return FAIL;
1989 }
1990 if (reg_incr == -1)
1991 reg_incr = 1;
1992 else if (reg_incr != 1)
1993 {
dcbf9037 1994 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1995 return FAIL;
1996 }
1997 ptr++;
dcbf9037 1998 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1999 if (hireg == FAIL)
2000 {
dcbf9037
JB
2001 first_error (_(reg_expected_msgs[rtype]));
2002 return FAIL;
2003 }
c921be7d 2004 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
2005 {
2006 first_error (_(type_error));
5287ad62
JB
2007 return FAIL;
2008 }
2009 count += hireg + dregs - getreg;
2010 continue;
2011 }
5f4273c7 2012
5287ad62
JB
2013 /* If we're using Q registers, we can't use [] or [n] syntax. */
2014 if (rtype == REG_TYPE_NQ)
2015 {
2016 count += 2;
2017 continue;
2018 }
5f4273c7 2019
dcbf9037 2020 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 2021 {
dcbf9037
JB
2022 if (lane == -1)
2023 lane = atype.index;
2024 else if (lane != atype.index)
5287ad62 2025 {
dcbf9037
JB
2026 first_error (_(type_error));
2027 return FAIL;
5287ad62
JB
2028 }
2029 }
2030 else if (lane == -1)
2031 lane = NEON_INTERLEAVE_LANES;
2032 else if (lane != NEON_INTERLEAVE_LANES)
2033 {
dcbf9037 2034 first_error (_(type_error));
5287ad62
JB
2035 return FAIL;
2036 }
2037 count++;
2038 }
2039 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2040
5287ad62
JB
2041 /* No lane set by [x]. We must be interleaving structures. */
2042 if (lane == -1)
2043 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2044
5287ad62
JB
2045 /* Sanity check. */
2046 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2047 || (count > 1 && reg_incr == -1))
2048 {
dcbf9037 2049 first_error (_("error parsing element/structure list"));
5287ad62
JB
2050 return FAIL;
2051 }
2052
2053 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2054 {
dcbf9037 2055 first_error (_("expected }"));
5287ad62
JB
2056 return FAIL;
2057 }
5f4273c7 2058
5287ad62
JB
2059 if (reg_incr == -1)
2060 reg_incr = 1;
2061
dcbf9037
JB
2062 if (eltype)
2063 *eltype = firsttype.eltype;
2064
5287ad62
JB
2065 *pbase = base_reg;
2066 *str = ptr;
5f4273c7 2067
5287ad62
JB
2068 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2069}
2070
c19d1205
ZW
2071/* Parse an explicit relocation suffix on an expression. This is
2072 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2073 arm_reloc_hsh contains no entries, so this function can only
2074 succeed if there is no () after the word. Returns -1 on error,
2075 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2076
c19d1205
ZW
2077static int
2078parse_reloc (char **str)
b99bd4ef 2079{
c19d1205
ZW
2080 struct reloc_entry *r;
2081 char *p, *q;
b99bd4ef 2082
c19d1205
ZW
2083 if (**str != '(')
2084 return BFD_RELOC_UNUSED;
b99bd4ef 2085
c19d1205
ZW
2086 p = *str + 1;
2087 q = p;
2088
2089 while (*q && *q != ')' && *q != ',')
2090 q++;
2091 if (*q != ')')
2092 return -1;
2093
21d799b5
NC
2094 if ((r = (struct reloc_entry *)
2095 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2096 return -1;
2097
2098 *str = q + 1;
2099 return r->reloc;
b99bd4ef
NC
2100}
2101
c19d1205
ZW
2102/* Directives: register aliases. */
2103
dcbf9037 2104static struct reg_entry *
90ec0d68 2105insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2106{
d3ce72d0 2107 struct reg_entry *new_reg;
c19d1205 2108 const char *name;
b99bd4ef 2109
d3ce72d0 2110 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2111 {
d3ce72d0 2112 if (new_reg->builtin)
c19d1205 2113 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2114
c19d1205
ZW
2115 /* Only warn about a redefinition if it's not defined as the
2116 same register. */
d3ce72d0 2117 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2118 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2119
d929913e 2120 return NULL;
c19d1205 2121 }
b99bd4ef 2122
c19d1205 2123 name = xstrdup (str);
d3ce72d0 2124 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2125
d3ce72d0
NC
2126 new_reg->name = name;
2127 new_reg->number = number;
2128 new_reg->type = type;
2129 new_reg->builtin = FALSE;
2130 new_reg->neon = NULL;
b99bd4ef 2131
d3ce72d0 2132 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2133 abort ();
5f4273c7 2134
d3ce72d0 2135 return new_reg;
dcbf9037
JB
2136}
2137
2138static void
2139insert_neon_reg_alias (char *str, int number, int type,
2140 struct neon_typed_alias *atype)
2141{
2142 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2143
dcbf9037
JB
2144 if (!reg)
2145 {
2146 first_error (_("attempt to redefine typed alias"));
2147 return;
2148 }
5f4273c7 2149
dcbf9037
JB
2150 if (atype)
2151 {
21d799b5
NC
2152 reg->neon = (struct neon_typed_alias *)
2153 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2154 *reg->neon = *atype;
2155 }
c19d1205 2156}
b99bd4ef 2157
c19d1205 2158/* Look for the .req directive. This is of the form:
b99bd4ef 2159
c19d1205 2160 new_register_name .req existing_register_name
b99bd4ef 2161
c19d1205 2162 If we find one, or if it looks sufficiently like one that we want to
d929913e 2163 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2164
d929913e 2165static bfd_boolean
c19d1205
ZW
2166create_register_alias (char * newname, char *p)
2167{
2168 struct reg_entry *old;
2169 char *oldname, *nbuf;
2170 size_t nlen;
b99bd4ef 2171
c19d1205
ZW
2172 /* The input scrubber ensures that whitespace after the mnemonic is
2173 collapsed to single spaces. */
2174 oldname = p;
2175 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2176 return FALSE;
b99bd4ef 2177
c19d1205
ZW
2178 oldname += 6;
2179 if (*oldname == '\0')
d929913e 2180 return FALSE;
b99bd4ef 2181
21d799b5 2182 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2183 if (!old)
b99bd4ef 2184 {
c19d1205 2185 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2186 return TRUE;
b99bd4ef
NC
2187 }
2188
c19d1205
ZW
2189 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2190 the desired alias name, and p points to its end. If not, then
2191 the desired alias name is in the global original_case_string. */
2192#ifdef TC_CASE_SENSITIVE
2193 nlen = p - newname;
2194#else
2195 newname = original_case_string;
2196 nlen = strlen (newname);
2197#endif
b99bd4ef 2198
21d799b5 2199 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2200 memcpy (nbuf, newname, nlen);
2201 nbuf[nlen] = '\0';
b99bd4ef 2202
c19d1205
ZW
2203 /* Create aliases under the new name as stated; an all-lowercase
2204 version of the new name; and an all-uppercase version of the new
2205 name. */
d929913e
NC
2206 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2207 {
2208 for (p = nbuf; *p; p++)
2209 *p = TOUPPER (*p);
c19d1205 2210
d929913e
NC
2211 if (strncmp (nbuf, newname, nlen))
2212 {
2213 /* If this attempt to create an additional alias fails, do not bother
2214 trying to create the all-lower case alias. We will fail and issue
2215 a second, duplicate error message. This situation arises when the
2216 programmer does something like:
2217 foo .req r0
2218 Foo .req r1
2219 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2220 the artificial FOO alias because it has already been created by the
d929913e
NC
2221 first .req. */
2222 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2223 return TRUE;
2224 }
c19d1205 2225
d929913e
NC
2226 for (p = nbuf; *p; p++)
2227 *p = TOLOWER (*p);
c19d1205 2228
d929913e
NC
2229 if (strncmp (nbuf, newname, nlen))
2230 insert_reg_alias (nbuf, old->number, old->type);
2231 }
c19d1205 2232
d929913e 2233 return TRUE;
b99bd4ef
NC
2234}
2235
dcbf9037
JB
2236/* Create a Neon typed/indexed register alias using directives, e.g.:
2237 X .dn d5.s32[1]
2238 Y .qn 6.s16
2239 Z .dn d7
2240 T .dn Z[0]
2241 These typed registers can be used instead of the types specified after the
2242 Neon mnemonic, so long as all operands given have types. Types can also be
2243 specified directly, e.g.:
5f4273c7 2244 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2245
c921be7d 2246static bfd_boolean
dcbf9037
JB
2247create_neon_reg_alias (char *newname, char *p)
2248{
2249 enum arm_reg_type basetype;
2250 struct reg_entry *basereg;
2251 struct reg_entry mybasereg;
2252 struct neon_type ntype;
2253 struct neon_typed_alias typeinfo;
12d6b0b7 2254 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2255 int namelen;
5f4273c7 2256
dcbf9037
JB
2257 typeinfo.defined = 0;
2258 typeinfo.eltype.type = NT_invtype;
2259 typeinfo.eltype.size = -1;
2260 typeinfo.index = -1;
5f4273c7 2261
dcbf9037 2262 nameend = p;
5f4273c7 2263
dcbf9037
JB
2264 if (strncmp (p, " .dn ", 5) == 0)
2265 basetype = REG_TYPE_VFD;
2266 else if (strncmp (p, " .qn ", 5) == 0)
2267 basetype = REG_TYPE_NQ;
2268 else
c921be7d 2269 return FALSE;
5f4273c7 2270
dcbf9037 2271 p += 5;
5f4273c7 2272
dcbf9037 2273 if (*p == '\0')
c921be7d 2274 return FALSE;
5f4273c7 2275
dcbf9037
JB
2276 basereg = arm_reg_parse_multi (&p);
2277
2278 if (basereg && basereg->type != basetype)
2279 {
2280 as_bad (_("bad type for register"));
c921be7d 2281 return FALSE;
dcbf9037
JB
2282 }
2283
2284 if (basereg == NULL)
2285 {
2286 expressionS exp;
2287 /* Try parsing as an integer. */
2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
2289 if (exp.X_op != O_constant)
2290 {
2291 as_bad (_("expression must be constant"));
c921be7d 2292 return FALSE;
dcbf9037
JB
2293 }
2294 basereg = &mybasereg;
2295 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2296 : exp.X_add_number;
2297 basereg->neon = 0;
2298 }
2299
2300 if (basereg->neon)
2301 typeinfo = *basereg->neon;
2302
2303 if (parse_neon_type (&ntype, &p) == SUCCESS)
2304 {
2305 /* We got a type. */
2306 if (typeinfo.defined & NTA_HASTYPE)
2307 {
2308 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2309 return FALSE;
dcbf9037 2310 }
5f4273c7 2311
dcbf9037
JB
2312 typeinfo.defined |= NTA_HASTYPE;
2313 if (ntype.elems != 1)
2314 {
2315 as_bad (_("you must specify a single type only"));
c921be7d 2316 return FALSE;
dcbf9037
JB
2317 }
2318 typeinfo.eltype = ntype.el[0];
2319 }
5f4273c7 2320
dcbf9037
JB
2321 if (skip_past_char (&p, '[') == SUCCESS)
2322 {
2323 expressionS exp;
2324 /* We got a scalar index. */
5f4273c7 2325
dcbf9037
JB
2326 if (typeinfo.defined & NTA_HASINDEX)
2327 {
2328 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2329 return FALSE;
dcbf9037 2330 }
5f4273c7 2331
dcbf9037 2332 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2333
dcbf9037
JB
2334 if (exp.X_op != O_constant)
2335 {
2336 as_bad (_("scalar index must be constant"));
c921be7d 2337 return FALSE;
dcbf9037 2338 }
5f4273c7 2339
dcbf9037
JB
2340 typeinfo.defined |= NTA_HASINDEX;
2341 typeinfo.index = exp.X_add_number;
5f4273c7 2342
dcbf9037
JB
2343 if (skip_past_char (&p, ']') == FAIL)
2344 {
2345 as_bad (_("expecting ]"));
c921be7d 2346 return FALSE;
dcbf9037
JB
2347 }
2348 }
2349
15735687
NS
2350 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2351 the desired alias name, and p points to its end. If not, then
2352 the desired alias name is in the global original_case_string. */
2353#ifdef TC_CASE_SENSITIVE
dcbf9037 2354 namelen = nameend - newname;
15735687
NS
2355#else
2356 newname = original_case_string;
2357 namelen = strlen (newname);
2358#endif
2359
21d799b5 2360 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2361 strncpy (namebuf, newname, namelen);
2362 namebuf[namelen] = '\0';
5f4273c7 2363
dcbf9037
JB
2364 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2365 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2366
dcbf9037
JB
2367 /* Insert name in all uppercase. */
2368 for (p = namebuf; *p; p++)
2369 *p = TOUPPER (*p);
5f4273c7 2370
dcbf9037
JB
2371 if (strncmp (namebuf, newname, namelen))
2372 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2373 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2374
dcbf9037
JB
2375 /* Insert name in all lowercase. */
2376 for (p = namebuf; *p; p++)
2377 *p = TOLOWER (*p);
5f4273c7 2378
dcbf9037
JB
2379 if (strncmp (namebuf, newname, namelen))
2380 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2381 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2382
c921be7d 2383 return TRUE;
dcbf9037
JB
2384}
2385
c19d1205
ZW
2386/* Should never be called, as .req goes between the alias and the
2387 register name, not at the beginning of the line. */
c921be7d 2388
b99bd4ef 2389static void
c19d1205 2390s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2391{
c19d1205
ZW
2392 as_bad (_("invalid syntax for .req directive"));
2393}
b99bd4ef 2394
dcbf9037
JB
2395static void
2396s_dn (int a ATTRIBUTE_UNUSED)
2397{
2398 as_bad (_("invalid syntax for .dn directive"));
2399}
2400
2401static void
2402s_qn (int a ATTRIBUTE_UNUSED)
2403{
2404 as_bad (_("invalid syntax for .qn directive"));
2405}
2406
c19d1205
ZW
2407/* The .unreq directive deletes an alias which was previously defined
2408 by .req. For example:
b99bd4ef 2409
c19d1205
ZW
2410 my_alias .req r11
2411 .unreq my_alias */
b99bd4ef
NC
2412
2413static void
c19d1205 2414s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2415{
c19d1205
ZW
2416 char * name;
2417 char saved_char;
b99bd4ef 2418
c19d1205
ZW
2419 name = input_line_pointer;
2420
2421 while (*input_line_pointer != 0
2422 && *input_line_pointer != ' '
2423 && *input_line_pointer != '\n')
2424 ++input_line_pointer;
2425
2426 saved_char = *input_line_pointer;
2427 *input_line_pointer = 0;
2428
2429 if (!*name)
2430 as_bad (_("invalid syntax for .unreq directive"));
2431 else
2432 {
21d799b5
NC
2433 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2434 name);
c19d1205
ZW
2435
2436 if (!reg)
2437 as_bad (_("unknown register alias '%s'"), name);
2438 else if (reg->builtin)
a1727c1a 2439 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2440 name);
2441 else
2442 {
d929913e
NC
2443 char * p;
2444 char * nbuf;
2445
db0bc284 2446 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2447 free ((char *) reg->name);
dcbf9037
JB
2448 if (reg->neon)
2449 free (reg->neon);
c19d1205 2450 free (reg);
d929913e
NC
2451
2452 /* Also locate the all upper case and all lower case versions.
2453 Do not complain if we cannot find one or the other as it
2454 was probably deleted above. */
5f4273c7 2455
d929913e
NC
2456 nbuf = strdup (name);
2457 for (p = nbuf; *p; p++)
2458 *p = TOUPPER (*p);
21d799b5 2459 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2460 if (reg)
2461 {
db0bc284 2462 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2463 free ((char *) reg->name);
2464 if (reg->neon)
2465 free (reg->neon);
2466 free (reg);
2467 }
2468
2469 for (p = nbuf; *p; p++)
2470 *p = TOLOWER (*p);
21d799b5 2471 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2472 if (reg)
2473 {
db0bc284 2474 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2475 free ((char *) reg->name);
2476 if (reg->neon)
2477 free (reg->neon);
2478 free (reg);
2479 }
2480
2481 free (nbuf);
c19d1205
ZW
2482 }
2483 }
b99bd4ef 2484
c19d1205 2485 *input_line_pointer = saved_char;
b99bd4ef
NC
2486 demand_empty_rest_of_line ();
2487}
2488
c19d1205
ZW
2489/* Directives: Instruction set selection. */
2490
2491#ifdef OBJ_ELF
2492/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2493 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2494 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2495 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2496
cd000bff
DJ
2497/* Create a new mapping symbol for the transition to STATE. */
2498
2499static void
2500make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2501{
a737bd4d 2502 symbolS * symbolP;
c19d1205
ZW
2503 const char * symname;
2504 int type;
b99bd4ef 2505
c19d1205 2506 switch (state)
b99bd4ef 2507 {
c19d1205
ZW
2508 case MAP_DATA:
2509 symname = "$d";
2510 type = BSF_NO_FLAGS;
2511 break;
2512 case MAP_ARM:
2513 symname = "$a";
2514 type = BSF_NO_FLAGS;
2515 break;
2516 case MAP_THUMB:
2517 symname = "$t";
2518 type = BSF_NO_FLAGS;
2519 break;
c19d1205
ZW
2520 default:
2521 abort ();
2522 }
2523
cd000bff 2524 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2525 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2526
2527 switch (state)
2528 {
2529 case MAP_ARM:
2530 THUMB_SET_FUNC (symbolP, 0);
2531 ARM_SET_THUMB (symbolP, 0);
2532 ARM_SET_INTERWORK (symbolP, support_interwork);
2533 break;
2534
2535 case MAP_THUMB:
2536 THUMB_SET_FUNC (symbolP, 1);
2537 ARM_SET_THUMB (symbolP, 1);
2538 ARM_SET_INTERWORK (symbolP, support_interwork);
2539 break;
2540
2541 case MAP_DATA:
2542 default:
cd000bff
DJ
2543 break;
2544 }
2545
2546 /* Save the mapping symbols for future reference. Also check that
2547 we do not place two mapping symbols at the same offset within a
2548 frag. We'll handle overlap between frags in
2de7820f
JZ
2549 check_mapping_symbols.
2550
2551 If .fill or other data filling directive generates zero sized data,
2552 the mapping symbol for the following code will have the same value
2553 as the one generated for the data filling directive. In this case,
2554 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2555 if (value == 0)
2556 {
2de7820f
JZ
2557 if (frag->tc_frag_data.first_map != NULL)
2558 {
2559 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2560 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2561 }
cd000bff
DJ
2562 frag->tc_frag_data.first_map = symbolP;
2563 }
2564 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2565 {
2566 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2567 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2568 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2569 }
cd000bff
DJ
2570 frag->tc_frag_data.last_map = symbolP;
2571}
2572
2573/* We must sometimes convert a region marked as code to data during
2574 code alignment, if an odd number of bytes have to be padded. The
2575 code mapping symbol is pushed to an aligned address. */
2576
2577static void
2578insert_data_mapping_symbol (enum mstate state,
2579 valueT value, fragS *frag, offsetT bytes)
2580{
2581 /* If there was already a mapping symbol, remove it. */
2582 if (frag->tc_frag_data.last_map != NULL
2583 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2584 {
2585 symbolS *symp = frag->tc_frag_data.last_map;
2586
2587 if (value == 0)
2588 {
2589 know (frag->tc_frag_data.first_map == symp);
2590 frag->tc_frag_data.first_map = NULL;
2591 }
2592 frag->tc_frag_data.last_map = NULL;
2593 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2594 }
cd000bff
DJ
2595
2596 make_mapping_symbol (MAP_DATA, value, frag);
2597 make_mapping_symbol (state, value + bytes, frag);
2598}
2599
2600static void mapping_state_2 (enum mstate state, int max_chars);
2601
2602/* Set the mapping state to STATE. Only call this when about to
2603 emit some STATE bytes to the file. */
2604
2605void
2606mapping_state (enum mstate state)
2607{
940b5ce0
DJ
2608 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2609
cd000bff
DJ
2610#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2611
2612 if (mapstate == state)
2613 /* The mapping symbol has already been emitted.
2614 There is nothing else to do. */
2615 return;
49c62a33
NC
2616
2617 if (state == MAP_ARM || state == MAP_THUMB)
2618 /* PR gas/12931
2619 All ARM instructions require 4-byte alignment.
2620 (Almost) all Thumb instructions require 2-byte alignment.
2621
2622 When emitting instructions into any section, mark the section
2623 appropriately.
2624
2625 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2626 but themselves require 2-byte alignment; this applies to some
2627 PC- relative forms. However, these cases will invovle implicit
2628 literal pool generation or an explicit .align >=2, both of
2629 which will cause the section to me marked with sufficient
2630 alignment. Thus, we don't handle those cases here. */
2631 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2632
2633 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
cd000bff
DJ
2634 /* This case will be evaluated later in the next else. */
2635 return;
2636 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2637 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2638 {
2639 /* Only add the symbol if the offset is > 0:
2640 if we're at the first frag, check it's size > 0;
2641 if we're not at the first frag, then for sure
2642 the offset is > 0. */
2643 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2644 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2645
2646 if (add_symbol)
2647 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2648 }
2649
2650 mapping_state_2 (state, 0);
2651#undef TRANSITION
2652}
2653
2654/* Same as mapping_state, but MAX_CHARS bytes have already been
2655 allocated. Put the mapping symbol that far back. */
2656
2657static void
2658mapping_state_2 (enum mstate state, int max_chars)
2659{
940b5ce0
DJ
2660 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2661
2662 if (!SEG_NORMAL (now_seg))
2663 return;
2664
cd000bff
DJ
2665 if (mapstate == state)
2666 /* The mapping symbol has already been emitted.
2667 There is nothing else to do. */
2668 return;
2669
cd000bff
DJ
2670 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2671 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2672}
2673#else
d3106081
NS
2674#define mapping_state(x) ((void)0)
2675#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2676#endif
2677
2678/* Find the real, Thumb encoded start of a Thumb function. */
2679
4343666d 2680#ifdef OBJ_COFF
c19d1205
ZW
2681static symbolS *
2682find_real_start (symbolS * symbolP)
2683{
2684 char * real_start;
2685 const char * name = S_GET_NAME (symbolP);
2686 symbolS * new_target;
2687
2688 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2689#define STUB_NAME ".real_start_of"
2690
2691 if (name == NULL)
2692 abort ();
2693
37f6032b
ZW
2694 /* The compiler may generate BL instructions to local labels because
2695 it needs to perform a branch to a far away location. These labels
2696 do not have a corresponding ".real_start_of" label. We check
2697 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2698 the ".real_start_of" convention for nonlocal branches. */
2699 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2700 return symbolP;
2701
37f6032b 2702 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2703 new_target = symbol_find (real_start);
2704
2705 if (new_target == NULL)
2706 {
bd3ba5d1 2707 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2708 new_target = symbolP;
2709 }
2710
c19d1205
ZW
2711 return new_target;
2712}
4343666d 2713#endif
c19d1205
ZW
2714
2715static void
2716opcode_select (int width)
2717{
2718 switch (width)
2719 {
2720 case 16:
2721 if (! thumb_mode)
2722 {
e74cfd16 2723 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2724 as_bad (_("selected processor does not support THUMB opcodes"));
2725
2726 thumb_mode = 1;
2727 /* No need to force the alignment, since we will have been
2728 coming from ARM mode, which is word-aligned. */
2729 record_alignment (now_seg, 1);
2730 }
c19d1205
ZW
2731 break;
2732
2733 case 32:
2734 if (thumb_mode)
2735 {
e74cfd16 2736 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2737 as_bad (_("selected processor does not support ARM opcodes"));
2738
2739 thumb_mode = 0;
2740
2741 if (!need_pass_2)
2742 frag_align (2, 0, 0);
2743
2744 record_alignment (now_seg, 1);
2745 }
c19d1205
ZW
2746 break;
2747
2748 default:
2749 as_bad (_("invalid instruction size selected (%d)"), width);
2750 }
2751}
2752
2753static void
2754s_arm (int ignore ATTRIBUTE_UNUSED)
2755{
2756 opcode_select (32);
2757 demand_empty_rest_of_line ();
2758}
2759
2760static void
2761s_thumb (int ignore ATTRIBUTE_UNUSED)
2762{
2763 opcode_select (16);
2764 demand_empty_rest_of_line ();
2765}
2766
2767static void
2768s_code (int unused ATTRIBUTE_UNUSED)
2769{
2770 int temp;
2771
2772 temp = get_absolute_expression ();
2773 switch (temp)
2774 {
2775 case 16:
2776 case 32:
2777 opcode_select (temp);
2778 break;
2779
2780 default:
2781 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2782 }
2783}
2784
2785static void
2786s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2787{
2788 /* If we are not already in thumb mode go into it, EVEN if
2789 the target processor does not support thumb instructions.
2790 This is used by gcc/config/arm/lib1funcs.asm for example
2791 to compile interworking support functions even if the
2792 target processor should not support interworking. */
2793 if (! thumb_mode)
2794 {
2795 thumb_mode = 2;
2796 record_alignment (now_seg, 1);
2797 }
2798
2799 demand_empty_rest_of_line ();
2800}
2801
2802static void
2803s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2804{
2805 s_thumb (0);
2806
2807 /* The following label is the name/address of the start of a Thumb function.
2808 We need to know this for the interworking support. */
2809 label_is_thumb_function_name = TRUE;
2810}
2811
2812/* Perform a .set directive, but also mark the alias as
2813 being a thumb function. */
2814
2815static void
2816s_thumb_set (int equiv)
2817{
2818 /* XXX the following is a duplicate of the code for s_set() in read.c
2819 We cannot just call that code as we need to get at the symbol that
2820 is created. */
2821 char * name;
2822 char delim;
2823 char * end_name;
2824 symbolS * symbolP;
2825
2826 /* Especial apologies for the random logic:
2827 This just grew, and could be parsed much more simply!
2828 Dean - in haste. */
2829 name = input_line_pointer;
2830 delim = get_symbol_end ();
2831 end_name = input_line_pointer;
2832 *end_name = delim;
2833
2834 if (*input_line_pointer != ',')
2835 {
2836 *end_name = 0;
2837 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2838 *end_name = delim;
2839 ignore_rest_of_line ();
2840 return;
2841 }
2842
2843 input_line_pointer++;
2844 *end_name = 0;
2845
2846 if (name[0] == '.' && name[1] == '\0')
2847 {
2848 /* XXX - this should not happen to .thumb_set. */
2849 abort ();
2850 }
2851
2852 if ((symbolP = symbol_find (name)) == NULL
2853 && (symbolP = md_undefined_symbol (name)) == NULL)
2854 {
2855#ifndef NO_LISTING
2856 /* When doing symbol listings, play games with dummy fragments living
2857 outside the normal fragment chain to record the file and line info
c19d1205 2858 for this symbol. */
b99bd4ef
NC
2859 if (listing & LISTING_SYMBOLS)
2860 {
2861 extern struct list_info_struct * listing_tail;
21d799b5 2862 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2863
2864 memset (dummy_frag, 0, sizeof (fragS));
2865 dummy_frag->fr_type = rs_fill;
2866 dummy_frag->line = listing_tail;
2867 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2868 dummy_frag->fr_symbol = symbolP;
2869 }
2870 else
2871#endif
2872 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2873
2874#ifdef OBJ_COFF
2875 /* "set" symbols are local unless otherwise specified. */
2876 SF_SET_LOCAL (symbolP);
2877#endif /* OBJ_COFF */
2878 } /* Make a new symbol. */
2879
2880 symbol_table_insert (symbolP);
2881
2882 * end_name = delim;
2883
2884 if (equiv
2885 && S_IS_DEFINED (symbolP)
2886 && S_GET_SEGMENT (symbolP) != reg_section)
2887 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2888
2889 pseudo_set (symbolP);
2890
2891 demand_empty_rest_of_line ();
2892
c19d1205 2893 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2894
2895 THUMB_SET_FUNC (symbolP, 1);
2896 ARM_SET_THUMB (symbolP, 1);
2897#if defined OBJ_ELF || defined OBJ_COFF
2898 ARM_SET_INTERWORK (symbolP, support_interwork);
2899#endif
2900}
2901
c19d1205 2902/* Directives: Mode selection. */
b99bd4ef 2903
c19d1205
ZW
2904/* .syntax [unified|divided] - choose the new unified syntax
2905 (same for Arm and Thumb encoding, modulo slight differences in what
2906 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2907static void
c19d1205 2908s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2909{
c19d1205
ZW
2910 char *name, delim;
2911
2912 name = input_line_pointer;
2913 delim = get_symbol_end ();
2914
2915 if (!strcasecmp (name, "unified"))
2916 unified_syntax = TRUE;
2917 else if (!strcasecmp (name, "divided"))
2918 unified_syntax = FALSE;
2919 else
2920 {
2921 as_bad (_("unrecognized syntax mode \"%s\""), name);
2922 return;
2923 }
2924 *input_line_pointer = delim;
b99bd4ef
NC
2925 demand_empty_rest_of_line ();
2926}
2927
c19d1205
ZW
2928/* Directives: sectioning and alignment. */
2929
2930/* Same as s_align_ptwo but align 0 => align 2. */
2931
b99bd4ef 2932static void
c19d1205 2933s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2934{
a737bd4d 2935 int temp;
dce323d1 2936 bfd_boolean fill_p;
c19d1205
ZW
2937 long temp_fill;
2938 long max_alignment = 15;
b99bd4ef
NC
2939
2940 temp = get_absolute_expression ();
c19d1205
ZW
2941 if (temp > max_alignment)
2942 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2943 else if (temp < 0)
b99bd4ef 2944 {
c19d1205
ZW
2945 as_bad (_("alignment negative. 0 assumed."));
2946 temp = 0;
2947 }
b99bd4ef 2948
c19d1205
ZW
2949 if (*input_line_pointer == ',')
2950 {
2951 input_line_pointer++;
2952 temp_fill = get_absolute_expression ();
dce323d1 2953 fill_p = TRUE;
b99bd4ef 2954 }
c19d1205 2955 else
dce323d1
PB
2956 {
2957 fill_p = FALSE;
2958 temp_fill = 0;
2959 }
b99bd4ef 2960
c19d1205
ZW
2961 if (!temp)
2962 temp = 2;
b99bd4ef 2963
c19d1205
ZW
2964 /* Only make a frag if we HAVE to. */
2965 if (temp && !need_pass_2)
dce323d1
PB
2966 {
2967 if (!fill_p && subseg_text_p (now_seg))
2968 frag_align_code (temp, 0);
2969 else
2970 frag_align (temp, (int) temp_fill, 0);
2971 }
c19d1205
ZW
2972 demand_empty_rest_of_line ();
2973
2974 record_alignment (now_seg, temp);
b99bd4ef
NC
2975}
2976
c19d1205
ZW
2977static void
2978s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2979{
c19d1205
ZW
2980 /* We don't support putting frags in the BSS segment, we fake it by
2981 marking in_bss, then looking at s_skip for clues. */
2982 subseg_set (bss_section, 0);
2983 demand_empty_rest_of_line ();
cd000bff
DJ
2984
2985#ifdef md_elf_section_change_hook
2986 md_elf_section_change_hook ();
2987#endif
c19d1205 2988}
b99bd4ef 2989
c19d1205
ZW
2990static void
2991s_even (int ignore ATTRIBUTE_UNUSED)
2992{
2993 /* Never make frag if expect extra pass. */
2994 if (!need_pass_2)
2995 frag_align (1, 0, 0);
b99bd4ef 2996
c19d1205 2997 record_alignment (now_seg, 1);
b99bd4ef 2998
c19d1205 2999 demand_empty_rest_of_line ();
b99bd4ef
NC
3000}
3001
c19d1205 3002/* Directives: Literal pools. */
a737bd4d 3003
c19d1205
ZW
3004static literal_pool *
3005find_literal_pool (void)
a737bd4d 3006{
c19d1205 3007 literal_pool * pool;
a737bd4d 3008
c19d1205 3009 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3010 {
c19d1205
ZW
3011 if (pool->section == now_seg
3012 && pool->sub_section == now_subseg)
3013 break;
a737bd4d
NC
3014 }
3015
c19d1205 3016 return pool;
a737bd4d
NC
3017}
3018
c19d1205
ZW
3019static literal_pool *
3020find_or_make_literal_pool (void)
a737bd4d 3021{
c19d1205
ZW
3022 /* Next literal pool ID number. */
3023 static unsigned int latest_pool_num = 1;
3024 literal_pool * pool;
a737bd4d 3025
c19d1205 3026 pool = find_literal_pool ();
a737bd4d 3027
c19d1205 3028 if (pool == NULL)
a737bd4d 3029 {
c19d1205 3030 /* Create a new pool. */
21d799b5 3031 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3032 if (! pool)
3033 return NULL;
a737bd4d 3034
c19d1205
ZW
3035 pool->next_free_entry = 0;
3036 pool->section = now_seg;
3037 pool->sub_section = now_subseg;
3038 pool->next = list_of_pools;
3039 pool->symbol = NULL;
3040
3041 /* Add it to the list. */
3042 list_of_pools = pool;
a737bd4d 3043 }
a737bd4d 3044
c19d1205
ZW
3045 /* New pools, and emptied pools, will have a NULL symbol. */
3046 if (pool->symbol == NULL)
a737bd4d 3047 {
c19d1205
ZW
3048 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3049 (valueT) 0, &zero_address_frag);
3050 pool->id = latest_pool_num ++;
a737bd4d
NC
3051 }
3052
c19d1205
ZW
3053 /* Done. */
3054 return pool;
a737bd4d
NC
3055}
3056
c19d1205 3057/* Add the literal in the global 'inst'
5f4273c7 3058 structure to the relevant literal pool. */
b99bd4ef
NC
3059
3060static int
c19d1205 3061add_to_lit_pool (void)
b99bd4ef 3062{
c19d1205
ZW
3063 literal_pool * pool;
3064 unsigned int entry;
b99bd4ef 3065
c19d1205
ZW
3066 pool = find_or_make_literal_pool ();
3067
3068 /* Check if this literal value is already in the pool. */
3069 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3070 {
c19d1205
ZW
3071 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3072 && (inst.reloc.exp.X_op == O_constant)
3073 && (pool->literals[entry].X_add_number
3074 == inst.reloc.exp.X_add_number)
3075 && (pool->literals[entry].X_unsigned
3076 == inst.reloc.exp.X_unsigned))
3077 break;
3078
3079 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3080 && (inst.reloc.exp.X_op == O_symbol)
3081 && (pool->literals[entry].X_add_number
3082 == inst.reloc.exp.X_add_number)
3083 && (pool->literals[entry].X_add_symbol
3084 == inst.reloc.exp.X_add_symbol)
3085 && (pool->literals[entry].X_op_symbol
3086 == inst.reloc.exp.X_op_symbol))
3087 break;
b99bd4ef
NC
3088 }
3089
c19d1205
ZW
3090 /* Do we need to create a new entry? */
3091 if (entry == pool->next_free_entry)
3092 {
3093 if (entry >= MAX_LITERAL_POOL_SIZE)
3094 {
3095 inst.error = _("literal pool overflow");
3096 return FAIL;
3097 }
3098
3099 pool->literals[entry] = inst.reloc.exp;
a8040cf2
NC
3100#ifdef OBJ_ELF
3101 /* PR ld/12974: Record the location of the first source line to reference
3102 this entry in the literal pool. If it turns out during linking that the
3103 symbol does not exist we will be able to give an accurate line number for
3104 the (first use of the) missing reference. */
3105 if (debug_type == DEBUG_DWARF2)
3106 dwarf2_where (pool->locs + entry);
3107#endif
c19d1205
ZW
3108 pool->next_free_entry += 1;
3109 }
b99bd4ef 3110
c19d1205
ZW
3111 inst.reloc.exp.X_op = O_symbol;
3112 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3113 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3114
c19d1205 3115 return SUCCESS;
b99bd4ef
NC
3116}
3117
c19d1205
ZW
3118/* Can't use symbol_new here, so have to create a symbol and then at
3119 a later date assign it a value. Thats what these functions do. */
e16bb312 3120
c19d1205
ZW
3121static void
3122symbol_locate (symbolS * symbolP,
3123 const char * name, /* It is copied, the caller can modify. */
3124 segT segment, /* Segment identifier (SEG_<something>). */
3125 valueT valu, /* Symbol value. */
3126 fragS * frag) /* Associated fragment. */
3127{
3128 unsigned int name_length;
3129 char * preserved_copy_of_name;
e16bb312 3130
c19d1205
ZW
3131 name_length = strlen (name) + 1; /* +1 for \0. */
3132 obstack_grow (&notes, name, name_length);
21d799b5 3133 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3134
c19d1205
ZW
3135#ifdef tc_canonicalize_symbol_name
3136 preserved_copy_of_name =
3137 tc_canonicalize_symbol_name (preserved_copy_of_name);
3138#endif
b99bd4ef 3139
c19d1205 3140 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3141
c19d1205
ZW
3142 S_SET_SEGMENT (symbolP, segment);
3143 S_SET_VALUE (symbolP, valu);
3144 symbol_clear_list_pointers (symbolP);
b99bd4ef 3145
c19d1205 3146 symbol_set_frag (symbolP, frag);
b99bd4ef 3147
c19d1205
ZW
3148 /* Link to end of symbol chain. */
3149 {
3150 extern int symbol_table_frozen;
b99bd4ef 3151
c19d1205
ZW
3152 if (symbol_table_frozen)
3153 abort ();
3154 }
b99bd4ef 3155
c19d1205 3156 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3157
c19d1205 3158 obj_symbol_new_hook (symbolP);
b99bd4ef 3159
c19d1205
ZW
3160#ifdef tc_symbol_new_hook
3161 tc_symbol_new_hook (symbolP);
3162#endif
3163
3164#ifdef DEBUG_SYMS
3165 verify_symbol_chain (symbol_rootP, symbol_lastP);
3166#endif /* DEBUG_SYMS */
b99bd4ef
NC
3167}
3168
b99bd4ef 3169
c19d1205
ZW
3170static void
3171s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3172{
c19d1205
ZW
3173 unsigned int entry;
3174 literal_pool * pool;
3175 char sym_name[20];
b99bd4ef 3176
c19d1205
ZW
3177 pool = find_literal_pool ();
3178 if (pool == NULL
3179 || pool->symbol == NULL
3180 || pool->next_free_entry == 0)
3181 return;
b99bd4ef 3182
c19d1205 3183 mapping_state (MAP_DATA);
b99bd4ef 3184
c19d1205
ZW
3185 /* Align pool as you have word accesses.
3186 Only make a frag if we have to. */
3187 if (!need_pass_2)
3188 frag_align (2, 0, 0);
b99bd4ef 3189
c19d1205 3190 record_alignment (now_seg, 2);
b99bd4ef 3191
c19d1205 3192 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3193
c19d1205
ZW
3194 symbol_locate (pool->symbol, sym_name, now_seg,
3195 (valueT) frag_now_fix (), frag_now);
3196 symbol_table_insert (pool->symbol);
b99bd4ef 3197
c19d1205 3198 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3199
c19d1205
ZW
3200#if defined OBJ_COFF || defined OBJ_ELF
3201 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3202#endif
6c43fab6 3203
c19d1205 3204 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3205 {
3206#ifdef OBJ_ELF
3207 if (debug_type == DEBUG_DWARF2)
3208 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3209#endif
3210 /* First output the expression in the instruction to the pool. */
3211 emit_expr (&(pool->literals[entry]), 4); /* .word */
3212 }
b99bd4ef 3213
c19d1205
ZW
3214 /* Mark the pool as empty. */
3215 pool->next_free_entry = 0;
3216 pool->symbol = NULL;
b99bd4ef
NC
3217}
3218
c19d1205
ZW
3219#ifdef OBJ_ELF
3220/* Forward declarations for functions below, in the MD interface
3221 section. */
3222static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3223static valueT create_unwind_entry (int);
3224static void start_unwind_section (const segT, int);
3225static void add_unwind_opcode (valueT, int);
3226static void flush_pending_unwind (void);
b99bd4ef 3227
c19d1205 3228/* Directives: Data. */
b99bd4ef 3229
c19d1205
ZW
3230static void
3231s_arm_elf_cons (int nbytes)
3232{
3233 expressionS exp;
b99bd4ef 3234
c19d1205
ZW
3235#ifdef md_flush_pending_output
3236 md_flush_pending_output ();
3237#endif
b99bd4ef 3238
c19d1205 3239 if (is_it_end_of_statement ())
b99bd4ef 3240 {
c19d1205
ZW
3241 demand_empty_rest_of_line ();
3242 return;
b99bd4ef
NC
3243 }
3244
c19d1205
ZW
3245#ifdef md_cons_align
3246 md_cons_align (nbytes);
3247#endif
b99bd4ef 3248
c19d1205
ZW
3249 mapping_state (MAP_DATA);
3250 do
b99bd4ef 3251 {
c19d1205
ZW
3252 int reloc;
3253 char *base = input_line_pointer;
b99bd4ef 3254
c19d1205 3255 expression (& exp);
b99bd4ef 3256
c19d1205
ZW
3257 if (exp.X_op != O_symbol)
3258 emit_expr (&exp, (unsigned int) nbytes);
3259 else
3260 {
3261 char *before_reloc = input_line_pointer;
3262 reloc = parse_reloc (&input_line_pointer);
3263 if (reloc == -1)
3264 {
3265 as_bad (_("unrecognized relocation suffix"));
3266 ignore_rest_of_line ();
3267 return;
3268 }
3269 else if (reloc == BFD_RELOC_UNUSED)
3270 emit_expr (&exp, (unsigned int) nbytes);
3271 else
3272 {
21d799b5
NC
3273 reloc_howto_type *howto = (reloc_howto_type *)
3274 bfd_reloc_type_lookup (stdoutput,
3275 (bfd_reloc_code_real_type) reloc);
c19d1205 3276 int size = bfd_get_reloc_size (howto);
b99bd4ef 3277
2fc8bdac
ZW
3278 if (reloc == BFD_RELOC_ARM_PLT32)
3279 {
3280 as_bad (_("(plt) is only valid on branch targets"));
3281 reloc = BFD_RELOC_UNUSED;
3282 size = 0;
3283 }
3284
c19d1205 3285 if (size > nbytes)
2fc8bdac 3286 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3287 howto->name, nbytes);
3288 else
3289 {
3290 /* We've parsed an expression stopping at O_symbol.
3291 But there may be more expression left now that we
3292 have parsed the relocation marker. Parse it again.
3293 XXX Surely there is a cleaner way to do this. */
3294 char *p = input_line_pointer;
3295 int offset;
21d799b5 3296 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3297 memcpy (save_buf, base, input_line_pointer - base);
3298 memmove (base + (input_line_pointer - before_reloc),
3299 base, before_reloc - base);
3300
3301 input_line_pointer = base + (input_line_pointer-before_reloc);
3302 expression (&exp);
3303 memcpy (base, save_buf, p - base);
3304
3305 offset = nbytes - size;
3306 p = frag_more ((int) nbytes);
3307 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3308 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3309 }
3310 }
3311 }
b99bd4ef 3312 }
c19d1205 3313 while (*input_line_pointer++ == ',');
b99bd4ef 3314
c19d1205
ZW
3315 /* Put terminator back into stream. */
3316 input_line_pointer --;
3317 demand_empty_rest_of_line ();
b99bd4ef
NC
3318}
3319
c921be7d
NC
3320/* Emit an expression containing a 32-bit thumb instruction.
3321 Implementation based on put_thumb32_insn. */
3322
3323static void
3324emit_thumb32_expr (expressionS * exp)
3325{
3326 expressionS exp_high = *exp;
3327
3328 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3329 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3330 exp->X_add_number &= 0xffff;
3331 emit_expr (exp, (unsigned int) THUMB_SIZE);
3332}
3333
3334/* Guess the instruction size based on the opcode. */
3335
3336static int
3337thumb_insn_size (int opcode)
3338{
3339 if ((unsigned int) opcode < 0xe800u)
3340 return 2;
3341 else if ((unsigned int) opcode >= 0xe8000000u)
3342 return 4;
3343 else
3344 return 0;
3345}
3346
3347static bfd_boolean
3348emit_insn (expressionS *exp, int nbytes)
3349{
3350 int size = 0;
3351
3352 if (exp->X_op == O_constant)
3353 {
3354 size = nbytes;
3355
3356 if (size == 0)
3357 size = thumb_insn_size (exp->X_add_number);
3358
3359 if (size != 0)
3360 {
3361 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3362 {
3363 as_bad (_(".inst.n operand too big. "\
3364 "Use .inst.w instead"));
3365 size = 0;
3366 }
3367 else
3368 {
3369 if (now_it.state == AUTOMATIC_IT_BLOCK)
3370 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3371 else
3372 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3373
3374 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3375 emit_thumb32_expr (exp);
3376 else
3377 emit_expr (exp, (unsigned int) size);
3378
3379 it_fsm_post_encode ();
3380 }
3381 }
3382 else
3383 as_bad (_("cannot determine Thumb instruction size. " \
3384 "Use .inst.n/.inst.w instead"));
3385 }
3386 else
3387 as_bad (_("constant expression required"));
3388
3389 return (size != 0);
3390}
3391
3392/* Like s_arm_elf_cons but do not use md_cons_align and
3393 set the mapping state to MAP_ARM/MAP_THUMB. */
3394
3395static void
3396s_arm_elf_inst (int nbytes)
3397{
3398 if (is_it_end_of_statement ())
3399 {
3400 demand_empty_rest_of_line ();
3401 return;
3402 }
3403
3404 /* Calling mapping_state () here will not change ARM/THUMB,
3405 but will ensure not to be in DATA state. */
3406
3407 if (thumb_mode)
3408 mapping_state (MAP_THUMB);
3409 else
3410 {
3411 if (nbytes != 0)
3412 {
3413 as_bad (_("width suffixes are invalid in ARM mode"));
3414 ignore_rest_of_line ();
3415 return;
3416 }
3417
3418 nbytes = 4;
3419
3420 mapping_state (MAP_ARM);
3421 }
3422
3423 do
3424 {
3425 expressionS exp;
3426
3427 expression (& exp);
3428
3429 if (! emit_insn (& exp, nbytes))
3430 {
3431 ignore_rest_of_line ();
3432 return;
3433 }
3434 }
3435 while (*input_line_pointer++ == ',');
3436
3437 /* Put terminator back into stream. */
3438 input_line_pointer --;
3439 demand_empty_rest_of_line ();
3440}
b99bd4ef 3441
c19d1205 3442/* Parse a .rel31 directive. */
b99bd4ef 3443
c19d1205
ZW
3444static void
3445s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3446{
3447 expressionS exp;
3448 char *p;
3449 valueT highbit;
b99bd4ef 3450
c19d1205
ZW
3451 highbit = 0;
3452 if (*input_line_pointer == '1')
3453 highbit = 0x80000000;
3454 else if (*input_line_pointer != '0')
3455 as_bad (_("expected 0 or 1"));
b99bd4ef 3456
c19d1205
ZW
3457 input_line_pointer++;
3458 if (*input_line_pointer != ',')
3459 as_bad (_("missing comma"));
3460 input_line_pointer++;
b99bd4ef 3461
c19d1205
ZW
3462#ifdef md_flush_pending_output
3463 md_flush_pending_output ();
3464#endif
b99bd4ef 3465
c19d1205
ZW
3466#ifdef md_cons_align
3467 md_cons_align (4);
3468#endif
b99bd4ef 3469
c19d1205 3470 mapping_state (MAP_DATA);
b99bd4ef 3471
c19d1205 3472 expression (&exp);
b99bd4ef 3473
c19d1205
ZW
3474 p = frag_more (4);
3475 md_number_to_chars (p, highbit, 4);
3476 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3477 BFD_RELOC_ARM_PREL31);
b99bd4ef 3478
c19d1205 3479 demand_empty_rest_of_line ();
b99bd4ef
NC
3480}
3481
c19d1205 3482/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3483
c19d1205 3484/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3485
c19d1205
ZW
3486static void
3487s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3488{
3489 demand_empty_rest_of_line ();
921e5f0a
PB
3490 if (unwind.proc_start)
3491 {
c921be7d 3492 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3493 return;
3494 }
3495
c19d1205
ZW
3496 /* Mark the start of the function. */
3497 unwind.proc_start = expr_build_dot ();
b99bd4ef 3498
c19d1205
ZW
3499 /* Reset the rest of the unwind info. */
3500 unwind.opcode_count = 0;
3501 unwind.table_entry = NULL;
3502 unwind.personality_routine = NULL;
3503 unwind.personality_index = -1;
3504 unwind.frame_size = 0;
3505 unwind.fp_offset = 0;
fdfde340 3506 unwind.fp_reg = REG_SP;
c19d1205
ZW
3507 unwind.fp_used = 0;
3508 unwind.sp_restored = 0;
3509}
b99bd4ef 3510
b99bd4ef 3511
c19d1205
ZW
3512/* Parse a handlerdata directive. Creates the exception handling table entry
3513 for the function. */
b99bd4ef 3514
c19d1205
ZW
3515static void
3516s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3517{
3518 demand_empty_rest_of_line ();
921e5f0a 3519 if (!unwind.proc_start)
c921be7d 3520 as_bad (MISSING_FNSTART);
921e5f0a 3521
c19d1205 3522 if (unwind.table_entry)
6decc662 3523 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3524
c19d1205
ZW
3525 create_unwind_entry (1);
3526}
a737bd4d 3527
c19d1205 3528/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3529
c19d1205
ZW
3530static void
3531s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3532{
3533 long where;
3534 char *ptr;
3535 valueT val;
940b5ce0 3536 unsigned int marked_pr_dependency;
f02232aa 3537
c19d1205 3538 demand_empty_rest_of_line ();
f02232aa 3539
921e5f0a
PB
3540 if (!unwind.proc_start)
3541 {
c921be7d 3542 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3543 return;
3544 }
3545
c19d1205
ZW
3546 /* Add eh table entry. */
3547 if (unwind.table_entry == NULL)
3548 val = create_unwind_entry (0);
3549 else
3550 val = 0;
f02232aa 3551
c19d1205
ZW
3552 /* Add index table entry. This is two words. */
3553 start_unwind_section (unwind.saved_seg, 1);
3554 frag_align (2, 0, 0);
3555 record_alignment (now_seg, 2);
b99bd4ef 3556
c19d1205 3557 ptr = frag_more (8);
5011093d 3558 memset (ptr, 0, 8);
c19d1205 3559 where = frag_now_fix () - 8;
f02232aa 3560
c19d1205
ZW
3561 /* Self relative offset of the function start. */
3562 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3563 BFD_RELOC_ARM_PREL31);
f02232aa 3564
c19d1205
ZW
3565 /* Indicate dependency on EHABI-defined personality routines to the
3566 linker, if it hasn't been done already. */
940b5ce0
DJ
3567 marked_pr_dependency
3568 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3569 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3570 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3571 {
5f4273c7
NC
3572 static const char *const name[] =
3573 {
3574 "__aeabi_unwind_cpp_pr0",
3575 "__aeabi_unwind_cpp_pr1",
3576 "__aeabi_unwind_cpp_pr2"
3577 };
c19d1205
ZW
3578 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3579 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3580 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3581 |= 1 << unwind.personality_index;
c19d1205 3582 }
f02232aa 3583
c19d1205
ZW
3584 if (val)
3585 /* Inline exception table entry. */
3586 md_number_to_chars (ptr + 4, val, 4);
3587 else
3588 /* Self relative offset of the table entry. */
3589 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3590 BFD_RELOC_ARM_PREL31);
f02232aa 3591
c19d1205
ZW
3592 /* Restore the original section. */
3593 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3594
3595 unwind.proc_start = NULL;
c19d1205 3596}
f02232aa 3597
f02232aa 3598
c19d1205 3599/* Parse an unwind_cantunwind directive. */
b99bd4ef 3600
c19d1205
ZW
3601static void
3602s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3603{
3604 demand_empty_rest_of_line ();
921e5f0a 3605 if (!unwind.proc_start)
c921be7d 3606 as_bad (MISSING_FNSTART);
921e5f0a 3607
c19d1205
ZW
3608 if (unwind.personality_routine || unwind.personality_index != -1)
3609 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3610
c19d1205
ZW
3611 unwind.personality_index = -2;
3612}
b99bd4ef 3613
b99bd4ef 3614
c19d1205 3615/* Parse a personalityindex directive. */
b99bd4ef 3616
c19d1205
ZW
3617static void
3618s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3619{
3620 expressionS exp;
b99bd4ef 3621
921e5f0a 3622 if (!unwind.proc_start)
c921be7d 3623 as_bad (MISSING_FNSTART);
921e5f0a 3624
c19d1205
ZW
3625 if (unwind.personality_routine || unwind.personality_index != -1)
3626 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3627
c19d1205 3628 expression (&exp);
b99bd4ef 3629
c19d1205
ZW
3630 if (exp.X_op != O_constant
3631 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3632 {
c19d1205
ZW
3633 as_bad (_("bad personality routine number"));
3634 ignore_rest_of_line ();
3635 return;
b99bd4ef
NC
3636 }
3637
c19d1205 3638 unwind.personality_index = exp.X_add_number;
b99bd4ef 3639
c19d1205
ZW
3640 demand_empty_rest_of_line ();
3641}
e16bb312 3642
e16bb312 3643
c19d1205 3644/* Parse a personality directive. */
e16bb312 3645
c19d1205
ZW
3646static void
3647s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3648{
3649 char *name, *p, c;
a737bd4d 3650
921e5f0a 3651 if (!unwind.proc_start)
c921be7d 3652 as_bad (MISSING_FNSTART);
921e5f0a 3653
c19d1205
ZW
3654 if (unwind.personality_routine || unwind.personality_index != -1)
3655 as_bad (_("duplicate .personality directive"));
a737bd4d 3656
c19d1205
ZW
3657 name = input_line_pointer;
3658 c = get_symbol_end ();
3659 p = input_line_pointer;
3660 unwind.personality_routine = symbol_find_or_make (name);
3661 *p = c;
3662 demand_empty_rest_of_line ();
3663}
e16bb312 3664
e16bb312 3665
c19d1205 3666/* Parse a directive saving core registers. */
e16bb312 3667
c19d1205
ZW
3668static void
3669s_arm_unwind_save_core (void)
e16bb312 3670{
c19d1205
ZW
3671 valueT op;
3672 long range;
3673 int n;
e16bb312 3674
c19d1205
ZW
3675 range = parse_reg_list (&input_line_pointer);
3676 if (range == FAIL)
e16bb312 3677 {
c19d1205
ZW
3678 as_bad (_("expected register list"));
3679 ignore_rest_of_line ();
3680 return;
3681 }
e16bb312 3682
c19d1205 3683 demand_empty_rest_of_line ();
e16bb312 3684
c19d1205
ZW
3685 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3686 into .unwind_save {..., sp...}. We aren't bothered about the value of
3687 ip because it is clobbered by calls. */
3688 if (unwind.sp_restored && unwind.fp_reg == 12
3689 && (range & 0x3000) == 0x1000)
3690 {
3691 unwind.opcode_count--;
3692 unwind.sp_restored = 0;
3693 range = (range | 0x2000) & ~0x1000;
3694 unwind.pending_offset = 0;
3695 }
e16bb312 3696
01ae4198
DJ
3697 /* Pop r4-r15. */
3698 if (range & 0xfff0)
c19d1205 3699 {
01ae4198
DJ
3700 /* See if we can use the short opcodes. These pop a block of up to 8
3701 registers starting with r4, plus maybe r14. */
3702 for (n = 0; n < 8; n++)
3703 {
3704 /* Break at the first non-saved register. */
3705 if ((range & (1 << (n + 4))) == 0)
3706 break;
3707 }
3708 /* See if there are any other bits set. */
3709 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3710 {
3711 /* Use the long form. */
3712 op = 0x8000 | ((range >> 4) & 0xfff);
3713 add_unwind_opcode (op, 2);
3714 }
0dd132b6 3715 else
01ae4198
DJ
3716 {
3717 /* Use the short form. */
3718 if (range & 0x4000)
3719 op = 0xa8; /* Pop r14. */
3720 else
3721 op = 0xa0; /* Do not pop r14. */
3722 op |= (n - 1);
3723 add_unwind_opcode (op, 1);
3724 }
c19d1205 3725 }
0dd132b6 3726
c19d1205
ZW
3727 /* Pop r0-r3. */
3728 if (range & 0xf)
3729 {
3730 op = 0xb100 | (range & 0xf);
3731 add_unwind_opcode (op, 2);
0dd132b6
NC
3732 }
3733
c19d1205
ZW
3734 /* Record the number of bytes pushed. */
3735 for (n = 0; n < 16; n++)
3736 {
3737 if (range & (1 << n))
3738 unwind.frame_size += 4;
3739 }
0dd132b6
NC
3740}
3741
c19d1205
ZW
3742
3743/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3744
3745static void
c19d1205 3746s_arm_unwind_save_fpa (int reg)
b99bd4ef 3747{
c19d1205
ZW
3748 expressionS exp;
3749 int num_regs;
3750 valueT op;
b99bd4ef 3751
c19d1205
ZW
3752 /* Get Number of registers to transfer. */
3753 if (skip_past_comma (&input_line_pointer) != FAIL)
3754 expression (&exp);
3755 else
3756 exp.X_op = O_illegal;
b99bd4ef 3757
c19d1205 3758 if (exp.X_op != O_constant)
b99bd4ef 3759 {
c19d1205
ZW
3760 as_bad (_("expected , <constant>"));
3761 ignore_rest_of_line ();
b99bd4ef
NC
3762 return;
3763 }
3764
c19d1205
ZW
3765 num_regs = exp.X_add_number;
3766
3767 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3768 {
c19d1205
ZW
3769 as_bad (_("number of registers must be in the range [1:4]"));
3770 ignore_rest_of_line ();
b99bd4ef
NC
3771 return;
3772 }
3773
c19d1205 3774 demand_empty_rest_of_line ();
b99bd4ef 3775
c19d1205
ZW
3776 if (reg == 4)
3777 {
3778 /* Short form. */
3779 op = 0xb4 | (num_regs - 1);
3780 add_unwind_opcode (op, 1);
3781 }
b99bd4ef
NC
3782 else
3783 {
c19d1205
ZW
3784 /* Long form. */
3785 op = 0xc800 | (reg << 4) | (num_regs - 1);
3786 add_unwind_opcode (op, 2);
b99bd4ef 3787 }
c19d1205 3788 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3789}
3790
c19d1205 3791
fa073d69
MS
3792/* Parse a directive saving VFP registers for ARMv6 and above. */
3793
3794static void
3795s_arm_unwind_save_vfp_armv6 (void)
3796{
3797 int count;
3798 unsigned int start;
3799 valueT op;
3800 int num_vfpv3_regs = 0;
3801 int num_regs_below_16;
3802
3803 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3804 if (count == FAIL)
3805 {
3806 as_bad (_("expected register list"));
3807 ignore_rest_of_line ();
3808 return;
3809 }
3810
3811 demand_empty_rest_of_line ();
3812
3813 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3814 than FSTMX/FLDMX-style ones). */
3815
3816 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3817 if (start >= 16)
3818 num_vfpv3_regs = count;
3819 else if (start + count > 16)
3820 num_vfpv3_regs = start + count - 16;
3821
3822 if (num_vfpv3_regs > 0)
3823 {
3824 int start_offset = start > 16 ? start - 16 : 0;
3825 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3826 add_unwind_opcode (op, 2);
3827 }
3828
3829 /* Generate opcode for registers numbered in the range 0 .. 15. */
3830 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3831 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3832 if (num_regs_below_16 > 0)
3833 {
3834 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3835 add_unwind_opcode (op, 2);
3836 }
3837
3838 unwind.frame_size += count * 8;
3839}
3840
3841
3842/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3843
3844static void
c19d1205 3845s_arm_unwind_save_vfp (void)
b99bd4ef 3846{
c19d1205 3847 int count;
ca3f61f7 3848 unsigned int reg;
c19d1205 3849 valueT op;
b99bd4ef 3850
5287ad62 3851 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3852 if (count == FAIL)
b99bd4ef 3853 {
c19d1205
ZW
3854 as_bad (_("expected register list"));
3855 ignore_rest_of_line ();
b99bd4ef
NC
3856 return;
3857 }
3858
c19d1205 3859 demand_empty_rest_of_line ();
b99bd4ef 3860
c19d1205 3861 if (reg == 8)
b99bd4ef 3862 {
c19d1205
ZW
3863 /* Short form. */
3864 op = 0xb8 | (count - 1);
3865 add_unwind_opcode (op, 1);
b99bd4ef 3866 }
c19d1205 3867 else
b99bd4ef 3868 {
c19d1205
ZW
3869 /* Long form. */
3870 op = 0xb300 | (reg << 4) | (count - 1);
3871 add_unwind_opcode (op, 2);
b99bd4ef 3872 }
c19d1205
ZW
3873 unwind.frame_size += count * 8 + 4;
3874}
b99bd4ef 3875
b99bd4ef 3876
c19d1205
ZW
3877/* Parse a directive saving iWMMXt data registers. */
3878
3879static void
3880s_arm_unwind_save_mmxwr (void)
3881{
3882 int reg;
3883 int hi_reg;
3884 int i;
3885 unsigned mask = 0;
3886 valueT op;
b99bd4ef 3887
c19d1205
ZW
3888 if (*input_line_pointer == '{')
3889 input_line_pointer++;
b99bd4ef 3890
c19d1205 3891 do
b99bd4ef 3892 {
dcbf9037 3893 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3894
c19d1205 3895 if (reg == FAIL)
b99bd4ef 3896 {
9b7132d3 3897 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3898 goto error;
b99bd4ef
NC
3899 }
3900
c19d1205
ZW
3901 if (mask >> reg)
3902 as_tsktsk (_("register list not in ascending order"));
3903 mask |= 1 << reg;
b99bd4ef 3904
c19d1205
ZW
3905 if (*input_line_pointer == '-')
3906 {
3907 input_line_pointer++;
dcbf9037 3908 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3909 if (hi_reg == FAIL)
3910 {
9b7132d3 3911 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3912 goto error;
3913 }
3914 else if (reg >= hi_reg)
3915 {
3916 as_bad (_("bad register range"));
3917 goto error;
3918 }
3919 for (; reg < hi_reg; reg++)
3920 mask |= 1 << reg;
3921 }
3922 }
3923 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3924
c19d1205
ZW
3925 if (*input_line_pointer == '}')
3926 input_line_pointer++;
b99bd4ef 3927
c19d1205 3928 demand_empty_rest_of_line ();
b99bd4ef 3929
708587a4 3930 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3931 the list. */
3932 flush_pending_unwind ();
b99bd4ef 3933
c19d1205 3934 for (i = 0; i < 16; i++)
b99bd4ef 3935 {
c19d1205
ZW
3936 if (mask & (1 << i))
3937 unwind.frame_size += 8;
b99bd4ef
NC
3938 }
3939
c19d1205
ZW
3940 /* Attempt to combine with a previous opcode. We do this because gcc
3941 likes to output separate unwind directives for a single block of
3942 registers. */
3943 if (unwind.opcode_count > 0)
b99bd4ef 3944 {
c19d1205
ZW
3945 i = unwind.opcodes[unwind.opcode_count - 1];
3946 if ((i & 0xf8) == 0xc0)
3947 {
3948 i &= 7;
3949 /* Only merge if the blocks are contiguous. */
3950 if (i < 6)
3951 {
3952 if ((mask & 0xfe00) == (1 << 9))
3953 {
3954 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3955 unwind.opcode_count--;
3956 }
3957 }
3958 else if (i == 6 && unwind.opcode_count >= 2)
3959 {
3960 i = unwind.opcodes[unwind.opcode_count - 2];
3961 reg = i >> 4;
3962 i &= 0xf;
b99bd4ef 3963
c19d1205
ZW
3964 op = 0xffff << (reg - 1);
3965 if (reg > 0
87a1fd79 3966 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3967 {
3968 op = (1 << (reg + i + 1)) - 1;
3969 op &= ~((1 << reg) - 1);
3970 mask |= op;
3971 unwind.opcode_count -= 2;
3972 }
3973 }
3974 }
b99bd4ef
NC
3975 }
3976
c19d1205
ZW
3977 hi_reg = 15;
3978 /* We want to generate opcodes in the order the registers have been
3979 saved, ie. descending order. */
3980 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3981 {
c19d1205
ZW
3982 /* Save registers in blocks. */
3983 if (reg < 0
3984 || !(mask & (1 << reg)))
3985 {
3986 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3987 preceding block. */
c19d1205
ZW
3988 if (reg != hi_reg)
3989 {
3990 if (reg == 9)
3991 {
3992 /* Short form. */
3993 op = 0xc0 | (hi_reg - 10);
3994 add_unwind_opcode (op, 1);
3995 }
3996 else
3997 {
3998 /* Long form. */
3999 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4000 add_unwind_opcode (op, 2);
4001 }
4002 }
4003 hi_reg = reg - 1;
4004 }
b99bd4ef
NC
4005 }
4006
c19d1205
ZW
4007 return;
4008error:
4009 ignore_rest_of_line ();
b99bd4ef
NC
4010}
4011
4012static void
c19d1205 4013s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4014{
c19d1205
ZW
4015 int reg;
4016 int hi_reg;
4017 unsigned mask = 0;
4018 valueT op;
b99bd4ef 4019
c19d1205
ZW
4020 if (*input_line_pointer == '{')
4021 input_line_pointer++;
b99bd4ef 4022
c19d1205 4023 do
b99bd4ef 4024 {
dcbf9037 4025 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4026
c19d1205
ZW
4027 if (reg == FAIL)
4028 {
9b7132d3 4029 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4030 goto error;
4031 }
b99bd4ef 4032
c19d1205
ZW
4033 reg -= 8;
4034 if (mask >> reg)
4035 as_tsktsk (_("register list not in ascending order"));
4036 mask |= 1 << reg;
b99bd4ef 4037
c19d1205
ZW
4038 if (*input_line_pointer == '-')
4039 {
4040 input_line_pointer++;
dcbf9037 4041 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4042 if (hi_reg == FAIL)
4043 {
9b7132d3 4044 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4045 goto error;
4046 }
4047 else if (reg >= hi_reg)
4048 {
4049 as_bad (_("bad register range"));
4050 goto error;
4051 }
4052 for (; reg < hi_reg; reg++)
4053 mask |= 1 << reg;
4054 }
b99bd4ef 4055 }
c19d1205 4056 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4057
c19d1205
ZW
4058 if (*input_line_pointer == '}')
4059 input_line_pointer++;
b99bd4ef 4060
c19d1205
ZW
4061 demand_empty_rest_of_line ();
4062
708587a4 4063 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4064 the list. */
4065 flush_pending_unwind ();
b99bd4ef 4066
c19d1205 4067 for (reg = 0; reg < 16; reg++)
b99bd4ef 4068 {
c19d1205
ZW
4069 if (mask & (1 << reg))
4070 unwind.frame_size += 4;
b99bd4ef 4071 }
c19d1205
ZW
4072 op = 0xc700 | mask;
4073 add_unwind_opcode (op, 2);
4074 return;
4075error:
4076 ignore_rest_of_line ();
b99bd4ef
NC
4077}
4078
c19d1205 4079
fa073d69
MS
4080/* Parse an unwind_save directive.
4081 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4082
b99bd4ef 4083static void
fa073d69 4084s_arm_unwind_save (int arch_v6)
b99bd4ef 4085{
c19d1205
ZW
4086 char *peek;
4087 struct reg_entry *reg;
4088 bfd_boolean had_brace = FALSE;
b99bd4ef 4089
921e5f0a 4090 if (!unwind.proc_start)
c921be7d 4091 as_bad (MISSING_FNSTART);
921e5f0a 4092
c19d1205
ZW
4093 /* Figure out what sort of save we have. */
4094 peek = input_line_pointer;
b99bd4ef 4095
c19d1205 4096 if (*peek == '{')
b99bd4ef 4097 {
c19d1205
ZW
4098 had_brace = TRUE;
4099 peek++;
b99bd4ef
NC
4100 }
4101
c19d1205 4102 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4103
c19d1205 4104 if (!reg)
b99bd4ef 4105 {
c19d1205
ZW
4106 as_bad (_("register expected"));
4107 ignore_rest_of_line ();
b99bd4ef
NC
4108 return;
4109 }
4110
c19d1205 4111 switch (reg->type)
b99bd4ef 4112 {
c19d1205
ZW
4113 case REG_TYPE_FN:
4114 if (had_brace)
4115 {
4116 as_bad (_("FPA .unwind_save does not take a register list"));
4117 ignore_rest_of_line ();
4118 return;
4119 }
93ac2687 4120 input_line_pointer = peek;
c19d1205 4121 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4122 return;
c19d1205
ZW
4123
4124 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4125 case REG_TYPE_VFD:
4126 if (arch_v6)
4127 s_arm_unwind_save_vfp_armv6 ();
4128 else
4129 s_arm_unwind_save_vfp ();
4130 return;
c19d1205
ZW
4131 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4132 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4133
4134 default:
4135 as_bad (_(".unwind_save does not support this kind of register"));
4136 ignore_rest_of_line ();
b99bd4ef 4137 }
c19d1205 4138}
b99bd4ef 4139
b99bd4ef 4140
c19d1205
ZW
4141/* Parse an unwind_movsp directive. */
4142
4143static void
4144s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4145{
4146 int reg;
4147 valueT op;
4fa3602b 4148 int offset;
c19d1205 4149
921e5f0a 4150 if (!unwind.proc_start)
c921be7d 4151 as_bad (MISSING_FNSTART);
921e5f0a 4152
dcbf9037 4153 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4154 if (reg == FAIL)
b99bd4ef 4155 {
9b7132d3 4156 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4157 ignore_rest_of_line ();
b99bd4ef
NC
4158 return;
4159 }
4fa3602b
PB
4160
4161 /* Optional constant. */
4162 if (skip_past_comma (&input_line_pointer) != FAIL)
4163 {
4164 if (immediate_for_directive (&offset) == FAIL)
4165 return;
4166 }
4167 else
4168 offset = 0;
4169
c19d1205 4170 demand_empty_rest_of_line ();
b99bd4ef 4171
c19d1205 4172 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4173 {
c19d1205 4174 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4175 return;
4176 }
4177
c19d1205
ZW
4178 if (unwind.fp_reg != REG_SP)
4179 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4180
c19d1205
ZW
4181 /* Generate opcode to restore the value. */
4182 op = 0x90 | reg;
4183 add_unwind_opcode (op, 1);
4184
4185 /* Record the information for later. */
4186 unwind.fp_reg = reg;
4fa3602b 4187 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4188 unwind.sp_restored = 1;
b05fe5cf
ZW
4189}
4190
c19d1205
ZW
4191/* Parse an unwind_pad directive. */
4192
b05fe5cf 4193static void
c19d1205 4194s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4195{
c19d1205 4196 int offset;
b05fe5cf 4197
921e5f0a 4198 if (!unwind.proc_start)
c921be7d 4199 as_bad (MISSING_FNSTART);
921e5f0a 4200
c19d1205
ZW
4201 if (immediate_for_directive (&offset) == FAIL)
4202 return;
b99bd4ef 4203
c19d1205
ZW
4204 if (offset & 3)
4205 {
4206 as_bad (_("stack increment must be multiple of 4"));
4207 ignore_rest_of_line ();
4208 return;
4209 }
b99bd4ef 4210
c19d1205
ZW
4211 /* Don't generate any opcodes, just record the details for later. */
4212 unwind.frame_size += offset;
4213 unwind.pending_offset += offset;
4214
4215 demand_empty_rest_of_line ();
4216}
4217
4218/* Parse an unwind_setfp directive. */
4219
4220static void
4221s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4222{
c19d1205
ZW
4223 int sp_reg;
4224 int fp_reg;
4225 int offset;
4226
921e5f0a 4227 if (!unwind.proc_start)
c921be7d 4228 as_bad (MISSING_FNSTART);
921e5f0a 4229
dcbf9037 4230 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4231 if (skip_past_comma (&input_line_pointer) == FAIL)
4232 sp_reg = FAIL;
4233 else
dcbf9037 4234 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4235
c19d1205
ZW
4236 if (fp_reg == FAIL || sp_reg == FAIL)
4237 {
4238 as_bad (_("expected <reg>, <reg>"));
4239 ignore_rest_of_line ();
4240 return;
4241 }
b99bd4ef 4242
c19d1205
ZW
4243 /* Optional constant. */
4244 if (skip_past_comma (&input_line_pointer) != FAIL)
4245 {
4246 if (immediate_for_directive (&offset) == FAIL)
4247 return;
4248 }
4249 else
4250 offset = 0;
a737bd4d 4251
c19d1205 4252 demand_empty_rest_of_line ();
a737bd4d 4253
fdfde340 4254 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4255 {
c19d1205
ZW
4256 as_bad (_("register must be either sp or set by a previous"
4257 "unwind_movsp directive"));
4258 return;
a737bd4d
NC
4259 }
4260
c19d1205
ZW
4261 /* Don't generate any opcodes, just record the information for later. */
4262 unwind.fp_reg = fp_reg;
4263 unwind.fp_used = 1;
fdfde340 4264 if (sp_reg == REG_SP)
c19d1205
ZW
4265 unwind.fp_offset = unwind.frame_size - offset;
4266 else
4267 unwind.fp_offset -= offset;
a737bd4d
NC
4268}
4269
c19d1205
ZW
4270/* Parse an unwind_raw directive. */
4271
4272static void
4273s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4274{
c19d1205 4275 expressionS exp;
708587a4 4276 /* This is an arbitrary limit. */
c19d1205
ZW
4277 unsigned char op[16];
4278 int count;
a737bd4d 4279
921e5f0a 4280 if (!unwind.proc_start)
c921be7d 4281 as_bad (MISSING_FNSTART);
921e5f0a 4282
c19d1205
ZW
4283 expression (&exp);
4284 if (exp.X_op == O_constant
4285 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4286 {
c19d1205
ZW
4287 unwind.frame_size += exp.X_add_number;
4288 expression (&exp);
4289 }
4290 else
4291 exp.X_op = O_illegal;
a737bd4d 4292
c19d1205
ZW
4293 if (exp.X_op != O_constant)
4294 {
4295 as_bad (_("expected <offset>, <opcode>"));
4296 ignore_rest_of_line ();
4297 return;
4298 }
a737bd4d 4299
c19d1205 4300 count = 0;
a737bd4d 4301
c19d1205
ZW
4302 /* Parse the opcode. */
4303 for (;;)
4304 {
4305 if (count >= 16)
4306 {
4307 as_bad (_("unwind opcode too long"));
4308 ignore_rest_of_line ();
a737bd4d 4309 }
c19d1205 4310 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4311 {
c19d1205
ZW
4312 as_bad (_("invalid unwind opcode"));
4313 ignore_rest_of_line ();
4314 return;
a737bd4d 4315 }
c19d1205 4316 op[count++] = exp.X_add_number;
a737bd4d 4317
c19d1205
ZW
4318 /* Parse the next byte. */
4319 if (skip_past_comma (&input_line_pointer) == FAIL)
4320 break;
a737bd4d 4321
c19d1205
ZW
4322 expression (&exp);
4323 }
b99bd4ef 4324
c19d1205
ZW
4325 /* Add the opcode bytes in reverse order. */
4326 while (count--)
4327 add_unwind_opcode (op[count], 1);
b99bd4ef 4328
c19d1205 4329 demand_empty_rest_of_line ();
b99bd4ef 4330}
ee065d83
PB
4331
4332
4333/* Parse a .eabi_attribute directive. */
4334
4335static void
4336s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4337{
ee3c0378
AS
4338 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4339
4340 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4341 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4342}
4343
0855e32b
NS
4344/* Emit a tls fix for the symbol. */
4345
4346static void
4347s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4348{
4349 char *p;
4350 expressionS exp;
4351#ifdef md_flush_pending_output
4352 md_flush_pending_output ();
4353#endif
4354
4355#ifdef md_cons_align
4356 md_cons_align (4);
4357#endif
4358
4359 /* Since we're just labelling the code, there's no need to define a
4360 mapping symbol. */
4361 expression (&exp);
4362 p = obstack_next_free (&frchain_now->frch_obstack);
4363 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4364 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4365 : BFD_RELOC_ARM_TLS_DESCSEQ);
4366}
cdf9ccec 4367#endif /* OBJ_ELF */
0855e32b 4368
ee065d83 4369static void s_arm_arch (int);
7a1d4c38 4370static void s_arm_object_arch (int);
ee065d83
PB
4371static void s_arm_cpu (int);
4372static void s_arm_fpu (int);
69133863 4373static void s_arm_arch_extension (int);
b99bd4ef 4374
f0927246
NC
4375#ifdef TE_PE
4376
4377static void
5f4273c7 4378pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4379{
4380 expressionS exp;
4381
4382 do
4383 {
4384 expression (&exp);
4385 if (exp.X_op == O_symbol)
4386 exp.X_op = O_secrel;
4387
4388 emit_expr (&exp, 4);
4389 }
4390 while (*input_line_pointer++ == ',');
4391
4392 input_line_pointer--;
4393 demand_empty_rest_of_line ();
4394}
4395#endif /* TE_PE */
4396
c19d1205
ZW
4397/* This table describes all the machine specific pseudo-ops the assembler
4398 has to support. The fields are:
4399 pseudo-op name without dot
4400 function to call to execute this pseudo-op
4401 Integer arg to pass to the function. */
b99bd4ef 4402
c19d1205 4403const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4404{
c19d1205
ZW
4405 /* Never called because '.req' does not start a line. */
4406 { "req", s_req, 0 },
dcbf9037
JB
4407 /* Following two are likewise never called. */
4408 { "dn", s_dn, 0 },
4409 { "qn", s_qn, 0 },
c19d1205
ZW
4410 { "unreq", s_unreq, 0 },
4411 { "bss", s_bss, 0 },
4412 { "align", s_align, 0 },
4413 { "arm", s_arm, 0 },
4414 { "thumb", s_thumb, 0 },
4415 { "code", s_code, 0 },
4416 { "force_thumb", s_force_thumb, 0 },
4417 { "thumb_func", s_thumb_func, 0 },
4418 { "thumb_set", s_thumb_set, 0 },
4419 { "even", s_even, 0 },
4420 { "ltorg", s_ltorg, 0 },
4421 { "pool", s_ltorg, 0 },
4422 { "syntax", s_syntax, 0 },
8463be01
PB
4423 { "cpu", s_arm_cpu, 0 },
4424 { "arch", s_arm_arch, 0 },
7a1d4c38 4425 { "object_arch", s_arm_object_arch, 0 },
8463be01 4426 { "fpu", s_arm_fpu, 0 },
69133863 4427 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4428#ifdef OBJ_ELF
c921be7d
NC
4429 { "word", s_arm_elf_cons, 4 },
4430 { "long", s_arm_elf_cons, 4 },
4431 { "inst.n", s_arm_elf_inst, 2 },
4432 { "inst.w", s_arm_elf_inst, 4 },
4433 { "inst", s_arm_elf_inst, 0 },
4434 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4435 { "fnstart", s_arm_unwind_fnstart, 0 },
4436 { "fnend", s_arm_unwind_fnend, 0 },
4437 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4438 { "personality", s_arm_unwind_personality, 0 },
4439 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4440 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4441 { "save", s_arm_unwind_save, 0 },
fa073d69 4442 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4443 { "movsp", s_arm_unwind_movsp, 0 },
4444 { "pad", s_arm_unwind_pad, 0 },
4445 { "setfp", s_arm_unwind_setfp, 0 },
4446 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4447 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4448 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4449#else
4450 { "word", cons, 4},
f0927246
NC
4451
4452 /* These are used for dwarf. */
4453 {"2byte", cons, 2},
4454 {"4byte", cons, 4},
4455 {"8byte", cons, 8},
4456 /* These are used for dwarf2. */
4457 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4458 { "loc", dwarf2_directive_loc, 0 },
4459 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4460#endif
4461 { "extend", float_cons, 'x' },
4462 { "ldouble", float_cons, 'x' },
4463 { "packed", float_cons, 'p' },
f0927246
NC
4464#ifdef TE_PE
4465 {"secrel32", pe_directive_secrel, 0},
4466#endif
c19d1205
ZW
4467 { 0, 0, 0 }
4468};
4469\f
4470/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4471
c19d1205
ZW
4472/* Generic immediate-value read function for use in insn parsing.
4473 STR points to the beginning of the immediate (the leading #);
4474 VAL receives the value; if the value is outside [MIN, MAX]
4475 issue an error. PREFIX_OPT is true if the immediate prefix is
4476 optional. */
b99bd4ef 4477
c19d1205
ZW
4478static int
4479parse_immediate (char **str, int *val, int min, int max,
4480 bfd_boolean prefix_opt)
4481{
4482 expressionS exp;
4483 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4484 if (exp.X_op != O_constant)
b99bd4ef 4485 {
c19d1205
ZW
4486 inst.error = _("constant expression required");
4487 return FAIL;
4488 }
b99bd4ef 4489
c19d1205
ZW
4490 if (exp.X_add_number < min || exp.X_add_number > max)
4491 {
4492 inst.error = _("immediate value out of range");
4493 return FAIL;
4494 }
b99bd4ef 4495
c19d1205
ZW
4496 *val = exp.X_add_number;
4497 return SUCCESS;
4498}
b99bd4ef 4499
5287ad62 4500/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4501 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4502 instructions. Puts the result directly in inst.operands[i]. */
4503
4504static int
4505parse_big_immediate (char **str, int i)
4506{
4507 expressionS exp;
4508 char *ptr = *str;
4509
4510 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4511
4512 if (exp.X_op == O_constant)
036dc3f7
PB
4513 {
4514 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4515 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4516 O_constant. We have to be careful not to break compilation for
4517 32-bit X_add_number, though. */
58ad575f 4518 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7
PB
4519 {
4520 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4521 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4522 inst.operands[i].regisimm = 1;
4523 }
4524 }
5287ad62 4525 else if (exp.X_op == O_big
95b75c01 4526 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
5287ad62
JB
4527 {
4528 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4529
5287ad62
JB
4530 /* Bignums have their least significant bits in
4531 generic_bignum[0]. Make sure we put 32 bits in imm and
4532 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4533 gas_assert (parts != 0);
95b75c01
NC
4534
4535 /* Make sure that the number is not too big.
4536 PR 11972: Bignums can now be sign-extended to the
4537 size of a .octa so check that the out of range bits
4538 are all zero or all one. */
4539 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4540 {
4541 LITTLENUM_TYPE m = -1;
4542
4543 if (generic_bignum[parts * 2] != 0
4544 && generic_bignum[parts * 2] != m)
4545 return FAIL;
4546
4547 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4548 if (generic_bignum[j] != generic_bignum[j-1])
4549 return FAIL;
4550 }
4551
5287ad62
JB
4552 inst.operands[i].imm = 0;
4553 for (j = 0; j < parts; j++, idx++)
4554 inst.operands[i].imm |= generic_bignum[idx]
4555 << (LITTLENUM_NUMBER_OF_BITS * j);
4556 inst.operands[i].reg = 0;
4557 for (j = 0; j < parts; j++, idx++)
4558 inst.operands[i].reg |= generic_bignum[idx]
4559 << (LITTLENUM_NUMBER_OF_BITS * j);
4560 inst.operands[i].regisimm = 1;
4561 }
4562 else
4563 return FAIL;
5f4273c7 4564
5287ad62
JB
4565 *str = ptr;
4566
4567 return SUCCESS;
4568}
4569
c19d1205
ZW
4570/* Returns the pseudo-register number of an FPA immediate constant,
4571 or FAIL if there isn't a valid constant here. */
b99bd4ef 4572
c19d1205
ZW
4573static int
4574parse_fpa_immediate (char ** str)
4575{
4576 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4577 char * save_in;
4578 expressionS exp;
4579 int i;
4580 int j;
b99bd4ef 4581
c19d1205
ZW
4582 /* First try and match exact strings, this is to guarantee
4583 that some formats will work even for cross assembly. */
b99bd4ef 4584
c19d1205
ZW
4585 for (i = 0; fp_const[i]; i++)
4586 {
4587 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4588 {
c19d1205 4589 char *start = *str;
b99bd4ef 4590
c19d1205
ZW
4591 *str += strlen (fp_const[i]);
4592 if (is_end_of_line[(unsigned char) **str])
4593 return i + 8;
4594 *str = start;
4595 }
4596 }
b99bd4ef 4597
c19d1205
ZW
4598 /* Just because we didn't get a match doesn't mean that the constant
4599 isn't valid, just that it is in a format that we don't
4600 automatically recognize. Try parsing it with the standard
4601 expression routines. */
b99bd4ef 4602
c19d1205 4603 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4604
c19d1205
ZW
4605 /* Look for a raw floating point number. */
4606 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4607 && is_end_of_line[(unsigned char) *save_in])
4608 {
4609 for (i = 0; i < NUM_FLOAT_VALS; i++)
4610 {
4611 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4612 {
c19d1205
ZW
4613 if (words[j] != fp_values[i][j])
4614 break;
b99bd4ef
NC
4615 }
4616
c19d1205 4617 if (j == MAX_LITTLENUMS)
b99bd4ef 4618 {
c19d1205
ZW
4619 *str = save_in;
4620 return i + 8;
b99bd4ef
NC
4621 }
4622 }
4623 }
b99bd4ef 4624
c19d1205
ZW
4625 /* Try and parse a more complex expression, this will probably fail
4626 unless the code uses a floating point prefix (eg "0f"). */
4627 save_in = input_line_pointer;
4628 input_line_pointer = *str;
4629 if (expression (&exp) == absolute_section
4630 && exp.X_op == O_big
4631 && exp.X_add_number < 0)
4632 {
4633 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4634 Ditto for 15. */
4635 if (gen_to_words (words, 5, (long) 15) == 0)
4636 {
4637 for (i = 0; i < NUM_FLOAT_VALS; i++)
4638 {
4639 for (j = 0; j < MAX_LITTLENUMS; j++)
4640 {
4641 if (words[j] != fp_values[i][j])
4642 break;
4643 }
b99bd4ef 4644
c19d1205
ZW
4645 if (j == MAX_LITTLENUMS)
4646 {
4647 *str = input_line_pointer;
4648 input_line_pointer = save_in;
4649 return i + 8;
4650 }
4651 }
4652 }
b99bd4ef
NC
4653 }
4654
c19d1205
ZW
4655 *str = input_line_pointer;
4656 input_line_pointer = save_in;
4657 inst.error = _("invalid FPA immediate expression");
4658 return FAIL;
b99bd4ef
NC
4659}
4660
136da414
JB
4661/* Returns 1 if a number has "quarter-precision" float format
4662 0baBbbbbbc defgh000 00000000 00000000. */
4663
4664static int
4665is_quarter_float (unsigned imm)
4666{
4667 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4668 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4669}
4670
4671/* Parse an 8-bit "quarter-precision" floating point number of the form:
4672 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4673 The zero and minus-zero cases need special handling, since they can't be
4674 encoded in the "quarter-precision" float format, but can nonetheless be
4675 loaded as integer constants. */
136da414
JB
4676
4677static unsigned
4678parse_qfloat_immediate (char **ccp, int *immed)
4679{
4680 char *str = *ccp;
c96612cc 4681 char *fpnum;
136da414 4682 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4683 int found_fpchar = 0;
5f4273c7 4684
136da414 4685 skip_past_char (&str, '#');
5f4273c7 4686
c96612cc
JB
4687 /* We must not accidentally parse an integer as a floating-point number. Make
4688 sure that the value we parse is not an integer by checking for special
4689 characters '.' or 'e'.
4690 FIXME: This is a horrible hack, but doing better is tricky because type
4691 information isn't in a very usable state at parse time. */
4692 fpnum = str;
4693 skip_whitespace (fpnum);
4694
4695 if (strncmp (fpnum, "0x", 2) == 0)
4696 return FAIL;
4697 else
4698 {
4699 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4700 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4701 {
4702 found_fpchar = 1;
4703 break;
4704 }
4705
4706 if (!found_fpchar)
4707 return FAIL;
4708 }
5f4273c7 4709
136da414
JB
4710 if ((str = atof_ieee (str, 's', words)) != NULL)
4711 {
4712 unsigned fpword = 0;
4713 int i;
5f4273c7 4714
136da414
JB
4715 /* Our FP word must be 32 bits (single-precision FP). */
4716 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4717 {
4718 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4719 fpword |= words[i];
4720 }
5f4273c7 4721
c96612cc 4722 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4723 *immed = fpword;
4724 else
4725 return FAIL;
4726
4727 *ccp = str;
5f4273c7 4728
136da414
JB
4729 return SUCCESS;
4730 }
5f4273c7 4731
136da414
JB
4732 return FAIL;
4733}
4734
c19d1205
ZW
4735/* Shift operands. */
4736enum shift_kind
b99bd4ef 4737{
c19d1205
ZW
4738 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4739};
b99bd4ef 4740
c19d1205
ZW
4741struct asm_shift_name
4742{
4743 const char *name;
4744 enum shift_kind kind;
4745};
b99bd4ef 4746
c19d1205
ZW
4747/* Third argument to parse_shift. */
4748enum parse_shift_mode
4749{
4750 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4751 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4752 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4753 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4754 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4755};
b99bd4ef 4756
c19d1205
ZW
4757/* Parse a <shift> specifier on an ARM data processing instruction.
4758 This has three forms:
b99bd4ef 4759
c19d1205
ZW
4760 (LSL|LSR|ASL|ASR|ROR) Rs
4761 (LSL|LSR|ASL|ASR|ROR) #imm
4762 RRX
b99bd4ef 4763
c19d1205
ZW
4764 Note that ASL is assimilated to LSL in the instruction encoding, and
4765 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4766
c19d1205
ZW
4767static int
4768parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4769{
c19d1205
ZW
4770 const struct asm_shift_name *shift_name;
4771 enum shift_kind shift;
4772 char *s = *str;
4773 char *p = s;
4774 int reg;
b99bd4ef 4775
c19d1205
ZW
4776 for (p = *str; ISALPHA (*p); p++)
4777 ;
b99bd4ef 4778
c19d1205 4779 if (p == *str)
b99bd4ef 4780 {
c19d1205
ZW
4781 inst.error = _("shift expression expected");
4782 return FAIL;
b99bd4ef
NC
4783 }
4784
21d799b5
NC
4785 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4786 p - *str);
c19d1205
ZW
4787
4788 if (shift_name == NULL)
b99bd4ef 4789 {
c19d1205
ZW
4790 inst.error = _("shift expression expected");
4791 return FAIL;
b99bd4ef
NC
4792 }
4793
c19d1205 4794 shift = shift_name->kind;
b99bd4ef 4795
c19d1205
ZW
4796 switch (mode)
4797 {
4798 case NO_SHIFT_RESTRICT:
4799 case SHIFT_IMMEDIATE: break;
b99bd4ef 4800
c19d1205
ZW
4801 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4802 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4803 {
4804 inst.error = _("'LSL' or 'ASR' required");
4805 return FAIL;
4806 }
4807 break;
b99bd4ef 4808
c19d1205
ZW
4809 case SHIFT_LSL_IMMEDIATE:
4810 if (shift != SHIFT_LSL)
4811 {
4812 inst.error = _("'LSL' required");
4813 return FAIL;
4814 }
4815 break;
b99bd4ef 4816
c19d1205
ZW
4817 case SHIFT_ASR_IMMEDIATE:
4818 if (shift != SHIFT_ASR)
4819 {
4820 inst.error = _("'ASR' required");
4821 return FAIL;
4822 }
4823 break;
b99bd4ef 4824
c19d1205
ZW
4825 default: abort ();
4826 }
b99bd4ef 4827
c19d1205
ZW
4828 if (shift != SHIFT_RRX)
4829 {
4830 /* Whitespace can appear here if the next thing is a bare digit. */
4831 skip_whitespace (p);
b99bd4ef 4832
c19d1205 4833 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4834 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4835 {
4836 inst.operands[i].imm = reg;
4837 inst.operands[i].immisreg = 1;
4838 }
4839 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4840 return FAIL;
4841 }
4842 inst.operands[i].shift_kind = shift;
4843 inst.operands[i].shifted = 1;
4844 *str = p;
4845 return SUCCESS;
b99bd4ef
NC
4846}
4847
c19d1205 4848/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4849
c19d1205
ZW
4850 #<immediate>
4851 #<immediate>, <rotate>
4852 <Rm>
4853 <Rm>, <shift>
b99bd4ef 4854
c19d1205
ZW
4855 where <shift> is defined by parse_shift above, and <rotate> is a
4856 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4857 is deferred to md_apply_fix. */
b99bd4ef 4858
c19d1205
ZW
4859static int
4860parse_shifter_operand (char **str, int i)
4861{
4862 int value;
91d6fa6a 4863 expressionS exp;
b99bd4ef 4864
dcbf9037 4865 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4866 {
4867 inst.operands[i].reg = value;
4868 inst.operands[i].isreg = 1;
b99bd4ef 4869
c19d1205
ZW
4870 /* parse_shift will override this if appropriate */
4871 inst.reloc.exp.X_op = O_constant;
4872 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4873
c19d1205
ZW
4874 if (skip_past_comma (str) == FAIL)
4875 return SUCCESS;
b99bd4ef 4876
c19d1205
ZW
4877 /* Shift operation on register. */
4878 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4879 }
4880
c19d1205
ZW
4881 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4882 return FAIL;
b99bd4ef 4883
c19d1205 4884 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4885 {
c19d1205 4886 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4887 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4888 return FAIL;
b99bd4ef 4889
91d6fa6a 4890 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4891 {
4892 inst.error = _("constant expression expected");
4893 return FAIL;
4894 }
b99bd4ef 4895
91d6fa6a 4896 value = exp.X_add_number;
c19d1205
ZW
4897 if (value < 0 || value > 30 || value % 2 != 0)
4898 {
4899 inst.error = _("invalid rotation");
4900 return FAIL;
4901 }
4902 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4903 {
4904 inst.error = _("invalid constant");
4905 return FAIL;
4906 }
09d92015 4907
a415b1cd
JB
4908 /* Encode as specified. */
4909 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4910 return SUCCESS;
09d92015
MM
4911 }
4912
c19d1205
ZW
4913 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4914 inst.reloc.pc_rel = 0;
4915 return SUCCESS;
09d92015
MM
4916}
4917
4962c51a
MS
4918/* Group relocation information. Each entry in the table contains the
4919 textual name of the relocation as may appear in assembler source
4920 and must end with a colon.
4921 Along with this textual name are the relocation codes to be used if
4922 the corresponding instruction is an ALU instruction (ADD or SUB only),
4923 an LDR, an LDRS, or an LDC. */
4924
4925struct group_reloc_table_entry
4926{
4927 const char *name;
4928 int alu_code;
4929 int ldr_code;
4930 int ldrs_code;
4931 int ldc_code;
4932};
4933
4934typedef enum
4935{
4936 /* Varieties of non-ALU group relocation. */
4937
4938 GROUP_LDR,
4939 GROUP_LDRS,
4940 GROUP_LDC
4941} group_reloc_type;
4942
4943static struct group_reloc_table_entry group_reloc_table[] =
4944 { /* Program counter relative: */
4945 { "pc_g0_nc",
4946 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4947 0, /* LDR */
4948 0, /* LDRS */
4949 0 }, /* LDC */
4950 { "pc_g0",
4951 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4952 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4953 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4954 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4955 { "pc_g1_nc",
4956 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4957 0, /* LDR */
4958 0, /* LDRS */
4959 0 }, /* LDC */
4960 { "pc_g1",
4961 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4962 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4963 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4964 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4965 { "pc_g2",
4966 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4967 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4968 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4969 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4970 /* Section base relative */
4971 { "sb_g0_nc",
4972 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4973 0, /* LDR */
4974 0, /* LDRS */
4975 0 }, /* LDC */
4976 { "sb_g0",
4977 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4978 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4979 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4980 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4981 { "sb_g1_nc",
4982 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4983 0, /* LDR */
4984 0, /* LDRS */
4985 0 }, /* LDC */
4986 { "sb_g1",
4987 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4988 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4989 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4990 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4991 { "sb_g2",
4992 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4993 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4994 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4995 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4996
4997/* Given the address of a pointer pointing to the textual name of a group
4998 relocation as may appear in assembler source, attempt to find its details
4999 in group_reloc_table. The pointer will be updated to the character after
5000 the trailing colon. On failure, FAIL will be returned; SUCCESS
5001 otherwise. On success, *entry will be updated to point at the relevant
5002 group_reloc_table entry. */
5003
5004static int
5005find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5006{
5007 unsigned int i;
5008 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5009 {
5010 int length = strlen (group_reloc_table[i].name);
5011
5f4273c7
NC
5012 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5013 && (*str)[length] == ':')
4962c51a
MS
5014 {
5015 *out = &group_reloc_table[i];
5016 *str += (length + 1);
5017 return SUCCESS;
5018 }
5019 }
5020
5021 return FAIL;
5022}
5023
5024/* Parse a <shifter_operand> for an ARM data processing instruction
5025 (as for parse_shifter_operand) where group relocations are allowed:
5026
5027 #<immediate>
5028 #<immediate>, <rotate>
5029 #:<group_reloc>:<expression>
5030 <Rm>
5031 <Rm>, <shift>
5032
5033 where <group_reloc> is one of the strings defined in group_reloc_table.
5034 The hashes are optional.
5035
5036 Everything else is as for parse_shifter_operand. */
5037
5038static parse_operand_result
5039parse_shifter_operand_group_reloc (char **str, int i)
5040{
5041 /* Determine if we have the sequence of characters #: or just :
5042 coming next. If we do, then we check for a group relocation.
5043 If we don't, punt the whole lot to parse_shifter_operand. */
5044
5045 if (((*str)[0] == '#' && (*str)[1] == ':')
5046 || (*str)[0] == ':')
5047 {
5048 struct group_reloc_table_entry *entry;
5049
5050 if ((*str)[0] == '#')
5051 (*str) += 2;
5052 else
5053 (*str)++;
5054
5055 /* Try to parse a group relocation. Anything else is an error. */
5056 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5057 {
5058 inst.error = _("unknown group relocation");
5059 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5060 }
5061
5062 /* We now have the group relocation table entry corresponding to
5063 the name in the assembler source. Next, we parse the expression. */
5064 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5065 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5066
5067 /* Record the relocation type (always the ALU variant here). */
21d799b5 5068 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5069 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5070
5071 return PARSE_OPERAND_SUCCESS;
5072 }
5073 else
5074 return parse_shifter_operand (str, i) == SUCCESS
5075 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5076
5077 /* Never reached. */
5078}
5079
8e560766
MGD
5080/* Parse a Neon alignment expression. Information is written to
5081 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5082
8e560766
MGD
5083 align .imm = align << 8, .immisalign=1, .preind=0 */
5084static parse_operand_result
5085parse_neon_alignment (char **str, int i)
5086{
5087 char *p = *str;
5088 expressionS exp;
5089
5090 my_get_expression (&exp, &p, GE_NO_PREFIX);
5091
5092 if (exp.X_op != O_constant)
5093 {
5094 inst.error = _("alignment must be constant");
5095 return PARSE_OPERAND_FAIL;
5096 }
5097
5098 inst.operands[i].imm = exp.X_add_number << 8;
5099 inst.operands[i].immisalign = 1;
5100 /* Alignments are not pre-indexes. */
5101 inst.operands[i].preind = 0;
5102
5103 *str = p;
5104 return PARSE_OPERAND_SUCCESS;
5105}
5106
c19d1205
ZW
5107/* Parse all forms of an ARM address expression. Information is written
5108 to inst.operands[i] and/or inst.reloc.
09d92015 5109
c19d1205 5110 Preindexed addressing (.preind=1):
09d92015 5111
c19d1205
ZW
5112 [Rn, #offset] .reg=Rn .reloc.exp=offset
5113 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5114 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5115 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5116
c19d1205 5117 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5118
c19d1205 5119 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5120
c19d1205
ZW
5121 [Rn], #offset .reg=Rn .reloc.exp=offset
5122 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5123 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5124 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5125
c19d1205 5126 Unindexed addressing (.preind=0, .postind=0):
09d92015 5127
c19d1205 5128 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5129
c19d1205 5130 Other:
09d92015 5131
c19d1205
ZW
5132 [Rn]{!} shorthand for [Rn,#0]{!}
5133 =immediate .isreg=0 .reloc.exp=immediate
5134 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5135
c19d1205
ZW
5136 It is the caller's responsibility to check for addressing modes not
5137 supported by the instruction, and to set inst.reloc.type. */
5138
4962c51a
MS
5139static parse_operand_result
5140parse_address_main (char **str, int i, int group_relocations,
5141 group_reloc_type group_type)
09d92015 5142{
c19d1205
ZW
5143 char *p = *str;
5144 int reg;
09d92015 5145
c19d1205 5146 if (skip_past_char (&p, '[') == FAIL)
09d92015 5147 {
c19d1205
ZW
5148 if (skip_past_char (&p, '=') == FAIL)
5149 {
974da60d 5150 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5151 inst.reloc.pc_rel = 1;
5152 inst.operands[i].reg = REG_PC;
5153 inst.operands[i].isreg = 1;
5154 inst.operands[i].preind = 1;
5155 }
974da60d 5156 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5157
c19d1205 5158 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5159 return PARSE_OPERAND_FAIL;
09d92015 5160
c19d1205 5161 *str = p;
4962c51a 5162 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5163 }
5164
dcbf9037 5165 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5166 {
c19d1205 5167 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5168 return PARSE_OPERAND_FAIL;
09d92015 5169 }
c19d1205
ZW
5170 inst.operands[i].reg = reg;
5171 inst.operands[i].isreg = 1;
09d92015 5172
c19d1205 5173 if (skip_past_comma (&p) == SUCCESS)
09d92015 5174 {
c19d1205 5175 inst.operands[i].preind = 1;
09d92015 5176
c19d1205
ZW
5177 if (*p == '+') p++;
5178 else if (*p == '-') p++, inst.operands[i].negative = 1;
5179
dcbf9037 5180 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5181 {
c19d1205
ZW
5182 inst.operands[i].imm = reg;
5183 inst.operands[i].immisreg = 1;
5184
5185 if (skip_past_comma (&p) == SUCCESS)
5186 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5187 return PARSE_OPERAND_FAIL;
c19d1205 5188 }
5287ad62 5189 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5190 {
5191 /* FIXME: '@' should be used here, but it's filtered out by generic
5192 code before we get to see it here. This may be subject to
5193 change. */
5194 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5195
8e560766
MGD
5196 if (result != PARSE_OPERAND_SUCCESS)
5197 return result;
5198 }
c19d1205
ZW
5199 else
5200 {
5201 if (inst.operands[i].negative)
5202 {
5203 inst.operands[i].negative = 0;
5204 p--;
5205 }
4962c51a 5206
5f4273c7
NC
5207 if (group_relocations
5208 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5209 {
5210 struct group_reloc_table_entry *entry;
5211
5212 /* Skip over the #: or : sequence. */
5213 if (*p == '#')
5214 p += 2;
5215 else
5216 p++;
5217
5218 /* Try to parse a group relocation. Anything else is an
5219 error. */
5220 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5221 {
5222 inst.error = _("unknown group relocation");
5223 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5224 }
5225
5226 /* We now have the group relocation table entry corresponding to
5227 the name in the assembler source. Next, we parse the
5228 expression. */
5229 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5230 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5231
5232 /* Record the relocation type. */
5233 switch (group_type)
5234 {
5235 case GROUP_LDR:
21d799b5 5236 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5237 break;
5238
5239 case GROUP_LDRS:
21d799b5 5240 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5241 break;
5242
5243 case GROUP_LDC:
21d799b5 5244 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5245 break;
5246
5247 default:
9c2799c2 5248 gas_assert (0);
4962c51a
MS
5249 }
5250
5251 if (inst.reloc.type == 0)
5252 {
5253 inst.error = _("this group relocation is not allowed on this instruction");
5254 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5255 }
5256 }
5257 else
26d97720
NS
5258 {
5259 char *q = p;
5260 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5261 return PARSE_OPERAND_FAIL;
5262 /* If the offset is 0, find out if it's a +0 or -0. */
5263 if (inst.reloc.exp.X_op == O_constant
5264 && inst.reloc.exp.X_add_number == 0)
5265 {
5266 skip_whitespace (q);
5267 if (*q == '#')
5268 {
5269 q++;
5270 skip_whitespace (q);
5271 }
5272 if (*q == '-')
5273 inst.operands[i].negative = 1;
5274 }
5275 }
09d92015
MM
5276 }
5277 }
8e560766
MGD
5278 else if (skip_past_char (&p, ':') == SUCCESS)
5279 {
5280 /* FIXME: '@' should be used here, but it's filtered out by generic code
5281 before we get to see it here. This may be subject to change. */
5282 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5283
8e560766
MGD
5284 if (result != PARSE_OPERAND_SUCCESS)
5285 return result;
5286 }
09d92015 5287
c19d1205 5288 if (skip_past_char (&p, ']') == FAIL)
09d92015 5289 {
c19d1205 5290 inst.error = _("']' expected");
4962c51a 5291 return PARSE_OPERAND_FAIL;
09d92015
MM
5292 }
5293
c19d1205
ZW
5294 if (skip_past_char (&p, '!') == SUCCESS)
5295 inst.operands[i].writeback = 1;
09d92015 5296
c19d1205 5297 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5298 {
c19d1205
ZW
5299 if (skip_past_char (&p, '{') == SUCCESS)
5300 {
5301 /* [Rn], {expr} - unindexed, with option */
5302 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5303 0, 255, TRUE) == FAIL)
4962c51a 5304 return PARSE_OPERAND_FAIL;
09d92015 5305
c19d1205
ZW
5306 if (skip_past_char (&p, '}') == FAIL)
5307 {
5308 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5309 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5310 }
5311 if (inst.operands[i].preind)
5312 {
5313 inst.error = _("cannot combine index with option");
4962c51a 5314 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5315 }
5316 *str = p;
4962c51a 5317 return PARSE_OPERAND_SUCCESS;
09d92015 5318 }
c19d1205
ZW
5319 else
5320 {
5321 inst.operands[i].postind = 1;
5322 inst.operands[i].writeback = 1;
09d92015 5323
c19d1205
ZW
5324 if (inst.operands[i].preind)
5325 {
5326 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5327 return PARSE_OPERAND_FAIL;
c19d1205 5328 }
09d92015 5329
c19d1205
ZW
5330 if (*p == '+') p++;
5331 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5332
dcbf9037 5333 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5334 {
5287ad62
JB
5335 /* We might be using the immediate for alignment already. If we
5336 are, OR the register number into the low-order bits. */
5337 if (inst.operands[i].immisalign)
5338 inst.operands[i].imm |= reg;
5339 else
5340 inst.operands[i].imm = reg;
c19d1205 5341 inst.operands[i].immisreg = 1;
a737bd4d 5342
c19d1205
ZW
5343 if (skip_past_comma (&p) == SUCCESS)
5344 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5345 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5346 }
5347 else
5348 {
26d97720 5349 char *q = p;
c19d1205
ZW
5350 if (inst.operands[i].negative)
5351 {
5352 inst.operands[i].negative = 0;
5353 p--;
5354 }
5355 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5356 return PARSE_OPERAND_FAIL;
26d97720
NS
5357 /* If the offset is 0, find out if it's a +0 or -0. */
5358 if (inst.reloc.exp.X_op == O_constant
5359 && inst.reloc.exp.X_add_number == 0)
5360 {
5361 skip_whitespace (q);
5362 if (*q == '#')
5363 {
5364 q++;
5365 skip_whitespace (q);
5366 }
5367 if (*q == '-')
5368 inst.operands[i].negative = 1;
5369 }
c19d1205
ZW
5370 }
5371 }
a737bd4d
NC
5372 }
5373
c19d1205
ZW
5374 /* If at this point neither .preind nor .postind is set, we have a
5375 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5376 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5377 {
5378 inst.operands[i].preind = 1;
5379 inst.reloc.exp.X_op = O_constant;
5380 inst.reloc.exp.X_add_number = 0;
5381 }
5382 *str = p;
4962c51a
MS
5383 return PARSE_OPERAND_SUCCESS;
5384}
5385
5386static int
5387parse_address (char **str, int i)
5388{
21d799b5 5389 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5390 ? SUCCESS : FAIL;
5391}
5392
5393static parse_operand_result
5394parse_address_group_reloc (char **str, int i, group_reloc_type type)
5395{
5396 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5397}
5398
b6895b4f
PB
5399/* Parse an operand for a MOVW or MOVT instruction. */
5400static int
5401parse_half (char **str)
5402{
5403 char * p;
5f4273c7 5404
b6895b4f
PB
5405 p = *str;
5406 skip_past_char (&p, '#');
5f4273c7 5407 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5408 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5409 else if (strncasecmp (p, ":upper16:", 9) == 0)
5410 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5411
5412 if (inst.reloc.type != BFD_RELOC_UNUSED)
5413 {
5414 p += 9;
5f4273c7 5415 skip_whitespace (p);
b6895b4f
PB
5416 }
5417
5418 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5419 return FAIL;
5420
5421 if (inst.reloc.type == BFD_RELOC_UNUSED)
5422 {
5423 if (inst.reloc.exp.X_op != O_constant)
5424 {
5425 inst.error = _("constant expression expected");
5426 return FAIL;
5427 }
5428 if (inst.reloc.exp.X_add_number < 0
5429 || inst.reloc.exp.X_add_number > 0xffff)
5430 {
5431 inst.error = _("immediate value out of range");
5432 return FAIL;
5433 }
5434 }
5435 *str = p;
5436 return SUCCESS;
5437}
5438
c19d1205 5439/* Miscellaneous. */
a737bd4d 5440
c19d1205
ZW
5441/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5442 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5443static int
d2cd1205 5444parse_psr (char **str, bfd_boolean lhs)
09d92015 5445{
c19d1205
ZW
5446 char *p;
5447 unsigned long psr_field;
62b3e311
PB
5448 const struct asm_psr *psr;
5449 char *start;
d2cd1205 5450 bfd_boolean is_apsr = FALSE;
ac7f631b 5451 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5452
a4482bb6
NC
5453 /* PR gas/12698: If the user has specified -march=all then m_profile will
5454 be TRUE, but we want to ignore it in this case as we are building for any
5455 CPU type, including non-m variants. */
5456 if (selected_cpu.core == arm_arch_any.core)
5457 m_profile = FALSE;
5458
c19d1205
ZW
5459 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5460 feature for ease of use and backwards compatibility. */
5461 p = *str;
62b3e311 5462 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5463 {
5464 if (m_profile)
5465 goto unsupported_psr;
fa94de6b 5466
d2cd1205
JB
5467 psr_field = SPSR_BIT;
5468 }
5469 else if (strncasecmp (p, "CPSR", 4) == 0)
5470 {
5471 if (m_profile)
5472 goto unsupported_psr;
5473
5474 psr_field = 0;
5475 }
5476 else if (strncasecmp (p, "APSR", 4) == 0)
5477 {
5478 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5479 and ARMv7-R architecture CPUs. */
5480 is_apsr = TRUE;
5481 psr_field = 0;
5482 }
5483 else if (m_profile)
62b3e311
PB
5484 {
5485 start = p;
5486 do
5487 p++;
5488 while (ISALNUM (*p) || *p == '_');
5489
d2cd1205
JB
5490 if (strncasecmp (start, "iapsr", 5) == 0
5491 || strncasecmp (start, "eapsr", 5) == 0
5492 || strncasecmp (start, "xpsr", 4) == 0
5493 || strncasecmp (start, "psr", 3) == 0)
5494 p = start + strcspn (start, "rR") + 1;
5495
21d799b5
NC
5496 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5497 p - start);
d2cd1205 5498
62b3e311
PB
5499 if (!psr)
5500 return FAIL;
09d92015 5501
d2cd1205
JB
5502 /* If APSR is being written, a bitfield may be specified. Note that
5503 APSR itself is handled above. */
5504 if (psr->field <= 3)
5505 {
5506 psr_field = psr->field;
5507 is_apsr = TRUE;
5508 goto check_suffix;
5509 }
5510
62b3e311 5511 *str = p;
d2cd1205
JB
5512 /* M-profile MSR instructions have the mask field set to "10", except
5513 *PSR variants which modify APSR, which may use a different mask (and
5514 have been handled already). Do that by setting the PSR_f field
5515 here. */
5516 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5517 }
d2cd1205
JB
5518 else
5519 goto unsupported_psr;
09d92015 5520
62b3e311 5521 p += 4;
d2cd1205 5522check_suffix:
c19d1205
ZW
5523 if (*p == '_')
5524 {
5525 /* A suffix follows. */
c19d1205
ZW
5526 p++;
5527 start = p;
a737bd4d 5528
c19d1205
ZW
5529 do
5530 p++;
5531 while (ISALNUM (*p) || *p == '_');
a737bd4d 5532
d2cd1205
JB
5533 if (is_apsr)
5534 {
5535 /* APSR uses a notation for bits, rather than fields. */
5536 unsigned int nzcvq_bits = 0;
5537 unsigned int g_bit = 0;
5538 char *bit;
fa94de6b 5539
d2cd1205
JB
5540 for (bit = start; bit != p; bit++)
5541 {
5542 switch (TOLOWER (*bit))
5543 {
5544 case 'n':
5545 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5546 break;
5547
5548 case 'z':
5549 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5550 break;
5551
5552 case 'c':
5553 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5554 break;
5555
5556 case 'v':
5557 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5558 break;
fa94de6b 5559
d2cd1205
JB
5560 case 'q':
5561 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5562 break;
fa94de6b 5563
d2cd1205
JB
5564 case 'g':
5565 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5566 break;
fa94de6b 5567
d2cd1205
JB
5568 default:
5569 inst.error = _("unexpected bit specified after APSR");
5570 return FAIL;
5571 }
5572 }
fa94de6b 5573
d2cd1205
JB
5574 if (nzcvq_bits == 0x1f)
5575 psr_field |= PSR_f;
fa94de6b 5576
d2cd1205
JB
5577 if (g_bit == 0x1)
5578 {
5579 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5580 {
5581 inst.error = _("selected processor does not "
5582 "support DSP extension");
5583 return FAIL;
5584 }
5585
5586 psr_field |= PSR_s;
5587 }
fa94de6b 5588
d2cd1205
JB
5589 if ((nzcvq_bits & 0x20) != 0
5590 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5591 || (g_bit & 0x2) != 0)
5592 {
5593 inst.error = _("bad bitmask specified after APSR");
5594 return FAIL;
5595 }
5596 }
5597 else
5598 {
5599 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5600 p - start);
5601 if (!psr)
5602 goto error;
a737bd4d 5603
d2cd1205
JB
5604 psr_field |= psr->field;
5605 }
a737bd4d 5606 }
c19d1205 5607 else
a737bd4d 5608 {
c19d1205
ZW
5609 if (ISALNUM (*p))
5610 goto error; /* Garbage after "[CS]PSR". */
5611
d2cd1205
JB
5612 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5613 is deprecated, but allow it anyway. */
5614 if (is_apsr && lhs)
5615 {
5616 psr_field |= PSR_f;
5617 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5618 "deprecated"));
5619 }
5620 else if (!m_profile)
5621 /* These bits are never right for M-profile devices: don't set them
5622 (only code paths which read/write APSR reach here). */
5623 psr_field |= (PSR_c | PSR_f);
a737bd4d 5624 }
c19d1205
ZW
5625 *str = p;
5626 return psr_field;
a737bd4d 5627
d2cd1205
JB
5628 unsupported_psr:
5629 inst.error = _("selected processor does not support requested special "
5630 "purpose register");
5631 return FAIL;
5632
c19d1205
ZW
5633 error:
5634 inst.error = _("flag for {c}psr instruction expected");
5635 return FAIL;
a737bd4d
NC
5636}
5637
c19d1205
ZW
5638/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5639 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5640
c19d1205
ZW
5641static int
5642parse_cps_flags (char **str)
a737bd4d 5643{
c19d1205
ZW
5644 int val = 0;
5645 int saw_a_flag = 0;
5646 char *s = *str;
a737bd4d 5647
c19d1205
ZW
5648 for (;;)
5649 switch (*s++)
5650 {
5651 case '\0': case ',':
5652 goto done;
a737bd4d 5653
c19d1205
ZW
5654 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5655 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5656 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5657
c19d1205
ZW
5658 default:
5659 inst.error = _("unrecognized CPS flag");
5660 return FAIL;
5661 }
a737bd4d 5662
c19d1205
ZW
5663 done:
5664 if (saw_a_flag == 0)
a737bd4d 5665 {
c19d1205
ZW
5666 inst.error = _("missing CPS flags");
5667 return FAIL;
a737bd4d 5668 }
a737bd4d 5669
c19d1205
ZW
5670 *str = s - 1;
5671 return val;
a737bd4d
NC
5672}
5673
c19d1205
ZW
5674/* Parse an endian specifier ("BE" or "LE", case insensitive);
5675 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5676
5677static int
c19d1205 5678parse_endian_specifier (char **str)
a737bd4d 5679{
c19d1205
ZW
5680 int little_endian;
5681 char *s = *str;
a737bd4d 5682
c19d1205
ZW
5683 if (strncasecmp (s, "BE", 2))
5684 little_endian = 0;
5685 else if (strncasecmp (s, "LE", 2))
5686 little_endian = 1;
5687 else
a737bd4d 5688 {
c19d1205 5689 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5690 return FAIL;
5691 }
5692
c19d1205 5693 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5694 {
c19d1205 5695 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5696 return FAIL;
5697 }
5698
c19d1205
ZW
5699 *str = s + 2;
5700 return little_endian;
5701}
a737bd4d 5702
c19d1205
ZW
5703/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5704 value suitable for poking into the rotate field of an sxt or sxta
5705 instruction, or FAIL on error. */
5706
5707static int
5708parse_ror (char **str)
5709{
5710 int rot;
5711 char *s = *str;
5712
5713 if (strncasecmp (s, "ROR", 3) == 0)
5714 s += 3;
5715 else
a737bd4d 5716 {
c19d1205 5717 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5718 return FAIL;
5719 }
c19d1205
ZW
5720
5721 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5722 return FAIL;
5723
5724 switch (rot)
a737bd4d 5725 {
c19d1205
ZW
5726 case 0: *str = s; return 0x0;
5727 case 8: *str = s; return 0x1;
5728 case 16: *str = s; return 0x2;
5729 case 24: *str = s; return 0x3;
5730
5731 default:
5732 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5733 return FAIL;
5734 }
c19d1205 5735}
a737bd4d 5736
c19d1205
ZW
5737/* Parse a conditional code (from conds[] below). The value returned is in the
5738 range 0 .. 14, or FAIL. */
5739static int
5740parse_cond (char **str)
5741{
c462b453 5742 char *q;
c19d1205 5743 const struct asm_cond *c;
c462b453
PB
5744 int n;
5745 /* Condition codes are always 2 characters, so matching up to
5746 3 characters is sufficient. */
5747 char cond[3];
a737bd4d 5748
c462b453
PB
5749 q = *str;
5750 n = 0;
5751 while (ISALPHA (*q) && n < 3)
5752 {
e07e6e58 5753 cond[n] = TOLOWER (*q);
c462b453
PB
5754 q++;
5755 n++;
5756 }
a737bd4d 5757
21d799b5 5758 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5759 if (!c)
a737bd4d 5760 {
c19d1205 5761 inst.error = _("condition required");
a737bd4d
NC
5762 return FAIL;
5763 }
5764
c19d1205
ZW
5765 *str = q;
5766 return c->value;
5767}
5768
62b3e311
PB
5769/* Parse an option for a barrier instruction. Returns the encoding for the
5770 option, or FAIL. */
5771static int
5772parse_barrier (char **str)
5773{
5774 char *p, *q;
5775 const struct asm_barrier_opt *o;
5776
5777 p = q = *str;
5778 while (ISALPHA (*q))
5779 q++;
5780
21d799b5
NC
5781 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5782 q - p);
62b3e311
PB
5783 if (!o)
5784 return FAIL;
5785
5786 *str = q;
5787 return o->value;
5788}
5789
92e90b6e
PB
5790/* Parse the operands of a table branch instruction. Similar to a memory
5791 operand. */
5792static int
5793parse_tb (char **str)
5794{
5795 char * p = *str;
5796 int reg;
5797
5798 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5799 {
5800 inst.error = _("'[' expected");
5801 return FAIL;
5802 }
92e90b6e 5803
dcbf9037 5804 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5805 {
5806 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5807 return FAIL;
5808 }
5809 inst.operands[0].reg = reg;
5810
5811 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5812 {
5813 inst.error = _("',' expected");
5814 return FAIL;
5815 }
5f4273c7 5816
dcbf9037 5817 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5818 {
5819 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5820 return FAIL;
5821 }
5822 inst.operands[0].imm = reg;
5823
5824 if (skip_past_comma (&p) == SUCCESS)
5825 {
5826 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5827 return FAIL;
5828 if (inst.reloc.exp.X_add_number != 1)
5829 {
5830 inst.error = _("invalid shift");
5831 return FAIL;
5832 }
5833 inst.operands[0].shifted = 1;
5834 }
5835
5836 if (skip_past_char (&p, ']') == FAIL)
5837 {
5838 inst.error = _("']' expected");
5839 return FAIL;
5840 }
5841 *str = p;
5842 return SUCCESS;
5843}
5844
5287ad62
JB
5845/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5846 information on the types the operands can take and how they are encoded.
037e8744
JB
5847 Up to four operands may be read; this function handles setting the
5848 ".present" field for each read operand itself.
5287ad62
JB
5849 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5850 else returns FAIL. */
5851
5852static int
5853parse_neon_mov (char **str, int *which_operand)
5854{
5855 int i = *which_operand, val;
5856 enum arm_reg_type rtype;
5857 char *ptr = *str;
dcbf9037 5858 struct neon_type_el optype;
5f4273c7 5859
dcbf9037 5860 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5861 {
5862 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5863 inst.operands[i].reg = val;
5864 inst.operands[i].isscalar = 1;
dcbf9037 5865 inst.operands[i].vectype = optype;
5287ad62
JB
5866 inst.operands[i++].present = 1;
5867
5868 if (skip_past_comma (&ptr) == FAIL)
5869 goto wanted_comma;
5f4273c7 5870
dcbf9037 5871 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5872 goto wanted_arm;
5f4273c7 5873
5287ad62
JB
5874 inst.operands[i].reg = val;
5875 inst.operands[i].isreg = 1;
5876 inst.operands[i].present = 1;
5877 }
037e8744 5878 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5879 != FAIL)
5287ad62
JB
5880 {
5881 /* Cases 0, 1, 2, 3, 5 (D only). */
5882 if (skip_past_comma (&ptr) == FAIL)
5883 goto wanted_comma;
5f4273c7 5884
5287ad62
JB
5885 inst.operands[i].reg = val;
5886 inst.operands[i].isreg = 1;
5887 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5888 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5889 inst.operands[i].isvec = 1;
dcbf9037 5890 inst.operands[i].vectype = optype;
5287ad62
JB
5891 inst.operands[i++].present = 1;
5892
dcbf9037 5893 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5894 {
037e8744
JB
5895 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5896 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5897 inst.operands[i].reg = val;
5898 inst.operands[i].isreg = 1;
037e8744 5899 inst.operands[i].present = 1;
5287ad62
JB
5900
5901 if (rtype == REG_TYPE_NQ)
5902 {
dcbf9037 5903 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5904 return FAIL;
5905 }
037e8744
JB
5906 else if (rtype != REG_TYPE_VFS)
5907 {
5908 i++;
5909 if (skip_past_comma (&ptr) == FAIL)
5910 goto wanted_comma;
5911 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5912 goto wanted_arm;
5913 inst.operands[i].reg = val;
5914 inst.operands[i].isreg = 1;
5915 inst.operands[i].present = 1;
5916 }
5287ad62 5917 }
037e8744
JB
5918 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5919 &optype)) != FAIL)
5287ad62
JB
5920 {
5921 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5922 Case 1: VMOV<c><q> <Dd>, <Dm>
5923 Case 8: VMOV.F32 <Sd>, <Sm>
5924 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5925
5926 inst.operands[i].reg = val;
5927 inst.operands[i].isreg = 1;
5928 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5929 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5930 inst.operands[i].isvec = 1;
dcbf9037 5931 inst.operands[i].vectype = optype;
5287ad62 5932 inst.operands[i].present = 1;
5f4273c7 5933
037e8744
JB
5934 if (skip_past_comma (&ptr) == SUCCESS)
5935 {
5936 /* Case 15. */
5937 i++;
5938
5939 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5940 goto wanted_arm;
5941
5942 inst.operands[i].reg = val;
5943 inst.operands[i].isreg = 1;
5944 inst.operands[i++].present = 1;
5f4273c7 5945
037e8744
JB
5946 if (skip_past_comma (&ptr) == FAIL)
5947 goto wanted_comma;
5f4273c7 5948
037e8744
JB
5949 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5950 goto wanted_arm;
5f4273c7 5951
037e8744
JB
5952 inst.operands[i].reg = val;
5953 inst.operands[i].isreg = 1;
1b11b49f 5954 inst.operands[i].present = 1;
037e8744 5955 }
5287ad62 5956 }
4641781c
PB
5957 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5958 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5959 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5960 Case 10: VMOV.F32 <Sd>, #<imm>
5961 Case 11: VMOV.F64 <Dd>, #<imm> */
5962 inst.operands[i].immisfloat = 1;
5963 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5964 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5965 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5966 ;
5287ad62
JB
5967 else
5968 {
dcbf9037 5969 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5970 return FAIL;
5971 }
5972 }
dcbf9037 5973 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5974 {
5975 /* Cases 6, 7. */
5976 inst.operands[i].reg = val;
5977 inst.operands[i].isreg = 1;
5978 inst.operands[i++].present = 1;
5f4273c7 5979
5287ad62
JB
5980 if (skip_past_comma (&ptr) == FAIL)
5981 goto wanted_comma;
5f4273c7 5982
dcbf9037 5983 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5984 {
5985 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5986 inst.operands[i].reg = val;
5987 inst.operands[i].isscalar = 1;
5988 inst.operands[i].present = 1;
dcbf9037 5989 inst.operands[i].vectype = optype;
5287ad62 5990 }
dcbf9037 5991 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5992 {
5993 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5994 inst.operands[i].reg = val;
5995 inst.operands[i].isreg = 1;
5996 inst.operands[i++].present = 1;
5f4273c7 5997
5287ad62
JB
5998 if (skip_past_comma (&ptr) == FAIL)
5999 goto wanted_comma;
5f4273c7 6000
037e8744 6001 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 6002 == FAIL)
5287ad62 6003 {
037e8744 6004 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
6005 return FAIL;
6006 }
6007
6008 inst.operands[i].reg = val;
6009 inst.operands[i].isreg = 1;
037e8744
JB
6010 inst.operands[i].isvec = 1;
6011 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 6012 inst.operands[i].vectype = optype;
5287ad62 6013 inst.operands[i].present = 1;
5f4273c7 6014
037e8744
JB
6015 if (rtype == REG_TYPE_VFS)
6016 {
6017 /* Case 14. */
6018 i++;
6019 if (skip_past_comma (&ptr) == FAIL)
6020 goto wanted_comma;
6021 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6022 &optype)) == FAIL)
6023 {
6024 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6025 return FAIL;
6026 }
6027 inst.operands[i].reg = val;
6028 inst.operands[i].isreg = 1;
6029 inst.operands[i].isvec = 1;
6030 inst.operands[i].issingle = 1;
6031 inst.operands[i].vectype = optype;
6032 inst.operands[i].present = 1;
6033 }
6034 }
6035 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6036 != FAIL)
6037 {
6038 /* Case 13. */
6039 inst.operands[i].reg = val;
6040 inst.operands[i].isreg = 1;
6041 inst.operands[i].isvec = 1;
6042 inst.operands[i].issingle = 1;
6043 inst.operands[i].vectype = optype;
1b11b49f 6044 inst.operands[i].present = 1;
5287ad62
JB
6045 }
6046 }
6047 else
6048 {
dcbf9037 6049 first_error (_("parse error"));
5287ad62
JB
6050 return FAIL;
6051 }
6052
6053 /* Successfully parsed the operands. Update args. */
6054 *which_operand = i;
6055 *str = ptr;
6056 return SUCCESS;
6057
5f4273c7 6058 wanted_comma:
dcbf9037 6059 first_error (_("expected comma"));
5287ad62 6060 return FAIL;
5f4273c7
NC
6061
6062 wanted_arm:
dcbf9037 6063 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6064 return FAIL;
5287ad62
JB
6065}
6066
5be8be5d
DG
6067/* Use this macro when the operand constraints are different
6068 for ARM and THUMB (e.g. ldrd). */
6069#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6070 ((arm_operand) | ((thumb_operand) << 16))
6071
c19d1205
ZW
6072/* Matcher codes for parse_operands. */
6073enum operand_parse_code
6074{
6075 OP_stop, /* end of line */
6076
6077 OP_RR, /* ARM register */
6078 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6079 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6080 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6081 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6082 optional trailing ! */
c19d1205
ZW
6083 OP_RRw, /* ARM register, not r15, optional trailing ! */
6084 OP_RCP, /* Coprocessor number */
6085 OP_RCN, /* Coprocessor register */
6086 OP_RF, /* FPA register */
6087 OP_RVS, /* VFP single precision register */
5287ad62
JB
6088 OP_RVD, /* VFP double precision register (0..15) */
6089 OP_RND, /* Neon double precision register (0..31) */
6090 OP_RNQ, /* Neon quad precision register */
037e8744 6091 OP_RVSD, /* VFP single or double precision register */
5287ad62 6092 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6093 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6094 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6095 OP_RVC, /* VFP control register */
6096 OP_RMF, /* Maverick F register */
6097 OP_RMD, /* Maverick D register */
6098 OP_RMFX, /* Maverick FX register */
6099 OP_RMDX, /* Maverick DX register */
6100 OP_RMAX, /* Maverick AX register */
6101 OP_RMDS, /* Maverick DSPSC register */
6102 OP_RIWR, /* iWMMXt wR register */
6103 OP_RIWC, /* iWMMXt wC register */
6104 OP_RIWG, /* iWMMXt wCG register */
6105 OP_RXA, /* XScale accumulator register */
6106
6107 OP_REGLST, /* ARM register list */
6108 OP_VRSLST, /* VFP single-precision register list */
6109 OP_VRDLST, /* VFP double-precision register list */
037e8744 6110 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6111 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6112 OP_NSTRLST, /* Neon element/structure list */
6113
5287ad62 6114 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6115 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 6116 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6117 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6118 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6119 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6120 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6121 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6122 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6123 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6124
6125 OP_I0, /* immediate zero */
c19d1205
ZW
6126 OP_I7, /* immediate value 0 .. 7 */
6127 OP_I15, /* 0 .. 15 */
6128 OP_I16, /* 1 .. 16 */
5287ad62 6129 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6130 OP_I31, /* 0 .. 31 */
6131 OP_I31w, /* 0 .. 31, optional trailing ! */
6132 OP_I32, /* 1 .. 32 */
5287ad62
JB
6133 OP_I32z, /* 0 .. 32 */
6134 OP_I63, /* 0 .. 63 */
c19d1205 6135 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6136 OP_I64, /* 1 .. 64 */
6137 OP_I64z, /* 0 .. 64 */
c19d1205 6138 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6139
6140 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6141 OP_I7b, /* 0 .. 7 */
6142 OP_I15b, /* 0 .. 15 */
6143 OP_I31b, /* 0 .. 31 */
6144
6145 OP_SH, /* shifter operand */
4962c51a 6146 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6147 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6148 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6149 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6150 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6151 OP_EXP, /* arbitrary expression */
6152 OP_EXPi, /* same, with optional immediate prefix */
6153 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6154 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6155
6156 OP_CPSF, /* CPS flags */
6157 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6158 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6159 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6160 OP_COND, /* conditional code */
92e90b6e 6161 OP_TB, /* Table branch. */
c19d1205 6162
037e8744
JB
6163 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6164
c19d1205
ZW
6165 OP_RRnpc_I0, /* ARM register or literal 0 */
6166 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6167 OP_RR_EXi, /* ARM register or expression with imm prefix */
6168 OP_RF_IF, /* FPA register or immediate */
6169 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6170 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6171
6172 /* Optional operands. */
6173 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6174 OP_oI31b, /* 0 .. 31 */
5287ad62 6175 OP_oI32b, /* 1 .. 32 */
5f1af56b 6176 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6177 OP_oIffffb, /* 0 .. 65535 */
6178 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6179
6180 OP_oRR, /* ARM register */
6181 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6182 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6183 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6184 OP_oRND, /* Optional Neon double precision register */
6185 OP_oRNQ, /* Optional Neon quad precision register */
6186 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6187 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6188 OP_oSHll, /* LSL immediate */
6189 OP_oSHar, /* ASR immediate */
6190 OP_oSHllar, /* LSL or ASR immediate */
6191 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6192 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6193
5be8be5d
DG
6194 /* Some pre-defined mixed (ARM/THUMB) operands. */
6195 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6196 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6197 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6198
c19d1205
ZW
6199 OP_FIRST_OPTIONAL = OP_oI7b
6200};
a737bd4d 6201
c19d1205
ZW
6202/* Generic instruction operand parser. This does no encoding and no
6203 semantic validation; it merely squirrels values away in the inst
6204 structure. Returns SUCCESS or FAIL depending on whether the
6205 specified grammar matched. */
6206static int
5be8be5d 6207parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6208{
5be8be5d 6209 unsigned const int *upat = pattern;
c19d1205
ZW
6210 char *backtrack_pos = 0;
6211 const char *backtrack_error = 0;
99aad254 6212 int i, val = 0, backtrack_index = 0;
5287ad62 6213 enum arm_reg_type rtype;
4962c51a 6214 parse_operand_result result;
5be8be5d 6215 unsigned int op_parse_code;
c19d1205 6216
e07e6e58
NC
6217#define po_char_or_fail(chr) \
6218 do \
6219 { \
6220 if (skip_past_char (&str, chr) == FAIL) \
6221 goto bad_args; \
6222 } \
6223 while (0)
c19d1205 6224
e07e6e58
NC
6225#define po_reg_or_fail(regtype) \
6226 do \
dcbf9037 6227 { \
e07e6e58
NC
6228 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6229 & inst.operands[i].vectype); \
6230 if (val == FAIL) \
6231 { \
6232 first_error (_(reg_expected_msgs[regtype])); \
6233 goto failure; \
6234 } \
6235 inst.operands[i].reg = val; \
6236 inst.operands[i].isreg = 1; \
6237 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6238 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6239 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6240 || rtype == REG_TYPE_VFD \
6241 || rtype == REG_TYPE_NQ); \
dcbf9037 6242 } \
e07e6e58
NC
6243 while (0)
6244
6245#define po_reg_or_goto(regtype, label) \
6246 do \
6247 { \
6248 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6249 & inst.operands[i].vectype); \
6250 if (val == FAIL) \
6251 goto label; \
dcbf9037 6252 \
e07e6e58
NC
6253 inst.operands[i].reg = val; \
6254 inst.operands[i].isreg = 1; \
6255 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6256 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6257 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6258 || rtype == REG_TYPE_VFD \
6259 || rtype == REG_TYPE_NQ); \
6260 } \
6261 while (0)
6262
6263#define po_imm_or_fail(min, max, popt) \
6264 do \
6265 { \
6266 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6267 goto failure; \
6268 inst.operands[i].imm = val; \
6269 } \
6270 while (0)
6271
6272#define po_scalar_or_goto(elsz, label) \
6273 do \
6274 { \
6275 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6276 if (val == FAIL) \
6277 goto label; \
6278 inst.operands[i].reg = val; \
6279 inst.operands[i].isscalar = 1; \
6280 } \
6281 while (0)
6282
6283#define po_misc_or_fail(expr) \
6284 do \
6285 { \
6286 if (expr) \
6287 goto failure; \
6288 } \
6289 while (0)
6290
6291#define po_misc_or_fail_no_backtrack(expr) \
6292 do \
6293 { \
6294 result = expr; \
6295 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6296 backtrack_pos = 0; \
6297 if (result != PARSE_OPERAND_SUCCESS) \
6298 goto failure; \
6299 } \
6300 while (0)
4962c51a 6301
52e7f43d
RE
6302#define po_barrier_or_imm(str) \
6303 do \
6304 { \
6305 val = parse_barrier (&str); \
6306 if (val == FAIL) \
6307 { \
6308 if (ISALPHA (*str)) \
6309 goto failure; \
6310 else \
6311 goto immediate; \
6312 } \
6313 else \
6314 { \
6315 if ((inst.instruction & 0xf0) == 0x60 \
6316 && val != 0xf) \
6317 { \
6318 /* ISB can only take SY as an option. */ \
6319 inst.error = _("invalid barrier type"); \
6320 goto failure; \
6321 } \
6322 } \
6323 } \
6324 while (0)
6325
c19d1205
ZW
6326 skip_whitespace (str);
6327
6328 for (i = 0; upat[i] != OP_stop; i++)
6329 {
5be8be5d
DG
6330 op_parse_code = upat[i];
6331 if (op_parse_code >= 1<<16)
6332 op_parse_code = thumb ? (op_parse_code >> 16)
6333 : (op_parse_code & ((1<<16)-1));
6334
6335 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6336 {
6337 /* Remember where we are in case we need to backtrack. */
9c2799c2 6338 gas_assert (!backtrack_pos);
c19d1205
ZW
6339 backtrack_pos = str;
6340 backtrack_error = inst.error;
6341 backtrack_index = i;
6342 }
6343
b6702015 6344 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6345 po_char_or_fail (',');
6346
5be8be5d 6347 switch (op_parse_code)
c19d1205
ZW
6348 {
6349 /* Registers */
6350 case OP_oRRnpc:
5be8be5d 6351 case OP_oRRnpcsp:
c19d1205 6352 case OP_RRnpc:
5be8be5d 6353 case OP_RRnpcsp:
c19d1205
ZW
6354 case OP_oRR:
6355 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6356 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6357 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6358 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6359 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6360 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6361 case OP_oRND:
6362 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6363 case OP_RVC:
6364 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6365 break;
6366 /* Also accept generic coprocessor regs for unknown registers. */
6367 coproc_reg:
6368 po_reg_or_fail (REG_TYPE_CN);
6369 break;
c19d1205
ZW
6370 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6371 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6372 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6373 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6374 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6375 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6376 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6377 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6378 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6379 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6380 case OP_oRNQ:
6381 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6382 case OP_oRNDQ:
6383 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6384 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6385 case OP_oRNSDQ:
6386 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6387
6388 /* Neon scalar. Using an element size of 8 means that some invalid
6389 scalars are accepted here, so deal with those in later code. */
6390 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6391
5287ad62
JB
6392 case OP_RNDQ_I0:
6393 {
6394 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6395 break;
6396 try_imm0:
6397 po_imm_or_fail (0, 0, TRUE);
6398 }
6399 break;
6400
037e8744
JB
6401 case OP_RVSD_I0:
6402 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6403 break;
6404
5287ad62
JB
6405 case OP_RR_RNSC:
6406 {
6407 po_scalar_or_goto (8, try_rr);
6408 break;
6409 try_rr:
6410 po_reg_or_fail (REG_TYPE_RN);
6411 }
6412 break;
6413
037e8744
JB
6414 case OP_RNSDQ_RNSC:
6415 {
6416 po_scalar_or_goto (8, try_nsdq);
6417 break;
6418 try_nsdq:
6419 po_reg_or_fail (REG_TYPE_NSDQ);
6420 }
6421 break;
6422
5287ad62
JB
6423 case OP_RNDQ_RNSC:
6424 {
6425 po_scalar_or_goto (8, try_ndq);
6426 break;
6427 try_ndq:
6428 po_reg_or_fail (REG_TYPE_NDQ);
6429 }
6430 break;
6431
6432 case OP_RND_RNSC:
6433 {
6434 po_scalar_or_goto (8, try_vfd);
6435 break;
6436 try_vfd:
6437 po_reg_or_fail (REG_TYPE_VFD);
6438 }
6439 break;
6440
6441 case OP_VMOV:
6442 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6443 not careful then bad things might happen. */
6444 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6445 break;
6446
4316f0d2 6447 case OP_RNDQ_Ibig:
5287ad62 6448 {
4316f0d2 6449 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6450 break;
4316f0d2 6451 try_immbig:
5287ad62
JB
6452 /* There's a possibility of getting a 64-bit immediate here, so
6453 we need special handling. */
6454 if (parse_big_immediate (&str, i) == FAIL)
6455 {
6456 inst.error = _("immediate value is out of range");
6457 goto failure;
6458 }
6459 }
6460 break;
6461
6462 case OP_RNDQ_I63b:
6463 {
6464 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6465 break;
6466 try_shimm:
6467 po_imm_or_fail (0, 63, TRUE);
6468 }
6469 break;
c19d1205
ZW
6470
6471 case OP_RRnpcb:
6472 po_char_or_fail ('[');
6473 po_reg_or_fail (REG_TYPE_RN);
6474 po_char_or_fail (']');
6475 break;
a737bd4d 6476
55881a11 6477 case OP_RRnpctw:
c19d1205 6478 case OP_RRw:
b6702015 6479 case OP_oRRw:
c19d1205
ZW
6480 po_reg_or_fail (REG_TYPE_RN);
6481 if (skip_past_char (&str, '!') == SUCCESS)
6482 inst.operands[i].writeback = 1;
6483 break;
6484
6485 /* Immediates */
6486 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6487 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6488 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6489 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6490 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6491 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6492 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6493 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6494 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6495 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6496 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6497 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6498
6499 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6500 case OP_oI7b:
6501 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6502 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6503 case OP_oI31b:
6504 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6505 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5f1af56b 6506 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6507 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6508
6509 /* Immediate variants */
6510 case OP_oI255c:
6511 po_char_or_fail ('{');
6512 po_imm_or_fail (0, 255, TRUE);
6513 po_char_or_fail ('}');
6514 break;
6515
6516 case OP_I31w:
6517 /* The expression parser chokes on a trailing !, so we have
6518 to find it first and zap it. */
6519 {
6520 char *s = str;
6521 while (*s && *s != ',')
6522 s++;
6523 if (s[-1] == '!')
6524 {
6525 s[-1] = '\0';
6526 inst.operands[i].writeback = 1;
6527 }
6528 po_imm_or_fail (0, 31, TRUE);
6529 if (str == s - 1)
6530 str = s;
6531 }
6532 break;
6533
6534 /* Expressions */
6535 case OP_EXPi: EXPi:
6536 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6537 GE_OPT_PREFIX));
6538 break;
6539
6540 case OP_EXP:
6541 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6542 GE_NO_PREFIX));
6543 break;
6544
6545 case OP_EXPr: EXPr:
6546 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6547 GE_NO_PREFIX));
6548 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6549 {
c19d1205
ZW
6550 val = parse_reloc (&str);
6551 if (val == -1)
6552 {
6553 inst.error = _("unrecognized relocation suffix");
6554 goto failure;
6555 }
6556 else if (val != BFD_RELOC_UNUSED)
6557 {
6558 inst.operands[i].imm = val;
6559 inst.operands[i].hasreloc = 1;
6560 }
a737bd4d 6561 }
c19d1205 6562 break;
a737bd4d 6563
b6895b4f
PB
6564 /* Operand for MOVW or MOVT. */
6565 case OP_HALF:
6566 po_misc_or_fail (parse_half (&str));
6567 break;
6568
e07e6e58 6569 /* Register or expression. */
c19d1205
ZW
6570 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6571 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6572
e07e6e58 6573 /* Register or immediate. */
c19d1205
ZW
6574 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6575 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6576
c19d1205
ZW
6577 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6578 IF:
6579 if (!is_immediate_prefix (*str))
6580 goto bad_args;
6581 str++;
6582 val = parse_fpa_immediate (&str);
6583 if (val == FAIL)
6584 goto failure;
6585 /* FPA immediates are encoded as registers 8-15.
6586 parse_fpa_immediate has already applied the offset. */
6587 inst.operands[i].reg = val;
6588 inst.operands[i].isreg = 1;
6589 break;
09d92015 6590
2d447fca
JM
6591 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6592 I32z: po_imm_or_fail (0, 32, FALSE); break;
6593
e07e6e58 6594 /* Two kinds of register. */
c19d1205
ZW
6595 case OP_RIWR_RIWC:
6596 {
6597 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6598 if (!rege
6599 || (rege->type != REG_TYPE_MMXWR
6600 && rege->type != REG_TYPE_MMXWC
6601 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6602 {
6603 inst.error = _("iWMMXt data or control register expected");
6604 goto failure;
6605 }
6606 inst.operands[i].reg = rege->number;
6607 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6608 }
6609 break;
09d92015 6610
41adaa5c
JM
6611 case OP_RIWC_RIWG:
6612 {
6613 struct reg_entry *rege = arm_reg_parse_multi (&str);
6614 if (!rege
6615 || (rege->type != REG_TYPE_MMXWC
6616 && rege->type != REG_TYPE_MMXWCG))
6617 {
6618 inst.error = _("iWMMXt control register expected");
6619 goto failure;
6620 }
6621 inst.operands[i].reg = rege->number;
6622 inst.operands[i].isreg = 1;
6623 }
6624 break;
6625
c19d1205
ZW
6626 /* Misc */
6627 case OP_CPSF: val = parse_cps_flags (&str); break;
6628 case OP_ENDI: val = parse_endian_specifier (&str); break;
6629 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6630 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6631 case OP_oBARRIER_I15:
6632 po_barrier_or_imm (str); break;
6633 immediate:
6634 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6635 goto failure;
6636 break;
c19d1205 6637
fa94de6b 6638 case OP_wPSR:
d2cd1205 6639 case OP_rPSR:
90ec0d68
MGD
6640 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6641 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6642 {
6643 inst.error = _("Banked registers are not available with this "
6644 "architecture.");
6645 goto failure;
6646 }
6647 break;
d2cd1205
JB
6648 try_psr:
6649 val = parse_psr (&str, op_parse_code == OP_wPSR);
6650 break;
037e8744
JB
6651
6652 case OP_APSR_RR:
6653 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6654 break;
6655 try_apsr:
6656 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6657 instruction). */
6658 if (strncasecmp (str, "APSR_", 5) == 0)
6659 {
6660 unsigned found = 0;
6661 str += 5;
6662 while (found < 15)
6663 switch (*str++)
6664 {
6665 case 'c': found = (found & 1) ? 16 : found | 1; break;
6666 case 'n': found = (found & 2) ? 16 : found | 2; break;
6667 case 'z': found = (found & 4) ? 16 : found | 4; break;
6668 case 'v': found = (found & 8) ? 16 : found | 8; break;
6669 default: found = 16;
6670 }
6671 if (found != 15)
6672 goto failure;
6673 inst.operands[i].isvec = 1;
f7c21dc7
NC
6674 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6675 inst.operands[i].reg = REG_PC;
037e8744
JB
6676 }
6677 else
6678 goto failure;
6679 break;
6680
92e90b6e
PB
6681 case OP_TB:
6682 po_misc_or_fail (parse_tb (&str));
6683 break;
6684
e07e6e58 6685 /* Register lists. */
c19d1205
ZW
6686 case OP_REGLST:
6687 val = parse_reg_list (&str);
6688 if (*str == '^')
6689 {
6690 inst.operands[1].writeback = 1;
6691 str++;
6692 }
6693 break;
09d92015 6694
c19d1205 6695 case OP_VRSLST:
5287ad62 6696 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6697 break;
09d92015 6698
c19d1205 6699 case OP_VRDLST:
5287ad62 6700 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6701 break;
a737bd4d 6702
037e8744
JB
6703 case OP_VRSDLST:
6704 /* Allow Q registers too. */
6705 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6706 REGLIST_NEON_D);
6707 if (val == FAIL)
6708 {
6709 inst.error = NULL;
6710 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6711 REGLIST_VFP_S);
6712 inst.operands[i].issingle = 1;
6713 }
6714 break;
6715
5287ad62
JB
6716 case OP_NRDLST:
6717 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6718 REGLIST_NEON_D);
6719 break;
6720
6721 case OP_NSTRLST:
dcbf9037
JB
6722 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6723 &inst.operands[i].vectype);
5287ad62
JB
6724 break;
6725
c19d1205
ZW
6726 /* Addressing modes */
6727 case OP_ADDR:
6728 po_misc_or_fail (parse_address (&str, i));
6729 break;
09d92015 6730
4962c51a
MS
6731 case OP_ADDRGLDR:
6732 po_misc_or_fail_no_backtrack (
6733 parse_address_group_reloc (&str, i, GROUP_LDR));
6734 break;
6735
6736 case OP_ADDRGLDRS:
6737 po_misc_or_fail_no_backtrack (
6738 parse_address_group_reloc (&str, i, GROUP_LDRS));
6739 break;
6740
6741 case OP_ADDRGLDC:
6742 po_misc_or_fail_no_backtrack (
6743 parse_address_group_reloc (&str, i, GROUP_LDC));
6744 break;
6745
c19d1205
ZW
6746 case OP_SH:
6747 po_misc_or_fail (parse_shifter_operand (&str, i));
6748 break;
09d92015 6749
4962c51a
MS
6750 case OP_SHG:
6751 po_misc_or_fail_no_backtrack (
6752 parse_shifter_operand_group_reloc (&str, i));
6753 break;
6754
c19d1205
ZW
6755 case OP_oSHll:
6756 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6757 break;
09d92015 6758
c19d1205
ZW
6759 case OP_oSHar:
6760 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6761 break;
09d92015 6762
c19d1205
ZW
6763 case OP_oSHllar:
6764 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6765 break;
09d92015 6766
c19d1205 6767 default:
5be8be5d 6768 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6769 }
09d92015 6770
c19d1205
ZW
6771 /* Various value-based sanity checks and shared operations. We
6772 do not signal immediate failures for the register constraints;
6773 this allows a syntax error to take precedence. */
5be8be5d 6774 switch (op_parse_code)
c19d1205
ZW
6775 {
6776 case OP_oRRnpc:
6777 case OP_RRnpc:
6778 case OP_RRnpcb:
6779 case OP_RRw:
b6702015 6780 case OP_oRRw:
c19d1205
ZW
6781 case OP_RRnpc_I0:
6782 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6783 inst.error = BAD_PC;
6784 break;
09d92015 6785
5be8be5d
DG
6786 case OP_oRRnpcsp:
6787 case OP_RRnpcsp:
6788 if (inst.operands[i].isreg)
6789 {
6790 if (inst.operands[i].reg == REG_PC)
6791 inst.error = BAD_PC;
6792 else if (inst.operands[i].reg == REG_SP)
6793 inst.error = BAD_SP;
6794 }
6795 break;
6796
55881a11 6797 case OP_RRnpctw:
fa94de6b
RM
6798 if (inst.operands[i].isreg
6799 && inst.operands[i].reg == REG_PC
55881a11
MGD
6800 && (inst.operands[i].writeback || thumb))
6801 inst.error = BAD_PC;
6802 break;
6803
c19d1205
ZW
6804 case OP_CPSF:
6805 case OP_ENDI:
6806 case OP_oROR:
d2cd1205
JB
6807 case OP_wPSR:
6808 case OP_rPSR:
c19d1205 6809 case OP_COND:
52e7f43d 6810 case OP_oBARRIER_I15:
c19d1205
ZW
6811 case OP_REGLST:
6812 case OP_VRSLST:
6813 case OP_VRDLST:
037e8744 6814 case OP_VRSDLST:
5287ad62
JB
6815 case OP_NRDLST:
6816 case OP_NSTRLST:
c19d1205
ZW
6817 if (val == FAIL)
6818 goto failure;
6819 inst.operands[i].imm = val;
6820 break;
a737bd4d 6821
c19d1205
ZW
6822 default:
6823 break;
6824 }
09d92015 6825
c19d1205
ZW
6826 /* If we get here, this operand was successfully parsed. */
6827 inst.operands[i].present = 1;
6828 continue;
09d92015 6829
c19d1205 6830 bad_args:
09d92015 6831 inst.error = BAD_ARGS;
c19d1205
ZW
6832
6833 failure:
6834 if (!backtrack_pos)
d252fdde
PB
6835 {
6836 /* The parse routine should already have set inst.error, but set a
5f4273c7 6837 default here just in case. */
d252fdde
PB
6838 if (!inst.error)
6839 inst.error = _("syntax error");
6840 return FAIL;
6841 }
c19d1205
ZW
6842
6843 /* Do not backtrack over a trailing optional argument that
6844 absorbed some text. We will only fail again, with the
6845 'garbage following instruction' error message, which is
6846 probably less helpful than the current one. */
6847 if (backtrack_index == i && backtrack_pos != str
6848 && upat[i+1] == OP_stop)
d252fdde
PB
6849 {
6850 if (!inst.error)
6851 inst.error = _("syntax error");
6852 return FAIL;
6853 }
c19d1205
ZW
6854
6855 /* Try again, skipping the optional argument at backtrack_pos. */
6856 str = backtrack_pos;
6857 inst.error = backtrack_error;
6858 inst.operands[backtrack_index].present = 0;
6859 i = backtrack_index;
6860 backtrack_pos = 0;
09d92015 6861 }
09d92015 6862
c19d1205
ZW
6863 /* Check that we have parsed all the arguments. */
6864 if (*str != '\0' && !inst.error)
6865 inst.error = _("garbage following instruction");
09d92015 6866
c19d1205 6867 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6868}
6869
c19d1205
ZW
6870#undef po_char_or_fail
6871#undef po_reg_or_fail
6872#undef po_reg_or_goto
6873#undef po_imm_or_fail
5287ad62 6874#undef po_scalar_or_fail
52e7f43d 6875#undef po_barrier_or_imm
e07e6e58 6876
c19d1205 6877/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6878#define constraint(expr, err) \
6879 do \
c19d1205 6880 { \
e07e6e58
NC
6881 if (expr) \
6882 { \
6883 inst.error = err; \
6884 return; \
6885 } \
c19d1205 6886 } \
e07e6e58 6887 while (0)
c19d1205 6888
fdfde340
JM
6889/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6890 instructions are unpredictable if these registers are used. This
6891 is the BadReg predicate in ARM's Thumb-2 documentation. */
6892#define reject_bad_reg(reg) \
6893 do \
6894 if (reg == REG_SP || reg == REG_PC) \
6895 { \
6896 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6897 return; \
6898 } \
6899 while (0)
6900
94206790
MM
6901/* If REG is R13 (the stack pointer), warn that its use is
6902 deprecated. */
6903#define warn_deprecated_sp(reg) \
6904 do \
6905 if (warn_on_deprecated && reg == REG_SP) \
6906 as_warn (_("use of r13 is deprecated")); \
6907 while (0)
6908
c19d1205
ZW
6909/* Functions for operand encoding. ARM, then Thumb. */
6910
6911#define rotate_left(v, n) (v << n | v >> (32 - n))
6912
6913/* If VAL can be encoded in the immediate field of an ARM instruction,
6914 return the encoded form. Otherwise, return FAIL. */
6915
6916static unsigned int
6917encode_arm_immediate (unsigned int val)
09d92015 6918{
c19d1205
ZW
6919 unsigned int a, i;
6920
6921 for (i = 0; i < 32; i += 2)
6922 if ((a = rotate_left (val, i)) <= 0xff)
6923 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6924
6925 return FAIL;
09d92015
MM
6926}
6927
c19d1205
ZW
6928/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6929 return the encoded form. Otherwise, return FAIL. */
6930static unsigned int
6931encode_thumb32_immediate (unsigned int val)
09d92015 6932{
c19d1205 6933 unsigned int a, i;
09d92015 6934
9c3c69f2 6935 if (val <= 0xff)
c19d1205 6936 return val;
a737bd4d 6937
9c3c69f2 6938 for (i = 1; i <= 24; i++)
09d92015 6939 {
9c3c69f2
PB
6940 a = val >> i;
6941 if ((val & ~(0xff << i)) == 0)
6942 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6943 }
a737bd4d 6944
c19d1205
ZW
6945 a = val & 0xff;
6946 if (val == ((a << 16) | a))
6947 return 0x100 | a;
6948 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6949 return 0x300 | a;
09d92015 6950
c19d1205
ZW
6951 a = val & 0xff00;
6952 if (val == ((a << 16) | a))
6953 return 0x200 | (a >> 8);
a737bd4d 6954
c19d1205 6955 return FAIL;
09d92015 6956}
5287ad62 6957/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6958
6959static void
5287ad62
JB
6960encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6961{
6962 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6963 && reg > 15)
6964 {
b1cc4aeb 6965 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6966 {
6967 if (thumb_mode)
6968 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6969 fpu_vfp_ext_d32);
5287ad62
JB
6970 else
6971 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6972 fpu_vfp_ext_d32);
5287ad62
JB
6973 }
6974 else
6975 {
dcbf9037 6976 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6977 return;
6978 }
6979 }
6980
c19d1205 6981 switch (pos)
09d92015 6982 {
c19d1205
ZW
6983 case VFP_REG_Sd:
6984 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6985 break;
6986
6987 case VFP_REG_Sn:
6988 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6989 break;
6990
6991 case VFP_REG_Sm:
6992 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6993 break;
6994
5287ad62
JB
6995 case VFP_REG_Dd:
6996 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6997 break;
5f4273c7 6998
5287ad62
JB
6999 case VFP_REG_Dn:
7000 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7001 break;
5f4273c7 7002
5287ad62
JB
7003 case VFP_REG_Dm:
7004 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7005 break;
7006
c19d1205
ZW
7007 default:
7008 abort ();
09d92015 7009 }
09d92015
MM
7010}
7011
c19d1205 7012/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7013 if any, is handled by md_apply_fix. */
09d92015 7014static void
c19d1205 7015encode_arm_shift (int i)
09d92015 7016{
c19d1205
ZW
7017 if (inst.operands[i].shift_kind == SHIFT_RRX)
7018 inst.instruction |= SHIFT_ROR << 5;
7019 else
09d92015 7020 {
c19d1205
ZW
7021 inst.instruction |= inst.operands[i].shift_kind << 5;
7022 if (inst.operands[i].immisreg)
7023 {
7024 inst.instruction |= SHIFT_BY_REG;
7025 inst.instruction |= inst.operands[i].imm << 8;
7026 }
7027 else
7028 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7029 }
c19d1205 7030}
09d92015 7031
c19d1205
ZW
7032static void
7033encode_arm_shifter_operand (int i)
7034{
7035 if (inst.operands[i].isreg)
09d92015 7036 {
c19d1205
ZW
7037 inst.instruction |= inst.operands[i].reg;
7038 encode_arm_shift (i);
09d92015 7039 }
c19d1205 7040 else
a415b1cd
JB
7041 {
7042 inst.instruction |= INST_IMMEDIATE;
7043 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7044 inst.instruction |= inst.operands[i].imm;
7045 }
09d92015
MM
7046}
7047
c19d1205 7048/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7049static void
c19d1205 7050encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7051{
2b2f5df9
NC
7052 /* PR 14260:
7053 Generate an error if the operand is not a register. */
7054 constraint (!inst.operands[i].isreg,
7055 _("Instruction does not support =N addresses"));
7056
c19d1205 7057 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7058
c19d1205 7059 if (inst.operands[i].preind)
09d92015 7060 {
c19d1205
ZW
7061 if (is_t)
7062 {
7063 inst.error = _("instruction does not accept preindexed addressing");
7064 return;
7065 }
7066 inst.instruction |= PRE_INDEX;
7067 if (inst.operands[i].writeback)
7068 inst.instruction |= WRITE_BACK;
09d92015 7069
c19d1205
ZW
7070 }
7071 else if (inst.operands[i].postind)
7072 {
9c2799c2 7073 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7074 if (is_t)
7075 inst.instruction |= WRITE_BACK;
7076 }
7077 else /* unindexed - only for coprocessor */
09d92015 7078 {
c19d1205 7079 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7080 return;
7081 }
7082
c19d1205
ZW
7083 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7084 && (((inst.instruction & 0x000f0000) >> 16)
7085 == ((inst.instruction & 0x0000f000) >> 12)))
7086 as_warn ((inst.instruction & LOAD_BIT)
7087 ? _("destination register same as write-back base")
7088 : _("source register same as write-back base"));
09d92015
MM
7089}
7090
c19d1205
ZW
7091/* inst.operands[i] was set up by parse_address. Encode it into an
7092 ARM-format mode 2 load or store instruction. If is_t is true,
7093 reject forms that cannot be used with a T instruction (i.e. not
7094 post-indexed). */
a737bd4d 7095static void
c19d1205 7096encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7097{
5be8be5d
DG
7098 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7099
c19d1205 7100 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7101
c19d1205 7102 if (inst.operands[i].immisreg)
09d92015 7103 {
5be8be5d
DG
7104 constraint ((inst.operands[i].imm == REG_PC
7105 || (is_pc && inst.operands[i].writeback)),
7106 BAD_PC_ADDRESSING);
c19d1205
ZW
7107 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7108 inst.instruction |= inst.operands[i].imm;
7109 if (!inst.operands[i].negative)
7110 inst.instruction |= INDEX_UP;
7111 if (inst.operands[i].shifted)
7112 {
7113 if (inst.operands[i].shift_kind == SHIFT_RRX)
7114 inst.instruction |= SHIFT_ROR << 5;
7115 else
7116 {
7117 inst.instruction |= inst.operands[i].shift_kind << 5;
7118 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7119 }
7120 }
09d92015 7121 }
c19d1205 7122 else /* immediate offset in inst.reloc */
09d92015 7123 {
5be8be5d
DG
7124 if (is_pc && !inst.reloc.pc_rel)
7125 {
7126 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7127
7128 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7129 cannot use PC in addressing.
7130 PC cannot be used in writeback addressing, either. */
7131 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7132 BAD_PC_ADDRESSING);
23a10334 7133
dc5ec521 7134 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7135 if (warn_on_deprecated
7136 && !is_load
7137 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7138 as_warn (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7139 }
7140
c19d1205 7141 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7142 {
7143 /* Prefer + for zero encoded value. */
7144 if (!inst.operands[i].negative)
7145 inst.instruction |= INDEX_UP;
7146 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7147 }
09d92015 7148 }
09d92015
MM
7149}
7150
c19d1205
ZW
7151/* inst.operands[i] was set up by parse_address. Encode it into an
7152 ARM-format mode 3 load or store instruction. Reject forms that
7153 cannot be used with such instructions. If is_t is true, reject
7154 forms that cannot be used with a T instruction (i.e. not
7155 post-indexed). */
7156static void
7157encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7158{
c19d1205 7159 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7160 {
c19d1205
ZW
7161 inst.error = _("instruction does not accept scaled register index");
7162 return;
09d92015 7163 }
a737bd4d 7164
c19d1205 7165 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7166
c19d1205
ZW
7167 if (inst.operands[i].immisreg)
7168 {
5be8be5d
DG
7169 constraint ((inst.operands[i].imm == REG_PC
7170 || inst.operands[i].reg == REG_PC),
7171 BAD_PC_ADDRESSING);
c19d1205
ZW
7172 inst.instruction |= inst.operands[i].imm;
7173 if (!inst.operands[i].negative)
7174 inst.instruction |= INDEX_UP;
7175 }
7176 else /* immediate offset in inst.reloc */
7177 {
5be8be5d
DG
7178 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7179 && inst.operands[i].writeback),
7180 BAD_PC_WRITEBACK);
c19d1205
ZW
7181 inst.instruction |= HWOFFSET_IMM;
7182 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7183 {
7184 /* Prefer + for zero encoded value. */
7185 if (!inst.operands[i].negative)
7186 inst.instruction |= INDEX_UP;
7187
7188 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7189 }
c19d1205 7190 }
a737bd4d
NC
7191}
7192
c19d1205
ZW
7193/* inst.operands[i] was set up by parse_address. Encode it into an
7194 ARM-format instruction. Reject all forms which cannot be encoded
7195 into a coprocessor load/store instruction. If wb_ok is false,
7196 reject use of writeback; if unind_ok is false, reject use of
7197 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
7198 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7199 (in which case it is preserved). */
09d92015 7200
c19d1205
ZW
7201static int
7202encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 7203{
c19d1205 7204 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7205
9c2799c2 7206 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 7207
c19d1205 7208 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 7209 {
9c2799c2 7210 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
7211 if (!unind_ok)
7212 {
7213 inst.error = _("instruction does not support unindexed addressing");
7214 return FAIL;
7215 }
7216 inst.instruction |= inst.operands[i].imm;
7217 inst.instruction |= INDEX_UP;
7218 return SUCCESS;
09d92015 7219 }
a737bd4d 7220
c19d1205
ZW
7221 if (inst.operands[i].preind)
7222 inst.instruction |= PRE_INDEX;
a737bd4d 7223
c19d1205 7224 if (inst.operands[i].writeback)
09d92015 7225 {
c19d1205
ZW
7226 if (inst.operands[i].reg == REG_PC)
7227 {
7228 inst.error = _("pc may not be used with write-back");
7229 return FAIL;
7230 }
7231 if (!wb_ok)
7232 {
7233 inst.error = _("instruction does not support writeback");
7234 return FAIL;
7235 }
7236 inst.instruction |= WRITE_BACK;
09d92015 7237 }
a737bd4d 7238
c19d1205 7239 if (reloc_override)
21d799b5 7240 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
7241 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7242 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7243 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7244 {
7245 if (thumb_mode)
7246 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7247 else
7248 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7249 }
7250
26d97720
NS
7251 /* Prefer + for zero encoded value. */
7252 if (!inst.operands[i].negative)
7253 inst.instruction |= INDEX_UP;
7254
c19d1205
ZW
7255 return SUCCESS;
7256}
a737bd4d 7257
c19d1205
ZW
7258/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7259 Determine whether it can be performed with a move instruction; if
7260 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7261 return TRUE; if it can't, convert inst.instruction to a literal-pool
7262 load and return FALSE. If this is not a valid thing to do in the
7263 current context, set inst.error and return TRUE.
a737bd4d 7264
c19d1205
ZW
7265 inst.operands[i] describes the destination register. */
7266
c921be7d 7267static bfd_boolean
c19d1205
ZW
7268move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7269{
53365c0d
PB
7270 unsigned long tbit;
7271
7272 if (thumb_p)
7273 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7274 else
7275 tbit = LOAD_BIT;
7276
7277 if ((inst.instruction & tbit) == 0)
09d92015 7278 {
c19d1205 7279 inst.error = _("invalid pseudo operation");
c921be7d 7280 return TRUE;
09d92015 7281 }
c19d1205 7282 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
7283 {
7284 inst.error = _("constant expression expected");
c921be7d 7285 return TRUE;
09d92015 7286 }
c19d1205 7287 if (inst.reloc.exp.X_op == O_constant)
09d92015 7288 {
c19d1205
ZW
7289 if (thumb_p)
7290 {
53365c0d 7291 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
7292 {
7293 /* This can be done with a mov(1) instruction. */
7294 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7295 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 7296 return TRUE;
c19d1205
ZW
7297 }
7298 }
7299 else
7300 {
7301 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7302 if (value != FAIL)
7303 {
7304 /* This can be done with a mov instruction. */
7305 inst.instruction &= LITERAL_MASK;
7306 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7307 inst.instruction |= value & 0xfff;
c921be7d 7308 return TRUE;
c19d1205 7309 }
09d92015 7310
c19d1205
ZW
7311 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7312 if (value != FAIL)
7313 {
7314 /* This can be done with a mvn instruction. */
7315 inst.instruction &= LITERAL_MASK;
7316 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7317 inst.instruction |= value & 0xfff;
c921be7d 7318 return TRUE;
c19d1205
ZW
7319 }
7320 }
09d92015
MM
7321 }
7322
c19d1205
ZW
7323 if (add_to_lit_pool () == FAIL)
7324 {
7325 inst.error = _("literal pool insertion failed");
c921be7d 7326 return TRUE;
c19d1205
ZW
7327 }
7328 inst.operands[1].reg = REG_PC;
7329 inst.operands[1].isreg = 1;
7330 inst.operands[1].preind = 1;
7331 inst.reloc.pc_rel = 1;
7332 inst.reloc.type = (thumb_p
7333 ? BFD_RELOC_ARM_THUMB_OFFSET
7334 : (mode_3
7335 ? BFD_RELOC_ARM_HWLITERAL
7336 : BFD_RELOC_ARM_LITERAL));
c921be7d 7337 return FALSE;
09d92015
MM
7338}
7339
5f4273c7 7340/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7341 First some generics; their names are taken from the conventional
7342 bit positions for register arguments in ARM format instructions. */
09d92015 7343
a737bd4d 7344static void
c19d1205 7345do_noargs (void)
09d92015 7346{
c19d1205 7347}
a737bd4d 7348
c19d1205
ZW
7349static void
7350do_rd (void)
7351{
7352 inst.instruction |= inst.operands[0].reg << 12;
7353}
a737bd4d 7354
c19d1205
ZW
7355static void
7356do_rd_rm (void)
7357{
7358 inst.instruction |= inst.operands[0].reg << 12;
7359 inst.instruction |= inst.operands[1].reg;
7360}
09d92015 7361
c19d1205
ZW
7362static void
7363do_rd_rn (void)
7364{
7365 inst.instruction |= inst.operands[0].reg << 12;
7366 inst.instruction |= inst.operands[1].reg << 16;
7367}
a737bd4d 7368
c19d1205
ZW
7369static void
7370do_rn_rd (void)
7371{
7372 inst.instruction |= inst.operands[0].reg << 16;
7373 inst.instruction |= inst.operands[1].reg << 12;
7374}
09d92015 7375
59d09be6
MGD
7376static bfd_boolean
7377check_obsolete (const arm_feature_set *feature, const char *msg)
7378{
7379 if (ARM_CPU_IS_ANY (cpu_variant))
7380 {
7381 as_warn ("%s", msg);
7382 return TRUE;
7383 }
7384 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7385 {
7386 as_bad ("%s", msg);
7387 return TRUE;
7388 }
7389
7390 return FALSE;
7391}
7392
c19d1205
ZW
7393static void
7394do_rd_rm_rn (void)
7395{
9a64e435 7396 unsigned Rn = inst.operands[2].reg;
708587a4 7397 /* Enforce restrictions on SWP instruction. */
9a64e435 7398 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
7399 {
7400 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7401 _("Rn must not overlap other operands"));
7402
59d09be6
MGD
7403 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7404 */
7405 if (!check_obsolete (&arm_ext_v8,
7406 _("swp{b} use is obsoleted for ARMv8 and later"))
7407 && warn_on_deprecated
7408 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7409 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 7410 }
59d09be6 7411
c19d1205
ZW
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= inst.operands[1].reg;
9a64e435 7414 inst.instruction |= Rn << 16;
c19d1205 7415}
09d92015 7416
c19d1205
ZW
7417static void
7418do_rd_rn_rm (void)
7419{
7420 inst.instruction |= inst.operands[0].reg << 12;
7421 inst.instruction |= inst.operands[1].reg << 16;
7422 inst.instruction |= inst.operands[2].reg;
7423}
a737bd4d 7424
c19d1205
ZW
7425static void
7426do_rm_rd_rn (void)
7427{
5be8be5d
DG
7428 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7429 constraint (((inst.reloc.exp.X_op != O_constant
7430 && inst.reloc.exp.X_op != O_illegal)
7431 || inst.reloc.exp.X_add_number != 0),
7432 BAD_ADDR_MODE);
c19d1205
ZW
7433 inst.instruction |= inst.operands[0].reg;
7434 inst.instruction |= inst.operands[1].reg << 12;
7435 inst.instruction |= inst.operands[2].reg << 16;
7436}
09d92015 7437
c19d1205
ZW
7438static void
7439do_imm0 (void)
7440{
7441 inst.instruction |= inst.operands[0].imm;
7442}
09d92015 7443
c19d1205
ZW
7444static void
7445do_rd_cpaddr (void)
7446{
7447 inst.instruction |= inst.operands[0].reg << 12;
7448 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7449}
a737bd4d 7450
c19d1205
ZW
7451/* ARM instructions, in alphabetical order by function name (except
7452 that wrapper functions appear immediately after the function they
7453 wrap). */
09d92015 7454
c19d1205
ZW
7455/* This is a pseudo-op of the form "adr rd, label" to be converted
7456 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7457
7458static void
c19d1205 7459do_adr (void)
09d92015 7460{
c19d1205 7461 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7462
c19d1205
ZW
7463 /* Frag hacking will turn this into a sub instruction if the offset turns
7464 out to be negative. */
7465 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7466 inst.reloc.pc_rel = 1;
2fc8bdac 7467 inst.reloc.exp.X_add_number -= 8;
c19d1205 7468}
b99bd4ef 7469
c19d1205
ZW
7470/* This is a pseudo-op of the form "adrl rd, label" to be converted
7471 into a relative address of the form:
7472 add rd, pc, #low(label-.-8)"
7473 add rd, rd, #high(label-.-8)" */
b99bd4ef 7474
c19d1205
ZW
7475static void
7476do_adrl (void)
7477{
7478 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7479
c19d1205
ZW
7480 /* Frag hacking will turn this into a sub instruction if the offset turns
7481 out to be negative. */
7482 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7483 inst.reloc.pc_rel = 1;
7484 inst.size = INSN_SIZE * 2;
2fc8bdac 7485 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7486}
7487
b99bd4ef 7488static void
c19d1205 7489do_arit (void)
b99bd4ef 7490{
c19d1205
ZW
7491 if (!inst.operands[1].present)
7492 inst.operands[1].reg = inst.operands[0].reg;
7493 inst.instruction |= inst.operands[0].reg << 12;
7494 inst.instruction |= inst.operands[1].reg << 16;
7495 encode_arm_shifter_operand (2);
7496}
b99bd4ef 7497
62b3e311
PB
7498static void
7499do_barrier (void)
7500{
7501 if (inst.operands[0].present)
7502 {
7503 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
7504 && inst.operands[0].imm > 0xf
7505 && inst.operands[0].imm < 0x0,
bd3ba5d1 7506 _("bad barrier type"));
62b3e311
PB
7507 inst.instruction |= inst.operands[0].imm;
7508 }
7509 else
7510 inst.instruction |= 0xf;
7511}
7512
c19d1205
ZW
7513static void
7514do_bfc (void)
7515{
7516 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7517 constraint (msb > 32, _("bit-field extends past end of register"));
7518 /* The instruction encoding stores the LSB and MSB,
7519 not the LSB and width. */
7520 inst.instruction |= inst.operands[0].reg << 12;
7521 inst.instruction |= inst.operands[1].imm << 7;
7522 inst.instruction |= (msb - 1) << 16;
7523}
b99bd4ef 7524
c19d1205
ZW
7525static void
7526do_bfi (void)
7527{
7528 unsigned int msb;
b99bd4ef 7529
c19d1205
ZW
7530 /* #0 in second position is alternative syntax for bfc, which is
7531 the same instruction but with REG_PC in the Rm field. */
7532 if (!inst.operands[1].isreg)
7533 inst.operands[1].reg = REG_PC;
b99bd4ef 7534
c19d1205
ZW
7535 msb = inst.operands[2].imm + inst.operands[3].imm;
7536 constraint (msb > 32, _("bit-field extends past end of register"));
7537 /* The instruction encoding stores the LSB and MSB,
7538 not the LSB and width. */
7539 inst.instruction |= inst.operands[0].reg << 12;
7540 inst.instruction |= inst.operands[1].reg;
7541 inst.instruction |= inst.operands[2].imm << 7;
7542 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7543}
7544
b99bd4ef 7545static void
c19d1205 7546do_bfx (void)
b99bd4ef 7547{
c19d1205
ZW
7548 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7549 _("bit-field extends past end of register"));
7550 inst.instruction |= inst.operands[0].reg << 12;
7551 inst.instruction |= inst.operands[1].reg;
7552 inst.instruction |= inst.operands[2].imm << 7;
7553 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7554}
09d92015 7555
c19d1205
ZW
7556/* ARM V5 breakpoint instruction (argument parse)
7557 BKPT <16 bit unsigned immediate>
7558 Instruction is not conditional.
7559 The bit pattern given in insns[] has the COND_ALWAYS condition,
7560 and it is an error if the caller tried to override that. */
b99bd4ef 7561
c19d1205
ZW
7562static void
7563do_bkpt (void)
7564{
7565 /* Top 12 of 16 bits to bits 19:8. */
7566 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7567
c19d1205
ZW
7568 /* Bottom 4 of 16 bits to bits 3:0. */
7569 inst.instruction |= inst.operands[0].imm & 0xf;
7570}
09d92015 7571
c19d1205
ZW
7572static void
7573encode_branch (int default_reloc)
7574{
7575 if (inst.operands[0].hasreloc)
7576 {
0855e32b
NS
7577 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7578 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7579 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7580 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7581 ? BFD_RELOC_ARM_PLT32
7582 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 7583 }
b99bd4ef 7584 else
9ae92b05 7585 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 7586 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7587}
7588
b99bd4ef 7589static void
c19d1205 7590do_branch (void)
b99bd4ef 7591{
39b41c9c
PB
7592#ifdef OBJ_ELF
7593 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7594 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7595 else
7596#endif
7597 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7598}
7599
7600static void
7601do_bl (void)
7602{
7603#ifdef OBJ_ELF
7604 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7605 {
7606 if (inst.cond == COND_ALWAYS)
7607 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7608 else
7609 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7610 }
7611 else
7612#endif
7613 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7614}
b99bd4ef 7615
c19d1205
ZW
7616/* ARM V5 branch-link-exchange instruction (argument parse)
7617 BLX <target_addr> ie BLX(1)
7618 BLX{<condition>} <Rm> ie BLX(2)
7619 Unfortunately, there are two different opcodes for this mnemonic.
7620 So, the insns[].value is not used, and the code here zaps values
7621 into inst.instruction.
7622 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7623
c19d1205
ZW
7624static void
7625do_blx (void)
7626{
7627 if (inst.operands[0].isreg)
b99bd4ef 7628 {
c19d1205
ZW
7629 /* Arg is a register; the opcode provided by insns[] is correct.
7630 It is not illegal to do "blx pc", just useless. */
7631 if (inst.operands[0].reg == REG_PC)
7632 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7633
c19d1205
ZW
7634 inst.instruction |= inst.operands[0].reg;
7635 }
7636 else
b99bd4ef 7637 {
c19d1205 7638 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7639 conditionally, and the opcode must be adjusted.
7640 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7641 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7642 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7643 inst.instruction = 0xfa000000;
267bf995 7644 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7645 }
c19d1205
ZW
7646}
7647
7648static void
7649do_bx (void)
7650{
845b51d6
PB
7651 bfd_boolean want_reloc;
7652
c19d1205
ZW
7653 if (inst.operands[0].reg == REG_PC)
7654 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7655
c19d1205 7656 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7657 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7658 it is for ARMv4t or earlier. */
7659 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7660 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7661 want_reloc = TRUE;
7662
5ad34203 7663#ifdef OBJ_ELF
845b51d6 7664 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7665#endif
584206db 7666 want_reloc = FALSE;
845b51d6
PB
7667
7668 if (want_reloc)
7669 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7670}
7671
c19d1205
ZW
7672
7673/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7674
7675static void
c19d1205 7676do_bxj (void)
a737bd4d 7677{
c19d1205
ZW
7678 if (inst.operands[0].reg == REG_PC)
7679 as_tsktsk (_("use of r15 in bxj is not really useful"));
7680
7681 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7682}
7683
c19d1205
ZW
7684/* Co-processor data operation:
7685 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7686 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7687static void
7688do_cdp (void)
7689{
7690 inst.instruction |= inst.operands[0].reg << 8;
7691 inst.instruction |= inst.operands[1].imm << 20;
7692 inst.instruction |= inst.operands[2].reg << 12;
7693 inst.instruction |= inst.operands[3].reg << 16;
7694 inst.instruction |= inst.operands[4].reg;
7695 inst.instruction |= inst.operands[5].imm << 5;
7696}
a737bd4d
NC
7697
7698static void
c19d1205 7699do_cmp (void)
a737bd4d 7700{
c19d1205
ZW
7701 inst.instruction |= inst.operands[0].reg << 16;
7702 encode_arm_shifter_operand (1);
a737bd4d
NC
7703}
7704
c19d1205
ZW
7705/* Transfer between coprocessor and ARM registers.
7706 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7707 MRC2
7708 MCR{cond}
7709 MCR2
7710
7711 No special properties. */
09d92015
MM
7712
7713static void
c19d1205 7714do_co_reg (void)
09d92015 7715{
fdfde340
JM
7716 unsigned Rd;
7717
7718 Rd = inst.operands[2].reg;
7719 if (thumb_mode)
7720 {
7721 if (inst.instruction == 0xee000010
7722 || inst.instruction == 0xfe000010)
7723 /* MCR, MCR2 */
7724 reject_bad_reg (Rd);
7725 else
7726 /* MRC, MRC2 */
7727 constraint (Rd == REG_SP, BAD_SP);
7728 }
7729 else
7730 {
7731 /* MCR */
7732 if (inst.instruction == 0xe000010)
7733 constraint (Rd == REG_PC, BAD_PC);
7734 }
7735
7736
c19d1205
ZW
7737 inst.instruction |= inst.operands[0].reg << 8;
7738 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7739 inst.instruction |= Rd << 12;
c19d1205
ZW
7740 inst.instruction |= inst.operands[3].reg << 16;
7741 inst.instruction |= inst.operands[4].reg;
7742 inst.instruction |= inst.operands[5].imm << 5;
7743}
09d92015 7744
c19d1205
ZW
7745/* Transfer between coprocessor register and pair of ARM registers.
7746 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7747 MCRR2
7748 MRRC{cond}
7749 MRRC2
b99bd4ef 7750
c19d1205 7751 Two XScale instructions are special cases of these:
09d92015 7752
c19d1205
ZW
7753 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7754 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7755
5f4273c7 7756 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7757
c19d1205
ZW
7758static void
7759do_co_reg2c (void)
7760{
fdfde340
JM
7761 unsigned Rd, Rn;
7762
7763 Rd = inst.operands[2].reg;
7764 Rn = inst.operands[3].reg;
7765
7766 if (thumb_mode)
7767 {
7768 reject_bad_reg (Rd);
7769 reject_bad_reg (Rn);
7770 }
7771 else
7772 {
7773 constraint (Rd == REG_PC, BAD_PC);
7774 constraint (Rn == REG_PC, BAD_PC);
7775 }
7776
c19d1205
ZW
7777 inst.instruction |= inst.operands[0].reg << 8;
7778 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7779 inst.instruction |= Rd << 12;
7780 inst.instruction |= Rn << 16;
c19d1205 7781 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7782}
7783
c19d1205
ZW
7784static void
7785do_cpsi (void)
7786{
7787 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7788 if (inst.operands[1].present)
7789 {
7790 inst.instruction |= CPSI_MMOD;
7791 inst.instruction |= inst.operands[1].imm;
7792 }
c19d1205 7793}
b99bd4ef 7794
62b3e311
PB
7795static void
7796do_dbg (void)
7797{
7798 inst.instruction |= inst.operands[0].imm;
7799}
7800
eea54501
MGD
7801static void
7802do_div (void)
7803{
7804 unsigned Rd, Rn, Rm;
7805
7806 Rd = inst.operands[0].reg;
7807 Rn = (inst.operands[1].present
7808 ? inst.operands[1].reg : Rd);
7809 Rm = inst.operands[2].reg;
7810
7811 constraint ((Rd == REG_PC), BAD_PC);
7812 constraint ((Rn == REG_PC), BAD_PC);
7813 constraint ((Rm == REG_PC), BAD_PC);
7814
7815 inst.instruction |= Rd << 16;
7816 inst.instruction |= Rn << 0;
7817 inst.instruction |= Rm << 8;
7818}
7819
b99bd4ef 7820static void
c19d1205 7821do_it (void)
b99bd4ef 7822{
c19d1205 7823 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7824 process it to do the validation as if in
7825 thumb mode, just in case the code gets
7826 assembled for thumb using the unified syntax. */
7827
c19d1205 7828 inst.size = 0;
e07e6e58
NC
7829 if (unified_syntax)
7830 {
7831 set_it_insn_type (IT_INSN);
7832 now_it.mask = (inst.instruction & 0xf) | 0x10;
7833 now_it.cc = inst.operands[0].imm;
7834 }
09d92015 7835}
b99bd4ef 7836
6530b175
NC
7837/* If there is only one register in the register list,
7838 then return its register number. Otherwise return -1. */
7839static int
7840only_one_reg_in_list (int range)
7841{
7842 int i = ffs (range) - 1;
7843 return (i > 15 || range != (1 << i)) ? -1 : i;
7844}
7845
09d92015 7846static void
6530b175 7847encode_ldmstm(int from_push_pop_mnem)
ea6ef066 7848{
c19d1205
ZW
7849 int base_reg = inst.operands[0].reg;
7850 int range = inst.operands[1].imm;
6530b175 7851 int one_reg;
ea6ef066 7852
c19d1205
ZW
7853 inst.instruction |= base_reg << 16;
7854 inst.instruction |= range;
ea6ef066 7855
c19d1205
ZW
7856 if (inst.operands[1].writeback)
7857 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7858
c19d1205 7859 if (inst.operands[0].writeback)
ea6ef066 7860 {
c19d1205
ZW
7861 inst.instruction |= WRITE_BACK;
7862 /* Check for unpredictable uses of writeback. */
7863 if (inst.instruction & LOAD_BIT)
09d92015 7864 {
c19d1205
ZW
7865 /* Not allowed in LDM type 2. */
7866 if ((inst.instruction & LDM_TYPE_2_OR_3)
7867 && ((range & (1 << REG_PC)) == 0))
7868 as_warn (_("writeback of base register is UNPREDICTABLE"));
7869 /* Only allowed if base reg not in list for other types. */
7870 else if (range & (1 << base_reg))
7871 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7872 }
7873 else /* STM. */
7874 {
7875 /* Not allowed for type 2. */
7876 if (inst.instruction & LDM_TYPE_2_OR_3)
7877 as_warn (_("writeback of base register is UNPREDICTABLE"));
7878 /* Only allowed if base reg not in list, or first in list. */
7879 else if ((range & (1 << base_reg))
7880 && (range & ((1 << base_reg) - 1)))
7881 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7882 }
ea6ef066 7883 }
6530b175
NC
7884
7885 /* If PUSH/POP has only one register, then use the A2 encoding. */
7886 one_reg = only_one_reg_in_list (range);
7887 if (from_push_pop_mnem && one_reg >= 0)
7888 {
7889 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7890
7891 inst.instruction &= A_COND_MASK;
7892 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7893 inst.instruction |= one_reg << 12;
7894 }
7895}
7896
7897static void
7898do_ldmstm (void)
7899{
7900 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
7901}
7902
c19d1205
ZW
7903/* ARMv5TE load-consecutive (argument parse)
7904 Mode is like LDRH.
7905
7906 LDRccD R, mode
7907 STRccD R, mode. */
7908
a737bd4d 7909static void
c19d1205 7910do_ldrd (void)
a737bd4d 7911{
c19d1205 7912 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 7913 _("first transfer register must be even"));
c19d1205
ZW
7914 constraint (inst.operands[1].present
7915 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 7916 _("can only transfer two consecutive registers"));
c19d1205
ZW
7917 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7918 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7919
c19d1205
ZW
7920 if (!inst.operands[1].present)
7921 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7922
c56791bb
RE
7923 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7924 register and the first register written; we have to diagnose
7925 overlap between the base and the second register written here. */
ea6ef066 7926
c56791bb
RE
7927 if (inst.operands[2].reg == inst.operands[1].reg
7928 && (inst.operands[2].writeback || inst.operands[2].postind))
7929 as_warn (_("base register written back, and overlaps "
7930 "second transfer register"));
b05fe5cf 7931
c56791bb
RE
7932 if (!(inst.instruction & V4_STR_BIT))
7933 {
c19d1205 7934 /* For an index-register load, the index register must not overlap the
c56791bb
RE
7935 destination (even if not write-back). */
7936 if (inst.operands[2].immisreg
7937 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7938 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7939 as_warn (_("index register overlaps transfer register"));
b05fe5cf 7940 }
c19d1205
ZW
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7943}
7944
7945static void
c19d1205 7946do_ldrex (void)
b05fe5cf 7947{
c19d1205
ZW
7948 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7949 || inst.operands[1].postind || inst.operands[1].writeback
7950 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7951 || inst.operands[1].negative
7952 /* This can arise if the programmer has written
7953 strex rN, rM, foo
7954 or if they have mistakenly used a register name as the last
7955 operand, eg:
7956 strex rN, rM, rX
7957 It is very difficult to distinguish between these two cases
7958 because "rX" might actually be a label. ie the register
7959 name has been occluded by a symbol of the same name. So we
7960 just generate a general 'bad addressing mode' type error
7961 message and leave it up to the programmer to discover the
7962 true cause and fix their mistake. */
7963 || (inst.operands[1].reg == REG_PC),
7964 BAD_ADDR_MODE);
b05fe5cf 7965
c19d1205
ZW
7966 constraint (inst.reloc.exp.X_op != O_constant
7967 || inst.reloc.exp.X_add_number != 0,
7968 _("offset must be zero in ARM encoding"));
b05fe5cf 7969
5be8be5d
DG
7970 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7971
c19d1205
ZW
7972 inst.instruction |= inst.operands[0].reg << 12;
7973 inst.instruction |= inst.operands[1].reg << 16;
7974 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7975}
7976
7977static void
c19d1205 7978do_ldrexd (void)
b05fe5cf 7979{
c19d1205
ZW
7980 constraint (inst.operands[0].reg % 2 != 0,
7981 _("even register required"));
7982 constraint (inst.operands[1].present
7983 && inst.operands[1].reg != inst.operands[0].reg + 1,
7984 _("can only load two consecutive registers"));
7985 /* If op 1 were present and equal to PC, this function wouldn't
7986 have been called in the first place. */
7987 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7988
c19d1205
ZW
7989 inst.instruction |= inst.operands[0].reg << 12;
7990 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7991}
7992
1be5fd2e
NC
7993/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
7994 which is not a multiple of four is UNPREDICTABLE. */
7995static void
7996check_ldr_r15_aligned (void)
7997{
7998 constraint (!(inst.operands[1].immisreg)
7999 && (inst.operands[0].reg == REG_PC
8000 && inst.operands[1].reg == REG_PC
8001 && (inst.reloc.exp.X_add_number & 0x3)),
8002 _("ldr to register 15 must be 4-byte alligned"));
8003}
8004
b05fe5cf 8005static void
c19d1205 8006do_ldst (void)
b05fe5cf 8007{
c19d1205
ZW
8008 inst.instruction |= inst.operands[0].reg << 12;
8009 if (!inst.operands[1].isreg)
8010 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 8011 return;
c19d1205 8012 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8013 check_ldr_r15_aligned ();
b05fe5cf
ZW
8014}
8015
8016static void
c19d1205 8017do_ldstt (void)
b05fe5cf 8018{
c19d1205
ZW
8019 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8020 reject [Rn,...]. */
8021 if (inst.operands[1].preind)
b05fe5cf 8022 {
bd3ba5d1
NC
8023 constraint (inst.reloc.exp.X_op != O_constant
8024 || inst.reloc.exp.X_add_number != 0,
c19d1205 8025 _("this instruction requires a post-indexed address"));
b05fe5cf 8026
c19d1205
ZW
8027 inst.operands[1].preind = 0;
8028 inst.operands[1].postind = 1;
8029 inst.operands[1].writeback = 1;
b05fe5cf 8030 }
c19d1205
ZW
8031 inst.instruction |= inst.operands[0].reg << 12;
8032 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8033}
b05fe5cf 8034
c19d1205 8035/* Halfword and signed-byte load/store operations. */
b05fe5cf 8036
c19d1205
ZW
8037static void
8038do_ldstv4 (void)
8039{
ff4a8d2b 8040 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8041 inst.instruction |= inst.operands[0].reg << 12;
8042 if (!inst.operands[1].isreg)
8043 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 8044 return;
c19d1205 8045 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8046}
8047
8048static void
c19d1205 8049do_ldsttv4 (void)
b05fe5cf 8050{
c19d1205
ZW
8051 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8052 reject [Rn,...]. */
8053 if (inst.operands[1].preind)
b05fe5cf 8054 {
bd3ba5d1
NC
8055 constraint (inst.reloc.exp.X_op != O_constant
8056 || inst.reloc.exp.X_add_number != 0,
c19d1205 8057 _("this instruction requires a post-indexed address"));
b05fe5cf 8058
c19d1205
ZW
8059 inst.operands[1].preind = 0;
8060 inst.operands[1].postind = 1;
8061 inst.operands[1].writeback = 1;
b05fe5cf 8062 }
c19d1205
ZW
8063 inst.instruction |= inst.operands[0].reg << 12;
8064 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8065}
b05fe5cf 8066
c19d1205
ZW
8067/* Co-processor register load/store.
8068 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8069static void
8070do_lstc (void)
8071{
8072 inst.instruction |= inst.operands[0].reg << 8;
8073 inst.instruction |= inst.operands[1].reg << 12;
8074 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8075}
8076
b05fe5cf 8077static void
c19d1205 8078do_mlas (void)
b05fe5cf 8079{
8fb9d7b9 8080 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8081 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8082 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8083 && !(inst.instruction & 0x00400000))
8fb9d7b9 8084 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8085
c19d1205
ZW
8086 inst.instruction |= inst.operands[0].reg << 16;
8087 inst.instruction |= inst.operands[1].reg;
8088 inst.instruction |= inst.operands[2].reg << 8;
8089 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8090}
b05fe5cf 8091
c19d1205
ZW
8092static void
8093do_mov (void)
8094{
8095 inst.instruction |= inst.operands[0].reg << 12;
8096 encode_arm_shifter_operand (1);
8097}
b05fe5cf 8098
c19d1205
ZW
8099/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8100static void
8101do_mov16 (void)
8102{
b6895b4f
PB
8103 bfd_vma imm;
8104 bfd_boolean top;
8105
8106 top = (inst.instruction & 0x00400000) != 0;
8107 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8108 _(":lower16: not allowed this instruction"));
8109 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8110 _(":upper16: not allowed instruction"));
c19d1205 8111 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8112 if (inst.reloc.type == BFD_RELOC_UNUSED)
8113 {
8114 imm = inst.reloc.exp.X_add_number;
8115 /* The value is in two pieces: 0:11, 16:19. */
8116 inst.instruction |= (imm & 0x00000fff);
8117 inst.instruction |= (imm & 0x0000f000) << 4;
8118 }
b05fe5cf 8119}
b99bd4ef 8120
037e8744
JB
8121static void do_vfp_nsyn_opcode (const char *);
8122
8123static int
8124do_vfp_nsyn_mrs (void)
8125{
8126 if (inst.operands[0].isvec)
8127 {
8128 if (inst.operands[1].reg != 1)
8129 first_error (_("operand 1 must be FPSCR"));
8130 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8131 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8132 do_vfp_nsyn_opcode ("fmstat");
8133 }
8134 else if (inst.operands[1].isvec)
8135 do_vfp_nsyn_opcode ("fmrx");
8136 else
8137 return FAIL;
5f4273c7 8138
037e8744
JB
8139 return SUCCESS;
8140}
8141
8142static int
8143do_vfp_nsyn_msr (void)
8144{
8145 if (inst.operands[0].isvec)
8146 do_vfp_nsyn_opcode ("fmxr");
8147 else
8148 return FAIL;
8149
8150 return SUCCESS;
8151}
8152
f7c21dc7
NC
8153static void
8154do_vmrs (void)
8155{
8156 unsigned Rt = inst.operands[0].reg;
fa94de6b 8157
f7c21dc7
NC
8158 if (thumb_mode && inst.operands[0].reg == REG_SP)
8159 {
8160 inst.error = BAD_SP;
8161 return;
8162 }
8163
8164 /* APSR_ sets isvec. All other refs to PC are illegal. */
8165 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8166 {
8167 inst.error = BAD_PC;
8168 return;
8169 }
8170
7465e07a
NC
8171 switch (inst.operands[1].reg)
8172 {
8173 case 0: /* FPSID */
8174 case 1: /* FPSCR */
8175 case 6: /* MVFR1 */
8176 case 7: /* MVFR0 */
8177 case 8: /* FPEXC */
8178 inst.instruction |= (inst.operands[1].reg << 16);
8179 break;
8180 default:
8181 first_error (_("operand 1 must be a VFP extension System Register"));
8182 }
f7c21dc7
NC
8183
8184 inst.instruction |= (Rt << 12);
8185}
8186
8187static void
8188do_vmsr (void)
8189{
8190 unsigned Rt = inst.operands[1].reg;
fa94de6b 8191
f7c21dc7
NC
8192 if (thumb_mode)
8193 reject_bad_reg (Rt);
8194 else if (Rt == REG_PC)
8195 {
8196 inst.error = BAD_PC;
8197 return;
8198 }
8199
7465e07a
NC
8200 switch (inst.operands[0].reg)
8201 {
8202 case 0: /* FPSID */
8203 case 1: /* FPSCR */
8204 case 8: /* FPEXC */
8205 inst.instruction |= (inst.operands[0].reg << 16);
8206 break;
8207 default:
8208 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8209 }
f7c21dc7
NC
8210
8211 inst.instruction |= (Rt << 12);
8212}
8213
b99bd4ef 8214static void
c19d1205 8215do_mrs (void)
b99bd4ef 8216{
90ec0d68
MGD
8217 unsigned br;
8218
037e8744
JB
8219 if (do_vfp_nsyn_mrs () == SUCCESS)
8220 return;
8221
ff4a8d2b 8222 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8223 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8224
8225 if (inst.operands[1].isreg)
8226 {
8227 br = inst.operands[1].reg;
8228 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8229 as_bad (_("bad register for mrs"));
8230 }
8231 else
8232 {
8233 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8234 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8235 != (PSR_c|PSR_f),
d2cd1205 8236 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8237 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8238 }
8239
8240 inst.instruction |= br;
c19d1205 8241}
b99bd4ef 8242
c19d1205
ZW
8243/* Two possible forms:
8244 "{C|S}PSR_<field>, Rm",
8245 "{C|S}PSR_f, #expression". */
b99bd4ef 8246
c19d1205
ZW
8247static void
8248do_msr (void)
8249{
037e8744
JB
8250 if (do_vfp_nsyn_msr () == SUCCESS)
8251 return;
8252
c19d1205
ZW
8253 inst.instruction |= inst.operands[0].imm;
8254 if (inst.operands[1].isreg)
8255 inst.instruction |= inst.operands[1].reg;
8256 else
b99bd4ef 8257 {
c19d1205
ZW
8258 inst.instruction |= INST_IMMEDIATE;
8259 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8260 inst.reloc.pc_rel = 0;
b99bd4ef 8261 }
b99bd4ef
NC
8262}
8263
c19d1205
ZW
8264static void
8265do_mul (void)
a737bd4d 8266{
ff4a8d2b
NC
8267 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8268
c19d1205
ZW
8269 if (!inst.operands[2].present)
8270 inst.operands[2].reg = inst.operands[0].reg;
8271 inst.instruction |= inst.operands[0].reg << 16;
8272 inst.instruction |= inst.operands[1].reg;
8273 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8274
8fb9d7b9
MS
8275 if (inst.operands[0].reg == inst.operands[1].reg
8276 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8277 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8278}
8279
c19d1205
ZW
8280/* Long Multiply Parser
8281 UMULL RdLo, RdHi, Rm, Rs
8282 SMULL RdLo, RdHi, Rm, Rs
8283 UMLAL RdLo, RdHi, Rm, Rs
8284 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8285
8286static void
c19d1205 8287do_mull (void)
b99bd4ef 8288{
c19d1205
ZW
8289 inst.instruction |= inst.operands[0].reg << 12;
8290 inst.instruction |= inst.operands[1].reg << 16;
8291 inst.instruction |= inst.operands[2].reg;
8292 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8293
682b27ad
PB
8294 /* rdhi and rdlo must be different. */
8295 if (inst.operands[0].reg == inst.operands[1].reg)
8296 as_tsktsk (_("rdhi and rdlo must be different"));
8297
8298 /* rdhi, rdlo and rm must all be different before armv6. */
8299 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8300 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8301 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8302 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8303}
b99bd4ef 8304
c19d1205
ZW
8305static void
8306do_nop (void)
8307{
e7495e45
NS
8308 if (inst.operands[0].present
8309 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8310 {
8311 /* Architectural NOP hints are CPSR sets with no bits selected. */
8312 inst.instruction &= 0xf0000000;
e7495e45
NS
8313 inst.instruction |= 0x0320f000;
8314 if (inst.operands[0].present)
8315 inst.instruction |= inst.operands[0].imm;
c19d1205 8316 }
b99bd4ef
NC
8317}
8318
c19d1205
ZW
8319/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8320 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8321 Condition defaults to COND_ALWAYS.
8322 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8323
8324static void
c19d1205 8325do_pkhbt (void)
b99bd4ef 8326{
c19d1205
ZW
8327 inst.instruction |= inst.operands[0].reg << 12;
8328 inst.instruction |= inst.operands[1].reg << 16;
8329 inst.instruction |= inst.operands[2].reg;
8330 if (inst.operands[3].present)
8331 encode_arm_shift (3);
8332}
b99bd4ef 8333
c19d1205 8334/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8335
c19d1205
ZW
8336static void
8337do_pkhtb (void)
8338{
8339 if (!inst.operands[3].present)
b99bd4ef 8340 {
c19d1205
ZW
8341 /* If the shift specifier is omitted, turn the instruction
8342 into pkhbt rd, rm, rn. */
8343 inst.instruction &= 0xfff00010;
8344 inst.instruction |= inst.operands[0].reg << 12;
8345 inst.instruction |= inst.operands[1].reg;
8346 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8347 }
8348 else
8349 {
c19d1205
ZW
8350 inst.instruction |= inst.operands[0].reg << 12;
8351 inst.instruction |= inst.operands[1].reg << 16;
8352 inst.instruction |= inst.operands[2].reg;
8353 encode_arm_shift (3);
b99bd4ef
NC
8354 }
8355}
8356
c19d1205 8357/* ARMv5TE: Preload-Cache
60e5ef9f 8358 MP Extensions: Preload for write
c19d1205 8359
60e5ef9f 8360 PLD(W) <addr_mode>
c19d1205
ZW
8361
8362 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
8363
8364static void
c19d1205 8365do_pld (void)
b99bd4ef 8366{
c19d1205
ZW
8367 constraint (!inst.operands[0].isreg,
8368 _("'[' expected after PLD mnemonic"));
8369 constraint (inst.operands[0].postind,
8370 _("post-indexed expression used in preload instruction"));
8371 constraint (inst.operands[0].writeback,
8372 _("writeback used in preload instruction"));
8373 constraint (!inst.operands[0].preind,
8374 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
8375 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8376}
b99bd4ef 8377
62b3e311
PB
8378/* ARMv7: PLI <addr_mode> */
8379static void
8380do_pli (void)
8381{
8382 constraint (!inst.operands[0].isreg,
8383 _("'[' expected after PLI mnemonic"));
8384 constraint (inst.operands[0].postind,
8385 _("post-indexed expression used in preload instruction"));
8386 constraint (inst.operands[0].writeback,
8387 _("writeback used in preload instruction"));
8388 constraint (!inst.operands[0].preind,
8389 _("unindexed addressing used in preload instruction"));
8390 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8391 inst.instruction &= ~PRE_INDEX;
8392}
8393
c19d1205
ZW
8394static void
8395do_push_pop (void)
8396{
8397 inst.operands[1] = inst.operands[0];
8398 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8399 inst.operands[0].isreg = 1;
8400 inst.operands[0].writeback = 1;
8401 inst.operands[0].reg = REG_SP;
6530b175 8402 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 8403}
b99bd4ef 8404
c19d1205
ZW
8405/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8406 word at the specified address and the following word
8407 respectively.
8408 Unconditionally executed.
8409 Error if Rn is R15. */
b99bd4ef 8410
c19d1205
ZW
8411static void
8412do_rfe (void)
8413{
8414 inst.instruction |= inst.operands[0].reg << 16;
8415 if (inst.operands[0].writeback)
8416 inst.instruction |= WRITE_BACK;
8417}
b99bd4ef 8418
c19d1205 8419/* ARM V6 ssat (argument parse). */
b99bd4ef 8420
c19d1205
ZW
8421static void
8422do_ssat (void)
8423{
8424 inst.instruction |= inst.operands[0].reg << 12;
8425 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8426 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8427
c19d1205
ZW
8428 if (inst.operands[3].present)
8429 encode_arm_shift (3);
b99bd4ef
NC
8430}
8431
c19d1205 8432/* ARM V6 usat (argument parse). */
b99bd4ef
NC
8433
8434static void
c19d1205 8435do_usat (void)
b99bd4ef 8436{
c19d1205
ZW
8437 inst.instruction |= inst.operands[0].reg << 12;
8438 inst.instruction |= inst.operands[1].imm << 16;
8439 inst.instruction |= inst.operands[2].reg;
b99bd4ef 8440
c19d1205
ZW
8441 if (inst.operands[3].present)
8442 encode_arm_shift (3);
b99bd4ef
NC
8443}
8444
c19d1205 8445/* ARM V6 ssat16 (argument parse). */
09d92015
MM
8446
8447static void
c19d1205 8448do_ssat16 (void)
09d92015 8449{
c19d1205
ZW
8450 inst.instruction |= inst.operands[0].reg << 12;
8451 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8452 inst.instruction |= inst.operands[2].reg;
09d92015
MM
8453}
8454
c19d1205
ZW
8455static void
8456do_usat16 (void)
a737bd4d 8457{
c19d1205
ZW
8458 inst.instruction |= inst.operands[0].reg << 12;
8459 inst.instruction |= inst.operands[1].imm << 16;
8460 inst.instruction |= inst.operands[2].reg;
8461}
a737bd4d 8462
c19d1205
ZW
8463/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8464 preserving the other bits.
a737bd4d 8465
c19d1205
ZW
8466 setend <endian_specifier>, where <endian_specifier> is either
8467 BE or LE. */
a737bd4d 8468
c19d1205
ZW
8469static void
8470do_setend (void)
8471{
8472 if (inst.operands[0].imm)
8473 inst.instruction |= 0x200;
a737bd4d
NC
8474}
8475
8476static void
c19d1205 8477do_shift (void)
a737bd4d 8478{
c19d1205
ZW
8479 unsigned int Rm = (inst.operands[1].present
8480 ? inst.operands[1].reg
8481 : inst.operands[0].reg);
a737bd4d 8482
c19d1205
ZW
8483 inst.instruction |= inst.operands[0].reg << 12;
8484 inst.instruction |= Rm;
8485 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 8486 {
c19d1205
ZW
8487 inst.instruction |= inst.operands[2].reg << 8;
8488 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
8489 /* PR 12854: Error on extraneous shifts. */
8490 constraint (inst.operands[2].shifted,
8491 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
8492 }
8493 else
c19d1205 8494 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
8495}
8496
09d92015 8497static void
3eb17e6b 8498do_smc (void)
09d92015 8499{
3eb17e6b 8500 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 8501 inst.reloc.pc_rel = 0;
09d92015
MM
8502}
8503
90ec0d68
MGD
8504static void
8505do_hvc (void)
8506{
8507 inst.reloc.type = BFD_RELOC_ARM_HVC;
8508 inst.reloc.pc_rel = 0;
8509}
8510
09d92015 8511static void
c19d1205 8512do_swi (void)
09d92015 8513{
c19d1205
ZW
8514 inst.reloc.type = BFD_RELOC_ARM_SWI;
8515 inst.reloc.pc_rel = 0;
09d92015
MM
8516}
8517
c19d1205
ZW
8518/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8519 SMLAxy{cond} Rd,Rm,Rs,Rn
8520 SMLAWy{cond} Rd,Rm,Rs,Rn
8521 Error if any register is R15. */
e16bb312 8522
c19d1205
ZW
8523static void
8524do_smla (void)
e16bb312 8525{
c19d1205
ZW
8526 inst.instruction |= inst.operands[0].reg << 16;
8527 inst.instruction |= inst.operands[1].reg;
8528 inst.instruction |= inst.operands[2].reg << 8;
8529 inst.instruction |= inst.operands[3].reg << 12;
8530}
a737bd4d 8531
c19d1205
ZW
8532/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8533 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8534 Error if any register is R15.
8535 Warning if Rdlo == Rdhi. */
a737bd4d 8536
c19d1205
ZW
8537static void
8538do_smlal (void)
8539{
8540 inst.instruction |= inst.operands[0].reg << 12;
8541 inst.instruction |= inst.operands[1].reg << 16;
8542 inst.instruction |= inst.operands[2].reg;
8543 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8544
c19d1205
ZW
8545 if (inst.operands[0].reg == inst.operands[1].reg)
8546 as_tsktsk (_("rdhi and rdlo must be different"));
8547}
a737bd4d 8548
c19d1205
ZW
8549/* ARM V5E (El Segundo) signed-multiply (argument parse)
8550 SMULxy{cond} Rd,Rm,Rs
8551 Error if any register is R15. */
a737bd4d 8552
c19d1205
ZW
8553static void
8554do_smul (void)
8555{
8556 inst.instruction |= inst.operands[0].reg << 16;
8557 inst.instruction |= inst.operands[1].reg;
8558 inst.instruction |= inst.operands[2].reg << 8;
8559}
a737bd4d 8560
b6702015
PB
8561/* ARM V6 srs (argument parse). The variable fields in the encoding are
8562 the same for both ARM and Thumb-2. */
a737bd4d 8563
c19d1205
ZW
8564static void
8565do_srs (void)
8566{
b6702015
PB
8567 int reg;
8568
8569 if (inst.operands[0].present)
8570 {
8571 reg = inst.operands[0].reg;
fdfde340 8572 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8573 }
8574 else
fdfde340 8575 reg = REG_SP;
b6702015
PB
8576
8577 inst.instruction |= reg << 16;
8578 inst.instruction |= inst.operands[1].imm;
8579 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8580 inst.instruction |= WRITE_BACK;
8581}
a737bd4d 8582
c19d1205 8583/* ARM V6 strex (argument parse). */
a737bd4d 8584
c19d1205
ZW
8585static void
8586do_strex (void)
8587{
8588 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8589 || inst.operands[2].postind || inst.operands[2].writeback
8590 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8591 || inst.operands[2].negative
8592 /* See comment in do_ldrex(). */
8593 || (inst.operands[2].reg == REG_PC),
8594 BAD_ADDR_MODE);
a737bd4d 8595
c19d1205
ZW
8596 constraint (inst.operands[0].reg == inst.operands[1].reg
8597 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8598
c19d1205
ZW
8599 constraint (inst.reloc.exp.X_op != O_constant
8600 || inst.reloc.exp.X_add_number != 0,
8601 _("offset must be zero in ARM encoding"));
a737bd4d 8602
c19d1205
ZW
8603 inst.instruction |= inst.operands[0].reg << 12;
8604 inst.instruction |= inst.operands[1].reg;
8605 inst.instruction |= inst.operands[2].reg << 16;
8606 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8607}
8608
877807f8
NC
8609static void
8610do_t_strexbh (void)
8611{
8612 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8613 || inst.operands[2].postind || inst.operands[2].writeback
8614 || inst.operands[2].immisreg || inst.operands[2].shifted
8615 || inst.operands[2].negative,
8616 BAD_ADDR_MODE);
8617
8618 constraint (inst.operands[0].reg == inst.operands[1].reg
8619 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8620
8621 do_rm_rd_rn ();
8622}
8623
e16bb312 8624static void
c19d1205 8625do_strexd (void)
e16bb312 8626{
c19d1205
ZW
8627 constraint (inst.operands[1].reg % 2 != 0,
8628 _("even register required"));
8629 constraint (inst.operands[2].present
8630 && inst.operands[2].reg != inst.operands[1].reg + 1,
8631 _("can only store two consecutive registers"));
8632 /* If op 2 were present and equal to PC, this function wouldn't
8633 have been called in the first place. */
8634 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8635
c19d1205
ZW
8636 constraint (inst.operands[0].reg == inst.operands[1].reg
8637 || inst.operands[0].reg == inst.operands[1].reg + 1
8638 || inst.operands[0].reg == inst.operands[3].reg,
8639 BAD_OVERLAP);
e16bb312 8640
c19d1205
ZW
8641 inst.instruction |= inst.operands[0].reg << 12;
8642 inst.instruction |= inst.operands[1].reg;
8643 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8644}
8645
c19d1205
ZW
8646/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8647 extends it to 32-bits, and adds the result to a value in another
8648 register. You can specify a rotation by 0, 8, 16, or 24 bits
8649 before extracting the 16-bit value.
8650 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8651 Condition defaults to COND_ALWAYS.
8652 Error if any register uses R15. */
8653
e16bb312 8654static void
c19d1205 8655do_sxtah (void)
e16bb312 8656{
c19d1205
ZW
8657 inst.instruction |= inst.operands[0].reg << 12;
8658 inst.instruction |= inst.operands[1].reg << 16;
8659 inst.instruction |= inst.operands[2].reg;
8660 inst.instruction |= inst.operands[3].imm << 10;
8661}
e16bb312 8662
c19d1205 8663/* ARM V6 SXTH.
e16bb312 8664
c19d1205
ZW
8665 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8666 Condition defaults to COND_ALWAYS.
8667 Error if any register uses R15. */
e16bb312
NC
8668
8669static void
c19d1205 8670do_sxth (void)
e16bb312 8671{
c19d1205
ZW
8672 inst.instruction |= inst.operands[0].reg << 12;
8673 inst.instruction |= inst.operands[1].reg;
8674 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8675}
c19d1205
ZW
8676\f
8677/* VFP instructions. In a logical order: SP variant first, monad
8678 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8679
8680static void
c19d1205 8681do_vfp_sp_monadic (void)
e16bb312 8682{
5287ad62
JB
8683 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8684 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8685}
8686
8687static void
c19d1205 8688do_vfp_sp_dyadic (void)
e16bb312 8689{
5287ad62
JB
8690 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8691 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8692 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8693}
8694
8695static void
c19d1205 8696do_vfp_sp_compare_z (void)
e16bb312 8697{
5287ad62 8698 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8699}
8700
8701static void
c19d1205 8702do_vfp_dp_sp_cvt (void)
e16bb312 8703{
5287ad62
JB
8704 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8705 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8706}
8707
8708static void
c19d1205 8709do_vfp_sp_dp_cvt (void)
e16bb312 8710{
5287ad62
JB
8711 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8712 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8713}
8714
8715static void
c19d1205 8716do_vfp_reg_from_sp (void)
e16bb312 8717{
c19d1205 8718 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8719 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8720}
8721
8722static void
c19d1205 8723do_vfp_reg2_from_sp2 (void)
e16bb312 8724{
c19d1205
ZW
8725 constraint (inst.operands[2].imm != 2,
8726 _("only two consecutive VFP SP registers allowed here"));
8727 inst.instruction |= inst.operands[0].reg << 12;
8728 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8729 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8730}
8731
8732static void
c19d1205 8733do_vfp_sp_from_reg (void)
e16bb312 8734{
5287ad62 8735 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8736 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8737}
8738
8739static void
c19d1205 8740do_vfp_sp2_from_reg2 (void)
e16bb312 8741{
c19d1205
ZW
8742 constraint (inst.operands[0].imm != 2,
8743 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8744 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8745 inst.instruction |= inst.operands[1].reg << 12;
8746 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8747}
8748
8749static void
c19d1205 8750do_vfp_sp_ldst (void)
e16bb312 8751{
5287ad62 8752 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8753 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8754}
8755
8756static void
c19d1205 8757do_vfp_dp_ldst (void)
e16bb312 8758{
5287ad62 8759 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8760 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8761}
8762
c19d1205 8763
e16bb312 8764static void
c19d1205 8765vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8766{
c19d1205
ZW
8767 if (inst.operands[0].writeback)
8768 inst.instruction |= WRITE_BACK;
8769 else
8770 constraint (ldstm_type != VFP_LDSTMIA,
8771 _("this addressing mode requires base-register writeback"));
8772 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8773 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8774 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8775}
8776
8777static void
c19d1205 8778vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8779{
c19d1205 8780 int count;
e16bb312 8781
c19d1205
ZW
8782 if (inst.operands[0].writeback)
8783 inst.instruction |= WRITE_BACK;
8784 else
8785 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8786 _("this addressing mode requires base-register writeback"));
e16bb312 8787
c19d1205 8788 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8789 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8790
c19d1205
ZW
8791 count = inst.operands[1].imm << 1;
8792 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8793 count += 1;
e16bb312 8794
c19d1205 8795 inst.instruction |= count;
e16bb312
NC
8796}
8797
8798static void
c19d1205 8799do_vfp_sp_ldstmia (void)
e16bb312 8800{
c19d1205 8801 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8802}
8803
8804static void
c19d1205 8805do_vfp_sp_ldstmdb (void)
e16bb312 8806{
c19d1205 8807 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8808}
8809
8810static void
c19d1205 8811do_vfp_dp_ldstmia (void)
e16bb312 8812{
c19d1205 8813 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8814}
8815
8816static void
c19d1205 8817do_vfp_dp_ldstmdb (void)
e16bb312 8818{
c19d1205 8819 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8820}
8821
8822static void
c19d1205 8823do_vfp_xp_ldstmia (void)
e16bb312 8824{
c19d1205
ZW
8825 vfp_dp_ldstm (VFP_LDSTMIAX);
8826}
e16bb312 8827
c19d1205
ZW
8828static void
8829do_vfp_xp_ldstmdb (void)
8830{
8831 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8832}
5287ad62
JB
8833
8834static void
8835do_vfp_dp_rd_rm (void)
8836{
8837 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8838 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8839}
8840
8841static void
8842do_vfp_dp_rn_rd (void)
8843{
8844 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8845 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8846}
8847
8848static void
8849do_vfp_dp_rd_rn (void)
8850{
8851 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8852 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8853}
8854
8855static void
8856do_vfp_dp_rd_rn_rm (void)
8857{
8858 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8859 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8860 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8861}
8862
8863static void
8864do_vfp_dp_rd (void)
8865{
8866 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8867}
8868
8869static void
8870do_vfp_dp_rm_rd_rn (void)
8871{
8872 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8873 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8874 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8875}
8876
8877/* VFPv3 instructions. */
8878static void
8879do_vfp_sp_const (void)
8880{
8881 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8882 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8883 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8884}
8885
8886static void
8887do_vfp_dp_const (void)
8888{
8889 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8890 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8891 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8892}
8893
8894static void
8895vfp_conv (int srcsize)
8896{
5f1af56b
MGD
8897 int immbits = srcsize - inst.operands[1].imm;
8898
fa94de6b
RM
8899 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8900 {
5f1af56b
MGD
8901 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8902 i.e. immbits must be in range 0 - 16. */
8903 inst.error = _("immediate value out of range, expected range [0, 16]");
8904 return;
8905 }
fa94de6b 8906 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
8907 {
8908 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8909 i.e. immbits must be in range 0 - 31. */
8910 inst.error = _("immediate value out of range, expected range [1, 32]");
8911 return;
8912 }
8913
5287ad62
JB
8914 inst.instruction |= (immbits & 1) << 5;
8915 inst.instruction |= (immbits >> 1);
8916}
8917
8918static void
8919do_vfp_sp_conv_16 (void)
8920{
8921 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8922 vfp_conv (16);
8923}
8924
8925static void
8926do_vfp_dp_conv_16 (void)
8927{
8928 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8929 vfp_conv (16);
8930}
8931
8932static void
8933do_vfp_sp_conv_32 (void)
8934{
8935 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8936 vfp_conv (32);
8937}
8938
8939static void
8940do_vfp_dp_conv_32 (void)
8941{
8942 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8943 vfp_conv (32);
8944}
c19d1205
ZW
8945\f
8946/* FPA instructions. Also in a logical order. */
e16bb312 8947
c19d1205
ZW
8948static void
8949do_fpa_cmp (void)
8950{
8951 inst.instruction |= inst.operands[0].reg << 16;
8952 inst.instruction |= inst.operands[1].reg;
8953}
b99bd4ef
NC
8954
8955static void
c19d1205 8956do_fpa_ldmstm (void)
b99bd4ef 8957{
c19d1205
ZW
8958 inst.instruction |= inst.operands[0].reg << 12;
8959 switch (inst.operands[1].imm)
8960 {
8961 case 1: inst.instruction |= CP_T_X; break;
8962 case 2: inst.instruction |= CP_T_Y; break;
8963 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8964 case 4: break;
8965 default: abort ();
8966 }
b99bd4ef 8967
c19d1205
ZW
8968 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8969 {
8970 /* The instruction specified "ea" or "fd", so we can only accept
8971 [Rn]{!}. The instruction does not really support stacking or
8972 unstacking, so we have to emulate these by setting appropriate
8973 bits and offsets. */
8974 constraint (inst.reloc.exp.X_op != O_constant
8975 || inst.reloc.exp.X_add_number != 0,
8976 _("this instruction does not support indexing"));
b99bd4ef 8977
c19d1205
ZW
8978 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8979 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8980
c19d1205
ZW
8981 if (!(inst.instruction & INDEX_UP))
8982 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8983
c19d1205
ZW
8984 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8985 {
8986 inst.operands[2].preind = 0;
8987 inst.operands[2].postind = 1;
8988 }
8989 }
b99bd4ef 8990
c19d1205 8991 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8992}
c19d1205
ZW
8993\f
8994/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8995
c19d1205
ZW
8996static void
8997do_iwmmxt_tandorc (void)
8998{
8999 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9000}
b99bd4ef 9001
c19d1205
ZW
9002static void
9003do_iwmmxt_textrc (void)
9004{
9005 inst.instruction |= inst.operands[0].reg << 12;
9006 inst.instruction |= inst.operands[1].imm;
9007}
b99bd4ef
NC
9008
9009static void
c19d1205 9010do_iwmmxt_textrm (void)
b99bd4ef 9011{
c19d1205
ZW
9012 inst.instruction |= inst.operands[0].reg << 12;
9013 inst.instruction |= inst.operands[1].reg << 16;
9014 inst.instruction |= inst.operands[2].imm;
9015}
b99bd4ef 9016
c19d1205
ZW
9017static void
9018do_iwmmxt_tinsr (void)
9019{
9020 inst.instruction |= inst.operands[0].reg << 16;
9021 inst.instruction |= inst.operands[1].reg << 12;
9022 inst.instruction |= inst.operands[2].imm;
9023}
b99bd4ef 9024
c19d1205
ZW
9025static void
9026do_iwmmxt_tmia (void)
9027{
9028 inst.instruction |= inst.operands[0].reg << 5;
9029 inst.instruction |= inst.operands[1].reg;
9030 inst.instruction |= inst.operands[2].reg << 12;
9031}
b99bd4ef 9032
c19d1205
ZW
9033static void
9034do_iwmmxt_waligni (void)
9035{
9036 inst.instruction |= inst.operands[0].reg << 12;
9037 inst.instruction |= inst.operands[1].reg << 16;
9038 inst.instruction |= inst.operands[2].reg;
9039 inst.instruction |= inst.operands[3].imm << 20;
9040}
b99bd4ef 9041
2d447fca
JM
9042static void
9043do_iwmmxt_wmerge (void)
9044{
9045 inst.instruction |= inst.operands[0].reg << 12;
9046 inst.instruction |= inst.operands[1].reg << 16;
9047 inst.instruction |= inst.operands[2].reg;
9048 inst.instruction |= inst.operands[3].imm << 21;
9049}
9050
c19d1205
ZW
9051static void
9052do_iwmmxt_wmov (void)
9053{
9054 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9055 inst.instruction |= inst.operands[0].reg << 12;
9056 inst.instruction |= inst.operands[1].reg << 16;
9057 inst.instruction |= inst.operands[1].reg;
9058}
b99bd4ef 9059
c19d1205
ZW
9060static void
9061do_iwmmxt_wldstbh (void)
9062{
8f06b2d8 9063 int reloc;
c19d1205 9064 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9065 if (thumb_mode)
9066 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9067 else
9068 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9069 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9070}
9071
c19d1205
ZW
9072static void
9073do_iwmmxt_wldstw (void)
9074{
9075 /* RIWR_RIWC clears .isreg for a control register. */
9076 if (!inst.operands[0].isreg)
9077 {
9078 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9079 inst.instruction |= 0xf0000000;
9080 }
b99bd4ef 9081
c19d1205
ZW
9082 inst.instruction |= inst.operands[0].reg << 12;
9083 encode_arm_cp_address (1, TRUE, TRUE, 0);
9084}
b99bd4ef
NC
9085
9086static void
c19d1205 9087do_iwmmxt_wldstd (void)
b99bd4ef 9088{
c19d1205 9089 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9090 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9091 && inst.operands[1].immisreg)
9092 {
9093 inst.instruction &= ~0x1a000ff;
9094 inst.instruction |= (0xf << 28);
9095 if (inst.operands[1].preind)
9096 inst.instruction |= PRE_INDEX;
9097 if (!inst.operands[1].negative)
9098 inst.instruction |= INDEX_UP;
9099 if (inst.operands[1].writeback)
9100 inst.instruction |= WRITE_BACK;
9101 inst.instruction |= inst.operands[1].reg << 16;
9102 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9103 inst.instruction |= inst.operands[1].imm;
9104 }
9105 else
9106 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9107}
b99bd4ef 9108
c19d1205
ZW
9109static void
9110do_iwmmxt_wshufh (void)
9111{
9112 inst.instruction |= inst.operands[0].reg << 12;
9113 inst.instruction |= inst.operands[1].reg << 16;
9114 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9115 inst.instruction |= (inst.operands[2].imm & 0x0f);
9116}
b99bd4ef 9117
c19d1205
ZW
9118static void
9119do_iwmmxt_wzero (void)
9120{
9121 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9122 inst.instruction |= inst.operands[0].reg;
9123 inst.instruction |= inst.operands[0].reg << 12;
9124 inst.instruction |= inst.operands[0].reg << 16;
9125}
2d447fca
JM
9126
9127static void
9128do_iwmmxt_wrwrwr_or_imm5 (void)
9129{
9130 if (inst.operands[2].isreg)
9131 do_rd_rn_rm ();
9132 else {
9133 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9134 _("immediate operand requires iWMMXt2"));
9135 do_rd_rn ();
9136 if (inst.operands[2].imm == 0)
9137 {
9138 switch ((inst.instruction >> 20) & 0xf)
9139 {
9140 case 4:
9141 case 5:
9142 case 6:
5f4273c7 9143 case 7:
2d447fca
JM
9144 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9145 inst.operands[2].imm = 16;
9146 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9147 break;
9148 case 8:
9149 case 9:
9150 case 10:
9151 case 11:
9152 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9153 inst.operands[2].imm = 32;
9154 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9155 break;
9156 case 12:
9157 case 13:
9158 case 14:
9159 case 15:
9160 {
9161 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9162 unsigned long wrn;
9163 wrn = (inst.instruction >> 16) & 0xf;
9164 inst.instruction &= 0xff0fff0f;
9165 inst.instruction |= wrn;
9166 /* Bail out here; the instruction is now assembled. */
9167 return;
9168 }
9169 }
9170 }
9171 /* Map 32 -> 0, etc. */
9172 inst.operands[2].imm &= 0x1f;
9173 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9174 }
9175}
c19d1205
ZW
9176\f
9177/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9178 operations first, then control, shift, and load/store. */
b99bd4ef 9179
c19d1205 9180/* Insns like "foo X,Y,Z". */
b99bd4ef 9181
c19d1205
ZW
9182static void
9183do_mav_triple (void)
9184{
9185 inst.instruction |= inst.operands[0].reg << 16;
9186 inst.instruction |= inst.operands[1].reg;
9187 inst.instruction |= inst.operands[2].reg << 12;
9188}
b99bd4ef 9189
c19d1205
ZW
9190/* Insns like "foo W,X,Y,Z".
9191 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9192
c19d1205
ZW
9193static void
9194do_mav_quad (void)
9195{
9196 inst.instruction |= inst.operands[0].reg << 5;
9197 inst.instruction |= inst.operands[1].reg << 12;
9198 inst.instruction |= inst.operands[2].reg << 16;
9199 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9200}
9201
c19d1205
ZW
9202/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9203static void
9204do_mav_dspsc (void)
a737bd4d 9205{
c19d1205
ZW
9206 inst.instruction |= inst.operands[1].reg << 12;
9207}
a737bd4d 9208
c19d1205
ZW
9209/* Maverick shift immediate instructions.
9210 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9211 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9212
c19d1205
ZW
9213static void
9214do_mav_shift (void)
9215{
9216 int imm = inst.operands[2].imm;
a737bd4d 9217
c19d1205
ZW
9218 inst.instruction |= inst.operands[0].reg << 12;
9219 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9220
c19d1205
ZW
9221 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9222 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9223 Bit 4 should be 0. */
9224 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9225
c19d1205
ZW
9226 inst.instruction |= imm;
9227}
9228\f
9229/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9230
c19d1205
ZW
9231/* Xscale multiply-accumulate (argument parse)
9232 MIAcc acc0,Rm,Rs
9233 MIAPHcc acc0,Rm,Rs
9234 MIAxycc acc0,Rm,Rs. */
a737bd4d 9235
c19d1205
ZW
9236static void
9237do_xsc_mia (void)
9238{
9239 inst.instruction |= inst.operands[1].reg;
9240 inst.instruction |= inst.operands[2].reg << 12;
9241}
a737bd4d 9242
c19d1205 9243/* Xscale move-accumulator-register (argument parse)
a737bd4d 9244
c19d1205 9245 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9246
c19d1205
ZW
9247static void
9248do_xsc_mar (void)
9249{
9250 inst.instruction |= inst.operands[1].reg << 12;
9251 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9252}
9253
c19d1205 9254/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9255
c19d1205 9256 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9257
9258static void
c19d1205 9259do_xsc_mra (void)
b99bd4ef 9260{
c19d1205
ZW
9261 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9262 inst.instruction |= inst.operands[0].reg << 12;
9263 inst.instruction |= inst.operands[1].reg << 16;
9264}
9265\f
9266/* Encoding functions relevant only to Thumb. */
b99bd4ef 9267
c19d1205
ZW
9268/* inst.operands[i] is a shifted-register operand; encode
9269 it into inst.instruction in the format used by Thumb32. */
9270
9271static void
9272encode_thumb32_shifted_operand (int i)
9273{
9274 unsigned int value = inst.reloc.exp.X_add_number;
9275 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9276
9c3c69f2
PB
9277 constraint (inst.operands[i].immisreg,
9278 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9279 inst.instruction |= inst.operands[i].reg;
9280 if (shift == SHIFT_RRX)
9281 inst.instruction |= SHIFT_ROR << 4;
9282 else
b99bd4ef 9283 {
c19d1205
ZW
9284 constraint (inst.reloc.exp.X_op != O_constant,
9285 _("expression too complex"));
9286
9287 constraint (value > 32
9288 || (value == 32 && (shift == SHIFT_LSL
9289 || shift == SHIFT_ROR)),
9290 _("shift expression is too large"));
9291
9292 if (value == 0)
9293 shift = SHIFT_LSL;
9294 else if (value == 32)
9295 value = 0;
9296
9297 inst.instruction |= shift << 4;
9298 inst.instruction |= (value & 0x1c) << 10;
9299 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 9300 }
c19d1205 9301}
b99bd4ef 9302
b99bd4ef 9303
c19d1205
ZW
9304/* inst.operands[i] was set up by parse_address. Encode it into a
9305 Thumb32 format load or store instruction. Reject forms that cannot
9306 be used with such instructions. If is_t is true, reject forms that
9307 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
9308 that cannot be used with a D instruction. If it is a store insn,
9309 reject PC in Rn. */
b99bd4ef 9310
c19d1205
ZW
9311static void
9312encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9313{
5be8be5d 9314 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
9315
9316 constraint (!inst.operands[i].isreg,
53365c0d 9317 _("Instruction does not support =N addresses"));
b99bd4ef 9318
c19d1205
ZW
9319 inst.instruction |= inst.operands[i].reg << 16;
9320 if (inst.operands[i].immisreg)
b99bd4ef 9321 {
5be8be5d 9322 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
9323 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9324 constraint (inst.operands[i].negative,
9325 _("Thumb does not support negative register indexing"));
9326 constraint (inst.operands[i].postind,
9327 _("Thumb does not support register post-indexing"));
9328 constraint (inst.operands[i].writeback,
9329 _("Thumb does not support register indexing with writeback"));
9330 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9331 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 9332
f40d1643 9333 inst.instruction |= inst.operands[i].imm;
c19d1205 9334 if (inst.operands[i].shifted)
b99bd4ef 9335 {
c19d1205
ZW
9336 constraint (inst.reloc.exp.X_op != O_constant,
9337 _("expression too complex"));
9c3c69f2
PB
9338 constraint (inst.reloc.exp.X_add_number < 0
9339 || inst.reloc.exp.X_add_number > 3,
c19d1205 9340 _("shift out of range"));
9c3c69f2 9341 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
9342 }
9343 inst.reloc.type = BFD_RELOC_UNUSED;
9344 }
9345 else if (inst.operands[i].preind)
9346 {
5be8be5d 9347 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 9348 constraint (is_t && inst.operands[i].writeback,
c19d1205 9349 _("cannot use writeback with this instruction"));
5be8be5d
DG
9350 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9351 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
9352
9353 if (is_d)
9354 {
9355 inst.instruction |= 0x01000000;
9356 if (inst.operands[i].writeback)
9357 inst.instruction |= 0x00200000;
b99bd4ef 9358 }
c19d1205 9359 else
b99bd4ef 9360 {
c19d1205
ZW
9361 inst.instruction |= 0x00000c00;
9362 if (inst.operands[i].writeback)
9363 inst.instruction |= 0x00000100;
b99bd4ef 9364 }
c19d1205 9365 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 9366 }
c19d1205 9367 else if (inst.operands[i].postind)
b99bd4ef 9368 {
9c2799c2 9369 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
9370 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9371 constraint (is_t, _("cannot use post-indexing with this instruction"));
9372
9373 if (is_d)
9374 inst.instruction |= 0x00200000;
9375 else
9376 inst.instruction |= 0x00000900;
9377 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9378 }
9379 else /* unindexed - only for coprocessor */
9380 inst.error = _("instruction does not accept unindexed addressing");
9381}
9382
9383/* Table of Thumb instructions which exist in both 16- and 32-bit
9384 encodings (the latter only in post-V6T2 cores). The index is the
9385 value used in the insns table below. When there is more than one
9386 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
9387 holds variant (1).
9388 Also contains several pseudo-instructions used during relaxation. */
c19d1205 9389#define T16_32_TAB \
21d799b5
NC
9390 X(_adc, 4140, eb400000), \
9391 X(_adcs, 4140, eb500000), \
9392 X(_add, 1c00, eb000000), \
9393 X(_adds, 1c00, eb100000), \
9394 X(_addi, 0000, f1000000), \
9395 X(_addis, 0000, f1100000), \
9396 X(_add_pc,000f, f20f0000), \
9397 X(_add_sp,000d, f10d0000), \
9398 X(_adr, 000f, f20f0000), \
9399 X(_and, 4000, ea000000), \
9400 X(_ands, 4000, ea100000), \
9401 X(_asr, 1000, fa40f000), \
9402 X(_asrs, 1000, fa50f000), \
9403 X(_b, e000, f000b000), \
9404 X(_bcond, d000, f0008000), \
9405 X(_bic, 4380, ea200000), \
9406 X(_bics, 4380, ea300000), \
9407 X(_cmn, 42c0, eb100f00), \
9408 X(_cmp, 2800, ebb00f00), \
9409 X(_cpsie, b660, f3af8400), \
9410 X(_cpsid, b670, f3af8600), \
9411 X(_cpy, 4600, ea4f0000), \
9412 X(_dec_sp,80dd, f1ad0d00), \
9413 X(_eor, 4040, ea800000), \
9414 X(_eors, 4040, ea900000), \
9415 X(_inc_sp,00dd, f10d0d00), \
9416 X(_ldmia, c800, e8900000), \
9417 X(_ldr, 6800, f8500000), \
9418 X(_ldrb, 7800, f8100000), \
9419 X(_ldrh, 8800, f8300000), \
9420 X(_ldrsb, 5600, f9100000), \
9421 X(_ldrsh, 5e00, f9300000), \
9422 X(_ldr_pc,4800, f85f0000), \
9423 X(_ldr_pc2,4800, f85f0000), \
9424 X(_ldr_sp,9800, f85d0000), \
9425 X(_lsl, 0000, fa00f000), \
9426 X(_lsls, 0000, fa10f000), \
9427 X(_lsr, 0800, fa20f000), \
9428 X(_lsrs, 0800, fa30f000), \
9429 X(_mov, 2000, ea4f0000), \
9430 X(_movs, 2000, ea5f0000), \
9431 X(_mul, 4340, fb00f000), \
9432 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9433 X(_mvn, 43c0, ea6f0000), \
9434 X(_mvns, 43c0, ea7f0000), \
9435 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9436 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9437 X(_orr, 4300, ea400000), \
9438 X(_orrs, 4300, ea500000), \
9439 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9440 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9441 X(_rev, ba00, fa90f080), \
9442 X(_rev16, ba40, fa90f090), \
9443 X(_revsh, bac0, fa90f0b0), \
9444 X(_ror, 41c0, fa60f000), \
9445 X(_rors, 41c0, fa70f000), \
9446 X(_sbc, 4180, eb600000), \
9447 X(_sbcs, 4180, eb700000), \
9448 X(_stmia, c000, e8800000), \
9449 X(_str, 6000, f8400000), \
9450 X(_strb, 7000, f8000000), \
9451 X(_strh, 8000, f8200000), \
9452 X(_str_sp,9000, f84d0000), \
9453 X(_sub, 1e00, eba00000), \
9454 X(_subs, 1e00, ebb00000), \
9455 X(_subi, 8000, f1a00000), \
9456 X(_subis, 8000, f1b00000), \
9457 X(_sxtb, b240, fa4ff080), \
9458 X(_sxth, b200, fa0ff080), \
9459 X(_tst, 4200, ea100f00), \
9460 X(_uxtb, b2c0, fa5ff080), \
9461 X(_uxth, b280, fa1ff080), \
9462 X(_nop, bf00, f3af8000), \
9463 X(_yield, bf10, f3af8001), \
9464 X(_wfe, bf20, f3af8002), \
9465 X(_wfi, bf30, f3af8003), \
9466 X(_sev, bf40, f3af8004),
c19d1205
ZW
9467
9468/* To catch errors in encoding functions, the codes are all offset by
9469 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9470 as 16-bit instructions. */
21d799b5 9471#define X(a,b,c) T_MNEM##a
c19d1205
ZW
9472enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9473#undef X
9474
9475#define X(a,b,c) 0x##b
9476static const unsigned short thumb_op16[] = { T16_32_TAB };
9477#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9478#undef X
9479
9480#define X(a,b,c) 0x##c
9481static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
9482#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9483#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
9484#undef X
9485#undef T16_32_TAB
9486
9487/* Thumb instruction encoders, in alphabetical order. */
9488
92e90b6e 9489/* ADDW or SUBW. */
c921be7d 9490
92e90b6e
PB
9491static void
9492do_t_add_sub_w (void)
9493{
9494 int Rd, Rn;
9495
9496 Rd = inst.operands[0].reg;
9497 Rn = inst.operands[1].reg;
9498
539d4391
NC
9499 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9500 is the SP-{plus,minus}-immediate form of the instruction. */
9501 if (Rn == REG_SP)
9502 constraint (Rd == REG_PC, BAD_PC);
9503 else
9504 reject_bad_reg (Rd);
fdfde340 9505
92e90b6e
PB
9506 inst.instruction |= (Rn << 16) | (Rd << 8);
9507 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9508}
9509
c19d1205
ZW
9510/* Parse an add or subtract instruction. We get here with inst.instruction
9511 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9512
9513static void
9514do_t_add_sub (void)
9515{
9516 int Rd, Rs, Rn;
9517
9518 Rd = inst.operands[0].reg;
9519 Rs = (inst.operands[1].present
9520 ? inst.operands[1].reg /* Rd, Rs, foo */
9521 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9522
e07e6e58
NC
9523 if (Rd == REG_PC)
9524 set_it_insn_type_last ();
9525
c19d1205
ZW
9526 if (unified_syntax)
9527 {
0110f2b8
PB
9528 bfd_boolean flags;
9529 bfd_boolean narrow;
9530 int opcode;
9531
9532 flags = (inst.instruction == T_MNEM_adds
9533 || inst.instruction == T_MNEM_subs);
9534 if (flags)
e07e6e58 9535 narrow = !in_it_block ();
0110f2b8 9536 else
e07e6e58 9537 narrow = in_it_block ();
c19d1205 9538 if (!inst.operands[2].isreg)
b99bd4ef 9539 {
16805f35
PB
9540 int add;
9541
fdfde340
JM
9542 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9543
16805f35
PB
9544 add = (inst.instruction == T_MNEM_add
9545 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9546 opcode = 0;
9547 if (inst.size_req != 4)
9548 {
0110f2b8
PB
9549 /* Attempt to use a narrow opcode, with relaxation if
9550 appropriate. */
9551 if (Rd == REG_SP && Rs == REG_SP && !flags)
9552 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9553 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9554 opcode = T_MNEM_add_sp;
9555 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9556 opcode = T_MNEM_add_pc;
9557 else if (Rd <= 7 && Rs <= 7 && narrow)
9558 {
9559 if (flags)
9560 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9561 else
9562 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9563 }
9564 if (opcode)
9565 {
9566 inst.instruction = THUMB_OP16(opcode);
9567 inst.instruction |= (Rd << 4) | Rs;
9568 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9569 if (inst.size_req != 2)
9570 inst.relax = opcode;
9571 }
9572 else
9573 constraint (inst.size_req == 2, BAD_HIREG);
9574 }
9575 if (inst.size_req == 4
9576 || (inst.size_req != 2 && !opcode))
9577 {
efd81785
PB
9578 if (Rd == REG_PC)
9579 {
fdfde340 9580 constraint (add, BAD_PC);
efd81785
PB
9581 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9582 _("only SUBS PC, LR, #const allowed"));
9583 constraint (inst.reloc.exp.X_op != O_constant,
9584 _("expression too complex"));
9585 constraint (inst.reloc.exp.X_add_number < 0
9586 || inst.reloc.exp.X_add_number > 0xff,
9587 _("immediate value out of range"));
9588 inst.instruction = T2_SUBS_PC_LR
9589 | inst.reloc.exp.X_add_number;
9590 inst.reloc.type = BFD_RELOC_UNUSED;
9591 return;
9592 }
9593 else if (Rs == REG_PC)
16805f35
PB
9594 {
9595 /* Always use addw/subw. */
9596 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9597 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9598 }
9599 else
9600 {
9601 inst.instruction = THUMB_OP32 (inst.instruction);
9602 inst.instruction = (inst.instruction & 0xe1ffffff)
9603 | 0x10000000;
9604 if (flags)
9605 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9606 else
9607 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9608 }
dc4503c6
PB
9609 inst.instruction |= Rd << 8;
9610 inst.instruction |= Rs << 16;
0110f2b8 9611 }
b99bd4ef 9612 }
c19d1205
ZW
9613 else
9614 {
5f4cb198
NC
9615 unsigned int value = inst.reloc.exp.X_add_number;
9616 unsigned int shift = inst.operands[2].shift_kind;
9617
c19d1205
ZW
9618 Rn = inst.operands[2].reg;
9619 /* See if we can do this with a 16-bit instruction. */
9620 if (!inst.operands[2].shifted && inst.size_req != 4)
9621 {
e27ec89e
PB
9622 if (Rd > 7 || Rs > 7 || Rn > 7)
9623 narrow = FALSE;
9624
9625 if (narrow)
c19d1205 9626 {
e27ec89e
PB
9627 inst.instruction = ((inst.instruction == T_MNEM_adds
9628 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9629 ? T_OPCODE_ADD_R3
9630 : T_OPCODE_SUB_R3);
9631 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9632 return;
9633 }
b99bd4ef 9634
7e806470 9635 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9636 {
7e806470
PB
9637 /* Thumb-1 cores (except v6-M) require at least one high
9638 register in a narrow non flag setting add. */
9639 if (Rd > 7 || Rn > 7
9640 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9641 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9642 {
7e806470
PB
9643 if (Rd == Rn)
9644 {
9645 Rn = Rs;
9646 Rs = Rd;
9647 }
c19d1205
ZW
9648 inst.instruction = T_OPCODE_ADD_HI;
9649 inst.instruction |= (Rd & 8) << 4;
9650 inst.instruction |= (Rd & 7);
9651 inst.instruction |= Rn << 3;
9652 return;
9653 }
c19d1205
ZW
9654 }
9655 }
c921be7d 9656
fdfde340
JM
9657 constraint (Rd == REG_PC, BAD_PC);
9658 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9659 constraint (Rs == REG_PC, BAD_PC);
9660 reject_bad_reg (Rn);
9661
c19d1205
ZW
9662 /* If we get here, it can't be done in 16 bits. */
9663 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9664 _("shift must be constant"));
9665 inst.instruction = THUMB_OP32 (inst.instruction);
9666 inst.instruction |= Rd << 8;
9667 inst.instruction |= Rs << 16;
5f4cb198
NC
9668 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9669 _("shift value over 3 not allowed in thumb mode"));
9670 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9671 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
9672 encode_thumb32_shifted_operand (2);
9673 }
9674 }
9675 else
9676 {
9677 constraint (inst.instruction == T_MNEM_adds
9678 || inst.instruction == T_MNEM_subs,
9679 BAD_THUMB32);
b99bd4ef 9680
c19d1205 9681 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9682 {
c19d1205
ZW
9683 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9684 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9685 BAD_HIREG);
9686
9687 inst.instruction = (inst.instruction == T_MNEM_add
9688 ? 0x0000 : 0x8000);
9689 inst.instruction |= (Rd << 4) | Rs;
9690 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9691 return;
9692 }
9693
c19d1205
ZW
9694 Rn = inst.operands[2].reg;
9695 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9696
c19d1205
ZW
9697 /* We now have Rd, Rs, and Rn set to registers. */
9698 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9699 {
c19d1205
ZW
9700 /* Can't do this for SUB. */
9701 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9702 inst.instruction = T_OPCODE_ADD_HI;
9703 inst.instruction |= (Rd & 8) << 4;
9704 inst.instruction |= (Rd & 7);
9705 if (Rs == Rd)
9706 inst.instruction |= Rn << 3;
9707 else if (Rn == Rd)
9708 inst.instruction |= Rs << 3;
9709 else
9710 constraint (1, _("dest must overlap one source register"));
9711 }
9712 else
9713 {
9714 inst.instruction = (inst.instruction == T_MNEM_add
9715 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9716 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9717 }
b99bd4ef 9718 }
b99bd4ef
NC
9719}
9720
c19d1205
ZW
9721static void
9722do_t_adr (void)
9723{
fdfde340
JM
9724 unsigned Rd;
9725
9726 Rd = inst.operands[0].reg;
9727 reject_bad_reg (Rd);
9728
9729 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9730 {
9731 /* Defer to section relaxation. */
9732 inst.relax = inst.instruction;
9733 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9734 inst.instruction |= Rd << 4;
0110f2b8
PB
9735 }
9736 else if (unified_syntax && inst.size_req != 2)
e9f89963 9737 {
0110f2b8 9738 /* Generate a 32-bit opcode. */
e9f89963 9739 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9740 inst.instruction |= Rd << 8;
e9f89963
PB
9741 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9742 inst.reloc.pc_rel = 1;
9743 }
9744 else
9745 {
0110f2b8 9746 /* Generate a 16-bit opcode. */
e9f89963
PB
9747 inst.instruction = THUMB_OP16 (inst.instruction);
9748 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9749 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9750 inst.reloc.pc_rel = 1;
b99bd4ef 9751
fdfde340 9752 inst.instruction |= Rd << 4;
e9f89963 9753 }
c19d1205 9754}
b99bd4ef 9755
c19d1205
ZW
9756/* Arithmetic instructions for which there is just one 16-bit
9757 instruction encoding, and it allows only two low registers.
9758 For maximal compatibility with ARM syntax, we allow three register
9759 operands even when Thumb-32 instructions are not available, as long
9760 as the first two are identical. For instance, both "sbc r0,r1" and
9761 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9762static void
c19d1205 9763do_t_arit3 (void)
b99bd4ef 9764{
c19d1205 9765 int Rd, Rs, Rn;
b99bd4ef 9766
c19d1205
ZW
9767 Rd = inst.operands[0].reg;
9768 Rs = (inst.operands[1].present
9769 ? inst.operands[1].reg /* Rd, Rs, foo */
9770 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9771 Rn = inst.operands[2].reg;
b99bd4ef 9772
fdfde340
JM
9773 reject_bad_reg (Rd);
9774 reject_bad_reg (Rs);
9775 if (inst.operands[2].isreg)
9776 reject_bad_reg (Rn);
9777
c19d1205 9778 if (unified_syntax)
b99bd4ef 9779 {
c19d1205
ZW
9780 if (!inst.operands[2].isreg)
9781 {
9782 /* For an immediate, we always generate a 32-bit opcode;
9783 section relaxation will shrink it later if possible. */
9784 inst.instruction = THUMB_OP32 (inst.instruction);
9785 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9786 inst.instruction |= Rd << 8;
9787 inst.instruction |= Rs << 16;
9788 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9789 }
9790 else
9791 {
e27ec89e
PB
9792 bfd_boolean narrow;
9793
c19d1205 9794 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9795 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9796 narrow = !in_it_block ();
e27ec89e 9797 else
e07e6e58 9798 narrow = in_it_block ();
e27ec89e
PB
9799
9800 if (Rd > 7 || Rn > 7 || Rs > 7)
9801 narrow = FALSE;
9802 if (inst.operands[2].shifted)
9803 narrow = FALSE;
9804 if (inst.size_req == 4)
9805 narrow = FALSE;
9806
9807 if (narrow
c19d1205
ZW
9808 && Rd == Rs)
9809 {
9810 inst.instruction = THUMB_OP16 (inst.instruction);
9811 inst.instruction |= Rd;
9812 inst.instruction |= Rn << 3;
9813 return;
9814 }
b99bd4ef 9815
c19d1205
ZW
9816 /* If we get here, it can't be done in 16 bits. */
9817 constraint (inst.operands[2].shifted
9818 && inst.operands[2].immisreg,
9819 _("shift must be constant"));
9820 inst.instruction = THUMB_OP32 (inst.instruction);
9821 inst.instruction |= Rd << 8;
9822 inst.instruction |= Rs << 16;
9823 encode_thumb32_shifted_operand (2);
9824 }
a737bd4d 9825 }
c19d1205 9826 else
b99bd4ef 9827 {
c19d1205
ZW
9828 /* On its face this is a lie - the instruction does set the
9829 flags. However, the only supported mnemonic in this mode
9830 says it doesn't. */
9831 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9832
c19d1205
ZW
9833 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9834 _("unshifted register required"));
9835 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9836 constraint (Rd != Rs,
9837 _("dest and source1 must be the same register"));
a737bd4d 9838
c19d1205
ZW
9839 inst.instruction = THUMB_OP16 (inst.instruction);
9840 inst.instruction |= Rd;
9841 inst.instruction |= Rn << 3;
b99bd4ef 9842 }
a737bd4d 9843}
b99bd4ef 9844
c19d1205
ZW
9845/* Similarly, but for instructions where the arithmetic operation is
9846 commutative, so we can allow either of them to be different from
9847 the destination operand in a 16-bit instruction. For instance, all
9848 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9849 accepted. */
9850static void
9851do_t_arit3c (void)
a737bd4d 9852{
c19d1205 9853 int Rd, Rs, Rn;
b99bd4ef 9854
c19d1205
ZW
9855 Rd = inst.operands[0].reg;
9856 Rs = (inst.operands[1].present
9857 ? inst.operands[1].reg /* Rd, Rs, foo */
9858 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9859 Rn = inst.operands[2].reg;
c921be7d 9860
fdfde340
JM
9861 reject_bad_reg (Rd);
9862 reject_bad_reg (Rs);
9863 if (inst.operands[2].isreg)
9864 reject_bad_reg (Rn);
a737bd4d 9865
c19d1205 9866 if (unified_syntax)
a737bd4d 9867 {
c19d1205 9868 if (!inst.operands[2].isreg)
b99bd4ef 9869 {
c19d1205
ZW
9870 /* For an immediate, we always generate a 32-bit opcode;
9871 section relaxation will shrink it later if possible. */
9872 inst.instruction = THUMB_OP32 (inst.instruction);
9873 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9874 inst.instruction |= Rd << 8;
9875 inst.instruction |= Rs << 16;
9876 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9877 }
c19d1205 9878 else
a737bd4d 9879 {
e27ec89e
PB
9880 bfd_boolean narrow;
9881
c19d1205 9882 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9883 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9884 narrow = !in_it_block ();
e27ec89e 9885 else
e07e6e58 9886 narrow = in_it_block ();
e27ec89e
PB
9887
9888 if (Rd > 7 || Rn > 7 || Rs > 7)
9889 narrow = FALSE;
9890 if (inst.operands[2].shifted)
9891 narrow = FALSE;
9892 if (inst.size_req == 4)
9893 narrow = FALSE;
9894
9895 if (narrow)
a737bd4d 9896 {
c19d1205 9897 if (Rd == Rs)
a737bd4d 9898 {
c19d1205
ZW
9899 inst.instruction = THUMB_OP16 (inst.instruction);
9900 inst.instruction |= Rd;
9901 inst.instruction |= Rn << 3;
9902 return;
a737bd4d 9903 }
c19d1205 9904 if (Rd == Rn)
a737bd4d 9905 {
c19d1205
ZW
9906 inst.instruction = THUMB_OP16 (inst.instruction);
9907 inst.instruction |= Rd;
9908 inst.instruction |= Rs << 3;
9909 return;
a737bd4d
NC
9910 }
9911 }
c19d1205
ZW
9912
9913 /* If we get here, it can't be done in 16 bits. */
9914 constraint (inst.operands[2].shifted
9915 && inst.operands[2].immisreg,
9916 _("shift must be constant"));
9917 inst.instruction = THUMB_OP32 (inst.instruction);
9918 inst.instruction |= Rd << 8;
9919 inst.instruction |= Rs << 16;
9920 encode_thumb32_shifted_operand (2);
a737bd4d 9921 }
b99bd4ef 9922 }
c19d1205
ZW
9923 else
9924 {
9925 /* On its face this is a lie - the instruction does set the
9926 flags. However, the only supported mnemonic in this mode
9927 says it doesn't. */
9928 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9929
c19d1205
ZW
9930 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9931 _("unshifted register required"));
9932 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9933
9934 inst.instruction = THUMB_OP16 (inst.instruction);
9935 inst.instruction |= Rd;
9936
9937 if (Rd == Rs)
9938 inst.instruction |= Rn << 3;
9939 else if (Rd == Rn)
9940 inst.instruction |= Rs << 3;
9941 else
9942 constraint (1, _("dest must overlap one source register"));
9943 }
a737bd4d
NC
9944}
9945
62b3e311
PB
9946static void
9947do_t_barrier (void)
9948{
9949 if (inst.operands[0].present)
9950 {
9951 constraint ((inst.instruction & 0xf0) != 0x40
52e7f43d
RE
9952 && inst.operands[0].imm > 0xf
9953 && inst.operands[0].imm < 0x0,
bd3ba5d1 9954 _("bad barrier type"));
62b3e311
PB
9955 inst.instruction |= inst.operands[0].imm;
9956 }
9957 else
9958 inst.instruction |= 0xf;
9959}
9960
c19d1205
ZW
9961static void
9962do_t_bfc (void)
a737bd4d 9963{
fdfde340 9964 unsigned Rd;
c19d1205
ZW
9965 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9966 constraint (msb > 32, _("bit-field extends past end of register"));
9967 /* The instruction encoding stores the LSB and MSB,
9968 not the LSB and width. */
fdfde340
JM
9969 Rd = inst.operands[0].reg;
9970 reject_bad_reg (Rd);
9971 inst.instruction |= Rd << 8;
c19d1205
ZW
9972 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9973 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9974 inst.instruction |= msb - 1;
b99bd4ef
NC
9975}
9976
c19d1205
ZW
9977static void
9978do_t_bfi (void)
b99bd4ef 9979{
fdfde340 9980 int Rd, Rn;
c19d1205 9981 unsigned int msb;
b99bd4ef 9982
fdfde340
JM
9983 Rd = inst.operands[0].reg;
9984 reject_bad_reg (Rd);
9985
c19d1205
ZW
9986 /* #0 in second position is alternative syntax for bfc, which is
9987 the same instruction but with REG_PC in the Rm field. */
9988 if (!inst.operands[1].isreg)
fdfde340
JM
9989 Rn = REG_PC;
9990 else
9991 {
9992 Rn = inst.operands[1].reg;
9993 reject_bad_reg (Rn);
9994 }
b99bd4ef 9995
c19d1205
ZW
9996 msb = inst.operands[2].imm + inst.operands[3].imm;
9997 constraint (msb > 32, _("bit-field extends past end of register"));
9998 /* The instruction encoding stores the LSB and MSB,
9999 not the LSB and width. */
fdfde340
JM
10000 inst.instruction |= Rd << 8;
10001 inst.instruction |= Rn << 16;
c19d1205
ZW
10002 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10003 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10004 inst.instruction |= msb - 1;
b99bd4ef
NC
10005}
10006
c19d1205
ZW
10007static void
10008do_t_bfx (void)
b99bd4ef 10009{
fdfde340
JM
10010 unsigned Rd, Rn;
10011
10012 Rd = inst.operands[0].reg;
10013 Rn = inst.operands[1].reg;
10014
10015 reject_bad_reg (Rd);
10016 reject_bad_reg (Rn);
10017
c19d1205
ZW
10018 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10019 _("bit-field extends past end of register"));
fdfde340
JM
10020 inst.instruction |= Rd << 8;
10021 inst.instruction |= Rn << 16;
c19d1205
ZW
10022 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10023 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10024 inst.instruction |= inst.operands[3].imm - 1;
10025}
b99bd4ef 10026
c19d1205
ZW
10027/* ARM V5 Thumb BLX (argument parse)
10028 BLX <target_addr> which is BLX(1)
10029 BLX <Rm> which is BLX(2)
10030 Unfortunately, there are two different opcodes for this mnemonic.
10031 So, the insns[].value is not used, and the code here zaps values
10032 into inst.instruction.
b99bd4ef 10033
c19d1205
ZW
10034 ??? How to take advantage of the additional two bits of displacement
10035 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10036
c19d1205
ZW
10037static void
10038do_t_blx (void)
10039{
e07e6e58
NC
10040 set_it_insn_type_last ();
10041
c19d1205 10042 if (inst.operands[0].isreg)
fdfde340
JM
10043 {
10044 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10045 /* We have a register, so this is BLX(2). */
10046 inst.instruction |= inst.operands[0].reg << 3;
10047 }
b99bd4ef
NC
10048 else
10049 {
c19d1205 10050 /* No register. This must be BLX(1). */
2fc8bdac 10051 inst.instruction = 0xf000e800;
0855e32b 10052 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10053 }
10054}
10055
c19d1205
ZW
10056static void
10057do_t_branch (void)
b99bd4ef 10058{
0110f2b8 10059 int opcode;
dfa9f0d5 10060 int cond;
9ae92b05 10061 int reloc;
dfa9f0d5 10062
e07e6e58
NC
10063 cond = inst.cond;
10064 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10065
10066 if (in_it_block ())
dfa9f0d5
PB
10067 {
10068 /* Conditional branches inside IT blocks are encoded as unconditional
10069 branches. */
10070 cond = COND_ALWAYS;
dfa9f0d5
PB
10071 }
10072 else
10073 cond = inst.cond;
10074
10075 if (cond != COND_ALWAYS)
0110f2b8
PB
10076 opcode = T_MNEM_bcond;
10077 else
10078 opcode = inst.instruction;
10079
12d6b0b7
RS
10080 if (unified_syntax
10081 && (inst.size_req == 4
10960bfb
PB
10082 || (inst.size_req != 2
10083 && (inst.operands[0].hasreloc
10084 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10085 {
0110f2b8 10086 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10087 if (cond == COND_ALWAYS)
9ae92b05 10088 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10089 else
10090 {
9c2799c2 10091 gas_assert (cond != 0xF);
dfa9f0d5 10092 inst.instruction |= cond << 22;
9ae92b05 10093 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10094 }
10095 }
b99bd4ef
NC
10096 else
10097 {
0110f2b8 10098 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10099 if (cond == COND_ALWAYS)
9ae92b05 10100 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10101 else
b99bd4ef 10102 {
dfa9f0d5 10103 inst.instruction |= cond << 8;
9ae92b05 10104 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10105 }
0110f2b8
PB
10106 /* Allow section relaxation. */
10107 if (unified_syntax && inst.size_req != 2)
10108 inst.relax = opcode;
b99bd4ef 10109 }
9ae92b05 10110 inst.reloc.type = reloc;
c19d1205 10111 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10112}
10113
10114static void
c19d1205 10115do_t_bkpt (void)
b99bd4ef 10116{
dfa9f0d5
PB
10117 constraint (inst.cond != COND_ALWAYS,
10118 _("instruction is always unconditional"));
c19d1205 10119 if (inst.operands[0].present)
b99bd4ef 10120 {
c19d1205
ZW
10121 constraint (inst.operands[0].imm > 255,
10122 _("immediate value out of range"));
10123 inst.instruction |= inst.operands[0].imm;
e07e6e58 10124 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 10125 }
b99bd4ef
NC
10126}
10127
10128static void
c19d1205 10129do_t_branch23 (void)
b99bd4ef 10130{
e07e6e58 10131 set_it_insn_type_last ();
0855e32b 10132 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10133
0855e32b
NS
10134 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10135 this file. We used to simply ignore the PLT reloc type here --
10136 the branch encoding is now needed to deal with TLSCALL relocs.
10137 So if we see a PLT reloc now, put it back to how it used to be to
10138 keep the preexisting behaviour. */
10139 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10140 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10141
4343666d 10142#if defined(OBJ_COFF)
c19d1205
ZW
10143 /* If the destination of the branch is a defined symbol which does not have
10144 the THUMB_FUNC attribute, then we must be calling a function which has
10145 the (interfacearm) attribute. We look for the Thumb entry point to that
10146 function and change the branch to refer to that function instead. */
10147 if ( inst.reloc.exp.X_op == O_symbol
10148 && inst.reloc.exp.X_add_symbol != NULL
10149 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10150 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10151 inst.reloc.exp.X_add_symbol =
10152 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10153#endif
90e4755a
RE
10154}
10155
10156static void
c19d1205 10157do_t_bx (void)
90e4755a 10158{
e07e6e58 10159 set_it_insn_type_last ();
c19d1205
ZW
10160 inst.instruction |= inst.operands[0].reg << 3;
10161 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10162 should cause the alignment to be checked once it is known. This is
10163 because BX PC only works if the instruction is word aligned. */
10164}
90e4755a 10165
c19d1205
ZW
10166static void
10167do_t_bxj (void)
10168{
fdfde340 10169 int Rm;
90e4755a 10170
e07e6e58 10171 set_it_insn_type_last ();
fdfde340
JM
10172 Rm = inst.operands[0].reg;
10173 reject_bad_reg (Rm);
10174 inst.instruction |= Rm << 16;
90e4755a
RE
10175}
10176
10177static void
c19d1205 10178do_t_clz (void)
90e4755a 10179{
fdfde340
JM
10180 unsigned Rd;
10181 unsigned Rm;
10182
10183 Rd = inst.operands[0].reg;
10184 Rm = inst.operands[1].reg;
10185
10186 reject_bad_reg (Rd);
10187 reject_bad_reg (Rm);
10188
10189 inst.instruction |= Rd << 8;
10190 inst.instruction |= Rm << 16;
10191 inst.instruction |= Rm;
c19d1205 10192}
90e4755a 10193
dfa9f0d5
PB
10194static void
10195do_t_cps (void)
10196{
e07e6e58 10197 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10198 inst.instruction |= inst.operands[0].imm;
10199}
10200
c19d1205
ZW
10201static void
10202do_t_cpsi (void)
10203{
e07e6e58 10204 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10205 if (unified_syntax
62b3e311
PB
10206 && (inst.operands[1].present || inst.size_req == 4)
10207 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10208 {
c19d1205
ZW
10209 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10210 inst.instruction = 0xf3af8000;
10211 inst.instruction |= imod << 9;
10212 inst.instruction |= inst.operands[0].imm << 5;
10213 if (inst.operands[1].present)
10214 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10215 }
c19d1205 10216 else
90e4755a 10217 {
62b3e311
PB
10218 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10219 && (inst.operands[0].imm & 4),
10220 _("selected processor does not support 'A' form "
10221 "of this instruction"));
10222 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10223 _("Thumb does not support the 2-argument "
10224 "form of this instruction"));
10225 inst.instruction |= inst.operands[0].imm;
90e4755a 10226 }
90e4755a
RE
10227}
10228
c19d1205
ZW
10229/* THUMB CPY instruction (argument parse). */
10230
90e4755a 10231static void
c19d1205 10232do_t_cpy (void)
90e4755a 10233{
c19d1205 10234 if (inst.size_req == 4)
90e4755a 10235 {
c19d1205
ZW
10236 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10237 inst.instruction |= inst.operands[0].reg << 8;
10238 inst.instruction |= inst.operands[1].reg;
90e4755a 10239 }
c19d1205 10240 else
90e4755a 10241 {
c19d1205
ZW
10242 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10243 inst.instruction |= (inst.operands[0].reg & 0x7);
10244 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10245 }
90e4755a
RE
10246}
10247
90e4755a 10248static void
25fe350b 10249do_t_cbz (void)
90e4755a 10250{
e07e6e58 10251 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10252 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10253 inst.instruction |= inst.operands[0].reg;
10254 inst.reloc.pc_rel = 1;
10255 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10256}
90e4755a 10257
62b3e311
PB
10258static void
10259do_t_dbg (void)
10260{
10261 inst.instruction |= inst.operands[0].imm;
10262}
10263
10264static void
10265do_t_div (void)
10266{
fdfde340
JM
10267 unsigned Rd, Rn, Rm;
10268
10269 Rd = inst.operands[0].reg;
10270 Rn = (inst.operands[1].present
10271 ? inst.operands[1].reg : Rd);
10272 Rm = inst.operands[2].reg;
10273
10274 reject_bad_reg (Rd);
10275 reject_bad_reg (Rn);
10276 reject_bad_reg (Rm);
10277
10278 inst.instruction |= Rd << 8;
10279 inst.instruction |= Rn << 16;
10280 inst.instruction |= Rm;
62b3e311
PB
10281}
10282
c19d1205
ZW
10283static void
10284do_t_hint (void)
10285{
10286 if (unified_syntax && inst.size_req == 4)
10287 inst.instruction = THUMB_OP32 (inst.instruction);
10288 else
10289 inst.instruction = THUMB_OP16 (inst.instruction);
10290}
90e4755a 10291
c19d1205
ZW
10292static void
10293do_t_it (void)
10294{
10295 unsigned int cond = inst.operands[0].imm;
e27ec89e 10296
e07e6e58
NC
10297 set_it_insn_type (IT_INSN);
10298 now_it.mask = (inst.instruction & 0xf) | 0x10;
10299 now_it.cc = cond;
e27ec89e
PB
10300
10301 /* If the condition is a negative condition, invert the mask. */
c19d1205 10302 if ((cond & 0x1) == 0x0)
90e4755a 10303 {
c19d1205 10304 unsigned int mask = inst.instruction & 0x000f;
90e4755a 10305
c19d1205
ZW
10306 if ((mask & 0x7) == 0)
10307 /* no conversion needed */;
10308 else if ((mask & 0x3) == 0)
e27ec89e
PB
10309 mask ^= 0x8;
10310 else if ((mask & 0x1) == 0)
10311 mask ^= 0xC;
c19d1205 10312 else
e27ec89e 10313 mask ^= 0xE;
90e4755a 10314
e27ec89e
PB
10315 inst.instruction &= 0xfff0;
10316 inst.instruction |= mask;
c19d1205 10317 }
90e4755a 10318
c19d1205
ZW
10319 inst.instruction |= cond << 4;
10320}
90e4755a 10321
3c707909
PB
10322/* Helper function used for both push/pop and ldm/stm. */
10323static void
10324encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10325{
10326 bfd_boolean load;
10327
10328 load = (inst.instruction & (1 << 20)) != 0;
10329
10330 if (mask & (1 << 13))
10331 inst.error = _("SP not allowed in register list");
1e5b0379
NC
10332
10333 if ((mask & (1 << base)) != 0
10334 && writeback)
10335 inst.error = _("having the base register in the register list when "
10336 "using write back is UNPREDICTABLE");
10337
3c707909
PB
10338 if (load)
10339 {
e07e6e58
NC
10340 if (mask & (1 << 15))
10341 {
10342 if (mask & (1 << 14))
10343 inst.error = _("LR and PC should not both be in register list");
10344 else
10345 set_it_insn_type_last ();
10346 }
3c707909
PB
10347 }
10348 else
10349 {
10350 if (mask & (1 << 15))
10351 inst.error = _("PC not allowed in register list");
3c707909
PB
10352 }
10353
10354 if ((mask & (mask - 1)) == 0)
10355 {
10356 /* Single register transfers implemented as str/ldr. */
10357 if (writeback)
10358 {
10359 if (inst.instruction & (1 << 23))
10360 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10361 else
10362 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10363 }
10364 else
10365 {
10366 if (inst.instruction & (1 << 23))
10367 inst.instruction = 0x00800000; /* ia -> [base] */
10368 else
10369 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10370 }
10371
10372 inst.instruction |= 0xf8400000;
10373 if (load)
10374 inst.instruction |= 0x00100000;
10375
5f4273c7 10376 mask = ffs (mask) - 1;
3c707909
PB
10377 mask <<= 12;
10378 }
10379 else if (writeback)
10380 inst.instruction |= WRITE_BACK;
10381
10382 inst.instruction |= mask;
10383 inst.instruction |= base << 16;
10384}
10385
c19d1205
ZW
10386static void
10387do_t_ldmstm (void)
10388{
10389 /* This really doesn't seem worth it. */
10390 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10391 _("expression too complex"));
10392 constraint (inst.operands[1].writeback,
10393 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 10394
c19d1205
ZW
10395 if (unified_syntax)
10396 {
3c707909
PB
10397 bfd_boolean narrow;
10398 unsigned mask;
10399
10400 narrow = FALSE;
c19d1205
ZW
10401 /* See if we can use a 16-bit instruction. */
10402 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10403 && inst.size_req != 4
3c707909 10404 && !(inst.operands[1].imm & ~0xff))
90e4755a 10405 {
3c707909 10406 mask = 1 << inst.operands[0].reg;
90e4755a 10407
eab4f823 10408 if (inst.operands[0].reg <= 7)
90e4755a 10409 {
3c707909 10410 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
10411 ? inst.operands[0].writeback
10412 : (inst.operands[0].writeback
10413 == !(inst.operands[1].imm & mask)))
10414 {
10415 if (inst.instruction == T_MNEM_stmia
10416 && (inst.operands[1].imm & mask)
10417 && (inst.operands[1].imm & (mask - 1)))
10418 as_warn (_("value stored for r%d is UNKNOWN"),
10419 inst.operands[0].reg);
3c707909 10420
eab4f823
MGD
10421 inst.instruction = THUMB_OP16 (inst.instruction);
10422 inst.instruction |= inst.operands[0].reg << 8;
10423 inst.instruction |= inst.operands[1].imm;
10424 narrow = TRUE;
10425 }
10426 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10427 {
10428 /* This means 1 register in reg list one of 3 situations:
10429 1. Instruction is stmia, but without writeback.
10430 2. lmdia without writeback, but with Rn not in
10431 reglist.
10432 3. ldmia with writeback, but with Rn in reglist.
10433 Case 3 is UNPREDICTABLE behaviour, so we handle
10434 case 1 and 2 which can be converted into a 16-bit
10435 str or ldr. The SP cases are handled below. */
10436 unsigned long opcode;
10437 /* First, record an error for Case 3. */
10438 if (inst.operands[1].imm & mask
10439 && inst.operands[0].writeback)
fa94de6b 10440 inst.error =
eab4f823
MGD
10441 _("having the base register in the register list when "
10442 "using write back is UNPREDICTABLE");
fa94de6b
RM
10443
10444 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
10445 : T_MNEM_ldr);
10446 inst.instruction = THUMB_OP16 (opcode);
10447 inst.instruction |= inst.operands[0].reg << 3;
10448 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10449 narrow = TRUE;
10450 }
90e4755a 10451 }
eab4f823 10452 else if (inst.operands[0] .reg == REG_SP)
90e4755a 10453 {
eab4f823
MGD
10454 if (inst.operands[0].writeback)
10455 {
fa94de6b 10456 inst.instruction =
eab4f823
MGD
10457 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10458 ? T_MNEM_push : T_MNEM_pop);
10459 inst.instruction |= inst.operands[1].imm;
10460 narrow = TRUE;
10461 }
10462 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10463 {
fa94de6b 10464 inst.instruction =
eab4f823
MGD
10465 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10466 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10467 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10468 narrow = TRUE;
10469 }
90e4755a 10470 }
3c707909
PB
10471 }
10472
10473 if (!narrow)
10474 {
c19d1205
ZW
10475 if (inst.instruction < 0xffff)
10476 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 10477
5f4273c7
NC
10478 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10479 inst.operands[0].writeback);
90e4755a
RE
10480 }
10481 }
c19d1205 10482 else
90e4755a 10483 {
c19d1205
ZW
10484 constraint (inst.operands[0].reg > 7
10485 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
10486 constraint (inst.instruction != T_MNEM_ldmia
10487 && inst.instruction != T_MNEM_stmia,
10488 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 10489 if (inst.instruction == T_MNEM_stmia)
f03698e6 10490 {
c19d1205
ZW
10491 if (!inst.operands[0].writeback)
10492 as_warn (_("this instruction will write back the base register"));
10493 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10494 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 10495 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 10496 inst.operands[0].reg);
f03698e6 10497 }
c19d1205 10498 else
90e4755a 10499 {
c19d1205
ZW
10500 if (!inst.operands[0].writeback
10501 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10502 as_warn (_("this instruction will write back the base register"));
10503 else if (inst.operands[0].writeback
10504 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10505 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
10506 }
10507
c19d1205
ZW
10508 inst.instruction = THUMB_OP16 (inst.instruction);
10509 inst.instruction |= inst.operands[0].reg << 8;
10510 inst.instruction |= inst.operands[1].imm;
10511 }
10512}
e28cd48c 10513
c19d1205
ZW
10514static void
10515do_t_ldrex (void)
10516{
10517 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10518 || inst.operands[1].postind || inst.operands[1].writeback
10519 || inst.operands[1].immisreg || inst.operands[1].shifted
10520 || inst.operands[1].negative,
01cfc07f 10521 BAD_ADDR_MODE);
e28cd48c 10522
5be8be5d
DG
10523 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10524
c19d1205
ZW
10525 inst.instruction |= inst.operands[0].reg << 12;
10526 inst.instruction |= inst.operands[1].reg << 16;
10527 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10528}
e28cd48c 10529
c19d1205
ZW
10530static void
10531do_t_ldrexd (void)
10532{
10533 if (!inst.operands[1].present)
1cac9012 10534 {
c19d1205
ZW
10535 constraint (inst.operands[0].reg == REG_LR,
10536 _("r14 not allowed as first register "
10537 "when second register is omitted"));
10538 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 10539 }
c19d1205
ZW
10540 constraint (inst.operands[0].reg == inst.operands[1].reg,
10541 BAD_OVERLAP);
b99bd4ef 10542
c19d1205
ZW
10543 inst.instruction |= inst.operands[0].reg << 12;
10544 inst.instruction |= inst.operands[1].reg << 8;
10545 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10546}
10547
10548static void
c19d1205 10549do_t_ldst (void)
b99bd4ef 10550{
0110f2b8
PB
10551 unsigned long opcode;
10552 int Rn;
10553
e07e6e58
NC
10554 if (inst.operands[0].isreg
10555 && !inst.operands[0].preind
10556 && inst.operands[0].reg == REG_PC)
10557 set_it_insn_type_last ();
10558
0110f2b8 10559 opcode = inst.instruction;
c19d1205 10560 if (unified_syntax)
b99bd4ef 10561 {
53365c0d
PB
10562 if (!inst.operands[1].isreg)
10563 {
10564 if (opcode <= 0xffff)
10565 inst.instruction = THUMB_OP32 (opcode);
10566 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10567 return;
10568 }
0110f2b8
PB
10569 if (inst.operands[1].isreg
10570 && !inst.operands[1].writeback
c19d1205
ZW
10571 && !inst.operands[1].shifted && !inst.operands[1].postind
10572 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
10573 && opcode <= 0xffff
10574 && inst.size_req != 4)
c19d1205 10575 {
0110f2b8
PB
10576 /* Insn may have a 16-bit form. */
10577 Rn = inst.operands[1].reg;
10578 if (inst.operands[1].immisreg)
10579 {
10580 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 10581 /* [Rn, Rik] */
0110f2b8
PB
10582 if (Rn <= 7 && inst.operands[1].imm <= 7)
10583 goto op16;
5be8be5d
DG
10584 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10585 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
10586 }
10587 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10588 && opcode != T_MNEM_ldrsb)
10589 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10590 || (Rn == REG_SP && opcode == T_MNEM_str))
10591 {
10592 /* [Rn, #const] */
10593 if (Rn > 7)
10594 {
10595 if (Rn == REG_PC)
10596 {
10597 if (inst.reloc.pc_rel)
10598 opcode = T_MNEM_ldr_pc2;
10599 else
10600 opcode = T_MNEM_ldr_pc;
10601 }
10602 else
10603 {
10604 if (opcode == T_MNEM_ldr)
10605 opcode = T_MNEM_ldr_sp;
10606 else
10607 opcode = T_MNEM_str_sp;
10608 }
10609 inst.instruction = inst.operands[0].reg << 8;
10610 }
10611 else
10612 {
10613 inst.instruction = inst.operands[0].reg;
10614 inst.instruction |= inst.operands[1].reg << 3;
10615 }
10616 inst.instruction |= THUMB_OP16 (opcode);
10617 if (inst.size_req == 2)
10618 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10619 else
10620 inst.relax = opcode;
10621 return;
10622 }
c19d1205 10623 }
0110f2b8 10624 /* Definitely a 32-bit variant. */
5be8be5d 10625
8d67f500
NC
10626 /* Warning for Erratum 752419. */
10627 if (opcode == T_MNEM_ldr
10628 && inst.operands[0].reg == REG_SP
10629 && inst.operands[1].writeback == 1
10630 && !inst.operands[1].immisreg)
10631 {
10632 if (no_cpu_selected ()
10633 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10634 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10635 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10636 as_warn (_("This instruction may be unpredictable "
10637 "if executed on M-profile cores "
10638 "with interrupts enabled."));
10639 }
10640
5be8be5d 10641 /* Do some validations regarding addressing modes. */
1be5fd2e 10642 if (inst.operands[1].immisreg)
5be8be5d
DG
10643 reject_bad_reg (inst.operands[1].imm);
10644
1be5fd2e
NC
10645 constraint (inst.operands[1].writeback == 1
10646 && inst.operands[0].reg == inst.operands[1].reg,
10647 BAD_OVERLAP);
10648
0110f2b8 10649 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10650 inst.instruction |= inst.operands[0].reg << 12;
10651 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 10652 check_ldr_r15_aligned ();
b99bd4ef
NC
10653 return;
10654 }
10655
c19d1205
ZW
10656 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10657
10658 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10659 {
c19d1205
ZW
10660 /* Only [Rn,Rm] is acceptable. */
10661 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10662 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10663 || inst.operands[1].postind || inst.operands[1].shifted
10664 || inst.operands[1].negative,
10665 _("Thumb does not support this addressing mode"));
10666 inst.instruction = THUMB_OP16 (inst.instruction);
10667 goto op16;
b99bd4ef 10668 }
5f4273c7 10669
c19d1205
ZW
10670 inst.instruction = THUMB_OP16 (inst.instruction);
10671 if (!inst.operands[1].isreg)
10672 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10673 return;
b99bd4ef 10674
c19d1205
ZW
10675 constraint (!inst.operands[1].preind
10676 || inst.operands[1].shifted
10677 || inst.operands[1].writeback,
10678 _("Thumb does not support this addressing mode"));
10679 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10680 {
c19d1205
ZW
10681 constraint (inst.instruction & 0x0600,
10682 _("byte or halfword not valid for base register"));
10683 constraint (inst.operands[1].reg == REG_PC
10684 && !(inst.instruction & THUMB_LOAD_BIT),
10685 _("r15 based store not allowed"));
10686 constraint (inst.operands[1].immisreg,
10687 _("invalid base register for register offset"));
b99bd4ef 10688
c19d1205
ZW
10689 if (inst.operands[1].reg == REG_PC)
10690 inst.instruction = T_OPCODE_LDR_PC;
10691 else if (inst.instruction & THUMB_LOAD_BIT)
10692 inst.instruction = T_OPCODE_LDR_SP;
10693 else
10694 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10695
c19d1205
ZW
10696 inst.instruction |= inst.operands[0].reg << 8;
10697 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10698 return;
10699 }
90e4755a 10700
c19d1205
ZW
10701 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10702 if (!inst.operands[1].immisreg)
10703 {
10704 /* Immediate offset. */
10705 inst.instruction |= inst.operands[0].reg;
10706 inst.instruction |= inst.operands[1].reg << 3;
10707 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10708 return;
10709 }
90e4755a 10710
c19d1205
ZW
10711 /* Register offset. */
10712 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10713 constraint (inst.operands[1].negative,
10714 _("Thumb does not support this addressing mode"));
90e4755a 10715
c19d1205
ZW
10716 op16:
10717 switch (inst.instruction)
10718 {
10719 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10720 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10721 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10722 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10723 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10724 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10725 case 0x5600 /* ldrsb */:
10726 case 0x5e00 /* ldrsh */: break;
10727 default: abort ();
10728 }
90e4755a 10729
c19d1205
ZW
10730 inst.instruction |= inst.operands[0].reg;
10731 inst.instruction |= inst.operands[1].reg << 3;
10732 inst.instruction |= inst.operands[1].imm << 6;
10733}
90e4755a 10734
c19d1205
ZW
10735static void
10736do_t_ldstd (void)
10737{
10738 if (!inst.operands[1].present)
b99bd4ef 10739 {
c19d1205
ZW
10740 inst.operands[1].reg = inst.operands[0].reg + 1;
10741 constraint (inst.operands[0].reg == REG_LR,
10742 _("r14 not allowed here"));
bd340a04
MGD
10743 constraint (inst.operands[0].reg == REG_R12,
10744 _("r12 not allowed here"));
b99bd4ef 10745 }
bd340a04
MGD
10746
10747 if (inst.operands[2].writeback
10748 && (inst.operands[0].reg == inst.operands[2].reg
10749 || inst.operands[1].reg == inst.operands[2].reg))
10750 as_warn (_("base register written back, and overlaps "
10751 "one of transfer registers"));
10752
c19d1205
ZW
10753 inst.instruction |= inst.operands[0].reg << 12;
10754 inst.instruction |= inst.operands[1].reg << 8;
10755 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10756}
10757
c19d1205
ZW
10758static void
10759do_t_ldstt (void)
10760{
10761 inst.instruction |= inst.operands[0].reg << 12;
10762 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10763}
a737bd4d 10764
b99bd4ef 10765static void
c19d1205 10766do_t_mla (void)
b99bd4ef 10767{
fdfde340 10768 unsigned Rd, Rn, Rm, Ra;
c921be7d 10769
fdfde340
JM
10770 Rd = inst.operands[0].reg;
10771 Rn = inst.operands[1].reg;
10772 Rm = inst.operands[2].reg;
10773 Ra = inst.operands[3].reg;
10774
10775 reject_bad_reg (Rd);
10776 reject_bad_reg (Rn);
10777 reject_bad_reg (Rm);
10778 reject_bad_reg (Ra);
10779
10780 inst.instruction |= Rd << 8;
10781 inst.instruction |= Rn << 16;
10782 inst.instruction |= Rm;
10783 inst.instruction |= Ra << 12;
c19d1205 10784}
b99bd4ef 10785
c19d1205
ZW
10786static void
10787do_t_mlal (void)
10788{
fdfde340
JM
10789 unsigned RdLo, RdHi, Rn, Rm;
10790
10791 RdLo = inst.operands[0].reg;
10792 RdHi = inst.operands[1].reg;
10793 Rn = inst.operands[2].reg;
10794 Rm = inst.operands[3].reg;
10795
10796 reject_bad_reg (RdLo);
10797 reject_bad_reg (RdHi);
10798 reject_bad_reg (Rn);
10799 reject_bad_reg (Rm);
10800
10801 inst.instruction |= RdLo << 12;
10802 inst.instruction |= RdHi << 8;
10803 inst.instruction |= Rn << 16;
10804 inst.instruction |= Rm;
c19d1205 10805}
b99bd4ef 10806
c19d1205
ZW
10807static void
10808do_t_mov_cmp (void)
10809{
fdfde340
JM
10810 unsigned Rn, Rm;
10811
10812 Rn = inst.operands[0].reg;
10813 Rm = inst.operands[1].reg;
10814
e07e6e58
NC
10815 if (Rn == REG_PC)
10816 set_it_insn_type_last ();
10817
c19d1205 10818 if (unified_syntax)
b99bd4ef 10819 {
c19d1205
ZW
10820 int r0off = (inst.instruction == T_MNEM_mov
10821 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10822 unsigned long opcode;
3d388997
PB
10823 bfd_boolean narrow;
10824 bfd_boolean low_regs;
10825
fdfde340 10826 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10827 opcode = inst.instruction;
e07e6e58 10828 if (in_it_block ())
0110f2b8 10829 narrow = opcode != T_MNEM_movs;
3d388997 10830 else
0110f2b8 10831 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10832 if (inst.size_req == 4
10833 || inst.operands[1].shifted)
10834 narrow = FALSE;
10835
efd81785
PB
10836 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10837 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10838 && !inst.operands[1].shifted
fdfde340
JM
10839 && Rn == REG_PC
10840 && Rm == REG_LR)
efd81785
PB
10841 {
10842 inst.instruction = T2_SUBS_PC_LR;
10843 return;
10844 }
10845
fdfde340
JM
10846 if (opcode == T_MNEM_cmp)
10847 {
10848 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10849 if (narrow)
10850 {
10851 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10852 but valid. */
10853 warn_deprecated_sp (Rm);
10854 /* R15 was documented as a valid choice for Rm in ARMv6,
10855 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10856 tools reject R15, so we do too. */
10857 constraint (Rm == REG_PC, BAD_PC);
10858 }
10859 else
10860 reject_bad_reg (Rm);
fdfde340
JM
10861 }
10862 else if (opcode == T_MNEM_mov
10863 || opcode == T_MNEM_movs)
10864 {
10865 if (inst.operands[1].isreg)
10866 {
10867 if (opcode == T_MNEM_movs)
10868 {
10869 reject_bad_reg (Rn);
10870 reject_bad_reg (Rm);
10871 }
76fa04a4
MGD
10872 else if (narrow)
10873 {
10874 /* This is mov.n. */
10875 if ((Rn == REG_SP || Rn == REG_PC)
10876 && (Rm == REG_SP || Rm == REG_PC))
10877 {
10878 as_warn (_("Use of r%u as a source register is "
10879 "deprecated when r%u is the destination "
10880 "register."), Rm, Rn);
10881 }
10882 }
10883 else
10884 {
10885 /* This is mov.w. */
10886 constraint (Rn == REG_PC, BAD_PC);
10887 constraint (Rm == REG_PC, BAD_PC);
10888 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10889 }
fdfde340
JM
10890 }
10891 else
10892 reject_bad_reg (Rn);
10893 }
10894
c19d1205
ZW
10895 if (!inst.operands[1].isreg)
10896 {
0110f2b8 10897 /* Immediate operand. */
e07e6e58 10898 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10899 narrow = 0;
10900 if (low_regs && narrow)
10901 {
10902 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10903 inst.instruction |= Rn << 8;
0110f2b8
PB
10904 if (inst.size_req == 2)
10905 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10906 else
10907 inst.relax = opcode;
10908 }
10909 else
10910 {
10911 inst.instruction = THUMB_OP32 (inst.instruction);
10912 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10913 inst.instruction |= Rn << r0off;
0110f2b8
PB
10914 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10915 }
c19d1205 10916 }
728ca7c9
PB
10917 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10918 && (inst.instruction == T_MNEM_mov
10919 || inst.instruction == T_MNEM_movs))
10920 {
10921 /* Register shifts are encoded as separate shift instructions. */
10922 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10923
e07e6e58 10924 if (in_it_block ())
728ca7c9
PB
10925 narrow = !flags;
10926 else
10927 narrow = flags;
10928
10929 if (inst.size_req == 4)
10930 narrow = FALSE;
10931
10932 if (!low_regs || inst.operands[1].imm > 7)
10933 narrow = FALSE;
10934
fdfde340 10935 if (Rn != Rm)
728ca7c9
PB
10936 narrow = FALSE;
10937
10938 switch (inst.operands[1].shift_kind)
10939 {
10940 case SHIFT_LSL:
10941 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10942 break;
10943 case SHIFT_ASR:
10944 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10945 break;
10946 case SHIFT_LSR:
10947 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10948 break;
10949 case SHIFT_ROR:
10950 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10951 break;
10952 default:
5f4273c7 10953 abort ();
728ca7c9
PB
10954 }
10955
10956 inst.instruction = opcode;
10957 if (narrow)
10958 {
fdfde340 10959 inst.instruction |= Rn;
728ca7c9
PB
10960 inst.instruction |= inst.operands[1].imm << 3;
10961 }
10962 else
10963 {
10964 if (flags)
10965 inst.instruction |= CONDS_BIT;
10966
fdfde340
JM
10967 inst.instruction |= Rn << 8;
10968 inst.instruction |= Rm << 16;
728ca7c9
PB
10969 inst.instruction |= inst.operands[1].imm;
10970 }
10971 }
3d388997 10972 else if (!narrow)
c19d1205 10973 {
728ca7c9
PB
10974 /* Some mov with immediate shift have narrow variants.
10975 Register shifts are handled above. */
10976 if (low_regs && inst.operands[1].shifted
10977 && (inst.instruction == T_MNEM_mov
10978 || inst.instruction == T_MNEM_movs))
10979 {
e07e6e58 10980 if (in_it_block ())
728ca7c9
PB
10981 narrow = (inst.instruction == T_MNEM_mov);
10982 else
10983 narrow = (inst.instruction == T_MNEM_movs);
10984 }
10985
10986 if (narrow)
10987 {
10988 switch (inst.operands[1].shift_kind)
10989 {
10990 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10991 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10992 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10993 default: narrow = FALSE; break;
10994 }
10995 }
10996
10997 if (narrow)
10998 {
fdfde340
JM
10999 inst.instruction |= Rn;
11000 inst.instruction |= Rm << 3;
728ca7c9
PB
11001 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11002 }
11003 else
11004 {
11005 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11006 inst.instruction |= Rn << r0off;
728ca7c9
PB
11007 encode_thumb32_shifted_operand (1);
11008 }
c19d1205
ZW
11009 }
11010 else
11011 switch (inst.instruction)
11012 {
11013 case T_MNEM_mov:
837b3435 11014 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11015 results. Don't allow this. */
11016 if (low_regs)
11017 {
11018 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11019 "MOV Rd, Rs with two low registers is not "
11020 "permitted on this architecture");
fa94de6b 11021 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11022 arm_ext_v6);
11023 }
11024
c19d1205 11025 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11026 inst.instruction |= (Rn & 0x8) << 4;
11027 inst.instruction |= (Rn & 0x7);
11028 inst.instruction |= Rm << 3;
c19d1205 11029 break;
b99bd4ef 11030
c19d1205
ZW
11031 case T_MNEM_movs:
11032 /* We know we have low registers at this point.
941a8a52
MGD
11033 Generate LSLS Rd, Rs, #0. */
11034 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11035 inst.instruction |= Rn;
11036 inst.instruction |= Rm << 3;
c19d1205
ZW
11037 break;
11038
11039 case T_MNEM_cmp:
3d388997 11040 if (low_regs)
c19d1205
ZW
11041 {
11042 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11043 inst.instruction |= Rn;
11044 inst.instruction |= Rm << 3;
c19d1205
ZW
11045 }
11046 else
11047 {
11048 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11049 inst.instruction |= (Rn & 0x8) << 4;
11050 inst.instruction |= (Rn & 0x7);
11051 inst.instruction |= Rm << 3;
c19d1205
ZW
11052 }
11053 break;
11054 }
b99bd4ef
NC
11055 return;
11056 }
11057
c19d1205 11058 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11059
11060 /* PR 10443: Do not silently ignore shifted operands. */
11061 constraint (inst.operands[1].shifted,
11062 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11063
c19d1205 11064 if (inst.operands[1].isreg)
b99bd4ef 11065 {
fdfde340 11066 if (Rn < 8 && Rm < 8)
b99bd4ef 11067 {
c19d1205
ZW
11068 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11069 since a MOV instruction produces unpredictable results. */
11070 if (inst.instruction == T_OPCODE_MOV_I8)
11071 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11072 else
c19d1205 11073 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11074
fdfde340
JM
11075 inst.instruction |= Rn;
11076 inst.instruction |= Rm << 3;
b99bd4ef
NC
11077 }
11078 else
11079 {
c19d1205
ZW
11080 if (inst.instruction == T_OPCODE_MOV_I8)
11081 inst.instruction = T_OPCODE_MOV_HR;
11082 else
11083 inst.instruction = T_OPCODE_CMP_HR;
11084 do_t_cpy ();
b99bd4ef
NC
11085 }
11086 }
c19d1205 11087 else
b99bd4ef 11088 {
fdfde340 11089 constraint (Rn > 7,
c19d1205 11090 _("only lo regs allowed with immediate"));
fdfde340 11091 inst.instruction |= Rn << 8;
c19d1205
ZW
11092 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11093 }
11094}
b99bd4ef 11095
c19d1205
ZW
11096static void
11097do_t_mov16 (void)
11098{
fdfde340 11099 unsigned Rd;
b6895b4f
PB
11100 bfd_vma imm;
11101 bfd_boolean top;
11102
11103 top = (inst.instruction & 0x00800000) != 0;
11104 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11105 {
11106 constraint (top, _(":lower16: not allowed this instruction"));
11107 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11108 }
11109 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11110 {
11111 constraint (!top, _(":upper16: not allowed this instruction"));
11112 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11113 }
11114
fdfde340
JM
11115 Rd = inst.operands[0].reg;
11116 reject_bad_reg (Rd);
11117
11118 inst.instruction |= Rd << 8;
b6895b4f
PB
11119 if (inst.reloc.type == BFD_RELOC_UNUSED)
11120 {
11121 imm = inst.reloc.exp.X_add_number;
11122 inst.instruction |= (imm & 0xf000) << 4;
11123 inst.instruction |= (imm & 0x0800) << 15;
11124 inst.instruction |= (imm & 0x0700) << 4;
11125 inst.instruction |= (imm & 0x00ff);
11126 }
c19d1205 11127}
b99bd4ef 11128
c19d1205
ZW
11129static void
11130do_t_mvn_tst (void)
11131{
fdfde340 11132 unsigned Rn, Rm;
c921be7d 11133
fdfde340
JM
11134 Rn = inst.operands[0].reg;
11135 Rm = inst.operands[1].reg;
11136
11137 if (inst.instruction == T_MNEM_cmp
11138 || inst.instruction == T_MNEM_cmn)
11139 constraint (Rn == REG_PC, BAD_PC);
11140 else
11141 reject_bad_reg (Rn);
11142 reject_bad_reg (Rm);
11143
c19d1205
ZW
11144 if (unified_syntax)
11145 {
11146 int r0off = (inst.instruction == T_MNEM_mvn
11147 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11148 bfd_boolean narrow;
11149
11150 if (inst.size_req == 4
11151 || inst.instruction > 0xffff
11152 || inst.operands[1].shifted
fdfde340 11153 || Rn > 7 || Rm > 7)
3d388997
PB
11154 narrow = FALSE;
11155 else if (inst.instruction == T_MNEM_cmn)
11156 narrow = TRUE;
11157 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11158 narrow = !in_it_block ();
3d388997 11159 else
e07e6e58 11160 narrow = in_it_block ();
3d388997 11161
c19d1205 11162 if (!inst.operands[1].isreg)
b99bd4ef 11163 {
c19d1205
ZW
11164 /* For an immediate, we always generate a 32-bit opcode;
11165 section relaxation will shrink it later if possible. */
11166 if (inst.instruction < 0xffff)
11167 inst.instruction = THUMB_OP32 (inst.instruction);
11168 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11169 inst.instruction |= Rn << r0off;
c19d1205 11170 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11171 }
c19d1205 11172 else
b99bd4ef 11173 {
c19d1205 11174 /* See if we can do this with a 16-bit instruction. */
3d388997 11175 if (narrow)
b99bd4ef 11176 {
c19d1205 11177 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11178 inst.instruction |= Rn;
11179 inst.instruction |= Rm << 3;
b99bd4ef 11180 }
c19d1205 11181 else
b99bd4ef 11182 {
c19d1205
ZW
11183 constraint (inst.operands[1].shifted
11184 && inst.operands[1].immisreg,
11185 _("shift must be constant"));
11186 if (inst.instruction < 0xffff)
11187 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11188 inst.instruction |= Rn << r0off;
c19d1205 11189 encode_thumb32_shifted_operand (1);
b99bd4ef 11190 }
b99bd4ef
NC
11191 }
11192 }
11193 else
11194 {
c19d1205
ZW
11195 constraint (inst.instruction > 0xffff
11196 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11197 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11198 _("unshifted register required"));
fdfde340 11199 constraint (Rn > 7 || Rm > 7,
c19d1205 11200 BAD_HIREG);
b99bd4ef 11201
c19d1205 11202 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11203 inst.instruction |= Rn;
11204 inst.instruction |= Rm << 3;
b99bd4ef 11205 }
b99bd4ef
NC
11206}
11207
b05fe5cf 11208static void
c19d1205 11209do_t_mrs (void)
b05fe5cf 11210{
fdfde340 11211 unsigned Rd;
037e8744
JB
11212
11213 if (do_vfp_nsyn_mrs () == SUCCESS)
11214 return;
11215
90ec0d68
MGD
11216 Rd = inst.operands[0].reg;
11217 reject_bad_reg (Rd);
11218 inst.instruction |= Rd << 8;
11219
11220 if (inst.operands[1].isreg)
62b3e311 11221 {
90ec0d68
MGD
11222 unsigned br = inst.operands[1].reg;
11223 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11224 as_bad (_("bad register for mrs"));
11225
11226 inst.instruction |= br & (0xf << 16);
11227 inst.instruction |= (br & 0x300) >> 4;
11228 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11229 }
11230 else
11231 {
90ec0d68 11232 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11233
d2cd1205 11234 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
11235 {
11236 /* PR gas/12698: The constraint is only applied for m_profile.
11237 If the user has specified -march=all, we want to ignore it as
11238 we are building for any CPU type, including non-m variants. */
11239 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11240 constraint ((flags != 0) && m_profile, _("selected processor does "
11241 "not support requested special purpose register"));
11242 }
90ec0d68 11243 else
d2cd1205
JB
11244 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11245 devices). */
11246 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11247 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11248
90ec0d68
MGD
11249 inst.instruction |= (flags & SPSR_BIT) >> 2;
11250 inst.instruction |= inst.operands[1].imm & 0xff;
11251 inst.instruction |= 0xf0000;
11252 }
c19d1205 11253}
b05fe5cf 11254
c19d1205
ZW
11255static void
11256do_t_msr (void)
11257{
62b3e311 11258 int flags;
fdfde340 11259 unsigned Rn;
62b3e311 11260
037e8744
JB
11261 if (do_vfp_nsyn_msr () == SUCCESS)
11262 return;
11263
c19d1205
ZW
11264 constraint (!inst.operands[1].isreg,
11265 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11266
11267 if (inst.operands[0].isreg)
11268 flags = (int)(inst.operands[0].reg);
11269 else
11270 flags = inst.operands[0].imm;
11271
d2cd1205 11272 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11273 {
d2cd1205
JB
11274 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11275
1a43faaf
NC
11276 /* PR gas/12698: The constraint is only applied for m_profile.
11277 If the user has specified -march=all, we want to ignore it as
11278 we are building for any CPU type, including non-m variants. */
11279 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11280 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11281 && (bits & ~(PSR_s | PSR_f)) != 0)
11282 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11283 && bits != PSR_f)) && m_profile,
11284 _("selected processor does not support requested special "
11285 "purpose register"));
62b3e311
PB
11286 }
11287 else
d2cd1205
JB
11288 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11289 "requested special purpose register"));
c921be7d 11290
fdfde340
JM
11291 Rn = inst.operands[1].reg;
11292 reject_bad_reg (Rn);
11293
62b3e311 11294 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
11295 inst.instruction |= (flags & 0xf0000) >> 8;
11296 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 11297 inst.instruction |= (flags & 0xff);
fdfde340 11298 inst.instruction |= Rn << 16;
c19d1205 11299}
b05fe5cf 11300
c19d1205
ZW
11301static void
11302do_t_mul (void)
11303{
17828f45 11304 bfd_boolean narrow;
fdfde340 11305 unsigned Rd, Rn, Rm;
17828f45 11306
c19d1205
ZW
11307 if (!inst.operands[2].present)
11308 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 11309
fdfde340
JM
11310 Rd = inst.operands[0].reg;
11311 Rn = inst.operands[1].reg;
11312 Rm = inst.operands[2].reg;
11313
17828f45 11314 if (unified_syntax)
b05fe5cf 11315 {
17828f45 11316 if (inst.size_req == 4
fdfde340
JM
11317 || (Rd != Rn
11318 && Rd != Rm)
11319 || Rn > 7
11320 || Rm > 7)
17828f45
JM
11321 narrow = FALSE;
11322 else if (inst.instruction == T_MNEM_muls)
e07e6e58 11323 narrow = !in_it_block ();
17828f45 11324 else
e07e6e58 11325 narrow = in_it_block ();
b05fe5cf 11326 }
c19d1205 11327 else
b05fe5cf 11328 {
17828f45 11329 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 11330 constraint (Rn > 7 || Rm > 7,
c19d1205 11331 BAD_HIREG);
17828f45
JM
11332 narrow = TRUE;
11333 }
b05fe5cf 11334
17828f45
JM
11335 if (narrow)
11336 {
11337 /* 16-bit MULS/Conditional MUL. */
c19d1205 11338 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 11339 inst.instruction |= Rd;
b05fe5cf 11340
fdfde340
JM
11341 if (Rd == Rn)
11342 inst.instruction |= Rm << 3;
11343 else if (Rd == Rm)
11344 inst.instruction |= Rn << 3;
c19d1205
ZW
11345 else
11346 constraint (1, _("dest must overlap one source register"));
11347 }
17828f45
JM
11348 else
11349 {
e07e6e58
NC
11350 constraint (inst.instruction != T_MNEM_mul,
11351 _("Thumb-2 MUL must not set flags"));
17828f45
JM
11352 /* 32-bit MUL. */
11353 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11354 inst.instruction |= Rd << 8;
11355 inst.instruction |= Rn << 16;
11356 inst.instruction |= Rm << 0;
11357
11358 reject_bad_reg (Rd);
11359 reject_bad_reg (Rn);
11360 reject_bad_reg (Rm);
17828f45 11361 }
c19d1205 11362}
b05fe5cf 11363
c19d1205
ZW
11364static void
11365do_t_mull (void)
11366{
fdfde340 11367 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 11368
fdfde340
JM
11369 RdLo = inst.operands[0].reg;
11370 RdHi = inst.operands[1].reg;
11371 Rn = inst.operands[2].reg;
11372 Rm = inst.operands[3].reg;
11373
11374 reject_bad_reg (RdLo);
11375 reject_bad_reg (RdHi);
11376 reject_bad_reg (Rn);
11377 reject_bad_reg (Rm);
11378
11379 inst.instruction |= RdLo << 12;
11380 inst.instruction |= RdHi << 8;
11381 inst.instruction |= Rn << 16;
11382 inst.instruction |= Rm;
11383
11384 if (RdLo == RdHi)
c19d1205
ZW
11385 as_tsktsk (_("rdhi and rdlo must be different"));
11386}
b05fe5cf 11387
c19d1205
ZW
11388static void
11389do_t_nop (void)
11390{
e07e6e58
NC
11391 set_it_insn_type (NEUTRAL_IT_INSN);
11392
c19d1205
ZW
11393 if (unified_syntax)
11394 {
11395 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 11396 {
c19d1205
ZW
11397 inst.instruction = THUMB_OP32 (inst.instruction);
11398 inst.instruction |= inst.operands[0].imm;
11399 }
11400 else
11401 {
bc2d1808
NC
11402 /* PR9722: Check for Thumb2 availability before
11403 generating a thumb2 nop instruction. */
afa62d5e 11404 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
11405 {
11406 inst.instruction = THUMB_OP16 (inst.instruction);
11407 inst.instruction |= inst.operands[0].imm << 4;
11408 }
11409 else
11410 inst.instruction = 0x46c0;
c19d1205
ZW
11411 }
11412 }
11413 else
11414 {
11415 constraint (inst.operands[0].present,
11416 _("Thumb does not support NOP with hints"));
11417 inst.instruction = 0x46c0;
11418 }
11419}
b05fe5cf 11420
c19d1205
ZW
11421static void
11422do_t_neg (void)
11423{
11424 if (unified_syntax)
11425 {
3d388997
PB
11426 bfd_boolean narrow;
11427
11428 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11429 narrow = !in_it_block ();
3d388997 11430 else
e07e6e58 11431 narrow = in_it_block ();
3d388997
PB
11432 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11433 narrow = FALSE;
11434 if (inst.size_req == 4)
11435 narrow = FALSE;
11436
11437 if (!narrow)
c19d1205
ZW
11438 {
11439 inst.instruction = THUMB_OP32 (inst.instruction);
11440 inst.instruction |= inst.operands[0].reg << 8;
11441 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
11442 }
11443 else
11444 {
c19d1205
ZW
11445 inst.instruction = THUMB_OP16 (inst.instruction);
11446 inst.instruction |= inst.operands[0].reg;
11447 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
11448 }
11449 }
11450 else
11451 {
c19d1205
ZW
11452 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11453 BAD_HIREG);
11454 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11455
11456 inst.instruction = THUMB_OP16 (inst.instruction);
11457 inst.instruction |= inst.operands[0].reg;
11458 inst.instruction |= inst.operands[1].reg << 3;
11459 }
11460}
11461
1c444d06
JM
11462static void
11463do_t_orn (void)
11464{
11465 unsigned Rd, Rn;
11466
11467 Rd = inst.operands[0].reg;
11468 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11469
fdfde340
JM
11470 reject_bad_reg (Rd);
11471 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11472 reject_bad_reg (Rn);
11473
1c444d06
JM
11474 inst.instruction |= Rd << 8;
11475 inst.instruction |= Rn << 16;
11476
11477 if (!inst.operands[2].isreg)
11478 {
11479 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11480 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11481 }
11482 else
11483 {
11484 unsigned Rm;
11485
11486 Rm = inst.operands[2].reg;
fdfde340 11487 reject_bad_reg (Rm);
1c444d06
JM
11488
11489 constraint (inst.operands[2].shifted
11490 && inst.operands[2].immisreg,
11491 _("shift must be constant"));
11492 encode_thumb32_shifted_operand (2);
11493 }
11494}
11495
c19d1205
ZW
11496static void
11497do_t_pkhbt (void)
11498{
fdfde340
JM
11499 unsigned Rd, Rn, Rm;
11500
11501 Rd = inst.operands[0].reg;
11502 Rn = inst.operands[1].reg;
11503 Rm = inst.operands[2].reg;
11504
11505 reject_bad_reg (Rd);
11506 reject_bad_reg (Rn);
11507 reject_bad_reg (Rm);
11508
11509 inst.instruction |= Rd << 8;
11510 inst.instruction |= Rn << 16;
11511 inst.instruction |= Rm;
c19d1205
ZW
11512 if (inst.operands[3].present)
11513 {
11514 unsigned int val = inst.reloc.exp.X_add_number;
11515 constraint (inst.reloc.exp.X_op != O_constant,
11516 _("expression too complex"));
11517 inst.instruction |= (val & 0x1c) << 10;
11518 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 11519 }
c19d1205 11520}
b05fe5cf 11521
c19d1205
ZW
11522static void
11523do_t_pkhtb (void)
11524{
11525 if (!inst.operands[3].present)
1ef52f49
NC
11526 {
11527 unsigned Rtmp;
11528
11529 inst.instruction &= ~0x00000020;
11530
11531 /* PR 10168. Swap the Rm and Rn registers. */
11532 Rtmp = inst.operands[1].reg;
11533 inst.operands[1].reg = inst.operands[2].reg;
11534 inst.operands[2].reg = Rtmp;
11535 }
c19d1205 11536 do_t_pkhbt ();
b05fe5cf
ZW
11537}
11538
c19d1205
ZW
11539static void
11540do_t_pld (void)
11541{
fdfde340
JM
11542 if (inst.operands[0].immisreg)
11543 reject_bad_reg (inst.operands[0].imm);
11544
c19d1205
ZW
11545 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11546}
b05fe5cf 11547
c19d1205
ZW
11548static void
11549do_t_push_pop (void)
b99bd4ef 11550{
e9f89963 11551 unsigned mask;
5f4273c7 11552
c19d1205
ZW
11553 constraint (inst.operands[0].writeback,
11554 _("push/pop do not support {reglist}^"));
11555 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11556 _("expression too complex"));
b99bd4ef 11557
e9f89963
PB
11558 mask = inst.operands[0].imm;
11559 if ((mask & ~0xff) == 0)
3c707909 11560 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 11561 else if ((inst.instruction == T_MNEM_push
e9f89963 11562 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 11563 || (inst.instruction == T_MNEM_pop
e9f89963 11564 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 11565 {
c19d1205
ZW
11566 inst.instruction = THUMB_OP16 (inst.instruction);
11567 inst.instruction |= THUMB_PP_PC_LR;
3c707909 11568 inst.instruction |= mask & 0xff;
c19d1205
ZW
11569 }
11570 else if (unified_syntax)
11571 {
3c707909 11572 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 11573 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
11574 }
11575 else
11576 {
11577 inst.error = _("invalid register list to push/pop instruction");
11578 return;
11579 }
c19d1205 11580}
b99bd4ef 11581
c19d1205
ZW
11582static void
11583do_t_rbit (void)
11584{
fdfde340
JM
11585 unsigned Rd, Rm;
11586
11587 Rd = inst.operands[0].reg;
11588 Rm = inst.operands[1].reg;
11589
11590 reject_bad_reg (Rd);
11591 reject_bad_reg (Rm);
11592
11593 inst.instruction |= Rd << 8;
11594 inst.instruction |= Rm << 16;
11595 inst.instruction |= Rm;
c19d1205 11596}
b99bd4ef 11597
c19d1205
ZW
11598static void
11599do_t_rev (void)
11600{
fdfde340
JM
11601 unsigned Rd, Rm;
11602
11603 Rd = inst.operands[0].reg;
11604 Rm = inst.operands[1].reg;
11605
11606 reject_bad_reg (Rd);
11607 reject_bad_reg (Rm);
11608
11609 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
11610 && inst.size_req != 4)
11611 {
11612 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11613 inst.instruction |= Rd;
11614 inst.instruction |= Rm << 3;
c19d1205
ZW
11615 }
11616 else if (unified_syntax)
11617 {
11618 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11619 inst.instruction |= Rd << 8;
11620 inst.instruction |= Rm << 16;
11621 inst.instruction |= Rm;
c19d1205
ZW
11622 }
11623 else
11624 inst.error = BAD_HIREG;
11625}
b99bd4ef 11626
1c444d06
JM
11627static void
11628do_t_rrx (void)
11629{
11630 unsigned Rd, Rm;
11631
11632 Rd = inst.operands[0].reg;
11633 Rm = inst.operands[1].reg;
11634
fdfde340
JM
11635 reject_bad_reg (Rd);
11636 reject_bad_reg (Rm);
c921be7d 11637
1c444d06
JM
11638 inst.instruction |= Rd << 8;
11639 inst.instruction |= Rm;
11640}
11641
c19d1205
ZW
11642static void
11643do_t_rsb (void)
11644{
fdfde340 11645 unsigned Rd, Rs;
b99bd4ef 11646
c19d1205
ZW
11647 Rd = inst.operands[0].reg;
11648 Rs = (inst.operands[1].present
11649 ? inst.operands[1].reg /* Rd, Rs, foo */
11650 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 11651
fdfde340
JM
11652 reject_bad_reg (Rd);
11653 reject_bad_reg (Rs);
11654 if (inst.operands[2].isreg)
11655 reject_bad_reg (inst.operands[2].reg);
11656
c19d1205
ZW
11657 inst.instruction |= Rd << 8;
11658 inst.instruction |= Rs << 16;
11659 if (!inst.operands[2].isreg)
11660 {
026d3abb
PB
11661 bfd_boolean narrow;
11662
11663 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 11664 narrow = !in_it_block ();
026d3abb 11665 else
e07e6e58 11666 narrow = in_it_block ();
026d3abb
PB
11667
11668 if (Rd > 7 || Rs > 7)
11669 narrow = FALSE;
11670
11671 if (inst.size_req == 4 || !unified_syntax)
11672 narrow = FALSE;
11673
11674 if (inst.reloc.exp.X_op != O_constant
11675 || inst.reloc.exp.X_add_number != 0)
11676 narrow = FALSE;
11677
11678 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11679 relaxation, but it doesn't seem worth the hassle. */
11680 if (narrow)
11681 {
11682 inst.reloc.type = BFD_RELOC_UNUSED;
11683 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11684 inst.instruction |= Rs << 3;
11685 inst.instruction |= Rd;
11686 }
11687 else
11688 {
11689 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11690 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11691 }
c19d1205
ZW
11692 }
11693 else
11694 encode_thumb32_shifted_operand (2);
11695}
b99bd4ef 11696
c19d1205
ZW
11697static void
11698do_t_setend (void)
11699{
e07e6e58 11700 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11701 if (inst.operands[0].imm)
11702 inst.instruction |= 0x8;
11703}
b99bd4ef 11704
c19d1205
ZW
11705static void
11706do_t_shift (void)
11707{
11708 if (!inst.operands[1].present)
11709 inst.operands[1].reg = inst.operands[0].reg;
11710
11711 if (unified_syntax)
11712 {
3d388997
PB
11713 bfd_boolean narrow;
11714 int shift_kind;
11715
11716 switch (inst.instruction)
11717 {
11718 case T_MNEM_asr:
11719 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11720 case T_MNEM_lsl:
11721 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11722 case T_MNEM_lsr:
11723 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11724 case T_MNEM_ror:
11725 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11726 default: abort ();
11727 }
11728
11729 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11730 narrow = !in_it_block ();
3d388997 11731 else
e07e6e58 11732 narrow = in_it_block ();
3d388997
PB
11733 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11734 narrow = FALSE;
11735 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11736 narrow = FALSE;
11737 if (inst.operands[2].isreg
11738 && (inst.operands[1].reg != inst.operands[0].reg
11739 || inst.operands[2].reg > 7))
11740 narrow = FALSE;
11741 if (inst.size_req == 4)
11742 narrow = FALSE;
11743
fdfde340
JM
11744 reject_bad_reg (inst.operands[0].reg);
11745 reject_bad_reg (inst.operands[1].reg);
c921be7d 11746
3d388997 11747 if (!narrow)
c19d1205
ZW
11748 {
11749 if (inst.operands[2].isreg)
b99bd4ef 11750 {
fdfde340 11751 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11752 inst.instruction = THUMB_OP32 (inst.instruction);
11753 inst.instruction |= inst.operands[0].reg << 8;
11754 inst.instruction |= inst.operands[1].reg << 16;
11755 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
11756
11757 /* PR 12854: Error on extraneous shifts. */
11758 constraint (inst.operands[2].shifted,
11759 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11760 }
11761 else
11762 {
11763 inst.operands[1].shifted = 1;
3d388997 11764 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11765 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11766 ? T_MNEM_movs : T_MNEM_mov);
11767 inst.instruction |= inst.operands[0].reg << 8;
11768 encode_thumb32_shifted_operand (1);
11769 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11770 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11771 }
11772 }
11773 else
11774 {
c19d1205 11775 if (inst.operands[2].isreg)
b99bd4ef 11776 {
3d388997 11777 switch (shift_kind)
b99bd4ef 11778 {
3d388997
PB
11779 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11780 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11781 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11782 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11783 default: abort ();
b99bd4ef 11784 }
5f4273c7 11785
c19d1205
ZW
11786 inst.instruction |= inst.operands[0].reg;
11787 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11788
11789 /* PR 12854: Error on extraneous shifts. */
11790 constraint (inst.operands[2].shifted,
11791 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
11792 }
11793 else
11794 {
3d388997 11795 switch (shift_kind)
b99bd4ef 11796 {
3d388997
PB
11797 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11798 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11799 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11800 default: abort ();
b99bd4ef 11801 }
c19d1205
ZW
11802 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11803 inst.instruction |= inst.operands[0].reg;
11804 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11805 }
11806 }
c19d1205
ZW
11807 }
11808 else
11809 {
11810 constraint (inst.operands[0].reg > 7
11811 || inst.operands[1].reg > 7, BAD_HIREG);
11812 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11813
c19d1205
ZW
11814 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11815 {
11816 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11817 constraint (inst.operands[0].reg != inst.operands[1].reg,
11818 _("source1 and dest must be same register"));
b99bd4ef 11819
c19d1205
ZW
11820 switch (inst.instruction)
11821 {
11822 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11823 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11824 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11825 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11826 default: abort ();
11827 }
5f4273c7 11828
c19d1205
ZW
11829 inst.instruction |= inst.operands[0].reg;
11830 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
11831
11832 /* PR 12854: Error on extraneous shifts. */
11833 constraint (inst.operands[2].shifted,
11834 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
11835 }
11836 else
b99bd4ef 11837 {
c19d1205
ZW
11838 switch (inst.instruction)
11839 {
11840 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11841 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11842 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11843 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11844 default: abort ();
11845 }
11846 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11847 inst.instruction |= inst.operands[0].reg;
11848 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11849 }
11850 }
b99bd4ef
NC
11851}
11852
11853static void
c19d1205 11854do_t_simd (void)
b99bd4ef 11855{
fdfde340
JM
11856 unsigned Rd, Rn, Rm;
11857
11858 Rd = inst.operands[0].reg;
11859 Rn = inst.operands[1].reg;
11860 Rm = inst.operands[2].reg;
11861
11862 reject_bad_reg (Rd);
11863 reject_bad_reg (Rn);
11864 reject_bad_reg (Rm);
11865
11866 inst.instruction |= Rd << 8;
11867 inst.instruction |= Rn << 16;
11868 inst.instruction |= Rm;
c19d1205 11869}
b99bd4ef 11870
03ee1b7f
NC
11871static void
11872do_t_simd2 (void)
11873{
11874 unsigned Rd, Rn, Rm;
11875
11876 Rd = inst.operands[0].reg;
11877 Rm = inst.operands[1].reg;
11878 Rn = inst.operands[2].reg;
11879
11880 reject_bad_reg (Rd);
11881 reject_bad_reg (Rn);
11882 reject_bad_reg (Rm);
11883
11884 inst.instruction |= Rd << 8;
11885 inst.instruction |= Rn << 16;
11886 inst.instruction |= Rm;
11887}
11888
c19d1205 11889static void
3eb17e6b 11890do_t_smc (void)
c19d1205
ZW
11891{
11892 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
11893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11894 _("SMC is not permitted on this architecture"));
c19d1205
ZW
11895 constraint (inst.reloc.exp.X_op != O_constant,
11896 _("expression too complex"));
11897 inst.reloc.type = BFD_RELOC_UNUSED;
11898 inst.instruction |= (value & 0xf000) >> 12;
11899 inst.instruction |= (value & 0x0ff0);
11900 inst.instruction |= (value & 0x000f) << 16;
11901}
b99bd4ef 11902
90ec0d68
MGD
11903static void
11904do_t_hvc (void)
11905{
11906 unsigned int value = inst.reloc.exp.X_add_number;
11907
11908 inst.reloc.type = BFD_RELOC_UNUSED;
11909 inst.instruction |= (value & 0x0fff);
11910 inst.instruction |= (value & 0xf000) << 4;
11911}
11912
c19d1205 11913static void
3a21c15a 11914do_t_ssat_usat (int bias)
c19d1205 11915{
fdfde340
JM
11916 unsigned Rd, Rn;
11917
11918 Rd = inst.operands[0].reg;
11919 Rn = inst.operands[2].reg;
11920
11921 reject_bad_reg (Rd);
11922 reject_bad_reg (Rn);
11923
11924 inst.instruction |= Rd << 8;
3a21c15a 11925 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11926 inst.instruction |= Rn << 16;
b99bd4ef 11927
c19d1205 11928 if (inst.operands[3].present)
b99bd4ef 11929 {
3a21c15a
NC
11930 offsetT shift_amount = inst.reloc.exp.X_add_number;
11931
11932 inst.reloc.type = BFD_RELOC_UNUSED;
11933
c19d1205
ZW
11934 constraint (inst.reloc.exp.X_op != O_constant,
11935 _("expression too complex"));
b99bd4ef 11936
3a21c15a 11937 if (shift_amount != 0)
6189168b 11938 {
3a21c15a
NC
11939 constraint (shift_amount > 31,
11940 _("shift expression is too large"));
11941
c19d1205 11942 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11943 inst.instruction |= 0x00200000; /* sh bit. */
11944
11945 inst.instruction |= (shift_amount & 0x1c) << 10;
11946 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11947 }
11948 }
b99bd4ef 11949}
c921be7d 11950
3a21c15a
NC
11951static void
11952do_t_ssat (void)
11953{
11954 do_t_ssat_usat (1);
11955}
b99bd4ef 11956
0dd132b6 11957static void
c19d1205 11958do_t_ssat16 (void)
0dd132b6 11959{
fdfde340
JM
11960 unsigned Rd, Rn;
11961
11962 Rd = inst.operands[0].reg;
11963 Rn = inst.operands[2].reg;
11964
11965 reject_bad_reg (Rd);
11966 reject_bad_reg (Rn);
11967
11968 inst.instruction |= Rd << 8;
c19d1205 11969 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11970 inst.instruction |= Rn << 16;
c19d1205 11971}
0dd132b6 11972
c19d1205
ZW
11973static void
11974do_t_strex (void)
11975{
11976 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11977 || inst.operands[2].postind || inst.operands[2].writeback
11978 || inst.operands[2].immisreg || inst.operands[2].shifted
11979 || inst.operands[2].negative,
01cfc07f 11980 BAD_ADDR_MODE);
0dd132b6 11981
5be8be5d
DG
11982 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11983
c19d1205
ZW
11984 inst.instruction |= inst.operands[0].reg << 8;
11985 inst.instruction |= inst.operands[1].reg << 12;
11986 inst.instruction |= inst.operands[2].reg << 16;
11987 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11988}
11989
b99bd4ef 11990static void
c19d1205 11991do_t_strexd (void)
b99bd4ef 11992{
c19d1205
ZW
11993 if (!inst.operands[2].present)
11994 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11995
c19d1205
ZW
11996 constraint (inst.operands[0].reg == inst.operands[1].reg
11997 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11998 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11999 BAD_OVERLAP);
b99bd4ef 12000
c19d1205
ZW
12001 inst.instruction |= inst.operands[0].reg;
12002 inst.instruction |= inst.operands[1].reg << 12;
12003 inst.instruction |= inst.operands[2].reg << 8;
12004 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12005}
12006
12007static void
c19d1205 12008do_t_sxtah (void)
b99bd4ef 12009{
fdfde340
JM
12010 unsigned Rd, Rn, Rm;
12011
12012 Rd = inst.operands[0].reg;
12013 Rn = inst.operands[1].reg;
12014 Rm = inst.operands[2].reg;
12015
12016 reject_bad_reg (Rd);
12017 reject_bad_reg (Rn);
12018 reject_bad_reg (Rm);
12019
12020 inst.instruction |= Rd << 8;
12021 inst.instruction |= Rn << 16;
12022 inst.instruction |= Rm;
c19d1205
ZW
12023 inst.instruction |= inst.operands[3].imm << 4;
12024}
b99bd4ef 12025
c19d1205
ZW
12026static void
12027do_t_sxth (void)
12028{
fdfde340
JM
12029 unsigned Rd, Rm;
12030
12031 Rd = inst.operands[0].reg;
12032 Rm = inst.operands[1].reg;
12033
12034 reject_bad_reg (Rd);
12035 reject_bad_reg (Rm);
c921be7d
NC
12036
12037 if (inst.instruction <= 0xffff
12038 && inst.size_req != 4
fdfde340 12039 && Rd <= 7 && Rm <= 7
c19d1205 12040 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12041 {
c19d1205 12042 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12043 inst.instruction |= Rd;
12044 inst.instruction |= Rm << 3;
b99bd4ef 12045 }
c19d1205 12046 else if (unified_syntax)
b99bd4ef 12047 {
c19d1205
ZW
12048 if (inst.instruction <= 0xffff)
12049 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12050 inst.instruction |= Rd << 8;
12051 inst.instruction |= Rm;
c19d1205 12052 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12053 }
c19d1205 12054 else
b99bd4ef 12055 {
c19d1205
ZW
12056 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12057 _("Thumb encoding does not support rotation"));
12058 constraint (1, BAD_HIREG);
b99bd4ef 12059 }
c19d1205 12060}
b99bd4ef 12061
c19d1205
ZW
12062static void
12063do_t_swi (void)
12064{
b2a5fbdc
MGD
12065 /* We have to do the following check manually as ARM_EXT_OS only applies
12066 to ARM_EXT_V6M. */
12067 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12068 {
ac7f631b
NC
12069 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12070 /* This only applies to the v6m howver, not later architectures. */
12071 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12072 as_bad (_("SVC is not permitted on this architecture"));
12073 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12074 }
12075
c19d1205
ZW
12076 inst.reloc.type = BFD_RELOC_ARM_SWI;
12077}
b99bd4ef 12078
92e90b6e
PB
12079static void
12080do_t_tb (void)
12081{
fdfde340 12082 unsigned Rn, Rm;
92e90b6e
PB
12083 int half;
12084
12085 half = (inst.instruction & 0x10) != 0;
e07e6e58 12086 set_it_insn_type_last ();
dfa9f0d5
PB
12087 constraint (inst.operands[0].immisreg,
12088 _("instruction requires register index"));
fdfde340
JM
12089
12090 Rn = inst.operands[0].reg;
12091 Rm = inst.operands[0].imm;
c921be7d 12092
fdfde340
JM
12093 constraint (Rn == REG_SP, BAD_SP);
12094 reject_bad_reg (Rm);
12095
92e90b6e
PB
12096 constraint (!half && inst.operands[0].shifted,
12097 _("instruction does not allow shifted index"));
fdfde340 12098 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12099}
12100
c19d1205
ZW
12101static void
12102do_t_usat (void)
12103{
3a21c15a 12104 do_t_ssat_usat (0);
b99bd4ef
NC
12105}
12106
12107static void
c19d1205 12108do_t_usat16 (void)
b99bd4ef 12109{
fdfde340
JM
12110 unsigned Rd, Rn;
12111
12112 Rd = inst.operands[0].reg;
12113 Rn = inst.operands[2].reg;
12114
12115 reject_bad_reg (Rd);
12116 reject_bad_reg (Rn);
12117
12118 inst.instruction |= Rd << 8;
c19d1205 12119 inst.instruction |= inst.operands[1].imm;
fdfde340 12120 inst.instruction |= Rn << 16;
b99bd4ef 12121}
c19d1205 12122
5287ad62 12123/* Neon instruction encoder helpers. */
5f4273c7 12124
5287ad62 12125/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12126
5287ad62
JB
12127/* An "invalid" code for the following tables. */
12128#define N_INV -1u
12129
12130struct neon_tab_entry
b99bd4ef 12131{
5287ad62
JB
12132 unsigned integer;
12133 unsigned float_or_poly;
12134 unsigned scalar_or_imm;
12135};
5f4273c7 12136
5287ad62
JB
12137/* Map overloaded Neon opcodes to their respective encodings. */
12138#define NEON_ENC_TAB \
12139 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12140 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12141 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12142 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12143 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12144 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12145 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12146 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12147 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12148 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12149 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12150 /* Register variants of the following two instructions are encoded as
e07e6e58 12151 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
12152 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12153 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
12154 X(vfma, N_INV, 0x0000c10, N_INV), \
12155 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
12156 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12157 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12158 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12159 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12160 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12161 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12162 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12163 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12164 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12165 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12166 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12167 X(vshl, 0x0000400, N_INV, 0x0800510), \
12168 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12169 X(vand, 0x0000110, N_INV, 0x0800030), \
12170 X(vbic, 0x0100110, N_INV, 0x0800030), \
12171 X(veor, 0x1000110, N_INV, N_INV), \
12172 X(vorn, 0x0300110, N_INV, 0x0800010), \
12173 X(vorr, 0x0200110, N_INV, 0x0800010), \
12174 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12175 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12176 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12177 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12178 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12179 X(vst1, 0x0000000, 0x0800000, N_INV), \
12180 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12181 X(vst2, 0x0000100, 0x0800100, N_INV), \
12182 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12183 X(vst3, 0x0000200, 0x0800200, N_INV), \
12184 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12185 X(vst4, 0x0000300, 0x0800300, N_INV), \
12186 X(vmovn, 0x1b20200, N_INV, N_INV), \
12187 X(vtrn, 0x1b20080, N_INV, N_INV), \
12188 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12189 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12190 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12191 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12192 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12193 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12194 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12195 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12196 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12197 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12198 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
12199
12200enum neon_opc
12201{
12202#define X(OPC,I,F,S) N_MNEM_##OPC
12203NEON_ENC_TAB
12204#undef X
12205};
b99bd4ef 12206
5287ad62
JB
12207static const struct neon_tab_entry neon_enc_tab[] =
12208{
12209#define X(OPC,I,F,S) { (I), (F), (S) }
12210NEON_ENC_TAB
12211#undef X
12212};
b99bd4ef 12213
88714cb8
DG
12214/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12215#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12216#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12217#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12218#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12219#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12220#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12221#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12222#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12223#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12224#define NEON_ENC_SINGLE_(X) \
037e8744 12225 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12226#define NEON_ENC_DOUBLE_(X) \
037e8744 12227 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 12228
88714cb8
DG
12229#define NEON_ENCODE(type, inst) \
12230 do \
12231 { \
12232 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12233 inst.is_neon = 1; \
12234 } \
12235 while (0)
12236
12237#define check_neon_suffixes \
12238 do \
12239 { \
12240 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12241 { \
12242 as_bad (_("invalid neon suffix for non neon instruction")); \
12243 return; \
12244 } \
12245 } \
12246 while (0)
12247
037e8744
JB
12248/* Define shapes for instruction operands. The following mnemonic characters
12249 are used in this table:
5287ad62 12250
037e8744 12251 F - VFP S<n> register
5287ad62
JB
12252 D - Neon D<n> register
12253 Q - Neon Q<n> register
12254 I - Immediate
12255 S - Scalar
12256 R - ARM register
12257 L - D<n> register list
5f4273c7 12258
037e8744
JB
12259 This table is used to generate various data:
12260 - enumerations of the form NS_DDR to be used as arguments to
12261 neon_select_shape.
12262 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 12263 - a table used to drive neon_select_shape. */
b99bd4ef 12264
037e8744
JB
12265#define NEON_SHAPE_DEF \
12266 X(3, (D, D, D), DOUBLE), \
12267 X(3, (Q, Q, Q), QUAD), \
12268 X(3, (D, D, I), DOUBLE), \
12269 X(3, (Q, Q, I), QUAD), \
12270 X(3, (D, D, S), DOUBLE), \
12271 X(3, (Q, Q, S), QUAD), \
12272 X(2, (D, D), DOUBLE), \
12273 X(2, (Q, Q), QUAD), \
12274 X(2, (D, S), DOUBLE), \
12275 X(2, (Q, S), QUAD), \
12276 X(2, (D, R), DOUBLE), \
12277 X(2, (Q, R), QUAD), \
12278 X(2, (D, I), DOUBLE), \
12279 X(2, (Q, I), QUAD), \
12280 X(3, (D, L, D), DOUBLE), \
12281 X(2, (D, Q), MIXED), \
12282 X(2, (Q, D), MIXED), \
12283 X(3, (D, Q, I), MIXED), \
12284 X(3, (Q, D, I), MIXED), \
12285 X(3, (Q, D, D), MIXED), \
12286 X(3, (D, Q, Q), MIXED), \
12287 X(3, (Q, Q, D), MIXED), \
12288 X(3, (Q, D, S), MIXED), \
12289 X(3, (D, Q, S), MIXED), \
12290 X(4, (D, D, D, I), DOUBLE), \
12291 X(4, (Q, Q, Q, I), QUAD), \
12292 X(2, (F, F), SINGLE), \
12293 X(3, (F, F, F), SINGLE), \
12294 X(2, (F, I), SINGLE), \
12295 X(2, (F, D), MIXED), \
12296 X(2, (D, F), MIXED), \
12297 X(3, (F, F, I), MIXED), \
12298 X(4, (R, R, F, F), SINGLE), \
12299 X(4, (F, F, R, R), SINGLE), \
12300 X(3, (D, R, R), DOUBLE), \
12301 X(3, (R, R, D), DOUBLE), \
12302 X(2, (S, R), SINGLE), \
12303 X(2, (R, S), SINGLE), \
12304 X(2, (F, R), SINGLE), \
12305 X(2, (R, F), SINGLE)
12306
12307#define S2(A,B) NS_##A##B
12308#define S3(A,B,C) NS_##A##B##C
12309#define S4(A,B,C,D) NS_##A##B##C##D
12310
12311#define X(N, L, C) S##N L
12312
5287ad62
JB
12313enum neon_shape
12314{
037e8744
JB
12315 NEON_SHAPE_DEF,
12316 NS_NULL
5287ad62 12317};
b99bd4ef 12318
037e8744
JB
12319#undef X
12320#undef S2
12321#undef S3
12322#undef S4
12323
12324enum neon_shape_class
12325{
12326 SC_SINGLE,
12327 SC_DOUBLE,
12328 SC_QUAD,
12329 SC_MIXED
12330};
12331
12332#define X(N, L, C) SC_##C
12333
12334static enum neon_shape_class neon_shape_class[] =
12335{
12336 NEON_SHAPE_DEF
12337};
12338
12339#undef X
12340
12341enum neon_shape_el
12342{
12343 SE_F,
12344 SE_D,
12345 SE_Q,
12346 SE_I,
12347 SE_S,
12348 SE_R,
12349 SE_L
12350};
12351
12352/* Register widths of above. */
12353static unsigned neon_shape_el_size[] =
12354{
12355 32,
12356 64,
12357 128,
12358 0,
12359 32,
12360 32,
12361 0
12362};
12363
12364struct neon_shape_info
12365{
12366 unsigned els;
12367 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12368};
12369
12370#define S2(A,B) { SE_##A, SE_##B }
12371#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12372#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12373
12374#define X(N, L, C) { N, S##N L }
12375
12376static struct neon_shape_info neon_shape_tab[] =
12377{
12378 NEON_SHAPE_DEF
12379};
12380
12381#undef X
12382#undef S2
12383#undef S3
12384#undef S4
12385
5287ad62
JB
12386/* Bit masks used in type checking given instructions.
12387 'N_EQK' means the type must be the same as (or based on in some way) the key
12388 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12389 set, various other bits can be set as well in order to modify the meaning of
12390 the type constraint. */
12391
12392enum neon_type_mask
12393{
8e79c3df
CM
12394 N_S8 = 0x0000001,
12395 N_S16 = 0x0000002,
12396 N_S32 = 0x0000004,
12397 N_S64 = 0x0000008,
12398 N_U8 = 0x0000010,
12399 N_U16 = 0x0000020,
12400 N_U32 = 0x0000040,
12401 N_U64 = 0x0000080,
12402 N_I8 = 0x0000100,
12403 N_I16 = 0x0000200,
12404 N_I32 = 0x0000400,
12405 N_I64 = 0x0000800,
12406 N_8 = 0x0001000,
12407 N_16 = 0x0002000,
12408 N_32 = 0x0004000,
12409 N_64 = 0x0008000,
12410 N_P8 = 0x0010000,
12411 N_P16 = 0x0020000,
12412 N_F16 = 0x0040000,
12413 N_F32 = 0x0080000,
12414 N_F64 = 0x0100000,
c921be7d
NC
12415 N_KEY = 0x1000000, /* Key element (main type specifier). */
12416 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 12417 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
12418 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12419 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12420 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12421 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12422 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12423 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12424 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 12425 N_UTYP = 0,
037e8744 12426 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
12427};
12428
dcbf9037
JB
12429#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12430
5287ad62
JB
12431#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12432#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12433#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12434#define N_SUF_32 (N_SU_32 | N_F32)
12435#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12436#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12437
12438/* Pass this as the first type argument to neon_check_type to ignore types
12439 altogether. */
12440#define N_IGNORE_TYPE (N_KEY | N_EQK)
12441
037e8744
JB
12442/* Select a "shape" for the current instruction (describing register types or
12443 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12444 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12445 function of operand parsing, so this function doesn't need to be called.
12446 Shapes should be listed in order of decreasing length. */
5287ad62
JB
12447
12448static enum neon_shape
037e8744 12449neon_select_shape (enum neon_shape shape, ...)
5287ad62 12450{
037e8744
JB
12451 va_list ap;
12452 enum neon_shape first_shape = shape;
5287ad62
JB
12453
12454 /* Fix missing optional operands. FIXME: we don't know at this point how
12455 many arguments we should have, so this makes the assumption that we have
12456 > 1. This is true of all current Neon opcodes, I think, but may not be
12457 true in the future. */
12458 if (!inst.operands[1].present)
12459 inst.operands[1] = inst.operands[0];
12460
037e8744 12461 va_start (ap, shape);
5f4273c7 12462
21d799b5 12463 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
12464 {
12465 unsigned j;
12466 int matches = 1;
12467
12468 for (j = 0; j < neon_shape_tab[shape].els; j++)
12469 {
12470 if (!inst.operands[j].present)
12471 {
12472 matches = 0;
12473 break;
12474 }
12475
12476 switch (neon_shape_tab[shape].el[j])
12477 {
12478 case SE_F:
12479 if (!(inst.operands[j].isreg
12480 && inst.operands[j].isvec
12481 && inst.operands[j].issingle
12482 && !inst.operands[j].isquad))
12483 matches = 0;
12484 break;
12485
12486 case SE_D:
12487 if (!(inst.operands[j].isreg
12488 && inst.operands[j].isvec
12489 && !inst.operands[j].isquad
12490 && !inst.operands[j].issingle))
12491 matches = 0;
12492 break;
12493
12494 case SE_R:
12495 if (!(inst.operands[j].isreg
12496 && !inst.operands[j].isvec))
12497 matches = 0;
12498 break;
12499
12500 case SE_Q:
12501 if (!(inst.operands[j].isreg
12502 && inst.operands[j].isvec
12503 && inst.operands[j].isquad
12504 && !inst.operands[j].issingle))
12505 matches = 0;
12506 break;
12507
12508 case SE_I:
12509 if (!(!inst.operands[j].isreg
12510 && !inst.operands[j].isscalar))
12511 matches = 0;
12512 break;
12513
12514 case SE_S:
12515 if (!(!inst.operands[j].isreg
12516 && inst.operands[j].isscalar))
12517 matches = 0;
12518 break;
12519
12520 case SE_L:
12521 break;
12522 }
3fde54a2
JZ
12523 if (!matches)
12524 break;
037e8744 12525 }
ad6cec43
MGD
12526 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12527 /* We've matched all the entries in the shape table, and we don't
12528 have any left over operands which have not been matched. */
5287ad62 12529 break;
037e8744 12530 }
5f4273c7 12531
037e8744 12532 va_end (ap);
5287ad62 12533
037e8744
JB
12534 if (shape == NS_NULL && first_shape != NS_NULL)
12535 first_error (_("invalid instruction shape"));
5287ad62 12536
037e8744
JB
12537 return shape;
12538}
5287ad62 12539
037e8744
JB
12540/* True if SHAPE is predominantly a quadword operation (most of the time, this
12541 means the Q bit should be set). */
12542
12543static int
12544neon_quad (enum neon_shape shape)
12545{
12546 return neon_shape_class[shape] == SC_QUAD;
5287ad62 12547}
037e8744 12548
5287ad62
JB
12549static void
12550neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12551 unsigned *g_size)
12552{
12553 /* Allow modification to be made to types which are constrained to be
12554 based on the key element, based on bits set alongside N_EQK. */
12555 if ((typebits & N_EQK) != 0)
12556 {
12557 if ((typebits & N_HLF) != 0)
12558 *g_size /= 2;
12559 else if ((typebits & N_DBL) != 0)
12560 *g_size *= 2;
12561 if ((typebits & N_SGN) != 0)
12562 *g_type = NT_signed;
12563 else if ((typebits & N_UNS) != 0)
12564 *g_type = NT_unsigned;
12565 else if ((typebits & N_INT) != 0)
12566 *g_type = NT_integer;
12567 else if ((typebits & N_FLT) != 0)
12568 *g_type = NT_float;
dcbf9037
JB
12569 else if ((typebits & N_SIZ) != 0)
12570 *g_type = NT_untyped;
5287ad62
JB
12571 }
12572}
5f4273c7 12573
5287ad62
JB
12574/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12575 operand type, i.e. the single type specified in a Neon instruction when it
12576 is the only one given. */
12577
12578static struct neon_type_el
12579neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12580{
12581 struct neon_type_el dest = *key;
5f4273c7 12582
9c2799c2 12583 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 12584
5287ad62
JB
12585 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12586
12587 return dest;
12588}
12589
12590/* Convert Neon type and size into compact bitmask representation. */
12591
12592static enum neon_type_mask
12593type_chk_of_el_type (enum neon_el_type type, unsigned size)
12594{
12595 switch (type)
12596 {
12597 case NT_untyped:
12598 switch (size)
12599 {
12600 case 8: return N_8;
12601 case 16: return N_16;
12602 case 32: return N_32;
12603 case 64: return N_64;
12604 default: ;
12605 }
12606 break;
12607
12608 case NT_integer:
12609 switch (size)
12610 {
12611 case 8: return N_I8;
12612 case 16: return N_I16;
12613 case 32: return N_I32;
12614 case 64: return N_I64;
12615 default: ;
12616 }
12617 break;
12618
12619 case NT_float:
037e8744
JB
12620 switch (size)
12621 {
8e79c3df 12622 case 16: return N_F16;
037e8744
JB
12623 case 32: return N_F32;
12624 case 64: return N_F64;
12625 default: ;
12626 }
5287ad62
JB
12627 break;
12628
12629 case NT_poly:
12630 switch (size)
12631 {
12632 case 8: return N_P8;
12633 case 16: return N_P16;
12634 default: ;
12635 }
12636 break;
12637
12638 case NT_signed:
12639 switch (size)
12640 {
12641 case 8: return N_S8;
12642 case 16: return N_S16;
12643 case 32: return N_S32;
12644 case 64: return N_S64;
12645 default: ;
12646 }
12647 break;
12648
12649 case NT_unsigned:
12650 switch (size)
12651 {
12652 case 8: return N_U8;
12653 case 16: return N_U16;
12654 case 32: return N_U32;
12655 case 64: return N_U64;
12656 default: ;
12657 }
12658 break;
12659
12660 default: ;
12661 }
5f4273c7 12662
5287ad62
JB
12663 return N_UTYP;
12664}
12665
12666/* Convert compact Neon bitmask type representation to a type and size. Only
12667 handles the case where a single bit is set in the mask. */
12668
dcbf9037 12669static int
5287ad62
JB
12670el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12671 enum neon_type_mask mask)
12672{
dcbf9037
JB
12673 if ((mask & N_EQK) != 0)
12674 return FAIL;
12675
5287ad62
JB
12676 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12677 *size = 8;
dcbf9037 12678 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 12679 *size = 16;
dcbf9037 12680 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 12681 *size = 32;
037e8744 12682 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 12683 *size = 64;
dcbf9037
JB
12684 else
12685 return FAIL;
12686
5287ad62
JB
12687 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12688 *type = NT_signed;
dcbf9037 12689 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 12690 *type = NT_unsigned;
dcbf9037 12691 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 12692 *type = NT_integer;
dcbf9037 12693 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 12694 *type = NT_untyped;
dcbf9037 12695 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 12696 *type = NT_poly;
037e8744 12697 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 12698 *type = NT_float;
dcbf9037
JB
12699 else
12700 return FAIL;
5f4273c7 12701
dcbf9037 12702 return SUCCESS;
5287ad62
JB
12703}
12704
12705/* Modify a bitmask of allowed types. This is only needed for type
12706 relaxation. */
12707
12708static unsigned
12709modify_types_allowed (unsigned allowed, unsigned mods)
12710{
12711 unsigned size;
12712 enum neon_el_type type;
12713 unsigned destmask;
12714 int i;
5f4273c7 12715
5287ad62 12716 destmask = 0;
5f4273c7 12717
5287ad62
JB
12718 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12719 {
21d799b5
NC
12720 if (el_type_of_type_chk (&type, &size,
12721 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12722 {
12723 neon_modify_type_size (mods, &type, &size);
12724 destmask |= type_chk_of_el_type (type, size);
12725 }
5287ad62 12726 }
5f4273c7 12727
5287ad62
JB
12728 return destmask;
12729}
12730
12731/* Check type and return type classification.
12732 The manual states (paraphrase): If one datatype is given, it indicates the
12733 type given in:
12734 - the second operand, if there is one
12735 - the operand, if there is no second operand
12736 - the result, if there are no operands.
12737 This isn't quite good enough though, so we use a concept of a "key" datatype
12738 which is set on a per-instruction basis, which is the one which matters when
12739 only one data type is written.
12740 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12741 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12742
12743static struct neon_type_el
12744neon_check_type (unsigned els, enum neon_shape ns, ...)
12745{
12746 va_list ap;
12747 unsigned i, pass, key_el = 0;
12748 unsigned types[NEON_MAX_TYPE_ELS];
12749 enum neon_el_type k_type = NT_invtype;
12750 unsigned k_size = -1u;
12751 struct neon_type_el badtype = {NT_invtype, -1};
12752 unsigned key_allowed = 0;
12753
12754 /* Optional registers in Neon instructions are always (not) in operand 1.
12755 Fill in the missing operand here, if it was omitted. */
12756 if (els > 1 && !inst.operands[1].present)
12757 inst.operands[1] = inst.operands[0];
12758
12759 /* Suck up all the varargs. */
12760 va_start (ap, ns);
12761 for (i = 0; i < els; i++)
12762 {
12763 unsigned thisarg = va_arg (ap, unsigned);
12764 if (thisarg == N_IGNORE_TYPE)
12765 {
12766 va_end (ap);
12767 return badtype;
12768 }
12769 types[i] = thisarg;
12770 if ((thisarg & N_KEY) != 0)
12771 key_el = i;
12772 }
12773 va_end (ap);
12774
dcbf9037
JB
12775 if (inst.vectype.elems > 0)
12776 for (i = 0; i < els; i++)
12777 if (inst.operands[i].vectype.type != NT_invtype)
12778 {
12779 first_error (_("types specified in both the mnemonic and operands"));
12780 return badtype;
12781 }
12782
5287ad62
JB
12783 /* Duplicate inst.vectype elements here as necessary.
12784 FIXME: No idea if this is exactly the same as the ARM assembler,
12785 particularly when an insn takes one register and one non-register
12786 operand. */
12787 if (inst.vectype.elems == 1 && els > 1)
12788 {
12789 unsigned j;
12790 inst.vectype.elems = els;
12791 inst.vectype.el[key_el] = inst.vectype.el[0];
12792 for (j = 0; j < els; j++)
dcbf9037
JB
12793 if (j != key_el)
12794 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12795 types[j]);
12796 }
12797 else if (inst.vectype.elems == 0 && els > 0)
12798 {
12799 unsigned j;
12800 /* No types were given after the mnemonic, so look for types specified
12801 after each operand. We allow some flexibility here; as long as the
12802 "key" operand has a type, we can infer the others. */
12803 for (j = 0; j < els; j++)
12804 if (inst.operands[j].vectype.type != NT_invtype)
12805 inst.vectype.el[j] = inst.operands[j].vectype;
12806
12807 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12808 {
dcbf9037
JB
12809 for (j = 0; j < els; j++)
12810 if (inst.operands[j].vectype.type == NT_invtype)
12811 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12812 types[j]);
12813 }
12814 else
12815 {
12816 first_error (_("operand types can't be inferred"));
12817 return badtype;
5287ad62
JB
12818 }
12819 }
12820 else if (inst.vectype.elems != els)
12821 {
dcbf9037 12822 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12823 return badtype;
12824 }
12825
12826 for (pass = 0; pass < 2; pass++)
12827 {
12828 for (i = 0; i < els; i++)
12829 {
12830 unsigned thisarg = types[i];
12831 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12832 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12833 enum neon_el_type g_type = inst.vectype.el[i].type;
12834 unsigned g_size = inst.vectype.el[i].size;
12835
12836 /* Decay more-specific signed & unsigned types to sign-insensitive
12837 integer types if sign-specific variants are unavailable. */
12838 if ((g_type == NT_signed || g_type == NT_unsigned)
12839 && (types_allowed & N_SU_ALL) == 0)
12840 g_type = NT_integer;
12841
12842 /* If only untyped args are allowed, decay any more specific types to
12843 them. Some instructions only care about signs for some element
12844 sizes, so handle that properly. */
12845 if ((g_size == 8 && (types_allowed & N_8) != 0)
12846 || (g_size == 16 && (types_allowed & N_16) != 0)
12847 || (g_size == 32 && (types_allowed & N_32) != 0)
12848 || (g_size == 64 && (types_allowed & N_64) != 0))
12849 g_type = NT_untyped;
12850
12851 if (pass == 0)
12852 {
12853 if ((thisarg & N_KEY) != 0)
12854 {
12855 k_type = g_type;
12856 k_size = g_size;
12857 key_allowed = thisarg & ~N_KEY;
12858 }
12859 }
12860 else
12861 {
037e8744
JB
12862 if ((thisarg & N_VFP) != 0)
12863 {
99b253c5
NC
12864 enum neon_shape_el regshape;
12865 unsigned regwidth, match;
12866
12867 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12868 if (ns == NS_NULL)
12869 {
12870 first_error (_("invalid instruction shape"));
12871 return badtype;
12872 }
12873 regshape = neon_shape_tab[ns].el[i];
12874 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12875
12876 /* In VFP mode, operands must match register widths. If we
12877 have a key operand, use its width, else use the width of
12878 the current operand. */
12879 if (k_size != -1u)
12880 match = k_size;
12881 else
12882 match = g_size;
12883
12884 if (regwidth != match)
12885 {
12886 first_error (_("operand size must match register width"));
12887 return badtype;
12888 }
12889 }
5f4273c7 12890
5287ad62
JB
12891 if ((thisarg & N_EQK) == 0)
12892 {
12893 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12894
12895 if ((given_type & types_allowed) == 0)
12896 {
dcbf9037 12897 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12898 return badtype;
12899 }
12900 }
12901 else
12902 {
12903 enum neon_el_type mod_k_type = k_type;
12904 unsigned mod_k_size = k_size;
12905 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12906 if (g_type != mod_k_type || g_size != mod_k_size)
12907 {
dcbf9037 12908 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12909 return badtype;
12910 }
12911 }
12912 }
12913 }
12914 }
12915
12916 return inst.vectype.el[key_el];
12917}
12918
037e8744 12919/* Neon-style VFP instruction forwarding. */
5287ad62 12920
037e8744
JB
12921/* Thumb VFP instructions have 0xE in the condition field. */
12922
12923static void
12924do_vfp_cond_or_thumb (void)
5287ad62 12925{
88714cb8
DG
12926 inst.is_neon = 1;
12927
5287ad62 12928 if (thumb_mode)
037e8744 12929 inst.instruction |= 0xe0000000;
5287ad62 12930 else
037e8744 12931 inst.instruction |= inst.cond << 28;
5287ad62
JB
12932}
12933
037e8744
JB
12934/* Look up and encode a simple mnemonic, for use as a helper function for the
12935 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12936 etc. It is assumed that operand parsing has already been done, and that the
12937 operands are in the form expected by the given opcode (this isn't necessarily
12938 the same as the form in which they were parsed, hence some massaging must
12939 take place before this function is called).
12940 Checks current arch version against that in the looked-up opcode. */
5287ad62 12941
037e8744
JB
12942static void
12943do_vfp_nsyn_opcode (const char *opname)
5287ad62 12944{
037e8744 12945 const struct asm_opcode *opcode;
5f4273c7 12946
21d799b5 12947 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12948
037e8744
JB
12949 if (!opcode)
12950 abort ();
5287ad62 12951
037e8744
JB
12952 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12953 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12954 _(BAD_FPU));
5287ad62 12955
88714cb8
DG
12956 inst.is_neon = 1;
12957
037e8744
JB
12958 if (thumb_mode)
12959 {
12960 inst.instruction = opcode->tvalue;
12961 opcode->tencode ();
12962 }
12963 else
12964 {
12965 inst.instruction = (inst.cond << 28) | opcode->avalue;
12966 opcode->aencode ();
12967 }
12968}
5287ad62
JB
12969
12970static void
037e8744 12971do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12972{
037e8744
JB
12973 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12974
12975 if (rs == NS_FFF)
12976 {
12977 if (is_add)
12978 do_vfp_nsyn_opcode ("fadds");
12979 else
12980 do_vfp_nsyn_opcode ("fsubs");
12981 }
12982 else
12983 {
12984 if (is_add)
12985 do_vfp_nsyn_opcode ("faddd");
12986 else
12987 do_vfp_nsyn_opcode ("fsubd");
12988 }
12989}
12990
12991/* Check operand types to see if this is a VFP instruction, and if so call
12992 PFN (). */
12993
12994static int
12995try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12996{
12997 enum neon_shape rs;
12998 struct neon_type_el et;
12999
13000 switch (args)
13001 {
13002 case 2:
13003 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13004 et = neon_check_type (2, rs,
13005 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13006 break;
5f4273c7 13007
037e8744
JB
13008 case 3:
13009 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13010 et = neon_check_type (3, rs,
13011 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13012 break;
13013
13014 default:
13015 abort ();
13016 }
13017
13018 if (et.type != NT_invtype)
13019 {
13020 pfn (rs);
13021 return SUCCESS;
13022 }
037e8744 13023
99b253c5 13024 inst.error = NULL;
037e8744
JB
13025 return FAIL;
13026}
13027
13028static void
13029do_vfp_nsyn_mla_mls (enum neon_shape rs)
13030{
13031 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13032
037e8744
JB
13033 if (rs == NS_FFF)
13034 {
13035 if (is_mla)
13036 do_vfp_nsyn_opcode ("fmacs");
13037 else
1ee69515 13038 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13039 }
13040 else
13041 {
13042 if (is_mla)
13043 do_vfp_nsyn_opcode ("fmacd");
13044 else
1ee69515 13045 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13046 }
13047}
13048
62f3b8c8
PB
13049static void
13050do_vfp_nsyn_fma_fms (enum neon_shape rs)
13051{
13052 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13053
13054 if (rs == NS_FFF)
13055 {
13056 if (is_fma)
13057 do_vfp_nsyn_opcode ("ffmas");
13058 else
13059 do_vfp_nsyn_opcode ("ffnmas");
13060 }
13061 else
13062 {
13063 if (is_fma)
13064 do_vfp_nsyn_opcode ("ffmad");
13065 else
13066 do_vfp_nsyn_opcode ("ffnmad");
13067 }
13068}
13069
037e8744
JB
13070static void
13071do_vfp_nsyn_mul (enum neon_shape rs)
13072{
13073 if (rs == NS_FFF)
13074 do_vfp_nsyn_opcode ("fmuls");
13075 else
13076 do_vfp_nsyn_opcode ("fmuld");
13077}
13078
13079static void
13080do_vfp_nsyn_abs_neg (enum neon_shape rs)
13081{
13082 int is_neg = (inst.instruction & 0x80) != 0;
13083 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13084
13085 if (rs == NS_FF)
13086 {
13087 if (is_neg)
13088 do_vfp_nsyn_opcode ("fnegs");
13089 else
13090 do_vfp_nsyn_opcode ("fabss");
13091 }
13092 else
13093 {
13094 if (is_neg)
13095 do_vfp_nsyn_opcode ("fnegd");
13096 else
13097 do_vfp_nsyn_opcode ("fabsd");
13098 }
13099}
13100
13101/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13102 insns belong to Neon, and are handled elsewhere. */
13103
13104static void
13105do_vfp_nsyn_ldm_stm (int is_dbmode)
13106{
13107 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13108 if (is_ldm)
13109 {
13110 if (is_dbmode)
13111 do_vfp_nsyn_opcode ("fldmdbs");
13112 else
13113 do_vfp_nsyn_opcode ("fldmias");
13114 }
13115 else
13116 {
13117 if (is_dbmode)
13118 do_vfp_nsyn_opcode ("fstmdbs");
13119 else
13120 do_vfp_nsyn_opcode ("fstmias");
13121 }
13122}
13123
037e8744
JB
13124static void
13125do_vfp_nsyn_sqrt (void)
13126{
13127 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13128 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13129
037e8744
JB
13130 if (rs == NS_FF)
13131 do_vfp_nsyn_opcode ("fsqrts");
13132 else
13133 do_vfp_nsyn_opcode ("fsqrtd");
13134}
13135
13136static void
13137do_vfp_nsyn_div (void)
13138{
13139 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13140 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13141 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13142
037e8744
JB
13143 if (rs == NS_FFF)
13144 do_vfp_nsyn_opcode ("fdivs");
13145 else
13146 do_vfp_nsyn_opcode ("fdivd");
13147}
13148
13149static void
13150do_vfp_nsyn_nmul (void)
13151{
13152 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13153 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13154 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13155
037e8744
JB
13156 if (rs == NS_FFF)
13157 {
88714cb8 13158 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13159 do_vfp_sp_dyadic ();
13160 }
13161 else
13162 {
88714cb8 13163 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13164 do_vfp_dp_rd_rn_rm ();
13165 }
13166 do_vfp_cond_or_thumb ();
13167}
13168
13169static void
13170do_vfp_nsyn_cmp (void)
13171{
13172 if (inst.operands[1].isreg)
13173 {
13174 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13175 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13176
037e8744
JB
13177 if (rs == NS_FF)
13178 {
88714cb8 13179 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13180 do_vfp_sp_monadic ();
13181 }
13182 else
13183 {
88714cb8 13184 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13185 do_vfp_dp_rd_rm ();
13186 }
13187 }
13188 else
13189 {
13190 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13191 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13192
13193 switch (inst.instruction & 0x0fffffff)
13194 {
13195 case N_MNEM_vcmp:
13196 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13197 break;
13198 case N_MNEM_vcmpe:
13199 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13200 break;
13201 default:
13202 abort ();
13203 }
5f4273c7 13204
037e8744
JB
13205 if (rs == NS_FI)
13206 {
88714cb8 13207 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13208 do_vfp_sp_compare_z ();
13209 }
13210 else
13211 {
88714cb8 13212 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13213 do_vfp_dp_rd ();
13214 }
13215 }
13216 do_vfp_cond_or_thumb ();
13217}
13218
13219static void
13220nsyn_insert_sp (void)
13221{
13222 inst.operands[1] = inst.operands[0];
13223 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13224 inst.operands[0].reg = REG_SP;
037e8744
JB
13225 inst.operands[0].isreg = 1;
13226 inst.operands[0].writeback = 1;
13227 inst.operands[0].present = 1;
13228}
13229
13230static void
13231do_vfp_nsyn_push (void)
13232{
13233 nsyn_insert_sp ();
13234 if (inst.operands[1].issingle)
13235 do_vfp_nsyn_opcode ("fstmdbs");
13236 else
13237 do_vfp_nsyn_opcode ("fstmdbd");
13238}
13239
13240static void
13241do_vfp_nsyn_pop (void)
13242{
13243 nsyn_insert_sp ();
13244 if (inst.operands[1].issingle)
22b5b651 13245 do_vfp_nsyn_opcode ("fldmias");
037e8744 13246 else
22b5b651 13247 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
13248}
13249
13250/* Fix up Neon data-processing instructions, ORing in the correct bits for
13251 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13252
88714cb8
DG
13253static void
13254neon_dp_fixup (struct arm_it* insn)
037e8744 13255{
88714cb8
DG
13256 unsigned int i = insn->instruction;
13257 insn->is_neon = 1;
13258
037e8744
JB
13259 if (thumb_mode)
13260 {
13261 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13262 if (i & (1 << 24))
13263 i |= 1 << 28;
5f4273c7 13264
037e8744 13265 i &= ~(1 << 24);
5f4273c7 13266
037e8744
JB
13267 i |= 0xef000000;
13268 }
13269 else
13270 i |= 0xf2000000;
5f4273c7 13271
88714cb8 13272 insn->instruction = i;
037e8744
JB
13273}
13274
13275/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13276 (0, 1, 2, 3). */
13277
13278static unsigned
13279neon_logbits (unsigned x)
13280{
13281 return ffs (x) - 4;
13282}
13283
13284#define LOW4(R) ((R) & 0xf)
13285#define HI1(R) (((R) >> 4) & 1)
13286
13287/* Encode insns with bit pattern:
13288
13289 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13290 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 13291
037e8744
JB
13292 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13293 different meaning for some instruction. */
13294
13295static void
13296neon_three_same (int isquad, int ubit, int size)
13297{
13298 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13299 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13300 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13301 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13302 inst.instruction |= LOW4 (inst.operands[2].reg);
13303 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13304 inst.instruction |= (isquad != 0) << 6;
13305 inst.instruction |= (ubit != 0) << 24;
13306 if (size != -1)
13307 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13308
88714cb8 13309 neon_dp_fixup (&inst);
037e8744
JB
13310}
13311
13312/* Encode instructions of the form:
13313
13314 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13315 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
13316
13317 Don't write size if SIZE == -1. */
13318
13319static void
13320neon_two_same (int qbit, int ubit, int size)
13321{
13322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13324 inst.instruction |= LOW4 (inst.operands[1].reg);
13325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13326 inst.instruction |= (qbit != 0) << 6;
13327 inst.instruction |= (ubit != 0) << 24;
13328
13329 if (size != -1)
13330 inst.instruction |= neon_logbits (size) << 18;
13331
88714cb8 13332 neon_dp_fixup (&inst);
5287ad62
JB
13333}
13334
13335/* Neon instruction encoders, in approximate order of appearance. */
13336
13337static void
13338do_neon_dyadic_i_su (void)
13339{
037e8744 13340 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13341 struct neon_type_el et = neon_check_type (3, rs,
13342 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 13343 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13344}
13345
13346static void
13347do_neon_dyadic_i64_su (void)
13348{
037e8744 13349 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13350 struct neon_type_el et = neon_check_type (3, rs,
13351 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 13352 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13353}
13354
13355static void
13356neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13357 unsigned immbits)
13358{
13359 unsigned size = et.size >> 3;
13360 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13361 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13362 inst.instruction |= LOW4 (inst.operands[1].reg);
13363 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13364 inst.instruction |= (isquad != 0) << 6;
13365 inst.instruction |= immbits << 16;
13366 inst.instruction |= (size >> 3) << 7;
13367 inst.instruction |= (size & 0x7) << 19;
13368 if (write_ubit)
13369 inst.instruction |= (uval != 0) << 24;
13370
88714cb8 13371 neon_dp_fixup (&inst);
5287ad62
JB
13372}
13373
13374static void
13375do_neon_shl_imm (void)
13376{
13377 if (!inst.operands[2].isreg)
13378 {
037e8744 13379 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13380 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 13381 NEON_ENCODE (IMMED, inst);
037e8744 13382 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
13383 }
13384 else
13385 {
037e8744 13386 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13387 struct neon_type_el et = neon_check_type (3, rs,
13388 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13389 unsigned int tmp;
13390
13391 /* VSHL/VQSHL 3-register variants have syntax such as:
13392 vshl.xx Dd, Dm, Dn
13393 whereas other 3-register operations encoded by neon_three_same have
13394 syntax like:
13395 vadd.xx Dd, Dn, Dm
13396 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13397 here. */
13398 tmp = inst.operands[2].reg;
13399 inst.operands[2].reg = inst.operands[1].reg;
13400 inst.operands[1].reg = tmp;
88714cb8 13401 NEON_ENCODE (INTEGER, inst);
037e8744 13402 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13403 }
13404}
13405
13406static void
13407do_neon_qshl_imm (void)
13408{
13409 if (!inst.operands[2].isreg)
13410 {
037e8744 13411 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 13412 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 13413
88714cb8 13414 NEON_ENCODE (IMMED, inst);
037e8744 13415 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13416 inst.operands[2].imm);
13417 }
13418 else
13419 {
037e8744 13420 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13421 struct neon_type_el et = neon_check_type (3, rs,
13422 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
13423 unsigned int tmp;
13424
13425 /* See note in do_neon_shl_imm. */
13426 tmp = inst.operands[2].reg;
13427 inst.operands[2].reg = inst.operands[1].reg;
13428 inst.operands[1].reg = tmp;
88714cb8 13429 NEON_ENCODE (INTEGER, inst);
037e8744 13430 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
13431 }
13432}
13433
627907b7
JB
13434static void
13435do_neon_rshl (void)
13436{
13437 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13438 struct neon_type_el et = neon_check_type (3, rs,
13439 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13440 unsigned int tmp;
13441
13442 tmp = inst.operands[2].reg;
13443 inst.operands[2].reg = inst.operands[1].reg;
13444 inst.operands[1].reg = tmp;
13445 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13446}
13447
5287ad62
JB
13448static int
13449neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13450{
036dc3f7
PB
13451 /* Handle .I8 pseudo-instructions. */
13452 if (size == 8)
5287ad62 13453 {
5287ad62
JB
13454 /* Unfortunately, this will make everything apart from zero out-of-range.
13455 FIXME is this the intended semantics? There doesn't seem much point in
13456 accepting .I8 if so. */
13457 immediate |= immediate << 8;
13458 size = 16;
036dc3f7
PB
13459 }
13460
13461 if (size >= 32)
13462 {
13463 if (immediate == (immediate & 0x000000ff))
13464 {
13465 *immbits = immediate;
13466 return 0x1;
13467 }
13468 else if (immediate == (immediate & 0x0000ff00))
13469 {
13470 *immbits = immediate >> 8;
13471 return 0x3;
13472 }
13473 else if (immediate == (immediate & 0x00ff0000))
13474 {
13475 *immbits = immediate >> 16;
13476 return 0x5;
13477 }
13478 else if (immediate == (immediate & 0xff000000))
13479 {
13480 *immbits = immediate >> 24;
13481 return 0x7;
13482 }
13483 if ((immediate & 0xffff) != (immediate >> 16))
13484 goto bad_immediate;
13485 immediate &= 0xffff;
5287ad62
JB
13486 }
13487
13488 if (immediate == (immediate & 0x000000ff))
13489 {
13490 *immbits = immediate;
036dc3f7 13491 return 0x9;
5287ad62
JB
13492 }
13493 else if (immediate == (immediate & 0x0000ff00))
13494 {
13495 *immbits = immediate >> 8;
036dc3f7 13496 return 0xb;
5287ad62
JB
13497 }
13498
13499 bad_immediate:
dcbf9037 13500 first_error (_("immediate value out of range"));
5287ad62
JB
13501 return FAIL;
13502}
13503
13504/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13505 A, B, C, D. */
13506
13507static int
13508neon_bits_same_in_bytes (unsigned imm)
13509{
13510 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13511 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13512 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13513 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13514}
13515
13516/* For immediate of above form, return 0bABCD. */
13517
13518static unsigned
13519neon_squash_bits (unsigned imm)
13520{
13521 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13522 | ((imm & 0x01000000) >> 21);
13523}
13524
136da414 13525/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
13526
13527static unsigned
13528neon_qfloat_bits (unsigned imm)
13529{
136da414 13530 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
13531}
13532
13533/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13534 the instruction. *OP is passed as the initial value of the op field, and
13535 may be set to a different value depending on the constant (i.e.
13536 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 13537 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 13538 try smaller element sizes. */
5287ad62
JB
13539
13540static int
c96612cc
JB
13541neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13542 unsigned *immbits, int *op, int size,
13543 enum neon_el_type type)
5287ad62 13544{
c96612cc
JB
13545 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13546 float. */
13547 if (type == NT_float && !float_p)
13548 return FAIL;
13549
136da414
JB
13550 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13551 {
13552 if (size != 32 || *op == 1)
13553 return FAIL;
13554 *immbits = neon_qfloat_bits (immlo);
13555 return 0xf;
13556 }
036dc3f7
PB
13557
13558 if (size == 64)
5287ad62 13559 {
036dc3f7
PB
13560 if (neon_bits_same_in_bytes (immhi)
13561 && neon_bits_same_in_bytes (immlo))
13562 {
13563 if (*op == 1)
13564 return FAIL;
13565 *immbits = (neon_squash_bits (immhi) << 4)
13566 | neon_squash_bits (immlo);
13567 *op = 1;
13568 return 0xe;
13569 }
13570
13571 if (immhi != immlo)
13572 return FAIL;
5287ad62 13573 }
036dc3f7
PB
13574
13575 if (size >= 32)
5287ad62 13576 {
036dc3f7
PB
13577 if (immlo == (immlo & 0x000000ff))
13578 {
13579 *immbits = immlo;
13580 return 0x0;
13581 }
13582 else if (immlo == (immlo & 0x0000ff00))
13583 {
13584 *immbits = immlo >> 8;
13585 return 0x2;
13586 }
13587 else if (immlo == (immlo & 0x00ff0000))
13588 {
13589 *immbits = immlo >> 16;
13590 return 0x4;
13591 }
13592 else if (immlo == (immlo & 0xff000000))
13593 {
13594 *immbits = immlo >> 24;
13595 return 0x6;
13596 }
13597 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13598 {
13599 *immbits = (immlo >> 8) & 0xff;
13600 return 0xc;
13601 }
13602 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13603 {
13604 *immbits = (immlo >> 16) & 0xff;
13605 return 0xd;
13606 }
13607
13608 if ((immlo & 0xffff) != (immlo >> 16))
13609 return FAIL;
13610 immlo &= 0xffff;
5287ad62 13611 }
036dc3f7
PB
13612
13613 if (size >= 16)
5287ad62 13614 {
036dc3f7
PB
13615 if (immlo == (immlo & 0x000000ff))
13616 {
13617 *immbits = immlo;
13618 return 0x8;
13619 }
13620 else if (immlo == (immlo & 0x0000ff00))
13621 {
13622 *immbits = immlo >> 8;
13623 return 0xa;
13624 }
13625
13626 if ((immlo & 0xff) != (immlo >> 8))
13627 return FAIL;
13628 immlo &= 0xff;
5287ad62 13629 }
036dc3f7
PB
13630
13631 if (immlo == (immlo & 0x000000ff))
5287ad62 13632 {
036dc3f7
PB
13633 /* Don't allow MVN with 8-bit immediate. */
13634 if (*op == 1)
13635 return FAIL;
13636 *immbits = immlo;
13637 return 0xe;
5287ad62 13638 }
5287ad62
JB
13639
13640 return FAIL;
13641}
13642
13643/* Write immediate bits [7:0] to the following locations:
13644
13645 |28/24|23 19|18 16|15 4|3 0|
13646 | 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|
13647
13648 This function is used by VMOV/VMVN/VORR/VBIC. */
13649
13650static void
13651neon_write_immbits (unsigned immbits)
13652{
13653 inst.instruction |= immbits & 0xf;
13654 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13655 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13656}
13657
13658/* Invert low-order SIZE bits of XHI:XLO. */
13659
13660static void
13661neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13662{
13663 unsigned immlo = xlo ? *xlo : 0;
13664 unsigned immhi = xhi ? *xhi : 0;
13665
13666 switch (size)
13667 {
13668 case 8:
13669 immlo = (~immlo) & 0xff;
13670 break;
13671
13672 case 16:
13673 immlo = (~immlo) & 0xffff;
13674 break;
13675
13676 case 64:
13677 immhi = (~immhi) & 0xffffffff;
13678 /* fall through. */
13679
13680 case 32:
13681 immlo = (~immlo) & 0xffffffff;
13682 break;
13683
13684 default:
13685 abort ();
13686 }
13687
13688 if (xlo)
13689 *xlo = immlo;
13690
13691 if (xhi)
13692 *xhi = immhi;
13693}
13694
13695static void
13696do_neon_logic (void)
13697{
13698 if (inst.operands[2].present && inst.operands[2].isreg)
13699 {
037e8744 13700 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13701 neon_check_type (3, rs, N_IGNORE_TYPE);
13702 /* U bit and size field were set as part of the bitmask. */
88714cb8 13703 NEON_ENCODE (INTEGER, inst);
037e8744 13704 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13705 }
13706 else
13707 {
4316f0d2
DG
13708 const int three_ops_form = (inst.operands[2].present
13709 && !inst.operands[2].isreg);
13710 const int immoperand = (three_ops_form ? 2 : 1);
13711 enum neon_shape rs = (three_ops_form
13712 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13713 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13714 struct neon_type_el et = neon_check_type (2, rs,
13715 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13716 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13717 unsigned immbits;
13718 int cmode;
5f4273c7 13719
5287ad62
JB
13720 if (et.type == NT_invtype)
13721 return;
5f4273c7 13722
4316f0d2
DG
13723 if (three_ops_form)
13724 constraint (inst.operands[0].reg != inst.operands[1].reg,
13725 _("first and second operands shall be the same register"));
13726
88714cb8 13727 NEON_ENCODE (IMMED, inst);
5287ad62 13728
4316f0d2 13729 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13730 if (et.size == 64)
13731 {
13732 /* .i64 is a pseudo-op, so the immediate must be a repeating
13733 pattern. */
4316f0d2
DG
13734 if (immbits != (inst.operands[immoperand].regisimm ?
13735 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13736 {
13737 /* Set immbits to an invalid constant. */
13738 immbits = 0xdeadbeef;
13739 }
13740 }
13741
5287ad62
JB
13742 switch (opcode)
13743 {
13744 case N_MNEM_vbic:
036dc3f7 13745 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13746 break;
5f4273c7 13747
5287ad62 13748 case N_MNEM_vorr:
036dc3f7 13749 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13750 break;
5f4273c7 13751
5287ad62
JB
13752 case N_MNEM_vand:
13753 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13754 neon_invert_size (&immbits, 0, et.size);
13755 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13756 break;
5f4273c7 13757
5287ad62
JB
13758 case N_MNEM_vorn:
13759 /* Pseudo-instruction for VORR. */
5287ad62
JB
13760 neon_invert_size (&immbits, 0, et.size);
13761 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13762 break;
5f4273c7 13763
5287ad62
JB
13764 default:
13765 abort ();
13766 }
13767
13768 if (cmode == FAIL)
13769 return;
13770
037e8744 13771 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13772 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13773 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13774 inst.instruction |= cmode << 8;
13775 neon_write_immbits (immbits);
5f4273c7 13776
88714cb8 13777 neon_dp_fixup (&inst);
5287ad62
JB
13778 }
13779}
13780
13781static void
13782do_neon_bitfield (void)
13783{
037e8744 13784 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13785 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13786 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13787}
13788
13789static void
dcbf9037
JB
13790neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13791 unsigned destbits)
5287ad62 13792{
037e8744 13793 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13794 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13795 types | N_KEY);
5287ad62
JB
13796 if (et.type == NT_float)
13797 {
88714cb8 13798 NEON_ENCODE (FLOAT, inst);
037e8744 13799 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13800 }
13801 else
13802 {
88714cb8 13803 NEON_ENCODE (INTEGER, inst);
037e8744 13804 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13805 }
13806}
13807
13808static void
13809do_neon_dyadic_if_su (void)
13810{
dcbf9037 13811 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13812}
13813
13814static void
13815do_neon_dyadic_if_su_d (void)
13816{
13817 /* This version only allow D registers, but that constraint is enforced during
13818 operand parsing so we don't need to do anything extra here. */
dcbf9037 13819 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13820}
13821
5287ad62
JB
13822static void
13823do_neon_dyadic_if_i_d (void)
13824{
428e3f1f
PB
13825 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13826 affected if we specify unsigned args. */
13827 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13828}
13829
037e8744
JB
13830enum vfp_or_neon_is_neon_bits
13831{
13832 NEON_CHECK_CC = 1,
13833 NEON_CHECK_ARCH = 2
13834};
13835
13836/* Call this function if an instruction which may have belonged to the VFP or
13837 Neon instruction sets, but turned out to be a Neon instruction (due to the
13838 operand types involved, etc.). We have to check and/or fix-up a couple of
13839 things:
13840
13841 - Make sure the user hasn't attempted to make a Neon instruction
13842 conditional.
13843 - Alter the value in the condition code field if necessary.
13844 - Make sure that the arch supports Neon instructions.
13845
13846 Which of these operations take place depends on bits from enum
13847 vfp_or_neon_is_neon_bits.
13848
13849 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13850 current instruction's condition is COND_ALWAYS, the condition field is
13851 changed to inst.uncond_value. This is necessary because instructions shared
13852 between VFP and Neon may be conditional for the VFP variants only, and the
13853 unconditional Neon version must have, e.g., 0xF in the condition field. */
13854
13855static int
13856vfp_or_neon_is_neon (unsigned check)
13857{
13858 /* Conditions are always legal in Thumb mode (IT blocks). */
13859 if (!thumb_mode && (check & NEON_CHECK_CC))
13860 {
13861 if (inst.cond != COND_ALWAYS)
13862 {
13863 first_error (_(BAD_COND));
13864 return FAIL;
13865 }
13866 if (inst.uncond_value != -1)
13867 inst.instruction |= inst.uncond_value << 28;
13868 }
5f4273c7 13869
037e8744
JB
13870 if ((check & NEON_CHECK_ARCH)
13871 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13872 {
13873 first_error (_(BAD_FPU));
13874 return FAIL;
13875 }
5f4273c7 13876
037e8744
JB
13877 return SUCCESS;
13878}
13879
5287ad62
JB
13880static void
13881do_neon_addsub_if_i (void)
13882{
037e8744
JB
13883 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13884 return;
13885
13886 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13887 return;
13888
5287ad62
JB
13889 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13890 affected if we specify unsigned args. */
dcbf9037 13891 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13892}
13893
13894/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13895 result to be:
13896 V<op> A,B (A is operand 0, B is operand 2)
13897 to mean:
13898 V<op> A,B,A
13899 not:
13900 V<op> A,B,B
13901 so handle that case specially. */
13902
13903static void
13904neon_exchange_operands (void)
13905{
13906 void *scratch = alloca (sizeof (inst.operands[0]));
13907 if (inst.operands[1].present)
13908 {
13909 /* Swap operands[1] and operands[2]. */
13910 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13911 inst.operands[1] = inst.operands[2];
13912 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13913 }
13914 else
13915 {
13916 inst.operands[1] = inst.operands[2];
13917 inst.operands[2] = inst.operands[0];
13918 }
13919}
13920
13921static void
13922neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13923{
13924 if (inst.operands[2].isreg)
13925 {
13926 if (invert)
13927 neon_exchange_operands ();
dcbf9037 13928 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13929 }
13930 else
13931 {
037e8744 13932 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13933 struct neon_type_el et = neon_check_type (2, rs,
13934 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13935
88714cb8 13936 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13937 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13938 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13939 inst.instruction |= LOW4 (inst.operands[1].reg);
13940 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13941 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13942 inst.instruction |= (et.type == NT_float) << 10;
13943 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13944
88714cb8 13945 neon_dp_fixup (&inst);
5287ad62
JB
13946 }
13947}
13948
13949static void
13950do_neon_cmp (void)
13951{
13952 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13953}
13954
13955static void
13956do_neon_cmp_inv (void)
13957{
13958 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13959}
13960
13961static void
13962do_neon_ceq (void)
13963{
13964 neon_compare (N_IF_32, N_IF_32, FALSE);
13965}
13966
13967/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13968 scalars, which are encoded in 5 bits, M : Rm.
13969 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13970 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13971 index in M. */
13972
13973static unsigned
13974neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13975{
dcbf9037
JB
13976 unsigned regno = NEON_SCALAR_REG (scalar);
13977 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13978
13979 switch (elsize)
13980 {
13981 case 16:
13982 if (regno > 7 || elno > 3)
13983 goto bad_scalar;
13984 return regno | (elno << 3);
5f4273c7 13985
5287ad62
JB
13986 case 32:
13987 if (regno > 15 || elno > 1)
13988 goto bad_scalar;
13989 return regno | (elno << 4);
13990
13991 default:
13992 bad_scalar:
dcbf9037 13993 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13994 }
13995
13996 return 0;
13997}
13998
13999/* Encode multiply / multiply-accumulate scalar instructions. */
14000
14001static void
14002neon_mul_mac (struct neon_type_el et, int ubit)
14003{
dcbf9037
JB
14004 unsigned scalar;
14005
14006 /* Give a more helpful error message if we have an invalid type. */
14007 if (et.type == NT_invtype)
14008 return;
5f4273c7 14009
dcbf9037 14010 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14013 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14014 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14015 inst.instruction |= LOW4 (scalar);
14016 inst.instruction |= HI1 (scalar) << 5;
14017 inst.instruction |= (et.type == NT_float) << 8;
14018 inst.instruction |= neon_logbits (et.size) << 20;
14019 inst.instruction |= (ubit != 0) << 24;
14020
88714cb8 14021 neon_dp_fixup (&inst);
5287ad62
JB
14022}
14023
14024static void
14025do_neon_mac_maybe_scalar (void)
14026{
037e8744
JB
14027 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14028 return;
14029
14030 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14031 return;
14032
5287ad62
JB
14033 if (inst.operands[2].isscalar)
14034 {
037e8744 14035 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14036 struct neon_type_el et = neon_check_type (3, rs,
14037 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14038 NEON_ENCODE (SCALAR, inst);
037e8744 14039 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14040 }
14041 else
428e3f1f
PB
14042 {
14043 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14044 affected if we specify unsigned args. */
14045 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14046 }
5287ad62
JB
14047}
14048
62f3b8c8
PB
14049static void
14050do_neon_fmac (void)
14051{
14052 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14053 return;
14054
14055 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14056 return;
14057
14058 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14059}
14060
5287ad62
JB
14061static void
14062do_neon_tst (void)
14063{
037e8744 14064 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14065 struct neon_type_el et = neon_check_type (3, rs,
14066 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14067 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14068}
14069
14070/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14071 same types as the MAC equivalents. The polynomial type for this instruction
14072 is encoded the same as the integer type. */
14073
14074static void
14075do_neon_mul (void)
14076{
037e8744
JB
14077 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14078 return;
14079
14080 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14081 return;
14082
5287ad62
JB
14083 if (inst.operands[2].isscalar)
14084 do_neon_mac_maybe_scalar ();
14085 else
dcbf9037 14086 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14087}
14088
14089static void
14090do_neon_qdmulh (void)
14091{
14092 if (inst.operands[2].isscalar)
14093 {
037e8744 14094 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
14095 struct neon_type_el et = neon_check_type (3, rs,
14096 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14097 NEON_ENCODE (SCALAR, inst);
037e8744 14098 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14099 }
14100 else
14101 {
037e8744 14102 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14103 struct neon_type_el et = neon_check_type (3, rs,
14104 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14105 NEON_ENCODE (INTEGER, inst);
5287ad62 14106 /* The U bit (rounding) comes from bit mask. */
037e8744 14107 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14108 }
14109}
14110
14111static void
14112do_neon_fcmp_absolute (void)
14113{
037e8744 14114 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14115 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14116 /* Size field comes from bit mask. */
037e8744 14117 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14118}
14119
14120static void
14121do_neon_fcmp_absolute_inv (void)
14122{
14123 neon_exchange_operands ();
14124 do_neon_fcmp_absolute ();
14125}
14126
14127static void
14128do_neon_step (void)
14129{
037e8744 14130 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14131 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14132 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14133}
14134
14135static void
14136do_neon_abs_neg (void)
14137{
037e8744
JB
14138 enum neon_shape rs;
14139 struct neon_type_el et;
5f4273c7 14140
037e8744
JB
14141 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14142 return;
14143
14144 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14145 return;
14146
14147 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14148 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14149
5287ad62
JB
14150 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14151 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14152 inst.instruction |= LOW4 (inst.operands[1].reg);
14153 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14154 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14155 inst.instruction |= (et.type == NT_float) << 10;
14156 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14157
88714cb8 14158 neon_dp_fixup (&inst);
5287ad62
JB
14159}
14160
14161static void
14162do_neon_sli (void)
14163{
037e8744 14164 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14165 struct neon_type_el et = neon_check_type (2, rs,
14166 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14167 int imm = inst.operands[2].imm;
14168 constraint (imm < 0 || (unsigned)imm >= et.size,
14169 _("immediate out of range for insert"));
037e8744 14170 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14171}
14172
14173static void
14174do_neon_sri (void)
14175{
037e8744 14176 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14177 struct neon_type_el et = neon_check_type (2, rs,
14178 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14179 int imm = inst.operands[2].imm;
14180 constraint (imm < 1 || (unsigned)imm > et.size,
14181 _("immediate out of range for insert"));
037e8744 14182 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14183}
14184
14185static void
14186do_neon_qshlu_imm (void)
14187{
037e8744 14188 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14189 struct neon_type_el et = neon_check_type (2, rs,
14190 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14191 int imm = inst.operands[2].imm;
14192 constraint (imm < 0 || (unsigned)imm >= et.size,
14193 _("immediate out of range for shift"));
14194 /* Only encodes the 'U present' variant of the instruction.
14195 In this case, signed types have OP (bit 8) set to 0.
14196 Unsigned types have OP set to 1. */
14197 inst.instruction |= (et.type == NT_unsigned) << 8;
14198 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14199 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14200}
14201
14202static void
14203do_neon_qmovn (void)
14204{
14205 struct neon_type_el et = neon_check_type (2, NS_DQ,
14206 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14207 /* Saturating move where operands can be signed or unsigned, and the
14208 destination has the same signedness. */
88714cb8 14209 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14210 if (et.type == NT_unsigned)
14211 inst.instruction |= 0xc0;
14212 else
14213 inst.instruction |= 0x80;
14214 neon_two_same (0, 1, et.size / 2);
14215}
14216
14217static void
14218do_neon_qmovun (void)
14219{
14220 struct neon_type_el et = neon_check_type (2, NS_DQ,
14221 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14222 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14223 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14224 neon_two_same (0, 1, et.size / 2);
14225}
14226
14227static void
14228do_neon_rshift_sat_narrow (void)
14229{
14230 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14231 or unsigned. If operands are unsigned, results must also be unsigned. */
14232 struct neon_type_el et = neon_check_type (2, NS_DQI,
14233 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14234 int imm = inst.operands[2].imm;
14235 /* This gets the bounds check, size encoding and immediate bits calculation
14236 right. */
14237 et.size /= 2;
5f4273c7 14238
5287ad62
JB
14239 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14240 VQMOVN.I<size> <Dd>, <Qm>. */
14241 if (imm == 0)
14242 {
14243 inst.operands[2].present = 0;
14244 inst.instruction = N_MNEM_vqmovn;
14245 do_neon_qmovn ();
14246 return;
14247 }
5f4273c7 14248
5287ad62
JB
14249 constraint (imm < 1 || (unsigned)imm > et.size,
14250 _("immediate out of range"));
14251 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14252}
14253
14254static void
14255do_neon_rshift_sat_narrow_u (void)
14256{
14257 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14258 or unsigned. If operands are unsigned, results must also be unsigned. */
14259 struct neon_type_el et = neon_check_type (2, NS_DQI,
14260 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14261 int imm = inst.operands[2].imm;
14262 /* This gets the bounds check, size encoding and immediate bits calculation
14263 right. */
14264 et.size /= 2;
14265
14266 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14267 VQMOVUN.I<size> <Dd>, <Qm>. */
14268 if (imm == 0)
14269 {
14270 inst.operands[2].present = 0;
14271 inst.instruction = N_MNEM_vqmovun;
14272 do_neon_qmovun ();
14273 return;
14274 }
14275
14276 constraint (imm < 1 || (unsigned)imm > et.size,
14277 _("immediate out of range"));
14278 /* FIXME: The manual is kind of unclear about what value U should have in
14279 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14280 must be 1. */
14281 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14282}
14283
14284static void
14285do_neon_movn (void)
14286{
14287 struct neon_type_el et = neon_check_type (2, NS_DQ,
14288 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14289 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14290 neon_two_same (0, 1, et.size / 2);
14291}
14292
14293static void
14294do_neon_rshift_narrow (void)
14295{
14296 struct neon_type_el et = neon_check_type (2, NS_DQI,
14297 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14298 int imm = inst.operands[2].imm;
14299 /* This gets the bounds check, size encoding and immediate bits calculation
14300 right. */
14301 et.size /= 2;
5f4273c7 14302
5287ad62
JB
14303 /* If immediate is zero then we are a pseudo-instruction for
14304 VMOVN.I<size> <Dd>, <Qm> */
14305 if (imm == 0)
14306 {
14307 inst.operands[2].present = 0;
14308 inst.instruction = N_MNEM_vmovn;
14309 do_neon_movn ();
14310 return;
14311 }
5f4273c7 14312
5287ad62
JB
14313 constraint (imm < 1 || (unsigned)imm > et.size,
14314 _("immediate out of range for narrowing operation"));
14315 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14316}
14317
14318static void
14319do_neon_shll (void)
14320{
14321 /* FIXME: Type checking when lengthening. */
14322 struct neon_type_el et = neon_check_type (2, NS_QDI,
14323 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14324 unsigned imm = inst.operands[2].imm;
14325
14326 if (imm == et.size)
14327 {
14328 /* Maximum shift variant. */
88714cb8 14329 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14330 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14331 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14332 inst.instruction |= LOW4 (inst.operands[1].reg);
14333 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14334 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14335
88714cb8 14336 neon_dp_fixup (&inst);
5287ad62
JB
14337 }
14338 else
14339 {
14340 /* A more-specific type check for non-max versions. */
14341 et = neon_check_type (2, NS_QDI,
14342 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14343 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14344 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14345 }
14346}
14347
037e8744 14348/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14349 the current instruction is. */
14350
14351static int
14352neon_cvt_flavour (enum neon_shape rs)
14353{
037e8744
JB
14354#define CVT_VAR(C,X,Y) \
14355 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14356 if (et.type != NT_invtype) \
14357 { \
14358 inst.error = NULL; \
14359 return (C); \
5287ad62
JB
14360 }
14361 struct neon_type_el et;
037e8744
JB
14362 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14363 || rs == NS_FF) ? N_VFP : 0;
14364 /* The instruction versions which take an immediate take one register
14365 argument, which is extended to the width of the full register. Thus the
14366 "source" and "destination" registers must have the same width. Hack that
14367 here by making the size equal to the key (wider, in this case) operand. */
14368 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 14369
5287ad62
JB
14370 CVT_VAR (0, N_S32, N_F32);
14371 CVT_VAR (1, N_U32, N_F32);
14372 CVT_VAR (2, N_F32, N_S32);
14373 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
14374 /* Half-precision conversions. */
14375 CVT_VAR (4, N_F32, N_F16);
14376 CVT_VAR (5, N_F16, N_F32);
5f4273c7 14377
037e8744 14378 whole_reg = N_VFP;
5f4273c7 14379
037e8744 14380 /* VFP instructions. */
8e79c3df
CM
14381 CVT_VAR (6, N_F32, N_F64);
14382 CVT_VAR (7, N_F64, N_F32);
14383 CVT_VAR (8, N_S32, N_F64 | key);
14384 CVT_VAR (9, N_U32, N_F64 | key);
14385 CVT_VAR (10, N_F64 | key, N_S32);
14386 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 14387 /* VFP instructions with bitshift. */
8e79c3df
CM
14388 CVT_VAR (12, N_F32 | key, N_S16);
14389 CVT_VAR (13, N_F32 | key, N_U16);
14390 CVT_VAR (14, N_F64 | key, N_S16);
14391 CVT_VAR (15, N_F64 | key, N_U16);
14392 CVT_VAR (16, N_S16, N_F32 | key);
14393 CVT_VAR (17, N_U16, N_F32 | key);
14394 CVT_VAR (18, N_S16, N_F64 | key);
14395 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 14396
5287ad62
JB
14397 return -1;
14398#undef CVT_VAR
14399}
14400
037e8744
JB
14401/* Neon-syntax VFP conversions. */
14402
5287ad62 14403static void
037e8744 14404do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 14405{
037e8744 14406 const char *opname = 0;
5f4273c7 14407
037e8744 14408 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 14409 {
037e8744
JB
14410 /* Conversions with immediate bitshift. */
14411 const char *enc[] =
14412 {
14413 "ftosls",
14414 "ftouls",
14415 "fsltos",
14416 "fultos",
14417 NULL,
14418 NULL,
8e79c3df
CM
14419 NULL,
14420 NULL,
037e8744
JB
14421 "ftosld",
14422 "ftould",
14423 "fsltod",
14424 "fultod",
14425 "fshtos",
14426 "fuhtos",
14427 "fshtod",
14428 "fuhtod",
14429 "ftoshs",
14430 "ftouhs",
14431 "ftoshd",
14432 "ftouhd"
14433 };
14434
14435 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14436 {
14437 opname = enc[flavour];
14438 constraint (inst.operands[0].reg != inst.operands[1].reg,
14439 _("operands 0 and 1 must be the same register"));
14440 inst.operands[1] = inst.operands[2];
14441 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14442 }
5287ad62
JB
14443 }
14444 else
14445 {
037e8744
JB
14446 /* Conversions without bitshift. */
14447 const char *enc[] =
14448 {
14449 "ftosis",
14450 "ftouis",
14451 "fsitos",
14452 "fuitos",
8e79c3df
CM
14453 "NULL",
14454 "NULL",
037e8744
JB
14455 "fcvtsd",
14456 "fcvtds",
14457 "ftosid",
14458 "ftouid",
14459 "fsitod",
14460 "fuitod"
14461 };
14462
14463 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14464 opname = enc[flavour];
14465 }
14466
14467 if (opname)
14468 do_vfp_nsyn_opcode (opname);
14469}
14470
14471static void
14472do_vfp_nsyn_cvtz (void)
14473{
14474 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14475 int flavour = neon_cvt_flavour (rs);
14476 const char *enc[] =
14477 {
14478 "ftosizs",
14479 "ftouizs",
14480 NULL,
14481 NULL,
14482 NULL,
14483 NULL,
8e79c3df
CM
14484 NULL,
14485 NULL,
037e8744
JB
14486 "ftosizd",
14487 "ftouizd"
14488 };
14489
14490 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14491 do_vfp_nsyn_opcode (enc[flavour]);
14492}
f31fef98 14493
037e8744 14494static void
e3e535bc 14495do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
14496{
14497 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 14498 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
14499 int flavour = neon_cvt_flavour (rs);
14500
e3e535bc
NC
14501 /* PR11109: Handle round-to-zero for VCVT conversions. */
14502 if (round_to_zero
14503 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14504 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14505 && (rs == NS_FD || rs == NS_FF))
14506 {
14507 do_vfp_nsyn_cvtz ();
14508 return;
14509 }
14510
037e8744 14511 /* VFP rather than Neon conversions. */
8e79c3df 14512 if (flavour >= 6)
037e8744
JB
14513 {
14514 do_vfp_nsyn_cvt (rs, flavour);
14515 return;
14516 }
14517
14518 switch (rs)
14519 {
14520 case NS_DDI:
14521 case NS_QQI:
14522 {
35997600
NC
14523 unsigned immbits;
14524 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14525
037e8744
JB
14526 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14527 return;
14528
14529 /* Fixed-point conversion with #0 immediate is encoded as an
14530 integer conversion. */
14531 if (inst.operands[2].present && inst.operands[2].imm == 0)
14532 goto int_encode;
35997600 14533 immbits = 32 - inst.operands[2].imm;
88714cb8 14534 NEON_ENCODE (IMMED, inst);
037e8744
JB
14535 if (flavour != -1)
14536 inst.instruction |= enctab[flavour];
14537 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14538 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14539 inst.instruction |= LOW4 (inst.operands[1].reg);
14540 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14541 inst.instruction |= neon_quad (rs) << 6;
14542 inst.instruction |= 1 << 21;
14543 inst.instruction |= immbits << 16;
14544
88714cb8 14545 neon_dp_fixup (&inst);
037e8744
JB
14546 }
14547 break;
14548
14549 case NS_DD:
14550 case NS_QQ:
14551 int_encode:
14552 {
14553 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14554
88714cb8 14555 NEON_ENCODE (INTEGER, inst);
037e8744
JB
14556
14557 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14558 return;
14559
14560 if (flavour != -1)
14561 inst.instruction |= enctab[flavour];
14562
14563 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14564 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14565 inst.instruction |= LOW4 (inst.operands[1].reg);
14566 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14567 inst.instruction |= neon_quad (rs) << 6;
14568 inst.instruction |= 2 << 18;
14569
88714cb8 14570 neon_dp_fixup (&inst);
037e8744
JB
14571 }
14572 break;
14573
8e79c3df
CM
14574 /* Half-precision conversions for Advanced SIMD -- neon. */
14575 case NS_QD:
14576 case NS_DQ:
14577
14578 if ((rs == NS_DQ)
14579 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14580 {
14581 as_bad (_("operand size must match register width"));
14582 break;
14583 }
14584
14585 if ((rs == NS_QD)
14586 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14587 {
14588 as_bad (_("operand size must match register width"));
14589 break;
14590 }
14591
14592 if (rs == NS_DQ)
14593 inst.instruction = 0x3b60600;
14594 else
14595 inst.instruction = 0x3b60700;
14596
14597 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14598 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14599 inst.instruction |= LOW4 (inst.operands[1].reg);
14600 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 14601 neon_dp_fixup (&inst);
8e79c3df
CM
14602 break;
14603
037e8744
JB
14604 default:
14605 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14606 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 14607 }
5287ad62
JB
14608}
14609
e3e535bc
NC
14610static void
14611do_neon_cvtr (void)
14612{
14613 do_neon_cvt_1 (FALSE);
14614}
14615
14616static void
14617do_neon_cvt (void)
14618{
14619 do_neon_cvt_1 (TRUE);
14620}
14621
8e79c3df
CM
14622static void
14623do_neon_cvtb (void)
14624{
14625 inst.instruction = 0xeb20a40;
14626
14627 /* The sizes are attached to the mnemonic. */
14628 if (inst.vectype.el[0].type != NT_invtype
14629 && inst.vectype.el[0].size == 16)
14630 inst.instruction |= 0x00010000;
14631
14632 /* Programmer's syntax: the sizes are attached to the operands. */
14633 else if (inst.operands[0].vectype.type != NT_invtype
14634 && inst.operands[0].vectype.size == 16)
14635 inst.instruction |= 0x00010000;
14636
14637 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14638 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14639 do_vfp_cond_or_thumb ();
14640}
14641
14642
14643static void
14644do_neon_cvtt (void)
14645{
14646 do_neon_cvtb ();
14647 inst.instruction |= 0x80;
14648}
14649
5287ad62
JB
14650static void
14651neon_move_immediate (void)
14652{
037e8744
JB
14653 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14654 struct neon_type_el et = neon_check_type (2, rs,
14655 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 14656 unsigned immlo, immhi = 0, immbits;
c96612cc 14657 int op, cmode, float_p;
5287ad62 14658
037e8744
JB
14659 constraint (et.type == NT_invtype,
14660 _("operand size must be specified for immediate VMOV"));
14661
5287ad62
JB
14662 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14663 op = (inst.instruction & (1 << 5)) != 0;
14664
14665 immlo = inst.operands[1].imm;
14666 if (inst.operands[1].regisimm)
14667 immhi = inst.operands[1].reg;
14668
14669 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14670 _("immediate has bits set outside the operand size"));
14671
c96612cc
JB
14672 float_p = inst.operands[1].immisfloat;
14673
14674 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 14675 et.size, et.type)) == FAIL)
5287ad62
JB
14676 {
14677 /* Invert relevant bits only. */
14678 neon_invert_size (&immlo, &immhi, et.size);
14679 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14680 with one or the other; those cases are caught by
14681 neon_cmode_for_move_imm. */
14682 op = !op;
c96612cc
JB
14683 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14684 &op, et.size, et.type)) == FAIL)
5287ad62 14685 {
dcbf9037 14686 first_error (_("immediate out of range"));
5287ad62
JB
14687 return;
14688 }
14689 }
14690
14691 inst.instruction &= ~(1 << 5);
14692 inst.instruction |= op << 5;
14693
14694 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14695 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 14696 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14697 inst.instruction |= cmode << 8;
14698
14699 neon_write_immbits (immbits);
14700}
14701
14702static void
14703do_neon_mvn (void)
14704{
14705 if (inst.operands[1].isreg)
14706 {
037e8744 14707 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 14708
88714cb8 14709 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14710 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14711 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14712 inst.instruction |= LOW4 (inst.operands[1].reg);
14713 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14714 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14715 }
14716 else
14717 {
88714cb8 14718 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14719 neon_move_immediate ();
14720 }
14721
88714cb8 14722 neon_dp_fixup (&inst);
5287ad62
JB
14723}
14724
14725/* Encode instructions of form:
14726
14727 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14728 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14729
14730static void
14731neon_mixed_length (struct neon_type_el et, unsigned size)
14732{
14733 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14734 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14735 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14736 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14737 inst.instruction |= LOW4 (inst.operands[2].reg);
14738 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14739 inst.instruction |= (et.type == NT_unsigned) << 24;
14740 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14741
88714cb8 14742 neon_dp_fixup (&inst);
5287ad62
JB
14743}
14744
14745static void
14746do_neon_dyadic_long (void)
14747{
14748 /* FIXME: Type checking for lengthening op. */
14749 struct neon_type_el et = neon_check_type (3, NS_QDD,
14750 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14751 neon_mixed_length (et, et.size);
14752}
14753
14754static void
14755do_neon_abal (void)
14756{
14757 struct neon_type_el et = neon_check_type (3, NS_QDD,
14758 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14759 neon_mixed_length (et, et.size);
14760}
14761
14762static void
14763neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14764{
14765 if (inst.operands[2].isscalar)
14766 {
dcbf9037
JB
14767 struct neon_type_el et = neon_check_type (3, NS_QDS,
14768 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14769 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14770 neon_mul_mac (et, et.type == NT_unsigned);
14771 }
14772 else
14773 {
14774 struct neon_type_el et = neon_check_type (3, NS_QDD,
14775 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14776 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14777 neon_mixed_length (et, et.size);
14778 }
14779}
14780
14781static void
14782do_neon_mac_maybe_scalar_long (void)
14783{
14784 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14785}
14786
14787static void
14788do_neon_dyadic_wide (void)
14789{
14790 struct neon_type_el et = neon_check_type (3, NS_QQD,
14791 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14792 neon_mixed_length (et, et.size);
14793}
14794
14795static void
14796do_neon_dyadic_narrow (void)
14797{
14798 struct neon_type_el et = neon_check_type (3, NS_QDD,
14799 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14800 /* Operand sign is unimportant, and the U bit is part of the opcode,
14801 so force the operand type to integer. */
14802 et.type = NT_integer;
5287ad62
JB
14803 neon_mixed_length (et, et.size / 2);
14804}
14805
14806static void
14807do_neon_mul_sat_scalar_long (void)
14808{
14809 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14810}
14811
14812static void
14813do_neon_vmull (void)
14814{
14815 if (inst.operands[2].isscalar)
14816 do_neon_mac_maybe_scalar_long ();
14817 else
14818 {
14819 struct neon_type_el et = neon_check_type (3, NS_QDD,
14820 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14821 if (et.type == NT_poly)
88714cb8 14822 NEON_ENCODE (POLY, inst);
5287ad62 14823 else
88714cb8 14824 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14825 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14826 zero. Should be OK as-is. */
14827 neon_mixed_length (et, et.size);
14828 }
14829}
14830
14831static void
14832do_neon_ext (void)
14833{
037e8744 14834 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14835 struct neon_type_el et = neon_check_type (3, rs,
14836 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14837 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14838
14839 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14840 _("shift out of range"));
5287ad62
JB
14841 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14842 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14843 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14844 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14845 inst.instruction |= LOW4 (inst.operands[2].reg);
14846 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14847 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14848 inst.instruction |= imm << 8;
5f4273c7 14849
88714cb8 14850 neon_dp_fixup (&inst);
5287ad62
JB
14851}
14852
14853static void
14854do_neon_rev (void)
14855{
037e8744 14856 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14857 struct neon_type_el et = neon_check_type (2, rs,
14858 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14859 unsigned op = (inst.instruction >> 7) & 3;
14860 /* N (width of reversed regions) is encoded as part of the bitmask. We
14861 extract it here to check the elements to be reversed are smaller.
14862 Otherwise we'd get a reserved instruction. */
14863 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14864 gas_assert (elsize != 0);
5287ad62
JB
14865 constraint (et.size >= elsize,
14866 _("elements must be smaller than reversal region"));
037e8744 14867 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14868}
14869
14870static void
14871do_neon_dup (void)
14872{
14873 if (inst.operands[1].isscalar)
14874 {
037e8744 14875 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14876 struct neon_type_el et = neon_check_type (2, rs,
14877 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14878 unsigned sizebits = et.size >> 3;
dcbf9037 14879 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14880 int logsize = neon_logbits (et.size);
dcbf9037 14881 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14882
14883 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14884 return;
14885
88714cb8 14886 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14887 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14888 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14889 inst.instruction |= LOW4 (dm);
14890 inst.instruction |= HI1 (dm) << 5;
037e8744 14891 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14892 inst.instruction |= x << 17;
14893 inst.instruction |= sizebits << 16;
5f4273c7 14894
88714cb8 14895 neon_dp_fixup (&inst);
5287ad62
JB
14896 }
14897 else
14898 {
037e8744
JB
14899 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14900 struct neon_type_el et = neon_check_type (2, rs,
14901 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14902 /* Duplicate ARM register to lanes of vector. */
88714cb8 14903 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14904 switch (et.size)
14905 {
14906 case 8: inst.instruction |= 0x400000; break;
14907 case 16: inst.instruction |= 0x000020; break;
14908 case 32: inst.instruction |= 0x000000; break;
14909 default: break;
14910 }
14911 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14912 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14913 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14914 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14915 /* The encoding for this instruction is identical for the ARM and Thumb
14916 variants, except for the condition field. */
037e8744 14917 do_vfp_cond_or_thumb ();
5287ad62
JB
14918 }
14919}
14920
14921/* VMOV has particularly many variations. It can be one of:
14922 0. VMOV<c><q> <Qd>, <Qm>
14923 1. VMOV<c><q> <Dd>, <Dm>
14924 (Register operations, which are VORR with Rm = Rn.)
14925 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14926 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14927 (Immediate loads.)
14928 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14929 (ARM register to scalar.)
14930 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14931 (Two ARM registers to vector.)
14932 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14933 (Scalar to ARM register.)
14934 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14935 (Vector to two ARM registers.)
037e8744
JB
14936 8. VMOV.F32 <Sd>, <Sm>
14937 9. VMOV.F64 <Dd>, <Dm>
14938 (VFP register moves.)
14939 10. VMOV.F32 <Sd>, #imm
14940 11. VMOV.F64 <Dd>, #imm
14941 (VFP float immediate load.)
14942 12. VMOV <Rd>, <Sm>
14943 (VFP single to ARM reg.)
14944 13. VMOV <Sd>, <Rm>
14945 (ARM reg to VFP single.)
14946 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14947 (Two ARM regs to two VFP singles.)
14948 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14949 (Two VFP singles to two ARM regs.)
5f4273c7 14950
037e8744
JB
14951 These cases can be disambiguated using neon_select_shape, except cases 1/9
14952 and 3/11 which depend on the operand type too.
5f4273c7 14953
5287ad62 14954 All the encoded bits are hardcoded by this function.
5f4273c7 14955
b7fc2769
JB
14956 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14957 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14958
5287ad62 14959 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14960 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14961
14962static void
14963do_neon_mov (void)
14964{
037e8744
JB
14965 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14966 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14967 NS_NULL);
14968 struct neon_type_el et;
14969 const char *ldconst = 0;
5287ad62 14970
037e8744 14971 switch (rs)
5287ad62 14972 {
037e8744
JB
14973 case NS_DD: /* case 1/9. */
14974 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14975 /* It is not an error here if no type is given. */
14976 inst.error = NULL;
14977 if (et.type == NT_float && et.size == 64)
5287ad62 14978 {
037e8744
JB
14979 do_vfp_nsyn_opcode ("fcpyd");
14980 break;
5287ad62 14981 }
037e8744 14982 /* fall through. */
5287ad62 14983
037e8744
JB
14984 case NS_QQ: /* case 0/1. */
14985 {
14986 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14987 return;
14988 /* The architecture manual I have doesn't explicitly state which
14989 value the U bit should have for register->register moves, but
14990 the equivalent VORR instruction has U = 0, so do that. */
14991 inst.instruction = 0x0200110;
14992 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14993 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14994 inst.instruction |= LOW4 (inst.operands[1].reg);
14995 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14996 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14997 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14998 inst.instruction |= neon_quad (rs) << 6;
14999
88714cb8 15000 neon_dp_fixup (&inst);
037e8744
JB
15001 }
15002 break;
5f4273c7 15003
037e8744
JB
15004 case NS_DI: /* case 3/11. */
15005 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15006 inst.error = NULL;
15007 if (et.type == NT_float && et.size == 64)
5287ad62 15008 {
037e8744
JB
15009 /* case 11 (fconstd). */
15010 ldconst = "fconstd";
15011 goto encode_fconstd;
5287ad62 15012 }
037e8744
JB
15013 /* fall through. */
15014
15015 case NS_QI: /* case 2/3. */
15016 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15017 return;
15018 inst.instruction = 0x0800010;
15019 neon_move_immediate ();
88714cb8 15020 neon_dp_fixup (&inst);
5287ad62 15021 break;
5f4273c7 15022
037e8744
JB
15023 case NS_SR: /* case 4. */
15024 {
15025 unsigned bcdebits = 0;
91d6fa6a 15026 int logsize;
037e8744
JB
15027 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15028 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15029
91d6fa6a
NC
15030 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15031 logsize = neon_logbits (et.size);
15032
037e8744
JB
15033 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15034 _(BAD_FPU));
15035 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15036 && et.size != 32, _(BAD_FPU));
15037 constraint (et.type == NT_invtype, _("bad type for scalar"));
15038 constraint (x >= 64 / et.size, _("scalar index out of range"));
15039
15040 switch (et.size)
15041 {
15042 case 8: bcdebits = 0x8; break;
15043 case 16: bcdebits = 0x1; break;
15044 case 32: bcdebits = 0x0; break;
15045 default: ;
15046 }
15047
15048 bcdebits |= x << logsize;
15049
15050 inst.instruction = 0xe000b10;
15051 do_vfp_cond_or_thumb ();
15052 inst.instruction |= LOW4 (dn) << 16;
15053 inst.instruction |= HI1 (dn) << 7;
15054 inst.instruction |= inst.operands[1].reg << 12;
15055 inst.instruction |= (bcdebits & 3) << 5;
15056 inst.instruction |= (bcdebits >> 2) << 21;
15057 }
15058 break;
5f4273c7 15059
037e8744 15060 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15061 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 15062 _(BAD_FPU));
b7fc2769 15063
037e8744
JB
15064 inst.instruction = 0xc400b10;
15065 do_vfp_cond_or_thumb ();
15066 inst.instruction |= LOW4 (inst.operands[0].reg);
15067 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15068 inst.instruction |= inst.operands[1].reg << 12;
15069 inst.instruction |= inst.operands[2].reg << 16;
15070 break;
5f4273c7 15071
037e8744
JB
15072 case NS_RS: /* case 6. */
15073 {
91d6fa6a 15074 unsigned logsize;
037e8744
JB
15075 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15076 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15077 unsigned abcdebits = 0;
15078
91d6fa6a
NC
15079 et = neon_check_type (2, NS_NULL,
15080 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15081 logsize = neon_logbits (et.size);
15082
037e8744
JB
15083 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15084 _(BAD_FPU));
15085 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15086 && et.size != 32, _(BAD_FPU));
15087 constraint (et.type == NT_invtype, _("bad type for scalar"));
15088 constraint (x >= 64 / et.size, _("scalar index out of range"));
15089
15090 switch (et.size)
15091 {
15092 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15093 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15094 case 32: abcdebits = 0x00; break;
15095 default: ;
15096 }
15097
15098 abcdebits |= x << logsize;
15099 inst.instruction = 0xe100b10;
15100 do_vfp_cond_or_thumb ();
15101 inst.instruction |= LOW4 (dn) << 16;
15102 inst.instruction |= HI1 (dn) << 7;
15103 inst.instruction |= inst.operands[0].reg << 12;
15104 inst.instruction |= (abcdebits & 3) << 5;
15105 inst.instruction |= (abcdebits >> 2) << 21;
15106 }
15107 break;
5f4273c7 15108
037e8744
JB
15109 case NS_RRD: /* case 7 (fmrrd). */
15110 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15111 _(BAD_FPU));
15112
15113 inst.instruction = 0xc500b10;
15114 do_vfp_cond_or_thumb ();
15115 inst.instruction |= inst.operands[0].reg << 12;
15116 inst.instruction |= inst.operands[1].reg << 16;
15117 inst.instruction |= LOW4 (inst.operands[2].reg);
15118 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15119 break;
5f4273c7 15120
037e8744
JB
15121 case NS_FF: /* case 8 (fcpys). */
15122 do_vfp_nsyn_opcode ("fcpys");
15123 break;
5f4273c7 15124
037e8744
JB
15125 case NS_FI: /* case 10 (fconsts). */
15126 ldconst = "fconsts";
15127 encode_fconstd:
15128 if (is_quarter_float (inst.operands[1].imm))
5287ad62 15129 {
037e8744
JB
15130 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15131 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
15132 }
15133 else
037e8744
JB
15134 first_error (_("immediate out of range"));
15135 break;
5f4273c7 15136
037e8744
JB
15137 case NS_RF: /* case 12 (fmrs). */
15138 do_vfp_nsyn_opcode ("fmrs");
15139 break;
5f4273c7 15140
037e8744
JB
15141 case NS_FR: /* case 13 (fmsr). */
15142 do_vfp_nsyn_opcode ("fmsr");
15143 break;
5f4273c7 15144
037e8744
JB
15145 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15146 (one of which is a list), but we have parsed four. Do some fiddling to
15147 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15148 expect. */
15149 case NS_RRFF: /* case 14 (fmrrs). */
15150 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15151 _("VFP registers must be adjacent"));
15152 inst.operands[2].imm = 2;
15153 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15154 do_vfp_nsyn_opcode ("fmrrs");
15155 break;
5f4273c7 15156
037e8744
JB
15157 case NS_FFRR: /* case 15 (fmsrr). */
15158 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15159 _("VFP registers must be adjacent"));
15160 inst.operands[1] = inst.operands[2];
15161 inst.operands[2] = inst.operands[3];
15162 inst.operands[0].imm = 2;
15163 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15164 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 15165 break;
5f4273c7 15166
5287ad62
JB
15167 default:
15168 abort ();
15169 }
15170}
15171
15172static void
15173do_neon_rshift_round_imm (void)
15174{
037e8744 15175 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15176 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15177 int imm = inst.operands[2].imm;
15178
15179 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15180 if (imm == 0)
15181 {
15182 inst.operands[2].present = 0;
15183 do_neon_mov ();
15184 return;
15185 }
15186
15187 constraint (imm < 1 || (unsigned)imm > et.size,
15188 _("immediate out of range for shift"));
037e8744 15189 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
15190 et.size - imm);
15191}
15192
15193static void
15194do_neon_movl (void)
15195{
15196 struct neon_type_el et = neon_check_type (2, NS_QD,
15197 N_EQK | N_DBL, N_SU_32 | N_KEY);
15198 unsigned sizebits = et.size >> 3;
15199 inst.instruction |= sizebits << 19;
15200 neon_two_same (0, et.type == NT_unsigned, -1);
15201}
15202
15203static void
15204do_neon_trn (void)
15205{
037e8744 15206 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15207 struct neon_type_el et = neon_check_type (2, rs,
15208 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15209 NEON_ENCODE (INTEGER, inst);
037e8744 15210 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15211}
15212
15213static void
15214do_neon_zip_uzp (void)
15215{
037e8744 15216 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15217 struct neon_type_el et = neon_check_type (2, rs,
15218 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15219 if (rs == NS_DD && et.size == 32)
15220 {
15221 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15222 inst.instruction = N_MNEM_vtrn;
15223 do_neon_trn ();
15224 return;
15225 }
037e8744 15226 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15227}
15228
15229static void
15230do_neon_sat_abs_neg (void)
15231{
037e8744 15232 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15233 struct neon_type_el et = neon_check_type (2, rs,
15234 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15235 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15236}
15237
15238static void
15239do_neon_pair_long (void)
15240{
037e8744 15241 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15242 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15243 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15244 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 15245 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15246}
15247
15248static void
15249do_neon_recip_est (void)
15250{
037e8744 15251 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15252 struct neon_type_el et = neon_check_type (2, rs,
15253 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15254 inst.instruction |= (et.type == NT_float) << 8;
037e8744 15255 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15256}
15257
15258static void
15259do_neon_cls (void)
15260{
037e8744 15261 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15262 struct neon_type_el et = neon_check_type (2, rs,
15263 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 15264 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15265}
15266
15267static void
15268do_neon_clz (void)
15269{
037e8744 15270 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15271 struct neon_type_el et = neon_check_type (2, rs,
15272 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 15273 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15274}
15275
15276static void
15277do_neon_cnt (void)
15278{
037e8744 15279 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15280 struct neon_type_el et = neon_check_type (2, rs,
15281 N_EQK | N_INT, N_8 | N_KEY);
037e8744 15282 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15283}
15284
15285static void
15286do_neon_swp (void)
15287{
037e8744
JB
15288 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15289 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
15290}
15291
15292static void
15293do_neon_tbl_tbx (void)
15294{
15295 unsigned listlenbits;
dcbf9037 15296 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 15297
5287ad62
JB
15298 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15299 {
dcbf9037 15300 first_error (_("bad list length for table lookup"));
5287ad62
JB
15301 return;
15302 }
5f4273c7 15303
5287ad62
JB
15304 listlenbits = inst.operands[1].imm - 1;
15305 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15306 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15307 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15308 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15309 inst.instruction |= LOW4 (inst.operands[2].reg);
15310 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15311 inst.instruction |= listlenbits << 8;
5f4273c7 15312
88714cb8 15313 neon_dp_fixup (&inst);
5287ad62
JB
15314}
15315
15316static void
15317do_neon_ldm_stm (void)
15318{
15319 /* P, U and L bits are part of bitmask. */
15320 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15321 unsigned offsetbits = inst.operands[1].imm * 2;
15322
037e8744
JB
15323 if (inst.operands[1].issingle)
15324 {
15325 do_vfp_nsyn_ldm_stm (is_dbmode);
15326 return;
15327 }
15328
5287ad62
JB
15329 constraint (is_dbmode && !inst.operands[0].writeback,
15330 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15331
15332 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15333 _("register list must contain at least 1 and at most 16 "
15334 "registers"));
15335
15336 inst.instruction |= inst.operands[0].reg << 16;
15337 inst.instruction |= inst.operands[0].writeback << 21;
15338 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15339 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15340
15341 inst.instruction |= offsetbits;
5f4273c7 15342
037e8744 15343 do_vfp_cond_or_thumb ();
5287ad62
JB
15344}
15345
15346static void
15347do_neon_ldr_str (void)
15348{
5287ad62 15349 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 15350
6844b2c2
MGD
15351 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15352 And is UNPREDICTABLE in thumb mode. */
fa94de6b 15353 if (!is_ldr
6844b2c2
MGD
15354 && inst.operands[1].reg == REG_PC
15355 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15356 {
15357 if (!thumb_mode && warn_on_deprecated)
15358 as_warn (_("Use of PC here is deprecated"));
15359 else
15360 inst.error = _("Use of PC here is UNPREDICTABLE");
15361 }
15362
037e8744
JB
15363 if (inst.operands[0].issingle)
15364 {
cd2f129f
JB
15365 if (is_ldr)
15366 do_vfp_nsyn_opcode ("flds");
15367 else
15368 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
15369 }
15370 else
5287ad62 15371 {
cd2f129f
JB
15372 if (is_ldr)
15373 do_vfp_nsyn_opcode ("fldd");
5287ad62 15374 else
cd2f129f 15375 do_vfp_nsyn_opcode ("fstd");
5287ad62 15376 }
5287ad62
JB
15377}
15378
15379/* "interleave" version also handles non-interleaving register VLD1/VST1
15380 instructions. */
15381
15382static void
15383do_neon_ld_st_interleave (void)
15384{
037e8744 15385 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
15386 N_8 | N_16 | N_32 | N_64);
15387 unsigned alignbits = 0;
15388 unsigned idx;
15389 /* The bits in this table go:
15390 0: register stride of one (0) or two (1)
15391 1,2: register list length, minus one (1, 2, 3, 4).
15392 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15393 We use -1 for invalid entries. */
15394 const int typetable[] =
15395 {
15396 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15397 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15398 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15399 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15400 };
15401 int typebits;
15402
dcbf9037
JB
15403 if (et.type == NT_invtype)
15404 return;
15405
5287ad62
JB
15406 if (inst.operands[1].immisalign)
15407 switch (inst.operands[1].imm >> 8)
15408 {
15409 case 64: alignbits = 1; break;
15410 case 128:
e23c0ad8
JZ
15411 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15412 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15413 goto bad_alignment;
15414 alignbits = 2;
15415 break;
15416 case 256:
e23c0ad8 15417 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
15418 goto bad_alignment;
15419 alignbits = 3;
15420 break;
15421 default:
15422 bad_alignment:
dcbf9037 15423 first_error (_("bad alignment"));
5287ad62
JB
15424 return;
15425 }
15426
15427 inst.instruction |= alignbits << 4;
15428 inst.instruction |= neon_logbits (et.size) << 6;
15429
15430 /* Bits [4:6] of the immediate in a list specifier encode register stride
15431 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15432 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15433 up the right value for "type" in a table based on this value and the given
15434 list style, then stick it back. */
15435 idx = ((inst.operands[0].imm >> 4) & 7)
15436 | (((inst.instruction >> 8) & 3) << 3);
15437
15438 typebits = typetable[idx];
5f4273c7 15439
5287ad62
JB
15440 constraint (typebits == -1, _("bad list type for instruction"));
15441
15442 inst.instruction &= ~0xf00;
15443 inst.instruction |= typebits << 8;
15444}
15445
15446/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15447 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15448 otherwise. The variable arguments are a list of pairs of legal (size, align)
15449 values, terminated with -1. */
15450
15451static int
15452neon_alignment_bit (int size, int align, int *do_align, ...)
15453{
15454 va_list ap;
15455 int result = FAIL, thissize, thisalign;
5f4273c7 15456
5287ad62
JB
15457 if (!inst.operands[1].immisalign)
15458 {
15459 *do_align = 0;
15460 return SUCCESS;
15461 }
5f4273c7 15462
5287ad62
JB
15463 va_start (ap, do_align);
15464
15465 do
15466 {
15467 thissize = va_arg (ap, int);
15468 if (thissize == -1)
15469 break;
15470 thisalign = va_arg (ap, int);
15471
15472 if (size == thissize && align == thisalign)
15473 result = SUCCESS;
15474 }
15475 while (result != SUCCESS);
15476
15477 va_end (ap);
15478
15479 if (result == SUCCESS)
15480 *do_align = 1;
15481 else
dcbf9037 15482 first_error (_("unsupported alignment for instruction"));
5f4273c7 15483
5287ad62
JB
15484 return result;
15485}
15486
15487static void
15488do_neon_ld_st_lane (void)
15489{
037e8744 15490 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15491 int align_good, do_align = 0;
15492 int logsize = neon_logbits (et.size);
15493 int align = inst.operands[1].imm >> 8;
15494 int n = (inst.instruction >> 8) & 3;
15495 int max_el = 64 / et.size;
5f4273c7 15496
dcbf9037
JB
15497 if (et.type == NT_invtype)
15498 return;
5f4273c7 15499
5287ad62
JB
15500 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15501 _("bad list length"));
15502 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15503 _("scalar index out of range"));
15504 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15505 && et.size == 8,
15506 _("stride of 2 unavailable when element size is 8"));
5f4273c7 15507
5287ad62
JB
15508 switch (n)
15509 {
15510 case 0: /* VLD1 / VST1. */
15511 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15512 32, 32, -1);
15513 if (align_good == FAIL)
15514 return;
15515 if (do_align)
15516 {
15517 unsigned alignbits = 0;
15518 switch (et.size)
15519 {
15520 case 16: alignbits = 0x1; break;
15521 case 32: alignbits = 0x3; break;
15522 default: ;
15523 }
15524 inst.instruction |= alignbits << 4;
15525 }
15526 break;
15527
15528 case 1: /* VLD2 / VST2. */
15529 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15530 32, 64, -1);
15531 if (align_good == FAIL)
15532 return;
15533 if (do_align)
15534 inst.instruction |= 1 << 4;
15535 break;
15536
15537 case 2: /* VLD3 / VST3. */
15538 constraint (inst.operands[1].immisalign,
15539 _("can't use alignment with this instruction"));
15540 break;
15541
15542 case 3: /* VLD4 / VST4. */
15543 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15544 16, 64, 32, 64, 32, 128, -1);
15545 if (align_good == FAIL)
15546 return;
15547 if (do_align)
15548 {
15549 unsigned alignbits = 0;
15550 switch (et.size)
15551 {
15552 case 8: alignbits = 0x1; break;
15553 case 16: alignbits = 0x1; break;
15554 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15555 default: ;
15556 }
15557 inst.instruction |= alignbits << 4;
15558 }
15559 break;
15560
15561 default: ;
15562 }
15563
15564 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15565 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15566 inst.instruction |= 1 << (4 + logsize);
5f4273c7 15567
5287ad62
JB
15568 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15569 inst.instruction |= logsize << 10;
15570}
15571
15572/* Encode single n-element structure to all lanes VLD<n> instructions. */
15573
15574static void
15575do_neon_ld_dup (void)
15576{
037e8744 15577 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
15578 int align_good, do_align = 0;
15579
dcbf9037
JB
15580 if (et.type == NT_invtype)
15581 return;
15582
5287ad62
JB
15583 switch ((inst.instruction >> 8) & 3)
15584 {
15585 case 0: /* VLD1. */
9c2799c2 15586 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
15587 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15588 &do_align, 16, 16, 32, 32, -1);
15589 if (align_good == FAIL)
15590 return;
15591 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15592 {
15593 case 1: break;
15594 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 15595 default: first_error (_("bad list length")); return;
5287ad62
JB
15596 }
15597 inst.instruction |= neon_logbits (et.size) << 6;
15598 break;
15599
15600 case 1: /* VLD2. */
15601 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15602 &do_align, 8, 16, 16, 32, 32, 64, -1);
15603 if (align_good == FAIL)
15604 return;
15605 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15606 _("bad list length"));
15607 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15608 inst.instruction |= 1 << 5;
15609 inst.instruction |= neon_logbits (et.size) << 6;
15610 break;
15611
15612 case 2: /* VLD3. */
15613 constraint (inst.operands[1].immisalign,
15614 _("can't use alignment with this instruction"));
15615 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15616 _("bad list length"));
15617 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15618 inst.instruction |= 1 << 5;
15619 inst.instruction |= neon_logbits (et.size) << 6;
15620 break;
15621
15622 case 3: /* VLD4. */
15623 {
15624 int align = inst.operands[1].imm >> 8;
15625 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15626 16, 64, 32, 64, 32, 128, -1);
15627 if (align_good == FAIL)
15628 return;
15629 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15630 _("bad list length"));
15631 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15632 inst.instruction |= 1 << 5;
15633 if (et.size == 32 && align == 128)
15634 inst.instruction |= 0x3 << 6;
15635 else
15636 inst.instruction |= neon_logbits (et.size) << 6;
15637 }
15638 break;
15639
15640 default: ;
15641 }
15642
15643 inst.instruction |= do_align << 4;
15644}
15645
15646/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15647 apart from bits [11:4]. */
15648
15649static void
15650do_neon_ldx_stx (void)
15651{
b1a769ed
DG
15652 if (inst.operands[1].isreg)
15653 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15654
5287ad62
JB
15655 switch (NEON_LANE (inst.operands[0].imm))
15656 {
15657 case NEON_INTERLEAVE_LANES:
88714cb8 15658 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
15659 do_neon_ld_st_interleave ();
15660 break;
5f4273c7 15661
5287ad62 15662 case NEON_ALL_LANES:
88714cb8 15663 NEON_ENCODE (DUP, inst);
5287ad62
JB
15664 do_neon_ld_dup ();
15665 break;
5f4273c7 15666
5287ad62 15667 default:
88714cb8 15668 NEON_ENCODE (LANE, inst);
5287ad62
JB
15669 do_neon_ld_st_lane ();
15670 }
15671
15672 /* L bit comes from bit mask. */
15673 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15674 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15675 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 15676
5287ad62
JB
15677 if (inst.operands[1].postind)
15678 {
15679 int postreg = inst.operands[1].imm & 0xf;
15680 constraint (!inst.operands[1].immisreg,
15681 _("post-index must be a register"));
15682 constraint (postreg == 0xd || postreg == 0xf,
15683 _("bad register for post-index"));
15684 inst.instruction |= postreg;
15685 }
15686 else if (inst.operands[1].writeback)
15687 {
15688 inst.instruction |= 0xd;
15689 }
15690 else
5f4273c7
NC
15691 inst.instruction |= 0xf;
15692
5287ad62
JB
15693 if (thumb_mode)
15694 inst.instruction |= 0xf9000000;
15695 else
15696 inst.instruction |= 0xf4000000;
15697}
5287ad62
JB
15698\f
15699/* Overall per-instruction processing. */
15700
15701/* We need to be able to fix up arbitrary expressions in some statements.
15702 This is so that we can handle symbols that are an arbitrary distance from
15703 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15704 which returns part of an address in a form which will be valid for
15705 a data instruction. We do this by pushing the expression into a symbol
15706 in the expr_section, and creating a fix for that. */
15707
15708static void
15709fix_new_arm (fragS * frag,
15710 int where,
15711 short int size,
15712 expressionS * exp,
15713 int pc_rel,
15714 int reloc)
15715{
15716 fixS * new_fix;
15717
15718 switch (exp->X_op)
15719 {
15720 case O_constant:
6e7ce2cd
PB
15721 if (pc_rel)
15722 {
15723 /* Create an absolute valued symbol, so we have something to
15724 refer to in the object file. Unfortunately for us, gas's
15725 generic expression parsing will already have folded out
15726 any use of .set foo/.type foo %function that may have
15727 been used to set type information of the target location,
15728 that's being specified symbolically. We have to presume
15729 the user knows what they are doing. */
15730 char name[16 + 8];
15731 symbolS *symbol;
15732
15733 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15734
15735 symbol = symbol_find_or_make (name);
15736 S_SET_SEGMENT (symbol, absolute_section);
15737 symbol_set_frag (symbol, &zero_address_frag);
15738 S_SET_VALUE (symbol, exp->X_add_number);
15739 exp->X_op = O_symbol;
15740 exp->X_add_symbol = symbol;
15741 exp->X_add_number = 0;
15742 }
15743 /* FALLTHROUGH */
5287ad62
JB
15744 case O_symbol:
15745 case O_add:
15746 case O_subtract:
21d799b5
NC
15747 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15748 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15749 break;
15750
15751 default:
21d799b5
NC
15752 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15753 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15754 break;
15755 }
15756
15757 /* Mark whether the fix is to a THUMB instruction, or an ARM
15758 instruction. */
15759 new_fix->tc_fix_data = thumb_mode;
15760}
15761
15762/* Create a frg for an instruction requiring relaxation. */
15763static void
15764output_relax_insn (void)
15765{
15766 char * to;
15767 symbolS *sym;
0110f2b8
PB
15768 int offset;
15769
6e1cb1a6
PB
15770 /* The size of the instruction is unknown, so tie the debug info to the
15771 start of the instruction. */
15772 dwarf2_emit_insn (0);
6e1cb1a6 15773
0110f2b8
PB
15774 switch (inst.reloc.exp.X_op)
15775 {
15776 case O_symbol:
15777 sym = inst.reloc.exp.X_add_symbol;
15778 offset = inst.reloc.exp.X_add_number;
15779 break;
15780 case O_constant:
15781 sym = NULL;
15782 offset = inst.reloc.exp.X_add_number;
15783 break;
15784 default:
15785 sym = make_expr_symbol (&inst.reloc.exp);
15786 offset = 0;
15787 break;
15788 }
15789 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15790 inst.relax, sym, offset, NULL/*offset, opcode*/);
15791 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15792}
15793
15794/* Write a 32-bit thumb instruction to buf. */
15795static void
15796put_thumb32_insn (char * buf, unsigned long insn)
15797{
15798 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15799 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15800}
15801
b99bd4ef 15802static void
c19d1205 15803output_inst (const char * str)
b99bd4ef 15804{
c19d1205 15805 char * to = NULL;
b99bd4ef 15806
c19d1205 15807 if (inst.error)
b99bd4ef 15808 {
c19d1205 15809 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15810 return;
15811 }
5f4273c7
NC
15812 if (inst.relax)
15813 {
15814 output_relax_insn ();
0110f2b8 15815 return;
5f4273c7 15816 }
c19d1205
ZW
15817 if (inst.size == 0)
15818 return;
b99bd4ef 15819
c19d1205 15820 to = frag_more (inst.size);
8dc2430f
NC
15821 /* PR 9814: Record the thumb mode into the current frag so that we know
15822 what type of NOP padding to use, if necessary. We override any previous
15823 setting so that if the mode has changed then the NOPS that we use will
15824 match the encoding of the last instruction in the frag. */
cd000bff 15825 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15826
15827 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15828 {
9c2799c2 15829 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15830 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15831 }
c19d1205 15832 else if (inst.size > INSN_SIZE)
b99bd4ef 15833 {
9c2799c2 15834 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15835 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15836 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15837 }
c19d1205
ZW
15838 else
15839 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15840
c19d1205
ZW
15841 if (inst.reloc.type != BFD_RELOC_UNUSED)
15842 fix_new_arm (frag_now, to - frag_now->fr_literal,
15843 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15844 inst.reloc.type);
b99bd4ef 15845
c19d1205 15846 dwarf2_emit_insn (inst.size);
c19d1205 15847}
b99bd4ef 15848
e07e6e58
NC
15849static char *
15850output_it_inst (int cond, int mask, char * to)
15851{
15852 unsigned long instruction = 0xbf00;
15853
15854 mask &= 0xf;
15855 instruction |= mask;
15856 instruction |= cond << 4;
15857
15858 if (to == NULL)
15859 {
15860 to = frag_more (2);
15861#ifdef OBJ_ELF
15862 dwarf2_emit_insn (2);
15863#endif
15864 }
15865
15866 md_number_to_chars (to, instruction, 2);
15867
15868 return to;
15869}
15870
c19d1205
ZW
15871/* Tag values used in struct asm_opcode's tag field. */
15872enum opcode_tag
15873{
15874 OT_unconditional, /* Instruction cannot be conditionalized.
15875 The ARM condition field is still 0xE. */
15876 OT_unconditionalF, /* Instruction cannot be conditionalized
15877 and carries 0xF in its ARM condition field. */
15878 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15879 OT_csuffixF, /* Some forms of the instruction take a conditional
15880 suffix, others place 0xF where the condition field
15881 would be. */
c19d1205
ZW
15882 OT_cinfix3, /* Instruction takes a conditional infix,
15883 beginning at character index 3. (In
15884 unified mode, it becomes a suffix.) */
088fa78e
KH
15885 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15886 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15887 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15888 character index 3, even in unified mode. Used for
15889 legacy instructions where suffix and infix forms
15890 may be ambiguous. */
c19d1205 15891 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15892 suffix or an infix at character index 3. */
c19d1205
ZW
15893 OT_odd_infix_unc, /* This is the unconditional variant of an
15894 instruction that takes a conditional infix
15895 at an unusual position. In unified mode,
15896 this variant will accept a suffix. */
15897 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15898 are the conditional variants of instructions that
15899 take conditional infixes in unusual positions.
15900 The infix appears at character index
15901 (tag - OT_odd_infix_0). These are not accepted
15902 in unified mode. */
15903};
b99bd4ef 15904
c19d1205
ZW
15905/* Subroutine of md_assemble, responsible for looking up the primary
15906 opcode from the mnemonic the user wrote. STR points to the
15907 beginning of the mnemonic.
15908
15909 This is not simply a hash table lookup, because of conditional
15910 variants. Most instructions have conditional variants, which are
15911 expressed with a _conditional affix_ to the mnemonic. If we were
15912 to encode each conditional variant as a literal string in the opcode
15913 table, it would have approximately 20,000 entries.
15914
15915 Most mnemonics take this affix as a suffix, and in unified syntax,
15916 'most' is upgraded to 'all'. However, in the divided syntax, some
15917 instructions take the affix as an infix, notably the s-variants of
15918 the arithmetic instructions. Of those instructions, all but six
15919 have the infix appear after the third character of the mnemonic.
15920
15921 Accordingly, the algorithm for looking up primary opcodes given
15922 an identifier is:
15923
15924 1. Look up the identifier in the opcode table.
15925 If we find a match, go to step U.
15926
15927 2. Look up the last two characters of the identifier in the
15928 conditions table. If we find a match, look up the first N-2
15929 characters of the identifier in the opcode table. If we
15930 find a match, go to step CE.
15931
15932 3. Look up the fourth and fifth characters of the identifier in
15933 the conditions table. If we find a match, extract those
15934 characters from the identifier, and look up the remaining
15935 characters in the opcode table. If we find a match, go
15936 to step CM.
15937
15938 4. Fail.
15939
15940 U. Examine the tag field of the opcode structure, in case this is
15941 one of the six instructions with its conditional infix in an
15942 unusual place. If it is, the tag tells us where to find the
15943 infix; look it up in the conditions table and set inst.cond
15944 accordingly. Otherwise, this is an unconditional instruction.
15945 Again set inst.cond accordingly. Return the opcode structure.
15946
15947 CE. Examine the tag field to make sure this is an instruction that
15948 should receive a conditional suffix. If it is not, fail.
15949 Otherwise, set inst.cond from the suffix we already looked up,
15950 and return the opcode structure.
15951
15952 CM. Examine the tag field to make sure this is an instruction that
15953 should receive a conditional infix after the third character.
15954 If it is not, fail. Otherwise, undo the edits to the current
15955 line of input and proceed as for case CE. */
15956
15957static const struct asm_opcode *
15958opcode_lookup (char **str)
15959{
15960 char *end, *base;
15961 char *affix;
15962 const struct asm_opcode *opcode;
15963 const struct asm_cond *cond;
e3cb604e 15964 char save[2];
c19d1205
ZW
15965
15966 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15967 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15968 for (base = end = *str; *end != '\0'; end++)
721a8186 15969 if (*end == ' ' || *end == '.')
c19d1205 15970 break;
b99bd4ef 15971
c19d1205 15972 if (end == base)
c921be7d 15973 return NULL;
b99bd4ef 15974
5287ad62 15975 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15976 if (end[0] == '.')
b99bd4ef 15977 {
5287ad62 15978 int offset = 2;
5f4273c7 15979
267d2029
JB
15980 /* The .w and .n suffixes are only valid if the unified syntax is in
15981 use. */
15982 if (unified_syntax && end[1] == 'w')
c19d1205 15983 inst.size_req = 4;
267d2029 15984 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15985 inst.size_req = 2;
15986 else
5287ad62
JB
15987 offset = 0;
15988
15989 inst.vectype.elems = 0;
15990
15991 *str = end + offset;
b99bd4ef 15992
5f4273c7 15993 if (end[offset] == '.')
5287ad62 15994 {
267d2029
JB
15995 /* See if we have a Neon type suffix (possible in either unified or
15996 non-unified ARM syntax mode). */
dcbf9037 15997 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15998 return NULL;
5287ad62
JB
15999 }
16000 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 16001 return NULL;
b99bd4ef 16002 }
c19d1205
ZW
16003 else
16004 *str = end;
b99bd4ef 16005
c19d1205 16006 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
16007 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16008 end - base);
c19d1205 16009 if (opcode)
b99bd4ef 16010 {
c19d1205
ZW
16011 /* step U */
16012 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 16013 {
c19d1205
ZW
16014 inst.cond = COND_ALWAYS;
16015 return opcode;
b99bd4ef 16016 }
b99bd4ef 16017
278df34e 16018 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
16019 as_warn (_("conditional infixes are deprecated in unified syntax"));
16020 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 16021 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 16022 gas_assert (cond);
b99bd4ef 16023
c19d1205
ZW
16024 inst.cond = cond->value;
16025 return opcode;
16026 }
b99bd4ef 16027
c19d1205
ZW
16028 /* Cannot have a conditional suffix on a mnemonic of less than two
16029 characters. */
16030 if (end - base < 3)
c921be7d 16031 return NULL;
b99bd4ef 16032
c19d1205
ZW
16033 /* Look for suffixed mnemonic. */
16034 affix = end - 2;
21d799b5
NC
16035 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16036 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16037 affix - base);
c19d1205
ZW
16038 if (opcode && cond)
16039 {
16040 /* step CE */
16041 switch (opcode->tag)
16042 {
e3cb604e
PB
16043 case OT_cinfix3_legacy:
16044 /* Ignore conditional suffixes matched on infix only mnemonics. */
16045 break;
16046
c19d1205 16047 case OT_cinfix3:
088fa78e 16048 case OT_cinfix3_deprecated:
c19d1205
ZW
16049 case OT_odd_infix_unc:
16050 if (!unified_syntax)
e3cb604e 16051 return 0;
c19d1205
ZW
16052 /* else fall through */
16053
16054 case OT_csuffix:
037e8744 16055 case OT_csuffixF:
c19d1205
ZW
16056 case OT_csuf_or_in3:
16057 inst.cond = cond->value;
16058 return opcode;
16059
16060 case OT_unconditional:
16061 case OT_unconditionalF:
dfa9f0d5 16062 if (thumb_mode)
c921be7d 16063 inst.cond = cond->value;
dfa9f0d5
PB
16064 else
16065 {
c921be7d 16066 /* Delayed diagnostic. */
dfa9f0d5
PB
16067 inst.error = BAD_COND;
16068 inst.cond = COND_ALWAYS;
16069 }
c19d1205 16070 return opcode;
b99bd4ef 16071
c19d1205 16072 default:
c921be7d 16073 return NULL;
c19d1205
ZW
16074 }
16075 }
b99bd4ef 16076
c19d1205
ZW
16077 /* Cannot have a usual-position infix on a mnemonic of less than
16078 six characters (five would be a suffix). */
16079 if (end - base < 6)
c921be7d 16080 return NULL;
b99bd4ef 16081
c19d1205
ZW
16082 /* Look for infixed mnemonic in the usual position. */
16083 affix = base + 3;
21d799b5 16084 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 16085 if (!cond)
c921be7d 16086 return NULL;
e3cb604e
PB
16087
16088 memcpy (save, affix, 2);
16089 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
16090 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16091 (end - base) - 2);
e3cb604e
PB
16092 memmove (affix + 2, affix, (end - affix) - 2);
16093 memcpy (affix, save, 2);
16094
088fa78e
KH
16095 if (opcode
16096 && (opcode->tag == OT_cinfix3
16097 || opcode->tag == OT_cinfix3_deprecated
16098 || opcode->tag == OT_csuf_or_in3
16099 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 16100 {
c921be7d 16101 /* Step CM. */
278df34e 16102 if (warn_on_deprecated && unified_syntax
088fa78e
KH
16103 && (opcode->tag == OT_cinfix3
16104 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
16105 as_warn (_("conditional infixes are deprecated in unified syntax"));
16106
16107 inst.cond = cond->value;
16108 return opcode;
b99bd4ef
NC
16109 }
16110
c921be7d 16111 return NULL;
b99bd4ef
NC
16112}
16113
e07e6e58
NC
16114/* This function generates an initial IT instruction, leaving its block
16115 virtually open for the new instructions. Eventually,
16116 the mask will be updated by now_it_add_mask () each time
16117 a new instruction needs to be included in the IT block.
16118 Finally, the block is closed with close_automatic_it_block ().
16119 The block closure can be requested either from md_assemble (),
16120 a tencode (), or due to a label hook. */
16121
16122static void
16123new_automatic_it_block (int cond)
16124{
16125 now_it.state = AUTOMATIC_IT_BLOCK;
16126 now_it.mask = 0x18;
16127 now_it.cc = cond;
16128 now_it.block_length = 1;
cd000bff 16129 mapping_state (MAP_THUMB);
e07e6e58
NC
16130 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16131}
16132
16133/* Close an automatic IT block.
16134 See comments in new_automatic_it_block (). */
16135
16136static void
16137close_automatic_it_block (void)
16138{
16139 now_it.mask = 0x10;
16140 now_it.block_length = 0;
16141}
16142
16143/* Update the mask of the current automatically-generated IT
16144 instruction. See comments in new_automatic_it_block (). */
16145
16146static void
16147now_it_add_mask (int cond)
16148{
16149#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16150#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16151 | ((bitvalue) << (nbit)))
e07e6e58 16152 const int resulting_bit = (cond & 1);
c921be7d 16153
e07e6e58
NC
16154 now_it.mask &= 0xf;
16155 now_it.mask = SET_BIT_VALUE (now_it.mask,
16156 resulting_bit,
16157 (5 - now_it.block_length));
16158 now_it.mask = SET_BIT_VALUE (now_it.mask,
16159 1,
16160 ((5 - now_it.block_length) - 1) );
16161 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16162
16163#undef CLEAR_BIT
16164#undef SET_BIT_VALUE
e07e6e58
NC
16165}
16166
16167/* The IT blocks handling machinery is accessed through the these functions:
16168 it_fsm_pre_encode () from md_assemble ()
16169 set_it_insn_type () optional, from the tencode functions
16170 set_it_insn_type_last () ditto
16171 in_it_block () ditto
16172 it_fsm_post_encode () from md_assemble ()
16173 force_automatic_it_block_close () from label habdling functions
16174
16175 Rationale:
16176 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16177 initializing the IT insn type with a generic initial value depending
16178 on the inst.condition.
16179 2) During the tencode function, two things may happen:
16180 a) The tencode function overrides the IT insn type by
16181 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16182 b) The tencode function queries the IT block state by
16183 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16184
16185 Both set_it_insn_type and in_it_block run the internal FSM state
16186 handling function (handle_it_state), because: a) setting the IT insn
16187 type may incur in an invalid state (exiting the function),
16188 and b) querying the state requires the FSM to be updated.
16189 Specifically we want to avoid creating an IT block for conditional
16190 branches, so it_fsm_pre_encode is actually a guess and we can't
16191 determine whether an IT block is required until the tencode () routine
16192 has decided what type of instruction this actually it.
16193 Because of this, if set_it_insn_type and in_it_block have to be used,
16194 set_it_insn_type has to be called first.
16195
16196 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16197 determines the insn IT type depending on the inst.cond code.
16198 When a tencode () routine encodes an instruction that can be
16199 either outside an IT block, or, in the case of being inside, has to be
16200 the last one, set_it_insn_type_last () will determine the proper
16201 IT instruction type based on the inst.cond code. Otherwise,
16202 set_it_insn_type can be called for overriding that logic or
16203 for covering other cases.
16204
16205 Calling handle_it_state () may not transition the IT block state to
16206 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16207 still queried. Instead, if the FSM determines that the state should
16208 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16209 after the tencode () function: that's what it_fsm_post_encode () does.
16210
16211 Since in_it_block () calls the state handling function to get an
16212 updated state, an error may occur (due to invalid insns combination).
16213 In that case, inst.error is set.
16214 Therefore, inst.error has to be checked after the execution of
16215 the tencode () routine.
16216
16217 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16218 any pending state change (if any) that didn't take place in
16219 handle_it_state () as explained above. */
16220
16221static void
16222it_fsm_pre_encode (void)
16223{
16224 if (inst.cond != COND_ALWAYS)
16225 inst.it_insn_type = INSIDE_IT_INSN;
16226 else
16227 inst.it_insn_type = OUTSIDE_IT_INSN;
16228
16229 now_it.state_handled = 0;
16230}
16231
16232/* IT state FSM handling function. */
16233
16234static int
16235handle_it_state (void)
16236{
16237 now_it.state_handled = 1;
16238
16239 switch (now_it.state)
16240 {
16241 case OUTSIDE_IT_BLOCK:
16242 switch (inst.it_insn_type)
16243 {
16244 case OUTSIDE_IT_INSN:
16245 break;
16246
16247 case INSIDE_IT_INSN:
16248 case INSIDE_IT_LAST_INSN:
16249 if (thumb_mode == 0)
16250 {
c921be7d 16251 if (unified_syntax
e07e6e58
NC
16252 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16253 as_tsktsk (_("Warning: conditional outside an IT block"\
16254 " for Thumb."));
16255 }
16256 else
16257 {
16258 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16259 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16260 {
16261 /* Automatically generate the IT instruction. */
16262 new_automatic_it_block (inst.cond);
16263 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16264 close_automatic_it_block ();
16265 }
16266 else
16267 {
16268 inst.error = BAD_OUT_IT;
16269 return FAIL;
16270 }
16271 }
16272 break;
16273
16274 case IF_INSIDE_IT_LAST_INSN:
16275 case NEUTRAL_IT_INSN:
16276 break;
16277
16278 case IT_INSN:
16279 now_it.state = MANUAL_IT_BLOCK;
16280 now_it.block_length = 0;
16281 break;
16282 }
16283 break;
16284
16285 case AUTOMATIC_IT_BLOCK:
16286 /* Three things may happen now:
16287 a) We should increment current it block size;
16288 b) We should close current it block (closing insn or 4 insns);
16289 c) We should close current it block and start a new one (due
16290 to incompatible conditions or
16291 4 insns-length block reached). */
16292
16293 switch (inst.it_insn_type)
16294 {
16295 case OUTSIDE_IT_INSN:
16296 /* The closure of the block shall happen immediatelly,
16297 so any in_it_block () call reports the block as closed. */
16298 force_automatic_it_block_close ();
16299 break;
16300
16301 case INSIDE_IT_INSN:
16302 case INSIDE_IT_LAST_INSN:
16303 case IF_INSIDE_IT_LAST_INSN:
16304 now_it.block_length++;
16305
16306 if (now_it.block_length > 4
16307 || !now_it_compatible (inst.cond))
16308 {
16309 force_automatic_it_block_close ();
16310 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16311 new_automatic_it_block (inst.cond);
16312 }
16313 else
16314 {
16315 now_it_add_mask (inst.cond);
16316 }
16317
16318 if (now_it.state == AUTOMATIC_IT_BLOCK
16319 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16320 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16321 close_automatic_it_block ();
16322 break;
16323
16324 case NEUTRAL_IT_INSN:
16325 now_it.block_length++;
16326
16327 if (now_it.block_length > 4)
16328 force_automatic_it_block_close ();
16329 else
16330 now_it_add_mask (now_it.cc & 1);
16331 break;
16332
16333 case IT_INSN:
16334 close_automatic_it_block ();
16335 now_it.state = MANUAL_IT_BLOCK;
16336 break;
16337 }
16338 break;
16339
16340 case MANUAL_IT_BLOCK:
16341 {
16342 /* Check conditional suffixes. */
16343 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16344 int is_last;
16345 now_it.mask <<= 1;
16346 now_it.mask &= 0x1f;
16347 is_last = (now_it.mask == 0x10);
16348
16349 switch (inst.it_insn_type)
16350 {
16351 case OUTSIDE_IT_INSN:
16352 inst.error = BAD_NOT_IT;
16353 return FAIL;
16354
16355 case INSIDE_IT_INSN:
16356 if (cond != inst.cond)
16357 {
16358 inst.error = BAD_IT_COND;
16359 return FAIL;
16360 }
16361 break;
16362
16363 case INSIDE_IT_LAST_INSN:
16364 case IF_INSIDE_IT_LAST_INSN:
16365 if (cond != inst.cond)
16366 {
16367 inst.error = BAD_IT_COND;
16368 return FAIL;
16369 }
16370 if (!is_last)
16371 {
16372 inst.error = BAD_BRANCH;
16373 return FAIL;
16374 }
16375 break;
16376
16377 case NEUTRAL_IT_INSN:
16378 /* The BKPT instruction is unconditional even in an IT block. */
16379 break;
16380
16381 case IT_INSN:
16382 inst.error = BAD_IT_IT;
16383 return FAIL;
16384 }
16385 }
16386 break;
16387 }
16388
16389 return SUCCESS;
16390}
16391
16392static void
16393it_fsm_post_encode (void)
16394{
16395 int is_last;
16396
16397 if (!now_it.state_handled)
16398 handle_it_state ();
16399
16400 is_last = (now_it.mask == 0x10);
16401 if (is_last)
16402 {
16403 now_it.state = OUTSIDE_IT_BLOCK;
16404 now_it.mask = 0;
16405 }
16406}
16407
16408static void
16409force_automatic_it_block_close (void)
16410{
16411 if (now_it.state == AUTOMATIC_IT_BLOCK)
16412 {
16413 close_automatic_it_block ();
16414 now_it.state = OUTSIDE_IT_BLOCK;
16415 now_it.mask = 0;
16416 }
16417}
16418
16419static int
16420in_it_block (void)
16421{
16422 if (!now_it.state_handled)
16423 handle_it_state ();
16424
16425 return now_it.state != OUTSIDE_IT_BLOCK;
16426}
16427
c19d1205
ZW
16428void
16429md_assemble (char *str)
b99bd4ef 16430{
c19d1205
ZW
16431 char *p = str;
16432 const struct asm_opcode * opcode;
b99bd4ef 16433
c19d1205
ZW
16434 /* Align the previous label if needed. */
16435 if (last_label_seen != NULL)
b99bd4ef 16436 {
c19d1205
ZW
16437 symbol_set_frag (last_label_seen, frag_now);
16438 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16439 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
16440 }
16441
c19d1205
ZW
16442 memset (&inst, '\0', sizeof (inst));
16443 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 16444
c19d1205
ZW
16445 opcode = opcode_lookup (&p);
16446 if (!opcode)
b99bd4ef 16447 {
c19d1205 16448 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 16449 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
16450 if (! create_register_alias (str, p)
16451 && ! create_neon_reg_alias (str, p))
c19d1205 16452 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 16453
b99bd4ef
NC
16454 return;
16455 }
16456
278df34e 16457 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
16458 as_warn (_("s suffix on comparison instruction is deprecated"));
16459
037e8744
JB
16460 /* The value which unconditional instructions should have in place of the
16461 condition field. */
16462 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16463
c19d1205 16464 if (thumb_mode)
b99bd4ef 16465 {
e74cfd16 16466 arm_feature_set variant;
8f06b2d8
PB
16467
16468 variant = cpu_variant;
16469 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
16470 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16471 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 16472 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
16473 if (!opcode->tvariant
16474 || (thumb_mode == 1
16475 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 16476 {
bf3eeda7 16477 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
16478 return;
16479 }
c19d1205
ZW
16480 if (inst.cond != COND_ALWAYS && !unified_syntax
16481 && opcode->tencode != do_t_branch)
b99bd4ef 16482 {
c19d1205 16483 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
16484 return;
16485 }
16486
752d5da4 16487 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 16488 {
7e806470 16489 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
16490 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16491 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16492 {
16493 /* Two things are addressed here.
16494 1) Implicit require narrow instructions on Thumb-1.
16495 This avoids relaxation accidentally introducing Thumb-2
16496 instructions.
16497 2) Reject wide instructions in non Thumb-2 cores. */
16498 if (inst.size_req == 0)
16499 inst.size_req = 2;
16500 else if (inst.size_req == 4)
16501 {
bf3eeda7 16502 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
16503 return;
16504 }
16505 }
076d447c
PB
16506 }
16507
c19d1205
ZW
16508 inst.instruction = opcode->tvalue;
16509
5be8be5d 16510 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
16511 {
16512 /* Prepare the it_insn_type for those encodings that don't set
16513 it. */
16514 it_fsm_pre_encode ();
c19d1205 16515
e07e6e58
NC
16516 opcode->tencode ();
16517
16518 it_fsm_post_encode ();
16519 }
e27ec89e 16520
0110f2b8 16521 if (!(inst.error || inst.relax))
b99bd4ef 16522 {
9c2799c2 16523 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
16524 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16525 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 16526 {
c19d1205 16527 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
16528 return;
16529 }
16530 }
076d447c
PB
16531
16532 /* Something has gone badly wrong if we try to relax a fixed size
16533 instruction. */
9c2799c2 16534 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 16535
e74cfd16
PB
16536 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16537 *opcode->tvariant);
ee065d83 16538 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 16539 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 16540 anything other than bl/blx and v6-M instructions.
ee065d83 16541 This is overly pessimistic for relaxable instructions. */
7e806470
PB
16542 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16543 || inst.relax)
e07e6e58
NC
16544 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16545 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
16546 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16547 arm_ext_v6t2);
cd000bff 16548
88714cb8
DG
16549 check_neon_suffixes;
16550
cd000bff 16551 if (!inst.error)
c877a2f2
NC
16552 {
16553 mapping_state (MAP_THUMB);
16554 }
c19d1205 16555 }
3e9e4fcf 16556 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 16557 {
845b51d6
PB
16558 bfd_boolean is_bx;
16559
16560 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16561 is_bx = (opcode->aencode == do_bx);
16562
c19d1205 16563 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
16564 if (!(is_bx && fix_v4bx)
16565 && !(opcode->avariant &&
16566 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 16567 {
bf3eeda7 16568 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 16569 return;
b99bd4ef 16570 }
c19d1205 16571 if (inst.size_req)
b99bd4ef 16572 {
c19d1205
ZW
16573 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16574 return;
b99bd4ef
NC
16575 }
16576
c19d1205
ZW
16577 inst.instruction = opcode->avalue;
16578 if (opcode->tag == OT_unconditionalF)
16579 inst.instruction |= 0xF << 28;
16580 else
16581 inst.instruction |= inst.cond << 28;
16582 inst.size = INSN_SIZE;
5be8be5d 16583 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
16584 {
16585 it_fsm_pre_encode ();
16586 opcode->aencode ();
16587 it_fsm_post_encode ();
16588 }
ee065d83
PB
16589 /* Arm mode bx is marked as both v4T and v5 because it's still required
16590 on a hypothetical non-thumb v5 core. */
845b51d6 16591 if (is_bx)
e74cfd16 16592 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 16593 else
e74cfd16
PB
16594 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16595 *opcode->avariant);
88714cb8
DG
16596
16597 check_neon_suffixes;
16598
cd000bff 16599 if (!inst.error)
c877a2f2
NC
16600 {
16601 mapping_state (MAP_ARM);
16602 }
b99bd4ef 16603 }
3e9e4fcf
JB
16604 else
16605 {
16606 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16607 "-- `%s'"), str);
16608 return;
16609 }
c19d1205
ZW
16610 output_inst (str);
16611}
b99bd4ef 16612
e07e6e58
NC
16613static void
16614check_it_blocks_finished (void)
16615{
16616#ifdef OBJ_ELF
16617 asection *sect;
16618
16619 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16620 if (seg_info (sect)->tc_segment_info_data.current_it.state
16621 == MANUAL_IT_BLOCK)
16622 {
16623 as_warn (_("section '%s' finished with an open IT block."),
16624 sect->name);
16625 }
16626#else
16627 if (now_it.state == MANUAL_IT_BLOCK)
16628 as_warn (_("file finished with an open IT block."));
16629#endif
16630}
16631
c19d1205
ZW
16632/* Various frobbings of labels and their addresses. */
16633
16634void
16635arm_start_line_hook (void)
16636{
16637 last_label_seen = NULL;
b99bd4ef
NC
16638}
16639
c19d1205
ZW
16640void
16641arm_frob_label (symbolS * sym)
b99bd4ef 16642{
c19d1205 16643 last_label_seen = sym;
b99bd4ef 16644
c19d1205 16645 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 16646
c19d1205
ZW
16647#if defined OBJ_COFF || defined OBJ_ELF
16648 ARM_SET_INTERWORK (sym, support_interwork);
16649#endif
b99bd4ef 16650
e07e6e58
NC
16651 force_automatic_it_block_close ();
16652
5f4273c7 16653 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
16654 as Thumb functions. This is because these labels, whilst
16655 they exist inside Thumb code, are not the entry points for
16656 possible ARM->Thumb calls. Also, these labels can be used
16657 as part of a computed goto or switch statement. eg gcc
16658 can generate code that looks like this:
b99bd4ef 16659
c19d1205
ZW
16660 ldr r2, [pc, .Laaa]
16661 lsl r3, r3, #2
16662 ldr r2, [r3, r2]
16663 mov pc, r2
b99bd4ef 16664
c19d1205
ZW
16665 .Lbbb: .word .Lxxx
16666 .Lccc: .word .Lyyy
16667 ..etc...
16668 .Laaa: .word Lbbb
b99bd4ef 16669
c19d1205
ZW
16670 The first instruction loads the address of the jump table.
16671 The second instruction converts a table index into a byte offset.
16672 The third instruction gets the jump address out of the table.
16673 The fourth instruction performs the jump.
b99bd4ef 16674
c19d1205
ZW
16675 If the address stored at .Laaa is that of a symbol which has the
16676 Thumb_Func bit set, then the linker will arrange for this address
16677 to have the bottom bit set, which in turn would mean that the
16678 address computation performed by the third instruction would end
16679 up with the bottom bit set. Since the ARM is capable of unaligned
16680 word loads, the instruction would then load the incorrect address
16681 out of the jump table, and chaos would ensue. */
16682 if (label_is_thumb_function_name
16683 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16684 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 16685 {
c19d1205
ZW
16686 /* When the address of a Thumb function is taken the bottom
16687 bit of that address should be set. This will allow
16688 interworking between Arm and Thumb functions to work
16689 correctly. */
b99bd4ef 16690
c19d1205 16691 THUMB_SET_FUNC (sym, 1);
b99bd4ef 16692
c19d1205 16693 label_is_thumb_function_name = FALSE;
b99bd4ef 16694 }
07a53e5c 16695
07a53e5c 16696 dwarf2_emit_label (sym);
b99bd4ef
NC
16697}
16698
c921be7d 16699bfd_boolean
c19d1205 16700arm_data_in_code (void)
b99bd4ef 16701{
c19d1205 16702 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 16703 {
c19d1205
ZW
16704 *input_line_pointer = '/';
16705 input_line_pointer += 5;
16706 *input_line_pointer = 0;
c921be7d 16707 return TRUE;
b99bd4ef
NC
16708 }
16709
c921be7d 16710 return FALSE;
b99bd4ef
NC
16711}
16712
c19d1205
ZW
16713char *
16714arm_canonicalize_symbol_name (char * name)
b99bd4ef 16715{
c19d1205 16716 int len;
b99bd4ef 16717
c19d1205
ZW
16718 if (thumb_mode && (len = strlen (name)) > 5
16719 && streq (name + len - 5, "/data"))
16720 *(name + len - 5) = 0;
b99bd4ef 16721
c19d1205 16722 return name;
b99bd4ef 16723}
c19d1205
ZW
16724\f
16725/* Table of all register names defined by default. The user can
16726 define additional names with .req. Note that all register names
16727 should appear in both upper and lowercase variants. Some registers
16728 also have mixed-case names. */
b99bd4ef 16729
dcbf9037 16730#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 16731#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 16732#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
16733#define REGSET(p,t) \
16734 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16735 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16736 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16737 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
16738#define REGSETH(p,t) \
16739 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16740 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16741 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16742 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16743#define REGSET2(p,t) \
16744 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16745 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16746 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16747 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
16748#define SPLRBANK(base,bank,t) \
16749 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16750 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16751 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16752 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16753 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16754 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 16755
c19d1205 16756static const struct reg_entry reg_names[] =
7ed4c4c5 16757{
c19d1205
ZW
16758 /* ARM integer registers. */
16759 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16760
c19d1205
ZW
16761 /* ATPCS synonyms. */
16762 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16763 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16764 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16765
c19d1205
ZW
16766 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16767 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16768 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16769
c19d1205
ZW
16770 /* Well-known aliases. */
16771 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16772 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16773
16774 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16775 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16776
16777 /* Coprocessor numbers. */
16778 REGSET(p, CP), REGSET(P, CP),
16779
16780 /* Coprocessor register numbers. The "cr" variants are for backward
16781 compatibility. */
16782 REGSET(c, CN), REGSET(C, CN),
16783 REGSET(cr, CN), REGSET(CR, CN),
16784
90ec0d68
MGD
16785 /* ARM banked registers. */
16786 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16787 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16788 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16789 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16790 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16791 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16792 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16793
16794 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16795 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16796 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16797 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16798 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16799 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16800 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16801 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16802
16803 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16804 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16805 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16806 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16807 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16808 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16809 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 16810 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
16811 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16812
c19d1205
ZW
16813 /* FPA registers. */
16814 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16815 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16816
16817 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16818 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16819
16820 /* VFP SP registers. */
5287ad62
JB
16821 REGSET(s,VFS), REGSET(S,VFS),
16822 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16823
16824 /* VFP DP Registers. */
5287ad62
JB
16825 REGSET(d,VFD), REGSET(D,VFD),
16826 /* Extra Neon DP registers. */
16827 REGSETH(d,VFD), REGSETH(D,VFD),
16828
16829 /* Neon QP registers. */
16830 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16831
16832 /* VFP control registers. */
16833 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16834 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16835 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16836 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16837 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16838 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16839
16840 /* Maverick DSP coprocessor registers. */
16841 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16842 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16843
16844 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16845 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16846 REGDEF(dspsc,0,DSPSC),
16847
16848 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16849 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16850 REGDEF(DSPSC,0,DSPSC),
16851
16852 /* iWMMXt data registers - p0, c0-15. */
16853 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16854
16855 /* iWMMXt control registers - p1, c0-3. */
16856 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16857 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16858 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16859 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16860
16861 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16862 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16863 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16864 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16865 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16866
16867 /* XScale accumulator registers. */
16868 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16869};
16870#undef REGDEF
16871#undef REGNUM
16872#undef REGSET
7ed4c4c5 16873
c19d1205
ZW
16874/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16875 within psr_required_here. */
16876static const struct asm_psr psrs[] =
16877{
16878 /* Backward compatibility notation. Note that "all" is no longer
16879 truly all possible PSR bits. */
16880 {"all", PSR_c | PSR_f},
16881 {"flg", PSR_f},
16882 {"ctl", PSR_c},
16883
16884 /* Individual flags. */
16885 {"f", PSR_f},
16886 {"c", PSR_c},
16887 {"x", PSR_x},
16888 {"s", PSR_s},
59b42a0d 16889
c19d1205
ZW
16890 /* Combinations of flags. */
16891 {"fs", PSR_f | PSR_s},
16892 {"fx", PSR_f | PSR_x},
16893 {"fc", PSR_f | PSR_c},
16894 {"sf", PSR_s | PSR_f},
16895 {"sx", PSR_s | PSR_x},
16896 {"sc", PSR_s | PSR_c},
16897 {"xf", PSR_x | PSR_f},
16898 {"xs", PSR_x | PSR_s},
16899 {"xc", PSR_x | PSR_c},
16900 {"cf", PSR_c | PSR_f},
16901 {"cs", PSR_c | PSR_s},
16902 {"cx", PSR_c | PSR_x},
16903 {"fsx", PSR_f | PSR_s | PSR_x},
16904 {"fsc", PSR_f | PSR_s | PSR_c},
16905 {"fxs", PSR_f | PSR_x | PSR_s},
16906 {"fxc", PSR_f | PSR_x | PSR_c},
16907 {"fcs", PSR_f | PSR_c | PSR_s},
16908 {"fcx", PSR_f | PSR_c | PSR_x},
16909 {"sfx", PSR_s | PSR_f | PSR_x},
16910 {"sfc", PSR_s | PSR_f | PSR_c},
16911 {"sxf", PSR_s | PSR_x | PSR_f},
16912 {"sxc", PSR_s | PSR_x | PSR_c},
16913 {"scf", PSR_s | PSR_c | PSR_f},
16914 {"scx", PSR_s | PSR_c | PSR_x},
16915 {"xfs", PSR_x | PSR_f | PSR_s},
16916 {"xfc", PSR_x | PSR_f | PSR_c},
16917 {"xsf", PSR_x | PSR_s | PSR_f},
16918 {"xsc", PSR_x | PSR_s | PSR_c},
16919 {"xcf", PSR_x | PSR_c | PSR_f},
16920 {"xcs", PSR_x | PSR_c | PSR_s},
16921 {"cfs", PSR_c | PSR_f | PSR_s},
16922 {"cfx", PSR_c | PSR_f | PSR_x},
16923 {"csf", PSR_c | PSR_s | PSR_f},
16924 {"csx", PSR_c | PSR_s | PSR_x},
16925 {"cxf", PSR_c | PSR_x | PSR_f},
16926 {"cxs", PSR_c | PSR_x | PSR_s},
16927 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16928 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16929 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16930 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16931 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16932 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16933 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16934 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16935 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16936 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16937 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16938 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16939 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16940 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16941 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16942 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16943 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16944 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16945 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16946 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16947 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16948 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16949 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16950 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16951};
16952
62b3e311
PB
16953/* Table of V7M psr names. */
16954static const struct asm_psr v7m_psrs[] =
16955{
2b744c99
PB
16956 {"apsr", 0 }, {"APSR", 0 },
16957 {"iapsr", 1 }, {"IAPSR", 1 },
16958 {"eapsr", 2 }, {"EAPSR", 2 },
16959 {"psr", 3 }, {"PSR", 3 },
16960 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16961 {"ipsr", 5 }, {"IPSR", 5 },
16962 {"epsr", 6 }, {"EPSR", 6 },
16963 {"iepsr", 7 }, {"IEPSR", 7 },
16964 {"msp", 8 }, {"MSP", 8 },
16965 {"psp", 9 }, {"PSP", 9 },
16966 {"primask", 16}, {"PRIMASK", 16},
16967 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
16968 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16969 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
16970 {"faultmask", 19}, {"FAULTMASK", 19},
16971 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16972};
16973
c19d1205
ZW
16974/* Table of all shift-in-operand names. */
16975static const struct asm_shift_name shift_names [] =
b99bd4ef 16976{
c19d1205
ZW
16977 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16978 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16979 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16980 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16981 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16982 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16983};
b99bd4ef 16984
c19d1205
ZW
16985/* Table of all explicit relocation names. */
16986#ifdef OBJ_ELF
16987static struct reloc_entry reloc_names[] =
16988{
16989 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16990 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16991 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16992 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16993 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16994 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16995 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16996 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16997 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16998 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 16999 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
17000 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17001 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
17002 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
17003 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
17004 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
17005 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
17006 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
17007};
17008#endif
b99bd4ef 17009
c19d1205
ZW
17010/* Table of all conditional affixes. 0xF is not defined as a condition code. */
17011static const struct asm_cond conds[] =
17012{
17013 {"eq", 0x0},
17014 {"ne", 0x1},
17015 {"cs", 0x2}, {"hs", 0x2},
17016 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17017 {"mi", 0x4},
17018 {"pl", 0x5},
17019 {"vs", 0x6},
17020 {"vc", 0x7},
17021 {"hi", 0x8},
17022 {"ls", 0x9},
17023 {"ge", 0xa},
17024 {"lt", 0xb},
17025 {"gt", 0xc},
17026 {"le", 0xd},
17027 {"al", 0xe}
17028};
bfae80f2 17029
62b3e311
PB
17030static struct asm_barrier_opt barrier_opt_names[] =
17031{
52e7f43d
RE
17032 { "sy", 0xf }, { "SY", 0xf },
17033 { "un", 0x7 }, { "UN", 0x7 },
17034 { "st", 0xe }, { "ST", 0xe },
17035 { "unst", 0x6 }, { "UNST", 0x6 },
17036 { "ish", 0xb }, { "ISH", 0xb },
17037 { "sh", 0xb }, { "SH", 0xb },
17038 { "ishst", 0xa }, { "ISHST", 0xa },
17039 { "shst", 0xa }, { "SHST", 0xa },
17040 { "nsh", 0x7 }, { "NSH", 0x7 },
17041 { "nshst", 0x6 }, { "NSHST", 0x6 },
17042 { "osh", 0x3 }, { "OSH", 0x3 },
17043 { "oshst", 0x2 }, { "OSHST", 0x2 }
62b3e311
PB
17044};
17045
c19d1205
ZW
17046/* Table of ARM-format instructions. */
17047
17048/* Macros for gluing together operand strings. N.B. In all cases
17049 other than OPS0, the trailing OP_stop comes from default
17050 zero-initialization of the unspecified elements of the array. */
17051#define OPS0() { OP_stop, }
17052#define OPS1(a) { OP_##a, }
17053#define OPS2(a,b) { OP_##a,OP_##b, }
17054#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17055#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17056#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17057#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17058
5be8be5d
DG
17059/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17060 This is useful when mixing operands for ARM and THUMB, i.e. using the
17061 MIX_ARM_THUMB_OPERANDS macro.
17062 In order to use these macros, prefix the number of operands with _
17063 e.g. _3. */
17064#define OPS_1(a) { a, }
17065#define OPS_2(a,b) { a,b, }
17066#define OPS_3(a,b,c) { a,b,c, }
17067#define OPS_4(a,b,c,d) { a,b,c,d, }
17068#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17069#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17070
c19d1205
ZW
17071/* These macros abstract out the exact format of the mnemonic table and
17072 save some repeated characters. */
17073
17074/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17075#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17076 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 17077 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17078
17079/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17080 a T_MNEM_xyz enumerator. */
17081#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17082 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17083#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17084 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17085
17086/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17087 infix after the third character. */
17088#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 17089 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 17090 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 17091#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 17092 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 17093 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 17094#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17095 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 17096#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 17097 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 17098#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17099 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 17100#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 17101 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17102
17103/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
17104 appear in the condition table. */
17105#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 17106 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 17107 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17108
17109#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
17110 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
17111 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
17112 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
17113 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
17114 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
17115 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
17116 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
17117 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
17118 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
17119 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
17120 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
17121 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
17122 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
17123 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
17124 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
17125 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
17126 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
17127 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
17128 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
17129
17130#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
17131 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
17132#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 17133 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
17134
17135/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
17136 field is still 0xE. Many of the Thumb variants can be executed
17137 conditionally, so this is checked separately. */
c19d1205 17138#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 17139 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17140 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17141
17142/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17143 condition code field. */
17144#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 17145 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 17146 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
17147
17148/* ARM-only variants of all the above. */
6a86118a 17149#define CE(mnem, op, nops, ops, ae) \
21d799b5 17150 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
17151
17152#define C3(mnem, op, nops, ops, ae) \
17153 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17154
e3cb604e
PB
17155/* Legacy mnemonics that always have conditional infix after the third
17156 character. */
17157#define CL(mnem, op, nops, ops, ae) \
21d799b5 17158 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17159 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17160
8f06b2d8
PB
17161/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17162#define cCE(mnem, op, nops, ops, ae) \
21d799b5 17163 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17164
e3cb604e
PB
17165/* Legacy coprocessor instructions where conditional infix and conditional
17166 suffix are ambiguous. For consistency this includes all FPA instructions,
17167 not just the potentially ambiguous ones. */
17168#define cCL(mnem, op, nops, ops, ae) \
21d799b5 17169 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
17170 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17171
17172/* Coprocessor, takes either a suffix or a position-3 infix
17173 (for an FPA corner case). */
17174#define C3E(mnem, op, nops, ops, ae) \
21d799b5 17175 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 17176 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 17177
6a86118a 17178#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
17179 { m1 #m2 m3, OPS##nops ops, \
17180 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
17181 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17182
17183#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
17184 xCM_ (m1, , m2, op, nops, ops, ae), \
17185 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17186 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17187 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17188 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17189 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17190 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17191 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17192 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17193 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17194 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17195 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17196 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17197 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17198 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17199 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17200 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17201 xCM_ (m1, le, m2, op, nops, ops, ae), \
17202 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
17203
17204#define UE(mnem, op, nops, ops, ae) \
17205 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17206
17207#define UF(mnem, op, nops, ops, ae) \
17208 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17209
5287ad62
JB
17210/* Neon data-processing. ARM versions are unconditional with cond=0xf.
17211 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17212 use the same encoding function for each. */
17213#define NUF(mnem, op, nops, ops, enc) \
17214 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17215 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17216
17217/* Neon data processing, version which indirects through neon_enc_tab for
17218 the various overloaded versions of opcodes. */
17219#define nUF(mnem, op, nops, ops, enc) \
21d799b5 17220 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17221 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17222
17223/* Neon insn with conditional suffix for the ARM version, non-overloaded
17224 version. */
037e8744
JB
17225#define NCE_tag(mnem, op, nops, ops, enc, tag) \
17226 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
17227 THUMB_VARIANT, do_##enc, do_##enc }
17228
037e8744 17229#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 17230 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17231
17232#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 17233 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17234
5287ad62 17235/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 17236#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 17237 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
17238 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17239
037e8744 17240#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 17241 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
17242
17243#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 17244 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 17245
c19d1205
ZW
17246#define do_0 0
17247
c19d1205 17248static const struct asm_opcode insns[] =
bfae80f2 17249{
e74cfd16
PB
17250#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17251#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
17252 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17253 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17254 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17255 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17256 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17257 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17258 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17259 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17260 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17261 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17262 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17263 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17264 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17265 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17266 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17267 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
17268
17269 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17270 for setting PSR flag bits. They are obsolete in V6 and do not
17271 have Thumb equivalents. */
21d799b5
NC
17272 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17273 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17274 CL("tstp", 110f000, 2, (RR, SH), cmp),
17275 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17276 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17277 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17278 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17279 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17280 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17281
17282 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17283 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17284 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17285 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17286
17287 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
17288 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17289 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17290 OP_RRnpc),
17291 OP_ADDRGLDR),ldst, t_ldst),
17292 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
17293
17294 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17295 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17296 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17297 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17298 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17299 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17300
17301 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17302 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17303 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17304 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 17305
c19d1205 17306 /* Pseudo ops. */
21d799b5 17307 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 17308 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 17309 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
17310
17311 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
17312 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17313 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17314 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17315 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17316 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17317 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17318 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17319 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17320 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17321 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17322 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17323 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 17324
16a4cf17 17325 /* These may simplify to neg. */
21d799b5
NC
17326 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17327 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 17328
c921be7d
NC
17329#undef THUMB_VARIANT
17330#define THUMB_VARIANT & arm_ext_v6
17331
21d799b5 17332 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
17333
17334 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
17335#undef THUMB_VARIANT
17336#define THUMB_VARIANT & arm_ext_v6t2
17337
21d799b5
NC
17338 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17339 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17340 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 17341
5be8be5d
DG
17342 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17343 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17344 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17345 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 17346
21d799b5
NC
17347 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17348 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 17349
21d799b5
NC
17350 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17351 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
17352
17353 /* V1 instructions with no Thumb analogue at all. */
21d799b5 17354 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
17355 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17356
17357 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17358 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17359 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17360 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17361 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17362 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17363 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17364 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17365
c921be7d
NC
17366#undef ARM_VARIANT
17367#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17368#undef THUMB_VARIANT
17369#define THUMB_VARIANT & arm_ext_v4t
17370
21d799b5
NC
17371 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17372 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 17373
c921be7d
NC
17374#undef THUMB_VARIANT
17375#define THUMB_VARIANT & arm_ext_v6t2
17376
21d799b5 17377 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
17378 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17379
17380 /* Generic coprocessor instructions. */
21d799b5
NC
17381 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17382 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17383 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17384 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17385 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17386 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 17387 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17388
c921be7d
NC
17389#undef ARM_VARIANT
17390#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17391
21d799b5 17392 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
17393 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17394
c921be7d
NC
17395#undef ARM_VARIANT
17396#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17397#undef THUMB_VARIANT
17398#define THUMB_VARIANT & arm_ext_msr
17399
d2cd1205
JB
17400 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17401 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 17402
c921be7d
NC
17403#undef ARM_VARIANT
17404#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17405#undef THUMB_VARIANT
17406#define THUMB_VARIANT & arm_ext_v6t2
17407
21d799b5
NC
17408 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17409 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17410 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17411 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17412 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17413 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17414 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17415 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 17416
c921be7d
NC
17417#undef ARM_VARIANT
17418#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17419#undef THUMB_VARIANT
17420#define THUMB_VARIANT & arm_ext_v4t
17421
5be8be5d
DG
17422 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17423 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17424 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17425 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17426 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17427 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 17428
c921be7d
NC
17429#undef ARM_VARIANT
17430#define ARM_VARIANT & arm_ext_v4t_5
17431
c19d1205
ZW
17432 /* ARM Architecture 4T. */
17433 /* Note: bx (and blx) are required on V5, even if the processor does
17434 not support Thumb. */
21d799b5 17435 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 17436
c921be7d
NC
17437#undef ARM_VARIANT
17438#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17439#undef THUMB_VARIANT
17440#define THUMB_VARIANT & arm_ext_v5t
17441
c19d1205
ZW
17442 /* Note: blx has 2 variants; the .value coded here is for
17443 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
17444 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17445 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 17446
c921be7d
NC
17447#undef THUMB_VARIANT
17448#define THUMB_VARIANT & arm_ext_v6t2
17449
21d799b5
NC
17450 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17451 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17452 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17453 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17454 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17455 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17456 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17457 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 17458
c921be7d
NC
17459#undef ARM_VARIANT
17460#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
17461#undef THUMB_VARIANT
17462#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 17463
21d799b5
NC
17464 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17465 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17466 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17467 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17468
21d799b5
NC
17469 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17470 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 17471
21d799b5
NC
17472 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17473 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17474 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17475 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 17476
21d799b5
NC
17477 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17478 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17479 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17480 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17481
21d799b5
NC
17482 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17483 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 17484
03ee1b7f
NC
17485 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17486 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17487 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17488 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 17489
c921be7d
NC
17490#undef ARM_VARIANT
17491#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
17492#undef THUMB_VARIANT
17493#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 17494
21d799b5 17495 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
17496 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17497 ldrd, t_ldstd),
17498 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17499 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 17500
21d799b5
NC
17501 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17502 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 17503
c921be7d
NC
17504#undef ARM_VARIANT
17505#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17506
21d799b5 17507 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 17508
c921be7d
NC
17509#undef ARM_VARIANT
17510#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17511#undef THUMB_VARIANT
17512#define THUMB_VARIANT & arm_ext_v6
17513
21d799b5
NC
17514 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17515 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17516 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17517 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17518 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17519 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17520 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17521 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17522 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17523 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 17524
c921be7d
NC
17525#undef THUMB_VARIANT
17526#define THUMB_VARIANT & arm_ext_v6t2
17527
5be8be5d
DG
17528 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17529 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17530 strex, t_strex),
21d799b5
NC
17531 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17532 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 17533
21d799b5
NC
17534 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17535 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 17536
9e3c6df6 17537/* ARM V6 not included in V7M. */
c921be7d
NC
17538#undef THUMB_VARIANT
17539#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
17540 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17541 UF(rfeib, 9900a00, 1, (RRw), rfe),
17542 UF(rfeda, 8100a00, 1, (RRw), rfe),
17543 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17544 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17545 UF(rfefa, 9900a00, 1, (RRw), rfe),
17546 UF(rfeea, 8100a00, 1, (RRw), rfe),
17547 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17548 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17549 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17550 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17551 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 17552
9e3c6df6
PB
17553/* ARM V6 not included in V7M (eg. integer SIMD). */
17554#undef THUMB_VARIANT
17555#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
17556 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17557 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17558 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17559 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17560 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17561 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17562 /* Old name for QASX. */
21d799b5
NC
17563 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17564 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17565 /* Old name for QSAX. */
21d799b5
NC
17566 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17567 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17568 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17569 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17570 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17571 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17572 /* Old name for SASX. */
21d799b5
NC
17573 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17574 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17575 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17576 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17577 /* Old name for SHASX. */
21d799b5
NC
17578 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17579 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17580 /* Old name for SHSAX. */
21d799b5
NC
17581 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17582 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17583 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17584 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17585 /* Old name for SSAX. */
21d799b5
NC
17586 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17587 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17588 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17589 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17590 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17591 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17592 /* Old name for UASX. */
21d799b5
NC
17593 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17594 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17595 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17596 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17597 /* Old name for UHASX. */
21d799b5
NC
17598 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17599 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17600 /* Old name for UHSAX. */
21d799b5
NC
17601 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17602 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17603 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17604 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17605 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17606 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17607 /* Old name for UQASX. */
21d799b5
NC
17608 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17609 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17610 /* Old name for UQSAX. */
21d799b5
NC
17611 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17612 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17613 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17614 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17615 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 17616 /* Old name for USAX. */
21d799b5
NC
17617 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17618 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
17619 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17620 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17621 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17622 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17623 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17624 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17625 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17626 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17627 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17628 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17629 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17630 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17631 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17632 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17633 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17634 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17635 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17636 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17637 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17638 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17639 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17640 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17641 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17642 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17643 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17644 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17645 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
17646 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17647 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17648 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17649 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17650 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 17651
c921be7d
NC
17652#undef ARM_VARIANT
17653#define ARM_VARIANT & arm_ext_v6k
17654#undef THUMB_VARIANT
17655#define THUMB_VARIANT & arm_ext_v6k
17656
21d799b5
NC
17657 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17658 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17659 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17660 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 17661
c921be7d
NC
17662#undef THUMB_VARIANT
17663#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
17664 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17665 ldrexd, t_ldrexd),
17666 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17667 RRnpcb), strexd, t_strexd),
ebdca51a 17668
c921be7d
NC
17669#undef THUMB_VARIANT
17670#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
17671 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17672 rd_rn, rd_rn),
17673 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17674 rd_rn, rd_rn),
17675 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 17676 strex, t_strexbh),
5be8be5d 17677 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 17678 strex, t_strexbh),
21d799b5 17679 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 17680
c921be7d 17681#undef ARM_VARIANT
f4c65163
MGD
17682#define ARM_VARIANT & arm_ext_sec
17683#undef THUMB_VARIANT
17684#define THUMB_VARIANT & arm_ext_sec
c921be7d 17685
21d799b5 17686 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 17687
90ec0d68
MGD
17688#undef ARM_VARIANT
17689#define ARM_VARIANT & arm_ext_virt
17690#undef THUMB_VARIANT
17691#define THUMB_VARIANT & arm_ext_virt
17692
17693 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17694 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17695
c921be7d
NC
17696#undef ARM_VARIANT
17697#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
17698#undef THUMB_VARIANT
17699#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 17700
21d799b5
NC
17701 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17702 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17703 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17704 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 17705
21d799b5
NC
17706 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17707 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17708 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17709 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 17710
5be8be5d
DG
17711 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17712 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17713 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17714 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 17715
bf3eeda7
NS
17716 /* Thumb-only instructions. */
17717#undef ARM_VARIANT
17718#define ARM_VARIANT NULL
17719 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17720 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
17721
17722 /* ARM does not really have an IT instruction, so always allow it.
17723 The opcode is copied from Thumb in order to allow warnings in
17724 -mimplicit-it=[never | arm] modes. */
17725#undef ARM_VARIANT
17726#define ARM_VARIANT & arm_ext_v1
17727
21d799b5
NC
17728 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17729 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17730 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17731 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17732 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17733 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17734 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17735 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17736 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17737 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17738 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17739 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17740 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17741 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17742 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 17743 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
17744 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17745 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 17746
92e90b6e 17747 /* Thumb2 only instructions. */
c921be7d
NC
17748#undef ARM_VARIANT
17749#define ARM_VARIANT NULL
92e90b6e 17750
21d799b5
NC
17751 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17752 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17753 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17754 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17755 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17756 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 17757
eea54501
MGD
17758 /* Hardware division instructions. */
17759#undef ARM_VARIANT
17760#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
17761#undef THUMB_VARIANT
17762#define THUMB_VARIANT & arm_ext_div
17763
eea54501
MGD
17764 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17765 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 17766
7e806470 17767 /* ARM V6M/V7 instructions. */
c921be7d
NC
17768#undef ARM_VARIANT
17769#define ARM_VARIANT & arm_ext_barrier
17770#undef THUMB_VARIANT
17771#define THUMB_VARIANT & arm_ext_barrier
17772
52e7f43d
RE
17773 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17774 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17775 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
7e806470 17776
62b3e311 17777 /* ARM V7 instructions. */
c921be7d
NC
17778#undef ARM_VARIANT
17779#define ARM_VARIANT & arm_ext_v7
17780#undef THUMB_VARIANT
17781#define THUMB_VARIANT & arm_ext_v7
17782
21d799b5
NC
17783 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17784 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 17785
60e5ef9f
MGD
17786#undef ARM_VARIANT
17787#define ARM_VARIANT & arm_ext_mp
17788#undef THUMB_VARIANT
17789#define THUMB_VARIANT & arm_ext_mp
17790
17791 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17792
c921be7d
NC
17793#undef ARM_VARIANT
17794#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17795
21d799b5
NC
17796 cCE("wfs", e200110, 1, (RR), rd),
17797 cCE("rfs", e300110, 1, (RR), rd),
17798 cCE("wfc", e400110, 1, (RR), rd),
17799 cCE("rfc", e500110, 1, (RR), rd),
17800
17801 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17802 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17803 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17804 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17805
17806 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17807 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17808 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17809 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17810
17811 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17812 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17813 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17814 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17815 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17816 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17817 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17818 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17819 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17820 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17821 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17822 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17823
17824 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17825 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17826 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17827 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17828 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17829 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17830 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17831 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17832 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17833 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17834 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17835 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17836
17837 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17838 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17839 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17840 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17841 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17842 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17843 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17844 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17845 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17846 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17847 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17848 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17849
17850 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17851 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17852 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17853 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17854 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17855 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17856 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17857 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17858 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17859 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17860 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17861 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17862
17863 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17864 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17865 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17866 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17867 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17868 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17869 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17870 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17871 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17872 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17873 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17874 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17875
17876 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17877 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17878 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17879 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17880 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17881 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17882 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17883 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17884 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17885 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17886 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17887 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17888
17889 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17890 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17891 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17892 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17893 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17894 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17895 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17896 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17897 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17898 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17899 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17900 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17901
17902 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17903 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17904 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17905 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17906 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17907 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17908 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17909 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17910 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17911 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17912 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17913 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17914
17915 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17916 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17917 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17918 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17919 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17920 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17921 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17922 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17923 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17924 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17925 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17926 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17927
17928 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17929 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17930 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17931 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17932 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17933 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17934 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17935 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17936 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17937 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17938 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17939 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17940
17941 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17942 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17943 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17944 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17945 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17946 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17947 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17948 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17949 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17950 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17951 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17952 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17953
17954 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17955 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17956 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17957 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17958 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17959 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17960 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17961 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17962 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17963 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17964 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17965 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17966
17967 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17968 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17969 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17970 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17971 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17972 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17973 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17974 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17975 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17976 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17977 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17978 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17979
17980 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17981 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17982 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17983 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17984 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17985 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17986 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17987 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17988 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17989 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17990 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17991 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17992
17993 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17994 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17995 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17996 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17997 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17998 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17999 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
18000 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
18001 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
18002 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
18003 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
18004 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
18005
18006 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
18007 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
18008 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
18009 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
18010 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
18011 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
18012 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
18013 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
18014 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
18015 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
18016 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
18017 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
18018
18019 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
18020 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
18021 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
18022 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
18023 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
18024 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18025 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18026 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18027 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18028 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18029 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18030 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18031
18032 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18033 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18034 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18035 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18036 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18037 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18038 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18039 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18040 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18041 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18042 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18043 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18044
18045 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18046 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18047 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18048 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18049 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18050 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18051 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18052 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18053 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18054 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18055 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18056 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18057
18058 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18059 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18060 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18061 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18062 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18063 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18064 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18065 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18066 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18067 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18068 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18069 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18070
18071 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18072 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18073 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18074 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18075 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18076 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18077 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18078 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18079 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18080 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18081 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18082 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18083
18084 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18085 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18086 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18087 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18088 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18089 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18090 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18091 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18092 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18093 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18094 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18095 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18096
18097 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18098 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18099 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18100 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18101 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18102 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18103 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18104 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18105 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18106 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18107 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18108 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18109
18110 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18111 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18112 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18113 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18114 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18115 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18116 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18117 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18118 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18119 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18120 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18121 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18122
18123 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18124 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18125 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18126 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18127 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18128 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18129 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18130 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18131 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18132 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18133 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18134 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18135
18136 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18137 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18138 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18139 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18140 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18141 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18142 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18143 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18144 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18145 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18146 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18147 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18148
18149 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18150 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18151 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18152 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18153 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18154 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18155 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18156 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18157 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18158 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18159 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18160 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18161
18162 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18163 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18164 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18165 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18166 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18167 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18168 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18169 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18170 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18171 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18172 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18173 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18174
18175 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18176 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18177 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18178 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18179 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18180 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18181 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18182 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18183 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18184 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18185 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18186 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18187
18188 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18189 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18190 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18191 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18192
18193 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18194 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18195 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18196 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18197 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18198 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18199 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18200 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18201 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18202 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18203 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18204 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 18205
c19d1205
ZW
18206 /* The implementation of the FIX instruction is broken on some
18207 assemblers, in that it accepts a precision specifier as well as a
18208 rounding specifier, despite the fact that this is meaningless.
18209 To be more compatible, we accept it as well, though of course it
18210 does not set any bits. */
21d799b5
NC
18211 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18212 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18213 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18214 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18215 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18216 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18217 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18218 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18219 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18220 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18221 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18222 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18223 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 18224
c19d1205 18225 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
18226#undef ARM_VARIANT
18227#define ARM_VARIANT & fpu_fpa_ext_v2
18228
21d799b5
NC
18229 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18230 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18231 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18232 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18233 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18234 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 18235
c921be7d
NC
18236#undef ARM_VARIANT
18237#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18238
c19d1205 18239 /* Moves and type conversions. */
21d799b5
NC
18240 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18241 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18242 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18243 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
18244 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18245 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
18246 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18247 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18248 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18249 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18250 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18251 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18252 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18253 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
18254
18255 /* Memory operations. */
21d799b5
NC
18256 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18257 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
18258 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18259 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18260 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18261 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18262 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18263 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18264 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18265 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18266 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18267 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18268 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18269 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18270 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18271 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18272 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18273 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 18274
c19d1205 18275 /* Monadic operations. */
21d799b5
NC
18276 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18277 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18278 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
18279
18280 /* Dyadic operations. */
21d799b5
NC
18281 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18282 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18283 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18284 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18285 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18286 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18287 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18288 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18289 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 18290
c19d1205 18291 /* Comparisons. */
21d799b5
NC
18292 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18293 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18294 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18295 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 18296
62f3b8c8
PB
18297 /* Double precision load/store are still present on single precision
18298 implementations. */
18299 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18300 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
18301 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18302 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18303 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18304 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18305 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18306 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18307 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18308 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 18309
c921be7d
NC
18310#undef ARM_VARIANT
18311#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18312
c19d1205 18313 /* Moves and type conversions. */
21d799b5
NC
18314 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18315 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18316 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18317 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18318 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18319 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18320 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18321 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18322 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18323 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18324 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18325 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18326 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 18327
c19d1205 18328 /* Monadic operations. */
21d799b5
NC
18329 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18330 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18331 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
18332
18333 /* Dyadic operations. */
21d799b5
NC
18334 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18335 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18336 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18337 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18338 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18339 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18340 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18341 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18342 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 18343
c19d1205 18344 /* Comparisons. */
21d799b5
NC
18345 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18346 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18347 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18348 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 18349
c921be7d
NC
18350#undef ARM_VARIANT
18351#define ARM_VARIANT & fpu_vfp_ext_v2
18352
21d799b5
NC
18353 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18354 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18355 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18356 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 18357
037e8744
JB
18358/* Instructions which may belong to either the Neon or VFP instruction sets.
18359 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
18360#undef ARM_VARIANT
18361#define ARM_VARIANT & fpu_vfp_ext_v1xd
18362#undef THUMB_VARIANT
18363#define THUMB_VARIANT & fpu_vfp_ext_v1xd
18364
037e8744
JB
18365 /* These mnemonics are unique to VFP. */
18366 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18367 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
18368 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18369 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18370 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18371 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18372 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
18373 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18374 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18375 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18376
18377 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
18378 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18379 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18380 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 18381
21d799b5
NC
18382 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18383 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
18384
18385 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18386 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18387
55881a11
MGD
18388 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18389 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18390 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18391 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18392 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18393 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
18394 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18395 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 18396
5f1af56b 18397 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 18398 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
18399 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18400 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 18401
037e8744
JB
18402
18403 /* NOTE: All VMOV encoding is special-cased! */
18404 NCE(vmov, 0, 1, (VMOV), neon_mov),
18405 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18406
c921be7d
NC
18407#undef THUMB_VARIANT
18408#define THUMB_VARIANT & fpu_neon_ext_v1
18409#undef ARM_VARIANT
18410#define ARM_VARIANT & fpu_neon_ext_v1
18411
5287ad62
JB
18412 /* Data processing with three registers of the same length. */
18413 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18414 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18415 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18416 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18417 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18418 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18419 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18420 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18421 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18422 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18423 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18424 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18425 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18426 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
18427 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18428 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18429 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18430 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
18431 /* If not immediate, fall back to neon_dyadic_i64_su.
18432 shl_imm should accept I8 I16 I32 I64,
18433 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
18434 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18435 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18436 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18437 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 18438 /* Logic ops, types optional & ignored. */
4316f0d2
DG
18439 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18440 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18441 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18442 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18443 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18444 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18445 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18446 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18447 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18448 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
18449 /* Bitfield ops, untyped. */
18450 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18451 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18452 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18453 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18454 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18455 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18456 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
18457 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18458 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18459 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18460 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18461 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18462 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
18463 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18464 back to neon_dyadic_if_su. */
21d799b5
NC
18465 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18466 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18467 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18468 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18469 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18470 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18471 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18472 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 18473 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
18474 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18475 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 18476 /* As above, D registers only. */
21d799b5
NC
18477 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18478 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 18479 /* Int and float variants, signedness unimportant. */
21d799b5
NC
18480 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18481 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18482 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 18483 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
18484 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18485 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
18486 /* vtst takes sizes 8, 16, 32. */
18487 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18488 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18489 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 18490 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 18491 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
18492 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18493 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18494 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18495 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
18496 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18497 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18498 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18499 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
18500 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18501 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18502 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18503 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
18504 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18505 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18506 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18507 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18508
18509 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 18510 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
18511 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18512
18513 /* Data processing with two registers and a shift amount. */
18514 /* Right shifts, and variants with rounding.
18515 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18516 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18517 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18518 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18519 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18520 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18521 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18522 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18523 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18524 /* Shift and insert. Sizes accepted 8 16 32 64. */
18525 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18526 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18527 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18528 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18529 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18530 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18531 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18532 /* Right shift immediate, saturating & narrowing, with rounding variants.
18533 Types accepted S16 S32 S64 U16 U32 U64. */
18534 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18535 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18536 /* As above, unsigned. Types accepted S16 S32 S64. */
18537 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18538 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18539 /* Right shift narrowing. Types accepted I16 I32 I64. */
18540 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18541 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18542 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 18543 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 18544 /* CVT with optional immediate for fixed-point variant. */
21d799b5 18545 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 18546
4316f0d2
DG
18547 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18548 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
18549
18550 /* Data processing, three registers of different lengths. */
18551 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18552 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18553 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18554 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18555 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18556 /* If not scalar, fall back to neon_dyadic_long.
18557 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
18558 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18559 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
18560 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18561 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18562 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18563 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18564 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18565 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18566 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18567 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18568 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
18569 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18570 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18571 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
18572 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18573 S16 S32 U16 U32. */
21d799b5 18574 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
18575
18576 /* Extract. Size 8. */
3b8d421e
PB
18577 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18578 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
18579
18580 /* Two registers, miscellaneous. */
18581 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18582 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18583 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18584 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18585 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18586 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18587 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18588 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
18589 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18590 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
18591 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18592 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18593 /* VMOVN. Types I16 I32 I64. */
21d799b5 18594 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 18595 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 18596 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 18597 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 18598 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
18599 /* VZIP / VUZP. Sizes 8 16 32. */
18600 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18601 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18602 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18603 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18604 /* VQABS / VQNEG. Types S8 S16 S32. */
18605 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18606 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18607 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18608 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18609 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18610 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18611 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18612 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18613 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18614 /* Reciprocal estimates. Types U32 F32. */
18615 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18616 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18617 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18618 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18619 /* VCLS. Types S8 S16 S32. */
18620 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18621 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18622 /* VCLZ. Types I8 I16 I32. */
18623 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18624 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18625 /* VCNT. Size 8. */
18626 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18627 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18628 /* Two address, untyped. */
18629 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18630 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18631 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
18632 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18633 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
18634
18635 /* Table lookup. Size 8. */
18636 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18637 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18638
c921be7d
NC
18639#undef THUMB_VARIANT
18640#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18641#undef ARM_VARIANT
18642#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18643
5287ad62 18644 /* Neon element/structure load/store. */
21d799b5
NC
18645 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18646 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18647 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18648 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18649 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18650 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18651 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18652 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 18653
c921be7d 18654#undef THUMB_VARIANT
62f3b8c8
PB
18655#define THUMB_VARIANT &fpu_vfp_ext_v3xd
18656#undef ARM_VARIANT
18657#define ARM_VARIANT &fpu_vfp_ext_v3xd
18658 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18659 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18660 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18661 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18662 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18663 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18664 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18665 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18666 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18667
18668#undef THUMB_VARIANT
c921be7d
NC
18669#define THUMB_VARIANT & fpu_vfp_ext_v3
18670#undef ARM_VARIANT
18671#define ARM_VARIANT & fpu_vfp_ext_v3
18672
21d799b5 18673 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 18674 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18675 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18676 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18677 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18678 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18679 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 18680 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 18681 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 18682
62f3b8c8
PB
18683#undef ARM_VARIANT
18684#define ARM_VARIANT &fpu_vfp_ext_fma
18685#undef THUMB_VARIANT
18686#define THUMB_VARIANT &fpu_vfp_ext_fma
18687 /* Mnemonics shared by Neon and VFP. These are included in the
18688 VFP FMA variant; NEON and VFP FMA always includes the NEON
18689 FMA instructions. */
18690 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18691 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18692 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18693 the v form should always be used. */
18694 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18695 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18696 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18697 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18698 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18699 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18700
5287ad62 18701#undef THUMB_VARIANT
c921be7d
NC
18702#undef ARM_VARIANT
18703#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18704
21d799b5
NC
18705 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18706 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18707 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18708 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18709 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18710 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18711 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18712 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 18713
c921be7d
NC
18714#undef ARM_VARIANT
18715#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18716
21d799b5
NC
18717 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18718 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18719 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18720 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18721 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18722 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18723 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18724 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18725 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18726 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18727 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18728 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18729 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18730 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18731 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18732 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18733 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18734 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18735 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18736 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18737 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18738 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18739 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18740 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18741 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18742 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18743 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18744 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18745 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18746 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18747 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18748 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18749 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18750 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18751 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18752 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18753 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18754 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18755 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18756 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18757 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18758 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18759 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18760 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18761 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18762 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18763 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18764 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18765 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18766 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18767 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18768 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18769 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18770 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18771 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18772 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18773 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18774 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18775 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18776 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18777 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18778 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18779 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18780 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18781 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18782 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18783 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18784 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18785 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18786 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18787 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18788 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18789 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18790 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18791 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18792 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18793 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18794 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18795 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18796 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18797 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18798 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18799 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18800 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18801 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18802 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18803 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18804 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18805 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18806 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18807 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18808 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18809 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18810 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18811 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18812 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18813 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18814 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18815 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18816 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18817 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18818 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18819 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18820 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18821 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18822 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18823 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18824 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18825 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18826 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18827 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18828 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18829 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18830 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18831 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18832 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18833 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18834 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18835 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18836 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18837 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18838 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18839 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18840 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18841 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18842 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18843 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18844 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18845 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18846 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18847 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18848 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18849 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18850 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18851 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18852 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18853 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18854 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18855 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18856 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18857 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18858 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18859 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18860 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18861 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18862 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18863 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18864 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18865 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18866 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18867 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18868 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18869 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18870 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18871 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18872 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18873 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18874 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18875 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18876 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18877 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18878 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18879
c921be7d
NC
18880#undef ARM_VARIANT
18881#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18882
21d799b5
NC
18883 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18884 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18885 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18886 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18887 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18888 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18889 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18890 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18891 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18892 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18893 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18894 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18895 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18896 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18897 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18898 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18899 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18900 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18901 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18902 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18903 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18904 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18905 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18906 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18907 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18908 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18909 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18910 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18911 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18912 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18913 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18914 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18915 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18916 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18917 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18918 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18919 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18920 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18921 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18922 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18923 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18924 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18925 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18926 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18927 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18928 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18929 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18930 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18931 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18932 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18933 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18934 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18935 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18936 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18937 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18938 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18939 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18940
c921be7d
NC
18941#undef ARM_VARIANT
18942#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18943
21d799b5
NC
18944 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18945 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18946 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18947 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18948 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18949 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18950 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18951 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18952 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18953 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18954 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18955 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18956 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18957 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18958 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18959 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18960 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18961 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18962 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18963 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18964 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18965 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18966 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18967 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18968 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18969 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18970 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18971 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18972 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18973 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18974 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18975 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18976 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18977 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18978 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18979 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18980 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18981 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18982 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18983 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18984 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18985 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18986 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18987 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18988 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18989 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18990 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18991 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18992 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18993 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18994 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18995 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18996 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18997 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18998 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18999 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
19000 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
19001 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
19002 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
19003 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
19004 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
19005 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
19006 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
19007 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
19008 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19009 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19010 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19011 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19012 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19013 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19014 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19015 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19016 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19017 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19018 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19019 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
19020};
19021#undef ARM_VARIANT
19022#undef THUMB_VARIANT
19023#undef TCE
19024#undef TCM
19025#undef TUE
19026#undef TUF
19027#undef TCC
8f06b2d8 19028#undef cCE
e3cb604e
PB
19029#undef cCL
19030#undef C3E
c19d1205
ZW
19031#undef CE
19032#undef CM
19033#undef UE
19034#undef UF
19035#undef UT
5287ad62
JB
19036#undef NUF
19037#undef nUF
19038#undef NCE
19039#undef nCE
c19d1205
ZW
19040#undef OPS0
19041#undef OPS1
19042#undef OPS2
19043#undef OPS3
19044#undef OPS4
19045#undef OPS5
19046#undef OPS6
19047#undef do_0
19048\f
19049/* MD interface: bits in the object file. */
bfae80f2 19050
c19d1205
ZW
19051/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19052 for use in the a.out file, and stores them in the array pointed to by buf.
19053 This knows about the endian-ness of the target machine and does
19054 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19055 2 (short) and 4 (long) Floating numbers are put out as a series of
19056 LITTLENUMS (shorts, here at least). */
b99bd4ef 19057
c19d1205
ZW
19058void
19059md_number_to_chars (char * buf, valueT val, int n)
19060{
19061 if (target_big_endian)
19062 number_to_chars_bigendian (buf, val, n);
19063 else
19064 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
19065}
19066
c19d1205
ZW
19067static valueT
19068md_chars_to_number (char * buf, int n)
bfae80f2 19069{
c19d1205
ZW
19070 valueT result = 0;
19071 unsigned char * where = (unsigned char *) buf;
bfae80f2 19072
c19d1205 19073 if (target_big_endian)
b99bd4ef 19074 {
c19d1205
ZW
19075 while (n--)
19076 {
19077 result <<= 8;
19078 result |= (*where++ & 255);
19079 }
b99bd4ef 19080 }
c19d1205 19081 else
b99bd4ef 19082 {
c19d1205
ZW
19083 while (n--)
19084 {
19085 result <<= 8;
19086 result |= (where[n] & 255);
19087 }
bfae80f2 19088 }
b99bd4ef 19089
c19d1205 19090 return result;
bfae80f2 19091}
b99bd4ef 19092
c19d1205 19093/* MD interface: Sections. */
b99bd4ef 19094
fa94de6b
RM
19095/* Calculate the maximum variable size (i.e., excluding fr_fix)
19096 that an rs_machine_dependent frag may reach. */
19097
19098unsigned int
19099arm_frag_max_var (fragS *fragp)
19100{
19101 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19102 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19103
19104 Note that we generate relaxable instructions even for cases that don't
19105 really need it, like an immediate that's a trivial constant. So we're
19106 overestimating the instruction size for some of those cases. Rather
19107 than putting more intelligence here, it would probably be better to
19108 avoid generating a relaxation frag in the first place when it can be
19109 determined up front that a short instruction will suffice. */
19110
19111 gas_assert (fragp->fr_type == rs_machine_dependent);
19112 return INSN_SIZE;
19113}
19114
0110f2b8
PB
19115/* Estimate the size of a frag before relaxing. Assume everything fits in
19116 2 bytes. */
19117
c19d1205 19118int
0110f2b8 19119md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
19120 segT segtype ATTRIBUTE_UNUSED)
19121{
0110f2b8
PB
19122 fragp->fr_var = 2;
19123 return 2;
19124}
19125
19126/* Convert a machine dependent frag. */
19127
19128void
19129md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19130{
19131 unsigned long insn;
19132 unsigned long old_op;
19133 char *buf;
19134 expressionS exp;
19135 fixS *fixp;
19136 int reloc_type;
19137 int pc_rel;
19138 int opcode;
19139
19140 buf = fragp->fr_literal + fragp->fr_fix;
19141
19142 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
19143 if (fragp->fr_symbol)
19144 {
0110f2b8
PB
19145 exp.X_op = O_symbol;
19146 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
19147 }
19148 else
19149 {
0110f2b8 19150 exp.X_op = O_constant;
5f4273c7 19151 }
0110f2b8
PB
19152 exp.X_add_number = fragp->fr_offset;
19153 opcode = fragp->fr_subtype;
19154 switch (opcode)
19155 {
19156 case T_MNEM_ldr_pc:
19157 case T_MNEM_ldr_pc2:
19158 case T_MNEM_ldr_sp:
19159 case T_MNEM_str_sp:
19160 case T_MNEM_ldr:
19161 case T_MNEM_ldrb:
19162 case T_MNEM_ldrh:
19163 case T_MNEM_str:
19164 case T_MNEM_strb:
19165 case T_MNEM_strh:
19166 if (fragp->fr_var == 4)
19167 {
5f4273c7 19168 insn = THUMB_OP32 (opcode);
0110f2b8
PB
19169 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19170 {
19171 insn |= (old_op & 0x700) << 4;
19172 }
19173 else
19174 {
19175 insn |= (old_op & 7) << 12;
19176 insn |= (old_op & 0x38) << 13;
19177 }
19178 insn |= 0x00000c00;
19179 put_thumb32_insn (buf, insn);
19180 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19181 }
19182 else
19183 {
19184 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19185 }
19186 pc_rel = (opcode == T_MNEM_ldr_pc2);
19187 break;
19188 case T_MNEM_adr:
19189 if (fragp->fr_var == 4)
19190 {
19191 insn = THUMB_OP32 (opcode);
19192 insn |= (old_op & 0xf0) << 4;
19193 put_thumb32_insn (buf, insn);
19194 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19195 }
19196 else
19197 {
19198 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19199 exp.X_add_number -= 4;
19200 }
19201 pc_rel = 1;
19202 break;
19203 case T_MNEM_mov:
19204 case T_MNEM_movs:
19205 case T_MNEM_cmp:
19206 case T_MNEM_cmn:
19207 if (fragp->fr_var == 4)
19208 {
19209 int r0off = (opcode == T_MNEM_mov
19210 || opcode == T_MNEM_movs) ? 0 : 8;
19211 insn = THUMB_OP32 (opcode);
19212 insn = (insn & 0xe1ffffff) | 0x10000000;
19213 insn |= (old_op & 0x700) << r0off;
19214 put_thumb32_insn (buf, insn);
19215 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19216 }
19217 else
19218 {
19219 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19220 }
19221 pc_rel = 0;
19222 break;
19223 case T_MNEM_b:
19224 if (fragp->fr_var == 4)
19225 {
19226 insn = THUMB_OP32(opcode);
19227 put_thumb32_insn (buf, insn);
19228 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19229 }
19230 else
19231 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19232 pc_rel = 1;
19233 break;
19234 case T_MNEM_bcond:
19235 if (fragp->fr_var == 4)
19236 {
19237 insn = THUMB_OP32(opcode);
19238 insn |= (old_op & 0xf00) << 14;
19239 put_thumb32_insn (buf, insn);
19240 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19241 }
19242 else
19243 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19244 pc_rel = 1;
19245 break;
19246 case T_MNEM_add_sp:
19247 case T_MNEM_add_pc:
19248 case T_MNEM_inc_sp:
19249 case T_MNEM_dec_sp:
19250 if (fragp->fr_var == 4)
19251 {
19252 /* ??? Choose between add and addw. */
19253 insn = THUMB_OP32 (opcode);
19254 insn |= (old_op & 0xf0) << 4;
19255 put_thumb32_insn (buf, insn);
16805f35
PB
19256 if (opcode == T_MNEM_add_pc)
19257 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19258 else
19259 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
19260 }
19261 else
19262 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19263 pc_rel = 0;
19264 break;
19265
19266 case T_MNEM_addi:
19267 case T_MNEM_addis:
19268 case T_MNEM_subi:
19269 case T_MNEM_subis:
19270 if (fragp->fr_var == 4)
19271 {
19272 insn = THUMB_OP32 (opcode);
19273 insn |= (old_op & 0xf0) << 4;
19274 insn |= (old_op & 0xf) << 16;
19275 put_thumb32_insn (buf, insn);
16805f35
PB
19276 if (insn & (1 << 20))
19277 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19278 else
19279 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
19280 }
19281 else
19282 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19283 pc_rel = 0;
19284 break;
19285 default:
5f4273c7 19286 abort ();
0110f2b8
PB
19287 }
19288 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 19289 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
19290 fixp->fx_file = fragp->fr_file;
19291 fixp->fx_line = fragp->fr_line;
19292 fragp->fr_fix += fragp->fr_var;
19293}
19294
19295/* Return the size of a relaxable immediate operand instruction.
19296 SHIFT and SIZE specify the form of the allowable immediate. */
19297static int
19298relax_immediate (fragS *fragp, int size, int shift)
19299{
19300 offsetT offset;
19301 offsetT mask;
19302 offsetT low;
19303
19304 /* ??? Should be able to do better than this. */
19305 if (fragp->fr_symbol)
19306 return 4;
19307
19308 low = (1 << shift) - 1;
19309 mask = (1 << (shift + size)) - (1 << shift);
19310 offset = fragp->fr_offset;
19311 /* Force misaligned offsets to 32-bit variant. */
19312 if (offset & low)
5e77afaa 19313 return 4;
0110f2b8
PB
19314 if (offset & ~mask)
19315 return 4;
19316 return 2;
19317}
19318
5e77afaa
PB
19319/* Get the address of a symbol during relaxation. */
19320static addressT
5f4273c7 19321relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
19322{
19323 fragS *sym_frag;
19324 addressT addr;
19325 symbolS *sym;
19326
19327 sym = fragp->fr_symbol;
19328 sym_frag = symbol_get_frag (sym);
19329 know (S_GET_SEGMENT (sym) != absolute_section
19330 || sym_frag == &zero_address_frag);
19331 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19332
19333 /* If frag has yet to be reached on this pass, assume it will
19334 move by STRETCH just as we did. If this is not so, it will
19335 be because some frag between grows, and that will force
19336 another pass. */
19337
19338 if (stretch != 0
19339 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
19340 {
19341 fragS *f;
19342
19343 /* Adjust stretch for any alignment frag. Note that if have
19344 been expanding the earlier code, the symbol may be
19345 defined in what appears to be an earlier frag. FIXME:
19346 This doesn't handle the fr_subtype field, which specifies
19347 a maximum number of bytes to skip when doing an
19348 alignment. */
19349 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19350 {
19351 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19352 {
19353 if (stretch < 0)
19354 stretch = - ((- stretch)
19355 & ~ ((1 << (int) f->fr_offset) - 1));
19356 else
19357 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19358 if (stretch == 0)
19359 break;
19360 }
19361 }
19362 if (f != NULL)
19363 addr += stretch;
19364 }
5e77afaa
PB
19365
19366 return addr;
19367}
19368
0110f2b8
PB
19369/* Return the size of a relaxable adr pseudo-instruction or PC-relative
19370 load. */
19371static int
5e77afaa 19372relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
19373{
19374 addressT addr;
19375 offsetT val;
19376
19377 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
19378 if (fragp->fr_symbol == NULL
19379 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19380 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19381 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19382 return 4;
19383
5f4273c7 19384 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19385 addr = fragp->fr_address + fragp->fr_fix;
19386 addr = (addr + 4) & ~3;
5e77afaa 19387 /* Force misaligned targets to 32-bit variant. */
0110f2b8 19388 if (val & 3)
5e77afaa 19389 return 4;
0110f2b8
PB
19390 val -= addr;
19391 if (val < 0 || val > 1020)
19392 return 4;
19393 return 2;
19394}
19395
19396/* Return the size of a relaxable add/sub immediate instruction. */
19397static int
19398relax_addsub (fragS *fragp, asection *sec)
19399{
19400 char *buf;
19401 int op;
19402
19403 buf = fragp->fr_literal + fragp->fr_fix;
19404 op = bfd_get_16(sec->owner, buf);
19405 if ((op & 0xf) == ((op >> 4) & 0xf))
19406 return relax_immediate (fragp, 8, 0);
19407 else
19408 return relax_immediate (fragp, 3, 0);
19409}
19410
19411
19412/* Return the size of a relaxable branch instruction. BITS is the
19413 size of the offset field in the narrow instruction. */
19414
19415static int
5e77afaa 19416relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
19417{
19418 addressT addr;
19419 offsetT val;
19420 offsetT limit;
19421
19422 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 19423 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
19424 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19425 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
19426 return 4;
19427
267bf995
RR
19428#ifdef OBJ_ELF
19429 if (S_IS_DEFINED (fragp->fr_symbol)
19430 && ARM_IS_FUNC (fragp->fr_symbol))
19431 return 4;
0d9b4b55
NC
19432
19433 /* PR 12532. Global symbols with default visibility might
19434 be preempted, so do not relax relocations to them. */
19435 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19436 && (! S_IS_LOCAL (fragp->fr_symbol)))
19437 return 4;
267bf995
RR
19438#endif
19439
5f4273c7 19440 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
19441 addr = fragp->fr_address + fragp->fr_fix + 4;
19442 val -= addr;
19443
19444 /* Offset is a signed value *2 */
19445 limit = 1 << bits;
19446 if (val >= limit || val < -limit)
19447 return 4;
19448 return 2;
19449}
19450
19451
19452/* Relax a machine dependent frag. This returns the amount by which
19453 the current size of the frag should change. */
19454
19455int
5e77afaa 19456arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
19457{
19458 int oldsize;
19459 int newsize;
19460
19461 oldsize = fragp->fr_var;
19462 switch (fragp->fr_subtype)
19463 {
19464 case T_MNEM_ldr_pc2:
5f4273c7 19465 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19466 break;
19467 case T_MNEM_ldr_pc:
19468 case T_MNEM_ldr_sp:
19469 case T_MNEM_str_sp:
5f4273c7 19470 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
19471 break;
19472 case T_MNEM_ldr:
19473 case T_MNEM_str:
5f4273c7 19474 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
19475 break;
19476 case T_MNEM_ldrh:
19477 case T_MNEM_strh:
5f4273c7 19478 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
19479 break;
19480 case T_MNEM_ldrb:
19481 case T_MNEM_strb:
5f4273c7 19482 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
19483 break;
19484 case T_MNEM_adr:
5f4273c7 19485 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
19486 break;
19487 case T_MNEM_mov:
19488 case T_MNEM_movs:
19489 case T_MNEM_cmp:
19490 case T_MNEM_cmn:
5f4273c7 19491 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
19492 break;
19493 case T_MNEM_b:
5f4273c7 19494 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
19495 break;
19496 case T_MNEM_bcond:
5f4273c7 19497 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
19498 break;
19499 case T_MNEM_add_sp:
19500 case T_MNEM_add_pc:
19501 newsize = relax_immediate (fragp, 8, 2);
19502 break;
19503 case T_MNEM_inc_sp:
19504 case T_MNEM_dec_sp:
19505 newsize = relax_immediate (fragp, 7, 2);
19506 break;
19507 case T_MNEM_addi:
19508 case T_MNEM_addis:
19509 case T_MNEM_subi:
19510 case T_MNEM_subis:
19511 newsize = relax_addsub (fragp, sec);
19512 break;
19513 default:
5f4273c7 19514 abort ();
0110f2b8 19515 }
5e77afaa
PB
19516
19517 fragp->fr_var = newsize;
19518 /* Freeze wide instructions that are at or before the same location as
19519 in the previous pass. This avoids infinite loops.
5f4273c7
NC
19520 Don't freeze them unconditionally because targets may be artificially
19521 misaligned by the expansion of preceding frags. */
5e77afaa 19522 if (stretch <= 0 && newsize > 2)
0110f2b8 19523 {
0110f2b8 19524 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 19525 frag_wane (fragp);
0110f2b8 19526 }
5e77afaa 19527
0110f2b8 19528 return newsize - oldsize;
c19d1205 19529}
b99bd4ef 19530
c19d1205 19531/* Round up a section size to the appropriate boundary. */
b99bd4ef 19532
c19d1205
ZW
19533valueT
19534md_section_align (segT segment ATTRIBUTE_UNUSED,
19535 valueT size)
19536{
f0927246
NC
19537#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19538 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19539 {
19540 /* For a.out, force the section size to be aligned. If we don't do
19541 this, BFD will align it for us, but it will not write out the
19542 final bytes of the section. This may be a bug in BFD, but it is
19543 easier to fix it here since that is how the other a.out targets
19544 work. */
19545 int align;
19546
19547 align = bfd_get_section_alignment (stdoutput, segment);
19548 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19549 }
c19d1205 19550#endif
f0927246
NC
19551
19552 return size;
bfae80f2 19553}
b99bd4ef 19554
c19d1205
ZW
19555/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19556 of an rs_align_code fragment. */
19557
19558void
19559arm_handle_align (fragS * fragP)
bfae80f2 19560{
e7495e45
NS
19561 static char const arm_noop[2][2][4] =
19562 {
19563 { /* ARMv1 */
19564 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19565 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19566 },
19567 { /* ARMv6k */
19568 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19569 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19570 },
19571 };
19572 static char const thumb_noop[2][2][2] =
19573 {
19574 { /* Thumb-1 */
19575 {0xc0, 0x46}, /* LE */
19576 {0x46, 0xc0}, /* BE */
19577 },
19578 { /* Thumb-2 */
19579 {0x00, 0xbf}, /* LE */
19580 {0xbf, 0x00} /* BE */
19581 }
19582 };
19583 static char const wide_thumb_noop[2][4] =
19584 { /* Wide Thumb-2 */
19585 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19586 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19587 };
c921be7d 19588
e7495e45 19589 unsigned bytes, fix, noop_size;
c19d1205
ZW
19590 char * p;
19591 const char * noop;
e7495e45 19592 const char *narrow_noop = NULL;
cd000bff
DJ
19593#ifdef OBJ_ELF
19594 enum mstate state;
19595#endif
bfae80f2 19596
c19d1205 19597 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
19598 return;
19599
c19d1205
ZW
19600 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19601 p = fragP->fr_literal + fragP->fr_fix;
19602 fix = 0;
bfae80f2 19603
c19d1205
ZW
19604 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19605 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 19606
cd000bff 19607 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 19608
cd000bff 19609 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 19610 {
e7495e45
NS
19611 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19612 {
19613 narrow_noop = thumb_noop[1][target_big_endian];
19614 noop = wide_thumb_noop[target_big_endian];
19615 }
c19d1205 19616 else
e7495e45
NS
19617 noop = thumb_noop[0][target_big_endian];
19618 noop_size = 2;
cd000bff
DJ
19619#ifdef OBJ_ELF
19620 state = MAP_THUMB;
19621#endif
7ed4c4c5
NC
19622 }
19623 else
19624 {
e7495e45
NS
19625 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19626 [target_big_endian];
19627 noop_size = 4;
cd000bff
DJ
19628#ifdef OBJ_ELF
19629 state = MAP_ARM;
19630#endif
7ed4c4c5 19631 }
c921be7d 19632
e7495e45 19633 fragP->fr_var = noop_size;
c921be7d 19634
c19d1205 19635 if (bytes & (noop_size - 1))
7ed4c4c5 19636 {
c19d1205 19637 fix = bytes & (noop_size - 1);
cd000bff
DJ
19638#ifdef OBJ_ELF
19639 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19640#endif
c19d1205
ZW
19641 memset (p, 0, fix);
19642 p += fix;
19643 bytes -= fix;
a737bd4d 19644 }
a737bd4d 19645
e7495e45
NS
19646 if (narrow_noop)
19647 {
19648 if (bytes & noop_size)
19649 {
19650 /* Insert a narrow noop. */
19651 memcpy (p, narrow_noop, noop_size);
19652 p += noop_size;
19653 bytes -= noop_size;
19654 fix += noop_size;
19655 }
19656
19657 /* Use wide noops for the remainder */
19658 noop_size = 4;
19659 }
19660
c19d1205 19661 while (bytes >= noop_size)
a737bd4d 19662 {
c19d1205
ZW
19663 memcpy (p, noop, noop_size);
19664 p += noop_size;
19665 bytes -= noop_size;
19666 fix += noop_size;
a737bd4d
NC
19667 }
19668
c19d1205 19669 fragP->fr_fix += fix;
a737bd4d
NC
19670}
19671
c19d1205
ZW
19672/* Called from md_do_align. Used to create an alignment
19673 frag in a code section. */
19674
19675void
19676arm_frag_align_code (int n, int max)
bfae80f2 19677{
c19d1205 19678 char * p;
7ed4c4c5 19679
c19d1205 19680 /* We assume that there will never be a requirement
6ec8e702 19681 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 19682 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
19683 {
19684 char err_msg[128];
19685
fa94de6b 19686 sprintf (err_msg,
6ec8e702
NC
19687 _("alignments greater than %d bytes not supported in .text sections."),
19688 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 19689 as_fatal ("%s", err_msg);
6ec8e702 19690 }
bfae80f2 19691
c19d1205
ZW
19692 p = frag_var (rs_align_code,
19693 MAX_MEM_FOR_RS_ALIGN_CODE,
19694 1,
19695 (relax_substateT) max,
19696 (symbolS *) NULL,
19697 (offsetT) n,
19698 (char *) NULL);
19699 *p = 0;
19700}
bfae80f2 19701
8dc2430f
NC
19702/* Perform target specific initialisation of a frag.
19703 Note - despite the name this initialisation is not done when the frag
19704 is created, but only when its type is assigned. A frag can be created
19705 and used a long time before its type is set, so beware of assuming that
19706 this initialisationis performed first. */
bfae80f2 19707
cd000bff
DJ
19708#ifndef OBJ_ELF
19709void
19710arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19711{
19712 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 19713 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
19714}
19715
19716#else /* OBJ_ELF is defined. */
c19d1205 19717void
cd000bff 19718arm_init_frag (fragS * fragP, int max_chars)
c19d1205 19719{
8dc2430f
NC
19720 /* If the current ARM vs THUMB mode has not already
19721 been recorded into this frag then do so now. */
cd000bff
DJ
19722 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19723 {
19724 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19725
19726 /* Record a mapping symbol for alignment frags. We will delete this
19727 later if the alignment ends up empty. */
19728 switch (fragP->fr_type)
19729 {
19730 case rs_align:
19731 case rs_align_test:
19732 case rs_fill:
19733 mapping_state_2 (MAP_DATA, max_chars);
19734 break;
19735 case rs_align_code:
19736 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19737 break;
19738 default:
19739 break;
19740 }
19741 }
bfae80f2
RE
19742}
19743
c19d1205
ZW
19744/* When we change sections we need to issue a new mapping symbol. */
19745
19746void
19747arm_elf_change_section (void)
bfae80f2 19748{
c19d1205
ZW
19749 /* Link an unlinked unwind index table section to the .text section. */
19750 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19751 && elf_linked_to_section (now_seg) == NULL)
19752 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
19753}
19754
c19d1205
ZW
19755int
19756arm_elf_section_type (const char * str, size_t len)
e45d0630 19757{
c19d1205
ZW
19758 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19759 return SHT_ARM_EXIDX;
e45d0630 19760
c19d1205
ZW
19761 return -1;
19762}
19763\f
19764/* Code to deal with unwinding tables. */
e45d0630 19765
c19d1205 19766static void add_unwind_adjustsp (offsetT);
e45d0630 19767
5f4273c7 19768/* Generate any deferred unwind frame offset. */
e45d0630 19769
bfae80f2 19770static void
c19d1205 19771flush_pending_unwind (void)
bfae80f2 19772{
c19d1205 19773 offsetT offset;
bfae80f2 19774
c19d1205
ZW
19775 offset = unwind.pending_offset;
19776 unwind.pending_offset = 0;
19777 if (offset != 0)
19778 add_unwind_adjustsp (offset);
bfae80f2
RE
19779}
19780
c19d1205
ZW
19781/* Add an opcode to this list for this function. Two-byte opcodes should
19782 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19783 order. */
19784
bfae80f2 19785static void
c19d1205 19786add_unwind_opcode (valueT op, int length)
bfae80f2 19787{
c19d1205
ZW
19788 /* Add any deferred stack adjustment. */
19789 if (unwind.pending_offset)
19790 flush_pending_unwind ();
bfae80f2 19791
c19d1205 19792 unwind.sp_restored = 0;
bfae80f2 19793
c19d1205 19794 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 19795 {
c19d1205
ZW
19796 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19797 if (unwind.opcodes)
21d799b5
NC
19798 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19799 unwind.opcode_alloc);
c19d1205 19800 else
21d799b5 19801 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 19802 }
c19d1205 19803 while (length > 0)
bfae80f2 19804 {
c19d1205
ZW
19805 length--;
19806 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19807 op >>= 8;
19808 unwind.opcode_count++;
bfae80f2 19809 }
bfae80f2
RE
19810}
19811
c19d1205
ZW
19812/* Add unwind opcodes to adjust the stack pointer. */
19813
bfae80f2 19814static void
c19d1205 19815add_unwind_adjustsp (offsetT offset)
bfae80f2 19816{
c19d1205 19817 valueT op;
bfae80f2 19818
c19d1205 19819 if (offset > 0x200)
bfae80f2 19820 {
c19d1205
ZW
19821 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19822 char bytes[5];
19823 int n;
19824 valueT o;
bfae80f2 19825
c19d1205
ZW
19826 /* Long form: 0xb2, uleb128. */
19827 /* This might not fit in a word so add the individual bytes,
19828 remembering the list is built in reverse order. */
19829 o = (valueT) ((offset - 0x204) >> 2);
19830 if (o == 0)
19831 add_unwind_opcode (0, 1);
bfae80f2 19832
c19d1205
ZW
19833 /* Calculate the uleb128 encoding of the offset. */
19834 n = 0;
19835 while (o)
19836 {
19837 bytes[n] = o & 0x7f;
19838 o >>= 7;
19839 if (o)
19840 bytes[n] |= 0x80;
19841 n++;
19842 }
19843 /* Add the insn. */
19844 for (; n; n--)
19845 add_unwind_opcode (bytes[n - 1], 1);
19846 add_unwind_opcode (0xb2, 1);
19847 }
19848 else if (offset > 0x100)
bfae80f2 19849 {
c19d1205
ZW
19850 /* Two short opcodes. */
19851 add_unwind_opcode (0x3f, 1);
19852 op = (offset - 0x104) >> 2;
19853 add_unwind_opcode (op, 1);
bfae80f2 19854 }
c19d1205
ZW
19855 else if (offset > 0)
19856 {
19857 /* Short opcode. */
19858 op = (offset - 4) >> 2;
19859 add_unwind_opcode (op, 1);
19860 }
19861 else if (offset < 0)
bfae80f2 19862 {
c19d1205
ZW
19863 offset = -offset;
19864 while (offset > 0x100)
bfae80f2 19865 {
c19d1205
ZW
19866 add_unwind_opcode (0x7f, 1);
19867 offset -= 0x100;
bfae80f2 19868 }
c19d1205
ZW
19869 op = ((offset - 4) >> 2) | 0x40;
19870 add_unwind_opcode (op, 1);
bfae80f2 19871 }
bfae80f2
RE
19872}
19873
c19d1205
ZW
19874/* Finish the list of unwind opcodes for this function. */
19875static void
19876finish_unwind_opcodes (void)
bfae80f2 19877{
c19d1205 19878 valueT op;
bfae80f2 19879
c19d1205 19880 if (unwind.fp_used)
bfae80f2 19881 {
708587a4 19882 /* Adjust sp as necessary. */
c19d1205
ZW
19883 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19884 flush_pending_unwind ();
bfae80f2 19885
c19d1205
ZW
19886 /* After restoring sp from the frame pointer. */
19887 op = 0x90 | unwind.fp_reg;
19888 add_unwind_opcode (op, 1);
19889 }
19890 else
19891 flush_pending_unwind ();
bfae80f2
RE
19892}
19893
bfae80f2 19894
c19d1205
ZW
19895/* Start an exception table entry. If idx is nonzero this is an index table
19896 entry. */
bfae80f2
RE
19897
19898static void
c19d1205 19899start_unwind_section (const segT text_seg, int idx)
bfae80f2 19900{
c19d1205
ZW
19901 const char * text_name;
19902 const char * prefix;
19903 const char * prefix_once;
19904 const char * group_name;
19905 size_t prefix_len;
19906 size_t text_len;
19907 char * sec_name;
19908 size_t sec_name_len;
19909 int type;
19910 int flags;
19911 int linkonce;
bfae80f2 19912
c19d1205 19913 if (idx)
bfae80f2 19914 {
c19d1205
ZW
19915 prefix = ELF_STRING_ARM_unwind;
19916 prefix_once = ELF_STRING_ARM_unwind_once;
19917 type = SHT_ARM_EXIDX;
bfae80f2 19918 }
c19d1205 19919 else
bfae80f2 19920 {
c19d1205
ZW
19921 prefix = ELF_STRING_ARM_unwind_info;
19922 prefix_once = ELF_STRING_ARM_unwind_info_once;
19923 type = SHT_PROGBITS;
bfae80f2
RE
19924 }
19925
c19d1205
ZW
19926 text_name = segment_name (text_seg);
19927 if (streq (text_name, ".text"))
19928 text_name = "";
19929
19930 if (strncmp (text_name, ".gnu.linkonce.t.",
19931 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19932 {
c19d1205
ZW
19933 prefix = prefix_once;
19934 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19935 }
19936
c19d1205
ZW
19937 prefix_len = strlen (prefix);
19938 text_len = strlen (text_name);
19939 sec_name_len = prefix_len + text_len;
21d799b5 19940 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19941 memcpy (sec_name, prefix, prefix_len);
19942 memcpy (sec_name + prefix_len, text_name, text_len);
19943 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19944
c19d1205
ZW
19945 flags = SHF_ALLOC;
19946 linkonce = 0;
19947 group_name = 0;
bfae80f2 19948
c19d1205
ZW
19949 /* Handle COMDAT group. */
19950 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19951 {
c19d1205
ZW
19952 group_name = elf_group_name (text_seg);
19953 if (group_name == NULL)
19954 {
bd3ba5d1 19955 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19956 segment_name (text_seg));
19957 ignore_rest_of_line ();
19958 return;
19959 }
19960 flags |= SHF_GROUP;
19961 linkonce = 1;
bfae80f2
RE
19962 }
19963
c19d1205 19964 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19965
5f4273c7 19966 /* Set the section link for index tables. */
c19d1205
ZW
19967 if (idx)
19968 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19969}
19970
bfae80f2 19971
c19d1205
ZW
19972/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19973 personality routine data. Returns zero, or the index table value for
19974 and inline entry. */
19975
19976static valueT
19977create_unwind_entry (int have_data)
bfae80f2 19978{
c19d1205
ZW
19979 int size;
19980 addressT where;
19981 char *ptr;
19982 /* The current word of data. */
19983 valueT data;
19984 /* The number of bytes left in this word. */
19985 int n;
bfae80f2 19986
c19d1205 19987 finish_unwind_opcodes ();
bfae80f2 19988
c19d1205
ZW
19989 /* Remember the current text section. */
19990 unwind.saved_seg = now_seg;
19991 unwind.saved_subseg = now_subseg;
bfae80f2 19992
c19d1205 19993 start_unwind_section (now_seg, 0);
bfae80f2 19994
c19d1205 19995 if (unwind.personality_routine == NULL)
bfae80f2 19996 {
c19d1205
ZW
19997 if (unwind.personality_index == -2)
19998 {
19999 if (have_data)
5f4273c7 20000 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
20001 return 1; /* EXIDX_CANTUNWIND. */
20002 }
bfae80f2 20003
c19d1205
ZW
20004 /* Use a default personality routine if none is specified. */
20005 if (unwind.personality_index == -1)
20006 {
20007 if (unwind.opcode_count > 3)
20008 unwind.personality_index = 1;
20009 else
20010 unwind.personality_index = 0;
20011 }
bfae80f2 20012
c19d1205
ZW
20013 /* Space for the personality routine entry. */
20014 if (unwind.personality_index == 0)
20015 {
20016 if (unwind.opcode_count > 3)
20017 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 20018
c19d1205
ZW
20019 if (!have_data)
20020 {
20021 /* All the data is inline in the index table. */
20022 data = 0x80;
20023 n = 3;
20024 while (unwind.opcode_count > 0)
20025 {
20026 unwind.opcode_count--;
20027 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20028 n--;
20029 }
bfae80f2 20030
c19d1205
ZW
20031 /* Pad with "finish" opcodes. */
20032 while (n--)
20033 data = (data << 8) | 0xb0;
bfae80f2 20034
c19d1205
ZW
20035 return data;
20036 }
20037 size = 0;
20038 }
20039 else
20040 /* We get two opcodes "free" in the first word. */
20041 size = unwind.opcode_count - 2;
20042 }
20043 else
5011093d
NC
20044 {
20045 gas_assert (unwind.personality_index == -1);
20046
20047 /* An extra byte is required for the opcode count. */
20048 size = unwind.opcode_count + 1;
20049 }
bfae80f2 20050
c19d1205
ZW
20051 size = (size + 3) >> 2;
20052 if (size > 0xff)
20053 as_bad (_("too many unwind opcodes"));
bfae80f2 20054
c19d1205
ZW
20055 frag_align (2, 0, 0);
20056 record_alignment (now_seg, 2);
20057 unwind.table_entry = expr_build_dot ();
20058
20059 /* Allocate the table entry. */
20060 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
20061 /* PR 13449: Zero the table entries in case some of them are not used. */
20062 memset (ptr, 0, (size << 2) + 4);
c19d1205 20063 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 20064
c19d1205 20065 switch (unwind.personality_index)
bfae80f2 20066 {
c19d1205
ZW
20067 case -1:
20068 /* ??? Should this be a PLT generating relocation? */
20069 /* Custom personality routine. */
20070 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20071 BFD_RELOC_ARM_PREL31);
bfae80f2 20072
c19d1205
ZW
20073 where += 4;
20074 ptr += 4;
bfae80f2 20075
c19d1205 20076 /* Set the first byte to the number of additional words. */
5011093d 20077 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
20078 n = 3;
20079 break;
bfae80f2 20080
c19d1205
ZW
20081 /* ABI defined personality routines. */
20082 case 0:
20083 /* Three opcodes bytes are packed into the first word. */
20084 data = 0x80;
20085 n = 3;
20086 break;
bfae80f2 20087
c19d1205
ZW
20088 case 1:
20089 case 2:
20090 /* The size and first two opcode bytes go in the first word. */
20091 data = ((0x80 + unwind.personality_index) << 8) | size;
20092 n = 2;
20093 break;
bfae80f2 20094
c19d1205
ZW
20095 default:
20096 /* Should never happen. */
20097 abort ();
20098 }
bfae80f2 20099
c19d1205
ZW
20100 /* Pack the opcodes into words (MSB first), reversing the list at the same
20101 time. */
20102 while (unwind.opcode_count > 0)
20103 {
20104 if (n == 0)
20105 {
20106 md_number_to_chars (ptr, data, 4);
20107 ptr += 4;
20108 n = 4;
20109 data = 0;
20110 }
20111 unwind.opcode_count--;
20112 n--;
20113 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20114 }
20115
20116 /* Finish off the last word. */
20117 if (n < 4)
20118 {
20119 /* Pad with "finish" opcodes. */
20120 while (n--)
20121 data = (data << 8) | 0xb0;
20122
20123 md_number_to_chars (ptr, data, 4);
20124 }
20125
20126 if (!have_data)
20127 {
20128 /* Add an empty descriptor if there is no user-specified data. */
20129 ptr = frag_more (4);
20130 md_number_to_chars (ptr, 0, 4);
20131 }
20132
20133 return 0;
bfae80f2
RE
20134}
20135
f0927246
NC
20136
20137/* Initialize the DWARF-2 unwind information for this procedure. */
20138
20139void
20140tc_arm_frame_initial_instructions (void)
20141{
20142 cfi_add_CFA_def_cfa (REG_SP, 0);
20143}
20144#endif /* OBJ_ELF */
20145
c19d1205
ZW
20146/* Convert REGNAME to a DWARF-2 register number. */
20147
20148int
1df69f4f 20149tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 20150{
1df69f4f 20151 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
20152
20153 if (reg == FAIL)
20154 return -1;
20155
20156 return reg;
bfae80f2
RE
20157}
20158
f0927246 20159#ifdef TE_PE
c19d1205 20160void
f0927246 20161tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 20162{
91d6fa6a 20163 expressionS exp;
bfae80f2 20164
91d6fa6a
NC
20165 exp.X_op = O_secrel;
20166 exp.X_add_symbol = symbol;
20167 exp.X_add_number = 0;
20168 emit_expr (&exp, size);
f0927246
NC
20169}
20170#endif
bfae80f2 20171
c19d1205 20172/* MD interface: Symbol and relocation handling. */
bfae80f2 20173
2fc8bdac
ZW
20174/* Return the address within the segment that a PC-relative fixup is
20175 relative to. For ARM, PC-relative fixups applied to instructions
20176 are generally relative to the location of the fixup plus 8 bytes.
20177 Thumb branches are offset by 4, and Thumb loads relative to PC
20178 require special handling. */
bfae80f2 20179
c19d1205 20180long
2fc8bdac 20181md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 20182{
2fc8bdac
ZW
20183 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20184
20185 /* If this is pc-relative and we are going to emit a relocation
20186 then we just want to put out any pipeline compensation that the linker
53baae48
NC
20187 will need. Otherwise we want to use the calculated base.
20188 For WinCE we skip the bias for externals as well, since this
20189 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 20190 if (fixP->fx_pcrel
2fc8bdac 20191 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
20192 || (arm_force_relocation (fixP)
20193#ifdef TE_WINCE
20194 && !S_IS_EXTERNAL (fixP->fx_addsy)
20195#endif
20196 )))
2fc8bdac 20197 base = 0;
bfae80f2 20198
267bf995 20199
c19d1205 20200 switch (fixP->fx_r_type)
bfae80f2 20201 {
2fc8bdac
ZW
20202 /* PC relative addressing on the Thumb is slightly odd as the
20203 bottom two bits of the PC are forced to zero for the
20204 calculation. This happens *after* application of the
20205 pipeline offset. However, Thumb adrl already adjusts for
20206 this, so we need not do it again. */
c19d1205 20207 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 20208 return base & ~3;
c19d1205
ZW
20209
20210 case BFD_RELOC_ARM_THUMB_OFFSET:
20211 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 20212 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 20213 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 20214 return (base + 4) & ~3;
c19d1205 20215
2fc8bdac
ZW
20216 /* Thumb branches are simply offset by +4. */
20217 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20218 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20219 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20220 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 20221 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 20222 return base + 4;
bfae80f2 20223
267bf995 20224 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
20225 if (fixP->fx_addsy
20226 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20227 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20228 && ARM_IS_FUNC (fixP->fx_addsy)
20229 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20230 base = fixP->fx_where + fixP->fx_frag->fr_address;
20231 return base + 4;
20232
00adf2d4
JB
20233 /* BLX is like branches above, but forces the low two bits of PC to
20234 zero. */
486499d0
CL
20235 case BFD_RELOC_THUMB_PCREL_BLX:
20236 if (fixP->fx_addsy
20237 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20238 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20239 && THUMB_IS_FUNC (fixP->fx_addsy)
20240 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20241 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
20242 return (base + 4) & ~3;
20243
2fc8bdac
ZW
20244 /* ARM mode branches are offset by +8. However, the Windows CE
20245 loader expects the relocation not to take this into account. */
267bf995 20246 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
20247 if (fixP->fx_addsy
20248 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20249 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20250 && ARM_IS_FUNC (fixP->fx_addsy)
20251 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20252 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20253 return base + 8;
267bf995 20254
486499d0
CL
20255 case BFD_RELOC_ARM_PCREL_CALL:
20256 if (fixP->fx_addsy
20257 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 20258 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
20259 && THUMB_IS_FUNC (fixP->fx_addsy)
20260 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20261 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 20262 return base + 8;
267bf995 20263
2fc8bdac 20264 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 20265 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 20266 case BFD_RELOC_ARM_PLT32:
c19d1205 20267#ifdef TE_WINCE
5f4273c7 20268 /* When handling fixups immediately, because we have already
53baae48
NC
20269 discovered the value of a symbol, or the address of the frag involved
20270 we must account for the offset by +8, as the OS loader will never see the reloc.
20271 see fixup_segment() in write.c
20272 The S_IS_EXTERNAL test handles the case of global symbols.
20273 Those need the calculated base, not just the pipe compensation the linker will need. */
20274 if (fixP->fx_pcrel
20275 && fixP->fx_addsy != NULL
20276 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20277 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20278 return base + 8;
2fc8bdac 20279 return base;
c19d1205 20280#else
2fc8bdac 20281 return base + 8;
c19d1205 20282#endif
2fc8bdac 20283
267bf995 20284
2fc8bdac
ZW
20285 /* ARM mode loads relative to PC are also offset by +8. Unlike
20286 branches, the Windows CE loader *does* expect the relocation
20287 to take this into account. */
20288 case BFD_RELOC_ARM_OFFSET_IMM:
20289 case BFD_RELOC_ARM_OFFSET_IMM8:
20290 case BFD_RELOC_ARM_HWLITERAL:
20291 case BFD_RELOC_ARM_LITERAL:
20292 case BFD_RELOC_ARM_CP_OFF_IMM:
20293 return base + 8;
20294
20295
20296 /* Other PC-relative relocations are un-offset. */
20297 default:
20298 return base;
20299 }
bfae80f2
RE
20300}
20301
c19d1205
ZW
20302/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20303 Otherwise we have no need to default values of symbols. */
20304
20305symbolS *
20306md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 20307{
c19d1205
ZW
20308#ifdef OBJ_ELF
20309 if (name[0] == '_' && name[1] == 'G'
20310 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20311 {
20312 if (!GOT_symbol)
20313 {
20314 if (symbol_find (name))
bd3ba5d1 20315 as_bad (_("GOT already in the symbol table"));
bfae80f2 20316
c19d1205
ZW
20317 GOT_symbol = symbol_new (name, undefined_section,
20318 (valueT) 0, & zero_address_frag);
20319 }
bfae80f2 20320
c19d1205 20321 return GOT_symbol;
bfae80f2 20322 }
c19d1205 20323#endif
bfae80f2 20324
c921be7d 20325 return NULL;
bfae80f2
RE
20326}
20327
55cf6793 20328/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
20329 computed as two separate immediate values, added together. We
20330 already know that this value cannot be computed by just one ARM
20331 instruction. */
20332
20333static unsigned int
20334validate_immediate_twopart (unsigned int val,
20335 unsigned int * highpart)
bfae80f2 20336{
c19d1205
ZW
20337 unsigned int a;
20338 unsigned int i;
bfae80f2 20339
c19d1205
ZW
20340 for (i = 0; i < 32; i += 2)
20341 if (((a = rotate_left (val, i)) & 0xff) != 0)
20342 {
20343 if (a & 0xff00)
20344 {
20345 if (a & ~ 0xffff)
20346 continue;
20347 * highpart = (a >> 8) | ((i + 24) << 7);
20348 }
20349 else if (a & 0xff0000)
20350 {
20351 if (a & 0xff000000)
20352 continue;
20353 * highpart = (a >> 16) | ((i + 16) << 7);
20354 }
20355 else
20356 {
9c2799c2 20357 gas_assert (a & 0xff000000);
c19d1205
ZW
20358 * highpart = (a >> 24) | ((i + 8) << 7);
20359 }
bfae80f2 20360
c19d1205
ZW
20361 return (a & 0xff) | (i << 7);
20362 }
bfae80f2 20363
c19d1205 20364 return FAIL;
bfae80f2
RE
20365}
20366
c19d1205
ZW
20367static int
20368validate_offset_imm (unsigned int val, int hwse)
20369{
20370 if ((hwse && val > 255) || val > 4095)
20371 return FAIL;
20372 return val;
20373}
bfae80f2 20374
55cf6793 20375/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
20376 negative immediate constant by altering the instruction. A bit of
20377 a hack really.
20378 MOV <-> MVN
20379 AND <-> BIC
20380 ADC <-> SBC
20381 by inverting the second operand, and
20382 ADD <-> SUB
20383 CMP <-> CMN
20384 by negating the second operand. */
bfae80f2 20385
c19d1205
ZW
20386static int
20387negate_data_op (unsigned long * instruction,
20388 unsigned long value)
bfae80f2 20389{
c19d1205
ZW
20390 int op, new_inst;
20391 unsigned long negated, inverted;
bfae80f2 20392
c19d1205
ZW
20393 negated = encode_arm_immediate (-value);
20394 inverted = encode_arm_immediate (~value);
bfae80f2 20395
c19d1205
ZW
20396 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20397 switch (op)
bfae80f2 20398 {
c19d1205
ZW
20399 /* First negates. */
20400 case OPCODE_SUB: /* ADD <-> SUB */
20401 new_inst = OPCODE_ADD;
20402 value = negated;
20403 break;
bfae80f2 20404
c19d1205
ZW
20405 case OPCODE_ADD:
20406 new_inst = OPCODE_SUB;
20407 value = negated;
20408 break;
bfae80f2 20409
c19d1205
ZW
20410 case OPCODE_CMP: /* CMP <-> CMN */
20411 new_inst = OPCODE_CMN;
20412 value = negated;
20413 break;
bfae80f2 20414
c19d1205
ZW
20415 case OPCODE_CMN:
20416 new_inst = OPCODE_CMP;
20417 value = negated;
20418 break;
bfae80f2 20419
c19d1205
ZW
20420 /* Now Inverted ops. */
20421 case OPCODE_MOV: /* MOV <-> MVN */
20422 new_inst = OPCODE_MVN;
20423 value = inverted;
20424 break;
bfae80f2 20425
c19d1205
ZW
20426 case OPCODE_MVN:
20427 new_inst = OPCODE_MOV;
20428 value = inverted;
20429 break;
bfae80f2 20430
c19d1205
ZW
20431 case OPCODE_AND: /* AND <-> BIC */
20432 new_inst = OPCODE_BIC;
20433 value = inverted;
20434 break;
bfae80f2 20435
c19d1205
ZW
20436 case OPCODE_BIC:
20437 new_inst = OPCODE_AND;
20438 value = inverted;
20439 break;
bfae80f2 20440
c19d1205
ZW
20441 case OPCODE_ADC: /* ADC <-> SBC */
20442 new_inst = OPCODE_SBC;
20443 value = inverted;
20444 break;
bfae80f2 20445
c19d1205
ZW
20446 case OPCODE_SBC:
20447 new_inst = OPCODE_ADC;
20448 value = inverted;
20449 break;
bfae80f2 20450
c19d1205
ZW
20451 /* We cannot do anything. */
20452 default:
20453 return FAIL;
b99bd4ef
NC
20454 }
20455
c19d1205
ZW
20456 if (value == (unsigned) FAIL)
20457 return FAIL;
20458
20459 *instruction &= OPCODE_MASK;
20460 *instruction |= new_inst << DATA_OP_SHIFT;
20461 return value;
b99bd4ef
NC
20462}
20463
ef8d22e6
PB
20464/* Like negate_data_op, but for Thumb-2. */
20465
20466static unsigned int
16dd5e42 20467thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
20468{
20469 int op, new_inst;
20470 int rd;
16dd5e42 20471 unsigned int negated, inverted;
ef8d22e6
PB
20472
20473 negated = encode_thumb32_immediate (-value);
20474 inverted = encode_thumb32_immediate (~value);
20475
20476 rd = (*instruction >> 8) & 0xf;
20477 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20478 switch (op)
20479 {
20480 /* ADD <-> SUB. Includes CMP <-> CMN. */
20481 case T2_OPCODE_SUB:
20482 new_inst = T2_OPCODE_ADD;
20483 value = negated;
20484 break;
20485
20486 case T2_OPCODE_ADD:
20487 new_inst = T2_OPCODE_SUB;
20488 value = negated;
20489 break;
20490
20491 /* ORR <-> ORN. Includes MOV <-> MVN. */
20492 case T2_OPCODE_ORR:
20493 new_inst = T2_OPCODE_ORN;
20494 value = inverted;
20495 break;
20496
20497 case T2_OPCODE_ORN:
20498 new_inst = T2_OPCODE_ORR;
20499 value = inverted;
20500 break;
20501
20502 /* AND <-> BIC. TST has no inverted equivalent. */
20503 case T2_OPCODE_AND:
20504 new_inst = T2_OPCODE_BIC;
20505 if (rd == 15)
20506 value = FAIL;
20507 else
20508 value = inverted;
20509 break;
20510
20511 case T2_OPCODE_BIC:
20512 new_inst = T2_OPCODE_AND;
20513 value = inverted;
20514 break;
20515
20516 /* ADC <-> SBC */
20517 case T2_OPCODE_ADC:
20518 new_inst = T2_OPCODE_SBC;
20519 value = inverted;
20520 break;
20521
20522 case T2_OPCODE_SBC:
20523 new_inst = T2_OPCODE_ADC;
20524 value = inverted;
20525 break;
20526
20527 /* We cannot do anything. */
20528 default:
20529 return FAIL;
20530 }
20531
16dd5e42 20532 if (value == (unsigned int)FAIL)
ef8d22e6
PB
20533 return FAIL;
20534
20535 *instruction &= T2_OPCODE_MASK;
20536 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20537 return value;
20538}
20539
8f06b2d8
PB
20540/* Read a 32-bit thumb instruction from buf. */
20541static unsigned long
20542get_thumb32_insn (char * buf)
20543{
20544 unsigned long insn;
20545 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20546 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20547
20548 return insn;
20549}
20550
a8bc6c78
PB
20551
20552/* We usually want to set the low bit on the address of thumb function
20553 symbols. In particular .word foo - . should have the low bit set.
20554 Generic code tries to fold the difference of two symbols to
20555 a constant. Prevent this and force a relocation when the first symbols
20556 is a thumb function. */
c921be7d
NC
20557
20558bfd_boolean
a8bc6c78
PB
20559arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20560{
20561 if (op == O_subtract
20562 && l->X_op == O_symbol
20563 && r->X_op == O_symbol
20564 && THUMB_IS_FUNC (l->X_add_symbol))
20565 {
20566 l->X_op = O_subtract;
20567 l->X_op_symbol = r->X_add_symbol;
20568 l->X_add_number -= r->X_add_number;
c921be7d 20569 return TRUE;
a8bc6c78 20570 }
c921be7d 20571
a8bc6c78 20572 /* Process as normal. */
c921be7d 20573 return FALSE;
a8bc6c78
PB
20574}
20575
4a42ebbc
RR
20576/* Encode Thumb2 unconditional branches and calls. The encoding
20577 for the 2 are identical for the immediate values. */
20578
20579static void
20580encode_thumb2_b_bl_offset (char * buf, offsetT value)
20581{
20582#define T2I1I2MASK ((1 << 13) | (1 << 11))
20583 offsetT newval;
20584 offsetT newval2;
20585 addressT S, I1, I2, lo, hi;
20586
20587 S = (value >> 24) & 0x01;
20588 I1 = (value >> 23) & 0x01;
20589 I2 = (value >> 22) & 0x01;
20590 hi = (value >> 12) & 0x3ff;
fa94de6b 20591 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
20592 newval = md_chars_to_number (buf, THUMB_SIZE);
20593 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20594 newval |= (S << 10) | hi;
20595 newval2 &= ~T2I1I2MASK;
20596 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20597 md_number_to_chars (buf, newval, THUMB_SIZE);
20598 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20599}
20600
c19d1205 20601void
55cf6793 20602md_apply_fix (fixS * fixP,
c19d1205
ZW
20603 valueT * valP,
20604 segT seg)
20605{
20606 offsetT value = * valP;
20607 offsetT newval;
20608 unsigned int newimm;
20609 unsigned long temp;
20610 int sign;
20611 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 20612
9c2799c2 20613 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 20614
c19d1205 20615 /* Note whether this will delete the relocation. */
4962c51a 20616
c19d1205
ZW
20617 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20618 fixP->fx_done = 1;
b99bd4ef 20619
adbaf948 20620 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 20621 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
20622 for emit_reloc. */
20623 value &= 0xffffffff;
20624 value ^= 0x80000000;
5f4273c7 20625 value -= 0x80000000;
adbaf948
ZW
20626
20627 *valP = value;
c19d1205 20628 fixP->fx_addnumber = value;
b99bd4ef 20629
adbaf948
ZW
20630 /* Same treatment for fixP->fx_offset. */
20631 fixP->fx_offset &= 0xffffffff;
20632 fixP->fx_offset ^= 0x80000000;
20633 fixP->fx_offset -= 0x80000000;
20634
c19d1205 20635 switch (fixP->fx_r_type)
b99bd4ef 20636 {
c19d1205
ZW
20637 case BFD_RELOC_NONE:
20638 /* This will need to go in the object file. */
20639 fixP->fx_done = 0;
20640 break;
b99bd4ef 20641
c19d1205
ZW
20642 case BFD_RELOC_ARM_IMMEDIATE:
20643 /* We claim that this fixup has been processed here,
20644 even if in fact we generate an error because we do
20645 not have a reloc for it, so tc_gen_reloc will reject it. */
20646 fixP->fx_done = 1;
b99bd4ef 20647
77db8e2e 20648 if (fixP->fx_addsy)
b99bd4ef 20649 {
77db8e2e 20650 const char *msg = 0;
b99bd4ef 20651
77db8e2e
NC
20652 if (! S_IS_DEFINED (fixP->fx_addsy))
20653 msg = _("undefined symbol %s used as an immediate value");
20654 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20655 msg = _("symbol %s is in a different section");
20656 else if (S_IS_WEAK (fixP->fx_addsy))
20657 msg = _("symbol %s is weak and may be overridden later");
20658
20659 if (msg)
20660 {
20661 as_bad_where (fixP->fx_file, fixP->fx_line,
20662 msg, S_GET_NAME (fixP->fx_addsy));
20663 break;
20664 }
42e5fcbf
AS
20665 }
20666
c19d1205
ZW
20667 temp = md_chars_to_number (buf, INSN_SIZE);
20668
5e73442d
SL
20669 /* If the offset is negative, we should use encoding A2 for ADR. */
20670 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
20671 newimm = negate_data_op (&temp, value);
20672 else
20673 {
20674 newimm = encode_arm_immediate (value);
20675
20676 /* If the instruction will fail, see if we can fix things up by
20677 changing the opcode. */
20678 if (newimm == (unsigned int) FAIL)
20679 newimm = negate_data_op (&temp, value);
20680 }
20681
20682 if (newimm == (unsigned int) FAIL)
b99bd4ef 20683 {
c19d1205
ZW
20684 as_bad_where (fixP->fx_file, fixP->fx_line,
20685 _("invalid constant (%lx) after fixup"),
20686 (unsigned long) value);
20687 break;
b99bd4ef 20688 }
b99bd4ef 20689
c19d1205
ZW
20690 newimm |= (temp & 0xfffff000);
20691 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20692 break;
b99bd4ef 20693
c19d1205
ZW
20694 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20695 {
20696 unsigned int highpart = 0;
20697 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 20698
77db8e2e 20699 if (fixP->fx_addsy)
42e5fcbf 20700 {
77db8e2e 20701 const char *msg = 0;
42e5fcbf 20702
77db8e2e
NC
20703 if (! S_IS_DEFINED (fixP->fx_addsy))
20704 msg = _("undefined symbol %s used as an immediate value");
20705 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20706 msg = _("symbol %s is in a different section");
20707 else if (S_IS_WEAK (fixP->fx_addsy))
20708 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 20709
77db8e2e
NC
20710 if (msg)
20711 {
20712 as_bad_where (fixP->fx_file, fixP->fx_line,
20713 msg, S_GET_NAME (fixP->fx_addsy));
20714 break;
20715 }
20716 }
fa94de6b 20717
c19d1205
ZW
20718 newimm = encode_arm_immediate (value);
20719 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 20720
c19d1205
ZW
20721 /* If the instruction will fail, see if we can fix things up by
20722 changing the opcode. */
20723 if (newimm == (unsigned int) FAIL
20724 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20725 {
20726 /* No ? OK - try using two ADD instructions to generate
20727 the value. */
20728 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 20729
c19d1205
ZW
20730 /* Yes - then make sure that the second instruction is
20731 also an add. */
20732 if (newimm != (unsigned int) FAIL)
20733 newinsn = temp;
20734 /* Still No ? Try using a negated value. */
20735 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20736 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20737 /* Otherwise - give up. */
20738 else
20739 {
20740 as_bad_where (fixP->fx_file, fixP->fx_line,
20741 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20742 (long) value);
20743 break;
20744 }
b99bd4ef 20745
c19d1205
ZW
20746 /* Replace the first operand in the 2nd instruction (which
20747 is the PC) with the destination register. We have
20748 already added in the PC in the first instruction and we
20749 do not want to do it again. */
20750 newinsn &= ~ 0xf0000;
20751 newinsn |= ((newinsn & 0x0f000) << 4);
20752 }
b99bd4ef 20753
c19d1205
ZW
20754 newimm |= (temp & 0xfffff000);
20755 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 20756
c19d1205
ZW
20757 highpart |= (newinsn & 0xfffff000);
20758 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20759 }
20760 break;
b99bd4ef 20761
c19d1205 20762 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20763 if (!fixP->fx_done && seg->use_rela_p)
20764 value = 0;
20765
c19d1205 20766 case BFD_RELOC_ARM_LITERAL:
26d97720 20767 sign = value > 0;
b99bd4ef 20768
c19d1205
ZW
20769 if (value < 0)
20770 value = - value;
b99bd4ef 20771
c19d1205 20772 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 20773 {
c19d1205
ZW
20774 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20775 as_bad_where (fixP->fx_file, fixP->fx_line,
20776 _("invalid literal constant: pool needs to be closer"));
20777 else
20778 as_bad_where (fixP->fx_file, fixP->fx_line,
20779 _("bad immediate value for offset (%ld)"),
20780 (long) value);
20781 break;
f03698e6
RE
20782 }
20783
c19d1205 20784 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20785 if (value == 0)
20786 newval &= 0xfffff000;
20787 else
20788 {
20789 newval &= 0xff7ff000;
20790 newval |= value | (sign ? INDEX_UP : 0);
20791 }
c19d1205
ZW
20792 md_number_to_chars (buf, newval, INSN_SIZE);
20793 break;
b99bd4ef 20794
c19d1205
ZW
20795 case BFD_RELOC_ARM_OFFSET_IMM8:
20796 case BFD_RELOC_ARM_HWLITERAL:
26d97720 20797 sign = value > 0;
b99bd4ef 20798
c19d1205
ZW
20799 if (value < 0)
20800 value = - value;
b99bd4ef 20801
c19d1205 20802 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 20803 {
c19d1205
ZW
20804 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20805 as_bad_where (fixP->fx_file, fixP->fx_line,
20806 _("invalid literal constant: pool needs to be closer"));
20807 else
f9d4405b 20808 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
20809 (long) value);
20810 break;
b99bd4ef
NC
20811 }
20812
c19d1205 20813 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
20814 if (value == 0)
20815 newval &= 0xfffff0f0;
20816 else
20817 {
20818 newval &= 0xff7ff0f0;
20819 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20820 }
c19d1205
ZW
20821 md_number_to_chars (buf, newval, INSN_SIZE);
20822 break;
b99bd4ef 20823
c19d1205
ZW
20824 case BFD_RELOC_ARM_T32_OFFSET_U8:
20825 if (value < 0 || value > 1020 || value % 4 != 0)
20826 as_bad_where (fixP->fx_file, fixP->fx_line,
20827 _("bad immediate value for offset (%ld)"), (long) value);
20828 value /= 4;
b99bd4ef 20829
c19d1205 20830 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
20831 newval |= value;
20832 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20833 break;
b99bd4ef 20834
c19d1205
ZW
20835 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20836 /* This is a complicated relocation used for all varieties of Thumb32
20837 load/store instruction with immediate offset:
20838
20839 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20840 *4, optional writeback(W)
20841 (doubleword load/store)
20842
20843 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20844 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20845 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20846 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20847 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20848
20849 Uppercase letters indicate bits that are already encoded at
20850 this point. Lowercase letters are our problem. For the
20851 second block of instructions, the secondary opcode nybble
20852 (bits 8..11) is present, and bit 23 is zero, even if this is
20853 a PC-relative operation. */
20854 newval = md_chars_to_number (buf, THUMB_SIZE);
20855 newval <<= 16;
20856 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 20857
c19d1205 20858 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 20859 {
c19d1205
ZW
20860 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20861 if (value >= 0)
20862 newval |= (1 << 23);
20863 else
20864 value = -value;
20865 if (value % 4 != 0)
20866 {
20867 as_bad_where (fixP->fx_file, fixP->fx_line,
20868 _("offset not a multiple of 4"));
20869 break;
20870 }
20871 value /= 4;
216d22bc 20872 if (value > 0xff)
c19d1205
ZW
20873 {
20874 as_bad_where (fixP->fx_file, fixP->fx_line,
20875 _("offset out of range"));
20876 break;
20877 }
20878 newval &= ~0xff;
b99bd4ef 20879 }
c19d1205 20880 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20881 {
c19d1205
ZW
20882 /* PC-relative, 12-bit offset. */
20883 if (value >= 0)
20884 newval |= (1 << 23);
20885 else
20886 value = -value;
216d22bc 20887 if (value > 0xfff)
c19d1205
ZW
20888 {
20889 as_bad_where (fixP->fx_file, fixP->fx_line,
20890 _("offset out of range"));
20891 break;
20892 }
20893 newval &= ~0xfff;
b99bd4ef 20894 }
c19d1205 20895 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20896 {
c19d1205
ZW
20897 /* Writeback: 8-bit, +/- offset. */
20898 if (value >= 0)
20899 newval |= (1 << 9);
20900 else
20901 value = -value;
216d22bc 20902 if (value > 0xff)
c19d1205
ZW
20903 {
20904 as_bad_where (fixP->fx_file, fixP->fx_line,
20905 _("offset out of range"));
20906 break;
20907 }
20908 newval &= ~0xff;
b99bd4ef 20909 }
c19d1205 20910 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20911 {
c19d1205 20912 /* T-instruction: positive 8-bit offset. */
216d22bc 20913 if (value < 0 || value > 0xff)
b99bd4ef 20914 {
c19d1205
ZW
20915 as_bad_where (fixP->fx_file, fixP->fx_line,
20916 _("offset out of range"));
20917 break;
b99bd4ef 20918 }
c19d1205
ZW
20919 newval &= ~0xff;
20920 newval |= value;
b99bd4ef
NC
20921 }
20922 else
b99bd4ef 20923 {
c19d1205
ZW
20924 /* Positive 12-bit or negative 8-bit offset. */
20925 int limit;
20926 if (value >= 0)
b99bd4ef 20927 {
c19d1205
ZW
20928 newval |= (1 << 23);
20929 limit = 0xfff;
20930 }
20931 else
20932 {
20933 value = -value;
20934 limit = 0xff;
20935 }
20936 if (value > limit)
20937 {
20938 as_bad_where (fixP->fx_file, fixP->fx_line,
20939 _("offset out of range"));
20940 break;
b99bd4ef 20941 }
c19d1205 20942 newval &= ~limit;
b99bd4ef 20943 }
b99bd4ef 20944
c19d1205
ZW
20945 newval |= value;
20946 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20947 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20948 break;
404ff6b5 20949
c19d1205
ZW
20950 case BFD_RELOC_ARM_SHIFT_IMM:
20951 newval = md_chars_to_number (buf, INSN_SIZE);
20952 if (((unsigned long) value) > 32
20953 || (value == 32
20954 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20955 {
20956 as_bad_where (fixP->fx_file, fixP->fx_line,
20957 _("shift expression is too large"));
20958 break;
20959 }
404ff6b5 20960
c19d1205
ZW
20961 if (value == 0)
20962 /* Shifts of zero must be done as lsl. */
20963 newval &= ~0x60;
20964 else if (value == 32)
20965 value = 0;
20966 newval &= 0xfffff07f;
20967 newval |= (value & 0x1f) << 7;
20968 md_number_to_chars (buf, newval, INSN_SIZE);
20969 break;
404ff6b5 20970
c19d1205 20971 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20972 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20973 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20974 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20975 /* We claim that this fixup has been processed here,
20976 even if in fact we generate an error because we do
20977 not have a reloc for it, so tc_gen_reloc will reject it. */
20978 fixP->fx_done = 1;
404ff6b5 20979
c19d1205
ZW
20980 if (fixP->fx_addsy
20981 && ! S_IS_DEFINED (fixP->fx_addsy))
20982 {
20983 as_bad_where (fixP->fx_file, fixP->fx_line,
20984 _("undefined symbol %s used as an immediate value"),
20985 S_GET_NAME (fixP->fx_addsy));
20986 break;
20987 }
404ff6b5 20988
c19d1205
ZW
20989 newval = md_chars_to_number (buf, THUMB_SIZE);
20990 newval <<= 16;
20991 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20992
16805f35
PB
20993 newimm = FAIL;
20994 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20995 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20996 {
20997 newimm = encode_thumb32_immediate (value);
20998 if (newimm == (unsigned int) FAIL)
20999 newimm = thumb32_negate_data_op (&newval, value);
21000 }
16805f35
PB
21001 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
21002 && newimm == (unsigned int) FAIL)
92e90b6e 21003 {
16805f35
PB
21004 /* Turn add/sum into addw/subw. */
21005 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21006 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
21007 /* No flat 12-bit imm encoding for addsw/subsw. */
21008 if ((newval & 0x00100000) == 0)
e9f89963 21009 {
40f246e3
NC
21010 /* 12 bit immediate for addw/subw. */
21011 if (value < 0)
21012 {
21013 value = -value;
21014 newval ^= 0x00a00000;
21015 }
21016 if (value > 0xfff)
21017 newimm = (unsigned int) FAIL;
21018 else
21019 newimm = value;
e9f89963 21020 }
92e90b6e 21021 }
cc8a6dd0 21022
c19d1205 21023 if (newimm == (unsigned int)FAIL)
3631a3c8 21024 {
c19d1205
ZW
21025 as_bad_where (fixP->fx_file, fixP->fx_line,
21026 _("invalid constant (%lx) after fixup"),
21027 (unsigned long) value);
21028 break;
3631a3c8
NC
21029 }
21030
c19d1205
ZW
21031 newval |= (newimm & 0x800) << 15;
21032 newval |= (newimm & 0x700) << 4;
21033 newval |= (newimm & 0x0ff);
cc8a6dd0 21034
c19d1205
ZW
21035 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21036 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21037 break;
a737bd4d 21038
3eb17e6b 21039 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
21040 if (((unsigned long) value) > 0xffff)
21041 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 21042 _("invalid smc expression"));
2fc8bdac 21043 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21044 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21045 md_number_to_chars (buf, newval, INSN_SIZE);
21046 break;
a737bd4d 21047
90ec0d68
MGD
21048 case BFD_RELOC_ARM_HVC:
21049 if (((unsigned long) value) > 0xffff)
21050 as_bad_where (fixP->fx_file, fixP->fx_line,
21051 _("invalid hvc expression"));
21052 newval = md_chars_to_number (buf, INSN_SIZE);
21053 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21054 md_number_to_chars (buf, newval, INSN_SIZE);
21055 break;
21056
c19d1205 21057 case BFD_RELOC_ARM_SWI:
adbaf948 21058 if (fixP->tc_fix_data != 0)
c19d1205
ZW
21059 {
21060 if (((unsigned long) value) > 0xff)
21061 as_bad_where (fixP->fx_file, fixP->fx_line,
21062 _("invalid swi expression"));
2fc8bdac 21063 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
21064 newval |= value;
21065 md_number_to_chars (buf, newval, THUMB_SIZE);
21066 }
21067 else
21068 {
21069 if (((unsigned long) value) > 0x00ffffff)
21070 as_bad_where (fixP->fx_file, fixP->fx_line,
21071 _("invalid swi expression"));
2fc8bdac 21072 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
21073 newval |= value;
21074 md_number_to_chars (buf, newval, INSN_SIZE);
21075 }
21076 break;
a737bd4d 21077
c19d1205
ZW
21078 case BFD_RELOC_ARM_MULTI:
21079 if (((unsigned long) value) > 0xffff)
21080 as_bad_where (fixP->fx_file, fixP->fx_line,
21081 _("invalid expression in load/store multiple"));
21082 newval = value | md_chars_to_number (buf, INSN_SIZE);
21083 md_number_to_chars (buf, newval, INSN_SIZE);
21084 break;
a737bd4d 21085
c19d1205 21086#ifdef OBJ_ELF
39b41c9c 21087 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
21088
21089 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21090 && fixP->fx_addsy
34e77a92 21091 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21092 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21093 && THUMB_IS_FUNC (fixP->fx_addsy))
21094 /* Flip the bl to blx. This is a simple flip
21095 bit here because we generate PCREL_CALL for
21096 unconditional bls. */
21097 {
21098 newval = md_chars_to_number (buf, INSN_SIZE);
21099 newval = newval | 0x10000000;
21100 md_number_to_chars (buf, newval, INSN_SIZE);
21101 temp = 1;
21102 fixP->fx_done = 1;
21103 }
39b41c9c
PB
21104 else
21105 temp = 3;
21106 goto arm_branch_common;
21107
21108 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
21109 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21110 && fixP->fx_addsy
34e77a92 21111 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21112 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21113 && THUMB_IS_FUNC (fixP->fx_addsy))
21114 {
21115 /* This would map to a bl<cond>, b<cond>,
21116 b<always> to a Thumb function. We
21117 need to force a relocation for this particular
21118 case. */
21119 newval = md_chars_to_number (buf, INSN_SIZE);
21120 fixP->fx_done = 0;
21121 }
21122
2fc8bdac 21123 case BFD_RELOC_ARM_PLT32:
c19d1205 21124#endif
39b41c9c
PB
21125 case BFD_RELOC_ARM_PCREL_BRANCH:
21126 temp = 3;
21127 goto arm_branch_common;
a737bd4d 21128
39b41c9c 21129 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 21130
39b41c9c 21131 temp = 1;
267bf995
RR
21132 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21133 && fixP->fx_addsy
34e77a92 21134 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21135 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21136 && ARM_IS_FUNC (fixP->fx_addsy))
21137 {
21138 /* Flip the blx to a bl and warn. */
21139 const char *name = S_GET_NAME (fixP->fx_addsy);
21140 newval = 0xeb000000;
21141 as_warn_where (fixP->fx_file, fixP->fx_line,
21142 _("blx to '%s' an ARM ISA state function changed to bl"),
21143 name);
21144 md_number_to_chars (buf, newval, INSN_SIZE);
21145 temp = 3;
21146 fixP->fx_done = 1;
21147 }
21148
21149#ifdef OBJ_ELF
21150 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21151 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21152#endif
21153
39b41c9c 21154 arm_branch_common:
c19d1205 21155 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
21156 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21157 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21158 also be be clear. */
21159 if (value & temp)
c19d1205 21160 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
21161 _("misaligned branch destination"));
21162 if ((value & (offsetT)0xfe000000) != (offsetT)0
21163 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 21164 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21165
2fc8bdac 21166 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21167 {
2fc8bdac
ZW
21168 newval = md_chars_to_number (buf, INSN_SIZE);
21169 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
21170 /* Set the H bit on BLX instructions. */
21171 if (temp == 1)
21172 {
21173 if (value & 2)
21174 newval |= 0x01000000;
21175 else
21176 newval &= ~0x01000000;
21177 }
2fc8bdac 21178 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 21179 }
c19d1205 21180 break;
a737bd4d 21181
25fe350b
MS
21182 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21183 /* CBZ can only branch forward. */
a737bd4d 21184
738755b0
MS
21185 /* Attempts to use CBZ to branch to the next instruction
21186 (which, strictly speaking, are prohibited) will be turned into
21187 no-ops.
21188
21189 FIXME: It may be better to remove the instruction completely and
21190 perform relaxation. */
21191 if (value == -2)
2fc8bdac
ZW
21192 {
21193 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 21194 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
21195 md_number_to_chars (buf, newval, THUMB_SIZE);
21196 }
738755b0
MS
21197 else
21198 {
21199 if (value & ~0x7e)
08f10d51 21200 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0
MS
21201
21202 if (fixP->fx_done || !seg->use_rela_p)
21203 {
21204 newval = md_chars_to_number (buf, THUMB_SIZE);
21205 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21206 md_number_to_chars (buf, newval, THUMB_SIZE);
21207 }
21208 }
c19d1205 21209 break;
a737bd4d 21210
c19d1205 21211 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 21212 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 21213 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21214
2fc8bdac
ZW
21215 if (fixP->fx_done || !seg->use_rela_p)
21216 {
21217 newval = md_chars_to_number (buf, THUMB_SIZE);
21218 newval |= (value & 0x1ff) >> 1;
21219 md_number_to_chars (buf, newval, THUMB_SIZE);
21220 }
c19d1205 21221 break;
a737bd4d 21222
c19d1205 21223 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 21224 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 21225 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 21226
2fc8bdac
ZW
21227 if (fixP->fx_done || !seg->use_rela_p)
21228 {
21229 newval = md_chars_to_number (buf, THUMB_SIZE);
21230 newval |= (value & 0xfff) >> 1;
21231 md_number_to_chars (buf, newval, THUMB_SIZE);
21232 }
c19d1205 21233 break;
a737bd4d 21234
c19d1205 21235 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
21236 if (fixP->fx_addsy
21237 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21238 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21239 && ARM_IS_FUNC (fixP->fx_addsy)
21240 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21241 {
21242 /* Force a relocation for a branch 20 bits wide. */
21243 fixP->fx_done = 0;
21244 }
08f10d51 21245 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
21246 as_bad_where (fixP->fx_file, fixP->fx_line,
21247 _("conditional branch out of range"));
404ff6b5 21248
2fc8bdac
ZW
21249 if (fixP->fx_done || !seg->use_rela_p)
21250 {
21251 offsetT newval2;
21252 addressT S, J1, J2, lo, hi;
404ff6b5 21253
2fc8bdac
ZW
21254 S = (value & 0x00100000) >> 20;
21255 J2 = (value & 0x00080000) >> 19;
21256 J1 = (value & 0x00040000) >> 18;
21257 hi = (value & 0x0003f000) >> 12;
21258 lo = (value & 0x00000ffe) >> 1;
6c43fab6 21259
2fc8bdac
ZW
21260 newval = md_chars_to_number (buf, THUMB_SIZE);
21261 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21262 newval |= (S << 10) | hi;
21263 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21264 md_number_to_chars (buf, newval, THUMB_SIZE);
21265 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21266 }
c19d1205 21267 break;
6c43fab6 21268
c19d1205 21269 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
21270 /* If there is a blx from a thumb state function to
21271 another thumb function flip this to a bl and warn
21272 about it. */
21273
21274 if (fixP->fx_addsy
34e77a92 21275 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21276 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21277 && THUMB_IS_FUNC (fixP->fx_addsy))
21278 {
21279 const char *name = S_GET_NAME (fixP->fx_addsy);
21280 as_warn_where (fixP->fx_file, fixP->fx_line,
21281 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21282 name);
21283 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21284 newval = newval | 0x1000;
21285 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21286 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21287 fixP->fx_done = 1;
21288 }
21289
21290
21291 goto thumb_bl_common;
21292
c19d1205 21293 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
21294 /* A bl from Thumb state ISA to an internal ARM state function
21295 is converted to a blx. */
21296 if (fixP->fx_addsy
21297 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21298 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
21299 && ARM_IS_FUNC (fixP->fx_addsy)
21300 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21301 {
21302 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21303 newval = newval & ~0x1000;
21304 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21305 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21306 fixP->fx_done = 1;
21307 }
21308
21309 thumb_bl_common:
21310
21311#ifdef OBJ_ELF
2b2f5df9
NC
21312 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
21313 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
267bf995
RR
21314 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21315#endif
21316
2fc8bdac
ZW
21317 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21318 /* For a BLX instruction, make sure that the relocation is rounded up
21319 to a word boundary. This follows the semantics of the instruction
21320 which specifies that bit 1 of the target address will come from bit
21321 1 of the base address. */
21322 value = (value + 1) & ~ 1;
404ff6b5 21323
2b2f5df9
NC
21324 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21325 {
21326 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21327 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21328 else if ((value & ~0x1ffffff)
21329 && ((value & ~0x1ffffff) != ~0x1ffffff))
21330 as_bad_where (fixP->fx_file, fixP->fx_line,
21331 _("Thumb2 branch out of range"));
21332 }
4a42ebbc
RR
21333
21334 if (fixP->fx_done || !seg->use_rela_p)
21335 encode_thumb2_b_bl_offset (buf, value);
21336
c19d1205 21337 break;
404ff6b5 21338
c19d1205 21339 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
21340 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21341 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 21342
2fc8bdac 21343 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 21344 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 21345
2fc8bdac 21346 break;
a737bd4d 21347
2fc8bdac
ZW
21348 case BFD_RELOC_8:
21349 if (fixP->fx_done || !seg->use_rela_p)
21350 md_number_to_chars (buf, value, 1);
c19d1205 21351 break;
a737bd4d 21352
c19d1205 21353 case BFD_RELOC_16:
2fc8bdac 21354 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 21355 md_number_to_chars (buf, value, 2);
c19d1205 21356 break;
a737bd4d 21357
c19d1205 21358#ifdef OBJ_ELF
0855e32b
NS
21359 case BFD_RELOC_ARM_TLS_CALL:
21360 case BFD_RELOC_ARM_THM_TLS_CALL:
21361 case BFD_RELOC_ARM_TLS_DESCSEQ:
21362 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21363 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21364 break;
21365
21366 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
21367 case BFD_RELOC_ARM_TLS_GD32:
21368 case BFD_RELOC_ARM_TLS_LE32:
21369 case BFD_RELOC_ARM_TLS_IE32:
21370 case BFD_RELOC_ARM_TLS_LDM32:
21371 case BFD_RELOC_ARM_TLS_LDO32:
21372 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21373 /* fall through */
6c43fab6 21374
c19d1205
ZW
21375 case BFD_RELOC_ARM_GOT32:
21376 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
21377 if (fixP->fx_done || !seg->use_rela_p)
21378 md_number_to_chars (buf, 0, 4);
c19d1205 21379 break;
b43420e6
NC
21380
21381 case BFD_RELOC_ARM_GOT_PREL:
21382 if (fixP->fx_done || !seg->use_rela_p)
21383 md_number_to_chars (buf, value, 4);
21384 break;
21385
9a6f4e97
NS
21386 case BFD_RELOC_ARM_TARGET2:
21387 /* TARGET2 is not partial-inplace, so we need to write the
21388 addend here for REL targets, because it won't be written out
21389 during reloc processing later. */
21390 if (fixP->fx_done || !seg->use_rela_p)
21391 md_number_to_chars (buf, fixP->fx_offset, 4);
21392 break;
c19d1205 21393#endif
6c43fab6 21394
c19d1205
ZW
21395 case BFD_RELOC_RVA:
21396 case BFD_RELOC_32:
21397 case BFD_RELOC_ARM_TARGET1:
21398 case BFD_RELOC_ARM_ROSEGREL32:
21399 case BFD_RELOC_ARM_SBREL32:
21400 case BFD_RELOC_32_PCREL:
f0927246
NC
21401#ifdef TE_PE
21402 case BFD_RELOC_32_SECREL:
21403#endif
2fc8bdac 21404 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
21405#ifdef TE_WINCE
21406 /* For WinCE we only do this for pcrel fixups. */
21407 if (fixP->fx_done || fixP->fx_pcrel)
21408#endif
21409 md_number_to_chars (buf, value, 4);
c19d1205 21410 break;
6c43fab6 21411
c19d1205
ZW
21412#ifdef OBJ_ELF
21413 case BFD_RELOC_ARM_PREL31:
2fc8bdac 21414 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
21415 {
21416 newval = md_chars_to_number (buf, 4) & 0x80000000;
21417 if ((value ^ (value >> 1)) & 0x40000000)
21418 {
21419 as_bad_where (fixP->fx_file, fixP->fx_line,
21420 _("rel31 relocation overflow"));
21421 }
21422 newval |= value & 0x7fffffff;
21423 md_number_to_chars (buf, newval, 4);
21424 }
21425 break;
c19d1205 21426#endif
a737bd4d 21427
c19d1205 21428 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 21429 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
21430 if (value < -1023 || value > 1023 || (value & 3))
21431 as_bad_where (fixP->fx_file, fixP->fx_line,
21432 _("co-processor offset out of range"));
21433 cp_off_common:
26d97720 21434 sign = value > 0;
c19d1205
ZW
21435 if (value < 0)
21436 value = -value;
8f06b2d8
PB
21437 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21438 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21439 newval = md_chars_to_number (buf, INSN_SIZE);
21440 else
21441 newval = get_thumb32_insn (buf);
26d97720
NS
21442 if (value == 0)
21443 newval &= 0xffffff00;
21444 else
21445 {
21446 newval &= 0xff7fff00;
21447 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21448 }
8f06b2d8
PB
21449 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21450 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21451 md_number_to_chars (buf, newval, INSN_SIZE);
21452 else
21453 put_thumb32_insn (buf, newval);
c19d1205 21454 break;
a737bd4d 21455
c19d1205 21456 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 21457 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
21458 if (value < -255 || value > 255)
21459 as_bad_where (fixP->fx_file, fixP->fx_line,
21460 _("co-processor offset out of range"));
df7849c5 21461 value *= 4;
c19d1205 21462 goto cp_off_common;
6c43fab6 21463
c19d1205
ZW
21464 case BFD_RELOC_ARM_THUMB_OFFSET:
21465 newval = md_chars_to_number (buf, THUMB_SIZE);
21466 /* Exactly what ranges, and where the offset is inserted depends
21467 on the type of instruction, we can establish this from the
21468 top 4 bits. */
21469 switch (newval >> 12)
21470 {
21471 case 4: /* PC load. */
21472 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21473 forced to zero for these loads; md_pcrel_from has already
21474 compensated for this. */
21475 if (value & 3)
21476 as_bad_where (fixP->fx_file, fixP->fx_line,
21477 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
21478 (((unsigned long) fixP->fx_frag->fr_address
21479 + (unsigned long) fixP->fx_where) & ~3)
21480 + (unsigned long) value);
a737bd4d 21481
c19d1205
ZW
21482 if (value & ~0x3fc)
21483 as_bad_where (fixP->fx_file, fixP->fx_line,
21484 _("invalid offset, value too big (0x%08lX)"),
21485 (long) value);
a737bd4d 21486
c19d1205
ZW
21487 newval |= value >> 2;
21488 break;
a737bd4d 21489
c19d1205
ZW
21490 case 9: /* SP load/store. */
21491 if (value & ~0x3fc)
21492 as_bad_where (fixP->fx_file, fixP->fx_line,
21493 _("invalid offset, value too big (0x%08lX)"),
21494 (long) value);
21495 newval |= value >> 2;
21496 break;
6c43fab6 21497
c19d1205
ZW
21498 case 6: /* Word load/store. */
21499 if (value & ~0x7c)
21500 as_bad_where (fixP->fx_file, fixP->fx_line,
21501 _("invalid offset, value too big (0x%08lX)"),
21502 (long) value);
21503 newval |= value << 4; /* 6 - 2. */
21504 break;
a737bd4d 21505
c19d1205
ZW
21506 case 7: /* Byte load/store. */
21507 if (value & ~0x1f)
21508 as_bad_where (fixP->fx_file, fixP->fx_line,
21509 _("invalid offset, value too big (0x%08lX)"),
21510 (long) value);
21511 newval |= value << 6;
21512 break;
a737bd4d 21513
c19d1205
ZW
21514 case 8: /* Halfword load/store. */
21515 if (value & ~0x3e)
21516 as_bad_where (fixP->fx_file, fixP->fx_line,
21517 _("invalid offset, value too big (0x%08lX)"),
21518 (long) value);
21519 newval |= value << 5; /* 6 - 1. */
21520 break;
a737bd4d 21521
c19d1205
ZW
21522 default:
21523 as_bad_where (fixP->fx_file, fixP->fx_line,
21524 "Unable to process relocation for thumb opcode: %lx",
21525 (unsigned long) newval);
21526 break;
21527 }
21528 md_number_to_chars (buf, newval, THUMB_SIZE);
21529 break;
a737bd4d 21530
c19d1205
ZW
21531 case BFD_RELOC_ARM_THUMB_ADD:
21532 /* This is a complicated relocation, since we use it for all of
21533 the following immediate relocations:
a737bd4d 21534
c19d1205
ZW
21535 3bit ADD/SUB
21536 8bit ADD/SUB
21537 9bit ADD/SUB SP word-aligned
21538 10bit ADD PC/SP word-aligned
a737bd4d 21539
c19d1205
ZW
21540 The type of instruction being processed is encoded in the
21541 instruction field:
a737bd4d 21542
c19d1205
ZW
21543 0x8000 SUB
21544 0x00F0 Rd
21545 0x000F Rs
21546 */
21547 newval = md_chars_to_number (buf, THUMB_SIZE);
21548 {
21549 int rd = (newval >> 4) & 0xf;
21550 int rs = newval & 0xf;
21551 int subtract = !!(newval & 0x8000);
a737bd4d 21552
c19d1205
ZW
21553 /* Check for HI regs, only very restricted cases allowed:
21554 Adjusting SP, and using PC or SP to get an address. */
21555 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21556 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21557 as_bad_where (fixP->fx_file, fixP->fx_line,
21558 _("invalid Hi register with immediate"));
a737bd4d 21559
c19d1205
ZW
21560 /* If value is negative, choose the opposite instruction. */
21561 if (value < 0)
21562 {
21563 value = -value;
21564 subtract = !subtract;
21565 if (value < 0)
21566 as_bad_where (fixP->fx_file, fixP->fx_line,
21567 _("immediate value out of range"));
21568 }
a737bd4d 21569
c19d1205
ZW
21570 if (rd == REG_SP)
21571 {
21572 if (value & ~0x1fc)
21573 as_bad_where (fixP->fx_file, fixP->fx_line,
21574 _("invalid immediate for stack address calculation"));
21575 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21576 newval |= value >> 2;
21577 }
21578 else if (rs == REG_PC || rs == REG_SP)
21579 {
21580 if (subtract || value & ~0x3fc)
21581 as_bad_where (fixP->fx_file, fixP->fx_line,
21582 _("invalid immediate for address calculation (value = 0x%08lX)"),
21583 (unsigned long) value);
21584 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21585 newval |= rd << 8;
21586 newval |= value >> 2;
21587 }
21588 else if (rs == rd)
21589 {
21590 if (value & ~0xff)
21591 as_bad_where (fixP->fx_file, fixP->fx_line,
21592 _("immediate value out of range"));
21593 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21594 newval |= (rd << 8) | value;
21595 }
21596 else
21597 {
21598 if (value & ~0x7)
21599 as_bad_where (fixP->fx_file, fixP->fx_line,
21600 _("immediate value out of range"));
21601 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21602 newval |= rd | (rs << 3) | (value << 6);
21603 }
21604 }
21605 md_number_to_chars (buf, newval, THUMB_SIZE);
21606 break;
a737bd4d 21607
c19d1205
ZW
21608 case BFD_RELOC_ARM_THUMB_IMM:
21609 newval = md_chars_to_number (buf, THUMB_SIZE);
21610 if (value < 0 || value > 255)
21611 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 21612 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
21613 (long) value);
21614 newval |= value;
21615 md_number_to_chars (buf, newval, THUMB_SIZE);
21616 break;
a737bd4d 21617
c19d1205
ZW
21618 case BFD_RELOC_ARM_THUMB_SHIFT:
21619 /* 5bit shift value (0..32). LSL cannot take 32. */
21620 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21621 temp = newval & 0xf800;
21622 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21623 as_bad_where (fixP->fx_file, fixP->fx_line,
21624 _("invalid shift value: %ld"), (long) value);
21625 /* Shifts of zero must be encoded as LSL. */
21626 if (value == 0)
21627 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21628 /* Shifts of 32 are encoded as zero. */
21629 else if (value == 32)
21630 value = 0;
21631 newval |= value << 6;
21632 md_number_to_chars (buf, newval, THUMB_SIZE);
21633 break;
a737bd4d 21634
c19d1205
ZW
21635 case BFD_RELOC_VTABLE_INHERIT:
21636 case BFD_RELOC_VTABLE_ENTRY:
21637 fixP->fx_done = 0;
21638 return;
6c43fab6 21639
b6895b4f
PB
21640 case BFD_RELOC_ARM_MOVW:
21641 case BFD_RELOC_ARM_MOVT:
21642 case BFD_RELOC_ARM_THUMB_MOVW:
21643 case BFD_RELOC_ARM_THUMB_MOVT:
21644 if (fixP->fx_done || !seg->use_rela_p)
21645 {
21646 /* REL format relocations are limited to a 16-bit addend. */
21647 if (!fixP->fx_done)
21648 {
39623e12 21649 if (value < -0x8000 || value > 0x7fff)
b6895b4f 21650 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 21651 _("offset out of range"));
b6895b4f
PB
21652 }
21653 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21654 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21655 {
21656 value >>= 16;
21657 }
21658
21659 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21660 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21661 {
21662 newval = get_thumb32_insn (buf);
21663 newval &= 0xfbf08f00;
21664 newval |= (value & 0xf000) << 4;
21665 newval |= (value & 0x0800) << 15;
21666 newval |= (value & 0x0700) << 4;
21667 newval |= (value & 0x00ff);
21668 put_thumb32_insn (buf, newval);
21669 }
21670 else
21671 {
21672 newval = md_chars_to_number (buf, 4);
21673 newval &= 0xfff0f000;
21674 newval |= value & 0x0fff;
21675 newval |= (value & 0xf000) << 4;
21676 md_number_to_chars (buf, newval, 4);
21677 }
21678 }
21679 return;
21680
4962c51a
MS
21681 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21682 case BFD_RELOC_ARM_ALU_PC_G0:
21683 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21684 case BFD_RELOC_ARM_ALU_PC_G1:
21685 case BFD_RELOC_ARM_ALU_PC_G2:
21686 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21687 case BFD_RELOC_ARM_ALU_SB_G0:
21688 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21689 case BFD_RELOC_ARM_ALU_SB_G1:
21690 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 21691 gas_assert (!fixP->fx_done);
4962c51a
MS
21692 if (!seg->use_rela_p)
21693 {
21694 bfd_vma insn;
21695 bfd_vma encoded_addend;
21696 bfd_vma addend_abs = abs (value);
21697
21698 /* Check that the absolute value of the addend can be
21699 expressed as an 8-bit constant plus a rotation. */
21700 encoded_addend = encode_arm_immediate (addend_abs);
21701 if (encoded_addend == (unsigned int) FAIL)
21702 as_bad_where (fixP->fx_file, fixP->fx_line,
21703 _("the offset 0x%08lX is not representable"),
495bde8e 21704 (unsigned long) addend_abs);
4962c51a
MS
21705
21706 /* Extract the instruction. */
21707 insn = md_chars_to_number (buf, INSN_SIZE);
21708
21709 /* If the addend is positive, use an ADD instruction.
21710 Otherwise use a SUB. Take care not to destroy the S bit. */
21711 insn &= 0xff1fffff;
21712 if (value < 0)
21713 insn |= 1 << 22;
21714 else
21715 insn |= 1 << 23;
21716
21717 /* Place the encoded addend into the first 12 bits of the
21718 instruction. */
21719 insn &= 0xfffff000;
21720 insn |= encoded_addend;
5f4273c7
NC
21721
21722 /* Update the instruction. */
4962c51a
MS
21723 md_number_to_chars (buf, insn, INSN_SIZE);
21724 }
21725 break;
21726
21727 case BFD_RELOC_ARM_LDR_PC_G0:
21728 case BFD_RELOC_ARM_LDR_PC_G1:
21729 case BFD_RELOC_ARM_LDR_PC_G2:
21730 case BFD_RELOC_ARM_LDR_SB_G0:
21731 case BFD_RELOC_ARM_LDR_SB_G1:
21732 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 21733 gas_assert (!fixP->fx_done);
4962c51a
MS
21734 if (!seg->use_rela_p)
21735 {
21736 bfd_vma insn;
21737 bfd_vma addend_abs = abs (value);
21738
21739 /* Check that the absolute value of the addend can be
21740 encoded in 12 bits. */
21741 if (addend_abs >= 0x1000)
21742 as_bad_where (fixP->fx_file, fixP->fx_line,
21743 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 21744 (unsigned long) addend_abs);
4962c51a
MS
21745
21746 /* Extract the instruction. */
21747 insn = md_chars_to_number (buf, INSN_SIZE);
21748
21749 /* If the addend is negative, clear bit 23 of the instruction.
21750 Otherwise set it. */
21751 if (value < 0)
21752 insn &= ~(1 << 23);
21753 else
21754 insn |= 1 << 23;
21755
21756 /* Place the absolute value of the addend into the first 12 bits
21757 of the instruction. */
21758 insn &= 0xfffff000;
21759 insn |= addend_abs;
5f4273c7
NC
21760
21761 /* Update the instruction. */
4962c51a
MS
21762 md_number_to_chars (buf, insn, INSN_SIZE);
21763 }
21764 break;
21765
21766 case BFD_RELOC_ARM_LDRS_PC_G0:
21767 case BFD_RELOC_ARM_LDRS_PC_G1:
21768 case BFD_RELOC_ARM_LDRS_PC_G2:
21769 case BFD_RELOC_ARM_LDRS_SB_G0:
21770 case BFD_RELOC_ARM_LDRS_SB_G1:
21771 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 21772 gas_assert (!fixP->fx_done);
4962c51a
MS
21773 if (!seg->use_rela_p)
21774 {
21775 bfd_vma insn;
21776 bfd_vma addend_abs = abs (value);
21777
21778 /* Check that the absolute value of the addend can be
21779 encoded in 8 bits. */
21780 if (addend_abs >= 0x100)
21781 as_bad_where (fixP->fx_file, fixP->fx_line,
21782 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 21783 (unsigned long) addend_abs);
4962c51a
MS
21784
21785 /* Extract the instruction. */
21786 insn = md_chars_to_number (buf, INSN_SIZE);
21787
21788 /* If the addend is negative, clear bit 23 of the instruction.
21789 Otherwise set it. */
21790 if (value < 0)
21791 insn &= ~(1 << 23);
21792 else
21793 insn |= 1 << 23;
21794
21795 /* Place the first four bits of the absolute value of the addend
21796 into the first 4 bits of the instruction, and the remaining
21797 four into bits 8 .. 11. */
21798 insn &= 0xfffff0f0;
21799 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
21800
21801 /* Update the instruction. */
4962c51a
MS
21802 md_number_to_chars (buf, insn, INSN_SIZE);
21803 }
21804 break;
21805
21806 case BFD_RELOC_ARM_LDC_PC_G0:
21807 case BFD_RELOC_ARM_LDC_PC_G1:
21808 case BFD_RELOC_ARM_LDC_PC_G2:
21809 case BFD_RELOC_ARM_LDC_SB_G0:
21810 case BFD_RELOC_ARM_LDC_SB_G1:
21811 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 21812 gas_assert (!fixP->fx_done);
4962c51a
MS
21813 if (!seg->use_rela_p)
21814 {
21815 bfd_vma insn;
21816 bfd_vma addend_abs = abs (value);
21817
21818 /* Check that the absolute value of the addend is a multiple of
21819 four and, when divided by four, fits in 8 bits. */
21820 if (addend_abs & 0x3)
21821 as_bad_where (fixP->fx_file, fixP->fx_line,
21822 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 21823 (unsigned long) addend_abs);
4962c51a
MS
21824
21825 if ((addend_abs >> 2) > 0xff)
21826 as_bad_where (fixP->fx_file, fixP->fx_line,
21827 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 21828 (unsigned long) addend_abs);
4962c51a
MS
21829
21830 /* Extract the instruction. */
21831 insn = md_chars_to_number (buf, INSN_SIZE);
21832
21833 /* If the addend is negative, clear bit 23 of the instruction.
21834 Otherwise set it. */
21835 if (value < 0)
21836 insn &= ~(1 << 23);
21837 else
21838 insn |= 1 << 23;
21839
21840 /* Place the addend (divided by four) into the first eight
21841 bits of the instruction. */
21842 insn &= 0xfffffff0;
21843 insn |= addend_abs >> 2;
5f4273c7
NC
21844
21845 /* Update the instruction. */
4962c51a
MS
21846 md_number_to_chars (buf, insn, INSN_SIZE);
21847 }
21848 break;
21849
845b51d6
PB
21850 case BFD_RELOC_ARM_V4BX:
21851 /* This will need to go in the object file. */
21852 fixP->fx_done = 0;
21853 break;
21854
c19d1205
ZW
21855 case BFD_RELOC_UNUSED:
21856 default:
21857 as_bad_where (fixP->fx_file, fixP->fx_line,
21858 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21859 }
6c43fab6
RE
21860}
21861
c19d1205
ZW
21862/* Translate internal representation of relocation info to BFD target
21863 format. */
a737bd4d 21864
c19d1205 21865arelent *
00a97672 21866tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 21867{
c19d1205
ZW
21868 arelent * reloc;
21869 bfd_reloc_code_real_type code;
a737bd4d 21870
21d799b5 21871 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 21872
21d799b5 21873 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
21874 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21875 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 21876
2fc8bdac 21877 if (fixp->fx_pcrel)
00a97672
RS
21878 {
21879 if (section->use_rela_p)
21880 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21881 else
21882 fixp->fx_offset = reloc->address;
21883 }
c19d1205 21884 reloc->addend = fixp->fx_offset;
a737bd4d 21885
c19d1205 21886 switch (fixp->fx_r_type)
a737bd4d 21887 {
c19d1205
ZW
21888 case BFD_RELOC_8:
21889 if (fixp->fx_pcrel)
21890 {
21891 code = BFD_RELOC_8_PCREL;
21892 break;
21893 }
a737bd4d 21894
c19d1205
ZW
21895 case BFD_RELOC_16:
21896 if (fixp->fx_pcrel)
21897 {
21898 code = BFD_RELOC_16_PCREL;
21899 break;
21900 }
6c43fab6 21901
c19d1205
ZW
21902 case BFD_RELOC_32:
21903 if (fixp->fx_pcrel)
21904 {
21905 code = BFD_RELOC_32_PCREL;
21906 break;
21907 }
a737bd4d 21908
b6895b4f
PB
21909 case BFD_RELOC_ARM_MOVW:
21910 if (fixp->fx_pcrel)
21911 {
21912 code = BFD_RELOC_ARM_MOVW_PCREL;
21913 break;
21914 }
21915
21916 case BFD_RELOC_ARM_MOVT:
21917 if (fixp->fx_pcrel)
21918 {
21919 code = BFD_RELOC_ARM_MOVT_PCREL;
21920 break;
21921 }
21922
21923 case BFD_RELOC_ARM_THUMB_MOVW:
21924 if (fixp->fx_pcrel)
21925 {
21926 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21927 break;
21928 }
21929
21930 case BFD_RELOC_ARM_THUMB_MOVT:
21931 if (fixp->fx_pcrel)
21932 {
21933 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21934 break;
21935 }
21936
c19d1205
ZW
21937 case BFD_RELOC_NONE:
21938 case BFD_RELOC_ARM_PCREL_BRANCH:
21939 case BFD_RELOC_ARM_PCREL_BLX:
21940 case BFD_RELOC_RVA:
21941 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21942 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21943 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21944 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21945 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21946 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21947 case BFD_RELOC_VTABLE_ENTRY:
21948 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21949#ifdef TE_PE
21950 case BFD_RELOC_32_SECREL:
21951#endif
c19d1205
ZW
21952 code = fixp->fx_r_type;
21953 break;
a737bd4d 21954
00adf2d4
JB
21955 case BFD_RELOC_THUMB_PCREL_BLX:
21956#ifdef OBJ_ELF
21957 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21958 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21959 else
21960#endif
21961 code = BFD_RELOC_THUMB_PCREL_BLX;
21962 break;
21963
c19d1205
ZW
21964 case BFD_RELOC_ARM_LITERAL:
21965 case BFD_RELOC_ARM_HWLITERAL:
21966 /* If this is called then the a literal has
21967 been referenced across a section boundary. */
21968 as_bad_where (fixp->fx_file, fixp->fx_line,
21969 _("literal referenced across section boundary"));
21970 return NULL;
a737bd4d 21971
c19d1205 21972#ifdef OBJ_ELF
0855e32b
NS
21973 case BFD_RELOC_ARM_TLS_CALL:
21974 case BFD_RELOC_ARM_THM_TLS_CALL:
21975 case BFD_RELOC_ARM_TLS_DESCSEQ:
21976 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
21977 case BFD_RELOC_ARM_GOT32:
21978 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21979 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21980 case BFD_RELOC_ARM_PLT32:
21981 case BFD_RELOC_ARM_TARGET1:
21982 case BFD_RELOC_ARM_ROSEGREL32:
21983 case BFD_RELOC_ARM_SBREL32:
21984 case BFD_RELOC_ARM_PREL31:
21985 case BFD_RELOC_ARM_TARGET2:
21986 case BFD_RELOC_ARM_TLS_LE32:
21987 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21988 case BFD_RELOC_ARM_PCREL_CALL:
21989 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21990 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21991 case BFD_RELOC_ARM_ALU_PC_G0:
21992 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21993 case BFD_RELOC_ARM_ALU_PC_G1:
21994 case BFD_RELOC_ARM_ALU_PC_G2:
21995 case BFD_RELOC_ARM_LDR_PC_G0:
21996 case BFD_RELOC_ARM_LDR_PC_G1:
21997 case BFD_RELOC_ARM_LDR_PC_G2:
21998 case BFD_RELOC_ARM_LDRS_PC_G0:
21999 case BFD_RELOC_ARM_LDRS_PC_G1:
22000 case BFD_RELOC_ARM_LDRS_PC_G2:
22001 case BFD_RELOC_ARM_LDC_PC_G0:
22002 case BFD_RELOC_ARM_LDC_PC_G1:
22003 case BFD_RELOC_ARM_LDC_PC_G2:
22004 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22005 case BFD_RELOC_ARM_ALU_SB_G0:
22006 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22007 case BFD_RELOC_ARM_ALU_SB_G1:
22008 case BFD_RELOC_ARM_ALU_SB_G2:
22009 case BFD_RELOC_ARM_LDR_SB_G0:
22010 case BFD_RELOC_ARM_LDR_SB_G1:
22011 case BFD_RELOC_ARM_LDR_SB_G2:
22012 case BFD_RELOC_ARM_LDRS_SB_G0:
22013 case BFD_RELOC_ARM_LDRS_SB_G1:
22014 case BFD_RELOC_ARM_LDRS_SB_G2:
22015 case BFD_RELOC_ARM_LDC_SB_G0:
22016 case BFD_RELOC_ARM_LDC_SB_G1:
22017 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 22018 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
22019 code = fixp->fx_r_type;
22020 break;
a737bd4d 22021
0855e32b 22022 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22023 case BFD_RELOC_ARM_TLS_GD32:
22024 case BFD_RELOC_ARM_TLS_IE32:
22025 case BFD_RELOC_ARM_TLS_LDM32:
22026 /* BFD will include the symbol's address in the addend.
22027 But we don't want that, so subtract it out again here. */
22028 if (!S_IS_COMMON (fixp->fx_addsy))
22029 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
22030 code = fixp->fx_r_type;
22031 break;
22032#endif
a737bd4d 22033
c19d1205
ZW
22034 case BFD_RELOC_ARM_IMMEDIATE:
22035 as_bad_where (fixp->fx_file, fixp->fx_line,
22036 _("internal relocation (type: IMMEDIATE) not fixed up"));
22037 return NULL;
a737bd4d 22038
c19d1205
ZW
22039 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22040 as_bad_where (fixp->fx_file, fixp->fx_line,
22041 _("ADRL used for a symbol not defined in the same file"));
22042 return NULL;
a737bd4d 22043
c19d1205 22044 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22045 if (section->use_rela_p)
22046 {
22047 code = fixp->fx_r_type;
22048 break;
22049 }
22050
c19d1205
ZW
22051 if (fixp->fx_addsy != NULL
22052 && !S_IS_DEFINED (fixp->fx_addsy)
22053 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 22054 {
c19d1205
ZW
22055 as_bad_where (fixp->fx_file, fixp->fx_line,
22056 _("undefined local label `%s'"),
22057 S_GET_NAME (fixp->fx_addsy));
22058 return NULL;
a737bd4d
NC
22059 }
22060
c19d1205
ZW
22061 as_bad_where (fixp->fx_file, fixp->fx_line,
22062 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22063 return NULL;
a737bd4d 22064
c19d1205
ZW
22065 default:
22066 {
22067 char * type;
6c43fab6 22068
c19d1205
ZW
22069 switch (fixp->fx_r_type)
22070 {
22071 case BFD_RELOC_NONE: type = "NONE"; break;
22072 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22073 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 22074 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
22075 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22076 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22077 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 22078 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 22079 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
22080 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22081 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22082 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22083 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22084 default: type = _("<unknown>"); break;
22085 }
22086 as_bad_where (fixp->fx_file, fixp->fx_line,
22087 _("cannot represent %s relocation in this object file format"),
22088 type);
22089 return NULL;
22090 }
a737bd4d 22091 }
6c43fab6 22092
c19d1205
ZW
22093#ifdef OBJ_ELF
22094 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22095 && GOT_symbol
22096 && fixp->fx_addsy == GOT_symbol)
22097 {
22098 code = BFD_RELOC_ARM_GOTPC;
22099 reloc->addend = fixp->fx_offset = reloc->address;
22100 }
22101#endif
6c43fab6 22102
c19d1205 22103 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 22104
c19d1205
ZW
22105 if (reloc->howto == NULL)
22106 {
22107 as_bad_where (fixp->fx_file, fixp->fx_line,
22108 _("cannot represent %s relocation in this object file format"),
22109 bfd_get_reloc_code_name (code));
22110 return NULL;
22111 }
6c43fab6 22112
c19d1205
ZW
22113 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22114 vtable entry to be used in the relocation's section offset. */
22115 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22116 reloc->address = fixp->fx_offset;
6c43fab6 22117
c19d1205 22118 return reloc;
6c43fab6
RE
22119}
22120
c19d1205 22121/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 22122
c19d1205
ZW
22123void
22124cons_fix_new_arm (fragS * frag,
22125 int where,
22126 int size,
22127 expressionS * exp)
6c43fab6 22128{
c19d1205
ZW
22129 bfd_reloc_code_real_type type;
22130 int pcrel = 0;
6c43fab6 22131
c19d1205
ZW
22132 /* Pick a reloc.
22133 FIXME: @@ Should look at CPU word size. */
22134 switch (size)
22135 {
22136 case 1:
22137 type = BFD_RELOC_8;
22138 break;
22139 case 2:
22140 type = BFD_RELOC_16;
22141 break;
22142 case 4:
22143 default:
22144 type = BFD_RELOC_32;
22145 break;
22146 case 8:
22147 type = BFD_RELOC_64;
22148 break;
22149 }
6c43fab6 22150
f0927246
NC
22151#ifdef TE_PE
22152 if (exp->X_op == O_secrel)
22153 {
22154 exp->X_op = O_symbol;
22155 type = BFD_RELOC_32_SECREL;
22156 }
22157#endif
22158
c19d1205
ZW
22159 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22160}
6c43fab6 22161
4343666d 22162#if defined (OBJ_COFF)
c19d1205
ZW
22163void
22164arm_validate_fix (fixS * fixP)
6c43fab6 22165{
c19d1205
ZW
22166 /* If the destination of the branch is a defined symbol which does not have
22167 the THUMB_FUNC attribute, then we must be calling a function which has
22168 the (interfacearm) attribute. We look for the Thumb entry point to that
22169 function and change the branch to refer to that function instead. */
22170 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22171 && fixP->fx_addsy != NULL
22172 && S_IS_DEFINED (fixP->fx_addsy)
22173 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 22174 {
c19d1205 22175 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 22176 }
c19d1205
ZW
22177}
22178#endif
6c43fab6 22179
267bf995 22180
c19d1205
ZW
22181int
22182arm_force_relocation (struct fix * fixp)
22183{
22184#if defined (OBJ_COFF) && defined (TE_PE)
22185 if (fixp->fx_r_type == BFD_RELOC_RVA)
22186 return 1;
22187#endif
6c43fab6 22188
267bf995
RR
22189 /* In case we have a call or a branch to a function in ARM ISA mode from
22190 a thumb function or vice-versa force the relocation. These relocations
22191 are cleared off for some cores that might have blx and simple transformations
22192 are possible. */
22193
22194#ifdef OBJ_ELF
22195 switch (fixp->fx_r_type)
22196 {
22197 case BFD_RELOC_ARM_PCREL_JUMP:
22198 case BFD_RELOC_ARM_PCREL_CALL:
22199 case BFD_RELOC_THUMB_PCREL_BLX:
22200 if (THUMB_IS_FUNC (fixp->fx_addsy))
22201 return 1;
22202 break;
22203
22204 case BFD_RELOC_ARM_PCREL_BLX:
22205 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22206 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22207 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22208 if (ARM_IS_FUNC (fixp->fx_addsy))
22209 return 1;
22210 break;
22211
22212 default:
22213 break;
22214 }
22215#endif
22216
b5884301
PB
22217 /* Resolve these relocations even if the symbol is extern or weak.
22218 Technically this is probably wrong due to symbol preemption.
22219 In practice these relocations do not have enough range to be useful
22220 at dynamic link time, and some code (e.g. in the Linux kernel)
22221 expects these references to be resolved. */
c19d1205
ZW
22222 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22223 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 22224 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 22225 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
22226 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22227 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22228 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 22229 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
22230 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22231 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
22232 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22233 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22234 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22235 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 22236 return 0;
a737bd4d 22237
4962c51a
MS
22238 /* Always leave these relocations for the linker. */
22239 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22240 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22241 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22242 return 1;
22243
f0291e4c
PB
22244 /* Always generate relocations against function symbols. */
22245 if (fixp->fx_r_type == BFD_RELOC_32
22246 && fixp->fx_addsy
22247 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22248 return 1;
22249
c19d1205 22250 return generic_force_reloc (fixp);
404ff6b5
AH
22251}
22252
0ffdc86c 22253#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
22254/* Relocations against function names must be left unadjusted,
22255 so that the linker can use this information to generate interworking
22256 stubs. The MIPS version of this function
c19d1205
ZW
22257 also prevents relocations that are mips-16 specific, but I do not
22258 know why it does this.
404ff6b5 22259
c19d1205
ZW
22260 FIXME:
22261 There is one other problem that ought to be addressed here, but
22262 which currently is not: Taking the address of a label (rather
22263 than a function) and then later jumping to that address. Such
22264 addresses also ought to have their bottom bit set (assuming that
22265 they reside in Thumb code), but at the moment they will not. */
404ff6b5 22266
c19d1205
ZW
22267bfd_boolean
22268arm_fix_adjustable (fixS * fixP)
404ff6b5 22269{
c19d1205
ZW
22270 if (fixP->fx_addsy == NULL)
22271 return 1;
404ff6b5 22272
e28387c3
PB
22273 /* Preserve relocations against symbols with function type. */
22274 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 22275 return FALSE;
e28387c3 22276
c19d1205
ZW
22277 if (THUMB_IS_FUNC (fixP->fx_addsy)
22278 && fixP->fx_subsy == NULL)
c921be7d 22279 return FALSE;
a737bd4d 22280
c19d1205
ZW
22281 /* We need the symbol name for the VTABLE entries. */
22282 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22283 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 22284 return FALSE;
404ff6b5 22285
c19d1205
ZW
22286 /* Don't allow symbols to be discarded on GOT related relocs. */
22287 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22288 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22289 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22290 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22291 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22292 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22293 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22294 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
22295 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22296 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22297 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22298 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22299 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 22300 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 22301 return FALSE;
a737bd4d 22302
4962c51a
MS
22303 /* Similarly for group relocations. */
22304 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22305 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22306 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 22307 return FALSE;
4962c51a 22308
79947c54
CD
22309 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22310 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22311 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22312 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22313 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22314 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22315 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22316 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22317 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 22318 return FALSE;
79947c54 22319
c921be7d 22320 return TRUE;
a737bd4d 22321}
0ffdc86c
NC
22322#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22323
22324#ifdef OBJ_ELF
404ff6b5 22325
c19d1205
ZW
22326const char *
22327elf32_arm_target_format (void)
404ff6b5 22328{
c19d1205
ZW
22329#ifdef TE_SYMBIAN
22330 return (target_big_endian
22331 ? "elf32-bigarm-symbian"
22332 : "elf32-littlearm-symbian");
22333#elif defined (TE_VXWORKS)
22334 return (target_big_endian
22335 ? "elf32-bigarm-vxworks"
22336 : "elf32-littlearm-vxworks");
b38cadfb
NC
22337#elif defined (TE_NACL)
22338 return (target_big_endian
22339 ? "elf32-bigarm-nacl"
22340 : "elf32-littlearm-nacl");
c19d1205
ZW
22341#else
22342 if (target_big_endian)
22343 return "elf32-bigarm";
22344 else
22345 return "elf32-littlearm";
22346#endif
404ff6b5
AH
22347}
22348
c19d1205
ZW
22349void
22350armelf_frob_symbol (symbolS * symp,
22351 int * puntp)
404ff6b5 22352{
c19d1205
ZW
22353 elf_frob_symbol (symp, puntp);
22354}
22355#endif
404ff6b5 22356
c19d1205 22357/* MD interface: Finalization. */
a737bd4d 22358
c19d1205
ZW
22359void
22360arm_cleanup (void)
22361{
22362 literal_pool * pool;
a737bd4d 22363
e07e6e58
NC
22364 /* Ensure that all the IT blocks are properly closed. */
22365 check_it_blocks_finished ();
22366
c19d1205
ZW
22367 for (pool = list_of_pools; pool; pool = pool->next)
22368 {
5f4273c7 22369 /* Put it at the end of the relevant section. */
c19d1205
ZW
22370 subseg_set (pool->section, pool->sub_section);
22371#ifdef OBJ_ELF
22372 arm_elf_change_section ();
22373#endif
22374 s_ltorg (0);
22375 }
404ff6b5
AH
22376}
22377
cd000bff
DJ
22378#ifdef OBJ_ELF
22379/* Remove any excess mapping symbols generated for alignment frags in
22380 SEC. We may have created a mapping symbol before a zero byte
22381 alignment; remove it if there's a mapping symbol after the
22382 alignment. */
22383static void
22384check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22385 void *dummy ATTRIBUTE_UNUSED)
22386{
22387 segment_info_type *seginfo = seg_info (sec);
22388 fragS *fragp;
22389
22390 if (seginfo == NULL || seginfo->frchainP == NULL)
22391 return;
22392
22393 for (fragp = seginfo->frchainP->frch_root;
22394 fragp != NULL;
22395 fragp = fragp->fr_next)
22396 {
22397 symbolS *sym = fragp->tc_frag_data.last_map;
22398 fragS *next = fragp->fr_next;
22399
22400 /* Variable-sized frags have been converted to fixed size by
22401 this point. But if this was variable-sized to start with,
22402 there will be a fixed-size frag after it. So don't handle
22403 next == NULL. */
22404 if (sym == NULL || next == NULL)
22405 continue;
22406
22407 if (S_GET_VALUE (sym) < next->fr_address)
22408 /* Not at the end of this frag. */
22409 continue;
22410 know (S_GET_VALUE (sym) == next->fr_address);
22411
22412 do
22413 {
22414 if (next->tc_frag_data.first_map != NULL)
22415 {
22416 /* Next frag starts with a mapping symbol. Discard this
22417 one. */
22418 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22419 break;
22420 }
22421
22422 if (next->fr_next == NULL)
22423 {
22424 /* This mapping symbol is at the end of the section. Discard
22425 it. */
22426 know (next->fr_fix == 0 && next->fr_var == 0);
22427 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22428 break;
22429 }
22430
22431 /* As long as we have empty frags without any mapping symbols,
22432 keep looking. */
22433 /* If the next frag is non-empty and does not start with a
22434 mapping symbol, then this mapping symbol is required. */
22435 if (next->fr_address != next->fr_next->fr_address)
22436 break;
22437
22438 next = next->fr_next;
22439 }
22440 while (next != NULL);
22441 }
22442}
22443#endif
22444
c19d1205
ZW
22445/* Adjust the symbol table. This marks Thumb symbols as distinct from
22446 ARM ones. */
404ff6b5 22447
c19d1205
ZW
22448void
22449arm_adjust_symtab (void)
404ff6b5 22450{
c19d1205
ZW
22451#ifdef OBJ_COFF
22452 symbolS * sym;
404ff6b5 22453
c19d1205
ZW
22454 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22455 {
22456 if (ARM_IS_THUMB (sym))
22457 {
22458 if (THUMB_IS_FUNC (sym))
22459 {
22460 /* Mark the symbol as a Thumb function. */
22461 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22462 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22463 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 22464
c19d1205
ZW
22465 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22466 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22467 else
22468 as_bad (_("%s: unexpected function type: %d"),
22469 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22470 }
22471 else switch (S_GET_STORAGE_CLASS (sym))
22472 {
22473 case C_EXT:
22474 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22475 break;
22476 case C_STAT:
22477 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22478 break;
22479 case C_LABEL:
22480 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22481 break;
22482 default:
22483 /* Do nothing. */
22484 break;
22485 }
22486 }
a737bd4d 22487
c19d1205
ZW
22488 if (ARM_IS_INTERWORK (sym))
22489 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 22490 }
c19d1205
ZW
22491#endif
22492#ifdef OBJ_ELF
22493 symbolS * sym;
22494 char bind;
404ff6b5 22495
c19d1205 22496 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 22497 {
c19d1205
ZW
22498 if (ARM_IS_THUMB (sym))
22499 {
22500 elf_symbol_type * elf_sym;
404ff6b5 22501
c19d1205
ZW
22502 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22503 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 22504
b0796911
PB
22505 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22506 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
22507 {
22508 /* If it's a .thumb_func, declare it as so,
22509 otherwise tag label as .code 16. */
22510 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
22511 elf_sym->internal_elf_sym.st_target_internal
22512 = ST_BRANCH_TO_THUMB;
3ba67470 22513 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
22514 elf_sym->internal_elf_sym.st_info =
22515 ELF_ST_INFO (bind, STT_ARM_16BIT);
22516 }
22517 }
22518 }
cd000bff
DJ
22519
22520 /* Remove any overlapping mapping symbols generated by alignment frags. */
22521 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
22522 /* Now do generic ELF adjustments. */
22523 elf_adjust_symtab ();
c19d1205 22524#endif
404ff6b5
AH
22525}
22526
c19d1205 22527/* MD interface: Initialization. */
404ff6b5 22528
a737bd4d 22529static void
c19d1205 22530set_constant_flonums (void)
a737bd4d 22531{
c19d1205 22532 int i;
404ff6b5 22533
c19d1205
ZW
22534 for (i = 0; i < NUM_FLOAT_VALS; i++)
22535 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22536 abort ();
a737bd4d 22537}
404ff6b5 22538
3e9e4fcf
JB
22539/* Auto-select Thumb mode if it's the only available instruction set for the
22540 given architecture. */
22541
22542static void
22543autoselect_thumb_from_cpu_variant (void)
22544{
22545 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22546 opcode_select (16);
22547}
22548
c19d1205
ZW
22549void
22550md_begin (void)
a737bd4d 22551{
c19d1205
ZW
22552 unsigned mach;
22553 unsigned int i;
404ff6b5 22554
c19d1205
ZW
22555 if ( (arm_ops_hsh = hash_new ()) == NULL
22556 || (arm_cond_hsh = hash_new ()) == NULL
22557 || (arm_shift_hsh = hash_new ()) == NULL
22558 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 22559 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 22560 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
22561 || (arm_reloc_hsh = hash_new ()) == NULL
22562 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
22563 as_fatal (_("virtual memory exhausted"));
22564
22565 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 22566 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 22567 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 22568 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 22569 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 22570 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 22571 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 22572 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 22573 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
22574 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22575 (void *) (v7m_psrs + i));
c19d1205 22576 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 22577 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
22578 for (i = 0;
22579 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22580 i++)
d3ce72d0 22581 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 22582 (void *) (barrier_opt_names + i));
c19d1205 22583#ifdef OBJ_ELF
3da1d841
NC
22584 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
22585 {
22586 struct reloc_entry * entry = reloc_names + i;
22587
22588 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
22589 /* This makes encode_branch() use the EABI versions of this relocation. */
22590 entry->reloc = BFD_RELOC_UNUSED;
22591
22592 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
22593 }
c19d1205
ZW
22594#endif
22595
22596 set_constant_flonums ();
404ff6b5 22597
c19d1205
ZW
22598 /* Set the cpu variant based on the command-line options. We prefer
22599 -mcpu= over -march= if both are set (as for GCC); and we prefer
22600 -mfpu= over any other way of setting the floating point unit.
22601 Use of legacy options with new options are faulted. */
e74cfd16 22602 if (legacy_cpu)
404ff6b5 22603 {
e74cfd16 22604 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
22605 as_bad (_("use of old and new-style options to set CPU type"));
22606
22607 mcpu_cpu_opt = legacy_cpu;
404ff6b5 22608 }
e74cfd16 22609 else if (!mcpu_cpu_opt)
c19d1205 22610 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 22611
e74cfd16 22612 if (legacy_fpu)
c19d1205 22613 {
e74cfd16 22614 if (mfpu_opt)
c19d1205 22615 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
22616
22617 mfpu_opt = legacy_fpu;
22618 }
e74cfd16 22619 else if (!mfpu_opt)
03b1477f 22620 {
45eb4c1b
NS
22621#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22622 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
22623 /* Some environments specify a default FPU. If they don't, infer it
22624 from the processor. */
e74cfd16 22625 if (mcpu_fpu_opt)
03b1477f
RE
22626 mfpu_opt = mcpu_fpu_opt;
22627 else
22628 mfpu_opt = march_fpu_opt;
39c2da32 22629#else
e74cfd16 22630 mfpu_opt = &fpu_default;
39c2da32 22631#endif
03b1477f
RE
22632 }
22633
e74cfd16 22634 if (!mfpu_opt)
03b1477f 22635 {
493cb6ef 22636 if (mcpu_cpu_opt != NULL)
e74cfd16 22637 mfpu_opt = &fpu_default;
493cb6ef 22638 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 22639 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 22640 else
e74cfd16 22641 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
22642 }
22643
ee065d83 22644#ifdef CPU_DEFAULT
e74cfd16 22645 if (!mcpu_cpu_opt)
ee065d83 22646 {
e74cfd16
PB
22647 mcpu_cpu_opt = &cpu_default;
22648 selected_cpu = cpu_default;
ee065d83 22649 }
e74cfd16
PB
22650#else
22651 if (mcpu_cpu_opt)
22652 selected_cpu = *mcpu_cpu_opt;
ee065d83 22653 else
e74cfd16 22654 mcpu_cpu_opt = &arm_arch_any;
ee065d83 22655#endif
03b1477f 22656
e74cfd16 22657 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 22658
3e9e4fcf
JB
22659 autoselect_thumb_from_cpu_variant ();
22660
e74cfd16 22661 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 22662
f17c130b 22663#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 22664 {
7cc69913
NC
22665 unsigned int flags = 0;
22666
22667#if defined OBJ_ELF
22668 flags = meabi_flags;
d507cf36
PB
22669
22670 switch (meabi_flags)
33a392fb 22671 {
d507cf36 22672 case EF_ARM_EABI_UNKNOWN:
7cc69913 22673#endif
d507cf36
PB
22674 /* Set the flags in the private structure. */
22675 if (uses_apcs_26) flags |= F_APCS26;
22676 if (support_interwork) flags |= F_INTERWORK;
22677 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 22678 if (pic_code) flags |= F_PIC;
e74cfd16 22679 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
22680 flags |= F_SOFT_FLOAT;
22681
d507cf36
PB
22682 switch (mfloat_abi_opt)
22683 {
22684 case ARM_FLOAT_ABI_SOFT:
22685 case ARM_FLOAT_ABI_SOFTFP:
22686 flags |= F_SOFT_FLOAT;
22687 break;
33a392fb 22688
d507cf36
PB
22689 case ARM_FLOAT_ABI_HARD:
22690 if (flags & F_SOFT_FLOAT)
22691 as_bad (_("hard-float conflicts with specified fpu"));
22692 break;
22693 }
03b1477f 22694
e74cfd16
PB
22695 /* Using pure-endian doubles (even if soft-float). */
22696 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 22697 flags |= F_VFP_FLOAT;
f17c130b 22698
fde78edd 22699#if defined OBJ_ELF
e74cfd16 22700 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 22701 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
22702 break;
22703
8cb51566 22704 case EF_ARM_EABI_VER4:
3a4a14e9 22705 case EF_ARM_EABI_VER5:
c19d1205 22706 /* No additional flags to set. */
d507cf36
PB
22707 break;
22708
22709 default:
22710 abort ();
22711 }
7cc69913 22712#endif
b99bd4ef
NC
22713 bfd_set_private_flags (stdoutput, flags);
22714
22715 /* We have run out flags in the COFF header to encode the
22716 status of ATPCS support, so instead we create a dummy,
c19d1205 22717 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
22718 if (atpcs)
22719 {
22720 asection * sec;
22721
22722 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22723
22724 if (sec != NULL)
22725 {
22726 bfd_set_section_flags
22727 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22728 bfd_set_section_size (stdoutput, sec, 0);
22729 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22730 }
22731 }
7cc69913 22732 }
f17c130b 22733#endif
b99bd4ef
NC
22734
22735 /* Record the CPU type as well. */
2d447fca
JM
22736 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22737 mach = bfd_mach_arm_iWMMXt2;
22738 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 22739 mach = bfd_mach_arm_iWMMXt;
e74cfd16 22740 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 22741 mach = bfd_mach_arm_XScale;
e74cfd16 22742 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 22743 mach = bfd_mach_arm_ep9312;
e74cfd16 22744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 22745 mach = bfd_mach_arm_5TE;
e74cfd16 22746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 22747 {
e74cfd16 22748 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22749 mach = bfd_mach_arm_5T;
22750 else
22751 mach = bfd_mach_arm_5;
22752 }
e74cfd16 22753 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 22754 {
e74cfd16 22755 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
22756 mach = bfd_mach_arm_4T;
22757 else
22758 mach = bfd_mach_arm_4;
22759 }
e74cfd16 22760 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 22761 mach = bfd_mach_arm_3M;
e74cfd16
PB
22762 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22763 mach = bfd_mach_arm_3;
22764 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22765 mach = bfd_mach_arm_2a;
22766 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22767 mach = bfd_mach_arm_2;
22768 else
22769 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
22770
22771 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22772}
22773
c19d1205 22774/* Command line processing. */
b99bd4ef 22775
c19d1205
ZW
22776/* md_parse_option
22777 Invocation line includes a switch not recognized by the base assembler.
22778 See if it's a processor-specific option.
b99bd4ef 22779
c19d1205
ZW
22780 This routine is somewhat complicated by the need for backwards
22781 compatibility (since older releases of gcc can't be changed).
22782 The new options try to make the interface as compatible as
22783 possible with GCC.
b99bd4ef 22784
c19d1205 22785 New options (supported) are:
b99bd4ef 22786
c19d1205
ZW
22787 -mcpu=<cpu name> Assemble for selected processor
22788 -march=<architecture name> Assemble for selected architecture
22789 -mfpu=<fpu architecture> Assemble for selected FPU.
22790 -EB/-mbig-endian Big-endian
22791 -EL/-mlittle-endian Little-endian
22792 -k Generate PIC code
22793 -mthumb Start in Thumb mode
22794 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 22795
278df34e 22796 -m[no-]warn-deprecated Warn about deprecated features
267bf995 22797
c19d1205 22798 For now we will also provide support for:
b99bd4ef 22799
c19d1205
ZW
22800 -mapcs-32 32-bit Program counter
22801 -mapcs-26 26-bit Program counter
22802 -macps-float Floats passed in FP registers
22803 -mapcs-reentrant Reentrant code
22804 -matpcs
22805 (sometime these will probably be replaced with -mapcs=<list of options>
22806 and -matpcs=<list of options>)
b99bd4ef 22807
c19d1205
ZW
22808 The remaining options are only supported for back-wards compatibility.
22809 Cpu variants, the arm part is optional:
22810 -m[arm]1 Currently not supported.
22811 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22812 -m[arm]3 Arm 3 processor
22813 -m[arm]6[xx], Arm 6 processors
22814 -m[arm]7[xx][t][[d]m] Arm 7 processors
22815 -m[arm]8[10] Arm 8 processors
22816 -m[arm]9[20][tdmi] Arm 9 processors
22817 -mstrongarm[110[0]] StrongARM processors
22818 -mxscale XScale processors
22819 -m[arm]v[2345[t[e]]] Arm architectures
22820 -mall All (except the ARM1)
22821 FP variants:
22822 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22823 -mfpe-old (No float load/store multiples)
22824 -mvfpxd VFP Single precision
22825 -mvfp All VFP
22826 -mno-fpu Disable all floating point instructions
b99bd4ef 22827
c19d1205
ZW
22828 The following CPU names are recognized:
22829 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22830 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22831 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22832 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22833 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22834 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22835 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 22836
c19d1205 22837 */
b99bd4ef 22838
c19d1205 22839const char * md_shortopts = "m:k";
b99bd4ef 22840
c19d1205
ZW
22841#ifdef ARM_BI_ENDIAN
22842#define OPTION_EB (OPTION_MD_BASE + 0)
22843#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 22844#else
c19d1205
ZW
22845#if TARGET_BYTES_BIG_ENDIAN
22846#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 22847#else
c19d1205
ZW
22848#define OPTION_EL (OPTION_MD_BASE + 1)
22849#endif
b99bd4ef 22850#endif
845b51d6 22851#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 22852
c19d1205 22853struct option md_longopts[] =
b99bd4ef 22854{
c19d1205
ZW
22855#ifdef OPTION_EB
22856 {"EB", no_argument, NULL, OPTION_EB},
22857#endif
22858#ifdef OPTION_EL
22859 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 22860#endif
845b51d6 22861 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
22862 {NULL, no_argument, NULL, 0}
22863};
b99bd4ef 22864
c19d1205 22865size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 22866
c19d1205 22867struct arm_option_table
b99bd4ef 22868{
c19d1205
ZW
22869 char *option; /* Option name to match. */
22870 char *help; /* Help information. */
22871 int *var; /* Variable to change. */
22872 int value; /* What to change it to. */
22873 char *deprecated; /* If non-null, print this message. */
22874};
b99bd4ef 22875
c19d1205
ZW
22876struct arm_option_table arm_opts[] =
22877{
22878 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22879 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22880 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22881 &support_interwork, 1, NULL},
22882 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22883 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22884 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22885 1, NULL},
22886 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22887 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22888 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22889 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22890 NULL},
b99bd4ef 22891
c19d1205
ZW
22892 /* These are recognized by the assembler, but have no affect on code. */
22893 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22894 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
22895
22896 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22897 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22898 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
22899 {NULL, NULL, NULL, 0, NULL}
22900};
22901
22902struct arm_legacy_option_table
22903{
22904 char *option; /* Option name to match. */
22905 const arm_feature_set **var; /* Variable to change. */
22906 const arm_feature_set value; /* What to change it to. */
22907 char *deprecated; /* If non-null, print this message. */
22908};
b99bd4ef 22909
e74cfd16
PB
22910const struct arm_legacy_option_table arm_legacy_opts[] =
22911{
c19d1205
ZW
22912 /* DON'T add any new processors to this list -- we want the whole list
22913 to go away... Add them to the processors table instead. */
e74cfd16
PB
22914 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22915 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22916 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22917 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22918 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22919 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22920 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22921 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22922 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22923 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22924 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22925 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22926 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22927 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22928 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22929 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22930 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22931 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22932 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22933 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22934 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22935 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22936 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22937 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22938 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22939 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22940 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22941 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22942 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22943 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22944 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22945 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22946 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22947 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22948 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22949 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22950 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22951 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22952 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22953 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22954 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22955 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22956 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22957 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22958 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22959 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22960 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22961 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22962 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22963 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22964 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22965 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22966 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22967 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22968 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22969 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22970 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22971 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22972 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22973 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22974 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22975 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22976 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22977 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22978 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22979 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22980 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22981 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22982 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22983 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22984 N_("use -mcpu=strongarm110")},
e74cfd16 22985 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22986 N_("use -mcpu=strongarm1100")},
e74cfd16 22987 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22988 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22989 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22990 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22991 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22992
c19d1205 22993 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22994 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22995 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22996 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22997 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22998 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22999 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23000 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23001 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23002 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23003 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23004 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23005 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23006 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23007 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23008 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23009 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23010 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23011 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 23012
c19d1205 23013 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
23014 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
23015 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
23016 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
23017 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 23018 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 23019
e74cfd16 23020 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 23021};
7ed4c4c5 23022
c19d1205 23023struct arm_cpu_option_table
7ed4c4c5 23024{
c19d1205 23025 char *name;
f3bad469 23026 size_t name_len;
e74cfd16 23027 const arm_feature_set value;
c19d1205
ZW
23028 /* For some CPUs we assume an FPU unless the user explicitly sets
23029 -mfpu=... */
e74cfd16 23030 const arm_feature_set default_fpu;
ee065d83
PB
23031 /* The canonical name of the CPU, or NULL to use NAME converted to upper
23032 case. */
23033 const char *canonical_name;
c19d1205 23034};
7ed4c4c5 23035
c19d1205
ZW
23036/* This list should, at a minimum, contain all the cpu names
23037 recognized by GCC. */
f3bad469 23038#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 23039static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 23040{
f3bad469
MGD
23041 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23042 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23043 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23044 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23045 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23046 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23047 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23048 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23049 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23050 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23051 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23052 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23053 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23054 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23055 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23056 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23057 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23058 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23059 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23060 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23061 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23062 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23063 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23064 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23065 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23066 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23067 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23068 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23069 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23070 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23071 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23072 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23073 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23074 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23075 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23076 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23077 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23078 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23079 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23080 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23081 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23082 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23083 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23084 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23085 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23086 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
23087 /* For V5 or later processors we default to using VFP; but the user
23088 should really set the FPU type explicitly. */
f3bad469
MGD
23089 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23090 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23091 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23092 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23093 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23094 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23095 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23096 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23097 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23098 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23099 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23100 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23101 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23102 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23103 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23104 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23105 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23106 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23107 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23108 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23109 "ARM1026EJ-S"),
23110 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23111 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23112 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23113 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23114 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23115 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23116 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23117 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23118 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23119 "ARM1136JF-S"),
23120 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23121 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23122 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23123 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23124 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23125 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23126 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23127 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23128 FPU_NONE, "Cortex-A5"),
23129 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23130 FPU_ARCH_NEON_VFP_V4,
23131 "Cortex-A7"),
23132 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23133 ARM_FEATURE (0, FPU_VFP_V3
5287ad62 23134 | FPU_NEON_EXT_V1),
f3bad469
MGD
23135 "Cortex-A8"),
23136 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23137 ARM_FEATURE (0, FPU_VFP_V3
15290f0a 23138 | FPU_NEON_EXT_V1),
f3bad469
MGD
23139 "Cortex-A9"),
23140 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23141 FPU_ARCH_NEON_VFP_V4,
23142 "Cortex-A15"),
23143 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23144 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23145 "Cortex-R4F"),
23146 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23147 FPU_NONE, "Cortex-R5"),
23148 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23149 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23150 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23151 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 23152 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
c19d1205 23153 /* ??? XSCALE is really an architecture. */
f3bad469 23154 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23155 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
23156 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23157 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23158 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 23159 /* Maverick */
f3bad469
MGD
23160 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23161 FPU_ARCH_MAVERICK,
23162 "ARM920T"),
23163 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 23164};
f3bad469 23165#undef ARM_CPU_OPT
7ed4c4c5 23166
c19d1205 23167struct arm_arch_option_table
7ed4c4c5 23168{
c19d1205 23169 char *name;
f3bad469 23170 size_t name_len;
e74cfd16
PB
23171 const arm_feature_set value;
23172 const arm_feature_set default_fpu;
c19d1205 23173};
7ed4c4c5 23174
c19d1205
ZW
23175/* This list should, at a minimum, contain all the architecture names
23176 recognized by GCC. */
f3bad469 23177#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 23178static const struct arm_arch_option_table arm_archs[] =
c19d1205 23179{
f3bad469
MGD
23180 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23181 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23182 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23183 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23184 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23185 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23186 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23187 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23188 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23189 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23190 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23191 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23192 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23193 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23194 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23195 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23196 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23197 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23198 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23199 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23200 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23201 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23202 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23203 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23204 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23205 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23206 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23207 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23208 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
23209 /* The official spelling of the ARMv7 profile variants is the dashed form.
23210 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469
MGD
23211 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23212 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23213 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23214 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23215 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23216 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23217 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 23218 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
f3bad469
MGD
23219 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23220 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23221 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23222 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 23223};
f3bad469 23224#undef ARM_ARCH_OPT
7ed4c4c5 23225
69133863
MGD
23226/* ISA extensions in the co-processor and main instruction set space. */
23227struct arm_option_extension_value_table
c19d1205
ZW
23228{
23229 char *name;
f3bad469 23230 size_t name_len;
e74cfd16 23231 const arm_feature_set value;
69133863 23232 const arm_feature_set allowed_archs;
c19d1205 23233};
7ed4c4c5 23234
69133863
MGD
23235/* The following table must be in alphabetical order with a NULL last entry.
23236 */
f3bad469 23237#define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
69133863 23238static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 23239{
bca38921
MGD
23240 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
23241 ARM_FEATURE (ARM_EXT_V8, 0)),
23242 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
23243 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
23244 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23245 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23246 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23247 ARM_EXT_OPT ("iwmmxt2",
23248 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23249 ARM_EXT_OPT ("maverick",
23250 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23251 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23252 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
bca38921
MGD
23253 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
23254 ARM_FEATURE (ARM_EXT_V8, 0)),
f3bad469
MGD
23255 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
23256 ARM_FEATURE (ARM_EXT_V6M, 0)),
23257 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23258 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
23259 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
23260 | ARM_EXT_DIV, 0),
23261 ARM_FEATURE (ARM_EXT_V7A, 0)),
23262 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
23263 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 23264};
f3bad469 23265#undef ARM_EXT_OPT
69133863
MGD
23266
23267/* ISA floating-point and Advanced SIMD extensions. */
23268struct arm_option_fpu_value_table
23269{
23270 char *name;
23271 const arm_feature_set value;
c19d1205 23272};
7ed4c4c5 23273
c19d1205
ZW
23274/* This list should, at a minimum, contain all the fpu names
23275 recognized by GCC. */
69133863 23276static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
23277{
23278 {"softfpa", FPU_NONE},
23279 {"fpe", FPU_ARCH_FPE},
23280 {"fpe2", FPU_ARCH_FPE},
23281 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23282 {"fpa", FPU_ARCH_FPA},
23283 {"fpa10", FPU_ARCH_FPA},
23284 {"fpa11", FPU_ARCH_FPA},
23285 {"arm7500fe", FPU_ARCH_FPA},
23286 {"softvfp", FPU_ARCH_VFP},
23287 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23288 {"vfp", FPU_ARCH_VFP_V2},
23289 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 23290 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
23291 {"vfp10", FPU_ARCH_VFP_V2},
23292 {"vfp10-r0", FPU_ARCH_VFP_V1},
23293 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
23294 {"vfpv2", FPU_ARCH_VFP_V2},
23295 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 23296 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 23297 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
23298 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23299 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23300 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
23301 {"arm1020t", FPU_ARCH_VFP_V1},
23302 {"arm1020e", FPU_ARCH_VFP_V2},
23303 {"arm1136jfs", FPU_ARCH_VFP_V2},
23304 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23305 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 23306 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 23307 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
23308 {"vfpv4", FPU_ARCH_VFP_V4},
23309 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 23310 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 23311 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
23312 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
23313 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
23314 {"crypto-neon-fp-armv8",
23315 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
e74cfd16
PB
23316 {NULL, ARM_ARCH_NONE}
23317};
23318
23319struct arm_option_value_table
23320{
23321 char *name;
23322 long value;
c19d1205 23323};
7ed4c4c5 23324
e74cfd16 23325static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
23326{
23327 {"hard", ARM_FLOAT_ABI_HARD},
23328 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23329 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 23330 {NULL, 0}
c19d1205 23331};
7ed4c4c5 23332
c19d1205 23333#ifdef OBJ_ELF
3a4a14e9 23334/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 23335static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
23336{
23337 {"gnu", EF_ARM_EABI_UNKNOWN},
23338 {"4", EF_ARM_EABI_VER4},
3a4a14e9 23339 {"5", EF_ARM_EABI_VER5},
e74cfd16 23340 {NULL, 0}
c19d1205
ZW
23341};
23342#endif
7ed4c4c5 23343
c19d1205
ZW
23344struct arm_long_option_table
23345{
23346 char * option; /* Substring to match. */
23347 char * help; /* Help information. */
23348 int (* func) (char * subopt); /* Function to decode sub-option. */
23349 char * deprecated; /* If non-null, print this message. */
23350};
7ed4c4c5 23351
c921be7d 23352static bfd_boolean
f3bad469 23353arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 23354{
21d799b5
NC
23355 arm_feature_set *ext_set = (arm_feature_set *)
23356 xmalloc (sizeof (arm_feature_set));
e74cfd16 23357
69133863 23358 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
23359 extensions being added before being removed. We achieve this by having
23360 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 23361 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 23362 or removing it (0) and only allowing it to change in the order
69133863
MGD
23363 -1 -> 1 -> 0. */
23364 const struct arm_option_extension_value_table * opt = NULL;
23365 int adding_value = -1;
23366
e74cfd16
PB
23367 /* Copy the feature set, so that we can modify it. */
23368 *ext_set = **opt_p;
23369 *opt_p = ext_set;
23370
c19d1205 23371 while (str != NULL && *str != 0)
7ed4c4c5 23372 {
f3bad469
MGD
23373 char *ext;
23374 size_t len;
7ed4c4c5 23375
c19d1205
ZW
23376 if (*str != '+')
23377 {
23378 as_bad (_("invalid architectural extension"));
c921be7d 23379 return FALSE;
c19d1205 23380 }
7ed4c4c5 23381
c19d1205
ZW
23382 str++;
23383 ext = strchr (str, '+');
7ed4c4c5 23384
c19d1205 23385 if (ext != NULL)
f3bad469 23386 len = ext - str;
c19d1205 23387 else
f3bad469 23388 len = strlen (str);
7ed4c4c5 23389
f3bad469 23390 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
23391 {
23392 if (adding_value != 0)
23393 {
23394 adding_value = 0;
23395 opt = arm_extensions;
23396 }
23397
f3bad469 23398 len -= 2;
69133863
MGD
23399 str += 2;
23400 }
f3bad469 23401 else if (len > 0)
69133863
MGD
23402 {
23403 if (adding_value == -1)
23404 {
23405 adding_value = 1;
23406 opt = arm_extensions;
23407 }
23408 else if (adding_value != 1)
23409 {
23410 as_bad (_("must specify extensions to add before specifying "
23411 "those to remove"));
23412 return FALSE;
23413 }
23414 }
23415
f3bad469 23416 if (len == 0)
c19d1205
ZW
23417 {
23418 as_bad (_("missing architectural extension"));
c921be7d 23419 return FALSE;
c19d1205 23420 }
7ed4c4c5 23421
69133863
MGD
23422 gas_assert (adding_value != -1);
23423 gas_assert (opt != NULL);
23424
23425 /* Scan over the options table trying to find an exact match. */
23426 for (; opt->name != NULL; opt++)
f3bad469 23427 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23428 {
69133863
MGD
23429 /* Check we can apply the extension to this architecture. */
23430 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23431 {
23432 as_bad (_("extension does not apply to the base architecture"));
23433 return FALSE;
23434 }
23435
23436 /* Add or remove the extension. */
23437 if (adding_value)
23438 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23439 else
23440 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23441
c19d1205
ZW
23442 break;
23443 }
7ed4c4c5 23444
c19d1205
ZW
23445 if (opt->name == NULL)
23446 {
69133863
MGD
23447 /* Did we fail to find an extension because it wasn't specified in
23448 alphabetical order, or because it does not exist? */
23449
23450 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 23451 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
23452 break;
23453
23454 if (opt->name == NULL)
23455 as_bad (_("unknown architectural extension `%s'"), str);
23456 else
23457 as_bad (_("architectural extensions must be specified in "
23458 "alphabetical order"));
23459
c921be7d 23460 return FALSE;
c19d1205 23461 }
69133863
MGD
23462 else
23463 {
23464 /* We should skip the extension we've just matched the next time
23465 round. */
23466 opt++;
23467 }
7ed4c4c5 23468
c19d1205
ZW
23469 str = ext;
23470 };
7ed4c4c5 23471
c921be7d 23472 return TRUE;
c19d1205 23473}
7ed4c4c5 23474
c921be7d 23475static bfd_boolean
f3bad469 23476arm_parse_cpu (char *str)
7ed4c4c5 23477{
f3bad469
MGD
23478 const struct arm_cpu_option_table *opt;
23479 char *ext = strchr (str, '+');
23480 size_t len;
7ed4c4c5 23481
c19d1205 23482 if (ext != NULL)
f3bad469 23483 len = ext - str;
7ed4c4c5 23484 else
f3bad469 23485 len = strlen (str);
7ed4c4c5 23486
f3bad469 23487 if (len == 0)
7ed4c4c5 23488 {
c19d1205 23489 as_bad (_("missing cpu name `%s'"), str);
c921be7d 23490 return FALSE;
7ed4c4c5
NC
23491 }
23492
c19d1205 23493 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 23494 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23495 {
e74cfd16
PB
23496 mcpu_cpu_opt = &opt->value;
23497 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 23498 if (opt->canonical_name)
5f4273c7 23499 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
23500 else
23501 {
f3bad469 23502 size_t i;
c921be7d 23503
f3bad469 23504 for (i = 0; i < len; i++)
ee065d83
PB
23505 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23506 selected_cpu_name[i] = 0;
23507 }
7ed4c4c5 23508
c19d1205
ZW
23509 if (ext != NULL)
23510 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 23511
c921be7d 23512 return TRUE;
c19d1205 23513 }
7ed4c4c5 23514
c19d1205 23515 as_bad (_("unknown cpu `%s'"), str);
c921be7d 23516 return FALSE;
7ed4c4c5
NC
23517}
23518
c921be7d 23519static bfd_boolean
f3bad469 23520arm_parse_arch (char *str)
7ed4c4c5 23521{
e74cfd16 23522 const struct arm_arch_option_table *opt;
c19d1205 23523 char *ext = strchr (str, '+');
f3bad469 23524 size_t len;
7ed4c4c5 23525
c19d1205 23526 if (ext != NULL)
f3bad469 23527 len = ext - str;
7ed4c4c5 23528 else
f3bad469 23529 len = strlen (str);
7ed4c4c5 23530
f3bad469 23531 if (len == 0)
7ed4c4c5 23532 {
c19d1205 23533 as_bad (_("missing architecture name `%s'"), str);
c921be7d 23534 return FALSE;
7ed4c4c5
NC
23535 }
23536
c19d1205 23537 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 23538 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 23539 {
e74cfd16
PB
23540 march_cpu_opt = &opt->value;
23541 march_fpu_opt = &opt->default_fpu;
5f4273c7 23542 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 23543
c19d1205
ZW
23544 if (ext != NULL)
23545 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 23546
c921be7d 23547 return TRUE;
c19d1205
ZW
23548 }
23549
23550 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 23551 return FALSE;
7ed4c4c5 23552}
eb043451 23553
c921be7d 23554static bfd_boolean
c19d1205
ZW
23555arm_parse_fpu (char * str)
23556{
69133863 23557 const struct arm_option_fpu_value_table * opt;
b99bd4ef 23558
c19d1205
ZW
23559 for (opt = arm_fpus; opt->name != NULL; opt++)
23560 if (streq (opt->name, str))
23561 {
e74cfd16 23562 mfpu_opt = &opt->value;
c921be7d 23563 return TRUE;
c19d1205 23564 }
b99bd4ef 23565
c19d1205 23566 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 23567 return FALSE;
c19d1205
ZW
23568}
23569
c921be7d 23570static bfd_boolean
c19d1205 23571arm_parse_float_abi (char * str)
b99bd4ef 23572{
e74cfd16 23573 const struct arm_option_value_table * opt;
b99bd4ef 23574
c19d1205
ZW
23575 for (opt = arm_float_abis; opt->name != NULL; opt++)
23576 if (streq (opt->name, str))
23577 {
23578 mfloat_abi_opt = opt->value;
c921be7d 23579 return TRUE;
c19d1205 23580 }
cc8a6dd0 23581
c19d1205 23582 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 23583 return FALSE;
c19d1205 23584}
b99bd4ef 23585
c19d1205 23586#ifdef OBJ_ELF
c921be7d 23587static bfd_boolean
c19d1205
ZW
23588arm_parse_eabi (char * str)
23589{
e74cfd16 23590 const struct arm_option_value_table *opt;
cc8a6dd0 23591
c19d1205
ZW
23592 for (opt = arm_eabis; opt->name != NULL; opt++)
23593 if (streq (opt->name, str))
23594 {
23595 meabi_flags = opt->value;
c921be7d 23596 return TRUE;
c19d1205
ZW
23597 }
23598 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 23599 return FALSE;
c19d1205
ZW
23600}
23601#endif
cc8a6dd0 23602
c921be7d 23603static bfd_boolean
e07e6e58
NC
23604arm_parse_it_mode (char * str)
23605{
c921be7d 23606 bfd_boolean ret = TRUE;
e07e6e58
NC
23607
23608 if (streq ("arm", str))
23609 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23610 else if (streq ("thumb", str))
23611 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23612 else if (streq ("always", str))
23613 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23614 else if (streq ("never", str))
23615 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23616 else
23617 {
23618 as_bad (_("unknown implicit IT mode `%s', should be "\
23619 "arm, thumb, always, or never."), str);
c921be7d 23620 ret = FALSE;
e07e6e58
NC
23621 }
23622
23623 return ret;
23624}
23625
c19d1205
ZW
23626struct arm_long_option_table arm_long_opts[] =
23627{
23628 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23629 arm_parse_cpu, NULL},
23630 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23631 arm_parse_arch, NULL},
23632 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23633 arm_parse_fpu, NULL},
23634 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23635 arm_parse_float_abi, NULL},
23636#ifdef OBJ_ELF
7fac0536 23637 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
23638 arm_parse_eabi, NULL},
23639#endif
e07e6e58
NC
23640 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23641 arm_parse_it_mode, NULL},
c19d1205
ZW
23642 {NULL, NULL, 0, NULL}
23643};
cc8a6dd0 23644
c19d1205
ZW
23645int
23646md_parse_option (int c, char * arg)
23647{
23648 struct arm_option_table *opt;
e74cfd16 23649 const struct arm_legacy_option_table *fopt;
c19d1205 23650 struct arm_long_option_table *lopt;
b99bd4ef 23651
c19d1205 23652 switch (c)
b99bd4ef 23653 {
c19d1205
ZW
23654#ifdef OPTION_EB
23655 case OPTION_EB:
23656 target_big_endian = 1;
23657 break;
23658#endif
cc8a6dd0 23659
c19d1205
ZW
23660#ifdef OPTION_EL
23661 case OPTION_EL:
23662 target_big_endian = 0;
23663 break;
23664#endif
b99bd4ef 23665
845b51d6
PB
23666 case OPTION_FIX_V4BX:
23667 fix_v4bx = TRUE;
23668 break;
23669
c19d1205
ZW
23670 case 'a':
23671 /* Listing option. Just ignore these, we don't support additional
23672 ones. */
23673 return 0;
b99bd4ef 23674
c19d1205
ZW
23675 default:
23676 for (opt = arm_opts; opt->option != NULL; opt++)
23677 {
23678 if (c == opt->option[0]
23679 && ((arg == NULL && opt->option[1] == 0)
23680 || streq (arg, opt->option + 1)))
23681 {
c19d1205 23682 /* If the option is deprecated, tell the user. */
278df34e 23683 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
23684 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23685 arg ? arg : "", _(opt->deprecated));
b99bd4ef 23686
c19d1205
ZW
23687 if (opt->var != NULL)
23688 *opt->var = opt->value;
cc8a6dd0 23689
c19d1205
ZW
23690 return 1;
23691 }
23692 }
b99bd4ef 23693
e74cfd16
PB
23694 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23695 {
23696 if (c == fopt->option[0]
23697 && ((arg == NULL && fopt->option[1] == 0)
23698 || streq (arg, fopt->option + 1)))
23699 {
e74cfd16 23700 /* If the option is deprecated, tell the user. */
278df34e 23701 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
23702 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23703 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
23704
23705 if (fopt->var != NULL)
23706 *fopt->var = &fopt->value;
23707
23708 return 1;
23709 }
23710 }
23711
c19d1205
ZW
23712 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23713 {
23714 /* These options are expected to have an argument. */
23715 if (c == lopt->option[0]
23716 && arg != NULL
23717 && strncmp (arg, lopt->option + 1,
23718 strlen (lopt->option + 1)) == 0)
23719 {
c19d1205 23720 /* If the option is deprecated, tell the user. */
278df34e 23721 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
23722 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23723 _(lopt->deprecated));
b99bd4ef 23724
c19d1205
ZW
23725 /* Call the sup-option parser. */
23726 return lopt->func (arg + strlen (lopt->option) - 1);
23727 }
23728 }
a737bd4d 23729
c19d1205
ZW
23730 return 0;
23731 }
a394c00f 23732
c19d1205
ZW
23733 return 1;
23734}
a394c00f 23735
c19d1205
ZW
23736void
23737md_show_usage (FILE * fp)
a394c00f 23738{
c19d1205
ZW
23739 struct arm_option_table *opt;
23740 struct arm_long_option_table *lopt;
a394c00f 23741
c19d1205 23742 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 23743
c19d1205
ZW
23744 for (opt = arm_opts; opt->option != NULL; opt++)
23745 if (opt->help != NULL)
23746 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 23747
c19d1205
ZW
23748 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23749 if (lopt->help != NULL)
23750 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 23751
c19d1205
ZW
23752#ifdef OPTION_EB
23753 fprintf (fp, _("\
23754 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
23755#endif
23756
c19d1205
ZW
23757#ifdef OPTION_EL
23758 fprintf (fp, _("\
23759 -EL assemble code for a little-endian cpu\n"));
a737bd4d 23760#endif
845b51d6
PB
23761
23762 fprintf (fp, _("\
23763 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 23764}
ee065d83
PB
23765
23766
23767#ifdef OBJ_ELF
62b3e311
PB
23768typedef struct
23769{
23770 int val;
23771 arm_feature_set flags;
23772} cpu_arch_ver_table;
23773
23774/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23775 least features first. */
23776static const cpu_arch_ver_table cpu_arch_ver[] =
23777{
23778 {1, ARM_ARCH_V4},
23779 {2, ARM_ARCH_V4T},
23780 {3, ARM_ARCH_V5},
ee3c0378 23781 {3, ARM_ARCH_V5T},
62b3e311
PB
23782 {4, ARM_ARCH_V5TE},
23783 {5, ARM_ARCH_V5TEJ},
23784 {6, ARM_ARCH_V6},
7e806470 23785 {9, ARM_ARCH_V6K},
f4c65163 23786 {7, ARM_ARCH_V6Z},
91e22acd 23787 {11, ARM_ARCH_V6M},
b2a5fbdc 23788 {12, ARM_ARCH_V6SM},
7e806470 23789 {8, ARM_ARCH_V6T2},
bca38921 23790 {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT},
62b3e311
PB
23791 {10, ARM_ARCH_V7R},
23792 {10, ARM_ARCH_V7M},
bca38921 23793 {14, ARM_ARCH_V8A},
62b3e311
PB
23794 {0, ARM_ARCH_NONE}
23795};
23796
ee3c0378
AS
23797/* Set an attribute if it has not already been set by the user. */
23798static void
23799aeabi_set_attribute_int (int tag, int value)
23800{
23801 if (tag < 1
23802 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23803 || !attributes_set_explicitly[tag])
23804 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23805}
23806
23807static void
23808aeabi_set_attribute_string (int tag, const char *value)
23809{
23810 if (tag < 1
23811 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23812 || !attributes_set_explicitly[tag])
23813 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23814}
23815
ee065d83
PB
23816/* Set the public EABI object attributes. */
23817static void
23818aeabi_set_public_attributes (void)
23819{
23820 int arch;
69239280 23821 char profile;
90ec0d68 23822 int virt_sec = 0;
bca38921 23823 int fp16_optional = 0;
e74cfd16 23824 arm_feature_set flags;
62b3e311
PB
23825 arm_feature_set tmp;
23826 const cpu_arch_ver_table *p;
ee065d83
PB
23827
23828 /* Choose the architecture based on the capabilities of the requested cpu
23829 (if any) and/or the instructions actually used. */
e74cfd16
PB
23830 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23831 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23832 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
23833
23834 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
23835 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
23836
23837 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
23838 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
23839
23840 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
23841 if (object_arch)
23842 {
23843 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23844 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23845 }
23846
251665fc
MGD
23847 /* We need to make sure that the attributes do not identify us as v6S-M
23848 when the only v6S-M feature in use is the Operating System Extensions. */
23849 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23850 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23851 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23852
62b3e311
PB
23853 tmp = flags;
23854 arch = 0;
23855 for (p = cpu_arch_ver; p->val; p++)
23856 {
23857 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23858 {
23859 arch = p->val;
23860 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23861 }
23862 }
ee065d83 23863
9e3c6df6
PB
23864 /* The table lookup above finds the last architecture to contribute
23865 a new feature. Unfortunately, Tag13 is a subset of the union of
23866 v6T2 and v7-M, so it is never seen as contributing a new feature.
23867 We can not search for the last entry which is entirely used,
23868 because if no CPU is specified we build up only those flags
23869 actually used. Perhaps we should separate out the specified
23870 and implicit cases. Avoid taking this path for -march=all by
23871 checking for contradictory v7-A / v7-M features. */
23872 if (arch == 10
23873 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23874 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23875 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23876 arch = 13;
23877
ee065d83
PB
23878 /* Tag_CPU_name. */
23879 if (selected_cpu_name[0])
23880 {
91d6fa6a 23881 char *q;
ee065d83 23882
91d6fa6a
NC
23883 q = selected_cpu_name;
23884 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
23885 {
23886 int i;
5f4273c7 23887
91d6fa6a
NC
23888 q += 4;
23889 for (i = 0; q[i]; i++)
23890 q[i] = TOUPPER (q[i]);
ee065d83 23891 }
91d6fa6a 23892 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 23893 }
62f3b8c8 23894
ee065d83 23895 /* Tag_CPU_arch. */
ee3c0378 23896 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 23897
62b3e311
PB
23898 /* Tag_CPU_arch_profile. */
23899 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 23900 profile = 'A';
62b3e311 23901 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 23902 profile = 'R';
7e806470 23903 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
23904 profile = 'M';
23905 else
23906 profile = '\0';
23907
23908 if (profile != '\0')
23909 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 23910
ee065d83 23911 /* Tag_ARM_ISA_use. */
ee3c0378
AS
23912 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23913 || arch == 0)
23914 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 23915
ee065d83 23916 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
23917 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23918 || arch == 0)
23919 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23920 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 23921
ee065d83 23922 /* Tag_VFP_arch. */
bca38921
MGD
23923 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
23924 aeabi_set_attribute_int (Tag_VFP_arch, 7);
23925 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
23926 aeabi_set_attribute_int (Tag_VFP_arch,
23927 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23928 ? 5 : 6);
23929 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
23930 {
23931 fp16_optional = 1;
23932 aeabi_set_attribute_int (Tag_VFP_arch, 3);
23933 }
ada65aa3 23934 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
23935 {
23936 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23937 fp16_optional = 1;
23938 }
ee3c0378
AS
23939 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23940 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23941 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23942 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23943 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 23944
4547cb56
NC
23945 /* Tag_ABI_HardFP_use. */
23946 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23947 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23948 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23949
ee065d83 23950 /* Tag_WMMX_arch. */
ee3c0378
AS
23951 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23952 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23953 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23954 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 23955
ee3c0378 23956 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
23957 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
23958 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
23959 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
23960 {
23961 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
23962 {
23963 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
23964 }
23965 else
23966 {
23967 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
23968 fp16_optional = 1;
23969 }
23970 }
fa94de6b 23971
ee3c0378 23972 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 23973 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 23974 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 23975
69239280
MGD
23976 /* Tag_DIV_use.
23977
23978 We set Tag_DIV_use to two when integer divide instructions have been used
23979 in ARM state, or when Thumb integer divide instructions have been used,
23980 but we have no architecture profile set, nor have we any ARM instructions.
23981
bca38921
MGD
23982 For ARMv8 we set the tag to 0 as integer divide is implied by the base
23983 architecture.
23984
69239280 23985 For new architectures we will have to check these tests. */
bca38921
MGD
23986 gas_assert (arch <= TAG_CPU_ARCH_V8);
23987 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
23988 aeabi_set_attribute_int (Tag_DIV_use, 0);
23989 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
23990 || (profile == '\0'
23991 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
23992 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 23993 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
23994
23995 /* Tag_MP_extension_use. */
23996 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23997 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
23998
23999 /* Tag Virtualization_use. */
24000 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
24001 virt_sec |= 1;
24002 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
24003 virt_sec |= 2;
24004 if (virt_sec != 0)
24005 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
24006}
24007
104d59d1 24008/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
24009void
24010arm_md_end (void)
24011{
ee065d83
PB
24012 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24013 return;
24014
24015 aeabi_set_public_attributes ();
ee065d83 24016}
8463be01 24017#endif /* OBJ_ELF */
ee065d83
PB
24018
24019
24020/* Parse a .cpu directive. */
24021
24022static void
24023s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
24024{
e74cfd16 24025 const struct arm_cpu_option_table *opt;
ee065d83
PB
24026 char *name;
24027 char saved_char;
24028
24029 name = input_line_pointer;
5f4273c7 24030 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24031 input_line_pointer++;
24032 saved_char = *input_line_pointer;
24033 *input_line_pointer = 0;
24034
24035 /* Skip the first "all" entry. */
24036 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
24037 if (streq (opt->name, name))
24038 {
e74cfd16
PB
24039 mcpu_cpu_opt = &opt->value;
24040 selected_cpu = opt->value;
ee065d83 24041 if (opt->canonical_name)
5f4273c7 24042 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
24043 else
24044 {
24045 int i;
24046 for (i = 0; opt->name[i]; i++)
24047 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 24048
ee065d83
PB
24049 selected_cpu_name[i] = 0;
24050 }
e74cfd16 24051 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24052 *input_line_pointer = saved_char;
24053 demand_empty_rest_of_line ();
24054 return;
24055 }
24056 as_bad (_("unknown cpu `%s'"), name);
24057 *input_line_pointer = saved_char;
24058 ignore_rest_of_line ();
24059}
24060
24061
24062/* Parse a .arch directive. */
24063
24064static void
24065s_arm_arch (int ignored ATTRIBUTE_UNUSED)
24066{
e74cfd16 24067 const struct arm_arch_option_table *opt;
ee065d83
PB
24068 char saved_char;
24069 char *name;
24070
24071 name = input_line_pointer;
5f4273c7 24072 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24073 input_line_pointer++;
24074 saved_char = *input_line_pointer;
24075 *input_line_pointer = 0;
24076
24077 /* Skip the first "all" entry. */
24078 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24079 if (streq (opt->name, name))
24080 {
e74cfd16
PB
24081 mcpu_cpu_opt = &opt->value;
24082 selected_cpu = opt->value;
5f4273c7 24083 strcpy (selected_cpu_name, opt->name);
e74cfd16 24084 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24085 *input_line_pointer = saved_char;
24086 demand_empty_rest_of_line ();
24087 return;
24088 }
24089
24090 as_bad (_("unknown architecture `%s'\n"), name);
24091 *input_line_pointer = saved_char;
24092 ignore_rest_of_line ();
24093}
24094
24095
7a1d4c38
PB
24096/* Parse a .object_arch directive. */
24097
24098static void
24099s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24100{
24101 const struct arm_arch_option_table *opt;
24102 char saved_char;
24103 char *name;
24104
24105 name = input_line_pointer;
5f4273c7 24106 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
24107 input_line_pointer++;
24108 saved_char = *input_line_pointer;
24109 *input_line_pointer = 0;
24110
24111 /* Skip the first "all" entry. */
24112 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24113 if (streq (opt->name, name))
24114 {
24115 object_arch = &opt->value;
24116 *input_line_pointer = saved_char;
24117 demand_empty_rest_of_line ();
24118 return;
24119 }
24120
24121 as_bad (_("unknown architecture `%s'\n"), name);
24122 *input_line_pointer = saved_char;
24123 ignore_rest_of_line ();
24124}
24125
69133863
MGD
24126/* Parse a .arch_extension directive. */
24127
24128static void
24129s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24130{
24131 const struct arm_option_extension_value_table *opt;
24132 char saved_char;
24133 char *name;
24134 int adding_value = 1;
24135
24136 name = input_line_pointer;
24137 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24138 input_line_pointer++;
24139 saved_char = *input_line_pointer;
24140 *input_line_pointer = 0;
24141
24142 if (strlen (name) >= 2
24143 && strncmp (name, "no", 2) == 0)
24144 {
24145 adding_value = 0;
24146 name += 2;
24147 }
24148
24149 for (opt = arm_extensions; opt->name != NULL; opt++)
24150 if (streq (opt->name, name))
24151 {
24152 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24153 {
24154 as_bad (_("architectural extension `%s' is not allowed for the "
24155 "current base architecture"), name);
24156 break;
24157 }
24158
24159 if (adding_value)
24160 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24161 else
24162 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24163
24164 mcpu_cpu_opt = &selected_cpu;
24165 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24166 *input_line_pointer = saved_char;
24167 demand_empty_rest_of_line ();
24168 return;
24169 }
24170
24171 if (opt->name == NULL)
24172 as_bad (_("unknown architecture `%s'\n"), name);
24173
24174 *input_line_pointer = saved_char;
24175 ignore_rest_of_line ();
24176}
24177
ee065d83
PB
24178/* Parse a .fpu directive. */
24179
24180static void
24181s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24182{
69133863 24183 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
24184 char saved_char;
24185 char *name;
24186
24187 name = input_line_pointer;
5f4273c7 24188 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
24189 input_line_pointer++;
24190 saved_char = *input_line_pointer;
24191 *input_line_pointer = 0;
5f4273c7 24192
ee065d83
PB
24193 for (opt = arm_fpus; opt->name != NULL; opt++)
24194 if (streq (opt->name, name))
24195 {
e74cfd16
PB
24196 mfpu_opt = &opt->value;
24197 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
24198 *input_line_pointer = saved_char;
24199 demand_empty_rest_of_line ();
24200 return;
24201 }
24202
24203 as_bad (_("unknown floating point format `%s'\n"), name);
24204 *input_line_pointer = saved_char;
24205 ignore_rest_of_line ();
24206}
ee065d83 24207
794ba86a 24208/* Copy symbol information. */
f31fef98 24209
794ba86a
DJ
24210void
24211arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24212{
24213 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24214}
e04befd0 24215
f31fef98 24216#ifdef OBJ_ELF
e04befd0
AS
24217/* Given a symbolic attribute NAME, return the proper integer value.
24218 Returns -1 if the attribute is not known. */
f31fef98 24219
e04befd0
AS
24220int
24221arm_convert_symbolic_attribute (const char *name)
24222{
f31fef98
NC
24223 static const struct
24224 {
24225 const char * name;
24226 const int tag;
24227 }
24228 attribute_table[] =
24229 {
24230 /* When you modify this table you should
24231 also modify the list in doc/c-arm.texi. */
e04befd0 24232#define T(tag) {#tag, tag}
f31fef98
NC
24233 T (Tag_CPU_raw_name),
24234 T (Tag_CPU_name),
24235 T (Tag_CPU_arch),
24236 T (Tag_CPU_arch_profile),
24237 T (Tag_ARM_ISA_use),
24238 T (Tag_THUMB_ISA_use),
75375b3e 24239 T (Tag_FP_arch),
f31fef98
NC
24240 T (Tag_VFP_arch),
24241 T (Tag_WMMX_arch),
24242 T (Tag_Advanced_SIMD_arch),
24243 T (Tag_PCS_config),
24244 T (Tag_ABI_PCS_R9_use),
24245 T (Tag_ABI_PCS_RW_data),
24246 T (Tag_ABI_PCS_RO_data),
24247 T (Tag_ABI_PCS_GOT_use),
24248 T (Tag_ABI_PCS_wchar_t),
24249 T (Tag_ABI_FP_rounding),
24250 T (Tag_ABI_FP_denormal),
24251 T (Tag_ABI_FP_exceptions),
24252 T (Tag_ABI_FP_user_exceptions),
24253 T (Tag_ABI_FP_number_model),
75375b3e 24254 T (Tag_ABI_align_needed),
f31fef98 24255 T (Tag_ABI_align8_needed),
75375b3e 24256 T (Tag_ABI_align_preserved),
f31fef98
NC
24257 T (Tag_ABI_align8_preserved),
24258 T (Tag_ABI_enum_size),
24259 T (Tag_ABI_HardFP_use),
24260 T (Tag_ABI_VFP_args),
24261 T (Tag_ABI_WMMX_args),
24262 T (Tag_ABI_optimization_goals),
24263 T (Tag_ABI_FP_optimization_goals),
24264 T (Tag_compatibility),
24265 T (Tag_CPU_unaligned_access),
75375b3e 24266 T (Tag_FP_HP_extension),
f31fef98
NC
24267 T (Tag_VFP_HP_extension),
24268 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
24269 T (Tag_MPextension_use),
24270 T (Tag_DIV_use),
f31fef98
NC
24271 T (Tag_nodefaults),
24272 T (Tag_also_compatible_with),
24273 T (Tag_conformance),
24274 T (Tag_T2EE_use),
24275 T (Tag_Virtualization_use),
cd21e546 24276 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 24277#undef T
f31fef98 24278 };
e04befd0
AS
24279 unsigned int i;
24280
24281 if (name == NULL)
24282 return -1;
24283
f31fef98 24284 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 24285 if (streq (name, attribute_table[i].name))
e04befd0
AS
24286 return attribute_table[i].tag;
24287
24288 return -1;
24289}
267bf995
RR
24290
24291
24292/* Apply sym value for relocations only in the case that
24293 they are for local symbols and you have the respective
24294 architectural feature for blx and simple switches. */
24295int
24296arm_apply_sym_value (struct fix * fixP)
24297{
24298 if (fixP->fx_addsy
24299 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
34e77a92 24300 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
24301 {
24302 switch (fixP->fx_r_type)
24303 {
24304 case BFD_RELOC_ARM_PCREL_BLX:
24305 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24306 if (ARM_IS_FUNC (fixP->fx_addsy))
24307 return 1;
24308 break;
24309
24310 case BFD_RELOC_ARM_PCREL_CALL:
24311 case BFD_RELOC_THUMB_PCREL_BLX:
24312 if (THUMB_IS_FUNC (fixP->fx_addsy))
24313 return 1;
24314 break;
24315
24316 default:
24317 break;
24318 }
24319
24320 }
24321 return 0;
24322}
f31fef98 24323#endif /* OBJ_ELF */