]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
2010-01-06 Tristan Gingold <gingold@adacore.com>
[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,
f31fef98 3 2004, 2005, 2006, 2007, 2008, 2009
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"
b99bd4ef 35
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
NC
99#ifndef CPU_DEFAULT
100#if defined __XSCALE__
e74cfd16 101#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
102#else
103#if defined __thumb__
e74cfd16 104#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
105#endif
106#endif
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
e74cfd16
PB
129static arm_feature_set cpu_variant;
130static arm_feature_set arm_arch_used;
131static arm_feature_set thumb_arch_used;
b99bd4ef 132
b99bd4ef 133/* Flags stored in private area of BFD structure. */
c19d1205
ZW
134static int uses_apcs_26 = FALSE;
135static int atpcs = FALSE;
b34976b6
AM
136static int support_interwork = FALSE;
137static int uses_apcs_float = FALSE;
c19d1205 138static int pic_code = FALSE;
845b51d6 139static int fix_v4bx = FALSE;
278df34e
NS
140/* Warn on using deprecated features. */
141static int warn_on_deprecated = TRUE;
142
03b1477f
RE
143
144/* Variables that we set while parsing command-line options. Once all
145 options have been read we re-process these values to set the real
146 assembly flags. */
e74cfd16
PB
147static const arm_feature_set *legacy_cpu = NULL;
148static const arm_feature_set *legacy_fpu = NULL;
149
150static const arm_feature_set *mcpu_cpu_opt = NULL;
151static const arm_feature_set *mcpu_fpu_opt = NULL;
152static const arm_feature_set *march_cpu_opt = NULL;
153static const arm_feature_set *march_fpu_opt = NULL;
154static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 155static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
156
157/* Constants for known architecture features. */
158static const arm_feature_set fpu_default = FPU_DEFAULT;
159static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
160static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
161static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
162static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
163static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
164static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
165static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
166static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
167
168#ifdef CPU_DEFAULT
169static const arm_feature_set cpu_default = CPU_DEFAULT;
170#endif
171
172static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
174static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
175static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
176static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
177static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
178static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
179static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
180static const arm_feature_set arm_ext_v4t_5 =
181 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
182static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
183static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
184static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
185static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
186static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
187static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
188static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
189static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 190static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 191static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
192static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
193static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
194static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 198static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470
PB
199static const arm_feature_set arm_ext_m =
200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
201
202static const arm_feature_set arm_arch_any = ARM_ANY;
203static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
204static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
205static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
206
2d447fca
JM
207static const arm_feature_set arm_cext_iwmmxt2 =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
209static const arm_feature_set arm_cext_iwmmxt =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
211static const arm_feature_set arm_cext_xscale =
212 ARM_FEATURE (0, ARM_CEXT_XSCALE);
213static const arm_feature_set arm_cext_maverick =
214 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
215static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
216static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
217static const arm_feature_set fpu_vfp_ext_v1xd =
218 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
219static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
220static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 221static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 222static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
223static const arm_feature_set fpu_vfp_ext_d32 =
224 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
225static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
226static const arm_feature_set fpu_vfp_v3_or_neon_ext =
227 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
228static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
229static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
230static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 231
33a392fb 232static int mfloat_abi_opt = -1;
e74cfd16
PB
233/* Record user cpu selection for object attributes. */
234static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
235/* Must be long enough to hold any of the names in arm_cpus. */
236static char selected_cpu_name[16];
7cc69913 237#ifdef OBJ_ELF
deeaaff8
DJ
238# ifdef EABI_DEFAULT
239static int meabi_flags = EABI_DEFAULT;
240# else
d507cf36 241static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 242# endif
e1da3f5b 243
ee3c0378
AS
244static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
e1da3f5b 246bfd_boolean
5f4273c7 247arm_is_eabi (void)
e1da3f5b
PB
248{
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250}
7cc69913 251#endif
b99bd4ef 252
b99bd4ef 253#ifdef OBJ_ELF
c19d1205 254/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
255symbolS * GOT_symbol;
256#endif
257
b99bd4ef
NC
258/* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262static int thumb_mode = 0;
8dc2430f
NC
263/* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266#define MODE_RECORDED (1 << 4)
b99bd4ef 267
e07e6e58
NC
268/* Specifies the intrinsic IT insn behavior mode. */
269enum implicit_it_mode
270{
271 IMPLICIT_IT_MODE_NEVER = 0x00,
272 IMPLICIT_IT_MODE_ARM = 0x01,
273 IMPLICIT_IT_MODE_THUMB = 0x02,
274 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
275};
276static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
277
c19d1205
ZW
278/* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
280
281 - Immediate operands do not require a # prefix.
282 - Conditional affixes always appear at the end of the
283 instruction. (For backward compatibility, those instructions
284 that formerly had them in the middle, continue to accept them
285 there.)
286 - The IT instruction may appear, and if it does is validated
287 against subsequent conditional affixes. It does not generate
288 machine code.
289
290 Important differences from the old Thumb mode:
291
292 - Immediate operands do not require a # prefix.
293 - Most of the V6T2 instructions are only available in unified mode.
294 - The .N and .W suffixes are recognized and honored (it is an error
295 if they cannot be honored).
296 - All instructions set the flags if and only if they have an 's' affix.
297 - Conditional affixes may be used. They are validated against
298 preceding IT instructions. Unlike ARM mode, you cannot use a
299 conditional affix except in the scope of an IT instruction. */
300
301static bfd_boolean unified_syntax = FALSE;
b99bd4ef 302
5287ad62
JB
303enum neon_el_type
304{
dcbf9037 305 NT_invtype,
5287ad62
JB
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
dcbf9037 311 NT_unsigned
5287ad62
JB
312};
313
314struct neon_type_el
315{
316 enum neon_el_type type;
317 unsigned size;
318};
319
320#define NEON_MAX_TYPE_ELS 4
321
322struct neon_type
323{
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
326};
327
e07e6e58
NC
328enum it_instruction_type
329{
330 OUTSIDE_IT_INSN,
331 INSIDE_IT_INSN,
332 INSIDE_IT_LAST_INSN,
333 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
334 if inside, should be the last one. */
335 NEUTRAL_IT_INSN, /* This could be either inside or outside,
336 i.e. BKPT and NOP. */
337 IT_INSN /* The IT insn has been parsed. */
338};
339
b99bd4ef
NC
340struct arm_it
341{
c19d1205 342 const char * error;
b99bd4ef 343 unsigned long instruction;
c19d1205
ZW
344 int size;
345 int size_req;
346 int cond;
037e8744
JB
347 /* "uncond_value" is set to the value in place of the conditional field in
348 unconditional versions of the instruction, or -1 if nothing is
349 appropriate. */
350 int uncond_value;
5287ad62 351 struct neon_type vectype;
88714cb8
DG
352 /* This does not indicate an actual NEON instruction, only that
353 the mnemonic accepts neon-style type suffixes. */
354 int is_neon;
0110f2b8
PB
355 /* Set to the opcode if the instruction needs relaxation.
356 Zero if the instruction is not relaxed. */
357 unsigned long relax;
b99bd4ef
NC
358 struct
359 {
360 bfd_reloc_code_real_type type;
c19d1205
ZW
361 expressionS exp;
362 int pc_rel;
b99bd4ef 363 } reloc;
b99bd4ef 364
e07e6e58
NC
365 enum it_instruction_type it_insn_type;
366
c19d1205
ZW
367 struct
368 {
369 unsigned reg;
ca3f61f7 370 signed int imm;
dcbf9037 371 struct neon_type_el vectype;
ca3f61f7
NC
372 unsigned present : 1; /* Operand present. */
373 unsigned isreg : 1; /* Operand was a register. */
374 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
375 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
376 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 377 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
378 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
379 instructions. This allows us to disambiguate ARM <-> vector insns. */
380 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 381 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 382 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 383 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
384 unsigned hasreloc : 1; /* Operand has relocation suffix. */
385 unsigned writeback : 1; /* Operand has trailing ! */
386 unsigned preind : 1; /* Preindexed address. */
387 unsigned postind : 1; /* Postindexed address. */
388 unsigned negative : 1; /* Index register was negated. */
389 unsigned shifted : 1; /* Shift applied to operation. */
390 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 391 } operands[6];
b99bd4ef
NC
392};
393
c19d1205 394static struct arm_it inst;
b99bd4ef
NC
395
396#define NUM_FLOAT_VALS 8
397
05d2d07e 398const char * fp_const[] =
b99bd4ef
NC
399{
400 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
401};
402
c19d1205 403/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
404#define MAX_LITTLENUMS 6
405
406LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
407
408#define FAIL (-1)
409#define SUCCESS (0)
410
411#define SUFF_S 1
412#define SUFF_D 2
413#define SUFF_E 3
414#define SUFF_P 4
415
c19d1205
ZW
416#define CP_T_X 0x00008000
417#define CP_T_Y 0x00400000
b99bd4ef 418
c19d1205
ZW
419#define CONDS_BIT 0x00100000
420#define LOAD_BIT 0x00100000
b99bd4ef
NC
421
422#define DOUBLE_LOAD_FLAG 0x00000001
423
424struct asm_cond
425{
d3ce72d0 426 const char * template_name;
c921be7d 427 unsigned long value;
b99bd4ef
NC
428};
429
c19d1205 430#define COND_ALWAYS 0xE
b99bd4ef 431
b99bd4ef
NC
432struct asm_psr
433{
d3ce72d0 434 const char * template_name;
c921be7d 435 unsigned long field;
b99bd4ef
NC
436};
437
62b3e311
PB
438struct asm_barrier_opt
439{
d3ce72d0 440 const char * template_name;
c921be7d 441 unsigned long value;
62b3e311
PB
442};
443
2d2255b5 444/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
445#define SPSR_BIT (1 << 22)
446
c19d1205
ZW
447/* The individual PSR flag bits. */
448#define PSR_c (1 << 16)
449#define PSR_x (1 << 17)
450#define PSR_s (1 << 18)
451#define PSR_f (1 << 19)
b99bd4ef 452
c19d1205 453struct reloc_entry
bfae80f2 454{
c921be7d
NC
455 char * name;
456 bfd_reloc_code_real_type reloc;
bfae80f2
RE
457};
458
5287ad62 459enum vfp_reg_pos
bfae80f2 460{
5287ad62
JB
461 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
462 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
463};
464
465enum vfp_ldstm_type
466{
467 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
468};
469
dcbf9037
JB
470/* Bits for DEFINED field in neon_typed_alias. */
471#define NTA_HASTYPE 1
472#define NTA_HASINDEX 2
473
474struct neon_typed_alias
475{
c921be7d
NC
476 unsigned char defined;
477 unsigned char index;
478 struct neon_type_el eltype;
dcbf9037
JB
479};
480
c19d1205
ZW
481/* ARM register categories. This includes coprocessor numbers and various
482 architecture extensions' registers. */
483enum arm_reg_type
bfae80f2 484{
c19d1205
ZW
485 REG_TYPE_RN,
486 REG_TYPE_CP,
487 REG_TYPE_CN,
488 REG_TYPE_FN,
489 REG_TYPE_VFS,
490 REG_TYPE_VFD,
5287ad62 491 REG_TYPE_NQ,
037e8744 492 REG_TYPE_VFSD,
5287ad62 493 REG_TYPE_NDQ,
037e8744 494 REG_TYPE_NSDQ,
c19d1205
ZW
495 REG_TYPE_VFC,
496 REG_TYPE_MVF,
497 REG_TYPE_MVD,
498 REG_TYPE_MVFX,
499 REG_TYPE_MVDX,
500 REG_TYPE_MVAX,
501 REG_TYPE_DSPSC,
502 REG_TYPE_MMXWR,
503 REG_TYPE_MMXWC,
504 REG_TYPE_MMXWCG,
505 REG_TYPE_XSCALE,
bfae80f2
RE
506};
507
dcbf9037
JB
508/* Structure for a hash table entry for a register.
509 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
510 information which states whether a vector type or index is specified (for a
511 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
512struct reg_entry
513{
c921be7d
NC
514 const char * name;
515 unsigned char number;
516 unsigned char type;
517 unsigned char builtin;
518 struct neon_typed_alias * neon;
6c43fab6
RE
519};
520
c19d1205 521/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 522const char * const reg_expected_msgs[] =
c19d1205
ZW
523{
524 N_("ARM register expected"),
525 N_("bad or missing co-processor number"),
526 N_("co-processor register expected"),
527 N_("FPA register expected"),
528 N_("VFP single precision register expected"),
5287ad62
JB
529 N_("VFP/Neon double precision register expected"),
530 N_("Neon quad precision register expected"),
037e8744 531 N_("VFP single or double precision register expected"),
5287ad62 532 N_("Neon double or quad precision register expected"),
037e8744 533 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
534 N_("VFP system register expected"),
535 N_("Maverick MVF register expected"),
536 N_("Maverick MVD register expected"),
537 N_("Maverick MVFX register expected"),
538 N_("Maverick MVDX register expected"),
539 N_("Maverick MVAX register expected"),
540 N_("Maverick DSPSC register expected"),
541 N_("iWMMXt data register expected"),
542 N_("iWMMXt control register expected"),
543 N_("iWMMXt scalar register expected"),
544 N_("XScale accumulator register expected"),
6c43fab6
RE
545};
546
c19d1205
ZW
547/* Some well known registers that we refer to directly elsewhere. */
548#define REG_SP 13
549#define REG_LR 14
550#define REG_PC 15
404ff6b5 551
b99bd4ef
NC
552/* ARM instructions take 4bytes in the object file, Thumb instructions
553 take 2: */
c19d1205 554#define INSN_SIZE 4
b99bd4ef
NC
555
556struct asm_opcode
557{
558 /* Basic string to match. */
d3ce72d0 559 const char * template_name;
c19d1205
ZW
560
561 /* Parameters to instruction. */
562 unsigned char operands[8];
563
564 /* Conditional tag - see opcode_lookup. */
565 unsigned int tag : 4;
b99bd4ef
NC
566
567 /* Basic instruction code. */
c19d1205 568 unsigned int avalue : 28;
b99bd4ef 569
c19d1205
ZW
570 /* Thumb-format instruction code. */
571 unsigned int tvalue;
b99bd4ef 572
90e4755a 573 /* Which architecture variant provides this instruction. */
c921be7d
NC
574 const arm_feature_set * avariant;
575 const arm_feature_set * tvariant;
c19d1205
ZW
576
577 /* Function to call to encode instruction in ARM format. */
578 void (* aencode) (void);
b99bd4ef 579
c19d1205
ZW
580 /* Function to call to encode instruction in Thumb format. */
581 void (* tencode) (void);
b99bd4ef
NC
582};
583
a737bd4d
NC
584/* Defines for various bits that we will want to toggle. */
585#define INST_IMMEDIATE 0x02000000
586#define OFFSET_REG 0x02000000
c19d1205 587#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
588#define SHIFT_BY_REG 0x00000010
589#define PRE_INDEX 0x01000000
590#define INDEX_UP 0x00800000
591#define WRITE_BACK 0x00200000
592#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 593#define CPSI_MMOD 0x00020000
90e4755a 594
a737bd4d
NC
595#define LITERAL_MASK 0xf000f000
596#define OPCODE_MASK 0xfe1fffff
597#define V4_STR_BIT 0x00000020
90e4755a 598
efd81785
PB
599#define T2_SUBS_PC_LR 0xf3de8f00
600
a737bd4d 601#define DATA_OP_SHIFT 21
90e4755a 602
ef8d22e6
PB
603#define T2_OPCODE_MASK 0xfe1fffff
604#define T2_DATA_OP_SHIFT 21
605
a737bd4d
NC
606/* Codes to distinguish the arithmetic instructions. */
607#define OPCODE_AND 0
608#define OPCODE_EOR 1
609#define OPCODE_SUB 2
610#define OPCODE_RSB 3
611#define OPCODE_ADD 4
612#define OPCODE_ADC 5
613#define OPCODE_SBC 6
614#define OPCODE_RSC 7
615#define OPCODE_TST 8
616#define OPCODE_TEQ 9
617#define OPCODE_CMP 10
618#define OPCODE_CMN 11
619#define OPCODE_ORR 12
620#define OPCODE_MOV 13
621#define OPCODE_BIC 14
622#define OPCODE_MVN 15
90e4755a 623
ef8d22e6
PB
624#define T2_OPCODE_AND 0
625#define T2_OPCODE_BIC 1
626#define T2_OPCODE_ORR 2
627#define T2_OPCODE_ORN 3
628#define T2_OPCODE_EOR 4
629#define T2_OPCODE_ADD 8
630#define T2_OPCODE_ADC 10
631#define T2_OPCODE_SBC 11
632#define T2_OPCODE_SUB 13
633#define T2_OPCODE_RSB 14
634
a737bd4d
NC
635#define T_OPCODE_MUL 0x4340
636#define T_OPCODE_TST 0x4200
637#define T_OPCODE_CMN 0x42c0
638#define T_OPCODE_NEG 0x4240
639#define T_OPCODE_MVN 0x43c0
90e4755a 640
a737bd4d
NC
641#define T_OPCODE_ADD_R3 0x1800
642#define T_OPCODE_SUB_R3 0x1a00
643#define T_OPCODE_ADD_HI 0x4400
644#define T_OPCODE_ADD_ST 0xb000
645#define T_OPCODE_SUB_ST 0xb080
646#define T_OPCODE_ADD_SP 0xa800
647#define T_OPCODE_ADD_PC 0xa000
648#define T_OPCODE_ADD_I8 0x3000
649#define T_OPCODE_SUB_I8 0x3800
650#define T_OPCODE_ADD_I3 0x1c00
651#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 652
a737bd4d
NC
653#define T_OPCODE_ASR_R 0x4100
654#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
655#define T_OPCODE_LSR_R 0x40c0
656#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
657#define T_OPCODE_ASR_I 0x1000
658#define T_OPCODE_LSL_I 0x0000
659#define T_OPCODE_LSR_I 0x0800
b99bd4ef 660
a737bd4d
NC
661#define T_OPCODE_MOV_I8 0x2000
662#define T_OPCODE_CMP_I8 0x2800
663#define T_OPCODE_CMP_LR 0x4280
664#define T_OPCODE_MOV_HR 0x4600
665#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 666
a737bd4d
NC
667#define T_OPCODE_LDR_PC 0x4800
668#define T_OPCODE_LDR_SP 0x9800
669#define T_OPCODE_STR_SP 0x9000
670#define T_OPCODE_LDR_IW 0x6800
671#define T_OPCODE_STR_IW 0x6000
672#define T_OPCODE_LDR_IH 0x8800
673#define T_OPCODE_STR_IH 0x8000
674#define T_OPCODE_LDR_IB 0x7800
675#define T_OPCODE_STR_IB 0x7000
676#define T_OPCODE_LDR_RW 0x5800
677#define T_OPCODE_STR_RW 0x5000
678#define T_OPCODE_LDR_RH 0x5a00
679#define T_OPCODE_STR_RH 0x5200
680#define T_OPCODE_LDR_RB 0x5c00
681#define T_OPCODE_STR_RB 0x5400
c9b604bd 682
a737bd4d
NC
683#define T_OPCODE_PUSH 0xb400
684#define T_OPCODE_POP 0xbc00
b99bd4ef 685
2fc8bdac 686#define T_OPCODE_BRANCH 0xe000
b99bd4ef 687
a737bd4d 688#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 689#define THUMB_PP_PC_LR 0x0100
c19d1205 690#define THUMB_LOAD_BIT 0x0800
53365c0d 691#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
692
693#define BAD_ARGS _("bad arguments to instruction")
fdfde340 694#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
695#define BAD_PC _("r15 not allowed here")
696#define BAD_COND _("instruction cannot be conditional")
697#define BAD_OVERLAP _("registers may not be the same")
698#define BAD_HIREG _("lo register required")
699#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 700#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
701#define BAD_BRANCH _("branch must be last instruction in IT block")
702#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 703#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
704#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
705#define BAD_IT_COND _("incorrect condition in IT block")
706#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 707#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
c19d1205 708
c921be7d
NC
709static struct hash_control * arm_ops_hsh;
710static struct hash_control * arm_cond_hsh;
711static struct hash_control * arm_shift_hsh;
712static struct hash_control * arm_psr_hsh;
713static struct hash_control * arm_v7m_psr_hsh;
714static struct hash_control * arm_reg_hsh;
715static struct hash_control * arm_reloc_hsh;
716static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 717
b99bd4ef
NC
718/* Stuff needed to resolve the label ambiguity
719 As:
720 ...
721 label: <insn>
722 may differ from:
723 ...
724 label:
5f4273c7 725 <insn> */
b99bd4ef
NC
726
727symbolS * last_label_seen;
b34976b6 728static int label_is_thumb_function_name = FALSE;
e07e6e58 729
3d0c9500
NC
730/* Literal pool structure. Held on a per-section
731 and per-sub-section basis. */
a737bd4d 732
c19d1205 733#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 734typedef struct literal_pool
b99bd4ef 735{
c921be7d
NC
736 expressionS literals [MAX_LITERAL_POOL_SIZE];
737 unsigned int next_free_entry;
738 unsigned int id;
739 symbolS * symbol;
740 segT section;
741 subsegT sub_section;
742 struct literal_pool * next;
3d0c9500 743} literal_pool;
b99bd4ef 744
3d0c9500
NC
745/* Pointer to a linked list of literal pools. */
746literal_pool * list_of_pools = NULL;
e27ec89e 747
e07e6e58
NC
748#ifdef OBJ_ELF
749# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
750#else
751static struct current_it now_it;
752#endif
753
754static inline int
755now_it_compatible (int cond)
756{
757 return (cond & ~1) == (now_it.cc & ~1);
758}
759
760static inline int
761conditional_insn (void)
762{
763 return inst.cond != COND_ALWAYS;
764}
765
766static int in_it_block (void);
767
768static int handle_it_state (void);
769
770static void force_automatic_it_block_close (void);
771
c921be7d
NC
772static void it_fsm_post_encode (void);
773
e07e6e58
NC
774#define set_it_insn_type(type) \
775 do \
776 { \
777 inst.it_insn_type = type; \
778 if (handle_it_state () == FAIL) \
779 return; \
780 } \
781 while (0)
782
c921be7d
NC
783#define set_it_insn_type_nonvoid(type, failret) \
784 do \
785 { \
786 inst.it_insn_type = type; \
787 if (handle_it_state () == FAIL) \
788 return failret; \
789 } \
790 while(0)
791
e07e6e58
NC
792#define set_it_insn_type_last() \
793 do \
794 { \
795 if (inst.cond == COND_ALWAYS) \
796 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
797 else \
798 set_it_insn_type (INSIDE_IT_LAST_INSN); \
799 } \
800 while (0)
801
c19d1205 802/* Pure syntax. */
b99bd4ef 803
c19d1205
ZW
804/* This array holds the chars that always start a comment. If the
805 pre-processor is disabled, these aren't very useful. */
806const char comment_chars[] = "@";
3d0c9500 807
c19d1205
ZW
808/* This array holds the chars that only start a comment at the beginning of
809 a line. If the line seems to have the form '# 123 filename'
810 .line and .file directives will appear in the pre-processed output. */
811/* Note that input_file.c hand checks for '#' at the beginning of the
812 first line of the input file. This is because the compiler outputs
813 #NO_APP at the beginning of its output. */
814/* Also note that comments like this one will always work. */
815const char line_comment_chars[] = "#";
3d0c9500 816
c19d1205 817const char line_separator_chars[] = ";";
b99bd4ef 818
c19d1205
ZW
819/* Chars that can be used to separate mant
820 from exp in floating point numbers. */
821const char EXP_CHARS[] = "eE";
3d0c9500 822
c19d1205
ZW
823/* Chars that mean this number is a floating point constant. */
824/* As in 0f12.456 */
825/* or 0d1.2345e12 */
b99bd4ef 826
c19d1205 827const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 828
c19d1205
ZW
829/* Prefix characters that indicate the start of an immediate
830 value. */
831#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 832
c19d1205
ZW
833/* Separator character handling. */
834
835#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
836
837static inline int
838skip_past_char (char ** str, char c)
839{
840 if (**str == c)
841 {
842 (*str)++;
843 return SUCCESS;
3d0c9500 844 }
c19d1205
ZW
845 else
846 return FAIL;
847}
c921be7d 848
c19d1205 849#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 850
c19d1205
ZW
851/* Arithmetic expressions (possibly involving symbols). */
852
853/* Return TRUE if anything in the expression is a bignum. */
854
855static int
856walk_no_bignums (symbolS * sp)
857{
858 if (symbol_get_value_expression (sp)->X_op == O_big)
859 return 1;
860
861 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 862 {
c19d1205
ZW
863 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
864 || (symbol_get_value_expression (sp)->X_op_symbol
865 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
866 }
867
c19d1205 868 return 0;
3d0c9500
NC
869}
870
c19d1205
ZW
871static int in_my_get_expression = 0;
872
873/* Third argument to my_get_expression. */
874#define GE_NO_PREFIX 0
875#define GE_IMM_PREFIX 1
876#define GE_OPT_PREFIX 2
5287ad62
JB
877/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
878 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
879#define GE_OPT_PREFIX_BIG 3
a737bd4d 880
b99bd4ef 881static int
c19d1205 882my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 883{
c19d1205
ZW
884 char * save_in;
885 segT seg;
b99bd4ef 886
c19d1205
ZW
887 /* In unified syntax, all prefixes are optional. */
888 if (unified_syntax)
5287ad62
JB
889 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
890 : GE_OPT_PREFIX;
b99bd4ef 891
c19d1205 892 switch (prefix_mode)
b99bd4ef 893 {
c19d1205
ZW
894 case GE_NO_PREFIX: break;
895 case GE_IMM_PREFIX:
896 if (!is_immediate_prefix (**str))
897 {
898 inst.error = _("immediate expression requires a # prefix");
899 return FAIL;
900 }
901 (*str)++;
902 break;
903 case GE_OPT_PREFIX:
5287ad62 904 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
905 if (is_immediate_prefix (**str))
906 (*str)++;
907 break;
908 default: abort ();
909 }
b99bd4ef 910
c19d1205 911 memset (ep, 0, sizeof (expressionS));
b99bd4ef 912
c19d1205
ZW
913 save_in = input_line_pointer;
914 input_line_pointer = *str;
915 in_my_get_expression = 1;
916 seg = expression (ep);
917 in_my_get_expression = 0;
918
f86adc07 919 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 920 {
f86adc07 921 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
922 *str = input_line_pointer;
923 input_line_pointer = save_in;
924 if (inst.error == NULL)
f86adc07
NS
925 inst.error = (ep->X_op == O_absent
926 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
927 return 1;
928 }
b99bd4ef 929
c19d1205
ZW
930#ifdef OBJ_AOUT
931 if (seg != absolute_section
932 && seg != text_section
933 && seg != data_section
934 && seg != bss_section
935 && seg != undefined_section)
936 {
937 inst.error = _("bad segment");
938 *str = input_line_pointer;
939 input_line_pointer = save_in;
940 return 1;
b99bd4ef 941 }
c19d1205 942#endif
b99bd4ef 943
c19d1205
ZW
944 /* Get rid of any bignums now, so that we don't generate an error for which
945 we can't establish a line number later on. Big numbers are never valid
946 in instructions, which is where this routine is always called. */
5287ad62
JB
947 if (prefix_mode != GE_OPT_PREFIX_BIG
948 && (ep->X_op == O_big
949 || (ep->X_add_symbol
950 && (walk_no_bignums (ep->X_add_symbol)
951 || (ep->X_op_symbol
952 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
953 {
954 inst.error = _("invalid constant");
955 *str = input_line_pointer;
956 input_line_pointer = save_in;
957 return 1;
958 }
b99bd4ef 959
c19d1205
ZW
960 *str = input_line_pointer;
961 input_line_pointer = save_in;
962 return 0;
b99bd4ef
NC
963}
964
c19d1205
ZW
965/* Turn a string in input_line_pointer into a floating point constant
966 of type TYPE, and store the appropriate bytes in *LITP. The number
967 of LITTLENUMS emitted is stored in *SIZEP. An error message is
968 returned, or NULL on OK.
b99bd4ef 969
c19d1205
ZW
970 Note that fp constants aren't represent in the normal way on the ARM.
971 In big endian mode, things are as expected. However, in little endian
972 mode fp constants are big-endian word-wise, and little-endian byte-wise
973 within the words. For example, (double) 1.1 in big endian mode is
974 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
975 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 976
c19d1205 977 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 978
c19d1205
ZW
979char *
980md_atof (int type, char * litP, int * sizeP)
981{
982 int prec;
983 LITTLENUM_TYPE words[MAX_LITTLENUMS];
984 char *t;
985 int i;
b99bd4ef 986
c19d1205
ZW
987 switch (type)
988 {
989 case 'f':
990 case 'F':
991 case 's':
992 case 'S':
993 prec = 2;
994 break;
b99bd4ef 995
c19d1205
ZW
996 case 'd':
997 case 'D':
998 case 'r':
999 case 'R':
1000 prec = 4;
1001 break;
b99bd4ef 1002
c19d1205
ZW
1003 case 'x':
1004 case 'X':
499ac353 1005 prec = 5;
c19d1205 1006 break;
b99bd4ef 1007
c19d1205
ZW
1008 case 'p':
1009 case 'P':
499ac353 1010 prec = 5;
c19d1205 1011 break;
a737bd4d 1012
c19d1205
ZW
1013 default:
1014 *sizeP = 0;
499ac353 1015 return _("Unrecognized or unsupported floating point constant");
c19d1205 1016 }
b99bd4ef 1017
c19d1205
ZW
1018 t = atof_ieee (input_line_pointer, type, words);
1019 if (t)
1020 input_line_pointer = t;
499ac353 1021 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1022
c19d1205
ZW
1023 if (target_big_endian)
1024 {
1025 for (i = 0; i < prec; i++)
1026 {
499ac353
NC
1027 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1028 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1029 }
1030 }
1031 else
1032 {
e74cfd16 1033 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1034 for (i = prec - 1; i >= 0; i--)
1035 {
499ac353
NC
1036 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1037 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1038 }
1039 else
1040 /* For a 4 byte float the order of elements in `words' is 1 0.
1041 For an 8 byte float the order is 1 0 3 2. */
1042 for (i = 0; i < prec; i += 2)
1043 {
499ac353
NC
1044 md_number_to_chars (litP, (valueT) words[i + 1],
1045 sizeof (LITTLENUM_TYPE));
1046 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1047 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1048 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1049 }
1050 }
b99bd4ef 1051
499ac353 1052 return NULL;
c19d1205 1053}
b99bd4ef 1054
c19d1205
ZW
1055/* We handle all bad expressions here, so that we can report the faulty
1056 instruction in the error message. */
1057void
91d6fa6a 1058md_operand (expressionS * exp)
c19d1205
ZW
1059{
1060 if (in_my_get_expression)
91d6fa6a 1061 exp->X_op = O_illegal;
b99bd4ef
NC
1062}
1063
c19d1205 1064/* Immediate values. */
b99bd4ef 1065
c19d1205
ZW
1066/* Generic immediate-value read function for use in directives.
1067 Accepts anything that 'expression' can fold to a constant.
1068 *val receives the number. */
1069#ifdef OBJ_ELF
1070static int
1071immediate_for_directive (int *val)
b99bd4ef 1072{
c19d1205
ZW
1073 expressionS exp;
1074 exp.X_op = O_illegal;
b99bd4ef 1075
c19d1205
ZW
1076 if (is_immediate_prefix (*input_line_pointer))
1077 {
1078 input_line_pointer++;
1079 expression (&exp);
1080 }
b99bd4ef 1081
c19d1205
ZW
1082 if (exp.X_op != O_constant)
1083 {
1084 as_bad (_("expected #constant"));
1085 ignore_rest_of_line ();
1086 return FAIL;
1087 }
1088 *val = exp.X_add_number;
1089 return SUCCESS;
b99bd4ef 1090}
c19d1205 1091#endif
b99bd4ef 1092
c19d1205 1093/* Register parsing. */
b99bd4ef 1094
c19d1205
ZW
1095/* Generic register parser. CCP points to what should be the
1096 beginning of a register name. If it is indeed a valid register
1097 name, advance CCP over it and return the reg_entry structure;
1098 otherwise return NULL. Does not issue diagnostics. */
1099
1100static struct reg_entry *
1101arm_reg_parse_multi (char **ccp)
b99bd4ef 1102{
c19d1205
ZW
1103 char *start = *ccp;
1104 char *p;
1105 struct reg_entry *reg;
b99bd4ef 1106
c19d1205
ZW
1107#ifdef REGISTER_PREFIX
1108 if (*start != REGISTER_PREFIX)
01cfc07f 1109 return NULL;
c19d1205
ZW
1110 start++;
1111#endif
1112#ifdef OPTIONAL_REGISTER_PREFIX
1113 if (*start == OPTIONAL_REGISTER_PREFIX)
1114 start++;
1115#endif
b99bd4ef 1116
c19d1205
ZW
1117 p = start;
1118 if (!ISALPHA (*p) || !is_name_beginner (*p))
1119 return NULL;
b99bd4ef 1120
c19d1205
ZW
1121 do
1122 p++;
1123 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1124
1125 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1126
1127 if (!reg)
1128 return NULL;
1129
1130 *ccp = p;
1131 return reg;
b99bd4ef
NC
1132}
1133
1134static int
dcbf9037
JB
1135arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1136 enum arm_reg_type type)
b99bd4ef 1137{
c19d1205
ZW
1138 /* Alternative syntaxes are accepted for a few register classes. */
1139 switch (type)
1140 {
1141 case REG_TYPE_MVF:
1142 case REG_TYPE_MVD:
1143 case REG_TYPE_MVFX:
1144 case REG_TYPE_MVDX:
1145 /* Generic coprocessor register names are allowed for these. */
79134647 1146 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1147 return reg->number;
1148 break;
69b97547 1149
c19d1205
ZW
1150 case REG_TYPE_CP:
1151 /* For backward compatibility, a bare number is valid here. */
1152 {
1153 unsigned long processor = strtoul (start, ccp, 10);
1154 if (*ccp != start && processor <= 15)
1155 return processor;
1156 }
6057a28f 1157
c19d1205
ZW
1158 case REG_TYPE_MMXWC:
1159 /* WC includes WCG. ??? I'm not sure this is true for all
1160 instructions that take WC registers. */
79134647 1161 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1162 return reg->number;
6057a28f 1163 break;
c19d1205 1164
6057a28f 1165 default:
c19d1205 1166 break;
6057a28f
NC
1167 }
1168
dcbf9037
JB
1169 return FAIL;
1170}
1171
1172/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1173 return value is the register number or FAIL. */
1174
1175static int
1176arm_reg_parse (char **ccp, enum arm_reg_type type)
1177{
1178 char *start = *ccp;
1179 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1180 int ret;
1181
1182 /* Do not allow a scalar (reg+index) to parse as a register. */
1183 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1184 return FAIL;
1185
1186 if (reg && reg->type == type)
1187 return reg->number;
1188
1189 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1190 return ret;
1191
c19d1205
ZW
1192 *ccp = start;
1193 return FAIL;
1194}
69b97547 1195
dcbf9037
JB
1196/* Parse a Neon type specifier. *STR should point at the leading '.'
1197 character. Does no verification at this stage that the type fits the opcode
1198 properly. E.g.,
1199
1200 .i32.i32.s16
1201 .s32.f32
1202 .u16
1203
1204 Can all be legally parsed by this function.
1205
1206 Fills in neon_type struct pointer with parsed information, and updates STR
1207 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1208 type, FAIL if not. */
1209
1210static int
1211parse_neon_type (struct neon_type *type, char **str)
1212{
1213 char *ptr = *str;
1214
1215 if (type)
1216 type->elems = 0;
1217
1218 while (type->elems < NEON_MAX_TYPE_ELS)
1219 {
1220 enum neon_el_type thistype = NT_untyped;
1221 unsigned thissize = -1u;
1222
1223 if (*ptr != '.')
1224 break;
1225
1226 ptr++;
1227
1228 /* Just a size without an explicit type. */
1229 if (ISDIGIT (*ptr))
1230 goto parsesize;
1231
1232 switch (TOLOWER (*ptr))
1233 {
1234 case 'i': thistype = NT_integer; break;
1235 case 'f': thistype = NT_float; break;
1236 case 'p': thistype = NT_poly; break;
1237 case 's': thistype = NT_signed; break;
1238 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1239 case 'd':
1240 thistype = NT_float;
1241 thissize = 64;
1242 ptr++;
1243 goto done;
dcbf9037
JB
1244 default:
1245 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1246 return FAIL;
1247 }
1248
1249 ptr++;
1250
1251 /* .f is an abbreviation for .f32. */
1252 if (thistype == NT_float && !ISDIGIT (*ptr))
1253 thissize = 32;
1254 else
1255 {
1256 parsesize:
1257 thissize = strtoul (ptr, &ptr, 10);
1258
1259 if (thissize != 8 && thissize != 16 && thissize != 32
1260 && thissize != 64)
1261 {
1262 as_bad (_("bad size %d in type specifier"), thissize);
1263 return FAIL;
1264 }
1265 }
1266
037e8744 1267 done:
dcbf9037
JB
1268 if (type)
1269 {
1270 type->el[type->elems].type = thistype;
1271 type->el[type->elems].size = thissize;
1272 type->elems++;
1273 }
1274 }
1275
1276 /* Empty/missing type is not a successful parse. */
1277 if (type->elems == 0)
1278 return FAIL;
1279
1280 *str = ptr;
1281
1282 return SUCCESS;
1283}
1284
1285/* Errors may be set multiple times during parsing or bit encoding
1286 (particularly in the Neon bits), but usually the earliest error which is set
1287 will be the most meaningful. Avoid overwriting it with later (cascading)
1288 errors by calling this function. */
1289
1290static void
1291first_error (const char *err)
1292{
1293 if (!inst.error)
1294 inst.error = err;
1295}
1296
1297/* Parse a single type, e.g. ".s32", leading period included. */
1298static int
1299parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1300{
1301 char *str = *ccp;
1302 struct neon_type optype;
1303
1304 if (*str == '.')
1305 {
1306 if (parse_neon_type (&optype, &str) == SUCCESS)
1307 {
1308 if (optype.elems == 1)
1309 *vectype = optype.el[0];
1310 else
1311 {
1312 first_error (_("only one type should be specified for operand"));
1313 return FAIL;
1314 }
1315 }
1316 else
1317 {
1318 first_error (_("vector type expected"));
1319 return FAIL;
1320 }
1321 }
1322 else
1323 return FAIL;
5f4273c7 1324
dcbf9037 1325 *ccp = str;
5f4273c7 1326
dcbf9037
JB
1327 return SUCCESS;
1328}
1329
1330/* Special meanings for indices (which have a range of 0-7), which will fit into
1331 a 4-bit integer. */
1332
1333#define NEON_ALL_LANES 15
1334#define NEON_INTERLEAVE_LANES 14
1335
1336/* Parse either a register or a scalar, with an optional type. Return the
1337 register number, and optionally fill in the actual type of the register
1338 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1339 type/index information in *TYPEINFO. */
1340
1341static int
1342parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1343 enum arm_reg_type *rtype,
1344 struct neon_typed_alias *typeinfo)
1345{
1346 char *str = *ccp;
1347 struct reg_entry *reg = arm_reg_parse_multi (&str);
1348 struct neon_typed_alias atype;
1349 struct neon_type_el parsetype;
1350
1351 atype.defined = 0;
1352 atype.index = -1;
1353 atype.eltype.type = NT_invtype;
1354 atype.eltype.size = -1;
1355
1356 /* Try alternate syntax for some types of register. Note these are mutually
1357 exclusive with the Neon syntax extensions. */
1358 if (reg == NULL)
1359 {
1360 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1361 if (altreg != FAIL)
1362 *ccp = str;
1363 if (typeinfo)
1364 *typeinfo = atype;
1365 return altreg;
1366 }
1367
037e8744
JB
1368 /* Undo polymorphism when a set of register types may be accepted. */
1369 if ((type == REG_TYPE_NDQ
1370 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1371 || (type == REG_TYPE_VFSD
1372 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1373 || (type == REG_TYPE_NSDQ
1374 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1375 || reg->type == REG_TYPE_NQ))
1376 || (type == REG_TYPE_MMXWC
1377 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1378 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1379
1380 if (type != reg->type)
1381 return FAIL;
1382
1383 if (reg->neon)
1384 atype = *reg->neon;
5f4273c7 1385
dcbf9037
JB
1386 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1387 {
1388 if ((atype.defined & NTA_HASTYPE) != 0)
1389 {
1390 first_error (_("can't redefine type for operand"));
1391 return FAIL;
1392 }
1393 atype.defined |= NTA_HASTYPE;
1394 atype.eltype = parsetype;
1395 }
5f4273c7 1396
dcbf9037
JB
1397 if (skip_past_char (&str, '[') == SUCCESS)
1398 {
1399 if (type != REG_TYPE_VFD)
1400 {
1401 first_error (_("only D registers may be indexed"));
1402 return FAIL;
1403 }
5f4273c7 1404
dcbf9037
JB
1405 if ((atype.defined & NTA_HASINDEX) != 0)
1406 {
1407 first_error (_("can't change index for operand"));
1408 return FAIL;
1409 }
1410
1411 atype.defined |= NTA_HASINDEX;
1412
1413 if (skip_past_char (&str, ']') == SUCCESS)
1414 atype.index = NEON_ALL_LANES;
1415 else
1416 {
1417 expressionS exp;
1418
1419 my_get_expression (&exp, &str, GE_NO_PREFIX);
1420
1421 if (exp.X_op != O_constant)
1422 {
1423 first_error (_("constant expression required"));
1424 return FAIL;
1425 }
1426
1427 if (skip_past_char (&str, ']') == FAIL)
1428 return FAIL;
1429
1430 atype.index = exp.X_add_number;
1431 }
1432 }
5f4273c7 1433
dcbf9037
JB
1434 if (typeinfo)
1435 *typeinfo = atype;
5f4273c7 1436
dcbf9037
JB
1437 if (rtype)
1438 *rtype = type;
5f4273c7 1439
dcbf9037 1440 *ccp = str;
5f4273c7 1441
dcbf9037
JB
1442 return reg->number;
1443}
1444
1445/* Like arm_reg_parse, but allow allow the following extra features:
1446 - If RTYPE is non-zero, return the (possibly restricted) type of the
1447 register (e.g. Neon double or quad reg when either has been requested).
1448 - If this is a Neon vector type with additional type information, fill
1449 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1450 This function will fault on encountering a scalar. */
dcbf9037
JB
1451
1452static int
1453arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1454 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1455{
1456 struct neon_typed_alias atype;
1457 char *str = *ccp;
1458 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1459
1460 if (reg == FAIL)
1461 return FAIL;
1462
1463 /* Do not allow a scalar (reg+index) to parse as a register. */
1464 if ((atype.defined & NTA_HASINDEX) != 0)
1465 {
1466 first_error (_("register operand expected, but got scalar"));
1467 return FAIL;
1468 }
1469
1470 if (vectype)
1471 *vectype = atype.eltype;
1472
1473 *ccp = str;
1474
1475 return reg;
1476}
1477
1478#define NEON_SCALAR_REG(X) ((X) >> 4)
1479#define NEON_SCALAR_INDEX(X) ((X) & 15)
1480
5287ad62
JB
1481/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1482 have enough information to be able to do a good job bounds-checking. So, we
1483 just do easy checks here, and do further checks later. */
1484
1485static int
dcbf9037 1486parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1487{
dcbf9037 1488 int reg;
5287ad62 1489 char *str = *ccp;
dcbf9037 1490 struct neon_typed_alias atype;
5f4273c7 1491
dcbf9037 1492 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1493
dcbf9037 1494 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1495 return FAIL;
5f4273c7 1496
dcbf9037 1497 if (atype.index == NEON_ALL_LANES)
5287ad62 1498 {
dcbf9037 1499 first_error (_("scalar must have an index"));
5287ad62
JB
1500 return FAIL;
1501 }
dcbf9037 1502 else if (atype.index >= 64 / elsize)
5287ad62 1503 {
dcbf9037 1504 first_error (_("scalar index out of range"));
5287ad62
JB
1505 return FAIL;
1506 }
5f4273c7 1507
dcbf9037
JB
1508 if (type)
1509 *type = atype.eltype;
5f4273c7 1510
5287ad62 1511 *ccp = str;
5f4273c7 1512
dcbf9037 1513 return reg * 16 + atype.index;
5287ad62
JB
1514}
1515
c19d1205 1516/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1517
c19d1205
ZW
1518static long
1519parse_reg_list (char ** strp)
1520{
1521 char * str = * strp;
1522 long range = 0;
1523 int another_range;
a737bd4d 1524
c19d1205
ZW
1525 /* We come back here if we get ranges concatenated by '+' or '|'. */
1526 do
6057a28f 1527 {
c19d1205 1528 another_range = 0;
a737bd4d 1529
c19d1205
ZW
1530 if (*str == '{')
1531 {
1532 int in_range = 0;
1533 int cur_reg = -1;
a737bd4d 1534
c19d1205
ZW
1535 str++;
1536 do
1537 {
1538 int reg;
6057a28f 1539
dcbf9037 1540 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1541 {
dcbf9037 1542 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1543 return FAIL;
1544 }
a737bd4d 1545
c19d1205
ZW
1546 if (in_range)
1547 {
1548 int i;
a737bd4d 1549
c19d1205
ZW
1550 if (reg <= cur_reg)
1551 {
dcbf9037 1552 first_error (_("bad range in register list"));
c19d1205
ZW
1553 return FAIL;
1554 }
40a18ebd 1555
c19d1205
ZW
1556 for (i = cur_reg + 1; i < reg; i++)
1557 {
1558 if (range & (1 << i))
1559 as_tsktsk
1560 (_("Warning: duplicated register (r%d) in register list"),
1561 i);
1562 else
1563 range |= 1 << i;
1564 }
1565 in_range = 0;
1566 }
a737bd4d 1567
c19d1205
ZW
1568 if (range & (1 << reg))
1569 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1570 reg);
1571 else if (reg <= cur_reg)
1572 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1573
c19d1205
ZW
1574 range |= 1 << reg;
1575 cur_reg = reg;
1576 }
1577 while (skip_past_comma (&str) != FAIL
1578 || (in_range = 1, *str++ == '-'));
1579 str--;
a737bd4d 1580
c19d1205
ZW
1581 if (*str++ != '}')
1582 {
dcbf9037 1583 first_error (_("missing `}'"));
c19d1205
ZW
1584 return FAIL;
1585 }
1586 }
1587 else
1588 {
91d6fa6a 1589 expressionS exp;
40a18ebd 1590
91d6fa6a 1591 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1592 return FAIL;
40a18ebd 1593
91d6fa6a 1594 if (exp.X_op == O_constant)
c19d1205 1595 {
91d6fa6a
NC
1596 if (exp.X_add_number
1597 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1598 {
1599 inst.error = _("invalid register mask");
1600 return FAIL;
1601 }
a737bd4d 1602
91d6fa6a 1603 if ((range & exp.X_add_number) != 0)
c19d1205 1604 {
91d6fa6a 1605 int regno = range & exp.X_add_number;
a737bd4d 1606
c19d1205
ZW
1607 regno &= -regno;
1608 regno = (1 << regno) - 1;
1609 as_tsktsk
1610 (_("Warning: duplicated register (r%d) in register list"),
1611 regno);
1612 }
a737bd4d 1613
91d6fa6a 1614 range |= exp.X_add_number;
c19d1205
ZW
1615 }
1616 else
1617 {
1618 if (inst.reloc.type != 0)
1619 {
1620 inst.error = _("expression too complex");
1621 return FAIL;
1622 }
a737bd4d 1623
91d6fa6a 1624 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1625 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1626 inst.reloc.pc_rel = 0;
1627 }
1628 }
a737bd4d 1629
c19d1205
ZW
1630 if (*str == '|' || *str == '+')
1631 {
1632 str++;
1633 another_range = 1;
1634 }
a737bd4d 1635 }
c19d1205 1636 while (another_range);
a737bd4d 1637
c19d1205
ZW
1638 *strp = str;
1639 return range;
a737bd4d
NC
1640}
1641
5287ad62
JB
1642/* Types of registers in a list. */
1643
1644enum reg_list_els
1645{
1646 REGLIST_VFP_S,
1647 REGLIST_VFP_D,
1648 REGLIST_NEON_D
1649};
1650
c19d1205
ZW
1651/* Parse a VFP register list. If the string is invalid return FAIL.
1652 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1653 register. Parses registers of type ETYPE.
1654 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1655 - Q registers can be used to specify pairs of D registers
1656 - { } can be omitted from around a singleton register list
1657 FIXME: This is not implemented, as it would require backtracking in
1658 some cases, e.g.:
1659 vtbl.8 d3,d4,d5
1660 This could be done (the meaning isn't really ambiguous), but doesn't
1661 fit in well with the current parsing framework.
dcbf9037
JB
1662 - 32 D registers may be used (also true for VFPv3).
1663 FIXME: Types are ignored in these register lists, which is probably a
1664 bug. */
6057a28f 1665
c19d1205 1666static int
037e8744 1667parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1668{
037e8744 1669 char *str = *ccp;
c19d1205
ZW
1670 int base_reg;
1671 int new_base;
21d799b5 1672 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1673 int max_regs = 0;
c19d1205
ZW
1674 int count = 0;
1675 int warned = 0;
1676 unsigned long mask = 0;
a737bd4d 1677 int i;
6057a28f 1678
037e8744 1679 if (*str != '{')
5287ad62
JB
1680 {
1681 inst.error = _("expecting {");
1682 return FAIL;
1683 }
6057a28f 1684
037e8744 1685 str++;
6057a28f 1686
5287ad62 1687 switch (etype)
c19d1205 1688 {
5287ad62 1689 case REGLIST_VFP_S:
c19d1205
ZW
1690 regtype = REG_TYPE_VFS;
1691 max_regs = 32;
5287ad62 1692 break;
5f4273c7 1693
5287ad62
JB
1694 case REGLIST_VFP_D:
1695 regtype = REG_TYPE_VFD;
b7fc2769 1696 break;
5f4273c7 1697
b7fc2769
JB
1698 case REGLIST_NEON_D:
1699 regtype = REG_TYPE_NDQ;
1700 break;
1701 }
1702
1703 if (etype != REGLIST_VFP_S)
1704 {
b1cc4aeb
PB
1705 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1706 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1707 {
1708 max_regs = 32;
1709 if (thumb_mode)
1710 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1711 fpu_vfp_ext_d32);
5287ad62
JB
1712 else
1713 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1714 fpu_vfp_ext_d32);
5287ad62
JB
1715 }
1716 else
1717 max_regs = 16;
c19d1205 1718 }
6057a28f 1719
c19d1205 1720 base_reg = max_regs;
a737bd4d 1721
c19d1205
ZW
1722 do
1723 {
5287ad62 1724 int setmask = 1, addregs = 1;
dcbf9037 1725
037e8744 1726 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1727
c19d1205 1728 if (new_base == FAIL)
a737bd4d 1729 {
dcbf9037 1730 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1731 return FAIL;
1732 }
5f4273c7 1733
b7fc2769
JB
1734 if (new_base >= max_regs)
1735 {
1736 first_error (_("register out of range in list"));
1737 return FAIL;
1738 }
5f4273c7 1739
5287ad62
JB
1740 /* Note: a value of 2 * n is returned for the register Q<n>. */
1741 if (regtype == REG_TYPE_NQ)
1742 {
1743 setmask = 3;
1744 addregs = 2;
1745 }
1746
c19d1205
ZW
1747 if (new_base < base_reg)
1748 base_reg = new_base;
a737bd4d 1749
5287ad62 1750 if (mask & (setmask << new_base))
c19d1205 1751 {
dcbf9037 1752 first_error (_("invalid register list"));
c19d1205 1753 return FAIL;
a737bd4d 1754 }
a737bd4d 1755
c19d1205
ZW
1756 if ((mask >> new_base) != 0 && ! warned)
1757 {
1758 as_tsktsk (_("register list not in ascending order"));
1759 warned = 1;
1760 }
0bbf2aa4 1761
5287ad62
JB
1762 mask |= setmask << new_base;
1763 count += addregs;
0bbf2aa4 1764
037e8744 1765 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1766 {
1767 int high_range;
0bbf2aa4 1768
037e8744 1769 str++;
0bbf2aa4 1770
037e8744 1771 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1772 == FAIL)
c19d1205
ZW
1773 {
1774 inst.error = gettext (reg_expected_msgs[regtype]);
1775 return FAIL;
1776 }
0bbf2aa4 1777
b7fc2769
JB
1778 if (high_range >= max_regs)
1779 {
1780 first_error (_("register out of range in list"));
1781 return FAIL;
1782 }
1783
5287ad62
JB
1784 if (regtype == REG_TYPE_NQ)
1785 high_range = high_range + 1;
1786
c19d1205
ZW
1787 if (high_range <= new_base)
1788 {
1789 inst.error = _("register range not in ascending order");
1790 return FAIL;
1791 }
0bbf2aa4 1792
5287ad62 1793 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1794 {
5287ad62 1795 if (mask & (setmask << new_base))
0bbf2aa4 1796 {
c19d1205
ZW
1797 inst.error = _("invalid register list");
1798 return FAIL;
0bbf2aa4 1799 }
c19d1205 1800
5287ad62
JB
1801 mask |= setmask << new_base;
1802 count += addregs;
0bbf2aa4 1803 }
0bbf2aa4 1804 }
0bbf2aa4 1805 }
037e8744 1806 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1807
037e8744 1808 str++;
0bbf2aa4 1809
c19d1205
ZW
1810 /* Sanity check -- should have raised a parse error above. */
1811 if (count == 0 || count > max_regs)
1812 abort ();
1813
1814 *pbase = base_reg;
1815
1816 /* Final test -- the registers must be consecutive. */
1817 mask >>= base_reg;
1818 for (i = 0; i < count; i++)
1819 {
1820 if ((mask & (1u << i)) == 0)
1821 {
1822 inst.error = _("non-contiguous register range");
1823 return FAIL;
1824 }
1825 }
1826
037e8744
JB
1827 *ccp = str;
1828
c19d1205 1829 return count;
b99bd4ef
NC
1830}
1831
dcbf9037
JB
1832/* True if two alias types are the same. */
1833
c921be7d 1834static bfd_boolean
dcbf9037
JB
1835neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1836{
1837 if (!a && !b)
c921be7d 1838 return TRUE;
5f4273c7 1839
dcbf9037 1840 if (!a || !b)
c921be7d 1841 return FALSE;
dcbf9037
JB
1842
1843 if (a->defined != b->defined)
c921be7d 1844 return FALSE;
5f4273c7 1845
dcbf9037
JB
1846 if ((a->defined & NTA_HASTYPE) != 0
1847 && (a->eltype.type != b->eltype.type
1848 || a->eltype.size != b->eltype.size))
c921be7d 1849 return FALSE;
dcbf9037
JB
1850
1851 if ((a->defined & NTA_HASINDEX) != 0
1852 && (a->index != b->index))
c921be7d 1853 return FALSE;
5f4273c7 1854
c921be7d 1855 return TRUE;
dcbf9037
JB
1856}
1857
5287ad62
JB
1858/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1859 The base register is put in *PBASE.
dcbf9037 1860 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1861 the return value.
1862 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1863 Bits [6:5] encode the list length (minus one).
1864 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1865
5287ad62 1866#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1867#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1868#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1869
1870static int
dcbf9037
JB
1871parse_neon_el_struct_list (char **str, unsigned *pbase,
1872 struct neon_type_el *eltype)
5287ad62
JB
1873{
1874 char *ptr = *str;
1875 int base_reg = -1;
1876 int reg_incr = -1;
1877 int count = 0;
1878 int lane = -1;
1879 int leading_brace = 0;
1880 enum arm_reg_type rtype = REG_TYPE_NDQ;
1881 int addregs = 1;
20203fb9
NC
1882 const char *const incr_error = _("register stride must be 1 or 2");
1883 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1884 struct neon_typed_alias firsttype;
5f4273c7 1885
5287ad62
JB
1886 if (skip_past_char (&ptr, '{') == SUCCESS)
1887 leading_brace = 1;
5f4273c7 1888
5287ad62
JB
1889 do
1890 {
dcbf9037
JB
1891 struct neon_typed_alias atype;
1892 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1893
5287ad62
JB
1894 if (getreg == FAIL)
1895 {
dcbf9037 1896 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1897 return FAIL;
1898 }
5f4273c7 1899
5287ad62
JB
1900 if (base_reg == -1)
1901 {
1902 base_reg = getreg;
1903 if (rtype == REG_TYPE_NQ)
1904 {
1905 reg_incr = 1;
1906 addregs = 2;
1907 }
dcbf9037 1908 firsttype = atype;
5287ad62
JB
1909 }
1910 else if (reg_incr == -1)
1911 {
1912 reg_incr = getreg - base_reg;
1913 if (reg_incr < 1 || reg_incr > 2)
1914 {
dcbf9037 1915 first_error (_(incr_error));
5287ad62
JB
1916 return FAIL;
1917 }
1918 }
1919 else if (getreg != base_reg + reg_incr * count)
1920 {
dcbf9037
JB
1921 first_error (_(incr_error));
1922 return FAIL;
1923 }
1924
c921be7d 1925 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1926 {
1927 first_error (_(type_error));
5287ad62
JB
1928 return FAIL;
1929 }
5f4273c7 1930
5287ad62
JB
1931 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1932 modes. */
1933 if (ptr[0] == '-')
1934 {
dcbf9037 1935 struct neon_typed_alias htype;
5287ad62
JB
1936 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1937 if (lane == -1)
1938 lane = NEON_INTERLEAVE_LANES;
1939 else if (lane != NEON_INTERLEAVE_LANES)
1940 {
dcbf9037 1941 first_error (_(type_error));
5287ad62
JB
1942 return FAIL;
1943 }
1944 if (reg_incr == -1)
1945 reg_incr = 1;
1946 else if (reg_incr != 1)
1947 {
dcbf9037 1948 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1949 return FAIL;
1950 }
1951 ptr++;
dcbf9037 1952 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1953 if (hireg == FAIL)
1954 {
dcbf9037
JB
1955 first_error (_(reg_expected_msgs[rtype]));
1956 return FAIL;
1957 }
c921be7d 1958 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1959 {
1960 first_error (_(type_error));
5287ad62
JB
1961 return FAIL;
1962 }
1963 count += hireg + dregs - getreg;
1964 continue;
1965 }
5f4273c7 1966
5287ad62
JB
1967 /* If we're using Q registers, we can't use [] or [n] syntax. */
1968 if (rtype == REG_TYPE_NQ)
1969 {
1970 count += 2;
1971 continue;
1972 }
5f4273c7 1973
dcbf9037 1974 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1975 {
dcbf9037
JB
1976 if (lane == -1)
1977 lane = atype.index;
1978 else if (lane != atype.index)
5287ad62 1979 {
dcbf9037
JB
1980 first_error (_(type_error));
1981 return FAIL;
5287ad62
JB
1982 }
1983 }
1984 else if (lane == -1)
1985 lane = NEON_INTERLEAVE_LANES;
1986 else if (lane != NEON_INTERLEAVE_LANES)
1987 {
dcbf9037 1988 first_error (_(type_error));
5287ad62
JB
1989 return FAIL;
1990 }
1991 count++;
1992 }
1993 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1994
5287ad62
JB
1995 /* No lane set by [x]. We must be interleaving structures. */
1996 if (lane == -1)
1997 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1998
5287ad62
JB
1999 /* Sanity check. */
2000 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2001 || (count > 1 && reg_incr == -1))
2002 {
dcbf9037 2003 first_error (_("error parsing element/structure list"));
5287ad62
JB
2004 return FAIL;
2005 }
2006
2007 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2008 {
dcbf9037 2009 first_error (_("expected }"));
5287ad62
JB
2010 return FAIL;
2011 }
5f4273c7 2012
5287ad62
JB
2013 if (reg_incr == -1)
2014 reg_incr = 1;
2015
dcbf9037
JB
2016 if (eltype)
2017 *eltype = firsttype.eltype;
2018
5287ad62
JB
2019 *pbase = base_reg;
2020 *str = ptr;
5f4273c7 2021
5287ad62
JB
2022 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2023}
2024
c19d1205
ZW
2025/* Parse an explicit relocation suffix on an expression. This is
2026 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2027 arm_reloc_hsh contains no entries, so this function can only
2028 succeed if there is no () after the word. Returns -1 on error,
2029 BFD_RELOC_UNUSED if there wasn't any suffix. */
2030static int
2031parse_reloc (char **str)
b99bd4ef 2032{
c19d1205
ZW
2033 struct reloc_entry *r;
2034 char *p, *q;
b99bd4ef 2035
c19d1205
ZW
2036 if (**str != '(')
2037 return BFD_RELOC_UNUSED;
b99bd4ef 2038
c19d1205
ZW
2039 p = *str + 1;
2040 q = p;
2041
2042 while (*q && *q != ')' && *q != ',')
2043 q++;
2044 if (*q != ')')
2045 return -1;
2046
21d799b5
NC
2047 if ((r = (struct reloc_entry *)
2048 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2049 return -1;
2050
2051 *str = q + 1;
2052 return r->reloc;
b99bd4ef
NC
2053}
2054
c19d1205
ZW
2055/* Directives: register aliases. */
2056
dcbf9037 2057static struct reg_entry *
c19d1205 2058insert_reg_alias (char *str, int number, int type)
b99bd4ef 2059{
d3ce72d0 2060 struct reg_entry *new_reg;
c19d1205 2061 const char *name;
b99bd4ef 2062
d3ce72d0 2063 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2064 {
d3ce72d0 2065 if (new_reg->builtin)
c19d1205 2066 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2067
c19d1205
ZW
2068 /* Only warn about a redefinition if it's not defined as the
2069 same register. */
d3ce72d0 2070 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2071 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2072
d929913e 2073 return NULL;
c19d1205 2074 }
b99bd4ef 2075
c19d1205 2076 name = xstrdup (str);
d3ce72d0 2077 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2078
d3ce72d0
NC
2079 new_reg->name = name;
2080 new_reg->number = number;
2081 new_reg->type = type;
2082 new_reg->builtin = FALSE;
2083 new_reg->neon = NULL;
b99bd4ef 2084
d3ce72d0 2085 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2086 abort ();
5f4273c7 2087
d3ce72d0 2088 return new_reg;
dcbf9037
JB
2089}
2090
2091static void
2092insert_neon_reg_alias (char *str, int number, int type,
2093 struct neon_typed_alias *atype)
2094{
2095 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2096
dcbf9037
JB
2097 if (!reg)
2098 {
2099 first_error (_("attempt to redefine typed alias"));
2100 return;
2101 }
5f4273c7 2102
dcbf9037
JB
2103 if (atype)
2104 {
21d799b5
NC
2105 reg->neon = (struct neon_typed_alias *)
2106 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2107 *reg->neon = *atype;
2108 }
c19d1205 2109}
b99bd4ef 2110
c19d1205 2111/* Look for the .req directive. This is of the form:
b99bd4ef 2112
c19d1205 2113 new_register_name .req existing_register_name
b99bd4ef 2114
c19d1205 2115 If we find one, or if it looks sufficiently like one that we want to
d929913e 2116 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2117
d929913e 2118static bfd_boolean
c19d1205
ZW
2119create_register_alias (char * newname, char *p)
2120{
2121 struct reg_entry *old;
2122 char *oldname, *nbuf;
2123 size_t nlen;
b99bd4ef 2124
c19d1205
ZW
2125 /* The input scrubber ensures that whitespace after the mnemonic is
2126 collapsed to single spaces. */
2127 oldname = p;
2128 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2129 return FALSE;
b99bd4ef 2130
c19d1205
ZW
2131 oldname += 6;
2132 if (*oldname == '\0')
d929913e 2133 return FALSE;
b99bd4ef 2134
21d799b5 2135 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2136 if (!old)
b99bd4ef 2137 {
c19d1205 2138 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2139 return TRUE;
b99bd4ef
NC
2140 }
2141
c19d1205
ZW
2142 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2143 the desired alias name, and p points to its end. If not, then
2144 the desired alias name is in the global original_case_string. */
2145#ifdef TC_CASE_SENSITIVE
2146 nlen = p - newname;
2147#else
2148 newname = original_case_string;
2149 nlen = strlen (newname);
2150#endif
b99bd4ef 2151
21d799b5 2152 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2153 memcpy (nbuf, newname, nlen);
2154 nbuf[nlen] = '\0';
b99bd4ef 2155
c19d1205
ZW
2156 /* Create aliases under the new name as stated; an all-lowercase
2157 version of the new name; and an all-uppercase version of the new
2158 name. */
d929913e
NC
2159 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2160 {
2161 for (p = nbuf; *p; p++)
2162 *p = TOUPPER (*p);
c19d1205 2163
d929913e
NC
2164 if (strncmp (nbuf, newname, nlen))
2165 {
2166 /* If this attempt to create an additional alias fails, do not bother
2167 trying to create the all-lower case alias. We will fail and issue
2168 a second, duplicate error message. This situation arises when the
2169 programmer does something like:
2170 foo .req r0
2171 Foo .req r1
2172 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2173 the artificial FOO alias because it has already been created by the
d929913e
NC
2174 first .req. */
2175 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2176 return TRUE;
2177 }
c19d1205 2178
d929913e
NC
2179 for (p = nbuf; *p; p++)
2180 *p = TOLOWER (*p);
c19d1205 2181
d929913e
NC
2182 if (strncmp (nbuf, newname, nlen))
2183 insert_reg_alias (nbuf, old->number, old->type);
2184 }
c19d1205 2185
d929913e 2186 return TRUE;
b99bd4ef
NC
2187}
2188
dcbf9037
JB
2189/* Create a Neon typed/indexed register alias using directives, e.g.:
2190 X .dn d5.s32[1]
2191 Y .qn 6.s16
2192 Z .dn d7
2193 T .dn Z[0]
2194 These typed registers can be used instead of the types specified after the
2195 Neon mnemonic, so long as all operands given have types. Types can also be
2196 specified directly, e.g.:
5f4273c7 2197 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2198
c921be7d 2199static bfd_boolean
dcbf9037
JB
2200create_neon_reg_alias (char *newname, char *p)
2201{
2202 enum arm_reg_type basetype;
2203 struct reg_entry *basereg;
2204 struct reg_entry mybasereg;
2205 struct neon_type ntype;
2206 struct neon_typed_alias typeinfo;
2207 char *namebuf, *nameend;
2208 int namelen;
5f4273c7 2209
dcbf9037
JB
2210 typeinfo.defined = 0;
2211 typeinfo.eltype.type = NT_invtype;
2212 typeinfo.eltype.size = -1;
2213 typeinfo.index = -1;
5f4273c7 2214
dcbf9037 2215 nameend = p;
5f4273c7 2216
dcbf9037
JB
2217 if (strncmp (p, " .dn ", 5) == 0)
2218 basetype = REG_TYPE_VFD;
2219 else if (strncmp (p, " .qn ", 5) == 0)
2220 basetype = REG_TYPE_NQ;
2221 else
c921be7d 2222 return FALSE;
5f4273c7 2223
dcbf9037 2224 p += 5;
5f4273c7 2225
dcbf9037 2226 if (*p == '\0')
c921be7d 2227 return FALSE;
5f4273c7 2228
dcbf9037
JB
2229 basereg = arm_reg_parse_multi (&p);
2230
2231 if (basereg && basereg->type != basetype)
2232 {
2233 as_bad (_("bad type for register"));
c921be7d 2234 return FALSE;
dcbf9037
JB
2235 }
2236
2237 if (basereg == NULL)
2238 {
2239 expressionS exp;
2240 /* Try parsing as an integer. */
2241 my_get_expression (&exp, &p, GE_NO_PREFIX);
2242 if (exp.X_op != O_constant)
2243 {
2244 as_bad (_("expression must be constant"));
c921be7d 2245 return FALSE;
dcbf9037
JB
2246 }
2247 basereg = &mybasereg;
2248 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2249 : exp.X_add_number;
2250 basereg->neon = 0;
2251 }
2252
2253 if (basereg->neon)
2254 typeinfo = *basereg->neon;
2255
2256 if (parse_neon_type (&ntype, &p) == SUCCESS)
2257 {
2258 /* We got a type. */
2259 if (typeinfo.defined & NTA_HASTYPE)
2260 {
2261 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2262 return FALSE;
dcbf9037 2263 }
5f4273c7 2264
dcbf9037
JB
2265 typeinfo.defined |= NTA_HASTYPE;
2266 if (ntype.elems != 1)
2267 {
2268 as_bad (_("you must specify a single type only"));
c921be7d 2269 return FALSE;
dcbf9037
JB
2270 }
2271 typeinfo.eltype = ntype.el[0];
2272 }
5f4273c7 2273
dcbf9037
JB
2274 if (skip_past_char (&p, '[') == SUCCESS)
2275 {
2276 expressionS exp;
2277 /* We got a scalar index. */
5f4273c7 2278
dcbf9037
JB
2279 if (typeinfo.defined & NTA_HASINDEX)
2280 {
2281 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2282 return FALSE;
dcbf9037 2283 }
5f4273c7 2284
dcbf9037 2285 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2286
dcbf9037
JB
2287 if (exp.X_op != O_constant)
2288 {
2289 as_bad (_("scalar index must be constant"));
c921be7d 2290 return FALSE;
dcbf9037 2291 }
5f4273c7 2292
dcbf9037
JB
2293 typeinfo.defined |= NTA_HASINDEX;
2294 typeinfo.index = exp.X_add_number;
5f4273c7 2295
dcbf9037
JB
2296 if (skip_past_char (&p, ']') == FAIL)
2297 {
2298 as_bad (_("expecting ]"));
c921be7d 2299 return FALSE;
dcbf9037
JB
2300 }
2301 }
2302
2303 namelen = nameend - newname;
21d799b5 2304 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2305 strncpy (namebuf, newname, namelen);
2306 namebuf[namelen] = '\0';
5f4273c7 2307
dcbf9037
JB
2308 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2309 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2310
dcbf9037
JB
2311 /* Insert name in all uppercase. */
2312 for (p = namebuf; *p; p++)
2313 *p = TOUPPER (*p);
5f4273c7 2314
dcbf9037
JB
2315 if (strncmp (namebuf, newname, namelen))
2316 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2317 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2318
dcbf9037
JB
2319 /* Insert name in all lowercase. */
2320 for (p = namebuf; *p; p++)
2321 *p = TOLOWER (*p);
5f4273c7 2322
dcbf9037
JB
2323 if (strncmp (namebuf, newname, namelen))
2324 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2325 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2326
c921be7d 2327 return TRUE;
dcbf9037
JB
2328}
2329
c19d1205
ZW
2330/* Should never be called, as .req goes between the alias and the
2331 register name, not at the beginning of the line. */
c921be7d 2332
b99bd4ef 2333static void
c19d1205 2334s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2335{
c19d1205
ZW
2336 as_bad (_("invalid syntax for .req directive"));
2337}
b99bd4ef 2338
dcbf9037
JB
2339static void
2340s_dn (int a ATTRIBUTE_UNUSED)
2341{
2342 as_bad (_("invalid syntax for .dn directive"));
2343}
2344
2345static void
2346s_qn (int a ATTRIBUTE_UNUSED)
2347{
2348 as_bad (_("invalid syntax for .qn directive"));
2349}
2350
c19d1205
ZW
2351/* The .unreq directive deletes an alias which was previously defined
2352 by .req. For example:
b99bd4ef 2353
c19d1205
ZW
2354 my_alias .req r11
2355 .unreq my_alias */
b99bd4ef
NC
2356
2357static void
c19d1205 2358s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2359{
c19d1205
ZW
2360 char * name;
2361 char saved_char;
b99bd4ef 2362
c19d1205
ZW
2363 name = input_line_pointer;
2364
2365 while (*input_line_pointer != 0
2366 && *input_line_pointer != ' '
2367 && *input_line_pointer != '\n')
2368 ++input_line_pointer;
2369
2370 saved_char = *input_line_pointer;
2371 *input_line_pointer = 0;
2372
2373 if (!*name)
2374 as_bad (_("invalid syntax for .unreq directive"));
2375 else
2376 {
21d799b5
NC
2377 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2378 name);
c19d1205
ZW
2379
2380 if (!reg)
2381 as_bad (_("unknown register alias '%s'"), name);
2382 else if (reg->builtin)
2383 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2384 name);
2385 else
2386 {
d929913e
NC
2387 char * p;
2388 char * nbuf;
2389
db0bc284 2390 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2391 free ((char *) reg->name);
dcbf9037
JB
2392 if (reg->neon)
2393 free (reg->neon);
c19d1205 2394 free (reg);
d929913e
NC
2395
2396 /* Also locate the all upper case and all lower case versions.
2397 Do not complain if we cannot find one or the other as it
2398 was probably deleted above. */
5f4273c7 2399
d929913e
NC
2400 nbuf = strdup (name);
2401 for (p = nbuf; *p; p++)
2402 *p = TOUPPER (*p);
21d799b5 2403 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2404 if (reg)
2405 {
db0bc284 2406 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2407 free ((char *) reg->name);
2408 if (reg->neon)
2409 free (reg->neon);
2410 free (reg);
2411 }
2412
2413 for (p = nbuf; *p; p++)
2414 *p = TOLOWER (*p);
21d799b5 2415 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2416 if (reg)
2417 {
db0bc284 2418 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2419 free ((char *) reg->name);
2420 if (reg->neon)
2421 free (reg->neon);
2422 free (reg);
2423 }
2424
2425 free (nbuf);
c19d1205
ZW
2426 }
2427 }
b99bd4ef 2428
c19d1205 2429 *input_line_pointer = saved_char;
b99bd4ef
NC
2430 demand_empty_rest_of_line ();
2431}
2432
c19d1205
ZW
2433/* Directives: Instruction set selection. */
2434
2435#ifdef OBJ_ELF
2436/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2437 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2438 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2439 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2440
cd000bff
DJ
2441/* Create a new mapping symbol for the transition to STATE. */
2442
2443static void
2444make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2445{
a737bd4d 2446 symbolS * symbolP;
c19d1205
ZW
2447 const char * symname;
2448 int type;
b99bd4ef 2449
c19d1205 2450 switch (state)
b99bd4ef 2451 {
c19d1205
ZW
2452 case MAP_DATA:
2453 symname = "$d";
2454 type = BSF_NO_FLAGS;
2455 break;
2456 case MAP_ARM:
2457 symname = "$a";
2458 type = BSF_NO_FLAGS;
2459 break;
2460 case MAP_THUMB:
2461 symname = "$t";
2462 type = BSF_NO_FLAGS;
2463 break;
c19d1205
ZW
2464 default:
2465 abort ();
2466 }
2467
cd000bff 2468 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2469 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2470
2471 switch (state)
2472 {
2473 case MAP_ARM:
2474 THUMB_SET_FUNC (symbolP, 0);
2475 ARM_SET_THUMB (symbolP, 0);
2476 ARM_SET_INTERWORK (symbolP, support_interwork);
2477 break;
2478
2479 case MAP_THUMB:
2480 THUMB_SET_FUNC (symbolP, 1);
2481 ARM_SET_THUMB (symbolP, 1);
2482 ARM_SET_INTERWORK (symbolP, support_interwork);
2483 break;
2484
2485 case MAP_DATA:
2486 default:
cd000bff
DJ
2487 break;
2488 }
2489
2490 /* Save the mapping symbols for future reference. Also check that
2491 we do not place two mapping symbols at the same offset within a
2492 frag. We'll handle overlap between frags in
2493 check_mapping_symbols. */
2494 if (value == 0)
2495 {
2496 know (frag->tc_frag_data.first_map == NULL);
2497 frag->tc_frag_data.first_map = symbolP;
2498 }
2499 if (frag->tc_frag_data.last_map != NULL)
c5ed243b 2500 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
cd000bff
DJ
2501 frag->tc_frag_data.last_map = symbolP;
2502}
2503
2504/* We must sometimes convert a region marked as code to data during
2505 code alignment, if an odd number of bytes have to be padded. The
2506 code mapping symbol is pushed to an aligned address. */
2507
2508static void
2509insert_data_mapping_symbol (enum mstate state,
2510 valueT value, fragS *frag, offsetT bytes)
2511{
2512 /* If there was already a mapping symbol, remove it. */
2513 if (frag->tc_frag_data.last_map != NULL
2514 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2515 {
2516 symbolS *symp = frag->tc_frag_data.last_map;
2517
2518 if (value == 0)
2519 {
2520 know (frag->tc_frag_data.first_map == symp);
2521 frag->tc_frag_data.first_map = NULL;
2522 }
2523 frag->tc_frag_data.last_map = NULL;
2524 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2525 }
cd000bff
DJ
2526
2527 make_mapping_symbol (MAP_DATA, value, frag);
2528 make_mapping_symbol (state, value + bytes, frag);
2529}
2530
2531static void mapping_state_2 (enum mstate state, int max_chars);
2532
2533/* Set the mapping state to STATE. Only call this when about to
2534 emit some STATE bytes to the file. */
2535
2536void
2537mapping_state (enum mstate state)
2538{
940b5ce0
DJ
2539 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2540
cd000bff
DJ
2541#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2542
2543 if (mapstate == state)
2544 /* The mapping symbol has already been emitted.
2545 There is nothing else to do. */
2546 return;
2547 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2548 /* This case will be evaluated later in the next else. */
2549 return;
2550 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2551 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2552 {
2553 /* Only add the symbol if the offset is > 0:
2554 if we're at the first frag, check it's size > 0;
2555 if we're not at the first frag, then for sure
2556 the offset is > 0. */
2557 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2558 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2559
2560 if (add_symbol)
2561 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2562 }
2563
2564 mapping_state_2 (state, 0);
2565#undef TRANSITION
2566}
2567
2568/* Same as mapping_state, but MAX_CHARS bytes have already been
2569 allocated. Put the mapping symbol that far back. */
2570
2571static void
2572mapping_state_2 (enum mstate state, int max_chars)
2573{
940b5ce0
DJ
2574 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2575
2576 if (!SEG_NORMAL (now_seg))
2577 return;
2578
cd000bff
DJ
2579 if (mapstate == state)
2580 /* The mapping symbol has already been emitted.
2581 There is nothing else to do. */
2582 return;
2583
cd000bff
DJ
2584 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2585 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2586}
2587#else
d3106081
NS
2588#define mapping_state(x) ((void)0)
2589#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2590#endif
2591
2592/* Find the real, Thumb encoded start of a Thumb function. */
2593
4343666d 2594#ifdef OBJ_COFF
c19d1205
ZW
2595static symbolS *
2596find_real_start (symbolS * symbolP)
2597{
2598 char * real_start;
2599 const char * name = S_GET_NAME (symbolP);
2600 symbolS * new_target;
2601
2602 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2603#define STUB_NAME ".real_start_of"
2604
2605 if (name == NULL)
2606 abort ();
2607
37f6032b
ZW
2608 /* The compiler may generate BL instructions to local labels because
2609 it needs to perform a branch to a far away location. These labels
2610 do not have a corresponding ".real_start_of" label. We check
2611 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2612 the ".real_start_of" convention for nonlocal branches. */
2613 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2614 return symbolP;
2615
37f6032b 2616 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2617 new_target = symbol_find (real_start);
2618
2619 if (new_target == NULL)
2620 {
bd3ba5d1 2621 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2622 new_target = symbolP;
2623 }
2624
c19d1205
ZW
2625 return new_target;
2626}
4343666d 2627#endif
c19d1205
ZW
2628
2629static void
2630opcode_select (int width)
2631{
2632 switch (width)
2633 {
2634 case 16:
2635 if (! thumb_mode)
2636 {
e74cfd16 2637 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2638 as_bad (_("selected processor does not support THUMB opcodes"));
2639
2640 thumb_mode = 1;
2641 /* No need to force the alignment, since we will have been
2642 coming from ARM mode, which is word-aligned. */
2643 record_alignment (now_seg, 1);
2644 }
c19d1205
ZW
2645 break;
2646
2647 case 32:
2648 if (thumb_mode)
2649 {
e74cfd16 2650 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2651 as_bad (_("selected processor does not support ARM opcodes"));
2652
2653 thumb_mode = 0;
2654
2655 if (!need_pass_2)
2656 frag_align (2, 0, 0);
2657
2658 record_alignment (now_seg, 1);
2659 }
c19d1205
ZW
2660 break;
2661
2662 default:
2663 as_bad (_("invalid instruction size selected (%d)"), width);
2664 }
2665}
2666
2667static void
2668s_arm (int ignore ATTRIBUTE_UNUSED)
2669{
2670 opcode_select (32);
2671 demand_empty_rest_of_line ();
2672}
2673
2674static void
2675s_thumb (int ignore ATTRIBUTE_UNUSED)
2676{
2677 opcode_select (16);
2678 demand_empty_rest_of_line ();
2679}
2680
2681static void
2682s_code (int unused ATTRIBUTE_UNUSED)
2683{
2684 int temp;
2685
2686 temp = get_absolute_expression ();
2687 switch (temp)
2688 {
2689 case 16:
2690 case 32:
2691 opcode_select (temp);
2692 break;
2693
2694 default:
2695 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2696 }
2697}
2698
2699static void
2700s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2701{
2702 /* If we are not already in thumb mode go into it, EVEN if
2703 the target processor does not support thumb instructions.
2704 This is used by gcc/config/arm/lib1funcs.asm for example
2705 to compile interworking support functions even if the
2706 target processor should not support interworking. */
2707 if (! thumb_mode)
2708 {
2709 thumb_mode = 2;
2710 record_alignment (now_seg, 1);
2711 }
2712
2713 demand_empty_rest_of_line ();
2714}
2715
2716static void
2717s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2718{
2719 s_thumb (0);
2720
2721 /* The following label is the name/address of the start of a Thumb function.
2722 We need to know this for the interworking support. */
2723 label_is_thumb_function_name = TRUE;
2724}
2725
2726/* Perform a .set directive, but also mark the alias as
2727 being a thumb function. */
2728
2729static void
2730s_thumb_set (int equiv)
2731{
2732 /* XXX the following is a duplicate of the code for s_set() in read.c
2733 We cannot just call that code as we need to get at the symbol that
2734 is created. */
2735 char * name;
2736 char delim;
2737 char * end_name;
2738 symbolS * symbolP;
2739
2740 /* Especial apologies for the random logic:
2741 This just grew, and could be parsed much more simply!
2742 Dean - in haste. */
2743 name = input_line_pointer;
2744 delim = get_symbol_end ();
2745 end_name = input_line_pointer;
2746 *end_name = delim;
2747
2748 if (*input_line_pointer != ',')
2749 {
2750 *end_name = 0;
2751 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2752 *end_name = delim;
2753 ignore_rest_of_line ();
2754 return;
2755 }
2756
2757 input_line_pointer++;
2758 *end_name = 0;
2759
2760 if (name[0] == '.' && name[1] == '\0')
2761 {
2762 /* XXX - this should not happen to .thumb_set. */
2763 abort ();
2764 }
2765
2766 if ((symbolP = symbol_find (name)) == NULL
2767 && (symbolP = md_undefined_symbol (name)) == NULL)
2768 {
2769#ifndef NO_LISTING
2770 /* When doing symbol listings, play games with dummy fragments living
2771 outside the normal fragment chain to record the file and line info
c19d1205 2772 for this symbol. */
b99bd4ef
NC
2773 if (listing & LISTING_SYMBOLS)
2774 {
2775 extern struct list_info_struct * listing_tail;
21d799b5 2776 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2777
2778 memset (dummy_frag, 0, sizeof (fragS));
2779 dummy_frag->fr_type = rs_fill;
2780 dummy_frag->line = listing_tail;
2781 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2782 dummy_frag->fr_symbol = symbolP;
2783 }
2784 else
2785#endif
2786 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2787
2788#ifdef OBJ_COFF
2789 /* "set" symbols are local unless otherwise specified. */
2790 SF_SET_LOCAL (symbolP);
2791#endif /* OBJ_COFF */
2792 } /* Make a new symbol. */
2793
2794 symbol_table_insert (symbolP);
2795
2796 * end_name = delim;
2797
2798 if (equiv
2799 && S_IS_DEFINED (symbolP)
2800 && S_GET_SEGMENT (symbolP) != reg_section)
2801 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2802
2803 pseudo_set (symbolP);
2804
2805 demand_empty_rest_of_line ();
2806
c19d1205 2807 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2808
2809 THUMB_SET_FUNC (symbolP, 1);
2810 ARM_SET_THUMB (symbolP, 1);
2811#if defined OBJ_ELF || defined OBJ_COFF
2812 ARM_SET_INTERWORK (symbolP, support_interwork);
2813#endif
2814}
2815
c19d1205 2816/* Directives: Mode selection. */
b99bd4ef 2817
c19d1205
ZW
2818/* .syntax [unified|divided] - choose the new unified syntax
2819 (same for Arm and Thumb encoding, modulo slight differences in what
2820 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2821static void
c19d1205 2822s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2823{
c19d1205
ZW
2824 char *name, delim;
2825
2826 name = input_line_pointer;
2827 delim = get_symbol_end ();
2828
2829 if (!strcasecmp (name, "unified"))
2830 unified_syntax = TRUE;
2831 else if (!strcasecmp (name, "divided"))
2832 unified_syntax = FALSE;
2833 else
2834 {
2835 as_bad (_("unrecognized syntax mode \"%s\""), name);
2836 return;
2837 }
2838 *input_line_pointer = delim;
b99bd4ef
NC
2839 demand_empty_rest_of_line ();
2840}
2841
c19d1205
ZW
2842/* Directives: sectioning and alignment. */
2843
2844/* Same as s_align_ptwo but align 0 => align 2. */
2845
b99bd4ef 2846static void
c19d1205 2847s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2848{
a737bd4d 2849 int temp;
dce323d1 2850 bfd_boolean fill_p;
c19d1205
ZW
2851 long temp_fill;
2852 long max_alignment = 15;
b99bd4ef
NC
2853
2854 temp = get_absolute_expression ();
c19d1205
ZW
2855 if (temp > max_alignment)
2856 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2857 else if (temp < 0)
b99bd4ef 2858 {
c19d1205
ZW
2859 as_bad (_("alignment negative. 0 assumed."));
2860 temp = 0;
2861 }
b99bd4ef 2862
c19d1205
ZW
2863 if (*input_line_pointer == ',')
2864 {
2865 input_line_pointer++;
2866 temp_fill = get_absolute_expression ();
dce323d1 2867 fill_p = TRUE;
b99bd4ef 2868 }
c19d1205 2869 else
dce323d1
PB
2870 {
2871 fill_p = FALSE;
2872 temp_fill = 0;
2873 }
b99bd4ef 2874
c19d1205
ZW
2875 if (!temp)
2876 temp = 2;
b99bd4ef 2877
c19d1205
ZW
2878 /* Only make a frag if we HAVE to. */
2879 if (temp && !need_pass_2)
dce323d1
PB
2880 {
2881 if (!fill_p && subseg_text_p (now_seg))
2882 frag_align_code (temp, 0);
2883 else
2884 frag_align (temp, (int) temp_fill, 0);
2885 }
c19d1205
ZW
2886 demand_empty_rest_of_line ();
2887
2888 record_alignment (now_seg, temp);
b99bd4ef
NC
2889}
2890
c19d1205
ZW
2891static void
2892s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2893{
c19d1205
ZW
2894 /* We don't support putting frags in the BSS segment, we fake it by
2895 marking in_bss, then looking at s_skip for clues. */
2896 subseg_set (bss_section, 0);
2897 demand_empty_rest_of_line ();
cd000bff
DJ
2898
2899#ifdef md_elf_section_change_hook
2900 md_elf_section_change_hook ();
2901#endif
c19d1205 2902}
b99bd4ef 2903
c19d1205
ZW
2904static void
2905s_even (int ignore ATTRIBUTE_UNUSED)
2906{
2907 /* Never make frag if expect extra pass. */
2908 if (!need_pass_2)
2909 frag_align (1, 0, 0);
b99bd4ef 2910
c19d1205 2911 record_alignment (now_seg, 1);
b99bd4ef 2912
c19d1205 2913 demand_empty_rest_of_line ();
b99bd4ef
NC
2914}
2915
c19d1205 2916/* Directives: Literal pools. */
a737bd4d 2917
c19d1205
ZW
2918static literal_pool *
2919find_literal_pool (void)
a737bd4d 2920{
c19d1205 2921 literal_pool * pool;
a737bd4d 2922
c19d1205 2923 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2924 {
c19d1205
ZW
2925 if (pool->section == now_seg
2926 && pool->sub_section == now_subseg)
2927 break;
a737bd4d
NC
2928 }
2929
c19d1205 2930 return pool;
a737bd4d
NC
2931}
2932
c19d1205
ZW
2933static literal_pool *
2934find_or_make_literal_pool (void)
a737bd4d 2935{
c19d1205
ZW
2936 /* Next literal pool ID number. */
2937 static unsigned int latest_pool_num = 1;
2938 literal_pool * pool;
a737bd4d 2939
c19d1205 2940 pool = find_literal_pool ();
a737bd4d 2941
c19d1205 2942 if (pool == NULL)
a737bd4d 2943 {
c19d1205 2944 /* Create a new pool. */
21d799b5 2945 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2946 if (! pool)
2947 return NULL;
a737bd4d 2948
c19d1205
ZW
2949 pool->next_free_entry = 0;
2950 pool->section = now_seg;
2951 pool->sub_section = now_subseg;
2952 pool->next = list_of_pools;
2953 pool->symbol = NULL;
2954
2955 /* Add it to the list. */
2956 list_of_pools = pool;
a737bd4d 2957 }
a737bd4d 2958
c19d1205
ZW
2959 /* New pools, and emptied pools, will have a NULL symbol. */
2960 if (pool->symbol == NULL)
a737bd4d 2961 {
c19d1205
ZW
2962 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2963 (valueT) 0, &zero_address_frag);
2964 pool->id = latest_pool_num ++;
a737bd4d
NC
2965 }
2966
c19d1205
ZW
2967 /* Done. */
2968 return pool;
a737bd4d
NC
2969}
2970
c19d1205 2971/* Add the literal in the global 'inst'
5f4273c7 2972 structure to the relevant literal pool. */
b99bd4ef
NC
2973
2974static int
c19d1205 2975add_to_lit_pool (void)
b99bd4ef 2976{
c19d1205
ZW
2977 literal_pool * pool;
2978 unsigned int entry;
b99bd4ef 2979
c19d1205
ZW
2980 pool = find_or_make_literal_pool ();
2981
2982 /* Check if this literal value is already in the pool. */
2983 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2984 {
c19d1205
ZW
2985 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2986 && (inst.reloc.exp.X_op == O_constant)
2987 && (pool->literals[entry].X_add_number
2988 == inst.reloc.exp.X_add_number)
2989 && (pool->literals[entry].X_unsigned
2990 == inst.reloc.exp.X_unsigned))
2991 break;
2992
2993 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2994 && (inst.reloc.exp.X_op == O_symbol)
2995 && (pool->literals[entry].X_add_number
2996 == inst.reloc.exp.X_add_number)
2997 && (pool->literals[entry].X_add_symbol
2998 == inst.reloc.exp.X_add_symbol)
2999 && (pool->literals[entry].X_op_symbol
3000 == inst.reloc.exp.X_op_symbol))
3001 break;
b99bd4ef
NC
3002 }
3003
c19d1205
ZW
3004 /* Do we need to create a new entry? */
3005 if (entry == pool->next_free_entry)
3006 {
3007 if (entry >= MAX_LITERAL_POOL_SIZE)
3008 {
3009 inst.error = _("literal pool overflow");
3010 return FAIL;
3011 }
3012
3013 pool->literals[entry] = inst.reloc.exp;
3014 pool->next_free_entry += 1;
3015 }
b99bd4ef 3016
c19d1205
ZW
3017 inst.reloc.exp.X_op = O_symbol;
3018 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3019 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3020
c19d1205 3021 return SUCCESS;
b99bd4ef
NC
3022}
3023
c19d1205
ZW
3024/* Can't use symbol_new here, so have to create a symbol and then at
3025 a later date assign it a value. Thats what these functions do. */
e16bb312 3026
c19d1205
ZW
3027static void
3028symbol_locate (symbolS * symbolP,
3029 const char * name, /* It is copied, the caller can modify. */
3030 segT segment, /* Segment identifier (SEG_<something>). */
3031 valueT valu, /* Symbol value. */
3032 fragS * frag) /* Associated fragment. */
3033{
3034 unsigned int name_length;
3035 char * preserved_copy_of_name;
e16bb312 3036
c19d1205
ZW
3037 name_length = strlen (name) + 1; /* +1 for \0. */
3038 obstack_grow (&notes, name, name_length);
21d799b5 3039 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3040
c19d1205
ZW
3041#ifdef tc_canonicalize_symbol_name
3042 preserved_copy_of_name =
3043 tc_canonicalize_symbol_name (preserved_copy_of_name);
3044#endif
b99bd4ef 3045
c19d1205 3046 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3047
c19d1205
ZW
3048 S_SET_SEGMENT (symbolP, segment);
3049 S_SET_VALUE (symbolP, valu);
3050 symbol_clear_list_pointers (symbolP);
b99bd4ef 3051
c19d1205 3052 symbol_set_frag (symbolP, frag);
b99bd4ef 3053
c19d1205
ZW
3054 /* Link to end of symbol chain. */
3055 {
3056 extern int symbol_table_frozen;
b99bd4ef 3057
c19d1205
ZW
3058 if (symbol_table_frozen)
3059 abort ();
3060 }
b99bd4ef 3061
c19d1205 3062 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3063
c19d1205 3064 obj_symbol_new_hook (symbolP);
b99bd4ef 3065
c19d1205
ZW
3066#ifdef tc_symbol_new_hook
3067 tc_symbol_new_hook (symbolP);
3068#endif
3069
3070#ifdef DEBUG_SYMS
3071 verify_symbol_chain (symbol_rootP, symbol_lastP);
3072#endif /* DEBUG_SYMS */
b99bd4ef
NC
3073}
3074
b99bd4ef 3075
c19d1205
ZW
3076static void
3077s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3078{
c19d1205
ZW
3079 unsigned int entry;
3080 literal_pool * pool;
3081 char sym_name[20];
b99bd4ef 3082
c19d1205
ZW
3083 pool = find_literal_pool ();
3084 if (pool == NULL
3085 || pool->symbol == NULL
3086 || pool->next_free_entry == 0)
3087 return;
b99bd4ef 3088
c19d1205 3089 mapping_state (MAP_DATA);
b99bd4ef 3090
c19d1205
ZW
3091 /* Align pool as you have word accesses.
3092 Only make a frag if we have to. */
3093 if (!need_pass_2)
3094 frag_align (2, 0, 0);
b99bd4ef 3095
c19d1205 3096 record_alignment (now_seg, 2);
b99bd4ef 3097
c19d1205 3098 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3099
c19d1205
ZW
3100 symbol_locate (pool->symbol, sym_name, now_seg,
3101 (valueT) frag_now_fix (), frag_now);
3102 symbol_table_insert (pool->symbol);
b99bd4ef 3103
c19d1205 3104 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3105
c19d1205
ZW
3106#if defined OBJ_COFF || defined OBJ_ELF
3107 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3108#endif
6c43fab6 3109
c19d1205
ZW
3110 for (entry = 0; entry < pool->next_free_entry; entry ++)
3111 /* First output the expression in the instruction to the pool. */
3112 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3113
c19d1205
ZW
3114 /* Mark the pool as empty. */
3115 pool->next_free_entry = 0;
3116 pool->symbol = NULL;
b99bd4ef
NC
3117}
3118
c19d1205
ZW
3119#ifdef OBJ_ELF
3120/* Forward declarations for functions below, in the MD interface
3121 section. */
3122static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3123static valueT create_unwind_entry (int);
3124static void start_unwind_section (const segT, int);
3125static void add_unwind_opcode (valueT, int);
3126static void flush_pending_unwind (void);
b99bd4ef 3127
c19d1205 3128/* Directives: Data. */
b99bd4ef 3129
c19d1205
ZW
3130static void
3131s_arm_elf_cons (int nbytes)
3132{
3133 expressionS exp;
b99bd4ef 3134
c19d1205
ZW
3135#ifdef md_flush_pending_output
3136 md_flush_pending_output ();
3137#endif
b99bd4ef 3138
c19d1205 3139 if (is_it_end_of_statement ())
b99bd4ef 3140 {
c19d1205
ZW
3141 demand_empty_rest_of_line ();
3142 return;
b99bd4ef
NC
3143 }
3144
c19d1205
ZW
3145#ifdef md_cons_align
3146 md_cons_align (nbytes);
3147#endif
b99bd4ef 3148
c19d1205
ZW
3149 mapping_state (MAP_DATA);
3150 do
b99bd4ef 3151 {
c19d1205
ZW
3152 int reloc;
3153 char *base = input_line_pointer;
b99bd4ef 3154
c19d1205 3155 expression (& exp);
b99bd4ef 3156
c19d1205
ZW
3157 if (exp.X_op != O_symbol)
3158 emit_expr (&exp, (unsigned int) nbytes);
3159 else
3160 {
3161 char *before_reloc = input_line_pointer;
3162 reloc = parse_reloc (&input_line_pointer);
3163 if (reloc == -1)
3164 {
3165 as_bad (_("unrecognized relocation suffix"));
3166 ignore_rest_of_line ();
3167 return;
3168 }
3169 else if (reloc == BFD_RELOC_UNUSED)
3170 emit_expr (&exp, (unsigned int) nbytes);
3171 else
3172 {
21d799b5
NC
3173 reloc_howto_type *howto = (reloc_howto_type *)
3174 bfd_reloc_type_lookup (stdoutput,
3175 (bfd_reloc_code_real_type) reloc);
c19d1205 3176 int size = bfd_get_reloc_size (howto);
b99bd4ef 3177
2fc8bdac
ZW
3178 if (reloc == BFD_RELOC_ARM_PLT32)
3179 {
3180 as_bad (_("(plt) is only valid on branch targets"));
3181 reloc = BFD_RELOC_UNUSED;
3182 size = 0;
3183 }
3184
c19d1205 3185 if (size > nbytes)
2fc8bdac 3186 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3187 howto->name, nbytes);
3188 else
3189 {
3190 /* We've parsed an expression stopping at O_symbol.
3191 But there may be more expression left now that we
3192 have parsed the relocation marker. Parse it again.
3193 XXX Surely there is a cleaner way to do this. */
3194 char *p = input_line_pointer;
3195 int offset;
21d799b5 3196 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3197 memcpy (save_buf, base, input_line_pointer - base);
3198 memmove (base + (input_line_pointer - before_reloc),
3199 base, before_reloc - base);
3200
3201 input_line_pointer = base + (input_line_pointer-before_reloc);
3202 expression (&exp);
3203 memcpy (base, save_buf, p - base);
3204
3205 offset = nbytes - size;
3206 p = frag_more ((int) nbytes);
3207 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3208 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3209 }
3210 }
3211 }
b99bd4ef 3212 }
c19d1205 3213 while (*input_line_pointer++ == ',');
b99bd4ef 3214
c19d1205
ZW
3215 /* Put terminator back into stream. */
3216 input_line_pointer --;
3217 demand_empty_rest_of_line ();
b99bd4ef
NC
3218}
3219
c921be7d
NC
3220/* Emit an expression containing a 32-bit thumb instruction.
3221 Implementation based on put_thumb32_insn. */
3222
3223static void
3224emit_thumb32_expr (expressionS * exp)
3225{
3226 expressionS exp_high = *exp;
3227
3228 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3229 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3230 exp->X_add_number &= 0xffff;
3231 emit_expr (exp, (unsigned int) THUMB_SIZE);
3232}
3233
3234/* Guess the instruction size based on the opcode. */
3235
3236static int
3237thumb_insn_size (int opcode)
3238{
3239 if ((unsigned int) opcode < 0xe800u)
3240 return 2;
3241 else if ((unsigned int) opcode >= 0xe8000000u)
3242 return 4;
3243 else
3244 return 0;
3245}
3246
3247static bfd_boolean
3248emit_insn (expressionS *exp, int nbytes)
3249{
3250 int size = 0;
3251
3252 if (exp->X_op == O_constant)
3253 {
3254 size = nbytes;
3255
3256 if (size == 0)
3257 size = thumb_insn_size (exp->X_add_number);
3258
3259 if (size != 0)
3260 {
3261 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3262 {
3263 as_bad (_(".inst.n operand too big. "\
3264 "Use .inst.w instead"));
3265 size = 0;
3266 }
3267 else
3268 {
3269 if (now_it.state == AUTOMATIC_IT_BLOCK)
3270 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3271 else
3272 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3273
3274 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3275 emit_thumb32_expr (exp);
3276 else
3277 emit_expr (exp, (unsigned int) size);
3278
3279 it_fsm_post_encode ();
3280 }
3281 }
3282 else
3283 as_bad (_("cannot determine Thumb instruction size. " \
3284 "Use .inst.n/.inst.w instead"));
3285 }
3286 else
3287 as_bad (_("constant expression required"));
3288
3289 return (size != 0);
3290}
3291
3292/* Like s_arm_elf_cons but do not use md_cons_align and
3293 set the mapping state to MAP_ARM/MAP_THUMB. */
3294
3295static void
3296s_arm_elf_inst (int nbytes)
3297{
3298 if (is_it_end_of_statement ())
3299 {
3300 demand_empty_rest_of_line ();
3301 return;
3302 }
3303
3304 /* Calling mapping_state () here will not change ARM/THUMB,
3305 but will ensure not to be in DATA state. */
3306
3307 if (thumb_mode)
3308 mapping_state (MAP_THUMB);
3309 else
3310 {
3311 if (nbytes != 0)
3312 {
3313 as_bad (_("width suffixes are invalid in ARM mode"));
3314 ignore_rest_of_line ();
3315 return;
3316 }
3317
3318 nbytes = 4;
3319
3320 mapping_state (MAP_ARM);
3321 }
3322
3323 do
3324 {
3325 expressionS exp;
3326
3327 expression (& exp);
3328
3329 if (! emit_insn (& exp, nbytes))
3330 {
3331 ignore_rest_of_line ();
3332 return;
3333 }
3334 }
3335 while (*input_line_pointer++ == ',');
3336
3337 /* Put terminator back into stream. */
3338 input_line_pointer --;
3339 demand_empty_rest_of_line ();
3340}
b99bd4ef 3341
c19d1205 3342/* Parse a .rel31 directive. */
b99bd4ef 3343
c19d1205
ZW
3344static void
3345s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3346{
3347 expressionS exp;
3348 char *p;
3349 valueT highbit;
b99bd4ef 3350
c19d1205
ZW
3351 highbit = 0;
3352 if (*input_line_pointer == '1')
3353 highbit = 0x80000000;
3354 else if (*input_line_pointer != '0')
3355 as_bad (_("expected 0 or 1"));
b99bd4ef 3356
c19d1205
ZW
3357 input_line_pointer++;
3358 if (*input_line_pointer != ',')
3359 as_bad (_("missing comma"));
3360 input_line_pointer++;
b99bd4ef 3361
c19d1205
ZW
3362#ifdef md_flush_pending_output
3363 md_flush_pending_output ();
3364#endif
b99bd4ef 3365
c19d1205
ZW
3366#ifdef md_cons_align
3367 md_cons_align (4);
3368#endif
b99bd4ef 3369
c19d1205 3370 mapping_state (MAP_DATA);
b99bd4ef 3371
c19d1205 3372 expression (&exp);
b99bd4ef 3373
c19d1205
ZW
3374 p = frag_more (4);
3375 md_number_to_chars (p, highbit, 4);
3376 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3377 BFD_RELOC_ARM_PREL31);
b99bd4ef 3378
c19d1205 3379 demand_empty_rest_of_line ();
b99bd4ef
NC
3380}
3381
c19d1205 3382/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3383
c19d1205 3384/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3385
c19d1205
ZW
3386static void
3387s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3388{
3389 demand_empty_rest_of_line ();
921e5f0a
PB
3390 if (unwind.proc_start)
3391 {
c921be7d 3392 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3393 return;
3394 }
3395
c19d1205
ZW
3396 /* Mark the start of the function. */
3397 unwind.proc_start = expr_build_dot ();
b99bd4ef 3398
c19d1205
ZW
3399 /* Reset the rest of the unwind info. */
3400 unwind.opcode_count = 0;
3401 unwind.table_entry = NULL;
3402 unwind.personality_routine = NULL;
3403 unwind.personality_index = -1;
3404 unwind.frame_size = 0;
3405 unwind.fp_offset = 0;
fdfde340 3406 unwind.fp_reg = REG_SP;
c19d1205
ZW
3407 unwind.fp_used = 0;
3408 unwind.sp_restored = 0;
3409}
b99bd4ef 3410
b99bd4ef 3411
c19d1205
ZW
3412/* Parse a handlerdata directive. Creates the exception handling table entry
3413 for the function. */
b99bd4ef 3414
c19d1205
ZW
3415static void
3416s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3417{
3418 demand_empty_rest_of_line ();
921e5f0a 3419 if (!unwind.proc_start)
c921be7d 3420 as_bad (MISSING_FNSTART);
921e5f0a 3421
c19d1205 3422 if (unwind.table_entry)
6decc662 3423 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3424
c19d1205
ZW
3425 create_unwind_entry (1);
3426}
a737bd4d 3427
c19d1205 3428/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3429
c19d1205
ZW
3430static void
3431s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3432{
3433 long where;
3434 char *ptr;
3435 valueT val;
940b5ce0 3436 unsigned int marked_pr_dependency;
f02232aa 3437
c19d1205 3438 demand_empty_rest_of_line ();
f02232aa 3439
921e5f0a
PB
3440 if (!unwind.proc_start)
3441 {
c921be7d 3442 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3443 return;
3444 }
3445
c19d1205
ZW
3446 /* Add eh table entry. */
3447 if (unwind.table_entry == NULL)
3448 val = create_unwind_entry (0);
3449 else
3450 val = 0;
f02232aa 3451
c19d1205
ZW
3452 /* Add index table entry. This is two words. */
3453 start_unwind_section (unwind.saved_seg, 1);
3454 frag_align (2, 0, 0);
3455 record_alignment (now_seg, 2);
b99bd4ef 3456
c19d1205
ZW
3457 ptr = frag_more (8);
3458 where = frag_now_fix () - 8;
f02232aa 3459
c19d1205
ZW
3460 /* Self relative offset of the function start. */
3461 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3462 BFD_RELOC_ARM_PREL31);
f02232aa 3463
c19d1205
ZW
3464 /* Indicate dependency on EHABI-defined personality routines to the
3465 linker, if it hasn't been done already. */
940b5ce0
DJ
3466 marked_pr_dependency
3467 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3468 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3469 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3470 {
5f4273c7
NC
3471 static const char *const name[] =
3472 {
3473 "__aeabi_unwind_cpp_pr0",
3474 "__aeabi_unwind_cpp_pr1",
3475 "__aeabi_unwind_cpp_pr2"
3476 };
c19d1205
ZW
3477 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3478 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3479 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3480 |= 1 << unwind.personality_index;
c19d1205 3481 }
f02232aa 3482
c19d1205
ZW
3483 if (val)
3484 /* Inline exception table entry. */
3485 md_number_to_chars (ptr + 4, val, 4);
3486 else
3487 /* Self relative offset of the table entry. */
3488 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3489 BFD_RELOC_ARM_PREL31);
f02232aa 3490
c19d1205
ZW
3491 /* Restore the original section. */
3492 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3493
3494 unwind.proc_start = NULL;
c19d1205 3495}
f02232aa 3496
f02232aa 3497
c19d1205 3498/* Parse an unwind_cantunwind directive. */
b99bd4ef 3499
c19d1205
ZW
3500static void
3501s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3502{
3503 demand_empty_rest_of_line ();
921e5f0a 3504 if (!unwind.proc_start)
c921be7d 3505 as_bad (MISSING_FNSTART);
921e5f0a 3506
c19d1205
ZW
3507 if (unwind.personality_routine || unwind.personality_index != -1)
3508 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3509
c19d1205
ZW
3510 unwind.personality_index = -2;
3511}
b99bd4ef 3512
b99bd4ef 3513
c19d1205 3514/* Parse a personalityindex directive. */
b99bd4ef 3515
c19d1205
ZW
3516static void
3517s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3518{
3519 expressionS exp;
b99bd4ef 3520
921e5f0a 3521 if (!unwind.proc_start)
c921be7d 3522 as_bad (MISSING_FNSTART);
921e5f0a 3523
c19d1205
ZW
3524 if (unwind.personality_routine || unwind.personality_index != -1)
3525 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3526
c19d1205 3527 expression (&exp);
b99bd4ef 3528
c19d1205
ZW
3529 if (exp.X_op != O_constant
3530 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3531 {
c19d1205
ZW
3532 as_bad (_("bad personality routine number"));
3533 ignore_rest_of_line ();
3534 return;
b99bd4ef
NC
3535 }
3536
c19d1205 3537 unwind.personality_index = exp.X_add_number;
b99bd4ef 3538
c19d1205
ZW
3539 demand_empty_rest_of_line ();
3540}
e16bb312 3541
e16bb312 3542
c19d1205 3543/* Parse a personality directive. */
e16bb312 3544
c19d1205
ZW
3545static void
3546s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3547{
3548 char *name, *p, c;
a737bd4d 3549
921e5f0a 3550 if (!unwind.proc_start)
c921be7d 3551 as_bad (MISSING_FNSTART);
921e5f0a 3552
c19d1205
ZW
3553 if (unwind.personality_routine || unwind.personality_index != -1)
3554 as_bad (_("duplicate .personality directive"));
a737bd4d 3555
c19d1205
ZW
3556 name = input_line_pointer;
3557 c = get_symbol_end ();
3558 p = input_line_pointer;
3559 unwind.personality_routine = symbol_find_or_make (name);
3560 *p = c;
3561 demand_empty_rest_of_line ();
3562}
e16bb312 3563
e16bb312 3564
c19d1205 3565/* Parse a directive saving core registers. */
e16bb312 3566
c19d1205
ZW
3567static void
3568s_arm_unwind_save_core (void)
e16bb312 3569{
c19d1205
ZW
3570 valueT op;
3571 long range;
3572 int n;
e16bb312 3573
c19d1205
ZW
3574 range = parse_reg_list (&input_line_pointer);
3575 if (range == FAIL)
e16bb312 3576 {
c19d1205
ZW
3577 as_bad (_("expected register list"));
3578 ignore_rest_of_line ();
3579 return;
3580 }
e16bb312 3581
c19d1205 3582 demand_empty_rest_of_line ();
e16bb312 3583
c19d1205
ZW
3584 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3585 into .unwind_save {..., sp...}. We aren't bothered about the value of
3586 ip because it is clobbered by calls. */
3587 if (unwind.sp_restored && unwind.fp_reg == 12
3588 && (range & 0x3000) == 0x1000)
3589 {
3590 unwind.opcode_count--;
3591 unwind.sp_restored = 0;
3592 range = (range | 0x2000) & ~0x1000;
3593 unwind.pending_offset = 0;
3594 }
e16bb312 3595
01ae4198
DJ
3596 /* Pop r4-r15. */
3597 if (range & 0xfff0)
c19d1205 3598 {
01ae4198
DJ
3599 /* See if we can use the short opcodes. These pop a block of up to 8
3600 registers starting with r4, plus maybe r14. */
3601 for (n = 0; n < 8; n++)
3602 {
3603 /* Break at the first non-saved register. */
3604 if ((range & (1 << (n + 4))) == 0)
3605 break;
3606 }
3607 /* See if there are any other bits set. */
3608 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3609 {
3610 /* Use the long form. */
3611 op = 0x8000 | ((range >> 4) & 0xfff);
3612 add_unwind_opcode (op, 2);
3613 }
0dd132b6 3614 else
01ae4198
DJ
3615 {
3616 /* Use the short form. */
3617 if (range & 0x4000)
3618 op = 0xa8; /* Pop r14. */
3619 else
3620 op = 0xa0; /* Do not pop r14. */
3621 op |= (n - 1);
3622 add_unwind_opcode (op, 1);
3623 }
c19d1205 3624 }
0dd132b6 3625
c19d1205
ZW
3626 /* Pop r0-r3. */
3627 if (range & 0xf)
3628 {
3629 op = 0xb100 | (range & 0xf);
3630 add_unwind_opcode (op, 2);
0dd132b6
NC
3631 }
3632
c19d1205
ZW
3633 /* Record the number of bytes pushed. */
3634 for (n = 0; n < 16; n++)
3635 {
3636 if (range & (1 << n))
3637 unwind.frame_size += 4;
3638 }
0dd132b6
NC
3639}
3640
c19d1205
ZW
3641
3642/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3643
3644static void
c19d1205 3645s_arm_unwind_save_fpa (int reg)
b99bd4ef 3646{
c19d1205
ZW
3647 expressionS exp;
3648 int num_regs;
3649 valueT op;
b99bd4ef 3650
c19d1205
ZW
3651 /* Get Number of registers to transfer. */
3652 if (skip_past_comma (&input_line_pointer) != FAIL)
3653 expression (&exp);
3654 else
3655 exp.X_op = O_illegal;
b99bd4ef 3656
c19d1205 3657 if (exp.X_op != O_constant)
b99bd4ef 3658 {
c19d1205
ZW
3659 as_bad (_("expected , <constant>"));
3660 ignore_rest_of_line ();
b99bd4ef
NC
3661 return;
3662 }
3663
c19d1205
ZW
3664 num_regs = exp.X_add_number;
3665
3666 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3667 {
c19d1205
ZW
3668 as_bad (_("number of registers must be in the range [1:4]"));
3669 ignore_rest_of_line ();
b99bd4ef
NC
3670 return;
3671 }
3672
c19d1205 3673 demand_empty_rest_of_line ();
b99bd4ef 3674
c19d1205
ZW
3675 if (reg == 4)
3676 {
3677 /* Short form. */
3678 op = 0xb4 | (num_regs - 1);
3679 add_unwind_opcode (op, 1);
3680 }
b99bd4ef
NC
3681 else
3682 {
c19d1205
ZW
3683 /* Long form. */
3684 op = 0xc800 | (reg << 4) | (num_regs - 1);
3685 add_unwind_opcode (op, 2);
b99bd4ef 3686 }
c19d1205 3687 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3688}
3689
c19d1205 3690
fa073d69
MS
3691/* Parse a directive saving VFP registers for ARMv6 and above. */
3692
3693static void
3694s_arm_unwind_save_vfp_armv6 (void)
3695{
3696 int count;
3697 unsigned int start;
3698 valueT op;
3699 int num_vfpv3_regs = 0;
3700 int num_regs_below_16;
3701
3702 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3703 if (count == FAIL)
3704 {
3705 as_bad (_("expected register list"));
3706 ignore_rest_of_line ();
3707 return;
3708 }
3709
3710 demand_empty_rest_of_line ();
3711
3712 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3713 than FSTMX/FLDMX-style ones). */
3714
3715 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3716 if (start >= 16)
3717 num_vfpv3_regs = count;
3718 else if (start + count > 16)
3719 num_vfpv3_regs = start + count - 16;
3720
3721 if (num_vfpv3_regs > 0)
3722 {
3723 int start_offset = start > 16 ? start - 16 : 0;
3724 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3725 add_unwind_opcode (op, 2);
3726 }
3727
3728 /* Generate opcode for registers numbered in the range 0 .. 15. */
3729 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3730 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3731 if (num_regs_below_16 > 0)
3732 {
3733 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3734 add_unwind_opcode (op, 2);
3735 }
3736
3737 unwind.frame_size += count * 8;
3738}
3739
3740
3741/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3742
3743static void
c19d1205 3744s_arm_unwind_save_vfp (void)
b99bd4ef 3745{
c19d1205 3746 int count;
ca3f61f7 3747 unsigned int reg;
c19d1205 3748 valueT op;
b99bd4ef 3749
5287ad62 3750 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3751 if (count == FAIL)
b99bd4ef 3752 {
c19d1205
ZW
3753 as_bad (_("expected register list"));
3754 ignore_rest_of_line ();
b99bd4ef
NC
3755 return;
3756 }
3757
c19d1205 3758 demand_empty_rest_of_line ();
b99bd4ef 3759
c19d1205 3760 if (reg == 8)
b99bd4ef 3761 {
c19d1205
ZW
3762 /* Short form. */
3763 op = 0xb8 | (count - 1);
3764 add_unwind_opcode (op, 1);
b99bd4ef 3765 }
c19d1205 3766 else
b99bd4ef 3767 {
c19d1205
ZW
3768 /* Long form. */
3769 op = 0xb300 | (reg << 4) | (count - 1);
3770 add_unwind_opcode (op, 2);
b99bd4ef 3771 }
c19d1205
ZW
3772 unwind.frame_size += count * 8 + 4;
3773}
b99bd4ef 3774
b99bd4ef 3775
c19d1205
ZW
3776/* Parse a directive saving iWMMXt data registers. */
3777
3778static void
3779s_arm_unwind_save_mmxwr (void)
3780{
3781 int reg;
3782 int hi_reg;
3783 int i;
3784 unsigned mask = 0;
3785 valueT op;
b99bd4ef 3786
c19d1205
ZW
3787 if (*input_line_pointer == '{')
3788 input_line_pointer++;
b99bd4ef 3789
c19d1205 3790 do
b99bd4ef 3791 {
dcbf9037 3792 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3793
c19d1205 3794 if (reg == FAIL)
b99bd4ef 3795 {
9b7132d3 3796 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3797 goto error;
b99bd4ef
NC
3798 }
3799
c19d1205
ZW
3800 if (mask >> reg)
3801 as_tsktsk (_("register list not in ascending order"));
3802 mask |= 1 << reg;
b99bd4ef 3803
c19d1205
ZW
3804 if (*input_line_pointer == '-')
3805 {
3806 input_line_pointer++;
dcbf9037 3807 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3808 if (hi_reg == FAIL)
3809 {
9b7132d3 3810 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3811 goto error;
3812 }
3813 else if (reg >= hi_reg)
3814 {
3815 as_bad (_("bad register range"));
3816 goto error;
3817 }
3818 for (; reg < hi_reg; reg++)
3819 mask |= 1 << reg;
3820 }
3821 }
3822 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3823
c19d1205
ZW
3824 if (*input_line_pointer == '}')
3825 input_line_pointer++;
b99bd4ef 3826
c19d1205 3827 demand_empty_rest_of_line ();
b99bd4ef 3828
708587a4 3829 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3830 the list. */
3831 flush_pending_unwind ();
b99bd4ef 3832
c19d1205 3833 for (i = 0; i < 16; i++)
b99bd4ef 3834 {
c19d1205
ZW
3835 if (mask & (1 << i))
3836 unwind.frame_size += 8;
b99bd4ef
NC
3837 }
3838
c19d1205
ZW
3839 /* Attempt to combine with a previous opcode. We do this because gcc
3840 likes to output separate unwind directives for a single block of
3841 registers. */
3842 if (unwind.opcode_count > 0)
b99bd4ef 3843 {
c19d1205
ZW
3844 i = unwind.opcodes[unwind.opcode_count - 1];
3845 if ((i & 0xf8) == 0xc0)
3846 {
3847 i &= 7;
3848 /* Only merge if the blocks are contiguous. */
3849 if (i < 6)
3850 {
3851 if ((mask & 0xfe00) == (1 << 9))
3852 {
3853 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3854 unwind.opcode_count--;
3855 }
3856 }
3857 else if (i == 6 && unwind.opcode_count >= 2)
3858 {
3859 i = unwind.opcodes[unwind.opcode_count - 2];
3860 reg = i >> 4;
3861 i &= 0xf;
b99bd4ef 3862
c19d1205
ZW
3863 op = 0xffff << (reg - 1);
3864 if (reg > 0
87a1fd79 3865 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3866 {
3867 op = (1 << (reg + i + 1)) - 1;
3868 op &= ~((1 << reg) - 1);
3869 mask |= op;
3870 unwind.opcode_count -= 2;
3871 }
3872 }
3873 }
b99bd4ef
NC
3874 }
3875
c19d1205
ZW
3876 hi_reg = 15;
3877 /* We want to generate opcodes in the order the registers have been
3878 saved, ie. descending order. */
3879 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3880 {
c19d1205
ZW
3881 /* Save registers in blocks. */
3882 if (reg < 0
3883 || !(mask & (1 << reg)))
3884 {
3885 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3886 preceding block. */
c19d1205
ZW
3887 if (reg != hi_reg)
3888 {
3889 if (reg == 9)
3890 {
3891 /* Short form. */
3892 op = 0xc0 | (hi_reg - 10);
3893 add_unwind_opcode (op, 1);
3894 }
3895 else
3896 {
3897 /* Long form. */
3898 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3899 add_unwind_opcode (op, 2);
3900 }
3901 }
3902 hi_reg = reg - 1;
3903 }
b99bd4ef
NC
3904 }
3905
c19d1205
ZW
3906 return;
3907error:
3908 ignore_rest_of_line ();
b99bd4ef
NC
3909}
3910
3911static void
c19d1205 3912s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3913{
c19d1205
ZW
3914 int reg;
3915 int hi_reg;
3916 unsigned mask = 0;
3917 valueT op;
b99bd4ef 3918
c19d1205
ZW
3919 if (*input_line_pointer == '{')
3920 input_line_pointer++;
b99bd4ef 3921
c19d1205 3922 do
b99bd4ef 3923 {
dcbf9037 3924 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3925
c19d1205
ZW
3926 if (reg == FAIL)
3927 {
9b7132d3 3928 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3929 goto error;
3930 }
b99bd4ef 3931
c19d1205
ZW
3932 reg -= 8;
3933 if (mask >> reg)
3934 as_tsktsk (_("register list not in ascending order"));
3935 mask |= 1 << reg;
b99bd4ef 3936
c19d1205
ZW
3937 if (*input_line_pointer == '-')
3938 {
3939 input_line_pointer++;
dcbf9037 3940 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3941 if (hi_reg == FAIL)
3942 {
9b7132d3 3943 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3944 goto error;
3945 }
3946 else if (reg >= hi_reg)
3947 {
3948 as_bad (_("bad register range"));
3949 goto error;
3950 }
3951 for (; reg < hi_reg; reg++)
3952 mask |= 1 << reg;
3953 }
b99bd4ef 3954 }
c19d1205 3955 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3956
c19d1205
ZW
3957 if (*input_line_pointer == '}')
3958 input_line_pointer++;
b99bd4ef 3959
c19d1205
ZW
3960 demand_empty_rest_of_line ();
3961
708587a4 3962 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3963 the list. */
3964 flush_pending_unwind ();
b99bd4ef 3965
c19d1205 3966 for (reg = 0; reg < 16; reg++)
b99bd4ef 3967 {
c19d1205
ZW
3968 if (mask & (1 << reg))
3969 unwind.frame_size += 4;
b99bd4ef 3970 }
c19d1205
ZW
3971 op = 0xc700 | mask;
3972 add_unwind_opcode (op, 2);
3973 return;
3974error:
3975 ignore_rest_of_line ();
b99bd4ef
NC
3976}
3977
c19d1205 3978
fa073d69
MS
3979/* Parse an unwind_save directive.
3980 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3981
b99bd4ef 3982static void
fa073d69 3983s_arm_unwind_save (int arch_v6)
b99bd4ef 3984{
c19d1205
ZW
3985 char *peek;
3986 struct reg_entry *reg;
3987 bfd_boolean had_brace = FALSE;
b99bd4ef 3988
921e5f0a 3989 if (!unwind.proc_start)
c921be7d 3990 as_bad (MISSING_FNSTART);
921e5f0a 3991
c19d1205
ZW
3992 /* Figure out what sort of save we have. */
3993 peek = input_line_pointer;
b99bd4ef 3994
c19d1205 3995 if (*peek == '{')
b99bd4ef 3996 {
c19d1205
ZW
3997 had_brace = TRUE;
3998 peek++;
b99bd4ef
NC
3999 }
4000
c19d1205 4001 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4002
c19d1205 4003 if (!reg)
b99bd4ef 4004 {
c19d1205
ZW
4005 as_bad (_("register expected"));
4006 ignore_rest_of_line ();
b99bd4ef
NC
4007 return;
4008 }
4009
c19d1205 4010 switch (reg->type)
b99bd4ef 4011 {
c19d1205
ZW
4012 case REG_TYPE_FN:
4013 if (had_brace)
4014 {
4015 as_bad (_("FPA .unwind_save does not take a register list"));
4016 ignore_rest_of_line ();
4017 return;
4018 }
93ac2687 4019 input_line_pointer = peek;
c19d1205 4020 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4021 return;
c19d1205
ZW
4022
4023 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4024 case REG_TYPE_VFD:
4025 if (arch_v6)
4026 s_arm_unwind_save_vfp_armv6 ();
4027 else
4028 s_arm_unwind_save_vfp ();
4029 return;
c19d1205
ZW
4030 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4031 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4032
4033 default:
4034 as_bad (_(".unwind_save does not support this kind of register"));
4035 ignore_rest_of_line ();
b99bd4ef 4036 }
c19d1205 4037}
b99bd4ef 4038
b99bd4ef 4039
c19d1205
ZW
4040/* Parse an unwind_movsp directive. */
4041
4042static void
4043s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4044{
4045 int reg;
4046 valueT op;
4fa3602b 4047 int offset;
c19d1205 4048
921e5f0a 4049 if (!unwind.proc_start)
c921be7d 4050 as_bad (MISSING_FNSTART);
921e5f0a 4051
dcbf9037 4052 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4053 if (reg == FAIL)
b99bd4ef 4054 {
9b7132d3 4055 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4056 ignore_rest_of_line ();
b99bd4ef
NC
4057 return;
4058 }
4fa3602b
PB
4059
4060 /* Optional constant. */
4061 if (skip_past_comma (&input_line_pointer) != FAIL)
4062 {
4063 if (immediate_for_directive (&offset) == FAIL)
4064 return;
4065 }
4066 else
4067 offset = 0;
4068
c19d1205 4069 demand_empty_rest_of_line ();
b99bd4ef 4070
c19d1205 4071 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4072 {
c19d1205 4073 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4074 return;
4075 }
4076
c19d1205
ZW
4077 if (unwind.fp_reg != REG_SP)
4078 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4079
c19d1205
ZW
4080 /* Generate opcode to restore the value. */
4081 op = 0x90 | reg;
4082 add_unwind_opcode (op, 1);
4083
4084 /* Record the information for later. */
4085 unwind.fp_reg = reg;
4fa3602b 4086 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4087 unwind.sp_restored = 1;
b05fe5cf
ZW
4088}
4089
c19d1205
ZW
4090/* Parse an unwind_pad directive. */
4091
b05fe5cf 4092static void
c19d1205 4093s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4094{
c19d1205 4095 int offset;
b05fe5cf 4096
921e5f0a 4097 if (!unwind.proc_start)
c921be7d 4098 as_bad (MISSING_FNSTART);
921e5f0a 4099
c19d1205
ZW
4100 if (immediate_for_directive (&offset) == FAIL)
4101 return;
b99bd4ef 4102
c19d1205
ZW
4103 if (offset & 3)
4104 {
4105 as_bad (_("stack increment must be multiple of 4"));
4106 ignore_rest_of_line ();
4107 return;
4108 }
b99bd4ef 4109
c19d1205
ZW
4110 /* Don't generate any opcodes, just record the details for later. */
4111 unwind.frame_size += offset;
4112 unwind.pending_offset += offset;
4113
4114 demand_empty_rest_of_line ();
4115}
4116
4117/* Parse an unwind_setfp directive. */
4118
4119static void
4120s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4121{
c19d1205
ZW
4122 int sp_reg;
4123 int fp_reg;
4124 int offset;
4125
921e5f0a 4126 if (!unwind.proc_start)
c921be7d 4127 as_bad (MISSING_FNSTART);
921e5f0a 4128
dcbf9037 4129 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4130 if (skip_past_comma (&input_line_pointer) == FAIL)
4131 sp_reg = FAIL;
4132 else
dcbf9037 4133 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4134
c19d1205
ZW
4135 if (fp_reg == FAIL || sp_reg == FAIL)
4136 {
4137 as_bad (_("expected <reg>, <reg>"));
4138 ignore_rest_of_line ();
4139 return;
4140 }
b99bd4ef 4141
c19d1205
ZW
4142 /* Optional constant. */
4143 if (skip_past_comma (&input_line_pointer) != FAIL)
4144 {
4145 if (immediate_for_directive (&offset) == FAIL)
4146 return;
4147 }
4148 else
4149 offset = 0;
a737bd4d 4150
c19d1205 4151 demand_empty_rest_of_line ();
a737bd4d 4152
fdfde340 4153 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4154 {
c19d1205
ZW
4155 as_bad (_("register must be either sp or set by a previous"
4156 "unwind_movsp directive"));
4157 return;
a737bd4d
NC
4158 }
4159
c19d1205
ZW
4160 /* Don't generate any opcodes, just record the information for later. */
4161 unwind.fp_reg = fp_reg;
4162 unwind.fp_used = 1;
fdfde340 4163 if (sp_reg == REG_SP)
c19d1205
ZW
4164 unwind.fp_offset = unwind.frame_size - offset;
4165 else
4166 unwind.fp_offset -= offset;
a737bd4d
NC
4167}
4168
c19d1205
ZW
4169/* Parse an unwind_raw directive. */
4170
4171static void
4172s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4173{
c19d1205 4174 expressionS exp;
708587a4 4175 /* This is an arbitrary limit. */
c19d1205
ZW
4176 unsigned char op[16];
4177 int count;
a737bd4d 4178
921e5f0a 4179 if (!unwind.proc_start)
c921be7d 4180 as_bad (MISSING_FNSTART);
921e5f0a 4181
c19d1205
ZW
4182 expression (&exp);
4183 if (exp.X_op == O_constant
4184 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4185 {
c19d1205
ZW
4186 unwind.frame_size += exp.X_add_number;
4187 expression (&exp);
4188 }
4189 else
4190 exp.X_op = O_illegal;
a737bd4d 4191
c19d1205
ZW
4192 if (exp.X_op != O_constant)
4193 {
4194 as_bad (_("expected <offset>, <opcode>"));
4195 ignore_rest_of_line ();
4196 return;
4197 }
a737bd4d 4198
c19d1205 4199 count = 0;
a737bd4d 4200
c19d1205
ZW
4201 /* Parse the opcode. */
4202 for (;;)
4203 {
4204 if (count >= 16)
4205 {
4206 as_bad (_("unwind opcode too long"));
4207 ignore_rest_of_line ();
a737bd4d 4208 }
c19d1205 4209 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4210 {
c19d1205
ZW
4211 as_bad (_("invalid unwind opcode"));
4212 ignore_rest_of_line ();
4213 return;
a737bd4d 4214 }
c19d1205 4215 op[count++] = exp.X_add_number;
a737bd4d 4216
c19d1205
ZW
4217 /* Parse the next byte. */
4218 if (skip_past_comma (&input_line_pointer) == FAIL)
4219 break;
a737bd4d 4220
c19d1205
ZW
4221 expression (&exp);
4222 }
b99bd4ef 4223
c19d1205
ZW
4224 /* Add the opcode bytes in reverse order. */
4225 while (count--)
4226 add_unwind_opcode (op[count], 1);
b99bd4ef 4227
c19d1205 4228 demand_empty_rest_of_line ();
b99bd4ef 4229}
ee065d83
PB
4230
4231
4232/* Parse a .eabi_attribute directive. */
4233
4234static void
4235s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4236{
ee3c0378
AS
4237 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4238
4239 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4240 attributes_set_explicitly[tag] = 1;
ee065d83 4241}
8463be01 4242#endif /* OBJ_ELF */
ee065d83
PB
4243
4244static void s_arm_arch (int);
7a1d4c38 4245static void s_arm_object_arch (int);
ee065d83
PB
4246static void s_arm_cpu (int);
4247static void s_arm_fpu (int);
b99bd4ef 4248
f0927246
NC
4249#ifdef TE_PE
4250
4251static void
5f4273c7 4252pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4253{
4254 expressionS exp;
4255
4256 do
4257 {
4258 expression (&exp);
4259 if (exp.X_op == O_symbol)
4260 exp.X_op = O_secrel;
4261
4262 emit_expr (&exp, 4);
4263 }
4264 while (*input_line_pointer++ == ',');
4265
4266 input_line_pointer--;
4267 demand_empty_rest_of_line ();
4268}
4269#endif /* TE_PE */
4270
c19d1205
ZW
4271/* This table describes all the machine specific pseudo-ops the assembler
4272 has to support. The fields are:
4273 pseudo-op name without dot
4274 function to call to execute this pseudo-op
4275 Integer arg to pass to the function. */
b99bd4ef 4276
c19d1205 4277const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4278{
c19d1205
ZW
4279 /* Never called because '.req' does not start a line. */
4280 { "req", s_req, 0 },
dcbf9037
JB
4281 /* Following two are likewise never called. */
4282 { "dn", s_dn, 0 },
4283 { "qn", s_qn, 0 },
c19d1205
ZW
4284 { "unreq", s_unreq, 0 },
4285 { "bss", s_bss, 0 },
4286 { "align", s_align, 0 },
4287 { "arm", s_arm, 0 },
4288 { "thumb", s_thumb, 0 },
4289 { "code", s_code, 0 },
4290 { "force_thumb", s_force_thumb, 0 },
4291 { "thumb_func", s_thumb_func, 0 },
4292 { "thumb_set", s_thumb_set, 0 },
4293 { "even", s_even, 0 },
4294 { "ltorg", s_ltorg, 0 },
4295 { "pool", s_ltorg, 0 },
4296 { "syntax", s_syntax, 0 },
8463be01
PB
4297 { "cpu", s_arm_cpu, 0 },
4298 { "arch", s_arm_arch, 0 },
7a1d4c38 4299 { "object_arch", s_arm_object_arch, 0 },
8463be01 4300 { "fpu", s_arm_fpu, 0 },
c19d1205 4301#ifdef OBJ_ELF
c921be7d
NC
4302 { "word", s_arm_elf_cons, 4 },
4303 { "long", s_arm_elf_cons, 4 },
4304 { "inst.n", s_arm_elf_inst, 2 },
4305 { "inst.w", s_arm_elf_inst, 4 },
4306 { "inst", s_arm_elf_inst, 0 },
4307 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4308 { "fnstart", s_arm_unwind_fnstart, 0 },
4309 { "fnend", s_arm_unwind_fnend, 0 },
4310 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4311 { "personality", s_arm_unwind_personality, 0 },
4312 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4313 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4314 { "save", s_arm_unwind_save, 0 },
fa073d69 4315 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4316 { "movsp", s_arm_unwind_movsp, 0 },
4317 { "pad", s_arm_unwind_pad, 0 },
4318 { "setfp", s_arm_unwind_setfp, 0 },
4319 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4320 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4321#else
4322 { "word", cons, 4},
f0927246
NC
4323
4324 /* These are used for dwarf. */
4325 {"2byte", cons, 2},
4326 {"4byte", cons, 4},
4327 {"8byte", cons, 8},
4328 /* These are used for dwarf2. */
4329 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4330 { "loc", dwarf2_directive_loc, 0 },
4331 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4332#endif
4333 { "extend", float_cons, 'x' },
4334 { "ldouble", float_cons, 'x' },
4335 { "packed", float_cons, 'p' },
f0927246
NC
4336#ifdef TE_PE
4337 {"secrel32", pe_directive_secrel, 0},
4338#endif
c19d1205
ZW
4339 { 0, 0, 0 }
4340};
4341\f
4342/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4343
c19d1205
ZW
4344/* Generic immediate-value read function for use in insn parsing.
4345 STR points to the beginning of the immediate (the leading #);
4346 VAL receives the value; if the value is outside [MIN, MAX]
4347 issue an error. PREFIX_OPT is true if the immediate prefix is
4348 optional. */
b99bd4ef 4349
c19d1205
ZW
4350static int
4351parse_immediate (char **str, int *val, int min, int max,
4352 bfd_boolean prefix_opt)
4353{
4354 expressionS exp;
4355 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4356 if (exp.X_op != O_constant)
b99bd4ef 4357 {
c19d1205
ZW
4358 inst.error = _("constant expression required");
4359 return FAIL;
4360 }
b99bd4ef 4361
c19d1205
ZW
4362 if (exp.X_add_number < min || exp.X_add_number > max)
4363 {
4364 inst.error = _("immediate value out of range");
4365 return FAIL;
4366 }
b99bd4ef 4367
c19d1205
ZW
4368 *val = exp.X_add_number;
4369 return SUCCESS;
4370}
b99bd4ef 4371
5287ad62 4372/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4373 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4374 instructions. Puts the result directly in inst.operands[i]. */
4375
4376static int
4377parse_big_immediate (char **str, int i)
4378{
4379 expressionS exp;
4380 char *ptr = *str;
4381
4382 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4383
4384 if (exp.X_op == O_constant)
036dc3f7
PB
4385 {
4386 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4387 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4388 O_constant. We have to be careful not to break compilation for
4389 32-bit X_add_number, though. */
4390 if ((exp.X_add_number & ~0xffffffffl) != 0)
4391 {
4392 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4393 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4394 inst.operands[i].regisimm = 1;
4395 }
4396 }
5287ad62
JB
4397 else if (exp.X_op == O_big
4398 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4399 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4400 {
4401 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4402 /* Bignums have their least significant bits in
4403 generic_bignum[0]. Make sure we put 32 bits in imm and
4404 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4405 gas_assert (parts != 0);
5287ad62
JB
4406 inst.operands[i].imm = 0;
4407 for (j = 0; j < parts; j++, idx++)
4408 inst.operands[i].imm |= generic_bignum[idx]
4409 << (LITTLENUM_NUMBER_OF_BITS * j);
4410 inst.operands[i].reg = 0;
4411 for (j = 0; j < parts; j++, idx++)
4412 inst.operands[i].reg |= generic_bignum[idx]
4413 << (LITTLENUM_NUMBER_OF_BITS * j);
4414 inst.operands[i].regisimm = 1;
4415 }
4416 else
4417 return FAIL;
5f4273c7 4418
5287ad62
JB
4419 *str = ptr;
4420
4421 return SUCCESS;
4422}
4423
c19d1205
ZW
4424/* Returns the pseudo-register number of an FPA immediate constant,
4425 or FAIL if there isn't a valid constant here. */
b99bd4ef 4426
c19d1205
ZW
4427static int
4428parse_fpa_immediate (char ** str)
4429{
4430 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4431 char * save_in;
4432 expressionS exp;
4433 int i;
4434 int j;
b99bd4ef 4435
c19d1205
ZW
4436 /* First try and match exact strings, this is to guarantee
4437 that some formats will work even for cross assembly. */
b99bd4ef 4438
c19d1205
ZW
4439 for (i = 0; fp_const[i]; i++)
4440 {
4441 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4442 {
c19d1205 4443 char *start = *str;
b99bd4ef 4444
c19d1205
ZW
4445 *str += strlen (fp_const[i]);
4446 if (is_end_of_line[(unsigned char) **str])
4447 return i + 8;
4448 *str = start;
4449 }
4450 }
b99bd4ef 4451
c19d1205
ZW
4452 /* Just because we didn't get a match doesn't mean that the constant
4453 isn't valid, just that it is in a format that we don't
4454 automatically recognize. Try parsing it with the standard
4455 expression routines. */
b99bd4ef 4456
c19d1205 4457 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4458
c19d1205
ZW
4459 /* Look for a raw floating point number. */
4460 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4461 && is_end_of_line[(unsigned char) *save_in])
4462 {
4463 for (i = 0; i < NUM_FLOAT_VALS; i++)
4464 {
4465 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4466 {
c19d1205
ZW
4467 if (words[j] != fp_values[i][j])
4468 break;
b99bd4ef
NC
4469 }
4470
c19d1205 4471 if (j == MAX_LITTLENUMS)
b99bd4ef 4472 {
c19d1205
ZW
4473 *str = save_in;
4474 return i + 8;
b99bd4ef
NC
4475 }
4476 }
4477 }
b99bd4ef 4478
c19d1205
ZW
4479 /* Try and parse a more complex expression, this will probably fail
4480 unless the code uses a floating point prefix (eg "0f"). */
4481 save_in = input_line_pointer;
4482 input_line_pointer = *str;
4483 if (expression (&exp) == absolute_section
4484 && exp.X_op == O_big
4485 && exp.X_add_number < 0)
4486 {
4487 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4488 Ditto for 15. */
4489 if (gen_to_words (words, 5, (long) 15) == 0)
4490 {
4491 for (i = 0; i < NUM_FLOAT_VALS; i++)
4492 {
4493 for (j = 0; j < MAX_LITTLENUMS; j++)
4494 {
4495 if (words[j] != fp_values[i][j])
4496 break;
4497 }
b99bd4ef 4498
c19d1205
ZW
4499 if (j == MAX_LITTLENUMS)
4500 {
4501 *str = input_line_pointer;
4502 input_line_pointer = save_in;
4503 return i + 8;
4504 }
4505 }
4506 }
b99bd4ef
NC
4507 }
4508
c19d1205
ZW
4509 *str = input_line_pointer;
4510 input_line_pointer = save_in;
4511 inst.error = _("invalid FPA immediate expression");
4512 return FAIL;
b99bd4ef
NC
4513}
4514
136da414
JB
4515/* Returns 1 if a number has "quarter-precision" float format
4516 0baBbbbbbc defgh000 00000000 00000000. */
4517
4518static int
4519is_quarter_float (unsigned imm)
4520{
4521 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4522 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4523}
4524
4525/* Parse an 8-bit "quarter-precision" floating point number of the form:
4526 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4527 The zero and minus-zero cases need special handling, since they can't be
4528 encoded in the "quarter-precision" float format, but can nonetheless be
4529 loaded as integer constants. */
136da414
JB
4530
4531static unsigned
4532parse_qfloat_immediate (char **ccp, int *immed)
4533{
4534 char *str = *ccp;
c96612cc 4535 char *fpnum;
136da414 4536 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4537 int found_fpchar = 0;
5f4273c7 4538
136da414 4539 skip_past_char (&str, '#');
5f4273c7 4540
c96612cc
JB
4541 /* We must not accidentally parse an integer as a floating-point number. Make
4542 sure that the value we parse is not an integer by checking for special
4543 characters '.' or 'e'.
4544 FIXME: This is a horrible hack, but doing better is tricky because type
4545 information isn't in a very usable state at parse time. */
4546 fpnum = str;
4547 skip_whitespace (fpnum);
4548
4549 if (strncmp (fpnum, "0x", 2) == 0)
4550 return FAIL;
4551 else
4552 {
4553 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4554 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4555 {
4556 found_fpchar = 1;
4557 break;
4558 }
4559
4560 if (!found_fpchar)
4561 return FAIL;
4562 }
5f4273c7 4563
136da414
JB
4564 if ((str = atof_ieee (str, 's', words)) != NULL)
4565 {
4566 unsigned fpword = 0;
4567 int i;
5f4273c7 4568
136da414
JB
4569 /* Our FP word must be 32 bits (single-precision FP). */
4570 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4571 {
4572 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4573 fpword |= words[i];
4574 }
5f4273c7 4575
c96612cc 4576 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4577 *immed = fpword;
4578 else
4579 return FAIL;
4580
4581 *ccp = str;
5f4273c7 4582
136da414
JB
4583 return SUCCESS;
4584 }
5f4273c7 4585
136da414
JB
4586 return FAIL;
4587}
4588
c19d1205
ZW
4589/* Shift operands. */
4590enum shift_kind
b99bd4ef 4591{
c19d1205
ZW
4592 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4593};
b99bd4ef 4594
c19d1205
ZW
4595struct asm_shift_name
4596{
4597 const char *name;
4598 enum shift_kind kind;
4599};
b99bd4ef 4600
c19d1205
ZW
4601/* Third argument to parse_shift. */
4602enum parse_shift_mode
4603{
4604 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4605 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4606 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4607 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4608 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4609};
b99bd4ef 4610
c19d1205
ZW
4611/* Parse a <shift> specifier on an ARM data processing instruction.
4612 This has three forms:
b99bd4ef 4613
c19d1205
ZW
4614 (LSL|LSR|ASL|ASR|ROR) Rs
4615 (LSL|LSR|ASL|ASR|ROR) #imm
4616 RRX
b99bd4ef 4617
c19d1205
ZW
4618 Note that ASL is assimilated to LSL in the instruction encoding, and
4619 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4620
c19d1205
ZW
4621static int
4622parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4623{
c19d1205
ZW
4624 const struct asm_shift_name *shift_name;
4625 enum shift_kind shift;
4626 char *s = *str;
4627 char *p = s;
4628 int reg;
b99bd4ef 4629
c19d1205
ZW
4630 for (p = *str; ISALPHA (*p); p++)
4631 ;
b99bd4ef 4632
c19d1205 4633 if (p == *str)
b99bd4ef 4634 {
c19d1205
ZW
4635 inst.error = _("shift expression expected");
4636 return FAIL;
b99bd4ef
NC
4637 }
4638
21d799b5
NC
4639 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4640 p - *str);
c19d1205
ZW
4641
4642 if (shift_name == NULL)
b99bd4ef 4643 {
c19d1205
ZW
4644 inst.error = _("shift expression expected");
4645 return FAIL;
b99bd4ef
NC
4646 }
4647
c19d1205 4648 shift = shift_name->kind;
b99bd4ef 4649
c19d1205
ZW
4650 switch (mode)
4651 {
4652 case NO_SHIFT_RESTRICT:
4653 case SHIFT_IMMEDIATE: break;
b99bd4ef 4654
c19d1205
ZW
4655 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4656 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4657 {
4658 inst.error = _("'LSL' or 'ASR' required");
4659 return FAIL;
4660 }
4661 break;
b99bd4ef 4662
c19d1205
ZW
4663 case SHIFT_LSL_IMMEDIATE:
4664 if (shift != SHIFT_LSL)
4665 {
4666 inst.error = _("'LSL' required");
4667 return FAIL;
4668 }
4669 break;
b99bd4ef 4670
c19d1205
ZW
4671 case SHIFT_ASR_IMMEDIATE:
4672 if (shift != SHIFT_ASR)
4673 {
4674 inst.error = _("'ASR' required");
4675 return FAIL;
4676 }
4677 break;
b99bd4ef 4678
c19d1205
ZW
4679 default: abort ();
4680 }
b99bd4ef 4681
c19d1205
ZW
4682 if (shift != SHIFT_RRX)
4683 {
4684 /* Whitespace can appear here if the next thing is a bare digit. */
4685 skip_whitespace (p);
b99bd4ef 4686
c19d1205 4687 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4688 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4689 {
4690 inst.operands[i].imm = reg;
4691 inst.operands[i].immisreg = 1;
4692 }
4693 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4694 return FAIL;
4695 }
4696 inst.operands[i].shift_kind = shift;
4697 inst.operands[i].shifted = 1;
4698 *str = p;
4699 return SUCCESS;
b99bd4ef
NC
4700}
4701
c19d1205 4702/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4703
c19d1205
ZW
4704 #<immediate>
4705 #<immediate>, <rotate>
4706 <Rm>
4707 <Rm>, <shift>
b99bd4ef 4708
c19d1205
ZW
4709 where <shift> is defined by parse_shift above, and <rotate> is a
4710 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4711 is deferred to md_apply_fix. */
b99bd4ef 4712
c19d1205
ZW
4713static int
4714parse_shifter_operand (char **str, int i)
4715{
4716 int value;
91d6fa6a 4717 expressionS exp;
b99bd4ef 4718
dcbf9037 4719 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4720 {
4721 inst.operands[i].reg = value;
4722 inst.operands[i].isreg = 1;
b99bd4ef 4723
c19d1205
ZW
4724 /* parse_shift will override this if appropriate */
4725 inst.reloc.exp.X_op = O_constant;
4726 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4727
c19d1205
ZW
4728 if (skip_past_comma (str) == FAIL)
4729 return SUCCESS;
b99bd4ef 4730
c19d1205
ZW
4731 /* Shift operation on register. */
4732 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4733 }
4734
c19d1205
ZW
4735 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4736 return FAIL;
b99bd4ef 4737
c19d1205 4738 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4739 {
c19d1205 4740 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4741 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4742 return FAIL;
b99bd4ef 4743
91d6fa6a 4744 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4745 {
4746 inst.error = _("constant expression expected");
4747 return FAIL;
4748 }
b99bd4ef 4749
91d6fa6a 4750 value = exp.X_add_number;
c19d1205
ZW
4751 if (value < 0 || value > 30 || value % 2 != 0)
4752 {
4753 inst.error = _("invalid rotation");
4754 return FAIL;
4755 }
4756 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4757 {
4758 inst.error = _("invalid constant");
4759 return FAIL;
4760 }
09d92015 4761
55cf6793 4762 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4763 inst.reloc.exp.X_add_number
4764 = (((inst.reloc.exp.X_add_number << (32 - value))
4765 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4766 }
4767
c19d1205
ZW
4768 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4769 inst.reloc.pc_rel = 0;
4770 return SUCCESS;
09d92015
MM
4771}
4772
4962c51a
MS
4773/* Group relocation information. Each entry in the table contains the
4774 textual name of the relocation as may appear in assembler source
4775 and must end with a colon.
4776 Along with this textual name are the relocation codes to be used if
4777 the corresponding instruction is an ALU instruction (ADD or SUB only),
4778 an LDR, an LDRS, or an LDC. */
4779
4780struct group_reloc_table_entry
4781{
4782 const char *name;
4783 int alu_code;
4784 int ldr_code;
4785 int ldrs_code;
4786 int ldc_code;
4787};
4788
4789typedef enum
4790{
4791 /* Varieties of non-ALU group relocation. */
4792
4793 GROUP_LDR,
4794 GROUP_LDRS,
4795 GROUP_LDC
4796} group_reloc_type;
4797
4798static struct group_reloc_table_entry group_reloc_table[] =
4799 { /* Program counter relative: */
4800 { "pc_g0_nc",
4801 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4802 0, /* LDR */
4803 0, /* LDRS */
4804 0 }, /* LDC */
4805 { "pc_g0",
4806 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4807 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4808 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4809 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4810 { "pc_g1_nc",
4811 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4812 0, /* LDR */
4813 0, /* LDRS */
4814 0 }, /* LDC */
4815 { "pc_g1",
4816 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4817 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4818 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4819 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4820 { "pc_g2",
4821 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4822 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4823 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4824 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4825 /* Section base relative */
4826 { "sb_g0_nc",
4827 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4828 0, /* LDR */
4829 0, /* LDRS */
4830 0 }, /* LDC */
4831 { "sb_g0",
4832 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4833 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4834 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4835 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4836 { "sb_g1_nc",
4837 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4838 0, /* LDR */
4839 0, /* LDRS */
4840 0 }, /* LDC */
4841 { "sb_g1",
4842 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4843 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4844 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4845 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4846 { "sb_g2",
4847 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4848 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4849 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4850 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4851
4852/* Given the address of a pointer pointing to the textual name of a group
4853 relocation as may appear in assembler source, attempt to find its details
4854 in group_reloc_table. The pointer will be updated to the character after
4855 the trailing colon. On failure, FAIL will be returned; SUCCESS
4856 otherwise. On success, *entry will be updated to point at the relevant
4857 group_reloc_table entry. */
4858
4859static int
4860find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4861{
4862 unsigned int i;
4863 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4864 {
4865 int length = strlen (group_reloc_table[i].name);
4866
5f4273c7
NC
4867 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4868 && (*str)[length] == ':')
4962c51a
MS
4869 {
4870 *out = &group_reloc_table[i];
4871 *str += (length + 1);
4872 return SUCCESS;
4873 }
4874 }
4875
4876 return FAIL;
4877}
4878
4879/* Parse a <shifter_operand> for an ARM data processing instruction
4880 (as for parse_shifter_operand) where group relocations are allowed:
4881
4882 #<immediate>
4883 #<immediate>, <rotate>
4884 #:<group_reloc>:<expression>
4885 <Rm>
4886 <Rm>, <shift>
4887
4888 where <group_reloc> is one of the strings defined in group_reloc_table.
4889 The hashes are optional.
4890
4891 Everything else is as for parse_shifter_operand. */
4892
4893static parse_operand_result
4894parse_shifter_operand_group_reloc (char **str, int i)
4895{
4896 /* Determine if we have the sequence of characters #: or just :
4897 coming next. If we do, then we check for a group relocation.
4898 If we don't, punt the whole lot to parse_shifter_operand. */
4899
4900 if (((*str)[0] == '#' && (*str)[1] == ':')
4901 || (*str)[0] == ':')
4902 {
4903 struct group_reloc_table_entry *entry;
4904
4905 if ((*str)[0] == '#')
4906 (*str) += 2;
4907 else
4908 (*str)++;
4909
4910 /* Try to parse a group relocation. Anything else is an error. */
4911 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4912 {
4913 inst.error = _("unknown group relocation");
4914 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4915 }
4916
4917 /* We now have the group relocation table entry corresponding to
4918 the name in the assembler source. Next, we parse the expression. */
4919 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4920 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4921
4922 /* Record the relocation type (always the ALU variant here). */
21d799b5 4923 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4924 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4925
4926 return PARSE_OPERAND_SUCCESS;
4927 }
4928 else
4929 return parse_shifter_operand (str, i) == SUCCESS
4930 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4931
4932 /* Never reached. */
4933}
4934
c19d1205
ZW
4935/* Parse all forms of an ARM address expression. Information is written
4936 to inst.operands[i] and/or inst.reloc.
09d92015 4937
c19d1205 4938 Preindexed addressing (.preind=1):
09d92015 4939
c19d1205
ZW
4940 [Rn, #offset] .reg=Rn .reloc.exp=offset
4941 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4942 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4943 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4944
c19d1205 4945 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4946
c19d1205 4947 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4948
c19d1205
ZW
4949 [Rn], #offset .reg=Rn .reloc.exp=offset
4950 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4951 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4952 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4953
c19d1205 4954 Unindexed addressing (.preind=0, .postind=0):
09d92015 4955
c19d1205 4956 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4957
c19d1205 4958 Other:
09d92015 4959
c19d1205
ZW
4960 [Rn]{!} shorthand for [Rn,#0]{!}
4961 =immediate .isreg=0 .reloc.exp=immediate
4962 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4963
c19d1205
ZW
4964 It is the caller's responsibility to check for addressing modes not
4965 supported by the instruction, and to set inst.reloc.type. */
4966
4962c51a
MS
4967static parse_operand_result
4968parse_address_main (char **str, int i, int group_relocations,
4969 group_reloc_type group_type)
09d92015 4970{
c19d1205
ZW
4971 char *p = *str;
4972 int reg;
09d92015 4973
c19d1205 4974 if (skip_past_char (&p, '[') == FAIL)
09d92015 4975 {
c19d1205
ZW
4976 if (skip_past_char (&p, '=') == FAIL)
4977 {
974da60d 4978 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
4979 inst.reloc.pc_rel = 1;
4980 inst.operands[i].reg = REG_PC;
4981 inst.operands[i].isreg = 1;
4982 inst.operands[i].preind = 1;
4983 }
974da60d 4984 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 4985
c19d1205 4986 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4987 return PARSE_OPERAND_FAIL;
09d92015 4988
c19d1205 4989 *str = p;
4962c51a 4990 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4991 }
4992
dcbf9037 4993 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4994 {
c19d1205 4995 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4996 return PARSE_OPERAND_FAIL;
09d92015 4997 }
c19d1205
ZW
4998 inst.operands[i].reg = reg;
4999 inst.operands[i].isreg = 1;
09d92015 5000
c19d1205 5001 if (skip_past_comma (&p) == SUCCESS)
09d92015 5002 {
c19d1205 5003 inst.operands[i].preind = 1;
09d92015 5004
c19d1205
ZW
5005 if (*p == '+') p++;
5006 else if (*p == '-') p++, inst.operands[i].negative = 1;
5007
dcbf9037 5008 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5009 {
c19d1205
ZW
5010 inst.operands[i].imm = reg;
5011 inst.operands[i].immisreg = 1;
5012
5013 if (skip_past_comma (&p) == SUCCESS)
5014 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5015 return PARSE_OPERAND_FAIL;
c19d1205 5016 }
5287ad62
JB
5017 else if (skip_past_char (&p, ':') == SUCCESS)
5018 {
5019 /* FIXME: '@' should be used here, but it's filtered out by generic
5020 code before we get to see it here. This may be subject to
5021 change. */
5022 expressionS exp;
5023 my_get_expression (&exp, &p, GE_NO_PREFIX);
5024 if (exp.X_op != O_constant)
5025 {
5026 inst.error = _("alignment must be constant");
4962c51a 5027 return PARSE_OPERAND_FAIL;
5287ad62
JB
5028 }
5029 inst.operands[i].imm = exp.X_add_number << 8;
5030 inst.operands[i].immisalign = 1;
5031 /* Alignments are not pre-indexes. */
5032 inst.operands[i].preind = 0;
5033 }
c19d1205
ZW
5034 else
5035 {
5036 if (inst.operands[i].negative)
5037 {
5038 inst.operands[i].negative = 0;
5039 p--;
5040 }
4962c51a 5041
5f4273c7
NC
5042 if (group_relocations
5043 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5044 {
5045 struct group_reloc_table_entry *entry;
5046
5047 /* Skip over the #: or : sequence. */
5048 if (*p == '#')
5049 p += 2;
5050 else
5051 p++;
5052
5053 /* Try to parse a group relocation. Anything else is an
5054 error. */
5055 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5056 {
5057 inst.error = _("unknown group relocation");
5058 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5059 }
5060
5061 /* We now have the group relocation table entry corresponding to
5062 the name in the assembler source. Next, we parse the
5063 expression. */
5064 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5065 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5066
5067 /* Record the relocation type. */
5068 switch (group_type)
5069 {
5070 case GROUP_LDR:
21d799b5 5071 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5072 break;
5073
5074 case GROUP_LDRS:
21d799b5 5075 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5076 break;
5077
5078 case GROUP_LDC:
21d799b5 5079 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5080 break;
5081
5082 default:
9c2799c2 5083 gas_assert (0);
4962c51a
MS
5084 }
5085
5086 if (inst.reloc.type == 0)
5087 {
5088 inst.error = _("this group relocation is not allowed on this instruction");
5089 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5090 }
5091 }
5092 else
5093 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5094 return PARSE_OPERAND_FAIL;
09d92015
MM
5095 }
5096 }
5097
c19d1205 5098 if (skip_past_char (&p, ']') == FAIL)
09d92015 5099 {
c19d1205 5100 inst.error = _("']' expected");
4962c51a 5101 return PARSE_OPERAND_FAIL;
09d92015
MM
5102 }
5103
c19d1205
ZW
5104 if (skip_past_char (&p, '!') == SUCCESS)
5105 inst.operands[i].writeback = 1;
09d92015 5106
c19d1205 5107 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5108 {
c19d1205
ZW
5109 if (skip_past_char (&p, '{') == SUCCESS)
5110 {
5111 /* [Rn], {expr} - unindexed, with option */
5112 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5113 0, 255, TRUE) == FAIL)
4962c51a 5114 return PARSE_OPERAND_FAIL;
09d92015 5115
c19d1205
ZW
5116 if (skip_past_char (&p, '}') == FAIL)
5117 {
5118 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5119 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5120 }
5121 if (inst.operands[i].preind)
5122 {
5123 inst.error = _("cannot combine index with option");
4962c51a 5124 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5125 }
5126 *str = p;
4962c51a 5127 return PARSE_OPERAND_SUCCESS;
09d92015 5128 }
c19d1205
ZW
5129 else
5130 {
5131 inst.operands[i].postind = 1;
5132 inst.operands[i].writeback = 1;
09d92015 5133
c19d1205
ZW
5134 if (inst.operands[i].preind)
5135 {
5136 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5137 return PARSE_OPERAND_FAIL;
c19d1205 5138 }
09d92015 5139
c19d1205
ZW
5140 if (*p == '+') p++;
5141 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5142
dcbf9037 5143 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5144 {
5287ad62
JB
5145 /* We might be using the immediate for alignment already. If we
5146 are, OR the register number into the low-order bits. */
5147 if (inst.operands[i].immisalign)
5148 inst.operands[i].imm |= reg;
5149 else
5150 inst.operands[i].imm = reg;
c19d1205 5151 inst.operands[i].immisreg = 1;
a737bd4d 5152
c19d1205
ZW
5153 if (skip_past_comma (&p) == SUCCESS)
5154 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5155 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5156 }
5157 else
5158 {
5159 if (inst.operands[i].negative)
5160 {
5161 inst.operands[i].negative = 0;
5162 p--;
5163 }
5164 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5165 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5166 }
5167 }
a737bd4d
NC
5168 }
5169
c19d1205
ZW
5170 /* If at this point neither .preind nor .postind is set, we have a
5171 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5172 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5173 {
5174 inst.operands[i].preind = 1;
5175 inst.reloc.exp.X_op = O_constant;
5176 inst.reloc.exp.X_add_number = 0;
5177 }
5178 *str = p;
4962c51a
MS
5179 return PARSE_OPERAND_SUCCESS;
5180}
5181
5182static int
5183parse_address (char **str, int i)
5184{
21d799b5 5185 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5186 ? SUCCESS : FAIL;
5187}
5188
5189static parse_operand_result
5190parse_address_group_reloc (char **str, int i, group_reloc_type type)
5191{
5192 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5193}
5194
b6895b4f
PB
5195/* Parse an operand for a MOVW or MOVT instruction. */
5196static int
5197parse_half (char **str)
5198{
5199 char * p;
5f4273c7 5200
b6895b4f
PB
5201 p = *str;
5202 skip_past_char (&p, '#');
5f4273c7 5203 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5204 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5205 else if (strncasecmp (p, ":upper16:", 9) == 0)
5206 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5207
5208 if (inst.reloc.type != BFD_RELOC_UNUSED)
5209 {
5210 p += 9;
5f4273c7 5211 skip_whitespace (p);
b6895b4f
PB
5212 }
5213
5214 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5215 return FAIL;
5216
5217 if (inst.reloc.type == BFD_RELOC_UNUSED)
5218 {
5219 if (inst.reloc.exp.X_op != O_constant)
5220 {
5221 inst.error = _("constant expression expected");
5222 return FAIL;
5223 }
5224 if (inst.reloc.exp.X_add_number < 0
5225 || inst.reloc.exp.X_add_number > 0xffff)
5226 {
5227 inst.error = _("immediate value out of range");
5228 return FAIL;
5229 }
5230 }
5231 *str = p;
5232 return SUCCESS;
5233}
5234
c19d1205 5235/* Miscellaneous. */
a737bd4d 5236
c19d1205
ZW
5237/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5238 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5239static int
5240parse_psr (char **str)
09d92015 5241{
c19d1205
ZW
5242 char *p;
5243 unsigned long psr_field;
62b3e311
PB
5244 const struct asm_psr *psr;
5245 char *start;
09d92015 5246
c19d1205
ZW
5247 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5248 feature for ease of use and backwards compatibility. */
5249 p = *str;
62b3e311 5250 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5251 psr_field = SPSR_BIT;
62b3e311 5252 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5253 psr_field = 0;
5254 else
62b3e311
PB
5255 {
5256 start = p;
5257 do
5258 p++;
5259 while (ISALNUM (*p) || *p == '_');
5260
21d799b5
NC
5261 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5262 p - start);
62b3e311
PB
5263 if (!psr)
5264 return FAIL;
09d92015 5265
62b3e311
PB
5266 *str = p;
5267 return psr->field;
5268 }
09d92015 5269
62b3e311 5270 p += 4;
c19d1205
ZW
5271 if (*p == '_')
5272 {
5273 /* A suffix follows. */
c19d1205
ZW
5274 p++;
5275 start = p;
a737bd4d 5276
c19d1205
ZW
5277 do
5278 p++;
5279 while (ISALNUM (*p) || *p == '_');
a737bd4d 5280
21d799b5
NC
5281 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5282 p - start);
c19d1205
ZW
5283 if (!psr)
5284 goto error;
a737bd4d 5285
c19d1205 5286 psr_field |= psr->field;
a737bd4d 5287 }
c19d1205 5288 else
a737bd4d 5289 {
c19d1205
ZW
5290 if (ISALNUM (*p))
5291 goto error; /* Garbage after "[CS]PSR". */
5292
5293 psr_field |= (PSR_c | PSR_f);
a737bd4d 5294 }
c19d1205
ZW
5295 *str = p;
5296 return psr_field;
a737bd4d 5297
c19d1205
ZW
5298 error:
5299 inst.error = _("flag for {c}psr instruction expected");
5300 return FAIL;
a737bd4d
NC
5301}
5302
c19d1205
ZW
5303/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5304 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5305
c19d1205
ZW
5306static int
5307parse_cps_flags (char **str)
a737bd4d 5308{
c19d1205
ZW
5309 int val = 0;
5310 int saw_a_flag = 0;
5311 char *s = *str;
a737bd4d 5312
c19d1205
ZW
5313 for (;;)
5314 switch (*s++)
5315 {
5316 case '\0': case ',':
5317 goto done;
a737bd4d 5318
c19d1205
ZW
5319 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5320 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5321 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5322
c19d1205
ZW
5323 default:
5324 inst.error = _("unrecognized CPS flag");
5325 return FAIL;
5326 }
a737bd4d 5327
c19d1205
ZW
5328 done:
5329 if (saw_a_flag == 0)
a737bd4d 5330 {
c19d1205
ZW
5331 inst.error = _("missing CPS flags");
5332 return FAIL;
a737bd4d 5333 }
a737bd4d 5334
c19d1205
ZW
5335 *str = s - 1;
5336 return val;
a737bd4d
NC
5337}
5338
c19d1205
ZW
5339/* Parse an endian specifier ("BE" or "LE", case insensitive);
5340 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5341
5342static int
c19d1205 5343parse_endian_specifier (char **str)
a737bd4d 5344{
c19d1205
ZW
5345 int little_endian;
5346 char *s = *str;
a737bd4d 5347
c19d1205
ZW
5348 if (strncasecmp (s, "BE", 2))
5349 little_endian = 0;
5350 else if (strncasecmp (s, "LE", 2))
5351 little_endian = 1;
5352 else
a737bd4d 5353 {
c19d1205 5354 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5355 return FAIL;
5356 }
5357
c19d1205 5358 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5359 {
c19d1205 5360 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5361 return FAIL;
5362 }
5363
c19d1205
ZW
5364 *str = s + 2;
5365 return little_endian;
5366}
a737bd4d 5367
c19d1205
ZW
5368/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5369 value suitable for poking into the rotate field of an sxt or sxta
5370 instruction, or FAIL on error. */
5371
5372static int
5373parse_ror (char **str)
5374{
5375 int rot;
5376 char *s = *str;
5377
5378 if (strncasecmp (s, "ROR", 3) == 0)
5379 s += 3;
5380 else
a737bd4d 5381 {
c19d1205 5382 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5383 return FAIL;
5384 }
c19d1205
ZW
5385
5386 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5387 return FAIL;
5388
5389 switch (rot)
a737bd4d 5390 {
c19d1205
ZW
5391 case 0: *str = s; return 0x0;
5392 case 8: *str = s; return 0x1;
5393 case 16: *str = s; return 0x2;
5394 case 24: *str = s; return 0x3;
5395
5396 default:
5397 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5398 return FAIL;
5399 }
c19d1205 5400}
a737bd4d 5401
c19d1205
ZW
5402/* Parse a conditional code (from conds[] below). The value returned is in the
5403 range 0 .. 14, or FAIL. */
5404static int
5405parse_cond (char **str)
5406{
c462b453 5407 char *q;
c19d1205 5408 const struct asm_cond *c;
c462b453
PB
5409 int n;
5410 /* Condition codes are always 2 characters, so matching up to
5411 3 characters is sufficient. */
5412 char cond[3];
a737bd4d 5413
c462b453
PB
5414 q = *str;
5415 n = 0;
5416 while (ISALPHA (*q) && n < 3)
5417 {
e07e6e58 5418 cond[n] = TOLOWER (*q);
c462b453
PB
5419 q++;
5420 n++;
5421 }
a737bd4d 5422
21d799b5 5423 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5424 if (!c)
a737bd4d 5425 {
c19d1205 5426 inst.error = _("condition required");
a737bd4d
NC
5427 return FAIL;
5428 }
5429
c19d1205
ZW
5430 *str = q;
5431 return c->value;
5432}
5433
62b3e311
PB
5434/* Parse an option for a barrier instruction. Returns the encoding for the
5435 option, or FAIL. */
5436static int
5437parse_barrier (char **str)
5438{
5439 char *p, *q;
5440 const struct asm_barrier_opt *o;
5441
5442 p = q = *str;
5443 while (ISALPHA (*q))
5444 q++;
5445
21d799b5
NC
5446 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5447 q - p);
62b3e311
PB
5448 if (!o)
5449 return FAIL;
5450
5451 *str = q;
5452 return o->value;
5453}
5454
92e90b6e
PB
5455/* Parse the operands of a table branch instruction. Similar to a memory
5456 operand. */
5457static int
5458parse_tb (char **str)
5459{
5460 char * p = *str;
5461 int reg;
5462
5463 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5464 {
5465 inst.error = _("'[' expected");
5466 return FAIL;
5467 }
92e90b6e 5468
dcbf9037 5469 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5470 {
5471 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5472 return FAIL;
5473 }
5474 inst.operands[0].reg = reg;
5475
5476 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5477 {
5478 inst.error = _("',' expected");
5479 return FAIL;
5480 }
5f4273c7 5481
dcbf9037 5482 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5483 {
5484 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5485 return FAIL;
5486 }
5487 inst.operands[0].imm = reg;
5488
5489 if (skip_past_comma (&p) == SUCCESS)
5490 {
5491 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5492 return FAIL;
5493 if (inst.reloc.exp.X_add_number != 1)
5494 {
5495 inst.error = _("invalid shift");
5496 return FAIL;
5497 }
5498 inst.operands[0].shifted = 1;
5499 }
5500
5501 if (skip_past_char (&p, ']') == FAIL)
5502 {
5503 inst.error = _("']' expected");
5504 return FAIL;
5505 }
5506 *str = p;
5507 return SUCCESS;
5508}
5509
5287ad62
JB
5510/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5511 information on the types the operands can take and how they are encoded.
037e8744
JB
5512 Up to four operands may be read; this function handles setting the
5513 ".present" field for each read operand itself.
5287ad62
JB
5514 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5515 else returns FAIL. */
5516
5517static int
5518parse_neon_mov (char **str, int *which_operand)
5519{
5520 int i = *which_operand, val;
5521 enum arm_reg_type rtype;
5522 char *ptr = *str;
dcbf9037 5523 struct neon_type_el optype;
5f4273c7 5524
dcbf9037 5525 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5526 {
5527 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5528 inst.operands[i].reg = val;
5529 inst.operands[i].isscalar = 1;
dcbf9037 5530 inst.operands[i].vectype = optype;
5287ad62
JB
5531 inst.operands[i++].present = 1;
5532
5533 if (skip_past_comma (&ptr) == FAIL)
5534 goto wanted_comma;
5f4273c7 5535
dcbf9037 5536 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5537 goto wanted_arm;
5f4273c7 5538
5287ad62
JB
5539 inst.operands[i].reg = val;
5540 inst.operands[i].isreg = 1;
5541 inst.operands[i].present = 1;
5542 }
037e8744 5543 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5544 != FAIL)
5287ad62
JB
5545 {
5546 /* Cases 0, 1, 2, 3, 5 (D only). */
5547 if (skip_past_comma (&ptr) == FAIL)
5548 goto wanted_comma;
5f4273c7 5549
5287ad62
JB
5550 inst.operands[i].reg = val;
5551 inst.operands[i].isreg = 1;
5552 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5553 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5554 inst.operands[i].isvec = 1;
dcbf9037 5555 inst.operands[i].vectype = optype;
5287ad62
JB
5556 inst.operands[i++].present = 1;
5557
dcbf9037 5558 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5559 {
037e8744
JB
5560 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5561 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5562 inst.operands[i].reg = val;
5563 inst.operands[i].isreg = 1;
037e8744 5564 inst.operands[i].present = 1;
5287ad62
JB
5565
5566 if (rtype == REG_TYPE_NQ)
5567 {
dcbf9037 5568 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5569 return FAIL;
5570 }
037e8744
JB
5571 else if (rtype != REG_TYPE_VFS)
5572 {
5573 i++;
5574 if (skip_past_comma (&ptr) == FAIL)
5575 goto wanted_comma;
5576 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5577 goto wanted_arm;
5578 inst.operands[i].reg = val;
5579 inst.operands[i].isreg = 1;
5580 inst.operands[i].present = 1;
5581 }
5287ad62 5582 }
037e8744
JB
5583 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5584 &optype)) != FAIL)
5287ad62
JB
5585 {
5586 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5587 Case 1: VMOV<c><q> <Dd>, <Dm>
5588 Case 8: VMOV.F32 <Sd>, <Sm>
5589 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5590
5591 inst.operands[i].reg = val;
5592 inst.operands[i].isreg = 1;
5593 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5594 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5595 inst.operands[i].isvec = 1;
dcbf9037 5596 inst.operands[i].vectype = optype;
5287ad62 5597 inst.operands[i].present = 1;
5f4273c7 5598
037e8744
JB
5599 if (skip_past_comma (&ptr) == SUCCESS)
5600 {
5601 /* Case 15. */
5602 i++;
5603
5604 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5605 goto wanted_arm;
5606
5607 inst.operands[i].reg = val;
5608 inst.operands[i].isreg = 1;
5609 inst.operands[i++].present = 1;
5f4273c7 5610
037e8744
JB
5611 if (skip_past_comma (&ptr) == FAIL)
5612 goto wanted_comma;
5f4273c7 5613
037e8744
JB
5614 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5615 goto wanted_arm;
5f4273c7 5616
037e8744
JB
5617 inst.operands[i].reg = val;
5618 inst.operands[i].isreg = 1;
5619 inst.operands[i++].present = 1;
5620 }
5287ad62 5621 }
4641781c
PB
5622 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5623 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5624 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5625 Case 10: VMOV.F32 <Sd>, #<imm>
5626 Case 11: VMOV.F64 <Dd>, #<imm> */
5627 inst.operands[i].immisfloat = 1;
5628 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5629 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5630 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5631 ;
5287ad62
JB
5632 else
5633 {
dcbf9037 5634 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5635 return FAIL;
5636 }
5637 }
dcbf9037 5638 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5639 {
5640 /* Cases 6, 7. */
5641 inst.operands[i].reg = val;
5642 inst.operands[i].isreg = 1;
5643 inst.operands[i++].present = 1;
5f4273c7 5644
5287ad62
JB
5645 if (skip_past_comma (&ptr) == FAIL)
5646 goto wanted_comma;
5f4273c7 5647
dcbf9037 5648 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5649 {
5650 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5651 inst.operands[i].reg = val;
5652 inst.operands[i].isscalar = 1;
5653 inst.operands[i].present = 1;
dcbf9037 5654 inst.operands[i].vectype = optype;
5287ad62 5655 }
dcbf9037 5656 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5657 {
5658 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5659 inst.operands[i].reg = val;
5660 inst.operands[i].isreg = 1;
5661 inst.operands[i++].present = 1;
5f4273c7 5662
5287ad62
JB
5663 if (skip_past_comma (&ptr) == FAIL)
5664 goto wanted_comma;
5f4273c7 5665
037e8744 5666 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5667 == FAIL)
5287ad62 5668 {
037e8744 5669 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5670 return FAIL;
5671 }
5672
5673 inst.operands[i].reg = val;
5674 inst.operands[i].isreg = 1;
037e8744
JB
5675 inst.operands[i].isvec = 1;
5676 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5677 inst.operands[i].vectype = optype;
5287ad62 5678 inst.operands[i].present = 1;
5f4273c7 5679
037e8744
JB
5680 if (rtype == REG_TYPE_VFS)
5681 {
5682 /* Case 14. */
5683 i++;
5684 if (skip_past_comma (&ptr) == FAIL)
5685 goto wanted_comma;
5686 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5687 &optype)) == FAIL)
5688 {
5689 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5690 return FAIL;
5691 }
5692 inst.operands[i].reg = val;
5693 inst.operands[i].isreg = 1;
5694 inst.operands[i].isvec = 1;
5695 inst.operands[i].issingle = 1;
5696 inst.operands[i].vectype = optype;
5697 inst.operands[i].present = 1;
5698 }
5699 }
5700 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5701 != FAIL)
5702 {
5703 /* Case 13. */
5704 inst.operands[i].reg = val;
5705 inst.operands[i].isreg = 1;
5706 inst.operands[i].isvec = 1;
5707 inst.operands[i].issingle = 1;
5708 inst.operands[i].vectype = optype;
5709 inst.operands[i++].present = 1;
5287ad62
JB
5710 }
5711 }
5712 else
5713 {
dcbf9037 5714 first_error (_("parse error"));
5287ad62
JB
5715 return FAIL;
5716 }
5717
5718 /* Successfully parsed the operands. Update args. */
5719 *which_operand = i;
5720 *str = ptr;
5721 return SUCCESS;
5722
5f4273c7 5723 wanted_comma:
dcbf9037 5724 first_error (_("expected comma"));
5287ad62 5725 return FAIL;
5f4273c7
NC
5726
5727 wanted_arm:
dcbf9037 5728 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5729 return FAIL;
5287ad62
JB
5730}
5731
c19d1205
ZW
5732/* Matcher codes for parse_operands. */
5733enum operand_parse_code
5734{
5735 OP_stop, /* end of line */
5736
5737 OP_RR, /* ARM register */
5738 OP_RRnpc, /* ARM register, not r15 */
5739 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5740 OP_RRw, /* ARM register, not r15, optional trailing ! */
5741 OP_RCP, /* Coprocessor number */
5742 OP_RCN, /* Coprocessor register */
5743 OP_RF, /* FPA register */
5744 OP_RVS, /* VFP single precision register */
5287ad62
JB
5745 OP_RVD, /* VFP double precision register (0..15) */
5746 OP_RND, /* Neon double precision register (0..31) */
5747 OP_RNQ, /* Neon quad precision register */
037e8744 5748 OP_RVSD, /* VFP single or double precision register */
5287ad62 5749 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5750 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5751 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5752 OP_RVC, /* VFP control register */
5753 OP_RMF, /* Maverick F register */
5754 OP_RMD, /* Maverick D register */
5755 OP_RMFX, /* Maverick FX register */
5756 OP_RMDX, /* Maverick DX register */
5757 OP_RMAX, /* Maverick AX register */
5758 OP_RMDS, /* Maverick DSPSC register */
5759 OP_RIWR, /* iWMMXt wR register */
5760 OP_RIWC, /* iWMMXt wC register */
5761 OP_RIWG, /* iWMMXt wCG register */
5762 OP_RXA, /* XScale accumulator register */
5763
5764 OP_REGLST, /* ARM register list */
5765 OP_VRSLST, /* VFP single-precision register list */
5766 OP_VRDLST, /* VFP double-precision register list */
037e8744 5767 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5768 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5769 OP_NSTRLST, /* Neon element/structure list */
5770
5287ad62 5771 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5772 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5773 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5774 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5775 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5776 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5777 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5778 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5779 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5780 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5781
5782 OP_I0, /* immediate zero */
c19d1205
ZW
5783 OP_I7, /* immediate value 0 .. 7 */
5784 OP_I15, /* 0 .. 15 */
5785 OP_I16, /* 1 .. 16 */
5287ad62 5786 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5787 OP_I31, /* 0 .. 31 */
5788 OP_I31w, /* 0 .. 31, optional trailing ! */
5789 OP_I32, /* 1 .. 32 */
5287ad62
JB
5790 OP_I32z, /* 0 .. 32 */
5791 OP_I63, /* 0 .. 63 */
c19d1205 5792 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5793 OP_I64, /* 1 .. 64 */
5794 OP_I64z, /* 0 .. 64 */
c19d1205 5795 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5796
5797 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5798 OP_I7b, /* 0 .. 7 */
5799 OP_I15b, /* 0 .. 15 */
5800 OP_I31b, /* 0 .. 31 */
5801
5802 OP_SH, /* shifter operand */
4962c51a 5803 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5804 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5805 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5806 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5807 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5808 OP_EXP, /* arbitrary expression */
5809 OP_EXPi, /* same, with optional immediate prefix */
5810 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5811 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5812
5813 OP_CPSF, /* CPS flags */
5814 OP_ENDI, /* Endianness specifier */
5815 OP_PSR, /* CPSR/SPSR mask for msr */
5816 OP_COND, /* conditional code */
92e90b6e 5817 OP_TB, /* Table branch. */
c19d1205 5818
037e8744
JB
5819 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5820 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5821
c19d1205
ZW
5822 OP_RRnpc_I0, /* ARM register or literal 0 */
5823 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5824 OP_RR_EXi, /* ARM register or expression with imm prefix */
5825 OP_RF_IF, /* FPA register or immediate */
5826 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5827 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5828
5829 /* Optional operands. */
5830 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5831 OP_oI31b, /* 0 .. 31 */
5287ad62 5832 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5833 OP_oIffffb, /* 0 .. 65535 */
5834 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5835
5836 OP_oRR, /* ARM register */
5837 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5838 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5839 OP_oRND, /* Optional Neon double precision register */
5840 OP_oRNQ, /* Optional Neon quad precision register */
5841 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5842 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5843 OP_oSHll, /* LSL immediate */
5844 OP_oSHar, /* ASR immediate */
5845 OP_oSHllar, /* LSL or ASR immediate */
5846 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5847 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5848
5849 OP_FIRST_OPTIONAL = OP_oI7b
5850};
a737bd4d 5851
c19d1205
ZW
5852/* Generic instruction operand parser. This does no encoding and no
5853 semantic validation; it merely squirrels values away in the inst
5854 structure. Returns SUCCESS or FAIL depending on whether the
5855 specified grammar matched. */
5856static int
ca3f61f7 5857parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5858{
5859 unsigned const char *upat = pattern;
5860 char *backtrack_pos = 0;
5861 const char *backtrack_error = 0;
5862 int i, val, backtrack_index = 0;
5287ad62 5863 enum arm_reg_type rtype;
4962c51a 5864 parse_operand_result result;
c19d1205 5865
e07e6e58
NC
5866#define po_char_or_fail(chr) \
5867 do \
5868 { \
5869 if (skip_past_char (&str, chr) == FAIL) \
5870 goto bad_args; \
5871 } \
5872 while (0)
c19d1205 5873
e07e6e58
NC
5874#define po_reg_or_fail(regtype) \
5875 do \
dcbf9037 5876 { \
e07e6e58
NC
5877 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5878 & inst.operands[i].vectype); \
5879 if (val == FAIL) \
5880 { \
5881 first_error (_(reg_expected_msgs[regtype])); \
5882 goto failure; \
5883 } \
5884 inst.operands[i].reg = val; \
5885 inst.operands[i].isreg = 1; \
5886 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5887 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5888 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5889 || rtype == REG_TYPE_VFD \
5890 || rtype == REG_TYPE_NQ); \
dcbf9037 5891 } \
e07e6e58
NC
5892 while (0)
5893
5894#define po_reg_or_goto(regtype, label) \
5895 do \
5896 { \
5897 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5898 & inst.operands[i].vectype); \
5899 if (val == FAIL) \
5900 goto label; \
dcbf9037 5901 \
e07e6e58
NC
5902 inst.operands[i].reg = val; \
5903 inst.operands[i].isreg = 1; \
5904 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5905 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5906 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5907 || rtype == REG_TYPE_VFD \
5908 || rtype == REG_TYPE_NQ); \
5909 } \
5910 while (0)
5911
5912#define po_imm_or_fail(min, max, popt) \
5913 do \
5914 { \
5915 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5916 goto failure; \
5917 inst.operands[i].imm = val; \
5918 } \
5919 while (0)
5920
5921#define po_scalar_or_goto(elsz, label) \
5922 do \
5923 { \
5924 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5925 if (val == FAIL) \
5926 goto label; \
5927 inst.operands[i].reg = val; \
5928 inst.operands[i].isscalar = 1; \
5929 } \
5930 while (0)
5931
5932#define po_misc_or_fail(expr) \
5933 do \
5934 { \
5935 if (expr) \
5936 goto failure; \
5937 } \
5938 while (0)
5939
5940#define po_misc_or_fail_no_backtrack(expr) \
5941 do \
5942 { \
5943 result = expr; \
5944 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5945 backtrack_pos = 0; \
5946 if (result != PARSE_OPERAND_SUCCESS) \
5947 goto failure; \
5948 } \
5949 while (0)
4962c51a 5950
c19d1205
ZW
5951 skip_whitespace (str);
5952
5953 for (i = 0; upat[i] != OP_stop; i++)
5954 {
5955 if (upat[i] >= OP_FIRST_OPTIONAL)
5956 {
5957 /* Remember where we are in case we need to backtrack. */
9c2799c2 5958 gas_assert (!backtrack_pos);
c19d1205
ZW
5959 backtrack_pos = str;
5960 backtrack_error = inst.error;
5961 backtrack_index = i;
5962 }
5963
b6702015 5964 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5965 po_char_or_fail (',');
5966
5967 switch (upat[i])
5968 {
5969 /* Registers */
5970 case OP_oRRnpc:
5971 case OP_RRnpc:
5972 case OP_oRR:
5973 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5974 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5975 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5976 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5977 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5978 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5979 case OP_oRND:
5980 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5981 case OP_RVC:
5982 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5983 break;
5984 /* Also accept generic coprocessor regs for unknown registers. */
5985 coproc_reg:
5986 po_reg_or_fail (REG_TYPE_CN);
5987 break;
c19d1205
ZW
5988 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5989 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5990 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5991 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5992 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5993 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5994 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5995 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5996 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5997 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5998 case OP_oRNQ:
5999 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6000 case OP_oRNDQ:
6001 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6002 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6003 case OP_oRNSDQ:
6004 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6005
6006 /* Neon scalar. Using an element size of 8 means that some invalid
6007 scalars are accepted here, so deal with those in later code. */
6008 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6009
5287ad62
JB
6010 case OP_RNDQ_I0:
6011 {
6012 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6013 break;
6014 try_imm0:
6015 po_imm_or_fail (0, 0, TRUE);
6016 }
6017 break;
6018
037e8744
JB
6019 case OP_RVSD_I0:
6020 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6021 break;
6022
5287ad62
JB
6023 case OP_RR_RNSC:
6024 {
6025 po_scalar_or_goto (8, try_rr);
6026 break;
6027 try_rr:
6028 po_reg_or_fail (REG_TYPE_RN);
6029 }
6030 break;
6031
037e8744
JB
6032 case OP_RNSDQ_RNSC:
6033 {
6034 po_scalar_or_goto (8, try_nsdq);
6035 break;
6036 try_nsdq:
6037 po_reg_or_fail (REG_TYPE_NSDQ);
6038 }
6039 break;
6040
5287ad62
JB
6041 case OP_RNDQ_RNSC:
6042 {
6043 po_scalar_or_goto (8, try_ndq);
6044 break;
6045 try_ndq:
6046 po_reg_or_fail (REG_TYPE_NDQ);
6047 }
6048 break;
6049
6050 case OP_RND_RNSC:
6051 {
6052 po_scalar_or_goto (8, try_vfd);
6053 break;
6054 try_vfd:
6055 po_reg_or_fail (REG_TYPE_VFD);
6056 }
6057 break;
6058
6059 case OP_VMOV:
6060 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6061 not careful then bad things might happen. */
6062 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6063 break;
6064
4316f0d2 6065 case OP_RNDQ_Ibig:
5287ad62 6066 {
4316f0d2 6067 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6068 break;
4316f0d2 6069 try_immbig:
5287ad62
JB
6070 /* There's a possibility of getting a 64-bit immediate here, so
6071 we need special handling. */
6072 if (parse_big_immediate (&str, i) == FAIL)
6073 {
6074 inst.error = _("immediate value is out of range");
6075 goto failure;
6076 }
6077 }
6078 break;
6079
6080 case OP_RNDQ_I63b:
6081 {
6082 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6083 break;
6084 try_shimm:
6085 po_imm_or_fail (0, 63, TRUE);
6086 }
6087 break;
c19d1205
ZW
6088
6089 case OP_RRnpcb:
6090 po_char_or_fail ('[');
6091 po_reg_or_fail (REG_TYPE_RN);
6092 po_char_or_fail (']');
6093 break;
a737bd4d 6094
c19d1205 6095 case OP_RRw:
b6702015 6096 case OP_oRRw:
c19d1205
ZW
6097 po_reg_or_fail (REG_TYPE_RN);
6098 if (skip_past_char (&str, '!') == SUCCESS)
6099 inst.operands[i].writeback = 1;
6100 break;
6101
6102 /* Immediates */
6103 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6104 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6105 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6106 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6107 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6108 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6109 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6110 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6111 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6112 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6113 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6114 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6115
6116 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6117 case OP_oI7b:
6118 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6119 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6120 case OP_oI31b:
6121 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6122 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6123 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6124
6125 /* Immediate variants */
6126 case OP_oI255c:
6127 po_char_or_fail ('{');
6128 po_imm_or_fail (0, 255, TRUE);
6129 po_char_or_fail ('}');
6130 break;
6131
6132 case OP_I31w:
6133 /* The expression parser chokes on a trailing !, so we have
6134 to find it first and zap it. */
6135 {
6136 char *s = str;
6137 while (*s && *s != ',')
6138 s++;
6139 if (s[-1] == '!')
6140 {
6141 s[-1] = '\0';
6142 inst.operands[i].writeback = 1;
6143 }
6144 po_imm_or_fail (0, 31, TRUE);
6145 if (str == s - 1)
6146 str = s;
6147 }
6148 break;
6149
6150 /* Expressions */
6151 case OP_EXPi: EXPi:
6152 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6153 GE_OPT_PREFIX));
6154 break;
6155
6156 case OP_EXP:
6157 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6158 GE_NO_PREFIX));
6159 break;
6160
6161 case OP_EXPr: EXPr:
6162 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6163 GE_NO_PREFIX));
6164 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6165 {
c19d1205
ZW
6166 val = parse_reloc (&str);
6167 if (val == -1)
6168 {
6169 inst.error = _("unrecognized relocation suffix");
6170 goto failure;
6171 }
6172 else if (val != BFD_RELOC_UNUSED)
6173 {
6174 inst.operands[i].imm = val;
6175 inst.operands[i].hasreloc = 1;
6176 }
a737bd4d 6177 }
c19d1205 6178 break;
a737bd4d 6179
b6895b4f
PB
6180 /* Operand for MOVW or MOVT. */
6181 case OP_HALF:
6182 po_misc_or_fail (parse_half (&str));
6183 break;
6184
e07e6e58 6185 /* Register or expression. */
c19d1205
ZW
6186 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6187 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6188
e07e6e58 6189 /* Register or immediate. */
c19d1205
ZW
6190 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6191 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6192
c19d1205
ZW
6193 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6194 IF:
6195 if (!is_immediate_prefix (*str))
6196 goto bad_args;
6197 str++;
6198 val = parse_fpa_immediate (&str);
6199 if (val == FAIL)
6200 goto failure;
6201 /* FPA immediates are encoded as registers 8-15.
6202 parse_fpa_immediate has already applied the offset. */
6203 inst.operands[i].reg = val;
6204 inst.operands[i].isreg = 1;
6205 break;
09d92015 6206
2d447fca
JM
6207 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6208 I32z: po_imm_or_fail (0, 32, FALSE); break;
6209
e07e6e58 6210 /* Two kinds of register. */
c19d1205
ZW
6211 case OP_RIWR_RIWC:
6212 {
6213 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6214 if (!rege
6215 || (rege->type != REG_TYPE_MMXWR
6216 && rege->type != REG_TYPE_MMXWC
6217 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6218 {
6219 inst.error = _("iWMMXt data or control register expected");
6220 goto failure;
6221 }
6222 inst.operands[i].reg = rege->number;
6223 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6224 }
6225 break;
09d92015 6226
41adaa5c
JM
6227 case OP_RIWC_RIWG:
6228 {
6229 struct reg_entry *rege = arm_reg_parse_multi (&str);
6230 if (!rege
6231 || (rege->type != REG_TYPE_MMXWC
6232 && rege->type != REG_TYPE_MMXWCG))
6233 {
6234 inst.error = _("iWMMXt control register expected");
6235 goto failure;
6236 }
6237 inst.operands[i].reg = rege->number;
6238 inst.operands[i].isreg = 1;
6239 }
6240 break;
6241
c19d1205
ZW
6242 /* Misc */
6243 case OP_CPSF: val = parse_cps_flags (&str); break;
6244 case OP_ENDI: val = parse_endian_specifier (&str); break;
6245 case OP_oROR: val = parse_ror (&str); break;
6246 case OP_PSR: val = parse_psr (&str); break;
6247 case OP_COND: val = parse_cond (&str); break;
62b3e311 6248 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6249
037e8744
JB
6250 case OP_RVC_PSR:
6251 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6252 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6253 break;
6254 try_psr:
6255 val = parse_psr (&str);
6256 break;
6257
6258 case OP_APSR_RR:
6259 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6260 break;
6261 try_apsr:
6262 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6263 instruction). */
6264 if (strncasecmp (str, "APSR_", 5) == 0)
6265 {
6266 unsigned found = 0;
6267 str += 5;
6268 while (found < 15)
6269 switch (*str++)
6270 {
6271 case 'c': found = (found & 1) ? 16 : found | 1; break;
6272 case 'n': found = (found & 2) ? 16 : found | 2; break;
6273 case 'z': found = (found & 4) ? 16 : found | 4; break;
6274 case 'v': found = (found & 8) ? 16 : found | 8; break;
6275 default: found = 16;
6276 }
6277 if (found != 15)
6278 goto failure;
6279 inst.operands[i].isvec = 1;
f7c21dc7
NC
6280 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6281 inst.operands[i].reg = REG_PC;
037e8744
JB
6282 }
6283 else
6284 goto failure;
6285 break;
6286
92e90b6e
PB
6287 case OP_TB:
6288 po_misc_or_fail (parse_tb (&str));
6289 break;
6290
e07e6e58 6291 /* Register lists. */
c19d1205
ZW
6292 case OP_REGLST:
6293 val = parse_reg_list (&str);
6294 if (*str == '^')
6295 {
6296 inst.operands[1].writeback = 1;
6297 str++;
6298 }
6299 break;
09d92015 6300
c19d1205 6301 case OP_VRSLST:
5287ad62 6302 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6303 break;
09d92015 6304
c19d1205 6305 case OP_VRDLST:
5287ad62 6306 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6307 break;
a737bd4d 6308
037e8744
JB
6309 case OP_VRSDLST:
6310 /* Allow Q registers too. */
6311 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6312 REGLIST_NEON_D);
6313 if (val == FAIL)
6314 {
6315 inst.error = NULL;
6316 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6317 REGLIST_VFP_S);
6318 inst.operands[i].issingle = 1;
6319 }
6320 break;
6321
5287ad62
JB
6322 case OP_NRDLST:
6323 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6324 REGLIST_NEON_D);
6325 break;
6326
6327 case OP_NSTRLST:
dcbf9037
JB
6328 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6329 &inst.operands[i].vectype);
5287ad62
JB
6330 break;
6331
c19d1205
ZW
6332 /* Addressing modes */
6333 case OP_ADDR:
6334 po_misc_or_fail (parse_address (&str, i));
6335 break;
09d92015 6336
4962c51a
MS
6337 case OP_ADDRGLDR:
6338 po_misc_or_fail_no_backtrack (
6339 parse_address_group_reloc (&str, i, GROUP_LDR));
6340 break;
6341
6342 case OP_ADDRGLDRS:
6343 po_misc_or_fail_no_backtrack (
6344 parse_address_group_reloc (&str, i, GROUP_LDRS));
6345 break;
6346
6347 case OP_ADDRGLDC:
6348 po_misc_or_fail_no_backtrack (
6349 parse_address_group_reloc (&str, i, GROUP_LDC));
6350 break;
6351
c19d1205
ZW
6352 case OP_SH:
6353 po_misc_or_fail (parse_shifter_operand (&str, i));
6354 break;
09d92015 6355
4962c51a
MS
6356 case OP_SHG:
6357 po_misc_or_fail_no_backtrack (
6358 parse_shifter_operand_group_reloc (&str, i));
6359 break;
6360
c19d1205
ZW
6361 case OP_oSHll:
6362 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6363 break;
09d92015 6364
c19d1205
ZW
6365 case OP_oSHar:
6366 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6367 break;
09d92015 6368
c19d1205
ZW
6369 case OP_oSHllar:
6370 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6371 break;
09d92015 6372
c19d1205 6373 default:
bd3ba5d1 6374 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6375 }
09d92015 6376
c19d1205
ZW
6377 /* Various value-based sanity checks and shared operations. We
6378 do not signal immediate failures for the register constraints;
6379 this allows a syntax error to take precedence. */
6380 switch (upat[i])
6381 {
6382 case OP_oRRnpc:
6383 case OP_RRnpc:
6384 case OP_RRnpcb:
6385 case OP_RRw:
b6702015 6386 case OP_oRRw:
c19d1205
ZW
6387 case OP_RRnpc_I0:
6388 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6389 inst.error = BAD_PC;
6390 break;
09d92015 6391
c19d1205
ZW
6392 case OP_CPSF:
6393 case OP_ENDI:
6394 case OP_oROR:
6395 case OP_PSR:
037e8744 6396 case OP_RVC_PSR:
c19d1205 6397 case OP_COND:
62b3e311 6398 case OP_oBARRIER:
c19d1205
ZW
6399 case OP_REGLST:
6400 case OP_VRSLST:
6401 case OP_VRDLST:
037e8744 6402 case OP_VRSDLST:
5287ad62
JB
6403 case OP_NRDLST:
6404 case OP_NSTRLST:
c19d1205
ZW
6405 if (val == FAIL)
6406 goto failure;
6407 inst.operands[i].imm = val;
6408 break;
a737bd4d 6409
c19d1205
ZW
6410 default:
6411 break;
6412 }
09d92015 6413
c19d1205
ZW
6414 /* If we get here, this operand was successfully parsed. */
6415 inst.operands[i].present = 1;
6416 continue;
09d92015 6417
c19d1205 6418 bad_args:
09d92015 6419 inst.error = BAD_ARGS;
c19d1205
ZW
6420
6421 failure:
6422 if (!backtrack_pos)
d252fdde
PB
6423 {
6424 /* The parse routine should already have set inst.error, but set a
5f4273c7 6425 default here just in case. */
d252fdde
PB
6426 if (!inst.error)
6427 inst.error = _("syntax error");
6428 return FAIL;
6429 }
c19d1205
ZW
6430
6431 /* Do not backtrack over a trailing optional argument that
6432 absorbed some text. We will only fail again, with the
6433 'garbage following instruction' error message, which is
6434 probably less helpful than the current one. */
6435 if (backtrack_index == i && backtrack_pos != str
6436 && upat[i+1] == OP_stop)
d252fdde
PB
6437 {
6438 if (!inst.error)
6439 inst.error = _("syntax error");
6440 return FAIL;
6441 }
c19d1205
ZW
6442
6443 /* Try again, skipping the optional argument at backtrack_pos. */
6444 str = backtrack_pos;
6445 inst.error = backtrack_error;
6446 inst.operands[backtrack_index].present = 0;
6447 i = backtrack_index;
6448 backtrack_pos = 0;
09d92015 6449 }
09d92015 6450
c19d1205
ZW
6451 /* Check that we have parsed all the arguments. */
6452 if (*str != '\0' && !inst.error)
6453 inst.error = _("garbage following instruction");
09d92015 6454
c19d1205 6455 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6456}
6457
c19d1205
ZW
6458#undef po_char_or_fail
6459#undef po_reg_or_fail
6460#undef po_reg_or_goto
6461#undef po_imm_or_fail
5287ad62 6462#undef po_scalar_or_fail
e07e6e58 6463
c19d1205 6464/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6465#define constraint(expr, err) \
6466 do \
c19d1205 6467 { \
e07e6e58
NC
6468 if (expr) \
6469 { \
6470 inst.error = err; \
6471 return; \
6472 } \
c19d1205 6473 } \
e07e6e58 6474 while (0)
c19d1205 6475
fdfde340
JM
6476/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6477 instructions are unpredictable if these registers are used. This
6478 is the BadReg predicate in ARM's Thumb-2 documentation. */
6479#define reject_bad_reg(reg) \
6480 do \
6481 if (reg == REG_SP || reg == REG_PC) \
6482 { \
6483 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6484 return; \
6485 } \
6486 while (0)
6487
94206790
MM
6488/* If REG is R13 (the stack pointer), warn that its use is
6489 deprecated. */
6490#define warn_deprecated_sp(reg) \
6491 do \
6492 if (warn_on_deprecated && reg == REG_SP) \
6493 as_warn (_("use of r13 is deprecated")); \
6494 while (0)
6495
c19d1205
ZW
6496/* Functions for operand encoding. ARM, then Thumb. */
6497
6498#define rotate_left(v, n) (v << n | v >> (32 - n))
6499
6500/* If VAL can be encoded in the immediate field of an ARM instruction,
6501 return the encoded form. Otherwise, return FAIL. */
6502
6503static unsigned int
6504encode_arm_immediate (unsigned int val)
09d92015 6505{
c19d1205
ZW
6506 unsigned int a, i;
6507
6508 for (i = 0; i < 32; i += 2)
6509 if ((a = rotate_left (val, i)) <= 0xff)
6510 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6511
6512 return FAIL;
09d92015
MM
6513}
6514
c19d1205
ZW
6515/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6516 return the encoded form. Otherwise, return FAIL. */
6517static unsigned int
6518encode_thumb32_immediate (unsigned int val)
09d92015 6519{
c19d1205 6520 unsigned int a, i;
09d92015 6521
9c3c69f2 6522 if (val <= 0xff)
c19d1205 6523 return val;
a737bd4d 6524
9c3c69f2 6525 for (i = 1; i <= 24; i++)
09d92015 6526 {
9c3c69f2
PB
6527 a = val >> i;
6528 if ((val & ~(0xff << i)) == 0)
6529 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6530 }
a737bd4d 6531
c19d1205
ZW
6532 a = val & 0xff;
6533 if (val == ((a << 16) | a))
6534 return 0x100 | a;
6535 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6536 return 0x300 | a;
09d92015 6537
c19d1205
ZW
6538 a = val & 0xff00;
6539 if (val == ((a << 16) | a))
6540 return 0x200 | (a >> 8);
a737bd4d 6541
c19d1205 6542 return FAIL;
09d92015 6543}
5287ad62 6544/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6545
6546static void
5287ad62
JB
6547encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6548{
6549 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6550 && reg > 15)
6551 {
b1cc4aeb 6552 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6553 {
6554 if (thumb_mode)
6555 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6556 fpu_vfp_ext_d32);
5287ad62
JB
6557 else
6558 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6559 fpu_vfp_ext_d32);
5287ad62
JB
6560 }
6561 else
6562 {
dcbf9037 6563 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6564 return;
6565 }
6566 }
6567
c19d1205 6568 switch (pos)
09d92015 6569 {
c19d1205
ZW
6570 case VFP_REG_Sd:
6571 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6572 break;
6573
6574 case VFP_REG_Sn:
6575 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6576 break;
6577
6578 case VFP_REG_Sm:
6579 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6580 break;
6581
5287ad62
JB
6582 case VFP_REG_Dd:
6583 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6584 break;
5f4273c7 6585
5287ad62
JB
6586 case VFP_REG_Dn:
6587 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6588 break;
5f4273c7 6589
5287ad62
JB
6590 case VFP_REG_Dm:
6591 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6592 break;
6593
c19d1205
ZW
6594 default:
6595 abort ();
09d92015 6596 }
09d92015
MM
6597}
6598
c19d1205 6599/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6600 if any, is handled by md_apply_fix. */
09d92015 6601static void
c19d1205 6602encode_arm_shift (int i)
09d92015 6603{
c19d1205
ZW
6604 if (inst.operands[i].shift_kind == SHIFT_RRX)
6605 inst.instruction |= SHIFT_ROR << 5;
6606 else
09d92015 6607 {
c19d1205
ZW
6608 inst.instruction |= inst.operands[i].shift_kind << 5;
6609 if (inst.operands[i].immisreg)
6610 {
6611 inst.instruction |= SHIFT_BY_REG;
6612 inst.instruction |= inst.operands[i].imm << 8;
6613 }
6614 else
6615 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6616 }
c19d1205 6617}
09d92015 6618
c19d1205
ZW
6619static void
6620encode_arm_shifter_operand (int i)
6621{
6622 if (inst.operands[i].isreg)
09d92015 6623 {
c19d1205
ZW
6624 inst.instruction |= inst.operands[i].reg;
6625 encode_arm_shift (i);
09d92015 6626 }
c19d1205
ZW
6627 else
6628 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6629}
6630
c19d1205 6631/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6632static void
c19d1205 6633encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6634{
9c2799c2 6635 gas_assert (inst.operands[i].isreg);
c19d1205 6636 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6637
c19d1205 6638 if (inst.operands[i].preind)
09d92015 6639 {
c19d1205
ZW
6640 if (is_t)
6641 {
6642 inst.error = _("instruction does not accept preindexed addressing");
6643 return;
6644 }
6645 inst.instruction |= PRE_INDEX;
6646 if (inst.operands[i].writeback)
6647 inst.instruction |= WRITE_BACK;
09d92015 6648
c19d1205
ZW
6649 }
6650 else if (inst.operands[i].postind)
6651 {
9c2799c2 6652 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6653 if (is_t)
6654 inst.instruction |= WRITE_BACK;
6655 }
6656 else /* unindexed - only for coprocessor */
09d92015 6657 {
c19d1205 6658 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6659 return;
6660 }
6661
c19d1205
ZW
6662 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6663 && (((inst.instruction & 0x000f0000) >> 16)
6664 == ((inst.instruction & 0x0000f000) >> 12)))
6665 as_warn ((inst.instruction & LOAD_BIT)
6666 ? _("destination register same as write-back base")
6667 : _("source register same as write-back base"));
09d92015
MM
6668}
6669
c19d1205
ZW
6670/* inst.operands[i] was set up by parse_address. Encode it into an
6671 ARM-format mode 2 load or store instruction. If is_t is true,
6672 reject forms that cannot be used with a T instruction (i.e. not
6673 post-indexed). */
a737bd4d 6674static void
c19d1205 6675encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6676{
c19d1205 6677 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6678
c19d1205 6679 if (inst.operands[i].immisreg)
09d92015 6680 {
c19d1205
ZW
6681 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6682 inst.instruction |= inst.operands[i].imm;
6683 if (!inst.operands[i].negative)
6684 inst.instruction |= INDEX_UP;
6685 if (inst.operands[i].shifted)
6686 {
6687 if (inst.operands[i].shift_kind == SHIFT_RRX)
6688 inst.instruction |= SHIFT_ROR << 5;
6689 else
6690 {
6691 inst.instruction |= inst.operands[i].shift_kind << 5;
6692 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6693 }
6694 }
09d92015 6695 }
c19d1205 6696 else /* immediate offset in inst.reloc */
09d92015 6697 {
c19d1205
ZW
6698 if (inst.reloc.type == BFD_RELOC_UNUSED)
6699 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6700 }
09d92015
MM
6701}
6702
c19d1205
ZW
6703/* inst.operands[i] was set up by parse_address. Encode it into an
6704 ARM-format mode 3 load or store instruction. Reject forms that
6705 cannot be used with such instructions. If is_t is true, reject
6706 forms that cannot be used with a T instruction (i.e. not
6707 post-indexed). */
6708static void
6709encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6710{
c19d1205 6711 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6712 {
c19d1205
ZW
6713 inst.error = _("instruction does not accept scaled register index");
6714 return;
09d92015 6715 }
a737bd4d 6716
c19d1205 6717 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6718
c19d1205
ZW
6719 if (inst.operands[i].immisreg)
6720 {
6721 inst.instruction |= inst.operands[i].imm;
6722 if (!inst.operands[i].negative)
6723 inst.instruction |= INDEX_UP;
6724 }
6725 else /* immediate offset in inst.reloc */
6726 {
6727 inst.instruction |= HWOFFSET_IMM;
6728 if (inst.reloc.type == BFD_RELOC_UNUSED)
6729 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6730 }
a737bd4d
NC
6731}
6732
c19d1205
ZW
6733/* inst.operands[i] was set up by parse_address. Encode it into an
6734 ARM-format instruction. Reject all forms which cannot be encoded
6735 into a coprocessor load/store instruction. If wb_ok is false,
6736 reject use of writeback; if unind_ok is false, reject use of
6737 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6738 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6739 (in which case it is preserved). */
09d92015 6740
c19d1205
ZW
6741static int
6742encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6743{
c19d1205 6744 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6745
9c2799c2 6746 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6747
c19d1205 6748 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6749 {
9c2799c2 6750 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6751 if (!unind_ok)
6752 {
6753 inst.error = _("instruction does not support unindexed addressing");
6754 return FAIL;
6755 }
6756 inst.instruction |= inst.operands[i].imm;
6757 inst.instruction |= INDEX_UP;
6758 return SUCCESS;
09d92015 6759 }
a737bd4d 6760
c19d1205
ZW
6761 if (inst.operands[i].preind)
6762 inst.instruction |= PRE_INDEX;
a737bd4d 6763
c19d1205 6764 if (inst.operands[i].writeback)
09d92015 6765 {
c19d1205
ZW
6766 if (inst.operands[i].reg == REG_PC)
6767 {
6768 inst.error = _("pc may not be used with write-back");
6769 return FAIL;
6770 }
6771 if (!wb_ok)
6772 {
6773 inst.error = _("instruction does not support writeback");
6774 return FAIL;
6775 }
6776 inst.instruction |= WRITE_BACK;
09d92015 6777 }
a737bd4d 6778
c19d1205 6779 if (reloc_override)
21d799b5 6780 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6781 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6782 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6783 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6784 {
6785 if (thumb_mode)
6786 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6787 else
6788 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6789 }
6790
c19d1205
ZW
6791 return SUCCESS;
6792}
a737bd4d 6793
c19d1205
ZW
6794/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6795 Determine whether it can be performed with a move instruction; if
6796 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6797 return TRUE; if it can't, convert inst.instruction to a literal-pool
6798 load and return FALSE. If this is not a valid thing to do in the
6799 current context, set inst.error and return TRUE.
a737bd4d 6800
c19d1205
ZW
6801 inst.operands[i] describes the destination register. */
6802
c921be7d 6803static bfd_boolean
c19d1205
ZW
6804move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6805{
53365c0d
PB
6806 unsigned long tbit;
6807
6808 if (thumb_p)
6809 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6810 else
6811 tbit = LOAD_BIT;
6812
6813 if ((inst.instruction & tbit) == 0)
09d92015 6814 {
c19d1205 6815 inst.error = _("invalid pseudo operation");
c921be7d 6816 return TRUE;
09d92015 6817 }
c19d1205 6818 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6819 {
6820 inst.error = _("constant expression expected");
c921be7d 6821 return TRUE;
09d92015 6822 }
c19d1205 6823 if (inst.reloc.exp.X_op == O_constant)
09d92015 6824 {
c19d1205
ZW
6825 if (thumb_p)
6826 {
53365c0d 6827 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6828 {
6829 /* This can be done with a mov(1) instruction. */
6830 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6831 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 6832 return TRUE;
c19d1205
ZW
6833 }
6834 }
6835 else
6836 {
6837 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6838 if (value != FAIL)
6839 {
6840 /* This can be done with a mov instruction. */
6841 inst.instruction &= LITERAL_MASK;
6842 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6843 inst.instruction |= value & 0xfff;
c921be7d 6844 return TRUE;
c19d1205 6845 }
09d92015 6846
c19d1205
ZW
6847 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6848 if (value != FAIL)
6849 {
6850 /* This can be done with a mvn instruction. */
6851 inst.instruction &= LITERAL_MASK;
6852 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6853 inst.instruction |= value & 0xfff;
c921be7d 6854 return TRUE;
c19d1205
ZW
6855 }
6856 }
09d92015
MM
6857 }
6858
c19d1205
ZW
6859 if (add_to_lit_pool () == FAIL)
6860 {
6861 inst.error = _("literal pool insertion failed");
c921be7d 6862 return TRUE;
c19d1205
ZW
6863 }
6864 inst.operands[1].reg = REG_PC;
6865 inst.operands[1].isreg = 1;
6866 inst.operands[1].preind = 1;
6867 inst.reloc.pc_rel = 1;
6868 inst.reloc.type = (thumb_p
6869 ? BFD_RELOC_ARM_THUMB_OFFSET
6870 : (mode_3
6871 ? BFD_RELOC_ARM_HWLITERAL
6872 : BFD_RELOC_ARM_LITERAL));
c921be7d 6873 return FALSE;
09d92015
MM
6874}
6875
5f4273c7 6876/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6877 First some generics; their names are taken from the conventional
6878 bit positions for register arguments in ARM format instructions. */
09d92015 6879
a737bd4d 6880static void
c19d1205 6881do_noargs (void)
09d92015 6882{
c19d1205 6883}
a737bd4d 6884
c19d1205
ZW
6885static void
6886do_rd (void)
6887{
6888 inst.instruction |= inst.operands[0].reg << 12;
6889}
a737bd4d 6890
c19d1205
ZW
6891static void
6892do_rd_rm (void)
6893{
6894 inst.instruction |= inst.operands[0].reg << 12;
6895 inst.instruction |= inst.operands[1].reg;
6896}
09d92015 6897
c19d1205
ZW
6898static void
6899do_rd_rn (void)
6900{
6901 inst.instruction |= inst.operands[0].reg << 12;
6902 inst.instruction |= inst.operands[1].reg << 16;
6903}
a737bd4d 6904
c19d1205
ZW
6905static void
6906do_rn_rd (void)
6907{
6908 inst.instruction |= inst.operands[0].reg << 16;
6909 inst.instruction |= inst.operands[1].reg << 12;
6910}
09d92015 6911
c19d1205
ZW
6912static void
6913do_rd_rm_rn (void)
6914{
9a64e435 6915 unsigned Rn = inst.operands[2].reg;
708587a4 6916 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6917 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6918 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6919 _("Rn must not overlap other operands"));
c19d1205
ZW
6920 inst.instruction |= inst.operands[0].reg << 12;
6921 inst.instruction |= inst.operands[1].reg;
9a64e435 6922 inst.instruction |= Rn << 16;
c19d1205 6923}
09d92015 6924
c19d1205
ZW
6925static void
6926do_rd_rn_rm (void)
6927{
6928 inst.instruction |= inst.operands[0].reg << 12;
6929 inst.instruction |= inst.operands[1].reg << 16;
6930 inst.instruction |= inst.operands[2].reg;
6931}
a737bd4d 6932
c19d1205
ZW
6933static void
6934do_rm_rd_rn (void)
6935{
6936 inst.instruction |= inst.operands[0].reg;
6937 inst.instruction |= inst.operands[1].reg << 12;
6938 inst.instruction |= inst.operands[2].reg << 16;
6939}
09d92015 6940
c19d1205
ZW
6941static void
6942do_imm0 (void)
6943{
6944 inst.instruction |= inst.operands[0].imm;
6945}
09d92015 6946
c19d1205
ZW
6947static void
6948do_rd_cpaddr (void)
6949{
6950 inst.instruction |= inst.operands[0].reg << 12;
6951 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6952}
a737bd4d 6953
c19d1205
ZW
6954/* ARM instructions, in alphabetical order by function name (except
6955 that wrapper functions appear immediately after the function they
6956 wrap). */
09d92015 6957
c19d1205
ZW
6958/* This is a pseudo-op of the form "adr rd, label" to be converted
6959 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6960
6961static void
c19d1205 6962do_adr (void)
09d92015 6963{
c19d1205 6964 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6965
c19d1205
ZW
6966 /* Frag hacking will turn this into a sub instruction if the offset turns
6967 out to be negative. */
6968 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6969 inst.reloc.pc_rel = 1;
2fc8bdac 6970 inst.reloc.exp.X_add_number -= 8;
c19d1205 6971}
b99bd4ef 6972
c19d1205
ZW
6973/* This is a pseudo-op of the form "adrl rd, label" to be converted
6974 into a relative address of the form:
6975 add rd, pc, #low(label-.-8)"
6976 add rd, rd, #high(label-.-8)" */
b99bd4ef 6977
c19d1205
ZW
6978static void
6979do_adrl (void)
6980{
6981 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6982
c19d1205
ZW
6983 /* Frag hacking will turn this into a sub instruction if the offset turns
6984 out to be negative. */
6985 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6986 inst.reloc.pc_rel = 1;
6987 inst.size = INSN_SIZE * 2;
2fc8bdac 6988 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6989}
6990
b99bd4ef 6991static void
c19d1205 6992do_arit (void)
b99bd4ef 6993{
c19d1205
ZW
6994 if (!inst.operands[1].present)
6995 inst.operands[1].reg = inst.operands[0].reg;
6996 inst.instruction |= inst.operands[0].reg << 12;
6997 inst.instruction |= inst.operands[1].reg << 16;
6998 encode_arm_shifter_operand (2);
6999}
b99bd4ef 7000
62b3e311
PB
7001static void
7002do_barrier (void)
7003{
7004 if (inst.operands[0].present)
7005 {
7006 constraint ((inst.instruction & 0xf0) != 0x40
7007 && inst.operands[0].imm != 0xf,
bd3ba5d1 7008 _("bad barrier type"));
62b3e311
PB
7009 inst.instruction |= inst.operands[0].imm;
7010 }
7011 else
7012 inst.instruction |= 0xf;
7013}
7014
c19d1205
ZW
7015static void
7016do_bfc (void)
7017{
7018 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7019 constraint (msb > 32, _("bit-field extends past end of register"));
7020 /* The instruction encoding stores the LSB and MSB,
7021 not the LSB and width. */
7022 inst.instruction |= inst.operands[0].reg << 12;
7023 inst.instruction |= inst.operands[1].imm << 7;
7024 inst.instruction |= (msb - 1) << 16;
7025}
b99bd4ef 7026
c19d1205
ZW
7027static void
7028do_bfi (void)
7029{
7030 unsigned int msb;
b99bd4ef 7031
c19d1205
ZW
7032 /* #0 in second position is alternative syntax for bfc, which is
7033 the same instruction but with REG_PC in the Rm field. */
7034 if (!inst.operands[1].isreg)
7035 inst.operands[1].reg = REG_PC;
b99bd4ef 7036
c19d1205
ZW
7037 msb = inst.operands[2].imm + inst.operands[3].imm;
7038 constraint (msb > 32, _("bit-field extends past end of register"));
7039 /* The instruction encoding stores the LSB and MSB,
7040 not the LSB and width. */
7041 inst.instruction |= inst.operands[0].reg << 12;
7042 inst.instruction |= inst.operands[1].reg;
7043 inst.instruction |= inst.operands[2].imm << 7;
7044 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7045}
7046
b99bd4ef 7047static void
c19d1205 7048do_bfx (void)
b99bd4ef 7049{
c19d1205
ZW
7050 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7051 _("bit-field extends past end of register"));
7052 inst.instruction |= inst.operands[0].reg << 12;
7053 inst.instruction |= inst.operands[1].reg;
7054 inst.instruction |= inst.operands[2].imm << 7;
7055 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7056}
09d92015 7057
c19d1205
ZW
7058/* ARM V5 breakpoint instruction (argument parse)
7059 BKPT <16 bit unsigned immediate>
7060 Instruction is not conditional.
7061 The bit pattern given in insns[] has the COND_ALWAYS condition,
7062 and it is an error if the caller tried to override that. */
b99bd4ef 7063
c19d1205
ZW
7064static void
7065do_bkpt (void)
7066{
7067 /* Top 12 of 16 bits to bits 19:8. */
7068 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7069
c19d1205
ZW
7070 /* Bottom 4 of 16 bits to bits 3:0. */
7071 inst.instruction |= inst.operands[0].imm & 0xf;
7072}
09d92015 7073
c19d1205
ZW
7074static void
7075encode_branch (int default_reloc)
7076{
7077 if (inst.operands[0].hasreloc)
7078 {
7079 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7080 _("the only suffix valid here is '(plt)'"));
267bf995 7081 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7082 }
b99bd4ef 7083 else
c19d1205 7084 {
21d799b5 7085 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7086 }
2fc8bdac 7087 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7088}
7089
b99bd4ef 7090static void
c19d1205 7091do_branch (void)
b99bd4ef 7092{
39b41c9c
PB
7093#ifdef OBJ_ELF
7094 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7095 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7096 else
7097#endif
7098 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7099}
7100
7101static void
7102do_bl (void)
7103{
7104#ifdef OBJ_ELF
7105 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7106 {
7107 if (inst.cond == COND_ALWAYS)
7108 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7109 else
7110 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7111 }
7112 else
7113#endif
7114 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7115}
b99bd4ef 7116
c19d1205
ZW
7117/* ARM V5 branch-link-exchange instruction (argument parse)
7118 BLX <target_addr> ie BLX(1)
7119 BLX{<condition>} <Rm> ie BLX(2)
7120 Unfortunately, there are two different opcodes for this mnemonic.
7121 So, the insns[].value is not used, and the code here zaps values
7122 into inst.instruction.
7123 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7124
c19d1205
ZW
7125static void
7126do_blx (void)
7127{
7128 if (inst.operands[0].isreg)
b99bd4ef 7129 {
c19d1205
ZW
7130 /* Arg is a register; the opcode provided by insns[] is correct.
7131 It is not illegal to do "blx pc", just useless. */
7132 if (inst.operands[0].reg == REG_PC)
7133 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7134
c19d1205
ZW
7135 inst.instruction |= inst.operands[0].reg;
7136 }
7137 else
b99bd4ef 7138 {
c19d1205 7139 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7140 conditionally, and the opcode must be adjusted.
7141 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7142 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7143 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7144 inst.instruction = 0xfa000000;
267bf995 7145 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7146 }
c19d1205
ZW
7147}
7148
7149static void
7150do_bx (void)
7151{
845b51d6
PB
7152 bfd_boolean want_reloc;
7153
c19d1205
ZW
7154 if (inst.operands[0].reg == REG_PC)
7155 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7156
c19d1205 7157 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7158 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7159 it is for ARMv4t or earlier. */
7160 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7161 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7162 want_reloc = TRUE;
7163
5ad34203 7164#ifdef OBJ_ELF
845b51d6 7165 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7166#endif
584206db 7167 want_reloc = FALSE;
845b51d6
PB
7168
7169 if (want_reloc)
7170 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7171}
7172
c19d1205
ZW
7173
7174/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7175
7176static void
c19d1205 7177do_bxj (void)
a737bd4d 7178{
c19d1205
ZW
7179 if (inst.operands[0].reg == REG_PC)
7180 as_tsktsk (_("use of r15 in bxj is not really useful"));
7181
7182 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7183}
7184
c19d1205
ZW
7185/* Co-processor data operation:
7186 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7187 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7188static void
7189do_cdp (void)
7190{
7191 inst.instruction |= inst.operands[0].reg << 8;
7192 inst.instruction |= inst.operands[1].imm << 20;
7193 inst.instruction |= inst.operands[2].reg << 12;
7194 inst.instruction |= inst.operands[3].reg << 16;
7195 inst.instruction |= inst.operands[4].reg;
7196 inst.instruction |= inst.operands[5].imm << 5;
7197}
a737bd4d
NC
7198
7199static void
c19d1205 7200do_cmp (void)
a737bd4d 7201{
c19d1205
ZW
7202 inst.instruction |= inst.operands[0].reg << 16;
7203 encode_arm_shifter_operand (1);
a737bd4d
NC
7204}
7205
c19d1205
ZW
7206/* Transfer between coprocessor and ARM registers.
7207 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7208 MRC2
7209 MCR{cond}
7210 MCR2
7211
7212 No special properties. */
09d92015
MM
7213
7214static void
c19d1205 7215do_co_reg (void)
09d92015 7216{
fdfde340
JM
7217 unsigned Rd;
7218
7219 Rd = inst.operands[2].reg;
7220 if (thumb_mode)
7221 {
7222 if (inst.instruction == 0xee000010
7223 || inst.instruction == 0xfe000010)
7224 /* MCR, MCR2 */
7225 reject_bad_reg (Rd);
7226 else
7227 /* MRC, MRC2 */
7228 constraint (Rd == REG_SP, BAD_SP);
7229 }
7230 else
7231 {
7232 /* MCR */
7233 if (inst.instruction == 0xe000010)
7234 constraint (Rd == REG_PC, BAD_PC);
7235 }
7236
7237
c19d1205
ZW
7238 inst.instruction |= inst.operands[0].reg << 8;
7239 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7240 inst.instruction |= Rd << 12;
c19d1205
ZW
7241 inst.instruction |= inst.operands[3].reg << 16;
7242 inst.instruction |= inst.operands[4].reg;
7243 inst.instruction |= inst.operands[5].imm << 5;
7244}
09d92015 7245
c19d1205
ZW
7246/* Transfer between coprocessor register and pair of ARM registers.
7247 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7248 MCRR2
7249 MRRC{cond}
7250 MRRC2
b99bd4ef 7251
c19d1205 7252 Two XScale instructions are special cases of these:
09d92015 7253
c19d1205
ZW
7254 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7255 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7256
5f4273c7 7257 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7258
c19d1205
ZW
7259static void
7260do_co_reg2c (void)
7261{
fdfde340
JM
7262 unsigned Rd, Rn;
7263
7264 Rd = inst.operands[2].reg;
7265 Rn = inst.operands[3].reg;
7266
7267 if (thumb_mode)
7268 {
7269 reject_bad_reg (Rd);
7270 reject_bad_reg (Rn);
7271 }
7272 else
7273 {
7274 constraint (Rd == REG_PC, BAD_PC);
7275 constraint (Rn == REG_PC, BAD_PC);
7276 }
7277
c19d1205
ZW
7278 inst.instruction |= inst.operands[0].reg << 8;
7279 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7280 inst.instruction |= Rd << 12;
7281 inst.instruction |= Rn << 16;
c19d1205 7282 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7283}
7284
c19d1205
ZW
7285static void
7286do_cpsi (void)
7287{
7288 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7289 if (inst.operands[1].present)
7290 {
7291 inst.instruction |= CPSI_MMOD;
7292 inst.instruction |= inst.operands[1].imm;
7293 }
c19d1205 7294}
b99bd4ef 7295
62b3e311
PB
7296static void
7297do_dbg (void)
7298{
7299 inst.instruction |= inst.operands[0].imm;
7300}
7301
b99bd4ef 7302static void
c19d1205 7303do_it (void)
b99bd4ef 7304{
c19d1205 7305 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7306 process it to do the validation as if in
7307 thumb mode, just in case the code gets
7308 assembled for thumb using the unified syntax. */
7309
c19d1205 7310 inst.size = 0;
e07e6e58
NC
7311 if (unified_syntax)
7312 {
7313 set_it_insn_type (IT_INSN);
7314 now_it.mask = (inst.instruction & 0xf) | 0x10;
7315 now_it.cc = inst.operands[0].imm;
7316 }
09d92015 7317}
b99bd4ef 7318
09d92015 7319static void
c19d1205 7320do_ldmstm (void)
ea6ef066 7321{
c19d1205
ZW
7322 int base_reg = inst.operands[0].reg;
7323 int range = inst.operands[1].imm;
ea6ef066 7324
c19d1205
ZW
7325 inst.instruction |= base_reg << 16;
7326 inst.instruction |= range;
ea6ef066 7327
c19d1205
ZW
7328 if (inst.operands[1].writeback)
7329 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7330
c19d1205 7331 if (inst.operands[0].writeback)
ea6ef066 7332 {
c19d1205
ZW
7333 inst.instruction |= WRITE_BACK;
7334 /* Check for unpredictable uses of writeback. */
7335 if (inst.instruction & LOAD_BIT)
09d92015 7336 {
c19d1205
ZW
7337 /* Not allowed in LDM type 2. */
7338 if ((inst.instruction & LDM_TYPE_2_OR_3)
7339 && ((range & (1 << REG_PC)) == 0))
7340 as_warn (_("writeback of base register is UNPREDICTABLE"));
7341 /* Only allowed if base reg not in list for other types. */
7342 else if (range & (1 << base_reg))
7343 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7344 }
7345 else /* STM. */
7346 {
7347 /* Not allowed for type 2. */
7348 if (inst.instruction & LDM_TYPE_2_OR_3)
7349 as_warn (_("writeback of base register is UNPREDICTABLE"));
7350 /* Only allowed if base reg not in list, or first in list. */
7351 else if ((range & (1 << base_reg))
7352 && (range & ((1 << base_reg) - 1)))
7353 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7354 }
ea6ef066 7355 }
a737bd4d
NC
7356}
7357
c19d1205
ZW
7358/* ARMv5TE load-consecutive (argument parse)
7359 Mode is like LDRH.
7360
7361 LDRccD R, mode
7362 STRccD R, mode. */
7363
a737bd4d 7364static void
c19d1205 7365do_ldrd (void)
a737bd4d 7366{
c19d1205
ZW
7367 constraint (inst.operands[0].reg % 2 != 0,
7368 _("first destination register must be even"));
7369 constraint (inst.operands[1].present
7370 && inst.operands[1].reg != inst.operands[0].reg + 1,
7371 _("can only load two consecutive registers"));
7372 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7373 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7374
c19d1205
ZW
7375 if (!inst.operands[1].present)
7376 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7377
c19d1205 7378 if (inst.instruction & LOAD_BIT)
a737bd4d 7379 {
c19d1205
ZW
7380 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7381 register and the first register written; we have to diagnose
7382 overlap between the base and the second register written here. */
ea6ef066 7383
c19d1205
ZW
7384 if (inst.operands[2].reg == inst.operands[1].reg
7385 && (inst.operands[2].writeback || inst.operands[2].postind))
7386 as_warn (_("base register written back, and overlaps "
7387 "second destination register"));
b05fe5cf 7388
c19d1205
ZW
7389 /* For an index-register load, the index register must not overlap the
7390 destination (even if not write-back). */
7391 else if (inst.operands[2].immisreg
ca3f61f7
NC
7392 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7393 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7394 as_warn (_("index register overlaps destination register"));
b05fe5cf 7395 }
c19d1205
ZW
7396
7397 inst.instruction |= inst.operands[0].reg << 12;
7398 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7399}
7400
7401static void
c19d1205 7402do_ldrex (void)
b05fe5cf 7403{
c19d1205
ZW
7404 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7405 || inst.operands[1].postind || inst.operands[1].writeback
7406 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7407 || inst.operands[1].negative
7408 /* This can arise if the programmer has written
7409 strex rN, rM, foo
7410 or if they have mistakenly used a register name as the last
7411 operand, eg:
7412 strex rN, rM, rX
7413 It is very difficult to distinguish between these two cases
7414 because "rX" might actually be a label. ie the register
7415 name has been occluded by a symbol of the same name. So we
7416 just generate a general 'bad addressing mode' type error
7417 message and leave it up to the programmer to discover the
7418 true cause and fix their mistake. */
7419 || (inst.operands[1].reg == REG_PC),
7420 BAD_ADDR_MODE);
b05fe5cf 7421
c19d1205
ZW
7422 constraint (inst.reloc.exp.X_op != O_constant
7423 || inst.reloc.exp.X_add_number != 0,
7424 _("offset must be zero in ARM encoding"));
b05fe5cf 7425
c19d1205
ZW
7426 inst.instruction |= inst.operands[0].reg << 12;
7427 inst.instruction |= inst.operands[1].reg << 16;
7428 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7429}
7430
7431static void
c19d1205 7432do_ldrexd (void)
b05fe5cf 7433{
c19d1205
ZW
7434 constraint (inst.operands[0].reg % 2 != 0,
7435 _("even register required"));
7436 constraint (inst.operands[1].present
7437 && inst.operands[1].reg != inst.operands[0].reg + 1,
7438 _("can only load two consecutive registers"));
7439 /* If op 1 were present and equal to PC, this function wouldn't
7440 have been called in the first place. */
7441 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7442
c19d1205
ZW
7443 inst.instruction |= inst.operands[0].reg << 12;
7444 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7445}
7446
7447static void
c19d1205 7448do_ldst (void)
b05fe5cf 7449{
c19d1205
ZW
7450 inst.instruction |= inst.operands[0].reg << 12;
7451 if (!inst.operands[1].isreg)
7452 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7453 return;
c19d1205 7454 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7455}
7456
7457static void
c19d1205 7458do_ldstt (void)
b05fe5cf 7459{
c19d1205
ZW
7460 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7461 reject [Rn,...]. */
7462 if (inst.operands[1].preind)
b05fe5cf 7463 {
bd3ba5d1
NC
7464 constraint (inst.reloc.exp.X_op != O_constant
7465 || inst.reloc.exp.X_add_number != 0,
c19d1205 7466 _("this instruction requires a post-indexed address"));
b05fe5cf 7467
c19d1205
ZW
7468 inst.operands[1].preind = 0;
7469 inst.operands[1].postind = 1;
7470 inst.operands[1].writeback = 1;
b05fe5cf 7471 }
c19d1205
ZW
7472 inst.instruction |= inst.operands[0].reg << 12;
7473 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7474}
b05fe5cf 7475
c19d1205 7476/* Halfword and signed-byte load/store operations. */
b05fe5cf 7477
c19d1205
ZW
7478static void
7479do_ldstv4 (void)
7480{
ff4a8d2b 7481 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7482 inst.instruction |= inst.operands[0].reg << 12;
7483 if (!inst.operands[1].isreg)
7484 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7485 return;
c19d1205 7486 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7487}
7488
7489static void
c19d1205 7490do_ldsttv4 (void)
b05fe5cf 7491{
c19d1205
ZW
7492 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7493 reject [Rn,...]. */
7494 if (inst.operands[1].preind)
b05fe5cf 7495 {
bd3ba5d1
NC
7496 constraint (inst.reloc.exp.X_op != O_constant
7497 || inst.reloc.exp.X_add_number != 0,
c19d1205 7498 _("this instruction requires a post-indexed address"));
b05fe5cf 7499
c19d1205
ZW
7500 inst.operands[1].preind = 0;
7501 inst.operands[1].postind = 1;
7502 inst.operands[1].writeback = 1;
b05fe5cf 7503 }
c19d1205
ZW
7504 inst.instruction |= inst.operands[0].reg << 12;
7505 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7506}
b05fe5cf 7507
c19d1205
ZW
7508/* Co-processor register load/store.
7509 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7510static void
7511do_lstc (void)
7512{
7513 inst.instruction |= inst.operands[0].reg << 8;
7514 inst.instruction |= inst.operands[1].reg << 12;
7515 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7516}
7517
b05fe5cf 7518static void
c19d1205 7519do_mlas (void)
b05fe5cf 7520{
8fb9d7b9 7521 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7522 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7523 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7524 && !(inst.instruction & 0x00400000))
8fb9d7b9 7525 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7526
c19d1205
ZW
7527 inst.instruction |= inst.operands[0].reg << 16;
7528 inst.instruction |= inst.operands[1].reg;
7529 inst.instruction |= inst.operands[2].reg << 8;
7530 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7531}
b05fe5cf 7532
c19d1205
ZW
7533static void
7534do_mov (void)
7535{
7536 inst.instruction |= inst.operands[0].reg << 12;
7537 encode_arm_shifter_operand (1);
7538}
b05fe5cf 7539
c19d1205
ZW
7540/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7541static void
7542do_mov16 (void)
7543{
b6895b4f
PB
7544 bfd_vma imm;
7545 bfd_boolean top;
7546
7547 top = (inst.instruction & 0x00400000) != 0;
7548 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7549 _(":lower16: not allowed this instruction"));
7550 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7551 _(":upper16: not allowed instruction"));
c19d1205 7552 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7553 if (inst.reloc.type == BFD_RELOC_UNUSED)
7554 {
7555 imm = inst.reloc.exp.X_add_number;
7556 /* The value is in two pieces: 0:11, 16:19. */
7557 inst.instruction |= (imm & 0x00000fff);
7558 inst.instruction |= (imm & 0x0000f000) << 4;
7559 }
b05fe5cf 7560}
b99bd4ef 7561
037e8744
JB
7562static void do_vfp_nsyn_opcode (const char *);
7563
7564static int
7565do_vfp_nsyn_mrs (void)
7566{
7567 if (inst.operands[0].isvec)
7568 {
7569 if (inst.operands[1].reg != 1)
7570 first_error (_("operand 1 must be FPSCR"));
7571 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7572 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7573 do_vfp_nsyn_opcode ("fmstat");
7574 }
7575 else if (inst.operands[1].isvec)
7576 do_vfp_nsyn_opcode ("fmrx");
7577 else
7578 return FAIL;
5f4273c7 7579
037e8744
JB
7580 return SUCCESS;
7581}
7582
7583static int
7584do_vfp_nsyn_msr (void)
7585{
7586 if (inst.operands[0].isvec)
7587 do_vfp_nsyn_opcode ("fmxr");
7588 else
7589 return FAIL;
7590
7591 return SUCCESS;
7592}
7593
f7c21dc7
NC
7594static void
7595do_vmrs (void)
7596{
7597 unsigned Rt = inst.operands[0].reg;
7598
7599 if (thumb_mode && inst.operands[0].reg == REG_SP)
7600 {
7601 inst.error = BAD_SP;
7602 return;
7603 }
7604
7605 /* APSR_ sets isvec. All other refs to PC are illegal. */
7606 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7607 {
7608 inst.error = BAD_PC;
7609 return;
7610 }
7611
7612 if (inst.operands[1].reg != 1)
7613 first_error (_("operand 1 must be FPSCR"));
7614
7615 inst.instruction |= (Rt << 12);
7616}
7617
7618static void
7619do_vmsr (void)
7620{
7621 unsigned Rt = inst.operands[1].reg;
7622
7623 if (thumb_mode)
7624 reject_bad_reg (Rt);
7625 else if (Rt == REG_PC)
7626 {
7627 inst.error = BAD_PC;
7628 return;
7629 }
7630
7631 if (inst.operands[0].reg != 1)
7632 first_error (_("operand 0 must be FPSCR"));
7633
7634 inst.instruction |= (Rt << 12);
7635}
7636
b99bd4ef 7637static void
c19d1205 7638do_mrs (void)
b99bd4ef 7639{
037e8744
JB
7640 if (do_vfp_nsyn_mrs () == SUCCESS)
7641 return;
7642
c19d1205
ZW
7643 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7644 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7645 != (PSR_c|PSR_f),
7646 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7647 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7648 inst.instruction |= inst.operands[0].reg << 12;
7649 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7650}
b99bd4ef 7651
c19d1205
ZW
7652/* Two possible forms:
7653 "{C|S}PSR_<field>, Rm",
7654 "{C|S}PSR_f, #expression". */
b99bd4ef 7655
c19d1205
ZW
7656static void
7657do_msr (void)
7658{
037e8744
JB
7659 if (do_vfp_nsyn_msr () == SUCCESS)
7660 return;
7661
c19d1205
ZW
7662 inst.instruction |= inst.operands[0].imm;
7663 if (inst.operands[1].isreg)
7664 inst.instruction |= inst.operands[1].reg;
7665 else
b99bd4ef 7666 {
c19d1205
ZW
7667 inst.instruction |= INST_IMMEDIATE;
7668 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7669 inst.reloc.pc_rel = 0;
b99bd4ef 7670 }
b99bd4ef
NC
7671}
7672
c19d1205
ZW
7673static void
7674do_mul (void)
a737bd4d 7675{
ff4a8d2b
NC
7676 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7677
c19d1205
ZW
7678 if (!inst.operands[2].present)
7679 inst.operands[2].reg = inst.operands[0].reg;
7680 inst.instruction |= inst.operands[0].reg << 16;
7681 inst.instruction |= inst.operands[1].reg;
7682 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7683
8fb9d7b9
MS
7684 if (inst.operands[0].reg == inst.operands[1].reg
7685 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7686 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7687}
7688
c19d1205
ZW
7689/* Long Multiply Parser
7690 UMULL RdLo, RdHi, Rm, Rs
7691 SMULL RdLo, RdHi, Rm, Rs
7692 UMLAL RdLo, RdHi, Rm, Rs
7693 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7694
7695static void
c19d1205 7696do_mull (void)
b99bd4ef 7697{
c19d1205
ZW
7698 inst.instruction |= inst.operands[0].reg << 12;
7699 inst.instruction |= inst.operands[1].reg << 16;
7700 inst.instruction |= inst.operands[2].reg;
7701 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7702
682b27ad
PB
7703 /* rdhi and rdlo must be different. */
7704 if (inst.operands[0].reg == inst.operands[1].reg)
7705 as_tsktsk (_("rdhi and rdlo must be different"));
7706
7707 /* rdhi, rdlo and rm must all be different before armv6. */
7708 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7709 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7710 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7711 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7712}
b99bd4ef 7713
c19d1205
ZW
7714static void
7715do_nop (void)
7716{
e7495e45
NS
7717 if (inst.operands[0].present
7718 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7719 {
7720 /* Architectural NOP hints are CPSR sets with no bits selected. */
7721 inst.instruction &= 0xf0000000;
e7495e45
NS
7722 inst.instruction |= 0x0320f000;
7723 if (inst.operands[0].present)
7724 inst.instruction |= inst.operands[0].imm;
c19d1205 7725 }
b99bd4ef
NC
7726}
7727
c19d1205
ZW
7728/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7729 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7730 Condition defaults to COND_ALWAYS.
7731 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7732
7733static void
c19d1205 7734do_pkhbt (void)
b99bd4ef 7735{
c19d1205
ZW
7736 inst.instruction |= inst.operands[0].reg << 12;
7737 inst.instruction |= inst.operands[1].reg << 16;
7738 inst.instruction |= inst.operands[2].reg;
7739 if (inst.operands[3].present)
7740 encode_arm_shift (3);
7741}
b99bd4ef 7742
c19d1205 7743/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7744
c19d1205
ZW
7745static void
7746do_pkhtb (void)
7747{
7748 if (!inst.operands[3].present)
b99bd4ef 7749 {
c19d1205
ZW
7750 /* If the shift specifier is omitted, turn the instruction
7751 into pkhbt rd, rm, rn. */
7752 inst.instruction &= 0xfff00010;
7753 inst.instruction |= inst.operands[0].reg << 12;
7754 inst.instruction |= inst.operands[1].reg;
7755 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7756 }
7757 else
7758 {
c19d1205
ZW
7759 inst.instruction |= inst.operands[0].reg << 12;
7760 inst.instruction |= inst.operands[1].reg << 16;
7761 inst.instruction |= inst.operands[2].reg;
7762 encode_arm_shift (3);
b99bd4ef
NC
7763 }
7764}
7765
c19d1205
ZW
7766/* ARMv5TE: Preload-Cache
7767
7768 PLD <addr_mode>
7769
7770 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7771
7772static void
c19d1205 7773do_pld (void)
b99bd4ef 7774{
c19d1205
ZW
7775 constraint (!inst.operands[0].isreg,
7776 _("'[' expected after PLD mnemonic"));
7777 constraint (inst.operands[0].postind,
7778 _("post-indexed expression used in preload instruction"));
7779 constraint (inst.operands[0].writeback,
7780 _("writeback used in preload instruction"));
7781 constraint (!inst.operands[0].preind,
7782 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7783 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7784}
b99bd4ef 7785
62b3e311
PB
7786/* ARMv7: PLI <addr_mode> */
7787static void
7788do_pli (void)
7789{
7790 constraint (!inst.operands[0].isreg,
7791 _("'[' expected after PLI mnemonic"));
7792 constraint (inst.operands[0].postind,
7793 _("post-indexed expression used in preload instruction"));
7794 constraint (inst.operands[0].writeback,
7795 _("writeback used in preload instruction"));
7796 constraint (!inst.operands[0].preind,
7797 _("unindexed addressing used in preload instruction"));
7798 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7799 inst.instruction &= ~PRE_INDEX;
7800}
7801
c19d1205
ZW
7802static void
7803do_push_pop (void)
7804{
7805 inst.operands[1] = inst.operands[0];
7806 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7807 inst.operands[0].isreg = 1;
7808 inst.operands[0].writeback = 1;
7809 inst.operands[0].reg = REG_SP;
7810 do_ldmstm ();
7811}
b99bd4ef 7812
c19d1205
ZW
7813/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7814 word at the specified address and the following word
7815 respectively.
7816 Unconditionally executed.
7817 Error if Rn is R15. */
b99bd4ef 7818
c19d1205
ZW
7819static void
7820do_rfe (void)
7821{
7822 inst.instruction |= inst.operands[0].reg << 16;
7823 if (inst.operands[0].writeback)
7824 inst.instruction |= WRITE_BACK;
7825}
b99bd4ef 7826
c19d1205 7827/* ARM V6 ssat (argument parse). */
b99bd4ef 7828
c19d1205
ZW
7829static void
7830do_ssat (void)
7831{
7832 inst.instruction |= inst.operands[0].reg << 12;
7833 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7834 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7835
c19d1205
ZW
7836 if (inst.operands[3].present)
7837 encode_arm_shift (3);
b99bd4ef
NC
7838}
7839
c19d1205 7840/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7841
7842static void
c19d1205 7843do_usat (void)
b99bd4ef 7844{
c19d1205
ZW
7845 inst.instruction |= inst.operands[0].reg << 12;
7846 inst.instruction |= inst.operands[1].imm << 16;
7847 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7848
c19d1205
ZW
7849 if (inst.operands[3].present)
7850 encode_arm_shift (3);
b99bd4ef
NC
7851}
7852
c19d1205 7853/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7854
7855static void
c19d1205 7856do_ssat16 (void)
09d92015 7857{
c19d1205
ZW
7858 inst.instruction |= inst.operands[0].reg << 12;
7859 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7860 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7861}
7862
c19d1205
ZW
7863static void
7864do_usat16 (void)
a737bd4d 7865{
c19d1205
ZW
7866 inst.instruction |= inst.operands[0].reg << 12;
7867 inst.instruction |= inst.operands[1].imm << 16;
7868 inst.instruction |= inst.operands[2].reg;
7869}
a737bd4d 7870
c19d1205
ZW
7871/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7872 preserving the other bits.
a737bd4d 7873
c19d1205
ZW
7874 setend <endian_specifier>, where <endian_specifier> is either
7875 BE or LE. */
a737bd4d 7876
c19d1205
ZW
7877static void
7878do_setend (void)
7879{
7880 if (inst.operands[0].imm)
7881 inst.instruction |= 0x200;
a737bd4d
NC
7882}
7883
7884static void
c19d1205 7885do_shift (void)
a737bd4d 7886{
c19d1205
ZW
7887 unsigned int Rm = (inst.operands[1].present
7888 ? inst.operands[1].reg
7889 : inst.operands[0].reg);
a737bd4d 7890
c19d1205
ZW
7891 inst.instruction |= inst.operands[0].reg << 12;
7892 inst.instruction |= Rm;
7893 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7894 {
c19d1205
ZW
7895 inst.instruction |= inst.operands[2].reg << 8;
7896 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7897 }
7898 else
c19d1205 7899 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7900}
7901
09d92015 7902static void
3eb17e6b 7903do_smc (void)
09d92015 7904{
3eb17e6b 7905 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7906 inst.reloc.pc_rel = 0;
09d92015
MM
7907}
7908
09d92015 7909static void
c19d1205 7910do_swi (void)
09d92015 7911{
c19d1205
ZW
7912 inst.reloc.type = BFD_RELOC_ARM_SWI;
7913 inst.reloc.pc_rel = 0;
09d92015
MM
7914}
7915
c19d1205
ZW
7916/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7917 SMLAxy{cond} Rd,Rm,Rs,Rn
7918 SMLAWy{cond} Rd,Rm,Rs,Rn
7919 Error if any register is R15. */
e16bb312 7920
c19d1205
ZW
7921static void
7922do_smla (void)
e16bb312 7923{
c19d1205
ZW
7924 inst.instruction |= inst.operands[0].reg << 16;
7925 inst.instruction |= inst.operands[1].reg;
7926 inst.instruction |= inst.operands[2].reg << 8;
7927 inst.instruction |= inst.operands[3].reg << 12;
7928}
a737bd4d 7929
c19d1205
ZW
7930/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7931 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7932 Error if any register is R15.
7933 Warning if Rdlo == Rdhi. */
a737bd4d 7934
c19d1205
ZW
7935static void
7936do_smlal (void)
7937{
7938 inst.instruction |= inst.operands[0].reg << 12;
7939 inst.instruction |= inst.operands[1].reg << 16;
7940 inst.instruction |= inst.operands[2].reg;
7941 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7942
c19d1205
ZW
7943 if (inst.operands[0].reg == inst.operands[1].reg)
7944 as_tsktsk (_("rdhi and rdlo must be different"));
7945}
a737bd4d 7946
c19d1205
ZW
7947/* ARM V5E (El Segundo) signed-multiply (argument parse)
7948 SMULxy{cond} Rd,Rm,Rs
7949 Error if any register is R15. */
a737bd4d 7950
c19d1205
ZW
7951static void
7952do_smul (void)
7953{
7954 inst.instruction |= inst.operands[0].reg << 16;
7955 inst.instruction |= inst.operands[1].reg;
7956 inst.instruction |= inst.operands[2].reg << 8;
7957}
a737bd4d 7958
b6702015
PB
7959/* ARM V6 srs (argument parse). The variable fields in the encoding are
7960 the same for both ARM and Thumb-2. */
a737bd4d 7961
c19d1205
ZW
7962static void
7963do_srs (void)
7964{
b6702015
PB
7965 int reg;
7966
7967 if (inst.operands[0].present)
7968 {
7969 reg = inst.operands[0].reg;
fdfde340 7970 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7971 }
7972 else
fdfde340 7973 reg = REG_SP;
b6702015
PB
7974
7975 inst.instruction |= reg << 16;
7976 inst.instruction |= inst.operands[1].imm;
7977 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7978 inst.instruction |= WRITE_BACK;
7979}
a737bd4d 7980
c19d1205 7981/* ARM V6 strex (argument parse). */
a737bd4d 7982
c19d1205
ZW
7983static void
7984do_strex (void)
7985{
7986 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7987 || inst.operands[2].postind || inst.operands[2].writeback
7988 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7989 || inst.operands[2].negative
7990 /* See comment in do_ldrex(). */
7991 || (inst.operands[2].reg == REG_PC),
7992 BAD_ADDR_MODE);
a737bd4d 7993
c19d1205
ZW
7994 constraint (inst.operands[0].reg == inst.operands[1].reg
7995 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7996
c19d1205
ZW
7997 constraint (inst.reloc.exp.X_op != O_constant
7998 || inst.reloc.exp.X_add_number != 0,
7999 _("offset must be zero in ARM encoding"));
a737bd4d 8000
c19d1205
ZW
8001 inst.instruction |= inst.operands[0].reg << 12;
8002 inst.instruction |= inst.operands[1].reg;
8003 inst.instruction |= inst.operands[2].reg << 16;
8004 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8005}
8006
8007static void
c19d1205 8008do_strexd (void)
e16bb312 8009{
c19d1205
ZW
8010 constraint (inst.operands[1].reg % 2 != 0,
8011 _("even register required"));
8012 constraint (inst.operands[2].present
8013 && inst.operands[2].reg != inst.operands[1].reg + 1,
8014 _("can only store two consecutive registers"));
8015 /* If op 2 were present and equal to PC, this function wouldn't
8016 have been called in the first place. */
8017 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8018
c19d1205
ZW
8019 constraint (inst.operands[0].reg == inst.operands[1].reg
8020 || inst.operands[0].reg == inst.operands[1].reg + 1
8021 || inst.operands[0].reg == inst.operands[3].reg,
8022 BAD_OVERLAP);
e16bb312 8023
c19d1205
ZW
8024 inst.instruction |= inst.operands[0].reg << 12;
8025 inst.instruction |= inst.operands[1].reg;
8026 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8027}
8028
c19d1205
ZW
8029/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8030 extends it to 32-bits, and adds the result to a value in another
8031 register. You can specify a rotation by 0, 8, 16, or 24 bits
8032 before extracting the 16-bit value.
8033 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8034 Condition defaults to COND_ALWAYS.
8035 Error if any register uses R15. */
8036
e16bb312 8037static void
c19d1205 8038do_sxtah (void)
e16bb312 8039{
c19d1205
ZW
8040 inst.instruction |= inst.operands[0].reg << 12;
8041 inst.instruction |= inst.operands[1].reg << 16;
8042 inst.instruction |= inst.operands[2].reg;
8043 inst.instruction |= inst.operands[3].imm << 10;
8044}
e16bb312 8045
c19d1205 8046/* ARM V6 SXTH.
e16bb312 8047
c19d1205
ZW
8048 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8049 Condition defaults to COND_ALWAYS.
8050 Error if any register uses R15. */
e16bb312
NC
8051
8052static void
c19d1205 8053do_sxth (void)
e16bb312 8054{
c19d1205
ZW
8055 inst.instruction |= inst.operands[0].reg << 12;
8056 inst.instruction |= inst.operands[1].reg;
8057 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8058}
c19d1205
ZW
8059\f
8060/* VFP instructions. In a logical order: SP variant first, monad
8061 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8062
8063static void
c19d1205 8064do_vfp_sp_monadic (void)
e16bb312 8065{
5287ad62
JB
8066 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8067 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8068}
8069
8070static void
c19d1205 8071do_vfp_sp_dyadic (void)
e16bb312 8072{
5287ad62
JB
8073 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8074 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8075 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8076}
8077
8078static void
c19d1205 8079do_vfp_sp_compare_z (void)
e16bb312 8080{
5287ad62 8081 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8082}
8083
8084static void
c19d1205 8085do_vfp_dp_sp_cvt (void)
e16bb312 8086{
5287ad62
JB
8087 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8088 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8089}
8090
8091static void
c19d1205 8092do_vfp_sp_dp_cvt (void)
e16bb312 8093{
5287ad62
JB
8094 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8095 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8096}
8097
8098static void
c19d1205 8099do_vfp_reg_from_sp (void)
e16bb312 8100{
c19d1205 8101 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8102 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8103}
8104
8105static void
c19d1205 8106do_vfp_reg2_from_sp2 (void)
e16bb312 8107{
c19d1205
ZW
8108 constraint (inst.operands[2].imm != 2,
8109 _("only two consecutive VFP SP registers allowed here"));
8110 inst.instruction |= inst.operands[0].reg << 12;
8111 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8112 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8113}
8114
8115static void
c19d1205 8116do_vfp_sp_from_reg (void)
e16bb312 8117{
5287ad62 8118 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8119 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8120}
8121
8122static void
c19d1205 8123do_vfp_sp2_from_reg2 (void)
e16bb312 8124{
c19d1205
ZW
8125 constraint (inst.operands[0].imm != 2,
8126 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8127 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8128 inst.instruction |= inst.operands[1].reg << 12;
8129 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8130}
8131
8132static void
c19d1205 8133do_vfp_sp_ldst (void)
e16bb312 8134{
5287ad62 8135 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8136 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8137}
8138
8139static void
c19d1205 8140do_vfp_dp_ldst (void)
e16bb312 8141{
5287ad62 8142 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8143 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8144}
8145
c19d1205 8146
e16bb312 8147static void
c19d1205 8148vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8149{
c19d1205
ZW
8150 if (inst.operands[0].writeback)
8151 inst.instruction |= WRITE_BACK;
8152 else
8153 constraint (ldstm_type != VFP_LDSTMIA,
8154 _("this addressing mode requires base-register writeback"));
8155 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8156 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8157 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8158}
8159
8160static void
c19d1205 8161vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8162{
c19d1205 8163 int count;
e16bb312 8164
c19d1205
ZW
8165 if (inst.operands[0].writeback)
8166 inst.instruction |= WRITE_BACK;
8167 else
8168 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8169 _("this addressing mode requires base-register writeback"));
e16bb312 8170
c19d1205 8171 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8172 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8173
c19d1205
ZW
8174 count = inst.operands[1].imm << 1;
8175 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8176 count += 1;
e16bb312 8177
c19d1205 8178 inst.instruction |= count;
e16bb312
NC
8179}
8180
8181static void
c19d1205 8182do_vfp_sp_ldstmia (void)
e16bb312 8183{
c19d1205 8184 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8185}
8186
8187static void
c19d1205 8188do_vfp_sp_ldstmdb (void)
e16bb312 8189{
c19d1205 8190 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8191}
8192
8193static void
c19d1205 8194do_vfp_dp_ldstmia (void)
e16bb312 8195{
c19d1205 8196 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8197}
8198
8199static void
c19d1205 8200do_vfp_dp_ldstmdb (void)
e16bb312 8201{
c19d1205 8202 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8203}
8204
8205static void
c19d1205 8206do_vfp_xp_ldstmia (void)
e16bb312 8207{
c19d1205
ZW
8208 vfp_dp_ldstm (VFP_LDSTMIAX);
8209}
e16bb312 8210
c19d1205
ZW
8211static void
8212do_vfp_xp_ldstmdb (void)
8213{
8214 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8215}
5287ad62
JB
8216
8217static void
8218do_vfp_dp_rd_rm (void)
8219{
8220 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8221 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8222}
8223
8224static void
8225do_vfp_dp_rn_rd (void)
8226{
8227 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8228 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8229}
8230
8231static void
8232do_vfp_dp_rd_rn (void)
8233{
8234 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8235 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8236}
8237
8238static void
8239do_vfp_dp_rd_rn_rm (void)
8240{
8241 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8242 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8243 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8244}
8245
8246static void
8247do_vfp_dp_rd (void)
8248{
8249 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8250}
8251
8252static void
8253do_vfp_dp_rm_rd_rn (void)
8254{
8255 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8256 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8257 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8258}
8259
8260/* VFPv3 instructions. */
8261static void
8262do_vfp_sp_const (void)
8263{
8264 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8265 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8266 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8267}
8268
8269static void
8270do_vfp_dp_const (void)
8271{
8272 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8273 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8274 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8275}
8276
8277static void
8278vfp_conv (int srcsize)
8279{
8280 unsigned immbits = srcsize - inst.operands[1].imm;
8281 inst.instruction |= (immbits & 1) << 5;
8282 inst.instruction |= (immbits >> 1);
8283}
8284
8285static void
8286do_vfp_sp_conv_16 (void)
8287{
8288 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8289 vfp_conv (16);
8290}
8291
8292static void
8293do_vfp_dp_conv_16 (void)
8294{
8295 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8296 vfp_conv (16);
8297}
8298
8299static void
8300do_vfp_sp_conv_32 (void)
8301{
8302 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8303 vfp_conv (32);
8304}
8305
8306static void
8307do_vfp_dp_conv_32 (void)
8308{
8309 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8310 vfp_conv (32);
8311}
c19d1205
ZW
8312\f
8313/* FPA instructions. Also in a logical order. */
e16bb312 8314
c19d1205
ZW
8315static void
8316do_fpa_cmp (void)
8317{
8318 inst.instruction |= inst.operands[0].reg << 16;
8319 inst.instruction |= inst.operands[1].reg;
8320}
b99bd4ef
NC
8321
8322static void
c19d1205 8323do_fpa_ldmstm (void)
b99bd4ef 8324{
c19d1205
ZW
8325 inst.instruction |= inst.operands[0].reg << 12;
8326 switch (inst.operands[1].imm)
8327 {
8328 case 1: inst.instruction |= CP_T_X; break;
8329 case 2: inst.instruction |= CP_T_Y; break;
8330 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8331 case 4: break;
8332 default: abort ();
8333 }
b99bd4ef 8334
c19d1205
ZW
8335 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8336 {
8337 /* The instruction specified "ea" or "fd", so we can only accept
8338 [Rn]{!}. The instruction does not really support stacking or
8339 unstacking, so we have to emulate these by setting appropriate
8340 bits and offsets. */
8341 constraint (inst.reloc.exp.X_op != O_constant
8342 || inst.reloc.exp.X_add_number != 0,
8343 _("this instruction does not support indexing"));
b99bd4ef 8344
c19d1205
ZW
8345 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8346 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8347
c19d1205
ZW
8348 if (!(inst.instruction & INDEX_UP))
8349 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8350
c19d1205
ZW
8351 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8352 {
8353 inst.operands[2].preind = 0;
8354 inst.operands[2].postind = 1;
8355 }
8356 }
b99bd4ef 8357
c19d1205 8358 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8359}
c19d1205
ZW
8360\f
8361/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8362
c19d1205
ZW
8363static void
8364do_iwmmxt_tandorc (void)
8365{
8366 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8367}
b99bd4ef 8368
c19d1205
ZW
8369static void
8370do_iwmmxt_textrc (void)
8371{
8372 inst.instruction |= inst.operands[0].reg << 12;
8373 inst.instruction |= inst.operands[1].imm;
8374}
b99bd4ef
NC
8375
8376static void
c19d1205 8377do_iwmmxt_textrm (void)
b99bd4ef 8378{
c19d1205
ZW
8379 inst.instruction |= inst.operands[0].reg << 12;
8380 inst.instruction |= inst.operands[1].reg << 16;
8381 inst.instruction |= inst.operands[2].imm;
8382}
b99bd4ef 8383
c19d1205
ZW
8384static void
8385do_iwmmxt_tinsr (void)
8386{
8387 inst.instruction |= inst.operands[0].reg << 16;
8388 inst.instruction |= inst.operands[1].reg << 12;
8389 inst.instruction |= inst.operands[2].imm;
8390}
b99bd4ef 8391
c19d1205
ZW
8392static void
8393do_iwmmxt_tmia (void)
8394{
8395 inst.instruction |= inst.operands[0].reg << 5;
8396 inst.instruction |= inst.operands[1].reg;
8397 inst.instruction |= inst.operands[2].reg << 12;
8398}
b99bd4ef 8399
c19d1205
ZW
8400static void
8401do_iwmmxt_waligni (void)
8402{
8403 inst.instruction |= inst.operands[0].reg << 12;
8404 inst.instruction |= inst.operands[1].reg << 16;
8405 inst.instruction |= inst.operands[2].reg;
8406 inst.instruction |= inst.operands[3].imm << 20;
8407}
b99bd4ef 8408
2d447fca
JM
8409static void
8410do_iwmmxt_wmerge (void)
8411{
8412 inst.instruction |= inst.operands[0].reg << 12;
8413 inst.instruction |= inst.operands[1].reg << 16;
8414 inst.instruction |= inst.operands[2].reg;
8415 inst.instruction |= inst.operands[3].imm << 21;
8416}
8417
c19d1205
ZW
8418static void
8419do_iwmmxt_wmov (void)
8420{
8421 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8422 inst.instruction |= inst.operands[0].reg << 12;
8423 inst.instruction |= inst.operands[1].reg << 16;
8424 inst.instruction |= inst.operands[1].reg;
8425}
b99bd4ef 8426
c19d1205
ZW
8427static void
8428do_iwmmxt_wldstbh (void)
8429{
8f06b2d8 8430 int reloc;
c19d1205 8431 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8432 if (thumb_mode)
8433 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8434 else
8435 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8436 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8437}
8438
c19d1205
ZW
8439static void
8440do_iwmmxt_wldstw (void)
8441{
8442 /* RIWR_RIWC clears .isreg for a control register. */
8443 if (!inst.operands[0].isreg)
8444 {
8445 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8446 inst.instruction |= 0xf0000000;
8447 }
b99bd4ef 8448
c19d1205
ZW
8449 inst.instruction |= inst.operands[0].reg << 12;
8450 encode_arm_cp_address (1, TRUE, TRUE, 0);
8451}
b99bd4ef
NC
8452
8453static void
c19d1205 8454do_iwmmxt_wldstd (void)
b99bd4ef 8455{
c19d1205 8456 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8457 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8458 && inst.operands[1].immisreg)
8459 {
8460 inst.instruction &= ~0x1a000ff;
8461 inst.instruction |= (0xf << 28);
8462 if (inst.operands[1].preind)
8463 inst.instruction |= PRE_INDEX;
8464 if (!inst.operands[1].negative)
8465 inst.instruction |= INDEX_UP;
8466 if (inst.operands[1].writeback)
8467 inst.instruction |= WRITE_BACK;
8468 inst.instruction |= inst.operands[1].reg << 16;
8469 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8470 inst.instruction |= inst.operands[1].imm;
8471 }
8472 else
8473 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8474}
b99bd4ef 8475
c19d1205
ZW
8476static void
8477do_iwmmxt_wshufh (void)
8478{
8479 inst.instruction |= inst.operands[0].reg << 12;
8480 inst.instruction |= inst.operands[1].reg << 16;
8481 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8482 inst.instruction |= (inst.operands[2].imm & 0x0f);
8483}
b99bd4ef 8484
c19d1205
ZW
8485static void
8486do_iwmmxt_wzero (void)
8487{
8488 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8489 inst.instruction |= inst.operands[0].reg;
8490 inst.instruction |= inst.operands[0].reg << 12;
8491 inst.instruction |= inst.operands[0].reg << 16;
8492}
2d447fca
JM
8493
8494static void
8495do_iwmmxt_wrwrwr_or_imm5 (void)
8496{
8497 if (inst.operands[2].isreg)
8498 do_rd_rn_rm ();
8499 else {
8500 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8501 _("immediate operand requires iWMMXt2"));
8502 do_rd_rn ();
8503 if (inst.operands[2].imm == 0)
8504 {
8505 switch ((inst.instruction >> 20) & 0xf)
8506 {
8507 case 4:
8508 case 5:
8509 case 6:
5f4273c7 8510 case 7:
2d447fca
JM
8511 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8512 inst.operands[2].imm = 16;
8513 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8514 break;
8515 case 8:
8516 case 9:
8517 case 10:
8518 case 11:
8519 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8520 inst.operands[2].imm = 32;
8521 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8522 break;
8523 case 12:
8524 case 13:
8525 case 14:
8526 case 15:
8527 {
8528 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8529 unsigned long wrn;
8530 wrn = (inst.instruction >> 16) & 0xf;
8531 inst.instruction &= 0xff0fff0f;
8532 inst.instruction |= wrn;
8533 /* Bail out here; the instruction is now assembled. */
8534 return;
8535 }
8536 }
8537 }
8538 /* Map 32 -> 0, etc. */
8539 inst.operands[2].imm &= 0x1f;
8540 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8541 }
8542}
c19d1205
ZW
8543\f
8544/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8545 operations first, then control, shift, and load/store. */
b99bd4ef 8546
c19d1205 8547/* Insns like "foo X,Y,Z". */
b99bd4ef 8548
c19d1205
ZW
8549static void
8550do_mav_triple (void)
8551{
8552 inst.instruction |= inst.operands[0].reg << 16;
8553 inst.instruction |= inst.operands[1].reg;
8554 inst.instruction |= inst.operands[2].reg << 12;
8555}
b99bd4ef 8556
c19d1205
ZW
8557/* Insns like "foo W,X,Y,Z".
8558 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8559
c19d1205
ZW
8560static void
8561do_mav_quad (void)
8562{
8563 inst.instruction |= inst.operands[0].reg << 5;
8564 inst.instruction |= inst.operands[1].reg << 12;
8565 inst.instruction |= inst.operands[2].reg << 16;
8566 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8567}
8568
c19d1205
ZW
8569/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8570static void
8571do_mav_dspsc (void)
a737bd4d 8572{
c19d1205
ZW
8573 inst.instruction |= inst.operands[1].reg << 12;
8574}
a737bd4d 8575
c19d1205
ZW
8576/* Maverick shift immediate instructions.
8577 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8578 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8579
c19d1205
ZW
8580static void
8581do_mav_shift (void)
8582{
8583 int imm = inst.operands[2].imm;
a737bd4d 8584
c19d1205
ZW
8585 inst.instruction |= inst.operands[0].reg << 12;
8586 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8587
c19d1205
ZW
8588 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8589 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8590 Bit 4 should be 0. */
8591 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8592
c19d1205
ZW
8593 inst.instruction |= imm;
8594}
8595\f
8596/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8597
c19d1205
ZW
8598/* Xscale multiply-accumulate (argument parse)
8599 MIAcc acc0,Rm,Rs
8600 MIAPHcc acc0,Rm,Rs
8601 MIAxycc acc0,Rm,Rs. */
a737bd4d 8602
c19d1205
ZW
8603static void
8604do_xsc_mia (void)
8605{
8606 inst.instruction |= inst.operands[1].reg;
8607 inst.instruction |= inst.operands[2].reg << 12;
8608}
a737bd4d 8609
c19d1205 8610/* Xscale move-accumulator-register (argument parse)
a737bd4d 8611
c19d1205 8612 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8613
c19d1205
ZW
8614static void
8615do_xsc_mar (void)
8616{
8617 inst.instruction |= inst.operands[1].reg << 12;
8618 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8619}
8620
c19d1205 8621/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8622
c19d1205 8623 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8624
8625static void
c19d1205 8626do_xsc_mra (void)
b99bd4ef 8627{
c19d1205
ZW
8628 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8629 inst.instruction |= inst.operands[0].reg << 12;
8630 inst.instruction |= inst.operands[1].reg << 16;
8631}
8632\f
8633/* Encoding functions relevant only to Thumb. */
b99bd4ef 8634
c19d1205
ZW
8635/* inst.operands[i] is a shifted-register operand; encode
8636 it into inst.instruction in the format used by Thumb32. */
8637
8638static void
8639encode_thumb32_shifted_operand (int i)
8640{
8641 unsigned int value = inst.reloc.exp.X_add_number;
8642 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8643
9c3c69f2
PB
8644 constraint (inst.operands[i].immisreg,
8645 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8646 inst.instruction |= inst.operands[i].reg;
8647 if (shift == SHIFT_RRX)
8648 inst.instruction |= SHIFT_ROR << 4;
8649 else
b99bd4ef 8650 {
c19d1205
ZW
8651 constraint (inst.reloc.exp.X_op != O_constant,
8652 _("expression too complex"));
8653
8654 constraint (value > 32
8655 || (value == 32 && (shift == SHIFT_LSL
8656 || shift == SHIFT_ROR)),
8657 _("shift expression is too large"));
8658
8659 if (value == 0)
8660 shift = SHIFT_LSL;
8661 else if (value == 32)
8662 value = 0;
8663
8664 inst.instruction |= shift << 4;
8665 inst.instruction |= (value & 0x1c) << 10;
8666 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8667 }
c19d1205 8668}
b99bd4ef 8669
b99bd4ef 8670
c19d1205
ZW
8671/* inst.operands[i] was set up by parse_address. Encode it into a
8672 Thumb32 format load or store instruction. Reject forms that cannot
8673 be used with such instructions. If is_t is true, reject forms that
8674 cannot be used with a T instruction; if is_d is true, reject forms
8675 that cannot be used with a D instruction. */
b99bd4ef 8676
c19d1205
ZW
8677static void
8678encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8679{
8680 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8681
8682 constraint (!inst.operands[i].isreg,
53365c0d 8683 _("Instruction does not support =N addresses"));
b99bd4ef 8684
c19d1205
ZW
8685 inst.instruction |= inst.operands[i].reg << 16;
8686 if (inst.operands[i].immisreg)
b99bd4ef 8687 {
c19d1205
ZW
8688 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8689 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8690 constraint (inst.operands[i].negative,
8691 _("Thumb does not support negative register indexing"));
8692 constraint (inst.operands[i].postind,
8693 _("Thumb does not support register post-indexing"));
8694 constraint (inst.operands[i].writeback,
8695 _("Thumb does not support register indexing with writeback"));
8696 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8697 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8698
f40d1643 8699 inst.instruction |= inst.operands[i].imm;
c19d1205 8700 if (inst.operands[i].shifted)
b99bd4ef 8701 {
c19d1205
ZW
8702 constraint (inst.reloc.exp.X_op != O_constant,
8703 _("expression too complex"));
9c3c69f2
PB
8704 constraint (inst.reloc.exp.X_add_number < 0
8705 || inst.reloc.exp.X_add_number > 3,
c19d1205 8706 _("shift out of range"));
9c3c69f2 8707 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8708 }
8709 inst.reloc.type = BFD_RELOC_UNUSED;
8710 }
8711 else if (inst.operands[i].preind)
8712 {
8713 constraint (is_pc && inst.operands[i].writeback,
8714 _("cannot use writeback with PC-relative addressing"));
f40d1643 8715 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8716 _("cannot use writeback with this instruction"));
8717
8718 if (is_d)
8719 {
8720 inst.instruction |= 0x01000000;
8721 if (inst.operands[i].writeback)
8722 inst.instruction |= 0x00200000;
b99bd4ef 8723 }
c19d1205 8724 else
b99bd4ef 8725 {
c19d1205
ZW
8726 inst.instruction |= 0x00000c00;
8727 if (inst.operands[i].writeback)
8728 inst.instruction |= 0x00000100;
b99bd4ef 8729 }
c19d1205 8730 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8731 }
c19d1205 8732 else if (inst.operands[i].postind)
b99bd4ef 8733 {
9c2799c2 8734 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8735 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8736 constraint (is_t, _("cannot use post-indexing with this instruction"));
8737
8738 if (is_d)
8739 inst.instruction |= 0x00200000;
8740 else
8741 inst.instruction |= 0x00000900;
8742 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8743 }
8744 else /* unindexed - only for coprocessor */
8745 inst.error = _("instruction does not accept unindexed addressing");
8746}
8747
8748/* Table of Thumb instructions which exist in both 16- and 32-bit
8749 encodings (the latter only in post-V6T2 cores). The index is the
8750 value used in the insns table below. When there is more than one
8751 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8752 holds variant (1).
8753 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8754#define T16_32_TAB \
21d799b5
NC
8755 X(_adc, 4140, eb400000), \
8756 X(_adcs, 4140, eb500000), \
8757 X(_add, 1c00, eb000000), \
8758 X(_adds, 1c00, eb100000), \
8759 X(_addi, 0000, f1000000), \
8760 X(_addis, 0000, f1100000), \
8761 X(_add_pc,000f, f20f0000), \
8762 X(_add_sp,000d, f10d0000), \
8763 X(_adr, 000f, f20f0000), \
8764 X(_and, 4000, ea000000), \
8765 X(_ands, 4000, ea100000), \
8766 X(_asr, 1000, fa40f000), \
8767 X(_asrs, 1000, fa50f000), \
8768 X(_b, e000, f000b000), \
8769 X(_bcond, d000, f0008000), \
8770 X(_bic, 4380, ea200000), \
8771 X(_bics, 4380, ea300000), \
8772 X(_cmn, 42c0, eb100f00), \
8773 X(_cmp, 2800, ebb00f00), \
8774 X(_cpsie, b660, f3af8400), \
8775 X(_cpsid, b670, f3af8600), \
8776 X(_cpy, 4600, ea4f0000), \
8777 X(_dec_sp,80dd, f1ad0d00), \
8778 X(_eor, 4040, ea800000), \
8779 X(_eors, 4040, ea900000), \
8780 X(_inc_sp,00dd, f10d0d00), \
8781 X(_ldmia, c800, e8900000), \
8782 X(_ldr, 6800, f8500000), \
8783 X(_ldrb, 7800, f8100000), \
8784 X(_ldrh, 8800, f8300000), \
8785 X(_ldrsb, 5600, f9100000), \
8786 X(_ldrsh, 5e00, f9300000), \
8787 X(_ldr_pc,4800, f85f0000), \
8788 X(_ldr_pc2,4800, f85f0000), \
8789 X(_ldr_sp,9800, f85d0000), \
8790 X(_lsl, 0000, fa00f000), \
8791 X(_lsls, 0000, fa10f000), \
8792 X(_lsr, 0800, fa20f000), \
8793 X(_lsrs, 0800, fa30f000), \
8794 X(_mov, 2000, ea4f0000), \
8795 X(_movs, 2000, ea5f0000), \
8796 X(_mul, 4340, fb00f000), \
8797 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8798 X(_mvn, 43c0, ea6f0000), \
8799 X(_mvns, 43c0, ea7f0000), \
8800 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8801 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8802 X(_orr, 4300, ea400000), \
8803 X(_orrs, 4300, ea500000), \
8804 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8805 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8806 X(_rev, ba00, fa90f080), \
8807 X(_rev16, ba40, fa90f090), \
8808 X(_revsh, bac0, fa90f0b0), \
8809 X(_ror, 41c0, fa60f000), \
8810 X(_rors, 41c0, fa70f000), \
8811 X(_sbc, 4180, eb600000), \
8812 X(_sbcs, 4180, eb700000), \
8813 X(_stmia, c000, e8800000), \
8814 X(_str, 6000, f8400000), \
8815 X(_strb, 7000, f8000000), \
8816 X(_strh, 8000, f8200000), \
8817 X(_str_sp,9000, f84d0000), \
8818 X(_sub, 1e00, eba00000), \
8819 X(_subs, 1e00, ebb00000), \
8820 X(_subi, 8000, f1a00000), \
8821 X(_subis, 8000, f1b00000), \
8822 X(_sxtb, b240, fa4ff080), \
8823 X(_sxth, b200, fa0ff080), \
8824 X(_tst, 4200, ea100f00), \
8825 X(_uxtb, b2c0, fa5ff080), \
8826 X(_uxth, b280, fa1ff080), \
8827 X(_nop, bf00, f3af8000), \
8828 X(_yield, bf10, f3af8001), \
8829 X(_wfe, bf20, f3af8002), \
8830 X(_wfi, bf30, f3af8003), \
8831 X(_sev, bf40, f3af8004),
c19d1205
ZW
8832
8833/* To catch errors in encoding functions, the codes are all offset by
8834 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8835 as 16-bit instructions. */
21d799b5 8836#define X(a,b,c) T_MNEM##a
c19d1205
ZW
8837enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8838#undef X
8839
8840#define X(a,b,c) 0x##b
8841static const unsigned short thumb_op16[] = { T16_32_TAB };
8842#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8843#undef X
8844
8845#define X(a,b,c) 0x##c
8846static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
8847#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8848#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
8849#undef X
8850#undef T16_32_TAB
8851
8852/* Thumb instruction encoders, in alphabetical order. */
8853
92e90b6e 8854/* ADDW or SUBW. */
c921be7d 8855
92e90b6e
PB
8856static void
8857do_t_add_sub_w (void)
8858{
8859 int Rd, Rn;
8860
8861 Rd = inst.operands[0].reg;
8862 Rn = inst.operands[1].reg;
8863
539d4391
NC
8864 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8865 is the SP-{plus,minus}-immediate form of the instruction. */
8866 if (Rn == REG_SP)
8867 constraint (Rd == REG_PC, BAD_PC);
8868 else
8869 reject_bad_reg (Rd);
fdfde340 8870
92e90b6e
PB
8871 inst.instruction |= (Rn << 16) | (Rd << 8);
8872 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8873}
8874
c19d1205
ZW
8875/* Parse an add or subtract instruction. We get here with inst.instruction
8876 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8877
8878static void
8879do_t_add_sub (void)
8880{
8881 int Rd, Rs, Rn;
8882
8883 Rd = inst.operands[0].reg;
8884 Rs = (inst.operands[1].present
8885 ? inst.operands[1].reg /* Rd, Rs, foo */
8886 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8887
e07e6e58
NC
8888 if (Rd == REG_PC)
8889 set_it_insn_type_last ();
8890
c19d1205
ZW
8891 if (unified_syntax)
8892 {
0110f2b8
PB
8893 bfd_boolean flags;
8894 bfd_boolean narrow;
8895 int opcode;
8896
8897 flags = (inst.instruction == T_MNEM_adds
8898 || inst.instruction == T_MNEM_subs);
8899 if (flags)
e07e6e58 8900 narrow = !in_it_block ();
0110f2b8 8901 else
e07e6e58 8902 narrow = in_it_block ();
c19d1205 8903 if (!inst.operands[2].isreg)
b99bd4ef 8904 {
16805f35
PB
8905 int add;
8906
fdfde340
JM
8907 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8908
16805f35
PB
8909 add = (inst.instruction == T_MNEM_add
8910 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8911 opcode = 0;
8912 if (inst.size_req != 4)
8913 {
0110f2b8
PB
8914 /* Attempt to use a narrow opcode, with relaxation if
8915 appropriate. */
8916 if (Rd == REG_SP && Rs == REG_SP && !flags)
8917 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8918 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8919 opcode = T_MNEM_add_sp;
8920 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8921 opcode = T_MNEM_add_pc;
8922 else if (Rd <= 7 && Rs <= 7 && narrow)
8923 {
8924 if (flags)
8925 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8926 else
8927 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8928 }
8929 if (opcode)
8930 {
8931 inst.instruction = THUMB_OP16(opcode);
8932 inst.instruction |= (Rd << 4) | Rs;
8933 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8934 if (inst.size_req != 2)
8935 inst.relax = opcode;
8936 }
8937 else
8938 constraint (inst.size_req == 2, BAD_HIREG);
8939 }
8940 if (inst.size_req == 4
8941 || (inst.size_req != 2 && !opcode))
8942 {
efd81785
PB
8943 if (Rd == REG_PC)
8944 {
fdfde340 8945 constraint (add, BAD_PC);
efd81785
PB
8946 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8947 _("only SUBS PC, LR, #const allowed"));
8948 constraint (inst.reloc.exp.X_op != O_constant,
8949 _("expression too complex"));
8950 constraint (inst.reloc.exp.X_add_number < 0
8951 || inst.reloc.exp.X_add_number > 0xff,
8952 _("immediate value out of range"));
8953 inst.instruction = T2_SUBS_PC_LR
8954 | inst.reloc.exp.X_add_number;
8955 inst.reloc.type = BFD_RELOC_UNUSED;
8956 return;
8957 }
8958 else if (Rs == REG_PC)
16805f35
PB
8959 {
8960 /* Always use addw/subw. */
8961 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8962 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8963 }
8964 else
8965 {
8966 inst.instruction = THUMB_OP32 (inst.instruction);
8967 inst.instruction = (inst.instruction & 0xe1ffffff)
8968 | 0x10000000;
8969 if (flags)
8970 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8971 else
8972 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8973 }
dc4503c6
PB
8974 inst.instruction |= Rd << 8;
8975 inst.instruction |= Rs << 16;
0110f2b8 8976 }
b99bd4ef 8977 }
c19d1205
ZW
8978 else
8979 {
8980 Rn = inst.operands[2].reg;
8981 /* See if we can do this with a 16-bit instruction. */
8982 if (!inst.operands[2].shifted && inst.size_req != 4)
8983 {
e27ec89e
PB
8984 if (Rd > 7 || Rs > 7 || Rn > 7)
8985 narrow = FALSE;
8986
8987 if (narrow)
c19d1205 8988 {
e27ec89e
PB
8989 inst.instruction = ((inst.instruction == T_MNEM_adds
8990 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8991 ? T_OPCODE_ADD_R3
8992 : T_OPCODE_SUB_R3);
8993 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8994 return;
8995 }
b99bd4ef 8996
7e806470 8997 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8998 {
7e806470
PB
8999 /* Thumb-1 cores (except v6-M) require at least one high
9000 register in a narrow non flag setting add. */
9001 if (Rd > 7 || Rn > 7
9002 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9003 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9004 {
7e806470
PB
9005 if (Rd == Rn)
9006 {
9007 Rn = Rs;
9008 Rs = Rd;
9009 }
c19d1205
ZW
9010 inst.instruction = T_OPCODE_ADD_HI;
9011 inst.instruction |= (Rd & 8) << 4;
9012 inst.instruction |= (Rd & 7);
9013 inst.instruction |= Rn << 3;
9014 return;
9015 }
c19d1205
ZW
9016 }
9017 }
c921be7d 9018
fdfde340
JM
9019 constraint (Rd == REG_PC, BAD_PC);
9020 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9021 constraint (Rs == REG_PC, BAD_PC);
9022 reject_bad_reg (Rn);
9023
c19d1205
ZW
9024 /* If we get here, it can't be done in 16 bits. */
9025 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9026 _("shift must be constant"));
9027 inst.instruction = THUMB_OP32 (inst.instruction);
9028 inst.instruction |= Rd << 8;
9029 inst.instruction |= Rs << 16;
9030 encode_thumb32_shifted_operand (2);
9031 }
9032 }
9033 else
9034 {
9035 constraint (inst.instruction == T_MNEM_adds
9036 || inst.instruction == T_MNEM_subs,
9037 BAD_THUMB32);
b99bd4ef 9038
c19d1205 9039 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9040 {
c19d1205
ZW
9041 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9042 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9043 BAD_HIREG);
9044
9045 inst.instruction = (inst.instruction == T_MNEM_add
9046 ? 0x0000 : 0x8000);
9047 inst.instruction |= (Rd << 4) | Rs;
9048 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9049 return;
9050 }
9051
c19d1205
ZW
9052 Rn = inst.operands[2].reg;
9053 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9054
c19d1205
ZW
9055 /* We now have Rd, Rs, and Rn set to registers. */
9056 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9057 {
c19d1205
ZW
9058 /* Can't do this for SUB. */
9059 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9060 inst.instruction = T_OPCODE_ADD_HI;
9061 inst.instruction |= (Rd & 8) << 4;
9062 inst.instruction |= (Rd & 7);
9063 if (Rs == Rd)
9064 inst.instruction |= Rn << 3;
9065 else if (Rn == Rd)
9066 inst.instruction |= Rs << 3;
9067 else
9068 constraint (1, _("dest must overlap one source register"));
9069 }
9070 else
9071 {
9072 inst.instruction = (inst.instruction == T_MNEM_add
9073 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9074 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9075 }
b99bd4ef 9076 }
b99bd4ef
NC
9077}
9078
c19d1205
ZW
9079static void
9080do_t_adr (void)
9081{
fdfde340
JM
9082 unsigned Rd;
9083
9084 Rd = inst.operands[0].reg;
9085 reject_bad_reg (Rd);
9086
9087 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9088 {
9089 /* Defer to section relaxation. */
9090 inst.relax = inst.instruction;
9091 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9092 inst.instruction |= Rd << 4;
0110f2b8
PB
9093 }
9094 else if (unified_syntax && inst.size_req != 2)
e9f89963 9095 {
0110f2b8 9096 /* Generate a 32-bit opcode. */
e9f89963 9097 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9098 inst.instruction |= Rd << 8;
e9f89963
PB
9099 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9100 inst.reloc.pc_rel = 1;
9101 }
9102 else
9103 {
0110f2b8 9104 /* Generate a 16-bit opcode. */
e9f89963
PB
9105 inst.instruction = THUMB_OP16 (inst.instruction);
9106 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9107 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9108 inst.reloc.pc_rel = 1;
b99bd4ef 9109
fdfde340 9110 inst.instruction |= Rd << 4;
e9f89963 9111 }
c19d1205 9112}
b99bd4ef 9113
c19d1205
ZW
9114/* Arithmetic instructions for which there is just one 16-bit
9115 instruction encoding, and it allows only two low registers.
9116 For maximal compatibility with ARM syntax, we allow three register
9117 operands even when Thumb-32 instructions are not available, as long
9118 as the first two are identical. For instance, both "sbc r0,r1" and
9119 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9120static void
c19d1205 9121do_t_arit3 (void)
b99bd4ef 9122{
c19d1205 9123 int Rd, Rs, Rn;
b99bd4ef 9124
c19d1205
ZW
9125 Rd = inst.operands[0].reg;
9126 Rs = (inst.operands[1].present
9127 ? inst.operands[1].reg /* Rd, Rs, foo */
9128 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9129 Rn = inst.operands[2].reg;
b99bd4ef 9130
fdfde340
JM
9131 reject_bad_reg (Rd);
9132 reject_bad_reg (Rs);
9133 if (inst.operands[2].isreg)
9134 reject_bad_reg (Rn);
9135
c19d1205 9136 if (unified_syntax)
b99bd4ef 9137 {
c19d1205
ZW
9138 if (!inst.operands[2].isreg)
9139 {
9140 /* For an immediate, we always generate a 32-bit opcode;
9141 section relaxation will shrink it later if possible. */
9142 inst.instruction = THUMB_OP32 (inst.instruction);
9143 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9144 inst.instruction |= Rd << 8;
9145 inst.instruction |= Rs << 16;
9146 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9147 }
9148 else
9149 {
e27ec89e
PB
9150 bfd_boolean narrow;
9151
c19d1205 9152 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9153 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9154 narrow = !in_it_block ();
e27ec89e 9155 else
e07e6e58 9156 narrow = in_it_block ();
e27ec89e
PB
9157
9158 if (Rd > 7 || Rn > 7 || Rs > 7)
9159 narrow = FALSE;
9160 if (inst.operands[2].shifted)
9161 narrow = FALSE;
9162 if (inst.size_req == 4)
9163 narrow = FALSE;
9164
9165 if (narrow
c19d1205
ZW
9166 && Rd == Rs)
9167 {
9168 inst.instruction = THUMB_OP16 (inst.instruction);
9169 inst.instruction |= Rd;
9170 inst.instruction |= Rn << 3;
9171 return;
9172 }
b99bd4ef 9173
c19d1205
ZW
9174 /* If we get here, it can't be done in 16 bits. */
9175 constraint (inst.operands[2].shifted
9176 && inst.operands[2].immisreg,
9177 _("shift must be constant"));
9178 inst.instruction = THUMB_OP32 (inst.instruction);
9179 inst.instruction |= Rd << 8;
9180 inst.instruction |= Rs << 16;
9181 encode_thumb32_shifted_operand (2);
9182 }
a737bd4d 9183 }
c19d1205 9184 else
b99bd4ef 9185 {
c19d1205
ZW
9186 /* On its face this is a lie - the instruction does set the
9187 flags. However, the only supported mnemonic in this mode
9188 says it doesn't. */
9189 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9190
c19d1205
ZW
9191 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9192 _("unshifted register required"));
9193 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9194 constraint (Rd != Rs,
9195 _("dest and source1 must be the same register"));
a737bd4d 9196
c19d1205
ZW
9197 inst.instruction = THUMB_OP16 (inst.instruction);
9198 inst.instruction |= Rd;
9199 inst.instruction |= Rn << 3;
b99bd4ef 9200 }
a737bd4d 9201}
b99bd4ef 9202
c19d1205
ZW
9203/* Similarly, but for instructions where the arithmetic operation is
9204 commutative, so we can allow either of them to be different from
9205 the destination operand in a 16-bit instruction. For instance, all
9206 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9207 accepted. */
9208static void
9209do_t_arit3c (void)
a737bd4d 9210{
c19d1205 9211 int Rd, Rs, Rn;
b99bd4ef 9212
c19d1205
ZW
9213 Rd = inst.operands[0].reg;
9214 Rs = (inst.operands[1].present
9215 ? inst.operands[1].reg /* Rd, Rs, foo */
9216 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9217 Rn = inst.operands[2].reg;
c921be7d 9218
fdfde340
JM
9219 reject_bad_reg (Rd);
9220 reject_bad_reg (Rs);
9221 if (inst.operands[2].isreg)
9222 reject_bad_reg (Rn);
a737bd4d 9223
c19d1205 9224 if (unified_syntax)
a737bd4d 9225 {
c19d1205 9226 if (!inst.operands[2].isreg)
b99bd4ef 9227 {
c19d1205
ZW
9228 /* For an immediate, we always generate a 32-bit opcode;
9229 section relaxation will shrink it later if possible. */
9230 inst.instruction = THUMB_OP32 (inst.instruction);
9231 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9232 inst.instruction |= Rd << 8;
9233 inst.instruction |= Rs << 16;
9234 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9235 }
c19d1205 9236 else
a737bd4d 9237 {
e27ec89e
PB
9238 bfd_boolean narrow;
9239
c19d1205 9240 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9241 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9242 narrow = !in_it_block ();
e27ec89e 9243 else
e07e6e58 9244 narrow = in_it_block ();
e27ec89e
PB
9245
9246 if (Rd > 7 || Rn > 7 || Rs > 7)
9247 narrow = FALSE;
9248 if (inst.operands[2].shifted)
9249 narrow = FALSE;
9250 if (inst.size_req == 4)
9251 narrow = FALSE;
9252
9253 if (narrow)
a737bd4d 9254 {
c19d1205 9255 if (Rd == Rs)
a737bd4d 9256 {
c19d1205
ZW
9257 inst.instruction = THUMB_OP16 (inst.instruction);
9258 inst.instruction |= Rd;
9259 inst.instruction |= Rn << 3;
9260 return;
a737bd4d 9261 }
c19d1205 9262 if (Rd == Rn)
a737bd4d 9263 {
c19d1205
ZW
9264 inst.instruction = THUMB_OP16 (inst.instruction);
9265 inst.instruction |= Rd;
9266 inst.instruction |= Rs << 3;
9267 return;
a737bd4d
NC
9268 }
9269 }
c19d1205
ZW
9270
9271 /* If we get here, it can't be done in 16 bits. */
9272 constraint (inst.operands[2].shifted
9273 && inst.operands[2].immisreg,
9274 _("shift must be constant"));
9275 inst.instruction = THUMB_OP32 (inst.instruction);
9276 inst.instruction |= Rd << 8;
9277 inst.instruction |= Rs << 16;
9278 encode_thumb32_shifted_operand (2);
a737bd4d 9279 }
b99bd4ef 9280 }
c19d1205
ZW
9281 else
9282 {
9283 /* On its face this is a lie - the instruction does set the
9284 flags. However, the only supported mnemonic in this mode
9285 says it doesn't. */
9286 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9287
c19d1205
ZW
9288 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9289 _("unshifted register required"));
9290 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9291
9292 inst.instruction = THUMB_OP16 (inst.instruction);
9293 inst.instruction |= Rd;
9294
9295 if (Rd == Rs)
9296 inst.instruction |= Rn << 3;
9297 else if (Rd == Rn)
9298 inst.instruction |= Rs << 3;
9299 else
9300 constraint (1, _("dest must overlap one source register"));
9301 }
a737bd4d
NC
9302}
9303
62b3e311
PB
9304static void
9305do_t_barrier (void)
9306{
9307 if (inst.operands[0].present)
9308 {
9309 constraint ((inst.instruction & 0xf0) != 0x40
9310 && inst.operands[0].imm != 0xf,
bd3ba5d1 9311 _("bad barrier type"));
62b3e311
PB
9312 inst.instruction |= inst.operands[0].imm;
9313 }
9314 else
9315 inst.instruction |= 0xf;
9316}
9317
c19d1205
ZW
9318static void
9319do_t_bfc (void)
a737bd4d 9320{
fdfde340 9321 unsigned Rd;
c19d1205
ZW
9322 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9323 constraint (msb > 32, _("bit-field extends past end of register"));
9324 /* The instruction encoding stores the LSB and MSB,
9325 not the LSB and width. */
fdfde340
JM
9326 Rd = inst.operands[0].reg;
9327 reject_bad_reg (Rd);
9328 inst.instruction |= Rd << 8;
c19d1205
ZW
9329 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9330 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9331 inst.instruction |= msb - 1;
b99bd4ef
NC
9332}
9333
c19d1205
ZW
9334static void
9335do_t_bfi (void)
b99bd4ef 9336{
fdfde340 9337 int Rd, Rn;
c19d1205 9338 unsigned int msb;
b99bd4ef 9339
fdfde340
JM
9340 Rd = inst.operands[0].reg;
9341 reject_bad_reg (Rd);
9342
c19d1205
ZW
9343 /* #0 in second position is alternative syntax for bfc, which is
9344 the same instruction but with REG_PC in the Rm field. */
9345 if (!inst.operands[1].isreg)
fdfde340
JM
9346 Rn = REG_PC;
9347 else
9348 {
9349 Rn = inst.operands[1].reg;
9350 reject_bad_reg (Rn);
9351 }
b99bd4ef 9352
c19d1205
ZW
9353 msb = inst.operands[2].imm + inst.operands[3].imm;
9354 constraint (msb > 32, _("bit-field extends past end of register"));
9355 /* The instruction encoding stores the LSB and MSB,
9356 not the LSB and width. */
fdfde340
JM
9357 inst.instruction |= Rd << 8;
9358 inst.instruction |= Rn << 16;
c19d1205
ZW
9359 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9360 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9361 inst.instruction |= msb - 1;
b99bd4ef
NC
9362}
9363
c19d1205
ZW
9364static void
9365do_t_bfx (void)
b99bd4ef 9366{
fdfde340
JM
9367 unsigned Rd, Rn;
9368
9369 Rd = inst.operands[0].reg;
9370 Rn = inst.operands[1].reg;
9371
9372 reject_bad_reg (Rd);
9373 reject_bad_reg (Rn);
9374
c19d1205
ZW
9375 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9376 _("bit-field extends past end of register"));
fdfde340
JM
9377 inst.instruction |= Rd << 8;
9378 inst.instruction |= Rn << 16;
c19d1205
ZW
9379 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9380 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9381 inst.instruction |= inst.operands[3].imm - 1;
9382}
b99bd4ef 9383
c19d1205
ZW
9384/* ARM V5 Thumb BLX (argument parse)
9385 BLX <target_addr> which is BLX(1)
9386 BLX <Rm> which is BLX(2)
9387 Unfortunately, there are two different opcodes for this mnemonic.
9388 So, the insns[].value is not used, and the code here zaps values
9389 into inst.instruction.
b99bd4ef 9390
c19d1205
ZW
9391 ??? How to take advantage of the additional two bits of displacement
9392 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9393
c19d1205
ZW
9394static void
9395do_t_blx (void)
9396{
e07e6e58
NC
9397 set_it_insn_type_last ();
9398
c19d1205 9399 if (inst.operands[0].isreg)
fdfde340
JM
9400 {
9401 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9402 /* We have a register, so this is BLX(2). */
9403 inst.instruction |= inst.operands[0].reg << 3;
9404 }
b99bd4ef
NC
9405 else
9406 {
c19d1205 9407 /* No register. This must be BLX(1). */
2fc8bdac 9408 inst.instruction = 0xf000e800;
00adf2d4 9409 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9410 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9411 }
9412}
9413
c19d1205
ZW
9414static void
9415do_t_branch (void)
b99bd4ef 9416{
0110f2b8 9417 int opcode;
dfa9f0d5
PB
9418 int cond;
9419
e07e6e58
NC
9420 cond = inst.cond;
9421 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9422
9423 if (in_it_block ())
dfa9f0d5
PB
9424 {
9425 /* Conditional branches inside IT blocks are encoded as unconditional
9426 branches. */
9427 cond = COND_ALWAYS;
dfa9f0d5
PB
9428 }
9429 else
9430 cond = inst.cond;
9431
9432 if (cond != COND_ALWAYS)
0110f2b8
PB
9433 opcode = T_MNEM_bcond;
9434 else
9435 opcode = inst.instruction;
9436
9437 if (unified_syntax && inst.size_req == 4)
c19d1205 9438 {
0110f2b8 9439 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9440 if (cond == COND_ALWAYS)
0110f2b8 9441 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9442 else
9443 {
9c2799c2 9444 gas_assert (cond != 0xF);
dfa9f0d5 9445 inst.instruction |= cond << 22;
c19d1205
ZW
9446 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9447 }
9448 }
b99bd4ef
NC
9449 else
9450 {
0110f2b8 9451 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9452 if (cond == COND_ALWAYS)
c19d1205
ZW
9453 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9454 else
b99bd4ef 9455 {
dfa9f0d5 9456 inst.instruction |= cond << 8;
c19d1205 9457 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9458 }
0110f2b8
PB
9459 /* Allow section relaxation. */
9460 if (unified_syntax && inst.size_req != 2)
9461 inst.relax = opcode;
b99bd4ef 9462 }
c19d1205
ZW
9463
9464 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9465}
9466
9467static void
c19d1205 9468do_t_bkpt (void)
b99bd4ef 9469{
dfa9f0d5
PB
9470 constraint (inst.cond != COND_ALWAYS,
9471 _("instruction is always unconditional"));
c19d1205 9472 if (inst.operands[0].present)
b99bd4ef 9473 {
c19d1205
ZW
9474 constraint (inst.operands[0].imm > 255,
9475 _("immediate value out of range"));
9476 inst.instruction |= inst.operands[0].imm;
e07e6e58 9477 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9478 }
b99bd4ef
NC
9479}
9480
9481static void
c19d1205 9482do_t_branch23 (void)
b99bd4ef 9483{
e07e6e58 9484 set_it_insn_type_last ();
c19d1205 9485 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9486 inst.reloc.pc_rel = 1;
9487
4343666d 9488#if defined(OBJ_COFF)
c19d1205
ZW
9489 /* If the destination of the branch is a defined symbol which does not have
9490 the THUMB_FUNC attribute, then we must be calling a function which has
9491 the (interfacearm) attribute. We look for the Thumb entry point to that
9492 function and change the branch to refer to that function instead. */
9493 if ( inst.reloc.exp.X_op == O_symbol
9494 && inst.reloc.exp.X_add_symbol != NULL
9495 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9496 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9497 inst.reloc.exp.X_add_symbol =
9498 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9499#endif
90e4755a
RE
9500}
9501
9502static void
c19d1205 9503do_t_bx (void)
90e4755a 9504{
e07e6e58 9505 set_it_insn_type_last ();
c19d1205
ZW
9506 inst.instruction |= inst.operands[0].reg << 3;
9507 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9508 should cause the alignment to be checked once it is known. This is
9509 because BX PC only works if the instruction is word aligned. */
9510}
90e4755a 9511
c19d1205
ZW
9512static void
9513do_t_bxj (void)
9514{
fdfde340 9515 int Rm;
90e4755a 9516
e07e6e58 9517 set_it_insn_type_last ();
fdfde340
JM
9518 Rm = inst.operands[0].reg;
9519 reject_bad_reg (Rm);
9520 inst.instruction |= Rm << 16;
90e4755a
RE
9521}
9522
9523static void
c19d1205 9524do_t_clz (void)
90e4755a 9525{
fdfde340
JM
9526 unsigned Rd;
9527 unsigned Rm;
9528
9529 Rd = inst.operands[0].reg;
9530 Rm = inst.operands[1].reg;
9531
9532 reject_bad_reg (Rd);
9533 reject_bad_reg (Rm);
9534
9535 inst.instruction |= Rd << 8;
9536 inst.instruction |= Rm << 16;
9537 inst.instruction |= Rm;
c19d1205 9538}
90e4755a 9539
dfa9f0d5
PB
9540static void
9541do_t_cps (void)
9542{
e07e6e58 9543 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9544 inst.instruction |= inst.operands[0].imm;
9545}
9546
c19d1205
ZW
9547static void
9548do_t_cpsi (void)
9549{
e07e6e58 9550 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9551 if (unified_syntax
62b3e311
PB
9552 && (inst.operands[1].present || inst.size_req == 4)
9553 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9554 {
c19d1205
ZW
9555 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9556 inst.instruction = 0xf3af8000;
9557 inst.instruction |= imod << 9;
9558 inst.instruction |= inst.operands[0].imm << 5;
9559 if (inst.operands[1].present)
9560 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9561 }
c19d1205 9562 else
90e4755a 9563 {
62b3e311
PB
9564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9565 && (inst.operands[0].imm & 4),
9566 _("selected processor does not support 'A' form "
9567 "of this instruction"));
9568 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9569 _("Thumb does not support the 2-argument "
9570 "form of this instruction"));
9571 inst.instruction |= inst.operands[0].imm;
90e4755a 9572 }
90e4755a
RE
9573}
9574
c19d1205
ZW
9575/* THUMB CPY instruction (argument parse). */
9576
90e4755a 9577static void
c19d1205 9578do_t_cpy (void)
90e4755a 9579{
c19d1205 9580 if (inst.size_req == 4)
90e4755a 9581 {
c19d1205
ZW
9582 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9583 inst.instruction |= inst.operands[0].reg << 8;
9584 inst.instruction |= inst.operands[1].reg;
90e4755a 9585 }
c19d1205 9586 else
90e4755a 9587 {
c19d1205
ZW
9588 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9589 inst.instruction |= (inst.operands[0].reg & 0x7);
9590 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9591 }
90e4755a
RE
9592}
9593
90e4755a 9594static void
25fe350b 9595do_t_cbz (void)
90e4755a 9596{
e07e6e58 9597 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9598 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9599 inst.instruction |= inst.operands[0].reg;
9600 inst.reloc.pc_rel = 1;
9601 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9602}
90e4755a 9603
62b3e311
PB
9604static void
9605do_t_dbg (void)
9606{
9607 inst.instruction |= inst.operands[0].imm;
9608}
9609
9610static void
9611do_t_div (void)
9612{
fdfde340
JM
9613 unsigned Rd, Rn, Rm;
9614
9615 Rd = inst.operands[0].reg;
9616 Rn = (inst.operands[1].present
9617 ? inst.operands[1].reg : Rd);
9618 Rm = inst.operands[2].reg;
9619
9620 reject_bad_reg (Rd);
9621 reject_bad_reg (Rn);
9622 reject_bad_reg (Rm);
9623
9624 inst.instruction |= Rd << 8;
9625 inst.instruction |= Rn << 16;
9626 inst.instruction |= Rm;
62b3e311
PB
9627}
9628
c19d1205
ZW
9629static void
9630do_t_hint (void)
9631{
9632 if (unified_syntax && inst.size_req == 4)
9633 inst.instruction = THUMB_OP32 (inst.instruction);
9634 else
9635 inst.instruction = THUMB_OP16 (inst.instruction);
9636}
90e4755a 9637
c19d1205
ZW
9638static void
9639do_t_it (void)
9640{
9641 unsigned int cond = inst.operands[0].imm;
e27ec89e 9642
e07e6e58
NC
9643 set_it_insn_type (IT_INSN);
9644 now_it.mask = (inst.instruction & 0xf) | 0x10;
9645 now_it.cc = cond;
e27ec89e
PB
9646
9647 /* If the condition is a negative condition, invert the mask. */
c19d1205 9648 if ((cond & 0x1) == 0x0)
90e4755a 9649 {
c19d1205 9650 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9651
c19d1205
ZW
9652 if ((mask & 0x7) == 0)
9653 /* no conversion needed */;
9654 else if ((mask & 0x3) == 0)
e27ec89e
PB
9655 mask ^= 0x8;
9656 else if ((mask & 0x1) == 0)
9657 mask ^= 0xC;
c19d1205 9658 else
e27ec89e 9659 mask ^= 0xE;
90e4755a 9660
e27ec89e
PB
9661 inst.instruction &= 0xfff0;
9662 inst.instruction |= mask;
c19d1205 9663 }
90e4755a 9664
c19d1205
ZW
9665 inst.instruction |= cond << 4;
9666}
90e4755a 9667
3c707909
PB
9668/* Helper function used for both push/pop and ldm/stm. */
9669static void
9670encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9671{
9672 bfd_boolean load;
9673
9674 load = (inst.instruction & (1 << 20)) != 0;
9675
9676 if (mask & (1 << 13))
9677 inst.error = _("SP not allowed in register list");
9678 if (load)
9679 {
e07e6e58
NC
9680 if (mask & (1 << 15))
9681 {
9682 if (mask & (1 << 14))
9683 inst.error = _("LR and PC should not both be in register list");
9684 else
9685 set_it_insn_type_last ();
9686 }
3c707909
PB
9687
9688 if ((mask & (1 << base)) != 0
9689 && writeback)
9690 as_warn (_("base register should not be in register list "
9691 "when written back"));
9692 }
9693 else
9694 {
9695 if (mask & (1 << 15))
9696 inst.error = _("PC not allowed in register list");
9697
9698 if (mask & (1 << base))
9699 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9700 }
9701
9702 if ((mask & (mask - 1)) == 0)
9703 {
9704 /* Single register transfers implemented as str/ldr. */
9705 if (writeback)
9706 {
9707 if (inst.instruction & (1 << 23))
9708 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9709 else
9710 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9711 }
9712 else
9713 {
9714 if (inst.instruction & (1 << 23))
9715 inst.instruction = 0x00800000; /* ia -> [base] */
9716 else
9717 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9718 }
9719
9720 inst.instruction |= 0xf8400000;
9721 if (load)
9722 inst.instruction |= 0x00100000;
9723
5f4273c7 9724 mask = ffs (mask) - 1;
3c707909
PB
9725 mask <<= 12;
9726 }
9727 else if (writeback)
9728 inst.instruction |= WRITE_BACK;
9729
9730 inst.instruction |= mask;
9731 inst.instruction |= base << 16;
9732}
9733
c19d1205
ZW
9734static void
9735do_t_ldmstm (void)
9736{
9737 /* This really doesn't seem worth it. */
9738 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9739 _("expression too complex"));
9740 constraint (inst.operands[1].writeback,
9741 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9742
c19d1205
ZW
9743 if (unified_syntax)
9744 {
3c707909
PB
9745 bfd_boolean narrow;
9746 unsigned mask;
9747
9748 narrow = FALSE;
c19d1205
ZW
9749 /* See if we can use a 16-bit instruction. */
9750 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9751 && inst.size_req != 4
3c707909 9752 && !(inst.operands[1].imm & ~0xff))
90e4755a 9753 {
3c707909 9754 mask = 1 << inst.operands[0].reg;
90e4755a 9755
3c707909
PB
9756 if (inst.operands[0].reg <= 7
9757 && (inst.instruction == T_MNEM_stmia
9758 ? inst.operands[0].writeback
9759 : (inst.operands[0].writeback
9760 == !(inst.operands[1].imm & mask))))
90e4755a 9761 {
3c707909
PB
9762 if (inst.instruction == T_MNEM_stmia
9763 && (inst.operands[1].imm & mask)
9764 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9765 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9766 inst.operands[0].reg);
3c707909
PB
9767
9768 inst.instruction = THUMB_OP16 (inst.instruction);
9769 inst.instruction |= inst.operands[0].reg << 8;
9770 inst.instruction |= inst.operands[1].imm;
9771 narrow = TRUE;
90e4755a 9772 }
3c707909
PB
9773 else if (inst.operands[0] .reg == REG_SP
9774 && inst.operands[0].writeback)
90e4755a 9775 {
3c707909
PB
9776 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9777 ? T_MNEM_push : T_MNEM_pop);
9778 inst.instruction |= inst.operands[1].imm;
9779 narrow = TRUE;
90e4755a 9780 }
3c707909
PB
9781 }
9782
9783 if (!narrow)
9784 {
c19d1205
ZW
9785 if (inst.instruction < 0xffff)
9786 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9787
5f4273c7
NC
9788 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9789 inst.operands[0].writeback);
90e4755a
RE
9790 }
9791 }
c19d1205 9792 else
90e4755a 9793 {
c19d1205
ZW
9794 constraint (inst.operands[0].reg > 7
9795 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9796 constraint (inst.instruction != T_MNEM_ldmia
9797 && inst.instruction != T_MNEM_stmia,
9798 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9799 if (inst.instruction == T_MNEM_stmia)
f03698e6 9800 {
c19d1205
ZW
9801 if (!inst.operands[0].writeback)
9802 as_warn (_("this instruction will write back the base register"));
9803 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9804 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9805 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9806 inst.operands[0].reg);
f03698e6 9807 }
c19d1205 9808 else
90e4755a 9809 {
c19d1205
ZW
9810 if (!inst.operands[0].writeback
9811 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9812 as_warn (_("this instruction will write back the base register"));
9813 else if (inst.operands[0].writeback
9814 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9815 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9816 }
9817
c19d1205
ZW
9818 inst.instruction = THUMB_OP16 (inst.instruction);
9819 inst.instruction |= inst.operands[0].reg << 8;
9820 inst.instruction |= inst.operands[1].imm;
9821 }
9822}
e28cd48c 9823
c19d1205
ZW
9824static void
9825do_t_ldrex (void)
9826{
9827 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9828 || inst.operands[1].postind || inst.operands[1].writeback
9829 || inst.operands[1].immisreg || inst.operands[1].shifted
9830 || inst.operands[1].negative,
01cfc07f 9831 BAD_ADDR_MODE);
e28cd48c 9832
c19d1205
ZW
9833 inst.instruction |= inst.operands[0].reg << 12;
9834 inst.instruction |= inst.operands[1].reg << 16;
9835 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9836}
e28cd48c 9837
c19d1205
ZW
9838static void
9839do_t_ldrexd (void)
9840{
9841 if (!inst.operands[1].present)
1cac9012 9842 {
c19d1205
ZW
9843 constraint (inst.operands[0].reg == REG_LR,
9844 _("r14 not allowed as first register "
9845 "when second register is omitted"));
9846 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9847 }
c19d1205
ZW
9848 constraint (inst.operands[0].reg == inst.operands[1].reg,
9849 BAD_OVERLAP);
b99bd4ef 9850
c19d1205
ZW
9851 inst.instruction |= inst.operands[0].reg << 12;
9852 inst.instruction |= inst.operands[1].reg << 8;
9853 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9854}
9855
9856static void
c19d1205 9857do_t_ldst (void)
b99bd4ef 9858{
0110f2b8
PB
9859 unsigned long opcode;
9860 int Rn;
9861
e07e6e58
NC
9862 if (inst.operands[0].isreg
9863 && !inst.operands[0].preind
9864 && inst.operands[0].reg == REG_PC)
9865 set_it_insn_type_last ();
9866
0110f2b8 9867 opcode = inst.instruction;
c19d1205 9868 if (unified_syntax)
b99bd4ef 9869 {
53365c0d
PB
9870 if (!inst.operands[1].isreg)
9871 {
9872 if (opcode <= 0xffff)
9873 inst.instruction = THUMB_OP32 (opcode);
9874 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9875 return;
9876 }
0110f2b8
PB
9877 if (inst.operands[1].isreg
9878 && !inst.operands[1].writeback
c19d1205
ZW
9879 && !inst.operands[1].shifted && !inst.operands[1].postind
9880 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9881 && opcode <= 0xffff
9882 && inst.size_req != 4)
c19d1205 9883 {
0110f2b8
PB
9884 /* Insn may have a 16-bit form. */
9885 Rn = inst.operands[1].reg;
9886 if (inst.operands[1].immisreg)
9887 {
9888 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9889 /* [Rn, Rik] */
0110f2b8
PB
9890 if (Rn <= 7 && inst.operands[1].imm <= 7)
9891 goto op16;
9892 }
9893 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9894 && opcode != T_MNEM_ldrsb)
9895 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9896 || (Rn == REG_SP && opcode == T_MNEM_str))
9897 {
9898 /* [Rn, #const] */
9899 if (Rn > 7)
9900 {
9901 if (Rn == REG_PC)
9902 {
9903 if (inst.reloc.pc_rel)
9904 opcode = T_MNEM_ldr_pc2;
9905 else
9906 opcode = T_MNEM_ldr_pc;
9907 }
9908 else
9909 {
9910 if (opcode == T_MNEM_ldr)
9911 opcode = T_MNEM_ldr_sp;
9912 else
9913 opcode = T_MNEM_str_sp;
9914 }
9915 inst.instruction = inst.operands[0].reg << 8;
9916 }
9917 else
9918 {
9919 inst.instruction = inst.operands[0].reg;
9920 inst.instruction |= inst.operands[1].reg << 3;
9921 }
9922 inst.instruction |= THUMB_OP16 (opcode);
9923 if (inst.size_req == 2)
9924 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9925 else
9926 inst.relax = opcode;
9927 return;
9928 }
c19d1205 9929 }
0110f2b8
PB
9930 /* Definitely a 32-bit variant. */
9931 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9932 inst.instruction |= inst.operands[0].reg << 12;
9933 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9934 return;
9935 }
9936
c19d1205
ZW
9937 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9938
9939 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9940 {
c19d1205
ZW
9941 /* Only [Rn,Rm] is acceptable. */
9942 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9943 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9944 || inst.operands[1].postind || inst.operands[1].shifted
9945 || inst.operands[1].negative,
9946 _("Thumb does not support this addressing mode"));
9947 inst.instruction = THUMB_OP16 (inst.instruction);
9948 goto op16;
b99bd4ef 9949 }
5f4273c7 9950
c19d1205
ZW
9951 inst.instruction = THUMB_OP16 (inst.instruction);
9952 if (!inst.operands[1].isreg)
9953 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9954 return;
b99bd4ef 9955
c19d1205
ZW
9956 constraint (!inst.operands[1].preind
9957 || inst.operands[1].shifted
9958 || inst.operands[1].writeback,
9959 _("Thumb does not support this addressing mode"));
9960 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9961 {
c19d1205
ZW
9962 constraint (inst.instruction & 0x0600,
9963 _("byte or halfword not valid for base register"));
9964 constraint (inst.operands[1].reg == REG_PC
9965 && !(inst.instruction & THUMB_LOAD_BIT),
9966 _("r15 based store not allowed"));
9967 constraint (inst.operands[1].immisreg,
9968 _("invalid base register for register offset"));
b99bd4ef 9969
c19d1205
ZW
9970 if (inst.operands[1].reg == REG_PC)
9971 inst.instruction = T_OPCODE_LDR_PC;
9972 else if (inst.instruction & THUMB_LOAD_BIT)
9973 inst.instruction = T_OPCODE_LDR_SP;
9974 else
9975 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9976
c19d1205
ZW
9977 inst.instruction |= inst.operands[0].reg << 8;
9978 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9979 return;
9980 }
90e4755a 9981
c19d1205
ZW
9982 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9983 if (!inst.operands[1].immisreg)
9984 {
9985 /* Immediate offset. */
9986 inst.instruction |= inst.operands[0].reg;
9987 inst.instruction |= inst.operands[1].reg << 3;
9988 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9989 return;
9990 }
90e4755a 9991
c19d1205
ZW
9992 /* Register offset. */
9993 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9994 constraint (inst.operands[1].negative,
9995 _("Thumb does not support this addressing mode"));
90e4755a 9996
c19d1205
ZW
9997 op16:
9998 switch (inst.instruction)
9999 {
10000 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10001 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10002 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10003 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10004 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10005 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10006 case 0x5600 /* ldrsb */:
10007 case 0x5e00 /* ldrsh */: break;
10008 default: abort ();
10009 }
90e4755a 10010
c19d1205
ZW
10011 inst.instruction |= inst.operands[0].reg;
10012 inst.instruction |= inst.operands[1].reg << 3;
10013 inst.instruction |= inst.operands[1].imm << 6;
10014}
90e4755a 10015
c19d1205
ZW
10016static void
10017do_t_ldstd (void)
10018{
10019 if (!inst.operands[1].present)
b99bd4ef 10020 {
c19d1205
ZW
10021 inst.operands[1].reg = inst.operands[0].reg + 1;
10022 constraint (inst.operands[0].reg == REG_LR,
10023 _("r14 not allowed here"));
b99bd4ef 10024 }
c19d1205
ZW
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 inst.instruction |= inst.operands[1].reg << 8;
10027 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10028}
10029
c19d1205
ZW
10030static void
10031do_t_ldstt (void)
10032{
10033 inst.instruction |= inst.operands[0].reg << 12;
10034 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10035}
a737bd4d 10036
b99bd4ef 10037static void
c19d1205 10038do_t_mla (void)
b99bd4ef 10039{
fdfde340 10040 unsigned Rd, Rn, Rm, Ra;
c921be7d 10041
fdfde340
JM
10042 Rd = inst.operands[0].reg;
10043 Rn = inst.operands[1].reg;
10044 Rm = inst.operands[2].reg;
10045 Ra = inst.operands[3].reg;
10046
10047 reject_bad_reg (Rd);
10048 reject_bad_reg (Rn);
10049 reject_bad_reg (Rm);
10050 reject_bad_reg (Ra);
10051
10052 inst.instruction |= Rd << 8;
10053 inst.instruction |= Rn << 16;
10054 inst.instruction |= Rm;
10055 inst.instruction |= Ra << 12;
c19d1205 10056}
b99bd4ef 10057
c19d1205
ZW
10058static void
10059do_t_mlal (void)
10060{
fdfde340
JM
10061 unsigned RdLo, RdHi, Rn, Rm;
10062
10063 RdLo = inst.operands[0].reg;
10064 RdHi = inst.operands[1].reg;
10065 Rn = inst.operands[2].reg;
10066 Rm = inst.operands[3].reg;
10067
10068 reject_bad_reg (RdLo);
10069 reject_bad_reg (RdHi);
10070 reject_bad_reg (Rn);
10071 reject_bad_reg (Rm);
10072
10073 inst.instruction |= RdLo << 12;
10074 inst.instruction |= RdHi << 8;
10075 inst.instruction |= Rn << 16;
10076 inst.instruction |= Rm;
c19d1205 10077}
b99bd4ef 10078
c19d1205
ZW
10079static void
10080do_t_mov_cmp (void)
10081{
fdfde340
JM
10082 unsigned Rn, Rm;
10083
10084 Rn = inst.operands[0].reg;
10085 Rm = inst.operands[1].reg;
10086
e07e6e58
NC
10087 if (Rn == REG_PC)
10088 set_it_insn_type_last ();
10089
c19d1205 10090 if (unified_syntax)
b99bd4ef 10091 {
c19d1205
ZW
10092 int r0off = (inst.instruction == T_MNEM_mov
10093 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10094 unsigned long opcode;
3d388997
PB
10095 bfd_boolean narrow;
10096 bfd_boolean low_regs;
10097
fdfde340 10098 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10099 opcode = inst.instruction;
e07e6e58 10100 if (in_it_block ())
0110f2b8 10101 narrow = opcode != T_MNEM_movs;
3d388997 10102 else
0110f2b8 10103 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10104 if (inst.size_req == 4
10105 || inst.operands[1].shifted)
10106 narrow = FALSE;
10107
efd81785
PB
10108 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10109 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10110 && !inst.operands[1].shifted
fdfde340
JM
10111 && Rn == REG_PC
10112 && Rm == REG_LR)
efd81785
PB
10113 {
10114 inst.instruction = T2_SUBS_PC_LR;
10115 return;
10116 }
10117
fdfde340
JM
10118 if (opcode == T_MNEM_cmp)
10119 {
10120 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10121 if (narrow)
10122 {
10123 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10124 but valid. */
10125 warn_deprecated_sp (Rm);
10126 /* R15 was documented as a valid choice for Rm in ARMv6,
10127 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10128 tools reject R15, so we do too. */
10129 constraint (Rm == REG_PC, BAD_PC);
10130 }
10131 else
10132 reject_bad_reg (Rm);
fdfde340
JM
10133 }
10134 else if (opcode == T_MNEM_mov
10135 || opcode == T_MNEM_movs)
10136 {
10137 if (inst.operands[1].isreg)
10138 {
10139 if (opcode == T_MNEM_movs)
10140 {
10141 reject_bad_reg (Rn);
10142 reject_bad_reg (Rm);
10143 }
10144 else if ((Rn == REG_SP || Rn == REG_PC)
10145 && (Rm == REG_SP || Rm == REG_PC))
10146 reject_bad_reg (Rm);
10147 }
10148 else
10149 reject_bad_reg (Rn);
10150 }
10151
c19d1205
ZW
10152 if (!inst.operands[1].isreg)
10153 {
0110f2b8 10154 /* Immediate operand. */
e07e6e58 10155 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10156 narrow = 0;
10157 if (low_regs && narrow)
10158 {
10159 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10160 inst.instruction |= Rn << 8;
0110f2b8
PB
10161 if (inst.size_req == 2)
10162 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10163 else
10164 inst.relax = opcode;
10165 }
10166 else
10167 {
10168 inst.instruction = THUMB_OP32 (inst.instruction);
10169 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10170 inst.instruction |= Rn << r0off;
0110f2b8
PB
10171 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10172 }
c19d1205 10173 }
728ca7c9
PB
10174 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10175 && (inst.instruction == T_MNEM_mov
10176 || inst.instruction == T_MNEM_movs))
10177 {
10178 /* Register shifts are encoded as separate shift instructions. */
10179 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10180
e07e6e58 10181 if (in_it_block ())
728ca7c9
PB
10182 narrow = !flags;
10183 else
10184 narrow = flags;
10185
10186 if (inst.size_req == 4)
10187 narrow = FALSE;
10188
10189 if (!low_regs || inst.operands[1].imm > 7)
10190 narrow = FALSE;
10191
fdfde340 10192 if (Rn != Rm)
728ca7c9
PB
10193 narrow = FALSE;
10194
10195 switch (inst.operands[1].shift_kind)
10196 {
10197 case SHIFT_LSL:
10198 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10199 break;
10200 case SHIFT_ASR:
10201 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10202 break;
10203 case SHIFT_LSR:
10204 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10205 break;
10206 case SHIFT_ROR:
10207 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10208 break;
10209 default:
5f4273c7 10210 abort ();
728ca7c9
PB
10211 }
10212
10213 inst.instruction = opcode;
10214 if (narrow)
10215 {
fdfde340 10216 inst.instruction |= Rn;
728ca7c9
PB
10217 inst.instruction |= inst.operands[1].imm << 3;
10218 }
10219 else
10220 {
10221 if (flags)
10222 inst.instruction |= CONDS_BIT;
10223
fdfde340
JM
10224 inst.instruction |= Rn << 8;
10225 inst.instruction |= Rm << 16;
728ca7c9
PB
10226 inst.instruction |= inst.operands[1].imm;
10227 }
10228 }
3d388997 10229 else if (!narrow)
c19d1205 10230 {
728ca7c9
PB
10231 /* Some mov with immediate shift have narrow variants.
10232 Register shifts are handled above. */
10233 if (low_regs && inst.operands[1].shifted
10234 && (inst.instruction == T_MNEM_mov
10235 || inst.instruction == T_MNEM_movs))
10236 {
e07e6e58 10237 if (in_it_block ())
728ca7c9
PB
10238 narrow = (inst.instruction == T_MNEM_mov);
10239 else
10240 narrow = (inst.instruction == T_MNEM_movs);
10241 }
10242
10243 if (narrow)
10244 {
10245 switch (inst.operands[1].shift_kind)
10246 {
10247 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10248 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10249 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10250 default: narrow = FALSE; break;
10251 }
10252 }
10253
10254 if (narrow)
10255 {
fdfde340
JM
10256 inst.instruction |= Rn;
10257 inst.instruction |= Rm << 3;
728ca7c9
PB
10258 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10259 }
10260 else
10261 {
10262 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10263 inst.instruction |= Rn << r0off;
728ca7c9
PB
10264 encode_thumb32_shifted_operand (1);
10265 }
c19d1205
ZW
10266 }
10267 else
10268 switch (inst.instruction)
10269 {
10270 case T_MNEM_mov:
10271 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10272 inst.instruction |= (Rn & 0x8) << 4;
10273 inst.instruction |= (Rn & 0x7);
10274 inst.instruction |= Rm << 3;
c19d1205 10275 break;
b99bd4ef 10276
c19d1205
ZW
10277 case T_MNEM_movs:
10278 /* We know we have low registers at this point.
10279 Generate ADD Rd, Rs, #0. */
10280 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10281 inst.instruction |= Rn;
10282 inst.instruction |= Rm << 3;
c19d1205
ZW
10283 break;
10284
10285 case T_MNEM_cmp:
3d388997 10286 if (low_regs)
c19d1205
ZW
10287 {
10288 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10289 inst.instruction |= Rn;
10290 inst.instruction |= Rm << 3;
c19d1205
ZW
10291 }
10292 else
10293 {
10294 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10295 inst.instruction |= (Rn & 0x8) << 4;
10296 inst.instruction |= (Rn & 0x7);
10297 inst.instruction |= Rm << 3;
c19d1205
ZW
10298 }
10299 break;
10300 }
b99bd4ef
NC
10301 return;
10302 }
10303
c19d1205 10304 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10305
10306 /* PR 10443: Do not silently ignore shifted operands. */
10307 constraint (inst.operands[1].shifted,
10308 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10309
c19d1205 10310 if (inst.operands[1].isreg)
b99bd4ef 10311 {
fdfde340 10312 if (Rn < 8 && Rm < 8)
b99bd4ef 10313 {
c19d1205
ZW
10314 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10315 since a MOV instruction produces unpredictable results. */
10316 if (inst.instruction == T_OPCODE_MOV_I8)
10317 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10318 else
c19d1205 10319 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10320
fdfde340
JM
10321 inst.instruction |= Rn;
10322 inst.instruction |= Rm << 3;
b99bd4ef
NC
10323 }
10324 else
10325 {
c19d1205
ZW
10326 if (inst.instruction == T_OPCODE_MOV_I8)
10327 inst.instruction = T_OPCODE_MOV_HR;
10328 else
10329 inst.instruction = T_OPCODE_CMP_HR;
10330 do_t_cpy ();
b99bd4ef
NC
10331 }
10332 }
c19d1205 10333 else
b99bd4ef 10334 {
fdfde340 10335 constraint (Rn > 7,
c19d1205 10336 _("only lo regs allowed with immediate"));
fdfde340 10337 inst.instruction |= Rn << 8;
c19d1205
ZW
10338 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10339 }
10340}
b99bd4ef 10341
c19d1205
ZW
10342static void
10343do_t_mov16 (void)
10344{
fdfde340 10345 unsigned Rd;
b6895b4f
PB
10346 bfd_vma imm;
10347 bfd_boolean top;
10348
10349 top = (inst.instruction & 0x00800000) != 0;
10350 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10351 {
10352 constraint (top, _(":lower16: not allowed this instruction"));
10353 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10354 }
10355 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10356 {
10357 constraint (!top, _(":upper16: not allowed this instruction"));
10358 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10359 }
10360
fdfde340
JM
10361 Rd = inst.operands[0].reg;
10362 reject_bad_reg (Rd);
10363
10364 inst.instruction |= Rd << 8;
b6895b4f
PB
10365 if (inst.reloc.type == BFD_RELOC_UNUSED)
10366 {
10367 imm = inst.reloc.exp.X_add_number;
10368 inst.instruction |= (imm & 0xf000) << 4;
10369 inst.instruction |= (imm & 0x0800) << 15;
10370 inst.instruction |= (imm & 0x0700) << 4;
10371 inst.instruction |= (imm & 0x00ff);
10372 }
c19d1205 10373}
b99bd4ef 10374
c19d1205
ZW
10375static void
10376do_t_mvn_tst (void)
10377{
fdfde340 10378 unsigned Rn, Rm;
c921be7d 10379
fdfde340
JM
10380 Rn = inst.operands[0].reg;
10381 Rm = inst.operands[1].reg;
10382
10383 if (inst.instruction == T_MNEM_cmp
10384 || inst.instruction == T_MNEM_cmn)
10385 constraint (Rn == REG_PC, BAD_PC);
10386 else
10387 reject_bad_reg (Rn);
10388 reject_bad_reg (Rm);
10389
c19d1205
ZW
10390 if (unified_syntax)
10391 {
10392 int r0off = (inst.instruction == T_MNEM_mvn
10393 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10394 bfd_boolean narrow;
10395
10396 if (inst.size_req == 4
10397 || inst.instruction > 0xffff
10398 || inst.operands[1].shifted
fdfde340 10399 || Rn > 7 || Rm > 7)
3d388997
PB
10400 narrow = FALSE;
10401 else if (inst.instruction == T_MNEM_cmn)
10402 narrow = TRUE;
10403 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10404 narrow = !in_it_block ();
3d388997 10405 else
e07e6e58 10406 narrow = in_it_block ();
3d388997 10407
c19d1205 10408 if (!inst.operands[1].isreg)
b99bd4ef 10409 {
c19d1205
ZW
10410 /* For an immediate, we always generate a 32-bit opcode;
10411 section relaxation will shrink it later if possible. */
10412 if (inst.instruction < 0xffff)
10413 inst.instruction = THUMB_OP32 (inst.instruction);
10414 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10415 inst.instruction |= Rn << r0off;
c19d1205 10416 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10417 }
c19d1205 10418 else
b99bd4ef 10419 {
c19d1205 10420 /* See if we can do this with a 16-bit instruction. */
3d388997 10421 if (narrow)
b99bd4ef 10422 {
c19d1205 10423 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10424 inst.instruction |= Rn;
10425 inst.instruction |= Rm << 3;
b99bd4ef 10426 }
c19d1205 10427 else
b99bd4ef 10428 {
c19d1205
ZW
10429 constraint (inst.operands[1].shifted
10430 && inst.operands[1].immisreg,
10431 _("shift must be constant"));
10432 if (inst.instruction < 0xffff)
10433 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10434 inst.instruction |= Rn << r0off;
c19d1205 10435 encode_thumb32_shifted_operand (1);
b99bd4ef 10436 }
b99bd4ef
NC
10437 }
10438 }
10439 else
10440 {
c19d1205
ZW
10441 constraint (inst.instruction > 0xffff
10442 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10443 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10444 _("unshifted register required"));
fdfde340 10445 constraint (Rn > 7 || Rm > 7,
c19d1205 10446 BAD_HIREG);
b99bd4ef 10447
c19d1205 10448 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10449 inst.instruction |= Rn;
10450 inst.instruction |= Rm << 3;
b99bd4ef 10451 }
b99bd4ef
NC
10452}
10453
b05fe5cf 10454static void
c19d1205 10455do_t_mrs (void)
b05fe5cf 10456{
fdfde340 10457 unsigned Rd;
62b3e311 10458 int flags;
037e8744
JB
10459
10460 if (do_vfp_nsyn_mrs () == SUCCESS)
10461 return;
10462
62b3e311
PB
10463 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10464 if (flags == 0)
10465 {
7e806470 10466 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10467 _("selected processor does not support "
10468 "requested special purpose register"));
10469 }
10470 else
10471 {
10472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10473 _("selected processor does not support "
44bf2362 10474 "requested special purpose register"));
62b3e311
PB
10475 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10476 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10477 _("'CPSR' or 'SPSR' expected"));
10478 }
5f4273c7 10479
fdfde340
JM
10480 Rd = inst.operands[0].reg;
10481 reject_bad_reg (Rd);
10482
10483 inst.instruction |= Rd << 8;
62b3e311
PB
10484 inst.instruction |= (flags & SPSR_BIT) >> 2;
10485 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10486}
b05fe5cf 10487
c19d1205
ZW
10488static void
10489do_t_msr (void)
10490{
62b3e311 10491 int flags;
fdfde340 10492 unsigned Rn;
62b3e311 10493
037e8744
JB
10494 if (do_vfp_nsyn_msr () == SUCCESS)
10495 return;
10496
c19d1205
ZW
10497 constraint (!inst.operands[1].isreg,
10498 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10499 flags = inst.operands[0].imm;
10500 if (flags & ~0xff)
10501 {
10502 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10503 _("selected processor does not support "
10504 "requested special purpose register"));
10505 }
10506 else
10507 {
7e806470 10508 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10509 _("selected processor does not support "
10510 "requested special purpose register"));
10511 flags |= PSR_f;
10512 }
c921be7d 10513
fdfde340
JM
10514 Rn = inst.operands[1].reg;
10515 reject_bad_reg (Rn);
10516
62b3e311
PB
10517 inst.instruction |= (flags & SPSR_BIT) >> 2;
10518 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10519 inst.instruction |= (flags & 0xff);
fdfde340 10520 inst.instruction |= Rn << 16;
c19d1205 10521}
b05fe5cf 10522
c19d1205
ZW
10523static void
10524do_t_mul (void)
10525{
17828f45 10526 bfd_boolean narrow;
fdfde340 10527 unsigned Rd, Rn, Rm;
17828f45 10528
c19d1205
ZW
10529 if (!inst.operands[2].present)
10530 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10531
fdfde340
JM
10532 Rd = inst.operands[0].reg;
10533 Rn = inst.operands[1].reg;
10534 Rm = inst.operands[2].reg;
10535
17828f45 10536 if (unified_syntax)
b05fe5cf 10537 {
17828f45 10538 if (inst.size_req == 4
fdfde340
JM
10539 || (Rd != Rn
10540 && Rd != Rm)
10541 || Rn > 7
10542 || Rm > 7)
17828f45
JM
10543 narrow = FALSE;
10544 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10545 narrow = !in_it_block ();
17828f45 10546 else
e07e6e58 10547 narrow = in_it_block ();
b05fe5cf 10548 }
c19d1205 10549 else
b05fe5cf 10550 {
17828f45 10551 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10552 constraint (Rn > 7 || Rm > 7,
c19d1205 10553 BAD_HIREG);
17828f45
JM
10554 narrow = TRUE;
10555 }
b05fe5cf 10556
17828f45
JM
10557 if (narrow)
10558 {
10559 /* 16-bit MULS/Conditional MUL. */
c19d1205 10560 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10561 inst.instruction |= Rd;
b05fe5cf 10562
fdfde340
JM
10563 if (Rd == Rn)
10564 inst.instruction |= Rm << 3;
10565 else if (Rd == Rm)
10566 inst.instruction |= Rn << 3;
c19d1205
ZW
10567 else
10568 constraint (1, _("dest must overlap one source register"));
10569 }
17828f45
JM
10570 else
10571 {
e07e6e58
NC
10572 constraint (inst.instruction != T_MNEM_mul,
10573 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10574 /* 32-bit MUL. */
10575 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10576 inst.instruction |= Rd << 8;
10577 inst.instruction |= Rn << 16;
10578 inst.instruction |= Rm << 0;
10579
10580 reject_bad_reg (Rd);
10581 reject_bad_reg (Rn);
10582 reject_bad_reg (Rm);
17828f45 10583 }
c19d1205 10584}
b05fe5cf 10585
c19d1205
ZW
10586static void
10587do_t_mull (void)
10588{
fdfde340 10589 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10590
fdfde340
JM
10591 RdLo = inst.operands[0].reg;
10592 RdHi = inst.operands[1].reg;
10593 Rn = inst.operands[2].reg;
10594 Rm = inst.operands[3].reg;
10595
10596 reject_bad_reg (RdLo);
10597 reject_bad_reg (RdHi);
10598 reject_bad_reg (Rn);
10599 reject_bad_reg (Rm);
10600
10601 inst.instruction |= RdLo << 12;
10602 inst.instruction |= RdHi << 8;
10603 inst.instruction |= Rn << 16;
10604 inst.instruction |= Rm;
10605
10606 if (RdLo == RdHi)
c19d1205
ZW
10607 as_tsktsk (_("rdhi and rdlo must be different"));
10608}
b05fe5cf 10609
c19d1205
ZW
10610static void
10611do_t_nop (void)
10612{
e07e6e58
NC
10613 set_it_insn_type (NEUTRAL_IT_INSN);
10614
c19d1205
ZW
10615 if (unified_syntax)
10616 {
10617 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10618 {
c19d1205
ZW
10619 inst.instruction = THUMB_OP32 (inst.instruction);
10620 inst.instruction |= inst.operands[0].imm;
10621 }
10622 else
10623 {
bc2d1808
NC
10624 /* PR9722: Check for Thumb2 availability before
10625 generating a thumb2 nop instruction. */
10626 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10627 {
10628 inst.instruction = THUMB_OP16 (inst.instruction);
10629 inst.instruction |= inst.operands[0].imm << 4;
10630 }
10631 else
10632 inst.instruction = 0x46c0;
c19d1205
ZW
10633 }
10634 }
10635 else
10636 {
10637 constraint (inst.operands[0].present,
10638 _("Thumb does not support NOP with hints"));
10639 inst.instruction = 0x46c0;
10640 }
10641}
b05fe5cf 10642
c19d1205
ZW
10643static void
10644do_t_neg (void)
10645{
10646 if (unified_syntax)
10647 {
3d388997
PB
10648 bfd_boolean narrow;
10649
10650 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10651 narrow = !in_it_block ();
3d388997 10652 else
e07e6e58 10653 narrow = in_it_block ();
3d388997
PB
10654 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10655 narrow = FALSE;
10656 if (inst.size_req == 4)
10657 narrow = FALSE;
10658
10659 if (!narrow)
c19d1205
ZW
10660 {
10661 inst.instruction = THUMB_OP32 (inst.instruction);
10662 inst.instruction |= inst.operands[0].reg << 8;
10663 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10664 }
10665 else
10666 {
c19d1205
ZW
10667 inst.instruction = THUMB_OP16 (inst.instruction);
10668 inst.instruction |= inst.operands[0].reg;
10669 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10670 }
10671 }
10672 else
10673 {
c19d1205
ZW
10674 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10675 BAD_HIREG);
10676 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10677
10678 inst.instruction = THUMB_OP16 (inst.instruction);
10679 inst.instruction |= inst.operands[0].reg;
10680 inst.instruction |= inst.operands[1].reg << 3;
10681 }
10682}
10683
1c444d06
JM
10684static void
10685do_t_orn (void)
10686{
10687 unsigned Rd, Rn;
10688
10689 Rd = inst.operands[0].reg;
10690 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10691
fdfde340
JM
10692 reject_bad_reg (Rd);
10693 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10694 reject_bad_reg (Rn);
10695
1c444d06
JM
10696 inst.instruction |= Rd << 8;
10697 inst.instruction |= Rn << 16;
10698
10699 if (!inst.operands[2].isreg)
10700 {
10701 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10702 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10703 }
10704 else
10705 {
10706 unsigned Rm;
10707
10708 Rm = inst.operands[2].reg;
fdfde340 10709 reject_bad_reg (Rm);
1c444d06
JM
10710
10711 constraint (inst.operands[2].shifted
10712 && inst.operands[2].immisreg,
10713 _("shift must be constant"));
10714 encode_thumb32_shifted_operand (2);
10715 }
10716}
10717
c19d1205
ZW
10718static void
10719do_t_pkhbt (void)
10720{
fdfde340
JM
10721 unsigned Rd, Rn, Rm;
10722
10723 Rd = inst.operands[0].reg;
10724 Rn = inst.operands[1].reg;
10725 Rm = inst.operands[2].reg;
10726
10727 reject_bad_reg (Rd);
10728 reject_bad_reg (Rn);
10729 reject_bad_reg (Rm);
10730
10731 inst.instruction |= Rd << 8;
10732 inst.instruction |= Rn << 16;
10733 inst.instruction |= Rm;
c19d1205
ZW
10734 if (inst.operands[3].present)
10735 {
10736 unsigned int val = inst.reloc.exp.X_add_number;
10737 constraint (inst.reloc.exp.X_op != O_constant,
10738 _("expression too complex"));
10739 inst.instruction |= (val & 0x1c) << 10;
10740 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10741 }
c19d1205 10742}
b05fe5cf 10743
c19d1205
ZW
10744static void
10745do_t_pkhtb (void)
10746{
10747 if (!inst.operands[3].present)
1ef52f49
NC
10748 {
10749 unsigned Rtmp;
10750
10751 inst.instruction &= ~0x00000020;
10752
10753 /* PR 10168. Swap the Rm and Rn registers. */
10754 Rtmp = inst.operands[1].reg;
10755 inst.operands[1].reg = inst.operands[2].reg;
10756 inst.operands[2].reg = Rtmp;
10757 }
c19d1205 10758 do_t_pkhbt ();
b05fe5cf
ZW
10759}
10760
c19d1205
ZW
10761static void
10762do_t_pld (void)
10763{
fdfde340
JM
10764 if (inst.operands[0].immisreg)
10765 reject_bad_reg (inst.operands[0].imm);
10766
c19d1205
ZW
10767 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10768}
b05fe5cf 10769
c19d1205
ZW
10770static void
10771do_t_push_pop (void)
b99bd4ef 10772{
e9f89963 10773 unsigned mask;
5f4273c7 10774
c19d1205
ZW
10775 constraint (inst.operands[0].writeback,
10776 _("push/pop do not support {reglist}^"));
10777 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10778 _("expression too complex"));
b99bd4ef 10779
e9f89963
PB
10780 mask = inst.operands[0].imm;
10781 if ((mask & ~0xff) == 0)
3c707909 10782 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10783 else if ((inst.instruction == T_MNEM_push
e9f89963 10784 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10785 || (inst.instruction == T_MNEM_pop
e9f89963 10786 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10787 {
c19d1205
ZW
10788 inst.instruction = THUMB_OP16 (inst.instruction);
10789 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10790 inst.instruction |= mask & 0xff;
c19d1205
ZW
10791 }
10792 else if (unified_syntax)
10793 {
3c707909 10794 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10795 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10796 }
10797 else
10798 {
10799 inst.error = _("invalid register list to push/pop instruction");
10800 return;
10801 }
c19d1205 10802}
b99bd4ef 10803
c19d1205
ZW
10804static void
10805do_t_rbit (void)
10806{
fdfde340
JM
10807 unsigned Rd, Rm;
10808
10809 Rd = inst.operands[0].reg;
10810 Rm = inst.operands[1].reg;
10811
10812 reject_bad_reg (Rd);
10813 reject_bad_reg (Rm);
10814
10815 inst.instruction |= Rd << 8;
10816 inst.instruction |= Rm << 16;
10817 inst.instruction |= Rm;
c19d1205 10818}
b99bd4ef 10819
c19d1205
ZW
10820static void
10821do_t_rev (void)
10822{
fdfde340
JM
10823 unsigned Rd, Rm;
10824
10825 Rd = inst.operands[0].reg;
10826 Rm = inst.operands[1].reg;
10827
10828 reject_bad_reg (Rd);
10829 reject_bad_reg (Rm);
10830
10831 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10832 && inst.size_req != 4)
10833 {
10834 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10835 inst.instruction |= Rd;
10836 inst.instruction |= Rm << 3;
c19d1205
ZW
10837 }
10838 else if (unified_syntax)
10839 {
10840 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10841 inst.instruction |= Rd << 8;
10842 inst.instruction |= Rm << 16;
10843 inst.instruction |= Rm;
c19d1205
ZW
10844 }
10845 else
10846 inst.error = BAD_HIREG;
10847}
b99bd4ef 10848
1c444d06
JM
10849static void
10850do_t_rrx (void)
10851{
10852 unsigned Rd, Rm;
10853
10854 Rd = inst.operands[0].reg;
10855 Rm = inst.operands[1].reg;
10856
fdfde340
JM
10857 reject_bad_reg (Rd);
10858 reject_bad_reg (Rm);
c921be7d 10859
1c444d06
JM
10860 inst.instruction |= Rd << 8;
10861 inst.instruction |= Rm;
10862}
10863
c19d1205
ZW
10864static void
10865do_t_rsb (void)
10866{
fdfde340 10867 unsigned Rd, Rs;
b99bd4ef 10868
c19d1205
ZW
10869 Rd = inst.operands[0].reg;
10870 Rs = (inst.operands[1].present
10871 ? inst.operands[1].reg /* Rd, Rs, foo */
10872 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10873
fdfde340
JM
10874 reject_bad_reg (Rd);
10875 reject_bad_reg (Rs);
10876 if (inst.operands[2].isreg)
10877 reject_bad_reg (inst.operands[2].reg);
10878
c19d1205
ZW
10879 inst.instruction |= Rd << 8;
10880 inst.instruction |= Rs << 16;
10881 if (!inst.operands[2].isreg)
10882 {
026d3abb
PB
10883 bfd_boolean narrow;
10884
10885 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10886 narrow = !in_it_block ();
026d3abb 10887 else
e07e6e58 10888 narrow = in_it_block ();
026d3abb
PB
10889
10890 if (Rd > 7 || Rs > 7)
10891 narrow = FALSE;
10892
10893 if (inst.size_req == 4 || !unified_syntax)
10894 narrow = FALSE;
10895
10896 if (inst.reloc.exp.X_op != O_constant
10897 || inst.reloc.exp.X_add_number != 0)
10898 narrow = FALSE;
10899
10900 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10901 relaxation, but it doesn't seem worth the hassle. */
10902 if (narrow)
10903 {
10904 inst.reloc.type = BFD_RELOC_UNUSED;
10905 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10906 inst.instruction |= Rs << 3;
10907 inst.instruction |= Rd;
10908 }
10909 else
10910 {
10911 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10912 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10913 }
c19d1205
ZW
10914 }
10915 else
10916 encode_thumb32_shifted_operand (2);
10917}
b99bd4ef 10918
c19d1205
ZW
10919static void
10920do_t_setend (void)
10921{
e07e6e58 10922 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10923 if (inst.operands[0].imm)
10924 inst.instruction |= 0x8;
10925}
b99bd4ef 10926
c19d1205
ZW
10927static void
10928do_t_shift (void)
10929{
10930 if (!inst.operands[1].present)
10931 inst.operands[1].reg = inst.operands[0].reg;
10932
10933 if (unified_syntax)
10934 {
3d388997
PB
10935 bfd_boolean narrow;
10936 int shift_kind;
10937
10938 switch (inst.instruction)
10939 {
10940 case T_MNEM_asr:
10941 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10942 case T_MNEM_lsl:
10943 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10944 case T_MNEM_lsr:
10945 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10946 case T_MNEM_ror:
10947 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10948 default: abort ();
10949 }
10950
10951 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10952 narrow = !in_it_block ();
3d388997 10953 else
e07e6e58 10954 narrow = in_it_block ();
3d388997
PB
10955 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10956 narrow = FALSE;
10957 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10958 narrow = FALSE;
10959 if (inst.operands[2].isreg
10960 && (inst.operands[1].reg != inst.operands[0].reg
10961 || inst.operands[2].reg > 7))
10962 narrow = FALSE;
10963 if (inst.size_req == 4)
10964 narrow = FALSE;
10965
fdfde340
JM
10966 reject_bad_reg (inst.operands[0].reg);
10967 reject_bad_reg (inst.operands[1].reg);
c921be7d 10968
3d388997 10969 if (!narrow)
c19d1205
ZW
10970 {
10971 if (inst.operands[2].isreg)
b99bd4ef 10972 {
fdfde340 10973 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10974 inst.instruction = THUMB_OP32 (inst.instruction);
10975 inst.instruction |= inst.operands[0].reg << 8;
10976 inst.instruction |= inst.operands[1].reg << 16;
10977 inst.instruction |= inst.operands[2].reg;
10978 }
10979 else
10980 {
10981 inst.operands[1].shifted = 1;
3d388997 10982 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10983 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10984 ? T_MNEM_movs : T_MNEM_mov);
10985 inst.instruction |= inst.operands[0].reg << 8;
10986 encode_thumb32_shifted_operand (1);
10987 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10988 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10989 }
10990 }
10991 else
10992 {
c19d1205 10993 if (inst.operands[2].isreg)
b99bd4ef 10994 {
3d388997 10995 switch (shift_kind)
b99bd4ef 10996 {
3d388997
PB
10997 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10998 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10999 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11000 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11001 default: abort ();
b99bd4ef 11002 }
5f4273c7 11003
c19d1205
ZW
11004 inst.instruction |= inst.operands[0].reg;
11005 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11006 }
11007 else
11008 {
3d388997 11009 switch (shift_kind)
b99bd4ef 11010 {
3d388997
PB
11011 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11012 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11013 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11014 default: abort ();
b99bd4ef 11015 }
c19d1205
ZW
11016 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11017 inst.instruction |= inst.operands[0].reg;
11018 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11019 }
11020 }
c19d1205
ZW
11021 }
11022 else
11023 {
11024 constraint (inst.operands[0].reg > 7
11025 || inst.operands[1].reg > 7, BAD_HIREG);
11026 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11027
c19d1205
ZW
11028 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11029 {
11030 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11031 constraint (inst.operands[0].reg != inst.operands[1].reg,
11032 _("source1 and dest must be same register"));
b99bd4ef 11033
c19d1205
ZW
11034 switch (inst.instruction)
11035 {
11036 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11037 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11038 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11039 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11040 default: abort ();
11041 }
5f4273c7 11042
c19d1205
ZW
11043 inst.instruction |= inst.operands[0].reg;
11044 inst.instruction |= inst.operands[2].reg << 3;
11045 }
11046 else
b99bd4ef 11047 {
c19d1205
ZW
11048 switch (inst.instruction)
11049 {
11050 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11051 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11052 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11053 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11054 default: abort ();
11055 }
11056 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11057 inst.instruction |= inst.operands[0].reg;
11058 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11059 }
11060 }
b99bd4ef
NC
11061}
11062
11063static void
c19d1205 11064do_t_simd (void)
b99bd4ef 11065{
fdfde340
JM
11066 unsigned Rd, Rn, Rm;
11067
11068 Rd = inst.operands[0].reg;
11069 Rn = inst.operands[1].reg;
11070 Rm = inst.operands[2].reg;
11071
11072 reject_bad_reg (Rd);
11073 reject_bad_reg (Rn);
11074 reject_bad_reg (Rm);
11075
11076 inst.instruction |= Rd << 8;
11077 inst.instruction |= Rn << 16;
11078 inst.instruction |= Rm;
c19d1205 11079}
b99bd4ef 11080
03ee1b7f
NC
11081static void
11082do_t_simd2 (void)
11083{
11084 unsigned Rd, Rn, Rm;
11085
11086 Rd = inst.operands[0].reg;
11087 Rm = inst.operands[1].reg;
11088 Rn = inst.operands[2].reg;
11089
11090 reject_bad_reg (Rd);
11091 reject_bad_reg (Rn);
11092 reject_bad_reg (Rm);
11093
11094 inst.instruction |= Rd << 8;
11095 inst.instruction |= Rn << 16;
11096 inst.instruction |= Rm;
11097}
11098
c19d1205 11099static void
3eb17e6b 11100do_t_smc (void)
c19d1205
ZW
11101{
11102 unsigned int value = inst.reloc.exp.X_add_number;
11103 constraint (inst.reloc.exp.X_op != O_constant,
11104 _("expression too complex"));
11105 inst.reloc.type = BFD_RELOC_UNUSED;
11106 inst.instruction |= (value & 0xf000) >> 12;
11107 inst.instruction |= (value & 0x0ff0);
11108 inst.instruction |= (value & 0x000f) << 16;
11109}
b99bd4ef 11110
c19d1205 11111static void
3a21c15a 11112do_t_ssat_usat (int bias)
c19d1205 11113{
fdfde340
JM
11114 unsigned Rd, Rn;
11115
11116 Rd = inst.operands[0].reg;
11117 Rn = inst.operands[2].reg;
11118
11119 reject_bad_reg (Rd);
11120 reject_bad_reg (Rn);
11121
11122 inst.instruction |= Rd << 8;
3a21c15a 11123 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11124 inst.instruction |= Rn << 16;
b99bd4ef 11125
c19d1205 11126 if (inst.operands[3].present)
b99bd4ef 11127 {
3a21c15a
NC
11128 offsetT shift_amount = inst.reloc.exp.X_add_number;
11129
11130 inst.reloc.type = BFD_RELOC_UNUSED;
11131
c19d1205
ZW
11132 constraint (inst.reloc.exp.X_op != O_constant,
11133 _("expression too complex"));
b99bd4ef 11134
3a21c15a 11135 if (shift_amount != 0)
6189168b 11136 {
3a21c15a
NC
11137 constraint (shift_amount > 31,
11138 _("shift expression is too large"));
11139
c19d1205 11140 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11141 inst.instruction |= 0x00200000; /* sh bit. */
11142
11143 inst.instruction |= (shift_amount & 0x1c) << 10;
11144 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11145 }
11146 }
b99bd4ef 11147}
c921be7d 11148
3a21c15a
NC
11149static void
11150do_t_ssat (void)
11151{
11152 do_t_ssat_usat (1);
11153}
b99bd4ef 11154
0dd132b6 11155static void
c19d1205 11156do_t_ssat16 (void)
0dd132b6 11157{
fdfde340
JM
11158 unsigned Rd, Rn;
11159
11160 Rd = inst.operands[0].reg;
11161 Rn = inst.operands[2].reg;
11162
11163 reject_bad_reg (Rd);
11164 reject_bad_reg (Rn);
11165
11166 inst.instruction |= Rd << 8;
c19d1205 11167 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11168 inst.instruction |= Rn << 16;
c19d1205 11169}
0dd132b6 11170
c19d1205
ZW
11171static void
11172do_t_strex (void)
11173{
11174 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11175 || inst.operands[2].postind || inst.operands[2].writeback
11176 || inst.operands[2].immisreg || inst.operands[2].shifted
11177 || inst.operands[2].negative,
01cfc07f 11178 BAD_ADDR_MODE);
0dd132b6 11179
c19d1205
ZW
11180 inst.instruction |= inst.operands[0].reg << 8;
11181 inst.instruction |= inst.operands[1].reg << 12;
11182 inst.instruction |= inst.operands[2].reg << 16;
11183 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11184}
11185
b99bd4ef 11186static void
c19d1205 11187do_t_strexd (void)
b99bd4ef 11188{
c19d1205
ZW
11189 if (!inst.operands[2].present)
11190 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11191
c19d1205
ZW
11192 constraint (inst.operands[0].reg == inst.operands[1].reg
11193 || inst.operands[0].reg == inst.operands[2].reg
11194 || inst.operands[0].reg == inst.operands[3].reg
11195 || inst.operands[1].reg == inst.operands[2].reg,
11196 BAD_OVERLAP);
b99bd4ef 11197
c19d1205
ZW
11198 inst.instruction |= inst.operands[0].reg;
11199 inst.instruction |= inst.operands[1].reg << 12;
11200 inst.instruction |= inst.operands[2].reg << 8;
11201 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11202}
11203
11204static void
c19d1205 11205do_t_sxtah (void)
b99bd4ef 11206{
fdfde340
JM
11207 unsigned Rd, Rn, Rm;
11208
11209 Rd = inst.operands[0].reg;
11210 Rn = inst.operands[1].reg;
11211 Rm = inst.operands[2].reg;
11212
11213 reject_bad_reg (Rd);
11214 reject_bad_reg (Rn);
11215 reject_bad_reg (Rm);
11216
11217 inst.instruction |= Rd << 8;
11218 inst.instruction |= Rn << 16;
11219 inst.instruction |= Rm;
c19d1205
ZW
11220 inst.instruction |= inst.operands[3].imm << 4;
11221}
b99bd4ef 11222
c19d1205
ZW
11223static void
11224do_t_sxth (void)
11225{
fdfde340
JM
11226 unsigned Rd, Rm;
11227
11228 Rd = inst.operands[0].reg;
11229 Rm = inst.operands[1].reg;
11230
11231 reject_bad_reg (Rd);
11232 reject_bad_reg (Rm);
c921be7d
NC
11233
11234 if (inst.instruction <= 0xffff
11235 && inst.size_req != 4
fdfde340 11236 && Rd <= 7 && Rm <= 7
c19d1205 11237 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11238 {
c19d1205 11239 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11240 inst.instruction |= Rd;
11241 inst.instruction |= Rm << 3;
b99bd4ef 11242 }
c19d1205 11243 else if (unified_syntax)
b99bd4ef 11244 {
c19d1205
ZW
11245 if (inst.instruction <= 0xffff)
11246 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11247 inst.instruction |= Rd << 8;
11248 inst.instruction |= Rm;
c19d1205 11249 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11250 }
c19d1205 11251 else
b99bd4ef 11252 {
c19d1205
ZW
11253 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11254 _("Thumb encoding does not support rotation"));
11255 constraint (1, BAD_HIREG);
b99bd4ef 11256 }
c19d1205 11257}
b99bd4ef 11258
c19d1205
ZW
11259static void
11260do_t_swi (void)
11261{
11262 inst.reloc.type = BFD_RELOC_ARM_SWI;
11263}
b99bd4ef 11264
92e90b6e
PB
11265static void
11266do_t_tb (void)
11267{
fdfde340 11268 unsigned Rn, Rm;
92e90b6e
PB
11269 int half;
11270
11271 half = (inst.instruction & 0x10) != 0;
e07e6e58 11272 set_it_insn_type_last ();
dfa9f0d5
PB
11273 constraint (inst.operands[0].immisreg,
11274 _("instruction requires register index"));
fdfde340
JM
11275
11276 Rn = inst.operands[0].reg;
11277 Rm = inst.operands[0].imm;
c921be7d 11278
fdfde340
JM
11279 constraint (Rn == REG_SP, BAD_SP);
11280 reject_bad_reg (Rm);
11281
92e90b6e
PB
11282 constraint (!half && inst.operands[0].shifted,
11283 _("instruction does not allow shifted index"));
fdfde340 11284 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11285}
11286
c19d1205
ZW
11287static void
11288do_t_usat (void)
11289{
3a21c15a 11290 do_t_ssat_usat (0);
b99bd4ef
NC
11291}
11292
11293static void
c19d1205 11294do_t_usat16 (void)
b99bd4ef 11295{
fdfde340
JM
11296 unsigned Rd, Rn;
11297
11298 Rd = inst.operands[0].reg;
11299 Rn = inst.operands[2].reg;
11300
11301 reject_bad_reg (Rd);
11302 reject_bad_reg (Rn);
11303
11304 inst.instruction |= Rd << 8;
c19d1205 11305 inst.instruction |= inst.operands[1].imm;
fdfde340 11306 inst.instruction |= Rn << 16;
b99bd4ef 11307}
c19d1205 11308
5287ad62 11309/* Neon instruction encoder helpers. */
5f4273c7 11310
5287ad62 11311/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11312
5287ad62
JB
11313/* An "invalid" code for the following tables. */
11314#define N_INV -1u
11315
11316struct neon_tab_entry
b99bd4ef 11317{
5287ad62
JB
11318 unsigned integer;
11319 unsigned float_or_poly;
11320 unsigned scalar_or_imm;
11321};
5f4273c7 11322
5287ad62
JB
11323/* Map overloaded Neon opcodes to their respective encodings. */
11324#define NEON_ENC_TAB \
11325 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11326 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11327 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11328 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11329 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11330 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11331 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11332 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11333 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11334 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11335 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11336 /* Register variants of the following two instructions are encoded as
e07e6e58 11337 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11338 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11339 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11340 X(vfma, N_INV, 0x0000c10, N_INV), \
11341 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11342 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11343 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11344 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11345 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11346 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11347 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11348 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11349 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11350 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11351 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11352 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11353 X(vshl, 0x0000400, N_INV, 0x0800510), \
11354 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11355 X(vand, 0x0000110, N_INV, 0x0800030), \
11356 X(vbic, 0x0100110, N_INV, 0x0800030), \
11357 X(veor, 0x1000110, N_INV, N_INV), \
11358 X(vorn, 0x0300110, N_INV, 0x0800010), \
11359 X(vorr, 0x0200110, N_INV, 0x0800010), \
11360 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11361 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11362 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11363 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11364 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11365 X(vst1, 0x0000000, 0x0800000, N_INV), \
11366 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11367 X(vst2, 0x0000100, 0x0800100, N_INV), \
11368 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11369 X(vst3, 0x0000200, 0x0800200, N_INV), \
11370 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11371 X(vst4, 0x0000300, 0x0800300, N_INV), \
11372 X(vmovn, 0x1b20200, N_INV, N_INV), \
11373 X(vtrn, 0x1b20080, N_INV, N_INV), \
11374 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11375 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11376 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11377 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11378 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11379 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11380 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11381 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11382 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11383 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11384 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11385
11386enum neon_opc
11387{
11388#define X(OPC,I,F,S) N_MNEM_##OPC
11389NEON_ENC_TAB
11390#undef X
11391};
b99bd4ef 11392
5287ad62
JB
11393static const struct neon_tab_entry neon_enc_tab[] =
11394{
11395#define X(OPC,I,F,S) { (I), (F), (S) }
11396NEON_ENC_TAB
11397#undef X
11398};
b99bd4ef 11399
88714cb8
DG
11400/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11401#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11402#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11403#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11404#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11405#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11406#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11407#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11408#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11409#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11410#define NEON_ENC_SINGLE_(X) \
037e8744 11411 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11412#define NEON_ENC_DOUBLE_(X) \
037e8744 11413 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11414
88714cb8
DG
11415#define NEON_ENCODE(type, inst) \
11416 do \
11417 { \
11418 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11419 inst.is_neon = 1; \
11420 } \
11421 while (0)
11422
11423#define check_neon_suffixes \
11424 do \
11425 { \
11426 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11427 { \
11428 as_bad (_("invalid neon suffix for non neon instruction")); \
11429 return; \
11430 } \
11431 } \
11432 while (0)
11433
037e8744
JB
11434/* Define shapes for instruction operands. The following mnemonic characters
11435 are used in this table:
5287ad62 11436
037e8744 11437 F - VFP S<n> register
5287ad62
JB
11438 D - Neon D<n> register
11439 Q - Neon Q<n> register
11440 I - Immediate
11441 S - Scalar
11442 R - ARM register
11443 L - D<n> register list
5f4273c7 11444
037e8744
JB
11445 This table is used to generate various data:
11446 - enumerations of the form NS_DDR to be used as arguments to
11447 neon_select_shape.
11448 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11449 - a table used to drive neon_select_shape. */
b99bd4ef 11450
037e8744
JB
11451#define NEON_SHAPE_DEF \
11452 X(3, (D, D, D), DOUBLE), \
11453 X(3, (Q, Q, Q), QUAD), \
11454 X(3, (D, D, I), DOUBLE), \
11455 X(3, (Q, Q, I), QUAD), \
11456 X(3, (D, D, S), DOUBLE), \
11457 X(3, (Q, Q, S), QUAD), \
11458 X(2, (D, D), DOUBLE), \
11459 X(2, (Q, Q), QUAD), \
11460 X(2, (D, S), DOUBLE), \
11461 X(2, (Q, S), QUAD), \
11462 X(2, (D, R), DOUBLE), \
11463 X(2, (Q, R), QUAD), \
11464 X(2, (D, I), DOUBLE), \
11465 X(2, (Q, I), QUAD), \
11466 X(3, (D, L, D), DOUBLE), \
11467 X(2, (D, Q), MIXED), \
11468 X(2, (Q, D), MIXED), \
11469 X(3, (D, Q, I), MIXED), \
11470 X(3, (Q, D, I), MIXED), \
11471 X(3, (Q, D, D), MIXED), \
11472 X(3, (D, Q, Q), MIXED), \
11473 X(3, (Q, Q, D), MIXED), \
11474 X(3, (Q, D, S), MIXED), \
11475 X(3, (D, Q, S), MIXED), \
11476 X(4, (D, D, D, I), DOUBLE), \
11477 X(4, (Q, Q, Q, I), QUAD), \
11478 X(2, (F, F), SINGLE), \
11479 X(3, (F, F, F), SINGLE), \
11480 X(2, (F, I), SINGLE), \
11481 X(2, (F, D), MIXED), \
11482 X(2, (D, F), MIXED), \
11483 X(3, (F, F, I), MIXED), \
11484 X(4, (R, R, F, F), SINGLE), \
11485 X(4, (F, F, R, R), SINGLE), \
11486 X(3, (D, R, R), DOUBLE), \
11487 X(3, (R, R, D), DOUBLE), \
11488 X(2, (S, R), SINGLE), \
11489 X(2, (R, S), SINGLE), \
11490 X(2, (F, R), SINGLE), \
11491 X(2, (R, F), SINGLE)
11492
11493#define S2(A,B) NS_##A##B
11494#define S3(A,B,C) NS_##A##B##C
11495#define S4(A,B,C,D) NS_##A##B##C##D
11496
11497#define X(N, L, C) S##N L
11498
5287ad62
JB
11499enum neon_shape
11500{
037e8744
JB
11501 NEON_SHAPE_DEF,
11502 NS_NULL
5287ad62 11503};
b99bd4ef 11504
037e8744
JB
11505#undef X
11506#undef S2
11507#undef S3
11508#undef S4
11509
11510enum neon_shape_class
11511{
11512 SC_SINGLE,
11513 SC_DOUBLE,
11514 SC_QUAD,
11515 SC_MIXED
11516};
11517
11518#define X(N, L, C) SC_##C
11519
11520static enum neon_shape_class neon_shape_class[] =
11521{
11522 NEON_SHAPE_DEF
11523};
11524
11525#undef X
11526
11527enum neon_shape_el
11528{
11529 SE_F,
11530 SE_D,
11531 SE_Q,
11532 SE_I,
11533 SE_S,
11534 SE_R,
11535 SE_L
11536};
11537
11538/* Register widths of above. */
11539static unsigned neon_shape_el_size[] =
11540{
11541 32,
11542 64,
11543 128,
11544 0,
11545 32,
11546 32,
11547 0
11548};
11549
11550struct neon_shape_info
11551{
11552 unsigned els;
11553 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11554};
11555
11556#define S2(A,B) { SE_##A, SE_##B }
11557#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11558#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11559
11560#define X(N, L, C) { N, S##N L }
11561
11562static struct neon_shape_info neon_shape_tab[] =
11563{
11564 NEON_SHAPE_DEF
11565};
11566
11567#undef X
11568#undef S2
11569#undef S3
11570#undef S4
11571
5287ad62
JB
11572/* Bit masks used in type checking given instructions.
11573 'N_EQK' means the type must be the same as (or based on in some way) the key
11574 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11575 set, various other bits can be set as well in order to modify the meaning of
11576 the type constraint. */
11577
11578enum neon_type_mask
11579{
8e79c3df
CM
11580 N_S8 = 0x0000001,
11581 N_S16 = 0x0000002,
11582 N_S32 = 0x0000004,
11583 N_S64 = 0x0000008,
11584 N_U8 = 0x0000010,
11585 N_U16 = 0x0000020,
11586 N_U32 = 0x0000040,
11587 N_U64 = 0x0000080,
11588 N_I8 = 0x0000100,
11589 N_I16 = 0x0000200,
11590 N_I32 = 0x0000400,
11591 N_I64 = 0x0000800,
11592 N_8 = 0x0001000,
11593 N_16 = 0x0002000,
11594 N_32 = 0x0004000,
11595 N_64 = 0x0008000,
11596 N_P8 = 0x0010000,
11597 N_P16 = 0x0020000,
11598 N_F16 = 0x0040000,
11599 N_F32 = 0x0080000,
11600 N_F64 = 0x0100000,
c921be7d
NC
11601 N_KEY = 0x1000000, /* Key element (main type specifier). */
11602 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11603 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11604 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11605 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11606 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11607 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11608 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11609 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11610 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11611 N_UTYP = 0,
037e8744 11612 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11613};
11614
dcbf9037
JB
11615#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11616
5287ad62
JB
11617#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11618#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11619#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11620#define N_SUF_32 (N_SU_32 | N_F32)
11621#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11622#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11623
11624/* Pass this as the first type argument to neon_check_type to ignore types
11625 altogether. */
11626#define N_IGNORE_TYPE (N_KEY | N_EQK)
11627
037e8744
JB
11628/* Select a "shape" for the current instruction (describing register types or
11629 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11630 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11631 function of operand parsing, so this function doesn't need to be called.
11632 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11633
11634static enum neon_shape
037e8744 11635neon_select_shape (enum neon_shape shape, ...)
5287ad62 11636{
037e8744
JB
11637 va_list ap;
11638 enum neon_shape first_shape = shape;
5287ad62
JB
11639
11640 /* Fix missing optional operands. FIXME: we don't know at this point how
11641 many arguments we should have, so this makes the assumption that we have
11642 > 1. This is true of all current Neon opcodes, I think, but may not be
11643 true in the future. */
11644 if (!inst.operands[1].present)
11645 inst.operands[1] = inst.operands[0];
11646
037e8744 11647 va_start (ap, shape);
5f4273c7 11648
21d799b5 11649 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11650 {
11651 unsigned j;
11652 int matches = 1;
11653
11654 for (j = 0; j < neon_shape_tab[shape].els; j++)
11655 {
11656 if (!inst.operands[j].present)
11657 {
11658 matches = 0;
11659 break;
11660 }
11661
11662 switch (neon_shape_tab[shape].el[j])
11663 {
11664 case SE_F:
11665 if (!(inst.operands[j].isreg
11666 && inst.operands[j].isvec
11667 && inst.operands[j].issingle
11668 && !inst.operands[j].isquad))
11669 matches = 0;
11670 break;
11671
11672 case SE_D:
11673 if (!(inst.operands[j].isreg
11674 && inst.operands[j].isvec
11675 && !inst.operands[j].isquad
11676 && !inst.operands[j].issingle))
11677 matches = 0;
11678 break;
11679
11680 case SE_R:
11681 if (!(inst.operands[j].isreg
11682 && !inst.operands[j].isvec))
11683 matches = 0;
11684 break;
11685
11686 case SE_Q:
11687 if (!(inst.operands[j].isreg
11688 && inst.operands[j].isvec
11689 && inst.operands[j].isquad
11690 && !inst.operands[j].issingle))
11691 matches = 0;
11692 break;
11693
11694 case SE_I:
11695 if (!(!inst.operands[j].isreg
11696 && !inst.operands[j].isscalar))
11697 matches = 0;
11698 break;
11699
11700 case SE_S:
11701 if (!(!inst.operands[j].isreg
11702 && inst.operands[j].isscalar))
11703 matches = 0;
11704 break;
11705
11706 case SE_L:
11707 break;
11708 }
11709 }
11710 if (matches)
5287ad62 11711 break;
037e8744 11712 }
5f4273c7 11713
037e8744 11714 va_end (ap);
5287ad62 11715
037e8744
JB
11716 if (shape == NS_NULL && first_shape != NS_NULL)
11717 first_error (_("invalid instruction shape"));
5287ad62 11718
037e8744
JB
11719 return shape;
11720}
5287ad62 11721
037e8744
JB
11722/* True if SHAPE is predominantly a quadword operation (most of the time, this
11723 means the Q bit should be set). */
11724
11725static int
11726neon_quad (enum neon_shape shape)
11727{
11728 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11729}
037e8744 11730
5287ad62
JB
11731static void
11732neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11733 unsigned *g_size)
11734{
11735 /* Allow modification to be made to types which are constrained to be
11736 based on the key element, based on bits set alongside N_EQK. */
11737 if ((typebits & N_EQK) != 0)
11738 {
11739 if ((typebits & N_HLF) != 0)
11740 *g_size /= 2;
11741 else if ((typebits & N_DBL) != 0)
11742 *g_size *= 2;
11743 if ((typebits & N_SGN) != 0)
11744 *g_type = NT_signed;
11745 else if ((typebits & N_UNS) != 0)
11746 *g_type = NT_unsigned;
11747 else if ((typebits & N_INT) != 0)
11748 *g_type = NT_integer;
11749 else if ((typebits & N_FLT) != 0)
11750 *g_type = NT_float;
dcbf9037
JB
11751 else if ((typebits & N_SIZ) != 0)
11752 *g_type = NT_untyped;
5287ad62
JB
11753 }
11754}
5f4273c7 11755
5287ad62
JB
11756/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11757 operand type, i.e. the single type specified in a Neon instruction when it
11758 is the only one given. */
11759
11760static struct neon_type_el
11761neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11762{
11763 struct neon_type_el dest = *key;
5f4273c7 11764
9c2799c2 11765 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11766
5287ad62
JB
11767 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11768
11769 return dest;
11770}
11771
11772/* Convert Neon type and size into compact bitmask representation. */
11773
11774static enum neon_type_mask
11775type_chk_of_el_type (enum neon_el_type type, unsigned size)
11776{
11777 switch (type)
11778 {
11779 case NT_untyped:
11780 switch (size)
11781 {
11782 case 8: return N_8;
11783 case 16: return N_16;
11784 case 32: return N_32;
11785 case 64: return N_64;
11786 default: ;
11787 }
11788 break;
11789
11790 case NT_integer:
11791 switch (size)
11792 {
11793 case 8: return N_I8;
11794 case 16: return N_I16;
11795 case 32: return N_I32;
11796 case 64: return N_I64;
11797 default: ;
11798 }
11799 break;
11800
11801 case NT_float:
037e8744
JB
11802 switch (size)
11803 {
8e79c3df 11804 case 16: return N_F16;
037e8744
JB
11805 case 32: return N_F32;
11806 case 64: return N_F64;
11807 default: ;
11808 }
5287ad62
JB
11809 break;
11810
11811 case NT_poly:
11812 switch (size)
11813 {
11814 case 8: return N_P8;
11815 case 16: return N_P16;
11816 default: ;
11817 }
11818 break;
11819
11820 case NT_signed:
11821 switch (size)
11822 {
11823 case 8: return N_S8;
11824 case 16: return N_S16;
11825 case 32: return N_S32;
11826 case 64: return N_S64;
11827 default: ;
11828 }
11829 break;
11830
11831 case NT_unsigned:
11832 switch (size)
11833 {
11834 case 8: return N_U8;
11835 case 16: return N_U16;
11836 case 32: return N_U32;
11837 case 64: return N_U64;
11838 default: ;
11839 }
11840 break;
11841
11842 default: ;
11843 }
5f4273c7 11844
5287ad62
JB
11845 return N_UTYP;
11846}
11847
11848/* Convert compact Neon bitmask type representation to a type and size. Only
11849 handles the case where a single bit is set in the mask. */
11850
dcbf9037 11851static int
5287ad62
JB
11852el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11853 enum neon_type_mask mask)
11854{
dcbf9037
JB
11855 if ((mask & N_EQK) != 0)
11856 return FAIL;
11857
5287ad62
JB
11858 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11859 *size = 8;
dcbf9037 11860 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11861 *size = 16;
dcbf9037 11862 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11863 *size = 32;
037e8744 11864 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11865 *size = 64;
dcbf9037
JB
11866 else
11867 return FAIL;
11868
5287ad62
JB
11869 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11870 *type = NT_signed;
dcbf9037 11871 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11872 *type = NT_unsigned;
dcbf9037 11873 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11874 *type = NT_integer;
dcbf9037 11875 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11876 *type = NT_untyped;
dcbf9037 11877 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11878 *type = NT_poly;
037e8744 11879 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11880 *type = NT_float;
dcbf9037
JB
11881 else
11882 return FAIL;
5f4273c7 11883
dcbf9037 11884 return SUCCESS;
5287ad62
JB
11885}
11886
11887/* Modify a bitmask of allowed types. This is only needed for type
11888 relaxation. */
11889
11890static unsigned
11891modify_types_allowed (unsigned allowed, unsigned mods)
11892{
11893 unsigned size;
11894 enum neon_el_type type;
11895 unsigned destmask;
11896 int i;
5f4273c7 11897
5287ad62 11898 destmask = 0;
5f4273c7 11899
5287ad62
JB
11900 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11901 {
21d799b5
NC
11902 if (el_type_of_type_chk (&type, &size,
11903 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
11904 {
11905 neon_modify_type_size (mods, &type, &size);
11906 destmask |= type_chk_of_el_type (type, size);
11907 }
5287ad62 11908 }
5f4273c7 11909
5287ad62
JB
11910 return destmask;
11911}
11912
11913/* Check type and return type classification.
11914 The manual states (paraphrase): If one datatype is given, it indicates the
11915 type given in:
11916 - the second operand, if there is one
11917 - the operand, if there is no second operand
11918 - the result, if there are no operands.
11919 This isn't quite good enough though, so we use a concept of a "key" datatype
11920 which is set on a per-instruction basis, which is the one which matters when
11921 only one data type is written.
11922 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11923 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11924
11925static struct neon_type_el
11926neon_check_type (unsigned els, enum neon_shape ns, ...)
11927{
11928 va_list ap;
11929 unsigned i, pass, key_el = 0;
11930 unsigned types[NEON_MAX_TYPE_ELS];
11931 enum neon_el_type k_type = NT_invtype;
11932 unsigned k_size = -1u;
11933 struct neon_type_el badtype = {NT_invtype, -1};
11934 unsigned key_allowed = 0;
11935
11936 /* Optional registers in Neon instructions are always (not) in operand 1.
11937 Fill in the missing operand here, if it was omitted. */
11938 if (els > 1 && !inst.operands[1].present)
11939 inst.operands[1] = inst.operands[0];
11940
11941 /* Suck up all the varargs. */
11942 va_start (ap, ns);
11943 for (i = 0; i < els; i++)
11944 {
11945 unsigned thisarg = va_arg (ap, unsigned);
11946 if (thisarg == N_IGNORE_TYPE)
11947 {
11948 va_end (ap);
11949 return badtype;
11950 }
11951 types[i] = thisarg;
11952 if ((thisarg & N_KEY) != 0)
11953 key_el = i;
11954 }
11955 va_end (ap);
11956
dcbf9037
JB
11957 if (inst.vectype.elems > 0)
11958 for (i = 0; i < els; i++)
11959 if (inst.operands[i].vectype.type != NT_invtype)
11960 {
11961 first_error (_("types specified in both the mnemonic and operands"));
11962 return badtype;
11963 }
11964
5287ad62
JB
11965 /* Duplicate inst.vectype elements here as necessary.
11966 FIXME: No idea if this is exactly the same as the ARM assembler,
11967 particularly when an insn takes one register and one non-register
11968 operand. */
11969 if (inst.vectype.elems == 1 && els > 1)
11970 {
11971 unsigned j;
11972 inst.vectype.elems = els;
11973 inst.vectype.el[key_el] = inst.vectype.el[0];
11974 for (j = 0; j < els; j++)
dcbf9037
JB
11975 if (j != key_el)
11976 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11977 types[j]);
11978 }
11979 else if (inst.vectype.elems == 0 && els > 0)
11980 {
11981 unsigned j;
11982 /* No types were given after the mnemonic, so look for types specified
11983 after each operand. We allow some flexibility here; as long as the
11984 "key" operand has a type, we can infer the others. */
11985 for (j = 0; j < els; j++)
11986 if (inst.operands[j].vectype.type != NT_invtype)
11987 inst.vectype.el[j] = inst.operands[j].vectype;
11988
11989 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11990 {
dcbf9037
JB
11991 for (j = 0; j < els; j++)
11992 if (inst.operands[j].vectype.type == NT_invtype)
11993 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11994 types[j]);
11995 }
11996 else
11997 {
11998 first_error (_("operand types can't be inferred"));
11999 return badtype;
5287ad62
JB
12000 }
12001 }
12002 else if (inst.vectype.elems != els)
12003 {
dcbf9037 12004 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12005 return badtype;
12006 }
12007
12008 for (pass = 0; pass < 2; pass++)
12009 {
12010 for (i = 0; i < els; i++)
12011 {
12012 unsigned thisarg = types[i];
12013 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12014 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12015 enum neon_el_type g_type = inst.vectype.el[i].type;
12016 unsigned g_size = inst.vectype.el[i].size;
12017
12018 /* Decay more-specific signed & unsigned types to sign-insensitive
12019 integer types if sign-specific variants are unavailable. */
12020 if ((g_type == NT_signed || g_type == NT_unsigned)
12021 && (types_allowed & N_SU_ALL) == 0)
12022 g_type = NT_integer;
12023
12024 /* If only untyped args are allowed, decay any more specific types to
12025 them. Some instructions only care about signs for some element
12026 sizes, so handle that properly. */
12027 if ((g_size == 8 && (types_allowed & N_8) != 0)
12028 || (g_size == 16 && (types_allowed & N_16) != 0)
12029 || (g_size == 32 && (types_allowed & N_32) != 0)
12030 || (g_size == 64 && (types_allowed & N_64) != 0))
12031 g_type = NT_untyped;
12032
12033 if (pass == 0)
12034 {
12035 if ((thisarg & N_KEY) != 0)
12036 {
12037 k_type = g_type;
12038 k_size = g_size;
12039 key_allowed = thisarg & ~N_KEY;
12040 }
12041 }
12042 else
12043 {
037e8744
JB
12044 if ((thisarg & N_VFP) != 0)
12045 {
12046 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
12047 unsigned regwidth = neon_shape_el_size[regshape], match;
12048
12049 /* In VFP mode, operands must match register widths. If we
12050 have a key operand, use its width, else use the width of
12051 the current operand. */
12052 if (k_size != -1u)
12053 match = k_size;
12054 else
12055 match = g_size;
12056
12057 if (regwidth != match)
12058 {
12059 first_error (_("operand size must match register width"));
12060 return badtype;
12061 }
12062 }
5f4273c7 12063
5287ad62
JB
12064 if ((thisarg & N_EQK) == 0)
12065 {
12066 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12067
12068 if ((given_type & types_allowed) == 0)
12069 {
dcbf9037 12070 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12071 return badtype;
12072 }
12073 }
12074 else
12075 {
12076 enum neon_el_type mod_k_type = k_type;
12077 unsigned mod_k_size = k_size;
12078 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12079 if (g_type != mod_k_type || g_size != mod_k_size)
12080 {
dcbf9037 12081 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12082 return badtype;
12083 }
12084 }
12085 }
12086 }
12087 }
12088
12089 return inst.vectype.el[key_el];
12090}
12091
037e8744 12092/* Neon-style VFP instruction forwarding. */
5287ad62 12093
037e8744
JB
12094/* Thumb VFP instructions have 0xE in the condition field. */
12095
12096static void
12097do_vfp_cond_or_thumb (void)
5287ad62 12098{
88714cb8
DG
12099 inst.is_neon = 1;
12100
5287ad62 12101 if (thumb_mode)
037e8744 12102 inst.instruction |= 0xe0000000;
5287ad62 12103 else
037e8744 12104 inst.instruction |= inst.cond << 28;
5287ad62
JB
12105}
12106
037e8744
JB
12107/* Look up and encode a simple mnemonic, for use as a helper function for the
12108 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12109 etc. It is assumed that operand parsing has already been done, and that the
12110 operands are in the form expected by the given opcode (this isn't necessarily
12111 the same as the form in which they were parsed, hence some massaging must
12112 take place before this function is called).
12113 Checks current arch version against that in the looked-up opcode. */
5287ad62 12114
037e8744
JB
12115static void
12116do_vfp_nsyn_opcode (const char *opname)
5287ad62 12117{
037e8744 12118 const struct asm_opcode *opcode;
5f4273c7 12119
21d799b5 12120 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12121
037e8744
JB
12122 if (!opcode)
12123 abort ();
5287ad62 12124
037e8744
JB
12125 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12126 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12127 _(BAD_FPU));
5287ad62 12128
88714cb8
DG
12129 inst.is_neon = 1;
12130
037e8744
JB
12131 if (thumb_mode)
12132 {
12133 inst.instruction = opcode->tvalue;
12134 opcode->tencode ();
12135 }
12136 else
12137 {
12138 inst.instruction = (inst.cond << 28) | opcode->avalue;
12139 opcode->aencode ();
12140 }
12141}
5287ad62
JB
12142
12143static void
037e8744 12144do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12145{
037e8744
JB
12146 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12147
12148 if (rs == NS_FFF)
12149 {
12150 if (is_add)
12151 do_vfp_nsyn_opcode ("fadds");
12152 else
12153 do_vfp_nsyn_opcode ("fsubs");
12154 }
12155 else
12156 {
12157 if (is_add)
12158 do_vfp_nsyn_opcode ("faddd");
12159 else
12160 do_vfp_nsyn_opcode ("fsubd");
12161 }
12162}
12163
12164/* Check operand types to see if this is a VFP instruction, and if so call
12165 PFN (). */
12166
12167static int
12168try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12169{
12170 enum neon_shape rs;
12171 struct neon_type_el et;
12172
12173 switch (args)
12174 {
12175 case 2:
12176 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12177 et = neon_check_type (2, rs,
12178 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12179 break;
5f4273c7 12180
037e8744
JB
12181 case 3:
12182 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12183 et = neon_check_type (3, rs,
12184 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12185 break;
12186
12187 default:
12188 abort ();
12189 }
12190
12191 if (et.type != NT_invtype)
12192 {
12193 pfn (rs);
12194 return SUCCESS;
12195 }
12196 else
12197 inst.error = NULL;
12198
12199 return FAIL;
12200}
12201
12202static void
12203do_vfp_nsyn_mla_mls (enum neon_shape rs)
12204{
12205 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12206
037e8744
JB
12207 if (rs == NS_FFF)
12208 {
12209 if (is_mla)
12210 do_vfp_nsyn_opcode ("fmacs");
12211 else
1ee69515 12212 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12213 }
12214 else
12215 {
12216 if (is_mla)
12217 do_vfp_nsyn_opcode ("fmacd");
12218 else
1ee69515 12219 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12220 }
12221}
12222
62f3b8c8
PB
12223static void
12224do_vfp_nsyn_fma_fms (enum neon_shape rs)
12225{
12226 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12227
12228 if (rs == NS_FFF)
12229 {
12230 if (is_fma)
12231 do_vfp_nsyn_opcode ("ffmas");
12232 else
12233 do_vfp_nsyn_opcode ("ffnmas");
12234 }
12235 else
12236 {
12237 if (is_fma)
12238 do_vfp_nsyn_opcode ("ffmad");
12239 else
12240 do_vfp_nsyn_opcode ("ffnmad");
12241 }
12242}
12243
037e8744
JB
12244static void
12245do_vfp_nsyn_mul (enum neon_shape rs)
12246{
12247 if (rs == NS_FFF)
12248 do_vfp_nsyn_opcode ("fmuls");
12249 else
12250 do_vfp_nsyn_opcode ("fmuld");
12251}
12252
12253static void
12254do_vfp_nsyn_abs_neg (enum neon_shape rs)
12255{
12256 int is_neg = (inst.instruction & 0x80) != 0;
12257 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12258
12259 if (rs == NS_FF)
12260 {
12261 if (is_neg)
12262 do_vfp_nsyn_opcode ("fnegs");
12263 else
12264 do_vfp_nsyn_opcode ("fabss");
12265 }
12266 else
12267 {
12268 if (is_neg)
12269 do_vfp_nsyn_opcode ("fnegd");
12270 else
12271 do_vfp_nsyn_opcode ("fabsd");
12272 }
12273}
12274
12275/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12276 insns belong to Neon, and are handled elsewhere. */
12277
12278static void
12279do_vfp_nsyn_ldm_stm (int is_dbmode)
12280{
12281 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12282 if (is_ldm)
12283 {
12284 if (is_dbmode)
12285 do_vfp_nsyn_opcode ("fldmdbs");
12286 else
12287 do_vfp_nsyn_opcode ("fldmias");
12288 }
12289 else
12290 {
12291 if (is_dbmode)
12292 do_vfp_nsyn_opcode ("fstmdbs");
12293 else
12294 do_vfp_nsyn_opcode ("fstmias");
12295 }
12296}
12297
037e8744
JB
12298static void
12299do_vfp_nsyn_sqrt (void)
12300{
12301 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12302 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12303
037e8744
JB
12304 if (rs == NS_FF)
12305 do_vfp_nsyn_opcode ("fsqrts");
12306 else
12307 do_vfp_nsyn_opcode ("fsqrtd");
12308}
12309
12310static void
12311do_vfp_nsyn_div (void)
12312{
12313 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12314 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12315 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12316
037e8744
JB
12317 if (rs == NS_FFF)
12318 do_vfp_nsyn_opcode ("fdivs");
12319 else
12320 do_vfp_nsyn_opcode ("fdivd");
12321}
12322
12323static void
12324do_vfp_nsyn_nmul (void)
12325{
12326 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12327 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12328 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12329
037e8744
JB
12330 if (rs == NS_FFF)
12331 {
88714cb8 12332 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12333 do_vfp_sp_dyadic ();
12334 }
12335 else
12336 {
88714cb8 12337 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12338 do_vfp_dp_rd_rn_rm ();
12339 }
12340 do_vfp_cond_or_thumb ();
12341}
12342
12343static void
12344do_vfp_nsyn_cmp (void)
12345{
12346 if (inst.operands[1].isreg)
12347 {
12348 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12349 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12350
037e8744
JB
12351 if (rs == NS_FF)
12352 {
88714cb8 12353 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12354 do_vfp_sp_monadic ();
12355 }
12356 else
12357 {
88714cb8 12358 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12359 do_vfp_dp_rd_rm ();
12360 }
12361 }
12362 else
12363 {
12364 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12365 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12366
12367 switch (inst.instruction & 0x0fffffff)
12368 {
12369 case N_MNEM_vcmp:
12370 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12371 break;
12372 case N_MNEM_vcmpe:
12373 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12374 break;
12375 default:
12376 abort ();
12377 }
5f4273c7 12378
037e8744
JB
12379 if (rs == NS_FI)
12380 {
88714cb8 12381 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12382 do_vfp_sp_compare_z ();
12383 }
12384 else
12385 {
88714cb8 12386 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12387 do_vfp_dp_rd ();
12388 }
12389 }
12390 do_vfp_cond_or_thumb ();
12391}
12392
12393static void
12394nsyn_insert_sp (void)
12395{
12396 inst.operands[1] = inst.operands[0];
12397 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12398 inst.operands[0].reg = REG_SP;
037e8744
JB
12399 inst.operands[0].isreg = 1;
12400 inst.operands[0].writeback = 1;
12401 inst.operands[0].present = 1;
12402}
12403
12404static void
12405do_vfp_nsyn_push (void)
12406{
12407 nsyn_insert_sp ();
12408 if (inst.operands[1].issingle)
12409 do_vfp_nsyn_opcode ("fstmdbs");
12410 else
12411 do_vfp_nsyn_opcode ("fstmdbd");
12412}
12413
12414static void
12415do_vfp_nsyn_pop (void)
12416{
12417 nsyn_insert_sp ();
12418 if (inst.operands[1].issingle)
22b5b651 12419 do_vfp_nsyn_opcode ("fldmias");
037e8744 12420 else
22b5b651 12421 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12422}
12423
12424/* Fix up Neon data-processing instructions, ORing in the correct bits for
12425 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12426
88714cb8
DG
12427static void
12428neon_dp_fixup (struct arm_it* insn)
037e8744 12429{
88714cb8
DG
12430 unsigned int i = insn->instruction;
12431 insn->is_neon = 1;
12432
037e8744
JB
12433 if (thumb_mode)
12434 {
12435 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12436 if (i & (1 << 24))
12437 i |= 1 << 28;
5f4273c7 12438
037e8744 12439 i &= ~(1 << 24);
5f4273c7 12440
037e8744
JB
12441 i |= 0xef000000;
12442 }
12443 else
12444 i |= 0xf2000000;
5f4273c7 12445
88714cb8 12446 insn->instruction = i;
037e8744
JB
12447}
12448
12449/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12450 (0, 1, 2, 3). */
12451
12452static unsigned
12453neon_logbits (unsigned x)
12454{
12455 return ffs (x) - 4;
12456}
12457
12458#define LOW4(R) ((R) & 0xf)
12459#define HI1(R) (((R) >> 4) & 1)
12460
12461/* Encode insns with bit pattern:
12462
12463 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12464 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12465
037e8744
JB
12466 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12467 different meaning for some instruction. */
12468
12469static void
12470neon_three_same (int isquad, int ubit, int size)
12471{
12472 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12473 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12474 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12475 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12476 inst.instruction |= LOW4 (inst.operands[2].reg);
12477 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12478 inst.instruction |= (isquad != 0) << 6;
12479 inst.instruction |= (ubit != 0) << 24;
12480 if (size != -1)
12481 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12482
88714cb8 12483 neon_dp_fixup (&inst);
037e8744
JB
12484}
12485
12486/* Encode instructions of the form:
12487
12488 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12489 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12490
12491 Don't write size if SIZE == -1. */
12492
12493static void
12494neon_two_same (int qbit, int ubit, int size)
12495{
12496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12498 inst.instruction |= LOW4 (inst.operands[1].reg);
12499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12500 inst.instruction |= (qbit != 0) << 6;
12501 inst.instruction |= (ubit != 0) << 24;
12502
12503 if (size != -1)
12504 inst.instruction |= neon_logbits (size) << 18;
12505
88714cb8 12506 neon_dp_fixup (&inst);
5287ad62
JB
12507}
12508
12509/* Neon instruction encoders, in approximate order of appearance. */
12510
12511static void
12512do_neon_dyadic_i_su (void)
12513{
037e8744 12514 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12515 struct neon_type_el et = neon_check_type (3, rs,
12516 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12517 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12518}
12519
12520static void
12521do_neon_dyadic_i64_su (void)
12522{
037e8744 12523 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12524 struct neon_type_el et = neon_check_type (3, rs,
12525 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12526 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12527}
12528
12529static void
12530neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12531 unsigned immbits)
12532{
12533 unsigned size = et.size >> 3;
12534 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12535 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12536 inst.instruction |= LOW4 (inst.operands[1].reg);
12537 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12538 inst.instruction |= (isquad != 0) << 6;
12539 inst.instruction |= immbits << 16;
12540 inst.instruction |= (size >> 3) << 7;
12541 inst.instruction |= (size & 0x7) << 19;
12542 if (write_ubit)
12543 inst.instruction |= (uval != 0) << 24;
12544
88714cb8 12545 neon_dp_fixup (&inst);
5287ad62
JB
12546}
12547
12548static void
12549do_neon_shl_imm (void)
12550{
12551 if (!inst.operands[2].isreg)
12552 {
037e8744 12553 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12554 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12555 NEON_ENCODE (IMMED, inst);
037e8744 12556 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12557 }
12558 else
12559 {
037e8744 12560 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12561 struct neon_type_el et = neon_check_type (3, rs,
12562 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12563 unsigned int tmp;
12564
12565 /* VSHL/VQSHL 3-register variants have syntax such as:
12566 vshl.xx Dd, Dm, Dn
12567 whereas other 3-register operations encoded by neon_three_same have
12568 syntax like:
12569 vadd.xx Dd, Dn, Dm
12570 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12571 here. */
12572 tmp = inst.operands[2].reg;
12573 inst.operands[2].reg = inst.operands[1].reg;
12574 inst.operands[1].reg = tmp;
88714cb8 12575 NEON_ENCODE (INTEGER, inst);
037e8744 12576 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12577 }
12578}
12579
12580static void
12581do_neon_qshl_imm (void)
12582{
12583 if (!inst.operands[2].isreg)
12584 {
037e8744 12585 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12586 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12587
88714cb8 12588 NEON_ENCODE (IMMED, inst);
037e8744 12589 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12590 inst.operands[2].imm);
12591 }
12592 else
12593 {
037e8744 12594 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12595 struct neon_type_el et = neon_check_type (3, rs,
12596 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12597 unsigned int tmp;
12598
12599 /* See note in do_neon_shl_imm. */
12600 tmp = inst.operands[2].reg;
12601 inst.operands[2].reg = inst.operands[1].reg;
12602 inst.operands[1].reg = tmp;
88714cb8 12603 NEON_ENCODE (INTEGER, inst);
037e8744 12604 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12605 }
12606}
12607
627907b7
JB
12608static void
12609do_neon_rshl (void)
12610{
12611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12612 struct neon_type_el et = neon_check_type (3, rs,
12613 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12614 unsigned int tmp;
12615
12616 tmp = inst.operands[2].reg;
12617 inst.operands[2].reg = inst.operands[1].reg;
12618 inst.operands[1].reg = tmp;
12619 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12620}
12621
5287ad62
JB
12622static int
12623neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12624{
036dc3f7
PB
12625 /* Handle .I8 pseudo-instructions. */
12626 if (size == 8)
5287ad62 12627 {
5287ad62
JB
12628 /* Unfortunately, this will make everything apart from zero out-of-range.
12629 FIXME is this the intended semantics? There doesn't seem much point in
12630 accepting .I8 if so. */
12631 immediate |= immediate << 8;
12632 size = 16;
036dc3f7
PB
12633 }
12634
12635 if (size >= 32)
12636 {
12637 if (immediate == (immediate & 0x000000ff))
12638 {
12639 *immbits = immediate;
12640 return 0x1;
12641 }
12642 else if (immediate == (immediate & 0x0000ff00))
12643 {
12644 *immbits = immediate >> 8;
12645 return 0x3;
12646 }
12647 else if (immediate == (immediate & 0x00ff0000))
12648 {
12649 *immbits = immediate >> 16;
12650 return 0x5;
12651 }
12652 else if (immediate == (immediate & 0xff000000))
12653 {
12654 *immbits = immediate >> 24;
12655 return 0x7;
12656 }
12657 if ((immediate & 0xffff) != (immediate >> 16))
12658 goto bad_immediate;
12659 immediate &= 0xffff;
5287ad62
JB
12660 }
12661
12662 if (immediate == (immediate & 0x000000ff))
12663 {
12664 *immbits = immediate;
036dc3f7 12665 return 0x9;
5287ad62
JB
12666 }
12667 else if (immediate == (immediate & 0x0000ff00))
12668 {
12669 *immbits = immediate >> 8;
036dc3f7 12670 return 0xb;
5287ad62
JB
12671 }
12672
12673 bad_immediate:
dcbf9037 12674 first_error (_("immediate value out of range"));
5287ad62
JB
12675 return FAIL;
12676}
12677
12678/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12679 A, B, C, D. */
12680
12681static int
12682neon_bits_same_in_bytes (unsigned imm)
12683{
12684 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12685 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12686 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12687 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12688}
12689
12690/* For immediate of above form, return 0bABCD. */
12691
12692static unsigned
12693neon_squash_bits (unsigned imm)
12694{
12695 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12696 | ((imm & 0x01000000) >> 21);
12697}
12698
136da414 12699/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12700
12701static unsigned
12702neon_qfloat_bits (unsigned imm)
12703{
136da414 12704 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12705}
12706
12707/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12708 the instruction. *OP is passed as the initial value of the op field, and
12709 may be set to a different value depending on the constant (i.e.
12710 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12711 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12712 try smaller element sizes. */
5287ad62
JB
12713
12714static int
c96612cc
JB
12715neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12716 unsigned *immbits, int *op, int size,
12717 enum neon_el_type type)
5287ad62 12718{
c96612cc
JB
12719 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12720 float. */
12721 if (type == NT_float && !float_p)
12722 return FAIL;
12723
136da414
JB
12724 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12725 {
12726 if (size != 32 || *op == 1)
12727 return FAIL;
12728 *immbits = neon_qfloat_bits (immlo);
12729 return 0xf;
12730 }
036dc3f7
PB
12731
12732 if (size == 64)
5287ad62 12733 {
036dc3f7
PB
12734 if (neon_bits_same_in_bytes (immhi)
12735 && neon_bits_same_in_bytes (immlo))
12736 {
12737 if (*op == 1)
12738 return FAIL;
12739 *immbits = (neon_squash_bits (immhi) << 4)
12740 | neon_squash_bits (immlo);
12741 *op = 1;
12742 return 0xe;
12743 }
12744
12745 if (immhi != immlo)
12746 return FAIL;
5287ad62 12747 }
036dc3f7
PB
12748
12749 if (size >= 32)
5287ad62 12750 {
036dc3f7
PB
12751 if (immlo == (immlo & 0x000000ff))
12752 {
12753 *immbits = immlo;
12754 return 0x0;
12755 }
12756 else if (immlo == (immlo & 0x0000ff00))
12757 {
12758 *immbits = immlo >> 8;
12759 return 0x2;
12760 }
12761 else if (immlo == (immlo & 0x00ff0000))
12762 {
12763 *immbits = immlo >> 16;
12764 return 0x4;
12765 }
12766 else if (immlo == (immlo & 0xff000000))
12767 {
12768 *immbits = immlo >> 24;
12769 return 0x6;
12770 }
12771 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12772 {
12773 *immbits = (immlo >> 8) & 0xff;
12774 return 0xc;
12775 }
12776 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12777 {
12778 *immbits = (immlo >> 16) & 0xff;
12779 return 0xd;
12780 }
12781
12782 if ((immlo & 0xffff) != (immlo >> 16))
12783 return FAIL;
12784 immlo &= 0xffff;
5287ad62 12785 }
036dc3f7
PB
12786
12787 if (size >= 16)
5287ad62 12788 {
036dc3f7
PB
12789 if (immlo == (immlo & 0x000000ff))
12790 {
12791 *immbits = immlo;
12792 return 0x8;
12793 }
12794 else if (immlo == (immlo & 0x0000ff00))
12795 {
12796 *immbits = immlo >> 8;
12797 return 0xa;
12798 }
12799
12800 if ((immlo & 0xff) != (immlo >> 8))
12801 return FAIL;
12802 immlo &= 0xff;
5287ad62 12803 }
036dc3f7
PB
12804
12805 if (immlo == (immlo & 0x000000ff))
5287ad62 12806 {
036dc3f7
PB
12807 /* Don't allow MVN with 8-bit immediate. */
12808 if (*op == 1)
12809 return FAIL;
12810 *immbits = immlo;
12811 return 0xe;
5287ad62 12812 }
5287ad62
JB
12813
12814 return FAIL;
12815}
12816
12817/* Write immediate bits [7:0] to the following locations:
12818
12819 |28/24|23 19|18 16|15 4|3 0|
12820 | 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|
12821
12822 This function is used by VMOV/VMVN/VORR/VBIC. */
12823
12824static void
12825neon_write_immbits (unsigned immbits)
12826{
12827 inst.instruction |= immbits & 0xf;
12828 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12829 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12830}
12831
12832/* Invert low-order SIZE bits of XHI:XLO. */
12833
12834static void
12835neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12836{
12837 unsigned immlo = xlo ? *xlo : 0;
12838 unsigned immhi = xhi ? *xhi : 0;
12839
12840 switch (size)
12841 {
12842 case 8:
12843 immlo = (~immlo) & 0xff;
12844 break;
12845
12846 case 16:
12847 immlo = (~immlo) & 0xffff;
12848 break;
12849
12850 case 64:
12851 immhi = (~immhi) & 0xffffffff;
12852 /* fall through. */
12853
12854 case 32:
12855 immlo = (~immlo) & 0xffffffff;
12856 break;
12857
12858 default:
12859 abort ();
12860 }
12861
12862 if (xlo)
12863 *xlo = immlo;
12864
12865 if (xhi)
12866 *xhi = immhi;
12867}
12868
12869static void
12870do_neon_logic (void)
12871{
12872 if (inst.operands[2].present && inst.operands[2].isreg)
12873 {
037e8744 12874 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12875 neon_check_type (3, rs, N_IGNORE_TYPE);
12876 /* U bit and size field were set as part of the bitmask. */
88714cb8 12877 NEON_ENCODE (INTEGER, inst);
037e8744 12878 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12879 }
12880 else
12881 {
4316f0d2
DG
12882 const int three_ops_form = (inst.operands[2].present
12883 && !inst.operands[2].isreg);
12884 const int immoperand = (three_ops_form ? 2 : 1);
12885 enum neon_shape rs = (three_ops_form
12886 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
12887 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
12888 struct neon_type_el et = neon_check_type (2, rs,
12889 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 12890 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
12891 unsigned immbits;
12892 int cmode;
5f4273c7 12893
5287ad62
JB
12894 if (et.type == NT_invtype)
12895 return;
5f4273c7 12896
4316f0d2
DG
12897 if (three_ops_form)
12898 constraint (inst.operands[0].reg != inst.operands[1].reg,
12899 _("first and second operands shall be the same register"));
12900
88714cb8 12901 NEON_ENCODE (IMMED, inst);
5287ad62 12902
4316f0d2 12903 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
12904 if (et.size == 64)
12905 {
12906 /* .i64 is a pseudo-op, so the immediate must be a repeating
12907 pattern. */
4316f0d2
DG
12908 if (immbits != (inst.operands[immoperand].regisimm ?
12909 inst.operands[immoperand].reg : 0))
036dc3f7
PB
12910 {
12911 /* Set immbits to an invalid constant. */
12912 immbits = 0xdeadbeef;
12913 }
12914 }
12915
5287ad62
JB
12916 switch (opcode)
12917 {
12918 case N_MNEM_vbic:
036dc3f7 12919 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12920 break;
5f4273c7 12921
5287ad62 12922 case N_MNEM_vorr:
036dc3f7 12923 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12924 break;
5f4273c7 12925
5287ad62
JB
12926 case N_MNEM_vand:
12927 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12928 neon_invert_size (&immbits, 0, et.size);
12929 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12930 break;
5f4273c7 12931
5287ad62
JB
12932 case N_MNEM_vorn:
12933 /* Pseudo-instruction for VORR. */
5287ad62
JB
12934 neon_invert_size (&immbits, 0, et.size);
12935 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12936 break;
5f4273c7 12937
5287ad62
JB
12938 default:
12939 abort ();
12940 }
12941
12942 if (cmode == FAIL)
12943 return;
12944
037e8744 12945 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12946 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12947 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12948 inst.instruction |= cmode << 8;
12949 neon_write_immbits (immbits);
5f4273c7 12950
88714cb8 12951 neon_dp_fixup (&inst);
5287ad62
JB
12952 }
12953}
12954
12955static void
12956do_neon_bitfield (void)
12957{
037e8744 12958 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12959 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12960 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12961}
12962
12963static void
dcbf9037
JB
12964neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12965 unsigned destbits)
5287ad62 12966{
037e8744 12967 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12968 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12969 types | N_KEY);
5287ad62
JB
12970 if (et.type == NT_float)
12971 {
88714cb8 12972 NEON_ENCODE (FLOAT, inst);
037e8744 12973 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12974 }
12975 else
12976 {
88714cb8 12977 NEON_ENCODE (INTEGER, inst);
037e8744 12978 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12979 }
12980}
12981
12982static void
12983do_neon_dyadic_if_su (void)
12984{
dcbf9037 12985 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12986}
12987
12988static void
12989do_neon_dyadic_if_su_d (void)
12990{
12991 /* This version only allow D registers, but that constraint is enforced during
12992 operand parsing so we don't need to do anything extra here. */
dcbf9037 12993 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12994}
12995
5287ad62
JB
12996static void
12997do_neon_dyadic_if_i_d (void)
12998{
428e3f1f
PB
12999 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13000 affected if we specify unsigned args. */
13001 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13002}
13003
037e8744
JB
13004enum vfp_or_neon_is_neon_bits
13005{
13006 NEON_CHECK_CC = 1,
13007 NEON_CHECK_ARCH = 2
13008};
13009
13010/* Call this function if an instruction which may have belonged to the VFP or
13011 Neon instruction sets, but turned out to be a Neon instruction (due to the
13012 operand types involved, etc.). We have to check and/or fix-up a couple of
13013 things:
13014
13015 - Make sure the user hasn't attempted to make a Neon instruction
13016 conditional.
13017 - Alter the value in the condition code field if necessary.
13018 - Make sure that the arch supports Neon instructions.
13019
13020 Which of these operations take place depends on bits from enum
13021 vfp_or_neon_is_neon_bits.
13022
13023 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13024 current instruction's condition is COND_ALWAYS, the condition field is
13025 changed to inst.uncond_value. This is necessary because instructions shared
13026 between VFP and Neon may be conditional for the VFP variants only, and the
13027 unconditional Neon version must have, e.g., 0xF in the condition field. */
13028
13029static int
13030vfp_or_neon_is_neon (unsigned check)
13031{
13032 /* Conditions are always legal in Thumb mode (IT blocks). */
13033 if (!thumb_mode && (check & NEON_CHECK_CC))
13034 {
13035 if (inst.cond != COND_ALWAYS)
13036 {
13037 first_error (_(BAD_COND));
13038 return FAIL;
13039 }
13040 if (inst.uncond_value != -1)
13041 inst.instruction |= inst.uncond_value << 28;
13042 }
5f4273c7 13043
037e8744
JB
13044 if ((check & NEON_CHECK_ARCH)
13045 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13046 {
13047 first_error (_(BAD_FPU));
13048 return FAIL;
13049 }
5f4273c7 13050
037e8744
JB
13051 return SUCCESS;
13052}
13053
5287ad62
JB
13054static void
13055do_neon_addsub_if_i (void)
13056{
037e8744
JB
13057 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13058 return;
13059
13060 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13061 return;
13062
5287ad62
JB
13063 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13064 affected if we specify unsigned args. */
dcbf9037 13065 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13066}
13067
13068/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13069 result to be:
13070 V<op> A,B (A is operand 0, B is operand 2)
13071 to mean:
13072 V<op> A,B,A
13073 not:
13074 V<op> A,B,B
13075 so handle that case specially. */
13076
13077static void
13078neon_exchange_operands (void)
13079{
13080 void *scratch = alloca (sizeof (inst.operands[0]));
13081 if (inst.operands[1].present)
13082 {
13083 /* Swap operands[1] and operands[2]. */
13084 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13085 inst.operands[1] = inst.operands[2];
13086 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13087 }
13088 else
13089 {
13090 inst.operands[1] = inst.operands[2];
13091 inst.operands[2] = inst.operands[0];
13092 }
13093}
13094
13095static void
13096neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13097{
13098 if (inst.operands[2].isreg)
13099 {
13100 if (invert)
13101 neon_exchange_operands ();
dcbf9037 13102 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13103 }
13104 else
13105 {
037e8744 13106 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13107 struct neon_type_el et = neon_check_type (2, rs,
13108 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13109
88714cb8 13110 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13111 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13112 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13113 inst.instruction |= LOW4 (inst.operands[1].reg);
13114 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13115 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13116 inst.instruction |= (et.type == NT_float) << 10;
13117 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13118
88714cb8 13119 neon_dp_fixup (&inst);
5287ad62
JB
13120 }
13121}
13122
13123static void
13124do_neon_cmp (void)
13125{
13126 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13127}
13128
13129static void
13130do_neon_cmp_inv (void)
13131{
13132 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13133}
13134
13135static void
13136do_neon_ceq (void)
13137{
13138 neon_compare (N_IF_32, N_IF_32, FALSE);
13139}
13140
13141/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13142 scalars, which are encoded in 5 bits, M : Rm.
13143 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13144 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13145 index in M. */
13146
13147static unsigned
13148neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13149{
dcbf9037
JB
13150 unsigned regno = NEON_SCALAR_REG (scalar);
13151 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13152
13153 switch (elsize)
13154 {
13155 case 16:
13156 if (regno > 7 || elno > 3)
13157 goto bad_scalar;
13158 return regno | (elno << 3);
5f4273c7 13159
5287ad62
JB
13160 case 32:
13161 if (regno > 15 || elno > 1)
13162 goto bad_scalar;
13163 return regno | (elno << 4);
13164
13165 default:
13166 bad_scalar:
dcbf9037 13167 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13168 }
13169
13170 return 0;
13171}
13172
13173/* Encode multiply / multiply-accumulate scalar instructions. */
13174
13175static void
13176neon_mul_mac (struct neon_type_el et, int ubit)
13177{
dcbf9037
JB
13178 unsigned scalar;
13179
13180 /* Give a more helpful error message if we have an invalid type. */
13181 if (et.type == NT_invtype)
13182 return;
5f4273c7 13183
dcbf9037 13184 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13185 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13186 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13187 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13188 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13189 inst.instruction |= LOW4 (scalar);
13190 inst.instruction |= HI1 (scalar) << 5;
13191 inst.instruction |= (et.type == NT_float) << 8;
13192 inst.instruction |= neon_logbits (et.size) << 20;
13193 inst.instruction |= (ubit != 0) << 24;
13194
88714cb8 13195 neon_dp_fixup (&inst);
5287ad62
JB
13196}
13197
13198static void
13199do_neon_mac_maybe_scalar (void)
13200{
037e8744
JB
13201 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13202 return;
13203
13204 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13205 return;
13206
5287ad62
JB
13207 if (inst.operands[2].isscalar)
13208 {
037e8744 13209 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13210 struct neon_type_el et = neon_check_type (3, rs,
13211 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13212 NEON_ENCODE (SCALAR, inst);
037e8744 13213 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13214 }
13215 else
428e3f1f
PB
13216 {
13217 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13218 affected if we specify unsigned args. */
13219 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13220 }
5287ad62
JB
13221}
13222
62f3b8c8
PB
13223static void
13224do_neon_fmac (void)
13225{
13226 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13227 return;
13228
13229 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13230 return;
13231
13232 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13233}
13234
5287ad62
JB
13235static void
13236do_neon_tst (void)
13237{
037e8744 13238 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13239 struct neon_type_el et = neon_check_type (3, rs,
13240 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13241 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13242}
13243
13244/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13245 same types as the MAC equivalents. The polynomial type for this instruction
13246 is encoded the same as the integer type. */
13247
13248static void
13249do_neon_mul (void)
13250{
037e8744
JB
13251 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13252 return;
13253
13254 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13255 return;
13256
5287ad62
JB
13257 if (inst.operands[2].isscalar)
13258 do_neon_mac_maybe_scalar ();
13259 else
dcbf9037 13260 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13261}
13262
13263static void
13264do_neon_qdmulh (void)
13265{
13266 if (inst.operands[2].isscalar)
13267 {
037e8744 13268 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13269 struct neon_type_el et = neon_check_type (3, rs,
13270 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13271 NEON_ENCODE (SCALAR, inst);
037e8744 13272 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13273 }
13274 else
13275 {
037e8744 13276 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13277 struct neon_type_el et = neon_check_type (3, rs,
13278 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13279 NEON_ENCODE (INTEGER, inst);
5287ad62 13280 /* The U bit (rounding) comes from bit mask. */
037e8744 13281 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13282 }
13283}
13284
13285static void
13286do_neon_fcmp_absolute (void)
13287{
037e8744 13288 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13289 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13290 /* Size field comes from bit mask. */
037e8744 13291 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13292}
13293
13294static void
13295do_neon_fcmp_absolute_inv (void)
13296{
13297 neon_exchange_operands ();
13298 do_neon_fcmp_absolute ();
13299}
13300
13301static void
13302do_neon_step (void)
13303{
037e8744 13304 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13305 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13306 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13307}
13308
13309static void
13310do_neon_abs_neg (void)
13311{
037e8744
JB
13312 enum neon_shape rs;
13313 struct neon_type_el et;
5f4273c7 13314
037e8744
JB
13315 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13316 return;
13317
13318 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13319 return;
13320
13321 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13322 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13323
5287ad62
JB
13324 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13325 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13326 inst.instruction |= LOW4 (inst.operands[1].reg);
13327 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13328 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13329 inst.instruction |= (et.type == NT_float) << 10;
13330 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13331
88714cb8 13332 neon_dp_fixup (&inst);
5287ad62
JB
13333}
13334
13335static void
13336do_neon_sli (void)
13337{
037e8744 13338 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13339 struct neon_type_el et = neon_check_type (2, rs,
13340 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13341 int imm = inst.operands[2].imm;
13342 constraint (imm < 0 || (unsigned)imm >= et.size,
13343 _("immediate out of range for insert"));
037e8744 13344 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13345}
13346
13347static void
13348do_neon_sri (void)
13349{
037e8744 13350 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13351 struct neon_type_el et = neon_check_type (2, rs,
13352 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13353 int imm = inst.operands[2].imm;
13354 constraint (imm < 1 || (unsigned)imm > et.size,
13355 _("immediate out of range for insert"));
037e8744 13356 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13357}
13358
13359static void
13360do_neon_qshlu_imm (void)
13361{
037e8744 13362 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13363 struct neon_type_el et = neon_check_type (2, rs,
13364 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13365 int imm = inst.operands[2].imm;
13366 constraint (imm < 0 || (unsigned)imm >= et.size,
13367 _("immediate out of range for shift"));
13368 /* Only encodes the 'U present' variant of the instruction.
13369 In this case, signed types have OP (bit 8) set to 0.
13370 Unsigned types have OP set to 1. */
13371 inst.instruction |= (et.type == NT_unsigned) << 8;
13372 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13373 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13374}
13375
13376static void
13377do_neon_qmovn (void)
13378{
13379 struct neon_type_el et = neon_check_type (2, NS_DQ,
13380 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13381 /* Saturating move where operands can be signed or unsigned, and the
13382 destination has the same signedness. */
88714cb8 13383 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13384 if (et.type == NT_unsigned)
13385 inst.instruction |= 0xc0;
13386 else
13387 inst.instruction |= 0x80;
13388 neon_two_same (0, 1, et.size / 2);
13389}
13390
13391static void
13392do_neon_qmovun (void)
13393{
13394 struct neon_type_el et = neon_check_type (2, NS_DQ,
13395 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13396 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13397 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13398 neon_two_same (0, 1, et.size / 2);
13399}
13400
13401static void
13402do_neon_rshift_sat_narrow (void)
13403{
13404 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13405 or unsigned. If operands are unsigned, results must also be unsigned. */
13406 struct neon_type_el et = neon_check_type (2, NS_DQI,
13407 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13408 int imm = inst.operands[2].imm;
13409 /* This gets the bounds check, size encoding and immediate bits calculation
13410 right. */
13411 et.size /= 2;
5f4273c7 13412
5287ad62
JB
13413 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13414 VQMOVN.I<size> <Dd>, <Qm>. */
13415 if (imm == 0)
13416 {
13417 inst.operands[2].present = 0;
13418 inst.instruction = N_MNEM_vqmovn;
13419 do_neon_qmovn ();
13420 return;
13421 }
5f4273c7 13422
5287ad62
JB
13423 constraint (imm < 1 || (unsigned)imm > et.size,
13424 _("immediate out of range"));
13425 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13426}
13427
13428static void
13429do_neon_rshift_sat_narrow_u (void)
13430{
13431 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13432 or unsigned. If operands are unsigned, results must also be unsigned. */
13433 struct neon_type_el et = neon_check_type (2, NS_DQI,
13434 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13435 int imm = inst.operands[2].imm;
13436 /* This gets the bounds check, size encoding and immediate bits calculation
13437 right. */
13438 et.size /= 2;
13439
13440 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13441 VQMOVUN.I<size> <Dd>, <Qm>. */
13442 if (imm == 0)
13443 {
13444 inst.operands[2].present = 0;
13445 inst.instruction = N_MNEM_vqmovun;
13446 do_neon_qmovun ();
13447 return;
13448 }
13449
13450 constraint (imm < 1 || (unsigned)imm > et.size,
13451 _("immediate out of range"));
13452 /* FIXME: The manual is kind of unclear about what value U should have in
13453 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13454 must be 1. */
13455 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13456}
13457
13458static void
13459do_neon_movn (void)
13460{
13461 struct neon_type_el et = neon_check_type (2, NS_DQ,
13462 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13463 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13464 neon_two_same (0, 1, et.size / 2);
13465}
13466
13467static void
13468do_neon_rshift_narrow (void)
13469{
13470 struct neon_type_el et = neon_check_type (2, NS_DQI,
13471 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13472 int imm = inst.operands[2].imm;
13473 /* This gets the bounds check, size encoding and immediate bits calculation
13474 right. */
13475 et.size /= 2;
5f4273c7 13476
5287ad62
JB
13477 /* If immediate is zero then we are a pseudo-instruction for
13478 VMOVN.I<size> <Dd>, <Qm> */
13479 if (imm == 0)
13480 {
13481 inst.operands[2].present = 0;
13482 inst.instruction = N_MNEM_vmovn;
13483 do_neon_movn ();
13484 return;
13485 }
5f4273c7 13486
5287ad62
JB
13487 constraint (imm < 1 || (unsigned)imm > et.size,
13488 _("immediate out of range for narrowing operation"));
13489 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13490}
13491
13492static void
13493do_neon_shll (void)
13494{
13495 /* FIXME: Type checking when lengthening. */
13496 struct neon_type_el et = neon_check_type (2, NS_QDI,
13497 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13498 unsigned imm = inst.operands[2].imm;
13499
13500 if (imm == et.size)
13501 {
13502 /* Maximum shift variant. */
88714cb8 13503 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13504 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13505 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13506 inst.instruction |= LOW4 (inst.operands[1].reg);
13507 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13508 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13509
88714cb8 13510 neon_dp_fixup (&inst);
5287ad62
JB
13511 }
13512 else
13513 {
13514 /* A more-specific type check for non-max versions. */
13515 et = neon_check_type (2, NS_QDI,
13516 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13517 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13518 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13519 }
13520}
13521
037e8744 13522/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13523 the current instruction is. */
13524
13525static int
13526neon_cvt_flavour (enum neon_shape rs)
13527{
037e8744
JB
13528#define CVT_VAR(C,X,Y) \
13529 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13530 if (et.type != NT_invtype) \
13531 { \
13532 inst.error = NULL; \
13533 return (C); \
5287ad62
JB
13534 }
13535 struct neon_type_el et;
037e8744
JB
13536 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13537 || rs == NS_FF) ? N_VFP : 0;
13538 /* The instruction versions which take an immediate take one register
13539 argument, which is extended to the width of the full register. Thus the
13540 "source" and "destination" registers must have the same width. Hack that
13541 here by making the size equal to the key (wider, in this case) operand. */
13542 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13543
5287ad62
JB
13544 CVT_VAR (0, N_S32, N_F32);
13545 CVT_VAR (1, N_U32, N_F32);
13546 CVT_VAR (2, N_F32, N_S32);
13547 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13548 /* Half-precision conversions. */
13549 CVT_VAR (4, N_F32, N_F16);
13550 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13551
037e8744 13552 whole_reg = N_VFP;
5f4273c7 13553
037e8744 13554 /* VFP instructions. */
8e79c3df
CM
13555 CVT_VAR (6, N_F32, N_F64);
13556 CVT_VAR (7, N_F64, N_F32);
13557 CVT_VAR (8, N_S32, N_F64 | key);
13558 CVT_VAR (9, N_U32, N_F64 | key);
13559 CVT_VAR (10, N_F64 | key, N_S32);
13560 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13561 /* VFP instructions with bitshift. */
8e79c3df
CM
13562 CVT_VAR (12, N_F32 | key, N_S16);
13563 CVT_VAR (13, N_F32 | key, N_U16);
13564 CVT_VAR (14, N_F64 | key, N_S16);
13565 CVT_VAR (15, N_F64 | key, N_U16);
13566 CVT_VAR (16, N_S16, N_F32 | key);
13567 CVT_VAR (17, N_U16, N_F32 | key);
13568 CVT_VAR (18, N_S16, N_F64 | key);
13569 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13570
5287ad62
JB
13571 return -1;
13572#undef CVT_VAR
13573}
13574
037e8744
JB
13575/* Neon-syntax VFP conversions. */
13576
5287ad62 13577static void
037e8744 13578do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13579{
037e8744 13580 const char *opname = 0;
5f4273c7 13581
037e8744 13582 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13583 {
037e8744
JB
13584 /* Conversions with immediate bitshift. */
13585 const char *enc[] =
13586 {
13587 "ftosls",
13588 "ftouls",
13589 "fsltos",
13590 "fultos",
13591 NULL,
13592 NULL,
8e79c3df
CM
13593 NULL,
13594 NULL,
037e8744
JB
13595 "ftosld",
13596 "ftould",
13597 "fsltod",
13598 "fultod",
13599 "fshtos",
13600 "fuhtos",
13601 "fshtod",
13602 "fuhtod",
13603 "ftoshs",
13604 "ftouhs",
13605 "ftoshd",
13606 "ftouhd"
13607 };
13608
13609 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13610 {
13611 opname = enc[flavour];
13612 constraint (inst.operands[0].reg != inst.operands[1].reg,
13613 _("operands 0 and 1 must be the same register"));
13614 inst.operands[1] = inst.operands[2];
13615 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13616 }
5287ad62
JB
13617 }
13618 else
13619 {
037e8744
JB
13620 /* Conversions without bitshift. */
13621 const char *enc[] =
13622 {
13623 "ftosis",
13624 "ftouis",
13625 "fsitos",
13626 "fuitos",
8e79c3df
CM
13627 "NULL",
13628 "NULL",
037e8744
JB
13629 "fcvtsd",
13630 "fcvtds",
13631 "ftosid",
13632 "ftouid",
13633 "fsitod",
13634 "fuitod"
13635 };
13636
13637 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13638 opname = enc[flavour];
13639 }
13640
13641 if (opname)
13642 do_vfp_nsyn_opcode (opname);
13643}
13644
13645static void
13646do_vfp_nsyn_cvtz (void)
13647{
13648 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13649 int flavour = neon_cvt_flavour (rs);
13650 const char *enc[] =
13651 {
13652 "ftosizs",
13653 "ftouizs",
13654 NULL,
13655 NULL,
13656 NULL,
13657 NULL,
8e79c3df
CM
13658 NULL,
13659 NULL,
037e8744
JB
13660 "ftosizd",
13661 "ftouizd"
13662 };
13663
13664 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13665 do_vfp_nsyn_opcode (enc[flavour]);
13666}
f31fef98 13667
037e8744
JB
13668static void
13669do_neon_cvt (void)
13670{
13671 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13672 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13673 int flavour = neon_cvt_flavour (rs);
13674
13675 /* VFP rather than Neon conversions. */
8e79c3df 13676 if (flavour >= 6)
037e8744
JB
13677 {
13678 do_vfp_nsyn_cvt (rs, flavour);
13679 return;
13680 }
13681
13682 switch (rs)
13683 {
13684 case NS_DDI:
13685 case NS_QQI:
13686 {
35997600
NC
13687 unsigned immbits;
13688 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13689
037e8744
JB
13690 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13691 return;
13692
13693 /* Fixed-point conversion with #0 immediate is encoded as an
13694 integer conversion. */
13695 if (inst.operands[2].present && inst.operands[2].imm == 0)
13696 goto int_encode;
35997600 13697 immbits = 32 - inst.operands[2].imm;
88714cb8 13698 NEON_ENCODE (IMMED, inst);
037e8744
JB
13699 if (flavour != -1)
13700 inst.instruction |= enctab[flavour];
13701 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13702 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13703 inst.instruction |= LOW4 (inst.operands[1].reg);
13704 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13705 inst.instruction |= neon_quad (rs) << 6;
13706 inst.instruction |= 1 << 21;
13707 inst.instruction |= immbits << 16;
13708
88714cb8 13709 neon_dp_fixup (&inst);
037e8744
JB
13710 }
13711 break;
13712
13713 case NS_DD:
13714 case NS_QQ:
13715 int_encode:
13716 {
13717 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13718
88714cb8 13719 NEON_ENCODE (INTEGER, inst);
037e8744
JB
13720
13721 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13722 return;
13723
13724 if (flavour != -1)
13725 inst.instruction |= enctab[flavour];
13726
13727 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13728 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13729 inst.instruction |= LOW4 (inst.operands[1].reg);
13730 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13731 inst.instruction |= neon_quad (rs) << 6;
13732 inst.instruction |= 2 << 18;
13733
88714cb8 13734 neon_dp_fixup (&inst);
037e8744
JB
13735 }
13736 break;
13737
8e79c3df
CM
13738 /* Half-precision conversions for Advanced SIMD -- neon. */
13739 case NS_QD:
13740 case NS_DQ:
13741
13742 if ((rs == NS_DQ)
13743 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13744 {
13745 as_bad (_("operand size must match register width"));
13746 break;
13747 }
13748
13749 if ((rs == NS_QD)
13750 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13751 {
13752 as_bad (_("operand size must match register width"));
13753 break;
13754 }
13755
13756 if (rs == NS_DQ)
13757 inst.instruction = 0x3b60600;
13758 else
13759 inst.instruction = 0x3b60700;
13760
13761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13763 inst.instruction |= LOW4 (inst.operands[1].reg);
13764 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 13765 neon_dp_fixup (&inst);
8e79c3df
CM
13766 break;
13767
037e8744
JB
13768 default:
13769 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13770 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13771 }
5287ad62
JB
13772}
13773
8e79c3df
CM
13774static void
13775do_neon_cvtb (void)
13776{
13777 inst.instruction = 0xeb20a40;
13778
13779 /* The sizes are attached to the mnemonic. */
13780 if (inst.vectype.el[0].type != NT_invtype
13781 && inst.vectype.el[0].size == 16)
13782 inst.instruction |= 0x00010000;
13783
13784 /* Programmer's syntax: the sizes are attached to the operands. */
13785 else if (inst.operands[0].vectype.type != NT_invtype
13786 && inst.operands[0].vectype.size == 16)
13787 inst.instruction |= 0x00010000;
13788
13789 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13790 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13791 do_vfp_cond_or_thumb ();
13792}
13793
13794
13795static void
13796do_neon_cvtt (void)
13797{
13798 do_neon_cvtb ();
13799 inst.instruction |= 0x80;
13800}
13801
5287ad62
JB
13802static void
13803neon_move_immediate (void)
13804{
037e8744
JB
13805 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13806 struct neon_type_el et = neon_check_type (2, rs,
13807 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13808 unsigned immlo, immhi = 0, immbits;
c96612cc 13809 int op, cmode, float_p;
5287ad62 13810
037e8744
JB
13811 constraint (et.type == NT_invtype,
13812 _("operand size must be specified for immediate VMOV"));
13813
5287ad62
JB
13814 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13815 op = (inst.instruction & (1 << 5)) != 0;
13816
13817 immlo = inst.operands[1].imm;
13818 if (inst.operands[1].regisimm)
13819 immhi = inst.operands[1].reg;
13820
13821 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13822 _("immediate has bits set outside the operand size"));
13823
c96612cc
JB
13824 float_p = inst.operands[1].immisfloat;
13825
13826 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13827 et.size, et.type)) == FAIL)
5287ad62
JB
13828 {
13829 /* Invert relevant bits only. */
13830 neon_invert_size (&immlo, &immhi, et.size);
13831 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13832 with one or the other; those cases are caught by
13833 neon_cmode_for_move_imm. */
13834 op = !op;
c96612cc
JB
13835 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13836 &op, et.size, et.type)) == FAIL)
5287ad62 13837 {
dcbf9037 13838 first_error (_("immediate out of range"));
5287ad62
JB
13839 return;
13840 }
13841 }
13842
13843 inst.instruction &= ~(1 << 5);
13844 inst.instruction |= op << 5;
13845
13846 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13847 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13848 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13849 inst.instruction |= cmode << 8;
13850
13851 neon_write_immbits (immbits);
13852}
13853
13854static void
13855do_neon_mvn (void)
13856{
13857 if (inst.operands[1].isreg)
13858 {
037e8744 13859 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13860
88714cb8 13861 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13862 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13863 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13864 inst.instruction |= LOW4 (inst.operands[1].reg);
13865 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13866 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13867 }
13868 else
13869 {
88714cb8 13870 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13871 neon_move_immediate ();
13872 }
13873
88714cb8 13874 neon_dp_fixup (&inst);
5287ad62
JB
13875}
13876
13877/* Encode instructions of form:
13878
13879 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13880 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13881
13882static void
13883neon_mixed_length (struct neon_type_el et, unsigned size)
13884{
13885 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13886 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13887 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13888 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13889 inst.instruction |= LOW4 (inst.operands[2].reg);
13890 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13891 inst.instruction |= (et.type == NT_unsigned) << 24;
13892 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13893
88714cb8 13894 neon_dp_fixup (&inst);
5287ad62
JB
13895}
13896
13897static void
13898do_neon_dyadic_long (void)
13899{
13900 /* FIXME: Type checking for lengthening op. */
13901 struct neon_type_el et = neon_check_type (3, NS_QDD,
13902 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13903 neon_mixed_length (et, et.size);
13904}
13905
13906static void
13907do_neon_abal (void)
13908{
13909 struct neon_type_el et = neon_check_type (3, NS_QDD,
13910 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13911 neon_mixed_length (et, et.size);
13912}
13913
13914static void
13915neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13916{
13917 if (inst.operands[2].isscalar)
13918 {
dcbf9037
JB
13919 struct neon_type_el et = neon_check_type (3, NS_QDS,
13920 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 13921 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
13922 neon_mul_mac (et, et.type == NT_unsigned);
13923 }
13924 else
13925 {
13926 struct neon_type_el et = neon_check_type (3, NS_QDD,
13927 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 13928 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13929 neon_mixed_length (et, et.size);
13930 }
13931}
13932
13933static void
13934do_neon_mac_maybe_scalar_long (void)
13935{
13936 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13937}
13938
13939static void
13940do_neon_dyadic_wide (void)
13941{
13942 struct neon_type_el et = neon_check_type (3, NS_QQD,
13943 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13944 neon_mixed_length (et, et.size);
13945}
13946
13947static void
13948do_neon_dyadic_narrow (void)
13949{
13950 struct neon_type_el et = neon_check_type (3, NS_QDD,
13951 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13952 /* Operand sign is unimportant, and the U bit is part of the opcode,
13953 so force the operand type to integer. */
13954 et.type = NT_integer;
5287ad62
JB
13955 neon_mixed_length (et, et.size / 2);
13956}
13957
13958static void
13959do_neon_mul_sat_scalar_long (void)
13960{
13961 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13962}
13963
13964static void
13965do_neon_vmull (void)
13966{
13967 if (inst.operands[2].isscalar)
13968 do_neon_mac_maybe_scalar_long ();
13969 else
13970 {
13971 struct neon_type_el et = neon_check_type (3, NS_QDD,
13972 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13973 if (et.type == NT_poly)
88714cb8 13974 NEON_ENCODE (POLY, inst);
5287ad62 13975 else
88714cb8 13976 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13977 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13978 zero. Should be OK as-is. */
13979 neon_mixed_length (et, et.size);
13980 }
13981}
13982
13983static void
13984do_neon_ext (void)
13985{
037e8744 13986 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13987 struct neon_type_el et = neon_check_type (3, rs,
13988 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13989 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13990
13991 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13992 _("shift out of range"));
5287ad62
JB
13993 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13994 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13995 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13996 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13997 inst.instruction |= LOW4 (inst.operands[2].reg);
13998 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13999 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14000 inst.instruction |= imm << 8;
5f4273c7 14001
88714cb8 14002 neon_dp_fixup (&inst);
5287ad62
JB
14003}
14004
14005static void
14006do_neon_rev (void)
14007{
037e8744 14008 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14009 struct neon_type_el et = neon_check_type (2, rs,
14010 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14011 unsigned op = (inst.instruction >> 7) & 3;
14012 /* N (width of reversed regions) is encoded as part of the bitmask. We
14013 extract it here to check the elements to be reversed are smaller.
14014 Otherwise we'd get a reserved instruction. */
14015 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14016 gas_assert (elsize != 0);
5287ad62
JB
14017 constraint (et.size >= elsize,
14018 _("elements must be smaller than reversal region"));
037e8744 14019 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14020}
14021
14022static void
14023do_neon_dup (void)
14024{
14025 if (inst.operands[1].isscalar)
14026 {
037e8744 14027 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14028 struct neon_type_el et = neon_check_type (2, rs,
14029 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14030 unsigned sizebits = et.size >> 3;
dcbf9037 14031 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14032 int logsize = neon_logbits (et.size);
dcbf9037 14033 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14034
14035 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14036 return;
14037
88714cb8 14038 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14039 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14040 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14041 inst.instruction |= LOW4 (dm);
14042 inst.instruction |= HI1 (dm) << 5;
037e8744 14043 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14044 inst.instruction |= x << 17;
14045 inst.instruction |= sizebits << 16;
5f4273c7 14046
88714cb8 14047 neon_dp_fixup (&inst);
5287ad62
JB
14048 }
14049 else
14050 {
037e8744
JB
14051 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14052 struct neon_type_el et = neon_check_type (2, rs,
14053 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14054 /* Duplicate ARM register to lanes of vector. */
88714cb8 14055 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14056 switch (et.size)
14057 {
14058 case 8: inst.instruction |= 0x400000; break;
14059 case 16: inst.instruction |= 0x000020; break;
14060 case 32: inst.instruction |= 0x000000; break;
14061 default: break;
14062 }
14063 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14064 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14065 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14066 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14067 /* The encoding for this instruction is identical for the ARM and Thumb
14068 variants, except for the condition field. */
037e8744 14069 do_vfp_cond_or_thumb ();
5287ad62
JB
14070 }
14071}
14072
14073/* VMOV has particularly many variations. It can be one of:
14074 0. VMOV<c><q> <Qd>, <Qm>
14075 1. VMOV<c><q> <Dd>, <Dm>
14076 (Register operations, which are VORR with Rm = Rn.)
14077 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14078 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14079 (Immediate loads.)
14080 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14081 (ARM register to scalar.)
14082 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14083 (Two ARM registers to vector.)
14084 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14085 (Scalar to ARM register.)
14086 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14087 (Vector to two ARM registers.)
037e8744
JB
14088 8. VMOV.F32 <Sd>, <Sm>
14089 9. VMOV.F64 <Dd>, <Dm>
14090 (VFP register moves.)
14091 10. VMOV.F32 <Sd>, #imm
14092 11. VMOV.F64 <Dd>, #imm
14093 (VFP float immediate load.)
14094 12. VMOV <Rd>, <Sm>
14095 (VFP single to ARM reg.)
14096 13. VMOV <Sd>, <Rm>
14097 (ARM reg to VFP single.)
14098 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14099 (Two ARM regs to two VFP singles.)
14100 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14101 (Two VFP singles to two ARM regs.)
5f4273c7 14102
037e8744
JB
14103 These cases can be disambiguated using neon_select_shape, except cases 1/9
14104 and 3/11 which depend on the operand type too.
5f4273c7 14105
5287ad62 14106 All the encoded bits are hardcoded by this function.
5f4273c7 14107
b7fc2769
JB
14108 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14109 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14110
5287ad62 14111 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14112 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14113
14114static void
14115do_neon_mov (void)
14116{
037e8744
JB
14117 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14118 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14119 NS_NULL);
14120 struct neon_type_el et;
14121 const char *ldconst = 0;
5287ad62 14122
037e8744 14123 switch (rs)
5287ad62 14124 {
037e8744
JB
14125 case NS_DD: /* case 1/9. */
14126 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14127 /* It is not an error here if no type is given. */
14128 inst.error = NULL;
14129 if (et.type == NT_float && et.size == 64)
5287ad62 14130 {
037e8744
JB
14131 do_vfp_nsyn_opcode ("fcpyd");
14132 break;
5287ad62 14133 }
037e8744 14134 /* fall through. */
5287ad62 14135
037e8744
JB
14136 case NS_QQ: /* case 0/1. */
14137 {
14138 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14139 return;
14140 /* The architecture manual I have doesn't explicitly state which
14141 value the U bit should have for register->register moves, but
14142 the equivalent VORR instruction has U = 0, so do that. */
14143 inst.instruction = 0x0200110;
14144 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14145 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14146 inst.instruction |= LOW4 (inst.operands[1].reg);
14147 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14148 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14149 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14150 inst.instruction |= neon_quad (rs) << 6;
14151
88714cb8 14152 neon_dp_fixup (&inst);
037e8744
JB
14153 }
14154 break;
5f4273c7 14155
037e8744
JB
14156 case NS_DI: /* case 3/11. */
14157 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14158 inst.error = NULL;
14159 if (et.type == NT_float && et.size == 64)
5287ad62 14160 {
037e8744
JB
14161 /* case 11 (fconstd). */
14162 ldconst = "fconstd";
14163 goto encode_fconstd;
5287ad62 14164 }
037e8744
JB
14165 /* fall through. */
14166
14167 case NS_QI: /* case 2/3. */
14168 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14169 return;
14170 inst.instruction = 0x0800010;
14171 neon_move_immediate ();
88714cb8 14172 neon_dp_fixup (&inst);
5287ad62 14173 break;
5f4273c7 14174
037e8744
JB
14175 case NS_SR: /* case 4. */
14176 {
14177 unsigned bcdebits = 0;
91d6fa6a 14178 int logsize;
037e8744
JB
14179 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14180 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14181
91d6fa6a
NC
14182 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14183 logsize = neon_logbits (et.size);
14184
037e8744
JB
14185 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14186 _(BAD_FPU));
14187 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14188 && et.size != 32, _(BAD_FPU));
14189 constraint (et.type == NT_invtype, _("bad type for scalar"));
14190 constraint (x >= 64 / et.size, _("scalar index out of range"));
14191
14192 switch (et.size)
14193 {
14194 case 8: bcdebits = 0x8; break;
14195 case 16: bcdebits = 0x1; break;
14196 case 32: bcdebits = 0x0; break;
14197 default: ;
14198 }
14199
14200 bcdebits |= x << logsize;
14201
14202 inst.instruction = 0xe000b10;
14203 do_vfp_cond_or_thumb ();
14204 inst.instruction |= LOW4 (dn) << 16;
14205 inst.instruction |= HI1 (dn) << 7;
14206 inst.instruction |= inst.operands[1].reg << 12;
14207 inst.instruction |= (bcdebits & 3) << 5;
14208 inst.instruction |= (bcdebits >> 2) << 21;
14209 }
14210 break;
5f4273c7 14211
037e8744 14212 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14214 _(BAD_FPU));
b7fc2769 14215
037e8744
JB
14216 inst.instruction = 0xc400b10;
14217 do_vfp_cond_or_thumb ();
14218 inst.instruction |= LOW4 (inst.operands[0].reg);
14219 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14220 inst.instruction |= inst.operands[1].reg << 12;
14221 inst.instruction |= inst.operands[2].reg << 16;
14222 break;
5f4273c7 14223
037e8744
JB
14224 case NS_RS: /* case 6. */
14225 {
91d6fa6a 14226 unsigned logsize;
037e8744
JB
14227 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14228 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14229 unsigned abcdebits = 0;
14230
91d6fa6a
NC
14231 et = neon_check_type (2, NS_NULL,
14232 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14233 logsize = neon_logbits (et.size);
14234
037e8744
JB
14235 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14236 _(BAD_FPU));
14237 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14238 && et.size != 32, _(BAD_FPU));
14239 constraint (et.type == NT_invtype, _("bad type for scalar"));
14240 constraint (x >= 64 / et.size, _("scalar index out of range"));
14241
14242 switch (et.size)
14243 {
14244 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14245 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14246 case 32: abcdebits = 0x00; break;
14247 default: ;
14248 }
14249
14250 abcdebits |= x << logsize;
14251 inst.instruction = 0xe100b10;
14252 do_vfp_cond_or_thumb ();
14253 inst.instruction |= LOW4 (dn) << 16;
14254 inst.instruction |= HI1 (dn) << 7;
14255 inst.instruction |= inst.operands[0].reg << 12;
14256 inst.instruction |= (abcdebits & 3) << 5;
14257 inst.instruction |= (abcdebits >> 2) << 21;
14258 }
14259 break;
5f4273c7 14260
037e8744
JB
14261 case NS_RRD: /* case 7 (fmrrd). */
14262 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14263 _(BAD_FPU));
14264
14265 inst.instruction = 0xc500b10;
14266 do_vfp_cond_or_thumb ();
14267 inst.instruction |= inst.operands[0].reg << 12;
14268 inst.instruction |= inst.operands[1].reg << 16;
14269 inst.instruction |= LOW4 (inst.operands[2].reg);
14270 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14271 break;
5f4273c7 14272
037e8744
JB
14273 case NS_FF: /* case 8 (fcpys). */
14274 do_vfp_nsyn_opcode ("fcpys");
14275 break;
5f4273c7 14276
037e8744
JB
14277 case NS_FI: /* case 10 (fconsts). */
14278 ldconst = "fconsts";
14279 encode_fconstd:
14280 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14281 {
037e8744
JB
14282 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14283 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14284 }
14285 else
037e8744
JB
14286 first_error (_("immediate out of range"));
14287 break;
5f4273c7 14288
037e8744
JB
14289 case NS_RF: /* case 12 (fmrs). */
14290 do_vfp_nsyn_opcode ("fmrs");
14291 break;
5f4273c7 14292
037e8744
JB
14293 case NS_FR: /* case 13 (fmsr). */
14294 do_vfp_nsyn_opcode ("fmsr");
14295 break;
5f4273c7 14296
037e8744
JB
14297 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14298 (one of which is a list), but we have parsed four. Do some fiddling to
14299 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14300 expect. */
14301 case NS_RRFF: /* case 14 (fmrrs). */
14302 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14303 _("VFP registers must be adjacent"));
14304 inst.operands[2].imm = 2;
14305 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14306 do_vfp_nsyn_opcode ("fmrrs");
14307 break;
5f4273c7 14308
037e8744
JB
14309 case NS_FFRR: /* case 15 (fmsrr). */
14310 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14311 _("VFP registers must be adjacent"));
14312 inst.operands[1] = inst.operands[2];
14313 inst.operands[2] = inst.operands[3];
14314 inst.operands[0].imm = 2;
14315 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14316 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14317 break;
5f4273c7 14318
5287ad62
JB
14319 default:
14320 abort ();
14321 }
14322}
14323
14324static void
14325do_neon_rshift_round_imm (void)
14326{
037e8744 14327 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14328 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14329 int imm = inst.operands[2].imm;
14330
14331 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14332 if (imm == 0)
14333 {
14334 inst.operands[2].present = 0;
14335 do_neon_mov ();
14336 return;
14337 }
14338
14339 constraint (imm < 1 || (unsigned)imm > et.size,
14340 _("immediate out of range for shift"));
037e8744 14341 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14342 et.size - imm);
14343}
14344
14345static void
14346do_neon_movl (void)
14347{
14348 struct neon_type_el et = neon_check_type (2, NS_QD,
14349 N_EQK | N_DBL, N_SU_32 | N_KEY);
14350 unsigned sizebits = et.size >> 3;
14351 inst.instruction |= sizebits << 19;
14352 neon_two_same (0, et.type == NT_unsigned, -1);
14353}
14354
14355static void
14356do_neon_trn (void)
14357{
037e8744 14358 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14359 struct neon_type_el et = neon_check_type (2, rs,
14360 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14361 NEON_ENCODE (INTEGER, inst);
037e8744 14362 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14363}
14364
14365static void
14366do_neon_zip_uzp (void)
14367{
037e8744 14368 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14369 struct neon_type_el et = neon_check_type (2, rs,
14370 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14371 if (rs == NS_DD && et.size == 32)
14372 {
14373 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14374 inst.instruction = N_MNEM_vtrn;
14375 do_neon_trn ();
14376 return;
14377 }
037e8744 14378 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14379}
14380
14381static void
14382do_neon_sat_abs_neg (void)
14383{
037e8744 14384 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14385 struct neon_type_el et = neon_check_type (2, rs,
14386 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14387 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14388}
14389
14390static void
14391do_neon_pair_long (void)
14392{
037e8744 14393 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14394 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14395 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14396 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14397 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14398}
14399
14400static void
14401do_neon_recip_est (void)
14402{
037e8744 14403 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14404 struct neon_type_el et = neon_check_type (2, rs,
14405 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14406 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14407 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14408}
14409
14410static void
14411do_neon_cls (void)
14412{
037e8744 14413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14414 struct neon_type_el et = neon_check_type (2, rs,
14415 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14416 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14417}
14418
14419static void
14420do_neon_clz (void)
14421{
037e8744 14422 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14423 struct neon_type_el et = neon_check_type (2, rs,
14424 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14425 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14426}
14427
14428static void
14429do_neon_cnt (void)
14430{
037e8744 14431 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14432 struct neon_type_el et = neon_check_type (2, rs,
14433 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14434 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14435}
14436
14437static void
14438do_neon_swp (void)
14439{
037e8744
JB
14440 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14441 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14442}
14443
14444static void
14445do_neon_tbl_tbx (void)
14446{
14447 unsigned listlenbits;
dcbf9037 14448 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14449
5287ad62
JB
14450 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14451 {
dcbf9037 14452 first_error (_("bad list length for table lookup"));
5287ad62
JB
14453 return;
14454 }
5f4273c7 14455
5287ad62
JB
14456 listlenbits = inst.operands[1].imm - 1;
14457 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14458 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14459 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14460 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14461 inst.instruction |= LOW4 (inst.operands[2].reg);
14462 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14463 inst.instruction |= listlenbits << 8;
5f4273c7 14464
88714cb8 14465 neon_dp_fixup (&inst);
5287ad62
JB
14466}
14467
14468static void
14469do_neon_ldm_stm (void)
14470{
14471 /* P, U and L bits are part of bitmask. */
14472 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14473 unsigned offsetbits = inst.operands[1].imm * 2;
14474
037e8744
JB
14475 if (inst.operands[1].issingle)
14476 {
14477 do_vfp_nsyn_ldm_stm (is_dbmode);
14478 return;
14479 }
14480
5287ad62
JB
14481 constraint (is_dbmode && !inst.operands[0].writeback,
14482 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14483
14484 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14485 _("register list must contain at least 1 and at most 16 "
14486 "registers"));
14487
14488 inst.instruction |= inst.operands[0].reg << 16;
14489 inst.instruction |= inst.operands[0].writeback << 21;
14490 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14491 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14492
14493 inst.instruction |= offsetbits;
5f4273c7 14494
037e8744 14495 do_vfp_cond_or_thumb ();
5287ad62
JB
14496}
14497
14498static void
14499do_neon_ldr_str (void)
14500{
5287ad62 14501 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14502
037e8744
JB
14503 if (inst.operands[0].issingle)
14504 {
cd2f129f
JB
14505 if (is_ldr)
14506 do_vfp_nsyn_opcode ("flds");
14507 else
14508 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14509 }
14510 else
5287ad62 14511 {
cd2f129f
JB
14512 if (is_ldr)
14513 do_vfp_nsyn_opcode ("fldd");
5287ad62 14514 else
cd2f129f 14515 do_vfp_nsyn_opcode ("fstd");
5287ad62 14516 }
5287ad62
JB
14517}
14518
14519/* "interleave" version also handles non-interleaving register VLD1/VST1
14520 instructions. */
14521
14522static void
14523do_neon_ld_st_interleave (void)
14524{
037e8744 14525 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14526 N_8 | N_16 | N_32 | N_64);
14527 unsigned alignbits = 0;
14528 unsigned idx;
14529 /* The bits in this table go:
14530 0: register stride of one (0) or two (1)
14531 1,2: register list length, minus one (1, 2, 3, 4).
14532 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14533 We use -1 for invalid entries. */
14534 const int typetable[] =
14535 {
14536 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14537 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14538 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14539 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14540 };
14541 int typebits;
14542
dcbf9037
JB
14543 if (et.type == NT_invtype)
14544 return;
14545
5287ad62
JB
14546 if (inst.operands[1].immisalign)
14547 switch (inst.operands[1].imm >> 8)
14548 {
14549 case 64: alignbits = 1; break;
14550 case 128:
14551 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14552 goto bad_alignment;
14553 alignbits = 2;
14554 break;
14555 case 256:
14556 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14557 goto bad_alignment;
14558 alignbits = 3;
14559 break;
14560 default:
14561 bad_alignment:
dcbf9037 14562 first_error (_("bad alignment"));
5287ad62
JB
14563 return;
14564 }
14565
14566 inst.instruction |= alignbits << 4;
14567 inst.instruction |= neon_logbits (et.size) << 6;
14568
14569 /* Bits [4:6] of the immediate in a list specifier encode register stride
14570 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14571 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14572 up the right value for "type" in a table based on this value and the given
14573 list style, then stick it back. */
14574 idx = ((inst.operands[0].imm >> 4) & 7)
14575 | (((inst.instruction >> 8) & 3) << 3);
14576
14577 typebits = typetable[idx];
5f4273c7 14578
5287ad62
JB
14579 constraint (typebits == -1, _("bad list type for instruction"));
14580
14581 inst.instruction &= ~0xf00;
14582 inst.instruction |= typebits << 8;
14583}
14584
14585/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14586 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14587 otherwise. The variable arguments are a list of pairs of legal (size, align)
14588 values, terminated with -1. */
14589
14590static int
14591neon_alignment_bit (int size, int align, int *do_align, ...)
14592{
14593 va_list ap;
14594 int result = FAIL, thissize, thisalign;
5f4273c7 14595
5287ad62
JB
14596 if (!inst.operands[1].immisalign)
14597 {
14598 *do_align = 0;
14599 return SUCCESS;
14600 }
5f4273c7 14601
5287ad62
JB
14602 va_start (ap, do_align);
14603
14604 do
14605 {
14606 thissize = va_arg (ap, int);
14607 if (thissize == -1)
14608 break;
14609 thisalign = va_arg (ap, int);
14610
14611 if (size == thissize && align == thisalign)
14612 result = SUCCESS;
14613 }
14614 while (result != SUCCESS);
14615
14616 va_end (ap);
14617
14618 if (result == SUCCESS)
14619 *do_align = 1;
14620 else
dcbf9037 14621 first_error (_("unsupported alignment for instruction"));
5f4273c7 14622
5287ad62
JB
14623 return result;
14624}
14625
14626static void
14627do_neon_ld_st_lane (void)
14628{
037e8744 14629 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14630 int align_good, do_align = 0;
14631 int logsize = neon_logbits (et.size);
14632 int align = inst.operands[1].imm >> 8;
14633 int n = (inst.instruction >> 8) & 3;
14634 int max_el = 64 / et.size;
5f4273c7 14635
dcbf9037
JB
14636 if (et.type == NT_invtype)
14637 return;
5f4273c7 14638
5287ad62
JB
14639 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14640 _("bad list length"));
14641 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14642 _("scalar index out of range"));
14643 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14644 && et.size == 8,
14645 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14646
5287ad62
JB
14647 switch (n)
14648 {
14649 case 0: /* VLD1 / VST1. */
14650 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14651 32, 32, -1);
14652 if (align_good == FAIL)
14653 return;
14654 if (do_align)
14655 {
14656 unsigned alignbits = 0;
14657 switch (et.size)
14658 {
14659 case 16: alignbits = 0x1; break;
14660 case 32: alignbits = 0x3; break;
14661 default: ;
14662 }
14663 inst.instruction |= alignbits << 4;
14664 }
14665 break;
14666
14667 case 1: /* VLD2 / VST2. */
14668 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14669 32, 64, -1);
14670 if (align_good == FAIL)
14671 return;
14672 if (do_align)
14673 inst.instruction |= 1 << 4;
14674 break;
14675
14676 case 2: /* VLD3 / VST3. */
14677 constraint (inst.operands[1].immisalign,
14678 _("can't use alignment with this instruction"));
14679 break;
14680
14681 case 3: /* VLD4 / VST4. */
14682 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14683 16, 64, 32, 64, 32, 128, -1);
14684 if (align_good == FAIL)
14685 return;
14686 if (do_align)
14687 {
14688 unsigned alignbits = 0;
14689 switch (et.size)
14690 {
14691 case 8: alignbits = 0x1; break;
14692 case 16: alignbits = 0x1; break;
14693 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14694 default: ;
14695 }
14696 inst.instruction |= alignbits << 4;
14697 }
14698 break;
14699
14700 default: ;
14701 }
14702
14703 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14704 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14705 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14706
5287ad62
JB
14707 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14708 inst.instruction |= logsize << 10;
14709}
14710
14711/* Encode single n-element structure to all lanes VLD<n> instructions. */
14712
14713static void
14714do_neon_ld_dup (void)
14715{
037e8744 14716 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14717 int align_good, do_align = 0;
14718
dcbf9037
JB
14719 if (et.type == NT_invtype)
14720 return;
14721
5287ad62
JB
14722 switch ((inst.instruction >> 8) & 3)
14723 {
14724 case 0: /* VLD1. */
9c2799c2 14725 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14726 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14727 &do_align, 16, 16, 32, 32, -1);
14728 if (align_good == FAIL)
14729 return;
14730 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14731 {
14732 case 1: break;
14733 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14734 default: first_error (_("bad list length")); return;
5287ad62
JB
14735 }
14736 inst.instruction |= neon_logbits (et.size) << 6;
14737 break;
14738
14739 case 1: /* VLD2. */
14740 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14741 &do_align, 8, 16, 16, 32, 32, 64, -1);
14742 if (align_good == FAIL)
14743 return;
14744 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14745 _("bad list length"));
14746 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14747 inst.instruction |= 1 << 5;
14748 inst.instruction |= neon_logbits (et.size) << 6;
14749 break;
14750
14751 case 2: /* VLD3. */
14752 constraint (inst.operands[1].immisalign,
14753 _("can't use alignment with this instruction"));
14754 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14755 _("bad list length"));
14756 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14757 inst.instruction |= 1 << 5;
14758 inst.instruction |= neon_logbits (et.size) << 6;
14759 break;
14760
14761 case 3: /* VLD4. */
14762 {
14763 int align = inst.operands[1].imm >> 8;
14764 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14765 16, 64, 32, 64, 32, 128, -1);
14766 if (align_good == FAIL)
14767 return;
14768 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14769 _("bad list length"));
14770 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14771 inst.instruction |= 1 << 5;
14772 if (et.size == 32 && align == 128)
14773 inst.instruction |= 0x3 << 6;
14774 else
14775 inst.instruction |= neon_logbits (et.size) << 6;
14776 }
14777 break;
14778
14779 default: ;
14780 }
14781
14782 inst.instruction |= do_align << 4;
14783}
14784
14785/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14786 apart from bits [11:4]. */
14787
14788static void
14789do_neon_ldx_stx (void)
14790{
b1a769ed
DG
14791 if (inst.operands[1].isreg)
14792 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14793
5287ad62
JB
14794 switch (NEON_LANE (inst.operands[0].imm))
14795 {
14796 case NEON_INTERLEAVE_LANES:
88714cb8 14797 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
14798 do_neon_ld_st_interleave ();
14799 break;
5f4273c7 14800
5287ad62 14801 case NEON_ALL_LANES:
88714cb8 14802 NEON_ENCODE (DUP, inst);
5287ad62
JB
14803 do_neon_ld_dup ();
14804 break;
5f4273c7 14805
5287ad62 14806 default:
88714cb8 14807 NEON_ENCODE (LANE, inst);
5287ad62
JB
14808 do_neon_ld_st_lane ();
14809 }
14810
14811 /* L bit comes from bit mask. */
14812 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14813 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14814 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14815
5287ad62
JB
14816 if (inst.operands[1].postind)
14817 {
14818 int postreg = inst.operands[1].imm & 0xf;
14819 constraint (!inst.operands[1].immisreg,
14820 _("post-index must be a register"));
14821 constraint (postreg == 0xd || postreg == 0xf,
14822 _("bad register for post-index"));
14823 inst.instruction |= postreg;
14824 }
14825 else if (inst.operands[1].writeback)
14826 {
14827 inst.instruction |= 0xd;
14828 }
14829 else
5f4273c7
NC
14830 inst.instruction |= 0xf;
14831
5287ad62
JB
14832 if (thumb_mode)
14833 inst.instruction |= 0xf9000000;
14834 else
14835 inst.instruction |= 0xf4000000;
14836}
5287ad62
JB
14837\f
14838/* Overall per-instruction processing. */
14839
14840/* We need to be able to fix up arbitrary expressions in some statements.
14841 This is so that we can handle symbols that are an arbitrary distance from
14842 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14843 which returns part of an address in a form which will be valid for
14844 a data instruction. We do this by pushing the expression into a symbol
14845 in the expr_section, and creating a fix for that. */
14846
14847static void
14848fix_new_arm (fragS * frag,
14849 int where,
14850 short int size,
14851 expressionS * exp,
14852 int pc_rel,
14853 int reloc)
14854{
14855 fixS * new_fix;
14856
14857 switch (exp->X_op)
14858 {
14859 case O_constant:
14860 case O_symbol:
14861 case O_add:
14862 case O_subtract:
21d799b5
NC
14863 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14864 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14865 break;
14866
14867 default:
21d799b5
NC
14868 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14869 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14870 break;
14871 }
14872
14873 /* Mark whether the fix is to a THUMB instruction, or an ARM
14874 instruction. */
14875 new_fix->tc_fix_data = thumb_mode;
14876}
14877
14878/* Create a frg for an instruction requiring relaxation. */
14879static void
14880output_relax_insn (void)
14881{
14882 char * to;
14883 symbolS *sym;
0110f2b8
PB
14884 int offset;
14885
6e1cb1a6
PB
14886 /* The size of the instruction is unknown, so tie the debug info to the
14887 start of the instruction. */
14888 dwarf2_emit_insn (0);
6e1cb1a6 14889
0110f2b8
PB
14890 switch (inst.reloc.exp.X_op)
14891 {
14892 case O_symbol:
14893 sym = inst.reloc.exp.X_add_symbol;
14894 offset = inst.reloc.exp.X_add_number;
14895 break;
14896 case O_constant:
14897 sym = NULL;
14898 offset = inst.reloc.exp.X_add_number;
14899 break;
14900 default:
14901 sym = make_expr_symbol (&inst.reloc.exp);
14902 offset = 0;
14903 break;
14904 }
14905 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14906 inst.relax, sym, offset, NULL/*offset, opcode*/);
14907 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14908}
14909
14910/* Write a 32-bit thumb instruction to buf. */
14911static void
14912put_thumb32_insn (char * buf, unsigned long insn)
14913{
14914 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14915 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14916}
14917
b99bd4ef 14918static void
c19d1205 14919output_inst (const char * str)
b99bd4ef 14920{
c19d1205 14921 char * to = NULL;
b99bd4ef 14922
c19d1205 14923 if (inst.error)
b99bd4ef 14924 {
c19d1205 14925 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14926 return;
14927 }
5f4273c7
NC
14928 if (inst.relax)
14929 {
14930 output_relax_insn ();
0110f2b8 14931 return;
5f4273c7 14932 }
c19d1205
ZW
14933 if (inst.size == 0)
14934 return;
b99bd4ef 14935
c19d1205 14936 to = frag_more (inst.size);
8dc2430f
NC
14937 /* PR 9814: Record the thumb mode into the current frag so that we know
14938 what type of NOP padding to use, if necessary. We override any previous
14939 setting so that if the mode has changed then the NOPS that we use will
14940 match the encoding of the last instruction in the frag. */
cd000bff 14941 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14942
14943 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14944 {
9c2799c2 14945 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14946 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14947 }
c19d1205 14948 else if (inst.size > INSN_SIZE)
b99bd4ef 14949 {
9c2799c2 14950 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
14951 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14952 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14953 }
c19d1205
ZW
14954 else
14955 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14956
c19d1205
ZW
14957 if (inst.reloc.type != BFD_RELOC_UNUSED)
14958 fix_new_arm (frag_now, to - frag_now->fr_literal,
14959 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14960 inst.reloc.type);
b99bd4ef 14961
c19d1205 14962 dwarf2_emit_insn (inst.size);
c19d1205 14963}
b99bd4ef 14964
e07e6e58
NC
14965static char *
14966output_it_inst (int cond, int mask, char * to)
14967{
14968 unsigned long instruction = 0xbf00;
14969
14970 mask &= 0xf;
14971 instruction |= mask;
14972 instruction |= cond << 4;
14973
14974 if (to == NULL)
14975 {
14976 to = frag_more (2);
14977#ifdef OBJ_ELF
14978 dwarf2_emit_insn (2);
14979#endif
14980 }
14981
14982 md_number_to_chars (to, instruction, 2);
14983
14984 return to;
14985}
14986
c19d1205
ZW
14987/* Tag values used in struct asm_opcode's tag field. */
14988enum opcode_tag
14989{
14990 OT_unconditional, /* Instruction cannot be conditionalized.
14991 The ARM condition field is still 0xE. */
14992 OT_unconditionalF, /* Instruction cannot be conditionalized
14993 and carries 0xF in its ARM condition field. */
14994 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14995 OT_csuffixF, /* Some forms of the instruction take a conditional
14996 suffix, others place 0xF where the condition field
14997 would be. */
c19d1205
ZW
14998 OT_cinfix3, /* Instruction takes a conditional infix,
14999 beginning at character index 3. (In
15000 unified mode, it becomes a suffix.) */
088fa78e
KH
15001 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15002 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15003 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15004 character index 3, even in unified mode. Used for
15005 legacy instructions where suffix and infix forms
15006 may be ambiguous. */
c19d1205 15007 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15008 suffix or an infix at character index 3. */
c19d1205
ZW
15009 OT_odd_infix_unc, /* This is the unconditional variant of an
15010 instruction that takes a conditional infix
15011 at an unusual position. In unified mode,
15012 this variant will accept a suffix. */
15013 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15014 are the conditional variants of instructions that
15015 take conditional infixes in unusual positions.
15016 The infix appears at character index
15017 (tag - OT_odd_infix_0). These are not accepted
15018 in unified mode. */
15019};
b99bd4ef 15020
c19d1205
ZW
15021/* Subroutine of md_assemble, responsible for looking up the primary
15022 opcode from the mnemonic the user wrote. STR points to the
15023 beginning of the mnemonic.
15024
15025 This is not simply a hash table lookup, because of conditional
15026 variants. Most instructions have conditional variants, which are
15027 expressed with a _conditional affix_ to the mnemonic. If we were
15028 to encode each conditional variant as a literal string in the opcode
15029 table, it would have approximately 20,000 entries.
15030
15031 Most mnemonics take this affix as a suffix, and in unified syntax,
15032 'most' is upgraded to 'all'. However, in the divided syntax, some
15033 instructions take the affix as an infix, notably the s-variants of
15034 the arithmetic instructions. Of those instructions, all but six
15035 have the infix appear after the third character of the mnemonic.
15036
15037 Accordingly, the algorithm for looking up primary opcodes given
15038 an identifier is:
15039
15040 1. Look up the identifier in the opcode table.
15041 If we find a match, go to step U.
15042
15043 2. Look up the last two characters of the identifier in the
15044 conditions table. If we find a match, look up the first N-2
15045 characters of the identifier in the opcode table. If we
15046 find a match, go to step CE.
15047
15048 3. Look up the fourth and fifth characters of the identifier in
15049 the conditions table. If we find a match, extract those
15050 characters from the identifier, and look up the remaining
15051 characters in the opcode table. If we find a match, go
15052 to step CM.
15053
15054 4. Fail.
15055
15056 U. Examine the tag field of the opcode structure, in case this is
15057 one of the six instructions with its conditional infix in an
15058 unusual place. If it is, the tag tells us where to find the
15059 infix; look it up in the conditions table and set inst.cond
15060 accordingly. Otherwise, this is an unconditional instruction.
15061 Again set inst.cond accordingly. Return the opcode structure.
15062
15063 CE. Examine the tag field to make sure this is an instruction that
15064 should receive a conditional suffix. If it is not, fail.
15065 Otherwise, set inst.cond from the suffix we already looked up,
15066 and return the opcode structure.
15067
15068 CM. Examine the tag field to make sure this is an instruction that
15069 should receive a conditional infix after the third character.
15070 If it is not, fail. Otherwise, undo the edits to the current
15071 line of input and proceed as for case CE. */
15072
15073static const struct asm_opcode *
15074opcode_lookup (char **str)
15075{
15076 char *end, *base;
15077 char *affix;
15078 const struct asm_opcode *opcode;
15079 const struct asm_cond *cond;
e3cb604e 15080 char save[2];
c19d1205
ZW
15081
15082 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15083 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15084 for (base = end = *str; *end != '\0'; end++)
721a8186 15085 if (*end == ' ' || *end == '.')
c19d1205 15086 break;
b99bd4ef 15087
c19d1205 15088 if (end == base)
c921be7d 15089 return NULL;
b99bd4ef 15090
5287ad62 15091 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15092 if (end[0] == '.')
b99bd4ef 15093 {
5287ad62 15094 int offset = 2;
5f4273c7 15095
267d2029
JB
15096 /* The .w and .n suffixes are only valid if the unified syntax is in
15097 use. */
15098 if (unified_syntax && end[1] == 'w')
c19d1205 15099 inst.size_req = 4;
267d2029 15100 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15101 inst.size_req = 2;
15102 else
5287ad62
JB
15103 offset = 0;
15104
15105 inst.vectype.elems = 0;
15106
15107 *str = end + offset;
b99bd4ef 15108
5f4273c7 15109 if (end[offset] == '.')
5287ad62 15110 {
267d2029
JB
15111 /* See if we have a Neon type suffix (possible in either unified or
15112 non-unified ARM syntax mode). */
dcbf9037 15113 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15114 return NULL;
5287ad62
JB
15115 }
15116 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15117 return NULL;
b99bd4ef 15118 }
c19d1205
ZW
15119 else
15120 *str = end;
b99bd4ef 15121
c19d1205 15122 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15123 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15124 end - base);
c19d1205 15125 if (opcode)
b99bd4ef 15126 {
c19d1205
ZW
15127 /* step U */
15128 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15129 {
c19d1205
ZW
15130 inst.cond = COND_ALWAYS;
15131 return opcode;
b99bd4ef 15132 }
b99bd4ef 15133
278df34e 15134 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15135 as_warn (_("conditional infixes are deprecated in unified syntax"));
15136 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15137 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15138 gas_assert (cond);
b99bd4ef 15139
c19d1205
ZW
15140 inst.cond = cond->value;
15141 return opcode;
15142 }
b99bd4ef 15143
c19d1205
ZW
15144 /* Cannot have a conditional suffix on a mnemonic of less than two
15145 characters. */
15146 if (end - base < 3)
c921be7d 15147 return NULL;
b99bd4ef 15148
c19d1205
ZW
15149 /* Look for suffixed mnemonic. */
15150 affix = end - 2;
21d799b5
NC
15151 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15152 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15153 affix - base);
c19d1205
ZW
15154 if (opcode && cond)
15155 {
15156 /* step CE */
15157 switch (opcode->tag)
15158 {
e3cb604e
PB
15159 case OT_cinfix3_legacy:
15160 /* Ignore conditional suffixes matched on infix only mnemonics. */
15161 break;
15162
c19d1205 15163 case OT_cinfix3:
088fa78e 15164 case OT_cinfix3_deprecated:
c19d1205
ZW
15165 case OT_odd_infix_unc:
15166 if (!unified_syntax)
e3cb604e 15167 return 0;
c19d1205
ZW
15168 /* else fall through */
15169
15170 case OT_csuffix:
037e8744 15171 case OT_csuffixF:
c19d1205
ZW
15172 case OT_csuf_or_in3:
15173 inst.cond = cond->value;
15174 return opcode;
15175
15176 case OT_unconditional:
15177 case OT_unconditionalF:
dfa9f0d5 15178 if (thumb_mode)
c921be7d 15179 inst.cond = cond->value;
dfa9f0d5
PB
15180 else
15181 {
c921be7d 15182 /* Delayed diagnostic. */
dfa9f0d5
PB
15183 inst.error = BAD_COND;
15184 inst.cond = COND_ALWAYS;
15185 }
c19d1205 15186 return opcode;
b99bd4ef 15187
c19d1205 15188 default:
c921be7d 15189 return NULL;
c19d1205
ZW
15190 }
15191 }
b99bd4ef 15192
c19d1205
ZW
15193 /* Cannot have a usual-position infix on a mnemonic of less than
15194 six characters (five would be a suffix). */
15195 if (end - base < 6)
c921be7d 15196 return NULL;
b99bd4ef 15197
c19d1205
ZW
15198 /* Look for infixed mnemonic in the usual position. */
15199 affix = base + 3;
21d799b5 15200 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15201 if (!cond)
c921be7d 15202 return NULL;
e3cb604e
PB
15203
15204 memcpy (save, affix, 2);
15205 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15206 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15207 (end - base) - 2);
e3cb604e
PB
15208 memmove (affix + 2, affix, (end - affix) - 2);
15209 memcpy (affix, save, 2);
15210
088fa78e
KH
15211 if (opcode
15212 && (opcode->tag == OT_cinfix3
15213 || opcode->tag == OT_cinfix3_deprecated
15214 || opcode->tag == OT_csuf_or_in3
15215 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15216 {
c921be7d 15217 /* Step CM. */
278df34e 15218 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15219 && (opcode->tag == OT_cinfix3
15220 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15221 as_warn (_("conditional infixes are deprecated in unified syntax"));
15222
15223 inst.cond = cond->value;
15224 return opcode;
b99bd4ef
NC
15225 }
15226
c921be7d 15227 return NULL;
b99bd4ef
NC
15228}
15229
e07e6e58
NC
15230/* This function generates an initial IT instruction, leaving its block
15231 virtually open for the new instructions. Eventually,
15232 the mask will be updated by now_it_add_mask () each time
15233 a new instruction needs to be included in the IT block.
15234 Finally, the block is closed with close_automatic_it_block ().
15235 The block closure can be requested either from md_assemble (),
15236 a tencode (), or due to a label hook. */
15237
15238static void
15239new_automatic_it_block (int cond)
15240{
15241 now_it.state = AUTOMATIC_IT_BLOCK;
15242 now_it.mask = 0x18;
15243 now_it.cc = cond;
15244 now_it.block_length = 1;
cd000bff 15245 mapping_state (MAP_THUMB);
e07e6e58
NC
15246 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15247}
15248
15249/* Close an automatic IT block.
15250 See comments in new_automatic_it_block (). */
15251
15252static void
15253close_automatic_it_block (void)
15254{
15255 now_it.mask = 0x10;
15256 now_it.block_length = 0;
15257}
15258
15259/* Update the mask of the current automatically-generated IT
15260 instruction. See comments in new_automatic_it_block (). */
15261
15262static void
15263now_it_add_mask (int cond)
15264{
15265#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15266#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15267 | ((bitvalue) << (nbit)))
e07e6e58 15268 const int resulting_bit = (cond & 1);
c921be7d 15269
e07e6e58
NC
15270 now_it.mask &= 0xf;
15271 now_it.mask = SET_BIT_VALUE (now_it.mask,
15272 resulting_bit,
15273 (5 - now_it.block_length));
15274 now_it.mask = SET_BIT_VALUE (now_it.mask,
15275 1,
15276 ((5 - now_it.block_length) - 1) );
15277 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15278
15279#undef CLEAR_BIT
15280#undef SET_BIT_VALUE
e07e6e58
NC
15281}
15282
15283/* The IT blocks handling machinery is accessed through the these functions:
15284 it_fsm_pre_encode () from md_assemble ()
15285 set_it_insn_type () optional, from the tencode functions
15286 set_it_insn_type_last () ditto
15287 in_it_block () ditto
15288 it_fsm_post_encode () from md_assemble ()
15289 force_automatic_it_block_close () from label habdling functions
15290
15291 Rationale:
15292 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15293 initializing the IT insn type with a generic initial value depending
15294 on the inst.condition.
15295 2) During the tencode function, two things may happen:
15296 a) The tencode function overrides the IT insn type by
15297 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15298 b) The tencode function queries the IT block state by
15299 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15300
15301 Both set_it_insn_type and in_it_block run the internal FSM state
15302 handling function (handle_it_state), because: a) setting the IT insn
15303 type may incur in an invalid state (exiting the function),
15304 and b) querying the state requires the FSM to be updated.
15305 Specifically we want to avoid creating an IT block for conditional
15306 branches, so it_fsm_pre_encode is actually a guess and we can't
15307 determine whether an IT block is required until the tencode () routine
15308 has decided what type of instruction this actually it.
15309 Because of this, if set_it_insn_type and in_it_block have to be used,
15310 set_it_insn_type has to be called first.
15311
15312 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15313 determines the insn IT type depending on the inst.cond code.
15314 When a tencode () routine encodes an instruction that can be
15315 either outside an IT block, or, in the case of being inside, has to be
15316 the last one, set_it_insn_type_last () will determine the proper
15317 IT instruction type based on the inst.cond code. Otherwise,
15318 set_it_insn_type can be called for overriding that logic or
15319 for covering other cases.
15320
15321 Calling handle_it_state () may not transition the IT block state to
15322 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15323 still queried. Instead, if the FSM determines that the state should
15324 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15325 after the tencode () function: that's what it_fsm_post_encode () does.
15326
15327 Since in_it_block () calls the state handling function to get an
15328 updated state, an error may occur (due to invalid insns combination).
15329 In that case, inst.error is set.
15330 Therefore, inst.error has to be checked after the execution of
15331 the tencode () routine.
15332
15333 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15334 any pending state change (if any) that didn't take place in
15335 handle_it_state () as explained above. */
15336
15337static void
15338it_fsm_pre_encode (void)
15339{
15340 if (inst.cond != COND_ALWAYS)
15341 inst.it_insn_type = INSIDE_IT_INSN;
15342 else
15343 inst.it_insn_type = OUTSIDE_IT_INSN;
15344
15345 now_it.state_handled = 0;
15346}
15347
15348/* IT state FSM handling function. */
15349
15350static int
15351handle_it_state (void)
15352{
15353 now_it.state_handled = 1;
15354
15355 switch (now_it.state)
15356 {
15357 case OUTSIDE_IT_BLOCK:
15358 switch (inst.it_insn_type)
15359 {
15360 case OUTSIDE_IT_INSN:
15361 break;
15362
15363 case INSIDE_IT_INSN:
15364 case INSIDE_IT_LAST_INSN:
15365 if (thumb_mode == 0)
15366 {
c921be7d 15367 if (unified_syntax
e07e6e58
NC
15368 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15369 as_tsktsk (_("Warning: conditional outside an IT block"\
15370 " for Thumb."));
15371 }
15372 else
15373 {
15374 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15375 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15376 {
15377 /* Automatically generate the IT instruction. */
15378 new_automatic_it_block (inst.cond);
15379 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15380 close_automatic_it_block ();
15381 }
15382 else
15383 {
15384 inst.error = BAD_OUT_IT;
15385 return FAIL;
15386 }
15387 }
15388 break;
15389
15390 case IF_INSIDE_IT_LAST_INSN:
15391 case NEUTRAL_IT_INSN:
15392 break;
15393
15394 case IT_INSN:
15395 now_it.state = MANUAL_IT_BLOCK;
15396 now_it.block_length = 0;
15397 break;
15398 }
15399 break;
15400
15401 case AUTOMATIC_IT_BLOCK:
15402 /* Three things may happen now:
15403 a) We should increment current it block size;
15404 b) We should close current it block (closing insn or 4 insns);
15405 c) We should close current it block and start a new one (due
15406 to incompatible conditions or
15407 4 insns-length block reached). */
15408
15409 switch (inst.it_insn_type)
15410 {
15411 case OUTSIDE_IT_INSN:
15412 /* The closure of the block shall happen immediatelly,
15413 so any in_it_block () call reports the block as closed. */
15414 force_automatic_it_block_close ();
15415 break;
15416
15417 case INSIDE_IT_INSN:
15418 case INSIDE_IT_LAST_INSN:
15419 case IF_INSIDE_IT_LAST_INSN:
15420 now_it.block_length++;
15421
15422 if (now_it.block_length > 4
15423 || !now_it_compatible (inst.cond))
15424 {
15425 force_automatic_it_block_close ();
15426 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15427 new_automatic_it_block (inst.cond);
15428 }
15429 else
15430 {
15431 now_it_add_mask (inst.cond);
15432 }
15433
15434 if (now_it.state == AUTOMATIC_IT_BLOCK
15435 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15436 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15437 close_automatic_it_block ();
15438 break;
15439
15440 case NEUTRAL_IT_INSN:
15441 now_it.block_length++;
15442
15443 if (now_it.block_length > 4)
15444 force_automatic_it_block_close ();
15445 else
15446 now_it_add_mask (now_it.cc & 1);
15447 break;
15448
15449 case IT_INSN:
15450 close_automatic_it_block ();
15451 now_it.state = MANUAL_IT_BLOCK;
15452 break;
15453 }
15454 break;
15455
15456 case MANUAL_IT_BLOCK:
15457 {
15458 /* Check conditional suffixes. */
15459 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15460 int is_last;
15461 now_it.mask <<= 1;
15462 now_it.mask &= 0x1f;
15463 is_last = (now_it.mask == 0x10);
15464
15465 switch (inst.it_insn_type)
15466 {
15467 case OUTSIDE_IT_INSN:
15468 inst.error = BAD_NOT_IT;
15469 return FAIL;
15470
15471 case INSIDE_IT_INSN:
15472 if (cond != inst.cond)
15473 {
15474 inst.error = BAD_IT_COND;
15475 return FAIL;
15476 }
15477 break;
15478
15479 case INSIDE_IT_LAST_INSN:
15480 case IF_INSIDE_IT_LAST_INSN:
15481 if (cond != inst.cond)
15482 {
15483 inst.error = BAD_IT_COND;
15484 return FAIL;
15485 }
15486 if (!is_last)
15487 {
15488 inst.error = BAD_BRANCH;
15489 return FAIL;
15490 }
15491 break;
15492
15493 case NEUTRAL_IT_INSN:
15494 /* The BKPT instruction is unconditional even in an IT block. */
15495 break;
15496
15497 case IT_INSN:
15498 inst.error = BAD_IT_IT;
15499 return FAIL;
15500 }
15501 }
15502 break;
15503 }
15504
15505 return SUCCESS;
15506}
15507
15508static void
15509it_fsm_post_encode (void)
15510{
15511 int is_last;
15512
15513 if (!now_it.state_handled)
15514 handle_it_state ();
15515
15516 is_last = (now_it.mask == 0x10);
15517 if (is_last)
15518 {
15519 now_it.state = OUTSIDE_IT_BLOCK;
15520 now_it.mask = 0;
15521 }
15522}
15523
15524static void
15525force_automatic_it_block_close (void)
15526{
15527 if (now_it.state == AUTOMATIC_IT_BLOCK)
15528 {
15529 close_automatic_it_block ();
15530 now_it.state = OUTSIDE_IT_BLOCK;
15531 now_it.mask = 0;
15532 }
15533}
15534
15535static int
15536in_it_block (void)
15537{
15538 if (!now_it.state_handled)
15539 handle_it_state ();
15540
15541 return now_it.state != OUTSIDE_IT_BLOCK;
15542}
15543
c19d1205
ZW
15544void
15545md_assemble (char *str)
b99bd4ef 15546{
c19d1205
ZW
15547 char *p = str;
15548 const struct asm_opcode * opcode;
b99bd4ef 15549
c19d1205
ZW
15550 /* Align the previous label if needed. */
15551 if (last_label_seen != NULL)
b99bd4ef 15552 {
c19d1205
ZW
15553 symbol_set_frag (last_label_seen, frag_now);
15554 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15555 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15556 }
15557
c19d1205
ZW
15558 memset (&inst, '\0', sizeof (inst));
15559 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15560
c19d1205
ZW
15561 opcode = opcode_lookup (&p);
15562 if (!opcode)
b99bd4ef 15563 {
c19d1205 15564 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15565 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15566 if (! create_register_alias (str, p)
15567 && ! create_neon_reg_alias (str, p))
c19d1205 15568 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15569
b99bd4ef
NC
15570 return;
15571 }
15572
278df34e 15573 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15574 as_warn (_("s suffix on comparison instruction is deprecated"));
15575
037e8744
JB
15576 /* The value which unconditional instructions should have in place of the
15577 condition field. */
15578 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15579
c19d1205 15580 if (thumb_mode)
b99bd4ef 15581 {
e74cfd16 15582 arm_feature_set variant;
8f06b2d8
PB
15583
15584 variant = cpu_variant;
15585 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15586 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15587 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15588 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15589 if (!opcode->tvariant
15590 || (thumb_mode == 1
15591 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15592 {
c19d1205 15593 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
15594 return;
15595 }
c19d1205
ZW
15596 if (inst.cond != COND_ALWAYS && !unified_syntax
15597 && opcode->tencode != do_t_branch)
b99bd4ef 15598 {
c19d1205 15599 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15600 return;
15601 }
15602
752d5da4 15603 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15604 {
7e806470 15605 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15606 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15607 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15608 {
15609 /* Two things are addressed here.
15610 1) Implicit require narrow instructions on Thumb-1.
15611 This avoids relaxation accidentally introducing Thumb-2
15612 instructions.
15613 2) Reject wide instructions in non Thumb-2 cores. */
15614 if (inst.size_req == 0)
15615 inst.size_req = 2;
15616 else if (inst.size_req == 4)
15617 {
15618 as_bad (_("selected processor does not support `%s'"), str);
15619 return;
15620 }
15621 }
076d447c
PB
15622 }
15623
c19d1205
ZW
15624 inst.instruction = opcode->tvalue;
15625
15626 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15627 {
15628 /* Prepare the it_insn_type for those encodings that don't set
15629 it. */
15630 it_fsm_pre_encode ();
c19d1205 15631
e07e6e58
NC
15632 opcode->tencode ();
15633
15634 it_fsm_post_encode ();
15635 }
e27ec89e 15636
0110f2b8 15637 if (!(inst.error || inst.relax))
b99bd4ef 15638 {
9c2799c2 15639 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15640 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15641 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15642 {
c19d1205 15643 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15644 return;
15645 }
15646 }
076d447c
PB
15647
15648 /* Something has gone badly wrong if we try to relax a fixed size
15649 instruction. */
9c2799c2 15650 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15651
e74cfd16
PB
15652 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15653 *opcode->tvariant);
ee065d83 15654 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15655 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15656 anything other than bl/blx and v6-M instructions.
ee065d83 15657 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15658 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15659 || inst.relax)
e07e6e58
NC
15660 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15661 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15662 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15663 arm_ext_v6t2);
cd000bff 15664
88714cb8
DG
15665 check_neon_suffixes;
15666
cd000bff 15667 if (!inst.error)
c877a2f2
NC
15668 {
15669 mapping_state (MAP_THUMB);
15670 }
c19d1205 15671 }
3e9e4fcf 15672 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15673 {
845b51d6
PB
15674 bfd_boolean is_bx;
15675
15676 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15677 is_bx = (opcode->aencode == do_bx);
15678
c19d1205 15679 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15680 if (!(is_bx && fix_v4bx)
15681 && !(opcode->avariant &&
15682 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15683 {
c19d1205
ZW
15684 as_bad (_("selected processor does not support `%s'"), str);
15685 return;
b99bd4ef 15686 }
c19d1205 15687 if (inst.size_req)
b99bd4ef 15688 {
c19d1205
ZW
15689 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15690 return;
b99bd4ef
NC
15691 }
15692
c19d1205
ZW
15693 inst.instruction = opcode->avalue;
15694 if (opcode->tag == OT_unconditionalF)
15695 inst.instruction |= 0xF << 28;
15696 else
15697 inst.instruction |= inst.cond << 28;
15698 inst.size = INSN_SIZE;
15699 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15700 {
15701 it_fsm_pre_encode ();
15702 opcode->aencode ();
15703 it_fsm_post_encode ();
15704 }
ee065d83
PB
15705 /* Arm mode bx is marked as both v4T and v5 because it's still required
15706 on a hypothetical non-thumb v5 core. */
845b51d6 15707 if (is_bx)
e74cfd16 15708 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15709 else
e74cfd16
PB
15710 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15711 *opcode->avariant);
88714cb8
DG
15712
15713 check_neon_suffixes;
15714
cd000bff 15715 if (!inst.error)
c877a2f2
NC
15716 {
15717 mapping_state (MAP_ARM);
15718 }
b99bd4ef 15719 }
3e9e4fcf
JB
15720 else
15721 {
15722 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15723 "-- `%s'"), str);
15724 return;
15725 }
c19d1205
ZW
15726 output_inst (str);
15727}
b99bd4ef 15728
e07e6e58
NC
15729static void
15730check_it_blocks_finished (void)
15731{
15732#ifdef OBJ_ELF
15733 asection *sect;
15734
15735 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15736 if (seg_info (sect)->tc_segment_info_data.current_it.state
15737 == MANUAL_IT_BLOCK)
15738 {
15739 as_warn (_("section '%s' finished with an open IT block."),
15740 sect->name);
15741 }
15742#else
15743 if (now_it.state == MANUAL_IT_BLOCK)
15744 as_warn (_("file finished with an open IT block."));
15745#endif
15746}
15747
c19d1205
ZW
15748/* Various frobbings of labels and their addresses. */
15749
15750void
15751arm_start_line_hook (void)
15752{
15753 last_label_seen = NULL;
b99bd4ef
NC
15754}
15755
c19d1205
ZW
15756void
15757arm_frob_label (symbolS * sym)
b99bd4ef 15758{
c19d1205 15759 last_label_seen = sym;
b99bd4ef 15760
c19d1205 15761 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15762
c19d1205
ZW
15763#if defined OBJ_COFF || defined OBJ_ELF
15764 ARM_SET_INTERWORK (sym, support_interwork);
15765#endif
b99bd4ef 15766
e07e6e58
NC
15767 force_automatic_it_block_close ();
15768
5f4273c7 15769 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15770 as Thumb functions. This is because these labels, whilst
15771 they exist inside Thumb code, are not the entry points for
15772 possible ARM->Thumb calls. Also, these labels can be used
15773 as part of a computed goto or switch statement. eg gcc
15774 can generate code that looks like this:
b99bd4ef 15775
c19d1205
ZW
15776 ldr r2, [pc, .Laaa]
15777 lsl r3, r3, #2
15778 ldr r2, [r3, r2]
15779 mov pc, r2
b99bd4ef 15780
c19d1205
ZW
15781 .Lbbb: .word .Lxxx
15782 .Lccc: .word .Lyyy
15783 ..etc...
15784 .Laaa: .word Lbbb
b99bd4ef 15785
c19d1205
ZW
15786 The first instruction loads the address of the jump table.
15787 The second instruction converts a table index into a byte offset.
15788 The third instruction gets the jump address out of the table.
15789 The fourth instruction performs the jump.
b99bd4ef 15790
c19d1205
ZW
15791 If the address stored at .Laaa is that of a symbol which has the
15792 Thumb_Func bit set, then the linker will arrange for this address
15793 to have the bottom bit set, which in turn would mean that the
15794 address computation performed by the third instruction would end
15795 up with the bottom bit set. Since the ARM is capable of unaligned
15796 word loads, the instruction would then load the incorrect address
15797 out of the jump table, and chaos would ensue. */
15798 if (label_is_thumb_function_name
15799 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15800 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15801 {
c19d1205
ZW
15802 /* When the address of a Thumb function is taken the bottom
15803 bit of that address should be set. This will allow
15804 interworking between Arm and Thumb functions to work
15805 correctly. */
b99bd4ef 15806
c19d1205 15807 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15808
c19d1205 15809 label_is_thumb_function_name = FALSE;
b99bd4ef 15810 }
07a53e5c 15811
07a53e5c 15812 dwarf2_emit_label (sym);
b99bd4ef
NC
15813}
15814
c921be7d 15815bfd_boolean
c19d1205 15816arm_data_in_code (void)
b99bd4ef 15817{
c19d1205 15818 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15819 {
c19d1205
ZW
15820 *input_line_pointer = '/';
15821 input_line_pointer += 5;
15822 *input_line_pointer = 0;
c921be7d 15823 return TRUE;
b99bd4ef
NC
15824 }
15825
c921be7d 15826 return FALSE;
b99bd4ef
NC
15827}
15828
c19d1205
ZW
15829char *
15830arm_canonicalize_symbol_name (char * name)
b99bd4ef 15831{
c19d1205 15832 int len;
b99bd4ef 15833
c19d1205
ZW
15834 if (thumb_mode && (len = strlen (name)) > 5
15835 && streq (name + len - 5, "/data"))
15836 *(name + len - 5) = 0;
b99bd4ef 15837
c19d1205 15838 return name;
b99bd4ef 15839}
c19d1205
ZW
15840\f
15841/* Table of all register names defined by default. The user can
15842 define additional names with .req. Note that all register names
15843 should appear in both upper and lowercase variants. Some registers
15844 also have mixed-case names. */
b99bd4ef 15845
dcbf9037 15846#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15847#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15848#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15849#define REGSET(p,t) \
15850 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15851 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15852 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15853 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15854#define REGSETH(p,t) \
15855 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15856 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15857 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15858 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15859#define REGSET2(p,t) \
15860 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15861 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15862 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15863 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15864
c19d1205 15865static const struct reg_entry reg_names[] =
7ed4c4c5 15866{
c19d1205
ZW
15867 /* ARM integer registers. */
15868 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15869
c19d1205
ZW
15870 /* ATPCS synonyms. */
15871 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15872 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15873 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 15874
c19d1205
ZW
15875 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15876 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15877 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 15878
c19d1205
ZW
15879 /* Well-known aliases. */
15880 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15881 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15882
15883 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15884 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15885
15886 /* Coprocessor numbers. */
15887 REGSET(p, CP), REGSET(P, CP),
15888
15889 /* Coprocessor register numbers. The "cr" variants are for backward
15890 compatibility. */
15891 REGSET(c, CN), REGSET(C, CN),
15892 REGSET(cr, CN), REGSET(CR, CN),
15893
15894 /* FPA registers. */
15895 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15896 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15897
15898 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15899 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15900
15901 /* VFP SP registers. */
5287ad62
JB
15902 REGSET(s,VFS), REGSET(S,VFS),
15903 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15904
15905 /* VFP DP Registers. */
5287ad62
JB
15906 REGSET(d,VFD), REGSET(D,VFD),
15907 /* Extra Neon DP registers. */
15908 REGSETH(d,VFD), REGSETH(D,VFD),
15909
15910 /* Neon QP registers. */
15911 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15912
15913 /* VFP control registers. */
15914 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15915 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15916 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15917 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15918 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15919 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15920
15921 /* Maverick DSP coprocessor registers. */
15922 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15923 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15924
15925 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15926 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15927 REGDEF(dspsc,0,DSPSC),
15928
15929 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15930 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15931 REGDEF(DSPSC,0,DSPSC),
15932
15933 /* iWMMXt data registers - p0, c0-15. */
15934 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15935
15936 /* iWMMXt control registers - p1, c0-3. */
15937 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15938 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15939 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15940 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15941
15942 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15943 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15944 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15945 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15946 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15947
15948 /* XScale accumulator registers. */
15949 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15950};
15951#undef REGDEF
15952#undef REGNUM
15953#undef REGSET
7ed4c4c5 15954
c19d1205
ZW
15955/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15956 within psr_required_here. */
15957static const struct asm_psr psrs[] =
15958{
15959 /* Backward compatibility notation. Note that "all" is no longer
15960 truly all possible PSR bits. */
15961 {"all", PSR_c | PSR_f},
15962 {"flg", PSR_f},
15963 {"ctl", PSR_c},
15964
15965 /* Individual flags. */
15966 {"f", PSR_f},
15967 {"c", PSR_c},
15968 {"x", PSR_x},
15969 {"s", PSR_s},
15970 /* Combinations of flags. */
15971 {"fs", PSR_f | PSR_s},
15972 {"fx", PSR_f | PSR_x},
15973 {"fc", PSR_f | PSR_c},
15974 {"sf", PSR_s | PSR_f},
15975 {"sx", PSR_s | PSR_x},
15976 {"sc", PSR_s | PSR_c},
15977 {"xf", PSR_x | PSR_f},
15978 {"xs", PSR_x | PSR_s},
15979 {"xc", PSR_x | PSR_c},
15980 {"cf", PSR_c | PSR_f},
15981 {"cs", PSR_c | PSR_s},
15982 {"cx", PSR_c | PSR_x},
15983 {"fsx", PSR_f | PSR_s | PSR_x},
15984 {"fsc", PSR_f | PSR_s | PSR_c},
15985 {"fxs", PSR_f | PSR_x | PSR_s},
15986 {"fxc", PSR_f | PSR_x | PSR_c},
15987 {"fcs", PSR_f | PSR_c | PSR_s},
15988 {"fcx", PSR_f | PSR_c | PSR_x},
15989 {"sfx", PSR_s | PSR_f | PSR_x},
15990 {"sfc", PSR_s | PSR_f | PSR_c},
15991 {"sxf", PSR_s | PSR_x | PSR_f},
15992 {"sxc", PSR_s | PSR_x | PSR_c},
15993 {"scf", PSR_s | PSR_c | PSR_f},
15994 {"scx", PSR_s | PSR_c | PSR_x},
15995 {"xfs", PSR_x | PSR_f | PSR_s},
15996 {"xfc", PSR_x | PSR_f | PSR_c},
15997 {"xsf", PSR_x | PSR_s | PSR_f},
15998 {"xsc", PSR_x | PSR_s | PSR_c},
15999 {"xcf", PSR_x | PSR_c | PSR_f},
16000 {"xcs", PSR_x | PSR_c | PSR_s},
16001 {"cfs", PSR_c | PSR_f | PSR_s},
16002 {"cfx", PSR_c | PSR_f | PSR_x},
16003 {"csf", PSR_c | PSR_s | PSR_f},
16004 {"csx", PSR_c | PSR_s | PSR_x},
16005 {"cxf", PSR_c | PSR_x | PSR_f},
16006 {"cxs", PSR_c | PSR_x | PSR_s},
16007 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16008 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16009 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16010 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16011 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16012 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16013 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16014 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16015 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16016 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16017 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16018 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16019 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16020 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16021 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16022 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16023 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16024 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16025 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16026 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16027 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16028 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16029 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16030 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16031};
16032
62b3e311
PB
16033/* Table of V7M psr names. */
16034static const struct asm_psr v7m_psrs[] =
16035{
2b744c99
PB
16036 {"apsr", 0 }, {"APSR", 0 },
16037 {"iapsr", 1 }, {"IAPSR", 1 },
16038 {"eapsr", 2 }, {"EAPSR", 2 },
16039 {"psr", 3 }, {"PSR", 3 },
16040 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16041 {"ipsr", 5 }, {"IPSR", 5 },
16042 {"epsr", 6 }, {"EPSR", 6 },
16043 {"iepsr", 7 }, {"IEPSR", 7 },
16044 {"msp", 8 }, {"MSP", 8 },
16045 {"psp", 9 }, {"PSP", 9 },
16046 {"primask", 16}, {"PRIMASK", 16},
16047 {"basepri", 17}, {"BASEPRI", 17},
16048 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16049 {"faultmask", 19}, {"FAULTMASK", 19},
16050 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16051};
16052
c19d1205
ZW
16053/* Table of all shift-in-operand names. */
16054static const struct asm_shift_name shift_names [] =
b99bd4ef 16055{
c19d1205
ZW
16056 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16057 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16058 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16059 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16060 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16061 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16062};
b99bd4ef 16063
c19d1205
ZW
16064/* Table of all explicit relocation names. */
16065#ifdef OBJ_ELF
16066static struct reloc_entry reloc_names[] =
16067{
16068 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16069 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16070 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16071 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16072 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16073 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16074 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16075 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16076 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16077 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16078 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
16079};
16080#endif
b99bd4ef 16081
c19d1205
ZW
16082/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16083static const struct asm_cond conds[] =
16084{
16085 {"eq", 0x0},
16086 {"ne", 0x1},
16087 {"cs", 0x2}, {"hs", 0x2},
16088 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16089 {"mi", 0x4},
16090 {"pl", 0x5},
16091 {"vs", 0x6},
16092 {"vc", 0x7},
16093 {"hi", 0x8},
16094 {"ls", 0x9},
16095 {"ge", 0xa},
16096 {"lt", 0xb},
16097 {"gt", 0xc},
16098 {"le", 0xd},
16099 {"al", 0xe}
16100};
bfae80f2 16101
62b3e311
PB
16102static struct asm_barrier_opt barrier_opt_names[] =
16103{
16104 { "sy", 0xf },
16105 { "un", 0x7 },
16106 { "st", 0xe },
16107 { "unst", 0x6 }
16108};
16109
c19d1205
ZW
16110/* Table of ARM-format instructions. */
16111
16112/* Macros for gluing together operand strings. N.B. In all cases
16113 other than OPS0, the trailing OP_stop comes from default
16114 zero-initialization of the unspecified elements of the array. */
16115#define OPS0() { OP_stop, }
16116#define OPS1(a) { OP_##a, }
16117#define OPS2(a,b) { OP_##a,OP_##b, }
16118#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16119#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16120#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16121#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16122
16123/* These macros abstract out the exact format of the mnemonic table and
16124 save some repeated characters. */
16125
16126/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16127#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16128 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16129 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16130
16131/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16132 a T_MNEM_xyz enumerator. */
16133#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16134 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16135#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16136 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16137
16138/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16139 infix after the third character. */
16140#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16141 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16142 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16143#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16144 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16145 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16146#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16147 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16148#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16149 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16150#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16151 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16152#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16153 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16154
16155/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16156 appear in the condition table. */
16157#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16158 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16159 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16160
16161#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16162 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16163 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16164 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16165 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16166 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16167 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16168 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16169 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16170 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16171 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16172 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16173 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16174 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16175 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16176 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16177 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16178 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16179 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16180 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16181
16182#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16183 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16184#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16185 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16186
16187/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16188 field is still 0xE. Many of the Thumb variants can be executed
16189 conditionally, so this is checked separately. */
c19d1205 16190#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16191 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16192 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16193
16194/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16195 condition code field. */
16196#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16197 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16198 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16199
16200/* ARM-only variants of all the above. */
6a86118a 16201#define CE(mnem, op, nops, ops, ae) \
21d799b5 16202 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16203
16204#define C3(mnem, op, nops, ops, ae) \
16205 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16206
e3cb604e
PB
16207/* Legacy mnemonics that always have conditional infix after the third
16208 character. */
16209#define CL(mnem, op, nops, ops, ae) \
21d799b5 16210 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16211 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16212
8f06b2d8
PB
16213/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16214#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16215 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16216
e3cb604e
PB
16217/* Legacy coprocessor instructions where conditional infix and conditional
16218 suffix are ambiguous. For consistency this includes all FPA instructions,
16219 not just the potentially ambiguous ones. */
16220#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16221 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16222 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16223
16224/* Coprocessor, takes either a suffix or a position-3 infix
16225 (for an FPA corner case). */
16226#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16227 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16228 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16229
6a86118a 16230#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16231 { m1 #m2 m3, OPS##nops ops, \
16232 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16233 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16234
16235#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16236 xCM_ (m1, , m2, op, nops, ops, ae), \
16237 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16238 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16239 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16240 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16241 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16242 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16243 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16244 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16245 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16246 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16247 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16248 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16249 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16250 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16251 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16252 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16253 xCM_ (m1, le, m2, op, nops, ops, ae), \
16254 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16255
16256#define UE(mnem, op, nops, ops, ae) \
16257 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16258
16259#define UF(mnem, op, nops, ops, ae) \
16260 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16261
5287ad62
JB
16262/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16263 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16264 use the same encoding function for each. */
16265#define NUF(mnem, op, nops, ops, enc) \
16266 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16267 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16268
16269/* Neon data processing, version which indirects through neon_enc_tab for
16270 the various overloaded versions of opcodes. */
16271#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16272 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16273 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16274
16275/* Neon insn with conditional suffix for the ARM version, non-overloaded
16276 version. */
037e8744
JB
16277#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16278 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16279 THUMB_VARIANT, do_##enc, do_##enc }
16280
037e8744 16281#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16282 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16283
16284#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16285 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16286
5287ad62 16287/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16288#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16289 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16290 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16291
037e8744 16292#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16293 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16294
16295#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16296 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16297
c19d1205
ZW
16298#define do_0 0
16299
16300/* Thumb-only, unconditional. */
e07e6e58 16301#define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
c19d1205 16302
c19d1205 16303static const struct asm_opcode insns[] =
bfae80f2 16304{
e74cfd16
PB
16305#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16306#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16307 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16308 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16309 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16310 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16311 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16312 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16313 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16314 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16315 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16316 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16317 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16318 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16319 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16320 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16321 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16322 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16323
16324 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16325 for setting PSR flag bits. They are obsolete in V6 and do not
16326 have Thumb equivalents. */
21d799b5
NC
16327 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16328 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16329 CL("tstp", 110f000, 2, (RR, SH), cmp),
16330 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16331 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16332 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16333 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16334 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16335 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16336
16337 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16338 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16339 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16340 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16341
16342 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16343 tC3("ldrb", 4500000, _ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16344 tCE("str", 4000000, _str, 2, (RR, ADDRGLDR),ldst, t_ldst),
16345 tC3("strb", 4400000, _strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16346
16347 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16348 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16349 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16350 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16351 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16352 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16353
16354 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16355 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16356 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16357 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16358
c19d1205 16359 /* Pseudo ops. */
21d799b5 16360 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16361 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16362 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16363
16364 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16365 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16366 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16367 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16368 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16369 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16370 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16371 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16372 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16373 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16374 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16375 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16376 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16377
16a4cf17 16378 /* These may simplify to neg. */
21d799b5
NC
16379 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16380 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16381
c921be7d
NC
16382#undef THUMB_VARIANT
16383#define THUMB_VARIANT & arm_ext_v6
16384
21d799b5 16385 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16386
16387 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16388#undef THUMB_VARIANT
16389#define THUMB_VARIANT & arm_ext_v6t2
16390
21d799b5
NC
16391 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16392 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16393 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16394
21d799b5
NC
16395 TC3("ldrt", 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
16396 TC3("ldrbt", 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
16397 TC3("strt", 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
16398 TC3("strbt", 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 16399
21d799b5
NC
16400 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16401 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16402
21d799b5
NC
16403 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16404 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16405
16406 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16407 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16408 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16409
16410 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16411 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16412 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16413 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16414 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16415 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16416 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16417 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16418
c921be7d
NC
16419#undef ARM_VARIANT
16420#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16421#undef THUMB_VARIANT
16422#define THUMB_VARIANT & arm_ext_v4t
16423
21d799b5
NC
16424 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16425 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16426
c921be7d
NC
16427#undef THUMB_VARIANT
16428#define THUMB_VARIANT & arm_ext_v6t2
16429
21d799b5 16430 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16431 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16432
16433 /* Generic coprocessor instructions. */
21d799b5
NC
16434 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16435 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16436 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16437 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16438 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16439 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16440 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16441
c921be7d
NC
16442#undef ARM_VARIANT
16443#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16444
21d799b5 16445 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16446 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16447
c921be7d
NC
16448#undef ARM_VARIANT
16449#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16450#undef THUMB_VARIANT
16451#define THUMB_VARIANT & arm_ext_msr
16452
21d799b5
NC
16453 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16454 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16455
c921be7d
NC
16456#undef ARM_VARIANT
16457#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16458#undef THUMB_VARIANT
16459#define THUMB_VARIANT & arm_ext_v6t2
16460
21d799b5
NC
16461 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16462 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16463 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16464 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16465 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16466 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16467 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16468 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16469
c921be7d
NC
16470#undef ARM_VARIANT
16471#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16472#undef THUMB_VARIANT
16473#define THUMB_VARIANT & arm_ext_v4t
16474
21d799b5
NC
16475 tC3("ldrh", 01000b0, _ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16476 tC3("strh", 00000b0, _strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16477 tC3("ldrsh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16478 tC3("ldrsb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16479 tCM("ld","sh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16480 tCM("ld","sb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16481
c921be7d
NC
16482#undef ARM_VARIANT
16483#define ARM_VARIANT & arm_ext_v4t_5
16484
c19d1205
ZW
16485 /* ARM Architecture 4T. */
16486 /* Note: bx (and blx) are required on V5, even if the processor does
16487 not support Thumb. */
21d799b5 16488 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16489
c921be7d
NC
16490#undef ARM_VARIANT
16491#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16492#undef THUMB_VARIANT
16493#define THUMB_VARIANT & arm_ext_v5t
16494
c19d1205
ZW
16495 /* Note: blx has 2 variants; the .value coded here is for
16496 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16497 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16498 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16499
c921be7d
NC
16500#undef THUMB_VARIANT
16501#define THUMB_VARIANT & arm_ext_v6t2
16502
21d799b5
NC
16503 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16504 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16505 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16506 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16507 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16508 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16509 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16510 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16511
c921be7d
NC
16512#undef ARM_VARIANT
16513#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16514#undef THUMB_VARIANT
16515#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16516
21d799b5
NC
16517 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16518 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16519 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16520 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16521
21d799b5
NC
16522 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16523 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16524
21d799b5
NC
16525 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16526 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16527 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16528 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16529
21d799b5
NC
16530 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16531 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16532 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16533 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16534
21d799b5
NC
16535 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16536 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16537
03ee1b7f
NC
16538 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16539 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16540 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16541 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16542
c921be7d
NC
16543#undef ARM_VARIANT
16544#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16545#undef THUMB_VARIANT
16546#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16547
21d799b5
NC
16548 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16549 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16550 TC3("strd", 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16551
21d799b5
NC
16552 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16553 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16554
c921be7d
NC
16555#undef ARM_VARIANT
16556#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16557
21d799b5 16558 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16559
c921be7d
NC
16560#undef ARM_VARIANT
16561#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16562#undef THUMB_VARIANT
16563#define THUMB_VARIANT & arm_ext_v6
16564
21d799b5
NC
16565 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16566 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16567 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16568 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16569 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16570 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16571 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16572 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16573 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16574 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16575
c921be7d
NC
16576#undef THUMB_VARIANT
16577#define THUMB_VARIANT & arm_ext_v6t2
16578
21d799b5
NC
16579 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
16580 TCE("strex", 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
16581 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16582 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16583
21d799b5
NC
16584 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16585 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16586
9e3c6df6 16587/* ARM V6 not included in V7M. */
c921be7d
NC
16588#undef THUMB_VARIANT
16589#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16590 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16591 UF(rfeib, 9900a00, 1, (RRw), rfe),
16592 UF(rfeda, 8100a00, 1, (RRw), rfe),
16593 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16594 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16595 UF(rfefa, 9900a00, 1, (RRw), rfe),
16596 UF(rfeea, 8100a00, 1, (RRw), rfe),
16597 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16598 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16599 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16600 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16601 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16602
9e3c6df6
PB
16603/* ARM V6 not included in V7M (eg. integer SIMD). */
16604#undef THUMB_VARIANT
16605#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16606 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16607 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16608 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16609 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16610 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16611 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16612 /* Old name for QASX. */
21d799b5
NC
16613 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16614 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16615 /* Old name for QSAX. */
21d799b5
NC
16616 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16617 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16618 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16619 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16620 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16621 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16622 /* Old name for SASX. */
21d799b5
NC
16623 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16624 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16625 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16626 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16627 /* Old name for SHASX. */
21d799b5
NC
16628 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16629 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16630 /* Old name for SHSAX. */
21d799b5
NC
16631 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16632 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16633 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16634 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16635 /* Old name for SSAX. */
21d799b5
NC
16636 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16637 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16638 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16639 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16640 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16641 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16642 /* Old name for UASX. */
21d799b5
NC
16643 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16644 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16645 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16646 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16647 /* Old name for UHASX. */
21d799b5
NC
16648 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16649 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16650 /* Old name for UHSAX. */
21d799b5
NC
16651 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16652 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16653 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16654 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16655 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16656 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16657 /* Old name for UQASX. */
21d799b5
NC
16658 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16659 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16660 /* Old name for UQSAX. */
21d799b5
NC
16661 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16662 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16663 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16664 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16665 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16666 /* Old name for USAX. */
21d799b5
NC
16667 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16668 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16669 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16670 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16671 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16672 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16673 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16674 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16675 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16676 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16677 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16678 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16679 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16680 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16681 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16682 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16683 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16684 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16685 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16686 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16687 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16688 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16689 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16690 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16691 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16692 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16693 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16694 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16695 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
16696 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16697 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16698 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16699 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16700 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 16701
c921be7d
NC
16702#undef ARM_VARIANT
16703#define ARM_VARIANT & arm_ext_v6k
16704#undef THUMB_VARIANT
16705#define THUMB_VARIANT & arm_ext_v6k
16706
21d799b5
NC
16707 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16708 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16709 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16710 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 16711
c921be7d
NC
16712#undef THUMB_VARIANT
16713#define THUMB_VARIANT & arm_ext_v6_notm
16714
21d799b5
NC
16715 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
16716 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
ebdca51a 16717
c921be7d
NC
16718#undef THUMB_VARIANT
16719#define THUMB_VARIANT & arm_ext_v6t2
16720
21d799b5
NC
16721 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16722 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16723 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16724 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16725 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 16726
c921be7d
NC
16727#undef ARM_VARIANT
16728#define ARM_VARIANT & arm_ext_v6z
16729
21d799b5 16730 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 16731
c921be7d
NC
16732#undef ARM_VARIANT
16733#define ARM_VARIANT & arm_ext_v6t2
16734
21d799b5
NC
16735 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16736 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16737 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16738 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 16739
21d799b5
NC
16740 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16741 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16742 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16743 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 16744
21d799b5
NC
16745 TC3("ldrht", 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16746 TC3("ldrsht", 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16747 TC3("ldrsbt", 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16748 TC3("strht", 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
c19d1205 16749
21d799b5
NC
16750 UT("cbnz", b900, 2, (RR, EXP), t_cbz),
16751 UT("cbz", b100, 2, (RR, EXP), t_cbz),
c921be7d
NC
16752
16753 /* ARM does not really have an IT instruction, so always allow it.
16754 The opcode is copied from Thumb in order to allow warnings in
16755 -mimplicit-it=[never | arm] modes. */
16756#undef ARM_VARIANT
16757#define ARM_VARIANT & arm_ext_v1
16758
21d799b5
NC
16759 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16760 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16761 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16762 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16763 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16764 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16765 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16766 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16767 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16768 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16769 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16770 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16771 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16772 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16773 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 16774 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
16775 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16776 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16777
92e90b6e 16778 /* Thumb2 only instructions. */
c921be7d
NC
16779#undef ARM_VARIANT
16780#define ARM_VARIANT NULL
92e90b6e 16781
21d799b5
NC
16782 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16783 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16784 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16785 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16786 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16787 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 16788
62b3e311 16789 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
16790#undef THUMB_VARIANT
16791#define THUMB_VARIANT & arm_ext_div
16792
21d799b5
NC
16793 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16794 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 16795
7e806470 16796 /* ARM V6M/V7 instructions. */
c921be7d
NC
16797#undef ARM_VARIANT
16798#define ARM_VARIANT & arm_ext_barrier
16799#undef THUMB_VARIANT
16800#define THUMB_VARIANT & arm_ext_barrier
16801
21d799b5
NC
16802 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16803 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16804 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
7e806470 16805
62b3e311 16806 /* ARM V7 instructions. */
c921be7d
NC
16807#undef ARM_VARIANT
16808#define ARM_VARIANT & arm_ext_v7
16809#undef THUMB_VARIANT
16810#define THUMB_VARIANT & arm_ext_v7
16811
21d799b5
NC
16812 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16813 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16814
c921be7d
NC
16815#undef ARM_VARIANT
16816#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16817
21d799b5
NC
16818 cCE("wfs", e200110, 1, (RR), rd),
16819 cCE("rfs", e300110, 1, (RR), rd),
16820 cCE("wfc", e400110, 1, (RR), rd),
16821 cCE("rfc", e500110, 1, (RR), rd),
16822
16823 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16824 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16825 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16826 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16827
16828 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16829 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16830 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16831 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16832
16833 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16834 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16835 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16836 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16837 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16838 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16839 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16840 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16841 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16842 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16843 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16844 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16845
16846 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16847 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16848 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16849 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16850 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
16851 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
16852 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
16853 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
16854 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
16855 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
16856 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
16857 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
16858
16859 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
16860 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
16861 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
16862 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
16863 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
16864 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
16865 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
16866 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
16867 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
16868 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
16869 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
16870 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
16871
16872 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
16873 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
16874 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
16875 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
16876 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
16877 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
16878 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
16879 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
16880 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
16881 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
16882 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
16883 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
16884
16885 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
16886 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
16887 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
16888 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
16889 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
16890 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
16891 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
16892 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
16893 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
16894 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
16895 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
16896 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
16897
16898 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
16899 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
16900 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
16901 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
16902 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
16903 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
16904 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
16905 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
16906 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
16907 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
16908 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
16909 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
16910
16911 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
16912 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
16913 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
16914 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
16915 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
16916 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
16917 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
16918 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
16919 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
16920 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
16921 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
16922 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
16923
16924 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
16925 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
16926 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
16927 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
16928 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
16929 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
16930 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
16931 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
16932 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
16933 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
16934 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
16935 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
16936
16937 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
16938 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
16939 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
16940 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
16941 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
16942 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
16943 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
16944 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
16945 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
16946 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
16947 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
16948 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
16949
16950 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
16951 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
16952 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
16953 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
16954 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
16955 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
16956 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
16957 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
16958 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
16959 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
16960 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
16961 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
16962
16963 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
16964 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
16965 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
16966 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
16967 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
16968 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
16969 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
16970 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
16971 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
16972 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
16973 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
16974 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
16975
16976 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
16977 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
16978 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
16979 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
16980 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
16981 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
16982 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
16983 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
16984 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
16985 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
16986 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
16987 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
16988
16989 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
16990 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
16991 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
16992 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
16993 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
16994 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
16995 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
16996 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
16997 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
16998 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
16999 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17000 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17001
17002 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17003 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17004 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17005 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17006 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17007 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17008 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17009 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17010 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17011 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17012 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17013 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17014
17015 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17016 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17017 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17018 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17019 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17020 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17021 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17022 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17023 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17024 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17025 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17026 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17027
17028 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17029 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17030 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17031 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17032 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17033 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17034 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17035 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17036 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17037 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17038 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17039 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17040
17041 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17042 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17043 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17044 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17045 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17046 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17047 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17048 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17049 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17050 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17051 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17052 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17053
17054 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17055 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17056 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17057 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17058 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17059 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17060 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17061 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17062 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17063 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17064 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17065 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17066
17067 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17068 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17069 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17070 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17071 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17072 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17073 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17074 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17075 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17076 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17077 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17078 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17079
17080 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17081 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17082 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17083 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17084 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17085 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17086 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17087 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17088 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17089 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17090 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17091 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17092
17093 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17094 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17095 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17096 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17097 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17098 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17099 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17100 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17101 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17102 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17103 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17104 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17105
17106 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17107 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17108 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17109 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17110 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17111 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17112 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17113 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17114 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17115 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17116 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17117 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17118
17119 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17120 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17121 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17122 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17123 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17124 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17125 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17126 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17127 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17128 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17129 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17130 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17131
17132 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17133 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17134 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17135 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17136 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17137 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17138 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17139 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17140 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17141 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17142 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17143 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17144
17145 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17146 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17147 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17148 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17149 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17150 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17151 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17152 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17153 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17154 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17155 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17156 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17157
17158 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17159 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17160 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17161 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17162 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17163 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17164 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17165 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17166 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17167 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17168 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17169 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17170
17171 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17172 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17173 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17174 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17175 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17176 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17177 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17178 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17179 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17180 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17181 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17182 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17183
17184 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17185 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17186 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17187 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17188 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17189 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17190 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17191 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17192 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17193 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17194 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17195 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17196
17197 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17198 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17199 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17200 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17202 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17203 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17204 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17205 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17207 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17208 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17209
17210 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17211 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17212 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17213 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17214
17215 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17216 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17217 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17218 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17219 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17220 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17221 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17222 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17223 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17224 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17225 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17226 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17227
c19d1205
ZW
17228 /* The implementation of the FIX instruction is broken on some
17229 assemblers, in that it accepts a precision specifier as well as a
17230 rounding specifier, despite the fact that this is meaningless.
17231 To be more compatible, we accept it as well, though of course it
17232 does not set any bits. */
21d799b5
NC
17233 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17234 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17235 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17236 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17237 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17238 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17239 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17240 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17241 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17242 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17243 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17244 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17245 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17246
c19d1205 17247 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17248#undef ARM_VARIANT
17249#define ARM_VARIANT & fpu_fpa_ext_v2
17250
21d799b5
NC
17251 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17252 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17253 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17254 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17255 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17256 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17257
c921be7d
NC
17258#undef ARM_VARIANT
17259#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17260
c19d1205 17261 /* Moves and type conversions. */
21d799b5
NC
17262 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17263 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17264 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17265 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17266 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17267 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17268 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17269 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17270 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17271 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17272 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17273 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17274 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17275 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17276
17277 /* Memory operations. */
21d799b5
NC
17278 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17279 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17280 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17281 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17282 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17283 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17284 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17285 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17286 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17287 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17288 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17289 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17290 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17291 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17292 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17293 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17294 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17295 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17296
c19d1205 17297 /* Monadic operations. */
21d799b5
NC
17298 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17299 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17300 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17301
17302 /* Dyadic operations. */
21d799b5
NC
17303 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17304 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17305 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17306 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17307 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17308 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17309 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17310 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17311 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17312
c19d1205 17313 /* Comparisons. */
21d799b5
NC
17314 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17315 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17316 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17317 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17318
62f3b8c8
PB
17319 /* Double precision load/store are still present on single precision
17320 implementations. */
17321 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17322 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17323 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17324 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17325 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17326 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17327 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17328 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17329 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17330 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17331
c921be7d
NC
17332#undef ARM_VARIANT
17333#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17334
c19d1205 17335 /* Moves and type conversions. */
21d799b5
NC
17336 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17337 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17338 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17339 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17340 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17341 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17342 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17343 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17344 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17345 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17346 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17347 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17348 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17349
c19d1205 17350 /* Monadic operations. */
21d799b5
NC
17351 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17352 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17353 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17354
17355 /* Dyadic operations. */
21d799b5
NC
17356 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17357 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17358 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17359 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17360 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17361 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17362 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17363 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17364 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17365
c19d1205 17366 /* Comparisons. */
21d799b5
NC
17367 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17368 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17369 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17370 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17371
c921be7d
NC
17372#undef ARM_VARIANT
17373#define ARM_VARIANT & fpu_vfp_ext_v2
17374
21d799b5
NC
17375 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17376 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17377 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17378 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17379
037e8744
JB
17380/* Instructions which may belong to either the Neon or VFP instruction sets.
17381 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17382#undef ARM_VARIANT
17383#define ARM_VARIANT & fpu_vfp_ext_v1xd
17384#undef THUMB_VARIANT
17385#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17386
037e8744
JB
17387 /* These mnemonics are unique to VFP. */
17388 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17389 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17390 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17391 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17392 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17393 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17394 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17395 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17396 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17397 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17398
17399 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17400 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17401 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17402 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17403
21d799b5
NC
17404 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17405 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17406
17407 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17408 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17409
17410 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17411 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17412 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17413 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17414 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17415 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17416 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17417 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17418
21d799b5
NC
17419 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17420 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17421 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17422
037e8744
JB
17423
17424 /* NOTE: All VMOV encoding is special-cased! */
17425 NCE(vmov, 0, 1, (VMOV), neon_mov),
17426 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17427
c921be7d
NC
17428#undef THUMB_VARIANT
17429#define THUMB_VARIANT & fpu_neon_ext_v1
17430#undef ARM_VARIANT
17431#define ARM_VARIANT & fpu_neon_ext_v1
17432
5287ad62
JB
17433 /* Data processing with three registers of the same length. */
17434 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17435 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17436 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17437 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17438 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17439 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17440 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17441 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17442 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17443 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17444 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17445 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17446 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17447 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17448 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17449 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17450 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17451 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17452 /* If not immediate, fall back to neon_dyadic_i64_su.
17453 shl_imm should accept I8 I16 I32 I64,
17454 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17455 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17456 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17457 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17458 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17459 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17460 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17461 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17462 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17463 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17464 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17465 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17466 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17467 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17468 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17469 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17470 /* Bitfield ops, untyped. */
17471 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17472 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17473 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17474 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17475 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17476 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17477 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17478 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17479 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17480 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17481 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17482 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17483 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17484 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17485 back to neon_dyadic_if_su. */
21d799b5
NC
17486 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17487 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17488 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17489 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17490 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17491 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17492 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17493 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17494 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17495 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17496 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17497 /* As above, D registers only. */
21d799b5
NC
17498 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17499 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17500 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17501 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17502 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17503 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17504 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17505 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17506 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17507 /* vtst takes sizes 8, 16, 32. */
17508 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17509 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17510 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17511 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17512 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17513 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17514 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17515 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17516 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17517 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17518 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17519 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17520 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17521 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17522 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17523 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17524 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17525 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17526 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17527 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17528 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17529
17530 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17531 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17532 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17533
17534 /* Data processing with two registers and a shift amount. */
17535 /* Right shifts, and variants with rounding.
17536 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17537 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17538 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17539 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17540 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17541 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17542 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17543 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17544 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17545 /* Shift and insert. Sizes accepted 8 16 32 64. */
17546 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17547 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17548 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17549 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17550 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17551 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17552 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17553 /* Right shift immediate, saturating & narrowing, with rounding variants.
17554 Types accepted S16 S32 S64 U16 U32 U64. */
17555 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17556 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17557 /* As above, unsigned. Types accepted S16 S32 S64. */
17558 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17559 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17560 /* Right shift narrowing. Types accepted I16 I32 I64. */
17561 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17562 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17563 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17564 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17565 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17566 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17567
4316f0d2
DG
17568 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17569 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17570
17571 /* Data processing, three registers of different lengths. */
17572 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17573 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17574 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17575 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17576 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17577 /* If not scalar, fall back to neon_dyadic_long.
17578 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17579 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17580 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17581 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17582 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17583 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17584 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17585 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17586 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17587 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17588 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17589 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17590 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17591 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17592 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17593 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17594 S16 S32 U16 U32. */
21d799b5 17595 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17596
17597 /* Extract. Size 8. */
3b8d421e
PB
17598 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17599 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17600
17601 /* Two registers, miscellaneous. */
17602 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17603 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17604 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17605 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17606 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17607 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17608 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17609 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17610 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17611 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17612 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17613 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17614 /* VMOVN. Types I16 I32 I64. */
21d799b5 17615 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17616 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17617 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17618 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17619 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17620 /* VZIP / VUZP. Sizes 8 16 32. */
17621 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17622 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17623 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17624 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17625 /* VQABS / VQNEG. Types S8 S16 S32. */
17626 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17627 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17628 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17629 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17630 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17631 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17632 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17633 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17634 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17635 /* Reciprocal estimates. Types U32 F32. */
17636 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17637 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17638 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17639 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17640 /* VCLS. Types S8 S16 S32. */
17641 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17642 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17643 /* VCLZ. Types I8 I16 I32. */
17644 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17645 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17646 /* VCNT. Size 8. */
17647 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17648 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17649 /* Two address, untyped. */
17650 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17651 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17652 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17653 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17654 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17655
17656 /* Table lookup. Size 8. */
17657 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17658 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17659
c921be7d
NC
17660#undef THUMB_VARIANT
17661#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17662#undef ARM_VARIANT
17663#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17664
5287ad62 17665 /* Neon element/structure load/store. */
21d799b5
NC
17666 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17667 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17668 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17669 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17670 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17671 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17672 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17673 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17674
c921be7d 17675#undef THUMB_VARIANT
62f3b8c8
PB
17676#define THUMB_VARIANT &fpu_vfp_ext_v3xd
17677#undef ARM_VARIANT
17678#define ARM_VARIANT &fpu_vfp_ext_v3xd
17679 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17680 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17681 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17682 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17683 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17684 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17685 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17686 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17687 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17688
17689#undef THUMB_VARIANT
c921be7d
NC
17690#define THUMB_VARIANT & fpu_vfp_ext_v3
17691#undef ARM_VARIANT
17692#define ARM_VARIANT & fpu_vfp_ext_v3
17693
21d799b5 17694 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 17695 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17696 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17697 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17698 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17699 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17700 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17701 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17702 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17703
62f3b8c8
PB
17704#undef ARM_VARIANT
17705#define ARM_VARIANT &fpu_vfp_ext_fma
17706#undef THUMB_VARIANT
17707#define THUMB_VARIANT &fpu_vfp_ext_fma
17708 /* Mnemonics shared by Neon and VFP. These are included in the
17709 VFP FMA variant; NEON and VFP FMA always includes the NEON
17710 FMA instructions. */
17711 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17712 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17713 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17714 the v form should always be used. */
17715 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17716 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17717 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17718 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17719 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17720 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17721
5287ad62 17722#undef THUMB_VARIANT
c921be7d
NC
17723#undef ARM_VARIANT
17724#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17725
21d799b5
NC
17726 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17727 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17728 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17729 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17730 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17731 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17732 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17733 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 17734
c921be7d
NC
17735#undef ARM_VARIANT
17736#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17737
21d799b5
NC
17738 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17739 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17740 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17741 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17742 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17743 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17744 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17745 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17746 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17747 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17748 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17749 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17750 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17751 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17752 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17753 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17754 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17755 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17756 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17757 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17758 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17759 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17760 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17761 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17762 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17763 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17764 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17765 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17766 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17767 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17768 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17769 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17770 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17771 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17772 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17773 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17774 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17775 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17776 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17777 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17778 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17779 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17780 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17781 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17782 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17783 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17784 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17785 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17786 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17787 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17788 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17789 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17790 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17791 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17792 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17793 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17794 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17795 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17796 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17797 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17798 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17799 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17800 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17801 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17802 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17803 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17804 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17805 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17806 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17807 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17808 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17809 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17810 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17811 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17812 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17813 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17814 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17815 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17816 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17817 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17818 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17819 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17820 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17821 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17822 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17823 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17824 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17825 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17826 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17827 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17828 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17829 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17830 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17831 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17832 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17833 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17834 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17835 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17836 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17837 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17838 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17839 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17840 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17841 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17842 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17843 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17844 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17845 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17846 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17847 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17848 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17849 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17850 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17851 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17852 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17853 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17854 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17855 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17856 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17857 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17858 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17859 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17860 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17861 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17862 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17863 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17864 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17865 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17866 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17867 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17868 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17869 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17870 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17871 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17872 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17873 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17874 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17875 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17876 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17877 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17878 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17879 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17880 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
17881 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
17882 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
17883 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
17884 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
17885 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
17886 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17887 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17888 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17889 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
17890 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
17891 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
17892 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
17893 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
17894 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
17895 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17896 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17897 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17898 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17899 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 17900
c921be7d
NC
17901#undef ARM_VARIANT
17902#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
17903
21d799b5
NC
17904 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
17905 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
17906 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
17907 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
17908 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
17909 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
17910 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17911 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17912 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17913 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17914 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17915 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17916 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17917 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17918 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17919 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17920 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17921 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17922 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17923 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17924 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
17925 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17934 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17935 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17945 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17946 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17947 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17955 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17956 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17957 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17958 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 17961
c921be7d
NC
17962#undef ARM_VARIANT
17963#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
17964
21d799b5
NC
17965 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17966 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17967 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17968 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17969 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17970 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17971 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17972 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17973 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
17974 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
17975 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
17976 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
17977 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
17978 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
17979 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
17980 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
17981 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
17982 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
17983 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
17984 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
17985 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
17986 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
17987 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
17988 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
17989 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
17990 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
17991 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
17992 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
17993 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17994 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
17995 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
17996 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
17997 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
17998 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
17999 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18000 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18001 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18002 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18003 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18004 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18005 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18006 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18007 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18008 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18009 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18010 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18011 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18012 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18013 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18014 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18015 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18016 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18017 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18018 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18019 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18020 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18021 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18022 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18023 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18024 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18025 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18026 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18027 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18028 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18029 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18030 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18031 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18032 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18033 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18034 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18035 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18036 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18037 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18038 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18039 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18040 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18041};
18042#undef ARM_VARIANT
18043#undef THUMB_VARIANT
18044#undef TCE
18045#undef TCM
18046#undef TUE
18047#undef TUF
18048#undef TCC
8f06b2d8 18049#undef cCE
e3cb604e
PB
18050#undef cCL
18051#undef C3E
c19d1205
ZW
18052#undef CE
18053#undef CM
18054#undef UE
18055#undef UF
18056#undef UT
5287ad62
JB
18057#undef NUF
18058#undef nUF
18059#undef NCE
18060#undef nCE
c19d1205
ZW
18061#undef OPS0
18062#undef OPS1
18063#undef OPS2
18064#undef OPS3
18065#undef OPS4
18066#undef OPS5
18067#undef OPS6
18068#undef do_0
18069\f
18070/* MD interface: bits in the object file. */
bfae80f2 18071
c19d1205
ZW
18072/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18073 for use in the a.out file, and stores them in the array pointed to by buf.
18074 This knows about the endian-ness of the target machine and does
18075 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18076 2 (short) and 4 (long) Floating numbers are put out as a series of
18077 LITTLENUMS (shorts, here at least). */
b99bd4ef 18078
c19d1205
ZW
18079void
18080md_number_to_chars (char * buf, valueT val, int n)
18081{
18082 if (target_big_endian)
18083 number_to_chars_bigendian (buf, val, n);
18084 else
18085 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18086}
18087
c19d1205
ZW
18088static valueT
18089md_chars_to_number (char * buf, int n)
bfae80f2 18090{
c19d1205
ZW
18091 valueT result = 0;
18092 unsigned char * where = (unsigned char *) buf;
bfae80f2 18093
c19d1205 18094 if (target_big_endian)
b99bd4ef 18095 {
c19d1205
ZW
18096 while (n--)
18097 {
18098 result <<= 8;
18099 result |= (*where++ & 255);
18100 }
b99bd4ef 18101 }
c19d1205 18102 else
b99bd4ef 18103 {
c19d1205
ZW
18104 while (n--)
18105 {
18106 result <<= 8;
18107 result |= (where[n] & 255);
18108 }
bfae80f2 18109 }
b99bd4ef 18110
c19d1205 18111 return result;
bfae80f2 18112}
b99bd4ef 18113
c19d1205 18114/* MD interface: Sections. */
b99bd4ef 18115
0110f2b8
PB
18116/* Estimate the size of a frag before relaxing. Assume everything fits in
18117 2 bytes. */
18118
c19d1205 18119int
0110f2b8 18120md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18121 segT segtype ATTRIBUTE_UNUSED)
18122{
0110f2b8
PB
18123 fragp->fr_var = 2;
18124 return 2;
18125}
18126
18127/* Convert a machine dependent frag. */
18128
18129void
18130md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18131{
18132 unsigned long insn;
18133 unsigned long old_op;
18134 char *buf;
18135 expressionS exp;
18136 fixS *fixp;
18137 int reloc_type;
18138 int pc_rel;
18139 int opcode;
18140
18141 buf = fragp->fr_literal + fragp->fr_fix;
18142
18143 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18144 if (fragp->fr_symbol)
18145 {
0110f2b8
PB
18146 exp.X_op = O_symbol;
18147 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18148 }
18149 else
18150 {
0110f2b8 18151 exp.X_op = O_constant;
5f4273c7 18152 }
0110f2b8
PB
18153 exp.X_add_number = fragp->fr_offset;
18154 opcode = fragp->fr_subtype;
18155 switch (opcode)
18156 {
18157 case T_MNEM_ldr_pc:
18158 case T_MNEM_ldr_pc2:
18159 case T_MNEM_ldr_sp:
18160 case T_MNEM_str_sp:
18161 case T_MNEM_ldr:
18162 case T_MNEM_ldrb:
18163 case T_MNEM_ldrh:
18164 case T_MNEM_str:
18165 case T_MNEM_strb:
18166 case T_MNEM_strh:
18167 if (fragp->fr_var == 4)
18168 {
5f4273c7 18169 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18170 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18171 {
18172 insn |= (old_op & 0x700) << 4;
18173 }
18174 else
18175 {
18176 insn |= (old_op & 7) << 12;
18177 insn |= (old_op & 0x38) << 13;
18178 }
18179 insn |= 0x00000c00;
18180 put_thumb32_insn (buf, insn);
18181 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18182 }
18183 else
18184 {
18185 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18186 }
18187 pc_rel = (opcode == T_MNEM_ldr_pc2);
18188 break;
18189 case T_MNEM_adr:
18190 if (fragp->fr_var == 4)
18191 {
18192 insn = THUMB_OP32 (opcode);
18193 insn |= (old_op & 0xf0) << 4;
18194 put_thumb32_insn (buf, insn);
18195 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18196 }
18197 else
18198 {
18199 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18200 exp.X_add_number -= 4;
18201 }
18202 pc_rel = 1;
18203 break;
18204 case T_MNEM_mov:
18205 case T_MNEM_movs:
18206 case T_MNEM_cmp:
18207 case T_MNEM_cmn:
18208 if (fragp->fr_var == 4)
18209 {
18210 int r0off = (opcode == T_MNEM_mov
18211 || opcode == T_MNEM_movs) ? 0 : 8;
18212 insn = THUMB_OP32 (opcode);
18213 insn = (insn & 0xe1ffffff) | 0x10000000;
18214 insn |= (old_op & 0x700) << r0off;
18215 put_thumb32_insn (buf, insn);
18216 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18217 }
18218 else
18219 {
18220 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18221 }
18222 pc_rel = 0;
18223 break;
18224 case T_MNEM_b:
18225 if (fragp->fr_var == 4)
18226 {
18227 insn = THUMB_OP32(opcode);
18228 put_thumb32_insn (buf, insn);
18229 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18230 }
18231 else
18232 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18233 pc_rel = 1;
18234 break;
18235 case T_MNEM_bcond:
18236 if (fragp->fr_var == 4)
18237 {
18238 insn = THUMB_OP32(opcode);
18239 insn |= (old_op & 0xf00) << 14;
18240 put_thumb32_insn (buf, insn);
18241 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18242 }
18243 else
18244 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18245 pc_rel = 1;
18246 break;
18247 case T_MNEM_add_sp:
18248 case T_MNEM_add_pc:
18249 case T_MNEM_inc_sp:
18250 case T_MNEM_dec_sp:
18251 if (fragp->fr_var == 4)
18252 {
18253 /* ??? Choose between add and addw. */
18254 insn = THUMB_OP32 (opcode);
18255 insn |= (old_op & 0xf0) << 4;
18256 put_thumb32_insn (buf, insn);
16805f35
PB
18257 if (opcode == T_MNEM_add_pc)
18258 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18259 else
18260 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18261 }
18262 else
18263 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18264 pc_rel = 0;
18265 break;
18266
18267 case T_MNEM_addi:
18268 case T_MNEM_addis:
18269 case T_MNEM_subi:
18270 case T_MNEM_subis:
18271 if (fragp->fr_var == 4)
18272 {
18273 insn = THUMB_OP32 (opcode);
18274 insn |= (old_op & 0xf0) << 4;
18275 insn |= (old_op & 0xf) << 16;
18276 put_thumb32_insn (buf, insn);
16805f35
PB
18277 if (insn & (1 << 20))
18278 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18279 else
18280 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18281 }
18282 else
18283 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18284 pc_rel = 0;
18285 break;
18286 default:
5f4273c7 18287 abort ();
0110f2b8
PB
18288 }
18289 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18290 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18291 fixp->fx_file = fragp->fr_file;
18292 fixp->fx_line = fragp->fr_line;
18293 fragp->fr_fix += fragp->fr_var;
18294}
18295
18296/* Return the size of a relaxable immediate operand instruction.
18297 SHIFT and SIZE specify the form of the allowable immediate. */
18298static int
18299relax_immediate (fragS *fragp, int size, int shift)
18300{
18301 offsetT offset;
18302 offsetT mask;
18303 offsetT low;
18304
18305 /* ??? Should be able to do better than this. */
18306 if (fragp->fr_symbol)
18307 return 4;
18308
18309 low = (1 << shift) - 1;
18310 mask = (1 << (shift + size)) - (1 << shift);
18311 offset = fragp->fr_offset;
18312 /* Force misaligned offsets to 32-bit variant. */
18313 if (offset & low)
5e77afaa 18314 return 4;
0110f2b8
PB
18315 if (offset & ~mask)
18316 return 4;
18317 return 2;
18318}
18319
5e77afaa
PB
18320/* Get the address of a symbol during relaxation. */
18321static addressT
5f4273c7 18322relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18323{
18324 fragS *sym_frag;
18325 addressT addr;
18326 symbolS *sym;
18327
18328 sym = fragp->fr_symbol;
18329 sym_frag = symbol_get_frag (sym);
18330 know (S_GET_SEGMENT (sym) != absolute_section
18331 || sym_frag == &zero_address_frag);
18332 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18333
18334 /* If frag has yet to be reached on this pass, assume it will
18335 move by STRETCH just as we did. If this is not so, it will
18336 be because some frag between grows, and that will force
18337 another pass. */
18338
18339 if (stretch != 0
18340 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18341 {
18342 fragS *f;
18343
18344 /* Adjust stretch for any alignment frag. Note that if have
18345 been expanding the earlier code, the symbol may be
18346 defined in what appears to be an earlier frag. FIXME:
18347 This doesn't handle the fr_subtype field, which specifies
18348 a maximum number of bytes to skip when doing an
18349 alignment. */
18350 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18351 {
18352 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18353 {
18354 if (stretch < 0)
18355 stretch = - ((- stretch)
18356 & ~ ((1 << (int) f->fr_offset) - 1));
18357 else
18358 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18359 if (stretch == 0)
18360 break;
18361 }
18362 }
18363 if (f != NULL)
18364 addr += stretch;
18365 }
5e77afaa
PB
18366
18367 return addr;
18368}
18369
0110f2b8
PB
18370/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18371 load. */
18372static int
5e77afaa 18373relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18374{
18375 addressT addr;
18376 offsetT val;
18377
18378 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18379 if (fragp->fr_symbol == NULL
18380 || !S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18381 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18382 return 4;
18383
5f4273c7 18384 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18385 addr = fragp->fr_address + fragp->fr_fix;
18386 addr = (addr + 4) & ~3;
5e77afaa 18387 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18388 if (val & 3)
5e77afaa 18389 return 4;
0110f2b8
PB
18390 val -= addr;
18391 if (val < 0 || val > 1020)
18392 return 4;
18393 return 2;
18394}
18395
18396/* Return the size of a relaxable add/sub immediate instruction. */
18397static int
18398relax_addsub (fragS *fragp, asection *sec)
18399{
18400 char *buf;
18401 int op;
18402
18403 buf = fragp->fr_literal + fragp->fr_fix;
18404 op = bfd_get_16(sec->owner, buf);
18405 if ((op & 0xf) == ((op >> 4) & 0xf))
18406 return relax_immediate (fragp, 8, 0);
18407 else
18408 return relax_immediate (fragp, 3, 0);
18409}
18410
18411
18412/* Return the size of a relaxable branch instruction. BITS is the
18413 size of the offset field in the narrow instruction. */
18414
18415static int
5e77afaa 18416relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18417{
18418 addressT addr;
18419 offsetT val;
18420 offsetT limit;
18421
18422 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18423 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18424 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18425 return 4;
18426
267bf995
RR
18427#ifdef OBJ_ELF
18428 if (S_IS_DEFINED (fragp->fr_symbol)
18429 && ARM_IS_FUNC (fragp->fr_symbol))
18430 return 4;
18431#endif
18432
5f4273c7 18433 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18434 addr = fragp->fr_address + fragp->fr_fix + 4;
18435 val -= addr;
18436
18437 /* Offset is a signed value *2 */
18438 limit = 1 << bits;
18439 if (val >= limit || val < -limit)
18440 return 4;
18441 return 2;
18442}
18443
18444
18445/* Relax a machine dependent frag. This returns the amount by which
18446 the current size of the frag should change. */
18447
18448int
5e77afaa 18449arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18450{
18451 int oldsize;
18452 int newsize;
18453
18454 oldsize = fragp->fr_var;
18455 switch (fragp->fr_subtype)
18456 {
18457 case T_MNEM_ldr_pc2:
5f4273c7 18458 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18459 break;
18460 case T_MNEM_ldr_pc:
18461 case T_MNEM_ldr_sp:
18462 case T_MNEM_str_sp:
5f4273c7 18463 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18464 break;
18465 case T_MNEM_ldr:
18466 case T_MNEM_str:
5f4273c7 18467 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18468 break;
18469 case T_MNEM_ldrh:
18470 case T_MNEM_strh:
5f4273c7 18471 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18472 break;
18473 case T_MNEM_ldrb:
18474 case T_MNEM_strb:
5f4273c7 18475 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18476 break;
18477 case T_MNEM_adr:
5f4273c7 18478 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18479 break;
18480 case T_MNEM_mov:
18481 case T_MNEM_movs:
18482 case T_MNEM_cmp:
18483 case T_MNEM_cmn:
5f4273c7 18484 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18485 break;
18486 case T_MNEM_b:
5f4273c7 18487 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18488 break;
18489 case T_MNEM_bcond:
5f4273c7 18490 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18491 break;
18492 case T_MNEM_add_sp:
18493 case T_MNEM_add_pc:
18494 newsize = relax_immediate (fragp, 8, 2);
18495 break;
18496 case T_MNEM_inc_sp:
18497 case T_MNEM_dec_sp:
18498 newsize = relax_immediate (fragp, 7, 2);
18499 break;
18500 case T_MNEM_addi:
18501 case T_MNEM_addis:
18502 case T_MNEM_subi:
18503 case T_MNEM_subis:
18504 newsize = relax_addsub (fragp, sec);
18505 break;
18506 default:
5f4273c7 18507 abort ();
0110f2b8 18508 }
5e77afaa
PB
18509
18510 fragp->fr_var = newsize;
18511 /* Freeze wide instructions that are at or before the same location as
18512 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18513 Don't freeze them unconditionally because targets may be artificially
18514 misaligned by the expansion of preceding frags. */
5e77afaa 18515 if (stretch <= 0 && newsize > 2)
0110f2b8 18516 {
0110f2b8 18517 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18518 frag_wane (fragp);
0110f2b8 18519 }
5e77afaa 18520
0110f2b8 18521 return newsize - oldsize;
c19d1205 18522}
b99bd4ef 18523
c19d1205 18524/* Round up a section size to the appropriate boundary. */
b99bd4ef 18525
c19d1205
ZW
18526valueT
18527md_section_align (segT segment ATTRIBUTE_UNUSED,
18528 valueT size)
18529{
f0927246
NC
18530#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18531 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18532 {
18533 /* For a.out, force the section size to be aligned. If we don't do
18534 this, BFD will align it for us, but it will not write out the
18535 final bytes of the section. This may be a bug in BFD, but it is
18536 easier to fix it here since that is how the other a.out targets
18537 work. */
18538 int align;
18539
18540 align = bfd_get_section_alignment (stdoutput, segment);
18541 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18542 }
c19d1205 18543#endif
f0927246
NC
18544
18545 return size;
bfae80f2 18546}
b99bd4ef 18547
c19d1205
ZW
18548/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18549 of an rs_align_code fragment. */
18550
18551void
18552arm_handle_align (fragS * fragP)
bfae80f2 18553{
e7495e45
NS
18554 static char const arm_noop[2][2][4] =
18555 {
18556 { /* ARMv1 */
18557 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18558 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18559 },
18560 { /* ARMv6k */
18561 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18562 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18563 },
18564 };
18565 static char const thumb_noop[2][2][2] =
18566 {
18567 { /* Thumb-1 */
18568 {0xc0, 0x46}, /* LE */
18569 {0x46, 0xc0}, /* BE */
18570 },
18571 { /* Thumb-2 */
18572 {0x00, 0xbf}, /* LE */
18573 {0xbf, 0x00} /* BE */
18574 }
18575 };
18576 static char const wide_thumb_noop[2][4] =
18577 { /* Wide Thumb-2 */
18578 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18579 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18580 };
c921be7d 18581
e7495e45 18582 unsigned bytes, fix, noop_size;
c19d1205
ZW
18583 char * p;
18584 const char * noop;
e7495e45 18585 const char *narrow_noop = NULL;
cd000bff
DJ
18586#ifdef OBJ_ELF
18587 enum mstate state;
18588#endif
bfae80f2 18589
c19d1205 18590 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18591 return;
18592
c19d1205
ZW
18593 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18594 p = fragP->fr_literal + fragP->fr_fix;
18595 fix = 0;
bfae80f2 18596
c19d1205
ZW
18597 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18598 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18599
cd000bff 18600 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18601
cd000bff 18602 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18603 {
e7495e45
NS
18604 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18605 {
18606 narrow_noop = thumb_noop[1][target_big_endian];
18607 noop = wide_thumb_noop[target_big_endian];
18608 }
c19d1205 18609 else
e7495e45
NS
18610 noop = thumb_noop[0][target_big_endian];
18611 noop_size = 2;
cd000bff
DJ
18612#ifdef OBJ_ELF
18613 state = MAP_THUMB;
18614#endif
7ed4c4c5
NC
18615 }
18616 else
18617 {
e7495e45
NS
18618 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18619 [target_big_endian];
18620 noop_size = 4;
cd000bff
DJ
18621#ifdef OBJ_ELF
18622 state = MAP_ARM;
18623#endif
7ed4c4c5 18624 }
c921be7d 18625
e7495e45 18626 fragP->fr_var = noop_size;
c921be7d 18627
c19d1205 18628 if (bytes & (noop_size - 1))
7ed4c4c5 18629 {
c19d1205 18630 fix = bytes & (noop_size - 1);
cd000bff
DJ
18631#ifdef OBJ_ELF
18632 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18633#endif
c19d1205
ZW
18634 memset (p, 0, fix);
18635 p += fix;
18636 bytes -= fix;
a737bd4d 18637 }
a737bd4d 18638
e7495e45
NS
18639 if (narrow_noop)
18640 {
18641 if (bytes & noop_size)
18642 {
18643 /* Insert a narrow noop. */
18644 memcpy (p, narrow_noop, noop_size);
18645 p += noop_size;
18646 bytes -= noop_size;
18647 fix += noop_size;
18648 }
18649
18650 /* Use wide noops for the remainder */
18651 noop_size = 4;
18652 }
18653
c19d1205 18654 while (bytes >= noop_size)
a737bd4d 18655 {
c19d1205
ZW
18656 memcpy (p, noop, noop_size);
18657 p += noop_size;
18658 bytes -= noop_size;
18659 fix += noop_size;
a737bd4d
NC
18660 }
18661
c19d1205 18662 fragP->fr_fix += fix;
a737bd4d
NC
18663}
18664
c19d1205
ZW
18665/* Called from md_do_align. Used to create an alignment
18666 frag in a code section. */
18667
18668void
18669arm_frag_align_code (int n, int max)
bfae80f2 18670{
c19d1205 18671 char * p;
7ed4c4c5 18672
c19d1205 18673 /* We assume that there will never be a requirement
6ec8e702 18674 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 18675 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
18676 {
18677 char err_msg[128];
18678
18679 sprintf (err_msg,
18680 _("alignments greater than %d bytes not supported in .text sections."),
18681 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 18682 as_fatal ("%s", err_msg);
6ec8e702 18683 }
bfae80f2 18684
c19d1205
ZW
18685 p = frag_var (rs_align_code,
18686 MAX_MEM_FOR_RS_ALIGN_CODE,
18687 1,
18688 (relax_substateT) max,
18689 (symbolS *) NULL,
18690 (offsetT) n,
18691 (char *) NULL);
18692 *p = 0;
18693}
bfae80f2 18694
8dc2430f
NC
18695/* Perform target specific initialisation of a frag.
18696 Note - despite the name this initialisation is not done when the frag
18697 is created, but only when its type is assigned. A frag can be created
18698 and used a long time before its type is set, so beware of assuming that
18699 this initialisationis performed first. */
bfae80f2 18700
cd000bff
DJ
18701#ifndef OBJ_ELF
18702void
18703arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18704{
18705 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 18706 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
18707}
18708
18709#else /* OBJ_ELF is defined. */
c19d1205 18710void
cd000bff 18711arm_init_frag (fragS * fragP, int max_chars)
c19d1205 18712{
8dc2430f
NC
18713 /* If the current ARM vs THUMB mode has not already
18714 been recorded into this frag then do so now. */
cd000bff
DJ
18715 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18716 {
18717 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18718
18719 /* Record a mapping symbol for alignment frags. We will delete this
18720 later if the alignment ends up empty. */
18721 switch (fragP->fr_type)
18722 {
18723 case rs_align:
18724 case rs_align_test:
18725 case rs_fill:
18726 mapping_state_2 (MAP_DATA, max_chars);
18727 break;
18728 case rs_align_code:
18729 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18730 break;
18731 default:
18732 break;
18733 }
18734 }
bfae80f2
RE
18735}
18736
c19d1205
ZW
18737/* When we change sections we need to issue a new mapping symbol. */
18738
18739void
18740arm_elf_change_section (void)
bfae80f2 18741{
c19d1205
ZW
18742 /* Link an unlinked unwind index table section to the .text section. */
18743 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18744 && elf_linked_to_section (now_seg) == NULL)
18745 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
18746}
18747
c19d1205
ZW
18748int
18749arm_elf_section_type (const char * str, size_t len)
e45d0630 18750{
c19d1205
ZW
18751 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18752 return SHT_ARM_EXIDX;
e45d0630 18753
c19d1205
ZW
18754 return -1;
18755}
18756\f
18757/* Code to deal with unwinding tables. */
e45d0630 18758
c19d1205 18759static void add_unwind_adjustsp (offsetT);
e45d0630 18760
5f4273c7 18761/* Generate any deferred unwind frame offset. */
e45d0630 18762
bfae80f2 18763static void
c19d1205 18764flush_pending_unwind (void)
bfae80f2 18765{
c19d1205 18766 offsetT offset;
bfae80f2 18767
c19d1205
ZW
18768 offset = unwind.pending_offset;
18769 unwind.pending_offset = 0;
18770 if (offset != 0)
18771 add_unwind_adjustsp (offset);
bfae80f2
RE
18772}
18773
c19d1205
ZW
18774/* Add an opcode to this list for this function. Two-byte opcodes should
18775 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18776 order. */
18777
bfae80f2 18778static void
c19d1205 18779add_unwind_opcode (valueT op, int length)
bfae80f2 18780{
c19d1205
ZW
18781 /* Add any deferred stack adjustment. */
18782 if (unwind.pending_offset)
18783 flush_pending_unwind ();
bfae80f2 18784
c19d1205 18785 unwind.sp_restored = 0;
bfae80f2 18786
c19d1205 18787 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18788 {
c19d1205
ZW
18789 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18790 if (unwind.opcodes)
21d799b5
NC
18791 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18792 unwind.opcode_alloc);
c19d1205 18793 else
21d799b5 18794 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 18795 }
c19d1205 18796 while (length > 0)
bfae80f2 18797 {
c19d1205
ZW
18798 length--;
18799 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18800 op >>= 8;
18801 unwind.opcode_count++;
bfae80f2 18802 }
bfae80f2
RE
18803}
18804
c19d1205
ZW
18805/* Add unwind opcodes to adjust the stack pointer. */
18806
bfae80f2 18807static void
c19d1205 18808add_unwind_adjustsp (offsetT offset)
bfae80f2 18809{
c19d1205 18810 valueT op;
bfae80f2 18811
c19d1205 18812 if (offset > 0x200)
bfae80f2 18813 {
c19d1205
ZW
18814 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18815 char bytes[5];
18816 int n;
18817 valueT o;
bfae80f2 18818
c19d1205
ZW
18819 /* Long form: 0xb2, uleb128. */
18820 /* This might not fit in a word so add the individual bytes,
18821 remembering the list is built in reverse order. */
18822 o = (valueT) ((offset - 0x204) >> 2);
18823 if (o == 0)
18824 add_unwind_opcode (0, 1);
bfae80f2 18825
c19d1205
ZW
18826 /* Calculate the uleb128 encoding of the offset. */
18827 n = 0;
18828 while (o)
18829 {
18830 bytes[n] = o & 0x7f;
18831 o >>= 7;
18832 if (o)
18833 bytes[n] |= 0x80;
18834 n++;
18835 }
18836 /* Add the insn. */
18837 for (; n; n--)
18838 add_unwind_opcode (bytes[n - 1], 1);
18839 add_unwind_opcode (0xb2, 1);
18840 }
18841 else if (offset > 0x100)
bfae80f2 18842 {
c19d1205
ZW
18843 /* Two short opcodes. */
18844 add_unwind_opcode (0x3f, 1);
18845 op = (offset - 0x104) >> 2;
18846 add_unwind_opcode (op, 1);
bfae80f2 18847 }
c19d1205
ZW
18848 else if (offset > 0)
18849 {
18850 /* Short opcode. */
18851 op = (offset - 4) >> 2;
18852 add_unwind_opcode (op, 1);
18853 }
18854 else if (offset < 0)
bfae80f2 18855 {
c19d1205
ZW
18856 offset = -offset;
18857 while (offset > 0x100)
bfae80f2 18858 {
c19d1205
ZW
18859 add_unwind_opcode (0x7f, 1);
18860 offset -= 0x100;
bfae80f2 18861 }
c19d1205
ZW
18862 op = ((offset - 4) >> 2) | 0x40;
18863 add_unwind_opcode (op, 1);
bfae80f2 18864 }
bfae80f2
RE
18865}
18866
c19d1205
ZW
18867/* Finish the list of unwind opcodes for this function. */
18868static void
18869finish_unwind_opcodes (void)
bfae80f2 18870{
c19d1205 18871 valueT op;
bfae80f2 18872
c19d1205 18873 if (unwind.fp_used)
bfae80f2 18874 {
708587a4 18875 /* Adjust sp as necessary. */
c19d1205
ZW
18876 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18877 flush_pending_unwind ();
bfae80f2 18878
c19d1205
ZW
18879 /* After restoring sp from the frame pointer. */
18880 op = 0x90 | unwind.fp_reg;
18881 add_unwind_opcode (op, 1);
18882 }
18883 else
18884 flush_pending_unwind ();
bfae80f2
RE
18885}
18886
bfae80f2 18887
c19d1205
ZW
18888/* Start an exception table entry. If idx is nonzero this is an index table
18889 entry. */
bfae80f2
RE
18890
18891static void
c19d1205 18892start_unwind_section (const segT text_seg, int idx)
bfae80f2 18893{
c19d1205
ZW
18894 const char * text_name;
18895 const char * prefix;
18896 const char * prefix_once;
18897 const char * group_name;
18898 size_t prefix_len;
18899 size_t text_len;
18900 char * sec_name;
18901 size_t sec_name_len;
18902 int type;
18903 int flags;
18904 int linkonce;
bfae80f2 18905
c19d1205 18906 if (idx)
bfae80f2 18907 {
c19d1205
ZW
18908 prefix = ELF_STRING_ARM_unwind;
18909 prefix_once = ELF_STRING_ARM_unwind_once;
18910 type = SHT_ARM_EXIDX;
bfae80f2 18911 }
c19d1205 18912 else
bfae80f2 18913 {
c19d1205
ZW
18914 prefix = ELF_STRING_ARM_unwind_info;
18915 prefix_once = ELF_STRING_ARM_unwind_info_once;
18916 type = SHT_PROGBITS;
bfae80f2
RE
18917 }
18918
c19d1205
ZW
18919 text_name = segment_name (text_seg);
18920 if (streq (text_name, ".text"))
18921 text_name = "";
18922
18923 if (strncmp (text_name, ".gnu.linkonce.t.",
18924 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 18925 {
c19d1205
ZW
18926 prefix = prefix_once;
18927 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
18928 }
18929
c19d1205
ZW
18930 prefix_len = strlen (prefix);
18931 text_len = strlen (text_name);
18932 sec_name_len = prefix_len + text_len;
21d799b5 18933 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
18934 memcpy (sec_name, prefix, prefix_len);
18935 memcpy (sec_name + prefix_len, text_name, text_len);
18936 sec_name[prefix_len + text_len] = '\0';
bfae80f2 18937
c19d1205
ZW
18938 flags = SHF_ALLOC;
18939 linkonce = 0;
18940 group_name = 0;
bfae80f2 18941
c19d1205
ZW
18942 /* Handle COMDAT group. */
18943 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 18944 {
c19d1205
ZW
18945 group_name = elf_group_name (text_seg);
18946 if (group_name == NULL)
18947 {
bd3ba5d1 18948 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
18949 segment_name (text_seg));
18950 ignore_rest_of_line ();
18951 return;
18952 }
18953 flags |= SHF_GROUP;
18954 linkonce = 1;
bfae80f2
RE
18955 }
18956
c19d1205 18957 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 18958
5f4273c7 18959 /* Set the section link for index tables. */
c19d1205
ZW
18960 if (idx)
18961 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
18962}
18963
bfae80f2 18964
c19d1205
ZW
18965/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
18966 personality routine data. Returns zero, or the index table value for
18967 and inline entry. */
18968
18969static valueT
18970create_unwind_entry (int have_data)
bfae80f2 18971{
c19d1205
ZW
18972 int size;
18973 addressT where;
18974 char *ptr;
18975 /* The current word of data. */
18976 valueT data;
18977 /* The number of bytes left in this word. */
18978 int n;
bfae80f2 18979
c19d1205 18980 finish_unwind_opcodes ();
bfae80f2 18981
c19d1205
ZW
18982 /* Remember the current text section. */
18983 unwind.saved_seg = now_seg;
18984 unwind.saved_subseg = now_subseg;
bfae80f2 18985
c19d1205 18986 start_unwind_section (now_seg, 0);
bfae80f2 18987
c19d1205 18988 if (unwind.personality_routine == NULL)
bfae80f2 18989 {
c19d1205
ZW
18990 if (unwind.personality_index == -2)
18991 {
18992 if (have_data)
5f4273c7 18993 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
18994 return 1; /* EXIDX_CANTUNWIND. */
18995 }
bfae80f2 18996
c19d1205
ZW
18997 /* Use a default personality routine if none is specified. */
18998 if (unwind.personality_index == -1)
18999 {
19000 if (unwind.opcode_count > 3)
19001 unwind.personality_index = 1;
19002 else
19003 unwind.personality_index = 0;
19004 }
bfae80f2 19005
c19d1205
ZW
19006 /* Space for the personality routine entry. */
19007 if (unwind.personality_index == 0)
19008 {
19009 if (unwind.opcode_count > 3)
19010 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19011
c19d1205
ZW
19012 if (!have_data)
19013 {
19014 /* All the data is inline in the index table. */
19015 data = 0x80;
19016 n = 3;
19017 while (unwind.opcode_count > 0)
19018 {
19019 unwind.opcode_count--;
19020 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19021 n--;
19022 }
bfae80f2 19023
c19d1205
ZW
19024 /* Pad with "finish" opcodes. */
19025 while (n--)
19026 data = (data << 8) | 0xb0;
bfae80f2 19027
c19d1205
ZW
19028 return data;
19029 }
19030 size = 0;
19031 }
19032 else
19033 /* We get two opcodes "free" in the first word. */
19034 size = unwind.opcode_count - 2;
19035 }
19036 else
19037 /* An extra byte is required for the opcode count. */
19038 size = unwind.opcode_count + 1;
bfae80f2 19039
c19d1205
ZW
19040 size = (size + 3) >> 2;
19041 if (size > 0xff)
19042 as_bad (_("too many unwind opcodes"));
bfae80f2 19043
c19d1205
ZW
19044 frag_align (2, 0, 0);
19045 record_alignment (now_seg, 2);
19046 unwind.table_entry = expr_build_dot ();
19047
19048 /* Allocate the table entry. */
19049 ptr = frag_more ((size << 2) + 4);
19050 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19051
c19d1205 19052 switch (unwind.personality_index)
bfae80f2 19053 {
c19d1205
ZW
19054 case -1:
19055 /* ??? Should this be a PLT generating relocation? */
19056 /* Custom personality routine. */
19057 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19058 BFD_RELOC_ARM_PREL31);
bfae80f2 19059
c19d1205
ZW
19060 where += 4;
19061 ptr += 4;
bfae80f2 19062
c19d1205
ZW
19063 /* Set the first byte to the number of additional words. */
19064 data = size - 1;
19065 n = 3;
19066 break;
bfae80f2 19067
c19d1205
ZW
19068 /* ABI defined personality routines. */
19069 case 0:
19070 /* Three opcodes bytes are packed into the first word. */
19071 data = 0x80;
19072 n = 3;
19073 break;
bfae80f2 19074
c19d1205
ZW
19075 case 1:
19076 case 2:
19077 /* The size and first two opcode bytes go in the first word. */
19078 data = ((0x80 + unwind.personality_index) << 8) | size;
19079 n = 2;
19080 break;
bfae80f2 19081
c19d1205
ZW
19082 default:
19083 /* Should never happen. */
19084 abort ();
19085 }
bfae80f2 19086
c19d1205
ZW
19087 /* Pack the opcodes into words (MSB first), reversing the list at the same
19088 time. */
19089 while (unwind.opcode_count > 0)
19090 {
19091 if (n == 0)
19092 {
19093 md_number_to_chars (ptr, data, 4);
19094 ptr += 4;
19095 n = 4;
19096 data = 0;
19097 }
19098 unwind.opcode_count--;
19099 n--;
19100 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19101 }
19102
19103 /* Finish off the last word. */
19104 if (n < 4)
19105 {
19106 /* Pad with "finish" opcodes. */
19107 while (n--)
19108 data = (data << 8) | 0xb0;
19109
19110 md_number_to_chars (ptr, data, 4);
19111 }
19112
19113 if (!have_data)
19114 {
19115 /* Add an empty descriptor if there is no user-specified data. */
19116 ptr = frag_more (4);
19117 md_number_to_chars (ptr, 0, 4);
19118 }
19119
19120 return 0;
bfae80f2
RE
19121}
19122
f0927246
NC
19123
19124/* Initialize the DWARF-2 unwind information for this procedure. */
19125
19126void
19127tc_arm_frame_initial_instructions (void)
19128{
19129 cfi_add_CFA_def_cfa (REG_SP, 0);
19130}
19131#endif /* OBJ_ELF */
19132
c19d1205
ZW
19133/* Convert REGNAME to a DWARF-2 register number. */
19134
19135int
1df69f4f 19136tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19137{
1df69f4f 19138 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19139
19140 if (reg == FAIL)
19141 return -1;
19142
19143 return reg;
bfae80f2
RE
19144}
19145
f0927246 19146#ifdef TE_PE
c19d1205 19147void
f0927246 19148tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19149{
91d6fa6a 19150 expressionS exp;
bfae80f2 19151
91d6fa6a
NC
19152 exp.X_op = O_secrel;
19153 exp.X_add_symbol = symbol;
19154 exp.X_add_number = 0;
19155 emit_expr (&exp, size);
f0927246
NC
19156}
19157#endif
bfae80f2 19158
c19d1205 19159/* MD interface: Symbol and relocation handling. */
bfae80f2 19160
2fc8bdac
ZW
19161/* Return the address within the segment that a PC-relative fixup is
19162 relative to. For ARM, PC-relative fixups applied to instructions
19163 are generally relative to the location of the fixup plus 8 bytes.
19164 Thumb branches are offset by 4, and Thumb loads relative to PC
19165 require special handling. */
bfae80f2 19166
c19d1205 19167long
2fc8bdac 19168md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19169{
2fc8bdac
ZW
19170 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19171
19172 /* If this is pc-relative and we are going to emit a relocation
19173 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19174 will need. Otherwise we want to use the calculated base.
19175 For WinCE we skip the bias for externals as well, since this
19176 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19177 if (fixP->fx_pcrel
2fc8bdac 19178 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19179 || (arm_force_relocation (fixP)
19180#ifdef TE_WINCE
19181 && !S_IS_EXTERNAL (fixP->fx_addsy)
19182#endif
19183 )))
2fc8bdac 19184 base = 0;
bfae80f2 19185
267bf995 19186
c19d1205 19187 switch (fixP->fx_r_type)
bfae80f2 19188 {
2fc8bdac
ZW
19189 /* PC relative addressing on the Thumb is slightly odd as the
19190 bottom two bits of the PC are forced to zero for the
19191 calculation. This happens *after* application of the
19192 pipeline offset. However, Thumb adrl already adjusts for
19193 this, so we need not do it again. */
c19d1205 19194 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19195 return base & ~3;
c19d1205
ZW
19196
19197 case BFD_RELOC_ARM_THUMB_OFFSET:
19198 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19199 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19200 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19201 return (base + 4) & ~3;
c19d1205 19202
2fc8bdac
ZW
19203 /* Thumb branches are simply offset by +4. */
19204 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19205 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19206 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19207 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19208 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19209 return base + 4;
bfae80f2 19210
267bf995
RR
19211 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19212 if (fixP->fx_addsy
19213 && ARM_IS_FUNC (fixP->fx_addsy)
19214 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19215 base = fixP->fx_where + fixP->fx_frag->fr_address;
19216 return base + 4;
19217
00adf2d4
JB
19218 /* BLX is like branches above, but forces the low two bits of PC to
19219 zero. */
267bf995
RR
19220 case BFD_RELOC_THUMB_PCREL_BLX:
19221 if (fixP->fx_addsy
19222 && THUMB_IS_FUNC (fixP->fx_addsy)
19223 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19224 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19225 return (base + 4) & ~3;
19226
2fc8bdac
ZW
19227 /* ARM mode branches are offset by +8. However, the Windows CE
19228 loader expects the relocation not to take this into account. */
267bf995
RR
19229 case BFD_RELOC_ARM_PCREL_BLX:
19230 if (fixP->fx_addsy
19231 && ARM_IS_FUNC (fixP->fx_addsy)
19232 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19233 base = fixP->fx_where + fixP->fx_frag->fr_address;
19234 return base + 8;
19235
19236 case BFD_RELOC_ARM_PCREL_CALL:
19237 if (fixP->fx_addsy
19238 && THUMB_IS_FUNC (fixP->fx_addsy)
19239 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19240 base = fixP->fx_where + fixP->fx_frag->fr_address;
19241 return base + 8;
19242
2fc8bdac 19243 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19244 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19245 case BFD_RELOC_ARM_PLT32:
c19d1205 19246#ifdef TE_WINCE
5f4273c7 19247 /* When handling fixups immediately, because we have already
53baae48
NC
19248 discovered the value of a symbol, or the address of the frag involved
19249 we must account for the offset by +8, as the OS loader will never see the reloc.
19250 see fixup_segment() in write.c
19251 The S_IS_EXTERNAL test handles the case of global symbols.
19252 Those need the calculated base, not just the pipe compensation the linker will need. */
19253 if (fixP->fx_pcrel
19254 && fixP->fx_addsy != NULL
19255 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19256 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19257 return base + 8;
2fc8bdac 19258 return base;
c19d1205 19259#else
2fc8bdac 19260 return base + 8;
c19d1205 19261#endif
2fc8bdac 19262
267bf995 19263
2fc8bdac
ZW
19264 /* ARM mode loads relative to PC are also offset by +8. Unlike
19265 branches, the Windows CE loader *does* expect the relocation
19266 to take this into account. */
19267 case BFD_RELOC_ARM_OFFSET_IMM:
19268 case BFD_RELOC_ARM_OFFSET_IMM8:
19269 case BFD_RELOC_ARM_HWLITERAL:
19270 case BFD_RELOC_ARM_LITERAL:
19271 case BFD_RELOC_ARM_CP_OFF_IMM:
19272 return base + 8;
19273
19274
19275 /* Other PC-relative relocations are un-offset. */
19276 default:
19277 return base;
19278 }
bfae80f2
RE
19279}
19280
c19d1205
ZW
19281/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19282 Otherwise we have no need to default values of symbols. */
19283
19284symbolS *
19285md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19286{
c19d1205
ZW
19287#ifdef OBJ_ELF
19288 if (name[0] == '_' && name[1] == 'G'
19289 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19290 {
19291 if (!GOT_symbol)
19292 {
19293 if (symbol_find (name))
bd3ba5d1 19294 as_bad (_("GOT already in the symbol table"));
bfae80f2 19295
c19d1205
ZW
19296 GOT_symbol = symbol_new (name, undefined_section,
19297 (valueT) 0, & zero_address_frag);
19298 }
bfae80f2 19299
c19d1205 19300 return GOT_symbol;
bfae80f2 19301 }
c19d1205 19302#endif
bfae80f2 19303
c921be7d 19304 return NULL;
bfae80f2
RE
19305}
19306
55cf6793 19307/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19308 computed as two separate immediate values, added together. We
19309 already know that this value cannot be computed by just one ARM
19310 instruction. */
19311
19312static unsigned int
19313validate_immediate_twopart (unsigned int val,
19314 unsigned int * highpart)
bfae80f2 19315{
c19d1205
ZW
19316 unsigned int a;
19317 unsigned int i;
bfae80f2 19318
c19d1205
ZW
19319 for (i = 0; i < 32; i += 2)
19320 if (((a = rotate_left (val, i)) & 0xff) != 0)
19321 {
19322 if (a & 0xff00)
19323 {
19324 if (a & ~ 0xffff)
19325 continue;
19326 * highpart = (a >> 8) | ((i + 24) << 7);
19327 }
19328 else if (a & 0xff0000)
19329 {
19330 if (a & 0xff000000)
19331 continue;
19332 * highpart = (a >> 16) | ((i + 16) << 7);
19333 }
19334 else
19335 {
9c2799c2 19336 gas_assert (a & 0xff000000);
c19d1205
ZW
19337 * highpart = (a >> 24) | ((i + 8) << 7);
19338 }
bfae80f2 19339
c19d1205
ZW
19340 return (a & 0xff) | (i << 7);
19341 }
bfae80f2 19342
c19d1205 19343 return FAIL;
bfae80f2
RE
19344}
19345
c19d1205
ZW
19346static int
19347validate_offset_imm (unsigned int val, int hwse)
19348{
19349 if ((hwse && val > 255) || val > 4095)
19350 return FAIL;
19351 return val;
19352}
bfae80f2 19353
55cf6793 19354/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19355 negative immediate constant by altering the instruction. A bit of
19356 a hack really.
19357 MOV <-> MVN
19358 AND <-> BIC
19359 ADC <-> SBC
19360 by inverting the second operand, and
19361 ADD <-> SUB
19362 CMP <-> CMN
19363 by negating the second operand. */
bfae80f2 19364
c19d1205
ZW
19365static int
19366negate_data_op (unsigned long * instruction,
19367 unsigned long value)
bfae80f2 19368{
c19d1205
ZW
19369 int op, new_inst;
19370 unsigned long negated, inverted;
bfae80f2 19371
c19d1205
ZW
19372 negated = encode_arm_immediate (-value);
19373 inverted = encode_arm_immediate (~value);
bfae80f2 19374
c19d1205
ZW
19375 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19376 switch (op)
bfae80f2 19377 {
c19d1205
ZW
19378 /* First negates. */
19379 case OPCODE_SUB: /* ADD <-> SUB */
19380 new_inst = OPCODE_ADD;
19381 value = negated;
19382 break;
bfae80f2 19383
c19d1205
ZW
19384 case OPCODE_ADD:
19385 new_inst = OPCODE_SUB;
19386 value = negated;
19387 break;
bfae80f2 19388
c19d1205
ZW
19389 case OPCODE_CMP: /* CMP <-> CMN */
19390 new_inst = OPCODE_CMN;
19391 value = negated;
19392 break;
bfae80f2 19393
c19d1205
ZW
19394 case OPCODE_CMN:
19395 new_inst = OPCODE_CMP;
19396 value = negated;
19397 break;
bfae80f2 19398
c19d1205
ZW
19399 /* Now Inverted ops. */
19400 case OPCODE_MOV: /* MOV <-> MVN */
19401 new_inst = OPCODE_MVN;
19402 value = inverted;
19403 break;
bfae80f2 19404
c19d1205
ZW
19405 case OPCODE_MVN:
19406 new_inst = OPCODE_MOV;
19407 value = inverted;
19408 break;
bfae80f2 19409
c19d1205
ZW
19410 case OPCODE_AND: /* AND <-> BIC */
19411 new_inst = OPCODE_BIC;
19412 value = inverted;
19413 break;
bfae80f2 19414
c19d1205
ZW
19415 case OPCODE_BIC:
19416 new_inst = OPCODE_AND;
19417 value = inverted;
19418 break;
bfae80f2 19419
c19d1205
ZW
19420 case OPCODE_ADC: /* ADC <-> SBC */
19421 new_inst = OPCODE_SBC;
19422 value = inverted;
19423 break;
bfae80f2 19424
c19d1205
ZW
19425 case OPCODE_SBC:
19426 new_inst = OPCODE_ADC;
19427 value = inverted;
19428 break;
bfae80f2 19429
c19d1205
ZW
19430 /* We cannot do anything. */
19431 default:
19432 return FAIL;
b99bd4ef
NC
19433 }
19434
c19d1205
ZW
19435 if (value == (unsigned) FAIL)
19436 return FAIL;
19437
19438 *instruction &= OPCODE_MASK;
19439 *instruction |= new_inst << DATA_OP_SHIFT;
19440 return value;
b99bd4ef
NC
19441}
19442
ef8d22e6
PB
19443/* Like negate_data_op, but for Thumb-2. */
19444
19445static unsigned int
16dd5e42 19446thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19447{
19448 int op, new_inst;
19449 int rd;
16dd5e42 19450 unsigned int negated, inverted;
ef8d22e6
PB
19451
19452 negated = encode_thumb32_immediate (-value);
19453 inverted = encode_thumb32_immediate (~value);
19454
19455 rd = (*instruction >> 8) & 0xf;
19456 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19457 switch (op)
19458 {
19459 /* ADD <-> SUB. Includes CMP <-> CMN. */
19460 case T2_OPCODE_SUB:
19461 new_inst = T2_OPCODE_ADD;
19462 value = negated;
19463 break;
19464
19465 case T2_OPCODE_ADD:
19466 new_inst = T2_OPCODE_SUB;
19467 value = negated;
19468 break;
19469
19470 /* ORR <-> ORN. Includes MOV <-> MVN. */
19471 case T2_OPCODE_ORR:
19472 new_inst = T2_OPCODE_ORN;
19473 value = inverted;
19474 break;
19475
19476 case T2_OPCODE_ORN:
19477 new_inst = T2_OPCODE_ORR;
19478 value = inverted;
19479 break;
19480
19481 /* AND <-> BIC. TST has no inverted equivalent. */
19482 case T2_OPCODE_AND:
19483 new_inst = T2_OPCODE_BIC;
19484 if (rd == 15)
19485 value = FAIL;
19486 else
19487 value = inverted;
19488 break;
19489
19490 case T2_OPCODE_BIC:
19491 new_inst = T2_OPCODE_AND;
19492 value = inverted;
19493 break;
19494
19495 /* ADC <-> SBC */
19496 case T2_OPCODE_ADC:
19497 new_inst = T2_OPCODE_SBC;
19498 value = inverted;
19499 break;
19500
19501 case T2_OPCODE_SBC:
19502 new_inst = T2_OPCODE_ADC;
19503 value = inverted;
19504 break;
19505
19506 /* We cannot do anything. */
19507 default:
19508 return FAIL;
19509 }
19510
16dd5e42 19511 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19512 return FAIL;
19513
19514 *instruction &= T2_OPCODE_MASK;
19515 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19516 return value;
19517}
19518
8f06b2d8
PB
19519/* Read a 32-bit thumb instruction from buf. */
19520static unsigned long
19521get_thumb32_insn (char * buf)
19522{
19523 unsigned long insn;
19524 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19525 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19526
19527 return insn;
19528}
19529
a8bc6c78
PB
19530
19531/* We usually want to set the low bit on the address of thumb function
19532 symbols. In particular .word foo - . should have the low bit set.
19533 Generic code tries to fold the difference of two symbols to
19534 a constant. Prevent this and force a relocation when the first symbols
19535 is a thumb function. */
c921be7d
NC
19536
19537bfd_boolean
a8bc6c78
PB
19538arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19539{
19540 if (op == O_subtract
19541 && l->X_op == O_symbol
19542 && r->X_op == O_symbol
19543 && THUMB_IS_FUNC (l->X_add_symbol))
19544 {
19545 l->X_op = O_subtract;
19546 l->X_op_symbol = r->X_add_symbol;
19547 l->X_add_number -= r->X_add_number;
c921be7d 19548 return TRUE;
a8bc6c78 19549 }
c921be7d 19550
a8bc6c78 19551 /* Process as normal. */
c921be7d 19552 return FALSE;
a8bc6c78
PB
19553}
19554
4a42ebbc
RR
19555/* Encode Thumb2 unconditional branches and calls. The encoding
19556 for the 2 are identical for the immediate values. */
19557
19558static void
19559encode_thumb2_b_bl_offset (char * buf, offsetT value)
19560{
19561#define T2I1I2MASK ((1 << 13) | (1 << 11))
19562 offsetT newval;
19563 offsetT newval2;
19564 addressT S, I1, I2, lo, hi;
19565
19566 S = (value >> 24) & 0x01;
19567 I1 = (value >> 23) & 0x01;
19568 I2 = (value >> 22) & 0x01;
19569 hi = (value >> 12) & 0x3ff;
19570 lo = (value >> 1) & 0x7ff;
19571 newval = md_chars_to_number (buf, THUMB_SIZE);
19572 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19573 newval |= (S << 10) | hi;
19574 newval2 &= ~T2I1I2MASK;
19575 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19576 md_number_to_chars (buf, newval, THUMB_SIZE);
19577 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19578}
19579
c19d1205 19580void
55cf6793 19581md_apply_fix (fixS * fixP,
c19d1205
ZW
19582 valueT * valP,
19583 segT seg)
19584{
19585 offsetT value = * valP;
19586 offsetT newval;
19587 unsigned int newimm;
19588 unsigned long temp;
19589 int sign;
19590 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19591
9c2799c2 19592 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19593
c19d1205 19594 /* Note whether this will delete the relocation. */
4962c51a 19595
c19d1205
ZW
19596 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19597 fixP->fx_done = 1;
b99bd4ef 19598
adbaf948 19599 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19600 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19601 for emit_reloc. */
19602 value &= 0xffffffff;
19603 value ^= 0x80000000;
5f4273c7 19604 value -= 0x80000000;
adbaf948
ZW
19605
19606 *valP = value;
c19d1205 19607 fixP->fx_addnumber = value;
b99bd4ef 19608
adbaf948
ZW
19609 /* Same treatment for fixP->fx_offset. */
19610 fixP->fx_offset &= 0xffffffff;
19611 fixP->fx_offset ^= 0x80000000;
19612 fixP->fx_offset -= 0x80000000;
19613
c19d1205 19614 switch (fixP->fx_r_type)
b99bd4ef 19615 {
c19d1205
ZW
19616 case BFD_RELOC_NONE:
19617 /* This will need to go in the object file. */
19618 fixP->fx_done = 0;
19619 break;
b99bd4ef 19620
c19d1205
ZW
19621 case BFD_RELOC_ARM_IMMEDIATE:
19622 /* We claim that this fixup has been processed here,
19623 even if in fact we generate an error because we do
19624 not have a reloc for it, so tc_gen_reloc will reject it. */
19625 fixP->fx_done = 1;
b99bd4ef 19626
c19d1205
ZW
19627 if (fixP->fx_addsy
19628 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 19629 {
c19d1205
ZW
19630 as_bad_where (fixP->fx_file, fixP->fx_line,
19631 _("undefined symbol %s used as an immediate value"),
19632 S_GET_NAME (fixP->fx_addsy));
19633 break;
b99bd4ef
NC
19634 }
19635
42e5fcbf
AS
19636 if (fixP->fx_addsy
19637 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19638 {
19639 as_bad_where (fixP->fx_file, fixP->fx_line,
19640 _("symbol %s is in a different section"),
19641 S_GET_NAME (fixP->fx_addsy));
19642 break;
19643 }
19644
c19d1205
ZW
19645 newimm = encode_arm_immediate (value);
19646 temp = md_chars_to_number (buf, INSN_SIZE);
19647
19648 /* If the instruction will fail, see if we can fix things up by
19649 changing the opcode. */
19650 if (newimm == (unsigned int) FAIL
19651 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19652 {
c19d1205
ZW
19653 as_bad_where (fixP->fx_file, fixP->fx_line,
19654 _("invalid constant (%lx) after fixup"),
19655 (unsigned long) value);
19656 break;
b99bd4ef 19657 }
b99bd4ef 19658
c19d1205
ZW
19659 newimm |= (temp & 0xfffff000);
19660 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19661 break;
b99bd4ef 19662
c19d1205
ZW
19663 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19664 {
19665 unsigned int highpart = 0;
19666 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19667
42e5fcbf
AS
19668 if (fixP->fx_addsy
19669 && ! S_IS_DEFINED (fixP->fx_addsy))
19670 {
19671 as_bad_where (fixP->fx_file, fixP->fx_line,
19672 _("undefined symbol %s used as an immediate value"),
19673 S_GET_NAME (fixP->fx_addsy));
19674 break;
19675 }
19676
19677 if (fixP->fx_addsy
19678 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19679 {
19680 as_bad_where (fixP->fx_file, fixP->fx_line,
19681 _("symbol %s is in a different section"),
19682 S_GET_NAME (fixP->fx_addsy));
19683 break;
19684 }
19685
c19d1205
ZW
19686 newimm = encode_arm_immediate (value);
19687 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19688
c19d1205
ZW
19689 /* If the instruction will fail, see if we can fix things up by
19690 changing the opcode. */
19691 if (newimm == (unsigned int) FAIL
19692 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19693 {
19694 /* No ? OK - try using two ADD instructions to generate
19695 the value. */
19696 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19697
c19d1205
ZW
19698 /* Yes - then make sure that the second instruction is
19699 also an add. */
19700 if (newimm != (unsigned int) FAIL)
19701 newinsn = temp;
19702 /* Still No ? Try using a negated value. */
19703 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19704 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19705 /* Otherwise - give up. */
19706 else
19707 {
19708 as_bad_where (fixP->fx_file, fixP->fx_line,
19709 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19710 (long) value);
19711 break;
19712 }
b99bd4ef 19713
c19d1205
ZW
19714 /* Replace the first operand in the 2nd instruction (which
19715 is the PC) with the destination register. We have
19716 already added in the PC in the first instruction and we
19717 do not want to do it again. */
19718 newinsn &= ~ 0xf0000;
19719 newinsn |= ((newinsn & 0x0f000) << 4);
19720 }
b99bd4ef 19721
c19d1205
ZW
19722 newimm |= (temp & 0xfffff000);
19723 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19724
c19d1205
ZW
19725 highpart |= (newinsn & 0xfffff000);
19726 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19727 }
19728 break;
b99bd4ef 19729
c19d1205 19730 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19731 if (!fixP->fx_done && seg->use_rela_p)
19732 value = 0;
19733
c19d1205
ZW
19734 case BFD_RELOC_ARM_LITERAL:
19735 sign = value >= 0;
b99bd4ef 19736
c19d1205
ZW
19737 if (value < 0)
19738 value = - value;
b99bd4ef 19739
c19d1205 19740 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19741 {
c19d1205
ZW
19742 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19743 as_bad_where (fixP->fx_file, fixP->fx_line,
19744 _("invalid literal constant: pool needs to be closer"));
19745 else
19746 as_bad_where (fixP->fx_file, fixP->fx_line,
19747 _("bad immediate value for offset (%ld)"),
19748 (long) value);
19749 break;
f03698e6
RE
19750 }
19751
c19d1205
ZW
19752 newval = md_chars_to_number (buf, INSN_SIZE);
19753 newval &= 0xff7ff000;
19754 newval |= value | (sign ? INDEX_UP : 0);
19755 md_number_to_chars (buf, newval, INSN_SIZE);
19756 break;
b99bd4ef 19757
c19d1205
ZW
19758 case BFD_RELOC_ARM_OFFSET_IMM8:
19759 case BFD_RELOC_ARM_HWLITERAL:
19760 sign = value >= 0;
b99bd4ef 19761
c19d1205
ZW
19762 if (value < 0)
19763 value = - value;
b99bd4ef 19764
c19d1205 19765 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19766 {
c19d1205
ZW
19767 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19768 as_bad_where (fixP->fx_file, fixP->fx_line,
19769 _("invalid literal constant: pool needs to be closer"));
19770 else
f9d4405b 19771 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19772 (long) value);
19773 break;
b99bd4ef
NC
19774 }
19775
c19d1205
ZW
19776 newval = md_chars_to_number (buf, INSN_SIZE);
19777 newval &= 0xff7ff0f0;
19778 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19779 md_number_to_chars (buf, newval, INSN_SIZE);
19780 break;
b99bd4ef 19781
c19d1205
ZW
19782 case BFD_RELOC_ARM_T32_OFFSET_U8:
19783 if (value < 0 || value > 1020 || value % 4 != 0)
19784 as_bad_where (fixP->fx_file, fixP->fx_line,
19785 _("bad immediate value for offset (%ld)"), (long) value);
19786 value /= 4;
b99bd4ef 19787
c19d1205 19788 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19789 newval |= value;
19790 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19791 break;
b99bd4ef 19792
c19d1205
ZW
19793 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19794 /* This is a complicated relocation used for all varieties of Thumb32
19795 load/store instruction with immediate offset:
19796
19797 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19798 *4, optional writeback(W)
19799 (doubleword load/store)
19800
19801 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19802 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19803 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19804 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19805 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19806
19807 Uppercase letters indicate bits that are already encoded at
19808 this point. Lowercase letters are our problem. For the
19809 second block of instructions, the secondary opcode nybble
19810 (bits 8..11) is present, and bit 23 is zero, even if this is
19811 a PC-relative operation. */
19812 newval = md_chars_to_number (buf, THUMB_SIZE);
19813 newval <<= 16;
19814 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19815
c19d1205 19816 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19817 {
c19d1205
ZW
19818 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19819 if (value >= 0)
19820 newval |= (1 << 23);
19821 else
19822 value = -value;
19823 if (value % 4 != 0)
19824 {
19825 as_bad_where (fixP->fx_file, fixP->fx_line,
19826 _("offset not a multiple of 4"));
19827 break;
19828 }
19829 value /= 4;
216d22bc 19830 if (value > 0xff)
c19d1205
ZW
19831 {
19832 as_bad_where (fixP->fx_file, fixP->fx_line,
19833 _("offset out of range"));
19834 break;
19835 }
19836 newval &= ~0xff;
b99bd4ef 19837 }
c19d1205 19838 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 19839 {
c19d1205
ZW
19840 /* PC-relative, 12-bit offset. */
19841 if (value >= 0)
19842 newval |= (1 << 23);
19843 else
19844 value = -value;
216d22bc 19845 if (value > 0xfff)
c19d1205
ZW
19846 {
19847 as_bad_where (fixP->fx_file, fixP->fx_line,
19848 _("offset out of range"));
19849 break;
19850 }
19851 newval &= ~0xfff;
b99bd4ef 19852 }
c19d1205 19853 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 19854 {
c19d1205
ZW
19855 /* Writeback: 8-bit, +/- offset. */
19856 if (value >= 0)
19857 newval |= (1 << 9);
19858 else
19859 value = -value;
216d22bc 19860 if (value > 0xff)
c19d1205
ZW
19861 {
19862 as_bad_where (fixP->fx_file, fixP->fx_line,
19863 _("offset out of range"));
19864 break;
19865 }
19866 newval &= ~0xff;
b99bd4ef 19867 }
c19d1205 19868 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 19869 {
c19d1205 19870 /* T-instruction: positive 8-bit offset. */
216d22bc 19871 if (value < 0 || value > 0xff)
b99bd4ef 19872 {
c19d1205
ZW
19873 as_bad_where (fixP->fx_file, fixP->fx_line,
19874 _("offset out of range"));
19875 break;
b99bd4ef 19876 }
c19d1205
ZW
19877 newval &= ~0xff;
19878 newval |= value;
b99bd4ef
NC
19879 }
19880 else
b99bd4ef 19881 {
c19d1205
ZW
19882 /* Positive 12-bit or negative 8-bit offset. */
19883 int limit;
19884 if (value >= 0)
b99bd4ef 19885 {
c19d1205
ZW
19886 newval |= (1 << 23);
19887 limit = 0xfff;
19888 }
19889 else
19890 {
19891 value = -value;
19892 limit = 0xff;
19893 }
19894 if (value > limit)
19895 {
19896 as_bad_where (fixP->fx_file, fixP->fx_line,
19897 _("offset out of range"));
19898 break;
b99bd4ef 19899 }
c19d1205 19900 newval &= ~limit;
b99bd4ef 19901 }
b99bd4ef 19902
c19d1205
ZW
19903 newval |= value;
19904 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
19905 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
19906 break;
404ff6b5 19907
c19d1205
ZW
19908 case BFD_RELOC_ARM_SHIFT_IMM:
19909 newval = md_chars_to_number (buf, INSN_SIZE);
19910 if (((unsigned long) value) > 32
19911 || (value == 32
19912 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
19913 {
19914 as_bad_where (fixP->fx_file, fixP->fx_line,
19915 _("shift expression is too large"));
19916 break;
19917 }
404ff6b5 19918
c19d1205
ZW
19919 if (value == 0)
19920 /* Shifts of zero must be done as lsl. */
19921 newval &= ~0x60;
19922 else if (value == 32)
19923 value = 0;
19924 newval &= 0xfffff07f;
19925 newval |= (value & 0x1f) << 7;
19926 md_number_to_chars (buf, newval, INSN_SIZE);
19927 break;
404ff6b5 19928
c19d1205 19929 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 19930 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 19931 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 19932 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
19933 /* We claim that this fixup has been processed here,
19934 even if in fact we generate an error because we do
19935 not have a reloc for it, so tc_gen_reloc will reject it. */
19936 fixP->fx_done = 1;
404ff6b5 19937
c19d1205
ZW
19938 if (fixP->fx_addsy
19939 && ! S_IS_DEFINED (fixP->fx_addsy))
19940 {
19941 as_bad_where (fixP->fx_file, fixP->fx_line,
19942 _("undefined symbol %s used as an immediate value"),
19943 S_GET_NAME (fixP->fx_addsy));
19944 break;
19945 }
404ff6b5 19946
c19d1205
ZW
19947 newval = md_chars_to_number (buf, THUMB_SIZE);
19948 newval <<= 16;
19949 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 19950
16805f35
PB
19951 newimm = FAIL;
19952 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19953 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
19954 {
19955 newimm = encode_thumb32_immediate (value);
19956 if (newimm == (unsigned int) FAIL)
19957 newimm = thumb32_negate_data_op (&newval, value);
19958 }
16805f35
PB
19959 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19960 && newimm == (unsigned int) FAIL)
92e90b6e 19961 {
16805f35
PB
19962 /* Turn add/sum into addw/subw. */
19963 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19964 newval = (newval & 0xfeffffff) | 0x02000000;
19965
e9f89963
PB
19966 /* 12 bit immediate for addw/subw. */
19967 if (value < 0)
19968 {
19969 value = -value;
19970 newval ^= 0x00a00000;
19971 }
92e90b6e
PB
19972 if (value > 0xfff)
19973 newimm = (unsigned int) FAIL;
19974 else
19975 newimm = value;
19976 }
cc8a6dd0 19977
c19d1205 19978 if (newimm == (unsigned int)FAIL)
3631a3c8 19979 {
c19d1205
ZW
19980 as_bad_where (fixP->fx_file, fixP->fx_line,
19981 _("invalid constant (%lx) after fixup"),
19982 (unsigned long) value);
19983 break;
3631a3c8
NC
19984 }
19985
c19d1205
ZW
19986 newval |= (newimm & 0x800) << 15;
19987 newval |= (newimm & 0x700) << 4;
19988 newval |= (newimm & 0x0ff);
cc8a6dd0 19989
c19d1205
ZW
19990 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
19991 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
19992 break;
a737bd4d 19993
3eb17e6b 19994 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
19995 if (((unsigned long) value) > 0xffff)
19996 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 19997 _("invalid smc expression"));
2fc8bdac 19998 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19999 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20000 md_number_to_chars (buf, newval, INSN_SIZE);
20001 break;
a737bd4d 20002
c19d1205 20003 case BFD_RELOC_ARM_SWI:
adbaf948 20004 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20005 {
20006 if (((unsigned long) value) > 0xff)
20007 as_bad_where (fixP->fx_file, fixP->fx_line,
20008 _("invalid swi expression"));
2fc8bdac 20009 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20010 newval |= value;
20011 md_number_to_chars (buf, newval, THUMB_SIZE);
20012 }
20013 else
20014 {
20015 if (((unsigned long) value) > 0x00ffffff)
20016 as_bad_where (fixP->fx_file, fixP->fx_line,
20017 _("invalid swi expression"));
2fc8bdac 20018 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20019 newval |= value;
20020 md_number_to_chars (buf, newval, INSN_SIZE);
20021 }
20022 break;
a737bd4d 20023
c19d1205
ZW
20024 case BFD_RELOC_ARM_MULTI:
20025 if (((unsigned long) value) > 0xffff)
20026 as_bad_where (fixP->fx_file, fixP->fx_line,
20027 _("invalid expression in load/store multiple"));
20028 newval = value | md_chars_to_number (buf, INSN_SIZE);
20029 md_number_to_chars (buf, newval, INSN_SIZE);
20030 break;
a737bd4d 20031
c19d1205 20032#ifdef OBJ_ELF
39b41c9c 20033 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20034
20035 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20036 && fixP->fx_addsy
20037 && !S_IS_EXTERNAL (fixP->fx_addsy)
20038 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20039 && THUMB_IS_FUNC (fixP->fx_addsy))
20040 /* Flip the bl to blx. This is a simple flip
20041 bit here because we generate PCREL_CALL for
20042 unconditional bls. */
20043 {
20044 newval = md_chars_to_number (buf, INSN_SIZE);
20045 newval = newval | 0x10000000;
20046 md_number_to_chars (buf, newval, INSN_SIZE);
20047 temp = 1;
20048 fixP->fx_done = 1;
20049 }
39b41c9c
PB
20050 else
20051 temp = 3;
20052 goto arm_branch_common;
20053
20054 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20055 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20056 && fixP->fx_addsy
20057 && !S_IS_EXTERNAL (fixP->fx_addsy)
20058 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20059 && THUMB_IS_FUNC (fixP->fx_addsy))
20060 {
20061 /* This would map to a bl<cond>, b<cond>,
20062 b<always> to a Thumb function. We
20063 need to force a relocation for this particular
20064 case. */
20065 newval = md_chars_to_number (buf, INSN_SIZE);
20066 fixP->fx_done = 0;
20067 }
20068
2fc8bdac 20069 case BFD_RELOC_ARM_PLT32:
c19d1205 20070#endif
39b41c9c
PB
20071 case BFD_RELOC_ARM_PCREL_BRANCH:
20072 temp = 3;
20073 goto arm_branch_common;
a737bd4d 20074
39b41c9c 20075 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20076
39b41c9c 20077 temp = 1;
267bf995
RR
20078 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20079 && fixP->fx_addsy
20080 && !S_IS_EXTERNAL (fixP->fx_addsy)
20081 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20082 && ARM_IS_FUNC (fixP->fx_addsy))
20083 {
20084 /* Flip the blx to a bl and warn. */
20085 const char *name = S_GET_NAME (fixP->fx_addsy);
20086 newval = 0xeb000000;
20087 as_warn_where (fixP->fx_file, fixP->fx_line,
20088 _("blx to '%s' an ARM ISA state function changed to bl"),
20089 name);
20090 md_number_to_chars (buf, newval, INSN_SIZE);
20091 temp = 3;
20092 fixP->fx_done = 1;
20093 }
20094
20095#ifdef OBJ_ELF
20096 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20097 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20098#endif
20099
39b41c9c 20100 arm_branch_common:
c19d1205 20101 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20102 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20103 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20104 also be be clear. */
20105 if (value & temp)
c19d1205 20106 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20107 _("misaligned branch destination"));
20108 if ((value & (offsetT)0xfe000000) != (offsetT)0
20109 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20110 as_bad_where (fixP->fx_file, fixP->fx_line,
20111 _("branch out of range"));
a737bd4d 20112
2fc8bdac 20113 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20114 {
2fc8bdac
ZW
20115 newval = md_chars_to_number (buf, INSN_SIZE);
20116 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20117 /* Set the H bit on BLX instructions. */
20118 if (temp == 1)
20119 {
20120 if (value & 2)
20121 newval |= 0x01000000;
20122 else
20123 newval &= ~0x01000000;
20124 }
2fc8bdac 20125 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20126 }
c19d1205 20127 break;
a737bd4d 20128
25fe350b
MS
20129 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20130 /* CBZ can only branch forward. */
a737bd4d 20131
738755b0
MS
20132 /* Attempts to use CBZ to branch to the next instruction
20133 (which, strictly speaking, are prohibited) will be turned into
20134 no-ops.
20135
20136 FIXME: It may be better to remove the instruction completely and
20137 perform relaxation. */
20138 if (value == -2)
2fc8bdac
ZW
20139 {
20140 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20141 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20142 md_number_to_chars (buf, newval, THUMB_SIZE);
20143 }
738755b0
MS
20144 else
20145 {
20146 if (value & ~0x7e)
20147 as_bad_where (fixP->fx_file, fixP->fx_line,
20148 _("branch out of range"));
20149
20150 if (fixP->fx_done || !seg->use_rela_p)
20151 {
20152 newval = md_chars_to_number (buf, THUMB_SIZE);
20153 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20154 md_number_to_chars (buf, newval, THUMB_SIZE);
20155 }
20156 }
c19d1205 20157 break;
a737bd4d 20158
c19d1205 20159 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20160 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20161 as_bad_where (fixP->fx_file, fixP->fx_line,
20162 _("branch out of range"));
a737bd4d 20163
2fc8bdac
ZW
20164 if (fixP->fx_done || !seg->use_rela_p)
20165 {
20166 newval = md_chars_to_number (buf, THUMB_SIZE);
20167 newval |= (value & 0x1ff) >> 1;
20168 md_number_to_chars (buf, newval, THUMB_SIZE);
20169 }
c19d1205 20170 break;
a737bd4d 20171
c19d1205 20172 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20173 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20174 as_bad_where (fixP->fx_file, fixP->fx_line,
20175 _("branch out of range"));
a737bd4d 20176
2fc8bdac
ZW
20177 if (fixP->fx_done || !seg->use_rela_p)
20178 {
20179 newval = md_chars_to_number (buf, THUMB_SIZE);
20180 newval |= (value & 0xfff) >> 1;
20181 md_number_to_chars (buf, newval, THUMB_SIZE);
20182 }
c19d1205 20183 break;
a737bd4d 20184
c19d1205 20185 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20186 if (fixP->fx_addsy
20187 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20188 && !S_IS_EXTERNAL (fixP->fx_addsy)
20189 && S_IS_DEFINED (fixP->fx_addsy)
20190 && ARM_IS_FUNC (fixP->fx_addsy)
20191 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20192 {
20193 /* Force a relocation for a branch 20 bits wide. */
20194 fixP->fx_done = 0;
20195 }
2fc8bdac
ZW
20196 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20197 as_bad_where (fixP->fx_file, fixP->fx_line,
20198 _("conditional branch out of range"));
404ff6b5 20199
2fc8bdac
ZW
20200 if (fixP->fx_done || !seg->use_rela_p)
20201 {
20202 offsetT newval2;
20203 addressT S, J1, J2, lo, hi;
404ff6b5 20204
2fc8bdac
ZW
20205 S = (value & 0x00100000) >> 20;
20206 J2 = (value & 0x00080000) >> 19;
20207 J1 = (value & 0x00040000) >> 18;
20208 hi = (value & 0x0003f000) >> 12;
20209 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20210
2fc8bdac
ZW
20211 newval = md_chars_to_number (buf, THUMB_SIZE);
20212 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20213 newval |= (S << 10) | hi;
20214 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20215 md_number_to_chars (buf, newval, THUMB_SIZE);
20216 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20217 }
c19d1205 20218 break;
6c43fab6 20219
c19d1205 20220 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20221
20222 /* If there is a blx from a thumb state function to
20223 another thumb function flip this to a bl and warn
20224 about it. */
20225
20226 if (fixP->fx_addsy
20227 && S_IS_DEFINED (fixP->fx_addsy)
20228 && !S_IS_EXTERNAL (fixP->fx_addsy)
20229 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20230 && THUMB_IS_FUNC (fixP->fx_addsy))
20231 {
20232 const char *name = S_GET_NAME (fixP->fx_addsy);
20233 as_warn_where (fixP->fx_file, fixP->fx_line,
20234 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20235 name);
20236 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20237 newval = newval | 0x1000;
20238 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20239 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20240 fixP->fx_done = 1;
20241 }
20242
20243
20244 goto thumb_bl_common;
20245
c19d1205 20246 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20247
20248 /* A bl from Thumb state ISA to an internal ARM state function
20249 is converted to a blx. */
20250 if (fixP->fx_addsy
20251 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20252 && !S_IS_EXTERNAL (fixP->fx_addsy)
20253 && S_IS_DEFINED (fixP->fx_addsy)
20254 && ARM_IS_FUNC (fixP->fx_addsy)
20255 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20256 {
20257 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20258 newval = newval & ~0x1000;
20259 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20260 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20261 fixP->fx_done = 1;
20262 }
20263
20264 thumb_bl_common:
20265
20266#ifdef OBJ_ELF
20267 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20268 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20269 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20270#endif
20271
2fc8bdac
ZW
20272 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20273 /* For a BLX instruction, make sure that the relocation is rounded up
20274 to a word boundary. This follows the semantics of the instruction
20275 which specifies that bit 1 of the target address will come from bit
20276 1 of the base address. */
20277 value = (value + 1) & ~ 1;
404ff6b5 20278
2fc8bdac 20279
4a42ebbc
RR
20280 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20281 {
20282 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20283 {
20284 as_bad_where (fixP->fx_file, fixP->fx_line,
20285 _("branch out of range"));
20286 }
20287 else if ((value & ~0x1ffffff)
20288 && ((value & ~0x1ffffff) != ~0x1ffffff))
20289 {
20290 as_bad_where (fixP->fx_file, fixP->fx_line,
20291 _("Thumb2 branch out of range"));
20292 }
c19d1205 20293 }
4a42ebbc
RR
20294
20295 if (fixP->fx_done || !seg->use_rela_p)
20296 encode_thumb2_b_bl_offset (buf, value);
20297
c19d1205 20298 break;
404ff6b5 20299
c19d1205 20300 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20301 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20302 as_bad_where (fixP->fx_file, fixP->fx_line,
20303 _("branch out of range"));
6c43fab6 20304
2fc8bdac 20305 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20306 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20307
2fc8bdac 20308 break;
a737bd4d 20309
2fc8bdac
ZW
20310 case BFD_RELOC_8:
20311 if (fixP->fx_done || !seg->use_rela_p)
20312 md_number_to_chars (buf, value, 1);
c19d1205 20313 break;
a737bd4d 20314
c19d1205 20315 case BFD_RELOC_16:
2fc8bdac 20316 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20317 md_number_to_chars (buf, value, 2);
c19d1205 20318 break;
a737bd4d 20319
c19d1205
ZW
20320#ifdef OBJ_ELF
20321 case BFD_RELOC_ARM_TLS_GD32:
20322 case BFD_RELOC_ARM_TLS_LE32:
20323 case BFD_RELOC_ARM_TLS_IE32:
20324 case BFD_RELOC_ARM_TLS_LDM32:
20325 case BFD_RELOC_ARM_TLS_LDO32:
20326 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20327 /* fall through */
6c43fab6 20328
c19d1205
ZW
20329 case BFD_RELOC_ARM_GOT32:
20330 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20331 if (fixP->fx_done || !seg->use_rela_p)
20332 md_number_to_chars (buf, 0, 4);
c19d1205 20333 break;
9a6f4e97
NS
20334
20335 case BFD_RELOC_ARM_TARGET2:
20336 /* TARGET2 is not partial-inplace, so we need to write the
20337 addend here for REL targets, because it won't be written out
20338 during reloc processing later. */
20339 if (fixP->fx_done || !seg->use_rela_p)
20340 md_number_to_chars (buf, fixP->fx_offset, 4);
20341 break;
c19d1205 20342#endif
6c43fab6 20343
c19d1205
ZW
20344 case BFD_RELOC_RVA:
20345 case BFD_RELOC_32:
20346 case BFD_RELOC_ARM_TARGET1:
20347 case BFD_RELOC_ARM_ROSEGREL32:
20348 case BFD_RELOC_ARM_SBREL32:
20349 case BFD_RELOC_32_PCREL:
f0927246
NC
20350#ifdef TE_PE
20351 case BFD_RELOC_32_SECREL:
20352#endif
2fc8bdac 20353 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20354#ifdef TE_WINCE
20355 /* For WinCE we only do this for pcrel fixups. */
20356 if (fixP->fx_done || fixP->fx_pcrel)
20357#endif
20358 md_number_to_chars (buf, value, 4);
c19d1205 20359 break;
6c43fab6 20360
c19d1205
ZW
20361#ifdef OBJ_ELF
20362 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20363 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20364 {
20365 newval = md_chars_to_number (buf, 4) & 0x80000000;
20366 if ((value ^ (value >> 1)) & 0x40000000)
20367 {
20368 as_bad_where (fixP->fx_file, fixP->fx_line,
20369 _("rel31 relocation overflow"));
20370 }
20371 newval |= value & 0x7fffffff;
20372 md_number_to_chars (buf, newval, 4);
20373 }
20374 break;
c19d1205 20375#endif
a737bd4d 20376
c19d1205 20377 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20378 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20379 if (value < -1023 || value > 1023 || (value & 3))
20380 as_bad_where (fixP->fx_file, fixP->fx_line,
20381 _("co-processor offset out of range"));
20382 cp_off_common:
20383 sign = value >= 0;
20384 if (value < 0)
20385 value = -value;
8f06b2d8
PB
20386 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20387 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20388 newval = md_chars_to_number (buf, INSN_SIZE);
20389 else
20390 newval = get_thumb32_insn (buf);
20391 newval &= 0xff7fff00;
c19d1205 20392 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20393 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20394 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20395 md_number_to_chars (buf, newval, INSN_SIZE);
20396 else
20397 put_thumb32_insn (buf, newval);
c19d1205 20398 break;
a737bd4d 20399
c19d1205 20400 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20401 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20402 if (value < -255 || value > 255)
20403 as_bad_where (fixP->fx_file, fixP->fx_line,
20404 _("co-processor offset out of range"));
df7849c5 20405 value *= 4;
c19d1205 20406 goto cp_off_common;
6c43fab6 20407
c19d1205
ZW
20408 case BFD_RELOC_ARM_THUMB_OFFSET:
20409 newval = md_chars_to_number (buf, THUMB_SIZE);
20410 /* Exactly what ranges, and where the offset is inserted depends
20411 on the type of instruction, we can establish this from the
20412 top 4 bits. */
20413 switch (newval >> 12)
20414 {
20415 case 4: /* PC load. */
20416 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20417 forced to zero for these loads; md_pcrel_from has already
20418 compensated for this. */
20419 if (value & 3)
20420 as_bad_where (fixP->fx_file, fixP->fx_line,
20421 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20422 (((unsigned long) fixP->fx_frag->fr_address
20423 + (unsigned long) fixP->fx_where) & ~3)
20424 + (unsigned long) value);
a737bd4d 20425
c19d1205
ZW
20426 if (value & ~0x3fc)
20427 as_bad_where (fixP->fx_file, fixP->fx_line,
20428 _("invalid offset, value too big (0x%08lX)"),
20429 (long) value);
a737bd4d 20430
c19d1205
ZW
20431 newval |= value >> 2;
20432 break;
a737bd4d 20433
c19d1205
ZW
20434 case 9: /* SP load/store. */
20435 if (value & ~0x3fc)
20436 as_bad_where (fixP->fx_file, fixP->fx_line,
20437 _("invalid offset, value too big (0x%08lX)"),
20438 (long) value);
20439 newval |= value >> 2;
20440 break;
6c43fab6 20441
c19d1205
ZW
20442 case 6: /* Word load/store. */
20443 if (value & ~0x7c)
20444 as_bad_where (fixP->fx_file, fixP->fx_line,
20445 _("invalid offset, value too big (0x%08lX)"),
20446 (long) value);
20447 newval |= value << 4; /* 6 - 2. */
20448 break;
a737bd4d 20449
c19d1205
ZW
20450 case 7: /* Byte load/store. */
20451 if (value & ~0x1f)
20452 as_bad_where (fixP->fx_file, fixP->fx_line,
20453 _("invalid offset, value too big (0x%08lX)"),
20454 (long) value);
20455 newval |= value << 6;
20456 break;
a737bd4d 20457
c19d1205
ZW
20458 case 8: /* Halfword load/store. */
20459 if (value & ~0x3e)
20460 as_bad_where (fixP->fx_file, fixP->fx_line,
20461 _("invalid offset, value too big (0x%08lX)"),
20462 (long) value);
20463 newval |= value << 5; /* 6 - 1. */
20464 break;
a737bd4d 20465
c19d1205
ZW
20466 default:
20467 as_bad_where (fixP->fx_file, fixP->fx_line,
20468 "Unable to process relocation for thumb opcode: %lx",
20469 (unsigned long) newval);
20470 break;
20471 }
20472 md_number_to_chars (buf, newval, THUMB_SIZE);
20473 break;
a737bd4d 20474
c19d1205
ZW
20475 case BFD_RELOC_ARM_THUMB_ADD:
20476 /* This is a complicated relocation, since we use it for all of
20477 the following immediate relocations:
a737bd4d 20478
c19d1205
ZW
20479 3bit ADD/SUB
20480 8bit ADD/SUB
20481 9bit ADD/SUB SP word-aligned
20482 10bit ADD PC/SP word-aligned
a737bd4d 20483
c19d1205
ZW
20484 The type of instruction being processed is encoded in the
20485 instruction field:
a737bd4d 20486
c19d1205
ZW
20487 0x8000 SUB
20488 0x00F0 Rd
20489 0x000F Rs
20490 */
20491 newval = md_chars_to_number (buf, THUMB_SIZE);
20492 {
20493 int rd = (newval >> 4) & 0xf;
20494 int rs = newval & 0xf;
20495 int subtract = !!(newval & 0x8000);
a737bd4d 20496
c19d1205
ZW
20497 /* Check for HI regs, only very restricted cases allowed:
20498 Adjusting SP, and using PC or SP to get an address. */
20499 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20500 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20501 as_bad_where (fixP->fx_file, fixP->fx_line,
20502 _("invalid Hi register with immediate"));
a737bd4d 20503
c19d1205
ZW
20504 /* If value is negative, choose the opposite instruction. */
20505 if (value < 0)
20506 {
20507 value = -value;
20508 subtract = !subtract;
20509 if (value < 0)
20510 as_bad_where (fixP->fx_file, fixP->fx_line,
20511 _("immediate value out of range"));
20512 }
a737bd4d 20513
c19d1205
ZW
20514 if (rd == REG_SP)
20515 {
20516 if (value & ~0x1fc)
20517 as_bad_where (fixP->fx_file, fixP->fx_line,
20518 _("invalid immediate for stack address calculation"));
20519 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20520 newval |= value >> 2;
20521 }
20522 else if (rs == REG_PC || rs == REG_SP)
20523 {
20524 if (subtract || value & ~0x3fc)
20525 as_bad_where (fixP->fx_file, fixP->fx_line,
20526 _("invalid immediate for address calculation (value = 0x%08lX)"),
20527 (unsigned long) value);
20528 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20529 newval |= rd << 8;
20530 newval |= value >> 2;
20531 }
20532 else if (rs == rd)
20533 {
20534 if (value & ~0xff)
20535 as_bad_where (fixP->fx_file, fixP->fx_line,
20536 _("immediate value out of range"));
20537 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20538 newval |= (rd << 8) | value;
20539 }
20540 else
20541 {
20542 if (value & ~0x7)
20543 as_bad_where (fixP->fx_file, fixP->fx_line,
20544 _("immediate value out of range"));
20545 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20546 newval |= rd | (rs << 3) | (value << 6);
20547 }
20548 }
20549 md_number_to_chars (buf, newval, THUMB_SIZE);
20550 break;
a737bd4d 20551
c19d1205
ZW
20552 case BFD_RELOC_ARM_THUMB_IMM:
20553 newval = md_chars_to_number (buf, THUMB_SIZE);
20554 if (value < 0 || value > 255)
20555 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20556 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20557 (long) value);
20558 newval |= value;
20559 md_number_to_chars (buf, newval, THUMB_SIZE);
20560 break;
a737bd4d 20561
c19d1205
ZW
20562 case BFD_RELOC_ARM_THUMB_SHIFT:
20563 /* 5bit shift value (0..32). LSL cannot take 32. */
20564 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20565 temp = newval & 0xf800;
20566 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20567 as_bad_where (fixP->fx_file, fixP->fx_line,
20568 _("invalid shift value: %ld"), (long) value);
20569 /* Shifts of zero must be encoded as LSL. */
20570 if (value == 0)
20571 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20572 /* Shifts of 32 are encoded as zero. */
20573 else if (value == 32)
20574 value = 0;
20575 newval |= value << 6;
20576 md_number_to_chars (buf, newval, THUMB_SIZE);
20577 break;
a737bd4d 20578
c19d1205
ZW
20579 case BFD_RELOC_VTABLE_INHERIT:
20580 case BFD_RELOC_VTABLE_ENTRY:
20581 fixP->fx_done = 0;
20582 return;
6c43fab6 20583
b6895b4f
PB
20584 case BFD_RELOC_ARM_MOVW:
20585 case BFD_RELOC_ARM_MOVT:
20586 case BFD_RELOC_ARM_THUMB_MOVW:
20587 case BFD_RELOC_ARM_THUMB_MOVT:
20588 if (fixP->fx_done || !seg->use_rela_p)
20589 {
20590 /* REL format relocations are limited to a 16-bit addend. */
20591 if (!fixP->fx_done)
20592 {
39623e12 20593 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20594 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20595 _("offset out of range"));
b6895b4f
PB
20596 }
20597 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20598 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20599 {
20600 value >>= 16;
20601 }
20602
20603 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20604 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20605 {
20606 newval = get_thumb32_insn (buf);
20607 newval &= 0xfbf08f00;
20608 newval |= (value & 0xf000) << 4;
20609 newval |= (value & 0x0800) << 15;
20610 newval |= (value & 0x0700) << 4;
20611 newval |= (value & 0x00ff);
20612 put_thumb32_insn (buf, newval);
20613 }
20614 else
20615 {
20616 newval = md_chars_to_number (buf, 4);
20617 newval &= 0xfff0f000;
20618 newval |= value & 0x0fff;
20619 newval |= (value & 0xf000) << 4;
20620 md_number_to_chars (buf, newval, 4);
20621 }
20622 }
20623 return;
20624
4962c51a
MS
20625 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20626 case BFD_RELOC_ARM_ALU_PC_G0:
20627 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20628 case BFD_RELOC_ARM_ALU_PC_G1:
20629 case BFD_RELOC_ARM_ALU_PC_G2:
20630 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20631 case BFD_RELOC_ARM_ALU_SB_G0:
20632 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20633 case BFD_RELOC_ARM_ALU_SB_G1:
20634 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20635 gas_assert (!fixP->fx_done);
4962c51a
MS
20636 if (!seg->use_rela_p)
20637 {
20638 bfd_vma insn;
20639 bfd_vma encoded_addend;
20640 bfd_vma addend_abs = abs (value);
20641
20642 /* Check that the absolute value of the addend can be
20643 expressed as an 8-bit constant plus a rotation. */
20644 encoded_addend = encode_arm_immediate (addend_abs);
20645 if (encoded_addend == (unsigned int) FAIL)
20646 as_bad_where (fixP->fx_file, fixP->fx_line,
20647 _("the offset 0x%08lX is not representable"),
495bde8e 20648 (unsigned long) addend_abs);
4962c51a
MS
20649
20650 /* Extract the instruction. */
20651 insn = md_chars_to_number (buf, INSN_SIZE);
20652
20653 /* If the addend is positive, use an ADD instruction.
20654 Otherwise use a SUB. Take care not to destroy the S bit. */
20655 insn &= 0xff1fffff;
20656 if (value < 0)
20657 insn |= 1 << 22;
20658 else
20659 insn |= 1 << 23;
20660
20661 /* Place the encoded addend into the first 12 bits of the
20662 instruction. */
20663 insn &= 0xfffff000;
20664 insn |= encoded_addend;
5f4273c7
NC
20665
20666 /* Update the instruction. */
4962c51a
MS
20667 md_number_to_chars (buf, insn, INSN_SIZE);
20668 }
20669 break;
20670
20671 case BFD_RELOC_ARM_LDR_PC_G0:
20672 case BFD_RELOC_ARM_LDR_PC_G1:
20673 case BFD_RELOC_ARM_LDR_PC_G2:
20674 case BFD_RELOC_ARM_LDR_SB_G0:
20675 case BFD_RELOC_ARM_LDR_SB_G1:
20676 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20677 gas_assert (!fixP->fx_done);
4962c51a
MS
20678 if (!seg->use_rela_p)
20679 {
20680 bfd_vma insn;
20681 bfd_vma addend_abs = abs (value);
20682
20683 /* Check that the absolute value of the addend can be
20684 encoded in 12 bits. */
20685 if (addend_abs >= 0x1000)
20686 as_bad_where (fixP->fx_file, fixP->fx_line,
20687 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20688 (unsigned long) addend_abs);
4962c51a
MS
20689
20690 /* Extract the instruction. */
20691 insn = md_chars_to_number (buf, INSN_SIZE);
20692
20693 /* If the addend is negative, clear bit 23 of the instruction.
20694 Otherwise set it. */
20695 if (value < 0)
20696 insn &= ~(1 << 23);
20697 else
20698 insn |= 1 << 23;
20699
20700 /* Place the absolute value of the addend into the first 12 bits
20701 of the instruction. */
20702 insn &= 0xfffff000;
20703 insn |= addend_abs;
5f4273c7
NC
20704
20705 /* Update the instruction. */
4962c51a
MS
20706 md_number_to_chars (buf, insn, INSN_SIZE);
20707 }
20708 break;
20709
20710 case BFD_RELOC_ARM_LDRS_PC_G0:
20711 case BFD_RELOC_ARM_LDRS_PC_G1:
20712 case BFD_RELOC_ARM_LDRS_PC_G2:
20713 case BFD_RELOC_ARM_LDRS_SB_G0:
20714 case BFD_RELOC_ARM_LDRS_SB_G1:
20715 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20716 gas_assert (!fixP->fx_done);
4962c51a
MS
20717 if (!seg->use_rela_p)
20718 {
20719 bfd_vma insn;
20720 bfd_vma addend_abs = abs (value);
20721
20722 /* Check that the absolute value of the addend can be
20723 encoded in 8 bits. */
20724 if (addend_abs >= 0x100)
20725 as_bad_where (fixP->fx_file, fixP->fx_line,
20726 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20727 (unsigned long) addend_abs);
4962c51a
MS
20728
20729 /* Extract the instruction. */
20730 insn = md_chars_to_number (buf, INSN_SIZE);
20731
20732 /* If the addend is negative, clear bit 23 of the instruction.
20733 Otherwise set it. */
20734 if (value < 0)
20735 insn &= ~(1 << 23);
20736 else
20737 insn |= 1 << 23;
20738
20739 /* Place the first four bits of the absolute value of the addend
20740 into the first 4 bits of the instruction, and the remaining
20741 four into bits 8 .. 11. */
20742 insn &= 0xfffff0f0;
20743 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20744
20745 /* Update the instruction. */
4962c51a
MS
20746 md_number_to_chars (buf, insn, INSN_SIZE);
20747 }
20748 break;
20749
20750 case BFD_RELOC_ARM_LDC_PC_G0:
20751 case BFD_RELOC_ARM_LDC_PC_G1:
20752 case BFD_RELOC_ARM_LDC_PC_G2:
20753 case BFD_RELOC_ARM_LDC_SB_G0:
20754 case BFD_RELOC_ARM_LDC_SB_G1:
20755 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20756 gas_assert (!fixP->fx_done);
4962c51a
MS
20757 if (!seg->use_rela_p)
20758 {
20759 bfd_vma insn;
20760 bfd_vma addend_abs = abs (value);
20761
20762 /* Check that the absolute value of the addend is a multiple of
20763 four and, when divided by four, fits in 8 bits. */
20764 if (addend_abs & 0x3)
20765 as_bad_where (fixP->fx_file, fixP->fx_line,
20766 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20767 (unsigned long) addend_abs);
4962c51a
MS
20768
20769 if ((addend_abs >> 2) > 0xff)
20770 as_bad_where (fixP->fx_file, fixP->fx_line,
20771 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20772 (unsigned long) addend_abs);
4962c51a
MS
20773
20774 /* Extract the instruction. */
20775 insn = md_chars_to_number (buf, INSN_SIZE);
20776
20777 /* If the addend is negative, clear bit 23 of the instruction.
20778 Otherwise set it. */
20779 if (value < 0)
20780 insn &= ~(1 << 23);
20781 else
20782 insn |= 1 << 23;
20783
20784 /* Place the addend (divided by four) into the first eight
20785 bits of the instruction. */
20786 insn &= 0xfffffff0;
20787 insn |= addend_abs >> 2;
5f4273c7
NC
20788
20789 /* Update the instruction. */
4962c51a
MS
20790 md_number_to_chars (buf, insn, INSN_SIZE);
20791 }
20792 break;
20793
845b51d6
PB
20794 case BFD_RELOC_ARM_V4BX:
20795 /* This will need to go in the object file. */
20796 fixP->fx_done = 0;
20797 break;
20798
c19d1205
ZW
20799 case BFD_RELOC_UNUSED:
20800 default:
20801 as_bad_where (fixP->fx_file, fixP->fx_line,
20802 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20803 }
6c43fab6
RE
20804}
20805
c19d1205
ZW
20806/* Translate internal representation of relocation info to BFD target
20807 format. */
a737bd4d 20808
c19d1205 20809arelent *
00a97672 20810tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20811{
c19d1205
ZW
20812 arelent * reloc;
20813 bfd_reloc_code_real_type code;
a737bd4d 20814
21d799b5 20815 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 20816
21d799b5 20817 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
20818 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20819 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20820
2fc8bdac 20821 if (fixp->fx_pcrel)
00a97672
RS
20822 {
20823 if (section->use_rela_p)
20824 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20825 else
20826 fixp->fx_offset = reloc->address;
20827 }
c19d1205 20828 reloc->addend = fixp->fx_offset;
a737bd4d 20829
c19d1205 20830 switch (fixp->fx_r_type)
a737bd4d 20831 {
c19d1205
ZW
20832 case BFD_RELOC_8:
20833 if (fixp->fx_pcrel)
20834 {
20835 code = BFD_RELOC_8_PCREL;
20836 break;
20837 }
a737bd4d 20838
c19d1205
ZW
20839 case BFD_RELOC_16:
20840 if (fixp->fx_pcrel)
20841 {
20842 code = BFD_RELOC_16_PCREL;
20843 break;
20844 }
6c43fab6 20845
c19d1205
ZW
20846 case BFD_RELOC_32:
20847 if (fixp->fx_pcrel)
20848 {
20849 code = BFD_RELOC_32_PCREL;
20850 break;
20851 }
a737bd4d 20852
b6895b4f
PB
20853 case BFD_RELOC_ARM_MOVW:
20854 if (fixp->fx_pcrel)
20855 {
20856 code = BFD_RELOC_ARM_MOVW_PCREL;
20857 break;
20858 }
20859
20860 case BFD_RELOC_ARM_MOVT:
20861 if (fixp->fx_pcrel)
20862 {
20863 code = BFD_RELOC_ARM_MOVT_PCREL;
20864 break;
20865 }
20866
20867 case BFD_RELOC_ARM_THUMB_MOVW:
20868 if (fixp->fx_pcrel)
20869 {
20870 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20871 break;
20872 }
20873
20874 case BFD_RELOC_ARM_THUMB_MOVT:
20875 if (fixp->fx_pcrel)
20876 {
20877 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20878 break;
20879 }
20880
c19d1205
ZW
20881 case BFD_RELOC_NONE:
20882 case BFD_RELOC_ARM_PCREL_BRANCH:
20883 case BFD_RELOC_ARM_PCREL_BLX:
20884 case BFD_RELOC_RVA:
20885 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20886 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20887 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20888 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20889 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20890 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
20891 case BFD_RELOC_VTABLE_ENTRY:
20892 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
20893#ifdef TE_PE
20894 case BFD_RELOC_32_SECREL:
20895#endif
c19d1205
ZW
20896 code = fixp->fx_r_type;
20897 break;
a737bd4d 20898
00adf2d4
JB
20899 case BFD_RELOC_THUMB_PCREL_BLX:
20900#ifdef OBJ_ELF
20901 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20902 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
20903 else
20904#endif
20905 code = BFD_RELOC_THUMB_PCREL_BLX;
20906 break;
20907
c19d1205
ZW
20908 case BFD_RELOC_ARM_LITERAL:
20909 case BFD_RELOC_ARM_HWLITERAL:
20910 /* If this is called then the a literal has
20911 been referenced across a section boundary. */
20912 as_bad_where (fixp->fx_file, fixp->fx_line,
20913 _("literal referenced across section boundary"));
20914 return NULL;
a737bd4d 20915
c19d1205
ZW
20916#ifdef OBJ_ELF
20917 case BFD_RELOC_ARM_GOT32:
20918 case BFD_RELOC_ARM_GOTOFF:
20919 case BFD_RELOC_ARM_PLT32:
20920 case BFD_RELOC_ARM_TARGET1:
20921 case BFD_RELOC_ARM_ROSEGREL32:
20922 case BFD_RELOC_ARM_SBREL32:
20923 case BFD_RELOC_ARM_PREL31:
20924 case BFD_RELOC_ARM_TARGET2:
20925 case BFD_RELOC_ARM_TLS_LE32:
20926 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
20927 case BFD_RELOC_ARM_PCREL_CALL:
20928 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
20929 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20930 case BFD_RELOC_ARM_ALU_PC_G0:
20931 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20932 case BFD_RELOC_ARM_ALU_PC_G1:
20933 case BFD_RELOC_ARM_ALU_PC_G2:
20934 case BFD_RELOC_ARM_LDR_PC_G0:
20935 case BFD_RELOC_ARM_LDR_PC_G1:
20936 case BFD_RELOC_ARM_LDR_PC_G2:
20937 case BFD_RELOC_ARM_LDRS_PC_G0:
20938 case BFD_RELOC_ARM_LDRS_PC_G1:
20939 case BFD_RELOC_ARM_LDRS_PC_G2:
20940 case BFD_RELOC_ARM_LDC_PC_G0:
20941 case BFD_RELOC_ARM_LDC_PC_G1:
20942 case BFD_RELOC_ARM_LDC_PC_G2:
20943 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20944 case BFD_RELOC_ARM_ALU_SB_G0:
20945 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20946 case BFD_RELOC_ARM_ALU_SB_G1:
20947 case BFD_RELOC_ARM_ALU_SB_G2:
20948 case BFD_RELOC_ARM_LDR_SB_G0:
20949 case BFD_RELOC_ARM_LDR_SB_G1:
20950 case BFD_RELOC_ARM_LDR_SB_G2:
20951 case BFD_RELOC_ARM_LDRS_SB_G0:
20952 case BFD_RELOC_ARM_LDRS_SB_G1:
20953 case BFD_RELOC_ARM_LDRS_SB_G2:
20954 case BFD_RELOC_ARM_LDC_SB_G0:
20955 case BFD_RELOC_ARM_LDC_SB_G1:
20956 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 20957 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
20958 code = fixp->fx_r_type;
20959 break;
a737bd4d 20960
c19d1205
ZW
20961 case BFD_RELOC_ARM_TLS_GD32:
20962 case BFD_RELOC_ARM_TLS_IE32:
20963 case BFD_RELOC_ARM_TLS_LDM32:
20964 /* BFD will include the symbol's address in the addend.
20965 But we don't want that, so subtract it out again here. */
20966 if (!S_IS_COMMON (fixp->fx_addsy))
20967 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
20968 code = fixp->fx_r_type;
20969 break;
20970#endif
a737bd4d 20971
c19d1205
ZW
20972 case BFD_RELOC_ARM_IMMEDIATE:
20973 as_bad_where (fixp->fx_file, fixp->fx_line,
20974 _("internal relocation (type: IMMEDIATE) not fixed up"));
20975 return NULL;
a737bd4d 20976
c19d1205
ZW
20977 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20978 as_bad_where (fixp->fx_file, fixp->fx_line,
20979 _("ADRL used for a symbol not defined in the same file"));
20980 return NULL;
a737bd4d 20981
c19d1205 20982 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20983 if (section->use_rela_p)
20984 {
20985 code = fixp->fx_r_type;
20986 break;
20987 }
20988
c19d1205
ZW
20989 if (fixp->fx_addsy != NULL
20990 && !S_IS_DEFINED (fixp->fx_addsy)
20991 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 20992 {
c19d1205
ZW
20993 as_bad_where (fixp->fx_file, fixp->fx_line,
20994 _("undefined local label `%s'"),
20995 S_GET_NAME (fixp->fx_addsy));
20996 return NULL;
a737bd4d
NC
20997 }
20998
c19d1205
ZW
20999 as_bad_where (fixp->fx_file, fixp->fx_line,
21000 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21001 return NULL;
a737bd4d 21002
c19d1205
ZW
21003 default:
21004 {
21005 char * type;
6c43fab6 21006
c19d1205
ZW
21007 switch (fixp->fx_r_type)
21008 {
21009 case BFD_RELOC_NONE: type = "NONE"; break;
21010 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21011 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21012 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21013 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21014 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21015 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 21016 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21017 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21018 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21019 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21020 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21021 default: type = _("<unknown>"); break;
21022 }
21023 as_bad_where (fixp->fx_file, fixp->fx_line,
21024 _("cannot represent %s relocation in this object file format"),
21025 type);
21026 return NULL;
21027 }
a737bd4d 21028 }
6c43fab6 21029
c19d1205
ZW
21030#ifdef OBJ_ELF
21031 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21032 && GOT_symbol
21033 && fixp->fx_addsy == GOT_symbol)
21034 {
21035 code = BFD_RELOC_ARM_GOTPC;
21036 reloc->addend = fixp->fx_offset = reloc->address;
21037 }
21038#endif
6c43fab6 21039
c19d1205 21040 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21041
c19d1205
ZW
21042 if (reloc->howto == NULL)
21043 {
21044 as_bad_where (fixp->fx_file, fixp->fx_line,
21045 _("cannot represent %s relocation in this object file format"),
21046 bfd_get_reloc_code_name (code));
21047 return NULL;
21048 }
6c43fab6 21049
c19d1205
ZW
21050 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21051 vtable entry to be used in the relocation's section offset. */
21052 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21053 reloc->address = fixp->fx_offset;
6c43fab6 21054
c19d1205 21055 return reloc;
6c43fab6
RE
21056}
21057
c19d1205 21058/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21059
c19d1205
ZW
21060void
21061cons_fix_new_arm (fragS * frag,
21062 int where,
21063 int size,
21064 expressionS * exp)
6c43fab6 21065{
c19d1205
ZW
21066 bfd_reloc_code_real_type type;
21067 int pcrel = 0;
6c43fab6 21068
c19d1205
ZW
21069 /* Pick a reloc.
21070 FIXME: @@ Should look at CPU word size. */
21071 switch (size)
21072 {
21073 case 1:
21074 type = BFD_RELOC_8;
21075 break;
21076 case 2:
21077 type = BFD_RELOC_16;
21078 break;
21079 case 4:
21080 default:
21081 type = BFD_RELOC_32;
21082 break;
21083 case 8:
21084 type = BFD_RELOC_64;
21085 break;
21086 }
6c43fab6 21087
f0927246
NC
21088#ifdef TE_PE
21089 if (exp->X_op == O_secrel)
21090 {
21091 exp->X_op = O_symbol;
21092 type = BFD_RELOC_32_SECREL;
21093 }
21094#endif
21095
c19d1205
ZW
21096 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21097}
6c43fab6 21098
4343666d 21099#if defined (OBJ_COFF)
c19d1205
ZW
21100void
21101arm_validate_fix (fixS * fixP)
6c43fab6 21102{
c19d1205
ZW
21103 /* If the destination of the branch is a defined symbol which does not have
21104 the THUMB_FUNC attribute, then we must be calling a function which has
21105 the (interfacearm) attribute. We look for the Thumb entry point to that
21106 function and change the branch to refer to that function instead. */
21107 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21108 && fixP->fx_addsy != NULL
21109 && S_IS_DEFINED (fixP->fx_addsy)
21110 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21111 {
c19d1205 21112 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21113 }
c19d1205
ZW
21114}
21115#endif
6c43fab6 21116
267bf995 21117
c19d1205
ZW
21118int
21119arm_force_relocation (struct fix * fixp)
21120{
21121#if defined (OBJ_COFF) && defined (TE_PE)
21122 if (fixp->fx_r_type == BFD_RELOC_RVA)
21123 return 1;
21124#endif
6c43fab6 21125
267bf995
RR
21126 /* In case we have a call or a branch to a function in ARM ISA mode from
21127 a thumb function or vice-versa force the relocation. These relocations
21128 are cleared off for some cores that might have blx and simple transformations
21129 are possible. */
21130
21131#ifdef OBJ_ELF
21132 switch (fixp->fx_r_type)
21133 {
21134 case BFD_RELOC_ARM_PCREL_JUMP:
21135 case BFD_RELOC_ARM_PCREL_CALL:
21136 case BFD_RELOC_THUMB_PCREL_BLX:
21137 if (THUMB_IS_FUNC (fixp->fx_addsy))
21138 return 1;
21139 break;
21140
21141 case BFD_RELOC_ARM_PCREL_BLX:
21142 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21143 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21144 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21145 if (ARM_IS_FUNC (fixp->fx_addsy))
21146 return 1;
21147 break;
21148
21149 default:
21150 break;
21151 }
21152#endif
21153
c19d1205
ZW
21154 /* Resolve these relocations even if the symbol is extern or weak. */
21155 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21156 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21157 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21158 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21159 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21160 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21161 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21162 return 0;
a737bd4d 21163
4962c51a
MS
21164 /* Always leave these relocations for the linker. */
21165 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21166 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21167 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21168 return 1;
21169
f0291e4c
PB
21170 /* Always generate relocations against function symbols. */
21171 if (fixp->fx_r_type == BFD_RELOC_32
21172 && fixp->fx_addsy
21173 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21174 return 1;
21175
c19d1205 21176 return generic_force_reloc (fixp);
404ff6b5
AH
21177}
21178
0ffdc86c 21179#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21180/* Relocations against function names must be left unadjusted,
21181 so that the linker can use this information to generate interworking
21182 stubs. The MIPS version of this function
c19d1205
ZW
21183 also prevents relocations that are mips-16 specific, but I do not
21184 know why it does this.
404ff6b5 21185
c19d1205
ZW
21186 FIXME:
21187 There is one other problem that ought to be addressed here, but
21188 which currently is not: Taking the address of a label (rather
21189 than a function) and then later jumping to that address. Such
21190 addresses also ought to have their bottom bit set (assuming that
21191 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21192
c19d1205
ZW
21193bfd_boolean
21194arm_fix_adjustable (fixS * fixP)
404ff6b5 21195{
c19d1205
ZW
21196 if (fixP->fx_addsy == NULL)
21197 return 1;
404ff6b5 21198
e28387c3
PB
21199 /* Preserve relocations against symbols with function type. */
21200 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21201 return FALSE;
e28387c3 21202
c19d1205
ZW
21203 if (THUMB_IS_FUNC (fixP->fx_addsy)
21204 && fixP->fx_subsy == NULL)
c921be7d 21205 return FALSE;
a737bd4d 21206
c19d1205
ZW
21207 /* We need the symbol name for the VTABLE entries. */
21208 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21209 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21210 return FALSE;
404ff6b5 21211
c19d1205
ZW
21212 /* Don't allow symbols to be discarded on GOT related relocs. */
21213 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21214 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21215 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21216 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21217 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21218 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21219 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21220 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21221 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21222 return FALSE;
a737bd4d 21223
4962c51a
MS
21224 /* Similarly for group relocations. */
21225 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21226 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21227 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21228 return FALSE;
4962c51a 21229
79947c54
CD
21230 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21231 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21232 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21233 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21234 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21235 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21236 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21237 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21238 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21239 return FALSE;
79947c54 21240
c921be7d 21241 return TRUE;
a737bd4d 21242}
0ffdc86c
NC
21243#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21244
21245#ifdef OBJ_ELF
404ff6b5 21246
c19d1205
ZW
21247const char *
21248elf32_arm_target_format (void)
404ff6b5 21249{
c19d1205
ZW
21250#ifdef TE_SYMBIAN
21251 return (target_big_endian
21252 ? "elf32-bigarm-symbian"
21253 : "elf32-littlearm-symbian");
21254#elif defined (TE_VXWORKS)
21255 return (target_big_endian
21256 ? "elf32-bigarm-vxworks"
21257 : "elf32-littlearm-vxworks");
21258#else
21259 if (target_big_endian)
21260 return "elf32-bigarm";
21261 else
21262 return "elf32-littlearm";
21263#endif
404ff6b5
AH
21264}
21265
c19d1205
ZW
21266void
21267armelf_frob_symbol (symbolS * symp,
21268 int * puntp)
404ff6b5 21269{
c19d1205
ZW
21270 elf_frob_symbol (symp, puntp);
21271}
21272#endif
404ff6b5 21273
c19d1205 21274/* MD interface: Finalization. */
a737bd4d 21275
c19d1205
ZW
21276void
21277arm_cleanup (void)
21278{
21279 literal_pool * pool;
a737bd4d 21280
e07e6e58
NC
21281 /* Ensure that all the IT blocks are properly closed. */
21282 check_it_blocks_finished ();
21283
c19d1205
ZW
21284 for (pool = list_of_pools; pool; pool = pool->next)
21285 {
5f4273c7 21286 /* Put it at the end of the relevant section. */
c19d1205
ZW
21287 subseg_set (pool->section, pool->sub_section);
21288#ifdef OBJ_ELF
21289 arm_elf_change_section ();
21290#endif
21291 s_ltorg (0);
21292 }
404ff6b5
AH
21293}
21294
cd000bff
DJ
21295#ifdef OBJ_ELF
21296/* Remove any excess mapping symbols generated for alignment frags in
21297 SEC. We may have created a mapping symbol before a zero byte
21298 alignment; remove it if there's a mapping symbol after the
21299 alignment. */
21300static void
21301check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21302 void *dummy ATTRIBUTE_UNUSED)
21303{
21304 segment_info_type *seginfo = seg_info (sec);
21305 fragS *fragp;
21306
21307 if (seginfo == NULL || seginfo->frchainP == NULL)
21308 return;
21309
21310 for (fragp = seginfo->frchainP->frch_root;
21311 fragp != NULL;
21312 fragp = fragp->fr_next)
21313 {
21314 symbolS *sym = fragp->tc_frag_data.last_map;
21315 fragS *next = fragp->fr_next;
21316
21317 /* Variable-sized frags have been converted to fixed size by
21318 this point. But if this was variable-sized to start with,
21319 there will be a fixed-size frag after it. So don't handle
21320 next == NULL. */
21321 if (sym == NULL || next == NULL)
21322 continue;
21323
21324 if (S_GET_VALUE (sym) < next->fr_address)
21325 /* Not at the end of this frag. */
21326 continue;
21327 know (S_GET_VALUE (sym) == next->fr_address);
21328
21329 do
21330 {
21331 if (next->tc_frag_data.first_map != NULL)
21332 {
21333 /* Next frag starts with a mapping symbol. Discard this
21334 one. */
21335 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21336 break;
21337 }
21338
21339 if (next->fr_next == NULL)
21340 {
21341 /* This mapping symbol is at the end of the section. Discard
21342 it. */
21343 know (next->fr_fix == 0 && next->fr_var == 0);
21344 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21345 break;
21346 }
21347
21348 /* As long as we have empty frags without any mapping symbols,
21349 keep looking. */
21350 /* If the next frag is non-empty and does not start with a
21351 mapping symbol, then this mapping symbol is required. */
21352 if (next->fr_address != next->fr_next->fr_address)
21353 break;
21354
21355 next = next->fr_next;
21356 }
21357 while (next != NULL);
21358 }
21359}
21360#endif
21361
c19d1205
ZW
21362/* Adjust the symbol table. This marks Thumb symbols as distinct from
21363 ARM ones. */
404ff6b5 21364
c19d1205
ZW
21365void
21366arm_adjust_symtab (void)
404ff6b5 21367{
c19d1205
ZW
21368#ifdef OBJ_COFF
21369 symbolS * sym;
404ff6b5 21370
c19d1205
ZW
21371 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21372 {
21373 if (ARM_IS_THUMB (sym))
21374 {
21375 if (THUMB_IS_FUNC (sym))
21376 {
21377 /* Mark the symbol as a Thumb function. */
21378 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21379 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21380 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21381
c19d1205
ZW
21382 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21383 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21384 else
21385 as_bad (_("%s: unexpected function type: %d"),
21386 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21387 }
21388 else switch (S_GET_STORAGE_CLASS (sym))
21389 {
21390 case C_EXT:
21391 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21392 break;
21393 case C_STAT:
21394 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21395 break;
21396 case C_LABEL:
21397 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21398 break;
21399 default:
21400 /* Do nothing. */
21401 break;
21402 }
21403 }
a737bd4d 21404
c19d1205
ZW
21405 if (ARM_IS_INTERWORK (sym))
21406 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21407 }
c19d1205
ZW
21408#endif
21409#ifdef OBJ_ELF
21410 symbolS * sym;
21411 char bind;
404ff6b5 21412
c19d1205 21413 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21414 {
c19d1205
ZW
21415 if (ARM_IS_THUMB (sym))
21416 {
21417 elf_symbol_type * elf_sym;
404ff6b5 21418
c19d1205
ZW
21419 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21420 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21421
b0796911
PB
21422 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21423 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21424 {
21425 /* If it's a .thumb_func, declare it as so,
21426 otherwise tag label as .code 16. */
21427 if (THUMB_IS_FUNC (sym))
21428 elf_sym->internal_elf_sym.st_info =
21429 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21430 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21431 elf_sym->internal_elf_sym.st_info =
21432 ELF_ST_INFO (bind, STT_ARM_16BIT);
21433 }
21434 }
21435 }
cd000bff
DJ
21436
21437 /* Remove any overlapping mapping symbols generated by alignment frags. */
21438 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21439#endif
404ff6b5
AH
21440}
21441
c19d1205 21442/* MD interface: Initialization. */
404ff6b5 21443
a737bd4d 21444static void
c19d1205 21445set_constant_flonums (void)
a737bd4d 21446{
c19d1205 21447 int i;
404ff6b5 21448
c19d1205
ZW
21449 for (i = 0; i < NUM_FLOAT_VALS; i++)
21450 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21451 abort ();
a737bd4d 21452}
404ff6b5 21453
3e9e4fcf
JB
21454/* Auto-select Thumb mode if it's the only available instruction set for the
21455 given architecture. */
21456
21457static void
21458autoselect_thumb_from_cpu_variant (void)
21459{
21460 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21461 opcode_select (16);
21462}
21463
c19d1205
ZW
21464void
21465md_begin (void)
a737bd4d 21466{
c19d1205
ZW
21467 unsigned mach;
21468 unsigned int i;
404ff6b5 21469
c19d1205
ZW
21470 if ( (arm_ops_hsh = hash_new ()) == NULL
21471 || (arm_cond_hsh = hash_new ()) == NULL
21472 || (arm_shift_hsh = hash_new ()) == NULL
21473 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21474 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21475 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21476 || (arm_reloc_hsh = hash_new ()) == NULL
21477 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21478 as_fatal (_("virtual memory exhausted"));
21479
21480 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21481 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21482 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21483 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21484 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21485 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21486 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21487 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21488 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21489 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21490 (void *) (v7m_psrs + i));
c19d1205 21491 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21492 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21493 for (i = 0;
21494 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21495 i++)
d3ce72d0 21496 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21497 (void *) (barrier_opt_names + i));
c19d1205
ZW
21498#ifdef OBJ_ELF
21499 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21500 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21501#endif
21502
21503 set_constant_flonums ();
404ff6b5 21504
c19d1205
ZW
21505 /* Set the cpu variant based on the command-line options. We prefer
21506 -mcpu= over -march= if both are set (as for GCC); and we prefer
21507 -mfpu= over any other way of setting the floating point unit.
21508 Use of legacy options with new options are faulted. */
e74cfd16 21509 if (legacy_cpu)
404ff6b5 21510 {
e74cfd16 21511 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21512 as_bad (_("use of old and new-style options to set CPU type"));
21513
21514 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21515 }
e74cfd16 21516 else if (!mcpu_cpu_opt)
c19d1205 21517 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21518
e74cfd16 21519 if (legacy_fpu)
c19d1205 21520 {
e74cfd16 21521 if (mfpu_opt)
c19d1205 21522 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21523
21524 mfpu_opt = legacy_fpu;
21525 }
e74cfd16 21526 else if (!mfpu_opt)
03b1477f 21527 {
45eb4c1b
NS
21528#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21529 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21530 /* Some environments specify a default FPU. If they don't, infer it
21531 from the processor. */
e74cfd16 21532 if (mcpu_fpu_opt)
03b1477f
RE
21533 mfpu_opt = mcpu_fpu_opt;
21534 else
21535 mfpu_opt = march_fpu_opt;
39c2da32 21536#else
e74cfd16 21537 mfpu_opt = &fpu_default;
39c2da32 21538#endif
03b1477f
RE
21539 }
21540
e74cfd16 21541 if (!mfpu_opt)
03b1477f 21542 {
493cb6ef 21543 if (mcpu_cpu_opt != NULL)
e74cfd16 21544 mfpu_opt = &fpu_default;
493cb6ef 21545 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21546 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21547 else
e74cfd16 21548 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21549 }
21550
ee065d83 21551#ifdef CPU_DEFAULT
e74cfd16 21552 if (!mcpu_cpu_opt)
ee065d83 21553 {
e74cfd16
PB
21554 mcpu_cpu_opt = &cpu_default;
21555 selected_cpu = cpu_default;
ee065d83 21556 }
e74cfd16
PB
21557#else
21558 if (mcpu_cpu_opt)
21559 selected_cpu = *mcpu_cpu_opt;
ee065d83 21560 else
e74cfd16 21561 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21562#endif
03b1477f 21563
e74cfd16 21564 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21565
3e9e4fcf
JB
21566 autoselect_thumb_from_cpu_variant ();
21567
e74cfd16 21568 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21569
f17c130b 21570#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21571 {
7cc69913
NC
21572 unsigned int flags = 0;
21573
21574#if defined OBJ_ELF
21575 flags = meabi_flags;
d507cf36
PB
21576
21577 switch (meabi_flags)
33a392fb 21578 {
d507cf36 21579 case EF_ARM_EABI_UNKNOWN:
7cc69913 21580#endif
d507cf36
PB
21581 /* Set the flags in the private structure. */
21582 if (uses_apcs_26) flags |= F_APCS26;
21583 if (support_interwork) flags |= F_INTERWORK;
21584 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21585 if (pic_code) flags |= F_PIC;
e74cfd16 21586 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21587 flags |= F_SOFT_FLOAT;
21588
d507cf36
PB
21589 switch (mfloat_abi_opt)
21590 {
21591 case ARM_FLOAT_ABI_SOFT:
21592 case ARM_FLOAT_ABI_SOFTFP:
21593 flags |= F_SOFT_FLOAT;
21594 break;
33a392fb 21595
d507cf36
PB
21596 case ARM_FLOAT_ABI_HARD:
21597 if (flags & F_SOFT_FLOAT)
21598 as_bad (_("hard-float conflicts with specified fpu"));
21599 break;
21600 }
03b1477f 21601
e74cfd16
PB
21602 /* Using pure-endian doubles (even if soft-float). */
21603 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21604 flags |= F_VFP_FLOAT;
f17c130b 21605
fde78edd 21606#if defined OBJ_ELF
e74cfd16 21607 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21608 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21609 break;
21610
8cb51566 21611 case EF_ARM_EABI_VER4:
3a4a14e9 21612 case EF_ARM_EABI_VER5:
c19d1205 21613 /* No additional flags to set. */
d507cf36
PB
21614 break;
21615
21616 default:
21617 abort ();
21618 }
7cc69913 21619#endif
b99bd4ef
NC
21620 bfd_set_private_flags (stdoutput, flags);
21621
21622 /* We have run out flags in the COFF header to encode the
21623 status of ATPCS support, so instead we create a dummy,
c19d1205 21624 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21625 if (atpcs)
21626 {
21627 asection * sec;
21628
21629 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21630
21631 if (sec != NULL)
21632 {
21633 bfd_set_section_flags
21634 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21635 bfd_set_section_size (stdoutput, sec, 0);
21636 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21637 }
21638 }
7cc69913 21639 }
f17c130b 21640#endif
b99bd4ef
NC
21641
21642 /* Record the CPU type as well. */
2d447fca
JM
21643 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21644 mach = bfd_mach_arm_iWMMXt2;
21645 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21646 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21647 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21648 mach = bfd_mach_arm_XScale;
e74cfd16 21649 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21650 mach = bfd_mach_arm_ep9312;
e74cfd16 21651 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21652 mach = bfd_mach_arm_5TE;
e74cfd16 21653 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21654 {
e74cfd16 21655 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21656 mach = bfd_mach_arm_5T;
21657 else
21658 mach = bfd_mach_arm_5;
21659 }
e74cfd16 21660 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21661 {
e74cfd16 21662 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21663 mach = bfd_mach_arm_4T;
21664 else
21665 mach = bfd_mach_arm_4;
21666 }
e74cfd16 21667 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21668 mach = bfd_mach_arm_3M;
e74cfd16
PB
21669 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21670 mach = bfd_mach_arm_3;
21671 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21672 mach = bfd_mach_arm_2a;
21673 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21674 mach = bfd_mach_arm_2;
21675 else
21676 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21677
21678 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21679}
21680
c19d1205 21681/* Command line processing. */
b99bd4ef 21682
c19d1205
ZW
21683/* md_parse_option
21684 Invocation line includes a switch not recognized by the base assembler.
21685 See if it's a processor-specific option.
b99bd4ef 21686
c19d1205
ZW
21687 This routine is somewhat complicated by the need for backwards
21688 compatibility (since older releases of gcc can't be changed).
21689 The new options try to make the interface as compatible as
21690 possible with GCC.
b99bd4ef 21691
c19d1205 21692 New options (supported) are:
b99bd4ef 21693
c19d1205
ZW
21694 -mcpu=<cpu name> Assemble for selected processor
21695 -march=<architecture name> Assemble for selected architecture
21696 -mfpu=<fpu architecture> Assemble for selected FPU.
21697 -EB/-mbig-endian Big-endian
21698 -EL/-mlittle-endian Little-endian
21699 -k Generate PIC code
21700 -mthumb Start in Thumb mode
21701 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21702
278df34e 21703 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21704
c19d1205 21705 For now we will also provide support for:
b99bd4ef 21706
c19d1205
ZW
21707 -mapcs-32 32-bit Program counter
21708 -mapcs-26 26-bit Program counter
21709 -macps-float Floats passed in FP registers
21710 -mapcs-reentrant Reentrant code
21711 -matpcs
21712 (sometime these will probably be replaced with -mapcs=<list of options>
21713 and -matpcs=<list of options>)
b99bd4ef 21714
c19d1205
ZW
21715 The remaining options are only supported for back-wards compatibility.
21716 Cpu variants, the arm part is optional:
21717 -m[arm]1 Currently not supported.
21718 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21719 -m[arm]3 Arm 3 processor
21720 -m[arm]6[xx], Arm 6 processors
21721 -m[arm]7[xx][t][[d]m] Arm 7 processors
21722 -m[arm]8[10] Arm 8 processors
21723 -m[arm]9[20][tdmi] Arm 9 processors
21724 -mstrongarm[110[0]] StrongARM processors
21725 -mxscale XScale processors
21726 -m[arm]v[2345[t[e]]] Arm architectures
21727 -mall All (except the ARM1)
21728 FP variants:
21729 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21730 -mfpe-old (No float load/store multiples)
21731 -mvfpxd VFP Single precision
21732 -mvfp All VFP
21733 -mno-fpu Disable all floating point instructions
b99bd4ef 21734
c19d1205
ZW
21735 The following CPU names are recognized:
21736 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21737 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21738 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21739 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21740 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21741 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21742 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21743
c19d1205 21744 */
b99bd4ef 21745
c19d1205 21746const char * md_shortopts = "m:k";
b99bd4ef 21747
c19d1205
ZW
21748#ifdef ARM_BI_ENDIAN
21749#define OPTION_EB (OPTION_MD_BASE + 0)
21750#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21751#else
c19d1205
ZW
21752#if TARGET_BYTES_BIG_ENDIAN
21753#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21754#else
c19d1205
ZW
21755#define OPTION_EL (OPTION_MD_BASE + 1)
21756#endif
b99bd4ef 21757#endif
845b51d6 21758#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21759
c19d1205 21760struct option md_longopts[] =
b99bd4ef 21761{
c19d1205
ZW
21762#ifdef OPTION_EB
21763 {"EB", no_argument, NULL, OPTION_EB},
21764#endif
21765#ifdef OPTION_EL
21766 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21767#endif
845b51d6 21768 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21769 {NULL, no_argument, NULL, 0}
21770};
b99bd4ef 21771
c19d1205 21772size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21773
c19d1205 21774struct arm_option_table
b99bd4ef 21775{
c19d1205
ZW
21776 char *option; /* Option name to match. */
21777 char *help; /* Help information. */
21778 int *var; /* Variable to change. */
21779 int value; /* What to change it to. */
21780 char *deprecated; /* If non-null, print this message. */
21781};
b99bd4ef 21782
c19d1205
ZW
21783struct arm_option_table arm_opts[] =
21784{
21785 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21786 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21787 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21788 &support_interwork, 1, NULL},
21789 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21790 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21791 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21792 1, NULL},
21793 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21794 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21795 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21796 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21797 NULL},
b99bd4ef 21798
c19d1205
ZW
21799 /* These are recognized by the assembler, but have no affect on code. */
21800 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21801 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21802
21803 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21804 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21805 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21806 {NULL, NULL, NULL, 0, NULL}
21807};
21808
21809struct arm_legacy_option_table
21810{
21811 char *option; /* Option name to match. */
21812 const arm_feature_set **var; /* Variable to change. */
21813 const arm_feature_set value; /* What to change it to. */
21814 char *deprecated; /* If non-null, print this message. */
21815};
b99bd4ef 21816
e74cfd16
PB
21817const struct arm_legacy_option_table arm_legacy_opts[] =
21818{
c19d1205
ZW
21819 /* DON'T add any new processors to this list -- we want the whole list
21820 to go away... Add them to the processors table instead. */
e74cfd16
PB
21821 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21822 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21823 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21824 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21825 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21826 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21827 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21828 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21829 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21830 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21831 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21832 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21833 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21834 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21835 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21836 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21837 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21838 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21839 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21840 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21841 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21842 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21843 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21844 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21845 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21846 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21847 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21848 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21849 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21850 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21851 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21852 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21853 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21854 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21855 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21856 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21857 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21858 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21859 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21860 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21861 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21862 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21863 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21864 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21865 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21866 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21867 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21868 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21869 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21870 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21871 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21872 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21873 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21874 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21875 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21876 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21877 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21878 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21879 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21880 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21881 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21882 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21883 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21884 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21885 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21886 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21887 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21888 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21889 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
21890 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21891 N_("use -mcpu=strongarm110")},
e74cfd16 21892 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21893 N_("use -mcpu=strongarm1100")},
e74cfd16 21894 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21895 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
21896 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
21897 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
21898 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 21899
c19d1205 21900 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
21901 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21902 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21903 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21904 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21905 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21906 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21907 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21908 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21909 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21910 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21911 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21912 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21913 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21914 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21915 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21916 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21917 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21918 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 21919
c19d1205 21920 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
21921 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
21922 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
21923 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
21924 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 21925 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 21926
e74cfd16 21927 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 21928};
7ed4c4c5 21929
c19d1205 21930struct arm_cpu_option_table
7ed4c4c5 21931{
c19d1205 21932 char *name;
e74cfd16 21933 const arm_feature_set value;
c19d1205
ZW
21934 /* For some CPUs we assume an FPU unless the user explicitly sets
21935 -mfpu=... */
e74cfd16 21936 const arm_feature_set default_fpu;
ee065d83
PB
21937 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21938 case. */
21939 const char *canonical_name;
c19d1205 21940};
7ed4c4c5 21941
c19d1205
ZW
21942/* This list should, at a minimum, contain all the cpu names
21943 recognized by GCC. */
e74cfd16 21944static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 21945{
ee065d83
PB
21946 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
21947 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
21948 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
21949 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21950 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21951 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21952 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21953 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21954 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21955 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21956 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21957 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21958 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21959 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21960 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21961 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21962 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21963 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21964 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21965 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21966 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21967 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21968 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21969 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21970 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21971 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21972 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21973 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21974 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21975 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21976 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21977 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21978 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21979 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21980 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21981 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21982 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21983 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21984 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21985 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
21986 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21987 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21988 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21989 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
21990 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21991 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
21992 /* For V5 or later processors we default to using VFP; but the user
21993 should really set the FPU type explicitly. */
ee065d83
PB
21994 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21995 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21996 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21997 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21998 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21999 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22000 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22001 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22002 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22003 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22004 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22005 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22006 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22007 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22008 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22009 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22010 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22011 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22012 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22013 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22014 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22015 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22016 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22017 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22018 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22019 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22020 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22021 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22022 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22023 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22024 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22025 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22026 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
b38f9f31 22027 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
e07e6e58 22028 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22029 | FPU_NEON_EXT_V1),
15290f0a 22030 NULL},
e07e6e58 22031 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22032 | FPU_NEON_EXT_V1),
5287ad62 22033 NULL},
62b3e311 22034 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
307c948d 22035 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
62b3e311 22036 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 22037 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 22038 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 22039 /* ??? XSCALE is really an architecture. */
ee065d83 22040 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22041 /* ??? iwmmxt is not a processor. */
ee065d83 22042 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22043 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22044 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22045 /* Maverick */
e07e6e58 22046 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22047 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22048};
7ed4c4c5 22049
c19d1205 22050struct arm_arch_option_table
7ed4c4c5 22051{
c19d1205 22052 char *name;
e74cfd16
PB
22053 const arm_feature_set value;
22054 const arm_feature_set default_fpu;
c19d1205 22055};
7ed4c4c5 22056
c19d1205
ZW
22057/* This list should, at a minimum, contain all the architecture names
22058 recognized by GCC. */
e74cfd16 22059static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22060{
22061 {"all", ARM_ANY, FPU_ARCH_FPA},
22062 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22063 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22064 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22065 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22066 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22067 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22068 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22069 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22070 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22071 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22072 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22073 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22074 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22075 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22076 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22077 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22078 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22079 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22080 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22081 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22082 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22083 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22084 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22085 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22086 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22087 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22088 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22089 /* The official spelling of the ARMv7 profile variants is the dashed form.
22090 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22091 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22092 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22093 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22094 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22095 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22096 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22097 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22098 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22099 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22100 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22101 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22102};
7ed4c4c5 22103
c19d1205 22104/* ISA extensions in the co-processor space. */
e74cfd16 22105struct arm_option_cpu_value_table
c19d1205
ZW
22106{
22107 char *name;
e74cfd16 22108 const arm_feature_set value;
c19d1205 22109};
7ed4c4c5 22110
e74cfd16 22111static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22112{
e74cfd16
PB
22113 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22114 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22115 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22116 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22117 {NULL, ARM_ARCH_NONE}
c19d1205 22118};
7ed4c4c5 22119
c19d1205
ZW
22120/* This list should, at a minimum, contain all the fpu names
22121 recognized by GCC. */
e74cfd16 22122static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22123{
22124 {"softfpa", FPU_NONE},
22125 {"fpe", FPU_ARCH_FPE},
22126 {"fpe2", FPU_ARCH_FPE},
22127 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22128 {"fpa", FPU_ARCH_FPA},
22129 {"fpa10", FPU_ARCH_FPA},
22130 {"fpa11", FPU_ARCH_FPA},
22131 {"arm7500fe", FPU_ARCH_FPA},
22132 {"softvfp", FPU_ARCH_VFP},
22133 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22134 {"vfp", FPU_ARCH_VFP_V2},
22135 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22136 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22137 {"vfp10", FPU_ARCH_VFP_V2},
22138 {"vfp10-r0", FPU_ARCH_VFP_V1},
22139 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22140 {"vfpv2", FPU_ARCH_VFP_V2},
22141 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22142 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22143 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22144 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22145 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22146 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22147 {"arm1020t", FPU_ARCH_VFP_V1},
22148 {"arm1020e", FPU_ARCH_VFP_V2},
22149 {"arm1136jfs", FPU_ARCH_VFP_V2},
22150 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22151 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22152 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22153 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22154 {"vfpv4", FPU_ARCH_VFP_V4},
22155 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22156 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22157 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22158 {NULL, ARM_ARCH_NONE}
22159};
22160
22161struct arm_option_value_table
22162{
22163 char *name;
22164 long value;
c19d1205 22165};
7ed4c4c5 22166
e74cfd16 22167static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22168{
22169 {"hard", ARM_FLOAT_ABI_HARD},
22170 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22171 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22172 {NULL, 0}
c19d1205 22173};
7ed4c4c5 22174
c19d1205 22175#ifdef OBJ_ELF
3a4a14e9 22176/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22177static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22178{
22179 {"gnu", EF_ARM_EABI_UNKNOWN},
22180 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22181 {"5", EF_ARM_EABI_VER5},
e74cfd16 22182 {NULL, 0}
c19d1205
ZW
22183};
22184#endif
7ed4c4c5 22185
c19d1205
ZW
22186struct arm_long_option_table
22187{
22188 char * option; /* Substring to match. */
22189 char * help; /* Help information. */
22190 int (* func) (char * subopt); /* Function to decode sub-option. */
22191 char * deprecated; /* If non-null, print this message. */
22192};
7ed4c4c5 22193
c921be7d 22194static bfd_boolean
e74cfd16 22195arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22196{
21d799b5
NC
22197 arm_feature_set *ext_set = (arm_feature_set *)
22198 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22199
22200 /* Copy the feature set, so that we can modify it. */
22201 *ext_set = **opt_p;
22202 *opt_p = ext_set;
22203
c19d1205 22204 while (str != NULL && *str != 0)
7ed4c4c5 22205 {
e74cfd16 22206 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22207 char * ext;
22208 int optlen;
7ed4c4c5 22209
c19d1205
ZW
22210 if (*str != '+')
22211 {
22212 as_bad (_("invalid architectural extension"));
c921be7d 22213 return FALSE;
c19d1205 22214 }
7ed4c4c5 22215
c19d1205
ZW
22216 str++;
22217 ext = strchr (str, '+');
7ed4c4c5 22218
c19d1205
ZW
22219 if (ext != NULL)
22220 optlen = ext - str;
22221 else
22222 optlen = strlen (str);
7ed4c4c5 22223
c19d1205
ZW
22224 if (optlen == 0)
22225 {
22226 as_bad (_("missing architectural extension"));
c921be7d 22227 return FALSE;
c19d1205 22228 }
7ed4c4c5 22229
c19d1205
ZW
22230 for (opt = arm_extensions; opt->name != NULL; opt++)
22231 if (strncmp (opt->name, str, optlen) == 0)
22232 {
e74cfd16 22233 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22234 break;
22235 }
7ed4c4c5 22236
c19d1205
ZW
22237 if (opt->name == NULL)
22238 {
5f4273c7 22239 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22240 return FALSE;
c19d1205 22241 }
7ed4c4c5 22242
c19d1205
ZW
22243 str = ext;
22244 };
7ed4c4c5 22245
c921be7d 22246 return TRUE;
c19d1205 22247}
7ed4c4c5 22248
c921be7d 22249static bfd_boolean
c19d1205 22250arm_parse_cpu (char * str)
7ed4c4c5 22251{
e74cfd16 22252 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22253 char * ext = strchr (str, '+');
22254 int optlen;
7ed4c4c5 22255
c19d1205
ZW
22256 if (ext != NULL)
22257 optlen = ext - str;
7ed4c4c5 22258 else
c19d1205 22259 optlen = strlen (str);
7ed4c4c5 22260
c19d1205 22261 if (optlen == 0)
7ed4c4c5 22262 {
c19d1205 22263 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22264 return FALSE;
7ed4c4c5
NC
22265 }
22266
c19d1205
ZW
22267 for (opt = arm_cpus; opt->name != NULL; opt++)
22268 if (strncmp (opt->name, str, optlen) == 0)
22269 {
e74cfd16
PB
22270 mcpu_cpu_opt = &opt->value;
22271 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22272 if (opt->canonical_name)
5f4273c7 22273 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22274 else
22275 {
22276 int i;
c921be7d 22277
ee065d83
PB
22278 for (i = 0; i < optlen; i++)
22279 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22280 selected_cpu_name[i] = 0;
22281 }
7ed4c4c5 22282
c19d1205
ZW
22283 if (ext != NULL)
22284 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22285
c921be7d 22286 return TRUE;
c19d1205 22287 }
7ed4c4c5 22288
c19d1205 22289 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22290 return FALSE;
7ed4c4c5
NC
22291}
22292
c921be7d 22293static bfd_boolean
c19d1205 22294arm_parse_arch (char * str)
7ed4c4c5 22295{
e74cfd16 22296 const struct arm_arch_option_table *opt;
c19d1205
ZW
22297 char *ext = strchr (str, '+');
22298 int optlen;
7ed4c4c5 22299
c19d1205
ZW
22300 if (ext != NULL)
22301 optlen = ext - str;
7ed4c4c5 22302 else
c19d1205 22303 optlen = strlen (str);
7ed4c4c5 22304
c19d1205 22305 if (optlen == 0)
7ed4c4c5 22306 {
c19d1205 22307 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22308 return FALSE;
7ed4c4c5
NC
22309 }
22310
c19d1205
ZW
22311 for (opt = arm_archs; opt->name != NULL; opt++)
22312 if (streq (opt->name, str))
22313 {
e74cfd16
PB
22314 march_cpu_opt = &opt->value;
22315 march_fpu_opt = &opt->default_fpu;
5f4273c7 22316 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22317
c19d1205
ZW
22318 if (ext != NULL)
22319 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22320
c921be7d 22321 return TRUE;
c19d1205
ZW
22322 }
22323
22324 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22325 return FALSE;
7ed4c4c5 22326}
eb043451 22327
c921be7d 22328static bfd_boolean
c19d1205
ZW
22329arm_parse_fpu (char * str)
22330{
e74cfd16 22331 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22332
c19d1205
ZW
22333 for (opt = arm_fpus; opt->name != NULL; opt++)
22334 if (streq (opt->name, str))
22335 {
e74cfd16 22336 mfpu_opt = &opt->value;
c921be7d 22337 return TRUE;
c19d1205 22338 }
b99bd4ef 22339
c19d1205 22340 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22341 return FALSE;
c19d1205
ZW
22342}
22343
c921be7d 22344static bfd_boolean
c19d1205 22345arm_parse_float_abi (char * str)
b99bd4ef 22346{
e74cfd16 22347 const struct arm_option_value_table * opt;
b99bd4ef 22348
c19d1205
ZW
22349 for (opt = arm_float_abis; opt->name != NULL; opt++)
22350 if (streq (opt->name, str))
22351 {
22352 mfloat_abi_opt = opt->value;
c921be7d 22353 return TRUE;
c19d1205 22354 }
cc8a6dd0 22355
c19d1205 22356 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22357 return FALSE;
c19d1205 22358}
b99bd4ef 22359
c19d1205 22360#ifdef OBJ_ELF
c921be7d 22361static bfd_boolean
c19d1205
ZW
22362arm_parse_eabi (char * str)
22363{
e74cfd16 22364 const struct arm_option_value_table *opt;
cc8a6dd0 22365
c19d1205
ZW
22366 for (opt = arm_eabis; opt->name != NULL; opt++)
22367 if (streq (opt->name, str))
22368 {
22369 meabi_flags = opt->value;
c921be7d 22370 return TRUE;
c19d1205
ZW
22371 }
22372 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22373 return FALSE;
c19d1205
ZW
22374}
22375#endif
cc8a6dd0 22376
c921be7d 22377static bfd_boolean
e07e6e58
NC
22378arm_parse_it_mode (char * str)
22379{
c921be7d 22380 bfd_boolean ret = TRUE;
e07e6e58
NC
22381
22382 if (streq ("arm", str))
22383 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22384 else if (streq ("thumb", str))
22385 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22386 else if (streq ("always", str))
22387 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22388 else if (streq ("never", str))
22389 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22390 else
22391 {
22392 as_bad (_("unknown implicit IT mode `%s', should be "\
22393 "arm, thumb, always, or never."), str);
c921be7d 22394 ret = FALSE;
e07e6e58
NC
22395 }
22396
22397 return ret;
22398}
22399
c19d1205
ZW
22400struct arm_long_option_table arm_long_opts[] =
22401{
22402 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22403 arm_parse_cpu, NULL},
22404 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22405 arm_parse_arch, NULL},
22406 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22407 arm_parse_fpu, NULL},
22408 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22409 arm_parse_float_abi, NULL},
22410#ifdef OBJ_ELF
7fac0536 22411 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22412 arm_parse_eabi, NULL},
22413#endif
e07e6e58
NC
22414 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22415 arm_parse_it_mode, NULL},
c19d1205
ZW
22416 {NULL, NULL, 0, NULL}
22417};
cc8a6dd0 22418
c19d1205
ZW
22419int
22420md_parse_option (int c, char * arg)
22421{
22422 struct arm_option_table *opt;
e74cfd16 22423 const struct arm_legacy_option_table *fopt;
c19d1205 22424 struct arm_long_option_table *lopt;
b99bd4ef 22425
c19d1205 22426 switch (c)
b99bd4ef 22427 {
c19d1205
ZW
22428#ifdef OPTION_EB
22429 case OPTION_EB:
22430 target_big_endian = 1;
22431 break;
22432#endif
cc8a6dd0 22433
c19d1205
ZW
22434#ifdef OPTION_EL
22435 case OPTION_EL:
22436 target_big_endian = 0;
22437 break;
22438#endif
b99bd4ef 22439
845b51d6
PB
22440 case OPTION_FIX_V4BX:
22441 fix_v4bx = TRUE;
22442 break;
22443
c19d1205
ZW
22444 case 'a':
22445 /* Listing option. Just ignore these, we don't support additional
22446 ones. */
22447 return 0;
b99bd4ef 22448
c19d1205
ZW
22449 default:
22450 for (opt = arm_opts; opt->option != NULL; opt++)
22451 {
22452 if (c == opt->option[0]
22453 && ((arg == NULL && opt->option[1] == 0)
22454 || streq (arg, opt->option + 1)))
22455 {
c19d1205 22456 /* If the option is deprecated, tell the user. */
278df34e 22457 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22458 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22459 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22460
c19d1205
ZW
22461 if (opt->var != NULL)
22462 *opt->var = opt->value;
cc8a6dd0 22463
c19d1205
ZW
22464 return 1;
22465 }
22466 }
b99bd4ef 22467
e74cfd16
PB
22468 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22469 {
22470 if (c == fopt->option[0]
22471 && ((arg == NULL && fopt->option[1] == 0)
22472 || streq (arg, fopt->option + 1)))
22473 {
e74cfd16 22474 /* If the option is deprecated, tell the user. */
278df34e 22475 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22476 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22477 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22478
22479 if (fopt->var != NULL)
22480 *fopt->var = &fopt->value;
22481
22482 return 1;
22483 }
22484 }
22485
c19d1205
ZW
22486 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22487 {
22488 /* These options are expected to have an argument. */
22489 if (c == lopt->option[0]
22490 && arg != NULL
22491 && strncmp (arg, lopt->option + 1,
22492 strlen (lopt->option + 1)) == 0)
22493 {
c19d1205 22494 /* If the option is deprecated, tell the user. */
278df34e 22495 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22496 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22497 _(lopt->deprecated));
b99bd4ef 22498
c19d1205
ZW
22499 /* Call the sup-option parser. */
22500 return lopt->func (arg + strlen (lopt->option) - 1);
22501 }
22502 }
a737bd4d 22503
c19d1205
ZW
22504 return 0;
22505 }
a394c00f 22506
c19d1205
ZW
22507 return 1;
22508}
a394c00f 22509
c19d1205
ZW
22510void
22511md_show_usage (FILE * fp)
a394c00f 22512{
c19d1205
ZW
22513 struct arm_option_table *opt;
22514 struct arm_long_option_table *lopt;
a394c00f 22515
c19d1205 22516 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22517
c19d1205
ZW
22518 for (opt = arm_opts; opt->option != NULL; opt++)
22519 if (opt->help != NULL)
22520 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22521
c19d1205
ZW
22522 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22523 if (lopt->help != NULL)
22524 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22525
c19d1205
ZW
22526#ifdef OPTION_EB
22527 fprintf (fp, _("\
22528 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22529#endif
22530
c19d1205
ZW
22531#ifdef OPTION_EL
22532 fprintf (fp, _("\
22533 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22534#endif
845b51d6
PB
22535
22536 fprintf (fp, _("\
22537 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22538}
ee065d83
PB
22539
22540
22541#ifdef OBJ_ELF
62b3e311
PB
22542typedef struct
22543{
22544 int val;
22545 arm_feature_set flags;
22546} cpu_arch_ver_table;
22547
22548/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22549 least features first. */
22550static const cpu_arch_ver_table cpu_arch_ver[] =
22551{
22552 {1, ARM_ARCH_V4},
22553 {2, ARM_ARCH_V4T},
22554 {3, ARM_ARCH_V5},
ee3c0378 22555 {3, ARM_ARCH_V5T},
62b3e311
PB
22556 {4, ARM_ARCH_V5TE},
22557 {5, ARM_ARCH_V5TEJ},
22558 {6, ARM_ARCH_V6},
22559 {7, ARM_ARCH_V6Z},
7e806470 22560 {9, ARM_ARCH_V6K},
91e22acd 22561 {11, ARM_ARCH_V6M},
7e806470 22562 {8, ARM_ARCH_V6T2},
62b3e311
PB
22563 {10, ARM_ARCH_V7A},
22564 {10, ARM_ARCH_V7R},
22565 {10, ARM_ARCH_V7M},
22566 {0, ARM_ARCH_NONE}
22567};
22568
ee3c0378
AS
22569/* Set an attribute if it has not already been set by the user. */
22570static void
22571aeabi_set_attribute_int (int tag, int value)
22572{
22573 if (tag < 1
22574 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22575 || !attributes_set_explicitly[tag])
22576 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22577}
22578
22579static void
22580aeabi_set_attribute_string (int tag, const char *value)
22581{
22582 if (tag < 1
22583 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22584 || !attributes_set_explicitly[tag])
22585 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22586}
22587
ee065d83
PB
22588/* Set the public EABI object attributes. */
22589static void
22590aeabi_set_public_attributes (void)
22591{
22592 int arch;
e74cfd16 22593 arm_feature_set flags;
62b3e311
PB
22594 arm_feature_set tmp;
22595 const cpu_arch_ver_table *p;
ee065d83
PB
22596
22597 /* Choose the architecture based on the capabilities of the requested cpu
22598 (if any) and/or the instructions actually used. */
e74cfd16
PB
22599 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22600 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22601 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22602 /*Allow the user to override the reported architecture. */
22603 if (object_arch)
22604 {
22605 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22606 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22607 }
22608
62b3e311
PB
22609 tmp = flags;
22610 arch = 0;
22611 for (p = cpu_arch_ver; p->val; p++)
22612 {
22613 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22614 {
22615 arch = p->val;
22616 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22617 }
22618 }
ee065d83 22619
9e3c6df6
PB
22620 /* The table lookup above finds the last architecture to contribute
22621 a new feature. Unfortunately, Tag13 is a subset of the union of
22622 v6T2 and v7-M, so it is never seen as contributing a new feature.
22623 We can not search for the last entry which is entirely used,
22624 because if no CPU is specified we build up only those flags
22625 actually used. Perhaps we should separate out the specified
22626 and implicit cases. Avoid taking this path for -march=all by
22627 checking for contradictory v7-A / v7-M features. */
22628 if (arch == 10
22629 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22630 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22631 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22632 arch = 13;
22633
ee065d83
PB
22634 /* Tag_CPU_name. */
22635 if (selected_cpu_name[0])
22636 {
91d6fa6a 22637 char *q;
ee065d83 22638
91d6fa6a
NC
22639 q = selected_cpu_name;
22640 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
22641 {
22642 int i;
5f4273c7 22643
91d6fa6a
NC
22644 q += 4;
22645 for (i = 0; q[i]; i++)
22646 q[i] = TOUPPER (q[i]);
ee065d83 22647 }
91d6fa6a 22648 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 22649 }
62f3b8c8 22650
ee065d83 22651 /* Tag_CPU_arch. */
ee3c0378 22652 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 22653
62b3e311
PB
22654 /* Tag_CPU_arch_profile. */
22655 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22656 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22657 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22658 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22659 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22660 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 22661
ee065d83 22662 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22663 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22664 || arch == 0)
22665 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 22666
ee065d83 22667 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22668 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22669 || arch == 0)
22670 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22671 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 22672
ee065d83 22673 /* Tag_VFP_arch. */
62f3b8c8
PB
22674 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22675 aeabi_set_attribute_int (Tag_VFP_arch,
22676 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22677 ? 5 : 6);
22678 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 22679 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 22680 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
22681 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22682 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22683 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22684 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22685 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22686 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 22687
ee065d83 22688 /* Tag_WMMX_arch. */
ee3c0378
AS
22689 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22690 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22691 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22692 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 22693
ee3c0378 22694 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22695 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
22696 aeabi_set_attribute_int
22697 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22698 ? 2 : 1));
22699
ee3c0378 22700 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 22701 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 22702 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
22703}
22704
104d59d1 22705/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22706void
22707arm_md_end (void)
22708{
ee065d83
PB
22709 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22710 return;
22711
22712 aeabi_set_public_attributes ();
ee065d83 22713}
8463be01 22714#endif /* OBJ_ELF */
ee065d83
PB
22715
22716
22717/* Parse a .cpu directive. */
22718
22719static void
22720s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22721{
e74cfd16 22722 const struct arm_cpu_option_table *opt;
ee065d83
PB
22723 char *name;
22724 char saved_char;
22725
22726 name = input_line_pointer;
5f4273c7 22727 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22728 input_line_pointer++;
22729 saved_char = *input_line_pointer;
22730 *input_line_pointer = 0;
22731
22732 /* Skip the first "all" entry. */
22733 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22734 if (streq (opt->name, name))
22735 {
e74cfd16
PB
22736 mcpu_cpu_opt = &opt->value;
22737 selected_cpu = opt->value;
ee065d83 22738 if (opt->canonical_name)
5f4273c7 22739 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22740 else
22741 {
22742 int i;
22743 for (i = 0; opt->name[i]; i++)
22744 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22745 selected_cpu_name[i] = 0;
22746 }
e74cfd16 22747 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22748 *input_line_pointer = saved_char;
22749 demand_empty_rest_of_line ();
22750 return;
22751 }
22752 as_bad (_("unknown cpu `%s'"), name);
22753 *input_line_pointer = saved_char;
22754 ignore_rest_of_line ();
22755}
22756
22757
22758/* Parse a .arch directive. */
22759
22760static void
22761s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22762{
e74cfd16 22763 const struct arm_arch_option_table *opt;
ee065d83
PB
22764 char saved_char;
22765 char *name;
22766
22767 name = input_line_pointer;
5f4273c7 22768 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22769 input_line_pointer++;
22770 saved_char = *input_line_pointer;
22771 *input_line_pointer = 0;
22772
22773 /* Skip the first "all" entry. */
22774 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22775 if (streq (opt->name, name))
22776 {
e74cfd16
PB
22777 mcpu_cpu_opt = &opt->value;
22778 selected_cpu = opt->value;
5f4273c7 22779 strcpy (selected_cpu_name, opt->name);
e74cfd16 22780 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22781 *input_line_pointer = saved_char;
22782 demand_empty_rest_of_line ();
22783 return;
22784 }
22785
22786 as_bad (_("unknown architecture `%s'\n"), name);
22787 *input_line_pointer = saved_char;
22788 ignore_rest_of_line ();
22789}
22790
22791
7a1d4c38
PB
22792/* Parse a .object_arch directive. */
22793
22794static void
22795s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22796{
22797 const struct arm_arch_option_table *opt;
22798 char saved_char;
22799 char *name;
22800
22801 name = input_line_pointer;
5f4273c7 22802 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22803 input_line_pointer++;
22804 saved_char = *input_line_pointer;
22805 *input_line_pointer = 0;
22806
22807 /* Skip the first "all" entry. */
22808 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22809 if (streq (opt->name, name))
22810 {
22811 object_arch = &opt->value;
22812 *input_line_pointer = saved_char;
22813 demand_empty_rest_of_line ();
22814 return;
22815 }
22816
22817 as_bad (_("unknown architecture `%s'\n"), name);
22818 *input_line_pointer = saved_char;
22819 ignore_rest_of_line ();
22820}
22821
ee065d83
PB
22822/* Parse a .fpu directive. */
22823
22824static void
22825s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22826{
e74cfd16 22827 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
22828 char saved_char;
22829 char *name;
22830
22831 name = input_line_pointer;
5f4273c7 22832 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22833 input_line_pointer++;
22834 saved_char = *input_line_pointer;
22835 *input_line_pointer = 0;
5f4273c7 22836
ee065d83
PB
22837 for (opt = arm_fpus; opt->name != NULL; opt++)
22838 if (streq (opt->name, name))
22839 {
e74cfd16
PB
22840 mfpu_opt = &opt->value;
22841 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22842 *input_line_pointer = saved_char;
22843 demand_empty_rest_of_line ();
22844 return;
22845 }
22846
22847 as_bad (_("unknown floating point format `%s'\n"), name);
22848 *input_line_pointer = saved_char;
22849 ignore_rest_of_line ();
22850}
ee065d83 22851
794ba86a 22852/* Copy symbol information. */
f31fef98 22853
794ba86a
DJ
22854void
22855arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22856{
22857 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22858}
e04befd0 22859
f31fef98 22860#ifdef OBJ_ELF
e04befd0
AS
22861/* Given a symbolic attribute NAME, return the proper integer value.
22862 Returns -1 if the attribute is not known. */
f31fef98 22863
e04befd0
AS
22864int
22865arm_convert_symbolic_attribute (const char *name)
22866{
f31fef98
NC
22867 static const struct
22868 {
22869 const char * name;
22870 const int tag;
22871 }
22872 attribute_table[] =
22873 {
22874 /* When you modify this table you should
22875 also modify the list in doc/c-arm.texi. */
e04befd0 22876#define T(tag) {#tag, tag}
f31fef98
NC
22877 T (Tag_CPU_raw_name),
22878 T (Tag_CPU_name),
22879 T (Tag_CPU_arch),
22880 T (Tag_CPU_arch_profile),
22881 T (Tag_ARM_ISA_use),
22882 T (Tag_THUMB_ISA_use),
22883 T (Tag_VFP_arch),
22884 T (Tag_WMMX_arch),
22885 T (Tag_Advanced_SIMD_arch),
22886 T (Tag_PCS_config),
22887 T (Tag_ABI_PCS_R9_use),
22888 T (Tag_ABI_PCS_RW_data),
22889 T (Tag_ABI_PCS_RO_data),
22890 T (Tag_ABI_PCS_GOT_use),
22891 T (Tag_ABI_PCS_wchar_t),
22892 T (Tag_ABI_FP_rounding),
22893 T (Tag_ABI_FP_denormal),
22894 T (Tag_ABI_FP_exceptions),
22895 T (Tag_ABI_FP_user_exceptions),
22896 T (Tag_ABI_FP_number_model),
22897 T (Tag_ABI_align8_needed),
22898 T (Tag_ABI_align8_preserved),
22899 T (Tag_ABI_enum_size),
22900 T (Tag_ABI_HardFP_use),
22901 T (Tag_ABI_VFP_args),
22902 T (Tag_ABI_WMMX_args),
22903 T (Tag_ABI_optimization_goals),
22904 T (Tag_ABI_FP_optimization_goals),
22905 T (Tag_compatibility),
22906 T (Tag_CPU_unaligned_access),
22907 T (Tag_VFP_HP_extension),
22908 T (Tag_ABI_FP_16bit_format),
22909 T (Tag_nodefaults),
22910 T (Tag_also_compatible_with),
22911 T (Tag_conformance),
22912 T (Tag_T2EE_use),
22913 T (Tag_Virtualization_use),
22914 T (Tag_MPextension_use)
e04befd0 22915#undef T
f31fef98 22916 };
e04befd0
AS
22917 unsigned int i;
22918
22919 if (name == NULL)
22920 return -1;
22921
f31fef98 22922 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 22923 if (streq (name, attribute_table[i].name))
e04befd0
AS
22924 return attribute_table[i].tag;
22925
22926 return -1;
22927}
267bf995
RR
22928
22929
22930/* Apply sym value for relocations only in the case that
22931 they are for local symbols and you have the respective
22932 architectural feature for blx and simple switches. */
22933int
22934arm_apply_sym_value (struct fix * fixP)
22935{
22936 if (fixP->fx_addsy
22937 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22938 && !S_IS_EXTERNAL (fixP->fx_addsy))
22939 {
22940 switch (fixP->fx_r_type)
22941 {
22942 case BFD_RELOC_ARM_PCREL_BLX:
22943 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22944 if (ARM_IS_FUNC (fixP->fx_addsy))
22945 return 1;
22946 break;
22947
22948 case BFD_RELOC_ARM_PCREL_CALL:
22949 case BFD_RELOC_THUMB_PCREL_BLX:
22950 if (THUMB_IS_FUNC (fixP->fx_addsy))
22951 return 1;
22952 break;
22953
22954 default:
22955 break;
22956 }
22957
22958 }
22959 return 0;
22960}
f31fef98 22961#endif /* OBJ_ELF */