daily update
[deliverable/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 5761 OP_RRnpcb, /* ARM register, not r15, in square brackets */
55881a11
MGD
5762 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5763 optional trailing ! */
c19d1205
ZW
5764 OP_RRw, /* ARM register, not r15, optional trailing ! */
5765 OP_RCP, /* Coprocessor number */
5766 OP_RCN, /* Coprocessor register */
5767 OP_RF, /* FPA register */
5768 OP_RVS, /* VFP single precision register */
5287ad62
JB
5769 OP_RVD, /* VFP double precision register (0..15) */
5770 OP_RND, /* Neon double precision register (0..31) */
5771 OP_RNQ, /* Neon quad precision register */
037e8744 5772 OP_RVSD, /* VFP single or double precision register */
5287ad62 5773 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5774 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5775 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5776 OP_RVC, /* VFP control register */
5777 OP_RMF, /* Maverick F register */
5778 OP_RMD, /* Maverick D register */
5779 OP_RMFX, /* Maverick FX register */
5780 OP_RMDX, /* Maverick DX register */
5781 OP_RMAX, /* Maverick AX register */
5782 OP_RMDS, /* Maverick DSPSC register */
5783 OP_RIWR, /* iWMMXt wR register */
5784 OP_RIWC, /* iWMMXt wC register */
5785 OP_RIWG, /* iWMMXt wCG register */
5786 OP_RXA, /* XScale accumulator register */
5787
5788 OP_REGLST, /* ARM register list */
5789 OP_VRSLST, /* VFP single-precision register list */
5790 OP_VRDLST, /* VFP double-precision register list */
037e8744 5791 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5792 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5793 OP_NSTRLST, /* Neon element/structure list */
5794
5287ad62 5795 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5796 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5797 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5798 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5799 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5800 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5801 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5802 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5803 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5804 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5805
5806 OP_I0, /* immediate zero */
c19d1205
ZW
5807 OP_I7, /* immediate value 0 .. 7 */
5808 OP_I15, /* 0 .. 15 */
5809 OP_I16, /* 1 .. 16 */
5287ad62 5810 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5811 OP_I31, /* 0 .. 31 */
5812 OP_I31w, /* 0 .. 31, optional trailing ! */
5813 OP_I32, /* 1 .. 32 */
5287ad62
JB
5814 OP_I32z, /* 0 .. 32 */
5815 OP_I63, /* 0 .. 63 */
c19d1205 5816 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5817 OP_I64, /* 1 .. 64 */
5818 OP_I64z, /* 0 .. 64 */
c19d1205 5819 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5820
5821 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5822 OP_I7b, /* 0 .. 7 */
5823 OP_I15b, /* 0 .. 15 */
5824 OP_I31b, /* 0 .. 31 */
5825
5826 OP_SH, /* shifter operand */
4962c51a 5827 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5828 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5829 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5830 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5831 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5832 OP_EXP, /* arbitrary expression */
5833 OP_EXPi, /* same, with optional immediate prefix */
5834 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5835 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5836
5837 OP_CPSF, /* CPS flags */
5838 OP_ENDI, /* Endianness specifier */
5839 OP_PSR, /* CPSR/SPSR mask for msr */
5840 OP_COND, /* conditional code */
92e90b6e 5841 OP_TB, /* Table branch. */
c19d1205 5842
037e8744
JB
5843 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5844 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5845
c19d1205
ZW
5846 OP_RRnpc_I0, /* ARM register or literal 0 */
5847 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5848 OP_RR_EXi, /* ARM register or expression with imm prefix */
5849 OP_RF_IF, /* FPA register or immediate */
5850 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5851 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5852
5853 /* Optional operands. */
5854 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5855 OP_oI31b, /* 0 .. 31 */
5287ad62 5856 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5857 OP_oIffffb, /* 0 .. 65535 */
5858 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5859
5860 OP_oRR, /* ARM register */
5861 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5862 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5863 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5864 OP_oRND, /* Optional Neon double precision register */
5865 OP_oRNQ, /* Optional Neon quad precision register */
5866 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5867 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5868 OP_oSHll, /* LSL immediate */
5869 OP_oSHar, /* ASR immediate */
5870 OP_oSHllar, /* LSL or ASR immediate */
5871 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5872 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205 5873
5be8be5d
DG
5874 /* Some pre-defined mixed (ARM/THUMB) operands. */
5875 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5876 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5877 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5878
c19d1205
ZW
5879 OP_FIRST_OPTIONAL = OP_oI7b
5880};
a737bd4d 5881
c19d1205
ZW
5882/* Generic instruction operand parser. This does no encoding and no
5883 semantic validation; it merely squirrels values away in the inst
5884 structure. Returns SUCCESS or FAIL depending on whether the
5885 specified grammar matched. */
5886static int
5be8be5d 5887parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5888{
5be8be5d 5889 unsigned const int *upat = pattern;
c19d1205
ZW
5890 char *backtrack_pos = 0;
5891 const char *backtrack_error = 0;
5892 int i, val, backtrack_index = 0;
5287ad62 5893 enum arm_reg_type rtype;
4962c51a 5894 parse_operand_result result;
5be8be5d 5895 unsigned int op_parse_code;
c19d1205 5896
e07e6e58
NC
5897#define po_char_or_fail(chr) \
5898 do \
5899 { \
5900 if (skip_past_char (&str, chr) == FAIL) \
5901 goto bad_args; \
5902 } \
5903 while (0)
c19d1205 5904
e07e6e58
NC
5905#define po_reg_or_fail(regtype) \
5906 do \
dcbf9037 5907 { \
e07e6e58
NC
5908 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5909 & inst.operands[i].vectype); \
5910 if (val == FAIL) \
5911 { \
5912 first_error (_(reg_expected_msgs[regtype])); \
5913 goto failure; \
5914 } \
5915 inst.operands[i].reg = val; \
5916 inst.operands[i].isreg = 1; \
5917 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5918 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5919 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5920 || rtype == REG_TYPE_VFD \
5921 || rtype == REG_TYPE_NQ); \
dcbf9037 5922 } \
e07e6e58
NC
5923 while (0)
5924
5925#define po_reg_or_goto(regtype, label) \
5926 do \
5927 { \
5928 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5929 & inst.operands[i].vectype); \
5930 if (val == FAIL) \
5931 goto label; \
dcbf9037 5932 \
e07e6e58
NC
5933 inst.operands[i].reg = val; \
5934 inst.operands[i].isreg = 1; \
5935 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5936 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5937 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5938 || rtype == REG_TYPE_VFD \
5939 || rtype == REG_TYPE_NQ); \
5940 } \
5941 while (0)
5942
5943#define po_imm_or_fail(min, max, popt) \
5944 do \
5945 { \
5946 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5947 goto failure; \
5948 inst.operands[i].imm = val; \
5949 } \
5950 while (0)
5951
5952#define po_scalar_or_goto(elsz, label) \
5953 do \
5954 { \
5955 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5956 if (val == FAIL) \
5957 goto label; \
5958 inst.operands[i].reg = val; \
5959 inst.operands[i].isscalar = 1; \
5960 } \
5961 while (0)
5962
5963#define po_misc_or_fail(expr) \
5964 do \
5965 { \
5966 if (expr) \
5967 goto failure; \
5968 } \
5969 while (0)
5970
5971#define po_misc_or_fail_no_backtrack(expr) \
5972 do \
5973 { \
5974 result = expr; \
5975 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5976 backtrack_pos = 0; \
5977 if (result != PARSE_OPERAND_SUCCESS) \
5978 goto failure; \
5979 } \
5980 while (0)
4962c51a 5981
c19d1205
ZW
5982 skip_whitespace (str);
5983
5984 for (i = 0; upat[i] != OP_stop; i++)
5985 {
5be8be5d
DG
5986 op_parse_code = upat[i];
5987 if (op_parse_code >= 1<<16)
5988 op_parse_code = thumb ? (op_parse_code >> 16)
5989 : (op_parse_code & ((1<<16)-1));
5990
5991 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
5992 {
5993 /* Remember where we are in case we need to backtrack. */
9c2799c2 5994 gas_assert (!backtrack_pos);
c19d1205
ZW
5995 backtrack_pos = str;
5996 backtrack_error = inst.error;
5997 backtrack_index = i;
5998 }
5999
b6702015 6000 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6001 po_char_or_fail (',');
6002
5be8be5d 6003 switch (op_parse_code)
c19d1205
ZW
6004 {
6005 /* Registers */
6006 case OP_oRRnpc:
5be8be5d 6007 case OP_oRRnpcsp:
c19d1205 6008 case OP_RRnpc:
5be8be5d 6009 case OP_RRnpcsp:
c19d1205
ZW
6010 case OP_oRR:
6011 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6012 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6013 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6014 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6015 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6016 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6017 case OP_oRND:
6018 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6019 case OP_RVC:
6020 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6021 break;
6022 /* Also accept generic coprocessor regs for unknown registers. */
6023 coproc_reg:
6024 po_reg_or_fail (REG_TYPE_CN);
6025 break;
c19d1205
ZW
6026 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6027 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6028 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6029 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6030 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6031 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6032 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6033 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6034 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6035 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6036 case OP_oRNQ:
6037 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6038 case OP_oRNDQ:
6039 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6040 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6041 case OP_oRNSDQ:
6042 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6043
6044 /* Neon scalar. Using an element size of 8 means that some invalid
6045 scalars are accepted here, so deal with those in later code. */
6046 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6047
5287ad62
JB
6048 case OP_RNDQ_I0:
6049 {
6050 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6051 break;
6052 try_imm0:
6053 po_imm_or_fail (0, 0, TRUE);
6054 }
6055 break;
6056
037e8744
JB
6057 case OP_RVSD_I0:
6058 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6059 break;
6060
5287ad62
JB
6061 case OP_RR_RNSC:
6062 {
6063 po_scalar_or_goto (8, try_rr);
6064 break;
6065 try_rr:
6066 po_reg_or_fail (REG_TYPE_RN);
6067 }
6068 break;
6069
037e8744
JB
6070 case OP_RNSDQ_RNSC:
6071 {
6072 po_scalar_or_goto (8, try_nsdq);
6073 break;
6074 try_nsdq:
6075 po_reg_or_fail (REG_TYPE_NSDQ);
6076 }
6077 break;
6078
5287ad62
JB
6079 case OP_RNDQ_RNSC:
6080 {
6081 po_scalar_or_goto (8, try_ndq);
6082 break;
6083 try_ndq:
6084 po_reg_or_fail (REG_TYPE_NDQ);
6085 }
6086 break;
6087
6088 case OP_RND_RNSC:
6089 {
6090 po_scalar_or_goto (8, try_vfd);
6091 break;
6092 try_vfd:
6093 po_reg_or_fail (REG_TYPE_VFD);
6094 }
6095 break;
6096
6097 case OP_VMOV:
6098 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6099 not careful then bad things might happen. */
6100 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6101 break;
6102
4316f0d2 6103 case OP_RNDQ_Ibig:
5287ad62 6104 {
4316f0d2 6105 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6106 break;
4316f0d2 6107 try_immbig:
5287ad62
JB
6108 /* There's a possibility of getting a 64-bit immediate here, so
6109 we need special handling. */
6110 if (parse_big_immediate (&str, i) == FAIL)
6111 {
6112 inst.error = _("immediate value is out of range");
6113 goto failure;
6114 }
6115 }
6116 break;
6117
6118 case OP_RNDQ_I63b:
6119 {
6120 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6121 break;
6122 try_shimm:
6123 po_imm_or_fail (0, 63, TRUE);
6124 }
6125 break;
c19d1205
ZW
6126
6127 case OP_RRnpcb:
6128 po_char_or_fail ('[');
6129 po_reg_or_fail (REG_TYPE_RN);
6130 po_char_or_fail (']');
6131 break;
a737bd4d 6132
55881a11 6133 case OP_RRnpctw:
c19d1205 6134 case OP_RRw:
b6702015 6135 case OP_oRRw:
c19d1205
ZW
6136 po_reg_or_fail (REG_TYPE_RN);
6137 if (skip_past_char (&str, '!') == SUCCESS)
6138 inst.operands[i].writeback = 1;
6139 break;
6140
6141 /* Immediates */
6142 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6143 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6144 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6145 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6146 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6147 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6148 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6149 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6150 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6151 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6152 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6153 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6154
6155 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6156 case OP_oI7b:
6157 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6158 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6159 case OP_oI31b:
6160 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6161 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6162 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6163
6164 /* Immediate variants */
6165 case OP_oI255c:
6166 po_char_or_fail ('{');
6167 po_imm_or_fail (0, 255, TRUE);
6168 po_char_or_fail ('}');
6169 break;
6170
6171 case OP_I31w:
6172 /* The expression parser chokes on a trailing !, so we have
6173 to find it first and zap it. */
6174 {
6175 char *s = str;
6176 while (*s && *s != ',')
6177 s++;
6178 if (s[-1] == '!')
6179 {
6180 s[-1] = '\0';
6181 inst.operands[i].writeback = 1;
6182 }
6183 po_imm_or_fail (0, 31, TRUE);
6184 if (str == s - 1)
6185 str = s;
6186 }
6187 break;
6188
6189 /* Expressions */
6190 case OP_EXPi: EXPi:
6191 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6192 GE_OPT_PREFIX));
6193 break;
6194
6195 case OP_EXP:
6196 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6197 GE_NO_PREFIX));
6198 break;
6199
6200 case OP_EXPr: EXPr:
6201 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6202 GE_NO_PREFIX));
6203 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6204 {
c19d1205
ZW
6205 val = parse_reloc (&str);
6206 if (val == -1)
6207 {
6208 inst.error = _("unrecognized relocation suffix");
6209 goto failure;
6210 }
6211 else if (val != BFD_RELOC_UNUSED)
6212 {
6213 inst.operands[i].imm = val;
6214 inst.operands[i].hasreloc = 1;
6215 }
a737bd4d 6216 }
c19d1205 6217 break;
a737bd4d 6218
b6895b4f
PB
6219 /* Operand for MOVW or MOVT. */
6220 case OP_HALF:
6221 po_misc_or_fail (parse_half (&str));
6222 break;
6223
e07e6e58 6224 /* Register or expression. */
c19d1205
ZW
6225 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6226 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6227
e07e6e58 6228 /* Register or immediate. */
c19d1205
ZW
6229 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6230 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6231
c19d1205
ZW
6232 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6233 IF:
6234 if (!is_immediate_prefix (*str))
6235 goto bad_args;
6236 str++;
6237 val = parse_fpa_immediate (&str);
6238 if (val == FAIL)
6239 goto failure;
6240 /* FPA immediates are encoded as registers 8-15.
6241 parse_fpa_immediate has already applied the offset. */
6242 inst.operands[i].reg = val;
6243 inst.operands[i].isreg = 1;
6244 break;
09d92015 6245
2d447fca
JM
6246 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6247 I32z: po_imm_or_fail (0, 32, FALSE); break;
6248
e07e6e58 6249 /* Two kinds of register. */
c19d1205
ZW
6250 case OP_RIWR_RIWC:
6251 {
6252 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6253 if (!rege
6254 || (rege->type != REG_TYPE_MMXWR
6255 && rege->type != REG_TYPE_MMXWC
6256 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6257 {
6258 inst.error = _("iWMMXt data or control register expected");
6259 goto failure;
6260 }
6261 inst.operands[i].reg = rege->number;
6262 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6263 }
6264 break;
09d92015 6265
41adaa5c
JM
6266 case OP_RIWC_RIWG:
6267 {
6268 struct reg_entry *rege = arm_reg_parse_multi (&str);
6269 if (!rege
6270 || (rege->type != REG_TYPE_MMXWC
6271 && rege->type != REG_TYPE_MMXWCG))
6272 {
6273 inst.error = _("iWMMXt control register expected");
6274 goto failure;
6275 }
6276 inst.operands[i].reg = rege->number;
6277 inst.operands[i].isreg = 1;
6278 }
6279 break;
6280
c19d1205
ZW
6281 /* Misc */
6282 case OP_CPSF: val = parse_cps_flags (&str); break;
6283 case OP_ENDI: val = parse_endian_specifier (&str); break;
6284 case OP_oROR: val = parse_ror (&str); break;
6285 case OP_PSR: val = parse_psr (&str); break;
6286 case OP_COND: val = parse_cond (&str); break;
62b3e311 6287 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6288
037e8744
JB
6289 case OP_RVC_PSR:
6290 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6291 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6292 break;
6293 try_psr:
6294 val = parse_psr (&str);
6295 break;
6296
6297 case OP_APSR_RR:
6298 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6299 break;
6300 try_apsr:
6301 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6302 instruction). */
6303 if (strncasecmp (str, "APSR_", 5) == 0)
6304 {
6305 unsigned found = 0;
6306 str += 5;
6307 while (found < 15)
6308 switch (*str++)
6309 {
6310 case 'c': found = (found & 1) ? 16 : found | 1; break;
6311 case 'n': found = (found & 2) ? 16 : found | 2; break;
6312 case 'z': found = (found & 4) ? 16 : found | 4; break;
6313 case 'v': found = (found & 8) ? 16 : found | 8; break;
6314 default: found = 16;
6315 }
6316 if (found != 15)
6317 goto failure;
6318 inst.operands[i].isvec = 1;
f7c21dc7
NC
6319 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6320 inst.operands[i].reg = REG_PC;
037e8744
JB
6321 }
6322 else
6323 goto failure;
6324 break;
6325
92e90b6e
PB
6326 case OP_TB:
6327 po_misc_or_fail (parse_tb (&str));
6328 break;
6329
e07e6e58 6330 /* Register lists. */
c19d1205
ZW
6331 case OP_REGLST:
6332 val = parse_reg_list (&str);
6333 if (*str == '^')
6334 {
6335 inst.operands[1].writeback = 1;
6336 str++;
6337 }
6338 break;
09d92015 6339
c19d1205 6340 case OP_VRSLST:
5287ad62 6341 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6342 break;
09d92015 6343
c19d1205 6344 case OP_VRDLST:
5287ad62 6345 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6346 break;
a737bd4d 6347
037e8744
JB
6348 case OP_VRSDLST:
6349 /* Allow Q registers too. */
6350 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6351 REGLIST_NEON_D);
6352 if (val == FAIL)
6353 {
6354 inst.error = NULL;
6355 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6356 REGLIST_VFP_S);
6357 inst.operands[i].issingle = 1;
6358 }
6359 break;
6360
5287ad62
JB
6361 case OP_NRDLST:
6362 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6363 REGLIST_NEON_D);
6364 break;
6365
6366 case OP_NSTRLST:
dcbf9037
JB
6367 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6368 &inst.operands[i].vectype);
5287ad62
JB
6369 break;
6370
c19d1205
ZW
6371 /* Addressing modes */
6372 case OP_ADDR:
6373 po_misc_or_fail (parse_address (&str, i));
6374 break;
09d92015 6375
4962c51a
MS
6376 case OP_ADDRGLDR:
6377 po_misc_or_fail_no_backtrack (
6378 parse_address_group_reloc (&str, i, GROUP_LDR));
6379 break;
6380
6381 case OP_ADDRGLDRS:
6382 po_misc_or_fail_no_backtrack (
6383 parse_address_group_reloc (&str, i, GROUP_LDRS));
6384 break;
6385
6386 case OP_ADDRGLDC:
6387 po_misc_or_fail_no_backtrack (
6388 parse_address_group_reloc (&str, i, GROUP_LDC));
6389 break;
6390
c19d1205
ZW
6391 case OP_SH:
6392 po_misc_or_fail (parse_shifter_operand (&str, i));
6393 break;
09d92015 6394
4962c51a
MS
6395 case OP_SHG:
6396 po_misc_or_fail_no_backtrack (
6397 parse_shifter_operand_group_reloc (&str, i));
6398 break;
6399
c19d1205
ZW
6400 case OP_oSHll:
6401 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6402 break;
09d92015 6403
c19d1205
ZW
6404 case OP_oSHar:
6405 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6406 break;
09d92015 6407
c19d1205
ZW
6408 case OP_oSHllar:
6409 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6410 break;
09d92015 6411
c19d1205 6412 default:
5be8be5d 6413 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6414 }
09d92015 6415
c19d1205
ZW
6416 /* Various value-based sanity checks and shared operations. We
6417 do not signal immediate failures for the register constraints;
6418 this allows a syntax error to take precedence. */
5be8be5d 6419 switch (op_parse_code)
c19d1205
ZW
6420 {
6421 case OP_oRRnpc:
6422 case OP_RRnpc:
6423 case OP_RRnpcb:
6424 case OP_RRw:
b6702015 6425 case OP_oRRw:
c19d1205
ZW
6426 case OP_RRnpc_I0:
6427 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6428 inst.error = BAD_PC;
6429 break;
09d92015 6430
5be8be5d
DG
6431 case OP_oRRnpcsp:
6432 case OP_RRnpcsp:
6433 if (inst.operands[i].isreg)
6434 {
6435 if (inst.operands[i].reg == REG_PC)
6436 inst.error = BAD_PC;
6437 else if (inst.operands[i].reg == REG_SP)
6438 inst.error = BAD_SP;
6439 }
6440 break;
6441
55881a11
MGD
6442 case OP_RRnpctw:
6443 if (inst.operands[i].isreg
6444 && inst.operands[i].reg == REG_PC
6445 && (inst.operands[i].writeback || thumb))
6446 inst.error = BAD_PC;
6447 break;
6448
c19d1205
ZW
6449 case OP_CPSF:
6450 case OP_ENDI:
6451 case OP_oROR:
6452 case OP_PSR:
037e8744 6453 case OP_RVC_PSR:
c19d1205 6454 case OP_COND:
62b3e311 6455 case OP_oBARRIER:
c19d1205
ZW
6456 case OP_REGLST:
6457 case OP_VRSLST:
6458 case OP_VRDLST:
037e8744 6459 case OP_VRSDLST:
5287ad62
JB
6460 case OP_NRDLST:
6461 case OP_NSTRLST:
c19d1205
ZW
6462 if (val == FAIL)
6463 goto failure;
6464 inst.operands[i].imm = val;
6465 break;
a737bd4d 6466
c19d1205
ZW
6467 default:
6468 break;
6469 }
09d92015 6470
c19d1205
ZW
6471 /* If we get here, this operand was successfully parsed. */
6472 inst.operands[i].present = 1;
6473 continue;
09d92015 6474
c19d1205 6475 bad_args:
09d92015 6476 inst.error = BAD_ARGS;
c19d1205
ZW
6477
6478 failure:
6479 if (!backtrack_pos)
d252fdde
PB
6480 {
6481 /* The parse routine should already have set inst.error, but set a
5f4273c7 6482 default here just in case. */
d252fdde
PB
6483 if (!inst.error)
6484 inst.error = _("syntax error");
6485 return FAIL;
6486 }
c19d1205
ZW
6487
6488 /* Do not backtrack over a trailing optional argument that
6489 absorbed some text. We will only fail again, with the
6490 'garbage following instruction' error message, which is
6491 probably less helpful than the current one. */
6492 if (backtrack_index == i && backtrack_pos != str
6493 && upat[i+1] == OP_stop)
d252fdde
PB
6494 {
6495 if (!inst.error)
6496 inst.error = _("syntax error");
6497 return FAIL;
6498 }
c19d1205
ZW
6499
6500 /* Try again, skipping the optional argument at backtrack_pos. */
6501 str = backtrack_pos;
6502 inst.error = backtrack_error;
6503 inst.operands[backtrack_index].present = 0;
6504 i = backtrack_index;
6505 backtrack_pos = 0;
09d92015 6506 }
09d92015 6507
c19d1205
ZW
6508 /* Check that we have parsed all the arguments. */
6509 if (*str != '\0' && !inst.error)
6510 inst.error = _("garbage following instruction");
09d92015 6511
c19d1205 6512 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6513}
6514
c19d1205
ZW
6515#undef po_char_or_fail
6516#undef po_reg_or_fail
6517#undef po_reg_or_goto
6518#undef po_imm_or_fail
5287ad62 6519#undef po_scalar_or_fail
e07e6e58 6520
c19d1205 6521/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6522#define constraint(expr, err) \
6523 do \
c19d1205 6524 { \
e07e6e58
NC
6525 if (expr) \
6526 { \
6527 inst.error = err; \
6528 return; \
6529 } \
c19d1205 6530 } \
e07e6e58 6531 while (0)
c19d1205 6532
fdfde340
JM
6533/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6534 instructions are unpredictable if these registers are used. This
6535 is the BadReg predicate in ARM's Thumb-2 documentation. */
6536#define reject_bad_reg(reg) \
6537 do \
6538 if (reg == REG_SP || reg == REG_PC) \
6539 { \
6540 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6541 return; \
6542 } \
6543 while (0)
6544
94206790
MM
6545/* If REG is R13 (the stack pointer), warn that its use is
6546 deprecated. */
6547#define warn_deprecated_sp(reg) \
6548 do \
6549 if (warn_on_deprecated && reg == REG_SP) \
6550 as_warn (_("use of r13 is deprecated")); \
6551 while (0)
6552
c19d1205
ZW
6553/* Functions for operand encoding. ARM, then Thumb. */
6554
6555#define rotate_left(v, n) (v << n | v >> (32 - n))
6556
6557/* If VAL can be encoded in the immediate field of an ARM instruction,
6558 return the encoded form. Otherwise, return FAIL. */
6559
6560static unsigned int
6561encode_arm_immediate (unsigned int val)
09d92015 6562{
c19d1205
ZW
6563 unsigned int a, i;
6564
6565 for (i = 0; i < 32; i += 2)
6566 if ((a = rotate_left (val, i)) <= 0xff)
6567 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6568
6569 return FAIL;
09d92015
MM
6570}
6571
c19d1205
ZW
6572/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6573 return the encoded form. Otherwise, return FAIL. */
6574static unsigned int
6575encode_thumb32_immediate (unsigned int val)
09d92015 6576{
c19d1205 6577 unsigned int a, i;
09d92015 6578
9c3c69f2 6579 if (val <= 0xff)
c19d1205 6580 return val;
a737bd4d 6581
9c3c69f2 6582 for (i = 1; i <= 24; i++)
09d92015 6583 {
9c3c69f2
PB
6584 a = val >> i;
6585 if ((val & ~(0xff << i)) == 0)
6586 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6587 }
a737bd4d 6588
c19d1205
ZW
6589 a = val & 0xff;
6590 if (val == ((a << 16) | a))
6591 return 0x100 | a;
6592 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6593 return 0x300 | a;
09d92015 6594
c19d1205
ZW
6595 a = val & 0xff00;
6596 if (val == ((a << 16) | a))
6597 return 0x200 | (a >> 8);
a737bd4d 6598
c19d1205 6599 return FAIL;
09d92015 6600}
5287ad62 6601/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6602
6603static void
5287ad62
JB
6604encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6605{
6606 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6607 && reg > 15)
6608 {
b1cc4aeb 6609 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6610 {
6611 if (thumb_mode)
6612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6613 fpu_vfp_ext_d32);
5287ad62
JB
6614 else
6615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6616 fpu_vfp_ext_d32);
5287ad62
JB
6617 }
6618 else
6619 {
dcbf9037 6620 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6621 return;
6622 }
6623 }
6624
c19d1205 6625 switch (pos)
09d92015 6626 {
c19d1205
ZW
6627 case VFP_REG_Sd:
6628 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6629 break;
6630
6631 case VFP_REG_Sn:
6632 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6633 break;
6634
6635 case VFP_REG_Sm:
6636 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6637 break;
6638
5287ad62
JB
6639 case VFP_REG_Dd:
6640 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6641 break;
5f4273c7 6642
5287ad62
JB
6643 case VFP_REG_Dn:
6644 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6645 break;
5f4273c7 6646
5287ad62
JB
6647 case VFP_REG_Dm:
6648 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6649 break;
6650
c19d1205
ZW
6651 default:
6652 abort ();
09d92015 6653 }
09d92015
MM
6654}
6655
c19d1205 6656/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6657 if any, is handled by md_apply_fix. */
09d92015 6658static void
c19d1205 6659encode_arm_shift (int i)
09d92015 6660{
c19d1205
ZW
6661 if (inst.operands[i].shift_kind == SHIFT_RRX)
6662 inst.instruction |= SHIFT_ROR << 5;
6663 else
09d92015 6664 {
c19d1205
ZW
6665 inst.instruction |= inst.operands[i].shift_kind << 5;
6666 if (inst.operands[i].immisreg)
6667 {
6668 inst.instruction |= SHIFT_BY_REG;
6669 inst.instruction |= inst.operands[i].imm << 8;
6670 }
6671 else
6672 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6673 }
c19d1205 6674}
09d92015 6675
c19d1205
ZW
6676static void
6677encode_arm_shifter_operand (int i)
6678{
6679 if (inst.operands[i].isreg)
09d92015 6680 {
c19d1205
ZW
6681 inst.instruction |= inst.operands[i].reg;
6682 encode_arm_shift (i);
09d92015 6683 }
c19d1205
ZW
6684 else
6685 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6686}
6687
c19d1205 6688/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6689static void
c19d1205 6690encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6691{
9c2799c2 6692 gas_assert (inst.operands[i].isreg);
c19d1205 6693 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6694
c19d1205 6695 if (inst.operands[i].preind)
09d92015 6696 {
c19d1205
ZW
6697 if (is_t)
6698 {
6699 inst.error = _("instruction does not accept preindexed addressing");
6700 return;
6701 }
6702 inst.instruction |= PRE_INDEX;
6703 if (inst.operands[i].writeback)
6704 inst.instruction |= WRITE_BACK;
09d92015 6705
c19d1205
ZW
6706 }
6707 else if (inst.operands[i].postind)
6708 {
9c2799c2 6709 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6710 if (is_t)
6711 inst.instruction |= WRITE_BACK;
6712 }
6713 else /* unindexed - only for coprocessor */
09d92015 6714 {
c19d1205 6715 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6716 return;
6717 }
6718
c19d1205
ZW
6719 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6720 && (((inst.instruction & 0x000f0000) >> 16)
6721 == ((inst.instruction & 0x0000f000) >> 12)))
6722 as_warn ((inst.instruction & LOAD_BIT)
6723 ? _("destination register same as write-back base")
6724 : _("source register same as write-back base"));
09d92015
MM
6725}
6726
c19d1205
ZW
6727/* inst.operands[i] was set up by parse_address. Encode it into an
6728 ARM-format mode 2 load or store instruction. If is_t is true,
6729 reject forms that cannot be used with a T instruction (i.e. not
6730 post-indexed). */
a737bd4d 6731static void
c19d1205 6732encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6733{
5be8be5d
DG
6734 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6735
c19d1205 6736 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6737
c19d1205 6738 if (inst.operands[i].immisreg)
09d92015 6739 {
5be8be5d
DG
6740 constraint ((inst.operands[i].imm == REG_PC
6741 || (is_pc && inst.operands[i].writeback)),
6742 BAD_PC_ADDRESSING);
c19d1205
ZW
6743 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6744 inst.instruction |= inst.operands[i].imm;
6745 if (!inst.operands[i].negative)
6746 inst.instruction |= INDEX_UP;
6747 if (inst.operands[i].shifted)
6748 {
6749 if (inst.operands[i].shift_kind == SHIFT_RRX)
6750 inst.instruction |= SHIFT_ROR << 5;
6751 else
6752 {
6753 inst.instruction |= inst.operands[i].shift_kind << 5;
6754 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6755 }
6756 }
09d92015 6757 }
c19d1205 6758 else /* immediate offset in inst.reloc */
09d92015 6759 {
5be8be5d
DG
6760 if (is_pc && !inst.reloc.pc_rel)
6761 {
6762 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6763 /* BAD_PC_ADDRESSING Condition =
6764 is_load => is_t
6765 which becomes !is_load || is_t. */
6766 constraint ((!is_load || is_t),
6767 BAD_PC_ADDRESSING);
6768 }
6769
c19d1205
ZW
6770 if (inst.reloc.type == BFD_RELOC_UNUSED)
6771 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6772 }
09d92015
MM
6773}
6774
c19d1205
ZW
6775/* inst.operands[i] was set up by parse_address. Encode it into an
6776 ARM-format mode 3 load or store instruction. Reject forms that
6777 cannot be used with such instructions. If is_t is true, reject
6778 forms that cannot be used with a T instruction (i.e. not
6779 post-indexed). */
6780static void
6781encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6782{
c19d1205 6783 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6784 {
c19d1205
ZW
6785 inst.error = _("instruction does not accept scaled register index");
6786 return;
09d92015 6787 }
a737bd4d 6788
c19d1205 6789 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6790
c19d1205
ZW
6791 if (inst.operands[i].immisreg)
6792 {
5be8be5d
DG
6793 constraint ((inst.operands[i].imm == REG_PC
6794 || inst.operands[i].reg == REG_PC),
6795 BAD_PC_ADDRESSING);
c19d1205
ZW
6796 inst.instruction |= inst.operands[i].imm;
6797 if (!inst.operands[i].negative)
6798 inst.instruction |= INDEX_UP;
6799 }
6800 else /* immediate offset in inst.reloc */
6801 {
5be8be5d
DG
6802 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6803 && inst.operands[i].writeback),
6804 BAD_PC_WRITEBACK);
c19d1205
ZW
6805 inst.instruction |= HWOFFSET_IMM;
6806 if (inst.reloc.type == BFD_RELOC_UNUSED)
6807 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6808 }
a737bd4d
NC
6809}
6810
c19d1205
ZW
6811/* inst.operands[i] was set up by parse_address. Encode it into an
6812 ARM-format instruction. Reject all forms which cannot be encoded
6813 into a coprocessor load/store instruction. If wb_ok is false,
6814 reject use of writeback; if unind_ok is false, reject use of
6815 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6816 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6817 (in which case it is preserved). */
09d92015 6818
c19d1205
ZW
6819static int
6820encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6821{
c19d1205 6822 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6823
9c2799c2 6824 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6825
c19d1205 6826 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6827 {
9c2799c2 6828 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6829 if (!unind_ok)
6830 {
6831 inst.error = _("instruction does not support unindexed addressing");
6832 return FAIL;
6833 }
6834 inst.instruction |= inst.operands[i].imm;
6835 inst.instruction |= INDEX_UP;
6836 return SUCCESS;
09d92015 6837 }
a737bd4d 6838
c19d1205
ZW
6839 if (inst.operands[i].preind)
6840 inst.instruction |= PRE_INDEX;
a737bd4d 6841
c19d1205 6842 if (inst.operands[i].writeback)
09d92015 6843 {
c19d1205
ZW
6844 if (inst.operands[i].reg == REG_PC)
6845 {
6846 inst.error = _("pc may not be used with write-back");
6847 return FAIL;
6848 }
6849 if (!wb_ok)
6850 {
6851 inst.error = _("instruction does not support writeback");
6852 return FAIL;
6853 }
6854 inst.instruction |= WRITE_BACK;
09d92015 6855 }
a737bd4d 6856
c19d1205 6857 if (reloc_override)
21d799b5 6858 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6859 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6860 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6861 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6862 {
6863 if (thumb_mode)
6864 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6865 else
6866 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6867 }
6868
c19d1205
ZW
6869 return SUCCESS;
6870}
a737bd4d 6871
c19d1205
ZW
6872/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6873 Determine whether it can be performed with a move instruction; if
6874 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6875 return TRUE; if it can't, convert inst.instruction to a literal-pool
6876 load and return FALSE. If this is not a valid thing to do in the
6877 current context, set inst.error and return TRUE.
a737bd4d 6878
c19d1205
ZW
6879 inst.operands[i] describes the destination register. */
6880
c921be7d 6881static bfd_boolean
c19d1205
ZW
6882move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6883{
53365c0d
PB
6884 unsigned long tbit;
6885
6886 if (thumb_p)
6887 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6888 else
6889 tbit = LOAD_BIT;
6890
6891 if ((inst.instruction & tbit) == 0)
09d92015 6892 {
c19d1205 6893 inst.error = _("invalid pseudo operation");
c921be7d 6894 return TRUE;
09d92015 6895 }
c19d1205 6896 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6897 {
6898 inst.error = _("constant expression expected");
c921be7d 6899 return TRUE;
09d92015 6900 }
c19d1205 6901 if (inst.reloc.exp.X_op == O_constant)
09d92015 6902 {
c19d1205
ZW
6903 if (thumb_p)
6904 {
53365c0d 6905 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6906 {
6907 /* This can be done with a mov(1) instruction. */
6908 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6909 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 6910 return TRUE;
c19d1205
ZW
6911 }
6912 }
6913 else
6914 {
6915 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6916 if (value != FAIL)
6917 {
6918 /* This can be done with a mov instruction. */
6919 inst.instruction &= LITERAL_MASK;
6920 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6921 inst.instruction |= value & 0xfff;
c921be7d 6922 return TRUE;
c19d1205 6923 }
09d92015 6924
c19d1205
ZW
6925 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6926 if (value != FAIL)
6927 {
6928 /* This can be done with a mvn instruction. */
6929 inst.instruction &= LITERAL_MASK;
6930 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6931 inst.instruction |= value & 0xfff;
c921be7d 6932 return TRUE;
c19d1205
ZW
6933 }
6934 }
09d92015
MM
6935 }
6936
c19d1205
ZW
6937 if (add_to_lit_pool () == FAIL)
6938 {
6939 inst.error = _("literal pool insertion failed");
c921be7d 6940 return TRUE;
c19d1205
ZW
6941 }
6942 inst.operands[1].reg = REG_PC;
6943 inst.operands[1].isreg = 1;
6944 inst.operands[1].preind = 1;
6945 inst.reloc.pc_rel = 1;
6946 inst.reloc.type = (thumb_p
6947 ? BFD_RELOC_ARM_THUMB_OFFSET
6948 : (mode_3
6949 ? BFD_RELOC_ARM_HWLITERAL
6950 : BFD_RELOC_ARM_LITERAL));
c921be7d 6951 return FALSE;
09d92015
MM
6952}
6953
5f4273c7 6954/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6955 First some generics; their names are taken from the conventional
6956 bit positions for register arguments in ARM format instructions. */
09d92015 6957
a737bd4d 6958static void
c19d1205 6959do_noargs (void)
09d92015 6960{
c19d1205 6961}
a737bd4d 6962
c19d1205
ZW
6963static void
6964do_rd (void)
6965{
6966 inst.instruction |= inst.operands[0].reg << 12;
6967}
a737bd4d 6968
c19d1205
ZW
6969static void
6970do_rd_rm (void)
6971{
6972 inst.instruction |= inst.operands[0].reg << 12;
6973 inst.instruction |= inst.operands[1].reg;
6974}
09d92015 6975
c19d1205
ZW
6976static void
6977do_rd_rn (void)
6978{
6979 inst.instruction |= inst.operands[0].reg << 12;
6980 inst.instruction |= inst.operands[1].reg << 16;
6981}
a737bd4d 6982
c19d1205
ZW
6983static void
6984do_rn_rd (void)
6985{
6986 inst.instruction |= inst.operands[0].reg << 16;
6987 inst.instruction |= inst.operands[1].reg << 12;
6988}
09d92015 6989
c19d1205
ZW
6990static void
6991do_rd_rm_rn (void)
6992{
9a64e435 6993 unsigned Rn = inst.operands[2].reg;
708587a4 6994 /* Enforce restrictions on SWP instruction. */
9a64e435 6995 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
6996 {
6997 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6998 _("Rn must not overlap other operands"));
6999
7000 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7001 if (warn_on_deprecated
7002 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7003 as_warn (_("swp{b} use is deprecated for this architecture"));
7004
7005 }
c19d1205
ZW
7006 inst.instruction |= inst.operands[0].reg << 12;
7007 inst.instruction |= inst.operands[1].reg;
9a64e435 7008 inst.instruction |= Rn << 16;
c19d1205 7009}
09d92015 7010
c19d1205
ZW
7011static void
7012do_rd_rn_rm (void)
7013{
7014 inst.instruction |= inst.operands[0].reg << 12;
7015 inst.instruction |= inst.operands[1].reg << 16;
7016 inst.instruction |= inst.operands[2].reg;
7017}
a737bd4d 7018
c19d1205
ZW
7019static void
7020do_rm_rd_rn (void)
7021{
5be8be5d
DG
7022 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7023 constraint (((inst.reloc.exp.X_op != O_constant
7024 && inst.reloc.exp.X_op != O_illegal)
7025 || inst.reloc.exp.X_add_number != 0),
7026 BAD_ADDR_MODE);
c19d1205
ZW
7027 inst.instruction |= inst.operands[0].reg;
7028 inst.instruction |= inst.operands[1].reg << 12;
7029 inst.instruction |= inst.operands[2].reg << 16;
7030}
09d92015 7031
c19d1205
ZW
7032static void
7033do_imm0 (void)
7034{
7035 inst.instruction |= inst.operands[0].imm;
7036}
09d92015 7037
c19d1205
ZW
7038static void
7039do_rd_cpaddr (void)
7040{
7041 inst.instruction |= inst.operands[0].reg << 12;
7042 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7043}
a737bd4d 7044
c19d1205
ZW
7045/* ARM instructions, in alphabetical order by function name (except
7046 that wrapper functions appear immediately after the function they
7047 wrap). */
09d92015 7048
c19d1205
ZW
7049/* This is a pseudo-op of the form "adr rd, label" to be converted
7050 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7051
7052static void
c19d1205 7053do_adr (void)
09d92015 7054{
c19d1205 7055 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7056
c19d1205
ZW
7057 /* Frag hacking will turn this into a sub instruction if the offset turns
7058 out to be negative. */
7059 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7060 inst.reloc.pc_rel = 1;
2fc8bdac 7061 inst.reloc.exp.X_add_number -= 8;
c19d1205 7062}
b99bd4ef 7063
c19d1205
ZW
7064/* This is a pseudo-op of the form "adrl rd, label" to be converted
7065 into a relative address of the form:
7066 add rd, pc, #low(label-.-8)"
7067 add rd, rd, #high(label-.-8)" */
b99bd4ef 7068
c19d1205
ZW
7069static void
7070do_adrl (void)
7071{
7072 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7073
c19d1205
ZW
7074 /* Frag hacking will turn this into a sub instruction if the offset turns
7075 out to be negative. */
7076 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7077 inst.reloc.pc_rel = 1;
7078 inst.size = INSN_SIZE * 2;
2fc8bdac 7079 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7080}
7081
b99bd4ef 7082static void
c19d1205 7083do_arit (void)
b99bd4ef 7084{
c19d1205
ZW
7085 if (!inst.operands[1].present)
7086 inst.operands[1].reg = inst.operands[0].reg;
7087 inst.instruction |= inst.operands[0].reg << 12;
7088 inst.instruction |= inst.operands[1].reg << 16;
7089 encode_arm_shifter_operand (2);
7090}
b99bd4ef 7091
62b3e311
PB
7092static void
7093do_barrier (void)
7094{
7095 if (inst.operands[0].present)
7096 {
7097 constraint ((inst.instruction & 0xf0) != 0x40
7098 && inst.operands[0].imm != 0xf,
bd3ba5d1 7099 _("bad barrier type"));
62b3e311
PB
7100 inst.instruction |= inst.operands[0].imm;
7101 }
7102 else
7103 inst.instruction |= 0xf;
7104}
7105
c19d1205
ZW
7106static void
7107do_bfc (void)
7108{
7109 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7110 constraint (msb > 32, _("bit-field extends past end of register"));
7111 /* The instruction encoding stores the LSB and MSB,
7112 not the LSB and width. */
7113 inst.instruction |= inst.operands[0].reg << 12;
7114 inst.instruction |= inst.operands[1].imm << 7;
7115 inst.instruction |= (msb - 1) << 16;
7116}
b99bd4ef 7117
c19d1205
ZW
7118static void
7119do_bfi (void)
7120{
7121 unsigned int msb;
b99bd4ef 7122
c19d1205
ZW
7123 /* #0 in second position is alternative syntax for bfc, which is
7124 the same instruction but with REG_PC in the Rm field. */
7125 if (!inst.operands[1].isreg)
7126 inst.operands[1].reg = REG_PC;
b99bd4ef 7127
c19d1205
ZW
7128 msb = inst.operands[2].imm + inst.operands[3].imm;
7129 constraint (msb > 32, _("bit-field extends past end of register"));
7130 /* The instruction encoding stores the LSB and MSB,
7131 not the LSB and width. */
7132 inst.instruction |= inst.operands[0].reg << 12;
7133 inst.instruction |= inst.operands[1].reg;
7134 inst.instruction |= inst.operands[2].imm << 7;
7135 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7136}
7137
b99bd4ef 7138static void
c19d1205 7139do_bfx (void)
b99bd4ef 7140{
c19d1205
ZW
7141 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7142 _("bit-field extends past end of register"));
7143 inst.instruction |= inst.operands[0].reg << 12;
7144 inst.instruction |= inst.operands[1].reg;
7145 inst.instruction |= inst.operands[2].imm << 7;
7146 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7147}
09d92015 7148
c19d1205
ZW
7149/* ARM V5 breakpoint instruction (argument parse)
7150 BKPT <16 bit unsigned immediate>
7151 Instruction is not conditional.
7152 The bit pattern given in insns[] has the COND_ALWAYS condition,
7153 and it is an error if the caller tried to override that. */
b99bd4ef 7154
c19d1205
ZW
7155static void
7156do_bkpt (void)
7157{
7158 /* Top 12 of 16 bits to bits 19:8. */
7159 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7160
c19d1205
ZW
7161 /* Bottom 4 of 16 bits to bits 3:0. */
7162 inst.instruction |= inst.operands[0].imm & 0xf;
7163}
09d92015 7164
c19d1205
ZW
7165static void
7166encode_branch (int default_reloc)
7167{
7168 if (inst.operands[0].hasreloc)
7169 {
7170 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7171 _("the only suffix valid here is '(plt)'"));
267bf995 7172 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7173 }
b99bd4ef 7174 else
c19d1205 7175 {
21d799b5 7176 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7177 }
2fc8bdac 7178 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7179}
7180
b99bd4ef 7181static void
c19d1205 7182do_branch (void)
b99bd4ef 7183{
39b41c9c
PB
7184#ifdef OBJ_ELF
7185 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7186 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7187 else
7188#endif
7189 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7190}
7191
7192static void
7193do_bl (void)
7194{
7195#ifdef OBJ_ELF
7196 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7197 {
7198 if (inst.cond == COND_ALWAYS)
7199 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7200 else
7201 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7202 }
7203 else
7204#endif
7205 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7206}
b99bd4ef 7207
c19d1205
ZW
7208/* ARM V5 branch-link-exchange instruction (argument parse)
7209 BLX <target_addr> ie BLX(1)
7210 BLX{<condition>} <Rm> ie BLX(2)
7211 Unfortunately, there are two different opcodes for this mnemonic.
7212 So, the insns[].value is not used, and the code here zaps values
7213 into inst.instruction.
7214 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7215
c19d1205
ZW
7216static void
7217do_blx (void)
7218{
7219 if (inst.operands[0].isreg)
b99bd4ef 7220 {
c19d1205
ZW
7221 /* Arg is a register; the opcode provided by insns[] is correct.
7222 It is not illegal to do "blx pc", just useless. */
7223 if (inst.operands[0].reg == REG_PC)
7224 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7225
c19d1205
ZW
7226 inst.instruction |= inst.operands[0].reg;
7227 }
7228 else
b99bd4ef 7229 {
c19d1205 7230 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7231 conditionally, and the opcode must be adjusted.
7232 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7233 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7234 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7235 inst.instruction = 0xfa000000;
267bf995 7236 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7237 }
c19d1205
ZW
7238}
7239
7240static void
7241do_bx (void)
7242{
845b51d6
PB
7243 bfd_boolean want_reloc;
7244
c19d1205
ZW
7245 if (inst.operands[0].reg == REG_PC)
7246 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7247
c19d1205 7248 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7249 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7250 it is for ARMv4t or earlier. */
7251 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7252 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7253 want_reloc = TRUE;
7254
5ad34203 7255#ifdef OBJ_ELF
845b51d6 7256 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7257#endif
584206db 7258 want_reloc = FALSE;
845b51d6
PB
7259
7260 if (want_reloc)
7261 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7262}
7263
c19d1205
ZW
7264
7265/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7266
7267static void
c19d1205 7268do_bxj (void)
a737bd4d 7269{
c19d1205
ZW
7270 if (inst.operands[0].reg == REG_PC)
7271 as_tsktsk (_("use of r15 in bxj is not really useful"));
7272
7273 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7274}
7275
c19d1205
ZW
7276/* Co-processor data operation:
7277 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7278 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7279static void
7280do_cdp (void)
7281{
7282 inst.instruction |= inst.operands[0].reg << 8;
7283 inst.instruction |= inst.operands[1].imm << 20;
7284 inst.instruction |= inst.operands[2].reg << 12;
7285 inst.instruction |= inst.operands[3].reg << 16;
7286 inst.instruction |= inst.operands[4].reg;
7287 inst.instruction |= inst.operands[5].imm << 5;
7288}
a737bd4d
NC
7289
7290static void
c19d1205 7291do_cmp (void)
a737bd4d 7292{
c19d1205
ZW
7293 inst.instruction |= inst.operands[0].reg << 16;
7294 encode_arm_shifter_operand (1);
a737bd4d
NC
7295}
7296
c19d1205
ZW
7297/* Transfer between coprocessor and ARM registers.
7298 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7299 MRC2
7300 MCR{cond}
7301 MCR2
7302
7303 No special properties. */
09d92015
MM
7304
7305static void
c19d1205 7306do_co_reg (void)
09d92015 7307{
fdfde340
JM
7308 unsigned Rd;
7309
7310 Rd = inst.operands[2].reg;
7311 if (thumb_mode)
7312 {
7313 if (inst.instruction == 0xee000010
7314 || inst.instruction == 0xfe000010)
7315 /* MCR, MCR2 */
7316 reject_bad_reg (Rd);
7317 else
7318 /* MRC, MRC2 */
7319 constraint (Rd == REG_SP, BAD_SP);
7320 }
7321 else
7322 {
7323 /* MCR */
7324 if (inst.instruction == 0xe000010)
7325 constraint (Rd == REG_PC, BAD_PC);
7326 }
7327
7328
c19d1205
ZW
7329 inst.instruction |= inst.operands[0].reg << 8;
7330 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7331 inst.instruction |= Rd << 12;
c19d1205
ZW
7332 inst.instruction |= inst.operands[3].reg << 16;
7333 inst.instruction |= inst.operands[4].reg;
7334 inst.instruction |= inst.operands[5].imm << 5;
7335}
09d92015 7336
c19d1205
ZW
7337/* Transfer between coprocessor register and pair of ARM registers.
7338 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7339 MCRR2
7340 MRRC{cond}
7341 MRRC2
b99bd4ef 7342
c19d1205 7343 Two XScale instructions are special cases of these:
09d92015 7344
c19d1205
ZW
7345 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7346 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7347
5f4273c7 7348 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7349
c19d1205
ZW
7350static void
7351do_co_reg2c (void)
7352{
fdfde340
JM
7353 unsigned Rd, Rn;
7354
7355 Rd = inst.operands[2].reg;
7356 Rn = inst.operands[3].reg;
7357
7358 if (thumb_mode)
7359 {
7360 reject_bad_reg (Rd);
7361 reject_bad_reg (Rn);
7362 }
7363 else
7364 {
7365 constraint (Rd == REG_PC, BAD_PC);
7366 constraint (Rn == REG_PC, BAD_PC);
7367 }
7368
c19d1205
ZW
7369 inst.instruction |= inst.operands[0].reg << 8;
7370 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7371 inst.instruction |= Rd << 12;
7372 inst.instruction |= Rn << 16;
c19d1205 7373 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7374}
7375
c19d1205
ZW
7376static void
7377do_cpsi (void)
7378{
7379 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7380 if (inst.operands[1].present)
7381 {
7382 inst.instruction |= CPSI_MMOD;
7383 inst.instruction |= inst.operands[1].imm;
7384 }
c19d1205 7385}
b99bd4ef 7386
62b3e311
PB
7387static void
7388do_dbg (void)
7389{
7390 inst.instruction |= inst.operands[0].imm;
7391}
7392
b99bd4ef 7393static void
c19d1205 7394do_it (void)
b99bd4ef 7395{
c19d1205 7396 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7397 process it to do the validation as if in
7398 thumb mode, just in case the code gets
7399 assembled for thumb using the unified syntax. */
7400
c19d1205 7401 inst.size = 0;
e07e6e58
NC
7402 if (unified_syntax)
7403 {
7404 set_it_insn_type (IT_INSN);
7405 now_it.mask = (inst.instruction & 0xf) | 0x10;
7406 now_it.cc = inst.operands[0].imm;
7407 }
09d92015 7408}
b99bd4ef 7409
09d92015 7410static void
c19d1205 7411do_ldmstm (void)
ea6ef066 7412{
c19d1205
ZW
7413 int base_reg = inst.operands[0].reg;
7414 int range = inst.operands[1].imm;
ea6ef066 7415
c19d1205
ZW
7416 inst.instruction |= base_reg << 16;
7417 inst.instruction |= range;
ea6ef066 7418
c19d1205
ZW
7419 if (inst.operands[1].writeback)
7420 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7421
c19d1205 7422 if (inst.operands[0].writeback)
ea6ef066 7423 {
c19d1205
ZW
7424 inst.instruction |= WRITE_BACK;
7425 /* Check for unpredictable uses of writeback. */
7426 if (inst.instruction & LOAD_BIT)
09d92015 7427 {
c19d1205
ZW
7428 /* Not allowed in LDM type 2. */
7429 if ((inst.instruction & LDM_TYPE_2_OR_3)
7430 && ((range & (1 << REG_PC)) == 0))
7431 as_warn (_("writeback of base register is UNPREDICTABLE"));
7432 /* Only allowed if base reg not in list for other types. */
7433 else if (range & (1 << base_reg))
7434 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7435 }
7436 else /* STM. */
7437 {
7438 /* Not allowed for type 2. */
7439 if (inst.instruction & LDM_TYPE_2_OR_3)
7440 as_warn (_("writeback of base register is UNPREDICTABLE"));
7441 /* Only allowed if base reg not in list, or first in list. */
7442 else if ((range & (1 << base_reg))
7443 && (range & ((1 << base_reg) - 1)))
7444 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7445 }
ea6ef066 7446 }
a737bd4d
NC
7447}
7448
c19d1205
ZW
7449/* ARMv5TE load-consecutive (argument parse)
7450 Mode is like LDRH.
7451
7452 LDRccD R, mode
7453 STRccD R, mode. */
7454
a737bd4d 7455static void
c19d1205 7456do_ldrd (void)
a737bd4d 7457{
c19d1205
ZW
7458 constraint (inst.operands[0].reg % 2 != 0,
7459 _("first destination register must be even"));
7460 constraint (inst.operands[1].present
7461 && inst.operands[1].reg != inst.operands[0].reg + 1,
7462 _("can only load two consecutive registers"));
7463 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7464 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7465
c19d1205
ZW
7466 if (!inst.operands[1].present)
7467 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7468
c19d1205 7469 if (inst.instruction & LOAD_BIT)
a737bd4d 7470 {
c19d1205
ZW
7471 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7472 register and the first register written; we have to diagnose
7473 overlap between the base and the second register written here. */
ea6ef066 7474
c19d1205
ZW
7475 if (inst.operands[2].reg == inst.operands[1].reg
7476 && (inst.operands[2].writeback || inst.operands[2].postind))
7477 as_warn (_("base register written back, and overlaps "
7478 "second destination register"));
b05fe5cf 7479
c19d1205
ZW
7480 /* For an index-register load, the index register must not overlap the
7481 destination (even if not write-back). */
7482 else if (inst.operands[2].immisreg
ca3f61f7
NC
7483 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7484 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7485 as_warn (_("index register overlaps destination register"));
b05fe5cf 7486 }
c19d1205
ZW
7487
7488 inst.instruction |= inst.operands[0].reg << 12;
7489 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7490}
7491
7492static void
c19d1205 7493do_ldrex (void)
b05fe5cf 7494{
c19d1205
ZW
7495 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7496 || inst.operands[1].postind || inst.operands[1].writeback
7497 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7498 || inst.operands[1].negative
7499 /* This can arise if the programmer has written
7500 strex rN, rM, foo
7501 or if they have mistakenly used a register name as the last
7502 operand, eg:
7503 strex rN, rM, rX
7504 It is very difficult to distinguish between these two cases
7505 because "rX" might actually be a label. ie the register
7506 name has been occluded by a symbol of the same name. So we
7507 just generate a general 'bad addressing mode' type error
7508 message and leave it up to the programmer to discover the
7509 true cause and fix their mistake. */
7510 || (inst.operands[1].reg == REG_PC),
7511 BAD_ADDR_MODE);
b05fe5cf 7512
c19d1205
ZW
7513 constraint (inst.reloc.exp.X_op != O_constant
7514 || inst.reloc.exp.X_add_number != 0,
7515 _("offset must be zero in ARM encoding"));
b05fe5cf 7516
5be8be5d
DG
7517 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7518
c19d1205
ZW
7519 inst.instruction |= inst.operands[0].reg << 12;
7520 inst.instruction |= inst.operands[1].reg << 16;
7521 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7522}
7523
7524static void
c19d1205 7525do_ldrexd (void)
b05fe5cf 7526{
c19d1205
ZW
7527 constraint (inst.operands[0].reg % 2 != 0,
7528 _("even register required"));
7529 constraint (inst.operands[1].present
7530 && inst.operands[1].reg != inst.operands[0].reg + 1,
7531 _("can only load two consecutive registers"));
7532 /* If op 1 were present and equal to PC, this function wouldn't
7533 have been called in the first place. */
7534 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7535
c19d1205
ZW
7536 inst.instruction |= inst.operands[0].reg << 12;
7537 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7538}
7539
7540static void
c19d1205 7541do_ldst (void)
b05fe5cf 7542{
c19d1205
ZW
7543 inst.instruction |= inst.operands[0].reg << 12;
7544 if (!inst.operands[1].isreg)
7545 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7546 return;
c19d1205 7547 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7548}
7549
7550static void
c19d1205 7551do_ldstt (void)
b05fe5cf 7552{
c19d1205
ZW
7553 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7554 reject [Rn,...]. */
7555 if (inst.operands[1].preind)
b05fe5cf 7556 {
bd3ba5d1
NC
7557 constraint (inst.reloc.exp.X_op != O_constant
7558 || inst.reloc.exp.X_add_number != 0,
c19d1205 7559 _("this instruction requires a post-indexed address"));
b05fe5cf 7560
c19d1205
ZW
7561 inst.operands[1].preind = 0;
7562 inst.operands[1].postind = 1;
7563 inst.operands[1].writeback = 1;
b05fe5cf 7564 }
c19d1205
ZW
7565 inst.instruction |= inst.operands[0].reg << 12;
7566 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7567}
b05fe5cf 7568
c19d1205 7569/* Halfword and signed-byte load/store operations. */
b05fe5cf 7570
c19d1205
ZW
7571static void
7572do_ldstv4 (void)
7573{
ff4a8d2b 7574 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7575 inst.instruction |= inst.operands[0].reg << 12;
7576 if (!inst.operands[1].isreg)
7577 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7578 return;
c19d1205 7579 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7580}
7581
7582static void
c19d1205 7583do_ldsttv4 (void)
b05fe5cf 7584{
c19d1205
ZW
7585 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7586 reject [Rn,...]. */
7587 if (inst.operands[1].preind)
b05fe5cf 7588 {
bd3ba5d1
NC
7589 constraint (inst.reloc.exp.X_op != O_constant
7590 || inst.reloc.exp.X_add_number != 0,
c19d1205 7591 _("this instruction requires a post-indexed address"));
b05fe5cf 7592
c19d1205
ZW
7593 inst.operands[1].preind = 0;
7594 inst.operands[1].postind = 1;
7595 inst.operands[1].writeback = 1;
b05fe5cf 7596 }
c19d1205
ZW
7597 inst.instruction |= inst.operands[0].reg << 12;
7598 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7599}
b05fe5cf 7600
c19d1205
ZW
7601/* Co-processor register load/store.
7602 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7603static void
7604do_lstc (void)
7605{
7606 inst.instruction |= inst.operands[0].reg << 8;
7607 inst.instruction |= inst.operands[1].reg << 12;
7608 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7609}
7610
b05fe5cf 7611static void
c19d1205 7612do_mlas (void)
b05fe5cf 7613{
8fb9d7b9 7614 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7615 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7616 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7617 && !(inst.instruction & 0x00400000))
8fb9d7b9 7618 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7619
c19d1205
ZW
7620 inst.instruction |= inst.operands[0].reg << 16;
7621 inst.instruction |= inst.operands[1].reg;
7622 inst.instruction |= inst.operands[2].reg << 8;
7623 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7624}
b05fe5cf 7625
c19d1205
ZW
7626static void
7627do_mov (void)
7628{
7629 inst.instruction |= inst.operands[0].reg << 12;
7630 encode_arm_shifter_operand (1);
7631}
b05fe5cf 7632
c19d1205
ZW
7633/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7634static void
7635do_mov16 (void)
7636{
b6895b4f
PB
7637 bfd_vma imm;
7638 bfd_boolean top;
7639
7640 top = (inst.instruction & 0x00400000) != 0;
7641 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7642 _(":lower16: not allowed this instruction"));
7643 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7644 _(":upper16: not allowed instruction"));
c19d1205 7645 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7646 if (inst.reloc.type == BFD_RELOC_UNUSED)
7647 {
7648 imm = inst.reloc.exp.X_add_number;
7649 /* The value is in two pieces: 0:11, 16:19. */
7650 inst.instruction |= (imm & 0x00000fff);
7651 inst.instruction |= (imm & 0x0000f000) << 4;
7652 }
b05fe5cf 7653}
b99bd4ef 7654
037e8744
JB
7655static void do_vfp_nsyn_opcode (const char *);
7656
7657static int
7658do_vfp_nsyn_mrs (void)
7659{
7660 if (inst.operands[0].isvec)
7661 {
7662 if (inst.operands[1].reg != 1)
7663 first_error (_("operand 1 must be FPSCR"));
7664 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7665 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7666 do_vfp_nsyn_opcode ("fmstat");
7667 }
7668 else if (inst.operands[1].isvec)
7669 do_vfp_nsyn_opcode ("fmrx");
7670 else
7671 return FAIL;
5f4273c7 7672
037e8744
JB
7673 return SUCCESS;
7674}
7675
7676static int
7677do_vfp_nsyn_msr (void)
7678{
7679 if (inst.operands[0].isvec)
7680 do_vfp_nsyn_opcode ("fmxr");
7681 else
7682 return FAIL;
7683
7684 return SUCCESS;
7685}
7686
f7c21dc7
NC
7687static void
7688do_vmrs (void)
7689{
7690 unsigned Rt = inst.operands[0].reg;
7691
7692 if (thumb_mode && inst.operands[0].reg == REG_SP)
7693 {
7694 inst.error = BAD_SP;
7695 return;
7696 }
7697
7698 /* APSR_ sets isvec. All other refs to PC are illegal. */
7699 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7700 {
7701 inst.error = BAD_PC;
7702 return;
7703 }
7704
7705 if (inst.operands[1].reg != 1)
7706 first_error (_("operand 1 must be FPSCR"));
7707
7708 inst.instruction |= (Rt << 12);
7709}
7710
7711static void
7712do_vmsr (void)
7713{
7714 unsigned Rt = inst.operands[1].reg;
7715
7716 if (thumb_mode)
7717 reject_bad_reg (Rt);
7718 else if (Rt == REG_PC)
7719 {
7720 inst.error = BAD_PC;
7721 return;
7722 }
7723
7724 if (inst.operands[0].reg != 1)
7725 first_error (_("operand 0 must be FPSCR"));
7726
7727 inst.instruction |= (Rt << 12);
7728}
7729
b99bd4ef 7730static void
c19d1205 7731do_mrs (void)
b99bd4ef 7732{
037e8744
JB
7733 if (do_vfp_nsyn_mrs () == SUCCESS)
7734 return;
7735
c19d1205
ZW
7736 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7737 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7738 != (PSR_c|PSR_f),
7739 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7740 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7741 inst.instruction |= inst.operands[0].reg << 12;
7742 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7743}
b99bd4ef 7744
c19d1205
ZW
7745/* Two possible forms:
7746 "{C|S}PSR_<field>, Rm",
7747 "{C|S}PSR_f, #expression". */
b99bd4ef 7748
c19d1205
ZW
7749static void
7750do_msr (void)
7751{
037e8744
JB
7752 if (do_vfp_nsyn_msr () == SUCCESS)
7753 return;
7754
c19d1205
ZW
7755 inst.instruction |= inst.operands[0].imm;
7756 if (inst.operands[1].isreg)
7757 inst.instruction |= inst.operands[1].reg;
7758 else
b99bd4ef 7759 {
c19d1205
ZW
7760 inst.instruction |= INST_IMMEDIATE;
7761 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7762 inst.reloc.pc_rel = 0;
b99bd4ef 7763 }
b99bd4ef
NC
7764}
7765
c19d1205
ZW
7766static void
7767do_mul (void)
a737bd4d 7768{
ff4a8d2b
NC
7769 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7770
c19d1205
ZW
7771 if (!inst.operands[2].present)
7772 inst.operands[2].reg = inst.operands[0].reg;
7773 inst.instruction |= inst.operands[0].reg << 16;
7774 inst.instruction |= inst.operands[1].reg;
7775 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7776
8fb9d7b9
MS
7777 if (inst.operands[0].reg == inst.operands[1].reg
7778 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7779 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7780}
7781
c19d1205
ZW
7782/* Long Multiply Parser
7783 UMULL RdLo, RdHi, Rm, Rs
7784 SMULL RdLo, RdHi, Rm, Rs
7785 UMLAL RdLo, RdHi, Rm, Rs
7786 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7787
7788static void
c19d1205 7789do_mull (void)
b99bd4ef 7790{
c19d1205
ZW
7791 inst.instruction |= inst.operands[0].reg << 12;
7792 inst.instruction |= inst.operands[1].reg << 16;
7793 inst.instruction |= inst.operands[2].reg;
7794 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7795
682b27ad
PB
7796 /* rdhi and rdlo must be different. */
7797 if (inst.operands[0].reg == inst.operands[1].reg)
7798 as_tsktsk (_("rdhi and rdlo must be different"));
7799
7800 /* rdhi, rdlo and rm must all be different before armv6. */
7801 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7802 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7803 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7804 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7805}
b99bd4ef 7806
c19d1205
ZW
7807static void
7808do_nop (void)
7809{
e7495e45
NS
7810 if (inst.operands[0].present
7811 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7812 {
7813 /* Architectural NOP hints are CPSR sets with no bits selected. */
7814 inst.instruction &= 0xf0000000;
e7495e45
NS
7815 inst.instruction |= 0x0320f000;
7816 if (inst.operands[0].present)
7817 inst.instruction |= inst.operands[0].imm;
c19d1205 7818 }
b99bd4ef
NC
7819}
7820
c19d1205
ZW
7821/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7822 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7823 Condition defaults to COND_ALWAYS.
7824 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7825
7826static void
c19d1205 7827do_pkhbt (void)
b99bd4ef 7828{
c19d1205
ZW
7829 inst.instruction |= inst.operands[0].reg << 12;
7830 inst.instruction |= inst.operands[1].reg << 16;
7831 inst.instruction |= inst.operands[2].reg;
7832 if (inst.operands[3].present)
7833 encode_arm_shift (3);
7834}
b99bd4ef 7835
c19d1205 7836/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7837
c19d1205
ZW
7838static void
7839do_pkhtb (void)
7840{
7841 if (!inst.operands[3].present)
b99bd4ef 7842 {
c19d1205
ZW
7843 /* If the shift specifier is omitted, turn the instruction
7844 into pkhbt rd, rm, rn. */
7845 inst.instruction &= 0xfff00010;
7846 inst.instruction |= inst.operands[0].reg << 12;
7847 inst.instruction |= inst.operands[1].reg;
7848 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7849 }
7850 else
7851 {
c19d1205
ZW
7852 inst.instruction |= inst.operands[0].reg << 12;
7853 inst.instruction |= inst.operands[1].reg << 16;
7854 inst.instruction |= inst.operands[2].reg;
7855 encode_arm_shift (3);
b99bd4ef
NC
7856 }
7857}
7858
c19d1205
ZW
7859/* ARMv5TE: Preload-Cache
7860
7861 PLD <addr_mode>
7862
7863 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7864
7865static void
c19d1205 7866do_pld (void)
b99bd4ef 7867{
c19d1205
ZW
7868 constraint (!inst.operands[0].isreg,
7869 _("'[' expected after PLD mnemonic"));
7870 constraint (inst.operands[0].postind,
7871 _("post-indexed expression used in preload instruction"));
7872 constraint (inst.operands[0].writeback,
7873 _("writeback used in preload instruction"));
7874 constraint (!inst.operands[0].preind,
7875 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7876 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7877}
b99bd4ef 7878
62b3e311
PB
7879/* ARMv7: PLI <addr_mode> */
7880static void
7881do_pli (void)
7882{
7883 constraint (!inst.operands[0].isreg,
7884 _("'[' expected after PLI mnemonic"));
7885 constraint (inst.operands[0].postind,
7886 _("post-indexed expression used in preload instruction"));
7887 constraint (inst.operands[0].writeback,
7888 _("writeback used in preload instruction"));
7889 constraint (!inst.operands[0].preind,
7890 _("unindexed addressing used in preload instruction"));
7891 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7892 inst.instruction &= ~PRE_INDEX;
7893}
7894
c19d1205
ZW
7895static void
7896do_push_pop (void)
7897{
7898 inst.operands[1] = inst.operands[0];
7899 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7900 inst.operands[0].isreg = 1;
7901 inst.operands[0].writeback = 1;
7902 inst.operands[0].reg = REG_SP;
7903 do_ldmstm ();
7904}
b99bd4ef 7905
c19d1205
ZW
7906/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7907 word at the specified address and the following word
7908 respectively.
7909 Unconditionally executed.
7910 Error if Rn is R15. */
b99bd4ef 7911
c19d1205
ZW
7912static void
7913do_rfe (void)
7914{
7915 inst.instruction |= inst.operands[0].reg << 16;
7916 if (inst.operands[0].writeback)
7917 inst.instruction |= WRITE_BACK;
7918}
b99bd4ef 7919
c19d1205 7920/* ARM V6 ssat (argument parse). */
b99bd4ef 7921
c19d1205
ZW
7922static void
7923do_ssat (void)
7924{
7925 inst.instruction |= inst.operands[0].reg << 12;
7926 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7927 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7928
c19d1205
ZW
7929 if (inst.operands[3].present)
7930 encode_arm_shift (3);
b99bd4ef
NC
7931}
7932
c19d1205 7933/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7934
7935static void
c19d1205 7936do_usat (void)
b99bd4ef 7937{
c19d1205
ZW
7938 inst.instruction |= inst.operands[0].reg << 12;
7939 inst.instruction |= inst.operands[1].imm << 16;
7940 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7941
c19d1205
ZW
7942 if (inst.operands[3].present)
7943 encode_arm_shift (3);
b99bd4ef
NC
7944}
7945
c19d1205 7946/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7947
7948static void
c19d1205 7949do_ssat16 (void)
09d92015 7950{
c19d1205
ZW
7951 inst.instruction |= inst.operands[0].reg << 12;
7952 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7953 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7954}
7955
c19d1205
ZW
7956static void
7957do_usat16 (void)
a737bd4d 7958{
c19d1205
ZW
7959 inst.instruction |= inst.operands[0].reg << 12;
7960 inst.instruction |= inst.operands[1].imm << 16;
7961 inst.instruction |= inst.operands[2].reg;
7962}
a737bd4d 7963
c19d1205
ZW
7964/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7965 preserving the other bits.
a737bd4d 7966
c19d1205
ZW
7967 setend <endian_specifier>, where <endian_specifier> is either
7968 BE or LE. */
a737bd4d 7969
c19d1205
ZW
7970static void
7971do_setend (void)
7972{
7973 if (inst.operands[0].imm)
7974 inst.instruction |= 0x200;
a737bd4d
NC
7975}
7976
7977static void
c19d1205 7978do_shift (void)
a737bd4d 7979{
c19d1205
ZW
7980 unsigned int Rm = (inst.operands[1].present
7981 ? inst.operands[1].reg
7982 : inst.operands[0].reg);
a737bd4d 7983
c19d1205
ZW
7984 inst.instruction |= inst.operands[0].reg << 12;
7985 inst.instruction |= Rm;
7986 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7987 {
c19d1205
ZW
7988 inst.instruction |= inst.operands[2].reg << 8;
7989 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7990 }
7991 else
c19d1205 7992 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7993}
7994
09d92015 7995static void
3eb17e6b 7996do_smc (void)
09d92015 7997{
3eb17e6b 7998 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7999 inst.reloc.pc_rel = 0;
09d92015
MM
8000}
8001
09d92015 8002static void
c19d1205 8003do_swi (void)
09d92015 8004{
c19d1205
ZW
8005 inst.reloc.type = BFD_RELOC_ARM_SWI;
8006 inst.reloc.pc_rel = 0;
09d92015
MM
8007}
8008
c19d1205
ZW
8009/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8010 SMLAxy{cond} Rd,Rm,Rs,Rn
8011 SMLAWy{cond} Rd,Rm,Rs,Rn
8012 Error if any register is R15. */
e16bb312 8013
c19d1205
ZW
8014static void
8015do_smla (void)
e16bb312 8016{
c19d1205
ZW
8017 inst.instruction |= inst.operands[0].reg << 16;
8018 inst.instruction |= inst.operands[1].reg;
8019 inst.instruction |= inst.operands[2].reg << 8;
8020 inst.instruction |= inst.operands[3].reg << 12;
8021}
a737bd4d 8022
c19d1205
ZW
8023/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8024 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8025 Error if any register is R15.
8026 Warning if Rdlo == Rdhi. */
a737bd4d 8027
c19d1205
ZW
8028static void
8029do_smlal (void)
8030{
8031 inst.instruction |= inst.operands[0].reg << 12;
8032 inst.instruction |= inst.operands[1].reg << 16;
8033 inst.instruction |= inst.operands[2].reg;
8034 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8035
c19d1205
ZW
8036 if (inst.operands[0].reg == inst.operands[1].reg)
8037 as_tsktsk (_("rdhi and rdlo must be different"));
8038}
a737bd4d 8039
c19d1205
ZW
8040/* ARM V5E (El Segundo) signed-multiply (argument parse)
8041 SMULxy{cond} Rd,Rm,Rs
8042 Error if any register is R15. */
a737bd4d 8043
c19d1205
ZW
8044static void
8045do_smul (void)
8046{
8047 inst.instruction |= inst.operands[0].reg << 16;
8048 inst.instruction |= inst.operands[1].reg;
8049 inst.instruction |= inst.operands[2].reg << 8;
8050}
a737bd4d 8051
b6702015
PB
8052/* ARM V6 srs (argument parse). The variable fields in the encoding are
8053 the same for both ARM and Thumb-2. */
a737bd4d 8054
c19d1205
ZW
8055static void
8056do_srs (void)
8057{
b6702015
PB
8058 int reg;
8059
8060 if (inst.operands[0].present)
8061 {
8062 reg = inst.operands[0].reg;
fdfde340 8063 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8064 }
8065 else
fdfde340 8066 reg = REG_SP;
b6702015
PB
8067
8068 inst.instruction |= reg << 16;
8069 inst.instruction |= inst.operands[1].imm;
8070 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8071 inst.instruction |= WRITE_BACK;
8072}
a737bd4d 8073
c19d1205 8074/* ARM V6 strex (argument parse). */
a737bd4d 8075
c19d1205
ZW
8076static void
8077do_strex (void)
8078{
8079 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8080 || inst.operands[2].postind || inst.operands[2].writeback
8081 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8082 || inst.operands[2].negative
8083 /* See comment in do_ldrex(). */
8084 || (inst.operands[2].reg == REG_PC),
8085 BAD_ADDR_MODE);
a737bd4d 8086
c19d1205
ZW
8087 constraint (inst.operands[0].reg == inst.operands[1].reg
8088 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8089
c19d1205
ZW
8090 constraint (inst.reloc.exp.X_op != O_constant
8091 || inst.reloc.exp.X_add_number != 0,
8092 _("offset must be zero in ARM encoding"));
a737bd4d 8093
c19d1205
ZW
8094 inst.instruction |= inst.operands[0].reg << 12;
8095 inst.instruction |= inst.operands[1].reg;
8096 inst.instruction |= inst.operands[2].reg << 16;
8097 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8098}
8099
8100static void
c19d1205 8101do_strexd (void)
e16bb312 8102{
c19d1205
ZW
8103 constraint (inst.operands[1].reg % 2 != 0,
8104 _("even register required"));
8105 constraint (inst.operands[2].present
8106 && inst.operands[2].reg != inst.operands[1].reg + 1,
8107 _("can only store two consecutive registers"));
8108 /* If op 2 were present and equal to PC, this function wouldn't
8109 have been called in the first place. */
8110 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8111
c19d1205
ZW
8112 constraint (inst.operands[0].reg == inst.operands[1].reg
8113 || inst.operands[0].reg == inst.operands[1].reg + 1
8114 || inst.operands[0].reg == inst.operands[3].reg,
8115 BAD_OVERLAP);
e16bb312 8116
c19d1205
ZW
8117 inst.instruction |= inst.operands[0].reg << 12;
8118 inst.instruction |= inst.operands[1].reg;
8119 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8120}
8121
c19d1205
ZW
8122/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8123 extends it to 32-bits, and adds the result to a value in another
8124 register. You can specify a rotation by 0, 8, 16, or 24 bits
8125 before extracting the 16-bit value.
8126 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8127 Condition defaults to COND_ALWAYS.
8128 Error if any register uses R15. */
8129
e16bb312 8130static void
c19d1205 8131do_sxtah (void)
e16bb312 8132{
c19d1205
ZW
8133 inst.instruction |= inst.operands[0].reg << 12;
8134 inst.instruction |= inst.operands[1].reg << 16;
8135 inst.instruction |= inst.operands[2].reg;
8136 inst.instruction |= inst.operands[3].imm << 10;
8137}
e16bb312 8138
c19d1205 8139/* ARM V6 SXTH.
e16bb312 8140
c19d1205
ZW
8141 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8142 Condition defaults to COND_ALWAYS.
8143 Error if any register uses R15. */
e16bb312
NC
8144
8145static void
c19d1205 8146do_sxth (void)
e16bb312 8147{
c19d1205
ZW
8148 inst.instruction |= inst.operands[0].reg << 12;
8149 inst.instruction |= inst.operands[1].reg;
8150 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8151}
c19d1205
ZW
8152\f
8153/* VFP instructions. In a logical order: SP variant first, monad
8154 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8155
8156static void
c19d1205 8157do_vfp_sp_monadic (void)
e16bb312 8158{
5287ad62
JB
8159 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8160 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8161}
8162
8163static void
c19d1205 8164do_vfp_sp_dyadic (void)
e16bb312 8165{
5287ad62
JB
8166 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8167 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8168 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8169}
8170
8171static void
c19d1205 8172do_vfp_sp_compare_z (void)
e16bb312 8173{
5287ad62 8174 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8175}
8176
8177static void
c19d1205 8178do_vfp_dp_sp_cvt (void)
e16bb312 8179{
5287ad62
JB
8180 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8181 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8182}
8183
8184static void
c19d1205 8185do_vfp_sp_dp_cvt (void)
e16bb312 8186{
5287ad62
JB
8187 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8188 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8189}
8190
8191static void
c19d1205 8192do_vfp_reg_from_sp (void)
e16bb312 8193{
c19d1205 8194 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8195 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8196}
8197
8198static void
c19d1205 8199do_vfp_reg2_from_sp2 (void)
e16bb312 8200{
c19d1205
ZW
8201 constraint (inst.operands[2].imm != 2,
8202 _("only two consecutive VFP SP registers allowed here"));
8203 inst.instruction |= inst.operands[0].reg << 12;
8204 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8205 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8206}
8207
8208static void
c19d1205 8209do_vfp_sp_from_reg (void)
e16bb312 8210{
5287ad62 8211 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8212 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8213}
8214
8215static void
c19d1205 8216do_vfp_sp2_from_reg2 (void)
e16bb312 8217{
c19d1205
ZW
8218 constraint (inst.operands[0].imm != 2,
8219 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8220 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8221 inst.instruction |= inst.operands[1].reg << 12;
8222 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8223}
8224
8225static void
c19d1205 8226do_vfp_sp_ldst (void)
e16bb312 8227{
5287ad62 8228 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8229 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8230}
8231
8232static void
c19d1205 8233do_vfp_dp_ldst (void)
e16bb312 8234{
5287ad62 8235 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8236 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8237}
8238
c19d1205 8239
e16bb312 8240static void
c19d1205 8241vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8242{
c19d1205
ZW
8243 if (inst.operands[0].writeback)
8244 inst.instruction |= WRITE_BACK;
8245 else
8246 constraint (ldstm_type != VFP_LDSTMIA,
8247 _("this addressing mode requires base-register writeback"));
8248 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8249 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8250 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8251}
8252
8253static void
c19d1205 8254vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8255{
c19d1205 8256 int count;
e16bb312 8257
c19d1205
ZW
8258 if (inst.operands[0].writeback)
8259 inst.instruction |= WRITE_BACK;
8260 else
8261 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8262 _("this addressing mode requires base-register writeback"));
e16bb312 8263
c19d1205 8264 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8265 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8266
c19d1205
ZW
8267 count = inst.operands[1].imm << 1;
8268 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8269 count += 1;
e16bb312 8270
c19d1205 8271 inst.instruction |= count;
e16bb312
NC
8272}
8273
8274static void
c19d1205 8275do_vfp_sp_ldstmia (void)
e16bb312 8276{
c19d1205 8277 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8278}
8279
8280static void
c19d1205 8281do_vfp_sp_ldstmdb (void)
e16bb312 8282{
c19d1205 8283 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8284}
8285
8286static void
c19d1205 8287do_vfp_dp_ldstmia (void)
e16bb312 8288{
c19d1205 8289 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8290}
8291
8292static void
c19d1205 8293do_vfp_dp_ldstmdb (void)
e16bb312 8294{
c19d1205 8295 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8296}
8297
8298static void
c19d1205 8299do_vfp_xp_ldstmia (void)
e16bb312 8300{
c19d1205
ZW
8301 vfp_dp_ldstm (VFP_LDSTMIAX);
8302}
e16bb312 8303
c19d1205
ZW
8304static void
8305do_vfp_xp_ldstmdb (void)
8306{
8307 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8308}
5287ad62
JB
8309
8310static void
8311do_vfp_dp_rd_rm (void)
8312{
8313 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8314 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8315}
8316
8317static void
8318do_vfp_dp_rn_rd (void)
8319{
8320 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8321 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8322}
8323
8324static void
8325do_vfp_dp_rd_rn (void)
8326{
8327 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8328 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8329}
8330
8331static void
8332do_vfp_dp_rd_rn_rm (void)
8333{
8334 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8335 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8336 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8337}
8338
8339static void
8340do_vfp_dp_rd (void)
8341{
8342 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8343}
8344
8345static void
8346do_vfp_dp_rm_rd_rn (void)
8347{
8348 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8349 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8350 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8351}
8352
8353/* VFPv3 instructions. */
8354static void
8355do_vfp_sp_const (void)
8356{
8357 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8358 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8359 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8360}
8361
8362static void
8363do_vfp_dp_const (void)
8364{
8365 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8366 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8367 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8368}
8369
8370static void
8371vfp_conv (int srcsize)
8372{
8373 unsigned immbits = srcsize - inst.operands[1].imm;
8374 inst.instruction |= (immbits & 1) << 5;
8375 inst.instruction |= (immbits >> 1);
8376}
8377
8378static void
8379do_vfp_sp_conv_16 (void)
8380{
8381 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8382 vfp_conv (16);
8383}
8384
8385static void
8386do_vfp_dp_conv_16 (void)
8387{
8388 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8389 vfp_conv (16);
8390}
8391
8392static void
8393do_vfp_sp_conv_32 (void)
8394{
8395 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8396 vfp_conv (32);
8397}
8398
8399static void
8400do_vfp_dp_conv_32 (void)
8401{
8402 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8403 vfp_conv (32);
8404}
c19d1205
ZW
8405\f
8406/* FPA instructions. Also in a logical order. */
e16bb312 8407
c19d1205
ZW
8408static void
8409do_fpa_cmp (void)
8410{
8411 inst.instruction |= inst.operands[0].reg << 16;
8412 inst.instruction |= inst.operands[1].reg;
8413}
b99bd4ef
NC
8414
8415static void
c19d1205 8416do_fpa_ldmstm (void)
b99bd4ef 8417{
c19d1205
ZW
8418 inst.instruction |= inst.operands[0].reg << 12;
8419 switch (inst.operands[1].imm)
8420 {
8421 case 1: inst.instruction |= CP_T_X; break;
8422 case 2: inst.instruction |= CP_T_Y; break;
8423 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8424 case 4: break;
8425 default: abort ();
8426 }
b99bd4ef 8427
c19d1205
ZW
8428 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8429 {
8430 /* The instruction specified "ea" or "fd", so we can only accept
8431 [Rn]{!}. The instruction does not really support stacking or
8432 unstacking, so we have to emulate these by setting appropriate
8433 bits and offsets. */
8434 constraint (inst.reloc.exp.X_op != O_constant
8435 || inst.reloc.exp.X_add_number != 0,
8436 _("this instruction does not support indexing"));
b99bd4ef 8437
c19d1205
ZW
8438 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8439 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8440
c19d1205
ZW
8441 if (!(inst.instruction & INDEX_UP))
8442 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8443
c19d1205
ZW
8444 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8445 {
8446 inst.operands[2].preind = 0;
8447 inst.operands[2].postind = 1;
8448 }
8449 }
b99bd4ef 8450
c19d1205 8451 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8452}
c19d1205
ZW
8453\f
8454/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8455
c19d1205
ZW
8456static void
8457do_iwmmxt_tandorc (void)
8458{
8459 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8460}
b99bd4ef 8461
c19d1205
ZW
8462static void
8463do_iwmmxt_textrc (void)
8464{
8465 inst.instruction |= inst.operands[0].reg << 12;
8466 inst.instruction |= inst.operands[1].imm;
8467}
b99bd4ef
NC
8468
8469static void
c19d1205 8470do_iwmmxt_textrm (void)
b99bd4ef 8471{
c19d1205
ZW
8472 inst.instruction |= inst.operands[0].reg << 12;
8473 inst.instruction |= inst.operands[1].reg << 16;
8474 inst.instruction |= inst.operands[2].imm;
8475}
b99bd4ef 8476
c19d1205
ZW
8477static void
8478do_iwmmxt_tinsr (void)
8479{
8480 inst.instruction |= inst.operands[0].reg << 16;
8481 inst.instruction |= inst.operands[1].reg << 12;
8482 inst.instruction |= inst.operands[2].imm;
8483}
b99bd4ef 8484
c19d1205
ZW
8485static void
8486do_iwmmxt_tmia (void)
8487{
8488 inst.instruction |= inst.operands[0].reg << 5;
8489 inst.instruction |= inst.operands[1].reg;
8490 inst.instruction |= inst.operands[2].reg << 12;
8491}
b99bd4ef 8492
c19d1205
ZW
8493static void
8494do_iwmmxt_waligni (void)
8495{
8496 inst.instruction |= inst.operands[0].reg << 12;
8497 inst.instruction |= inst.operands[1].reg << 16;
8498 inst.instruction |= inst.operands[2].reg;
8499 inst.instruction |= inst.operands[3].imm << 20;
8500}
b99bd4ef 8501
2d447fca
JM
8502static void
8503do_iwmmxt_wmerge (void)
8504{
8505 inst.instruction |= inst.operands[0].reg << 12;
8506 inst.instruction |= inst.operands[1].reg << 16;
8507 inst.instruction |= inst.operands[2].reg;
8508 inst.instruction |= inst.operands[3].imm << 21;
8509}
8510
c19d1205
ZW
8511static void
8512do_iwmmxt_wmov (void)
8513{
8514 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8515 inst.instruction |= inst.operands[0].reg << 12;
8516 inst.instruction |= inst.operands[1].reg << 16;
8517 inst.instruction |= inst.operands[1].reg;
8518}
b99bd4ef 8519
c19d1205
ZW
8520static void
8521do_iwmmxt_wldstbh (void)
8522{
8f06b2d8 8523 int reloc;
c19d1205 8524 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8525 if (thumb_mode)
8526 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8527 else
8528 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8529 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8530}
8531
c19d1205
ZW
8532static void
8533do_iwmmxt_wldstw (void)
8534{
8535 /* RIWR_RIWC clears .isreg for a control register. */
8536 if (!inst.operands[0].isreg)
8537 {
8538 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8539 inst.instruction |= 0xf0000000;
8540 }
b99bd4ef 8541
c19d1205
ZW
8542 inst.instruction |= inst.operands[0].reg << 12;
8543 encode_arm_cp_address (1, TRUE, TRUE, 0);
8544}
b99bd4ef
NC
8545
8546static void
c19d1205 8547do_iwmmxt_wldstd (void)
b99bd4ef 8548{
c19d1205 8549 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8550 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8551 && inst.operands[1].immisreg)
8552 {
8553 inst.instruction &= ~0x1a000ff;
8554 inst.instruction |= (0xf << 28);
8555 if (inst.operands[1].preind)
8556 inst.instruction |= PRE_INDEX;
8557 if (!inst.operands[1].negative)
8558 inst.instruction |= INDEX_UP;
8559 if (inst.operands[1].writeback)
8560 inst.instruction |= WRITE_BACK;
8561 inst.instruction |= inst.operands[1].reg << 16;
8562 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8563 inst.instruction |= inst.operands[1].imm;
8564 }
8565 else
8566 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8567}
b99bd4ef 8568
c19d1205
ZW
8569static void
8570do_iwmmxt_wshufh (void)
8571{
8572 inst.instruction |= inst.operands[0].reg << 12;
8573 inst.instruction |= inst.operands[1].reg << 16;
8574 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8575 inst.instruction |= (inst.operands[2].imm & 0x0f);
8576}
b99bd4ef 8577
c19d1205
ZW
8578static void
8579do_iwmmxt_wzero (void)
8580{
8581 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8582 inst.instruction |= inst.operands[0].reg;
8583 inst.instruction |= inst.operands[0].reg << 12;
8584 inst.instruction |= inst.operands[0].reg << 16;
8585}
2d447fca
JM
8586
8587static void
8588do_iwmmxt_wrwrwr_or_imm5 (void)
8589{
8590 if (inst.operands[2].isreg)
8591 do_rd_rn_rm ();
8592 else {
8593 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8594 _("immediate operand requires iWMMXt2"));
8595 do_rd_rn ();
8596 if (inst.operands[2].imm == 0)
8597 {
8598 switch ((inst.instruction >> 20) & 0xf)
8599 {
8600 case 4:
8601 case 5:
8602 case 6:
5f4273c7 8603 case 7:
2d447fca
JM
8604 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8605 inst.operands[2].imm = 16;
8606 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8607 break;
8608 case 8:
8609 case 9:
8610 case 10:
8611 case 11:
8612 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8613 inst.operands[2].imm = 32;
8614 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8615 break;
8616 case 12:
8617 case 13:
8618 case 14:
8619 case 15:
8620 {
8621 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8622 unsigned long wrn;
8623 wrn = (inst.instruction >> 16) & 0xf;
8624 inst.instruction &= 0xff0fff0f;
8625 inst.instruction |= wrn;
8626 /* Bail out here; the instruction is now assembled. */
8627 return;
8628 }
8629 }
8630 }
8631 /* Map 32 -> 0, etc. */
8632 inst.operands[2].imm &= 0x1f;
8633 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8634 }
8635}
c19d1205
ZW
8636\f
8637/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8638 operations first, then control, shift, and load/store. */
b99bd4ef 8639
c19d1205 8640/* Insns like "foo X,Y,Z". */
b99bd4ef 8641
c19d1205
ZW
8642static void
8643do_mav_triple (void)
8644{
8645 inst.instruction |= inst.operands[0].reg << 16;
8646 inst.instruction |= inst.operands[1].reg;
8647 inst.instruction |= inst.operands[2].reg << 12;
8648}
b99bd4ef 8649
c19d1205
ZW
8650/* Insns like "foo W,X,Y,Z".
8651 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8652
c19d1205
ZW
8653static void
8654do_mav_quad (void)
8655{
8656 inst.instruction |= inst.operands[0].reg << 5;
8657 inst.instruction |= inst.operands[1].reg << 12;
8658 inst.instruction |= inst.operands[2].reg << 16;
8659 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8660}
8661
c19d1205
ZW
8662/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8663static void
8664do_mav_dspsc (void)
a737bd4d 8665{
c19d1205
ZW
8666 inst.instruction |= inst.operands[1].reg << 12;
8667}
a737bd4d 8668
c19d1205
ZW
8669/* Maverick shift immediate instructions.
8670 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8671 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8672
c19d1205
ZW
8673static void
8674do_mav_shift (void)
8675{
8676 int imm = inst.operands[2].imm;
a737bd4d 8677
c19d1205
ZW
8678 inst.instruction |= inst.operands[0].reg << 12;
8679 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8680
c19d1205
ZW
8681 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8682 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8683 Bit 4 should be 0. */
8684 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8685
c19d1205
ZW
8686 inst.instruction |= imm;
8687}
8688\f
8689/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8690
c19d1205
ZW
8691/* Xscale multiply-accumulate (argument parse)
8692 MIAcc acc0,Rm,Rs
8693 MIAPHcc acc0,Rm,Rs
8694 MIAxycc acc0,Rm,Rs. */
a737bd4d 8695
c19d1205
ZW
8696static void
8697do_xsc_mia (void)
8698{
8699 inst.instruction |= inst.operands[1].reg;
8700 inst.instruction |= inst.operands[2].reg << 12;
8701}
a737bd4d 8702
c19d1205 8703/* Xscale move-accumulator-register (argument parse)
a737bd4d 8704
c19d1205 8705 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8706
c19d1205
ZW
8707static void
8708do_xsc_mar (void)
8709{
8710 inst.instruction |= inst.operands[1].reg << 12;
8711 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8712}
8713
c19d1205 8714/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8715
c19d1205 8716 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8717
8718static void
c19d1205 8719do_xsc_mra (void)
b99bd4ef 8720{
c19d1205
ZW
8721 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8722 inst.instruction |= inst.operands[0].reg << 12;
8723 inst.instruction |= inst.operands[1].reg << 16;
8724}
8725\f
8726/* Encoding functions relevant only to Thumb. */
b99bd4ef 8727
c19d1205
ZW
8728/* inst.operands[i] is a shifted-register operand; encode
8729 it into inst.instruction in the format used by Thumb32. */
8730
8731static void
8732encode_thumb32_shifted_operand (int i)
8733{
8734 unsigned int value = inst.reloc.exp.X_add_number;
8735 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8736
9c3c69f2
PB
8737 constraint (inst.operands[i].immisreg,
8738 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8739 inst.instruction |= inst.operands[i].reg;
8740 if (shift == SHIFT_RRX)
8741 inst.instruction |= SHIFT_ROR << 4;
8742 else
b99bd4ef 8743 {
c19d1205
ZW
8744 constraint (inst.reloc.exp.X_op != O_constant,
8745 _("expression too complex"));
8746
8747 constraint (value > 32
8748 || (value == 32 && (shift == SHIFT_LSL
8749 || shift == SHIFT_ROR)),
8750 _("shift expression is too large"));
8751
8752 if (value == 0)
8753 shift = SHIFT_LSL;
8754 else if (value == 32)
8755 value = 0;
8756
8757 inst.instruction |= shift << 4;
8758 inst.instruction |= (value & 0x1c) << 10;
8759 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8760 }
c19d1205 8761}
b99bd4ef 8762
b99bd4ef 8763
c19d1205
ZW
8764/* inst.operands[i] was set up by parse_address. Encode it into a
8765 Thumb32 format load or store instruction. Reject forms that cannot
8766 be used with such instructions. If is_t is true, reject forms that
8767 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8768 that cannot be used with a D instruction. If it is a store insn,
8769 reject PC in Rn. */
b99bd4ef 8770
c19d1205
ZW
8771static void
8772encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8773{
5be8be5d 8774 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8775
8776 constraint (!inst.operands[i].isreg,
53365c0d 8777 _("Instruction does not support =N addresses"));
b99bd4ef 8778
c19d1205
ZW
8779 inst.instruction |= inst.operands[i].reg << 16;
8780 if (inst.operands[i].immisreg)
b99bd4ef 8781 {
5be8be5d 8782 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8783 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8784 constraint (inst.operands[i].negative,
8785 _("Thumb does not support negative register indexing"));
8786 constraint (inst.operands[i].postind,
8787 _("Thumb does not support register post-indexing"));
8788 constraint (inst.operands[i].writeback,
8789 _("Thumb does not support register indexing with writeback"));
8790 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8791 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8792
f40d1643 8793 inst.instruction |= inst.operands[i].imm;
c19d1205 8794 if (inst.operands[i].shifted)
b99bd4ef 8795 {
c19d1205
ZW
8796 constraint (inst.reloc.exp.X_op != O_constant,
8797 _("expression too complex"));
9c3c69f2
PB
8798 constraint (inst.reloc.exp.X_add_number < 0
8799 || inst.reloc.exp.X_add_number > 3,
c19d1205 8800 _("shift out of range"));
9c3c69f2 8801 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8802 }
8803 inst.reloc.type = BFD_RELOC_UNUSED;
8804 }
8805 else if (inst.operands[i].preind)
8806 {
5be8be5d 8807 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8808 constraint (is_t && inst.operands[i].writeback,
c19d1205 8809 _("cannot use writeback with this instruction"));
5be8be5d
DG
8810 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8811 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8812
8813 if (is_d)
8814 {
8815 inst.instruction |= 0x01000000;
8816 if (inst.operands[i].writeback)
8817 inst.instruction |= 0x00200000;
b99bd4ef 8818 }
c19d1205 8819 else
b99bd4ef 8820 {
c19d1205
ZW
8821 inst.instruction |= 0x00000c00;
8822 if (inst.operands[i].writeback)
8823 inst.instruction |= 0x00000100;
b99bd4ef 8824 }
c19d1205 8825 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8826 }
c19d1205 8827 else if (inst.operands[i].postind)
b99bd4ef 8828 {
9c2799c2 8829 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8830 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8831 constraint (is_t, _("cannot use post-indexing with this instruction"));
8832
8833 if (is_d)
8834 inst.instruction |= 0x00200000;
8835 else
8836 inst.instruction |= 0x00000900;
8837 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8838 }
8839 else /* unindexed - only for coprocessor */
8840 inst.error = _("instruction does not accept unindexed addressing");
8841}
8842
8843/* Table of Thumb instructions which exist in both 16- and 32-bit
8844 encodings (the latter only in post-V6T2 cores). The index is the
8845 value used in the insns table below. When there is more than one
8846 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8847 holds variant (1).
8848 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8849#define T16_32_TAB \
21d799b5
NC
8850 X(_adc, 4140, eb400000), \
8851 X(_adcs, 4140, eb500000), \
8852 X(_add, 1c00, eb000000), \
8853 X(_adds, 1c00, eb100000), \
8854 X(_addi, 0000, f1000000), \
8855 X(_addis, 0000, f1100000), \
8856 X(_add_pc,000f, f20f0000), \
8857 X(_add_sp,000d, f10d0000), \
8858 X(_adr, 000f, f20f0000), \
8859 X(_and, 4000, ea000000), \
8860 X(_ands, 4000, ea100000), \
8861 X(_asr, 1000, fa40f000), \
8862 X(_asrs, 1000, fa50f000), \
8863 X(_b, e000, f000b000), \
8864 X(_bcond, d000, f0008000), \
8865 X(_bic, 4380, ea200000), \
8866 X(_bics, 4380, ea300000), \
8867 X(_cmn, 42c0, eb100f00), \
8868 X(_cmp, 2800, ebb00f00), \
8869 X(_cpsie, b660, f3af8400), \
8870 X(_cpsid, b670, f3af8600), \
8871 X(_cpy, 4600, ea4f0000), \
8872 X(_dec_sp,80dd, f1ad0d00), \
8873 X(_eor, 4040, ea800000), \
8874 X(_eors, 4040, ea900000), \
8875 X(_inc_sp,00dd, f10d0d00), \
8876 X(_ldmia, c800, e8900000), \
8877 X(_ldr, 6800, f8500000), \
8878 X(_ldrb, 7800, f8100000), \
8879 X(_ldrh, 8800, f8300000), \
8880 X(_ldrsb, 5600, f9100000), \
8881 X(_ldrsh, 5e00, f9300000), \
8882 X(_ldr_pc,4800, f85f0000), \
8883 X(_ldr_pc2,4800, f85f0000), \
8884 X(_ldr_sp,9800, f85d0000), \
8885 X(_lsl, 0000, fa00f000), \
8886 X(_lsls, 0000, fa10f000), \
8887 X(_lsr, 0800, fa20f000), \
8888 X(_lsrs, 0800, fa30f000), \
8889 X(_mov, 2000, ea4f0000), \
8890 X(_movs, 2000, ea5f0000), \
8891 X(_mul, 4340, fb00f000), \
8892 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8893 X(_mvn, 43c0, ea6f0000), \
8894 X(_mvns, 43c0, ea7f0000), \
8895 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8896 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8897 X(_orr, 4300, ea400000), \
8898 X(_orrs, 4300, ea500000), \
8899 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8900 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8901 X(_rev, ba00, fa90f080), \
8902 X(_rev16, ba40, fa90f090), \
8903 X(_revsh, bac0, fa90f0b0), \
8904 X(_ror, 41c0, fa60f000), \
8905 X(_rors, 41c0, fa70f000), \
8906 X(_sbc, 4180, eb600000), \
8907 X(_sbcs, 4180, eb700000), \
8908 X(_stmia, c000, e8800000), \
8909 X(_str, 6000, f8400000), \
8910 X(_strb, 7000, f8000000), \
8911 X(_strh, 8000, f8200000), \
8912 X(_str_sp,9000, f84d0000), \
8913 X(_sub, 1e00, eba00000), \
8914 X(_subs, 1e00, ebb00000), \
8915 X(_subi, 8000, f1a00000), \
8916 X(_subis, 8000, f1b00000), \
8917 X(_sxtb, b240, fa4ff080), \
8918 X(_sxth, b200, fa0ff080), \
8919 X(_tst, 4200, ea100f00), \
8920 X(_uxtb, b2c0, fa5ff080), \
8921 X(_uxth, b280, fa1ff080), \
8922 X(_nop, bf00, f3af8000), \
8923 X(_yield, bf10, f3af8001), \
8924 X(_wfe, bf20, f3af8002), \
8925 X(_wfi, bf30, f3af8003), \
8926 X(_sev, bf40, f3af8004),
c19d1205
ZW
8927
8928/* To catch errors in encoding functions, the codes are all offset by
8929 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8930 as 16-bit instructions. */
21d799b5 8931#define X(a,b,c) T_MNEM##a
c19d1205
ZW
8932enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8933#undef X
8934
8935#define X(a,b,c) 0x##b
8936static const unsigned short thumb_op16[] = { T16_32_TAB };
8937#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8938#undef X
8939
8940#define X(a,b,c) 0x##c
8941static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
8942#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8943#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
8944#undef X
8945#undef T16_32_TAB
8946
8947/* Thumb instruction encoders, in alphabetical order. */
8948
92e90b6e 8949/* ADDW or SUBW. */
c921be7d 8950
92e90b6e
PB
8951static void
8952do_t_add_sub_w (void)
8953{
8954 int Rd, Rn;
8955
8956 Rd = inst.operands[0].reg;
8957 Rn = inst.operands[1].reg;
8958
539d4391
NC
8959 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8960 is the SP-{plus,minus}-immediate form of the instruction. */
8961 if (Rn == REG_SP)
8962 constraint (Rd == REG_PC, BAD_PC);
8963 else
8964 reject_bad_reg (Rd);
fdfde340 8965
92e90b6e
PB
8966 inst.instruction |= (Rn << 16) | (Rd << 8);
8967 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8968}
8969
c19d1205
ZW
8970/* Parse an add or subtract instruction. We get here with inst.instruction
8971 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8972
8973static void
8974do_t_add_sub (void)
8975{
8976 int Rd, Rs, Rn;
8977
8978 Rd = inst.operands[0].reg;
8979 Rs = (inst.operands[1].present
8980 ? inst.operands[1].reg /* Rd, Rs, foo */
8981 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8982
e07e6e58
NC
8983 if (Rd == REG_PC)
8984 set_it_insn_type_last ();
8985
c19d1205
ZW
8986 if (unified_syntax)
8987 {
0110f2b8
PB
8988 bfd_boolean flags;
8989 bfd_boolean narrow;
8990 int opcode;
8991
8992 flags = (inst.instruction == T_MNEM_adds
8993 || inst.instruction == T_MNEM_subs);
8994 if (flags)
e07e6e58 8995 narrow = !in_it_block ();
0110f2b8 8996 else
e07e6e58 8997 narrow = in_it_block ();
c19d1205 8998 if (!inst.operands[2].isreg)
b99bd4ef 8999 {
16805f35
PB
9000 int add;
9001
fdfde340
JM
9002 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9003
16805f35
PB
9004 add = (inst.instruction == T_MNEM_add
9005 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
9006 opcode = 0;
9007 if (inst.size_req != 4)
9008 {
0110f2b8
PB
9009 /* Attempt to use a narrow opcode, with relaxation if
9010 appropriate. */
9011 if (Rd == REG_SP && Rs == REG_SP && !flags)
9012 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9013 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9014 opcode = T_MNEM_add_sp;
9015 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9016 opcode = T_MNEM_add_pc;
9017 else if (Rd <= 7 && Rs <= 7 && narrow)
9018 {
9019 if (flags)
9020 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9021 else
9022 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9023 }
9024 if (opcode)
9025 {
9026 inst.instruction = THUMB_OP16(opcode);
9027 inst.instruction |= (Rd << 4) | Rs;
9028 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9029 if (inst.size_req != 2)
9030 inst.relax = opcode;
9031 }
9032 else
9033 constraint (inst.size_req == 2, BAD_HIREG);
9034 }
9035 if (inst.size_req == 4
9036 || (inst.size_req != 2 && !opcode))
9037 {
efd81785
PB
9038 if (Rd == REG_PC)
9039 {
fdfde340 9040 constraint (add, BAD_PC);
efd81785
PB
9041 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9042 _("only SUBS PC, LR, #const allowed"));
9043 constraint (inst.reloc.exp.X_op != O_constant,
9044 _("expression too complex"));
9045 constraint (inst.reloc.exp.X_add_number < 0
9046 || inst.reloc.exp.X_add_number > 0xff,
9047 _("immediate value out of range"));
9048 inst.instruction = T2_SUBS_PC_LR
9049 | inst.reloc.exp.X_add_number;
9050 inst.reloc.type = BFD_RELOC_UNUSED;
9051 return;
9052 }
9053 else if (Rs == REG_PC)
16805f35
PB
9054 {
9055 /* Always use addw/subw. */
9056 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9057 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9058 }
9059 else
9060 {
9061 inst.instruction = THUMB_OP32 (inst.instruction);
9062 inst.instruction = (inst.instruction & 0xe1ffffff)
9063 | 0x10000000;
9064 if (flags)
9065 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9066 else
9067 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9068 }
dc4503c6
PB
9069 inst.instruction |= Rd << 8;
9070 inst.instruction |= Rs << 16;
0110f2b8 9071 }
b99bd4ef 9072 }
c19d1205
ZW
9073 else
9074 {
9075 Rn = inst.operands[2].reg;
9076 /* See if we can do this with a 16-bit instruction. */
9077 if (!inst.operands[2].shifted && inst.size_req != 4)
9078 {
e27ec89e
PB
9079 if (Rd > 7 || Rs > 7 || Rn > 7)
9080 narrow = FALSE;
9081
9082 if (narrow)
c19d1205 9083 {
e27ec89e
PB
9084 inst.instruction = ((inst.instruction == T_MNEM_adds
9085 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9086 ? T_OPCODE_ADD_R3
9087 : T_OPCODE_SUB_R3);
9088 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9089 return;
9090 }
b99bd4ef 9091
7e806470 9092 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9093 {
7e806470
PB
9094 /* Thumb-1 cores (except v6-M) require at least one high
9095 register in a narrow non flag setting add. */
9096 if (Rd > 7 || Rn > 7
9097 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9098 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9099 {
7e806470
PB
9100 if (Rd == Rn)
9101 {
9102 Rn = Rs;
9103 Rs = Rd;
9104 }
c19d1205
ZW
9105 inst.instruction = T_OPCODE_ADD_HI;
9106 inst.instruction |= (Rd & 8) << 4;
9107 inst.instruction |= (Rd & 7);
9108 inst.instruction |= Rn << 3;
9109 return;
9110 }
c19d1205
ZW
9111 }
9112 }
c921be7d 9113
fdfde340
JM
9114 constraint (Rd == REG_PC, BAD_PC);
9115 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9116 constraint (Rs == REG_PC, BAD_PC);
9117 reject_bad_reg (Rn);
9118
c19d1205
ZW
9119 /* If we get here, it can't be done in 16 bits. */
9120 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9121 _("shift must be constant"));
9122 inst.instruction = THUMB_OP32 (inst.instruction);
9123 inst.instruction |= Rd << 8;
9124 inst.instruction |= Rs << 16;
9125 encode_thumb32_shifted_operand (2);
9126 }
9127 }
9128 else
9129 {
9130 constraint (inst.instruction == T_MNEM_adds
9131 || inst.instruction == T_MNEM_subs,
9132 BAD_THUMB32);
b99bd4ef 9133
c19d1205 9134 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9135 {
c19d1205
ZW
9136 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9137 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9138 BAD_HIREG);
9139
9140 inst.instruction = (inst.instruction == T_MNEM_add
9141 ? 0x0000 : 0x8000);
9142 inst.instruction |= (Rd << 4) | Rs;
9143 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9144 return;
9145 }
9146
c19d1205
ZW
9147 Rn = inst.operands[2].reg;
9148 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9149
c19d1205
ZW
9150 /* We now have Rd, Rs, and Rn set to registers. */
9151 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9152 {
c19d1205
ZW
9153 /* Can't do this for SUB. */
9154 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9155 inst.instruction = T_OPCODE_ADD_HI;
9156 inst.instruction |= (Rd & 8) << 4;
9157 inst.instruction |= (Rd & 7);
9158 if (Rs == Rd)
9159 inst.instruction |= Rn << 3;
9160 else if (Rn == Rd)
9161 inst.instruction |= Rs << 3;
9162 else
9163 constraint (1, _("dest must overlap one source register"));
9164 }
9165 else
9166 {
9167 inst.instruction = (inst.instruction == T_MNEM_add
9168 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9169 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9170 }
b99bd4ef 9171 }
b99bd4ef
NC
9172}
9173
c19d1205
ZW
9174static void
9175do_t_adr (void)
9176{
fdfde340
JM
9177 unsigned Rd;
9178
9179 Rd = inst.operands[0].reg;
9180 reject_bad_reg (Rd);
9181
9182 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9183 {
9184 /* Defer to section relaxation. */
9185 inst.relax = inst.instruction;
9186 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9187 inst.instruction |= Rd << 4;
0110f2b8
PB
9188 }
9189 else if (unified_syntax && inst.size_req != 2)
e9f89963 9190 {
0110f2b8 9191 /* Generate a 32-bit opcode. */
e9f89963 9192 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9193 inst.instruction |= Rd << 8;
e9f89963
PB
9194 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9195 inst.reloc.pc_rel = 1;
9196 }
9197 else
9198 {
0110f2b8 9199 /* Generate a 16-bit opcode. */
e9f89963
PB
9200 inst.instruction = THUMB_OP16 (inst.instruction);
9201 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9202 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9203 inst.reloc.pc_rel = 1;
b99bd4ef 9204
fdfde340 9205 inst.instruction |= Rd << 4;
e9f89963 9206 }
c19d1205 9207}
b99bd4ef 9208
c19d1205
ZW
9209/* Arithmetic instructions for which there is just one 16-bit
9210 instruction encoding, and it allows only two low registers.
9211 For maximal compatibility with ARM syntax, we allow three register
9212 operands even when Thumb-32 instructions are not available, as long
9213 as the first two are identical. For instance, both "sbc r0,r1" and
9214 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9215static void
c19d1205 9216do_t_arit3 (void)
b99bd4ef 9217{
c19d1205 9218 int Rd, Rs, Rn;
b99bd4ef 9219
c19d1205
ZW
9220 Rd = inst.operands[0].reg;
9221 Rs = (inst.operands[1].present
9222 ? inst.operands[1].reg /* Rd, Rs, foo */
9223 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9224 Rn = inst.operands[2].reg;
b99bd4ef 9225
fdfde340
JM
9226 reject_bad_reg (Rd);
9227 reject_bad_reg (Rs);
9228 if (inst.operands[2].isreg)
9229 reject_bad_reg (Rn);
9230
c19d1205 9231 if (unified_syntax)
b99bd4ef 9232 {
c19d1205
ZW
9233 if (!inst.operands[2].isreg)
9234 {
9235 /* For an immediate, we always generate a 32-bit opcode;
9236 section relaxation will shrink it later if possible. */
9237 inst.instruction = THUMB_OP32 (inst.instruction);
9238 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9239 inst.instruction |= Rd << 8;
9240 inst.instruction |= Rs << 16;
9241 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9242 }
9243 else
9244 {
e27ec89e
PB
9245 bfd_boolean narrow;
9246
c19d1205 9247 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9248 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9249 narrow = !in_it_block ();
e27ec89e 9250 else
e07e6e58 9251 narrow = in_it_block ();
e27ec89e
PB
9252
9253 if (Rd > 7 || Rn > 7 || Rs > 7)
9254 narrow = FALSE;
9255 if (inst.operands[2].shifted)
9256 narrow = FALSE;
9257 if (inst.size_req == 4)
9258 narrow = FALSE;
9259
9260 if (narrow
c19d1205
ZW
9261 && Rd == Rs)
9262 {
9263 inst.instruction = THUMB_OP16 (inst.instruction);
9264 inst.instruction |= Rd;
9265 inst.instruction |= Rn << 3;
9266 return;
9267 }
b99bd4ef 9268
c19d1205
ZW
9269 /* If we get here, it can't be done in 16 bits. */
9270 constraint (inst.operands[2].shifted
9271 && inst.operands[2].immisreg,
9272 _("shift must be constant"));
9273 inst.instruction = THUMB_OP32 (inst.instruction);
9274 inst.instruction |= Rd << 8;
9275 inst.instruction |= Rs << 16;
9276 encode_thumb32_shifted_operand (2);
9277 }
a737bd4d 9278 }
c19d1205 9279 else
b99bd4ef 9280 {
c19d1205
ZW
9281 /* On its face this is a lie - the instruction does set the
9282 flags. However, the only supported mnemonic in this mode
9283 says it doesn't. */
9284 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9285
c19d1205
ZW
9286 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9287 _("unshifted register required"));
9288 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9289 constraint (Rd != Rs,
9290 _("dest and source1 must be the same register"));
a737bd4d 9291
c19d1205
ZW
9292 inst.instruction = THUMB_OP16 (inst.instruction);
9293 inst.instruction |= Rd;
9294 inst.instruction |= Rn << 3;
b99bd4ef 9295 }
a737bd4d 9296}
b99bd4ef 9297
c19d1205
ZW
9298/* Similarly, but for instructions where the arithmetic operation is
9299 commutative, so we can allow either of them to be different from
9300 the destination operand in a 16-bit instruction. For instance, all
9301 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9302 accepted. */
9303static void
9304do_t_arit3c (void)
a737bd4d 9305{
c19d1205 9306 int Rd, Rs, Rn;
b99bd4ef 9307
c19d1205
ZW
9308 Rd = inst.operands[0].reg;
9309 Rs = (inst.operands[1].present
9310 ? inst.operands[1].reg /* Rd, Rs, foo */
9311 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9312 Rn = inst.operands[2].reg;
c921be7d 9313
fdfde340
JM
9314 reject_bad_reg (Rd);
9315 reject_bad_reg (Rs);
9316 if (inst.operands[2].isreg)
9317 reject_bad_reg (Rn);
a737bd4d 9318
c19d1205 9319 if (unified_syntax)
a737bd4d 9320 {
c19d1205 9321 if (!inst.operands[2].isreg)
b99bd4ef 9322 {
c19d1205
ZW
9323 /* For an immediate, we always generate a 32-bit opcode;
9324 section relaxation will shrink it later if possible. */
9325 inst.instruction = THUMB_OP32 (inst.instruction);
9326 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9327 inst.instruction |= Rd << 8;
9328 inst.instruction |= Rs << 16;
9329 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9330 }
c19d1205 9331 else
a737bd4d 9332 {
e27ec89e
PB
9333 bfd_boolean narrow;
9334
c19d1205 9335 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9336 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9337 narrow = !in_it_block ();
e27ec89e 9338 else
e07e6e58 9339 narrow = in_it_block ();
e27ec89e
PB
9340
9341 if (Rd > 7 || Rn > 7 || Rs > 7)
9342 narrow = FALSE;
9343 if (inst.operands[2].shifted)
9344 narrow = FALSE;
9345 if (inst.size_req == 4)
9346 narrow = FALSE;
9347
9348 if (narrow)
a737bd4d 9349 {
c19d1205 9350 if (Rd == Rs)
a737bd4d 9351 {
c19d1205
ZW
9352 inst.instruction = THUMB_OP16 (inst.instruction);
9353 inst.instruction |= Rd;
9354 inst.instruction |= Rn << 3;
9355 return;
a737bd4d 9356 }
c19d1205 9357 if (Rd == Rn)
a737bd4d 9358 {
c19d1205
ZW
9359 inst.instruction = THUMB_OP16 (inst.instruction);
9360 inst.instruction |= Rd;
9361 inst.instruction |= Rs << 3;
9362 return;
a737bd4d
NC
9363 }
9364 }
c19d1205
ZW
9365
9366 /* If we get here, it can't be done in 16 bits. */
9367 constraint (inst.operands[2].shifted
9368 && inst.operands[2].immisreg,
9369 _("shift must be constant"));
9370 inst.instruction = THUMB_OP32 (inst.instruction);
9371 inst.instruction |= Rd << 8;
9372 inst.instruction |= Rs << 16;
9373 encode_thumb32_shifted_operand (2);
a737bd4d 9374 }
b99bd4ef 9375 }
c19d1205
ZW
9376 else
9377 {
9378 /* On its face this is a lie - the instruction does set the
9379 flags. However, the only supported mnemonic in this mode
9380 says it doesn't. */
9381 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9382
c19d1205
ZW
9383 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9384 _("unshifted register required"));
9385 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9386
9387 inst.instruction = THUMB_OP16 (inst.instruction);
9388 inst.instruction |= Rd;
9389
9390 if (Rd == Rs)
9391 inst.instruction |= Rn << 3;
9392 else if (Rd == Rn)
9393 inst.instruction |= Rs << 3;
9394 else
9395 constraint (1, _("dest must overlap one source register"));
9396 }
a737bd4d
NC
9397}
9398
62b3e311
PB
9399static void
9400do_t_barrier (void)
9401{
9402 if (inst.operands[0].present)
9403 {
9404 constraint ((inst.instruction & 0xf0) != 0x40
9405 && inst.operands[0].imm != 0xf,
bd3ba5d1 9406 _("bad barrier type"));
62b3e311
PB
9407 inst.instruction |= inst.operands[0].imm;
9408 }
9409 else
9410 inst.instruction |= 0xf;
9411}
9412
c19d1205
ZW
9413static void
9414do_t_bfc (void)
a737bd4d 9415{
fdfde340 9416 unsigned Rd;
c19d1205
ZW
9417 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9418 constraint (msb > 32, _("bit-field extends past end of register"));
9419 /* The instruction encoding stores the LSB and MSB,
9420 not the LSB and width. */
fdfde340
JM
9421 Rd = inst.operands[0].reg;
9422 reject_bad_reg (Rd);
9423 inst.instruction |= Rd << 8;
c19d1205
ZW
9424 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9425 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9426 inst.instruction |= msb - 1;
b99bd4ef
NC
9427}
9428
c19d1205
ZW
9429static void
9430do_t_bfi (void)
b99bd4ef 9431{
fdfde340 9432 int Rd, Rn;
c19d1205 9433 unsigned int msb;
b99bd4ef 9434
fdfde340
JM
9435 Rd = inst.operands[0].reg;
9436 reject_bad_reg (Rd);
9437
c19d1205
ZW
9438 /* #0 in second position is alternative syntax for bfc, which is
9439 the same instruction but with REG_PC in the Rm field. */
9440 if (!inst.operands[1].isreg)
fdfde340
JM
9441 Rn = REG_PC;
9442 else
9443 {
9444 Rn = inst.operands[1].reg;
9445 reject_bad_reg (Rn);
9446 }
b99bd4ef 9447
c19d1205
ZW
9448 msb = inst.operands[2].imm + inst.operands[3].imm;
9449 constraint (msb > 32, _("bit-field extends past end of register"));
9450 /* The instruction encoding stores the LSB and MSB,
9451 not the LSB and width. */
fdfde340
JM
9452 inst.instruction |= Rd << 8;
9453 inst.instruction |= Rn << 16;
c19d1205
ZW
9454 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9455 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9456 inst.instruction |= msb - 1;
b99bd4ef
NC
9457}
9458
c19d1205
ZW
9459static void
9460do_t_bfx (void)
b99bd4ef 9461{
fdfde340
JM
9462 unsigned Rd, Rn;
9463
9464 Rd = inst.operands[0].reg;
9465 Rn = inst.operands[1].reg;
9466
9467 reject_bad_reg (Rd);
9468 reject_bad_reg (Rn);
9469
c19d1205
ZW
9470 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9471 _("bit-field extends past end of register"));
fdfde340
JM
9472 inst.instruction |= Rd << 8;
9473 inst.instruction |= Rn << 16;
c19d1205
ZW
9474 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9475 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9476 inst.instruction |= inst.operands[3].imm - 1;
9477}
b99bd4ef 9478
c19d1205
ZW
9479/* ARM V5 Thumb BLX (argument parse)
9480 BLX <target_addr> which is BLX(1)
9481 BLX <Rm> which is BLX(2)
9482 Unfortunately, there are two different opcodes for this mnemonic.
9483 So, the insns[].value is not used, and the code here zaps values
9484 into inst.instruction.
b99bd4ef 9485
c19d1205
ZW
9486 ??? How to take advantage of the additional two bits of displacement
9487 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9488
c19d1205
ZW
9489static void
9490do_t_blx (void)
9491{
e07e6e58
NC
9492 set_it_insn_type_last ();
9493
c19d1205 9494 if (inst.operands[0].isreg)
fdfde340
JM
9495 {
9496 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9497 /* We have a register, so this is BLX(2). */
9498 inst.instruction |= inst.operands[0].reg << 3;
9499 }
b99bd4ef
NC
9500 else
9501 {
c19d1205 9502 /* No register. This must be BLX(1). */
2fc8bdac 9503 inst.instruction = 0xf000e800;
00adf2d4 9504 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9505 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9506 }
9507}
9508
c19d1205
ZW
9509static void
9510do_t_branch (void)
b99bd4ef 9511{
0110f2b8 9512 int opcode;
dfa9f0d5
PB
9513 int cond;
9514
e07e6e58
NC
9515 cond = inst.cond;
9516 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9517
9518 if (in_it_block ())
dfa9f0d5
PB
9519 {
9520 /* Conditional branches inside IT blocks are encoded as unconditional
9521 branches. */
9522 cond = COND_ALWAYS;
dfa9f0d5
PB
9523 }
9524 else
9525 cond = inst.cond;
9526
9527 if (cond != COND_ALWAYS)
0110f2b8
PB
9528 opcode = T_MNEM_bcond;
9529 else
9530 opcode = inst.instruction;
9531
9532 if (unified_syntax && inst.size_req == 4)
c19d1205 9533 {
0110f2b8 9534 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9535 if (cond == COND_ALWAYS)
0110f2b8 9536 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9537 else
9538 {
9c2799c2 9539 gas_assert (cond != 0xF);
dfa9f0d5 9540 inst.instruction |= cond << 22;
c19d1205
ZW
9541 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9542 }
9543 }
b99bd4ef
NC
9544 else
9545 {
0110f2b8 9546 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9547 if (cond == COND_ALWAYS)
c19d1205
ZW
9548 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9549 else
b99bd4ef 9550 {
dfa9f0d5 9551 inst.instruction |= cond << 8;
c19d1205 9552 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9553 }
0110f2b8
PB
9554 /* Allow section relaxation. */
9555 if (unified_syntax && inst.size_req != 2)
9556 inst.relax = opcode;
b99bd4ef 9557 }
c19d1205
ZW
9558
9559 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9560}
9561
9562static void
c19d1205 9563do_t_bkpt (void)
b99bd4ef 9564{
dfa9f0d5
PB
9565 constraint (inst.cond != COND_ALWAYS,
9566 _("instruction is always unconditional"));
c19d1205 9567 if (inst.operands[0].present)
b99bd4ef 9568 {
c19d1205
ZW
9569 constraint (inst.operands[0].imm > 255,
9570 _("immediate value out of range"));
9571 inst.instruction |= inst.operands[0].imm;
e07e6e58 9572 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9573 }
b99bd4ef
NC
9574}
9575
9576static void
c19d1205 9577do_t_branch23 (void)
b99bd4ef 9578{
e07e6e58 9579 set_it_insn_type_last ();
c19d1205 9580 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9581 inst.reloc.pc_rel = 1;
9582
4343666d 9583#if defined(OBJ_COFF)
c19d1205
ZW
9584 /* If the destination of the branch is a defined symbol which does not have
9585 the THUMB_FUNC attribute, then we must be calling a function which has
9586 the (interfacearm) attribute. We look for the Thumb entry point to that
9587 function and change the branch to refer to that function instead. */
9588 if ( inst.reloc.exp.X_op == O_symbol
9589 && inst.reloc.exp.X_add_symbol != NULL
9590 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9591 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9592 inst.reloc.exp.X_add_symbol =
9593 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9594#endif
90e4755a
RE
9595}
9596
9597static void
c19d1205 9598do_t_bx (void)
90e4755a 9599{
e07e6e58 9600 set_it_insn_type_last ();
c19d1205
ZW
9601 inst.instruction |= inst.operands[0].reg << 3;
9602 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9603 should cause the alignment to be checked once it is known. This is
9604 because BX PC only works if the instruction is word aligned. */
9605}
90e4755a 9606
c19d1205
ZW
9607static void
9608do_t_bxj (void)
9609{
fdfde340 9610 int Rm;
90e4755a 9611
e07e6e58 9612 set_it_insn_type_last ();
fdfde340
JM
9613 Rm = inst.operands[0].reg;
9614 reject_bad_reg (Rm);
9615 inst.instruction |= Rm << 16;
90e4755a
RE
9616}
9617
9618static void
c19d1205 9619do_t_clz (void)
90e4755a 9620{
fdfde340
JM
9621 unsigned Rd;
9622 unsigned Rm;
9623
9624 Rd = inst.operands[0].reg;
9625 Rm = inst.operands[1].reg;
9626
9627 reject_bad_reg (Rd);
9628 reject_bad_reg (Rm);
9629
9630 inst.instruction |= Rd << 8;
9631 inst.instruction |= Rm << 16;
9632 inst.instruction |= Rm;
c19d1205 9633}
90e4755a 9634
dfa9f0d5
PB
9635static void
9636do_t_cps (void)
9637{
e07e6e58 9638 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9639 inst.instruction |= inst.operands[0].imm;
9640}
9641
c19d1205
ZW
9642static void
9643do_t_cpsi (void)
9644{
e07e6e58 9645 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9646 if (unified_syntax
62b3e311
PB
9647 && (inst.operands[1].present || inst.size_req == 4)
9648 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9649 {
c19d1205
ZW
9650 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9651 inst.instruction = 0xf3af8000;
9652 inst.instruction |= imod << 9;
9653 inst.instruction |= inst.operands[0].imm << 5;
9654 if (inst.operands[1].present)
9655 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9656 }
c19d1205 9657 else
90e4755a 9658 {
62b3e311
PB
9659 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9660 && (inst.operands[0].imm & 4),
9661 _("selected processor does not support 'A' form "
9662 "of this instruction"));
9663 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9664 _("Thumb does not support the 2-argument "
9665 "form of this instruction"));
9666 inst.instruction |= inst.operands[0].imm;
90e4755a 9667 }
90e4755a
RE
9668}
9669
c19d1205
ZW
9670/* THUMB CPY instruction (argument parse). */
9671
90e4755a 9672static void
c19d1205 9673do_t_cpy (void)
90e4755a 9674{
c19d1205 9675 if (inst.size_req == 4)
90e4755a 9676 {
c19d1205
ZW
9677 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9678 inst.instruction |= inst.operands[0].reg << 8;
9679 inst.instruction |= inst.operands[1].reg;
90e4755a 9680 }
c19d1205 9681 else
90e4755a 9682 {
c19d1205
ZW
9683 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9684 inst.instruction |= (inst.operands[0].reg & 0x7);
9685 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9686 }
90e4755a
RE
9687}
9688
90e4755a 9689static void
25fe350b 9690do_t_cbz (void)
90e4755a 9691{
e07e6e58 9692 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9693 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9694 inst.instruction |= inst.operands[0].reg;
9695 inst.reloc.pc_rel = 1;
9696 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9697}
90e4755a 9698
62b3e311
PB
9699static void
9700do_t_dbg (void)
9701{
9702 inst.instruction |= inst.operands[0].imm;
9703}
9704
9705static void
9706do_t_div (void)
9707{
fdfde340
JM
9708 unsigned Rd, Rn, Rm;
9709
9710 Rd = inst.operands[0].reg;
9711 Rn = (inst.operands[1].present
9712 ? inst.operands[1].reg : Rd);
9713 Rm = inst.operands[2].reg;
9714
9715 reject_bad_reg (Rd);
9716 reject_bad_reg (Rn);
9717 reject_bad_reg (Rm);
9718
9719 inst.instruction |= Rd << 8;
9720 inst.instruction |= Rn << 16;
9721 inst.instruction |= Rm;
62b3e311
PB
9722}
9723
c19d1205
ZW
9724static void
9725do_t_hint (void)
9726{
9727 if (unified_syntax && inst.size_req == 4)
9728 inst.instruction = THUMB_OP32 (inst.instruction);
9729 else
9730 inst.instruction = THUMB_OP16 (inst.instruction);
9731}
90e4755a 9732
c19d1205
ZW
9733static void
9734do_t_it (void)
9735{
9736 unsigned int cond = inst.operands[0].imm;
e27ec89e 9737
e07e6e58
NC
9738 set_it_insn_type (IT_INSN);
9739 now_it.mask = (inst.instruction & 0xf) | 0x10;
9740 now_it.cc = cond;
e27ec89e
PB
9741
9742 /* If the condition is a negative condition, invert the mask. */
c19d1205 9743 if ((cond & 0x1) == 0x0)
90e4755a 9744 {
c19d1205 9745 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9746
c19d1205
ZW
9747 if ((mask & 0x7) == 0)
9748 /* no conversion needed */;
9749 else if ((mask & 0x3) == 0)
e27ec89e
PB
9750 mask ^= 0x8;
9751 else if ((mask & 0x1) == 0)
9752 mask ^= 0xC;
c19d1205 9753 else
e27ec89e 9754 mask ^= 0xE;
90e4755a 9755
e27ec89e
PB
9756 inst.instruction &= 0xfff0;
9757 inst.instruction |= mask;
c19d1205 9758 }
90e4755a 9759
c19d1205
ZW
9760 inst.instruction |= cond << 4;
9761}
90e4755a 9762
3c707909
PB
9763/* Helper function used for both push/pop and ldm/stm. */
9764static void
9765encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9766{
9767 bfd_boolean load;
9768
9769 load = (inst.instruction & (1 << 20)) != 0;
9770
9771 if (mask & (1 << 13))
9772 inst.error = _("SP not allowed in register list");
1e5b0379
NC
9773
9774 if ((mask & (1 << base)) != 0
9775 && writeback)
9776 inst.error = _("having the base register in the register list when "
9777 "using write back is UNPREDICTABLE");
9778
3c707909
PB
9779 if (load)
9780 {
e07e6e58
NC
9781 if (mask & (1 << 15))
9782 {
9783 if (mask & (1 << 14))
9784 inst.error = _("LR and PC should not both be in register list");
9785 else
9786 set_it_insn_type_last ();
9787 }
3c707909
PB
9788 }
9789 else
9790 {
9791 if (mask & (1 << 15))
9792 inst.error = _("PC not allowed in register list");
3c707909
PB
9793 }
9794
9795 if ((mask & (mask - 1)) == 0)
9796 {
9797 /* Single register transfers implemented as str/ldr. */
9798 if (writeback)
9799 {
9800 if (inst.instruction & (1 << 23))
9801 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9802 else
9803 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9804 }
9805 else
9806 {
9807 if (inst.instruction & (1 << 23))
9808 inst.instruction = 0x00800000; /* ia -> [base] */
9809 else
9810 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9811 }
9812
9813 inst.instruction |= 0xf8400000;
9814 if (load)
9815 inst.instruction |= 0x00100000;
9816
5f4273c7 9817 mask = ffs (mask) - 1;
3c707909
PB
9818 mask <<= 12;
9819 }
9820 else if (writeback)
9821 inst.instruction |= WRITE_BACK;
9822
9823 inst.instruction |= mask;
9824 inst.instruction |= base << 16;
9825}
9826
c19d1205
ZW
9827static void
9828do_t_ldmstm (void)
9829{
9830 /* This really doesn't seem worth it. */
9831 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9832 _("expression too complex"));
9833 constraint (inst.operands[1].writeback,
9834 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9835
c19d1205
ZW
9836 if (unified_syntax)
9837 {
3c707909
PB
9838 bfd_boolean narrow;
9839 unsigned mask;
9840
9841 narrow = FALSE;
c19d1205
ZW
9842 /* See if we can use a 16-bit instruction. */
9843 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9844 && inst.size_req != 4
3c707909 9845 && !(inst.operands[1].imm & ~0xff))
90e4755a 9846 {
3c707909 9847 mask = 1 << inst.operands[0].reg;
90e4755a 9848
3c707909
PB
9849 if (inst.operands[0].reg <= 7
9850 && (inst.instruction == T_MNEM_stmia
9851 ? inst.operands[0].writeback
9852 : (inst.operands[0].writeback
9853 == !(inst.operands[1].imm & mask))))
90e4755a 9854 {
3c707909
PB
9855 if (inst.instruction == T_MNEM_stmia
9856 && (inst.operands[1].imm & mask)
9857 && (inst.operands[1].imm & (mask - 1)))
1e5b0379 9858 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 9859 inst.operands[0].reg);
3c707909
PB
9860
9861 inst.instruction = THUMB_OP16 (inst.instruction);
9862 inst.instruction |= inst.operands[0].reg << 8;
9863 inst.instruction |= inst.operands[1].imm;
9864 narrow = TRUE;
90e4755a 9865 }
3c707909
PB
9866 else if (inst.operands[0] .reg == REG_SP
9867 && inst.operands[0].writeback)
90e4755a 9868 {
3c707909
PB
9869 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9870 ? T_MNEM_push : T_MNEM_pop);
9871 inst.instruction |= inst.operands[1].imm;
9872 narrow = TRUE;
90e4755a 9873 }
3c707909
PB
9874 }
9875
9876 if (!narrow)
9877 {
c19d1205
ZW
9878 if (inst.instruction < 0xffff)
9879 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9880
5f4273c7
NC
9881 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9882 inst.operands[0].writeback);
90e4755a
RE
9883 }
9884 }
c19d1205 9885 else
90e4755a 9886 {
c19d1205
ZW
9887 constraint (inst.operands[0].reg > 7
9888 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9889 constraint (inst.instruction != T_MNEM_ldmia
9890 && inst.instruction != T_MNEM_stmia,
9891 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9892 if (inst.instruction == T_MNEM_stmia)
f03698e6 9893 {
c19d1205
ZW
9894 if (!inst.operands[0].writeback)
9895 as_warn (_("this instruction will write back the base register"));
9896 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9897 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 9898 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 9899 inst.operands[0].reg);
f03698e6 9900 }
c19d1205 9901 else
90e4755a 9902 {
c19d1205
ZW
9903 if (!inst.operands[0].writeback
9904 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9905 as_warn (_("this instruction will write back the base register"));
9906 else if (inst.operands[0].writeback
9907 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9908 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9909 }
9910
c19d1205
ZW
9911 inst.instruction = THUMB_OP16 (inst.instruction);
9912 inst.instruction |= inst.operands[0].reg << 8;
9913 inst.instruction |= inst.operands[1].imm;
9914 }
9915}
e28cd48c 9916
c19d1205
ZW
9917static void
9918do_t_ldrex (void)
9919{
9920 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9921 || inst.operands[1].postind || inst.operands[1].writeback
9922 || inst.operands[1].immisreg || inst.operands[1].shifted
9923 || inst.operands[1].negative,
01cfc07f 9924 BAD_ADDR_MODE);
e28cd48c 9925
5be8be5d
DG
9926 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9927
c19d1205
ZW
9928 inst.instruction |= inst.operands[0].reg << 12;
9929 inst.instruction |= inst.operands[1].reg << 16;
9930 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9931}
e28cd48c 9932
c19d1205
ZW
9933static void
9934do_t_ldrexd (void)
9935{
9936 if (!inst.operands[1].present)
1cac9012 9937 {
c19d1205
ZW
9938 constraint (inst.operands[0].reg == REG_LR,
9939 _("r14 not allowed as first register "
9940 "when second register is omitted"));
9941 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9942 }
c19d1205
ZW
9943 constraint (inst.operands[0].reg == inst.operands[1].reg,
9944 BAD_OVERLAP);
b99bd4ef 9945
c19d1205
ZW
9946 inst.instruction |= inst.operands[0].reg << 12;
9947 inst.instruction |= inst.operands[1].reg << 8;
9948 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9949}
9950
9951static void
c19d1205 9952do_t_ldst (void)
b99bd4ef 9953{
0110f2b8
PB
9954 unsigned long opcode;
9955 int Rn;
9956
e07e6e58
NC
9957 if (inst.operands[0].isreg
9958 && !inst.operands[0].preind
9959 && inst.operands[0].reg == REG_PC)
9960 set_it_insn_type_last ();
9961
0110f2b8 9962 opcode = inst.instruction;
c19d1205 9963 if (unified_syntax)
b99bd4ef 9964 {
53365c0d
PB
9965 if (!inst.operands[1].isreg)
9966 {
9967 if (opcode <= 0xffff)
9968 inst.instruction = THUMB_OP32 (opcode);
9969 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9970 return;
9971 }
0110f2b8
PB
9972 if (inst.operands[1].isreg
9973 && !inst.operands[1].writeback
c19d1205
ZW
9974 && !inst.operands[1].shifted && !inst.operands[1].postind
9975 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9976 && opcode <= 0xffff
9977 && inst.size_req != 4)
c19d1205 9978 {
0110f2b8
PB
9979 /* Insn may have a 16-bit form. */
9980 Rn = inst.operands[1].reg;
9981 if (inst.operands[1].immisreg)
9982 {
9983 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9984 /* [Rn, Rik] */
0110f2b8
PB
9985 if (Rn <= 7 && inst.operands[1].imm <= 7)
9986 goto op16;
5be8be5d
DG
9987 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
9988 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
9989 }
9990 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9991 && opcode != T_MNEM_ldrsb)
9992 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9993 || (Rn == REG_SP && opcode == T_MNEM_str))
9994 {
9995 /* [Rn, #const] */
9996 if (Rn > 7)
9997 {
9998 if (Rn == REG_PC)
9999 {
10000 if (inst.reloc.pc_rel)
10001 opcode = T_MNEM_ldr_pc2;
10002 else
10003 opcode = T_MNEM_ldr_pc;
10004 }
10005 else
10006 {
10007 if (opcode == T_MNEM_ldr)
10008 opcode = T_MNEM_ldr_sp;
10009 else
10010 opcode = T_MNEM_str_sp;
10011 }
10012 inst.instruction = inst.operands[0].reg << 8;
10013 }
10014 else
10015 {
10016 inst.instruction = inst.operands[0].reg;
10017 inst.instruction |= inst.operands[1].reg << 3;
10018 }
10019 inst.instruction |= THUMB_OP16 (opcode);
10020 if (inst.size_req == 2)
10021 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10022 else
10023 inst.relax = opcode;
10024 return;
10025 }
c19d1205 10026 }
0110f2b8 10027 /* Definitely a 32-bit variant. */
5be8be5d
DG
10028
10029 /* Do some validations regarding addressing modes. */
10030 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10031 && opcode != T_MNEM_str)
10032 reject_bad_reg (inst.operands[1].imm);
10033
0110f2b8 10034 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10035 inst.instruction |= inst.operands[0].reg << 12;
10036 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10037 return;
10038 }
10039
c19d1205
ZW
10040 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10041
10042 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10043 {
c19d1205
ZW
10044 /* Only [Rn,Rm] is acceptable. */
10045 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10046 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10047 || inst.operands[1].postind || inst.operands[1].shifted
10048 || inst.operands[1].negative,
10049 _("Thumb does not support this addressing mode"));
10050 inst.instruction = THUMB_OP16 (inst.instruction);
10051 goto op16;
b99bd4ef 10052 }
5f4273c7 10053
c19d1205
ZW
10054 inst.instruction = THUMB_OP16 (inst.instruction);
10055 if (!inst.operands[1].isreg)
10056 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10057 return;
b99bd4ef 10058
c19d1205
ZW
10059 constraint (!inst.operands[1].preind
10060 || inst.operands[1].shifted
10061 || inst.operands[1].writeback,
10062 _("Thumb does not support this addressing mode"));
10063 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10064 {
c19d1205
ZW
10065 constraint (inst.instruction & 0x0600,
10066 _("byte or halfword not valid for base register"));
10067 constraint (inst.operands[1].reg == REG_PC
10068 && !(inst.instruction & THUMB_LOAD_BIT),
10069 _("r15 based store not allowed"));
10070 constraint (inst.operands[1].immisreg,
10071 _("invalid base register for register offset"));
b99bd4ef 10072
c19d1205
ZW
10073 if (inst.operands[1].reg == REG_PC)
10074 inst.instruction = T_OPCODE_LDR_PC;
10075 else if (inst.instruction & THUMB_LOAD_BIT)
10076 inst.instruction = T_OPCODE_LDR_SP;
10077 else
10078 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10079
c19d1205
ZW
10080 inst.instruction |= inst.operands[0].reg << 8;
10081 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10082 return;
10083 }
90e4755a 10084
c19d1205
ZW
10085 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10086 if (!inst.operands[1].immisreg)
10087 {
10088 /* Immediate offset. */
10089 inst.instruction |= inst.operands[0].reg;
10090 inst.instruction |= inst.operands[1].reg << 3;
10091 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10092 return;
10093 }
90e4755a 10094
c19d1205
ZW
10095 /* Register offset. */
10096 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10097 constraint (inst.operands[1].negative,
10098 _("Thumb does not support this addressing mode"));
90e4755a 10099
c19d1205
ZW
10100 op16:
10101 switch (inst.instruction)
10102 {
10103 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10104 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10105 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10106 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10107 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10108 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10109 case 0x5600 /* ldrsb */:
10110 case 0x5e00 /* ldrsh */: break;
10111 default: abort ();
10112 }
90e4755a 10113
c19d1205
ZW
10114 inst.instruction |= inst.operands[0].reg;
10115 inst.instruction |= inst.operands[1].reg << 3;
10116 inst.instruction |= inst.operands[1].imm << 6;
10117}
90e4755a 10118
c19d1205
ZW
10119static void
10120do_t_ldstd (void)
10121{
10122 if (!inst.operands[1].present)
b99bd4ef 10123 {
c19d1205
ZW
10124 inst.operands[1].reg = inst.operands[0].reg + 1;
10125 constraint (inst.operands[0].reg == REG_LR,
10126 _("r14 not allowed here"));
b99bd4ef 10127 }
c19d1205
ZW
10128 inst.instruction |= inst.operands[0].reg << 12;
10129 inst.instruction |= inst.operands[1].reg << 8;
10130 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10131}
10132
c19d1205
ZW
10133static void
10134do_t_ldstt (void)
10135{
10136 inst.instruction |= inst.operands[0].reg << 12;
10137 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10138}
a737bd4d 10139
b99bd4ef 10140static void
c19d1205 10141do_t_mla (void)
b99bd4ef 10142{
fdfde340 10143 unsigned Rd, Rn, Rm, Ra;
c921be7d 10144
fdfde340
JM
10145 Rd = inst.operands[0].reg;
10146 Rn = inst.operands[1].reg;
10147 Rm = inst.operands[2].reg;
10148 Ra = inst.operands[3].reg;
10149
10150 reject_bad_reg (Rd);
10151 reject_bad_reg (Rn);
10152 reject_bad_reg (Rm);
10153 reject_bad_reg (Ra);
10154
10155 inst.instruction |= Rd << 8;
10156 inst.instruction |= Rn << 16;
10157 inst.instruction |= Rm;
10158 inst.instruction |= Ra << 12;
c19d1205 10159}
b99bd4ef 10160
c19d1205
ZW
10161static void
10162do_t_mlal (void)
10163{
fdfde340
JM
10164 unsigned RdLo, RdHi, Rn, Rm;
10165
10166 RdLo = inst.operands[0].reg;
10167 RdHi = inst.operands[1].reg;
10168 Rn = inst.operands[2].reg;
10169 Rm = inst.operands[3].reg;
10170
10171 reject_bad_reg (RdLo);
10172 reject_bad_reg (RdHi);
10173 reject_bad_reg (Rn);
10174 reject_bad_reg (Rm);
10175
10176 inst.instruction |= RdLo << 12;
10177 inst.instruction |= RdHi << 8;
10178 inst.instruction |= Rn << 16;
10179 inst.instruction |= Rm;
c19d1205 10180}
b99bd4ef 10181
c19d1205
ZW
10182static void
10183do_t_mov_cmp (void)
10184{
fdfde340
JM
10185 unsigned Rn, Rm;
10186
10187 Rn = inst.operands[0].reg;
10188 Rm = inst.operands[1].reg;
10189
e07e6e58
NC
10190 if (Rn == REG_PC)
10191 set_it_insn_type_last ();
10192
c19d1205 10193 if (unified_syntax)
b99bd4ef 10194 {
c19d1205
ZW
10195 int r0off = (inst.instruction == T_MNEM_mov
10196 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10197 unsigned long opcode;
3d388997
PB
10198 bfd_boolean narrow;
10199 bfd_boolean low_regs;
10200
fdfde340 10201 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10202 opcode = inst.instruction;
e07e6e58 10203 if (in_it_block ())
0110f2b8 10204 narrow = opcode != T_MNEM_movs;
3d388997 10205 else
0110f2b8 10206 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10207 if (inst.size_req == 4
10208 || inst.operands[1].shifted)
10209 narrow = FALSE;
10210
efd81785
PB
10211 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10212 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10213 && !inst.operands[1].shifted
fdfde340
JM
10214 && Rn == REG_PC
10215 && Rm == REG_LR)
efd81785
PB
10216 {
10217 inst.instruction = T2_SUBS_PC_LR;
10218 return;
10219 }
10220
fdfde340
JM
10221 if (opcode == T_MNEM_cmp)
10222 {
10223 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10224 if (narrow)
10225 {
10226 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10227 but valid. */
10228 warn_deprecated_sp (Rm);
10229 /* R15 was documented as a valid choice for Rm in ARMv6,
10230 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10231 tools reject R15, so we do too. */
10232 constraint (Rm == REG_PC, BAD_PC);
10233 }
10234 else
10235 reject_bad_reg (Rm);
fdfde340
JM
10236 }
10237 else if (opcode == T_MNEM_mov
10238 || opcode == T_MNEM_movs)
10239 {
10240 if (inst.operands[1].isreg)
10241 {
10242 if (opcode == T_MNEM_movs)
10243 {
10244 reject_bad_reg (Rn);
10245 reject_bad_reg (Rm);
10246 }
10247 else if ((Rn == REG_SP || Rn == REG_PC)
10248 && (Rm == REG_SP || Rm == REG_PC))
10249 reject_bad_reg (Rm);
10250 }
10251 else
10252 reject_bad_reg (Rn);
10253 }
10254
c19d1205
ZW
10255 if (!inst.operands[1].isreg)
10256 {
0110f2b8 10257 /* Immediate operand. */
e07e6e58 10258 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10259 narrow = 0;
10260 if (low_regs && narrow)
10261 {
10262 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10263 inst.instruction |= Rn << 8;
0110f2b8
PB
10264 if (inst.size_req == 2)
10265 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10266 else
10267 inst.relax = opcode;
10268 }
10269 else
10270 {
10271 inst.instruction = THUMB_OP32 (inst.instruction);
10272 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10273 inst.instruction |= Rn << r0off;
0110f2b8
PB
10274 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10275 }
c19d1205 10276 }
728ca7c9
PB
10277 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10278 && (inst.instruction == T_MNEM_mov
10279 || inst.instruction == T_MNEM_movs))
10280 {
10281 /* Register shifts are encoded as separate shift instructions. */
10282 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10283
e07e6e58 10284 if (in_it_block ())
728ca7c9
PB
10285 narrow = !flags;
10286 else
10287 narrow = flags;
10288
10289 if (inst.size_req == 4)
10290 narrow = FALSE;
10291
10292 if (!low_regs || inst.operands[1].imm > 7)
10293 narrow = FALSE;
10294
fdfde340 10295 if (Rn != Rm)
728ca7c9
PB
10296 narrow = FALSE;
10297
10298 switch (inst.operands[1].shift_kind)
10299 {
10300 case SHIFT_LSL:
10301 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10302 break;
10303 case SHIFT_ASR:
10304 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10305 break;
10306 case SHIFT_LSR:
10307 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10308 break;
10309 case SHIFT_ROR:
10310 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10311 break;
10312 default:
5f4273c7 10313 abort ();
728ca7c9
PB
10314 }
10315
10316 inst.instruction = opcode;
10317 if (narrow)
10318 {
fdfde340 10319 inst.instruction |= Rn;
728ca7c9
PB
10320 inst.instruction |= inst.operands[1].imm << 3;
10321 }
10322 else
10323 {
10324 if (flags)
10325 inst.instruction |= CONDS_BIT;
10326
fdfde340
JM
10327 inst.instruction |= Rn << 8;
10328 inst.instruction |= Rm << 16;
728ca7c9
PB
10329 inst.instruction |= inst.operands[1].imm;
10330 }
10331 }
3d388997 10332 else if (!narrow)
c19d1205 10333 {
728ca7c9
PB
10334 /* Some mov with immediate shift have narrow variants.
10335 Register shifts are handled above. */
10336 if (low_regs && inst.operands[1].shifted
10337 && (inst.instruction == T_MNEM_mov
10338 || inst.instruction == T_MNEM_movs))
10339 {
e07e6e58 10340 if (in_it_block ())
728ca7c9
PB
10341 narrow = (inst.instruction == T_MNEM_mov);
10342 else
10343 narrow = (inst.instruction == T_MNEM_movs);
10344 }
10345
10346 if (narrow)
10347 {
10348 switch (inst.operands[1].shift_kind)
10349 {
10350 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10351 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10352 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10353 default: narrow = FALSE; break;
10354 }
10355 }
10356
10357 if (narrow)
10358 {
fdfde340
JM
10359 inst.instruction |= Rn;
10360 inst.instruction |= Rm << 3;
728ca7c9
PB
10361 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10362 }
10363 else
10364 {
10365 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10366 inst.instruction |= Rn << r0off;
728ca7c9
PB
10367 encode_thumb32_shifted_operand (1);
10368 }
c19d1205
ZW
10369 }
10370 else
10371 switch (inst.instruction)
10372 {
10373 case T_MNEM_mov:
10374 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10375 inst.instruction |= (Rn & 0x8) << 4;
10376 inst.instruction |= (Rn & 0x7);
10377 inst.instruction |= Rm << 3;
c19d1205 10378 break;
b99bd4ef 10379
c19d1205
ZW
10380 case T_MNEM_movs:
10381 /* We know we have low registers at this point.
941a8a52
MGD
10382 Generate LSLS Rd, Rs, #0. */
10383 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
10384 inst.instruction |= Rn;
10385 inst.instruction |= Rm << 3;
c19d1205
ZW
10386 break;
10387
10388 case T_MNEM_cmp:
3d388997 10389 if (low_regs)
c19d1205
ZW
10390 {
10391 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10392 inst.instruction |= Rn;
10393 inst.instruction |= Rm << 3;
c19d1205
ZW
10394 }
10395 else
10396 {
10397 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10398 inst.instruction |= (Rn & 0x8) << 4;
10399 inst.instruction |= (Rn & 0x7);
10400 inst.instruction |= Rm << 3;
c19d1205
ZW
10401 }
10402 break;
10403 }
b99bd4ef
NC
10404 return;
10405 }
10406
c19d1205 10407 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10408
10409 /* PR 10443: Do not silently ignore shifted operands. */
10410 constraint (inst.operands[1].shifted,
10411 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10412
c19d1205 10413 if (inst.operands[1].isreg)
b99bd4ef 10414 {
fdfde340 10415 if (Rn < 8 && Rm < 8)
b99bd4ef 10416 {
c19d1205
ZW
10417 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10418 since a MOV instruction produces unpredictable results. */
10419 if (inst.instruction == T_OPCODE_MOV_I8)
10420 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10421 else
c19d1205 10422 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10423
fdfde340
JM
10424 inst.instruction |= Rn;
10425 inst.instruction |= Rm << 3;
b99bd4ef
NC
10426 }
10427 else
10428 {
c19d1205
ZW
10429 if (inst.instruction == T_OPCODE_MOV_I8)
10430 inst.instruction = T_OPCODE_MOV_HR;
10431 else
10432 inst.instruction = T_OPCODE_CMP_HR;
10433 do_t_cpy ();
b99bd4ef
NC
10434 }
10435 }
c19d1205 10436 else
b99bd4ef 10437 {
fdfde340 10438 constraint (Rn > 7,
c19d1205 10439 _("only lo regs allowed with immediate"));
fdfde340 10440 inst.instruction |= Rn << 8;
c19d1205
ZW
10441 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10442 }
10443}
b99bd4ef 10444
c19d1205
ZW
10445static void
10446do_t_mov16 (void)
10447{
fdfde340 10448 unsigned Rd;
b6895b4f
PB
10449 bfd_vma imm;
10450 bfd_boolean top;
10451
10452 top = (inst.instruction & 0x00800000) != 0;
10453 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10454 {
10455 constraint (top, _(":lower16: not allowed this instruction"));
10456 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10457 }
10458 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10459 {
10460 constraint (!top, _(":upper16: not allowed this instruction"));
10461 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10462 }
10463
fdfde340
JM
10464 Rd = inst.operands[0].reg;
10465 reject_bad_reg (Rd);
10466
10467 inst.instruction |= Rd << 8;
b6895b4f
PB
10468 if (inst.reloc.type == BFD_RELOC_UNUSED)
10469 {
10470 imm = inst.reloc.exp.X_add_number;
10471 inst.instruction |= (imm & 0xf000) << 4;
10472 inst.instruction |= (imm & 0x0800) << 15;
10473 inst.instruction |= (imm & 0x0700) << 4;
10474 inst.instruction |= (imm & 0x00ff);
10475 }
c19d1205 10476}
b99bd4ef 10477
c19d1205
ZW
10478static void
10479do_t_mvn_tst (void)
10480{
fdfde340 10481 unsigned Rn, Rm;
c921be7d 10482
fdfde340
JM
10483 Rn = inst.operands[0].reg;
10484 Rm = inst.operands[1].reg;
10485
10486 if (inst.instruction == T_MNEM_cmp
10487 || inst.instruction == T_MNEM_cmn)
10488 constraint (Rn == REG_PC, BAD_PC);
10489 else
10490 reject_bad_reg (Rn);
10491 reject_bad_reg (Rm);
10492
c19d1205
ZW
10493 if (unified_syntax)
10494 {
10495 int r0off = (inst.instruction == T_MNEM_mvn
10496 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10497 bfd_boolean narrow;
10498
10499 if (inst.size_req == 4
10500 || inst.instruction > 0xffff
10501 || inst.operands[1].shifted
fdfde340 10502 || Rn > 7 || Rm > 7)
3d388997
PB
10503 narrow = FALSE;
10504 else if (inst.instruction == T_MNEM_cmn)
10505 narrow = TRUE;
10506 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10507 narrow = !in_it_block ();
3d388997 10508 else
e07e6e58 10509 narrow = in_it_block ();
3d388997 10510
c19d1205 10511 if (!inst.operands[1].isreg)
b99bd4ef 10512 {
c19d1205
ZW
10513 /* For an immediate, we always generate a 32-bit opcode;
10514 section relaxation will shrink it later if possible. */
10515 if (inst.instruction < 0xffff)
10516 inst.instruction = THUMB_OP32 (inst.instruction);
10517 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10518 inst.instruction |= Rn << r0off;
c19d1205 10519 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10520 }
c19d1205 10521 else
b99bd4ef 10522 {
c19d1205 10523 /* See if we can do this with a 16-bit instruction. */
3d388997 10524 if (narrow)
b99bd4ef 10525 {
c19d1205 10526 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10527 inst.instruction |= Rn;
10528 inst.instruction |= Rm << 3;
b99bd4ef 10529 }
c19d1205 10530 else
b99bd4ef 10531 {
c19d1205
ZW
10532 constraint (inst.operands[1].shifted
10533 && inst.operands[1].immisreg,
10534 _("shift must be constant"));
10535 if (inst.instruction < 0xffff)
10536 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10537 inst.instruction |= Rn << r0off;
c19d1205 10538 encode_thumb32_shifted_operand (1);
b99bd4ef 10539 }
b99bd4ef
NC
10540 }
10541 }
10542 else
10543 {
c19d1205
ZW
10544 constraint (inst.instruction > 0xffff
10545 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10546 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10547 _("unshifted register required"));
fdfde340 10548 constraint (Rn > 7 || Rm > 7,
c19d1205 10549 BAD_HIREG);
b99bd4ef 10550
c19d1205 10551 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10552 inst.instruction |= Rn;
10553 inst.instruction |= Rm << 3;
b99bd4ef 10554 }
b99bd4ef
NC
10555}
10556
b05fe5cf 10557static void
c19d1205 10558do_t_mrs (void)
b05fe5cf 10559{
fdfde340 10560 unsigned Rd;
62b3e311 10561 int flags;
037e8744
JB
10562
10563 if (do_vfp_nsyn_mrs () == SUCCESS)
10564 return;
10565
62b3e311
PB
10566 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10567 if (flags == 0)
10568 {
7e806470 10569 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10570 _("selected processor does not support "
10571 "requested special purpose register"));
10572 }
10573 else
10574 {
10575 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10576 _("selected processor does not support "
44bf2362 10577 "requested special purpose register"));
62b3e311
PB
10578 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10579 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10580 _("'CPSR' or 'SPSR' expected"));
10581 }
5f4273c7 10582
fdfde340
JM
10583 Rd = inst.operands[0].reg;
10584 reject_bad_reg (Rd);
10585
10586 inst.instruction |= Rd << 8;
62b3e311
PB
10587 inst.instruction |= (flags & SPSR_BIT) >> 2;
10588 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10589}
b05fe5cf 10590
c19d1205
ZW
10591static void
10592do_t_msr (void)
10593{
62b3e311 10594 int flags;
fdfde340 10595 unsigned Rn;
62b3e311 10596
037e8744
JB
10597 if (do_vfp_nsyn_msr () == SUCCESS)
10598 return;
10599
c19d1205
ZW
10600 constraint (!inst.operands[1].isreg,
10601 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10602 flags = inst.operands[0].imm;
10603 if (flags & ~0xff)
10604 {
10605 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10606 _("selected processor does not support "
10607 "requested special purpose register"));
10608 }
10609 else
10610 {
7e806470 10611 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10612 _("selected processor does not support "
10613 "requested special purpose register"));
10614 flags |= PSR_f;
10615 }
c921be7d 10616
fdfde340
JM
10617 Rn = inst.operands[1].reg;
10618 reject_bad_reg (Rn);
10619
62b3e311
PB
10620 inst.instruction |= (flags & SPSR_BIT) >> 2;
10621 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10622 inst.instruction |= (flags & 0xff);
fdfde340 10623 inst.instruction |= Rn << 16;
c19d1205 10624}
b05fe5cf 10625
c19d1205
ZW
10626static void
10627do_t_mul (void)
10628{
17828f45 10629 bfd_boolean narrow;
fdfde340 10630 unsigned Rd, Rn, Rm;
17828f45 10631
c19d1205
ZW
10632 if (!inst.operands[2].present)
10633 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10634
fdfde340
JM
10635 Rd = inst.operands[0].reg;
10636 Rn = inst.operands[1].reg;
10637 Rm = inst.operands[2].reg;
10638
17828f45 10639 if (unified_syntax)
b05fe5cf 10640 {
17828f45 10641 if (inst.size_req == 4
fdfde340
JM
10642 || (Rd != Rn
10643 && Rd != Rm)
10644 || Rn > 7
10645 || Rm > 7)
17828f45
JM
10646 narrow = FALSE;
10647 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10648 narrow = !in_it_block ();
17828f45 10649 else
e07e6e58 10650 narrow = in_it_block ();
b05fe5cf 10651 }
c19d1205 10652 else
b05fe5cf 10653 {
17828f45 10654 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10655 constraint (Rn > 7 || Rm > 7,
c19d1205 10656 BAD_HIREG);
17828f45
JM
10657 narrow = TRUE;
10658 }
b05fe5cf 10659
17828f45
JM
10660 if (narrow)
10661 {
10662 /* 16-bit MULS/Conditional MUL. */
c19d1205 10663 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10664 inst.instruction |= Rd;
b05fe5cf 10665
fdfde340
JM
10666 if (Rd == Rn)
10667 inst.instruction |= Rm << 3;
10668 else if (Rd == Rm)
10669 inst.instruction |= Rn << 3;
c19d1205
ZW
10670 else
10671 constraint (1, _("dest must overlap one source register"));
10672 }
17828f45
JM
10673 else
10674 {
e07e6e58
NC
10675 constraint (inst.instruction != T_MNEM_mul,
10676 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10677 /* 32-bit MUL. */
10678 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10679 inst.instruction |= Rd << 8;
10680 inst.instruction |= Rn << 16;
10681 inst.instruction |= Rm << 0;
10682
10683 reject_bad_reg (Rd);
10684 reject_bad_reg (Rn);
10685 reject_bad_reg (Rm);
17828f45 10686 }
c19d1205 10687}
b05fe5cf 10688
c19d1205
ZW
10689static void
10690do_t_mull (void)
10691{
fdfde340 10692 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10693
fdfde340
JM
10694 RdLo = inst.operands[0].reg;
10695 RdHi = inst.operands[1].reg;
10696 Rn = inst.operands[2].reg;
10697 Rm = inst.operands[3].reg;
10698
10699 reject_bad_reg (RdLo);
10700 reject_bad_reg (RdHi);
10701 reject_bad_reg (Rn);
10702 reject_bad_reg (Rm);
10703
10704 inst.instruction |= RdLo << 12;
10705 inst.instruction |= RdHi << 8;
10706 inst.instruction |= Rn << 16;
10707 inst.instruction |= Rm;
10708
10709 if (RdLo == RdHi)
c19d1205
ZW
10710 as_tsktsk (_("rdhi and rdlo must be different"));
10711}
b05fe5cf 10712
c19d1205
ZW
10713static void
10714do_t_nop (void)
10715{
e07e6e58
NC
10716 set_it_insn_type (NEUTRAL_IT_INSN);
10717
c19d1205
ZW
10718 if (unified_syntax)
10719 {
10720 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10721 {
c19d1205
ZW
10722 inst.instruction = THUMB_OP32 (inst.instruction);
10723 inst.instruction |= inst.operands[0].imm;
10724 }
10725 else
10726 {
bc2d1808
NC
10727 /* PR9722: Check for Thumb2 availability before
10728 generating a thumb2 nop instruction. */
afa62d5e 10729 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10730 {
10731 inst.instruction = THUMB_OP16 (inst.instruction);
10732 inst.instruction |= inst.operands[0].imm << 4;
10733 }
10734 else
10735 inst.instruction = 0x46c0;
c19d1205
ZW
10736 }
10737 }
10738 else
10739 {
10740 constraint (inst.operands[0].present,
10741 _("Thumb does not support NOP with hints"));
10742 inst.instruction = 0x46c0;
10743 }
10744}
b05fe5cf 10745
c19d1205
ZW
10746static void
10747do_t_neg (void)
10748{
10749 if (unified_syntax)
10750 {
3d388997
PB
10751 bfd_boolean narrow;
10752
10753 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10754 narrow = !in_it_block ();
3d388997 10755 else
e07e6e58 10756 narrow = in_it_block ();
3d388997
PB
10757 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10758 narrow = FALSE;
10759 if (inst.size_req == 4)
10760 narrow = FALSE;
10761
10762 if (!narrow)
c19d1205
ZW
10763 {
10764 inst.instruction = THUMB_OP32 (inst.instruction);
10765 inst.instruction |= inst.operands[0].reg << 8;
10766 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10767 }
10768 else
10769 {
c19d1205
ZW
10770 inst.instruction = THUMB_OP16 (inst.instruction);
10771 inst.instruction |= inst.operands[0].reg;
10772 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10773 }
10774 }
10775 else
10776 {
c19d1205
ZW
10777 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10778 BAD_HIREG);
10779 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10780
10781 inst.instruction = THUMB_OP16 (inst.instruction);
10782 inst.instruction |= inst.operands[0].reg;
10783 inst.instruction |= inst.operands[1].reg << 3;
10784 }
10785}
10786
1c444d06
JM
10787static void
10788do_t_orn (void)
10789{
10790 unsigned Rd, Rn;
10791
10792 Rd = inst.operands[0].reg;
10793 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10794
fdfde340
JM
10795 reject_bad_reg (Rd);
10796 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10797 reject_bad_reg (Rn);
10798
1c444d06
JM
10799 inst.instruction |= Rd << 8;
10800 inst.instruction |= Rn << 16;
10801
10802 if (!inst.operands[2].isreg)
10803 {
10804 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10805 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10806 }
10807 else
10808 {
10809 unsigned Rm;
10810
10811 Rm = inst.operands[2].reg;
fdfde340 10812 reject_bad_reg (Rm);
1c444d06
JM
10813
10814 constraint (inst.operands[2].shifted
10815 && inst.operands[2].immisreg,
10816 _("shift must be constant"));
10817 encode_thumb32_shifted_operand (2);
10818 }
10819}
10820
c19d1205
ZW
10821static void
10822do_t_pkhbt (void)
10823{
fdfde340
JM
10824 unsigned Rd, Rn, Rm;
10825
10826 Rd = inst.operands[0].reg;
10827 Rn = inst.operands[1].reg;
10828 Rm = inst.operands[2].reg;
10829
10830 reject_bad_reg (Rd);
10831 reject_bad_reg (Rn);
10832 reject_bad_reg (Rm);
10833
10834 inst.instruction |= Rd << 8;
10835 inst.instruction |= Rn << 16;
10836 inst.instruction |= Rm;
c19d1205
ZW
10837 if (inst.operands[3].present)
10838 {
10839 unsigned int val = inst.reloc.exp.X_add_number;
10840 constraint (inst.reloc.exp.X_op != O_constant,
10841 _("expression too complex"));
10842 inst.instruction |= (val & 0x1c) << 10;
10843 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10844 }
c19d1205 10845}
b05fe5cf 10846
c19d1205
ZW
10847static void
10848do_t_pkhtb (void)
10849{
10850 if (!inst.operands[3].present)
1ef52f49
NC
10851 {
10852 unsigned Rtmp;
10853
10854 inst.instruction &= ~0x00000020;
10855
10856 /* PR 10168. Swap the Rm and Rn registers. */
10857 Rtmp = inst.operands[1].reg;
10858 inst.operands[1].reg = inst.operands[2].reg;
10859 inst.operands[2].reg = Rtmp;
10860 }
c19d1205 10861 do_t_pkhbt ();
b05fe5cf
ZW
10862}
10863
c19d1205
ZW
10864static void
10865do_t_pld (void)
10866{
fdfde340
JM
10867 if (inst.operands[0].immisreg)
10868 reject_bad_reg (inst.operands[0].imm);
10869
c19d1205
ZW
10870 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10871}
b05fe5cf 10872
c19d1205
ZW
10873static void
10874do_t_push_pop (void)
b99bd4ef 10875{
e9f89963 10876 unsigned mask;
5f4273c7 10877
c19d1205
ZW
10878 constraint (inst.operands[0].writeback,
10879 _("push/pop do not support {reglist}^"));
10880 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10881 _("expression too complex"));
b99bd4ef 10882
e9f89963
PB
10883 mask = inst.operands[0].imm;
10884 if ((mask & ~0xff) == 0)
3c707909 10885 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10886 else if ((inst.instruction == T_MNEM_push
e9f89963 10887 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10888 || (inst.instruction == T_MNEM_pop
e9f89963 10889 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10890 {
c19d1205
ZW
10891 inst.instruction = THUMB_OP16 (inst.instruction);
10892 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10893 inst.instruction |= mask & 0xff;
c19d1205
ZW
10894 }
10895 else if (unified_syntax)
10896 {
3c707909 10897 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10898 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10899 }
10900 else
10901 {
10902 inst.error = _("invalid register list to push/pop instruction");
10903 return;
10904 }
c19d1205 10905}
b99bd4ef 10906
c19d1205
ZW
10907static void
10908do_t_rbit (void)
10909{
fdfde340
JM
10910 unsigned Rd, Rm;
10911
10912 Rd = inst.operands[0].reg;
10913 Rm = inst.operands[1].reg;
10914
10915 reject_bad_reg (Rd);
10916 reject_bad_reg (Rm);
10917
10918 inst.instruction |= Rd << 8;
10919 inst.instruction |= Rm << 16;
10920 inst.instruction |= Rm;
c19d1205 10921}
b99bd4ef 10922
c19d1205
ZW
10923static void
10924do_t_rev (void)
10925{
fdfde340
JM
10926 unsigned Rd, Rm;
10927
10928 Rd = inst.operands[0].reg;
10929 Rm = inst.operands[1].reg;
10930
10931 reject_bad_reg (Rd);
10932 reject_bad_reg (Rm);
10933
10934 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10935 && inst.size_req != 4)
10936 {
10937 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10938 inst.instruction |= Rd;
10939 inst.instruction |= Rm << 3;
c19d1205
ZW
10940 }
10941 else if (unified_syntax)
10942 {
10943 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10944 inst.instruction |= Rd << 8;
10945 inst.instruction |= Rm << 16;
10946 inst.instruction |= Rm;
c19d1205
ZW
10947 }
10948 else
10949 inst.error = BAD_HIREG;
10950}
b99bd4ef 10951
1c444d06
JM
10952static void
10953do_t_rrx (void)
10954{
10955 unsigned Rd, Rm;
10956
10957 Rd = inst.operands[0].reg;
10958 Rm = inst.operands[1].reg;
10959
fdfde340
JM
10960 reject_bad_reg (Rd);
10961 reject_bad_reg (Rm);
c921be7d 10962
1c444d06
JM
10963 inst.instruction |= Rd << 8;
10964 inst.instruction |= Rm;
10965}
10966
c19d1205
ZW
10967static void
10968do_t_rsb (void)
10969{
fdfde340 10970 unsigned Rd, Rs;
b99bd4ef 10971
c19d1205
ZW
10972 Rd = inst.operands[0].reg;
10973 Rs = (inst.operands[1].present
10974 ? inst.operands[1].reg /* Rd, Rs, foo */
10975 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10976
fdfde340
JM
10977 reject_bad_reg (Rd);
10978 reject_bad_reg (Rs);
10979 if (inst.operands[2].isreg)
10980 reject_bad_reg (inst.operands[2].reg);
10981
c19d1205
ZW
10982 inst.instruction |= Rd << 8;
10983 inst.instruction |= Rs << 16;
10984 if (!inst.operands[2].isreg)
10985 {
026d3abb
PB
10986 bfd_boolean narrow;
10987
10988 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10989 narrow = !in_it_block ();
026d3abb 10990 else
e07e6e58 10991 narrow = in_it_block ();
026d3abb
PB
10992
10993 if (Rd > 7 || Rs > 7)
10994 narrow = FALSE;
10995
10996 if (inst.size_req == 4 || !unified_syntax)
10997 narrow = FALSE;
10998
10999 if (inst.reloc.exp.X_op != O_constant
11000 || inst.reloc.exp.X_add_number != 0)
11001 narrow = FALSE;
11002
11003 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11004 relaxation, but it doesn't seem worth the hassle. */
11005 if (narrow)
11006 {
11007 inst.reloc.type = BFD_RELOC_UNUSED;
11008 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11009 inst.instruction |= Rs << 3;
11010 inst.instruction |= Rd;
11011 }
11012 else
11013 {
11014 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11015 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11016 }
c19d1205
ZW
11017 }
11018 else
11019 encode_thumb32_shifted_operand (2);
11020}
b99bd4ef 11021
c19d1205
ZW
11022static void
11023do_t_setend (void)
11024{
e07e6e58 11025 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11026 if (inst.operands[0].imm)
11027 inst.instruction |= 0x8;
11028}
b99bd4ef 11029
c19d1205
ZW
11030static void
11031do_t_shift (void)
11032{
11033 if (!inst.operands[1].present)
11034 inst.operands[1].reg = inst.operands[0].reg;
11035
11036 if (unified_syntax)
11037 {
3d388997
PB
11038 bfd_boolean narrow;
11039 int shift_kind;
11040
11041 switch (inst.instruction)
11042 {
11043 case T_MNEM_asr:
11044 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11045 case T_MNEM_lsl:
11046 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11047 case T_MNEM_lsr:
11048 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11049 case T_MNEM_ror:
11050 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11051 default: abort ();
11052 }
11053
11054 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11055 narrow = !in_it_block ();
3d388997 11056 else
e07e6e58 11057 narrow = in_it_block ();
3d388997
PB
11058 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11059 narrow = FALSE;
11060 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11061 narrow = FALSE;
11062 if (inst.operands[2].isreg
11063 && (inst.operands[1].reg != inst.operands[0].reg
11064 || inst.operands[2].reg > 7))
11065 narrow = FALSE;
11066 if (inst.size_req == 4)
11067 narrow = FALSE;
11068
fdfde340
JM
11069 reject_bad_reg (inst.operands[0].reg);
11070 reject_bad_reg (inst.operands[1].reg);
c921be7d 11071
3d388997 11072 if (!narrow)
c19d1205
ZW
11073 {
11074 if (inst.operands[2].isreg)
b99bd4ef 11075 {
fdfde340 11076 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11077 inst.instruction = THUMB_OP32 (inst.instruction);
11078 inst.instruction |= inst.operands[0].reg << 8;
11079 inst.instruction |= inst.operands[1].reg << 16;
11080 inst.instruction |= inst.operands[2].reg;
11081 }
11082 else
11083 {
11084 inst.operands[1].shifted = 1;
3d388997 11085 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11086 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11087 ? T_MNEM_movs : T_MNEM_mov);
11088 inst.instruction |= inst.operands[0].reg << 8;
11089 encode_thumb32_shifted_operand (1);
11090 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11091 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11092 }
11093 }
11094 else
11095 {
c19d1205 11096 if (inst.operands[2].isreg)
b99bd4ef 11097 {
3d388997 11098 switch (shift_kind)
b99bd4ef 11099 {
3d388997
PB
11100 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11101 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11102 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11103 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11104 default: abort ();
b99bd4ef 11105 }
5f4273c7 11106
c19d1205
ZW
11107 inst.instruction |= inst.operands[0].reg;
11108 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11109 }
11110 else
11111 {
3d388997 11112 switch (shift_kind)
b99bd4ef 11113 {
3d388997
PB
11114 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11115 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11116 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11117 default: abort ();
b99bd4ef 11118 }
c19d1205
ZW
11119 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11120 inst.instruction |= inst.operands[0].reg;
11121 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11122 }
11123 }
c19d1205
ZW
11124 }
11125 else
11126 {
11127 constraint (inst.operands[0].reg > 7
11128 || inst.operands[1].reg > 7, BAD_HIREG);
11129 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11130
c19d1205
ZW
11131 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11132 {
11133 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11134 constraint (inst.operands[0].reg != inst.operands[1].reg,
11135 _("source1 and dest must be same register"));
b99bd4ef 11136
c19d1205
ZW
11137 switch (inst.instruction)
11138 {
11139 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11140 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11141 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11142 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11143 default: abort ();
11144 }
5f4273c7 11145
c19d1205
ZW
11146 inst.instruction |= inst.operands[0].reg;
11147 inst.instruction |= inst.operands[2].reg << 3;
11148 }
11149 else
b99bd4ef 11150 {
c19d1205
ZW
11151 switch (inst.instruction)
11152 {
11153 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11154 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11155 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11156 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11157 default: abort ();
11158 }
11159 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11160 inst.instruction |= inst.operands[0].reg;
11161 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11162 }
11163 }
b99bd4ef
NC
11164}
11165
11166static void
c19d1205 11167do_t_simd (void)
b99bd4ef 11168{
fdfde340
JM
11169 unsigned Rd, Rn, Rm;
11170
11171 Rd = inst.operands[0].reg;
11172 Rn = inst.operands[1].reg;
11173 Rm = inst.operands[2].reg;
11174
11175 reject_bad_reg (Rd);
11176 reject_bad_reg (Rn);
11177 reject_bad_reg (Rm);
11178
11179 inst.instruction |= Rd << 8;
11180 inst.instruction |= Rn << 16;
11181 inst.instruction |= Rm;
c19d1205 11182}
b99bd4ef 11183
03ee1b7f
NC
11184static void
11185do_t_simd2 (void)
11186{
11187 unsigned Rd, Rn, Rm;
11188
11189 Rd = inst.operands[0].reg;
11190 Rm = inst.operands[1].reg;
11191 Rn = inst.operands[2].reg;
11192
11193 reject_bad_reg (Rd);
11194 reject_bad_reg (Rn);
11195 reject_bad_reg (Rm);
11196
11197 inst.instruction |= Rd << 8;
11198 inst.instruction |= Rn << 16;
11199 inst.instruction |= Rm;
11200}
11201
c19d1205 11202static void
3eb17e6b 11203do_t_smc (void)
c19d1205
ZW
11204{
11205 unsigned int value = inst.reloc.exp.X_add_number;
11206 constraint (inst.reloc.exp.X_op != O_constant,
11207 _("expression too complex"));
11208 inst.reloc.type = BFD_RELOC_UNUSED;
11209 inst.instruction |= (value & 0xf000) >> 12;
11210 inst.instruction |= (value & 0x0ff0);
11211 inst.instruction |= (value & 0x000f) << 16;
11212}
b99bd4ef 11213
c19d1205 11214static void
3a21c15a 11215do_t_ssat_usat (int bias)
c19d1205 11216{
fdfde340
JM
11217 unsigned Rd, Rn;
11218
11219 Rd = inst.operands[0].reg;
11220 Rn = inst.operands[2].reg;
11221
11222 reject_bad_reg (Rd);
11223 reject_bad_reg (Rn);
11224
11225 inst.instruction |= Rd << 8;
3a21c15a 11226 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11227 inst.instruction |= Rn << 16;
b99bd4ef 11228
c19d1205 11229 if (inst.operands[3].present)
b99bd4ef 11230 {
3a21c15a
NC
11231 offsetT shift_amount = inst.reloc.exp.X_add_number;
11232
11233 inst.reloc.type = BFD_RELOC_UNUSED;
11234
c19d1205
ZW
11235 constraint (inst.reloc.exp.X_op != O_constant,
11236 _("expression too complex"));
b99bd4ef 11237
3a21c15a 11238 if (shift_amount != 0)
6189168b 11239 {
3a21c15a
NC
11240 constraint (shift_amount > 31,
11241 _("shift expression is too large"));
11242
c19d1205 11243 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11244 inst.instruction |= 0x00200000; /* sh bit. */
11245
11246 inst.instruction |= (shift_amount & 0x1c) << 10;
11247 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11248 }
11249 }
b99bd4ef 11250}
c921be7d 11251
3a21c15a
NC
11252static void
11253do_t_ssat (void)
11254{
11255 do_t_ssat_usat (1);
11256}
b99bd4ef 11257
0dd132b6 11258static void
c19d1205 11259do_t_ssat16 (void)
0dd132b6 11260{
fdfde340
JM
11261 unsigned Rd, Rn;
11262
11263 Rd = inst.operands[0].reg;
11264 Rn = inst.operands[2].reg;
11265
11266 reject_bad_reg (Rd);
11267 reject_bad_reg (Rn);
11268
11269 inst.instruction |= Rd << 8;
c19d1205 11270 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11271 inst.instruction |= Rn << 16;
c19d1205 11272}
0dd132b6 11273
c19d1205
ZW
11274static void
11275do_t_strex (void)
11276{
11277 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11278 || inst.operands[2].postind || inst.operands[2].writeback
11279 || inst.operands[2].immisreg || inst.operands[2].shifted
11280 || inst.operands[2].negative,
01cfc07f 11281 BAD_ADDR_MODE);
0dd132b6 11282
5be8be5d
DG
11283 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11284
c19d1205
ZW
11285 inst.instruction |= inst.operands[0].reg << 8;
11286 inst.instruction |= inst.operands[1].reg << 12;
11287 inst.instruction |= inst.operands[2].reg << 16;
11288 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11289}
11290
b99bd4ef 11291static void
c19d1205 11292do_t_strexd (void)
b99bd4ef 11293{
c19d1205
ZW
11294 if (!inst.operands[2].present)
11295 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11296
c19d1205
ZW
11297 constraint (inst.operands[0].reg == inst.operands[1].reg
11298 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11299 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11300 BAD_OVERLAP);
b99bd4ef 11301
c19d1205
ZW
11302 inst.instruction |= inst.operands[0].reg;
11303 inst.instruction |= inst.operands[1].reg << 12;
11304 inst.instruction |= inst.operands[2].reg << 8;
11305 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11306}
11307
11308static void
c19d1205 11309do_t_sxtah (void)
b99bd4ef 11310{
fdfde340
JM
11311 unsigned Rd, Rn, Rm;
11312
11313 Rd = inst.operands[0].reg;
11314 Rn = inst.operands[1].reg;
11315 Rm = inst.operands[2].reg;
11316
11317 reject_bad_reg (Rd);
11318 reject_bad_reg (Rn);
11319 reject_bad_reg (Rm);
11320
11321 inst.instruction |= Rd << 8;
11322 inst.instruction |= Rn << 16;
11323 inst.instruction |= Rm;
c19d1205
ZW
11324 inst.instruction |= inst.operands[3].imm << 4;
11325}
b99bd4ef 11326
c19d1205
ZW
11327static void
11328do_t_sxth (void)
11329{
fdfde340
JM
11330 unsigned Rd, Rm;
11331
11332 Rd = inst.operands[0].reg;
11333 Rm = inst.operands[1].reg;
11334
11335 reject_bad_reg (Rd);
11336 reject_bad_reg (Rm);
c921be7d
NC
11337
11338 if (inst.instruction <= 0xffff
11339 && inst.size_req != 4
fdfde340 11340 && Rd <= 7 && Rm <= 7
c19d1205 11341 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11342 {
c19d1205 11343 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11344 inst.instruction |= Rd;
11345 inst.instruction |= Rm << 3;
b99bd4ef 11346 }
c19d1205 11347 else if (unified_syntax)
b99bd4ef 11348 {
c19d1205
ZW
11349 if (inst.instruction <= 0xffff)
11350 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11351 inst.instruction |= Rd << 8;
11352 inst.instruction |= Rm;
c19d1205 11353 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11354 }
c19d1205 11355 else
b99bd4ef 11356 {
c19d1205
ZW
11357 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11358 _("Thumb encoding does not support rotation"));
11359 constraint (1, BAD_HIREG);
b99bd4ef 11360 }
c19d1205 11361}
b99bd4ef 11362
c19d1205
ZW
11363static void
11364do_t_swi (void)
11365{
11366 inst.reloc.type = BFD_RELOC_ARM_SWI;
11367}
b99bd4ef 11368
92e90b6e
PB
11369static void
11370do_t_tb (void)
11371{
fdfde340 11372 unsigned Rn, Rm;
92e90b6e
PB
11373 int half;
11374
11375 half = (inst.instruction & 0x10) != 0;
e07e6e58 11376 set_it_insn_type_last ();
dfa9f0d5
PB
11377 constraint (inst.operands[0].immisreg,
11378 _("instruction requires register index"));
fdfde340
JM
11379
11380 Rn = inst.operands[0].reg;
11381 Rm = inst.operands[0].imm;
c921be7d 11382
fdfde340
JM
11383 constraint (Rn == REG_SP, BAD_SP);
11384 reject_bad_reg (Rm);
11385
92e90b6e
PB
11386 constraint (!half && inst.operands[0].shifted,
11387 _("instruction does not allow shifted index"));
fdfde340 11388 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11389}
11390
c19d1205
ZW
11391static void
11392do_t_usat (void)
11393{
3a21c15a 11394 do_t_ssat_usat (0);
b99bd4ef
NC
11395}
11396
11397static void
c19d1205 11398do_t_usat16 (void)
b99bd4ef 11399{
fdfde340
JM
11400 unsigned Rd, Rn;
11401
11402 Rd = inst.operands[0].reg;
11403 Rn = inst.operands[2].reg;
11404
11405 reject_bad_reg (Rd);
11406 reject_bad_reg (Rn);
11407
11408 inst.instruction |= Rd << 8;
c19d1205 11409 inst.instruction |= inst.operands[1].imm;
fdfde340 11410 inst.instruction |= Rn << 16;
b99bd4ef 11411}
c19d1205 11412
5287ad62 11413/* Neon instruction encoder helpers. */
5f4273c7 11414
5287ad62 11415/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11416
5287ad62
JB
11417/* An "invalid" code for the following tables. */
11418#define N_INV -1u
11419
11420struct neon_tab_entry
b99bd4ef 11421{
5287ad62
JB
11422 unsigned integer;
11423 unsigned float_or_poly;
11424 unsigned scalar_or_imm;
11425};
5f4273c7 11426
5287ad62
JB
11427/* Map overloaded Neon opcodes to their respective encodings. */
11428#define NEON_ENC_TAB \
11429 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11430 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11431 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11432 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11433 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11434 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11435 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11436 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11437 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11438 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11439 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11440 /* Register variants of the following two instructions are encoded as
e07e6e58 11441 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11442 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11443 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11444 X(vfma, N_INV, 0x0000c10, N_INV), \
11445 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11446 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11447 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11448 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11449 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11450 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11451 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11452 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11453 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11454 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11455 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11456 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11457 X(vshl, 0x0000400, N_INV, 0x0800510), \
11458 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11459 X(vand, 0x0000110, N_INV, 0x0800030), \
11460 X(vbic, 0x0100110, N_INV, 0x0800030), \
11461 X(veor, 0x1000110, N_INV, N_INV), \
11462 X(vorn, 0x0300110, N_INV, 0x0800010), \
11463 X(vorr, 0x0200110, N_INV, 0x0800010), \
11464 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11465 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11466 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11467 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11468 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11469 X(vst1, 0x0000000, 0x0800000, N_INV), \
11470 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11471 X(vst2, 0x0000100, 0x0800100, N_INV), \
11472 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11473 X(vst3, 0x0000200, 0x0800200, N_INV), \
11474 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11475 X(vst4, 0x0000300, 0x0800300, N_INV), \
11476 X(vmovn, 0x1b20200, N_INV, N_INV), \
11477 X(vtrn, 0x1b20080, N_INV, N_INV), \
11478 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11479 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11480 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11481 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11482 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11483 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11484 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11485 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11486 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11487 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11488 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11489
11490enum neon_opc
11491{
11492#define X(OPC,I,F,S) N_MNEM_##OPC
11493NEON_ENC_TAB
11494#undef X
11495};
b99bd4ef 11496
5287ad62
JB
11497static const struct neon_tab_entry neon_enc_tab[] =
11498{
11499#define X(OPC,I,F,S) { (I), (F), (S) }
11500NEON_ENC_TAB
11501#undef X
11502};
b99bd4ef 11503
88714cb8
DG
11504/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11505#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11506#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11507#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11508#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11509#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11510#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11511#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11512#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11513#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11514#define NEON_ENC_SINGLE_(X) \
037e8744 11515 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11516#define NEON_ENC_DOUBLE_(X) \
037e8744 11517 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11518
88714cb8
DG
11519#define NEON_ENCODE(type, inst) \
11520 do \
11521 { \
11522 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11523 inst.is_neon = 1; \
11524 } \
11525 while (0)
11526
11527#define check_neon_suffixes \
11528 do \
11529 { \
11530 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11531 { \
11532 as_bad (_("invalid neon suffix for non neon instruction")); \
11533 return; \
11534 } \
11535 } \
11536 while (0)
11537
037e8744
JB
11538/* Define shapes for instruction operands. The following mnemonic characters
11539 are used in this table:
5287ad62 11540
037e8744 11541 F - VFP S<n> register
5287ad62
JB
11542 D - Neon D<n> register
11543 Q - Neon Q<n> register
11544 I - Immediate
11545 S - Scalar
11546 R - ARM register
11547 L - D<n> register list
5f4273c7 11548
037e8744
JB
11549 This table is used to generate various data:
11550 - enumerations of the form NS_DDR to be used as arguments to
11551 neon_select_shape.
11552 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11553 - a table used to drive neon_select_shape. */
b99bd4ef 11554
037e8744
JB
11555#define NEON_SHAPE_DEF \
11556 X(3, (D, D, D), DOUBLE), \
11557 X(3, (Q, Q, Q), QUAD), \
11558 X(3, (D, D, I), DOUBLE), \
11559 X(3, (Q, Q, I), QUAD), \
11560 X(3, (D, D, S), DOUBLE), \
11561 X(3, (Q, Q, S), QUAD), \
11562 X(2, (D, D), DOUBLE), \
11563 X(2, (Q, Q), QUAD), \
11564 X(2, (D, S), DOUBLE), \
11565 X(2, (Q, S), QUAD), \
11566 X(2, (D, R), DOUBLE), \
11567 X(2, (Q, R), QUAD), \
11568 X(2, (D, I), DOUBLE), \
11569 X(2, (Q, I), QUAD), \
11570 X(3, (D, L, D), DOUBLE), \
11571 X(2, (D, Q), MIXED), \
11572 X(2, (Q, D), MIXED), \
11573 X(3, (D, Q, I), MIXED), \
11574 X(3, (Q, D, I), MIXED), \
11575 X(3, (Q, D, D), MIXED), \
11576 X(3, (D, Q, Q), MIXED), \
11577 X(3, (Q, Q, D), MIXED), \
11578 X(3, (Q, D, S), MIXED), \
11579 X(3, (D, Q, S), MIXED), \
11580 X(4, (D, D, D, I), DOUBLE), \
11581 X(4, (Q, Q, Q, I), QUAD), \
11582 X(2, (F, F), SINGLE), \
11583 X(3, (F, F, F), SINGLE), \
11584 X(2, (F, I), SINGLE), \
11585 X(2, (F, D), MIXED), \
11586 X(2, (D, F), MIXED), \
11587 X(3, (F, F, I), MIXED), \
11588 X(4, (R, R, F, F), SINGLE), \
11589 X(4, (F, F, R, R), SINGLE), \
11590 X(3, (D, R, R), DOUBLE), \
11591 X(3, (R, R, D), DOUBLE), \
11592 X(2, (S, R), SINGLE), \
11593 X(2, (R, S), SINGLE), \
11594 X(2, (F, R), SINGLE), \
11595 X(2, (R, F), SINGLE)
11596
11597#define S2(A,B) NS_##A##B
11598#define S3(A,B,C) NS_##A##B##C
11599#define S4(A,B,C,D) NS_##A##B##C##D
11600
11601#define X(N, L, C) S##N L
11602
5287ad62
JB
11603enum neon_shape
11604{
037e8744
JB
11605 NEON_SHAPE_DEF,
11606 NS_NULL
5287ad62 11607};
b99bd4ef 11608
037e8744
JB
11609#undef X
11610#undef S2
11611#undef S3
11612#undef S4
11613
11614enum neon_shape_class
11615{
11616 SC_SINGLE,
11617 SC_DOUBLE,
11618 SC_QUAD,
11619 SC_MIXED
11620};
11621
11622#define X(N, L, C) SC_##C
11623
11624static enum neon_shape_class neon_shape_class[] =
11625{
11626 NEON_SHAPE_DEF
11627};
11628
11629#undef X
11630
11631enum neon_shape_el
11632{
11633 SE_F,
11634 SE_D,
11635 SE_Q,
11636 SE_I,
11637 SE_S,
11638 SE_R,
11639 SE_L
11640};
11641
11642/* Register widths of above. */
11643static unsigned neon_shape_el_size[] =
11644{
11645 32,
11646 64,
11647 128,
11648 0,
11649 32,
11650 32,
11651 0
11652};
11653
11654struct neon_shape_info
11655{
11656 unsigned els;
11657 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11658};
11659
11660#define S2(A,B) { SE_##A, SE_##B }
11661#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11662#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11663
11664#define X(N, L, C) { N, S##N L }
11665
11666static struct neon_shape_info neon_shape_tab[] =
11667{
11668 NEON_SHAPE_DEF
11669};
11670
11671#undef X
11672#undef S2
11673#undef S3
11674#undef S4
11675
5287ad62
JB
11676/* Bit masks used in type checking given instructions.
11677 'N_EQK' means the type must be the same as (or based on in some way) the key
11678 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11679 set, various other bits can be set as well in order to modify the meaning of
11680 the type constraint. */
11681
11682enum neon_type_mask
11683{
8e79c3df
CM
11684 N_S8 = 0x0000001,
11685 N_S16 = 0x0000002,
11686 N_S32 = 0x0000004,
11687 N_S64 = 0x0000008,
11688 N_U8 = 0x0000010,
11689 N_U16 = 0x0000020,
11690 N_U32 = 0x0000040,
11691 N_U64 = 0x0000080,
11692 N_I8 = 0x0000100,
11693 N_I16 = 0x0000200,
11694 N_I32 = 0x0000400,
11695 N_I64 = 0x0000800,
11696 N_8 = 0x0001000,
11697 N_16 = 0x0002000,
11698 N_32 = 0x0004000,
11699 N_64 = 0x0008000,
11700 N_P8 = 0x0010000,
11701 N_P16 = 0x0020000,
11702 N_F16 = 0x0040000,
11703 N_F32 = 0x0080000,
11704 N_F64 = 0x0100000,
c921be7d
NC
11705 N_KEY = 0x1000000, /* Key element (main type specifier). */
11706 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11707 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11708 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11709 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11710 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11711 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11712 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11713 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11714 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11715 N_UTYP = 0,
037e8744 11716 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11717};
11718
dcbf9037
JB
11719#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11720
5287ad62
JB
11721#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11722#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11723#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11724#define N_SUF_32 (N_SU_32 | N_F32)
11725#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11726#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11727
11728/* Pass this as the first type argument to neon_check_type to ignore types
11729 altogether. */
11730#define N_IGNORE_TYPE (N_KEY | N_EQK)
11731
037e8744
JB
11732/* Select a "shape" for the current instruction (describing register types or
11733 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11734 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11735 function of operand parsing, so this function doesn't need to be called.
11736 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11737
11738static enum neon_shape
037e8744 11739neon_select_shape (enum neon_shape shape, ...)
5287ad62 11740{
037e8744
JB
11741 va_list ap;
11742 enum neon_shape first_shape = shape;
5287ad62
JB
11743
11744 /* Fix missing optional operands. FIXME: we don't know at this point how
11745 many arguments we should have, so this makes the assumption that we have
11746 > 1. This is true of all current Neon opcodes, I think, but may not be
11747 true in the future. */
11748 if (!inst.operands[1].present)
11749 inst.operands[1] = inst.operands[0];
11750
037e8744 11751 va_start (ap, shape);
5f4273c7 11752
21d799b5 11753 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11754 {
11755 unsigned j;
11756 int matches = 1;
11757
11758 for (j = 0; j < neon_shape_tab[shape].els; j++)
11759 {
11760 if (!inst.operands[j].present)
11761 {
11762 matches = 0;
11763 break;
11764 }
11765
11766 switch (neon_shape_tab[shape].el[j])
11767 {
11768 case SE_F:
11769 if (!(inst.operands[j].isreg
11770 && inst.operands[j].isvec
11771 && inst.operands[j].issingle
11772 && !inst.operands[j].isquad))
11773 matches = 0;
11774 break;
11775
11776 case SE_D:
11777 if (!(inst.operands[j].isreg
11778 && inst.operands[j].isvec
11779 && !inst.operands[j].isquad
11780 && !inst.operands[j].issingle))
11781 matches = 0;
11782 break;
11783
11784 case SE_R:
11785 if (!(inst.operands[j].isreg
11786 && !inst.operands[j].isvec))
11787 matches = 0;
11788 break;
11789
11790 case SE_Q:
11791 if (!(inst.operands[j].isreg
11792 && inst.operands[j].isvec
11793 && inst.operands[j].isquad
11794 && !inst.operands[j].issingle))
11795 matches = 0;
11796 break;
11797
11798 case SE_I:
11799 if (!(!inst.operands[j].isreg
11800 && !inst.operands[j].isscalar))
11801 matches = 0;
11802 break;
11803
11804 case SE_S:
11805 if (!(!inst.operands[j].isreg
11806 && inst.operands[j].isscalar))
11807 matches = 0;
11808 break;
11809
11810 case SE_L:
11811 break;
11812 }
3fde54a2
JZ
11813 if (!matches)
11814 break;
037e8744
JB
11815 }
11816 if (matches)
5287ad62 11817 break;
037e8744 11818 }
5f4273c7 11819
037e8744 11820 va_end (ap);
5287ad62 11821
037e8744
JB
11822 if (shape == NS_NULL && first_shape != NS_NULL)
11823 first_error (_("invalid instruction shape"));
5287ad62 11824
037e8744
JB
11825 return shape;
11826}
5287ad62 11827
037e8744
JB
11828/* True if SHAPE is predominantly a quadword operation (most of the time, this
11829 means the Q bit should be set). */
11830
11831static int
11832neon_quad (enum neon_shape shape)
11833{
11834 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11835}
037e8744 11836
5287ad62
JB
11837static void
11838neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11839 unsigned *g_size)
11840{
11841 /* Allow modification to be made to types which are constrained to be
11842 based on the key element, based on bits set alongside N_EQK. */
11843 if ((typebits & N_EQK) != 0)
11844 {
11845 if ((typebits & N_HLF) != 0)
11846 *g_size /= 2;
11847 else if ((typebits & N_DBL) != 0)
11848 *g_size *= 2;
11849 if ((typebits & N_SGN) != 0)
11850 *g_type = NT_signed;
11851 else if ((typebits & N_UNS) != 0)
11852 *g_type = NT_unsigned;
11853 else if ((typebits & N_INT) != 0)
11854 *g_type = NT_integer;
11855 else if ((typebits & N_FLT) != 0)
11856 *g_type = NT_float;
dcbf9037
JB
11857 else if ((typebits & N_SIZ) != 0)
11858 *g_type = NT_untyped;
5287ad62
JB
11859 }
11860}
5f4273c7 11861
5287ad62
JB
11862/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11863 operand type, i.e. the single type specified in a Neon instruction when it
11864 is the only one given. */
11865
11866static struct neon_type_el
11867neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11868{
11869 struct neon_type_el dest = *key;
5f4273c7 11870
9c2799c2 11871 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11872
5287ad62
JB
11873 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11874
11875 return dest;
11876}
11877
11878/* Convert Neon type and size into compact bitmask representation. */
11879
11880static enum neon_type_mask
11881type_chk_of_el_type (enum neon_el_type type, unsigned size)
11882{
11883 switch (type)
11884 {
11885 case NT_untyped:
11886 switch (size)
11887 {
11888 case 8: return N_8;
11889 case 16: return N_16;
11890 case 32: return N_32;
11891 case 64: return N_64;
11892 default: ;
11893 }
11894 break;
11895
11896 case NT_integer:
11897 switch (size)
11898 {
11899 case 8: return N_I8;
11900 case 16: return N_I16;
11901 case 32: return N_I32;
11902 case 64: return N_I64;
11903 default: ;
11904 }
11905 break;
11906
11907 case NT_float:
037e8744
JB
11908 switch (size)
11909 {
8e79c3df 11910 case 16: return N_F16;
037e8744
JB
11911 case 32: return N_F32;
11912 case 64: return N_F64;
11913 default: ;
11914 }
5287ad62
JB
11915 break;
11916
11917 case NT_poly:
11918 switch (size)
11919 {
11920 case 8: return N_P8;
11921 case 16: return N_P16;
11922 default: ;
11923 }
11924 break;
11925
11926 case NT_signed:
11927 switch (size)
11928 {
11929 case 8: return N_S8;
11930 case 16: return N_S16;
11931 case 32: return N_S32;
11932 case 64: return N_S64;
11933 default: ;
11934 }
11935 break;
11936
11937 case NT_unsigned:
11938 switch (size)
11939 {
11940 case 8: return N_U8;
11941 case 16: return N_U16;
11942 case 32: return N_U32;
11943 case 64: return N_U64;
11944 default: ;
11945 }
11946 break;
11947
11948 default: ;
11949 }
5f4273c7 11950
5287ad62
JB
11951 return N_UTYP;
11952}
11953
11954/* Convert compact Neon bitmask type representation to a type and size. Only
11955 handles the case where a single bit is set in the mask. */
11956
dcbf9037 11957static int
5287ad62
JB
11958el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11959 enum neon_type_mask mask)
11960{
dcbf9037
JB
11961 if ((mask & N_EQK) != 0)
11962 return FAIL;
11963
5287ad62
JB
11964 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11965 *size = 8;
dcbf9037 11966 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11967 *size = 16;
dcbf9037 11968 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11969 *size = 32;
037e8744 11970 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11971 *size = 64;
dcbf9037
JB
11972 else
11973 return FAIL;
11974
5287ad62
JB
11975 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11976 *type = NT_signed;
dcbf9037 11977 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11978 *type = NT_unsigned;
dcbf9037 11979 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11980 *type = NT_integer;
dcbf9037 11981 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11982 *type = NT_untyped;
dcbf9037 11983 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11984 *type = NT_poly;
037e8744 11985 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11986 *type = NT_float;
dcbf9037
JB
11987 else
11988 return FAIL;
5f4273c7 11989
dcbf9037 11990 return SUCCESS;
5287ad62
JB
11991}
11992
11993/* Modify a bitmask of allowed types. This is only needed for type
11994 relaxation. */
11995
11996static unsigned
11997modify_types_allowed (unsigned allowed, unsigned mods)
11998{
11999 unsigned size;
12000 enum neon_el_type type;
12001 unsigned destmask;
12002 int i;
5f4273c7 12003
5287ad62 12004 destmask = 0;
5f4273c7 12005
5287ad62
JB
12006 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12007 {
21d799b5
NC
12008 if (el_type_of_type_chk (&type, &size,
12009 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
12010 {
12011 neon_modify_type_size (mods, &type, &size);
12012 destmask |= type_chk_of_el_type (type, size);
12013 }
5287ad62 12014 }
5f4273c7 12015
5287ad62
JB
12016 return destmask;
12017}
12018
12019/* Check type and return type classification.
12020 The manual states (paraphrase): If one datatype is given, it indicates the
12021 type given in:
12022 - the second operand, if there is one
12023 - the operand, if there is no second operand
12024 - the result, if there are no operands.
12025 This isn't quite good enough though, so we use a concept of a "key" datatype
12026 which is set on a per-instruction basis, which is the one which matters when
12027 only one data type is written.
12028 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12029 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12030
12031static struct neon_type_el
12032neon_check_type (unsigned els, enum neon_shape ns, ...)
12033{
12034 va_list ap;
12035 unsigned i, pass, key_el = 0;
12036 unsigned types[NEON_MAX_TYPE_ELS];
12037 enum neon_el_type k_type = NT_invtype;
12038 unsigned k_size = -1u;
12039 struct neon_type_el badtype = {NT_invtype, -1};
12040 unsigned key_allowed = 0;
12041
12042 /* Optional registers in Neon instructions are always (not) in operand 1.
12043 Fill in the missing operand here, if it was omitted. */
12044 if (els > 1 && !inst.operands[1].present)
12045 inst.operands[1] = inst.operands[0];
12046
12047 /* Suck up all the varargs. */
12048 va_start (ap, ns);
12049 for (i = 0; i < els; i++)
12050 {
12051 unsigned thisarg = va_arg (ap, unsigned);
12052 if (thisarg == N_IGNORE_TYPE)
12053 {
12054 va_end (ap);
12055 return badtype;
12056 }
12057 types[i] = thisarg;
12058 if ((thisarg & N_KEY) != 0)
12059 key_el = i;
12060 }
12061 va_end (ap);
12062
dcbf9037
JB
12063 if (inst.vectype.elems > 0)
12064 for (i = 0; i < els; i++)
12065 if (inst.operands[i].vectype.type != NT_invtype)
12066 {
12067 first_error (_("types specified in both the mnemonic and operands"));
12068 return badtype;
12069 }
12070
5287ad62
JB
12071 /* Duplicate inst.vectype elements here as necessary.
12072 FIXME: No idea if this is exactly the same as the ARM assembler,
12073 particularly when an insn takes one register and one non-register
12074 operand. */
12075 if (inst.vectype.elems == 1 && els > 1)
12076 {
12077 unsigned j;
12078 inst.vectype.elems = els;
12079 inst.vectype.el[key_el] = inst.vectype.el[0];
12080 for (j = 0; j < els; j++)
dcbf9037
JB
12081 if (j != key_el)
12082 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12083 types[j]);
12084 }
12085 else if (inst.vectype.elems == 0 && els > 0)
12086 {
12087 unsigned j;
12088 /* No types were given after the mnemonic, so look for types specified
12089 after each operand. We allow some flexibility here; as long as the
12090 "key" operand has a type, we can infer the others. */
12091 for (j = 0; j < els; j++)
12092 if (inst.operands[j].vectype.type != NT_invtype)
12093 inst.vectype.el[j] = inst.operands[j].vectype;
12094
12095 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12096 {
dcbf9037
JB
12097 for (j = 0; j < els; j++)
12098 if (inst.operands[j].vectype.type == NT_invtype)
12099 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12100 types[j]);
12101 }
12102 else
12103 {
12104 first_error (_("operand types can't be inferred"));
12105 return badtype;
5287ad62
JB
12106 }
12107 }
12108 else if (inst.vectype.elems != els)
12109 {
dcbf9037 12110 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12111 return badtype;
12112 }
12113
12114 for (pass = 0; pass < 2; pass++)
12115 {
12116 for (i = 0; i < els; i++)
12117 {
12118 unsigned thisarg = types[i];
12119 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12120 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12121 enum neon_el_type g_type = inst.vectype.el[i].type;
12122 unsigned g_size = inst.vectype.el[i].size;
12123
12124 /* Decay more-specific signed & unsigned types to sign-insensitive
12125 integer types if sign-specific variants are unavailable. */
12126 if ((g_type == NT_signed || g_type == NT_unsigned)
12127 && (types_allowed & N_SU_ALL) == 0)
12128 g_type = NT_integer;
12129
12130 /* If only untyped args are allowed, decay any more specific types to
12131 them. Some instructions only care about signs for some element
12132 sizes, so handle that properly. */
12133 if ((g_size == 8 && (types_allowed & N_8) != 0)
12134 || (g_size == 16 && (types_allowed & N_16) != 0)
12135 || (g_size == 32 && (types_allowed & N_32) != 0)
12136 || (g_size == 64 && (types_allowed & N_64) != 0))
12137 g_type = NT_untyped;
12138
12139 if (pass == 0)
12140 {
12141 if ((thisarg & N_KEY) != 0)
12142 {
12143 k_type = g_type;
12144 k_size = g_size;
12145 key_allowed = thisarg & ~N_KEY;
12146 }
12147 }
12148 else
12149 {
037e8744
JB
12150 if ((thisarg & N_VFP) != 0)
12151 {
99b253c5
NC
12152 enum neon_shape_el regshape;
12153 unsigned regwidth, match;
12154
12155 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12156 if (ns == NS_NULL)
12157 {
12158 first_error (_("invalid instruction shape"));
12159 return badtype;
12160 }
12161 regshape = neon_shape_tab[ns].el[i];
12162 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12163
12164 /* In VFP mode, operands must match register widths. If we
12165 have a key operand, use its width, else use the width of
12166 the current operand. */
12167 if (k_size != -1u)
12168 match = k_size;
12169 else
12170 match = g_size;
12171
12172 if (regwidth != match)
12173 {
12174 first_error (_("operand size must match register width"));
12175 return badtype;
12176 }
12177 }
5f4273c7 12178
5287ad62
JB
12179 if ((thisarg & N_EQK) == 0)
12180 {
12181 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12182
12183 if ((given_type & types_allowed) == 0)
12184 {
dcbf9037 12185 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12186 return badtype;
12187 }
12188 }
12189 else
12190 {
12191 enum neon_el_type mod_k_type = k_type;
12192 unsigned mod_k_size = k_size;
12193 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12194 if (g_type != mod_k_type || g_size != mod_k_size)
12195 {
dcbf9037 12196 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12197 return badtype;
12198 }
12199 }
12200 }
12201 }
12202 }
12203
12204 return inst.vectype.el[key_el];
12205}
12206
037e8744 12207/* Neon-style VFP instruction forwarding. */
5287ad62 12208
037e8744
JB
12209/* Thumb VFP instructions have 0xE in the condition field. */
12210
12211static void
12212do_vfp_cond_or_thumb (void)
5287ad62 12213{
88714cb8
DG
12214 inst.is_neon = 1;
12215
5287ad62 12216 if (thumb_mode)
037e8744 12217 inst.instruction |= 0xe0000000;
5287ad62 12218 else
037e8744 12219 inst.instruction |= inst.cond << 28;
5287ad62
JB
12220}
12221
037e8744
JB
12222/* Look up and encode a simple mnemonic, for use as a helper function for the
12223 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12224 etc. It is assumed that operand parsing has already been done, and that the
12225 operands are in the form expected by the given opcode (this isn't necessarily
12226 the same as the form in which they were parsed, hence some massaging must
12227 take place before this function is called).
12228 Checks current arch version against that in the looked-up opcode. */
5287ad62 12229
037e8744
JB
12230static void
12231do_vfp_nsyn_opcode (const char *opname)
5287ad62 12232{
037e8744 12233 const struct asm_opcode *opcode;
5f4273c7 12234
21d799b5 12235 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12236
037e8744
JB
12237 if (!opcode)
12238 abort ();
5287ad62 12239
037e8744
JB
12240 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12241 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12242 _(BAD_FPU));
5287ad62 12243
88714cb8
DG
12244 inst.is_neon = 1;
12245
037e8744
JB
12246 if (thumb_mode)
12247 {
12248 inst.instruction = opcode->tvalue;
12249 opcode->tencode ();
12250 }
12251 else
12252 {
12253 inst.instruction = (inst.cond << 28) | opcode->avalue;
12254 opcode->aencode ();
12255 }
12256}
5287ad62
JB
12257
12258static void
037e8744 12259do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12260{
037e8744
JB
12261 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12262
12263 if (rs == NS_FFF)
12264 {
12265 if (is_add)
12266 do_vfp_nsyn_opcode ("fadds");
12267 else
12268 do_vfp_nsyn_opcode ("fsubs");
12269 }
12270 else
12271 {
12272 if (is_add)
12273 do_vfp_nsyn_opcode ("faddd");
12274 else
12275 do_vfp_nsyn_opcode ("fsubd");
12276 }
12277}
12278
12279/* Check operand types to see if this is a VFP instruction, and if so call
12280 PFN (). */
12281
12282static int
12283try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12284{
12285 enum neon_shape rs;
12286 struct neon_type_el et;
12287
12288 switch (args)
12289 {
12290 case 2:
12291 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12292 et = neon_check_type (2, rs,
12293 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12294 break;
5f4273c7 12295
037e8744
JB
12296 case 3:
12297 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12298 et = neon_check_type (3, rs,
12299 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12300 break;
12301
12302 default:
12303 abort ();
12304 }
12305
12306 if (et.type != NT_invtype)
12307 {
12308 pfn (rs);
12309 return SUCCESS;
12310 }
037e8744 12311
99b253c5 12312 inst.error = NULL;
037e8744
JB
12313 return FAIL;
12314}
12315
12316static void
12317do_vfp_nsyn_mla_mls (enum neon_shape rs)
12318{
12319 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12320
037e8744
JB
12321 if (rs == NS_FFF)
12322 {
12323 if (is_mla)
12324 do_vfp_nsyn_opcode ("fmacs");
12325 else
1ee69515 12326 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12327 }
12328 else
12329 {
12330 if (is_mla)
12331 do_vfp_nsyn_opcode ("fmacd");
12332 else
1ee69515 12333 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12334 }
12335}
12336
62f3b8c8
PB
12337static void
12338do_vfp_nsyn_fma_fms (enum neon_shape rs)
12339{
12340 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12341
12342 if (rs == NS_FFF)
12343 {
12344 if (is_fma)
12345 do_vfp_nsyn_opcode ("ffmas");
12346 else
12347 do_vfp_nsyn_opcode ("ffnmas");
12348 }
12349 else
12350 {
12351 if (is_fma)
12352 do_vfp_nsyn_opcode ("ffmad");
12353 else
12354 do_vfp_nsyn_opcode ("ffnmad");
12355 }
12356}
12357
037e8744
JB
12358static void
12359do_vfp_nsyn_mul (enum neon_shape rs)
12360{
12361 if (rs == NS_FFF)
12362 do_vfp_nsyn_opcode ("fmuls");
12363 else
12364 do_vfp_nsyn_opcode ("fmuld");
12365}
12366
12367static void
12368do_vfp_nsyn_abs_neg (enum neon_shape rs)
12369{
12370 int is_neg = (inst.instruction & 0x80) != 0;
12371 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12372
12373 if (rs == NS_FF)
12374 {
12375 if (is_neg)
12376 do_vfp_nsyn_opcode ("fnegs");
12377 else
12378 do_vfp_nsyn_opcode ("fabss");
12379 }
12380 else
12381 {
12382 if (is_neg)
12383 do_vfp_nsyn_opcode ("fnegd");
12384 else
12385 do_vfp_nsyn_opcode ("fabsd");
12386 }
12387}
12388
12389/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12390 insns belong to Neon, and are handled elsewhere. */
12391
12392static void
12393do_vfp_nsyn_ldm_stm (int is_dbmode)
12394{
12395 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12396 if (is_ldm)
12397 {
12398 if (is_dbmode)
12399 do_vfp_nsyn_opcode ("fldmdbs");
12400 else
12401 do_vfp_nsyn_opcode ("fldmias");
12402 }
12403 else
12404 {
12405 if (is_dbmode)
12406 do_vfp_nsyn_opcode ("fstmdbs");
12407 else
12408 do_vfp_nsyn_opcode ("fstmias");
12409 }
12410}
12411
037e8744
JB
12412static void
12413do_vfp_nsyn_sqrt (void)
12414{
12415 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12416 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12417
037e8744
JB
12418 if (rs == NS_FF)
12419 do_vfp_nsyn_opcode ("fsqrts");
12420 else
12421 do_vfp_nsyn_opcode ("fsqrtd");
12422}
12423
12424static void
12425do_vfp_nsyn_div (void)
12426{
12427 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12428 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12429 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12430
037e8744
JB
12431 if (rs == NS_FFF)
12432 do_vfp_nsyn_opcode ("fdivs");
12433 else
12434 do_vfp_nsyn_opcode ("fdivd");
12435}
12436
12437static void
12438do_vfp_nsyn_nmul (void)
12439{
12440 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12441 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12442 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12443
037e8744
JB
12444 if (rs == NS_FFF)
12445 {
88714cb8 12446 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12447 do_vfp_sp_dyadic ();
12448 }
12449 else
12450 {
88714cb8 12451 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12452 do_vfp_dp_rd_rn_rm ();
12453 }
12454 do_vfp_cond_or_thumb ();
12455}
12456
12457static void
12458do_vfp_nsyn_cmp (void)
12459{
12460 if (inst.operands[1].isreg)
12461 {
12462 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12463 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12464
037e8744
JB
12465 if (rs == NS_FF)
12466 {
88714cb8 12467 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12468 do_vfp_sp_monadic ();
12469 }
12470 else
12471 {
88714cb8 12472 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12473 do_vfp_dp_rd_rm ();
12474 }
12475 }
12476 else
12477 {
12478 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12479 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12480
12481 switch (inst.instruction & 0x0fffffff)
12482 {
12483 case N_MNEM_vcmp:
12484 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12485 break;
12486 case N_MNEM_vcmpe:
12487 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12488 break;
12489 default:
12490 abort ();
12491 }
5f4273c7 12492
037e8744
JB
12493 if (rs == NS_FI)
12494 {
88714cb8 12495 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12496 do_vfp_sp_compare_z ();
12497 }
12498 else
12499 {
88714cb8 12500 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12501 do_vfp_dp_rd ();
12502 }
12503 }
12504 do_vfp_cond_or_thumb ();
12505}
12506
12507static void
12508nsyn_insert_sp (void)
12509{
12510 inst.operands[1] = inst.operands[0];
12511 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12512 inst.operands[0].reg = REG_SP;
037e8744
JB
12513 inst.operands[0].isreg = 1;
12514 inst.operands[0].writeback = 1;
12515 inst.operands[0].present = 1;
12516}
12517
12518static void
12519do_vfp_nsyn_push (void)
12520{
12521 nsyn_insert_sp ();
12522 if (inst.operands[1].issingle)
12523 do_vfp_nsyn_opcode ("fstmdbs");
12524 else
12525 do_vfp_nsyn_opcode ("fstmdbd");
12526}
12527
12528static void
12529do_vfp_nsyn_pop (void)
12530{
12531 nsyn_insert_sp ();
12532 if (inst.operands[1].issingle)
22b5b651 12533 do_vfp_nsyn_opcode ("fldmias");
037e8744 12534 else
22b5b651 12535 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12536}
12537
12538/* Fix up Neon data-processing instructions, ORing in the correct bits for
12539 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12540
88714cb8
DG
12541static void
12542neon_dp_fixup (struct arm_it* insn)
037e8744 12543{
88714cb8
DG
12544 unsigned int i = insn->instruction;
12545 insn->is_neon = 1;
12546
037e8744
JB
12547 if (thumb_mode)
12548 {
12549 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12550 if (i & (1 << 24))
12551 i |= 1 << 28;
5f4273c7 12552
037e8744 12553 i &= ~(1 << 24);
5f4273c7 12554
037e8744
JB
12555 i |= 0xef000000;
12556 }
12557 else
12558 i |= 0xf2000000;
5f4273c7 12559
88714cb8 12560 insn->instruction = i;
037e8744
JB
12561}
12562
12563/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12564 (0, 1, 2, 3). */
12565
12566static unsigned
12567neon_logbits (unsigned x)
12568{
12569 return ffs (x) - 4;
12570}
12571
12572#define LOW4(R) ((R) & 0xf)
12573#define HI1(R) (((R) >> 4) & 1)
12574
12575/* Encode insns with bit pattern:
12576
12577 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12578 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12579
037e8744
JB
12580 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12581 different meaning for some instruction. */
12582
12583static void
12584neon_three_same (int isquad, int ubit, int size)
12585{
12586 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12587 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12588 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12589 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12590 inst.instruction |= LOW4 (inst.operands[2].reg);
12591 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12592 inst.instruction |= (isquad != 0) << 6;
12593 inst.instruction |= (ubit != 0) << 24;
12594 if (size != -1)
12595 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12596
88714cb8 12597 neon_dp_fixup (&inst);
037e8744
JB
12598}
12599
12600/* Encode instructions of the form:
12601
12602 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12603 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12604
12605 Don't write size if SIZE == -1. */
12606
12607static void
12608neon_two_same (int qbit, int ubit, int size)
12609{
12610 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12611 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12612 inst.instruction |= LOW4 (inst.operands[1].reg);
12613 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12614 inst.instruction |= (qbit != 0) << 6;
12615 inst.instruction |= (ubit != 0) << 24;
12616
12617 if (size != -1)
12618 inst.instruction |= neon_logbits (size) << 18;
12619
88714cb8 12620 neon_dp_fixup (&inst);
5287ad62
JB
12621}
12622
12623/* Neon instruction encoders, in approximate order of appearance. */
12624
12625static void
12626do_neon_dyadic_i_su (void)
12627{
037e8744 12628 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12629 struct neon_type_el et = neon_check_type (3, rs,
12630 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12631 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12632}
12633
12634static void
12635do_neon_dyadic_i64_su (void)
12636{
037e8744 12637 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12638 struct neon_type_el et = neon_check_type (3, rs,
12639 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12640 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12641}
12642
12643static void
12644neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12645 unsigned immbits)
12646{
12647 unsigned size = et.size >> 3;
12648 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12649 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12650 inst.instruction |= LOW4 (inst.operands[1].reg);
12651 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12652 inst.instruction |= (isquad != 0) << 6;
12653 inst.instruction |= immbits << 16;
12654 inst.instruction |= (size >> 3) << 7;
12655 inst.instruction |= (size & 0x7) << 19;
12656 if (write_ubit)
12657 inst.instruction |= (uval != 0) << 24;
12658
88714cb8 12659 neon_dp_fixup (&inst);
5287ad62
JB
12660}
12661
12662static void
12663do_neon_shl_imm (void)
12664{
12665 if (!inst.operands[2].isreg)
12666 {
037e8744 12667 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12668 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12669 NEON_ENCODE (IMMED, inst);
037e8744 12670 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12671 }
12672 else
12673 {
037e8744 12674 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12675 struct neon_type_el et = neon_check_type (3, rs,
12676 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12677 unsigned int tmp;
12678
12679 /* VSHL/VQSHL 3-register variants have syntax such as:
12680 vshl.xx Dd, Dm, Dn
12681 whereas other 3-register operations encoded by neon_three_same have
12682 syntax like:
12683 vadd.xx Dd, Dn, Dm
12684 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12685 here. */
12686 tmp = inst.operands[2].reg;
12687 inst.operands[2].reg = inst.operands[1].reg;
12688 inst.operands[1].reg = tmp;
88714cb8 12689 NEON_ENCODE (INTEGER, inst);
037e8744 12690 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12691 }
12692}
12693
12694static void
12695do_neon_qshl_imm (void)
12696{
12697 if (!inst.operands[2].isreg)
12698 {
037e8744 12699 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12700 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12701
88714cb8 12702 NEON_ENCODE (IMMED, inst);
037e8744 12703 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12704 inst.operands[2].imm);
12705 }
12706 else
12707 {
037e8744 12708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12709 struct neon_type_el et = neon_check_type (3, rs,
12710 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12711 unsigned int tmp;
12712
12713 /* See note in do_neon_shl_imm. */
12714 tmp = inst.operands[2].reg;
12715 inst.operands[2].reg = inst.operands[1].reg;
12716 inst.operands[1].reg = tmp;
88714cb8 12717 NEON_ENCODE (INTEGER, inst);
037e8744 12718 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12719 }
12720}
12721
627907b7
JB
12722static void
12723do_neon_rshl (void)
12724{
12725 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12726 struct neon_type_el et = neon_check_type (3, rs,
12727 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12728 unsigned int tmp;
12729
12730 tmp = inst.operands[2].reg;
12731 inst.operands[2].reg = inst.operands[1].reg;
12732 inst.operands[1].reg = tmp;
12733 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12734}
12735
5287ad62
JB
12736static int
12737neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12738{
036dc3f7
PB
12739 /* Handle .I8 pseudo-instructions. */
12740 if (size == 8)
5287ad62 12741 {
5287ad62
JB
12742 /* Unfortunately, this will make everything apart from zero out-of-range.
12743 FIXME is this the intended semantics? There doesn't seem much point in
12744 accepting .I8 if so. */
12745 immediate |= immediate << 8;
12746 size = 16;
036dc3f7
PB
12747 }
12748
12749 if (size >= 32)
12750 {
12751 if (immediate == (immediate & 0x000000ff))
12752 {
12753 *immbits = immediate;
12754 return 0x1;
12755 }
12756 else if (immediate == (immediate & 0x0000ff00))
12757 {
12758 *immbits = immediate >> 8;
12759 return 0x3;
12760 }
12761 else if (immediate == (immediate & 0x00ff0000))
12762 {
12763 *immbits = immediate >> 16;
12764 return 0x5;
12765 }
12766 else if (immediate == (immediate & 0xff000000))
12767 {
12768 *immbits = immediate >> 24;
12769 return 0x7;
12770 }
12771 if ((immediate & 0xffff) != (immediate >> 16))
12772 goto bad_immediate;
12773 immediate &= 0xffff;
5287ad62
JB
12774 }
12775
12776 if (immediate == (immediate & 0x000000ff))
12777 {
12778 *immbits = immediate;
036dc3f7 12779 return 0x9;
5287ad62
JB
12780 }
12781 else if (immediate == (immediate & 0x0000ff00))
12782 {
12783 *immbits = immediate >> 8;
036dc3f7 12784 return 0xb;
5287ad62
JB
12785 }
12786
12787 bad_immediate:
dcbf9037 12788 first_error (_("immediate value out of range"));
5287ad62
JB
12789 return FAIL;
12790}
12791
12792/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12793 A, B, C, D. */
12794
12795static int
12796neon_bits_same_in_bytes (unsigned imm)
12797{
12798 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12799 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12800 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12801 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12802}
12803
12804/* For immediate of above form, return 0bABCD. */
12805
12806static unsigned
12807neon_squash_bits (unsigned imm)
12808{
12809 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12810 | ((imm & 0x01000000) >> 21);
12811}
12812
136da414 12813/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12814
12815static unsigned
12816neon_qfloat_bits (unsigned imm)
12817{
136da414 12818 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12819}
12820
12821/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12822 the instruction. *OP is passed as the initial value of the op field, and
12823 may be set to a different value depending on the constant (i.e.
12824 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12825 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12826 try smaller element sizes. */
5287ad62
JB
12827
12828static int
c96612cc
JB
12829neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12830 unsigned *immbits, int *op, int size,
12831 enum neon_el_type type)
5287ad62 12832{
c96612cc
JB
12833 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12834 float. */
12835 if (type == NT_float && !float_p)
12836 return FAIL;
12837
136da414
JB
12838 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12839 {
12840 if (size != 32 || *op == 1)
12841 return FAIL;
12842 *immbits = neon_qfloat_bits (immlo);
12843 return 0xf;
12844 }
036dc3f7
PB
12845
12846 if (size == 64)
5287ad62 12847 {
036dc3f7
PB
12848 if (neon_bits_same_in_bytes (immhi)
12849 && neon_bits_same_in_bytes (immlo))
12850 {
12851 if (*op == 1)
12852 return FAIL;
12853 *immbits = (neon_squash_bits (immhi) << 4)
12854 | neon_squash_bits (immlo);
12855 *op = 1;
12856 return 0xe;
12857 }
12858
12859 if (immhi != immlo)
12860 return FAIL;
5287ad62 12861 }
036dc3f7
PB
12862
12863 if (size >= 32)
5287ad62 12864 {
036dc3f7
PB
12865 if (immlo == (immlo & 0x000000ff))
12866 {
12867 *immbits = immlo;
12868 return 0x0;
12869 }
12870 else if (immlo == (immlo & 0x0000ff00))
12871 {
12872 *immbits = immlo >> 8;
12873 return 0x2;
12874 }
12875 else if (immlo == (immlo & 0x00ff0000))
12876 {
12877 *immbits = immlo >> 16;
12878 return 0x4;
12879 }
12880 else if (immlo == (immlo & 0xff000000))
12881 {
12882 *immbits = immlo >> 24;
12883 return 0x6;
12884 }
12885 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12886 {
12887 *immbits = (immlo >> 8) & 0xff;
12888 return 0xc;
12889 }
12890 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12891 {
12892 *immbits = (immlo >> 16) & 0xff;
12893 return 0xd;
12894 }
12895
12896 if ((immlo & 0xffff) != (immlo >> 16))
12897 return FAIL;
12898 immlo &= 0xffff;
5287ad62 12899 }
036dc3f7
PB
12900
12901 if (size >= 16)
5287ad62 12902 {
036dc3f7
PB
12903 if (immlo == (immlo & 0x000000ff))
12904 {
12905 *immbits = immlo;
12906 return 0x8;
12907 }
12908 else if (immlo == (immlo & 0x0000ff00))
12909 {
12910 *immbits = immlo >> 8;
12911 return 0xa;
12912 }
12913
12914 if ((immlo & 0xff) != (immlo >> 8))
12915 return FAIL;
12916 immlo &= 0xff;
5287ad62 12917 }
036dc3f7
PB
12918
12919 if (immlo == (immlo & 0x000000ff))
5287ad62 12920 {
036dc3f7
PB
12921 /* Don't allow MVN with 8-bit immediate. */
12922 if (*op == 1)
12923 return FAIL;
12924 *immbits = immlo;
12925 return 0xe;
5287ad62 12926 }
5287ad62
JB
12927
12928 return FAIL;
12929}
12930
12931/* Write immediate bits [7:0] to the following locations:
12932
12933 |28/24|23 19|18 16|15 4|3 0|
12934 | 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|
12935
12936 This function is used by VMOV/VMVN/VORR/VBIC. */
12937
12938static void
12939neon_write_immbits (unsigned immbits)
12940{
12941 inst.instruction |= immbits & 0xf;
12942 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12943 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12944}
12945
12946/* Invert low-order SIZE bits of XHI:XLO. */
12947
12948static void
12949neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12950{
12951 unsigned immlo = xlo ? *xlo : 0;
12952 unsigned immhi = xhi ? *xhi : 0;
12953
12954 switch (size)
12955 {
12956 case 8:
12957 immlo = (~immlo) & 0xff;
12958 break;
12959
12960 case 16:
12961 immlo = (~immlo) & 0xffff;
12962 break;
12963
12964 case 64:
12965 immhi = (~immhi) & 0xffffffff;
12966 /* fall through. */
12967
12968 case 32:
12969 immlo = (~immlo) & 0xffffffff;
12970 break;
12971
12972 default:
12973 abort ();
12974 }
12975
12976 if (xlo)
12977 *xlo = immlo;
12978
12979 if (xhi)
12980 *xhi = immhi;
12981}
12982
12983static void
12984do_neon_logic (void)
12985{
12986 if (inst.operands[2].present && inst.operands[2].isreg)
12987 {
037e8744 12988 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12989 neon_check_type (3, rs, N_IGNORE_TYPE);
12990 /* U bit and size field were set as part of the bitmask. */
88714cb8 12991 NEON_ENCODE (INTEGER, inst);
037e8744 12992 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12993 }
12994 else
12995 {
4316f0d2
DG
12996 const int three_ops_form = (inst.operands[2].present
12997 && !inst.operands[2].isreg);
12998 const int immoperand = (three_ops_form ? 2 : 1);
12999 enum neon_shape rs = (three_ops_form
13000 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13001 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
13002 struct neon_type_el et = neon_check_type (2, rs,
13003 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 13004 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
13005 unsigned immbits;
13006 int cmode;
5f4273c7 13007
5287ad62
JB
13008 if (et.type == NT_invtype)
13009 return;
5f4273c7 13010
4316f0d2
DG
13011 if (three_ops_form)
13012 constraint (inst.operands[0].reg != inst.operands[1].reg,
13013 _("first and second operands shall be the same register"));
13014
88714cb8 13015 NEON_ENCODE (IMMED, inst);
5287ad62 13016
4316f0d2 13017 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
13018 if (et.size == 64)
13019 {
13020 /* .i64 is a pseudo-op, so the immediate must be a repeating
13021 pattern. */
4316f0d2
DG
13022 if (immbits != (inst.operands[immoperand].regisimm ?
13023 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13024 {
13025 /* Set immbits to an invalid constant. */
13026 immbits = 0xdeadbeef;
13027 }
13028 }
13029
5287ad62
JB
13030 switch (opcode)
13031 {
13032 case N_MNEM_vbic:
036dc3f7 13033 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13034 break;
5f4273c7 13035
5287ad62 13036 case N_MNEM_vorr:
036dc3f7 13037 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13038 break;
5f4273c7 13039
5287ad62
JB
13040 case N_MNEM_vand:
13041 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13042 neon_invert_size (&immbits, 0, et.size);
13043 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13044 break;
5f4273c7 13045
5287ad62
JB
13046 case N_MNEM_vorn:
13047 /* Pseudo-instruction for VORR. */
5287ad62
JB
13048 neon_invert_size (&immbits, 0, et.size);
13049 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13050 break;
5f4273c7 13051
5287ad62
JB
13052 default:
13053 abort ();
13054 }
13055
13056 if (cmode == FAIL)
13057 return;
13058
037e8744 13059 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13060 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13061 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13062 inst.instruction |= cmode << 8;
13063 neon_write_immbits (immbits);
5f4273c7 13064
88714cb8 13065 neon_dp_fixup (&inst);
5287ad62
JB
13066 }
13067}
13068
13069static void
13070do_neon_bitfield (void)
13071{
037e8744 13072 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13073 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13074 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13075}
13076
13077static void
dcbf9037
JB
13078neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13079 unsigned destbits)
5287ad62 13080{
037e8744 13081 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13082 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13083 types | N_KEY);
5287ad62
JB
13084 if (et.type == NT_float)
13085 {
88714cb8 13086 NEON_ENCODE (FLOAT, inst);
037e8744 13087 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13088 }
13089 else
13090 {
88714cb8 13091 NEON_ENCODE (INTEGER, inst);
037e8744 13092 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13093 }
13094}
13095
13096static void
13097do_neon_dyadic_if_su (void)
13098{
dcbf9037 13099 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13100}
13101
13102static void
13103do_neon_dyadic_if_su_d (void)
13104{
13105 /* This version only allow D registers, but that constraint is enforced during
13106 operand parsing so we don't need to do anything extra here. */
dcbf9037 13107 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13108}
13109
5287ad62
JB
13110static void
13111do_neon_dyadic_if_i_d (void)
13112{
428e3f1f
PB
13113 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13114 affected if we specify unsigned args. */
13115 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13116}
13117
037e8744
JB
13118enum vfp_or_neon_is_neon_bits
13119{
13120 NEON_CHECK_CC = 1,
13121 NEON_CHECK_ARCH = 2
13122};
13123
13124/* Call this function if an instruction which may have belonged to the VFP or
13125 Neon instruction sets, but turned out to be a Neon instruction (due to the
13126 operand types involved, etc.). We have to check and/or fix-up a couple of
13127 things:
13128
13129 - Make sure the user hasn't attempted to make a Neon instruction
13130 conditional.
13131 - Alter the value in the condition code field if necessary.
13132 - Make sure that the arch supports Neon instructions.
13133
13134 Which of these operations take place depends on bits from enum
13135 vfp_or_neon_is_neon_bits.
13136
13137 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13138 current instruction's condition is COND_ALWAYS, the condition field is
13139 changed to inst.uncond_value. This is necessary because instructions shared
13140 between VFP and Neon may be conditional for the VFP variants only, and the
13141 unconditional Neon version must have, e.g., 0xF in the condition field. */
13142
13143static int
13144vfp_or_neon_is_neon (unsigned check)
13145{
13146 /* Conditions are always legal in Thumb mode (IT blocks). */
13147 if (!thumb_mode && (check & NEON_CHECK_CC))
13148 {
13149 if (inst.cond != COND_ALWAYS)
13150 {
13151 first_error (_(BAD_COND));
13152 return FAIL;
13153 }
13154 if (inst.uncond_value != -1)
13155 inst.instruction |= inst.uncond_value << 28;
13156 }
5f4273c7 13157
037e8744
JB
13158 if ((check & NEON_CHECK_ARCH)
13159 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13160 {
13161 first_error (_(BAD_FPU));
13162 return FAIL;
13163 }
5f4273c7 13164
037e8744
JB
13165 return SUCCESS;
13166}
13167
5287ad62
JB
13168static void
13169do_neon_addsub_if_i (void)
13170{
037e8744
JB
13171 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13172 return;
13173
13174 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13175 return;
13176
5287ad62
JB
13177 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13178 affected if we specify unsigned args. */
dcbf9037 13179 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13180}
13181
13182/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13183 result to be:
13184 V<op> A,B (A is operand 0, B is operand 2)
13185 to mean:
13186 V<op> A,B,A
13187 not:
13188 V<op> A,B,B
13189 so handle that case specially. */
13190
13191static void
13192neon_exchange_operands (void)
13193{
13194 void *scratch = alloca (sizeof (inst.operands[0]));
13195 if (inst.operands[1].present)
13196 {
13197 /* Swap operands[1] and operands[2]. */
13198 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13199 inst.operands[1] = inst.operands[2];
13200 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13201 }
13202 else
13203 {
13204 inst.operands[1] = inst.operands[2];
13205 inst.operands[2] = inst.operands[0];
13206 }
13207}
13208
13209static void
13210neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13211{
13212 if (inst.operands[2].isreg)
13213 {
13214 if (invert)
13215 neon_exchange_operands ();
dcbf9037 13216 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13217 }
13218 else
13219 {
037e8744 13220 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13221 struct neon_type_el et = neon_check_type (2, rs,
13222 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13223
88714cb8 13224 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13225 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13226 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13227 inst.instruction |= LOW4 (inst.operands[1].reg);
13228 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13229 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13230 inst.instruction |= (et.type == NT_float) << 10;
13231 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13232
88714cb8 13233 neon_dp_fixup (&inst);
5287ad62
JB
13234 }
13235}
13236
13237static void
13238do_neon_cmp (void)
13239{
13240 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13241}
13242
13243static void
13244do_neon_cmp_inv (void)
13245{
13246 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13247}
13248
13249static void
13250do_neon_ceq (void)
13251{
13252 neon_compare (N_IF_32, N_IF_32, FALSE);
13253}
13254
13255/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13256 scalars, which are encoded in 5 bits, M : Rm.
13257 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13258 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13259 index in M. */
13260
13261static unsigned
13262neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13263{
dcbf9037
JB
13264 unsigned regno = NEON_SCALAR_REG (scalar);
13265 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13266
13267 switch (elsize)
13268 {
13269 case 16:
13270 if (regno > 7 || elno > 3)
13271 goto bad_scalar;
13272 return regno | (elno << 3);
5f4273c7 13273
5287ad62
JB
13274 case 32:
13275 if (regno > 15 || elno > 1)
13276 goto bad_scalar;
13277 return regno | (elno << 4);
13278
13279 default:
13280 bad_scalar:
dcbf9037 13281 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13282 }
13283
13284 return 0;
13285}
13286
13287/* Encode multiply / multiply-accumulate scalar instructions. */
13288
13289static void
13290neon_mul_mac (struct neon_type_el et, int ubit)
13291{
dcbf9037
JB
13292 unsigned scalar;
13293
13294 /* Give a more helpful error message if we have an invalid type. */
13295 if (et.type == NT_invtype)
13296 return;
5f4273c7 13297
dcbf9037 13298 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13299 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13300 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13301 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13302 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13303 inst.instruction |= LOW4 (scalar);
13304 inst.instruction |= HI1 (scalar) << 5;
13305 inst.instruction |= (et.type == NT_float) << 8;
13306 inst.instruction |= neon_logbits (et.size) << 20;
13307 inst.instruction |= (ubit != 0) << 24;
13308
88714cb8 13309 neon_dp_fixup (&inst);
5287ad62
JB
13310}
13311
13312static void
13313do_neon_mac_maybe_scalar (void)
13314{
037e8744
JB
13315 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13316 return;
13317
13318 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13319 return;
13320
5287ad62
JB
13321 if (inst.operands[2].isscalar)
13322 {
037e8744 13323 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13324 struct neon_type_el et = neon_check_type (3, rs,
13325 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13326 NEON_ENCODE (SCALAR, inst);
037e8744 13327 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13328 }
13329 else
428e3f1f
PB
13330 {
13331 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13332 affected if we specify unsigned args. */
13333 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13334 }
5287ad62
JB
13335}
13336
62f3b8c8
PB
13337static void
13338do_neon_fmac (void)
13339{
13340 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13341 return;
13342
13343 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13344 return;
13345
13346 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13347}
13348
5287ad62
JB
13349static void
13350do_neon_tst (void)
13351{
037e8744 13352 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13353 struct neon_type_el et = neon_check_type (3, rs,
13354 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13355 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13356}
13357
13358/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13359 same types as the MAC equivalents. The polynomial type for this instruction
13360 is encoded the same as the integer type. */
13361
13362static void
13363do_neon_mul (void)
13364{
037e8744
JB
13365 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13366 return;
13367
13368 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13369 return;
13370
5287ad62
JB
13371 if (inst.operands[2].isscalar)
13372 do_neon_mac_maybe_scalar ();
13373 else
dcbf9037 13374 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13375}
13376
13377static void
13378do_neon_qdmulh (void)
13379{
13380 if (inst.operands[2].isscalar)
13381 {
037e8744 13382 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13383 struct neon_type_el et = neon_check_type (3, rs,
13384 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13385 NEON_ENCODE (SCALAR, inst);
037e8744 13386 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13387 }
13388 else
13389 {
037e8744 13390 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13391 struct neon_type_el et = neon_check_type (3, rs,
13392 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13393 NEON_ENCODE (INTEGER, inst);
5287ad62 13394 /* The U bit (rounding) comes from bit mask. */
037e8744 13395 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13396 }
13397}
13398
13399static void
13400do_neon_fcmp_absolute (void)
13401{
037e8744 13402 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13403 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13404 /* Size field comes from bit mask. */
037e8744 13405 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13406}
13407
13408static void
13409do_neon_fcmp_absolute_inv (void)
13410{
13411 neon_exchange_operands ();
13412 do_neon_fcmp_absolute ();
13413}
13414
13415static void
13416do_neon_step (void)
13417{
037e8744 13418 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13419 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13420 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13421}
13422
13423static void
13424do_neon_abs_neg (void)
13425{
037e8744
JB
13426 enum neon_shape rs;
13427 struct neon_type_el et;
5f4273c7 13428
037e8744
JB
13429 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13430 return;
13431
13432 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13433 return;
13434
13435 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13436 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13437
5287ad62
JB
13438 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13439 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13440 inst.instruction |= LOW4 (inst.operands[1].reg);
13441 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13442 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13443 inst.instruction |= (et.type == NT_float) << 10;
13444 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13445
88714cb8 13446 neon_dp_fixup (&inst);
5287ad62
JB
13447}
13448
13449static void
13450do_neon_sli (void)
13451{
037e8744 13452 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13453 struct neon_type_el et = neon_check_type (2, rs,
13454 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13455 int imm = inst.operands[2].imm;
13456 constraint (imm < 0 || (unsigned)imm >= et.size,
13457 _("immediate out of range for insert"));
037e8744 13458 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13459}
13460
13461static void
13462do_neon_sri (void)
13463{
037e8744 13464 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13465 struct neon_type_el et = neon_check_type (2, rs,
13466 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13467 int imm = inst.operands[2].imm;
13468 constraint (imm < 1 || (unsigned)imm > et.size,
13469 _("immediate out of range for insert"));
037e8744 13470 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13471}
13472
13473static void
13474do_neon_qshlu_imm (void)
13475{
037e8744 13476 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13477 struct neon_type_el et = neon_check_type (2, rs,
13478 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13479 int imm = inst.operands[2].imm;
13480 constraint (imm < 0 || (unsigned)imm >= et.size,
13481 _("immediate out of range for shift"));
13482 /* Only encodes the 'U present' variant of the instruction.
13483 In this case, signed types have OP (bit 8) set to 0.
13484 Unsigned types have OP set to 1. */
13485 inst.instruction |= (et.type == NT_unsigned) << 8;
13486 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13487 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13488}
13489
13490static void
13491do_neon_qmovn (void)
13492{
13493 struct neon_type_el et = neon_check_type (2, NS_DQ,
13494 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13495 /* Saturating move where operands can be signed or unsigned, and the
13496 destination has the same signedness. */
88714cb8 13497 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13498 if (et.type == NT_unsigned)
13499 inst.instruction |= 0xc0;
13500 else
13501 inst.instruction |= 0x80;
13502 neon_two_same (0, 1, et.size / 2);
13503}
13504
13505static void
13506do_neon_qmovun (void)
13507{
13508 struct neon_type_el et = neon_check_type (2, NS_DQ,
13509 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13510 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13511 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13512 neon_two_same (0, 1, et.size / 2);
13513}
13514
13515static void
13516do_neon_rshift_sat_narrow (void)
13517{
13518 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13519 or unsigned. If operands are unsigned, results must also be unsigned. */
13520 struct neon_type_el et = neon_check_type (2, NS_DQI,
13521 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13522 int imm = inst.operands[2].imm;
13523 /* This gets the bounds check, size encoding and immediate bits calculation
13524 right. */
13525 et.size /= 2;
5f4273c7 13526
5287ad62
JB
13527 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13528 VQMOVN.I<size> <Dd>, <Qm>. */
13529 if (imm == 0)
13530 {
13531 inst.operands[2].present = 0;
13532 inst.instruction = N_MNEM_vqmovn;
13533 do_neon_qmovn ();
13534 return;
13535 }
5f4273c7 13536
5287ad62
JB
13537 constraint (imm < 1 || (unsigned)imm > et.size,
13538 _("immediate out of range"));
13539 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13540}
13541
13542static void
13543do_neon_rshift_sat_narrow_u (void)
13544{
13545 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13546 or unsigned. If operands are unsigned, results must also be unsigned. */
13547 struct neon_type_el et = neon_check_type (2, NS_DQI,
13548 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13549 int imm = inst.operands[2].imm;
13550 /* This gets the bounds check, size encoding and immediate bits calculation
13551 right. */
13552 et.size /= 2;
13553
13554 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13555 VQMOVUN.I<size> <Dd>, <Qm>. */
13556 if (imm == 0)
13557 {
13558 inst.operands[2].present = 0;
13559 inst.instruction = N_MNEM_vqmovun;
13560 do_neon_qmovun ();
13561 return;
13562 }
13563
13564 constraint (imm < 1 || (unsigned)imm > et.size,
13565 _("immediate out of range"));
13566 /* FIXME: The manual is kind of unclear about what value U should have in
13567 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13568 must be 1. */
13569 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13570}
13571
13572static void
13573do_neon_movn (void)
13574{
13575 struct neon_type_el et = neon_check_type (2, NS_DQ,
13576 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13577 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13578 neon_two_same (0, 1, et.size / 2);
13579}
13580
13581static void
13582do_neon_rshift_narrow (void)
13583{
13584 struct neon_type_el et = neon_check_type (2, NS_DQI,
13585 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13586 int imm = inst.operands[2].imm;
13587 /* This gets the bounds check, size encoding and immediate bits calculation
13588 right. */
13589 et.size /= 2;
5f4273c7 13590
5287ad62
JB
13591 /* If immediate is zero then we are a pseudo-instruction for
13592 VMOVN.I<size> <Dd>, <Qm> */
13593 if (imm == 0)
13594 {
13595 inst.operands[2].present = 0;
13596 inst.instruction = N_MNEM_vmovn;
13597 do_neon_movn ();
13598 return;
13599 }
5f4273c7 13600
5287ad62
JB
13601 constraint (imm < 1 || (unsigned)imm > et.size,
13602 _("immediate out of range for narrowing operation"));
13603 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13604}
13605
13606static void
13607do_neon_shll (void)
13608{
13609 /* FIXME: Type checking when lengthening. */
13610 struct neon_type_el et = neon_check_type (2, NS_QDI,
13611 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13612 unsigned imm = inst.operands[2].imm;
13613
13614 if (imm == et.size)
13615 {
13616 /* Maximum shift variant. */
88714cb8 13617 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13618 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13619 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13620 inst.instruction |= LOW4 (inst.operands[1].reg);
13621 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13622 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13623
88714cb8 13624 neon_dp_fixup (&inst);
5287ad62
JB
13625 }
13626 else
13627 {
13628 /* A more-specific type check for non-max versions. */
13629 et = neon_check_type (2, NS_QDI,
13630 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13631 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13632 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13633 }
13634}
13635
037e8744 13636/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13637 the current instruction is. */
13638
13639static int
13640neon_cvt_flavour (enum neon_shape rs)
13641{
037e8744
JB
13642#define CVT_VAR(C,X,Y) \
13643 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13644 if (et.type != NT_invtype) \
13645 { \
13646 inst.error = NULL; \
13647 return (C); \
5287ad62
JB
13648 }
13649 struct neon_type_el et;
037e8744
JB
13650 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13651 || rs == NS_FF) ? N_VFP : 0;
13652 /* The instruction versions which take an immediate take one register
13653 argument, which is extended to the width of the full register. Thus the
13654 "source" and "destination" registers must have the same width. Hack that
13655 here by making the size equal to the key (wider, in this case) operand. */
13656 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13657
5287ad62
JB
13658 CVT_VAR (0, N_S32, N_F32);
13659 CVT_VAR (1, N_U32, N_F32);
13660 CVT_VAR (2, N_F32, N_S32);
13661 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13662 /* Half-precision conversions. */
13663 CVT_VAR (4, N_F32, N_F16);
13664 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13665
037e8744 13666 whole_reg = N_VFP;
5f4273c7 13667
037e8744 13668 /* VFP instructions. */
8e79c3df
CM
13669 CVT_VAR (6, N_F32, N_F64);
13670 CVT_VAR (7, N_F64, N_F32);
13671 CVT_VAR (8, N_S32, N_F64 | key);
13672 CVT_VAR (9, N_U32, N_F64 | key);
13673 CVT_VAR (10, N_F64 | key, N_S32);
13674 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13675 /* VFP instructions with bitshift. */
8e79c3df
CM
13676 CVT_VAR (12, N_F32 | key, N_S16);
13677 CVT_VAR (13, N_F32 | key, N_U16);
13678 CVT_VAR (14, N_F64 | key, N_S16);
13679 CVT_VAR (15, N_F64 | key, N_U16);
13680 CVT_VAR (16, N_S16, N_F32 | key);
13681 CVT_VAR (17, N_U16, N_F32 | key);
13682 CVT_VAR (18, N_S16, N_F64 | key);
13683 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13684
5287ad62
JB
13685 return -1;
13686#undef CVT_VAR
13687}
13688
037e8744
JB
13689/* Neon-syntax VFP conversions. */
13690
5287ad62 13691static void
037e8744 13692do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13693{
037e8744 13694 const char *opname = 0;
5f4273c7 13695
037e8744 13696 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13697 {
037e8744
JB
13698 /* Conversions with immediate bitshift. */
13699 const char *enc[] =
13700 {
13701 "ftosls",
13702 "ftouls",
13703 "fsltos",
13704 "fultos",
13705 NULL,
13706 NULL,
8e79c3df
CM
13707 NULL,
13708 NULL,
037e8744
JB
13709 "ftosld",
13710 "ftould",
13711 "fsltod",
13712 "fultod",
13713 "fshtos",
13714 "fuhtos",
13715 "fshtod",
13716 "fuhtod",
13717 "ftoshs",
13718 "ftouhs",
13719 "ftoshd",
13720 "ftouhd"
13721 };
13722
13723 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13724 {
13725 opname = enc[flavour];
13726 constraint (inst.operands[0].reg != inst.operands[1].reg,
13727 _("operands 0 and 1 must be the same register"));
13728 inst.operands[1] = inst.operands[2];
13729 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13730 }
5287ad62
JB
13731 }
13732 else
13733 {
037e8744
JB
13734 /* Conversions without bitshift. */
13735 const char *enc[] =
13736 {
13737 "ftosis",
13738 "ftouis",
13739 "fsitos",
13740 "fuitos",
8e79c3df
CM
13741 "NULL",
13742 "NULL",
037e8744
JB
13743 "fcvtsd",
13744 "fcvtds",
13745 "ftosid",
13746 "ftouid",
13747 "fsitod",
13748 "fuitod"
13749 };
13750
13751 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13752 opname = enc[flavour];
13753 }
13754
13755 if (opname)
13756 do_vfp_nsyn_opcode (opname);
13757}
13758
13759static void
13760do_vfp_nsyn_cvtz (void)
13761{
13762 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13763 int flavour = neon_cvt_flavour (rs);
13764 const char *enc[] =
13765 {
13766 "ftosizs",
13767 "ftouizs",
13768 NULL,
13769 NULL,
13770 NULL,
13771 NULL,
8e79c3df
CM
13772 NULL,
13773 NULL,
037e8744
JB
13774 "ftosizd",
13775 "ftouizd"
13776 };
13777
13778 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13779 do_vfp_nsyn_opcode (enc[flavour]);
13780}
f31fef98 13781
037e8744 13782static void
e3e535bc 13783do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
13784{
13785 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13786 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13787 int flavour = neon_cvt_flavour (rs);
13788
e3e535bc
NC
13789 /* PR11109: Handle round-to-zero for VCVT conversions. */
13790 if (round_to_zero
13791 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13792 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13793 && (rs == NS_FD || rs == NS_FF))
13794 {
13795 do_vfp_nsyn_cvtz ();
13796 return;
13797 }
13798
037e8744 13799 /* VFP rather than Neon conversions. */
8e79c3df 13800 if (flavour >= 6)
037e8744
JB
13801 {
13802 do_vfp_nsyn_cvt (rs, flavour);
13803 return;
13804 }
13805
13806 switch (rs)
13807 {
13808 case NS_DDI:
13809 case NS_QQI:
13810 {
35997600
NC
13811 unsigned immbits;
13812 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13813
037e8744
JB
13814 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13815 return;
13816
13817 /* Fixed-point conversion with #0 immediate is encoded as an
13818 integer conversion. */
13819 if (inst.operands[2].present && inst.operands[2].imm == 0)
13820 goto int_encode;
35997600 13821 immbits = 32 - inst.operands[2].imm;
88714cb8 13822 NEON_ENCODE (IMMED, inst);
037e8744
JB
13823 if (flavour != -1)
13824 inst.instruction |= enctab[flavour];
13825 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13826 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13827 inst.instruction |= LOW4 (inst.operands[1].reg);
13828 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13829 inst.instruction |= neon_quad (rs) << 6;
13830 inst.instruction |= 1 << 21;
13831 inst.instruction |= immbits << 16;
13832
88714cb8 13833 neon_dp_fixup (&inst);
037e8744
JB
13834 }
13835 break;
13836
13837 case NS_DD:
13838 case NS_QQ:
13839 int_encode:
13840 {
13841 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13842
88714cb8 13843 NEON_ENCODE (INTEGER, inst);
037e8744
JB
13844
13845 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13846 return;
13847
13848 if (flavour != -1)
13849 inst.instruction |= enctab[flavour];
13850
13851 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13852 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13853 inst.instruction |= LOW4 (inst.operands[1].reg);
13854 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13855 inst.instruction |= neon_quad (rs) << 6;
13856 inst.instruction |= 2 << 18;
13857
88714cb8 13858 neon_dp_fixup (&inst);
037e8744
JB
13859 }
13860 break;
13861
8e79c3df
CM
13862 /* Half-precision conversions for Advanced SIMD -- neon. */
13863 case NS_QD:
13864 case NS_DQ:
13865
13866 if ((rs == NS_DQ)
13867 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13868 {
13869 as_bad (_("operand size must match register width"));
13870 break;
13871 }
13872
13873 if ((rs == NS_QD)
13874 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13875 {
13876 as_bad (_("operand size must match register width"));
13877 break;
13878 }
13879
13880 if (rs == NS_DQ)
13881 inst.instruction = 0x3b60600;
13882 else
13883 inst.instruction = 0x3b60700;
13884
13885 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13886 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13887 inst.instruction |= LOW4 (inst.operands[1].reg);
13888 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 13889 neon_dp_fixup (&inst);
8e79c3df
CM
13890 break;
13891
037e8744
JB
13892 default:
13893 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13894 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13895 }
5287ad62
JB
13896}
13897
e3e535bc
NC
13898static void
13899do_neon_cvtr (void)
13900{
13901 do_neon_cvt_1 (FALSE);
13902}
13903
13904static void
13905do_neon_cvt (void)
13906{
13907 do_neon_cvt_1 (TRUE);
13908}
13909
8e79c3df
CM
13910static void
13911do_neon_cvtb (void)
13912{
13913 inst.instruction = 0xeb20a40;
13914
13915 /* The sizes are attached to the mnemonic. */
13916 if (inst.vectype.el[0].type != NT_invtype
13917 && inst.vectype.el[0].size == 16)
13918 inst.instruction |= 0x00010000;
13919
13920 /* Programmer's syntax: the sizes are attached to the operands. */
13921 else if (inst.operands[0].vectype.type != NT_invtype
13922 && inst.operands[0].vectype.size == 16)
13923 inst.instruction |= 0x00010000;
13924
13925 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13926 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13927 do_vfp_cond_or_thumb ();
13928}
13929
13930
13931static void
13932do_neon_cvtt (void)
13933{
13934 do_neon_cvtb ();
13935 inst.instruction |= 0x80;
13936}
13937
5287ad62
JB
13938static void
13939neon_move_immediate (void)
13940{
037e8744
JB
13941 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13942 struct neon_type_el et = neon_check_type (2, rs,
13943 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13944 unsigned immlo, immhi = 0, immbits;
c96612cc 13945 int op, cmode, float_p;
5287ad62 13946
037e8744
JB
13947 constraint (et.type == NT_invtype,
13948 _("operand size must be specified for immediate VMOV"));
13949
5287ad62
JB
13950 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13951 op = (inst.instruction & (1 << 5)) != 0;
13952
13953 immlo = inst.operands[1].imm;
13954 if (inst.operands[1].regisimm)
13955 immhi = inst.operands[1].reg;
13956
13957 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13958 _("immediate has bits set outside the operand size"));
13959
c96612cc
JB
13960 float_p = inst.operands[1].immisfloat;
13961
13962 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13963 et.size, et.type)) == FAIL)
5287ad62
JB
13964 {
13965 /* Invert relevant bits only. */
13966 neon_invert_size (&immlo, &immhi, et.size);
13967 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13968 with one or the other; those cases are caught by
13969 neon_cmode_for_move_imm. */
13970 op = !op;
c96612cc
JB
13971 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13972 &op, et.size, et.type)) == FAIL)
5287ad62 13973 {
dcbf9037 13974 first_error (_("immediate out of range"));
5287ad62
JB
13975 return;
13976 }
13977 }
13978
13979 inst.instruction &= ~(1 << 5);
13980 inst.instruction |= op << 5;
13981
13982 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13983 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13984 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13985 inst.instruction |= cmode << 8;
13986
13987 neon_write_immbits (immbits);
13988}
13989
13990static void
13991do_neon_mvn (void)
13992{
13993 if (inst.operands[1].isreg)
13994 {
037e8744 13995 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13996
88714cb8 13997 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13998 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13999 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14000 inst.instruction |= LOW4 (inst.operands[1].reg);
14001 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14002 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14003 }
14004 else
14005 {
88714cb8 14006 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14007 neon_move_immediate ();
14008 }
14009
88714cb8 14010 neon_dp_fixup (&inst);
5287ad62
JB
14011}
14012
14013/* Encode instructions of form:
14014
14015 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 14016 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
14017
14018static void
14019neon_mixed_length (struct neon_type_el et, unsigned size)
14020{
14021 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14022 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14023 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14024 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14025 inst.instruction |= LOW4 (inst.operands[2].reg);
14026 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14027 inst.instruction |= (et.type == NT_unsigned) << 24;
14028 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14029
88714cb8 14030 neon_dp_fixup (&inst);
5287ad62
JB
14031}
14032
14033static void
14034do_neon_dyadic_long (void)
14035{
14036 /* FIXME: Type checking for lengthening op. */
14037 struct neon_type_el et = neon_check_type (3, NS_QDD,
14038 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14039 neon_mixed_length (et, et.size);
14040}
14041
14042static void
14043do_neon_abal (void)
14044{
14045 struct neon_type_el et = neon_check_type (3, NS_QDD,
14046 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14047 neon_mixed_length (et, et.size);
14048}
14049
14050static void
14051neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14052{
14053 if (inst.operands[2].isscalar)
14054 {
dcbf9037
JB
14055 struct neon_type_el et = neon_check_type (3, NS_QDS,
14056 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14057 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14058 neon_mul_mac (et, et.type == NT_unsigned);
14059 }
14060 else
14061 {
14062 struct neon_type_el et = neon_check_type (3, NS_QDD,
14063 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14064 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14065 neon_mixed_length (et, et.size);
14066 }
14067}
14068
14069static void
14070do_neon_mac_maybe_scalar_long (void)
14071{
14072 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14073}
14074
14075static void
14076do_neon_dyadic_wide (void)
14077{
14078 struct neon_type_el et = neon_check_type (3, NS_QQD,
14079 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14080 neon_mixed_length (et, et.size);
14081}
14082
14083static void
14084do_neon_dyadic_narrow (void)
14085{
14086 struct neon_type_el et = neon_check_type (3, NS_QDD,
14087 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14088 /* Operand sign is unimportant, and the U bit is part of the opcode,
14089 so force the operand type to integer. */
14090 et.type = NT_integer;
5287ad62
JB
14091 neon_mixed_length (et, et.size / 2);
14092}
14093
14094static void
14095do_neon_mul_sat_scalar_long (void)
14096{
14097 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14098}
14099
14100static void
14101do_neon_vmull (void)
14102{
14103 if (inst.operands[2].isscalar)
14104 do_neon_mac_maybe_scalar_long ();
14105 else
14106 {
14107 struct neon_type_el et = neon_check_type (3, NS_QDD,
14108 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14109 if (et.type == NT_poly)
88714cb8 14110 NEON_ENCODE (POLY, inst);
5287ad62 14111 else
88714cb8 14112 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14113 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14114 zero. Should be OK as-is. */
14115 neon_mixed_length (et, et.size);
14116 }
14117}
14118
14119static void
14120do_neon_ext (void)
14121{
037e8744 14122 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14123 struct neon_type_el et = neon_check_type (3, rs,
14124 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14125 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14126
14127 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14128 _("shift out of range"));
5287ad62
JB
14129 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14130 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14131 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14132 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14133 inst.instruction |= LOW4 (inst.operands[2].reg);
14134 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14135 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14136 inst.instruction |= imm << 8;
5f4273c7 14137
88714cb8 14138 neon_dp_fixup (&inst);
5287ad62
JB
14139}
14140
14141static void
14142do_neon_rev (void)
14143{
037e8744 14144 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14145 struct neon_type_el et = neon_check_type (2, rs,
14146 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14147 unsigned op = (inst.instruction >> 7) & 3;
14148 /* N (width of reversed regions) is encoded as part of the bitmask. We
14149 extract it here to check the elements to be reversed are smaller.
14150 Otherwise we'd get a reserved instruction. */
14151 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14152 gas_assert (elsize != 0);
5287ad62
JB
14153 constraint (et.size >= elsize,
14154 _("elements must be smaller than reversal region"));
037e8744 14155 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14156}
14157
14158static void
14159do_neon_dup (void)
14160{
14161 if (inst.operands[1].isscalar)
14162 {
037e8744 14163 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14164 struct neon_type_el et = neon_check_type (2, rs,
14165 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14166 unsigned sizebits = et.size >> 3;
dcbf9037 14167 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14168 int logsize = neon_logbits (et.size);
dcbf9037 14169 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14170
14171 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14172 return;
14173
88714cb8 14174 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14175 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14176 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14177 inst.instruction |= LOW4 (dm);
14178 inst.instruction |= HI1 (dm) << 5;
037e8744 14179 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14180 inst.instruction |= x << 17;
14181 inst.instruction |= sizebits << 16;
5f4273c7 14182
88714cb8 14183 neon_dp_fixup (&inst);
5287ad62
JB
14184 }
14185 else
14186 {
037e8744
JB
14187 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14188 struct neon_type_el et = neon_check_type (2, rs,
14189 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14190 /* Duplicate ARM register to lanes of vector. */
88714cb8 14191 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14192 switch (et.size)
14193 {
14194 case 8: inst.instruction |= 0x400000; break;
14195 case 16: inst.instruction |= 0x000020; break;
14196 case 32: inst.instruction |= 0x000000; break;
14197 default: break;
14198 }
14199 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14200 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14201 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14202 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14203 /* The encoding for this instruction is identical for the ARM and Thumb
14204 variants, except for the condition field. */
037e8744 14205 do_vfp_cond_or_thumb ();
5287ad62
JB
14206 }
14207}
14208
14209/* VMOV has particularly many variations. It can be one of:
14210 0. VMOV<c><q> <Qd>, <Qm>
14211 1. VMOV<c><q> <Dd>, <Dm>
14212 (Register operations, which are VORR with Rm = Rn.)
14213 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14214 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14215 (Immediate loads.)
14216 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14217 (ARM register to scalar.)
14218 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14219 (Two ARM registers to vector.)
14220 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14221 (Scalar to ARM register.)
14222 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14223 (Vector to two ARM registers.)
037e8744
JB
14224 8. VMOV.F32 <Sd>, <Sm>
14225 9. VMOV.F64 <Dd>, <Dm>
14226 (VFP register moves.)
14227 10. VMOV.F32 <Sd>, #imm
14228 11. VMOV.F64 <Dd>, #imm
14229 (VFP float immediate load.)
14230 12. VMOV <Rd>, <Sm>
14231 (VFP single to ARM reg.)
14232 13. VMOV <Sd>, <Rm>
14233 (ARM reg to VFP single.)
14234 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14235 (Two ARM regs to two VFP singles.)
14236 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14237 (Two VFP singles to two ARM regs.)
5f4273c7 14238
037e8744
JB
14239 These cases can be disambiguated using neon_select_shape, except cases 1/9
14240 and 3/11 which depend on the operand type too.
5f4273c7 14241
5287ad62 14242 All the encoded bits are hardcoded by this function.
5f4273c7 14243
b7fc2769
JB
14244 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14245 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14246
5287ad62 14247 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14248 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14249
14250static void
14251do_neon_mov (void)
14252{
037e8744
JB
14253 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14254 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14255 NS_NULL);
14256 struct neon_type_el et;
14257 const char *ldconst = 0;
5287ad62 14258
037e8744 14259 switch (rs)
5287ad62 14260 {
037e8744
JB
14261 case NS_DD: /* case 1/9. */
14262 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14263 /* It is not an error here if no type is given. */
14264 inst.error = NULL;
14265 if (et.type == NT_float && et.size == 64)
5287ad62 14266 {
037e8744
JB
14267 do_vfp_nsyn_opcode ("fcpyd");
14268 break;
5287ad62 14269 }
037e8744 14270 /* fall through. */
5287ad62 14271
037e8744
JB
14272 case NS_QQ: /* case 0/1. */
14273 {
14274 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14275 return;
14276 /* The architecture manual I have doesn't explicitly state which
14277 value the U bit should have for register->register moves, but
14278 the equivalent VORR instruction has U = 0, so do that. */
14279 inst.instruction = 0x0200110;
14280 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14281 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14282 inst.instruction |= LOW4 (inst.operands[1].reg);
14283 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14284 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14285 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14286 inst.instruction |= neon_quad (rs) << 6;
14287
88714cb8 14288 neon_dp_fixup (&inst);
037e8744
JB
14289 }
14290 break;
5f4273c7 14291
037e8744
JB
14292 case NS_DI: /* case 3/11. */
14293 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14294 inst.error = NULL;
14295 if (et.type == NT_float && et.size == 64)
5287ad62 14296 {
037e8744
JB
14297 /* case 11 (fconstd). */
14298 ldconst = "fconstd";
14299 goto encode_fconstd;
5287ad62 14300 }
037e8744
JB
14301 /* fall through. */
14302
14303 case NS_QI: /* case 2/3. */
14304 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14305 return;
14306 inst.instruction = 0x0800010;
14307 neon_move_immediate ();
88714cb8 14308 neon_dp_fixup (&inst);
5287ad62 14309 break;
5f4273c7 14310
037e8744
JB
14311 case NS_SR: /* case 4. */
14312 {
14313 unsigned bcdebits = 0;
91d6fa6a 14314 int logsize;
037e8744
JB
14315 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14316 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14317
91d6fa6a
NC
14318 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14319 logsize = neon_logbits (et.size);
14320
037e8744
JB
14321 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14322 _(BAD_FPU));
14323 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14324 && et.size != 32, _(BAD_FPU));
14325 constraint (et.type == NT_invtype, _("bad type for scalar"));
14326 constraint (x >= 64 / et.size, _("scalar index out of range"));
14327
14328 switch (et.size)
14329 {
14330 case 8: bcdebits = 0x8; break;
14331 case 16: bcdebits = 0x1; break;
14332 case 32: bcdebits = 0x0; break;
14333 default: ;
14334 }
14335
14336 bcdebits |= x << logsize;
14337
14338 inst.instruction = 0xe000b10;
14339 do_vfp_cond_or_thumb ();
14340 inst.instruction |= LOW4 (dn) << 16;
14341 inst.instruction |= HI1 (dn) << 7;
14342 inst.instruction |= inst.operands[1].reg << 12;
14343 inst.instruction |= (bcdebits & 3) << 5;
14344 inst.instruction |= (bcdebits >> 2) << 21;
14345 }
14346 break;
5f4273c7 14347
037e8744 14348 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14349 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14350 _(BAD_FPU));
b7fc2769 14351
037e8744
JB
14352 inst.instruction = 0xc400b10;
14353 do_vfp_cond_or_thumb ();
14354 inst.instruction |= LOW4 (inst.operands[0].reg);
14355 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14356 inst.instruction |= inst.operands[1].reg << 12;
14357 inst.instruction |= inst.operands[2].reg << 16;
14358 break;
5f4273c7 14359
037e8744
JB
14360 case NS_RS: /* case 6. */
14361 {
91d6fa6a 14362 unsigned logsize;
037e8744
JB
14363 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14364 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14365 unsigned abcdebits = 0;
14366
91d6fa6a
NC
14367 et = neon_check_type (2, NS_NULL,
14368 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14369 logsize = neon_logbits (et.size);
14370
037e8744
JB
14371 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14372 _(BAD_FPU));
14373 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14374 && et.size != 32, _(BAD_FPU));
14375 constraint (et.type == NT_invtype, _("bad type for scalar"));
14376 constraint (x >= 64 / et.size, _("scalar index out of range"));
14377
14378 switch (et.size)
14379 {
14380 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14381 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14382 case 32: abcdebits = 0x00; break;
14383 default: ;
14384 }
14385
14386 abcdebits |= x << logsize;
14387 inst.instruction = 0xe100b10;
14388 do_vfp_cond_or_thumb ();
14389 inst.instruction |= LOW4 (dn) << 16;
14390 inst.instruction |= HI1 (dn) << 7;
14391 inst.instruction |= inst.operands[0].reg << 12;
14392 inst.instruction |= (abcdebits & 3) << 5;
14393 inst.instruction |= (abcdebits >> 2) << 21;
14394 }
14395 break;
5f4273c7 14396
037e8744
JB
14397 case NS_RRD: /* case 7 (fmrrd). */
14398 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14399 _(BAD_FPU));
14400
14401 inst.instruction = 0xc500b10;
14402 do_vfp_cond_or_thumb ();
14403 inst.instruction |= inst.operands[0].reg << 12;
14404 inst.instruction |= inst.operands[1].reg << 16;
14405 inst.instruction |= LOW4 (inst.operands[2].reg);
14406 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14407 break;
5f4273c7 14408
037e8744
JB
14409 case NS_FF: /* case 8 (fcpys). */
14410 do_vfp_nsyn_opcode ("fcpys");
14411 break;
5f4273c7 14412
037e8744
JB
14413 case NS_FI: /* case 10 (fconsts). */
14414 ldconst = "fconsts";
14415 encode_fconstd:
14416 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14417 {
037e8744
JB
14418 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14419 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14420 }
14421 else
037e8744
JB
14422 first_error (_("immediate out of range"));
14423 break;
5f4273c7 14424
037e8744
JB
14425 case NS_RF: /* case 12 (fmrs). */
14426 do_vfp_nsyn_opcode ("fmrs");
14427 break;
5f4273c7 14428
037e8744
JB
14429 case NS_FR: /* case 13 (fmsr). */
14430 do_vfp_nsyn_opcode ("fmsr");
14431 break;
5f4273c7 14432
037e8744
JB
14433 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14434 (one of which is a list), but we have parsed four. Do some fiddling to
14435 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14436 expect. */
14437 case NS_RRFF: /* case 14 (fmrrs). */
14438 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14439 _("VFP registers must be adjacent"));
14440 inst.operands[2].imm = 2;
14441 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14442 do_vfp_nsyn_opcode ("fmrrs");
14443 break;
5f4273c7 14444
037e8744
JB
14445 case NS_FFRR: /* case 15 (fmsrr). */
14446 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14447 _("VFP registers must be adjacent"));
14448 inst.operands[1] = inst.operands[2];
14449 inst.operands[2] = inst.operands[3];
14450 inst.operands[0].imm = 2;
14451 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14452 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14453 break;
5f4273c7 14454
5287ad62
JB
14455 default:
14456 abort ();
14457 }
14458}
14459
14460static void
14461do_neon_rshift_round_imm (void)
14462{
037e8744 14463 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14464 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14465 int imm = inst.operands[2].imm;
14466
14467 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14468 if (imm == 0)
14469 {
14470 inst.operands[2].present = 0;
14471 do_neon_mov ();
14472 return;
14473 }
14474
14475 constraint (imm < 1 || (unsigned)imm > et.size,
14476 _("immediate out of range for shift"));
037e8744 14477 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14478 et.size - imm);
14479}
14480
14481static void
14482do_neon_movl (void)
14483{
14484 struct neon_type_el et = neon_check_type (2, NS_QD,
14485 N_EQK | N_DBL, N_SU_32 | N_KEY);
14486 unsigned sizebits = et.size >> 3;
14487 inst.instruction |= sizebits << 19;
14488 neon_two_same (0, et.type == NT_unsigned, -1);
14489}
14490
14491static void
14492do_neon_trn (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);
88714cb8 14497 NEON_ENCODE (INTEGER, inst);
037e8744 14498 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14499}
14500
14501static void
14502do_neon_zip_uzp (void)
14503{
037e8744 14504 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14505 struct neon_type_el et = neon_check_type (2, rs,
14506 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14507 if (rs == NS_DD && et.size == 32)
14508 {
14509 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14510 inst.instruction = N_MNEM_vtrn;
14511 do_neon_trn ();
14512 return;
14513 }
037e8744 14514 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14515}
14516
14517static void
14518do_neon_sat_abs_neg (void)
14519{
037e8744 14520 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14521 struct neon_type_el et = neon_check_type (2, rs,
14522 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14523 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14524}
14525
14526static void
14527do_neon_pair_long (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, N_EQK, N_SU_32 | N_KEY);
14531 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14532 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14533 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14534}
14535
14536static void
14537do_neon_recip_est (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_FLT, N_F32 | N_U32 | N_KEY);
14542 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14543 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14544}
14545
14546static void
14547do_neon_cls (void)
14548{
037e8744 14549 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14550 struct neon_type_el et = neon_check_type (2, rs,
14551 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14552 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14553}
14554
14555static void
14556do_neon_clz (void)
14557{
037e8744 14558 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14559 struct neon_type_el et = neon_check_type (2, rs,
14560 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14561 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14562}
14563
14564static void
14565do_neon_cnt (void)
14566{
037e8744 14567 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14568 struct neon_type_el et = neon_check_type (2, rs,
14569 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14570 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14571}
14572
14573static void
14574do_neon_swp (void)
14575{
037e8744
JB
14576 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14577 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14578}
14579
14580static void
14581do_neon_tbl_tbx (void)
14582{
14583 unsigned listlenbits;
dcbf9037 14584 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14585
5287ad62
JB
14586 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14587 {
dcbf9037 14588 first_error (_("bad list length for table lookup"));
5287ad62
JB
14589 return;
14590 }
5f4273c7 14591
5287ad62
JB
14592 listlenbits = inst.operands[1].imm - 1;
14593 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14594 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14595 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14596 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14597 inst.instruction |= LOW4 (inst.operands[2].reg);
14598 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14599 inst.instruction |= listlenbits << 8;
5f4273c7 14600
88714cb8 14601 neon_dp_fixup (&inst);
5287ad62
JB
14602}
14603
14604static void
14605do_neon_ldm_stm (void)
14606{
14607 /* P, U and L bits are part of bitmask. */
14608 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14609 unsigned offsetbits = inst.operands[1].imm * 2;
14610
037e8744
JB
14611 if (inst.operands[1].issingle)
14612 {
14613 do_vfp_nsyn_ldm_stm (is_dbmode);
14614 return;
14615 }
14616
5287ad62
JB
14617 constraint (is_dbmode && !inst.operands[0].writeback,
14618 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14619
14620 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14621 _("register list must contain at least 1 and at most 16 "
14622 "registers"));
14623
14624 inst.instruction |= inst.operands[0].reg << 16;
14625 inst.instruction |= inst.operands[0].writeback << 21;
14626 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14627 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14628
14629 inst.instruction |= offsetbits;
5f4273c7 14630
037e8744 14631 do_vfp_cond_or_thumb ();
5287ad62
JB
14632}
14633
14634static void
14635do_neon_ldr_str (void)
14636{
5287ad62 14637 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14638
037e8744
JB
14639 if (inst.operands[0].issingle)
14640 {
cd2f129f
JB
14641 if (is_ldr)
14642 do_vfp_nsyn_opcode ("flds");
14643 else
14644 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14645 }
14646 else
5287ad62 14647 {
cd2f129f
JB
14648 if (is_ldr)
14649 do_vfp_nsyn_opcode ("fldd");
5287ad62 14650 else
cd2f129f 14651 do_vfp_nsyn_opcode ("fstd");
5287ad62 14652 }
5287ad62
JB
14653}
14654
14655/* "interleave" version also handles non-interleaving register VLD1/VST1
14656 instructions. */
14657
14658static void
14659do_neon_ld_st_interleave (void)
14660{
037e8744 14661 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14662 N_8 | N_16 | N_32 | N_64);
14663 unsigned alignbits = 0;
14664 unsigned idx;
14665 /* The bits in this table go:
14666 0: register stride of one (0) or two (1)
14667 1,2: register list length, minus one (1, 2, 3, 4).
14668 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14669 We use -1 for invalid entries. */
14670 const int typetable[] =
14671 {
14672 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14673 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14674 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14675 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14676 };
14677 int typebits;
14678
dcbf9037
JB
14679 if (et.type == NT_invtype)
14680 return;
14681
5287ad62
JB
14682 if (inst.operands[1].immisalign)
14683 switch (inst.operands[1].imm >> 8)
14684 {
14685 case 64: alignbits = 1; break;
14686 case 128:
e23c0ad8
JZ
14687 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14688 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14689 goto bad_alignment;
14690 alignbits = 2;
14691 break;
14692 case 256:
e23c0ad8 14693 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14694 goto bad_alignment;
14695 alignbits = 3;
14696 break;
14697 default:
14698 bad_alignment:
dcbf9037 14699 first_error (_("bad alignment"));
5287ad62
JB
14700 return;
14701 }
14702
14703 inst.instruction |= alignbits << 4;
14704 inst.instruction |= neon_logbits (et.size) << 6;
14705
14706 /* Bits [4:6] of the immediate in a list specifier encode register stride
14707 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14708 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14709 up the right value for "type" in a table based on this value and the given
14710 list style, then stick it back. */
14711 idx = ((inst.operands[0].imm >> 4) & 7)
14712 | (((inst.instruction >> 8) & 3) << 3);
14713
14714 typebits = typetable[idx];
5f4273c7 14715
5287ad62
JB
14716 constraint (typebits == -1, _("bad list type for instruction"));
14717
14718 inst.instruction &= ~0xf00;
14719 inst.instruction |= typebits << 8;
14720}
14721
14722/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14723 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14724 otherwise. The variable arguments are a list of pairs of legal (size, align)
14725 values, terminated with -1. */
14726
14727static int
14728neon_alignment_bit (int size, int align, int *do_align, ...)
14729{
14730 va_list ap;
14731 int result = FAIL, thissize, thisalign;
5f4273c7 14732
5287ad62
JB
14733 if (!inst.operands[1].immisalign)
14734 {
14735 *do_align = 0;
14736 return SUCCESS;
14737 }
5f4273c7 14738
5287ad62
JB
14739 va_start (ap, do_align);
14740
14741 do
14742 {
14743 thissize = va_arg (ap, int);
14744 if (thissize == -1)
14745 break;
14746 thisalign = va_arg (ap, int);
14747
14748 if (size == thissize && align == thisalign)
14749 result = SUCCESS;
14750 }
14751 while (result != SUCCESS);
14752
14753 va_end (ap);
14754
14755 if (result == SUCCESS)
14756 *do_align = 1;
14757 else
dcbf9037 14758 first_error (_("unsupported alignment for instruction"));
5f4273c7 14759
5287ad62
JB
14760 return result;
14761}
14762
14763static void
14764do_neon_ld_st_lane (void)
14765{
037e8744 14766 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14767 int align_good, do_align = 0;
14768 int logsize = neon_logbits (et.size);
14769 int align = inst.operands[1].imm >> 8;
14770 int n = (inst.instruction >> 8) & 3;
14771 int max_el = 64 / et.size;
5f4273c7 14772
dcbf9037
JB
14773 if (et.type == NT_invtype)
14774 return;
5f4273c7 14775
5287ad62
JB
14776 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14777 _("bad list length"));
14778 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14779 _("scalar index out of range"));
14780 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14781 && et.size == 8,
14782 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14783
5287ad62
JB
14784 switch (n)
14785 {
14786 case 0: /* VLD1 / VST1. */
14787 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14788 32, 32, -1);
14789 if (align_good == FAIL)
14790 return;
14791 if (do_align)
14792 {
14793 unsigned alignbits = 0;
14794 switch (et.size)
14795 {
14796 case 16: alignbits = 0x1; break;
14797 case 32: alignbits = 0x3; break;
14798 default: ;
14799 }
14800 inst.instruction |= alignbits << 4;
14801 }
14802 break;
14803
14804 case 1: /* VLD2 / VST2. */
14805 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14806 32, 64, -1);
14807 if (align_good == FAIL)
14808 return;
14809 if (do_align)
14810 inst.instruction |= 1 << 4;
14811 break;
14812
14813 case 2: /* VLD3 / VST3. */
14814 constraint (inst.operands[1].immisalign,
14815 _("can't use alignment with this instruction"));
14816 break;
14817
14818 case 3: /* VLD4 / VST4. */
14819 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14820 16, 64, 32, 64, 32, 128, -1);
14821 if (align_good == FAIL)
14822 return;
14823 if (do_align)
14824 {
14825 unsigned alignbits = 0;
14826 switch (et.size)
14827 {
14828 case 8: alignbits = 0x1; break;
14829 case 16: alignbits = 0x1; break;
14830 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14831 default: ;
14832 }
14833 inst.instruction |= alignbits << 4;
14834 }
14835 break;
14836
14837 default: ;
14838 }
14839
14840 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14841 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14842 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14843
5287ad62
JB
14844 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14845 inst.instruction |= logsize << 10;
14846}
14847
14848/* Encode single n-element structure to all lanes VLD<n> instructions. */
14849
14850static void
14851do_neon_ld_dup (void)
14852{
037e8744 14853 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14854 int align_good, do_align = 0;
14855
dcbf9037
JB
14856 if (et.type == NT_invtype)
14857 return;
14858
5287ad62
JB
14859 switch ((inst.instruction >> 8) & 3)
14860 {
14861 case 0: /* VLD1. */
9c2799c2 14862 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14863 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14864 &do_align, 16, 16, 32, 32, -1);
14865 if (align_good == FAIL)
14866 return;
14867 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14868 {
14869 case 1: break;
14870 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14871 default: first_error (_("bad list length")); return;
5287ad62
JB
14872 }
14873 inst.instruction |= neon_logbits (et.size) << 6;
14874 break;
14875
14876 case 1: /* VLD2. */
14877 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14878 &do_align, 8, 16, 16, 32, 32, 64, -1);
14879 if (align_good == FAIL)
14880 return;
14881 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
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 2: /* VLD3. */
14889 constraint (inst.operands[1].immisalign,
14890 _("can't use alignment with this instruction"));
14891 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14892 _("bad list length"));
14893 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14894 inst.instruction |= 1 << 5;
14895 inst.instruction |= neon_logbits (et.size) << 6;
14896 break;
14897
14898 case 3: /* VLD4. */
14899 {
14900 int align = inst.operands[1].imm >> 8;
14901 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14902 16, 64, 32, 64, 32, 128, -1);
14903 if (align_good == FAIL)
14904 return;
14905 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14906 _("bad list length"));
14907 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14908 inst.instruction |= 1 << 5;
14909 if (et.size == 32 && align == 128)
14910 inst.instruction |= 0x3 << 6;
14911 else
14912 inst.instruction |= neon_logbits (et.size) << 6;
14913 }
14914 break;
14915
14916 default: ;
14917 }
14918
14919 inst.instruction |= do_align << 4;
14920}
14921
14922/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14923 apart from bits [11:4]. */
14924
14925static void
14926do_neon_ldx_stx (void)
14927{
b1a769ed
DG
14928 if (inst.operands[1].isreg)
14929 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14930
5287ad62
JB
14931 switch (NEON_LANE (inst.operands[0].imm))
14932 {
14933 case NEON_INTERLEAVE_LANES:
88714cb8 14934 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
14935 do_neon_ld_st_interleave ();
14936 break;
5f4273c7 14937
5287ad62 14938 case NEON_ALL_LANES:
88714cb8 14939 NEON_ENCODE (DUP, inst);
5287ad62
JB
14940 do_neon_ld_dup ();
14941 break;
5f4273c7 14942
5287ad62 14943 default:
88714cb8 14944 NEON_ENCODE (LANE, inst);
5287ad62
JB
14945 do_neon_ld_st_lane ();
14946 }
14947
14948 /* L bit comes from bit mask. */
14949 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14950 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14951 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14952
5287ad62
JB
14953 if (inst.operands[1].postind)
14954 {
14955 int postreg = inst.operands[1].imm & 0xf;
14956 constraint (!inst.operands[1].immisreg,
14957 _("post-index must be a register"));
14958 constraint (postreg == 0xd || postreg == 0xf,
14959 _("bad register for post-index"));
14960 inst.instruction |= postreg;
14961 }
14962 else if (inst.operands[1].writeback)
14963 {
14964 inst.instruction |= 0xd;
14965 }
14966 else
5f4273c7
NC
14967 inst.instruction |= 0xf;
14968
5287ad62
JB
14969 if (thumb_mode)
14970 inst.instruction |= 0xf9000000;
14971 else
14972 inst.instruction |= 0xf4000000;
14973}
5287ad62
JB
14974\f
14975/* Overall per-instruction processing. */
14976
14977/* We need to be able to fix up arbitrary expressions in some statements.
14978 This is so that we can handle symbols that are an arbitrary distance from
14979 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14980 which returns part of an address in a form which will be valid for
14981 a data instruction. We do this by pushing the expression into a symbol
14982 in the expr_section, and creating a fix for that. */
14983
14984static void
14985fix_new_arm (fragS * frag,
14986 int where,
14987 short int size,
14988 expressionS * exp,
14989 int pc_rel,
14990 int reloc)
14991{
14992 fixS * new_fix;
14993
14994 switch (exp->X_op)
14995 {
14996 case O_constant:
14997 case O_symbol:
14998 case O_add:
14999 case O_subtract:
21d799b5
NC
15000 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15001 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15002 break;
15003
15004 default:
21d799b5
NC
15005 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15006 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
15007 break;
15008 }
15009
15010 /* Mark whether the fix is to a THUMB instruction, or an ARM
15011 instruction. */
15012 new_fix->tc_fix_data = thumb_mode;
15013}
15014
15015/* Create a frg for an instruction requiring relaxation. */
15016static void
15017output_relax_insn (void)
15018{
15019 char * to;
15020 symbolS *sym;
0110f2b8
PB
15021 int offset;
15022
6e1cb1a6
PB
15023 /* The size of the instruction is unknown, so tie the debug info to the
15024 start of the instruction. */
15025 dwarf2_emit_insn (0);
6e1cb1a6 15026
0110f2b8
PB
15027 switch (inst.reloc.exp.X_op)
15028 {
15029 case O_symbol:
15030 sym = inst.reloc.exp.X_add_symbol;
15031 offset = inst.reloc.exp.X_add_number;
15032 break;
15033 case O_constant:
15034 sym = NULL;
15035 offset = inst.reloc.exp.X_add_number;
15036 break;
15037 default:
15038 sym = make_expr_symbol (&inst.reloc.exp);
15039 offset = 0;
15040 break;
15041 }
15042 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15043 inst.relax, sym, offset, NULL/*offset, opcode*/);
15044 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15045}
15046
15047/* Write a 32-bit thumb instruction to buf. */
15048static void
15049put_thumb32_insn (char * buf, unsigned long insn)
15050{
15051 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15052 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15053}
15054
b99bd4ef 15055static void
c19d1205 15056output_inst (const char * str)
b99bd4ef 15057{
c19d1205 15058 char * to = NULL;
b99bd4ef 15059
c19d1205 15060 if (inst.error)
b99bd4ef 15061 {
c19d1205 15062 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15063 return;
15064 }
5f4273c7
NC
15065 if (inst.relax)
15066 {
15067 output_relax_insn ();
0110f2b8 15068 return;
5f4273c7 15069 }
c19d1205
ZW
15070 if (inst.size == 0)
15071 return;
b99bd4ef 15072
c19d1205 15073 to = frag_more (inst.size);
8dc2430f
NC
15074 /* PR 9814: Record the thumb mode into the current frag so that we know
15075 what type of NOP padding to use, if necessary. We override any previous
15076 setting so that if the mode has changed then the NOPS that we use will
15077 match the encoding of the last instruction in the frag. */
cd000bff 15078 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15079
15080 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15081 {
9c2799c2 15082 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15083 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15084 }
c19d1205 15085 else if (inst.size > INSN_SIZE)
b99bd4ef 15086 {
9c2799c2 15087 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15088 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15089 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15090 }
c19d1205
ZW
15091 else
15092 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15093
c19d1205
ZW
15094 if (inst.reloc.type != BFD_RELOC_UNUSED)
15095 fix_new_arm (frag_now, to - frag_now->fr_literal,
15096 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15097 inst.reloc.type);
b99bd4ef 15098
c19d1205 15099 dwarf2_emit_insn (inst.size);
c19d1205 15100}
b99bd4ef 15101
e07e6e58
NC
15102static char *
15103output_it_inst (int cond, int mask, char * to)
15104{
15105 unsigned long instruction = 0xbf00;
15106
15107 mask &= 0xf;
15108 instruction |= mask;
15109 instruction |= cond << 4;
15110
15111 if (to == NULL)
15112 {
15113 to = frag_more (2);
15114#ifdef OBJ_ELF
15115 dwarf2_emit_insn (2);
15116#endif
15117 }
15118
15119 md_number_to_chars (to, instruction, 2);
15120
15121 return to;
15122}
15123
c19d1205
ZW
15124/* Tag values used in struct asm_opcode's tag field. */
15125enum opcode_tag
15126{
15127 OT_unconditional, /* Instruction cannot be conditionalized.
15128 The ARM condition field is still 0xE. */
15129 OT_unconditionalF, /* Instruction cannot be conditionalized
15130 and carries 0xF in its ARM condition field. */
15131 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15132 OT_csuffixF, /* Some forms of the instruction take a conditional
15133 suffix, others place 0xF where the condition field
15134 would be. */
c19d1205
ZW
15135 OT_cinfix3, /* Instruction takes a conditional infix,
15136 beginning at character index 3. (In
15137 unified mode, it becomes a suffix.) */
088fa78e
KH
15138 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15139 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15140 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15141 character index 3, even in unified mode. Used for
15142 legacy instructions where suffix and infix forms
15143 may be ambiguous. */
c19d1205 15144 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15145 suffix or an infix at character index 3. */
c19d1205
ZW
15146 OT_odd_infix_unc, /* This is the unconditional variant of an
15147 instruction that takes a conditional infix
15148 at an unusual position. In unified mode,
15149 this variant will accept a suffix. */
15150 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15151 are the conditional variants of instructions that
15152 take conditional infixes in unusual positions.
15153 The infix appears at character index
15154 (tag - OT_odd_infix_0). These are not accepted
15155 in unified mode. */
15156};
b99bd4ef 15157
c19d1205
ZW
15158/* Subroutine of md_assemble, responsible for looking up the primary
15159 opcode from the mnemonic the user wrote. STR points to the
15160 beginning of the mnemonic.
15161
15162 This is not simply a hash table lookup, because of conditional
15163 variants. Most instructions have conditional variants, which are
15164 expressed with a _conditional affix_ to the mnemonic. If we were
15165 to encode each conditional variant as a literal string in the opcode
15166 table, it would have approximately 20,000 entries.
15167
15168 Most mnemonics take this affix as a suffix, and in unified syntax,
15169 'most' is upgraded to 'all'. However, in the divided syntax, some
15170 instructions take the affix as an infix, notably the s-variants of
15171 the arithmetic instructions. Of those instructions, all but six
15172 have the infix appear after the third character of the mnemonic.
15173
15174 Accordingly, the algorithm for looking up primary opcodes given
15175 an identifier is:
15176
15177 1. Look up the identifier in the opcode table.
15178 If we find a match, go to step U.
15179
15180 2. Look up the last two characters of the identifier in the
15181 conditions table. If we find a match, look up the first N-2
15182 characters of the identifier in the opcode table. If we
15183 find a match, go to step CE.
15184
15185 3. Look up the fourth and fifth characters of the identifier in
15186 the conditions table. If we find a match, extract those
15187 characters from the identifier, and look up the remaining
15188 characters in the opcode table. If we find a match, go
15189 to step CM.
15190
15191 4. Fail.
15192
15193 U. Examine the tag field of the opcode structure, in case this is
15194 one of the six instructions with its conditional infix in an
15195 unusual place. If it is, the tag tells us where to find the
15196 infix; look it up in the conditions table and set inst.cond
15197 accordingly. Otherwise, this is an unconditional instruction.
15198 Again set inst.cond accordingly. Return the opcode structure.
15199
15200 CE. Examine the tag field to make sure this is an instruction that
15201 should receive a conditional suffix. If it is not, fail.
15202 Otherwise, set inst.cond from the suffix we already looked up,
15203 and return the opcode structure.
15204
15205 CM. Examine the tag field to make sure this is an instruction that
15206 should receive a conditional infix after the third character.
15207 If it is not, fail. Otherwise, undo the edits to the current
15208 line of input and proceed as for case CE. */
15209
15210static const struct asm_opcode *
15211opcode_lookup (char **str)
15212{
15213 char *end, *base;
15214 char *affix;
15215 const struct asm_opcode *opcode;
15216 const struct asm_cond *cond;
e3cb604e 15217 char save[2];
c19d1205
ZW
15218
15219 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15220 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15221 for (base = end = *str; *end != '\0'; end++)
721a8186 15222 if (*end == ' ' || *end == '.')
c19d1205 15223 break;
b99bd4ef 15224
c19d1205 15225 if (end == base)
c921be7d 15226 return NULL;
b99bd4ef 15227
5287ad62 15228 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15229 if (end[0] == '.')
b99bd4ef 15230 {
5287ad62 15231 int offset = 2;
5f4273c7 15232
267d2029
JB
15233 /* The .w and .n suffixes are only valid if the unified syntax is in
15234 use. */
15235 if (unified_syntax && end[1] == 'w')
c19d1205 15236 inst.size_req = 4;
267d2029 15237 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15238 inst.size_req = 2;
15239 else
5287ad62
JB
15240 offset = 0;
15241
15242 inst.vectype.elems = 0;
15243
15244 *str = end + offset;
b99bd4ef 15245
5f4273c7 15246 if (end[offset] == '.')
5287ad62 15247 {
267d2029
JB
15248 /* See if we have a Neon type suffix (possible in either unified or
15249 non-unified ARM syntax mode). */
dcbf9037 15250 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15251 return NULL;
5287ad62
JB
15252 }
15253 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15254 return NULL;
b99bd4ef 15255 }
c19d1205
ZW
15256 else
15257 *str = end;
b99bd4ef 15258
c19d1205 15259 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15260 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15261 end - base);
c19d1205 15262 if (opcode)
b99bd4ef 15263 {
c19d1205
ZW
15264 /* step U */
15265 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15266 {
c19d1205
ZW
15267 inst.cond = COND_ALWAYS;
15268 return opcode;
b99bd4ef 15269 }
b99bd4ef 15270
278df34e 15271 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15272 as_warn (_("conditional infixes are deprecated in unified syntax"));
15273 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15274 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15275 gas_assert (cond);
b99bd4ef 15276
c19d1205
ZW
15277 inst.cond = cond->value;
15278 return opcode;
15279 }
b99bd4ef 15280
c19d1205
ZW
15281 /* Cannot have a conditional suffix on a mnemonic of less than two
15282 characters. */
15283 if (end - base < 3)
c921be7d 15284 return NULL;
b99bd4ef 15285
c19d1205
ZW
15286 /* Look for suffixed mnemonic. */
15287 affix = end - 2;
21d799b5
NC
15288 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15289 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15290 affix - base);
c19d1205
ZW
15291 if (opcode && cond)
15292 {
15293 /* step CE */
15294 switch (opcode->tag)
15295 {
e3cb604e
PB
15296 case OT_cinfix3_legacy:
15297 /* Ignore conditional suffixes matched on infix only mnemonics. */
15298 break;
15299
c19d1205 15300 case OT_cinfix3:
088fa78e 15301 case OT_cinfix3_deprecated:
c19d1205
ZW
15302 case OT_odd_infix_unc:
15303 if (!unified_syntax)
e3cb604e 15304 return 0;
c19d1205
ZW
15305 /* else fall through */
15306
15307 case OT_csuffix:
037e8744 15308 case OT_csuffixF:
c19d1205
ZW
15309 case OT_csuf_or_in3:
15310 inst.cond = cond->value;
15311 return opcode;
15312
15313 case OT_unconditional:
15314 case OT_unconditionalF:
dfa9f0d5 15315 if (thumb_mode)
c921be7d 15316 inst.cond = cond->value;
dfa9f0d5
PB
15317 else
15318 {
c921be7d 15319 /* Delayed diagnostic. */
dfa9f0d5
PB
15320 inst.error = BAD_COND;
15321 inst.cond = COND_ALWAYS;
15322 }
c19d1205 15323 return opcode;
b99bd4ef 15324
c19d1205 15325 default:
c921be7d 15326 return NULL;
c19d1205
ZW
15327 }
15328 }
b99bd4ef 15329
c19d1205
ZW
15330 /* Cannot have a usual-position infix on a mnemonic of less than
15331 six characters (five would be a suffix). */
15332 if (end - base < 6)
c921be7d 15333 return NULL;
b99bd4ef 15334
c19d1205
ZW
15335 /* Look for infixed mnemonic in the usual position. */
15336 affix = base + 3;
21d799b5 15337 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15338 if (!cond)
c921be7d 15339 return NULL;
e3cb604e
PB
15340
15341 memcpy (save, affix, 2);
15342 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15343 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15344 (end - base) - 2);
e3cb604e
PB
15345 memmove (affix + 2, affix, (end - affix) - 2);
15346 memcpy (affix, save, 2);
15347
088fa78e
KH
15348 if (opcode
15349 && (opcode->tag == OT_cinfix3
15350 || opcode->tag == OT_cinfix3_deprecated
15351 || opcode->tag == OT_csuf_or_in3
15352 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15353 {
c921be7d 15354 /* Step CM. */
278df34e 15355 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15356 && (opcode->tag == OT_cinfix3
15357 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15358 as_warn (_("conditional infixes are deprecated in unified syntax"));
15359
15360 inst.cond = cond->value;
15361 return opcode;
b99bd4ef
NC
15362 }
15363
c921be7d 15364 return NULL;
b99bd4ef
NC
15365}
15366
e07e6e58
NC
15367/* This function generates an initial IT instruction, leaving its block
15368 virtually open for the new instructions. Eventually,
15369 the mask will be updated by now_it_add_mask () each time
15370 a new instruction needs to be included in the IT block.
15371 Finally, the block is closed with close_automatic_it_block ().
15372 The block closure can be requested either from md_assemble (),
15373 a tencode (), or due to a label hook. */
15374
15375static void
15376new_automatic_it_block (int cond)
15377{
15378 now_it.state = AUTOMATIC_IT_BLOCK;
15379 now_it.mask = 0x18;
15380 now_it.cc = cond;
15381 now_it.block_length = 1;
cd000bff 15382 mapping_state (MAP_THUMB);
e07e6e58
NC
15383 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15384}
15385
15386/* Close an automatic IT block.
15387 See comments in new_automatic_it_block (). */
15388
15389static void
15390close_automatic_it_block (void)
15391{
15392 now_it.mask = 0x10;
15393 now_it.block_length = 0;
15394}
15395
15396/* Update the mask of the current automatically-generated IT
15397 instruction. See comments in new_automatic_it_block (). */
15398
15399static void
15400now_it_add_mask (int cond)
15401{
15402#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15403#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15404 | ((bitvalue) << (nbit)))
e07e6e58 15405 const int resulting_bit = (cond & 1);
c921be7d 15406
e07e6e58
NC
15407 now_it.mask &= 0xf;
15408 now_it.mask = SET_BIT_VALUE (now_it.mask,
15409 resulting_bit,
15410 (5 - now_it.block_length));
15411 now_it.mask = SET_BIT_VALUE (now_it.mask,
15412 1,
15413 ((5 - now_it.block_length) - 1) );
15414 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15415
15416#undef CLEAR_BIT
15417#undef SET_BIT_VALUE
e07e6e58
NC
15418}
15419
15420/* The IT blocks handling machinery is accessed through the these functions:
15421 it_fsm_pre_encode () from md_assemble ()
15422 set_it_insn_type () optional, from the tencode functions
15423 set_it_insn_type_last () ditto
15424 in_it_block () ditto
15425 it_fsm_post_encode () from md_assemble ()
15426 force_automatic_it_block_close () from label habdling functions
15427
15428 Rationale:
15429 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15430 initializing the IT insn type with a generic initial value depending
15431 on the inst.condition.
15432 2) During the tencode function, two things may happen:
15433 a) The tencode function overrides the IT insn type by
15434 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15435 b) The tencode function queries the IT block state by
15436 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15437
15438 Both set_it_insn_type and in_it_block run the internal FSM state
15439 handling function (handle_it_state), because: a) setting the IT insn
15440 type may incur in an invalid state (exiting the function),
15441 and b) querying the state requires the FSM to be updated.
15442 Specifically we want to avoid creating an IT block for conditional
15443 branches, so it_fsm_pre_encode is actually a guess and we can't
15444 determine whether an IT block is required until the tencode () routine
15445 has decided what type of instruction this actually it.
15446 Because of this, if set_it_insn_type and in_it_block have to be used,
15447 set_it_insn_type has to be called first.
15448
15449 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15450 determines the insn IT type depending on the inst.cond code.
15451 When a tencode () routine encodes an instruction that can be
15452 either outside an IT block, or, in the case of being inside, has to be
15453 the last one, set_it_insn_type_last () will determine the proper
15454 IT instruction type based on the inst.cond code. Otherwise,
15455 set_it_insn_type can be called for overriding that logic or
15456 for covering other cases.
15457
15458 Calling handle_it_state () may not transition the IT block state to
15459 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15460 still queried. Instead, if the FSM determines that the state should
15461 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15462 after the tencode () function: that's what it_fsm_post_encode () does.
15463
15464 Since in_it_block () calls the state handling function to get an
15465 updated state, an error may occur (due to invalid insns combination).
15466 In that case, inst.error is set.
15467 Therefore, inst.error has to be checked after the execution of
15468 the tencode () routine.
15469
15470 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15471 any pending state change (if any) that didn't take place in
15472 handle_it_state () as explained above. */
15473
15474static void
15475it_fsm_pre_encode (void)
15476{
15477 if (inst.cond != COND_ALWAYS)
15478 inst.it_insn_type = INSIDE_IT_INSN;
15479 else
15480 inst.it_insn_type = OUTSIDE_IT_INSN;
15481
15482 now_it.state_handled = 0;
15483}
15484
15485/* IT state FSM handling function. */
15486
15487static int
15488handle_it_state (void)
15489{
15490 now_it.state_handled = 1;
15491
15492 switch (now_it.state)
15493 {
15494 case OUTSIDE_IT_BLOCK:
15495 switch (inst.it_insn_type)
15496 {
15497 case OUTSIDE_IT_INSN:
15498 break;
15499
15500 case INSIDE_IT_INSN:
15501 case INSIDE_IT_LAST_INSN:
15502 if (thumb_mode == 0)
15503 {
c921be7d 15504 if (unified_syntax
e07e6e58
NC
15505 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15506 as_tsktsk (_("Warning: conditional outside an IT block"\
15507 " for Thumb."));
15508 }
15509 else
15510 {
15511 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15512 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15513 {
15514 /* Automatically generate the IT instruction. */
15515 new_automatic_it_block (inst.cond);
15516 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15517 close_automatic_it_block ();
15518 }
15519 else
15520 {
15521 inst.error = BAD_OUT_IT;
15522 return FAIL;
15523 }
15524 }
15525 break;
15526
15527 case IF_INSIDE_IT_LAST_INSN:
15528 case NEUTRAL_IT_INSN:
15529 break;
15530
15531 case IT_INSN:
15532 now_it.state = MANUAL_IT_BLOCK;
15533 now_it.block_length = 0;
15534 break;
15535 }
15536 break;
15537
15538 case AUTOMATIC_IT_BLOCK:
15539 /* Three things may happen now:
15540 a) We should increment current it block size;
15541 b) We should close current it block (closing insn or 4 insns);
15542 c) We should close current it block and start a new one (due
15543 to incompatible conditions or
15544 4 insns-length block reached). */
15545
15546 switch (inst.it_insn_type)
15547 {
15548 case OUTSIDE_IT_INSN:
15549 /* The closure of the block shall happen immediatelly,
15550 so any in_it_block () call reports the block as closed. */
15551 force_automatic_it_block_close ();
15552 break;
15553
15554 case INSIDE_IT_INSN:
15555 case INSIDE_IT_LAST_INSN:
15556 case IF_INSIDE_IT_LAST_INSN:
15557 now_it.block_length++;
15558
15559 if (now_it.block_length > 4
15560 || !now_it_compatible (inst.cond))
15561 {
15562 force_automatic_it_block_close ();
15563 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15564 new_automatic_it_block (inst.cond);
15565 }
15566 else
15567 {
15568 now_it_add_mask (inst.cond);
15569 }
15570
15571 if (now_it.state == AUTOMATIC_IT_BLOCK
15572 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15573 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15574 close_automatic_it_block ();
15575 break;
15576
15577 case NEUTRAL_IT_INSN:
15578 now_it.block_length++;
15579
15580 if (now_it.block_length > 4)
15581 force_automatic_it_block_close ();
15582 else
15583 now_it_add_mask (now_it.cc & 1);
15584 break;
15585
15586 case IT_INSN:
15587 close_automatic_it_block ();
15588 now_it.state = MANUAL_IT_BLOCK;
15589 break;
15590 }
15591 break;
15592
15593 case MANUAL_IT_BLOCK:
15594 {
15595 /* Check conditional suffixes. */
15596 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15597 int is_last;
15598 now_it.mask <<= 1;
15599 now_it.mask &= 0x1f;
15600 is_last = (now_it.mask == 0x10);
15601
15602 switch (inst.it_insn_type)
15603 {
15604 case OUTSIDE_IT_INSN:
15605 inst.error = BAD_NOT_IT;
15606 return FAIL;
15607
15608 case INSIDE_IT_INSN:
15609 if (cond != inst.cond)
15610 {
15611 inst.error = BAD_IT_COND;
15612 return FAIL;
15613 }
15614 break;
15615
15616 case INSIDE_IT_LAST_INSN:
15617 case IF_INSIDE_IT_LAST_INSN:
15618 if (cond != inst.cond)
15619 {
15620 inst.error = BAD_IT_COND;
15621 return FAIL;
15622 }
15623 if (!is_last)
15624 {
15625 inst.error = BAD_BRANCH;
15626 return FAIL;
15627 }
15628 break;
15629
15630 case NEUTRAL_IT_INSN:
15631 /* The BKPT instruction is unconditional even in an IT block. */
15632 break;
15633
15634 case IT_INSN:
15635 inst.error = BAD_IT_IT;
15636 return FAIL;
15637 }
15638 }
15639 break;
15640 }
15641
15642 return SUCCESS;
15643}
15644
15645static void
15646it_fsm_post_encode (void)
15647{
15648 int is_last;
15649
15650 if (!now_it.state_handled)
15651 handle_it_state ();
15652
15653 is_last = (now_it.mask == 0x10);
15654 if (is_last)
15655 {
15656 now_it.state = OUTSIDE_IT_BLOCK;
15657 now_it.mask = 0;
15658 }
15659}
15660
15661static void
15662force_automatic_it_block_close (void)
15663{
15664 if (now_it.state == AUTOMATIC_IT_BLOCK)
15665 {
15666 close_automatic_it_block ();
15667 now_it.state = OUTSIDE_IT_BLOCK;
15668 now_it.mask = 0;
15669 }
15670}
15671
15672static int
15673in_it_block (void)
15674{
15675 if (!now_it.state_handled)
15676 handle_it_state ();
15677
15678 return now_it.state != OUTSIDE_IT_BLOCK;
15679}
15680
c19d1205
ZW
15681void
15682md_assemble (char *str)
b99bd4ef 15683{
c19d1205
ZW
15684 char *p = str;
15685 const struct asm_opcode * opcode;
b99bd4ef 15686
c19d1205
ZW
15687 /* Align the previous label if needed. */
15688 if (last_label_seen != NULL)
b99bd4ef 15689 {
c19d1205
ZW
15690 symbol_set_frag (last_label_seen, frag_now);
15691 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15692 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15693 }
15694
c19d1205
ZW
15695 memset (&inst, '\0', sizeof (inst));
15696 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15697
c19d1205
ZW
15698 opcode = opcode_lookup (&p);
15699 if (!opcode)
b99bd4ef 15700 {
c19d1205 15701 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15702 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15703 if (! create_register_alias (str, p)
15704 && ! create_neon_reg_alias (str, p))
c19d1205 15705 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15706
b99bd4ef
NC
15707 return;
15708 }
15709
278df34e 15710 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15711 as_warn (_("s suffix on comparison instruction is deprecated"));
15712
037e8744
JB
15713 /* The value which unconditional instructions should have in place of the
15714 condition field. */
15715 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15716
c19d1205 15717 if (thumb_mode)
b99bd4ef 15718 {
e74cfd16 15719 arm_feature_set variant;
8f06b2d8
PB
15720
15721 variant = cpu_variant;
15722 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15723 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15724 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15725 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15726 if (!opcode->tvariant
15727 || (thumb_mode == 1
15728 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15729 {
bf3eeda7 15730 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
15731 return;
15732 }
c19d1205
ZW
15733 if (inst.cond != COND_ALWAYS && !unified_syntax
15734 && opcode->tencode != do_t_branch)
b99bd4ef 15735 {
c19d1205 15736 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15737 return;
15738 }
15739
752d5da4 15740 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15741 {
7e806470 15742 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15743 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15744 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15745 {
15746 /* Two things are addressed here.
15747 1) Implicit require narrow instructions on Thumb-1.
15748 This avoids relaxation accidentally introducing Thumb-2
15749 instructions.
15750 2) Reject wide instructions in non Thumb-2 cores. */
15751 if (inst.size_req == 0)
15752 inst.size_req = 2;
15753 else if (inst.size_req == 4)
15754 {
bf3eeda7 15755 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
15756 return;
15757 }
15758 }
076d447c
PB
15759 }
15760
c19d1205
ZW
15761 inst.instruction = opcode->tvalue;
15762
5be8be5d 15763 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
15764 {
15765 /* Prepare the it_insn_type for those encodings that don't set
15766 it. */
15767 it_fsm_pre_encode ();
c19d1205 15768
e07e6e58
NC
15769 opcode->tencode ();
15770
15771 it_fsm_post_encode ();
15772 }
e27ec89e 15773
0110f2b8 15774 if (!(inst.error || inst.relax))
b99bd4ef 15775 {
9c2799c2 15776 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15777 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15778 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15779 {
c19d1205 15780 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15781 return;
15782 }
15783 }
076d447c
PB
15784
15785 /* Something has gone badly wrong if we try to relax a fixed size
15786 instruction. */
9c2799c2 15787 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15788
e74cfd16
PB
15789 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15790 *opcode->tvariant);
ee065d83 15791 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15792 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15793 anything other than bl/blx and v6-M instructions.
ee065d83 15794 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15795 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15796 || inst.relax)
e07e6e58
NC
15797 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15798 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15799 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15800 arm_ext_v6t2);
cd000bff 15801
88714cb8
DG
15802 check_neon_suffixes;
15803
cd000bff 15804 if (!inst.error)
c877a2f2
NC
15805 {
15806 mapping_state (MAP_THUMB);
15807 }
c19d1205 15808 }
3e9e4fcf 15809 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15810 {
845b51d6
PB
15811 bfd_boolean is_bx;
15812
15813 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15814 is_bx = (opcode->aencode == do_bx);
15815
c19d1205 15816 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15817 if (!(is_bx && fix_v4bx)
15818 && !(opcode->avariant &&
15819 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15820 {
bf3eeda7 15821 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 15822 return;
b99bd4ef 15823 }
c19d1205 15824 if (inst.size_req)
b99bd4ef 15825 {
c19d1205
ZW
15826 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15827 return;
b99bd4ef
NC
15828 }
15829
c19d1205
ZW
15830 inst.instruction = opcode->avalue;
15831 if (opcode->tag == OT_unconditionalF)
15832 inst.instruction |= 0xF << 28;
15833 else
15834 inst.instruction |= inst.cond << 28;
15835 inst.size = INSN_SIZE;
5be8be5d 15836 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
15837 {
15838 it_fsm_pre_encode ();
15839 opcode->aencode ();
15840 it_fsm_post_encode ();
15841 }
ee065d83
PB
15842 /* Arm mode bx is marked as both v4T and v5 because it's still required
15843 on a hypothetical non-thumb v5 core. */
845b51d6 15844 if (is_bx)
e74cfd16 15845 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15846 else
e74cfd16
PB
15847 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15848 *opcode->avariant);
88714cb8
DG
15849
15850 check_neon_suffixes;
15851
cd000bff 15852 if (!inst.error)
c877a2f2
NC
15853 {
15854 mapping_state (MAP_ARM);
15855 }
b99bd4ef 15856 }
3e9e4fcf
JB
15857 else
15858 {
15859 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15860 "-- `%s'"), str);
15861 return;
15862 }
c19d1205
ZW
15863 output_inst (str);
15864}
b99bd4ef 15865
e07e6e58
NC
15866static void
15867check_it_blocks_finished (void)
15868{
15869#ifdef OBJ_ELF
15870 asection *sect;
15871
15872 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15873 if (seg_info (sect)->tc_segment_info_data.current_it.state
15874 == MANUAL_IT_BLOCK)
15875 {
15876 as_warn (_("section '%s' finished with an open IT block."),
15877 sect->name);
15878 }
15879#else
15880 if (now_it.state == MANUAL_IT_BLOCK)
15881 as_warn (_("file finished with an open IT block."));
15882#endif
15883}
15884
c19d1205
ZW
15885/* Various frobbings of labels and their addresses. */
15886
15887void
15888arm_start_line_hook (void)
15889{
15890 last_label_seen = NULL;
b99bd4ef
NC
15891}
15892
c19d1205
ZW
15893void
15894arm_frob_label (symbolS * sym)
b99bd4ef 15895{
c19d1205 15896 last_label_seen = sym;
b99bd4ef 15897
c19d1205 15898 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15899
c19d1205
ZW
15900#if defined OBJ_COFF || defined OBJ_ELF
15901 ARM_SET_INTERWORK (sym, support_interwork);
15902#endif
b99bd4ef 15903
e07e6e58
NC
15904 force_automatic_it_block_close ();
15905
5f4273c7 15906 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15907 as Thumb functions. This is because these labels, whilst
15908 they exist inside Thumb code, are not the entry points for
15909 possible ARM->Thumb calls. Also, these labels can be used
15910 as part of a computed goto or switch statement. eg gcc
15911 can generate code that looks like this:
b99bd4ef 15912
c19d1205
ZW
15913 ldr r2, [pc, .Laaa]
15914 lsl r3, r3, #2
15915 ldr r2, [r3, r2]
15916 mov pc, r2
b99bd4ef 15917
c19d1205
ZW
15918 .Lbbb: .word .Lxxx
15919 .Lccc: .word .Lyyy
15920 ..etc...
15921 .Laaa: .word Lbbb
b99bd4ef 15922
c19d1205
ZW
15923 The first instruction loads the address of the jump table.
15924 The second instruction converts a table index into a byte offset.
15925 The third instruction gets the jump address out of the table.
15926 The fourth instruction performs the jump.
b99bd4ef 15927
c19d1205
ZW
15928 If the address stored at .Laaa is that of a symbol which has the
15929 Thumb_Func bit set, then the linker will arrange for this address
15930 to have the bottom bit set, which in turn would mean that the
15931 address computation performed by the third instruction would end
15932 up with the bottom bit set. Since the ARM is capable of unaligned
15933 word loads, the instruction would then load the incorrect address
15934 out of the jump table, and chaos would ensue. */
15935 if (label_is_thumb_function_name
15936 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15937 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15938 {
c19d1205
ZW
15939 /* When the address of a Thumb function is taken the bottom
15940 bit of that address should be set. This will allow
15941 interworking between Arm and Thumb functions to work
15942 correctly. */
b99bd4ef 15943
c19d1205 15944 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15945
c19d1205 15946 label_is_thumb_function_name = FALSE;
b99bd4ef 15947 }
07a53e5c 15948
07a53e5c 15949 dwarf2_emit_label (sym);
b99bd4ef
NC
15950}
15951
c921be7d 15952bfd_boolean
c19d1205 15953arm_data_in_code (void)
b99bd4ef 15954{
c19d1205 15955 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15956 {
c19d1205
ZW
15957 *input_line_pointer = '/';
15958 input_line_pointer += 5;
15959 *input_line_pointer = 0;
c921be7d 15960 return TRUE;
b99bd4ef
NC
15961 }
15962
c921be7d 15963 return FALSE;
b99bd4ef
NC
15964}
15965
c19d1205
ZW
15966char *
15967arm_canonicalize_symbol_name (char * name)
b99bd4ef 15968{
c19d1205 15969 int len;
b99bd4ef 15970
c19d1205
ZW
15971 if (thumb_mode && (len = strlen (name)) > 5
15972 && streq (name + len - 5, "/data"))
15973 *(name + len - 5) = 0;
b99bd4ef 15974
c19d1205 15975 return name;
b99bd4ef 15976}
c19d1205
ZW
15977\f
15978/* Table of all register names defined by default. The user can
15979 define additional names with .req. Note that all register names
15980 should appear in both upper and lowercase variants. Some registers
15981 also have mixed-case names. */
b99bd4ef 15982
dcbf9037 15983#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15984#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15985#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15986#define REGSET(p,t) \
15987 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15988 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15989 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15990 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15991#define REGSETH(p,t) \
15992 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15993 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15994 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15995 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15996#define REGSET2(p,t) \
15997 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15998 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15999 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16000 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 16001
c19d1205 16002static const struct reg_entry reg_names[] =
7ed4c4c5 16003{
c19d1205
ZW
16004 /* ARM integer registers. */
16005 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 16006
c19d1205
ZW
16007 /* ATPCS synonyms. */
16008 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16009 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16010 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 16011
c19d1205
ZW
16012 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16013 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16014 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 16015
c19d1205
ZW
16016 /* Well-known aliases. */
16017 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16018 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16019
16020 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16021 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16022
16023 /* Coprocessor numbers. */
16024 REGSET(p, CP), REGSET(P, CP),
16025
16026 /* Coprocessor register numbers. The "cr" variants are for backward
16027 compatibility. */
16028 REGSET(c, CN), REGSET(C, CN),
16029 REGSET(cr, CN), REGSET(CR, CN),
16030
16031 /* FPA registers. */
16032 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16033 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16034
16035 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16036 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16037
16038 /* VFP SP registers. */
5287ad62
JB
16039 REGSET(s,VFS), REGSET(S,VFS),
16040 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16041
16042 /* VFP DP Registers. */
5287ad62
JB
16043 REGSET(d,VFD), REGSET(D,VFD),
16044 /* Extra Neon DP registers. */
16045 REGSETH(d,VFD), REGSETH(D,VFD),
16046
16047 /* Neon QP registers. */
16048 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16049
16050 /* VFP control registers. */
16051 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16052 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16053 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16054 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16055 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16056 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16057
16058 /* Maverick DSP coprocessor registers. */
16059 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16060 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16061
16062 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16063 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16064 REGDEF(dspsc,0,DSPSC),
16065
16066 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16067 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16068 REGDEF(DSPSC,0,DSPSC),
16069
16070 /* iWMMXt data registers - p0, c0-15. */
16071 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16072
16073 /* iWMMXt control registers - p1, c0-3. */
16074 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16075 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16076 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16077 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16078
16079 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16080 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16081 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16082 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16083 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16084
16085 /* XScale accumulator registers. */
16086 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16087};
16088#undef REGDEF
16089#undef REGNUM
16090#undef REGSET
7ed4c4c5 16091
c19d1205
ZW
16092/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16093 within psr_required_here. */
16094static const struct asm_psr psrs[] =
16095{
16096 /* Backward compatibility notation. Note that "all" is no longer
16097 truly all possible PSR bits. */
16098 {"all", PSR_c | PSR_f},
16099 {"flg", PSR_f},
16100 {"ctl", PSR_c},
16101
16102 /* Individual flags. */
16103 {"f", PSR_f},
16104 {"c", PSR_c},
16105 {"x", PSR_x},
16106 {"s", PSR_s},
16107 /* Combinations of flags. */
16108 {"fs", PSR_f | PSR_s},
16109 {"fx", PSR_f | PSR_x},
16110 {"fc", PSR_f | PSR_c},
16111 {"sf", PSR_s | PSR_f},
16112 {"sx", PSR_s | PSR_x},
16113 {"sc", PSR_s | PSR_c},
16114 {"xf", PSR_x | PSR_f},
16115 {"xs", PSR_x | PSR_s},
16116 {"xc", PSR_x | PSR_c},
16117 {"cf", PSR_c | PSR_f},
16118 {"cs", PSR_c | PSR_s},
16119 {"cx", PSR_c | PSR_x},
16120 {"fsx", PSR_f | PSR_s | PSR_x},
16121 {"fsc", PSR_f | PSR_s | PSR_c},
16122 {"fxs", PSR_f | PSR_x | PSR_s},
16123 {"fxc", PSR_f | PSR_x | PSR_c},
16124 {"fcs", PSR_f | PSR_c | PSR_s},
16125 {"fcx", PSR_f | PSR_c | PSR_x},
16126 {"sfx", PSR_s | PSR_f | PSR_x},
16127 {"sfc", PSR_s | PSR_f | PSR_c},
16128 {"sxf", PSR_s | PSR_x | PSR_f},
16129 {"sxc", PSR_s | PSR_x | PSR_c},
16130 {"scf", PSR_s | PSR_c | PSR_f},
16131 {"scx", PSR_s | PSR_c | PSR_x},
16132 {"xfs", PSR_x | PSR_f | PSR_s},
16133 {"xfc", PSR_x | PSR_f | PSR_c},
16134 {"xsf", PSR_x | PSR_s | PSR_f},
16135 {"xsc", PSR_x | PSR_s | PSR_c},
16136 {"xcf", PSR_x | PSR_c | PSR_f},
16137 {"xcs", PSR_x | PSR_c | PSR_s},
16138 {"cfs", PSR_c | PSR_f | PSR_s},
16139 {"cfx", PSR_c | PSR_f | PSR_x},
16140 {"csf", PSR_c | PSR_s | PSR_f},
16141 {"csx", PSR_c | PSR_s | PSR_x},
16142 {"cxf", PSR_c | PSR_x | PSR_f},
16143 {"cxs", PSR_c | PSR_x | PSR_s},
16144 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16145 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16146 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16147 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16148 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16149 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16150 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16151 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16152 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16153 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16154 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16155 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16156 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16157 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16158 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16159 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16160 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16161 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16162 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16163 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16164 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16165 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16166 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16167 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16168};
16169
62b3e311
PB
16170/* Table of V7M psr names. */
16171static const struct asm_psr v7m_psrs[] =
16172{
2b744c99
PB
16173 {"apsr", 0 }, {"APSR", 0 },
16174 {"iapsr", 1 }, {"IAPSR", 1 },
16175 {"eapsr", 2 }, {"EAPSR", 2 },
16176 {"psr", 3 }, {"PSR", 3 },
16177 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16178 {"ipsr", 5 }, {"IPSR", 5 },
16179 {"epsr", 6 }, {"EPSR", 6 },
16180 {"iepsr", 7 }, {"IEPSR", 7 },
16181 {"msp", 8 }, {"MSP", 8 },
16182 {"psp", 9 }, {"PSP", 9 },
16183 {"primask", 16}, {"PRIMASK", 16},
16184 {"basepri", 17}, {"BASEPRI", 17},
16185 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16186 {"faultmask", 19}, {"FAULTMASK", 19},
16187 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16188};
16189
c19d1205
ZW
16190/* Table of all shift-in-operand names. */
16191static const struct asm_shift_name shift_names [] =
b99bd4ef 16192{
c19d1205
ZW
16193 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16194 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16195 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16196 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16197 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16198 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16199};
b99bd4ef 16200
c19d1205
ZW
16201/* Table of all explicit relocation names. */
16202#ifdef OBJ_ELF
16203static struct reloc_entry reloc_names[] =
16204{
16205 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16206 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16207 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16208 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16209 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16210 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16211 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16212 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16213 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16214 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6
NC
16215 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16216 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
c19d1205
ZW
16217};
16218#endif
b99bd4ef 16219
c19d1205
ZW
16220/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16221static const struct asm_cond conds[] =
16222{
16223 {"eq", 0x0},
16224 {"ne", 0x1},
16225 {"cs", 0x2}, {"hs", 0x2},
16226 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16227 {"mi", 0x4},
16228 {"pl", 0x5},
16229 {"vs", 0x6},
16230 {"vc", 0x7},
16231 {"hi", 0x8},
16232 {"ls", 0x9},
16233 {"ge", 0xa},
16234 {"lt", 0xb},
16235 {"gt", 0xc},
16236 {"le", 0xd},
16237 {"al", 0xe}
16238};
bfae80f2 16239
62b3e311
PB
16240static struct asm_barrier_opt barrier_opt_names[] =
16241{
16242 { "sy", 0xf },
16243 { "un", 0x7 },
16244 { "st", 0xe },
16245 { "unst", 0x6 }
16246};
16247
c19d1205
ZW
16248/* Table of ARM-format instructions. */
16249
16250/* Macros for gluing together operand strings. N.B. In all cases
16251 other than OPS0, the trailing OP_stop comes from default
16252 zero-initialization of the unspecified elements of the array. */
16253#define OPS0() { OP_stop, }
16254#define OPS1(a) { OP_##a, }
16255#define OPS2(a,b) { OP_##a,OP_##b, }
16256#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16257#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16258#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16259#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16260
5be8be5d
DG
16261/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16262 This is useful when mixing operands for ARM and THUMB, i.e. using the
16263 MIX_ARM_THUMB_OPERANDS macro.
16264 In order to use these macros, prefix the number of operands with _
16265 e.g. _3. */
16266#define OPS_1(a) { a, }
16267#define OPS_2(a,b) { a,b, }
16268#define OPS_3(a,b,c) { a,b,c, }
16269#define OPS_4(a,b,c,d) { a,b,c,d, }
16270#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16271#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16272
c19d1205
ZW
16273/* These macros abstract out the exact format of the mnemonic table and
16274 save some repeated characters. */
16275
16276/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16277#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16278 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16279 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16280
16281/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16282 a T_MNEM_xyz enumerator. */
16283#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16284 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16285#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16286 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16287
16288/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16289 infix after the third character. */
16290#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16291 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16292 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16293#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16294 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16295 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16296#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16297 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16298#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16299 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16300#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16301 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16302#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16303 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16304
16305/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16306 appear in the condition table. */
16307#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16308 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16309 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16310
16311#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16312 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16313 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16314 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16315 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16316 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16317 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16318 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16319 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16320 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16321 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16322 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16323 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16324 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16325 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16326 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16327 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16328 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16329 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16330 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16331
16332#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16333 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16334#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16335 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16336
16337/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16338 field is still 0xE. Many of the Thumb variants can be executed
16339 conditionally, so this is checked separately. */
c19d1205 16340#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16341 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16342 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16343
16344/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16345 condition code field. */
16346#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16347 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16348 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16349
16350/* ARM-only variants of all the above. */
6a86118a 16351#define CE(mnem, op, nops, ops, ae) \
21d799b5 16352 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16353
16354#define C3(mnem, op, nops, ops, ae) \
16355 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16356
e3cb604e
PB
16357/* Legacy mnemonics that always have conditional infix after the third
16358 character. */
16359#define CL(mnem, op, nops, ops, ae) \
21d799b5 16360 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16361 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16362
8f06b2d8
PB
16363/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16364#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16365 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16366
e3cb604e
PB
16367/* Legacy coprocessor instructions where conditional infix and conditional
16368 suffix are ambiguous. For consistency this includes all FPA instructions,
16369 not just the potentially ambiguous ones. */
16370#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16371 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16372 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16373
16374/* Coprocessor, takes either a suffix or a position-3 infix
16375 (for an FPA corner case). */
16376#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16377 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16378 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16379
6a86118a 16380#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16381 { m1 #m2 m3, OPS##nops ops, \
16382 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16383 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16384
16385#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16386 xCM_ (m1, , m2, op, nops, ops, ae), \
16387 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16388 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16389 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16390 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16391 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16392 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16393 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16394 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16395 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16396 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16397 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16398 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16399 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16400 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16401 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16402 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16403 xCM_ (m1, le, m2, op, nops, ops, ae), \
16404 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16405
16406#define UE(mnem, op, nops, ops, ae) \
16407 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16408
16409#define UF(mnem, op, nops, ops, ae) \
16410 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16411
5287ad62
JB
16412/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16413 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16414 use the same encoding function for each. */
16415#define NUF(mnem, op, nops, ops, enc) \
16416 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16417 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16418
16419/* Neon data processing, version which indirects through neon_enc_tab for
16420 the various overloaded versions of opcodes. */
16421#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16422 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16423 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16424
16425/* Neon insn with conditional suffix for the ARM version, non-overloaded
16426 version. */
037e8744
JB
16427#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16428 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16429 THUMB_VARIANT, do_##enc, do_##enc }
16430
037e8744 16431#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16432 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16433
16434#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16435 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16436
5287ad62 16437/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16438#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16439 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16440 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16441
037e8744 16442#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16443 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16444
16445#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16446 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16447
c19d1205
ZW
16448#define do_0 0
16449
c19d1205 16450static const struct asm_opcode insns[] =
bfae80f2 16451{
e74cfd16
PB
16452#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16453#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16454 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16455 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16456 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16457 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16458 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16459 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16460 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16461 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16462 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16463 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16464 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16465 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16466 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16467 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16468 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16469 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16470
16471 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16472 for setting PSR flag bits. They are obsolete in V6 and do not
16473 have Thumb equivalents. */
21d799b5
NC
16474 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16475 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16476 CL("tstp", 110f000, 2, (RR, SH), cmp),
16477 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16478 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16479 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16480 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16481 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16482 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16483
16484 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16485 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16486 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16487 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16488
16489 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16490 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16491 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16492 OP_RRnpc),
16493 OP_ADDRGLDR),ldst, t_ldst),
16494 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16495
16496 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16497 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16498 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16499 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16500 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16501 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16502
16503 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16504 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16505 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16506 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16507
c19d1205 16508 /* Pseudo ops. */
21d799b5 16509 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16510 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16511 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16512
16513 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16514 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16515 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16516 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16517 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16518 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16519 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16520 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16521 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16522 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16523 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16524 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16525 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16526
16a4cf17 16527 /* These may simplify to neg. */
21d799b5
NC
16528 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16529 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16530
c921be7d
NC
16531#undef THUMB_VARIANT
16532#define THUMB_VARIANT & arm_ext_v6
16533
21d799b5 16534 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16535
16536 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16537#undef THUMB_VARIANT
16538#define THUMB_VARIANT & arm_ext_v6t2
16539
21d799b5
NC
16540 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16541 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16542 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16543
5be8be5d
DG
16544 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16545 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16546 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16547 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16548
21d799b5
NC
16549 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16550 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16551
21d799b5
NC
16552 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16553 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16554
16555 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16556 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16557 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16558
16559 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16560 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16561 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16562 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16563 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16564 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16565 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16566 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16567
c921be7d
NC
16568#undef ARM_VARIANT
16569#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16570#undef THUMB_VARIANT
16571#define THUMB_VARIANT & arm_ext_v4t
16572
21d799b5
NC
16573 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16574 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16575
c921be7d
NC
16576#undef THUMB_VARIANT
16577#define THUMB_VARIANT & arm_ext_v6t2
16578
21d799b5 16579 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16580 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16581
16582 /* Generic coprocessor instructions. */
21d799b5
NC
16583 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16584 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16585 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16586 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16587 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16588 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16589 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16590
c921be7d
NC
16591#undef ARM_VARIANT
16592#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16593
21d799b5 16594 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16595 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16596
c921be7d
NC
16597#undef ARM_VARIANT
16598#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16599#undef THUMB_VARIANT
16600#define THUMB_VARIANT & arm_ext_msr
16601
21d799b5
NC
16602 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16603 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16604
c921be7d
NC
16605#undef ARM_VARIANT
16606#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16607#undef THUMB_VARIANT
16608#define THUMB_VARIANT & arm_ext_v6t2
16609
21d799b5
NC
16610 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16611 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16612 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16613 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16614 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16615 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16616 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16617 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16618
c921be7d
NC
16619#undef ARM_VARIANT
16620#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16621#undef THUMB_VARIANT
16622#define THUMB_VARIANT & arm_ext_v4t
16623
5be8be5d
DG
16624 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16625 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16626 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16627 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16628 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16629 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16630
c921be7d
NC
16631#undef ARM_VARIANT
16632#define ARM_VARIANT & arm_ext_v4t_5
16633
c19d1205
ZW
16634 /* ARM Architecture 4T. */
16635 /* Note: bx (and blx) are required on V5, even if the processor does
16636 not support Thumb. */
21d799b5 16637 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16638
c921be7d
NC
16639#undef ARM_VARIANT
16640#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16641#undef THUMB_VARIANT
16642#define THUMB_VARIANT & arm_ext_v5t
16643
c19d1205
ZW
16644 /* Note: blx has 2 variants; the .value coded here is for
16645 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16646 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16647 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16648
c921be7d
NC
16649#undef THUMB_VARIANT
16650#define THUMB_VARIANT & arm_ext_v6t2
16651
21d799b5
NC
16652 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16653 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16654 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16655 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16656 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16657 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16658 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16659 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16660
c921be7d
NC
16661#undef ARM_VARIANT
16662#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16663#undef THUMB_VARIANT
16664#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16665
21d799b5
NC
16666 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16667 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16668 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16669 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16670
21d799b5
NC
16671 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16672 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16673
21d799b5
NC
16674 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16675 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16676 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16677 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16678
21d799b5
NC
16679 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16680 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16681 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16682 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16683
21d799b5
NC
16684 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16685 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16686
03ee1b7f
NC
16687 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16688 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16689 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16690 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16691
c921be7d
NC
16692#undef ARM_VARIANT
16693#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16694#undef THUMB_VARIANT
16695#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16696
21d799b5 16697 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
16698 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16699 ldrd, t_ldstd),
16700 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16701 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16702
21d799b5
NC
16703 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16704 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16705
c921be7d
NC
16706#undef ARM_VARIANT
16707#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16708
21d799b5 16709 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16710
c921be7d
NC
16711#undef ARM_VARIANT
16712#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16713#undef THUMB_VARIANT
16714#define THUMB_VARIANT & arm_ext_v6
16715
21d799b5
NC
16716 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16717 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16718 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16719 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16720 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16721 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16722 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16723 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16724 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16725 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16726
c921be7d
NC
16727#undef THUMB_VARIANT
16728#define THUMB_VARIANT & arm_ext_v6t2
16729
5be8be5d
DG
16730 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16731 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16732 strex, t_strex),
21d799b5
NC
16733 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16734 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16735
21d799b5
NC
16736 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16737 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16738
9e3c6df6 16739/* ARM V6 not included in V7M. */
c921be7d
NC
16740#undef THUMB_VARIANT
16741#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16742 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16743 UF(rfeib, 9900a00, 1, (RRw), rfe),
16744 UF(rfeda, 8100a00, 1, (RRw), rfe),
16745 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16746 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16747 UF(rfefa, 9900a00, 1, (RRw), rfe),
16748 UF(rfeea, 8100a00, 1, (RRw), rfe),
16749 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16750 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16751 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16752 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16753 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16754
9e3c6df6
PB
16755/* ARM V6 not included in V7M (eg. integer SIMD). */
16756#undef THUMB_VARIANT
16757#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16758 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16759 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16760 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16761 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16762 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16763 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16764 /* Old name for QASX. */
21d799b5
NC
16765 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16766 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16767 /* Old name for QSAX. */
21d799b5
NC
16768 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16769 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16770 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16771 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16772 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16773 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16774 /* Old name for SASX. */
21d799b5
NC
16775 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16776 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16777 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16778 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16779 /* Old name for SHASX. */
21d799b5
NC
16780 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16781 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16782 /* Old name for SHSAX. */
21d799b5
NC
16783 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16784 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16785 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16786 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16787 /* Old name for SSAX. */
21d799b5
NC
16788 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16789 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16790 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16791 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16792 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16793 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16794 /* Old name for UASX. */
21d799b5
NC
16795 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16796 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16797 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16798 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16799 /* Old name for UHASX. */
21d799b5
NC
16800 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16801 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16802 /* Old name for UHSAX. */
21d799b5
NC
16803 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16804 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16805 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16806 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16807 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16808 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16809 /* Old name for UQASX. */
21d799b5
NC
16810 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16811 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16812 /* Old name for UQSAX. */
21d799b5
NC
16813 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16814 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16815 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16816 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16817 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16818 /* Old name for USAX. */
21d799b5
NC
16819 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16820 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16821 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16822 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16823 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16824 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16825 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16826 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16827 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16828 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16829 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16830 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16831 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16832 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16833 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16834 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16835 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16836 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16837 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16838 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16839 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16840 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16841 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16842 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16843 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16844 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16845 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16846 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16847 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
16848 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16849 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16850 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16851 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16852 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 16853
c921be7d
NC
16854#undef ARM_VARIANT
16855#define ARM_VARIANT & arm_ext_v6k
16856#undef THUMB_VARIANT
16857#define THUMB_VARIANT & arm_ext_v6k
16858
21d799b5
NC
16859 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16860 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16861 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16862 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 16863
c921be7d
NC
16864#undef THUMB_VARIANT
16865#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
16866 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16867 ldrexd, t_ldrexd),
16868 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16869 RRnpcb), strexd, t_strexd),
ebdca51a 16870
c921be7d
NC
16871#undef THUMB_VARIANT
16872#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
16873 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16874 rd_rn, rd_rn),
16875 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16876 rd_rn, rd_rn),
16877 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16878 strex, rm_rd_rn),
16879 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16880 strex, rm_rd_rn),
21d799b5 16881 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 16882
c921be7d
NC
16883#undef ARM_VARIANT
16884#define ARM_VARIANT & arm_ext_v6z
16885
21d799b5 16886 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 16887
c921be7d
NC
16888#undef ARM_VARIANT
16889#define ARM_VARIANT & arm_ext_v6t2
16890
21d799b5
NC
16891 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16892 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16893 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16894 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 16895
21d799b5
NC
16896 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16897 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16898 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16899 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 16900
5be8be5d
DG
16901 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16902 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16903 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16904 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 16905
bf3eeda7
NS
16906 /* Thumb-only instructions. */
16907#undef ARM_VARIANT
16908#define ARM_VARIANT NULL
16909 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
16910 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
16911
16912 /* ARM does not really have an IT instruction, so always allow it.
16913 The opcode is copied from Thumb in order to allow warnings in
16914 -mimplicit-it=[never | arm] modes. */
16915#undef ARM_VARIANT
16916#define ARM_VARIANT & arm_ext_v1
16917
21d799b5
NC
16918 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16919 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16920 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16921 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16922 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16923 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16924 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16925 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16926 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16927 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16928 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16929 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16930 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16931 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16932 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 16933 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
16934 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16935 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16936
92e90b6e 16937 /* Thumb2 only instructions. */
c921be7d
NC
16938#undef ARM_VARIANT
16939#define ARM_VARIANT NULL
92e90b6e 16940
21d799b5
NC
16941 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16942 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16943 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16944 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16945 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16946 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 16947
62b3e311 16948 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
16949#undef THUMB_VARIANT
16950#define THUMB_VARIANT & arm_ext_div
16951
21d799b5
NC
16952 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16953 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 16954
7e806470 16955 /* ARM V6M/V7 instructions. */
c921be7d
NC
16956#undef ARM_VARIANT
16957#define ARM_VARIANT & arm_ext_barrier
16958#undef THUMB_VARIANT
16959#define THUMB_VARIANT & arm_ext_barrier
16960
21d799b5
NC
16961 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16962 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16963 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
7e806470 16964
62b3e311 16965 /* ARM V7 instructions. */
c921be7d
NC
16966#undef ARM_VARIANT
16967#define ARM_VARIANT & arm_ext_v7
16968#undef THUMB_VARIANT
16969#define THUMB_VARIANT & arm_ext_v7
16970
21d799b5
NC
16971 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16972 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16973
c921be7d
NC
16974#undef ARM_VARIANT
16975#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16976
21d799b5
NC
16977 cCE("wfs", e200110, 1, (RR), rd),
16978 cCE("rfs", e300110, 1, (RR), rd),
16979 cCE("wfc", e400110, 1, (RR), rd),
16980 cCE("rfc", e500110, 1, (RR), rd),
16981
16982 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16983 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16984 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16985 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16986
16987 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16988 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16989 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16990 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16991
16992 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16993 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16994 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16995 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16996 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16997 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16998 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16999 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17000 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17001 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17002 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17003 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17004
17005 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17006 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17007 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17008 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17009 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17010 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17011 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17012 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17013 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17014 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17015 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17016 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17017
17018 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17019 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17020 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17021 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17022 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17023 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17024 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17025 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17026 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17027 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17028 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17029 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17030
17031 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17032 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17033 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17034 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17035 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17036 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17037 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17038 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17039 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17040 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17041 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17042 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17043
17044 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17045 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17046 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17047 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17048 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17049 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17050 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17051 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17052 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17053 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17054 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17055 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17056
17057 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17058 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17059 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17060 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17061 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17062 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17063 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17064 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17065 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17066 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17067 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17068 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17069
17070 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17071 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17072 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17073 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17074 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17075 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17076 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17077 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17078 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17079 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17080 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17081 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17082
17083 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17084 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17085 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17086 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17087 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17088 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17089 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17090 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17091 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17092 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17093 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17094 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17095
17096 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17097 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17098 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17099 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17100 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17101 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17102 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17103 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17104 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17105 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17106 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17107 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17108
17109 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17110 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17111 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17112 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17113 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17114 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17115 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17116 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17117 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17118 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17119 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17120 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17121
17122 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17123 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17124 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17125 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17126 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17127 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17128 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17129 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17130 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17131 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17132 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17133 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17134
17135 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17136 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17137 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17138 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17139 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17140 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17141 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17142 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17143 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17144 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17145 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17146 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17147
17148 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17149 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17150 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17151 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17152 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17153 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17154 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17155 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17156 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17157 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17158 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17159 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17160
17161 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17162 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17163 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17164 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17165 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17166 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17167 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17168 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17169 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17170 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17171 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17172 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17173
17174 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17175 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17176 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17177 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17178 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17179 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17180 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17181 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17182 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17183 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17184 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17185 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17186
17187 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17188 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17189 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17190 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17191 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17192 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17193 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17194 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17195 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17196 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17197 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17198 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17199
17200 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17202 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17203 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17204 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17205 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17207 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17208 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17209 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17210 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17211 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17212
17213 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17214 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17215 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17216 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17217 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17218 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17219 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17220 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17221 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17222 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17223 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17224 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17225
17226 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17227 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17228 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17229 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17230 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17231 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17232 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17233 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17234 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17235 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17236 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17237 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17238
17239 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17240 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17241 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17242 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17243 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17244 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17245 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17246 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17247 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17248 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17249 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17250 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17251
17252 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17253 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17254 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17255 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17256 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17257 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17258 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17259 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17260 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17261 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17262 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17263 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17264
17265 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17266 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17267 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17268 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17269 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17270 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17271 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17272 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17273 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17274 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17275 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17276 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17277
17278 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17279 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17280 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17281 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17282 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17283 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17284 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17285 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17286 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17290
17291 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17293 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17294 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17295 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17296 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17297 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17298 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17299 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17303
17304 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17306 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17307 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17308 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17309 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17310 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17311 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17312 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17316
17317 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17319 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17320 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17321 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17322 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17323 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17324 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17325 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17329
17330 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17332 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17333 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17334 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17335 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17336 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17337 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17338 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17339 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17340 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17341 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17342
17343 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17344 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17345 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17346 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17347 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17348 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17349 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17350 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17351 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17352 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17353 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17354 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17355
17356 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17357 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17358 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17359 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17360 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17361 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17362 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17363 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17364 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17365 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17366 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17367 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17368
17369 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17370 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17371 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17372 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17373
17374 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17375 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17376 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17377 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17378 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17379 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17380 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17381 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17382 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17383 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17384 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17385 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17386
c19d1205
ZW
17387 /* The implementation of the FIX instruction is broken on some
17388 assemblers, in that it accepts a precision specifier as well as a
17389 rounding specifier, despite the fact that this is meaningless.
17390 To be more compatible, we accept it as well, though of course it
17391 does not set any bits. */
21d799b5
NC
17392 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17393 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17394 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17395 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17396 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17397 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17398 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17399 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17400 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17401 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17402 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17403 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17404 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17405
c19d1205 17406 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17407#undef ARM_VARIANT
17408#define ARM_VARIANT & fpu_fpa_ext_v2
17409
21d799b5
NC
17410 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17411 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17412 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17413 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17414 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17415 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17416
c921be7d
NC
17417#undef ARM_VARIANT
17418#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17419
c19d1205 17420 /* Moves and type conversions. */
21d799b5
NC
17421 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17422 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17423 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17424 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17425 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17426 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17427 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17428 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17429 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17430 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17431 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17432 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17433 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17434 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17435
17436 /* Memory operations. */
21d799b5
NC
17437 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17438 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
17439 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17440 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17441 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17442 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17443 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17444 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17445 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17446 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17447 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17448 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17449 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17450 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17451 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17452 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17453 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17454 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17455
c19d1205 17456 /* Monadic operations. */
21d799b5
NC
17457 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17458 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17459 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17460
17461 /* Dyadic operations. */
21d799b5
NC
17462 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17463 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17464 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17465 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17466 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17467 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17468 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17469 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17470 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17471
c19d1205 17472 /* Comparisons. */
21d799b5
NC
17473 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17474 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17475 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17476 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17477
62f3b8c8
PB
17478 /* Double precision load/store are still present on single precision
17479 implementations. */
17480 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17481 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
17482 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17483 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17484 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17485 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17486 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17487 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17488 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17489 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 17490
c921be7d
NC
17491#undef ARM_VARIANT
17492#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17493
c19d1205 17494 /* Moves and type conversions. */
21d799b5
NC
17495 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17496 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17497 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17498 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17499 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17500 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17501 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17502 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17503 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17504 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17505 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17506 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17507 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17508
c19d1205 17509 /* Monadic operations. */
21d799b5
NC
17510 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17511 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17512 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17513
17514 /* Dyadic operations. */
21d799b5
NC
17515 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17516 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17517 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17518 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17519 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17520 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17521 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17522 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17523 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17524
c19d1205 17525 /* Comparisons. */
21d799b5
NC
17526 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17527 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17528 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17529 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17530
c921be7d
NC
17531#undef ARM_VARIANT
17532#define ARM_VARIANT & fpu_vfp_ext_v2
17533
21d799b5
NC
17534 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17535 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17536 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17537 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17538
037e8744
JB
17539/* Instructions which may belong to either the Neon or VFP instruction sets.
17540 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17541#undef ARM_VARIANT
17542#define ARM_VARIANT & fpu_vfp_ext_v1xd
17543#undef THUMB_VARIANT
17544#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17545
037e8744
JB
17546 /* These mnemonics are unique to VFP. */
17547 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17548 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17549 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17550 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17551 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17552 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17553 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17554 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17555 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17556 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17557
17558 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17559 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17560 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17561 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17562
21d799b5
NC
17563 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17564 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17565
17566 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17567 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17568
55881a11
MGD
17569 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17570 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17571 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17572 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17573 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17574 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17575 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17576 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17577
e3e535bc
NC
17578 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17579 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17580 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17581 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17582
037e8744
JB
17583
17584 /* NOTE: All VMOV encoding is special-cased! */
17585 NCE(vmov, 0, 1, (VMOV), neon_mov),
17586 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17587
c921be7d
NC
17588#undef THUMB_VARIANT
17589#define THUMB_VARIANT & fpu_neon_ext_v1
17590#undef ARM_VARIANT
17591#define ARM_VARIANT & fpu_neon_ext_v1
17592
5287ad62
JB
17593 /* Data processing with three registers of the same length. */
17594 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17595 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17596 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17597 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17598 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17599 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17600 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17601 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17602 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17603 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17604 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17605 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17606 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17607 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17608 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17609 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17610 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17611 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17612 /* If not immediate, fall back to neon_dyadic_i64_su.
17613 shl_imm should accept I8 I16 I32 I64,
17614 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17615 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17616 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17617 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17618 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17619 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17620 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17621 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17622 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17623 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17624 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17625 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17626 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17627 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17628 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17629 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17630 /* Bitfield ops, untyped. */
17631 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17632 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17633 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17634 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17635 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17636 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17637 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17638 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17639 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17640 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17641 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17642 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17643 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17644 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17645 back to neon_dyadic_if_su. */
21d799b5
NC
17646 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17647 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17648 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17649 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17650 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17651 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17652 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17653 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17654 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17655 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17656 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17657 /* As above, D registers only. */
21d799b5
NC
17658 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17659 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17660 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17661 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17662 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17663 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17664 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17665 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17666 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17667 /* vtst takes sizes 8, 16, 32. */
17668 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17669 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17670 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17671 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17672 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17673 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17674 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17675 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17676 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17677 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17678 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17679 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17680 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17681 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17682 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17683 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17684 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17685 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17686 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17687 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17688 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17689
17690 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17691 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17692 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17693
17694 /* Data processing with two registers and a shift amount. */
17695 /* Right shifts, and variants with rounding.
17696 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17697 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17698 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17699 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17700 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17701 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17702 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17703 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17704 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17705 /* Shift and insert. Sizes accepted 8 16 32 64. */
17706 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17707 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17708 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17709 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17710 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17711 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17712 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17713 /* Right shift immediate, saturating & narrowing, with rounding variants.
17714 Types accepted S16 S32 S64 U16 U32 U64. */
17715 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17716 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17717 /* As above, unsigned. Types accepted S16 S32 S64. */
17718 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17719 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17720 /* Right shift narrowing. Types accepted I16 I32 I64. */
17721 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17722 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17723 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17724 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17725 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17726 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17727
4316f0d2
DG
17728 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17729 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17730
17731 /* Data processing, three registers of different lengths. */
17732 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17733 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17734 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17735 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17736 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17737 /* If not scalar, fall back to neon_dyadic_long.
17738 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17739 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17740 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17741 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17742 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17743 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17744 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17745 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17746 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17747 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17748 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17749 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17750 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17751 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17752 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17753 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17754 S16 S32 U16 U32. */
21d799b5 17755 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17756
17757 /* Extract. Size 8. */
3b8d421e
PB
17758 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17759 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17760
17761 /* Two registers, miscellaneous. */
17762 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17763 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17764 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17765 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17766 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17767 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17768 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17769 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17770 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17771 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17772 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17773 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17774 /* VMOVN. Types I16 I32 I64. */
21d799b5 17775 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17776 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17777 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17778 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17779 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17780 /* VZIP / VUZP. Sizes 8 16 32. */
17781 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17782 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17783 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17784 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17785 /* VQABS / VQNEG. Types S8 S16 S32. */
17786 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17787 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17788 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17789 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17790 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17791 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17792 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17793 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17794 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17795 /* Reciprocal estimates. Types U32 F32. */
17796 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17797 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17798 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17799 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17800 /* VCLS. Types S8 S16 S32. */
17801 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17802 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17803 /* VCLZ. Types I8 I16 I32. */
17804 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17805 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17806 /* VCNT. Size 8. */
17807 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17808 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17809 /* Two address, untyped. */
17810 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17811 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17812 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17813 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17814 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17815
17816 /* Table lookup. Size 8. */
17817 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17818 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17819
c921be7d
NC
17820#undef THUMB_VARIANT
17821#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17822#undef ARM_VARIANT
17823#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17824
5287ad62 17825 /* Neon element/structure load/store. */
21d799b5
NC
17826 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17827 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17828 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17829 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17830 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17831 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17832 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17833 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17834
c921be7d 17835#undef THUMB_VARIANT
62f3b8c8
PB
17836#define THUMB_VARIANT &fpu_vfp_ext_v3xd
17837#undef ARM_VARIANT
17838#define ARM_VARIANT &fpu_vfp_ext_v3xd
17839 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17840 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17841 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17842 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17843 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17844 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17845 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17846 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17847 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17848
17849#undef THUMB_VARIANT
c921be7d
NC
17850#define THUMB_VARIANT & fpu_vfp_ext_v3
17851#undef ARM_VARIANT
17852#define ARM_VARIANT & fpu_vfp_ext_v3
17853
21d799b5 17854 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 17855 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17856 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17857 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17858 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17859 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17860 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17861 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17862 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17863
62f3b8c8
PB
17864#undef ARM_VARIANT
17865#define ARM_VARIANT &fpu_vfp_ext_fma
17866#undef THUMB_VARIANT
17867#define THUMB_VARIANT &fpu_vfp_ext_fma
17868 /* Mnemonics shared by Neon and VFP. These are included in the
17869 VFP FMA variant; NEON and VFP FMA always includes the NEON
17870 FMA instructions. */
17871 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17872 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17873 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17874 the v form should always be used. */
17875 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17876 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17877 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17878 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17879 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17880 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17881
5287ad62 17882#undef THUMB_VARIANT
c921be7d
NC
17883#undef ARM_VARIANT
17884#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17885
21d799b5
NC
17886 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17887 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17888 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17889 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17890 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17891 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17892 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17893 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 17894
c921be7d
NC
17895#undef ARM_VARIANT
17896#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17897
21d799b5
NC
17898 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17899 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17900 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17901 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17902 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17903 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17904 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17905 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17906 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17907 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17908 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17909 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17910 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17911 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17912 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17913 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17914 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17915 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17916 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17917 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17918 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17919 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17920 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17921 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17922 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17923 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17924 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17925 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17926 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17927 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17928 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17929 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17930 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17931 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17932 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17933 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17934 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17935 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17945 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17946 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17947 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17955 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17956 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17957 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17958 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17961 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17962 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17963 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17964 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17965 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17966 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17967 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17968 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17969 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17970 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17971 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17972 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17973 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17974 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17975 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17976 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17977 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17978 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17979 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17980 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17981 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17982 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17983 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17984 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17985 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17986 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17987 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17988 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17989 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17990 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17991 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17992 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17993 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17994 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17995 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17996 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17997 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17998 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17999 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18000 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18001 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18002 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18003 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18004 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18005 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18006 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18007 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18008 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18009 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18010 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18011 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18012 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18013 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18014 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18015 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18016 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18017 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18018 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18019 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18020 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18021 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18022 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18023 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18024 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18025 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18026 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18027 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18028 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18029 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18030 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18031 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18032 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18033 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18034 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18035 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18036 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18037 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18038 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18039 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18040 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18041 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18042 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18043 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18044 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18045 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18046 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18047 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18048 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18049 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18050 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18051 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18052 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18053 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18054 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18055 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18056 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18057 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18058 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18059 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18060
c921be7d
NC
18061#undef ARM_VARIANT
18062#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18063
21d799b5
NC
18064 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18065 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18066 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18067 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18068 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18069 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18070 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18071 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18075 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18083 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18084 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18085 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18086 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18087 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18088 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18091 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18092 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18093 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18094 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18095 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18096 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18097 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18098 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18099 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18100 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18101 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18102 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18103 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18104 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18105 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18106 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18107 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18108 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18109 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18110 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18111 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18112 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18113 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18114 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18115 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18116 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18117 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18118 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18119 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18120 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18121
c921be7d
NC
18122#undef ARM_VARIANT
18123#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18124
21d799b5
NC
18125 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18126 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18127 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18128 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18129 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18130 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18131 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18132 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18133 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18134 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18135 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18136 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18137 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18138 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18139 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18140 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18141 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18142 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18143 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18144 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18145 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18146 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18147 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18148 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18149 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18150 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18151 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18152 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18153 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18154 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18155 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18156 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18157 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18158 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18159 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18160 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18161 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18162 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18163 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18164 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18165 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18166 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18167 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18168 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18169 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18170 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18171 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18172 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18173 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18174 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18175 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18176 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18177 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18178 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18179 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18180 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18181 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18182 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18183 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18184 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18185 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18186 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18187 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18188 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18189 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18190 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18191 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18192 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18193 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18194 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18195 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18196 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18197 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18198 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18199 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18200 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18201};
18202#undef ARM_VARIANT
18203#undef THUMB_VARIANT
18204#undef TCE
18205#undef TCM
18206#undef TUE
18207#undef TUF
18208#undef TCC
8f06b2d8 18209#undef cCE
e3cb604e
PB
18210#undef cCL
18211#undef C3E
c19d1205
ZW
18212#undef CE
18213#undef CM
18214#undef UE
18215#undef UF
18216#undef UT
5287ad62
JB
18217#undef NUF
18218#undef nUF
18219#undef NCE
18220#undef nCE
c19d1205
ZW
18221#undef OPS0
18222#undef OPS1
18223#undef OPS2
18224#undef OPS3
18225#undef OPS4
18226#undef OPS5
18227#undef OPS6
18228#undef do_0
18229\f
18230/* MD interface: bits in the object file. */
bfae80f2 18231
c19d1205
ZW
18232/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18233 for use in the a.out file, and stores them in the array pointed to by buf.
18234 This knows about the endian-ness of the target machine and does
18235 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18236 2 (short) and 4 (long) Floating numbers are put out as a series of
18237 LITTLENUMS (shorts, here at least). */
b99bd4ef 18238
c19d1205
ZW
18239void
18240md_number_to_chars (char * buf, valueT val, int n)
18241{
18242 if (target_big_endian)
18243 number_to_chars_bigendian (buf, val, n);
18244 else
18245 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18246}
18247
c19d1205
ZW
18248static valueT
18249md_chars_to_number (char * buf, int n)
bfae80f2 18250{
c19d1205
ZW
18251 valueT result = 0;
18252 unsigned char * where = (unsigned char *) buf;
bfae80f2 18253
c19d1205 18254 if (target_big_endian)
b99bd4ef 18255 {
c19d1205
ZW
18256 while (n--)
18257 {
18258 result <<= 8;
18259 result |= (*where++ & 255);
18260 }
b99bd4ef 18261 }
c19d1205 18262 else
b99bd4ef 18263 {
c19d1205
ZW
18264 while (n--)
18265 {
18266 result <<= 8;
18267 result |= (where[n] & 255);
18268 }
bfae80f2 18269 }
b99bd4ef 18270
c19d1205 18271 return result;
bfae80f2 18272}
b99bd4ef 18273
c19d1205 18274/* MD interface: Sections. */
b99bd4ef 18275
0110f2b8
PB
18276/* Estimate the size of a frag before relaxing. Assume everything fits in
18277 2 bytes. */
18278
c19d1205 18279int
0110f2b8 18280md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18281 segT segtype ATTRIBUTE_UNUSED)
18282{
0110f2b8
PB
18283 fragp->fr_var = 2;
18284 return 2;
18285}
18286
18287/* Convert a machine dependent frag. */
18288
18289void
18290md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18291{
18292 unsigned long insn;
18293 unsigned long old_op;
18294 char *buf;
18295 expressionS exp;
18296 fixS *fixp;
18297 int reloc_type;
18298 int pc_rel;
18299 int opcode;
18300
18301 buf = fragp->fr_literal + fragp->fr_fix;
18302
18303 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18304 if (fragp->fr_symbol)
18305 {
0110f2b8
PB
18306 exp.X_op = O_symbol;
18307 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18308 }
18309 else
18310 {
0110f2b8 18311 exp.X_op = O_constant;
5f4273c7 18312 }
0110f2b8
PB
18313 exp.X_add_number = fragp->fr_offset;
18314 opcode = fragp->fr_subtype;
18315 switch (opcode)
18316 {
18317 case T_MNEM_ldr_pc:
18318 case T_MNEM_ldr_pc2:
18319 case T_MNEM_ldr_sp:
18320 case T_MNEM_str_sp:
18321 case T_MNEM_ldr:
18322 case T_MNEM_ldrb:
18323 case T_MNEM_ldrh:
18324 case T_MNEM_str:
18325 case T_MNEM_strb:
18326 case T_MNEM_strh:
18327 if (fragp->fr_var == 4)
18328 {
5f4273c7 18329 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18330 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18331 {
18332 insn |= (old_op & 0x700) << 4;
18333 }
18334 else
18335 {
18336 insn |= (old_op & 7) << 12;
18337 insn |= (old_op & 0x38) << 13;
18338 }
18339 insn |= 0x00000c00;
18340 put_thumb32_insn (buf, insn);
18341 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18342 }
18343 else
18344 {
18345 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18346 }
18347 pc_rel = (opcode == T_MNEM_ldr_pc2);
18348 break;
18349 case T_MNEM_adr:
18350 if (fragp->fr_var == 4)
18351 {
18352 insn = THUMB_OP32 (opcode);
18353 insn |= (old_op & 0xf0) << 4;
18354 put_thumb32_insn (buf, insn);
18355 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18356 }
18357 else
18358 {
18359 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18360 exp.X_add_number -= 4;
18361 }
18362 pc_rel = 1;
18363 break;
18364 case T_MNEM_mov:
18365 case T_MNEM_movs:
18366 case T_MNEM_cmp:
18367 case T_MNEM_cmn:
18368 if (fragp->fr_var == 4)
18369 {
18370 int r0off = (opcode == T_MNEM_mov
18371 || opcode == T_MNEM_movs) ? 0 : 8;
18372 insn = THUMB_OP32 (opcode);
18373 insn = (insn & 0xe1ffffff) | 0x10000000;
18374 insn |= (old_op & 0x700) << r0off;
18375 put_thumb32_insn (buf, insn);
18376 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18377 }
18378 else
18379 {
18380 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18381 }
18382 pc_rel = 0;
18383 break;
18384 case T_MNEM_b:
18385 if (fragp->fr_var == 4)
18386 {
18387 insn = THUMB_OP32(opcode);
18388 put_thumb32_insn (buf, insn);
18389 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18390 }
18391 else
18392 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18393 pc_rel = 1;
18394 break;
18395 case T_MNEM_bcond:
18396 if (fragp->fr_var == 4)
18397 {
18398 insn = THUMB_OP32(opcode);
18399 insn |= (old_op & 0xf00) << 14;
18400 put_thumb32_insn (buf, insn);
18401 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18402 }
18403 else
18404 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18405 pc_rel = 1;
18406 break;
18407 case T_MNEM_add_sp:
18408 case T_MNEM_add_pc:
18409 case T_MNEM_inc_sp:
18410 case T_MNEM_dec_sp:
18411 if (fragp->fr_var == 4)
18412 {
18413 /* ??? Choose between add and addw. */
18414 insn = THUMB_OP32 (opcode);
18415 insn |= (old_op & 0xf0) << 4;
18416 put_thumb32_insn (buf, insn);
16805f35
PB
18417 if (opcode == T_MNEM_add_pc)
18418 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18419 else
18420 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18421 }
18422 else
18423 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18424 pc_rel = 0;
18425 break;
18426
18427 case T_MNEM_addi:
18428 case T_MNEM_addis:
18429 case T_MNEM_subi:
18430 case T_MNEM_subis:
18431 if (fragp->fr_var == 4)
18432 {
18433 insn = THUMB_OP32 (opcode);
18434 insn |= (old_op & 0xf0) << 4;
18435 insn |= (old_op & 0xf) << 16;
18436 put_thumb32_insn (buf, insn);
16805f35
PB
18437 if (insn & (1 << 20))
18438 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18439 else
18440 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18441 }
18442 else
18443 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18444 pc_rel = 0;
18445 break;
18446 default:
5f4273c7 18447 abort ();
0110f2b8
PB
18448 }
18449 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18450 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18451 fixp->fx_file = fragp->fr_file;
18452 fixp->fx_line = fragp->fr_line;
18453 fragp->fr_fix += fragp->fr_var;
18454}
18455
18456/* Return the size of a relaxable immediate operand instruction.
18457 SHIFT and SIZE specify the form of the allowable immediate. */
18458static int
18459relax_immediate (fragS *fragp, int size, int shift)
18460{
18461 offsetT offset;
18462 offsetT mask;
18463 offsetT low;
18464
18465 /* ??? Should be able to do better than this. */
18466 if (fragp->fr_symbol)
18467 return 4;
18468
18469 low = (1 << shift) - 1;
18470 mask = (1 << (shift + size)) - (1 << shift);
18471 offset = fragp->fr_offset;
18472 /* Force misaligned offsets to 32-bit variant. */
18473 if (offset & low)
5e77afaa 18474 return 4;
0110f2b8
PB
18475 if (offset & ~mask)
18476 return 4;
18477 return 2;
18478}
18479
5e77afaa
PB
18480/* Get the address of a symbol during relaxation. */
18481static addressT
5f4273c7 18482relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18483{
18484 fragS *sym_frag;
18485 addressT addr;
18486 symbolS *sym;
18487
18488 sym = fragp->fr_symbol;
18489 sym_frag = symbol_get_frag (sym);
18490 know (S_GET_SEGMENT (sym) != absolute_section
18491 || sym_frag == &zero_address_frag);
18492 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18493
18494 /* If frag has yet to be reached on this pass, assume it will
18495 move by STRETCH just as we did. If this is not so, it will
18496 be because some frag between grows, and that will force
18497 another pass. */
18498
18499 if (stretch != 0
18500 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18501 {
18502 fragS *f;
18503
18504 /* Adjust stretch for any alignment frag. Note that if have
18505 been expanding the earlier code, the symbol may be
18506 defined in what appears to be an earlier frag. FIXME:
18507 This doesn't handle the fr_subtype field, which specifies
18508 a maximum number of bytes to skip when doing an
18509 alignment. */
18510 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18511 {
18512 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18513 {
18514 if (stretch < 0)
18515 stretch = - ((- stretch)
18516 & ~ ((1 << (int) f->fr_offset) - 1));
18517 else
18518 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18519 if (stretch == 0)
18520 break;
18521 }
18522 }
18523 if (f != NULL)
18524 addr += stretch;
18525 }
5e77afaa
PB
18526
18527 return addr;
18528}
18529
0110f2b8
PB
18530/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18531 load. */
18532static int
5e77afaa 18533relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18534{
18535 addressT addr;
18536 offsetT val;
18537
18538 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18539 if (fragp->fr_symbol == NULL
18540 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18541 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18542 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18543 return 4;
18544
5f4273c7 18545 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18546 addr = fragp->fr_address + fragp->fr_fix;
18547 addr = (addr + 4) & ~3;
5e77afaa 18548 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18549 if (val & 3)
5e77afaa 18550 return 4;
0110f2b8
PB
18551 val -= addr;
18552 if (val < 0 || val > 1020)
18553 return 4;
18554 return 2;
18555}
18556
18557/* Return the size of a relaxable add/sub immediate instruction. */
18558static int
18559relax_addsub (fragS *fragp, asection *sec)
18560{
18561 char *buf;
18562 int op;
18563
18564 buf = fragp->fr_literal + fragp->fr_fix;
18565 op = bfd_get_16(sec->owner, buf);
18566 if ((op & 0xf) == ((op >> 4) & 0xf))
18567 return relax_immediate (fragp, 8, 0);
18568 else
18569 return relax_immediate (fragp, 3, 0);
18570}
18571
18572
18573/* Return the size of a relaxable branch instruction. BITS is the
18574 size of the offset field in the narrow instruction. */
18575
18576static int
5e77afaa 18577relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18578{
18579 addressT addr;
18580 offsetT val;
18581 offsetT limit;
18582
18583 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18584 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
18585 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18586 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
18587 return 4;
18588
267bf995
RR
18589#ifdef OBJ_ELF
18590 if (S_IS_DEFINED (fragp->fr_symbol)
18591 && ARM_IS_FUNC (fragp->fr_symbol))
18592 return 4;
18593#endif
18594
5f4273c7 18595 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18596 addr = fragp->fr_address + fragp->fr_fix + 4;
18597 val -= addr;
18598
18599 /* Offset is a signed value *2 */
18600 limit = 1 << bits;
18601 if (val >= limit || val < -limit)
18602 return 4;
18603 return 2;
18604}
18605
18606
18607/* Relax a machine dependent frag. This returns the amount by which
18608 the current size of the frag should change. */
18609
18610int
5e77afaa 18611arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18612{
18613 int oldsize;
18614 int newsize;
18615
18616 oldsize = fragp->fr_var;
18617 switch (fragp->fr_subtype)
18618 {
18619 case T_MNEM_ldr_pc2:
5f4273c7 18620 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18621 break;
18622 case T_MNEM_ldr_pc:
18623 case T_MNEM_ldr_sp:
18624 case T_MNEM_str_sp:
5f4273c7 18625 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18626 break;
18627 case T_MNEM_ldr:
18628 case T_MNEM_str:
5f4273c7 18629 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18630 break;
18631 case T_MNEM_ldrh:
18632 case T_MNEM_strh:
5f4273c7 18633 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18634 break;
18635 case T_MNEM_ldrb:
18636 case T_MNEM_strb:
5f4273c7 18637 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18638 break;
18639 case T_MNEM_adr:
5f4273c7 18640 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18641 break;
18642 case T_MNEM_mov:
18643 case T_MNEM_movs:
18644 case T_MNEM_cmp:
18645 case T_MNEM_cmn:
5f4273c7 18646 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18647 break;
18648 case T_MNEM_b:
5f4273c7 18649 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18650 break;
18651 case T_MNEM_bcond:
5f4273c7 18652 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18653 break;
18654 case T_MNEM_add_sp:
18655 case T_MNEM_add_pc:
18656 newsize = relax_immediate (fragp, 8, 2);
18657 break;
18658 case T_MNEM_inc_sp:
18659 case T_MNEM_dec_sp:
18660 newsize = relax_immediate (fragp, 7, 2);
18661 break;
18662 case T_MNEM_addi:
18663 case T_MNEM_addis:
18664 case T_MNEM_subi:
18665 case T_MNEM_subis:
18666 newsize = relax_addsub (fragp, sec);
18667 break;
18668 default:
5f4273c7 18669 abort ();
0110f2b8 18670 }
5e77afaa
PB
18671
18672 fragp->fr_var = newsize;
18673 /* Freeze wide instructions that are at or before the same location as
18674 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18675 Don't freeze them unconditionally because targets may be artificially
18676 misaligned by the expansion of preceding frags. */
5e77afaa 18677 if (stretch <= 0 && newsize > 2)
0110f2b8 18678 {
0110f2b8 18679 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18680 frag_wane (fragp);
0110f2b8 18681 }
5e77afaa 18682
0110f2b8 18683 return newsize - oldsize;
c19d1205 18684}
b99bd4ef 18685
c19d1205 18686/* Round up a section size to the appropriate boundary. */
b99bd4ef 18687
c19d1205
ZW
18688valueT
18689md_section_align (segT segment ATTRIBUTE_UNUSED,
18690 valueT size)
18691{
f0927246
NC
18692#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18693 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18694 {
18695 /* For a.out, force the section size to be aligned. If we don't do
18696 this, BFD will align it for us, but it will not write out the
18697 final bytes of the section. This may be a bug in BFD, but it is
18698 easier to fix it here since that is how the other a.out targets
18699 work. */
18700 int align;
18701
18702 align = bfd_get_section_alignment (stdoutput, segment);
18703 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18704 }
c19d1205 18705#endif
f0927246
NC
18706
18707 return size;
bfae80f2 18708}
b99bd4ef 18709
c19d1205
ZW
18710/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18711 of an rs_align_code fragment. */
18712
18713void
18714arm_handle_align (fragS * fragP)
bfae80f2 18715{
e7495e45
NS
18716 static char const arm_noop[2][2][4] =
18717 {
18718 { /* ARMv1 */
18719 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18720 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18721 },
18722 { /* ARMv6k */
18723 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18724 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18725 },
18726 };
18727 static char const thumb_noop[2][2][2] =
18728 {
18729 { /* Thumb-1 */
18730 {0xc0, 0x46}, /* LE */
18731 {0x46, 0xc0}, /* BE */
18732 },
18733 { /* Thumb-2 */
18734 {0x00, 0xbf}, /* LE */
18735 {0xbf, 0x00} /* BE */
18736 }
18737 };
18738 static char const wide_thumb_noop[2][4] =
18739 { /* Wide Thumb-2 */
18740 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18741 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18742 };
c921be7d 18743
e7495e45 18744 unsigned bytes, fix, noop_size;
c19d1205
ZW
18745 char * p;
18746 const char * noop;
e7495e45 18747 const char *narrow_noop = NULL;
cd000bff
DJ
18748#ifdef OBJ_ELF
18749 enum mstate state;
18750#endif
bfae80f2 18751
c19d1205 18752 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18753 return;
18754
c19d1205
ZW
18755 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18756 p = fragP->fr_literal + fragP->fr_fix;
18757 fix = 0;
bfae80f2 18758
c19d1205
ZW
18759 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18760 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18761
cd000bff 18762 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18763
cd000bff 18764 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18765 {
e7495e45
NS
18766 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18767 {
18768 narrow_noop = thumb_noop[1][target_big_endian];
18769 noop = wide_thumb_noop[target_big_endian];
18770 }
c19d1205 18771 else
e7495e45
NS
18772 noop = thumb_noop[0][target_big_endian];
18773 noop_size = 2;
cd000bff
DJ
18774#ifdef OBJ_ELF
18775 state = MAP_THUMB;
18776#endif
7ed4c4c5
NC
18777 }
18778 else
18779 {
e7495e45
NS
18780 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18781 [target_big_endian];
18782 noop_size = 4;
cd000bff
DJ
18783#ifdef OBJ_ELF
18784 state = MAP_ARM;
18785#endif
7ed4c4c5 18786 }
c921be7d 18787
e7495e45 18788 fragP->fr_var = noop_size;
c921be7d 18789
c19d1205 18790 if (bytes & (noop_size - 1))
7ed4c4c5 18791 {
c19d1205 18792 fix = bytes & (noop_size - 1);
cd000bff
DJ
18793#ifdef OBJ_ELF
18794 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18795#endif
c19d1205
ZW
18796 memset (p, 0, fix);
18797 p += fix;
18798 bytes -= fix;
a737bd4d 18799 }
a737bd4d 18800
e7495e45
NS
18801 if (narrow_noop)
18802 {
18803 if (bytes & noop_size)
18804 {
18805 /* Insert a narrow noop. */
18806 memcpy (p, narrow_noop, noop_size);
18807 p += noop_size;
18808 bytes -= noop_size;
18809 fix += noop_size;
18810 }
18811
18812 /* Use wide noops for the remainder */
18813 noop_size = 4;
18814 }
18815
c19d1205 18816 while (bytes >= noop_size)
a737bd4d 18817 {
c19d1205
ZW
18818 memcpy (p, noop, noop_size);
18819 p += noop_size;
18820 bytes -= noop_size;
18821 fix += noop_size;
a737bd4d
NC
18822 }
18823
c19d1205 18824 fragP->fr_fix += fix;
a737bd4d
NC
18825}
18826
c19d1205
ZW
18827/* Called from md_do_align. Used to create an alignment
18828 frag in a code section. */
18829
18830void
18831arm_frag_align_code (int n, int max)
bfae80f2 18832{
c19d1205 18833 char * p;
7ed4c4c5 18834
c19d1205 18835 /* We assume that there will never be a requirement
6ec8e702 18836 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 18837 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
18838 {
18839 char err_msg[128];
18840
18841 sprintf (err_msg,
18842 _("alignments greater than %d bytes not supported in .text sections."),
18843 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 18844 as_fatal ("%s", err_msg);
6ec8e702 18845 }
bfae80f2 18846
c19d1205
ZW
18847 p = frag_var (rs_align_code,
18848 MAX_MEM_FOR_RS_ALIGN_CODE,
18849 1,
18850 (relax_substateT) max,
18851 (symbolS *) NULL,
18852 (offsetT) n,
18853 (char *) NULL);
18854 *p = 0;
18855}
bfae80f2 18856
8dc2430f
NC
18857/* Perform target specific initialisation of a frag.
18858 Note - despite the name this initialisation is not done when the frag
18859 is created, but only when its type is assigned. A frag can be created
18860 and used a long time before its type is set, so beware of assuming that
18861 this initialisationis performed first. */
bfae80f2 18862
cd000bff
DJ
18863#ifndef OBJ_ELF
18864void
18865arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18866{
18867 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 18868 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
18869}
18870
18871#else /* OBJ_ELF is defined. */
c19d1205 18872void
cd000bff 18873arm_init_frag (fragS * fragP, int max_chars)
c19d1205 18874{
8dc2430f
NC
18875 /* If the current ARM vs THUMB mode has not already
18876 been recorded into this frag then do so now. */
cd000bff
DJ
18877 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18878 {
18879 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18880
18881 /* Record a mapping symbol for alignment frags. We will delete this
18882 later if the alignment ends up empty. */
18883 switch (fragP->fr_type)
18884 {
18885 case rs_align:
18886 case rs_align_test:
18887 case rs_fill:
18888 mapping_state_2 (MAP_DATA, max_chars);
18889 break;
18890 case rs_align_code:
18891 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18892 break;
18893 default:
18894 break;
18895 }
18896 }
bfae80f2
RE
18897}
18898
c19d1205
ZW
18899/* When we change sections we need to issue a new mapping symbol. */
18900
18901void
18902arm_elf_change_section (void)
bfae80f2 18903{
c19d1205
ZW
18904 /* Link an unlinked unwind index table section to the .text section. */
18905 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18906 && elf_linked_to_section (now_seg) == NULL)
18907 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
18908}
18909
c19d1205
ZW
18910int
18911arm_elf_section_type (const char * str, size_t len)
e45d0630 18912{
c19d1205
ZW
18913 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18914 return SHT_ARM_EXIDX;
e45d0630 18915
c19d1205
ZW
18916 return -1;
18917}
18918\f
18919/* Code to deal with unwinding tables. */
e45d0630 18920
c19d1205 18921static void add_unwind_adjustsp (offsetT);
e45d0630 18922
5f4273c7 18923/* Generate any deferred unwind frame offset. */
e45d0630 18924
bfae80f2 18925static void
c19d1205 18926flush_pending_unwind (void)
bfae80f2 18927{
c19d1205 18928 offsetT offset;
bfae80f2 18929
c19d1205
ZW
18930 offset = unwind.pending_offset;
18931 unwind.pending_offset = 0;
18932 if (offset != 0)
18933 add_unwind_adjustsp (offset);
bfae80f2
RE
18934}
18935
c19d1205
ZW
18936/* Add an opcode to this list for this function. Two-byte opcodes should
18937 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18938 order. */
18939
bfae80f2 18940static void
c19d1205 18941add_unwind_opcode (valueT op, int length)
bfae80f2 18942{
c19d1205
ZW
18943 /* Add any deferred stack adjustment. */
18944 if (unwind.pending_offset)
18945 flush_pending_unwind ();
bfae80f2 18946
c19d1205 18947 unwind.sp_restored = 0;
bfae80f2 18948
c19d1205 18949 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18950 {
c19d1205
ZW
18951 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18952 if (unwind.opcodes)
21d799b5
NC
18953 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18954 unwind.opcode_alloc);
c19d1205 18955 else
21d799b5 18956 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 18957 }
c19d1205 18958 while (length > 0)
bfae80f2 18959 {
c19d1205
ZW
18960 length--;
18961 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18962 op >>= 8;
18963 unwind.opcode_count++;
bfae80f2 18964 }
bfae80f2
RE
18965}
18966
c19d1205
ZW
18967/* Add unwind opcodes to adjust the stack pointer. */
18968
bfae80f2 18969static void
c19d1205 18970add_unwind_adjustsp (offsetT offset)
bfae80f2 18971{
c19d1205 18972 valueT op;
bfae80f2 18973
c19d1205 18974 if (offset > 0x200)
bfae80f2 18975 {
c19d1205
ZW
18976 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18977 char bytes[5];
18978 int n;
18979 valueT o;
bfae80f2 18980
c19d1205
ZW
18981 /* Long form: 0xb2, uleb128. */
18982 /* This might not fit in a word so add the individual bytes,
18983 remembering the list is built in reverse order. */
18984 o = (valueT) ((offset - 0x204) >> 2);
18985 if (o == 0)
18986 add_unwind_opcode (0, 1);
bfae80f2 18987
c19d1205
ZW
18988 /* Calculate the uleb128 encoding of the offset. */
18989 n = 0;
18990 while (o)
18991 {
18992 bytes[n] = o & 0x7f;
18993 o >>= 7;
18994 if (o)
18995 bytes[n] |= 0x80;
18996 n++;
18997 }
18998 /* Add the insn. */
18999 for (; n; n--)
19000 add_unwind_opcode (bytes[n - 1], 1);
19001 add_unwind_opcode (0xb2, 1);
19002 }
19003 else if (offset > 0x100)
bfae80f2 19004 {
c19d1205
ZW
19005 /* Two short opcodes. */
19006 add_unwind_opcode (0x3f, 1);
19007 op = (offset - 0x104) >> 2;
19008 add_unwind_opcode (op, 1);
bfae80f2 19009 }
c19d1205
ZW
19010 else if (offset > 0)
19011 {
19012 /* Short opcode. */
19013 op = (offset - 4) >> 2;
19014 add_unwind_opcode (op, 1);
19015 }
19016 else if (offset < 0)
bfae80f2 19017 {
c19d1205
ZW
19018 offset = -offset;
19019 while (offset > 0x100)
bfae80f2 19020 {
c19d1205
ZW
19021 add_unwind_opcode (0x7f, 1);
19022 offset -= 0x100;
bfae80f2 19023 }
c19d1205
ZW
19024 op = ((offset - 4) >> 2) | 0x40;
19025 add_unwind_opcode (op, 1);
bfae80f2 19026 }
bfae80f2
RE
19027}
19028
c19d1205
ZW
19029/* Finish the list of unwind opcodes for this function. */
19030static void
19031finish_unwind_opcodes (void)
bfae80f2 19032{
c19d1205 19033 valueT op;
bfae80f2 19034
c19d1205 19035 if (unwind.fp_used)
bfae80f2 19036 {
708587a4 19037 /* Adjust sp as necessary. */
c19d1205
ZW
19038 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19039 flush_pending_unwind ();
bfae80f2 19040
c19d1205
ZW
19041 /* After restoring sp from the frame pointer. */
19042 op = 0x90 | unwind.fp_reg;
19043 add_unwind_opcode (op, 1);
19044 }
19045 else
19046 flush_pending_unwind ();
bfae80f2
RE
19047}
19048
bfae80f2 19049
c19d1205
ZW
19050/* Start an exception table entry. If idx is nonzero this is an index table
19051 entry. */
bfae80f2
RE
19052
19053static void
c19d1205 19054start_unwind_section (const segT text_seg, int idx)
bfae80f2 19055{
c19d1205
ZW
19056 const char * text_name;
19057 const char * prefix;
19058 const char * prefix_once;
19059 const char * group_name;
19060 size_t prefix_len;
19061 size_t text_len;
19062 char * sec_name;
19063 size_t sec_name_len;
19064 int type;
19065 int flags;
19066 int linkonce;
bfae80f2 19067
c19d1205 19068 if (idx)
bfae80f2 19069 {
c19d1205
ZW
19070 prefix = ELF_STRING_ARM_unwind;
19071 prefix_once = ELF_STRING_ARM_unwind_once;
19072 type = SHT_ARM_EXIDX;
bfae80f2 19073 }
c19d1205 19074 else
bfae80f2 19075 {
c19d1205
ZW
19076 prefix = ELF_STRING_ARM_unwind_info;
19077 prefix_once = ELF_STRING_ARM_unwind_info_once;
19078 type = SHT_PROGBITS;
bfae80f2
RE
19079 }
19080
c19d1205
ZW
19081 text_name = segment_name (text_seg);
19082 if (streq (text_name, ".text"))
19083 text_name = "";
19084
19085 if (strncmp (text_name, ".gnu.linkonce.t.",
19086 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19087 {
c19d1205
ZW
19088 prefix = prefix_once;
19089 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19090 }
19091
c19d1205
ZW
19092 prefix_len = strlen (prefix);
19093 text_len = strlen (text_name);
19094 sec_name_len = prefix_len + text_len;
21d799b5 19095 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19096 memcpy (sec_name, prefix, prefix_len);
19097 memcpy (sec_name + prefix_len, text_name, text_len);
19098 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19099
c19d1205
ZW
19100 flags = SHF_ALLOC;
19101 linkonce = 0;
19102 group_name = 0;
bfae80f2 19103
c19d1205
ZW
19104 /* Handle COMDAT group. */
19105 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19106 {
c19d1205
ZW
19107 group_name = elf_group_name (text_seg);
19108 if (group_name == NULL)
19109 {
bd3ba5d1 19110 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19111 segment_name (text_seg));
19112 ignore_rest_of_line ();
19113 return;
19114 }
19115 flags |= SHF_GROUP;
19116 linkonce = 1;
bfae80f2
RE
19117 }
19118
c19d1205 19119 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19120
5f4273c7 19121 /* Set the section link for index tables. */
c19d1205
ZW
19122 if (idx)
19123 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19124}
19125
bfae80f2 19126
c19d1205
ZW
19127/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19128 personality routine data. Returns zero, or the index table value for
19129 and inline entry. */
19130
19131static valueT
19132create_unwind_entry (int have_data)
bfae80f2 19133{
c19d1205
ZW
19134 int size;
19135 addressT where;
19136 char *ptr;
19137 /* The current word of data. */
19138 valueT data;
19139 /* The number of bytes left in this word. */
19140 int n;
bfae80f2 19141
c19d1205 19142 finish_unwind_opcodes ();
bfae80f2 19143
c19d1205
ZW
19144 /* Remember the current text section. */
19145 unwind.saved_seg = now_seg;
19146 unwind.saved_subseg = now_subseg;
bfae80f2 19147
c19d1205 19148 start_unwind_section (now_seg, 0);
bfae80f2 19149
c19d1205 19150 if (unwind.personality_routine == NULL)
bfae80f2 19151 {
c19d1205
ZW
19152 if (unwind.personality_index == -2)
19153 {
19154 if (have_data)
5f4273c7 19155 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19156 return 1; /* EXIDX_CANTUNWIND. */
19157 }
bfae80f2 19158
c19d1205
ZW
19159 /* Use a default personality routine if none is specified. */
19160 if (unwind.personality_index == -1)
19161 {
19162 if (unwind.opcode_count > 3)
19163 unwind.personality_index = 1;
19164 else
19165 unwind.personality_index = 0;
19166 }
bfae80f2 19167
c19d1205
ZW
19168 /* Space for the personality routine entry. */
19169 if (unwind.personality_index == 0)
19170 {
19171 if (unwind.opcode_count > 3)
19172 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19173
c19d1205
ZW
19174 if (!have_data)
19175 {
19176 /* All the data is inline in the index table. */
19177 data = 0x80;
19178 n = 3;
19179 while (unwind.opcode_count > 0)
19180 {
19181 unwind.opcode_count--;
19182 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19183 n--;
19184 }
bfae80f2 19185
c19d1205
ZW
19186 /* Pad with "finish" opcodes. */
19187 while (n--)
19188 data = (data << 8) | 0xb0;
bfae80f2 19189
c19d1205
ZW
19190 return data;
19191 }
19192 size = 0;
19193 }
19194 else
19195 /* We get two opcodes "free" in the first word. */
19196 size = unwind.opcode_count - 2;
19197 }
19198 else
19199 /* An extra byte is required for the opcode count. */
19200 size = unwind.opcode_count + 1;
bfae80f2 19201
c19d1205
ZW
19202 size = (size + 3) >> 2;
19203 if (size > 0xff)
19204 as_bad (_("too many unwind opcodes"));
bfae80f2 19205
c19d1205
ZW
19206 frag_align (2, 0, 0);
19207 record_alignment (now_seg, 2);
19208 unwind.table_entry = expr_build_dot ();
19209
19210 /* Allocate the table entry. */
19211 ptr = frag_more ((size << 2) + 4);
19212 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19213
c19d1205 19214 switch (unwind.personality_index)
bfae80f2 19215 {
c19d1205
ZW
19216 case -1:
19217 /* ??? Should this be a PLT generating relocation? */
19218 /* Custom personality routine. */
19219 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19220 BFD_RELOC_ARM_PREL31);
bfae80f2 19221
c19d1205
ZW
19222 where += 4;
19223 ptr += 4;
bfae80f2 19224
c19d1205
ZW
19225 /* Set the first byte to the number of additional words. */
19226 data = size - 1;
19227 n = 3;
19228 break;
bfae80f2 19229
c19d1205
ZW
19230 /* ABI defined personality routines. */
19231 case 0:
19232 /* Three opcodes bytes are packed into the first word. */
19233 data = 0x80;
19234 n = 3;
19235 break;
bfae80f2 19236
c19d1205
ZW
19237 case 1:
19238 case 2:
19239 /* The size and first two opcode bytes go in the first word. */
19240 data = ((0x80 + unwind.personality_index) << 8) | size;
19241 n = 2;
19242 break;
bfae80f2 19243
c19d1205
ZW
19244 default:
19245 /* Should never happen. */
19246 abort ();
19247 }
bfae80f2 19248
c19d1205
ZW
19249 /* Pack the opcodes into words (MSB first), reversing the list at the same
19250 time. */
19251 while (unwind.opcode_count > 0)
19252 {
19253 if (n == 0)
19254 {
19255 md_number_to_chars (ptr, data, 4);
19256 ptr += 4;
19257 n = 4;
19258 data = 0;
19259 }
19260 unwind.opcode_count--;
19261 n--;
19262 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19263 }
19264
19265 /* Finish off the last word. */
19266 if (n < 4)
19267 {
19268 /* Pad with "finish" opcodes. */
19269 while (n--)
19270 data = (data << 8) | 0xb0;
19271
19272 md_number_to_chars (ptr, data, 4);
19273 }
19274
19275 if (!have_data)
19276 {
19277 /* Add an empty descriptor if there is no user-specified data. */
19278 ptr = frag_more (4);
19279 md_number_to_chars (ptr, 0, 4);
19280 }
19281
19282 return 0;
bfae80f2
RE
19283}
19284
f0927246
NC
19285
19286/* Initialize the DWARF-2 unwind information for this procedure. */
19287
19288void
19289tc_arm_frame_initial_instructions (void)
19290{
19291 cfi_add_CFA_def_cfa (REG_SP, 0);
19292}
19293#endif /* OBJ_ELF */
19294
c19d1205
ZW
19295/* Convert REGNAME to a DWARF-2 register number. */
19296
19297int
1df69f4f 19298tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19299{
1df69f4f 19300 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19301
19302 if (reg == FAIL)
19303 return -1;
19304
19305 return reg;
bfae80f2
RE
19306}
19307
f0927246 19308#ifdef TE_PE
c19d1205 19309void
f0927246 19310tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19311{
91d6fa6a 19312 expressionS exp;
bfae80f2 19313
91d6fa6a
NC
19314 exp.X_op = O_secrel;
19315 exp.X_add_symbol = symbol;
19316 exp.X_add_number = 0;
19317 emit_expr (&exp, size);
f0927246
NC
19318}
19319#endif
bfae80f2 19320
c19d1205 19321/* MD interface: Symbol and relocation handling. */
bfae80f2 19322
2fc8bdac
ZW
19323/* Return the address within the segment that a PC-relative fixup is
19324 relative to. For ARM, PC-relative fixups applied to instructions
19325 are generally relative to the location of the fixup plus 8 bytes.
19326 Thumb branches are offset by 4, and Thumb loads relative to PC
19327 require special handling. */
bfae80f2 19328
c19d1205 19329long
2fc8bdac 19330md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19331{
2fc8bdac
ZW
19332 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19333
19334 /* If this is pc-relative and we are going to emit a relocation
19335 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19336 will need. Otherwise we want to use the calculated base.
19337 For WinCE we skip the bias for externals as well, since this
19338 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19339 if (fixP->fx_pcrel
2fc8bdac 19340 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19341 || (arm_force_relocation (fixP)
19342#ifdef TE_WINCE
19343 && !S_IS_EXTERNAL (fixP->fx_addsy)
19344#endif
19345 )))
2fc8bdac 19346 base = 0;
bfae80f2 19347
267bf995 19348
c19d1205 19349 switch (fixP->fx_r_type)
bfae80f2 19350 {
2fc8bdac
ZW
19351 /* PC relative addressing on the Thumb is slightly odd as the
19352 bottom two bits of the PC are forced to zero for the
19353 calculation. This happens *after* application of the
19354 pipeline offset. However, Thumb adrl already adjusts for
19355 this, so we need not do it again. */
c19d1205 19356 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19357 return base & ~3;
c19d1205
ZW
19358
19359 case BFD_RELOC_ARM_THUMB_OFFSET:
19360 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19361 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19362 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19363 return (base + 4) & ~3;
c19d1205 19364
2fc8bdac
ZW
19365 /* Thumb branches are simply offset by +4. */
19366 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19367 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19368 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19369 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19370 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19371 return base + 4;
bfae80f2 19372
267bf995 19373 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19374 if (fixP->fx_addsy
19375 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19376 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19377 && ARM_IS_FUNC (fixP->fx_addsy)
19378 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19379 base = fixP->fx_where + fixP->fx_frag->fr_address;
19380 return base + 4;
19381
00adf2d4
JB
19382 /* BLX is like branches above, but forces the low two bits of PC to
19383 zero. */
486499d0
CL
19384 case BFD_RELOC_THUMB_PCREL_BLX:
19385 if (fixP->fx_addsy
19386 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19387 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19388 && THUMB_IS_FUNC (fixP->fx_addsy)
19389 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19390 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19391 return (base + 4) & ~3;
19392
2fc8bdac
ZW
19393 /* ARM mode branches are offset by +8. However, the Windows CE
19394 loader expects the relocation not to take this into account. */
267bf995 19395 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19396 if (fixP->fx_addsy
19397 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19398 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19399 && ARM_IS_FUNC (fixP->fx_addsy)
19400 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19401 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19402 return base + 8;
267bf995 19403
486499d0
CL
19404 case BFD_RELOC_ARM_PCREL_CALL:
19405 if (fixP->fx_addsy
19406 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19407 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19408 && THUMB_IS_FUNC (fixP->fx_addsy)
19409 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19410 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19411 return base + 8;
267bf995 19412
2fc8bdac 19413 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19414 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19415 case BFD_RELOC_ARM_PLT32:
c19d1205 19416#ifdef TE_WINCE
5f4273c7 19417 /* When handling fixups immediately, because we have already
53baae48
NC
19418 discovered the value of a symbol, or the address of the frag involved
19419 we must account for the offset by +8, as the OS loader will never see the reloc.
19420 see fixup_segment() in write.c
19421 The S_IS_EXTERNAL test handles the case of global symbols.
19422 Those need the calculated base, not just the pipe compensation the linker will need. */
19423 if (fixP->fx_pcrel
19424 && fixP->fx_addsy != NULL
19425 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19426 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19427 return base + 8;
2fc8bdac 19428 return base;
c19d1205 19429#else
2fc8bdac 19430 return base + 8;
c19d1205 19431#endif
2fc8bdac 19432
267bf995 19433
2fc8bdac
ZW
19434 /* ARM mode loads relative to PC are also offset by +8. Unlike
19435 branches, the Windows CE loader *does* expect the relocation
19436 to take this into account. */
19437 case BFD_RELOC_ARM_OFFSET_IMM:
19438 case BFD_RELOC_ARM_OFFSET_IMM8:
19439 case BFD_RELOC_ARM_HWLITERAL:
19440 case BFD_RELOC_ARM_LITERAL:
19441 case BFD_RELOC_ARM_CP_OFF_IMM:
19442 return base + 8;
19443
19444
19445 /* Other PC-relative relocations are un-offset. */
19446 default:
19447 return base;
19448 }
bfae80f2
RE
19449}
19450
c19d1205
ZW
19451/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19452 Otherwise we have no need to default values of symbols. */
19453
19454symbolS *
19455md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19456{
c19d1205
ZW
19457#ifdef OBJ_ELF
19458 if (name[0] == '_' && name[1] == 'G'
19459 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19460 {
19461 if (!GOT_symbol)
19462 {
19463 if (symbol_find (name))
bd3ba5d1 19464 as_bad (_("GOT already in the symbol table"));
bfae80f2 19465
c19d1205
ZW
19466 GOT_symbol = symbol_new (name, undefined_section,
19467 (valueT) 0, & zero_address_frag);
19468 }
bfae80f2 19469
c19d1205 19470 return GOT_symbol;
bfae80f2 19471 }
c19d1205 19472#endif
bfae80f2 19473
c921be7d 19474 return NULL;
bfae80f2
RE
19475}
19476
55cf6793 19477/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19478 computed as two separate immediate values, added together. We
19479 already know that this value cannot be computed by just one ARM
19480 instruction. */
19481
19482static unsigned int
19483validate_immediate_twopart (unsigned int val,
19484 unsigned int * highpart)
bfae80f2 19485{
c19d1205
ZW
19486 unsigned int a;
19487 unsigned int i;
bfae80f2 19488
c19d1205
ZW
19489 for (i = 0; i < 32; i += 2)
19490 if (((a = rotate_left (val, i)) & 0xff) != 0)
19491 {
19492 if (a & 0xff00)
19493 {
19494 if (a & ~ 0xffff)
19495 continue;
19496 * highpart = (a >> 8) | ((i + 24) << 7);
19497 }
19498 else if (a & 0xff0000)
19499 {
19500 if (a & 0xff000000)
19501 continue;
19502 * highpart = (a >> 16) | ((i + 16) << 7);
19503 }
19504 else
19505 {
9c2799c2 19506 gas_assert (a & 0xff000000);
c19d1205
ZW
19507 * highpart = (a >> 24) | ((i + 8) << 7);
19508 }
bfae80f2 19509
c19d1205
ZW
19510 return (a & 0xff) | (i << 7);
19511 }
bfae80f2 19512
c19d1205 19513 return FAIL;
bfae80f2
RE
19514}
19515
c19d1205
ZW
19516static int
19517validate_offset_imm (unsigned int val, int hwse)
19518{
19519 if ((hwse && val > 255) || val > 4095)
19520 return FAIL;
19521 return val;
19522}
bfae80f2 19523
55cf6793 19524/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19525 negative immediate constant by altering the instruction. A bit of
19526 a hack really.
19527 MOV <-> MVN
19528 AND <-> BIC
19529 ADC <-> SBC
19530 by inverting the second operand, and
19531 ADD <-> SUB
19532 CMP <-> CMN
19533 by negating the second operand. */
bfae80f2 19534
c19d1205
ZW
19535static int
19536negate_data_op (unsigned long * instruction,
19537 unsigned long value)
bfae80f2 19538{
c19d1205
ZW
19539 int op, new_inst;
19540 unsigned long negated, inverted;
bfae80f2 19541
c19d1205
ZW
19542 negated = encode_arm_immediate (-value);
19543 inverted = encode_arm_immediate (~value);
bfae80f2 19544
c19d1205
ZW
19545 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19546 switch (op)
bfae80f2 19547 {
c19d1205
ZW
19548 /* First negates. */
19549 case OPCODE_SUB: /* ADD <-> SUB */
19550 new_inst = OPCODE_ADD;
19551 value = negated;
19552 break;
bfae80f2 19553
c19d1205
ZW
19554 case OPCODE_ADD:
19555 new_inst = OPCODE_SUB;
19556 value = negated;
19557 break;
bfae80f2 19558
c19d1205
ZW
19559 case OPCODE_CMP: /* CMP <-> CMN */
19560 new_inst = OPCODE_CMN;
19561 value = negated;
19562 break;
bfae80f2 19563
c19d1205
ZW
19564 case OPCODE_CMN:
19565 new_inst = OPCODE_CMP;
19566 value = negated;
19567 break;
bfae80f2 19568
c19d1205
ZW
19569 /* Now Inverted ops. */
19570 case OPCODE_MOV: /* MOV <-> MVN */
19571 new_inst = OPCODE_MVN;
19572 value = inverted;
19573 break;
bfae80f2 19574
c19d1205
ZW
19575 case OPCODE_MVN:
19576 new_inst = OPCODE_MOV;
19577 value = inverted;
19578 break;
bfae80f2 19579
c19d1205
ZW
19580 case OPCODE_AND: /* AND <-> BIC */
19581 new_inst = OPCODE_BIC;
19582 value = inverted;
19583 break;
bfae80f2 19584
c19d1205
ZW
19585 case OPCODE_BIC:
19586 new_inst = OPCODE_AND;
19587 value = inverted;
19588 break;
bfae80f2 19589
c19d1205
ZW
19590 case OPCODE_ADC: /* ADC <-> SBC */
19591 new_inst = OPCODE_SBC;
19592 value = inverted;
19593 break;
bfae80f2 19594
c19d1205
ZW
19595 case OPCODE_SBC:
19596 new_inst = OPCODE_ADC;
19597 value = inverted;
19598 break;
bfae80f2 19599
c19d1205
ZW
19600 /* We cannot do anything. */
19601 default:
19602 return FAIL;
b99bd4ef
NC
19603 }
19604
c19d1205
ZW
19605 if (value == (unsigned) FAIL)
19606 return FAIL;
19607
19608 *instruction &= OPCODE_MASK;
19609 *instruction |= new_inst << DATA_OP_SHIFT;
19610 return value;
b99bd4ef
NC
19611}
19612
ef8d22e6
PB
19613/* Like negate_data_op, but for Thumb-2. */
19614
19615static unsigned int
16dd5e42 19616thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19617{
19618 int op, new_inst;
19619 int rd;
16dd5e42 19620 unsigned int negated, inverted;
ef8d22e6
PB
19621
19622 negated = encode_thumb32_immediate (-value);
19623 inverted = encode_thumb32_immediate (~value);
19624
19625 rd = (*instruction >> 8) & 0xf;
19626 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19627 switch (op)
19628 {
19629 /* ADD <-> SUB. Includes CMP <-> CMN. */
19630 case T2_OPCODE_SUB:
19631 new_inst = T2_OPCODE_ADD;
19632 value = negated;
19633 break;
19634
19635 case T2_OPCODE_ADD:
19636 new_inst = T2_OPCODE_SUB;
19637 value = negated;
19638 break;
19639
19640 /* ORR <-> ORN. Includes MOV <-> MVN. */
19641 case T2_OPCODE_ORR:
19642 new_inst = T2_OPCODE_ORN;
19643 value = inverted;
19644 break;
19645
19646 case T2_OPCODE_ORN:
19647 new_inst = T2_OPCODE_ORR;
19648 value = inverted;
19649 break;
19650
19651 /* AND <-> BIC. TST has no inverted equivalent. */
19652 case T2_OPCODE_AND:
19653 new_inst = T2_OPCODE_BIC;
19654 if (rd == 15)
19655 value = FAIL;
19656 else
19657 value = inverted;
19658 break;
19659
19660 case T2_OPCODE_BIC:
19661 new_inst = T2_OPCODE_AND;
19662 value = inverted;
19663 break;
19664
19665 /* ADC <-> SBC */
19666 case T2_OPCODE_ADC:
19667 new_inst = T2_OPCODE_SBC;
19668 value = inverted;
19669 break;
19670
19671 case T2_OPCODE_SBC:
19672 new_inst = T2_OPCODE_ADC;
19673 value = inverted;
19674 break;
19675
19676 /* We cannot do anything. */
19677 default:
19678 return FAIL;
19679 }
19680
16dd5e42 19681 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19682 return FAIL;
19683
19684 *instruction &= T2_OPCODE_MASK;
19685 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19686 return value;
19687}
19688
8f06b2d8
PB
19689/* Read a 32-bit thumb instruction from buf. */
19690static unsigned long
19691get_thumb32_insn (char * buf)
19692{
19693 unsigned long insn;
19694 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19695 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19696
19697 return insn;
19698}
19699
a8bc6c78
PB
19700
19701/* We usually want to set the low bit on the address of thumb function
19702 symbols. In particular .word foo - . should have the low bit set.
19703 Generic code tries to fold the difference of two symbols to
19704 a constant. Prevent this and force a relocation when the first symbols
19705 is a thumb function. */
c921be7d
NC
19706
19707bfd_boolean
a8bc6c78
PB
19708arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19709{
19710 if (op == O_subtract
19711 && l->X_op == O_symbol
19712 && r->X_op == O_symbol
19713 && THUMB_IS_FUNC (l->X_add_symbol))
19714 {
19715 l->X_op = O_subtract;
19716 l->X_op_symbol = r->X_add_symbol;
19717 l->X_add_number -= r->X_add_number;
c921be7d 19718 return TRUE;
a8bc6c78 19719 }
c921be7d 19720
a8bc6c78 19721 /* Process as normal. */
c921be7d 19722 return FALSE;
a8bc6c78
PB
19723}
19724
4a42ebbc
RR
19725/* Encode Thumb2 unconditional branches and calls. The encoding
19726 for the 2 are identical for the immediate values. */
19727
19728static void
19729encode_thumb2_b_bl_offset (char * buf, offsetT value)
19730{
19731#define T2I1I2MASK ((1 << 13) | (1 << 11))
19732 offsetT newval;
19733 offsetT newval2;
19734 addressT S, I1, I2, lo, hi;
19735
19736 S = (value >> 24) & 0x01;
19737 I1 = (value >> 23) & 0x01;
19738 I2 = (value >> 22) & 0x01;
19739 hi = (value >> 12) & 0x3ff;
19740 lo = (value >> 1) & 0x7ff;
19741 newval = md_chars_to_number (buf, THUMB_SIZE);
19742 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19743 newval |= (S << 10) | hi;
19744 newval2 &= ~T2I1I2MASK;
19745 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19746 md_number_to_chars (buf, newval, THUMB_SIZE);
19747 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19748}
19749
c19d1205 19750void
55cf6793 19751md_apply_fix (fixS * fixP,
c19d1205
ZW
19752 valueT * valP,
19753 segT seg)
19754{
19755 offsetT value = * valP;
19756 offsetT newval;
19757 unsigned int newimm;
19758 unsigned long temp;
19759 int sign;
19760 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19761
9c2799c2 19762 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19763
c19d1205 19764 /* Note whether this will delete the relocation. */
4962c51a 19765
c19d1205
ZW
19766 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19767 fixP->fx_done = 1;
b99bd4ef 19768
adbaf948 19769 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19770 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19771 for emit_reloc. */
19772 value &= 0xffffffff;
19773 value ^= 0x80000000;
5f4273c7 19774 value -= 0x80000000;
adbaf948
ZW
19775
19776 *valP = value;
c19d1205 19777 fixP->fx_addnumber = value;
b99bd4ef 19778
adbaf948
ZW
19779 /* Same treatment for fixP->fx_offset. */
19780 fixP->fx_offset &= 0xffffffff;
19781 fixP->fx_offset ^= 0x80000000;
19782 fixP->fx_offset -= 0x80000000;
19783
c19d1205 19784 switch (fixP->fx_r_type)
b99bd4ef 19785 {
c19d1205
ZW
19786 case BFD_RELOC_NONE:
19787 /* This will need to go in the object file. */
19788 fixP->fx_done = 0;
19789 break;
b99bd4ef 19790
c19d1205
ZW
19791 case BFD_RELOC_ARM_IMMEDIATE:
19792 /* We claim that this fixup has been processed here,
19793 even if in fact we generate an error because we do
19794 not have a reloc for it, so tc_gen_reloc will reject it. */
19795 fixP->fx_done = 1;
b99bd4ef 19796
77db8e2e 19797 if (fixP->fx_addsy)
b99bd4ef 19798 {
77db8e2e 19799 const char *msg = 0;
b99bd4ef 19800
77db8e2e
NC
19801 if (! S_IS_DEFINED (fixP->fx_addsy))
19802 msg = _("undefined symbol %s used as an immediate value");
19803 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19804 msg = _("symbol %s is in a different section");
19805 else if (S_IS_WEAK (fixP->fx_addsy))
19806 msg = _("symbol %s is weak and may be overridden later");
19807
19808 if (msg)
19809 {
19810 as_bad_where (fixP->fx_file, fixP->fx_line,
19811 msg, S_GET_NAME (fixP->fx_addsy));
19812 break;
19813 }
42e5fcbf
AS
19814 }
19815
c19d1205
ZW
19816 newimm = encode_arm_immediate (value);
19817 temp = md_chars_to_number (buf, INSN_SIZE);
19818
19819 /* If the instruction will fail, see if we can fix things up by
19820 changing the opcode. */
19821 if (newimm == (unsigned int) FAIL
19822 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19823 {
c19d1205
ZW
19824 as_bad_where (fixP->fx_file, fixP->fx_line,
19825 _("invalid constant (%lx) after fixup"),
19826 (unsigned long) value);
19827 break;
b99bd4ef 19828 }
b99bd4ef 19829
c19d1205
ZW
19830 newimm |= (temp & 0xfffff000);
19831 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19832 break;
b99bd4ef 19833
c19d1205
ZW
19834 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19835 {
19836 unsigned int highpart = 0;
19837 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19838
77db8e2e 19839 if (fixP->fx_addsy)
42e5fcbf 19840 {
77db8e2e 19841 const char *msg = 0;
42e5fcbf 19842
77db8e2e
NC
19843 if (! S_IS_DEFINED (fixP->fx_addsy))
19844 msg = _("undefined symbol %s used as an immediate value");
19845 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19846 msg = _("symbol %s is in a different section");
19847 else if (S_IS_WEAK (fixP->fx_addsy))
19848 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 19849
77db8e2e
NC
19850 if (msg)
19851 {
19852 as_bad_where (fixP->fx_file, fixP->fx_line,
19853 msg, S_GET_NAME (fixP->fx_addsy));
19854 break;
19855 }
19856 }
19857
c19d1205
ZW
19858 newimm = encode_arm_immediate (value);
19859 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19860
c19d1205
ZW
19861 /* If the instruction will fail, see if we can fix things up by
19862 changing the opcode. */
19863 if (newimm == (unsigned int) FAIL
19864 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19865 {
19866 /* No ? OK - try using two ADD instructions to generate
19867 the value. */
19868 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19869
c19d1205
ZW
19870 /* Yes - then make sure that the second instruction is
19871 also an add. */
19872 if (newimm != (unsigned int) FAIL)
19873 newinsn = temp;
19874 /* Still No ? Try using a negated value. */
19875 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19876 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19877 /* Otherwise - give up. */
19878 else
19879 {
19880 as_bad_where (fixP->fx_file, fixP->fx_line,
19881 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19882 (long) value);
19883 break;
19884 }
b99bd4ef 19885
c19d1205
ZW
19886 /* Replace the first operand in the 2nd instruction (which
19887 is the PC) with the destination register. We have
19888 already added in the PC in the first instruction and we
19889 do not want to do it again. */
19890 newinsn &= ~ 0xf0000;
19891 newinsn |= ((newinsn & 0x0f000) << 4);
19892 }
b99bd4ef 19893
c19d1205
ZW
19894 newimm |= (temp & 0xfffff000);
19895 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19896
c19d1205
ZW
19897 highpart |= (newinsn & 0xfffff000);
19898 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19899 }
19900 break;
b99bd4ef 19901
c19d1205 19902 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19903 if (!fixP->fx_done && seg->use_rela_p)
19904 value = 0;
19905
c19d1205
ZW
19906 case BFD_RELOC_ARM_LITERAL:
19907 sign = value >= 0;
b99bd4ef 19908
c19d1205
ZW
19909 if (value < 0)
19910 value = - value;
b99bd4ef 19911
c19d1205 19912 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19913 {
c19d1205
ZW
19914 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19915 as_bad_where (fixP->fx_file, fixP->fx_line,
19916 _("invalid literal constant: pool needs to be closer"));
19917 else
19918 as_bad_where (fixP->fx_file, fixP->fx_line,
19919 _("bad immediate value for offset (%ld)"),
19920 (long) value);
19921 break;
f03698e6
RE
19922 }
19923
c19d1205
ZW
19924 newval = md_chars_to_number (buf, INSN_SIZE);
19925 newval &= 0xff7ff000;
19926 newval |= value | (sign ? INDEX_UP : 0);
19927 md_number_to_chars (buf, newval, INSN_SIZE);
19928 break;
b99bd4ef 19929
c19d1205
ZW
19930 case BFD_RELOC_ARM_OFFSET_IMM8:
19931 case BFD_RELOC_ARM_HWLITERAL:
19932 sign = value >= 0;
b99bd4ef 19933
c19d1205
ZW
19934 if (value < 0)
19935 value = - value;
b99bd4ef 19936
c19d1205 19937 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19938 {
c19d1205
ZW
19939 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19940 as_bad_where (fixP->fx_file, fixP->fx_line,
19941 _("invalid literal constant: pool needs to be closer"));
19942 else
f9d4405b 19943 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19944 (long) value);
19945 break;
b99bd4ef
NC
19946 }
19947
c19d1205
ZW
19948 newval = md_chars_to_number (buf, INSN_SIZE);
19949 newval &= 0xff7ff0f0;
19950 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19951 md_number_to_chars (buf, newval, INSN_SIZE);
19952 break;
b99bd4ef 19953
c19d1205
ZW
19954 case BFD_RELOC_ARM_T32_OFFSET_U8:
19955 if (value < 0 || value > 1020 || value % 4 != 0)
19956 as_bad_where (fixP->fx_file, fixP->fx_line,
19957 _("bad immediate value for offset (%ld)"), (long) value);
19958 value /= 4;
b99bd4ef 19959
c19d1205 19960 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19961 newval |= value;
19962 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19963 break;
b99bd4ef 19964
c19d1205
ZW
19965 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19966 /* This is a complicated relocation used for all varieties of Thumb32
19967 load/store instruction with immediate offset:
19968
19969 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19970 *4, optional writeback(W)
19971 (doubleword load/store)
19972
19973 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19974 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19975 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19976 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19977 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19978
19979 Uppercase letters indicate bits that are already encoded at
19980 this point. Lowercase letters are our problem. For the
19981 second block of instructions, the secondary opcode nybble
19982 (bits 8..11) is present, and bit 23 is zero, even if this is
19983 a PC-relative operation. */
19984 newval = md_chars_to_number (buf, THUMB_SIZE);
19985 newval <<= 16;
19986 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19987
c19d1205 19988 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19989 {
c19d1205
ZW
19990 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19991 if (value >= 0)
19992 newval |= (1 << 23);
19993 else
19994 value = -value;
19995 if (value % 4 != 0)
19996 {
19997 as_bad_where (fixP->fx_file, fixP->fx_line,
19998 _("offset not a multiple of 4"));
19999 break;
20000 }
20001 value /= 4;
216d22bc 20002 if (value > 0xff)
c19d1205
ZW
20003 {
20004 as_bad_where (fixP->fx_file, fixP->fx_line,
20005 _("offset out of range"));
20006 break;
20007 }
20008 newval &= ~0xff;
b99bd4ef 20009 }
c19d1205 20010 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 20011 {
c19d1205
ZW
20012 /* PC-relative, 12-bit offset. */
20013 if (value >= 0)
20014 newval |= (1 << 23);
20015 else
20016 value = -value;
216d22bc 20017 if (value > 0xfff)
c19d1205
ZW
20018 {
20019 as_bad_where (fixP->fx_file, fixP->fx_line,
20020 _("offset out of range"));
20021 break;
20022 }
20023 newval &= ~0xfff;
b99bd4ef 20024 }
c19d1205 20025 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20026 {
c19d1205
ZW
20027 /* Writeback: 8-bit, +/- offset. */
20028 if (value >= 0)
20029 newval |= (1 << 9);
20030 else
20031 value = -value;
216d22bc 20032 if (value > 0xff)
c19d1205
ZW
20033 {
20034 as_bad_where (fixP->fx_file, fixP->fx_line,
20035 _("offset out of range"));
20036 break;
20037 }
20038 newval &= ~0xff;
b99bd4ef 20039 }
c19d1205 20040 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20041 {
c19d1205 20042 /* T-instruction: positive 8-bit offset. */
216d22bc 20043 if (value < 0 || value > 0xff)
b99bd4ef 20044 {
c19d1205
ZW
20045 as_bad_where (fixP->fx_file, fixP->fx_line,
20046 _("offset out of range"));
20047 break;
b99bd4ef 20048 }
c19d1205
ZW
20049 newval &= ~0xff;
20050 newval |= value;
b99bd4ef
NC
20051 }
20052 else
b99bd4ef 20053 {
c19d1205
ZW
20054 /* Positive 12-bit or negative 8-bit offset. */
20055 int limit;
20056 if (value >= 0)
b99bd4ef 20057 {
c19d1205
ZW
20058 newval |= (1 << 23);
20059 limit = 0xfff;
20060 }
20061 else
20062 {
20063 value = -value;
20064 limit = 0xff;
20065 }
20066 if (value > limit)
20067 {
20068 as_bad_where (fixP->fx_file, fixP->fx_line,
20069 _("offset out of range"));
20070 break;
b99bd4ef 20071 }
c19d1205 20072 newval &= ~limit;
b99bd4ef 20073 }
b99bd4ef 20074
c19d1205
ZW
20075 newval |= value;
20076 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20077 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20078 break;
404ff6b5 20079
c19d1205
ZW
20080 case BFD_RELOC_ARM_SHIFT_IMM:
20081 newval = md_chars_to_number (buf, INSN_SIZE);
20082 if (((unsigned long) value) > 32
20083 || (value == 32
20084 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20085 {
20086 as_bad_where (fixP->fx_file, fixP->fx_line,
20087 _("shift expression is too large"));
20088 break;
20089 }
404ff6b5 20090
c19d1205
ZW
20091 if (value == 0)
20092 /* Shifts of zero must be done as lsl. */
20093 newval &= ~0x60;
20094 else if (value == 32)
20095 value = 0;
20096 newval &= 0xfffff07f;
20097 newval |= (value & 0x1f) << 7;
20098 md_number_to_chars (buf, newval, INSN_SIZE);
20099 break;
404ff6b5 20100
c19d1205 20101 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20102 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20103 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20104 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20105 /* We claim that this fixup has been processed here,
20106 even if in fact we generate an error because we do
20107 not have a reloc for it, so tc_gen_reloc will reject it. */
20108 fixP->fx_done = 1;
404ff6b5 20109
c19d1205
ZW
20110 if (fixP->fx_addsy
20111 && ! S_IS_DEFINED (fixP->fx_addsy))
20112 {
20113 as_bad_where (fixP->fx_file, fixP->fx_line,
20114 _("undefined symbol %s used as an immediate value"),
20115 S_GET_NAME (fixP->fx_addsy));
20116 break;
20117 }
404ff6b5 20118
c19d1205
ZW
20119 newval = md_chars_to_number (buf, THUMB_SIZE);
20120 newval <<= 16;
20121 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20122
16805f35
PB
20123 newimm = FAIL;
20124 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20125 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20126 {
20127 newimm = encode_thumb32_immediate (value);
20128 if (newimm == (unsigned int) FAIL)
20129 newimm = thumb32_negate_data_op (&newval, value);
20130 }
16805f35
PB
20131 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20132 && newimm == (unsigned int) FAIL)
92e90b6e 20133 {
16805f35
PB
20134 /* Turn add/sum into addw/subw. */
20135 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20136 newval = (newval & 0xfeffffff) | 0x02000000;
20137
e9f89963
PB
20138 /* 12 bit immediate for addw/subw. */
20139 if (value < 0)
20140 {
20141 value = -value;
20142 newval ^= 0x00a00000;
20143 }
92e90b6e
PB
20144 if (value > 0xfff)
20145 newimm = (unsigned int) FAIL;
20146 else
20147 newimm = value;
20148 }
cc8a6dd0 20149
c19d1205 20150 if (newimm == (unsigned int)FAIL)
3631a3c8 20151 {
c19d1205
ZW
20152 as_bad_where (fixP->fx_file, fixP->fx_line,
20153 _("invalid constant (%lx) after fixup"),
20154 (unsigned long) value);
20155 break;
3631a3c8
NC
20156 }
20157
c19d1205
ZW
20158 newval |= (newimm & 0x800) << 15;
20159 newval |= (newimm & 0x700) << 4;
20160 newval |= (newimm & 0x0ff);
cc8a6dd0 20161
c19d1205
ZW
20162 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20163 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20164 break;
a737bd4d 20165
3eb17e6b 20166 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20167 if (((unsigned long) value) > 0xffff)
20168 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20169 _("invalid smc expression"));
2fc8bdac 20170 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20171 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20172 md_number_to_chars (buf, newval, INSN_SIZE);
20173 break;
a737bd4d 20174
c19d1205 20175 case BFD_RELOC_ARM_SWI:
adbaf948 20176 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20177 {
20178 if (((unsigned long) value) > 0xff)
20179 as_bad_where (fixP->fx_file, fixP->fx_line,
20180 _("invalid swi expression"));
2fc8bdac 20181 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20182 newval |= value;
20183 md_number_to_chars (buf, newval, THUMB_SIZE);
20184 }
20185 else
20186 {
20187 if (((unsigned long) value) > 0x00ffffff)
20188 as_bad_where (fixP->fx_file, fixP->fx_line,
20189 _("invalid swi expression"));
2fc8bdac 20190 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20191 newval |= value;
20192 md_number_to_chars (buf, newval, INSN_SIZE);
20193 }
20194 break;
a737bd4d 20195
c19d1205
ZW
20196 case BFD_RELOC_ARM_MULTI:
20197 if (((unsigned long) value) > 0xffff)
20198 as_bad_where (fixP->fx_file, fixP->fx_line,
20199 _("invalid expression in load/store multiple"));
20200 newval = value | md_chars_to_number (buf, INSN_SIZE);
20201 md_number_to_chars (buf, newval, INSN_SIZE);
20202 break;
a737bd4d 20203
c19d1205 20204#ifdef OBJ_ELF
39b41c9c 20205 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20206
20207 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20208 && fixP->fx_addsy
20209 && !S_IS_EXTERNAL (fixP->fx_addsy)
20210 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20211 && THUMB_IS_FUNC (fixP->fx_addsy))
20212 /* Flip the bl to blx. This is a simple flip
20213 bit here because we generate PCREL_CALL for
20214 unconditional bls. */
20215 {
20216 newval = md_chars_to_number (buf, INSN_SIZE);
20217 newval = newval | 0x10000000;
20218 md_number_to_chars (buf, newval, INSN_SIZE);
20219 temp = 1;
20220 fixP->fx_done = 1;
20221 }
39b41c9c
PB
20222 else
20223 temp = 3;
20224 goto arm_branch_common;
20225
20226 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20227 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20228 && fixP->fx_addsy
20229 && !S_IS_EXTERNAL (fixP->fx_addsy)
20230 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20231 && THUMB_IS_FUNC (fixP->fx_addsy))
20232 {
20233 /* This would map to a bl<cond>, b<cond>,
20234 b<always> to a Thumb function. We
20235 need to force a relocation for this particular
20236 case. */
20237 newval = md_chars_to_number (buf, INSN_SIZE);
20238 fixP->fx_done = 0;
20239 }
20240
2fc8bdac 20241 case BFD_RELOC_ARM_PLT32:
c19d1205 20242#endif
39b41c9c
PB
20243 case BFD_RELOC_ARM_PCREL_BRANCH:
20244 temp = 3;
20245 goto arm_branch_common;
a737bd4d 20246
39b41c9c 20247 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20248
39b41c9c 20249 temp = 1;
267bf995
RR
20250 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20251 && fixP->fx_addsy
20252 && !S_IS_EXTERNAL (fixP->fx_addsy)
20253 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20254 && ARM_IS_FUNC (fixP->fx_addsy))
20255 {
20256 /* Flip the blx to a bl and warn. */
20257 const char *name = S_GET_NAME (fixP->fx_addsy);
20258 newval = 0xeb000000;
20259 as_warn_where (fixP->fx_file, fixP->fx_line,
20260 _("blx to '%s' an ARM ISA state function changed to bl"),
20261 name);
20262 md_number_to_chars (buf, newval, INSN_SIZE);
20263 temp = 3;
20264 fixP->fx_done = 1;
20265 }
20266
20267#ifdef OBJ_ELF
20268 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20269 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20270#endif
20271
39b41c9c 20272 arm_branch_common:
c19d1205 20273 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20274 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20275 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20276 also be be clear. */
20277 if (value & temp)
c19d1205 20278 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20279 _("misaligned branch destination"));
20280 if ((value & (offsetT)0xfe000000) != (offsetT)0
20281 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20282 as_bad_where (fixP->fx_file, fixP->fx_line,
20283 _("branch out of range"));
a737bd4d 20284
2fc8bdac 20285 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20286 {
2fc8bdac
ZW
20287 newval = md_chars_to_number (buf, INSN_SIZE);
20288 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20289 /* Set the H bit on BLX instructions. */
20290 if (temp == 1)
20291 {
20292 if (value & 2)
20293 newval |= 0x01000000;
20294 else
20295 newval &= ~0x01000000;
20296 }
2fc8bdac 20297 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20298 }
c19d1205 20299 break;
a737bd4d 20300
25fe350b
MS
20301 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20302 /* CBZ can only branch forward. */
a737bd4d 20303
738755b0
MS
20304 /* Attempts to use CBZ to branch to the next instruction
20305 (which, strictly speaking, are prohibited) will be turned into
20306 no-ops.
20307
20308 FIXME: It may be better to remove the instruction completely and
20309 perform relaxation. */
20310 if (value == -2)
2fc8bdac
ZW
20311 {
20312 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20313 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20314 md_number_to_chars (buf, newval, THUMB_SIZE);
20315 }
738755b0
MS
20316 else
20317 {
20318 if (value & ~0x7e)
20319 as_bad_where (fixP->fx_file, fixP->fx_line,
20320 _("branch out of range"));
20321
20322 if (fixP->fx_done || !seg->use_rela_p)
20323 {
20324 newval = md_chars_to_number (buf, THUMB_SIZE);
20325 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20326 md_number_to_chars (buf, newval, THUMB_SIZE);
20327 }
20328 }
c19d1205 20329 break;
a737bd4d 20330
c19d1205 20331 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20332 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20333 as_bad_where (fixP->fx_file, fixP->fx_line,
20334 _("branch out of range"));
a737bd4d 20335
2fc8bdac
ZW
20336 if (fixP->fx_done || !seg->use_rela_p)
20337 {
20338 newval = md_chars_to_number (buf, THUMB_SIZE);
20339 newval |= (value & 0x1ff) >> 1;
20340 md_number_to_chars (buf, newval, THUMB_SIZE);
20341 }
c19d1205 20342 break;
a737bd4d 20343
c19d1205 20344 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20345 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20346 as_bad_where (fixP->fx_file, fixP->fx_line,
20347 _("branch out of range"));
a737bd4d 20348
2fc8bdac
ZW
20349 if (fixP->fx_done || !seg->use_rela_p)
20350 {
20351 newval = md_chars_to_number (buf, THUMB_SIZE);
20352 newval |= (value & 0xfff) >> 1;
20353 md_number_to_chars (buf, newval, THUMB_SIZE);
20354 }
c19d1205 20355 break;
a737bd4d 20356
c19d1205 20357 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20358 if (fixP->fx_addsy
20359 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20360 && !S_IS_EXTERNAL (fixP->fx_addsy)
20361 && S_IS_DEFINED (fixP->fx_addsy)
20362 && ARM_IS_FUNC (fixP->fx_addsy)
20363 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20364 {
20365 /* Force a relocation for a branch 20 bits wide. */
20366 fixP->fx_done = 0;
20367 }
2fc8bdac
ZW
20368 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20369 as_bad_where (fixP->fx_file, fixP->fx_line,
20370 _("conditional branch out of range"));
404ff6b5 20371
2fc8bdac
ZW
20372 if (fixP->fx_done || !seg->use_rela_p)
20373 {
20374 offsetT newval2;
20375 addressT S, J1, J2, lo, hi;
404ff6b5 20376
2fc8bdac
ZW
20377 S = (value & 0x00100000) >> 20;
20378 J2 = (value & 0x00080000) >> 19;
20379 J1 = (value & 0x00040000) >> 18;
20380 hi = (value & 0x0003f000) >> 12;
20381 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20382
2fc8bdac
ZW
20383 newval = md_chars_to_number (buf, THUMB_SIZE);
20384 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20385 newval |= (S << 10) | hi;
20386 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20387 md_number_to_chars (buf, newval, THUMB_SIZE);
20388 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20389 }
c19d1205 20390 break;
6c43fab6 20391
c19d1205 20392 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20393
20394 /* If there is a blx from a thumb state function to
20395 another thumb function flip this to a bl and warn
20396 about it. */
20397
20398 if (fixP->fx_addsy
20399 && S_IS_DEFINED (fixP->fx_addsy)
20400 && !S_IS_EXTERNAL (fixP->fx_addsy)
20401 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20402 && THUMB_IS_FUNC (fixP->fx_addsy))
20403 {
20404 const char *name = S_GET_NAME (fixP->fx_addsy);
20405 as_warn_where (fixP->fx_file, fixP->fx_line,
20406 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20407 name);
20408 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20409 newval = newval | 0x1000;
20410 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20411 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20412 fixP->fx_done = 1;
20413 }
20414
20415
20416 goto thumb_bl_common;
20417
c19d1205 20418 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20419
20420 /* A bl from Thumb state ISA to an internal ARM state function
20421 is converted to a blx. */
20422 if (fixP->fx_addsy
20423 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20424 && !S_IS_EXTERNAL (fixP->fx_addsy)
20425 && S_IS_DEFINED (fixP->fx_addsy)
20426 && ARM_IS_FUNC (fixP->fx_addsy)
20427 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20428 {
20429 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20430 newval = newval & ~0x1000;
20431 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20432 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20433 fixP->fx_done = 1;
20434 }
20435
20436 thumb_bl_common:
20437
20438#ifdef OBJ_ELF
20439 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20440 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20441 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20442#endif
20443
2fc8bdac
ZW
20444 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20445 /* For a BLX instruction, make sure that the relocation is rounded up
20446 to a word boundary. This follows the semantics of the instruction
20447 which specifies that bit 1 of the target address will come from bit
20448 1 of the base address. */
20449 value = (value + 1) & ~ 1;
404ff6b5 20450
2fc8bdac 20451
4a42ebbc
RR
20452 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20453 {
20454 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20455 {
20456 as_bad_where (fixP->fx_file, fixP->fx_line,
20457 _("branch out of range"));
20458 }
20459 else if ((value & ~0x1ffffff)
20460 && ((value & ~0x1ffffff) != ~0x1ffffff))
20461 {
20462 as_bad_where (fixP->fx_file, fixP->fx_line,
20463 _("Thumb2 branch out of range"));
20464 }
c19d1205 20465 }
4a42ebbc
RR
20466
20467 if (fixP->fx_done || !seg->use_rela_p)
20468 encode_thumb2_b_bl_offset (buf, value);
20469
c19d1205 20470 break;
404ff6b5 20471
c19d1205 20472 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20473 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20474 as_bad_where (fixP->fx_file, fixP->fx_line,
20475 _("branch out of range"));
6c43fab6 20476
2fc8bdac 20477 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20478 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20479
2fc8bdac 20480 break;
a737bd4d 20481
2fc8bdac
ZW
20482 case BFD_RELOC_8:
20483 if (fixP->fx_done || !seg->use_rela_p)
20484 md_number_to_chars (buf, value, 1);
c19d1205 20485 break;
a737bd4d 20486
c19d1205 20487 case BFD_RELOC_16:
2fc8bdac 20488 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20489 md_number_to_chars (buf, value, 2);
c19d1205 20490 break;
a737bd4d 20491
c19d1205
ZW
20492#ifdef OBJ_ELF
20493 case BFD_RELOC_ARM_TLS_GD32:
20494 case BFD_RELOC_ARM_TLS_LE32:
20495 case BFD_RELOC_ARM_TLS_IE32:
20496 case BFD_RELOC_ARM_TLS_LDM32:
20497 case BFD_RELOC_ARM_TLS_LDO32:
20498 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20499 /* fall through */
6c43fab6 20500
c19d1205
ZW
20501 case BFD_RELOC_ARM_GOT32:
20502 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20503 if (fixP->fx_done || !seg->use_rela_p)
20504 md_number_to_chars (buf, 0, 4);
c19d1205 20505 break;
b43420e6
NC
20506
20507 case BFD_RELOC_ARM_GOT_PREL:
20508 if (fixP->fx_done || !seg->use_rela_p)
20509 md_number_to_chars (buf, value, 4);
20510 break;
20511
9a6f4e97
NS
20512 case BFD_RELOC_ARM_TARGET2:
20513 /* TARGET2 is not partial-inplace, so we need to write the
20514 addend here for REL targets, because it won't be written out
20515 during reloc processing later. */
20516 if (fixP->fx_done || !seg->use_rela_p)
20517 md_number_to_chars (buf, fixP->fx_offset, 4);
20518 break;
c19d1205 20519#endif
6c43fab6 20520
c19d1205
ZW
20521 case BFD_RELOC_RVA:
20522 case BFD_RELOC_32:
20523 case BFD_RELOC_ARM_TARGET1:
20524 case BFD_RELOC_ARM_ROSEGREL32:
20525 case BFD_RELOC_ARM_SBREL32:
20526 case BFD_RELOC_32_PCREL:
f0927246
NC
20527#ifdef TE_PE
20528 case BFD_RELOC_32_SECREL:
20529#endif
2fc8bdac 20530 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20531#ifdef TE_WINCE
20532 /* For WinCE we only do this for pcrel fixups. */
20533 if (fixP->fx_done || fixP->fx_pcrel)
20534#endif
20535 md_number_to_chars (buf, value, 4);
c19d1205 20536 break;
6c43fab6 20537
c19d1205
ZW
20538#ifdef OBJ_ELF
20539 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20540 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20541 {
20542 newval = md_chars_to_number (buf, 4) & 0x80000000;
20543 if ((value ^ (value >> 1)) & 0x40000000)
20544 {
20545 as_bad_where (fixP->fx_file, fixP->fx_line,
20546 _("rel31 relocation overflow"));
20547 }
20548 newval |= value & 0x7fffffff;
20549 md_number_to_chars (buf, newval, 4);
20550 }
20551 break;
c19d1205 20552#endif
a737bd4d 20553
c19d1205 20554 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20555 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20556 if (value < -1023 || value > 1023 || (value & 3))
20557 as_bad_where (fixP->fx_file, fixP->fx_line,
20558 _("co-processor offset out of range"));
20559 cp_off_common:
20560 sign = value >= 0;
20561 if (value < 0)
20562 value = -value;
8f06b2d8
PB
20563 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20564 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20565 newval = md_chars_to_number (buf, INSN_SIZE);
20566 else
20567 newval = get_thumb32_insn (buf);
20568 newval &= 0xff7fff00;
c19d1205 20569 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20570 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20571 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20572 md_number_to_chars (buf, newval, INSN_SIZE);
20573 else
20574 put_thumb32_insn (buf, newval);
c19d1205 20575 break;
a737bd4d 20576
c19d1205 20577 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20578 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20579 if (value < -255 || value > 255)
20580 as_bad_where (fixP->fx_file, fixP->fx_line,
20581 _("co-processor offset out of range"));
df7849c5 20582 value *= 4;
c19d1205 20583 goto cp_off_common;
6c43fab6 20584
c19d1205
ZW
20585 case BFD_RELOC_ARM_THUMB_OFFSET:
20586 newval = md_chars_to_number (buf, THUMB_SIZE);
20587 /* Exactly what ranges, and where the offset is inserted depends
20588 on the type of instruction, we can establish this from the
20589 top 4 bits. */
20590 switch (newval >> 12)
20591 {
20592 case 4: /* PC load. */
20593 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20594 forced to zero for these loads; md_pcrel_from has already
20595 compensated for this. */
20596 if (value & 3)
20597 as_bad_where (fixP->fx_file, fixP->fx_line,
20598 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20599 (((unsigned long) fixP->fx_frag->fr_address
20600 + (unsigned long) fixP->fx_where) & ~3)
20601 + (unsigned long) value);
a737bd4d 20602
c19d1205
ZW
20603 if (value & ~0x3fc)
20604 as_bad_where (fixP->fx_file, fixP->fx_line,
20605 _("invalid offset, value too big (0x%08lX)"),
20606 (long) value);
a737bd4d 20607
c19d1205
ZW
20608 newval |= value >> 2;
20609 break;
a737bd4d 20610
c19d1205
ZW
20611 case 9: /* SP load/store. */
20612 if (value & ~0x3fc)
20613 as_bad_where (fixP->fx_file, fixP->fx_line,
20614 _("invalid offset, value too big (0x%08lX)"),
20615 (long) value);
20616 newval |= value >> 2;
20617 break;
6c43fab6 20618
c19d1205
ZW
20619 case 6: /* Word load/store. */
20620 if (value & ~0x7c)
20621 as_bad_where (fixP->fx_file, fixP->fx_line,
20622 _("invalid offset, value too big (0x%08lX)"),
20623 (long) value);
20624 newval |= value << 4; /* 6 - 2. */
20625 break;
a737bd4d 20626
c19d1205
ZW
20627 case 7: /* Byte load/store. */
20628 if (value & ~0x1f)
20629 as_bad_where (fixP->fx_file, fixP->fx_line,
20630 _("invalid offset, value too big (0x%08lX)"),
20631 (long) value);
20632 newval |= value << 6;
20633 break;
a737bd4d 20634
c19d1205
ZW
20635 case 8: /* Halfword load/store. */
20636 if (value & ~0x3e)
20637 as_bad_where (fixP->fx_file, fixP->fx_line,
20638 _("invalid offset, value too big (0x%08lX)"),
20639 (long) value);
20640 newval |= value << 5; /* 6 - 1. */
20641 break;
a737bd4d 20642
c19d1205
ZW
20643 default:
20644 as_bad_where (fixP->fx_file, fixP->fx_line,
20645 "Unable to process relocation for thumb opcode: %lx",
20646 (unsigned long) newval);
20647 break;
20648 }
20649 md_number_to_chars (buf, newval, THUMB_SIZE);
20650 break;
a737bd4d 20651
c19d1205
ZW
20652 case BFD_RELOC_ARM_THUMB_ADD:
20653 /* This is a complicated relocation, since we use it for all of
20654 the following immediate relocations:
a737bd4d 20655
c19d1205
ZW
20656 3bit ADD/SUB
20657 8bit ADD/SUB
20658 9bit ADD/SUB SP word-aligned
20659 10bit ADD PC/SP word-aligned
a737bd4d 20660
c19d1205
ZW
20661 The type of instruction being processed is encoded in the
20662 instruction field:
a737bd4d 20663
c19d1205
ZW
20664 0x8000 SUB
20665 0x00F0 Rd
20666 0x000F Rs
20667 */
20668 newval = md_chars_to_number (buf, THUMB_SIZE);
20669 {
20670 int rd = (newval >> 4) & 0xf;
20671 int rs = newval & 0xf;
20672 int subtract = !!(newval & 0x8000);
a737bd4d 20673
c19d1205
ZW
20674 /* Check for HI regs, only very restricted cases allowed:
20675 Adjusting SP, and using PC or SP to get an address. */
20676 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20677 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20678 as_bad_where (fixP->fx_file, fixP->fx_line,
20679 _("invalid Hi register with immediate"));
a737bd4d 20680
c19d1205
ZW
20681 /* If value is negative, choose the opposite instruction. */
20682 if (value < 0)
20683 {
20684 value = -value;
20685 subtract = !subtract;
20686 if (value < 0)
20687 as_bad_where (fixP->fx_file, fixP->fx_line,
20688 _("immediate value out of range"));
20689 }
a737bd4d 20690
c19d1205
ZW
20691 if (rd == REG_SP)
20692 {
20693 if (value & ~0x1fc)
20694 as_bad_where (fixP->fx_file, fixP->fx_line,
20695 _("invalid immediate for stack address calculation"));
20696 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20697 newval |= value >> 2;
20698 }
20699 else if (rs == REG_PC || rs == REG_SP)
20700 {
20701 if (subtract || value & ~0x3fc)
20702 as_bad_where (fixP->fx_file, fixP->fx_line,
20703 _("invalid immediate for address calculation (value = 0x%08lX)"),
20704 (unsigned long) value);
20705 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20706 newval |= rd << 8;
20707 newval |= value >> 2;
20708 }
20709 else if (rs == rd)
20710 {
20711 if (value & ~0xff)
20712 as_bad_where (fixP->fx_file, fixP->fx_line,
20713 _("immediate value out of range"));
20714 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20715 newval |= (rd << 8) | value;
20716 }
20717 else
20718 {
20719 if (value & ~0x7)
20720 as_bad_where (fixP->fx_file, fixP->fx_line,
20721 _("immediate value out of range"));
20722 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20723 newval |= rd | (rs << 3) | (value << 6);
20724 }
20725 }
20726 md_number_to_chars (buf, newval, THUMB_SIZE);
20727 break;
a737bd4d 20728
c19d1205
ZW
20729 case BFD_RELOC_ARM_THUMB_IMM:
20730 newval = md_chars_to_number (buf, THUMB_SIZE);
20731 if (value < 0 || value > 255)
20732 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20733 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20734 (long) value);
20735 newval |= value;
20736 md_number_to_chars (buf, newval, THUMB_SIZE);
20737 break;
a737bd4d 20738
c19d1205
ZW
20739 case BFD_RELOC_ARM_THUMB_SHIFT:
20740 /* 5bit shift value (0..32). LSL cannot take 32. */
20741 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20742 temp = newval & 0xf800;
20743 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20744 as_bad_where (fixP->fx_file, fixP->fx_line,
20745 _("invalid shift value: %ld"), (long) value);
20746 /* Shifts of zero must be encoded as LSL. */
20747 if (value == 0)
20748 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20749 /* Shifts of 32 are encoded as zero. */
20750 else if (value == 32)
20751 value = 0;
20752 newval |= value << 6;
20753 md_number_to_chars (buf, newval, THUMB_SIZE);
20754 break;
a737bd4d 20755
c19d1205
ZW
20756 case BFD_RELOC_VTABLE_INHERIT:
20757 case BFD_RELOC_VTABLE_ENTRY:
20758 fixP->fx_done = 0;
20759 return;
6c43fab6 20760
b6895b4f
PB
20761 case BFD_RELOC_ARM_MOVW:
20762 case BFD_RELOC_ARM_MOVT:
20763 case BFD_RELOC_ARM_THUMB_MOVW:
20764 case BFD_RELOC_ARM_THUMB_MOVT:
20765 if (fixP->fx_done || !seg->use_rela_p)
20766 {
20767 /* REL format relocations are limited to a 16-bit addend. */
20768 if (!fixP->fx_done)
20769 {
39623e12 20770 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20771 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20772 _("offset out of range"));
b6895b4f
PB
20773 }
20774 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20775 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20776 {
20777 value >>= 16;
20778 }
20779
20780 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20781 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20782 {
20783 newval = get_thumb32_insn (buf);
20784 newval &= 0xfbf08f00;
20785 newval |= (value & 0xf000) << 4;
20786 newval |= (value & 0x0800) << 15;
20787 newval |= (value & 0x0700) << 4;
20788 newval |= (value & 0x00ff);
20789 put_thumb32_insn (buf, newval);
20790 }
20791 else
20792 {
20793 newval = md_chars_to_number (buf, 4);
20794 newval &= 0xfff0f000;
20795 newval |= value & 0x0fff;
20796 newval |= (value & 0xf000) << 4;
20797 md_number_to_chars (buf, newval, 4);
20798 }
20799 }
20800 return;
20801
4962c51a
MS
20802 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20803 case BFD_RELOC_ARM_ALU_PC_G0:
20804 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20805 case BFD_RELOC_ARM_ALU_PC_G1:
20806 case BFD_RELOC_ARM_ALU_PC_G2:
20807 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20808 case BFD_RELOC_ARM_ALU_SB_G0:
20809 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20810 case BFD_RELOC_ARM_ALU_SB_G1:
20811 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20812 gas_assert (!fixP->fx_done);
4962c51a
MS
20813 if (!seg->use_rela_p)
20814 {
20815 bfd_vma insn;
20816 bfd_vma encoded_addend;
20817 bfd_vma addend_abs = abs (value);
20818
20819 /* Check that the absolute value of the addend can be
20820 expressed as an 8-bit constant plus a rotation. */
20821 encoded_addend = encode_arm_immediate (addend_abs);
20822 if (encoded_addend == (unsigned int) FAIL)
20823 as_bad_where (fixP->fx_file, fixP->fx_line,
20824 _("the offset 0x%08lX is not representable"),
495bde8e 20825 (unsigned long) addend_abs);
4962c51a
MS
20826
20827 /* Extract the instruction. */
20828 insn = md_chars_to_number (buf, INSN_SIZE);
20829
20830 /* If the addend is positive, use an ADD instruction.
20831 Otherwise use a SUB. Take care not to destroy the S bit. */
20832 insn &= 0xff1fffff;
20833 if (value < 0)
20834 insn |= 1 << 22;
20835 else
20836 insn |= 1 << 23;
20837
20838 /* Place the encoded addend into the first 12 bits of the
20839 instruction. */
20840 insn &= 0xfffff000;
20841 insn |= encoded_addend;
5f4273c7
NC
20842
20843 /* Update the instruction. */
4962c51a
MS
20844 md_number_to_chars (buf, insn, INSN_SIZE);
20845 }
20846 break;
20847
20848 case BFD_RELOC_ARM_LDR_PC_G0:
20849 case BFD_RELOC_ARM_LDR_PC_G1:
20850 case BFD_RELOC_ARM_LDR_PC_G2:
20851 case BFD_RELOC_ARM_LDR_SB_G0:
20852 case BFD_RELOC_ARM_LDR_SB_G1:
20853 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20854 gas_assert (!fixP->fx_done);
4962c51a
MS
20855 if (!seg->use_rela_p)
20856 {
20857 bfd_vma insn;
20858 bfd_vma addend_abs = abs (value);
20859
20860 /* Check that the absolute value of the addend can be
20861 encoded in 12 bits. */
20862 if (addend_abs >= 0x1000)
20863 as_bad_where (fixP->fx_file, fixP->fx_line,
20864 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20865 (unsigned long) addend_abs);
4962c51a
MS
20866
20867 /* Extract the instruction. */
20868 insn = md_chars_to_number (buf, INSN_SIZE);
20869
20870 /* If the addend is negative, clear bit 23 of the instruction.
20871 Otherwise set it. */
20872 if (value < 0)
20873 insn &= ~(1 << 23);
20874 else
20875 insn |= 1 << 23;
20876
20877 /* Place the absolute value of the addend into the first 12 bits
20878 of the instruction. */
20879 insn &= 0xfffff000;
20880 insn |= addend_abs;
5f4273c7
NC
20881
20882 /* Update the instruction. */
4962c51a
MS
20883 md_number_to_chars (buf, insn, INSN_SIZE);
20884 }
20885 break;
20886
20887 case BFD_RELOC_ARM_LDRS_PC_G0:
20888 case BFD_RELOC_ARM_LDRS_PC_G1:
20889 case BFD_RELOC_ARM_LDRS_PC_G2:
20890 case BFD_RELOC_ARM_LDRS_SB_G0:
20891 case BFD_RELOC_ARM_LDRS_SB_G1:
20892 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20893 gas_assert (!fixP->fx_done);
4962c51a
MS
20894 if (!seg->use_rela_p)
20895 {
20896 bfd_vma insn;
20897 bfd_vma addend_abs = abs (value);
20898
20899 /* Check that the absolute value of the addend can be
20900 encoded in 8 bits. */
20901 if (addend_abs >= 0x100)
20902 as_bad_where (fixP->fx_file, fixP->fx_line,
20903 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20904 (unsigned long) addend_abs);
4962c51a
MS
20905
20906 /* Extract the instruction. */
20907 insn = md_chars_to_number (buf, INSN_SIZE);
20908
20909 /* If the addend is negative, clear bit 23 of the instruction.
20910 Otherwise set it. */
20911 if (value < 0)
20912 insn &= ~(1 << 23);
20913 else
20914 insn |= 1 << 23;
20915
20916 /* Place the first four bits of the absolute value of the addend
20917 into the first 4 bits of the instruction, and the remaining
20918 four into bits 8 .. 11. */
20919 insn &= 0xfffff0f0;
20920 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20921
20922 /* Update the instruction. */
4962c51a
MS
20923 md_number_to_chars (buf, insn, INSN_SIZE);
20924 }
20925 break;
20926
20927 case BFD_RELOC_ARM_LDC_PC_G0:
20928 case BFD_RELOC_ARM_LDC_PC_G1:
20929 case BFD_RELOC_ARM_LDC_PC_G2:
20930 case BFD_RELOC_ARM_LDC_SB_G0:
20931 case BFD_RELOC_ARM_LDC_SB_G1:
20932 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20933 gas_assert (!fixP->fx_done);
4962c51a
MS
20934 if (!seg->use_rela_p)
20935 {
20936 bfd_vma insn;
20937 bfd_vma addend_abs = abs (value);
20938
20939 /* Check that the absolute value of the addend is a multiple of
20940 four and, when divided by four, fits in 8 bits. */
20941 if (addend_abs & 0x3)
20942 as_bad_where (fixP->fx_file, fixP->fx_line,
20943 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20944 (unsigned long) addend_abs);
4962c51a
MS
20945
20946 if ((addend_abs >> 2) > 0xff)
20947 as_bad_where (fixP->fx_file, fixP->fx_line,
20948 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20949 (unsigned long) addend_abs);
4962c51a
MS
20950
20951 /* Extract the instruction. */
20952 insn = md_chars_to_number (buf, INSN_SIZE);
20953
20954 /* If the addend is negative, clear bit 23 of the instruction.
20955 Otherwise set it. */
20956 if (value < 0)
20957 insn &= ~(1 << 23);
20958 else
20959 insn |= 1 << 23;
20960
20961 /* Place the addend (divided by four) into the first eight
20962 bits of the instruction. */
20963 insn &= 0xfffffff0;
20964 insn |= addend_abs >> 2;
5f4273c7
NC
20965
20966 /* Update the instruction. */
4962c51a
MS
20967 md_number_to_chars (buf, insn, INSN_SIZE);
20968 }
20969 break;
20970
845b51d6
PB
20971 case BFD_RELOC_ARM_V4BX:
20972 /* This will need to go in the object file. */
20973 fixP->fx_done = 0;
20974 break;
20975
c19d1205
ZW
20976 case BFD_RELOC_UNUSED:
20977 default:
20978 as_bad_where (fixP->fx_file, fixP->fx_line,
20979 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20980 }
6c43fab6
RE
20981}
20982
c19d1205
ZW
20983/* Translate internal representation of relocation info to BFD target
20984 format. */
a737bd4d 20985
c19d1205 20986arelent *
00a97672 20987tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20988{
c19d1205
ZW
20989 arelent * reloc;
20990 bfd_reloc_code_real_type code;
a737bd4d 20991
21d799b5 20992 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 20993
21d799b5 20994 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
20995 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20996 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20997
2fc8bdac 20998 if (fixp->fx_pcrel)
00a97672
RS
20999 {
21000 if (section->use_rela_p)
21001 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21002 else
21003 fixp->fx_offset = reloc->address;
21004 }
c19d1205 21005 reloc->addend = fixp->fx_offset;
a737bd4d 21006
c19d1205 21007 switch (fixp->fx_r_type)
a737bd4d 21008 {
c19d1205
ZW
21009 case BFD_RELOC_8:
21010 if (fixp->fx_pcrel)
21011 {
21012 code = BFD_RELOC_8_PCREL;
21013 break;
21014 }
a737bd4d 21015
c19d1205
ZW
21016 case BFD_RELOC_16:
21017 if (fixp->fx_pcrel)
21018 {
21019 code = BFD_RELOC_16_PCREL;
21020 break;
21021 }
6c43fab6 21022
c19d1205
ZW
21023 case BFD_RELOC_32:
21024 if (fixp->fx_pcrel)
21025 {
21026 code = BFD_RELOC_32_PCREL;
21027 break;
21028 }
a737bd4d 21029
b6895b4f
PB
21030 case BFD_RELOC_ARM_MOVW:
21031 if (fixp->fx_pcrel)
21032 {
21033 code = BFD_RELOC_ARM_MOVW_PCREL;
21034 break;
21035 }
21036
21037 case BFD_RELOC_ARM_MOVT:
21038 if (fixp->fx_pcrel)
21039 {
21040 code = BFD_RELOC_ARM_MOVT_PCREL;
21041 break;
21042 }
21043
21044 case BFD_RELOC_ARM_THUMB_MOVW:
21045 if (fixp->fx_pcrel)
21046 {
21047 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21048 break;
21049 }
21050
21051 case BFD_RELOC_ARM_THUMB_MOVT:
21052 if (fixp->fx_pcrel)
21053 {
21054 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21055 break;
21056 }
21057
c19d1205
ZW
21058 case BFD_RELOC_NONE:
21059 case BFD_RELOC_ARM_PCREL_BRANCH:
21060 case BFD_RELOC_ARM_PCREL_BLX:
21061 case BFD_RELOC_RVA:
21062 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21063 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21064 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21065 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21066 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21067 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21068 case BFD_RELOC_VTABLE_ENTRY:
21069 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21070#ifdef TE_PE
21071 case BFD_RELOC_32_SECREL:
21072#endif
c19d1205
ZW
21073 code = fixp->fx_r_type;
21074 break;
a737bd4d 21075
00adf2d4
JB
21076 case BFD_RELOC_THUMB_PCREL_BLX:
21077#ifdef OBJ_ELF
21078 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21079 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21080 else
21081#endif
21082 code = BFD_RELOC_THUMB_PCREL_BLX;
21083 break;
21084
c19d1205
ZW
21085 case BFD_RELOC_ARM_LITERAL:
21086 case BFD_RELOC_ARM_HWLITERAL:
21087 /* If this is called then the a literal has
21088 been referenced across a section boundary. */
21089 as_bad_where (fixp->fx_file, fixp->fx_line,
21090 _("literal referenced across section boundary"));
21091 return NULL;
a737bd4d 21092
c19d1205
ZW
21093#ifdef OBJ_ELF
21094 case BFD_RELOC_ARM_GOT32:
21095 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21096 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21097 case BFD_RELOC_ARM_PLT32:
21098 case BFD_RELOC_ARM_TARGET1:
21099 case BFD_RELOC_ARM_ROSEGREL32:
21100 case BFD_RELOC_ARM_SBREL32:
21101 case BFD_RELOC_ARM_PREL31:
21102 case BFD_RELOC_ARM_TARGET2:
21103 case BFD_RELOC_ARM_TLS_LE32:
21104 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21105 case BFD_RELOC_ARM_PCREL_CALL:
21106 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21107 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21108 case BFD_RELOC_ARM_ALU_PC_G0:
21109 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21110 case BFD_RELOC_ARM_ALU_PC_G1:
21111 case BFD_RELOC_ARM_ALU_PC_G2:
21112 case BFD_RELOC_ARM_LDR_PC_G0:
21113 case BFD_RELOC_ARM_LDR_PC_G1:
21114 case BFD_RELOC_ARM_LDR_PC_G2:
21115 case BFD_RELOC_ARM_LDRS_PC_G0:
21116 case BFD_RELOC_ARM_LDRS_PC_G1:
21117 case BFD_RELOC_ARM_LDRS_PC_G2:
21118 case BFD_RELOC_ARM_LDC_PC_G0:
21119 case BFD_RELOC_ARM_LDC_PC_G1:
21120 case BFD_RELOC_ARM_LDC_PC_G2:
21121 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21122 case BFD_RELOC_ARM_ALU_SB_G0:
21123 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21124 case BFD_RELOC_ARM_ALU_SB_G1:
21125 case BFD_RELOC_ARM_ALU_SB_G2:
21126 case BFD_RELOC_ARM_LDR_SB_G0:
21127 case BFD_RELOC_ARM_LDR_SB_G1:
21128 case BFD_RELOC_ARM_LDR_SB_G2:
21129 case BFD_RELOC_ARM_LDRS_SB_G0:
21130 case BFD_RELOC_ARM_LDRS_SB_G1:
21131 case BFD_RELOC_ARM_LDRS_SB_G2:
21132 case BFD_RELOC_ARM_LDC_SB_G0:
21133 case BFD_RELOC_ARM_LDC_SB_G1:
21134 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21135 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21136 code = fixp->fx_r_type;
21137 break;
a737bd4d 21138
c19d1205
ZW
21139 case BFD_RELOC_ARM_TLS_GD32:
21140 case BFD_RELOC_ARM_TLS_IE32:
21141 case BFD_RELOC_ARM_TLS_LDM32:
21142 /* BFD will include the symbol's address in the addend.
21143 But we don't want that, so subtract it out again here. */
21144 if (!S_IS_COMMON (fixp->fx_addsy))
21145 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21146 code = fixp->fx_r_type;
21147 break;
21148#endif
a737bd4d 21149
c19d1205
ZW
21150 case BFD_RELOC_ARM_IMMEDIATE:
21151 as_bad_where (fixp->fx_file, fixp->fx_line,
21152 _("internal relocation (type: IMMEDIATE) not fixed up"));
21153 return NULL;
a737bd4d 21154
c19d1205
ZW
21155 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21156 as_bad_where (fixp->fx_file, fixp->fx_line,
21157 _("ADRL used for a symbol not defined in the same file"));
21158 return NULL;
a737bd4d 21159
c19d1205 21160 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21161 if (section->use_rela_p)
21162 {
21163 code = fixp->fx_r_type;
21164 break;
21165 }
21166
c19d1205
ZW
21167 if (fixp->fx_addsy != NULL
21168 && !S_IS_DEFINED (fixp->fx_addsy)
21169 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21170 {
c19d1205
ZW
21171 as_bad_where (fixp->fx_file, fixp->fx_line,
21172 _("undefined local label `%s'"),
21173 S_GET_NAME (fixp->fx_addsy));
21174 return NULL;
a737bd4d
NC
21175 }
21176
c19d1205
ZW
21177 as_bad_where (fixp->fx_file, fixp->fx_line,
21178 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21179 return NULL;
a737bd4d 21180
c19d1205
ZW
21181 default:
21182 {
21183 char * type;
6c43fab6 21184
c19d1205
ZW
21185 switch (fixp->fx_r_type)
21186 {
21187 case BFD_RELOC_NONE: type = "NONE"; break;
21188 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21189 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21190 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21191 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21192 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21193 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 21194 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21195 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21196 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21197 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21198 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21199 default: type = _("<unknown>"); break;
21200 }
21201 as_bad_where (fixp->fx_file, fixp->fx_line,
21202 _("cannot represent %s relocation in this object file format"),
21203 type);
21204 return NULL;
21205 }
a737bd4d 21206 }
6c43fab6 21207
c19d1205
ZW
21208#ifdef OBJ_ELF
21209 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21210 && GOT_symbol
21211 && fixp->fx_addsy == GOT_symbol)
21212 {
21213 code = BFD_RELOC_ARM_GOTPC;
21214 reloc->addend = fixp->fx_offset = reloc->address;
21215 }
21216#endif
6c43fab6 21217
c19d1205 21218 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21219
c19d1205
ZW
21220 if (reloc->howto == NULL)
21221 {
21222 as_bad_where (fixp->fx_file, fixp->fx_line,
21223 _("cannot represent %s relocation in this object file format"),
21224 bfd_get_reloc_code_name (code));
21225 return NULL;
21226 }
6c43fab6 21227
c19d1205
ZW
21228 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21229 vtable entry to be used in the relocation's section offset. */
21230 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21231 reloc->address = fixp->fx_offset;
6c43fab6 21232
c19d1205 21233 return reloc;
6c43fab6
RE
21234}
21235
c19d1205 21236/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21237
c19d1205
ZW
21238void
21239cons_fix_new_arm (fragS * frag,
21240 int where,
21241 int size,
21242 expressionS * exp)
6c43fab6 21243{
c19d1205
ZW
21244 bfd_reloc_code_real_type type;
21245 int pcrel = 0;
6c43fab6 21246
c19d1205
ZW
21247 /* Pick a reloc.
21248 FIXME: @@ Should look at CPU word size. */
21249 switch (size)
21250 {
21251 case 1:
21252 type = BFD_RELOC_8;
21253 break;
21254 case 2:
21255 type = BFD_RELOC_16;
21256 break;
21257 case 4:
21258 default:
21259 type = BFD_RELOC_32;
21260 break;
21261 case 8:
21262 type = BFD_RELOC_64;
21263 break;
21264 }
6c43fab6 21265
f0927246
NC
21266#ifdef TE_PE
21267 if (exp->X_op == O_secrel)
21268 {
21269 exp->X_op = O_symbol;
21270 type = BFD_RELOC_32_SECREL;
21271 }
21272#endif
21273
c19d1205
ZW
21274 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21275}
6c43fab6 21276
4343666d 21277#if defined (OBJ_COFF)
c19d1205
ZW
21278void
21279arm_validate_fix (fixS * fixP)
6c43fab6 21280{
c19d1205
ZW
21281 /* If the destination of the branch is a defined symbol which does not have
21282 the THUMB_FUNC attribute, then we must be calling a function which has
21283 the (interfacearm) attribute. We look for the Thumb entry point to that
21284 function and change the branch to refer to that function instead. */
21285 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21286 && fixP->fx_addsy != NULL
21287 && S_IS_DEFINED (fixP->fx_addsy)
21288 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21289 {
c19d1205 21290 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21291 }
c19d1205
ZW
21292}
21293#endif
6c43fab6 21294
267bf995 21295
c19d1205
ZW
21296int
21297arm_force_relocation (struct fix * fixp)
21298{
21299#if defined (OBJ_COFF) && defined (TE_PE)
21300 if (fixp->fx_r_type == BFD_RELOC_RVA)
21301 return 1;
21302#endif
6c43fab6 21303
267bf995
RR
21304 /* In case we have a call or a branch to a function in ARM ISA mode from
21305 a thumb function or vice-versa force the relocation. These relocations
21306 are cleared off for some cores that might have blx and simple transformations
21307 are possible. */
21308
21309#ifdef OBJ_ELF
21310 switch (fixp->fx_r_type)
21311 {
21312 case BFD_RELOC_ARM_PCREL_JUMP:
21313 case BFD_RELOC_ARM_PCREL_CALL:
21314 case BFD_RELOC_THUMB_PCREL_BLX:
21315 if (THUMB_IS_FUNC (fixp->fx_addsy))
21316 return 1;
21317 break;
21318
21319 case BFD_RELOC_ARM_PCREL_BLX:
21320 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21321 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21322 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21323 if (ARM_IS_FUNC (fixp->fx_addsy))
21324 return 1;
21325 break;
21326
21327 default:
21328 break;
21329 }
21330#endif
21331
c19d1205
ZW
21332 /* Resolve these relocations even if the symbol is extern or weak. */
21333 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21334 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21335 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21336 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21337 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21338 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21339 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21340 return 0;
a737bd4d 21341
4962c51a
MS
21342 /* Always leave these relocations for the linker. */
21343 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21344 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21345 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21346 return 1;
21347
f0291e4c
PB
21348 /* Always generate relocations against function symbols. */
21349 if (fixp->fx_r_type == BFD_RELOC_32
21350 && fixp->fx_addsy
21351 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21352 return 1;
21353
c19d1205 21354 return generic_force_reloc (fixp);
404ff6b5
AH
21355}
21356
0ffdc86c 21357#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21358/* Relocations against function names must be left unadjusted,
21359 so that the linker can use this information to generate interworking
21360 stubs. The MIPS version of this function
c19d1205
ZW
21361 also prevents relocations that are mips-16 specific, but I do not
21362 know why it does this.
404ff6b5 21363
c19d1205
ZW
21364 FIXME:
21365 There is one other problem that ought to be addressed here, but
21366 which currently is not: Taking the address of a label (rather
21367 than a function) and then later jumping to that address. Such
21368 addresses also ought to have their bottom bit set (assuming that
21369 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21370
c19d1205
ZW
21371bfd_boolean
21372arm_fix_adjustable (fixS * fixP)
404ff6b5 21373{
c19d1205
ZW
21374 if (fixP->fx_addsy == NULL)
21375 return 1;
404ff6b5 21376
e28387c3
PB
21377 /* Preserve relocations against symbols with function type. */
21378 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21379 return FALSE;
e28387c3 21380
c19d1205
ZW
21381 if (THUMB_IS_FUNC (fixP->fx_addsy)
21382 && fixP->fx_subsy == NULL)
c921be7d 21383 return FALSE;
a737bd4d 21384
c19d1205
ZW
21385 /* We need the symbol name for the VTABLE entries. */
21386 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21387 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21388 return FALSE;
404ff6b5 21389
c19d1205
ZW
21390 /* Don't allow symbols to be discarded on GOT related relocs. */
21391 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21392 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21393 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21394 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21395 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21396 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21397 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21398 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21399 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21400 return FALSE;
a737bd4d 21401
4962c51a
MS
21402 /* Similarly for group relocations. */
21403 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21404 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21405 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21406 return FALSE;
4962c51a 21407
79947c54
CD
21408 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21409 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21410 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21411 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21412 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21413 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21414 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21415 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21416 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21417 return FALSE;
79947c54 21418
c921be7d 21419 return TRUE;
a737bd4d 21420}
0ffdc86c
NC
21421#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21422
21423#ifdef OBJ_ELF
404ff6b5 21424
c19d1205
ZW
21425const char *
21426elf32_arm_target_format (void)
404ff6b5 21427{
c19d1205
ZW
21428#ifdef TE_SYMBIAN
21429 return (target_big_endian
21430 ? "elf32-bigarm-symbian"
21431 : "elf32-littlearm-symbian");
21432#elif defined (TE_VXWORKS)
21433 return (target_big_endian
21434 ? "elf32-bigarm-vxworks"
21435 : "elf32-littlearm-vxworks");
21436#else
21437 if (target_big_endian)
21438 return "elf32-bigarm";
21439 else
21440 return "elf32-littlearm";
21441#endif
404ff6b5
AH
21442}
21443
c19d1205
ZW
21444void
21445armelf_frob_symbol (symbolS * symp,
21446 int * puntp)
404ff6b5 21447{
c19d1205
ZW
21448 elf_frob_symbol (symp, puntp);
21449}
21450#endif
404ff6b5 21451
c19d1205 21452/* MD interface: Finalization. */
a737bd4d 21453
c19d1205
ZW
21454void
21455arm_cleanup (void)
21456{
21457 literal_pool * pool;
a737bd4d 21458
e07e6e58
NC
21459 /* Ensure that all the IT blocks are properly closed. */
21460 check_it_blocks_finished ();
21461
c19d1205
ZW
21462 for (pool = list_of_pools; pool; pool = pool->next)
21463 {
5f4273c7 21464 /* Put it at the end of the relevant section. */
c19d1205
ZW
21465 subseg_set (pool->section, pool->sub_section);
21466#ifdef OBJ_ELF
21467 arm_elf_change_section ();
21468#endif
21469 s_ltorg (0);
21470 }
404ff6b5
AH
21471}
21472
cd000bff
DJ
21473#ifdef OBJ_ELF
21474/* Remove any excess mapping symbols generated for alignment frags in
21475 SEC. We may have created a mapping symbol before a zero byte
21476 alignment; remove it if there's a mapping symbol after the
21477 alignment. */
21478static void
21479check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21480 void *dummy ATTRIBUTE_UNUSED)
21481{
21482 segment_info_type *seginfo = seg_info (sec);
21483 fragS *fragp;
21484
21485 if (seginfo == NULL || seginfo->frchainP == NULL)
21486 return;
21487
21488 for (fragp = seginfo->frchainP->frch_root;
21489 fragp != NULL;
21490 fragp = fragp->fr_next)
21491 {
21492 symbolS *sym = fragp->tc_frag_data.last_map;
21493 fragS *next = fragp->fr_next;
21494
21495 /* Variable-sized frags have been converted to fixed size by
21496 this point. But if this was variable-sized to start with,
21497 there will be a fixed-size frag after it. So don't handle
21498 next == NULL. */
21499 if (sym == NULL || next == NULL)
21500 continue;
21501
21502 if (S_GET_VALUE (sym) < next->fr_address)
21503 /* Not at the end of this frag. */
21504 continue;
21505 know (S_GET_VALUE (sym) == next->fr_address);
21506
21507 do
21508 {
21509 if (next->tc_frag_data.first_map != NULL)
21510 {
21511 /* Next frag starts with a mapping symbol. Discard this
21512 one. */
21513 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21514 break;
21515 }
21516
21517 if (next->fr_next == NULL)
21518 {
21519 /* This mapping symbol is at the end of the section. Discard
21520 it. */
21521 know (next->fr_fix == 0 && next->fr_var == 0);
21522 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21523 break;
21524 }
21525
21526 /* As long as we have empty frags without any mapping symbols,
21527 keep looking. */
21528 /* If the next frag is non-empty and does not start with a
21529 mapping symbol, then this mapping symbol is required. */
21530 if (next->fr_address != next->fr_next->fr_address)
21531 break;
21532
21533 next = next->fr_next;
21534 }
21535 while (next != NULL);
21536 }
21537}
21538#endif
21539
c19d1205
ZW
21540/* Adjust the symbol table. This marks Thumb symbols as distinct from
21541 ARM ones. */
404ff6b5 21542
c19d1205
ZW
21543void
21544arm_adjust_symtab (void)
404ff6b5 21545{
c19d1205
ZW
21546#ifdef OBJ_COFF
21547 symbolS * sym;
404ff6b5 21548
c19d1205
ZW
21549 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21550 {
21551 if (ARM_IS_THUMB (sym))
21552 {
21553 if (THUMB_IS_FUNC (sym))
21554 {
21555 /* Mark the symbol as a Thumb function. */
21556 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21557 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21558 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21559
c19d1205
ZW
21560 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21561 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21562 else
21563 as_bad (_("%s: unexpected function type: %d"),
21564 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21565 }
21566 else switch (S_GET_STORAGE_CLASS (sym))
21567 {
21568 case C_EXT:
21569 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21570 break;
21571 case C_STAT:
21572 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21573 break;
21574 case C_LABEL:
21575 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21576 break;
21577 default:
21578 /* Do nothing. */
21579 break;
21580 }
21581 }
a737bd4d 21582
c19d1205
ZW
21583 if (ARM_IS_INTERWORK (sym))
21584 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21585 }
c19d1205
ZW
21586#endif
21587#ifdef OBJ_ELF
21588 symbolS * sym;
21589 char bind;
404ff6b5 21590
c19d1205 21591 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21592 {
c19d1205
ZW
21593 if (ARM_IS_THUMB (sym))
21594 {
21595 elf_symbol_type * elf_sym;
404ff6b5 21596
c19d1205
ZW
21597 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21598 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21599
b0796911
PB
21600 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21601 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21602 {
21603 /* If it's a .thumb_func, declare it as so,
21604 otherwise tag label as .code 16. */
21605 if (THUMB_IS_FUNC (sym))
21606 elf_sym->internal_elf_sym.st_info =
21607 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21608 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21609 elf_sym->internal_elf_sym.st_info =
21610 ELF_ST_INFO (bind, STT_ARM_16BIT);
21611 }
21612 }
21613 }
cd000bff
DJ
21614
21615 /* Remove any overlapping mapping symbols generated by alignment frags. */
21616 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21617#endif
404ff6b5
AH
21618}
21619
c19d1205 21620/* MD interface: Initialization. */
404ff6b5 21621
a737bd4d 21622static void
c19d1205 21623set_constant_flonums (void)
a737bd4d 21624{
c19d1205 21625 int i;
404ff6b5 21626
c19d1205
ZW
21627 for (i = 0; i < NUM_FLOAT_VALS; i++)
21628 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21629 abort ();
a737bd4d 21630}
404ff6b5 21631
3e9e4fcf
JB
21632/* Auto-select Thumb mode if it's the only available instruction set for the
21633 given architecture. */
21634
21635static void
21636autoselect_thumb_from_cpu_variant (void)
21637{
21638 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21639 opcode_select (16);
21640}
21641
c19d1205
ZW
21642void
21643md_begin (void)
a737bd4d 21644{
c19d1205
ZW
21645 unsigned mach;
21646 unsigned int i;
404ff6b5 21647
c19d1205
ZW
21648 if ( (arm_ops_hsh = hash_new ()) == NULL
21649 || (arm_cond_hsh = hash_new ()) == NULL
21650 || (arm_shift_hsh = hash_new ()) == NULL
21651 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21652 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21653 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21654 || (arm_reloc_hsh = hash_new ()) == NULL
21655 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21656 as_fatal (_("virtual memory exhausted"));
21657
21658 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21659 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21660 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21661 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21662 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21663 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21664 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21665 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21666 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21667 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21668 (void *) (v7m_psrs + i));
c19d1205 21669 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21670 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21671 for (i = 0;
21672 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21673 i++)
d3ce72d0 21674 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21675 (void *) (barrier_opt_names + i));
c19d1205
ZW
21676#ifdef OBJ_ELF
21677 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21678 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21679#endif
21680
21681 set_constant_flonums ();
404ff6b5 21682
c19d1205
ZW
21683 /* Set the cpu variant based on the command-line options. We prefer
21684 -mcpu= over -march= if both are set (as for GCC); and we prefer
21685 -mfpu= over any other way of setting the floating point unit.
21686 Use of legacy options with new options are faulted. */
e74cfd16 21687 if (legacy_cpu)
404ff6b5 21688 {
e74cfd16 21689 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21690 as_bad (_("use of old and new-style options to set CPU type"));
21691
21692 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21693 }
e74cfd16 21694 else if (!mcpu_cpu_opt)
c19d1205 21695 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21696
e74cfd16 21697 if (legacy_fpu)
c19d1205 21698 {
e74cfd16 21699 if (mfpu_opt)
c19d1205 21700 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21701
21702 mfpu_opt = legacy_fpu;
21703 }
e74cfd16 21704 else if (!mfpu_opt)
03b1477f 21705 {
45eb4c1b
NS
21706#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21707 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21708 /* Some environments specify a default FPU. If they don't, infer it
21709 from the processor. */
e74cfd16 21710 if (mcpu_fpu_opt)
03b1477f
RE
21711 mfpu_opt = mcpu_fpu_opt;
21712 else
21713 mfpu_opt = march_fpu_opt;
39c2da32 21714#else
e74cfd16 21715 mfpu_opt = &fpu_default;
39c2da32 21716#endif
03b1477f
RE
21717 }
21718
e74cfd16 21719 if (!mfpu_opt)
03b1477f 21720 {
493cb6ef 21721 if (mcpu_cpu_opt != NULL)
e74cfd16 21722 mfpu_opt = &fpu_default;
493cb6ef 21723 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21724 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21725 else
e74cfd16 21726 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21727 }
21728
ee065d83 21729#ifdef CPU_DEFAULT
e74cfd16 21730 if (!mcpu_cpu_opt)
ee065d83 21731 {
e74cfd16
PB
21732 mcpu_cpu_opt = &cpu_default;
21733 selected_cpu = cpu_default;
ee065d83 21734 }
e74cfd16
PB
21735#else
21736 if (mcpu_cpu_opt)
21737 selected_cpu = *mcpu_cpu_opt;
ee065d83 21738 else
e74cfd16 21739 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21740#endif
03b1477f 21741
e74cfd16 21742 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21743
3e9e4fcf
JB
21744 autoselect_thumb_from_cpu_variant ();
21745
e74cfd16 21746 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21747
f17c130b 21748#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21749 {
7cc69913
NC
21750 unsigned int flags = 0;
21751
21752#if defined OBJ_ELF
21753 flags = meabi_flags;
d507cf36
PB
21754
21755 switch (meabi_flags)
33a392fb 21756 {
d507cf36 21757 case EF_ARM_EABI_UNKNOWN:
7cc69913 21758#endif
d507cf36
PB
21759 /* Set the flags in the private structure. */
21760 if (uses_apcs_26) flags |= F_APCS26;
21761 if (support_interwork) flags |= F_INTERWORK;
21762 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21763 if (pic_code) flags |= F_PIC;
e74cfd16 21764 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21765 flags |= F_SOFT_FLOAT;
21766
d507cf36
PB
21767 switch (mfloat_abi_opt)
21768 {
21769 case ARM_FLOAT_ABI_SOFT:
21770 case ARM_FLOAT_ABI_SOFTFP:
21771 flags |= F_SOFT_FLOAT;
21772 break;
33a392fb 21773
d507cf36
PB
21774 case ARM_FLOAT_ABI_HARD:
21775 if (flags & F_SOFT_FLOAT)
21776 as_bad (_("hard-float conflicts with specified fpu"));
21777 break;
21778 }
03b1477f 21779
e74cfd16
PB
21780 /* Using pure-endian doubles (even if soft-float). */
21781 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21782 flags |= F_VFP_FLOAT;
f17c130b 21783
fde78edd 21784#if defined OBJ_ELF
e74cfd16 21785 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21786 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21787 break;
21788
8cb51566 21789 case EF_ARM_EABI_VER4:
3a4a14e9 21790 case EF_ARM_EABI_VER5:
c19d1205 21791 /* No additional flags to set. */
d507cf36
PB
21792 break;
21793
21794 default:
21795 abort ();
21796 }
7cc69913 21797#endif
b99bd4ef
NC
21798 bfd_set_private_flags (stdoutput, flags);
21799
21800 /* We have run out flags in the COFF header to encode the
21801 status of ATPCS support, so instead we create a dummy,
c19d1205 21802 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21803 if (atpcs)
21804 {
21805 asection * sec;
21806
21807 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21808
21809 if (sec != NULL)
21810 {
21811 bfd_set_section_flags
21812 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21813 bfd_set_section_size (stdoutput, sec, 0);
21814 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21815 }
21816 }
7cc69913 21817 }
f17c130b 21818#endif
b99bd4ef
NC
21819
21820 /* Record the CPU type as well. */
2d447fca
JM
21821 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21822 mach = bfd_mach_arm_iWMMXt2;
21823 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21824 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21825 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21826 mach = bfd_mach_arm_XScale;
e74cfd16 21827 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21828 mach = bfd_mach_arm_ep9312;
e74cfd16 21829 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21830 mach = bfd_mach_arm_5TE;
e74cfd16 21831 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21832 {
e74cfd16 21833 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21834 mach = bfd_mach_arm_5T;
21835 else
21836 mach = bfd_mach_arm_5;
21837 }
e74cfd16 21838 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21839 {
e74cfd16 21840 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21841 mach = bfd_mach_arm_4T;
21842 else
21843 mach = bfd_mach_arm_4;
21844 }
e74cfd16 21845 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21846 mach = bfd_mach_arm_3M;
e74cfd16
PB
21847 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21848 mach = bfd_mach_arm_3;
21849 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21850 mach = bfd_mach_arm_2a;
21851 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21852 mach = bfd_mach_arm_2;
21853 else
21854 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21855
21856 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21857}
21858
c19d1205 21859/* Command line processing. */
b99bd4ef 21860
c19d1205
ZW
21861/* md_parse_option
21862 Invocation line includes a switch not recognized by the base assembler.
21863 See if it's a processor-specific option.
b99bd4ef 21864
c19d1205
ZW
21865 This routine is somewhat complicated by the need for backwards
21866 compatibility (since older releases of gcc can't be changed).
21867 The new options try to make the interface as compatible as
21868 possible with GCC.
b99bd4ef 21869
c19d1205 21870 New options (supported) are:
b99bd4ef 21871
c19d1205
ZW
21872 -mcpu=<cpu name> Assemble for selected processor
21873 -march=<architecture name> Assemble for selected architecture
21874 -mfpu=<fpu architecture> Assemble for selected FPU.
21875 -EB/-mbig-endian Big-endian
21876 -EL/-mlittle-endian Little-endian
21877 -k Generate PIC code
21878 -mthumb Start in Thumb mode
21879 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21880
278df34e 21881 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21882
c19d1205 21883 For now we will also provide support for:
b99bd4ef 21884
c19d1205
ZW
21885 -mapcs-32 32-bit Program counter
21886 -mapcs-26 26-bit Program counter
21887 -macps-float Floats passed in FP registers
21888 -mapcs-reentrant Reentrant code
21889 -matpcs
21890 (sometime these will probably be replaced with -mapcs=<list of options>
21891 and -matpcs=<list of options>)
b99bd4ef 21892
c19d1205
ZW
21893 The remaining options are only supported for back-wards compatibility.
21894 Cpu variants, the arm part is optional:
21895 -m[arm]1 Currently not supported.
21896 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21897 -m[arm]3 Arm 3 processor
21898 -m[arm]6[xx], Arm 6 processors
21899 -m[arm]7[xx][t][[d]m] Arm 7 processors
21900 -m[arm]8[10] Arm 8 processors
21901 -m[arm]9[20][tdmi] Arm 9 processors
21902 -mstrongarm[110[0]] StrongARM processors
21903 -mxscale XScale processors
21904 -m[arm]v[2345[t[e]]] Arm architectures
21905 -mall All (except the ARM1)
21906 FP variants:
21907 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21908 -mfpe-old (No float load/store multiples)
21909 -mvfpxd VFP Single precision
21910 -mvfp All VFP
21911 -mno-fpu Disable all floating point instructions
b99bd4ef 21912
c19d1205
ZW
21913 The following CPU names are recognized:
21914 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21915 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21916 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21917 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21918 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21919 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21920 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21921
c19d1205 21922 */
b99bd4ef 21923
c19d1205 21924const char * md_shortopts = "m:k";
b99bd4ef 21925
c19d1205
ZW
21926#ifdef ARM_BI_ENDIAN
21927#define OPTION_EB (OPTION_MD_BASE + 0)
21928#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21929#else
c19d1205
ZW
21930#if TARGET_BYTES_BIG_ENDIAN
21931#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21932#else
c19d1205
ZW
21933#define OPTION_EL (OPTION_MD_BASE + 1)
21934#endif
b99bd4ef 21935#endif
845b51d6 21936#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21937
c19d1205 21938struct option md_longopts[] =
b99bd4ef 21939{
c19d1205
ZW
21940#ifdef OPTION_EB
21941 {"EB", no_argument, NULL, OPTION_EB},
21942#endif
21943#ifdef OPTION_EL
21944 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21945#endif
845b51d6 21946 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21947 {NULL, no_argument, NULL, 0}
21948};
b99bd4ef 21949
c19d1205 21950size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21951
c19d1205 21952struct arm_option_table
b99bd4ef 21953{
c19d1205
ZW
21954 char *option; /* Option name to match. */
21955 char *help; /* Help information. */
21956 int *var; /* Variable to change. */
21957 int value; /* What to change it to. */
21958 char *deprecated; /* If non-null, print this message. */
21959};
b99bd4ef 21960
c19d1205
ZW
21961struct arm_option_table arm_opts[] =
21962{
21963 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21964 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21965 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21966 &support_interwork, 1, NULL},
21967 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21968 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21969 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21970 1, NULL},
21971 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21972 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21973 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21974 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21975 NULL},
b99bd4ef 21976
c19d1205
ZW
21977 /* These are recognized by the assembler, but have no affect on code. */
21978 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21979 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21980
21981 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21982 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21983 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21984 {NULL, NULL, NULL, 0, NULL}
21985};
21986
21987struct arm_legacy_option_table
21988{
21989 char *option; /* Option name to match. */
21990 const arm_feature_set **var; /* Variable to change. */
21991 const arm_feature_set value; /* What to change it to. */
21992 char *deprecated; /* If non-null, print this message. */
21993};
b99bd4ef 21994
e74cfd16
PB
21995const struct arm_legacy_option_table arm_legacy_opts[] =
21996{
c19d1205
ZW
21997 /* DON'T add any new processors to this list -- we want the whole list
21998 to go away... Add them to the processors table instead. */
e74cfd16
PB
21999 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22000 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22001 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22002 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22003 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22004 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22005 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22006 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22007 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22008 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22009 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22010 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22011 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22012 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22013 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22014 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22015 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22016 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22017 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22018 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22019 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22020 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22021 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22022 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22023 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22024 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22025 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22026 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22027 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22028 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22029 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22030 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22031 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22032 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22033 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22034 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22035 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22036 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22037 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22038 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22039 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22040 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22041 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22042 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22043 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22044 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22045 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22046 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22047 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22048 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22049 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22050 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22051 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22052 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22053 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22054 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22055 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22056 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22057 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22058 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22059 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22060 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22061 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22062 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22063 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22064 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22065 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22066 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22067 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22068 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22069 N_("use -mcpu=strongarm110")},
e74cfd16 22070 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22071 N_("use -mcpu=strongarm1100")},
e74cfd16 22072 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22073 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22074 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22075 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22076 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22077
c19d1205 22078 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22079 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22080 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22081 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22082 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22083 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22084 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22085 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22086 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22087 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22088 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22089 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22090 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22091 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22092 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22093 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22094 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22095 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22096 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22097
c19d1205 22098 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22099 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22100 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22101 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22102 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22103 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22104
e74cfd16 22105 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22106};
7ed4c4c5 22107
c19d1205 22108struct arm_cpu_option_table
7ed4c4c5 22109{
c19d1205 22110 char *name;
e74cfd16 22111 const arm_feature_set value;
c19d1205
ZW
22112 /* For some CPUs we assume an FPU unless the user explicitly sets
22113 -mfpu=... */
e74cfd16 22114 const arm_feature_set default_fpu;
ee065d83
PB
22115 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22116 case. */
22117 const char *canonical_name;
c19d1205 22118};
7ed4c4c5 22119
c19d1205
ZW
22120/* This list should, at a minimum, contain all the cpu names
22121 recognized by GCC. */
e74cfd16 22122static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22123{
ee065d83
PB
22124 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22125 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22126 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22127 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22128 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22129 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22130 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22131 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22132 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22133 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22134 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22135 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22136 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22137 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22138 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22139 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22140 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22141 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22142 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22143 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22144 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22145 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22146 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22147 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22148 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22149 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22150 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22151 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22152 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22153 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22154 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22155 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22156 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22157 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22158 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22159 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22160 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22161 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22162 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22163 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22164 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22165 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22166 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22167 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22168 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22169 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22170 /* For V5 or later processors we default to using VFP; but the user
22171 should really set the FPU type explicitly. */
ee065d83
PB
22172 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22173 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22174 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22175 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22176 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22177 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22178 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22179 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22180 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22181 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22182 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22183 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22184 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22185 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22186 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22187 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22188 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22189 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22190 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22191 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22192 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22193 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22194 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22195 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22196 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22197 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22198 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22199 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22200 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22201 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22202 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22203 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22204 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
b38f9f31 22205 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
e07e6e58 22206 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22207 | FPU_NEON_EXT_V1),
15290f0a 22208 NULL},
e07e6e58 22209 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22210 | FPU_NEON_EXT_V1),
5287ad62 22211 NULL},
62b3e311 22212 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
307c948d 22213 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
26b6f191 22214 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, NULL},
62b3e311 22215 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 22216 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 22217 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 22218 /* ??? XSCALE is really an architecture. */
ee065d83 22219 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22220 /* ??? iwmmxt is not a processor. */
ee065d83 22221 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22222 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22223 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22224 /* Maverick */
e07e6e58 22225 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22226 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22227};
7ed4c4c5 22228
c19d1205 22229struct arm_arch_option_table
7ed4c4c5 22230{
c19d1205 22231 char *name;
e74cfd16
PB
22232 const arm_feature_set value;
22233 const arm_feature_set default_fpu;
c19d1205 22234};
7ed4c4c5 22235
c19d1205
ZW
22236/* This list should, at a minimum, contain all the architecture names
22237 recognized by GCC. */
e74cfd16 22238static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22239{
22240 {"all", ARM_ANY, FPU_ARCH_FPA},
22241 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22242 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22243 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22244 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22245 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22246 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22247 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22248 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22249 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22250 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22251 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22252 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22253 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22254 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22255 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22256 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22257 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22258 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22259 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22260 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22261 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22262 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22263 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22264 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22265 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22266 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22267 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22268 /* The official spelling of the ARMv7 profile variants is the dashed form.
22269 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22270 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22271 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22272 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22273 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22274 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22275 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22276 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22277 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22278 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22279 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22280 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22281};
7ed4c4c5 22282
c19d1205 22283/* ISA extensions in the co-processor space. */
e74cfd16 22284struct arm_option_cpu_value_table
c19d1205
ZW
22285{
22286 char *name;
e74cfd16 22287 const arm_feature_set value;
c19d1205 22288};
7ed4c4c5 22289
e74cfd16 22290static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22291{
e74cfd16
PB
22292 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22293 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22294 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22295 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22296 {NULL, ARM_ARCH_NONE}
c19d1205 22297};
7ed4c4c5 22298
c19d1205
ZW
22299/* This list should, at a minimum, contain all the fpu names
22300 recognized by GCC. */
e74cfd16 22301static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22302{
22303 {"softfpa", FPU_NONE},
22304 {"fpe", FPU_ARCH_FPE},
22305 {"fpe2", FPU_ARCH_FPE},
22306 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22307 {"fpa", FPU_ARCH_FPA},
22308 {"fpa10", FPU_ARCH_FPA},
22309 {"fpa11", FPU_ARCH_FPA},
22310 {"arm7500fe", FPU_ARCH_FPA},
22311 {"softvfp", FPU_ARCH_VFP},
22312 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22313 {"vfp", FPU_ARCH_VFP_V2},
22314 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22315 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22316 {"vfp10", FPU_ARCH_VFP_V2},
22317 {"vfp10-r0", FPU_ARCH_VFP_V1},
22318 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22319 {"vfpv2", FPU_ARCH_VFP_V2},
22320 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22321 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22322 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22323 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22324 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22325 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22326 {"arm1020t", FPU_ARCH_VFP_V1},
22327 {"arm1020e", FPU_ARCH_VFP_V2},
22328 {"arm1136jfs", FPU_ARCH_VFP_V2},
22329 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22330 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22331 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22332 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22333 {"vfpv4", FPU_ARCH_VFP_V4},
22334 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22335 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22336 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22337 {NULL, ARM_ARCH_NONE}
22338};
22339
22340struct arm_option_value_table
22341{
22342 char *name;
22343 long value;
c19d1205 22344};
7ed4c4c5 22345
e74cfd16 22346static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22347{
22348 {"hard", ARM_FLOAT_ABI_HARD},
22349 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22350 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22351 {NULL, 0}
c19d1205 22352};
7ed4c4c5 22353
c19d1205 22354#ifdef OBJ_ELF
3a4a14e9 22355/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22356static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22357{
22358 {"gnu", EF_ARM_EABI_UNKNOWN},
22359 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22360 {"5", EF_ARM_EABI_VER5},
e74cfd16 22361 {NULL, 0}
c19d1205
ZW
22362};
22363#endif
7ed4c4c5 22364
c19d1205
ZW
22365struct arm_long_option_table
22366{
22367 char * option; /* Substring to match. */
22368 char * help; /* Help information. */
22369 int (* func) (char * subopt); /* Function to decode sub-option. */
22370 char * deprecated; /* If non-null, print this message. */
22371};
7ed4c4c5 22372
c921be7d 22373static bfd_boolean
e74cfd16 22374arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22375{
21d799b5
NC
22376 arm_feature_set *ext_set = (arm_feature_set *)
22377 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22378
22379 /* Copy the feature set, so that we can modify it. */
22380 *ext_set = **opt_p;
22381 *opt_p = ext_set;
22382
c19d1205 22383 while (str != NULL && *str != 0)
7ed4c4c5 22384 {
e74cfd16 22385 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22386 char * ext;
22387 int optlen;
7ed4c4c5 22388
c19d1205
ZW
22389 if (*str != '+')
22390 {
22391 as_bad (_("invalid architectural extension"));
c921be7d 22392 return FALSE;
c19d1205 22393 }
7ed4c4c5 22394
c19d1205
ZW
22395 str++;
22396 ext = strchr (str, '+');
7ed4c4c5 22397
c19d1205
ZW
22398 if (ext != NULL)
22399 optlen = ext - str;
22400 else
22401 optlen = strlen (str);
7ed4c4c5 22402
c19d1205
ZW
22403 if (optlen == 0)
22404 {
22405 as_bad (_("missing architectural extension"));
c921be7d 22406 return FALSE;
c19d1205 22407 }
7ed4c4c5 22408
c19d1205
ZW
22409 for (opt = arm_extensions; opt->name != NULL; opt++)
22410 if (strncmp (opt->name, str, optlen) == 0)
22411 {
e74cfd16 22412 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22413 break;
22414 }
7ed4c4c5 22415
c19d1205
ZW
22416 if (opt->name == NULL)
22417 {
5f4273c7 22418 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22419 return FALSE;
c19d1205 22420 }
7ed4c4c5 22421
c19d1205
ZW
22422 str = ext;
22423 };
7ed4c4c5 22424
c921be7d 22425 return TRUE;
c19d1205 22426}
7ed4c4c5 22427
c921be7d 22428static bfd_boolean
c19d1205 22429arm_parse_cpu (char * str)
7ed4c4c5 22430{
e74cfd16 22431 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22432 char * ext = strchr (str, '+');
22433 int optlen;
7ed4c4c5 22434
c19d1205
ZW
22435 if (ext != NULL)
22436 optlen = ext - str;
7ed4c4c5 22437 else
c19d1205 22438 optlen = strlen (str);
7ed4c4c5 22439
c19d1205 22440 if (optlen == 0)
7ed4c4c5 22441 {
c19d1205 22442 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22443 return FALSE;
7ed4c4c5
NC
22444 }
22445
c19d1205
ZW
22446 for (opt = arm_cpus; opt->name != NULL; opt++)
22447 if (strncmp (opt->name, str, optlen) == 0)
22448 {
e74cfd16
PB
22449 mcpu_cpu_opt = &opt->value;
22450 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22451 if (opt->canonical_name)
5f4273c7 22452 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22453 else
22454 {
22455 int i;
c921be7d 22456
ee065d83
PB
22457 for (i = 0; i < optlen; i++)
22458 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22459 selected_cpu_name[i] = 0;
22460 }
7ed4c4c5 22461
c19d1205
ZW
22462 if (ext != NULL)
22463 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22464
c921be7d 22465 return TRUE;
c19d1205 22466 }
7ed4c4c5 22467
c19d1205 22468 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22469 return FALSE;
7ed4c4c5
NC
22470}
22471
c921be7d 22472static bfd_boolean
c19d1205 22473arm_parse_arch (char * str)
7ed4c4c5 22474{
e74cfd16 22475 const struct arm_arch_option_table *opt;
c19d1205
ZW
22476 char *ext = strchr (str, '+');
22477 int optlen;
7ed4c4c5 22478
c19d1205
ZW
22479 if (ext != NULL)
22480 optlen = ext - str;
7ed4c4c5 22481 else
c19d1205 22482 optlen = strlen (str);
7ed4c4c5 22483
c19d1205 22484 if (optlen == 0)
7ed4c4c5 22485 {
c19d1205 22486 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22487 return FALSE;
7ed4c4c5
NC
22488 }
22489
c19d1205
ZW
22490 for (opt = arm_archs; opt->name != NULL; opt++)
22491 if (streq (opt->name, str))
22492 {
e74cfd16
PB
22493 march_cpu_opt = &opt->value;
22494 march_fpu_opt = &opt->default_fpu;
5f4273c7 22495 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22496
c19d1205
ZW
22497 if (ext != NULL)
22498 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22499
c921be7d 22500 return TRUE;
c19d1205
ZW
22501 }
22502
22503 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22504 return FALSE;
7ed4c4c5 22505}
eb043451 22506
c921be7d 22507static bfd_boolean
c19d1205
ZW
22508arm_parse_fpu (char * str)
22509{
e74cfd16 22510 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22511
c19d1205
ZW
22512 for (opt = arm_fpus; opt->name != NULL; opt++)
22513 if (streq (opt->name, str))
22514 {
e74cfd16 22515 mfpu_opt = &opt->value;
c921be7d 22516 return TRUE;
c19d1205 22517 }
b99bd4ef 22518
c19d1205 22519 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22520 return FALSE;
c19d1205
ZW
22521}
22522
c921be7d 22523static bfd_boolean
c19d1205 22524arm_parse_float_abi (char * str)
b99bd4ef 22525{
e74cfd16 22526 const struct arm_option_value_table * opt;
b99bd4ef 22527
c19d1205
ZW
22528 for (opt = arm_float_abis; opt->name != NULL; opt++)
22529 if (streq (opt->name, str))
22530 {
22531 mfloat_abi_opt = opt->value;
c921be7d 22532 return TRUE;
c19d1205 22533 }
cc8a6dd0 22534
c19d1205 22535 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22536 return FALSE;
c19d1205 22537}
b99bd4ef 22538
c19d1205 22539#ifdef OBJ_ELF
c921be7d 22540static bfd_boolean
c19d1205
ZW
22541arm_parse_eabi (char * str)
22542{
e74cfd16 22543 const struct arm_option_value_table *opt;
cc8a6dd0 22544
c19d1205
ZW
22545 for (opt = arm_eabis; opt->name != NULL; opt++)
22546 if (streq (opt->name, str))
22547 {
22548 meabi_flags = opt->value;
c921be7d 22549 return TRUE;
c19d1205
ZW
22550 }
22551 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22552 return FALSE;
c19d1205
ZW
22553}
22554#endif
cc8a6dd0 22555
c921be7d 22556static bfd_boolean
e07e6e58
NC
22557arm_parse_it_mode (char * str)
22558{
c921be7d 22559 bfd_boolean ret = TRUE;
e07e6e58
NC
22560
22561 if (streq ("arm", str))
22562 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22563 else if (streq ("thumb", str))
22564 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22565 else if (streq ("always", str))
22566 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22567 else if (streq ("never", str))
22568 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22569 else
22570 {
22571 as_bad (_("unknown implicit IT mode `%s', should be "\
22572 "arm, thumb, always, or never."), str);
c921be7d 22573 ret = FALSE;
e07e6e58
NC
22574 }
22575
22576 return ret;
22577}
22578
c19d1205
ZW
22579struct arm_long_option_table arm_long_opts[] =
22580{
22581 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22582 arm_parse_cpu, NULL},
22583 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22584 arm_parse_arch, NULL},
22585 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22586 arm_parse_fpu, NULL},
22587 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22588 arm_parse_float_abi, NULL},
22589#ifdef OBJ_ELF
7fac0536 22590 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22591 arm_parse_eabi, NULL},
22592#endif
e07e6e58
NC
22593 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22594 arm_parse_it_mode, NULL},
c19d1205
ZW
22595 {NULL, NULL, 0, NULL}
22596};
cc8a6dd0 22597
c19d1205
ZW
22598int
22599md_parse_option (int c, char * arg)
22600{
22601 struct arm_option_table *opt;
e74cfd16 22602 const struct arm_legacy_option_table *fopt;
c19d1205 22603 struct arm_long_option_table *lopt;
b99bd4ef 22604
c19d1205 22605 switch (c)
b99bd4ef 22606 {
c19d1205
ZW
22607#ifdef OPTION_EB
22608 case OPTION_EB:
22609 target_big_endian = 1;
22610 break;
22611#endif
cc8a6dd0 22612
c19d1205
ZW
22613#ifdef OPTION_EL
22614 case OPTION_EL:
22615 target_big_endian = 0;
22616 break;
22617#endif
b99bd4ef 22618
845b51d6
PB
22619 case OPTION_FIX_V4BX:
22620 fix_v4bx = TRUE;
22621 break;
22622
c19d1205
ZW
22623 case 'a':
22624 /* Listing option. Just ignore these, we don't support additional
22625 ones. */
22626 return 0;
b99bd4ef 22627
c19d1205
ZW
22628 default:
22629 for (opt = arm_opts; opt->option != NULL; opt++)
22630 {
22631 if (c == opt->option[0]
22632 && ((arg == NULL && opt->option[1] == 0)
22633 || streq (arg, opt->option + 1)))
22634 {
c19d1205 22635 /* If the option is deprecated, tell the user. */
278df34e 22636 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22637 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22638 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22639
c19d1205
ZW
22640 if (opt->var != NULL)
22641 *opt->var = opt->value;
cc8a6dd0 22642
c19d1205
ZW
22643 return 1;
22644 }
22645 }
b99bd4ef 22646
e74cfd16
PB
22647 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22648 {
22649 if (c == fopt->option[0]
22650 && ((arg == NULL && fopt->option[1] == 0)
22651 || streq (arg, fopt->option + 1)))
22652 {
e74cfd16 22653 /* If the option is deprecated, tell the user. */
278df34e 22654 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22655 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22656 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22657
22658 if (fopt->var != NULL)
22659 *fopt->var = &fopt->value;
22660
22661 return 1;
22662 }
22663 }
22664
c19d1205
ZW
22665 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22666 {
22667 /* These options are expected to have an argument. */
22668 if (c == lopt->option[0]
22669 && arg != NULL
22670 && strncmp (arg, lopt->option + 1,
22671 strlen (lopt->option + 1)) == 0)
22672 {
c19d1205 22673 /* If the option is deprecated, tell the user. */
278df34e 22674 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22675 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22676 _(lopt->deprecated));
b99bd4ef 22677
c19d1205
ZW
22678 /* Call the sup-option parser. */
22679 return lopt->func (arg + strlen (lopt->option) - 1);
22680 }
22681 }
a737bd4d 22682
c19d1205
ZW
22683 return 0;
22684 }
a394c00f 22685
c19d1205
ZW
22686 return 1;
22687}
a394c00f 22688
c19d1205
ZW
22689void
22690md_show_usage (FILE * fp)
a394c00f 22691{
c19d1205
ZW
22692 struct arm_option_table *opt;
22693 struct arm_long_option_table *lopt;
a394c00f 22694
c19d1205 22695 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22696
c19d1205
ZW
22697 for (opt = arm_opts; opt->option != NULL; opt++)
22698 if (opt->help != NULL)
22699 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22700
c19d1205
ZW
22701 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22702 if (lopt->help != NULL)
22703 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22704
c19d1205
ZW
22705#ifdef OPTION_EB
22706 fprintf (fp, _("\
22707 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22708#endif
22709
c19d1205
ZW
22710#ifdef OPTION_EL
22711 fprintf (fp, _("\
22712 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22713#endif
845b51d6
PB
22714
22715 fprintf (fp, _("\
22716 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22717}
ee065d83
PB
22718
22719
22720#ifdef OBJ_ELF
62b3e311
PB
22721typedef struct
22722{
22723 int val;
22724 arm_feature_set flags;
22725} cpu_arch_ver_table;
22726
22727/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22728 least features first. */
22729static const cpu_arch_ver_table cpu_arch_ver[] =
22730{
22731 {1, ARM_ARCH_V4},
22732 {2, ARM_ARCH_V4T},
22733 {3, ARM_ARCH_V5},
ee3c0378 22734 {3, ARM_ARCH_V5T},
62b3e311
PB
22735 {4, ARM_ARCH_V5TE},
22736 {5, ARM_ARCH_V5TEJ},
22737 {6, ARM_ARCH_V6},
22738 {7, ARM_ARCH_V6Z},
7e806470 22739 {9, ARM_ARCH_V6K},
91e22acd 22740 {11, ARM_ARCH_V6M},
7e806470 22741 {8, ARM_ARCH_V6T2},
62b3e311
PB
22742 {10, ARM_ARCH_V7A},
22743 {10, ARM_ARCH_V7R},
22744 {10, ARM_ARCH_V7M},
22745 {0, ARM_ARCH_NONE}
22746};
22747
ee3c0378
AS
22748/* Set an attribute if it has not already been set by the user. */
22749static void
22750aeabi_set_attribute_int (int tag, int value)
22751{
22752 if (tag < 1
22753 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22754 || !attributes_set_explicitly[tag])
22755 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22756}
22757
22758static void
22759aeabi_set_attribute_string (int tag, const char *value)
22760{
22761 if (tag < 1
22762 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22763 || !attributes_set_explicitly[tag])
22764 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22765}
22766
ee065d83
PB
22767/* Set the public EABI object attributes. */
22768static void
22769aeabi_set_public_attributes (void)
22770{
22771 int arch;
e74cfd16 22772 arm_feature_set flags;
62b3e311
PB
22773 arm_feature_set tmp;
22774 const cpu_arch_ver_table *p;
ee065d83
PB
22775
22776 /* Choose the architecture based on the capabilities of the requested cpu
22777 (if any) and/or the instructions actually used. */
e74cfd16
PB
22778 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22779 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22780 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22781 /*Allow the user to override the reported architecture. */
22782 if (object_arch)
22783 {
22784 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22785 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22786 }
22787
62b3e311
PB
22788 tmp = flags;
22789 arch = 0;
22790 for (p = cpu_arch_ver; p->val; p++)
22791 {
22792 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22793 {
22794 arch = p->val;
22795 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22796 }
22797 }
ee065d83 22798
9e3c6df6
PB
22799 /* The table lookup above finds the last architecture to contribute
22800 a new feature. Unfortunately, Tag13 is a subset of the union of
22801 v6T2 and v7-M, so it is never seen as contributing a new feature.
22802 We can not search for the last entry which is entirely used,
22803 because if no CPU is specified we build up only those flags
22804 actually used. Perhaps we should separate out the specified
22805 and implicit cases. Avoid taking this path for -march=all by
22806 checking for contradictory v7-A / v7-M features. */
22807 if (arch == 10
22808 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22809 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22810 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22811 arch = 13;
22812
ee065d83
PB
22813 /* Tag_CPU_name. */
22814 if (selected_cpu_name[0])
22815 {
91d6fa6a 22816 char *q;
ee065d83 22817
91d6fa6a
NC
22818 q = selected_cpu_name;
22819 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
22820 {
22821 int i;
5f4273c7 22822
91d6fa6a
NC
22823 q += 4;
22824 for (i = 0; q[i]; i++)
22825 q[i] = TOUPPER (q[i]);
ee065d83 22826 }
91d6fa6a 22827 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 22828 }
62f3b8c8 22829
ee065d83 22830 /* Tag_CPU_arch. */
ee3c0378 22831 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 22832
62b3e311
PB
22833 /* Tag_CPU_arch_profile. */
22834 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22835 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22836 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22837 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22838 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22839 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 22840
ee065d83 22841 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22842 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22843 || arch == 0)
22844 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 22845
ee065d83 22846 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22847 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22848 || arch == 0)
22849 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22850 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 22851
ee065d83 22852 /* Tag_VFP_arch. */
62f3b8c8
PB
22853 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22854 aeabi_set_attribute_int (Tag_VFP_arch,
22855 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22856 ? 5 : 6);
22857 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 22858 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 22859 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
22860 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22861 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22862 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22863 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22864 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22865 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 22866
4547cb56
NC
22867 /* Tag_ABI_HardFP_use. */
22868 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
22869 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
22870 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
22871
ee065d83 22872 /* Tag_WMMX_arch. */
ee3c0378
AS
22873 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22874 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22875 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22876 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 22877
ee3c0378 22878 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22879 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
22880 aeabi_set_attribute_int
22881 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22882 ? 2 : 1));
22883
ee3c0378 22884 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 22885 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 22886 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56
NC
22887
22888 /* Tag_DIV_use. */
22889 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
22890 aeabi_set_attribute_int (Tag_DIV_use, 0);
22891 /* Fill this in when gas supports v7a sdiv/udiv.
22892 else if (... v7a with div extension used ...)
22893 aeabi_set_attribute_int (Tag_DIV_use, 2); */
22894 else
22895 aeabi_set_attribute_int (Tag_DIV_use, 1);
ee065d83
PB
22896}
22897
104d59d1 22898/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22899void
22900arm_md_end (void)
22901{
ee065d83
PB
22902 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22903 return;
22904
22905 aeabi_set_public_attributes ();
ee065d83 22906}
8463be01 22907#endif /* OBJ_ELF */
ee065d83
PB
22908
22909
22910/* Parse a .cpu directive. */
22911
22912static void
22913s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22914{
e74cfd16 22915 const struct arm_cpu_option_table *opt;
ee065d83
PB
22916 char *name;
22917 char saved_char;
22918
22919 name = input_line_pointer;
5f4273c7 22920 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22921 input_line_pointer++;
22922 saved_char = *input_line_pointer;
22923 *input_line_pointer = 0;
22924
22925 /* Skip the first "all" entry. */
22926 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22927 if (streq (opt->name, name))
22928 {
e74cfd16
PB
22929 mcpu_cpu_opt = &opt->value;
22930 selected_cpu = opt->value;
ee065d83 22931 if (opt->canonical_name)
5f4273c7 22932 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22933 else
22934 {
22935 int i;
22936 for (i = 0; opt->name[i]; i++)
22937 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22938 selected_cpu_name[i] = 0;
22939 }
e74cfd16 22940 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22941 *input_line_pointer = saved_char;
22942 demand_empty_rest_of_line ();
22943 return;
22944 }
22945 as_bad (_("unknown cpu `%s'"), name);
22946 *input_line_pointer = saved_char;
22947 ignore_rest_of_line ();
22948}
22949
22950
22951/* Parse a .arch directive. */
22952
22953static void
22954s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22955{
e74cfd16 22956 const struct arm_arch_option_table *opt;
ee065d83
PB
22957 char saved_char;
22958 char *name;
22959
22960 name = input_line_pointer;
5f4273c7 22961 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22962 input_line_pointer++;
22963 saved_char = *input_line_pointer;
22964 *input_line_pointer = 0;
22965
22966 /* Skip the first "all" entry. */
22967 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22968 if (streq (opt->name, name))
22969 {
e74cfd16
PB
22970 mcpu_cpu_opt = &opt->value;
22971 selected_cpu = opt->value;
5f4273c7 22972 strcpy (selected_cpu_name, opt->name);
e74cfd16 22973 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22974 *input_line_pointer = saved_char;
22975 demand_empty_rest_of_line ();
22976 return;
22977 }
22978
22979 as_bad (_("unknown architecture `%s'\n"), name);
22980 *input_line_pointer = saved_char;
22981 ignore_rest_of_line ();
22982}
22983
22984
7a1d4c38
PB
22985/* Parse a .object_arch directive. */
22986
22987static void
22988s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22989{
22990 const struct arm_arch_option_table *opt;
22991 char saved_char;
22992 char *name;
22993
22994 name = input_line_pointer;
5f4273c7 22995 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22996 input_line_pointer++;
22997 saved_char = *input_line_pointer;
22998 *input_line_pointer = 0;
22999
23000 /* Skip the first "all" entry. */
23001 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23002 if (streq (opt->name, name))
23003 {
23004 object_arch = &opt->value;
23005 *input_line_pointer = saved_char;
23006 demand_empty_rest_of_line ();
23007 return;
23008 }
23009
23010 as_bad (_("unknown architecture `%s'\n"), name);
23011 *input_line_pointer = saved_char;
23012 ignore_rest_of_line ();
23013}
23014
ee065d83
PB
23015/* Parse a .fpu directive. */
23016
23017static void
23018s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23019{
e74cfd16 23020 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
23021 char saved_char;
23022 char *name;
23023
23024 name = input_line_pointer;
5f4273c7 23025 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
23026 input_line_pointer++;
23027 saved_char = *input_line_pointer;
23028 *input_line_pointer = 0;
5f4273c7 23029
ee065d83
PB
23030 for (opt = arm_fpus; opt->name != NULL; opt++)
23031 if (streq (opt->name, name))
23032 {
e74cfd16
PB
23033 mfpu_opt = &opt->value;
23034 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
23035 *input_line_pointer = saved_char;
23036 demand_empty_rest_of_line ();
23037 return;
23038 }
23039
23040 as_bad (_("unknown floating point format `%s'\n"), name);
23041 *input_line_pointer = saved_char;
23042 ignore_rest_of_line ();
23043}
ee065d83 23044
794ba86a 23045/* Copy symbol information. */
f31fef98 23046
794ba86a
DJ
23047void
23048arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23049{
23050 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23051}
e04befd0 23052
f31fef98 23053#ifdef OBJ_ELF
e04befd0
AS
23054/* Given a symbolic attribute NAME, return the proper integer value.
23055 Returns -1 if the attribute is not known. */
f31fef98 23056
e04befd0
AS
23057int
23058arm_convert_symbolic_attribute (const char *name)
23059{
f31fef98
NC
23060 static const struct
23061 {
23062 const char * name;
23063 const int tag;
23064 }
23065 attribute_table[] =
23066 {
23067 /* When you modify this table you should
23068 also modify the list in doc/c-arm.texi. */
e04befd0 23069#define T(tag) {#tag, tag}
f31fef98
NC
23070 T (Tag_CPU_raw_name),
23071 T (Tag_CPU_name),
23072 T (Tag_CPU_arch),
23073 T (Tag_CPU_arch_profile),
23074 T (Tag_ARM_ISA_use),
23075 T (Tag_THUMB_ISA_use),
75375b3e 23076 T (Tag_FP_arch),
f31fef98
NC
23077 T (Tag_VFP_arch),
23078 T (Tag_WMMX_arch),
23079 T (Tag_Advanced_SIMD_arch),
23080 T (Tag_PCS_config),
23081 T (Tag_ABI_PCS_R9_use),
23082 T (Tag_ABI_PCS_RW_data),
23083 T (Tag_ABI_PCS_RO_data),
23084 T (Tag_ABI_PCS_GOT_use),
23085 T (Tag_ABI_PCS_wchar_t),
23086 T (Tag_ABI_FP_rounding),
23087 T (Tag_ABI_FP_denormal),
23088 T (Tag_ABI_FP_exceptions),
23089 T (Tag_ABI_FP_user_exceptions),
23090 T (Tag_ABI_FP_number_model),
75375b3e 23091 T (Tag_ABI_align_needed),
f31fef98 23092 T (Tag_ABI_align8_needed),
75375b3e 23093 T (Tag_ABI_align_preserved),
f31fef98
NC
23094 T (Tag_ABI_align8_preserved),
23095 T (Tag_ABI_enum_size),
23096 T (Tag_ABI_HardFP_use),
23097 T (Tag_ABI_VFP_args),
23098 T (Tag_ABI_WMMX_args),
23099 T (Tag_ABI_optimization_goals),
23100 T (Tag_ABI_FP_optimization_goals),
23101 T (Tag_compatibility),
23102 T (Tag_CPU_unaligned_access),
75375b3e 23103 T (Tag_FP_HP_extension),
f31fef98
NC
23104 T (Tag_VFP_HP_extension),
23105 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23106 T (Tag_MPextension_use),
23107 T (Tag_DIV_use),
f31fef98
NC
23108 T (Tag_nodefaults),
23109 T (Tag_also_compatible_with),
23110 T (Tag_conformance),
23111 T (Tag_T2EE_use),
23112 T (Tag_Virtualization_use),
cd21e546 23113 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23114#undef T
f31fef98 23115 };
e04befd0
AS
23116 unsigned int i;
23117
23118 if (name == NULL)
23119 return -1;
23120
f31fef98 23121 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23122 if (streq (name, attribute_table[i].name))
e04befd0
AS
23123 return attribute_table[i].tag;
23124
23125 return -1;
23126}
267bf995
RR
23127
23128
23129/* Apply sym value for relocations only in the case that
23130 they are for local symbols and you have the respective
23131 architectural feature for blx and simple switches. */
23132int
23133arm_apply_sym_value (struct fix * fixP)
23134{
23135 if (fixP->fx_addsy
23136 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23137 && !S_IS_EXTERNAL (fixP->fx_addsy))
23138 {
23139 switch (fixP->fx_r_type)
23140 {
23141 case BFD_RELOC_ARM_PCREL_BLX:
23142 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23143 if (ARM_IS_FUNC (fixP->fx_addsy))
23144 return 1;
23145 break;
23146
23147 case BFD_RELOC_ARM_PCREL_CALL:
23148 case BFD_RELOC_THUMB_PCREL_BLX:
23149 if (THUMB_IS_FUNC (fixP->fx_addsy))
23150 return 1;
23151 break;
23152
23153 default:
23154 break;
23155 }
23156
23157 }
23158 return 0;
23159}
f31fef98 23160#endif /* OBJ_ELF */
This page took 2.275938 seconds and 4 git commands to generate.