]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* Makefile.am (eshlelf_fd.c): Fix typo in rule.
[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,
b43420e6 3 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 99#ifndef CPU_DEFAULT
8a59fff3
MGD
100/* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
188static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470
PB
198static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
200
201static const arm_feature_set arm_arch_any = ARM_ANY;
202static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
2d447fca
JM
206static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
208static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 220static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 221static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
222static const arm_feature_set fpu_vfp_ext_d32 =
223 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
224static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
227static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
228static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
229static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 230
33a392fb 231static int mfloat_abi_opt = -1;
e74cfd16
PB
232/* Record user cpu selection for object attributes. */
233static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
234/* Must be long enough to hold any of the names in arm_cpus. */
235static char selected_cpu_name[16];
7cc69913 236#ifdef OBJ_ELF
deeaaff8
DJ
237# ifdef EABI_DEFAULT
238static int meabi_flags = EABI_DEFAULT;
239# else
d507cf36 240static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 241# endif
e1da3f5b 242
ee3c0378
AS
243static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
244
e1da3f5b 245bfd_boolean
5f4273c7 246arm_is_eabi (void)
e1da3f5b
PB
247{
248 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
249}
7cc69913 250#endif
b99bd4ef 251
b99bd4ef 252#ifdef OBJ_ELF
c19d1205 253/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
254symbolS * GOT_symbol;
255#endif
256
b99bd4ef
NC
257/* 0: assemble for ARM,
258 1: assemble for Thumb,
259 2: assemble for Thumb even though target CPU does not support thumb
260 instructions. */
261static int thumb_mode = 0;
8dc2430f
NC
262/* A value distinct from the possible values for thumb_mode that we
263 can use to record whether thumb_mode has been copied into the
264 tc_frag_data field of a frag. */
265#define MODE_RECORDED (1 << 4)
b99bd4ef 266
e07e6e58
NC
267/* Specifies the intrinsic IT insn behavior mode. */
268enum implicit_it_mode
269{
270 IMPLICIT_IT_MODE_NEVER = 0x00,
271 IMPLICIT_IT_MODE_ARM = 0x01,
272 IMPLICIT_IT_MODE_THUMB = 0x02,
273 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
274};
275static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
276
c19d1205
ZW
277/* If unified_syntax is true, we are processing the new unified
278 ARM/Thumb syntax. Important differences from the old ARM mode:
279
280 - Immediate operands do not require a # prefix.
281 - Conditional affixes always appear at the end of the
282 instruction. (For backward compatibility, those instructions
283 that formerly had them in the middle, continue to accept them
284 there.)
285 - The IT instruction may appear, and if it does is validated
286 against subsequent conditional affixes. It does not generate
287 machine code.
288
289 Important differences from the old Thumb mode:
290
291 - Immediate operands do not require a # prefix.
292 - Most of the V6T2 instructions are only available in unified mode.
293 - The .N and .W suffixes are recognized and honored (it is an error
294 if they cannot be honored).
295 - All instructions set the flags if and only if they have an 's' affix.
296 - Conditional affixes may be used. They are validated against
297 preceding IT instructions. Unlike ARM mode, you cannot use a
298 conditional affix except in the scope of an IT instruction. */
299
300static bfd_boolean unified_syntax = FALSE;
b99bd4ef 301
5287ad62
JB
302enum neon_el_type
303{
dcbf9037 304 NT_invtype,
5287ad62
JB
305 NT_untyped,
306 NT_integer,
307 NT_float,
308 NT_poly,
309 NT_signed,
dcbf9037 310 NT_unsigned
5287ad62
JB
311};
312
313struct neon_type_el
314{
315 enum neon_el_type type;
316 unsigned size;
317};
318
319#define NEON_MAX_TYPE_ELS 4
320
321struct neon_type
322{
323 struct neon_type_el el[NEON_MAX_TYPE_ELS];
324 unsigned elems;
325};
326
e07e6e58
NC
327enum it_instruction_type
328{
329 OUTSIDE_IT_INSN,
330 INSIDE_IT_INSN,
331 INSIDE_IT_LAST_INSN,
332 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
333 if inside, should be the last one. */
334 NEUTRAL_IT_INSN, /* This could be either inside or outside,
335 i.e. BKPT and NOP. */
336 IT_INSN /* The IT insn has been parsed. */
337};
338
b99bd4ef
NC
339struct arm_it
340{
c19d1205 341 const char * error;
b99bd4ef 342 unsigned long instruction;
c19d1205
ZW
343 int size;
344 int size_req;
345 int cond;
037e8744
JB
346 /* "uncond_value" is set to the value in place of the conditional field in
347 unconditional versions of the instruction, or -1 if nothing is
348 appropriate. */
349 int uncond_value;
5287ad62 350 struct neon_type vectype;
88714cb8
DG
351 /* This does not indicate an actual NEON instruction, only that
352 the mnemonic accepts neon-style type suffixes. */
353 int is_neon;
0110f2b8
PB
354 /* Set to the opcode if the instruction needs relaxation.
355 Zero if the instruction is not relaxed. */
356 unsigned long relax;
b99bd4ef
NC
357 struct
358 {
359 bfd_reloc_code_real_type type;
c19d1205
ZW
360 expressionS exp;
361 int pc_rel;
b99bd4ef 362 } reloc;
b99bd4ef 363
e07e6e58
NC
364 enum it_instruction_type it_insn_type;
365
c19d1205
ZW
366 struct
367 {
368 unsigned reg;
ca3f61f7 369 signed int imm;
dcbf9037 370 struct neon_type_el vectype;
ca3f61f7
NC
371 unsigned present : 1; /* Operand present. */
372 unsigned isreg : 1; /* Operand was a register. */
373 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
374 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
375 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 376 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
377 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
378 instructions. This allows us to disambiguate ARM <-> vector insns. */
379 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 380 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 381 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 382 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
383 unsigned hasreloc : 1; /* Operand has relocation suffix. */
384 unsigned writeback : 1; /* Operand has trailing ! */
385 unsigned preind : 1; /* Preindexed address. */
386 unsigned postind : 1; /* Postindexed address. */
387 unsigned negative : 1; /* Index register was negated. */
388 unsigned shifted : 1; /* Shift applied to operation. */
389 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 390 } operands[6];
b99bd4ef
NC
391};
392
c19d1205 393static struct arm_it inst;
b99bd4ef
NC
394
395#define NUM_FLOAT_VALS 8
396
05d2d07e 397const char * fp_const[] =
b99bd4ef
NC
398{
399 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400};
401
c19d1205 402/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
403#define MAX_LITTLENUMS 6
404
405LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
406
407#define FAIL (-1)
408#define SUCCESS (0)
409
410#define SUFF_S 1
411#define SUFF_D 2
412#define SUFF_E 3
413#define SUFF_P 4
414
c19d1205
ZW
415#define CP_T_X 0x00008000
416#define CP_T_Y 0x00400000
b99bd4ef 417
c19d1205
ZW
418#define CONDS_BIT 0x00100000
419#define LOAD_BIT 0x00100000
b99bd4ef
NC
420
421#define DOUBLE_LOAD_FLAG 0x00000001
422
423struct asm_cond
424{
d3ce72d0 425 const char * template_name;
c921be7d 426 unsigned long value;
b99bd4ef
NC
427};
428
c19d1205 429#define COND_ALWAYS 0xE
b99bd4ef 430
b99bd4ef
NC
431struct asm_psr
432{
d3ce72d0 433 const char * template_name;
c921be7d 434 unsigned long field;
b99bd4ef
NC
435};
436
62b3e311
PB
437struct asm_barrier_opt
438{
d3ce72d0 439 const char * template_name;
c921be7d 440 unsigned long value;
62b3e311
PB
441};
442
2d2255b5 443/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
444#define SPSR_BIT (1 << 22)
445
c19d1205
ZW
446/* The individual PSR flag bits. */
447#define PSR_c (1 << 16)
448#define PSR_x (1 << 17)
449#define PSR_s (1 << 18)
450#define PSR_f (1 << 19)
b99bd4ef 451
c19d1205 452struct reloc_entry
bfae80f2 453{
c921be7d
NC
454 char * name;
455 bfd_reloc_code_real_type reloc;
bfae80f2
RE
456};
457
5287ad62 458enum vfp_reg_pos
bfae80f2 459{
5287ad62
JB
460 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
461 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
462};
463
464enum vfp_ldstm_type
465{
466 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467};
468
dcbf9037
JB
469/* Bits for DEFINED field in neon_typed_alias. */
470#define NTA_HASTYPE 1
471#define NTA_HASINDEX 2
472
473struct neon_typed_alias
474{
c921be7d
NC
475 unsigned char defined;
476 unsigned char index;
477 struct neon_type_el eltype;
dcbf9037
JB
478};
479
c19d1205
ZW
480/* ARM register categories. This includes coprocessor numbers and various
481 architecture extensions' registers. */
482enum arm_reg_type
bfae80f2 483{
c19d1205
ZW
484 REG_TYPE_RN,
485 REG_TYPE_CP,
486 REG_TYPE_CN,
487 REG_TYPE_FN,
488 REG_TYPE_VFS,
489 REG_TYPE_VFD,
5287ad62 490 REG_TYPE_NQ,
037e8744 491 REG_TYPE_VFSD,
5287ad62 492 REG_TYPE_NDQ,
037e8744 493 REG_TYPE_NSDQ,
c19d1205
ZW
494 REG_TYPE_VFC,
495 REG_TYPE_MVF,
496 REG_TYPE_MVD,
497 REG_TYPE_MVFX,
498 REG_TYPE_MVDX,
499 REG_TYPE_MVAX,
500 REG_TYPE_DSPSC,
501 REG_TYPE_MMXWR,
502 REG_TYPE_MMXWC,
503 REG_TYPE_MMXWCG,
504 REG_TYPE_XSCALE,
bfae80f2
RE
505};
506
dcbf9037
JB
507/* Structure for a hash table entry for a register.
508 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
509 information which states whether a vector type or index is specified (for a
510 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
511struct reg_entry
512{
c921be7d
NC
513 const char * name;
514 unsigned char number;
515 unsigned char type;
516 unsigned char builtin;
517 struct neon_typed_alias * neon;
6c43fab6
RE
518};
519
c19d1205 520/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 521const char * const reg_expected_msgs[] =
c19d1205
ZW
522{
523 N_("ARM register expected"),
524 N_("bad or missing co-processor number"),
525 N_("co-processor register expected"),
526 N_("FPA register expected"),
527 N_("VFP single precision register expected"),
5287ad62
JB
528 N_("VFP/Neon double precision register expected"),
529 N_("Neon quad precision register expected"),
037e8744 530 N_("VFP single or double precision register expected"),
5287ad62 531 N_("Neon double or quad precision register expected"),
037e8744 532 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
533 N_("VFP system register expected"),
534 N_("Maverick MVF register expected"),
535 N_("Maverick MVD register expected"),
536 N_("Maverick MVFX register expected"),
537 N_("Maverick MVDX register expected"),
538 N_("Maverick MVAX register expected"),
539 N_("Maverick DSPSC register expected"),
540 N_("iWMMXt data register expected"),
541 N_("iWMMXt control register expected"),
542 N_("iWMMXt scalar register expected"),
543 N_("XScale accumulator register expected"),
6c43fab6
RE
544};
545
c19d1205
ZW
546/* Some well known registers that we refer to directly elsewhere. */
547#define REG_SP 13
548#define REG_LR 14
549#define REG_PC 15
404ff6b5 550
b99bd4ef
NC
551/* ARM instructions take 4bytes in the object file, Thumb instructions
552 take 2: */
c19d1205 553#define INSN_SIZE 4
b99bd4ef
NC
554
555struct asm_opcode
556{
557 /* Basic string to match. */
d3ce72d0 558 const char * template_name;
c19d1205
ZW
559
560 /* Parameters to instruction. */
5be8be5d 561 unsigned int operands[8];
c19d1205
ZW
562
563 /* Conditional tag - see opcode_lookup. */
564 unsigned int tag : 4;
b99bd4ef
NC
565
566 /* Basic instruction code. */
c19d1205 567 unsigned int avalue : 28;
b99bd4ef 568
c19d1205
ZW
569 /* Thumb-format instruction code. */
570 unsigned int tvalue;
b99bd4ef 571
90e4755a 572 /* Which architecture variant provides this instruction. */
c921be7d
NC
573 const arm_feature_set * avariant;
574 const arm_feature_set * tvariant;
c19d1205
ZW
575
576 /* Function to call to encode instruction in ARM format. */
577 void (* aencode) (void);
b99bd4ef 578
c19d1205
ZW
579 /* Function to call to encode instruction in Thumb format. */
580 void (* tencode) (void);
b99bd4ef
NC
581};
582
a737bd4d
NC
583/* Defines for various bits that we will want to toggle. */
584#define INST_IMMEDIATE 0x02000000
585#define OFFSET_REG 0x02000000
c19d1205 586#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
587#define SHIFT_BY_REG 0x00000010
588#define PRE_INDEX 0x01000000
589#define INDEX_UP 0x00800000
590#define WRITE_BACK 0x00200000
591#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 592#define CPSI_MMOD 0x00020000
90e4755a 593
a737bd4d
NC
594#define LITERAL_MASK 0xf000f000
595#define OPCODE_MASK 0xfe1fffff
596#define V4_STR_BIT 0x00000020
90e4755a 597
efd81785
PB
598#define T2_SUBS_PC_LR 0xf3de8f00
599
a737bd4d 600#define DATA_OP_SHIFT 21
90e4755a 601
ef8d22e6
PB
602#define T2_OPCODE_MASK 0xfe1fffff
603#define T2_DATA_OP_SHIFT 21
604
a737bd4d
NC
605/* Codes to distinguish the arithmetic instructions. */
606#define OPCODE_AND 0
607#define OPCODE_EOR 1
608#define OPCODE_SUB 2
609#define OPCODE_RSB 3
610#define OPCODE_ADD 4
611#define OPCODE_ADC 5
612#define OPCODE_SBC 6
613#define OPCODE_RSC 7
614#define OPCODE_TST 8
615#define OPCODE_TEQ 9
616#define OPCODE_CMP 10
617#define OPCODE_CMN 11
618#define OPCODE_ORR 12
619#define OPCODE_MOV 13
620#define OPCODE_BIC 14
621#define OPCODE_MVN 15
90e4755a 622
ef8d22e6
PB
623#define T2_OPCODE_AND 0
624#define T2_OPCODE_BIC 1
625#define T2_OPCODE_ORR 2
626#define T2_OPCODE_ORN 3
627#define T2_OPCODE_EOR 4
628#define T2_OPCODE_ADD 8
629#define T2_OPCODE_ADC 10
630#define T2_OPCODE_SBC 11
631#define T2_OPCODE_SUB 13
632#define T2_OPCODE_RSB 14
633
a737bd4d
NC
634#define T_OPCODE_MUL 0x4340
635#define T_OPCODE_TST 0x4200
636#define T_OPCODE_CMN 0x42c0
637#define T_OPCODE_NEG 0x4240
638#define T_OPCODE_MVN 0x43c0
90e4755a 639
a737bd4d
NC
640#define T_OPCODE_ADD_R3 0x1800
641#define T_OPCODE_SUB_R3 0x1a00
642#define T_OPCODE_ADD_HI 0x4400
643#define T_OPCODE_ADD_ST 0xb000
644#define T_OPCODE_SUB_ST 0xb080
645#define T_OPCODE_ADD_SP 0xa800
646#define T_OPCODE_ADD_PC 0xa000
647#define T_OPCODE_ADD_I8 0x3000
648#define T_OPCODE_SUB_I8 0x3800
649#define T_OPCODE_ADD_I3 0x1c00
650#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 651
a737bd4d
NC
652#define T_OPCODE_ASR_R 0x4100
653#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
654#define T_OPCODE_LSR_R 0x40c0
655#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
656#define T_OPCODE_ASR_I 0x1000
657#define T_OPCODE_LSL_I 0x0000
658#define T_OPCODE_LSR_I 0x0800
b99bd4ef 659
a737bd4d
NC
660#define T_OPCODE_MOV_I8 0x2000
661#define T_OPCODE_CMP_I8 0x2800
662#define T_OPCODE_CMP_LR 0x4280
663#define T_OPCODE_MOV_HR 0x4600
664#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 665
a737bd4d
NC
666#define T_OPCODE_LDR_PC 0x4800
667#define T_OPCODE_LDR_SP 0x9800
668#define T_OPCODE_STR_SP 0x9000
669#define T_OPCODE_LDR_IW 0x6800
670#define T_OPCODE_STR_IW 0x6000
671#define T_OPCODE_LDR_IH 0x8800
672#define T_OPCODE_STR_IH 0x8000
673#define T_OPCODE_LDR_IB 0x7800
674#define T_OPCODE_STR_IB 0x7000
675#define T_OPCODE_LDR_RW 0x5800
676#define T_OPCODE_STR_RW 0x5000
677#define T_OPCODE_LDR_RH 0x5a00
678#define T_OPCODE_STR_RH 0x5200
679#define T_OPCODE_LDR_RB 0x5c00
680#define T_OPCODE_STR_RB 0x5400
c9b604bd 681
a737bd4d
NC
682#define T_OPCODE_PUSH 0xb400
683#define T_OPCODE_POP 0xbc00
b99bd4ef 684
2fc8bdac 685#define T_OPCODE_BRANCH 0xe000
b99bd4ef 686
a737bd4d 687#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 688#define THUMB_PP_PC_LR 0x0100
c19d1205 689#define THUMB_LOAD_BIT 0x0800
53365c0d 690#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
691
692#define BAD_ARGS _("bad arguments to instruction")
fdfde340 693#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
694#define BAD_PC _("r15 not allowed here")
695#define BAD_COND _("instruction cannot be conditional")
696#define BAD_OVERLAP _("registers may not be the same")
697#define BAD_HIREG _("lo register required")
698#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 699#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
700#define BAD_BRANCH _("branch must be last instruction in IT block")
701#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 702#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
703#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
704#define BAD_IT_COND _("incorrect condition in IT block")
705#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 706#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
707#define BAD_PC_ADDRESSING \
708 _("cannot use register index with PC-relative addressing")
709#define BAD_PC_WRITEBACK \
710 _("cannot use writeback with PC-relative addressing")
c19d1205 711
c921be7d
NC
712static struct hash_control * arm_ops_hsh;
713static struct hash_control * arm_cond_hsh;
714static struct hash_control * arm_shift_hsh;
715static struct hash_control * arm_psr_hsh;
716static struct hash_control * arm_v7m_psr_hsh;
717static struct hash_control * arm_reg_hsh;
718static struct hash_control * arm_reloc_hsh;
719static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 720
b99bd4ef
NC
721/* Stuff needed to resolve the label ambiguity
722 As:
723 ...
724 label: <insn>
725 may differ from:
726 ...
727 label:
5f4273c7 728 <insn> */
b99bd4ef
NC
729
730symbolS * last_label_seen;
b34976b6 731static int label_is_thumb_function_name = FALSE;
e07e6e58 732
3d0c9500
NC
733/* Literal pool structure. Held on a per-section
734 and per-sub-section basis. */
a737bd4d 735
c19d1205 736#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 737typedef struct literal_pool
b99bd4ef 738{
c921be7d
NC
739 expressionS literals [MAX_LITERAL_POOL_SIZE];
740 unsigned int next_free_entry;
741 unsigned int id;
742 symbolS * symbol;
743 segT section;
744 subsegT sub_section;
745 struct literal_pool * next;
3d0c9500 746} literal_pool;
b99bd4ef 747
3d0c9500
NC
748/* Pointer to a linked list of literal pools. */
749literal_pool * list_of_pools = NULL;
e27ec89e 750
e07e6e58
NC
751#ifdef OBJ_ELF
752# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
753#else
754static struct current_it now_it;
755#endif
756
757static inline int
758now_it_compatible (int cond)
759{
760 return (cond & ~1) == (now_it.cc & ~1);
761}
762
763static inline int
764conditional_insn (void)
765{
766 return inst.cond != COND_ALWAYS;
767}
768
769static int in_it_block (void);
770
771static int handle_it_state (void);
772
773static void force_automatic_it_block_close (void);
774
c921be7d
NC
775static void it_fsm_post_encode (void);
776
e07e6e58
NC
777#define set_it_insn_type(type) \
778 do \
779 { \
780 inst.it_insn_type = type; \
781 if (handle_it_state () == FAIL) \
782 return; \
783 } \
784 while (0)
785
c921be7d
NC
786#define set_it_insn_type_nonvoid(type, failret) \
787 do \
788 { \
789 inst.it_insn_type = type; \
790 if (handle_it_state () == FAIL) \
791 return failret; \
792 } \
793 while(0)
794
e07e6e58
NC
795#define set_it_insn_type_last() \
796 do \
797 { \
798 if (inst.cond == COND_ALWAYS) \
799 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
800 else \
801 set_it_insn_type (INSIDE_IT_LAST_INSN); \
802 } \
803 while (0)
804
c19d1205 805/* Pure syntax. */
b99bd4ef 806
c19d1205
ZW
807/* This array holds the chars that always start a comment. If the
808 pre-processor is disabled, these aren't very useful. */
809const char comment_chars[] = "@";
3d0c9500 810
c19d1205
ZW
811/* This array holds the chars that only start a comment at the beginning of
812 a line. If the line seems to have the form '# 123 filename'
813 .line and .file directives will appear in the pre-processed output. */
814/* Note that input_file.c hand checks for '#' at the beginning of the
815 first line of the input file. This is because the compiler outputs
816 #NO_APP at the beginning of its output. */
817/* Also note that comments like this one will always work. */
818const char line_comment_chars[] = "#";
3d0c9500 819
c19d1205 820const char line_separator_chars[] = ";";
b99bd4ef 821
c19d1205
ZW
822/* Chars that can be used to separate mant
823 from exp in floating point numbers. */
824const char EXP_CHARS[] = "eE";
3d0c9500 825
c19d1205
ZW
826/* Chars that mean this number is a floating point constant. */
827/* As in 0f12.456 */
828/* or 0d1.2345e12 */
b99bd4ef 829
c19d1205 830const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 831
c19d1205
ZW
832/* Prefix characters that indicate the start of an immediate
833 value. */
834#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 835
c19d1205
ZW
836/* Separator character handling. */
837
838#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
839
840static inline int
841skip_past_char (char ** str, char c)
842{
843 if (**str == c)
844 {
845 (*str)++;
846 return SUCCESS;
3d0c9500 847 }
c19d1205
ZW
848 else
849 return FAIL;
850}
c921be7d 851
c19d1205 852#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 853
c19d1205
ZW
854/* Arithmetic expressions (possibly involving symbols). */
855
856/* Return TRUE if anything in the expression is a bignum. */
857
858static int
859walk_no_bignums (symbolS * sp)
860{
861 if (symbol_get_value_expression (sp)->X_op == O_big)
862 return 1;
863
864 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 865 {
c19d1205
ZW
866 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
867 || (symbol_get_value_expression (sp)->X_op_symbol
868 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
869 }
870
c19d1205 871 return 0;
3d0c9500
NC
872}
873
c19d1205
ZW
874static int in_my_get_expression = 0;
875
876/* Third argument to my_get_expression. */
877#define GE_NO_PREFIX 0
878#define GE_IMM_PREFIX 1
879#define GE_OPT_PREFIX 2
5287ad62
JB
880/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
881 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
882#define GE_OPT_PREFIX_BIG 3
a737bd4d 883
b99bd4ef 884static int
c19d1205 885my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 886{
c19d1205
ZW
887 char * save_in;
888 segT seg;
b99bd4ef 889
c19d1205
ZW
890 /* In unified syntax, all prefixes are optional. */
891 if (unified_syntax)
5287ad62
JB
892 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
893 : GE_OPT_PREFIX;
b99bd4ef 894
c19d1205 895 switch (prefix_mode)
b99bd4ef 896 {
c19d1205
ZW
897 case GE_NO_PREFIX: break;
898 case GE_IMM_PREFIX:
899 if (!is_immediate_prefix (**str))
900 {
901 inst.error = _("immediate expression requires a # prefix");
902 return FAIL;
903 }
904 (*str)++;
905 break;
906 case GE_OPT_PREFIX:
5287ad62 907 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
908 if (is_immediate_prefix (**str))
909 (*str)++;
910 break;
911 default: abort ();
912 }
b99bd4ef 913
c19d1205 914 memset (ep, 0, sizeof (expressionS));
b99bd4ef 915
c19d1205
ZW
916 save_in = input_line_pointer;
917 input_line_pointer = *str;
918 in_my_get_expression = 1;
919 seg = expression (ep);
920 in_my_get_expression = 0;
921
f86adc07 922 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 923 {
f86adc07 924 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
925 *str = input_line_pointer;
926 input_line_pointer = save_in;
927 if (inst.error == NULL)
f86adc07
NS
928 inst.error = (ep->X_op == O_absent
929 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
930 return 1;
931 }
b99bd4ef 932
c19d1205
ZW
933#ifdef OBJ_AOUT
934 if (seg != absolute_section
935 && seg != text_section
936 && seg != data_section
937 && seg != bss_section
938 && seg != undefined_section)
939 {
940 inst.error = _("bad segment");
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 return 1;
b99bd4ef 944 }
c19d1205 945#endif
b99bd4ef 946
c19d1205
ZW
947 /* Get rid of any bignums now, so that we don't generate an error for which
948 we can't establish a line number later on. Big numbers are never valid
949 in instructions, which is where this routine is always called. */
5287ad62
JB
950 if (prefix_mode != GE_OPT_PREFIX_BIG
951 && (ep->X_op == O_big
952 || (ep->X_add_symbol
953 && (walk_no_bignums (ep->X_add_symbol)
954 || (ep->X_op_symbol
955 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
956 {
957 inst.error = _("invalid constant");
958 *str = input_line_pointer;
959 input_line_pointer = save_in;
960 return 1;
961 }
b99bd4ef 962
c19d1205
ZW
963 *str = input_line_pointer;
964 input_line_pointer = save_in;
965 return 0;
b99bd4ef
NC
966}
967
c19d1205
ZW
968/* Turn a string in input_line_pointer into a floating point constant
969 of type TYPE, and store the appropriate bytes in *LITP. The number
970 of LITTLENUMS emitted is stored in *SIZEP. An error message is
971 returned, or NULL on OK.
b99bd4ef 972
c19d1205
ZW
973 Note that fp constants aren't represent in the normal way on the ARM.
974 In big endian mode, things are as expected. However, in little endian
975 mode fp constants are big-endian word-wise, and little-endian byte-wise
976 within the words. For example, (double) 1.1 in big endian mode is
977 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
978 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 979
c19d1205 980 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 981
c19d1205
ZW
982char *
983md_atof (int type, char * litP, int * sizeP)
984{
985 int prec;
986 LITTLENUM_TYPE words[MAX_LITTLENUMS];
987 char *t;
988 int i;
b99bd4ef 989
c19d1205
ZW
990 switch (type)
991 {
992 case 'f':
993 case 'F':
994 case 's':
995 case 'S':
996 prec = 2;
997 break;
b99bd4ef 998
c19d1205
ZW
999 case 'd':
1000 case 'D':
1001 case 'r':
1002 case 'R':
1003 prec = 4;
1004 break;
b99bd4ef 1005
c19d1205
ZW
1006 case 'x':
1007 case 'X':
499ac353 1008 prec = 5;
c19d1205 1009 break;
b99bd4ef 1010
c19d1205
ZW
1011 case 'p':
1012 case 'P':
499ac353 1013 prec = 5;
c19d1205 1014 break;
a737bd4d 1015
c19d1205
ZW
1016 default:
1017 *sizeP = 0;
499ac353 1018 return _("Unrecognized or unsupported floating point constant");
c19d1205 1019 }
b99bd4ef 1020
c19d1205
ZW
1021 t = atof_ieee (input_line_pointer, type, words);
1022 if (t)
1023 input_line_pointer = t;
499ac353 1024 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1025
c19d1205
ZW
1026 if (target_big_endian)
1027 {
1028 for (i = 0; i < prec; i++)
1029 {
499ac353
NC
1030 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1031 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1032 }
1033 }
1034 else
1035 {
e74cfd16 1036 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1037 for (i = prec - 1; i >= 0; i--)
1038 {
499ac353
NC
1039 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1040 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1041 }
1042 else
1043 /* For a 4 byte float the order of elements in `words' is 1 0.
1044 For an 8 byte float the order is 1 0 3 2. */
1045 for (i = 0; i < prec; i += 2)
1046 {
499ac353
NC
1047 md_number_to_chars (litP, (valueT) words[i + 1],
1048 sizeof (LITTLENUM_TYPE));
1049 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1050 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1051 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1052 }
1053 }
b99bd4ef 1054
499ac353 1055 return NULL;
c19d1205 1056}
b99bd4ef 1057
c19d1205
ZW
1058/* We handle all bad expressions here, so that we can report the faulty
1059 instruction in the error message. */
1060void
91d6fa6a 1061md_operand (expressionS * exp)
c19d1205
ZW
1062{
1063 if (in_my_get_expression)
91d6fa6a 1064 exp->X_op = O_illegal;
b99bd4ef
NC
1065}
1066
c19d1205 1067/* Immediate values. */
b99bd4ef 1068
c19d1205
ZW
1069/* Generic immediate-value read function for use in directives.
1070 Accepts anything that 'expression' can fold to a constant.
1071 *val receives the number. */
1072#ifdef OBJ_ELF
1073static int
1074immediate_for_directive (int *val)
b99bd4ef 1075{
c19d1205
ZW
1076 expressionS exp;
1077 exp.X_op = O_illegal;
b99bd4ef 1078
c19d1205
ZW
1079 if (is_immediate_prefix (*input_line_pointer))
1080 {
1081 input_line_pointer++;
1082 expression (&exp);
1083 }
b99bd4ef 1084
c19d1205
ZW
1085 if (exp.X_op != O_constant)
1086 {
1087 as_bad (_("expected #constant"));
1088 ignore_rest_of_line ();
1089 return FAIL;
1090 }
1091 *val = exp.X_add_number;
1092 return SUCCESS;
b99bd4ef 1093}
c19d1205 1094#endif
b99bd4ef 1095
c19d1205 1096/* Register parsing. */
b99bd4ef 1097
c19d1205
ZW
1098/* Generic register parser. CCP points to what should be the
1099 beginning of a register name. If it is indeed a valid register
1100 name, advance CCP over it and return the reg_entry structure;
1101 otherwise return NULL. Does not issue diagnostics. */
1102
1103static struct reg_entry *
1104arm_reg_parse_multi (char **ccp)
b99bd4ef 1105{
c19d1205
ZW
1106 char *start = *ccp;
1107 char *p;
1108 struct reg_entry *reg;
b99bd4ef 1109
c19d1205
ZW
1110#ifdef REGISTER_PREFIX
1111 if (*start != REGISTER_PREFIX)
01cfc07f 1112 return NULL;
c19d1205
ZW
1113 start++;
1114#endif
1115#ifdef OPTIONAL_REGISTER_PREFIX
1116 if (*start == OPTIONAL_REGISTER_PREFIX)
1117 start++;
1118#endif
b99bd4ef 1119
c19d1205
ZW
1120 p = start;
1121 if (!ISALPHA (*p) || !is_name_beginner (*p))
1122 return NULL;
b99bd4ef 1123
c19d1205
ZW
1124 do
1125 p++;
1126 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1127
1128 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1129
1130 if (!reg)
1131 return NULL;
1132
1133 *ccp = p;
1134 return reg;
b99bd4ef
NC
1135}
1136
1137static int
dcbf9037
JB
1138arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1139 enum arm_reg_type type)
b99bd4ef 1140{
c19d1205
ZW
1141 /* Alternative syntaxes are accepted for a few register classes. */
1142 switch (type)
1143 {
1144 case REG_TYPE_MVF:
1145 case REG_TYPE_MVD:
1146 case REG_TYPE_MVFX:
1147 case REG_TYPE_MVDX:
1148 /* Generic coprocessor register names are allowed for these. */
79134647 1149 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1150 return reg->number;
1151 break;
69b97547 1152
c19d1205
ZW
1153 case REG_TYPE_CP:
1154 /* For backward compatibility, a bare number is valid here. */
1155 {
1156 unsigned long processor = strtoul (start, ccp, 10);
1157 if (*ccp != start && processor <= 15)
1158 return processor;
1159 }
6057a28f 1160
c19d1205
ZW
1161 case REG_TYPE_MMXWC:
1162 /* WC includes WCG. ??? I'm not sure this is true for all
1163 instructions that take WC registers. */
79134647 1164 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1165 return reg->number;
6057a28f 1166 break;
c19d1205 1167
6057a28f 1168 default:
c19d1205 1169 break;
6057a28f
NC
1170 }
1171
dcbf9037
JB
1172 return FAIL;
1173}
1174
1175/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1176 return value is the register number or FAIL. */
1177
1178static int
1179arm_reg_parse (char **ccp, enum arm_reg_type type)
1180{
1181 char *start = *ccp;
1182 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1183 int ret;
1184
1185 /* Do not allow a scalar (reg+index) to parse as a register. */
1186 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1187 return FAIL;
1188
1189 if (reg && reg->type == type)
1190 return reg->number;
1191
1192 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1193 return ret;
1194
c19d1205
ZW
1195 *ccp = start;
1196 return FAIL;
1197}
69b97547 1198
dcbf9037
JB
1199/* Parse a Neon type specifier. *STR should point at the leading '.'
1200 character. Does no verification at this stage that the type fits the opcode
1201 properly. E.g.,
1202
1203 .i32.i32.s16
1204 .s32.f32
1205 .u16
1206
1207 Can all be legally parsed by this function.
1208
1209 Fills in neon_type struct pointer with parsed information, and updates STR
1210 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1211 type, FAIL if not. */
1212
1213static int
1214parse_neon_type (struct neon_type *type, char **str)
1215{
1216 char *ptr = *str;
1217
1218 if (type)
1219 type->elems = 0;
1220
1221 while (type->elems < NEON_MAX_TYPE_ELS)
1222 {
1223 enum neon_el_type thistype = NT_untyped;
1224 unsigned thissize = -1u;
1225
1226 if (*ptr != '.')
1227 break;
1228
1229 ptr++;
1230
1231 /* Just a size without an explicit type. */
1232 if (ISDIGIT (*ptr))
1233 goto parsesize;
1234
1235 switch (TOLOWER (*ptr))
1236 {
1237 case 'i': thistype = NT_integer; break;
1238 case 'f': thistype = NT_float; break;
1239 case 'p': thistype = NT_poly; break;
1240 case 's': thistype = NT_signed; break;
1241 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1242 case 'd':
1243 thistype = NT_float;
1244 thissize = 64;
1245 ptr++;
1246 goto done;
dcbf9037
JB
1247 default:
1248 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1249 return FAIL;
1250 }
1251
1252 ptr++;
1253
1254 /* .f is an abbreviation for .f32. */
1255 if (thistype == NT_float && !ISDIGIT (*ptr))
1256 thissize = 32;
1257 else
1258 {
1259 parsesize:
1260 thissize = strtoul (ptr, &ptr, 10);
1261
1262 if (thissize != 8 && thissize != 16 && thissize != 32
1263 && thissize != 64)
1264 {
1265 as_bad (_("bad size %d in type specifier"), thissize);
1266 return FAIL;
1267 }
1268 }
1269
037e8744 1270 done:
dcbf9037
JB
1271 if (type)
1272 {
1273 type->el[type->elems].type = thistype;
1274 type->el[type->elems].size = thissize;
1275 type->elems++;
1276 }
1277 }
1278
1279 /* Empty/missing type is not a successful parse. */
1280 if (type->elems == 0)
1281 return FAIL;
1282
1283 *str = ptr;
1284
1285 return SUCCESS;
1286}
1287
1288/* Errors may be set multiple times during parsing or bit encoding
1289 (particularly in the Neon bits), but usually the earliest error which is set
1290 will be the most meaningful. Avoid overwriting it with later (cascading)
1291 errors by calling this function. */
1292
1293static void
1294first_error (const char *err)
1295{
1296 if (!inst.error)
1297 inst.error = err;
1298}
1299
1300/* Parse a single type, e.g. ".s32", leading period included. */
1301static int
1302parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1303{
1304 char *str = *ccp;
1305 struct neon_type optype;
1306
1307 if (*str == '.')
1308 {
1309 if (parse_neon_type (&optype, &str) == SUCCESS)
1310 {
1311 if (optype.elems == 1)
1312 *vectype = optype.el[0];
1313 else
1314 {
1315 first_error (_("only one type should be specified for operand"));
1316 return FAIL;
1317 }
1318 }
1319 else
1320 {
1321 first_error (_("vector type expected"));
1322 return FAIL;
1323 }
1324 }
1325 else
1326 return FAIL;
5f4273c7 1327
dcbf9037 1328 *ccp = str;
5f4273c7 1329
dcbf9037
JB
1330 return SUCCESS;
1331}
1332
1333/* Special meanings for indices (which have a range of 0-7), which will fit into
1334 a 4-bit integer. */
1335
1336#define NEON_ALL_LANES 15
1337#define NEON_INTERLEAVE_LANES 14
1338
1339/* Parse either a register or a scalar, with an optional type. Return the
1340 register number, and optionally fill in the actual type of the register
1341 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1342 type/index information in *TYPEINFO. */
1343
1344static int
1345parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1346 enum arm_reg_type *rtype,
1347 struct neon_typed_alias *typeinfo)
1348{
1349 char *str = *ccp;
1350 struct reg_entry *reg = arm_reg_parse_multi (&str);
1351 struct neon_typed_alias atype;
1352 struct neon_type_el parsetype;
1353
1354 atype.defined = 0;
1355 atype.index = -1;
1356 atype.eltype.type = NT_invtype;
1357 atype.eltype.size = -1;
1358
1359 /* Try alternate syntax for some types of register. Note these are mutually
1360 exclusive with the Neon syntax extensions. */
1361 if (reg == NULL)
1362 {
1363 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1364 if (altreg != FAIL)
1365 *ccp = str;
1366 if (typeinfo)
1367 *typeinfo = atype;
1368 return altreg;
1369 }
1370
037e8744
JB
1371 /* Undo polymorphism when a set of register types may be accepted. */
1372 if ((type == REG_TYPE_NDQ
1373 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1374 || (type == REG_TYPE_VFSD
1375 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1376 || (type == REG_TYPE_NSDQ
1377 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1378 || reg->type == REG_TYPE_NQ))
1379 || (type == REG_TYPE_MMXWC
1380 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1381 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1382
1383 if (type != reg->type)
1384 return FAIL;
1385
1386 if (reg->neon)
1387 atype = *reg->neon;
5f4273c7 1388
dcbf9037
JB
1389 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1390 {
1391 if ((atype.defined & NTA_HASTYPE) != 0)
1392 {
1393 first_error (_("can't redefine type for operand"));
1394 return FAIL;
1395 }
1396 atype.defined |= NTA_HASTYPE;
1397 atype.eltype = parsetype;
1398 }
5f4273c7 1399
dcbf9037
JB
1400 if (skip_past_char (&str, '[') == SUCCESS)
1401 {
1402 if (type != REG_TYPE_VFD)
1403 {
1404 first_error (_("only D registers may be indexed"));
1405 return FAIL;
1406 }
5f4273c7 1407
dcbf9037
JB
1408 if ((atype.defined & NTA_HASINDEX) != 0)
1409 {
1410 first_error (_("can't change index for operand"));
1411 return FAIL;
1412 }
1413
1414 atype.defined |= NTA_HASINDEX;
1415
1416 if (skip_past_char (&str, ']') == SUCCESS)
1417 atype.index = NEON_ALL_LANES;
1418 else
1419 {
1420 expressionS exp;
1421
1422 my_get_expression (&exp, &str, GE_NO_PREFIX);
1423
1424 if (exp.X_op != O_constant)
1425 {
1426 first_error (_("constant expression required"));
1427 return FAIL;
1428 }
1429
1430 if (skip_past_char (&str, ']') == FAIL)
1431 return FAIL;
1432
1433 atype.index = exp.X_add_number;
1434 }
1435 }
5f4273c7 1436
dcbf9037
JB
1437 if (typeinfo)
1438 *typeinfo = atype;
5f4273c7 1439
dcbf9037
JB
1440 if (rtype)
1441 *rtype = type;
5f4273c7 1442
dcbf9037 1443 *ccp = str;
5f4273c7 1444
dcbf9037
JB
1445 return reg->number;
1446}
1447
1448/* Like arm_reg_parse, but allow allow the following extra features:
1449 - If RTYPE is non-zero, return the (possibly restricted) type of the
1450 register (e.g. Neon double or quad reg when either has been requested).
1451 - If this is a Neon vector type with additional type information, fill
1452 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1453 This function will fault on encountering a scalar. */
dcbf9037
JB
1454
1455static int
1456arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1457 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1458{
1459 struct neon_typed_alias atype;
1460 char *str = *ccp;
1461 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1462
1463 if (reg == FAIL)
1464 return FAIL;
1465
1466 /* Do not allow a scalar (reg+index) to parse as a register. */
1467 if ((atype.defined & NTA_HASINDEX) != 0)
1468 {
1469 first_error (_("register operand expected, but got scalar"));
1470 return FAIL;
1471 }
1472
1473 if (vectype)
1474 *vectype = atype.eltype;
1475
1476 *ccp = str;
1477
1478 return reg;
1479}
1480
1481#define NEON_SCALAR_REG(X) ((X) >> 4)
1482#define NEON_SCALAR_INDEX(X) ((X) & 15)
1483
5287ad62
JB
1484/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1485 have enough information to be able to do a good job bounds-checking. So, we
1486 just do easy checks here, and do further checks later. */
1487
1488static int
dcbf9037 1489parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1490{
dcbf9037 1491 int reg;
5287ad62 1492 char *str = *ccp;
dcbf9037 1493 struct neon_typed_alias atype;
5f4273c7 1494
dcbf9037 1495 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1496
dcbf9037 1497 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1498 return FAIL;
5f4273c7 1499
dcbf9037 1500 if (atype.index == NEON_ALL_LANES)
5287ad62 1501 {
dcbf9037 1502 first_error (_("scalar must have an index"));
5287ad62
JB
1503 return FAIL;
1504 }
dcbf9037 1505 else if (atype.index >= 64 / elsize)
5287ad62 1506 {
dcbf9037 1507 first_error (_("scalar index out of range"));
5287ad62
JB
1508 return FAIL;
1509 }
5f4273c7 1510
dcbf9037
JB
1511 if (type)
1512 *type = atype.eltype;
5f4273c7 1513
5287ad62 1514 *ccp = str;
5f4273c7 1515
dcbf9037 1516 return reg * 16 + atype.index;
5287ad62
JB
1517}
1518
c19d1205 1519/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1520
c19d1205
ZW
1521static long
1522parse_reg_list (char ** strp)
1523{
1524 char * str = * strp;
1525 long range = 0;
1526 int another_range;
a737bd4d 1527
c19d1205
ZW
1528 /* We come back here if we get ranges concatenated by '+' or '|'. */
1529 do
6057a28f 1530 {
c19d1205 1531 another_range = 0;
a737bd4d 1532
c19d1205
ZW
1533 if (*str == '{')
1534 {
1535 int in_range = 0;
1536 int cur_reg = -1;
a737bd4d 1537
c19d1205
ZW
1538 str++;
1539 do
1540 {
1541 int reg;
6057a28f 1542
dcbf9037 1543 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1544 {
dcbf9037 1545 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1546 return FAIL;
1547 }
a737bd4d 1548
c19d1205
ZW
1549 if (in_range)
1550 {
1551 int i;
a737bd4d 1552
c19d1205
ZW
1553 if (reg <= cur_reg)
1554 {
dcbf9037 1555 first_error (_("bad range in register list"));
c19d1205
ZW
1556 return FAIL;
1557 }
40a18ebd 1558
c19d1205
ZW
1559 for (i = cur_reg + 1; i < reg; i++)
1560 {
1561 if (range & (1 << i))
1562 as_tsktsk
1563 (_("Warning: duplicated register (r%d) in register list"),
1564 i);
1565 else
1566 range |= 1 << i;
1567 }
1568 in_range = 0;
1569 }
a737bd4d 1570
c19d1205
ZW
1571 if (range & (1 << reg))
1572 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1573 reg);
1574 else if (reg <= cur_reg)
1575 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1576
c19d1205
ZW
1577 range |= 1 << reg;
1578 cur_reg = reg;
1579 }
1580 while (skip_past_comma (&str) != FAIL
1581 || (in_range = 1, *str++ == '-'));
1582 str--;
a737bd4d 1583
c19d1205
ZW
1584 if (*str++ != '}')
1585 {
dcbf9037 1586 first_error (_("missing `}'"));
c19d1205
ZW
1587 return FAIL;
1588 }
1589 }
1590 else
1591 {
91d6fa6a 1592 expressionS exp;
40a18ebd 1593
91d6fa6a 1594 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1595 return FAIL;
40a18ebd 1596
91d6fa6a 1597 if (exp.X_op == O_constant)
c19d1205 1598 {
91d6fa6a
NC
1599 if (exp.X_add_number
1600 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1601 {
1602 inst.error = _("invalid register mask");
1603 return FAIL;
1604 }
a737bd4d 1605
91d6fa6a 1606 if ((range & exp.X_add_number) != 0)
c19d1205 1607 {
91d6fa6a 1608 int regno = range & exp.X_add_number;
a737bd4d 1609
c19d1205
ZW
1610 regno &= -regno;
1611 regno = (1 << regno) - 1;
1612 as_tsktsk
1613 (_("Warning: duplicated register (r%d) in register list"),
1614 regno);
1615 }
a737bd4d 1616
91d6fa6a 1617 range |= exp.X_add_number;
c19d1205
ZW
1618 }
1619 else
1620 {
1621 if (inst.reloc.type != 0)
1622 {
1623 inst.error = _("expression too complex");
1624 return FAIL;
1625 }
a737bd4d 1626
91d6fa6a 1627 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1628 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1629 inst.reloc.pc_rel = 0;
1630 }
1631 }
a737bd4d 1632
c19d1205
ZW
1633 if (*str == '|' || *str == '+')
1634 {
1635 str++;
1636 another_range = 1;
1637 }
a737bd4d 1638 }
c19d1205 1639 while (another_range);
a737bd4d 1640
c19d1205
ZW
1641 *strp = str;
1642 return range;
a737bd4d
NC
1643}
1644
5287ad62
JB
1645/* Types of registers in a list. */
1646
1647enum reg_list_els
1648{
1649 REGLIST_VFP_S,
1650 REGLIST_VFP_D,
1651 REGLIST_NEON_D
1652};
1653
c19d1205
ZW
1654/* Parse a VFP register list. If the string is invalid return FAIL.
1655 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1656 register. Parses registers of type ETYPE.
1657 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1658 - Q registers can be used to specify pairs of D registers
1659 - { } can be omitted from around a singleton register list
1660 FIXME: This is not implemented, as it would require backtracking in
1661 some cases, e.g.:
1662 vtbl.8 d3,d4,d5
1663 This could be done (the meaning isn't really ambiguous), but doesn't
1664 fit in well with the current parsing framework.
dcbf9037
JB
1665 - 32 D registers may be used (also true for VFPv3).
1666 FIXME: Types are ignored in these register lists, which is probably a
1667 bug. */
6057a28f 1668
c19d1205 1669static int
037e8744 1670parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1671{
037e8744 1672 char *str = *ccp;
c19d1205
ZW
1673 int base_reg;
1674 int new_base;
21d799b5 1675 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1676 int max_regs = 0;
c19d1205
ZW
1677 int count = 0;
1678 int warned = 0;
1679 unsigned long mask = 0;
a737bd4d 1680 int i;
6057a28f 1681
037e8744 1682 if (*str != '{')
5287ad62
JB
1683 {
1684 inst.error = _("expecting {");
1685 return FAIL;
1686 }
6057a28f 1687
037e8744 1688 str++;
6057a28f 1689
5287ad62 1690 switch (etype)
c19d1205 1691 {
5287ad62 1692 case REGLIST_VFP_S:
c19d1205
ZW
1693 regtype = REG_TYPE_VFS;
1694 max_regs = 32;
5287ad62 1695 break;
5f4273c7 1696
5287ad62
JB
1697 case REGLIST_VFP_D:
1698 regtype = REG_TYPE_VFD;
b7fc2769 1699 break;
5f4273c7 1700
b7fc2769
JB
1701 case REGLIST_NEON_D:
1702 regtype = REG_TYPE_NDQ;
1703 break;
1704 }
1705
1706 if (etype != REGLIST_VFP_S)
1707 {
b1cc4aeb
PB
1708 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1709 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1710 {
1711 max_regs = 32;
1712 if (thumb_mode)
1713 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1714 fpu_vfp_ext_d32);
5287ad62
JB
1715 else
1716 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1717 fpu_vfp_ext_d32);
5287ad62
JB
1718 }
1719 else
1720 max_regs = 16;
c19d1205 1721 }
6057a28f 1722
c19d1205 1723 base_reg = max_regs;
a737bd4d 1724
c19d1205
ZW
1725 do
1726 {
5287ad62 1727 int setmask = 1, addregs = 1;
dcbf9037 1728
037e8744 1729 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1730
c19d1205 1731 if (new_base == FAIL)
a737bd4d 1732 {
dcbf9037 1733 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1734 return FAIL;
1735 }
5f4273c7 1736
b7fc2769
JB
1737 if (new_base >= max_regs)
1738 {
1739 first_error (_("register out of range in list"));
1740 return FAIL;
1741 }
5f4273c7 1742
5287ad62
JB
1743 /* Note: a value of 2 * n is returned for the register Q<n>. */
1744 if (regtype == REG_TYPE_NQ)
1745 {
1746 setmask = 3;
1747 addregs = 2;
1748 }
1749
c19d1205
ZW
1750 if (new_base < base_reg)
1751 base_reg = new_base;
a737bd4d 1752
5287ad62 1753 if (mask & (setmask << new_base))
c19d1205 1754 {
dcbf9037 1755 first_error (_("invalid register list"));
c19d1205 1756 return FAIL;
a737bd4d 1757 }
a737bd4d 1758
c19d1205
ZW
1759 if ((mask >> new_base) != 0 && ! warned)
1760 {
1761 as_tsktsk (_("register list not in ascending order"));
1762 warned = 1;
1763 }
0bbf2aa4 1764
5287ad62
JB
1765 mask |= setmask << new_base;
1766 count += addregs;
0bbf2aa4 1767
037e8744 1768 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1769 {
1770 int high_range;
0bbf2aa4 1771
037e8744 1772 str++;
0bbf2aa4 1773
037e8744 1774 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1775 == FAIL)
c19d1205
ZW
1776 {
1777 inst.error = gettext (reg_expected_msgs[regtype]);
1778 return FAIL;
1779 }
0bbf2aa4 1780
b7fc2769
JB
1781 if (high_range >= max_regs)
1782 {
1783 first_error (_("register out of range in list"));
1784 return FAIL;
1785 }
1786
5287ad62
JB
1787 if (regtype == REG_TYPE_NQ)
1788 high_range = high_range + 1;
1789
c19d1205
ZW
1790 if (high_range <= new_base)
1791 {
1792 inst.error = _("register range not in ascending order");
1793 return FAIL;
1794 }
0bbf2aa4 1795
5287ad62 1796 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1797 {
5287ad62 1798 if (mask & (setmask << new_base))
0bbf2aa4 1799 {
c19d1205
ZW
1800 inst.error = _("invalid register list");
1801 return FAIL;
0bbf2aa4 1802 }
c19d1205 1803
5287ad62
JB
1804 mask |= setmask << new_base;
1805 count += addregs;
0bbf2aa4 1806 }
0bbf2aa4 1807 }
0bbf2aa4 1808 }
037e8744 1809 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1810
037e8744 1811 str++;
0bbf2aa4 1812
c19d1205
ZW
1813 /* Sanity check -- should have raised a parse error above. */
1814 if (count == 0 || count > max_regs)
1815 abort ();
1816
1817 *pbase = base_reg;
1818
1819 /* Final test -- the registers must be consecutive. */
1820 mask >>= base_reg;
1821 for (i = 0; i < count; i++)
1822 {
1823 if ((mask & (1u << i)) == 0)
1824 {
1825 inst.error = _("non-contiguous register range");
1826 return FAIL;
1827 }
1828 }
1829
037e8744
JB
1830 *ccp = str;
1831
c19d1205 1832 return count;
b99bd4ef
NC
1833}
1834
dcbf9037
JB
1835/* True if two alias types are the same. */
1836
c921be7d 1837static bfd_boolean
dcbf9037
JB
1838neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1839{
1840 if (!a && !b)
c921be7d 1841 return TRUE;
5f4273c7 1842
dcbf9037 1843 if (!a || !b)
c921be7d 1844 return FALSE;
dcbf9037
JB
1845
1846 if (a->defined != b->defined)
c921be7d 1847 return FALSE;
5f4273c7 1848
dcbf9037
JB
1849 if ((a->defined & NTA_HASTYPE) != 0
1850 && (a->eltype.type != b->eltype.type
1851 || a->eltype.size != b->eltype.size))
c921be7d 1852 return FALSE;
dcbf9037
JB
1853
1854 if ((a->defined & NTA_HASINDEX) != 0
1855 && (a->index != b->index))
c921be7d 1856 return FALSE;
5f4273c7 1857
c921be7d 1858 return TRUE;
dcbf9037
JB
1859}
1860
5287ad62
JB
1861/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1862 The base register is put in *PBASE.
dcbf9037 1863 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1864 the return value.
1865 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1866 Bits [6:5] encode the list length (minus one).
1867 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1868
5287ad62 1869#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1870#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1871#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1872
1873static int
dcbf9037
JB
1874parse_neon_el_struct_list (char **str, unsigned *pbase,
1875 struct neon_type_el *eltype)
5287ad62
JB
1876{
1877 char *ptr = *str;
1878 int base_reg = -1;
1879 int reg_incr = -1;
1880 int count = 0;
1881 int lane = -1;
1882 int leading_brace = 0;
1883 enum arm_reg_type rtype = REG_TYPE_NDQ;
1884 int addregs = 1;
20203fb9
NC
1885 const char *const incr_error = _("register stride must be 1 or 2");
1886 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1887 struct neon_typed_alias firsttype;
5f4273c7 1888
5287ad62
JB
1889 if (skip_past_char (&ptr, '{') == SUCCESS)
1890 leading_brace = 1;
5f4273c7 1891
5287ad62
JB
1892 do
1893 {
dcbf9037
JB
1894 struct neon_typed_alias atype;
1895 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1896
5287ad62
JB
1897 if (getreg == FAIL)
1898 {
dcbf9037 1899 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1900 return FAIL;
1901 }
5f4273c7 1902
5287ad62
JB
1903 if (base_reg == -1)
1904 {
1905 base_reg = getreg;
1906 if (rtype == REG_TYPE_NQ)
1907 {
1908 reg_incr = 1;
1909 addregs = 2;
1910 }
dcbf9037 1911 firsttype = atype;
5287ad62
JB
1912 }
1913 else if (reg_incr == -1)
1914 {
1915 reg_incr = getreg - base_reg;
1916 if (reg_incr < 1 || reg_incr > 2)
1917 {
dcbf9037 1918 first_error (_(incr_error));
5287ad62
JB
1919 return FAIL;
1920 }
1921 }
1922 else if (getreg != base_reg + reg_incr * count)
1923 {
dcbf9037
JB
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927
c921be7d 1928 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1929 {
1930 first_error (_(type_error));
5287ad62
JB
1931 return FAIL;
1932 }
5f4273c7 1933
5287ad62
JB
1934 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1935 modes. */
1936 if (ptr[0] == '-')
1937 {
dcbf9037 1938 struct neon_typed_alias htype;
5287ad62
JB
1939 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1940 if (lane == -1)
1941 lane = NEON_INTERLEAVE_LANES;
1942 else if (lane != NEON_INTERLEAVE_LANES)
1943 {
dcbf9037 1944 first_error (_(type_error));
5287ad62
JB
1945 return FAIL;
1946 }
1947 if (reg_incr == -1)
1948 reg_incr = 1;
1949 else if (reg_incr != 1)
1950 {
dcbf9037 1951 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1952 return FAIL;
1953 }
1954 ptr++;
dcbf9037 1955 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1956 if (hireg == FAIL)
1957 {
dcbf9037
JB
1958 first_error (_(reg_expected_msgs[rtype]));
1959 return FAIL;
1960 }
c921be7d 1961 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1962 {
1963 first_error (_(type_error));
5287ad62
JB
1964 return FAIL;
1965 }
1966 count += hireg + dregs - getreg;
1967 continue;
1968 }
5f4273c7 1969
5287ad62
JB
1970 /* If we're using Q registers, we can't use [] or [n] syntax. */
1971 if (rtype == REG_TYPE_NQ)
1972 {
1973 count += 2;
1974 continue;
1975 }
5f4273c7 1976
dcbf9037 1977 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1978 {
dcbf9037
JB
1979 if (lane == -1)
1980 lane = atype.index;
1981 else if (lane != atype.index)
5287ad62 1982 {
dcbf9037
JB
1983 first_error (_(type_error));
1984 return FAIL;
5287ad62
JB
1985 }
1986 }
1987 else if (lane == -1)
1988 lane = NEON_INTERLEAVE_LANES;
1989 else if (lane != NEON_INTERLEAVE_LANES)
1990 {
dcbf9037 1991 first_error (_(type_error));
5287ad62
JB
1992 return FAIL;
1993 }
1994 count++;
1995 }
1996 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1997
5287ad62
JB
1998 /* No lane set by [x]. We must be interleaving structures. */
1999 if (lane == -1)
2000 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2001
5287ad62
JB
2002 /* Sanity check. */
2003 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2004 || (count > 1 && reg_incr == -1))
2005 {
dcbf9037 2006 first_error (_("error parsing element/structure list"));
5287ad62
JB
2007 return FAIL;
2008 }
2009
2010 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2011 {
dcbf9037 2012 first_error (_("expected }"));
5287ad62
JB
2013 return FAIL;
2014 }
5f4273c7 2015
5287ad62
JB
2016 if (reg_incr == -1)
2017 reg_incr = 1;
2018
dcbf9037
JB
2019 if (eltype)
2020 *eltype = firsttype.eltype;
2021
5287ad62
JB
2022 *pbase = base_reg;
2023 *str = ptr;
5f4273c7 2024
5287ad62
JB
2025 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2026}
2027
c19d1205
ZW
2028/* Parse an explicit relocation suffix on an expression. This is
2029 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2030 arm_reloc_hsh contains no entries, so this function can only
2031 succeed if there is no () after the word. Returns -1 on error,
2032 BFD_RELOC_UNUSED if there wasn't any suffix. */
2033static int
2034parse_reloc (char **str)
b99bd4ef 2035{
c19d1205
ZW
2036 struct reloc_entry *r;
2037 char *p, *q;
b99bd4ef 2038
c19d1205
ZW
2039 if (**str != '(')
2040 return BFD_RELOC_UNUSED;
b99bd4ef 2041
c19d1205
ZW
2042 p = *str + 1;
2043 q = p;
2044
2045 while (*q && *q != ')' && *q != ',')
2046 q++;
2047 if (*q != ')')
2048 return -1;
2049
21d799b5
NC
2050 if ((r = (struct reloc_entry *)
2051 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2052 return -1;
2053
2054 *str = q + 1;
2055 return r->reloc;
b99bd4ef
NC
2056}
2057
c19d1205
ZW
2058/* Directives: register aliases. */
2059
dcbf9037 2060static struct reg_entry *
c19d1205 2061insert_reg_alias (char *str, int number, int type)
b99bd4ef 2062{
d3ce72d0 2063 struct reg_entry *new_reg;
c19d1205 2064 const char *name;
b99bd4ef 2065
d3ce72d0 2066 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2067 {
d3ce72d0 2068 if (new_reg->builtin)
c19d1205 2069 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2070
c19d1205
ZW
2071 /* Only warn about a redefinition if it's not defined as the
2072 same register. */
d3ce72d0 2073 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2074 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2075
d929913e 2076 return NULL;
c19d1205 2077 }
b99bd4ef 2078
c19d1205 2079 name = xstrdup (str);
d3ce72d0 2080 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2081
d3ce72d0
NC
2082 new_reg->name = name;
2083 new_reg->number = number;
2084 new_reg->type = type;
2085 new_reg->builtin = FALSE;
2086 new_reg->neon = NULL;
b99bd4ef 2087
d3ce72d0 2088 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2089 abort ();
5f4273c7 2090
d3ce72d0 2091 return new_reg;
dcbf9037
JB
2092}
2093
2094static void
2095insert_neon_reg_alias (char *str, int number, int type,
2096 struct neon_typed_alias *atype)
2097{
2098 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2099
dcbf9037
JB
2100 if (!reg)
2101 {
2102 first_error (_("attempt to redefine typed alias"));
2103 return;
2104 }
5f4273c7 2105
dcbf9037
JB
2106 if (atype)
2107 {
21d799b5
NC
2108 reg->neon = (struct neon_typed_alias *)
2109 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2110 *reg->neon = *atype;
2111 }
c19d1205 2112}
b99bd4ef 2113
c19d1205 2114/* Look for the .req directive. This is of the form:
b99bd4ef 2115
c19d1205 2116 new_register_name .req existing_register_name
b99bd4ef 2117
c19d1205 2118 If we find one, or if it looks sufficiently like one that we want to
d929913e 2119 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2120
d929913e 2121static bfd_boolean
c19d1205
ZW
2122create_register_alias (char * newname, char *p)
2123{
2124 struct reg_entry *old;
2125 char *oldname, *nbuf;
2126 size_t nlen;
b99bd4ef 2127
c19d1205
ZW
2128 /* The input scrubber ensures that whitespace after the mnemonic is
2129 collapsed to single spaces. */
2130 oldname = p;
2131 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2132 return FALSE;
b99bd4ef 2133
c19d1205
ZW
2134 oldname += 6;
2135 if (*oldname == '\0')
d929913e 2136 return FALSE;
b99bd4ef 2137
21d799b5 2138 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2139 if (!old)
b99bd4ef 2140 {
c19d1205 2141 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2142 return TRUE;
b99bd4ef
NC
2143 }
2144
c19d1205
ZW
2145 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2146 the desired alias name, and p points to its end. If not, then
2147 the desired alias name is in the global original_case_string. */
2148#ifdef TC_CASE_SENSITIVE
2149 nlen = p - newname;
2150#else
2151 newname = original_case_string;
2152 nlen = strlen (newname);
2153#endif
b99bd4ef 2154
21d799b5 2155 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2156 memcpy (nbuf, newname, nlen);
2157 nbuf[nlen] = '\0';
b99bd4ef 2158
c19d1205
ZW
2159 /* Create aliases under the new name as stated; an all-lowercase
2160 version of the new name; and an all-uppercase version of the new
2161 name. */
d929913e
NC
2162 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2163 {
2164 for (p = nbuf; *p; p++)
2165 *p = TOUPPER (*p);
c19d1205 2166
d929913e
NC
2167 if (strncmp (nbuf, newname, nlen))
2168 {
2169 /* If this attempt to create an additional alias fails, do not bother
2170 trying to create the all-lower case alias. We will fail and issue
2171 a second, duplicate error message. This situation arises when the
2172 programmer does something like:
2173 foo .req r0
2174 Foo .req r1
2175 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2176 the artificial FOO alias because it has already been created by the
d929913e
NC
2177 first .req. */
2178 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2179 return TRUE;
2180 }
c19d1205 2181
d929913e
NC
2182 for (p = nbuf; *p; p++)
2183 *p = TOLOWER (*p);
c19d1205 2184
d929913e
NC
2185 if (strncmp (nbuf, newname, nlen))
2186 insert_reg_alias (nbuf, old->number, old->type);
2187 }
c19d1205 2188
d929913e 2189 return TRUE;
b99bd4ef
NC
2190}
2191
dcbf9037
JB
2192/* Create a Neon typed/indexed register alias using directives, e.g.:
2193 X .dn d5.s32[1]
2194 Y .qn 6.s16
2195 Z .dn d7
2196 T .dn Z[0]
2197 These typed registers can be used instead of the types specified after the
2198 Neon mnemonic, so long as all operands given have types. Types can also be
2199 specified directly, e.g.:
5f4273c7 2200 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2201
c921be7d 2202static bfd_boolean
dcbf9037
JB
2203create_neon_reg_alias (char *newname, char *p)
2204{
2205 enum arm_reg_type basetype;
2206 struct reg_entry *basereg;
2207 struct reg_entry mybasereg;
2208 struct neon_type ntype;
2209 struct neon_typed_alias typeinfo;
2210 char *namebuf, *nameend;
2211 int namelen;
5f4273c7 2212
dcbf9037
JB
2213 typeinfo.defined = 0;
2214 typeinfo.eltype.type = NT_invtype;
2215 typeinfo.eltype.size = -1;
2216 typeinfo.index = -1;
5f4273c7 2217
dcbf9037 2218 nameend = p;
5f4273c7 2219
dcbf9037
JB
2220 if (strncmp (p, " .dn ", 5) == 0)
2221 basetype = REG_TYPE_VFD;
2222 else if (strncmp (p, " .qn ", 5) == 0)
2223 basetype = REG_TYPE_NQ;
2224 else
c921be7d 2225 return FALSE;
5f4273c7 2226
dcbf9037 2227 p += 5;
5f4273c7 2228
dcbf9037 2229 if (*p == '\0')
c921be7d 2230 return FALSE;
5f4273c7 2231
dcbf9037
JB
2232 basereg = arm_reg_parse_multi (&p);
2233
2234 if (basereg && basereg->type != basetype)
2235 {
2236 as_bad (_("bad type for register"));
c921be7d 2237 return FALSE;
dcbf9037
JB
2238 }
2239
2240 if (basereg == NULL)
2241 {
2242 expressionS exp;
2243 /* Try parsing as an integer. */
2244 my_get_expression (&exp, &p, GE_NO_PREFIX);
2245 if (exp.X_op != O_constant)
2246 {
2247 as_bad (_("expression must be constant"));
c921be7d 2248 return FALSE;
dcbf9037
JB
2249 }
2250 basereg = &mybasereg;
2251 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2252 : exp.X_add_number;
2253 basereg->neon = 0;
2254 }
2255
2256 if (basereg->neon)
2257 typeinfo = *basereg->neon;
2258
2259 if (parse_neon_type (&ntype, &p) == SUCCESS)
2260 {
2261 /* We got a type. */
2262 if (typeinfo.defined & NTA_HASTYPE)
2263 {
2264 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2265 return FALSE;
dcbf9037 2266 }
5f4273c7 2267
dcbf9037
JB
2268 typeinfo.defined |= NTA_HASTYPE;
2269 if (ntype.elems != 1)
2270 {
2271 as_bad (_("you must specify a single type only"));
c921be7d 2272 return FALSE;
dcbf9037
JB
2273 }
2274 typeinfo.eltype = ntype.el[0];
2275 }
5f4273c7 2276
dcbf9037
JB
2277 if (skip_past_char (&p, '[') == SUCCESS)
2278 {
2279 expressionS exp;
2280 /* We got a scalar index. */
5f4273c7 2281
dcbf9037
JB
2282 if (typeinfo.defined & NTA_HASINDEX)
2283 {
2284 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2285 return FALSE;
dcbf9037 2286 }
5f4273c7 2287
dcbf9037 2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2289
dcbf9037
JB
2290 if (exp.X_op != O_constant)
2291 {
2292 as_bad (_("scalar index must be constant"));
c921be7d 2293 return FALSE;
dcbf9037 2294 }
5f4273c7 2295
dcbf9037
JB
2296 typeinfo.defined |= NTA_HASINDEX;
2297 typeinfo.index = exp.X_add_number;
5f4273c7 2298
dcbf9037
JB
2299 if (skip_past_char (&p, ']') == FAIL)
2300 {
2301 as_bad (_("expecting ]"));
c921be7d 2302 return FALSE;
dcbf9037
JB
2303 }
2304 }
2305
2306 namelen = nameend - newname;
21d799b5 2307 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2308 strncpy (namebuf, newname, namelen);
2309 namebuf[namelen] = '\0';
5f4273c7 2310
dcbf9037
JB
2311 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2312 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2313
dcbf9037
JB
2314 /* Insert name in all uppercase. */
2315 for (p = namebuf; *p; p++)
2316 *p = TOUPPER (*p);
5f4273c7 2317
dcbf9037
JB
2318 if (strncmp (namebuf, newname, namelen))
2319 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2320 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2321
dcbf9037
JB
2322 /* Insert name in all lowercase. */
2323 for (p = namebuf; *p; p++)
2324 *p = TOLOWER (*p);
5f4273c7 2325
dcbf9037
JB
2326 if (strncmp (namebuf, newname, namelen))
2327 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2328 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2329
c921be7d 2330 return TRUE;
dcbf9037
JB
2331}
2332
c19d1205
ZW
2333/* Should never be called, as .req goes between the alias and the
2334 register name, not at the beginning of the line. */
c921be7d 2335
b99bd4ef 2336static void
c19d1205 2337s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2338{
c19d1205
ZW
2339 as_bad (_("invalid syntax for .req directive"));
2340}
b99bd4ef 2341
dcbf9037
JB
2342static void
2343s_dn (int a ATTRIBUTE_UNUSED)
2344{
2345 as_bad (_("invalid syntax for .dn directive"));
2346}
2347
2348static void
2349s_qn (int a ATTRIBUTE_UNUSED)
2350{
2351 as_bad (_("invalid syntax for .qn directive"));
2352}
2353
c19d1205
ZW
2354/* The .unreq directive deletes an alias which was previously defined
2355 by .req. For example:
b99bd4ef 2356
c19d1205
ZW
2357 my_alias .req r11
2358 .unreq my_alias */
b99bd4ef
NC
2359
2360static void
c19d1205 2361s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2362{
c19d1205
ZW
2363 char * name;
2364 char saved_char;
b99bd4ef 2365
c19d1205
ZW
2366 name = input_line_pointer;
2367
2368 while (*input_line_pointer != 0
2369 && *input_line_pointer != ' '
2370 && *input_line_pointer != '\n')
2371 ++input_line_pointer;
2372
2373 saved_char = *input_line_pointer;
2374 *input_line_pointer = 0;
2375
2376 if (!*name)
2377 as_bad (_("invalid syntax for .unreq directive"));
2378 else
2379 {
21d799b5
NC
2380 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2381 name);
c19d1205
ZW
2382
2383 if (!reg)
2384 as_bad (_("unknown register alias '%s'"), name);
2385 else if (reg->builtin)
2386 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2387 name);
2388 else
2389 {
d929913e
NC
2390 char * p;
2391 char * nbuf;
2392
db0bc284 2393 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2394 free ((char *) reg->name);
dcbf9037
JB
2395 if (reg->neon)
2396 free (reg->neon);
c19d1205 2397 free (reg);
d929913e
NC
2398
2399 /* Also locate the all upper case and all lower case versions.
2400 Do not complain if we cannot find one or the other as it
2401 was probably deleted above. */
5f4273c7 2402
d929913e
NC
2403 nbuf = strdup (name);
2404 for (p = nbuf; *p; p++)
2405 *p = TOUPPER (*p);
21d799b5 2406 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2407 if (reg)
2408 {
db0bc284 2409 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2410 free ((char *) reg->name);
2411 if (reg->neon)
2412 free (reg->neon);
2413 free (reg);
2414 }
2415
2416 for (p = nbuf; *p; p++)
2417 *p = TOLOWER (*p);
21d799b5 2418 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2419 if (reg)
2420 {
db0bc284 2421 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2422 free ((char *) reg->name);
2423 if (reg->neon)
2424 free (reg->neon);
2425 free (reg);
2426 }
2427
2428 free (nbuf);
c19d1205
ZW
2429 }
2430 }
b99bd4ef 2431
c19d1205 2432 *input_line_pointer = saved_char;
b99bd4ef
NC
2433 demand_empty_rest_of_line ();
2434}
2435
c19d1205
ZW
2436/* Directives: Instruction set selection. */
2437
2438#ifdef OBJ_ELF
2439/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2440 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2441 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2442 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2443
cd000bff
DJ
2444/* Create a new mapping symbol for the transition to STATE. */
2445
2446static void
2447make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2448{
a737bd4d 2449 symbolS * symbolP;
c19d1205
ZW
2450 const char * symname;
2451 int type;
b99bd4ef 2452
c19d1205 2453 switch (state)
b99bd4ef 2454 {
c19d1205
ZW
2455 case MAP_DATA:
2456 symname = "$d";
2457 type = BSF_NO_FLAGS;
2458 break;
2459 case MAP_ARM:
2460 symname = "$a";
2461 type = BSF_NO_FLAGS;
2462 break;
2463 case MAP_THUMB:
2464 symname = "$t";
2465 type = BSF_NO_FLAGS;
2466 break;
c19d1205
ZW
2467 default:
2468 abort ();
2469 }
2470
cd000bff 2471 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2472 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2473
2474 switch (state)
2475 {
2476 case MAP_ARM:
2477 THUMB_SET_FUNC (symbolP, 0);
2478 ARM_SET_THUMB (symbolP, 0);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_THUMB:
2483 THUMB_SET_FUNC (symbolP, 1);
2484 ARM_SET_THUMB (symbolP, 1);
2485 ARM_SET_INTERWORK (symbolP, support_interwork);
2486 break;
2487
2488 case MAP_DATA:
2489 default:
cd000bff
DJ
2490 break;
2491 }
2492
2493 /* Save the mapping symbols for future reference. Also check that
2494 we do not place two mapping symbols at the same offset within a
2495 frag. We'll handle overlap between frags in
2de7820f
JZ
2496 check_mapping_symbols.
2497
2498 If .fill or other data filling directive generates zero sized data,
2499 the mapping symbol for the following code will have the same value
2500 as the one generated for the data filling directive. In this case,
2501 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2502 if (value == 0)
2503 {
2de7820f
JZ
2504 if (frag->tc_frag_data.first_map != NULL)
2505 {
2506 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2507 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2508 }
cd000bff
DJ
2509 frag->tc_frag_data.first_map = symbolP;
2510 }
2511 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2512 {
2513 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2514 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2515 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2516 }
cd000bff
DJ
2517 frag->tc_frag_data.last_map = symbolP;
2518}
2519
2520/* We must sometimes convert a region marked as code to data during
2521 code alignment, if an odd number of bytes have to be padded. The
2522 code mapping symbol is pushed to an aligned address. */
2523
2524static void
2525insert_data_mapping_symbol (enum mstate state,
2526 valueT value, fragS *frag, offsetT bytes)
2527{
2528 /* If there was already a mapping symbol, remove it. */
2529 if (frag->tc_frag_data.last_map != NULL
2530 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2531 {
2532 symbolS *symp = frag->tc_frag_data.last_map;
2533
2534 if (value == 0)
2535 {
2536 know (frag->tc_frag_data.first_map == symp);
2537 frag->tc_frag_data.first_map = NULL;
2538 }
2539 frag->tc_frag_data.last_map = NULL;
2540 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2541 }
cd000bff
DJ
2542
2543 make_mapping_symbol (MAP_DATA, value, frag);
2544 make_mapping_symbol (state, value + bytes, frag);
2545}
2546
2547static void mapping_state_2 (enum mstate state, int max_chars);
2548
2549/* Set the mapping state to STATE. Only call this when about to
2550 emit some STATE bytes to the file. */
2551
2552void
2553mapping_state (enum mstate state)
2554{
940b5ce0
DJ
2555 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2556
cd000bff
DJ
2557#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2558
2559 if (mapstate == state)
2560 /* The mapping symbol has already been emitted.
2561 There is nothing else to do. */
2562 return;
2563 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2564 /* This case will be evaluated later in the next else. */
2565 return;
2566 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2567 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2568 {
2569 /* Only add the symbol if the offset is > 0:
2570 if we're at the first frag, check it's size > 0;
2571 if we're not at the first frag, then for sure
2572 the offset is > 0. */
2573 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2574 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2575
2576 if (add_symbol)
2577 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2578 }
2579
2580 mapping_state_2 (state, 0);
2581#undef TRANSITION
2582}
2583
2584/* Same as mapping_state, but MAX_CHARS bytes have already been
2585 allocated. Put the mapping symbol that far back. */
2586
2587static void
2588mapping_state_2 (enum mstate state, int max_chars)
2589{
940b5ce0
DJ
2590 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2591
2592 if (!SEG_NORMAL (now_seg))
2593 return;
2594
cd000bff
DJ
2595 if (mapstate == state)
2596 /* The mapping symbol has already been emitted.
2597 There is nothing else to do. */
2598 return;
2599
cd000bff
DJ
2600 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2601 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2602}
2603#else
d3106081
NS
2604#define mapping_state(x) ((void)0)
2605#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2606#endif
2607
2608/* Find the real, Thumb encoded start of a Thumb function. */
2609
4343666d 2610#ifdef OBJ_COFF
c19d1205
ZW
2611static symbolS *
2612find_real_start (symbolS * symbolP)
2613{
2614 char * real_start;
2615 const char * name = S_GET_NAME (symbolP);
2616 symbolS * new_target;
2617
2618 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2619#define STUB_NAME ".real_start_of"
2620
2621 if (name == NULL)
2622 abort ();
2623
37f6032b
ZW
2624 /* The compiler may generate BL instructions to local labels because
2625 it needs to perform a branch to a far away location. These labels
2626 do not have a corresponding ".real_start_of" label. We check
2627 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2628 the ".real_start_of" convention for nonlocal branches. */
2629 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2630 return symbolP;
2631
37f6032b 2632 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2633 new_target = symbol_find (real_start);
2634
2635 if (new_target == NULL)
2636 {
bd3ba5d1 2637 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2638 new_target = symbolP;
2639 }
2640
c19d1205
ZW
2641 return new_target;
2642}
4343666d 2643#endif
c19d1205
ZW
2644
2645static void
2646opcode_select (int width)
2647{
2648 switch (width)
2649 {
2650 case 16:
2651 if (! thumb_mode)
2652 {
e74cfd16 2653 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2654 as_bad (_("selected processor does not support THUMB opcodes"));
2655
2656 thumb_mode = 1;
2657 /* No need to force the alignment, since we will have been
2658 coming from ARM mode, which is word-aligned. */
2659 record_alignment (now_seg, 1);
2660 }
c19d1205
ZW
2661 break;
2662
2663 case 32:
2664 if (thumb_mode)
2665 {
e74cfd16 2666 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2667 as_bad (_("selected processor does not support ARM opcodes"));
2668
2669 thumb_mode = 0;
2670
2671 if (!need_pass_2)
2672 frag_align (2, 0, 0);
2673
2674 record_alignment (now_seg, 1);
2675 }
c19d1205
ZW
2676 break;
2677
2678 default:
2679 as_bad (_("invalid instruction size selected (%d)"), width);
2680 }
2681}
2682
2683static void
2684s_arm (int ignore ATTRIBUTE_UNUSED)
2685{
2686 opcode_select (32);
2687 demand_empty_rest_of_line ();
2688}
2689
2690static void
2691s_thumb (int ignore ATTRIBUTE_UNUSED)
2692{
2693 opcode_select (16);
2694 demand_empty_rest_of_line ();
2695}
2696
2697static void
2698s_code (int unused ATTRIBUTE_UNUSED)
2699{
2700 int temp;
2701
2702 temp = get_absolute_expression ();
2703 switch (temp)
2704 {
2705 case 16:
2706 case 32:
2707 opcode_select (temp);
2708 break;
2709
2710 default:
2711 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2712 }
2713}
2714
2715static void
2716s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2717{
2718 /* If we are not already in thumb mode go into it, EVEN if
2719 the target processor does not support thumb instructions.
2720 This is used by gcc/config/arm/lib1funcs.asm for example
2721 to compile interworking support functions even if the
2722 target processor should not support interworking. */
2723 if (! thumb_mode)
2724 {
2725 thumb_mode = 2;
2726 record_alignment (now_seg, 1);
2727 }
2728
2729 demand_empty_rest_of_line ();
2730}
2731
2732static void
2733s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2734{
2735 s_thumb (0);
2736
2737 /* The following label is the name/address of the start of a Thumb function.
2738 We need to know this for the interworking support. */
2739 label_is_thumb_function_name = TRUE;
2740}
2741
2742/* Perform a .set directive, but also mark the alias as
2743 being a thumb function. */
2744
2745static void
2746s_thumb_set (int equiv)
2747{
2748 /* XXX the following is a duplicate of the code for s_set() in read.c
2749 We cannot just call that code as we need to get at the symbol that
2750 is created. */
2751 char * name;
2752 char delim;
2753 char * end_name;
2754 symbolS * symbolP;
2755
2756 /* Especial apologies for the random logic:
2757 This just grew, and could be parsed much more simply!
2758 Dean - in haste. */
2759 name = input_line_pointer;
2760 delim = get_symbol_end ();
2761 end_name = input_line_pointer;
2762 *end_name = delim;
2763
2764 if (*input_line_pointer != ',')
2765 {
2766 *end_name = 0;
2767 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2768 *end_name = delim;
2769 ignore_rest_of_line ();
2770 return;
2771 }
2772
2773 input_line_pointer++;
2774 *end_name = 0;
2775
2776 if (name[0] == '.' && name[1] == '\0')
2777 {
2778 /* XXX - this should not happen to .thumb_set. */
2779 abort ();
2780 }
2781
2782 if ((symbolP = symbol_find (name)) == NULL
2783 && (symbolP = md_undefined_symbol (name)) == NULL)
2784 {
2785#ifndef NO_LISTING
2786 /* When doing symbol listings, play games with dummy fragments living
2787 outside the normal fragment chain to record the file and line info
c19d1205 2788 for this symbol. */
b99bd4ef
NC
2789 if (listing & LISTING_SYMBOLS)
2790 {
2791 extern struct list_info_struct * listing_tail;
21d799b5 2792 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2793
2794 memset (dummy_frag, 0, sizeof (fragS));
2795 dummy_frag->fr_type = rs_fill;
2796 dummy_frag->line = listing_tail;
2797 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2798 dummy_frag->fr_symbol = symbolP;
2799 }
2800 else
2801#endif
2802 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2803
2804#ifdef OBJ_COFF
2805 /* "set" symbols are local unless otherwise specified. */
2806 SF_SET_LOCAL (symbolP);
2807#endif /* OBJ_COFF */
2808 } /* Make a new symbol. */
2809
2810 symbol_table_insert (symbolP);
2811
2812 * end_name = delim;
2813
2814 if (equiv
2815 && S_IS_DEFINED (symbolP)
2816 && S_GET_SEGMENT (symbolP) != reg_section)
2817 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2818
2819 pseudo_set (symbolP);
2820
2821 demand_empty_rest_of_line ();
2822
c19d1205 2823 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2824
2825 THUMB_SET_FUNC (symbolP, 1);
2826 ARM_SET_THUMB (symbolP, 1);
2827#if defined OBJ_ELF || defined OBJ_COFF
2828 ARM_SET_INTERWORK (symbolP, support_interwork);
2829#endif
2830}
2831
c19d1205 2832/* Directives: Mode selection. */
b99bd4ef 2833
c19d1205
ZW
2834/* .syntax [unified|divided] - choose the new unified syntax
2835 (same for Arm and Thumb encoding, modulo slight differences in what
2836 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2837static void
c19d1205 2838s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2839{
c19d1205
ZW
2840 char *name, delim;
2841
2842 name = input_line_pointer;
2843 delim = get_symbol_end ();
2844
2845 if (!strcasecmp (name, "unified"))
2846 unified_syntax = TRUE;
2847 else if (!strcasecmp (name, "divided"))
2848 unified_syntax = FALSE;
2849 else
2850 {
2851 as_bad (_("unrecognized syntax mode \"%s\""), name);
2852 return;
2853 }
2854 *input_line_pointer = delim;
b99bd4ef
NC
2855 demand_empty_rest_of_line ();
2856}
2857
c19d1205
ZW
2858/* Directives: sectioning and alignment. */
2859
2860/* Same as s_align_ptwo but align 0 => align 2. */
2861
b99bd4ef 2862static void
c19d1205 2863s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2864{
a737bd4d 2865 int temp;
dce323d1 2866 bfd_boolean fill_p;
c19d1205
ZW
2867 long temp_fill;
2868 long max_alignment = 15;
b99bd4ef
NC
2869
2870 temp = get_absolute_expression ();
c19d1205
ZW
2871 if (temp > max_alignment)
2872 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2873 else if (temp < 0)
b99bd4ef 2874 {
c19d1205
ZW
2875 as_bad (_("alignment negative. 0 assumed."));
2876 temp = 0;
2877 }
b99bd4ef 2878
c19d1205
ZW
2879 if (*input_line_pointer == ',')
2880 {
2881 input_line_pointer++;
2882 temp_fill = get_absolute_expression ();
dce323d1 2883 fill_p = TRUE;
b99bd4ef 2884 }
c19d1205 2885 else
dce323d1
PB
2886 {
2887 fill_p = FALSE;
2888 temp_fill = 0;
2889 }
b99bd4ef 2890
c19d1205
ZW
2891 if (!temp)
2892 temp = 2;
b99bd4ef 2893
c19d1205
ZW
2894 /* Only make a frag if we HAVE to. */
2895 if (temp && !need_pass_2)
dce323d1
PB
2896 {
2897 if (!fill_p && subseg_text_p (now_seg))
2898 frag_align_code (temp, 0);
2899 else
2900 frag_align (temp, (int) temp_fill, 0);
2901 }
c19d1205
ZW
2902 demand_empty_rest_of_line ();
2903
2904 record_alignment (now_seg, temp);
b99bd4ef
NC
2905}
2906
c19d1205
ZW
2907static void
2908s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2909{
c19d1205
ZW
2910 /* We don't support putting frags in the BSS segment, we fake it by
2911 marking in_bss, then looking at s_skip for clues. */
2912 subseg_set (bss_section, 0);
2913 demand_empty_rest_of_line ();
cd000bff
DJ
2914
2915#ifdef md_elf_section_change_hook
2916 md_elf_section_change_hook ();
2917#endif
c19d1205 2918}
b99bd4ef 2919
c19d1205
ZW
2920static void
2921s_even (int ignore ATTRIBUTE_UNUSED)
2922{
2923 /* Never make frag if expect extra pass. */
2924 if (!need_pass_2)
2925 frag_align (1, 0, 0);
b99bd4ef 2926
c19d1205 2927 record_alignment (now_seg, 1);
b99bd4ef 2928
c19d1205 2929 demand_empty_rest_of_line ();
b99bd4ef
NC
2930}
2931
c19d1205 2932/* Directives: Literal pools. */
a737bd4d 2933
c19d1205
ZW
2934static literal_pool *
2935find_literal_pool (void)
a737bd4d 2936{
c19d1205 2937 literal_pool * pool;
a737bd4d 2938
c19d1205 2939 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2940 {
c19d1205
ZW
2941 if (pool->section == now_seg
2942 && pool->sub_section == now_subseg)
2943 break;
a737bd4d
NC
2944 }
2945
c19d1205 2946 return pool;
a737bd4d
NC
2947}
2948
c19d1205
ZW
2949static literal_pool *
2950find_or_make_literal_pool (void)
a737bd4d 2951{
c19d1205
ZW
2952 /* Next literal pool ID number. */
2953 static unsigned int latest_pool_num = 1;
2954 literal_pool * pool;
a737bd4d 2955
c19d1205 2956 pool = find_literal_pool ();
a737bd4d 2957
c19d1205 2958 if (pool == NULL)
a737bd4d 2959 {
c19d1205 2960 /* Create a new pool. */
21d799b5 2961 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2962 if (! pool)
2963 return NULL;
a737bd4d 2964
c19d1205
ZW
2965 pool->next_free_entry = 0;
2966 pool->section = now_seg;
2967 pool->sub_section = now_subseg;
2968 pool->next = list_of_pools;
2969 pool->symbol = NULL;
2970
2971 /* Add it to the list. */
2972 list_of_pools = pool;
a737bd4d 2973 }
a737bd4d 2974
c19d1205
ZW
2975 /* New pools, and emptied pools, will have a NULL symbol. */
2976 if (pool->symbol == NULL)
a737bd4d 2977 {
c19d1205
ZW
2978 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2979 (valueT) 0, &zero_address_frag);
2980 pool->id = latest_pool_num ++;
a737bd4d
NC
2981 }
2982
c19d1205
ZW
2983 /* Done. */
2984 return pool;
a737bd4d
NC
2985}
2986
c19d1205 2987/* Add the literal in the global 'inst'
5f4273c7 2988 structure to the relevant literal pool. */
b99bd4ef
NC
2989
2990static int
c19d1205 2991add_to_lit_pool (void)
b99bd4ef 2992{
c19d1205
ZW
2993 literal_pool * pool;
2994 unsigned int entry;
b99bd4ef 2995
c19d1205
ZW
2996 pool = find_or_make_literal_pool ();
2997
2998 /* Check if this literal value is already in the pool. */
2999 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3000 {
c19d1205
ZW
3001 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3002 && (inst.reloc.exp.X_op == O_constant)
3003 && (pool->literals[entry].X_add_number
3004 == inst.reloc.exp.X_add_number)
3005 && (pool->literals[entry].X_unsigned
3006 == inst.reloc.exp.X_unsigned))
3007 break;
3008
3009 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3010 && (inst.reloc.exp.X_op == O_symbol)
3011 && (pool->literals[entry].X_add_number
3012 == inst.reloc.exp.X_add_number)
3013 && (pool->literals[entry].X_add_symbol
3014 == inst.reloc.exp.X_add_symbol)
3015 && (pool->literals[entry].X_op_symbol
3016 == inst.reloc.exp.X_op_symbol))
3017 break;
b99bd4ef
NC
3018 }
3019
c19d1205
ZW
3020 /* Do we need to create a new entry? */
3021 if (entry == pool->next_free_entry)
3022 {
3023 if (entry >= MAX_LITERAL_POOL_SIZE)
3024 {
3025 inst.error = _("literal pool overflow");
3026 return FAIL;
3027 }
3028
3029 pool->literals[entry] = inst.reloc.exp;
3030 pool->next_free_entry += 1;
3031 }
b99bd4ef 3032
c19d1205
ZW
3033 inst.reloc.exp.X_op = O_symbol;
3034 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3035 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3036
c19d1205 3037 return SUCCESS;
b99bd4ef
NC
3038}
3039
c19d1205
ZW
3040/* Can't use symbol_new here, so have to create a symbol and then at
3041 a later date assign it a value. Thats what these functions do. */
e16bb312 3042
c19d1205
ZW
3043static void
3044symbol_locate (symbolS * symbolP,
3045 const char * name, /* It is copied, the caller can modify. */
3046 segT segment, /* Segment identifier (SEG_<something>). */
3047 valueT valu, /* Symbol value. */
3048 fragS * frag) /* Associated fragment. */
3049{
3050 unsigned int name_length;
3051 char * preserved_copy_of_name;
e16bb312 3052
c19d1205
ZW
3053 name_length = strlen (name) + 1; /* +1 for \0. */
3054 obstack_grow (&notes, name, name_length);
21d799b5 3055 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3056
c19d1205
ZW
3057#ifdef tc_canonicalize_symbol_name
3058 preserved_copy_of_name =
3059 tc_canonicalize_symbol_name (preserved_copy_of_name);
3060#endif
b99bd4ef 3061
c19d1205 3062 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3063
c19d1205
ZW
3064 S_SET_SEGMENT (symbolP, segment);
3065 S_SET_VALUE (symbolP, valu);
3066 symbol_clear_list_pointers (symbolP);
b99bd4ef 3067
c19d1205 3068 symbol_set_frag (symbolP, frag);
b99bd4ef 3069
c19d1205
ZW
3070 /* Link to end of symbol chain. */
3071 {
3072 extern int symbol_table_frozen;
b99bd4ef 3073
c19d1205
ZW
3074 if (symbol_table_frozen)
3075 abort ();
3076 }
b99bd4ef 3077
c19d1205 3078 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3079
c19d1205 3080 obj_symbol_new_hook (symbolP);
b99bd4ef 3081
c19d1205
ZW
3082#ifdef tc_symbol_new_hook
3083 tc_symbol_new_hook (symbolP);
3084#endif
3085
3086#ifdef DEBUG_SYMS
3087 verify_symbol_chain (symbol_rootP, symbol_lastP);
3088#endif /* DEBUG_SYMS */
b99bd4ef
NC
3089}
3090
b99bd4ef 3091
c19d1205
ZW
3092static void
3093s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3094{
c19d1205
ZW
3095 unsigned int entry;
3096 literal_pool * pool;
3097 char sym_name[20];
b99bd4ef 3098
c19d1205
ZW
3099 pool = find_literal_pool ();
3100 if (pool == NULL
3101 || pool->symbol == NULL
3102 || pool->next_free_entry == 0)
3103 return;
b99bd4ef 3104
c19d1205 3105 mapping_state (MAP_DATA);
b99bd4ef 3106
c19d1205
ZW
3107 /* Align pool as you have word accesses.
3108 Only make a frag if we have to. */
3109 if (!need_pass_2)
3110 frag_align (2, 0, 0);
b99bd4ef 3111
c19d1205 3112 record_alignment (now_seg, 2);
b99bd4ef 3113
c19d1205 3114 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3115
c19d1205
ZW
3116 symbol_locate (pool->symbol, sym_name, now_seg,
3117 (valueT) frag_now_fix (), frag_now);
3118 symbol_table_insert (pool->symbol);
b99bd4ef 3119
c19d1205 3120 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3121
c19d1205
ZW
3122#if defined OBJ_COFF || defined OBJ_ELF
3123 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3124#endif
6c43fab6 3125
c19d1205
ZW
3126 for (entry = 0; entry < pool->next_free_entry; entry ++)
3127 /* First output the expression in the instruction to the pool. */
3128 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3129
c19d1205
ZW
3130 /* Mark the pool as empty. */
3131 pool->next_free_entry = 0;
3132 pool->symbol = NULL;
b99bd4ef
NC
3133}
3134
c19d1205
ZW
3135#ifdef OBJ_ELF
3136/* Forward declarations for functions below, in the MD interface
3137 section. */
3138static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3139static valueT create_unwind_entry (int);
3140static void start_unwind_section (const segT, int);
3141static void add_unwind_opcode (valueT, int);
3142static void flush_pending_unwind (void);
b99bd4ef 3143
c19d1205 3144/* Directives: Data. */
b99bd4ef 3145
c19d1205
ZW
3146static void
3147s_arm_elf_cons (int nbytes)
3148{
3149 expressionS exp;
b99bd4ef 3150
c19d1205
ZW
3151#ifdef md_flush_pending_output
3152 md_flush_pending_output ();
3153#endif
b99bd4ef 3154
c19d1205 3155 if (is_it_end_of_statement ())
b99bd4ef 3156 {
c19d1205
ZW
3157 demand_empty_rest_of_line ();
3158 return;
b99bd4ef
NC
3159 }
3160
c19d1205
ZW
3161#ifdef md_cons_align
3162 md_cons_align (nbytes);
3163#endif
b99bd4ef 3164
c19d1205
ZW
3165 mapping_state (MAP_DATA);
3166 do
b99bd4ef 3167 {
c19d1205
ZW
3168 int reloc;
3169 char *base = input_line_pointer;
b99bd4ef 3170
c19d1205 3171 expression (& exp);
b99bd4ef 3172
c19d1205
ZW
3173 if (exp.X_op != O_symbol)
3174 emit_expr (&exp, (unsigned int) nbytes);
3175 else
3176 {
3177 char *before_reloc = input_line_pointer;
3178 reloc = parse_reloc (&input_line_pointer);
3179 if (reloc == -1)
3180 {
3181 as_bad (_("unrecognized relocation suffix"));
3182 ignore_rest_of_line ();
3183 return;
3184 }
3185 else if (reloc == BFD_RELOC_UNUSED)
3186 emit_expr (&exp, (unsigned int) nbytes);
3187 else
3188 {
21d799b5
NC
3189 reloc_howto_type *howto = (reloc_howto_type *)
3190 bfd_reloc_type_lookup (stdoutput,
3191 (bfd_reloc_code_real_type) reloc);
c19d1205 3192 int size = bfd_get_reloc_size (howto);
b99bd4ef 3193
2fc8bdac
ZW
3194 if (reloc == BFD_RELOC_ARM_PLT32)
3195 {
3196 as_bad (_("(plt) is only valid on branch targets"));
3197 reloc = BFD_RELOC_UNUSED;
3198 size = 0;
3199 }
3200
c19d1205 3201 if (size > nbytes)
2fc8bdac 3202 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3203 howto->name, nbytes);
3204 else
3205 {
3206 /* We've parsed an expression stopping at O_symbol.
3207 But there may be more expression left now that we
3208 have parsed the relocation marker. Parse it again.
3209 XXX Surely there is a cleaner way to do this. */
3210 char *p = input_line_pointer;
3211 int offset;
21d799b5 3212 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3213 memcpy (save_buf, base, input_line_pointer - base);
3214 memmove (base + (input_line_pointer - before_reloc),
3215 base, before_reloc - base);
3216
3217 input_line_pointer = base + (input_line_pointer-before_reloc);
3218 expression (&exp);
3219 memcpy (base, save_buf, p - base);
3220
3221 offset = nbytes - size;
3222 p = frag_more ((int) nbytes);
3223 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3224 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3225 }
3226 }
3227 }
b99bd4ef 3228 }
c19d1205 3229 while (*input_line_pointer++ == ',');
b99bd4ef 3230
c19d1205
ZW
3231 /* Put terminator back into stream. */
3232 input_line_pointer --;
3233 demand_empty_rest_of_line ();
b99bd4ef
NC
3234}
3235
c921be7d
NC
3236/* Emit an expression containing a 32-bit thumb instruction.
3237 Implementation based on put_thumb32_insn. */
3238
3239static void
3240emit_thumb32_expr (expressionS * exp)
3241{
3242 expressionS exp_high = *exp;
3243
3244 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3245 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3246 exp->X_add_number &= 0xffff;
3247 emit_expr (exp, (unsigned int) THUMB_SIZE);
3248}
3249
3250/* Guess the instruction size based on the opcode. */
3251
3252static int
3253thumb_insn_size (int opcode)
3254{
3255 if ((unsigned int) opcode < 0xe800u)
3256 return 2;
3257 else if ((unsigned int) opcode >= 0xe8000000u)
3258 return 4;
3259 else
3260 return 0;
3261}
3262
3263static bfd_boolean
3264emit_insn (expressionS *exp, int nbytes)
3265{
3266 int size = 0;
3267
3268 if (exp->X_op == O_constant)
3269 {
3270 size = nbytes;
3271
3272 if (size == 0)
3273 size = thumb_insn_size (exp->X_add_number);
3274
3275 if (size != 0)
3276 {
3277 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3278 {
3279 as_bad (_(".inst.n operand too big. "\
3280 "Use .inst.w instead"));
3281 size = 0;
3282 }
3283 else
3284 {
3285 if (now_it.state == AUTOMATIC_IT_BLOCK)
3286 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3287 else
3288 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3289
3290 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3291 emit_thumb32_expr (exp);
3292 else
3293 emit_expr (exp, (unsigned int) size);
3294
3295 it_fsm_post_encode ();
3296 }
3297 }
3298 else
3299 as_bad (_("cannot determine Thumb instruction size. " \
3300 "Use .inst.n/.inst.w instead"));
3301 }
3302 else
3303 as_bad (_("constant expression required"));
3304
3305 return (size != 0);
3306}
3307
3308/* Like s_arm_elf_cons but do not use md_cons_align and
3309 set the mapping state to MAP_ARM/MAP_THUMB. */
3310
3311static void
3312s_arm_elf_inst (int nbytes)
3313{
3314 if (is_it_end_of_statement ())
3315 {
3316 demand_empty_rest_of_line ();
3317 return;
3318 }
3319
3320 /* Calling mapping_state () here will not change ARM/THUMB,
3321 but will ensure not to be in DATA state. */
3322
3323 if (thumb_mode)
3324 mapping_state (MAP_THUMB);
3325 else
3326 {
3327 if (nbytes != 0)
3328 {
3329 as_bad (_("width suffixes are invalid in ARM mode"));
3330 ignore_rest_of_line ();
3331 return;
3332 }
3333
3334 nbytes = 4;
3335
3336 mapping_state (MAP_ARM);
3337 }
3338
3339 do
3340 {
3341 expressionS exp;
3342
3343 expression (& exp);
3344
3345 if (! emit_insn (& exp, nbytes))
3346 {
3347 ignore_rest_of_line ();
3348 return;
3349 }
3350 }
3351 while (*input_line_pointer++ == ',');
3352
3353 /* Put terminator back into stream. */
3354 input_line_pointer --;
3355 demand_empty_rest_of_line ();
3356}
b99bd4ef 3357
c19d1205 3358/* Parse a .rel31 directive. */
b99bd4ef 3359
c19d1205
ZW
3360static void
3361s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3362{
3363 expressionS exp;
3364 char *p;
3365 valueT highbit;
b99bd4ef 3366
c19d1205
ZW
3367 highbit = 0;
3368 if (*input_line_pointer == '1')
3369 highbit = 0x80000000;
3370 else if (*input_line_pointer != '0')
3371 as_bad (_("expected 0 or 1"));
b99bd4ef 3372
c19d1205
ZW
3373 input_line_pointer++;
3374 if (*input_line_pointer != ',')
3375 as_bad (_("missing comma"));
3376 input_line_pointer++;
b99bd4ef 3377
c19d1205
ZW
3378#ifdef md_flush_pending_output
3379 md_flush_pending_output ();
3380#endif
b99bd4ef 3381
c19d1205
ZW
3382#ifdef md_cons_align
3383 md_cons_align (4);
3384#endif
b99bd4ef 3385
c19d1205 3386 mapping_state (MAP_DATA);
b99bd4ef 3387
c19d1205 3388 expression (&exp);
b99bd4ef 3389
c19d1205
ZW
3390 p = frag_more (4);
3391 md_number_to_chars (p, highbit, 4);
3392 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3393 BFD_RELOC_ARM_PREL31);
b99bd4ef 3394
c19d1205 3395 demand_empty_rest_of_line ();
b99bd4ef
NC
3396}
3397
c19d1205 3398/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3399
c19d1205 3400/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3401
c19d1205
ZW
3402static void
3403s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3404{
3405 demand_empty_rest_of_line ();
921e5f0a
PB
3406 if (unwind.proc_start)
3407 {
c921be7d 3408 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3409 return;
3410 }
3411
c19d1205
ZW
3412 /* Mark the start of the function. */
3413 unwind.proc_start = expr_build_dot ();
b99bd4ef 3414
c19d1205
ZW
3415 /* Reset the rest of the unwind info. */
3416 unwind.opcode_count = 0;
3417 unwind.table_entry = NULL;
3418 unwind.personality_routine = NULL;
3419 unwind.personality_index = -1;
3420 unwind.frame_size = 0;
3421 unwind.fp_offset = 0;
fdfde340 3422 unwind.fp_reg = REG_SP;
c19d1205
ZW
3423 unwind.fp_used = 0;
3424 unwind.sp_restored = 0;
3425}
b99bd4ef 3426
b99bd4ef 3427
c19d1205
ZW
3428/* Parse a handlerdata directive. Creates the exception handling table entry
3429 for the function. */
b99bd4ef 3430
c19d1205
ZW
3431static void
3432s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3433{
3434 demand_empty_rest_of_line ();
921e5f0a 3435 if (!unwind.proc_start)
c921be7d 3436 as_bad (MISSING_FNSTART);
921e5f0a 3437
c19d1205 3438 if (unwind.table_entry)
6decc662 3439 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3440
c19d1205
ZW
3441 create_unwind_entry (1);
3442}
a737bd4d 3443
c19d1205 3444/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3445
c19d1205
ZW
3446static void
3447s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3448{
3449 long where;
3450 char *ptr;
3451 valueT val;
940b5ce0 3452 unsigned int marked_pr_dependency;
f02232aa 3453
c19d1205 3454 demand_empty_rest_of_line ();
f02232aa 3455
921e5f0a
PB
3456 if (!unwind.proc_start)
3457 {
c921be7d 3458 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3459 return;
3460 }
3461
c19d1205
ZW
3462 /* Add eh table entry. */
3463 if (unwind.table_entry == NULL)
3464 val = create_unwind_entry (0);
3465 else
3466 val = 0;
f02232aa 3467
c19d1205
ZW
3468 /* Add index table entry. This is two words. */
3469 start_unwind_section (unwind.saved_seg, 1);
3470 frag_align (2, 0, 0);
3471 record_alignment (now_seg, 2);
b99bd4ef 3472
c19d1205
ZW
3473 ptr = frag_more (8);
3474 where = frag_now_fix () - 8;
f02232aa 3475
c19d1205
ZW
3476 /* Self relative offset of the function start. */
3477 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3478 BFD_RELOC_ARM_PREL31);
f02232aa 3479
c19d1205
ZW
3480 /* Indicate dependency on EHABI-defined personality routines to the
3481 linker, if it hasn't been done already. */
940b5ce0
DJ
3482 marked_pr_dependency
3483 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3484 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3485 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3486 {
5f4273c7
NC
3487 static const char *const name[] =
3488 {
3489 "__aeabi_unwind_cpp_pr0",
3490 "__aeabi_unwind_cpp_pr1",
3491 "__aeabi_unwind_cpp_pr2"
3492 };
c19d1205
ZW
3493 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3494 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3495 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3496 |= 1 << unwind.personality_index;
c19d1205 3497 }
f02232aa 3498
c19d1205
ZW
3499 if (val)
3500 /* Inline exception table entry. */
3501 md_number_to_chars (ptr + 4, val, 4);
3502 else
3503 /* Self relative offset of the table entry. */
3504 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3505 BFD_RELOC_ARM_PREL31);
f02232aa 3506
c19d1205
ZW
3507 /* Restore the original section. */
3508 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3509
3510 unwind.proc_start = NULL;
c19d1205 3511}
f02232aa 3512
f02232aa 3513
c19d1205 3514/* Parse an unwind_cantunwind directive. */
b99bd4ef 3515
c19d1205
ZW
3516static void
3517s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3518{
3519 demand_empty_rest_of_line ();
921e5f0a 3520 if (!unwind.proc_start)
c921be7d 3521 as_bad (MISSING_FNSTART);
921e5f0a 3522
c19d1205
ZW
3523 if (unwind.personality_routine || unwind.personality_index != -1)
3524 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3525
c19d1205
ZW
3526 unwind.personality_index = -2;
3527}
b99bd4ef 3528
b99bd4ef 3529
c19d1205 3530/* Parse a personalityindex directive. */
b99bd4ef 3531
c19d1205
ZW
3532static void
3533s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3534{
3535 expressionS exp;
b99bd4ef 3536
921e5f0a 3537 if (!unwind.proc_start)
c921be7d 3538 as_bad (MISSING_FNSTART);
921e5f0a 3539
c19d1205
ZW
3540 if (unwind.personality_routine || unwind.personality_index != -1)
3541 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3542
c19d1205 3543 expression (&exp);
b99bd4ef 3544
c19d1205
ZW
3545 if (exp.X_op != O_constant
3546 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3547 {
c19d1205
ZW
3548 as_bad (_("bad personality routine number"));
3549 ignore_rest_of_line ();
3550 return;
b99bd4ef
NC
3551 }
3552
c19d1205 3553 unwind.personality_index = exp.X_add_number;
b99bd4ef 3554
c19d1205
ZW
3555 demand_empty_rest_of_line ();
3556}
e16bb312 3557
e16bb312 3558
c19d1205 3559/* Parse a personality directive. */
e16bb312 3560
c19d1205
ZW
3561static void
3562s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3563{
3564 char *name, *p, c;
a737bd4d 3565
921e5f0a 3566 if (!unwind.proc_start)
c921be7d 3567 as_bad (MISSING_FNSTART);
921e5f0a 3568
c19d1205
ZW
3569 if (unwind.personality_routine || unwind.personality_index != -1)
3570 as_bad (_("duplicate .personality directive"));
a737bd4d 3571
c19d1205
ZW
3572 name = input_line_pointer;
3573 c = get_symbol_end ();
3574 p = input_line_pointer;
3575 unwind.personality_routine = symbol_find_or_make (name);
3576 *p = c;
3577 demand_empty_rest_of_line ();
3578}
e16bb312 3579
e16bb312 3580
c19d1205 3581/* Parse a directive saving core registers. */
e16bb312 3582
c19d1205
ZW
3583static void
3584s_arm_unwind_save_core (void)
e16bb312 3585{
c19d1205
ZW
3586 valueT op;
3587 long range;
3588 int n;
e16bb312 3589
c19d1205
ZW
3590 range = parse_reg_list (&input_line_pointer);
3591 if (range == FAIL)
e16bb312 3592 {
c19d1205
ZW
3593 as_bad (_("expected register list"));
3594 ignore_rest_of_line ();
3595 return;
3596 }
e16bb312 3597
c19d1205 3598 demand_empty_rest_of_line ();
e16bb312 3599
c19d1205
ZW
3600 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3601 into .unwind_save {..., sp...}. We aren't bothered about the value of
3602 ip because it is clobbered by calls. */
3603 if (unwind.sp_restored && unwind.fp_reg == 12
3604 && (range & 0x3000) == 0x1000)
3605 {
3606 unwind.opcode_count--;
3607 unwind.sp_restored = 0;
3608 range = (range | 0x2000) & ~0x1000;
3609 unwind.pending_offset = 0;
3610 }
e16bb312 3611
01ae4198
DJ
3612 /* Pop r4-r15. */
3613 if (range & 0xfff0)
c19d1205 3614 {
01ae4198
DJ
3615 /* See if we can use the short opcodes. These pop a block of up to 8
3616 registers starting with r4, plus maybe r14. */
3617 for (n = 0; n < 8; n++)
3618 {
3619 /* Break at the first non-saved register. */
3620 if ((range & (1 << (n + 4))) == 0)
3621 break;
3622 }
3623 /* See if there are any other bits set. */
3624 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3625 {
3626 /* Use the long form. */
3627 op = 0x8000 | ((range >> 4) & 0xfff);
3628 add_unwind_opcode (op, 2);
3629 }
0dd132b6 3630 else
01ae4198
DJ
3631 {
3632 /* Use the short form. */
3633 if (range & 0x4000)
3634 op = 0xa8; /* Pop r14. */
3635 else
3636 op = 0xa0; /* Do not pop r14. */
3637 op |= (n - 1);
3638 add_unwind_opcode (op, 1);
3639 }
c19d1205 3640 }
0dd132b6 3641
c19d1205
ZW
3642 /* Pop r0-r3. */
3643 if (range & 0xf)
3644 {
3645 op = 0xb100 | (range & 0xf);
3646 add_unwind_opcode (op, 2);
0dd132b6
NC
3647 }
3648
c19d1205
ZW
3649 /* Record the number of bytes pushed. */
3650 for (n = 0; n < 16; n++)
3651 {
3652 if (range & (1 << n))
3653 unwind.frame_size += 4;
3654 }
0dd132b6
NC
3655}
3656
c19d1205
ZW
3657
3658/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3659
3660static void
c19d1205 3661s_arm_unwind_save_fpa (int reg)
b99bd4ef 3662{
c19d1205
ZW
3663 expressionS exp;
3664 int num_regs;
3665 valueT op;
b99bd4ef 3666
c19d1205
ZW
3667 /* Get Number of registers to transfer. */
3668 if (skip_past_comma (&input_line_pointer) != FAIL)
3669 expression (&exp);
3670 else
3671 exp.X_op = O_illegal;
b99bd4ef 3672
c19d1205 3673 if (exp.X_op != O_constant)
b99bd4ef 3674 {
c19d1205
ZW
3675 as_bad (_("expected , <constant>"));
3676 ignore_rest_of_line ();
b99bd4ef
NC
3677 return;
3678 }
3679
c19d1205
ZW
3680 num_regs = exp.X_add_number;
3681
3682 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3683 {
c19d1205
ZW
3684 as_bad (_("number of registers must be in the range [1:4]"));
3685 ignore_rest_of_line ();
b99bd4ef
NC
3686 return;
3687 }
3688
c19d1205 3689 demand_empty_rest_of_line ();
b99bd4ef 3690
c19d1205
ZW
3691 if (reg == 4)
3692 {
3693 /* Short form. */
3694 op = 0xb4 | (num_regs - 1);
3695 add_unwind_opcode (op, 1);
3696 }
b99bd4ef
NC
3697 else
3698 {
c19d1205
ZW
3699 /* Long form. */
3700 op = 0xc800 | (reg << 4) | (num_regs - 1);
3701 add_unwind_opcode (op, 2);
b99bd4ef 3702 }
c19d1205 3703 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3704}
3705
c19d1205 3706
fa073d69
MS
3707/* Parse a directive saving VFP registers for ARMv6 and above. */
3708
3709static void
3710s_arm_unwind_save_vfp_armv6 (void)
3711{
3712 int count;
3713 unsigned int start;
3714 valueT op;
3715 int num_vfpv3_regs = 0;
3716 int num_regs_below_16;
3717
3718 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3719 if (count == FAIL)
3720 {
3721 as_bad (_("expected register list"));
3722 ignore_rest_of_line ();
3723 return;
3724 }
3725
3726 demand_empty_rest_of_line ();
3727
3728 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3729 than FSTMX/FLDMX-style ones). */
3730
3731 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3732 if (start >= 16)
3733 num_vfpv3_regs = count;
3734 else if (start + count > 16)
3735 num_vfpv3_regs = start + count - 16;
3736
3737 if (num_vfpv3_regs > 0)
3738 {
3739 int start_offset = start > 16 ? start - 16 : 0;
3740 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3741 add_unwind_opcode (op, 2);
3742 }
3743
3744 /* Generate opcode for registers numbered in the range 0 .. 15. */
3745 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3746 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3747 if (num_regs_below_16 > 0)
3748 {
3749 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3750 add_unwind_opcode (op, 2);
3751 }
3752
3753 unwind.frame_size += count * 8;
3754}
3755
3756
3757/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3758
3759static void
c19d1205 3760s_arm_unwind_save_vfp (void)
b99bd4ef 3761{
c19d1205 3762 int count;
ca3f61f7 3763 unsigned int reg;
c19d1205 3764 valueT op;
b99bd4ef 3765
5287ad62 3766 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3767 if (count == FAIL)
b99bd4ef 3768 {
c19d1205
ZW
3769 as_bad (_("expected register list"));
3770 ignore_rest_of_line ();
b99bd4ef
NC
3771 return;
3772 }
3773
c19d1205 3774 demand_empty_rest_of_line ();
b99bd4ef 3775
c19d1205 3776 if (reg == 8)
b99bd4ef 3777 {
c19d1205
ZW
3778 /* Short form. */
3779 op = 0xb8 | (count - 1);
3780 add_unwind_opcode (op, 1);
b99bd4ef 3781 }
c19d1205 3782 else
b99bd4ef 3783 {
c19d1205
ZW
3784 /* Long form. */
3785 op = 0xb300 | (reg << 4) | (count - 1);
3786 add_unwind_opcode (op, 2);
b99bd4ef 3787 }
c19d1205
ZW
3788 unwind.frame_size += count * 8 + 4;
3789}
b99bd4ef 3790
b99bd4ef 3791
c19d1205
ZW
3792/* Parse a directive saving iWMMXt data registers. */
3793
3794static void
3795s_arm_unwind_save_mmxwr (void)
3796{
3797 int reg;
3798 int hi_reg;
3799 int i;
3800 unsigned mask = 0;
3801 valueT op;
b99bd4ef 3802
c19d1205
ZW
3803 if (*input_line_pointer == '{')
3804 input_line_pointer++;
b99bd4ef 3805
c19d1205 3806 do
b99bd4ef 3807 {
dcbf9037 3808 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3809
c19d1205 3810 if (reg == FAIL)
b99bd4ef 3811 {
9b7132d3 3812 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3813 goto error;
b99bd4ef
NC
3814 }
3815
c19d1205
ZW
3816 if (mask >> reg)
3817 as_tsktsk (_("register list not in ascending order"));
3818 mask |= 1 << reg;
b99bd4ef 3819
c19d1205
ZW
3820 if (*input_line_pointer == '-')
3821 {
3822 input_line_pointer++;
dcbf9037 3823 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3824 if (hi_reg == FAIL)
3825 {
9b7132d3 3826 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3827 goto error;
3828 }
3829 else if (reg >= hi_reg)
3830 {
3831 as_bad (_("bad register range"));
3832 goto error;
3833 }
3834 for (; reg < hi_reg; reg++)
3835 mask |= 1 << reg;
3836 }
3837 }
3838 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3839
c19d1205
ZW
3840 if (*input_line_pointer == '}')
3841 input_line_pointer++;
b99bd4ef 3842
c19d1205 3843 demand_empty_rest_of_line ();
b99bd4ef 3844
708587a4 3845 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3846 the list. */
3847 flush_pending_unwind ();
b99bd4ef 3848
c19d1205 3849 for (i = 0; i < 16; i++)
b99bd4ef 3850 {
c19d1205
ZW
3851 if (mask & (1 << i))
3852 unwind.frame_size += 8;
b99bd4ef
NC
3853 }
3854
c19d1205
ZW
3855 /* Attempt to combine with a previous opcode. We do this because gcc
3856 likes to output separate unwind directives for a single block of
3857 registers. */
3858 if (unwind.opcode_count > 0)
b99bd4ef 3859 {
c19d1205
ZW
3860 i = unwind.opcodes[unwind.opcode_count - 1];
3861 if ((i & 0xf8) == 0xc0)
3862 {
3863 i &= 7;
3864 /* Only merge if the blocks are contiguous. */
3865 if (i < 6)
3866 {
3867 if ((mask & 0xfe00) == (1 << 9))
3868 {
3869 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3870 unwind.opcode_count--;
3871 }
3872 }
3873 else if (i == 6 && unwind.opcode_count >= 2)
3874 {
3875 i = unwind.opcodes[unwind.opcode_count - 2];
3876 reg = i >> 4;
3877 i &= 0xf;
b99bd4ef 3878
c19d1205
ZW
3879 op = 0xffff << (reg - 1);
3880 if (reg > 0
87a1fd79 3881 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3882 {
3883 op = (1 << (reg + i + 1)) - 1;
3884 op &= ~((1 << reg) - 1);
3885 mask |= op;
3886 unwind.opcode_count -= 2;
3887 }
3888 }
3889 }
b99bd4ef
NC
3890 }
3891
c19d1205
ZW
3892 hi_reg = 15;
3893 /* We want to generate opcodes in the order the registers have been
3894 saved, ie. descending order. */
3895 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3896 {
c19d1205
ZW
3897 /* Save registers in blocks. */
3898 if (reg < 0
3899 || !(mask & (1 << reg)))
3900 {
3901 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3902 preceding block. */
c19d1205
ZW
3903 if (reg != hi_reg)
3904 {
3905 if (reg == 9)
3906 {
3907 /* Short form. */
3908 op = 0xc0 | (hi_reg - 10);
3909 add_unwind_opcode (op, 1);
3910 }
3911 else
3912 {
3913 /* Long form. */
3914 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3915 add_unwind_opcode (op, 2);
3916 }
3917 }
3918 hi_reg = reg - 1;
3919 }
b99bd4ef
NC
3920 }
3921
c19d1205
ZW
3922 return;
3923error:
3924 ignore_rest_of_line ();
b99bd4ef
NC
3925}
3926
3927static void
c19d1205 3928s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3929{
c19d1205
ZW
3930 int reg;
3931 int hi_reg;
3932 unsigned mask = 0;
3933 valueT op;
b99bd4ef 3934
c19d1205
ZW
3935 if (*input_line_pointer == '{')
3936 input_line_pointer++;
b99bd4ef 3937
c19d1205 3938 do
b99bd4ef 3939 {
dcbf9037 3940 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3941
c19d1205
ZW
3942 if (reg == FAIL)
3943 {
9b7132d3 3944 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3945 goto error;
3946 }
b99bd4ef 3947
c19d1205
ZW
3948 reg -= 8;
3949 if (mask >> reg)
3950 as_tsktsk (_("register list not in ascending order"));
3951 mask |= 1 << reg;
b99bd4ef 3952
c19d1205
ZW
3953 if (*input_line_pointer == '-')
3954 {
3955 input_line_pointer++;
dcbf9037 3956 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3957 if (hi_reg == FAIL)
3958 {
9b7132d3 3959 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3960 goto error;
3961 }
3962 else if (reg >= hi_reg)
3963 {
3964 as_bad (_("bad register range"));
3965 goto error;
3966 }
3967 for (; reg < hi_reg; reg++)
3968 mask |= 1 << reg;
3969 }
b99bd4ef 3970 }
c19d1205 3971 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3972
c19d1205
ZW
3973 if (*input_line_pointer == '}')
3974 input_line_pointer++;
b99bd4ef 3975
c19d1205
ZW
3976 demand_empty_rest_of_line ();
3977
708587a4 3978 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3979 the list. */
3980 flush_pending_unwind ();
b99bd4ef 3981
c19d1205 3982 for (reg = 0; reg < 16; reg++)
b99bd4ef 3983 {
c19d1205
ZW
3984 if (mask & (1 << reg))
3985 unwind.frame_size += 4;
b99bd4ef 3986 }
c19d1205
ZW
3987 op = 0xc700 | mask;
3988 add_unwind_opcode (op, 2);
3989 return;
3990error:
3991 ignore_rest_of_line ();
b99bd4ef
NC
3992}
3993
c19d1205 3994
fa073d69
MS
3995/* Parse an unwind_save directive.
3996 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3997
b99bd4ef 3998static void
fa073d69 3999s_arm_unwind_save (int arch_v6)
b99bd4ef 4000{
c19d1205
ZW
4001 char *peek;
4002 struct reg_entry *reg;
4003 bfd_boolean had_brace = FALSE;
b99bd4ef 4004
921e5f0a 4005 if (!unwind.proc_start)
c921be7d 4006 as_bad (MISSING_FNSTART);
921e5f0a 4007
c19d1205
ZW
4008 /* Figure out what sort of save we have. */
4009 peek = input_line_pointer;
b99bd4ef 4010
c19d1205 4011 if (*peek == '{')
b99bd4ef 4012 {
c19d1205
ZW
4013 had_brace = TRUE;
4014 peek++;
b99bd4ef
NC
4015 }
4016
c19d1205 4017 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4018
c19d1205 4019 if (!reg)
b99bd4ef 4020 {
c19d1205
ZW
4021 as_bad (_("register expected"));
4022 ignore_rest_of_line ();
b99bd4ef
NC
4023 return;
4024 }
4025
c19d1205 4026 switch (reg->type)
b99bd4ef 4027 {
c19d1205
ZW
4028 case REG_TYPE_FN:
4029 if (had_brace)
4030 {
4031 as_bad (_("FPA .unwind_save does not take a register list"));
4032 ignore_rest_of_line ();
4033 return;
4034 }
93ac2687 4035 input_line_pointer = peek;
c19d1205 4036 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4037 return;
c19d1205
ZW
4038
4039 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4040 case REG_TYPE_VFD:
4041 if (arch_v6)
4042 s_arm_unwind_save_vfp_armv6 ();
4043 else
4044 s_arm_unwind_save_vfp ();
4045 return;
c19d1205
ZW
4046 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4047 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4048
4049 default:
4050 as_bad (_(".unwind_save does not support this kind of register"));
4051 ignore_rest_of_line ();
b99bd4ef 4052 }
c19d1205 4053}
b99bd4ef 4054
b99bd4ef 4055
c19d1205
ZW
4056/* Parse an unwind_movsp directive. */
4057
4058static void
4059s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4060{
4061 int reg;
4062 valueT op;
4fa3602b 4063 int offset;
c19d1205 4064
921e5f0a 4065 if (!unwind.proc_start)
c921be7d 4066 as_bad (MISSING_FNSTART);
921e5f0a 4067
dcbf9037 4068 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4069 if (reg == FAIL)
b99bd4ef 4070 {
9b7132d3 4071 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4072 ignore_rest_of_line ();
b99bd4ef
NC
4073 return;
4074 }
4fa3602b
PB
4075
4076 /* Optional constant. */
4077 if (skip_past_comma (&input_line_pointer) != FAIL)
4078 {
4079 if (immediate_for_directive (&offset) == FAIL)
4080 return;
4081 }
4082 else
4083 offset = 0;
4084
c19d1205 4085 demand_empty_rest_of_line ();
b99bd4ef 4086
c19d1205 4087 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4088 {
c19d1205 4089 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4090 return;
4091 }
4092
c19d1205
ZW
4093 if (unwind.fp_reg != REG_SP)
4094 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4095
c19d1205
ZW
4096 /* Generate opcode to restore the value. */
4097 op = 0x90 | reg;
4098 add_unwind_opcode (op, 1);
4099
4100 /* Record the information for later. */
4101 unwind.fp_reg = reg;
4fa3602b 4102 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4103 unwind.sp_restored = 1;
b05fe5cf
ZW
4104}
4105
c19d1205
ZW
4106/* Parse an unwind_pad directive. */
4107
b05fe5cf 4108static void
c19d1205 4109s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4110{
c19d1205 4111 int offset;
b05fe5cf 4112
921e5f0a 4113 if (!unwind.proc_start)
c921be7d 4114 as_bad (MISSING_FNSTART);
921e5f0a 4115
c19d1205
ZW
4116 if (immediate_for_directive (&offset) == FAIL)
4117 return;
b99bd4ef 4118
c19d1205
ZW
4119 if (offset & 3)
4120 {
4121 as_bad (_("stack increment must be multiple of 4"));
4122 ignore_rest_of_line ();
4123 return;
4124 }
b99bd4ef 4125
c19d1205
ZW
4126 /* Don't generate any opcodes, just record the details for later. */
4127 unwind.frame_size += offset;
4128 unwind.pending_offset += offset;
4129
4130 demand_empty_rest_of_line ();
4131}
4132
4133/* Parse an unwind_setfp directive. */
4134
4135static void
4136s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4137{
c19d1205
ZW
4138 int sp_reg;
4139 int fp_reg;
4140 int offset;
4141
921e5f0a 4142 if (!unwind.proc_start)
c921be7d 4143 as_bad (MISSING_FNSTART);
921e5f0a 4144
dcbf9037 4145 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4146 if (skip_past_comma (&input_line_pointer) == FAIL)
4147 sp_reg = FAIL;
4148 else
dcbf9037 4149 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4150
c19d1205
ZW
4151 if (fp_reg == FAIL || sp_reg == FAIL)
4152 {
4153 as_bad (_("expected <reg>, <reg>"));
4154 ignore_rest_of_line ();
4155 return;
4156 }
b99bd4ef 4157
c19d1205
ZW
4158 /* Optional constant. */
4159 if (skip_past_comma (&input_line_pointer) != FAIL)
4160 {
4161 if (immediate_for_directive (&offset) == FAIL)
4162 return;
4163 }
4164 else
4165 offset = 0;
a737bd4d 4166
c19d1205 4167 demand_empty_rest_of_line ();
a737bd4d 4168
fdfde340 4169 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4170 {
c19d1205
ZW
4171 as_bad (_("register must be either sp or set by a previous"
4172 "unwind_movsp directive"));
4173 return;
a737bd4d
NC
4174 }
4175
c19d1205
ZW
4176 /* Don't generate any opcodes, just record the information for later. */
4177 unwind.fp_reg = fp_reg;
4178 unwind.fp_used = 1;
fdfde340 4179 if (sp_reg == REG_SP)
c19d1205
ZW
4180 unwind.fp_offset = unwind.frame_size - offset;
4181 else
4182 unwind.fp_offset -= offset;
a737bd4d
NC
4183}
4184
c19d1205
ZW
4185/* Parse an unwind_raw directive. */
4186
4187static void
4188s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4189{
c19d1205 4190 expressionS exp;
708587a4 4191 /* This is an arbitrary limit. */
c19d1205
ZW
4192 unsigned char op[16];
4193 int count;
a737bd4d 4194
921e5f0a 4195 if (!unwind.proc_start)
c921be7d 4196 as_bad (MISSING_FNSTART);
921e5f0a 4197
c19d1205
ZW
4198 expression (&exp);
4199 if (exp.X_op == O_constant
4200 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4201 {
c19d1205
ZW
4202 unwind.frame_size += exp.X_add_number;
4203 expression (&exp);
4204 }
4205 else
4206 exp.X_op = O_illegal;
a737bd4d 4207
c19d1205
ZW
4208 if (exp.X_op != O_constant)
4209 {
4210 as_bad (_("expected <offset>, <opcode>"));
4211 ignore_rest_of_line ();
4212 return;
4213 }
a737bd4d 4214
c19d1205 4215 count = 0;
a737bd4d 4216
c19d1205
ZW
4217 /* Parse the opcode. */
4218 for (;;)
4219 {
4220 if (count >= 16)
4221 {
4222 as_bad (_("unwind opcode too long"));
4223 ignore_rest_of_line ();
a737bd4d 4224 }
c19d1205 4225 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4226 {
c19d1205
ZW
4227 as_bad (_("invalid unwind opcode"));
4228 ignore_rest_of_line ();
4229 return;
a737bd4d 4230 }
c19d1205 4231 op[count++] = exp.X_add_number;
a737bd4d 4232
c19d1205
ZW
4233 /* Parse the next byte. */
4234 if (skip_past_comma (&input_line_pointer) == FAIL)
4235 break;
a737bd4d 4236
c19d1205
ZW
4237 expression (&exp);
4238 }
b99bd4ef 4239
c19d1205
ZW
4240 /* Add the opcode bytes in reverse order. */
4241 while (count--)
4242 add_unwind_opcode (op[count], 1);
b99bd4ef 4243
c19d1205 4244 demand_empty_rest_of_line ();
b99bd4ef 4245}
ee065d83
PB
4246
4247
4248/* Parse a .eabi_attribute directive. */
4249
4250static void
4251s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4252{
ee3c0378
AS
4253 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4254
4255 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4256 attributes_set_explicitly[tag] = 1;
ee065d83 4257}
8463be01 4258#endif /* OBJ_ELF */
ee065d83
PB
4259
4260static void s_arm_arch (int);
7a1d4c38 4261static void s_arm_object_arch (int);
ee065d83
PB
4262static void s_arm_cpu (int);
4263static void s_arm_fpu (int);
b99bd4ef 4264
f0927246
NC
4265#ifdef TE_PE
4266
4267static void
5f4273c7 4268pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4269{
4270 expressionS exp;
4271
4272 do
4273 {
4274 expression (&exp);
4275 if (exp.X_op == O_symbol)
4276 exp.X_op = O_secrel;
4277
4278 emit_expr (&exp, 4);
4279 }
4280 while (*input_line_pointer++ == ',');
4281
4282 input_line_pointer--;
4283 demand_empty_rest_of_line ();
4284}
4285#endif /* TE_PE */
4286
c19d1205
ZW
4287/* This table describes all the machine specific pseudo-ops the assembler
4288 has to support. The fields are:
4289 pseudo-op name without dot
4290 function to call to execute this pseudo-op
4291 Integer arg to pass to the function. */
b99bd4ef 4292
c19d1205 4293const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4294{
c19d1205
ZW
4295 /* Never called because '.req' does not start a line. */
4296 { "req", s_req, 0 },
dcbf9037
JB
4297 /* Following two are likewise never called. */
4298 { "dn", s_dn, 0 },
4299 { "qn", s_qn, 0 },
c19d1205
ZW
4300 { "unreq", s_unreq, 0 },
4301 { "bss", s_bss, 0 },
4302 { "align", s_align, 0 },
4303 { "arm", s_arm, 0 },
4304 { "thumb", s_thumb, 0 },
4305 { "code", s_code, 0 },
4306 { "force_thumb", s_force_thumb, 0 },
4307 { "thumb_func", s_thumb_func, 0 },
4308 { "thumb_set", s_thumb_set, 0 },
4309 { "even", s_even, 0 },
4310 { "ltorg", s_ltorg, 0 },
4311 { "pool", s_ltorg, 0 },
4312 { "syntax", s_syntax, 0 },
8463be01
PB
4313 { "cpu", s_arm_cpu, 0 },
4314 { "arch", s_arm_arch, 0 },
7a1d4c38 4315 { "object_arch", s_arm_object_arch, 0 },
8463be01 4316 { "fpu", s_arm_fpu, 0 },
c19d1205 4317#ifdef OBJ_ELF
c921be7d
NC
4318 { "word", s_arm_elf_cons, 4 },
4319 { "long", s_arm_elf_cons, 4 },
4320 { "inst.n", s_arm_elf_inst, 2 },
4321 { "inst.w", s_arm_elf_inst, 4 },
4322 { "inst", s_arm_elf_inst, 0 },
4323 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4324 { "fnstart", s_arm_unwind_fnstart, 0 },
4325 { "fnend", s_arm_unwind_fnend, 0 },
4326 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4327 { "personality", s_arm_unwind_personality, 0 },
4328 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4329 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4330 { "save", s_arm_unwind_save, 0 },
fa073d69 4331 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4332 { "movsp", s_arm_unwind_movsp, 0 },
4333 { "pad", s_arm_unwind_pad, 0 },
4334 { "setfp", s_arm_unwind_setfp, 0 },
4335 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4336 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4337#else
4338 { "word", cons, 4},
f0927246
NC
4339
4340 /* These are used for dwarf. */
4341 {"2byte", cons, 2},
4342 {"4byte", cons, 4},
4343 {"8byte", cons, 8},
4344 /* These are used for dwarf2. */
4345 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4346 { "loc", dwarf2_directive_loc, 0 },
4347 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4348#endif
4349 { "extend", float_cons, 'x' },
4350 { "ldouble", float_cons, 'x' },
4351 { "packed", float_cons, 'p' },
f0927246
NC
4352#ifdef TE_PE
4353 {"secrel32", pe_directive_secrel, 0},
4354#endif
c19d1205
ZW
4355 { 0, 0, 0 }
4356};
4357\f
4358/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4359
c19d1205
ZW
4360/* Generic immediate-value read function for use in insn parsing.
4361 STR points to the beginning of the immediate (the leading #);
4362 VAL receives the value; if the value is outside [MIN, MAX]
4363 issue an error. PREFIX_OPT is true if the immediate prefix is
4364 optional. */
b99bd4ef 4365
c19d1205
ZW
4366static int
4367parse_immediate (char **str, int *val, int min, int max,
4368 bfd_boolean prefix_opt)
4369{
4370 expressionS exp;
4371 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4372 if (exp.X_op != O_constant)
b99bd4ef 4373 {
c19d1205
ZW
4374 inst.error = _("constant expression required");
4375 return FAIL;
4376 }
b99bd4ef 4377
c19d1205
ZW
4378 if (exp.X_add_number < min || exp.X_add_number > max)
4379 {
4380 inst.error = _("immediate value out of range");
4381 return FAIL;
4382 }
b99bd4ef 4383
c19d1205
ZW
4384 *val = exp.X_add_number;
4385 return SUCCESS;
4386}
b99bd4ef 4387
5287ad62 4388/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4389 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4390 instructions. Puts the result directly in inst.operands[i]. */
4391
4392static int
4393parse_big_immediate (char **str, int i)
4394{
4395 expressionS exp;
4396 char *ptr = *str;
4397
4398 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4399
4400 if (exp.X_op == O_constant)
036dc3f7
PB
4401 {
4402 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4403 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4404 O_constant. We have to be careful not to break compilation for
4405 32-bit X_add_number, though. */
4406 if ((exp.X_add_number & ~0xffffffffl) != 0)
4407 {
4408 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4409 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4410 inst.operands[i].regisimm = 1;
4411 }
4412 }
5287ad62
JB
4413 else if (exp.X_op == O_big
4414 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4415 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4416 {
4417 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4418 /* Bignums have their least significant bits in
4419 generic_bignum[0]. Make sure we put 32 bits in imm and
4420 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4421 gas_assert (parts != 0);
5287ad62
JB
4422 inst.operands[i].imm = 0;
4423 for (j = 0; j < parts; j++, idx++)
4424 inst.operands[i].imm |= generic_bignum[idx]
4425 << (LITTLENUM_NUMBER_OF_BITS * j);
4426 inst.operands[i].reg = 0;
4427 for (j = 0; j < parts; j++, idx++)
4428 inst.operands[i].reg |= generic_bignum[idx]
4429 << (LITTLENUM_NUMBER_OF_BITS * j);
4430 inst.operands[i].regisimm = 1;
4431 }
4432 else
4433 return FAIL;
5f4273c7 4434
5287ad62
JB
4435 *str = ptr;
4436
4437 return SUCCESS;
4438}
4439
c19d1205
ZW
4440/* Returns the pseudo-register number of an FPA immediate constant,
4441 or FAIL if there isn't a valid constant here. */
b99bd4ef 4442
c19d1205
ZW
4443static int
4444parse_fpa_immediate (char ** str)
4445{
4446 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4447 char * save_in;
4448 expressionS exp;
4449 int i;
4450 int j;
b99bd4ef 4451
c19d1205
ZW
4452 /* First try and match exact strings, this is to guarantee
4453 that some formats will work even for cross assembly. */
b99bd4ef 4454
c19d1205
ZW
4455 for (i = 0; fp_const[i]; i++)
4456 {
4457 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4458 {
c19d1205 4459 char *start = *str;
b99bd4ef 4460
c19d1205
ZW
4461 *str += strlen (fp_const[i]);
4462 if (is_end_of_line[(unsigned char) **str])
4463 return i + 8;
4464 *str = start;
4465 }
4466 }
b99bd4ef 4467
c19d1205
ZW
4468 /* Just because we didn't get a match doesn't mean that the constant
4469 isn't valid, just that it is in a format that we don't
4470 automatically recognize. Try parsing it with the standard
4471 expression routines. */
b99bd4ef 4472
c19d1205 4473 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4474
c19d1205
ZW
4475 /* Look for a raw floating point number. */
4476 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4477 && is_end_of_line[(unsigned char) *save_in])
4478 {
4479 for (i = 0; i < NUM_FLOAT_VALS; i++)
4480 {
4481 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4482 {
c19d1205
ZW
4483 if (words[j] != fp_values[i][j])
4484 break;
b99bd4ef
NC
4485 }
4486
c19d1205 4487 if (j == MAX_LITTLENUMS)
b99bd4ef 4488 {
c19d1205
ZW
4489 *str = save_in;
4490 return i + 8;
b99bd4ef
NC
4491 }
4492 }
4493 }
b99bd4ef 4494
c19d1205
ZW
4495 /* Try and parse a more complex expression, this will probably fail
4496 unless the code uses a floating point prefix (eg "0f"). */
4497 save_in = input_line_pointer;
4498 input_line_pointer = *str;
4499 if (expression (&exp) == absolute_section
4500 && exp.X_op == O_big
4501 && exp.X_add_number < 0)
4502 {
4503 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4504 Ditto for 15. */
4505 if (gen_to_words (words, 5, (long) 15) == 0)
4506 {
4507 for (i = 0; i < NUM_FLOAT_VALS; i++)
4508 {
4509 for (j = 0; j < MAX_LITTLENUMS; j++)
4510 {
4511 if (words[j] != fp_values[i][j])
4512 break;
4513 }
b99bd4ef 4514
c19d1205
ZW
4515 if (j == MAX_LITTLENUMS)
4516 {
4517 *str = input_line_pointer;
4518 input_line_pointer = save_in;
4519 return i + 8;
4520 }
4521 }
4522 }
b99bd4ef
NC
4523 }
4524
c19d1205
ZW
4525 *str = input_line_pointer;
4526 input_line_pointer = save_in;
4527 inst.error = _("invalid FPA immediate expression");
4528 return FAIL;
b99bd4ef
NC
4529}
4530
136da414
JB
4531/* Returns 1 if a number has "quarter-precision" float format
4532 0baBbbbbbc defgh000 00000000 00000000. */
4533
4534static int
4535is_quarter_float (unsigned imm)
4536{
4537 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4538 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4539}
4540
4541/* Parse an 8-bit "quarter-precision" floating point number of the form:
4542 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4543 The zero and minus-zero cases need special handling, since they can't be
4544 encoded in the "quarter-precision" float format, but can nonetheless be
4545 loaded as integer constants. */
136da414
JB
4546
4547static unsigned
4548parse_qfloat_immediate (char **ccp, int *immed)
4549{
4550 char *str = *ccp;
c96612cc 4551 char *fpnum;
136da414 4552 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4553 int found_fpchar = 0;
5f4273c7 4554
136da414 4555 skip_past_char (&str, '#');
5f4273c7 4556
c96612cc
JB
4557 /* We must not accidentally parse an integer as a floating-point number. Make
4558 sure that the value we parse is not an integer by checking for special
4559 characters '.' or 'e'.
4560 FIXME: This is a horrible hack, but doing better is tricky because type
4561 information isn't in a very usable state at parse time. */
4562 fpnum = str;
4563 skip_whitespace (fpnum);
4564
4565 if (strncmp (fpnum, "0x", 2) == 0)
4566 return FAIL;
4567 else
4568 {
4569 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4570 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4571 {
4572 found_fpchar = 1;
4573 break;
4574 }
4575
4576 if (!found_fpchar)
4577 return FAIL;
4578 }
5f4273c7 4579
136da414
JB
4580 if ((str = atof_ieee (str, 's', words)) != NULL)
4581 {
4582 unsigned fpword = 0;
4583 int i;
5f4273c7 4584
136da414
JB
4585 /* Our FP word must be 32 bits (single-precision FP). */
4586 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4587 {
4588 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4589 fpword |= words[i];
4590 }
5f4273c7 4591
c96612cc 4592 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4593 *immed = fpword;
4594 else
4595 return FAIL;
4596
4597 *ccp = str;
5f4273c7 4598
136da414
JB
4599 return SUCCESS;
4600 }
5f4273c7 4601
136da414
JB
4602 return FAIL;
4603}
4604
c19d1205
ZW
4605/* Shift operands. */
4606enum shift_kind
b99bd4ef 4607{
c19d1205
ZW
4608 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4609};
b99bd4ef 4610
c19d1205
ZW
4611struct asm_shift_name
4612{
4613 const char *name;
4614 enum shift_kind kind;
4615};
b99bd4ef 4616
c19d1205
ZW
4617/* Third argument to parse_shift. */
4618enum parse_shift_mode
4619{
4620 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4621 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4622 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4623 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4624 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4625};
b99bd4ef 4626
c19d1205
ZW
4627/* Parse a <shift> specifier on an ARM data processing instruction.
4628 This has three forms:
b99bd4ef 4629
c19d1205
ZW
4630 (LSL|LSR|ASL|ASR|ROR) Rs
4631 (LSL|LSR|ASL|ASR|ROR) #imm
4632 RRX
b99bd4ef 4633
c19d1205
ZW
4634 Note that ASL is assimilated to LSL in the instruction encoding, and
4635 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4636
c19d1205
ZW
4637static int
4638parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4639{
c19d1205
ZW
4640 const struct asm_shift_name *shift_name;
4641 enum shift_kind shift;
4642 char *s = *str;
4643 char *p = s;
4644 int reg;
b99bd4ef 4645
c19d1205
ZW
4646 for (p = *str; ISALPHA (*p); p++)
4647 ;
b99bd4ef 4648
c19d1205 4649 if (p == *str)
b99bd4ef 4650 {
c19d1205
ZW
4651 inst.error = _("shift expression expected");
4652 return FAIL;
b99bd4ef
NC
4653 }
4654
21d799b5
NC
4655 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4656 p - *str);
c19d1205
ZW
4657
4658 if (shift_name == NULL)
b99bd4ef 4659 {
c19d1205
ZW
4660 inst.error = _("shift expression expected");
4661 return FAIL;
b99bd4ef
NC
4662 }
4663
c19d1205 4664 shift = shift_name->kind;
b99bd4ef 4665
c19d1205
ZW
4666 switch (mode)
4667 {
4668 case NO_SHIFT_RESTRICT:
4669 case SHIFT_IMMEDIATE: break;
b99bd4ef 4670
c19d1205
ZW
4671 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4672 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4673 {
4674 inst.error = _("'LSL' or 'ASR' required");
4675 return FAIL;
4676 }
4677 break;
b99bd4ef 4678
c19d1205
ZW
4679 case SHIFT_LSL_IMMEDIATE:
4680 if (shift != SHIFT_LSL)
4681 {
4682 inst.error = _("'LSL' required");
4683 return FAIL;
4684 }
4685 break;
b99bd4ef 4686
c19d1205
ZW
4687 case SHIFT_ASR_IMMEDIATE:
4688 if (shift != SHIFT_ASR)
4689 {
4690 inst.error = _("'ASR' required");
4691 return FAIL;
4692 }
4693 break;
b99bd4ef 4694
c19d1205
ZW
4695 default: abort ();
4696 }
b99bd4ef 4697
c19d1205
ZW
4698 if (shift != SHIFT_RRX)
4699 {
4700 /* Whitespace can appear here if the next thing is a bare digit. */
4701 skip_whitespace (p);
b99bd4ef 4702
c19d1205 4703 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4704 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4705 {
4706 inst.operands[i].imm = reg;
4707 inst.operands[i].immisreg = 1;
4708 }
4709 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4710 return FAIL;
4711 }
4712 inst.operands[i].shift_kind = shift;
4713 inst.operands[i].shifted = 1;
4714 *str = p;
4715 return SUCCESS;
b99bd4ef
NC
4716}
4717
c19d1205 4718/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4719
c19d1205
ZW
4720 #<immediate>
4721 #<immediate>, <rotate>
4722 <Rm>
4723 <Rm>, <shift>
b99bd4ef 4724
c19d1205
ZW
4725 where <shift> is defined by parse_shift above, and <rotate> is a
4726 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4727 is deferred to md_apply_fix. */
b99bd4ef 4728
c19d1205
ZW
4729static int
4730parse_shifter_operand (char **str, int i)
4731{
4732 int value;
91d6fa6a 4733 expressionS exp;
b99bd4ef 4734
dcbf9037 4735 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4736 {
4737 inst.operands[i].reg = value;
4738 inst.operands[i].isreg = 1;
b99bd4ef 4739
c19d1205
ZW
4740 /* parse_shift will override this if appropriate */
4741 inst.reloc.exp.X_op = O_constant;
4742 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4743
c19d1205
ZW
4744 if (skip_past_comma (str) == FAIL)
4745 return SUCCESS;
b99bd4ef 4746
c19d1205
ZW
4747 /* Shift operation on register. */
4748 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4749 }
4750
c19d1205
ZW
4751 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4752 return FAIL;
b99bd4ef 4753
c19d1205 4754 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4755 {
c19d1205 4756 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4757 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4758 return FAIL;
b99bd4ef 4759
91d6fa6a 4760 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4761 {
4762 inst.error = _("constant expression expected");
4763 return FAIL;
4764 }
b99bd4ef 4765
91d6fa6a 4766 value = exp.X_add_number;
c19d1205
ZW
4767 if (value < 0 || value > 30 || value % 2 != 0)
4768 {
4769 inst.error = _("invalid rotation");
4770 return FAIL;
4771 }
4772 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4773 {
4774 inst.error = _("invalid constant");
4775 return FAIL;
4776 }
09d92015 4777
55cf6793 4778 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4779 inst.reloc.exp.X_add_number
4780 = (((inst.reloc.exp.X_add_number << (32 - value))
4781 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4782 }
4783
c19d1205
ZW
4784 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4785 inst.reloc.pc_rel = 0;
4786 return SUCCESS;
09d92015
MM
4787}
4788
4962c51a
MS
4789/* Group relocation information. Each entry in the table contains the
4790 textual name of the relocation as may appear in assembler source
4791 and must end with a colon.
4792 Along with this textual name are the relocation codes to be used if
4793 the corresponding instruction is an ALU instruction (ADD or SUB only),
4794 an LDR, an LDRS, or an LDC. */
4795
4796struct group_reloc_table_entry
4797{
4798 const char *name;
4799 int alu_code;
4800 int ldr_code;
4801 int ldrs_code;
4802 int ldc_code;
4803};
4804
4805typedef enum
4806{
4807 /* Varieties of non-ALU group relocation. */
4808
4809 GROUP_LDR,
4810 GROUP_LDRS,
4811 GROUP_LDC
4812} group_reloc_type;
4813
4814static struct group_reloc_table_entry group_reloc_table[] =
4815 { /* Program counter relative: */
4816 { "pc_g0_nc",
4817 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4818 0, /* LDR */
4819 0, /* LDRS */
4820 0 }, /* LDC */
4821 { "pc_g0",
4822 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4823 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4824 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4825 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4826 { "pc_g1_nc",
4827 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4828 0, /* LDR */
4829 0, /* LDRS */
4830 0 }, /* LDC */
4831 { "pc_g1",
4832 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4833 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4834 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4835 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4836 { "pc_g2",
4837 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4838 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4839 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4840 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4841 /* Section base relative */
4842 { "sb_g0_nc",
4843 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4844 0, /* LDR */
4845 0, /* LDRS */
4846 0 }, /* LDC */
4847 { "sb_g0",
4848 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4849 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4850 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4851 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4852 { "sb_g1_nc",
4853 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4854 0, /* LDR */
4855 0, /* LDRS */
4856 0 }, /* LDC */
4857 { "sb_g1",
4858 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4859 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4860 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4861 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4862 { "sb_g2",
4863 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4864 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4865 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4866 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4867
4868/* Given the address of a pointer pointing to the textual name of a group
4869 relocation as may appear in assembler source, attempt to find its details
4870 in group_reloc_table. The pointer will be updated to the character after
4871 the trailing colon. On failure, FAIL will be returned; SUCCESS
4872 otherwise. On success, *entry will be updated to point at the relevant
4873 group_reloc_table entry. */
4874
4875static int
4876find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4877{
4878 unsigned int i;
4879 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4880 {
4881 int length = strlen (group_reloc_table[i].name);
4882
5f4273c7
NC
4883 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4884 && (*str)[length] == ':')
4962c51a
MS
4885 {
4886 *out = &group_reloc_table[i];
4887 *str += (length + 1);
4888 return SUCCESS;
4889 }
4890 }
4891
4892 return FAIL;
4893}
4894
4895/* Parse a <shifter_operand> for an ARM data processing instruction
4896 (as for parse_shifter_operand) where group relocations are allowed:
4897
4898 #<immediate>
4899 #<immediate>, <rotate>
4900 #:<group_reloc>:<expression>
4901 <Rm>
4902 <Rm>, <shift>
4903
4904 where <group_reloc> is one of the strings defined in group_reloc_table.
4905 The hashes are optional.
4906
4907 Everything else is as for parse_shifter_operand. */
4908
4909static parse_operand_result
4910parse_shifter_operand_group_reloc (char **str, int i)
4911{
4912 /* Determine if we have the sequence of characters #: or just :
4913 coming next. If we do, then we check for a group relocation.
4914 If we don't, punt the whole lot to parse_shifter_operand. */
4915
4916 if (((*str)[0] == '#' && (*str)[1] == ':')
4917 || (*str)[0] == ':')
4918 {
4919 struct group_reloc_table_entry *entry;
4920
4921 if ((*str)[0] == '#')
4922 (*str) += 2;
4923 else
4924 (*str)++;
4925
4926 /* Try to parse a group relocation. Anything else is an error. */
4927 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4928 {
4929 inst.error = _("unknown group relocation");
4930 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4931 }
4932
4933 /* We now have the group relocation table entry corresponding to
4934 the name in the assembler source. Next, we parse the expression. */
4935 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4936 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4937
4938 /* Record the relocation type (always the ALU variant here). */
21d799b5 4939 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4940 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4941
4942 return PARSE_OPERAND_SUCCESS;
4943 }
4944 else
4945 return parse_shifter_operand (str, i) == SUCCESS
4946 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4947
4948 /* Never reached. */
4949}
4950
c19d1205
ZW
4951/* Parse all forms of an ARM address expression. Information is written
4952 to inst.operands[i] and/or inst.reloc.
09d92015 4953
c19d1205 4954 Preindexed addressing (.preind=1):
09d92015 4955
c19d1205
ZW
4956 [Rn, #offset] .reg=Rn .reloc.exp=offset
4957 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4958 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4959 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4960
c19d1205 4961 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4962
c19d1205 4963 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4964
c19d1205
ZW
4965 [Rn], #offset .reg=Rn .reloc.exp=offset
4966 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4967 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4968 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4969
c19d1205 4970 Unindexed addressing (.preind=0, .postind=0):
09d92015 4971
c19d1205 4972 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4973
c19d1205 4974 Other:
09d92015 4975
c19d1205
ZW
4976 [Rn]{!} shorthand for [Rn,#0]{!}
4977 =immediate .isreg=0 .reloc.exp=immediate
4978 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4979
c19d1205
ZW
4980 It is the caller's responsibility to check for addressing modes not
4981 supported by the instruction, and to set inst.reloc.type. */
4982
4962c51a
MS
4983static parse_operand_result
4984parse_address_main (char **str, int i, int group_relocations,
4985 group_reloc_type group_type)
09d92015 4986{
c19d1205
ZW
4987 char *p = *str;
4988 int reg;
09d92015 4989
c19d1205 4990 if (skip_past_char (&p, '[') == FAIL)
09d92015 4991 {
c19d1205
ZW
4992 if (skip_past_char (&p, '=') == FAIL)
4993 {
974da60d 4994 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
4995 inst.reloc.pc_rel = 1;
4996 inst.operands[i].reg = REG_PC;
4997 inst.operands[i].isreg = 1;
4998 inst.operands[i].preind = 1;
4999 }
974da60d 5000 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 5001
c19d1205 5002 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 5003 return PARSE_OPERAND_FAIL;
09d92015 5004
c19d1205 5005 *str = p;
4962c51a 5006 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5007 }
5008
dcbf9037 5009 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5010 {
c19d1205 5011 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5012 return PARSE_OPERAND_FAIL;
09d92015 5013 }
c19d1205
ZW
5014 inst.operands[i].reg = reg;
5015 inst.operands[i].isreg = 1;
09d92015 5016
c19d1205 5017 if (skip_past_comma (&p) == SUCCESS)
09d92015 5018 {
c19d1205 5019 inst.operands[i].preind = 1;
09d92015 5020
c19d1205
ZW
5021 if (*p == '+') p++;
5022 else if (*p == '-') p++, inst.operands[i].negative = 1;
5023
dcbf9037 5024 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5025 {
c19d1205
ZW
5026 inst.operands[i].imm = reg;
5027 inst.operands[i].immisreg = 1;
5028
5029 if (skip_past_comma (&p) == SUCCESS)
5030 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5031 return PARSE_OPERAND_FAIL;
c19d1205 5032 }
5287ad62
JB
5033 else if (skip_past_char (&p, ':') == SUCCESS)
5034 {
5035 /* FIXME: '@' should be used here, but it's filtered out by generic
5036 code before we get to see it here. This may be subject to
5037 change. */
5038 expressionS exp;
5039 my_get_expression (&exp, &p, GE_NO_PREFIX);
5040 if (exp.X_op != O_constant)
5041 {
5042 inst.error = _("alignment must be constant");
4962c51a 5043 return PARSE_OPERAND_FAIL;
5287ad62
JB
5044 }
5045 inst.operands[i].imm = exp.X_add_number << 8;
5046 inst.operands[i].immisalign = 1;
5047 /* Alignments are not pre-indexes. */
5048 inst.operands[i].preind = 0;
5049 }
c19d1205
ZW
5050 else
5051 {
5052 if (inst.operands[i].negative)
5053 {
5054 inst.operands[i].negative = 0;
5055 p--;
5056 }
4962c51a 5057
5f4273c7
NC
5058 if (group_relocations
5059 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5060 {
5061 struct group_reloc_table_entry *entry;
5062
5063 /* Skip over the #: or : sequence. */
5064 if (*p == '#')
5065 p += 2;
5066 else
5067 p++;
5068
5069 /* Try to parse a group relocation. Anything else is an
5070 error. */
5071 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5072 {
5073 inst.error = _("unknown group relocation");
5074 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5075 }
5076
5077 /* We now have the group relocation table entry corresponding to
5078 the name in the assembler source. Next, we parse the
5079 expression. */
5080 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5081 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5082
5083 /* Record the relocation type. */
5084 switch (group_type)
5085 {
5086 case GROUP_LDR:
21d799b5 5087 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5088 break;
5089
5090 case GROUP_LDRS:
21d799b5 5091 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5092 break;
5093
5094 case GROUP_LDC:
21d799b5 5095 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5096 break;
5097
5098 default:
9c2799c2 5099 gas_assert (0);
4962c51a
MS
5100 }
5101
5102 if (inst.reloc.type == 0)
5103 {
5104 inst.error = _("this group relocation is not allowed on this instruction");
5105 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5106 }
5107 }
5108 else
5109 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5110 return PARSE_OPERAND_FAIL;
09d92015
MM
5111 }
5112 }
5113
c19d1205 5114 if (skip_past_char (&p, ']') == FAIL)
09d92015 5115 {
c19d1205 5116 inst.error = _("']' expected");
4962c51a 5117 return PARSE_OPERAND_FAIL;
09d92015
MM
5118 }
5119
c19d1205
ZW
5120 if (skip_past_char (&p, '!') == SUCCESS)
5121 inst.operands[i].writeback = 1;
09d92015 5122
c19d1205 5123 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5124 {
c19d1205
ZW
5125 if (skip_past_char (&p, '{') == SUCCESS)
5126 {
5127 /* [Rn], {expr} - unindexed, with option */
5128 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5129 0, 255, TRUE) == FAIL)
4962c51a 5130 return PARSE_OPERAND_FAIL;
09d92015 5131
c19d1205
ZW
5132 if (skip_past_char (&p, '}') == FAIL)
5133 {
5134 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5135 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5136 }
5137 if (inst.operands[i].preind)
5138 {
5139 inst.error = _("cannot combine index with option");
4962c51a 5140 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5141 }
5142 *str = p;
4962c51a 5143 return PARSE_OPERAND_SUCCESS;
09d92015 5144 }
c19d1205
ZW
5145 else
5146 {
5147 inst.operands[i].postind = 1;
5148 inst.operands[i].writeback = 1;
09d92015 5149
c19d1205
ZW
5150 if (inst.operands[i].preind)
5151 {
5152 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5153 return PARSE_OPERAND_FAIL;
c19d1205 5154 }
09d92015 5155
c19d1205
ZW
5156 if (*p == '+') p++;
5157 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5158
dcbf9037 5159 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5160 {
5287ad62
JB
5161 /* We might be using the immediate for alignment already. If we
5162 are, OR the register number into the low-order bits. */
5163 if (inst.operands[i].immisalign)
5164 inst.operands[i].imm |= reg;
5165 else
5166 inst.operands[i].imm = reg;
c19d1205 5167 inst.operands[i].immisreg = 1;
a737bd4d 5168
c19d1205
ZW
5169 if (skip_past_comma (&p) == SUCCESS)
5170 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5171 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5172 }
5173 else
5174 {
5175 if (inst.operands[i].negative)
5176 {
5177 inst.operands[i].negative = 0;
5178 p--;
5179 }
5180 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5181 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5182 }
5183 }
a737bd4d
NC
5184 }
5185
c19d1205
ZW
5186 /* If at this point neither .preind nor .postind is set, we have a
5187 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5188 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5189 {
5190 inst.operands[i].preind = 1;
5191 inst.reloc.exp.X_op = O_constant;
5192 inst.reloc.exp.X_add_number = 0;
5193 }
5194 *str = p;
4962c51a
MS
5195 return PARSE_OPERAND_SUCCESS;
5196}
5197
5198static int
5199parse_address (char **str, int i)
5200{
21d799b5 5201 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5202 ? SUCCESS : FAIL;
5203}
5204
5205static parse_operand_result
5206parse_address_group_reloc (char **str, int i, group_reloc_type type)
5207{
5208 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5209}
5210
b6895b4f
PB
5211/* Parse an operand for a MOVW or MOVT instruction. */
5212static int
5213parse_half (char **str)
5214{
5215 char * p;
5f4273c7 5216
b6895b4f
PB
5217 p = *str;
5218 skip_past_char (&p, '#');
5f4273c7 5219 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5220 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5221 else if (strncasecmp (p, ":upper16:", 9) == 0)
5222 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5223
5224 if (inst.reloc.type != BFD_RELOC_UNUSED)
5225 {
5226 p += 9;
5f4273c7 5227 skip_whitespace (p);
b6895b4f
PB
5228 }
5229
5230 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5231 return FAIL;
5232
5233 if (inst.reloc.type == BFD_RELOC_UNUSED)
5234 {
5235 if (inst.reloc.exp.X_op != O_constant)
5236 {
5237 inst.error = _("constant expression expected");
5238 return FAIL;
5239 }
5240 if (inst.reloc.exp.X_add_number < 0
5241 || inst.reloc.exp.X_add_number > 0xffff)
5242 {
5243 inst.error = _("immediate value out of range");
5244 return FAIL;
5245 }
5246 }
5247 *str = p;
5248 return SUCCESS;
5249}
5250
c19d1205 5251/* Miscellaneous. */
a737bd4d 5252
c19d1205
ZW
5253/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5254 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5255static int
5256parse_psr (char **str)
09d92015 5257{
c19d1205
ZW
5258 char *p;
5259 unsigned long psr_field;
62b3e311
PB
5260 const struct asm_psr *psr;
5261 char *start;
09d92015 5262
c19d1205
ZW
5263 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5264 feature for ease of use and backwards compatibility. */
5265 p = *str;
62b3e311 5266 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5267 psr_field = SPSR_BIT;
62b3e311 5268 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5269 psr_field = 0;
5270 else
62b3e311
PB
5271 {
5272 start = p;
5273 do
5274 p++;
5275 while (ISALNUM (*p) || *p == '_');
5276
21d799b5
NC
5277 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5278 p - start);
62b3e311
PB
5279 if (!psr)
5280 return FAIL;
09d92015 5281
62b3e311
PB
5282 *str = p;
5283 return psr->field;
5284 }
09d92015 5285
62b3e311 5286 p += 4;
c19d1205
ZW
5287 if (*p == '_')
5288 {
5289 /* A suffix follows. */
c19d1205
ZW
5290 p++;
5291 start = p;
a737bd4d 5292
c19d1205
ZW
5293 do
5294 p++;
5295 while (ISALNUM (*p) || *p == '_');
a737bd4d 5296
21d799b5
NC
5297 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5298 p - start);
c19d1205
ZW
5299 if (!psr)
5300 goto error;
a737bd4d 5301
c19d1205 5302 psr_field |= psr->field;
a737bd4d 5303 }
c19d1205 5304 else
a737bd4d 5305 {
c19d1205
ZW
5306 if (ISALNUM (*p))
5307 goto error; /* Garbage after "[CS]PSR". */
5308
5309 psr_field |= (PSR_c | PSR_f);
a737bd4d 5310 }
c19d1205
ZW
5311 *str = p;
5312 return psr_field;
a737bd4d 5313
c19d1205
ZW
5314 error:
5315 inst.error = _("flag for {c}psr instruction expected");
5316 return FAIL;
a737bd4d
NC
5317}
5318
c19d1205
ZW
5319/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5320 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5321
c19d1205
ZW
5322static int
5323parse_cps_flags (char **str)
a737bd4d 5324{
c19d1205
ZW
5325 int val = 0;
5326 int saw_a_flag = 0;
5327 char *s = *str;
a737bd4d 5328
c19d1205
ZW
5329 for (;;)
5330 switch (*s++)
5331 {
5332 case '\0': case ',':
5333 goto done;
a737bd4d 5334
c19d1205
ZW
5335 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5336 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5337 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5338
c19d1205
ZW
5339 default:
5340 inst.error = _("unrecognized CPS flag");
5341 return FAIL;
5342 }
a737bd4d 5343
c19d1205
ZW
5344 done:
5345 if (saw_a_flag == 0)
a737bd4d 5346 {
c19d1205
ZW
5347 inst.error = _("missing CPS flags");
5348 return FAIL;
a737bd4d 5349 }
a737bd4d 5350
c19d1205
ZW
5351 *str = s - 1;
5352 return val;
a737bd4d
NC
5353}
5354
c19d1205
ZW
5355/* Parse an endian specifier ("BE" or "LE", case insensitive);
5356 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5357
5358static int
c19d1205 5359parse_endian_specifier (char **str)
a737bd4d 5360{
c19d1205
ZW
5361 int little_endian;
5362 char *s = *str;
a737bd4d 5363
c19d1205
ZW
5364 if (strncasecmp (s, "BE", 2))
5365 little_endian = 0;
5366 else if (strncasecmp (s, "LE", 2))
5367 little_endian = 1;
5368 else
a737bd4d 5369 {
c19d1205 5370 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5371 return FAIL;
5372 }
5373
c19d1205 5374 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5375 {
c19d1205 5376 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5377 return FAIL;
5378 }
5379
c19d1205
ZW
5380 *str = s + 2;
5381 return little_endian;
5382}
a737bd4d 5383
c19d1205
ZW
5384/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5385 value suitable for poking into the rotate field of an sxt or sxta
5386 instruction, or FAIL on error. */
5387
5388static int
5389parse_ror (char **str)
5390{
5391 int rot;
5392 char *s = *str;
5393
5394 if (strncasecmp (s, "ROR", 3) == 0)
5395 s += 3;
5396 else
a737bd4d 5397 {
c19d1205 5398 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5399 return FAIL;
5400 }
c19d1205
ZW
5401
5402 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5403 return FAIL;
5404
5405 switch (rot)
a737bd4d 5406 {
c19d1205
ZW
5407 case 0: *str = s; return 0x0;
5408 case 8: *str = s; return 0x1;
5409 case 16: *str = s; return 0x2;
5410 case 24: *str = s; return 0x3;
5411
5412 default:
5413 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5414 return FAIL;
5415 }
c19d1205 5416}
a737bd4d 5417
c19d1205
ZW
5418/* Parse a conditional code (from conds[] below). The value returned is in the
5419 range 0 .. 14, or FAIL. */
5420static int
5421parse_cond (char **str)
5422{
c462b453 5423 char *q;
c19d1205 5424 const struct asm_cond *c;
c462b453
PB
5425 int n;
5426 /* Condition codes are always 2 characters, so matching up to
5427 3 characters is sufficient. */
5428 char cond[3];
a737bd4d 5429
c462b453
PB
5430 q = *str;
5431 n = 0;
5432 while (ISALPHA (*q) && n < 3)
5433 {
e07e6e58 5434 cond[n] = TOLOWER (*q);
c462b453
PB
5435 q++;
5436 n++;
5437 }
a737bd4d 5438
21d799b5 5439 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5440 if (!c)
a737bd4d 5441 {
c19d1205 5442 inst.error = _("condition required");
a737bd4d
NC
5443 return FAIL;
5444 }
5445
c19d1205
ZW
5446 *str = q;
5447 return c->value;
5448}
5449
62b3e311
PB
5450/* Parse an option for a barrier instruction. Returns the encoding for the
5451 option, or FAIL. */
5452static int
5453parse_barrier (char **str)
5454{
5455 char *p, *q;
5456 const struct asm_barrier_opt *o;
5457
5458 p = q = *str;
5459 while (ISALPHA (*q))
5460 q++;
5461
21d799b5
NC
5462 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5463 q - p);
62b3e311
PB
5464 if (!o)
5465 return FAIL;
5466
5467 *str = q;
5468 return o->value;
5469}
5470
92e90b6e
PB
5471/* Parse the operands of a table branch instruction. Similar to a memory
5472 operand. */
5473static int
5474parse_tb (char **str)
5475{
5476 char * p = *str;
5477 int reg;
5478
5479 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5480 {
5481 inst.error = _("'[' expected");
5482 return FAIL;
5483 }
92e90b6e 5484
dcbf9037 5485 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5486 {
5487 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5488 return FAIL;
5489 }
5490 inst.operands[0].reg = reg;
5491
5492 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5493 {
5494 inst.error = _("',' expected");
5495 return FAIL;
5496 }
5f4273c7 5497
dcbf9037 5498 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5499 {
5500 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5501 return FAIL;
5502 }
5503 inst.operands[0].imm = reg;
5504
5505 if (skip_past_comma (&p) == SUCCESS)
5506 {
5507 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5508 return FAIL;
5509 if (inst.reloc.exp.X_add_number != 1)
5510 {
5511 inst.error = _("invalid shift");
5512 return FAIL;
5513 }
5514 inst.operands[0].shifted = 1;
5515 }
5516
5517 if (skip_past_char (&p, ']') == FAIL)
5518 {
5519 inst.error = _("']' expected");
5520 return FAIL;
5521 }
5522 *str = p;
5523 return SUCCESS;
5524}
5525
5287ad62
JB
5526/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5527 information on the types the operands can take and how they are encoded.
037e8744
JB
5528 Up to four operands may be read; this function handles setting the
5529 ".present" field for each read operand itself.
5287ad62
JB
5530 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5531 else returns FAIL. */
5532
5533static int
5534parse_neon_mov (char **str, int *which_operand)
5535{
5536 int i = *which_operand, val;
5537 enum arm_reg_type rtype;
5538 char *ptr = *str;
dcbf9037 5539 struct neon_type_el optype;
5f4273c7 5540
dcbf9037 5541 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5542 {
5543 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5544 inst.operands[i].reg = val;
5545 inst.operands[i].isscalar = 1;
dcbf9037 5546 inst.operands[i].vectype = optype;
5287ad62
JB
5547 inst.operands[i++].present = 1;
5548
5549 if (skip_past_comma (&ptr) == FAIL)
5550 goto wanted_comma;
5f4273c7 5551
dcbf9037 5552 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5553 goto wanted_arm;
5f4273c7 5554
5287ad62
JB
5555 inst.operands[i].reg = val;
5556 inst.operands[i].isreg = 1;
5557 inst.operands[i].present = 1;
5558 }
037e8744 5559 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5560 != FAIL)
5287ad62
JB
5561 {
5562 /* Cases 0, 1, 2, 3, 5 (D only). */
5563 if (skip_past_comma (&ptr) == FAIL)
5564 goto wanted_comma;
5f4273c7 5565
5287ad62
JB
5566 inst.operands[i].reg = val;
5567 inst.operands[i].isreg = 1;
5568 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5569 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5570 inst.operands[i].isvec = 1;
dcbf9037 5571 inst.operands[i].vectype = optype;
5287ad62
JB
5572 inst.operands[i++].present = 1;
5573
dcbf9037 5574 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5575 {
037e8744
JB
5576 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5577 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5578 inst.operands[i].reg = val;
5579 inst.operands[i].isreg = 1;
037e8744 5580 inst.operands[i].present = 1;
5287ad62
JB
5581
5582 if (rtype == REG_TYPE_NQ)
5583 {
dcbf9037 5584 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5585 return FAIL;
5586 }
037e8744
JB
5587 else if (rtype != REG_TYPE_VFS)
5588 {
5589 i++;
5590 if (skip_past_comma (&ptr) == FAIL)
5591 goto wanted_comma;
5592 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5593 goto wanted_arm;
5594 inst.operands[i].reg = val;
5595 inst.operands[i].isreg = 1;
5596 inst.operands[i].present = 1;
5597 }
5287ad62 5598 }
037e8744
JB
5599 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5600 &optype)) != FAIL)
5287ad62
JB
5601 {
5602 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5603 Case 1: VMOV<c><q> <Dd>, <Dm>
5604 Case 8: VMOV.F32 <Sd>, <Sm>
5605 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5606
5607 inst.operands[i].reg = val;
5608 inst.operands[i].isreg = 1;
5609 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5610 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5611 inst.operands[i].isvec = 1;
dcbf9037 5612 inst.operands[i].vectype = optype;
5287ad62 5613 inst.operands[i].present = 1;
5f4273c7 5614
037e8744
JB
5615 if (skip_past_comma (&ptr) == SUCCESS)
5616 {
5617 /* Case 15. */
5618 i++;
5619
5620 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5621 goto wanted_arm;
5622
5623 inst.operands[i].reg = val;
5624 inst.operands[i].isreg = 1;
5625 inst.operands[i++].present = 1;
5f4273c7 5626
037e8744
JB
5627 if (skip_past_comma (&ptr) == FAIL)
5628 goto wanted_comma;
5f4273c7 5629
037e8744
JB
5630 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5631 goto wanted_arm;
5f4273c7 5632
037e8744
JB
5633 inst.operands[i].reg = val;
5634 inst.operands[i].isreg = 1;
5635 inst.operands[i++].present = 1;
5636 }
5287ad62 5637 }
4641781c
PB
5638 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5639 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5640 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5641 Case 10: VMOV.F32 <Sd>, #<imm>
5642 Case 11: VMOV.F64 <Dd>, #<imm> */
5643 inst.operands[i].immisfloat = 1;
5644 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5645 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5646 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5647 ;
5287ad62
JB
5648 else
5649 {
dcbf9037 5650 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5651 return FAIL;
5652 }
5653 }
dcbf9037 5654 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5655 {
5656 /* Cases 6, 7. */
5657 inst.operands[i].reg = val;
5658 inst.operands[i].isreg = 1;
5659 inst.operands[i++].present = 1;
5f4273c7 5660
5287ad62
JB
5661 if (skip_past_comma (&ptr) == FAIL)
5662 goto wanted_comma;
5f4273c7 5663
dcbf9037 5664 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5665 {
5666 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5667 inst.operands[i].reg = val;
5668 inst.operands[i].isscalar = 1;
5669 inst.operands[i].present = 1;
dcbf9037 5670 inst.operands[i].vectype = optype;
5287ad62 5671 }
dcbf9037 5672 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5673 {
5674 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5675 inst.operands[i].reg = val;
5676 inst.operands[i].isreg = 1;
5677 inst.operands[i++].present = 1;
5f4273c7 5678
5287ad62
JB
5679 if (skip_past_comma (&ptr) == FAIL)
5680 goto wanted_comma;
5f4273c7 5681
037e8744 5682 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5683 == FAIL)
5287ad62 5684 {
037e8744 5685 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5686 return FAIL;
5687 }
5688
5689 inst.operands[i].reg = val;
5690 inst.operands[i].isreg = 1;
037e8744
JB
5691 inst.operands[i].isvec = 1;
5692 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5693 inst.operands[i].vectype = optype;
5287ad62 5694 inst.operands[i].present = 1;
5f4273c7 5695
037e8744
JB
5696 if (rtype == REG_TYPE_VFS)
5697 {
5698 /* Case 14. */
5699 i++;
5700 if (skip_past_comma (&ptr) == FAIL)
5701 goto wanted_comma;
5702 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5703 &optype)) == FAIL)
5704 {
5705 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5706 return FAIL;
5707 }
5708 inst.operands[i].reg = val;
5709 inst.operands[i].isreg = 1;
5710 inst.operands[i].isvec = 1;
5711 inst.operands[i].issingle = 1;
5712 inst.operands[i].vectype = optype;
5713 inst.operands[i].present = 1;
5714 }
5715 }
5716 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5717 != FAIL)
5718 {
5719 /* Case 13. */
5720 inst.operands[i].reg = val;
5721 inst.operands[i].isreg = 1;
5722 inst.operands[i].isvec = 1;
5723 inst.operands[i].issingle = 1;
5724 inst.operands[i].vectype = optype;
5725 inst.operands[i++].present = 1;
5287ad62
JB
5726 }
5727 }
5728 else
5729 {
dcbf9037 5730 first_error (_("parse error"));
5287ad62
JB
5731 return FAIL;
5732 }
5733
5734 /* Successfully parsed the operands. Update args. */
5735 *which_operand = i;
5736 *str = ptr;
5737 return SUCCESS;
5738
5f4273c7 5739 wanted_comma:
dcbf9037 5740 first_error (_("expected comma"));
5287ad62 5741 return FAIL;
5f4273c7
NC
5742
5743 wanted_arm:
dcbf9037 5744 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5745 return FAIL;
5287ad62
JB
5746}
5747
5be8be5d
DG
5748/* Use this macro when the operand constraints are different
5749 for ARM and THUMB (e.g. ldrd). */
5750#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5751 ((arm_operand) | ((thumb_operand) << 16))
5752
c19d1205
ZW
5753/* Matcher codes for parse_operands. */
5754enum operand_parse_code
5755{
5756 OP_stop, /* end of line */
5757
5758 OP_RR, /* ARM register */
5759 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5760 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205
ZW
5761 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5762 OP_RRw, /* ARM register, not r15, optional trailing ! */
5763 OP_RCP, /* Coprocessor number */
5764 OP_RCN, /* Coprocessor register */
5765 OP_RF, /* FPA register */
5766 OP_RVS, /* VFP single precision register */
5287ad62
JB
5767 OP_RVD, /* VFP double precision register (0..15) */
5768 OP_RND, /* Neon double precision register (0..31) */
5769 OP_RNQ, /* Neon quad precision register */
037e8744 5770 OP_RVSD, /* VFP single or double precision register */
5287ad62 5771 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5772 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5773 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5774 OP_RVC, /* VFP control register */
5775 OP_RMF, /* Maverick F register */
5776 OP_RMD, /* Maverick D register */
5777 OP_RMFX, /* Maverick FX register */
5778 OP_RMDX, /* Maverick DX register */
5779 OP_RMAX, /* Maverick AX register */
5780 OP_RMDS, /* Maverick DSPSC register */
5781 OP_RIWR, /* iWMMXt wR register */
5782 OP_RIWC, /* iWMMXt wC register */
5783 OP_RIWG, /* iWMMXt wCG register */
5784 OP_RXA, /* XScale accumulator register */
5785
5786 OP_REGLST, /* ARM register list */
5787 OP_VRSLST, /* VFP single-precision register list */
5788 OP_VRDLST, /* VFP double-precision register list */
037e8744 5789 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5790 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5791 OP_NSTRLST, /* Neon element/structure list */
5792
5287ad62 5793 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5794 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5795 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5796 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5797 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5798 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5799 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5800 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5801 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5802 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5803
5804 OP_I0, /* immediate zero */
c19d1205
ZW
5805 OP_I7, /* immediate value 0 .. 7 */
5806 OP_I15, /* 0 .. 15 */
5807 OP_I16, /* 1 .. 16 */
5287ad62 5808 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5809 OP_I31, /* 0 .. 31 */
5810 OP_I31w, /* 0 .. 31, optional trailing ! */
5811 OP_I32, /* 1 .. 32 */
5287ad62
JB
5812 OP_I32z, /* 0 .. 32 */
5813 OP_I63, /* 0 .. 63 */
c19d1205 5814 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5815 OP_I64, /* 1 .. 64 */
5816 OP_I64z, /* 0 .. 64 */
c19d1205 5817 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5818
5819 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5820 OP_I7b, /* 0 .. 7 */
5821 OP_I15b, /* 0 .. 15 */
5822 OP_I31b, /* 0 .. 31 */
5823
5824 OP_SH, /* shifter operand */
4962c51a 5825 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5826 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5827 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5828 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5829 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5830 OP_EXP, /* arbitrary expression */
5831 OP_EXPi, /* same, with optional immediate prefix */
5832 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5833 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5834
5835 OP_CPSF, /* CPS flags */
5836 OP_ENDI, /* Endianness specifier */
5837 OP_PSR, /* CPSR/SPSR mask for msr */
5838 OP_COND, /* conditional code */
92e90b6e 5839 OP_TB, /* Table branch. */
c19d1205 5840
037e8744
JB
5841 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5842 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5843
c19d1205
ZW
5844 OP_RRnpc_I0, /* ARM register or literal 0 */
5845 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5846 OP_RR_EXi, /* ARM register or expression with imm prefix */
5847 OP_RF_IF, /* FPA register or immediate */
5848 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5849 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5850
5851 /* Optional operands. */
5852 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5853 OP_oI31b, /* 0 .. 31 */
5287ad62 5854 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5855 OP_oIffffb, /* 0 .. 65535 */
5856 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5857
5858 OP_oRR, /* ARM register */
5859 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5860 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5861 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5862 OP_oRND, /* Optional Neon double precision register */
5863 OP_oRNQ, /* Optional Neon quad precision register */
5864 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5865 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5866 OP_oSHll, /* LSL immediate */
5867 OP_oSHar, /* ASR immediate */
5868 OP_oSHllar, /* LSL or ASR immediate */
5869 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5870 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205 5871
5be8be5d
DG
5872 /* Some pre-defined mixed (ARM/THUMB) operands. */
5873 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5874 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5875 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5876
c19d1205
ZW
5877 OP_FIRST_OPTIONAL = OP_oI7b
5878};
a737bd4d 5879
c19d1205
ZW
5880/* Generic instruction operand parser. This does no encoding and no
5881 semantic validation; it merely squirrels values away in the inst
5882 structure. Returns SUCCESS or FAIL depending on whether the
5883 specified grammar matched. */
5884static int
5be8be5d 5885parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5886{
5be8be5d 5887 unsigned const int *upat = pattern;
c19d1205
ZW
5888 char *backtrack_pos = 0;
5889 const char *backtrack_error = 0;
5890 int i, val, backtrack_index = 0;
5287ad62 5891 enum arm_reg_type rtype;
4962c51a 5892 parse_operand_result result;
5be8be5d 5893 unsigned int op_parse_code;
c19d1205 5894
e07e6e58
NC
5895#define po_char_or_fail(chr) \
5896 do \
5897 { \
5898 if (skip_past_char (&str, chr) == FAIL) \
5899 goto bad_args; \
5900 } \
5901 while (0)
c19d1205 5902
e07e6e58
NC
5903#define po_reg_or_fail(regtype) \
5904 do \
dcbf9037 5905 { \
e07e6e58
NC
5906 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5907 & inst.operands[i].vectype); \
5908 if (val == FAIL) \
5909 { \
5910 first_error (_(reg_expected_msgs[regtype])); \
5911 goto failure; \
5912 } \
5913 inst.operands[i].reg = val; \
5914 inst.operands[i].isreg = 1; \
5915 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5916 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5917 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5918 || rtype == REG_TYPE_VFD \
5919 || rtype == REG_TYPE_NQ); \
dcbf9037 5920 } \
e07e6e58
NC
5921 while (0)
5922
5923#define po_reg_or_goto(regtype, label) \
5924 do \
5925 { \
5926 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5927 & inst.operands[i].vectype); \
5928 if (val == FAIL) \
5929 goto label; \
dcbf9037 5930 \
e07e6e58
NC
5931 inst.operands[i].reg = val; \
5932 inst.operands[i].isreg = 1; \
5933 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5934 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5935 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5936 || rtype == REG_TYPE_VFD \
5937 || rtype == REG_TYPE_NQ); \
5938 } \
5939 while (0)
5940
5941#define po_imm_or_fail(min, max, popt) \
5942 do \
5943 { \
5944 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5945 goto failure; \
5946 inst.operands[i].imm = val; \
5947 } \
5948 while (0)
5949
5950#define po_scalar_or_goto(elsz, label) \
5951 do \
5952 { \
5953 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5954 if (val == FAIL) \
5955 goto label; \
5956 inst.operands[i].reg = val; \
5957 inst.operands[i].isscalar = 1; \
5958 } \
5959 while (0)
5960
5961#define po_misc_or_fail(expr) \
5962 do \
5963 { \
5964 if (expr) \
5965 goto failure; \
5966 } \
5967 while (0)
5968
5969#define po_misc_or_fail_no_backtrack(expr) \
5970 do \
5971 { \
5972 result = expr; \
5973 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5974 backtrack_pos = 0; \
5975 if (result != PARSE_OPERAND_SUCCESS) \
5976 goto failure; \
5977 } \
5978 while (0)
4962c51a 5979
c19d1205
ZW
5980 skip_whitespace (str);
5981
5982 for (i = 0; upat[i] != OP_stop; i++)
5983 {
5be8be5d
DG
5984 op_parse_code = upat[i];
5985 if (op_parse_code >= 1<<16)
5986 op_parse_code = thumb ? (op_parse_code >> 16)
5987 : (op_parse_code & ((1<<16)-1));
5988
5989 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
5990 {
5991 /* Remember where we are in case we need to backtrack. */
9c2799c2 5992 gas_assert (!backtrack_pos);
c19d1205
ZW
5993 backtrack_pos = str;
5994 backtrack_error = inst.error;
5995 backtrack_index = i;
5996 }
5997
b6702015 5998 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5999 po_char_or_fail (',');
6000
5be8be5d 6001 switch (op_parse_code)
c19d1205
ZW
6002 {
6003 /* Registers */
6004 case OP_oRRnpc:
5be8be5d 6005 case OP_oRRnpcsp:
c19d1205 6006 case OP_RRnpc:
5be8be5d 6007 case OP_RRnpcsp:
c19d1205
ZW
6008 case OP_oRR:
6009 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6010 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6011 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6012 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6013 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6014 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6015 case OP_oRND:
6016 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6017 case OP_RVC:
6018 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6019 break;
6020 /* Also accept generic coprocessor regs for unknown registers. */
6021 coproc_reg:
6022 po_reg_or_fail (REG_TYPE_CN);
6023 break;
c19d1205
ZW
6024 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6025 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6026 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6027 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6028 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6029 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6030 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6031 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6032 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6033 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6034 case OP_oRNQ:
6035 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6036 case OP_oRNDQ:
6037 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6038 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6039 case OP_oRNSDQ:
6040 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6041
6042 /* Neon scalar. Using an element size of 8 means that some invalid
6043 scalars are accepted here, so deal with those in later code. */
6044 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6045
5287ad62
JB
6046 case OP_RNDQ_I0:
6047 {
6048 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6049 break;
6050 try_imm0:
6051 po_imm_or_fail (0, 0, TRUE);
6052 }
6053 break;
6054
037e8744
JB
6055 case OP_RVSD_I0:
6056 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6057 break;
6058
5287ad62
JB
6059 case OP_RR_RNSC:
6060 {
6061 po_scalar_or_goto (8, try_rr);
6062 break;
6063 try_rr:
6064 po_reg_or_fail (REG_TYPE_RN);
6065 }
6066 break;
6067
037e8744
JB
6068 case OP_RNSDQ_RNSC:
6069 {
6070 po_scalar_or_goto (8, try_nsdq);
6071 break;
6072 try_nsdq:
6073 po_reg_or_fail (REG_TYPE_NSDQ);
6074 }
6075 break;
6076
5287ad62
JB
6077 case OP_RNDQ_RNSC:
6078 {
6079 po_scalar_or_goto (8, try_ndq);
6080 break;
6081 try_ndq:
6082 po_reg_or_fail (REG_TYPE_NDQ);
6083 }
6084 break;
6085
6086 case OP_RND_RNSC:
6087 {
6088 po_scalar_or_goto (8, try_vfd);
6089 break;
6090 try_vfd:
6091 po_reg_or_fail (REG_TYPE_VFD);
6092 }
6093 break;
6094
6095 case OP_VMOV:
6096 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6097 not careful then bad things might happen. */
6098 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6099 break;
6100
4316f0d2 6101 case OP_RNDQ_Ibig:
5287ad62 6102 {
4316f0d2 6103 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6104 break;
4316f0d2 6105 try_immbig:
5287ad62
JB
6106 /* There's a possibility of getting a 64-bit immediate here, so
6107 we need special handling. */
6108 if (parse_big_immediate (&str, i) == FAIL)
6109 {
6110 inst.error = _("immediate value is out of range");
6111 goto failure;
6112 }
6113 }
6114 break;
6115
6116 case OP_RNDQ_I63b:
6117 {
6118 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6119 break;
6120 try_shimm:
6121 po_imm_or_fail (0, 63, TRUE);
6122 }
6123 break;
c19d1205
ZW
6124
6125 case OP_RRnpcb:
6126 po_char_or_fail ('[');
6127 po_reg_or_fail (REG_TYPE_RN);
6128 po_char_or_fail (']');
6129 break;
a737bd4d 6130
c19d1205 6131 case OP_RRw:
b6702015 6132 case OP_oRRw:
c19d1205
ZW
6133 po_reg_or_fail (REG_TYPE_RN);
6134 if (skip_past_char (&str, '!') == SUCCESS)
6135 inst.operands[i].writeback = 1;
6136 break;
6137
6138 /* Immediates */
6139 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6140 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6141 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6142 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6143 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6144 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6145 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6146 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6147 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6148 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6149 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6150 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6151
6152 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6153 case OP_oI7b:
6154 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6155 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6156 case OP_oI31b:
6157 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6158 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6159 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6160
6161 /* Immediate variants */
6162 case OP_oI255c:
6163 po_char_or_fail ('{');
6164 po_imm_or_fail (0, 255, TRUE);
6165 po_char_or_fail ('}');
6166 break;
6167
6168 case OP_I31w:
6169 /* The expression parser chokes on a trailing !, so we have
6170 to find it first and zap it. */
6171 {
6172 char *s = str;
6173 while (*s && *s != ',')
6174 s++;
6175 if (s[-1] == '!')
6176 {
6177 s[-1] = '\0';
6178 inst.operands[i].writeback = 1;
6179 }
6180 po_imm_or_fail (0, 31, TRUE);
6181 if (str == s - 1)
6182 str = s;
6183 }
6184 break;
6185
6186 /* Expressions */
6187 case OP_EXPi: EXPi:
6188 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6189 GE_OPT_PREFIX));
6190 break;
6191
6192 case OP_EXP:
6193 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6194 GE_NO_PREFIX));
6195 break;
6196
6197 case OP_EXPr: EXPr:
6198 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6199 GE_NO_PREFIX));
6200 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6201 {
c19d1205
ZW
6202 val = parse_reloc (&str);
6203 if (val == -1)
6204 {
6205 inst.error = _("unrecognized relocation suffix");
6206 goto failure;
6207 }
6208 else if (val != BFD_RELOC_UNUSED)
6209 {
6210 inst.operands[i].imm = val;
6211 inst.operands[i].hasreloc = 1;
6212 }
a737bd4d 6213 }
c19d1205 6214 break;
a737bd4d 6215
b6895b4f
PB
6216 /* Operand for MOVW or MOVT. */
6217 case OP_HALF:
6218 po_misc_or_fail (parse_half (&str));
6219 break;
6220
e07e6e58 6221 /* Register or expression. */
c19d1205
ZW
6222 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6223 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6224
e07e6e58 6225 /* Register or immediate. */
c19d1205
ZW
6226 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6227 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6228
c19d1205
ZW
6229 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6230 IF:
6231 if (!is_immediate_prefix (*str))
6232 goto bad_args;
6233 str++;
6234 val = parse_fpa_immediate (&str);
6235 if (val == FAIL)
6236 goto failure;
6237 /* FPA immediates are encoded as registers 8-15.
6238 parse_fpa_immediate has already applied the offset. */
6239 inst.operands[i].reg = val;
6240 inst.operands[i].isreg = 1;
6241 break;
09d92015 6242
2d447fca
JM
6243 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6244 I32z: po_imm_or_fail (0, 32, FALSE); break;
6245
e07e6e58 6246 /* Two kinds of register. */
c19d1205
ZW
6247 case OP_RIWR_RIWC:
6248 {
6249 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6250 if (!rege
6251 || (rege->type != REG_TYPE_MMXWR
6252 && rege->type != REG_TYPE_MMXWC
6253 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6254 {
6255 inst.error = _("iWMMXt data or control register expected");
6256 goto failure;
6257 }
6258 inst.operands[i].reg = rege->number;
6259 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6260 }
6261 break;
09d92015 6262
41adaa5c
JM
6263 case OP_RIWC_RIWG:
6264 {
6265 struct reg_entry *rege = arm_reg_parse_multi (&str);
6266 if (!rege
6267 || (rege->type != REG_TYPE_MMXWC
6268 && rege->type != REG_TYPE_MMXWCG))
6269 {
6270 inst.error = _("iWMMXt control register expected");
6271 goto failure;
6272 }
6273 inst.operands[i].reg = rege->number;
6274 inst.operands[i].isreg = 1;
6275 }
6276 break;
6277
c19d1205
ZW
6278 /* Misc */
6279 case OP_CPSF: val = parse_cps_flags (&str); break;
6280 case OP_ENDI: val = parse_endian_specifier (&str); break;
6281 case OP_oROR: val = parse_ror (&str); break;
6282 case OP_PSR: val = parse_psr (&str); break;
6283 case OP_COND: val = parse_cond (&str); break;
62b3e311 6284 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6285
037e8744
JB
6286 case OP_RVC_PSR:
6287 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6288 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6289 break;
6290 try_psr:
6291 val = parse_psr (&str);
6292 break;
6293
6294 case OP_APSR_RR:
6295 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6296 break;
6297 try_apsr:
6298 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6299 instruction). */
6300 if (strncasecmp (str, "APSR_", 5) == 0)
6301 {
6302 unsigned found = 0;
6303 str += 5;
6304 while (found < 15)
6305 switch (*str++)
6306 {
6307 case 'c': found = (found & 1) ? 16 : found | 1; break;
6308 case 'n': found = (found & 2) ? 16 : found | 2; break;
6309 case 'z': found = (found & 4) ? 16 : found | 4; break;
6310 case 'v': found = (found & 8) ? 16 : found | 8; break;
6311 default: found = 16;
6312 }
6313 if (found != 15)
6314 goto failure;
6315 inst.operands[i].isvec = 1;
f7c21dc7
NC
6316 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6317 inst.operands[i].reg = REG_PC;
037e8744
JB
6318 }
6319 else
6320 goto failure;
6321 break;
6322
92e90b6e
PB
6323 case OP_TB:
6324 po_misc_or_fail (parse_tb (&str));
6325 break;
6326
e07e6e58 6327 /* Register lists. */
c19d1205
ZW
6328 case OP_REGLST:
6329 val = parse_reg_list (&str);
6330 if (*str == '^')
6331 {
6332 inst.operands[1].writeback = 1;
6333 str++;
6334 }
6335 break;
09d92015 6336
c19d1205 6337 case OP_VRSLST:
5287ad62 6338 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6339 break;
09d92015 6340
c19d1205 6341 case OP_VRDLST:
5287ad62 6342 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6343 break;
a737bd4d 6344
037e8744
JB
6345 case OP_VRSDLST:
6346 /* Allow Q registers too. */
6347 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6348 REGLIST_NEON_D);
6349 if (val == FAIL)
6350 {
6351 inst.error = NULL;
6352 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6353 REGLIST_VFP_S);
6354 inst.operands[i].issingle = 1;
6355 }
6356 break;
6357
5287ad62
JB
6358 case OP_NRDLST:
6359 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6360 REGLIST_NEON_D);
6361 break;
6362
6363 case OP_NSTRLST:
dcbf9037
JB
6364 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6365 &inst.operands[i].vectype);
5287ad62
JB
6366 break;
6367
c19d1205
ZW
6368 /* Addressing modes */
6369 case OP_ADDR:
6370 po_misc_or_fail (parse_address (&str, i));
6371 break;
09d92015 6372
4962c51a
MS
6373 case OP_ADDRGLDR:
6374 po_misc_or_fail_no_backtrack (
6375 parse_address_group_reloc (&str, i, GROUP_LDR));
6376 break;
6377
6378 case OP_ADDRGLDRS:
6379 po_misc_or_fail_no_backtrack (
6380 parse_address_group_reloc (&str, i, GROUP_LDRS));
6381 break;
6382
6383 case OP_ADDRGLDC:
6384 po_misc_or_fail_no_backtrack (
6385 parse_address_group_reloc (&str, i, GROUP_LDC));
6386 break;
6387
c19d1205
ZW
6388 case OP_SH:
6389 po_misc_or_fail (parse_shifter_operand (&str, i));
6390 break;
09d92015 6391
4962c51a
MS
6392 case OP_SHG:
6393 po_misc_or_fail_no_backtrack (
6394 parse_shifter_operand_group_reloc (&str, i));
6395 break;
6396
c19d1205
ZW
6397 case OP_oSHll:
6398 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6399 break;
09d92015 6400
c19d1205
ZW
6401 case OP_oSHar:
6402 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6403 break;
09d92015 6404
c19d1205
ZW
6405 case OP_oSHllar:
6406 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6407 break;
09d92015 6408
c19d1205 6409 default:
5be8be5d 6410 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6411 }
09d92015 6412
c19d1205
ZW
6413 /* Various value-based sanity checks and shared operations. We
6414 do not signal immediate failures for the register constraints;
6415 this allows a syntax error to take precedence. */
5be8be5d 6416 switch (op_parse_code)
c19d1205
ZW
6417 {
6418 case OP_oRRnpc:
6419 case OP_RRnpc:
6420 case OP_RRnpcb:
6421 case OP_RRw:
b6702015 6422 case OP_oRRw:
c19d1205
ZW
6423 case OP_RRnpc_I0:
6424 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6425 inst.error = BAD_PC;
6426 break;
09d92015 6427
5be8be5d
DG
6428 case OP_oRRnpcsp:
6429 case OP_RRnpcsp:
6430 if (inst.operands[i].isreg)
6431 {
6432 if (inst.operands[i].reg == REG_PC)
6433 inst.error = BAD_PC;
6434 else if (inst.operands[i].reg == REG_SP)
6435 inst.error = BAD_SP;
6436 }
6437 break;
6438
c19d1205
ZW
6439 case OP_CPSF:
6440 case OP_ENDI:
6441 case OP_oROR:
6442 case OP_PSR:
037e8744 6443 case OP_RVC_PSR:
c19d1205 6444 case OP_COND:
62b3e311 6445 case OP_oBARRIER:
c19d1205
ZW
6446 case OP_REGLST:
6447 case OP_VRSLST:
6448 case OP_VRDLST:
037e8744 6449 case OP_VRSDLST:
5287ad62
JB
6450 case OP_NRDLST:
6451 case OP_NSTRLST:
c19d1205
ZW
6452 if (val == FAIL)
6453 goto failure;
6454 inst.operands[i].imm = val;
6455 break;
a737bd4d 6456
c19d1205
ZW
6457 default:
6458 break;
6459 }
09d92015 6460
c19d1205
ZW
6461 /* If we get here, this operand was successfully parsed. */
6462 inst.operands[i].present = 1;
6463 continue;
09d92015 6464
c19d1205 6465 bad_args:
09d92015 6466 inst.error = BAD_ARGS;
c19d1205
ZW
6467
6468 failure:
6469 if (!backtrack_pos)
d252fdde
PB
6470 {
6471 /* The parse routine should already have set inst.error, but set a
5f4273c7 6472 default here just in case. */
d252fdde
PB
6473 if (!inst.error)
6474 inst.error = _("syntax error");
6475 return FAIL;
6476 }
c19d1205
ZW
6477
6478 /* Do not backtrack over a trailing optional argument that
6479 absorbed some text. We will only fail again, with the
6480 'garbage following instruction' error message, which is
6481 probably less helpful than the current one. */
6482 if (backtrack_index == i && backtrack_pos != str
6483 && upat[i+1] == OP_stop)
d252fdde
PB
6484 {
6485 if (!inst.error)
6486 inst.error = _("syntax error");
6487 return FAIL;
6488 }
c19d1205
ZW
6489
6490 /* Try again, skipping the optional argument at backtrack_pos. */
6491 str = backtrack_pos;
6492 inst.error = backtrack_error;
6493 inst.operands[backtrack_index].present = 0;
6494 i = backtrack_index;
6495 backtrack_pos = 0;
09d92015 6496 }
09d92015 6497
c19d1205
ZW
6498 /* Check that we have parsed all the arguments. */
6499 if (*str != '\0' && !inst.error)
6500 inst.error = _("garbage following instruction");
09d92015 6501
c19d1205 6502 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6503}
6504
c19d1205
ZW
6505#undef po_char_or_fail
6506#undef po_reg_or_fail
6507#undef po_reg_or_goto
6508#undef po_imm_or_fail
5287ad62 6509#undef po_scalar_or_fail
e07e6e58 6510
c19d1205 6511/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6512#define constraint(expr, err) \
6513 do \
c19d1205 6514 { \
e07e6e58
NC
6515 if (expr) \
6516 { \
6517 inst.error = err; \
6518 return; \
6519 } \
c19d1205 6520 } \
e07e6e58 6521 while (0)
c19d1205 6522
fdfde340
JM
6523/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6524 instructions are unpredictable if these registers are used. This
6525 is the BadReg predicate in ARM's Thumb-2 documentation. */
6526#define reject_bad_reg(reg) \
6527 do \
6528 if (reg == REG_SP || reg == REG_PC) \
6529 { \
6530 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6531 return; \
6532 } \
6533 while (0)
6534
94206790
MM
6535/* If REG is R13 (the stack pointer), warn that its use is
6536 deprecated. */
6537#define warn_deprecated_sp(reg) \
6538 do \
6539 if (warn_on_deprecated && reg == REG_SP) \
6540 as_warn (_("use of r13 is deprecated")); \
6541 while (0)
6542
c19d1205
ZW
6543/* Functions for operand encoding. ARM, then Thumb. */
6544
6545#define rotate_left(v, n) (v << n | v >> (32 - n))
6546
6547/* If VAL can be encoded in the immediate field of an ARM instruction,
6548 return the encoded form. Otherwise, return FAIL. */
6549
6550static unsigned int
6551encode_arm_immediate (unsigned int val)
09d92015 6552{
c19d1205
ZW
6553 unsigned int a, i;
6554
6555 for (i = 0; i < 32; i += 2)
6556 if ((a = rotate_left (val, i)) <= 0xff)
6557 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6558
6559 return FAIL;
09d92015
MM
6560}
6561
c19d1205
ZW
6562/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6563 return the encoded form. Otherwise, return FAIL. */
6564static unsigned int
6565encode_thumb32_immediate (unsigned int val)
09d92015 6566{
c19d1205 6567 unsigned int a, i;
09d92015 6568
9c3c69f2 6569 if (val <= 0xff)
c19d1205 6570 return val;
a737bd4d 6571
9c3c69f2 6572 for (i = 1; i <= 24; i++)
09d92015 6573 {
9c3c69f2
PB
6574 a = val >> i;
6575 if ((val & ~(0xff << i)) == 0)
6576 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6577 }
a737bd4d 6578
c19d1205
ZW
6579 a = val & 0xff;
6580 if (val == ((a << 16) | a))
6581 return 0x100 | a;
6582 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6583 return 0x300 | a;
09d92015 6584
c19d1205
ZW
6585 a = val & 0xff00;
6586 if (val == ((a << 16) | a))
6587 return 0x200 | (a >> 8);
a737bd4d 6588
c19d1205 6589 return FAIL;
09d92015 6590}
5287ad62 6591/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6592
6593static void
5287ad62
JB
6594encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6595{
6596 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6597 && reg > 15)
6598 {
b1cc4aeb 6599 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6600 {
6601 if (thumb_mode)
6602 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6603 fpu_vfp_ext_d32);
5287ad62
JB
6604 else
6605 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6606 fpu_vfp_ext_d32);
5287ad62
JB
6607 }
6608 else
6609 {
dcbf9037 6610 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6611 return;
6612 }
6613 }
6614
c19d1205 6615 switch (pos)
09d92015 6616 {
c19d1205
ZW
6617 case VFP_REG_Sd:
6618 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6619 break;
6620
6621 case VFP_REG_Sn:
6622 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6623 break;
6624
6625 case VFP_REG_Sm:
6626 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6627 break;
6628
5287ad62
JB
6629 case VFP_REG_Dd:
6630 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6631 break;
5f4273c7 6632
5287ad62
JB
6633 case VFP_REG_Dn:
6634 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6635 break;
5f4273c7 6636
5287ad62
JB
6637 case VFP_REG_Dm:
6638 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6639 break;
6640
c19d1205
ZW
6641 default:
6642 abort ();
09d92015 6643 }
09d92015
MM
6644}
6645
c19d1205 6646/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6647 if any, is handled by md_apply_fix. */
09d92015 6648static void
c19d1205 6649encode_arm_shift (int i)
09d92015 6650{
c19d1205
ZW
6651 if (inst.operands[i].shift_kind == SHIFT_RRX)
6652 inst.instruction |= SHIFT_ROR << 5;
6653 else
09d92015 6654 {
c19d1205
ZW
6655 inst.instruction |= inst.operands[i].shift_kind << 5;
6656 if (inst.operands[i].immisreg)
6657 {
6658 inst.instruction |= SHIFT_BY_REG;
6659 inst.instruction |= inst.operands[i].imm << 8;
6660 }
6661 else
6662 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6663 }
c19d1205 6664}
09d92015 6665
c19d1205
ZW
6666static void
6667encode_arm_shifter_operand (int i)
6668{
6669 if (inst.operands[i].isreg)
09d92015 6670 {
c19d1205
ZW
6671 inst.instruction |= inst.operands[i].reg;
6672 encode_arm_shift (i);
09d92015 6673 }
c19d1205
ZW
6674 else
6675 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6676}
6677
c19d1205 6678/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6679static void
c19d1205 6680encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6681{
9c2799c2 6682 gas_assert (inst.operands[i].isreg);
c19d1205 6683 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6684
c19d1205 6685 if (inst.operands[i].preind)
09d92015 6686 {
c19d1205
ZW
6687 if (is_t)
6688 {
6689 inst.error = _("instruction does not accept preindexed addressing");
6690 return;
6691 }
6692 inst.instruction |= PRE_INDEX;
6693 if (inst.operands[i].writeback)
6694 inst.instruction |= WRITE_BACK;
09d92015 6695
c19d1205
ZW
6696 }
6697 else if (inst.operands[i].postind)
6698 {
9c2799c2 6699 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6700 if (is_t)
6701 inst.instruction |= WRITE_BACK;
6702 }
6703 else /* unindexed - only for coprocessor */
09d92015 6704 {
c19d1205 6705 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6706 return;
6707 }
6708
c19d1205
ZW
6709 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6710 && (((inst.instruction & 0x000f0000) >> 16)
6711 == ((inst.instruction & 0x0000f000) >> 12)))
6712 as_warn ((inst.instruction & LOAD_BIT)
6713 ? _("destination register same as write-back base")
6714 : _("source register same as write-back base"));
09d92015
MM
6715}
6716
c19d1205
ZW
6717/* inst.operands[i] was set up by parse_address. Encode it into an
6718 ARM-format mode 2 load or store instruction. If is_t is true,
6719 reject forms that cannot be used with a T instruction (i.e. not
6720 post-indexed). */
a737bd4d 6721static void
c19d1205 6722encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6723{
5be8be5d
DG
6724 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6725
c19d1205 6726 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6727
c19d1205 6728 if (inst.operands[i].immisreg)
09d92015 6729 {
5be8be5d
DG
6730 constraint ((inst.operands[i].imm == REG_PC
6731 || (is_pc && inst.operands[i].writeback)),
6732 BAD_PC_ADDRESSING);
c19d1205
ZW
6733 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6734 inst.instruction |= inst.operands[i].imm;
6735 if (!inst.operands[i].negative)
6736 inst.instruction |= INDEX_UP;
6737 if (inst.operands[i].shifted)
6738 {
6739 if (inst.operands[i].shift_kind == SHIFT_RRX)
6740 inst.instruction |= SHIFT_ROR << 5;
6741 else
6742 {
6743 inst.instruction |= inst.operands[i].shift_kind << 5;
6744 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6745 }
6746 }
09d92015 6747 }
c19d1205 6748 else /* immediate offset in inst.reloc */
09d92015 6749 {
5be8be5d
DG
6750 if (is_pc && !inst.reloc.pc_rel)
6751 {
6752 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6753 /* BAD_PC_ADDRESSING Condition =
6754 is_load => is_t
6755 which becomes !is_load || is_t. */
6756 constraint ((!is_load || is_t),
6757 BAD_PC_ADDRESSING);
6758 }
6759
c19d1205
ZW
6760 if (inst.reloc.type == BFD_RELOC_UNUSED)
6761 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6762 }
09d92015
MM
6763}
6764
c19d1205
ZW
6765/* inst.operands[i] was set up by parse_address. Encode it into an
6766 ARM-format mode 3 load or store instruction. Reject forms that
6767 cannot be used with such instructions. If is_t is true, reject
6768 forms that cannot be used with a T instruction (i.e. not
6769 post-indexed). */
6770static void
6771encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6772{
c19d1205 6773 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6774 {
c19d1205
ZW
6775 inst.error = _("instruction does not accept scaled register index");
6776 return;
09d92015 6777 }
a737bd4d 6778
c19d1205 6779 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6780
c19d1205
ZW
6781 if (inst.operands[i].immisreg)
6782 {
5be8be5d
DG
6783 constraint ((inst.operands[i].imm == REG_PC
6784 || inst.operands[i].reg == REG_PC),
6785 BAD_PC_ADDRESSING);
c19d1205
ZW
6786 inst.instruction |= inst.operands[i].imm;
6787 if (!inst.operands[i].negative)
6788 inst.instruction |= INDEX_UP;
6789 }
6790 else /* immediate offset in inst.reloc */
6791 {
5be8be5d
DG
6792 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6793 && inst.operands[i].writeback),
6794 BAD_PC_WRITEBACK);
c19d1205
ZW
6795 inst.instruction |= HWOFFSET_IMM;
6796 if (inst.reloc.type == BFD_RELOC_UNUSED)
6797 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6798 }
a737bd4d
NC
6799}
6800
c19d1205
ZW
6801/* inst.operands[i] was set up by parse_address. Encode it into an
6802 ARM-format instruction. Reject all forms which cannot be encoded
6803 into a coprocessor load/store instruction. If wb_ok is false,
6804 reject use of writeback; if unind_ok is false, reject use of
6805 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6806 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6807 (in which case it is preserved). */
09d92015 6808
c19d1205
ZW
6809static int
6810encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6811{
c19d1205 6812 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6813
9c2799c2 6814 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6815
c19d1205 6816 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6817 {
9c2799c2 6818 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6819 if (!unind_ok)
6820 {
6821 inst.error = _("instruction does not support unindexed addressing");
6822 return FAIL;
6823 }
6824 inst.instruction |= inst.operands[i].imm;
6825 inst.instruction |= INDEX_UP;
6826 return SUCCESS;
09d92015 6827 }
a737bd4d 6828
c19d1205
ZW
6829 if (inst.operands[i].preind)
6830 inst.instruction |= PRE_INDEX;
a737bd4d 6831
c19d1205 6832 if (inst.operands[i].writeback)
09d92015 6833 {
c19d1205
ZW
6834 if (inst.operands[i].reg == REG_PC)
6835 {
6836 inst.error = _("pc may not be used with write-back");
6837 return FAIL;
6838 }
6839 if (!wb_ok)
6840 {
6841 inst.error = _("instruction does not support writeback");
6842 return FAIL;
6843 }
6844 inst.instruction |= WRITE_BACK;
09d92015 6845 }
a737bd4d 6846
c19d1205 6847 if (reloc_override)
21d799b5 6848 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6849 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6850 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6851 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6852 {
6853 if (thumb_mode)
6854 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6855 else
6856 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6857 }
6858
c19d1205
ZW
6859 return SUCCESS;
6860}
a737bd4d 6861
c19d1205
ZW
6862/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6863 Determine whether it can be performed with a move instruction; if
6864 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6865 return TRUE; if it can't, convert inst.instruction to a literal-pool
6866 load and return FALSE. If this is not a valid thing to do in the
6867 current context, set inst.error and return TRUE.
a737bd4d 6868
c19d1205
ZW
6869 inst.operands[i] describes the destination register. */
6870
c921be7d 6871static bfd_boolean
c19d1205
ZW
6872move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6873{
53365c0d
PB
6874 unsigned long tbit;
6875
6876 if (thumb_p)
6877 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6878 else
6879 tbit = LOAD_BIT;
6880
6881 if ((inst.instruction & tbit) == 0)
09d92015 6882 {
c19d1205 6883 inst.error = _("invalid pseudo operation");
c921be7d 6884 return TRUE;
09d92015 6885 }
c19d1205 6886 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6887 {
6888 inst.error = _("constant expression expected");
c921be7d 6889 return TRUE;
09d92015 6890 }
c19d1205 6891 if (inst.reloc.exp.X_op == O_constant)
09d92015 6892 {
c19d1205
ZW
6893 if (thumb_p)
6894 {
53365c0d 6895 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6896 {
6897 /* This can be done with a mov(1) instruction. */
6898 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6899 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 6900 return TRUE;
c19d1205
ZW
6901 }
6902 }
6903 else
6904 {
6905 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6906 if (value != FAIL)
6907 {
6908 /* This can be done with a mov instruction. */
6909 inst.instruction &= LITERAL_MASK;
6910 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6911 inst.instruction |= value & 0xfff;
c921be7d 6912 return TRUE;
c19d1205 6913 }
09d92015 6914
c19d1205
ZW
6915 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6916 if (value != FAIL)
6917 {
6918 /* This can be done with a mvn instruction. */
6919 inst.instruction &= LITERAL_MASK;
6920 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6921 inst.instruction |= value & 0xfff;
c921be7d 6922 return TRUE;
c19d1205
ZW
6923 }
6924 }
09d92015
MM
6925 }
6926
c19d1205
ZW
6927 if (add_to_lit_pool () == FAIL)
6928 {
6929 inst.error = _("literal pool insertion failed");
c921be7d 6930 return TRUE;
c19d1205
ZW
6931 }
6932 inst.operands[1].reg = REG_PC;
6933 inst.operands[1].isreg = 1;
6934 inst.operands[1].preind = 1;
6935 inst.reloc.pc_rel = 1;
6936 inst.reloc.type = (thumb_p
6937 ? BFD_RELOC_ARM_THUMB_OFFSET
6938 : (mode_3
6939 ? BFD_RELOC_ARM_HWLITERAL
6940 : BFD_RELOC_ARM_LITERAL));
c921be7d 6941 return FALSE;
09d92015
MM
6942}
6943
5f4273c7 6944/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6945 First some generics; their names are taken from the conventional
6946 bit positions for register arguments in ARM format instructions. */
09d92015 6947
a737bd4d 6948static void
c19d1205 6949do_noargs (void)
09d92015 6950{
c19d1205 6951}
a737bd4d 6952
c19d1205
ZW
6953static void
6954do_rd (void)
6955{
6956 inst.instruction |= inst.operands[0].reg << 12;
6957}
a737bd4d 6958
c19d1205
ZW
6959static void
6960do_rd_rm (void)
6961{
6962 inst.instruction |= inst.operands[0].reg << 12;
6963 inst.instruction |= inst.operands[1].reg;
6964}
09d92015 6965
c19d1205
ZW
6966static void
6967do_rd_rn (void)
6968{
6969 inst.instruction |= inst.operands[0].reg << 12;
6970 inst.instruction |= inst.operands[1].reg << 16;
6971}
a737bd4d 6972
c19d1205
ZW
6973static void
6974do_rn_rd (void)
6975{
6976 inst.instruction |= inst.operands[0].reg << 16;
6977 inst.instruction |= inst.operands[1].reg << 12;
6978}
09d92015 6979
c19d1205
ZW
6980static void
6981do_rd_rm_rn (void)
6982{
9a64e435 6983 unsigned Rn = inst.operands[2].reg;
708587a4 6984 /* Enforce restrictions on SWP instruction. */
9a64e435 6985 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
6986 {
6987 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6988 _("Rn must not overlap other operands"));
6989
6990 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
6991 if (warn_on_deprecated
6992 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
6993 as_warn (_("swp{b} use is deprecated for this architecture"));
6994
6995 }
c19d1205
ZW
6996 inst.instruction |= inst.operands[0].reg << 12;
6997 inst.instruction |= inst.operands[1].reg;
9a64e435 6998 inst.instruction |= Rn << 16;
c19d1205 6999}
09d92015 7000
c19d1205
ZW
7001static void
7002do_rd_rn_rm (void)
7003{
7004 inst.instruction |= inst.operands[0].reg << 12;
7005 inst.instruction |= inst.operands[1].reg << 16;
7006 inst.instruction |= inst.operands[2].reg;
7007}
a737bd4d 7008
c19d1205
ZW
7009static void
7010do_rm_rd_rn (void)
7011{
5be8be5d
DG
7012 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7013 constraint (((inst.reloc.exp.X_op != O_constant
7014 && inst.reloc.exp.X_op != O_illegal)
7015 || inst.reloc.exp.X_add_number != 0),
7016 BAD_ADDR_MODE);
c19d1205
ZW
7017 inst.instruction |= inst.operands[0].reg;
7018 inst.instruction |= inst.operands[1].reg << 12;
7019 inst.instruction |= inst.operands[2].reg << 16;
7020}
09d92015 7021
c19d1205
ZW
7022static void
7023do_imm0 (void)
7024{
7025 inst.instruction |= inst.operands[0].imm;
7026}
09d92015 7027
c19d1205
ZW
7028static void
7029do_rd_cpaddr (void)
7030{
7031 inst.instruction |= inst.operands[0].reg << 12;
7032 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7033}
a737bd4d 7034
c19d1205
ZW
7035/* ARM instructions, in alphabetical order by function name (except
7036 that wrapper functions appear immediately after the function they
7037 wrap). */
09d92015 7038
c19d1205
ZW
7039/* This is a pseudo-op of the form "adr rd, label" to be converted
7040 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7041
7042static void
c19d1205 7043do_adr (void)
09d92015 7044{
c19d1205 7045 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7046
c19d1205
ZW
7047 /* Frag hacking will turn this into a sub instruction if the offset turns
7048 out to be negative. */
7049 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7050 inst.reloc.pc_rel = 1;
2fc8bdac 7051 inst.reloc.exp.X_add_number -= 8;
c19d1205 7052}
b99bd4ef 7053
c19d1205
ZW
7054/* This is a pseudo-op of the form "adrl rd, label" to be converted
7055 into a relative address of the form:
7056 add rd, pc, #low(label-.-8)"
7057 add rd, rd, #high(label-.-8)" */
b99bd4ef 7058
c19d1205
ZW
7059static void
7060do_adrl (void)
7061{
7062 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7063
c19d1205
ZW
7064 /* Frag hacking will turn this into a sub instruction if the offset turns
7065 out to be negative. */
7066 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7067 inst.reloc.pc_rel = 1;
7068 inst.size = INSN_SIZE * 2;
2fc8bdac 7069 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7070}
7071
b99bd4ef 7072static void
c19d1205 7073do_arit (void)
b99bd4ef 7074{
c19d1205
ZW
7075 if (!inst.operands[1].present)
7076 inst.operands[1].reg = inst.operands[0].reg;
7077 inst.instruction |= inst.operands[0].reg << 12;
7078 inst.instruction |= inst.operands[1].reg << 16;
7079 encode_arm_shifter_operand (2);
7080}
b99bd4ef 7081
62b3e311
PB
7082static void
7083do_barrier (void)
7084{
7085 if (inst.operands[0].present)
7086 {
7087 constraint ((inst.instruction & 0xf0) != 0x40
7088 && inst.operands[0].imm != 0xf,
bd3ba5d1 7089 _("bad barrier type"));
62b3e311
PB
7090 inst.instruction |= inst.operands[0].imm;
7091 }
7092 else
7093 inst.instruction |= 0xf;
7094}
7095
c19d1205
ZW
7096static void
7097do_bfc (void)
7098{
7099 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7100 constraint (msb > 32, _("bit-field extends past end of register"));
7101 /* The instruction encoding stores the LSB and MSB,
7102 not the LSB and width. */
7103 inst.instruction |= inst.operands[0].reg << 12;
7104 inst.instruction |= inst.operands[1].imm << 7;
7105 inst.instruction |= (msb - 1) << 16;
7106}
b99bd4ef 7107
c19d1205
ZW
7108static void
7109do_bfi (void)
7110{
7111 unsigned int msb;
b99bd4ef 7112
c19d1205
ZW
7113 /* #0 in second position is alternative syntax for bfc, which is
7114 the same instruction but with REG_PC in the Rm field. */
7115 if (!inst.operands[1].isreg)
7116 inst.operands[1].reg = REG_PC;
b99bd4ef 7117
c19d1205
ZW
7118 msb = inst.operands[2].imm + inst.operands[3].imm;
7119 constraint (msb > 32, _("bit-field extends past end of register"));
7120 /* The instruction encoding stores the LSB and MSB,
7121 not the LSB and width. */
7122 inst.instruction |= inst.operands[0].reg << 12;
7123 inst.instruction |= inst.operands[1].reg;
7124 inst.instruction |= inst.operands[2].imm << 7;
7125 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7126}
7127
b99bd4ef 7128static void
c19d1205 7129do_bfx (void)
b99bd4ef 7130{
c19d1205
ZW
7131 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7132 _("bit-field extends past end of register"));
7133 inst.instruction |= inst.operands[0].reg << 12;
7134 inst.instruction |= inst.operands[1].reg;
7135 inst.instruction |= inst.operands[2].imm << 7;
7136 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7137}
09d92015 7138
c19d1205
ZW
7139/* ARM V5 breakpoint instruction (argument parse)
7140 BKPT <16 bit unsigned immediate>
7141 Instruction is not conditional.
7142 The bit pattern given in insns[] has the COND_ALWAYS condition,
7143 and it is an error if the caller tried to override that. */
b99bd4ef 7144
c19d1205
ZW
7145static void
7146do_bkpt (void)
7147{
7148 /* Top 12 of 16 bits to bits 19:8. */
7149 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7150
c19d1205
ZW
7151 /* Bottom 4 of 16 bits to bits 3:0. */
7152 inst.instruction |= inst.operands[0].imm & 0xf;
7153}
09d92015 7154
c19d1205
ZW
7155static void
7156encode_branch (int default_reloc)
7157{
7158 if (inst.operands[0].hasreloc)
7159 {
7160 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7161 _("the only suffix valid here is '(plt)'"));
267bf995 7162 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7163 }
b99bd4ef 7164 else
c19d1205 7165 {
21d799b5 7166 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7167 }
2fc8bdac 7168 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7169}
7170
b99bd4ef 7171static void
c19d1205 7172do_branch (void)
b99bd4ef 7173{
39b41c9c
PB
7174#ifdef OBJ_ELF
7175 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7176 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7177 else
7178#endif
7179 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7180}
7181
7182static void
7183do_bl (void)
7184{
7185#ifdef OBJ_ELF
7186 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7187 {
7188 if (inst.cond == COND_ALWAYS)
7189 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7190 else
7191 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7192 }
7193 else
7194#endif
7195 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7196}
b99bd4ef 7197
c19d1205
ZW
7198/* ARM V5 branch-link-exchange instruction (argument parse)
7199 BLX <target_addr> ie BLX(1)
7200 BLX{<condition>} <Rm> ie BLX(2)
7201 Unfortunately, there are two different opcodes for this mnemonic.
7202 So, the insns[].value is not used, and the code here zaps values
7203 into inst.instruction.
7204 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7205
c19d1205
ZW
7206static void
7207do_blx (void)
7208{
7209 if (inst.operands[0].isreg)
b99bd4ef 7210 {
c19d1205
ZW
7211 /* Arg is a register; the opcode provided by insns[] is correct.
7212 It is not illegal to do "blx pc", just useless. */
7213 if (inst.operands[0].reg == REG_PC)
7214 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7215
c19d1205
ZW
7216 inst.instruction |= inst.operands[0].reg;
7217 }
7218 else
b99bd4ef 7219 {
c19d1205 7220 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7221 conditionally, and the opcode must be adjusted.
7222 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7223 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7224 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7225 inst.instruction = 0xfa000000;
267bf995 7226 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7227 }
c19d1205
ZW
7228}
7229
7230static void
7231do_bx (void)
7232{
845b51d6
PB
7233 bfd_boolean want_reloc;
7234
c19d1205
ZW
7235 if (inst.operands[0].reg == REG_PC)
7236 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7237
c19d1205 7238 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7239 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7240 it is for ARMv4t or earlier. */
7241 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7242 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7243 want_reloc = TRUE;
7244
5ad34203 7245#ifdef OBJ_ELF
845b51d6 7246 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7247#endif
584206db 7248 want_reloc = FALSE;
845b51d6
PB
7249
7250 if (want_reloc)
7251 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7252}
7253
c19d1205
ZW
7254
7255/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7256
7257static void
c19d1205 7258do_bxj (void)
a737bd4d 7259{
c19d1205
ZW
7260 if (inst.operands[0].reg == REG_PC)
7261 as_tsktsk (_("use of r15 in bxj is not really useful"));
7262
7263 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7264}
7265
c19d1205
ZW
7266/* Co-processor data operation:
7267 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7268 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7269static void
7270do_cdp (void)
7271{
7272 inst.instruction |= inst.operands[0].reg << 8;
7273 inst.instruction |= inst.operands[1].imm << 20;
7274 inst.instruction |= inst.operands[2].reg << 12;
7275 inst.instruction |= inst.operands[3].reg << 16;
7276 inst.instruction |= inst.operands[4].reg;
7277 inst.instruction |= inst.operands[5].imm << 5;
7278}
a737bd4d
NC
7279
7280static void
c19d1205 7281do_cmp (void)
a737bd4d 7282{
c19d1205
ZW
7283 inst.instruction |= inst.operands[0].reg << 16;
7284 encode_arm_shifter_operand (1);
a737bd4d
NC
7285}
7286
c19d1205
ZW
7287/* Transfer between coprocessor and ARM registers.
7288 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7289 MRC2
7290 MCR{cond}
7291 MCR2
7292
7293 No special properties. */
09d92015
MM
7294
7295static void
c19d1205 7296do_co_reg (void)
09d92015 7297{
fdfde340
JM
7298 unsigned Rd;
7299
7300 Rd = inst.operands[2].reg;
7301 if (thumb_mode)
7302 {
7303 if (inst.instruction == 0xee000010
7304 || inst.instruction == 0xfe000010)
7305 /* MCR, MCR2 */
7306 reject_bad_reg (Rd);
7307 else
7308 /* MRC, MRC2 */
7309 constraint (Rd == REG_SP, BAD_SP);
7310 }
7311 else
7312 {
7313 /* MCR */
7314 if (inst.instruction == 0xe000010)
7315 constraint (Rd == REG_PC, BAD_PC);
7316 }
7317
7318
c19d1205
ZW
7319 inst.instruction |= inst.operands[0].reg << 8;
7320 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7321 inst.instruction |= Rd << 12;
c19d1205
ZW
7322 inst.instruction |= inst.operands[3].reg << 16;
7323 inst.instruction |= inst.operands[4].reg;
7324 inst.instruction |= inst.operands[5].imm << 5;
7325}
09d92015 7326
c19d1205
ZW
7327/* Transfer between coprocessor register and pair of ARM registers.
7328 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7329 MCRR2
7330 MRRC{cond}
7331 MRRC2
b99bd4ef 7332
c19d1205 7333 Two XScale instructions are special cases of these:
09d92015 7334
c19d1205
ZW
7335 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7336 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7337
5f4273c7 7338 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7339
c19d1205
ZW
7340static void
7341do_co_reg2c (void)
7342{
fdfde340
JM
7343 unsigned Rd, Rn;
7344
7345 Rd = inst.operands[2].reg;
7346 Rn = inst.operands[3].reg;
7347
7348 if (thumb_mode)
7349 {
7350 reject_bad_reg (Rd);
7351 reject_bad_reg (Rn);
7352 }
7353 else
7354 {
7355 constraint (Rd == REG_PC, BAD_PC);
7356 constraint (Rn == REG_PC, BAD_PC);
7357 }
7358
c19d1205
ZW
7359 inst.instruction |= inst.operands[0].reg << 8;
7360 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7361 inst.instruction |= Rd << 12;
7362 inst.instruction |= Rn << 16;
c19d1205 7363 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7364}
7365
c19d1205
ZW
7366static void
7367do_cpsi (void)
7368{
7369 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7370 if (inst.operands[1].present)
7371 {
7372 inst.instruction |= CPSI_MMOD;
7373 inst.instruction |= inst.operands[1].imm;
7374 }
c19d1205 7375}
b99bd4ef 7376
62b3e311
PB
7377static void
7378do_dbg (void)
7379{
7380 inst.instruction |= inst.operands[0].imm;
7381}
7382
b99bd4ef 7383static void
c19d1205 7384do_it (void)
b99bd4ef 7385{
c19d1205 7386 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7387 process it to do the validation as if in
7388 thumb mode, just in case the code gets
7389 assembled for thumb using the unified syntax. */
7390
c19d1205 7391 inst.size = 0;
e07e6e58
NC
7392 if (unified_syntax)
7393 {
7394 set_it_insn_type (IT_INSN);
7395 now_it.mask = (inst.instruction & 0xf) | 0x10;
7396 now_it.cc = inst.operands[0].imm;
7397 }
09d92015 7398}
b99bd4ef 7399
09d92015 7400static void
c19d1205 7401do_ldmstm (void)
ea6ef066 7402{
c19d1205
ZW
7403 int base_reg = inst.operands[0].reg;
7404 int range = inst.operands[1].imm;
ea6ef066 7405
c19d1205
ZW
7406 inst.instruction |= base_reg << 16;
7407 inst.instruction |= range;
ea6ef066 7408
c19d1205
ZW
7409 if (inst.operands[1].writeback)
7410 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7411
c19d1205 7412 if (inst.operands[0].writeback)
ea6ef066 7413 {
c19d1205
ZW
7414 inst.instruction |= WRITE_BACK;
7415 /* Check for unpredictable uses of writeback. */
7416 if (inst.instruction & LOAD_BIT)
09d92015 7417 {
c19d1205
ZW
7418 /* Not allowed in LDM type 2. */
7419 if ((inst.instruction & LDM_TYPE_2_OR_3)
7420 && ((range & (1 << REG_PC)) == 0))
7421 as_warn (_("writeback of base register is UNPREDICTABLE"));
7422 /* Only allowed if base reg not in list for other types. */
7423 else if (range & (1 << base_reg))
7424 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7425 }
7426 else /* STM. */
7427 {
7428 /* Not allowed for type 2. */
7429 if (inst.instruction & LDM_TYPE_2_OR_3)
7430 as_warn (_("writeback of base register is UNPREDICTABLE"));
7431 /* Only allowed if base reg not in list, or first in list. */
7432 else if ((range & (1 << base_reg))
7433 && (range & ((1 << base_reg) - 1)))
7434 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7435 }
ea6ef066 7436 }
a737bd4d
NC
7437}
7438
c19d1205
ZW
7439/* ARMv5TE load-consecutive (argument parse)
7440 Mode is like LDRH.
7441
7442 LDRccD R, mode
7443 STRccD R, mode. */
7444
a737bd4d 7445static void
c19d1205 7446do_ldrd (void)
a737bd4d 7447{
c19d1205
ZW
7448 constraint (inst.operands[0].reg % 2 != 0,
7449 _("first destination register must be even"));
7450 constraint (inst.operands[1].present
7451 && inst.operands[1].reg != inst.operands[0].reg + 1,
7452 _("can only load two consecutive registers"));
7453 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7454 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7455
c19d1205
ZW
7456 if (!inst.operands[1].present)
7457 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7458
c19d1205 7459 if (inst.instruction & LOAD_BIT)
a737bd4d 7460 {
c19d1205
ZW
7461 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7462 register and the first register written; we have to diagnose
7463 overlap between the base and the second register written here. */
ea6ef066 7464
c19d1205
ZW
7465 if (inst.operands[2].reg == inst.operands[1].reg
7466 && (inst.operands[2].writeback || inst.operands[2].postind))
7467 as_warn (_("base register written back, and overlaps "
7468 "second destination register"));
b05fe5cf 7469
c19d1205
ZW
7470 /* For an index-register load, the index register must not overlap the
7471 destination (even if not write-back). */
7472 else if (inst.operands[2].immisreg
ca3f61f7
NC
7473 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7474 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7475 as_warn (_("index register overlaps destination register"));
b05fe5cf 7476 }
c19d1205
ZW
7477
7478 inst.instruction |= inst.operands[0].reg << 12;
7479 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7480}
7481
7482static void
c19d1205 7483do_ldrex (void)
b05fe5cf 7484{
c19d1205
ZW
7485 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7486 || inst.operands[1].postind || inst.operands[1].writeback
7487 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7488 || inst.operands[1].negative
7489 /* This can arise if the programmer has written
7490 strex rN, rM, foo
7491 or if they have mistakenly used a register name as the last
7492 operand, eg:
7493 strex rN, rM, rX
7494 It is very difficult to distinguish between these two cases
7495 because "rX" might actually be a label. ie the register
7496 name has been occluded by a symbol of the same name. So we
7497 just generate a general 'bad addressing mode' type error
7498 message and leave it up to the programmer to discover the
7499 true cause and fix their mistake. */
7500 || (inst.operands[1].reg == REG_PC),
7501 BAD_ADDR_MODE);
b05fe5cf 7502
c19d1205
ZW
7503 constraint (inst.reloc.exp.X_op != O_constant
7504 || inst.reloc.exp.X_add_number != 0,
7505 _("offset must be zero in ARM encoding"));
b05fe5cf 7506
5be8be5d
DG
7507 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7508
c19d1205
ZW
7509 inst.instruction |= inst.operands[0].reg << 12;
7510 inst.instruction |= inst.operands[1].reg << 16;
7511 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7512}
7513
7514static void
c19d1205 7515do_ldrexd (void)
b05fe5cf 7516{
c19d1205
ZW
7517 constraint (inst.operands[0].reg % 2 != 0,
7518 _("even register required"));
7519 constraint (inst.operands[1].present
7520 && inst.operands[1].reg != inst.operands[0].reg + 1,
7521 _("can only load two consecutive registers"));
7522 /* If op 1 were present and equal to PC, this function wouldn't
7523 have been called in the first place. */
7524 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7525
c19d1205
ZW
7526 inst.instruction |= inst.operands[0].reg << 12;
7527 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7528}
7529
7530static void
c19d1205 7531do_ldst (void)
b05fe5cf 7532{
c19d1205
ZW
7533 inst.instruction |= inst.operands[0].reg << 12;
7534 if (!inst.operands[1].isreg)
7535 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7536 return;
c19d1205 7537 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7538}
7539
7540static void
c19d1205 7541do_ldstt (void)
b05fe5cf 7542{
c19d1205
ZW
7543 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7544 reject [Rn,...]. */
7545 if (inst.operands[1].preind)
b05fe5cf 7546 {
bd3ba5d1
NC
7547 constraint (inst.reloc.exp.X_op != O_constant
7548 || inst.reloc.exp.X_add_number != 0,
c19d1205 7549 _("this instruction requires a post-indexed address"));
b05fe5cf 7550
c19d1205
ZW
7551 inst.operands[1].preind = 0;
7552 inst.operands[1].postind = 1;
7553 inst.operands[1].writeback = 1;
b05fe5cf 7554 }
c19d1205
ZW
7555 inst.instruction |= inst.operands[0].reg << 12;
7556 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7557}
b05fe5cf 7558
c19d1205 7559/* Halfword and signed-byte load/store operations. */
b05fe5cf 7560
c19d1205
ZW
7561static void
7562do_ldstv4 (void)
7563{
ff4a8d2b 7564 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7565 inst.instruction |= inst.operands[0].reg << 12;
7566 if (!inst.operands[1].isreg)
7567 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7568 return;
c19d1205 7569 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7570}
7571
7572static void
c19d1205 7573do_ldsttv4 (void)
b05fe5cf 7574{
c19d1205
ZW
7575 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7576 reject [Rn,...]. */
7577 if (inst.operands[1].preind)
b05fe5cf 7578 {
bd3ba5d1
NC
7579 constraint (inst.reloc.exp.X_op != O_constant
7580 || inst.reloc.exp.X_add_number != 0,
c19d1205 7581 _("this instruction requires a post-indexed address"));
b05fe5cf 7582
c19d1205
ZW
7583 inst.operands[1].preind = 0;
7584 inst.operands[1].postind = 1;
7585 inst.operands[1].writeback = 1;
b05fe5cf 7586 }
c19d1205
ZW
7587 inst.instruction |= inst.operands[0].reg << 12;
7588 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7589}
b05fe5cf 7590
c19d1205
ZW
7591/* Co-processor register load/store.
7592 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7593static void
7594do_lstc (void)
7595{
7596 inst.instruction |= inst.operands[0].reg << 8;
7597 inst.instruction |= inst.operands[1].reg << 12;
7598 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7599}
7600
b05fe5cf 7601static void
c19d1205 7602do_mlas (void)
b05fe5cf 7603{
8fb9d7b9 7604 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7605 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7606 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7607 && !(inst.instruction & 0x00400000))
8fb9d7b9 7608 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7609
c19d1205
ZW
7610 inst.instruction |= inst.operands[0].reg << 16;
7611 inst.instruction |= inst.operands[1].reg;
7612 inst.instruction |= inst.operands[2].reg << 8;
7613 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7614}
b05fe5cf 7615
c19d1205
ZW
7616static void
7617do_mov (void)
7618{
7619 inst.instruction |= inst.operands[0].reg << 12;
7620 encode_arm_shifter_operand (1);
7621}
b05fe5cf 7622
c19d1205
ZW
7623/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7624static void
7625do_mov16 (void)
7626{
b6895b4f
PB
7627 bfd_vma imm;
7628 bfd_boolean top;
7629
7630 top = (inst.instruction & 0x00400000) != 0;
7631 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7632 _(":lower16: not allowed this instruction"));
7633 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7634 _(":upper16: not allowed instruction"));
c19d1205 7635 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7636 if (inst.reloc.type == BFD_RELOC_UNUSED)
7637 {
7638 imm = inst.reloc.exp.X_add_number;
7639 /* The value is in two pieces: 0:11, 16:19. */
7640 inst.instruction |= (imm & 0x00000fff);
7641 inst.instruction |= (imm & 0x0000f000) << 4;
7642 }
b05fe5cf 7643}
b99bd4ef 7644
037e8744
JB
7645static void do_vfp_nsyn_opcode (const char *);
7646
7647static int
7648do_vfp_nsyn_mrs (void)
7649{
7650 if (inst.operands[0].isvec)
7651 {
7652 if (inst.operands[1].reg != 1)
7653 first_error (_("operand 1 must be FPSCR"));
7654 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7655 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7656 do_vfp_nsyn_opcode ("fmstat");
7657 }
7658 else if (inst.operands[1].isvec)
7659 do_vfp_nsyn_opcode ("fmrx");
7660 else
7661 return FAIL;
5f4273c7 7662
037e8744
JB
7663 return SUCCESS;
7664}
7665
7666static int
7667do_vfp_nsyn_msr (void)
7668{
7669 if (inst.operands[0].isvec)
7670 do_vfp_nsyn_opcode ("fmxr");
7671 else
7672 return FAIL;
7673
7674 return SUCCESS;
7675}
7676
f7c21dc7
NC
7677static void
7678do_vmrs (void)
7679{
7680 unsigned Rt = inst.operands[0].reg;
7681
7682 if (thumb_mode && inst.operands[0].reg == REG_SP)
7683 {
7684 inst.error = BAD_SP;
7685 return;
7686 }
7687
7688 /* APSR_ sets isvec. All other refs to PC are illegal. */
7689 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7690 {
7691 inst.error = BAD_PC;
7692 return;
7693 }
7694
7695 if (inst.operands[1].reg != 1)
7696 first_error (_("operand 1 must be FPSCR"));
7697
7698 inst.instruction |= (Rt << 12);
7699}
7700
7701static void
7702do_vmsr (void)
7703{
7704 unsigned Rt = inst.operands[1].reg;
7705
7706 if (thumb_mode)
7707 reject_bad_reg (Rt);
7708 else if (Rt == REG_PC)
7709 {
7710 inst.error = BAD_PC;
7711 return;
7712 }
7713
7714 if (inst.operands[0].reg != 1)
7715 first_error (_("operand 0 must be FPSCR"));
7716
7717 inst.instruction |= (Rt << 12);
7718}
7719
b99bd4ef 7720static void
c19d1205 7721do_mrs (void)
b99bd4ef 7722{
037e8744
JB
7723 if (do_vfp_nsyn_mrs () == SUCCESS)
7724 return;
7725
c19d1205
ZW
7726 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7727 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7728 != (PSR_c|PSR_f),
7729 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7730 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7731 inst.instruction |= inst.operands[0].reg << 12;
7732 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7733}
b99bd4ef 7734
c19d1205
ZW
7735/* Two possible forms:
7736 "{C|S}PSR_<field>, Rm",
7737 "{C|S}PSR_f, #expression". */
b99bd4ef 7738
c19d1205
ZW
7739static void
7740do_msr (void)
7741{
037e8744
JB
7742 if (do_vfp_nsyn_msr () == SUCCESS)
7743 return;
7744
c19d1205
ZW
7745 inst.instruction |= inst.operands[0].imm;
7746 if (inst.operands[1].isreg)
7747 inst.instruction |= inst.operands[1].reg;
7748 else
b99bd4ef 7749 {
c19d1205
ZW
7750 inst.instruction |= INST_IMMEDIATE;
7751 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7752 inst.reloc.pc_rel = 0;
b99bd4ef 7753 }
b99bd4ef
NC
7754}
7755
c19d1205
ZW
7756static void
7757do_mul (void)
a737bd4d 7758{
ff4a8d2b
NC
7759 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7760
c19d1205
ZW
7761 if (!inst.operands[2].present)
7762 inst.operands[2].reg = inst.operands[0].reg;
7763 inst.instruction |= inst.operands[0].reg << 16;
7764 inst.instruction |= inst.operands[1].reg;
7765 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7766
8fb9d7b9
MS
7767 if (inst.operands[0].reg == inst.operands[1].reg
7768 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7769 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7770}
7771
c19d1205
ZW
7772/* Long Multiply Parser
7773 UMULL RdLo, RdHi, Rm, Rs
7774 SMULL RdLo, RdHi, Rm, Rs
7775 UMLAL RdLo, RdHi, Rm, Rs
7776 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7777
7778static void
c19d1205 7779do_mull (void)
b99bd4ef 7780{
c19d1205
ZW
7781 inst.instruction |= inst.operands[0].reg << 12;
7782 inst.instruction |= inst.operands[1].reg << 16;
7783 inst.instruction |= inst.operands[2].reg;
7784 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7785
682b27ad
PB
7786 /* rdhi and rdlo must be different. */
7787 if (inst.operands[0].reg == inst.operands[1].reg)
7788 as_tsktsk (_("rdhi and rdlo must be different"));
7789
7790 /* rdhi, rdlo and rm must all be different before armv6. */
7791 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7792 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7793 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7794 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7795}
b99bd4ef 7796
c19d1205
ZW
7797static void
7798do_nop (void)
7799{
e7495e45
NS
7800 if (inst.operands[0].present
7801 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7802 {
7803 /* Architectural NOP hints are CPSR sets with no bits selected. */
7804 inst.instruction &= 0xf0000000;
e7495e45
NS
7805 inst.instruction |= 0x0320f000;
7806 if (inst.operands[0].present)
7807 inst.instruction |= inst.operands[0].imm;
c19d1205 7808 }
b99bd4ef
NC
7809}
7810
c19d1205
ZW
7811/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7812 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7813 Condition defaults to COND_ALWAYS.
7814 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7815
7816static void
c19d1205 7817do_pkhbt (void)
b99bd4ef 7818{
c19d1205
ZW
7819 inst.instruction |= inst.operands[0].reg << 12;
7820 inst.instruction |= inst.operands[1].reg << 16;
7821 inst.instruction |= inst.operands[2].reg;
7822 if (inst.operands[3].present)
7823 encode_arm_shift (3);
7824}
b99bd4ef 7825
c19d1205 7826/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7827
c19d1205
ZW
7828static void
7829do_pkhtb (void)
7830{
7831 if (!inst.operands[3].present)
b99bd4ef 7832 {
c19d1205
ZW
7833 /* If the shift specifier is omitted, turn the instruction
7834 into pkhbt rd, rm, rn. */
7835 inst.instruction &= 0xfff00010;
7836 inst.instruction |= inst.operands[0].reg << 12;
7837 inst.instruction |= inst.operands[1].reg;
7838 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7839 }
7840 else
7841 {
c19d1205
ZW
7842 inst.instruction |= inst.operands[0].reg << 12;
7843 inst.instruction |= inst.operands[1].reg << 16;
7844 inst.instruction |= inst.operands[2].reg;
7845 encode_arm_shift (3);
b99bd4ef
NC
7846 }
7847}
7848
c19d1205
ZW
7849/* ARMv5TE: Preload-Cache
7850
7851 PLD <addr_mode>
7852
7853 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7854
7855static void
c19d1205 7856do_pld (void)
b99bd4ef 7857{
c19d1205
ZW
7858 constraint (!inst.operands[0].isreg,
7859 _("'[' expected after PLD mnemonic"));
7860 constraint (inst.operands[0].postind,
7861 _("post-indexed expression used in preload instruction"));
7862 constraint (inst.operands[0].writeback,
7863 _("writeback used in preload instruction"));
7864 constraint (!inst.operands[0].preind,
7865 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7866 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7867}
b99bd4ef 7868
62b3e311
PB
7869/* ARMv7: PLI <addr_mode> */
7870static void
7871do_pli (void)
7872{
7873 constraint (!inst.operands[0].isreg,
7874 _("'[' expected after PLI mnemonic"));
7875 constraint (inst.operands[0].postind,
7876 _("post-indexed expression used in preload instruction"));
7877 constraint (inst.operands[0].writeback,
7878 _("writeback used in preload instruction"));
7879 constraint (!inst.operands[0].preind,
7880 _("unindexed addressing used in preload instruction"));
7881 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7882 inst.instruction &= ~PRE_INDEX;
7883}
7884
c19d1205
ZW
7885static void
7886do_push_pop (void)
7887{
7888 inst.operands[1] = inst.operands[0];
7889 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7890 inst.operands[0].isreg = 1;
7891 inst.operands[0].writeback = 1;
7892 inst.operands[0].reg = REG_SP;
7893 do_ldmstm ();
7894}
b99bd4ef 7895
c19d1205
ZW
7896/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7897 word at the specified address and the following word
7898 respectively.
7899 Unconditionally executed.
7900 Error if Rn is R15. */
b99bd4ef 7901
c19d1205
ZW
7902static void
7903do_rfe (void)
7904{
7905 inst.instruction |= inst.operands[0].reg << 16;
7906 if (inst.operands[0].writeback)
7907 inst.instruction |= WRITE_BACK;
7908}
b99bd4ef 7909
c19d1205 7910/* ARM V6 ssat (argument parse). */
b99bd4ef 7911
c19d1205
ZW
7912static void
7913do_ssat (void)
7914{
7915 inst.instruction |= inst.operands[0].reg << 12;
7916 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7917 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7918
c19d1205
ZW
7919 if (inst.operands[3].present)
7920 encode_arm_shift (3);
b99bd4ef
NC
7921}
7922
c19d1205 7923/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7924
7925static void
c19d1205 7926do_usat (void)
b99bd4ef 7927{
c19d1205
ZW
7928 inst.instruction |= inst.operands[0].reg << 12;
7929 inst.instruction |= inst.operands[1].imm << 16;
7930 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7931
c19d1205
ZW
7932 if (inst.operands[3].present)
7933 encode_arm_shift (3);
b99bd4ef
NC
7934}
7935
c19d1205 7936/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7937
7938static void
c19d1205 7939do_ssat16 (void)
09d92015 7940{
c19d1205
ZW
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7943 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7944}
7945
c19d1205
ZW
7946static void
7947do_usat16 (void)
a737bd4d 7948{
c19d1205
ZW
7949 inst.instruction |= inst.operands[0].reg << 12;
7950 inst.instruction |= inst.operands[1].imm << 16;
7951 inst.instruction |= inst.operands[2].reg;
7952}
a737bd4d 7953
c19d1205
ZW
7954/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7955 preserving the other bits.
a737bd4d 7956
c19d1205
ZW
7957 setend <endian_specifier>, where <endian_specifier> is either
7958 BE or LE. */
a737bd4d 7959
c19d1205
ZW
7960static void
7961do_setend (void)
7962{
7963 if (inst.operands[0].imm)
7964 inst.instruction |= 0x200;
a737bd4d
NC
7965}
7966
7967static void
c19d1205 7968do_shift (void)
a737bd4d 7969{
c19d1205
ZW
7970 unsigned int Rm = (inst.operands[1].present
7971 ? inst.operands[1].reg
7972 : inst.operands[0].reg);
a737bd4d 7973
c19d1205
ZW
7974 inst.instruction |= inst.operands[0].reg << 12;
7975 inst.instruction |= Rm;
7976 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7977 {
c19d1205
ZW
7978 inst.instruction |= inst.operands[2].reg << 8;
7979 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7980 }
7981 else
c19d1205 7982 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7983}
7984
09d92015 7985static void
3eb17e6b 7986do_smc (void)
09d92015 7987{
3eb17e6b 7988 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7989 inst.reloc.pc_rel = 0;
09d92015
MM
7990}
7991
09d92015 7992static void
c19d1205 7993do_swi (void)
09d92015 7994{
c19d1205
ZW
7995 inst.reloc.type = BFD_RELOC_ARM_SWI;
7996 inst.reloc.pc_rel = 0;
09d92015
MM
7997}
7998
c19d1205
ZW
7999/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8000 SMLAxy{cond} Rd,Rm,Rs,Rn
8001 SMLAWy{cond} Rd,Rm,Rs,Rn
8002 Error if any register is R15. */
e16bb312 8003
c19d1205
ZW
8004static void
8005do_smla (void)
e16bb312 8006{
c19d1205
ZW
8007 inst.instruction |= inst.operands[0].reg << 16;
8008 inst.instruction |= inst.operands[1].reg;
8009 inst.instruction |= inst.operands[2].reg << 8;
8010 inst.instruction |= inst.operands[3].reg << 12;
8011}
a737bd4d 8012
c19d1205
ZW
8013/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8014 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8015 Error if any register is R15.
8016 Warning if Rdlo == Rdhi. */
a737bd4d 8017
c19d1205
ZW
8018static void
8019do_smlal (void)
8020{
8021 inst.instruction |= inst.operands[0].reg << 12;
8022 inst.instruction |= inst.operands[1].reg << 16;
8023 inst.instruction |= inst.operands[2].reg;
8024 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8025
c19d1205
ZW
8026 if (inst.operands[0].reg == inst.operands[1].reg)
8027 as_tsktsk (_("rdhi and rdlo must be different"));
8028}
a737bd4d 8029
c19d1205
ZW
8030/* ARM V5E (El Segundo) signed-multiply (argument parse)
8031 SMULxy{cond} Rd,Rm,Rs
8032 Error if any register is R15. */
a737bd4d 8033
c19d1205
ZW
8034static void
8035do_smul (void)
8036{
8037 inst.instruction |= inst.operands[0].reg << 16;
8038 inst.instruction |= inst.operands[1].reg;
8039 inst.instruction |= inst.operands[2].reg << 8;
8040}
a737bd4d 8041
b6702015
PB
8042/* ARM V6 srs (argument parse). The variable fields in the encoding are
8043 the same for both ARM and Thumb-2. */
a737bd4d 8044
c19d1205
ZW
8045static void
8046do_srs (void)
8047{
b6702015
PB
8048 int reg;
8049
8050 if (inst.operands[0].present)
8051 {
8052 reg = inst.operands[0].reg;
fdfde340 8053 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8054 }
8055 else
fdfde340 8056 reg = REG_SP;
b6702015
PB
8057
8058 inst.instruction |= reg << 16;
8059 inst.instruction |= inst.operands[1].imm;
8060 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8061 inst.instruction |= WRITE_BACK;
8062}
a737bd4d 8063
c19d1205 8064/* ARM V6 strex (argument parse). */
a737bd4d 8065
c19d1205
ZW
8066static void
8067do_strex (void)
8068{
8069 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8070 || inst.operands[2].postind || inst.operands[2].writeback
8071 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8072 || inst.operands[2].negative
8073 /* See comment in do_ldrex(). */
8074 || (inst.operands[2].reg == REG_PC),
8075 BAD_ADDR_MODE);
a737bd4d 8076
c19d1205
ZW
8077 constraint (inst.operands[0].reg == inst.operands[1].reg
8078 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8079
c19d1205
ZW
8080 constraint (inst.reloc.exp.X_op != O_constant
8081 || inst.reloc.exp.X_add_number != 0,
8082 _("offset must be zero in ARM encoding"));
a737bd4d 8083
c19d1205
ZW
8084 inst.instruction |= inst.operands[0].reg << 12;
8085 inst.instruction |= inst.operands[1].reg;
8086 inst.instruction |= inst.operands[2].reg << 16;
8087 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8088}
8089
8090static void
c19d1205 8091do_strexd (void)
e16bb312 8092{
c19d1205
ZW
8093 constraint (inst.operands[1].reg % 2 != 0,
8094 _("even register required"));
8095 constraint (inst.operands[2].present
8096 && inst.operands[2].reg != inst.operands[1].reg + 1,
8097 _("can only store two consecutive registers"));
8098 /* If op 2 were present and equal to PC, this function wouldn't
8099 have been called in the first place. */
8100 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8101
c19d1205
ZW
8102 constraint (inst.operands[0].reg == inst.operands[1].reg
8103 || inst.operands[0].reg == inst.operands[1].reg + 1
8104 || inst.operands[0].reg == inst.operands[3].reg,
8105 BAD_OVERLAP);
e16bb312 8106
c19d1205
ZW
8107 inst.instruction |= inst.operands[0].reg << 12;
8108 inst.instruction |= inst.operands[1].reg;
8109 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8110}
8111
c19d1205
ZW
8112/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8113 extends it to 32-bits, and adds the result to a value in another
8114 register. You can specify a rotation by 0, 8, 16, or 24 bits
8115 before extracting the 16-bit value.
8116 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8117 Condition defaults to COND_ALWAYS.
8118 Error if any register uses R15. */
8119
e16bb312 8120static void
c19d1205 8121do_sxtah (void)
e16bb312 8122{
c19d1205
ZW
8123 inst.instruction |= inst.operands[0].reg << 12;
8124 inst.instruction |= inst.operands[1].reg << 16;
8125 inst.instruction |= inst.operands[2].reg;
8126 inst.instruction |= inst.operands[3].imm << 10;
8127}
e16bb312 8128
c19d1205 8129/* ARM V6 SXTH.
e16bb312 8130
c19d1205
ZW
8131 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8132 Condition defaults to COND_ALWAYS.
8133 Error if any register uses R15. */
e16bb312
NC
8134
8135static void
c19d1205 8136do_sxth (void)
e16bb312 8137{
c19d1205
ZW
8138 inst.instruction |= inst.operands[0].reg << 12;
8139 inst.instruction |= inst.operands[1].reg;
8140 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8141}
c19d1205
ZW
8142\f
8143/* VFP instructions. In a logical order: SP variant first, monad
8144 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8145
8146static void
c19d1205 8147do_vfp_sp_monadic (void)
e16bb312 8148{
5287ad62
JB
8149 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8150 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8151}
8152
8153static void
c19d1205 8154do_vfp_sp_dyadic (void)
e16bb312 8155{
5287ad62
JB
8156 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8157 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8158 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8159}
8160
8161static void
c19d1205 8162do_vfp_sp_compare_z (void)
e16bb312 8163{
5287ad62 8164 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8165}
8166
8167static void
c19d1205 8168do_vfp_dp_sp_cvt (void)
e16bb312 8169{
5287ad62
JB
8170 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8171 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8172}
8173
8174static void
c19d1205 8175do_vfp_sp_dp_cvt (void)
e16bb312 8176{
5287ad62
JB
8177 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8178 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8179}
8180
8181static void
c19d1205 8182do_vfp_reg_from_sp (void)
e16bb312 8183{
c19d1205 8184 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8185 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8186}
8187
8188static void
c19d1205 8189do_vfp_reg2_from_sp2 (void)
e16bb312 8190{
c19d1205
ZW
8191 constraint (inst.operands[2].imm != 2,
8192 _("only two consecutive VFP SP registers allowed here"));
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8195 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8196}
8197
8198static void
c19d1205 8199do_vfp_sp_from_reg (void)
e16bb312 8200{
5287ad62 8201 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8202 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8203}
8204
8205static void
c19d1205 8206do_vfp_sp2_from_reg2 (void)
e16bb312 8207{
c19d1205
ZW
8208 constraint (inst.operands[0].imm != 2,
8209 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8210 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8211 inst.instruction |= inst.operands[1].reg << 12;
8212 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8213}
8214
8215static void
c19d1205 8216do_vfp_sp_ldst (void)
e16bb312 8217{
5287ad62 8218 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8219 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8220}
8221
8222static void
c19d1205 8223do_vfp_dp_ldst (void)
e16bb312 8224{
5287ad62 8225 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8226 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8227}
8228
c19d1205 8229
e16bb312 8230static void
c19d1205 8231vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8232{
c19d1205
ZW
8233 if (inst.operands[0].writeback)
8234 inst.instruction |= WRITE_BACK;
8235 else
8236 constraint (ldstm_type != VFP_LDSTMIA,
8237 _("this addressing mode requires base-register writeback"));
8238 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8239 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8240 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8241}
8242
8243static void
c19d1205 8244vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8245{
c19d1205 8246 int count;
e16bb312 8247
c19d1205
ZW
8248 if (inst.operands[0].writeback)
8249 inst.instruction |= WRITE_BACK;
8250 else
8251 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8252 _("this addressing mode requires base-register writeback"));
e16bb312 8253
c19d1205 8254 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8255 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8256
c19d1205
ZW
8257 count = inst.operands[1].imm << 1;
8258 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8259 count += 1;
e16bb312 8260
c19d1205 8261 inst.instruction |= count;
e16bb312
NC
8262}
8263
8264static void
c19d1205 8265do_vfp_sp_ldstmia (void)
e16bb312 8266{
c19d1205 8267 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8268}
8269
8270static void
c19d1205 8271do_vfp_sp_ldstmdb (void)
e16bb312 8272{
c19d1205 8273 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8274}
8275
8276static void
c19d1205 8277do_vfp_dp_ldstmia (void)
e16bb312 8278{
c19d1205 8279 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8280}
8281
8282static void
c19d1205 8283do_vfp_dp_ldstmdb (void)
e16bb312 8284{
c19d1205 8285 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8286}
8287
8288static void
c19d1205 8289do_vfp_xp_ldstmia (void)
e16bb312 8290{
c19d1205
ZW
8291 vfp_dp_ldstm (VFP_LDSTMIAX);
8292}
e16bb312 8293
c19d1205
ZW
8294static void
8295do_vfp_xp_ldstmdb (void)
8296{
8297 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8298}
5287ad62
JB
8299
8300static void
8301do_vfp_dp_rd_rm (void)
8302{
8303 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8304 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8305}
8306
8307static void
8308do_vfp_dp_rn_rd (void)
8309{
8310 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8311 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8312}
8313
8314static void
8315do_vfp_dp_rd_rn (void)
8316{
8317 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8318 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8319}
8320
8321static void
8322do_vfp_dp_rd_rn_rm (void)
8323{
8324 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8325 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8326 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8327}
8328
8329static void
8330do_vfp_dp_rd (void)
8331{
8332 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8333}
8334
8335static void
8336do_vfp_dp_rm_rd_rn (void)
8337{
8338 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8339 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8340 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8341}
8342
8343/* VFPv3 instructions. */
8344static void
8345do_vfp_sp_const (void)
8346{
8347 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8348 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8349 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8350}
8351
8352static void
8353do_vfp_dp_const (void)
8354{
8355 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8356 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8357 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8358}
8359
8360static void
8361vfp_conv (int srcsize)
8362{
8363 unsigned immbits = srcsize - inst.operands[1].imm;
8364 inst.instruction |= (immbits & 1) << 5;
8365 inst.instruction |= (immbits >> 1);
8366}
8367
8368static void
8369do_vfp_sp_conv_16 (void)
8370{
8371 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8372 vfp_conv (16);
8373}
8374
8375static void
8376do_vfp_dp_conv_16 (void)
8377{
8378 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8379 vfp_conv (16);
8380}
8381
8382static void
8383do_vfp_sp_conv_32 (void)
8384{
8385 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8386 vfp_conv (32);
8387}
8388
8389static void
8390do_vfp_dp_conv_32 (void)
8391{
8392 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8393 vfp_conv (32);
8394}
c19d1205
ZW
8395\f
8396/* FPA instructions. Also in a logical order. */
e16bb312 8397
c19d1205
ZW
8398static void
8399do_fpa_cmp (void)
8400{
8401 inst.instruction |= inst.operands[0].reg << 16;
8402 inst.instruction |= inst.operands[1].reg;
8403}
b99bd4ef
NC
8404
8405static void
c19d1205 8406do_fpa_ldmstm (void)
b99bd4ef 8407{
c19d1205
ZW
8408 inst.instruction |= inst.operands[0].reg << 12;
8409 switch (inst.operands[1].imm)
8410 {
8411 case 1: inst.instruction |= CP_T_X; break;
8412 case 2: inst.instruction |= CP_T_Y; break;
8413 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8414 case 4: break;
8415 default: abort ();
8416 }
b99bd4ef 8417
c19d1205
ZW
8418 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8419 {
8420 /* The instruction specified "ea" or "fd", so we can only accept
8421 [Rn]{!}. The instruction does not really support stacking or
8422 unstacking, so we have to emulate these by setting appropriate
8423 bits and offsets. */
8424 constraint (inst.reloc.exp.X_op != O_constant
8425 || inst.reloc.exp.X_add_number != 0,
8426 _("this instruction does not support indexing"));
b99bd4ef 8427
c19d1205
ZW
8428 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8429 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8430
c19d1205
ZW
8431 if (!(inst.instruction & INDEX_UP))
8432 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8433
c19d1205
ZW
8434 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8435 {
8436 inst.operands[2].preind = 0;
8437 inst.operands[2].postind = 1;
8438 }
8439 }
b99bd4ef 8440
c19d1205 8441 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8442}
c19d1205
ZW
8443\f
8444/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8445
c19d1205
ZW
8446static void
8447do_iwmmxt_tandorc (void)
8448{
8449 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8450}
b99bd4ef 8451
c19d1205
ZW
8452static void
8453do_iwmmxt_textrc (void)
8454{
8455 inst.instruction |= inst.operands[0].reg << 12;
8456 inst.instruction |= inst.operands[1].imm;
8457}
b99bd4ef
NC
8458
8459static void
c19d1205 8460do_iwmmxt_textrm (void)
b99bd4ef 8461{
c19d1205
ZW
8462 inst.instruction |= inst.operands[0].reg << 12;
8463 inst.instruction |= inst.operands[1].reg << 16;
8464 inst.instruction |= inst.operands[2].imm;
8465}
b99bd4ef 8466
c19d1205
ZW
8467static void
8468do_iwmmxt_tinsr (void)
8469{
8470 inst.instruction |= inst.operands[0].reg << 16;
8471 inst.instruction |= inst.operands[1].reg << 12;
8472 inst.instruction |= inst.operands[2].imm;
8473}
b99bd4ef 8474
c19d1205
ZW
8475static void
8476do_iwmmxt_tmia (void)
8477{
8478 inst.instruction |= inst.operands[0].reg << 5;
8479 inst.instruction |= inst.operands[1].reg;
8480 inst.instruction |= inst.operands[2].reg << 12;
8481}
b99bd4ef 8482
c19d1205
ZW
8483static void
8484do_iwmmxt_waligni (void)
8485{
8486 inst.instruction |= inst.operands[0].reg << 12;
8487 inst.instruction |= inst.operands[1].reg << 16;
8488 inst.instruction |= inst.operands[2].reg;
8489 inst.instruction |= inst.operands[3].imm << 20;
8490}
b99bd4ef 8491
2d447fca
JM
8492static void
8493do_iwmmxt_wmerge (void)
8494{
8495 inst.instruction |= inst.operands[0].reg << 12;
8496 inst.instruction |= inst.operands[1].reg << 16;
8497 inst.instruction |= inst.operands[2].reg;
8498 inst.instruction |= inst.operands[3].imm << 21;
8499}
8500
c19d1205
ZW
8501static void
8502do_iwmmxt_wmov (void)
8503{
8504 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8505 inst.instruction |= inst.operands[0].reg << 12;
8506 inst.instruction |= inst.operands[1].reg << 16;
8507 inst.instruction |= inst.operands[1].reg;
8508}
b99bd4ef 8509
c19d1205
ZW
8510static void
8511do_iwmmxt_wldstbh (void)
8512{
8f06b2d8 8513 int reloc;
c19d1205 8514 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8515 if (thumb_mode)
8516 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8517 else
8518 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8519 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8520}
8521
c19d1205
ZW
8522static void
8523do_iwmmxt_wldstw (void)
8524{
8525 /* RIWR_RIWC clears .isreg for a control register. */
8526 if (!inst.operands[0].isreg)
8527 {
8528 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8529 inst.instruction |= 0xf0000000;
8530 }
b99bd4ef 8531
c19d1205
ZW
8532 inst.instruction |= inst.operands[0].reg << 12;
8533 encode_arm_cp_address (1, TRUE, TRUE, 0);
8534}
b99bd4ef
NC
8535
8536static void
c19d1205 8537do_iwmmxt_wldstd (void)
b99bd4ef 8538{
c19d1205 8539 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8540 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8541 && inst.operands[1].immisreg)
8542 {
8543 inst.instruction &= ~0x1a000ff;
8544 inst.instruction |= (0xf << 28);
8545 if (inst.operands[1].preind)
8546 inst.instruction |= PRE_INDEX;
8547 if (!inst.operands[1].negative)
8548 inst.instruction |= INDEX_UP;
8549 if (inst.operands[1].writeback)
8550 inst.instruction |= WRITE_BACK;
8551 inst.instruction |= inst.operands[1].reg << 16;
8552 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8553 inst.instruction |= inst.operands[1].imm;
8554 }
8555 else
8556 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8557}
b99bd4ef 8558
c19d1205
ZW
8559static void
8560do_iwmmxt_wshufh (void)
8561{
8562 inst.instruction |= inst.operands[0].reg << 12;
8563 inst.instruction |= inst.operands[1].reg << 16;
8564 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8565 inst.instruction |= (inst.operands[2].imm & 0x0f);
8566}
b99bd4ef 8567
c19d1205
ZW
8568static void
8569do_iwmmxt_wzero (void)
8570{
8571 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8572 inst.instruction |= inst.operands[0].reg;
8573 inst.instruction |= inst.operands[0].reg << 12;
8574 inst.instruction |= inst.operands[0].reg << 16;
8575}
2d447fca
JM
8576
8577static void
8578do_iwmmxt_wrwrwr_or_imm5 (void)
8579{
8580 if (inst.operands[2].isreg)
8581 do_rd_rn_rm ();
8582 else {
8583 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8584 _("immediate operand requires iWMMXt2"));
8585 do_rd_rn ();
8586 if (inst.operands[2].imm == 0)
8587 {
8588 switch ((inst.instruction >> 20) & 0xf)
8589 {
8590 case 4:
8591 case 5:
8592 case 6:
5f4273c7 8593 case 7:
2d447fca
JM
8594 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8595 inst.operands[2].imm = 16;
8596 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8597 break;
8598 case 8:
8599 case 9:
8600 case 10:
8601 case 11:
8602 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8603 inst.operands[2].imm = 32;
8604 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8605 break;
8606 case 12:
8607 case 13:
8608 case 14:
8609 case 15:
8610 {
8611 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8612 unsigned long wrn;
8613 wrn = (inst.instruction >> 16) & 0xf;
8614 inst.instruction &= 0xff0fff0f;
8615 inst.instruction |= wrn;
8616 /* Bail out here; the instruction is now assembled. */
8617 return;
8618 }
8619 }
8620 }
8621 /* Map 32 -> 0, etc. */
8622 inst.operands[2].imm &= 0x1f;
8623 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8624 }
8625}
c19d1205
ZW
8626\f
8627/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8628 operations first, then control, shift, and load/store. */
b99bd4ef 8629
c19d1205 8630/* Insns like "foo X,Y,Z". */
b99bd4ef 8631
c19d1205
ZW
8632static void
8633do_mav_triple (void)
8634{
8635 inst.instruction |= inst.operands[0].reg << 16;
8636 inst.instruction |= inst.operands[1].reg;
8637 inst.instruction |= inst.operands[2].reg << 12;
8638}
b99bd4ef 8639
c19d1205
ZW
8640/* Insns like "foo W,X,Y,Z".
8641 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8642
c19d1205
ZW
8643static void
8644do_mav_quad (void)
8645{
8646 inst.instruction |= inst.operands[0].reg << 5;
8647 inst.instruction |= inst.operands[1].reg << 12;
8648 inst.instruction |= inst.operands[2].reg << 16;
8649 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8650}
8651
c19d1205
ZW
8652/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8653static void
8654do_mav_dspsc (void)
a737bd4d 8655{
c19d1205
ZW
8656 inst.instruction |= inst.operands[1].reg << 12;
8657}
a737bd4d 8658
c19d1205
ZW
8659/* Maverick shift immediate instructions.
8660 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8661 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8662
c19d1205
ZW
8663static void
8664do_mav_shift (void)
8665{
8666 int imm = inst.operands[2].imm;
a737bd4d 8667
c19d1205
ZW
8668 inst.instruction |= inst.operands[0].reg << 12;
8669 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8670
c19d1205
ZW
8671 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8672 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8673 Bit 4 should be 0. */
8674 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8675
c19d1205
ZW
8676 inst.instruction |= imm;
8677}
8678\f
8679/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8680
c19d1205
ZW
8681/* Xscale multiply-accumulate (argument parse)
8682 MIAcc acc0,Rm,Rs
8683 MIAPHcc acc0,Rm,Rs
8684 MIAxycc acc0,Rm,Rs. */
a737bd4d 8685
c19d1205
ZW
8686static void
8687do_xsc_mia (void)
8688{
8689 inst.instruction |= inst.operands[1].reg;
8690 inst.instruction |= inst.operands[2].reg << 12;
8691}
a737bd4d 8692
c19d1205 8693/* Xscale move-accumulator-register (argument parse)
a737bd4d 8694
c19d1205 8695 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8696
c19d1205
ZW
8697static void
8698do_xsc_mar (void)
8699{
8700 inst.instruction |= inst.operands[1].reg << 12;
8701 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8702}
8703
c19d1205 8704/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8705
c19d1205 8706 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8707
8708static void
c19d1205 8709do_xsc_mra (void)
b99bd4ef 8710{
c19d1205
ZW
8711 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8712 inst.instruction |= inst.operands[0].reg << 12;
8713 inst.instruction |= inst.operands[1].reg << 16;
8714}
8715\f
8716/* Encoding functions relevant only to Thumb. */
b99bd4ef 8717
c19d1205
ZW
8718/* inst.operands[i] is a shifted-register operand; encode
8719 it into inst.instruction in the format used by Thumb32. */
8720
8721static void
8722encode_thumb32_shifted_operand (int i)
8723{
8724 unsigned int value = inst.reloc.exp.X_add_number;
8725 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8726
9c3c69f2
PB
8727 constraint (inst.operands[i].immisreg,
8728 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8729 inst.instruction |= inst.operands[i].reg;
8730 if (shift == SHIFT_RRX)
8731 inst.instruction |= SHIFT_ROR << 4;
8732 else
b99bd4ef 8733 {
c19d1205
ZW
8734 constraint (inst.reloc.exp.X_op != O_constant,
8735 _("expression too complex"));
8736
8737 constraint (value > 32
8738 || (value == 32 && (shift == SHIFT_LSL
8739 || shift == SHIFT_ROR)),
8740 _("shift expression is too large"));
8741
8742 if (value == 0)
8743 shift = SHIFT_LSL;
8744 else if (value == 32)
8745 value = 0;
8746
8747 inst.instruction |= shift << 4;
8748 inst.instruction |= (value & 0x1c) << 10;
8749 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8750 }
c19d1205 8751}
b99bd4ef 8752
b99bd4ef 8753
c19d1205
ZW
8754/* inst.operands[i] was set up by parse_address. Encode it into a
8755 Thumb32 format load or store instruction. Reject forms that cannot
8756 be used with such instructions. If is_t is true, reject forms that
8757 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8758 that cannot be used with a D instruction. If it is a store insn,
8759 reject PC in Rn. */
b99bd4ef 8760
c19d1205
ZW
8761static void
8762encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8763{
5be8be5d 8764 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8765
8766 constraint (!inst.operands[i].isreg,
53365c0d 8767 _("Instruction does not support =N addresses"));
b99bd4ef 8768
c19d1205
ZW
8769 inst.instruction |= inst.operands[i].reg << 16;
8770 if (inst.operands[i].immisreg)
b99bd4ef 8771 {
5be8be5d 8772 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8773 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8774 constraint (inst.operands[i].negative,
8775 _("Thumb does not support negative register indexing"));
8776 constraint (inst.operands[i].postind,
8777 _("Thumb does not support register post-indexing"));
8778 constraint (inst.operands[i].writeback,
8779 _("Thumb does not support register indexing with writeback"));
8780 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8781 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8782
f40d1643 8783 inst.instruction |= inst.operands[i].imm;
c19d1205 8784 if (inst.operands[i].shifted)
b99bd4ef 8785 {
c19d1205
ZW
8786 constraint (inst.reloc.exp.X_op != O_constant,
8787 _("expression too complex"));
9c3c69f2
PB
8788 constraint (inst.reloc.exp.X_add_number < 0
8789 || inst.reloc.exp.X_add_number > 3,
c19d1205 8790 _("shift out of range"));
9c3c69f2 8791 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8792 }
8793 inst.reloc.type = BFD_RELOC_UNUSED;
8794 }
8795 else if (inst.operands[i].preind)
8796 {
5be8be5d 8797 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8798 constraint (is_t && inst.operands[i].writeback,
c19d1205 8799 _("cannot use writeback with this instruction"));
5be8be5d
DG
8800 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8801 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8802
8803 if (is_d)
8804 {
8805 inst.instruction |= 0x01000000;
8806 if (inst.operands[i].writeback)
8807 inst.instruction |= 0x00200000;
b99bd4ef 8808 }
c19d1205 8809 else
b99bd4ef 8810 {
c19d1205
ZW
8811 inst.instruction |= 0x00000c00;
8812 if (inst.operands[i].writeback)
8813 inst.instruction |= 0x00000100;
b99bd4ef 8814 }
c19d1205 8815 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8816 }
c19d1205 8817 else if (inst.operands[i].postind)
b99bd4ef 8818 {
9c2799c2 8819 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8820 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8821 constraint (is_t, _("cannot use post-indexing with this instruction"));
8822
8823 if (is_d)
8824 inst.instruction |= 0x00200000;
8825 else
8826 inst.instruction |= 0x00000900;
8827 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8828 }
8829 else /* unindexed - only for coprocessor */
8830 inst.error = _("instruction does not accept unindexed addressing");
8831}
8832
8833/* Table of Thumb instructions which exist in both 16- and 32-bit
8834 encodings (the latter only in post-V6T2 cores). The index is the
8835 value used in the insns table below. When there is more than one
8836 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8837 holds variant (1).
8838 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8839#define T16_32_TAB \
21d799b5
NC
8840 X(_adc, 4140, eb400000), \
8841 X(_adcs, 4140, eb500000), \
8842 X(_add, 1c00, eb000000), \
8843 X(_adds, 1c00, eb100000), \
8844 X(_addi, 0000, f1000000), \
8845 X(_addis, 0000, f1100000), \
8846 X(_add_pc,000f, f20f0000), \
8847 X(_add_sp,000d, f10d0000), \
8848 X(_adr, 000f, f20f0000), \
8849 X(_and, 4000, ea000000), \
8850 X(_ands, 4000, ea100000), \
8851 X(_asr, 1000, fa40f000), \
8852 X(_asrs, 1000, fa50f000), \
8853 X(_b, e000, f000b000), \
8854 X(_bcond, d000, f0008000), \
8855 X(_bic, 4380, ea200000), \
8856 X(_bics, 4380, ea300000), \
8857 X(_cmn, 42c0, eb100f00), \
8858 X(_cmp, 2800, ebb00f00), \
8859 X(_cpsie, b660, f3af8400), \
8860 X(_cpsid, b670, f3af8600), \
8861 X(_cpy, 4600, ea4f0000), \
8862 X(_dec_sp,80dd, f1ad0d00), \
8863 X(_eor, 4040, ea800000), \
8864 X(_eors, 4040, ea900000), \
8865 X(_inc_sp,00dd, f10d0d00), \
8866 X(_ldmia, c800, e8900000), \
8867 X(_ldr, 6800, f8500000), \
8868 X(_ldrb, 7800, f8100000), \
8869 X(_ldrh, 8800, f8300000), \
8870 X(_ldrsb, 5600, f9100000), \
8871 X(_ldrsh, 5e00, f9300000), \
8872 X(_ldr_pc,4800, f85f0000), \
8873 X(_ldr_pc2,4800, f85f0000), \
8874 X(_ldr_sp,9800, f85d0000), \
8875 X(_lsl, 0000, fa00f000), \
8876 X(_lsls, 0000, fa10f000), \
8877 X(_lsr, 0800, fa20f000), \
8878 X(_lsrs, 0800, fa30f000), \
8879 X(_mov, 2000, ea4f0000), \
8880 X(_movs, 2000, ea5f0000), \
8881 X(_mul, 4340, fb00f000), \
8882 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8883 X(_mvn, 43c0, ea6f0000), \
8884 X(_mvns, 43c0, ea7f0000), \
8885 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8886 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8887 X(_orr, 4300, ea400000), \
8888 X(_orrs, 4300, ea500000), \
8889 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8890 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8891 X(_rev, ba00, fa90f080), \
8892 X(_rev16, ba40, fa90f090), \
8893 X(_revsh, bac0, fa90f0b0), \
8894 X(_ror, 41c0, fa60f000), \
8895 X(_rors, 41c0, fa70f000), \
8896 X(_sbc, 4180, eb600000), \
8897 X(_sbcs, 4180, eb700000), \
8898 X(_stmia, c000, e8800000), \
8899 X(_str, 6000, f8400000), \
8900 X(_strb, 7000, f8000000), \
8901 X(_strh, 8000, f8200000), \
8902 X(_str_sp,9000, f84d0000), \
8903 X(_sub, 1e00, eba00000), \
8904 X(_subs, 1e00, ebb00000), \
8905 X(_subi, 8000, f1a00000), \
8906 X(_subis, 8000, f1b00000), \
8907 X(_sxtb, b240, fa4ff080), \
8908 X(_sxth, b200, fa0ff080), \
8909 X(_tst, 4200, ea100f00), \
8910 X(_uxtb, b2c0, fa5ff080), \
8911 X(_uxth, b280, fa1ff080), \
8912 X(_nop, bf00, f3af8000), \
8913 X(_yield, bf10, f3af8001), \
8914 X(_wfe, bf20, f3af8002), \
8915 X(_wfi, bf30, f3af8003), \
8916 X(_sev, bf40, f3af8004),
c19d1205
ZW
8917
8918/* To catch errors in encoding functions, the codes are all offset by
8919 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8920 as 16-bit instructions. */
21d799b5 8921#define X(a,b,c) T_MNEM##a
c19d1205
ZW
8922enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8923#undef X
8924
8925#define X(a,b,c) 0x##b
8926static const unsigned short thumb_op16[] = { T16_32_TAB };
8927#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8928#undef X
8929
8930#define X(a,b,c) 0x##c
8931static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
8932#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8933#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
8934#undef X
8935#undef T16_32_TAB
8936
8937/* Thumb instruction encoders, in alphabetical order. */
8938
92e90b6e 8939/* ADDW or SUBW. */
c921be7d 8940
92e90b6e
PB
8941static void
8942do_t_add_sub_w (void)
8943{
8944 int Rd, Rn;
8945
8946 Rd = inst.operands[0].reg;
8947 Rn = inst.operands[1].reg;
8948
539d4391
NC
8949 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8950 is the SP-{plus,minus}-immediate form of the instruction. */
8951 if (Rn == REG_SP)
8952 constraint (Rd == REG_PC, BAD_PC);
8953 else
8954 reject_bad_reg (Rd);
fdfde340 8955
92e90b6e
PB
8956 inst.instruction |= (Rn << 16) | (Rd << 8);
8957 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8958}
8959
c19d1205
ZW
8960/* Parse an add or subtract instruction. We get here with inst.instruction
8961 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8962
8963static void
8964do_t_add_sub (void)
8965{
8966 int Rd, Rs, Rn;
8967
8968 Rd = inst.operands[0].reg;
8969 Rs = (inst.operands[1].present
8970 ? inst.operands[1].reg /* Rd, Rs, foo */
8971 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8972
e07e6e58
NC
8973 if (Rd == REG_PC)
8974 set_it_insn_type_last ();
8975
c19d1205
ZW
8976 if (unified_syntax)
8977 {
0110f2b8
PB
8978 bfd_boolean flags;
8979 bfd_boolean narrow;
8980 int opcode;
8981
8982 flags = (inst.instruction == T_MNEM_adds
8983 || inst.instruction == T_MNEM_subs);
8984 if (flags)
e07e6e58 8985 narrow = !in_it_block ();
0110f2b8 8986 else
e07e6e58 8987 narrow = in_it_block ();
c19d1205 8988 if (!inst.operands[2].isreg)
b99bd4ef 8989 {
16805f35
PB
8990 int add;
8991
fdfde340
JM
8992 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8993
16805f35
PB
8994 add = (inst.instruction == T_MNEM_add
8995 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8996 opcode = 0;
8997 if (inst.size_req != 4)
8998 {
0110f2b8
PB
8999 /* Attempt to use a narrow opcode, with relaxation if
9000 appropriate. */
9001 if (Rd == REG_SP && Rs == REG_SP && !flags)
9002 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9003 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9004 opcode = T_MNEM_add_sp;
9005 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9006 opcode = T_MNEM_add_pc;
9007 else if (Rd <= 7 && Rs <= 7 && narrow)
9008 {
9009 if (flags)
9010 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9011 else
9012 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9013 }
9014 if (opcode)
9015 {
9016 inst.instruction = THUMB_OP16(opcode);
9017 inst.instruction |= (Rd << 4) | Rs;
9018 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9019 if (inst.size_req != 2)
9020 inst.relax = opcode;
9021 }
9022 else
9023 constraint (inst.size_req == 2, BAD_HIREG);
9024 }
9025 if (inst.size_req == 4
9026 || (inst.size_req != 2 && !opcode))
9027 {
efd81785
PB
9028 if (Rd == REG_PC)
9029 {
fdfde340 9030 constraint (add, BAD_PC);
efd81785
PB
9031 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9032 _("only SUBS PC, LR, #const allowed"));
9033 constraint (inst.reloc.exp.X_op != O_constant,
9034 _("expression too complex"));
9035 constraint (inst.reloc.exp.X_add_number < 0
9036 || inst.reloc.exp.X_add_number > 0xff,
9037 _("immediate value out of range"));
9038 inst.instruction = T2_SUBS_PC_LR
9039 | inst.reloc.exp.X_add_number;
9040 inst.reloc.type = BFD_RELOC_UNUSED;
9041 return;
9042 }
9043 else if (Rs == REG_PC)
16805f35
PB
9044 {
9045 /* Always use addw/subw. */
9046 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9047 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9048 }
9049 else
9050 {
9051 inst.instruction = THUMB_OP32 (inst.instruction);
9052 inst.instruction = (inst.instruction & 0xe1ffffff)
9053 | 0x10000000;
9054 if (flags)
9055 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9056 else
9057 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9058 }
dc4503c6
PB
9059 inst.instruction |= Rd << 8;
9060 inst.instruction |= Rs << 16;
0110f2b8 9061 }
b99bd4ef 9062 }
c19d1205
ZW
9063 else
9064 {
9065 Rn = inst.operands[2].reg;
9066 /* See if we can do this with a 16-bit instruction. */
9067 if (!inst.operands[2].shifted && inst.size_req != 4)
9068 {
e27ec89e
PB
9069 if (Rd > 7 || Rs > 7 || Rn > 7)
9070 narrow = FALSE;
9071
9072 if (narrow)
c19d1205 9073 {
e27ec89e
PB
9074 inst.instruction = ((inst.instruction == T_MNEM_adds
9075 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9076 ? T_OPCODE_ADD_R3
9077 : T_OPCODE_SUB_R3);
9078 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9079 return;
9080 }
b99bd4ef 9081
7e806470 9082 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9083 {
7e806470
PB
9084 /* Thumb-1 cores (except v6-M) require at least one high
9085 register in a narrow non flag setting add. */
9086 if (Rd > 7 || Rn > 7
9087 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9088 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9089 {
7e806470
PB
9090 if (Rd == Rn)
9091 {
9092 Rn = Rs;
9093 Rs = Rd;
9094 }
c19d1205
ZW
9095 inst.instruction = T_OPCODE_ADD_HI;
9096 inst.instruction |= (Rd & 8) << 4;
9097 inst.instruction |= (Rd & 7);
9098 inst.instruction |= Rn << 3;
9099 return;
9100 }
c19d1205
ZW
9101 }
9102 }
c921be7d 9103
fdfde340
JM
9104 constraint (Rd == REG_PC, BAD_PC);
9105 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9106 constraint (Rs == REG_PC, BAD_PC);
9107 reject_bad_reg (Rn);
9108
c19d1205
ZW
9109 /* If we get here, it can't be done in 16 bits. */
9110 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9111 _("shift must be constant"));
9112 inst.instruction = THUMB_OP32 (inst.instruction);
9113 inst.instruction |= Rd << 8;
9114 inst.instruction |= Rs << 16;
9115 encode_thumb32_shifted_operand (2);
9116 }
9117 }
9118 else
9119 {
9120 constraint (inst.instruction == T_MNEM_adds
9121 || inst.instruction == T_MNEM_subs,
9122 BAD_THUMB32);
b99bd4ef 9123
c19d1205 9124 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9125 {
c19d1205
ZW
9126 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9127 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9128 BAD_HIREG);
9129
9130 inst.instruction = (inst.instruction == T_MNEM_add
9131 ? 0x0000 : 0x8000);
9132 inst.instruction |= (Rd << 4) | Rs;
9133 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9134 return;
9135 }
9136
c19d1205
ZW
9137 Rn = inst.operands[2].reg;
9138 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9139
c19d1205
ZW
9140 /* We now have Rd, Rs, and Rn set to registers. */
9141 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9142 {
c19d1205
ZW
9143 /* Can't do this for SUB. */
9144 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9145 inst.instruction = T_OPCODE_ADD_HI;
9146 inst.instruction |= (Rd & 8) << 4;
9147 inst.instruction |= (Rd & 7);
9148 if (Rs == Rd)
9149 inst.instruction |= Rn << 3;
9150 else if (Rn == Rd)
9151 inst.instruction |= Rs << 3;
9152 else
9153 constraint (1, _("dest must overlap one source register"));
9154 }
9155 else
9156 {
9157 inst.instruction = (inst.instruction == T_MNEM_add
9158 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9159 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9160 }
b99bd4ef 9161 }
b99bd4ef
NC
9162}
9163
c19d1205
ZW
9164static void
9165do_t_adr (void)
9166{
fdfde340
JM
9167 unsigned Rd;
9168
9169 Rd = inst.operands[0].reg;
9170 reject_bad_reg (Rd);
9171
9172 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9173 {
9174 /* Defer to section relaxation. */
9175 inst.relax = inst.instruction;
9176 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9177 inst.instruction |= Rd << 4;
0110f2b8
PB
9178 }
9179 else if (unified_syntax && inst.size_req != 2)
e9f89963 9180 {
0110f2b8 9181 /* Generate a 32-bit opcode. */
e9f89963 9182 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9183 inst.instruction |= Rd << 8;
e9f89963
PB
9184 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9185 inst.reloc.pc_rel = 1;
9186 }
9187 else
9188 {
0110f2b8 9189 /* Generate a 16-bit opcode. */
e9f89963
PB
9190 inst.instruction = THUMB_OP16 (inst.instruction);
9191 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9192 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9193 inst.reloc.pc_rel = 1;
b99bd4ef 9194
fdfde340 9195 inst.instruction |= Rd << 4;
e9f89963 9196 }
c19d1205 9197}
b99bd4ef 9198
c19d1205
ZW
9199/* Arithmetic instructions for which there is just one 16-bit
9200 instruction encoding, and it allows only two low registers.
9201 For maximal compatibility with ARM syntax, we allow three register
9202 operands even when Thumb-32 instructions are not available, as long
9203 as the first two are identical. For instance, both "sbc r0,r1" and
9204 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9205static void
c19d1205 9206do_t_arit3 (void)
b99bd4ef 9207{
c19d1205 9208 int Rd, Rs, Rn;
b99bd4ef 9209
c19d1205
ZW
9210 Rd = inst.operands[0].reg;
9211 Rs = (inst.operands[1].present
9212 ? inst.operands[1].reg /* Rd, Rs, foo */
9213 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9214 Rn = inst.operands[2].reg;
b99bd4ef 9215
fdfde340
JM
9216 reject_bad_reg (Rd);
9217 reject_bad_reg (Rs);
9218 if (inst.operands[2].isreg)
9219 reject_bad_reg (Rn);
9220
c19d1205 9221 if (unified_syntax)
b99bd4ef 9222 {
c19d1205
ZW
9223 if (!inst.operands[2].isreg)
9224 {
9225 /* For an immediate, we always generate a 32-bit opcode;
9226 section relaxation will shrink it later if possible. */
9227 inst.instruction = THUMB_OP32 (inst.instruction);
9228 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9229 inst.instruction |= Rd << 8;
9230 inst.instruction |= Rs << 16;
9231 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9232 }
9233 else
9234 {
e27ec89e
PB
9235 bfd_boolean narrow;
9236
c19d1205 9237 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9238 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9239 narrow = !in_it_block ();
e27ec89e 9240 else
e07e6e58 9241 narrow = in_it_block ();
e27ec89e
PB
9242
9243 if (Rd > 7 || Rn > 7 || Rs > 7)
9244 narrow = FALSE;
9245 if (inst.operands[2].shifted)
9246 narrow = FALSE;
9247 if (inst.size_req == 4)
9248 narrow = FALSE;
9249
9250 if (narrow
c19d1205
ZW
9251 && Rd == Rs)
9252 {
9253 inst.instruction = THUMB_OP16 (inst.instruction);
9254 inst.instruction |= Rd;
9255 inst.instruction |= Rn << 3;
9256 return;
9257 }
b99bd4ef 9258
c19d1205
ZW
9259 /* If we get here, it can't be done in 16 bits. */
9260 constraint (inst.operands[2].shifted
9261 && inst.operands[2].immisreg,
9262 _("shift must be constant"));
9263 inst.instruction = THUMB_OP32 (inst.instruction);
9264 inst.instruction |= Rd << 8;
9265 inst.instruction |= Rs << 16;
9266 encode_thumb32_shifted_operand (2);
9267 }
a737bd4d 9268 }
c19d1205 9269 else
b99bd4ef 9270 {
c19d1205
ZW
9271 /* On its face this is a lie - the instruction does set the
9272 flags. However, the only supported mnemonic in this mode
9273 says it doesn't. */
9274 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9275
c19d1205
ZW
9276 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9277 _("unshifted register required"));
9278 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9279 constraint (Rd != Rs,
9280 _("dest and source1 must be the same register"));
a737bd4d 9281
c19d1205
ZW
9282 inst.instruction = THUMB_OP16 (inst.instruction);
9283 inst.instruction |= Rd;
9284 inst.instruction |= Rn << 3;
b99bd4ef 9285 }
a737bd4d 9286}
b99bd4ef 9287
c19d1205
ZW
9288/* Similarly, but for instructions where the arithmetic operation is
9289 commutative, so we can allow either of them to be different from
9290 the destination operand in a 16-bit instruction. For instance, all
9291 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9292 accepted. */
9293static void
9294do_t_arit3c (void)
a737bd4d 9295{
c19d1205 9296 int Rd, Rs, Rn;
b99bd4ef 9297
c19d1205
ZW
9298 Rd = inst.operands[0].reg;
9299 Rs = (inst.operands[1].present
9300 ? inst.operands[1].reg /* Rd, Rs, foo */
9301 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9302 Rn = inst.operands[2].reg;
c921be7d 9303
fdfde340
JM
9304 reject_bad_reg (Rd);
9305 reject_bad_reg (Rs);
9306 if (inst.operands[2].isreg)
9307 reject_bad_reg (Rn);
a737bd4d 9308
c19d1205 9309 if (unified_syntax)
a737bd4d 9310 {
c19d1205 9311 if (!inst.operands[2].isreg)
b99bd4ef 9312 {
c19d1205
ZW
9313 /* For an immediate, we always generate a 32-bit opcode;
9314 section relaxation will shrink it later if possible. */
9315 inst.instruction = THUMB_OP32 (inst.instruction);
9316 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9317 inst.instruction |= Rd << 8;
9318 inst.instruction |= Rs << 16;
9319 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9320 }
c19d1205 9321 else
a737bd4d 9322 {
e27ec89e
PB
9323 bfd_boolean narrow;
9324
c19d1205 9325 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9326 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9327 narrow = !in_it_block ();
e27ec89e 9328 else
e07e6e58 9329 narrow = in_it_block ();
e27ec89e
PB
9330
9331 if (Rd > 7 || Rn > 7 || Rs > 7)
9332 narrow = FALSE;
9333 if (inst.operands[2].shifted)
9334 narrow = FALSE;
9335 if (inst.size_req == 4)
9336 narrow = FALSE;
9337
9338 if (narrow)
a737bd4d 9339 {
c19d1205 9340 if (Rd == Rs)
a737bd4d 9341 {
c19d1205
ZW
9342 inst.instruction = THUMB_OP16 (inst.instruction);
9343 inst.instruction |= Rd;
9344 inst.instruction |= Rn << 3;
9345 return;
a737bd4d 9346 }
c19d1205 9347 if (Rd == Rn)
a737bd4d 9348 {
c19d1205
ZW
9349 inst.instruction = THUMB_OP16 (inst.instruction);
9350 inst.instruction |= Rd;
9351 inst.instruction |= Rs << 3;
9352 return;
a737bd4d
NC
9353 }
9354 }
c19d1205
ZW
9355
9356 /* If we get here, it can't be done in 16 bits. */
9357 constraint (inst.operands[2].shifted
9358 && inst.operands[2].immisreg,
9359 _("shift must be constant"));
9360 inst.instruction = THUMB_OP32 (inst.instruction);
9361 inst.instruction |= Rd << 8;
9362 inst.instruction |= Rs << 16;
9363 encode_thumb32_shifted_operand (2);
a737bd4d 9364 }
b99bd4ef 9365 }
c19d1205
ZW
9366 else
9367 {
9368 /* On its face this is a lie - the instruction does set the
9369 flags. However, the only supported mnemonic in this mode
9370 says it doesn't. */
9371 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9372
c19d1205
ZW
9373 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9374 _("unshifted register required"));
9375 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9376
9377 inst.instruction = THUMB_OP16 (inst.instruction);
9378 inst.instruction |= Rd;
9379
9380 if (Rd == Rs)
9381 inst.instruction |= Rn << 3;
9382 else if (Rd == Rn)
9383 inst.instruction |= Rs << 3;
9384 else
9385 constraint (1, _("dest must overlap one source register"));
9386 }
a737bd4d
NC
9387}
9388
62b3e311
PB
9389static void
9390do_t_barrier (void)
9391{
9392 if (inst.operands[0].present)
9393 {
9394 constraint ((inst.instruction & 0xf0) != 0x40
9395 && inst.operands[0].imm != 0xf,
bd3ba5d1 9396 _("bad barrier type"));
62b3e311
PB
9397 inst.instruction |= inst.operands[0].imm;
9398 }
9399 else
9400 inst.instruction |= 0xf;
9401}
9402
c19d1205
ZW
9403static void
9404do_t_bfc (void)
a737bd4d 9405{
fdfde340 9406 unsigned Rd;
c19d1205
ZW
9407 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9408 constraint (msb > 32, _("bit-field extends past end of register"));
9409 /* The instruction encoding stores the LSB and MSB,
9410 not the LSB and width. */
fdfde340
JM
9411 Rd = inst.operands[0].reg;
9412 reject_bad_reg (Rd);
9413 inst.instruction |= Rd << 8;
c19d1205
ZW
9414 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9415 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9416 inst.instruction |= msb - 1;
b99bd4ef
NC
9417}
9418
c19d1205
ZW
9419static void
9420do_t_bfi (void)
b99bd4ef 9421{
fdfde340 9422 int Rd, Rn;
c19d1205 9423 unsigned int msb;
b99bd4ef 9424
fdfde340
JM
9425 Rd = inst.operands[0].reg;
9426 reject_bad_reg (Rd);
9427
c19d1205
ZW
9428 /* #0 in second position is alternative syntax for bfc, which is
9429 the same instruction but with REG_PC in the Rm field. */
9430 if (!inst.operands[1].isreg)
fdfde340
JM
9431 Rn = REG_PC;
9432 else
9433 {
9434 Rn = inst.operands[1].reg;
9435 reject_bad_reg (Rn);
9436 }
b99bd4ef 9437
c19d1205
ZW
9438 msb = inst.operands[2].imm + inst.operands[3].imm;
9439 constraint (msb > 32, _("bit-field extends past end of register"));
9440 /* The instruction encoding stores the LSB and MSB,
9441 not the LSB and width. */
fdfde340
JM
9442 inst.instruction |= Rd << 8;
9443 inst.instruction |= Rn << 16;
c19d1205
ZW
9444 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9445 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9446 inst.instruction |= msb - 1;
b99bd4ef
NC
9447}
9448
c19d1205
ZW
9449static void
9450do_t_bfx (void)
b99bd4ef 9451{
fdfde340
JM
9452 unsigned Rd, Rn;
9453
9454 Rd = inst.operands[0].reg;
9455 Rn = inst.operands[1].reg;
9456
9457 reject_bad_reg (Rd);
9458 reject_bad_reg (Rn);
9459
c19d1205
ZW
9460 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9461 _("bit-field extends past end of register"));
fdfde340
JM
9462 inst.instruction |= Rd << 8;
9463 inst.instruction |= Rn << 16;
c19d1205
ZW
9464 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9465 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9466 inst.instruction |= inst.operands[3].imm - 1;
9467}
b99bd4ef 9468
c19d1205
ZW
9469/* ARM V5 Thumb BLX (argument parse)
9470 BLX <target_addr> which is BLX(1)
9471 BLX <Rm> which is BLX(2)
9472 Unfortunately, there are two different opcodes for this mnemonic.
9473 So, the insns[].value is not used, and the code here zaps values
9474 into inst.instruction.
b99bd4ef 9475
c19d1205
ZW
9476 ??? How to take advantage of the additional two bits of displacement
9477 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9478
c19d1205
ZW
9479static void
9480do_t_blx (void)
9481{
e07e6e58
NC
9482 set_it_insn_type_last ();
9483
c19d1205 9484 if (inst.operands[0].isreg)
fdfde340
JM
9485 {
9486 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9487 /* We have a register, so this is BLX(2). */
9488 inst.instruction |= inst.operands[0].reg << 3;
9489 }
b99bd4ef
NC
9490 else
9491 {
c19d1205 9492 /* No register. This must be BLX(1). */
2fc8bdac 9493 inst.instruction = 0xf000e800;
00adf2d4 9494 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9495 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9496 }
9497}
9498
c19d1205
ZW
9499static void
9500do_t_branch (void)
b99bd4ef 9501{
0110f2b8 9502 int opcode;
dfa9f0d5
PB
9503 int cond;
9504
e07e6e58
NC
9505 cond = inst.cond;
9506 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9507
9508 if (in_it_block ())
dfa9f0d5
PB
9509 {
9510 /* Conditional branches inside IT blocks are encoded as unconditional
9511 branches. */
9512 cond = COND_ALWAYS;
dfa9f0d5
PB
9513 }
9514 else
9515 cond = inst.cond;
9516
9517 if (cond != COND_ALWAYS)
0110f2b8
PB
9518 opcode = T_MNEM_bcond;
9519 else
9520 opcode = inst.instruction;
9521
9522 if (unified_syntax && inst.size_req == 4)
c19d1205 9523 {
0110f2b8 9524 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9525 if (cond == COND_ALWAYS)
0110f2b8 9526 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9527 else
9528 {
9c2799c2 9529 gas_assert (cond != 0xF);
dfa9f0d5 9530 inst.instruction |= cond << 22;
c19d1205
ZW
9531 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9532 }
9533 }
b99bd4ef
NC
9534 else
9535 {
0110f2b8 9536 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9537 if (cond == COND_ALWAYS)
c19d1205
ZW
9538 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9539 else
b99bd4ef 9540 {
dfa9f0d5 9541 inst.instruction |= cond << 8;
c19d1205 9542 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9543 }
0110f2b8
PB
9544 /* Allow section relaxation. */
9545 if (unified_syntax && inst.size_req != 2)
9546 inst.relax = opcode;
b99bd4ef 9547 }
c19d1205
ZW
9548
9549 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9550}
9551
9552static void
c19d1205 9553do_t_bkpt (void)
b99bd4ef 9554{
dfa9f0d5
PB
9555 constraint (inst.cond != COND_ALWAYS,
9556 _("instruction is always unconditional"));
c19d1205 9557 if (inst.operands[0].present)
b99bd4ef 9558 {
c19d1205
ZW
9559 constraint (inst.operands[0].imm > 255,
9560 _("immediate value out of range"));
9561 inst.instruction |= inst.operands[0].imm;
e07e6e58 9562 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9563 }
b99bd4ef
NC
9564}
9565
9566static void
c19d1205 9567do_t_branch23 (void)
b99bd4ef 9568{
e07e6e58 9569 set_it_insn_type_last ();
c19d1205 9570 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9571 inst.reloc.pc_rel = 1;
9572
4343666d 9573#if defined(OBJ_COFF)
c19d1205
ZW
9574 /* If the destination of the branch is a defined symbol which does not have
9575 the THUMB_FUNC attribute, then we must be calling a function which has
9576 the (interfacearm) attribute. We look for the Thumb entry point to that
9577 function and change the branch to refer to that function instead. */
9578 if ( inst.reloc.exp.X_op == O_symbol
9579 && inst.reloc.exp.X_add_symbol != NULL
9580 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9581 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9582 inst.reloc.exp.X_add_symbol =
9583 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9584#endif
90e4755a
RE
9585}
9586
9587static void
c19d1205 9588do_t_bx (void)
90e4755a 9589{
e07e6e58 9590 set_it_insn_type_last ();
c19d1205
ZW
9591 inst.instruction |= inst.operands[0].reg << 3;
9592 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9593 should cause the alignment to be checked once it is known. This is
9594 because BX PC only works if the instruction is word aligned. */
9595}
90e4755a 9596
c19d1205
ZW
9597static void
9598do_t_bxj (void)
9599{
fdfde340 9600 int Rm;
90e4755a 9601
e07e6e58 9602 set_it_insn_type_last ();
fdfde340
JM
9603 Rm = inst.operands[0].reg;
9604 reject_bad_reg (Rm);
9605 inst.instruction |= Rm << 16;
90e4755a
RE
9606}
9607
9608static void
c19d1205 9609do_t_clz (void)
90e4755a 9610{
fdfde340
JM
9611 unsigned Rd;
9612 unsigned Rm;
9613
9614 Rd = inst.operands[0].reg;
9615 Rm = inst.operands[1].reg;
9616
9617 reject_bad_reg (Rd);
9618 reject_bad_reg (Rm);
9619
9620 inst.instruction |= Rd << 8;
9621 inst.instruction |= Rm << 16;
9622 inst.instruction |= Rm;
c19d1205 9623}
90e4755a 9624
dfa9f0d5
PB
9625static void
9626do_t_cps (void)
9627{
e07e6e58 9628 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9629 inst.instruction |= inst.operands[0].imm;
9630}
9631
c19d1205
ZW
9632static void
9633do_t_cpsi (void)
9634{
e07e6e58 9635 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9636 if (unified_syntax
62b3e311
PB
9637 && (inst.operands[1].present || inst.size_req == 4)
9638 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9639 {
c19d1205
ZW
9640 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9641 inst.instruction = 0xf3af8000;
9642 inst.instruction |= imod << 9;
9643 inst.instruction |= inst.operands[0].imm << 5;
9644 if (inst.operands[1].present)
9645 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9646 }
c19d1205 9647 else
90e4755a 9648 {
62b3e311
PB
9649 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9650 && (inst.operands[0].imm & 4),
9651 _("selected processor does not support 'A' form "
9652 "of this instruction"));
9653 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9654 _("Thumb does not support the 2-argument "
9655 "form of this instruction"));
9656 inst.instruction |= inst.operands[0].imm;
90e4755a 9657 }
90e4755a
RE
9658}
9659
c19d1205
ZW
9660/* THUMB CPY instruction (argument parse). */
9661
90e4755a 9662static void
c19d1205 9663do_t_cpy (void)
90e4755a 9664{
c19d1205 9665 if (inst.size_req == 4)
90e4755a 9666 {
c19d1205
ZW
9667 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9668 inst.instruction |= inst.operands[0].reg << 8;
9669 inst.instruction |= inst.operands[1].reg;
90e4755a 9670 }
c19d1205 9671 else
90e4755a 9672 {
c19d1205
ZW
9673 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9674 inst.instruction |= (inst.operands[0].reg & 0x7);
9675 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9676 }
90e4755a
RE
9677}
9678
90e4755a 9679static void
25fe350b 9680do_t_cbz (void)
90e4755a 9681{
e07e6e58 9682 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9683 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9684 inst.instruction |= inst.operands[0].reg;
9685 inst.reloc.pc_rel = 1;
9686 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9687}
90e4755a 9688
62b3e311
PB
9689static void
9690do_t_dbg (void)
9691{
9692 inst.instruction |= inst.operands[0].imm;
9693}
9694
9695static void
9696do_t_div (void)
9697{
fdfde340
JM
9698 unsigned Rd, Rn, Rm;
9699
9700 Rd = inst.operands[0].reg;
9701 Rn = (inst.operands[1].present
9702 ? inst.operands[1].reg : Rd);
9703 Rm = inst.operands[2].reg;
9704
9705 reject_bad_reg (Rd);
9706 reject_bad_reg (Rn);
9707 reject_bad_reg (Rm);
9708
9709 inst.instruction |= Rd << 8;
9710 inst.instruction |= Rn << 16;
9711 inst.instruction |= Rm;
62b3e311
PB
9712}
9713
c19d1205
ZW
9714static void
9715do_t_hint (void)
9716{
9717 if (unified_syntax && inst.size_req == 4)
9718 inst.instruction = THUMB_OP32 (inst.instruction);
9719 else
9720 inst.instruction = THUMB_OP16 (inst.instruction);
9721}
90e4755a 9722
c19d1205
ZW
9723static void
9724do_t_it (void)
9725{
9726 unsigned int cond = inst.operands[0].imm;
e27ec89e 9727
e07e6e58
NC
9728 set_it_insn_type (IT_INSN);
9729 now_it.mask = (inst.instruction & 0xf) | 0x10;
9730 now_it.cc = cond;
e27ec89e
PB
9731
9732 /* If the condition is a negative condition, invert the mask. */
c19d1205 9733 if ((cond & 0x1) == 0x0)
90e4755a 9734 {
c19d1205 9735 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9736
c19d1205
ZW
9737 if ((mask & 0x7) == 0)
9738 /* no conversion needed */;
9739 else if ((mask & 0x3) == 0)
e27ec89e
PB
9740 mask ^= 0x8;
9741 else if ((mask & 0x1) == 0)
9742 mask ^= 0xC;
c19d1205 9743 else
e27ec89e 9744 mask ^= 0xE;
90e4755a 9745
e27ec89e
PB
9746 inst.instruction &= 0xfff0;
9747 inst.instruction |= mask;
c19d1205 9748 }
90e4755a 9749
c19d1205
ZW
9750 inst.instruction |= cond << 4;
9751}
90e4755a 9752
3c707909
PB
9753/* Helper function used for both push/pop and ldm/stm. */
9754static void
9755encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9756{
9757 bfd_boolean load;
9758
9759 load = (inst.instruction & (1 << 20)) != 0;
9760
9761 if (mask & (1 << 13))
9762 inst.error = _("SP not allowed in register list");
1e5b0379
NC
9763
9764 if ((mask & (1 << base)) != 0
9765 && writeback)
9766 inst.error = _("having the base register in the register list when "
9767 "using write back is UNPREDICTABLE");
9768
3c707909
PB
9769 if (load)
9770 {
e07e6e58
NC
9771 if (mask & (1 << 15))
9772 {
9773 if (mask & (1 << 14))
9774 inst.error = _("LR and PC should not both be in register list");
9775 else
9776 set_it_insn_type_last ();
9777 }
3c707909
PB
9778 }
9779 else
9780 {
9781 if (mask & (1 << 15))
9782 inst.error = _("PC not allowed in register list");
3c707909
PB
9783 }
9784
9785 if ((mask & (mask - 1)) == 0)
9786 {
9787 /* Single register transfers implemented as str/ldr. */
9788 if (writeback)
9789 {
9790 if (inst.instruction & (1 << 23))
9791 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9792 else
9793 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9794 }
9795 else
9796 {
9797 if (inst.instruction & (1 << 23))
9798 inst.instruction = 0x00800000; /* ia -> [base] */
9799 else
9800 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9801 }
9802
9803 inst.instruction |= 0xf8400000;
9804 if (load)
9805 inst.instruction |= 0x00100000;
9806
5f4273c7 9807 mask = ffs (mask) - 1;
3c707909
PB
9808 mask <<= 12;
9809 }
9810 else if (writeback)
9811 inst.instruction |= WRITE_BACK;
9812
9813 inst.instruction |= mask;
9814 inst.instruction |= base << 16;
9815}
9816
c19d1205
ZW
9817static void
9818do_t_ldmstm (void)
9819{
9820 /* This really doesn't seem worth it. */
9821 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9822 _("expression too complex"));
9823 constraint (inst.operands[1].writeback,
9824 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9825
c19d1205
ZW
9826 if (unified_syntax)
9827 {
3c707909
PB
9828 bfd_boolean narrow;
9829 unsigned mask;
9830
9831 narrow = FALSE;
c19d1205
ZW
9832 /* See if we can use a 16-bit instruction. */
9833 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9834 && inst.size_req != 4
3c707909 9835 && !(inst.operands[1].imm & ~0xff))
90e4755a 9836 {
3c707909 9837 mask = 1 << inst.operands[0].reg;
90e4755a 9838
3c707909
PB
9839 if (inst.operands[0].reg <= 7
9840 && (inst.instruction == T_MNEM_stmia
9841 ? inst.operands[0].writeback
9842 : (inst.operands[0].writeback
9843 == !(inst.operands[1].imm & mask))))
90e4755a 9844 {
3c707909
PB
9845 if (inst.instruction == T_MNEM_stmia
9846 && (inst.operands[1].imm & mask)
9847 && (inst.operands[1].imm & (mask - 1)))
1e5b0379 9848 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 9849 inst.operands[0].reg);
3c707909
PB
9850
9851 inst.instruction = THUMB_OP16 (inst.instruction);
9852 inst.instruction |= inst.operands[0].reg << 8;
9853 inst.instruction |= inst.operands[1].imm;
9854 narrow = TRUE;
90e4755a 9855 }
3c707909
PB
9856 else if (inst.operands[0] .reg == REG_SP
9857 && inst.operands[0].writeback)
90e4755a 9858 {
3c707909
PB
9859 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9860 ? T_MNEM_push : T_MNEM_pop);
9861 inst.instruction |= inst.operands[1].imm;
9862 narrow = TRUE;
90e4755a 9863 }
3c707909
PB
9864 }
9865
9866 if (!narrow)
9867 {
c19d1205
ZW
9868 if (inst.instruction < 0xffff)
9869 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9870
5f4273c7
NC
9871 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9872 inst.operands[0].writeback);
90e4755a
RE
9873 }
9874 }
c19d1205 9875 else
90e4755a 9876 {
c19d1205
ZW
9877 constraint (inst.operands[0].reg > 7
9878 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9879 constraint (inst.instruction != T_MNEM_ldmia
9880 && inst.instruction != T_MNEM_stmia,
9881 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9882 if (inst.instruction == T_MNEM_stmia)
f03698e6 9883 {
c19d1205
ZW
9884 if (!inst.operands[0].writeback)
9885 as_warn (_("this instruction will write back the base register"));
9886 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9887 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 9888 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 9889 inst.operands[0].reg);
f03698e6 9890 }
c19d1205 9891 else
90e4755a 9892 {
c19d1205
ZW
9893 if (!inst.operands[0].writeback
9894 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9895 as_warn (_("this instruction will write back the base register"));
9896 else if (inst.operands[0].writeback
9897 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9898 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9899 }
9900
c19d1205
ZW
9901 inst.instruction = THUMB_OP16 (inst.instruction);
9902 inst.instruction |= inst.operands[0].reg << 8;
9903 inst.instruction |= inst.operands[1].imm;
9904 }
9905}
e28cd48c 9906
c19d1205
ZW
9907static void
9908do_t_ldrex (void)
9909{
9910 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9911 || inst.operands[1].postind || inst.operands[1].writeback
9912 || inst.operands[1].immisreg || inst.operands[1].shifted
9913 || inst.operands[1].negative,
01cfc07f 9914 BAD_ADDR_MODE);
e28cd48c 9915
5be8be5d
DG
9916 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9917
c19d1205
ZW
9918 inst.instruction |= inst.operands[0].reg << 12;
9919 inst.instruction |= inst.operands[1].reg << 16;
9920 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9921}
e28cd48c 9922
c19d1205
ZW
9923static void
9924do_t_ldrexd (void)
9925{
9926 if (!inst.operands[1].present)
1cac9012 9927 {
c19d1205
ZW
9928 constraint (inst.operands[0].reg == REG_LR,
9929 _("r14 not allowed as first register "
9930 "when second register is omitted"));
9931 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9932 }
c19d1205
ZW
9933 constraint (inst.operands[0].reg == inst.operands[1].reg,
9934 BAD_OVERLAP);
b99bd4ef 9935
c19d1205
ZW
9936 inst.instruction |= inst.operands[0].reg << 12;
9937 inst.instruction |= inst.operands[1].reg << 8;
9938 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9939}
9940
9941static void
c19d1205 9942do_t_ldst (void)
b99bd4ef 9943{
0110f2b8
PB
9944 unsigned long opcode;
9945 int Rn;
9946
e07e6e58
NC
9947 if (inst.operands[0].isreg
9948 && !inst.operands[0].preind
9949 && inst.operands[0].reg == REG_PC)
9950 set_it_insn_type_last ();
9951
0110f2b8 9952 opcode = inst.instruction;
c19d1205 9953 if (unified_syntax)
b99bd4ef 9954 {
53365c0d
PB
9955 if (!inst.operands[1].isreg)
9956 {
9957 if (opcode <= 0xffff)
9958 inst.instruction = THUMB_OP32 (opcode);
9959 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9960 return;
9961 }
0110f2b8
PB
9962 if (inst.operands[1].isreg
9963 && !inst.operands[1].writeback
c19d1205
ZW
9964 && !inst.operands[1].shifted && !inst.operands[1].postind
9965 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9966 && opcode <= 0xffff
9967 && inst.size_req != 4)
c19d1205 9968 {
0110f2b8
PB
9969 /* Insn may have a 16-bit form. */
9970 Rn = inst.operands[1].reg;
9971 if (inst.operands[1].immisreg)
9972 {
9973 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9974 /* [Rn, Rik] */
0110f2b8
PB
9975 if (Rn <= 7 && inst.operands[1].imm <= 7)
9976 goto op16;
5be8be5d
DG
9977 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
9978 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
9979 }
9980 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9981 && opcode != T_MNEM_ldrsb)
9982 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9983 || (Rn == REG_SP && opcode == T_MNEM_str))
9984 {
9985 /* [Rn, #const] */
9986 if (Rn > 7)
9987 {
9988 if (Rn == REG_PC)
9989 {
9990 if (inst.reloc.pc_rel)
9991 opcode = T_MNEM_ldr_pc2;
9992 else
9993 opcode = T_MNEM_ldr_pc;
9994 }
9995 else
9996 {
9997 if (opcode == T_MNEM_ldr)
9998 opcode = T_MNEM_ldr_sp;
9999 else
10000 opcode = T_MNEM_str_sp;
10001 }
10002 inst.instruction = inst.operands[0].reg << 8;
10003 }
10004 else
10005 {
10006 inst.instruction = inst.operands[0].reg;
10007 inst.instruction |= inst.operands[1].reg << 3;
10008 }
10009 inst.instruction |= THUMB_OP16 (opcode);
10010 if (inst.size_req == 2)
10011 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10012 else
10013 inst.relax = opcode;
10014 return;
10015 }
c19d1205 10016 }
0110f2b8 10017 /* Definitely a 32-bit variant. */
5be8be5d
DG
10018
10019 /* Do some validations regarding addressing modes. */
10020 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10021 && opcode != T_MNEM_str)
10022 reject_bad_reg (inst.operands[1].imm);
10023
0110f2b8 10024 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10027 return;
10028 }
10029
c19d1205
ZW
10030 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10031
10032 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10033 {
c19d1205
ZW
10034 /* Only [Rn,Rm] is acceptable. */
10035 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10036 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10037 || inst.operands[1].postind || inst.operands[1].shifted
10038 || inst.operands[1].negative,
10039 _("Thumb does not support this addressing mode"));
10040 inst.instruction = THUMB_OP16 (inst.instruction);
10041 goto op16;
b99bd4ef 10042 }
5f4273c7 10043
c19d1205
ZW
10044 inst.instruction = THUMB_OP16 (inst.instruction);
10045 if (!inst.operands[1].isreg)
10046 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10047 return;
b99bd4ef 10048
c19d1205
ZW
10049 constraint (!inst.operands[1].preind
10050 || inst.operands[1].shifted
10051 || inst.operands[1].writeback,
10052 _("Thumb does not support this addressing mode"));
10053 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10054 {
c19d1205
ZW
10055 constraint (inst.instruction & 0x0600,
10056 _("byte or halfword not valid for base register"));
10057 constraint (inst.operands[1].reg == REG_PC
10058 && !(inst.instruction & THUMB_LOAD_BIT),
10059 _("r15 based store not allowed"));
10060 constraint (inst.operands[1].immisreg,
10061 _("invalid base register for register offset"));
b99bd4ef 10062
c19d1205
ZW
10063 if (inst.operands[1].reg == REG_PC)
10064 inst.instruction = T_OPCODE_LDR_PC;
10065 else if (inst.instruction & THUMB_LOAD_BIT)
10066 inst.instruction = T_OPCODE_LDR_SP;
10067 else
10068 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10069
c19d1205
ZW
10070 inst.instruction |= inst.operands[0].reg << 8;
10071 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10072 return;
10073 }
90e4755a 10074
c19d1205
ZW
10075 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10076 if (!inst.operands[1].immisreg)
10077 {
10078 /* Immediate offset. */
10079 inst.instruction |= inst.operands[0].reg;
10080 inst.instruction |= inst.operands[1].reg << 3;
10081 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10082 return;
10083 }
90e4755a 10084
c19d1205
ZW
10085 /* Register offset. */
10086 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10087 constraint (inst.operands[1].negative,
10088 _("Thumb does not support this addressing mode"));
90e4755a 10089
c19d1205
ZW
10090 op16:
10091 switch (inst.instruction)
10092 {
10093 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10094 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10095 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10096 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10097 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10098 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10099 case 0x5600 /* ldrsb */:
10100 case 0x5e00 /* ldrsh */: break;
10101 default: abort ();
10102 }
90e4755a 10103
c19d1205
ZW
10104 inst.instruction |= inst.operands[0].reg;
10105 inst.instruction |= inst.operands[1].reg << 3;
10106 inst.instruction |= inst.operands[1].imm << 6;
10107}
90e4755a 10108
c19d1205
ZW
10109static void
10110do_t_ldstd (void)
10111{
10112 if (!inst.operands[1].present)
b99bd4ef 10113 {
c19d1205
ZW
10114 inst.operands[1].reg = inst.operands[0].reg + 1;
10115 constraint (inst.operands[0].reg == REG_LR,
10116 _("r14 not allowed here"));
b99bd4ef 10117 }
c19d1205
ZW
10118 inst.instruction |= inst.operands[0].reg << 12;
10119 inst.instruction |= inst.operands[1].reg << 8;
10120 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10121}
10122
c19d1205
ZW
10123static void
10124do_t_ldstt (void)
10125{
10126 inst.instruction |= inst.operands[0].reg << 12;
10127 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10128}
a737bd4d 10129
b99bd4ef 10130static void
c19d1205 10131do_t_mla (void)
b99bd4ef 10132{
fdfde340 10133 unsigned Rd, Rn, Rm, Ra;
c921be7d 10134
fdfde340
JM
10135 Rd = inst.operands[0].reg;
10136 Rn = inst.operands[1].reg;
10137 Rm = inst.operands[2].reg;
10138 Ra = inst.operands[3].reg;
10139
10140 reject_bad_reg (Rd);
10141 reject_bad_reg (Rn);
10142 reject_bad_reg (Rm);
10143 reject_bad_reg (Ra);
10144
10145 inst.instruction |= Rd << 8;
10146 inst.instruction |= Rn << 16;
10147 inst.instruction |= Rm;
10148 inst.instruction |= Ra << 12;
c19d1205 10149}
b99bd4ef 10150
c19d1205
ZW
10151static void
10152do_t_mlal (void)
10153{
fdfde340
JM
10154 unsigned RdLo, RdHi, Rn, Rm;
10155
10156 RdLo = inst.operands[0].reg;
10157 RdHi = inst.operands[1].reg;
10158 Rn = inst.operands[2].reg;
10159 Rm = inst.operands[3].reg;
10160
10161 reject_bad_reg (RdLo);
10162 reject_bad_reg (RdHi);
10163 reject_bad_reg (Rn);
10164 reject_bad_reg (Rm);
10165
10166 inst.instruction |= RdLo << 12;
10167 inst.instruction |= RdHi << 8;
10168 inst.instruction |= Rn << 16;
10169 inst.instruction |= Rm;
c19d1205 10170}
b99bd4ef 10171
c19d1205
ZW
10172static void
10173do_t_mov_cmp (void)
10174{
fdfde340
JM
10175 unsigned Rn, Rm;
10176
10177 Rn = inst.operands[0].reg;
10178 Rm = inst.operands[1].reg;
10179
e07e6e58
NC
10180 if (Rn == REG_PC)
10181 set_it_insn_type_last ();
10182
c19d1205 10183 if (unified_syntax)
b99bd4ef 10184 {
c19d1205
ZW
10185 int r0off = (inst.instruction == T_MNEM_mov
10186 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10187 unsigned long opcode;
3d388997
PB
10188 bfd_boolean narrow;
10189 bfd_boolean low_regs;
10190
fdfde340 10191 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10192 opcode = inst.instruction;
e07e6e58 10193 if (in_it_block ())
0110f2b8 10194 narrow = opcode != T_MNEM_movs;
3d388997 10195 else
0110f2b8 10196 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10197 if (inst.size_req == 4
10198 || inst.operands[1].shifted)
10199 narrow = FALSE;
10200
efd81785
PB
10201 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10202 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10203 && !inst.operands[1].shifted
fdfde340
JM
10204 && Rn == REG_PC
10205 && Rm == REG_LR)
efd81785
PB
10206 {
10207 inst.instruction = T2_SUBS_PC_LR;
10208 return;
10209 }
10210
fdfde340
JM
10211 if (opcode == T_MNEM_cmp)
10212 {
10213 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10214 if (narrow)
10215 {
10216 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10217 but valid. */
10218 warn_deprecated_sp (Rm);
10219 /* R15 was documented as a valid choice for Rm in ARMv6,
10220 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10221 tools reject R15, so we do too. */
10222 constraint (Rm == REG_PC, BAD_PC);
10223 }
10224 else
10225 reject_bad_reg (Rm);
fdfde340
JM
10226 }
10227 else if (opcode == T_MNEM_mov
10228 || opcode == T_MNEM_movs)
10229 {
10230 if (inst.operands[1].isreg)
10231 {
10232 if (opcode == T_MNEM_movs)
10233 {
10234 reject_bad_reg (Rn);
10235 reject_bad_reg (Rm);
10236 }
10237 else if ((Rn == REG_SP || Rn == REG_PC)
10238 && (Rm == REG_SP || Rm == REG_PC))
10239 reject_bad_reg (Rm);
10240 }
10241 else
10242 reject_bad_reg (Rn);
10243 }
10244
c19d1205
ZW
10245 if (!inst.operands[1].isreg)
10246 {
0110f2b8 10247 /* Immediate operand. */
e07e6e58 10248 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10249 narrow = 0;
10250 if (low_regs && narrow)
10251 {
10252 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10253 inst.instruction |= Rn << 8;
0110f2b8
PB
10254 if (inst.size_req == 2)
10255 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10256 else
10257 inst.relax = opcode;
10258 }
10259 else
10260 {
10261 inst.instruction = THUMB_OP32 (inst.instruction);
10262 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10263 inst.instruction |= Rn << r0off;
0110f2b8
PB
10264 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10265 }
c19d1205 10266 }
728ca7c9
PB
10267 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10268 && (inst.instruction == T_MNEM_mov
10269 || inst.instruction == T_MNEM_movs))
10270 {
10271 /* Register shifts are encoded as separate shift instructions. */
10272 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10273
e07e6e58 10274 if (in_it_block ())
728ca7c9
PB
10275 narrow = !flags;
10276 else
10277 narrow = flags;
10278
10279 if (inst.size_req == 4)
10280 narrow = FALSE;
10281
10282 if (!low_regs || inst.operands[1].imm > 7)
10283 narrow = FALSE;
10284
fdfde340 10285 if (Rn != Rm)
728ca7c9
PB
10286 narrow = FALSE;
10287
10288 switch (inst.operands[1].shift_kind)
10289 {
10290 case SHIFT_LSL:
10291 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10292 break;
10293 case SHIFT_ASR:
10294 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10295 break;
10296 case SHIFT_LSR:
10297 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10298 break;
10299 case SHIFT_ROR:
10300 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10301 break;
10302 default:
5f4273c7 10303 abort ();
728ca7c9
PB
10304 }
10305
10306 inst.instruction = opcode;
10307 if (narrow)
10308 {
fdfde340 10309 inst.instruction |= Rn;
728ca7c9
PB
10310 inst.instruction |= inst.operands[1].imm << 3;
10311 }
10312 else
10313 {
10314 if (flags)
10315 inst.instruction |= CONDS_BIT;
10316
fdfde340
JM
10317 inst.instruction |= Rn << 8;
10318 inst.instruction |= Rm << 16;
728ca7c9
PB
10319 inst.instruction |= inst.operands[1].imm;
10320 }
10321 }
3d388997 10322 else if (!narrow)
c19d1205 10323 {
728ca7c9
PB
10324 /* Some mov with immediate shift have narrow variants.
10325 Register shifts are handled above. */
10326 if (low_regs && inst.operands[1].shifted
10327 && (inst.instruction == T_MNEM_mov
10328 || inst.instruction == T_MNEM_movs))
10329 {
e07e6e58 10330 if (in_it_block ())
728ca7c9
PB
10331 narrow = (inst.instruction == T_MNEM_mov);
10332 else
10333 narrow = (inst.instruction == T_MNEM_movs);
10334 }
10335
10336 if (narrow)
10337 {
10338 switch (inst.operands[1].shift_kind)
10339 {
10340 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10341 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10342 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10343 default: narrow = FALSE; break;
10344 }
10345 }
10346
10347 if (narrow)
10348 {
fdfde340
JM
10349 inst.instruction |= Rn;
10350 inst.instruction |= Rm << 3;
728ca7c9
PB
10351 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10352 }
10353 else
10354 {
10355 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10356 inst.instruction |= Rn << r0off;
728ca7c9
PB
10357 encode_thumb32_shifted_operand (1);
10358 }
c19d1205
ZW
10359 }
10360 else
10361 switch (inst.instruction)
10362 {
10363 case T_MNEM_mov:
10364 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10365 inst.instruction |= (Rn & 0x8) << 4;
10366 inst.instruction |= (Rn & 0x7);
10367 inst.instruction |= Rm << 3;
c19d1205 10368 break;
b99bd4ef 10369
c19d1205
ZW
10370 case T_MNEM_movs:
10371 /* We know we have low registers at this point.
10372 Generate ADD Rd, Rs, #0. */
10373 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10374 inst.instruction |= Rn;
10375 inst.instruction |= Rm << 3;
c19d1205
ZW
10376 break;
10377
10378 case T_MNEM_cmp:
3d388997 10379 if (low_regs)
c19d1205
ZW
10380 {
10381 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10382 inst.instruction |= Rn;
10383 inst.instruction |= Rm << 3;
c19d1205
ZW
10384 }
10385 else
10386 {
10387 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10388 inst.instruction |= (Rn & 0x8) << 4;
10389 inst.instruction |= (Rn & 0x7);
10390 inst.instruction |= Rm << 3;
c19d1205
ZW
10391 }
10392 break;
10393 }
b99bd4ef
NC
10394 return;
10395 }
10396
c19d1205 10397 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10398
10399 /* PR 10443: Do not silently ignore shifted operands. */
10400 constraint (inst.operands[1].shifted,
10401 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10402
c19d1205 10403 if (inst.operands[1].isreg)
b99bd4ef 10404 {
fdfde340 10405 if (Rn < 8 && Rm < 8)
b99bd4ef 10406 {
c19d1205
ZW
10407 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10408 since a MOV instruction produces unpredictable results. */
10409 if (inst.instruction == T_OPCODE_MOV_I8)
10410 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10411 else
c19d1205 10412 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10413
fdfde340
JM
10414 inst.instruction |= Rn;
10415 inst.instruction |= Rm << 3;
b99bd4ef
NC
10416 }
10417 else
10418 {
c19d1205
ZW
10419 if (inst.instruction == T_OPCODE_MOV_I8)
10420 inst.instruction = T_OPCODE_MOV_HR;
10421 else
10422 inst.instruction = T_OPCODE_CMP_HR;
10423 do_t_cpy ();
b99bd4ef
NC
10424 }
10425 }
c19d1205 10426 else
b99bd4ef 10427 {
fdfde340 10428 constraint (Rn > 7,
c19d1205 10429 _("only lo regs allowed with immediate"));
fdfde340 10430 inst.instruction |= Rn << 8;
c19d1205
ZW
10431 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10432 }
10433}
b99bd4ef 10434
c19d1205
ZW
10435static void
10436do_t_mov16 (void)
10437{
fdfde340 10438 unsigned Rd;
b6895b4f
PB
10439 bfd_vma imm;
10440 bfd_boolean top;
10441
10442 top = (inst.instruction & 0x00800000) != 0;
10443 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10444 {
10445 constraint (top, _(":lower16: not allowed this instruction"));
10446 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10447 }
10448 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10449 {
10450 constraint (!top, _(":upper16: not allowed this instruction"));
10451 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10452 }
10453
fdfde340
JM
10454 Rd = inst.operands[0].reg;
10455 reject_bad_reg (Rd);
10456
10457 inst.instruction |= Rd << 8;
b6895b4f
PB
10458 if (inst.reloc.type == BFD_RELOC_UNUSED)
10459 {
10460 imm = inst.reloc.exp.X_add_number;
10461 inst.instruction |= (imm & 0xf000) << 4;
10462 inst.instruction |= (imm & 0x0800) << 15;
10463 inst.instruction |= (imm & 0x0700) << 4;
10464 inst.instruction |= (imm & 0x00ff);
10465 }
c19d1205 10466}
b99bd4ef 10467
c19d1205
ZW
10468static void
10469do_t_mvn_tst (void)
10470{
fdfde340 10471 unsigned Rn, Rm;
c921be7d 10472
fdfde340
JM
10473 Rn = inst.operands[0].reg;
10474 Rm = inst.operands[1].reg;
10475
10476 if (inst.instruction == T_MNEM_cmp
10477 || inst.instruction == T_MNEM_cmn)
10478 constraint (Rn == REG_PC, BAD_PC);
10479 else
10480 reject_bad_reg (Rn);
10481 reject_bad_reg (Rm);
10482
c19d1205
ZW
10483 if (unified_syntax)
10484 {
10485 int r0off = (inst.instruction == T_MNEM_mvn
10486 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10487 bfd_boolean narrow;
10488
10489 if (inst.size_req == 4
10490 || inst.instruction > 0xffff
10491 || inst.operands[1].shifted
fdfde340 10492 || Rn > 7 || Rm > 7)
3d388997
PB
10493 narrow = FALSE;
10494 else if (inst.instruction == T_MNEM_cmn)
10495 narrow = TRUE;
10496 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10497 narrow = !in_it_block ();
3d388997 10498 else
e07e6e58 10499 narrow = in_it_block ();
3d388997 10500
c19d1205 10501 if (!inst.operands[1].isreg)
b99bd4ef 10502 {
c19d1205
ZW
10503 /* For an immediate, we always generate a 32-bit opcode;
10504 section relaxation will shrink it later if possible. */
10505 if (inst.instruction < 0xffff)
10506 inst.instruction = THUMB_OP32 (inst.instruction);
10507 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10508 inst.instruction |= Rn << r0off;
c19d1205 10509 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10510 }
c19d1205 10511 else
b99bd4ef 10512 {
c19d1205 10513 /* See if we can do this with a 16-bit instruction. */
3d388997 10514 if (narrow)
b99bd4ef 10515 {
c19d1205 10516 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10517 inst.instruction |= Rn;
10518 inst.instruction |= Rm << 3;
b99bd4ef 10519 }
c19d1205 10520 else
b99bd4ef 10521 {
c19d1205
ZW
10522 constraint (inst.operands[1].shifted
10523 && inst.operands[1].immisreg,
10524 _("shift must be constant"));
10525 if (inst.instruction < 0xffff)
10526 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10527 inst.instruction |= Rn << r0off;
c19d1205 10528 encode_thumb32_shifted_operand (1);
b99bd4ef 10529 }
b99bd4ef
NC
10530 }
10531 }
10532 else
10533 {
c19d1205
ZW
10534 constraint (inst.instruction > 0xffff
10535 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10536 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10537 _("unshifted register required"));
fdfde340 10538 constraint (Rn > 7 || Rm > 7,
c19d1205 10539 BAD_HIREG);
b99bd4ef 10540
c19d1205 10541 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10542 inst.instruction |= Rn;
10543 inst.instruction |= Rm << 3;
b99bd4ef 10544 }
b99bd4ef
NC
10545}
10546
b05fe5cf 10547static void
c19d1205 10548do_t_mrs (void)
b05fe5cf 10549{
fdfde340 10550 unsigned Rd;
62b3e311 10551 int flags;
037e8744
JB
10552
10553 if (do_vfp_nsyn_mrs () == SUCCESS)
10554 return;
10555
62b3e311
PB
10556 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10557 if (flags == 0)
10558 {
7e806470 10559 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10560 _("selected processor does not support "
10561 "requested special purpose register"));
10562 }
10563 else
10564 {
10565 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10566 _("selected processor does not support "
44bf2362 10567 "requested special purpose register"));
62b3e311
PB
10568 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10569 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10570 _("'CPSR' or 'SPSR' expected"));
10571 }
5f4273c7 10572
fdfde340
JM
10573 Rd = inst.operands[0].reg;
10574 reject_bad_reg (Rd);
10575
10576 inst.instruction |= Rd << 8;
62b3e311
PB
10577 inst.instruction |= (flags & SPSR_BIT) >> 2;
10578 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10579}
b05fe5cf 10580
c19d1205
ZW
10581static void
10582do_t_msr (void)
10583{
62b3e311 10584 int flags;
fdfde340 10585 unsigned Rn;
62b3e311 10586
037e8744
JB
10587 if (do_vfp_nsyn_msr () == SUCCESS)
10588 return;
10589
c19d1205
ZW
10590 constraint (!inst.operands[1].isreg,
10591 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10592 flags = inst.operands[0].imm;
10593 if (flags & ~0xff)
10594 {
10595 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10596 _("selected processor does not support "
10597 "requested special purpose register"));
10598 }
10599 else
10600 {
7e806470 10601 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10602 _("selected processor does not support "
10603 "requested special purpose register"));
10604 flags |= PSR_f;
10605 }
c921be7d 10606
fdfde340
JM
10607 Rn = inst.operands[1].reg;
10608 reject_bad_reg (Rn);
10609
62b3e311
PB
10610 inst.instruction |= (flags & SPSR_BIT) >> 2;
10611 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10612 inst.instruction |= (flags & 0xff);
fdfde340 10613 inst.instruction |= Rn << 16;
c19d1205 10614}
b05fe5cf 10615
c19d1205
ZW
10616static void
10617do_t_mul (void)
10618{
17828f45 10619 bfd_boolean narrow;
fdfde340 10620 unsigned Rd, Rn, Rm;
17828f45 10621
c19d1205
ZW
10622 if (!inst.operands[2].present)
10623 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10624
fdfde340
JM
10625 Rd = inst.operands[0].reg;
10626 Rn = inst.operands[1].reg;
10627 Rm = inst.operands[2].reg;
10628
17828f45 10629 if (unified_syntax)
b05fe5cf 10630 {
17828f45 10631 if (inst.size_req == 4
fdfde340
JM
10632 || (Rd != Rn
10633 && Rd != Rm)
10634 || Rn > 7
10635 || Rm > 7)
17828f45
JM
10636 narrow = FALSE;
10637 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10638 narrow = !in_it_block ();
17828f45 10639 else
e07e6e58 10640 narrow = in_it_block ();
b05fe5cf 10641 }
c19d1205 10642 else
b05fe5cf 10643 {
17828f45 10644 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10645 constraint (Rn > 7 || Rm > 7,
c19d1205 10646 BAD_HIREG);
17828f45
JM
10647 narrow = TRUE;
10648 }
b05fe5cf 10649
17828f45
JM
10650 if (narrow)
10651 {
10652 /* 16-bit MULS/Conditional MUL. */
c19d1205 10653 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10654 inst.instruction |= Rd;
b05fe5cf 10655
fdfde340
JM
10656 if (Rd == Rn)
10657 inst.instruction |= Rm << 3;
10658 else if (Rd == Rm)
10659 inst.instruction |= Rn << 3;
c19d1205
ZW
10660 else
10661 constraint (1, _("dest must overlap one source register"));
10662 }
17828f45
JM
10663 else
10664 {
e07e6e58
NC
10665 constraint (inst.instruction != T_MNEM_mul,
10666 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10667 /* 32-bit MUL. */
10668 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10669 inst.instruction |= Rd << 8;
10670 inst.instruction |= Rn << 16;
10671 inst.instruction |= Rm << 0;
10672
10673 reject_bad_reg (Rd);
10674 reject_bad_reg (Rn);
10675 reject_bad_reg (Rm);
17828f45 10676 }
c19d1205 10677}
b05fe5cf 10678
c19d1205
ZW
10679static void
10680do_t_mull (void)
10681{
fdfde340 10682 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10683
fdfde340
JM
10684 RdLo = inst.operands[0].reg;
10685 RdHi = inst.operands[1].reg;
10686 Rn = inst.operands[2].reg;
10687 Rm = inst.operands[3].reg;
10688
10689 reject_bad_reg (RdLo);
10690 reject_bad_reg (RdHi);
10691 reject_bad_reg (Rn);
10692 reject_bad_reg (Rm);
10693
10694 inst.instruction |= RdLo << 12;
10695 inst.instruction |= RdHi << 8;
10696 inst.instruction |= Rn << 16;
10697 inst.instruction |= Rm;
10698
10699 if (RdLo == RdHi)
c19d1205
ZW
10700 as_tsktsk (_("rdhi and rdlo must be different"));
10701}
b05fe5cf 10702
c19d1205
ZW
10703static void
10704do_t_nop (void)
10705{
e07e6e58
NC
10706 set_it_insn_type (NEUTRAL_IT_INSN);
10707
c19d1205
ZW
10708 if (unified_syntax)
10709 {
10710 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10711 {
c19d1205
ZW
10712 inst.instruction = THUMB_OP32 (inst.instruction);
10713 inst.instruction |= inst.operands[0].imm;
10714 }
10715 else
10716 {
bc2d1808
NC
10717 /* PR9722: Check for Thumb2 availability before
10718 generating a thumb2 nop instruction. */
afa62d5e 10719 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10720 {
10721 inst.instruction = THUMB_OP16 (inst.instruction);
10722 inst.instruction |= inst.operands[0].imm << 4;
10723 }
10724 else
10725 inst.instruction = 0x46c0;
c19d1205
ZW
10726 }
10727 }
10728 else
10729 {
10730 constraint (inst.operands[0].present,
10731 _("Thumb does not support NOP with hints"));
10732 inst.instruction = 0x46c0;
10733 }
10734}
b05fe5cf 10735
c19d1205
ZW
10736static void
10737do_t_neg (void)
10738{
10739 if (unified_syntax)
10740 {
3d388997
PB
10741 bfd_boolean narrow;
10742
10743 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10744 narrow = !in_it_block ();
3d388997 10745 else
e07e6e58 10746 narrow = in_it_block ();
3d388997
PB
10747 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10748 narrow = FALSE;
10749 if (inst.size_req == 4)
10750 narrow = FALSE;
10751
10752 if (!narrow)
c19d1205
ZW
10753 {
10754 inst.instruction = THUMB_OP32 (inst.instruction);
10755 inst.instruction |= inst.operands[0].reg << 8;
10756 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10757 }
10758 else
10759 {
c19d1205
ZW
10760 inst.instruction = THUMB_OP16 (inst.instruction);
10761 inst.instruction |= inst.operands[0].reg;
10762 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10763 }
10764 }
10765 else
10766 {
c19d1205
ZW
10767 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10768 BAD_HIREG);
10769 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10770
10771 inst.instruction = THUMB_OP16 (inst.instruction);
10772 inst.instruction |= inst.operands[0].reg;
10773 inst.instruction |= inst.operands[1].reg << 3;
10774 }
10775}
10776
1c444d06
JM
10777static void
10778do_t_orn (void)
10779{
10780 unsigned Rd, Rn;
10781
10782 Rd = inst.operands[0].reg;
10783 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10784
fdfde340
JM
10785 reject_bad_reg (Rd);
10786 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10787 reject_bad_reg (Rn);
10788
1c444d06
JM
10789 inst.instruction |= Rd << 8;
10790 inst.instruction |= Rn << 16;
10791
10792 if (!inst.operands[2].isreg)
10793 {
10794 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10795 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10796 }
10797 else
10798 {
10799 unsigned Rm;
10800
10801 Rm = inst.operands[2].reg;
fdfde340 10802 reject_bad_reg (Rm);
1c444d06
JM
10803
10804 constraint (inst.operands[2].shifted
10805 && inst.operands[2].immisreg,
10806 _("shift must be constant"));
10807 encode_thumb32_shifted_operand (2);
10808 }
10809}
10810
c19d1205
ZW
10811static void
10812do_t_pkhbt (void)
10813{
fdfde340
JM
10814 unsigned Rd, Rn, Rm;
10815
10816 Rd = inst.operands[0].reg;
10817 Rn = inst.operands[1].reg;
10818 Rm = inst.operands[2].reg;
10819
10820 reject_bad_reg (Rd);
10821 reject_bad_reg (Rn);
10822 reject_bad_reg (Rm);
10823
10824 inst.instruction |= Rd << 8;
10825 inst.instruction |= Rn << 16;
10826 inst.instruction |= Rm;
c19d1205
ZW
10827 if (inst.operands[3].present)
10828 {
10829 unsigned int val = inst.reloc.exp.X_add_number;
10830 constraint (inst.reloc.exp.X_op != O_constant,
10831 _("expression too complex"));
10832 inst.instruction |= (val & 0x1c) << 10;
10833 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10834 }
c19d1205 10835}
b05fe5cf 10836
c19d1205
ZW
10837static void
10838do_t_pkhtb (void)
10839{
10840 if (!inst.operands[3].present)
1ef52f49
NC
10841 {
10842 unsigned Rtmp;
10843
10844 inst.instruction &= ~0x00000020;
10845
10846 /* PR 10168. Swap the Rm and Rn registers. */
10847 Rtmp = inst.operands[1].reg;
10848 inst.operands[1].reg = inst.operands[2].reg;
10849 inst.operands[2].reg = Rtmp;
10850 }
c19d1205 10851 do_t_pkhbt ();
b05fe5cf
ZW
10852}
10853
c19d1205
ZW
10854static void
10855do_t_pld (void)
10856{
fdfde340
JM
10857 if (inst.operands[0].immisreg)
10858 reject_bad_reg (inst.operands[0].imm);
10859
c19d1205
ZW
10860 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10861}
b05fe5cf 10862
c19d1205
ZW
10863static void
10864do_t_push_pop (void)
b99bd4ef 10865{
e9f89963 10866 unsigned mask;
5f4273c7 10867
c19d1205
ZW
10868 constraint (inst.operands[0].writeback,
10869 _("push/pop do not support {reglist}^"));
10870 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10871 _("expression too complex"));
b99bd4ef 10872
e9f89963
PB
10873 mask = inst.operands[0].imm;
10874 if ((mask & ~0xff) == 0)
3c707909 10875 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10876 else if ((inst.instruction == T_MNEM_push
e9f89963 10877 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10878 || (inst.instruction == T_MNEM_pop
e9f89963 10879 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10880 {
c19d1205
ZW
10881 inst.instruction = THUMB_OP16 (inst.instruction);
10882 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10883 inst.instruction |= mask & 0xff;
c19d1205
ZW
10884 }
10885 else if (unified_syntax)
10886 {
3c707909 10887 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10888 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10889 }
10890 else
10891 {
10892 inst.error = _("invalid register list to push/pop instruction");
10893 return;
10894 }
c19d1205 10895}
b99bd4ef 10896
c19d1205
ZW
10897static void
10898do_t_rbit (void)
10899{
fdfde340
JM
10900 unsigned Rd, Rm;
10901
10902 Rd = inst.operands[0].reg;
10903 Rm = inst.operands[1].reg;
10904
10905 reject_bad_reg (Rd);
10906 reject_bad_reg (Rm);
10907
10908 inst.instruction |= Rd << 8;
10909 inst.instruction |= Rm << 16;
10910 inst.instruction |= Rm;
c19d1205 10911}
b99bd4ef 10912
c19d1205
ZW
10913static void
10914do_t_rev (void)
10915{
fdfde340
JM
10916 unsigned Rd, Rm;
10917
10918 Rd = inst.operands[0].reg;
10919 Rm = inst.operands[1].reg;
10920
10921 reject_bad_reg (Rd);
10922 reject_bad_reg (Rm);
10923
10924 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10925 && inst.size_req != 4)
10926 {
10927 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10928 inst.instruction |= Rd;
10929 inst.instruction |= Rm << 3;
c19d1205
ZW
10930 }
10931 else if (unified_syntax)
10932 {
10933 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10934 inst.instruction |= Rd << 8;
10935 inst.instruction |= Rm << 16;
10936 inst.instruction |= Rm;
c19d1205
ZW
10937 }
10938 else
10939 inst.error = BAD_HIREG;
10940}
b99bd4ef 10941
1c444d06
JM
10942static void
10943do_t_rrx (void)
10944{
10945 unsigned Rd, Rm;
10946
10947 Rd = inst.operands[0].reg;
10948 Rm = inst.operands[1].reg;
10949
fdfde340
JM
10950 reject_bad_reg (Rd);
10951 reject_bad_reg (Rm);
c921be7d 10952
1c444d06
JM
10953 inst.instruction |= Rd << 8;
10954 inst.instruction |= Rm;
10955}
10956
c19d1205
ZW
10957static void
10958do_t_rsb (void)
10959{
fdfde340 10960 unsigned Rd, Rs;
b99bd4ef 10961
c19d1205
ZW
10962 Rd = inst.operands[0].reg;
10963 Rs = (inst.operands[1].present
10964 ? inst.operands[1].reg /* Rd, Rs, foo */
10965 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10966
fdfde340
JM
10967 reject_bad_reg (Rd);
10968 reject_bad_reg (Rs);
10969 if (inst.operands[2].isreg)
10970 reject_bad_reg (inst.operands[2].reg);
10971
c19d1205
ZW
10972 inst.instruction |= Rd << 8;
10973 inst.instruction |= Rs << 16;
10974 if (!inst.operands[2].isreg)
10975 {
026d3abb
PB
10976 bfd_boolean narrow;
10977
10978 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10979 narrow = !in_it_block ();
026d3abb 10980 else
e07e6e58 10981 narrow = in_it_block ();
026d3abb
PB
10982
10983 if (Rd > 7 || Rs > 7)
10984 narrow = FALSE;
10985
10986 if (inst.size_req == 4 || !unified_syntax)
10987 narrow = FALSE;
10988
10989 if (inst.reloc.exp.X_op != O_constant
10990 || inst.reloc.exp.X_add_number != 0)
10991 narrow = FALSE;
10992
10993 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10994 relaxation, but it doesn't seem worth the hassle. */
10995 if (narrow)
10996 {
10997 inst.reloc.type = BFD_RELOC_UNUSED;
10998 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10999 inst.instruction |= Rs << 3;
11000 inst.instruction |= Rd;
11001 }
11002 else
11003 {
11004 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11005 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11006 }
c19d1205
ZW
11007 }
11008 else
11009 encode_thumb32_shifted_operand (2);
11010}
b99bd4ef 11011
c19d1205
ZW
11012static void
11013do_t_setend (void)
11014{
e07e6e58 11015 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11016 if (inst.operands[0].imm)
11017 inst.instruction |= 0x8;
11018}
b99bd4ef 11019
c19d1205
ZW
11020static void
11021do_t_shift (void)
11022{
11023 if (!inst.operands[1].present)
11024 inst.operands[1].reg = inst.operands[0].reg;
11025
11026 if (unified_syntax)
11027 {
3d388997
PB
11028 bfd_boolean narrow;
11029 int shift_kind;
11030
11031 switch (inst.instruction)
11032 {
11033 case T_MNEM_asr:
11034 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11035 case T_MNEM_lsl:
11036 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11037 case T_MNEM_lsr:
11038 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11039 case T_MNEM_ror:
11040 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11041 default: abort ();
11042 }
11043
11044 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11045 narrow = !in_it_block ();
3d388997 11046 else
e07e6e58 11047 narrow = in_it_block ();
3d388997
PB
11048 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11049 narrow = FALSE;
11050 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11051 narrow = FALSE;
11052 if (inst.operands[2].isreg
11053 && (inst.operands[1].reg != inst.operands[0].reg
11054 || inst.operands[2].reg > 7))
11055 narrow = FALSE;
11056 if (inst.size_req == 4)
11057 narrow = FALSE;
11058
fdfde340
JM
11059 reject_bad_reg (inst.operands[0].reg);
11060 reject_bad_reg (inst.operands[1].reg);
c921be7d 11061
3d388997 11062 if (!narrow)
c19d1205
ZW
11063 {
11064 if (inst.operands[2].isreg)
b99bd4ef 11065 {
fdfde340 11066 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11067 inst.instruction = THUMB_OP32 (inst.instruction);
11068 inst.instruction |= inst.operands[0].reg << 8;
11069 inst.instruction |= inst.operands[1].reg << 16;
11070 inst.instruction |= inst.operands[2].reg;
11071 }
11072 else
11073 {
11074 inst.operands[1].shifted = 1;
3d388997 11075 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11076 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11077 ? T_MNEM_movs : T_MNEM_mov);
11078 inst.instruction |= inst.operands[0].reg << 8;
11079 encode_thumb32_shifted_operand (1);
11080 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11081 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11082 }
11083 }
11084 else
11085 {
c19d1205 11086 if (inst.operands[2].isreg)
b99bd4ef 11087 {
3d388997 11088 switch (shift_kind)
b99bd4ef 11089 {
3d388997
PB
11090 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11091 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11092 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11093 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11094 default: abort ();
b99bd4ef 11095 }
5f4273c7 11096
c19d1205
ZW
11097 inst.instruction |= inst.operands[0].reg;
11098 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11099 }
11100 else
11101 {
3d388997 11102 switch (shift_kind)
b99bd4ef 11103 {
3d388997
PB
11104 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11105 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11106 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11107 default: abort ();
b99bd4ef 11108 }
c19d1205
ZW
11109 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11110 inst.instruction |= inst.operands[0].reg;
11111 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11112 }
11113 }
c19d1205
ZW
11114 }
11115 else
11116 {
11117 constraint (inst.operands[0].reg > 7
11118 || inst.operands[1].reg > 7, BAD_HIREG);
11119 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11120
c19d1205
ZW
11121 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11122 {
11123 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11124 constraint (inst.operands[0].reg != inst.operands[1].reg,
11125 _("source1 and dest must be same register"));
b99bd4ef 11126
c19d1205
ZW
11127 switch (inst.instruction)
11128 {
11129 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11130 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11131 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11132 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11133 default: abort ();
11134 }
5f4273c7 11135
c19d1205
ZW
11136 inst.instruction |= inst.operands[0].reg;
11137 inst.instruction |= inst.operands[2].reg << 3;
11138 }
11139 else
b99bd4ef 11140 {
c19d1205
ZW
11141 switch (inst.instruction)
11142 {
11143 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11144 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11145 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11146 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11147 default: abort ();
11148 }
11149 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11150 inst.instruction |= inst.operands[0].reg;
11151 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11152 }
11153 }
b99bd4ef
NC
11154}
11155
11156static void
c19d1205 11157do_t_simd (void)
b99bd4ef 11158{
fdfde340
JM
11159 unsigned Rd, Rn, Rm;
11160
11161 Rd = inst.operands[0].reg;
11162 Rn = inst.operands[1].reg;
11163 Rm = inst.operands[2].reg;
11164
11165 reject_bad_reg (Rd);
11166 reject_bad_reg (Rn);
11167 reject_bad_reg (Rm);
11168
11169 inst.instruction |= Rd << 8;
11170 inst.instruction |= Rn << 16;
11171 inst.instruction |= Rm;
c19d1205 11172}
b99bd4ef 11173
03ee1b7f
NC
11174static void
11175do_t_simd2 (void)
11176{
11177 unsigned Rd, Rn, Rm;
11178
11179 Rd = inst.operands[0].reg;
11180 Rm = inst.operands[1].reg;
11181 Rn = inst.operands[2].reg;
11182
11183 reject_bad_reg (Rd);
11184 reject_bad_reg (Rn);
11185 reject_bad_reg (Rm);
11186
11187 inst.instruction |= Rd << 8;
11188 inst.instruction |= Rn << 16;
11189 inst.instruction |= Rm;
11190}
11191
c19d1205 11192static void
3eb17e6b 11193do_t_smc (void)
c19d1205
ZW
11194{
11195 unsigned int value = inst.reloc.exp.X_add_number;
11196 constraint (inst.reloc.exp.X_op != O_constant,
11197 _("expression too complex"));
11198 inst.reloc.type = BFD_RELOC_UNUSED;
11199 inst.instruction |= (value & 0xf000) >> 12;
11200 inst.instruction |= (value & 0x0ff0);
11201 inst.instruction |= (value & 0x000f) << 16;
11202}
b99bd4ef 11203
c19d1205 11204static void
3a21c15a 11205do_t_ssat_usat (int bias)
c19d1205 11206{
fdfde340
JM
11207 unsigned Rd, Rn;
11208
11209 Rd = inst.operands[0].reg;
11210 Rn = inst.operands[2].reg;
11211
11212 reject_bad_reg (Rd);
11213 reject_bad_reg (Rn);
11214
11215 inst.instruction |= Rd << 8;
3a21c15a 11216 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11217 inst.instruction |= Rn << 16;
b99bd4ef 11218
c19d1205 11219 if (inst.operands[3].present)
b99bd4ef 11220 {
3a21c15a
NC
11221 offsetT shift_amount = inst.reloc.exp.X_add_number;
11222
11223 inst.reloc.type = BFD_RELOC_UNUSED;
11224
c19d1205
ZW
11225 constraint (inst.reloc.exp.X_op != O_constant,
11226 _("expression too complex"));
b99bd4ef 11227
3a21c15a 11228 if (shift_amount != 0)
6189168b 11229 {
3a21c15a
NC
11230 constraint (shift_amount > 31,
11231 _("shift expression is too large"));
11232
c19d1205 11233 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11234 inst.instruction |= 0x00200000; /* sh bit. */
11235
11236 inst.instruction |= (shift_amount & 0x1c) << 10;
11237 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11238 }
11239 }
b99bd4ef 11240}
c921be7d 11241
3a21c15a
NC
11242static void
11243do_t_ssat (void)
11244{
11245 do_t_ssat_usat (1);
11246}
b99bd4ef 11247
0dd132b6 11248static void
c19d1205 11249do_t_ssat16 (void)
0dd132b6 11250{
fdfde340
JM
11251 unsigned Rd, Rn;
11252
11253 Rd = inst.operands[0].reg;
11254 Rn = inst.operands[2].reg;
11255
11256 reject_bad_reg (Rd);
11257 reject_bad_reg (Rn);
11258
11259 inst.instruction |= Rd << 8;
c19d1205 11260 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11261 inst.instruction |= Rn << 16;
c19d1205 11262}
0dd132b6 11263
c19d1205
ZW
11264static void
11265do_t_strex (void)
11266{
11267 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11268 || inst.operands[2].postind || inst.operands[2].writeback
11269 || inst.operands[2].immisreg || inst.operands[2].shifted
11270 || inst.operands[2].negative,
01cfc07f 11271 BAD_ADDR_MODE);
0dd132b6 11272
5be8be5d
DG
11273 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11274
c19d1205
ZW
11275 inst.instruction |= inst.operands[0].reg << 8;
11276 inst.instruction |= inst.operands[1].reg << 12;
11277 inst.instruction |= inst.operands[2].reg << 16;
11278 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11279}
11280
b99bd4ef 11281static void
c19d1205 11282do_t_strexd (void)
b99bd4ef 11283{
c19d1205
ZW
11284 if (!inst.operands[2].present)
11285 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11286
c19d1205
ZW
11287 constraint (inst.operands[0].reg == inst.operands[1].reg
11288 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11289 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11290 BAD_OVERLAP);
b99bd4ef 11291
c19d1205
ZW
11292 inst.instruction |= inst.operands[0].reg;
11293 inst.instruction |= inst.operands[1].reg << 12;
11294 inst.instruction |= inst.operands[2].reg << 8;
11295 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11296}
11297
11298static void
c19d1205 11299do_t_sxtah (void)
b99bd4ef 11300{
fdfde340
JM
11301 unsigned Rd, Rn, Rm;
11302
11303 Rd = inst.operands[0].reg;
11304 Rn = inst.operands[1].reg;
11305 Rm = inst.operands[2].reg;
11306
11307 reject_bad_reg (Rd);
11308 reject_bad_reg (Rn);
11309 reject_bad_reg (Rm);
11310
11311 inst.instruction |= Rd << 8;
11312 inst.instruction |= Rn << 16;
11313 inst.instruction |= Rm;
c19d1205
ZW
11314 inst.instruction |= inst.operands[3].imm << 4;
11315}
b99bd4ef 11316
c19d1205
ZW
11317static void
11318do_t_sxth (void)
11319{
fdfde340
JM
11320 unsigned Rd, Rm;
11321
11322 Rd = inst.operands[0].reg;
11323 Rm = inst.operands[1].reg;
11324
11325 reject_bad_reg (Rd);
11326 reject_bad_reg (Rm);
c921be7d
NC
11327
11328 if (inst.instruction <= 0xffff
11329 && inst.size_req != 4
fdfde340 11330 && Rd <= 7 && Rm <= 7
c19d1205 11331 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11332 {
c19d1205 11333 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11334 inst.instruction |= Rd;
11335 inst.instruction |= Rm << 3;
b99bd4ef 11336 }
c19d1205 11337 else if (unified_syntax)
b99bd4ef 11338 {
c19d1205
ZW
11339 if (inst.instruction <= 0xffff)
11340 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11341 inst.instruction |= Rd << 8;
11342 inst.instruction |= Rm;
c19d1205 11343 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11344 }
c19d1205 11345 else
b99bd4ef 11346 {
c19d1205
ZW
11347 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11348 _("Thumb encoding does not support rotation"));
11349 constraint (1, BAD_HIREG);
b99bd4ef 11350 }
c19d1205 11351}
b99bd4ef 11352
c19d1205
ZW
11353static void
11354do_t_swi (void)
11355{
11356 inst.reloc.type = BFD_RELOC_ARM_SWI;
11357}
b99bd4ef 11358
92e90b6e
PB
11359static void
11360do_t_tb (void)
11361{
fdfde340 11362 unsigned Rn, Rm;
92e90b6e
PB
11363 int half;
11364
11365 half = (inst.instruction & 0x10) != 0;
e07e6e58 11366 set_it_insn_type_last ();
dfa9f0d5
PB
11367 constraint (inst.operands[0].immisreg,
11368 _("instruction requires register index"));
fdfde340
JM
11369
11370 Rn = inst.operands[0].reg;
11371 Rm = inst.operands[0].imm;
c921be7d 11372
fdfde340
JM
11373 constraint (Rn == REG_SP, BAD_SP);
11374 reject_bad_reg (Rm);
11375
92e90b6e
PB
11376 constraint (!half && inst.operands[0].shifted,
11377 _("instruction does not allow shifted index"));
fdfde340 11378 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11379}
11380
c19d1205
ZW
11381static void
11382do_t_usat (void)
11383{
3a21c15a 11384 do_t_ssat_usat (0);
b99bd4ef
NC
11385}
11386
11387static void
c19d1205 11388do_t_usat16 (void)
b99bd4ef 11389{
fdfde340
JM
11390 unsigned Rd, Rn;
11391
11392 Rd = inst.operands[0].reg;
11393 Rn = inst.operands[2].reg;
11394
11395 reject_bad_reg (Rd);
11396 reject_bad_reg (Rn);
11397
11398 inst.instruction |= Rd << 8;
c19d1205 11399 inst.instruction |= inst.operands[1].imm;
fdfde340 11400 inst.instruction |= Rn << 16;
b99bd4ef 11401}
c19d1205 11402
5287ad62 11403/* Neon instruction encoder helpers. */
5f4273c7 11404
5287ad62 11405/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11406
5287ad62
JB
11407/* An "invalid" code for the following tables. */
11408#define N_INV -1u
11409
11410struct neon_tab_entry
b99bd4ef 11411{
5287ad62
JB
11412 unsigned integer;
11413 unsigned float_or_poly;
11414 unsigned scalar_or_imm;
11415};
5f4273c7 11416
5287ad62
JB
11417/* Map overloaded Neon opcodes to their respective encodings. */
11418#define NEON_ENC_TAB \
11419 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11420 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11421 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11422 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11423 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11424 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11425 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11426 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11427 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11428 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11429 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11430 /* Register variants of the following two instructions are encoded as
e07e6e58 11431 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11432 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11433 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11434 X(vfma, N_INV, 0x0000c10, N_INV), \
11435 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11436 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11437 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11438 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11439 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11440 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11441 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11442 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11443 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11444 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11445 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11446 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11447 X(vshl, 0x0000400, N_INV, 0x0800510), \
11448 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11449 X(vand, 0x0000110, N_INV, 0x0800030), \
11450 X(vbic, 0x0100110, N_INV, 0x0800030), \
11451 X(veor, 0x1000110, N_INV, N_INV), \
11452 X(vorn, 0x0300110, N_INV, 0x0800010), \
11453 X(vorr, 0x0200110, N_INV, 0x0800010), \
11454 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11455 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11456 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11457 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11458 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11459 X(vst1, 0x0000000, 0x0800000, N_INV), \
11460 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11461 X(vst2, 0x0000100, 0x0800100, N_INV), \
11462 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11463 X(vst3, 0x0000200, 0x0800200, N_INV), \
11464 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11465 X(vst4, 0x0000300, 0x0800300, N_INV), \
11466 X(vmovn, 0x1b20200, N_INV, N_INV), \
11467 X(vtrn, 0x1b20080, N_INV, N_INV), \
11468 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11469 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11470 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11471 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11472 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11473 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11474 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11475 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11476 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11477 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11478 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11479
11480enum neon_opc
11481{
11482#define X(OPC,I,F,S) N_MNEM_##OPC
11483NEON_ENC_TAB
11484#undef X
11485};
b99bd4ef 11486
5287ad62
JB
11487static const struct neon_tab_entry neon_enc_tab[] =
11488{
11489#define X(OPC,I,F,S) { (I), (F), (S) }
11490NEON_ENC_TAB
11491#undef X
11492};
b99bd4ef 11493
88714cb8
DG
11494/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11495#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11496#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11497#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11498#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11499#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11500#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11501#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11502#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11503#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11504#define NEON_ENC_SINGLE_(X) \
037e8744 11505 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11506#define NEON_ENC_DOUBLE_(X) \
037e8744 11507 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11508
88714cb8
DG
11509#define NEON_ENCODE(type, inst) \
11510 do \
11511 { \
11512 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11513 inst.is_neon = 1; \
11514 } \
11515 while (0)
11516
11517#define check_neon_suffixes \
11518 do \
11519 { \
11520 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11521 { \
11522 as_bad (_("invalid neon suffix for non neon instruction")); \
11523 return; \
11524 } \
11525 } \
11526 while (0)
11527
037e8744
JB
11528/* Define shapes for instruction operands. The following mnemonic characters
11529 are used in this table:
5287ad62 11530
037e8744 11531 F - VFP S<n> register
5287ad62
JB
11532 D - Neon D<n> register
11533 Q - Neon Q<n> register
11534 I - Immediate
11535 S - Scalar
11536 R - ARM register
11537 L - D<n> register list
5f4273c7 11538
037e8744
JB
11539 This table is used to generate various data:
11540 - enumerations of the form NS_DDR to be used as arguments to
11541 neon_select_shape.
11542 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11543 - a table used to drive neon_select_shape. */
b99bd4ef 11544
037e8744
JB
11545#define NEON_SHAPE_DEF \
11546 X(3, (D, D, D), DOUBLE), \
11547 X(3, (Q, Q, Q), QUAD), \
11548 X(3, (D, D, I), DOUBLE), \
11549 X(3, (Q, Q, I), QUAD), \
11550 X(3, (D, D, S), DOUBLE), \
11551 X(3, (Q, Q, S), QUAD), \
11552 X(2, (D, D), DOUBLE), \
11553 X(2, (Q, Q), QUAD), \
11554 X(2, (D, S), DOUBLE), \
11555 X(2, (Q, S), QUAD), \
11556 X(2, (D, R), DOUBLE), \
11557 X(2, (Q, R), QUAD), \
11558 X(2, (D, I), DOUBLE), \
11559 X(2, (Q, I), QUAD), \
11560 X(3, (D, L, D), DOUBLE), \
11561 X(2, (D, Q), MIXED), \
11562 X(2, (Q, D), MIXED), \
11563 X(3, (D, Q, I), MIXED), \
11564 X(3, (Q, D, I), MIXED), \
11565 X(3, (Q, D, D), MIXED), \
11566 X(3, (D, Q, Q), MIXED), \
11567 X(3, (Q, Q, D), MIXED), \
11568 X(3, (Q, D, S), MIXED), \
11569 X(3, (D, Q, S), MIXED), \
11570 X(4, (D, D, D, I), DOUBLE), \
11571 X(4, (Q, Q, Q, I), QUAD), \
11572 X(2, (F, F), SINGLE), \
11573 X(3, (F, F, F), SINGLE), \
11574 X(2, (F, I), SINGLE), \
11575 X(2, (F, D), MIXED), \
11576 X(2, (D, F), MIXED), \
11577 X(3, (F, F, I), MIXED), \
11578 X(4, (R, R, F, F), SINGLE), \
11579 X(4, (F, F, R, R), SINGLE), \
11580 X(3, (D, R, R), DOUBLE), \
11581 X(3, (R, R, D), DOUBLE), \
11582 X(2, (S, R), SINGLE), \
11583 X(2, (R, S), SINGLE), \
11584 X(2, (F, R), SINGLE), \
11585 X(2, (R, F), SINGLE)
11586
11587#define S2(A,B) NS_##A##B
11588#define S3(A,B,C) NS_##A##B##C
11589#define S4(A,B,C,D) NS_##A##B##C##D
11590
11591#define X(N, L, C) S##N L
11592
5287ad62
JB
11593enum neon_shape
11594{
037e8744
JB
11595 NEON_SHAPE_DEF,
11596 NS_NULL
5287ad62 11597};
b99bd4ef 11598
037e8744
JB
11599#undef X
11600#undef S2
11601#undef S3
11602#undef S4
11603
11604enum neon_shape_class
11605{
11606 SC_SINGLE,
11607 SC_DOUBLE,
11608 SC_QUAD,
11609 SC_MIXED
11610};
11611
11612#define X(N, L, C) SC_##C
11613
11614static enum neon_shape_class neon_shape_class[] =
11615{
11616 NEON_SHAPE_DEF
11617};
11618
11619#undef X
11620
11621enum neon_shape_el
11622{
11623 SE_F,
11624 SE_D,
11625 SE_Q,
11626 SE_I,
11627 SE_S,
11628 SE_R,
11629 SE_L
11630};
11631
11632/* Register widths of above. */
11633static unsigned neon_shape_el_size[] =
11634{
11635 32,
11636 64,
11637 128,
11638 0,
11639 32,
11640 32,
11641 0
11642};
11643
11644struct neon_shape_info
11645{
11646 unsigned els;
11647 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11648};
11649
11650#define S2(A,B) { SE_##A, SE_##B }
11651#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11652#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11653
11654#define X(N, L, C) { N, S##N L }
11655
11656static struct neon_shape_info neon_shape_tab[] =
11657{
11658 NEON_SHAPE_DEF
11659};
11660
11661#undef X
11662#undef S2
11663#undef S3
11664#undef S4
11665
5287ad62
JB
11666/* Bit masks used in type checking given instructions.
11667 'N_EQK' means the type must be the same as (or based on in some way) the key
11668 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11669 set, various other bits can be set as well in order to modify the meaning of
11670 the type constraint. */
11671
11672enum neon_type_mask
11673{
8e79c3df
CM
11674 N_S8 = 0x0000001,
11675 N_S16 = 0x0000002,
11676 N_S32 = 0x0000004,
11677 N_S64 = 0x0000008,
11678 N_U8 = 0x0000010,
11679 N_U16 = 0x0000020,
11680 N_U32 = 0x0000040,
11681 N_U64 = 0x0000080,
11682 N_I8 = 0x0000100,
11683 N_I16 = 0x0000200,
11684 N_I32 = 0x0000400,
11685 N_I64 = 0x0000800,
11686 N_8 = 0x0001000,
11687 N_16 = 0x0002000,
11688 N_32 = 0x0004000,
11689 N_64 = 0x0008000,
11690 N_P8 = 0x0010000,
11691 N_P16 = 0x0020000,
11692 N_F16 = 0x0040000,
11693 N_F32 = 0x0080000,
11694 N_F64 = 0x0100000,
c921be7d
NC
11695 N_KEY = 0x1000000, /* Key element (main type specifier). */
11696 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11697 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11698 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11699 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11700 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11701 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11702 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11703 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11704 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11705 N_UTYP = 0,
037e8744 11706 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11707};
11708
dcbf9037
JB
11709#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11710
5287ad62
JB
11711#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11712#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11713#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11714#define N_SUF_32 (N_SU_32 | N_F32)
11715#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11716#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11717
11718/* Pass this as the first type argument to neon_check_type to ignore types
11719 altogether. */
11720#define N_IGNORE_TYPE (N_KEY | N_EQK)
11721
037e8744
JB
11722/* Select a "shape" for the current instruction (describing register types or
11723 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11724 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11725 function of operand parsing, so this function doesn't need to be called.
11726 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11727
11728static enum neon_shape
037e8744 11729neon_select_shape (enum neon_shape shape, ...)
5287ad62 11730{
037e8744
JB
11731 va_list ap;
11732 enum neon_shape first_shape = shape;
5287ad62
JB
11733
11734 /* Fix missing optional operands. FIXME: we don't know at this point how
11735 many arguments we should have, so this makes the assumption that we have
11736 > 1. This is true of all current Neon opcodes, I think, but may not be
11737 true in the future. */
11738 if (!inst.operands[1].present)
11739 inst.operands[1] = inst.operands[0];
11740
037e8744 11741 va_start (ap, shape);
5f4273c7 11742
21d799b5 11743 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11744 {
11745 unsigned j;
11746 int matches = 1;
11747
11748 for (j = 0; j < neon_shape_tab[shape].els; j++)
11749 {
11750 if (!inst.operands[j].present)
11751 {
11752 matches = 0;
11753 break;
11754 }
11755
11756 switch (neon_shape_tab[shape].el[j])
11757 {
11758 case SE_F:
11759 if (!(inst.operands[j].isreg
11760 && inst.operands[j].isvec
11761 && inst.operands[j].issingle
11762 && !inst.operands[j].isquad))
11763 matches = 0;
11764 break;
11765
11766 case SE_D:
11767 if (!(inst.operands[j].isreg
11768 && inst.operands[j].isvec
11769 && !inst.operands[j].isquad
11770 && !inst.operands[j].issingle))
11771 matches = 0;
11772 break;
11773
11774 case SE_R:
11775 if (!(inst.operands[j].isreg
11776 && !inst.operands[j].isvec))
11777 matches = 0;
11778 break;
11779
11780 case SE_Q:
11781 if (!(inst.operands[j].isreg
11782 && inst.operands[j].isvec
11783 && inst.operands[j].isquad
11784 && !inst.operands[j].issingle))
11785 matches = 0;
11786 break;
11787
11788 case SE_I:
11789 if (!(!inst.operands[j].isreg
11790 && !inst.operands[j].isscalar))
11791 matches = 0;
11792 break;
11793
11794 case SE_S:
11795 if (!(!inst.operands[j].isreg
11796 && inst.operands[j].isscalar))
11797 matches = 0;
11798 break;
11799
11800 case SE_L:
11801 break;
11802 }
3fde54a2
JZ
11803 if (!matches)
11804 break;
037e8744
JB
11805 }
11806 if (matches)
5287ad62 11807 break;
037e8744 11808 }
5f4273c7 11809
037e8744 11810 va_end (ap);
5287ad62 11811
037e8744
JB
11812 if (shape == NS_NULL && first_shape != NS_NULL)
11813 first_error (_("invalid instruction shape"));
5287ad62 11814
037e8744
JB
11815 return shape;
11816}
5287ad62 11817
037e8744
JB
11818/* True if SHAPE is predominantly a quadword operation (most of the time, this
11819 means the Q bit should be set). */
11820
11821static int
11822neon_quad (enum neon_shape shape)
11823{
11824 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11825}
037e8744 11826
5287ad62
JB
11827static void
11828neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11829 unsigned *g_size)
11830{
11831 /* Allow modification to be made to types which are constrained to be
11832 based on the key element, based on bits set alongside N_EQK. */
11833 if ((typebits & N_EQK) != 0)
11834 {
11835 if ((typebits & N_HLF) != 0)
11836 *g_size /= 2;
11837 else if ((typebits & N_DBL) != 0)
11838 *g_size *= 2;
11839 if ((typebits & N_SGN) != 0)
11840 *g_type = NT_signed;
11841 else if ((typebits & N_UNS) != 0)
11842 *g_type = NT_unsigned;
11843 else if ((typebits & N_INT) != 0)
11844 *g_type = NT_integer;
11845 else if ((typebits & N_FLT) != 0)
11846 *g_type = NT_float;
dcbf9037
JB
11847 else if ((typebits & N_SIZ) != 0)
11848 *g_type = NT_untyped;
5287ad62
JB
11849 }
11850}
5f4273c7 11851
5287ad62
JB
11852/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11853 operand type, i.e. the single type specified in a Neon instruction when it
11854 is the only one given. */
11855
11856static struct neon_type_el
11857neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11858{
11859 struct neon_type_el dest = *key;
5f4273c7 11860
9c2799c2 11861 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11862
5287ad62
JB
11863 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11864
11865 return dest;
11866}
11867
11868/* Convert Neon type and size into compact bitmask representation. */
11869
11870static enum neon_type_mask
11871type_chk_of_el_type (enum neon_el_type type, unsigned size)
11872{
11873 switch (type)
11874 {
11875 case NT_untyped:
11876 switch (size)
11877 {
11878 case 8: return N_8;
11879 case 16: return N_16;
11880 case 32: return N_32;
11881 case 64: return N_64;
11882 default: ;
11883 }
11884 break;
11885
11886 case NT_integer:
11887 switch (size)
11888 {
11889 case 8: return N_I8;
11890 case 16: return N_I16;
11891 case 32: return N_I32;
11892 case 64: return N_I64;
11893 default: ;
11894 }
11895 break;
11896
11897 case NT_float:
037e8744
JB
11898 switch (size)
11899 {
8e79c3df 11900 case 16: return N_F16;
037e8744
JB
11901 case 32: return N_F32;
11902 case 64: return N_F64;
11903 default: ;
11904 }
5287ad62
JB
11905 break;
11906
11907 case NT_poly:
11908 switch (size)
11909 {
11910 case 8: return N_P8;
11911 case 16: return N_P16;
11912 default: ;
11913 }
11914 break;
11915
11916 case NT_signed:
11917 switch (size)
11918 {
11919 case 8: return N_S8;
11920 case 16: return N_S16;
11921 case 32: return N_S32;
11922 case 64: return N_S64;
11923 default: ;
11924 }
11925 break;
11926
11927 case NT_unsigned:
11928 switch (size)
11929 {
11930 case 8: return N_U8;
11931 case 16: return N_U16;
11932 case 32: return N_U32;
11933 case 64: return N_U64;
11934 default: ;
11935 }
11936 break;
11937
11938 default: ;
11939 }
5f4273c7 11940
5287ad62
JB
11941 return N_UTYP;
11942}
11943
11944/* Convert compact Neon bitmask type representation to a type and size. Only
11945 handles the case where a single bit is set in the mask. */
11946
dcbf9037 11947static int
5287ad62
JB
11948el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11949 enum neon_type_mask mask)
11950{
dcbf9037
JB
11951 if ((mask & N_EQK) != 0)
11952 return FAIL;
11953
5287ad62
JB
11954 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11955 *size = 8;
dcbf9037 11956 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11957 *size = 16;
dcbf9037 11958 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11959 *size = 32;
037e8744 11960 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11961 *size = 64;
dcbf9037
JB
11962 else
11963 return FAIL;
11964
5287ad62
JB
11965 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11966 *type = NT_signed;
dcbf9037 11967 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11968 *type = NT_unsigned;
dcbf9037 11969 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11970 *type = NT_integer;
dcbf9037 11971 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11972 *type = NT_untyped;
dcbf9037 11973 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11974 *type = NT_poly;
037e8744 11975 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11976 *type = NT_float;
dcbf9037
JB
11977 else
11978 return FAIL;
5f4273c7 11979
dcbf9037 11980 return SUCCESS;
5287ad62
JB
11981}
11982
11983/* Modify a bitmask of allowed types. This is only needed for type
11984 relaxation. */
11985
11986static unsigned
11987modify_types_allowed (unsigned allowed, unsigned mods)
11988{
11989 unsigned size;
11990 enum neon_el_type type;
11991 unsigned destmask;
11992 int i;
5f4273c7 11993
5287ad62 11994 destmask = 0;
5f4273c7 11995
5287ad62
JB
11996 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11997 {
21d799b5
NC
11998 if (el_type_of_type_chk (&type, &size,
11999 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12000 {
12001 neon_modify_type_size (mods, &type, &size);
12002 destmask |= type_chk_of_el_type (type, size);
12003 }
5287ad62 12004 }
5f4273c7 12005
5287ad62
JB
12006 return destmask;
12007}
12008
12009/* Check type and return type classification.
12010 The manual states (paraphrase): If one datatype is given, it indicates the
12011 type given in:
12012 - the second operand, if there is one
12013 - the operand, if there is no second operand
12014 - the result, if there are no operands.
12015 This isn't quite good enough though, so we use a concept of a "key" datatype
12016 which is set on a per-instruction basis, which is the one which matters when
12017 only one data type is written.
12018 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12019 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12020
12021static struct neon_type_el
12022neon_check_type (unsigned els, enum neon_shape ns, ...)
12023{
12024 va_list ap;
12025 unsigned i, pass, key_el = 0;
12026 unsigned types[NEON_MAX_TYPE_ELS];
12027 enum neon_el_type k_type = NT_invtype;
12028 unsigned k_size = -1u;
12029 struct neon_type_el badtype = {NT_invtype, -1};
12030 unsigned key_allowed = 0;
12031
12032 /* Optional registers in Neon instructions are always (not) in operand 1.
12033 Fill in the missing operand here, if it was omitted. */
12034 if (els > 1 && !inst.operands[1].present)
12035 inst.operands[1] = inst.operands[0];
12036
12037 /* Suck up all the varargs. */
12038 va_start (ap, ns);
12039 for (i = 0; i < els; i++)
12040 {
12041 unsigned thisarg = va_arg (ap, unsigned);
12042 if (thisarg == N_IGNORE_TYPE)
12043 {
12044 va_end (ap);
12045 return badtype;
12046 }
12047 types[i] = thisarg;
12048 if ((thisarg & N_KEY) != 0)
12049 key_el = i;
12050 }
12051 va_end (ap);
12052
dcbf9037
JB
12053 if (inst.vectype.elems > 0)
12054 for (i = 0; i < els; i++)
12055 if (inst.operands[i].vectype.type != NT_invtype)
12056 {
12057 first_error (_("types specified in both the mnemonic and operands"));
12058 return badtype;
12059 }
12060
5287ad62
JB
12061 /* Duplicate inst.vectype elements here as necessary.
12062 FIXME: No idea if this is exactly the same as the ARM assembler,
12063 particularly when an insn takes one register and one non-register
12064 operand. */
12065 if (inst.vectype.elems == 1 && els > 1)
12066 {
12067 unsigned j;
12068 inst.vectype.elems = els;
12069 inst.vectype.el[key_el] = inst.vectype.el[0];
12070 for (j = 0; j < els; j++)
dcbf9037
JB
12071 if (j != key_el)
12072 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12073 types[j]);
12074 }
12075 else if (inst.vectype.elems == 0 && els > 0)
12076 {
12077 unsigned j;
12078 /* No types were given after the mnemonic, so look for types specified
12079 after each operand. We allow some flexibility here; as long as the
12080 "key" operand has a type, we can infer the others. */
12081 for (j = 0; j < els; j++)
12082 if (inst.operands[j].vectype.type != NT_invtype)
12083 inst.vectype.el[j] = inst.operands[j].vectype;
12084
12085 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12086 {
dcbf9037
JB
12087 for (j = 0; j < els; j++)
12088 if (inst.operands[j].vectype.type == NT_invtype)
12089 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12090 types[j]);
12091 }
12092 else
12093 {
12094 first_error (_("operand types can't be inferred"));
12095 return badtype;
5287ad62
JB
12096 }
12097 }
12098 else if (inst.vectype.elems != els)
12099 {
dcbf9037 12100 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12101 return badtype;
12102 }
12103
12104 for (pass = 0; pass < 2; pass++)
12105 {
12106 for (i = 0; i < els; i++)
12107 {
12108 unsigned thisarg = types[i];
12109 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12110 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12111 enum neon_el_type g_type = inst.vectype.el[i].type;
12112 unsigned g_size = inst.vectype.el[i].size;
12113
12114 /* Decay more-specific signed & unsigned types to sign-insensitive
12115 integer types if sign-specific variants are unavailable. */
12116 if ((g_type == NT_signed || g_type == NT_unsigned)
12117 && (types_allowed & N_SU_ALL) == 0)
12118 g_type = NT_integer;
12119
12120 /* If only untyped args are allowed, decay any more specific types to
12121 them. Some instructions only care about signs for some element
12122 sizes, so handle that properly. */
12123 if ((g_size == 8 && (types_allowed & N_8) != 0)
12124 || (g_size == 16 && (types_allowed & N_16) != 0)
12125 || (g_size == 32 && (types_allowed & N_32) != 0)
12126 || (g_size == 64 && (types_allowed & N_64) != 0))
12127 g_type = NT_untyped;
12128
12129 if (pass == 0)
12130 {
12131 if ((thisarg & N_KEY) != 0)
12132 {
12133 k_type = g_type;
12134 k_size = g_size;
12135 key_allowed = thisarg & ~N_KEY;
12136 }
12137 }
12138 else
12139 {
037e8744
JB
12140 if ((thisarg & N_VFP) != 0)
12141 {
99b253c5
NC
12142 enum neon_shape_el regshape;
12143 unsigned regwidth, match;
12144
12145 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12146 if (ns == NS_NULL)
12147 {
12148 first_error (_("invalid instruction shape"));
12149 return badtype;
12150 }
12151 regshape = neon_shape_tab[ns].el[i];
12152 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12153
12154 /* In VFP mode, operands must match register widths. If we
12155 have a key operand, use its width, else use the width of
12156 the current operand. */
12157 if (k_size != -1u)
12158 match = k_size;
12159 else
12160 match = g_size;
12161
12162 if (regwidth != match)
12163 {
12164 first_error (_("operand size must match register width"));
12165 return badtype;
12166 }
12167 }
5f4273c7 12168
5287ad62
JB
12169 if ((thisarg & N_EQK) == 0)
12170 {
12171 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12172
12173 if ((given_type & types_allowed) == 0)
12174 {
dcbf9037 12175 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12176 return badtype;
12177 }
12178 }
12179 else
12180 {
12181 enum neon_el_type mod_k_type = k_type;
12182 unsigned mod_k_size = k_size;
12183 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12184 if (g_type != mod_k_type || g_size != mod_k_size)
12185 {
dcbf9037 12186 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12187 return badtype;
12188 }
12189 }
12190 }
12191 }
12192 }
12193
12194 return inst.vectype.el[key_el];
12195}
12196
037e8744 12197/* Neon-style VFP instruction forwarding. */
5287ad62 12198
037e8744
JB
12199/* Thumb VFP instructions have 0xE in the condition field. */
12200
12201static void
12202do_vfp_cond_or_thumb (void)
5287ad62 12203{
88714cb8
DG
12204 inst.is_neon = 1;
12205
5287ad62 12206 if (thumb_mode)
037e8744 12207 inst.instruction |= 0xe0000000;
5287ad62 12208 else
037e8744 12209 inst.instruction |= inst.cond << 28;
5287ad62
JB
12210}
12211
037e8744
JB
12212/* Look up and encode a simple mnemonic, for use as a helper function for the
12213 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12214 etc. It is assumed that operand parsing has already been done, and that the
12215 operands are in the form expected by the given opcode (this isn't necessarily
12216 the same as the form in which they were parsed, hence some massaging must
12217 take place before this function is called).
12218 Checks current arch version against that in the looked-up opcode. */
5287ad62 12219
037e8744
JB
12220static void
12221do_vfp_nsyn_opcode (const char *opname)
5287ad62 12222{
037e8744 12223 const struct asm_opcode *opcode;
5f4273c7 12224
21d799b5 12225 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12226
037e8744
JB
12227 if (!opcode)
12228 abort ();
5287ad62 12229
037e8744
JB
12230 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12231 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12232 _(BAD_FPU));
5287ad62 12233
88714cb8
DG
12234 inst.is_neon = 1;
12235
037e8744
JB
12236 if (thumb_mode)
12237 {
12238 inst.instruction = opcode->tvalue;
12239 opcode->tencode ();
12240 }
12241 else
12242 {
12243 inst.instruction = (inst.cond << 28) | opcode->avalue;
12244 opcode->aencode ();
12245 }
12246}
5287ad62
JB
12247
12248static void
037e8744 12249do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12250{
037e8744
JB
12251 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12252
12253 if (rs == NS_FFF)
12254 {
12255 if (is_add)
12256 do_vfp_nsyn_opcode ("fadds");
12257 else
12258 do_vfp_nsyn_opcode ("fsubs");
12259 }
12260 else
12261 {
12262 if (is_add)
12263 do_vfp_nsyn_opcode ("faddd");
12264 else
12265 do_vfp_nsyn_opcode ("fsubd");
12266 }
12267}
12268
12269/* Check operand types to see if this is a VFP instruction, and if so call
12270 PFN (). */
12271
12272static int
12273try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12274{
12275 enum neon_shape rs;
12276 struct neon_type_el et;
12277
12278 switch (args)
12279 {
12280 case 2:
12281 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12282 et = neon_check_type (2, rs,
12283 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12284 break;
5f4273c7 12285
037e8744
JB
12286 case 3:
12287 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12288 et = neon_check_type (3, rs,
12289 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12290 break;
12291
12292 default:
12293 abort ();
12294 }
12295
12296 if (et.type != NT_invtype)
12297 {
12298 pfn (rs);
12299 return SUCCESS;
12300 }
037e8744 12301
99b253c5 12302 inst.error = NULL;
037e8744
JB
12303 return FAIL;
12304}
12305
12306static void
12307do_vfp_nsyn_mla_mls (enum neon_shape rs)
12308{
12309 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12310
037e8744
JB
12311 if (rs == NS_FFF)
12312 {
12313 if (is_mla)
12314 do_vfp_nsyn_opcode ("fmacs");
12315 else
1ee69515 12316 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12317 }
12318 else
12319 {
12320 if (is_mla)
12321 do_vfp_nsyn_opcode ("fmacd");
12322 else
1ee69515 12323 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12324 }
12325}
12326
62f3b8c8
PB
12327static void
12328do_vfp_nsyn_fma_fms (enum neon_shape rs)
12329{
12330 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12331
12332 if (rs == NS_FFF)
12333 {
12334 if (is_fma)
12335 do_vfp_nsyn_opcode ("ffmas");
12336 else
12337 do_vfp_nsyn_opcode ("ffnmas");
12338 }
12339 else
12340 {
12341 if (is_fma)
12342 do_vfp_nsyn_opcode ("ffmad");
12343 else
12344 do_vfp_nsyn_opcode ("ffnmad");
12345 }
12346}
12347
037e8744
JB
12348static void
12349do_vfp_nsyn_mul (enum neon_shape rs)
12350{
12351 if (rs == NS_FFF)
12352 do_vfp_nsyn_opcode ("fmuls");
12353 else
12354 do_vfp_nsyn_opcode ("fmuld");
12355}
12356
12357static void
12358do_vfp_nsyn_abs_neg (enum neon_shape rs)
12359{
12360 int is_neg = (inst.instruction & 0x80) != 0;
12361 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12362
12363 if (rs == NS_FF)
12364 {
12365 if (is_neg)
12366 do_vfp_nsyn_opcode ("fnegs");
12367 else
12368 do_vfp_nsyn_opcode ("fabss");
12369 }
12370 else
12371 {
12372 if (is_neg)
12373 do_vfp_nsyn_opcode ("fnegd");
12374 else
12375 do_vfp_nsyn_opcode ("fabsd");
12376 }
12377}
12378
12379/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12380 insns belong to Neon, and are handled elsewhere. */
12381
12382static void
12383do_vfp_nsyn_ldm_stm (int is_dbmode)
12384{
12385 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12386 if (is_ldm)
12387 {
12388 if (is_dbmode)
12389 do_vfp_nsyn_opcode ("fldmdbs");
12390 else
12391 do_vfp_nsyn_opcode ("fldmias");
12392 }
12393 else
12394 {
12395 if (is_dbmode)
12396 do_vfp_nsyn_opcode ("fstmdbs");
12397 else
12398 do_vfp_nsyn_opcode ("fstmias");
12399 }
12400}
12401
037e8744
JB
12402static void
12403do_vfp_nsyn_sqrt (void)
12404{
12405 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12406 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12407
037e8744
JB
12408 if (rs == NS_FF)
12409 do_vfp_nsyn_opcode ("fsqrts");
12410 else
12411 do_vfp_nsyn_opcode ("fsqrtd");
12412}
12413
12414static void
12415do_vfp_nsyn_div (void)
12416{
12417 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12418 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12419 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12420
037e8744
JB
12421 if (rs == NS_FFF)
12422 do_vfp_nsyn_opcode ("fdivs");
12423 else
12424 do_vfp_nsyn_opcode ("fdivd");
12425}
12426
12427static void
12428do_vfp_nsyn_nmul (void)
12429{
12430 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12431 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12432 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12433
037e8744
JB
12434 if (rs == NS_FFF)
12435 {
88714cb8 12436 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12437 do_vfp_sp_dyadic ();
12438 }
12439 else
12440 {
88714cb8 12441 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12442 do_vfp_dp_rd_rn_rm ();
12443 }
12444 do_vfp_cond_or_thumb ();
12445}
12446
12447static void
12448do_vfp_nsyn_cmp (void)
12449{
12450 if (inst.operands[1].isreg)
12451 {
12452 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12453 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12454
037e8744
JB
12455 if (rs == NS_FF)
12456 {
88714cb8 12457 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12458 do_vfp_sp_monadic ();
12459 }
12460 else
12461 {
88714cb8 12462 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12463 do_vfp_dp_rd_rm ();
12464 }
12465 }
12466 else
12467 {
12468 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12469 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12470
12471 switch (inst.instruction & 0x0fffffff)
12472 {
12473 case N_MNEM_vcmp:
12474 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12475 break;
12476 case N_MNEM_vcmpe:
12477 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12478 break;
12479 default:
12480 abort ();
12481 }
5f4273c7 12482
037e8744
JB
12483 if (rs == NS_FI)
12484 {
88714cb8 12485 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12486 do_vfp_sp_compare_z ();
12487 }
12488 else
12489 {
88714cb8 12490 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12491 do_vfp_dp_rd ();
12492 }
12493 }
12494 do_vfp_cond_or_thumb ();
12495}
12496
12497static void
12498nsyn_insert_sp (void)
12499{
12500 inst.operands[1] = inst.operands[0];
12501 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12502 inst.operands[0].reg = REG_SP;
037e8744
JB
12503 inst.operands[0].isreg = 1;
12504 inst.operands[0].writeback = 1;
12505 inst.operands[0].present = 1;
12506}
12507
12508static void
12509do_vfp_nsyn_push (void)
12510{
12511 nsyn_insert_sp ();
12512 if (inst.operands[1].issingle)
12513 do_vfp_nsyn_opcode ("fstmdbs");
12514 else
12515 do_vfp_nsyn_opcode ("fstmdbd");
12516}
12517
12518static void
12519do_vfp_nsyn_pop (void)
12520{
12521 nsyn_insert_sp ();
12522 if (inst.operands[1].issingle)
22b5b651 12523 do_vfp_nsyn_opcode ("fldmias");
037e8744 12524 else
22b5b651 12525 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12526}
12527
12528/* Fix up Neon data-processing instructions, ORing in the correct bits for
12529 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12530
88714cb8
DG
12531static void
12532neon_dp_fixup (struct arm_it* insn)
037e8744 12533{
88714cb8
DG
12534 unsigned int i = insn->instruction;
12535 insn->is_neon = 1;
12536
037e8744
JB
12537 if (thumb_mode)
12538 {
12539 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12540 if (i & (1 << 24))
12541 i |= 1 << 28;
5f4273c7 12542
037e8744 12543 i &= ~(1 << 24);
5f4273c7 12544
037e8744
JB
12545 i |= 0xef000000;
12546 }
12547 else
12548 i |= 0xf2000000;
5f4273c7 12549
88714cb8 12550 insn->instruction = i;
037e8744
JB
12551}
12552
12553/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12554 (0, 1, 2, 3). */
12555
12556static unsigned
12557neon_logbits (unsigned x)
12558{
12559 return ffs (x) - 4;
12560}
12561
12562#define LOW4(R) ((R) & 0xf)
12563#define HI1(R) (((R) >> 4) & 1)
12564
12565/* Encode insns with bit pattern:
12566
12567 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12568 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12569
037e8744
JB
12570 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12571 different meaning for some instruction. */
12572
12573static void
12574neon_three_same (int isquad, int ubit, int size)
12575{
12576 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12577 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12578 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12579 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12580 inst.instruction |= LOW4 (inst.operands[2].reg);
12581 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12582 inst.instruction |= (isquad != 0) << 6;
12583 inst.instruction |= (ubit != 0) << 24;
12584 if (size != -1)
12585 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12586
88714cb8 12587 neon_dp_fixup (&inst);
037e8744
JB
12588}
12589
12590/* Encode instructions of the form:
12591
12592 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12593 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12594
12595 Don't write size if SIZE == -1. */
12596
12597static void
12598neon_two_same (int qbit, int ubit, int size)
12599{
12600 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12601 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12602 inst.instruction |= LOW4 (inst.operands[1].reg);
12603 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12604 inst.instruction |= (qbit != 0) << 6;
12605 inst.instruction |= (ubit != 0) << 24;
12606
12607 if (size != -1)
12608 inst.instruction |= neon_logbits (size) << 18;
12609
88714cb8 12610 neon_dp_fixup (&inst);
5287ad62
JB
12611}
12612
12613/* Neon instruction encoders, in approximate order of appearance. */
12614
12615static void
12616do_neon_dyadic_i_su (void)
12617{
037e8744 12618 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12619 struct neon_type_el et = neon_check_type (3, rs,
12620 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12621 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12622}
12623
12624static void
12625do_neon_dyadic_i64_su (void)
12626{
037e8744 12627 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12628 struct neon_type_el et = neon_check_type (3, rs,
12629 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12630 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12631}
12632
12633static void
12634neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12635 unsigned immbits)
12636{
12637 unsigned size = et.size >> 3;
12638 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12639 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12640 inst.instruction |= LOW4 (inst.operands[1].reg);
12641 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12642 inst.instruction |= (isquad != 0) << 6;
12643 inst.instruction |= immbits << 16;
12644 inst.instruction |= (size >> 3) << 7;
12645 inst.instruction |= (size & 0x7) << 19;
12646 if (write_ubit)
12647 inst.instruction |= (uval != 0) << 24;
12648
88714cb8 12649 neon_dp_fixup (&inst);
5287ad62
JB
12650}
12651
12652static void
12653do_neon_shl_imm (void)
12654{
12655 if (!inst.operands[2].isreg)
12656 {
037e8744 12657 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12658 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12659 NEON_ENCODE (IMMED, inst);
037e8744 12660 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12661 }
12662 else
12663 {
037e8744 12664 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12665 struct neon_type_el et = neon_check_type (3, rs,
12666 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12667 unsigned int tmp;
12668
12669 /* VSHL/VQSHL 3-register variants have syntax such as:
12670 vshl.xx Dd, Dm, Dn
12671 whereas other 3-register operations encoded by neon_three_same have
12672 syntax like:
12673 vadd.xx Dd, Dn, Dm
12674 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12675 here. */
12676 tmp = inst.operands[2].reg;
12677 inst.operands[2].reg = inst.operands[1].reg;
12678 inst.operands[1].reg = tmp;
88714cb8 12679 NEON_ENCODE (INTEGER, inst);
037e8744 12680 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12681 }
12682}
12683
12684static void
12685do_neon_qshl_imm (void)
12686{
12687 if (!inst.operands[2].isreg)
12688 {
037e8744 12689 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12690 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12691
88714cb8 12692 NEON_ENCODE (IMMED, inst);
037e8744 12693 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12694 inst.operands[2].imm);
12695 }
12696 else
12697 {
037e8744 12698 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12699 struct neon_type_el et = neon_check_type (3, rs,
12700 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12701 unsigned int tmp;
12702
12703 /* See note in do_neon_shl_imm. */
12704 tmp = inst.operands[2].reg;
12705 inst.operands[2].reg = inst.operands[1].reg;
12706 inst.operands[1].reg = tmp;
88714cb8 12707 NEON_ENCODE (INTEGER, inst);
037e8744 12708 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12709 }
12710}
12711
627907b7
JB
12712static void
12713do_neon_rshl (void)
12714{
12715 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12716 struct neon_type_el et = neon_check_type (3, rs,
12717 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12718 unsigned int tmp;
12719
12720 tmp = inst.operands[2].reg;
12721 inst.operands[2].reg = inst.operands[1].reg;
12722 inst.operands[1].reg = tmp;
12723 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12724}
12725
5287ad62
JB
12726static int
12727neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12728{
036dc3f7
PB
12729 /* Handle .I8 pseudo-instructions. */
12730 if (size == 8)
5287ad62 12731 {
5287ad62
JB
12732 /* Unfortunately, this will make everything apart from zero out-of-range.
12733 FIXME is this the intended semantics? There doesn't seem much point in
12734 accepting .I8 if so. */
12735 immediate |= immediate << 8;
12736 size = 16;
036dc3f7
PB
12737 }
12738
12739 if (size >= 32)
12740 {
12741 if (immediate == (immediate & 0x000000ff))
12742 {
12743 *immbits = immediate;
12744 return 0x1;
12745 }
12746 else if (immediate == (immediate & 0x0000ff00))
12747 {
12748 *immbits = immediate >> 8;
12749 return 0x3;
12750 }
12751 else if (immediate == (immediate & 0x00ff0000))
12752 {
12753 *immbits = immediate >> 16;
12754 return 0x5;
12755 }
12756 else if (immediate == (immediate & 0xff000000))
12757 {
12758 *immbits = immediate >> 24;
12759 return 0x7;
12760 }
12761 if ((immediate & 0xffff) != (immediate >> 16))
12762 goto bad_immediate;
12763 immediate &= 0xffff;
5287ad62
JB
12764 }
12765
12766 if (immediate == (immediate & 0x000000ff))
12767 {
12768 *immbits = immediate;
036dc3f7 12769 return 0x9;
5287ad62
JB
12770 }
12771 else if (immediate == (immediate & 0x0000ff00))
12772 {
12773 *immbits = immediate >> 8;
036dc3f7 12774 return 0xb;
5287ad62
JB
12775 }
12776
12777 bad_immediate:
dcbf9037 12778 first_error (_("immediate value out of range"));
5287ad62
JB
12779 return FAIL;
12780}
12781
12782/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12783 A, B, C, D. */
12784
12785static int
12786neon_bits_same_in_bytes (unsigned imm)
12787{
12788 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12789 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12790 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12791 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12792}
12793
12794/* For immediate of above form, return 0bABCD. */
12795
12796static unsigned
12797neon_squash_bits (unsigned imm)
12798{
12799 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12800 | ((imm & 0x01000000) >> 21);
12801}
12802
136da414 12803/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12804
12805static unsigned
12806neon_qfloat_bits (unsigned imm)
12807{
136da414 12808 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12809}
12810
12811/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12812 the instruction. *OP is passed as the initial value of the op field, and
12813 may be set to a different value depending on the constant (i.e.
12814 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12815 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12816 try smaller element sizes. */
5287ad62
JB
12817
12818static int
c96612cc
JB
12819neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12820 unsigned *immbits, int *op, int size,
12821 enum neon_el_type type)
5287ad62 12822{
c96612cc
JB
12823 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12824 float. */
12825 if (type == NT_float && !float_p)
12826 return FAIL;
12827
136da414
JB
12828 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12829 {
12830 if (size != 32 || *op == 1)
12831 return FAIL;
12832 *immbits = neon_qfloat_bits (immlo);
12833 return 0xf;
12834 }
036dc3f7
PB
12835
12836 if (size == 64)
5287ad62 12837 {
036dc3f7
PB
12838 if (neon_bits_same_in_bytes (immhi)
12839 && neon_bits_same_in_bytes (immlo))
12840 {
12841 if (*op == 1)
12842 return FAIL;
12843 *immbits = (neon_squash_bits (immhi) << 4)
12844 | neon_squash_bits (immlo);
12845 *op = 1;
12846 return 0xe;
12847 }
12848
12849 if (immhi != immlo)
12850 return FAIL;
5287ad62 12851 }
036dc3f7
PB
12852
12853 if (size >= 32)
5287ad62 12854 {
036dc3f7
PB
12855 if (immlo == (immlo & 0x000000ff))
12856 {
12857 *immbits = immlo;
12858 return 0x0;
12859 }
12860 else if (immlo == (immlo & 0x0000ff00))
12861 {
12862 *immbits = immlo >> 8;
12863 return 0x2;
12864 }
12865 else if (immlo == (immlo & 0x00ff0000))
12866 {
12867 *immbits = immlo >> 16;
12868 return 0x4;
12869 }
12870 else if (immlo == (immlo & 0xff000000))
12871 {
12872 *immbits = immlo >> 24;
12873 return 0x6;
12874 }
12875 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12876 {
12877 *immbits = (immlo >> 8) & 0xff;
12878 return 0xc;
12879 }
12880 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12881 {
12882 *immbits = (immlo >> 16) & 0xff;
12883 return 0xd;
12884 }
12885
12886 if ((immlo & 0xffff) != (immlo >> 16))
12887 return FAIL;
12888 immlo &= 0xffff;
5287ad62 12889 }
036dc3f7
PB
12890
12891 if (size >= 16)
5287ad62 12892 {
036dc3f7
PB
12893 if (immlo == (immlo & 0x000000ff))
12894 {
12895 *immbits = immlo;
12896 return 0x8;
12897 }
12898 else if (immlo == (immlo & 0x0000ff00))
12899 {
12900 *immbits = immlo >> 8;
12901 return 0xa;
12902 }
12903
12904 if ((immlo & 0xff) != (immlo >> 8))
12905 return FAIL;
12906 immlo &= 0xff;
5287ad62 12907 }
036dc3f7
PB
12908
12909 if (immlo == (immlo & 0x000000ff))
5287ad62 12910 {
036dc3f7
PB
12911 /* Don't allow MVN with 8-bit immediate. */
12912 if (*op == 1)
12913 return FAIL;
12914 *immbits = immlo;
12915 return 0xe;
5287ad62 12916 }
5287ad62
JB
12917
12918 return FAIL;
12919}
12920
12921/* Write immediate bits [7:0] to the following locations:
12922
12923 |28/24|23 19|18 16|15 4|3 0|
12924 | 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|
12925
12926 This function is used by VMOV/VMVN/VORR/VBIC. */
12927
12928static void
12929neon_write_immbits (unsigned immbits)
12930{
12931 inst.instruction |= immbits & 0xf;
12932 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12933 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12934}
12935
12936/* Invert low-order SIZE bits of XHI:XLO. */
12937
12938static void
12939neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12940{
12941 unsigned immlo = xlo ? *xlo : 0;
12942 unsigned immhi = xhi ? *xhi : 0;
12943
12944 switch (size)
12945 {
12946 case 8:
12947 immlo = (~immlo) & 0xff;
12948 break;
12949
12950 case 16:
12951 immlo = (~immlo) & 0xffff;
12952 break;
12953
12954 case 64:
12955 immhi = (~immhi) & 0xffffffff;
12956 /* fall through. */
12957
12958 case 32:
12959 immlo = (~immlo) & 0xffffffff;
12960 break;
12961
12962 default:
12963 abort ();
12964 }
12965
12966 if (xlo)
12967 *xlo = immlo;
12968
12969 if (xhi)
12970 *xhi = immhi;
12971}
12972
12973static void
12974do_neon_logic (void)
12975{
12976 if (inst.operands[2].present && inst.operands[2].isreg)
12977 {
037e8744 12978 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12979 neon_check_type (3, rs, N_IGNORE_TYPE);
12980 /* U bit and size field were set as part of the bitmask. */
88714cb8 12981 NEON_ENCODE (INTEGER, inst);
037e8744 12982 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12983 }
12984 else
12985 {
4316f0d2
DG
12986 const int three_ops_form = (inst.operands[2].present
12987 && !inst.operands[2].isreg);
12988 const int immoperand = (three_ops_form ? 2 : 1);
12989 enum neon_shape rs = (three_ops_form
12990 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
12991 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
12992 struct neon_type_el et = neon_check_type (2, rs,
12993 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 12994 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
12995 unsigned immbits;
12996 int cmode;
5f4273c7 12997
5287ad62
JB
12998 if (et.type == NT_invtype)
12999 return;
5f4273c7 13000
4316f0d2
DG
13001 if (three_ops_form)
13002 constraint (inst.operands[0].reg != inst.operands[1].reg,
13003 _("first and second operands shall be the same register"));
13004
88714cb8 13005 NEON_ENCODE (IMMED, inst);
5287ad62 13006
4316f0d2 13007 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13008 if (et.size == 64)
13009 {
13010 /* .i64 is a pseudo-op, so the immediate must be a repeating
13011 pattern. */
4316f0d2
DG
13012 if (immbits != (inst.operands[immoperand].regisimm ?
13013 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13014 {
13015 /* Set immbits to an invalid constant. */
13016 immbits = 0xdeadbeef;
13017 }
13018 }
13019
5287ad62
JB
13020 switch (opcode)
13021 {
13022 case N_MNEM_vbic:
036dc3f7 13023 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13024 break;
5f4273c7 13025
5287ad62 13026 case N_MNEM_vorr:
036dc3f7 13027 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13028 break;
5f4273c7 13029
5287ad62
JB
13030 case N_MNEM_vand:
13031 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13032 neon_invert_size (&immbits, 0, et.size);
13033 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13034 break;
5f4273c7 13035
5287ad62
JB
13036 case N_MNEM_vorn:
13037 /* Pseudo-instruction for VORR. */
5287ad62
JB
13038 neon_invert_size (&immbits, 0, et.size);
13039 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13040 break;
5f4273c7 13041
5287ad62
JB
13042 default:
13043 abort ();
13044 }
13045
13046 if (cmode == FAIL)
13047 return;
13048
037e8744 13049 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13050 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13051 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13052 inst.instruction |= cmode << 8;
13053 neon_write_immbits (immbits);
5f4273c7 13054
88714cb8 13055 neon_dp_fixup (&inst);
5287ad62
JB
13056 }
13057}
13058
13059static void
13060do_neon_bitfield (void)
13061{
037e8744 13062 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13063 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13064 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13065}
13066
13067static void
dcbf9037
JB
13068neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13069 unsigned destbits)
5287ad62 13070{
037e8744 13071 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13072 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13073 types | N_KEY);
5287ad62
JB
13074 if (et.type == NT_float)
13075 {
88714cb8 13076 NEON_ENCODE (FLOAT, inst);
037e8744 13077 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13078 }
13079 else
13080 {
88714cb8 13081 NEON_ENCODE (INTEGER, inst);
037e8744 13082 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13083 }
13084}
13085
13086static void
13087do_neon_dyadic_if_su (void)
13088{
dcbf9037 13089 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13090}
13091
13092static void
13093do_neon_dyadic_if_su_d (void)
13094{
13095 /* This version only allow D registers, but that constraint is enforced during
13096 operand parsing so we don't need to do anything extra here. */
dcbf9037 13097 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13098}
13099
5287ad62
JB
13100static void
13101do_neon_dyadic_if_i_d (void)
13102{
428e3f1f
PB
13103 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13104 affected if we specify unsigned args. */
13105 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13106}
13107
037e8744
JB
13108enum vfp_or_neon_is_neon_bits
13109{
13110 NEON_CHECK_CC = 1,
13111 NEON_CHECK_ARCH = 2
13112};
13113
13114/* Call this function if an instruction which may have belonged to the VFP or
13115 Neon instruction sets, but turned out to be a Neon instruction (due to the
13116 operand types involved, etc.). We have to check and/or fix-up a couple of
13117 things:
13118
13119 - Make sure the user hasn't attempted to make a Neon instruction
13120 conditional.
13121 - Alter the value in the condition code field if necessary.
13122 - Make sure that the arch supports Neon instructions.
13123
13124 Which of these operations take place depends on bits from enum
13125 vfp_or_neon_is_neon_bits.
13126
13127 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13128 current instruction's condition is COND_ALWAYS, the condition field is
13129 changed to inst.uncond_value. This is necessary because instructions shared
13130 between VFP and Neon may be conditional for the VFP variants only, and the
13131 unconditional Neon version must have, e.g., 0xF in the condition field. */
13132
13133static int
13134vfp_or_neon_is_neon (unsigned check)
13135{
13136 /* Conditions are always legal in Thumb mode (IT blocks). */
13137 if (!thumb_mode && (check & NEON_CHECK_CC))
13138 {
13139 if (inst.cond != COND_ALWAYS)
13140 {
13141 first_error (_(BAD_COND));
13142 return FAIL;
13143 }
13144 if (inst.uncond_value != -1)
13145 inst.instruction |= inst.uncond_value << 28;
13146 }
5f4273c7 13147
037e8744
JB
13148 if ((check & NEON_CHECK_ARCH)
13149 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13150 {
13151 first_error (_(BAD_FPU));
13152 return FAIL;
13153 }
5f4273c7 13154
037e8744
JB
13155 return SUCCESS;
13156}
13157
5287ad62
JB
13158static void
13159do_neon_addsub_if_i (void)
13160{
037e8744
JB
13161 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13162 return;
13163
13164 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13165 return;
13166
5287ad62
JB
13167 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13168 affected if we specify unsigned args. */
dcbf9037 13169 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13170}
13171
13172/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13173 result to be:
13174 V<op> A,B (A is operand 0, B is operand 2)
13175 to mean:
13176 V<op> A,B,A
13177 not:
13178 V<op> A,B,B
13179 so handle that case specially. */
13180
13181static void
13182neon_exchange_operands (void)
13183{
13184 void *scratch = alloca (sizeof (inst.operands[0]));
13185 if (inst.operands[1].present)
13186 {
13187 /* Swap operands[1] and operands[2]. */
13188 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13189 inst.operands[1] = inst.operands[2];
13190 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13191 }
13192 else
13193 {
13194 inst.operands[1] = inst.operands[2];
13195 inst.operands[2] = inst.operands[0];
13196 }
13197}
13198
13199static void
13200neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13201{
13202 if (inst.operands[2].isreg)
13203 {
13204 if (invert)
13205 neon_exchange_operands ();
dcbf9037 13206 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13207 }
13208 else
13209 {
037e8744 13210 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13211 struct neon_type_el et = neon_check_type (2, rs,
13212 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13213
88714cb8 13214 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13215 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13216 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13217 inst.instruction |= LOW4 (inst.operands[1].reg);
13218 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13219 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13220 inst.instruction |= (et.type == NT_float) << 10;
13221 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13222
88714cb8 13223 neon_dp_fixup (&inst);
5287ad62
JB
13224 }
13225}
13226
13227static void
13228do_neon_cmp (void)
13229{
13230 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13231}
13232
13233static void
13234do_neon_cmp_inv (void)
13235{
13236 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13237}
13238
13239static void
13240do_neon_ceq (void)
13241{
13242 neon_compare (N_IF_32, N_IF_32, FALSE);
13243}
13244
13245/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13246 scalars, which are encoded in 5 bits, M : Rm.
13247 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13248 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13249 index in M. */
13250
13251static unsigned
13252neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13253{
dcbf9037
JB
13254 unsigned regno = NEON_SCALAR_REG (scalar);
13255 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13256
13257 switch (elsize)
13258 {
13259 case 16:
13260 if (regno > 7 || elno > 3)
13261 goto bad_scalar;
13262 return regno | (elno << 3);
5f4273c7 13263
5287ad62
JB
13264 case 32:
13265 if (regno > 15 || elno > 1)
13266 goto bad_scalar;
13267 return regno | (elno << 4);
13268
13269 default:
13270 bad_scalar:
dcbf9037 13271 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13272 }
13273
13274 return 0;
13275}
13276
13277/* Encode multiply / multiply-accumulate scalar instructions. */
13278
13279static void
13280neon_mul_mac (struct neon_type_el et, int ubit)
13281{
dcbf9037
JB
13282 unsigned scalar;
13283
13284 /* Give a more helpful error message if we have an invalid type. */
13285 if (et.type == NT_invtype)
13286 return;
5f4273c7 13287
dcbf9037 13288 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13289 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13290 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13291 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13292 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13293 inst.instruction |= LOW4 (scalar);
13294 inst.instruction |= HI1 (scalar) << 5;
13295 inst.instruction |= (et.type == NT_float) << 8;
13296 inst.instruction |= neon_logbits (et.size) << 20;
13297 inst.instruction |= (ubit != 0) << 24;
13298
88714cb8 13299 neon_dp_fixup (&inst);
5287ad62
JB
13300}
13301
13302static void
13303do_neon_mac_maybe_scalar (void)
13304{
037e8744
JB
13305 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13306 return;
13307
13308 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13309 return;
13310
5287ad62
JB
13311 if (inst.operands[2].isscalar)
13312 {
037e8744 13313 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13314 struct neon_type_el et = neon_check_type (3, rs,
13315 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13316 NEON_ENCODE (SCALAR, inst);
037e8744 13317 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13318 }
13319 else
428e3f1f
PB
13320 {
13321 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13322 affected if we specify unsigned args. */
13323 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13324 }
5287ad62
JB
13325}
13326
62f3b8c8
PB
13327static void
13328do_neon_fmac (void)
13329{
13330 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13331 return;
13332
13333 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13334 return;
13335
13336 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13337}
13338
5287ad62
JB
13339static void
13340do_neon_tst (void)
13341{
037e8744 13342 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13343 struct neon_type_el et = neon_check_type (3, rs,
13344 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13345 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13346}
13347
13348/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13349 same types as the MAC equivalents. The polynomial type for this instruction
13350 is encoded the same as the integer type. */
13351
13352static void
13353do_neon_mul (void)
13354{
037e8744
JB
13355 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13356 return;
13357
13358 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13359 return;
13360
5287ad62
JB
13361 if (inst.operands[2].isscalar)
13362 do_neon_mac_maybe_scalar ();
13363 else
dcbf9037 13364 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13365}
13366
13367static void
13368do_neon_qdmulh (void)
13369{
13370 if (inst.operands[2].isscalar)
13371 {
037e8744 13372 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13373 struct neon_type_el et = neon_check_type (3, rs,
13374 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13375 NEON_ENCODE (SCALAR, inst);
037e8744 13376 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13377 }
13378 else
13379 {
037e8744 13380 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13381 struct neon_type_el et = neon_check_type (3, rs,
13382 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13383 NEON_ENCODE (INTEGER, inst);
5287ad62 13384 /* The U bit (rounding) comes from bit mask. */
037e8744 13385 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13386 }
13387}
13388
13389static void
13390do_neon_fcmp_absolute (void)
13391{
037e8744 13392 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13393 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13394 /* Size field comes from bit mask. */
037e8744 13395 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13396}
13397
13398static void
13399do_neon_fcmp_absolute_inv (void)
13400{
13401 neon_exchange_operands ();
13402 do_neon_fcmp_absolute ();
13403}
13404
13405static void
13406do_neon_step (void)
13407{
037e8744 13408 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13409 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13410 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13411}
13412
13413static void
13414do_neon_abs_neg (void)
13415{
037e8744
JB
13416 enum neon_shape rs;
13417 struct neon_type_el et;
5f4273c7 13418
037e8744
JB
13419 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13420 return;
13421
13422 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13423 return;
13424
13425 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13426 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13427
5287ad62
JB
13428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13429 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13430 inst.instruction |= LOW4 (inst.operands[1].reg);
13431 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13432 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13433 inst.instruction |= (et.type == NT_float) << 10;
13434 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13435
88714cb8 13436 neon_dp_fixup (&inst);
5287ad62
JB
13437}
13438
13439static void
13440do_neon_sli (void)
13441{
037e8744 13442 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13443 struct neon_type_el et = neon_check_type (2, rs,
13444 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13445 int imm = inst.operands[2].imm;
13446 constraint (imm < 0 || (unsigned)imm >= et.size,
13447 _("immediate out of range for insert"));
037e8744 13448 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13449}
13450
13451static void
13452do_neon_sri (void)
13453{
037e8744 13454 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13455 struct neon_type_el et = neon_check_type (2, rs,
13456 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13457 int imm = inst.operands[2].imm;
13458 constraint (imm < 1 || (unsigned)imm > et.size,
13459 _("immediate out of range for insert"));
037e8744 13460 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13461}
13462
13463static void
13464do_neon_qshlu_imm (void)
13465{
037e8744 13466 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13467 struct neon_type_el et = neon_check_type (2, rs,
13468 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13469 int imm = inst.operands[2].imm;
13470 constraint (imm < 0 || (unsigned)imm >= et.size,
13471 _("immediate out of range for shift"));
13472 /* Only encodes the 'U present' variant of the instruction.
13473 In this case, signed types have OP (bit 8) set to 0.
13474 Unsigned types have OP set to 1. */
13475 inst.instruction |= (et.type == NT_unsigned) << 8;
13476 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13477 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13478}
13479
13480static void
13481do_neon_qmovn (void)
13482{
13483 struct neon_type_el et = neon_check_type (2, NS_DQ,
13484 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13485 /* Saturating move where operands can be signed or unsigned, and the
13486 destination has the same signedness. */
88714cb8 13487 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13488 if (et.type == NT_unsigned)
13489 inst.instruction |= 0xc0;
13490 else
13491 inst.instruction |= 0x80;
13492 neon_two_same (0, 1, et.size / 2);
13493}
13494
13495static void
13496do_neon_qmovun (void)
13497{
13498 struct neon_type_el et = neon_check_type (2, NS_DQ,
13499 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13500 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13501 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13502 neon_two_same (0, 1, et.size / 2);
13503}
13504
13505static void
13506do_neon_rshift_sat_narrow (void)
13507{
13508 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13509 or unsigned. If operands are unsigned, results must also be unsigned. */
13510 struct neon_type_el et = neon_check_type (2, NS_DQI,
13511 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13512 int imm = inst.operands[2].imm;
13513 /* This gets the bounds check, size encoding and immediate bits calculation
13514 right. */
13515 et.size /= 2;
5f4273c7 13516
5287ad62
JB
13517 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13518 VQMOVN.I<size> <Dd>, <Qm>. */
13519 if (imm == 0)
13520 {
13521 inst.operands[2].present = 0;
13522 inst.instruction = N_MNEM_vqmovn;
13523 do_neon_qmovn ();
13524 return;
13525 }
5f4273c7 13526
5287ad62
JB
13527 constraint (imm < 1 || (unsigned)imm > et.size,
13528 _("immediate out of range"));
13529 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13530}
13531
13532static void
13533do_neon_rshift_sat_narrow_u (void)
13534{
13535 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13536 or unsigned. If operands are unsigned, results must also be unsigned. */
13537 struct neon_type_el et = neon_check_type (2, NS_DQI,
13538 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13539 int imm = inst.operands[2].imm;
13540 /* This gets the bounds check, size encoding and immediate bits calculation
13541 right. */
13542 et.size /= 2;
13543
13544 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13545 VQMOVUN.I<size> <Dd>, <Qm>. */
13546 if (imm == 0)
13547 {
13548 inst.operands[2].present = 0;
13549 inst.instruction = N_MNEM_vqmovun;
13550 do_neon_qmovun ();
13551 return;
13552 }
13553
13554 constraint (imm < 1 || (unsigned)imm > et.size,
13555 _("immediate out of range"));
13556 /* FIXME: The manual is kind of unclear about what value U should have in
13557 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13558 must be 1. */
13559 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13560}
13561
13562static void
13563do_neon_movn (void)
13564{
13565 struct neon_type_el et = neon_check_type (2, NS_DQ,
13566 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13567 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13568 neon_two_same (0, 1, et.size / 2);
13569}
13570
13571static void
13572do_neon_rshift_narrow (void)
13573{
13574 struct neon_type_el et = neon_check_type (2, NS_DQI,
13575 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13576 int imm = inst.operands[2].imm;
13577 /* This gets the bounds check, size encoding and immediate bits calculation
13578 right. */
13579 et.size /= 2;
5f4273c7 13580
5287ad62
JB
13581 /* If immediate is zero then we are a pseudo-instruction for
13582 VMOVN.I<size> <Dd>, <Qm> */
13583 if (imm == 0)
13584 {
13585 inst.operands[2].present = 0;
13586 inst.instruction = N_MNEM_vmovn;
13587 do_neon_movn ();
13588 return;
13589 }
5f4273c7 13590
5287ad62
JB
13591 constraint (imm < 1 || (unsigned)imm > et.size,
13592 _("immediate out of range for narrowing operation"));
13593 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13594}
13595
13596static void
13597do_neon_shll (void)
13598{
13599 /* FIXME: Type checking when lengthening. */
13600 struct neon_type_el et = neon_check_type (2, NS_QDI,
13601 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13602 unsigned imm = inst.operands[2].imm;
13603
13604 if (imm == et.size)
13605 {
13606 /* Maximum shift variant. */
88714cb8 13607 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13608 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13609 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13610 inst.instruction |= LOW4 (inst.operands[1].reg);
13611 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13612 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13613
88714cb8 13614 neon_dp_fixup (&inst);
5287ad62
JB
13615 }
13616 else
13617 {
13618 /* A more-specific type check for non-max versions. */
13619 et = neon_check_type (2, NS_QDI,
13620 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13621 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13622 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13623 }
13624}
13625
037e8744 13626/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13627 the current instruction is. */
13628
13629static int
13630neon_cvt_flavour (enum neon_shape rs)
13631{
037e8744
JB
13632#define CVT_VAR(C,X,Y) \
13633 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13634 if (et.type != NT_invtype) \
13635 { \
13636 inst.error = NULL; \
13637 return (C); \
5287ad62
JB
13638 }
13639 struct neon_type_el et;
037e8744
JB
13640 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13641 || rs == NS_FF) ? N_VFP : 0;
13642 /* The instruction versions which take an immediate take one register
13643 argument, which is extended to the width of the full register. Thus the
13644 "source" and "destination" registers must have the same width. Hack that
13645 here by making the size equal to the key (wider, in this case) operand. */
13646 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13647
5287ad62
JB
13648 CVT_VAR (0, N_S32, N_F32);
13649 CVT_VAR (1, N_U32, N_F32);
13650 CVT_VAR (2, N_F32, N_S32);
13651 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13652 /* Half-precision conversions. */
13653 CVT_VAR (4, N_F32, N_F16);
13654 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13655
037e8744 13656 whole_reg = N_VFP;
5f4273c7 13657
037e8744 13658 /* VFP instructions. */
8e79c3df
CM
13659 CVT_VAR (6, N_F32, N_F64);
13660 CVT_VAR (7, N_F64, N_F32);
13661 CVT_VAR (8, N_S32, N_F64 | key);
13662 CVT_VAR (9, N_U32, N_F64 | key);
13663 CVT_VAR (10, N_F64 | key, N_S32);
13664 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13665 /* VFP instructions with bitshift. */
8e79c3df
CM
13666 CVT_VAR (12, N_F32 | key, N_S16);
13667 CVT_VAR (13, N_F32 | key, N_U16);
13668 CVT_VAR (14, N_F64 | key, N_S16);
13669 CVT_VAR (15, N_F64 | key, N_U16);
13670 CVT_VAR (16, N_S16, N_F32 | key);
13671 CVT_VAR (17, N_U16, N_F32 | key);
13672 CVT_VAR (18, N_S16, N_F64 | key);
13673 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13674
5287ad62
JB
13675 return -1;
13676#undef CVT_VAR
13677}
13678
037e8744
JB
13679/* Neon-syntax VFP conversions. */
13680
5287ad62 13681static void
037e8744 13682do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13683{
037e8744 13684 const char *opname = 0;
5f4273c7 13685
037e8744 13686 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13687 {
037e8744
JB
13688 /* Conversions with immediate bitshift. */
13689 const char *enc[] =
13690 {
13691 "ftosls",
13692 "ftouls",
13693 "fsltos",
13694 "fultos",
13695 NULL,
13696 NULL,
8e79c3df
CM
13697 NULL,
13698 NULL,
037e8744
JB
13699 "ftosld",
13700 "ftould",
13701 "fsltod",
13702 "fultod",
13703 "fshtos",
13704 "fuhtos",
13705 "fshtod",
13706 "fuhtod",
13707 "ftoshs",
13708 "ftouhs",
13709 "ftoshd",
13710 "ftouhd"
13711 };
13712
13713 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13714 {
13715 opname = enc[flavour];
13716 constraint (inst.operands[0].reg != inst.operands[1].reg,
13717 _("operands 0 and 1 must be the same register"));
13718 inst.operands[1] = inst.operands[2];
13719 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13720 }
5287ad62
JB
13721 }
13722 else
13723 {
037e8744
JB
13724 /* Conversions without bitshift. */
13725 const char *enc[] =
13726 {
13727 "ftosis",
13728 "ftouis",
13729 "fsitos",
13730 "fuitos",
8e79c3df
CM
13731 "NULL",
13732 "NULL",
037e8744
JB
13733 "fcvtsd",
13734 "fcvtds",
13735 "ftosid",
13736 "ftouid",
13737 "fsitod",
13738 "fuitod"
13739 };
13740
13741 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13742 opname = enc[flavour];
13743 }
13744
13745 if (opname)
13746 do_vfp_nsyn_opcode (opname);
13747}
13748
13749static void
13750do_vfp_nsyn_cvtz (void)
13751{
13752 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13753 int flavour = neon_cvt_flavour (rs);
13754 const char *enc[] =
13755 {
13756 "ftosizs",
13757 "ftouizs",
13758 NULL,
13759 NULL,
13760 NULL,
13761 NULL,
8e79c3df
CM
13762 NULL,
13763 NULL,
037e8744
JB
13764 "ftosizd",
13765 "ftouizd"
13766 };
13767
13768 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13769 do_vfp_nsyn_opcode (enc[flavour]);
13770}
f31fef98 13771
037e8744 13772static void
e3e535bc 13773do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
13774{
13775 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13776 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13777 int flavour = neon_cvt_flavour (rs);
13778
e3e535bc
NC
13779 /* PR11109: Handle round-to-zero for VCVT conversions. */
13780 if (round_to_zero
13781 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13782 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13783 && (rs == NS_FD || rs == NS_FF))
13784 {
13785 do_vfp_nsyn_cvtz ();
13786 return;
13787 }
13788
037e8744 13789 /* VFP rather than Neon conversions. */
8e79c3df 13790 if (flavour >= 6)
037e8744
JB
13791 {
13792 do_vfp_nsyn_cvt (rs, flavour);
13793 return;
13794 }
13795
13796 switch (rs)
13797 {
13798 case NS_DDI:
13799 case NS_QQI:
13800 {
35997600
NC
13801 unsigned immbits;
13802 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13803
037e8744
JB
13804 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13805 return;
13806
13807 /* Fixed-point conversion with #0 immediate is encoded as an
13808 integer conversion. */
13809 if (inst.operands[2].present && inst.operands[2].imm == 0)
13810 goto int_encode;
35997600 13811 immbits = 32 - inst.operands[2].imm;
88714cb8 13812 NEON_ENCODE (IMMED, inst);
037e8744
JB
13813 if (flavour != -1)
13814 inst.instruction |= enctab[flavour];
13815 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13816 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13817 inst.instruction |= LOW4 (inst.operands[1].reg);
13818 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13819 inst.instruction |= neon_quad (rs) << 6;
13820 inst.instruction |= 1 << 21;
13821 inst.instruction |= immbits << 16;
13822
88714cb8 13823 neon_dp_fixup (&inst);
037e8744
JB
13824 }
13825 break;
13826
13827 case NS_DD:
13828 case NS_QQ:
13829 int_encode:
13830 {
13831 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13832
88714cb8 13833 NEON_ENCODE (INTEGER, inst);
037e8744
JB
13834
13835 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13836 return;
13837
13838 if (flavour != -1)
13839 inst.instruction |= enctab[flavour];
13840
13841 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13842 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13843 inst.instruction |= LOW4 (inst.operands[1].reg);
13844 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13845 inst.instruction |= neon_quad (rs) << 6;
13846 inst.instruction |= 2 << 18;
13847
88714cb8 13848 neon_dp_fixup (&inst);
037e8744
JB
13849 }
13850 break;
13851
8e79c3df
CM
13852 /* Half-precision conversions for Advanced SIMD -- neon. */
13853 case NS_QD:
13854 case NS_DQ:
13855
13856 if ((rs == NS_DQ)
13857 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13858 {
13859 as_bad (_("operand size must match register width"));
13860 break;
13861 }
13862
13863 if ((rs == NS_QD)
13864 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13865 {
13866 as_bad (_("operand size must match register width"));
13867 break;
13868 }
13869
13870 if (rs == NS_DQ)
13871 inst.instruction = 0x3b60600;
13872 else
13873 inst.instruction = 0x3b60700;
13874
13875 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13876 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13877 inst.instruction |= LOW4 (inst.operands[1].reg);
13878 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 13879 neon_dp_fixup (&inst);
8e79c3df
CM
13880 break;
13881
037e8744
JB
13882 default:
13883 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13884 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13885 }
5287ad62
JB
13886}
13887
e3e535bc
NC
13888static void
13889do_neon_cvtr (void)
13890{
13891 do_neon_cvt_1 (FALSE);
13892}
13893
13894static void
13895do_neon_cvt (void)
13896{
13897 do_neon_cvt_1 (TRUE);
13898}
13899
8e79c3df
CM
13900static void
13901do_neon_cvtb (void)
13902{
13903 inst.instruction = 0xeb20a40;
13904
13905 /* The sizes are attached to the mnemonic. */
13906 if (inst.vectype.el[0].type != NT_invtype
13907 && inst.vectype.el[0].size == 16)
13908 inst.instruction |= 0x00010000;
13909
13910 /* Programmer's syntax: the sizes are attached to the operands. */
13911 else if (inst.operands[0].vectype.type != NT_invtype
13912 && inst.operands[0].vectype.size == 16)
13913 inst.instruction |= 0x00010000;
13914
13915 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13916 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13917 do_vfp_cond_or_thumb ();
13918}
13919
13920
13921static void
13922do_neon_cvtt (void)
13923{
13924 do_neon_cvtb ();
13925 inst.instruction |= 0x80;
13926}
13927
5287ad62
JB
13928static void
13929neon_move_immediate (void)
13930{
037e8744
JB
13931 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13932 struct neon_type_el et = neon_check_type (2, rs,
13933 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13934 unsigned immlo, immhi = 0, immbits;
c96612cc 13935 int op, cmode, float_p;
5287ad62 13936
037e8744
JB
13937 constraint (et.type == NT_invtype,
13938 _("operand size must be specified for immediate VMOV"));
13939
5287ad62
JB
13940 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13941 op = (inst.instruction & (1 << 5)) != 0;
13942
13943 immlo = inst.operands[1].imm;
13944 if (inst.operands[1].regisimm)
13945 immhi = inst.operands[1].reg;
13946
13947 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13948 _("immediate has bits set outside the operand size"));
13949
c96612cc
JB
13950 float_p = inst.operands[1].immisfloat;
13951
13952 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13953 et.size, et.type)) == FAIL)
5287ad62
JB
13954 {
13955 /* Invert relevant bits only. */
13956 neon_invert_size (&immlo, &immhi, et.size);
13957 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13958 with one or the other; those cases are caught by
13959 neon_cmode_for_move_imm. */
13960 op = !op;
c96612cc
JB
13961 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13962 &op, et.size, et.type)) == FAIL)
5287ad62 13963 {
dcbf9037 13964 first_error (_("immediate out of range"));
5287ad62
JB
13965 return;
13966 }
13967 }
13968
13969 inst.instruction &= ~(1 << 5);
13970 inst.instruction |= op << 5;
13971
13972 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13973 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13974 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13975 inst.instruction |= cmode << 8;
13976
13977 neon_write_immbits (immbits);
13978}
13979
13980static void
13981do_neon_mvn (void)
13982{
13983 if (inst.operands[1].isreg)
13984 {
037e8744 13985 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13986
88714cb8 13987 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13988 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13989 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13990 inst.instruction |= LOW4 (inst.operands[1].reg);
13991 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13992 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13993 }
13994 else
13995 {
88714cb8 13996 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13997 neon_move_immediate ();
13998 }
13999
88714cb8 14000 neon_dp_fixup (&inst);
5287ad62
JB
14001}
14002
14003/* Encode instructions of form:
14004
14005 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14006 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14007
14008static void
14009neon_mixed_length (struct neon_type_el et, unsigned size)
14010{
14011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14013 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14014 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14015 inst.instruction |= LOW4 (inst.operands[2].reg);
14016 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14017 inst.instruction |= (et.type == NT_unsigned) << 24;
14018 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14019
88714cb8 14020 neon_dp_fixup (&inst);
5287ad62
JB
14021}
14022
14023static void
14024do_neon_dyadic_long (void)
14025{
14026 /* FIXME: Type checking for lengthening op. */
14027 struct neon_type_el et = neon_check_type (3, NS_QDD,
14028 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14029 neon_mixed_length (et, et.size);
14030}
14031
14032static void
14033do_neon_abal (void)
14034{
14035 struct neon_type_el et = neon_check_type (3, NS_QDD,
14036 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14037 neon_mixed_length (et, et.size);
14038}
14039
14040static void
14041neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14042{
14043 if (inst.operands[2].isscalar)
14044 {
dcbf9037
JB
14045 struct neon_type_el et = neon_check_type (3, NS_QDS,
14046 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14047 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14048 neon_mul_mac (et, et.type == NT_unsigned);
14049 }
14050 else
14051 {
14052 struct neon_type_el et = neon_check_type (3, NS_QDD,
14053 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14054 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14055 neon_mixed_length (et, et.size);
14056 }
14057}
14058
14059static void
14060do_neon_mac_maybe_scalar_long (void)
14061{
14062 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14063}
14064
14065static void
14066do_neon_dyadic_wide (void)
14067{
14068 struct neon_type_el et = neon_check_type (3, NS_QQD,
14069 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14070 neon_mixed_length (et, et.size);
14071}
14072
14073static void
14074do_neon_dyadic_narrow (void)
14075{
14076 struct neon_type_el et = neon_check_type (3, NS_QDD,
14077 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14078 /* Operand sign is unimportant, and the U bit is part of the opcode,
14079 so force the operand type to integer. */
14080 et.type = NT_integer;
5287ad62
JB
14081 neon_mixed_length (et, et.size / 2);
14082}
14083
14084static void
14085do_neon_mul_sat_scalar_long (void)
14086{
14087 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14088}
14089
14090static void
14091do_neon_vmull (void)
14092{
14093 if (inst.operands[2].isscalar)
14094 do_neon_mac_maybe_scalar_long ();
14095 else
14096 {
14097 struct neon_type_el et = neon_check_type (3, NS_QDD,
14098 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14099 if (et.type == NT_poly)
88714cb8 14100 NEON_ENCODE (POLY, inst);
5287ad62 14101 else
88714cb8 14102 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14103 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14104 zero. Should be OK as-is. */
14105 neon_mixed_length (et, et.size);
14106 }
14107}
14108
14109static void
14110do_neon_ext (void)
14111{
037e8744 14112 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14113 struct neon_type_el et = neon_check_type (3, rs,
14114 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14115 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14116
14117 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14118 _("shift out of range"));
5287ad62
JB
14119 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14120 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14121 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14122 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14123 inst.instruction |= LOW4 (inst.operands[2].reg);
14124 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14125 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14126 inst.instruction |= imm << 8;
5f4273c7 14127
88714cb8 14128 neon_dp_fixup (&inst);
5287ad62
JB
14129}
14130
14131static void
14132do_neon_rev (void)
14133{
037e8744 14134 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14135 struct neon_type_el et = neon_check_type (2, rs,
14136 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14137 unsigned op = (inst.instruction >> 7) & 3;
14138 /* N (width of reversed regions) is encoded as part of the bitmask. We
14139 extract it here to check the elements to be reversed are smaller.
14140 Otherwise we'd get a reserved instruction. */
14141 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14142 gas_assert (elsize != 0);
5287ad62
JB
14143 constraint (et.size >= elsize,
14144 _("elements must be smaller than reversal region"));
037e8744 14145 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14146}
14147
14148static void
14149do_neon_dup (void)
14150{
14151 if (inst.operands[1].isscalar)
14152 {
037e8744 14153 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14154 struct neon_type_el et = neon_check_type (2, rs,
14155 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14156 unsigned sizebits = et.size >> 3;
dcbf9037 14157 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14158 int logsize = neon_logbits (et.size);
dcbf9037 14159 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14160
14161 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14162 return;
14163
88714cb8 14164 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14165 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14166 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14167 inst.instruction |= LOW4 (dm);
14168 inst.instruction |= HI1 (dm) << 5;
037e8744 14169 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14170 inst.instruction |= x << 17;
14171 inst.instruction |= sizebits << 16;
5f4273c7 14172
88714cb8 14173 neon_dp_fixup (&inst);
5287ad62
JB
14174 }
14175 else
14176 {
037e8744
JB
14177 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14178 struct neon_type_el et = neon_check_type (2, rs,
14179 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14180 /* Duplicate ARM register to lanes of vector. */
88714cb8 14181 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14182 switch (et.size)
14183 {
14184 case 8: inst.instruction |= 0x400000; break;
14185 case 16: inst.instruction |= 0x000020; break;
14186 case 32: inst.instruction |= 0x000000; break;
14187 default: break;
14188 }
14189 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14190 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14191 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14192 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14193 /* The encoding for this instruction is identical for the ARM and Thumb
14194 variants, except for the condition field. */
037e8744 14195 do_vfp_cond_or_thumb ();
5287ad62
JB
14196 }
14197}
14198
14199/* VMOV has particularly many variations. It can be one of:
14200 0. VMOV<c><q> <Qd>, <Qm>
14201 1. VMOV<c><q> <Dd>, <Dm>
14202 (Register operations, which are VORR with Rm = Rn.)
14203 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14204 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14205 (Immediate loads.)
14206 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14207 (ARM register to scalar.)
14208 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14209 (Two ARM registers to vector.)
14210 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14211 (Scalar to ARM register.)
14212 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14213 (Vector to two ARM registers.)
037e8744
JB
14214 8. VMOV.F32 <Sd>, <Sm>
14215 9. VMOV.F64 <Dd>, <Dm>
14216 (VFP register moves.)
14217 10. VMOV.F32 <Sd>, #imm
14218 11. VMOV.F64 <Dd>, #imm
14219 (VFP float immediate load.)
14220 12. VMOV <Rd>, <Sm>
14221 (VFP single to ARM reg.)
14222 13. VMOV <Sd>, <Rm>
14223 (ARM reg to VFP single.)
14224 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14225 (Two ARM regs to two VFP singles.)
14226 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14227 (Two VFP singles to two ARM regs.)
5f4273c7 14228
037e8744
JB
14229 These cases can be disambiguated using neon_select_shape, except cases 1/9
14230 and 3/11 which depend on the operand type too.
5f4273c7 14231
5287ad62 14232 All the encoded bits are hardcoded by this function.
5f4273c7 14233
b7fc2769
JB
14234 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14235 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14236
5287ad62 14237 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14238 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14239
14240static void
14241do_neon_mov (void)
14242{
037e8744
JB
14243 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14244 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14245 NS_NULL);
14246 struct neon_type_el et;
14247 const char *ldconst = 0;
5287ad62 14248
037e8744 14249 switch (rs)
5287ad62 14250 {
037e8744
JB
14251 case NS_DD: /* case 1/9. */
14252 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14253 /* It is not an error here if no type is given. */
14254 inst.error = NULL;
14255 if (et.type == NT_float && et.size == 64)
5287ad62 14256 {
037e8744
JB
14257 do_vfp_nsyn_opcode ("fcpyd");
14258 break;
5287ad62 14259 }
037e8744 14260 /* fall through. */
5287ad62 14261
037e8744
JB
14262 case NS_QQ: /* case 0/1. */
14263 {
14264 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14265 return;
14266 /* The architecture manual I have doesn't explicitly state which
14267 value the U bit should have for register->register moves, but
14268 the equivalent VORR instruction has U = 0, so do that. */
14269 inst.instruction = 0x0200110;
14270 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14271 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14272 inst.instruction |= LOW4 (inst.operands[1].reg);
14273 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14274 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14275 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14276 inst.instruction |= neon_quad (rs) << 6;
14277
88714cb8 14278 neon_dp_fixup (&inst);
037e8744
JB
14279 }
14280 break;
5f4273c7 14281
037e8744
JB
14282 case NS_DI: /* case 3/11. */
14283 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14284 inst.error = NULL;
14285 if (et.type == NT_float && et.size == 64)
5287ad62 14286 {
037e8744
JB
14287 /* case 11 (fconstd). */
14288 ldconst = "fconstd";
14289 goto encode_fconstd;
5287ad62 14290 }
037e8744
JB
14291 /* fall through. */
14292
14293 case NS_QI: /* case 2/3. */
14294 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14295 return;
14296 inst.instruction = 0x0800010;
14297 neon_move_immediate ();
88714cb8 14298 neon_dp_fixup (&inst);
5287ad62 14299 break;
5f4273c7 14300
037e8744
JB
14301 case NS_SR: /* case 4. */
14302 {
14303 unsigned bcdebits = 0;
91d6fa6a 14304 int logsize;
037e8744
JB
14305 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14306 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14307
91d6fa6a
NC
14308 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14309 logsize = neon_logbits (et.size);
14310
037e8744
JB
14311 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14312 _(BAD_FPU));
14313 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14314 && et.size != 32, _(BAD_FPU));
14315 constraint (et.type == NT_invtype, _("bad type for scalar"));
14316 constraint (x >= 64 / et.size, _("scalar index out of range"));
14317
14318 switch (et.size)
14319 {
14320 case 8: bcdebits = 0x8; break;
14321 case 16: bcdebits = 0x1; break;
14322 case 32: bcdebits = 0x0; break;
14323 default: ;
14324 }
14325
14326 bcdebits |= x << logsize;
14327
14328 inst.instruction = 0xe000b10;
14329 do_vfp_cond_or_thumb ();
14330 inst.instruction |= LOW4 (dn) << 16;
14331 inst.instruction |= HI1 (dn) << 7;
14332 inst.instruction |= inst.operands[1].reg << 12;
14333 inst.instruction |= (bcdebits & 3) << 5;
14334 inst.instruction |= (bcdebits >> 2) << 21;
14335 }
14336 break;
5f4273c7 14337
037e8744 14338 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14339 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14340 _(BAD_FPU));
b7fc2769 14341
037e8744
JB
14342 inst.instruction = 0xc400b10;
14343 do_vfp_cond_or_thumb ();
14344 inst.instruction |= LOW4 (inst.operands[0].reg);
14345 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14346 inst.instruction |= inst.operands[1].reg << 12;
14347 inst.instruction |= inst.operands[2].reg << 16;
14348 break;
5f4273c7 14349
037e8744
JB
14350 case NS_RS: /* case 6. */
14351 {
91d6fa6a 14352 unsigned logsize;
037e8744
JB
14353 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14354 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14355 unsigned abcdebits = 0;
14356
91d6fa6a
NC
14357 et = neon_check_type (2, NS_NULL,
14358 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14359 logsize = neon_logbits (et.size);
14360
037e8744
JB
14361 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14362 _(BAD_FPU));
14363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14364 && et.size != 32, _(BAD_FPU));
14365 constraint (et.type == NT_invtype, _("bad type for scalar"));
14366 constraint (x >= 64 / et.size, _("scalar index out of range"));
14367
14368 switch (et.size)
14369 {
14370 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14371 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14372 case 32: abcdebits = 0x00; break;
14373 default: ;
14374 }
14375
14376 abcdebits |= x << logsize;
14377 inst.instruction = 0xe100b10;
14378 do_vfp_cond_or_thumb ();
14379 inst.instruction |= LOW4 (dn) << 16;
14380 inst.instruction |= HI1 (dn) << 7;
14381 inst.instruction |= inst.operands[0].reg << 12;
14382 inst.instruction |= (abcdebits & 3) << 5;
14383 inst.instruction |= (abcdebits >> 2) << 21;
14384 }
14385 break;
5f4273c7 14386
037e8744
JB
14387 case NS_RRD: /* case 7 (fmrrd). */
14388 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14389 _(BAD_FPU));
14390
14391 inst.instruction = 0xc500b10;
14392 do_vfp_cond_or_thumb ();
14393 inst.instruction |= inst.operands[0].reg << 12;
14394 inst.instruction |= inst.operands[1].reg << 16;
14395 inst.instruction |= LOW4 (inst.operands[2].reg);
14396 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14397 break;
5f4273c7 14398
037e8744
JB
14399 case NS_FF: /* case 8 (fcpys). */
14400 do_vfp_nsyn_opcode ("fcpys");
14401 break;
5f4273c7 14402
037e8744
JB
14403 case NS_FI: /* case 10 (fconsts). */
14404 ldconst = "fconsts";
14405 encode_fconstd:
14406 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14407 {
037e8744
JB
14408 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14409 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14410 }
14411 else
037e8744
JB
14412 first_error (_("immediate out of range"));
14413 break;
5f4273c7 14414
037e8744
JB
14415 case NS_RF: /* case 12 (fmrs). */
14416 do_vfp_nsyn_opcode ("fmrs");
14417 break;
5f4273c7 14418
037e8744
JB
14419 case NS_FR: /* case 13 (fmsr). */
14420 do_vfp_nsyn_opcode ("fmsr");
14421 break;
5f4273c7 14422
037e8744
JB
14423 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14424 (one of which is a list), but we have parsed four. Do some fiddling to
14425 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14426 expect. */
14427 case NS_RRFF: /* case 14 (fmrrs). */
14428 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14429 _("VFP registers must be adjacent"));
14430 inst.operands[2].imm = 2;
14431 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14432 do_vfp_nsyn_opcode ("fmrrs");
14433 break;
5f4273c7 14434
037e8744
JB
14435 case NS_FFRR: /* case 15 (fmsrr). */
14436 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14437 _("VFP registers must be adjacent"));
14438 inst.operands[1] = inst.operands[2];
14439 inst.operands[2] = inst.operands[3];
14440 inst.operands[0].imm = 2;
14441 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14442 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14443 break;
5f4273c7 14444
5287ad62
JB
14445 default:
14446 abort ();
14447 }
14448}
14449
14450static void
14451do_neon_rshift_round_imm (void)
14452{
037e8744 14453 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14454 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14455 int imm = inst.operands[2].imm;
14456
14457 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14458 if (imm == 0)
14459 {
14460 inst.operands[2].present = 0;
14461 do_neon_mov ();
14462 return;
14463 }
14464
14465 constraint (imm < 1 || (unsigned)imm > et.size,
14466 _("immediate out of range for shift"));
037e8744 14467 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14468 et.size - imm);
14469}
14470
14471static void
14472do_neon_movl (void)
14473{
14474 struct neon_type_el et = neon_check_type (2, NS_QD,
14475 N_EQK | N_DBL, N_SU_32 | N_KEY);
14476 unsigned sizebits = et.size >> 3;
14477 inst.instruction |= sizebits << 19;
14478 neon_two_same (0, et.type == NT_unsigned, -1);
14479}
14480
14481static void
14482do_neon_trn (void)
14483{
037e8744 14484 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14485 struct neon_type_el et = neon_check_type (2, rs,
14486 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14487 NEON_ENCODE (INTEGER, inst);
037e8744 14488 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14489}
14490
14491static void
14492do_neon_zip_uzp (void)
14493{
037e8744 14494 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14495 struct neon_type_el et = neon_check_type (2, rs,
14496 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14497 if (rs == NS_DD && et.size == 32)
14498 {
14499 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14500 inst.instruction = N_MNEM_vtrn;
14501 do_neon_trn ();
14502 return;
14503 }
037e8744 14504 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14505}
14506
14507static void
14508do_neon_sat_abs_neg (void)
14509{
037e8744 14510 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14511 struct neon_type_el et = neon_check_type (2, rs,
14512 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14513 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14514}
14515
14516static void
14517do_neon_pair_long (void)
14518{
037e8744 14519 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14520 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14521 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14522 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14523 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14524}
14525
14526static void
14527do_neon_recip_est (void)
14528{
037e8744 14529 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14530 struct neon_type_el et = neon_check_type (2, rs,
14531 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14532 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14533 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14534}
14535
14536static void
14537do_neon_cls (void)
14538{
037e8744 14539 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14540 struct neon_type_el et = neon_check_type (2, rs,
14541 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14542 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14543}
14544
14545static void
14546do_neon_clz (void)
14547{
037e8744 14548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14549 struct neon_type_el et = neon_check_type (2, rs,
14550 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14551 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14552}
14553
14554static void
14555do_neon_cnt (void)
14556{
037e8744 14557 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14558 struct neon_type_el et = neon_check_type (2, rs,
14559 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14560 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14561}
14562
14563static void
14564do_neon_swp (void)
14565{
037e8744
JB
14566 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14567 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14568}
14569
14570static void
14571do_neon_tbl_tbx (void)
14572{
14573 unsigned listlenbits;
dcbf9037 14574 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14575
5287ad62
JB
14576 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14577 {
dcbf9037 14578 first_error (_("bad list length for table lookup"));
5287ad62
JB
14579 return;
14580 }
5f4273c7 14581
5287ad62
JB
14582 listlenbits = inst.operands[1].imm - 1;
14583 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14584 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14585 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14586 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14587 inst.instruction |= LOW4 (inst.operands[2].reg);
14588 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14589 inst.instruction |= listlenbits << 8;
5f4273c7 14590
88714cb8 14591 neon_dp_fixup (&inst);
5287ad62
JB
14592}
14593
14594static void
14595do_neon_ldm_stm (void)
14596{
14597 /* P, U and L bits are part of bitmask. */
14598 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14599 unsigned offsetbits = inst.operands[1].imm * 2;
14600
037e8744
JB
14601 if (inst.operands[1].issingle)
14602 {
14603 do_vfp_nsyn_ldm_stm (is_dbmode);
14604 return;
14605 }
14606
5287ad62
JB
14607 constraint (is_dbmode && !inst.operands[0].writeback,
14608 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14609
14610 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14611 _("register list must contain at least 1 and at most 16 "
14612 "registers"));
14613
14614 inst.instruction |= inst.operands[0].reg << 16;
14615 inst.instruction |= inst.operands[0].writeback << 21;
14616 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14617 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14618
14619 inst.instruction |= offsetbits;
5f4273c7 14620
037e8744 14621 do_vfp_cond_or_thumb ();
5287ad62
JB
14622}
14623
14624static void
14625do_neon_ldr_str (void)
14626{
5287ad62 14627 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14628
037e8744
JB
14629 if (inst.operands[0].issingle)
14630 {
cd2f129f
JB
14631 if (is_ldr)
14632 do_vfp_nsyn_opcode ("flds");
14633 else
14634 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14635 }
14636 else
5287ad62 14637 {
cd2f129f
JB
14638 if (is_ldr)
14639 do_vfp_nsyn_opcode ("fldd");
5287ad62 14640 else
cd2f129f 14641 do_vfp_nsyn_opcode ("fstd");
5287ad62 14642 }
5287ad62
JB
14643}
14644
14645/* "interleave" version also handles non-interleaving register VLD1/VST1
14646 instructions. */
14647
14648static void
14649do_neon_ld_st_interleave (void)
14650{
037e8744 14651 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14652 N_8 | N_16 | N_32 | N_64);
14653 unsigned alignbits = 0;
14654 unsigned idx;
14655 /* The bits in this table go:
14656 0: register stride of one (0) or two (1)
14657 1,2: register list length, minus one (1, 2, 3, 4).
14658 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14659 We use -1 for invalid entries. */
14660 const int typetable[] =
14661 {
14662 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14663 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14664 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14665 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14666 };
14667 int typebits;
14668
dcbf9037
JB
14669 if (et.type == NT_invtype)
14670 return;
14671
5287ad62
JB
14672 if (inst.operands[1].immisalign)
14673 switch (inst.operands[1].imm >> 8)
14674 {
14675 case 64: alignbits = 1; break;
14676 case 128:
e23c0ad8
JZ
14677 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14678 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14679 goto bad_alignment;
14680 alignbits = 2;
14681 break;
14682 case 256:
e23c0ad8 14683 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14684 goto bad_alignment;
14685 alignbits = 3;
14686 break;
14687 default:
14688 bad_alignment:
dcbf9037 14689 first_error (_("bad alignment"));
5287ad62
JB
14690 return;
14691 }
14692
14693 inst.instruction |= alignbits << 4;
14694 inst.instruction |= neon_logbits (et.size) << 6;
14695
14696 /* Bits [4:6] of the immediate in a list specifier encode register stride
14697 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14698 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14699 up the right value for "type" in a table based on this value and the given
14700 list style, then stick it back. */
14701 idx = ((inst.operands[0].imm >> 4) & 7)
14702 | (((inst.instruction >> 8) & 3) << 3);
14703
14704 typebits = typetable[idx];
5f4273c7 14705
5287ad62
JB
14706 constraint (typebits == -1, _("bad list type for instruction"));
14707
14708 inst.instruction &= ~0xf00;
14709 inst.instruction |= typebits << 8;
14710}
14711
14712/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14713 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14714 otherwise. The variable arguments are a list of pairs of legal (size, align)
14715 values, terminated with -1. */
14716
14717static int
14718neon_alignment_bit (int size, int align, int *do_align, ...)
14719{
14720 va_list ap;
14721 int result = FAIL, thissize, thisalign;
5f4273c7 14722
5287ad62
JB
14723 if (!inst.operands[1].immisalign)
14724 {
14725 *do_align = 0;
14726 return SUCCESS;
14727 }
5f4273c7 14728
5287ad62
JB
14729 va_start (ap, do_align);
14730
14731 do
14732 {
14733 thissize = va_arg (ap, int);
14734 if (thissize == -1)
14735 break;
14736 thisalign = va_arg (ap, int);
14737
14738 if (size == thissize && align == thisalign)
14739 result = SUCCESS;
14740 }
14741 while (result != SUCCESS);
14742
14743 va_end (ap);
14744
14745 if (result == SUCCESS)
14746 *do_align = 1;
14747 else
dcbf9037 14748 first_error (_("unsupported alignment for instruction"));
5f4273c7 14749
5287ad62
JB
14750 return result;
14751}
14752
14753static void
14754do_neon_ld_st_lane (void)
14755{
037e8744 14756 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14757 int align_good, do_align = 0;
14758 int logsize = neon_logbits (et.size);
14759 int align = inst.operands[1].imm >> 8;
14760 int n = (inst.instruction >> 8) & 3;
14761 int max_el = 64 / et.size;
5f4273c7 14762
dcbf9037
JB
14763 if (et.type == NT_invtype)
14764 return;
5f4273c7 14765
5287ad62
JB
14766 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14767 _("bad list length"));
14768 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14769 _("scalar index out of range"));
14770 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14771 && et.size == 8,
14772 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14773
5287ad62
JB
14774 switch (n)
14775 {
14776 case 0: /* VLD1 / VST1. */
14777 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14778 32, 32, -1);
14779 if (align_good == FAIL)
14780 return;
14781 if (do_align)
14782 {
14783 unsigned alignbits = 0;
14784 switch (et.size)
14785 {
14786 case 16: alignbits = 0x1; break;
14787 case 32: alignbits = 0x3; break;
14788 default: ;
14789 }
14790 inst.instruction |= alignbits << 4;
14791 }
14792 break;
14793
14794 case 1: /* VLD2 / VST2. */
14795 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14796 32, 64, -1);
14797 if (align_good == FAIL)
14798 return;
14799 if (do_align)
14800 inst.instruction |= 1 << 4;
14801 break;
14802
14803 case 2: /* VLD3 / VST3. */
14804 constraint (inst.operands[1].immisalign,
14805 _("can't use alignment with this instruction"));
14806 break;
14807
14808 case 3: /* VLD4 / VST4. */
14809 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14810 16, 64, 32, 64, 32, 128, -1);
14811 if (align_good == FAIL)
14812 return;
14813 if (do_align)
14814 {
14815 unsigned alignbits = 0;
14816 switch (et.size)
14817 {
14818 case 8: alignbits = 0x1; break;
14819 case 16: alignbits = 0x1; break;
14820 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14821 default: ;
14822 }
14823 inst.instruction |= alignbits << 4;
14824 }
14825 break;
14826
14827 default: ;
14828 }
14829
14830 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14831 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14832 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14833
5287ad62
JB
14834 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14835 inst.instruction |= logsize << 10;
14836}
14837
14838/* Encode single n-element structure to all lanes VLD<n> instructions. */
14839
14840static void
14841do_neon_ld_dup (void)
14842{
037e8744 14843 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14844 int align_good, do_align = 0;
14845
dcbf9037
JB
14846 if (et.type == NT_invtype)
14847 return;
14848
5287ad62
JB
14849 switch ((inst.instruction >> 8) & 3)
14850 {
14851 case 0: /* VLD1. */
9c2799c2 14852 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14853 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14854 &do_align, 16, 16, 32, 32, -1);
14855 if (align_good == FAIL)
14856 return;
14857 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14858 {
14859 case 1: break;
14860 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14861 default: first_error (_("bad list length")); return;
5287ad62
JB
14862 }
14863 inst.instruction |= neon_logbits (et.size) << 6;
14864 break;
14865
14866 case 1: /* VLD2. */
14867 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14868 &do_align, 8, 16, 16, 32, 32, 64, -1);
14869 if (align_good == FAIL)
14870 return;
14871 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14872 _("bad list length"));
14873 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14874 inst.instruction |= 1 << 5;
14875 inst.instruction |= neon_logbits (et.size) << 6;
14876 break;
14877
14878 case 2: /* VLD3. */
14879 constraint (inst.operands[1].immisalign,
14880 _("can't use alignment with this instruction"));
14881 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14882 _("bad list length"));
14883 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14884 inst.instruction |= 1 << 5;
14885 inst.instruction |= neon_logbits (et.size) << 6;
14886 break;
14887
14888 case 3: /* VLD4. */
14889 {
14890 int align = inst.operands[1].imm >> 8;
14891 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14892 16, 64, 32, 64, 32, 128, -1);
14893 if (align_good == FAIL)
14894 return;
14895 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14896 _("bad list length"));
14897 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14898 inst.instruction |= 1 << 5;
14899 if (et.size == 32 && align == 128)
14900 inst.instruction |= 0x3 << 6;
14901 else
14902 inst.instruction |= neon_logbits (et.size) << 6;
14903 }
14904 break;
14905
14906 default: ;
14907 }
14908
14909 inst.instruction |= do_align << 4;
14910}
14911
14912/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14913 apart from bits [11:4]. */
14914
14915static void
14916do_neon_ldx_stx (void)
14917{
b1a769ed
DG
14918 if (inst.operands[1].isreg)
14919 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14920
5287ad62
JB
14921 switch (NEON_LANE (inst.operands[0].imm))
14922 {
14923 case NEON_INTERLEAVE_LANES:
88714cb8 14924 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
14925 do_neon_ld_st_interleave ();
14926 break;
5f4273c7 14927
5287ad62 14928 case NEON_ALL_LANES:
88714cb8 14929 NEON_ENCODE (DUP, inst);
5287ad62
JB
14930 do_neon_ld_dup ();
14931 break;
5f4273c7 14932
5287ad62 14933 default:
88714cb8 14934 NEON_ENCODE (LANE, inst);
5287ad62
JB
14935 do_neon_ld_st_lane ();
14936 }
14937
14938 /* L bit comes from bit mask. */
14939 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14940 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14941 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14942
5287ad62
JB
14943 if (inst.operands[1].postind)
14944 {
14945 int postreg = inst.operands[1].imm & 0xf;
14946 constraint (!inst.operands[1].immisreg,
14947 _("post-index must be a register"));
14948 constraint (postreg == 0xd || postreg == 0xf,
14949 _("bad register for post-index"));
14950 inst.instruction |= postreg;
14951 }
14952 else if (inst.operands[1].writeback)
14953 {
14954 inst.instruction |= 0xd;
14955 }
14956 else
5f4273c7
NC
14957 inst.instruction |= 0xf;
14958
5287ad62
JB
14959 if (thumb_mode)
14960 inst.instruction |= 0xf9000000;
14961 else
14962 inst.instruction |= 0xf4000000;
14963}
5287ad62
JB
14964\f
14965/* Overall per-instruction processing. */
14966
14967/* We need to be able to fix up arbitrary expressions in some statements.
14968 This is so that we can handle symbols that are an arbitrary distance from
14969 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14970 which returns part of an address in a form which will be valid for
14971 a data instruction. We do this by pushing the expression into a symbol
14972 in the expr_section, and creating a fix for that. */
14973
14974static void
14975fix_new_arm (fragS * frag,
14976 int where,
14977 short int size,
14978 expressionS * exp,
14979 int pc_rel,
14980 int reloc)
14981{
14982 fixS * new_fix;
14983
14984 switch (exp->X_op)
14985 {
14986 case O_constant:
14987 case O_symbol:
14988 case O_add:
14989 case O_subtract:
21d799b5
NC
14990 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14991 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14992 break;
14993
14994 default:
21d799b5
NC
14995 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14996 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14997 break;
14998 }
14999
15000 /* Mark whether the fix is to a THUMB instruction, or an ARM
15001 instruction. */
15002 new_fix->tc_fix_data = thumb_mode;
15003}
15004
15005/* Create a frg for an instruction requiring relaxation. */
15006static void
15007output_relax_insn (void)
15008{
15009 char * to;
15010 symbolS *sym;
0110f2b8
PB
15011 int offset;
15012
6e1cb1a6
PB
15013 /* The size of the instruction is unknown, so tie the debug info to the
15014 start of the instruction. */
15015 dwarf2_emit_insn (0);
6e1cb1a6 15016
0110f2b8
PB
15017 switch (inst.reloc.exp.X_op)
15018 {
15019 case O_symbol:
15020 sym = inst.reloc.exp.X_add_symbol;
15021 offset = inst.reloc.exp.X_add_number;
15022 break;
15023 case O_constant:
15024 sym = NULL;
15025 offset = inst.reloc.exp.X_add_number;
15026 break;
15027 default:
15028 sym = make_expr_symbol (&inst.reloc.exp);
15029 offset = 0;
15030 break;
15031 }
15032 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15033 inst.relax, sym, offset, NULL/*offset, opcode*/);
15034 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15035}
15036
15037/* Write a 32-bit thumb instruction to buf. */
15038static void
15039put_thumb32_insn (char * buf, unsigned long insn)
15040{
15041 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15042 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15043}
15044
b99bd4ef 15045static void
c19d1205 15046output_inst (const char * str)
b99bd4ef 15047{
c19d1205 15048 char * to = NULL;
b99bd4ef 15049
c19d1205 15050 if (inst.error)
b99bd4ef 15051 {
c19d1205 15052 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15053 return;
15054 }
5f4273c7
NC
15055 if (inst.relax)
15056 {
15057 output_relax_insn ();
0110f2b8 15058 return;
5f4273c7 15059 }
c19d1205
ZW
15060 if (inst.size == 0)
15061 return;
b99bd4ef 15062
c19d1205 15063 to = frag_more (inst.size);
8dc2430f
NC
15064 /* PR 9814: Record the thumb mode into the current frag so that we know
15065 what type of NOP padding to use, if necessary. We override any previous
15066 setting so that if the mode has changed then the NOPS that we use will
15067 match the encoding of the last instruction in the frag. */
cd000bff 15068 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15069
15070 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15071 {
9c2799c2 15072 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15073 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15074 }
c19d1205 15075 else if (inst.size > INSN_SIZE)
b99bd4ef 15076 {
9c2799c2 15077 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15078 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15079 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15080 }
c19d1205
ZW
15081 else
15082 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15083
c19d1205
ZW
15084 if (inst.reloc.type != BFD_RELOC_UNUSED)
15085 fix_new_arm (frag_now, to - frag_now->fr_literal,
15086 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15087 inst.reloc.type);
b99bd4ef 15088
c19d1205 15089 dwarf2_emit_insn (inst.size);
c19d1205 15090}
b99bd4ef 15091
e07e6e58
NC
15092static char *
15093output_it_inst (int cond, int mask, char * to)
15094{
15095 unsigned long instruction = 0xbf00;
15096
15097 mask &= 0xf;
15098 instruction |= mask;
15099 instruction |= cond << 4;
15100
15101 if (to == NULL)
15102 {
15103 to = frag_more (2);
15104#ifdef OBJ_ELF
15105 dwarf2_emit_insn (2);
15106#endif
15107 }
15108
15109 md_number_to_chars (to, instruction, 2);
15110
15111 return to;
15112}
15113
c19d1205
ZW
15114/* Tag values used in struct asm_opcode's tag field. */
15115enum opcode_tag
15116{
15117 OT_unconditional, /* Instruction cannot be conditionalized.
15118 The ARM condition field is still 0xE. */
15119 OT_unconditionalF, /* Instruction cannot be conditionalized
15120 and carries 0xF in its ARM condition field. */
15121 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15122 OT_csuffixF, /* Some forms of the instruction take a conditional
15123 suffix, others place 0xF where the condition field
15124 would be. */
c19d1205
ZW
15125 OT_cinfix3, /* Instruction takes a conditional infix,
15126 beginning at character index 3. (In
15127 unified mode, it becomes a suffix.) */
088fa78e
KH
15128 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15129 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15130 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15131 character index 3, even in unified mode. Used for
15132 legacy instructions where suffix and infix forms
15133 may be ambiguous. */
c19d1205 15134 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15135 suffix or an infix at character index 3. */
c19d1205
ZW
15136 OT_odd_infix_unc, /* This is the unconditional variant of an
15137 instruction that takes a conditional infix
15138 at an unusual position. In unified mode,
15139 this variant will accept a suffix. */
15140 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15141 are the conditional variants of instructions that
15142 take conditional infixes in unusual positions.
15143 The infix appears at character index
15144 (tag - OT_odd_infix_0). These are not accepted
15145 in unified mode. */
15146};
b99bd4ef 15147
c19d1205
ZW
15148/* Subroutine of md_assemble, responsible for looking up the primary
15149 opcode from the mnemonic the user wrote. STR points to the
15150 beginning of the mnemonic.
15151
15152 This is not simply a hash table lookup, because of conditional
15153 variants. Most instructions have conditional variants, which are
15154 expressed with a _conditional affix_ to the mnemonic. If we were
15155 to encode each conditional variant as a literal string in the opcode
15156 table, it would have approximately 20,000 entries.
15157
15158 Most mnemonics take this affix as a suffix, and in unified syntax,
15159 'most' is upgraded to 'all'. However, in the divided syntax, some
15160 instructions take the affix as an infix, notably the s-variants of
15161 the arithmetic instructions. Of those instructions, all but six
15162 have the infix appear after the third character of the mnemonic.
15163
15164 Accordingly, the algorithm for looking up primary opcodes given
15165 an identifier is:
15166
15167 1. Look up the identifier in the opcode table.
15168 If we find a match, go to step U.
15169
15170 2. Look up the last two characters of the identifier in the
15171 conditions table. If we find a match, look up the first N-2
15172 characters of the identifier in the opcode table. If we
15173 find a match, go to step CE.
15174
15175 3. Look up the fourth and fifth characters of the identifier in
15176 the conditions table. If we find a match, extract those
15177 characters from the identifier, and look up the remaining
15178 characters in the opcode table. If we find a match, go
15179 to step CM.
15180
15181 4. Fail.
15182
15183 U. Examine the tag field of the opcode structure, in case this is
15184 one of the six instructions with its conditional infix in an
15185 unusual place. If it is, the tag tells us where to find the
15186 infix; look it up in the conditions table and set inst.cond
15187 accordingly. Otherwise, this is an unconditional instruction.
15188 Again set inst.cond accordingly. Return the opcode structure.
15189
15190 CE. Examine the tag field to make sure this is an instruction that
15191 should receive a conditional suffix. If it is not, fail.
15192 Otherwise, set inst.cond from the suffix we already looked up,
15193 and return the opcode structure.
15194
15195 CM. Examine the tag field to make sure this is an instruction that
15196 should receive a conditional infix after the third character.
15197 If it is not, fail. Otherwise, undo the edits to the current
15198 line of input and proceed as for case CE. */
15199
15200static const struct asm_opcode *
15201opcode_lookup (char **str)
15202{
15203 char *end, *base;
15204 char *affix;
15205 const struct asm_opcode *opcode;
15206 const struct asm_cond *cond;
e3cb604e 15207 char save[2];
c19d1205
ZW
15208
15209 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15210 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15211 for (base = end = *str; *end != '\0'; end++)
721a8186 15212 if (*end == ' ' || *end == '.')
c19d1205 15213 break;
b99bd4ef 15214
c19d1205 15215 if (end == base)
c921be7d 15216 return NULL;
b99bd4ef 15217
5287ad62 15218 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15219 if (end[0] == '.')
b99bd4ef 15220 {
5287ad62 15221 int offset = 2;
5f4273c7 15222
267d2029
JB
15223 /* The .w and .n suffixes are only valid if the unified syntax is in
15224 use. */
15225 if (unified_syntax && end[1] == 'w')
c19d1205 15226 inst.size_req = 4;
267d2029 15227 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15228 inst.size_req = 2;
15229 else
5287ad62
JB
15230 offset = 0;
15231
15232 inst.vectype.elems = 0;
15233
15234 *str = end + offset;
b99bd4ef 15235
5f4273c7 15236 if (end[offset] == '.')
5287ad62 15237 {
267d2029
JB
15238 /* See if we have a Neon type suffix (possible in either unified or
15239 non-unified ARM syntax mode). */
dcbf9037 15240 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15241 return NULL;
5287ad62
JB
15242 }
15243 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15244 return NULL;
b99bd4ef 15245 }
c19d1205
ZW
15246 else
15247 *str = end;
b99bd4ef 15248
c19d1205 15249 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15250 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15251 end - base);
c19d1205 15252 if (opcode)
b99bd4ef 15253 {
c19d1205
ZW
15254 /* step U */
15255 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15256 {
c19d1205
ZW
15257 inst.cond = COND_ALWAYS;
15258 return opcode;
b99bd4ef 15259 }
b99bd4ef 15260
278df34e 15261 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15262 as_warn (_("conditional infixes are deprecated in unified syntax"));
15263 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15264 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15265 gas_assert (cond);
b99bd4ef 15266
c19d1205
ZW
15267 inst.cond = cond->value;
15268 return opcode;
15269 }
b99bd4ef 15270
c19d1205
ZW
15271 /* Cannot have a conditional suffix on a mnemonic of less than two
15272 characters. */
15273 if (end - base < 3)
c921be7d 15274 return NULL;
b99bd4ef 15275
c19d1205
ZW
15276 /* Look for suffixed mnemonic. */
15277 affix = end - 2;
21d799b5
NC
15278 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15279 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15280 affix - base);
c19d1205
ZW
15281 if (opcode && cond)
15282 {
15283 /* step CE */
15284 switch (opcode->tag)
15285 {
e3cb604e
PB
15286 case OT_cinfix3_legacy:
15287 /* Ignore conditional suffixes matched on infix only mnemonics. */
15288 break;
15289
c19d1205 15290 case OT_cinfix3:
088fa78e 15291 case OT_cinfix3_deprecated:
c19d1205
ZW
15292 case OT_odd_infix_unc:
15293 if (!unified_syntax)
e3cb604e 15294 return 0;
c19d1205
ZW
15295 /* else fall through */
15296
15297 case OT_csuffix:
037e8744 15298 case OT_csuffixF:
c19d1205
ZW
15299 case OT_csuf_or_in3:
15300 inst.cond = cond->value;
15301 return opcode;
15302
15303 case OT_unconditional:
15304 case OT_unconditionalF:
dfa9f0d5 15305 if (thumb_mode)
c921be7d 15306 inst.cond = cond->value;
dfa9f0d5
PB
15307 else
15308 {
c921be7d 15309 /* Delayed diagnostic. */
dfa9f0d5
PB
15310 inst.error = BAD_COND;
15311 inst.cond = COND_ALWAYS;
15312 }
c19d1205 15313 return opcode;
b99bd4ef 15314
c19d1205 15315 default:
c921be7d 15316 return NULL;
c19d1205
ZW
15317 }
15318 }
b99bd4ef 15319
c19d1205
ZW
15320 /* Cannot have a usual-position infix on a mnemonic of less than
15321 six characters (five would be a suffix). */
15322 if (end - base < 6)
c921be7d 15323 return NULL;
b99bd4ef 15324
c19d1205
ZW
15325 /* Look for infixed mnemonic in the usual position. */
15326 affix = base + 3;
21d799b5 15327 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15328 if (!cond)
c921be7d 15329 return NULL;
e3cb604e
PB
15330
15331 memcpy (save, affix, 2);
15332 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15333 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15334 (end - base) - 2);
e3cb604e
PB
15335 memmove (affix + 2, affix, (end - affix) - 2);
15336 memcpy (affix, save, 2);
15337
088fa78e
KH
15338 if (opcode
15339 && (opcode->tag == OT_cinfix3
15340 || opcode->tag == OT_cinfix3_deprecated
15341 || opcode->tag == OT_csuf_or_in3
15342 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15343 {
c921be7d 15344 /* Step CM. */
278df34e 15345 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15346 && (opcode->tag == OT_cinfix3
15347 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15348 as_warn (_("conditional infixes are deprecated in unified syntax"));
15349
15350 inst.cond = cond->value;
15351 return opcode;
b99bd4ef
NC
15352 }
15353
c921be7d 15354 return NULL;
b99bd4ef
NC
15355}
15356
e07e6e58
NC
15357/* This function generates an initial IT instruction, leaving its block
15358 virtually open for the new instructions. Eventually,
15359 the mask will be updated by now_it_add_mask () each time
15360 a new instruction needs to be included in the IT block.
15361 Finally, the block is closed with close_automatic_it_block ().
15362 The block closure can be requested either from md_assemble (),
15363 a tencode (), or due to a label hook. */
15364
15365static void
15366new_automatic_it_block (int cond)
15367{
15368 now_it.state = AUTOMATIC_IT_BLOCK;
15369 now_it.mask = 0x18;
15370 now_it.cc = cond;
15371 now_it.block_length = 1;
cd000bff 15372 mapping_state (MAP_THUMB);
e07e6e58
NC
15373 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15374}
15375
15376/* Close an automatic IT block.
15377 See comments in new_automatic_it_block (). */
15378
15379static void
15380close_automatic_it_block (void)
15381{
15382 now_it.mask = 0x10;
15383 now_it.block_length = 0;
15384}
15385
15386/* Update the mask of the current automatically-generated IT
15387 instruction. See comments in new_automatic_it_block (). */
15388
15389static void
15390now_it_add_mask (int cond)
15391{
15392#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15393#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15394 | ((bitvalue) << (nbit)))
e07e6e58 15395 const int resulting_bit = (cond & 1);
c921be7d 15396
e07e6e58
NC
15397 now_it.mask &= 0xf;
15398 now_it.mask = SET_BIT_VALUE (now_it.mask,
15399 resulting_bit,
15400 (5 - now_it.block_length));
15401 now_it.mask = SET_BIT_VALUE (now_it.mask,
15402 1,
15403 ((5 - now_it.block_length) - 1) );
15404 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15405
15406#undef CLEAR_BIT
15407#undef SET_BIT_VALUE
e07e6e58
NC
15408}
15409
15410/* The IT blocks handling machinery is accessed through the these functions:
15411 it_fsm_pre_encode () from md_assemble ()
15412 set_it_insn_type () optional, from the tencode functions
15413 set_it_insn_type_last () ditto
15414 in_it_block () ditto
15415 it_fsm_post_encode () from md_assemble ()
15416 force_automatic_it_block_close () from label habdling functions
15417
15418 Rationale:
15419 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15420 initializing the IT insn type with a generic initial value depending
15421 on the inst.condition.
15422 2) During the tencode function, two things may happen:
15423 a) The tencode function overrides the IT insn type by
15424 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15425 b) The tencode function queries the IT block state by
15426 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15427
15428 Both set_it_insn_type and in_it_block run the internal FSM state
15429 handling function (handle_it_state), because: a) setting the IT insn
15430 type may incur in an invalid state (exiting the function),
15431 and b) querying the state requires the FSM to be updated.
15432 Specifically we want to avoid creating an IT block for conditional
15433 branches, so it_fsm_pre_encode is actually a guess and we can't
15434 determine whether an IT block is required until the tencode () routine
15435 has decided what type of instruction this actually it.
15436 Because of this, if set_it_insn_type and in_it_block have to be used,
15437 set_it_insn_type has to be called first.
15438
15439 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15440 determines the insn IT type depending on the inst.cond code.
15441 When a tencode () routine encodes an instruction that can be
15442 either outside an IT block, or, in the case of being inside, has to be
15443 the last one, set_it_insn_type_last () will determine the proper
15444 IT instruction type based on the inst.cond code. Otherwise,
15445 set_it_insn_type can be called for overriding that logic or
15446 for covering other cases.
15447
15448 Calling handle_it_state () may not transition the IT block state to
15449 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15450 still queried. Instead, if the FSM determines that the state should
15451 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15452 after the tencode () function: that's what it_fsm_post_encode () does.
15453
15454 Since in_it_block () calls the state handling function to get an
15455 updated state, an error may occur (due to invalid insns combination).
15456 In that case, inst.error is set.
15457 Therefore, inst.error has to be checked after the execution of
15458 the tencode () routine.
15459
15460 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15461 any pending state change (if any) that didn't take place in
15462 handle_it_state () as explained above. */
15463
15464static void
15465it_fsm_pre_encode (void)
15466{
15467 if (inst.cond != COND_ALWAYS)
15468 inst.it_insn_type = INSIDE_IT_INSN;
15469 else
15470 inst.it_insn_type = OUTSIDE_IT_INSN;
15471
15472 now_it.state_handled = 0;
15473}
15474
15475/* IT state FSM handling function. */
15476
15477static int
15478handle_it_state (void)
15479{
15480 now_it.state_handled = 1;
15481
15482 switch (now_it.state)
15483 {
15484 case OUTSIDE_IT_BLOCK:
15485 switch (inst.it_insn_type)
15486 {
15487 case OUTSIDE_IT_INSN:
15488 break;
15489
15490 case INSIDE_IT_INSN:
15491 case INSIDE_IT_LAST_INSN:
15492 if (thumb_mode == 0)
15493 {
c921be7d 15494 if (unified_syntax
e07e6e58
NC
15495 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15496 as_tsktsk (_("Warning: conditional outside an IT block"\
15497 " for Thumb."));
15498 }
15499 else
15500 {
15501 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15502 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15503 {
15504 /* Automatically generate the IT instruction. */
15505 new_automatic_it_block (inst.cond);
15506 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15507 close_automatic_it_block ();
15508 }
15509 else
15510 {
15511 inst.error = BAD_OUT_IT;
15512 return FAIL;
15513 }
15514 }
15515 break;
15516
15517 case IF_INSIDE_IT_LAST_INSN:
15518 case NEUTRAL_IT_INSN:
15519 break;
15520
15521 case IT_INSN:
15522 now_it.state = MANUAL_IT_BLOCK;
15523 now_it.block_length = 0;
15524 break;
15525 }
15526 break;
15527
15528 case AUTOMATIC_IT_BLOCK:
15529 /* Three things may happen now:
15530 a) We should increment current it block size;
15531 b) We should close current it block (closing insn or 4 insns);
15532 c) We should close current it block and start a new one (due
15533 to incompatible conditions or
15534 4 insns-length block reached). */
15535
15536 switch (inst.it_insn_type)
15537 {
15538 case OUTSIDE_IT_INSN:
15539 /* The closure of the block shall happen immediatelly,
15540 so any in_it_block () call reports the block as closed. */
15541 force_automatic_it_block_close ();
15542 break;
15543
15544 case INSIDE_IT_INSN:
15545 case INSIDE_IT_LAST_INSN:
15546 case IF_INSIDE_IT_LAST_INSN:
15547 now_it.block_length++;
15548
15549 if (now_it.block_length > 4
15550 || !now_it_compatible (inst.cond))
15551 {
15552 force_automatic_it_block_close ();
15553 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15554 new_automatic_it_block (inst.cond);
15555 }
15556 else
15557 {
15558 now_it_add_mask (inst.cond);
15559 }
15560
15561 if (now_it.state == AUTOMATIC_IT_BLOCK
15562 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15563 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15564 close_automatic_it_block ();
15565 break;
15566
15567 case NEUTRAL_IT_INSN:
15568 now_it.block_length++;
15569
15570 if (now_it.block_length > 4)
15571 force_automatic_it_block_close ();
15572 else
15573 now_it_add_mask (now_it.cc & 1);
15574 break;
15575
15576 case IT_INSN:
15577 close_automatic_it_block ();
15578 now_it.state = MANUAL_IT_BLOCK;
15579 break;
15580 }
15581 break;
15582
15583 case MANUAL_IT_BLOCK:
15584 {
15585 /* Check conditional suffixes. */
15586 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15587 int is_last;
15588 now_it.mask <<= 1;
15589 now_it.mask &= 0x1f;
15590 is_last = (now_it.mask == 0x10);
15591
15592 switch (inst.it_insn_type)
15593 {
15594 case OUTSIDE_IT_INSN:
15595 inst.error = BAD_NOT_IT;
15596 return FAIL;
15597
15598 case INSIDE_IT_INSN:
15599 if (cond != inst.cond)
15600 {
15601 inst.error = BAD_IT_COND;
15602 return FAIL;
15603 }
15604 break;
15605
15606 case INSIDE_IT_LAST_INSN:
15607 case IF_INSIDE_IT_LAST_INSN:
15608 if (cond != inst.cond)
15609 {
15610 inst.error = BAD_IT_COND;
15611 return FAIL;
15612 }
15613 if (!is_last)
15614 {
15615 inst.error = BAD_BRANCH;
15616 return FAIL;
15617 }
15618 break;
15619
15620 case NEUTRAL_IT_INSN:
15621 /* The BKPT instruction is unconditional even in an IT block. */
15622 break;
15623
15624 case IT_INSN:
15625 inst.error = BAD_IT_IT;
15626 return FAIL;
15627 }
15628 }
15629 break;
15630 }
15631
15632 return SUCCESS;
15633}
15634
15635static void
15636it_fsm_post_encode (void)
15637{
15638 int is_last;
15639
15640 if (!now_it.state_handled)
15641 handle_it_state ();
15642
15643 is_last = (now_it.mask == 0x10);
15644 if (is_last)
15645 {
15646 now_it.state = OUTSIDE_IT_BLOCK;
15647 now_it.mask = 0;
15648 }
15649}
15650
15651static void
15652force_automatic_it_block_close (void)
15653{
15654 if (now_it.state == AUTOMATIC_IT_BLOCK)
15655 {
15656 close_automatic_it_block ();
15657 now_it.state = OUTSIDE_IT_BLOCK;
15658 now_it.mask = 0;
15659 }
15660}
15661
15662static int
15663in_it_block (void)
15664{
15665 if (!now_it.state_handled)
15666 handle_it_state ();
15667
15668 return now_it.state != OUTSIDE_IT_BLOCK;
15669}
15670
c19d1205
ZW
15671void
15672md_assemble (char *str)
b99bd4ef 15673{
c19d1205
ZW
15674 char *p = str;
15675 const struct asm_opcode * opcode;
b99bd4ef 15676
c19d1205
ZW
15677 /* Align the previous label if needed. */
15678 if (last_label_seen != NULL)
b99bd4ef 15679 {
c19d1205
ZW
15680 symbol_set_frag (last_label_seen, frag_now);
15681 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15682 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15683 }
15684
c19d1205
ZW
15685 memset (&inst, '\0', sizeof (inst));
15686 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15687
c19d1205
ZW
15688 opcode = opcode_lookup (&p);
15689 if (!opcode)
b99bd4ef 15690 {
c19d1205 15691 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15692 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15693 if (! create_register_alias (str, p)
15694 && ! create_neon_reg_alias (str, p))
c19d1205 15695 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15696
b99bd4ef
NC
15697 return;
15698 }
15699
278df34e 15700 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15701 as_warn (_("s suffix on comparison instruction is deprecated"));
15702
037e8744
JB
15703 /* The value which unconditional instructions should have in place of the
15704 condition field. */
15705 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15706
c19d1205 15707 if (thumb_mode)
b99bd4ef 15708 {
e74cfd16 15709 arm_feature_set variant;
8f06b2d8
PB
15710
15711 variant = cpu_variant;
15712 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15713 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15714 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15715 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15716 if (!opcode->tvariant
15717 || (thumb_mode == 1
15718 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15719 {
bf3eeda7 15720 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
15721 return;
15722 }
c19d1205
ZW
15723 if (inst.cond != COND_ALWAYS && !unified_syntax
15724 && opcode->tencode != do_t_branch)
b99bd4ef 15725 {
c19d1205 15726 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15727 return;
15728 }
15729
752d5da4 15730 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15731 {
7e806470 15732 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15733 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15734 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15735 {
15736 /* Two things are addressed here.
15737 1) Implicit require narrow instructions on Thumb-1.
15738 This avoids relaxation accidentally introducing Thumb-2
15739 instructions.
15740 2) Reject wide instructions in non Thumb-2 cores. */
15741 if (inst.size_req == 0)
15742 inst.size_req = 2;
15743 else if (inst.size_req == 4)
15744 {
bf3eeda7 15745 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
15746 return;
15747 }
15748 }
076d447c
PB
15749 }
15750
c19d1205
ZW
15751 inst.instruction = opcode->tvalue;
15752
5be8be5d 15753 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
15754 {
15755 /* Prepare the it_insn_type for those encodings that don't set
15756 it. */
15757 it_fsm_pre_encode ();
c19d1205 15758
e07e6e58
NC
15759 opcode->tencode ();
15760
15761 it_fsm_post_encode ();
15762 }
e27ec89e 15763
0110f2b8 15764 if (!(inst.error || inst.relax))
b99bd4ef 15765 {
9c2799c2 15766 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15767 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15768 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15769 {
c19d1205 15770 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15771 return;
15772 }
15773 }
076d447c
PB
15774
15775 /* Something has gone badly wrong if we try to relax a fixed size
15776 instruction. */
9c2799c2 15777 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15778
e74cfd16
PB
15779 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15780 *opcode->tvariant);
ee065d83 15781 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15782 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15783 anything other than bl/blx and v6-M instructions.
ee065d83 15784 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15785 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15786 || inst.relax)
e07e6e58
NC
15787 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15788 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15789 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15790 arm_ext_v6t2);
cd000bff 15791
88714cb8
DG
15792 check_neon_suffixes;
15793
cd000bff 15794 if (!inst.error)
c877a2f2
NC
15795 {
15796 mapping_state (MAP_THUMB);
15797 }
c19d1205 15798 }
3e9e4fcf 15799 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15800 {
845b51d6
PB
15801 bfd_boolean is_bx;
15802
15803 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15804 is_bx = (opcode->aencode == do_bx);
15805
c19d1205 15806 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15807 if (!(is_bx && fix_v4bx)
15808 && !(opcode->avariant &&
15809 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15810 {
bf3eeda7 15811 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 15812 return;
b99bd4ef 15813 }
c19d1205 15814 if (inst.size_req)
b99bd4ef 15815 {
c19d1205
ZW
15816 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15817 return;
b99bd4ef
NC
15818 }
15819
c19d1205
ZW
15820 inst.instruction = opcode->avalue;
15821 if (opcode->tag == OT_unconditionalF)
15822 inst.instruction |= 0xF << 28;
15823 else
15824 inst.instruction |= inst.cond << 28;
15825 inst.size = INSN_SIZE;
5be8be5d 15826 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
15827 {
15828 it_fsm_pre_encode ();
15829 opcode->aencode ();
15830 it_fsm_post_encode ();
15831 }
ee065d83
PB
15832 /* Arm mode bx is marked as both v4T and v5 because it's still required
15833 on a hypothetical non-thumb v5 core. */
845b51d6 15834 if (is_bx)
e74cfd16 15835 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15836 else
e74cfd16
PB
15837 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15838 *opcode->avariant);
88714cb8
DG
15839
15840 check_neon_suffixes;
15841
cd000bff 15842 if (!inst.error)
c877a2f2
NC
15843 {
15844 mapping_state (MAP_ARM);
15845 }
b99bd4ef 15846 }
3e9e4fcf
JB
15847 else
15848 {
15849 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15850 "-- `%s'"), str);
15851 return;
15852 }
c19d1205
ZW
15853 output_inst (str);
15854}
b99bd4ef 15855
e07e6e58
NC
15856static void
15857check_it_blocks_finished (void)
15858{
15859#ifdef OBJ_ELF
15860 asection *sect;
15861
15862 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15863 if (seg_info (sect)->tc_segment_info_data.current_it.state
15864 == MANUAL_IT_BLOCK)
15865 {
15866 as_warn (_("section '%s' finished with an open IT block."),
15867 sect->name);
15868 }
15869#else
15870 if (now_it.state == MANUAL_IT_BLOCK)
15871 as_warn (_("file finished with an open IT block."));
15872#endif
15873}
15874
c19d1205
ZW
15875/* Various frobbings of labels and their addresses. */
15876
15877void
15878arm_start_line_hook (void)
15879{
15880 last_label_seen = NULL;
b99bd4ef
NC
15881}
15882
c19d1205
ZW
15883void
15884arm_frob_label (symbolS * sym)
b99bd4ef 15885{
c19d1205 15886 last_label_seen = sym;
b99bd4ef 15887
c19d1205 15888 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15889
c19d1205
ZW
15890#if defined OBJ_COFF || defined OBJ_ELF
15891 ARM_SET_INTERWORK (sym, support_interwork);
15892#endif
b99bd4ef 15893
e07e6e58
NC
15894 force_automatic_it_block_close ();
15895
5f4273c7 15896 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15897 as Thumb functions. This is because these labels, whilst
15898 they exist inside Thumb code, are not the entry points for
15899 possible ARM->Thumb calls. Also, these labels can be used
15900 as part of a computed goto or switch statement. eg gcc
15901 can generate code that looks like this:
b99bd4ef 15902
c19d1205
ZW
15903 ldr r2, [pc, .Laaa]
15904 lsl r3, r3, #2
15905 ldr r2, [r3, r2]
15906 mov pc, r2
b99bd4ef 15907
c19d1205
ZW
15908 .Lbbb: .word .Lxxx
15909 .Lccc: .word .Lyyy
15910 ..etc...
15911 .Laaa: .word Lbbb
b99bd4ef 15912
c19d1205
ZW
15913 The first instruction loads the address of the jump table.
15914 The second instruction converts a table index into a byte offset.
15915 The third instruction gets the jump address out of the table.
15916 The fourth instruction performs the jump.
b99bd4ef 15917
c19d1205
ZW
15918 If the address stored at .Laaa is that of a symbol which has the
15919 Thumb_Func bit set, then the linker will arrange for this address
15920 to have the bottom bit set, which in turn would mean that the
15921 address computation performed by the third instruction would end
15922 up with the bottom bit set. Since the ARM is capable of unaligned
15923 word loads, the instruction would then load the incorrect address
15924 out of the jump table, and chaos would ensue. */
15925 if (label_is_thumb_function_name
15926 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15927 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15928 {
c19d1205
ZW
15929 /* When the address of a Thumb function is taken the bottom
15930 bit of that address should be set. This will allow
15931 interworking between Arm and Thumb functions to work
15932 correctly. */
b99bd4ef 15933
c19d1205 15934 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15935
c19d1205 15936 label_is_thumb_function_name = FALSE;
b99bd4ef 15937 }
07a53e5c 15938
07a53e5c 15939 dwarf2_emit_label (sym);
b99bd4ef
NC
15940}
15941
c921be7d 15942bfd_boolean
c19d1205 15943arm_data_in_code (void)
b99bd4ef 15944{
c19d1205 15945 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15946 {
c19d1205
ZW
15947 *input_line_pointer = '/';
15948 input_line_pointer += 5;
15949 *input_line_pointer = 0;
c921be7d 15950 return TRUE;
b99bd4ef
NC
15951 }
15952
c921be7d 15953 return FALSE;
b99bd4ef
NC
15954}
15955
c19d1205
ZW
15956char *
15957arm_canonicalize_symbol_name (char * name)
b99bd4ef 15958{
c19d1205 15959 int len;
b99bd4ef 15960
c19d1205
ZW
15961 if (thumb_mode && (len = strlen (name)) > 5
15962 && streq (name + len - 5, "/data"))
15963 *(name + len - 5) = 0;
b99bd4ef 15964
c19d1205 15965 return name;
b99bd4ef 15966}
c19d1205
ZW
15967\f
15968/* Table of all register names defined by default. The user can
15969 define additional names with .req. Note that all register names
15970 should appear in both upper and lowercase variants. Some registers
15971 also have mixed-case names. */
b99bd4ef 15972
dcbf9037 15973#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15974#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15975#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15976#define REGSET(p,t) \
15977 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15978 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15979 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15980 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15981#define REGSETH(p,t) \
15982 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15983 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15984 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15985 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15986#define REGSET2(p,t) \
15987 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15988 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15989 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15990 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15991
c19d1205 15992static const struct reg_entry reg_names[] =
7ed4c4c5 15993{
c19d1205
ZW
15994 /* ARM integer registers. */
15995 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15996
c19d1205
ZW
15997 /* ATPCS synonyms. */
15998 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15999 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16000 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16001
c19d1205
ZW
16002 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16003 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16004 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16005
c19d1205
ZW
16006 /* Well-known aliases. */
16007 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16008 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16009
16010 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16011 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16012
16013 /* Coprocessor numbers. */
16014 REGSET(p, CP), REGSET(P, CP),
16015
16016 /* Coprocessor register numbers. The "cr" variants are for backward
16017 compatibility. */
16018 REGSET(c, CN), REGSET(C, CN),
16019 REGSET(cr, CN), REGSET(CR, CN),
16020
16021 /* FPA registers. */
16022 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16023 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16024
16025 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16026 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16027
16028 /* VFP SP registers. */
5287ad62
JB
16029 REGSET(s,VFS), REGSET(S,VFS),
16030 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16031
16032 /* VFP DP Registers. */
5287ad62
JB
16033 REGSET(d,VFD), REGSET(D,VFD),
16034 /* Extra Neon DP registers. */
16035 REGSETH(d,VFD), REGSETH(D,VFD),
16036
16037 /* Neon QP registers. */
16038 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16039
16040 /* VFP control registers. */
16041 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16042 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16043 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16044 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16045 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16046 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16047
16048 /* Maverick DSP coprocessor registers. */
16049 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16050 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16051
16052 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16053 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16054 REGDEF(dspsc,0,DSPSC),
16055
16056 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16057 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16058 REGDEF(DSPSC,0,DSPSC),
16059
16060 /* iWMMXt data registers - p0, c0-15. */
16061 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16062
16063 /* iWMMXt control registers - p1, c0-3. */
16064 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16065 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16066 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16067 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16068
16069 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16070 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16071 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16072 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16073 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16074
16075 /* XScale accumulator registers. */
16076 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16077};
16078#undef REGDEF
16079#undef REGNUM
16080#undef REGSET
7ed4c4c5 16081
c19d1205
ZW
16082/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16083 within psr_required_here. */
16084static const struct asm_psr psrs[] =
16085{
16086 /* Backward compatibility notation. Note that "all" is no longer
16087 truly all possible PSR bits. */
16088 {"all", PSR_c | PSR_f},
16089 {"flg", PSR_f},
16090 {"ctl", PSR_c},
16091
16092 /* Individual flags. */
16093 {"f", PSR_f},
16094 {"c", PSR_c},
16095 {"x", PSR_x},
16096 {"s", PSR_s},
16097 /* Combinations of flags. */
16098 {"fs", PSR_f | PSR_s},
16099 {"fx", PSR_f | PSR_x},
16100 {"fc", PSR_f | PSR_c},
16101 {"sf", PSR_s | PSR_f},
16102 {"sx", PSR_s | PSR_x},
16103 {"sc", PSR_s | PSR_c},
16104 {"xf", PSR_x | PSR_f},
16105 {"xs", PSR_x | PSR_s},
16106 {"xc", PSR_x | PSR_c},
16107 {"cf", PSR_c | PSR_f},
16108 {"cs", PSR_c | PSR_s},
16109 {"cx", PSR_c | PSR_x},
16110 {"fsx", PSR_f | PSR_s | PSR_x},
16111 {"fsc", PSR_f | PSR_s | PSR_c},
16112 {"fxs", PSR_f | PSR_x | PSR_s},
16113 {"fxc", PSR_f | PSR_x | PSR_c},
16114 {"fcs", PSR_f | PSR_c | PSR_s},
16115 {"fcx", PSR_f | PSR_c | PSR_x},
16116 {"sfx", PSR_s | PSR_f | PSR_x},
16117 {"sfc", PSR_s | PSR_f | PSR_c},
16118 {"sxf", PSR_s | PSR_x | PSR_f},
16119 {"sxc", PSR_s | PSR_x | PSR_c},
16120 {"scf", PSR_s | PSR_c | PSR_f},
16121 {"scx", PSR_s | PSR_c | PSR_x},
16122 {"xfs", PSR_x | PSR_f | PSR_s},
16123 {"xfc", PSR_x | PSR_f | PSR_c},
16124 {"xsf", PSR_x | PSR_s | PSR_f},
16125 {"xsc", PSR_x | PSR_s | PSR_c},
16126 {"xcf", PSR_x | PSR_c | PSR_f},
16127 {"xcs", PSR_x | PSR_c | PSR_s},
16128 {"cfs", PSR_c | PSR_f | PSR_s},
16129 {"cfx", PSR_c | PSR_f | PSR_x},
16130 {"csf", PSR_c | PSR_s | PSR_f},
16131 {"csx", PSR_c | PSR_s | PSR_x},
16132 {"cxf", PSR_c | PSR_x | PSR_f},
16133 {"cxs", PSR_c | PSR_x | PSR_s},
16134 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16135 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16136 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16137 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16138 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16139 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16140 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16141 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16142 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16143 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16144 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16145 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16146 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16147 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16148 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16149 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16150 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16151 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16152 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16153 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16154 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16155 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16156 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16157 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16158};
16159
62b3e311
PB
16160/* Table of V7M psr names. */
16161static const struct asm_psr v7m_psrs[] =
16162{
2b744c99
PB
16163 {"apsr", 0 }, {"APSR", 0 },
16164 {"iapsr", 1 }, {"IAPSR", 1 },
16165 {"eapsr", 2 }, {"EAPSR", 2 },
16166 {"psr", 3 }, {"PSR", 3 },
16167 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16168 {"ipsr", 5 }, {"IPSR", 5 },
16169 {"epsr", 6 }, {"EPSR", 6 },
16170 {"iepsr", 7 }, {"IEPSR", 7 },
16171 {"msp", 8 }, {"MSP", 8 },
16172 {"psp", 9 }, {"PSP", 9 },
16173 {"primask", 16}, {"PRIMASK", 16},
16174 {"basepri", 17}, {"BASEPRI", 17},
16175 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16176 {"faultmask", 19}, {"FAULTMASK", 19},
16177 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16178};
16179
c19d1205
ZW
16180/* Table of all shift-in-operand names. */
16181static const struct asm_shift_name shift_names [] =
b99bd4ef 16182{
c19d1205
ZW
16183 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16184 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16185 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16186 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16187 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16188 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16189};
b99bd4ef 16190
c19d1205
ZW
16191/* Table of all explicit relocation names. */
16192#ifdef OBJ_ELF
16193static struct reloc_entry reloc_names[] =
16194{
16195 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16196 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16197 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16198 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16199 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16200 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16201 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16202 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16203 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16204 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6
NC
16205 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16206 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
c19d1205
ZW
16207};
16208#endif
b99bd4ef 16209
c19d1205
ZW
16210/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16211static const struct asm_cond conds[] =
16212{
16213 {"eq", 0x0},
16214 {"ne", 0x1},
16215 {"cs", 0x2}, {"hs", 0x2},
16216 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16217 {"mi", 0x4},
16218 {"pl", 0x5},
16219 {"vs", 0x6},
16220 {"vc", 0x7},
16221 {"hi", 0x8},
16222 {"ls", 0x9},
16223 {"ge", 0xa},
16224 {"lt", 0xb},
16225 {"gt", 0xc},
16226 {"le", 0xd},
16227 {"al", 0xe}
16228};
bfae80f2 16229
62b3e311
PB
16230static struct asm_barrier_opt barrier_opt_names[] =
16231{
16232 { "sy", 0xf },
16233 { "un", 0x7 },
16234 { "st", 0xe },
16235 { "unst", 0x6 }
16236};
16237
c19d1205
ZW
16238/* Table of ARM-format instructions. */
16239
16240/* Macros for gluing together operand strings. N.B. In all cases
16241 other than OPS0, the trailing OP_stop comes from default
16242 zero-initialization of the unspecified elements of the array. */
16243#define OPS0() { OP_stop, }
16244#define OPS1(a) { OP_##a, }
16245#define OPS2(a,b) { OP_##a,OP_##b, }
16246#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16247#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16248#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16249#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16250
5be8be5d
DG
16251/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16252 This is useful when mixing operands for ARM and THUMB, i.e. using the
16253 MIX_ARM_THUMB_OPERANDS macro.
16254 In order to use these macros, prefix the number of operands with _
16255 e.g. _3. */
16256#define OPS_1(a) { a, }
16257#define OPS_2(a,b) { a,b, }
16258#define OPS_3(a,b,c) { a,b,c, }
16259#define OPS_4(a,b,c,d) { a,b,c,d, }
16260#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16261#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16262
c19d1205
ZW
16263/* These macros abstract out the exact format of the mnemonic table and
16264 save some repeated characters. */
16265
16266/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16267#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16268 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16269 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16270
16271/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16272 a T_MNEM_xyz enumerator. */
16273#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16274 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16275#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16276 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16277
16278/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16279 infix after the third character. */
16280#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16281 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16282 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16283#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16284 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16285 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16286#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16287 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16288#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16289 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16290#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16291 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16292#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16293 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16294
16295/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16296 appear in the condition table. */
16297#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16298 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16299 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16300
16301#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16302 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16303 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16304 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16305 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16306 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16307 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16308 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16309 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16310 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16311 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16312 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16313 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16314 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16315 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16316 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16317 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16318 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16319 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16320 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16321
16322#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16323 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16324#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16325 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16326
16327/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16328 field is still 0xE. Many of the Thumb variants can be executed
16329 conditionally, so this is checked separately. */
c19d1205 16330#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16331 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16332 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16333
16334/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16335 condition code field. */
16336#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16337 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16338 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16339
16340/* ARM-only variants of all the above. */
6a86118a 16341#define CE(mnem, op, nops, ops, ae) \
21d799b5 16342 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16343
16344#define C3(mnem, op, nops, ops, ae) \
16345 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16346
e3cb604e
PB
16347/* Legacy mnemonics that always have conditional infix after the third
16348 character. */
16349#define CL(mnem, op, nops, ops, ae) \
21d799b5 16350 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16351 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16352
8f06b2d8
PB
16353/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16354#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16355 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16356
e3cb604e
PB
16357/* Legacy coprocessor instructions where conditional infix and conditional
16358 suffix are ambiguous. For consistency this includes all FPA instructions,
16359 not just the potentially ambiguous ones. */
16360#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16361 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16362 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16363
16364/* Coprocessor, takes either a suffix or a position-3 infix
16365 (for an FPA corner case). */
16366#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16367 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16368 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16369
6a86118a 16370#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16371 { m1 #m2 m3, OPS##nops ops, \
16372 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16373 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16374
16375#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16376 xCM_ (m1, , m2, op, nops, ops, ae), \
16377 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16378 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16379 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16380 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16381 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16382 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16383 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16384 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16385 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16386 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16387 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16388 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16389 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16390 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16391 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16392 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16393 xCM_ (m1, le, m2, op, nops, ops, ae), \
16394 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16395
16396#define UE(mnem, op, nops, ops, ae) \
16397 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16398
16399#define UF(mnem, op, nops, ops, ae) \
16400 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16401
5287ad62
JB
16402/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16403 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16404 use the same encoding function for each. */
16405#define NUF(mnem, op, nops, ops, enc) \
16406 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16407 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16408
16409/* Neon data processing, version which indirects through neon_enc_tab for
16410 the various overloaded versions of opcodes. */
16411#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16412 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16413 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16414
16415/* Neon insn with conditional suffix for the ARM version, non-overloaded
16416 version. */
037e8744
JB
16417#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16418 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16419 THUMB_VARIANT, do_##enc, do_##enc }
16420
037e8744 16421#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16422 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16423
16424#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16425 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16426
5287ad62 16427/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16428#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16429 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16430 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16431
037e8744 16432#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16433 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16434
16435#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16436 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16437
c19d1205
ZW
16438#define do_0 0
16439
c19d1205 16440static const struct asm_opcode insns[] =
bfae80f2 16441{
e74cfd16
PB
16442#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16443#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16444 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16445 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16446 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16447 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16448 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16449 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16450 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16451 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16452 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16453 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16454 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16455 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16456 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16457 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16458 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16459 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16460
16461 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16462 for setting PSR flag bits. They are obsolete in V6 and do not
16463 have Thumb equivalents. */
21d799b5
NC
16464 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16465 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16466 CL("tstp", 110f000, 2, (RR, SH), cmp),
16467 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16468 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16469 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16470 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16471 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16472 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16473
16474 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16475 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16476 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16477 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16478
16479 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16480 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16481 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16482 OP_RRnpc),
16483 OP_ADDRGLDR),ldst, t_ldst),
16484 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16485
16486 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16487 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16488 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16489 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16490 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16491 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16492
16493 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16494 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16495 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16496 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16497
c19d1205 16498 /* Pseudo ops. */
21d799b5 16499 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16500 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16501 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16502
16503 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16504 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16505 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16506 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16507 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16508 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16509 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16510 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16511 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16512 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16513 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16514 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16515 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16516
16a4cf17 16517 /* These may simplify to neg. */
21d799b5
NC
16518 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16519 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16520
c921be7d
NC
16521#undef THUMB_VARIANT
16522#define THUMB_VARIANT & arm_ext_v6
16523
21d799b5 16524 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16525
16526 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16527#undef THUMB_VARIANT
16528#define THUMB_VARIANT & arm_ext_v6t2
16529
21d799b5
NC
16530 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16531 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16532 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16533
5be8be5d
DG
16534 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16535 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16536 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16537 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16538
21d799b5
NC
16539 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16540 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16541
21d799b5
NC
16542 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16543 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16544
16545 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16546 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16547 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16548
16549 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16550 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16551 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16552 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16553 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16554 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16555 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16556 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16557
c921be7d
NC
16558#undef ARM_VARIANT
16559#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16560#undef THUMB_VARIANT
16561#define THUMB_VARIANT & arm_ext_v4t
16562
21d799b5
NC
16563 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16564 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16565
c921be7d
NC
16566#undef THUMB_VARIANT
16567#define THUMB_VARIANT & arm_ext_v6t2
16568
21d799b5 16569 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16570 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16571
16572 /* Generic coprocessor instructions. */
21d799b5
NC
16573 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16574 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16575 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16576 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16577 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16578 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16579 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16580
c921be7d
NC
16581#undef ARM_VARIANT
16582#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16583
21d799b5 16584 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16585 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16586
c921be7d
NC
16587#undef ARM_VARIANT
16588#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16589#undef THUMB_VARIANT
16590#define THUMB_VARIANT & arm_ext_msr
16591
21d799b5
NC
16592 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16593 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16594
c921be7d
NC
16595#undef ARM_VARIANT
16596#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16597#undef THUMB_VARIANT
16598#define THUMB_VARIANT & arm_ext_v6t2
16599
21d799b5
NC
16600 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16601 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16602 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16603 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16604 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16605 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16606 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16607 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16608
c921be7d
NC
16609#undef ARM_VARIANT
16610#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16611#undef THUMB_VARIANT
16612#define THUMB_VARIANT & arm_ext_v4t
16613
5be8be5d
DG
16614 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16615 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16616 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16617 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16618 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16619 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16620
c921be7d
NC
16621#undef ARM_VARIANT
16622#define ARM_VARIANT & arm_ext_v4t_5
16623
c19d1205
ZW
16624 /* ARM Architecture 4T. */
16625 /* Note: bx (and blx) are required on V5, even if the processor does
16626 not support Thumb. */
21d799b5 16627 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16628
c921be7d
NC
16629#undef ARM_VARIANT
16630#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16631#undef THUMB_VARIANT
16632#define THUMB_VARIANT & arm_ext_v5t
16633
c19d1205
ZW
16634 /* Note: blx has 2 variants; the .value coded here is for
16635 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16636 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16637 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16638
c921be7d
NC
16639#undef THUMB_VARIANT
16640#define THUMB_VARIANT & arm_ext_v6t2
16641
21d799b5
NC
16642 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16643 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16644 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16645 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16646 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16647 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16648 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16649 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16650
c921be7d
NC
16651#undef ARM_VARIANT
16652#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16653#undef THUMB_VARIANT
16654#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16655
21d799b5
NC
16656 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16657 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16658 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16659 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16660
21d799b5
NC
16661 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16662 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16663
21d799b5
NC
16664 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16665 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16666 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16667 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16668
21d799b5
NC
16669 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16670 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16671 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16672 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16673
21d799b5
NC
16674 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16675 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16676
03ee1b7f
NC
16677 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16678 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16679 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16680 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16681
c921be7d
NC
16682#undef ARM_VARIANT
16683#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16684#undef THUMB_VARIANT
16685#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16686
21d799b5 16687 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
16688 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16689 ldrd, t_ldstd),
16690 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16691 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16692
21d799b5
NC
16693 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16694 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16695
c921be7d
NC
16696#undef ARM_VARIANT
16697#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16698
21d799b5 16699 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16700
c921be7d
NC
16701#undef ARM_VARIANT
16702#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16703#undef THUMB_VARIANT
16704#define THUMB_VARIANT & arm_ext_v6
16705
21d799b5
NC
16706 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16707 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16708 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16709 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16710 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16711 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16712 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16713 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16714 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16715 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16716
c921be7d
NC
16717#undef THUMB_VARIANT
16718#define THUMB_VARIANT & arm_ext_v6t2
16719
5be8be5d
DG
16720 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16721 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16722 strex, t_strex),
21d799b5
NC
16723 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16724 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16725
21d799b5
NC
16726 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16727 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16728
9e3c6df6 16729/* ARM V6 not included in V7M. */
c921be7d
NC
16730#undef THUMB_VARIANT
16731#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16732 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16733 UF(rfeib, 9900a00, 1, (RRw), rfe),
16734 UF(rfeda, 8100a00, 1, (RRw), rfe),
16735 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16736 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16737 UF(rfefa, 9900a00, 1, (RRw), rfe),
16738 UF(rfeea, 8100a00, 1, (RRw), rfe),
16739 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16740 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16741 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16742 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16743 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16744
9e3c6df6
PB
16745/* ARM V6 not included in V7M (eg. integer SIMD). */
16746#undef THUMB_VARIANT
16747#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16748 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16749 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16750 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16751 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16752 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16753 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16754 /* Old name for QASX. */
21d799b5
NC
16755 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16756 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16757 /* Old name for QSAX. */
21d799b5
NC
16758 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16759 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16760 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16761 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16762 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16763 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16764 /* Old name for SASX. */
21d799b5
NC
16765 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16766 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16767 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16768 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16769 /* Old name for SHASX. */
21d799b5
NC
16770 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16771 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16772 /* Old name for SHSAX. */
21d799b5
NC
16773 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16774 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16775 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16776 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16777 /* Old name for SSAX. */
21d799b5
NC
16778 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16779 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16780 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16781 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16782 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16783 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16784 /* Old name for UASX. */
21d799b5
NC
16785 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16786 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16787 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16788 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16789 /* Old name for UHASX. */
21d799b5
NC
16790 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16791 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16792 /* Old name for UHSAX. */
21d799b5
NC
16793 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16794 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16795 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16796 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16797 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16798 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16799 /* Old name for UQASX. */
21d799b5
NC
16800 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16801 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16802 /* Old name for UQSAX. */
21d799b5
NC
16803 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16804 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16805 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16806 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16807 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16808 /* Old name for USAX. */
21d799b5
NC
16809 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16810 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16811 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16812 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16813 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16814 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16815 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16816 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16817 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16818 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16819 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16820 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16821 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16822 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16823 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16824 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16825 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16826 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16827 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16828 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16829 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16830 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16831 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16832 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16833 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16834 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16835 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16836 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16837 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
16838 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16839 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16840 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16841 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16842 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 16843
c921be7d
NC
16844#undef ARM_VARIANT
16845#define ARM_VARIANT & arm_ext_v6k
16846#undef THUMB_VARIANT
16847#define THUMB_VARIANT & arm_ext_v6k
16848
21d799b5
NC
16849 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16850 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16851 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16852 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 16853
c921be7d
NC
16854#undef THUMB_VARIANT
16855#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
16856 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16857 ldrexd, t_ldrexd),
16858 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16859 RRnpcb), strexd, t_strexd),
ebdca51a 16860
c921be7d
NC
16861#undef THUMB_VARIANT
16862#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
16863 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16864 rd_rn, rd_rn),
16865 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16866 rd_rn, rd_rn),
16867 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16868 strex, rm_rd_rn),
16869 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16870 strex, rm_rd_rn),
21d799b5 16871 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 16872
c921be7d
NC
16873#undef ARM_VARIANT
16874#define ARM_VARIANT & arm_ext_v6z
16875
21d799b5 16876 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 16877
c921be7d
NC
16878#undef ARM_VARIANT
16879#define ARM_VARIANT & arm_ext_v6t2
16880
21d799b5
NC
16881 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16882 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16883 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16884 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 16885
21d799b5
NC
16886 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16887 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16888 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16889 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 16890
5be8be5d
DG
16891 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16892 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16893 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16894 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 16895
bf3eeda7
NS
16896 /* Thumb-only instructions. */
16897#undef ARM_VARIANT
16898#define ARM_VARIANT NULL
16899 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
16900 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
16901
16902 /* ARM does not really have an IT instruction, so always allow it.
16903 The opcode is copied from Thumb in order to allow warnings in
16904 -mimplicit-it=[never | arm] modes. */
16905#undef ARM_VARIANT
16906#define ARM_VARIANT & arm_ext_v1
16907
21d799b5
NC
16908 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16909 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16910 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16911 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16912 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16913 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16914 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16915 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16916 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16917 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16918 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16919 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16920 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16921 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16922 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 16923 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
16924 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16925 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16926
92e90b6e 16927 /* Thumb2 only instructions. */
c921be7d
NC
16928#undef ARM_VARIANT
16929#define ARM_VARIANT NULL
92e90b6e 16930
21d799b5
NC
16931 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16932 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16933 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16934 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16935 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16936 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 16937
62b3e311 16938 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
16939#undef THUMB_VARIANT
16940#define THUMB_VARIANT & arm_ext_div
16941
21d799b5
NC
16942 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16943 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 16944
7e806470 16945 /* ARM V6M/V7 instructions. */
c921be7d
NC
16946#undef ARM_VARIANT
16947#define ARM_VARIANT & arm_ext_barrier
16948#undef THUMB_VARIANT
16949#define THUMB_VARIANT & arm_ext_barrier
16950
21d799b5
NC
16951 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16952 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16953 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
7e806470 16954
62b3e311 16955 /* ARM V7 instructions. */
c921be7d
NC
16956#undef ARM_VARIANT
16957#define ARM_VARIANT & arm_ext_v7
16958#undef THUMB_VARIANT
16959#define THUMB_VARIANT & arm_ext_v7
16960
21d799b5
NC
16961 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16962 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16963
c921be7d
NC
16964#undef ARM_VARIANT
16965#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16966
21d799b5
NC
16967 cCE("wfs", e200110, 1, (RR), rd),
16968 cCE("rfs", e300110, 1, (RR), rd),
16969 cCE("wfc", e400110, 1, (RR), rd),
16970 cCE("rfc", e500110, 1, (RR), rd),
16971
16972 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16973 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16974 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16975 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16976
16977 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16978 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16979 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16980 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16981
16982 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16983 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16984 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16985 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16986 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16987 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16988 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16989 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16990 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16991 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16992 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16993 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16994
16995 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16996 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16997 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16998 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16999 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17000 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17001 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17002 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17003 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17004 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17005 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17006 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17007
17008 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17009 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17010 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17011 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17012 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17013 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17014 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17015 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17016 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17017 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17018 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17019 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17020
17021 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17022 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17023 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17024 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17025 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17026 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17027 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17028 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17029 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17030 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17031 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17032 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17033
17034 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17035 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17036 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17037 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17038 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17039 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17040 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17041 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17042 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17043 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17044 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17045 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17046
17047 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17048 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17049 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17050 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17051 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17052 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17053 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17054 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17055 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17056 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17057 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17058 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17059
17060 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17061 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17062 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17063 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17064 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17065 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17066 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17067 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17068 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17069 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17070 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17071 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17072
17073 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17074 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17075 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17076 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17077 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17078 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17079 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17080 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17081 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17082 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17083 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17084 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17085
17086 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17087 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17088 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17089 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17090 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17091 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17092 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17093 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17094 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17095 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17096 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17097 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17098
17099 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17100 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17101 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17102 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17103 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17104 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17105 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17106 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17107 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17108 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17109 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17110 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17111
17112 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17113 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17114 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17115 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17116 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17117 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17118 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17119 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17120 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17121 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17122 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17123 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17124
17125 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17126 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17127 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17128 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17129 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17130 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17131 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17132 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17133 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17134 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17135 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17136 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17137
17138 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17139 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17140 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17141 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17142 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17143 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17144 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17145 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17146 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17147 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17148 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17149 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17150
17151 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17152 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17153 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17154 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17155 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17156 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17157 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17158 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17159 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17160 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17161 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17162 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17163
17164 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17165 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17166 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17167 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17168 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17169 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17170 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17171 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17172 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17173 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17174 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17175 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17176
17177 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17178 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17179 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17180 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17181 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17182 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17183 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17184 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17185 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17186 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17187 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17188 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17189
17190 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17191 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17192 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17193 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17194 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17195 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17196 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17197 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17198 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17199 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17200 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17202
17203 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17204 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17205 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17207 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17208 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17209 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17210 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17211 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17212 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17213 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17214 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17215
17216 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17217 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17218 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17219 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17220 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17221 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17222 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17223 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17224 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17225 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17226 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17227 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17228
17229 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17230 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17231 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17232 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17233 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17234 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17235 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17236 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17237 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17238 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17239 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17240 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17241
17242 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17243 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17244 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17245 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17246 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17247 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17248 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17249 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17250 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17251 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17252 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17253 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17254
17255 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17256 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17257 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17258 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17259 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17260 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17261 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17262 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17263 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17264 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17265 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17266 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17267
17268 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17269 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17270 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17271 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17272 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17273 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17274 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17275 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17276 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17277 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17278 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17279 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17280
17281 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17282 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17283 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17284 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17285 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17286 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17290 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17291 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17293
17294 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17295 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17296 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17297 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17298 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17299 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17303 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17304 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17306
17307 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17308 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17309 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17310 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17311 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17312 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17316 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17317 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17319
17320 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17321 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17322 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17323 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17324 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17325 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17329 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17330 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17332
17333 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17334 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17335 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17336 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17337 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17338 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17339 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17340 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17341 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17342 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17343 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17344 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17345
17346 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17347 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17348 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17349 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17350 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17351 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17352 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17353 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17354 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17355 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17356 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17357 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17358
17359 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17360 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17361 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17362 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17363
17364 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17365 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17366 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17367 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17368 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17369 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17370 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17371 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17372 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17373 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17374 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17375 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17376
c19d1205
ZW
17377 /* The implementation of the FIX instruction is broken on some
17378 assemblers, in that it accepts a precision specifier as well as a
17379 rounding specifier, despite the fact that this is meaningless.
17380 To be more compatible, we accept it as well, though of course it
17381 does not set any bits. */
21d799b5
NC
17382 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17383 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17384 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17385 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17386 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17387 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17388 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17389 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17390 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17391 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17392 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17393 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17394 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17395
c19d1205 17396 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17397#undef ARM_VARIANT
17398#define ARM_VARIANT & fpu_fpa_ext_v2
17399
21d799b5
NC
17400 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17401 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17402 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17403 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17404 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17405 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17406
c921be7d
NC
17407#undef ARM_VARIANT
17408#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17409
c19d1205 17410 /* Moves and type conversions. */
21d799b5
NC
17411 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17412 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17413 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17414 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17415 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17416 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17417 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17418 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17419 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17420 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17421 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17422 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17423 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17424 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17425
17426 /* Memory operations. */
21d799b5
NC
17427 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17428 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17429 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17430 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17431 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17432 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17433 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17434 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17435 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17436 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17437 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17438 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17439 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17440 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17441 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17442 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17443 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17444 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17445
c19d1205 17446 /* Monadic operations. */
21d799b5
NC
17447 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17448 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17449 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17450
17451 /* Dyadic operations. */
21d799b5
NC
17452 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17453 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17454 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17455 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17456 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17457 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17458 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17459 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17460 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17461
c19d1205 17462 /* Comparisons. */
21d799b5
NC
17463 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17464 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17465 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17466 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17467
62f3b8c8
PB
17468 /* Double precision load/store are still present on single precision
17469 implementations. */
17470 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17471 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17472 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17473 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17474 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17475 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17476 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17477 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17478 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17479 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17480
c921be7d
NC
17481#undef ARM_VARIANT
17482#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17483
c19d1205 17484 /* Moves and type conversions. */
21d799b5
NC
17485 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17486 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17487 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17488 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17489 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17490 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17491 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17492 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17493 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17494 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17495 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17496 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17497 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17498
c19d1205 17499 /* Monadic operations. */
21d799b5
NC
17500 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17501 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17502 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17503
17504 /* Dyadic operations. */
21d799b5
NC
17505 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17506 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17507 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17508 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17509 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17510 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17511 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17512 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17513 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17514
c19d1205 17515 /* Comparisons. */
21d799b5
NC
17516 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17517 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17518 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17519 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17520
c921be7d
NC
17521#undef ARM_VARIANT
17522#define ARM_VARIANT & fpu_vfp_ext_v2
17523
21d799b5
NC
17524 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17525 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17526 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17527 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17528
037e8744
JB
17529/* Instructions which may belong to either the Neon or VFP instruction sets.
17530 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17531#undef ARM_VARIANT
17532#define ARM_VARIANT & fpu_vfp_ext_v1xd
17533#undef THUMB_VARIANT
17534#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17535
037e8744
JB
17536 /* These mnemonics are unique to VFP. */
17537 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17538 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17539 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17540 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17541 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17542 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17543 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17544 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17545 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17546 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17547
17548 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17549 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17550 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17551 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17552
21d799b5
NC
17553 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17554 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17555
17556 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17557 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17558
17559 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17560 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17561 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17562 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17563 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17564 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17565 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17566 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17567
e3e535bc
NC
17568 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17569 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17570 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17571 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17572
037e8744
JB
17573
17574 /* NOTE: All VMOV encoding is special-cased! */
17575 NCE(vmov, 0, 1, (VMOV), neon_mov),
17576 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17577
c921be7d
NC
17578#undef THUMB_VARIANT
17579#define THUMB_VARIANT & fpu_neon_ext_v1
17580#undef ARM_VARIANT
17581#define ARM_VARIANT & fpu_neon_ext_v1
17582
5287ad62
JB
17583 /* Data processing with three registers of the same length. */
17584 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17585 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17586 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17587 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17588 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17589 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17590 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17591 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17592 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17593 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17594 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17595 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17596 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17597 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17598 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17599 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17600 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17601 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17602 /* If not immediate, fall back to neon_dyadic_i64_su.
17603 shl_imm should accept I8 I16 I32 I64,
17604 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17605 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17606 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17607 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17608 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17609 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17610 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17611 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17612 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17613 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17614 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17615 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17616 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17617 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17618 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17619 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17620 /* Bitfield ops, untyped. */
17621 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17622 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17623 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17624 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17625 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17626 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17627 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17628 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17629 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17630 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17631 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17632 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17633 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17634 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17635 back to neon_dyadic_if_su. */
21d799b5
NC
17636 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17637 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17638 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17639 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17640 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17641 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17642 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17643 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17644 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17645 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17646 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17647 /* As above, D registers only. */
21d799b5
NC
17648 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17649 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17650 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17651 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17652 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17653 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17654 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17655 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17656 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17657 /* vtst takes sizes 8, 16, 32. */
17658 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17659 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17660 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17661 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17662 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17663 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17664 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17665 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17666 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17667 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17668 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17669 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17670 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17671 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17672 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17673 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17674 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17675 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17676 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17677 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17678 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17679
17680 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17681 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17682 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17683
17684 /* Data processing with two registers and a shift amount. */
17685 /* Right shifts, and variants with rounding.
17686 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17687 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17688 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17689 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17690 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17691 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17692 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17693 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17694 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17695 /* Shift and insert. Sizes accepted 8 16 32 64. */
17696 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17697 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17698 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17699 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17700 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17701 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17702 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17703 /* Right shift immediate, saturating & narrowing, with rounding variants.
17704 Types accepted S16 S32 S64 U16 U32 U64. */
17705 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17706 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17707 /* As above, unsigned. Types accepted S16 S32 S64. */
17708 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17709 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17710 /* Right shift narrowing. Types accepted I16 I32 I64. */
17711 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17712 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17713 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17714 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17715 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17716 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17717
4316f0d2
DG
17718 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17719 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17720
17721 /* Data processing, three registers of different lengths. */
17722 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17723 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17724 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17725 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17726 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17727 /* If not scalar, fall back to neon_dyadic_long.
17728 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17729 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17730 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17731 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17732 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17733 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17734 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17735 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17736 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17737 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17738 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17739 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17740 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17741 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17742 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17743 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17744 S16 S32 U16 U32. */
21d799b5 17745 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17746
17747 /* Extract. Size 8. */
3b8d421e
PB
17748 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17749 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17750
17751 /* Two registers, miscellaneous. */
17752 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17753 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17754 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17755 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17756 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17757 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17758 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17759 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17760 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17761 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17762 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17763 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17764 /* VMOVN. Types I16 I32 I64. */
21d799b5 17765 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17766 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17767 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17768 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17769 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17770 /* VZIP / VUZP. Sizes 8 16 32. */
17771 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17772 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17773 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17774 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17775 /* VQABS / VQNEG. Types S8 S16 S32. */
17776 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17777 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17778 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17779 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17780 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17781 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17782 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17783 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17784 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17785 /* Reciprocal estimates. Types U32 F32. */
17786 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17787 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17788 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17789 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17790 /* VCLS. Types S8 S16 S32. */
17791 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17792 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17793 /* VCLZ. Types I8 I16 I32. */
17794 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17795 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17796 /* VCNT. Size 8. */
17797 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17798 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17799 /* Two address, untyped. */
17800 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17801 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17802 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17803 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17804 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17805
17806 /* Table lookup. Size 8. */
17807 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17808 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17809
c921be7d
NC
17810#undef THUMB_VARIANT
17811#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17812#undef ARM_VARIANT
17813#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17814
5287ad62 17815 /* Neon element/structure load/store. */
21d799b5
NC
17816 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17817 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17818 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17819 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17820 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17821 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17822 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17823 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17824
c921be7d 17825#undef THUMB_VARIANT
62f3b8c8
PB
17826#define THUMB_VARIANT &fpu_vfp_ext_v3xd
17827#undef ARM_VARIANT
17828#define ARM_VARIANT &fpu_vfp_ext_v3xd
17829 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17830 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17831 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17832 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17833 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17834 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17835 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17836 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17837 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17838
17839#undef THUMB_VARIANT
c921be7d
NC
17840#define THUMB_VARIANT & fpu_vfp_ext_v3
17841#undef ARM_VARIANT
17842#define ARM_VARIANT & fpu_vfp_ext_v3
17843
21d799b5 17844 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 17845 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17846 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17847 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17848 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17849 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17850 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17851 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17852 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17853
62f3b8c8
PB
17854#undef ARM_VARIANT
17855#define ARM_VARIANT &fpu_vfp_ext_fma
17856#undef THUMB_VARIANT
17857#define THUMB_VARIANT &fpu_vfp_ext_fma
17858 /* Mnemonics shared by Neon and VFP. These are included in the
17859 VFP FMA variant; NEON and VFP FMA always includes the NEON
17860 FMA instructions. */
17861 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17862 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17863 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17864 the v form should always be used. */
17865 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17866 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17867 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17868 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17869 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17870 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17871
5287ad62 17872#undef THUMB_VARIANT
c921be7d
NC
17873#undef ARM_VARIANT
17874#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17875
21d799b5
NC
17876 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17877 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17878 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17879 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17880 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17881 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17882 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17883 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 17884
c921be7d
NC
17885#undef ARM_VARIANT
17886#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17887
21d799b5
NC
17888 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17889 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17890 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17891 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17892 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17893 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17894 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17895 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17896 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17897 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17898 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17899 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17900 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17901 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17902 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17903 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17904 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17905 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17906 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17907 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17908 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17909 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17910 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17911 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17912 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17913 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17914 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17915 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17916 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17917 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17918 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17919 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17920 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17921 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17922 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17923 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17924 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17925 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17934 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17935 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17945 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17946 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17947 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17955 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17956 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17957 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17958 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17961 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17962 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17963 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17964 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17965 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17966 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17967 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17968 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17969 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17970 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17971 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17972 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17973 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17974 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17975 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17976 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17977 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17978 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17979 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17980 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17981 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17982 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17983 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17984 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17985 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17986 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17987 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17988 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17989 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17990 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17991 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17992 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17993 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17994 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17995 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17996 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17997 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17998 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17999 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18000 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18001 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18002 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18003 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18004 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18005 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18006 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18007 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18008 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18009 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18010 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18011 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18012 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18013 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18014 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18015 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18016 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18017 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18018 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18019 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18020 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18021 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18022 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18023 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18024 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18025 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18026 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18027 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18028 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18029 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18030 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18031 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18032 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18033 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18034 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18035 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18036 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18037 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18038 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18039 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18040 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18041 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18042 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18043 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18044 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18045 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18046 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18047 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18048 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18049 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18050
c921be7d
NC
18051#undef ARM_VARIANT
18052#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18053
21d799b5
NC
18054 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18055 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18056 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18057 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18058 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18059 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18060 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18061 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18062 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18063 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18064 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18065 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18066 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18067 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18068 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18069 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18070 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18071 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18075 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18083 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18084 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18085 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18086 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18087 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18088 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18091 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18092 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18093 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18094 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18095 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18096 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18097 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18098 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18099 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18100 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18101 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18102 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18103 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18104 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18105 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18106 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18107 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18108 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18109 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18110 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18111
c921be7d
NC
18112#undef ARM_VARIANT
18113#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18114
21d799b5
NC
18115 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18116 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18117 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18118 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18119 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18120 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18121 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18122 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18123 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18124 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18125 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18126 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18127 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18128 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18129 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18130 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18131 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18132 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18133 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18134 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18135 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18136 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18137 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18138 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18139 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18140 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18141 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18142 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18143 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18144 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18145 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18146 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18147 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18148 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18149 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18150 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18151 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18152 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18153 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18154 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18155 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18156 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18157 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18158 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18159 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18160 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18161 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18162 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18163 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18164 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18165 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18166 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18167 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18168 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18169 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18170 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18171 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18172 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18173 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18174 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18175 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18176 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18177 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18178 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18179 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18180 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18181 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18182 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18183 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18184 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18185 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18186 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18187 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18188 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18189 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18190 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18191};
18192#undef ARM_VARIANT
18193#undef THUMB_VARIANT
18194#undef TCE
18195#undef TCM
18196#undef TUE
18197#undef TUF
18198#undef TCC
8f06b2d8 18199#undef cCE
e3cb604e
PB
18200#undef cCL
18201#undef C3E
c19d1205
ZW
18202#undef CE
18203#undef CM
18204#undef UE
18205#undef UF
18206#undef UT
5287ad62
JB
18207#undef NUF
18208#undef nUF
18209#undef NCE
18210#undef nCE
c19d1205
ZW
18211#undef OPS0
18212#undef OPS1
18213#undef OPS2
18214#undef OPS3
18215#undef OPS4
18216#undef OPS5
18217#undef OPS6
18218#undef do_0
18219\f
18220/* MD interface: bits in the object file. */
bfae80f2 18221
c19d1205
ZW
18222/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18223 for use in the a.out file, and stores them in the array pointed to by buf.
18224 This knows about the endian-ness of the target machine and does
18225 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18226 2 (short) and 4 (long) Floating numbers are put out as a series of
18227 LITTLENUMS (shorts, here at least). */
b99bd4ef 18228
c19d1205
ZW
18229void
18230md_number_to_chars (char * buf, valueT val, int n)
18231{
18232 if (target_big_endian)
18233 number_to_chars_bigendian (buf, val, n);
18234 else
18235 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18236}
18237
c19d1205
ZW
18238static valueT
18239md_chars_to_number (char * buf, int n)
bfae80f2 18240{
c19d1205
ZW
18241 valueT result = 0;
18242 unsigned char * where = (unsigned char *) buf;
bfae80f2 18243
c19d1205 18244 if (target_big_endian)
b99bd4ef 18245 {
c19d1205
ZW
18246 while (n--)
18247 {
18248 result <<= 8;
18249 result |= (*where++ & 255);
18250 }
b99bd4ef 18251 }
c19d1205 18252 else
b99bd4ef 18253 {
c19d1205
ZW
18254 while (n--)
18255 {
18256 result <<= 8;
18257 result |= (where[n] & 255);
18258 }
bfae80f2 18259 }
b99bd4ef 18260
c19d1205 18261 return result;
bfae80f2 18262}
b99bd4ef 18263
c19d1205 18264/* MD interface: Sections. */
b99bd4ef 18265
0110f2b8
PB
18266/* Estimate the size of a frag before relaxing. Assume everything fits in
18267 2 bytes. */
18268
c19d1205 18269int
0110f2b8 18270md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18271 segT segtype ATTRIBUTE_UNUSED)
18272{
0110f2b8
PB
18273 fragp->fr_var = 2;
18274 return 2;
18275}
18276
18277/* Convert a machine dependent frag. */
18278
18279void
18280md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18281{
18282 unsigned long insn;
18283 unsigned long old_op;
18284 char *buf;
18285 expressionS exp;
18286 fixS *fixp;
18287 int reloc_type;
18288 int pc_rel;
18289 int opcode;
18290
18291 buf = fragp->fr_literal + fragp->fr_fix;
18292
18293 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18294 if (fragp->fr_symbol)
18295 {
0110f2b8
PB
18296 exp.X_op = O_symbol;
18297 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18298 }
18299 else
18300 {
0110f2b8 18301 exp.X_op = O_constant;
5f4273c7 18302 }
0110f2b8
PB
18303 exp.X_add_number = fragp->fr_offset;
18304 opcode = fragp->fr_subtype;
18305 switch (opcode)
18306 {
18307 case T_MNEM_ldr_pc:
18308 case T_MNEM_ldr_pc2:
18309 case T_MNEM_ldr_sp:
18310 case T_MNEM_str_sp:
18311 case T_MNEM_ldr:
18312 case T_MNEM_ldrb:
18313 case T_MNEM_ldrh:
18314 case T_MNEM_str:
18315 case T_MNEM_strb:
18316 case T_MNEM_strh:
18317 if (fragp->fr_var == 4)
18318 {
5f4273c7 18319 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18320 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18321 {
18322 insn |= (old_op & 0x700) << 4;
18323 }
18324 else
18325 {
18326 insn |= (old_op & 7) << 12;
18327 insn |= (old_op & 0x38) << 13;
18328 }
18329 insn |= 0x00000c00;
18330 put_thumb32_insn (buf, insn);
18331 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18332 }
18333 else
18334 {
18335 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18336 }
18337 pc_rel = (opcode == T_MNEM_ldr_pc2);
18338 break;
18339 case T_MNEM_adr:
18340 if (fragp->fr_var == 4)
18341 {
18342 insn = THUMB_OP32 (opcode);
18343 insn |= (old_op & 0xf0) << 4;
18344 put_thumb32_insn (buf, insn);
18345 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18346 }
18347 else
18348 {
18349 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18350 exp.X_add_number -= 4;
18351 }
18352 pc_rel = 1;
18353 break;
18354 case T_MNEM_mov:
18355 case T_MNEM_movs:
18356 case T_MNEM_cmp:
18357 case T_MNEM_cmn:
18358 if (fragp->fr_var == 4)
18359 {
18360 int r0off = (opcode == T_MNEM_mov
18361 || opcode == T_MNEM_movs) ? 0 : 8;
18362 insn = THUMB_OP32 (opcode);
18363 insn = (insn & 0xe1ffffff) | 0x10000000;
18364 insn |= (old_op & 0x700) << r0off;
18365 put_thumb32_insn (buf, insn);
18366 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18367 }
18368 else
18369 {
18370 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18371 }
18372 pc_rel = 0;
18373 break;
18374 case T_MNEM_b:
18375 if (fragp->fr_var == 4)
18376 {
18377 insn = THUMB_OP32(opcode);
18378 put_thumb32_insn (buf, insn);
18379 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18380 }
18381 else
18382 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18383 pc_rel = 1;
18384 break;
18385 case T_MNEM_bcond:
18386 if (fragp->fr_var == 4)
18387 {
18388 insn = THUMB_OP32(opcode);
18389 insn |= (old_op & 0xf00) << 14;
18390 put_thumb32_insn (buf, insn);
18391 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18392 }
18393 else
18394 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18395 pc_rel = 1;
18396 break;
18397 case T_MNEM_add_sp:
18398 case T_MNEM_add_pc:
18399 case T_MNEM_inc_sp:
18400 case T_MNEM_dec_sp:
18401 if (fragp->fr_var == 4)
18402 {
18403 /* ??? Choose between add and addw. */
18404 insn = THUMB_OP32 (opcode);
18405 insn |= (old_op & 0xf0) << 4;
18406 put_thumb32_insn (buf, insn);
16805f35
PB
18407 if (opcode == T_MNEM_add_pc)
18408 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18409 else
18410 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18411 }
18412 else
18413 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18414 pc_rel = 0;
18415 break;
18416
18417 case T_MNEM_addi:
18418 case T_MNEM_addis:
18419 case T_MNEM_subi:
18420 case T_MNEM_subis:
18421 if (fragp->fr_var == 4)
18422 {
18423 insn = THUMB_OP32 (opcode);
18424 insn |= (old_op & 0xf0) << 4;
18425 insn |= (old_op & 0xf) << 16;
18426 put_thumb32_insn (buf, insn);
16805f35
PB
18427 if (insn & (1 << 20))
18428 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18429 else
18430 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18431 }
18432 else
18433 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18434 pc_rel = 0;
18435 break;
18436 default:
5f4273c7 18437 abort ();
0110f2b8
PB
18438 }
18439 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18440 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18441 fixp->fx_file = fragp->fr_file;
18442 fixp->fx_line = fragp->fr_line;
18443 fragp->fr_fix += fragp->fr_var;
18444}
18445
18446/* Return the size of a relaxable immediate operand instruction.
18447 SHIFT and SIZE specify the form of the allowable immediate. */
18448static int
18449relax_immediate (fragS *fragp, int size, int shift)
18450{
18451 offsetT offset;
18452 offsetT mask;
18453 offsetT low;
18454
18455 /* ??? Should be able to do better than this. */
18456 if (fragp->fr_symbol)
18457 return 4;
18458
18459 low = (1 << shift) - 1;
18460 mask = (1 << (shift + size)) - (1 << shift);
18461 offset = fragp->fr_offset;
18462 /* Force misaligned offsets to 32-bit variant. */
18463 if (offset & low)
5e77afaa 18464 return 4;
0110f2b8
PB
18465 if (offset & ~mask)
18466 return 4;
18467 return 2;
18468}
18469
5e77afaa
PB
18470/* Get the address of a symbol during relaxation. */
18471static addressT
5f4273c7 18472relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18473{
18474 fragS *sym_frag;
18475 addressT addr;
18476 symbolS *sym;
18477
18478 sym = fragp->fr_symbol;
18479 sym_frag = symbol_get_frag (sym);
18480 know (S_GET_SEGMENT (sym) != absolute_section
18481 || sym_frag == &zero_address_frag);
18482 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18483
18484 /* If frag has yet to be reached on this pass, assume it will
18485 move by STRETCH just as we did. If this is not so, it will
18486 be because some frag between grows, and that will force
18487 another pass. */
18488
18489 if (stretch != 0
18490 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18491 {
18492 fragS *f;
18493
18494 /* Adjust stretch for any alignment frag. Note that if have
18495 been expanding the earlier code, the symbol may be
18496 defined in what appears to be an earlier frag. FIXME:
18497 This doesn't handle the fr_subtype field, which specifies
18498 a maximum number of bytes to skip when doing an
18499 alignment. */
18500 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18501 {
18502 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18503 {
18504 if (stretch < 0)
18505 stretch = - ((- stretch)
18506 & ~ ((1 << (int) f->fr_offset) - 1));
18507 else
18508 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18509 if (stretch == 0)
18510 break;
18511 }
18512 }
18513 if (f != NULL)
18514 addr += stretch;
18515 }
5e77afaa
PB
18516
18517 return addr;
18518}
18519
0110f2b8
PB
18520/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18521 load. */
18522static int
5e77afaa 18523relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18524{
18525 addressT addr;
18526 offsetT val;
18527
18528 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18529 if (fragp->fr_symbol == NULL
18530 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18531 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18532 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18533 return 4;
18534
5f4273c7 18535 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18536 addr = fragp->fr_address + fragp->fr_fix;
18537 addr = (addr + 4) & ~3;
5e77afaa 18538 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18539 if (val & 3)
5e77afaa 18540 return 4;
0110f2b8
PB
18541 val -= addr;
18542 if (val < 0 || val > 1020)
18543 return 4;
18544 return 2;
18545}
18546
18547/* Return the size of a relaxable add/sub immediate instruction. */
18548static int
18549relax_addsub (fragS *fragp, asection *sec)
18550{
18551 char *buf;
18552 int op;
18553
18554 buf = fragp->fr_literal + fragp->fr_fix;
18555 op = bfd_get_16(sec->owner, buf);
18556 if ((op & 0xf) == ((op >> 4) & 0xf))
18557 return relax_immediate (fragp, 8, 0);
18558 else
18559 return relax_immediate (fragp, 3, 0);
18560}
18561
18562
18563/* Return the size of a relaxable branch instruction. BITS is the
18564 size of the offset field in the narrow instruction. */
18565
18566static int
5e77afaa 18567relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18568{
18569 addressT addr;
18570 offsetT val;
18571 offsetT limit;
18572
18573 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18574 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18575 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18576 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18577 return 4;
18578
267bf995
RR
18579#ifdef OBJ_ELF
18580 if (S_IS_DEFINED (fragp->fr_symbol)
18581 && ARM_IS_FUNC (fragp->fr_symbol))
18582 return 4;
18583#endif
18584
5f4273c7 18585 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18586 addr = fragp->fr_address + fragp->fr_fix + 4;
18587 val -= addr;
18588
18589 /* Offset is a signed value *2 */
18590 limit = 1 << bits;
18591 if (val >= limit || val < -limit)
18592 return 4;
18593 return 2;
18594}
18595
18596
18597/* Relax a machine dependent frag. This returns the amount by which
18598 the current size of the frag should change. */
18599
18600int
5e77afaa 18601arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18602{
18603 int oldsize;
18604 int newsize;
18605
18606 oldsize = fragp->fr_var;
18607 switch (fragp->fr_subtype)
18608 {
18609 case T_MNEM_ldr_pc2:
5f4273c7 18610 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18611 break;
18612 case T_MNEM_ldr_pc:
18613 case T_MNEM_ldr_sp:
18614 case T_MNEM_str_sp:
5f4273c7 18615 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18616 break;
18617 case T_MNEM_ldr:
18618 case T_MNEM_str:
5f4273c7 18619 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18620 break;
18621 case T_MNEM_ldrh:
18622 case T_MNEM_strh:
5f4273c7 18623 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18624 break;
18625 case T_MNEM_ldrb:
18626 case T_MNEM_strb:
5f4273c7 18627 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18628 break;
18629 case T_MNEM_adr:
5f4273c7 18630 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18631 break;
18632 case T_MNEM_mov:
18633 case T_MNEM_movs:
18634 case T_MNEM_cmp:
18635 case T_MNEM_cmn:
5f4273c7 18636 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18637 break;
18638 case T_MNEM_b:
5f4273c7 18639 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18640 break;
18641 case T_MNEM_bcond:
5f4273c7 18642 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18643 break;
18644 case T_MNEM_add_sp:
18645 case T_MNEM_add_pc:
18646 newsize = relax_immediate (fragp, 8, 2);
18647 break;
18648 case T_MNEM_inc_sp:
18649 case T_MNEM_dec_sp:
18650 newsize = relax_immediate (fragp, 7, 2);
18651 break;
18652 case T_MNEM_addi:
18653 case T_MNEM_addis:
18654 case T_MNEM_subi:
18655 case T_MNEM_subis:
18656 newsize = relax_addsub (fragp, sec);
18657 break;
18658 default:
5f4273c7 18659 abort ();
0110f2b8 18660 }
5e77afaa
PB
18661
18662 fragp->fr_var = newsize;
18663 /* Freeze wide instructions that are at or before the same location as
18664 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18665 Don't freeze them unconditionally because targets may be artificially
18666 misaligned by the expansion of preceding frags. */
5e77afaa 18667 if (stretch <= 0 && newsize > 2)
0110f2b8 18668 {
0110f2b8 18669 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18670 frag_wane (fragp);
0110f2b8 18671 }
5e77afaa 18672
0110f2b8 18673 return newsize - oldsize;
c19d1205 18674}
b99bd4ef 18675
c19d1205 18676/* Round up a section size to the appropriate boundary. */
b99bd4ef 18677
c19d1205
ZW
18678valueT
18679md_section_align (segT segment ATTRIBUTE_UNUSED,
18680 valueT size)
18681{
f0927246
NC
18682#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18683 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18684 {
18685 /* For a.out, force the section size to be aligned. If we don't do
18686 this, BFD will align it for us, but it will not write out the
18687 final bytes of the section. This may be a bug in BFD, but it is
18688 easier to fix it here since that is how the other a.out targets
18689 work. */
18690 int align;
18691
18692 align = bfd_get_section_alignment (stdoutput, segment);
18693 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18694 }
c19d1205 18695#endif
f0927246
NC
18696
18697 return size;
bfae80f2 18698}
b99bd4ef 18699
c19d1205
ZW
18700/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18701 of an rs_align_code fragment. */
18702
18703void
18704arm_handle_align (fragS * fragP)
bfae80f2 18705{
e7495e45
NS
18706 static char const arm_noop[2][2][4] =
18707 {
18708 { /* ARMv1 */
18709 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18710 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18711 },
18712 { /* ARMv6k */
18713 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18714 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18715 },
18716 };
18717 static char const thumb_noop[2][2][2] =
18718 {
18719 { /* Thumb-1 */
18720 {0xc0, 0x46}, /* LE */
18721 {0x46, 0xc0}, /* BE */
18722 },
18723 { /* Thumb-2 */
18724 {0x00, 0xbf}, /* LE */
18725 {0xbf, 0x00} /* BE */
18726 }
18727 };
18728 static char const wide_thumb_noop[2][4] =
18729 { /* Wide Thumb-2 */
18730 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18731 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18732 };
c921be7d 18733
e7495e45 18734 unsigned bytes, fix, noop_size;
c19d1205
ZW
18735 char * p;
18736 const char * noop;
e7495e45 18737 const char *narrow_noop = NULL;
cd000bff
DJ
18738#ifdef OBJ_ELF
18739 enum mstate state;
18740#endif
bfae80f2 18741
c19d1205 18742 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18743 return;
18744
c19d1205
ZW
18745 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18746 p = fragP->fr_literal + fragP->fr_fix;
18747 fix = 0;
bfae80f2 18748
c19d1205
ZW
18749 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18750 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18751
cd000bff 18752 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18753
cd000bff 18754 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18755 {
e7495e45
NS
18756 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18757 {
18758 narrow_noop = thumb_noop[1][target_big_endian];
18759 noop = wide_thumb_noop[target_big_endian];
18760 }
c19d1205 18761 else
e7495e45
NS
18762 noop = thumb_noop[0][target_big_endian];
18763 noop_size = 2;
cd000bff
DJ
18764#ifdef OBJ_ELF
18765 state = MAP_THUMB;
18766#endif
7ed4c4c5
NC
18767 }
18768 else
18769 {
e7495e45
NS
18770 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18771 [target_big_endian];
18772 noop_size = 4;
cd000bff
DJ
18773#ifdef OBJ_ELF
18774 state = MAP_ARM;
18775#endif
7ed4c4c5 18776 }
c921be7d 18777
e7495e45 18778 fragP->fr_var = noop_size;
c921be7d 18779
c19d1205 18780 if (bytes & (noop_size - 1))
7ed4c4c5 18781 {
c19d1205 18782 fix = bytes & (noop_size - 1);
cd000bff
DJ
18783#ifdef OBJ_ELF
18784 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18785#endif
c19d1205
ZW
18786 memset (p, 0, fix);
18787 p += fix;
18788 bytes -= fix;
a737bd4d 18789 }
a737bd4d 18790
e7495e45
NS
18791 if (narrow_noop)
18792 {
18793 if (bytes & noop_size)
18794 {
18795 /* Insert a narrow noop. */
18796 memcpy (p, narrow_noop, noop_size);
18797 p += noop_size;
18798 bytes -= noop_size;
18799 fix += noop_size;
18800 }
18801
18802 /* Use wide noops for the remainder */
18803 noop_size = 4;
18804 }
18805
c19d1205 18806 while (bytes >= noop_size)
a737bd4d 18807 {
c19d1205
ZW
18808 memcpy (p, noop, noop_size);
18809 p += noop_size;
18810 bytes -= noop_size;
18811 fix += noop_size;
a737bd4d
NC
18812 }
18813
c19d1205 18814 fragP->fr_fix += fix;
a737bd4d
NC
18815}
18816
c19d1205
ZW
18817/* Called from md_do_align. Used to create an alignment
18818 frag in a code section. */
18819
18820void
18821arm_frag_align_code (int n, int max)
bfae80f2 18822{
c19d1205 18823 char * p;
7ed4c4c5 18824
c19d1205 18825 /* We assume that there will never be a requirement
6ec8e702 18826 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 18827 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
18828 {
18829 char err_msg[128];
18830
18831 sprintf (err_msg,
18832 _("alignments greater than %d bytes not supported in .text sections."),
18833 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 18834 as_fatal ("%s", err_msg);
6ec8e702 18835 }
bfae80f2 18836
c19d1205
ZW
18837 p = frag_var (rs_align_code,
18838 MAX_MEM_FOR_RS_ALIGN_CODE,
18839 1,
18840 (relax_substateT) max,
18841 (symbolS *) NULL,
18842 (offsetT) n,
18843 (char *) NULL);
18844 *p = 0;
18845}
bfae80f2 18846
8dc2430f
NC
18847/* Perform target specific initialisation of a frag.
18848 Note - despite the name this initialisation is not done when the frag
18849 is created, but only when its type is assigned. A frag can be created
18850 and used a long time before its type is set, so beware of assuming that
18851 this initialisationis performed first. */
bfae80f2 18852
cd000bff
DJ
18853#ifndef OBJ_ELF
18854void
18855arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18856{
18857 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 18858 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
18859}
18860
18861#else /* OBJ_ELF is defined. */
c19d1205 18862void
cd000bff 18863arm_init_frag (fragS * fragP, int max_chars)
c19d1205 18864{
8dc2430f
NC
18865 /* If the current ARM vs THUMB mode has not already
18866 been recorded into this frag then do so now. */
cd000bff
DJ
18867 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18868 {
18869 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18870
18871 /* Record a mapping symbol for alignment frags. We will delete this
18872 later if the alignment ends up empty. */
18873 switch (fragP->fr_type)
18874 {
18875 case rs_align:
18876 case rs_align_test:
18877 case rs_fill:
18878 mapping_state_2 (MAP_DATA, max_chars);
18879 break;
18880 case rs_align_code:
18881 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18882 break;
18883 default:
18884 break;
18885 }
18886 }
bfae80f2
RE
18887}
18888
c19d1205
ZW
18889/* When we change sections we need to issue a new mapping symbol. */
18890
18891void
18892arm_elf_change_section (void)
bfae80f2 18893{
c19d1205
ZW
18894 /* Link an unlinked unwind index table section to the .text section. */
18895 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18896 && elf_linked_to_section (now_seg) == NULL)
18897 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
18898}
18899
c19d1205
ZW
18900int
18901arm_elf_section_type (const char * str, size_t len)
e45d0630 18902{
c19d1205
ZW
18903 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18904 return SHT_ARM_EXIDX;
e45d0630 18905
c19d1205
ZW
18906 return -1;
18907}
18908\f
18909/* Code to deal with unwinding tables. */
e45d0630 18910
c19d1205 18911static void add_unwind_adjustsp (offsetT);
e45d0630 18912
5f4273c7 18913/* Generate any deferred unwind frame offset. */
e45d0630 18914
bfae80f2 18915static void
c19d1205 18916flush_pending_unwind (void)
bfae80f2 18917{
c19d1205 18918 offsetT offset;
bfae80f2 18919
c19d1205
ZW
18920 offset = unwind.pending_offset;
18921 unwind.pending_offset = 0;
18922 if (offset != 0)
18923 add_unwind_adjustsp (offset);
bfae80f2
RE
18924}
18925
c19d1205
ZW
18926/* Add an opcode to this list for this function. Two-byte opcodes should
18927 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18928 order. */
18929
bfae80f2 18930static void
c19d1205 18931add_unwind_opcode (valueT op, int length)
bfae80f2 18932{
c19d1205
ZW
18933 /* Add any deferred stack adjustment. */
18934 if (unwind.pending_offset)
18935 flush_pending_unwind ();
bfae80f2 18936
c19d1205 18937 unwind.sp_restored = 0;
bfae80f2 18938
c19d1205 18939 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18940 {
c19d1205
ZW
18941 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18942 if (unwind.opcodes)
21d799b5
NC
18943 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18944 unwind.opcode_alloc);
c19d1205 18945 else
21d799b5 18946 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 18947 }
c19d1205 18948 while (length > 0)
bfae80f2 18949 {
c19d1205
ZW
18950 length--;
18951 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18952 op >>= 8;
18953 unwind.opcode_count++;
bfae80f2 18954 }
bfae80f2
RE
18955}
18956
c19d1205
ZW
18957/* Add unwind opcodes to adjust the stack pointer. */
18958
bfae80f2 18959static void
c19d1205 18960add_unwind_adjustsp (offsetT offset)
bfae80f2 18961{
c19d1205 18962 valueT op;
bfae80f2 18963
c19d1205 18964 if (offset > 0x200)
bfae80f2 18965 {
c19d1205
ZW
18966 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18967 char bytes[5];
18968 int n;
18969 valueT o;
bfae80f2 18970
c19d1205
ZW
18971 /* Long form: 0xb2, uleb128. */
18972 /* This might not fit in a word so add the individual bytes,
18973 remembering the list is built in reverse order. */
18974 o = (valueT) ((offset - 0x204) >> 2);
18975 if (o == 0)
18976 add_unwind_opcode (0, 1);
bfae80f2 18977
c19d1205
ZW
18978 /* Calculate the uleb128 encoding of the offset. */
18979 n = 0;
18980 while (o)
18981 {
18982 bytes[n] = o & 0x7f;
18983 o >>= 7;
18984 if (o)
18985 bytes[n] |= 0x80;
18986 n++;
18987 }
18988 /* Add the insn. */
18989 for (; n; n--)
18990 add_unwind_opcode (bytes[n - 1], 1);
18991 add_unwind_opcode (0xb2, 1);
18992 }
18993 else if (offset > 0x100)
bfae80f2 18994 {
c19d1205
ZW
18995 /* Two short opcodes. */
18996 add_unwind_opcode (0x3f, 1);
18997 op = (offset - 0x104) >> 2;
18998 add_unwind_opcode (op, 1);
bfae80f2 18999 }
c19d1205
ZW
19000 else if (offset > 0)
19001 {
19002 /* Short opcode. */
19003 op = (offset - 4) >> 2;
19004 add_unwind_opcode (op, 1);
19005 }
19006 else if (offset < 0)
bfae80f2 19007 {
c19d1205
ZW
19008 offset = -offset;
19009 while (offset > 0x100)
bfae80f2 19010 {
c19d1205
ZW
19011 add_unwind_opcode (0x7f, 1);
19012 offset -= 0x100;
bfae80f2 19013 }
c19d1205
ZW
19014 op = ((offset - 4) >> 2) | 0x40;
19015 add_unwind_opcode (op, 1);
bfae80f2 19016 }
bfae80f2
RE
19017}
19018
c19d1205
ZW
19019/* Finish the list of unwind opcodes for this function. */
19020static void
19021finish_unwind_opcodes (void)
bfae80f2 19022{
c19d1205 19023 valueT op;
bfae80f2 19024
c19d1205 19025 if (unwind.fp_used)
bfae80f2 19026 {
708587a4 19027 /* Adjust sp as necessary. */
c19d1205
ZW
19028 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19029 flush_pending_unwind ();
bfae80f2 19030
c19d1205
ZW
19031 /* After restoring sp from the frame pointer. */
19032 op = 0x90 | unwind.fp_reg;
19033 add_unwind_opcode (op, 1);
19034 }
19035 else
19036 flush_pending_unwind ();
bfae80f2
RE
19037}
19038
bfae80f2 19039
c19d1205
ZW
19040/* Start an exception table entry. If idx is nonzero this is an index table
19041 entry. */
bfae80f2
RE
19042
19043static void
c19d1205 19044start_unwind_section (const segT text_seg, int idx)
bfae80f2 19045{
c19d1205
ZW
19046 const char * text_name;
19047 const char * prefix;
19048 const char * prefix_once;
19049 const char * group_name;
19050 size_t prefix_len;
19051 size_t text_len;
19052 char * sec_name;
19053 size_t sec_name_len;
19054 int type;
19055 int flags;
19056 int linkonce;
bfae80f2 19057
c19d1205 19058 if (idx)
bfae80f2 19059 {
c19d1205
ZW
19060 prefix = ELF_STRING_ARM_unwind;
19061 prefix_once = ELF_STRING_ARM_unwind_once;
19062 type = SHT_ARM_EXIDX;
bfae80f2 19063 }
c19d1205 19064 else
bfae80f2 19065 {
c19d1205
ZW
19066 prefix = ELF_STRING_ARM_unwind_info;
19067 prefix_once = ELF_STRING_ARM_unwind_info_once;
19068 type = SHT_PROGBITS;
bfae80f2
RE
19069 }
19070
c19d1205
ZW
19071 text_name = segment_name (text_seg);
19072 if (streq (text_name, ".text"))
19073 text_name = "";
19074
19075 if (strncmp (text_name, ".gnu.linkonce.t.",
19076 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19077 {
c19d1205
ZW
19078 prefix = prefix_once;
19079 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19080 }
19081
c19d1205
ZW
19082 prefix_len = strlen (prefix);
19083 text_len = strlen (text_name);
19084 sec_name_len = prefix_len + text_len;
21d799b5 19085 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19086 memcpy (sec_name, prefix, prefix_len);
19087 memcpy (sec_name + prefix_len, text_name, text_len);
19088 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19089
c19d1205
ZW
19090 flags = SHF_ALLOC;
19091 linkonce = 0;
19092 group_name = 0;
bfae80f2 19093
c19d1205
ZW
19094 /* Handle COMDAT group. */
19095 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19096 {
c19d1205
ZW
19097 group_name = elf_group_name (text_seg);
19098 if (group_name == NULL)
19099 {
bd3ba5d1 19100 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19101 segment_name (text_seg));
19102 ignore_rest_of_line ();
19103 return;
19104 }
19105 flags |= SHF_GROUP;
19106 linkonce = 1;
bfae80f2
RE
19107 }
19108
c19d1205 19109 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19110
5f4273c7 19111 /* Set the section link for index tables. */
c19d1205
ZW
19112 if (idx)
19113 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19114}
19115
bfae80f2 19116
c19d1205
ZW
19117/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19118 personality routine data. Returns zero, or the index table value for
19119 and inline entry. */
19120
19121static valueT
19122create_unwind_entry (int have_data)
bfae80f2 19123{
c19d1205
ZW
19124 int size;
19125 addressT where;
19126 char *ptr;
19127 /* The current word of data. */
19128 valueT data;
19129 /* The number of bytes left in this word. */
19130 int n;
bfae80f2 19131
c19d1205 19132 finish_unwind_opcodes ();
bfae80f2 19133
c19d1205
ZW
19134 /* Remember the current text section. */
19135 unwind.saved_seg = now_seg;
19136 unwind.saved_subseg = now_subseg;
bfae80f2 19137
c19d1205 19138 start_unwind_section (now_seg, 0);
bfae80f2 19139
c19d1205 19140 if (unwind.personality_routine == NULL)
bfae80f2 19141 {
c19d1205
ZW
19142 if (unwind.personality_index == -2)
19143 {
19144 if (have_data)
5f4273c7 19145 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19146 return 1; /* EXIDX_CANTUNWIND. */
19147 }
bfae80f2 19148
c19d1205
ZW
19149 /* Use a default personality routine if none is specified. */
19150 if (unwind.personality_index == -1)
19151 {
19152 if (unwind.opcode_count > 3)
19153 unwind.personality_index = 1;
19154 else
19155 unwind.personality_index = 0;
19156 }
bfae80f2 19157
c19d1205
ZW
19158 /* Space for the personality routine entry. */
19159 if (unwind.personality_index == 0)
19160 {
19161 if (unwind.opcode_count > 3)
19162 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19163
c19d1205
ZW
19164 if (!have_data)
19165 {
19166 /* All the data is inline in the index table. */
19167 data = 0x80;
19168 n = 3;
19169 while (unwind.opcode_count > 0)
19170 {
19171 unwind.opcode_count--;
19172 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19173 n--;
19174 }
bfae80f2 19175
c19d1205
ZW
19176 /* Pad with "finish" opcodes. */
19177 while (n--)
19178 data = (data << 8) | 0xb0;
bfae80f2 19179
c19d1205
ZW
19180 return data;
19181 }
19182 size = 0;
19183 }
19184 else
19185 /* We get two opcodes "free" in the first word. */
19186 size = unwind.opcode_count - 2;
19187 }
19188 else
19189 /* An extra byte is required for the opcode count. */
19190 size = unwind.opcode_count + 1;
bfae80f2 19191
c19d1205
ZW
19192 size = (size + 3) >> 2;
19193 if (size > 0xff)
19194 as_bad (_("too many unwind opcodes"));
bfae80f2 19195
c19d1205
ZW
19196 frag_align (2, 0, 0);
19197 record_alignment (now_seg, 2);
19198 unwind.table_entry = expr_build_dot ();
19199
19200 /* Allocate the table entry. */
19201 ptr = frag_more ((size << 2) + 4);
19202 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19203
c19d1205 19204 switch (unwind.personality_index)
bfae80f2 19205 {
c19d1205
ZW
19206 case -1:
19207 /* ??? Should this be a PLT generating relocation? */
19208 /* Custom personality routine. */
19209 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19210 BFD_RELOC_ARM_PREL31);
bfae80f2 19211
c19d1205
ZW
19212 where += 4;
19213 ptr += 4;
bfae80f2 19214
c19d1205
ZW
19215 /* Set the first byte to the number of additional words. */
19216 data = size - 1;
19217 n = 3;
19218 break;
bfae80f2 19219
c19d1205
ZW
19220 /* ABI defined personality routines. */
19221 case 0:
19222 /* Three opcodes bytes are packed into the first word. */
19223 data = 0x80;
19224 n = 3;
19225 break;
bfae80f2 19226
c19d1205
ZW
19227 case 1:
19228 case 2:
19229 /* The size and first two opcode bytes go in the first word. */
19230 data = ((0x80 + unwind.personality_index) << 8) | size;
19231 n = 2;
19232 break;
bfae80f2 19233
c19d1205
ZW
19234 default:
19235 /* Should never happen. */
19236 abort ();
19237 }
bfae80f2 19238
c19d1205
ZW
19239 /* Pack the opcodes into words (MSB first), reversing the list at the same
19240 time. */
19241 while (unwind.opcode_count > 0)
19242 {
19243 if (n == 0)
19244 {
19245 md_number_to_chars (ptr, data, 4);
19246 ptr += 4;
19247 n = 4;
19248 data = 0;
19249 }
19250 unwind.opcode_count--;
19251 n--;
19252 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19253 }
19254
19255 /* Finish off the last word. */
19256 if (n < 4)
19257 {
19258 /* Pad with "finish" opcodes. */
19259 while (n--)
19260 data = (data << 8) | 0xb0;
19261
19262 md_number_to_chars (ptr, data, 4);
19263 }
19264
19265 if (!have_data)
19266 {
19267 /* Add an empty descriptor if there is no user-specified data. */
19268 ptr = frag_more (4);
19269 md_number_to_chars (ptr, 0, 4);
19270 }
19271
19272 return 0;
bfae80f2
RE
19273}
19274
f0927246
NC
19275
19276/* Initialize the DWARF-2 unwind information for this procedure. */
19277
19278void
19279tc_arm_frame_initial_instructions (void)
19280{
19281 cfi_add_CFA_def_cfa (REG_SP, 0);
19282}
19283#endif /* OBJ_ELF */
19284
c19d1205
ZW
19285/* Convert REGNAME to a DWARF-2 register number. */
19286
19287int
1df69f4f 19288tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19289{
1df69f4f 19290 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19291
19292 if (reg == FAIL)
19293 return -1;
19294
19295 return reg;
bfae80f2
RE
19296}
19297
f0927246 19298#ifdef TE_PE
c19d1205 19299void
f0927246 19300tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19301{
91d6fa6a 19302 expressionS exp;
bfae80f2 19303
91d6fa6a
NC
19304 exp.X_op = O_secrel;
19305 exp.X_add_symbol = symbol;
19306 exp.X_add_number = 0;
19307 emit_expr (&exp, size);
f0927246
NC
19308}
19309#endif
bfae80f2 19310
c19d1205 19311/* MD interface: Symbol and relocation handling. */
bfae80f2 19312
2fc8bdac
ZW
19313/* Return the address within the segment that a PC-relative fixup is
19314 relative to. For ARM, PC-relative fixups applied to instructions
19315 are generally relative to the location of the fixup plus 8 bytes.
19316 Thumb branches are offset by 4, and Thumb loads relative to PC
19317 require special handling. */
bfae80f2 19318
c19d1205 19319long
2fc8bdac 19320md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19321{
2fc8bdac
ZW
19322 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19323
19324 /* If this is pc-relative and we are going to emit a relocation
19325 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19326 will need. Otherwise we want to use the calculated base.
19327 For WinCE we skip the bias for externals as well, since this
19328 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19329 if (fixP->fx_pcrel
2fc8bdac 19330 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19331 || (arm_force_relocation (fixP)
19332#ifdef TE_WINCE
19333 && !S_IS_EXTERNAL (fixP->fx_addsy)
19334#endif
19335 )))
2fc8bdac 19336 base = 0;
bfae80f2 19337
267bf995 19338
c19d1205 19339 switch (fixP->fx_r_type)
bfae80f2 19340 {
2fc8bdac
ZW
19341 /* PC relative addressing on the Thumb is slightly odd as the
19342 bottom two bits of the PC are forced to zero for the
19343 calculation. This happens *after* application of the
19344 pipeline offset. However, Thumb adrl already adjusts for
19345 this, so we need not do it again. */
c19d1205 19346 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19347 return base & ~3;
c19d1205
ZW
19348
19349 case BFD_RELOC_ARM_THUMB_OFFSET:
19350 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19351 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19352 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19353 return (base + 4) & ~3;
c19d1205 19354
2fc8bdac
ZW
19355 /* Thumb branches are simply offset by +4. */
19356 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19357 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19358 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19359 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19360 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19361 return base + 4;
bfae80f2 19362
267bf995 19363 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19364 if (fixP->fx_addsy
19365 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19366 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19367 && ARM_IS_FUNC (fixP->fx_addsy)
19368 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19369 base = fixP->fx_where + fixP->fx_frag->fr_address;
19370 return base + 4;
19371
00adf2d4
JB
19372 /* BLX is like branches above, but forces the low two bits of PC to
19373 zero. */
486499d0
CL
19374 case BFD_RELOC_THUMB_PCREL_BLX:
19375 if (fixP->fx_addsy
19376 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19377 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19378 && THUMB_IS_FUNC (fixP->fx_addsy)
19379 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19380 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19381 return (base + 4) & ~3;
19382
2fc8bdac
ZW
19383 /* ARM mode branches are offset by +8. However, the Windows CE
19384 loader expects the relocation not to take this into account. */
267bf995 19385 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19386 if (fixP->fx_addsy
19387 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19388 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19389 && ARM_IS_FUNC (fixP->fx_addsy)
19390 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19391 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19392 return base + 8;
267bf995 19393
486499d0
CL
19394 case BFD_RELOC_ARM_PCREL_CALL:
19395 if (fixP->fx_addsy
19396 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19397 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19398 && THUMB_IS_FUNC (fixP->fx_addsy)
19399 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19400 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19401 return base + 8;
267bf995 19402
2fc8bdac 19403 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19404 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19405 case BFD_RELOC_ARM_PLT32:
c19d1205 19406#ifdef TE_WINCE
5f4273c7 19407 /* When handling fixups immediately, because we have already
53baae48
NC
19408 discovered the value of a symbol, or the address of the frag involved
19409 we must account for the offset by +8, as the OS loader will never see the reloc.
19410 see fixup_segment() in write.c
19411 The S_IS_EXTERNAL test handles the case of global symbols.
19412 Those need the calculated base, not just the pipe compensation the linker will need. */
19413 if (fixP->fx_pcrel
19414 && fixP->fx_addsy != NULL
19415 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19416 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19417 return base + 8;
2fc8bdac 19418 return base;
c19d1205 19419#else
2fc8bdac 19420 return base + 8;
c19d1205 19421#endif
2fc8bdac 19422
267bf995 19423
2fc8bdac
ZW
19424 /* ARM mode loads relative to PC are also offset by +8. Unlike
19425 branches, the Windows CE loader *does* expect the relocation
19426 to take this into account. */
19427 case BFD_RELOC_ARM_OFFSET_IMM:
19428 case BFD_RELOC_ARM_OFFSET_IMM8:
19429 case BFD_RELOC_ARM_HWLITERAL:
19430 case BFD_RELOC_ARM_LITERAL:
19431 case BFD_RELOC_ARM_CP_OFF_IMM:
19432 return base + 8;
19433
19434
19435 /* Other PC-relative relocations are un-offset. */
19436 default:
19437 return base;
19438 }
bfae80f2
RE
19439}
19440
c19d1205
ZW
19441/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19442 Otherwise we have no need to default values of symbols. */
19443
19444symbolS *
19445md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19446{
c19d1205
ZW
19447#ifdef OBJ_ELF
19448 if (name[0] == '_' && name[1] == 'G'
19449 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19450 {
19451 if (!GOT_symbol)
19452 {
19453 if (symbol_find (name))
bd3ba5d1 19454 as_bad (_("GOT already in the symbol table"));
bfae80f2 19455
c19d1205
ZW
19456 GOT_symbol = symbol_new (name, undefined_section,
19457 (valueT) 0, & zero_address_frag);
19458 }
bfae80f2 19459
c19d1205 19460 return GOT_symbol;
bfae80f2 19461 }
c19d1205 19462#endif
bfae80f2 19463
c921be7d 19464 return NULL;
bfae80f2
RE
19465}
19466
55cf6793 19467/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19468 computed as two separate immediate values, added together. We
19469 already know that this value cannot be computed by just one ARM
19470 instruction. */
19471
19472static unsigned int
19473validate_immediate_twopart (unsigned int val,
19474 unsigned int * highpart)
bfae80f2 19475{
c19d1205
ZW
19476 unsigned int a;
19477 unsigned int i;
bfae80f2 19478
c19d1205
ZW
19479 for (i = 0; i < 32; i += 2)
19480 if (((a = rotate_left (val, i)) & 0xff) != 0)
19481 {
19482 if (a & 0xff00)
19483 {
19484 if (a & ~ 0xffff)
19485 continue;
19486 * highpart = (a >> 8) | ((i + 24) << 7);
19487 }
19488 else if (a & 0xff0000)
19489 {
19490 if (a & 0xff000000)
19491 continue;
19492 * highpart = (a >> 16) | ((i + 16) << 7);
19493 }
19494 else
19495 {
9c2799c2 19496 gas_assert (a & 0xff000000);
c19d1205
ZW
19497 * highpart = (a >> 24) | ((i + 8) << 7);
19498 }
bfae80f2 19499
c19d1205
ZW
19500 return (a & 0xff) | (i << 7);
19501 }
bfae80f2 19502
c19d1205 19503 return FAIL;
bfae80f2
RE
19504}
19505
c19d1205
ZW
19506static int
19507validate_offset_imm (unsigned int val, int hwse)
19508{
19509 if ((hwse && val > 255) || val > 4095)
19510 return FAIL;
19511 return val;
19512}
bfae80f2 19513
55cf6793 19514/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19515 negative immediate constant by altering the instruction. A bit of
19516 a hack really.
19517 MOV <-> MVN
19518 AND <-> BIC
19519 ADC <-> SBC
19520 by inverting the second operand, and
19521 ADD <-> SUB
19522 CMP <-> CMN
19523 by negating the second operand. */
bfae80f2 19524
c19d1205
ZW
19525static int
19526negate_data_op (unsigned long * instruction,
19527 unsigned long value)
bfae80f2 19528{
c19d1205
ZW
19529 int op, new_inst;
19530 unsigned long negated, inverted;
bfae80f2 19531
c19d1205
ZW
19532 negated = encode_arm_immediate (-value);
19533 inverted = encode_arm_immediate (~value);
bfae80f2 19534
c19d1205
ZW
19535 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19536 switch (op)
bfae80f2 19537 {
c19d1205
ZW
19538 /* First negates. */
19539 case OPCODE_SUB: /* ADD <-> SUB */
19540 new_inst = OPCODE_ADD;
19541 value = negated;
19542 break;
bfae80f2 19543
c19d1205
ZW
19544 case OPCODE_ADD:
19545 new_inst = OPCODE_SUB;
19546 value = negated;
19547 break;
bfae80f2 19548
c19d1205
ZW
19549 case OPCODE_CMP: /* CMP <-> CMN */
19550 new_inst = OPCODE_CMN;
19551 value = negated;
19552 break;
bfae80f2 19553
c19d1205
ZW
19554 case OPCODE_CMN:
19555 new_inst = OPCODE_CMP;
19556 value = negated;
19557 break;
bfae80f2 19558
c19d1205
ZW
19559 /* Now Inverted ops. */
19560 case OPCODE_MOV: /* MOV <-> MVN */
19561 new_inst = OPCODE_MVN;
19562 value = inverted;
19563 break;
bfae80f2 19564
c19d1205
ZW
19565 case OPCODE_MVN:
19566 new_inst = OPCODE_MOV;
19567 value = inverted;
19568 break;
bfae80f2 19569
c19d1205
ZW
19570 case OPCODE_AND: /* AND <-> BIC */
19571 new_inst = OPCODE_BIC;
19572 value = inverted;
19573 break;
bfae80f2 19574
c19d1205
ZW
19575 case OPCODE_BIC:
19576 new_inst = OPCODE_AND;
19577 value = inverted;
19578 break;
bfae80f2 19579
c19d1205
ZW
19580 case OPCODE_ADC: /* ADC <-> SBC */
19581 new_inst = OPCODE_SBC;
19582 value = inverted;
19583 break;
bfae80f2 19584
c19d1205
ZW
19585 case OPCODE_SBC:
19586 new_inst = OPCODE_ADC;
19587 value = inverted;
19588 break;
bfae80f2 19589
c19d1205
ZW
19590 /* We cannot do anything. */
19591 default:
19592 return FAIL;
b99bd4ef
NC
19593 }
19594
c19d1205
ZW
19595 if (value == (unsigned) FAIL)
19596 return FAIL;
19597
19598 *instruction &= OPCODE_MASK;
19599 *instruction |= new_inst << DATA_OP_SHIFT;
19600 return value;
b99bd4ef
NC
19601}
19602
ef8d22e6
PB
19603/* Like negate_data_op, but for Thumb-2. */
19604
19605static unsigned int
16dd5e42 19606thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19607{
19608 int op, new_inst;
19609 int rd;
16dd5e42 19610 unsigned int negated, inverted;
ef8d22e6
PB
19611
19612 negated = encode_thumb32_immediate (-value);
19613 inverted = encode_thumb32_immediate (~value);
19614
19615 rd = (*instruction >> 8) & 0xf;
19616 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19617 switch (op)
19618 {
19619 /* ADD <-> SUB. Includes CMP <-> CMN. */
19620 case T2_OPCODE_SUB:
19621 new_inst = T2_OPCODE_ADD;
19622 value = negated;
19623 break;
19624
19625 case T2_OPCODE_ADD:
19626 new_inst = T2_OPCODE_SUB;
19627 value = negated;
19628 break;
19629
19630 /* ORR <-> ORN. Includes MOV <-> MVN. */
19631 case T2_OPCODE_ORR:
19632 new_inst = T2_OPCODE_ORN;
19633 value = inverted;
19634 break;
19635
19636 case T2_OPCODE_ORN:
19637 new_inst = T2_OPCODE_ORR;
19638 value = inverted;
19639 break;
19640
19641 /* AND <-> BIC. TST has no inverted equivalent. */
19642 case T2_OPCODE_AND:
19643 new_inst = T2_OPCODE_BIC;
19644 if (rd == 15)
19645 value = FAIL;
19646 else
19647 value = inverted;
19648 break;
19649
19650 case T2_OPCODE_BIC:
19651 new_inst = T2_OPCODE_AND;
19652 value = inverted;
19653 break;
19654
19655 /* ADC <-> SBC */
19656 case T2_OPCODE_ADC:
19657 new_inst = T2_OPCODE_SBC;
19658 value = inverted;
19659 break;
19660
19661 case T2_OPCODE_SBC:
19662 new_inst = T2_OPCODE_ADC;
19663 value = inverted;
19664 break;
19665
19666 /* We cannot do anything. */
19667 default:
19668 return FAIL;
19669 }
19670
16dd5e42 19671 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19672 return FAIL;
19673
19674 *instruction &= T2_OPCODE_MASK;
19675 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19676 return value;
19677}
19678
8f06b2d8
PB
19679/* Read a 32-bit thumb instruction from buf. */
19680static unsigned long
19681get_thumb32_insn (char * buf)
19682{
19683 unsigned long insn;
19684 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19685 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19686
19687 return insn;
19688}
19689
a8bc6c78
PB
19690
19691/* We usually want to set the low bit on the address of thumb function
19692 symbols. In particular .word foo - . should have the low bit set.
19693 Generic code tries to fold the difference of two symbols to
19694 a constant. Prevent this and force a relocation when the first symbols
19695 is a thumb function. */
c921be7d
NC
19696
19697bfd_boolean
a8bc6c78
PB
19698arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19699{
19700 if (op == O_subtract
19701 && l->X_op == O_symbol
19702 && r->X_op == O_symbol
19703 && THUMB_IS_FUNC (l->X_add_symbol))
19704 {
19705 l->X_op = O_subtract;
19706 l->X_op_symbol = r->X_add_symbol;
19707 l->X_add_number -= r->X_add_number;
c921be7d 19708 return TRUE;
a8bc6c78 19709 }
c921be7d 19710
a8bc6c78 19711 /* Process as normal. */
c921be7d 19712 return FALSE;
a8bc6c78
PB
19713}
19714
4a42ebbc
RR
19715/* Encode Thumb2 unconditional branches and calls. The encoding
19716 for the 2 are identical for the immediate values. */
19717
19718static void
19719encode_thumb2_b_bl_offset (char * buf, offsetT value)
19720{
19721#define T2I1I2MASK ((1 << 13) | (1 << 11))
19722 offsetT newval;
19723 offsetT newval2;
19724 addressT S, I1, I2, lo, hi;
19725
19726 S = (value >> 24) & 0x01;
19727 I1 = (value >> 23) & 0x01;
19728 I2 = (value >> 22) & 0x01;
19729 hi = (value >> 12) & 0x3ff;
19730 lo = (value >> 1) & 0x7ff;
19731 newval = md_chars_to_number (buf, THUMB_SIZE);
19732 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19733 newval |= (S << 10) | hi;
19734 newval2 &= ~T2I1I2MASK;
19735 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19736 md_number_to_chars (buf, newval, THUMB_SIZE);
19737 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19738}
19739
c19d1205 19740void
55cf6793 19741md_apply_fix (fixS * fixP,
c19d1205
ZW
19742 valueT * valP,
19743 segT seg)
19744{
19745 offsetT value = * valP;
19746 offsetT newval;
19747 unsigned int newimm;
19748 unsigned long temp;
19749 int sign;
19750 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19751
9c2799c2 19752 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19753
c19d1205 19754 /* Note whether this will delete the relocation. */
4962c51a 19755
c19d1205
ZW
19756 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19757 fixP->fx_done = 1;
b99bd4ef 19758
adbaf948 19759 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19760 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19761 for emit_reloc. */
19762 value &= 0xffffffff;
19763 value ^= 0x80000000;
5f4273c7 19764 value -= 0x80000000;
adbaf948
ZW
19765
19766 *valP = value;
c19d1205 19767 fixP->fx_addnumber = value;
b99bd4ef 19768
adbaf948
ZW
19769 /* Same treatment for fixP->fx_offset. */
19770 fixP->fx_offset &= 0xffffffff;
19771 fixP->fx_offset ^= 0x80000000;
19772 fixP->fx_offset -= 0x80000000;
19773
c19d1205 19774 switch (fixP->fx_r_type)
b99bd4ef 19775 {
c19d1205
ZW
19776 case BFD_RELOC_NONE:
19777 /* This will need to go in the object file. */
19778 fixP->fx_done = 0;
19779 break;
b99bd4ef 19780
c19d1205
ZW
19781 case BFD_RELOC_ARM_IMMEDIATE:
19782 /* We claim that this fixup has been processed here,
19783 even if in fact we generate an error because we do
19784 not have a reloc for it, so tc_gen_reloc will reject it. */
19785 fixP->fx_done = 1;
b99bd4ef 19786
77db8e2e 19787 if (fixP->fx_addsy)
b99bd4ef 19788 {
77db8e2e 19789 const char *msg = 0;
b99bd4ef 19790
77db8e2e
NC
19791 if (! S_IS_DEFINED (fixP->fx_addsy))
19792 msg = _("undefined symbol %s used as an immediate value");
19793 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19794 msg = _("symbol %s is in a different section");
19795 else if (S_IS_WEAK (fixP->fx_addsy))
19796 msg = _("symbol %s is weak and may be overridden later");
19797
19798 if (msg)
19799 {
19800 as_bad_where (fixP->fx_file, fixP->fx_line,
19801 msg, S_GET_NAME (fixP->fx_addsy));
19802 break;
19803 }
42e5fcbf
AS
19804 }
19805
c19d1205
ZW
19806 newimm = encode_arm_immediate (value);
19807 temp = md_chars_to_number (buf, INSN_SIZE);
19808
19809 /* If the instruction will fail, see if we can fix things up by
19810 changing the opcode. */
19811 if (newimm == (unsigned int) FAIL
19812 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19813 {
c19d1205
ZW
19814 as_bad_where (fixP->fx_file, fixP->fx_line,
19815 _("invalid constant (%lx) after fixup"),
19816 (unsigned long) value);
19817 break;
b99bd4ef 19818 }
b99bd4ef 19819
c19d1205
ZW
19820 newimm |= (temp & 0xfffff000);
19821 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19822 break;
b99bd4ef 19823
c19d1205
ZW
19824 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19825 {
19826 unsigned int highpart = 0;
19827 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19828
77db8e2e 19829 if (fixP->fx_addsy)
42e5fcbf 19830 {
77db8e2e 19831 const char *msg = 0;
42e5fcbf 19832
77db8e2e
NC
19833 if (! S_IS_DEFINED (fixP->fx_addsy))
19834 msg = _("undefined symbol %s used as an immediate value");
19835 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19836 msg = _("symbol %s is in a different section");
19837 else if (S_IS_WEAK (fixP->fx_addsy))
19838 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 19839
77db8e2e
NC
19840 if (msg)
19841 {
19842 as_bad_where (fixP->fx_file, fixP->fx_line,
19843 msg, S_GET_NAME (fixP->fx_addsy));
19844 break;
19845 }
19846 }
19847
c19d1205
ZW
19848 newimm = encode_arm_immediate (value);
19849 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19850
c19d1205
ZW
19851 /* If the instruction will fail, see if we can fix things up by
19852 changing the opcode. */
19853 if (newimm == (unsigned int) FAIL
19854 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19855 {
19856 /* No ? OK - try using two ADD instructions to generate
19857 the value. */
19858 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19859
c19d1205
ZW
19860 /* Yes - then make sure that the second instruction is
19861 also an add. */
19862 if (newimm != (unsigned int) FAIL)
19863 newinsn = temp;
19864 /* Still No ? Try using a negated value. */
19865 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19866 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19867 /* Otherwise - give up. */
19868 else
19869 {
19870 as_bad_where (fixP->fx_file, fixP->fx_line,
19871 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19872 (long) value);
19873 break;
19874 }
b99bd4ef 19875
c19d1205
ZW
19876 /* Replace the first operand in the 2nd instruction (which
19877 is the PC) with the destination register. We have
19878 already added in the PC in the first instruction and we
19879 do not want to do it again. */
19880 newinsn &= ~ 0xf0000;
19881 newinsn |= ((newinsn & 0x0f000) << 4);
19882 }
b99bd4ef 19883
c19d1205
ZW
19884 newimm |= (temp & 0xfffff000);
19885 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19886
c19d1205
ZW
19887 highpart |= (newinsn & 0xfffff000);
19888 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19889 }
19890 break;
b99bd4ef 19891
c19d1205 19892 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19893 if (!fixP->fx_done && seg->use_rela_p)
19894 value = 0;
19895
c19d1205
ZW
19896 case BFD_RELOC_ARM_LITERAL:
19897 sign = value >= 0;
b99bd4ef 19898
c19d1205
ZW
19899 if (value < 0)
19900 value = - value;
b99bd4ef 19901
c19d1205 19902 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19903 {
c19d1205
ZW
19904 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19905 as_bad_where (fixP->fx_file, fixP->fx_line,
19906 _("invalid literal constant: pool needs to be closer"));
19907 else
19908 as_bad_where (fixP->fx_file, fixP->fx_line,
19909 _("bad immediate value for offset (%ld)"),
19910 (long) value);
19911 break;
f03698e6
RE
19912 }
19913
c19d1205
ZW
19914 newval = md_chars_to_number (buf, INSN_SIZE);
19915 newval &= 0xff7ff000;
19916 newval |= value | (sign ? INDEX_UP : 0);
19917 md_number_to_chars (buf, newval, INSN_SIZE);
19918 break;
b99bd4ef 19919
c19d1205
ZW
19920 case BFD_RELOC_ARM_OFFSET_IMM8:
19921 case BFD_RELOC_ARM_HWLITERAL:
19922 sign = value >= 0;
b99bd4ef 19923
c19d1205
ZW
19924 if (value < 0)
19925 value = - value;
b99bd4ef 19926
c19d1205 19927 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19928 {
c19d1205
ZW
19929 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19930 as_bad_where (fixP->fx_file, fixP->fx_line,
19931 _("invalid literal constant: pool needs to be closer"));
19932 else
f9d4405b 19933 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19934 (long) value);
19935 break;
b99bd4ef
NC
19936 }
19937
c19d1205
ZW
19938 newval = md_chars_to_number (buf, INSN_SIZE);
19939 newval &= 0xff7ff0f0;
19940 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19941 md_number_to_chars (buf, newval, INSN_SIZE);
19942 break;
b99bd4ef 19943
c19d1205
ZW
19944 case BFD_RELOC_ARM_T32_OFFSET_U8:
19945 if (value < 0 || value > 1020 || value % 4 != 0)
19946 as_bad_where (fixP->fx_file, fixP->fx_line,
19947 _("bad immediate value for offset (%ld)"), (long) value);
19948 value /= 4;
b99bd4ef 19949
c19d1205 19950 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19951 newval |= value;
19952 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19953 break;
b99bd4ef 19954
c19d1205
ZW
19955 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19956 /* This is a complicated relocation used for all varieties of Thumb32
19957 load/store instruction with immediate offset:
19958
19959 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19960 *4, optional writeback(W)
19961 (doubleword load/store)
19962
19963 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19964 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19965 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19966 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19967 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19968
19969 Uppercase letters indicate bits that are already encoded at
19970 this point. Lowercase letters are our problem. For the
19971 second block of instructions, the secondary opcode nybble
19972 (bits 8..11) is present, and bit 23 is zero, even if this is
19973 a PC-relative operation. */
19974 newval = md_chars_to_number (buf, THUMB_SIZE);
19975 newval <<= 16;
19976 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19977
c19d1205 19978 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19979 {
c19d1205
ZW
19980 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19981 if (value >= 0)
19982 newval |= (1 << 23);
19983 else
19984 value = -value;
19985 if (value % 4 != 0)
19986 {
19987 as_bad_where (fixP->fx_file, fixP->fx_line,
19988 _("offset not a multiple of 4"));
19989 break;
19990 }
19991 value /= 4;
216d22bc 19992 if (value > 0xff)
c19d1205
ZW
19993 {
19994 as_bad_where (fixP->fx_file, fixP->fx_line,
19995 _("offset out of range"));
19996 break;
19997 }
19998 newval &= ~0xff;
b99bd4ef 19999 }
c19d1205 20000 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20001 {
c19d1205
ZW
20002 /* PC-relative, 12-bit offset. */
20003 if (value >= 0)
20004 newval |= (1 << 23);
20005 else
20006 value = -value;
216d22bc 20007 if (value > 0xfff)
c19d1205
ZW
20008 {
20009 as_bad_where (fixP->fx_file, fixP->fx_line,
20010 _("offset out of range"));
20011 break;
20012 }
20013 newval &= ~0xfff;
b99bd4ef 20014 }
c19d1205 20015 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20016 {
c19d1205
ZW
20017 /* Writeback: 8-bit, +/- offset. */
20018 if (value >= 0)
20019 newval |= (1 << 9);
20020 else
20021 value = -value;
216d22bc 20022 if (value > 0xff)
c19d1205
ZW
20023 {
20024 as_bad_where (fixP->fx_file, fixP->fx_line,
20025 _("offset out of range"));
20026 break;
20027 }
20028 newval &= ~0xff;
b99bd4ef 20029 }
c19d1205 20030 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20031 {
c19d1205 20032 /* T-instruction: positive 8-bit offset. */
216d22bc 20033 if (value < 0 || value > 0xff)
b99bd4ef 20034 {
c19d1205
ZW
20035 as_bad_where (fixP->fx_file, fixP->fx_line,
20036 _("offset out of range"));
20037 break;
b99bd4ef 20038 }
c19d1205
ZW
20039 newval &= ~0xff;
20040 newval |= value;
b99bd4ef
NC
20041 }
20042 else
b99bd4ef 20043 {
c19d1205
ZW
20044 /* Positive 12-bit or negative 8-bit offset. */
20045 int limit;
20046 if (value >= 0)
b99bd4ef 20047 {
c19d1205
ZW
20048 newval |= (1 << 23);
20049 limit = 0xfff;
20050 }
20051 else
20052 {
20053 value = -value;
20054 limit = 0xff;
20055 }
20056 if (value > limit)
20057 {
20058 as_bad_where (fixP->fx_file, fixP->fx_line,
20059 _("offset out of range"));
20060 break;
b99bd4ef 20061 }
c19d1205 20062 newval &= ~limit;
b99bd4ef 20063 }
b99bd4ef 20064
c19d1205
ZW
20065 newval |= value;
20066 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20067 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20068 break;
404ff6b5 20069
c19d1205
ZW
20070 case BFD_RELOC_ARM_SHIFT_IMM:
20071 newval = md_chars_to_number (buf, INSN_SIZE);
20072 if (((unsigned long) value) > 32
20073 || (value == 32
20074 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20075 {
20076 as_bad_where (fixP->fx_file, fixP->fx_line,
20077 _("shift expression is too large"));
20078 break;
20079 }
404ff6b5 20080
c19d1205
ZW
20081 if (value == 0)
20082 /* Shifts of zero must be done as lsl. */
20083 newval &= ~0x60;
20084 else if (value == 32)
20085 value = 0;
20086 newval &= 0xfffff07f;
20087 newval |= (value & 0x1f) << 7;
20088 md_number_to_chars (buf, newval, INSN_SIZE);
20089 break;
404ff6b5 20090
c19d1205 20091 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20092 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20093 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20094 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20095 /* We claim that this fixup has been processed here,
20096 even if in fact we generate an error because we do
20097 not have a reloc for it, so tc_gen_reloc will reject it. */
20098 fixP->fx_done = 1;
404ff6b5 20099
c19d1205
ZW
20100 if (fixP->fx_addsy
20101 && ! S_IS_DEFINED (fixP->fx_addsy))
20102 {
20103 as_bad_where (fixP->fx_file, fixP->fx_line,
20104 _("undefined symbol %s used as an immediate value"),
20105 S_GET_NAME (fixP->fx_addsy));
20106 break;
20107 }
404ff6b5 20108
c19d1205
ZW
20109 newval = md_chars_to_number (buf, THUMB_SIZE);
20110 newval <<= 16;
20111 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20112
16805f35
PB
20113 newimm = FAIL;
20114 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20115 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20116 {
20117 newimm = encode_thumb32_immediate (value);
20118 if (newimm == (unsigned int) FAIL)
20119 newimm = thumb32_negate_data_op (&newval, value);
20120 }
16805f35
PB
20121 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20122 && newimm == (unsigned int) FAIL)
92e90b6e 20123 {
16805f35
PB
20124 /* Turn add/sum into addw/subw. */
20125 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20126 newval = (newval & 0xfeffffff) | 0x02000000;
20127
e9f89963
PB
20128 /* 12 bit immediate for addw/subw. */
20129 if (value < 0)
20130 {
20131 value = -value;
20132 newval ^= 0x00a00000;
20133 }
92e90b6e
PB
20134 if (value > 0xfff)
20135 newimm = (unsigned int) FAIL;
20136 else
20137 newimm = value;
20138 }
cc8a6dd0 20139
c19d1205 20140 if (newimm == (unsigned int)FAIL)
3631a3c8 20141 {
c19d1205
ZW
20142 as_bad_where (fixP->fx_file, fixP->fx_line,
20143 _("invalid constant (%lx) after fixup"),
20144 (unsigned long) value);
20145 break;
3631a3c8
NC
20146 }
20147
c19d1205
ZW
20148 newval |= (newimm & 0x800) << 15;
20149 newval |= (newimm & 0x700) << 4;
20150 newval |= (newimm & 0x0ff);
cc8a6dd0 20151
c19d1205
ZW
20152 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20153 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20154 break;
a737bd4d 20155
3eb17e6b 20156 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20157 if (((unsigned long) value) > 0xffff)
20158 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20159 _("invalid smc expression"));
2fc8bdac 20160 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20161 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20162 md_number_to_chars (buf, newval, INSN_SIZE);
20163 break;
a737bd4d 20164
c19d1205 20165 case BFD_RELOC_ARM_SWI:
adbaf948 20166 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20167 {
20168 if (((unsigned long) value) > 0xff)
20169 as_bad_where (fixP->fx_file, fixP->fx_line,
20170 _("invalid swi expression"));
2fc8bdac 20171 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20172 newval |= value;
20173 md_number_to_chars (buf, newval, THUMB_SIZE);
20174 }
20175 else
20176 {
20177 if (((unsigned long) value) > 0x00ffffff)
20178 as_bad_where (fixP->fx_file, fixP->fx_line,
20179 _("invalid swi expression"));
2fc8bdac 20180 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20181 newval |= value;
20182 md_number_to_chars (buf, newval, INSN_SIZE);
20183 }
20184 break;
a737bd4d 20185
c19d1205
ZW
20186 case BFD_RELOC_ARM_MULTI:
20187 if (((unsigned long) value) > 0xffff)
20188 as_bad_where (fixP->fx_file, fixP->fx_line,
20189 _("invalid expression in load/store multiple"));
20190 newval = value | md_chars_to_number (buf, INSN_SIZE);
20191 md_number_to_chars (buf, newval, INSN_SIZE);
20192 break;
a737bd4d 20193
c19d1205 20194#ifdef OBJ_ELF
39b41c9c 20195 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20196
20197 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20198 && fixP->fx_addsy
20199 && !S_IS_EXTERNAL (fixP->fx_addsy)
20200 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20201 && THUMB_IS_FUNC (fixP->fx_addsy))
20202 /* Flip the bl to blx. This is a simple flip
20203 bit here because we generate PCREL_CALL for
20204 unconditional bls. */
20205 {
20206 newval = md_chars_to_number (buf, INSN_SIZE);
20207 newval = newval | 0x10000000;
20208 md_number_to_chars (buf, newval, INSN_SIZE);
20209 temp = 1;
20210 fixP->fx_done = 1;
20211 }
39b41c9c
PB
20212 else
20213 temp = 3;
20214 goto arm_branch_common;
20215
20216 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20217 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20218 && fixP->fx_addsy
20219 && !S_IS_EXTERNAL (fixP->fx_addsy)
20220 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20221 && THUMB_IS_FUNC (fixP->fx_addsy))
20222 {
20223 /* This would map to a bl<cond>, b<cond>,
20224 b<always> to a Thumb function. We
20225 need to force a relocation for this particular
20226 case. */
20227 newval = md_chars_to_number (buf, INSN_SIZE);
20228 fixP->fx_done = 0;
20229 }
20230
2fc8bdac 20231 case BFD_RELOC_ARM_PLT32:
c19d1205 20232#endif
39b41c9c
PB
20233 case BFD_RELOC_ARM_PCREL_BRANCH:
20234 temp = 3;
20235 goto arm_branch_common;
a737bd4d 20236
39b41c9c 20237 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20238
39b41c9c 20239 temp = 1;
267bf995
RR
20240 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20241 && fixP->fx_addsy
20242 && !S_IS_EXTERNAL (fixP->fx_addsy)
20243 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20244 && ARM_IS_FUNC (fixP->fx_addsy))
20245 {
20246 /* Flip the blx to a bl and warn. */
20247 const char *name = S_GET_NAME (fixP->fx_addsy);
20248 newval = 0xeb000000;
20249 as_warn_where (fixP->fx_file, fixP->fx_line,
20250 _("blx to '%s' an ARM ISA state function changed to bl"),
20251 name);
20252 md_number_to_chars (buf, newval, INSN_SIZE);
20253 temp = 3;
20254 fixP->fx_done = 1;
20255 }
20256
20257#ifdef OBJ_ELF
20258 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20259 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20260#endif
20261
39b41c9c 20262 arm_branch_common:
c19d1205 20263 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20264 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20265 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20266 also be be clear. */
20267 if (value & temp)
c19d1205 20268 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20269 _("misaligned branch destination"));
20270 if ((value & (offsetT)0xfe000000) != (offsetT)0
20271 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20272 as_bad_where (fixP->fx_file, fixP->fx_line,
20273 _("branch out of range"));
a737bd4d 20274
2fc8bdac 20275 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20276 {
2fc8bdac
ZW
20277 newval = md_chars_to_number (buf, INSN_SIZE);
20278 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20279 /* Set the H bit on BLX instructions. */
20280 if (temp == 1)
20281 {
20282 if (value & 2)
20283 newval |= 0x01000000;
20284 else
20285 newval &= ~0x01000000;
20286 }
2fc8bdac 20287 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20288 }
c19d1205 20289 break;
a737bd4d 20290
25fe350b
MS
20291 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20292 /* CBZ can only branch forward. */
a737bd4d 20293
738755b0
MS
20294 /* Attempts to use CBZ to branch to the next instruction
20295 (which, strictly speaking, are prohibited) will be turned into
20296 no-ops.
20297
20298 FIXME: It may be better to remove the instruction completely and
20299 perform relaxation. */
20300 if (value == -2)
2fc8bdac
ZW
20301 {
20302 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20303 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20304 md_number_to_chars (buf, newval, THUMB_SIZE);
20305 }
738755b0
MS
20306 else
20307 {
20308 if (value & ~0x7e)
20309 as_bad_where (fixP->fx_file, fixP->fx_line,
20310 _("branch out of range"));
20311
20312 if (fixP->fx_done || !seg->use_rela_p)
20313 {
20314 newval = md_chars_to_number (buf, THUMB_SIZE);
20315 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20316 md_number_to_chars (buf, newval, THUMB_SIZE);
20317 }
20318 }
c19d1205 20319 break;
a737bd4d 20320
c19d1205 20321 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20322 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20323 as_bad_where (fixP->fx_file, fixP->fx_line,
20324 _("branch out of range"));
a737bd4d 20325
2fc8bdac
ZW
20326 if (fixP->fx_done || !seg->use_rela_p)
20327 {
20328 newval = md_chars_to_number (buf, THUMB_SIZE);
20329 newval |= (value & 0x1ff) >> 1;
20330 md_number_to_chars (buf, newval, THUMB_SIZE);
20331 }
c19d1205 20332 break;
a737bd4d 20333
c19d1205 20334 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20335 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20336 as_bad_where (fixP->fx_file, fixP->fx_line,
20337 _("branch out of range"));
a737bd4d 20338
2fc8bdac
ZW
20339 if (fixP->fx_done || !seg->use_rela_p)
20340 {
20341 newval = md_chars_to_number (buf, THUMB_SIZE);
20342 newval |= (value & 0xfff) >> 1;
20343 md_number_to_chars (buf, newval, THUMB_SIZE);
20344 }
c19d1205 20345 break;
a737bd4d 20346
c19d1205 20347 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20348 if (fixP->fx_addsy
20349 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20350 && !S_IS_EXTERNAL (fixP->fx_addsy)
20351 && S_IS_DEFINED (fixP->fx_addsy)
20352 && ARM_IS_FUNC (fixP->fx_addsy)
20353 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20354 {
20355 /* Force a relocation for a branch 20 bits wide. */
20356 fixP->fx_done = 0;
20357 }
2fc8bdac
ZW
20358 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20359 as_bad_where (fixP->fx_file, fixP->fx_line,
20360 _("conditional branch out of range"));
404ff6b5 20361
2fc8bdac
ZW
20362 if (fixP->fx_done || !seg->use_rela_p)
20363 {
20364 offsetT newval2;
20365 addressT S, J1, J2, lo, hi;
404ff6b5 20366
2fc8bdac
ZW
20367 S = (value & 0x00100000) >> 20;
20368 J2 = (value & 0x00080000) >> 19;
20369 J1 = (value & 0x00040000) >> 18;
20370 hi = (value & 0x0003f000) >> 12;
20371 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20372
2fc8bdac
ZW
20373 newval = md_chars_to_number (buf, THUMB_SIZE);
20374 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20375 newval |= (S << 10) | hi;
20376 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20377 md_number_to_chars (buf, newval, THUMB_SIZE);
20378 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20379 }
c19d1205 20380 break;
6c43fab6 20381
c19d1205 20382 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20383
20384 /* If there is a blx from a thumb state function to
20385 another thumb function flip this to a bl and warn
20386 about it. */
20387
20388 if (fixP->fx_addsy
20389 && S_IS_DEFINED (fixP->fx_addsy)
20390 && !S_IS_EXTERNAL (fixP->fx_addsy)
20391 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20392 && THUMB_IS_FUNC (fixP->fx_addsy))
20393 {
20394 const char *name = S_GET_NAME (fixP->fx_addsy);
20395 as_warn_where (fixP->fx_file, fixP->fx_line,
20396 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20397 name);
20398 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20399 newval = newval | 0x1000;
20400 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20401 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20402 fixP->fx_done = 1;
20403 }
20404
20405
20406 goto thumb_bl_common;
20407
c19d1205 20408 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20409
20410 /* A bl from Thumb state ISA to an internal ARM state function
20411 is converted to a blx. */
20412 if (fixP->fx_addsy
20413 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20414 && !S_IS_EXTERNAL (fixP->fx_addsy)
20415 && S_IS_DEFINED (fixP->fx_addsy)
20416 && ARM_IS_FUNC (fixP->fx_addsy)
20417 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20418 {
20419 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20420 newval = newval & ~0x1000;
20421 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20422 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20423 fixP->fx_done = 1;
20424 }
20425
20426 thumb_bl_common:
20427
20428#ifdef OBJ_ELF
20429 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20430 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20431 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20432#endif
20433
2fc8bdac
ZW
20434 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20435 /* For a BLX instruction, make sure that the relocation is rounded up
20436 to a word boundary. This follows the semantics of the instruction
20437 which specifies that bit 1 of the target address will come from bit
20438 1 of the base address. */
20439 value = (value + 1) & ~ 1;
404ff6b5 20440
2fc8bdac 20441
4a42ebbc
RR
20442 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20443 {
20444 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20445 {
20446 as_bad_where (fixP->fx_file, fixP->fx_line,
20447 _("branch out of range"));
20448 }
20449 else if ((value & ~0x1ffffff)
20450 && ((value & ~0x1ffffff) != ~0x1ffffff))
20451 {
20452 as_bad_where (fixP->fx_file, fixP->fx_line,
20453 _("Thumb2 branch out of range"));
20454 }
c19d1205 20455 }
4a42ebbc
RR
20456
20457 if (fixP->fx_done || !seg->use_rela_p)
20458 encode_thumb2_b_bl_offset (buf, value);
20459
c19d1205 20460 break;
404ff6b5 20461
c19d1205 20462 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20463 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20464 as_bad_where (fixP->fx_file, fixP->fx_line,
20465 _("branch out of range"));
6c43fab6 20466
2fc8bdac 20467 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20468 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20469
2fc8bdac 20470 break;
a737bd4d 20471
2fc8bdac
ZW
20472 case BFD_RELOC_8:
20473 if (fixP->fx_done || !seg->use_rela_p)
20474 md_number_to_chars (buf, value, 1);
c19d1205 20475 break;
a737bd4d 20476
c19d1205 20477 case BFD_RELOC_16:
2fc8bdac 20478 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20479 md_number_to_chars (buf, value, 2);
c19d1205 20480 break;
a737bd4d 20481
c19d1205
ZW
20482#ifdef OBJ_ELF
20483 case BFD_RELOC_ARM_TLS_GD32:
20484 case BFD_RELOC_ARM_TLS_LE32:
20485 case BFD_RELOC_ARM_TLS_IE32:
20486 case BFD_RELOC_ARM_TLS_LDM32:
20487 case BFD_RELOC_ARM_TLS_LDO32:
20488 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20489 /* fall through */
6c43fab6 20490
c19d1205
ZW
20491 case BFD_RELOC_ARM_GOT32:
20492 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20493 if (fixP->fx_done || !seg->use_rela_p)
20494 md_number_to_chars (buf, 0, 4);
c19d1205 20495 break;
b43420e6
NC
20496
20497 case BFD_RELOC_ARM_GOT_PREL:
20498 if (fixP->fx_done || !seg->use_rela_p)
20499 md_number_to_chars (buf, value, 4);
20500 break;
20501
9a6f4e97
NS
20502 case BFD_RELOC_ARM_TARGET2:
20503 /* TARGET2 is not partial-inplace, so we need to write the
20504 addend here for REL targets, because it won't be written out
20505 during reloc processing later. */
20506 if (fixP->fx_done || !seg->use_rela_p)
20507 md_number_to_chars (buf, fixP->fx_offset, 4);
20508 break;
c19d1205 20509#endif
6c43fab6 20510
c19d1205
ZW
20511 case BFD_RELOC_RVA:
20512 case BFD_RELOC_32:
20513 case BFD_RELOC_ARM_TARGET1:
20514 case BFD_RELOC_ARM_ROSEGREL32:
20515 case BFD_RELOC_ARM_SBREL32:
20516 case BFD_RELOC_32_PCREL:
f0927246
NC
20517#ifdef TE_PE
20518 case BFD_RELOC_32_SECREL:
20519#endif
2fc8bdac 20520 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20521#ifdef TE_WINCE
20522 /* For WinCE we only do this for pcrel fixups. */
20523 if (fixP->fx_done || fixP->fx_pcrel)
20524#endif
20525 md_number_to_chars (buf, value, 4);
c19d1205 20526 break;
6c43fab6 20527
c19d1205
ZW
20528#ifdef OBJ_ELF
20529 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20530 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20531 {
20532 newval = md_chars_to_number (buf, 4) & 0x80000000;
20533 if ((value ^ (value >> 1)) & 0x40000000)
20534 {
20535 as_bad_where (fixP->fx_file, fixP->fx_line,
20536 _("rel31 relocation overflow"));
20537 }
20538 newval |= value & 0x7fffffff;
20539 md_number_to_chars (buf, newval, 4);
20540 }
20541 break;
c19d1205 20542#endif
a737bd4d 20543
c19d1205 20544 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20545 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20546 if (value < -1023 || value > 1023 || (value & 3))
20547 as_bad_where (fixP->fx_file, fixP->fx_line,
20548 _("co-processor offset out of range"));
20549 cp_off_common:
20550 sign = value >= 0;
20551 if (value < 0)
20552 value = -value;
8f06b2d8
PB
20553 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20554 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20555 newval = md_chars_to_number (buf, INSN_SIZE);
20556 else
20557 newval = get_thumb32_insn (buf);
20558 newval &= 0xff7fff00;
c19d1205 20559 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20560 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20561 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20562 md_number_to_chars (buf, newval, INSN_SIZE);
20563 else
20564 put_thumb32_insn (buf, newval);
c19d1205 20565 break;
a737bd4d 20566
c19d1205 20567 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20568 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20569 if (value < -255 || value > 255)
20570 as_bad_where (fixP->fx_file, fixP->fx_line,
20571 _("co-processor offset out of range"));
df7849c5 20572 value *= 4;
c19d1205 20573 goto cp_off_common;
6c43fab6 20574
c19d1205
ZW
20575 case BFD_RELOC_ARM_THUMB_OFFSET:
20576 newval = md_chars_to_number (buf, THUMB_SIZE);
20577 /* Exactly what ranges, and where the offset is inserted depends
20578 on the type of instruction, we can establish this from the
20579 top 4 bits. */
20580 switch (newval >> 12)
20581 {
20582 case 4: /* PC load. */
20583 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20584 forced to zero for these loads; md_pcrel_from has already
20585 compensated for this. */
20586 if (value & 3)
20587 as_bad_where (fixP->fx_file, fixP->fx_line,
20588 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20589 (((unsigned long) fixP->fx_frag->fr_address
20590 + (unsigned long) fixP->fx_where) & ~3)
20591 + (unsigned long) value);
a737bd4d 20592
c19d1205
ZW
20593 if (value & ~0x3fc)
20594 as_bad_where (fixP->fx_file, fixP->fx_line,
20595 _("invalid offset, value too big (0x%08lX)"),
20596 (long) value);
a737bd4d 20597
c19d1205
ZW
20598 newval |= value >> 2;
20599 break;
a737bd4d 20600
c19d1205
ZW
20601 case 9: /* SP load/store. */
20602 if (value & ~0x3fc)
20603 as_bad_where (fixP->fx_file, fixP->fx_line,
20604 _("invalid offset, value too big (0x%08lX)"),
20605 (long) value);
20606 newval |= value >> 2;
20607 break;
6c43fab6 20608
c19d1205
ZW
20609 case 6: /* Word load/store. */
20610 if (value & ~0x7c)
20611 as_bad_where (fixP->fx_file, fixP->fx_line,
20612 _("invalid offset, value too big (0x%08lX)"),
20613 (long) value);
20614 newval |= value << 4; /* 6 - 2. */
20615 break;
a737bd4d 20616
c19d1205
ZW
20617 case 7: /* Byte load/store. */
20618 if (value & ~0x1f)
20619 as_bad_where (fixP->fx_file, fixP->fx_line,
20620 _("invalid offset, value too big (0x%08lX)"),
20621 (long) value);
20622 newval |= value << 6;
20623 break;
a737bd4d 20624
c19d1205
ZW
20625 case 8: /* Halfword load/store. */
20626 if (value & ~0x3e)
20627 as_bad_where (fixP->fx_file, fixP->fx_line,
20628 _("invalid offset, value too big (0x%08lX)"),
20629 (long) value);
20630 newval |= value << 5; /* 6 - 1. */
20631 break;
a737bd4d 20632
c19d1205
ZW
20633 default:
20634 as_bad_where (fixP->fx_file, fixP->fx_line,
20635 "Unable to process relocation for thumb opcode: %lx",
20636 (unsigned long) newval);
20637 break;
20638 }
20639 md_number_to_chars (buf, newval, THUMB_SIZE);
20640 break;
a737bd4d 20641
c19d1205
ZW
20642 case BFD_RELOC_ARM_THUMB_ADD:
20643 /* This is a complicated relocation, since we use it for all of
20644 the following immediate relocations:
a737bd4d 20645
c19d1205
ZW
20646 3bit ADD/SUB
20647 8bit ADD/SUB
20648 9bit ADD/SUB SP word-aligned
20649 10bit ADD PC/SP word-aligned
a737bd4d 20650
c19d1205
ZW
20651 The type of instruction being processed is encoded in the
20652 instruction field:
a737bd4d 20653
c19d1205
ZW
20654 0x8000 SUB
20655 0x00F0 Rd
20656 0x000F Rs
20657 */
20658 newval = md_chars_to_number (buf, THUMB_SIZE);
20659 {
20660 int rd = (newval >> 4) & 0xf;
20661 int rs = newval & 0xf;
20662 int subtract = !!(newval & 0x8000);
a737bd4d 20663
c19d1205
ZW
20664 /* Check for HI regs, only very restricted cases allowed:
20665 Adjusting SP, and using PC or SP to get an address. */
20666 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20667 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20668 as_bad_where (fixP->fx_file, fixP->fx_line,
20669 _("invalid Hi register with immediate"));
a737bd4d 20670
c19d1205
ZW
20671 /* If value is negative, choose the opposite instruction. */
20672 if (value < 0)
20673 {
20674 value = -value;
20675 subtract = !subtract;
20676 if (value < 0)
20677 as_bad_where (fixP->fx_file, fixP->fx_line,
20678 _("immediate value out of range"));
20679 }
a737bd4d 20680
c19d1205
ZW
20681 if (rd == REG_SP)
20682 {
20683 if (value & ~0x1fc)
20684 as_bad_where (fixP->fx_file, fixP->fx_line,
20685 _("invalid immediate for stack address calculation"));
20686 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20687 newval |= value >> 2;
20688 }
20689 else if (rs == REG_PC || rs == REG_SP)
20690 {
20691 if (subtract || value & ~0x3fc)
20692 as_bad_where (fixP->fx_file, fixP->fx_line,
20693 _("invalid immediate for address calculation (value = 0x%08lX)"),
20694 (unsigned long) value);
20695 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20696 newval |= rd << 8;
20697 newval |= value >> 2;
20698 }
20699 else if (rs == rd)
20700 {
20701 if (value & ~0xff)
20702 as_bad_where (fixP->fx_file, fixP->fx_line,
20703 _("immediate value out of range"));
20704 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20705 newval |= (rd << 8) | value;
20706 }
20707 else
20708 {
20709 if (value & ~0x7)
20710 as_bad_where (fixP->fx_file, fixP->fx_line,
20711 _("immediate value out of range"));
20712 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20713 newval |= rd | (rs << 3) | (value << 6);
20714 }
20715 }
20716 md_number_to_chars (buf, newval, THUMB_SIZE);
20717 break;
a737bd4d 20718
c19d1205
ZW
20719 case BFD_RELOC_ARM_THUMB_IMM:
20720 newval = md_chars_to_number (buf, THUMB_SIZE);
20721 if (value < 0 || value > 255)
20722 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20723 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20724 (long) value);
20725 newval |= value;
20726 md_number_to_chars (buf, newval, THUMB_SIZE);
20727 break;
a737bd4d 20728
c19d1205
ZW
20729 case BFD_RELOC_ARM_THUMB_SHIFT:
20730 /* 5bit shift value (0..32). LSL cannot take 32. */
20731 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20732 temp = newval & 0xf800;
20733 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20734 as_bad_where (fixP->fx_file, fixP->fx_line,
20735 _("invalid shift value: %ld"), (long) value);
20736 /* Shifts of zero must be encoded as LSL. */
20737 if (value == 0)
20738 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20739 /* Shifts of 32 are encoded as zero. */
20740 else if (value == 32)
20741 value = 0;
20742 newval |= value << 6;
20743 md_number_to_chars (buf, newval, THUMB_SIZE);
20744 break;
a737bd4d 20745
c19d1205
ZW
20746 case BFD_RELOC_VTABLE_INHERIT:
20747 case BFD_RELOC_VTABLE_ENTRY:
20748 fixP->fx_done = 0;
20749 return;
6c43fab6 20750
b6895b4f
PB
20751 case BFD_RELOC_ARM_MOVW:
20752 case BFD_RELOC_ARM_MOVT:
20753 case BFD_RELOC_ARM_THUMB_MOVW:
20754 case BFD_RELOC_ARM_THUMB_MOVT:
20755 if (fixP->fx_done || !seg->use_rela_p)
20756 {
20757 /* REL format relocations are limited to a 16-bit addend. */
20758 if (!fixP->fx_done)
20759 {
39623e12 20760 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20761 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20762 _("offset out of range"));
b6895b4f
PB
20763 }
20764 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20765 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20766 {
20767 value >>= 16;
20768 }
20769
20770 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20771 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20772 {
20773 newval = get_thumb32_insn (buf);
20774 newval &= 0xfbf08f00;
20775 newval |= (value & 0xf000) << 4;
20776 newval |= (value & 0x0800) << 15;
20777 newval |= (value & 0x0700) << 4;
20778 newval |= (value & 0x00ff);
20779 put_thumb32_insn (buf, newval);
20780 }
20781 else
20782 {
20783 newval = md_chars_to_number (buf, 4);
20784 newval &= 0xfff0f000;
20785 newval |= value & 0x0fff;
20786 newval |= (value & 0xf000) << 4;
20787 md_number_to_chars (buf, newval, 4);
20788 }
20789 }
20790 return;
20791
4962c51a
MS
20792 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20793 case BFD_RELOC_ARM_ALU_PC_G0:
20794 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20795 case BFD_RELOC_ARM_ALU_PC_G1:
20796 case BFD_RELOC_ARM_ALU_PC_G2:
20797 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20798 case BFD_RELOC_ARM_ALU_SB_G0:
20799 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20800 case BFD_RELOC_ARM_ALU_SB_G1:
20801 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20802 gas_assert (!fixP->fx_done);
4962c51a
MS
20803 if (!seg->use_rela_p)
20804 {
20805 bfd_vma insn;
20806 bfd_vma encoded_addend;
20807 bfd_vma addend_abs = abs (value);
20808
20809 /* Check that the absolute value of the addend can be
20810 expressed as an 8-bit constant plus a rotation. */
20811 encoded_addend = encode_arm_immediate (addend_abs);
20812 if (encoded_addend == (unsigned int) FAIL)
20813 as_bad_where (fixP->fx_file, fixP->fx_line,
20814 _("the offset 0x%08lX is not representable"),
495bde8e 20815 (unsigned long) addend_abs);
4962c51a
MS
20816
20817 /* Extract the instruction. */
20818 insn = md_chars_to_number (buf, INSN_SIZE);
20819
20820 /* If the addend is positive, use an ADD instruction.
20821 Otherwise use a SUB. Take care not to destroy the S bit. */
20822 insn &= 0xff1fffff;
20823 if (value < 0)
20824 insn |= 1 << 22;
20825 else
20826 insn |= 1 << 23;
20827
20828 /* Place the encoded addend into the first 12 bits of the
20829 instruction. */
20830 insn &= 0xfffff000;
20831 insn |= encoded_addend;
5f4273c7
NC
20832
20833 /* Update the instruction. */
4962c51a
MS
20834 md_number_to_chars (buf, insn, INSN_SIZE);
20835 }
20836 break;
20837
20838 case BFD_RELOC_ARM_LDR_PC_G0:
20839 case BFD_RELOC_ARM_LDR_PC_G1:
20840 case BFD_RELOC_ARM_LDR_PC_G2:
20841 case BFD_RELOC_ARM_LDR_SB_G0:
20842 case BFD_RELOC_ARM_LDR_SB_G1:
20843 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20844 gas_assert (!fixP->fx_done);
4962c51a
MS
20845 if (!seg->use_rela_p)
20846 {
20847 bfd_vma insn;
20848 bfd_vma addend_abs = abs (value);
20849
20850 /* Check that the absolute value of the addend can be
20851 encoded in 12 bits. */
20852 if (addend_abs >= 0x1000)
20853 as_bad_where (fixP->fx_file, fixP->fx_line,
20854 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20855 (unsigned long) addend_abs);
4962c51a
MS
20856
20857 /* Extract the instruction. */
20858 insn = md_chars_to_number (buf, INSN_SIZE);
20859
20860 /* If the addend is negative, clear bit 23 of the instruction.
20861 Otherwise set it. */
20862 if (value < 0)
20863 insn &= ~(1 << 23);
20864 else
20865 insn |= 1 << 23;
20866
20867 /* Place the absolute value of the addend into the first 12 bits
20868 of the instruction. */
20869 insn &= 0xfffff000;
20870 insn |= addend_abs;
5f4273c7
NC
20871
20872 /* Update the instruction. */
4962c51a
MS
20873 md_number_to_chars (buf, insn, INSN_SIZE);
20874 }
20875 break;
20876
20877 case BFD_RELOC_ARM_LDRS_PC_G0:
20878 case BFD_RELOC_ARM_LDRS_PC_G1:
20879 case BFD_RELOC_ARM_LDRS_PC_G2:
20880 case BFD_RELOC_ARM_LDRS_SB_G0:
20881 case BFD_RELOC_ARM_LDRS_SB_G1:
20882 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20883 gas_assert (!fixP->fx_done);
4962c51a
MS
20884 if (!seg->use_rela_p)
20885 {
20886 bfd_vma insn;
20887 bfd_vma addend_abs = abs (value);
20888
20889 /* Check that the absolute value of the addend can be
20890 encoded in 8 bits. */
20891 if (addend_abs >= 0x100)
20892 as_bad_where (fixP->fx_file, fixP->fx_line,
20893 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20894 (unsigned long) addend_abs);
4962c51a
MS
20895
20896 /* Extract the instruction. */
20897 insn = md_chars_to_number (buf, INSN_SIZE);
20898
20899 /* If the addend is negative, clear bit 23 of the instruction.
20900 Otherwise set it. */
20901 if (value < 0)
20902 insn &= ~(1 << 23);
20903 else
20904 insn |= 1 << 23;
20905
20906 /* Place the first four bits of the absolute value of the addend
20907 into the first 4 bits of the instruction, and the remaining
20908 four into bits 8 .. 11. */
20909 insn &= 0xfffff0f0;
20910 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20911
20912 /* Update the instruction. */
4962c51a
MS
20913 md_number_to_chars (buf, insn, INSN_SIZE);
20914 }
20915 break;
20916
20917 case BFD_RELOC_ARM_LDC_PC_G0:
20918 case BFD_RELOC_ARM_LDC_PC_G1:
20919 case BFD_RELOC_ARM_LDC_PC_G2:
20920 case BFD_RELOC_ARM_LDC_SB_G0:
20921 case BFD_RELOC_ARM_LDC_SB_G1:
20922 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20923 gas_assert (!fixP->fx_done);
4962c51a
MS
20924 if (!seg->use_rela_p)
20925 {
20926 bfd_vma insn;
20927 bfd_vma addend_abs = abs (value);
20928
20929 /* Check that the absolute value of the addend is a multiple of
20930 four and, when divided by four, fits in 8 bits. */
20931 if (addend_abs & 0x3)
20932 as_bad_where (fixP->fx_file, fixP->fx_line,
20933 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20934 (unsigned long) addend_abs);
4962c51a
MS
20935
20936 if ((addend_abs >> 2) > 0xff)
20937 as_bad_where (fixP->fx_file, fixP->fx_line,
20938 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20939 (unsigned long) addend_abs);
4962c51a
MS
20940
20941 /* Extract the instruction. */
20942 insn = md_chars_to_number (buf, INSN_SIZE);
20943
20944 /* If the addend is negative, clear bit 23 of the instruction.
20945 Otherwise set it. */
20946 if (value < 0)
20947 insn &= ~(1 << 23);
20948 else
20949 insn |= 1 << 23;
20950
20951 /* Place the addend (divided by four) into the first eight
20952 bits of the instruction. */
20953 insn &= 0xfffffff0;
20954 insn |= addend_abs >> 2;
5f4273c7
NC
20955
20956 /* Update the instruction. */
4962c51a
MS
20957 md_number_to_chars (buf, insn, INSN_SIZE);
20958 }
20959 break;
20960
845b51d6
PB
20961 case BFD_RELOC_ARM_V4BX:
20962 /* This will need to go in the object file. */
20963 fixP->fx_done = 0;
20964 break;
20965
c19d1205
ZW
20966 case BFD_RELOC_UNUSED:
20967 default:
20968 as_bad_where (fixP->fx_file, fixP->fx_line,
20969 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20970 }
6c43fab6
RE
20971}
20972
c19d1205
ZW
20973/* Translate internal representation of relocation info to BFD target
20974 format. */
a737bd4d 20975
c19d1205 20976arelent *
00a97672 20977tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20978{
c19d1205
ZW
20979 arelent * reloc;
20980 bfd_reloc_code_real_type code;
a737bd4d 20981
21d799b5 20982 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 20983
21d799b5 20984 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
20985 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20986 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20987
2fc8bdac 20988 if (fixp->fx_pcrel)
00a97672
RS
20989 {
20990 if (section->use_rela_p)
20991 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20992 else
20993 fixp->fx_offset = reloc->address;
20994 }
c19d1205 20995 reloc->addend = fixp->fx_offset;
a737bd4d 20996
c19d1205 20997 switch (fixp->fx_r_type)
a737bd4d 20998 {
c19d1205
ZW
20999 case BFD_RELOC_8:
21000 if (fixp->fx_pcrel)
21001 {
21002 code = BFD_RELOC_8_PCREL;
21003 break;
21004 }
a737bd4d 21005
c19d1205
ZW
21006 case BFD_RELOC_16:
21007 if (fixp->fx_pcrel)
21008 {
21009 code = BFD_RELOC_16_PCREL;
21010 break;
21011 }
6c43fab6 21012
c19d1205
ZW
21013 case BFD_RELOC_32:
21014 if (fixp->fx_pcrel)
21015 {
21016 code = BFD_RELOC_32_PCREL;
21017 break;
21018 }
a737bd4d 21019
b6895b4f
PB
21020 case BFD_RELOC_ARM_MOVW:
21021 if (fixp->fx_pcrel)
21022 {
21023 code = BFD_RELOC_ARM_MOVW_PCREL;
21024 break;
21025 }
21026
21027 case BFD_RELOC_ARM_MOVT:
21028 if (fixp->fx_pcrel)
21029 {
21030 code = BFD_RELOC_ARM_MOVT_PCREL;
21031 break;
21032 }
21033
21034 case BFD_RELOC_ARM_THUMB_MOVW:
21035 if (fixp->fx_pcrel)
21036 {
21037 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21038 break;
21039 }
21040
21041 case BFD_RELOC_ARM_THUMB_MOVT:
21042 if (fixp->fx_pcrel)
21043 {
21044 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21045 break;
21046 }
21047
c19d1205
ZW
21048 case BFD_RELOC_NONE:
21049 case BFD_RELOC_ARM_PCREL_BRANCH:
21050 case BFD_RELOC_ARM_PCREL_BLX:
21051 case BFD_RELOC_RVA:
21052 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21053 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21054 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21055 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21056 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21057 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21058 case BFD_RELOC_VTABLE_ENTRY:
21059 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21060#ifdef TE_PE
21061 case BFD_RELOC_32_SECREL:
21062#endif
c19d1205
ZW
21063 code = fixp->fx_r_type;
21064 break;
a737bd4d 21065
00adf2d4
JB
21066 case BFD_RELOC_THUMB_PCREL_BLX:
21067#ifdef OBJ_ELF
21068 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21069 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21070 else
21071#endif
21072 code = BFD_RELOC_THUMB_PCREL_BLX;
21073 break;
21074
c19d1205
ZW
21075 case BFD_RELOC_ARM_LITERAL:
21076 case BFD_RELOC_ARM_HWLITERAL:
21077 /* If this is called then the a literal has
21078 been referenced across a section boundary. */
21079 as_bad_where (fixp->fx_file, fixp->fx_line,
21080 _("literal referenced across section boundary"));
21081 return NULL;
a737bd4d 21082
c19d1205
ZW
21083#ifdef OBJ_ELF
21084 case BFD_RELOC_ARM_GOT32:
21085 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21086 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21087 case BFD_RELOC_ARM_PLT32:
21088 case BFD_RELOC_ARM_TARGET1:
21089 case BFD_RELOC_ARM_ROSEGREL32:
21090 case BFD_RELOC_ARM_SBREL32:
21091 case BFD_RELOC_ARM_PREL31:
21092 case BFD_RELOC_ARM_TARGET2:
21093 case BFD_RELOC_ARM_TLS_LE32:
21094 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21095 case BFD_RELOC_ARM_PCREL_CALL:
21096 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21097 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21098 case BFD_RELOC_ARM_ALU_PC_G0:
21099 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21100 case BFD_RELOC_ARM_ALU_PC_G1:
21101 case BFD_RELOC_ARM_ALU_PC_G2:
21102 case BFD_RELOC_ARM_LDR_PC_G0:
21103 case BFD_RELOC_ARM_LDR_PC_G1:
21104 case BFD_RELOC_ARM_LDR_PC_G2:
21105 case BFD_RELOC_ARM_LDRS_PC_G0:
21106 case BFD_RELOC_ARM_LDRS_PC_G1:
21107 case BFD_RELOC_ARM_LDRS_PC_G2:
21108 case BFD_RELOC_ARM_LDC_PC_G0:
21109 case BFD_RELOC_ARM_LDC_PC_G1:
21110 case BFD_RELOC_ARM_LDC_PC_G2:
21111 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21112 case BFD_RELOC_ARM_ALU_SB_G0:
21113 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21114 case BFD_RELOC_ARM_ALU_SB_G1:
21115 case BFD_RELOC_ARM_ALU_SB_G2:
21116 case BFD_RELOC_ARM_LDR_SB_G0:
21117 case BFD_RELOC_ARM_LDR_SB_G1:
21118 case BFD_RELOC_ARM_LDR_SB_G2:
21119 case BFD_RELOC_ARM_LDRS_SB_G0:
21120 case BFD_RELOC_ARM_LDRS_SB_G1:
21121 case BFD_RELOC_ARM_LDRS_SB_G2:
21122 case BFD_RELOC_ARM_LDC_SB_G0:
21123 case BFD_RELOC_ARM_LDC_SB_G1:
21124 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21125 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21126 code = fixp->fx_r_type;
21127 break;
a737bd4d 21128
c19d1205
ZW
21129 case BFD_RELOC_ARM_TLS_GD32:
21130 case BFD_RELOC_ARM_TLS_IE32:
21131 case BFD_RELOC_ARM_TLS_LDM32:
21132 /* BFD will include the symbol's address in the addend.
21133 But we don't want that, so subtract it out again here. */
21134 if (!S_IS_COMMON (fixp->fx_addsy))
21135 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21136 code = fixp->fx_r_type;
21137 break;
21138#endif
a737bd4d 21139
c19d1205
ZW
21140 case BFD_RELOC_ARM_IMMEDIATE:
21141 as_bad_where (fixp->fx_file, fixp->fx_line,
21142 _("internal relocation (type: IMMEDIATE) not fixed up"));
21143 return NULL;
a737bd4d 21144
c19d1205
ZW
21145 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21146 as_bad_where (fixp->fx_file, fixp->fx_line,
21147 _("ADRL used for a symbol not defined in the same file"));
21148 return NULL;
a737bd4d 21149
c19d1205 21150 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21151 if (section->use_rela_p)
21152 {
21153 code = fixp->fx_r_type;
21154 break;
21155 }
21156
c19d1205
ZW
21157 if (fixp->fx_addsy != NULL
21158 && !S_IS_DEFINED (fixp->fx_addsy)
21159 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21160 {
c19d1205
ZW
21161 as_bad_where (fixp->fx_file, fixp->fx_line,
21162 _("undefined local label `%s'"),
21163 S_GET_NAME (fixp->fx_addsy));
21164 return NULL;
a737bd4d
NC
21165 }
21166
c19d1205
ZW
21167 as_bad_where (fixp->fx_file, fixp->fx_line,
21168 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21169 return NULL;
a737bd4d 21170
c19d1205
ZW
21171 default:
21172 {
21173 char * type;
6c43fab6 21174
c19d1205
ZW
21175 switch (fixp->fx_r_type)
21176 {
21177 case BFD_RELOC_NONE: type = "NONE"; break;
21178 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21179 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21180 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21181 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21182 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21183 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 21184 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21185 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21186 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21187 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21188 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21189 default: type = _("<unknown>"); break;
21190 }
21191 as_bad_where (fixp->fx_file, fixp->fx_line,
21192 _("cannot represent %s relocation in this object file format"),
21193 type);
21194 return NULL;
21195 }
a737bd4d 21196 }
6c43fab6 21197
c19d1205
ZW
21198#ifdef OBJ_ELF
21199 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21200 && GOT_symbol
21201 && fixp->fx_addsy == GOT_symbol)
21202 {
21203 code = BFD_RELOC_ARM_GOTPC;
21204 reloc->addend = fixp->fx_offset = reloc->address;
21205 }
21206#endif
6c43fab6 21207
c19d1205 21208 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21209
c19d1205
ZW
21210 if (reloc->howto == NULL)
21211 {
21212 as_bad_where (fixp->fx_file, fixp->fx_line,
21213 _("cannot represent %s relocation in this object file format"),
21214 bfd_get_reloc_code_name (code));
21215 return NULL;
21216 }
6c43fab6 21217
c19d1205
ZW
21218 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21219 vtable entry to be used in the relocation's section offset. */
21220 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21221 reloc->address = fixp->fx_offset;
6c43fab6 21222
c19d1205 21223 return reloc;
6c43fab6
RE
21224}
21225
c19d1205 21226/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21227
c19d1205
ZW
21228void
21229cons_fix_new_arm (fragS * frag,
21230 int where,
21231 int size,
21232 expressionS * exp)
6c43fab6 21233{
c19d1205
ZW
21234 bfd_reloc_code_real_type type;
21235 int pcrel = 0;
6c43fab6 21236
c19d1205
ZW
21237 /* Pick a reloc.
21238 FIXME: @@ Should look at CPU word size. */
21239 switch (size)
21240 {
21241 case 1:
21242 type = BFD_RELOC_8;
21243 break;
21244 case 2:
21245 type = BFD_RELOC_16;
21246 break;
21247 case 4:
21248 default:
21249 type = BFD_RELOC_32;
21250 break;
21251 case 8:
21252 type = BFD_RELOC_64;
21253 break;
21254 }
6c43fab6 21255
f0927246
NC
21256#ifdef TE_PE
21257 if (exp->X_op == O_secrel)
21258 {
21259 exp->X_op = O_symbol;
21260 type = BFD_RELOC_32_SECREL;
21261 }
21262#endif
21263
c19d1205
ZW
21264 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21265}
6c43fab6 21266
4343666d 21267#if defined (OBJ_COFF)
c19d1205
ZW
21268void
21269arm_validate_fix (fixS * fixP)
6c43fab6 21270{
c19d1205
ZW
21271 /* If the destination of the branch is a defined symbol which does not have
21272 the THUMB_FUNC attribute, then we must be calling a function which has
21273 the (interfacearm) attribute. We look for the Thumb entry point to that
21274 function and change the branch to refer to that function instead. */
21275 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21276 && fixP->fx_addsy != NULL
21277 && S_IS_DEFINED (fixP->fx_addsy)
21278 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21279 {
c19d1205 21280 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21281 }
c19d1205
ZW
21282}
21283#endif
6c43fab6 21284
267bf995 21285
c19d1205
ZW
21286int
21287arm_force_relocation (struct fix * fixp)
21288{
21289#if defined (OBJ_COFF) && defined (TE_PE)
21290 if (fixp->fx_r_type == BFD_RELOC_RVA)
21291 return 1;
21292#endif
6c43fab6 21293
267bf995
RR
21294 /* In case we have a call or a branch to a function in ARM ISA mode from
21295 a thumb function or vice-versa force the relocation. These relocations
21296 are cleared off for some cores that might have blx and simple transformations
21297 are possible. */
21298
21299#ifdef OBJ_ELF
21300 switch (fixp->fx_r_type)
21301 {
21302 case BFD_RELOC_ARM_PCREL_JUMP:
21303 case BFD_RELOC_ARM_PCREL_CALL:
21304 case BFD_RELOC_THUMB_PCREL_BLX:
21305 if (THUMB_IS_FUNC (fixp->fx_addsy))
21306 return 1;
21307 break;
21308
21309 case BFD_RELOC_ARM_PCREL_BLX:
21310 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21311 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21312 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21313 if (ARM_IS_FUNC (fixp->fx_addsy))
21314 return 1;
21315 break;
21316
21317 default:
21318 break;
21319 }
21320#endif
21321
c19d1205
ZW
21322 /* Resolve these relocations even if the symbol is extern or weak. */
21323 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21324 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21325 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21326 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21327 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21328 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21329 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21330 return 0;
a737bd4d 21331
4962c51a
MS
21332 /* Always leave these relocations for the linker. */
21333 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21334 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21335 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21336 return 1;
21337
f0291e4c
PB
21338 /* Always generate relocations against function symbols. */
21339 if (fixp->fx_r_type == BFD_RELOC_32
21340 && fixp->fx_addsy
21341 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21342 return 1;
21343
c19d1205 21344 return generic_force_reloc (fixp);
404ff6b5
AH
21345}
21346
0ffdc86c 21347#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21348/* Relocations against function names must be left unadjusted,
21349 so that the linker can use this information to generate interworking
21350 stubs. The MIPS version of this function
c19d1205
ZW
21351 also prevents relocations that are mips-16 specific, but I do not
21352 know why it does this.
404ff6b5 21353
c19d1205
ZW
21354 FIXME:
21355 There is one other problem that ought to be addressed here, but
21356 which currently is not: Taking the address of a label (rather
21357 than a function) and then later jumping to that address. Such
21358 addresses also ought to have their bottom bit set (assuming that
21359 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21360
c19d1205
ZW
21361bfd_boolean
21362arm_fix_adjustable (fixS * fixP)
404ff6b5 21363{
c19d1205
ZW
21364 if (fixP->fx_addsy == NULL)
21365 return 1;
404ff6b5 21366
e28387c3
PB
21367 /* Preserve relocations against symbols with function type. */
21368 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21369 return FALSE;
e28387c3 21370
c19d1205
ZW
21371 if (THUMB_IS_FUNC (fixP->fx_addsy)
21372 && fixP->fx_subsy == NULL)
c921be7d 21373 return FALSE;
a737bd4d 21374
c19d1205
ZW
21375 /* We need the symbol name for the VTABLE entries. */
21376 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21377 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21378 return FALSE;
404ff6b5 21379
c19d1205
ZW
21380 /* Don't allow symbols to be discarded on GOT related relocs. */
21381 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21382 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21383 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21384 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21385 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21386 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21387 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21388 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21389 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21390 return FALSE;
a737bd4d 21391
4962c51a
MS
21392 /* Similarly for group relocations. */
21393 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21394 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21395 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21396 return FALSE;
4962c51a 21397
79947c54
CD
21398 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21399 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21400 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21401 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21402 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21403 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21404 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21405 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21406 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21407 return FALSE;
79947c54 21408
c921be7d 21409 return TRUE;
a737bd4d 21410}
0ffdc86c
NC
21411#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21412
21413#ifdef OBJ_ELF
404ff6b5 21414
c19d1205
ZW
21415const char *
21416elf32_arm_target_format (void)
404ff6b5 21417{
c19d1205
ZW
21418#ifdef TE_SYMBIAN
21419 return (target_big_endian
21420 ? "elf32-bigarm-symbian"
21421 : "elf32-littlearm-symbian");
21422#elif defined (TE_VXWORKS)
21423 return (target_big_endian
21424 ? "elf32-bigarm-vxworks"
21425 : "elf32-littlearm-vxworks");
21426#else
21427 if (target_big_endian)
21428 return "elf32-bigarm";
21429 else
21430 return "elf32-littlearm";
21431#endif
404ff6b5
AH
21432}
21433
c19d1205
ZW
21434void
21435armelf_frob_symbol (symbolS * symp,
21436 int * puntp)
404ff6b5 21437{
c19d1205
ZW
21438 elf_frob_symbol (symp, puntp);
21439}
21440#endif
404ff6b5 21441
c19d1205 21442/* MD interface: Finalization. */
a737bd4d 21443
c19d1205
ZW
21444void
21445arm_cleanup (void)
21446{
21447 literal_pool * pool;
a737bd4d 21448
e07e6e58
NC
21449 /* Ensure that all the IT blocks are properly closed. */
21450 check_it_blocks_finished ();
21451
c19d1205
ZW
21452 for (pool = list_of_pools; pool; pool = pool->next)
21453 {
5f4273c7 21454 /* Put it at the end of the relevant section. */
c19d1205
ZW
21455 subseg_set (pool->section, pool->sub_section);
21456#ifdef OBJ_ELF
21457 arm_elf_change_section ();
21458#endif
21459 s_ltorg (0);
21460 }
404ff6b5
AH
21461}
21462
cd000bff
DJ
21463#ifdef OBJ_ELF
21464/* Remove any excess mapping symbols generated for alignment frags in
21465 SEC. We may have created a mapping symbol before a zero byte
21466 alignment; remove it if there's a mapping symbol after the
21467 alignment. */
21468static void
21469check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21470 void *dummy ATTRIBUTE_UNUSED)
21471{
21472 segment_info_type *seginfo = seg_info (sec);
21473 fragS *fragp;
21474
21475 if (seginfo == NULL || seginfo->frchainP == NULL)
21476 return;
21477
21478 for (fragp = seginfo->frchainP->frch_root;
21479 fragp != NULL;
21480 fragp = fragp->fr_next)
21481 {
21482 symbolS *sym = fragp->tc_frag_data.last_map;
21483 fragS *next = fragp->fr_next;
21484
21485 /* Variable-sized frags have been converted to fixed size by
21486 this point. But if this was variable-sized to start with,
21487 there will be a fixed-size frag after it. So don't handle
21488 next == NULL. */
21489 if (sym == NULL || next == NULL)
21490 continue;
21491
21492 if (S_GET_VALUE (sym) < next->fr_address)
21493 /* Not at the end of this frag. */
21494 continue;
21495 know (S_GET_VALUE (sym) == next->fr_address);
21496
21497 do
21498 {
21499 if (next->tc_frag_data.first_map != NULL)
21500 {
21501 /* Next frag starts with a mapping symbol. Discard this
21502 one. */
21503 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21504 break;
21505 }
21506
21507 if (next->fr_next == NULL)
21508 {
21509 /* This mapping symbol is at the end of the section. Discard
21510 it. */
21511 know (next->fr_fix == 0 && next->fr_var == 0);
21512 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21513 break;
21514 }
21515
21516 /* As long as we have empty frags without any mapping symbols,
21517 keep looking. */
21518 /* If the next frag is non-empty and does not start with a
21519 mapping symbol, then this mapping symbol is required. */
21520 if (next->fr_address != next->fr_next->fr_address)
21521 break;
21522
21523 next = next->fr_next;
21524 }
21525 while (next != NULL);
21526 }
21527}
21528#endif
21529
c19d1205
ZW
21530/* Adjust the symbol table. This marks Thumb symbols as distinct from
21531 ARM ones. */
404ff6b5 21532
c19d1205
ZW
21533void
21534arm_adjust_symtab (void)
404ff6b5 21535{
c19d1205
ZW
21536#ifdef OBJ_COFF
21537 symbolS * sym;
404ff6b5 21538
c19d1205
ZW
21539 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21540 {
21541 if (ARM_IS_THUMB (sym))
21542 {
21543 if (THUMB_IS_FUNC (sym))
21544 {
21545 /* Mark the symbol as a Thumb function. */
21546 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21547 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21548 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21549
c19d1205
ZW
21550 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21551 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21552 else
21553 as_bad (_("%s: unexpected function type: %d"),
21554 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21555 }
21556 else switch (S_GET_STORAGE_CLASS (sym))
21557 {
21558 case C_EXT:
21559 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21560 break;
21561 case C_STAT:
21562 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21563 break;
21564 case C_LABEL:
21565 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21566 break;
21567 default:
21568 /* Do nothing. */
21569 break;
21570 }
21571 }
a737bd4d 21572
c19d1205
ZW
21573 if (ARM_IS_INTERWORK (sym))
21574 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21575 }
c19d1205
ZW
21576#endif
21577#ifdef OBJ_ELF
21578 symbolS * sym;
21579 char bind;
404ff6b5 21580
c19d1205 21581 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21582 {
c19d1205
ZW
21583 if (ARM_IS_THUMB (sym))
21584 {
21585 elf_symbol_type * elf_sym;
404ff6b5 21586
c19d1205
ZW
21587 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21588 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21589
b0796911
PB
21590 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21591 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21592 {
21593 /* If it's a .thumb_func, declare it as so,
21594 otherwise tag label as .code 16. */
21595 if (THUMB_IS_FUNC (sym))
21596 elf_sym->internal_elf_sym.st_info =
21597 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21598 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21599 elf_sym->internal_elf_sym.st_info =
21600 ELF_ST_INFO (bind, STT_ARM_16BIT);
21601 }
21602 }
21603 }
cd000bff
DJ
21604
21605 /* Remove any overlapping mapping symbols generated by alignment frags. */
21606 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21607#endif
404ff6b5
AH
21608}
21609
c19d1205 21610/* MD interface: Initialization. */
404ff6b5 21611
a737bd4d 21612static void
c19d1205 21613set_constant_flonums (void)
a737bd4d 21614{
c19d1205 21615 int i;
404ff6b5 21616
c19d1205
ZW
21617 for (i = 0; i < NUM_FLOAT_VALS; i++)
21618 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21619 abort ();
a737bd4d 21620}
404ff6b5 21621
3e9e4fcf
JB
21622/* Auto-select Thumb mode if it's the only available instruction set for the
21623 given architecture. */
21624
21625static void
21626autoselect_thumb_from_cpu_variant (void)
21627{
21628 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21629 opcode_select (16);
21630}
21631
c19d1205
ZW
21632void
21633md_begin (void)
a737bd4d 21634{
c19d1205
ZW
21635 unsigned mach;
21636 unsigned int i;
404ff6b5 21637
c19d1205
ZW
21638 if ( (arm_ops_hsh = hash_new ()) == NULL
21639 || (arm_cond_hsh = hash_new ()) == NULL
21640 || (arm_shift_hsh = hash_new ()) == NULL
21641 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21642 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21643 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21644 || (arm_reloc_hsh = hash_new ()) == NULL
21645 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21646 as_fatal (_("virtual memory exhausted"));
21647
21648 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21649 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21650 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21651 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21652 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21653 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21654 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21655 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21656 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21657 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21658 (void *) (v7m_psrs + i));
c19d1205 21659 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21660 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21661 for (i = 0;
21662 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21663 i++)
d3ce72d0 21664 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21665 (void *) (barrier_opt_names + i));
c19d1205
ZW
21666#ifdef OBJ_ELF
21667 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21668 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21669#endif
21670
21671 set_constant_flonums ();
404ff6b5 21672
c19d1205
ZW
21673 /* Set the cpu variant based on the command-line options. We prefer
21674 -mcpu= over -march= if both are set (as for GCC); and we prefer
21675 -mfpu= over any other way of setting the floating point unit.
21676 Use of legacy options with new options are faulted. */
e74cfd16 21677 if (legacy_cpu)
404ff6b5 21678 {
e74cfd16 21679 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21680 as_bad (_("use of old and new-style options to set CPU type"));
21681
21682 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21683 }
e74cfd16 21684 else if (!mcpu_cpu_opt)
c19d1205 21685 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21686
e74cfd16 21687 if (legacy_fpu)
c19d1205 21688 {
e74cfd16 21689 if (mfpu_opt)
c19d1205 21690 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21691
21692 mfpu_opt = legacy_fpu;
21693 }
e74cfd16 21694 else if (!mfpu_opt)
03b1477f 21695 {
45eb4c1b
NS
21696#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21697 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21698 /* Some environments specify a default FPU. If they don't, infer it
21699 from the processor. */
e74cfd16 21700 if (mcpu_fpu_opt)
03b1477f
RE
21701 mfpu_opt = mcpu_fpu_opt;
21702 else
21703 mfpu_opt = march_fpu_opt;
39c2da32 21704#else
e74cfd16 21705 mfpu_opt = &fpu_default;
39c2da32 21706#endif
03b1477f
RE
21707 }
21708
e74cfd16 21709 if (!mfpu_opt)
03b1477f 21710 {
493cb6ef 21711 if (mcpu_cpu_opt != NULL)
e74cfd16 21712 mfpu_opt = &fpu_default;
493cb6ef 21713 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21714 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21715 else
e74cfd16 21716 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21717 }
21718
ee065d83 21719#ifdef CPU_DEFAULT
e74cfd16 21720 if (!mcpu_cpu_opt)
ee065d83 21721 {
e74cfd16
PB
21722 mcpu_cpu_opt = &cpu_default;
21723 selected_cpu = cpu_default;
ee065d83 21724 }
e74cfd16
PB
21725#else
21726 if (mcpu_cpu_opt)
21727 selected_cpu = *mcpu_cpu_opt;
ee065d83 21728 else
e74cfd16 21729 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21730#endif
03b1477f 21731
e74cfd16 21732 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21733
3e9e4fcf
JB
21734 autoselect_thumb_from_cpu_variant ();
21735
e74cfd16 21736 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21737
f17c130b 21738#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21739 {
7cc69913
NC
21740 unsigned int flags = 0;
21741
21742#if defined OBJ_ELF
21743 flags = meabi_flags;
d507cf36
PB
21744
21745 switch (meabi_flags)
33a392fb 21746 {
d507cf36 21747 case EF_ARM_EABI_UNKNOWN:
7cc69913 21748#endif
d507cf36
PB
21749 /* Set the flags in the private structure. */
21750 if (uses_apcs_26) flags |= F_APCS26;
21751 if (support_interwork) flags |= F_INTERWORK;
21752 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21753 if (pic_code) flags |= F_PIC;
e74cfd16 21754 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21755 flags |= F_SOFT_FLOAT;
21756
d507cf36
PB
21757 switch (mfloat_abi_opt)
21758 {
21759 case ARM_FLOAT_ABI_SOFT:
21760 case ARM_FLOAT_ABI_SOFTFP:
21761 flags |= F_SOFT_FLOAT;
21762 break;
33a392fb 21763
d507cf36
PB
21764 case ARM_FLOAT_ABI_HARD:
21765 if (flags & F_SOFT_FLOAT)
21766 as_bad (_("hard-float conflicts with specified fpu"));
21767 break;
21768 }
03b1477f 21769
e74cfd16
PB
21770 /* Using pure-endian doubles (even if soft-float). */
21771 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21772 flags |= F_VFP_FLOAT;
f17c130b 21773
fde78edd 21774#if defined OBJ_ELF
e74cfd16 21775 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21776 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21777 break;
21778
8cb51566 21779 case EF_ARM_EABI_VER4:
3a4a14e9 21780 case EF_ARM_EABI_VER5:
c19d1205 21781 /* No additional flags to set. */
d507cf36
PB
21782 break;
21783
21784 default:
21785 abort ();
21786 }
7cc69913 21787#endif
b99bd4ef
NC
21788 bfd_set_private_flags (stdoutput, flags);
21789
21790 /* We have run out flags in the COFF header to encode the
21791 status of ATPCS support, so instead we create a dummy,
c19d1205 21792 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21793 if (atpcs)
21794 {
21795 asection * sec;
21796
21797 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21798
21799 if (sec != NULL)
21800 {
21801 bfd_set_section_flags
21802 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21803 bfd_set_section_size (stdoutput, sec, 0);
21804 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21805 }
21806 }
7cc69913 21807 }
f17c130b 21808#endif
b99bd4ef
NC
21809
21810 /* Record the CPU type as well. */
2d447fca
JM
21811 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21812 mach = bfd_mach_arm_iWMMXt2;
21813 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21814 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21815 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21816 mach = bfd_mach_arm_XScale;
e74cfd16 21817 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21818 mach = bfd_mach_arm_ep9312;
e74cfd16 21819 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21820 mach = bfd_mach_arm_5TE;
e74cfd16 21821 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21822 {
e74cfd16 21823 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21824 mach = bfd_mach_arm_5T;
21825 else
21826 mach = bfd_mach_arm_5;
21827 }
e74cfd16 21828 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21829 {
e74cfd16 21830 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21831 mach = bfd_mach_arm_4T;
21832 else
21833 mach = bfd_mach_arm_4;
21834 }
e74cfd16 21835 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21836 mach = bfd_mach_arm_3M;
e74cfd16
PB
21837 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21838 mach = bfd_mach_arm_3;
21839 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21840 mach = bfd_mach_arm_2a;
21841 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21842 mach = bfd_mach_arm_2;
21843 else
21844 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21845
21846 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21847}
21848
c19d1205 21849/* Command line processing. */
b99bd4ef 21850
c19d1205
ZW
21851/* md_parse_option
21852 Invocation line includes a switch not recognized by the base assembler.
21853 See if it's a processor-specific option.
b99bd4ef 21854
c19d1205
ZW
21855 This routine is somewhat complicated by the need for backwards
21856 compatibility (since older releases of gcc can't be changed).
21857 The new options try to make the interface as compatible as
21858 possible with GCC.
b99bd4ef 21859
c19d1205 21860 New options (supported) are:
b99bd4ef 21861
c19d1205
ZW
21862 -mcpu=<cpu name> Assemble for selected processor
21863 -march=<architecture name> Assemble for selected architecture
21864 -mfpu=<fpu architecture> Assemble for selected FPU.
21865 -EB/-mbig-endian Big-endian
21866 -EL/-mlittle-endian Little-endian
21867 -k Generate PIC code
21868 -mthumb Start in Thumb mode
21869 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21870
278df34e 21871 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21872
c19d1205 21873 For now we will also provide support for:
b99bd4ef 21874
c19d1205
ZW
21875 -mapcs-32 32-bit Program counter
21876 -mapcs-26 26-bit Program counter
21877 -macps-float Floats passed in FP registers
21878 -mapcs-reentrant Reentrant code
21879 -matpcs
21880 (sometime these will probably be replaced with -mapcs=<list of options>
21881 and -matpcs=<list of options>)
b99bd4ef 21882
c19d1205
ZW
21883 The remaining options are only supported for back-wards compatibility.
21884 Cpu variants, the arm part is optional:
21885 -m[arm]1 Currently not supported.
21886 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21887 -m[arm]3 Arm 3 processor
21888 -m[arm]6[xx], Arm 6 processors
21889 -m[arm]7[xx][t][[d]m] Arm 7 processors
21890 -m[arm]8[10] Arm 8 processors
21891 -m[arm]9[20][tdmi] Arm 9 processors
21892 -mstrongarm[110[0]] StrongARM processors
21893 -mxscale XScale processors
21894 -m[arm]v[2345[t[e]]] Arm architectures
21895 -mall All (except the ARM1)
21896 FP variants:
21897 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21898 -mfpe-old (No float load/store multiples)
21899 -mvfpxd VFP Single precision
21900 -mvfp All VFP
21901 -mno-fpu Disable all floating point instructions
b99bd4ef 21902
c19d1205
ZW
21903 The following CPU names are recognized:
21904 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21905 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21906 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21907 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21908 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21909 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21910 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21911
c19d1205 21912 */
b99bd4ef 21913
c19d1205 21914const char * md_shortopts = "m:k";
b99bd4ef 21915
c19d1205
ZW
21916#ifdef ARM_BI_ENDIAN
21917#define OPTION_EB (OPTION_MD_BASE + 0)
21918#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21919#else
c19d1205
ZW
21920#if TARGET_BYTES_BIG_ENDIAN
21921#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21922#else
c19d1205
ZW
21923#define OPTION_EL (OPTION_MD_BASE + 1)
21924#endif
b99bd4ef 21925#endif
845b51d6 21926#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21927
c19d1205 21928struct option md_longopts[] =
b99bd4ef 21929{
c19d1205
ZW
21930#ifdef OPTION_EB
21931 {"EB", no_argument, NULL, OPTION_EB},
21932#endif
21933#ifdef OPTION_EL
21934 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21935#endif
845b51d6 21936 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21937 {NULL, no_argument, NULL, 0}
21938};
b99bd4ef 21939
c19d1205 21940size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21941
c19d1205 21942struct arm_option_table
b99bd4ef 21943{
c19d1205
ZW
21944 char *option; /* Option name to match. */
21945 char *help; /* Help information. */
21946 int *var; /* Variable to change. */
21947 int value; /* What to change it to. */
21948 char *deprecated; /* If non-null, print this message. */
21949};
b99bd4ef 21950
c19d1205
ZW
21951struct arm_option_table arm_opts[] =
21952{
21953 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21954 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21955 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21956 &support_interwork, 1, NULL},
21957 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21958 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21959 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21960 1, NULL},
21961 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21962 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21963 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21964 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21965 NULL},
b99bd4ef 21966
c19d1205
ZW
21967 /* These are recognized by the assembler, but have no affect on code. */
21968 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21969 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21970
21971 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21972 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21973 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21974 {NULL, NULL, NULL, 0, NULL}
21975};
21976
21977struct arm_legacy_option_table
21978{
21979 char *option; /* Option name to match. */
21980 const arm_feature_set **var; /* Variable to change. */
21981 const arm_feature_set value; /* What to change it to. */
21982 char *deprecated; /* If non-null, print this message. */
21983};
b99bd4ef 21984
e74cfd16
PB
21985const struct arm_legacy_option_table arm_legacy_opts[] =
21986{
c19d1205
ZW
21987 /* DON'T add any new processors to this list -- we want the whole list
21988 to go away... Add them to the processors table instead. */
e74cfd16
PB
21989 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21990 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21991 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21992 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21993 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21994 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21995 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21996 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21997 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21998 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21999 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22000 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22001 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22002 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22003 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22004 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22005 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22006 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22007 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22008 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22009 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22010 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22011 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22012 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22013 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22014 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22015 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22016 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22017 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22018 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22019 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22020 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22021 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22022 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22023 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22024 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22025 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22026 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22027 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22028 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22029 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22030 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22031 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22032 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22033 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22034 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22035 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22036 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22037 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22038 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22039 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22040 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22041 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22042 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22043 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22044 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22045 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22046 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22047 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22048 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22049 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22050 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22051 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22052 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22053 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22054 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22055 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22056 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22057 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22058 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22059 N_("use -mcpu=strongarm110")},
e74cfd16 22060 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22061 N_("use -mcpu=strongarm1100")},
e74cfd16 22062 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22063 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22064 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22065 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22066 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22067
c19d1205 22068 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22069 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22070 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22071 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22072 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22073 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22074 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22075 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22076 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22077 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22078 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22079 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22080 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22081 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22082 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22083 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22084 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22085 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22086 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22087
c19d1205 22088 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22089 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22090 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22091 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22092 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22093 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22094
e74cfd16 22095 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22096};
7ed4c4c5 22097
c19d1205 22098struct arm_cpu_option_table
7ed4c4c5 22099{
c19d1205 22100 char *name;
e74cfd16 22101 const arm_feature_set value;
c19d1205
ZW
22102 /* For some CPUs we assume an FPU unless the user explicitly sets
22103 -mfpu=... */
e74cfd16 22104 const arm_feature_set default_fpu;
ee065d83
PB
22105 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22106 case. */
22107 const char *canonical_name;
c19d1205 22108};
7ed4c4c5 22109
c19d1205
ZW
22110/* This list should, at a minimum, contain all the cpu names
22111 recognized by GCC. */
e74cfd16 22112static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22113{
ee065d83
PB
22114 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22115 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22116 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22117 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22118 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22119 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22120 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22121 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22122 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22123 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22124 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22125 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22126 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22127 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22128 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22129 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22130 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22131 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22132 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22133 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22134 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22135 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22136 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22137 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22138 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22139 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22140 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22141 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22142 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22143 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22144 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22145 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22146 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22147 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22148 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22149 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22150 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22151 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22152 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22153 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22154 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22155 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22156 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22157 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22158 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22159 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22160 /* For V5 or later processors we default to using VFP; but the user
22161 should really set the FPU type explicitly. */
ee065d83
PB
22162 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22163 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22164 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22165 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22166 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22167 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22168 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22169 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22170 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22171 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22172 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22173 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22174 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22175 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22176 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22177 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22178 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22179 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22180 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22181 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22182 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22183 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22184 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22185 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22186 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22187 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22188 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22189 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22190 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22191 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22192 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22193 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22194 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
b38f9f31 22195 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
e07e6e58 22196 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22197 | FPU_NEON_EXT_V1),
15290f0a 22198 NULL},
e07e6e58 22199 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22200 | FPU_NEON_EXT_V1),
5287ad62 22201 NULL},
62b3e311 22202 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
307c948d 22203 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
26b6f191 22204 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, NULL},
62b3e311 22205 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 22206 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 22207 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 22208 /* ??? XSCALE is really an architecture. */
ee065d83 22209 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22210 /* ??? iwmmxt is not a processor. */
ee065d83 22211 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22212 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22213 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22214 /* Maverick */
e07e6e58 22215 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22216 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22217};
7ed4c4c5 22218
c19d1205 22219struct arm_arch_option_table
7ed4c4c5 22220{
c19d1205 22221 char *name;
e74cfd16
PB
22222 const arm_feature_set value;
22223 const arm_feature_set default_fpu;
c19d1205 22224};
7ed4c4c5 22225
c19d1205
ZW
22226/* This list should, at a minimum, contain all the architecture names
22227 recognized by GCC. */
e74cfd16 22228static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22229{
22230 {"all", ARM_ANY, FPU_ARCH_FPA},
22231 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22232 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22233 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22234 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22235 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22236 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22237 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22238 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22239 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22240 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22241 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22242 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22243 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22244 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22245 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22246 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22247 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22248 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22249 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22250 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22251 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22252 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22253 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22254 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22255 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22256 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22257 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22258 /* The official spelling of the ARMv7 profile variants is the dashed form.
22259 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22260 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22261 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22262 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22263 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22264 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22265 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22266 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22267 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22268 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22269 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22270 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22271};
7ed4c4c5 22272
c19d1205 22273/* ISA extensions in the co-processor space. */
e74cfd16 22274struct arm_option_cpu_value_table
c19d1205
ZW
22275{
22276 char *name;
e74cfd16 22277 const arm_feature_set value;
c19d1205 22278};
7ed4c4c5 22279
e74cfd16 22280static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22281{
e74cfd16
PB
22282 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22283 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22284 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22285 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22286 {NULL, ARM_ARCH_NONE}
c19d1205 22287};
7ed4c4c5 22288
c19d1205
ZW
22289/* This list should, at a minimum, contain all the fpu names
22290 recognized by GCC. */
e74cfd16 22291static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22292{
22293 {"softfpa", FPU_NONE},
22294 {"fpe", FPU_ARCH_FPE},
22295 {"fpe2", FPU_ARCH_FPE},
22296 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22297 {"fpa", FPU_ARCH_FPA},
22298 {"fpa10", FPU_ARCH_FPA},
22299 {"fpa11", FPU_ARCH_FPA},
22300 {"arm7500fe", FPU_ARCH_FPA},
22301 {"softvfp", FPU_ARCH_VFP},
22302 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22303 {"vfp", FPU_ARCH_VFP_V2},
22304 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22305 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22306 {"vfp10", FPU_ARCH_VFP_V2},
22307 {"vfp10-r0", FPU_ARCH_VFP_V1},
22308 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22309 {"vfpv2", FPU_ARCH_VFP_V2},
22310 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22311 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22312 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22313 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22314 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22315 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22316 {"arm1020t", FPU_ARCH_VFP_V1},
22317 {"arm1020e", FPU_ARCH_VFP_V2},
22318 {"arm1136jfs", FPU_ARCH_VFP_V2},
22319 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22320 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22321 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22322 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22323 {"vfpv4", FPU_ARCH_VFP_V4},
22324 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22325 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22326 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22327 {NULL, ARM_ARCH_NONE}
22328};
22329
22330struct arm_option_value_table
22331{
22332 char *name;
22333 long value;
c19d1205 22334};
7ed4c4c5 22335
e74cfd16 22336static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22337{
22338 {"hard", ARM_FLOAT_ABI_HARD},
22339 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22340 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22341 {NULL, 0}
c19d1205 22342};
7ed4c4c5 22343
c19d1205 22344#ifdef OBJ_ELF
3a4a14e9 22345/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22346static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22347{
22348 {"gnu", EF_ARM_EABI_UNKNOWN},
22349 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22350 {"5", EF_ARM_EABI_VER5},
e74cfd16 22351 {NULL, 0}
c19d1205
ZW
22352};
22353#endif
7ed4c4c5 22354
c19d1205
ZW
22355struct arm_long_option_table
22356{
22357 char * option; /* Substring to match. */
22358 char * help; /* Help information. */
22359 int (* func) (char * subopt); /* Function to decode sub-option. */
22360 char * deprecated; /* If non-null, print this message. */
22361};
7ed4c4c5 22362
c921be7d 22363static bfd_boolean
e74cfd16 22364arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22365{
21d799b5
NC
22366 arm_feature_set *ext_set = (arm_feature_set *)
22367 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22368
22369 /* Copy the feature set, so that we can modify it. */
22370 *ext_set = **opt_p;
22371 *opt_p = ext_set;
22372
c19d1205 22373 while (str != NULL && *str != 0)
7ed4c4c5 22374 {
e74cfd16 22375 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22376 char * ext;
22377 int optlen;
7ed4c4c5 22378
c19d1205
ZW
22379 if (*str != '+')
22380 {
22381 as_bad (_("invalid architectural extension"));
c921be7d 22382 return FALSE;
c19d1205 22383 }
7ed4c4c5 22384
c19d1205
ZW
22385 str++;
22386 ext = strchr (str, '+');
7ed4c4c5 22387
c19d1205
ZW
22388 if (ext != NULL)
22389 optlen = ext - str;
22390 else
22391 optlen = strlen (str);
7ed4c4c5 22392
c19d1205
ZW
22393 if (optlen == 0)
22394 {
22395 as_bad (_("missing architectural extension"));
c921be7d 22396 return FALSE;
c19d1205 22397 }
7ed4c4c5 22398
c19d1205
ZW
22399 for (opt = arm_extensions; opt->name != NULL; opt++)
22400 if (strncmp (opt->name, str, optlen) == 0)
22401 {
e74cfd16 22402 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22403 break;
22404 }
7ed4c4c5 22405
c19d1205
ZW
22406 if (opt->name == NULL)
22407 {
5f4273c7 22408 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22409 return FALSE;
c19d1205 22410 }
7ed4c4c5 22411
c19d1205
ZW
22412 str = ext;
22413 };
7ed4c4c5 22414
c921be7d 22415 return TRUE;
c19d1205 22416}
7ed4c4c5 22417
c921be7d 22418static bfd_boolean
c19d1205 22419arm_parse_cpu (char * str)
7ed4c4c5 22420{
e74cfd16 22421 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22422 char * ext = strchr (str, '+');
22423 int optlen;
7ed4c4c5 22424
c19d1205
ZW
22425 if (ext != NULL)
22426 optlen = ext - str;
7ed4c4c5 22427 else
c19d1205 22428 optlen = strlen (str);
7ed4c4c5 22429
c19d1205 22430 if (optlen == 0)
7ed4c4c5 22431 {
c19d1205 22432 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22433 return FALSE;
7ed4c4c5
NC
22434 }
22435
c19d1205
ZW
22436 for (opt = arm_cpus; opt->name != NULL; opt++)
22437 if (strncmp (opt->name, str, optlen) == 0)
22438 {
e74cfd16
PB
22439 mcpu_cpu_opt = &opt->value;
22440 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22441 if (opt->canonical_name)
5f4273c7 22442 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22443 else
22444 {
22445 int i;
c921be7d 22446
ee065d83
PB
22447 for (i = 0; i < optlen; i++)
22448 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22449 selected_cpu_name[i] = 0;
22450 }
7ed4c4c5 22451
c19d1205
ZW
22452 if (ext != NULL)
22453 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22454
c921be7d 22455 return TRUE;
c19d1205 22456 }
7ed4c4c5 22457
c19d1205 22458 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22459 return FALSE;
7ed4c4c5
NC
22460}
22461
c921be7d 22462static bfd_boolean
c19d1205 22463arm_parse_arch (char * str)
7ed4c4c5 22464{
e74cfd16 22465 const struct arm_arch_option_table *opt;
c19d1205
ZW
22466 char *ext = strchr (str, '+');
22467 int optlen;
7ed4c4c5 22468
c19d1205
ZW
22469 if (ext != NULL)
22470 optlen = ext - str;
7ed4c4c5 22471 else
c19d1205 22472 optlen = strlen (str);
7ed4c4c5 22473
c19d1205 22474 if (optlen == 0)
7ed4c4c5 22475 {
c19d1205 22476 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22477 return FALSE;
7ed4c4c5
NC
22478 }
22479
c19d1205
ZW
22480 for (opt = arm_archs; opt->name != NULL; opt++)
22481 if (streq (opt->name, str))
22482 {
e74cfd16
PB
22483 march_cpu_opt = &opt->value;
22484 march_fpu_opt = &opt->default_fpu;
5f4273c7 22485 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22486
c19d1205
ZW
22487 if (ext != NULL)
22488 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22489
c921be7d 22490 return TRUE;
c19d1205
ZW
22491 }
22492
22493 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22494 return FALSE;
7ed4c4c5 22495}
eb043451 22496
c921be7d 22497static bfd_boolean
c19d1205
ZW
22498arm_parse_fpu (char * str)
22499{
e74cfd16 22500 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22501
c19d1205
ZW
22502 for (opt = arm_fpus; opt->name != NULL; opt++)
22503 if (streq (opt->name, str))
22504 {
e74cfd16 22505 mfpu_opt = &opt->value;
c921be7d 22506 return TRUE;
c19d1205 22507 }
b99bd4ef 22508
c19d1205 22509 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22510 return FALSE;
c19d1205
ZW
22511}
22512
c921be7d 22513static bfd_boolean
c19d1205 22514arm_parse_float_abi (char * str)
b99bd4ef 22515{
e74cfd16 22516 const struct arm_option_value_table * opt;
b99bd4ef 22517
c19d1205
ZW
22518 for (opt = arm_float_abis; opt->name != NULL; opt++)
22519 if (streq (opt->name, str))
22520 {
22521 mfloat_abi_opt = opt->value;
c921be7d 22522 return TRUE;
c19d1205 22523 }
cc8a6dd0 22524
c19d1205 22525 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22526 return FALSE;
c19d1205 22527}
b99bd4ef 22528
c19d1205 22529#ifdef OBJ_ELF
c921be7d 22530static bfd_boolean
c19d1205
ZW
22531arm_parse_eabi (char * str)
22532{
e74cfd16 22533 const struct arm_option_value_table *opt;
cc8a6dd0 22534
c19d1205
ZW
22535 for (opt = arm_eabis; opt->name != NULL; opt++)
22536 if (streq (opt->name, str))
22537 {
22538 meabi_flags = opt->value;
c921be7d 22539 return TRUE;
c19d1205
ZW
22540 }
22541 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22542 return FALSE;
c19d1205
ZW
22543}
22544#endif
cc8a6dd0 22545
c921be7d 22546static bfd_boolean
e07e6e58
NC
22547arm_parse_it_mode (char * str)
22548{
c921be7d 22549 bfd_boolean ret = TRUE;
e07e6e58
NC
22550
22551 if (streq ("arm", str))
22552 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22553 else if (streq ("thumb", str))
22554 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22555 else if (streq ("always", str))
22556 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22557 else if (streq ("never", str))
22558 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22559 else
22560 {
22561 as_bad (_("unknown implicit IT mode `%s', should be "\
22562 "arm, thumb, always, or never."), str);
c921be7d 22563 ret = FALSE;
e07e6e58
NC
22564 }
22565
22566 return ret;
22567}
22568
c19d1205
ZW
22569struct arm_long_option_table arm_long_opts[] =
22570{
22571 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22572 arm_parse_cpu, NULL},
22573 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22574 arm_parse_arch, NULL},
22575 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22576 arm_parse_fpu, NULL},
22577 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22578 arm_parse_float_abi, NULL},
22579#ifdef OBJ_ELF
7fac0536 22580 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22581 arm_parse_eabi, NULL},
22582#endif
e07e6e58
NC
22583 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22584 arm_parse_it_mode, NULL},
c19d1205
ZW
22585 {NULL, NULL, 0, NULL}
22586};
cc8a6dd0 22587
c19d1205
ZW
22588int
22589md_parse_option (int c, char * arg)
22590{
22591 struct arm_option_table *opt;
e74cfd16 22592 const struct arm_legacy_option_table *fopt;
c19d1205 22593 struct arm_long_option_table *lopt;
b99bd4ef 22594
c19d1205 22595 switch (c)
b99bd4ef 22596 {
c19d1205
ZW
22597#ifdef OPTION_EB
22598 case OPTION_EB:
22599 target_big_endian = 1;
22600 break;
22601#endif
cc8a6dd0 22602
c19d1205
ZW
22603#ifdef OPTION_EL
22604 case OPTION_EL:
22605 target_big_endian = 0;
22606 break;
22607#endif
b99bd4ef 22608
845b51d6
PB
22609 case OPTION_FIX_V4BX:
22610 fix_v4bx = TRUE;
22611 break;
22612
c19d1205
ZW
22613 case 'a':
22614 /* Listing option. Just ignore these, we don't support additional
22615 ones. */
22616 return 0;
b99bd4ef 22617
c19d1205
ZW
22618 default:
22619 for (opt = arm_opts; opt->option != NULL; opt++)
22620 {
22621 if (c == opt->option[0]
22622 && ((arg == NULL && opt->option[1] == 0)
22623 || streq (arg, opt->option + 1)))
22624 {
c19d1205 22625 /* If the option is deprecated, tell the user. */
278df34e 22626 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22627 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22628 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22629
c19d1205
ZW
22630 if (opt->var != NULL)
22631 *opt->var = opt->value;
cc8a6dd0 22632
c19d1205
ZW
22633 return 1;
22634 }
22635 }
b99bd4ef 22636
e74cfd16
PB
22637 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22638 {
22639 if (c == fopt->option[0]
22640 && ((arg == NULL && fopt->option[1] == 0)
22641 || streq (arg, fopt->option + 1)))
22642 {
e74cfd16 22643 /* If the option is deprecated, tell the user. */
278df34e 22644 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22645 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22646 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22647
22648 if (fopt->var != NULL)
22649 *fopt->var = &fopt->value;
22650
22651 return 1;
22652 }
22653 }
22654
c19d1205
ZW
22655 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22656 {
22657 /* These options are expected to have an argument. */
22658 if (c == lopt->option[0]
22659 && arg != NULL
22660 && strncmp (arg, lopt->option + 1,
22661 strlen (lopt->option + 1)) == 0)
22662 {
c19d1205 22663 /* If the option is deprecated, tell the user. */
278df34e 22664 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22665 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22666 _(lopt->deprecated));
b99bd4ef 22667
c19d1205
ZW
22668 /* Call the sup-option parser. */
22669 return lopt->func (arg + strlen (lopt->option) - 1);
22670 }
22671 }
a737bd4d 22672
c19d1205
ZW
22673 return 0;
22674 }
a394c00f 22675
c19d1205
ZW
22676 return 1;
22677}
a394c00f 22678
c19d1205
ZW
22679void
22680md_show_usage (FILE * fp)
a394c00f 22681{
c19d1205
ZW
22682 struct arm_option_table *opt;
22683 struct arm_long_option_table *lopt;
a394c00f 22684
c19d1205 22685 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22686
c19d1205
ZW
22687 for (opt = arm_opts; opt->option != NULL; opt++)
22688 if (opt->help != NULL)
22689 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22690
c19d1205
ZW
22691 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22692 if (lopt->help != NULL)
22693 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22694
c19d1205
ZW
22695#ifdef OPTION_EB
22696 fprintf (fp, _("\
22697 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22698#endif
22699
c19d1205
ZW
22700#ifdef OPTION_EL
22701 fprintf (fp, _("\
22702 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22703#endif
845b51d6
PB
22704
22705 fprintf (fp, _("\
22706 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22707}
ee065d83
PB
22708
22709
22710#ifdef OBJ_ELF
62b3e311
PB
22711typedef struct
22712{
22713 int val;
22714 arm_feature_set flags;
22715} cpu_arch_ver_table;
22716
22717/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22718 least features first. */
22719static const cpu_arch_ver_table cpu_arch_ver[] =
22720{
22721 {1, ARM_ARCH_V4},
22722 {2, ARM_ARCH_V4T},
22723 {3, ARM_ARCH_V5},
ee3c0378 22724 {3, ARM_ARCH_V5T},
62b3e311
PB
22725 {4, ARM_ARCH_V5TE},
22726 {5, ARM_ARCH_V5TEJ},
22727 {6, ARM_ARCH_V6},
22728 {7, ARM_ARCH_V6Z},
7e806470 22729 {9, ARM_ARCH_V6K},
91e22acd 22730 {11, ARM_ARCH_V6M},
7e806470 22731 {8, ARM_ARCH_V6T2},
62b3e311
PB
22732 {10, ARM_ARCH_V7A},
22733 {10, ARM_ARCH_V7R},
22734 {10, ARM_ARCH_V7M},
22735 {0, ARM_ARCH_NONE}
22736};
22737
ee3c0378
AS
22738/* Set an attribute if it has not already been set by the user. */
22739static void
22740aeabi_set_attribute_int (int tag, int value)
22741{
22742 if (tag < 1
22743 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22744 || !attributes_set_explicitly[tag])
22745 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22746}
22747
22748static void
22749aeabi_set_attribute_string (int tag, const char *value)
22750{
22751 if (tag < 1
22752 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22753 || !attributes_set_explicitly[tag])
22754 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22755}
22756
ee065d83
PB
22757/* Set the public EABI object attributes. */
22758static void
22759aeabi_set_public_attributes (void)
22760{
22761 int arch;
e74cfd16 22762 arm_feature_set flags;
62b3e311
PB
22763 arm_feature_set tmp;
22764 const cpu_arch_ver_table *p;
ee065d83
PB
22765
22766 /* Choose the architecture based on the capabilities of the requested cpu
22767 (if any) and/or the instructions actually used. */
e74cfd16
PB
22768 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22769 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22770 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22771 /*Allow the user to override the reported architecture. */
22772 if (object_arch)
22773 {
22774 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22775 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22776 }
22777
62b3e311
PB
22778 tmp = flags;
22779 arch = 0;
22780 for (p = cpu_arch_ver; p->val; p++)
22781 {
22782 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22783 {
22784 arch = p->val;
22785 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22786 }
22787 }
ee065d83 22788
9e3c6df6
PB
22789 /* The table lookup above finds the last architecture to contribute
22790 a new feature. Unfortunately, Tag13 is a subset of the union of
22791 v6T2 and v7-M, so it is never seen as contributing a new feature.
22792 We can not search for the last entry which is entirely used,
22793 because if no CPU is specified we build up only those flags
22794 actually used. Perhaps we should separate out the specified
22795 and implicit cases. Avoid taking this path for -march=all by
22796 checking for contradictory v7-A / v7-M features. */
22797 if (arch == 10
22798 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22799 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22800 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22801 arch = 13;
22802
ee065d83
PB
22803 /* Tag_CPU_name. */
22804 if (selected_cpu_name[0])
22805 {
91d6fa6a 22806 char *q;
ee065d83 22807
91d6fa6a
NC
22808 q = selected_cpu_name;
22809 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
22810 {
22811 int i;
5f4273c7 22812
91d6fa6a
NC
22813 q += 4;
22814 for (i = 0; q[i]; i++)
22815 q[i] = TOUPPER (q[i]);
ee065d83 22816 }
91d6fa6a 22817 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 22818 }
62f3b8c8 22819
ee065d83 22820 /* Tag_CPU_arch. */
ee3c0378 22821 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 22822
62b3e311
PB
22823 /* Tag_CPU_arch_profile. */
22824 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22825 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22826 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22827 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22828 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22829 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 22830
ee065d83 22831 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22832 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22833 || arch == 0)
22834 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 22835
ee065d83 22836 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22837 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22838 || arch == 0)
22839 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22840 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 22841
ee065d83 22842 /* Tag_VFP_arch. */
62f3b8c8
PB
22843 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22844 aeabi_set_attribute_int (Tag_VFP_arch,
22845 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22846 ? 5 : 6);
22847 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 22848 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 22849 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
22850 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22851 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22852 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22853 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22854 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22855 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 22856
4547cb56
NC
22857 /* Tag_ABI_HardFP_use. */
22858 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
22859 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
22860 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
22861
ee065d83 22862 /* Tag_WMMX_arch. */
ee3c0378
AS
22863 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22864 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22865 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22866 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 22867
ee3c0378 22868 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22869 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
22870 aeabi_set_attribute_int
22871 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22872 ? 2 : 1));
22873
ee3c0378 22874 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 22875 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 22876 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
22877
22878 /* Tag_DIV_use. */
22879 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
22880 aeabi_set_attribute_int (Tag_DIV_use, 0);
22881 /* Fill this in when gas supports v7a sdiv/udiv.
22882 else if (... v7a with div extension used ...)
22883 aeabi_set_attribute_int (Tag_DIV_use, 2); */
22884 else
22885 aeabi_set_attribute_int (Tag_DIV_use, 1);
ee065d83
PB
22886}
22887
104d59d1 22888/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22889void
22890arm_md_end (void)
22891{
ee065d83
PB
22892 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22893 return;
22894
22895 aeabi_set_public_attributes ();
ee065d83 22896}
8463be01 22897#endif /* OBJ_ELF */
ee065d83
PB
22898
22899
22900/* Parse a .cpu directive. */
22901
22902static void
22903s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22904{
e74cfd16 22905 const struct arm_cpu_option_table *opt;
ee065d83
PB
22906 char *name;
22907 char saved_char;
22908
22909 name = input_line_pointer;
5f4273c7 22910 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22911 input_line_pointer++;
22912 saved_char = *input_line_pointer;
22913 *input_line_pointer = 0;
22914
22915 /* Skip the first "all" entry. */
22916 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22917 if (streq (opt->name, name))
22918 {
e74cfd16
PB
22919 mcpu_cpu_opt = &opt->value;
22920 selected_cpu = opt->value;
ee065d83 22921 if (opt->canonical_name)
5f4273c7 22922 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22923 else
22924 {
22925 int i;
22926 for (i = 0; opt->name[i]; i++)
22927 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22928 selected_cpu_name[i] = 0;
22929 }
e74cfd16 22930 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22931 *input_line_pointer = saved_char;
22932 demand_empty_rest_of_line ();
22933 return;
22934 }
22935 as_bad (_("unknown cpu `%s'"), name);
22936 *input_line_pointer = saved_char;
22937 ignore_rest_of_line ();
22938}
22939
22940
22941/* Parse a .arch directive. */
22942
22943static void
22944s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22945{
e74cfd16 22946 const struct arm_arch_option_table *opt;
ee065d83
PB
22947 char saved_char;
22948 char *name;
22949
22950 name = input_line_pointer;
5f4273c7 22951 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22952 input_line_pointer++;
22953 saved_char = *input_line_pointer;
22954 *input_line_pointer = 0;
22955
22956 /* Skip the first "all" entry. */
22957 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22958 if (streq (opt->name, name))
22959 {
e74cfd16
PB
22960 mcpu_cpu_opt = &opt->value;
22961 selected_cpu = opt->value;
5f4273c7 22962 strcpy (selected_cpu_name, opt->name);
e74cfd16 22963 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22964 *input_line_pointer = saved_char;
22965 demand_empty_rest_of_line ();
22966 return;
22967 }
22968
22969 as_bad (_("unknown architecture `%s'\n"), name);
22970 *input_line_pointer = saved_char;
22971 ignore_rest_of_line ();
22972}
22973
22974
7a1d4c38
PB
22975/* Parse a .object_arch directive. */
22976
22977static void
22978s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22979{
22980 const struct arm_arch_option_table *opt;
22981 char saved_char;
22982 char *name;
22983
22984 name = input_line_pointer;
5f4273c7 22985 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22986 input_line_pointer++;
22987 saved_char = *input_line_pointer;
22988 *input_line_pointer = 0;
22989
22990 /* Skip the first "all" entry. */
22991 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22992 if (streq (opt->name, name))
22993 {
22994 object_arch = &opt->value;
22995 *input_line_pointer = saved_char;
22996 demand_empty_rest_of_line ();
22997 return;
22998 }
22999
23000 as_bad (_("unknown architecture `%s'\n"), name);
23001 *input_line_pointer = saved_char;
23002 ignore_rest_of_line ();
23003}
23004
ee065d83
PB
23005/* Parse a .fpu directive. */
23006
23007static void
23008s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23009{
e74cfd16 23010 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
23011 char saved_char;
23012 char *name;
23013
23014 name = input_line_pointer;
5f4273c7 23015 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23016 input_line_pointer++;
23017 saved_char = *input_line_pointer;
23018 *input_line_pointer = 0;
5f4273c7 23019
ee065d83
PB
23020 for (opt = arm_fpus; opt->name != NULL; opt++)
23021 if (streq (opt->name, name))
23022 {
e74cfd16
PB
23023 mfpu_opt = &opt->value;
23024 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23025 *input_line_pointer = saved_char;
23026 demand_empty_rest_of_line ();
23027 return;
23028 }
23029
23030 as_bad (_("unknown floating point format `%s'\n"), name);
23031 *input_line_pointer = saved_char;
23032 ignore_rest_of_line ();
23033}
ee065d83 23034
794ba86a 23035/* Copy symbol information. */
f31fef98 23036
794ba86a
DJ
23037void
23038arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23039{
23040 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23041}
e04befd0 23042
f31fef98 23043#ifdef OBJ_ELF
e04befd0
AS
23044/* Given a symbolic attribute NAME, return the proper integer value.
23045 Returns -1 if the attribute is not known. */
f31fef98 23046
e04befd0
AS
23047int
23048arm_convert_symbolic_attribute (const char *name)
23049{
f31fef98
NC
23050 static const struct
23051 {
23052 const char * name;
23053 const int tag;
23054 }
23055 attribute_table[] =
23056 {
23057 /* When you modify this table you should
23058 also modify the list in doc/c-arm.texi. */
e04befd0 23059#define T(tag) {#tag, tag}
f31fef98
NC
23060 T (Tag_CPU_raw_name),
23061 T (Tag_CPU_name),
23062 T (Tag_CPU_arch),
23063 T (Tag_CPU_arch_profile),
23064 T (Tag_ARM_ISA_use),
23065 T (Tag_THUMB_ISA_use),
75375b3e 23066 T (Tag_FP_arch),
f31fef98
NC
23067 T (Tag_VFP_arch),
23068 T (Tag_WMMX_arch),
23069 T (Tag_Advanced_SIMD_arch),
23070 T (Tag_PCS_config),
23071 T (Tag_ABI_PCS_R9_use),
23072 T (Tag_ABI_PCS_RW_data),
23073 T (Tag_ABI_PCS_RO_data),
23074 T (Tag_ABI_PCS_GOT_use),
23075 T (Tag_ABI_PCS_wchar_t),
23076 T (Tag_ABI_FP_rounding),
23077 T (Tag_ABI_FP_denormal),
23078 T (Tag_ABI_FP_exceptions),
23079 T (Tag_ABI_FP_user_exceptions),
23080 T (Tag_ABI_FP_number_model),
75375b3e 23081 T (Tag_ABI_align_needed),
f31fef98 23082 T (Tag_ABI_align8_needed),
75375b3e 23083 T (Tag_ABI_align_preserved),
f31fef98
NC
23084 T (Tag_ABI_align8_preserved),
23085 T (Tag_ABI_enum_size),
23086 T (Tag_ABI_HardFP_use),
23087 T (Tag_ABI_VFP_args),
23088 T (Tag_ABI_WMMX_args),
23089 T (Tag_ABI_optimization_goals),
23090 T (Tag_ABI_FP_optimization_goals),
23091 T (Tag_compatibility),
23092 T (Tag_CPU_unaligned_access),
75375b3e 23093 T (Tag_FP_HP_extension),
f31fef98
NC
23094 T (Tag_VFP_HP_extension),
23095 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23096 T (Tag_MPextension_use),
23097 T (Tag_DIV_use),
f31fef98
NC
23098 T (Tag_nodefaults),
23099 T (Tag_also_compatible_with),
23100 T (Tag_conformance),
23101 T (Tag_T2EE_use),
23102 T (Tag_Virtualization_use),
cd21e546 23103 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23104#undef T
f31fef98 23105 };
e04befd0
AS
23106 unsigned int i;
23107
23108 if (name == NULL)
23109 return -1;
23110
f31fef98 23111 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23112 if (streq (name, attribute_table[i].name))
e04befd0
AS
23113 return attribute_table[i].tag;
23114
23115 return -1;
23116}
267bf995
RR
23117
23118
23119/* Apply sym value for relocations only in the case that
23120 they are for local symbols and you have the respective
23121 architectural feature for blx and simple switches. */
23122int
23123arm_apply_sym_value (struct fix * fixP)
23124{
23125 if (fixP->fx_addsy
23126 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23127 && !S_IS_EXTERNAL (fixP->fx_addsy))
23128 {
23129 switch (fixP->fx_r_type)
23130 {
23131 case BFD_RELOC_ARM_PCREL_BLX:
23132 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23133 if (ARM_IS_FUNC (fixP->fx_addsy))
23134 return 1;
23135 break;
23136
23137 case BFD_RELOC_ARM_PCREL_CALL:
23138 case BFD_RELOC_THUMB_PCREL_BLX:
23139 if (THUMB_IS_FUNC (fixP->fx_addsy))
23140 return 1;
23141 break;
23142
23143 default:
23144 break;
23145 }
23146
23147 }
23148 return 0;
23149}
f31fef98 23150#endif /* OBJ_ELF */