]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
*** empty log message ***
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
b43420e6 3 2004, 2005, 2006, 2007, 2008, 2009, 2010
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef 99#ifndef CPU_DEFAULT
8a59fff3
MGD
100/* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
b99bd4ef
NC
106#endif
107
108#ifndef FPU_DEFAULT
c820d418
MM
109# ifdef TE_LINUX
110# define FPU_DEFAULT FPU_ARCH_FPA
111# elif defined (TE_NetBSD)
112# ifdef OBJ_ELF
113# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114# else
115 /* Legacy a.out format. */
116# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117# endif
4e7fd91e
PB
118# elif defined (TE_VXWORKS)
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
120# else
121 /* For backwards compatibility, default to FPA. */
122# define FPU_DEFAULT FPU_ARCH_FPA
123# endif
124#endif /* ifndef FPU_DEFAULT */
b99bd4ef 125
c19d1205 126#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 127
e74cfd16
PB
128static arm_feature_set cpu_variant;
129static arm_feature_set arm_arch_used;
130static arm_feature_set thumb_arch_used;
b99bd4ef 131
b99bd4ef 132/* Flags stored in private area of BFD structure. */
c19d1205
ZW
133static int uses_apcs_26 = FALSE;
134static int atpcs = FALSE;
b34976b6
AM
135static int support_interwork = FALSE;
136static int uses_apcs_float = FALSE;
c19d1205 137static int pic_code = FALSE;
845b51d6 138static int fix_v4bx = FALSE;
278df34e
NS
139/* Warn on using deprecated features. */
140static int warn_on_deprecated = TRUE;
141
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
188static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 189static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 190static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
191static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470
PB
198static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
200
201static const arm_feature_set arm_arch_any = ARM_ANY;
202static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
2d447fca
JM
206static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
208static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 220static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 221static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
222static const arm_feature_set fpu_vfp_ext_d32 =
223 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
224static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
227static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
228static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
229static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
e74cfd16 230
33a392fb 231static int mfloat_abi_opt = -1;
e74cfd16
PB
232/* Record user cpu selection for object attributes. */
233static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
234/* Must be long enough to hold any of the names in arm_cpus. */
235static char selected_cpu_name[16];
7cc69913 236#ifdef OBJ_ELF
deeaaff8
DJ
237# ifdef EABI_DEFAULT
238static int meabi_flags = EABI_DEFAULT;
239# else
d507cf36 240static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 241# endif
e1da3f5b 242
ee3c0378
AS
243static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
244
e1da3f5b 245bfd_boolean
5f4273c7 246arm_is_eabi (void)
e1da3f5b
PB
247{
248 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
249}
7cc69913 250#endif
b99bd4ef 251
b99bd4ef 252#ifdef OBJ_ELF
c19d1205 253/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
254symbolS * GOT_symbol;
255#endif
256
b99bd4ef
NC
257/* 0: assemble for ARM,
258 1: assemble for Thumb,
259 2: assemble for Thumb even though target CPU does not support thumb
260 instructions. */
261static int thumb_mode = 0;
8dc2430f
NC
262/* A value distinct from the possible values for thumb_mode that we
263 can use to record whether thumb_mode has been copied into the
264 tc_frag_data field of a frag. */
265#define MODE_RECORDED (1 << 4)
b99bd4ef 266
e07e6e58
NC
267/* Specifies the intrinsic IT insn behavior mode. */
268enum implicit_it_mode
269{
270 IMPLICIT_IT_MODE_NEVER = 0x00,
271 IMPLICIT_IT_MODE_ARM = 0x01,
272 IMPLICIT_IT_MODE_THUMB = 0x02,
273 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
274};
275static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
276
c19d1205
ZW
277/* If unified_syntax is true, we are processing the new unified
278 ARM/Thumb syntax. Important differences from the old ARM mode:
279
280 - Immediate operands do not require a # prefix.
281 - Conditional affixes always appear at the end of the
282 instruction. (For backward compatibility, those instructions
283 that formerly had them in the middle, continue to accept them
284 there.)
285 - The IT instruction may appear, and if it does is validated
286 against subsequent conditional affixes. It does not generate
287 machine code.
288
289 Important differences from the old Thumb mode:
290
291 - Immediate operands do not require a # prefix.
292 - Most of the V6T2 instructions are only available in unified mode.
293 - The .N and .W suffixes are recognized and honored (it is an error
294 if they cannot be honored).
295 - All instructions set the flags if and only if they have an 's' affix.
296 - Conditional affixes may be used. They are validated against
297 preceding IT instructions. Unlike ARM mode, you cannot use a
298 conditional affix except in the scope of an IT instruction. */
299
300static bfd_boolean unified_syntax = FALSE;
b99bd4ef 301
5287ad62
JB
302enum neon_el_type
303{
dcbf9037 304 NT_invtype,
5287ad62
JB
305 NT_untyped,
306 NT_integer,
307 NT_float,
308 NT_poly,
309 NT_signed,
dcbf9037 310 NT_unsigned
5287ad62
JB
311};
312
313struct neon_type_el
314{
315 enum neon_el_type type;
316 unsigned size;
317};
318
319#define NEON_MAX_TYPE_ELS 4
320
321struct neon_type
322{
323 struct neon_type_el el[NEON_MAX_TYPE_ELS];
324 unsigned elems;
325};
326
e07e6e58
NC
327enum it_instruction_type
328{
329 OUTSIDE_IT_INSN,
330 INSIDE_IT_INSN,
331 INSIDE_IT_LAST_INSN,
332 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
333 if inside, should be the last one. */
334 NEUTRAL_IT_INSN, /* This could be either inside or outside,
335 i.e. BKPT and NOP. */
336 IT_INSN /* The IT insn has been parsed. */
337};
338
b99bd4ef
NC
339struct arm_it
340{
c19d1205 341 const char * error;
b99bd4ef 342 unsigned long instruction;
c19d1205
ZW
343 int size;
344 int size_req;
345 int cond;
037e8744
JB
346 /* "uncond_value" is set to the value in place of the conditional field in
347 unconditional versions of the instruction, or -1 if nothing is
348 appropriate. */
349 int uncond_value;
5287ad62 350 struct neon_type vectype;
88714cb8
DG
351 /* This does not indicate an actual NEON instruction, only that
352 the mnemonic accepts neon-style type suffixes. */
353 int is_neon;
0110f2b8
PB
354 /* Set to the opcode if the instruction needs relaxation.
355 Zero if the instruction is not relaxed. */
356 unsigned long relax;
b99bd4ef
NC
357 struct
358 {
359 bfd_reloc_code_real_type type;
c19d1205
ZW
360 expressionS exp;
361 int pc_rel;
b99bd4ef 362 } reloc;
b99bd4ef 363
e07e6e58
NC
364 enum it_instruction_type it_insn_type;
365
c19d1205
ZW
366 struct
367 {
368 unsigned reg;
ca3f61f7 369 signed int imm;
dcbf9037 370 struct neon_type_el vectype;
ca3f61f7
NC
371 unsigned present : 1; /* Operand present. */
372 unsigned isreg : 1; /* Operand was a register. */
373 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
374 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
375 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 376 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
377 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
378 instructions. This allows us to disambiguate ARM <-> vector insns. */
379 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 380 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 381 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 382 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
383 unsigned hasreloc : 1; /* Operand has relocation suffix. */
384 unsigned writeback : 1; /* Operand has trailing ! */
385 unsigned preind : 1; /* Preindexed address. */
386 unsigned postind : 1; /* Postindexed address. */
387 unsigned negative : 1; /* Index register was negated. */
388 unsigned shifted : 1; /* Shift applied to operation. */
389 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 390 } operands[6];
b99bd4ef
NC
391};
392
c19d1205 393static struct arm_it inst;
b99bd4ef
NC
394
395#define NUM_FLOAT_VALS 8
396
05d2d07e 397const char * fp_const[] =
b99bd4ef
NC
398{
399 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400};
401
c19d1205 402/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
403#define MAX_LITTLENUMS 6
404
405LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
406
407#define FAIL (-1)
408#define SUCCESS (0)
409
410#define SUFF_S 1
411#define SUFF_D 2
412#define SUFF_E 3
413#define SUFF_P 4
414
c19d1205
ZW
415#define CP_T_X 0x00008000
416#define CP_T_Y 0x00400000
b99bd4ef 417
c19d1205
ZW
418#define CONDS_BIT 0x00100000
419#define LOAD_BIT 0x00100000
b99bd4ef
NC
420
421#define DOUBLE_LOAD_FLAG 0x00000001
422
423struct asm_cond
424{
d3ce72d0 425 const char * template_name;
c921be7d 426 unsigned long value;
b99bd4ef
NC
427};
428
c19d1205 429#define COND_ALWAYS 0xE
b99bd4ef 430
b99bd4ef
NC
431struct asm_psr
432{
d3ce72d0 433 const char * template_name;
c921be7d 434 unsigned long field;
b99bd4ef
NC
435};
436
62b3e311
PB
437struct asm_barrier_opt
438{
d3ce72d0 439 const char * template_name;
c921be7d 440 unsigned long value;
62b3e311
PB
441};
442
2d2255b5 443/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
444#define SPSR_BIT (1 << 22)
445
c19d1205
ZW
446/* The individual PSR flag bits. */
447#define PSR_c (1 << 16)
448#define PSR_x (1 << 17)
449#define PSR_s (1 << 18)
450#define PSR_f (1 << 19)
b99bd4ef 451
c19d1205 452struct reloc_entry
bfae80f2 453{
c921be7d
NC
454 char * name;
455 bfd_reloc_code_real_type reloc;
bfae80f2
RE
456};
457
5287ad62 458enum vfp_reg_pos
bfae80f2 459{
5287ad62
JB
460 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
461 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
462};
463
464enum vfp_ldstm_type
465{
466 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467};
468
dcbf9037
JB
469/* Bits for DEFINED field in neon_typed_alias. */
470#define NTA_HASTYPE 1
471#define NTA_HASINDEX 2
472
473struct neon_typed_alias
474{
c921be7d
NC
475 unsigned char defined;
476 unsigned char index;
477 struct neon_type_el eltype;
dcbf9037
JB
478};
479
c19d1205
ZW
480/* ARM register categories. This includes coprocessor numbers and various
481 architecture extensions' registers. */
482enum arm_reg_type
bfae80f2 483{
c19d1205
ZW
484 REG_TYPE_RN,
485 REG_TYPE_CP,
486 REG_TYPE_CN,
487 REG_TYPE_FN,
488 REG_TYPE_VFS,
489 REG_TYPE_VFD,
5287ad62 490 REG_TYPE_NQ,
037e8744 491 REG_TYPE_VFSD,
5287ad62 492 REG_TYPE_NDQ,
037e8744 493 REG_TYPE_NSDQ,
c19d1205
ZW
494 REG_TYPE_VFC,
495 REG_TYPE_MVF,
496 REG_TYPE_MVD,
497 REG_TYPE_MVFX,
498 REG_TYPE_MVDX,
499 REG_TYPE_MVAX,
500 REG_TYPE_DSPSC,
501 REG_TYPE_MMXWR,
502 REG_TYPE_MMXWC,
503 REG_TYPE_MMXWCG,
504 REG_TYPE_XSCALE,
bfae80f2
RE
505};
506
dcbf9037
JB
507/* Structure for a hash table entry for a register.
508 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
509 information which states whether a vector type or index is specified (for a
510 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
511struct reg_entry
512{
c921be7d
NC
513 const char * name;
514 unsigned char number;
515 unsigned char type;
516 unsigned char builtin;
517 struct neon_typed_alias * neon;
6c43fab6
RE
518};
519
c19d1205 520/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 521const char * const reg_expected_msgs[] =
c19d1205
ZW
522{
523 N_("ARM register expected"),
524 N_("bad or missing co-processor number"),
525 N_("co-processor register expected"),
526 N_("FPA register expected"),
527 N_("VFP single precision register expected"),
5287ad62
JB
528 N_("VFP/Neon double precision register expected"),
529 N_("Neon quad precision register expected"),
037e8744 530 N_("VFP single or double precision register expected"),
5287ad62 531 N_("Neon double or quad precision register expected"),
037e8744 532 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
533 N_("VFP system register expected"),
534 N_("Maverick MVF register expected"),
535 N_("Maverick MVD register expected"),
536 N_("Maverick MVFX register expected"),
537 N_("Maverick MVDX register expected"),
538 N_("Maverick MVAX register expected"),
539 N_("Maverick DSPSC register expected"),
540 N_("iWMMXt data register expected"),
541 N_("iWMMXt control register expected"),
542 N_("iWMMXt scalar register expected"),
543 N_("XScale accumulator register expected"),
6c43fab6
RE
544};
545
c19d1205
ZW
546/* Some well known registers that we refer to directly elsewhere. */
547#define REG_SP 13
548#define REG_LR 14
549#define REG_PC 15
404ff6b5 550
b99bd4ef
NC
551/* ARM instructions take 4bytes in the object file, Thumb instructions
552 take 2: */
c19d1205 553#define INSN_SIZE 4
b99bd4ef
NC
554
555struct asm_opcode
556{
557 /* Basic string to match. */
d3ce72d0 558 const char * template_name;
c19d1205
ZW
559
560 /* Parameters to instruction. */
5be8be5d 561 unsigned int operands[8];
c19d1205
ZW
562
563 /* Conditional tag - see opcode_lookup. */
564 unsigned int tag : 4;
b99bd4ef
NC
565
566 /* Basic instruction code. */
c19d1205 567 unsigned int avalue : 28;
b99bd4ef 568
c19d1205
ZW
569 /* Thumb-format instruction code. */
570 unsigned int tvalue;
b99bd4ef 571
90e4755a 572 /* Which architecture variant provides this instruction. */
c921be7d
NC
573 const arm_feature_set * avariant;
574 const arm_feature_set * tvariant;
c19d1205
ZW
575
576 /* Function to call to encode instruction in ARM format. */
577 void (* aencode) (void);
b99bd4ef 578
c19d1205
ZW
579 /* Function to call to encode instruction in Thumb format. */
580 void (* tencode) (void);
b99bd4ef
NC
581};
582
a737bd4d
NC
583/* Defines for various bits that we will want to toggle. */
584#define INST_IMMEDIATE 0x02000000
585#define OFFSET_REG 0x02000000
c19d1205 586#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
587#define SHIFT_BY_REG 0x00000010
588#define PRE_INDEX 0x01000000
589#define INDEX_UP 0x00800000
590#define WRITE_BACK 0x00200000
591#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 592#define CPSI_MMOD 0x00020000
90e4755a 593
a737bd4d
NC
594#define LITERAL_MASK 0xf000f000
595#define OPCODE_MASK 0xfe1fffff
596#define V4_STR_BIT 0x00000020
90e4755a 597
efd81785
PB
598#define T2_SUBS_PC_LR 0xf3de8f00
599
a737bd4d 600#define DATA_OP_SHIFT 21
90e4755a 601
ef8d22e6
PB
602#define T2_OPCODE_MASK 0xfe1fffff
603#define T2_DATA_OP_SHIFT 21
604
a737bd4d
NC
605/* Codes to distinguish the arithmetic instructions. */
606#define OPCODE_AND 0
607#define OPCODE_EOR 1
608#define OPCODE_SUB 2
609#define OPCODE_RSB 3
610#define OPCODE_ADD 4
611#define OPCODE_ADC 5
612#define OPCODE_SBC 6
613#define OPCODE_RSC 7
614#define OPCODE_TST 8
615#define OPCODE_TEQ 9
616#define OPCODE_CMP 10
617#define OPCODE_CMN 11
618#define OPCODE_ORR 12
619#define OPCODE_MOV 13
620#define OPCODE_BIC 14
621#define OPCODE_MVN 15
90e4755a 622
ef8d22e6
PB
623#define T2_OPCODE_AND 0
624#define T2_OPCODE_BIC 1
625#define T2_OPCODE_ORR 2
626#define T2_OPCODE_ORN 3
627#define T2_OPCODE_EOR 4
628#define T2_OPCODE_ADD 8
629#define T2_OPCODE_ADC 10
630#define T2_OPCODE_SBC 11
631#define T2_OPCODE_SUB 13
632#define T2_OPCODE_RSB 14
633
a737bd4d
NC
634#define T_OPCODE_MUL 0x4340
635#define T_OPCODE_TST 0x4200
636#define T_OPCODE_CMN 0x42c0
637#define T_OPCODE_NEG 0x4240
638#define T_OPCODE_MVN 0x43c0
90e4755a 639
a737bd4d
NC
640#define T_OPCODE_ADD_R3 0x1800
641#define T_OPCODE_SUB_R3 0x1a00
642#define T_OPCODE_ADD_HI 0x4400
643#define T_OPCODE_ADD_ST 0xb000
644#define T_OPCODE_SUB_ST 0xb080
645#define T_OPCODE_ADD_SP 0xa800
646#define T_OPCODE_ADD_PC 0xa000
647#define T_OPCODE_ADD_I8 0x3000
648#define T_OPCODE_SUB_I8 0x3800
649#define T_OPCODE_ADD_I3 0x1c00
650#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 651
a737bd4d
NC
652#define T_OPCODE_ASR_R 0x4100
653#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
654#define T_OPCODE_LSR_R 0x40c0
655#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
656#define T_OPCODE_ASR_I 0x1000
657#define T_OPCODE_LSL_I 0x0000
658#define T_OPCODE_LSR_I 0x0800
b99bd4ef 659
a737bd4d
NC
660#define T_OPCODE_MOV_I8 0x2000
661#define T_OPCODE_CMP_I8 0x2800
662#define T_OPCODE_CMP_LR 0x4280
663#define T_OPCODE_MOV_HR 0x4600
664#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 665
a737bd4d
NC
666#define T_OPCODE_LDR_PC 0x4800
667#define T_OPCODE_LDR_SP 0x9800
668#define T_OPCODE_STR_SP 0x9000
669#define T_OPCODE_LDR_IW 0x6800
670#define T_OPCODE_STR_IW 0x6000
671#define T_OPCODE_LDR_IH 0x8800
672#define T_OPCODE_STR_IH 0x8000
673#define T_OPCODE_LDR_IB 0x7800
674#define T_OPCODE_STR_IB 0x7000
675#define T_OPCODE_LDR_RW 0x5800
676#define T_OPCODE_STR_RW 0x5000
677#define T_OPCODE_LDR_RH 0x5a00
678#define T_OPCODE_STR_RH 0x5200
679#define T_OPCODE_LDR_RB 0x5c00
680#define T_OPCODE_STR_RB 0x5400
c9b604bd 681
a737bd4d
NC
682#define T_OPCODE_PUSH 0xb400
683#define T_OPCODE_POP 0xbc00
b99bd4ef 684
2fc8bdac 685#define T_OPCODE_BRANCH 0xe000
b99bd4ef 686
a737bd4d 687#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 688#define THUMB_PP_PC_LR 0x0100
c19d1205 689#define THUMB_LOAD_BIT 0x0800
53365c0d 690#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
691
692#define BAD_ARGS _("bad arguments to instruction")
fdfde340 693#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
694#define BAD_PC _("r15 not allowed here")
695#define BAD_COND _("instruction cannot be conditional")
696#define BAD_OVERLAP _("registers may not be the same")
697#define BAD_HIREG _("lo register required")
698#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 699#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
700#define BAD_BRANCH _("branch must be last instruction in IT block")
701#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 702#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
703#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
704#define BAD_IT_COND _("incorrect condition in IT block")
705#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 706#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
707#define BAD_PC_ADDRESSING \
708 _("cannot use register index with PC-relative addressing")
709#define BAD_PC_WRITEBACK \
710 _("cannot use writeback with PC-relative addressing")
c19d1205 711
c921be7d
NC
712static struct hash_control * arm_ops_hsh;
713static struct hash_control * arm_cond_hsh;
714static struct hash_control * arm_shift_hsh;
715static struct hash_control * arm_psr_hsh;
716static struct hash_control * arm_v7m_psr_hsh;
717static struct hash_control * arm_reg_hsh;
718static struct hash_control * arm_reloc_hsh;
719static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 720
b99bd4ef
NC
721/* Stuff needed to resolve the label ambiguity
722 As:
723 ...
724 label: <insn>
725 may differ from:
726 ...
727 label:
5f4273c7 728 <insn> */
b99bd4ef
NC
729
730symbolS * last_label_seen;
b34976b6 731static int label_is_thumb_function_name = FALSE;
e07e6e58 732
3d0c9500
NC
733/* Literal pool structure. Held on a per-section
734 and per-sub-section basis. */
a737bd4d 735
c19d1205 736#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 737typedef struct literal_pool
b99bd4ef 738{
c921be7d
NC
739 expressionS literals [MAX_LITERAL_POOL_SIZE];
740 unsigned int next_free_entry;
741 unsigned int id;
742 symbolS * symbol;
743 segT section;
744 subsegT sub_section;
745 struct literal_pool * next;
3d0c9500 746} literal_pool;
b99bd4ef 747
3d0c9500
NC
748/* Pointer to a linked list of literal pools. */
749literal_pool * list_of_pools = NULL;
e27ec89e 750
e07e6e58
NC
751#ifdef OBJ_ELF
752# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
753#else
754static struct current_it now_it;
755#endif
756
757static inline int
758now_it_compatible (int cond)
759{
760 return (cond & ~1) == (now_it.cc & ~1);
761}
762
763static inline int
764conditional_insn (void)
765{
766 return inst.cond != COND_ALWAYS;
767}
768
769static int in_it_block (void);
770
771static int handle_it_state (void);
772
773static void force_automatic_it_block_close (void);
774
c921be7d
NC
775static void it_fsm_post_encode (void);
776
e07e6e58
NC
777#define set_it_insn_type(type) \
778 do \
779 { \
780 inst.it_insn_type = type; \
781 if (handle_it_state () == FAIL) \
782 return; \
783 } \
784 while (0)
785
c921be7d
NC
786#define set_it_insn_type_nonvoid(type, failret) \
787 do \
788 { \
789 inst.it_insn_type = type; \
790 if (handle_it_state () == FAIL) \
791 return failret; \
792 } \
793 while(0)
794
e07e6e58
NC
795#define set_it_insn_type_last() \
796 do \
797 { \
798 if (inst.cond == COND_ALWAYS) \
799 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
800 else \
801 set_it_insn_type (INSIDE_IT_LAST_INSN); \
802 } \
803 while (0)
804
c19d1205 805/* Pure syntax. */
b99bd4ef 806
c19d1205
ZW
807/* This array holds the chars that always start a comment. If the
808 pre-processor is disabled, these aren't very useful. */
809const char comment_chars[] = "@";
3d0c9500 810
c19d1205
ZW
811/* This array holds the chars that only start a comment at the beginning of
812 a line. If the line seems to have the form '# 123 filename'
813 .line and .file directives will appear in the pre-processed output. */
814/* Note that input_file.c hand checks for '#' at the beginning of the
815 first line of the input file. This is because the compiler outputs
816 #NO_APP at the beginning of its output. */
817/* Also note that comments like this one will always work. */
818const char line_comment_chars[] = "#";
3d0c9500 819
c19d1205 820const char line_separator_chars[] = ";";
b99bd4ef 821
c19d1205
ZW
822/* Chars that can be used to separate mant
823 from exp in floating point numbers. */
824const char EXP_CHARS[] = "eE";
3d0c9500 825
c19d1205
ZW
826/* Chars that mean this number is a floating point constant. */
827/* As in 0f12.456 */
828/* or 0d1.2345e12 */
b99bd4ef 829
c19d1205 830const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 831
c19d1205
ZW
832/* Prefix characters that indicate the start of an immediate
833 value. */
834#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 835
c19d1205
ZW
836/* Separator character handling. */
837
838#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
839
840static inline int
841skip_past_char (char ** str, char c)
842{
843 if (**str == c)
844 {
845 (*str)++;
846 return SUCCESS;
3d0c9500 847 }
c19d1205
ZW
848 else
849 return FAIL;
850}
c921be7d 851
c19d1205 852#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 853
c19d1205
ZW
854/* Arithmetic expressions (possibly involving symbols). */
855
856/* Return TRUE if anything in the expression is a bignum. */
857
858static int
859walk_no_bignums (symbolS * sp)
860{
861 if (symbol_get_value_expression (sp)->X_op == O_big)
862 return 1;
863
864 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 865 {
c19d1205
ZW
866 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
867 || (symbol_get_value_expression (sp)->X_op_symbol
868 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
869 }
870
c19d1205 871 return 0;
3d0c9500
NC
872}
873
c19d1205
ZW
874static int in_my_get_expression = 0;
875
876/* Third argument to my_get_expression. */
877#define GE_NO_PREFIX 0
878#define GE_IMM_PREFIX 1
879#define GE_OPT_PREFIX 2
5287ad62
JB
880/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
881 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
882#define GE_OPT_PREFIX_BIG 3
a737bd4d 883
b99bd4ef 884static int
c19d1205 885my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 886{
c19d1205
ZW
887 char * save_in;
888 segT seg;
b99bd4ef 889
c19d1205
ZW
890 /* In unified syntax, all prefixes are optional. */
891 if (unified_syntax)
5287ad62
JB
892 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
893 : GE_OPT_PREFIX;
b99bd4ef 894
c19d1205 895 switch (prefix_mode)
b99bd4ef 896 {
c19d1205
ZW
897 case GE_NO_PREFIX: break;
898 case GE_IMM_PREFIX:
899 if (!is_immediate_prefix (**str))
900 {
901 inst.error = _("immediate expression requires a # prefix");
902 return FAIL;
903 }
904 (*str)++;
905 break;
906 case GE_OPT_PREFIX:
5287ad62 907 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
908 if (is_immediate_prefix (**str))
909 (*str)++;
910 break;
911 default: abort ();
912 }
b99bd4ef 913
c19d1205 914 memset (ep, 0, sizeof (expressionS));
b99bd4ef 915
c19d1205
ZW
916 save_in = input_line_pointer;
917 input_line_pointer = *str;
918 in_my_get_expression = 1;
919 seg = expression (ep);
920 in_my_get_expression = 0;
921
f86adc07 922 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 923 {
f86adc07 924 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
925 *str = input_line_pointer;
926 input_line_pointer = save_in;
927 if (inst.error == NULL)
f86adc07
NS
928 inst.error = (ep->X_op == O_absent
929 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
930 return 1;
931 }
b99bd4ef 932
c19d1205
ZW
933#ifdef OBJ_AOUT
934 if (seg != absolute_section
935 && seg != text_section
936 && seg != data_section
937 && seg != bss_section
938 && seg != undefined_section)
939 {
940 inst.error = _("bad segment");
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 return 1;
b99bd4ef 944 }
c19d1205 945#endif
b99bd4ef 946
c19d1205
ZW
947 /* Get rid of any bignums now, so that we don't generate an error for which
948 we can't establish a line number later on. Big numbers are never valid
949 in instructions, which is where this routine is always called. */
5287ad62
JB
950 if (prefix_mode != GE_OPT_PREFIX_BIG
951 && (ep->X_op == O_big
952 || (ep->X_add_symbol
953 && (walk_no_bignums (ep->X_add_symbol)
954 || (ep->X_op_symbol
955 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
956 {
957 inst.error = _("invalid constant");
958 *str = input_line_pointer;
959 input_line_pointer = save_in;
960 return 1;
961 }
b99bd4ef 962
c19d1205
ZW
963 *str = input_line_pointer;
964 input_line_pointer = save_in;
965 return 0;
b99bd4ef
NC
966}
967
c19d1205
ZW
968/* Turn a string in input_line_pointer into a floating point constant
969 of type TYPE, and store the appropriate bytes in *LITP. The number
970 of LITTLENUMS emitted is stored in *SIZEP. An error message is
971 returned, or NULL on OK.
b99bd4ef 972
c19d1205
ZW
973 Note that fp constants aren't represent in the normal way on the ARM.
974 In big endian mode, things are as expected. However, in little endian
975 mode fp constants are big-endian word-wise, and little-endian byte-wise
976 within the words. For example, (double) 1.1 in big endian mode is
977 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
978 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 979
c19d1205 980 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 981
c19d1205
ZW
982char *
983md_atof (int type, char * litP, int * sizeP)
984{
985 int prec;
986 LITTLENUM_TYPE words[MAX_LITTLENUMS];
987 char *t;
988 int i;
b99bd4ef 989
c19d1205
ZW
990 switch (type)
991 {
992 case 'f':
993 case 'F':
994 case 's':
995 case 'S':
996 prec = 2;
997 break;
b99bd4ef 998
c19d1205
ZW
999 case 'd':
1000 case 'D':
1001 case 'r':
1002 case 'R':
1003 prec = 4;
1004 break;
b99bd4ef 1005
c19d1205
ZW
1006 case 'x':
1007 case 'X':
499ac353 1008 prec = 5;
c19d1205 1009 break;
b99bd4ef 1010
c19d1205
ZW
1011 case 'p':
1012 case 'P':
499ac353 1013 prec = 5;
c19d1205 1014 break;
a737bd4d 1015
c19d1205
ZW
1016 default:
1017 *sizeP = 0;
499ac353 1018 return _("Unrecognized or unsupported floating point constant");
c19d1205 1019 }
b99bd4ef 1020
c19d1205
ZW
1021 t = atof_ieee (input_line_pointer, type, words);
1022 if (t)
1023 input_line_pointer = t;
499ac353 1024 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1025
c19d1205
ZW
1026 if (target_big_endian)
1027 {
1028 for (i = 0; i < prec; i++)
1029 {
499ac353
NC
1030 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1031 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1032 }
1033 }
1034 else
1035 {
e74cfd16 1036 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1037 for (i = prec - 1; i >= 0; i--)
1038 {
499ac353
NC
1039 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1040 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1041 }
1042 else
1043 /* For a 4 byte float the order of elements in `words' is 1 0.
1044 For an 8 byte float the order is 1 0 3 2. */
1045 for (i = 0; i < prec; i += 2)
1046 {
499ac353
NC
1047 md_number_to_chars (litP, (valueT) words[i + 1],
1048 sizeof (LITTLENUM_TYPE));
1049 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1050 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1051 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1052 }
1053 }
b99bd4ef 1054
499ac353 1055 return NULL;
c19d1205 1056}
b99bd4ef 1057
c19d1205
ZW
1058/* We handle all bad expressions here, so that we can report the faulty
1059 instruction in the error message. */
1060void
91d6fa6a 1061md_operand (expressionS * exp)
c19d1205
ZW
1062{
1063 if (in_my_get_expression)
91d6fa6a 1064 exp->X_op = O_illegal;
b99bd4ef
NC
1065}
1066
c19d1205 1067/* Immediate values. */
b99bd4ef 1068
c19d1205
ZW
1069/* Generic immediate-value read function for use in directives.
1070 Accepts anything that 'expression' can fold to a constant.
1071 *val receives the number. */
1072#ifdef OBJ_ELF
1073static int
1074immediate_for_directive (int *val)
b99bd4ef 1075{
c19d1205
ZW
1076 expressionS exp;
1077 exp.X_op = O_illegal;
b99bd4ef 1078
c19d1205
ZW
1079 if (is_immediate_prefix (*input_line_pointer))
1080 {
1081 input_line_pointer++;
1082 expression (&exp);
1083 }
b99bd4ef 1084
c19d1205
ZW
1085 if (exp.X_op != O_constant)
1086 {
1087 as_bad (_("expected #constant"));
1088 ignore_rest_of_line ();
1089 return FAIL;
1090 }
1091 *val = exp.X_add_number;
1092 return SUCCESS;
b99bd4ef 1093}
c19d1205 1094#endif
b99bd4ef 1095
c19d1205 1096/* Register parsing. */
b99bd4ef 1097
c19d1205
ZW
1098/* Generic register parser. CCP points to what should be the
1099 beginning of a register name. If it is indeed a valid register
1100 name, advance CCP over it and return the reg_entry structure;
1101 otherwise return NULL. Does not issue diagnostics. */
1102
1103static struct reg_entry *
1104arm_reg_parse_multi (char **ccp)
b99bd4ef 1105{
c19d1205
ZW
1106 char *start = *ccp;
1107 char *p;
1108 struct reg_entry *reg;
b99bd4ef 1109
c19d1205
ZW
1110#ifdef REGISTER_PREFIX
1111 if (*start != REGISTER_PREFIX)
01cfc07f 1112 return NULL;
c19d1205
ZW
1113 start++;
1114#endif
1115#ifdef OPTIONAL_REGISTER_PREFIX
1116 if (*start == OPTIONAL_REGISTER_PREFIX)
1117 start++;
1118#endif
b99bd4ef 1119
c19d1205
ZW
1120 p = start;
1121 if (!ISALPHA (*p) || !is_name_beginner (*p))
1122 return NULL;
b99bd4ef 1123
c19d1205
ZW
1124 do
1125 p++;
1126 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1127
1128 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1129
1130 if (!reg)
1131 return NULL;
1132
1133 *ccp = p;
1134 return reg;
b99bd4ef
NC
1135}
1136
1137static int
dcbf9037
JB
1138arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1139 enum arm_reg_type type)
b99bd4ef 1140{
c19d1205
ZW
1141 /* Alternative syntaxes are accepted for a few register classes. */
1142 switch (type)
1143 {
1144 case REG_TYPE_MVF:
1145 case REG_TYPE_MVD:
1146 case REG_TYPE_MVFX:
1147 case REG_TYPE_MVDX:
1148 /* Generic coprocessor register names are allowed for these. */
79134647 1149 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1150 return reg->number;
1151 break;
69b97547 1152
c19d1205
ZW
1153 case REG_TYPE_CP:
1154 /* For backward compatibility, a bare number is valid here. */
1155 {
1156 unsigned long processor = strtoul (start, ccp, 10);
1157 if (*ccp != start && processor <= 15)
1158 return processor;
1159 }
6057a28f 1160
c19d1205
ZW
1161 case REG_TYPE_MMXWC:
1162 /* WC includes WCG. ??? I'm not sure this is true for all
1163 instructions that take WC registers. */
79134647 1164 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1165 return reg->number;
6057a28f 1166 break;
c19d1205 1167
6057a28f 1168 default:
c19d1205 1169 break;
6057a28f
NC
1170 }
1171
dcbf9037
JB
1172 return FAIL;
1173}
1174
1175/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1176 return value is the register number or FAIL. */
1177
1178static int
1179arm_reg_parse (char **ccp, enum arm_reg_type type)
1180{
1181 char *start = *ccp;
1182 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1183 int ret;
1184
1185 /* Do not allow a scalar (reg+index) to parse as a register. */
1186 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1187 return FAIL;
1188
1189 if (reg && reg->type == type)
1190 return reg->number;
1191
1192 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1193 return ret;
1194
c19d1205
ZW
1195 *ccp = start;
1196 return FAIL;
1197}
69b97547 1198
dcbf9037
JB
1199/* Parse a Neon type specifier. *STR should point at the leading '.'
1200 character. Does no verification at this stage that the type fits the opcode
1201 properly. E.g.,
1202
1203 .i32.i32.s16
1204 .s32.f32
1205 .u16
1206
1207 Can all be legally parsed by this function.
1208
1209 Fills in neon_type struct pointer with parsed information, and updates STR
1210 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1211 type, FAIL if not. */
1212
1213static int
1214parse_neon_type (struct neon_type *type, char **str)
1215{
1216 char *ptr = *str;
1217
1218 if (type)
1219 type->elems = 0;
1220
1221 while (type->elems < NEON_MAX_TYPE_ELS)
1222 {
1223 enum neon_el_type thistype = NT_untyped;
1224 unsigned thissize = -1u;
1225
1226 if (*ptr != '.')
1227 break;
1228
1229 ptr++;
1230
1231 /* Just a size without an explicit type. */
1232 if (ISDIGIT (*ptr))
1233 goto parsesize;
1234
1235 switch (TOLOWER (*ptr))
1236 {
1237 case 'i': thistype = NT_integer; break;
1238 case 'f': thistype = NT_float; break;
1239 case 'p': thistype = NT_poly; break;
1240 case 's': thistype = NT_signed; break;
1241 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1242 case 'd':
1243 thistype = NT_float;
1244 thissize = 64;
1245 ptr++;
1246 goto done;
dcbf9037
JB
1247 default:
1248 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1249 return FAIL;
1250 }
1251
1252 ptr++;
1253
1254 /* .f is an abbreviation for .f32. */
1255 if (thistype == NT_float && !ISDIGIT (*ptr))
1256 thissize = 32;
1257 else
1258 {
1259 parsesize:
1260 thissize = strtoul (ptr, &ptr, 10);
1261
1262 if (thissize != 8 && thissize != 16 && thissize != 32
1263 && thissize != 64)
1264 {
1265 as_bad (_("bad size %d in type specifier"), thissize);
1266 return FAIL;
1267 }
1268 }
1269
037e8744 1270 done:
dcbf9037
JB
1271 if (type)
1272 {
1273 type->el[type->elems].type = thistype;
1274 type->el[type->elems].size = thissize;
1275 type->elems++;
1276 }
1277 }
1278
1279 /* Empty/missing type is not a successful parse. */
1280 if (type->elems == 0)
1281 return FAIL;
1282
1283 *str = ptr;
1284
1285 return SUCCESS;
1286}
1287
1288/* Errors may be set multiple times during parsing or bit encoding
1289 (particularly in the Neon bits), but usually the earliest error which is set
1290 will be the most meaningful. Avoid overwriting it with later (cascading)
1291 errors by calling this function. */
1292
1293static void
1294first_error (const char *err)
1295{
1296 if (!inst.error)
1297 inst.error = err;
1298}
1299
1300/* Parse a single type, e.g. ".s32", leading period included. */
1301static int
1302parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1303{
1304 char *str = *ccp;
1305 struct neon_type optype;
1306
1307 if (*str == '.')
1308 {
1309 if (parse_neon_type (&optype, &str) == SUCCESS)
1310 {
1311 if (optype.elems == 1)
1312 *vectype = optype.el[0];
1313 else
1314 {
1315 first_error (_("only one type should be specified for operand"));
1316 return FAIL;
1317 }
1318 }
1319 else
1320 {
1321 first_error (_("vector type expected"));
1322 return FAIL;
1323 }
1324 }
1325 else
1326 return FAIL;
5f4273c7 1327
dcbf9037 1328 *ccp = str;
5f4273c7 1329
dcbf9037
JB
1330 return SUCCESS;
1331}
1332
1333/* Special meanings for indices (which have a range of 0-7), which will fit into
1334 a 4-bit integer. */
1335
1336#define NEON_ALL_LANES 15
1337#define NEON_INTERLEAVE_LANES 14
1338
1339/* Parse either a register or a scalar, with an optional type. Return the
1340 register number, and optionally fill in the actual type of the register
1341 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1342 type/index information in *TYPEINFO. */
1343
1344static int
1345parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1346 enum arm_reg_type *rtype,
1347 struct neon_typed_alias *typeinfo)
1348{
1349 char *str = *ccp;
1350 struct reg_entry *reg = arm_reg_parse_multi (&str);
1351 struct neon_typed_alias atype;
1352 struct neon_type_el parsetype;
1353
1354 atype.defined = 0;
1355 atype.index = -1;
1356 atype.eltype.type = NT_invtype;
1357 atype.eltype.size = -1;
1358
1359 /* Try alternate syntax for some types of register. Note these are mutually
1360 exclusive with the Neon syntax extensions. */
1361 if (reg == NULL)
1362 {
1363 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1364 if (altreg != FAIL)
1365 *ccp = str;
1366 if (typeinfo)
1367 *typeinfo = atype;
1368 return altreg;
1369 }
1370
037e8744
JB
1371 /* Undo polymorphism when a set of register types may be accepted. */
1372 if ((type == REG_TYPE_NDQ
1373 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1374 || (type == REG_TYPE_VFSD
1375 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1376 || (type == REG_TYPE_NSDQ
1377 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1378 || reg->type == REG_TYPE_NQ))
1379 || (type == REG_TYPE_MMXWC
1380 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1381 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1382
1383 if (type != reg->type)
1384 return FAIL;
1385
1386 if (reg->neon)
1387 atype = *reg->neon;
5f4273c7 1388
dcbf9037
JB
1389 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1390 {
1391 if ((atype.defined & NTA_HASTYPE) != 0)
1392 {
1393 first_error (_("can't redefine type for operand"));
1394 return FAIL;
1395 }
1396 atype.defined |= NTA_HASTYPE;
1397 atype.eltype = parsetype;
1398 }
5f4273c7 1399
dcbf9037
JB
1400 if (skip_past_char (&str, '[') == SUCCESS)
1401 {
1402 if (type != REG_TYPE_VFD)
1403 {
1404 first_error (_("only D registers may be indexed"));
1405 return FAIL;
1406 }
5f4273c7 1407
dcbf9037
JB
1408 if ((atype.defined & NTA_HASINDEX) != 0)
1409 {
1410 first_error (_("can't change index for operand"));
1411 return FAIL;
1412 }
1413
1414 atype.defined |= NTA_HASINDEX;
1415
1416 if (skip_past_char (&str, ']') == SUCCESS)
1417 atype.index = NEON_ALL_LANES;
1418 else
1419 {
1420 expressionS exp;
1421
1422 my_get_expression (&exp, &str, GE_NO_PREFIX);
1423
1424 if (exp.X_op != O_constant)
1425 {
1426 first_error (_("constant expression required"));
1427 return FAIL;
1428 }
1429
1430 if (skip_past_char (&str, ']') == FAIL)
1431 return FAIL;
1432
1433 atype.index = exp.X_add_number;
1434 }
1435 }
5f4273c7 1436
dcbf9037
JB
1437 if (typeinfo)
1438 *typeinfo = atype;
5f4273c7 1439
dcbf9037
JB
1440 if (rtype)
1441 *rtype = type;
5f4273c7 1442
dcbf9037 1443 *ccp = str;
5f4273c7 1444
dcbf9037
JB
1445 return reg->number;
1446}
1447
1448/* Like arm_reg_parse, but allow allow the following extra features:
1449 - If RTYPE is non-zero, return the (possibly restricted) type of the
1450 register (e.g. Neon double or quad reg when either has been requested).
1451 - If this is a Neon vector type with additional type information, fill
1452 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1453 This function will fault on encountering a scalar. */
dcbf9037
JB
1454
1455static int
1456arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1457 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1458{
1459 struct neon_typed_alias atype;
1460 char *str = *ccp;
1461 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1462
1463 if (reg == FAIL)
1464 return FAIL;
1465
1466 /* Do not allow a scalar (reg+index) to parse as a register. */
1467 if ((atype.defined & NTA_HASINDEX) != 0)
1468 {
1469 first_error (_("register operand expected, but got scalar"));
1470 return FAIL;
1471 }
1472
1473 if (vectype)
1474 *vectype = atype.eltype;
1475
1476 *ccp = str;
1477
1478 return reg;
1479}
1480
1481#define NEON_SCALAR_REG(X) ((X) >> 4)
1482#define NEON_SCALAR_INDEX(X) ((X) & 15)
1483
5287ad62
JB
1484/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1485 have enough information to be able to do a good job bounds-checking. So, we
1486 just do easy checks here, and do further checks later. */
1487
1488static int
dcbf9037 1489parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1490{
dcbf9037 1491 int reg;
5287ad62 1492 char *str = *ccp;
dcbf9037 1493 struct neon_typed_alias atype;
5f4273c7 1494
dcbf9037 1495 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1496
dcbf9037 1497 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1498 return FAIL;
5f4273c7 1499
dcbf9037 1500 if (atype.index == NEON_ALL_LANES)
5287ad62 1501 {
dcbf9037 1502 first_error (_("scalar must have an index"));
5287ad62
JB
1503 return FAIL;
1504 }
dcbf9037 1505 else if (atype.index >= 64 / elsize)
5287ad62 1506 {
dcbf9037 1507 first_error (_("scalar index out of range"));
5287ad62
JB
1508 return FAIL;
1509 }
5f4273c7 1510
dcbf9037
JB
1511 if (type)
1512 *type = atype.eltype;
5f4273c7 1513
5287ad62 1514 *ccp = str;
5f4273c7 1515
dcbf9037 1516 return reg * 16 + atype.index;
5287ad62
JB
1517}
1518
c19d1205 1519/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1520
c19d1205
ZW
1521static long
1522parse_reg_list (char ** strp)
1523{
1524 char * str = * strp;
1525 long range = 0;
1526 int another_range;
a737bd4d 1527
c19d1205
ZW
1528 /* We come back here if we get ranges concatenated by '+' or '|'. */
1529 do
6057a28f 1530 {
c19d1205 1531 another_range = 0;
a737bd4d 1532
c19d1205
ZW
1533 if (*str == '{')
1534 {
1535 int in_range = 0;
1536 int cur_reg = -1;
a737bd4d 1537
c19d1205
ZW
1538 str++;
1539 do
1540 {
1541 int reg;
6057a28f 1542
dcbf9037 1543 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1544 {
dcbf9037 1545 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1546 return FAIL;
1547 }
a737bd4d 1548
c19d1205
ZW
1549 if (in_range)
1550 {
1551 int i;
a737bd4d 1552
c19d1205
ZW
1553 if (reg <= cur_reg)
1554 {
dcbf9037 1555 first_error (_("bad range in register list"));
c19d1205
ZW
1556 return FAIL;
1557 }
40a18ebd 1558
c19d1205
ZW
1559 for (i = cur_reg + 1; i < reg; i++)
1560 {
1561 if (range & (1 << i))
1562 as_tsktsk
1563 (_("Warning: duplicated register (r%d) in register list"),
1564 i);
1565 else
1566 range |= 1 << i;
1567 }
1568 in_range = 0;
1569 }
a737bd4d 1570
c19d1205
ZW
1571 if (range & (1 << reg))
1572 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1573 reg);
1574 else if (reg <= cur_reg)
1575 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1576
c19d1205
ZW
1577 range |= 1 << reg;
1578 cur_reg = reg;
1579 }
1580 while (skip_past_comma (&str) != FAIL
1581 || (in_range = 1, *str++ == '-'));
1582 str--;
a737bd4d 1583
c19d1205
ZW
1584 if (*str++ != '}')
1585 {
dcbf9037 1586 first_error (_("missing `}'"));
c19d1205
ZW
1587 return FAIL;
1588 }
1589 }
1590 else
1591 {
91d6fa6a 1592 expressionS exp;
40a18ebd 1593
91d6fa6a 1594 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1595 return FAIL;
40a18ebd 1596
91d6fa6a 1597 if (exp.X_op == O_constant)
c19d1205 1598 {
91d6fa6a
NC
1599 if (exp.X_add_number
1600 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1601 {
1602 inst.error = _("invalid register mask");
1603 return FAIL;
1604 }
a737bd4d 1605
91d6fa6a 1606 if ((range & exp.X_add_number) != 0)
c19d1205 1607 {
91d6fa6a 1608 int regno = range & exp.X_add_number;
a737bd4d 1609
c19d1205
ZW
1610 regno &= -regno;
1611 regno = (1 << regno) - 1;
1612 as_tsktsk
1613 (_("Warning: duplicated register (r%d) in register list"),
1614 regno);
1615 }
a737bd4d 1616
91d6fa6a 1617 range |= exp.X_add_number;
c19d1205
ZW
1618 }
1619 else
1620 {
1621 if (inst.reloc.type != 0)
1622 {
1623 inst.error = _("expression too complex");
1624 return FAIL;
1625 }
a737bd4d 1626
91d6fa6a 1627 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1628 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1629 inst.reloc.pc_rel = 0;
1630 }
1631 }
a737bd4d 1632
c19d1205
ZW
1633 if (*str == '|' || *str == '+')
1634 {
1635 str++;
1636 another_range = 1;
1637 }
a737bd4d 1638 }
c19d1205 1639 while (another_range);
a737bd4d 1640
c19d1205
ZW
1641 *strp = str;
1642 return range;
a737bd4d
NC
1643}
1644
5287ad62
JB
1645/* Types of registers in a list. */
1646
1647enum reg_list_els
1648{
1649 REGLIST_VFP_S,
1650 REGLIST_VFP_D,
1651 REGLIST_NEON_D
1652};
1653
c19d1205
ZW
1654/* Parse a VFP register list. If the string is invalid return FAIL.
1655 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1656 register. Parses registers of type ETYPE.
1657 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1658 - Q registers can be used to specify pairs of D registers
1659 - { } can be omitted from around a singleton register list
1660 FIXME: This is not implemented, as it would require backtracking in
1661 some cases, e.g.:
1662 vtbl.8 d3,d4,d5
1663 This could be done (the meaning isn't really ambiguous), but doesn't
1664 fit in well with the current parsing framework.
dcbf9037
JB
1665 - 32 D registers may be used (also true for VFPv3).
1666 FIXME: Types are ignored in these register lists, which is probably a
1667 bug. */
6057a28f 1668
c19d1205 1669static int
037e8744 1670parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1671{
037e8744 1672 char *str = *ccp;
c19d1205
ZW
1673 int base_reg;
1674 int new_base;
21d799b5 1675 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1676 int max_regs = 0;
c19d1205
ZW
1677 int count = 0;
1678 int warned = 0;
1679 unsigned long mask = 0;
a737bd4d 1680 int i;
6057a28f 1681
037e8744 1682 if (*str != '{')
5287ad62
JB
1683 {
1684 inst.error = _("expecting {");
1685 return FAIL;
1686 }
6057a28f 1687
037e8744 1688 str++;
6057a28f 1689
5287ad62 1690 switch (etype)
c19d1205 1691 {
5287ad62 1692 case REGLIST_VFP_S:
c19d1205
ZW
1693 regtype = REG_TYPE_VFS;
1694 max_regs = 32;
5287ad62 1695 break;
5f4273c7 1696
5287ad62
JB
1697 case REGLIST_VFP_D:
1698 regtype = REG_TYPE_VFD;
b7fc2769 1699 break;
5f4273c7 1700
b7fc2769
JB
1701 case REGLIST_NEON_D:
1702 regtype = REG_TYPE_NDQ;
1703 break;
1704 }
1705
1706 if (etype != REGLIST_VFP_S)
1707 {
b1cc4aeb
PB
1708 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1709 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1710 {
1711 max_regs = 32;
1712 if (thumb_mode)
1713 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1714 fpu_vfp_ext_d32);
5287ad62
JB
1715 else
1716 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1717 fpu_vfp_ext_d32);
5287ad62
JB
1718 }
1719 else
1720 max_regs = 16;
c19d1205 1721 }
6057a28f 1722
c19d1205 1723 base_reg = max_regs;
a737bd4d 1724
c19d1205
ZW
1725 do
1726 {
5287ad62 1727 int setmask = 1, addregs = 1;
dcbf9037 1728
037e8744 1729 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1730
c19d1205 1731 if (new_base == FAIL)
a737bd4d 1732 {
dcbf9037 1733 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1734 return FAIL;
1735 }
5f4273c7 1736
b7fc2769
JB
1737 if (new_base >= max_regs)
1738 {
1739 first_error (_("register out of range in list"));
1740 return FAIL;
1741 }
5f4273c7 1742
5287ad62
JB
1743 /* Note: a value of 2 * n is returned for the register Q<n>. */
1744 if (regtype == REG_TYPE_NQ)
1745 {
1746 setmask = 3;
1747 addregs = 2;
1748 }
1749
c19d1205
ZW
1750 if (new_base < base_reg)
1751 base_reg = new_base;
a737bd4d 1752
5287ad62 1753 if (mask & (setmask << new_base))
c19d1205 1754 {
dcbf9037 1755 first_error (_("invalid register list"));
c19d1205 1756 return FAIL;
a737bd4d 1757 }
a737bd4d 1758
c19d1205
ZW
1759 if ((mask >> new_base) != 0 && ! warned)
1760 {
1761 as_tsktsk (_("register list not in ascending order"));
1762 warned = 1;
1763 }
0bbf2aa4 1764
5287ad62
JB
1765 mask |= setmask << new_base;
1766 count += addregs;
0bbf2aa4 1767
037e8744 1768 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1769 {
1770 int high_range;
0bbf2aa4 1771
037e8744 1772 str++;
0bbf2aa4 1773
037e8744 1774 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1775 == FAIL)
c19d1205
ZW
1776 {
1777 inst.error = gettext (reg_expected_msgs[regtype]);
1778 return FAIL;
1779 }
0bbf2aa4 1780
b7fc2769
JB
1781 if (high_range >= max_regs)
1782 {
1783 first_error (_("register out of range in list"));
1784 return FAIL;
1785 }
1786
5287ad62
JB
1787 if (regtype == REG_TYPE_NQ)
1788 high_range = high_range + 1;
1789
c19d1205
ZW
1790 if (high_range <= new_base)
1791 {
1792 inst.error = _("register range not in ascending order");
1793 return FAIL;
1794 }
0bbf2aa4 1795
5287ad62 1796 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1797 {
5287ad62 1798 if (mask & (setmask << new_base))
0bbf2aa4 1799 {
c19d1205
ZW
1800 inst.error = _("invalid register list");
1801 return FAIL;
0bbf2aa4 1802 }
c19d1205 1803
5287ad62
JB
1804 mask |= setmask << new_base;
1805 count += addregs;
0bbf2aa4 1806 }
0bbf2aa4 1807 }
0bbf2aa4 1808 }
037e8744 1809 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1810
037e8744 1811 str++;
0bbf2aa4 1812
c19d1205
ZW
1813 /* Sanity check -- should have raised a parse error above. */
1814 if (count == 0 || count > max_regs)
1815 abort ();
1816
1817 *pbase = base_reg;
1818
1819 /* Final test -- the registers must be consecutive. */
1820 mask >>= base_reg;
1821 for (i = 0; i < count; i++)
1822 {
1823 if ((mask & (1u << i)) == 0)
1824 {
1825 inst.error = _("non-contiguous register range");
1826 return FAIL;
1827 }
1828 }
1829
037e8744
JB
1830 *ccp = str;
1831
c19d1205 1832 return count;
b99bd4ef
NC
1833}
1834
dcbf9037
JB
1835/* True if two alias types are the same. */
1836
c921be7d 1837static bfd_boolean
dcbf9037
JB
1838neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1839{
1840 if (!a && !b)
c921be7d 1841 return TRUE;
5f4273c7 1842
dcbf9037 1843 if (!a || !b)
c921be7d 1844 return FALSE;
dcbf9037
JB
1845
1846 if (a->defined != b->defined)
c921be7d 1847 return FALSE;
5f4273c7 1848
dcbf9037
JB
1849 if ((a->defined & NTA_HASTYPE) != 0
1850 && (a->eltype.type != b->eltype.type
1851 || a->eltype.size != b->eltype.size))
c921be7d 1852 return FALSE;
dcbf9037
JB
1853
1854 if ((a->defined & NTA_HASINDEX) != 0
1855 && (a->index != b->index))
c921be7d 1856 return FALSE;
5f4273c7 1857
c921be7d 1858 return TRUE;
dcbf9037
JB
1859}
1860
5287ad62
JB
1861/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1862 The base register is put in *PBASE.
dcbf9037 1863 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1864 the return value.
1865 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1866 Bits [6:5] encode the list length (minus one).
1867 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1868
5287ad62 1869#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1870#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1871#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1872
1873static int
dcbf9037
JB
1874parse_neon_el_struct_list (char **str, unsigned *pbase,
1875 struct neon_type_el *eltype)
5287ad62
JB
1876{
1877 char *ptr = *str;
1878 int base_reg = -1;
1879 int reg_incr = -1;
1880 int count = 0;
1881 int lane = -1;
1882 int leading_brace = 0;
1883 enum arm_reg_type rtype = REG_TYPE_NDQ;
1884 int addregs = 1;
20203fb9
NC
1885 const char *const incr_error = _("register stride must be 1 or 2");
1886 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1887 struct neon_typed_alias firsttype;
5f4273c7 1888
5287ad62
JB
1889 if (skip_past_char (&ptr, '{') == SUCCESS)
1890 leading_brace = 1;
5f4273c7 1891
5287ad62
JB
1892 do
1893 {
dcbf9037
JB
1894 struct neon_typed_alias atype;
1895 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1896
5287ad62
JB
1897 if (getreg == FAIL)
1898 {
dcbf9037 1899 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1900 return FAIL;
1901 }
5f4273c7 1902
5287ad62
JB
1903 if (base_reg == -1)
1904 {
1905 base_reg = getreg;
1906 if (rtype == REG_TYPE_NQ)
1907 {
1908 reg_incr = 1;
1909 addregs = 2;
1910 }
dcbf9037 1911 firsttype = atype;
5287ad62
JB
1912 }
1913 else if (reg_incr == -1)
1914 {
1915 reg_incr = getreg - base_reg;
1916 if (reg_incr < 1 || reg_incr > 2)
1917 {
dcbf9037 1918 first_error (_(incr_error));
5287ad62
JB
1919 return FAIL;
1920 }
1921 }
1922 else if (getreg != base_reg + reg_incr * count)
1923 {
dcbf9037
JB
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927
c921be7d 1928 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1929 {
1930 first_error (_(type_error));
5287ad62
JB
1931 return FAIL;
1932 }
5f4273c7 1933
5287ad62
JB
1934 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1935 modes. */
1936 if (ptr[0] == '-')
1937 {
dcbf9037 1938 struct neon_typed_alias htype;
5287ad62
JB
1939 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1940 if (lane == -1)
1941 lane = NEON_INTERLEAVE_LANES;
1942 else if (lane != NEON_INTERLEAVE_LANES)
1943 {
dcbf9037 1944 first_error (_(type_error));
5287ad62
JB
1945 return FAIL;
1946 }
1947 if (reg_incr == -1)
1948 reg_incr = 1;
1949 else if (reg_incr != 1)
1950 {
dcbf9037 1951 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1952 return FAIL;
1953 }
1954 ptr++;
dcbf9037 1955 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1956 if (hireg == FAIL)
1957 {
dcbf9037
JB
1958 first_error (_(reg_expected_msgs[rtype]));
1959 return FAIL;
1960 }
c921be7d 1961 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1962 {
1963 first_error (_(type_error));
5287ad62
JB
1964 return FAIL;
1965 }
1966 count += hireg + dregs - getreg;
1967 continue;
1968 }
5f4273c7 1969
5287ad62
JB
1970 /* If we're using Q registers, we can't use [] or [n] syntax. */
1971 if (rtype == REG_TYPE_NQ)
1972 {
1973 count += 2;
1974 continue;
1975 }
5f4273c7 1976
dcbf9037 1977 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1978 {
dcbf9037
JB
1979 if (lane == -1)
1980 lane = atype.index;
1981 else if (lane != atype.index)
5287ad62 1982 {
dcbf9037
JB
1983 first_error (_(type_error));
1984 return FAIL;
5287ad62
JB
1985 }
1986 }
1987 else if (lane == -1)
1988 lane = NEON_INTERLEAVE_LANES;
1989 else if (lane != NEON_INTERLEAVE_LANES)
1990 {
dcbf9037 1991 first_error (_(type_error));
5287ad62
JB
1992 return FAIL;
1993 }
1994 count++;
1995 }
1996 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1997
5287ad62
JB
1998 /* No lane set by [x]. We must be interleaving structures. */
1999 if (lane == -1)
2000 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2001
5287ad62
JB
2002 /* Sanity check. */
2003 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2004 || (count > 1 && reg_incr == -1))
2005 {
dcbf9037 2006 first_error (_("error parsing element/structure list"));
5287ad62
JB
2007 return FAIL;
2008 }
2009
2010 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2011 {
dcbf9037 2012 first_error (_("expected }"));
5287ad62
JB
2013 return FAIL;
2014 }
5f4273c7 2015
5287ad62
JB
2016 if (reg_incr == -1)
2017 reg_incr = 1;
2018
dcbf9037
JB
2019 if (eltype)
2020 *eltype = firsttype.eltype;
2021
5287ad62
JB
2022 *pbase = base_reg;
2023 *str = ptr;
5f4273c7 2024
5287ad62
JB
2025 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2026}
2027
c19d1205
ZW
2028/* Parse an explicit relocation suffix on an expression. This is
2029 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2030 arm_reloc_hsh contains no entries, so this function can only
2031 succeed if there is no () after the word. Returns -1 on error,
2032 BFD_RELOC_UNUSED if there wasn't any suffix. */
2033static int
2034parse_reloc (char **str)
b99bd4ef 2035{
c19d1205
ZW
2036 struct reloc_entry *r;
2037 char *p, *q;
b99bd4ef 2038
c19d1205
ZW
2039 if (**str != '(')
2040 return BFD_RELOC_UNUSED;
b99bd4ef 2041
c19d1205
ZW
2042 p = *str + 1;
2043 q = p;
2044
2045 while (*q && *q != ')' && *q != ',')
2046 q++;
2047 if (*q != ')')
2048 return -1;
2049
21d799b5
NC
2050 if ((r = (struct reloc_entry *)
2051 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2052 return -1;
2053
2054 *str = q + 1;
2055 return r->reloc;
b99bd4ef
NC
2056}
2057
c19d1205
ZW
2058/* Directives: register aliases. */
2059
dcbf9037 2060static struct reg_entry *
c19d1205 2061insert_reg_alias (char *str, int number, int type)
b99bd4ef 2062{
d3ce72d0 2063 struct reg_entry *new_reg;
c19d1205 2064 const char *name;
b99bd4ef 2065
d3ce72d0 2066 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2067 {
d3ce72d0 2068 if (new_reg->builtin)
c19d1205 2069 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2070
c19d1205
ZW
2071 /* Only warn about a redefinition if it's not defined as the
2072 same register. */
d3ce72d0 2073 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2074 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2075
d929913e 2076 return NULL;
c19d1205 2077 }
b99bd4ef 2078
c19d1205 2079 name = xstrdup (str);
d3ce72d0 2080 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2081
d3ce72d0
NC
2082 new_reg->name = name;
2083 new_reg->number = number;
2084 new_reg->type = type;
2085 new_reg->builtin = FALSE;
2086 new_reg->neon = NULL;
b99bd4ef 2087
d3ce72d0 2088 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2089 abort ();
5f4273c7 2090
d3ce72d0 2091 return new_reg;
dcbf9037
JB
2092}
2093
2094static void
2095insert_neon_reg_alias (char *str, int number, int type,
2096 struct neon_typed_alias *atype)
2097{
2098 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2099
dcbf9037
JB
2100 if (!reg)
2101 {
2102 first_error (_("attempt to redefine typed alias"));
2103 return;
2104 }
5f4273c7 2105
dcbf9037
JB
2106 if (atype)
2107 {
21d799b5
NC
2108 reg->neon = (struct neon_typed_alias *)
2109 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2110 *reg->neon = *atype;
2111 }
c19d1205 2112}
b99bd4ef 2113
c19d1205 2114/* Look for the .req directive. This is of the form:
b99bd4ef 2115
c19d1205 2116 new_register_name .req existing_register_name
b99bd4ef 2117
c19d1205 2118 If we find one, or if it looks sufficiently like one that we want to
d929913e 2119 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2120
d929913e 2121static bfd_boolean
c19d1205
ZW
2122create_register_alias (char * newname, char *p)
2123{
2124 struct reg_entry *old;
2125 char *oldname, *nbuf;
2126 size_t nlen;
b99bd4ef 2127
c19d1205
ZW
2128 /* The input scrubber ensures that whitespace after the mnemonic is
2129 collapsed to single spaces. */
2130 oldname = p;
2131 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2132 return FALSE;
b99bd4ef 2133
c19d1205
ZW
2134 oldname += 6;
2135 if (*oldname == '\0')
d929913e 2136 return FALSE;
b99bd4ef 2137
21d799b5 2138 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2139 if (!old)
b99bd4ef 2140 {
c19d1205 2141 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2142 return TRUE;
b99bd4ef
NC
2143 }
2144
c19d1205
ZW
2145 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2146 the desired alias name, and p points to its end. If not, then
2147 the desired alias name is in the global original_case_string. */
2148#ifdef TC_CASE_SENSITIVE
2149 nlen = p - newname;
2150#else
2151 newname = original_case_string;
2152 nlen = strlen (newname);
2153#endif
b99bd4ef 2154
21d799b5 2155 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2156 memcpy (nbuf, newname, nlen);
2157 nbuf[nlen] = '\0';
b99bd4ef 2158
c19d1205
ZW
2159 /* Create aliases under the new name as stated; an all-lowercase
2160 version of the new name; and an all-uppercase version of the new
2161 name. */
d929913e
NC
2162 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2163 {
2164 for (p = nbuf; *p; p++)
2165 *p = TOUPPER (*p);
c19d1205 2166
d929913e
NC
2167 if (strncmp (nbuf, newname, nlen))
2168 {
2169 /* If this attempt to create an additional alias fails, do not bother
2170 trying to create the all-lower case alias. We will fail and issue
2171 a second, duplicate error message. This situation arises when the
2172 programmer does something like:
2173 foo .req r0
2174 Foo .req r1
2175 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2176 the artificial FOO alias because it has already been created by the
d929913e
NC
2177 first .req. */
2178 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2179 return TRUE;
2180 }
c19d1205 2181
d929913e
NC
2182 for (p = nbuf; *p; p++)
2183 *p = TOLOWER (*p);
c19d1205 2184
d929913e
NC
2185 if (strncmp (nbuf, newname, nlen))
2186 insert_reg_alias (nbuf, old->number, old->type);
2187 }
c19d1205 2188
d929913e 2189 return TRUE;
b99bd4ef
NC
2190}
2191
dcbf9037
JB
2192/* Create a Neon typed/indexed register alias using directives, e.g.:
2193 X .dn d5.s32[1]
2194 Y .qn 6.s16
2195 Z .dn d7
2196 T .dn Z[0]
2197 These typed registers can be used instead of the types specified after the
2198 Neon mnemonic, so long as all operands given have types. Types can also be
2199 specified directly, e.g.:
5f4273c7 2200 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2201
c921be7d 2202static bfd_boolean
dcbf9037
JB
2203create_neon_reg_alias (char *newname, char *p)
2204{
2205 enum arm_reg_type basetype;
2206 struct reg_entry *basereg;
2207 struct reg_entry mybasereg;
2208 struct neon_type ntype;
2209 struct neon_typed_alias typeinfo;
2210 char *namebuf, *nameend;
2211 int namelen;
5f4273c7 2212
dcbf9037
JB
2213 typeinfo.defined = 0;
2214 typeinfo.eltype.type = NT_invtype;
2215 typeinfo.eltype.size = -1;
2216 typeinfo.index = -1;
5f4273c7 2217
dcbf9037 2218 nameend = p;
5f4273c7 2219
dcbf9037
JB
2220 if (strncmp (p, " .dn ", 5) == 0)
2221 basetype = REG_TYPE_VFD;
2222 else if (strncmp (p, " .qn ", 5) == 0)
2223 basetype = REG_TYPE_NQ;
2224 else
c921be7d 2225 return FALSE;
5f4273c7 2226
dcbf9037 2227 p += 5;
5f4273c7 2228
dcbf9037 2229 if (*p == '\0')
c921be7d 2230 return FALSE;
5f4273c7 2231
dcbf9037
JB
2232 basereg = arm_reg_parse_multi (&p);
2233
2234 if (basereg && basereg->type != basetype)
2235 {
2236 as_bad (_("bad type for register"));
c921be7d 2237 return FALSE;
dcbf9037
JB
2238 }
2239
2240 if (basereg == NULL)
2241 {
2242 expressionS exp;
2243 /* Try parsing as an integer. */
2244 my_get_expression (&exp, &p, GE_NO_PREFIX);
2245 if (exp.X_op != O_constant)
2246 {
2247 as_bad (_("expression must be constant"));
c921be7d 2248 return FALSE;
dcbf9037
JB
2249 }
2250 basereg = &mybasereg;
2251 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2252 : exp.X_add_number;
2253 basereg->neon = 0;
2254 }
2255
2256 if (basereg->neon)
2257 typeinfo = *basereg->neon;
2258
2259 if (parse_neon_type (&ntype, &p) == SUCCESS)
2260 {
2261 /* We got a type. */
2262 if (typeinfo.defined & NTA_HASTYPE)
2263 {
2264 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2265 return FALSE;
dcbf9037 2266 }
5f4273c7 2267
dcbf9037
JB
2268 typeinfo.defined |= NTA_HASTYPE;
2269 if (ntype.elems != 1)
2270 {
2271 as_bad (_("you must specify a single type only"));
c921be7d 2272 return FALSE;
dcbf9037
JB
2273 }
2274 typeinfo.eltype = ntype.el[0];
2275 }
5f4273c7 2276
dcbf9037
JB
2277 if (skip_past_char (&p, '[') == SUCCESS)
2278 {
2279 expressionS exp;
2280 /* We got a scalar index. */
5f4273c7 2281
dcbf9037
JB
2282 if (typeinfo.defined & NTA_HASINDEX)
2283 {
2284 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2285 return FALSE;
dcbf9037 2286 }
5f4273c7 2287
dcbf9037 2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2289
dcbf9037
JB
2290 if (exp.X_op != O_constant)
2291 {
2292 as_bad (_("scalar index must be constant"));
c921be7d 2293 return FALSE;
dcbf9037 2294 }
5f4273c7 2295
dcbf9037
JB
2296 typeinfo.defined |= NTA_HASINDEX;
2297 typeinfo.index = exp.X_add_number;
5f4273c7 2298
dcbf9037
JB
2299 if (skip_past_char (&p, ']') == FAIL)
2300 {
2301 as_bad (_("expecting ]"));
c921be7d 2302 return FALSE;
dcbf9037
JB
2303 }
2304 }
2305
2306 namelen = nameend - newname;
21d799b5 2307 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2308 strncpy (namebuf, newname, namelen);
2309 namebuf[namelen] = '\0';
5f4273c7 2310
dcbf9037
JB
2311 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2312 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2313
dcbf9037
JB
2314 /* Insert name in all uppercase. */
2315 for (p = namebuf; *p; p++)
2316 *p = TOUPPER (*p);
5f4273c7 2317
dcbf9037
JB
2318 if (strncmp (namebuf, newname, namelen))
2319 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2320 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2321
dcbf9037
JB
2322 /* Insert name in all lowercase. */
2323 for (p = namebuf; *p; p++)
2324 *p = TOLOWER (*p);
5f4273c7 2325
dcbf9037
JB
2326 if (strncmp (namebuf, newname, namelen))
2327 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2328 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2329
c921be7d 2330 return TRUE;
dcbf9037
JB
2331}
2332
c19d1205
ZW
2333/* Should never be called, as .req goes between the alias and the
2334 register name, not at the beginning of the line. */
c921be7d 2335
b99bd4ef 2336static void
c19d1205 2337s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2338{
c19d1205
ZW
2339 as_bad (_("invalid syntax for .req directive"));
2340}
b99bd4ef 2341
dcbf9037
JB
2342static void
2343s_dn (int a ATTRIBUTE_UNUSED)
2344{
2345 as_bad (_("invalid syntax for .dn directive"));
2346}
2347
2348static void
2349s_qn (int a ATTRIBUTE_UNUSED)
2350{
2351 as_bad (_("invalid syntax for .qn directive"));
2352}
2353
c19d1205
ZW
2354/* The .unreq directive deletes an alias which was previously defined
2355 by .req. For example:
b99bd4ef 2356
c19d1205
ZW
2357 my_alias .req r11
2358 .unreq my_alias */
b99bd4ef
NC
2359
2360static void
c19d1205 2361s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2362{
c19d1205
ZW
2363 char * name;
2364 char saved_char;
b99bd4ef 2365
c19d1205
ZW
2366 name = input_line_pointer;
2367
2368 while (*input_line_pointer != 0
2369 && *input_line_pointer != ' '
2370 && *input_line_pointer != '\n')
2371 ++input_line_pointer;
2372
2373 saved_char = *input_line_pointer;
2374 *input_line_pointer = 0;
2375
2376 if (!*name)
2377 as_bad (_("invalid syntax for .unreq directive"));
2378 else
2379 {
21d799b5
NC
2380 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2381 name);
c19d1205
ZW
2382
2383 if (!reg)
2384 as_bad (_("unknown register alias '%s'"), name);
2385 else if (reg->builtin)
2386 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2387 name);
2388 else
2389 {
d929913e
NC
2390 char * p;
2391 char * nbuf;
2392
db0bc284 2393 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2394 free ((char *) reg->name);
dcbf9037
JB
2395 if (reg->neon)
2396 free (reg->neon);
c19d1205 2397 free (reg);
d929913e
NC
2398
2399 /* Also locate the all upper case and all lower case versions.
2400 Do not complain if we cannot find one or the other as it
2401 was probably deleted above. */
5f4273c7 2402
d929913e
NC
2403 nbuf = strdup (name);
2404 for (p = nbuf; *p; p++)
2405 *p = TOUPPER (*p);
21d799b5 2406 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2407 if (reg)
2408 {
db0bc284 2409 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2410 free ((char *) reg->name);
2411 if (reg->neon)
2412 free (reg->neon);
2413 free (reg);
2414 }
2415
2416 for (p = nbuf; *p; p++)
2417 *p = TOLOWER (*p);
21d799b5 2418 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2419 if (reg)
2420 {
db0bc284 2421 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2422 free ((char *) reg->name);
2423 if (reg->neon)
2424 free (reg->neon);
2425 free (reg);
2426 }
2427
2428 free (nbuf);
c19d1205
ZW
2429 }
2430 }
b99bd4ef 2431
c19d1205 2432 *input_line_pointer = saved_char;
b99bd4ef
NC
2433 demand_empty_rest_of_line ();
2434}
2435
c19d1205
ZW
2436/* Directives: Instruction set selection. */
2437
2438#ifdef OBJ_ELF
2439/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2440 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2441 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2442 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2443
cd000bff
DJ
2444/* Create a new mapping symbol for the transition to STATE. */
2445
2446static void
2447make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2448{
a737bd4d 2449 symbolS * symbolP;
c19d1205
ZW
2450 const char * symname;
2451 int type;
b99bd4ef 2452
c19d1205 2453 switch (state)
b99bd4ef 2454 {
c19d1205
ZW
2455 case MAP_DATA:
2456 symname = "$d";
2457 type = BSF_NO_FLAGS;
2458 break;
2459 case MAP_ARM:
2460 symname = "$a";
2461 type = BSF_NO_FLAGS;
2462 break;
2463 case MAP_THUMB:
2464 symname = "$t";
2465 type = BSF_NO_FLAGS;
2466 break;
c19d1205
ZW
2467 default:
2468 abort ();
2469 }
2470
cd000bff 2471 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2472 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2473
2474 switch (state)
2475 {
2476 case MAP_ARM:
2477 THUMB_SET_FUNC (symbolP, 0);
2478 ARM_SET_THUMB (symbolP, 0);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_THUMB:
2483 THUMB_SET_FUNC (symbolP, 1);
2484 ARM_SET_THUMB (symbolP, 1);
2485 ARM_SET_INTERWORK (symbolP, support_interwork);
2486 break;
2487
2488 case MAP_DATA:
2489 default:
cd000bff
DJ
2490 break;
2491 }
2492
2493 /* Save the mapping symbols for future reference. Also check that
2494 we do not place two mapping symbols at the same offset within a
2495 frag. We'll handle overlap between frags in
2496 check_mapping_symbols. */
2497 if (value == 0)
2498 {
2499 know (frag->tc_frag_data.first_map == NULL);
2500 frag->tc_frag_data.first_map = symbolP;
2501 }
2502 if (frag->tc_frag_data.last_map != NULL)
c5ed243b 2503 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
cd000bff
DJ
2504 frag->tc_frag_data.last_map = symbolP;
2505}
2506
2507/* We must sometimes convert a region marked as code to data during
2508 code alignment, if an odd number of bytes have to be padded. The
2509 code mapping symbol is pushed to an aligned address. */
2510
2511static void
2512insert_data_mapping_symbol (enum mstate state,
2513 valueT value, fragS *frag, offsetT bytes)
2514{
2515 /* If there was already a mapping symbol, remove it. */
2516 if (frag->tc_frag_data.last_map != NULL
2517 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2518 {
2519 symbolS *symp = frag->tc_frag_data.last_map;
2520
2521 if (value == 0)
2522 {
2523 know (frag->tc_frag_data.first_map == symp);
2524 frag->tc_frag_data.first_map = NULL;
2525 }
2526 frag->tc_frag_data.last_map = NULL;
2527 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2528 }
cd000bff
DJ
2529
2530 make_mapping_symbol (MAP_DATA, value, frag);
2531 make_mapping_symbol (state, value + bytes, frag);
2532}
2533
2534static void mapping_state_2 (enum mstate state, int max_chars);
2535
2536/* Set the mapping state to STATE. Only call this when about to
2537 emit some STATE bytes to the file. */
2538
2539void
2540mapping_state (enum mstate state)
2541{
940b5ce0
DJ
2542 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2543
cd000bff
DJ
2544#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2545
2546 if (mapstate == state)
2547 /* The mapping symbol has already been emitted.
2548 There is nothing else to do. */
2549 return;
2550 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2551 /* This case will be evaluated later in the next else. */
2552 return;
2553 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2554 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2555 {
2556 /* Only add the symbol if the offset is > 0:
2557 if we're at the first frag, check it's size > 0;
2558 if we're not at the first frag, then for sure
2559 the offset is > 0. */
2560 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2561 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2562
2563 if (add_symbol)
2564 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2565 }
2566
2567 mapping_state_2 (state, 0);
2568#undef TRANSITION
2569}
2570
2571/* Same as mapping_state, but MAX_CHARS bytes have already been
2572 allocated. Put the mapping symbol that far back. */
2573
2574static void
2575mapping_state_2 (enum mstate state, int max_chars)
2576{
940b5ce0
DJ
2577 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2578
2579 if (!SEG_NORMAL (now_seg))
2580 return;
2581
cd000bff
DJ
2582 if (mapstate == state)
2583 /* The mapping symbol has already been emitted.
2584 There is nothing else to do. */
2585 return;
2586
cd000bff
DJ
2587 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2588 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2589}
2590#else
d3106081
NS
2591#define mapping_state(x) ((void)0)
2592#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2593#endif
2594
2595/* Find the real, Thumb encoded start of a Thumb function. */
2596
4343666d 2597#ifdef OBJ_COFF
c19d1205
ZW
2598static symbolS *
2599find_real_start (symbolS * symbolP)
2600{
2601 char * real_start;
2602 const char * name = S_GET_NAME (symbolP);
2603 symbolS * new_target;
2604
2605 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2606#define STUB_NAME ".real_start_of"
2607
2608 if (name == NULL)
2609 abort ();
2610
37f6032b
ZW
2611 /* The compiler may generate BL instructions to local labels because
2612 it needs to perform a branch to a far away location. These labels
2613 do not have a corresponding ".real_start_of" label. We check
2614 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2615 the ".real_start_of" convention for nonlocal branches. */
2616 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2617 return symbolP;
2618
37f6032b 2619 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2620 new_target = symbol_find (real_start);
2621
2622 if (new_target == NULL)
2623 {
bd3ba5d1 2624 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2625 new_target = symbolP;
2626 }
2627
c19d1205
ZW
2628 return new_target;
2629}
4343666d 2630#endif
c19d1205
ZW
2631
2632static void
2633opcode_select (int width)
2634{
2635 switch (width)
2636 {
2637 case 16:
2638 if (! thumb_mode)
2639 {
e74cfd16 2640 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2641 as_bad (_("selected processor does not support THUMB opcodes"));
2642
2643 thumb_mode = 1;
2644 /* No need to force the alignment, since we will have been
2645 coming from ARM mode, which is word-aligned. */
2646 record_alignment (now_seg, 1);
2647 }
c19d1205
ZW
2648 break;
2649
2650 case 32:
2651 if (thumb_mode)
2652 {
e74cfd16 2653 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2654 as_bad (_("selected processor does not support ARM opcodes"));
2655
2656 thumb_mode = 0;
2657
2658 if (!need_pass_2)
2659 frag_align (2, 0, 0);
2660
2661 record_alignment (now_seg, 1);
2662 }
c19d1205
ZW
2663 break;
2664
2665 default:
2666 as_bad (_("invalid instruction size selected (%d)"), width);
2667 }
2668}
2669
2670static void
2671s_arm (int ignore ATTRIBUTE_UNUSED)
2672{
2673 opcode_select (32);
2674 demand_empty_rest_of_line ();
2675}
2676
2677static void
2678s_thumb (int ignore ATTRIBUTE_UNUSED)
2679{
2680 opcode_select (16);
2681 demand_empty_rest_of_line ();
2682}
2683
2684static void
2685s_code (int unused ATTRIBUTE_UNUSED)
2686{
2687 int temp;
2688
2689 temp = get_absolute_expression ();
2690 switch (temp)
2691 {
2692 case 16:
2693 case 32:
2694 opcode_select (temp);
2695 break;
2696
2697 default:
2698 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2699 }
2700}
2701
2702static void
2703s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2704{
2705 /* If we are not already in thumb mode go into it, EVEN if
2706 the target processor does not support thumb instructions.
2707 This is used by gcc/config/arm/lib1funcs.asm for example
2708 to compile interworking support functions even if the
2709 target processor should not support interworking. */
2710 if (! thumb_mode)
2711 {
2712 thumb_mode = 2;
2713 record_alignment (now_seg, 1);
2714 }
2715
2716 demand_empty_rest_of_line ();
2717}
2718
2719static void
2720s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2721{
2722 s_thumb (0);
2723
2724 /* The following label is the name/address of the start of a Thumb function.
2725 We need to know this for the interworking support. */
2726 label_is_thumb_function_name = TRUE;
2727}
2728
2729/* Perform a .set directive, but also mark the alias as
2730 being a thumb function. */
2731
2732static void
2733s_thumb_set (int equiv)
2734{
2735 /* XXX the following is a duplicate of the code for s_set() in read.c
2736 We cannot just call that code as we need to get at the symbol that
2737 is created. */
2738 char * name;
2739 char delim;
2740 char * end_name;
2741 symbolS * symbolP;
2742
2743 /* Especial apologies for the random logic:
2744 This just grew, and could be parsed much more simply!
2745 Dean - in haste. */
2746 name = input_line_pointer;
2747 delim = get_symbol_end ();
2748 end_name = input_line_pointer;
2749 *end_name = delim;
2750
2751 if (*input_line_pointer != ',')
2752 {
2753 *end_name = 0;
2754 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2755 *end_name = delim;
2756 ignore_rest_of_line ();
2757 return;
2758 }
2759
2760 input_line_pointer++;
2761 *end_name = 0;
2762
2763 if (name[0] == '.' && name[1] == '\0')
2764 {
2765 /* XXX - this should not happen to .thumb_set. */
2766 abort ();
2767 }
2768
2769 if ((symbolP = symbol_find (name)) == NULL
2770 && (symbolP = md_undefined_symbol (name)) == NULL)
2771 {
2772#ifndef NO_LISTING
2773 /* When doing symbol listings, play games with dummy fragments living
2774 outside the normal fragment chain to record the file and line info
c19d1205 2775 for this symbol. */
b99bd4ef
NC
2776 if (listing & LISTING_SYMBOLS)
2777 {
2778 extern struct list_info_struct * listing_tail;
21d799b5 2779 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2780
2781 memset (dummy_frag, 0, sizeof (fragS));
2782 dummy_frag->fr_type = rs_fill;
2783 dummy_frag->line = listing_tail;
2784 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2785 dummy_frag->fr_symbol = symbolP;
2786 }
2787 else
2788#endif
2789 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2790
2791#ifdef OBJ_COFF
2792 /* "set" symbols are local unless otherwise specified. */
2793 SF_SET_LOCAL (symbolP);
2794#endif /* OBJ_COFF */
2795 } /* Make a new symbol. */
2796
2797 symbol_table_insert (symbolP);
2798
2799 * end_name = delim;
2800
2801 if (equiv
2802 && S_IS_DEFINED (symbolP)
2803 && S_GET_SEGMENT (symbolP) != reg_section)
2804 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2805
2806 pseudo_set (symbolP);
2807
2808 demand_empty_rest_of_line ();
2809
c19d1205 2810 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2811
2812 THUMB_SET_FUNC (symbolP, 1);
2813 ARM_SET_THUMB (symbolP, 1);
2814#if defined OBJ_ELF || defined OBJ_COFF
2815 ARM_SET_INTERWORK (symbolP, support_interwork);
2816#endif
2817}
2818
c19d1205 2819/* Directives: Mode selection. */
b99bd4ef 2820
c19d1205
ZW
2821/* .syntax [unified|divided] - choose the new unified syntax
2822 (same for Arm and Thumb encoding, modulo slight differences in what
2823 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2824static void
c19d1205 2825s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2826{
c19d1205
ZW
2827 char *name, delim;
2828
2829 name = input_line_pointer;
2830 delim = get_symbol_end ();
2831
2832 if (!strcasecmp (name, "unified"))
2833 unified_syntax = TRUE;
2834 else if (!strcasecmp (name, "divided"))
2835 unified_syntax = FALSE;
2836 else
2837 {
2838 as_bad (_("unrecognized syntax mode \"%s\""), name);
2839 return;
2840 }
2841 *input_line_pointer = delim;
b99bd4ef
NC
2842 demand_empty_rest_of_line ();
2843}
2844
c19d1205
ZW
2845/* Directives: sectioning and alignment. */
2846
2847/* Same as s_align_ptwo but align 0 => align 2. */
2848
b99bd4ef 2849static void
c19d1205 2850s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2851{
a737bd4d 2852 int temp;
dce323d1 2853 bfd_boolean fill_p;
c19d1205
ZW
2854 long temp_fill;
2855 long max_alignment = 15;
b99bd4ef
NC
2856
2857 temp = get_absolute_expression ();
c19d1205
ZW
2858 if (temp > max_alignment)
2859 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2860 else if (temp < 0)
b99bd4ef 2861 {
c19d1205
ZW
2862 as_bad (_("alignment negative. 0 assumed."));
2863 temp = 0;
2864 }
b99bd4ef 2865
c19d1205
ZW
2866 if (*input_line_pointer == ',')
2867 {
2868 input_line_pointer++;
2869 temp_fill = get_absolute_expression ();
dce323d1 2870 fill_p = TRUE;
b99bd4ef 2871 }
c19d1205 2872 else
dce323d1
PB
2873 {
2874 fill_p = FALSE;
2875 temp_fill = 0;
2876 }
b99bd4ef 2877
c19d1205
ZW
2878 if (!temp)
2879 temp = 2;
b99bd4ef 2880
c19d1205
ZW
2881 /* Only make a frag if we HAVE to. */
2882 if (temp && !need_pass_2)
dce323d1
PB
2883 {
2884 if (!fill_p && subseg_text_p (now_seg))
2885 frag_align_code (temp, 0);
2886 else
2887 frag_align (temp, (int) temp_fill, 0);
2888 }
c19d1205
ZW
2889 demand_empty_rest_of_line ();
2890
2891 record_alignment (now_seg, temp);
b99bd4ef
NC
2892}
2893
c19d1205
ZW
2894static void
2895s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2896{
c19d1205
ZW
2897 /* We don't support putting frags in the BSS segment, we fake it by
2898 marking in_bss, then looking at s_skip for clues. */
2899 subseg_set (bss_section, 0);
2900 demand_empty_rest_of_line ();
cd000bff
DJ
2901
2902#ifdef md_elf_section_change_hook
2903 md_elf_section_change_hook ();
2904#endif
c19d1205 2905}
b99bd4ef 2906
c19d1205
ZW
2907static void
2908s_even (int ignore ATTRIBUTE_UNUSED)
2909{
2910 /* Never make frag if expect extra pass. */
2911 if (!need_pass_2)
2912 frag_align (1, 0, 0);
b99bd4ef 2913
c19d1205 2914 record_alignment (now_seg, 1);
b99bd4ef 2915
c19d1205 2916 demand_empty_rest_of_line ();
b99bd4ef
NC
2917}
2918
c19d1205 2919/* Directives: Literal pools. */
a737bd4d 2920
c19d1205
ZW
2921static literal_pool *
2922find_literal_pool (void)
a737bd4d 2923{
c19d1205 2924 literal_pool * pool;
a737bd4d 2925
c19d1205 2926 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2927 {
c19d1205
ZW
2928 if (pool->section == now_seg
2929 && pool->sub_section == now_subseg)
2930 break;
a737bd4d
NC
2931 }
2932
c19d1205 2933 return pool;
a737bd4d
NC
2934}
2935
c19d1205
ZW
2936static literal_pool *
2937find_or_make_literal_pool (void)
a737bd4d 2938{
c19d1205
ZW
2939 /* Next literal pool ID number. */
2940 static unsigned int latest_pool_num = 1;
2941 literal_pool * pool;
a737bd4d 2942
c19d1205 2943 pool = find_literal_pool ();
a737bd4d 2944
c19d1205 2945 if (pool == NULL)
a737bd4d 2946 {
c19d1205 2947 /* Create a new pool. */
21d799b5 2948 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2949 if (! pool)
2950 return NULL;
a737bd4d 2951
c19d1205
ZW
2952 pool->next_free_entry = 0;
2953 pool->section = now_seg;
2954 pool->sub_section = now_subseg;
2955 pool->next = list_of_pools;
2956 pool->symbol = NULL;
2957
2958 /* Add it to the list. */
2959 list_of_pools = pool;
a737bd4d 2960 }
a737bd4d 2961
c19d1205
ZW
2962 /* New pools, and emptied pools, will have a NULL symbol. */
2963 if (pool->symbol == NULL)
a737bd4d 2964 {
c19d1205
ZW
2965 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2966 (valueT) 0, &zero_address_frag);
2967 pool->id = latest_pool_num ++;
a737bd4d
NC
2968 }
2969
c19d1205
ZW
2970 /* Done. */
2971 return pool;
a737bd4d
NC
2972}
2973
c19d1205 2974/* Add the literal in the global 'inst'
5f4273c7 2975 structure to the relevant literal pool. */
b99bd4ef
NC
2976
2977static int
c19d1205 2978add_to_lit_pool (void)
b99bd4ef 2979{
c19d1205
ZW
2980 literal_pool * pool;
2981 unsigned int entry;
b99bd4ef 2982
c19d1205
ZW
2983 pool = find_or_make_literal_pool ();
2984
2985 /* Check if this literal value is already in the pool. */
2986 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2987 {
c19d1205
ZW
2988 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2989 && (inst.reloc.exp.X_op == O_constant)
2990 && (pool->literals[entry].X_add_number
2991 == inst.reloc.exp.X_add_number)
2992 && (pool->literals[entry].X_unsigned
2993 == inst.reloc.exp.X_unsigned))
2994 break;
2995
2996 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2997 && (inst.reloc.exp.X_op == O_symbol)
2998 && (pool->literals[entry].X_add_number
2999 == inst.reloc.exp.X_add_number)
3000 && (pool->literals[entry].X_add_symbol
3001 == inst.reloc.exp.X_add_symbol)
3002 && (pool->literals[entry].X_op_symbol
3003 == inst.reloc.exp.X_op_symbol))
3004 break;
b99bd4ef
NC
3005 }
3006
c19d1205
ZW
3007 /* Do we need to create a new entry? */
3008 if (entry == pool->next_free_entry)
3009 {
3010 if (entry >= MAX_LITERAL_POOL_SIZE)
3011 {
3012 inst.error = _("literal pool overflow");
3013 return FAIL;
3014 }
3015
3016 pool->literals[entry] = inst.reloc.exp;
3017 pool->next_free_entry += 1;
3018 }
b99bd4ef 3019
c19d1205
ZW
3020 inst.reloc.exp.X_op = O_symbol;
3021 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3022 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3023
c19d1205 3024 return SUCCESS;
b99bd4ef
NC
3025}
3026
c19d1205
ZW
3027/* Can't use symbol_new here, so have to create a symbol and then at
3028 a later date assign it a value. Thats what these functions do. */
e16bb312 3029
c19d1205
ZW
3030static void
3031symbol_locate (symbolS * symbolP,
3032 const char * name, /* It is copied, the caller can modify. */
3033 segT segment, /* Segment identifier (SEG_<something>). */
3034 valueT valu, /* Symbol value. */
3035 fragS * frag) /* Associated fragment. */
3036{
3037 unsigned int name_length;
3038 char * preserved_copy_of_name;
e16bb312 3039
c19d1205
ZW
3040 name_length = strlen (name) + 1; /* +1 for \0. */
3041 obstack_grow (&notes, name, name_length);
21d799b5 3042 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3043
c19d1205
ZW
3044#ifdef tc_canonicalize_symbol_name
3045 preserved_copy_of_name =
3046 tc_canonicalize_symbol_name (preserved_copy_of_name);
3047#endif
b99bd4ef 3048
c19d1205 3049 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3050
c19d1205
ZW
3051 S_SET_SEGMENT (symbolP, segment);
3052 S_SET_VALUE (symbolP, valu);
3053 symbol_clear_list_pointers (symbolP);
b99bd4ef 3054
c19d1205 3055 symbol_set_frag (symbolP, frag);
b99bd4ef 3056
c19d1205
ZW
3057 /* Link to end of symbol chain. */
3058 {
3059 extern int symbol_table_frozen;
b99bd4ef 3060
c19d1205
ZW
3061 if (symbol_table_frozen)
3062 abort ();
3063 }
b99bd4ef 3064
c19d1205 3065 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3066
c19d1205 3067 obj_symbol_new_hook (symbolP);
b99bd4ef 3068
c19d1205
ZW
3069#ifdef tc_symbol_new_hook
3070 tc_symbol_new_hook (symbolP);
3071#endif
3072
3073#ifdef DEBUG_SYMS
3074 verify_symbol_chain (symbol_rootP, symbol_lastP);
3075#endif /* DEBUG_SYMS */
b99bd4ef
NC
3076}
3077
b99bd4ef 3078
c19d1205
ZW
3079static void
3080s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3081{
c19d1205
ZW
3082 unsigned int entry;
3083 literal_pool * pool;
3084 char sym_name[20];
b99bd4ef 3085
c19d1205
ZW
3086 pool = find_literal_pool ();
3087 if (pool == NULL
3088 || pool->symbol == NULL
3089 || pool->next_free_entry == 0)
3090 return;
b99bd4ef 3091
c19d1205 3092 mapping_state (MAP_DATA);
b99bd4ef 3093
c19d1205
ZW
3094 /* Align pool as you have word accesses.
3095 Only make a frag if we have to. */
3096 if (!need_pass_2)
3097 frag_align (2, 0, 0);
b99bd4ef 3098
c19d1205 3099 record_alignment (now_seg, 2);
b99bd4ef 3100
c19d1205 3101 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3102
c19d1205
ZW
3103 symbol_locate (pool->symbol, sym_name, now_seg,
3104 (valueT) frag_now_fix (), frag_now);
3105 symbol_table_insert (pool->symbol);
b99bd4ef 3106
c19d1205 3107 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3108
c19d1205
ZW
3109#if defined OBJ_COFF || defined OBJ_ELF
3110 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3111#endif
6c43fab6 3112
c19d1205
ZW
3113 for (entry = 0; entry < pool->next_free_entry; entry ++)
3114 /* First output the expression in the instruction to the pool. */
3115 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3116
c19d1205
ZW
3117 /* Mark the pool as empty. */
3118 pool->next_free_entry = 0;
3119 pool->symbol = NULL;
b99bd4ef
NC
3120}
3121
c19d1205
ZW
3122#ifdef OBJ_ELF
3123/* Forward declarations for functions below, in the MD interface
3124 section. */
3125static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3126static valueT create_unwind_entry (int);
3127static void start_unwind_section (const segT, int);
3128static void add_unwind_opcode (valueT, int);
3129static void flush_pending_unwind (void);
b99bd4ef 3130
c19d1205 3131/* Directives: Data. */
b99bd4ef 3132
c19d1205
ZW
3133static void
3134s_arm_elf_cons (int nbytes)
3135{
3136 expressionS exp;
b99bd4ef 3137
c19d1205
ZW
3138#ifdef md_flush_pending_output
3139 md_flush_pending_output ();
3140#endif
b99bd4ef 3141
c19d1205 3142 if (is_it_end_of_statement ())
b99bd4ef 3143 {
c19d1205
ZW
3144 demand_empty_rest_of_line ();
3145 return;
b99bd4ef
NC
3146 }
3147
c19d1205
ZW
3148#ifdef md_cons_align
3149 md_cons_align (nbytes);
3150#endif
b99bd4ef 3151
c19d1205
ZW
3152 mapping_state (MAP_DATA);
3153 do
b99bd4ef 3154 {
c19d1205
ZW
3155 int reloc;
3156 char *base = input_line_pointer;
b99bd4ef 3157
c19d1205 3158 expression (& exp);
b99bd4ef 3159
c19d1205
ZW
3160 if (exp.X_op != O_symbol)
3161 emit_expr (&exp, (unsigned int) nbytes);
3162 else
3163 {
3164 char *before_reloc = input_line_pointer;
3165 reloc = parse_reloc (&input_line_pointer);
3166 if (reloc == -1)
3167 {
3168 as_bad (_("unrecognized relocation suffix"));
3169 ignore_rest_of_line ();
3170 return;
3171 }
3172 else if (reloc == BFD_RELOC_UNUSED)
3173 emit_expr (&exp, (unsigned int) nbytes);
3174 else
3175 {
21d799b5
NC
3176 reloc_howto_type *howto = (reloc_howto_type *)
3177 bfd_reloc_type_lookup (stdoutput,
3178 (bfd_reloc_code_real_type) reloc);
c19d1205 3179 int size = bfd_get_reloc_size (howto);
b99bd4ef 3180
2fc8bdac
ZW
3181 if (reloc == BFD_RELOC_ARM_PLT32)
3182 {
3183 as_bad (_("(plt) is only valid on branch targets"));
3184 reloc = BFD_RELOC_UNUSED;
3185 size = 0;
3186 }
3187
c19d1205 3188 if (size > nbytes)
2fc8bdac 3189 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3190 howto->name, nbytes);
3191 else
3192 {
3193 /* We've parsed an expression stopping at O_symbol.
3194 But there may be more expression left now that we
3195 have parsed the relocation marker. Parse it again.
3196 XXX Surely there is a cleaner way to do this. */
3197 char *p = input_line_pointer;
3198 int offset;
21d799b5 3199 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3200 memcpy (save_buf, base, input_line_pointer - base);
3201 memmove (base + (input_line_pointer - before_reloc),
3202 base, before_reloc - base);
3203
3204 input_line_pointer = base + (input_line_pointer-before_reloc);
3205 expression (&exp);
3206 memcpy (base, save_buf, p - base);
3207
3208 offset = nbytes - size;
3209 p = frag_more ((int) nbytes);
3210 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3211 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3212 }
3213 }
3214 }
b99bd4ef 3215 }
c19d1205 3216 while (*input_line_pointer++ == ',');
b99bd4ef 3217
c19d1205
ZW
3218 /* Put terminator back into stream. */
3219 input_line_pointer --;
3220 demand_empty_rest_of_line ();
b99bd4ef
NC
3221}
3222
c921be7d
NC
3223/* Emit an expression containing a 32-bit thumb instruction.
3224 Implementation based on put_thumb32_insn. */
3225
3226static void
3227emit_thumb32_expr (expressionS * exp)
3228{
3229 expressionS exp_high = *exp;
3230
3231 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3232 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3233 exp->X_add_number &= 0xffff;
3234 emit_expr (exp, (unsigned int) THUMB_SIZE);
3235}
3236
3237/* Guess the instruction size based on the opcode. */
3238
3239static int
3240thumb_insn_size (int opcode)
3241{
3242 if ((unsigned int) opcode < 0xe800u)
3243 return 2;
3244 else if ((unsigned int) opcode >= 0xe8000000u)
3245 return 4;
3246 else
3247 return 0;
3248}
3249
3250static bfd_boolean
3251emit_insn (expressionS *exp, int nbytes)
3252{
3253 int size = 0;
3254
3255 if (exp->X_op == O_constant)
3256 {
3257 size = nbytes;
3258
3259 if (size == 0)
3260 size = thumb_insn_size (exp->X_add_number);
3261
3262 if (size != 0)
3263 {
3264 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3265 {
3266 as_bad (_(".inst.n operand too big. "\
3267 "Use .inst.w instead"));
3268 size = 0;
3269 }
3270 else
3271 {
3272 if (now_it.state == AUTOMATIC_IT_BLOCK)
3273 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3274 else
3275 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3276
3277 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3278 emit_thumb32_expr (exp);
3279 else
3280 emit_expr (exp, (unsigned int) size);
3281
3282 it_fsm_post_encode ();
3283 }
3284 }
3285 else
3286 as_bad (_("cannot determine Thumb instruction size. " \
3287 "Use .inst.n/.inst.w instead"));
3288 }
3289 else
3290 as_bad (_("constant expression required"));
3291
3292 return (size != 0);
3293}
3294
3295/* Like s_arm_elf_cons but do not use md_cons_align and
3296 set the mapping state to MAP_ARM/MAP_THUMB. */
3297
3298static void
3299s_arm_elf_inst (int nbytes)
3300{
3301 if (is_it_end_of_statement ())
3302 {
3303 demand_empty_rest_of_line ();
3304 return;
3305 }
3306
3307 /* Calling mapping_state () here will not change ARM/THUMB,
3308 but will ensure not to be in DATA state. */
3309
3310 if (thumb_mode)
3311 mapping_state (MAP_THUMB);
3312 else
3313 {
3314 if (nbytes != 0)
3315 {
3316 as_bad (_("width suffixes are invalid in ARM mode"));
3317 ignore_rest_of_line ();
3318 return;
3319 }
3320
3321 nbytes = 4;
3322
3323 mapping_state (MAP_ARM);
3324 }
3325
3326 do
3327 {
3328 expressionS exp;
3329
3330 expression (& exp);
3331
3332 if (! emit_insn (& exp, nbytes))
3333 {
3334 ignore_rest_of_line ();
3335 return;
3336 }
3337 }
3338 while (*input_line_pointer++ == ',');
3339
3340 /* Put terminator back into stream. */
3341 input_line_pointer --;
3342 demand_empty_rest_of_line ();
3343}
b99bd4ef 3344
c19d1205 3345/* Parse a .rel31 directive. */
b99bd4ef 3346
c19d1205
ZW
3347static void
3348s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3349{
3350 expressionS exp;
3351 char *p;
3352 valueT highbit;
b99bd4ef 3353
c19d1205
ZW
3354 highbit = 0;
3355 if (*input_line_pointer == '1')
3356 highbit = 0x80000000;
3357 else if (*input_line_pointer != '0')
3358 as_bad (_("expected 0 or 1"));
b99bd4ef 3359
c19d1205
ZW
3360 input_line_pointer++;
3361 if (*input_line_pointer != ',')
3362 as_bad (_("missing comma"));
3363 input_line_pointer++;
b99bd4ef 3364
c19d1205
ZW
3365#ifdef md_flush_pending_output
3366 md_flush_pending_output ();
3367#endif
b99bd4ef 3368
c19d1205
ZW
3369#ifdef md_cons_align
3370 md_cons_align (4);
3371#endif
b99bd4ef 3372
c19d1205 3373 mapping_state (MAP_DATA);
b99bd4ef 3374
c19d1205 3375 expression (&exp);
b99bd4ef 3376
c19d1205
ZW
3377 p = frag_more (4);
3378 md_number_to_chars (p, highbit, 4);
3379 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3380 BFD_RELOC_ARM_PREL31);
b99bd4ef 3381
c19d1205 3382 demand_empty_rest_of_line ();
b99bd4ef
NC
3383}
3384
c19d1205 3385/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3386
c19d1205 3387/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3388
c19d1205
ZW
3389static void
3390s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3391{
3392 demand_empty_rest_of_line ();
921e5f0a
PB
3393 if (unwind.proc_start)
3394 {
c921be7d 3395 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3396 return;
3397 }
3398
c19d1205
ZW
3399 /* Mark the start of the function. */
3400 unwind.proc_start = expr_build_dot ();
b99bd4ef 3401
c19d1205
ZW
3402 /* Reset the rest of the unwind info. */
3403 unwind.opcode_count = 0;
3404 unwind.table_entry = NULL;
3405 unwind.personality_routine = NULL;
3406 unwind.personality_index = -1;
3407 unwind.frame_size = 0;
3408 unwind.fp_offset = 0;
fdfde340 3409 unwind.fp_reg = REG_SP;
c19d1205
ZW
3410 unwind.fp_used = 0;
3411 unwind.sp_restored = 0;
3412}
b99bd4ef 3413
b99bd4ef 3414
c19d1205
ZW
3415/* Parse a handlerdata directive. Creates the exception handling table entry
3416 for the function. */
b99bd4ef 3417
c19d1205
ZW
3418static void
3419s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3420{
3421 demand_empty_rest_of_line ();
921e5f0a 3422 if (!unwind.proc_start)
c921be7d 3423 as_bad (MISSING_FNSTART);
921e5f0a 3424
c19d1205 3425 if (unwind.table_entry)
6decc662 3426 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3427
c19d1205
ZW
3428 create_unwind_entry (1);
3429}
a737bd4d 3430
c19d1205 3431/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3432
c19d1205
ZW
3433static void
3434s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3435{
3436 long where;
3437 char *ptr;
3438 valueT val;
940b5ce0 3439 unsigned int marked_pr_dependency;
f02232aa 3440
c19d1205 3441 demand_empty_rest_of_line ();
f02232aa 3442
921e5f0a
PB
3443 if (!unwind.proc_start)
3444 {
c921be7d 3445 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3446 return;
3447 }
3448
c19d1205
ZW
3449 /* Add eh table entry. */
3450 if (unwind.table_entry == NULL)
3451 val = create_unwind_entry (0);
3452 else
3453 val = 0;
f02232aa 3454
c19d1205
ZW
3455 /* Add index table entry. This is two words. */
3456 start_unwind_section (unwind.saved_seg, 1);
3457 frag_align (2, 0, 0);
3458 record_alignment (now_seg, 2);
b99bd4ef 3459
c19d1205
ZW
3460 ptr = frag_more (8);
3461 where = frag_now_fix () - 8;
f02232aa 3462
c19d1205
ZW
3463 /* Self relative offset of the function start. */
3464 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3465 BFD_RELOC_ARM_PREL31);
f02232aa 3466
c19d1205
ZW
3467 /* Indicate dependency on EHABI-defined personality routines to the
3468 linker, if it hasn't been done already. */
940b5ce0
DJ
3469 marked_pr_dependency
3470 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3471 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3472 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3473 {
5f4273c7
NC
3474 static const char *const name[] =
3475 {
3476 "__aeabi_unwind_cpp_pr0",
3477 "__aeabi_unwind_cpp_pr1",
3478 "__aeabi_unwind_cpp_pr2"
3479 };
c19d1205
ZW
3480 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3481 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3482 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3483 |= 1 << unwind.personality_index;
c19d1205 3484 }
f02232aa 3485
c19d1205
ZW
3486 if (val)
3487 /* Inline exception table entry. */
3488 md_number_to_chars (ptr + 4, val, 4);
3489 else
3490 /* Self relative offset of the table entry. */
3491 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3492 BFD_RELOC_ARM_PREL31);
f02232aa 3493
c19d1205
ZW
3494 /* Restore the original section. */
3495 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3496
3497 unwind.proc_start = NULL;
c19d1205 3498}
f02232aa 3499
f02232aa 3500
c19d1205 3501/* Parse an unwind_cantunwind directive. */
b99bd4ef 3502
c19d1205
ZW
3503static void
3504s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3505{
3506 demand_empty_rest_of_line ();
921e5f0a 3507 if (!unwind.proc_start)
c921be7d 3508 as_bad (MISSING_FNSTART);
921e5f0a 3509
c19d1205
ZW
3510 if (unwind.personality_routine || unwind.personality_index != -1)
3511 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3512
c19d1205
ZW
3513 unwind.personality_index = -2;
3514}
b99bd4ef 3515
b99bd4ef 3516
c19d1205 3517/* Parse a personalityindex directive. */
b99bd4ef 3518
c19d1205
ZW
3519static void
3520s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3521{
3522 expressionS exp;
b99bd4ef 3523
921e5f0a 3524 if (!unwind.proc_start)
c921be7d 3525 as_bad (MISSING_FNSTART);
921e5f0a 3526
c19d1205
ZW
3527 if (unwind.personality_routine || unwind.personality_index != -1)
3528 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3529
c19d1205 3530 expression (&exp);
b99bd4ef 3531
c19d1205
ZW
3532 if (exp.X_op != O_constant
3533 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3534 {
c19d1205
ZW
3535 as_bad (_("bad personality routine number"));
3536 ignore_rest_of_line ();
3537 return;
b99bd4ef
NC
3538 }
3539
c19d1205 3540 unwind.personality_index = exp.X_add_number;
b99bd4ef 3541
c19d1205
ZW
3542 demand_empty_rest_of_line ();
3543}
e16bb312 3544
e16bb312 3545
c19d1205 3546/* Parse a personality directive. */
e16bb312 3547
c19d1205
ZW
3548static void
3549s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3550{
3551 char *name, *p, c;
a737bd4d 3552
921e5f0a 3553 if (!unwind.proc_start)
c921be7d 3554 as_bad (MISSING_FNSTART);
921e5f0a 3555
c19d1205
ZW
3556 if (unwind.personality_routine || unwind.personality_index != -1)
3557 as_bad (_("duplicate .personality directive"));
a737bd4d 3558
c19d1205
ZW
3559 name = input_line_pointer;
3560 c = get_symbol_end ();
3561 p = input_line_pointer;
3562 unwind.personality_routine = symbol_find_or_make (name);
3563 *p = c;
3564 demand_empty_rest_of_line ();
3565}
e16bb312 3566
e16bb312 3567
c19d1205 3568/* Parse a directive saving core registers. */
e16bb312 3569
c19d1205
ZW
3570static void
3571s_arm_unwind_save_core (void)
e16bb312 3572{
c19d1205
ZW
3573 valueT op;
3574 long range;
3575 int n;
e16bb312 3576
c19d1205
ZW
3577 range = parse_reg_list (&input_line_pointer);
3578 if (range == FAIL)
e16bb312 3579 {
c19d1205
ZW
3580 as_bad (_("expected register list"));
3581 ignore_rest_of_line ();
3582 return;
3583 }
e16bb312 3584
c19d1205 3585 demand_empty_rest_of_line ();
e16bb312 3586
c19d1205
ZW
3587 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3588 into .unwind_save {..., sp...}. We aren't bothered about the value of
3589 ip because it is clobbered by calls. */
3590 if (unwind.sp_restored && unwind.fp_reg == 12
3591 && (range & 0x3000) == 0x1000)
3592 {
3593 unwind.opcode_count--;
3594 unwind.sp_restored = 0;
3595 range = (range | 0x2000) & ~0x1000;
3596 unwind.pending_offset = 0;
3597 }
e16bb312 3598
01ae4198
DJ
3599 /* Pop r4-r15. */
3600 if (range & 0xfff0)
c19d1205 3601 {
01ae4198
DJ
3602 /* See if we can use the short opcodes. These pop a block of up to 8
3603 registers starting with r4, plus maybe r14. */
3604 for (n = 0; n < 8; n++)
3605 {
3606 /* Break at the first non-saved register. */
3607 if ((range & (1 << (n + 4))) == 0)
3608 break;
3609 }
3610 /* See if there are any other bits set. */
3611 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3612 {
3613 /* Use the long form. */
3614 op = 0x8000 | ((range >> 4) & 0xfff);
3615 add_unwind_opcode (op, 2);
3616 }
0dd132b6 3617 else
01ae4198
DJ
3618 {
3619 /* Use the short form. */
3620 if (range & 0x4000)
3621 op = 0xa8; /* Pop r14. */
3622 else
3623 op = 0xa0; /* Do not pop r14. */
3624 op |= (n - 1);
3625 add_unwind_opcode (op, 1);
3626 }
c19d1205 3627 }
0dd132b6 3628
c19d1205
ZW
3629 /* Pop r0-r3. */
3630 if (range & 0xf)
3631 {
3632 op = 0xb100 | (range & 0xf);
3633 add_unwind_opcode (op, 2);
0dd132b6
NC
3634 }
3635
c19d1205
ZW
3636 /* Record the number of bytes pushed. */
3637 for (n = 0; n < 16; n++)
3638 {
3639 if (range & (1 << n))
3640 unwind.frame_size += 4;
3641 }
0dd132b6
NC
3642}
3643
c19d1205
ZW
3644
3645/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3646
3647static void
c19d1205 3648s_arm_unwind_save_fpa (int reg)
b99bd4ef 3649{
c19d1205
ZW
3650 expressionS exp;
3651 int num_regs;
3652 valueT op;
b99bd4ef 3653
c19d1205
ZW
3654 /* Get Number of registers to transfer. */
3655 if (skip_past_comma (&input_line_pointer) != FAIL)
3656 expression (&exp);
3657 else
3658 exp.X_op = O_illegal;
b99bd4ef 3659
c19d1205 3660 if (exp.X_op != O_constant)
b99bd4ef 3661 {
c19d1205
ZW
3662 as_bad (_("expected , <constant>"));
3663 ignore_rest_of_line ();
b99bd4ef
NC
3664 return;
3665 }
3666
c19d1205
ZW
3667 num_regs = exp.X_add_number;
3668
3669 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3670 {
c19d1205
ZW
3671 as_bad (_("number of registers must be in the range [1:4]"));
3672 ignore_rest_of_line ();
b99bd4ef
NC
3673 return;
3674 }
3675
c19d1205 3676 demand_empty_rest_of_line ();
b99bd4ef 3677
c19d1205
ZW
3678 if (reg == 4)
3679 {
3680 /* Short form. */
3681 op = 0xb4 | (num_regs - 1);
3682 add_unwind_opcode (op, 1);
3683 }
b99bd4ef
NC
3684 else
3685 {
c19d1205
ZW
3686 /* Long form. */
3687 op = 0xc800 | (reg << 4) | (num_regs - 1);
3688 add_unwind_opcode (op, 2);
b99bd4ef 3689 }
c19d1205 3690 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3691}
3692
c19d1205 3693
fa073d69
MS
3694/* Parse a directive saving VFP registers for ARMv6 and above. */
3695
3696static void
3697s_arm_unwind_save_vfp_armv6 (void)
3698{
3699 int count;
3700 unsigned int start;
3701 valueT op;
3702 int num_vfpv3_regs = 0;
3703 int num_regs_below_16;
3704
3705 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3706 if (count == FAIL)
3707 {
3708 as_bad (_("expected register list"));
3709 ignore_rest_of_line ();
3710 return;
3711 }
3712
3713 demand_empty_rest_of_line ();
3714
3715 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3716 than FSTMX/FLDMX-style ones). */
3717
3718 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3719 if (start >= 16)
3720 num_vfpv3_regs = count;
3721 else if (start + count > 16)
3722 num_vfpv3_regs = start + count - 16;
3723
3724 if (num_vfpv3_regs > 0)
3725 {
3726 int start_offset = start > 16 ? start - 16 : 0;
3727 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3728 add_unwind_opcode (op, 2);
3729 }
3730
3731 /* Generate opcode for registers numbered in the range 0 .. 15. */
3732 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3733 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3734 if (num_regs_below_16 > 0)
3735 {
3736 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3737 add_unwind_opcode (op, 2);
3738 }
3739
3740 unwind.frame_size += count * 8;
3741}
3742
3743
3744/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3745
3746static void
c19d1205 3747s_arm_unwind_save_vfp (void)
b99bd4ef 3748{
c19d1205 3749 int count;
ca3f61f7 3750 unsigned int reg;
c19d1205 3751 valueT op;
b99bd4ef 3752
5287ad62 3753 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3754 if (count == FAIL)
b99bd4ef 3755 {
c19d1205
ZW
3756 as_bad (_("expected register list"));
3757 ignore_rest_of_line ();
b99bd4ef
NC
3758 return;
3759 }
3760
c19d1205 3761 demand_empty_rest_of_line ();
b99bd4ef 3762
c19d1205 3763 if (reg == 8)
b99bd4ef 3764 {
c19d1205
ZW
3765 /* Short form. */
3766 op = 0xb8 | (count - 1);
3767 add_unwind_opcode (op, 1);
b99bd4ef 3768 }
c19d1205 3769 else
b99bd4ef 3770 {
c19d1205
ZW
3771 /* Long form. */
3772 op = 0xb300 | (reg << 4) | (count - 1);
3773 add_unwind_opcode (op, 2);
b99bd4ef 3774 }
c19d1205
ZW
3775 unwind.frame_size += count * 8 + 4;
3776}
b99bd4ef 3777
b99bd4ef 3778
c19d1205
ZW
3779/* Parse a directive saving iWMMXt data registers. */
3780
3781static void
3782s_arm_unwind_save_mmxwr (void)
3783{
3784 int reg;
3785 int hi_reg;
3786 int i;
3787 unsigned mask = 0;
3788 valueT op;
b99bd4ef 3789
c19d1205
ZW
3790 if (*input_line_pointer == '{')
3791 input_line_pointer++;
b99bd4ef 3792
c19d1205 3793 do
b99bd4ef 3794 {
dcbf9037 3795 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3796
c19d1205 3797 if (reg == FAIL)
b99bd4ef 3798 {
9b7132d3 3799 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3800 goto error;
b99bd4ef
NC
3801 }
3802
c19d1205
ZW
3803 if (mask >> reg)
3804 as_tsktsk (_("register list not in ascending order"));
3805 mask |= 1 << reg;
b99bd4ef 3806
c19d1205
ZW
3807 if (*input_line_pointer == '-')
3808 {
3809 input_line_pointer++;
dcbf9037 3810 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3811 if (hi_reg == FAIL)
3812 {
9b7132d3 3813 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3814 goto error;
3815 }
3816 else if (reg >= hi_reg)
3817 {
3818 as_bad (_("bad register range"));
3819 goto error;
3820 }
3821 for (; reg < hi_reg; reg++)
3822 mask |= 1 << reg;
3823 }
3824 }
3825 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3826
c19d1205
ZW
3827 if (*input_line_pointer == '}')
3828 input_line_pointer++;
b99bd4ef 3829
c19d1205 3830 demand_empty_rest_of_line ();
b99bd4ef 3831
708587a4 3832 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3833 the list. */
3834 flush_pending_unwind ();
b99bd4ef 3835
c19d1205 3836 for (i = 0; i < 16; i++)
b99bd4ef 3837 {
c19d1205
ZW
3838 if (mask & (1 << i))
3839 unwind.frame_size += 8;
b99bd4ef
NC
3840 }
3841
c19d1205
ZW
3842 /* Attempt to combine with a previous opcode. We do this because gcc
3843 likes to output separate unwind directives for a single block of
3844 registers. */
3845 if (unwind.opcode_count > 0)
b99bd4ef 3846 {
c19d1205
ZW
3847 i = unwind.opcodes[unwind.opcode_count - 1];
3848 if ((i & 0xf8) == 0xc0)
3849 {
3850 i &= 7;
3851 /* Only merge if the blocks are contiguous. */
3852 if (i < 6)
3853 {
3854 if ((mask & 0xfe00) == (1 << 9))
3855 {
3856 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3857 unwind.opcode_count--;
3858 }
3859 }
3860 else if (i == 6 && unwind.opcode_count >= 2)
3861 {
3862 i = unwind.opcodes[unwind.opcode_count - 2];
3863 reg = i >> 4;
3864 i &= 0xf;
b99bd4ef 3865
c19d1205
ZW
3866 op = 0xffff << (reg - 1);
3867 if (reg > 0
87a1fd79 3868 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3869 {
3870 op = (1 << (reg + i + 1)) - 1;
3871 op &= ~((1 << reg) - 1);
3872 mask |= op;
3873 unwind.opcode_count -= 2;
3874 }
3875 }
3876 }
b99bd4ef
NC
3877 }
3878
c19d1205
ZW
3879 hi_reg = 15;
3880 /* We want to generate opcodes in the order the registers have been
3881 saved, ie. descending order. */
3882 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3883 {
c19d1205
ZW
3884 /* Save registers in blocks. */
3885 if (reg < 0
3886 || !(mask & (1 << reg)))
3887 {
3888 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3889 preceding block. */
c19d1205
ZW
3890 if (reg != hi_reg)
3891 {
3892 if (reg == 9)
3893 {
3894 /* Short form. */
3895 op = 0xc0 | (hi_reg - 10);
3896 add_unwind_opcode (op, 1);
3897 }
3898 else
3899 {
3900 /* Long form. */
3901 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3902 add_unwind_opcode (op, 2);
3903 }
3904 }
3905 hi_reg = reg - 1;
3906 }
b99bd4ef
NC
3907 }
3908
c19d1205
ZW
3909 return;
3910error:
3911 ignore_rest_of_line ();
b99bd4ef
NC
3912}
3913
3914static void
c19d1205 3915s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3916{
c19d1205
ZW
3917 int reg;
3918 int hi_reg;
3919 unsigned mask = 0;
3920 valueT op;
b99bd4ef 3921
c19d1205
ZW
3922 if (*input_line_pointer == '{')
3923 input_line_pointer++;
b99bd4ef 3924
c19d1205 3925 do
b99bd4ef 3926 {
dcbf9037 3927 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3928
c19d1205
ZW
3929 if (reg == FAIL)
3930 {
9b7132d3 3931 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3932 goto error;
3933 }
b99bd4ef 3934
c19d1205
ZW
3935 reg -= 8;
3936 if (mask >> reg)
3937 as_tsktsk (_("register list not in ascending order"));
3938 mask |= 1 << reg;
b99bd4ef 3939
c19d1205
ZW
3940 if (*input_line_pointer == '-')
3941 {
3942 input_line_pointer++;
dcbf9037 3943 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3944 if (hi_reg == FAIL)
3945 {
9b7132d3 3946 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3947 goto error;
3948 }
3949 else if (reg >= hi_reg)
3950 {
3951 as_bad (_("bad register range"));
3952 goto error;
3953 }
3954 for (; reg < hi_reg; reg++)
3955 mask |= 1 << reg;
3956 }
b99bd4ef 3957 }
c19d1205 3958 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3959
c19d1205
ZW
3960 if (*input_line_pointer == '}')
3961 input_line_pointer++;
b99bd4ef 3962
c19d1205
ZW
3963 demand_empty_rest_of_line ();
3964
708587a4 3965 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3966 the list. */
3967 flush_pending_unwind ();
b99bd4ef 3968
c19d1205 3969 for (reg = 0; reg < 16; reg++)
b99bd4ef 3970 {
c19d1205
ZW
3971 if (mask & (1 << reg))
3972 unwind.frame_size += 4;
b99bd4ef 3973 }
c19d1205
ZW
3974 op = 0xc700 | mask;
3975 add_unwind_opcode (op, 2);
3976 return;
3977error:
3978 ignore_rest_of_line ();
b99bd4ef
NC
3979}
3980
c19d1205 3981
fa073d69
MS
3982/* Parse an unwind_save directive.
3983 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3984
b99bd4ef 3985static void
fa073d69 3986s_arm_unwind_save (int arch_v6)
b99bd4ef 3987{
c19d1205
ZW
3988 char *peek;
3989 struct reg_entry *reg;
3990 bfd_boolean had_brace = FALSE;
b99bd4ef 3991
921e5f0a 3992 if (!unwind.proc_start)
c921be7d 3993 as_bad (MISSING_FNSTART);
921e5f0a 3994
c19d1205
ZW
3995 /* Figure out what sort of save we have. */
3996 peek = input_line_pointer;
b99bd4ef 3997
c19d1205 3998 if (*peek == '{')
b99bd4ef 3999 {
c19d1205
ZW
4000 had_brace = TRUE;
4001 peek++;
b99bd4ef
NC
4002 }
4003
c19d1205 4004 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4005
c19d1205 4006 if (!reg)
b99bd4ef 4007 {
c19d1205
ZW
4008 as_bad (_("register expected"));
4009 ignore_rest_of_line ();
b99bd4ef
NC
4010 return;
4011 }
4012
c19d1205 4013 switch (reg->type)
b99bd4ef 4014 {
c19d1205
ZW
4015 case REG_TYPE_FN:
4016 if (had_brace)
4017 {
4018 as_bad (_("FPA .unwind_save does not take a register list"));
4019 ignore_rest_of_line ();
4020 return;
4021 }
93ac2687 4022 input_line_pointer = peek;
c19d1205 4023 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4024 return;
c19d1205
ZW
4025
4026 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4027 case REG_TYPE_VFD:
4028 if (arch_v6)
4029 s_arm_unwind_save_vfp_armv6 ();
4030 else
4031 s_arm_unwind_save_vfp ();
4032 return;
c19d1205
ZW
4033 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4034 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4035
4036 default:
4037 as_bad (_(".unwind_save does not support this kind of register"));
4038 ignore_rest_of_line ();
b99bd4ef 4039 }
c19d1205 4040}
b99bd4ef 4041
b99bd4ef 4042
c19d1205
ZW
4043/* Parse an unwind_movsp directive. */
4044
4045static void
4046s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4047{
4048 int reg;
4049 valueT op;
4fa3602b 4050 int offset;
c19d1205 4051
921e5f0a 4052 if (!unwind.proc_start)
c921be7d 4053 as_bad (MISSING_FNSTART);
921e5f0a 4054
dcbf9037 4055 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4056 if (reg == FAIL)
b99bd4ef 4057 {
9b7132d3 4058 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4059 ignore_rest_of_line ();
b99bd4ef
NC
4060 return;
4061 }
4fa3602b
PB
4062
4063 /* Optional constant. */
4064 if (skip_past_comma (&input_line_pointer) != FAIL)
4065 {
4066 if (immediate_for_directive (&offset) == FAIL)
4067 return;
4068 }
4069 else
4070 offset = 0;
4071
c19d1205 4072 demand_empty_rest_of_line ();
b99bd4ef 4073
c19d1205 4074 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4075 {
c19d1205 4076 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4077 return;
4078 }
4079
c19d1205
ZW
4080 if (unwind.fp_reg != REG_SP)
4081 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4082
c19d1205
ZW
4083 /* Generate opcode to restore the value. */
4084 op = 0x90 | reg;
4085 add_unwind_opcode (op, 1);
4086
4087 /* Record the information for later. */
4088 unwind.fp_reg = reg;
4fa3602b 4089 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4090 unwind.sp_restored = 1;
b05fe5cf
ZW
4091}
4092
c19d1205
ZW
4093/* Parse an unwind_pad directive. */
4094
b05fe5cf 4095static void
c19d1205 4096s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4097{
c19d1205 4098 int offset;
b05fe5cf 4099
921e5f0a 4100 if (!unwind.proc_start)
c921be7d 4101 as_bad (MISSING_FNSTART);
921e5f0a 4102
c19d1205
ZW
4103 if (immediate_for_directive (&offset) == FAIL)
4104 return;
b99bd4ef 4105
c19d1205
ZW
4106 if (offset & 3)
4107 {
4108 as_bad (_("stack increment must be multiple of 4"));
4109 ignore_rest_of_line ();
4110 return;
4111 }
b99bd4ef 4112
c19d1205
ZW
4113 /* Don't generate any opcodes, just record the details for later. */
4114 unwind.frame_size += offset;
4115 unwind.pending_offset += offset;
4116
4117 demand_empty_rest_of_line ();
4118}
4119
4120/* Parse an unwind_setfp directive. */
4121
4122static void
4123s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4124{
c19d1205
ZW
4125 int sp_reg;
4126 int fp_reg;
4127 int offset;
4128
921e5f0a 4129 if (!unwind.proc_start)
c921be7d 4130 as_bad (MISSING_FNSTART);
921e5f0a 4131
dcbf9037 4132 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4133 if (skip_past_comma (&input_line_pointer) == FAIL)
4134 sp_reg = FAIL;
4135 else
dcbf9037 4136 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4137
c19d1205
ZW
4138 if (fp_reg == FAIL || sp_reg == FAIL)
4139 {
4140 as_bad (_("expected <reg>, <reg>"));
4141 ignore_rest_of_line ();
4142 return;
4143 }
b99bd4ef 4144
c19d1205
ZW
4145 /* Optional constant. */
4146 if (skip_past_comma (&input_line_pointer) != FAIL)
4147 {
4148 if (immediate_for_directive (&offset) == FAIL)
4149 return;
4150 }
4151 else
4152 offset = 0;
a737bd4d 4153
c19d1205 4154 demand_empty_rest_of_line ();
a737bd4d 4155
fdfde340 4156 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4157 {
c19d1205
ZW
4158 as_bad (_("register must be either sp or set by a previous"
4159 "unwind_movsp directive"));
4160 return;
a737bd4d
NC
4161 }
4162
c19d1205
ZW
4163 /* Don't generate any opcodes, just record the information for later. */
4164 unwind.fp_reg = fp_reg;
4165 unwind.fp_used = 1;
fdfde340 4166 if (sp_reg == REG_SP)
c19d1205
ZW
4167 unwind.fp_offset = unwind.frame_size - offset;
4168 else
4169 unwind.fp_offset -= offset;
a737bd4d
NC
4170}
4171
c19d1205
ZW
4172/* Parse an unwind_raw directive. */
4173
4174static void
4175s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4176{
c19d1205 4177 expressionS exp;
708587a4 4178 /* This is an arbitrary limit. */
c19d1205
ZW
4179 unsigned char op[16];
4180 int count;
a737bd4d 4181
921e5f0a 4182 if (!unwind.proc_start)
c921be7d 4183 as_bad (MISSING_FNSTART);
921e5f0a 4184
c19d1205
ZW
4185 expression (&exp);
4186 if (exp.X_op == O_constant
4187 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4188 {
c19d1205
ZW
4189 unwind.frame_size += exp.X_add_number;
4190 expression (&exp);
4191 }
4192 else
4193 exp.X_op = O_illegal;
a737bd4d 4194
c19d1205
ZW
4195 if (exp.X_op != O_constant)
4196 {
4197 as_bad (_("expected <offset>, <opcode>"));
4198 ignore_rest_of_line ();
4199 return;
4200 }
a737bd4d 4201
c19d1205 4202 count = 0;
a737bd4d 4203
c19d1205
ZW
4204 /* Parse the opcode. */
4205 for (;;)
4206 {
4207 if (count >= 16)
4208 {
4209 as_bad (_("unwind opcode too long"));
4210 ignore_rest_of_line ();
a737bd4d 4211 }
c19d1205 4212 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4213 {
c19d1205
ZW
4214 as_bad (_("invalid unwind opcode"));
4215 ignore_rest_of_line ();
4216 return;
a737bd4d 4217 }
c19d1205 4218 op[count++] = exp.X_add_number;
a737bd4d 4219
c19d1205
ZW
4220 /* Parse the next byte. */
4221 if (skip_past_comma (&input_line_pointer) == FAIL)
4222 break;
a737bd4d 4223
c19d1205
ZW
4224 expression (&exp);
4225 }
b99bd4ef 4226
c19d1205
ZW
4227 /* Add the opcode bytes in reverse order. */
4228 while (count--)
4229 add_unwind_opcode (op[count], 1);
b99bd4ef 4230
c19d1205 4231 demand_empty_rest_of_line ();
b99bd4ef 4232}
ee065d83
PB
4233
4234
4235/* Parse a .eabi_attribute directive. */
4236
4237static void
4238s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4239{
ee3c0378
AS
4240 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4241
4242 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4243 attributes_set_explicitly[tag] = 1;
ee065d83 4244}
8463be01 4245#endif /* OBJ_ELF */
ee065d83
PB
4246
4247static void s_arm_arch (int);
7a1d4c38 4248static void s_arm_object_arch (int);
ee065d83
PB
4249static void s_arm_cpu (int);
4250static void s_arm_fpu (int);
b99bd4ef 4251
f0927246
NC
4252#ifdef TE_PE
4253
4254static void
5f4273c7 4255pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4256{
4257 expressionS exp;
4258
4259 do
4260 {
4261 expression (&exp);
4262 if (exp.X_op == O_symbol)
4263 exp.X_op = O_secrel;
4264
4265 emit_expr (&exp, 4);
4266 }
4267 while (*input_line_pointer++ == ',');
4268
4269 input_line_pointer--;
4270 demand_empty_rest_of_line ();
4271}
4272#endif /* TE_PE */
4273
c19d1205
ZW
4274/* This table describes all the machine specific pseudo-ops the assembler
4275 has to support. The fields are:
4276 pseudo-op name without dot
4277 function to call to execute this pseudo-op
4278 Integer arg to pass to the function. */
b99bd4ef 4279
c19d1205 4280const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4281{
c19d1205
ZW
4282 /* Never called because '.req' does not start a line. */
4283 { "req", s_req, 0 },
dcbf9037
JB
4284 /* Following two are likewise never called. */
4285 { "dn", s_dn, 0 },
4286 { "qn", s_qn, 0 },
c19d1205
ZW
4287 { "unreq", s_unreq, 0 },
4288 { "bss", s_bss, 0 },
4289 { "align", s_align, 0 },
4290 { "arm", s_arm, 0 },
4291 { "thumb", s_thumb, 0 },
4292 { "code", s_code, 0 },
4293 { "force_thumb", s_force_thumb, 0 },
4294 { "thumb_func", s_thumb_func, 0 },
4295 { "thumb_set", s_thumb_set, 0 },
4296 { "even", s_even, 0 },
4297 { "ltorg", s_ltorg, 0 },
4298 { "pool", s_ltorg, 0 },
4299 { "syntax", s_syntax, 0 },
8463be01
PB
4300 { "cpu", s_arm_cpu, 0 },
4301 { "arch", s_arm_arch, 0 },
7a1d4c38 4302 { "object_arch", s_arm_object_arch, 0 },
8463be01 4303 { "fpu", s_arm_fpu, 0 },
c19d1205 4304#ifdef OBJ_ELF
c921be7d
NC
4305 { "word", s_arm_elf_cons, 4 },
4306 { "long", s_arm_elf_cons, 4 },
4307 { "inst.n", s_arm_elf_inst, 2 },
4308 { "inst.w", s_arm_elf_inst, 4 },
4309 { "inst", s_arm_elf_inst, 0 },
4310 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4311 { "fnstart", s_arm_unwind_fnstart, 0 },
4312 { "fnend", s_arm_unwind_fnend, 0 },
4313 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4314 { "personality", s_arm_unwind_personality, 0 },
4315 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4316 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4317 { "save", s_arm_unwind_save, 0 },
fa073d69 4318 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4319 { "movsp", s_arm_unwind_movsp, 0 },
4320 { "pad", s_arm_unwind_pad, 0 },
4321 { "setfp", s_arm_unwind_setfp, 0 },
4322 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4323 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4324#else
4325 { "word", cons, 4},
f0927246
NC
4326
4327 /* These are used for dwarf. */
4328 {"2byte", cons, 2},
4329 {"4byte", cons, 4},
4330 {"8byte", cons, 8},
4331 /* These are used for dwarf2. */
4332 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4333 { "loc", dwarf2_directive_loc, 0 },
4334 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4335#endif
4336 { "extend", float_cons, 'x' },
4337 { "ldouble", float_cons, 'x' },
4338 { "packed", float_cons, 'p' },
f0927246
NC
4339#ifdef TE_PE
4340 {"secrel32", pe_directive_secrel, 0},
4341#endif
c19d1205
ZW
4342 { 0, 0, 0 }
4343};
4344\f
4345/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4346
c19d1205
ZW
4347/* Generic immediate-value read function for use in insn parsing.
4348 STR points to the beginning of the immediate (the leading #);
4349 VAL receives the value; if the value is outside [MIN, MAX]
4350 issue an error. PREFIX_OPT is true if the immediate prefix is
4351 optional. */
b99bd4ef 4352
c19d1205
ZW
4353static int
4354parse_immediate (char **str, int *val, int min, int max,
4355 bfd_boolean prefix_opt)
4356{
4357 expressionS exp;
4358 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4359 if (exp.X_op != O_constant)
b99bd4ef 4360 {
c19d1205
ZW
4361 inst.error = _("constant expression required");
4362 return FAIL;
4363 }
b99bd4ef 4364
c19d1205
ZW
4365 if (exp.X_add_number < min || exp.X_add_number > max)
4366 {
4367 inst.error = _("immediate value out of range");
4368 return FAIL;
4369 }
b99bd4ef 4370
c19d1205
ZW
4371 *val = exp.X_add_number;
4372 return SUCCESS;
4373}
b99bd4ef 4374
5287ad62 4375/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4376 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4377 instructions. Puts the result directly in inst.operands[i]. */
4378
4379static int
4380parse_big_immediate (char **str, int i)
4381{
4382 expressionS exp;
4383 char *ptr = *str;
4384
4385 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4386
4387 if (exp.X_op == O_constant)
036dc3f7
PB
4388 {
4389 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4390 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4391 O_constant. We have to be careful not to break compilation for
4392 32-bit X_add_number, though. */
4393 if ((exp.X_add_number & ~0xffffffffl) != 0)
4394 {
4395 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4396 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4397 inst.operands[i].regisimm = 1;
4398 }
4399 }
5287ad62
JB
4400 else if (exp.X_op == O_big
4401 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4402 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4403 {
4404 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4405 /* Bignums have their least significant bits in
4406 generic_bignum[0]. Make sure we put 32 bits in imm and
4407 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4408 gas_assert (parts != 0);
5287ad62
JB
4409 inst.operands[i].imm = 0;
4410 for (j = 0; j < parts; j++, idx++)
4411 inst.operands[i].imm |= generic_bignum[idx]
4412 << (LITTLENUM_NUMBER_OF_BITS * j);
4413 inst.operands[i].reg = 0;
4414 for (j = 0; j < parts; j++, idx++)
4415 inst.operands[i].reg |= generic_bignum[idx]
4416 << (LITTLENUM_NUMBER_OF_BITS * j);
4417 inst.operands[i].regisimm = 1;
4418 }
4419 else
4420 return FAIL;
5f4273c7 4421
5287ad62
JB
4422 *str = ptr;
4423
4424 return SUCCESS;
4425}
4426
c19d1205
ZW
4427/* Returns the pseudo-register number of an FPA immediate constant,
4428 or FAIL if there isn't a valid constant here. */
b99bd4ef 4429
c19d1205
ZW
4430static int
4431parse_fpa_immediate (char ** str)
4432{
4433 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4434 char * save_in;
4435 expressionS exp;
4436 int i;
4437 int j;
b99bd4ef 4438
c19d1205
ZW
4439 /* First try and match exact strings, this is to guarantee
4440 that some formats will work even for cross assembly. */
b99bd4ef 4441
c19d1205
ZW
4442 for (i = 0; fp_const[i]; i++)
4443 {
4444 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4445 {
c19d1205 4446 char *start = *str;
b99bd4ef 4447
c19d1205
ZW
4448 *str += strlen (fp_const[i]);
4449 if (is_end_of_line[(unsigned char) **str])
4450 return i + 8;
4451 *str = start;
4452 }
4453 }
b99bd4ef 4454
c19d1205
ZW
4455 /* Just because we didn't get a match doesn't mean that the constant
4456 isn't valid, just that it is in a format that we don't
4457 automatically recognize. Try parsing it with the standard
4458 expression routines. */
b99bd4ef 4459
c19d1205 4460 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4461
c19d1205
ZW
4462 /* Look for a raw floating point number. */
4463 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4464 && is_end_of_line[(unsigned char) *save_in])
4465 {
4466 for (i = 0; i < NUM_FLOAT_VALS; i++)
4467 {
4468 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4469 {
c19d1205
ZW
4470 if (words[j] != fp_values[i][j])
4471 break;
b99bd4ef
NC
4472 }
4473
c19d1205 4474 if (j == MAX_LITTLENUMS)
b99bd4ef 4475 {
c19d1205
ZW
4476 *str = save_in;
4477 return i + 8;
b99bd4ef
NC
4478 }
4479 }
4480 }
b99bd4ef 4481
c19d1205
ZW
4482 /* Try and parse a more complex expression, this will probably fail
4483 unless the code uses a floating point prefix (eg "0f"). */
4484 save_in = input_line_pointer;
4485 input_line_pointer = *str;
4486 if (expression (&exp) == absolute_section
4487 && exp.X_op == O_big
4488 && exp.X_add_number < 0)
4489 {
4490 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4491 Ditto for 15. */
4492 if (gen_to_words (words, 5, (long) 15) == 0)
4493 {
4494 for (i = 0; i < NUM_FLOAT_VALS; i++)
4495 {
4496 for (j = 0; j < MAX_LITTLENUMS; j++)
4497 {
4498 if (words[j] != fp_values[i][j])
4499 break;
4500 }
b99bd4ef 4501
c19d1205
ZW
4502 if (j == MAX_LITTLENUMS)
4503 {
4504 *str = input_line_pointer;
4505 input_line_pointer = save_in;
4506 return i + 8;
4507 }
4508 }
4509 }
b99bd4ef
NC
4510 }
4511
c19d1205
ZW
4512 *str = input_line_pointer;
4513 input_line_pointer = save_in;
4514 inst.error = _("invalid FPA immediate expression");
4515 return FAIL;
b99bd4ef
NC
4516}
4517
136da414
JB
4518/* Returns 1 if a number has "quarter-precision" float format
4519 0baBbbbbbc defgh000 00000000 00000000. */
4520
4521static int
4522is_quarter_float (unsigned imm)
4523{
4524 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4525 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4526}
4527
4528/* Parse an 8-bit "quarter-precision" floating point number of the form:
4529 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4530 The zero and minus-zero cases need special handling, since they can't be
4531 encoded in the "quarter-precision" float format, but can nonetheless be
4532 loaded as integer constants. */
136da414
JB
4533
4534static unsigned
4535parse_qfloat_immediate (char **ccp, int *immed)
4536{
4537 char *str = *ccp;
c96612cc 4538 char *fpnum;
136da414 4539 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4540 int found_fpchar = 0;
5f4273c7 4541
136da414 4542 skip_past_char (&str, '#');
5f4273c7 4543
c96612cc
JB
4544 /* We must not accidentally parse an integer as a floating-point number. Make
4545 sure that the value we parse is not an integer by checking for special
4546 characters '.' or 'e'.
4547 FIXME: This is a horrible hack, but doing better is tricky because type
4548 information isn't in a very usable state at parse time. */
4549 fpnum = str;
4550 skip_whitespace (fpnum);
4551
4552 if (strncmp (fpnum, "0x", 2) == 0)
4553 return FAIL;
4554 else
4555 {
4556 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4557 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4558 {
4559 found_fpchar = 1;
4560 break;
4561 }
4562
4563 if (!found_fpchar)
4564 return FAIL;
4565 }
5f4273c7 4566
136da414
JB
4567 if ((str = atof_ieee (str, 's', words)) != NULL)
4568 {
4569 unsigned fpword = 0;
4570 int i;
5f4273c7 4571
136da414
JB
4572 /* Our FP word must be 32 bits (single-precision FP). */
4573 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4574 {
4575 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4576 fpword |= words[i];
4577 }
5f4273c7 4578
c96612cc 4579 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4580 *immed = fpword;
4581 else
4582 return FAIL;
4583
4584 *ccp = str;
5f4273c7 4585
136da414
JB
4586 return SUCCESS;
4587 }
5f4273c7 4588
136da414
JB
4589 return FAIL;
4590}
4591
c19d1205
ZW
4592/* Shift operands. */
4593enum shift_kind
b99bd4ef 4594{
c19d1205
ZW
4595 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4596};
b99bd4ef 4597
c19d1205
ZW
4598struct asm_shift_name
4599{
4600 const char *name;
4601 enum shift_kind kind;
4602};
b99bd4ef 4603
c19d1205
ZW
4604/* Third argument to parse_shift. */
4605enum parse_shift_mode
4606{
4607 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4608 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4609 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4610 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4611 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4612};
b99bd4ef 4613
c19d1205
ZW
4614/* Parse a <shift> specifier on an ARM data processing instruction.
4615 This has three forms:
b99bd4ef 4616
c19d1205
ZW
4617 (LSL|LSR|ASL|ASR|ROR) Rs
4618 (LSL|LSR|ASL|ASR|ROR) #imm
4619 RRX
b99bd4ef 4620
c19d1205
ZW
4621 Note that ASL is assimilated to LSL in the instruction encoding, and
4622 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4623
c19d1205
ZW
4624static int
4625parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4626{
c19d1205
ZW
4627 const struct asm_shift_name *shift_name;
4628 enum shift_kind shift;
4629 char *s = *str;
4630 char *p = s;
4631 int reg;
b99bd4ef 4632
c19d1205
ZW
4633 for (p = *str; ISALPHA (*p); p++)
4634 ;
b99bd4ef 4635
c19d1205 4636 if (p == *str)
b99bd4ef 4637 {
c19d1205
ZW
4638 inst.error = _("shift expression expected");
4639 return FAIL;
b99bd4ef
NC
4640 }
4641
21d799b5
NC
4642 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4643 p - *str);
c19d1205
ZW
4644
4645 if (shift_name == NULL)
b99bd4ef 4646 {
c19d1205
ZW
4647 inst.error = _("shift expression expected");
4648 return FAIL;
b99bd4ef
NC
4649 }
4650
c19d1205 4651 shift = shift_name->kind;
b99bd4ef 4652
c19d1205
ZW
4653 switch (mode)
4654 {
4655 case NO_SHIFT_RESTRICT:
4656 case SHIFT_IMMEDIATE: break;
b99bd4ef 4657
c19d1205
ZW
4658 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4659 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4660 {
4661 inst.error = _("'LSL' or 'ASR' required");
4662 return FAIL;
4663 }
4664 break;
b99bd4ef 4665
c19d1205
ZW
4666 case SHIFT_LSL_IMMEDIATE:
4667 if (shift != SHIFT_LSL)
4668 {
4669 inst.error = _("'LSL' required");
4670 return FAIL;
4671 }
4672 break;
b99bd4ef 4673
c19d1205
ZW
4674 case SHIFT_ASR_IMMEDIATE:
4675 if (shift != SHIFT_ASR)
4676 {
4677 inst.error = _("'ASR' required");
4678 return FAIL;
4679 }
4680 break;
b99bd4ef 4681
c19d1205
ZW
4682 default: abort ();
4683 }
b99bd4ef 4684
c19d1205
ZW
4685 if (shift != SHIFT_RRX)
4686 {
4687 /* Whitespace can appear here if the next thing is a bare digit. */
4688 skip_whitespace (p);
b99bd4ef 4689
c19d1205 4690 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4691 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4692 {
4693 inst.operands[i].imm = reg;
4694 inst.operands[i].immisreg = 1;
4695 }
4696 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4697 return FAIL;
4698 }
4699 inst.operands[i].shift_kind = shift;
4700 inst.operands[i].shifted = 1;
4701 *str = p;
4702 return SUCCESS;
b99bd4ef
NC
4703}
4704
c19d1205 4705/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4706
c19d1205
ZW
4707 #<immediate>
4708 #<immediate>, <rotate>
4709 <Rm>
4710 <Rm>, <shift>
b99bd4ef 4711
c19d1205
ZW
4712 where <shift> is defined by parse_shift above, and <rotate> is a
4713 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4714 is deferred to md_apply_fix. */
b99bd4ef 4715
c19d1205
ZW
4716static int
4717parse_shifter_operand (char **str, int i)
4718{
4719 int value;
91d6fa6a 4720 expressionS exp;
b99bd4ef 4721
dcbf9037 4722 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4723 {
4724 inst.operands[i].reg = value;
4725 inst.operands[i].isreg = 1;
b99bd4ef 4726
c19d1205
ZW
4727 /* parse_shift will override this if appropriate */
4728 inst.reloc.exp.X_op = O_constant;
4729 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4730
c19d1205
ZW
4731 if (skip_past_comma (str) == FAIL)
4732 return SUCCESS;
b99bd4ef 4733
c19d1205
ZW
4734 /* Shift operation on register. */
4735 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4736 }
4737
c19d1205
ZW
4738 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4739 return FAIL;
b99bd4ef 4740
c19d1205 4741 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4742 {
c19d1205 4743 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 4744 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 4745 return FAIL;
b99bd4ef 4746
91d6fa6a 4747 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
4748 {
4749 inst.error = _("constant expression expected");
4750 return FAIL;
4751 }
b99bd4ef 4752
91d6fa6a 4753 value = exp.X_add_number;
c19d1205
ZW
4754 if (value < 0 || value > 30 || value % 2 != 0)
4755 {
4756 inst.error = _("invalid rotation");
4757 return FAIL;
4758 }
4759 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4760 {
4761 inst.error = _("invalid constant");
4762 return FAIL;
4763 }
09d92015 4764
55cf6793 4765 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4766 inst.reloc.exp.X_add_number
4767 = (((inst.reloc.exp.X_add_number << (32 - value))
4768 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4769 }
4770
c19d1205
ZW
4771 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4772 inst.reloc.pc_rel = 0;
4773 return SUCCESS;
09d92015
MM
4774}
4775
4962c51a
MS
4776/* Group relocation information. Each entry in the table contains the
4777 textual name of the relocation as may appear in assembler source
4778 and must end with a colon.
4779 Along with this textual name are the relocation codes to be used if
4780 the corresponding instruction is an ALU instruction (ADD or SUB only),
4781 an LDR, an LDRS, or an LDC. */
4782
4783struct group_reloc_table_entry
4784{
4785 const char *name;
4786 int alu_code;
4787 int ldr_code;
4788 int ldrs_code;
4789 int ldc_code;
4790};
4791
4792typedef enum
4793{
4794 /* Varieties of non-ALU group relocation. */
4795
4796 GROUP_LDR,
4797 GROUP_LDRS,
4798 GROUP_LDC
4799} group_reloc_type;
4800
4801static struct group_reloc_table_entry group_reloc_table[] =
4802 { /* Program counter relative: */
4803 { "pc_g0_nc",
4804 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4805 0, /* LDR */
4806 0, /* LDRS */
4807 0 }, /* LDC */
4808 { "pc_g0",
4809 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4810 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4811 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4812 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4813 { "pc_g1_nc",
4814 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4815 0, /* LDR */
4816 0, /* LDRS */
4817 0 }, /* LDC */
4818 { "pc_g1",
4819 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4820 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4821 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4822 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4823 { "pc_g2",
4824 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4825 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4826 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4827 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4828 /* Section base relative */
4829 { "sb_g0_nc",
4830 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4831 0, /* LDR */
4832 0, /* LDRS */
4833 0 }, /* LDC */
4834 { "sb_g0",
4835 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4836 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4837 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4838 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4839 { "sb_g1_nc",
4840 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4841 0, /* LDR */
4842 0, /* LDRS */
4843 0 }, /* LDC */
4844 { "sb_g1",
4845 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4846 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4847 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4848 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4849 { "sb_g2",
4850 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4851 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4852 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4853 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4854
4855/* Given the address of a pointer pointing to the textual name of a group
4856 relocation as may appear in assembler source, attempt to find its details
4857 in group_reloc_table. The pointer will be updated to the character after
4858 the trailing colon. On failure, FAIL will be returned; SUCCESS
4859 otherwise. On success, *entry will be updated to point at the relevant
4860 group_reloc_table entry. */
4861
4862static int
4863find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4864{
4865 unsigned int i;
4866 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4867 {
4868 int length = strlen (group_reloc_table[i].name);
4869
5f4273c7
NC
4870 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4871 && (*str)[length] == ':')
4962c51a
MS
4872 {
4873 *out = &group_reloc_table[i];
4874 *str += (length + 1);
4875 return SUCCESS;
4876 }
4877 }
4878
4879 return FAIL;
4880}
4881
4882/* Parse a <shifter_operand> for an ARM data processing instruction
4883 (as for parse_shifter_operand) where group relocations are allowed:
4884
4885 #<immediate>
4886 #<immediate>, <rotate>
4887 #:<group_reloc>:<expression>
4888 <Rm>
4889 <Rm>, <shift>
4890
4891 where <group_reloc> is one of the strings defined in group_reloc_table.
4892 The hashes are optional.
4893
4894 Everything else is as for parse_shifter_operand. */
4895
4896static parse_operand_result
4897parse_shifter_operand_group_reloc (char **str, int i)
4898{
4899 /* Determine if we have the sequence of characters #: or just :
4900 coming next. If we do, then we check for a group relocation.
4901 If we don't, punt the whole lot to parse_shifter_operand. */
4902
4903 if (((*str)[0] == '#' && (*str)[1] == ':')
4904 || (*str)[0] == ':')
4905 {
4906 struct group_reloc_table_entry *entry;
4907
4908 if ((*str)[0] == '#')
4909 (*str) += 2;
4910 else
4911 (*str)++;
4912
4913 /* Try to parse a group relocation. Anything else is an error. */
4914 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4915 {
4916 inst.error = _("unknown group relocation");
4917 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4918 }
4919
4920 /* We now have the group relocation table entry corresponding to
4921 the name in the assembler source. Next, we parse the expression. */
4922 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4923 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4924
4925 /* Record the relocation type (always the ALU variant here). */
21d799b5 4926 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4927 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4928
4929 return PARSE_OPERAND_SUCCESS;
4930 }
4931 else
4932 return parse_shifter_operand (str, i) == SUCCESS
4933 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4934
4935 /* Never reached. */
4936}
4937
c19d1205
ZW
4938/* Parse all forms of an ARM address expression. Information is written
4939 to inst.operands[i] and/or inst.reloc.
09d92015 4940
c19d1205 4941 Preindexed addressing (.preind=1):
09d92015 4942
c19d1205
ZW
4943 [Rn, #offset] .reg=Rn .reloc.exp=offset
4944 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4945 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4946 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4947
c19d1205 4948 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4949
c19d1205 4950 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4951
c19d1205
ZW
4952 [Rn], #offset .reg=Rn .reloc.exp=offset
4953 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4954 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4955 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4956
c19d1205 4957 Unindexed addressing (.preind=0, .postind=0):
09d92015 4958
c19d1205 4959 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4960
c19d1205 4961 Other:
09d92015 4962
c19d1205
ZW
4963 [Rn]{!} shorthand for [Rn,#0]{!}
4964 =immediate .isreg=0 .reloc.exp=immediate
4965 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4966
c19d1205
ZW
4967 It is the caller's responsibility to check for addressing modes not
4968 supported by the instruction, and to set inst.reloc.type. */
4969
4962c51a
MS
4970static parse_operand_result
4971parse_address_main (char **str, int i, int group_relocations,
4972 group_reloc_type group_type)
09d92015 4973{
c19d1205
ZW
4974 char *p = *str;
4975 int reg;
09d92015 4976
c19d1205 4977 if (skip_past_char (&p, '[') == FAIL)
09d92015 4978 {
c19d1205
ZW
4979 if (skip_past_char (&p, '=') == FAIL)
4980 {
974da60d 4981 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
4982 inst.reloc.pc_rel = 1;
4983 inst.operands[i].reg = REG_PC;
4984 inst.operands[i].isreg = 1;
4985 inst.operands[i].preind = 1;
4986 }
974da60d 4987 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 4988
c19d1205 4989 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4990 return PARSE_OPERAND_FAIL;
09d92015 4991
c19d1205 4992 *str = p;
4962c51a 4993 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4994 }
4995
dcbf9037 4996 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4997 {
c19d1205 4998 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4999 return PARSE_OPERAND_FAIL;
09d92015 5000 }
c19d1205
ZW
5001 inst.operands[i].reg = reg;
5002 inst.operands[i].isreg = 1;
09d92015 5003
c19d1205 5004 if (skip_past_comma (&p) == SUCCESS)
09d92015 5005 {
c19d1205 5006 inst.operands[i].preind = 1;
09d92015 5007
c19d1205
ZW
5008 if (*p == '+') p++;
5009 else if (*p == '-') p++, inst.operands[i].negative = 1;
5010
dcbf9037 5011 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5012 {
c19d1205
ZW
5013 inst.operands[i].imm = reg;
5014 inst.operands[i].immisreg = 1;
5015
5016 if (skip_past_comma (&p) == SUCCESS)
5017 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5018 return PARSE_OPERAND_FAIL;
c19d1205 5019 }
5287ad62
JB
5020 else if (skip_past_char (&p, ':') == SUCCESS)
5021 {
5022 /* FIXME: '@' should be used here, but it's filtered out by generic
5023 code before we get to see it here. This may be subject to
5024 change. */
5025 expressionS exp;
5026 my_get_expression (&exp, &p, GE_NO_PREFIX);
5027 if (exp.X_op != O_constant)
5028 {
5029 inst.error = _("alignment must be constant");
4962c51a 5030 return PARSE_OPERAND_FAIL;
5287ad62
JB
5031 }
5032 inst.operands[i].imm = exp.X_add_number << 8;
5033 inst.operands[i].immisalign = 1;
5034 /* Alignments are not pre-indexes. */
5035 inst.operands[i].preind = 0;
5036 }
c19d1205
ZW
5037 else
5038 {
5039 if (inst.operands[i].negative)
5040 {
5041 inst.operands[i].negative = 0;
5042 p--;
5043 }
4962c51a 5044
5f4273c7
NC
5045 if (group_relocations
5046 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5047 {
5048 struct group_reloc_table_entry *entry;
5049
5050 /* Skip over the #: or : sequence. */
5051 if (*p == '#')
5052 p += 2;
5053 else
5054 p++;
5055
5056 /* Try to parse a group relocation. Anything else is an
5057 error. */
5058 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5059 {
5060 inst.error = _("unknown group relocation");
5061 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5062 }
5063
5064 /* We now have the group relocation table entry corresponding to
5065 the name in the assembler source. Next, we parse the
5066 expression. */
5067 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5068 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5069
5070 /* Record the relocation type. */
5071 switch (group_type)
5072 {
5073 case GROUP_LDR:
21d799b5 5074 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5075 break;
5076
5077 case GROUP_LDRS:
21d799b5 5078 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5079 break;
5080
5081 case GROUP_LDC:
21d799b5 5082 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5083 break;
5084
5085 default:
9c2799c2 5086 gas_assert (0);
4962c51a
MS
5087 }
5088
5089 if (inst.reloc.type == 0)
5090 {
5091 inst.error = _("this group relocation is not allowed on this instruction");
5092 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5093 }
5094 }
5095 else
5096 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5097 return PARSE_OPERAND_FAIL;
09d92015
MM
5098 }
5099 }
5100
c19d1205 5101 if (skip_past_char (&p, ']') == FAIL)
09d92015 5102 {
c19d1205 5103 inst.error = _("']' expected");
4962c51a 5104 return PARSE_OPERAND_FAIL;
09d92015
MM
5105 }
5106
c19d1205
ZW
5107 if (skip_past_char (&p, '!') == SUCCESS)
5108 inst.operands[i].writeback = 1;
09d92015 5109
c19d1205 5110 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5111 {
c19d1205
ZW
5112 if (skip_past_char (&p, '{') == SUCCESS)
5113 {
5114 /* [Rn], {expr} - unindexed, with option */
5115 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5116 0, 255, TRUE) == FAIL)
4962c51a 5117 return PARSE_OPERAND_FAIL;
09d92015 5118
c19d1205
ZW
5119 if (skip_past_char (&p, '}') == FAIL)
5120 {
5121 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5122 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5123 }
5124 if (inst.operands[i].preind)
5125 {
5126 inst.error = _("cannot combine index with option");
4962c51a 5127 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5128 }
5129 *str = p;
4962c51a 5130 return PARSE_OPERAND_SUCCESS;
09d92015 5131 }
c19d1205
ZW
5132 else
5133 {
5134 inst.operands[i].postind = 1;
5135 inst.operands[i].writeback = 1;
09d92015 5136
c19d1205
ZW
5137 if (inst.operands[i].preind)
5138 {
5139 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5140 return PARSE_OPERAND_FAIL;
c19d1205 5141 }
09d92015 5142
c19d1205
ZW
5143 if (*p == '+') p++;
5144 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5145
dcbf9037 5146 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5147 {
5287ad62
JB
5148 /* We might be using the immediate for alignment already. If we
5149 are, OR the register number into the low-order bits. */
5150 if (inst.operands[i].immisalign)
5151 inst.operands[i].imm |= reg;
5152 else
5153 inst.operands[i].imm = reg;
c19d1205 5154 inst.operands[i].immisreg = 1;
a737bd4d 5155
c19d1205
ZW
5156 if (skip_past_comma (&p) == SUCCESS)
5157 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5158 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5159 }
5160 else
5161 {
5162 if (inst.operands[i].negative)
5163 {
5164 inst.operands[i].negative = 0;
5165 p--;
5166 }
5167 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5168 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5169 }
5170 }
a737bd4d
NC
5171 }
5172
c19d1205
ZW
5173 /* If at this point neither .preind nor .postind is set, we have a
5174 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5175 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5176 {
5177 inst.operands[i].preind = 1;
5178 inst.reloc.exp.X_op = O_constant;
5179 inst.reloc.exp.X_add_number = 0;
5180 }
5181 *str = p;
4962c51a
MS
5182 return PARSE_OPERAND_SUCCESS;
5183}
5184
5185static int
5186parse_address (char **str, int i)
5187{
21d799b5 5188 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5189 ? SUCCESS : FAIL;
5190}
5191
5192static parse_operand_result
5193parse_address_group_reloc (char **str, int i, group_reloc_type type)
5194{
5195 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5196}
5197
b6895b4f
PB
5198/* Parse an operand for a MOVW or MOVT instruction. */
5199static int
5200parse_half (char **str)
5201{
5202 char * p;
5f4273c7 5203
b6895b4f
PB
5204 p = *str;
5205 skip_past_char (&p, '#');
5f4273c7 5206 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5207 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5208 else if (strncasecmp (p, ":upper16:", 9) == 0)
5209 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5210
5211 if (inst.reloc.type != BFD_RELOC_UNUSED)
5212 {
5213 p += 9;
5f4273c7 5214 skip_whitespace (p);
b6895b4f
PB
5215 }
5216
5217 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5218 return FAIL;
5219
5220 if (inst.reloc.type == BFD_RELOC_UNUSED)
5221 {
5222 if (inst.reloc.exp.X_op != O_constant)
5223 {
5224 inst.error = _("constant expression expected");
5225 return FAIL;
5226 }
5227 if (inst.reloc.exp.X_add_number < 0
5228 || inst.reloc.exp.X_add_number > 0xffff)
5229 {
5230 inst.error = _("immediate value out of range");
5231 return FAIL;
5232 }
5233 }
5234 *str = p;
5235 return SUCCESS;
5236}
5237
c19d1205 5238/* Miscellaneous. */
a737bd4d 5239
c19d1205
ZW
5240/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5241 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5242static int
5243parse_psr (char **str)
09d92015 5244{
c19d1205
ZW
5245 char *p;
5246 unsigned long psr_field;
62b3e311
PB
5247 const struct asm_psr *psr;
5248 char *start;
09d92015 5249
c19d1205
ZW
5250 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5251 feature for ease of use and backwards compatibility. */
5252 p = *str;
62b3e311 5253 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5254 psr_field = SPSR_BIT;
62b3e311 5255 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5256 psr_field = 0;
5257 else
62b3e311
PB
5258 {
5259 start = p;
5260 do
5261 p++;
5262 while (ISALNUM (*p) || *p == '_');
5263
21d799b5
NC
5264 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5265 p - start);
62b3e311
PB
5266 if (!psr)
5267 return FAIL;
09d92015 5268
62b3e311
PB
5269 *str = p;
5270 return psr->field;
5271 }
09d92015 5272
62b3e311 5273 p += 4;
c19d1205
ZW
5274 if (*p == '_')
5275 {
5276 /* A suffix follows. */
c19d1205
ZW
5277 p++;
5278 start = p;
a737bd4d 5279
c19d1205
ZW
5280 do
5281 p++;
5282 while (ISALNUM (*p) || *p == '_');
a737bd4d 5283
21d799b5
NC
5284 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5285 p - start);
c19d1205
ZW
5286 if (!psr)
5287 goto error;
a737bd4d 5288
c19d1205 5289 psr_field |= psr->field;
a737bd4d 5290 }
c19d1205 5291 else
a737bd4d 5292 {
c19d1205
ZW
5293 if (ISALNUM (*p))
5294 goto error; /* Garbage after "[CS]PSR". */
5295
5296 psr_field |= (PSR_c | PSR_f);
a737bd4d 5297 }
c19d1205
ZW
5298 *str = p;
5299 return psr_field;
a737bd4d 5300
c19d1205
ZW
5301 error:
5302 inst.error = _("flag for {c}psr instruction expected");
5303 return FAIL;
a737bd4d
NC
5304}
5305
c19d1205
ZW
5306/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5307 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5308
c19d1205
ZW
5309static int
5310parse_cps_flags (char **str)
a737bd4d 5311{
c19d1205
ZW
5312 int val = 0;
5313 int saw_a_flag = 0;
5314 char *s = *str;
a737bd4d 5315
c19d1205
ZW
5316 for (;;)
5317 switch (*s++)
5318 {
5319 case '\0': case ',':
5320 goto done;
a737bd4d 5321
c19d1205
ZW
5322 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5323 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5324 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5325
c19d1205
ZW
5326 default:
5327 inst.error = _("unrecognized CPS flag");
5328 return FAIL;
5329 }
a737bd4d 5330
c19d1205
ZW
5331 done:
5332 if (saw_a_flag == 0)
a737bd4d 5333 {
c19d1205
ZW
5334 inst.error = _("missing CPS flags");
5335 return FAIL;
a737bd4d 5336 }
a737bd4d 5337
c19d1205
ZW
5338 *str = s - 1;
5339 return val;
a737bd4d
NC
5340}
5341
c19d1205
ZW
5342/* Parse an endian specifier ("BE" or "LE", case insensitive);
5343 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5344
5345static int
c19d1205 5346parse_endian_specifier (char **str)
a737bd4d 5347{
c19d1205
ZW
5348 int little_endian;
5349 char *s = *str;
a737bd4d 5350
c19d1205
ZW
5351 if (strncasecmp (s, "BE", 2))
5352 little_endian = 0;
5353 else if (strncasecmp (s, "LE", 2))
5354 little_endian = 1;
5355 else
a737bd4d 5356 {
c19d1205 5357 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5358 return FAIL;
5359 }
5360
c19d1205 5361 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5362 {
c19d1205 5363 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5364 return FAIL;
5365 }
5366
c19d1205
ZW
5367 *str = s + 2;
5368 return little_endian;
5369}
a737bd4d 5370
c19d1205
ZW
5371/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5372 value suitable for poking into the rotate field of an sxt or sxta
5373 instruction, or FAIL on error. */
5374
5375static int
5376parse_ror (char **str)
5377{
5378 int rot;
5379 char *s = *str;
5380
5381 if (strncasecmp (s, "ROR", 3) == 0)
5382 s += 3;
5383 else
a737bd4d 5384 {
c19d1205 5385 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5386 return FAIL;
5387 }
c19d1205
ZW
5388
5389 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5390 return FAIL;
5391
5392 switch (rot)
a737bd4d 5393 {
c19d1205
ZW
5394 case 0: *str = s; return 0x0;
5395 case 8: *str = s; return 0x1;
5396 case 16: *str = s; return 0x2;
5397 case 24: *str = s; return 0x3;
5398
5399 default:
5400 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5401 return FAIL;
5402 }
c19d1205 5403}
a737bd4d 5404
c19d1205
ZW
5405/* Parse a conditional code (from conds[] below). The value returned is in the
5406 range 0 .. 14, or FAIL. */
5407static int
5408parse_cond (char **str)
5409{
c462b453 5410 char *q;
c19d1205 5411 const struct asm_cond *c;
c462b453
PB
5412 int n;
5413 /* Condition codes are always 2 characters, so matching up to
5414 3 characters is sufficient. */
5415 char cond[3];
a737bd4d 5416
c462b453
PB
5417 q = *str;
5418 n = 0;
5419 while (ISALPHA (*q) && n < 3)
5420 {
e07e6e58 5421 cond[n] = TOLOWER (*q);
c462b453
PB
5422 q++;
5423 n++;
5424 }
a737bd4d 5425
21d799b5 5426 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5427 if (!c)
a737bd4d 5428 {
c19d1205 5429 inst.error = _("condition required");
a737bd4d
NC
5430 return FAIL;
5431 }
5432
c19d1205
ZW
5433 *str = q;
5434 return c->value;
5435}
5436
62b3e311
PB
5437/* Parse an option for a barrier instruction. Returns the encoding for the
5438 option, or FAIL. */
5439static int
5440parse_barrier (char **str)
5441{
5442 char *p, *q;
5443 const struct asm_barrier_opt *o;
5444
5445 p = q = *str;
5446 while (ISALPHA (*q))
5447 q++;
5448
21d799b5
NC
5449 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5450 q - p);
62b3e311
PB
5451 if (!o)
5452 return FAIL;
5453
5454 *str = q;
5455 return o->value;
5456}
5457
92e90b6e
PB
5458/* Parse the operands of a table branch instruction. Similar to a memory
5459 operand. */
5460static int
5461parse_tb (char **str)
5462{
5463 char * p = *str;
5464 int reg;
5465
5466 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5467 {
5468 inst.error = _("'[' expected");
5469 return FAIL;
5470 }
92e90b6e 5471
dcbf9037 5472 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5473 {
5474 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5475 return FAIL;
5476 }
5477 inst.operands[0].reg = reg;
5478
5479 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5480 {
5481 inst.error = _("',' expected");
5482 return FAIL;
5483 }
5f4273c7 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].imm = reg;
5491
5492 if (skip_past_comma (&p) == SUCCESS)
5493 {
5494 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5495 return FAIL;
5496 if (inst.reloc.exp.X_add_number != 1)
5497 {
5498 inst.error = _("invalid shift");
5499 return FAIL;
5500 }
5501 inst.operands[0].shifted = 1;
5502 }
5503
5504 if (skip_past_char (&p, ']') == FAIL)
5505 {
5506 inst.error = _("']' expected");
5507 return FAIL;
5508 }
5509 *str = p;
5510 return SUCCESS;
5511}
5512
5287ad62
JB
5513/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5514 information on the types the operands can take and how they are encoded.
037e8744
JB
5515 Up to four operands may be read; this function handles setting the
5516 ".present" field for each read operand itself.
5287ad62
JB
5517 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5518 else returns FAIL. */
5519
5520static int
5521parse_neon_mov (char **str, int *which_operand)
5522{
5523 int i = *which_operand, val;
5524 enum arm_reg_type rtype;
5525 char *ptr = *str;
dcbf9037 5526 struct neon_type_el optype;
5f4273c7 5527
dcbf9037 5528 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5529 {
5530 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5531 inst.operands[i].reg = val;
5532 inst.operands[i].isscalar = 1;
dcbf9037 5533 inst.operands[i].vectype = optype;
5287ad62
JB
5534 inst.operands[i++].present = 1;
5535
5536 if (skip_past_comma (&ptr) == FAIL)
5537 goto wanted_comma;
5f4273c7 5538
dcbf9037 5539 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5540 goto wanted_arm;
5f4273c7 5541
5287ad62
JB
5542 inst.operands[i].reg = val;
5543 inst.operands[i].isreg = 1;
5544 inst.operands[i].present = 1;
5545 }
037e8744 5546 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5547 != FAIL)
5287ad62
JB
5548 {
5549 /* Cases 0, 1, 2, 3, 5 (D only). */
5550 if (skip_past_comma (&ptr) == FAIL)
5551 goto wanted_comma;
5f4273c7 5552
5287ad62
JB
5553 inst.operands[i].reg = val;
5554 inst.operands[i].isreg = 1;
5555 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5556 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5557 inst.operands[i].isvec = 1;
dcbf9037 5558 inst.operands[i].vectype = optype;
5287ad62
JB
5559 inst.operands[i++].present = 1;
5560
dcbf9037 5561 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5562 {
037e8744
JB
5563 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5564 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5565 inst.operands[i].reg = val;
5566 inst.operands[i].isreg = 1;
037e8744 5567 inst.operands[i].present = 1;
5287ad62
JB
5568
5569 if (rtype == REG_TYPE_NQ)
5570 {
dcbf9037 5571 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5572 return FAIL;
5573 }
037e8744
JB
5574 else if (rtype != REG_TYPE_VFS)
5575 {
5576 i++;
5577 if (skip_past_comma (&ptr) == FAIL)
5578 goto wanted_comma;
5579 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5580 goto wanted_arm;
5581 inst.operands[i].reg = val;
5582 inst.operands[i].isreg = 1;
5583 inst.operands[i].present = 1;
5584 }
5287ad62 5585 }
037e8744
JB
5586 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5587 &optype)) != FAIL)
5287ad62
JB
5588 {
5589 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5590 Case 1: VMOV<c><q> <Dd>, <Dm>
5591 Case 8: VMOV.F32 <Sd>, <Sm>
5592 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5593
5594 inst.operands[i].reg = val;
5595 inst.operands[i].isreg = 1;
5596 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5597 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5598 inst.operands[i].isvec = 1;
dcbf9037 5599 inst.operands[i].vectype = optype;
5287ad62 5600 inst.operands[i].present = 1;
5f4273c7 5601
037e8744
JB
5602 if (skip_past_comma (&ptr) == SUCCESS)
5603 {
5604 /* Case 15. */
5605 i++;
5606
5607 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5608 goto wanted_arm;
5609
5610 inst.operands[i].reg = val;
5611 inst.operands[i].isreg = 1;
5612 inst.operands[i++].present = 1;
5f4273c7 5613
037e8744
JB
5614 if (skip_past_comma (&ptr) == FAIL)
5615 goto wanted_comma;
5f4273c7 5616
037e8744
JB
5617 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5618 goto wanted_arm;
5f4273c7 5619
037e8744
JB
5620 inst.operands[i].reg = val;
5621 inst.operands[i].isreg = 1;
5622 inst.operands[i++].present = 1;
5623 }
5287ad62 5624 }
4641781c
PB
5625 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5626 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5627 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5628 Case 10: VMOV.F32 <Sd>, #<imm>
5629 Case 11: VMOV.F64 <Dd>, #<imm> */
5630 inst.operands[i].immisfloat = 1;
5631 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5632 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5633 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5634 ;
5287ad62
JB
5635 else
5636 {
dcbf9037 5637 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5638 return FAIL;
5639 }
5640 }
dcbf9037 5641 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5642 {
5643 /* Cases 6, 7. */
5644 inst.operands[i].reg = val;
5645 inst.operands[i].isreg = 1;
5646 inst.operands[i++].present = 1;
5f4273c7 5647
5287ad62
JB
5648 if (skip_past_comma (&ptr) == FAIL)
5649 goto wanted_comma;
5f4273c7 5650
dcbf9037 5651 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5652 {
5653 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5654 inst.operands[i].reg = val;
5655 inst.operands[i].isscalar = 1;
5656 inst.operands[i].present = 1;
dcbf9037 5657 inst.operands[i].vectype = optype;
5287ad62 5658 }
dcbf9037 5659 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5660 {
5661 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5662 inst.operands[i].reg = val;
5663 inst.operands[i].isreg = 1;
5664 inst.operands[i++].present = 1;
5f4273c7 5665
5287ad62
JB
5666 if (skip_past_comma (&ptr) == FAIL)
5667 goto wanted_comma;
5f4273c7 5668
037e8744 5669 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5670 == FAIL)
5287ad62 5671 {
037e8744 5672 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5673 return FAIL;
5674 }
5675
5676 inst.operands[i].reg = val;
5677 inst.operands[i].isreg = 1;
037e8744
JB
5678 inst.operands[i].isvec = 1;
5679 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5680 inst.operands[i].vectype = optype;
5287ad62 5681 inst.operands[i].present = 1;
5f4273c7 5682
037e8744
JB
5683 if (rtype == REG_TYPE_VFS)
5684 {
5685 /* Case 14. */
5686 i++;
5687 if (skip_past_comma (&ptr) == FAIL)
5688 goto wanted_comma;
5689 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5690 &optype)) == FAIL)
5691 {
5692 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5693 return FAIL;
5694 }
5695 inst.operands[i].reg = val;
5696 inst.operands[i].isreg = 1;
5697 inst.operands[i].isvec = 1;
5698 inst.operands[i].issingle = 1;
5699 inst.operands[i].vectype = optype;
5700 inst.operands[i].present = 1;
5701 }
5702 }
5703 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5704 != FAIL)
5705 {
5706 /* Case 13. */
5707 inst.operands[i].reg = val;
5708 inst.operands[i].isreg = 1;
5709 inst.operands[i].isvec = 1;
5710 inst.operands[i].issingle = 1;
5711 inst.operands[i].vectype = optype;
5712 inst.operands[i++].present = 1;
5287ad62
JB
5713 }
5714 }
5715 else
5716 {
dcbf9037 5717 first_error (_("parse error"));
5287ad62
JB
5718 return FAIL;
5719 }
5720
5721 /* Successfully parsed the operands. Update args. */
5722 *which_operand = i;
5723 *str = ptr;
5724 return SUCCESS;
5725
5f4273c7 5726 wanted_comma:
dcbf9037 5727 first_error (_("expected comma"));
5287ad62 5728 return FAIL;
5f4273c7
NC
5729
5730 wanted_arm:
dcbf9037 5731 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5732 return FAIL;
5287ad62
JB
5733}
5734
5be8be5d
DG
5735/* Use this macro when the operand constraints are different
5736 for ARM and THUMB (e.g. ldrd). */
5737#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5738 ((arm_operand) | ((thumb_operand) << 16))
5739
c19d1205
ZW
5740/* Matcher codes for parse_operands. */
5741enum operand_parse_code
5742{
5743 OP_stop, /* end of line */
5744
5745 OP_RR, /* ARM register */
5746 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 5747 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205
ZW
5748 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5749 OP_RRw, /* ARM register, not r15, optional trailing ! */
5750 OP_RCP, /* Coprocessor number */
5751 OP_RCN, /* Coprocessor register */
5752 OP_RF, /* FPA register */
5753 OP_RVS, /* VFP single precision register */
5287ad62
JB
5754 OP_RVD, /* VFP double precision register (0..15) */
5755 OP_RND, /* Neon double precision register (0..31) */
5756 OP_RNQ, /* Neon quad precision register */
037e8744 5757 OP_RVSD, /* VFP single or double precision register */
5287ad62 5758 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5759 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5760 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5761 OP_RVC, /* VFP control register */
5762 OP_RMF, /* Maverick F register */
5763 OP_RMD, /* Maverick D register */
5764 OP_RMFX, /* Maverick FX register */
5765 OP_RMDX, /* Maverick DX register */
5766 OP_RMAX, /* Maverick AX register */
5767 OP_RMDS, /* Maverick DSPSC register */
5768 OP_RIWR, /* iWMMXt wR register */
5769 OP_RIWC, /* iWMMXt wC register */
5770 OP_RIWG, /* iWMMXt wCG register */
5771 OP_RXA, /* XScale accumulator register */
5772
5773 OP_REGLST, /* ARM register list */
5774 OP_VRSLST, /* VFP single-precision register list */
5775 OP_VRDLST, /* VFP double-precision register list */
037e8744 5776 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5777 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5778 OP_NSTRLST, /* Neon element/structure list */
5779
5287ad62 5780 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5781 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5782 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5783 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5784 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5785 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5786 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 5787 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 5788 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5789 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5790
5791 OP_I0, /* immediate zero */
c19d1205
ZW
5792 OP_I7, /* immediate value 0 .. 7 */
5793 OP_I15, /* 0 .. 15 */
5794 OP_I16, /* 1 .. 16 */
5287ad62 5795 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5796 OP_I31, /* 0 .. 31 */
5797 OP_I31w, /* 0 .. 31, optional trailing ! */
5798 OP_I32, /* 1 .. 32 */
5287ad62
JB
5799 OP_I32z, /* 0 .. 32 */
5800 OP_I63, /* 0 .. 63 */
c19d1205 5801 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5802 OP_I64, /* 1 .. 64 */
5803 OP_I64z, /* 0 .. 64 */
c19d1205 5804 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5805
5806 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5807 OP_I7b, /* 0 .. 7 */
5808 OP_I15b, /* 0 .. 15 */
5809 OP_I31b, /* 0 .. 31 */
5810
5811 OP_SH, /* shifter operand */
4962c51a 5812 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5813 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5814 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5815 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5816 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5817 OP_EXP, /* arbitrary expression */
5818 OP_EXPi, /* same, with optional immediate prefix */
5819 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5820 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5821
5822 OP_CPSF, /* CPS flags */
5823 OP_ENDI, /* Endianness specifier */
5824 OP_PSR, /* CPSR/SPSR mask for msr */
5825 OP_COND, /* conditional code */
92e90b6e 5826 OP_TB, /* Table branch. */
c19d1205 5827
037e8744
JB
5828 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5829 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5830
c19d1205
ZW
5831 OP_RRnpc_I0, /* ARM register or literal 0 */
5832 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5833 OP_RR_EXi, /* ARM register or expression with imm prefix */
5834 OP_RF_IF, /* FPA register or immediate */
5835 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5836 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5837
5838 /* Optional operands. */
5839 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5840 OP_oI31b, /* 0 .. 31 */
5287ad62 5841 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5842 OP_oIffffb, /* 0 .. 65535 */
5843 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5844
5845 OP_oRR, /* ARM register */
5846 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 5847 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 5848 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5849 OP_oRND, /* Optional Neon double precision register */
5850 OP_oRNQ, /* Optional Neon quad precision register */
5851 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5852 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5853 OP_oSHll, /* LSL immediate */
5854 OP_oSHar, /* ASR immediate */
5855 OP_oSHllar, /* LSL or ASR immediate */
5856 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5857 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205 5858
5be8be5d
DG
5859 /* Some pre-defined mixed (ARM/THUMB) operands. */
5860 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5861 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5862 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5863
c19d1205
ZW
5864 OP_FIRST_OPTIONAL = OP_oI7b
5865};
a737bd4d 5866
c19d1205
ZW
5867/* Generic instruction operand parser. This does no encoding and no
5868 semantic validation; it merely squirrels values away in the inst
5869 structure. Returns SUCCESS or FAIL depending on whether the
5870 specified grammar matched. */
5871static int
5be8be5d 5872parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 5873{
5be8be5d 5874 unsigned const int *upat = pattern;
c19d1205
ZW
5875 char *backtrack_pos = 0;
5876 const char *backtrack_error = 0;
5877 int i, val, backtrack_index = 0;
5287ad62 5878 enum arm_reg_type rtype;
4962c51a 5879 parse_operand_result result;
5be8be5d 5880 unsigned int op_parse_code;
c19d1205 5881
e07e6e58
NC
5882#define po_char_or_fail(chr) \
5883 do \
5884 { \
5885 if (skip_past_char (&str, chr) == FAIL) \
5886 goto bad_args; \
5887 } \
5888 while (0)
c19d1205 5889
e07e6e58
NC
5890#define po_reg_or_fail(regtype) \
5891 do \
dcbf9037 5892 { \
e07e6e58
NC
5893 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5894 & inst.operands[i].vectype); \
5895 if (val == FAIL) \
5896 { \
5897 first_error (_(reg_expected_msgs[regtype])); \
5898 goto failure; \
5899 } \
5900 inst.operands[i].reg = val; \
5901 inst.operands[i].isreg = 1; \
5902 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5903 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5904 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5905 || rtype == REG_TYPE_VFD \
5906 || rtype == REG_TYPE_NQ); \
dcbf9037 5907 } \
e07e6e58
NC
5908 while (0)
5909
5910#define po_reg_or_goto(regtype, label) \
5911 do \
5912 { \
5913 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5914 & inst.operands[i].vectype); \
5915 if (val == FAIL) \
5916 goto label; \
dcbf9037 5917 \
e07e6e58
NC
5918 inst.operands[i].reg = val; \
5919 inst.operands[i].isreg = 1; \
5920 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5921 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5922 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5923 || rtype == REG_TYPE_VFD \
5924 || rtype == REG_TYPE_NQ); \
5925 } \
5926 while (0)
5927
5928#define po_imm_or_fail(min, max, popt) \
5929 do \
5930 { \
5931 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5932 goto failure; \
5933 inst.operands[i].imm = val; \
5934 } \
5935 while (0)
5936
5937#define po_scalar_or_goto(elsz, label) \
5938 do \
5939 { \
5940 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5941 if (val == FAIL) \
5942 goto label; \
5943 inst.operands[i].reg = val; \
5944 inst.operands[i].isscalar = 1; \
5945 } \
5946 while (0)
5947
5948#define po_misc_or_fail(expr) \
5949 do \
5950 { \
5951 if (expr) \
5952 goto failure; \
5953 } \
5954 while (0)
5955
5956#define po_misc_or_fail_no_backtrack(expr) \
5957 do \
5958 { \
5959 result = expr; \
5960 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5961 backtrack_pos = 0; \
5962 if (result != PARSE_OPERAND_SUCCESS) \
5963 goto failure; \
5964 } \
5965 while (0)
4962c51a 5966
c19d1205
ZW
5967 skip_whitespace (str);
5968
5969 for (i = 0; upat[i] != OP_stop; i++)
5970 {
5be8be5d
DG
5971 op_parse_code = upat[i];
5972 if (op_parse_code >= 1<<16)
5973 op_parse_code = thumb ? (op_parse_code >> 16)
5974 : (op_parse_code & ((1<<16)-1));
5975
5976 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
5977 {
5978 /* Remember where we are in case we need to backtrack. */
9c2799c2 5979 gas_assert (!backtrack_pos);
c19d1205
ZW
5980 backtrack_pos = str;
5981 backtrack_error = inst.error;
5982 backtrack_index = i;
5983 }
5984
b6702015 5985 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5986 po_char_or_fail (',');
5987
5be8be5d 5988 switch (op_parse_code)
c19d1205
ZW
5989 {
5990 /* Registers */
5991 case OP_oRRnpc:
5be8be5d 5992 case OP_oRRnpcsp:
c19d1205 5993 case OP_RRnpc:
5be8be5d 5994 case OP_RRnpcsp:
c19d1205
ZW
5995 case OP_oRR:
5996 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5997 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5998 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5999 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6000 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6001 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
6002 case OP_oRND:
6003 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6004 case OP_RVC:
6005 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6006 break;
6007 /* Also accept generic coprocessor regs for unknown registers. */
6008 coproc_reg:
6009 po_reg_or_fail (REG_TYPE_CN);
6010 break;
c19d1205
ZW
6011 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6012 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6013 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6014 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6015 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6016 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6017 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6018 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6019 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6020 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
6021 case OP_oRNQ:
6022 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6023 case OP_oRNDQ:
6024 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6025 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6026 case OP_oRNSDQ:
6027 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6028
6029 /* Neon scalar. Using an element size of 8 means that some invalid
6030 scalars are accepted here, so deal with those in later code. */
6031 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6032
5287ad62
JB
6033 case OP_RNDQ_I0:
6034 {
6035 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6036 break;
6037 try_imm0:
6038 po_imm_or_fail (0, 0, TRUE);
6039 }
6040 break;
6041
037e8744
JB
6042 case OP_RVSD_I0:
6043 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6044 break;
6045
5287ad62
JB
6046 case OP_RR_RNSC:
6047 {
6048 po_scalar_or_goto (8, try_rr);
6049 break;
6050 try_rr:
6051 po_reg_or_fail (REG_TYPE_RN);
6052 }
6053 break;
6054
037e8744
JB
6055 case OP_RNSDQ_RNSC:
6056 {
6057 po_scalar_or_goto (8, try_nsdq);
6058 break;
6059 try_nsdq:
6060 po_reg_or_fail (REG_TYPE_NSDQ);
6061 }
6062 break;
6063
5287ad62
JB
6064 case OP_RNDQ_RNSC:
6065 {
6066 po_scalar_or_goto (8, try_ndq);
6067 break;
6068 try_ndq:
6069 po_reg_or_fail (REG_TYPE_NDQ);
6070 }
6071 break;
6072
6073 case OP_RND_RNSC:
6074 {
6075 po_scalar_or_goto (8, try_vfd);
6076 break;
6077 try_vfd:
6078 po_reg_or_fail (REG_TYPE_VFD);
6079 }
6080 break;
6081
6082 case OP_VMOV:
6083 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6084 not careful then bad things might happen. */
6085 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6086 break;
6087
4316f0d2 6088 case OP_RNDQ_Ibig:
5287ad62 6089 {
4316f0d2 6090 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
5287ad62 6091 break;
4316f0d2 6092 try_immbig:
5287ad62
JB
6093 /* There's a possibility of getting a 64-bit immediate here, so
6094 we need special handling. */
6095 if (parse_big_immediate (&str, i) == FAIL)
6096 {
6097 inst.error = _("immediate value is out of range");
6098 goto failure;
6099 }
6100 }
6101 break;
6102
6103 case OP_RNDQ_I63b:
6104 {
6105 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6106 break;
6107 try_shimm:
6108 po_imm_or_fail (0, 63, TRUE);
6109 }
6110 break;
c19d1205
ZW
6111
6112 case OP_RRnpcb:
6113 po_char_or_fail ('[');
6114 po_reg_or_fail (REG_TYPE_RN);
6115 po_char_or_fail (']');
6116 break;
a737bd4d 6117
c19d1205 6118 case OP_RRw:
b6702015 6119 case OP_oRRw:
c19d1205
ZW
6120 po_reg_or_fail (REG_TYPE_RN);
6121 if (skip_past_char (&str, '!') == SUCCESS)
6122 inst.operands[i].writeback = 1;
6123 break;
6124
6125 /* Immediates */
6126 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6127 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6128 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6129 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6130 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6131 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6132 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6133 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6134 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6135 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6136 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6137 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6138
6139 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6140 case OP_oI7b:
6141 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6142 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6143 case OP_oI31b:
6144 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6145 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6146 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6147
6148 /* Immediate variants */
6149 case OP_oI255c:
6150 po_char_or_fail ('{');
6151 po_imm_or_fail (0, 255, TRUE);
6152 po_char_or_fail ('}');
6153 break;
6154
6155 case OP_I31w:
6156 /* The expression parser chokes on a trailing !, so we have
6157 to find it first and zap it. */
6158 {
6159 char *s = str;
6160 while (*s && *s != ',')
6161 s++;
6162 if (s[-1] == '!')
6163 {
6164 s[-1] = '\0';
6165 inst.operands[i].writeback = 1;
6166 }
6167 po_imm_or_fail (0, 31, TRUE);
6168 if (str == s - 1)
6169 str = s;
6170 }
6171 break;
6172
6173 /* Expressions */
6174 case OP_EXPi: EXPi:
6175 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6176 GE_OPT_PREFIX));
6177 break;
6178
6179 case OP_EXP:
6180 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6181 GE_NO_PREFIX));
6182 break;
6183
6184 case OP_EXPr: EXPr:
6185 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6186 GE_NO_PREFIX));
6187 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6188 {
c19d1205
ZW
6189 val = parse_reloc (&str);
6190 if (val == -1)
6191 {
6192 inst.error = _("unrecognized relocation suffix");
6193 goto failure;
6194 }
6195 else if (val != BFD_RELOC_UNUSED)
6196 {
6197 inst.operands[i].imm = val;
6198 inst.operands[i].hasreloc = 1;
6199 }
a737bd4d 6200 }
c19d1205 6201 break;
a737bd4d 6202
b6895b4f
PB
6203 /* Operand for MOVW or MOVT. */
6204 case OP_HALF:
6205 po_misc_or_fail (parse_half (&str));
6206 break;
6207
e07e6e58 6208 /* Register or expression. */
c19d1205
ZW
6209 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6210 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6211
e07e6e58 6212 /* Register or immediate. */
c19d1205
ZW
6213 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6214 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6215
c19d1205
ZW
6216 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6217 IF:
6218 if (!is_immediate_prefix (*str))
6219 goto bad_args;
6220 str++;
6221 val = parse_fpa_immediate (&str);
6222 if (val == FAIL)
6223 goto failure;
6224 /* FPA immediates are encoded as registers 8-15.
6225 parse_fpa_immediate has already applied the offset. */
6226 inst.operands[i].reg = val;
6227 inst.operands[i].isreg = 1;
6228 break;
09d92015 6229
2d447fca
JM
6230 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6231 I32z: po_imm_or_fail (0, 32, FALSE); break;
6232
e07e6e58 6233 /* Two kinds of register. */
c19d1205
ZW
6234 case OP_RIWR_RIWC:
6235 {
6236 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6237 if (!rege
6238 || (rege->type != REG_TYPE_MMXWR
6239 && rege->type != REG_TYPE_MMXWC
6240 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6241 {
6242 inst.error = _("iWMMXt data or control register expected");
6243 goto failure;
6244 }
6245 inst.operands[i].reg = rege->number;
6246 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6247 }
6248 break;
09d92015 6249
41adaa5c
JM
6250 case OP_RIWC_RIWG:
6251 {
6252 struct reg_entry *rege = arm_reg_parse_multi (&str);
6253 if (!rege
6254 || (rege->type != REG_TYPE_MMXWC
6255 && rege->type != REG_TYPE_MMXWCG))
6256 {
6257 inst.error = _("iWMMXt control register expected");
6258 goto failure;
6259 }
6260 inst.operands[i].reg = rege->number;
6261 inst.operands[i].isreg = 1;
6262 }
6263 break;
6264
c19d1205
ZW
6265 /* Misc */
6266 case OP_CPSF: val = parse_cps_flags (&str); break;
6267 case OP_ENDI: val = parse_endian_specifier (&str); break;
6268 case OP_oROR: val = parse_ror (&str); break;
6269 case OP_PSR: val = parse_psr (&str); break;
6270 case OP_COND: val = parse_cond (&str); break;
62b3e311 6271 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6272
037e8744
JB
6273 case OP_RVC_PSR:
6274 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6275 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6276 break;
6277 try_psr:
6278 val = parse_psr (&str);
6279 break;
6280
6281 case OP_APSR_RR:
6282 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6283 break;
6284 try_apsr:
6285 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6286 instruction). */
6287 if (strncasecmp (str, "APSR_", 5) == 0)
6288 {
6289 unsigned found = 0;
6290 str += 5;
6291 while (found < 15)
6292 switch (*str++)
6293 {
6294 case 'c': found = (found & 1) ? 16 : found | 1; break;
6295 case 'n': found = (found & 2) ? 16 : found | 2; break;
6296 case 'z': found = (found & 4) ? 16 : found | 4; break;
6297 case 'v': found = (found & 8) ? 16 : found | 8; break;
6298 default: found = 16;
6299 }
6300 if (found != 15)
6301 goto failure;
6302 inst.operands[i].isvec = 1;
f7c21dc7
NC
6303 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6304 inst.operands[i].reg = REG_PC;
037e8744
JB
6305 }
6306 else
6307 goto failure;
6308 break;
6309
92e90b6e
PB
6310 case OP_TB:
6311 po_misc_or_fail (parse_tb (&str));
6312 break;
6313
e07e6e58 6314 /* Register lists. */
c19d1205
ZW
6315 case OP_REGLST:
6316 val = parse_reg_list (&str);
6317 if (*str == '^')
6318 {
6319 inst.operands[1].writeback = 1;
6320 str++;
6321 }
6322 break;
09d92015 6323
c19d1205 6324 case OP_VRSLST:
5287ad62 6325 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6326 break;
09d92015 6327
c19d1205 6328 case OP_VRDLST:
5287ad62 6329 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6330 break;
a737bd4d 6331
037e8744
JB
6332 case OP_VRSDLST:
6333 /* Allow Q registers too. */
6334 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6335 REGLIST_NEON_D);
6336 if (val == FAIL)
6337 {
6338 inst.error = NULL;
6339 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6340 REGLIST_VFP_S);
6341 inst.operands[i].issingle = 1;
6342 }
6343 break;
6344
5287ad62
JB
6345 case OP_NRDLST:
6346 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6347 REGLIST_NEON_D);
6348 break;
6349
6350 case OP_NSTRLST:
dcbf9037
JB
6351 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6352 &inst.operands[i].vectype);
5287ad62
JB
6353 break;
6354
c19d1205
ZW
6355 /* Addressing modes */
6356 case OP_ADDR:
6357 po_misc_or_fail (parse_address (&str, i));
6358 break;
09d92015 6359
4962c51a
MS
6360 case OP_ADDRGLDR:
6361 po_misc_or_fail_no_backtrack (
6362 parse_address_group_reloc (&str, i, GROUP_LDR));
6363 break;
6364
6365 case OP_ADDRGLDRS:
6366 po_misc_or_fail_no_backtrack (
6367 parse_address_group_reloc (&str, i, GROUP_LDRS));
6368 break;
6369
6370 case OP_ADDRGLDC:
6371 po_misc_or_fail_no_backtrack (
6372 parse_address_group_reloc (&str, i, GROUP_LDC));
6373 break;
6374
c19d1205
ZW
6375 case OP_SH:
6376 po_misc_or_fail (parse_shifter_operand (&str, i));
6377 break;
09d92015 6378
4962c51a
MS
6379 case OP_SHG:
6380 po_misc_or_fail_no_backtrack (
6381 parse_shifter_operand_group_reloc (&str, i));
6382 break;
6383
c19d1205
ZW
6384 case OP_oSHll:
6385 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6386 break;
09d92015 6387
c19d1205
ZW
6388 case OP_oSHar:
6389 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6390 break;
09d92015 6391
c19d1205
ZW
6392 case OP_oSHllar:
6393 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6394 break;
09d92015 6395
c19d1205 6396 default:
5be8be5d 6397 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 6398 }
09d92015 6399
c19d1205
ZW
6400 /* Various value-based sanity checks and shared operations. We
6401 do not signal immediate failures for the register constraints;
6402 this allows a syntax error to take precedence. */
5be8be5d 6403 switch (op_parse_code)
c19d1205
ZW
6404 {
6405 case OP_oRRnpc:
6406 case OP_RRnpc:
6407 case OP_RRnpcb:
6408 case OP_RRw:
b6702015 6409 case OP_oRRw:
c19d1205
ZW
6410 case OP_RRnpc_I0:
6411 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6412 inst.error = BAD_PC;
6413 break;
09d92015 6414
5be8be5d
DG
6415 case OP_oRRnpcsp:
6416 case OP_RRnpcsp:
6417 if (inst.operands[i].isreg)
6418 {
6419 if (inst.operands[i].reg == REG_PC)
6420 inst.error = BAD_PC;
6421 else if (inst.operands[i].reg == REG_SP)
6422 inst.error = BAD_SP;
6423 }
6424 break;
6425
c19d1205
ZW
6426 case OP_CPSF:
6427 case OP_ENDI:
6428 case OP_oROR:
6429 case OP_PSR:
037e8744 6430 case OP_RVC_PSR:
c19d1205 6431 case OP_COND:
62b3e311 6432 case OP_oBARRIER:
c19d1205
ZW
6433 case OP_REGLST:
6434 case OP_VRSLST:
6435 case OP_VRDLST:
037e8744 6436 case OP_VRSDLST:
5287ad62
JB
6437 case OP_NRDLST:
6438 case OP_NSTRLST:
c19d1205
ZW
6439 if (val == FAIL)
6440 goto failure;
6441 inst.operands[i].imm = val;
6442 break;
a737bd4d 6443
c19d1205
ZW
6444 default:
6445 break;
6446 }
09d92015 6447
c19d1205
ZW
6448 /* If we get here, this operand was successfully parsed. */
6449 inst.operands[i].present = 1;
6450 continue;
09d92015 6451
c19d1205 6452 bad_args:
09d92015 6453 inst.error = BAD_ARGS;
c19d1205
ZW
6454
6455 failure:
6456 if (!backtrack_pos)
d252fdde
PB
6457 {
6458 /* The parse routine should already have set inst.error, but set a
5f4273c7 6459 default here just in case. */
d252fdde
PB
6460 if (!inst.error)
6461 inst.error = _("syntax error");
6462 return FAIL;
6463 }
c19d1205
ZW
6464
6465 /* Do not backtrack over a trailing optional argument that
6466 absorbed some text. We will only fail again, with the
6467 'garbage following instruction' error message, which is
6468 probably less helpful than the current one. */
6469 if (backtrack_index == i && backtrack_pos != str
6470 && upat[i+1] == OP_stop)
d252fdde
PB
6471 {
6472 if (!inst.error)
6473 inst.error = _("syntax error");
6474 return FAIL;
6475 }
c19d1205
ZW
6476
6477 /* Try again, skipping the optional argument at backtrack_pos. */
6478 str = backtrack_pos;
6479 inst.error = backtrack_error;
6480 inst.operands[backtrack_index].present = 0;
6481 i = backtrack_index;
6482 backtrack_pos = 0;
09d92015 6483 }
09d92015 6484
c19d1205
ZW
6485 /* Check that we have parsed all the arguments. */
6486 if (*str != '\0' && !inst.error)
6487 inst.error = _("garbage following instruction");
09d92015 6488
c19d1205 6489 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6490}
6491
c19d1205
ZW
6492#undef po_char_or_fail
6493#undef po_reg_or_fail
6494#undef po_reg_or_goto
6495#undef po_imm_or_fail
5287ad62 6496#undef po_scalar_or_fail
e07e6e58 6497
c19d1205 6498/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6499#define constraint(expr, err) \
6500 do \
c19d1205 6501 { \
e07e6e58
NC
6502 if (expr) \
6503 { \
6504 inst.error = err; \
6505 return; \
6506 } \
c19d1205 6507 } \
e07e6e58 6508 while (0)
c19d1205 6509
fdfde340
JM
6510/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6511 instructions are unpredictable if these registers are used. This
6512 is the BadReg predicate in ARM's Thumb-2 documentation. */
6513#define reject_bad_reg(reg) \
6514 do \
6515 if (reg == REG_SP || reg == REG_PC) \
6516 { \
6517 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6518 return; \
6519 } \
6520 while (0)
6521
94206790
MM
6522/* If REG is R13 (the stack pointer), warn that its use is
6523 deprecated. */
6524#define warn_deprecated_sp(reg) \
6525 do \
6526 if (warn_on_deprecated && reg == REG_SP) \
6527 as_warn (_("use of r13 is deprecated")); \
6528 while (0)
6529
c19d1205
ZW
6530/* Functions for operand encoding. ARM, then Thumb. */
6531
6532#define rotate_left(v, n) (v << n | v >> (32 - n))
6533
6534/* If VAL can be encoded in the immediate field of an ARM instruction,
6535 return the encoded form. Otherwise, return FAIL. */
6536
6537static unsigned int
6538encode_arm_immediate (unsigned int val)
09d92015 6539{
c19d1205
ZW
6540 unsigned int a, i;
6541
6542 for (i = 0; i < 32; i += 2)
6543 if ((a = rotate_left (val, i)) <= 0xff)
6544 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6545
6546 return FAIL;
09d92015
MM
6547}
6548
c19d1205
ZW
6549/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6550 return the encoded form. Otherwise, return FAIL. */
6551static unsigned int
6552encode_thumb32_immediate (unsigned int val)
09d92015 6553{
c19d1205 6554 unsigned int a, i;
09d92015 6555
9c3c69f2 6556 if (val <= 0xff)
c19d1205 6557 return val;
a737bd4d 6558
9c3c69f2 6559 for (i = 1; i <= 24; i++)
09d92015 6560 {
9c3c69f2
PB
6561 a = val >> i;
6562 if ((val & ~(0xff << i)) == 0)
6563 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6564 }
a737bd4d 6565
c19d1205
ZW
6566 a = val & 0xff;
6567 if (val == ((a << 16) | a))
6568 return 0x100 | a;
6569 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6570 return 0x300 | a;
09d92015 6571
c19d1205
ZW
6572 a = val & 0xff00;
6573 if (val == ((a << 16) | a))
6574 return 0x200 | (a >> 8);
a737bd4d 6575
c19d1205 6576 return FAIL;
09d92015 6577}
5287ad62 6578/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6579
6580static void
5287ad62
JB
6581encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6582{
6583 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6584 && reg > 15)
6585 {
b1cc4aeb 6586 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6587 {
6588 if (thumb_mode)
6589 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6590 fpu_vfp_ext_d32);
5287ad62
JB
6591 else
6592 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6593 fpu_vfp_ext_d32);
5287ad62
JB
6594 }
6595 else
6596 {
dcbf9037 6597 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6598 return;
6599 }
6600 }
6601
c19d1205 6602 switch (pos)
09d92015 6603 {
c19d1205
ZW
6604 case VFP_REG_Sd:
6605 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6606 break;
6607
6608 case VFP_REG_Sn:
6609 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6610 break;
6611
6612 case VFP_REG_Sm:
6613 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6614 break;
6615
5287ad62
JB
6616 case VFP_REG_Dd:
6617 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6618 break;
5f4273c7 6619
5287ad62
JB
6620 case VFP_REG_Dn:
6621 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6622 break;
5f4273c7 6623
5287ad62
JB
6624 case VFP_REG_Dm:
6625 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6626 break;
6627
c19d1205
ZW
6628 default:
6629 abort ();
09d92015 6630 }
09d92015
MM
6631}
6632
c19d1205 6633/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6634 if any, is handled by md_apply_fix. */
09d92015 6635static void
c19d1205 6636encode_arm_shift (int i)
09d92015 6637{
c19d1205
ZW
6638 if (inst.operands[i].shift_kind == SHIFT_RRX)
6639 inst.instruction |= SHIFT_ROR << 5;
6640 else
09d92015 6641 {
c19d1205
ZW
6642 inst.instruction |= inst.operands[i].shift_kind << 5;
6643 if (inst.operands[i].immisreg)
6644 {
6645 inst.instruction |= SHIFT_BY_REG;
6646 inst.instruction |= inst.operands[i].imm << 8;
6647 }
6648 else
6649 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6650 }
c19d1205 6651}
09d92015 6652
c19d1205
ZW
6653static void
6654encode_arm_shifter_operand (int i)
6655{
6656 if (inst.operands[i].isreg)
09d92015 6657 {
c19d1205
ZW
6658 inst.instruction |= inst.operands[i].reg;
6659 encode_arm_shift (i);
09d92015 6660 }
c19d1205
ZW
6661 else
6662 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6663}
6664
c19d1205 6665/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6666static void
c19d1205 6667encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6668{
9c2799c2 6669 gas_assert (inst.operands[i].isreg);
c19d1205 6670 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6671
c19d1205 6672 if (inst.operands[i].preind)
09d92015 6673 {
c19d1205
ZW
6674 if (is_t)
6675 {
6676 inst.error = _("instruction does not accept preindexed addressing");
6677 return;
6678 }
6679 inst.instruction |= PRE_INDEX;
6680 if (inst.operands[i].writeback)
6681 inst.instruction |= WRITE_BACK;
09d92015 6682
c19d1205
ZW
6683 }
6684 else if (inst.operands[i].postind)
6685 {
9c2799c2 6686 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6687 if (is_t)
6688 inst.instruction |= WRITE_BACK;
6689 }
6690 else /* unindexed - only for coprocessor */
09d92015 6691 {
c19d1205 6692 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6693 return;
6694 }
6695
c19d1205
ZW
6696 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6697 && (((inst.instruction & 0x000f0000) >> 16)
6698 == ((inst.instruction & 0x0000f000) >> 12)))
6699 as_warn ((inst.instruction & LOAD_BIT)
6700 ? _("destination register same as write-back base")
6701 : _("source register same as write-back base"));
09d92015
MM
6702}
6703
c19d1205
ZW
6704/* inst.operands[i] was set up by parse_address. Encode it into an
6705 ARM-format mode 2 load or store instruction. If is_t is true,
6706 reject forms that cannot be used with a T instruction (i.e. not
6707 post-indexed). */
a737bd4d 6708static void
c19d1205 6709encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6710{
5be8be5d
DG
6711 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6712
c19d1205 6713 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6714
c19d1205 6715 if (inst.operands[i].immisreg)
09d92015 6716 {
5be8be5d
DG
6717 constraint ((inst.operands[i].imm == REG_PC
6718 || (is_pc && inst.operands[i].writeback)),
6719 BAD_PC_ADDRESSING);
c19d1205
ZW
6720 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6721 inst.instruction |= inst.operands[i].imm;
6722 if (!inst.operands[i].negative)
6723 inst.instruction |= INDEX_UP;
6724 if (inst.operands[i].shifted)
6725 {
6726 if (inst.operands[i].shift_kind == SHIFT_RRX)
6727 inst.instruction |= SHIFT_ROR << 5;
6728 else
6729 {
6730 inst.instruction |= inst.operands[i].shift_kind << 5;
6731 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6732 }
6733 }
09d92015 6734 }
c19d1205 6735 else /* immediate offset in inst.reloc */
09d92015 6736 {
5be8be5d
DG
6737 if (is_pc && !inst.reloc.pc_rel)
6738 {
6739 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6740 /* BAD_PC_ADDRESSING Condition =
6741 is_load => is_t
6742 which becomes !is_load || is_t. */
6743 constraint ((!is_load || is_t),
6744 BAD_PC_ADDRESSING);
6745 }
6746
c19d1205
ZW
6747 if (inst.reloc.type == BFD_RELOC_UNUSED)
6748 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6749 }
09d92015
MM
6750}
6751
c19d1205
ZW
6752/* inst.operands[i] was set up by parse_address. Encode it into an
6753 ARM-format mode 3 load or store instruction. Reject forms that
6754 cannot be used with such instructions. If is_t is true, reject
6755 forms that cannot be used with a T instruction (i.e. not
6756 post-indexed). */
6757static void
6758encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6759{
c19d1205 6760 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6761 {
c19d1205
ZW
6762 inst.error = _("instruction does not accept scaled register index");
6763 return;
09d92015 6764 }
a737bd4d 6765
c19d1205 6766 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6767
c19d1205
ZW
6768 if (inst.operands[i].immisreg)
6769 {
5be8be5d
DG
6770 constraint ((inst.operands[i].imm == REG_PC
6771 || inst.operands[i].reg == REG_PC),
6772 BAD_PC_ADDRESSING);
c19d1205
ZW
6773 inst.instruction |= inst.operands[i].imm;
6774 if (!inst.operands[i].negative)
6775 inst.instruction |= INDEX_UP;
6776 }
6777 else /* immediate offset in inst.reloc */
6778 {
5be8be5d
DG
6779 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6780 && inst.operands[i].writeback),
6781 BAD_PC_WRITEBACK);
c19d1205
ZW
6782 inst.instruction |= HWOFFSET_IMM;
6783 if (inst.reloc.type == BFD_RELOC_UNUSED)
6784 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6785 }
a737bd4d
NC
6786}
6787
c19d1205
ZW
6788/* inst.operands[i] was set up by parse_address. Encode it into an
6789 ARM-format instruction. Reject all forms which cannot be encoded
6790 into a coprocessor load/store instruction. If wb_ok is false,
6791 reject use of writeback; if unind_ok is false, reject use of
6792 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6793 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6794 (in which case it is preserved). */
09d92015 6795
c19d1205
ZW
6796static int
6797encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6798{
c19d1205 6799 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6800
9c2799c2 6801 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6802
c19d1205 6803 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6804 {
9c2799c2 6805 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6806 if (!unind_ok)
6807 {
6808 inst.error = _("instruction does not support unindexed addressing");
6809 return FAIL;
6810 }
6811 inst.instruction |= inst.operands[i].imm;
6812 inst.instruction |= INDEX_UP;
6813 return SUCCESS;
09d92015 6814 }
a737bd4d 6815
c19d1205
ZW
6816 if (inst.operands[i].preind)
6817 inst.instruction |= PRE_INDEX;
a737bd4d 6818
c19d1205 6819 if (inst.operands[i].writeback)
09d92015 6820 {
c19d1205
ZW
6821 if (inst.operands[i].reg == REG_PC)
6822 {
6823 inst.error = _("pc may not be used with write-back");
6824 return FAIL;
6825 }
6826 if (!wb_ok)
6827 {
6828 inst.error = _("instruction does not support writeback");
6829 return FAIL;
6830 }
6831 inst.instruction |= WRITE_BACK;
09d92015 6832 }
a737bd4d 6833
c19d1205 6834 if (reloc_override)
21d799b5 6835 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6836 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6837 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6838 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6839 {
6840 if (thumb_mode)
6841 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6842 else
6843 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6844 }
6845
c19d1205
ZW
6846 return SUCCESS;
6847}
a737bd4d 6848
c19d1205
ZW
6849/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6850 Determine whether it can be performed with a move instruction; if
6851 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6852 return TRUE; if it can't, convert inst.instruction to a literal-pool
6853 load and return FALSE. If this is not a valid thing to do in the
6854 current context, set inst.error and return TRUE.
a737bd4d 6855
c19d1205
ZW
6856 inst.operands[i] describes the destination register. */
6857
c921be7d 6858static bfd_boolean
c19d1205
ZW
6859move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6860{
53365c0d
PB
6861 unsigned long tbit;
6862
6863 if (thumb_p)
6864 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6865 else
6866 tbit = LOAD_BIT;
6867
6868 if ((inst.instruction & tbit) == 0)
09d92015 6869 {
c19d1205 6870 inst.error = _("invalid pseudo operation");
c921be7d 6871 return TRUE;
09d92015 6872 }
c19d1205 6873 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6874 {
6875 inst.error = _("constant expression expected");
c921be7d 6876 return TRUE;
09d92015 6877 }
c19d1205 6878 if (inst.reloc.exp.X_op == O_constant)
09d92015 6879 {
c19d1205
ZW
6880 if (thumb_p)
6881 {
53365c0d 6882 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6883 {
6884 /* This can be done with a mov(1) instruction. */
6885 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6886 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 6887 return TRUE;
c19d1205
ZW
6888 }
6889 }
6890 else
6891 {
6892 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6893 if (value != FAIL)
6894 {
6895 /* This can be done with a mov instruction. */
6896 inst.instruction &= LITERAL_MASK;
6897 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6898 inst.instruction |= value & 0xfff;
c921be7d 6899 return TRUE;
c19d1205 6900 }
09d92015 6901
c19d1205
ZW
6902 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6903 if (value != FAIL)
6904 {
6905 /* This can be done with a mvn instruction. */
6906 inst.instruction &= LITERAL_MASK;
6907 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6908 inst.instruction |= value & 0xfff;
c921be7d 6909 return TRUE;
c19d1205
ZW
6910 }
6911 }
09d92015
MM
6912 }
6913
c19d1205
ZW
6914 if (add_to_lit_pool () == FAIL)
6915 {
6916 inst.error = _("literal pool insertion failed");
c921be7d 6917 return TRUE;
c19d1205
ZW
6918 }
6919 inst.operands[1].reg = REG_PC;
6920 inst.operands[1].isreg = 1;
6921 inst.operands[1].preind = 1;
6922 inst.reloc.pc_rel = 1;
6923 inst.reloc.type = (thumb_p
6924 ? BFD_RELOC_ARM_THUMB_OFFSET
6925 : (mode_3
6926 ? BFD_RELOC_ARM_HWLITERAL
6927 : BFD_RELOC_ARM_LITERAL));
c921be7d 6928 return FALSE;
09d92015
MM
6929}
6930
5f4273c7 6931/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6932 First some generics; their names are taken from the conventional
6933 bit positions for register arguments in ARM format instructions. */
09d92015 6934
a737bd4d 6935static void
c19d1205 6936do_noargs (void)
09d92015 6937{
c19d1205 6938}
a737bd4d 6939
c19d1205
ZW
6940static void
6941do_rd (void)
6942{
6943 inst.instruction |= inst.operands[0].reg << 12;
6944}
a737bd4d 6945
c19d1205
ZW
6946static void
6947do_rd_rm (void)
6948{
6949 inst.instruction |= inst.operands[0].reg << 12;
6950 inst.instruction |= inst.operands[1].reg;
6951}
09d92015 6952
c19d1205
ZW
6953static void
6954do_rd_rn (void)
6955{
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 inst.instruction |= inst.operands[1].reg << 16;
6958}
a737bd4d 6959
c19d1205
ZW
6960static void
6961do_rn_rd (void)
6962{
6963 inst.instruction |= inst.operands[0].reg << 16;
6964 inst.instruction |= inst.operands[1].reg << 12;
6965}
09d92015 6966
c19d1205
ZW
6967static void
6968do_rd_rm_rn (void)
6969{
9a64e435 6970 unsigned Rn = inst.operands[2].reg;
708587a4 6971 /* Enforce restrictions on SWP instruction. */
9a64e435 6972 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
6973 {
6974 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6975 _("Rn must not overlap other operands"));
6976
6977 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
6978 if (warn_on_deprecated
6979 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
6980 as_warn (_("swp{b} use is deprecated for this architecture"));
6981
6982 }
c19d1205
ZW
6983 inst.instruction |= inst.operands[0].reg << 12;
6984 inst.instruction |= inst.operands[1].reg;
9a64e435 6985 inst.instruction |= Rn << 16;
c19d1205 6986}
09d92015 6987
c19d1205
ZW
6988static void
6989do_rd_rn_rm (void)
6990{
6991 inst.instruction |= inst.operands[0].reg << 12;
6992 inst.instruction |= inst.operands[1].reg << 16;
6993 inst.instruction |= inst.operands[2].reg;
6994}
a737bd4d 6995
c19d1205
ZW
6996static void
6997do_rm_rd_rn (void)
6998{
5be8be5d
DG
6999 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7000 constraint (((inst.reloc.exp.X_op != O_constant
7001 && inst.reloc.exp.X_op != O_illegal)
7002 || inst.reloc.exp.X_add_number != 0),
7003 BAD_ADDR_MODE);
c19d1205
ZW
7004 inst.instruction |= inst.operands[0].reg;
7005 inst.instruction |= inst.operands[1].reg << 12;
7006 inst.instruction |= inst.operands[2].reg << 16;
7007}
09d92015 7008
c19d1205
ZW
7009static void
7010do_imm0 (void)
7011{
7012 inst.instruction |= inst.operands[0].imm;
7013}
09d92015 7014
c19d1205
ZW
7015static void
7016do_rd_cpaddr (void)
7017{
7018 inst.instruction |= inst.operands[0].reg << 12;
7019 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 7020}
a737bd4d 7021
c19d1205
ZW
7022/* ARM instructions, in alphabetical order by function name (except
7023 that wrapper functions appear immediately after the function they
7024 wrap). */
09d92015 7025
c19d1205
ZW
7026/* This is a pseudo-op of the form "adr rd, label" to be converted
7027 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
7028
7029static void
c19d1205 7030do_adr (void)
09d92015 7031{
c19d1205 7032 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7033
c19d1205
ZW
7034 /* Frag hacking will turn this into a sub instruction if the offset turns
7035 out to be negative. */
7036 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 7037 inst.reloc.pc_rel = 1;
2fc8bdac 7038 inst.reloc.exp.X_add_number -= 8;
c19d1205 7039}
b99bd4ef 7040
c19d1205
ZW
7041/* This is a pseudo-op of the form "adrl rd, label" to be converted
7042 into a relative address of the form:
7043 add rd, pc, #low(label-.-8)"
7044 add rd, rd, #high(label-.-8)" */
b99bd4ef 7045
c19d1205
ZW
7046static void
7047do_adrl (void)
7048{
7049 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7050
c19d1205
ZW
7051 /* Frag hacking will turn this into a sub instruction if the offset turns
7052 out to be negative. */
7053 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7054 inst.reloc.pc_rel = 1;
7055 inst.size = INSN_SIZE * 2;
2fc8bdac 7056 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7057}
7058
b99bd4ef 7059static void
c19d1205 7060do_arit (void)
b99bd4ef 7061{
c19d1205
ZW
7062 if (!inst.operands[1].present)
7063 inst.operands[1].reg = inst.operands[0].reg;
7064 inst.instruction |= inst.operands[0].reg << 12;
7065 inst.instruction |= inst.operands[1].reg << 16;
7066 encode_arm_shifter_operand (2);
7067}
b99bd4ef 7068
62b3e311
PB
7069static void
7070do_barrier (void)
7071{
7072 if (inst.operands[0].present)
7073 {
7074 constraint ((inst.instruction & 0xf0) != 0x40
7075 && inst.operands[0].imm != 0xf,
bd3ba5d1 7076 _("bad barrier type"));
62b3e311
PB
7077 inst.instruction |= inst.operands[0].imm;
7078 }
7079 else
7080 inst.instruction |= 0xf;
7081}
7082
c19d1205
ZW
7083static void
7084do_bfc (void)
7085{
7086 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7087 constraint (msb > 32, _("bit-field extends past end of register"));
7088 /* The instruction encoding stores the LSB and MSB,
7089 not the LSB and width. */
7090 inst.instruction |= inst.operands[0].reg << 12;
7091 inst.instruction |= inst.operands[1].imm << 7;
7092 inst.instruction |= (msb - 1) << 16;
7093}
b99bd4ef 7094
c19d1205
ZW
7095static void
7096do_bfi (void)
7097{
7098 unsigned int msb;
b99bd4ef 7099
c19d1205
ZW
7100 /* #0 in second position is alternative syntax for bfc, which is
7101 the same instruction but with REG_PC in the Rm field. */
7102 if (!inst.operands[1].isreg)
7103 inst.operands[1].reg = REG_PC;
b99bd4ef 7104
c19d1205
ZW
7105 msb = inst.operands[2].imm + inst.operands[3].imm;
7106 constraint (msb > 32, _("bit-field extends past end of register"));
7107 /* The instruction encoding stores the LSB and MSB,
7108 not the LSB and width. */
7109 inst.instruction |= inst.operands[0].reg << 12;
7110 inst.instruction |= inst.operands[1].reg;
7111 inst.instruction |= inst.operands[2].imm << 7;
7112 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7113}
7114
b99bd4ef 7115static void
c19d1205 7116do_bfx (void)
b99bd4ef 7117{
c19d1205
ZW
7118 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7119 _("bit-field extends past end of register"));
7120 inst.instruction |= inst.operands[0].reg << 12;
7121 inst.instruction |= inst.operands[1].reg;
7122 inst.instruction |= inst.operands[2].imm << 7;
7123 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7124}
09d92015 7125
c19d1205
ZW
7126/* ARM V5 breakpoint instruction (argument parse)
7127 BKPT <16 bit unsigned immediate>
7128 Instruction is not conditional.
7129 The bit pattern given in insns[] has the COND_ALWAYS condition,
7130 and it is an error if the caller tried to override that. */
b99bd4ef 7131
c19d1205
ZW
7132static void
7133do_bkpt (void)
7134{
7135 /* Top 12 of 16 bits to bits 19:8. */
7136 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7137
c19d1205
ZW
7138 /* Bottom 4 of 16 bits to bits 3:0. */
7139 inst.instruction |= inst.operands[0].imm & 0xf;
7140}
09d92015 7141
c19d1205
ZW
7142static void
7143encode_branch (int default_reloc)
7144{
7145 if (inst.operands[0].hasreloc)
7146 {
7147 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7148 _("the only suffix valid here is '(plt)'"));
267bf995 7149 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7150 }
b99bd4ef 7151 else
c19d1205 7152 {
21d799b5 7153 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7154 }
2fc8bdac 7155 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7156}
7157
b99bd4ef 7158static void
c19d1205 7159do_branch (void)
b99bd4ef 7160{
39b41c9c
PB
7161#ifdef OBJ_ELF
7162 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7163 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7164 else
7165#endif
7166 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7167}
7168
7169static void
7170do_bl (void)
7171{
7172#ifdef OBJ_ELF
7173 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7174 {
7175 if (inst.cond == COND_ALWAYS)
7176 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7177 else
7178 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7179 }
7180 else
7181#endif
7182 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7183}
b99bd4ef 7184
c19d1205
ZW
7185/* ARM V5 branch-link-exchange instruction (argument parse)
7186 BLX <target_addr> ie BLX(1)
7187 BLX{<condition>} <Rm> ie BLX(2)
7188 Unfortunately, there are two different opcodes for this mnemonic.
7189 So, the insns[].value is not used, and the code here zaps values
7190 into inst.instruction.
7191 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7192
c19d1205
ZW
7193static void
7194do_blx (void)
7195{
7196 if (inst.operands[0].isreg)
b99bd4ef 7197 {
c19d1205
ZW
7198 /* Arg is a register; the opcode provided by insns[] is correct.
7199 It is not illegal to do "blx pc", just useless. */
7200 if (inst.operands[0].reg == REG_PC)
7201 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7202
c19d1205
ZW
7203 inst.instruction |= inst.operands[0].reg;
7204 }
7205 else
b99bd4ef 7206 {
c19d1205 7207 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7208 conditionally, and the opcode must be adjusted.
7209 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7210 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7211 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7212 inst.instruction = 0xfa000000;
267bf995 7213 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7214 }
c19d1205
ZW
7215}
7216
7217static void
7218do_bx (void)
7219{
845b51d6
PB
7220 bfd_boolean want_reloc;
7221
c19d1205
ZW
7222 if (inst.operands[0].reg == REG_PC)
7223 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7224
c19d1205 7225 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7226 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7227 it is for ARMv4t or earlier. */
7228 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7229 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7230 want_reloc = TRUE;
7231
5ad34203 7232#ifdef OBJ_ELF
845b51d6 7233 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7234#endif
584206db 7235 want_reloc = FALSE;
845b51d6
PB
7236
7237 if (want_reloc)
7238 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7239}
7240
c19d1205
ZW
7241
7242/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7243
7244static void
c19d1205 7245do_bxj (void)
a737bd4d 7246{
c19d1205
ZW
7247 if (inst.operands[0].reg == REG_PC)
7248 as_tsktsk (_("use of r15 in bxj is not really useful"));
7249
7250 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7251}
7252
c19d1205
ZW
7253/* Co-processor data operation:
7254 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7255 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7256static void
7257do_cdp (void)
7258{
7259 inst.instruction |= inst.operands[0].reg << 8;
7260 inst.instruction |= inst.operands[1].imm << 20;
7261 inst.instruction |= inst.operands[2].reg << 12;
7262 inst.instruction |= inst.operands[3].reg << 16;
7263 inst.instruction |= inst.operands[4].reg;
7264 inst.instruction |= inst.operands[5].imm << 5;
7265}
a737bd4d
NC
7266
7267static void
c19d1205 7268do_cmp (void)
a737bd4d 7269{
c19d1205
ZW
7270 inst.instruction |= inst.operands[0].reg << 16;
7271 encode_arm_shifter_operand (1);
a737bd4d
NC
7272}
7273
c19d1205
ZW
7274/* Transfer between coprocessor and ARM registers.
7275 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7276 MRC2
7277 MCR{cond}
7278 MCR2
7279
7280 No special properties. */
09d92015
MM
7281
7282static void
c19d1205 7283do_co_reg (void)
09d92015 7284{
fdfde340
JM
7285 unsigned Rd;
7286
7287 Rd = inst.operands[2].reg;
7288 if (thumb_mode)
7289 {
7290 if (inst.instruction == 0xee000010
7291 || inst.instruction == 0xfe000010)
7292 /* MCR, MCR2 */
7293 reject_bad_reg (Rd);
7294 else
7295 /* MRC, MRC2 */
7296 constraint (Rd == REG_SP, BAD_SP);
7297 }
7298 else
7299 {
7300 /* MCR */
7301 if (inst.instruction == 0xe000010)
7302 constraint (Rd == REG_PC, BAD_PC);
7303 }
7304
7305
c19d1205
ZW
7306 inst.instruction |= inst.operands[0].reg << 8;
7307 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7308 inst.instruction |= Rd << 12;
c19d1205
ZW
7309 inst.instruction |= inst.operands[3].reg << 16;
7310 inst.instruction |= inst.operands[4].reg;
7311 inst.instruction |= inst.operands[5].imm << 5;
7312}
09d92015 7313
c19d1205
ZW
7314/* Transfer between coprocessor register and pair of ARM registers.
7315 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7316 MCRR2
7317 MRRC{cond}
7318 MRRC2
b99bd4ef 7319
c19d1205 7320 Two XScale instructions are special cases of these:
09d92015 7321
c19d1205
ZW
7322 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7323 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7324
5f4273c7 7325 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7326
c19d1205
ZW
7327static void
7328do_co_reg2c (void)
7329{
fdfde340
JM
7330 unsigned Rd, Rn;
7331
7332 Rd = inst.operands[2].reg;
7333 Rn = inst.operands[3].reg;
7334
7335 if (thumb_mode)
7336 {
7337 reject_bad_reg (Rd);
7338 reject_bad_reg (Rn);
7339 }
7340 else
7341 {
7342 constraint (Rd == REG_PC, BAD_PC);
7343 constraint (Rn == REG_PC, BAD_PC);
7344 }
7345
c19d1205
ZW
7346 inst.instruction |= inst.operands[0].reg << 8;
7347 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7348 inst.instruction |= Rd << 12;
7349 inst.instruction |= Rn << 16;
c19d1205 7350 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7351}
7352
c19d1205
ZW
7353static void
7354do_cpsi (void)
7355{
7356 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7357 if (inst.operands[1].present)
7358 {
7359 inst.instruction |= CPSI_MMOD;
7360 inst.instruction |= inst.operands[1].imm;
7361 }
c19d1205 7362}
b99bd4ef 7363
62b3e311
PB
7364static void
7365do_dbg (void)
7366{
7367 inst.instruction |= inst.operands[0].imm;
7368}
7369
b99bd4ef 7370static void
c19d1205 7371do_it (void)
b99bd4ef 7372{
c19d1205 7373 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7374 process it to do the validation as if in
7375 thumb mode, just in case the code gets
7376 assembled for thumb using the unified syntax. */
7377
c19d1205 7378 inst.size = 0;
e07e6e58
NC
7379 if (unified_syntax)
7380 {
7381 set_it_insn_type (IT_INSN);
7382 now_it.mask = (inst.instruction & 0xf) | 0x10;
7383 now_it.cc = inst.operands[0].imm;
7384 }
09d92015 7385}
b99bd4ef 7386
09d92015 7387static void
c19d1205 7388do_ldmstm (void)
ea6ef066 7389{
c19d1205
ZW
7390 int base_reg = inst.operands[0].reg;
7391 int range = inst.operands[1].imm;
ea6ef066 7392
c19d1205
ZW
7393 inst.instruction |= base_reg << 16;
7394 inst.instruction |= range;
ea6ef066 7395
c19d1205
ZW
7396 if (inst.operands[1].writeback)
7397 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7398
c19d1205 7399 if (inst.operands[0].writeback)
ea6ef066 7400 {
c19d1205
ZW
7401 inst.instruction |= WRITE_BACK;
7402 /* Check for unpredictable uses of writeback. */
7403 if (inst.instruction & LOAD_BIT)
09d92015 7404 {
c19d1205
ZW
7405 /* Not allowed in LDM type 2. */
7406 if ((inst.instruction & LDM_TYPE_2_OR_3)
7407 && ((range & (1 << REG_PC)) == 0))
7408 as_warn (_("writeback of base register is UNPREDICTABLE"));
7409 /* Only allowed if base reg not in list for other types. */
7410 else if (range & (1 << base_reg))
7411 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7412 }
7413 else /* STM. */
7414 {
7415 /* Not allowed for type 2. */
7416 if (inst.instruction & LDM_TYPE_2_OR_3)
7417 as_warn (_("writeback of base register is UNPREDICTABLE"));
7418 /* Only allowed if base reg not in list, or first in list. */
7419 else if ((range & (1 << base_reg))
7420 && (range & ((1 << base_reg) - 1)))
7421 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7422 }
ea6ef066 7423 }
a737bd4d
NC
7424}
7425
c19d1205
ZW
7426/* ARMv5TE load-consecutive (argument parse)
7427 Mode is like LDRH.
7428
7429 LDRccD R, mode
7430 STRccD R, mode. */
7431
a737bd4d 7432static void
c19d1205 7433do_ldrd (void)
a737bd4d 7434{
c19d1205
ZW
7435 constraint (inst.operands[0].reg % 2 != 0,
7436 _("first destination register must be even"));
7437 constraint (inst.operands[1].present
7438 && inst.operands[1].reg != inst.operands[0].reg + 1,
7439 _("can only load two consecutive registers"));
7440 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7441 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7442
c19d1205
ZW
7443 if (!inst.operands[1].present)
7444 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7445
c19d1205 7446 if (inst.instruction & LOAD_BIT)
a737bd4d 7447 {
c19d1205
ZW
7448 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7449 register and the first register written; we have to diagnose
7450 overlap between the base and the second register written here. */
ea6ef066 7451
c19d1205
ZW
7452 if (inst.operands[2].reg == inst.operands[1].reg
7453 && (inst.operands[2].writeback || inst.operands[2].postind))
7454 as_warn (_("base register written back, and overlaps "
7455 "second destination register"));
b05fe5cf 7456
c19d1205
ZW
7457 /* For an index-register load, the index register must not overlap the
7458 destination (even if not write-back). */
7459 else if (inst.operands[2].immisreg
ca3f61f7
NC
7460 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7461 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7462 as_warn (_("index register overlaps destination register"));
b05fe5cf 7463 }
c19d1205
ZW
7464
7465 inst.instruction |= inst.operands[0].reg << 12;
7466 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7467}
7468
7469static void
c19d1205 7470do_ldrex (void)
b05fe5cf 7471{
c19d1205
ZW
7472 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7473 || inst.operands[1].postind || inst.operands[1].writeback
7474 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7475 || inst.operands[1].negative
7476 /* This can arise if the programmer has written
7477 strex rN, rM, foo
7478 or if they have mistakenly used a register name as the last
7479 operand, eg:
7480 strex rN, rM, rX
7481 It is very difficult to distinguish between these two cases
7482 because "rX" might actually be a label. ie the register
7483 name has been occluded by a symbol of the same name. So we
7484 just generate a general 'bad addressing mode' type error
7485 message and leave it up to the programmer to discover the
7486 true cause and fix their mistake. */
7487 || (inst.operands[1].reg == REG_PC),
7488 BAD_ADDR_MODE);
b05fe5cf 7489
c19d1205
ZW
7490 constraint (inst.reloc.exp.X_op != O_constant
7491 || inst.reloc.exp.X_add_number != 0,
7492 _("offset must be zero in ARM encoding"));
b05fe5cf 7493
5be8be5d
DG
7494 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7495
c19d1205
ZW
7496 inst.instruction |= inst.operands[0].reg << 12;
7497 inst.instruction |= inst.operands[1].reg << 16;
7498 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7499}
7500
7501static void
c19d1205 7502do_ldrexd (void)
b05fe5cf 7503{
c19d1205
ZW
7504 constraint (inst.operands[0].reg % 2 != 0,
7505 _("even register required"));
7506 constraint (inst.operands[1].present
7507 && inst.operands[1].reg != inst.operands[0].reg + 1,
7508 _("can only load two consecutive registers"));
7509 /* If op 1 were present and equal to PC, this function wouldn't
7510 have been called in the first place. */
7511 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7512
c19d1205
ZW
7513 inst.instruction |= inst.operands[0].reg << 12;
7514 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7515}
7516
7517static void
c19d1205 7518do_ldst (void)
b05fe5cf 7519{
c19d1205
ZW
7520 inst.instruction |= inst.operands[0].reg << 12;
7521 if (!inst.operands[1].isreg)
7522 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7523 return;
c19d1205 7524 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7525}
7526
7527static void
c19d1205 7528do_ldstt (void)
b05fe5cf 7529{
c19d1205
ZW
7530 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7531 reject [Rn,...]. */
7532 if (inst.operands[1].preind)
b05fe5cf 7533 {
bd3ba5d1
NC
7534 constraint (inst.reloc.exp.X_op != O_constant
7535 || inst.reloc.exp.X_add_number != 0,
c19d1205 7536 _("this instruction requires a post-indexed address"));
b05fe5cf 7537
c19d1205
ZW
7538 inst.operands[1].preind = 0;
7539 inst.operands[1].postind = 1;
7540 inst.operands[1].writeback = 1;
b05fe5cf 7541 }
c19d1205
ZW
7542 inst.instruction |= inst.operands[0].reg << 12;
7543 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7544}
b05fe5cf 7545
c19d1205 7546/* Halfword and signed-byte load/store operations. */
b05fe5cf 7547
c19d1205
ZW
7548static void
7549do_ldstv4 (void)
7550{
ff4a8d2b 7551 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7552 inst.instruction |= inst.operands[0].reg << 12;
7553 if (!inst.operands[1].isreg)
7554 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7555 return;
c19d1205 7556 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7557}
7558
7559static void
c19d1205 7560do_ldsttv4 (void)
b05fe5cf 7561{
c19d1205
ZW
7562 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7563 reject [Rn,...]. */
7564 if (inst.operands[1].preind)
b05fe5cf 7565 {
bd3ba5d1
NC
7566 constraint (inst.reloc.exp.X_op != O_constant
7567 || inst.reloc.exp.X_add_number != 0,
c19d1205 7568 _("this instruction requires a post-indexed address"));
b05fe5cf 7569
c19d1205
ZW
7570 inst.operands[1].preind = 0;
7571 inst.operands[1].postind = 1;
7572 inst.operands[1].writeback = 1;
b05fe5cf 7573 }
c19d1205
ZW
7574 inst.instruction |= inst.operands[0].reg << 12;
7575 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7576}
b05fe5cf 7577
c19d1205
ZW
7578/* Co-processor register load/store.
7579 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7580static void
7581do_lstc (void)
7582{
7583 inst.instruction |= inst.operands[0].reg << 8;
7584 inst.instruction |= inst.operands[1].reg << 12;
7585 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7586}
7587
b05fe5cf 7588static void
c19d1205 7589do_mlas (void)
b05fe5cf 7590{
8fb9d7b9 7591 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7592 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7593 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7594 && !(inst.instruction & 0x00400000))
8fb9d7b9 7595 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7596
c19d1205
ZW
7597 inst.instruction |= inst.operands[0].reg << 16;
7598 inst.instruction |= inst.operands[1].reg;
7599 inst.instruction |= inst.operands[2].reg << 8;
7600 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7601}
b05fe5cf 7602
c19d1205
ZW
7603static void
7604do_mov (void)
7605{
7606 inst.instruction |= inst.operands[0].reg << 12;
7607 encode_arm_shifter_operand (1);
7608}
b05fe5cf 7609
c19d1205
ZW
7610/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7611static void
7612do_mov16 (void)
7613{
b6895b4f
PB
7614 bfd_vma imm;
7615 bfd_boolean top;
7616
7617 top = (inst.instruction & 0x00400000) != 0;
7618 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7619 _(":lower16: not allowed this instruction"));
7620 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7621 _(":upper16: not allowed instruction"));
c19d1205 7622 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7623 if (inst.reloc.type == BFD_RELOC_UNUSED)
7624 {
7625 imm = inst.reloc.exp.X_add_number;
7626 /* The value is in two pieces: 0:11, 16:19. */
7627 inst.instruction |= (imm & 0x00000fff);
7628 inst.instruction |= (imm & 0x0000f000) << 4;
7629 }
b05fe5cf 7630}
b99bd4ef 7631
037e8744
JB
7632static void do_vfp_nsyn_opcode (const char *);
7633
7634static int
7635do_vfp_nsyn_mrs (void)
7636{
7637 if (inst.operands[0].isvec)
7638 {
7639 if (inst.operands[1].reg != 1)
7640 first_error (_("operand 1 must be FPSCR"));
7641 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7642 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7643 do_vfp_nsyn_opcode ("fmstat");
7644 }
7645 else if (inst.operands[1].isvec)
7646 do_vfp_nsyn_opcode ("fmrx");
7647 else
7648 return FAIL;
5f4273c7 7649
037e8744
JB
7650 return SUCCESS;
7651}
7652
7653static int
7654do_vfp_nsyn_msr (void)
7655{
7656 if (inst.operands[0].isvec)
7657 do_vfp_nsyn_opcode ("fmxr");
7658 else
7659 return FAIL;
7660
7661 return SUCCESS;
7662}
7663
f7c21dc7
NC
7664static void
7665do_vmrs (void)
7666{
7667 unsigned Rt = inst.operands[0].reg;
7668
7669 if (thumb_mode && inst.operands[0].reg == REG_SP)
7670 {
7671 inst.error = BAD_SP;
7672 return;
7673 }
7674
7675 /* APSR_ sets isvec. All other refs to PC are illegal. */
7676 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7677 {
7678 inst.error = BAD_PC;
7679 return;
7680 }
7681
7682 if (inst.operands[1].reg != 1)
7683 first_error (_("operand 1 must be FPSCR"));
7684
7685 inst.instruction |= (Rt << 12);
7686}
7687
7688static void
7689do_vmsr (void)
7690{
7691 unsigned Rt = inst.operands[1].reg;
7692
7693 if (thumb_mode)
7694 reject_bad_reg (Rt);
7695 else if (Rt == REG_PC)
7696 {
7697 inst.error = BAD_PC;
7698 return;
7699 }
7700
7701 if (inst.operands[0].reg != 1)
7702 first_error (_("operand 0 must be FPSCR"));
7703
7704 inst.instruction |= (Rt << 12);
7705}
7706
b99bd4ef 7707static void
c19d1205 7708do_mrs (void)
b99bd4ef 7709{
037e8744
JB
7710 if (do_vfp_nsyn_mrs () == SUCCESS)
7711 return;
7712
c19d1205
ZW
7713 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7714 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7715 != (PSR_c|PSR_f),
7716 _("'CPSR' or 'SPSR' expected"));
ff4a8d2b 7717 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
7718 inst.instruction |= inst.operands[0].reg << 12;
7719 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7720}
b99bd4ef 7721
c19d1205
ZW
7722/* Two possible forms:
7723 "{C|S}PSR_<field>, Rm",
7724 "{C|S}PSR_f, #expression". */
b99bd4ef 7725
c19d1205
ZW
7726static void
7727do_msr (void)
7728{
037e8744
JB
7729 if (do_vfp_nsyn_msr () == SUCCESS)
7730 return;
7731
c19d1205
ZW
7732 inst.instruction |= inst.operands[0].imm;
7733 if (inst.operands[1].isreg)
7734 inst.instruction |= inst.operands[1].reg;
7735 else
b99bd4ef 7736 {
c19d1205
ZW
7737 inst.instruction |= INST_IMMEDIATE;
7738 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7739 inst.reloc.pc_rel = 0;
b99bd4ef 7740 }
b99bd4ef
NC
7741}
7742
c19d1205
ZW
7743static void
7744do_mul (void)
a737bd4d 7745{
ff4a8d2b
NC
7746 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7747
c19d1205
ZW
7748 if (!inst.operands[2].present)
7749 inst.operands[2].reg = inst.operands[0].reg;
7750 inst.instruction |= inst.operands[0].reg << 16;
7751 inst.instruction |= inst.operands[1].reg;
7752 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7753
8fb9d7b9
MS
7754 if (inst.operands[0].reg == inst.operands[1].reg
7755 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7756 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7757}
7758
c19d1205
ZW
7759/* Long Multiply Parser
7760 UMULL RdLo, RdHi, Rm, Rs
7761 SMULL RdLo, RdHi, Rm, Rs
7762 UMLAL RdLo, RdHi, Rm, Rs
7763 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7764
7765static void
c19d1205 7766do_mull (void)
b99bd4ef 7767{
c19d1205
ZW
7768 inst.instruction |= inst.operands[0].reg << 12;
7769 inst.instruction |= inst.operands[1].reg << 16;
7770 inst.instruction |= inst.operands[2].reg;
7771 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7772
682b27ad
PB
7773 /* rdhi and rdlo must be different. */
7774 if (inst.operands[0].reg == inst.operands[1].reg)
7775 as_tsktsk (_("rdhi and rdlo must be different"));
7776
7777 /* rdhi, rdlo and rm must all be different before armv6. */
7778 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7779 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7780 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7781 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7782}
b99bd4ef 7783
c19d1205
ZW
7784static void
7785do_nop (void)
7786{
e7495e45
NS
7787 if (inst.operands[0].present
7788 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7789 {
7790 /* Architectural NOP hints are CPSR sets with no bits selected. */
7791 inst.instruction &= 0xf0000000;
e7495e45
NS
7792 inst.instruction |= 0x0320f000;
7793 if (inst.operands[0].present)
7794 inst.instruction |= inst.operands[0].imm;
c19d1205 7795 }
b99bd4ef
NC
7796}
7797
c19d1205
ZW
7798/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7799 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7800 Condition defaults to COND_ALWAYS.
7801 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7802
7803static void
c19d1205 7804do_pkhbt (void)
b99bd4ef 7805{
c19d1205
ZW
7806 inst.instruction |= inst.operands[0].reg << 12;
7807 inst.instruction |= inst.operands[1].reg << 16;
7808 inst.instruction |= inst.operands[2].reg;
7809 if (inst.operands[3].present)
7810 encode_arm_shift (3);
7811}
b99bd4ef 7812
c19d1205 7813/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7814
c19d1205
ZW
7815static void
7816do_pkhtb (void)
7817{
7818 if (!inst.operands[3].present)
b99bd4ef 7819 {
c19d1205
ZW
7820 /* If the shift specifier is omitted, turn the instruction
7821 into pkhbt rd, rm, rn. */
7822 inst.instruction &= 0xfff00010;
7823 inst.instruction |= inst.operands[0].reg << 12;
7824 inst.instruction |= inst.operands[1].reg;
7825 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7826 }
7827 else
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 encode_arm_shift (3);
b99bd4ef
NC
7833 }
7834}
7835
c19d1205
ZW
7836/* ARMv5TE: Preload-Cache
7837
7838 PLD <addr_mode>
7839
7840 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7841
7842static void
c19d1205 7843do_pld (void)
b99bd4ef 7844{
c19d1205
ZW
7845 constraint (!inst.operands[0].isreg,
7846 _("'[' expected after PLD mnemonic"));
7847 constraint (inst.operands[0].postind,
7848 _("post-indexed expression used in preload instruction"));
7849 constraint (inst.operands[0].writeback,
7850 _("writeback used in preload instruction"));
7851 constraint (!inst.operands[0].preind,
7852 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7853 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7854}
b99bd4ef 7855
62b3e311
PB
7856/* ARMv7: PLI <addr_mode> */
7857static void
7858do_pli (void)
7859{
7860 constraint (!inst.operands[0].isreg,
7861 _("'[' expected after PLI mnemonic"));
7862 constraint (inst.operands[0].postind,
7863 _("post-indexed expression used in preload instruction"));
7864 constraint (inst.operands[0].writeback,
7865 _("writeback used in preload instruction"));
7866 constraint (!inst.operands[0].preind,
7867 _("unindexed addressing used in preload instruction"));
7868 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7869 inst.instruction &= ~PRE_INDEX;
7870}
7871
c19d1205
ZW
7872static void
7873do_push_pop (void)
7874{
7875 inst.operands[1] = inst.operands[0];
7876 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7877 inst.operands[0].isreg = 1;
7878 inst.operands[0].writeback = 1;
7879 inst.operands[0].reg = REG_SP;
7880 do_ldmstm ();
7881}
b99bd4ef 7882
c19d1205
ZW
7883/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7884 word at the specified address and the following word
7885 respectively.
7886 Unconditionally executed.
7887 Error if Rn is R15. */
b99bd4ef 7888
c19d1205
ZW
7889static void
7890do_rfe (void)
7891{
7892 inst.instruction |= inst.operands[0].reg << 16;
7893 if (inst.operands[0].writeback)
7894 inst.instruction |= WRITE_BACK;
7895}
b99bd4ef 7896
c19d1205 7897/* ARM V6 ssat (argument parse). */
b99bd4ef 7898
c19d1205
ZW
7899static void
7900do_ssat (void)
7901{
7902 inst.instruction |= inst.operands[0].reg << 12;
7903 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7904 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7905
c19d1205
ZW
7906 if (inst.operands[3].present)
7907 encode_arm_shift (3);
b99bd4ef
NC
7908}
7909
c19d1205 7910/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7911
7912static void
c19d1205 7913do_usat (void)
b99bd4ef 7914{
c19d1205
ZW
7915 inst.instruction |= inst.operands[0].reg << 12;
7916 inst.instruction |= inst.operands[1].imm << 16;
7917 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7918
c19d1205
ZW
7919 if (inst.operands[3].present)
7920 encode_arm_shift (3);
b99bd4ef
NC
7921}
7922
c19d1205 7923/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7924
7925static void
c19d1205 7926do_ssat16 (void)
09d92015 7927{
c19d1205
ZW
7928 inst.instruction |= inst.operands[0].reg << 12;
7929 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7930 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7931}
7932
c19d1205
ZW
7933static void
7934do_usat16 (void)
a737bd4d 7935{
c19d1205
ZW
7936 inst.instruction |= inst.operands[0].reg << 12;
7937 inst.instruction |= inst.operands[1].imm << 16;
7938 inst.instruction |= inst.operands[2].reg;
7939}
a737bd4d 7940
c19d1205
ZW
7941/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7942 preserving the other bits.
a737bd4d 7943
c19d1205
ZW
7944 setend <endian_specifier>, where <endian_specifier> is either
7945 BE or LE. */
a737bd4d 7946
c19d1205
ZW
7947static void
7948do_setend (void)
7949{
7950 if (inst.operands[0].imm)
7951 inst.instruction |= 0x200;
a737bd4d
NC
7952}
7953
7954static void
c19d1205 7955do_shift (void)
a737bd4d 7956{
c19d1205
ZW
7957 unsigned int Rm = (inst.operands[1].present
7958 ? inst.operands[1].reg
7959 : inst.operands[0].reg);
a737bd4d 7960
c19d1205
ZW
7961 inst.instruction |= inst.operands[0].reg << 12;
7962 inst.instruction |= Rm;
7963 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7964 {
c19d1205
ZW
7965 inst.instruction |= inst.operands[2].reg << 8;
7966 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7967 }
7968 else
c19d1205 7969 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7970}
7971
09d92015 7972static void
3eb17e6b 7973do_smc (void)
09d92015 7974{
3eb17e6b 7975 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7976 inst.reloc.pc_rel = 0;
09d92015
MM
7977}
7978
09d92015 7979static void
c19d1205 7980do_swi (void)
09d92015 7981{
c19d1205
ZW
7982 inst.reloc.type = BFD_RELOC_ARM_SWI;
7983 inst.reloc.pc_rel = 0;
09d92015
MM
7984}
7985
c19d1205
ZW
7986/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7987 SMLAxy{cond} Rd,Rm,Rs,Rn
7988 SMLAWy{cond} Rd,Rm,Rs,Rn
7989 Error if any register is R15. */
e16bb312 7990
c19d1205
ZW
7991static void
7992do_smla (void)
e16bb312 7993{
c19d1205
ZW
7994 inst.instruction |= inst.operands[0].reg << 16;
7995 inst.instruction |= inst.operands[1].reg;
7996 inst.instruction |= inst.operands[2].reg << 8;
7997 inst.instruction |= inst.operands[3].reg << 12;
7998}
a737bd4d 7999
c19d1205
ZW
8000/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8001 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8002 Error if any register is R15.
8003 Warning if Rdlo == Rdhi. */
a737bd4d 8004
c19d1205
ZW
8005static void
8006do_smlal (void)
8007{
8008 inst.instruction |= inst.operands[0].reg << 12;
8009 inst.instruction |= inst.operands[1].reg << 16;
8010 inst.instruction |= inst.operands[2].reg;
8011 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 8012
c19d1205
ZW
8013 if (inst.operands[0].reg == inst.operands[1].reg)
8014 as_tsktsk (_("rdhi and rdlo must be different"));
8015}
a737bd4d 8016
c19d1205
ZW
8017/* ARM V5E (El Segundo) signed-multiply (argument parse)
8018 SMULxy{cond} Rd,Rm,Rs
8019 Error if any register is R15. */
a737bd4d 8020
c19d1205
ZW
8021static void
8022do_smul (void)
8023{
8024 inst.instruction |= inst.operands[0].reg << 16;
8025 inst.instruction |= inst.operands[1].reg;
8026 inst.instruction |= inst.operands[2].reg << 8;
8027}
a737bd4d 8028
b6702015
PB
8029/* ARM V6 srs (argument parse). The variable fields in the encoding are
8030 the same for both ARM and Thumb-2. */
a737bd4d 8031
c19d1205
ZW
8032static void
8033do_srs (void)
8034{
b6702015
PB
8035 int reg;
8036
8037 if (inst.operands[0].present)
8038 {
8039 reg = inst.operands[0].reg;
fdfde340 8040 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
8041 }
8042 else
fdfde340 8043 reg = REG_SP;
b6702015
PB
8044
8045 inst.instruction |= reg << 16;
8046 inst.instruction |= inst.operands[1].imm;
8047 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8048 inst.instruction |= WRITE_BACK;
8049}
a737bd4d 8050
c19d1205 8051/* ARM V6 strex (argument parse). */
a737bd4d 8052
c19d1205
ZW
8053static void
8054do_strex (void)
8055{
8056 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8057 || inst.operands[2].postind || inst.operands[2].writeback
8058 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8059 || inst.operands[2].negative
8060 /* See comment in do_ldrex(). */
8061 || (inst.operands[2].reg == REG_PC),
8062 BAD_ADDR_MODE);
a737bd4d 8063
c19d1205
ZW
8064 constraint (inst.operands[0].reg == inst.operands[1].reg
8065 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8066
c19d1205
ZW
8067 constraint (inst.reloc.exp.X_op != O_constant
8068 || inst.reloc.exp.X_add_number != 0,
8069 _("offset must be zero in ARM encoding"));
a737bd4d 8070
c19d1205
ZW
8071 inst.instruction |= inst.operands[0].reg << 12;
8072 inst.instruction |= inst.operands[1].reg;
8073 inst.instruction |= inst.operands[2].reg << 16;
8074 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8075}
8076
8077static void
c19d1205 8078do_strexd (void)
e16bb312 8079{
c19d1205
ZW
8080 constraint (inst.operands[1].reg % 2 != 0,
8081 _("even register required"));
8082 constraint (inst.operands[2].present
8083 && inst.operands[2].reg != inst.operands[1].reg + 1,
8084 _("can only store two consecutive registers"));
8085 /* If op 2 were present and equal to PC, this function wouldn't
8086 have been called in the first place. */
8087 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8088
c19d1205
ZW
8089 constraint (inst.operands[0].reg == inst.operands[1].reg
8090 || inst.operands[0].reg == inst.operands[1].reg + 1
8091 || inst.operands[0].reg == inst.operands[3].reg,
8092 BAD_OVERLAP);
e16bb312 8093
c19d1205
ZW
8094 inst.instruction |= inst.operands[0].reg << 12;
8095 inst.instruction |= inst.operands[1].reg;
8096 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8097}
8098
c19d1205
ZW
8099/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8100 extends it to 32-bits, and adds the result to a value in another
8101 register. You can specify a rotation by 0, 8, 16, or 24 bits
8102 before extracting the 16-bit value.
8103 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8104 Condition defaults to COND_ALWAYS.
8105 Error if any register uses R15. */
8106
e16bb312 8107static void
c19d1205 8108do_sxtah (void)
e16bb312 8109{
c19d1205
ZW
8110 inst.instruction |= inst.operands[0].reg << 12;
8111 inst.instruction |= inst.operands[1].reg << 16;
8112 inst.instruction |= inst.operands[2].reg;
8113 inst.instruction |= inst.operands[3].imm << 10;
8114}
e16bb312 8115
c19d1205 8116/* ARM V6 SXTH.
e16bb312 8117
c19d1205
ZW
8118 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8119 Condition defaults to COND_ALWAYS.
8120 Error if any register uses R15. */
e16bb312
NC
8121
8122static void
c19d1205 8123do_sxth (void)
e16bb312 8124{
c19d1205
ZW
8125 inst.instruction |= inst.operands[0].reg << 12;
8126 inst.instruction |= inst.operands[1].reg;
8127 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8128}
c19d1205
ZW
8129\f
8130/* VFP instructions. In a logical order: SP variant first, monad
8131 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8132
8133static void
c19d1205 8134do_vfp_sp_monadic (void)
e16bb312 8135{
5287ad62
JB
8136 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8137 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8138}
8139
8140static void
c19d1205 8141do_vfp_sp_dyadic (void)
e16bb312 8142{
5287ad62
JB
8143 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8144 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8145 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8146}
8147
8148static void
c19d1205 8149do_vfp_sp_compare_z (void)
e16bb312 8150{
5287ad62 8151 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8152}
8153
8154static void
c19d1205 8155do_vfp_dp_sp_cvt (void)
e16bb312 8156{
5287ad62
JB
8157 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8158 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8159}
8160
8161static void
c19d1205 8162do_vfp_sp_dp_cvt (void)
e16bb312 8163{
5287ad62
JB
8164 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8165 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8166}
8167
8168static void
c19d1205 8169do_vfp_reg_from_sp (void)
e16bb312 8170{
c19d1205 8171 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8172 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8173}
8174
8175static void
c19d1205 8176do_vfp_reg2_from_sp2 (void)
e16bb312 8177{
c19d1205
ZW
8178 constraint (inst.operands[2].imm != 2,
8179 _("only two consecutive VFP SP registers allowed here"));
8180 inst.instruction |= inst.operands[0].reg << 12;
8181 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8182 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8183}
8184
8185static void
c19d1205 8186do_vfp_sp_from_reg (void)
e16bb312 8187{
5287ad62 8188 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8189 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8190}
8191
8192static void
c19d1205 8193do_vfp_sp2_from_reg2 (void)
e16bb312 8194{
c19d1205
ZW
8195 constraint (inst.operands[0].imm != 2,
8196 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8197 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8198 inst.instruction |= inst.operands[1].reg << 12;
8199 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8200}
8201
8202static void
c19d1205 8203do_vfp_sp_ldst (void)
e16bb312 8204{
5287ad62 8205 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8206 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8207}
8208
8209static void
c19d1205 8210do_vfp_dp_ldst (void)
e16bb312 8211{
5287ad62 8212 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8213 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8214}
8215
c19d1205 8216
e16bb312 8217static void
c19d1205 8218vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8219{
c19d1205
ZW
8220 if (inst.operands[0].writeback)
8221 inst.instruction |= WRITE_BACK;
8222 else
8223 constraint (ldstm_type != VFP_LDSTMIA,
8224 _("this addressing mode requires base-register writeback"));
8225 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8226 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8227 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8228}
8229
8230static void
c19d1205 8231vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8232{
c19d1205 8233 int count;
e16bb312 8234
c19d1205
ZW
8235 if (inst.operands[0].writeback)
8236 inst.instruction |= WRITE_BACK;
8237 else
8238 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8239 _("this addressing mode requires base-register writeback"));
e16bb312 8240
c19d1205 8241 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8242 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8243
c19d1205
ZW
8244 count = inst.operands[1].imm << 1;
8245 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8246 count += 1;
e16bb312 8247
c19d1205 8248 inst.instruction |= count;
e16bb312
NC
8249}
8250
8251static void
c19d1205 8252do_vfp_sp_ldstmia (void)
e16bb312 8253{
c19d1205 8254 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8255}
8256
8257static void
c19d1205 8258do_vfp_sp_ldstmdb (void)
e16bb312 8259{
c19d1205 8260 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8261}
8262
8263static void
c19d1205 8264do_vfp_dp_ldstmia (void)
e16bb312 8265{
c19d1205 8266 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8267}
8268
8269static void
c19d1205 8270do_vfp_dp_ldstmdb (void)
e16bb312 8271{
c19d1205 8272 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8273}
8274
8275static void
c19d1205 8276do_vfp_xp_ldstmia (void)
e16bb312 8277{
c19d1205
ZW
8278 vfp_dp_ldstm (VFP_LDSTMIAX);
8279}
e16bb312 8280
c19d1205
ZW
8281static void
8282do_vfp_xp_ldstmdb (void)
8283{
8284 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8285}
5287ad62
JB
8286
8287static void
8288do_vfp_dp_rd_rm (void)
8289{
8290 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8291 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8292}
8293
8294static void
8295do_vfp_dp_rn_rd (void)
8296{
8297 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8298 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8299}
8300
8301static void
8302do_vfp_dp_rd_rn (void)
8303{
8304 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8305 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8306}
8307
8308static void
8309do_vfp_dp_rd_rn_rm (void)
8310{
8311 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8312 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8313 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8314}
8315
8316static void
8317do_vfp_dp_rd (void)
8318{
8319 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8320}
8321
8322static void
8323do_vfp_dp_rm_rd_rn (void)
8324{
8325 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8326 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8327 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8328}
8329
8330/* VFPv3 instructions. */
8331static void
8332do_vfp_sp_const (void)
8333{
8334 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8335 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8336 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8337}
8338
8339static void
8340do_vfp_dp_const (void)
8341{
8342 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8343 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8344 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8345}
8346
8347static void
8348vfp_conv (int srcsize)
8349{
8350 unsigned immbits = srcsize - inst.operands[1].imm;
8351 inst.instruction |= (immbits & 1) << 5;
8352 inst.instruction |= (immbits >> 1);
8353}
8354
8355static void
8356do_vfp_sp_conv_16 (void)
8357{
8358 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8359 vfp_conv (16);
8360}
8361
8362static void
8363do_vfp_dp_conv_16 (void)
8364{
8365 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8366 vfp_conv (16);
8367}
8368
8369static void
8370do_vfp_sp_conv_32 (void)
8371{
8372 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8373 vfp_conv (32);
8374}
8375
8376static void
8377do_vfp_dp_conv_32 (void)
8378{
8379 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8380 vfp_conv (32);
8381}
c19d1205
ZW
8382\f
8383/* FPA instructions. Also in a logical order. */
e16bb312 8384
c19d1205
ZW
8385static void
8386do_fpa_cmp (void)
8387{
8388 inst.instruction |= inst.operands[0].reg << 16;
8389 inst.instruction |= inst.operands[1].reg;
8390}
b99bd4ef
NC
8391
8392static void
c19d1205 8393do_fpa_ldmstm (void)
b99bd4ef 8394{
c19d1205
ZW
8395 inst.instruction |= inst.operands[0].reg << 12;
8396 switch (inst.operands[1].imm)
8397 {
8398 case 1: inst.instruction |= CP_T_X; break;
8399 case 2: inst.instruction |= CP_T_Y; break;
8400 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8401 case 4: break;
8402 default: abort ();
8403 }
b99bd4ef 8404
c19d1205
ZW
8405 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8406 {
8407 /* The instruction specified "ea" or "fd", so we can only accept
8408 [Rn]{!}. The instruction does not really support stacking or
8409 unstacking, so we have to emulate these by setting appropriate
8410 bits and offsets. */
8411 constraint (inst.reloc.exp.X_op != O_constant
8412 || inst.reloc.exp.X_add_number != 0,
8413 _("this instruction does not support indexing"));
b99bd4ef 8414
c19d1205
ZW
8415 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8416 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8417
c19d1205
ZW
8418 if (!(inst.instruction & INDEX_UP))
8419 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8420
c19d1205
ZW
8421 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8422 {
8423 inst.operands[2].preind = 0;
8424 inst.operands[2].postind = 1;
8425 }
8426 }
b99bd4ef 8427
c19d1205 8428 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8429}
c19d1205
ZW
8430\f
8431/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8432
c19d1205
ZW
8433static void
8434do_iwmmxt_tandorc (void)
8435{
8436 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8437}
b99bd4ef 8438
c19d1205
ZW
8439static void
8440do_iwmmxt_textrc (void)
8441{
8442 inst.instruction |= inst.operands[0].reg << 12;
8443 inst.instruction |= inst.operands[1].imm;
8444}
b99bd4ef
NC
8445
8446static void
c19d1205 8447do_iwmmxt_textrm (void)
b99bd4ef 8448{
c19d1205
ZW
8449 inst.instruction |= inst.operands[0].reg << 12;
8450 inst.instruction |= inst.operands[1].reg << 16;
8451 inst.instruction |= inst.operands[2].imm;
8452}
b99bd4ef 8453
c19d1205
ZW
8454static void
8455do_iwmmxt_tinsr (void)
8456{
8457 inst.instruction |= inst.operands[0].reg << 16;
8458 inst.instruction |= inst.operands[1].reg << 12;
8459 inst.instruction |= inst.operands[2].imm;
8460}
b99bd4ef 8461
c19d1205
ZW
8462static void
8463do_iwmmxt_tmia (void)
8464{
8465 inst.instruction |= inst.operands[0].reg << 5;
8466 inst.instruction |= inst.operands[1].reg;
8467 inst.instruction |= inst.operands[2].reg << 12;
8468}
b99bd4ef 8469
c19d1205
ZW
8470static void
8471do_iwmmxt_waligni (void)
8472{
8473 inst.instruction |= inst.operands[0].reg << 12;
8474 inst.instruction |= inst.operands[1].reg << 16;
8475 inst.instruction |= inst.operands[2].reg;
8476 inst.instruction |= inst.operands[3].imm << 20;
8477}
b99bd4ef 8478
2d447fca
JM
8479static void
8480do_iwmmxt_wmerge (void)
8481{
8482 inst.instruction |= inst.operands[0].reg << 12;
8483 inst.instruction |= inst.operands[1].reg << 16;
8484 inst.instruction |= inst.operands[2].reg;
8485 inst.instruction |= inst.operands[3].imm << 21;
8486}
8487
c19d1205
ZW
8488static void
8489do_iwmmxt_wmov (void)
8490{
8491 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8492 inst.instruction |= inst.operands[0].reg << 12;
8493 inst.instruction |= inst.operands[1].reg << 16;
8494 inst.instruction |= inst.operands[1].reg;
8495}
b99bd4ef 8496
c19d1205
ZW
8497static void
8498do_iwmmxt_wldstbh (void)
8499{
8f06b2d8 8500 int reloc;
c19d1205 8501 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8502 if (thumb_mode)
8503 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8504 else
8505 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8506 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8507}
8508
c19d1205
ZW
8509static void
8510do_iwmmxt_wldstw (void)
8511{
8512 /* RIWR_RIWC clears .isreg for a control register. */
8513 if (!inst.operands[0].isreg)
8514 {
8515 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8516 inst.instruction |= 0xf0000000;
8517 }
b99bd4ef 8518
c19d1205
ZW
8519 inst.instruction |= inst.operands[0].reg << 12;
8520 encode_arm_cp_address (1, TRUE, TRUE, 0);
8521}
b99bd4ef
NC
8522
8523static void
c19d1205 8524do_iwmmxt_wldstd (void)
b99bd4ef 8525{
c19d1205 8526 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8527 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8528 && inst.operands[1].immisreg)
8529 {
8530 inst.instruction &= ~0x1a000ff;
8531 inst.instruction |= (0xf << 28);
8532 if (inst.operands[1].preind)
8533 inst.instruction |= PRE_INDEX;
8534 if (!inst.operands[1].negative)
8535 inst.instruction |= INDEX_UP;
8536 if (inst.operands[1].writeback)
8537 inst.instruction |= WRITE_BACK;
8538 inst.instruction |= inst.operands[1].reg << 16;
8539 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8540 inst.instruction |= inst.operands[1].imm;
8541 }
8542 else
8543 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8544}
b99bd4ef 8545
c19d1205
ZW
8546static void
8547do_iwmmxt_wshufh (void)
8548{
8549 inst.instruction |= inst.operands[0].reg << 12;
8550 inst.instruction |= inst.operands[1].reg << 16;
8551 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8552 inst.instruction |= (inst.operands[2].imm & 0x0f);
8553}
b99bd4ef 8554
c19d1205
ZW
8555static void
8556do_iwmmxt_wzero (void)
8557{
8558 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8559 inst.instruction |= inst.operands[0].reg;
8560 inst.instruction |= inst.operands[0].reg << 12;
8561 inst.instruction |= inst.operands[0].reg << 16;
8562}
2d447fca
JM
8563
8564static void
8565do_iwmmxt_wrwrwr_or_imm5 (void)
8566{
8567 if (inst.operands[2].isreg)
8568 do_rd_rn_rm ();
8569 else {
8570 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8571 _("immediate operand requires iWMMXt2"));
8572 do_rd_rn ();
8573 if (inst.operands[2].imm == 0)
8574 {
8575 switch ((inst.instruction >> 20) & 0xf)
8576 {
8577 case 4:
8578 case 5:
8579 case 6:
5f4273c7 8580 case 7:
2d447fca
JM
8581 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8582 inst.operands[2].imm = 16;
8583 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8584 break;
8585 case 8:
8586 case 9:
8587 case 10:
8588 case 11:
8589 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8590 inst.operands[2].imm = 32;
8591 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8592 break;
8593 case 12:
8594 case 13:
8595 case 14:
8596 case 15:
8597 {
8598 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8599 unsigned long wrn;
8600 wrn = (inst.instruction >> 16) & 0xf;
8601 inst.instruction &= 0xff0fff0f;
8602 inst.instruction |= wrn;
8603 /* Bail out here; the instruction is now assembled. */
8604 return;
8605 }
8606 }
8607 }
8608 /* Map 32 -> 0, etc. */
8609 inst.operands[2].imm &= 0x1f;
8610 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8611 }
8612}
c19d1205
ZW
8613\f
8614/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8615 operations first, then control, shift, and load/store. */
b99bd4ef 8616
c19d1205 8617/* Insns like "foo X,Y,Z". */
b99bd4ef 8618
c19d1205
ZW
8619static void
8620do_mav_triple (void)
8621{
8622 inst.instruction |= inst.operands[0].reg << 16;
8623 inst.instruction |= inst.operands[1].reg;
8624 inst.instruction |= inst.operands[2].reg << 12;
8625}
b99bd4ef 8626
c19d1205
ZW
8627/* Insns like "foo W,X,Y,Z".
8628 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8629
c19d1205
ZW
8630static void
8631do_mav_quad (void)
8632{
8633 inst.instruction |= inst.operands[0].reg << 5;
8634 inst.instruction |= inst.operands[1].reg << 12;
8635 inst.instruction |= inst.operands[2].reg << 16;
8636 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8637}
8638
c19d1205
ZW
8639/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8640static void
8641do_mav_dspsc (void)
a737bd4d 8642{
c19d1205
ZW
8643 inst.instruction |= inst.operands[1].reg << 12;
8644}
a737bd4d 8645
c19d1205
ZW
8646/* Maverick shift immediate instructions.
8647 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8648 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8649
c19d1205
ZW
8650static void
8651do_mav_shift (void)
8652{
8653 int imm = inst.operands[2].imm;
a737bd4d 8654
c19d1205
ZW
8655 inst.instruction |= inst.operands[0].reg << 12;
8656 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8657
c19d1205
ZW
8658 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8659 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8660 Bit 4 should be 0. */
8661 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8662
c19d1205
ZW
8663 inst.instruction |= imm;
8664}
8665\f
8666/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8667
c19d1205
ZW
8668/* Xscale multiply-accumulate (argument parse)
8669 MIAcc acc0,Rm,Rs
8670 MIAPHcc acc0,Rm,Rs
8671 MIAxycc acc0,Rm,Rs. */
a737bd4d 8672
c19d1205
ZW
8673static void
8674do_xsc_mia (void)
8675{
8676 inst.instruction |= inst.operands[1].reg;
8677 inst.instruction |= inst.operands[2].reg << 12;
8678}
a737bd4d 8679
c19d1205 8680/* Xscale move-accumulator-register (argument parse)
a737bd4d 8681
c19d1205 8682 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8683
c19d1205
ZW
8684static void
8685do_xsc_mar (void)
8686{
8687 inst.instruction |= inst.operands[1].reg << 12;
8688 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8689}
8690
c19d1205 8691/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8692
c19d1205 8693 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8694
8695static void
c19d1205 8696do_xsc_mra (void)
b99bd4ef 8697{
c19d1205
ZW
8698 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8699 inst.instruction |= inst.operands[0].reg << 12;
8700 inst.instruction |= inst.operands[1].reg << 16;
8701}
8702\f
8703/* Encoding functions relevant only to Thumb. */
b99bd4ef 8704
c19d1205
ZW
8705/* inst.operands[i] is a shifted-register operand; encode
8706 it into inst.instruction in the format used by Thumb32. */
8707
8708static void
8709encode_thumb32_shifted_operand (int i)
8710{
8711 unsigned int value = inst.reloc.exp.X_add_number;
8712 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8713
9c3c69f2
PB
8714 constraint (inst.operands[i].immisreg,
8715 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8716 inst.instruction |= inst.operands[i].reg;
8717 if (shift == SHIFT_RRX)
8718 inst.instruction |= SHIFT_ROR << 4;
8719 else
b99bd4ef 8720 {
c19d1205
ZW
8721 constraint (inst.reloc.exp.X_op != O_constant,
8722 _("expression too complex"));
8723
8724 constraint (value > 32
8725 || (value == 32 && (shift == SHIFT_LSL
8726 || shift == SHIFT_ROR)),
8727 _("shift expression is too large"));
8728
8729 if (value == 0)
8730 shift = SHIFT_LSL;
8731 else if (value == 32)
8732 value = 0;
8733
8734 inst.instruction |= shift << 4;
8735 inst.instruction |= (value & 0x1c) << 10;
8736 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8737 }
c19d1205 8738}
b99bd4ef 8739
b99bd4ef 8740
c19d1205
ZW
8741/* inst.operands[i] was set up by parse_address. Encode it into a
8742 Thumb32 format load or store instruction. Reject forms that cannot
8743 be used with such instructions. If is_t is true, reject forms that
8744 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
8745 that cannot be used with a D instruction. If it is a store insn,
8746 reject PC in Rn. */
b99bd4ef 8747
c19d1205
ZW
8748static void
8749encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8750{
5be8be5d 8751 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
8752
8753 constraint (!inst.operands[i].isreg,
53365c0d 8754 _("Instruction does not support =N addresses"));
b99bd4ef 8755
c19d1205
ZW
8756 inst.instruction |= inst.operands[i].reg << 16;
8757 if (inst.operands[i].immisreg)
b99bd4ef 8758 {
5be8be5d 8759 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
8760 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8761 constraint (inst.operands[i].negative,
8762 _("Thumb does not support negative register indexing"));
8763 constraint (inst.operands[i].postind,
8764 _("Thumb does not support register post-indexing"));
8765 constraint (inst.operands[i].writeback,
8766 _("Thumb does not support register indexing with writeback"));
8767 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8768 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8769
f40d1643 8770 inst.instruction |= inst.operands[i].imm;
c19d1205 8771 if (inst.operands[i].shifted)
b99bd4ef 8772 {
c19d1205
ZW
8773 constraint (inst.reloc.exp.X_op != O_constant,
8774 _("expression too complex"));
9c3c69f2
PB
8775 constraint (inst.reloc.exp.X_add_number < 0
8776 || inst.reloc.exp.X_add_number > 3,
c19d1205 8777 _("shift out of range"));
9c3c69f2 8778 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8779 }
8780 inst.reloc.type = BFD_RELOC_UNUSED;
8781 }
8782 else if (inst.operands[i].preind)
8783 {
5be8be5d 8784 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 8785 constraint (is_t && inst.operands[i].writeback,
c19d1205 8786 _("cannot use writeback with this instruction"));
5be8be5d
DG
8787 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8788 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
c19d1205
ZW
8789
8790 if (is_d)
8791 {
8792 inst.instruction |= 0x01000000;
8793 if (inst.operands[i].writeback)
8794 inst.instruction |= 0x00200000;
b99bd4ef 8795 }
c19d1205 8796 else
b99bd4ef 8797 {
c19d1205
ZW
8798 inst.instruction |= 0x00000c00;
8799 if (inst.operands[i].writeback)
8800 inst.instruction |= 0x00000100;
b99bd4ef 8801 }
c19d1205 8802 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8803 }
c19d1205 8804 else if (inst.operands[i].postind)
b99bd4ef 8805 {
9c2799c2 8806 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8807 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8808 constraint (is_t, _("cannot use post-indexing with this instruction"));
8809
8810 if (is_d)
8811 inst.instruction |= 0x00200000;
8812 else
8813 inst.instruction |= 0x00000900;
8814 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8815 }
8816 else /* unindexed - only for coprocessor */
8817 inst.error = _("instruction does not accept unindexed addressing");
8818}
8819
8820/* Table of Thumb instructions which exist in both 16- and 32-bit
8821 encodings (the latter only in post-V6T2 cores). The index is the
8822 value used in the insns table below. When there is more than one
8823 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8824 holds variant (1).
8825 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8826#define T16_32_TAB \
21d799b5
NC
8827 X(_adc, 4140, eb400000), \
8828 X(_adcs, 4140, eb500000), \
8829 X(_add, 1c00, eb000000), \
8830 X(_adds, 1c00, eb100000), \
8831 X(_addi, 0000, f1000000), \
8832 X(_addis, 0000, f1100000), \
8833 X(_add_pc,000f, f20f0000), \
8834 X(_add_sp,000d, f10d0000), \
8835 X(_adr, 000f, f20f0000), \
8836 X(_and, 4000, ea000000), \
8837 X(_ands, 4000, ea100000), \
8838 X(_asr, 1000, fa40f000), \
8839 X(_asrs, 1000, fa50f000), \
8840 X(_b, e000, f000b000), \
8841 X(_bcond, d000, f0008000), \
8842 X(_bic, 4380, ea200000), \
8843 X(_bics, 4380, ea300000), \
8844 X(_cmn, 42c0, eb100f00), \
8845 X(_cmp, 2800, ebb00f00), \
8846 X(_cpsie, b660, f3af8400), \
8847 X(_cpsid, b670, f3af8600), \
8848 X(_cpy, 4600, ea4f0000), \
8849 X(_dec_sp,80dd, f1ad0d00), \
8850 X(_eor, 4040, ea800000), \
8851 X(_eors, 4040, ea900000), \
8852 X(_inc_sp,00dd, f10d0d00), \
8853 X(_ldmia, c800, e8900000), \
8854 X(_ldr, 6800, f8500000), \
8855 X(_ldrb, 7800, f8100000), \
8856 X(_ldrh, 8800, f8300000), \
8857 X(_ldrsb, 5600, f9100000), \
8858 X(_ldrsh, 5e00, f9300000), \
8859 X(_ldr_pc,4800, f85f0000), \
8860 X(_ldr_pc2,4800, f85f0000), \
8861 X(_ldr_sp,9800, f85d0000), \
8862 X(_lsl, 0000, fa00f000), \
8863 X(_lsls, 0000, fa10f000), \
8864 X(_lsr, 0800, fa20f000), \
8865 X(_lsrs, 0800, fa30f000), \
8866 X(_mov, 2000, ea4f0000), \
8867 X(_movs, 2000, ea5f0000), \
8868 X(_mul, 4340, fb00f000), \
8869 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8870 X(_mvn, 43c0, ea6f0000), \
8871 X(_mvns, 43c0, ea7f0000), \
8872 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8873 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8874 X(_orr, 4300, ea400000), \
8875 X(_orrs, 4300, ea500000), \
8876 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8877 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8878 X(_rev, ba00, fa90f080), \
8879 X(_rev16, ba40, fa90f090), \
8880 X(_revsh, bac0, fa90f0b0), \
8881 X(_ror, 41c0, fa60f000), \
8882 X(_rors, 41c0, fa70f000), \
8883 X(_sbc, 4180, eb600000), \
8884 X(_sbcs, 4180, eb700000), \
8885 X(_stmia, c000, e8800000), \
8886 X(_str, 6000, f8400000), \
8887 X(_strb, 7000, f8000000), \
8888 X(_strh, 8000, f8200000), \
8889 X(_str_sp,9000, f84d0000), \
8890 X(_sub, 1e00, eba00000), \
8891 X(_subs, 1e00, ebb00000), \
8892 X(_subi, 8000, f1a00000), \
8893 X(_subis, 8000, f1b00000), \
8894 X(_sxtb, b240, fa4ff080), \
8895 X(_sxth, b200, fa0ff080), \
8896 X(_tst, 4200, ea100f00), \
8897 X(_uxtb, b2c0, fa5ff080), \
8898 X(_uxth, b280, fa1ff080), \
8899 X(_nop, bf00, f3af8000), \
8900 X(_yield, bf10, f3af8001), \
8901 X(_wfe, bf20, f3af8002), \
8902 X(_wfi, bf30, f3af8003), \
8903 X(_sev, bf40, f3af8004),
c19d1205
ZW
8904
8905/* To catch errors in encoding functions, the codes are all offset by
8906 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8907 as 16-bit instructions. */
21d799b5 8908#define X(a,b,c) T_MNEM##a
c19d1205
ZW
8909enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8910#undef X
8911
8912#define X(a,b,c) 0x##b
8913static const unsigned short thumb_op16[] = { T16_32_TAB };
8914#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8915#undef X
8916
8917#define X(a,b,c) 0x##c
8918static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
8919#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8920#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
8921#undef X
8922#undef T16_32_TAB
8923
8924/* Thumb instruction encoders, in alphabetical order. */
8925
92e90b6e 8926/* ADDW or SUBW. */
c921be7d 8927
92e90b6e
PB
8928static void
8929do_t_add_sub_w (void)
8930{
8931 int Rd, Rn;
8932
8933 Rd = inst.operands[0].reg;
8934 Rn = inst.operands[1].reg;
8935
539d4391
NC
8936 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8937 is the SP-{plus,minus}-immediate form of the instruction. */
8938 if (Rn == REG_SP)
8939 constraint (Rd == REG_PC, BAD_PC);
8940 else
8941 reject_bad_reg (Rd);
fdfde340 8942
92e90b6e
PB
8943 inst.instruction |= (Rn << 16) | (Rd << 8);
8944 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8945}
8946
c19d1205
ZW
8947/* Parse an add or subtract instruction. We get here with inst.instruction
8948 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8949
8950static void
8951do_t_add_sub (void)
8952{
8953 int Rd, Rs, Rn;
8954
8955 Rd = inst.operands[0].reg;
8956 Rs = (inst.operands[1].present
8957 ? inst.operands[1].reg /* Rd, Rs, foo */
8958 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8959
e07e6e58
NC
8960 if (Rd == REG_PC)
8961 set_it_insn_type_last ();
8962
c19d1205
ZW
8963 if (unified_syntax)
8964 {
0110f2b8
PB
8965 bfd_boolean flags;
8966 bfd_boolean narrow;
8967 int opcode;
8968
8969 flags = (inst.instruction == T_MNEM_adds
8970 || inst.instruction == T_MNEM_subs);
8971 if (flags)
e07e6e58 8972 narrow = !in_it_block ();
0110f2b8 8973 else
e07e6e58 8974 narrow = in_it_block ();
c19d1205 8975 if (!inst.operands[2].isreg)
b99bd4ef 8976 {
16805f35
PB
8977 int add;
8978
fdfde340
JM
8979 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8980
16805f35
PB
8981 add = (inst.instruction == T_MNEM_add
8982 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8983 opcode = 0;
8984 if (inst.size_req != 4)
8985 {
0110f2b8
PB
8986 /* Attempt to use a narrow opcode, with relaxation if
8987 appropriate. */
8988 if (Rd == REG_SP && Rs == REG_SP && !flags)
8989 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8990 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8991 opcode = T_MNEM_add_sp;
8992 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8993 opcode = T_MNEM_add_pc;
8994 else if (Rd <= 7 && Rs <= 7 && narrow)
8995 {
8996 if (flags)
8997 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8998 else
8999 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9000 }
9001 if (opcode)
9002 {
9003 inst.instruction = THUMB_OP16(opcode);
9004 inst.instruction |= (Rd << 4) | Rs;
9005 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9006 if (inst.size_req != 2)
9007 inst.relax = opcode;
9008 }
9009 else
9010 constraint (inst.size_req == 2, BAD_HIREG);
9011 }
9012 if (inst.size_req == 4
9013 || (inst.size_req != 2 && !opcode))
9014 {
efd81785
PB
9015 if (Rd == REG_PC)
9016 {
fdfde340 9017 constraint (add, BAD_PC);
efd81785
PB
9018 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9019 _("only SUBS PC, LR, #const allowed"));
9020 constraint (inst.reloc.exp.X_op != O_constant,
9021 _("expression too complex"));
9022 constraint (inst.reloc.exp.X_add_number < 0
9023 || inst.reloc.exp.X_add_number > 0xff,
9024 _("immediate value out of range"));
9025 inst.instruction = T2_SUBS_PC_LR
9026 | inst.reloc.exp.X_add_number;
9027 inst.reloc.type = BFD_RELOC_UNUSED;
9028 return;
9029 }
9030 else if (Rs == REG_PC)
16805f35
PB
9031 {
9032 /* Always use addw/subw. */
9033 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9034 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9035 }
9036 else
9037 {
9038 inst.instruction = THUMB_OP32 (inst.instruction);
9039 inst.instruction = (inst.instruction & 0xe1ffffff)
9040 | 0x10000000;
9041 if (flags)
9042 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9043 else
9044 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9045 }
dc4503c6
PB
9046 inst.instruction |= Rd << 8;
9047 inst.instruction |= Rs << 16;
0110f2b8 9048 }
b99bd4ef 9049 }
c19d1205
ZW
9050 else
9051 {
9052 Rn = inst.operands[2].reg;
9053 /* See if we can do this with a 16-bit instruction. */
9054 if (!inst.operands[2].shifted && inst.size_req != 4)
9055 {
e27ec89e
PB
9056 if (Rd > 7 || Rs > 7 || Rn > 7)
9057 narrow = FALSE;
9058
9059 if (narrow)
c19d1205 9060 {
e27ec89e
PB
9061 inst.instruction = ((inst.instruction == T_MNEM_adds
9062 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9063 ? T_OPCODE_ADD_R3
9064 : T_OPCODE_SUB_R3);
9065 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9066 return;
9067 }
b99bd4ef 9068
7e806470 9069 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9070 {
7e806470
PB
9071 /* Thumb-1 cores (except v6-M) require at least one high
9072 register in a narrow non flag setting add. */
9073 if (Rd > 7 || Rn > 7
9074 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9075 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9076 {
7e806470
PB
9077 if (Rd == Rn)
9078 {
9079 Rn = Rs;
9080 Rs = Rd;
9081 }
c19d1205
ZW
9082 inst.instruction = T_OPCODE_ADD_HI;
9083 inst.instruction |= (Rd & 8) << 4;
9084 inst.instruction |= (Rd & 7);
9085 inst.instruction |= Rn << 3;
9086 return;
9087 }
c19d1205
ZW
9088 }
9089 }
c921be7d 9090
fdfde340
JM
9091 constraint (Rd == REG_PC, BAD_PC);
9092 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9093 constraint (Rs == REG_PC, BAD_PC);
9094 reject_bad_reg (Rn);
9095
c19d1205
ZW
9096 /* If we get here, it can't be done in 16 bits. */
9097 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9098 _("shift must be constant"));
9099 inst.instruction = THUMB_OP32 (inst.instruction);
9100 inst.instruction |= Rd << 8;
9101 inst.instruction |= Rs << 16;
9102 encode_thumb32_shifted_operand (2);
9103 }
9104 }
9105 else
9106 {
9107 constraint (inst.instruction == T_MNEM_adds
9108 || inst.instruction == T_MNEM_subs,
9109 BAD_THUMB32);
b99bd4ef 9110
c19d1205 9111 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9112 {
c19d1205
ZW
9113 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9114 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9115 BAD_HIREG);
9116
9117 inst.instruction = (inst.instruction == T_MNEM_add
9118 ? 0x0000 : 0x8000);
9119 inst.instruction |= (Rd << 4) | Rs;
9120 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9121 return;
9122 }
9123
c19d1205
ZW
9124 Rn = inst.operands[2].reg;
9125 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9126
c19d1205
ZW
9127 /* We now have Rd, Rs, and Rn set to registers. */
9128 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9129 {
c19d1205
ZW
9130 /* Can't do this for SUB. */
9131 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9132 inst.instruction = T_OPCODE_ADD_HI;
9133 inst.instruction |= (Rd & 8) << 4;
9134 inst.instruction |= (Rd & 7);
9135 if (Rs == Rd)
9136 inst.instruction |= Rn << 3;
9137 else if (Rn == Rd)
9138 inst.instruction |= Rs << 3;
9139 else
9140 constraint (1, _("dest must overlap one source register"));
9141 }
9142 else
9143 {
9144 inst.instruction = (inst.instruction == T_MNEM_add
9145 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9146 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9147 }
b99bd4ef 9148 }
b99bd4ef
NC
9149}
9150
c19d1205
ZW
9151static void
9152do_t_adr (void)
9153{
fdfde340
JM
9154 unsigned Rd;
9155
9156 Rd = inst.operands[0].reg;
9157 reject_bad_reg (Rd);
9158
9159 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9160 {
9161 /* Defer to section relaxation. */
9162 inst.relax = inst.instruction;
9163 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9164 inst.instruction |= Rd << 4;
0110f2b8
PB
9165 }
9166 else if (unified_syntax && inst.size_req != 2)
e9f89963 9167 {
0110f2b8 9168 /* Generate a 32-bit opcode. */
e9f89963 9169 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9170 inst.instruction |= Rd << 8;
e9f89963
PB
9171 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9172 inst.reloc.pc_rel = 1;
9173 }
9174 else
9175 {
0110f2b8 9176 /* Generate a 16-bit opcode. */
e9f89963
PB
9177 inst.instruction = THUMB_OP16 (inst.instruction);
9178 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9179 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9180 inst.reloc.pc_rel = 1;
b99bd4ef 9181
fdfde340 9182 inst.instruction |= Rd << 4;
e9f89963 9183 }
c19d1205 9184}
b99bd4ef 9185
c19d1205
ZW
9186/* Arithmetic instructions for which there is just one 16-bit
9187 instruction encoding, and it allows only two low registers.
9188 For maximal compatibility with ARM syntax, we allow three register
9189 operands even when Thumb-32 instructions are not available, as long
9190 as the first two are identical. For instance, both "sbc r0,r1" and
9191 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9192static void
c19d1205 9193do_t_arit3 (void)
b99bd4ef 9194{
c19d1205 9195 int Rd, Rs, Rn;
b99bd4ef 9196
c19d1205
ZW
9197 Rd = inst.operands[0].reg;
9198 Rs = (inst.operands[1].present
9199 ? inst.operands[1].reg /* Rd, Rs, foo */
9200 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9201 Rn = inst.operands[2].reg;
b99bd4ef 9202
fdfde340
JM
9203 reject_bad_reg (Rd);
9204 reject_bad_reg (Rs);
9205 if (inst.operands[2].isreg)
9206 reject_bad_reg (Rn);
9207
c19d1205 9208 if (unified_syntax)
b99bd4ef 9209 {
c19d1205
ZW
9210 if (!inst.operands[2].isreg)
9211 {
9212 /* For an immediate, we always generate a 32-bit opcode;
9213 section relaxation will shrink it later if possible. */
9214 inst.instruction = THUMB_OP32 (inst.instruction);
9215 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9216 inst.instruction |= Rd << 8;
9217 inst.instruction |= Rs << 16;
9218 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9219 }
9220 else
9221 {
e27ec89e
PB
9222 bfd_boolean narrow;
9223
c19d1205 9224 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9225 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9226 narrow = !in_it_block ();
e27ec89e 9227 else
e07e6e58 9228 narrow = in_it_block ();
e27ec89e
PB
9229
9230 if (Rd > 7 || Rn > 7 || Rs > 7)
9231 narrow = FALSE;
9232 if (inst.operands[2].shifted)
9233 narrow = FALSE;
9234 if (inst.size_req == 4)
9235 narrow = FALSE;
9236
9237 if (narrow
c19d1205
ZW
9238 && Rd == Rs)
9239 {
9240 inst.instruction = THUMB_OP16 (inst.instruction);
9241 inst.instruction |= Rd;
9242 inst.instruction |= Rn << 3;
9243 return;
9244 }
b99bd4ef 9245
c19d1205
ZW
9246 /* If we get here, it can't be done in 16 bits. */
9247 constraint (inst.operands[2].shifted
9248 && inst.operands[2].immisreg,
9249 _("shift must be constant"));
9250 inst.instruction = THUMB_OP32 (inst.instruction);
9251 inst.instruction |= Rd << 8;
9252 inst.instruction |= Rs << 16;
9253 encode_thumb32_shifted_operand (2);
9254 }
a737bd4d 9255 }
c19d1205 9256 else
b99bd4ef 9257 {
c19d1205
ZW
9258 /* On its face this is a lie - the instruction does set the
9259 flags. However, the only supported mnemonic in this mode
9260 says it doesn't. */
9261 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9262
c19d1205
ZW
9263 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9264 _("unshifted register required"));
9265 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9266 constraint (Rd != Rs,
9267 _("dest and source1 must be the same register"));
a737bd4d 9268
c19d1205
ZW
9269 inst.instruction = THUMB_OP16 (inst.instruction);
9270 inst.instruction |= Rd;
9271 inst.instruction |= Rn << 3;
b99bd4ef 9272 }
a737bd4d 9273}
b99bd4ef 9274
c19d1205
ZW
9275/* Similarly, but for instructions where the arithmetic operation is
9276 commutative, so we can allow either of them to be different from
9277 the destination operand in a 16-bit instruction. For instance, all
9278 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9279 accepted. */
9280static void
9281do_t_arit3c (void)
a737bd4d 9282{
c19d1205 9283 int Rd, Rs, Rn;
b99bd4ef 9284
c19d1205
ZW
9285 Rd = inst.operands[0].reg;
9286 Rs = (inst.operands[1].present
9287 ? inst.operands[1].reg /* Rd, Rs, foo */
9288 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9289 Rn = inst.operands[2].reg;
c921be7d 9290
fdfde340
JM
9291 reject_bad_reg (Rd);
9292 reject_bad_reg (Rs);
9293 if (inst.operands[2].isreg)
9294 reject_bad_reg (Rn);
a737bd4d 9295
c19d1205 9296 if (unified_syntax)
a737bd4d 9297 {
c19d1205 9298 if (!inst.operands[2].isreg)
b99bd4ef 9299 {
c19d1205
ZW
9300 /* For an immediate, we always generate a 32-bit opcode;
9301 section relaxation will shrink it later if possible. */
9302 inst.instruction = THUMB_OP32 (inst.instruction);
9303 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9304 inst.instruction |= Rd << 8;
9305 inst.instruction |= Rs << 16;
9306 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9307 }
c19d1205 9308 else
a737bd4d 9309 {
e27ec89e
PB
9310 bfd_boolean narrow;
9311
c19d1205 9312 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9313 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9314 narrow = !in_it_block ();
e27ec89e 9315 else
e07e6e58 9316 narrow = in_it_block ();
e27ec89e
PB
9317
9318 if (Rd > 7 || Rn > 7 || Rs > 7)
9319 narrow = FALSE;
9320 if (inst.operands[2].shifted)
9321 narrow = FALSE;
9322 if (inst.size_req == 4)
9323 narrow = FALSE;
9324
9325 if (narrow)
a737bd4d 9326 {
c19d1205 9327 if (Rd == Rs)
a737bd4d 9328 {
c19d1205
ZW
9329 inst.instruction = THUMB_OP16 (inst.instruction);
9330 inst.instruction |= Rd;
9331 inst.instruction |= Rn << 3;
9332 return;
a737bd4d 9333 }
c19d1205 9334 if (Rd == Rn)
a737bd4d 9335 {
c19d1205
ZW
9336 inst.instruction = THUMB_OP16 (inst.instruction);
9337 inst.instruction |= Rd;
9338 inst.instruction |= Rs << 3;
9339 return;
a737bd4d
NC
9340 }
9341 }
c19d1205
ZW
9342
9343 /* If we get here, it can't be done in 16 bits. */
9344 constraint (inst.operands[2].shifted
9345 && inst.operands[2].immisreg,
9346 _("shift must be constant"));
9347 inst.instruction = THUMB_OP32 (inst.instruction);
9348 inst.instruction |= Rd << 8;
9349 inst.instruction |= Rs << 16;
9350 encode_thumb32_shifted_operand (2);
a737bd4d 9351 }
b99bd4ef 9352 }
c19d1205
ZW
9353 else
9354 {
9355 /* On its face this is a lie - the instruction does set the
9356 flags. However, the only supported mnemonic in this mode
9357 says it doesn't. */
9358 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9359
c19d1205
ZW
9360 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9361 _("unshifted register required"));
9362 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9363
9364 inst.instruction = THUMB_OP16 (inst.instruction);
9365 inst.instruction |= Rd;
9366
9367 if (Rd == Rs)
9368 inst.instruction |= Rn << 3;
9369 else if (Rd == Rn)
9370 inst.instruction |= Rs << 3;
9371 else
9372 constraint (1, _("dest must overlap one source register"));
9373 }
a737bd4d
NC
9374}
9375
62b3e311
PB
9376static void
9377do_t_barrier (void)
9378{
9379 if (inst.operands[0].present)
9380 {
9381 constraint ((inst.instruction & 0xf0) != 0x40
9382 && inst.operands[0].imm != 0xf,
bd3ba5d1 9383 _("bad barrier type"));
62b3e311
PB
9384 inst.instruction |= inst.operands[0].imm;
9385 }
9386 else
9387 inst.instruction |= 0xf;
9388}
9389
c19d1205
ZW
9390static void
9391do_t_bfc (void)
a737bd4d 9392{
fdfde340 9393 unsigned Rd;
c19d1205
ZW
9394 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9395 constraint (msb > 32, _("bit-field extends past end of register"));
9396 /* The instruction encoding stores the LSB and MSB,
9397 not the LSB and width. */
fdfde340
JM
9398 Rd = inst.operands[0].reg;
9399 reject_bad_reg (Rd);
9400 inst.instruction |= Rd << 8;
c19d1205
ZW
9401 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9402 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9403 inst.instruction |= msb - 1;
b99bd4ef
NC
9404}
9405
c19d1205
ZW
9406static void
9407do_t_bfi (void)
b99bd4ef 9408{
fdfde340 9409 int Rd, Rn;
c19d1205 9410 unsigned int msb;
b99bd4ef 9411
fdfde340
JM
9412 Rd = inst.operands[0].reg;
9413 reject_bad_reg (Rd);
9414
c19d1205
ZW
9415 /* #0 in second position is alternative syntax for bfc, which is
9416 the same instruction but with REG_PC in the Rm field. */
9417 if (!inst.operands[1].isreg)
fdfde340
JM
9418 Rn = REG_PC;
9419 else
9420 {
9421 Rn = inst.operands[1].reg;
9422 reject_bad_reg (Rn);
9423 }
b99bd4ef 9424
c19d1205
ZW
9425 msb = inst.operands[2].imm + inst.operands[3].imm;
9426 constraint (msb > 32, _("bit-field extends past end of register"));
9427 /* The instruction encoding stores the LSB and MSB,
9428 not the LSB and width. */
fdfde340
JM
9429 inst.instruction |= Rd << 8;
9430 inst.instruction |= Rn << 16;
c19d1205
ZW
9431 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9432 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9433 inst.instruction |= msb - 1;
b99bd4ef
NC
9434}
9435
c19d1205
ZW
9436static void
9437do_t_bfx (void)
b99bd4ef 9438{
fdfde340
JM
9439 unsigned Rd, Rn;
9440
9441 Rd = inst.operands[0].reg;
9442 Rn = inst.operands[1].reg;
9443
9444 reject_bad_reg (Rd);
9445 reject_bad_reg (Rn);
9446
c19d1205
ZW
9447 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9448 _("bit-field extends past end of register"));
fdfde340
JM
9449 inst.instruction |= Rd << 8;
9450 inst.instruction |= Rn << 16;
c19d1205
ZW
9451 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9452 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9453 inst.instruction |= inst.operands[3].imm - 1;
9454}
b99bd4ef 9455
c19d1205
ZW
9456/* ARM V5 Thumb BLX (argument parse)
9457 BLX <target_addr> which is BLX(1)
9458 BLX <Rm> which is BLX(2)
9459 Unfortunately, there are two different opcodes for this mnemonic.
9460 So, the insns[].value is not used, and the code here zaps values
9461 into inst.instruction.
b99bd4ef 9462
c19d1205
ZW
9463 ??? How to take advantage of the additional two bits of displacement
9464 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9465
c19d1205
ZW
9466static void
9467do_t_blx (void)
9468{
e07e6e58
NC
9469 set_it_insn_type_last ();
9470
c19d1205 9471 if (inst.operands[0].isreg)
fdfde340
JM
9472 {
9473 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9474 /* We have a register, so this is BLX(2). */
9475 inst.instruction |= inst.operands[0].reg << 3;
9476 }
b99bd4ef
NC
9477 else
9478 {
c19d1205 9479 /* No register. This must be BLX(1). */
2fc8bdac 9480 inst.instruction = 0xf000e800;
00adf2d4 9481 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9482 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9483 }
9484}
9485
c19d1205
ZW
9486static void
9487do_t_branch (void)
b99bd4ef 9488{
0110f2b8 9489 int opcode;
dfa9f0d5
PB
9490 int cond;
9491
e07e6e58
NC
9492 cond = inst.cond;
9493 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9494
9495 if (in_it_block ())
dfa9f0d5
PB
9496 {
9497 /* Conditional branches inside IT blocks are encoded as unconditional
9498 branches. */
9499 cond = COND_ALWAYS;
dfa9f0d5
PB
9500 }
9501 else
9502 cond = inst.cond;
9503
9504 if (cond != COND_ALWAYS)
0110f2b8
PB
9505 opcode = T_MNEM_bcond;
9506 else
9507 opcode = inst.instruction;
9508
9509 if (unified_syntax && inst.size_req == 4)
c19d1205 9510 {
0110f2b8 9511 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9512 if (cond == COND_ALWAYS)
0110f2b8 9513 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9514 else
9515 {
9c2799c2 9516 gas_assert (cond != 0xF);
dfa9f0d5 9517 inst.instruction |= cond << 22;
c19d1205
ZW
9518 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9519 }
9520 }
b99bd4ef
NC
9521 else
9522 {
0110f2b8 9523 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9524 if (cond == COND_ALWAYS)
c19d1205
ZW
9525 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9526 else
b99bd4ef 9527 {
dfa9f0d5 9528 inst.instruction |= cond << 8;
c19d1205 9529 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9530 }
0110f2b8
PB
9531 /* Allow section relaxation. */
9532 if (unified_syntax && inst.size_req != 2)
9533 inst.relax = opcode;
b99bd4ef 9534 }
c19d1205
ZW
9535
9536 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9537}
9538
9539static void
c19d1205 9540do_t_bkpt (void)
b99bd4ef 9541{
dfa9f0d5
PB
9542 constraint (inst.cond != COND_ALWAYS,
9543 _("instruction is always unconditional"));
c19d1205 9544 if (inst.operands[0].present)
b99bd4ef 9545 {
c19d1205
ZW
9546 constraint (inst.operands[0].imm > 255,
9547 _("immediate value out of range"));
9548 inst.instruction |= inst.operands[0].imm;
e07e6e58 9549 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9550 }
b99bd4ef
NC
9551}
9552
9553static void
c19d1205 9554do_t_branch23 (void)
b99bd4ef 9555{
e07e6e58 9556 set_it_insn_type_last ();
c19d1205 9557 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9558 inst.reloc.pc_rel = 1;
9559
4343666d 9560#if defined(OBJ_COFF)
c19d1205
ZW
9561 /* If the destination of the branch is a defined symbol which does not have
9562 the THUMB_FUNC attribute, then we must be calling a function which has
9563 the (interfacearm) attribute. We look for the Thumb entry point to that
9564 function and change the branch to refer to that function instead. */
9565 if ( inst.reloc.exp.X_op == O_symbol
9566 && inst.reloc.exp.X_add_symbol != NULL
9567 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9568 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9569 inst.reloc.exp.X_add_symbol =
9570 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9571#endif
90e4755a
RE
9572}
9573
9574static void
c19d1205 9575do_t_bx (void)
90e4755a 9576{
e07e6e58 9577 set_it_insn_type_last ();
c19d1205
ZW
9578 inst.instruction |= inst.operands[0].reg << 3;
9579 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9580 should cause the alignment to be checked once it is known. This is
9581 because BX PC only works if the instruction is word aligned. */
9582}
90e4755a 9583
c19d1205
ZW
9584static void
9585do_t_bxj (void)
9586{
fdfde340 9587 int Rm;
90e4755a 9588
e07e6e58 9589 set_it_insn_type_last ();
fdfde340
JM
9590 Rm = inst.operands[0].reg;
9591 reject_bad_reg (Rm);
9592 inst.instruction |= Rm << 16;
90e4755a
RE
9593}
9594
9595static void
c19d1205 9596do_t_clz (void)
90e4755a 9597{
fdfde340
JM
9598 unsigned Rd;
9599 unsigned Rm;
9600
9601 Rd = inst.operands[0].reg;
9602 Rm = inst.operands[1].reg;
9603
9604 reject_bad_reg (Rd);
9605 reject_bad_reg (Rm);
9606
9607 inst.instruction |= Rd << 8;
9608 inst.instruction |= Rm << 16;
9609 inst.instruction |= Rm;
c19d1205 9610}
90e4755a 9611
dfa9f0d5
PB
9612static void
9613do_t_cps (void)
9614{
e07e6e58 9615 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9616 inst.instruction |= inst.operands[0].imm;
9617}
9618
c19d1205
ZW
9619static void
9620do_t_cpsi (void)
9621{
e07e6e58 9622 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9623 if (unified_syntax
62b3e311
PB
9624 && (inst.operands[1].present || inst.size_req == 4)
9625 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9626 {
c19d1205
ZW
9627 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9628 inst.instruction = 0xf3af8000;
9629 inst.instruction |= imod << 9;
9630 inst.instruction |= inst.operands[0].imm << 5;
9631 if (inst.operands[1].present)
9632 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9633 }
c19d1205 9634 else
90e4755a 9635 {
62b3e311
PB
9636 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9637 && (inst.operands[0].imm & 4),
9638 _("selected processor does not support 'A' form "
9639 "of this instruction"));
9640 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9641 _("Thumb does not support the 2-argument "
9642 "form of this instruction"));
9643 inst.instruction |= inst.operands[0].imm;
90e4755a 9644 }
90e4755a
RE
9645}
9646
c19d1205
ZW
9647/* THUMB CPY instruction (argument parse). */
9648
90e4755a 9649static void
c19d1205 9650do_t_cpy (void)
90e4755a 9651{
c19d1205 9652 if (inst.size_req == 4)
90e4755a 9653 {
c19d1205
ZW
9654 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9655 inst.instruction |= inst.operands[0].reg << 8;
9656 inst.instruction |= inst.operands[1].reg;
90e4755a 9657 }
c19d1205 9658 else
90e4755a 9659 {
c19d1205
ZW
9660 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9661 inst.instruction |= (inst.operands[0].reg & 0x7);
9662 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9663 }
90e4755a
RE
9664}
9665
90e4755a 9666static void
25fe350b 9667do_t_cbz (void)
90e4755a 9668{
e07e6e58 9669 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9670 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9671 inst.instruction |= inst.operands[0].reg;
9672 inst.reloc.pc_rel = 1;
9673 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9674}
90e4755a 9675
62b3e311
PB
9676static void
9677do_t_dbg (void)
9678{
9679 inst.instruction |= inst.operands[0].imm;
9680}
9681
9682static void
9683do_t_div (void)
9684{
fdfde340
JM
9685 unsigned Rd, Rn, Rm;
9686
9687 Rd = inst.operands[0].reg;
9688 Rn = (inst.operands[1].present
9689 ? inst.operands[1].reg : Rd);
9690 Rm = inst.operands[2].reg;
9691
9692 reject_bad_reg (Rd);
9693 reject_bad_reg (Rn);
9694 reject_bad_reg (Rm);
9695
9696 inst.instruction |= Rd << 8;
9697 inst.instruction |= Rn << 16;
9698 inst.instruction |= Rm;
62b3e311
PB
9699}
9700
c19d1205
ZW
9701static void
9702do_t_hint (void)
9703{
9704 if (unified_syntax && inst.size_req == 4)
9705 inst.instruction = THUMB_OP32 (inst.instruction);
9706 else
9707 inst.instruction = THUMB_OP16 (inst.instruction);
9708}
90e4755a 9709
c19d1205
ZW
9710static void
9711do_t_it (void)
9712{
9713 unsigned int cond = inst.operands[0].imm;
e27ec89e 9714
e07e6e58
NC
9715 set_it_insn_type (IT_INSN);
9716 now_it.mask = (inst.instruction & 0xf) | 0x10;
9717 now_it.cc = cond;
e27ec89e
PB
9718
9719 /* If the condition is a negative condition, invert the mask. */
c19d1205 9720 if ((cond & 0x1) == 0x0)
90e4755a 9721 {
c19d1205 9722 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9723
c19d1205
ZW
9724 if ((mask & 0x7) == 0)
9725 /* no conversion needed */;
9726 else if ((mask & 0x3) == 0)
e27ec89e
PB
9727 mask ^= 0x8;
9728 else if ((mask & 0x1) == 0)
9729 mask ^= 0xC;
c19d1205 9730 else
e27ec89e 9731 mask ^= 0xE;
90e4755a 9732
e27ec89e
PB
9733 inst.instruction &= 0xfff0;
9734 inst.instruction |= mask;
c19d1205 9735 }
90e4755a 9736
c19d1205
ZW
9737 inst.instruction |= cond << 4;
9738}
90e4755a 9739
3c707909
PB
9740/* Helper function used for both push/pop and ldm/stm. */
9741static void
9742encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9743{
9744 bfd_boolean load;
9745
9746 load = (inst.instruction & (1 << 20)) != 0;
9747
9748 if (mask & (1 << 13))
9749 inst.error = _("SP not allowed in register list");
9750 if (load)
9751 {
e07e6e58
NC
9752 if (mask & (1 << 15))
9753 {
9754 if (mask & (1 << 14))
9755 inst.error = _("LR and PC should not both be in register list");
9756 else
9757 set_it_insn_type_last ();
9758 }
3c707909
PB
9759
9760 if ((mask & (1 << base)) != 0
9761 && writeback)
9762 as_warn (_("base register should not be in register list "
9763 "when written back"));
9764 }
9765 else
9766 {
9767 if (mask & (1 << 15))
9768 inst.error = _("PC not allowed in register list");
9769
9770 if (mask & (1 << base))
9771 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9772 }
9773
9774 if ((mask & (mask - 1)) == 0)
9775 {
9776 /* Single register transfers implemented as str/ldr. */
9777 if (writeback)
9778 {
9779 if (inst.instruction & (1 << 23))
9780 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9781 else
9782 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9783 }
9784 else
9785 {
9786 if (inst.instruction & (1 << 23))
9787 inst.instruction = 0x00800000; /* ia -> [base] */
9788 else
9789 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9790 }
9791
9792 inst.instruction |= 0xf8400000;
9793 if (load)
9794 inst.instruction |= 0x00100000;
9795
5f4273c7 9796 mask = ffs (mask) - 1;
3c707909
PB
9797 mask <<= 12;
9798 }
9799 else if (writeback)
9800 inst.instruction |= WRITE_BACK;
9801
9802 inst.instruction |= mask;
9803 inst.instruction |= base << 16;
9804}
9805
c19d1205
ZW
9806static void
9807do_t_ldmstm (void)
9808{
9809 /* This really doesn't seem worth it. */
9810 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9811 _("expression too complex"));
9812 constraint (inst.operands[1].writeback,
9813 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9814
c19d1205
ZW
9815 if (unified_syntax)
9816 {
3c707909
PB
9817 bfd_boolean narrow;
9818 unsigned mask;
9819
9820 narrow = FALSE;
c19d1205
ZW
9821 /* See if we can use a 16-bit instruction. */
9822 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9823 && inst.size_req != 4
3c707909 9824 && !(inst.operands[1].imm & ~0xff))
90e4755a 9825 {
3c707909 9826 mask = 1 << inst.operands[0].reg;
90e4755a 9827
3c707909
PB
9828 if (inst.operands[0].reg <= 7
9829 && (inst.instruction == T_MNEM_stmia
9830 ? inst.operands[0].writeback
9831 : (inst.operands[0].writeback
9832 == !(inst.operands[1].imm & mask))))
90e4755a 9833 {
3c707909
PB
9834 if (inst.instruction == T_MNEM_stmia
9835 && (inst.operands[1].imm & mask)
9836 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9837 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9838 inst.operands[0].reg);
3c707909
PB
9839
9840 inst.instruction = THUMB_OP16 (inst.instruction);
9841 inst.instruction |= inst.operands[0].reg << 8;
9842 inst.instruction |= inst.operands[1].imm;
9843 narrow = TRUE;
90e4755a 9844 }
3c707909
PB
9845 else if (inst.operands[0] .reg == REG_SP
9846 && inst.operands[0].writeback)
90e4755a 9847 {
3c707909
PB
9848 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9849 ? T_MNEM_push : T_MNEM_pop);
9850 inst.instruction |= inst.operands[1].imm;
9851 narrow = TRUE;
90e4755a 9852 }
3c707909
PB
9853 }
9854
9855 if (!narrow)
9856 {
c19d1205
ZW
9857 if (inst.instruction < 0xffff)
9858 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9859
5f4273c7
NC
9860 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9861 inst.operands[0].writeback);
90e4755a
RE
9862 }
9863 }
c19d1205 9864 else
90e4755a 9865 {
c19d1205
ZW
9866 constraint (inst.operands[0].reg > 7
9867 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9868 constraint (inst.instruction != T_MNEM_ldmia
9869 && inst.instruction != T_MNEM_stmia,
9870 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9871 if (inst.instruction == T_MNEM_stmia)
f03698e6 9872 {
c19d1205
ZW
9873 if (!inst.operands[0].writeback)
9874 as_warn (_("this instruction will write back the base register"));
9875 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9876 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9877 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9878 inst.operands[0].reg);
f03698e6 9879 }
c19d1205 9880 else
90e4755a 9881 {
c19d1205
ZW
9882 if (!inst.operands[0].writeback
9883 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9884 as_warn (_("this instruction will write back the base register"));
9885 else if (inst.operands[0].writeback
9886 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9887 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9888 }
9889
c19d1205
ZW
9890 inst.instruction = THUMB_OP16 (inst.instruction);
9891 inst.instruction |= inst.operands[0].reg << 8;
9892 inst.instruction |= inst.operands[1].imm;
9893 }
9894}
e28cd48c 9895
c19d1205
ZW
9896static void
9897do_t_ldrex (void)
9898{
9899 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9900 || inst.operands[1].postind || inst.operands[1].writeback
9901 || inst.operands[1].immisreg || inst.operands[1].shifted
9902 || inst.operands[1].negative,
01cfc07f 9903 BAD_ADDR_MODE);
e28cd48c 9904
5be8be5d
DG
9905 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9906
c19d1205
ZW
9907 inst.instruction |= inst.operands[0].reg << 12;
9908 inst.instruction |= inst.operands[1].reg << 16;
9909 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9910}
e28cd48c 9911
c19d1205
ZW
9912static void
9913do_t_ldrexd (void)
9914{
9915 if (!inst.operands[1].present)
1cac9012 9916 {
c19d1205
ZW
9917 constraint (inst.operands[0].reg == REG_LR,
9918 _("r14 not allowed as first register "
9919 "when second register is omitted"));
9920 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9921 }
c19d1205
ZW
9922 constraint (inst.operands[0].reg == inst.operands[1].reg,
9923 BAD_OVERLAP);
b99bd4ef 9924
c19d1205
ZW
9925 inst.instruction |= inst.operands[0].reg << 12;
9926 inst.instruction |= inst.operands[1].reg << 8;
9927 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9928}
9929
9930static void
c19d1205 9931do_t_ldst (void)
b99bd4ef 9932{
0110f2b8
PB
9933 unsigned long opcode;
9934 int Rn;
9935
e07e6e58
NC
9936 if (inst.operands[0].isreg
9937 && !inst.operands[0].preind
9938 && inst.operands[0].reg == REG_PC)
9939 set_it_insn_type_last ();
9940
0110f2b8 9941 opcode = inst.instruction;
c19d1205 9942 if (unified_syntax)
b99bd4ef 9943 {
53365c0d
PB
9944 if (!inst.operands[1].isreg)
9945 {
9946 if (opcode <= 0xffff)
9947 inst.instruction = THUMB_OP32 (opcode);
9948 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9949 return;
9950 }
0110f2b8
PB
9951 if (inst.operands[1].isreg
9952 && !inst.operands[1].writeback
c19d1205
ZW
9953 && !inst.operands[1].shifted && !inst.operands[1].postind
9954 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9955 && opcode <= 0xffff
9956 && inst.size_req != 4)
c19d1205 9957 {
0110f2b8
PB
9958 /* Insn may have a 16-bit form. */
9959 Rn = inst.operands[1].reg;
9960 if (inst.operands[1].immisreg)
9961 {
9962 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9963 /* [Rn, Rik] */
0110f2b8
PB
9964 if (Rn <= 7 && inst.operands[1].imm <= 7)
9965 goto op16;
5be8be5d
DG
9966 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
9967 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
9968 }
9969 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9970 && opcode != T_MNEM_ldrsb)
9971 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9972 || (Rn == REG_SP && opcode == T_MNEM_str))
9973 {
9974 /* [Rn, #const] */
9975 if (Rn > 7)
9976 {
9977 if (Rn == REG_PC)
9978 {
9979 if (inst.reloc.pc_rel)
9980 opcode = T_MNEM_ldr_pc2;
9981 else
9982 opcode = T_MNEM_ldr_pc;
9983 }
9984 else
9985 {
9986 if (opcode == T_MNEM_ldr)
9987 opcode = T_MNEM_ldr_sp;
9988 else
9989 opcode = T_MNEM_str_sp;
9990 }
9991 inst.instruction = inst.operands[0].reg << 8;
9992 }
9993 else
9994 {
9995 inst.instruction = inst.operands[0].reg;
9996 inst.instruction |= inst.operands[1].reg << 3;
9997 }
9998 inst.instruction |= THUMB_OP16 (opcode);
9999 if (inst.size_req == 2)
10000 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10001 else
10002 inst.relax = opcode;
10003 return;
10004 }
c19d1205 10005 }
0110f2b8 10006 /* Definitely a 32-bit variant. */
5be8be5d
DG
10007
10008 /* Do some validations regarding addressing modes. */
10009 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10010 && opcode != T_MNEM_str)
10011 reject_bad_reg (inst.operands[1].imm);
10012
0110f2b8 10013 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
10014 inst.instruction |= inst.operands[0].reg << 12;
10015 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
10016 return;
10017 }
10018
c19d1205
ZW
10019 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10020
10021 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 10022 {
c19d1205
ZW
10023 /* Only [Rn,Rm] is acceptable. */
10024 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10025 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10026 || inst.operands[1].postind || inst.operands[1].shifted
10027 || inst.operands[1].negative,
10028 _("Thumb does not support this addressing mode"));
10029 inst.instruction = THUMB_OP16 (inst.instruction);
10030 goto op16;
b99bd4ef 10031 }
5f4273c7 10032
c19d1205
ZW
10033 inst.instruction = THUMB_OP16 (inst.instruction);
10034 if (!inst.operands[1].isreg)
10035 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10036 return;
b99bd4ef 10037
c19d1205
ZW
10038 constraint (!inst.operands[1].preind
10039 || inst.operands[1].shifted
10040 || inst.operands[1].writeback,
10041 _("Thumb does not support this addressing mode"));
10042 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 10043 {
c19d1205
ZW
10044 constraint (inst.instruction & 0x0600,
10045 _("byte or halfword not valid for base register"));
10046 constraint (inst.operands[1].reg == REG_PC
10047 && !(inst.instruction & THUMB_LOAD_BIT),
10048 _("r15 based store not allowed"));
10049 constraint (inst.operands[1].immisreg,
10050 _("invalid base register for register offset"));
b99bd4ef 10051
c19d1205
ZW
10052 if (inst.operands[1].reg == REG_PC)
10053 inst.instruction = T_OPCODE_LDR_PC;
10054 else if (inst.instruction & THUMB_LOAD_BIT)
10055 inst.instruction = T_OPCODE_LDR_SP;
10056 else
10057 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10058
c19d1205
ZW
10059 inst.instruction |= inst.operands[0].reg << 8;
10060 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10061 return;
10062 }
90e4755a 10063
c19d1205
ZW
10064 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10065 if (!inst.operands[1].immisreg)
10066 {
10067 /* Immediate offset. */
10068 inst.instruction |= inst.operands[0].reg;
10069 inst.instruction |= inst.operands[1].reg << 3;
10070 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10071 return;
10072 }
90e4755a 10073
c19d1205
ZW
10074 /* Register offset. */
10075 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10076 constraint (inst.operands[1].negative,
10077 _("Thumb does not support this addressing mode"));
90e4755a 10078
c19d1205
ZW
10079 op16:
10080 switch (inst.instruction)
10081 {
10082 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10083 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10084 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10085 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10086 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10087 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10088 case 0x5600 /* ldrsb */:
10089 case 0x5e00 /* ldrsh */: break;
10090 default: abort ();
10091 }
90e4755a 10092
c19d1205
ZW
10093 inst.instruction |= inst.operands[0].reg;
10094 inst.instruction |= inst.operands[1].reg << 3;
10095 inst.instruction |= inst.operands[1].imm << 6;
10096}
90e4755a 10097
c19d1205
ZW
10098static void
10099do_t_ldstd (void)
10100{
10101 if (!inst.operands[1].present)
b99bd4ef 10102 {
c19d1205
ZW
10103 inst.operands[1].reg = inst.operands[0].reg + 1;
10104 constraint (inst.operands[0].reg == REG_LR,
10105 _("r14 not allowed here"));
b99bd4ef 10106 }
c19d1205
ZW
10107 inst.instruction |= inst.operands[0].reg << 12;
10108 inst.instruction |= inst.operands[1].reg << 8;
10109 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10110}
10111
c19d1205
ZW
10112static void
10113do_t_ldstt (void)
10114{
10115 inst.instruction |= inst.operands[0].reg << 12;
10116 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10117}
a737bd4d 10118
b99bd4ef 10119static void
c19d1205 10120do_t_mla (void)
b99bd4ef 10121{
fdfde340 10122 unsigned Rd, Rn, Rm, Ra;
c921be7d 10123
fdfde340
JM
10124 Rd = inst.operands[0].reg;
10125 Rn = inst.operands[1].reg;
10126 Rm = inst.operands[2].reg;
10127 Ra = inst.operands[3].reg;
10128
10129 reject_bad_reg (Rd);
10130 reject_bad_reg (Rn);
10131 reject_bad_reg (Rm);
10132 reject_bad_reg (Ra);
10133
10134 inst.instruction |= Rd << 8;
10135 inst.instruction |= Rn << 16;
10136 inst.instruction |= Rm;
10137 inst.instruction |= Ra << 12;
c19d1205 10138}
b99bd4ef 10139
c19d1205
ZW
10140static void
10141do_t_mlal (void)
10142{
fdfde340
JM
10143 unsigned RdLo, RdHi, Rn, Rm;
10144
10145 RdLo = inst.operands[0].reg;
10146 RdHi = inst.operands[1].reg;
10147 Rn = inst.operands[2].reg;
10148 Rm = inst.operands[3].reg;
10149
10150 reject_bad_reg (RdLo);
10151 reject_bad_reg (RdHi);
10152 reject_bad_reg (Rn);
10153 reject_bad_reg (Rm);
10154
10155 inst.instruction |= RdLo << 12;
10156 inst.instruction |= RdHi << 8;
10157 inst.instruction |= Rn << 16;
10158 inst.instruction |= Rm;
c19d1205 10159}
b99bd4ef 10160
c19d1205
ZW
10161static void
10162do_t_mov_cmp (void)
10163{
fdfde340
JM
10164 unsigned Rn, Rm;
10165
10166 Rn = inst.operands[0].reg;
10167 Rm = inst.operands[1].reg;
10168
e07e6e58
NC
10169 if (Rn == REG_PC)
10170 set_it_insn_type_last ();
10171
c19d1205 10172 if (unified_syntax)
b99bd4ef 10173 {
c19d1205
ZW
10174 int r0off = (inst.instruction == T_MNEM_mov
10175 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10176 unsigned long opcode;
3d388997
PB
10177 bfd_boolean narrow;
10178 bfd_boolean low_regs;
10179
fdfde340 10180 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10181 opcode = inst.instruction;
e07e6e58 10182 if (in_it_block ())
0110f2b8 10183 narrow = opcode != T_MNEM_movs;
3d388997 10184 else
0110f2b8 10185 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10186 if (inst.size_req == 4
10187 || inst.operands[1].shifted)
10188 narrow = FALSE;
10189
efd81785
PB
10190 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10191 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10192 && !inst.operands[1].shifted
fdfde340
JM
10193 && Rn == REG_PC
10194 && Rm == REG_LR)
efd81785
PB
10195 {
10196 inst.instruction = T2_SUBS_PC_LR;
10197 return;
10198 }
10199
fdfde340
JM
10200 if (opcode == T_MNEM_cmp)
10201 {
10202 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10203 if (narrow)
10204 {
10205 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10206 but valid. */
10207 warn_deprecated_sp (Rm);
10208 /* R15 was documented as a valid choice for Rm in ARMv6,
10209 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10210 tools reject R15, so we do too. */
10211 constraint (Rm == REG_PC, BAD_PC);
10212 }
10213 else
10214 reject_bad_reg (Rm);
fdfde340
JM
10215 }
10216 else if (opcode == T_MNEM_mov
10217 || opcode == T_MNEM_movs)
10218 {
10219 if (inst.operands[1].isreg)
10220 {
10221 if (opcode == T_MNEM_movs)
10222 {
10223 reject_bad_reg (Rn);
10224 reject_bad_reg (Rm);
10225 }
10226 else if ((Rn == REG_SP || Rn == REG_PC)
10227 && (Rm == REG_SP || Rm == REG_PC))
10228 reject_bad_reg (Rm);
10229 }
10230 else
10231 reject_bad_reg (Rn);
10232 }
10233
c19d1205
ZW
10234 if (!inst.operands[1].isreg)
10235 {
0110f2b8 10236 /* Immediate operand. */
e07e6e58 10237 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10238 narrow = 0;
10239 if (low_regs && narrow)
10240 {
10241 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10242 inst.instruction |= Rn << 8;
0110f2b8
PB
10243 if (inst.size_req == 2)
10244 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10245 else
10246 inst.relax = opcode;
10247 }
10248 else
10249 {
10250 inst.instruction = THUMB_OP32 (inst.instruction);
10251 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10252 inst.instruction |= Rn << r0off;
0110f2b8
PB
10253 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10254 }
c19d1205 10255 }
728ca7c9
PB
10256 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10257 && (inst.instruction == T_MNEM_mov
10258 || inst.instruction == T_MNEM_movs))
10259 {
10260 /* Register shifts are encoded as separate shift instructions. */
10261 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10262
e07e6e58 10263 if (in_it_block ())
728ca7c9
PB
10264 narrow = !flags;
10265 else
10266 narrow = flags;
10267
10268 if (inst.size_req == 4)
10269 narrow = FALSE;
10270
10271 if (!low_regs || inst.operands[1].imm > 7)
10272 narrow = FALSE;
10273
fdfde340 10274 if (Rn != Rm)
728ca7c9
PB
10275 narrow = FALSE;
10276
10277 switch (inst.operands[1].shift_kind)
10278 {
10279 case SHIFT_LSL:
10280 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10281 break;
10282 case SHIFT_ASR:
10283 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10284 break;
10285 case SHIFT_LSR:
10286 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10287 break;
10288 case SHIFT_ROR:
10289 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10290 break;
10291 default:
5f4273c7 10292 abort ();
728ca7c9
PB
10293 }
10294
10295 inst.instruction = opcode;
10296 if (narrow)
10297 {
fdfde340 10298 inst.instruction |= Rn;
728ca7c9
PB
10299 inst.instruction |= inst.operands[1].imm << 3;
10300 }
10301 else
10302 {
10303 if (flags)
10304 inst.instruction |= CONDS_BIT;
10305
fdfde340
JM
10306 inst.instruction |= Rn << 8;
10307 inst.instruction |= Rm << 16;
728ca7c9
PB
10308 inst.instruction |= inst.operands[1].imm;
10309 }
10310 }
3d388997 10311 else if (!narrow)
c19d1205 10312 {
728ca7c9
PB
10313 /* Some mov with immediate shift have narrow variants.
10314 Register shifts are handled above. */
10315 if (low_regs && inst.operands[1].shifted
10316 && (inst.instruction == T_MNEM_mov
10317 || inst.instruction == T_MNEM_movs))
10318 {
e07e6e58 10319 if (in_it_block ())
728ca7c9
PB
10320 narrow = (inst.instruction == T_MNEM_mov);
10321 else
10322 narrow = (inst.instruction == T_MNEM_movs);
10323 }
10324
10325 if (narrow)
10326 {
10327 switch (inst.operands[1].shift_kind)
10328 {
10329 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10330 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10331 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10332 default: narrow = FALSE; break;
10333 }
10334 }
10335
10336 if (narrow)
10337 {
fdfde340
JM
10338 inst.instruction |= Rn;
10339 inst.instruction |= Rm << 3;
728ca7c9
PB
10340 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10341 }
10342 else
10343 {
10344 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10345 inst.instruction |= Rn << r0off;
728ca7c9
PB
10346 encode_thumb32_shifted_operand (1);
10347 }
c19d1205
ZW
10348 }
10349 else
10350 switch (inst.instruction)
10351 {
10352 case T_MNEM_mov:
10353 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10354 inst.instruction |= (Rn & 0x8) << 4;
10355 inst.instruction |= (Rn & 0x7);
10356 inst.instruction |= Rm << 3;
c19d1205 10357 break;
b99bd4ef 10358
c19d1205
ZW
10359 case T_MNEM_movs:
10360 /* We know we have low registers at this point.
10361 Generate ADD Rd, Rs, #0. */
10362 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10363 inst.instruction |= Rn;
10364 inst.instruction |= Rm << 3;
c19d1205
ZW
10365 break;
10366
10367 case T_MNEM_cmp:
3d388997 10368 if (low_regs)
c19d1205
ZW
10369 {
10370 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10371 inst.instruction |= Rn;
10372 inst.instruction |= Rm << 3;
c19d1205
ZW
10373 }
10374 else
10375 {
10376 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10377 inst.instruction |= (Rn & 0x8) << 4;
10378 inst.instruction |= (Rn & 0x7);
10379 inst.instruction |= Rm << 3;
c19d1205
ZW
10380 }
10381 break;
10382 }
b99bd4ef
NC
10383 return;
10384 }
10385
c19d1205 10386 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10387
10388 /* PR 10443: Do not silently ignore shifted operands. */
10389 constraint (inst.operands[1].shifted,
10390 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10391
c19d1205 10392 if (inst.operands[1].isreg)
b99bd4ef 10393 {
fdfde340 10394 if (Rn < 8 && Rm < 8)
b99bd4ef 10395 {
c19d1205
ZW
10396 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10397 since a MOV instruction produces unpredictable results. */
10398 if (inst.instruction == T_OPCODE_MOV_I8)
10399 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10400 else
c19d1205 10401 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10402
fdfde340
JM
10403 inst.instruction |= Rn;
10404 inst.instruction |= Rm << 3;
b99bd4ef
NC
10405 }
10406 else
10407 {
c19d1205
ZW
10408 if (inst.instruction == T_OPCODE_MOV_I8)
10409 inst.instruction = T_OPCODE_MOV_HR;
10410 else
10411 inst.instruction = T_OPCODE_CMP_HR;
10412 do_t_cpy ();
b99bd4ef
NC
10413 }
10414 }
c19d1205 10415 else
b99bd4ef 10416 {
fdfde340 10417 constraint (Rn > 7,
c19d1205 10418 _("only lo regs allowed with immediate"));
fdfde340 10419 inst.instruction |= Rn << 8;
c19d1205
ZW
10420 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10421 }
10422}
b99bd4ef 10423
c19d1205
ZW
10424static void
10425do_t_mov16 (void)
10426{
fdfde340 10427 unsigned Rd;
b6895b4f
PB
10428 bfd_vma imm;
10429 bfd_boolean top;
10430
10431 top = (inst.instruction & 0x00800000) != 0;
10432 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10433 {
10434 constraint (top, _(":lower16: not allowed this instruction"));
10435 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10436 }
10437 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10438 {
10439 constraint (!top, _(":upper16: not allowed this instruction"));
10440 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10441 }
10442
fdfde340
JM
10443 Rd = inst.operands[0].reg;
10444 reject_bad_reg (Rd);
10445
10446 inst.instruction |= Rd << 8;
b6895b4f
PB
10447 if (inst.reloc.type == BFD_RELOC_UNUSED)
10448 {
10449 imm = inst.reloc.exp.X_add_number;
10450 inst.instruction |= (imm & 0xf000) << 4;
10451 inst.instruction |= (imm & 0x0800) << 15;
10452 inst.instruction |= (imm & 0x0700) << 4;
10453 inst.instruction |= (imm & 0x00ff);
10454 }
c19d1205 10455}
b99bd4ef 10456
c19d1205
ZW
10457static void
10458do_t_mvn_tst (void)
10459{
fdfde340 10460 unsigned Rn, Rm;
c921be7d 10461
fdfde340
JM
10462 Rn = inst.operands[0].reg;
10463 Rm = inst.operands[1].reg;
10464
10465 if (inst.instruction == T_MNEM_cmp
10466 || inst.instruction == T_MNEM_cmn)
10467 constraint (Rn == REG_PC, BAD_PC);
10468 else
10469 reject_bad_reg (Rn);
10470 reject_bad_reg (Rm);
10471
c19d1205
ZW
10472 if (unified_syntax)
10473 {
10474 int r0off = (inst.instruction == T_MNEM_mvn
10475 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10476 bfd_boolean narrow;
10477
10478 if (inst.size_req == 4
10479 || inst.instruction > 0xffff
10480 || inst.operands[1].shifted
fdfde340 10481 || Rn > 7 || Rm > 7)
3d388997
PB
10482 narrow = FALSE;
10483 else if (inst.instruction == T_MNEM_cmn)
10484 narrow = TRUE;
10485 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10486 narrow = !in_it_block ();
3d388997 10487 else
e07e6e58 10488 narrow = in_it_block ();
3d388997 10489
c19d1205 10490 if (!inst.operands[1].isreg)
b99bd4ef 10491 {
c19d1205
ZW
10492 /* For an immediate, we always generate a 32-bit opcode;
10493 section relaxation will shrink it later if possible. */
10494 if (inst.instruction < 0xffff)
10495 inst.instruction = THUMB_OP32 (inst.instruction);
10496 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10497 inst.instruction |= Rn << r0off;
c19d1205 10498 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10499 }
c19d1205 10500 else
b99bd4ef 10501 {
c19d1205 10502 /* See if we can do this with a 16-bit instruction. */
3d388997 10503 if (narrow)
b99bd4ef 10504 {
c19d1205 10505 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10506 inst.instruction |= Rn;
10507 inst.instruction |= Rm << 3;
b99bd4ef 10508 }
c19d1205 10509 else
b99bd4ef 10510 {
c19d1205
ZW
10511 constraint (inst.operands[1].shifted
10512 && inst.operands[1].immisreg,
10513 _("shift must be constant"));
10514 if (inst.instruction < 0xffff)
10515 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10516 inst.instruction |= Rn << r0off;
c19d1205 10517 encode_thumb32_shifted_operand (1);
b99bd4ef 10518 }
b99bd4ef
NC
10519 }
10520 }
10521 else
10522 {
c19d1205
ZW
10523 constraint (inst.instruction > 0xffff
10524 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10525 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10526 _("unshifted register required"));
fdfde340 10527 constraint (Rn > 7 || Rm > 7,
c19d1205 10528 BAD_HIREG);
b99bd4ef 10529
c19d1205 10530 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10531 inst.instruction |= Rn;
10532 inst.instruction |= Rm << 3;
b99bd4ef 10533 }
b99bd4ef
NC
10534}
10535
b05fe5cf 10536static void
c19d1205 10537do_t_mrs (void)
b05fe5cf 10538{
fdfde340 10539 unsigned Rd;
62b3e311 10540 int flags;
037e8744
JB
10541
10542 if (do_vfp_nsyn_mrs () == SUCCESS)
10543 return;
10544
62b3e311
PB
10545 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10546 if (flags == 0)
10547 {
7e806470 10548 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10549 _("selected processor does not support "
10550 "requested special purpose register"));
10551 }
10552 else
10553 {
10554 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10555 _("selected processor does not support "
44bf2362 10556 "requested special purpose register"));
62b3e311
PB
10557 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10558 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10559 _("'CPSR' or 'SPSR' expected"));
10560 }
5f4273c7 10561
fdfde340
JM
10562 Rd = inst.operands[0].reg;
10563 reject_bad_reg (Rd);
10564
10565 inst.instruction |= Rd << 8;
62b3e311
PB
10566 inst.instruction |= (flags & SPSR_BIT) >> 2;
10567 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10568}
b05fe5cf 10569
c19d1205
ZW
10570static void
10571do_t_msr (void)
10572{
62b3e311 10573 int flags;
fdfde340 10574 unsigned Rn;
62b3e311 10575
037e8744
JB
10576 if (do_vfp_nsyn_msr () == SUCCESS)
10577 return;
10578
c19d1205
ZW
10579 constraint (!inst.operands[1].isreg,
10580 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10581 flags = inst.operands[0].imm;
10582 if (flags & ~0xff)
10583 {
10584 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10585 _("selected processor does not support "
10586 "requested special purpose register"));
10587 }
10588 else
10589 {
7e806470 10590 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10591 _("selected processor does not support "
10592 "requested special purpose register"));
10593 flags |= PSR_f;
10594 }
c921be7d 10595
fdfde340
JM
10596 Rn = inst.operands[1].reg;
10597 reject_bad_reg (Rn);
10598
62b3e311
PB
10599 inst.instruction |= (flags & SPSR_BIT) >> 2;
10600 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10601 inst.instruction |= (flags & 0xff);
fdfde340 10602 inst.instruction |= Rn << 16;
c19d1205 10603}
b05fe5cf 10604
c19d1205
ZW
10605static void
10606do_t_mul (void)
10607{
17828f45 10608 bfd_boolean narrow;
fdfde340 10609 unsigned Rd, Rn, Rm;
17828f45 10610
c19d1205
ZW
10611 if (!inst.operands[2].present)
10612 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10613
fdfde340
JM
10614 Rd = inst.operands[0].reg;
10615 Rn = inst.operands[1].reg;
10616 Rm = inst.operands[2].reg;
10617
17828f45 10618 if (unified_syntax)
b05fe5cf 10619 {
17828f45 10620 if (inst.size_req == 4
fdfde340
JM
10621 || (Rd != Rn
10622 && Rd != Rm)
10623 || Rn > 7
10624 || Rm > 7)
17828f45
JM
10625 narrow = FALSE;
10626 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10627 narrow = !in_it_block ();
17828f45 10628 else
e07e6e58 10629 narrow = in_it_block ();
b05fe5cf 10630 }
c19d1205 10631 else
b05fe5cf 10632 {
17828f45 10633 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10634 constraint (Rn > 7 || Rm > 7,
c19d1205 10635 BAD_HIREG);
17828f45
JM
10636 narrow = TRUE;
10637 }
b05fe5cf 10638
17828f45
JM
10639 if (narrow)
10640 {
10641 /* 16-bit MULS/Conditional MUL. */
c19d1205 10642 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10643 inst.instruction |= Rd;
b05fe5cf 10644
fdfde340
JM
10645 if (Rd == Rn)
10646 inst.instruction |= Rm << 3;
10647 else if (Rd == Rm)
10648 inst.instruction |= Rn << 3;
c19d1205
ZW
10649 else
10650 constraint (1, _("dest must overlap one source register"));
10651 }
17828f45
JM
10652 else
10653 {
e07e6e58
NC
10654 constraint (inst.instruction != T_MNEM_mul,
10655 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10656 /* 32-bit MUL. */
10657 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10658 inst.instruction |= Rd << 8;
10659 inst.instruction |= Rn << 16;
10660 inst.instruction |= Rm << 0;
10661
10662 reject_bad_reg (Rd);
10663 reject_bad_reg (Rn);
10664 reject_bad_reg (Rm);
17828f45 10665 }
c19d1205 10666}
b05fe5cf 10667
c19d1205
ZW
10668static void
10669do_t_mull (void)
10670{
fdfde340 10671 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10672
fdfde340
JM
10673 RdLo = inst.operands[0].reg;
10674 RdHi = inst.operands[1].reg;
10675 Rn = inst.operands[2].reg;
10676 Rm = inst.operands[3].reg;
10677
10678 reject_bad_reg (RdLo);
10679 reject_bad_reg (RdHi);
10680 reject_bad_reg (Rn);
10681 reject_bad_reg (Rm);
10682
10683 inst.instruction |= RdLo << 12;
10684 inst.instruction |= RdHi << 8;
10685 inst.instruction |= Rn << 16;
10686 inst.instruction |= Rm;
10687
10688 if (RdLo == RdHi)
c19d1205
ZW
10689 as_tsktsk (_("rdhi and rdlo must be different"));
10690}
b05fe5cf 10691
c19d1205
ZW
10692static void
10693do_t_nop (void)
10694{
e07e6e58
NC
10695 set_it_insn_type (NEUTRAL_IT_INSN);
10696
c19d1205
ZW
10697 if (unified_syntax)
10698 {
10699 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10700 {
c19d1205
ZW
10701 inst.instruction = THUMB_OP32 (inst.instruction);
10702 inst.instruction |= inst.operands[0].imm;
10703 }
10704 else
10705 {
bc2d1808
NC
10706 /* PR9722: Check for Thumb2 availability before
10707 generating a thumb2 nop instruction. */
afa62d5e 10708 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
10709 {
10710 inst.instruction = THUMB_OP16 (inst.instruction);
10711 inst.instruction |= inst.operands[0].imm << 4;
10712 }
10713 else
10714 inst.instruction = 0x46c0;
c19d1205
ZW
10715 }
10716 }
10717 else
10718 {
10719 constraint (inst.operands[0].present,
10720 _("Thumb does not support NOP with hints"));
10721 inst.instruction = 0x46c0;
10722 }
10723}
b05fe5cf 10724
c19d1205
ZW
10725static void
10726do_t_neg (void)
10727{
10728 if (unified_syntax)
10729 {
3d388997
PB
10730 bfd_boolean narrow;
10731
10732 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10733 narrow = !in_it_block ();
3d388997 10734 else
e07e6e58 10735 narrow = in_it_block ();
3d388997
PB
10736 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10737 narrow = FALSE;
10738 if (inst.size_req == 4)
10739 narrow = FALSE;
10740
10741 if (!narrow)
c19d1205
ZW
10742 {
10743 inst.instruction = THUMB_OP32 (inst.instruction);
10744 inst.instruction |= inst.operands[0].reg << 8;
10745 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10746 }
10747 else
10748 {
c19d1205
ZW
10749 inst.instruction = THUMB_OP16 (inst.instruction);
10750 inst.instruction |= inst.operands[0].reg;
10751 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10752 }
10753 }
10754 else
10755 {
c19d1205
ZW
10756 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10757 BAD_HIREG);
10758 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10759
10760 inst.instruction = THUMB_OP16 (inst.instruction);
10761 inst.instruction |= inst.operands[0].reg;
10762 inst.instruction |= inst.operands[1].reg << 3;
10763 }
10764}
10765
1c444d06
JM
10766static void
10767do_t_orn (void)
10768{
10769 unsigned Rd, Rn;
10770
10771 Rd = inst.operands[0].reg;
10772 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10773
fdfde340
JM
10774 reject_bad_reg (Rd);
10775 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10776 reject_bad_reg (Rn);
10777
1c444d06
JM
10778 inst.instruction |= Rd << 8;
10779 inst.instruction |= Rn << 16;
10780
10781 if (!inst.operands[2].isreg)
10782 {
10783 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10784 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10785 }
10786 else
10787 {
10788 unsigned Rm;
10789
10790 Rm = inst.operands[2].reg;
fdfde340 10791 reject_bad_reg (Rm);
1c444d06
JM
10792
10793 constraint (inst.operands[2].shifted
10794 && inst.operands[2].immisreg,
10795 _("shift must be constant"));
10796 encode_thumb32_shifted_operand (2);
10797 }
10798}
10799
c19d1205
ZW
10800static void
10801do_t_pkhbt (void)
10802{
fdfde340
JM
10803 unsigned Rd, Rn, Rm;
10804
10805 Rd = inst.operands[0].reg;
10806 Rn = inst.operands[1].reg;
10807 Rm = inst.operands[2].reg;
10808
10809 reject_bad_reg (Rd);
10810 reject_bad_reg (Rn);
10811 reject_bad_reg (Rm);
10812
10813 inst.instruction |= Rd << 8;
10814 inst.instruction |= Rn << 16;
10815 inst.instruction |= Rm;
c19d1205
ZW
10816 if (inst.operands[3].present)
10817 {
10818 unsigned int val = inst.reloc.exp.X_add_number;
10819 constraint (inst.reloc.exp.X_op != O_constant,
10820 _("expression too complex"));
10821 inst.instruction |= (val & 0x1c) << 10;
10822 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10823 }
c19d1205 10824}
b05fe5cf 10825
c19d1205
ZW
10826static void
10827do_t_pkhtb (void)
10828{
10829 if (!inst.operands[3].present)
1ef52f49
NC
10830 {
10831 unsigned Rtmp;
10832
10833 inst.instruction &= ~0x00000020;
10834
10835 /* PR 10168. Swap the Rm and Rn registers. */
10836 Rtmp = inst.operands[1].reg;
10837 inst.operands[1].reg = inst.operands[2].reg;
10838 inst.operands[2].reg = Rtmp;
10839 }
c19d1205 10840 do_t_pkhbt ();
b05fe5cf
ZW
10841}
10842
c19d1205
ZW
10843static void
10844do_t_pld (void)
10845{
fdfde340
JM
10846 if (inst.operands[0].immisreg)
10847 reject_bad_reg (inst.operands[0].imm);
10848
c19d1205
ZW
10849 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10850}
b05fe5cf 10851
c19d1205
ZW
10852static void
10853do_t_push_pop (void)
b99bd4ef 10854{
e9f89963 10855 unsigned mask;
5f4273c7 10856
c19d1205
ZW
10857 constraint (inst.operands[0].writeback,
10858 _("push/pop do not support {reglist}^"));
10859 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10860 _("expression too complex"));
b99bd4ef 10861
e9f89963
PB
10862 mask = inst.operands[0].imm;
10863 if ((mask & ~0xff) == 0)
3c707909 10864 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10865 else if ((inst.instruction == T_MNEM_push
e9f89963 10866 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10867 || (inst.instruction == T_MNEM_pop
e9f89963 10868 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10869 {
c19d1205
ZW
10870 inst.instruction = THUMB_OP16 (inst.instruction);
10871 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10872 inst.instruction |= mask & 0xff;
c19d1205
ZW
10873 }
10874 else if (unified_syntax)
10875 {
3c707909 10876 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10877 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10878 }
10879 else
10880 {
10881 inst.error = _("invalid register list to push/pop instruction");
10882 return;
10883 }
c19d1205 10884}
b99bd4ef 10885
c19d1205
ZW
10886static void
10887do_t_rbit (void)
10888{
fdfde340
JM
10889 unsigned Rd, Rm;
10890
10891 Rd = inst.operands[0].reg;
10892 Rm = inst.operands[1].reg;
10893
10894 reject_bad_reg (Rd);
10895 reject_bad_reg (Rm);
10896
10897 inst.instruction |= Rd << 8;
10898 inst.instruction |= Rm << 16;
10899 inst.instruction |= Rm;
c19d1205 10900}
b99bd4ef 10901
c19d1205
ZW
10902static void
10903do_t_rev (void)
10904{
fdfde340
JM
10905 unsigned Rd, Rm;
10906
10907 Rd = inst.operands[0].reg;
10908 Rm = inst.operands[1].reg;
10909
10910 reject_bad_reg (Rd);
10911 reject_bad_reg (Rm);
10912
10913 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10914 && inst.size_req != 4)
10915 {
10916 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10917 inst.instruction |= Rd;
10918 inst.instruction |= Rm << 3;
c19d1205
ZW
10919 }
10920 else if (unified_syntax)
10921 {
10922 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10923 inst.instruction |= Rd << 8;
10924 inst.instruction |= Rm << 16;
10925 inst.instruction |= Rm;
c19d1205
ZW
10926 }
10927 else
10928 inst.error = BAD_HIREG;
10929}
b99bd4ef 10930
1c444d06
JM
10931static void
10932do_t_rrx (void)
10933{
10934 unsigned Rd, Rm;
10935
10936 Rd = inst.operands[0].reg;
10937 Rm = inst.operands[1].reg;
10938
fdfde340
JM
10939 reject_bad_reg (Rd);
10940 reject_bad_reg (Rm);
c921be7d 10941
1c444d06
JM
10942 inst.instruction |= Rd << 8;
10943 inst.instruction |= Rm;
10944}
10945
c19d1205
ZW
10946static void
10947do_t_rsb (void)
10948{
fdfde340 10949 unsigned Rd, Rs;
b99bd4ef 10950
c19d1205
ZW
10951 Rd = inst.operands[0].reg;
10952 Rs = (inst.operands[1].present
10953 ? inst.operands[1].reg /* Rd, Rs, foo */
10954 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10955
fdfde340
JM
10956 reject_bad_reg (Rd);
10957 reject_bad_reg (Rs);
10958 if (inst.operands[2].isreg)
10959 reject_bad_reg (inst.operands[2].reg);
10960
c19d1205
ZW
10961 inst.instruction |= Rd << 8;
10962 inst.instruction |= Rs << 16;
10963 if (!inst.operands[2].isreg)
10964 {
026d3abb
PB
10965 bfd_boolean narrow;
10966
10967 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10968 narrow = !in_it_block ();
026d3abb 10969 else
e07e6e58 10970 narrow = in_it_block ();
026d3abb
PB
10971
10972 if (Rd > 7 || Rs > 7)
10973 narrow = FALSE;
10974
10975 if (inst.size_req == 4 || !unified_syntax)
10976 narrow = FALSE;
10977
10978 if (inst.reloc.exp.X_op != O_constant
10979 || inst.reloc.exp.X_add_number != 0)
10980 narrow = FALSE;
10981
10982 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10983 relaxation, but it doesn't seem worth the hassle. */
10984 if (narrow)
10985 {
10986 inst.reloc.type = BFD_RELOC_UNUSED;
10987 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10988 inst.instruction |= Rs << 3;
10989 inst.instruction |= Rd;
10990 }
10991 else
10992 {
10993 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10994 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10995 }
c19d1205
ZW
10996 }
10997 else
10998 encode_thumb32_shifted_operand (2);
10999}
b99bd4ef 11000
c19d1205
ZW
11001static void
11002do_t_setend (void)
11003{
e07e6e58 11004 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11005 if (inst.operands[0].imm)
11006 inst.instruction |= 0x8;
11007}
b99bd4ef 11008
c19d1205
ZW
11009static void
11010do_t_shift (void)
11011{
11012 if (!inst.operands[1].present)
11013 inst.operands[1].reg = inst.operands[0].reg;
11014
11015 if (unified_syntax)
11016 {
3d388997
PB
11017 bfd_boolean narrow;
11018 int shift_kind;
11019
11020 switch (inst.instruction)
11021 {
11022 case T_MNEM_asr:
11023 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11024 case T_MNEM_lsl:
11025 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11026 case T_MNEM_lsr:
11027 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11028 case T_MNEM_ror:
11029 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11030 default: abort ();
11031 }
11032
11033 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11034 narrow = !in_it_block ();
3d388997 11035 else
e07e6e58 11036 narrow = in_it_block ();
3d388997
PB
11037 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11038 narrow = FALSE;
11039 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11040 narrow = FALSE;
11041 if (inst.operands[2].isreg
11042 && (inst.operands[1].reg != inst.operands[0].reg
11043 || inst.operands[2].reg > 7))
11044 narrow = FALSE;
11045 if (inst.size_req == 4)
11046 narrow = FALSE;
11047
fdfde340
JM
11048 reject_bad_reg (inst.operands[0].reg);
11049 reject_bad_reg (inst.operands[1].reg);
c921be7d 11050
3d388997 11051 if (!narrow)
c19d1205
ZW
11052 {
11053 if (inst.operands[2].isreg)
b99bd4ef 11054 {
fdfde340 11055 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
11056 inst.instruction = THUMB_OP32 (inst.instruction);
11057 inst.instruction |= inst.operands[0].reg << 8;
11058 inst.instruction |= inst.operands[1].reg << 16;
11059 inst.instruction |= inst.operands[2].reg;
11060 }
11061 else
11062 {
11063 inst.operands[1].shifted = 1;
3d388997 11064 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11065 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11066 ? T_MNEM_movs : T_MNEM_mov);
11067 inst.instruction |= inst.operands[0].reg << 8;
11068 encode_thumb32_shifted_operand (1);
11069 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11070 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11071 }
11072 }
11073 else
11074 {
c19d1205 11075 if (inst.operands[2].isreg)
b99bd4ef 11076 {
3d388997 11077 switch (shift_kind)
b99bd4ef 11078 {
3d388997
PB
11079 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11080 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11081 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11082 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11083 default: abort ();
b99bd4ef 11084 }
5f4273c7 11085
c19d1205
ZW
11086 inst.instruction |= inst.operands[0].reg;
11087 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11088 }
11089 else
11090 {
3d388997 11091 switch (shift_kind)
b99bd4ef 11092 {
3d388997
PB
11093 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11094 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11095 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11096 default: abort ();
b99bd4ef 11097 }
c19d1205
ZW
11098 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11099 inst.instruction |= inst.operands[0].reg;
11100 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11101 }
11102 }
c19d1205
ZW
11103 }
11104 else
11105 {
11106 constraint (inst.operands[0].reg > 7
11107 || inst.operands[1].reg > 7, BAD_HIREG);
11108 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11109
c19d1205
ZW
11110 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11111 {
11112 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11113 constraint (inst.operands[0].reg != inst.operands[1].reg,
11114 _("source1 and dest must be same register"));
b99bd4ef 11115
c19d1205
ZW
11116 switch (inst.instruction)
11117 {
11118 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11119 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11120 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11121 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11122 default: abort ();
11123 }
5f4273c7 11124
c19d1205
ZW
11125 inst.instruction |= inst.operands[0].reg;
11126 inst.instruction |= inst.operands[2].reg << 3;
11127 }
11128 else
b99bd4ef 11129 {
c19d1205
ZW
11130 switch (inst.instruction)
11131 {
11132 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11133 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11134 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11135 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11136 default: abort ();
11137 }
11138 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11139 inst.instruction |= inst.operands[0].reg;
11140 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11141 }
11142 }
b99bd4ef
NC
11143}
11144
11145static void
c19d1205 11146do_t_simd (void)
b99bd4ef 11147{
fdfde340
JM
11148 unsigned Rd, Rn, Rm;
11149
11150 Rd = inst.operands[0].reg;
11151 Rn = inst.operands[1].reg;
11152 Rm = inst.operands[2].reg;
11153
11154 reject_bad_reg (Rd);
11155 reject_bad_reg (Rn);
11156 reject_bad_reg (Rm);
11157
11158 inst.instruction |= Rd << 8;
11159 inst.instruction |= Rn << 16;
11160 inst.instruction |= Rm;
c19d1205 11161}
b99bd4ef 11162
03ee1b7f
NC
11163static void
11164do_t_simd2 (void)
11165{
11166 unsigned Rd, Rn, Rm;
11167
11168 Rd = inst.operands[0].reg;
11169 Rm = inst.operands[1].reg;
11170 Rn = inst.operands[2].reg;
11171
11172 reject_bad_reg (Rd);
11173 reject_bad_reg (Rn);
11174 reject_bad_reg (Rm);
11175
11176 inst.instruction |= Rd << 8;
11177 inst.instruction |= Rn << 16;
11178 inst.instruction |= Rm;
11179}
11180
c19d1205 11181static void
3eb17e6b 11182do_t_smc (void)
c19d1205
ZW
11183{
11184 unsigned int value = inst.reloc.exp.X_add_number;
11185 constraint (inst.reloc.exp.X_op != O_constant,
11186 _("expression too complex"));
11187 inst.reloc.type = BFD_RELOC_UNUSED;
11188 inst.instruction |= (value & 0xf000) >> 12;
11189 inst.instruction |= (value & 0x0ff0);
11190 inst.instruction |= (value & 0x000f) << 16;
11191}
b99bd4ef 11192
c19d1205 11193static void
3a21c15a 11194do_t_ssat_usat (int bias)
c19d1205 11195{
fdfde340
JM
11196 unsigned Rd, Rn;
11197
11198 Rd = inst.operands[0].reg;
11199 Rn = inst.operands[2].reg;
11200
11201 reject_bad_reg (Rd);
11202 reject_bad_reg (Rn);
11203
11204 inst.instruction |= Rd << 8;
3a21c15a 11205 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11206 inst.instruction |= Rn << 16;
b99bd4ef 11207
c19d1205 11208 if (inst.operands[3].present)
b99bd4ef 11209 {
3a21c15a
NC
11210 offsetT shift_amount = inst.reloc.exp.X_add_number;
11211
11212 inst.reloc.type = BFD_RELOC_UNUSED;
11213
c19d1205
ZW
11214 constraint (inst.reloc.exp.X_op != O_constant,
11215 _("expression too complex"));
b99bd4ef 11216
3a21c15a 11217 if (shift_amount != 0)
6189168b 11218 {
3a21c15a
NC
11219 constraint (shift_amount > 31,
11220 _("shift expression is too large"));
11221
c19d1205 11222 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11223 inst.instruction |= 0x00200000; /* sh bit. */
11224
11225 inst.instruction |= (shift_amount & 0x1c) << 10;
11226 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11227 }
11228 }
b99bd4ef 11229}
c921be7d 11230
3a21c15a
NC
11231static void
11232do_t_ssat (void)
11233{
11234 do_t_ssat_usat (1);
11235}
b99bd4ef 11236
0dd132b6 11237static void
c19d1205 11238do_t_ssat16 (void)
0dd132b6 11239{
fdfde340
JM
11240 unsigned Rd, Rn;
11241
11242 Rd = inst.operands[0].reg;
11243 Rn = inst.operands[2].reg;
11244
11245 reject_bad_reg (Rd);
11246 reject_bad_reg (Rn);
11247
11248 inst.instruction |= Rd << 8;
c19d1205 11249 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11250 inst.instruction |= Rn << 16;
c19d1205 11251}
0dd132b6 11252
c19d1205
ZW
11253static void
11254do_t_strex (void)
11255{
11256 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11257 || inst.operands[2].postind || inst.operands[2].writeback
11258 || inst.operands[2].immisreg || inst.operands[2].shifted
11259 || inst.operands[2].negative,
01cfc07f 11260 BAD_ADDR_MODE);
0dd132b6 11261
5be8be5d
DG
11262 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11263
c19d1205
ZW
11264 inst.instruction |= inst.operands[0].reg << 8;
11265 inst.instruction |= inst.operands[1].reg << 12;
11266 inst.instruction |= inst.operands[2].reg << 16;
11267 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11268}
11269
b99bd4ef 11270static void
c19d1205 11271do_t_strexd (void)
b99bd4ef 11272{
c19d1205
ZW
11273 if (!inst.operands[2].present)
11274 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11275
c19d1205
ZW
11276 constraint (inst.operands[0].reg == inst.operands[1].reg
11277 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 11278 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 11279 BAD_OVERLAP);
b99bd4ef 11280
c19d1205
ZW
11281 inst.instruction |= inst.operands[0].reg;
11282 inst.instruction |= inst.operands[1].reg << 12;
11283 inst.instruction |= inst.operands[2].reg << 8;
11284 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11285}
11286
11287static void
c19d1205 11288do_t_sxtah (void)
b99bd4ef 11289{
fdfde340
JM
11290 unsigned Rd, Rn, Rm;
11291
11292 Rd = inst.operands[0].reg;
11293 Rn = inst.operands[1].reg;
11294 Rm = inst.operands[2].reg;
11295
11296 reject_bad_reg (Rd);
11297 reject_bad_reg (Rn);
11298 reject_bad_reg (Rm);
11299
11300 inst.instruction |= Rd << 8;
11301 inst.instruction |= Rn << 16;
11302 inst.instruction |= Rm;
c19d1205
ZW
11303 inst.instruction |= inst.operands[3].imm << 4;
11304}
b99bd4ef 11305
c19d1205
ZW
11306static void
11307do_t_sxth (void)
11308{
fdfde340
JM
11309 unsigned Rd, Rm;
11310
11311 Rd = inst.operands[0].reg;
11312 Rm = inst.operands[1].reg;
11313
11314 reject_bad_reg (Rd);
11315 reject_bad_reg (Rm);
c921be7d
NC
11316
11317 if (inst.instruction <= 0xffff
11318 && inst.size_req != 4
fdfde340 11319 && Rd <= 7 && Rm <= 7
c19d1205 11320 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11321 {
c19d1205 11322 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11323 inst.instruction |= Rd;
11324 inst.instruction |= Rm << 3;
b99bd4ef 11325 }
c19d1205 11326 else if (unified_syntax)
b99bd4ef 11327 {
c19d1205
ZW
11328 if (inst.instruction <= 0xffff)
11329 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11330 inst.instruction |= Rd << 8;
11331 inst.instruction |= Rm;
c19d1205 11332 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11333 }
c19d1205 11334 else
b99bd4ef 11335 {
c19d1205
ZW
11336 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11337 _("Thumb encoding does not support rotation"));
11338 constraint (1, BAD_HIREG);
b99bd4ef 11339 }
c19d1205 11340}
b99bd4ef 11341
c19d1205
ZW
11342static void
11343do_t_swi (void)
11344{
11345 inst.reloc.type = BFD_RELOC_ARM_SWI;
11346}
b99bd4ef 11347
92e90b6e
PB
11348static void
11349do_t_tb (void)
11350{
fdfde340 11351 unsigned Rn, Rm;
92e90b6e
PB
11352 int half;
11353
11354 half = (inst.instruction & 0x10) != 0;
e07e6e58 11355 set_it_insn_type_last ();
dfa9f0d5
PB
11356 constraint (inst.operands[0].immisreg,
11357 _("instruction requires register index"));
fdfde340
JM
11358
11359 Rn = inst.operands[0].reg;
11360 Rm = inst.operands[0].imm;
c921be7d 11361
fdfde340
JM
11362 constraint (Rn == REG_SP, BAD_SP);
11363 reject_bad_reg (Rm);
11364
92e90b6e
PB
11365 constraint (!half && inst.operands[0].shifted,
11366 _("instruction does not allow shifted index"));
fdfde340 11367 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11368}
11369
c19d1205
ZW
11370static void
11371do_t_usat (void)
11372{
3a21c15a 11373 do_t_ssat_usat (0);
b99bd4ef
NC
11374}
11375
11376static void
c19d1205 11377do_t_usat16 (void)
b99bd4ef 11378{
fdfde340
JM
11379 unsigned Rd, Rn;
11380
11381 Rd = inst.operands[0].reg;
11382 Rn = inst.operands[2].reg;
11383
11384 reject_bad_reg (Rd);
11385 reject_bad_reg (Rn);
11386
11387 inst.instruction |= Rd << 8;
c19d1205 11388 inst.instruction |= inst.operands[1].imm;
fdfde340 11389 inst.instruction |= Rn << 16;
b99bd4ef 11390}
c19d1205 11391
5287ad62 11392/* Neon instruction encoder helpers. */
5f4273c7 11393
5287ad62 11394/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11395
5287ad62
JB
11396/* An "invalid" code for the following tables. */
11397#define N_INV -1u
11398
11399struct neon_tab_entry
b99bd4ef 11400{
5287ad62
JB
11401 unsigned integer;
11402 unsigned float_or_poly;
11403 unsigned scalar_or_imm;
11404};
5f4273c7 11405
5287ad62
JB
11406/* Map overloaded Neon opcodes to their respective encodings. */
11407#define NEON_ENC_TAB \
11408 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11409 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11410 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11411 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11412 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11413 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11414 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11415 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11416 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11417 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11418 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11419 /* Register variants of the following two instructions are encoded as
e07e6e58 11420 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11421 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11422 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11423 X(vfma, N_INV, 0x0000c10, N_INV), \
11424 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11425 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11426 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11427 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11428 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11429 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11430 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11431 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11432 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11433 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11434 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11435 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11436 X(vshl, 0x0000400, N_INV, 0x0800510), \
11437 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11438 X(vand, 0x0000110, N_INV, 0x0800030), \
11439 X(vbic, 0x0100110, N_INV, 0x0800030), \
11440 X(veor, 0x1000110, N_INV, N_INV), \
11441 X(vorn, 0x0300110, N_INV, 0x0800010), \
11442 X(vorr, 0x0200110, N_INV, 0x0800010), \
11443 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11444 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11445 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11446 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11447 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11448 X(vst1, 0x0000000, 0x0800000, N_INV), \
11449 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11450 X(vst2, 0x0000100, 0x0800100, N_INV), \
11451 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11452 X(vst3, 0x0000200, 0x0800200, N_INV), \
11453 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11454 X(vst4, 0x0000300, 0x0800300, N_INV), \
11455 X(vmovn, 0x1b20200, N_INV, N_INV), \
11456 X(vtrn, 0x1b20080, N_INV, N_INV), \
11457 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11458 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11459 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11460 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11461 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11462 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11463 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11464 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11465 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11466 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11467 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11468
11469enum neon_opc
11470{
11471#define X(OPC,I,F,S) N_MNEM_##OPC
11472NEON_ENC_TAB
11473#undef X
11474};
b99bd4ef 11475
5287ad62
JB
11476static const struct neon_tab_entry neon_enc_tab[] =
11477{
11478#define X(OPC,I,F,S) { (I), (F), (S) }
11479NEON_ENC_TAB
11480#undef X
11481};
b99bd4ef 11482
88714cb8
DG
11483/* Do not use these macros; instead, use NEON_ENCODE defined below. */
11484#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11485#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11486#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11487#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11488#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11489#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11490#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11491#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11492#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11493#define NEON_ENC_SINGLE_(X) \
037e8744 11494 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 11495#define NEON_ENC_DOUBLE_(X) \
037e8744 11496 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11497
88714cb8
DG
11498#define NEON_ENCODE(type, inst) \
11499 do \
11500 { \
11501 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11502 inst.is_neon = 1; \
11503 } \
11504 while (0)
11505
11506#define check_neon_suffixes \
11507 do \
11508 { \
11509 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11510 { \
11511 as_bad (_("invalid neon suffix for non neon instruction")); \
11512 return; \
11513 } \
11514 } \
11515 while (0)
11516
037e8744
JB
11517/* Define shapes for instruction operands. The following mnemonic characters
11518 are used in this table:
5287ad62 11519
037e8744 11520 F - VFP S<n> register
5287ad62
JB
11521 D - Neon D<n> register
11522 Q - Neon Q<n> register
11523 I - Immediate
11524 S - Scalar
11525 R - ARM register
11526 L - D<n> register list
5f4273c7 11527
037e8744
JB
11528 This table is used to generate various data:
11529 - enumerations of the form NS_DDR to be used as arguments to
11530 neon_select_shape.
11531 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11532 - a table used to drive neon_select_shape. */
b99bd4ef 11533
037e8744
JB
11534#define NEON_SHAPE_DEF \
11535 X(3, (D, D, D), DOUBLE), \
11536 X(3, (Q, Q, Q), QUAD), \
11537 X(3, (D, D, I), DOUBLE), \
11538 X(3, (Q, Q, I), QUAD), \
11539 X(3, (D, D, S), DOUBLE), \
11540 X(3, (Q, Q, S), QUAD), \
11541 X(2, (D, D), DOUBLE), \
11542 X(2, (Q, Q), QUAD), \
11543 X(2, (D, S), DOUBLE), \
11544 X(2, (Q, S), QUAD), \
11545 X(2, (D, R), DOUBLE), \
11546 X(2, (Q, R), QUAD), \
11547 X(2, (D, I), DOUBLE), \
11548 X(2, (Q, I), QUAD), \
11549 X(3, (D, L, D), DOUBLE), \
11550 X(2, (D, Q), MIXED), \
11551 X(2, (Q, D), MIXED), \
11552 X(3, (D, Q, I), MIXED), \
11553 X(3, (Q, D, I), MIXED), \
11554 X(3, (Q, D, D), MIXED), \
11555 X(3, (D, Q, Q), MIXED), \
11556 X(3, (Q, Q, D), MIXED), \
11557 X(3, (Q, D, S), MIXED), \
11558 X(3, (D, Q, S), MIXED), \
11559 X(4, (D, D, D, I), DOUBLE), \
11560 X(4, (Q, Q, Q, I), QUAD), \
11561 X(2, (F, F), SINGLE), \
11562 X(3, (F, F, F), SINGLE), \
11563 X(2, (F, I), SINGLE), \
11564 X(2, (F, D), MIXED), \
11565 X(2, (D, F), MIXED), \
11566 X(3, (F, F, I), MIXED), \
11567 X(4, (R, R, F, F), SINGLE), \
11568 X(4, (F, F, R, R), SINGLE), \
11569 X(3, (D, R, R), DOUBLE), \
11570 X(3, (R, R, D), DOUBLE), \
11571 X(2, (S, R), SINGLE), \
11572 X(2, (R, S), SINGLE), \
11573 X(2, (F, R), SINGLE), \
11574 X(2, (R, F), SINGLE)
11575
11576#define S2(A,B) NS_##A##B
11577#define S3(A,B,C) NS_##A##B##C
11578#define S4(A,B,C,D) NS_##A##B##C##D
11579
11580#define X(N, L, C) S##N L
11581
5287ad62
JB
11582enum neon_shape
11583{
037e8744
JB
11584 NEON_SHAPE_DEF,
11585 NS_NULL
5287ad62 11586};
b99bd4ef 11587
037e8744
JB
11588#undef X
11589#undef S2
11590#undef S3
11591#undef S4
11592
11593enum neon_shape_class
11594{
11595 SC_SINGLE,
11596 SC_DOUBLE,
11597 SC_QUAD,
11598 SC_MIXED
11599};
11600
11601#define X(N, L, C) SC_##C
11602
11603static enum neon_shape_class neon_shape_class[] =
11604{
11605 NEON_SHAPE_DEF
11606};
11607
11608#undef X
11609
11610enum neon_shape_el
11611{
11612 SE_F,
11613 SE_D,
11614 SE_Q,
11615 SE_I,
11616 SE_S,
11617 SE_R,
11618 SE_L
11619};
11620
11621/* Register widths of above. */
11622static unsigned neon_shape_el_size[] =
11623{
11624 32,
11625 64,
11626 128,
11627 0,
11628 32,
11629 32,
11630 0
11631};
11632
11633struct neon_shape_info
11634{
11635 unsigned els;
11636 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11637};
11638
11639#define S2(A,B) { SE_##A, SE_##B }
11640#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11641#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11642
11643#define X(N, L, C) { N, S##N L }
11644
11645static struct neon_shape_info neon_shape_tab[] =
11646{
11647 NEON_SHAPE_DEF
11648};
11649
11650#undef X
11651#undef S2
11652#undef S3
11653#undef S4
11654
5287ad62
JB
11655/* Bit masks used in type checking given instructions.
11656 'N_EQK' means the type must be the same as (or based on in some way) the key
11657 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11658 set, various other bits can be set as well in order to modify the meaning of
11659 the type constraint. */
11660
11661enum neon_type_mask
11662{
8e79c3df
CM
11663 N_S8 = 0x0000001,
11664 N_S16 = 0x0000002,
11665 N_S32 = 0x0000004,
11666 N_S64 = 0x0000008,
11667 N_U8 = 0x0000010,
11668 N_U16 = 0x0000020,
11669 N_U32 = 0x0000040,
11670 N_U64 = 0x0000080,
11671 N_I8 = 0x0000100,
11672 N_I16 = 0x0000200,
11673 N_I32 = 0x0000400,
11674 N_I64 = 0x0000800,
11675 N_8 = 0x0001000,
11676 N_16 = 0x0002000,
11677 N_32 = 0x0004000,
11678 N_64 = 0x0008000,
11679 N_P8 = 0x0010000,
11680 N_P16 = 0x0020000,
11681 N_F16 = 0x0040000,
11682 N_F32 = 0x0080000,
11683 N_F64 = 0x0100000,
c921be7d
NC
11684 N_KEY = 0x1000000, /* Key element (main type specifier). */
11685 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11686 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11687 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11688 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11689 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11690 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11691 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11692 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11693 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11694 N_UTYP = 0,
037e8744 11695 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11696};
11697
dcbf9037
JB
11698#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11699
5287ad62
JB
11700#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11701#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11702#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11703#define N_SUF_32 (N_SU_32 | N_F32)
11704#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11705#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11706
11707/* Pass this as the first type argument to neon_check_type to ignore types
11708 altogether. */
11709#define N_IGNORE_TYPE (N_KEY | N_EQK)
11710
037e8744
JB
11711/* Select a "shape" for the current instruction (describing register types or
11712 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11713 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11714 function of operand parsing, so this function doesn't need to be called.
11715 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11716
11717static enum neon_shape
037e8744 11718neon_select_shape (enum neon_shape shape, ...)
5287ad62 11719{
037e8744
JB
11720 va_list ap;
11721 enum neon_shape first_shape = shape;
5287ad62
JB
11722
11723 /* Fix missing optional operands. FIXME: we don't know at this point how
11724 many arguments we should have, so this makes the assumption that we have
11725 > 1. This is true of all current Neon opcodes, I think, but may not be
11726 true in the future. */
11727 if (!inst.operands[1].present)
11728 inst.operands[1] = inst.operands[0];
11729
037e8744 11730 va_start (ap, shape);
5f4273c7 11731
21d799b5 11732 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11733 {
11734 unsigned j;
11735 int matches = 1;
11736
11737 for (j = 0; j < neon_shape_tab[shape].els; j++)
11738 {
11739 if (!inst.operands[j].present)
11740 {
11741 matches = 0;
11742 break;
11743 }
11744
11745 switch (neon_shape_tab[shape].el[j])
11746 {
11747 case SE_F:
11748 if (!(inst.operands[j].isreg
11749 && inst.operands[j].isvec
11750 && inst.operands[j].issingle
11751 && !inst.operands[j].isquad))
11752 matches = 0;
11753 break;
11754
11755 case SE_D:
11756 if (!(inst.operands[j].isreg
11757 && inst.operands[j].isvec
11758 && !inst.operands[j].isquad
11759 && !inst.operands[j].issingle))
11760 matches = 0;
11761 break;
11762
11763 case SE_R:
11764 if (!(inst.operands[j].isreg
11765 && !inst.operands[j].isvec))
11766 matches = 0;
11767 break;
11768
11769 case SE_Q:
11770 if (!(inst.operands[j].isreg
11771 && inst.operands[j].isvec
11772 && inst.operands[j].isquad
11773 && !inst.operands[j].issingle))
11774 matches = 0;
11775 break;
11776
11777 case SE_I:
11778 if (!(!inst.operands[j].isreg
11779 && !inst.operands[j].isscalar))
11780 matches = 0;
11781 break;
11782
11783 case SE_S:
11784 if (!(!inst.operands[j].isreg
11785 && inst.operands[j].isscalar))
11786 matches = 0;
11787 break;
11788
11789 case SE_L:
11790 break;
11791 }
3fde54a2
JZ
11792 if (!matches)
11793 break;
037e8744
JB
11794 }
11795 if (matches)
5287ad62 11796 break;
037e8744 11797 }
5f4273c7 11798
037e8744 11799 va_end (ap);
5287ad62 11800
037e8744
JB
11801 if (shape == NS_NULL && first_shape != NS_NULL)
11802 first_error (_("invalid instruction shape"));
5287ad62 11803
037e8744
JB
11804 return shape;
11805}
5287ad62 11806
037e8744
JB
11807/* True if SHAPE is predominantly a quadword operation (most of the time, this
11808 means the Q bit should be set). */
11809
11810static int
11811neon_quad (enum neon_shape shape)
11812{
11813 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11814}
037e8744 11815
5287ad62
JB
11816static void
11817neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11818 unsigned *g_size)
11819{
11820 /* Allow modification to be made to types which are constrained to be
11821 based on the key element, based on bits set alongside N_EQK. */
11822 if ((typebits & N_EQK) != 0)
11823 {
11824 if ((typebits & N_HLF) != 0)
11825 *g_size /= 2;
11826 else if ((typebits & N_DBL) != 0)
11827 *g_size *= 2;
11828 if ((typebits & N_SGN) != 0)
11829 *g_type = NT_signed;
11830 else if ((typebits & N_UNS) != 0)
11831 *g_type = NT_unsigned;
11832 else if ((typebits & N_INT) != 0)
11833 *g_type = NT_integer;
11834 else if ((typebits & N_FLT) != 0)
11835 *g_type = NT_float;
dcbf9037
JB
11836 else if ((typebits & N_SIZ) != 0)
11837 *g_type = NT_untyped;
5287ad62
JB
11838 }
11839}
5f4273c7 11840
5287ad62
JB
11841/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11842 operand type, i.e. the single type specified in a Neon instruction when it
11843 is the only one given. */
11844
11845static struct neon_type_el
11846neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11847{
11848 struct neon_type_el dest = *key;
5f4273c7 11849
9c2799c2 11850 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11851
5287ad62
JB
11852 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11853
11854 return dest;
11855}
11856
11857/* Convert Neon type and size into compact bitmask representation. */
11858
11859static enum neon_type_mask
11860type_chk_of_el_type (enum neon_el_type type, unsigned size)
11861{
11862 switch (type)
11863 {
11864 case NT_untyped:
11865 switch (size)
11866 {
11867 case 8: return N_8;
11868 case 16: return N_16;
11869 case 32: return N_32;
11870 case 64: return N_64;
11871 default: ;
11872 }
11873 break;
11874
11875 case NT_integer:
11876 switch (size)
11877 {
11878 case 8: return N_I8;
11879 case 16: return N_I16;
11880 case 32: return N_I32;
11881 case 64: return N_I64;
11882 default: ;
11883 }
11884 break;
11885
11886 case NT_float:
037e8744
JB
11887 switch (size)
11888 {
8e79c3df 11889 case 16: return N_F16;
037e8744
JB
11890 case 32: return N_F32;
11891 case 64: return N_F64;
11892 default: ;
11893 }
5287ad62
JB
11894 break;
11895
11896 case NT_poly:
11897 switch (size)
11898 {
11899 case 8: return N_P8;
11900 case 16: return N_P16;
11901 default: ;
11902 }
11903 break;
11904
11905 case NT_signed:
11906 switch (size)
11907 {
11908 case 8: return N_S8;
11909 case 16: return N_S16;
11910 case 32: return N_S32;
11911 case 64: return N_S64;
11912 default: ;
11913 }
11914 break;
11915
11916 case NT_unsigned:
11917 switch (size)
11918 {
11919 case 8: return N_U8;
11920 case 16: return N_U16;
11921 case 32: return N_U32;
11922 case 64: return N_U64;
11923 default: ;
11924 }
11925 break;
11926
11927 default: ;
11928 }
5f4273c7 11929
5287ad62
JB
11930 return N_UTYP;
11931}
11932
11933/* Convert compact Neon bitmask type representation to a type and size. Only
11934 handles the case where a single bit is set in the mask. */
11935
dcbf9037 11936static int
5287ad62
JB
11937el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11938 enum neon_type_mask mask)
11939{
dcbf9037
JB
11940 if ((mask & N_EQK) != 0)
11941 return FAIL;
11942
5287ad62
JB
11943 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11944 *size = 8;
dcbf9037 11945 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11946 *size = 16;
dcbf9037 11947 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11948 *size = 32;
037e8744 11949 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11950 *size = 64;
dcbf9037
JB
11951 else
11952 return FAIL;
11953
5287ad62
JB
11954 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11955 *type = NT_signed;
dcbf9037 11956 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11957 *type = NT_unsigned;
dcbf9037 11958 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11959 *type = NT_integer;
dcbf9037 11960 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11961 *type = NT_untyped;
dcbf9037 11962 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11963 *type = NT_poly;
037e8744 11964 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11965 *type = NT_float;
dcbf9037
JB
11966 else
11967 return FAIL;
5f4273c7 11968
dcbf9037 11969 return SUCCESS;
5287ad62
JB
11970}
11971
11972/* Modify a bitmask of allowed types. This is only needed for type
11973 relaxation. */
11974
11975static unsigned
11976modify_types_allowed (unsigned allowed, unsigned mods)
11977{
11978 unsigned size;
11979 enum neon_el_type type;
11980 unsigned destmask;
11981 int i;
5f4273c7 11982
5287ad62 11983 destmask = 0;
5f4273c7 11984
5287ad62
JB
11985 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11986 {
21d799b5
NC
11987 if (el_type_of_type_chk (&type, &size,
11988 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
11989 {
11990 neon_modify_type_size (mods, &type, &size);
11991 destmask |= type_chk_of_el_type (type, size);
11992 }
5287ad62 11993 }
5f4273c7 11994
5287ad62
JB
11995 return destmask;
11996}
11997
11998/* Check type and return type classification.
11999 The manual states (paraphrase): If one datatype is given, it indicates the
12000 type given in:
12001 - the second operand, if there is one
12002 - the operand, if there is no second operand
12003 - the result, if there are no operands.
12004 This isn't quite good enough though, so we use a concept of a "key" datatype
12005 which is set on a per-instruction basis, which is the one which matters when
12006 only one data type is written.
12007 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 12008 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
12009
12010static struct neon_type_el
12011neon_check_type (unsigned els, enum neon_shape ns, ...)
12012{
12013 va_list ap;
12014 unsigned i, pass, key_el = 0;
12015 unsigned types[NEON_MAX_TYPE_ELS];
12016 enum neon_el_type k_type = NT_invtype;
12017 unsigned k_size = -1u;
12018 struct neon_type_el badtype = {NT_invtype, -1};
12019 unsigned key_allowed = 0;
12020
12021 /* Optional registers in Neon instructions are always (not) in operand 1.
12022 Fill in the missing operand here, if it was omitted. */
12023 if (els > 1 && !inst.operands[1].present)
12024 inst.operands[1] = inst.operands[0];
12025
12026 /* Suck up all the varargs. */
12027 va_start (ap, ns);
12028 for (i = 0; i < els; i++)
12029 {
12030 unsigned thisarg = va_arg (ap, unsigned);
12031 if (thisarg == N_IGNORE_TYPE)
12032 {
12033 va_end (ap);
12034 return badtype;
12035 }
12036 types[i] = thisarg;
12037 if ((thisarg & N_KEY) != 0)
12038 key_el = i;
12039 }
12040 va_end (ap);
12041
dcbf9037
JB
12042 if (inst.vectype.elems > 0)
12043 for (i = 0; i < els; i++)
12044 if (inst.operands[i].vectype.type != NT_invtype)
12045 {
12046 first_error (_("types specified in both the mnemonic and operands"));
12047 return badtype;
12048 }
12049
5287ad62
JB
12050 /* Duplicate inst.vectype elements here as necessary.
12051 FIXME: No idea if this is exactly the same as the ARM assembler,
12052 particularly when an insn takes one register and one non-register
12053 operand. */
12054 if (inst.vectype.elems == 1 && els > 1)
12055 {
12056 unsigned j;
12057 inst.vectype.elems = els;
12058 inst.vectype.el[key_el] = inst.vectype.el[0];
12059 for (j = 0; j < els; j++)
dcbf9037
JB
12060 if (j != key_el)
12061 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12062 types[j]);
12063 }
12064 else if (inst.vectype.elems == 0 && els > 0)
12065 {
12066 unsigned j;
12067 /* No types were given after the mnemonic, so look for types specified
12068 after each operand. We allow some flexibility here; as long as the
12069 "key" operand has a type, we can infer the others. */
12070 for (j = 0; j < els; j++)
12071 if (inst.operands[j].vectype.type != NT_invtype)
12072 inst.vectype.el[j] = inst.operands[j].vectype;
12073
12074 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 12075 {
dcbf9037
JB
12076 for (j = 0; j < els; j++)
12077 if (inst.operands[j].vectype.type == NT_invtype)
12078 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12079 types[j]);
12080 }
12081 else
12082 {
12083 first_error (_("operand types can't be inferred"));
12084 return badtype;
5287ad62
JB
12085 }
12086 }
12087 else if (inst.vectype.elems != els)
12088 {
dcbf9037 12089 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
12090 return badtype;
12091 }
12092
12093 for (pass = 0; pass < 2; pass++)
12094 {
12095 for (i = 0; i < els; i++)
12096 {
12097 unsigned thisarg = types[i];
12098 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12099 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12100 enum neon_el_type g_type = inst.vectype.el[i].type;
12101 unsigned g_size = inst.vectype.el[i].size;
12102
12103 /* Decay more-specific signed & unsigned types to sign-insensitive
12104 integer types if sign-specific variants are unavailable. */
12105 if ((g_type == NT_signed || g_type == NT_unsigned)
12106 && (types_allowed & N_SU_ALL) == 0)
12107 g_type = NT_integer;
12108
12109 /* If only untyped args are allowed, decay any more specific types to
12110 them. Some instructions only care about signs for some element
12111 sizes, so handle that properly. */
12112 if ((g_size == 8 && (types_allowed & N_8) != 0)
12113 || (g_size == 16 && (types_allowed & N_16) != 0)
12114 || (g_size == 32 && (types_allowed & N_32) != 0)
12115 || (g_size == 64 && (types_allowed & N_64) != 0))
12116 g_type = NT_untyped;
12117
12118 if (pass == 0)
12119 {
12120 if ((thisarg & N_KEY) != 0)
12121 {
12122 k_type = g_type;
12123 k_size = g_size;
12124 key_allowed = thisarg & ~N_KEY;
12125 }
12126 }
12127 else
12128 {
037e8744
JB
12129 if ((thisarg & N_VFP) != 0)
12130 {
99b253c5
NC
12131 enum neon_shape_el regshape;
12132 unsigned regwidth, match;
12133
12134 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12135 if (ns == NS_NULL)
12136 {
12137 first_error (_("invalid instruction shape"));
12138 return badtype;
12139 }
12140 regshape = neon_shape_tab[ns].el[i];
12141 regwidth = neon_shape_el_size[regshape];
037e8744
JB
12142
12143 /* In VFP mode, operands must match register widths. If we
12144 have a key operand, use its width, else use the width of
12145 the current operand. */
12146 if (k_size != -1u)
12147 match = k_size;
12148 else
12149 match = g_size;
12150
12151 if (regwidth != match)
12152 {
12153 first_error (_("operand size must match register width"));
12154 return badtype;
12155 }
12156 }
5f4273c7 12157
5287ad62
JB
12158 if ((thisarg & N_EQK) == 0)
12159 {
12160 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12161
12162 if ((given_type & types_allowed) == 0)
12163 {
dcbf9037 12164 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12165 return badtype;
12166 }
12167 }
12168 else
12169 {
12170 enum neon_el_type mod_k_type = k_type;
12171 unsigned mod_k_size = k_size;
12172 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12173 if (g_type != mod_k_type || g_size != mod_k_size)
12174 {
dcbf9037 12175 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12176 return badtype;
12177 }
12178 }
12179 }
12180 }
12181 }
12182
12183 return inst.vectype.el[key_el];
12184}
12185
037e8744 12186/* Neon-style VFP instruction forwarding. */
5287ad62 12187
037e8744
JB
12188/* Thumb VFP instructions have 0xE in the condition field. */
12189
12190static void
12191do_vfp_cond_or_thumb (void)
5287ad62 12192{
88714cb8
DG
12193 inst.is_neon = 1;
12194
5287ad62 12195 if (thumb_mode)
037e8744 12196 inst.instruction |= 0xe0000000;
5287ad62 12197 else
037e8744 12198 inst.instruction |= inst.cond << 28;
5287ad62
JB
12199}
12200
037e8744
JB
12201/* Look up and encode a simple mnemonic, for use as a helper function for the
12202 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12203 etc. It is assumed that operand parsing has already been done, and that the
12204 operands are in the form expected by the given opcode (this isn't necessarily
12205 the same as the form in which they were parsed, hence some massaging must
12206 take place before this function is called).
12207 Checks current arch version against that in the looked-up opcode. */
5287ad62 12208
037e8744
JB
12209static void
12210do_vfp_nsyn_opcode (const char *opname)
5287ad62 12211{
037e8744 12212 const struct asm_opcode *opcode;
5f4273c7 12213
21d799b5 12214 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12215
037e8744
JB
12216 if (!opcode)
12217 abort ();
5287ad62 12218
037e8744
JB
12219 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12220 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12221 _(BAD_FPU));
5287ad62 12222
88714cb8
DG
12223 inst.is_neon = 1;
12224
037e8744
JB
12225 if (thumb_mode)
12226 {
12227 inst.instruction = opcode->tvalue;
12228 opcode->tencode ();
12229 }
12230 else
12231 {
12232 inst.instruction = (inst.cond << 28) | opcode->avalue;
12233 opcode->aencode ();
12234 }
12235}
5287ad62
JB
12236
12237static void
037e8744 12238do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12239{
037e8744
JB
12240 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12241
12242 if (rs == NS_FFF)
12243 {
12244 if (is_add)
12245 do_vfp_nsyn_opcode ("fadds");
12246 else
12247 do_vfp_nsyn_opcode ("fsubs");
12248 }
12249 else
12250 {
12251 if (is_add)
12252 do_vfp_nsyn_opcode ("faddd");
12253 else
12254 do_vfp_nsyn_opcode ("fsubd");
12255 }
12256}
12257
12258/* Check operand types to see if this is a VFP instruction, and if so call
12259 PFN (). */
12260
12261static int
12262try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12263{
12264 enum neon_shape rs;
12265 struct neon_type_el et;
12266
12267 switch (args)
12268 {
12269 case 2:
12270 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12271 et = neon_check_type (2, rs,
12272 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12273 break;
5f4273c7 12274
037e8744
JB
12275 case 3:
12276 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12277 et = neon_check_type (3, rs,
12278 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12279 break;
12280
12281 default:
12282 abort ();
12283 }
12284
12285 if (et.type != NT_invtype)
12286 {
12287 pfn (rs);
12288 return SUCCESS;
12289 }
037e8744 12290
99b253c5 12291 inst.error = NULL;
037e8744
JB
12292 return FAIL;
12293}
12294
12295static void
12296do_vfp_nsyn_mla_mls (enum neon_shape rs)
12297{
12298 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12299
037e8744
JB
12300 if (rs == NS_FFF)
12301 {
12302 if (is_mla)
12303 do_vfp_nsyn_opcode ("fmacs");
12304 else
1ee69515 12305 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12306 }
12307 else
12308 {
12309 if (is_mla)
12310 do_vfp_nsyn_opcode ("fmacd");
12311 else
1ee69515 12312 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12313 }
12314}
12315
62f3b8c8
PB
12316static void
12317do_vfp_nsyn_fma_fms (enum neon_shape rs)
12318{
12319 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12320
12321 if (rs == NS_FFF)
12322 {
12323 if (is_fma)
12324 do_vfp_nsyn_opcode ("ffmas");
12325 else
12326 do_vfp_nsyn_opcode ("ffnmas");
12327 }
12328 else
12329 {
12330 if (is_fma)
12331 do_vfp_nsyn_opcode ("ffmad");
12332 else
12333 do_vfp_nsyn_opcode ("ffnmad");
12334 }
12335}
12336
037e8744
JB
12337static void
12338do_vfp_nsyn_mul (enum neon_shape rs)
12339{
12340 if (rs == NS_FFF)
12341 do_vfp_nsyn_opcode ("fmuls");
12342 else
12343 do_vfp_nsyn_opcode ("fmuld");
12344}
12345
12346static void
12347do_vfp_nsyn_abs_neg (enum neon_shape rs)
12348{
12349 int is_neg = (inst.instruction & 0x80) != 0;
12350 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12351
12352 if (rs == NS_FF)
12353 {
12354 if (is_neg)
12355 do_vfp_nsyn_opcode ("fnegs");
12356 else
12357 do_vfp_nsyn_opcode ("fabss");
12358 }
12359 else
12360 {
12361 if (is_neg)
12362 do_vfp_nsyn_opcode ("fnegd");
12363 else
12364 do_vfp_nsyn_opcode ("fabsd");
12365 }
12366}
12367
12368/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12369 insns belong to Neon, and are handled elsewhere. */
12370
12371static void
12372do_vfp_nsyn_ldm_stm (int is_dbmode)
12373{
12374 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12375 if (is_ldm)
12376 {
12377 if (is_dbmode)
12378 do_vfp_nsyn_opcode ("fldmdbs");
12379 else
12380 do_vfp_nsyn_opcode ("fldmias");
12381 }
12382 else
12383 {
12384 if (is_dbmode)
12385 do_vfp_nsyn_opcode ("fstmdbs");
12386 else
12387 do_vfp_nsyn_opcode ("fstmias");
12388 }
12389}
12390
037e8744
JB
12391static void
12392do_vfp_nsyn_sqrt (void)
12393{
12394 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12395 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12396
037e8744
JB
12397 if (rs == NS_FF)
12398 do_vfp_nsyn_opcode ("fsqrts");
12399 else
12400 do_vfp_nsyn_opcode ("fsqrtd");
12401}
12402
12403static void
12404do_vfp_nsyn_div (void)
12405{
12406 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12407 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12408 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12409
037e8744
JB
12410 if (rs == NS_FFF)
12411 do_vfp_nsyn_opcode ("fdivs");
12412 else
12413 do_vfp_nsyn_opcode ("fdivd");
12414}
12415
12416static void
12417do_vfp_nsyn_nmul (void)
12418{
12419 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12420 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12421 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12422
037e8744
JB
12423 if (rs == NS_FFF)
12424 {
88714cb8 12425 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12426 do_vfp_sp_dyadic ();
12427 }
12428 else
12429 {
88714cb8 12430 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12431 do_vfp_dp_rd_rn_rm ();
12432 }
12433 do_vfp_cond_or_thumb ();
12434}
12435
12436static void
12437do_vfp_nsyn_cmp (void)
12438{
12439 if (inst.operands[1].isreg)
12440 {
12441 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12442 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12443
037e8744
JB
12444 if (rs == NS_FF)
12445 {
88714cb8 12446 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12447 do_vfp_sp_monadic ();
12448 }
12449 else
12450 {
88714cb8 12451 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12452 do_vfp_dp_rd_rm ();
12453 }
12454 }
12455 else
12456 {
12457 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12458 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12459
12460 switch (inst.instruction & 0x0fffffff)
12461 {
12462 case N_MNEM_vcmp:
12463 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12464 break;
12465 case N_MNEM_vcmpe:
12466 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12467 break;
12468 default:
12469 abort ();
12470 }
5f4273c7 12471
037e8744
JB
12472 if (rs == NS_FI)
12473 {
88714cb8 12474 NEON_ENCODE (SINGLE, inst);
037e8744
JB
12475 do_vfp_sp_compare_z ();
12476 }
12477 else
12478 {
88714cb8 12479 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
12480 do_vfp_dp_rd ();
12481 }
12482 }
12483 do_vfp_cond_or_thumb ();
12484}
12485
12486static void
12487nsyn_insert_sp (void)
12488{
12489 inst.operands[1] = inst.operands[0];
12490 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12491 inst.operands[0].reg = REG_SP;
037e8744
JB
12492 inst.operands[0].isreg = 1;
12493 inst.operands[0].writeback = 1;
12494 inst.operands[0].present = 1;
12495}
12496
12497static void
12498do_vfp_nsyn_push (void)
12499{
12500 nsyn_insert_sp ();
12501 if (inst.operands[1].issingle)
12502 do_vfp_nsyn_opcode ("fstmdbs");
12503 else
12504 do_vfp_nsyn_opcode ("fstmdbd");
12505}
12506
12507static void
12508do_vfp_nsyn_pop (void)
12509{
12510 nsyn_insert_sp ();
12511 if (inst.operands[1].issingle)
22b5b651 12512 do_vfp_nsyn_opcode ("fldmias");
037e8744 12513 else
22b5b651 12514 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12515}
12516
12517/* Fix up Neon data-processing instructions, ORing in the correct bits for
12518 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12519
88714cb8
DG
12520static void
12521neon_dp_fixup (struct arm_it* insn)
037e8744 12522{
88714cb8
DG
12523 unsigned int i = insn->instruction;
12524 insn->is_neon = 1;
12525
037e8744
JB
12526 if (thumb_mode)
12527 {
12528 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12529 if (i & (1 << 24))
12530 i |= 1 << 28;
5f4273c7 12531
037e8744 12532 i &= ~(1 << 24);
5f4273c7 12533
037e8744
JB
12534 i |= 0xef000000;
12535 }
12536 else
12537 i |= 0xf2000000;
5f4273c7 12538
88714cb8 12539 insn->instruction = i;
037e8744
JB
12540}
12541
12542/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12543 (0, 1, 2, 3). */
12544
12545static unsigned
12546neon_logbits (unsigned x)
12547{
12548 return ffs (x) - 4;
12549}
12550
12551#define LOW4(R) ((R) & 0xf)
12552#define HI1(R) (((R) >> 4) & 1)
12553
12554/* Encode insns with bit pattern:
12555
12556 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12557 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12558
037e8744
JB
12559 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12560 different meaning for some instruction. */
12561
12562static void
12563neon_three_same (int isquad, int ubit, int size)
12564{
12565 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12566 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12567 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12568 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12569 inst.instruction |= LOW4 (inst.operands[2].reg);
12570 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12571 inst.instruction |= (isquad != 0) << 6;
12572 inst.instruction |= (ubit != 0) << 24;
12573 if (size != -1)
12574 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12575
88714cb8 12576 neon_dp_fixup (&inst);
037e8744
JB
12577}
12578
12579/* Encode instructions of the form:
12580
12581 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12582 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12583
12584 Don't write size if SIZE == -1. */
12585
12586static void
12587neon_two_same (int qbit, int ubit, int size)
12588{
12589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12591 inst.instruction |= LOW4 (inst.operands[1].reg);
12592 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12593 inst.instruction |= (qbit != 0) << 6;
12594 inst.instruction |= (ubit != 0) << 24;
12595
12596 if (size != -1)
12597 inst.instruction |= neon_logbits (size) << 18;
12598
88714cb8 12599 neon_dp_fixup (&inst);
5287ad62
JB
12600}
12601
12602/* Neon instruction encoders, in approximate order of appearance. */
12603
12604static void
12605do_neon_dyadic_i_su (void)
12606{
037e8744 12607 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12608 struct neon_type_el et = neon_check_type (3, rs,
12609 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12610 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12611}
12612
12613static void
12614do_neon_dyadic_i64_su (void)
12615{
037e8744 12616 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12617 struct neon_type_el et = neon_check_type (3, rs,
12618 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12619 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12620}
12621
12622static void
12623neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12624 unsigned immbits)
12625{
12626 unsigned size = et.size >> 3;
12627 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12628 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12629 inst.instruction |= LOW4 (inst.operands[1].reg);
12630 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12631 inst.instruction |= (isquad != 0) << 6;
12632 inst.instruction |= immbits << 16;
12633 inst.instruction |= (size >> 3) << 7;
12634 inst.instruction |= (size & 0x7) << 19;
12635 if (write_ubit)
12636 inst.instruction |= (uval != 0) << 24;
12637
88714cb8 12638 neon_dp_fixup (&inst);
5287ad62
JB
12639}
12640
12641static void
12642do_neon_shl_imm (void)
12643{
12644 if (!inst.operands[2].isreg)
12645 {
037e8744 12646 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12647 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
88714cb8 12648 NEON_ENCODE (IMMED, inst);
037e8744 12649 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12650 }
12651 else
12652 {
037e8744 12653 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12654 struct neon_type_el et = neon_check_type (3, rs,
12655 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12656 unsigned int tmp;
12657
12658 /* VSHL/VQSHL 3-register variants have syntax such as:
12659 vshl.xx Dd, Dm, Dn
12660 whereas other 3-register operations encoded by neon_three_same have
12661 syntax like:
12662 vadd.xx Dd, Dn, Dm
12663 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12664 here. */
12665 tmp = inst.operands[2].reg;
12666 inst.operands[2].reg = inst.operands[1].reg;
12667 inst.operands[1].reg = tmp;
88714cb8 12668 NEON_ENCODE (INTEGER, inst);
037e8744 12669 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12670 }
12671}
12672
12673static void
12674do_neon_qshl_imm (void)
12675{
12676 if (!inst.operands[2].isreg)
12677 {
037e8744 12678 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12679 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12680
88714cb8 12681 NEON_ENCODE (IMMED, inst);
037e8744 12682 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12683 inst.operands[2].imm);
12684 }
12685 else
12686 {
037e8744 12687 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12688 struct neon_type_el et = neon_check_type (3, rs,
12689 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12690 unsigned int tmp;
12691
12692 /* See note in do_neon_shl_imm. */
12693 tmp = inst.operands[2].reg;
12694 inst.operands[2].reg = inst.operands[1].reg;
12695 inst.operands[1].reg = tmp;
88714cb8 12696 NEON_ENCODE (INTEGER, inst);
037e8744 12697 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12698 }
12699}
12700
627907b7
JB
12701static void
12702do_neon_rshl (void)
12703{
12704 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12705 struct neon_type_el et = neon_check_type (3, rs,
12706 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12707 unsigned int tmp;
12708
12709 tmp = inst.operands[2].reg;
12710 inst.operands[2].reg = inst.operands[1].reg;
12711 inst.operands[1].reg = tmp;
12712 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12713}
12714
5287ad62
JB
12715static int
12716neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12717{
036dc3f7
PB
12718 /* Handle .I8 pseudo-instructions. */
12719 if (size == 8)
5287ad62 12720 {
5287ad62
JB
12721 /* Unfortunately, this will make everything apart from zero out-of-range.
12722 FIXME is this the intended semantics? There doesn't seem much point in
12723 accepting .I8 if so. */
12724 immediate |= immediate << 8;
12725 size = 16;
036dc3f7
PB
12726 }
12727
12728 if (size >= 32)
12729 {
12730 if (immediate == (immediate & 0x000000ff))
12731 {
12732 *immbits = immediate;
12733 return 0x1;
12734 }
12735 else if (immediate == (immediate & 0x0000ff00))
12736 {
12737 *immbits = immediate >> 8;
12738 return 0x3;
12739 }
12740 else if (immediate == (immediate & 0x00ff0000))
12741 {
12742 *immbits = immediate >> 16;
12743 return 0x5;
12744 }
12745 else if (immediate == (immediate & 0xff000000))
12746 {
12747 *immbits = immediate >> 24;
12748 return 0x7;
12749 }
12750 if ((immediate & 0xffff) != (immediate >> 16))
12751 goto bad_immediate;
12752 immediate &= 0xffff;
5287ad62
JB
12753 }
12754
12755 if (immediate == (immediate & 0x000000ff))
12756 {
12757 *immbits = immediate;
036dc3f7 12758 return 0x9;
5287ad62
JB
12759 }
12760 else if (immediate == (immediate & 0x0000ff00))
12761 {
12762 *immbits = immediate >> 8;
036dc3f7 12763 return 0xb;
5287ad62
JB
12764 }
12765
12766 bad_immediate:
dcbf9037 12767 first_error (_("immediate value out of range"));
5287ad62
JB
12768 return FAIL;
12769}
12770
12771/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12772 A, B, C, D. */
12773
12774static int
12775neon_bits_same_in_bytes (unsigned imm)
12776{
12777 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12778 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12779 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12780 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12781}
12782
12783/* For immediate of above form, return 0bABCD. */
12784
12785static unsigned
12786neon_squash_bits (unsigned imm)
12787{
12788 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12789 | ((imm & 0x01000000) >> 21);
12790}
12791
136da414 12792/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12793
12794static unsigned
12795neon_qfloat_bits (unsigned imm)
12796{
136da414 12797 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12798}
12799
12800/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12801 the instruction. *OP is passed as the initial value of the op field, and
12802 may be set to a different value depending on the constant (i.e.
12803 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12804 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12805 try smaller element sizes. */
5287ad62
JB
12806
12807static int
c96612cc
JB
12808neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12809 unsigned *immbits, int *op, int size,
12810 enum neon_el_type type)
5287ad62 12811{
c96612cc
JB
12812 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12813 float. */
12814 if (type == NT_float && !float_p)
12815 return FAIL;
12816
136da414
JB
12817 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12818 {
12819 if (size != 32 || *op == 1)
12820 return FAIL;
12821 *immbits = neon_qfloat_bits (immlo);
12822 return 0xf;
12823 }
036dc3f7
PB
12824
12825 if (size == 64)
5287ad62 12826 {
036dc3f7
PB
12827 if (neon_bits_same_in_bytes (immhi)
12828 && neon_bits_same_in_bytes (immlo))
12829 {
12830 if (*op == 1)
12831 return FAIL;
12832 *immbits = (neon_squash_bits (immhi) << 4)
12833 | neon_squash_bits (immlo);
12834 *op = 1;
12835 return 0xe;
12836 }
12837
12838 if (immhi != immlo)
12839 return FAIL;
5287ad62 12840 }
036dc3f7
PB
12841
12842 if (size >= 32)
5287ad62 12843 {
036dc3f7
PB
12844 if (immlo == (immlo & 0x000000ff))
12845 {
12846 *immbits = immlo;
12847 return 0x0;
12848 }
12849 else if (immlo == (immlo & 0x0000ff00))
12850 {
12851 *immbits = immlo >> 8;
12852 return 0x2;
12853 }
12854 else if (immlo == (immlo & 0x00ff0000))
12855 {
12856 *immbits = immlo >> 16;
12857 return 0x4;
12858 }
12859 else if (immlo == (immlo & 0xff000000))
12860 {
12861 *immbits = immlo >> 24;
12862 return 0x6;
12863 }
12864 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12865 {
12866 *immbits = (immlo >> 8) & 0xff;
12867 return 0xc;
12868 }
12869 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12870 {
12871 *immbits = (immlo >> 16) & 0xff;
12872 return 0xd;
12873 }
12874
12875 if ((immlo & 0xffff) != (immlo >> 16))
12876 return FAIL;
12877 immlo &= 0xffff;
5287ad62 12878 }
036dc3f7
PB
12879
12880 if (size >= 16)
5287ad62 12881 {
036dc3f7
PB
12882 if (immlo == (immlo & 0x000000ff))
12883 {
12884 *immbits = immlo;
12885 return 0x8;
12886 }
12887 else if (immlo == (immlo & 0x0000ff00))
12888 {
12889 *immbits = immlo >> 8;
12890 return 0xa;
12891 }
12892
12893 if ((immlo & 0xff) != (immlo >> 8))
12894 return FAIL;
12895 immlo &= 0xff;
5287ad62 12896 }
036dc3f7
PB
12897
12898 if (immlo == (immlo & 0x000000ff))
5287ad62 12899 {
036dc3f7
PB
12900 /* Don't allow MVN with 8-bit immediate. */
12901 if (*op == 1)
12902 return FAIL;
12903 *immbits = immlo;
12904 return 0xe;
5287ad62 12905 }
5287ad62
JB
12906
12907 return FAIL;
12908}
12909
12910/* Write immediate bits [7:0] to the following locations:
12911
12912 |28/24|23 19|18 16|15 4|3 0|
12913 | 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|
12914
12915 This function is used by VMOV/VMVN/VORR/VBIC. */
12916
12917static void
12918neon_write_immbits (unsigned immbits)
12919{
12920 inst.instruction |= immbits & 0xf;
12921 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12922 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12923}
12924
12925/* Invert low-order SIZE bits of XHI:XLO. */
12926
12927static void
12928neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12929{
12930 unsigned immlo = xlo ? *xlo : 0;
12931 unsigned immhi = xhi ? *xhi : 0;
12932
12933 switch (size)
12934 {
12935 case 8:
12936 immlo = (~immlo) & 0xff;
12937 break;
12938
12939 case 16:
12940 immlo = (~immlo) & 0xffff;
12941 break;
12942
12943 case 64:
12944 immhi = (~immhi) & 0xffffffff;
12945 /* fall through. */
12946
12947 case 32:
12948 immlo = (~immlo) & 0xffffffff;
12949 break;
12950
12951 default:
12952 abort ();
12953 }
12954
12955 if (xlo)
12956 *xlo = immlo;
12957
12958 if (xhi)
12959 *xhi = immhi;
12960}
12961
12962static void
12963do_neon_logic (void)
12964{
12965 if (inst.operands[2].present && inst.operands[2].isreg)
12966 {
037e8744 12967 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12968 neon_check_type (3, rs, N_IGNORE_TYPE);
12969 /* U bit and size field were set as part of the bitmask. */
88714cb8 12970 NEON_ENCODE (INTEGER, inst);
037e8744 12971 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12972 }
12973 else
12974 {
4316f0d2
DG
12975 const int three_ops_form = (inst.operands[2].present
12976 && !inst.operands[2].isreg);
12977 const int immoperand = (three_ops_form ? 2 : 1);
12978 enum neon_shape rs = (three_ops_form
12979 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
12980 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744
JB
12981 struct neon_type_el et = neon_check_type (2, rs,
12982 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 12983 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
12984 unsigned immbits;
12985 int cmode;
5f4273c7 12986
5287ad62
JB
12987 if (et.type == NT_invtype)
12988 return;
5f4273c7 12989
4316f0d2
DG
12990 if (three_ops_form)
12991 constraint (inst.operands[0].reg != inst.operands[1].reg,
12992 _("first and second operands shall be the same register"));
12993
88714cb8 12994 NEON_ENCODE (IMMED, inst);
5287ad62 12995
4316f0d2 12996 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
12997 if (et.size == 64)
12998 {
12999 /* .i64 is a pseudo-op, so the immediate must be a repeating
13000 pattern. */
4316f0d2
DG
13001 if (immbits != (inst.operands[immoperand].regisimm ?
13002 inst.operands[immoperand].reg : 0))
036dc3f7
PB
13003 {
13004 /* Set immbits to an invalid constant. */
13005 immbits = 0xdeadbeef;
13006 }
13007 }
13008
5287ad62
JB
13009 switch (opcode)
13010 {
13011 case N_MNEM_vbic:
036dc3f7 13012 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13013 break;
5f4273c7 13014
5287ad62 13015 case N_MNEM_vorr:
036dc3f7 13016 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 13017 break;
5f4273c7 13018
5287ad62
JB
13019 case N_MNEM_vand:
13020 /* Pseudo-instruction for VBIC. */
5287ad62
JB
13021 neon_invert_size (&immbits, 0, et.size);
13022 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13023 break;
5f4273c7 13024
5287ad62
JB
13025 case N_MNEM_vorn:
13026 /* Pseudo-instruction for VORR. */
5287ad62
JB
13027 neon_invert_size (&immbits, 0, et.size);
13028 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13029 break;
5f4273c7 13030
5287ad62
JB
13031 default:
13032 abort ();
13033 }
13034
13035 if (cmode == FAIL)
13036 return;
13037
037e8744 13038 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13039 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13040 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13041 inst.instruction |= cmode << 8;
13042 neon_write_immbits (immbits);
5f4273c7 13043
88714cb8 13044 neon_dp_fixup (&inst);
5287ad62
JB
13045 }
13046}
13047
13048static void
13049do_neon_bitfield (void)
13050{
037e8744 13051 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 13052 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 13053 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13054}
13055
13056static void
dcbf9037
JB
13057neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13058 unsigned destbits)
5287ad62 13059{
037e8744 13060 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
13061 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13062 types | N_KEY);
5287ad62
JB
13063 if (et.type == NT_float)
13064 {
88714cb8 13065 NEON_ENCODE (FLOAT, inst);
037e8744 13066 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13067 }
13068 else
13069 {
88714cb8 13070 NEON_ENCODE (INTEGER, inst);
037e8744 13071 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
13072 }
13073}
13074
13075static void
13076do_neon_dyadic_if_su (void)
13077{
dcbf9037 13078 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13079}
13080
13081static void
13082do_neon_dyadic_if_su_d (void)
13083{
13084 /* This version only allow D registers, but that constraint is enforced during
13085 operand parsing so we don't need to do anything extra here. */
dcbf9037 13086 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
13087}
13088
5287ad62
JB
13089static void
13090do_neon_dyadic_if_i_d (void)
13091{
428e3f1f
PB
13092 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13093 affected if we specify unsigned args. */
13094 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
13095}
13096
037e8744
JB
13097enum vfp_or_neon_is_neon_bits
13098{
13099 NEON_CHECK_CC = 1,
13100 NEON_CHECK_ARCH = 2
13101};
13102
13103/* Call this function if an instruction which may have belonged to the VFP or
13104 Neon instruction sets, but turned out to be a Neon instruction (due to the
13105 operand types involved, etc.). We have to check and/or fix-up a couple of
13106 things:
13107
13108 - Make sure the user hasn't attempted to make a Neon instruction
13109 conditional.
13110 - Alter the value in the condition code field if necessary.
13111 - Make sure that the arch supports Neon instructions.
13112
13113 Which of these operations take place depends on bits from enum
13114 vfp_or_neon_is_neon_bits.
13115
13116 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13117 current instruction's condition is COND_ALWAYS, the condition field is
13118 changed to inst.uncond_value. This is necessary because instructions shared
13119 between VFP and Neon may be conditional for the VFP variants only, and the
13120 unconditional Neon version must have, e.g., 0xF in the condition field. */
13121
13122static int
13123vfp_or_neon_is_neon (unsigned check)
13124{
13125 /* Conditions are always legal in Thumb mode (IT blocks). */
13126 if (!thumb_mode && (check & NEON_CHECK_CC))
13127 {
13128 if (inst.cond != COND_ALWAYS)
13129 {
13130 first_error (_(BAD_COND));
13131 return FAIL;
13132 }
13133 if (inst.uncond_value != -1)
13134 inst.instruction |= inst.uncond_value << 28;
13135 }
5f4273c7 13136
037e8744
JB
13137 if ((check & NEON_CHECK_ARCH)
13138 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13139 {
13140 first_error (_(BAD_FPU));
13141 return FAIL;
13142 }
5f4273c7 13143
037e8744
JB
13144 return SUCCESS;
13145}
13146
5287ad62
JB
13147static void
13148do_neon_addsub_if_i (void)
13149{
037e8744
JB
13150 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13151 return;
13152
13153 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13154 return;
13155
5287ad62
JB
13156 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13157 affected if we specify unsigned args. */
dcbf9037 13158 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13159}
13160
13161/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13162 result to be:
13163 V<op> A,B (A is operand 0, B is operand 2)
13164 to mean:
13165 V<op> A,B,A
13166 not:
13167 V<op> A,B,B
13168 so handle that case specially. */
13169
13170static void
13171neon_exchange_operands (void)
13172{
13173 void *scratch = alloca (sizeof (inst.operands[0]));
13174 if (inst.operands[1].present)
13175 {
13176 /* Swap operands[1] and operands[2]. */
13177 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13178 inst.operands[1] = inst.operands[2];
13179 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13180 }
13181 else
13182 {
13183 inst.operands[1] = inst.operands[2];
13184 inst.operands[2] = inst.operands[0];
13185 }
13186}
13187
13188static void
13189neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13190{
13191 if (inst.operands[2].isreg)
13192 {
13193 if (invert)
13194 neon_exchange_operands ();
dcbf9037 13195 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13196 }
13197 else
13198 {
037e8744 13199 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13200 struct neon_type_el et = neon_check_type (2, rs,
13201 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 13202
88714cb8 13203 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13204 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13205 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13206 inst.instruction |= LOW4 (inst.operands[1].reg);
13207 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13208 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13209 inst.instruction |= (et.type == NT_float) << 10;
13210 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13211
88714cb8 13212 neon_dp_fixup (&inst);
5287ad62
JB
13213 }
13214}
13215
13216static void
13217do_neon_cmp (void)
13218{
13219 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13220}
13221
13222static void
13223do_neon_cmp_inv (void)
13224{
13225 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13226}
13227
13228static void
13229do_neon_ceq (void)
13230{
13231 neon_compare (N_IF_32, N_IF_32, FALSE);
13232}
13233
13234/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13235 scalars, which are encoded in 5 bits, M : Rm.
13236 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13237 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13238 index in M. */
13239
13240static unsigned
13241neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13242{
dcbf9037
JB
13243 unsigned regno = NEON_SCALAR_REG (scalar);
13244 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13245
13246 switch (elsize)
13247 {
13248 case 16:
13249 if (regno > 7 || elno > 3)
13250 goto bad_scalar;
13251 return regno | (elno << 3);
5f4273c7 13252
5287ad62
JB
13253 case 32:
13254 if (regno > 15 || elno > 1)
13255 goto bad_scalar;
13256 return regno | (elno << 4);
13257
13258 default:
13259 bad_scalar:
dcbf9037 13260 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13261 }
13262
13263 return 0;
13264}
13265
13266/* Encode multiply / multiply-accumulate scalar instructions. */
13267
13268static void
13269neon_mul_mac (struct neon_type_el et, int ubit)
13270{
dcbf9037
JB
13271 unsigned scalar;
13272
13273 /* Give a more helpful error message if we have an invalid type. */
13274 if (et.type == NT_invtype)
13275 return;
5f4273c7 13276
dcbf9037 13277 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13278 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13279 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13280 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13281 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13282 inst.instruction |= LOW4 (scalar);
13283 inst.instruction |= HI1 (scalar) << 5;
13284 inst.instruction |= (et.type == NT_float) << 8;
13285 inst.instruction |= neon_logbits (et.size) << 20;
13286 inst.instruction |= (ubit != 0) << 24;
13287
88714cb8 13288 neon_dp_fixup (&inst);
5287ad62
JB
13289}
13290
13291static void
13292do_neon_mac_maybe_scalar (void)
13293{
037e8744
JB
13294 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13295 return;
13296
13297 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13298 return;
13299
5287ad62
JB
13300 if (inst.operands[2].isscalar)
13301 {
037e8744 13302 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13303 struct neon_type_el et = neon_check_type (3, rs,
13304 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 13305 NEON_ENCODE (SCALAR, inst);
037e8744 13306 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13307 }
13308 else
428e3f1f
PB
13309 {
13310 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13311 affected if we specify unsigned args. */
13312 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13313 }
5287ad62
JB
13314}
13315
62f3b8c8
PB
13316static void
13317do_neon_fmac (void)
13318{
13319 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13320 return;
13321
13322 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13323 return;
13324
13325 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13326}
13327
5287ad62
JB
13328static void
13329do_neon_tst (void)
13330{
037e8744 13331 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13332 struct neon_type_el et = neon_check_type (3, rs,
13333 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13334 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13335}
13336
13337/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13338 same types as the MAC equivalents. The polynomial type for this instruction
13339 is encoded the same as the integer type. */
13340
13341static void
13342do_neon_mul (void)
13343{
037e8744
JB
13344 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13345 return;
13346
13347 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13348 return;
13349
5287ad62
JB
13350 if (inst.operands[2].isscalar)
13351 do_neon_mac_maybe_scalar ();
13352 else
dcbf9037 13353 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13354}
13355
13356static void
13357do_neon_qdmulh (void)
13358{
13359 if (inst.operands[2].isscalar)
13360 {
037e8744 13361 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13362 struct neon_type_el et = neon_check_type (3, rs,
13363 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13364 NEON_ENCODE (SCALAR, inst);
037e8744 13365 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13366 }
13367 else
13368 {
037e8744 13369 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13370 struct neon_type_el et = neon_check_type (3, rs,
13371 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 13372 NEON_ENCODE (INTEGER, inst);
5287ad62 13373 /* The U bit (rounding) comes from bit mask. */
037e8744 13374 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13375 }
13376}
13377
13378static void
13379do_neon_fcmp_absolute (void)
13380{
037e8744 13381 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13382 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13383 /* Size field comes from bit mask. */
037e8744 13384 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13385}
13386
13387static void
13388do_neon_fcmp_absolute_inv (void)
13389{
13390 neon_exchange_operands ();
13391 do_neon_fcmp_absolute ();
13392}
13393
13394static void
13395do_neon_step (void)
13396{
037e8744 13397 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13398 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13399 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13400}
13401
13402static void
13403do_neon_abs_neg (void)
13404{
037e8744
JB
13405 enum neon_shape rs;
13406 struct neon_type_el et;
5f4273c7 13407
037e8744
JB
13408 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13409 return;
13410
13411 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13412 return;
13413
13414 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13415 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13416
5287ad62
JB
13417 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13418 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13419 inst.instruction |= LOW4 (inst.operands[1].reg);
13420 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13421 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13422 inst.instruction |= (et.type == NT_float) << 10;
13423 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13424
88714cb8 13425 neon_dp_fixup (&inst);
5287ad62
JB
13426}
13427
13428static void
13429do_neon_sli (void)
13430{
037e8744 13431 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13432 struct neon_type_el et = neon_check_type (2, rs,
13433 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13434 int imm = inst.operands[2].imm;
13435 constraint (imm < 0 || (unsigned)imm >= et.size,
13436 _("immediate out of range for insert"));
037e8744 13437 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13438}
13439
13440static void
13441do_neon_sri (void)
13442{
037e8744 13443 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13444 struct neon_type_el et = neon_check_type (2, rs,
13445 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13446 int imm = inst.operands[2].imm;
13447 constraint (imm < 1 || (unsigned)imm > et.size,
13448 _("immediate out of range for insert"));
037e8744 13449 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13450}
13451
13452static void
13453do_neon_qshlu_imm (void)
13454{
037e8744 13455 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13456 struct neon_type_el et = neon_check_type (2, rs,
13457 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13458 int imm = inst.operands[2].imm;
13459 constraint (imm < 0 || (unsigned)imm >= et.size,
13460 _("immediate out of range for shift"));
13461 /* Only encodes the 'U present' variant of the instruction.
13462 In this case, signed types have OP (bit 8) set to 0.
13463 Unsigned types have OP set to 1. */
13464 inst.instruction |= (et.type == NT_unsigned) << 8;
13465 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13466 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13467}
13468
13469static void
13470do_neon_qmovn (void)
13471{
13472 struct neon_type_el et = neon_check_type (2, NS_DQ,
13473 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13474 /* Saturating move where operands can be signed or unsigned, and the
13475 destination has the same signedness. */
88714cb8 13476 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13477 if (et.type == NT_unsigned)
13478 inst.instruction |= 0xc0;
13479 else
13480 inst.instruction |= 0x80;
13481 neon_two_same (0, 1, et.size / 2);
13482}
13483
13484static void
13485do_neon_qmovun (void)
13486{
13487 struct neon_type_el et = neon_check_type (2, NS_DQ,
13488 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13489 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 13490 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13491 neon_two_same (0, 1, et.size / 2);
13492}
13493
13494static void
13495do_neon_rshift_sat_narrow (void)
13496{
13497 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13498 or unsigned. If operands are unsigned, results must also be unsigned. */
13499 struct neon_type_el et = neon_check_type (2, NS_DQI,
13500 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13501 int imm = inst.operands[2].imm;
13502 /* This gets the bounds check, size encoding and immediate bits calculation
13503 right. */
13504 et.size /= 2;
5f4273c7 13505
5287ad62
JB
13506 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13507 VQMOVN.I<size> <Dd>, <Qm>. */
13508 if (imm == 0)
13509 {
13510 inst.operands[2].present = 0;
13511 inst.instruction = N_MNEM_vqmovn;
13512 do_neon_qmovn ();
13513 return;
13514 }
5f4273c7 13515
5287ad62
JB
13516 constraint (imm < 1 || (unsigned)imm > et.size,
13517 _("immediate out of range"));
13518 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13519}
13520
13521static void
13522do_neon_rshift_sat_narrow_u (void)
13523{
13524 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13525 or unsigned. If operands are unsigned, results must also be unsigned. */
13526 struct neon_type_el et = neon_check_type (2, NS_DQI,
13527 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13528 int imm = inst.operands[2].imm;
13529 /* This gets the bounds check, size encoding and immediate bits calculation
13530 right. */
13531 et.size /= 2;
13532
13533 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13534 VQMOVUN.I<size> <Dd>, <Qm>. */
13535 if (imm == 0)
13536 {
13537 inst.operands[2].present = 0;
13538 inst.instruction = N_MNEM_vqmovun;
13539 do_neon_qmovun ();
13540 return;
13541 }
13542
13543 constraint (imm < 1 || (unsigned)imm > et.size,
13544 _("immediate out of range"));
13545 /* FIXME: The manual is kind of unclear about what value U should have in
13546 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13547 must be 1. */
13548 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13549}
13550
13551static void
13552do_neon_movn (void)
13553{
13554 struct neon_type_el et = neon_check_type (2, NS_DQ,
13555 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 13556 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13557 neon_two_same (0, 1, et.size / 2);
13558}
13559
13560static void
13561do_neon_rshift_narrow (void)
13562{
13563 struct neon_type_el et = neon_check_type (2, NS_DQI,
13564 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13565 int imm = inst.operands[2].imm;
13566 /* This gets the bounds check, size encoding and immediate bits calculation
13567 right. */
13568 et.size /= 2;
5f4273c7 13569
5287ad62
JB
13570 /* If immediate is zero then we are a pseudo-instruction for
13571 VMOVN.I<size> <Dd>, <Qm> */
13572 if (imm == 0)
13573 {
13574 inst.operands[2].present = 0;
13575 inst.instruction = N_MNEM_vmovn;
13576 do_neon_movn ();
13577 return;
13578 }
5f4273c7 13579
5287ad62
JB
13580 constraint (imm < 1 || (unsigned)imm > et.size,
13581 _("immediate out of range for narrowing operation"));
13582 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13583}
13584
13585static void
13586do_neon_shll (void)
13587{
13588 /* FIXME: Type checking when lengthening. */
13589 struct neon_type_el et = neon_check_type (2, NS_QDI,
13590 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13591 unsigned imm = inst.operands[2].imm;
13592
13593 if (imm == et.size)
13594 {
13595 /* Maximum shift variant. */
88714cb8 13596 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13597 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13598 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13599 inst.instruction |= LOW4 (inst.operands[1].reg);
13600 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13601 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13602
88714cb8 13603 neon_dp_fixup (&inst);
5287ad62
JB
13604 }
13605 else
13606 {
13607 /* A more-specific type check for non-max versions. */
13608 et = neon_check_type (2, NS_QDI,
13609 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 13610 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13611 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13612 }
13613}
13614
037e8744 13615/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13616 the current instruction is. */
13617
13618static int
13619neon_cvt_flavour (enum neon_shape rs)
13620{
037e8744
JB
13621#define CVT_VAR(C,X,Y) \
13622 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13623 if (et.type != NT_invtype) \
13624 { \
13625 inst.error = NULL; \
13626 return (C); \
5287ad62
JB
13627 }
13628 struct neon_type_el et;
037e8744
JB
13629 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13630 || rs == NS_FF) ? N_VFP : 0;
13631 /* The instruction versions which take an immediate take one register
13632 argument, which is extended to the width of the full register. Thus the
13633 "source" and "destination" registers must have the same width. Hack that
13634 here by making the size equal to the key (wider, in this case) operand. */
13635 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13636
5287ad62
JB
13637 CVT_VAR (0, N_S32, N_F32);
13638 CVT_VAR (1, N_U32, N_F32);
13639 CVT_VAR (2, N_F32, N_S32);
13640 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13641 /* Half-precision conversions. */
13642 CVT_VAR (4, N_F32, N_F16);
13643 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13644
037e8744 13645 whole_reg = N_VFP;
5f4273c7 13646
037e8744 13647 /* VFP instructions. */
8e79c3df
CM
13648 CVT_VAR (6, N_F32, N_F64);
13649 CVT_VAR (7, N_F64, N_F32);
13650 CVT_VAR (8, N_S32, N_F64 | key);
13651 CVT_VAR (9, N_U32, N_F64 | key);
13652 CVT_VAR (10, N_F64 | key, N_S32);
13653 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13654 /* VFP instructions with bitshift. */
8e79c3df
CM
13655 CVT_VAR (12, N_F32 | key, N_S16);
13656 CVT_VAR (13, N_F32 | key, N_U16);
13657 CVT_VAR (14, N_F64 | key, N_S16);
13658 CVT_VAR (15, N_F64 | key, N_U16);
13659 CVT_VAR (16, N_S16, N_F32 | key);
13660 CVT_VAR (17, N_U16, N_F32 | key);
13661 CVT_VAR (18, N_S16, N_F64 | key);
13662 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13663
5287ad62
JB
13664 return -1;
13665#undef CVT_VAR
13666}
13667
037e8744
JB
13668/* Neon-syntax VFP conversions. */
13669
5287ad62 13670static void
037e8744 13671do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13672{
037e8744 13673 const char *opname = 0;
5f4273c7 13674
037e8744 13675 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13676 {
037e8744
JB
13677 /* Conversions with immediate bitshift. */
13678 const char *enc[] =
13679 {
13680 "ftosls",
13681 "ftouls",
13682 "fsltos",
13683 "fultos",
13684 NULL,
13685 NULL,
8e79c3df
CM
13686 NULL,
13687 NULL,
037e8744
JB
13688 "ftosld",
13689 "ftould",
13690 "fsltod",
13691 "fultod",
13692 "fshtos",
13693 "fuhtos",
13694 "fshtod",
13695 "fuhtod",
13696 "ftoshs",
13697 "ftouhs",
13698 "ftoshd",
13699 "ftouhd"
13700 };
13701
13702 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13703 {
13704 opname = enc[flavour];
13705 constraint (inst.operands[0].reg != inst.operands[1].reg,
13706 _("operands 0 and 1 must be the same register"));
13707 inst.operands[1] = inst.operands[2];
13708 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13709 }
5287ad62
JB
13710 }
13711 else
13712 {
037e8744
JB
13713 /* Conversions without bitshift. */
13714 const char *enc[] =
13715 {
13716 "ftosis",
13717 "ftouis",
13718 "fsitos",
13719 "fuitos",
8e79c3df
CM
13720 "NULL",
13721 "NULL",
037e8744
JB
13722 "fcvtsd",
13723 "fcvtds",
13724 "ftosid",
13725 "ftouid",
13726 "fsitod",
13727 "fuitod"
13728 };
13729
13730 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13731 opname = enc[flavour];
13732 }
13733
13734 if (opname)
13735 do_vfp_nsyn_opcode (opname);
13736}
13737
13738static void
13739do_vfp_nsyn_cvtz (void)
13740{
13741 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13742 int flavour = neon_cvt_flavour (rs);
13743 const char *enc[] =
13744 {
13745 "ftosizs",
13746 "ftouizs",
13747 NULL,
13748 NULL,
13749 NULL,
13750 NULL,
8e79c3df
CM
13751 NULL,
13752 NULL,
037e8744
JB
13753 "ftosizd",
13754 "ftouizd"
13755 };
13756
13757 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13758 do_vfp_nsyn_opcode (enc[flavour]);
13759}
f31fef98 13760
037e8744 13761static void
e3e535bc 13762do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
037e8744
JB
13763{
13764 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13765 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13766 int flavour = neon_cvt_flavour (rs);
13767
e3e535bc
NC
13768 /* PR11109: Handle round-to-zero for VCVT conversions. */
13769 if (round_to_zero
13770 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13771 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13772 && (rs == NS_FD || rs == NS_FF))
13773 {
13774 do_vfp_nsyn_cvtz ();
13775 return;
13776 }
13777
037e8744 13778 /* VFP rather than Neon conversions. */
8e79c3df 13779 if (flavour >= 6)
037e8744
JB
13780 {
13781 do_vfp_nsyn_cvt (rs, flavour);
13782 return;
13783 }
13784
13785 switch (rs)
13786 {
13787 case NS_DDI:
13788 case NS_QQI:
13789 {
35997600
NC
13790 unsigned immbits;
13791 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13792
037e8744
JB
13793 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13794 return;
13795
13796 /* Fixed-point conversion with #0 immediate is encoded as an
13797 integer conversion. */
13798 if (inst.operands[2].present && inst.operands[2].imm == 0)
13799 goto int_encode;
35997600 13800 immbits = 32 - inst.operands[2].imm;
88714cb8 13801 NEON_ENCODE (IMMED, inst);
037e8744
JB
13802 if (flavour != -1)
13803 inst.instruction |= enctab[flavour];
13804 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13805 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13806 inst.instruction |= LOW4 (inst.operands[1].reg);
13807 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13808 inst.instruction |= neon_quad (rs) << 6;
13809 inst.instruction |= 1 << 21;
13810 inst.instruction |= immbits << 16;
13811
88714cb8 13812 neon_dp_fixup (&inst);
037e8744
JB
13813 }
13814 break;
13815
13816 case NS_DD:
13817 case NS_QQ:
13818 int_encode:
13819 {
13820 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13821
88714cb8 13822 NEON_ENCODE (INTEGER, inst);
037e8744
JB
13823
13824 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13825 return;
13826
13827 if (flavour != -1)
13828 inst.instruction |= enctab[flavour];
13829
13830 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13832 inst.instruction |= LOW4 (inst.operands[1].reg);
13833 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13834 inst.instruction |= neon_quad (rs) << 6;
13835 inst.instruction |= 2 << 18;
13836
88714cb8 13837 neon_dp_fixup (&inst);
037e8744
JB
13838 }
13839 break;
13840
8e79c3df
CM
13841 /* Half-precision conversions for Advanced SIMD -- neon. */
13842 case NS_QD:
13843 case NS_DQ:
13844
13845 if ((rs == NS_DQ)
13846 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13847 {
13848 as_bad (_("operand size must match register width"));
13849 break;
13850 }
13851
13852 if ((rs == NS_QD)
13853 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13854 {
13855 as_bad (_("operand size must match register width"));
13856 break;
13857 }
13858
13859 if (rs == NS_DQ)
13860 inst.instruction = 0x3b60600;
13861 else
13862 inst.instruction = 0x3b60700;
13863
13864 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13865 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13866 inst.instruction |= LOW4 (inst.operands[1].reg);
13867 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 13868 neon_dp_fixup (&inst);
8e79c3df
CM
13869 break;
13870
037e8744
JB
13871 default:
13872 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13873 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13874 }
5287ad62
JB
13875}
13876
e3e535bc
NC
13877static void
13878do_neon_cvtr (void)
13879{
13880 do_neon_cvt_1 (FALSE);
13881}
13882
13883static void
13884do_neon_cvt (void)
13885{
13886 do_neon_cvt_1 (TRUE);
13887}
13888
8e79c3df
CM
13889static void
13890do_neon_cvtb (void)
13891{
13892 inst.instruction = 0xeb20a40;
13893
13894 /* The sizes are attached to the mnemonic. */
13895 if (inst.vectype.el[0].type != NT_invtype
13896 && inst.vectype.el[0].size == 16)
13897 inst.instruction |= 0x00010000;
13898
13899 /* Programmer's syntax: the sizes are attached to the operands. */
13900 else if (inst.operands[0].vectype.type != NT_invtype
13901 && inst.operands[0].vectype.size == 16)
13902 inst.instruction |= 0x00010000;
13903
13904 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13905 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13906 do_vfp_cond_or_thumb ();
13907}
13908
13909
13910static void
13911do_neon_cvtt (void)
13912{
13913 do_neon_cvtb ();
13914 inst.instruction |= 0x80;
13915}
13916
5287ad62
JB
13917static void
13918neon_move_immediate (void)
13919{
037e8744
JB
13920 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13921 struct neon_type_el et = neon_check_type (2, rs,
13922 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13923 unsigned immlo, immhi = 0, immbits;
c96612cc 13924 int op, cmode, float_p;
5287ad62 13925
037e8744
JB
13926 constraint (et.type == NT_invtype,
13927 _("operand size must be specified for immediate VMOV"));
13928
5287ad62
JB
13929 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13930 op = (inst.instruction & (1 << 5)) != 0;
13931
13932 immlo = inst.operands[1].imm;
13933 if (inst.operands[1].regisimm)
13934 immhi = inst.operands[1].reg;
13935
13936 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13937 _("immediate has bits set outside the operand size"));
13938
c96612cc
JB
13939 float_p = inst.operands[1].immisfloat;
13940
13941 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13942 et.size, et.type)) == FAIL)
5287ad62
JB
13943 {
13944 /* Invert relevant bits only. */
13945 neon_invert_size (&immlo, &immhi, et.size);
13946 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13947 with one or the other; those cases are caught by
13948 neon_cmode_for_move_imm. */
13949 op = !op;
c96612cc
JB
13950 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13951 &op, et.size, et.type)) == FAIL)
5287ad62 13952 {
dcbf9037 13953 first_error (_("immediate out of range"));
5287ad62
JB
13954 return;
13955 }
13956 }
13957
13958 inst.instruction &= ~(1 << 5);
13959 inst.instruction |= op << 5;
13960
13961 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13962 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13963 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13964 inst.instruction |= cmode << 8;
13965
13966 neon_write_immbits (immbits);
13967}
13968
13969static void
13970do_neon_mvn (void)
13971{
13972 if (inst.operands[1].isreg)
13973 {
037e8744 13974 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13975
88714cb8 13976 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
13977 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13978 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13979 inst.instruction |= LOW4 (inst.operands[1].reg);
13980 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13981 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13982 }
13983 else
13984 {
88714cb8 13985 NEON_ENCODE (IMMED, inst);
5287ad62
JB
13986 neon_move_immediate ();
13987 }
13988
88714cb8 13989 neon_dp_fixup (&inst);
5287ad62
JB
13990}
13991
13992/* Encode instructions of form:
13993
13994 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13995 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13996
13997static void
13998neon_mixed_length (struct neon_type_el et, unsigned size)
13999{
14000 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14001 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14002 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14003 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14004 inst.instruction |= LOW4 (inst.operands[2].reg);
14005 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14006 inst.instruction |= (et.type == NT_unsigned) << 24;
14007 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14008
88714cb8 14009 neon_dp_fixup (&inst);
5287ad62
JB
14010}
14011
14012static void
14013do_neon_dyadic_long (void)
14014{
14015 /* FIXME: Type checking for lengthening op. */
14016 struct neon_type_el et = neon_check_type (3, NS_QDD,
14017 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14018 neon_mixed_length (et, et.size);
14019}
14020
14021static void
14022do_neon_abal (void)
14023{
14024 struct neon_type_el et = neon_check_type (3, NS_QDD,
14025 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14026 neon_mixed_length (et, et.size);
14027}
14028
14029static void
14030neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14031{
14032 if (inst.operands[2].isscalar)
14033 {
dcbf9037
JB
14034 struct neon_type_el et = neon_check_type (3, NS_QDS,
14035 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 14036 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14037 neon_mul_mac (et, et.type == NT_unsigned);
14038 }
14039 else
14040 {
14041 struct neon_type_el et = neon_check_type (3, NS_QDD,
14042 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 14043 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14044 neon_mixed_length (et, et.size);
14045 }
14046}
14047
14048static void
14049do_neon_mac_maybe_scalar_long (void)
14050{
14051 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14052}
14053
14054static void
14055do_neon_dyadic_wide (void)
14056{
14057 struct neon_type_el et = neon_check_type (3, NS_QQD,
14058 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14059 neon_mixed_length (et, et.size);
14060}
14061
14062static void
14063do_neon_dyadic_narrow (void)
14064{
14065 struct neon_type_el et = neon_check_type (3, NS_QDD,
14066 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
14067 /* Operand sign is unimportant, and the U bit is part of the opcode,
14068 so force the operand type to integer. */
14069 et.type = NT_integer;
5287ad62
JB
14070 neon_mixed_length (et, et.size / 2);
14071}
14072
14073static void
14074do_neon_mul_sat_scalar_long (void)
14075{
14076 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14077}
14078
14079static void
14080do_neon_vmull (void)
14081{
14082 if (inst.operands[2].isscalar)
14083 do_neon_mac_maybe_scalar_long ();
14084 else
14085 {
14086 struct neon_type_el et = neon_check_type (3, NS_QDD,
14087 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14088 if (et.type == NT_poly)
88714cb8 14089 NEON_ENCODE (POLY, inst);
5287ad62 14090 else
88714cb8 14091 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14092 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14093 zero. Should be OK as-is. */
14094 neon_mixed_length (et, et.size);
14095 }
14096}
14097
14098static void
14099do_neon_ext (void)
14100{
037e8744 14101 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
14102 struct neon_type_el et = neon_check_type (3, rs,
14103 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14104 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
14105
14106 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14107 _("shift out of range"));
5287ad62
JB
14108 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14109 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14110 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14111 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14112 inst.instruction |= LOW4 (inst.operands[2].reg);
14113 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 14114 inst.instruction |= neon_quad (rs) << 6;
5287ad62 14115 inst.instruction |= imm << 8;
5f4273c7 14116
88714cb8 14117 neon_dp_fixup (&inst);
5287ad62
JB
14118}
14119
14120static void
14121do_neon_rev (void)
14122{
037e8744 14123 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14124 struct neon_type_el et = neon_check_type (2, rs,
14125 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14126 unsigned op = (inst.instruction >> 7) & 3;
14127 /* N (width of reversed regions) is encoded as part of the bitmask. We
14128 extract it here to check the elements to be reversed are smaller.
14129 Otherwise we'd get a reserved instruction. */
14130 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 14131 gas_assert (elsize != 0);
5287ad62
JB
14132 constraint (et.size >= elsize,
14133 _("elements must be smaller than reversal region"));
037e8744 14134 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14135}
14136
14137static void
14138do_neon_dup (void)
14139{
14140 if (inst.operands[1].isscalar)
14141 {
037e8744 14142 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
14143 struct neon_type_el et = neon_check_type (2, rs,
14144 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14145 unsigned sizebits = et.size >> 3;
dcbf9037 14146 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14147 int logsize = neon_logbits (et.size);
dcbf9037 14148 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14149
14150 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14151 return;
14152
88714cb8 14153 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
14154 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14155 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14156 inst.instruction |= LOW4 (dm);
14157 inst.instruction |= HI1 (dm) << 5;
037e8744 14158 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14159 inst.instruction |= x << 17;
14160 inst.instruction |= sizebits << 16;
5f4273c7 14161
88714cb8 14162 neon_dp_fixup (&inst);
5287ad62
JB
14163 }
14164 else
14165 {
037e8744
JB
14166 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14167 struct neon_type_el et = neon_check_type (2, rs,
14168 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 14169 /* Duplicate ARM register to lanes of vector. */
88714cb8 14170 NEON_ENCODE (ARMREG, inst);
5287ad62
JB
14171 switch (et.size)
14172 {
14173 case 8: inst.instruction |= 0x400000; break;
14174 case 16: inst.instruction |= 0x000020; break;
14175 case 32: inst.instruction |= 0x000000; break;
14176 default: break;
14177 }
14178 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14179 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14180 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14181 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14182 /* The encoding for this instruction is identical for the ARM and Thumb
14183 variants, except for the condition field. */
037e8744 14184 do_vfp_cond_or_thumb ();
5287ad62
JB
14185 }
14186}
14187
14188/* VMOV has particularly many variations. It can be one of:
14189 0. VMOV<c><q> <Qd>, <Qm>
14190 1. VMOV<c><q> <Dd>, <Dm>
14191 (Register operations, which are VORR with Rm = Rn.)
14192 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14193 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14194 (Immediate loads.)
14195 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14196 (ARM register to scalar.)
14197 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14198 (Two ARM registers to vector.)
14199 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14200 (Scalar to ARM register.)
14201 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14202 (Vector to two ARM registers.)
037e8744
JB
14203 8. VMOV.F32 <Sd>, <Sm>
14204 9. VMOV.F64 <Dd>, <Dm>
14205 (VFP register moves.)
14206 10. VMOV.F32 <Sd>, #imm
14207 11. VMOV.F64 <Dd>, #imm
14208 (VFP float immediate load.)
14209 12. VMOV <Rd>, <Sm>
14210 (VFP single to ARM reg.)
14211 13. VMOV <Sd>, <Rm>
14212 (ARM reg to VFP single.)
14213 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14214 (Two ARM regs to two VFP singles.)
14215 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14216 (Two VFP singles to two ARM regs.)
5f4273c7 14217
037e8744
JB
14218 These cases can be disambiguated using neon_select_shape, except cases 1/9
14219 and 3/11 which depend on the operand type too.
5f4273c7 14220
5287ad62 14221 All the encoded bits are hardcoded by this function.
5f4273c7 14222
b7fc2769
JB
14223 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14224 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14225
5287ad62 14226 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14227 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14228
14229static void
14230do_neon_mov (void)
14231{
037e8744
JB
14232 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14233 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14234 NS_NULL);
14235 struct neon_type_el et;
14236 const char *ldconst = 0;
5287ad62 14237
037e8744 14238 switch (rs)
5287ad62 14239 {
037e8744
JB
14240 case NS_DD: /* case 1/9. */
14241 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14242 /* It is not an error here if no type is given. */
14243 inst.error = NULL;
14244 if (et.type == NT_float && et.size == 64)
5287ad62 14245 {
037e8744
JB
14246 do_vfp_nsyn_opcode ("fcpyd");
14247 break;
5287ad62 14248 }
037e8744 14249 /* fall through. */
5287ad62 14250
037e8744
JB
14251 case NS_QQ: /* case 0/1. */
14252 {
14253 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14254 return;
14255 /* The architecture manual I have doesn't explicitly state which
14256 value the U bit should have for register->register moves, but
14257 the equivalent VORR instruction has U = 0, so do that. */
14258 inst.instruction = 0x0200110;
14259 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14260 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14261 inst.instruction |= LOW4 (inst.operands[1].reg);
14262 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14263 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14264 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14265 inst.instruction |= neon_quad (rs) << 6;
14266
88714cb8 14267 neon_dp_fixup (&inst);
037e8744
JB
14268 }
14269 break;
5f4273c7 14270
037e8744
JB
14271 case NS_DI: /* case 3/11. */
14272 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14273 inst.error = NULL;
14274 if (et.type == NT_float && et.size == 64)
5287ad62 14275 {
037e8744
JB
14276 /* case 11 (fconstd). */
14277 ldconst = "fconstd";
14278 goto encode_fconstd;
5287ad62 14279 }
037e8744
JB
14280 /* fall through. */
14281
14282 case NS_QI: /* case 2/3. */
14283 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14284 return;
14285 inst.instruction = 0x0800010;
14286 neon_move_immediate ();
88714cb8 14287 neon_dp_fixup (&inst);
5287ad62 14288 break;
5f4273c7 14289
037e8744
JB
14290 case NS_SR: /* case 4. */
14291 {
14292 unsigned bcdebits = 0;
91d6fa6a 14293 int logsize;
037e8744
JB
14294 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14295 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14296
91d6fa6a
NC
14297 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14298 logsize = neon_logbits (et.size);
14299
037e8744
JB
14300 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14301 _(BAD_FPU));
14302 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14303 && et.size != 32, _(BAD_FPU));
14304 constraint (et.type == NT_invtype, _("bad type for scalar"));
14305 constraint (x >= 64 / et.size, _("scalar index out of range"));
14306
14307 switch (et.size)
14308 {
14309 case 8: bcdebits = 0x8; break;
14310 case 16: bcdebits = 0x1; break;
14311 case 32: bcdebits = 0x0; break;
14312 default: ;
14313 }
14314
14315 bcdebits |= x << logsize;
14316
14317 inst.instruction = 0xe000b10;
14318 do_vfp_cond_or_thumb ();
14319 inst.instruction |= LOW4 (dn) << 16;
14320 inst.instruction |= HI1 (dn) << 7;
14321 inst.instruction |= inst.operands[1].reg << 12;
14322 inst.instruction |= (bcdebits & 3) << 5;
14323 inst.instruction |= (bcdebits >> 2) << 21;
14324 }
14325 break;
5f4273c7 14326
037e8744 14327 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14328 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14329 _(BAD_FPU));
b7fc2769 14330
037e8744
JB
14331 inst.instruction = 0xc400b10;
14332 do_vfp_cond_or_thumb ();
14333 inst.instruction |= LOW4 (inst.operands[0].reg);
14334 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14335 inst.instruction |= inst.operands[1].reg << 12;
14336 inst.instruction |= inst.operands[2].reg << 16;
14337 break;
5f4273c7 14338
037e8744
JB
14339 case NS_RS: /* case 6. */
14340 {
91d6fa6a 14341 unsigned logsize;
037e8744
JB
14342 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14343 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14344 unsigned abcdebits = 0;
14345
91d6fa6a
NC
14346 et = neon_check_type (2, NS_NULL,
14347 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14348 logsize = neon_logbits (et.size);
14349
037e8744
JB
14350 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14351 _(BAD_FPU));
14352 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14353 && et.size != 32, _(BAD_FPU));
14354 constraint (et.type == NT_invtype, _("bad type for scalar"));
14355 constraint (x >= 64 / et.size, _("scalar index out of range"));
14356
14357 switch (et.size)
14358 {
14359 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14360 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14361 case 32: abcdebits = 0x00; break;
14362 default: ;
14363 }
14364
14365 abcdebits |= x << logsize;
14366 inst.instruction = 0xe100b10;
14367 do_vfp_cond_or_thumb ();
14368 inst.instruction |= LOW4 (dn) << 16;
14369 inst.instruction |= HI1 (dn) << 7;
14370 inst.instruction |= inst.operands[0].reg << 12;
14371 inst.instruction |= (abcdebits & 3) << 5;
14372 inst.instruction |= (abcdebits >> 2) << 21;
14373 }
14374 break;
5f4273c7 14375
037e8744
JB
14376 case NS_RRD: /* case 7 (fmrrd). */
14377 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14378 _(BAD_FPU));
14379
14380 inst.instruction = 0xc500b10;
14381 do_vfp_cond_or_thumb ();
14382 inst.instruction |= inst.operands[0].reg << 12;
14383 inst.instruction |= inst.operands[1].reg << 16;
14384 inst.instruction |= LOW4 (inst.operands[2].reg);
14385 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14386 break;
5f4273c7 14387
037e8744
JB
14388 case NS_FF: /* case 8 (fcpys). */
14389 do_vfp_nsyn_opcode ("fcpys");
14390 break;
5f4273c7 14391
037e8744
JB
14392 case NS_FI: /* case 10 (fconsts). */
14393 ldconst = "fconsts";
14394 encode_fconstd:
14395 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14396 {
037e8744
JB
14397 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14398 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14399 }
14400 else
037e8744
JB
14401 first_error (_("immediate out of range"));
14402 break;
5f4273c7 14403
037e8744
JB
14404 case NS_RF: /* case 12 (fmrs). */
14405 do_vfp_nsyn_opcode ("fmrs");
14406 break;
5f4273c7 14407
037e8744
JB
14408 case NS_FR: /* case 13 (fmsr). */
14409 do_vfp_nsyn_opcode ("fmsr");
14410 break;
5f4273c7 14411
037e8744
JB
14412 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14413 (one of which is a list), but we have parsed four. Do some fiddling to
14414 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14415 expect. */
14416 case NS_RRFF: /* case 14 (fmrrs). */
14417 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14418 _("VFP registers must be adjacent"));
14419 inst.operands[2].imm = 2;
14420 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14421 do_vfp_nsyn_opcode ("fmrrs");
14422 break;
5f4273c7 14423
037e8744
JB
14424 case NS_FFRR: /* case 15 (fmsrr). */
14425 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14426 _("VFP registers must be adjacent"));
14427 inst.operands[1] = inst.operands[2];
14428 inst.operands[2] = inst.operands[3];
14429 inst.operands[0].imm = 2;
14430 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14431 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14432 break;
5f4273c7 14433
5287ad62
JB
14434 default:
14435 abort ();
14436 }
14437}
14438
14439static void
14440do_neon_rshift_round_imm (void)
14441{
037e8744 14442 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14443 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14444 int imm = inst.operands[2].imm;
14445
14446 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14447 if (imm == 0)
14448 {
14449 inst.operands[2].present = 0;
14450 do_neon_mov ();
14451 return;
14452 }
14453
14454 constraint (imm < 1 || (unsigned)imm > et.size,
14455 _("immediate out of range for shift"));
037e8744 14456 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14457 et.size - imm);
14458}
14459
14460static void
14461do_neon_movl (void)
14462{
14463 struct neon_type_el et = neon_check_type (2, NS_QD,
14464 N_EQK | N_DBL, N_SU_32 | N_KEY);
14465 unsigned sizebits = et.size >> 3;
14466 inst.instruction |= sizebits << 19;
14467 neon_two_same (0, et.type == NT_unsigned, -1);
14468}
14469
14470static void
14471do_neon_trn (void)
14472{
037e8744 14473 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14474 struct neon_type_el et = neon_check_type (2, rs,
14475 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 14476 NEON_ENCODE (INTEGER, inst);
037e8744 14477 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14478}
14479
14480static void
14481do_neon_zip_uzp (void)
14482{
037e8744 14483 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14484 struct neon_type_el et = neon_check_type (2, rs,
14485 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14486 if (rs == NS_DD && et.size == 32)
14487 {
14488 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14489 inst.instruction = N_MNEM_vtrn;
14490 do_neon_trn ();
14491 return;
14492 }
037e8744 14493 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14494}
14495
14496static void
14497do_neon_sat_abs_neg (void)
14498{
037e8744 14499 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14500 struct neon_type_el et = neon_check_type (2, rs,
14501 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14502 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14503}
14504
14505static void
14506do_neon_pair_long (void)
14507{
037e8744 14508 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14509 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14510 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14511 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14512 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14513}
14514
14515static void
14516do_neon_recip_est (void)
14517{
037e8744 14518 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14519 struct neon_type_el et = neon_check_type (2, rs,
14520 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14521 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14522 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14523}
14524
14525static void
14526do_neon_cls (void)
14527{
037e8744 14528 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14529 struct neon_type_el et = neon_check_type (2, rs,
14530 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14531 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14532}
14533
14534static void
14535do_neon_clz (void)
14536{
037e8744 14537 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14538 struct neon_type_el et = neon_check_type (2, rs,
14539 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14540 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14541}
14542
14543static void
14544do_neon_cnt (void)
14545{
037e8744 14546 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14547 struct neon_type_el et = neon_check_type (2, rs,
14548 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14549 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14550}
14551
14552static void
14553do_neon_swp (void)
14554{
037e8744
JB
14555 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14556 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14557}
14558
14559static void
14560do_neon_tbl_tbx (void)
14561{
14562 unsigned listlenbits;
dcbf9037 14563 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14564
5287ad62
JB
14565 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14566 {
dcbf9037 14567 first_error (_("bad list length for table lookup"));
5287ad62
JB
14568 return;
14569 }
5f4273c7 14570
5287ad62
JB
14571 listlenbits = inst.operands[1].imm - 1;
14572 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14573 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14574 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14575 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14576 inst.instruction |= LOW4 (inst.operands[2].reg);
14577 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14578 inst.instruction |= listlenbits << 8;
5f4273c7 14579
88714cb8 14580 neon_dp_fixup (&inst);
5287ad62
JB
14581}
14582
14583static void
14584do_neon_ldm_stm (void)
14585{
14586 /* P, U and L bits are part of bitmask. */
14587 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14588 unsigned offsetbits = inst.operands[1].imm * 2;
14589
037e8744
JB
14590 if (inst.operands[1].issingle)
14591 {
14592 do_vfp_nsyn_ldm_stm (is_dbmode);
14593 return;
14594 }
14595
5287ad62
JB
14596 constraint (is_dbmode && !inst.operands[0].writeback,
14597 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14598
14599 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14600 _("register list must contain at least 1 and at most 16 "
14601 "registers"));
14602
14603 inst.instruction |= inst.operands[0].reg << 16;
14604 inst.instruction |= inst.operands[0].writeback << 21;
14605 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14606 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14607
14608 inst.instruction |= offsetbits;
5f4273c7 14609
037e8744 14610 do_vfp_cond_or_thumb ();
5287ad62
JB
14611}
14612
14613static void
14614do_neon_ldr_str (void)
14615{
5287ad62 14616 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14617
037e8744
JB
14618 if (inst.operands[0].issingle)
14619 {
cd2f129f
JB
14620 if (is_ldr)
14621 do_vfp_nsyn_opcode ("flds");
14622 else
14623 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14624 }
14625 else
5287ad62 14626 {
cd2f129f
JB
14627 if (is_ldr)
14628 do_vfp_nsyn_opcode ("fldd");
5287ad62 14629 else
cd2f129f 14630 do_vfp_nsyn_opcode ("fstd");
5287ad62 14631 }
5287ad62
JB
14632}
14633
14634/* "interleave" version also handles non-interleaving register VLD1/VST1
14635 instructions. */
14636
14637static void
14638do_neon_ld_st_interleave (void)
14639{
037e8744 14640 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14641 N_8 | N_16 | N_32 | N_64);
14642 unsigned alignbits = 0;
14643 unsigned idx;
14644 /* The bits in this table go:
14645 0: register stride of one (0) or two (1)
14646 1,2: register list length, minus one (1, 2, 3, 4).
14647 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14648 We use -1 for invalid entries. */
14649 const int typetable[] =
14650 {
14651 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14652 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14653 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14654 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14655 };
14656 int typebits;
14657
dcbf9037
JB
14658 if (et.type == NT_invtype)
14659 return;
14660
5287ad62
JB
14661 if (inst.operands[1].immisalign)
14662 switch (inst.operands[1].imm >> 8)
14663 {
14664 case 64: alignbits = 1; break;
14665 case 128:
e23c0ad8
JZ
14666 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14667 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14668 goto bad_alignment;
14669 alignbits = 2;
14670 break;
14671 case 256:
e23c0ad8 14672 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
5287ad62
JB
14673 goto bad_alignment;
14674 alignbits = 3;
14675 break;
14676 default:
14677 bad_alignment:
dcbf9037 14678 first_error (_("bad alignment"));
5287ad62
JB
14679 return;
14680 }
14681
14682 inst.instruction |= alignbits << 4;
14683 inst.instruction |= neon_logbits (et.size) << 6;
14684
14685 /* Bits [4:6] of the immediate in a list specifier encode register stride
14686 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14687 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14688 up the right value for "type" in a table based on this value and the given
14689 list style, then stick it back. */
14690 idx = ((inst.operands[0].imm >> 4) & 7)
14691 | (((inst.instruction >> 8) & 3) << 3);
14692
14693 typebits = typetable[idx];
5f4273c7 14694
5287ad62
JB
14695 constraint (typebits == -1, _("bad list type for instruction"));
14696
14697 inst.instruction &= ~0xf00;
14698 inst.instruction |= typebits << 8;
14699}
14700
14701/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14702 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14703 otherwise. The variable arguments are a list of pairs of legal (size, align)
14704 values, terminated with -1. */
14705
14706static int
14707neon_alignment_bit (int size, int align, int *do_align, ...)
14708{
14709 va_list ap;
14710 int result = FAIL, thissize, thisalign;
5f4273c7 14711
5287ad62
JB
14712 if (!inst.operands[1].immisalign)
14713 {
14714 *do_align = 0;
14715 return SUCCESS;
14716 }
5f4273c7 14717
5287ad62
JB
14718 va_start (ap, do_align);
14719
14720 do
14721 {
14722 thissize = va_arg (ap, int);
14723 if (thissize == -1)
14724 break;
14725 thisalign = va_arg (ap, int);
14726
14727 if (size == thissize && align == thisalign)
14728 result = SUCCESS;
14729 }
14730 while (result != SUCCESS);
14731
14732 va_end (ap);
14733
14734 if (result == SUCCESS)
14735 *do_align = 1;
14736 else
dcbf9037 14737 first_error (_("unsupported alignment for instruction"));
5f4273c7 14738
5287ad62
JB
14739 return result;
14740}
14741
14742static void
14743do_neon_ld_st_lane (void)
14744{
037e8744 14745 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14746 int align_good, do_align = 0;
14747 int logsize = neon_logbits (et.size);
14748 int align = inst.operands[1].imm >> 8;
14749 int n = (inst.instruction >> 8) & 3;
14750 int max_el = 64 / et.size;
5f4273c7 14751
dcbf9037
JB
14752 if (et.type == NT_invtype)
14753 return;
5f4273c7 14754
5287ad62
JB
14755 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14756 _("bad list length"));
14757 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14758 _("scalar index out of range"));
14759 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14760 && et.size == 8,
14761 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14762
5287ad62
JB
14763 switch (n)
14764 {
14765 case 0: /* VLD1 / VST1. */
14766 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14767 32, 32, -1);
14768 if (align_good == FAIL)
14769 return;
14770 if (do_align)
14771 {
14772 unsigned alignbits = 0;
14773 switch (et.size)
14774 {
14775 case 16: alignbits = 0x1; break;
14776 case 32: alignbits = 0x3; break;
14777 default: ;
14778 }
14779 inst.instruction |= alignbits << 4;
14780 }
14781 break;
14782
14783 case 1: /* VLD2 / VST2. */
14784 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14785 32, 64, -1);
14786 if (align_good == FAIL)
14787 return;
14788 if (do_align)
14789 inst.instruction |= 1 << 4;
14790 break;
14791
14792 case 2: /* VLD3 / VST3. */
14793 constraint (inst.operands[1].immisalign,
14794 _("can't use alignment with this instruction"));
14795 break;
14796
14797 case 3: /* VLD4 / VST4. */
14798 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14799 16, 64, 32, 64, 32, 128, -1);
14800 if (align_good == FAIL)
14801 return;
14802 if (do_align)
14803 {
14804 unsigned alignbits = 0;
14805 switch (et.size)
14806 {
14807 case 8: alignbits = 0x1; break;
14808 case 16: alignbits = 0x1; break;
14809 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14810 default: ;
14811 }
14812 inst.instruction |= alignbits << 4;
14813 }
14814 break;
14815
14816 default: ;
14817 }
14818
14819 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14820 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14821 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14822
5287ad62
JB
14823 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14824 inst.instruction |= logsize << 10;
14825}
14826
14827/* Encode single n-element structure to all lanes VLD<n> instructions. */
14828
14829static void
14830do_neon_ld_dup (void)
14831{
037e8744 14832 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14833 int align_good, do_align = 0;
14834
dcbf9037
JB
14835 if (et.type == NT_invtype)
14836 return;
14837
5287ad62
JB
14838 switch ((inst.instruction >> 8) & 3)
14839 {
14840 case 0: /* VLD1. */
9c2799c2 14841 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14842 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14843 &do_align, 16, 16, 32, 32, -1);
14844 if (align_good == FAIL)
14845 return;
14846 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14847 {
14848 case 1: break;
14849 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14850 default: first_error (_("bad list length")); return;
5287ad62
JB
14851 }
14852 inst.instruction |= neon_logbits (et.size) << 6;
14853 break;
14854
14855 case 1: /* VLD2. */
14856 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14857 &do_align, 8, 16, 16, 32, 32, 64, -1);
14858 if (align_good == FAIL)
14859 return;
14860 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14861 _("bad list length"));
14862 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14863 inst.instruction |= 1 << 5;
14864 inst.instruction |= neon_logbits (et.size) << 6;
14865 break;
14866
14867 case 2: /* VLD3. */
14868 constraint (inst.operands[1].immisalign,
14869 _("can't use alignment with this instruction"));
14870 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14871 _("bad list length"));
14872 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14873 inst.instruction |= 1 << 5;
14874 inst.instruction |= neon_logbits (et.size) << 6;
14875 break;
14876
14877 case 3: /* VLD4. */
14878 {
14879 int align = inst.operands[1].imm >> 8;
14880 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14881 16, 64, 32, 64, 32, 128, -1);
14882 if (align_good == FAIL)
14883 return;
14884 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14885 _("bad list length"));
14886 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14887 inst.instruction |= 1 << 5;
14888 if (et.size == 32 && align == 128)
14889 inst.instruction |= 0x3 << 6;
14890 else
14891 inst.instruction |= neon_logbits (et.size) << 6;
14892 }
14893 break;
14894
14895 default: ;
14896 }
14897
14898 inst.instruction |= do_align << 4;
14899}
14900
14901/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14902 apart from bits [11:4]. */
14903
14904static void
14905do_neon_ldx_stx (void)
14906{
b1a769ed
DG
14907 if (inst.operands[1].isreg)
14908 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14909
5287ad62
JB
14910 switch (NEON_LANE (inst.operands[0].imm))
14911 {
14912 case NEON_INTERLEAVE_LANES:
88714cb8 14913 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
14914 do_neon_ld_st_interleave ();
14915 break;
5f4273c7 14916
5287ad62 14917 case NEON_ALL_LANES:
88714cb8 14918 NEON_ENCODE (DUP, inst);
5287ad62
JB
14919 do_neon_ld_dup ();
14920 break;
5f4273c7 14921
5287ad62 14922 default:
88714cb8 14923 NEON_ENCODE (LANE, inst);
5287ad62
JB
14924 do_neon_ld_st_lane ();
14925 }
14926
14927 /* L bit comes from bit mask. */
14928 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14929 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14930 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14931
5287ad62
JB
14932 if (inst.operands[1].postind)
14933 {
14934 int postreg = inst.operands[1].imm & 0xf;
14935 constraint (!inst.operands[1].immisreg,
14936 _("post-index must be a register"));
14937 constraint (postreg == 0xd || postreg == 0xf,
14938 _("bad register for post-index"));
14939 inst.instruction |= postreg;
14940 }
14941 else if (inst.operands[1].writeback)
14942 {
14943 inst.instruction |= 0xd;
14944 }
14945 else
5f4273c7
NC
14946 inst.instruction |= 0xf;
14947
5287ad62
JB
14948 if (thumb_mode)
14949 inst.instruction |= 0xf9000000;
14950 else
14951 inst.instruction |= 0xf4000000;
14952}
5287ad62
JB
14953\f
14954/* Overall per-instruction processing. */
14955
14956/* We need to be able to fix up arbitrary expressions in some statements.
14957 This is so that we can handle symbols that are an arbitrary distance from
14958 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14959 which returns part of an address in a form which will be valid for
14960 a data instruction. We do this by pushing the expression into a symbol
14961 in the expr_section, and creating a fix for that. */
14962
14963static void
14964fix_new_arm (fragS * frag,
14965 int where,
14966 short int size,
14967 expressionS * exp,
14968 int pc_rel,
14969 int reloc)
14970{
14971 fixS * new_fix;
14972
14973 switch (exp->X_op)
14974 {
14975 case O_constant:
14976 case O_symbol:
14977 case O_add:
14978 case O_subtract:
21d799b5
NC
14979 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14980 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14981 break;
14982
14983 default:
21d799b5
NC
14984 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14985 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14986 break;
14987 }
14988
14989 /* Mark whether the fix is to a THUMB instruction, or an ARM
14990 instruction. */
14991 new_fix->tc_fix_data = thumb_mode;
14992}
14993
14994/* Create a frg for an instruction requiring relaxation. */
14995static void
14996output_relax_insn (void)
14997{
14998 char * to;
14999 symbolS *sym;
0110f2b8
PB
15000 int offset;
15001
6e1cb1a6
PB
15002 /* The size of the instruction is unknown, so tie the debug info to the
15003 start of the instruction. */
15004 dwarf2_emit_insn (0);
6e1cb1a6 15005
0110f2b8
PB
15006 switch (inst.reloc.exp.X_op)
15007 {
15008 case O_symbol:
15009 sym = inst.reloc.exp.X_add_symbol;
15010 offset = inst.reloc.exp.X_add_number;
15011 break;
15012 case O_constant:
15013 sym = NULL;
15014 offset = inst.reloc.exp.X_add_number;
15015 break;
15016 default:
15017 sym = make_expr_symbol (&inst.reloc.exp);
15018 offset = 0;
15019 break;
15020 }
15021 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15022 inst.relax, sym, offset, NULL/*offset, opcode*/);
15023 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
15024}
15025
15026/* Write a 32-bit thumb instruction to buf. */
15027static void
15028put_thumb32_insn (char * buf, unsigned long insn)
15029{
15030 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15031 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15032}
15033
b99bd4ef 15034static void
c19d1205 15035output_inst (const char * str)
b99bd4ef 15036{
c19d1205 15037 char * to = NULL;
b99bd4ef 15038
c19d1205 15039 if (inst.error)
b99bd4ef 15040 {
c19d1205 15041 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
15042 return;
15043 }
5f4273c7
NC
15044 if (inst.relax)
15045 {
15046 output_relax_insn ();
0110f2b8 15047 return;
5f4273c7 15048 }
c19d1205
ZW
15049 if (inst.size == 0)
15050 return;
b99bd4ef 15051
c19d1205 15052 to = frag_more (inst.size);
8dc2430f
NC
15053 /* PR 9814: Record the thumb mode into the current frag so that we know
15054 what type of NOP padding to use, if necessary. We override any previous
15055 setting so that if the mode has changed then the NOPS that we use will
15056 match the encoding of the last instruction in the frag. */
cd000bff 15057 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
15058
15059 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 15060 {
9c2799c2 15061 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 15062 put_thumb32_insn (to, inst.instruction);
b99bd4ef 15063 }
c19d1205 15064 else if (inst.size > INSN_SIZE)
b99bd4ef 15065 {
9c2799c2 15066 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
15067 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15068 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 15069 }
c19d1205
ZW
15070 else
15071 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 15072
c19d1205
ZW
15073 if (inst.reloc.type != BFD_RELOC_UNUSED)
15074 fix_new_arm (frag_now, to - frag_now->fr_literal,
15075 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15076 inst.reloc.type);
b99bd4ef 15077
c19d1205 15078 dwarf2_emit_insn (inst.size);
c19d1205 15079}
b99bd4ef 15080
e07e6e58
NC
15081static char *
15082output_it_inst (int cond, int mask, char * to)
15083{
15084 unsigned long instruction = 0xbf00;
15085
15086 mask &= 0xf;
15087 instruction |= mask;
15088 instruction |= cond << 4;
15089
15090 if (to == NULL)
15091 {
15092 to = frag_more (2);
15093#ifdef OBJ_ELF
15094 dwarf2_emit_insn (2);
15095#endif
15096 }
15097
15098 md_number_to_chars (to, instruction, 2);
15099
15100 return to;
15101}
15102
c19d1205
ZW
15103/* Tag values used in struct asm_opcode's tag field. */
15104enum opcode_tag
15105{
15106 OT_unconditional, /* Instruction cannot be conditionalized.
15107 The ARM condition field is still 0xE. */
15108 OT_unconditionalF, /* Instruction cannot be conditionalized
15109 and carries 0xF in its ARM condition field. */
15110 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
15111 OT_csuffixF, /* Some forms of the instruction take a conditional
15112 suffix, others place 0xF where the condition field
15113 would be. */
c19d1205
ZW
15114 OT_cinfix3, /* Instruction takes a conditional infix,
15115 beginning at character index 3. (In
15116 unified mode, it becomes a suffix.) */
088fa78e
KH
15117 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15118 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
15119 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15120 character index 3, even in unified mode. Used for
15121 legacy instructions where suffix and infix forms
15122 may be ambiguous. */
c19d1205 15123 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 15124 suffix or an infix at character index 3. */
c19d1205
ZW
15125 OT_odd_infix_unc, /* This is the unconditional variant of an
15126 instruction that takes a conditional infix
15127 at an unusual position. In unified mode,
15128 this variant will accept a suffix. */
15129 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15130 are the conditional variants of instructions that
15131 take conditional infixes in unusual positions.
15132 The infix appears at character index
15133 (tag - OT_odd_infix_0). These are not accepted
15134 in unified mode. */
15135};
b99bd4ef 15136
c19d1205
ZW
15137/* Subroutine of md_assemble, responsible for looking up the primary
15138 opcode from the mnemonic the user wrote. STR points to the
15139 beginning of the mnemonic.
15140
15141 This is not simply a hash table lookup, because of conditional
15142 variants. Most instructions have conditional variants, which are
15143 expressed with a _conditional affix_ to the mnemonic. If we were
15144 to encode each conditional variant as a literal string in the opcode
15145 table, it would have approximately 20,000 entries.
15146
15147 Most mnemonics take this affix as a suffix, and in unified syntax,
15148 'most' is upgraded to 'all'. However, in the divided syntax, some
15149 instructions take the affix as an infix, notably the s-variants of
15150 the arithmetic instructions. Of those instructions, all but six
15151 have the infix appear after the third character of the mnemonic.
15152
15153 Accordingly, the algorithm for looking up primary opcodes given
15154 an identifier is:
15155
15156 1. Look up the identifier in the opcode table.
15157 If we find a match, go to step U.
15158
15159 2. Look up the last two characters of the identifier in the
15160 conditions table. If we find a match, look up the first N-2
15161 characters of the identifier in the opcode table. If we
15162 find a match, go to step CE.
15163
15164 3. Look up the fourth and fifth characters of the identifier in
15165 the conditions table. If we find a match, extract those
15166 characters from the identifier, and look up the remaining
15167 characters in the opcode table. If we find a match, go
15168 to step CM.
15169
15170 4. Fail.
15171
15172 U. Examine the tag field of the opcode structure, in case this is
15173 one of the six instructions with its conditional infix in an
15174 unusual place. If it is, the tag tells us where to find the
15175 infix; look it up in the conditions table and set inst.cond
15176 accordingly. Otherwise, this is an unconditional instruction.
15177 Again set inst.cond accordingly. Return the opcode structure.
15178
15179 CE. Examine the tag field to make sure this is an instruction that
15180 should receive a conditional suffix. If it is not, fail.
15181 Otherwise, set inst.cond from the suffix we already looked up,
15182 and return the opcode structure.
15183
15184 CM. Examine the tag field to make sure this is an instruction that
15185 should receive a conditional infix after the third character.
15186 If it is not, fail. Otherwise, undo the edits to the current
15187 line of input and proceed as for case CE. */
15188
15189static const struct asm_opcode *
15190opcode_lookup (char **str)
15191{
15192 char *end, *base;
15193 char *affix;
15194 const struct asm_opcode *opcode;
15195 const struct asm_cond *cond;
e3cb604e 15196 char save[2];
c19d1205
ZW
15197
15198 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15199 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15200 for (base = end = *str; *end != '\0'; end++)
721a8186 15201 if (*end == ' ' || *end == '.')
c19d1205 15202 break;
b99bd4ef 15203
c19d1205 15204 if (end == base)
c921be7d 15205 return NULL;
b99bd4ef 15206
5287ad62 15207 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15208 if (end[0] == '.')
b99bd4ef 15209 {
5287ad62 15210 int offset = 2;
5f4273c7 15211
267d2029
JB
15212 /* The .w and .n suffixes are only valid if the unified syntax is in
15213 use. */
15214 if (unified_syntax && end[1] == 'w')
c19d1205 15215 inst.size_req = 4;
267d2029 15216 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15217 inst.size_req = 2;
15218 else
5287ad62
JB
15219 offset = 0;
15220
15221 inst.vectype.elems = 0;
15222
15223 *str = end + offset;
b99bd4ef 15224
5f4273c7 15225 if (end[offset] == '.')
5287ad62 15226 {
267d2029
JB
15227 /* See if we have a Neon type suffix (possible in either unified or
15228 non-unified ARM syntax mode). */
dcbf9037 15229 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15230 return NULL;
5287ad62
JB
15231 }
15232 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15233 return NULL;
b99bd4ef 15234 }
c19d1205
ZW
15235 else
15236 *str = end;
b99bd4ef 15237
c19d1205 15238 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15239 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15240 end - base);
c19d1205 15241 if (opcode)
b99bd4ef 15242 {
c19d1205
ZW
15243 /* step U */
15244 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15245 {
c19d1205
ZW
15246 inst.cond = COND_ALWAYS;
15247 return opcode;
b99bd4ef 15248 }
b99bd4ef 15249
278df34e 15250 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15251 as_warn (_("conditional infixes are deprecated in unified syntax"));
15252 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15253 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15254 gas_assert (cond);
b99bd4ef 15255
c19d1205
ZW
15256 inst.cond = cond->value;
15257 return opcode;
15258 }
b99bd4ef 15259
c19d1205
ZW
15260 /* Cannot have a conditional suffix on a mnemonic of less than two
15261 characters. */
15262 if (end - base < 3)
c921be7d 15263 return NULL;
b99bd4ef 15264
c19d1205
ZW
15265 /* Look for suffixed mnemonic. */
15266 affix = end - 2;
21d799b5
NC
15267 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15268 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15269 affix - base);
c19d1205
ZW
15270 if (opcode && cond)
15271 {
15272 /* step CE */
15273 switch (opcode->tag)
15274 {
e3cb604e
PB
15275 case OT_cinfix3_legacy:
15276 /* Ignore conditional suffixes matched on infix only mnemonics. */
15277 break;
15278
c19d1205 15279 case OT_cinfix3:
088fa78e 15280 case OT_cinfix3_deprecated:
c19d1205
ZW
15281 case OT_odd_infix_unc:
15282 if (!unified_syntax)
e3cb604e 15283 return 0;
c19d1205
ZW
15284 /* else fall through */
15285
15286 case OT_csuffix:
037e8744 15287 case OT_csuffixF:
c19d1205
ZW
15288 case OT_csuf_or_in3:
15289 inst.cond = cond->value;
15290 return opcode;
15291
15292 case OT_unconditional:
15293 case OT_unconditionalF:
dfa9f0d5 15294 if (thumb_mode)
c921be7d 15295 inst.cond = cond->value;
dfa9f0d5
PB
15296 else
15297 {
c921be7d 15298 /* Delayed diagnostic. */
dfa9f0d5
PB
15299 inst.error = BAD_COND;
15300 inst.cond = COND_ALWAYS;
15301 }
c19d1205 15302 return opcode;
b99bd4ef 15303
c19d1205 15304 default:
c921be7d 15305 return NULL;
c19d1205
ZW
15306 }
15307 }
b99bd4ef 15308
c19d1205
ZW
15309 /* Cannot have a usual-position infix on a mnemonic of less than
15310 six characters (five would be a suffix). */
15311 if (end - base < 6)
c921be7d 15312 return NULL;
b99bd4ef 15313
c19d1205
ZW
15314 /* Look for infixed mnemonic in the usual position. */
15315 affix = base + 3;
21d799b5 15316 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15317 if (!cond)
c921be7d 15318 return NULL;
e3cb604e
PB
15319
15320 memcpy (save, affix, 2);
15321 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15322 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15323 (end - base) - 2);
e3cb604e
PB
15324 memmove (affix + 2, affix, (end - affix) - 2);
15325 memcpy (affix, save, 2);
15326
088fa78e
KH
15327 if (opcode
15328 && (opcode->tag == OT_cinfix3
15329 || opcode->tag == OT_cinfix3_deprecated
15330 || opcode->tag == OT_csuf_or_in3
15331 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15332 {
c921be7d 15333 /* Step CM. */
278df34e 15334 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15335 && (opcode->tag == OT_cinfix3
15336 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15337 as_warn (_("conditional infixes are deprecated in unified syntax"));
15338
15339 inst.cond = cond->value;
15340 return opcode;
b99bd4ef
NC
15341 }
15342
c921be7d 15343 return NULL;
b99bd4ef
NC
15344}
15345
e07e6e58
NC
15346/* This function generates an initial IT instruction, leaving its block
15347 virtually open for the new instructions. Eventually,
15348 the mask will be updated by now_it_add_mask () each time
15349 a new instruction needs to be included in the IT block.
15350 Finally, the block is closed with close_automatic_it_block ().
15351 The block closure can be requested either from md_assemble (),
15352 a tencode (), or due to a label hook. */
15353
15354static void
15355new_automatic_it_block (int cond)
15356{
15357 now_it.state = AUTOMATIC_IT_BLOCK;
15358 now_it.mask = 0x18;
15359 now_it.cc = cond;
15360 now_it.block_length = 1;
cd000bff 15361 mapping_state (MAP_THUMB);
e07e6e58
NC
15362 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15363}
15364
15365/* Close an automatic IT block.
15366 See comments in new_automatic_it_block (). */
15367
15368static void
15369close_automatic_it_block (void)
15370{
15371 now_it.mask = 0x10;
15372 now_it.block_length = 0;
15373}
15374
15375/* Update the mask of the current automatically-generated IT
15376 instruction. See comments in new_automatic_it_block (). */
15377
15378static void
15379now_it_add_mask (int cond)
15380{
15381#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15382#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15383 | ((bitvalue) << (nbit)))
e07e6e58 15384 const int resulting_bit = (cond & 1);
c921be7d 15385
e07e6e58
NC
15386 now_it.mask &= 0xf;
15387 now_it.mask = SET_BIT_VALUE (now_it.mask,
15388 resulting_bit,
15389 (5 - now_it.block_length));
15390 now_it.mask = SET_BIT_VALUE (now_it.mask,
15391 1,
15392 ((5 - now_it.block_length) - 1) );
15393 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15394
15395#undef CLEAR_BIT
15396#undef SET_BIT_VALUE
e07e6e58
NC
15397}
15398
15399/* The IT blocks handling machinery is accessed through the these functions:
15400 it_fsm_pre_encode () from md_assemble ()
15401 set_it_insn_type () optional, from the tencode functions
15402 set_it_insn_type_last () ditto
15403 in_it_block () ditto
15404 it_fsm_post_encode () from md_assemble ()
15405 force_automatic_it_block_close () from label habdling functions
15406
15407 Rationale:
15408 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15409 initializing the IT insn type with a generic initial value depending
15410 on the inst.condition.
15411 2) During the tencode function, two things may happen:
15412 a) The tencode function overrides the IT insn type by
15413 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15414 b) The tencode function queries the IT block state by
15415 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15416
15417 Both set_it_insn_type and in_it_block run the internal FSM state
15418 handling function (handle_it_state), because: a) setting the IT insn
15419 type may incur in an invalid state (exiting the function),
15420 and b) querying the state requires the FSM to be updated.
15421 Specifically we want to avoid creating an IT block for conditional
15422 branches, so it_fsm_pre_encode is actually a guess and we can't
15423 determine whether an IT block is required until the tencode () routine
15424 has decided what type of instruction this actually it.
15425 Because of this, if set_it_insn_type and in_it_block have to be used,
15426 set_it_insn_type has to be called first.
15427
15428 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15429 determines the insn IT type depending on the inst.cond code.
15430 When a tencode () routine encodes an instruction that can be
15431 either outside an IT block, or, in the case of being inside, has to be
15432 the last one, set_it_insn_type_last () will determine the proper
15433 IT instruction type based on the inst.cond code. Otherwise,
15434 set_it_insn_type can be called for overriding that logic or
15435 for covering other cases.
15436
15437 Calling handle_it_state () may not transition the IT block state to
15438 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15439 still queried. Instead, if the FSM determines that the state should
15440 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15441 after the tencode () function: that's what it_fsm_post_encode () does.
15442
15443 Since in_it_block () calls the state handling function to get an
15444 updated state, an error may occur (due to invalid insns combination).
15445 In that case, inst.error is set.
15446 Therefore, inst.error has to be checked after the execution of
15447 the tencode () routine.
15448
15449 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15450 any pending state change (if any) that didn't take place in
15451 handle_it_state () as explained above. */
15452
15453static void
15454it_fsm_pre_encode (void)
15455{
15456 if (inst.cond != COND_ALWAYS)
15457 inst.it_insn_type = INSIDE_IT_INSN;
15458 else
15459 inst.it_insn_type = OUTSIDE_IT_INSN;
15460
15461 now_it.state_handled = 0;
15462}
15463
15464/* IT state FSM handling function. */
15465
15466static int
15467handle_it_state (void)
15468{
15469 now_it.state_handled = 1;
15470
15471 switch (now_it.state)
15472 {
15473 case OUTSIDE_IT_BLOCK:
15474 switch (inst.it_insn_type)
15475 {
15476 case OUTSIDE_IT_INSN:
15477 break;
15478
15479 case INSIDE_IT_INSN:
15480 case INSIDE_IT_LAST_INSN:
15481 if (thumb_mode == 0)
15482 {
c921be7d 15483 if (unified_syntax
e07e6e58
NC
15484 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15485 as_tsktsk (_("Warning: conditional outside an IT block"\
15486 " for Thumb."));
15487 }
15488 else
15489 {
15490 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15491 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15492 {
15493 /* Automatically generate the IT instruction. */
15494 new_automatic_it_block (inst.cond);
15495 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15496 close_automatic_it_block ();
15497 }
15498 else
15499 {
15500 inst.error = BAD_OUT_IT;
15501 return FAIL;
15502 }
15503 }
15504 break;
15505
15506 case IF_INSIDE_IT_LAST_INSN:
15507 case NEUTRAL_IT_INSN:
15508 break;
15509
15510 case IT_INSN:
15511 now_it.state = MANUAL_IT_BLOCK;
15512 now_it.block_length = 0;
15513 break;
15514 }
15515 break;
15516
15517 case AUTOMATIC_IT_BLOCK:
15518 /* Three things may happen now:
15519 a) We should increment current it block size;
15520 b) We should close current it block (closing insn or 4 insns);
15521 c) We should close current it block and start a new one (due
15522 to incompatible conditions or
15523 4 insns-length block reached). */
15524
15525 switch (inst.it_insn_type)
15526 {
15527 case OUTSIDE_IT_INSN:
15528 /* The closure of the block shall happen immediatelly,
15529 so any in_it_block () call reports the block as closed. */
15530 force_automatic_it_block_close ();
15531 break;
15532
15533 case INSIDE_IT_INSN:
15534 case INSIDE_IT_LAST_INSN:
15535 case IF_INSIDE_IT_LAST_INSN:
15536 now_it.block_length++;
15537
15538 if (now_it.block_length > 4
15539 || !now_it_compatible (inst.cond))
15540 {
15541 force_automatic_it_block_close ();
15542 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15543 new_automatic_it_block (inst.cond);
15544 }
15545 else
15546 {
15547 now_it_add_mask (inst.cond);
15548 }
15549
15550 if (now_it.state == AUTOMATIC_IT_BLOCK
15551 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15552 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15553 close_automatic_it_block ();
15554 break;
15555
15556 case NEUTRAL_IT_INSN:
15557 now_it.block_length++;
15558
15559 if (now_it.block_length > 4)
15560 force_automatic_it_block_close ();
15561 else
15562 now_it_add_mask (now_it.cc & 1);
15563 break;
15564
15565 case IT_INSN:
15566 close_automatic_it_block ();
15567 now_it.state = MANUAL_IT_BLOCK;
15568 break;
15569 }
15570 break;
15571
15572 case MANUAL_IT_BLOCK:
15573 {
15574 /* Check conditional suffixes. */
15575 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15576 int is_last;
15577 now_it.mask <<= 1;
15578 now_it.mask &= 0x1f;
15579 is_last = (now_it.mask == 0x10);
15580
15581 switch (inst.it_insn_type)
15582 {
15583 case OUTSIDE_IT_INSN:
15584 inst.error = BAD_NOT_IT;
15585 return FAIL;
15586
15587 case INSIDE_IT_INSN:
15588 if (cond != inst.cond)
15589 {
15590 inst.error = BAD_IT_COND;
15591 return FAIL;
15592 }
15593 break;
15594
15595 case INSIDE_IT_LAST_INSN:
15596 case IF_INSIDE_IT_LAST_INSN:
15597 if (cond != inst.cond)
15598 {
15599 inst.error = BAD_IT_COND;
15600 return FAIL;
15601 }
15602 if (!is_last)
15603 {
15604 inst.error = BAD_BRANCH;
15605 return FAIL;
15606 }
15607 break;
15608
15609 case NEUTRAL_IT_INSN:
15610 /* The BKPT instruction is unconditional even in an IT block. */
15611 break;
15612
15613 case IT_INSN:
15614 inst.error = BAD_IT_IT;
15615 return FAIL;
15616 }
15617 }
15618 break;
15619 }
15620
15621 return SUCCESS;
15622}
15623
15624static void
15625it_fsm_post_encode (void)
15626{
15627 int is_last;
15628
15629 if (!now_it.state_handled)
15630 handle_it_state ();
15631
15632 is_last = (now_it.mask == 0x10);
15633 if (is_last)
15634 {
15635 now_it.state = OUTSIDE_IT_BLOCK;
15636 now_it.mask = 0;
15637 }
15638}
15639
15640static void
15641force_automatic_it_block_close (void)
15642{
15643 if (now_it.state == AUTOMATIC_IT_BLOCK)
15644 {
15645 close_automatic_it_block ();
15646 now_it.state = OUTSIDE_IT_BLOCK;
15647 now_it.mask = 0;
15648 }
15649}
15650
15651static int
15652in_it_block (void)
15653{
15654 if (!now_it.state_handled)
15655 handle_it_state ();
15656
15657 return now_it.state != OUTSIDE_IT_BLOCK;
15658}
15659
c19d1205
ZW
15660void
15661md_assemble (char *str)
b99bd4ef 15662{
c19d1205
ZW
15663 char *p = str;
15664 const struct asm_opcode * opcode;
b99bd4ef 15665
c19d1205
ZW
15666 /* Align the previous label if needed. */
15667 if (last_label_seen != NULL)
b99bd4ef 15668 {
c19d1205
ZW
15669 symbol_set_frag (last_label_seen, frag_now);
15670 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15671 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15672 }
15673
c19d1205
ZW
15674 memset (&inst, '\0', sizeof (inst));
15675 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15676
c19d1205
ZW
15677 opcode = opcode_lookup (&p);
15678 if (!opcode)
b99bd4ef 15679 {
c19d1205 15680 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15681 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15682 if (! create_register_alias (str, p)
15683 && ! create_neon_reg_alias (str, p))
c19d1205 15684 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15685
b99bd4ef
NC
15686 return;
15687 }
15688
278df34e 15689 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15690 as_warn (_("s suffix on comparison instruction is deprecated"));
15691
037e8744
JB
15692 /* The value which unconditional instructions should have in place of the
15693 condition field. */
15694 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15695
c19d1205 15696 if (thumb_mode)
b99bd4ef 15697 {
e74cfd16 15698 arm_feature_set variant;
8f06b2d8
PB
15699
15700 variant = cpu_variant;
15701 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15702 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15703 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15704 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15705 if (!opcode->tvariant
15706 || (thumb_mode == 1
15707 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15708 {
c19d1205 15709 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
15710 return;
15711 }
c19d1205
ZW
15712 if (inst.cond != COND_ALWAYS && !unified_syntax
15713 && opcode->tencode != do_t_branch)
b99bd4ef 15714 {
c19d1205 15715 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15716 return;
15717 }
15718
752d5da4 15719 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15720 {
7e806470 15721 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15722 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15723 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15724 {
15725 /* Two things are addressed here.
15726 1) Implicit require narrow instructions on Thumb-1.
15727 This avoids relaxation accidentally introducing Thumb-2
15728 instructions.
15729 2) Reject wide instructions in non Thumb-2 cores. */
15730 if (inst.size_req == 0)
15731 inst.size_req = 2;
15732 else if (inst.size_req == 4)
15733 {
15734 as_bad (_("selected processor does not support `%s'"), str);
15735 return;
15736 }
15737 }
076d447c
PB
15738 }
15739
c19d1205
ZW
15740 inst.instruction = opcode->tvalue;
15741
5be8be5d 15742 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
e07e6e58
NC
15743 {
15744 /* Prepare the it_insn_type for those encodings that don't set
15745 it. */
15746 it_fsm_pre_encode ();
c19d1205 15747
e07e6e58
NC
15748 opcode->tencode ();
15749
15750 it_fsm_post_encode ();
15751 }
e27ec89e 15752
0110f2b8 15753 if (!(inst.error || inst.relax))
b99bd4ef 15754 {
9c2799c2 15755 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15756 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15757 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15758 {
c19d1205 15759 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15760 return;
15761 }
15762 }
076d447c
PB
15763
15764 /* Something has gone badly wrong if we try to relax a fixed size
15765 instruction. */
9c2799c2 15766 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15767
e74cfd16
PB
15768 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15769 *opcode->tvariant);
ee065d83 15770 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15771 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15772 anything other than bl/blx and v6-M instructions.
ee065d83 15773 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15774 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15775 || inst.relax)
e07e6e58
NC
15776 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15777 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15778 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15779 arm_ext_v6t2);
cd000bff 15780
88714cb8
DG
15781 check_neon_suffixes;
15782
cd000bff 15783 if (!inst.error)
c877a2f2
NC
15784 {
15785 mapping_state (MAP_THUMB);
15786 }
c19d1205 15787 }
3e9e4fcf 15788 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15789 {
845b51d6
PB
15790 bfd_boolean is_bx;
15791
15792 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15793 is_bx = (opcode->aencode == do_bx);
15794
c19d1205 15795 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15796 if (!(is_bx && fix_v4bx)
15797 && !(opcode->avariant &&
15798 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15799 {
c19d1205
ZW
15800 as_bad (_("selected processor does not support `%s'"), str);
15801 return;
b99bd4ef 15802 }
c19d1205 15803 if (inst.size_req)
b99bd4ef 15804 {
c19d1205
ZW
15805 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15806 return;
b99bd4ef
NC
15807 }
15808
c19d1205
ZW
15809 inst.instruction = opcode->avalue;
15810 if (opcode->tag == OT_unconditionalF)
15811 inst.instruction |= 0xF << 28;
15812 else
15813 inst.instruction |= inst.cond << 28;
15814 inst.size = INSN_SIZE;
5be8be5d 15815 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
e07e6e58
NC
15816 {
15817 it_fsm_pre_encode ();
15818 opcode->aencode ();
15819 it_fsm_post_encode ();
15820 }
ee065d83
PB
15821 /* Arm mode bx is marked as both v4T and v5 because it's still required
15822 on a hypothetical non-thumb v5 core. */
845b51d6 15823 if (is_bx)
e74cfd16 15824 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15825 else
e74cfd16
PB
15826 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15827 *opcode->avariant);
88714cb8
DG
15828
15829 check_neon_suffixes;
15830
cd000bff 15831 if (!inst.error)
c877a2f2
NC
15832 {
15833 mapping_state (MAP_ARM);
15834 }
b99bd4ef 15835 }
3e9e4fcf
JB
15836 else
15837 {
15838 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15839 "-- `%s'"), str);
15840 return;
15841 }
c19d1205
ZW
15842 output_inst (str);
15843}
b99bd4ef 15844
e07e6e58
NC
15845static void
15846check_it_blocks_finished (void)
15847{
15848#ifdef OBJ_ELF
15849 asection *sect;
15850
15851 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15852 if (seg_info (sect)->tc_segment_info_data.current_it.state
15853 == MANUAL_IT_BLOCK)
15854 {
15855 as_warn (_("section '%s' finished with an open IT block."),
15856 sect->name);
15857 }
15858#else
15859 if (now_it.state == MANUAL_IT_BLOCK)
15860 as_warn (_("file finished with an open IT block."));
15861#endif
15862}
15863
c19d1205
ZW
15864/* Various frobbings of labels and their addresses. */
15865
15866void
15867arm_start_line_hook (void)
15868{
15869 last_label_seen = NULL;
b99bd4ef
NC
15870}
15871
c19d1205
ZW
15872void
15873arm_frob_label (symbolS * sym)
b99bd4ef 15874{
c19d1205 15875 last_label_seen = sym;
b99bd4ef 15876
c19d1205 15877 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15878
c19d1205
ZW
15879#if defined OBJ_COFF || defined OBJ_ELF
15880 ARM_SET_INTERWORK (sym, support_interwork);
15881#endif
b99bd4ef 15882
e07e6e58
NC
15883 force_automatic_it_block_close ();
15884
5f4273c7 15885 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15886 as Thumb functions. This is because these labels, whilst
15887 they exist inside Thumb code, are not the entry points for
15888 possible ARM->Thumb calls. Also, these labels can be used
15889 as part of a computed goto or switch statement. eg gcc
15890 can generate code that looks like this:
b99bd4ef 15891
c19d1205
ZW
15892 ldr r2, [pc, .Laaa]
15893 lsl r3, r3, #2
15894 ldr r2, [r3, r2]
15895 mov pc, r2
b99bd4ef 15896
c19d1205
ZW
15897 .Lbbb: .word .Lxxx
15898 .Lccc: .word .Lyyy
15899 ..etc...
15900 .Laaa: .word Lbbb
b99bd4ef 15901
c19d1205
ZW
15902 The first instruction loads the address of the jump table.
15903 The second instruction converts a table index into a byte offset.
15904 The third instruction gets the jump address out of the table.
15905 The fourth instruction performs the jump.
b99bd4ef 15906
c19d1205
ZW
15907 If the address stored at .Laaa is that of a symbol which has the
15908 Thumb_Func bit set, then the linker will arrange for this address
15909 to have the bottom bit set, which in turn would mean that the
15910 address computation performed by the third instruction would end
15911 up with the bottom bit set. Since the ARM is capable of unaligned
15912 word loads, the instruction would then load the incorrect address
15913 out of the jump table, and chaos would ensue. */
15914 if (label_is_thumb_function_name
15915 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15916 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15917 {
c19d1205
ZW
15918 /* When the address of a Thumb function is taken the bottom
15919 bit of that address should be set. This will allow
15920 interworking between Arm and Thumb functions to work
15921 correctly. */
b99bd4ef 15922
c19d1205 15923 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15924
c19d1205 15925 label_is_thumb_function_name = FALSE;
b99bd4ef 15926 }
07a53e5c 15927
07a53e5c 15928 dwarf2_emit_label (sym);
b99bd4ef
NC
15929}
15930
c921be7d 15931bfd_boolean
c19d1205 15932arm_data_in_code (void)
b99bd4ef 15933{
c19d1205 15934 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15935 {
c19d1205
ZW
15936 *input_line_pointer = '/';
15937 input_line_pointer += 5;
15938 *input_line_pointer = 0;
c921be7d 15939 return TRUE;
b99bd4ef
NC
15940 }
15941
c921be7d 15942 return FALSE;
b99bd4ef
NC
15943}
15944
c19d1205
ZW
15945char *
15946arm_canonicalize_symbol_name (char * name)
b99bd4ef 15947{
c19d1205 15948 int len;
b99bd4ef 15949
c19d1205
ZW
15950 if (thumb_mode && (len = strlen (name)) > 5
15951 && streq (name + len - 5, "/data"))
15952 *(name + len - 5) = 0;
b99bd4ef 15953
c19d1205 15954 return name;
b99bd4ef 15955}
c19d1205
ZW
15956\f
15957/* Table of all register names defined by default. The user can
15958 define additional names with .req. Note that all register names
15959 should appear in both upper and lowercase variants. Some registers
15960 also have mixed-case names. */
b99bd4ef 15961
dcbf9037 15962#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15963#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15964#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15965#define REGSET(p,t) \
15966 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15967 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15968 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15969 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15970#define REGSETH(p,t) \
15971 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15972 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15973 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15974 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15975#define REGSET2(p,t) \
15976 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15977 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15978 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15979 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15980
c19d1205 15981static const struct reg_entry reg_names[] =
7ed4c4c5 15982{
c19d1205
ZW
15983 /* ARM integer registers. */
15984 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15985
c19d1205
ZW
15986 /* ATPCS synonyms. */
15987 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15988 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15989 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 15990
c19d1205
ZW
15991 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15992 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15993 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 15994
c19d1205
ZW
15995 /* Well-known aliases. */
15996 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15997 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15998
15999 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16000 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16001
16002 /* Coprocessor numbers. */
16003 REGSET(p, CP), REGSET(P, CP),
16004
16005 /* Coprocessor register numbers. The "cr" variants are for backward
16006 compatibility. */
16007 REGSET(c, CN), REGSET(C, CN),
16008 REGSET(cr, CN), REGSET(CR, CN),
16009
16010 /* FPA registers. */
16011 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16012 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16013
16014 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16015 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16016
16017 /* VFP SP registers. */
5287ad62
JB
16018 REGSET(s,VFS), REGSET(S,VFS),
16019 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
16020
16021 /* VFP DP Registers. */
5287ad62
JB
16022 REGSET(d,VFD), REGSET(D,VFD),
16023 /* Extra Neon DP registers. */
16024 REGSETH(d,VFD), REGSETH(D,VFD),
16025
16026 /* Neon QP registers. */
16027 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
16028
16029 /* VFP control registers. */
16030 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16031 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
16032 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16033 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16034 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16035 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
16036
16037 /* Maverick DSP coprocessor registers. */
16038 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16039 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16040
16041 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16042 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16043 REGDEF(dspsc,0,DSPSC),
16044
16045 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16046 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16047 REGDEF(DSPSC,0,DSPSC),
16048
16049 /* iWMMXt data registers - p0, c0-15. */
16050 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16051
16052 /* iWMMXt control registers - p1, c0-3. */
16053 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16054 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16055 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16056 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16057
16058 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16059 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16060 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16061 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16062 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16063
16064 /* XScale accumulator registers. */
16065 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16066};
16067#undef REGDEF
16068#undef REGNUM
16069#undef REGSET
7ed4c4c5 16070
c19d1205
ZW
16071/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16072 within psr_required_here. */
16073static const struct asm_psr psrs[] =
16074{
16075 /* Backward compatibility notation. Note that "all" is no longer
16076 truly all possible PSR bits. */
16077 {"all", PSR_c | PSR_f},
16078 {"flg", PSR_f},
16079 {"ctl", PSR_c},
16080
16081 /* Individual flags. */
16082 {"f", PSR_f},
16083 {"c", PSR_c},
16084 {"x", PSR_x},
16085 {"s", PSR_s},
16086 /* Combinations of flags. */
16087 {"fs", PSR_f | PSR_s},
16088 {"fx", PSR_f | PSR_x},
16089 {"fc", PSR_f | PSR_c},
16090 {"sf", PSR_s | PSR_f},
16091 {"sx", PSR_s | PSR_x},
16092 {"sc", PSR_s | PSR_c},
16093 {"xf", PSR_x | PSR_f},
16094 {"xs", PSR_x | PSR_s},
16095 {"xc", PSR_x | PSR_c},
16096 {"cf", PSR_c | PSR_f},
16097 {"cs", PSR_c | PSR_s},
16098 {"cx", PSR_c | PSR_x},
16099 {"fsx", PSR_f | PSR_s | PSR_x},
16100 {"fsc", PSR_f | PSR_s | PSR_c},
16101 {"fxs", PSR_f | PSR_x | PSR_s},
16102 {"fxc", PSR_f | PSR_x | PSR_c},
16103 {"fcs", PSR_f | PSR_c | PSR_s},
16104 {"fcx", PSR_f | PSR_c | PSR_x},
16105 {"sfx", PSR_s | PSR_f | PSR_x},
16106 {"sfc", PSR_s | PSR_f | PSR_c},
16107 {"sxf", PSR_s | PSR_x | PSR_f},
16108 {"sxc", PSR_s | PSR_x | PSR_c},
16109 {"scf", PSR_s | PSR_c | PSR_f},
16110 {"scx", PSR_s | PSR_c | PSR_x},
16111 {"xfs", PSR_x | PSR_f | PSR_s},
16112 {"xfc", PSR_x | PSR_f | PSR_c},
16113 {"xsf", PSR_x | PSR_s | PSR_f},
16114 {"xsc", PSR_x | PSR_s | PSR_c},
16115 {"xcf", PSR_x | PSR_c | PSR_f},
16116 {"xcs", PSR_x | PSR_c | PSR_s},
16117 {"cfs", PSR_c | PSR_f | PSR_s},
16118 {"cfx", PSR_c | PSR_f | PSR_x},
16119 {"csf", PSR_c | PSR_s | PSR_f},
16120 {"csx", PSR_c | PSR_s | PSR_x},
16121 {"cxf", PSR_c | PSR_x | PSR_f},
16122 {"cxs", PSR_c | PSR_x | PSR_s},
16123 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16124 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16125 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16126 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16127 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16128 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16129 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16130 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16131 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16132 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16133 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16134 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16135 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16136 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16137 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16138 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16139 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16140 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16141 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16142 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16143 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16144 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16145 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16146 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16147};
16148
62b3e311
PB
16149/* Table of V7M psr names. */
16150static const struct asm_psr v7m_psrs[] =
16151{
2b744c99
PB
16152 {"apsr", 0 }, {"APSR", 0 },
16153 {"iapsr", 1 }, {"IAPSR", 1 },
16154 {"eapsr", 2 }, {"EAPSR", 2 },
16155 {"psr", 3 }, {"PSR", 3 },
16156 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16157 {"ipsr", 5 }, {"IPSR", 5 },
16158 {"epsr", 6 }, {"EPSR", 6 },
16159 {"iepsr", 7 }, {"IEPSR", 7 },
16160 {"msp", 8 }, {"MSP", 8 },
16161 {"psp", 9 }, {"PSP", 9 },
16162 {"primask", 16}, {"PRIMASK", 16},
16163 {"basepri", 17}, {"BASEPRI", 17},
16164 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16165 {"faultmask", 19}, {"FAULTMASK", 19},
16166 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16167};
16168
c19d1205
ZW
16169/* Table of all shift-in-operand names. */
16170static const struct asm_shift_name shift_names [] =
b99bd4ef 16171{
c19d1205
ZW
16172 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16173 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16174 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16175 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16176 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16177 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16178};
b99bd4ef 16179
c19d1205
ZW
16180/* Table of all explicit relocation names. */
16181#ifdef OBJ_ELF
16182static struct reloc_entry reloc_names[] =
16183{
16184 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16185 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16186 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16187 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16188 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16189 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16190 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16191 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16192 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16193 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6
NC
16194 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16195 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
c19d1205
ZW
16196};
16197#endif
b99bd4ef 16198
c19d1205
ZW
16199/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16200static const struct asm_cond conds[] =
16201{
16202 {"eq", 0x0},
16203 {"ne", 0x1},
16204 {"cs", 0x2}, {"hs", 0x2},
16205 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16206 {"mi", 0x4},
16207 {"pl", 0x5},
16208 {"vs", 0x6},
16209 {"vc", 0x7},
16210 {"hi", 0x8},
16211 {"ls", 0x9},
16212 {"ge", 0xa},
16213 {"lt", 0xb},
16214 {"gt", 0xc},
16215 {"le", 0xd},
16216 {"al", 0xe}
16217};
bfae80f2 16218
62b3e311
PB
16219static struct asm_barrier_opt barrier_opt_names[] =
16220{
16221 { "sy", 0xf },
16222 { "un", 0x7 },
16223 { "st", 0xe },
16224 { "unst", 0x6 }
16225};
16226
c19d1205
ZW
16227/* Table of ARM-format instructions. */
16228
16229/* Macros for gluing together operand strings. N.B. In all cases
16230 other than OPS0, the trailing OP_stop comes from default
16231 zero-initialization of the unspecified elements of the array. */
16232#define OPS0() { OP_stop, }
16233#define OPS1(a) { OP_##a, }
16234#define OPS2(a,b) { OP_##a,OP_##b, }
16235#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16236#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16237#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16238#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16239
5be8be5d
DG
16240/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16241 This is useful when mixing operands for ARM and THUMB, i.e. using the
16242 MIX_ARM_THUMB_OPERANDS macro.
16243 In order to use these macros, prefix the number of operands with _
16244 e.g. _3. */
16245#define OPS_1(a) { a, }
16246#define OPS_2(a,b) { a,b, }
16247#define OPS_3(a,b,c) { a,b,c, }
16248#define OPS_4(a,b,c,d) { a,b,c,d, }
16249#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16250#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16251
c19d1205
ZW
16252/* These macros abstract out the exact format of the mnemonic table and
16253 save some repeated characters. */
16254
16255/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16256#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16257 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16258 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16259
16260/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16261 a T_MNEM_xyz enumerator. */
16262#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16263 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16264#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16265 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16266
16267/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16268 infix after the third character. */
16269#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16270 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16271 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16272#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16273 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16274 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16275#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16276 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16277#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16278 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16279#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16280 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16281#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16282 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16283
16284/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16285 appear in the condition table. */
16286#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16287 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16288 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16289
16290#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16291 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16292 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16293 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16294 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16295 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16296 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16297 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16298 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16299 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16300 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16301 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16302 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16303 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16304 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16305 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16306 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16307 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16308 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16309 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16310
16311#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16312 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16313#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16314 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16315
16316/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16317 field is still 0xE. Many of the Thumb variants can be executed
16318 conditionally, so this is checked separately. */
c19d1205 16319#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16320 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16321 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16322
16323/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16324 condition code field. */
16325#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16326 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16327 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16328
16329/* ARM-only variants of all the above. */
6a86118a 16330#define CE(mnem, op, nops, ops, ae) \
21d799b5 16331 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16332
16333#define C3(mnem, op, nops, ops, ae) \
16334 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16335
e3cb604e
PB
16336/* Legacy mnemonics that always have conditional infix after the third
16337 character. */
16338#define CL(mnem, op, nops, ops, ae) \
21d799b5 16339 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16340 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16341
8f06b2d8
PB
16342/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16343#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16344 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16345
e3cb604e
PB
16346/* Legacy coprocessor instructions where conditional infix and conditional
16347 suffix are ambiguous. For consistency this includes all FPA instructions,
16348 not just the potentially ambiguous ones. */
16349#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16350 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16351 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16352
16353/* Coprocessor, takes either a suffix or a position-3 infix
16354 (for an FPA corner case). */
16355#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16356 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16357 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16358
6a86118a 16359#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16360 { m1 #m2 m3, OPS##nops ops, \
16361 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16362 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16363
16364#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16365 xCM_ (m1, , m2, op, nops, ops, ae), \
16366 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16367 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16368 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16369 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16370 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16371 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16372 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16373 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16374 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16375 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16376 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16377 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16378 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16379 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16380 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16381 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16382 xCM_ (m1, le, m2, op, nops, ops, ae), \
16383 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16384
16385#define UE(mnem, op, nops, ops, ae) \
16386 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16387
16388#define UF(mnem, op, nops, ops, ae) \
16389 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16390
5287ad62
JB
16391/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16392 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16393 use the same encoding function for each. */
16394#define NUF(mnem, op, nops, ops, enc) \
16395 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16396 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16397
16398/* Neon data processing, version which indirects through neon_enc_tab for
16399 the various overloaded versions of opcodes. */
16400#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16401 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16402 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16403
16404/* Neon insn with conditional suffix for the ARM version, non-overloaded
16405 version. */
037e8744
JB
16406#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16407 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16408 THUMB_VARIANT, do_##enc, do_##enc }
16409
037e8744 16410#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16411 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16412
16413#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16414 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16415
5287ad62 16416/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16417#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16418 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16419 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16420
037e8744 16421#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16422 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16423
16424#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16425 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16426
c19d1205
ZW
16427#define do_0 0
16428
16429/* Thumb-only, unconditional. */
e07e6e58 16430#define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
c19d1205 16431
c19d1205 16432static const struct asm_opcode insns[] =
bfae80f2 16433{
e74cfd16
PB
16434#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16435#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16436 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16437 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16438 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16439 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16440 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16441 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16442 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16443 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16444 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16445 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16446 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16447 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16448 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16449 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16450 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16451 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16452
16453 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16454 for setting PSR flag bits. They are obsolete in V6 and do not
16455 have Thumb equivalents. */
21d799b5
NC
16456 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16457 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16458 CL("tstp", 110f000, 2, (RR, SH), cmp),
16459 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16460 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16461 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16462 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16463 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16464 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16465
16466 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16467 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16468 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16469 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16470
16471 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
16472 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16473 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16474 OP_RRnpc),
16475 OP_ADDRGLDR),ldst, t_ldst),
16476 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
16477
16478 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16479 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16480 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16481 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16482 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16483 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16484
16485 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16486 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16487 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16488 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16489
c19d1205 16490 /* Pseudo ops. */
21d799b5 16491 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16492 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16493 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16494
16495 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16496 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16497 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16498 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16499 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16500 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16501 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16502 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16503 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16504 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16505 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16506 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16507 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16508
16a4cf17 16509 /* These may simplify to neg. */
21d799b5
NC
16510 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16511 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16512
c921be7d
NC
16513#undef THUMB_VARIANT
16514#define THUMB_VARIANT & arm_ext_v6
16515
21d799b5 16516 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16517
16518 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16519#undef THUMB_VARIANT
16520#define THUMB_VARIANT & arm_ext_v6t2
16521
21d799b5
NC
16522 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16523 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16524 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16525
5be8be5d
DG
16526 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16527 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16528 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16529 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 16530
21d799b5
NC
16531 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16532 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16533
21d799b5
NC
16534 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16535 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16536
16537 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16538 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16539 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16540
16541 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16542 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16543 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16544 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16545 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16546 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16547 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16548 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16549
c921be7d
NC
16550#undef ARM_VARIANT
16551#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16552#undef THUMB_VARIANT
16553#define THUMB_VARIANT & arm_ext_v4t
16554
21d799b5
NC
16555 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16556 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16557
c921be7d
NC
16558#undef THUMB_VARIANT
16559#define THUMB_VARIANT & arm_ext_v6t2
16560
21d799b5 16561 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16562 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16563
16564 /* Generic coprocessor instructions. */
21d799b5
NC
16565 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16566 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16567 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16568 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16569 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16570 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16571 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16572
c921be7d
NC
16573#undef ARM_VARIANT
16574#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16575
21d799b5 16576 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16577 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16578
c921be7d
NC
16579#undef ARM_VARIANT
16580#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16581#undef THUMB_VARIANT
16582#define THUMB_VARIANT & arm_ext_msr
16583
21d799b5
NC
16584 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16585 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16586
c921be7d
NC
16587#undef ARM_VARIANT
16588#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16589#undef THUMB_VARIANT
16590#define THUMB_VARIANT & arm_ext_v6t2
16591
21d799b5
NC
16592 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16593 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16594 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16595 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16596 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16597 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16598 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16599 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16600
c921be7d
NC
16601#undef ARM_VARIANT
16602#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16603#undef THUMB_VARIANT
16604#define THUMB_VARIANT & arm_ext_v4t
16605
5be8be5d
DG
16606 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16607 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16608 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16609 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16610 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16611 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16612
c921be7d
NC
16613#undef ARM_VARIANT
16614#define ARM_VARIANT & arm_ext_v4t_5
16615
c19d1205
ZW
16616 /* ARM Architecture 4T. */
16617 /* Note: bx (and blx) are required on V5, even if the processor does
16618 not support Thumb. */
21d799b5 16619 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16620
c921be7d
NC
16621#undef ARM_VARIANT
16622#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16623#undef THUMB_VARIANT
16624#define THUMB_VARIANT & arm_ext_v5t
16625
c19d1205
ZW
16626 /* Note: blx has 2 variants; the .value coded here is for
16627 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16628 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16629 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16630
c921be7d
NC
16631#undef THUMB_VARIANT
16632#define THUMB_VARIANT & arm_ext_v6t2
16633
21d799b5
NC
16634 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16635 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16636 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16637 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16638 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16639 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16640 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16641 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16642
c921be7d
NC
16643#undef ARM_VARIANT
16644#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16645#undef THUMB_VARIANT
16646#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16647
21d799b5
NC
16648 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16649 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16650 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16651 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16652
21d799b5
NC
16653 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16654 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16655
21d799b5
NC
16656 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16657 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16658 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16659 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16660
21d799b5
NC
16661 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16662 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16663 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16664 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16665
21d799b5
NC
16666 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16667 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16668
03ee1b7f
NC
16669 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16670 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16671 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16672 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 16673
c921be7d
NC
16674#undef ARM_VARIANT
16675#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16676#undef THUMB_VARIANT
16677#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16678
21d799b5 16679 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
16680 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16681 ldrd, t_ldstd),
16682 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16683 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16684
21d799b5
NC
16685 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16686 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16687
c921be7d
NC
16688#undef ARM_VARIANT
16689#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16690
21d799b5 16691 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16692
c921be7d
NC
16693#undef ARM_VARIANT
16694#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16695#undef THUMB_VARIANT
16696#define THUMB_VARIANT & arm_ext_v6
16697
21d799b5
NC
16698 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16699 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16700 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16701 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16702 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16703 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16704 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16705 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16706 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16707 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16708
c921be7d
NC
16709#undef THUMB_VARIANT
16710#define THUMB_VARIANT & arm_ext_v6t2
16711
5be8be5d
DG
16712 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16713 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16714 strex, t_strex),
21d799b5
NC
16715 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16716 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16717
21d799b5
NC
16718 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16719 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16720
9e3c6df6 16721/* ARM V6 not included in V7M. */
c921be7d
NC
16722#undef THUMB_VARIANT
16723#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16724 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16725 UF(rfeib, 9900a00, 1, (RRw), rfe),
16726 UF(rfeda, 8100a00, 1, (RRw), rfe),
16727 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16728 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16729 UF(rfefa, 9900a00, 1, (RRw), rfe),
16730 UF(rfeea, 8100a00, 1, (RRw), rfe),
16731 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16732 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16733 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16734 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16735 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16736
9e3c6df6
PB
16737/* ARM V6 not included in V7M (eg. integer SIMD). */
16738#undef THUMB_VARIANT
16739#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16740 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16741 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16742 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16743 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16744 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16745 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16746 /* Old name for QASX. */
21d799b5
NC
16747 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16748 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16749 /* Old name for QSAX. */
21d799b5
NC
16750 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16751 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16752 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16753 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16754 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16755 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16756 /* Old name for SASX. */
21d799b5
NC
16757 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16758 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16759 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16760 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16761 /* Old name for SHASX. */
21d799b5
NC
16762 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16763 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16764 /* Old name for SHSAX. */
21d799b5
NC
16765 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16766 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16767 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16768 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16769 /* Old name for SSAX. */
21d799b5
NC
16770 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16771 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16772 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16773 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16774 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16775 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16776 /* Old name for UASX. */
21d799b5
NC
16777 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16778 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16779 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16780 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16781 /* Old name for UHASX. */
21d799b5
NC
16782 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16783 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16784 /* Old name for UHSAX. */
21d799b5
NC
16785 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16786 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16787 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16788 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16789 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16790 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16791 /* Old name for UQASX. */
21d799b5
NC
16792 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16793 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16794 /* Old name for UQSAX. */
21d799b5
NC
16795 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16796 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16797 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16798 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16799 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16800 /* Old name for USAX. */
21d799b5
NC
16801 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16802 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16803 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16804 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16805 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16806 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16807 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16808 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16809 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16810 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16811 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16812 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16813 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16814 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16815 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16816 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16817 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16818 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16819 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16820 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16821 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16822 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16823 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16824 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16825 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16826 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16827 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16828 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16829 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
16830 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16831 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16832 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16833 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16834 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 16835
c921be7d
NC
16836#undef ARM_VARIANT
16837#define ARM_VARIANT & arm_ext_v6k
16838#undef THUMB_VARIANT
16839#define THUMB_VARIANT & arm_ext_v6k
16840
21d799b5
NC
16841 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16842 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16843 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16844 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 16845
c921be7d
NC
16846#undef THUMB_VARIANT
16847#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
16848 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16849 ldrexd, t_ldrexd),
16850 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16851 RRnpcb), strexd, t_strexd),
ebdca51a 16852
c921be7d
NC
16853#undef THUMB_VARIANT
16854#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
16855 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16856 rd_rn, rd_rn),
16857 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16858 rd_rn, rd_rn),
16859 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16860 strex, rm_rd_rn),
16861 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16862 strex, rm_rd_rn),
21d799b5 16863 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 16864
c921be7d
NC
16865#undef ARM_VARIANT
16866#define ARM_VARIANT & arm_ext_v6z
16867
21d799b5 16868 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 16869
c921be7d
NC
16870#undef ARM_VARIANT
16871#define ARM_VARIANT & arm_ext_v6t2
16872
21d799b5
NC
16873 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16874 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16875 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16876 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 16877
21d799b5
NC
16878 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16879 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16880 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16881 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 16882
5be8be5d
DG
16883 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16884 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16885 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16886 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 16887
21d799b5
NC
16888 UT("cbnz", b900, 2, (RR, EXP), t_cbz),
16889 UT("cbz", b100, 2, (RR, EXP), t_cbz),
c921be7d
NC
16890
16891 /* ARM does not really have an IT instruction, so always allow it.
16892 The opcode is copied from Thumb in order to allow warnings in
16893 -mimplicit-it=[never | arm] modes. */
16894#undef ARM_VARIANT
16895#define ARM_VARIANT & arm_ext_v1
16896
21d799b5
NC
16897 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16898 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16899 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16900 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16901 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16902 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16903 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16904 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16905 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16906 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16907 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16908 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16909 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16910 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16911 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 16912 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
16913 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16914 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16915
92e90b6e 16916 /* Thumb2 only instructions. */
c921be7d
NC
16917#undef ARM_VARIANT
16918#define ARM_VARIANT NULL
92e90b6e 16919
21d799b5
NC
16920 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16921 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16922 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16923 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16924 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16925 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 16926
62b3e311 16927 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
16928#undef THUMB_VARIANT
16929#define THUMB_VARIANT & arm_ext_div
16930
21d799b5
NC
16931 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16932 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 16933
7e806470 16934 /* ARM V6M/V7 instructions. */
c921be7d
NC
16935#undef ARM_VARIANT
16936#define ARM_VARIANT & arm_ext_barrier
16937#undef THUMB_VARIANT
16938#define THUMB_VARIANT & arm_ext_barrier
16939
21d799b5
NC
16940 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16941 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16942 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
7e806470 16943
62b3e311 16944 /* ARM V7 instructions. */
c921be7d
NC
16945#undef ARM_VARIANT
16946#define ARM_VARIANT & arm_ext_v7
16947#undef THUMB_VARIANT
16948#define THUMB_VARIANT & arm_ext_v7
16949
21d799b5
NC
16950 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16951 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16952
c921be7d
NC
16953#undef ARM_VARIANT
16954#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16955
21d799b5
NC
16956 cCE("wfs", e200110, 1, (RR), rd),
16957 cCE("rfs", e300110, 1, (RR), rd),
16958 cCE("wfc", e400110, 1, (RR), rd),
16959 cCE("rfc", e500110, 1, (RR), rd),
16960
16961 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16962 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16963 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16964 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16965
16966 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16967 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16968 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16969 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16970
16971 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16972 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16973 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16974 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16975 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16976 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16977 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16978 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16979 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16980 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16981 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16982 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16983
16984 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16985 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16986 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16987 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16988 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
16989 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
16990 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
16991 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
16992 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
16993 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
16994 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
16995 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
16996
16997 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
16998 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
16999 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17000 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17001 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17002 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17003 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17004 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17005 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17006 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17007 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17008 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17009
17010 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17011 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17012 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17013 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17014 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17015 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17016 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17017 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17018 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17019 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17020 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17021 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17022
17023 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17024 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17025 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17026 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17027 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17028 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17029 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17030 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17031 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17032 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17033 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17034 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17035
17036 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17037 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17038 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17039 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17040 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17041 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17042 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17043 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17044 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17045 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17046 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17047 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17048
17049 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17050 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17051 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17052 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17053 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17054 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17055 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17056 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17057 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17058 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17059 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17060 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17061
17062 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17063 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17064 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17065 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17066 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17067 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17068 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17069 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17070 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17071 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17072 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17073 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17074
17075 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17076 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17077 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17078 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17079 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17080 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17081 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17082 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17083 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17084 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17085 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17086 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17087
17088 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17089 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17090 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17091 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17092 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17093 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17094 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17095 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17096 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17097 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17098 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17099 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17100
17101 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17102 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17103 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17104 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17105 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17106 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17107 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17108 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17109 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17110 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17111 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17112 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17113
17114 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17115 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17116 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17117 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17118 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17119 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17120 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17121 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17122 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17123 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17124 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17125 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17126
17127 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17128 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17129 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17130 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17131 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17132 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17133 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17134 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17135 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17136 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17137 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17138 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17139
17140 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17141 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17142 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17143 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17144 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17145 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17146 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17147 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17148 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17149 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17150 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17151 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17152
17153 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17154 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17155 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17156 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17157 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17158 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17159 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17160 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17161 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17162 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17163 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17164 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17165
17166 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17167 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17168 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17169 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17170 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17171 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17172 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17173 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17174 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17175 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17176 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17177 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17178
17179 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17180 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17181 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17182 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17183 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17184 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17185 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17186 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17187 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17188 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17189 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17190 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17191
17192 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17193 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17194 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17195 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17196 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17197 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17198 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17199 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17200 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17202 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17203 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17204
17205 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17207 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17208 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17209 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17210 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17211 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17212 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17213 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17214 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17215 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17216 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17217
17218 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17219 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17220 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17221 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17222 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17223 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17224 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17225 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17226 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17227 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17228 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17229 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17230
17231 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17232 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17233 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17234 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17235 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17236 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17237 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17238 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17239 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17240 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17241 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17242 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17243
17244 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17245 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17246 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17247 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17248 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17249 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17250 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17251 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17252 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17253 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17254 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17255 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17256
17257 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17258 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17259 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17260 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17261 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17262 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17263 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17264 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17265 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17266 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17267 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17268 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17269
17270 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17271 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17272 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17273 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17274 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17275 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17276 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17277 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17278 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17279 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17280 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17281 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17282
17283 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17284 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17285 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17286 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17290 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17291 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17293 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17294 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17295
17296 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17297 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17298 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17299 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17303 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17304 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17306 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17307 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17308
17309 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17310 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17311 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17312 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17316 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17317 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17319 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17320 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17321
17322 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17323 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17324 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17325 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17329 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17330 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17332 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17333 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17334
17335 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17336 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17337 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17338 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17339 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17340 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17341 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17342 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17343 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17344 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17345 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17346 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17347
17348 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17349 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17350 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17351 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17352
17353 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17354 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17355 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17356 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17357 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17358 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17359 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17360 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17361 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17362 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17363 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17364 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17365
c19d1205
ZW
17366 /* The implementation of the FIX instruction is broken on some
17367 assemblers, in that it accepts a precision specifier as well as a
17368 rounding specifier, despite the fact that this is meaningless.
17369 To be more compatible, we accept it as well, though of course it
17370 does not set any bits. */
21d799b5
NC
17371 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17372 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17373 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17374 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17375 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17376 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17377 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17378 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17379 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17380 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17381 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17382 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17383 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17384
c19d1205 17385 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17386#undef ARM_VARIANT
17387#define ARM_VARIANT & fpu_fpa_ext_v2
17388
21d799b5
NC
17389 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17390 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17391 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17392 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17393 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17394 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17395
c921be7d
NC
17396#undef ARM_VARIANT
17397#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17398
c19d1205 17399 /* Moves and type conversions. */
21d799b5
NC
17400 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17401 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17402 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17403 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17404 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17405 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17406 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17407 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17408 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17409 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17410 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17411 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17412 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17413 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17414
17415 /* Memory operations. */
21d799b5
NC
17416 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17417 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17418 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17419 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17420 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17421 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17422 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17423 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17424 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17425 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17426 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17427 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17428 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17429 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17430 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17431 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17432 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17433 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17434
c19d1205 17435 /* Monadic operations. */
21d799b5
NC
17436 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17437 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17438 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17439
17440 /* Dyadic operations. */
21d799b5
NC
17441 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17442 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17443 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17444 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17445 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17446 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17447 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17448 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17449 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17450
c19d1205 17451 /* Comparisons. */
21d799b5
NC
17452 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17453 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17454 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17455 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17456
62f3b8c8
PB
17457 /* Double precision load/store are still present on single precision
17458 implementations. */
17459 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17460 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17461 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17462 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17463 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17464 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17465 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17466 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17467 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17468 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17469
c921be7d
NC
17470#undef ARM_VARIANT
17471#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17472
c19d1205 17473 /* Moves and type conversions. */
21d799b5
NC
17474 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17475 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17476 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17477 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17478 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17479 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17480 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17481 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17482 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17483 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17484 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17485 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17486 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17487
c19d1205 17488 /* Monadic operations. */
21d799b5
NC
17489 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17490 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17491 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17492
17493 /* Dyadic operations. */
21d799b5
NC
17494 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17495 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17496 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17497 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17498 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17499 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17500 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17501 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17502 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17503
c19d1205 17504 /* Comparisons. */
21d799b5
NC
17505 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17506 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17507 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17508 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17509
c921be7d
NC
17510#undef ARM_VARIANT
17511#define ARM_VARIANT & fpu_vfp_ext_v2
17512
21d799b5
NC
17513 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17514 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17515 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17516 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17517
037e8744
JB
17518/* Instructions which may belong to either the Neon or VFP instruction sets.
17519 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17520#undef ARM_VARIANT
17521#define ARM_VARIANT & fpu_vfp_ext_v1xd
17522#undef THUMB_VARIANT
17523#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17524
037e8744
JB
17525 /* These mnemonics are unique to VFP. */
17526 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17527 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17528 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17529 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17530 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17531 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17532 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17533 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17534 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17535 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17536
17537 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17538 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17539 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17540 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17541
21d799b5
NC
17542 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17543 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17544
17545 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17546 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17547
17548 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17549 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17550 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17551 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17552 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17553 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17554 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17555 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17556
e3e535bc
NC
17557 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17558 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
21d799b5
NC
17559 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17560 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17561
037e8744
JB
17562
17563 /* NOTE: All VMOV encoding is special-cased! */
17564 NCE(vmov, 0, 1, (VMOV), neon_mov),
17565 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17566
c921be7d
NC
17567#undef THUMB_VARIANT
17568#define THUMB_VARIANT & fpu_neon_ext_v1
17569#undef ARM_VARIANT
17570#define ARM_VARIANT & fpu_neon_ext_v1
17571
5287ad62
JB
17572 /* Data processing with three registers of the same length. */
17573 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17574 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17575 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17576 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17577 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17578 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17579 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17580 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17581 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17582 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17583 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17584 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17585 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17586 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17587 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17588 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17589 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17590 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17591 /* If not immediate, fall back to neon_dyadic_i64_su.
17592 shl_imm should accept I8 I16 I32 I64,
17593 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17594 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17595 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17596 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17597 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17598 /* Logic ops, types optional & ignored. */
4316f0d2
DG
17599 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17600 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17601 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17602 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17603 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17604 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17605 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17606 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17607 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17608 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17609 /* Bitfield ops, untyped. */
17610 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17611 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17612 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17613 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17614 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17615 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17616 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17617 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17618 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17619 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17620 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17621 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17622 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17623 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17624 back to neon_dyadic_if_su. */
21d799b5
NC
17625 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17626 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17627 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17628 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17629 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17630 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17631 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17632 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17633 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17634 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17635 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17636 /* As above, D registers only. */
21d799b5
NC
17637 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17638 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17639 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17640 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17641 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17642 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17643 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17644 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17645 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17646 /* vtst takes sizes 8, 16, 32. */
17647 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17648 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17649 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17650 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17651 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17652 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17653 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17654 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17655 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17656 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17657 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17658 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17659 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17660 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17661 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17662 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17663 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17664 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17665 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17666 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17667 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17668
17669 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17670 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17671 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17672
17673 /* Data processing with two registers and a shift amount. */
17674 /* Right shifts, and variants with rounding.
17675 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17676 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17677 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17678 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17679 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17680 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17681 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17682 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17683 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17684 /* Shift and insert. Sizes accepted 8 16 32 64. */
17685 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17686 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17687 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17688 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17689 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17690 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17691 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17692 /* Right shift immediate, saturating & narrowing, with rounding variants.
17693 Types accepted S16 S32 S64 U16 U32 U64. */
17694 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17695 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17696 /* As above, unsigned. Types accepted S16 S32 S64. */
17697 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17698 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17699 /* Right shift narrowing. Types accepted I16 I32 I64. */
17700 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17701 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17702 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17703 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17704 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17705 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17706
4316f0d2
DG
17707 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17708 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
17709
17710 /* Data processing, three registers of different lengths. */
17711 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17712 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17713 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17714 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17715 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17716 /* If not scalar, fall back to neon_dyadic_long.
17717 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17718 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17719 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17720 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17721 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17722 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17723 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17724 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17725 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17726 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17727 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17728 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17729 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17730 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17731 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17732 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17733 S16 S32 U16 U32. */
21d799b5 17734 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17735
17736 /* Extract. Size 8. */
3b8d421e
PB
17737 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17738 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17739
17740 /* Two registers, miscellaneous. */
17741 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17742 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17743 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17744 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17745 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17746 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17747 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17748 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17749 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17750 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17751 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17752 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17753 /* VMOVN. Types I16 I32 I64. */
21d799b5 17754 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17755 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17756 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17757 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17758 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17759 /* VZIP / VUZP. Sizes 8 16 32. */
17760 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17761 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17762 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17763 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17764 /* VQABS / VQNEG. Types S8 S16 S32. */
17765 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17766 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17767 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17768 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17769 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17770 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17771 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17772 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17773 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17774 /* Reciprocal estimates. Types U32 F32. */
17775 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17776 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17777 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17778 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17779 /* VCLS. Types S8 S16 S32. */
17780 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17781 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17782 /* VCLZ. Types I8 I16 I32. */
17783 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17784 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17785 /* VCNT. Size 8. */
17786 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17787 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17788 /* Two address, untyped. */
17789 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17790 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17791 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17792 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17793 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17794
17795 /* Table lookup. Size 8. */
17796 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17797 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17798
c921be7d
NC
17799#undef THUMB_VARIANT
17800#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17801#undef ARM_VARIANT
17802#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17803
5287ad62 17804 /* Neon element/structure load/store. */
21d799b5
NC
17805 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17806 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17807 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17808 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17809 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17810 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17811 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17812 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17813
c921be7d 17814#undef THUMB_VARIANT
62f3b8c8
PB
17815#define THUMB_VARIANT &fpu_vfp_ext_v3xd
17816#undef ARM_VARIANT
17817#define ARM_VARIANT &fpu_vfp_ext_v3xd
17818 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17819 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17820 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17821 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17822 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17823 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17824 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17825 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17826 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17827
17828#undef THUMB_VARIANT
c921be7d
NC
17829#define THUMB_VARIANT & fpu_vfp_ext_v3
17830#undef ARM_VARIANT
17831#define ARM_VARIANT & fpu_vfp_ext_v3
17832
21d799b5 17833 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 17834 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17835 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17836 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17837 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17838 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17839 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17840 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17841 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17842
62f3b8c8
PB
17843#undef ARM_VARIANT
17844#define ARM_VARIANT &fpu_vfp_ext_fma
17845#undef THUMB_VARIANT
17846#define THUMB_VARIANT &fpu_vfp_ext_fma
17847 /* Mnemonics shared by Neon and VFP. These are included in the
17848 VFP FMA variant; NEON and VFP FMA always includes the NEON
17849 FMA instructions. */
17850 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17851 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17852 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17853 the v form should always be used. */
17854 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17855 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17856 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17857 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17858 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17859 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17860
5287ad62 17861#undef THUMB_VARIANT
c921be7d
NC
17862#undef ARM_VARIANT
17863#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17864
21d799b5
NC
17865 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17866 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17867 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17868 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17869 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17870 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17871 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17872 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 17873
c921be7d
NC
17874#undef ARM_VARIANT
17875#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17876
21d799b5
NC
17877 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17878 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17879 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17880 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17881 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17882 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17883 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17884 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17885 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17886 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17887 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17888 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17889 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17890 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17891 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17892 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17893 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17894 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17895 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17896 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17897 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17898 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17899 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17900 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17901 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17902 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17903 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17904 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17905 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17906 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17907 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17908 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17909 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17910 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17911 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17912 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17913 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17914 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17915 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17916 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17917 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17918 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17919 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17920 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17921 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17922 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17923 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17924 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17925 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17934 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17935 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17944 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17945 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17946 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17947 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17955 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17956 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17957 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17958 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17961 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17962 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17963 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17964 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17965 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17966 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17967 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17968 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17969 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17970 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17971 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17972 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17973 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17974 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17975 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17976 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17977 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17978 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17979 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17980 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17981 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17982 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17983 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17984 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17985 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17986 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17987 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17988 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17989 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17990 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17991 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17992 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17993 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17994 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17995 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17996 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17997 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17998 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17999 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18000 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18001 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18002 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18003 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18004 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18005 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18006 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18007 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18008 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18009 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18010 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18011 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18012 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18013 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18014 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18015 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18016 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18017 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18018 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18019 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18020 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18021 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18022 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18023 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18024 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18025 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18026 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18027 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18028 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18029 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18030 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18031 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18032 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18033 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18034 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18035 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18036 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18037 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18038 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 18039
c921be7d
NC
18040#undef ARM_VARIANT
18041#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18042
21d799b5
NC
18043 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18044 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18045 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18046 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18047 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18048 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18049 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18050 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18051 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18052 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18053 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18054 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18055 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18056 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18057 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18058 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18059 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18060 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18061 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18062 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18063 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18064 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18065 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18066 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18067 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18068 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18069 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18070 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18071 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18075 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18083 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18084 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18085 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18086 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18087 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18088 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18091 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18092 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18093 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18094 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18095 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18096 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18097 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18098 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18099 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 18100
c921be7d
NC
18101#undef ARM_VARIANT
18102#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18103
21d799b5
NC
18104 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18105 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18106 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18107 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18108 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18109 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18110 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18111 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18112 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18113 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18114 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18115 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18116 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18117 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18118 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18119 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18120 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18121 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18122 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18123 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18124 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18125 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18126 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18127 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18128 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18129 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18130 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18131 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18132 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18133 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18134 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18135 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18136 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18137 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18138 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18139 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18140 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18141 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18142 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18143 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18144 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18145 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18146 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18147 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18148 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18149 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18150 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18151 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18152 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18153 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18154 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18155 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18156 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18157 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18158 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18159 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18160 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18161 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18162 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18163 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18164 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18165 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18166 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18167 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18168 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18169 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18170 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18171 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18172 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18173 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18174 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18175 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18176 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18177 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18178 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18179 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18180};
18181#undef ARM_VARIANT
18182#undef THUMB_VARIANT
18183#undef TCE
18184#undef TCM
18185#undef TUE
18186#undef TUF
18187#undef TCC
8f06b2d8 18188#undef cCE
e3cb604e
PB
18189#undef cCL
18190#undef C3E
c19d1205
ZW
18191#undef CE
18192#undef CM
18193#undef UE
18194#undef UF
18195#undef UT
5287ad62
JB
18196#undef NUF
18197#undef nUF
18198#undef NCE
18199#undef nCE
c19d1205
ZW
18200#undef OPS0
18201#undef OPS1
18202#undef OPS2
18203#undef OPS3
18204#undef OPS4
18205#undef OPS5
18206#undef OPS6
18207#undef do_0
18208\f
18209/* MD interface: bits in the object file. */
bfae80f2 18210
c19d1205
ZW
18211/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18212 for use in the a.out file, and stores them in the array pointed to by buf.
18213 This knows about the endian-ness of the target machine and does
18214 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18215 2 (short) and 4 (long) Floating numbers are put out as a series of
18216 LITTLENUMS (shorts, here at least). */
b99bd4ef 18217
c19d1205
ZW
18218void
18219md_number_to_chars (char * buf, valueT val, int n)
18220{
18221 if (target_big_endian)
18222 number_to_chars_bigendian (buf, val, n);
18223 else
18224 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18225}
18226
c19d1205
ZW
18227static valueT
18228md_chars_to_number (char * buf, int n)
bfae80f2 18229{
c19d1205
ZW
18230 valueT result = 0;
18231 unsigned char * where = (unsigned char *) buf;
bfae80f2 18232
c19d1205 18233 if (target_big_endian)
b99bd4ef 18234 {
c19d1205
ZW
18235 while (n--)
18236 {
18237 result <<= 8;
18238 result |= (*where++ & 255);
18239 }
b99bd4ef 18240 }
c19d1205 18241 else
b99bd4ef 18242 {
c19d1205
ZW
18243 while (n--)
18244 {
18245 result <<= 8;
18246 result |= (where[n] & 255);
18247 }
bfae80f2 18248 }
b99bd4ef 18249
c19d1205 18250 return result;
bfae80f2 18251}
b99bd4ef 18252
c19d1205 18253/* MD interface: Sections. */
b99bd4ef 18254
0110f2b8
PB
18255/* Estimate the size of a frag before relaxing. Assume everything fits in
18256 2 bytes. */
18257
c19d1205 18258int
0110f2b8 18259md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18260 segT segtype ATTRIBUTE_UNUSED)
18261{
0110f2b8
PB
18262 fragp->fr_var = 2;
18263 return 2;
18264}
18265
18266/* Convert a machine dependent frag. */
18267
18268void
18269md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18270{
18271 unsigned long insn;
18272 unsigned long old_op;
18273 char *buf;
18274 expressionS exp;
18275 fixS *fixp;
18276 int reloc_type;
18277 int pc_rel;
18278 int opcode;
18279
18280 buf = fragp->fr_literal + fragp->fr_fix;
18281
18282 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18283 if (fragp->fr_symbol)
18284 {
0110f2b8
PB
18285 exp.X_op = O_symbol;
18286 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18287 }
18288 else
18289 {
0110f2b8 18290 exp.X_op = O_constant;
5f4273c7 18291 }
0110f2b8
PB
18292 exp.X_add_number = fragp->fr_offset;
18293 opcode = fragp->fr_subtype;
18294 switch (opcode)
18295 {
18296 case T_MNEM_ldr_pc:
18297 case T_MNEM_ldr_pc2:
18298 case T_MNEM_ldr_sp:
18299 case T_MNEM_str_sp:
18300 case T_MNEM_ldr:
18301 case T_MNEM_ldrb:
18302 case T_MNEM_ldrh:
18303 case T_MNEM_str:
18304 case T_MNEM_strb:
18305 case T_MNEM_strh:
18306 if (fragp->fr_var == 4)
18307 {
5f4273c7 18308 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18309 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18310 {
18311 insn |= (old_op & 0x700) << 4;
18312 }
18313 else
18314 {
18315 insn |= (old_op & 7) << 12;
18316 insn |= (old_op & 0x38) << 13;
18317 }
18318 insn |= 0x00000c00;
18319 put_thumb32_insn (buf, insn);
18320 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18321 }
18322 else
18323 {
18324 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18325 }
18326 pc_rel = (opcode == T_MNEM_ldr_pc2);
18327 break;
18328 case T_MNEM_adr:
18329 if (fragp->fr_var == 4)
18330 {
18331 insn = THUMB_OP32 (opcode);
18332 insn |= (old_op & 0xf0) << 4;
18333 put_thumb32_insn (buf, insn);
18334 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18335 }
18336 else
18337 {
18338 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18339 exp.X_add_number -= 4;
18340 }
18341 pc_rel = 1;
18342 break;
18343 case T_MNEM_mov:
18344 case T_MNEM_movs:
18345 case T_MNEM_cmp:
18346 case T_MNEM_cmn:
18347 if (fragp->fr_var == 4)
18348 {
18349 int r0off = (opcode == T_MNEM_mov
18350 || opcode == T_MNEM_movs) ? 0 : 8;
18351 insn = THUMB_OP32 (opcode);
18352 insn = (insn & 0xe1ffffff) | 0x10000000;
18353 insn |= (old_op & 0x700) << r0off;
18354 put_thumb32_insn (buf, insn);
18355 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18356 }
18357 else
18358 {
18359 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18360 }
18361 pc_rel = 0;
18362 break;
18363 case T_MNEM_b:
18364 if (fragp->fr_var == 4)
18365 {
18366 insn = THUMB_OP32(opcode);
18367 put_thumb32_insn (buf, insn);
18368 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18369 }
18370 else
18371 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18372 pc_rel = 1;
18373 break;
18374 case T_MNEM_bcond:
18375 if (fragp->fr_var == 4)
18376 {
18377 insn = THUMB_OP32(opcode);
18378 insn |= (old_op & 0xf00) << 14;
18379 put_thumb32_insn (buf, insn);
18380 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18381 }
18382 else
18383 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18384 pc_rel = 1;
18385 break;
18386 case T_MNEM_add_sp:
18387 case T_MNEM_add_pc:
18388 case T_MNEM_inc_sp:
18389 case T_MNEM_dec_sp:
18390 if (fragp->fr_var == 4)
18391 {
18392 /* ??? Choose between add and addw. */
18393 insn = THUMB_OP32 (opcode);
18394 insn |= (old_op & 0xf0) << 4;
18395 put_thumb32_insn (buf, insn);
16805f35
PB
18396 if (opcode == T_MNEM_add_pc)
18397 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18398 else
18399 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18400 }
18401 else
18402 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18403 pc_rel = 0;
18404 break;
18405
18406 case T_MNEM_addi:
18407 case T_MNEM_addis:
18408 case T_MNEM_subi:
18409 case T_MNEM_subis:
18410 if (fragp->fr_var == 4)
18411 {
18412 insn = THUMB_OP32 (opcode);
18413 insn |= (old_op & 0xf0) << 4;
18414 insn |= (old_op & 0xf) << 16;
18415 put_thumb32_insn (buf, insn);
16805f35
PB
18416 if (insn & (1 << 20))
18417 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18418 else
18419 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18420 }
18421 else
18422 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18423 pc_rel = 0;
18424 break;
18425 default:
5f4273c7 18426 abort ();
0110f2b8
PB
18427 }
18428 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18429 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18430 fixp->fx_file = fragp->fr_file;
18431 fixp->fx_line = fragp->fr_line;
18432 fragp->fr_fix += fragp->fr_var;
18433}
18434
18435/* Return the size of a relaxable immediate operand instruction.
18436 SHIFT and SIZE specify the form of the allowable immediate. */
18437static int
18438relax_immediate (fragS *fragp, int size, int shift)
18439{
18440 offsetT offset;
18441 offsetT mask;
18442 offsetT low;
18443
18444 /* ??? Should be able to do better than this. */
18445 if (fragp->fr_symbol)
18446 return 4;
18447
18448 low = (1 << shift) - 1;
18449 mask = (1 << (shift + size)) - (1 << shift);
18450 offset = fragp->fr_offset;
18451 /* Force misaligned offsets to 32-bit variant. */
18452 if (offset & low)
5e77afaa 18453 return 4;
0110f2b8
PB
18454 if (offset & ~mask)
18455 return 4;
18456 return 2;
18457}
18458
5e77afaa
PB
18459/* Get the address of a symbol during relaxation. */
18460static addressT
5f4273c7 18461relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18462{
18463 fragS *sym_frag;
18464 addressT addr;
18465 symbolS *sym;
18466
18467 sym = fragp->fr_symbol;
18468 sym_frag = symbol_get_frag (sym);
18469 know (S_GET_SEGMENT (sym) != absolute_section
18470 || sym_frag == &zero_address_frag);
18471 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18472
18473 /* If frag has yet to be reached on this pass, assume it will
18474 move by STRETCH just as we did. If this is not so, it will
18475 be because some frag between grows, and that will force
18476 another pass. */
18477
18478 if (stretch != 0
18479 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18480 {
18481 fragS *f;
18482
18483 /* Adjust stretch for any alignment frag. Note that if have
18484 been expanding the earlier code, the symbol may be
18485 defined in what appears to be an earlier frag. FIXME:
18486 This doesn't handle the fr_subtype field, which specifies
18487 a maximum number of bytes to skip when doing an
18488 alignment. */
18489 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18490 {
18491 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18492 {
18493 if (stretch < 0)
18494 stretch = - ((- stretch)
18495 & ~ ((1 << (int) f->fr_offset) - 1));
18496 else
18497 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18498 if (stretch == 0)
18499 break;
18500 }
18501 }
18502 if (f != NULL)
18503 addr += stretch;
18504 }
5e77afaa
PB
18505
18506 return addr;
18507}
18508
0110f2b8
PB
18509/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18510 load. */
18511static int
5e77afaa 18512relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18513{
18514 addressT addr;
18515 offsetT val;
18516
18517 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18518 if (fragp->fr_symbol == NULL
18519 || !S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18520 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18521 return 4;
18522
5f4273c7 18523 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18524 addr = fragp->fr_address + fragp->fr_fix;
18525 addr = (addr + 4) & ~3;
5e77afaa 18526 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18527 if (val & 3)
5e77afaa 18528 return 4;
0110f2b8
PB
18529 val -= addr;
18530 if (val < 0 || val > 1020)
18531 return 4;
18532 return 2;
18533}
18534
18535/* Return the size of a relaxable add/sub immediate instruction. */
18536static int
18537relax_addsub (fragS *fragp, asection *sec)
18538{
18539 char *buf;
18540 int op;
18541
18542 buf = fragp->fr_literal + fragp->fr_fix;
18543 op = bfd_get_16(sec->owner, buf);
18544 if ((op & 0xf) == ((op >> 4) & 0xf))
18545 return relax_immediate (fragp, 8, 0);
18546 else
18547 return relax_immediate (fragp, 3, 0);
18548}
18549
18550
18551/* Return the size of a relaxable branch instruction. BITS is the
18552 size of the offset field in the narrow instruction. */
18553
18554static int
5e77afaa 18555relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18556{
18557 addressT addr;
18558 offsetT val;
18559 offsetT limit;
18560
18561 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18562 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18563 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18564 return 4;
18565
267bf995
RR
18566#ifdef OBJ_ELF
18567 if (S_IS_DEFINED (fragp->fr_symbol)
18568 && ARM_IS_FUNC (fragp->fr_symbol))
18569 return 4;
18570#endif
18571
5f4273c7 18572 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18573 addr = fragp->fr_address + fragp->fr_fix + 4;
18574 val -= addr;
18575
18576 /* Offset is a signed value *2 */
18577 limit = 1 << bits;
18578 if (val >= limit || val < -limit)
18579 return 4;
18580 return 2;
18581}
18582
18583
18584/* Relax a machine dependent frag. This returns the amount by which
18585 the current size of the frag should change. */
18586
18587int
5e77afaa 18588arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18589{
18590 int oldsize;
18591 int newsize;
18592
18593 oldsize = fragp->fr_var;
18594 switch (fragp->fr_subtype)
18595 {
18596 case T_MNEM_ldr_pc2:
5f4273c7 18597 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18598 break;
18599 case T_MNEM_ldr_pc:
18600 case T_MNEM_ldr_sp:
18601 case T_MNEM_str_sp:
5f4273c7 18602 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18603 break;
18604 case T_MNEM_ldr:
18605 case T_MNEM_str:
5f4273c7 18606 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18607 break;
18608 case T_MNEM_ldrh:
18609 case T_MNEM_strh:
5f4273c7 18610 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18611 break;
18612 case T_MNEM_ldrb:
18613 case T_MNEM_strb:
5f4273c7 18614 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18615 break;
18616 case T_MNEM_adr:
5f4273c7 18617 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18618 break;
18619 case T_MNEM_mov:
18620 case T_MNEM_movs:
18621 case T_MNEM_cmp:
18622 case T_MNEM_cmn:
5f4273c7 18623 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18624 break;
18625 case T_MNEM_b:
5f4273c7 18626 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18627 break;
18628 case T_MNEM_bcond:
5f4273c7 18629 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18630 break;
18631 case T_MNEM_add_sp:
18632 case T_MNEM_add_pc:
18633 newsize = relax_immediate (fragp, 8, 2);
18634 break;
18635 case T_MNEM_inc_sp:
18636 case T_MNEM_dec_sp:
18637 newsize = relax_immediate (fragp, 7, 2);
18638 break;
18639 case T_MNEM_addi:
18640 case T_MNEM_addis:
18641 case T_MNEM_subi:
18642 case T_MNEM_subis:
18643 newsize = relax_addsub (fragp, sec);
18644 break;
18645 default:
5f4273c7 18646 abort ();
0110f2b8 18647 }
5e77afaa
PB
18648
18649 fragp->fr_var = newsize;
18650 /* Freeze wide instructions that are at or before the same location as
18651 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18652 Don't freeze them unconditionally because targets may be artificially
18653 misaligned by the expansion of preceding frags. */
5e77afaa 18654 if (stretch <= 0 && newsize > 2)
0110f2b8 18655 {
0110f2b8 18656 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18657 frag_wane (fragp);
0110f2b8 18658 }
5e77afaa 18659
0110f2b8 18660 return newsize - oldsize;
c19d1205 18661}
b99bd4ef 18662
c19d1205 18663/* Round up a section size to the appropriate boundary. */
b99bd4ef 18664
c19d1205
ZW
18665valueT
18666md_section_align (segT segment ATTRIBUTE_UNUSED,
18667 valueT size)
18668{
f0927246
NC
18669#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18670 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18671 {
18672 /* For a.out, force the section size to be aligned. If we don't do
18673 this, BFD will align it for us, but it will not write out the
18674 final bytes of the section. This may be a bug in BFD, but it is
18675 easier to fix it here since that is how the other a.out targets
18676 work. */
18677 int align;
18678
18679 align = bfd_get_section_alignment (stdoutput, segment);
18680 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18681 }
c19d1205 18682#endif
f0927246
NC
18683
18684 return size;
bfae80f2 18685}
b99bd4ef 18686
c19d1205
ZW
18687/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18688 of an rs_align_code fragment. */
18689
18690void
18691arm_handle_align (fragS * fragP)
bfae80f2 18692{
e7495e45
NS
18693 static char const arm_noop[2][2][4] =
18694 {
18695 { /* ARMv1 */
18696 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18697 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18698 },
18699 { /* ARMv6k */
18700 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18701 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18702 },
18703 };
18704 static char const thumb_noop[2][2][2] =
18705 {
18706 { /* Thumb-1 */
18707 {0xc0, 0x46}, /* LE */
18708 {0x46, 0xc0}, /* BE */
18709 },
18710 { /* Thumb-2 */
18711 {0x00, 0xbf}, /* LE */
18712 {0xbf, 0x00} /* BE */
18713 }
18714 };
18715 static char const wide_thumb_noop[2][4] =
18716 { /* Wide Thumb-2 */
18717 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18718 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18719 };
c921be7d 18720
e7495e45 18721 unsigned bytes, fix, noop_size;
c19d1205
ZW
18722 char * p;
18723 const char * noop;
e7495e45 18724 const char *narrow_noop = NULL;
cd000bff
DJ
18725#ifdef OBJ_ELF
18726 enum mstate state;
18727#endif
bfae80f2 18728
c19d1205 18729 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18730 return;
18731
c19d1205
ZW
18732 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18733 p = fragP->fr_literal + fragP->fr_fix;
18734 fix = 0;
bfae80f2 18735
c19d1205
ZW
18736 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18737 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18738
cd000bff 18739 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 18740
cd000bff 18741 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18742 {
e7495e45
NS
18743 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18744 {
18745 narrow_noop = thumb_noop[1][target_big_endian];
18746 noop = wide_thumb_noop[target_big_endian];
18747 }
c19d1205 18748 else
e7495e45
NS
18749 noop = thumb_noop[0][target_big_endian];
18750 noop_size = 2;
cd000bff
DJ
18751#ifdef OBJ_ELF
18752 state = MAP_THUMB;
18753#endif
7ed4c4c5
NC
18754 }
18755 else
18756 {
e7495e45
NS
18757 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18758 [target_big_endian];
18759 noop_size = 4;
cd000bff
DJ
18760#ifdef OBJ_ELF
18761 state = MAP_ARM;
18762#endif
7ed4c4c5 18763 }
c921be7d 18764
e7495e45 18765 fragP->fr_var = noop_size;
c921be7d 18766
c19d1205 18767 if (bytes & (noop_size - 1))
7ed4c4c5 18768 {
c19d1205 18769 fix = bytes & (noop_size - 1);
cd000bff
DJ
18770#ifdef OBJ_ELF
18771 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18772#endif
c19d1205
ZW
18773 memset (p, 0, fix);
18774 p += fix;
18775 bytes -= fix;
a737bd4d 18776 }
a737bd4d 18777
e7495e45
NS
18778 if (narrow_noop)
18779 {
18780 if (bytes & noop_size)
18781 {
18782 /* Insert a narrow noop. */
18783 memcpy (p, narrow_noop, noop_size);
18784 p += noop_size;
18785 bytes -= noop_size;
18786 fix += noop_size;
18787 }
18788
18789 /* Use wide noops for the remainder */
18790 noop_size = 4;
18791 }
18792
c19d1205 18793 while (bytes >= noop_size)
a737bd4d 18794 {
c19d1205
ZW
18795 memcpy (p, noop, noop_size);
18796 p += noop_size;
18797 bytes -= noop_size;
18798 fix += noop_size;
a737bd4d
NC
18799 }
18800
c19d1205 18801 fragP->fr_fix += fix;
a737bd4d
NC
18802}
18803
c19d1205
ZW
18804/* Called from md_do_align. Used to create an alignment
18805 frag in a code section. */
18806
18807void
18808arm_frag_align_code (int n, int max)
bfae80f2 18809{
c19d1205 18810 char * p;
7ed4c4c5 18811
c19d1205 18812 /* We assume that there will never be a requirement
6ec8e702 18813 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 18814 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
18815 {
18816 char err_msg[128];
18817
18818 sprintf (err_msg,
18819 _("alignments greater than %d bytes not supported in .text sections."),
18820 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 18821 as_fatal ("%s", err_msg);
6ec8e702 18822 }
bfae80f2 18823
c19d1205
ZW
18824 p = frag_var (rs_align_code,
18825 MAX_MEM_FOR_RS_ALIGN_CODE,
18826 1,
18827 (relax_substateT) max,
18828 (symbolS *) NULL,
18829 (offsetT) n,
18830 (char *) NULL);
18831 *p = 0;
18832}
bfae80f2 18833
8dc2430f
NC
18834/* Perform target specific initialisation of a frag.
18835 Note - despite the name this initialisation is not done when the frag
18836 is created, but only when its type is assigned. A frag can be created
18837 and used a long time before its type is set, so beware of assuming that
18838 this initialisationis performed first. */
bfae80f2 18839
cd000bff
DJ
18840#ifndef OBJ_ELF
18841void
18842arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18843{
18844 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 18845 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
18846}
18847
18848#else /* OBJ_ELF is defined. */
c19d1205 18849void
cd000bff 18850arm_init_frag (fragS * fragP, int max_chars)
c19d1205 18851{
8dc2430f
NC
18852 /* If the current ARM vs THUMB mode has not already
18853 been recorded into this frag then do so now. */
cd000bff
DJ
18854 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18855 {
18856 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18857
18858 /* Record a mapping symbol for alignment frags. We will delete this
18859 later if the alignment ends up empty. */
18860 switch (fragP->fr_type)
18861 {
18862 case rs_align:
18863 case rs_align_test:
18864 case rs_fill:
18865 mapping_state_2 (MAP_DATA, max_chars);
18866 break;
18867 case rs_align_code:
18868 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18869 break;
18870 default:
18871 break;
18872 }
18873 }
bfae80f2
RE
18874}
18875
c19d1205
ZW
18876/* When we change sections we need to issue a new mapping symbol. */
18877
18878void
18879arm_elf_change_section (void)
bfae80f2 18880{
c19d1205
ZW
18881 /* Link an unlinked unwind index table section to the .text section. */
18882 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18883 && elf_linked_to_section (now_seg) == NULL)
18884 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
18885}
18886
c19d1205
ZW
18887int
18888arm_elf_section_type (const char * str, size_t len)
e45d0630 18889{
c19d1205
ZW
18890 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18891 return SHT_ARM_EXIDX;
e45d0630 18892
c19d1205
ZW
18893 return -1;
18894}
18895\f
18896/* Code to deal with unwinding tables. */
e45d0630 18897
c19d1205 18898static void add_unwind_adjustsp (offsetT);
e45d0630 18899
5f4273c7 18900/* Generate any deferred unwind frame offset. */
e45d0630 18901
bfae80f2 18902static void
c19d1205 18903flush_pending_unwind (void)
bfae80f2 18904{
c19d1205 18905 offsetT offset;
bfae80f2 18906
c19d1205
ZW
18907 offset = unwind.pending_offset;
18908 unwind.pending_offset = 0;
18909 if (offset != 0)
18910 add_unwind_adjustsp (offset);
bfae80f2
RE
18911}
18912
c19d1205
ZW
18913/* Add an opcode to this list for this function. Two-byte opcodes should
18914 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18915 order. */
18916
bfae80f2 18917static void
c19d1205 18918add_unwind_opcode (valueT op, int length)
bfae80f2 18919{
c19d1205
ZW
18920 /* Add any deferred stack adjustment. */
18921 if (unwind.pending_offset)
18922 flush_pending_unwind ();
bfae80f2 18923
c19d1205 18924 unwind.sp_restored = 0;
bfae80f2 18925
c19d1205 18926 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18927 {
c19d1205
ZW
18928 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18929 if (unwind.opcodes)
21d799b5
NC
18930 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18931 unwind.opcode_alloc);
c19d1205 18932 else
21d799b5 18933 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 18934 }
c19d1205 18935 while (length > 0)
bfae80f2 18936 {
c19d1205
ZW
18937 length--;
18938 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18939 op >>= 8;
18940 unwind.opcode_count++;
bfae80f2 18941 }
bfae80f2
RE
18942}
18943
c19d1205
ZW
18944/* Add unwind opcodes to adjust the stack pointer. */
18945
bfae80f2 18946static void
c19d1205 18947add_unwind_adjustsp (offsetT offset)
bfae80f2 18948{
c19d1205 18949 valueT op;
bfae80f2 18950
c19d1205 18951 if (offset > 0x200)
bfae80f2 18952 {
c19d1205
ZW
18953 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18954 char bytes[5];
18955 int n;
18956 valueT o;
bfae80f2 18957
c19d1205
ZW
18958 /* Long form: 0xb2, uleb128. */
18959 /* This might not fit in a word so add the individual bytes,
18960 remembering the list is built in reverse order. */
18961 o = (valueT) ((offset - 0x204) >> 2);
18962 if (o == 0)
18963 add_unwind_opcode (0, 1);
bfae80f2 18964
c19d1205
ZW
18965 /* Calculate the uleb128 encoding of the offset. */
18966 n = 0;
18967 while (o)
18968 {
18969 bytes[n] = o & 0x7f;
18970 o >>= 7;
18971 if (o)
18972 bytes[n] |= 0x80;
18973 n++;
18974 }
18975 /* Add the insn. */
18976 for (; n; n--)
18977 add_unwind_opcode (bytes[n - 1], 1);
18978 add_unwind_opcode (0xb2, 1);
18979 }
18980 else if (offset > 0x100)
bfae80f2 18981 {
c19d1205
ZW
18982 /* Two short opcodes. */
18983 add_unwind_opcode (0x3f, 1);
18984 op = (offset - 0x104) >> 2;
18985 add_unwind_opcode (op, 1);
bfae80f2 18986 }
c19d1205
ZW
18987 else if (offset > 0)
18988 {
18989 /* Short opcode. */
18990 op = (offset - 4) >> 2;
18991 add_unwind_opcode (op, 1);
18992 }
18993 else if (offset < 0)
bfae80f2 18994 {
c19d1205
ZW
18995 offset = -offset;
18996 while (offset > 0x100)
bfae80f2 18997 {
c19d1205
ZW
18998 add_unwind_opcode (0x7f, 1);
18999 offset -= 0x100;
bfae80f2 19000 }
c19d1205
ZW
19001 op = ((offset - 4) >> 2) | 0x40;
19002 add_unwind_opcode (op, 1);
bfae80f2 19003 }
bfae80f2
RE
19004}
19005
c19d1205
ZW
19006/* Finish the list of unwind opcodes for this function. */
19007static void
19008finish_unwind_opcodes (void)
bfae80f2 19009{
c19d1205 19010 valueT op;
bfae80f2 19011
c19d1205 19012 if (unwind.fp_used)
bfae80f2 19013 {
708587a4 19014 /* Adjust sp as necessary. */
c19d1205
ZW
19015 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19016 flush_pending_unwind ();
bfae80f2 19017
c19d1205
ZW
19018 /* After restoring sp from the frame pointer. */
19019 op = 0x90 | unwind.fp_reg;
19020 add_unwind_opcode (op, 1);
19021 }
19022 else
19023 flush_pending_unwind ();
bfae80f2
RE
19024}
19025
bfae80f2 19026
c19d1205
ZW
19027/* Start an exception table entry. If idx is nonzero this is an index table
19028 entry. */
bfae80f2
RE
19029
19030static void
c19d1205 19031start_unwind_section (const segT text_seg, int idx)
bfae80f2 19032{
c19d1205
ZW
19033 const char * text_name;
19034 const char * prefix;
19035 const char * prefix_once;
19036 const char * group_name;
19037 size_t prefix_len;
19038 size_t text_len;
19039 char * sec_name;
19040 size_t sec_name_len;
19041 int type;
19042 int flags;
19043 int linkonce;
bfae80f2 19044
c19d1205 19045 if (idx)
bfae80f2 19046 {
c19d1205
ZW
19047 prefix = ELF_STRING_ARM_unwind;
19048 prefix_once = ELF_STRING_ARM_unwind_once;
19049 type = SHT_ARM_EXIDX;
bfae80f2 19050 }
c19d1205 19051 else
bfae80f2 19052 {
c19d1205
ZW
19053 prefix = ELF_STRING_ARM_unwind_info;
19054 prefix_once = ELF_STRING_ARM_unwind_info_once;
19055 type = SHT_PROGBITS;
bfae80f2
RE
19056 }
19057
c19d1205
ZW
19058 text_name = segment_name (text_seg);
19059 if (streq (text_name, ".text"))
19060 text_name = "";
19061
19062 if (strncmp (text_name, ".gnu.linkonce.t.",
19063 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 19064 {
c19d1205
ZW
19065 prefix = prefix_once;
19066 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
19067 }
19068
c19d1205
ZW
19069 prefix_len = strlen (prefix);
19070 text_len = strlen (text_name);
19071 sec_name_len = prefix_len + text_len;
21d799b5 19072 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
19073 memcpy (sec_name, prefix, prefix_len);
19074 memcpy (sec_name + prefix_len, text_name, text_len);
19075 sec_name[prefix_len + text_len] = '\0';
bfae80f2 19076
c19d1205
ZW
19077 flags = SHF_ALLOC;
19078 linkonce = 0;
19079 group_name = 0;
bfae80f2 19080
c19d1205
ZW
19081 /* Handle COMDAT group. */
19082 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 19083 {
c19d1205
ZW
19084 group_name = elf_group_name (text_seg);
19085 if (group_name == NULL)
19086 {
bd3ba5d1 19087 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
19088 segment_name (text_seg));
19089 ignore_rest_of_line ();
19090 return;
19091 }
19092 flags |= SHF_GROUP;
19093 linkonce = 1;
bfae80f2
RE
19094 }
19095
c19d1205 19096 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 19097
5f4273c7 19098 /* Set the section link for index tables. */
c19d1205
ZW
19099 if (idx)
19100 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
19101}
19102
bfae80f2 19103
c19d1205
ZW
19104/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19105 personality routine data. Returns zero, or the index table value for
19106 and inline entry. */
19107
19108static valueT
19109create_unwind_entry (int have_data)
bfae80f2 19110{
c19d1205
ZW
19111 int size;
19112 addressT where;
19113 char *ptr;
19114 /* The current word of data. */
19115 valueT data;
19116 /* The number of bytes left in this word. */
19117 int n;
bfae80f2 19118
c19d1205 19119 finish_unwind_opcodes ();
bfae80f2 19120
c19d1205
ZW
19121 /* Remember the current text section. */
19122 unwind.saved_seg = now_seg;
19123 unwind.saved_subseg = now_subseg;
bfae80f2 19124
c19d1205 19125 start_unwind_section (now_seg, 0);
bfae80f2 19126
c19d1205 19127 if (unwind.personality_routine == NULL)
bfae80f2 19128 {
c19d1205
ZW
19129 if (unwind.personality_index == -2)
19130 {
19131 if (have_data)
5f4273c7 19132 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
19133 return 1; /* EXIDX_CANTUNWIND. */
19134 }
bfae80f2 19135
c19d1205
ZW
19136 /* Use a default personality routine if none is specified. */
19137 if (unwind.personality_index == -1)
19138 {
19139 if (unwind.opcode_count > 3)
19140 unwind.personality_index = 1;
19141 else
19142 unwind.personality_index = 0;
19143 }
bfae80f2 19144
c19d1205
ZW
19145 /* Space for the personality routine entry. */
19146 if (unwind.personality_index == 0)
19147 {
19148 if (unwind.opcode_count > 3)
19149 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 19150
c19d1205
ZW
19151 if (!have_data)
19152 {
19153 /* All the data is inline in the index table. */
19154 data = 0x80;
19155 n = 3;
19156 while (unwind.opcode_count > 0)
19157 {
19158 unwind.opcode_count--;
19159 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19160 n--;
19161 }
bfae80f2 19162
c19d1205
ZW
19163 /* Pad with "finish" opcodes. */
19164 while (n--)
19165 data = (data << 8) | 0xb0;
bfae80f2 19166
c19d1205
ZW
19167 return data;
19168 }
19169 size = 0;
19170 }
19171 else
19172 /* We get two opcodes "free" in the first word. */
19173 size = unwind.opcode_count - 2;
19174 }
19175 else
19176 /* An extra byte is required for the opcode count. */
19177 size = unwind.opcode_count + 1;
bfae80f2 19178
c19d1205
ZW
19179 size = (size + 3) >> 2;
19180 if (size > 0xff)
19181 as_bad (_("too many unwind opcodes"));
bfae80f2 19182
c19d1205
ZW
19183 frag_align (2, 0, 0);
19184 record_alignment (now_seg, 2);
19185 unwind.table_entry = expr_build_dot ();
19186
19187 /* Allocate the table entry. */
19188 ptr = frag_more ((size << 2) + 4);
19189 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19190
c19d1205 19191 switch (unwind.personality_index)
bfae80f2 19192 {
c19d1205
ZW
19193 case -1:
19194 /* ??? Should this be a PLT generating relocation? */
19195 /* Custom personality routine. */
19196 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19197 BFD_RELOC_ARM_PREL31);
bfae80f2 19198
c19d1205
ZW
19199 where += 4;
19200 ptr += 4;
bfae80f2 19201
c19d1205
ZW
19202 /* Set the first byte to the number of additional words. */
19203 data = size - 1;
19204 n = 3;
19205 break;
bfae80f2 19206
c19d1205
ZW
19207 /* ABI defined personality routines. */
19208 case 0:
19209 /* Three opcodes bytes are packed into the first word. */
19210 data = 0x80;
19211 n = 3;
19212 break;
bfae80f2 19213
c19d1205
ZW
19214 case 1:
19215 case 2:
19216 /* The size and first two opcode bytes go in the first word. */
19217 data = ((0x80 + unwind.personality_index) << 8) | size;
19218 n = 2;
19219 break;
bfae80f2 19220
c19d1205
ZW
19221 default:
19222 /* Should never happen. */
19223 abort ();
19224 }
bfae80f2 19225
c19d1205
ZW
19226 /* Pack the opcodes into words (MSB first), reversing the list at the same
19227 time. */
19228 while (unwind.opcode_count > 0)
19229 {
19230 if (n == 0)
19231 {
19232 md_number_to_chars (ptr, data, 4);
19233 ptr += 4;
19234 n = 4;
19235 data = 0;
19236 }
19237 unwind.opcode_count--;
19238 n--;
19239 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19240 }
19241
19242 /* Finish off the last word. */
19243 if (n < 4)
19244 {
19245 /* Pad with "finish" opcodes. */
19246 while (n--)
19247 data = (data << 8) | 0xb0;
19248
19249 md_number_to_chars (ptr, data, 4);
19250 }
19251
19252 if (!have_data)
19253 {
19254 /* Add an empty descriptor if there is no user-specified data. */
19255 ptr = frag_more (4);
19256 md_number_to_chars (ptr, 0, 4);
19257 }
19258
19259 return 0;
bfae80f2
RE
19260}
19261
f0927246
NC
19262
19263/* Initialize the DWARF-2 unwind information for this procedure. */
19264
19265void
19266tc_arm_frame_initial_instructions (void)
19267{
19268 cfi_add_CFA_def_cfa (REG_SP, 0);
19269}
19270#endif /* OBJ_ELF */
19271
c19d1205
ZW
19272/* Convert REGNAME to a DWARF-2 register number. */
19273
19274int
1df69f4f 19275tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19276{
1df69f4f 19277 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19278
19279 if (reg == FAIL)
19280 return -1;
19281
19282 return reg;
bfae80f2
RE
19283}
19284
f0927246 19285#ifdef TE_PE
c19d1205 19286void
f0927246 19287tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19288{
91d6fa6a 19289 expressionS exp;
bfae80f2 19290
91d6fa6a
NC
19291 exp.X_op = O_secrel;
19292 exp.X_add_symbol = symbol;
19293 exp.X_add_number = 0;
19294 emit_expr (&exp, size);
f0927246
NC
19295}
19296#endif
bfae80f2 19297
c19d1205 19298/* MD interface: Symbol and relocation handling. */
bfae80f2 19299
2fc8bdac
ZW
19300/* Return the address within the segment that a PC-relative fixup is
19301 relative to. For ARM, PC-relative fixups applied to instructions
19302 are generally relative to the location of the fixup plus 8 bytes.
19303 Thumb branches are offset by 4, and Thumb loads relative to PC
19304 require special handling. */
bfae80f2 19305
c19d1205 19306long
2fc8bdac 19307md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19308{
2fc8bdac
ZW
19309 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19310
19311 /* If this is pc-relative and we are going to emit a relocation
19312 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19313 will need. Otherwise we want to use the calculated base.
19314 For WinCE we skip the bias for externals as well, since this
19315 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19316 if (fixP->fx_pcrel
2fc8bdac 19317 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19318 || (arm_force_relocation (fixP)
19319#ifdef TE_WINCE
19320 && !S_IS_EXTERNAL (fixP->fx_addsy)
19321#endif
19322 )))
2fc8bdac 19323 base = 0;
bfae80f2 19324
267bf995 19325
c19d1205 19326 switch (fixP->fx_r_type)
bfae80f2 19327 {
2fc8bdac
ZW
19328 /* PC relative addressing on the Thumb is slightly odd as the
19329 bottom two bits of the PC are forced to zero for the
19330 calculation. This happens *after* application of the
19331 pipeline offset. However, Thumb adrl already adjusts for
19332 this, so we need not do it again. */
c19d1205 19333 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19334 return base & ~3;
c19d1205
ZW
19335
19336 case BFD_RELOC_ARM_THUMB_OFFSET:
19337 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19338 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19339 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19340 return (base + 4) & ~3;
c19d1205 19341
2fc8bdac
ZW
19342 /* Thumb branches are simply offset by +4. */
19343 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19344 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19345 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19346 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19347 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19348 return base + 4;
bfae80f2 19349
267bf995 19350 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
19351 if (fixP->fx_addsy
19352 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19353 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19354 && ARM_IS_FUNC (fixP->fx_addsy)
19355 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19356 base = fixP->fx_where + fixP->fx_frag->fr_address;
19357 return base + 4;
19358
00adf2d4
JB
19359 /* BLX is like branches above, but forces the low two bits of PC to
19360 zero. */
486499d0
CL
19361 case BFD_RELOC_THUMB_PCREL_BLX:
19362 if (fixP->fx_addsy
19363 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19364 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19365 && THUMB_IS_FUNC (fixP->fx_addsy)
19366 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19367 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19368 return (base + 4) & ~3;
19369
2fc8bdac
ZW
19370 /* ARM mode branches are offset by +8. However, the Windows CE
19371 loader expects the relocation not to take this into account. */
267bf995 19372 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
19373 if (fixP->fx_addsy
19374 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19375 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19376 && ARM_IS_FUNC (fixP->fx_addsy)
19377 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19378 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19379 return base + 8;
267bf995 19380
486499d0
CL
19381 case BFD_RELOC_ARM_PCREL_CALL:
19382 if (fixP->fx_addsy
19383 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19384 && (!S_IS_EXTERNAL (fixP->fx_addsy))
267bf995
RR
19385 && THUMB_IS_FUNC (fixP->fx_addsy)
19386 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19387 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 19388 return base + 8;
267bf995 19389
2fc8bdac 19390 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19391 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19392 case BFD_RELOC_ARM_PLT32:
c19d1205 19393#ifdef TE_WINCE
5f4273c7 19394 /* When handling fixups immediately, because we have already
53baae48
NC
19395 discovered the value of a symbol, or the address of the frag involved
19396 we must account for the offset by +8, as the OS loader will never see the reloc.
19397 see fixup_segment() in write.c
19398 The S_IS_EXTERNAL test handles the case of global symbols.
19399 Those need the calculated base, not just the pipe compensation the linker will need. */
19400 if (fixP->fx_pcrel
19401 && fixP->fx_addsy != NULL
19402 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19403 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19404 return base + 8;
2fc8bdac 19405 return base;
c19d1205 19406#else
2fc8bdac 19407 return base + 8;
c19d1205 19408#endif
2fc8bdac 19409
267bf995 19410
2fc8bdac
ZW
19411 /* ARM mode loads relative to PC are also offset by +8. Unlike
19412 branches, the Windows CE loader *does* expect the relocation
19413 to take this into account. */
19414 case BFD_RELOC_ARM_OFFSET_IMM:
19415 case BFD_RELOC_ARM_OFFSET_IMM8:
19416 case BFD_RELOC_ARM_HWLITERAL:
19417 case BFD_RELOC_ARM_LITERAL:
19418 case BFD_RELOC_ARM_CP_OFF_IMM:
19419 return base + 8;
19420
19421
19422 /* Other PC-relative relocations are un-offset. */
19423 default:
19424 return base;
19425 }
bfae80f2
RE
19426}
19427
c19d1205
ZW
19428/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19429 Otherwise we have no need to default values of symbols. */
19430
19431symbolS *
19432md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19433{
c19d1205
ZW
19434#ifdef OBJ_ELF
19435 if (name[0] == '_' && name[1] == 'G'
19436 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19437 {
19438 if (!GOT_symbol)
19439 {
19440 if (symbol_find (name))
bd3ba5d1 19441 as_bad (_("GOT already in the symbol table"));
bfae80f2 19442
c19d1205
ZW
19443 GOT_symbol = symbol_new (name, undefined_section,
19444 (valueT) 0, & zero_address_frag);
19445 }
bfae80f2 19446
c19d1205 19447 return GOT_symbol;
bfae80f2 19448 }
c19d1205 19449#endif
bfae80f2 19450
c921be7d 19451 return NULL;
bfae80f2
RE
19452}
19453
55cf6793 19454/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19455 computed as two separate immediate values, added together. We
19456 already know that this value cannot be computed by just one ARM
19457 instruction. */
19458
19459static unsigned int
19460validate_immediate_twopart (unsigned int val,
19461 unsigned int * highpart)
bfae80f2 19462{
c19d1205
ZW
19463 unsigned int a;
19464 unsigned int i;
bfae80f2 19465
c19d1205
ZW
19466 for (i = 0; i < 32; i += 2)
19467 if (((a = rotate_left (val, i)) & 0xff) != 0)
19468 {
19469 if (a & 0xff00)
19470 {
19471 if (a & ~ 0xffff)
19472 continue;
19473 * highpart = (a >> 8) | ((i + 24) << 7);
19474 }
19475 else if (a & 0xff0000)
19476 {
19477 if (a & 0xff000000)
19478 continue;
19479 * highpart = (a >> 16) | ((i + 16) << 7);
19480 }
19481 else
19482 {
9c2799c2 19483 gas_assert (a & 0xff000000);
c19d1205
ZW
19484 * highpart = (a >> 24) | ((i + 8) << 7);
19485 }
bfae80f2 19486
c19d1205
ZW
19487 return (a & 0xff) | (i << 7);
19488 }
bfae80f2 19489
c19d1205 19490 return FAIL;
bfae80f2
RE
19491}
19492
c19d1205
ZW
19493static int
19494validate_offset_imm (unsigned int val, int hwse)
19495{
19496 if ((hwse && val > 255) || val > 4095)
19497 return FAIL;
19498 return val;
19499}
bfae80f2 19500
55cf6793 19501/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19502 negative immediate constant by altering the instruction. A bit of
19503 a hack really.
19504 MOV <-> MVN
19505 AND <-> BIC
19506 ADC <-> SBC
19507 by inverting the second operand, and
19508 ADD <-> SUB
19509 CMP <-> CMN
19510 by negating the second operand. */
bfae80f2 19511
c19d1205
ZW
19512static int
19513negate_data_op (unsigned long * instruction,
19514 unsigned long value)
bfae80f2 19515{
c19d1205
ZW
19516 int op, new_inst;
19517 unsigned long negated, inverted;
bfae80f2 19518
c19d1205
ZW
19519 negated = encode_arm_immediate (-value);
19520 inverted = encode_arm_immediate (~value);
bfae80f2 19521
c19d1205
ZW
19522 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19523 switch (op)
bfae80f2 19524 {
c19d1205
ZW
19525 /* First negates. */
19526 case OPCODE_SUB: /* ADD <-> SUB */
19527 new_inst = OPCODE_ADD;
19528 value = negated;
19529 break;
bfae80f2 19530
c19d1205
ZW
19531 case OPCODE_ADD:
19532 new_inst = OPCODE_SUB;
19533 value = negated;
19534 break;
bfae80f2 19535
c19d1205
ZW
19536 case OPCODE_CMP: /* CMP <-> CMN */
19537 new_inst = OPCODE_CMN;
19538 value = negated;
19539 break;
bfae80f2 19540
c19d1205
ZW
19541 case OPCODE_CMN:
19542 new_inst = OPCODE_CMP;
19543 value = negated;
19544 break;
bfae80f2 19545
c19d1205
ZW
19546 /* Now Inverted ops. */
19547 case OPCODE_MOV: /* MOV <-> MVN */
19548 new_inst = OPCODE_MVN;
19549 value = inverted;
19550 break;
bfae80f2 19551
c19d1205
ZW
19552 case OPCODE_MVN:
19553 new_inst = OPCODE_MOV;
19554 value = inverted;
19555 break;
bfae80f2 19556
c19d1205
ZW
19557 case OPCODE_AND: /* AND <-> BIC */
19558 new_inst = OPCODE_BIC;
19559 value = inverted;
19560 break;
bfae80f2 19561
c19d1205
ZW
19562 case OPCODE_BIC:
19563 new_inst = OPCODE_AND;
19564 value = inverted;
19565 break;
bfae80f2 19566
c19d1205
ZW
19567 case OPCODE_ADC: /* ADC <-> SBC */
19568 new_inst = OPCODE_SBC;
19569 value = inverted;
19570 break;
bfae80f2 19571
c19d1205
ZW
19572 case OPCODE_SBC:
19573 new_inst = OPCODE_ADC;
19574 value = inverted;
19575 break;
bfae80f2 19576
c19d1205
ZW
19577 /* We cannot do anything. */
19578 default:
19579 return FAIL;
b99bd4ef
NC
19580 }
19581
c19d1205
ZW
19582 if (value == (unsigned) FAIL)
19583 return FAIL;
19584
19585 *instruction &= OPCODE_MASK;
19586 *instruction |= new_inst << DATA_OP_SHIFT;
19587 return value;
b99bd4ef
NC
19588}
19589
ef8d22e6
PB
19590/* Like negate_data_op, but for Thumb-2. */
19591
19592static unsigned int
16dd5e42 19593thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19594{
19595 int op, new_inst;
19596 int rd;
16dd5e42 19597 unsigned int negated, inverted;
ef8d22e6
PB
19598
19599 negated = encode_thumb32_immediate (-value);
19600 inverted = encode_thumb32_immediate (~value);
19601
19602 rd = (*instruction >> 8) & 0xf;
19603 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19604 switch (op)
19605 {
19606 /* ADD <-> SUB. Includes CMP <-> CMN. */
19607 case T2_OPCODE_SUB:
19608 new_inst = T2_OPCODE_ADD;
19609 value = negated;
19610 break;
19611
19612 case T2_OPCODE_ADD:
19613 new_inst = T2_OPCODE_SUB;
19614 value = negated;
19615 break;
19616
19617 /* ORR <-> ORN. Includes MOV <-> MVN. */
19618 case T2_OPCODE_ORR:
19619 new_inst = T2_OPCODE_ORN;
19620 value = inverted;
19621 break;
19622
19623 case T2_OPCODE_ORN:
19624 new_inst = T2_OPCODE_ORR;
19625 value = inverted;
19626 break;
19627
19628 /* AND <-> BIC. TST has no inverted equivalent. */
19629 case T2_OPCODE_AND:
19630 new_inst = T2_OPCODE_BIC;
19631 if (rd == 15)
19632 value = FAIL;
19633 else
19634 value = inverted;
19635 break;
19636
19637 case T2_OPCODE_BIC:
19638 new_inst = T2_OPCODE_AND;
19639 value = inverted;
19640 break;
19641
19642 /* ADC <-> SBC */
19643 case T2_OPCODE_ADC:
19644 new_inst = T2_OPCODE_SBC;
19645 value = inverted;
19646 break;
19647
19648 case T2_OPCODE_SBC:
19649 new_inst = T2_OPCODE_ADC;
19650 value = inverted;
19651 break;
19652
19653 /* We cannot do anything. */
19654 default:
19655 return FAIL;
19656 }
19657
16dd5e42 19658 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19659 return FAIL;
19660
19661 *instruction &= T2_OPCODE_MASK;
19662 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19663 return value;
19664}
19665
8f06b2d8
PB
19666/* Read a 32-bit thumb instruction from buf. */
19667static unsigned long
19668get_thumb32_insn (char * buf)
19669{
19670 unsigned long insn;
19671 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19672 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19673
19674 return insn;
19675}
19676
a8bc6c78
PB
19677
19678/* We usually want to set the low bit on the address of thumb function
19679 symbols. In particular .word foo - . should have the low bit set.
19680 Generic code tries to fold the difference of two symbols to
19681 a constant. Prevent this and force a relocation when the first symbols
19682 is a thumb function. */
c921be7d
NC
19683
19684bfd_boolean
a8bc6c78
PB
19685arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19686{
19687 if (op == O_subtract
19688 && l->X_op == O_symbol
19689 && r->X_op == O_symbol
19690 && THUMB_IS_FUNC (l->X_add_symbol))
19691 {
19692 l->X_op = O_subtract;
19693 l->X_op_symbol = r->X_add_symbol;
19694 l->X_add_number -= r->X_add_number;
c921be7d 19695 return TRUE;
a8bc6c78 19696 }
c921be7d 19697
a8bc6c78 19698 /* Process as normal. */
c921be7d 19699 return FALSE;
a8bc6c78
PB
19700}
19701
4a42ebbc
RR
19702/* Encode Thumb2 unconditional branches and calls. The encoding
19703 for the 2 are identical for the immediate values. */
19704
19705static void
19706encode_thumb2_b_bl_offset (char * buf, offsetT value)
19707{
19708#define T2I1I2MASK ((1 << 13) | (1 << 11))
19709 offsetT newval;
19710 offsetT newval2;
19711 addressT S, I1, I2, lo, hi;
19712
19713 S = (value >> 24) & 0x01;
19714 I1 = (value >> 23) & 0x01;
19715 I2 = (value >> 22) & 0x01;
19716 hi = (value >> 12) & 0x3ff;
19717 lo = (value >> 1) & 0x7ff;
19718 newval = md_chars_to_number (buf, THUMB_SIZE);
19719 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19720 newval |= (S << 10) | hi;
19721 newval2 &= ~T2I1I2MASK;
19722 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19723 md_number_to_chars (buf, newval, THUMB_SIZE);
19724 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19725}
19726
c19d1205 19727void
55cf6793 19728md_apply_fix (fixS * fixP,
c19d1205
ZW
19729 valueT * valP,
19730 segT seg)
19731{
19732 offsetT value = * valP;
19733 offsetT newval;
19734 unsigned int newimm;
19735 unsigned long temp;
19736 int sign;
19737 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19738
9c2799c2 19739 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19740
c19d1205 19741 /* Note whether this will delete the relocation. */
4962c51a 19742
c19d1205
ZW
19743 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19744 fixP->fx_done = 1;
b99bd4ef 19745
adbaf948 19746 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19747 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19748 for emit_reloc. */
19749 value &= 0xffffffff;
19750 value ^= 0x80000000;
5f4273c7 19751 value -= 0x80000000;
adbaf948
ZW
19752
19753 *valP = value;
c19d1205 19754 fixP->fx_addnumber = value;
b99bd4ef 19755
adbaf948
ZW
19756 /* Same treatment for fixP->fx_offset. */
19757 fixP->fx_offset &= 0xffffffff;
19758 fixP->fx_offset ^= 0x80000000;
19759 fixP->fx_offset -= 0x80000000;
19760
c19d1205 19761 switch (fixP->fx_r_type)
b99bd4ef 19762 {
c19d1205
ZW
19763 case BFD_RELOC_NONE:
19764 /* This will need to go in the object file. */
19765 fixP->fx_done = 0;
19766 break;
b99bd4ef 19767
c19d1205
ZW
19768 case BFD_RELOC_ARM_IMMEDIATE:
19769 /* We claim that this fixup has been processed here,
19770 even if in fact we generate an error because we do
19771 not have a reloc for it, so tc_gen_reloc will reject it. */
19772 fixP->fx_done = 1;
b99bd4ef 19773
c19d1205
ZW
19774 if (fixP->fx_addsy
19775 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 19776 {
c19d1205
ZW
19777 as_bad_where (fixP->fx_file, fixP->fx_line,
19778 _("undefined symbol %s used as an immediate value"),
19779 S_GET_NAME (fixP->fx_addsy));
19780 break;
b99bd4ef
NC
19781 }
19782
42e5fcbf
AS
19783 if (fixP->fx_addsy
19784 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19785 {
19786 as_bad_where (fixP->fx_file, fixP->fx_line,
19787 _("symbol %s is in a different section"),
19788 S_GET_NAME (fixP->fx_addsy));
19789 break;
19790 }
19791
c19d1205
ZW
19792 newimm = encode_arm_immediate (value);
19793 temp = md_chars_to_number (buf, INSN_SIZE);
19794
19795 /* If the instruction will fail, see if we can fix things up by
19796 changing the opcode. */
19797 if (newimm == (unsigned int) FAIL
19798 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19799 {
c19d1205
ZW
19800 as_bad_where (fixP->fx_file, fixP->fx_line,
19801 _("invalid constant (%lx) after fixup"),
19802 (unsigned long) value);
19803 break;
b99bd4ef 19804 }
b99bd4ef 19805
c19d1205
ZW
19806 newimm |= (temp & 0xfffff000);
19807 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19808 break;
b99bd4ef 19809
c19d1205
ZW
19810 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19811 {
19812 unsigned int highpart = 0;
19813 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19814
42e5fcbf
AS
19815 if (fixP->fx_addsy
19816 && ! S_IS_DEFINED (fixP->fx_addsy))
19817 {
19818 as_bad_where (fixP->fx_file, fixP->fx_line,
19819 _("undefined symbol %s used as an immediate value"),
19820 S_GET_NAME (fixP->fx_addsy));
19821 break;
19822 }
19823
19824 if (fixP->fx_addsy
19825 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19826 {
19827 as_bad_where (fixP->fx_file, fixP->fx_line,
19828 _("symbol %s is in a different section"),
19829 S_GET_NAME (fixP->fx_addsy));
19830 break;
19831 }
19832
c19d1205
ZW
19833 newimm = encode_arm_immediate (value);
19834 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19835
c19d1205
ZW
19836 /* If the instruction will fail, see if we can fix things up by
19837 changing the opcode. */
19838 if (newimm == (unsigned int) FAIL
19839 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19840 {
19841 /* No ? OK - try using two ADD instructions to generate
19842 the value. */
19843 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19844
c19d1205
ZW
19845 /* Yes - then make sure that the second instruction is
19846 also an add. */
19847 if (newimm != (unsigned int) FAIL)
19848 newinsn = temp;
19849 /* Still No ? Try using a negated value. */
19850 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19851 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19852 /* Otherwise - give up. */
19853 else
19854 {
19855 as_bad_where (fixP->fx_file, fixP->fx_line,
19856 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19857 (long) value);
19858 break;
19859 }
b99bd4ef 19860
c19d1205
ZW
19861 /* Replace the first operand in the 2nd instruction (which
19862 is the PC) with the destination register. We have
19863 already added in the PC in the first instruction and we
19864 do not want to do it again. */
19865 newinsn &= ~ 0xf0000;
19866 newinsn |= ((newinsn & 0x0f000) << 4);
19867 }
b99bd4ef 19868
c19d1205
ZW
19869 newimm |= (temp & 0xfffff000);
19870 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19871
c19d1205
ZW
19872 highpart |= (newinsn & 0xfffff000);
19873 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19874 }
19875 break;
b99bd4ef 19876
c19d1205 19877 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19878 if (!fixP->fx_done && seg->use_rela_p)
19879 value = 0;
19880
c19d1205
ZW
19881 case BFD_RELOC_ARM_LITERAL:
19882 sign = value >= 0;
b99bd4ef 19883
c19d1205
ZW
19884 if (value < 0)
19885 value = - value;
b99bd4ef 19886
c19d1205 19887 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19888 {
c19d1205
ZW
19889 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19890 as_bad_where (fixP->fx_file, fixP->fx_line,
19891 _("invalid literal constant: pool needs to be closer"));
19892 else
19893 as_bad_where (fixP->fx_file, fixP->fx_line,
19894 _("bad immediate value for offset (%ld)"),
19895 (long) value);
19896 break;
f03698e6
RE
19897 }
19898
c19d1205
ZW
19899 newval = md_chars_to_number (buf, INSN_SIZE);
19900 newval &= 0xff7ff000;
19901 newval |= value | (sign ? INDEX_UP : 0);
19902 md_number_to_chars (buf, newval, INSN_SIZE);
19903 break;
b99bd4ef 19904
c19d1205
ZW
19905 case BFD_RELOC_ARM_OFFSET_IMM8:
19906 case BFD_RELOC_ARM_HWLITERAL:
19907 sign = value >= 0;
b99bd4ef 19908
c19d1205
ZW
19909 if (value < 0)
19910 value = - value;
b99bd4ef 19911
c19d1205 19912 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19913 {
c19d1205
ZW
19914 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19915 as_bad_where (fixP->fx_file, fixP->fx_line,
19916 _("invalid literal constant: pool needs to be closer"));
19917 else
f9d4405b 19918 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19919 (long) value);
19920 break;
b99bd4ef
NC
19921 }
19922
c19d1205
ZW
19923 newval = md_chars_to_number (buf, INSN_SIZE);
19924 newval &= 0xff7ff0f0;
19925 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19926 md_number_to_chars (buf, newval, INSN_SIZE);
19927 break;
b99bd4ef 19928
c19d1205
ZW
19929 case BFD_RELOC_ARM_T32_OFFSET_U8:
19930 if (value < 0 || value > 1020 || value % 4 != 0)
19931 as_bad_where (fixP->fx_file, fixP->fx_line,
19932 _("bad immediate value for offset (%ld)"), (long) value);
19933 value /= 4;
b99bd4ef 19934
c19d1205 19935 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19936 newval |= value;
19937 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19938 break;
b99bd4ef 19939
c19d1205
ZW
19940 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19941 /* This is a complicated relocation used for all varieties of Thumb32
19942 load/store instruction with immediate offset:
19943
19944 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19945 *4, optional writeback(W)
19946 (doubleword load/store)
19947
19948 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19949 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19950 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19951 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19952 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19953
19954 Uppercase letters indicate bits that are already encoded at
19955 this point. Lowercase letters are our problem. For the
19956 second block of instructions, the secondary opcode nybble
19957 (bits 8..11) is present, and bit 23 is zero, even if this is
19958 a PC-relative operation. */
19959 newval = md_chars_to_number (buf, THUMB_SIZE);
19960 newval <<= 16;
19961 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19962
c19d1205 19963 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19964 {
c19d1205
ZW
19965 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19966 if (value >= 0)
19967 newval |= (1 << 23);
19968 else
19969 value = -value;
19970 if (value % 4 != 0)
19971 {
19972 as_bad_where (fixP->fx_file, fixP->fx_line,
19973 _("offset not a multiple of 4"));
19974 break;
19975 }
19976 value /= 4;
216d22bc 19977 if (value > 0xff)
c19d1205
ZW
19978 {
19979 as_bad_where (fixP->fx_file, fixP->fx_line,
19980 _("offset out of range"));
19981 break;
19982 }
19983 newval &= ~0xff;
b99bd4ef 19984 }
c19d1205 19985 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 19986 {
c19d1205
ZW
19987 /* PC-relative, 12-bit offset. */
19988 if (value >= 0)
19989 newval |= (1 << 23);
19990 else
19991 value = -value;
216d22bc 19992 if (value > 0xfff)
c19d1205
ZW
19993 {
19994 as_bad_where (fixP->fx_file, fixP->fx_line,
19995 _("offset out of range"));
19996 break;
19997 }
19998 newval &= ~0xfff;
b99bd4ef 19999 }
c19d1205 20000 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 20001 {
c19d1205
ZW
20002 /* Writeback: 8-bit, +/- offset. */
20003 if (value >= 0)
20004 newval |= (1 << 9);
20005 else
20006 value = -value;
216d22bc 20007 if (value > 0xff)
c19d1205
ZW
20008 {
20009 as_bad_where (fixP->fx_file, fixP->fx_line,
20010 _("offset out of range"));
20011 break;
20012 }
20013 newval &= ~0xff;
b99bd4ef 20014 }
c19d1205 20015 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 20016 {
c19d1205 20017 /* T-instruction: positive 8-bit offset. */
216d22bc 20018 if (value < 0 || value > 0xff)
b99bd4ef 20019 {
c19d1205
ZW
20020 as_bad_where (fixP->fx_file, fixP->fx_line,
20021 _("offset out of range"));
20022 break;
b99bd4ef 20023 }
c19d1205
ZW
20024 newval &= ~0xff;
20025 newval |= value;
b99bd4ef
NC
20026 }
20027 else
b99bd4ef 20028 {
c19d1205
ZW
20029 /* Positive 12-bit or negative 8-bit offset. */
20030 int limit;
20031 if (value >= 0)
b99bd4ef 20032 {
c19d1205
ZW
20033 newval |= (1 << 23);
20034 limit = 0xfff;
20035 }
20036 else
20037 {
20038 value = -value;
20039 limit = 0xff;
20040 }
20041 if (value > limit)
20042 {
20043 as_bad_where (fixP->fx_file, fixP->fx_line,
20044 _("offset out of range"));
20045 break;
b99bd4ef 20046 }
c19d1205 20047 newval &= ~limit;
b99bd4ef 20048 }
b99bd4ef 20049
c19d1205
ZW
20050 newval |= value;
20051 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20052 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20053 break;
404ff6b5 20054
c19d1205
ZW
20055 case BFD_RELOC_ARM_SHIFT_IMM:
20056 newval = md_chars_to_number (buf, INSN_SIZE);
20057 if (((unsigned long) value) > 32
20058 || (value == 32
20059 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20060 {
20061 as_bad_where (fixP->fx_file, fixP->fx_line,
20062 _("shift expression is too large"));
20063 break;
20064 }
404ff6b5 20065
c19d1205
ZW
20066 if (value == 0)
20067 /* Shifts of zero must be done as lsl. */
20068 newval &= ~0x60;
20069 else if (value == 32)
20070 value = 0;
20071 newval &= 0xfffff07f;
20072 newval |= (value & 0x1f) << 7;
20073 md_number_to_chars (buf, newval, INSN_SIZE);
20074 break;
404ff6b5 20075
c19d1205 20076 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 20077 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 20078 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 20079 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
20080 /* We claim that this fixup has been processed here,
20081 even if in fact we generate an error because we do
20082 not have a reloc for it, so tc_gen_reloc will reject it. */
20083 fixP->fx_done = 1;
404ff6b5 20084
c19d1205
ZW
20085 if (fixP->fx_addsy
20086 && ! S_IS_DEFINED (fixP->fx_addsy))
20087 {
20088 as_bad_where (fixP->fx_file, fixP->fx_line,
20089 _("undefined symbol %s used as an immediate value"),
20090 S_GET_NAME (fixP->fx_addsy));
20091 break;
20092 }
404ff6b5 20093
c19d1205
ZW
20094 newval = md_chars_to_number (buf, THUMB_SIZE);
20095 newval <<= 16;
20096 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 20097
16805f35
PB
20098 newimm = FAIL;
20099 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20100 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
20101 {
20102 newimm = encode_thumb32_immediate (value);
20103 if (newimm == (unsigned int) FAIL)
20104 newimm = thumb32_negate_data_op (&newval, value);
20105 }
16805f35
PB
20106 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20107 && newimm == (unsigned int) FAIL)
92e90b6e 20108 {
16805f35
PB
20109 /* Turn add/sum into addw/subw. */
20110 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20111 newval = (newval & 0xfeffffff) | 0x02000000;
20112
e9f89963
PB
20113 /* 12 bit immediate for addw/subw. */
20114 if (value < 0)
20115 {
20116 value = -value;
20117 newval ^= 0x00a00000;
20118 }
92e90b6e
PB
20119 if (value > 0xfff)
20120 newimm = (unsigned int) FAIL;
20121 else
20122 newimm = value;
20123 }
cc8a6dd0 20124
c19d1205 20125 if (newimm == (unsigned int)FAIL)
3631a3c8 20126 {
c19d1205
ZW
20127 as_bad_where (fixP->fx_file, fixP->fx_line,
20128 _("invalid constant (%lx) after fixup"),
20129 (unsigned long) value);
20130 break;
3631a3c8
NC
20131 }
20132
c19d1205
ZW
20133 newval |= (newimm & 0x800) << 15;
20134 newval |= (newimm & 0x700) << 4;
20135 newval |= (newimm & 0x0ff);
cc8a6dd0 20136
c19d1205
ZW
20137 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20138 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20139 break;
a737bd4d 20140
3eb17e6b 20141 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
20142 if (((unsigned long) value) > 0xffff)
20143 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 20144 _("invalid smc expression"));
2fc8bdac 20145 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20146 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20147 md_number_to_chars (buf, newval, INSN_SIZE);
20148 break;
a737bd4d 20149
c19d1205 20150 case BFD_RELOC_ARM_SWI:
adbaf948 20151 if (fixP->tc_fix_data != 0)
c19d1205
ZW
20152 {
20153 if (((unsigned long) value) > 0xff)
20154 as_bad_where (fixP->fx_file, fixP->fx_line,
20155 _("invalid swi expression"));
2fc8bdac 20156 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
20157 newval |= value;
20158 md_number_to_chars (buf, newval, THUMB_SIZE);
20159 }
20160 else
20161 {
20162 if (((unsigned long) value) > 0x00ffffff)
20163 as_bad_where (fixP->fx_file, fixP->fx_line,
20164 _("invalid swi expression"));
2fc8bdac 20165 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
20166 newval |= value;
20167 md_number_to_chars (buf, newval, INSN_SIZE);
20168 }
20169 break;
a737bd4d 20170
c19d1205
ZW
20171 case BFD_RELOC_ARM_MULTI:
20172 if (((unsigned long) value) > 0xffff)
20173 as_bad_where (fixP->fx_file, fixP->fx_line,
20174 _("invalid expression in load/store multiple"));
20175 newval = value | md_chars_to_number (buf, INSN_SIZE);
20176 md_number_to_chars (buf, newval, INSN_SIZE);
20177 break;
a737bd4d 20178
c19d1205 20179#ifdef OBJ_ELF
39b41c9c 20180 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
20181
20182 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20183 && fixP->fx_addsy
20184 && !S_IS_EXTERNAL (fixP->fx_addsy)
20185 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20186 && THUMB_IS_FUNC (fixP->fx_addsy))
20187 /* Flip the bl to blx. This is a simple flip
20188 bit here because we generate PCREL_CALL for
20189 unconditional bls. */
20190 {
20191 newval = md_chars_to_number (buf, INSN_SIZE);
20192 newval = newval | 0x10000000;
20193 md_number_to_chars (buf, newval, INSN_SIZE);
20194 temp = 1;
20195 fixP->fx_done = 1;
20196 }
39b41c9c
PB
20197 else
20198 temp = 3;
20199 goto arm_branch_common;
20200
20201 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
20202 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20203 && fixP->fx_addsy
20204 && !S_IS_EXTERNAL (fixP->fx_addsy)
20205 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20206 && THUMB_IS_FUNC (fixP->fx_addsy))
20207 {
20208 /* This would map to a bl<cond>, b<cond>,
20209 b<always> to a Thumb function. We
20210 need to force a relocation for this particular
20211 case. */
20212 newval = md_chars_to_number (buf, INSN_SIZE);
20213 fixP->fx_done = 0;
20214 }
20215
2fc8bdac 20216 case BFD_RELOC_ARM_PLT32:
c19d1205 20217#endif
39b41c9c
PB
20218 case BFD_RELOC_ARM_PCREL_BRANCH:
20219 temp = 3;
20220 goto arm_branch_common;
a737bd4d 20221
39b41c9c 20222 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20223
39b41c9c 20224 temp = 1;
267bf995
RR
20225 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20226 && fixP->fx_addsy
20227 && !S_IS_EXTERNAL (fixP->fx_addsy)
20228 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20229 && ARM_IS_FUNC (fixP->fx_addsy))
20230 {
20231 /* Flip the blx to a bl and warn. */
20232 const char *name = S_GET_NAME (fixP->fx_addsy);
20233 newval = 0xeb000000;
20234 as_warn_where (fixP->fx_file, fixP->fx_line,
20235 _("blx to '%s' an ARM ISA state function changed to bl"),
20236 name);
20237 md_number_to_chars (buf, newval, INSN_SIZE);
20238 temp = 3;
20239 fixP->fx_done = 1;
20240 }
20241
20242#ifdef OBJ_ELF
20243 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20244 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20245#endif
20246
39b41c9c 20247 arm_branch_common:
c19d1205 20248 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20249 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20250 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20251 also be be clear. */
20252 if (value & temp)
c19d1205 20253 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20254 _("misaligned branch destination"));
20255 if ((value & (offsetT)0xfe000000) != (offsetT)0
20256 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20257 as_bad_where (fixP->fx_file, fixP->fx_line,
20258 _("branch out of range"));
a737bd4d 20259
2fc8bdac 20260 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20261 {
2fc8bdac
ZW
20262 newval = md_chars_to_number (buf, INSN_SIZE);
20263 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20264 /* Set the H bit on BLX instructions. */
20265 if (temp == 1)
20266 {
20267 if (value & 2)
20268 newval |= 0x01000000;
20269 else
20270 newval &= ~0x01000000;
20271 }
2fc8bdac 20272 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20273 }
c19d1205 20274 break;
a737bd4d 20275
25fe350b
MS
20276 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20277 /* CBZ can only branch forward. */
a737bd4d 20278
738755b0
MS
20279 /* Attempts to use CBZ to branch to the next instruction
20280 (which, strictly speaking, are prohibited) will be turned into
20281 no-ops.
20282
20283 FIXME: It may be better to remove the instruction completely and
20284 perform relaxation. */
20285 if (value == -2)
2fc8bdac
ZW
20286 {
20287 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20288 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20289 md_number_to_chars (buf, newval, THUMB_SIZE);
20290 }
738755b0
MS
20291 else
20292 {
20293 if (value & ~0x7e)
20294 as_bad_where (fixP->fx_file, fixP->fx_line,
20295 _("branch out of range"));
20296
20297 if (fixP->fx_done || !seg->use_rela_p)
20298 {
20299 newval = md_chars_to_number (buf, THUMB_SIZE);
20300 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20301 md_number_to_chars (buf, newval, THUMB_SIZE);
20302 }
20303 }
c19d1205 20304 break;
a737bd4d 20305
c19d1205 20306 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20307 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20308 as_bad_where (fixP->fx_file, fixP->fx_line,
20309 _("branch out of range"));
a737bd4d 20310
2fc8bdac
ZW
20311 if (fixP->fx_done || !seg->use_rela_p)
20312 {
20313 newval = md_chars_to_number (buf, THUMB_SIZE);
20314 newval |= (value & 0x1ff) >> 1;
20315 md_number_to_chars (buf, newval, THUMB_SIZE);
20316 }
c19d1205 20317 break;
a737bd4d 20318
c19d1205 20319 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20320 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20321 as_bad_where (fixP->fx_file, fixP->fx_line,
20322 _("branch out of range"));
a737bd4d 20323
2fc8bdac
ZW
20324 if (fixP->fx_done || !seg->use_rela_p)
20325 {
20326 newval = md_chars_to_number (buf, THUMB_SIZE);
20327 newval |= (value & 0xfff) >> 1;
20328 md_number_to_chars (buf, newval, THUMB_SIZE);
20329 }
c19d1205 20330 break;
a737bd4d 20331
c19d1205 20332 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20333 if (fixP->fx_addsy
20334 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20335 && !S_IS_EXTERNAL (fixP->fx_addsy)
20336 && S_IS_DEFINED (fixP->fx_addsy)
20337 && ARM_IS_FUNC (fixP->fx_addsy)
20338 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20339 {
20340 /* Force a relocation for a branch 20 bits wide. */
20341 fixP->fx_done = 0;
20342 }
2fc8bdac
ZW
20343 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20344 as_bad_where (fixP->fx_file, fixP->fx_line,
20345 _("conditional branch out of range"));
404ff6b5 20346
2fc8bdac
ZW
20347 if (fixP->fx_done || !seg->use_rela_p)
20348 {
20349 offsetT newval2;
20350 addressT S, J1, J2, lo, hi;
404ff6b5 20351
2fc8bdac
ZW
20352 S = (value & 0x00100000) >> 20;
20353 J2 = (value & 0x00080000) >> 19;
20354 J1 = (value & 0x00040000) >> 18;
20355 hi = (value & 0x0003f000) >> 12;
20356 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20357
2fc8bdac
ZW
20358 newval = md_chars_to_number (buf, THUMB_SIZE);
20359 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20360 newval |= (S << 10) | hi;
20361 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20362 md_number_to_chars (buf, newval, THUMB_SIZE);
20363 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20364 }
c19d1205 20365 break;
6c43fab6 20366
c19d1205 20367 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20368
20369 /* If there is a blx from a thumb state function to
20370 another thumb function flip this to a bl and warn
20371 about it. */
20372
20373 if (fixP->fx_addsy
20374 && S_IS_DEFINED (fixP->fx_addsy)
20375 && !S_IS_EXTERNAL (fixP->fx_addsy)
20376 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20377 && THUMB_IS_FUNC (fixP->fx_addsy))
20378 {
20379 const char *name = S_GET_NAME (fixP->fx_addsy);
20380 as_warn_where (fixP->fx_file, fixP->fx_line,
20381 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20382 name);
20383 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20384 newval = newval | 0x1000;
20385 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20386 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20387 fixP->fx_done = 1;
20388 }
20389
20390
20391 goto thumb_bl_common;
20392
c19d1205 20393 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20394
20395 /* A bl from Thumb state ISA to an internal ARM state function
20396 is converted to a blx. */
20397 if (fixP->fx_addsy
20398 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20399 && !S_IS_EXTERNAL (fixP->fx_addsy)
20400 && S_IS_DEFINED (fixP->fx_addsy)
20401 && ARM_IS_FUNC (fixP->fx_addsy)
20402 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20403 {
20404 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20405 newval = newval & ~0x1000;
20406 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20407 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20408 fixP->fx_done = 1;
20409 }
20410
20411 thumb_bl_common:
20412
20413#ifdef OBJ_ELF
20414 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20415 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20416 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20417#endif
20418
2fc8bdac
ZW
20419 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20420 /* For a BLX instruction, make sure that the relocation is rounded up
20421 to a word boundary. This follows the semantics of the instruction
20422 which specifies that bit 1 of the target address will come from bit
20423 1 of the base address. */
20424 value = (value + 1) & ~ 1;
404ff6b5 20425
2fc8bdac 20426
4a42ebbc
RR
20427 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20428 {
20429 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20430 {
20431 as_bad_where (fixP->fx_file, fixP->fx_line,
20432 _("branch out of range"));
20433 }
20434 else if ((value & ~0x1ffffff)
20435 && ((value & ~0x1ffffff) != ~0x1ffffff))
20436 {
20437 as_bad_where (fixP->fx_file, fixP->fx_line,
20438 _("Thumb2 branch out of range"));
20439 }
c19d1205 20440 }
4a42ebbc
RR
20441
20442 if (fixP->fx_done || !seg->use_rela_p)
20443 encode_thumb2_b_bl_offset (buf, value);
20444
c19d1205 20445 break;
404ff6b5 20446
c19d1205 20447 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20448 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20449 as_bad_where (fixP->fx_file, fixP->fx_line,
20450 _("branch out of range"));
6c43fab6 20451
2fc8bdac 20452 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 20453 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 20454
2fc8bdac 20455 break;
a737bd4d 20456
2fc8bdac
ZW
20457 case BFD_RELOC_8:
20458 if (fixP->fx_done || !seg->use_rela_p)
20459 md_number_to_chars (buf, value, 1);
c19d1205 20460 break;
a737bd4d 20461
c19d1205 20462 case BFD_RELOC_16:
2fc8bdac 20463 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20464 md_number_to_chars (buf, value, 2);
c19d1205 20465 break;
a737bd4d 20466
c19d1205
ZW
20467#ifdef OBJ_ELF
20468 case BFD_RELOC_ARM_TLS_GD32:
20469 case BFD_RELOC_ARM_TLS_LE32:
20470 case BFD_RELOC_ARM_TLS_IE32:
20471 case BFD_RELOC_ARM_TLS_LDM32:
20472 case BFD_RELOC_ARM_TLS_LDO32:
20473 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20474 /* fall through */
6c43fab6 20475
c19d1205
ZW
20476 case BFD_RELOC_ARM_GOT32:
20477 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20478 if (fixP->fx_done || !seg->use_rela_p)
20479 md_number_to_chars (buf, 0, 4);
c19d1205 20480 break;
b43420e6
NC
20481
20482 case BFD_RELOC_ARM_GOT_PREL:
20483 if (fixP->fx_done || !seg->use_rela_p)
20484 md_number_to_chars (buf, value, 4);
20485 break;
20486
9a6f4e97
NS
20487 case BFD_RELOC_ARM_TARGET2:
20488 /* TARGET2 is not partial-inplace, so we need to write the
20489 addend here for REL targets, because it won't be written out
20490 during reloc processing later. */
20491 if (fixP->fx_done || !seg->use_rela_p)
20492 md_number_to_chars (buf, fixP->fx_offset, 4);
20493 break;
c19d1205 20494#endif
6c43fab6 20495
c19d1205
ZW
20496 case BFD_RELOC_RVA:
20497 case BFD_RELOC_32:
20498 case BFD_RELOC_ARM_TARGET1:
20499 case BFD_RELOC_ARM_ROSEGREL32:
20500 case BFD_RELOC_ARM_SBREL32:
20501 case BFD_RELOC_32_PCREL:
f0927246
NC
20502#ifdef TE_PE
20503 case BFD_RELOC_32_SECREL:
20504#endif
2fc8bdac 20505 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20506#ifdef TE_WINCE
20507 /* For WinCE we only do this for pcrel fixups. */
20508 if (fixP->fx_done || fixP->fx_pcrel)
20509#endif
20510 md_number_to_chars (buf, value, 4);
c19d1205 20511 break;
6c43fab6 20512
c19d1205
ZW
20513#ifdef OBJ_ELF
20514 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20515 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20516 {
20517 newval = md_chars_to_number (buf, 4) & 0x80000000;
20518 if ((value ^ (value >> 1)) & 0x40000000)
20519 {
20520 as_bad_where (fixP->fx_file, fixP->fx_line,
20521 _("rel31 relocation overflow"));
20522 }
20523 newval |= value & 0x7fffffff;
20524 md_number_to_chars (buf, newval, 4);
20525 }
20526 break;
c19d1205 20527#endif
a737bd4d 20528
c19d1205 20529 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20530 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20531 if (value < -1023 || value > 1023 || (value & 3))
20532 as_bad_where (fixP->fx_file, fixP->fx_line,
20533 _("co-processor offset out of range"));
20534 cp_off_common:
20535 sign = value >= 0;
20536 if (value < 0)
20537 value = -value;
8f06b2d8
PB
20538 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20539 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20540 newval = md_chars_to_number (buf, INSN_SIZE);
20541 else
20542 newval = get_thumb32_insn (buf);
20543 newval &= 0xff7fff00;
c19d1205 20544 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20545 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20546 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20547 md_number_to_chars (buf, newval, INSN_SIZE);
20548 else
20549 put_thumb32_insn (buf, newval);
c19d1205 20550 break;
a737bd4d 20551
c19d1205 20552 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20553 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20554 if (value < -255 || value > 255)
20555 as_bad_where (fixP->fx_file, fixP->fx_line,
20556 _("co-processor offset out of range"));
df7849c5 20557 value *= 4;
c19d1205 20558 goto cp_off_common;
6c43fab6 20559
c19d1205
ZW
20560 case BFD_RELOC_ARM_THUMB_OFFSET:
20561 newval = md_chars_to_number (buf, THUMB_SIZE);
20562 /* Exactly what ranges, and where the offset is inserted depends
20563 on the type of instruction, we can establish this from the
20564 top 4 bits. */
20565 switch (newval >> 12)
20566 {
20567 case 4: /* PC load. */
20568 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20569 forced to zero for these loads; md_pcrel_from has already
20570 compensated for this. */
20571 if (value & 3)
20572 as_bad_where (fixP->fx_file, fixP->fx_line,
20573 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20574 (((unsigned long) fixP->fx_frag->fr_address
20575 + (unsigned long) fixP->fx_where) & ~3)
20576 + (unsigned long) value);
a737bd4d 20577
c19d1205
ZW
20578 if (value & ~0x3fc)
20579 as_bad_where (fixP->fx_file, fixP->fx_line,
20580 _("invalid offset, value too big (0x%08lX)"),
20581 (long) value);
a737bd4d 20582
c19d1205
ZW
20583 newval |= value >> 2;
20584 break;
a737bd4d 20585
c19d1205
ZW
20586 case 9: /* SP load/store. */
20587 if (value & ~0x3fc)
20588 as_bad_where (fixP->fx_file, fixP->fx_line,
20589 _("invalid offset, value too big (0x%08lX)"),
20590 (long) value);
20591 newval |= value >> 2;
20592 break;
6c43fab6 20593
c19d1205
ZW
20594 case 6: /* Word load/store. */
20595 if (value & ~0x7c)
20596 as_bad_where (fixP->fx_file, fixP->fx_line,
20597 _("invalid offset, value too big (0x%08lX)"),
20598 (long) value);
20599 newval |= value << 4; /* 6 - 2. */
20600 break;
a737bd4d 20601
c19d1205
ZW
20602 case 7: /* Byte load/store. */
20603 if (value & ~0x1f)
20604 as_bad_where (fixP->fx_file, fixP->fx_line,
20605 _("invalid offset, value too big (0x%08lX)"),
20606 (long) value);
20607 newval |= value << 6;
20608 break;
a737bd4d 20609
c19d1205
ZW
20610 case 8: /* Halfword load/store. */
20611 if (value & ~0x3e)
20612 as_bad_where (fixP->fx_file, fixP->fx_line,
20613 _("invalid offset, value too big (0x%08lX)"),
20614 (long) value);
20615 newval |= value << 5; /* 6 - 1. */
20616 break;
a737bd4d 20617
c19d1205
ZW
20618 default:
20619 as_bad_where (fixP->fx_file, fixP->fx_line,
20620 "Unable to process relocation for thumb opcode: %lx",
20621 (unsigned long) newval);
20622 break;
20623 }
20624 md_number_to_chars (buf, newval, THUMB_SIZE);
20625 break;
a737bd4d 20626
c19d1205
ZW
20627 case BFD_RELOC_ARM_THUMB_ADD:
20628 /* This is a complicated relocation, since we use it for all of
20629 the following immediate relocations:
a737bd4d 20630
c19d1205
ZW
20631 3bit ADD/SUB
20632 8bit ADD/SUB
20633 9bit ADD/SUB SP word-aligned
20634 10bit ADD PC/SP word-aligned
a737bd4d 20635
c19d1205
ZW
20636 The type of instruction being processed is encoded in the
20637 instruction field:
a737bd4d 20638
c19d1205
ZW
20639 0x8000 SUB
20640 0x00F0 Rd
20641 0x000F Rs
20642 */
20643 newval = md_chars_to_number (buf, THUMB_SIZE);
20644 {
20645 int rd = (newval >> 4) & 0xf;
20646 int rs = newval & 0xf;
20647 int subtract = !!(newval & 0x8000);
a737bd4d 20648
c19d1205
ZW
20649 /* Check for HI regs, only very restricted cases allowed:
20650 Adjusting SP, and using PC or SP to get an address. */
20651 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20652 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20653 as_bad_where (fixP->fx_file, fixP->fx_line,
20654 _("invalid Hi register with immediate"));
a737bd4d 20655
c19d1205
ZW
20656 /* If value is negative, choose the opposite instruction. */
20657 if (value < 0)
20658 {
20659 value = -value;
20660 subtract = !subtract;
20661 if (value < 0)
20662 as_bad_where (fixP->fx_file, fixP->fx_line,
20663 _("immediate value out of range"));
20664 }
a737bd4d 20665
c19d1205
ZW
20666 if (rd == REG_SP)
20667 {
20668 if (value & ~0x1fc)
20669 as_bad_where (fixP->fx_file, fixP->fx_line,
20670 _("invalid immediate for stack address calculation"));
20671 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20672 newval |= value >> 2;
20673 }
20674 else if (rs == REG_PC || rs == REG_SP)
20675 {
20676 if (subtract || value & ~0x3fc)
20677 as_bad_where (fixP->fx_file, fixP->fx_line,
20678 _("invalid immediate for address calculation (value = 0x%08lX)"),
20679 (unsigned long) value);
20680 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20681 newval |= rd << 8;
20682 newval |= value >> 2;
20683 }
20684 else if (rs == rd)
20685 {
20686 if (value & ~0xff)
20687 as_bad_where (fixP->fx_file, fixP->fx_line,
20688 _("immediate value out of range"));
20689 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20690 newval |= (rd << 8) | value;
20691 }
20692 else
20693 {
20694 if (value & ~0x7)
20695 as_bad_where (fixP->fx_file, fixP->fx_line,
20696 _("immediate value out of range"));
20697 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20698 newval |= rd | (rs << 3) | (value << 6);
20699 }
20700 }
20701 md_number_to_chars (buf, newval, THUMB_SIZE);
20702 break;
a737bd4d 20703
c19d1205
ZW
20704 case BFD_RELOC_ARM_THUMB_IMM:
20705 newval = md_chars_to_number (buf, THUMB_SIZE);
20706 if (value < 0 || value > 255)
20707 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20708 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20709 (long) value);
20710 newval |= value;
20711 md_number_to_chars (buf, newval, THUMB_SIZE);
20712 break;
a737bd4d 20713
c19d1205
ZW
20714 case BFD_RELOC_ARM_THUMB_SHIFT:
20715 /* 5bit shift value (0..32). LSL cannot take 32. */
20716 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20717 temp = newval & 0xf800;
20718 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20719 as_bad_where (fixP->fx_file, fixP->fx_line,
20720 _("invalid shift value: %ld"), (long) value);
20721 /* Shifts of zero must be encoded as LSL. */
20722 if (value == 0)
20723 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20724 /* Shifts of 32 are encoded as zero. */
20725 else if (value == 32)
20726 value = 0;
20727 newval |= value << 6;
20728 md_number_to_chars (buf, newval, THUMB_SIZE);
20729 break;
a737bd4d 20730
c19d1205
ZW
20731 case BFD_RELOC_VTABLE_INHERIT:
20732 case BFD_RELOC_VTABLE_ENTRY:
20733 fixP->fx_done = 0;
20734 return;
6c43fab6 20735
b6895b4f
PB
20736 case BFD_RELOC_ARM_MOVW:
20737 case BFD_RELOC_ARM_MOVT:
20738 case BFD_RELOC_ARM_THUMB_MOVW:
20739 case BFD_RELOC_ARM_THUMB_MOVT:
20740 if (fixP->fx_done || !seg->use_rela_p)
20741 {
20742 /* REL format relocations are limited to a 16-bit addend. */
20743 if (!fixP->fx_done)
20744 {
39623e12 20745 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20746 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20747 _("offset out of range"));
b6895b4f
PB
20748 }
20749 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20750 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20751 {
20752 value >>= 16;
20753 }
20754
20755 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20756 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20757 {
20758 newval = get_thumb32_insn (buf);
20759 newval &= 0xfbf08f00;
20760 newval |= (value & 0xf000) << 4;
20761 newval |= (value & 0x0800) << 15;
20762 newval |= (value & 0x0700) << 4;
20763 newval |= (value & 0x00ff);
20764 put_thumb32_insn (buf, newval);
20765 }
20766 else
20767 {
20768 newval = md_chars_to_number (buf, 4);
20769 newval &= 0xfff0f000;
20770 newval |= value & 0x0fff;
20771 newval |= (value & 0xf000) << 4;
20772 md_number_to_chars (buf, newval, 4);
20773 }
20774 }
20775 return;
20776
4962c51a
MS
20777 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20778 case BFD_RELOC_ARM_ALU_PC_G0:
20779 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20780 case BFD_RELOC_ARM_ALU_PC_G1:
20781 case BFD_RELOC_ARM_ALU_PC_G2:
20782 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20783 case BFD_RELOC_ARM_ALU_SB_G0:
20784 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20785 case BFD_RELOC_ARM_ALU_SB_G1:
20786 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20787 gas_assert (!fixP->fx_done);
4962c51a
MS
20788 if (!seg->use_rela_p)
20789 {
20790 bfd_vma insn;
20791 bfd_vma encoded_addend;
20792 bfd_vma addend_abs = abs (value);
20793
20794 /* Check that the absolute value of the addend can be
20795 expressed as an 8-bit constant plus a rotation. */
20796 encoded_addend = encode_arm_immediate (addend_abs);
20797 if (encoded_addend == (unsigned int) FAIL)
20798 as_bad_where (fixP->fx_file, fixP->fx_line,
20799 _("the offset 0x%08lX is not representable"),
495bde8e 20800 (unsigned long) addend_abs);
4962c51a
MS
20801
20802 /* Extract the instruction. */
20803 insn = md_chars_to_number (buf, INSN_SIZE);
20804
20805 /* If the addend is positive, use an ADD instruction.
20806 Otherwise use a SUB. Take care not to destroy the S bit. */
20807 insn &= 0xff1fffff;
20808 if (value < 0)
20809 insn |= 1 << 22;
20810 else
20811 insn |= 1 << 23;
20812
20813 /* Place the encoded addend into the first 12 bits of the
20814 instruction. */
20815 insn &= 0xfffff000;
20816 insn |= encoded_addend;
5f4273c7
NC
20817
20818 /* Update the instruction. */
4962c51a
MS
20819 md_number_to_chars (buf, insn, INSN_SIZE);
20820 }
20821 break;
20822
20823 case BFD_RELOC_ARM_LDR_PC_G0:
20824 case BFD_RELOC_ARM_LDR_PC_G1:
20825 case BFD_RELOC_ARM_LDR_PC_G2:
20826 case BFD_RELOC_ARM_LDR_SB_G0:
20827 case BFD_RELOC_ARM_LDR_SB_G1:
20828 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20829 gas_assert (!fixP->fx_done);
4962c51a
MS
20830 if (!seg->use_rela_p)
20831 {
20832 bfd_vma insn;
20833 bfd_vma addend_abs = abs (value);
20834
20835 /* Check that the absolute value of the addend can be
20836 encoded in 12 bits. */
20837 if (addend_abs >= 0x1000)
20838 as_bad_where (fixP->fx_file, fixP->fx_line,
20839 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20840 (unsigned long) addend_abs);
4962c51a
MS
20841
20842 /* Extract the instruction. */
20843 insn = md_chars_to_number (buf, INSN_SIZE);
20844
20845 /* If the addend is negative, clear bit 23 of the instruction.
20846 Otherwise set it. */
20847 if (value < 0)
20848 insn &= ~(1 << 23);
20849 else
20850 insn |= 1 << 23;
20851
20852 /* Place the absolute value of the addend into the first 12 bits
20853 of the instruction. */
20854 insn &= 0xfffff000;
20855 insn |= addend_abs;
5f4273c7
NC
20856
20857 /* Update the instruction. */
4962c51a
MS
20858 md_number_to_chars (buf, insn, INSN_SIZE);
20859 }
20860 break;
20861
20862 case BFD_RELOC_ARM_LDRS_PC_G0:
20863 case BFD_RELOC_ARM_LDRS_PC_G1:
20864 case BFD_RELOC_ARM_LDRS_PC_G2:
20865 case BFD_RELOC_ARM_LDRS_SB_G0:
20866 case BFD_RELOC_ARM_LDRS_SB_G1:
20867 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20868 gas_assert (!fixP->fx_done);
4962c51a
MS
20869 if (!seg->use_rela_p)
20870 {
20871 bfd_vma insn;
20872 bfd_vma addend_abs = abs (value);
20873
20874 /* Check that the absolute value of the addend can be
20875 encoded in 8 bits. */
20876 if (addend_abs >= 0x100)
20877 as_bad_where (fixP->fx_file, fixP->fx_line,
20878 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20879 (unsigned long) addend_abs);
4962c51a
MS
20880
20881 /* Extract the instruction. */
20882 insn = md_chars_to_number (buf, INSN_SIZE);
20883
20884 /* If the addend is negative, clear bit 23 of the instruction.
20885 Otherwise set it. */
20886 if (value < 0)
20887 insn &= ~(1 << 23);
20888 else
20889 insn |= 1 << 23;
20890
20891 /* Place the first four bits of the absolute value of the addend
20892 into the first 4 bits of the instruction, and the remaining
20893 four into bits 8 .. 11. */
20894 insn &= 0xfffff0f0;
20895 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20896
20897 /* Update the instruction. */
4962c51a
MS
20898 md_number_to_chars (buf, insn, INSN_SIZE);
20899 }
20900 break;
20901
20902 case BFD_RELOC_ARM_LDC_PC_G0:
20903 case BFD_RELOC_ARM_LDC_PC_G1:
20904 case BFD_RELOC_ARM_LDC_PC_G2:
20905 case BFD_RELOC_ARM_LDC_SB_G0:
20906 case BFD_RELOC_ARM_LDC_SB_G1:
20907 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20908 gas_assert (!fixP->fx_done);
4962c51a
MS
20909 if (!seg->use_rela_p)
20910 {
20911 bfd_vma insn;
20912 bfd_vma addend_abs = abs (value);
20913
20914 /* Check that the absolute value of the addend is a multiple of
20915 four and, when divided by four, fits in 8 bits. */
20916 if (addend_abs & 0x3)
20917 as_bad_where (fixP->fx_file, fixP->fx_line,
20918 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20919 (unsigned long) addend_abs);
4962c51a
MS
20920
20921 if ((addend_abs >> 2) > 0xff)
20922 as_bad_where (fixP->fx_file, fixP->fx_line,
20923 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20924 (unsigned long) addend_abs);
4962c51a
MS
20925
20926 /* Extract the instruction. */
20927 insn = md_chars_to_number (buf, INSN_SIZE);
20928
20929 /* If the addend is negative, clear bit 23 of the instruction.
20930 Otherwise set it. */
20931 if (value < 0)
20932 insn &= ~(1 << 23);
20933 else
20934 insn |= 1 << 23;
20935
20936 /* Place the addend (divided by four) into the first eight
20937 bits of the instruction. */
20938 insn &= 0xfffffff0;
20939 insn |= addend_abs >> 2;
5f4273c7
NC
20940
20941 /* Update the instruction. */
4962c51a
MS
20942 md_number_to_chars (buf, insn, INSN_SIZE);
20943 }
20944 break;
20945
845b51d6
PB
20946 case BFD_RELOC_ARM_V4BX:
20947 /* This will need to go in the object file. */
20948 fixP->fx_done = 0;
20949 break;
20950
c19d1205
ZW
20951 case BFD_RELOC_UNUSED:
20952 default:
20953 as_bad_where (fixP->fx_file, fixP->fx_line,
20954 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20955 }
6c43fab6
RE
20956}
20957
c19d1205
ZW
20958/* Translate internal representation of relocation info to BFD target
20959 format. */
a737bd4d 20960
c19d1205 20961arelent *
00a97672 20962tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20963{
c19d1205
ZW
20964 arelent * reloc;
20965 bfd_reloc_code_real_type code;
a737bd4d 20966
21d799b5 20967 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 20968
21d799b5 20969 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
20970 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20971 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20972
2fc8bdac 20973 if (fixp->fx_pcrel)
00a97672
RS
20974 {
20975 if (section->use_rela_p)
20976 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20977 else
20978 fixp->fx_offset = reloc->address;
20979 }
c19d1205 20980 reloc->addend = fixp->fx_offset;
a737bd4d 20981
c19d1205 20982 switch (fixp->fx_r_type)
a737bd4d 20983 {
c19d1205
ZW
20984 case BFD_RELOC_8:
20985 if (fixp->fx_pcrel)
20986 {
20987 code = BFD_RELOC_8_PCREL;
20988 break;
20989 }
a737bd4d 20990
c19d1205
ZW
20991 case BFD_RELOC_16:
20992 if (fixp->fx_pcrel)
20993 {
20994 code = BFD_RELOC_16_PCREL;
20995 break;
20996 }
6c43fab6 20997
c19d1205
ZW
20998 case BFD_RELOC_32:
20999 if (fixp->fx_pcrel)
21000 {
21001 code = BFD_RELOC_32_PCREL;
21002 break;
21003 }
a737bd4d 21004
b6895b4f
PB
21005 case BFD_RELOC_ARM_MOVW:
21006 if (fixp->fx_pcrel)
21007 {
21008 code = BFD_RELOC_ARM_MOVW_PCREL;
21009 break;
21010 }
21011
21012 case BFD_RELOC_ARM_MOVT:
21013 if (fixp->fx_pcrel)
21014 {
21015 code = BFD_RELOC_ARM_MOVT_PCREL;
21016 break;
21017 }
21018
21019 case BFD_RELOC_ARM_THUMB_MOVW:
21020 if (fixp->fx_pcrel)
21021 {
21022 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21023 break;
21024 }
21025
21026 case BFD_RELOC_ARM_THUMB_MOVT:
21027 if (fixp->fx_pcrel)
21028 {
21029 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21030 break;
21031 }
21032
c19d1205
ZW
21033 case BFD_RELOC_NONE:
21034 case BFD_RELOC_ARM_PCREL_BRANCH:
21035 case BFD_RELOC_ARM_PCREL_BLX:
21036 case BFD_RELOC_RVA:
21037 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21038 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21039 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21040 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21041 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21042 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
21043 case BFD_RELOC_VTABLE_ENTRY:
21044 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
21045#ifdef TE_PE
21046 case BFD_RELOC_32_SECREL:
21047#endif
c19d1205
ZW
21048 code = fixp->fx_r_type;
21049 break;
a737bd4d 21050
00adf2d4
JB
21051 case BFD_RELOC_THUMB_PCREL_BLX:
21052#ifdef OBJ_ELF
21053 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21054 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21055 else
21056#endif
21057 code = BFD_RELOC_THUMB_PCREL_BLX;
21058 break;
21059
c19d1205
ZW
21060 case BFD_RELOC_ARM_LITERAL:
21061 case BFD_RELOC_ARM_HWLITERAL:
21062 /* If this is called then the a literal has
21063 been referenced across a section boundary. */
21064 as_bad_where (fixp->fx_file, fixp->fx_line,
21065 _("literal referenced across section boundary"));
21066 return NULL;
a737bd4d 21067
c19d1205
ZW
21068#ifdef OBJ_ELF
21069 case BFD_RELOC_ARM_GOT32:
21070 case BFD_RELOC_ARM_GOTOFF:
b43420e6 21071 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
21072 case BFD_RELOC_ARM_PLT32:
21073 case BFD_RELOC_ARM_TARGET1:
21074 case BFD_RELOC_ARM_ROSEGREL32:
21075 case BFD_RELOC_ARM_SBREL32:
21076 case BFD_RELOC_ARM_PREL31:
21077 case BFD_RELOC_ARM_TARGET2:
21078 case BFD_RELOC_ARM_TLS_LE32:
21079 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
21080 case BFD_RELOC_ARM_PCREL_CALL:
21081 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
21082 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21083 case BFD_RELOC_ARM_ALU_PC_G0:
21084 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21085 case BFD_RELOC_ARM_ALU_PC_G1:
21086 case BFD_RELOC_ARM_ALU_PC_G2:
21087 case BFD_RELOC_ARM_LDR_PC_G0:
21088 case BFD_RELOC_ARM_LDR_PC_G1:
21089 case BFD_RELOC_ARM_LDR_PC_G2:
21090 case BFD_RELOC_ARM_LDRS_PC_G0:
21091 case BFD_RELOC_ARM_LDRS_PC_G1:
21092 case BFD_RELOC_ARM_LDRS_PC_G2:
21093 case BFD_RELOC_ARM_LDC_PC_G0:
21094 case BFD_RELOC_ARM_LDC_PC_G1:
21095 case BFD_RELOC_ARM_LDC_PC_G2:
21096 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21097 case BFD_RELOC_ARM_ALU_SB_G0:
21098 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21099 case BFD_RELOC_ARM_ALU_SB_G1:
21100 case BFD_RELOC_ARM_ALU_SB_G2:
21101 case BFD_RELOC_ARM_LDR_SB_G0:
21102 case BFD_RELOC_ARM_LDR_SB_G1:
21103 case BFD_RELOC_ARM_LDR_SB_G2:
21104 case BFD_RELOC_ARM_LDRS_SB_G0:
21105 case BFD_RELOC_ARM_LDRS_SB_G1:
21106 case BFD_RELOC_ARM_LDRS_SB_G2:
21107 case BFD_RELOC_ARM_LDC_SB_G0:
21108 case BFD_RELOC_ARM_LDC_SB_G1:
21109 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 21110 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
21111 code = fixp->fx_r_type;
21112 break;
a737bd4d 21113
c19d1205
ZW
21114 case BFD_RELOC_ARM_TLS_GD32:
21115 case BFD_RELOC_ARM_TLS_IE32:
21116 case BFD_RELOC_ARM_TLS_LDM32:
21117 /* BFD will include the symbol's address in the addend.
21118 But we don't want that, so subtract it out again here. */
21119 if (!S_IS_COMMON (fixp->fx_addsy))
21120 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21121 code = fixp->fx_r_type;
21122 break;
21123#endif
a737bd4d 21124
c19d1205
ZW
21125 case BFD_RELOC_ARM_IMMEDIATE:
21126 as_bad_where (fixp->fx_file, fixp->fx_line,
21127 _("internal relocation (type: IMMEDIATE) not fixed up"));
21128 return NULL;
a737bd4d 21129
c19d1205
ZW
21130 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21131 as_bad_where (fixp->fx_file, fixp->fx_line,
21132 _("ADRL used for a symbol not defined in the same file"));
21133 return NULL;
a737bd4d 21134
c19d1205 21135 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
21136 if (section->use_rela_p)
21137 {
21138 code = fixp->fx_r_type;
21139 break;
21140 }
21141
c19d1205
ZW
21142 if (fixp->fx_addsy != NULL
21143 && !S_IS_DEFINED (fixp->fx_addsy)
21144 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 21145 {
c19d1205
ZW
21146 as_bad_where (fixp->fx_file, fixp->fx_line,
21147 _("undefined local label `%s'"),
21148 S_GET_NAME (fixp->fx_addsy));
21149 return NULL;
a737bd4d
NC
21150 }
21151
c19d1205
ZW
21152 as_bad_where (fixp->fx_file, fixp->fx_line,
21153 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21154 return NULL;
a737bd4d 21155
c19d1205
ZW
21156 default:
21157 {
21158 char * type;
6c43fab6 21159
c19d1205
ZW
21160 switch (fixp->fx_r_type)
21161 {
21162 case BFD_RELOC_NONE: type = "NONE"; break;
21163 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21164 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 21165 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
21166 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21167 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21168 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 21169 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
21170 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21171 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21172 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21173 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21174 default: type = _("<unknown>"); break;
21175 }
21176 as_bad_where (fixp->fx_file, fixp->fx_line,
21177 _("cannot represent %s relocation in this object file format"),
21178 type);
21179 return NULL;
21180 }
a737bd4d 21181 }
6c43fab6 21182
c19d1205
ZW
21183#ifdef OBJ_ELF
21184 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21185 && GOT_symbol
21186 && fixp->fx_addsy == GOT_symbol)
21187 {
21188 code = BFD_RELOC_ARM_GOTPC;
21189 reloc->addend = fixp->fx_offset = reloc->address;
21190 }
21191#endif
6c43fab6 21192
c19d1205 21193 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 21194
c19d1205
ZW
21195 if (reloc->howto == NULL)
21196 {
21197 as_bad_where (fixp->fx_file, fixp->fx_line,
21198 _("cannot represent %s relocation in this object file format"),
21199 bfd_get_reloc_code_name (code));
21200 return NULL;
21201 }
6c43fab6 21202
c19d1205
ZW
21203 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21204 vtable entry to be used in the relocation's section offset. */
21205 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21206 reloc->address = fixp->fx_offset;
6c43fab6 21207
c19d1205 21208 return reloc;
6c43fab6
RE
21209}
21210
c19d1205 21211/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21212
c19d1205
ZW
21213void
21214cons_fix_new_arm (fragS * frag,
21215 int where,
21216 int size,
21217 expressionS * exp)
6c43fab6 21218{
c19d1205
ZW
21219 bfd_reloc_code_real_type type;
21220 int pcrel = 0;
6c43fab6 21221
c19d1205
ZW
21222 /* Pick a reloc.
21223 FIXME: @@ Should look at CPU word size. */
21224 switch (size)
21225 {
21226 case 1:
21227 type = BFD_RELOC_8;
21228 break;
21229 case 2:
21230 type = BFD_RELOC_16;
21231 break;
21232 case 4:
21233 default:
21234 type = BFD_RELOC_32;
21235 break;
21236 case 8:
21237 type = BFD_RELOC_64;
21238 break;
21239 }
6c43fab6 21240
f0927246
NC
21241#ifdef TE_PE
21242 if (exp->X_op == O_secrel)
21243 {
21244 exp->X_op = O_symbol;
21245 type = BFD_RELOC_32_SECREL;
21246 }
21247#endif
21248
c19d1205
ZW
21249 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21250}
6c43fab6 21251
4343666d 21252#if defined (OBJ_COFF)
c19d1205
ZW
21253void
21254arm_validate_fix (fixS * fixP)
6c43fab6 21255{
c19d1205
ZW
21256 /* If the destination of the branch is a defined symbol which does not have
21257 the THUMB_FUNC attribute, then we must be calling a function which has
21258 the (interfacearm) attribute. We look for the Thumb entry point to that
21259 function and change the branch to refer to that function instead. */
21260 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21261 && fixP->fx_addsy != NULL
21262 && S_IS_DEFINED (fixP->fx_addsy)
21263 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21264 {
c19d1205 21265 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21266 }
c19d1205
ZW
21267}
21268#endif
6c43fab6 21269
267bf995 21270
c19d1205
ZW
21271int
21272arm_force_relocation (struct fix * fixp)
21273{
21274#if defined (OBJ_COFF) && defined (TE_PE)
21275 if (fixp->fx_r_type == BFD_RELOC_RVA)
21276 return 1;
21277#endif
6c43fab6 21278
267bf995
RR
21279 /* In case we have a call or a branch to a function in ARM ISA mode from
21280 a thumb function or vice-versa force the relocation. These relocations
21281 are cleared off for some cores that might have blx and simple transformations
21282 are possible. */
21283
21284#ifdef OBJ_ELF
21285 switch (fixp->fx_r_type)
21286 {
21287 case BFD_RELOC_ARM_PCREL_JUMP:
21288 case BFD_RELOC_ARM_PCREL_CALL:
21289 case BFD_RELOC_THUMB_PCREL_BLX:
21290 if (THUMB_IS_FUNC (fixp->fx_addsy))
21291 return 1;
21292 break;
21293
21294 case BFD_RELOC_ARM_PCREL_BLX:
21295 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21296 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21297 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21298 if (ARM_IS_FUNC (fixp->fx_addsy))
21299 return 1;
21300 break;
21301
21302 default:
21303 break;
21304 }
21305#endif
21306
c19d1205
ZW
21307 /* Resolve these relocations even if the symbol is extern or weak. */
21308 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21309 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21310 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21311 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21312 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21313 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21314 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21315 return 0;
a737bd4d 21316
4962c51a
MS
21317 /* Always leave these relocations for the linker. */
21318 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21319 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21320 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21321 return 1;
21322
f0291e4c
PB
21323 /* Always generate relocations against function symbols. */
21324 if (fixp->fx_r_type == BFD_RELOC_32
21325 && fixp->fx_addsy
21326 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21327 return 1;
21328
c19d1205 21329 return generic_force_reloc (fixp);
404ff6b5
AH
21330}
21331
0ffdc86c 21332#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21333/* Relocations against function names must be left unadjusted,
21334 so that the linker can use this information to generate interworking
21335 stubs. The MIPS version of this function
c19d1205
ZW
21336 also prevents relocations that are mips-16 specific, but I do not
21337 know why it does this.
404ff6b5 21338
c19d1205
ZW
21339 FIXME:
21340 There is one other problem that ought to be addressed here, but
21341 which currently is not: Taking the address of a label (rather
21342 than a function) and then later jumping to that address. Such
21343 addresses also ought to have their bottom bit set (assuming that
21344 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21345
c19d1205
ZW
21346bfd_boolean
21347arm_fix_adjustable (fixS * fixP)
404ff6b5 21348{
c19d1205
ZW
21349 if (fixP->fx_addsy == NULL)
21350 return 1;
404ff6b5 21351
e28387c3
PB
21352 /* Preserve relocations against symbols with function type. */
21353 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21354 return FALSE;
e28387c3 21355
c19d1205
ZW
21356 if (THUMB_IS_FUNC (fixP->fx_addsy)
21357 && fixP->fx_subsy == NULL)
c921be7d 21358 return FALSE;
a737bd4d 21359
c19d1205
ZW
21360 /* We need the symbol name for the VTABLE entries. */
21361 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21362 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21363 return FALSE;
404ff6b5 21364
c19d1205
ZW
21365 /* Don't allow symbols to be discarded on GOT related relocs. */
21366 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21367 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21368 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21369 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21370 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21371 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21372 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21373 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21374 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21375 return FALSE;
a737bd4d 21376
4962c51a
MS
21377 /* Similarly for group relocations. */
21378 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21379 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21380 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21381 return FALSE;
4962c51a 21382
79947c54
CD
21383 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21384 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21385 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21386 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21387 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21388 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21389 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21390 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21391 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21392 return FALSE;
79947c54 21393
c921be7d 21394 return TRUE;
a737bd4d 21395}
0ffdc86c
NC
21396#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21397
21398#ifdef OBJ_ELF
404ff6b5 21399
c19d1205
ZW
21400const char *
21401elf32_arm_target_format (void)
404ff6b5 21402{
c19d1205
ZW
21403#ifdef TE_SYMBIAN
21404 return (target_big_endian
21405 ? "elf32-bigarm-symbian"
21406 : "elf32-littlearm-symbian");
21407#elif defined (TE_VXWORKS)
21408 return (target_big_endian
21409 ? "elf32-bigarm-vxworks"
21410 : "elf32-littlearm-vxworks");
21411#else
21412 if (target_big_endian)
21413 return "elf32-bigarm";
21414 else
21415 return "elf32-littlearm";
21416#endif
404ff6b5
AH
21417}
21418
c19d1205
ZW
21419void
21420armelf_frob_symbol (symbolS * symp,
21421 int * puntp)
404ff6b5 21422{
c19d1205
ZW
21423 elf_frob_symbol (symp, puntp);
21424}
21425#endif
404ff6b5 21426
c19d1205 21427/* MD interface: Finalization. */
a737bd4d 21428
c19d1205
ZW
21429void
21430arm_cleanup (void)
21431{
21432 literal_pool * pool;
a737bd4d 21433
e07e6e58
NC
21434 /* Ensure that all the IT blocks are properly closed. */
21435 check_it_blocks_finished ();
21436
c19d1205
ZW
21437 for (pool = list_of_pools; pool; pool = pool->next)
21438 {
5f4273c7 21439 /* Put it at the end of the relevant section. */
c19d1205
ZW
21440 subseg_set (pool->section, pool->sub_section);
21441#ifdef OBJ_ELF
21442 arm_elf_change_section ();
21443#endif
21444 s_ltorg (0);
21445 }
404ff6b5
AH
21446}
21447
cd000bff
DJ
21448#ifdef OBJ_ELF
21449/* Remove any excess mapping symbols generated for alignment frags in
21450 SEC. We may have created a mapping symbol before a zero byte
21451 alignment; remove it if there's a mapping symbol after the
21452 alignment. */
21453static void
21454check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21455 void *dummy ATTRIBUTE_UNUSED)
21456{
21457 segment_info_type *seginfo = seg_info (sec);
21458 fragS *fragp;
21459
21460 if (seginfo == NULL || seginfo->frchainP == NULL)
21461 return;
21462
21463 for (fragp = seginfo->frchainP->frch_root;
21464 fragp != NULL;
21465 fragp = fragp->fr_next)
21466 {
21467 symbolS *sym = fragp->tc_frag_data.last_map;
21468 fragS *next = fragp->fr_next;
21469
21470 /* Variable-sized frags have been converted to fixed size by
21471 this point. But if this was variable-sized to start with,
21472 there will be a fixed-size frag after it. So don't handle
21473 next == NULL. */
21474 if (sym == NULL || next == NULL)
21475 continue;
21476
21477 if (S_GET_VALUE (sym) < next->fr_address)
21478 /* Not at the end of this frag. */
21479 continue;
21480 know (S_GET_VALUE (sym) == next->fr_address);
21481
21482 do
21483 {
21484 if (next->tc_frag_data.first_map != NULL)
21485 {
21486 /* Next frag starts with a mapping symbol. Discard this
21487 one. */
21488 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21489 break;
21490 }
21491
21492 if (next->fr_next == NULL)
21493 {
21494 /* This mapping symbol is at the end of the section. Discard
21495 it. */
21496 know (next->fr_fix == 0 && next->fr_var == 0);
21497 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21498 break;
21499 }
21500
21501 /* As long as we have empty frags without any mapping symbols,
21502 keep looking. */
21503 /* If the next frag is non-empty and does not start with a
21504 mapping symbol, then this mapping symbol is required. */
21505 if (next->fr_address != next->fr_next->fr_address)
21506 break;
21507
21508 next = next->fr_next;
21509 }
21510 while (next != NULL);
21511 }
21512}
21513#endif
21514
c19d1205
ZW
21515/* Adjust the symbol table. This marks Thumb symbols as distinct from
21516 ARM ones. */
404ff6b5 21517
c19d1205
ZW
21518void
21519arm_adjust_symtab (void)
404ff6b5 21520{
c19d1205
ZW
21521#ifdef OBJ_COFF
21522 symbolS * sym;
404ff6b5 21523
c19d1205
ZW
21524 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21525 {
21526 if (ARM_IS_THUMB (sym))
21527 {
21528 if (THUMB_IS_FUNC (sym))
21529 {
21530 /* Mark the symbol as a Thumb function. */
21531 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21532 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21533 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21534
c19d1205
ZW
21535 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21536 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21537 else
21538 as_bad (_("%s: unexpected function type: %d"),
21539 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21540 }
21541 else switch (S_GET_STORAGE_CLASS (sym))
21542 {
21543 case C_EXT:
21544 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21545 break;
21546 case C_STAT:
21547 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21548 break;
21549 case C_LABEL:
21550 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21551 break;
21552 default:
21553 /* Do nothing. */
21554 break;
21555 }
21556 }
a737bd4d 21557
c19d1205
ZW
21558 if (ARM_IS_INTERWORK (sym))
21559 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21560 }
c19d1205
ZW
21561#endif
21562#ifdef OBJ_ELF
21563 symbolS * sym;
21564 char bind;
404ff6b5 21565
c19d1205 21566 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21567 {
c19d1205
ZW
21568 if (ARM_IS_THUMB (sym))
21569 {
21570 elf_symbol_type * elf_sym;
404ff6b5 21571
c19d1205
ZW
21572 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21573 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21574
b0796911
PB
21575 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21576 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21577 {
21578 /* If it's a .thumb_func, declare it as so,
21579 otherwise tag label as .code 16. */
21580 if (THUMB_IS_FUNC (sym))
21581 elf_sym->internal_elf_sym.st_info =
21582 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21583 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21584 elf_sym->internal_elf_sym.st_info =
21585 ELF_ST_INFO (bind, STT_ARM_16BIT);
21586 }
21587 }
21588 }
cd000bff
DJ
21589
21590 /* Remove any overlapping mapping symbols generated by alignment frags. */
21591 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21592#endif
404ff6b5
AH
21593}
21594
c19d1205 21595/* MD interface: Initialization. */
404ff6b5 21596
a737bd4d 21597static void
c19d1205 21598set_constant_flonums (void)
a737bd4d 21599{
c19d1205 21600 int i;
404ff6b5 21601
c19d1205
ZW
21602 for (i = 0; i < NUM_FLOAT_VALS; i++)
21603 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21604 abort ();
a737bd4d 21605}
404ff6b5 21606
3e9e4fcf
JB
21607/* Auto-select Thumb mode if it's the only available instruction set for the
21608 given architecture. */
21609
21610static void
21611autoselect_thumb_from_cpu_variant (void)
21612{
21613 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21614 opcode_select (16);
21615}
21616
c19d1205
ZW
21617void
21618md_begin (void)
a737bd4d 21619{
c19d1205
ZW
21620 unsigned mach;
21621 unsigned int i;
404ff6b5 21622
c19d1205
ZW
21623 if ( (arm_ops_hsh = hash_new ()) == NULL
21624 || (arm_cond_hsh = hash_new ()) == NULL
21625 || (arm_shift_hsh = hash_new ()) == NULL
21626 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21627 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21628 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21629 || (arm_reloc_hsh = hash_new ()) == NULL
21630 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21631 as_fatal (_("virtual memory exhausted"));
21632
21633 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21634 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21635 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21636 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21637 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21638 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21639 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21640 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21641 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21642 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21643 (void *) (v7m_psrs + i));
c19d1205 21644 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21645 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21646 for (i = 0;
21647 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21648 i++)
d3ce72d0 21649 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21650 (void *) (barrier_opt_names + i));
c19d1205
ZW
21651#ifdef OBJ_ELF
21652 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21653 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21654#endif
21655
21656 set_constant_flonums ();
404ff6b5 21657
c19d1205
ZW
21658 /* Set the cpu variant based on the command-line options. We prefer
21659 -mcpu= over -march= if both are set (as for GCC); and we prefer
21660 -mfpu= over any other way of setting the floating point unit.
21661 Use of legacy options with new options are faulted. */
e74cfd16 21662 if (legacy_cpu)
404ff6b5 21663 {
e74cfd16 21664 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21665 as_bad (_("use of old and new-style options to set CPU type"));
21666
21667 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21668 }
e74cfd16 21669 else if (!mcpu_cpu_opt)
c19d1205 21670 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21671
e74cfd16 21672 if (legacy_fpu)
c19d1205 21673 {
e74cfd16 21674 if (mfpu_opt)
c19d1205 21675 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21676
21677 mfpu_opt = legacy_fpu;
21678 }
e74cfd16 21679 else if (!mfpu_opt)
03b1477f 21680 {
45eb4c1b
NS
21681#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21682 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21683 /* Some environments specify a default FPU. If they don't, infer it
21684 from the processor. */
e74cfd16 21685 if (mcpu_fpu_opt)
03b1477f
RE
21686 mfpu_opt = mcpu_fpu_opt;
21687 else
21688 mfpu_opt = march_fpu_opt;
39c2da32 21689#else
e74cfd16 21690 mfpu_opt = &fpu_default;
39c2da32 21691#endif
03b1477f
RE
21692 }
21693
e74cfd16 21694 if (!mfpu_opt)
03b1477f 21695 {
493cb6ef 21696 if (mcpu_cpu_opt != NULL)
e74cfd16 21697 mfpu_opt = &fpu_default;
493cb6ef 21698 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21699 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21700 else
e74cfd16 21701 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21702 }
21703
ee065d83 21704#ifdef CPU_DEFAULT
e74cfd16 21705 if (!mcpu_cpu_opt)
ee065d83 21706 {
e74cfd16
PB
21707 mcpu_cpu_opt = &cpu_default;
21708 selected_cpu = cpu_default;
ee065d83 21709 }
e74cfd16
PB
21710#else
21711 if (mcpu_cpu_opt)
21712 selected_cpu = *mcpu_cpu_opt;
ee065d83 21713 else
e74cfd16 21714 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21715#endif
03b1477f 21716
e74cfd16 21717 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21718
3e9e4fcf
JB
21719 autoselect_thumb_from_cpu_variant ();
21720
e74cfd16 21721 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21722
f17c130b 21723#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21724 {
7cc69913
NC
21725 unsigned int flags = 0;
21726
21727#if defined OBJ_ELF
21728 flags = meabi_flags;
d507cf36
PB
21729
21730 switch (meabi_flags)
33a392fb 21731 {
d507cf36 21732 case EF_ARM_EABI_UNKNOWN:
7cc69913 21733#endif
d507cf36
PB
21734 /* Set the flags in the private structure. */
21735 if (uses_apcs_26) flags |= F_APCS26;
21736 if (support_interwork) flags |= F_INTERWORK;
21737 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21738 if (pic_code) flags |= F_PIC;
e74cfd16 21739 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21740 flags |= F_SOFT_FLOAT;
21741
d507cf36
PB
21742 switch (mfloat_abi_opt)
21743 {
21744 case ARM_FLOAT_ABI_SOFT:
21745 case ARM_FLOAT_ABI_SOFTFP:
21746 flags |= F_SOFT_FLOAT;
21747 break;
33a392fb 21748
d507cf36
PB
21749 case ARM_FLOAT_ABI_HARD:
21750 if (flags & F_SOFT_FLOAT)
21751 as_bad (_("hard-float conflicts with specified fpu"));
21752 break;
21753 }
03b1477f 21754
e74cfd16
PB
21755 /* Using pure-endian doubles (even if soft-float). */
21756 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21757 flags |= F_VFP_FLOAT;
f17c130b 21758
fde78edd 21759#if defined OBJ_ELF
e74cfd16 21760 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21761 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21762 break;
21763
8cb51566 21764 case EF_ARM_EABI_VER4:
3a4a14e9 21765 case EF_ARM_EABI_VER5:
c19d1205 21766 /* No additional flags to set. */
d507cf36
PB
21767 break;
21768
21769 default:
21770 abort ();
21771 }
7cc69913 21772#endif
b99bd4ef
NC
21773 bfd_set_private_flags (stdoutput, flags);
21774
21775 /* We have run out flags in the COFF header to encode the
21776 status of ATPCS support, so instead we create a dummy,
c19d1205 21777 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21778 if (atpcs)
21779 {
21780 asection * sec;
21781
21782 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21783
21784 if (sec != NULL)
21785 {
21786 bfd_set_section_flags
21787 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21788 bfd_set_section_size (stdoutput, sec, 0);
21789 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21790 }
21791 }
7cc69913 21792 }
f17c130b 21793#endif
b99bd4ef
NC
21794
21795 /* Record the CPU type as well. */
2d447fca
JM
21796 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21797 mach = bfd_mach_arm_iWMMXt2;
21798 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21799 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21800 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21801 mach = bfd_mach_arm_XScale;
e74cfd16 21802 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21803 mach = bfd_mach_arm_ep9312;
e74cfd16 21804 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21805 mach = bfd_mach_arm_5TE;
e74cfd16 21806 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21807 {
e74cfd16 21808 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21809 mach = bfd_mach_arm_5T;
21810 else
21811 mach = bfd_mach_arm_5;
21812 }
e74cfd16 21813 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21814 {
e74cfd16 21815 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21816 mach = bfd_mach_arm_4T;
21817 else
21818 mach = bfd_mach_arm_4;
21819 }
e74cfd16 21820 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21821 mach = bfd_mach_arm_3M;
e74cfd16
PB
21822 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21823 mach = bfd_mach_arm_3;
21824 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21825 mach = bfd_mach_arm_2a;
21826 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21827 mach = bfd_mach_arm_2;
21828 else
21829 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21830
21831 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21832}
21833
c19d1205 21834/* Command line processing. */
b99bd4ef 21835
c19d1205
ZW
21836/* md_parse_option
21837 Invocation line includes a switch not recognized by the base assembler.
21838 See if it's a processor-specific option.
b99bd4ef 21839
c19d1205
ZW
21840 This routine is somewhat complicated by the need for backwards
21841 compatibility (since older releases of gcc can't be changed).
21842 The new options try to make the interface as compatible as
21843 possible with GCC.
b99bd4ef 21844
c19d1205 21845 New options (supported) are:
b99bd4ef 21846
c19d1205
ZW
21847 -mcpu=<cpu name> Assemble for selected processor
21848 -march=<architecture name> Assemble for selected architecture
21849 -mfpu=<fpu architecture> Assemble for selected FPU.
21850 -EB/-mbig-endian Big-endian
21851 -EL/-mlittle-endian Little-endian
21852 -k Generate PIC code
21853 -mthumb Start in Thumb mode
21854 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21855
278df34e 21856 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21857
c19d1205 21858 For now we will also provide support for:
b99bd4ef 21859
c19d1205
ZW
21860 -mapcs-32 32-bit Program counter
21861 -mapcs-26 26-bit Program counter
21862 -macps-float Floats passed in FP registers
21863 -mapcs-reentrant Reentrant code
21864 -matpcs
21865 (sometime these will probably be replaced with -mapcs=<list of options>
21866 and -matpcs=<list of options>)
b99bd4ef 21867
c19d1205
ZW
21868 The remaining options are only supported for back-wards compatibility.
21869 Cpu variants, the arm part is optional:
21870 -m[arm]1 Currently not supported.
21871 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21872 -m[arm]3 Arm 3 processor
21873 -m[arm]6[xx], Arm 6 processors
21874 -m[arm]7[xx][t][[d]m] Arm 7 processors
21875 -m[arm]8[10] Arm 8 processors
21876 -m[arm]9[20][tdmi] Arm 9 processors
21877 -mstrongarm[110[0]] StrongARM processors
21878 -mxscale XScale processors
21879 -m[arm]v[2345[t[e]]] Arm architectures
21880 -mall All (except the ARM1)
21881 FP variants:
21882 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21883 -mfpe-old (No float load/store multiples)
21884 -mvfpxd VFP Single precision
21885 -mvfp All VFP
21886 -mno-fpu Disable all floating point instructions
b99bd4ef 21887
c19d1205
ZW
21888 The following CPU names are recognized:
21889 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21890 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21891 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21892 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21893 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21894 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21895 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21896
c19d1205 21897 */
b99bd4ef 21898
c19d1205 21899const char * md_shortopts = "m:k";
b99bd4ef 21900
c19d1205
ZW
21901#ifdef ARM_BI_ENDIAN
21902#define OPTION_EB (OPTION_MD_BASE + 0)
21903#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21904#else
c19d1205
ZW
21905#if TARGET_BYTES_BIG_ENDIAN
21906#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21907#else
c19d1205
ZW
21908#define OPTION_EL (OPTION_MD_BASE + 1)
21909#endif
b99bd4ef 21910#endif
845b51d6 21911#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21912
c19d1205 21913struct option md_longopts[] =
b99bd4ef 21914{
c19d1205
ZW
21915#ifdef OPTION_EB
21916 {"EB", no_argument, NULL, OPTION_EB},
21917#endif
21918#ifdef OPTION_EL
21919 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21920#endif
845b51d6 21921 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21922 {NULL, no_argument, NULL, 0}
21923};
b99bd4ef 21924
c19d1205 21925size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21926
c19d1205 21927struct arm_option_table
b99bd4ef 21928{
c19d1205
ZW
21929 char *option; /* Option name to match. */
21930 char *help; /* Help information. */
21931 int *var; /* Variable to change. */
21932 int value; /* What to change it to. */
21933 char *deprecated; /* If non-null, print this message. */
21934};
b99bd4ef 21935
c19d1205
ZW
21936struct arm_option_table arm_opts[] =
21937{
21938 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21939 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21940 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21941 &support_interwork, 1, NULL},
21942 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21943 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21944 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21945 1, NULL},
21946 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21947 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21948 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21949 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21950 NULL},
b99bd4ef 21951
c19d1205
ZW
21952 /* These are recognized by the assembler, but have no affect on code. */
21953 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21954 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21955
21956 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21957 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21958 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21959 {NULL, NULL, NULL, 0, NULL}
21960};
21961
21962struct arm_legacy_option_table
21963{
21964 char *option; /* Option name to match. */
21965 const arm_feature_set **var; /* Variable to change. */
21966 const arm_feature_set value; /* What to change it to. */
21967 char *deprecated; /* If non-null, print this message. */
21968};
b99bd4ef 21969
e74cfd16
PB
21970const struct arm_legacy_option_table arm_legacy_opts[] =
21971{
c19d1205
ZW
21972 /* DON'T add any new processors to this list -- we want the whole list
21973 to go away... Add them to the processors table instead. */
e74cfd16
PB
21974 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21975 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21976 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21977 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21978 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21979 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21980 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21981 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21982 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21983 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21984 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21985 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21986 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21987 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21988 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21989 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21990 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21991 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21992 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21993 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21994 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21995 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21996 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21997 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21998 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21999 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22000 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22001 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22002 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22003 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22004 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22005 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22006 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22007 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22008 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22009 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22010 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22011 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22012 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22013 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22014 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22015 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22016 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22017 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22018 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22019 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22020 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22021 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22022 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22023 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22024 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22025 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22026 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22027 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22028 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22029 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22030 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22031 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22032 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22033 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22034 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22035 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22036 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22037 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22038 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22039 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22040 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22041 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22042 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22043 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22044 N_("use -mcpu=strongarm110")},
e74cfd16 22045 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22046 N_("use -mcpu=strongarm1100")},
e74cfd16 22047 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 22048 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
22049 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22050 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22051 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 22052
c19d1205 22053 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
22054 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22055 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22056 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22057 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22058 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22059 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22060 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22061 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22062 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22063 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22064 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22065 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22066 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22067 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22068 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22069 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22070 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22071 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 22072
c19d1205 22073 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
22074 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22075 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22076 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22077 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 22078 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 22079
e74cfd16 22080 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 22081};
7ed4c4c5 22082
c19d1205 22083struct arm_cpu_option_table
7ed4c4c5 22084{
c19d1205 22085 char *name;
e74cfd16 22086 const arm_feature_set value;
c19d1205
ZW
22087 /* For some CPUs we assume an FPU unless the user explicitly sets
22088 -mfpu=... */
e74cfd16 22089 const arm_feature_set default_fpu;
ee065d83
PB
22090 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22091 case. */
22092 const char *canonical_name;
c19d1205 22093};
7ed4c4c5 22094
c19d1205
ZW
22095/* This list should, at a minimum, contain all the cpu names
22096 recognized by GCC. */
e74cfd16 22097static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 22098{
ee065d83
PB
22099 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22100 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22101 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22102 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22103 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22104 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22105 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22106 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22107 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22108 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22109 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22110 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22111 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22112 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22113 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22114 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22115 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22116 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22117 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22118 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22119 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22120 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22121 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22122 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22123 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22124 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22125 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22126 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22127 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22128 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22129 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22130 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22131 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22132 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22133 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22134 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22135 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22136 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22137 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22138 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22139 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22140 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22141 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22142 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
22143 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22144 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
22145 /* For V5 or later processors we default to using VFP; but the user
22146 should really set the FPU type explicitly. */
ee065d83
PB
22147 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22148 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22149 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22150 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22151 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22152 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22153 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22154 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22155 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22156 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22157 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22158 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22159 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22160 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22161 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22162 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22163 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22164 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22165 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22166 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22167 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
22168 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22169 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
22170 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22171 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22172 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22173 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22174 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22175 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22176 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22177 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22178 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22179 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
b38f9f31 22180 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
e07e6e58 22181 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 22182 | FPU_NEON_EXT_V1),
15290f0a 22183 NULL},
e07e6e58 22184 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 22185 | FPU_NEON_EXT_V1),
5287ad62 22186 NULL},
62b3e311 22187 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
307c948d 22188 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
26b6f191 22189 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, NULL},
62b3e311 22190 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 22191 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 22192 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 22193 /* ??? XSCALE is really an architecture. */
ee065d83 22194 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22195 /* ??? iwmmxt is not a processor. */
ee065d83 22196 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 22197 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 22198 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 22199 /* Maverick */
e07e6e58 22200 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 22201 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 22202};
7ed4c4c5 22203
c19d1205 22204struct arm_arch_option_table
7ed4c4c5 22205{
c19d1205 22206 char *name;
e74cfd16
PB
22207 const arm_feature_set value;
22208 const arm_feature_set default_fpu;
c19d1205 22209};
7ed4c4c5 22210
c19d1205
ZW
22211/* This list should, at a minimum, contain all the architecture names
22212 recognized by GCC. */
e74cfd16 22213static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22214{
22215 {"all", ARM_ANY, FPU_ARCH_FPA},
22216 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22217 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22218 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22219 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22220 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22221 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22222 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22223 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22224 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22225 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22226 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22227 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22228 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22229 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22230 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22231 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22232 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22233 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22234 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22235 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22236 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22237 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22238 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22239 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22240 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22241 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22242 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22243 /* The official spelling of the ARMv7 profile variants is the dashed form.
22244 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22245 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22246 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22247 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22248 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22249 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22250 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22251 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22252 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22253 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22254 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22255 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22256};
7ed4c4c5 22257
c19d1205 22258/* ISA extensions in the co-processor space. */
e74cfd16 22259struct arm_option_cpu_value_table
c19d1205
ZW
22260{
22261 char *name;
e74cfd16 22262 const arm_feature_set value;
c19d1205 22263};
7ed4c4c5 22264
e74cfd16 22265static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22266{
e74cfd16
PB
22267 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22268 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22269 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22270 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22271 {NULL, ARM_ARCH_NONE}
c19d1205 22272};
7ed4c4c5 22273
c19d1205
ZW
22274/* This list should, at a minimum, contain all the fpu names
22275 recognized by GCC. */
e74cfd16 22276static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22277{
22278 {"softfpa", FPU_NONE},
22279 {"fpe", FPU_ARCH_FPE},
22280 {"fpe2", FPU_ARCH_FPE},
22281 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22282 {"fpa", FPU_ARCH_FPA},
22283 {"fpa10", FPU_ARCH_FPA},
22284 {"fpa11", FPU_ARCH_FPA},
22285 {"arm7500fe", FPU_ARCH_FPA},
22286 {"softvfp", FPU_ARCH_VFP},
22287 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22288 {"vfp", FPU_ARCH_VFP_V2},
22289 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22290 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22291 {"vfp10", FPU_ARCH_VFP_V2},
22292 {"vfp10-r0", FPU_ARCH_VFP_V1},
22293 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22294 {"vfpv2", FPU_ARCH_VFP_V2},
22295 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22296 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22297 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22298 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22299 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22300 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22301 {"arm1020t", FPU_ARCH_VFP_V1},
22302 {"arm1020e", FPU_ARCH_VFP_V2},
22303 {"arm1136jfs", FPU_ARCH_VFP_V2},
22304 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22305 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22306 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22307 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22308 {"vfpv4", FPU_ARCH_VFP_V4},
22309 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22310 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22311 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22312 {NULL, ARM_ARCH_NONE}
22313};
22314
22315struct arm_option_value_table
22316{
22317 char *name;
22318 long value;
c19d1205 22319};
7ed4c4c5 22320
e74cfd16 22321static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22322{
22323 {"hard", ARM_FLOAT_ABI_HARD},
22324 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22325 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22326 {NULL, 0}
c19d1205 22327};
7ed4c4c5 22328
c19d1205 22329#ifdef OBJ_ELF
3a4a14e9 22330/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22331static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22332{
22333 {"gnu", EF_ARM_EABI_UNKNOWN},
22334 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22335 {"5", EF_ARM_EABI_VER5},
e74cfd16 22336 {NULL, 0}
c19d1205
ZW
22337};
22338#endif
7ed4c4c5 22339
c19d1205
ZW
22340struct arm_long_option_table
22341{
22342 char * option; /* Substring to match. */
22343 char * help; /* Help information. */
22344 int (* func) (char * subopt); /* Function to decode sub-option. */
22345 char * deprecated; /* If non-null, print this message. */
22346};
7ed4c4c5 22347
c921be7d 22348static bfd_boolean
e74cfd16 22349arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22350{
21d799b5
NC
22351 arm_feature_set *ext_set = (arm_feature_set *)
22352 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22353
22354 /* Copy the feature set, so that we can modify it. */
22355 *ext_set = **opt_p;
22356 *opt_p = ext_set;
22357
c19d1205 22358 while (str != NULL && *str != 0)
7ed4c4c5 22359 {
e74cfd16 22360 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22361 char * ext;
22362 int optlen;
7ed4c4c5 22363
c19d1205
ZW
22364 if (*str != '+')
22365 {
22366 as_bad (_("invalid architectural extension"));
c921be7d 22367 return FALSE;
c19d1205 22368 }
7ed4c4c5 22369
c19d1205
ZW
22370 str++;
22371 ext = strchr (str, '+');
7ed4c4c5 22372
c19d1205
ZW
22373 if (ext != NULL)
22374 optlen = ext - str;
22375 else
22376 optlen = strlen (str);
7ed4c4c5 22377
c19d1205
ZW
22378 if (optlen == 0)
22379 {
22380 as_bad (_("missing architectural extension"));
c921be7d 22381 return FALSE;
c19d1205 22382 }
7ed4c4c5 22383
c19d1205
ZW
22384 for (opt = arm_extensions; opt->name != NULL; opt++)
22385 if (strncmp (opt->name, str, optlen) == 0)
22386 {
e74cfd16 22387 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22388 break;
22389 }
7ed4c4c5 22390
c19d1205
ZW
22391 if (opt->name == NULL)
22392 {
5f4273c7 22393 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22394 return FALSE;
c19d1205 22395 }
7ed4c4c5 22396
c19d1205
ZW
22397 str = ext;
22398 };
7ed4c4c5 22399
c921be7d 22400 return TRUE;
c19d1205 22401}
7ed4c4c5 22402
c921be7d 22403static bfd_boolean
c19d1205 22404arm_parse_cpu (char * str)
7ed4c4c5 22405{
e74cfd16 22406 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22407 char * ext = strchr (str, '+');
22408 int optlen;
7ed4c4c5 22409
c19d1205
ZW
22410 if (ext != NULL)
22411 optlen = ext - str;
7ed4c4c5 22412 else
c19d1205 22413 optlen = strlen (str);
7ed4c4c5 22414
c19d1205 22415 if (optlen == 0)
7ed4c4c5 22416 {
c19d1205 22417 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22418 return FALSE;
7ed4c4c5
NC
22419 }
22420
c19d1205
ZW
22421 for (opt = arm_cpus; opt->name != NULL; opt++)
22422 if (strncmp (opt->name, str, optlen) == 0)
22423 {
e74cfd16
PB
22424 mcpu_cpu_opt = &opt->value;
22425 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22426 if (opt->canonical_name)
5f4273c7 22427 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22428 else
22429 {
22430 int i;
c921be7d 22431
ee065d83
PB
22432 for (i = 0; i < optlen; i++)
22433 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22434 selected_cpu_name[i] = 0;
22435 }
7ed4c4c5 22436
c19d1205
ZW
22437 if (ext != NULL)
22438 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22439
c921be7d 22440 return TRUE;
c19d1205 22441 }
7ed4c4c5 22442
c19d1205 22443 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22444 return FALSE;
7ed4c4c5
NC
22445}
22446
c921be7d 22447static bfd_boolean
c19d1205 22448arm_parse_arch (char * str)
7ed4c4c5 22449{
e74cfd16 22450 const struct arm_arch_option_table *opt;
c19d1205
ZW
22451 char *ext = strchr (str, '+');
22452 int optlen;
7ed4c4c5 22453
c19d1205
ZW
22454 if (ext != NULL)
22455 optlen = ext - str;
7ed4c4c5 22456 else
c19d1205 22457 optlen = strlen (str);
7ed4c4c5 22458
c19d1205 22459 if (optlen == 0)
7ed4c4c5 22460 {
c19d1205 22461 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22462 return FALSE;
7ed4c4c5
NC
22463 }
22464
c19d1205
ZW
22465 for (opt = arm_archs; opt->name != NULL; opt++)
22466 if (streq (opt->name, str))
22467 {
e74cfd16
PB
22468 march_cpu_opt = &opt->value;
22469 march_fpu_opt = &opt->default_fpu;
5f4273c7 22470 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22471
c19d1205
ZW
22472 if (ext != NULL)
22473 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22474
c921be7d 22475 return TRUE;
c19d1205
ZW
22476 }
22477
22478 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22479 return FALSE;
7ed4c4c5 22480}
eb043451 22481
c921be7d 22482static bfd_boolean
c19d1205
ZW
22483arm_parse_fpu (char * str)
22484{
e74cfd16 22485 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22486
c19d1205
ZW
22487 for (opt = arm_fpus; opt->name != NULL; opt++)
22488 if (streq (opt->name, str))
22489 {
e74cfd16 22490 mfpu_opt = &opt->value;
c921be7d 22491 return TRUE;
c19d1205 22492 }
b99bd4ef 22493
c19d1205 22494 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22495 return FALSE;
c19d1205
ZW
22496}
22497
c921be7d 22498static bfd_boolean
c19d1205 22499arm_parse_float_abi (char * str)
b99bd4ef 22500{
e74cfd16 22501 const struct arm_option_value_table * opt;
b99bd4ef 22502
c19d1205
ZW
22503 for (opt = arm_float_abis; opt->name != NULL; opt++)
22504 if (streq (opt->name, str))
22505 {
22506 mfloat_abi_opt = opt->value;
c921be7d 22507 return TRUE;
c19d1205 22508 }
cc8a6dd0 22509
c19d1205 22510 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22511 return FALSE;
c19d1205 22512}
b99bd4ef 22513
c19d1205 22514#ifdef OBJ_ELF
c921be7d 22515static bfd_boolean
c19d1205
ZW
22516arm_parse_eabi (char * str)
22517{
e74cfd16 22518 const struct arm_option_value_table *opt;
cc8a6dd0 22519
c19d1205
ZW
22520 for (opt = arm_eabis; opt->name != NULL; opt++)
22521 if (streq (opt->name, str))
22522 {
22523 meabi_flags = opt->value;
c921be7d 22524 return TRUE;
c19d1205
ZW
22525 }
22526 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22527 return FALSE;
c19d1205
ZW
22528}
22529#endif
cc8a6dd0 22530
c921be7d 22531static bfd_boolean
e07e6e58
NC
22532arm_parse_it_mode (char * str)
22533{
c921be7d 22534 bfd_boolean ret = TRUE;
e07e6e58
NC
22535
22536 if (streq ("arm", str))
22537 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22538 else if (streq ("thumb", str))
22539 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22540 else if (streq ("always", str))
22541 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22542 else if (streq ("never", str))
22543 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22544 else
22545 {
22546 as_bad (_("unknown implicit IT mode `%s', should be "\
22547 "arm, thumb, always, or never."), str);
c921be7d 22548 ret = FALSE;
e07e6e58
NC
22549 }
22550
22551 return ret;
22552}
22553
c19d1205
ZW
22554struct arm_long_option_table arm_long_opts[] =
22555{
22556 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22557 arm_parse_cpu, NULL},
22558 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22559 arm_parse_arch, NULL},
22560 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22561 arm_parse_fpu, NULL},
22562 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22563 arm_parse_float_abi, NULL},
22564#ifdef OBJ_ELF
7fac0536 22565 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22566 arm_parse_eabi, NULL},
22567#endif
e07e6e58
NC
22568 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22569 arm_parse_it_mode, NULL},
c19d1205
ZW
22570 {NULL, NULL, 0, NULL}
22571};
cc8a6dd0 22572
c19d1205
ZW
22573int
22574md_parse_option (int c, char * arg)
22575{
22576 struct arm_option_table *opt;
e74cfd16 22577 const struct arm_legacy_option_table *fopt;
c19d1205 22578 struct arm_long_option_table *lopt;
b99bd4ef 22579
c19d1205 22580 switch (c)
b99bd4ef 22581 {
c19d1205
ZW
22582#ifdef OPTION_EB
22583 case OPTION_EB:
22584 target_big_endian = 1;
22585 break;
22586#endif
cc8a6dd0 22587
c19d1205
ZW
22588#ifdef OPTION_EL
22589 case OPTION_EL:
22590 target_big_endian = 0;
22591 break;
22592#endif
b99bd4ef 22593
845b51d6
PB
22594 case OPTION_FIX_V4BX:
22595 fix_v4bx = TRUE;
22596 break;
22597
c19d1205
ZW
22598 case 'a':
22599 /* Listing option. Just ignore these, we don't support additional
22600 ones. */
22601 return 0;
b99bd4ef 22602
c19d1205
ZW
22603 default:
22604 for (opt = arm_opts; opt->option != NULL; opt++)
22605 {
22606 if (c == opt->option[0]
22607 && ((arg == NULL && opt->option[1] == 0)
22608 || streq (arg, opt->option + 1)))
22609 {
c19d1205 22610 /* If the option is deprecated, tell the user. */
278df34e 22611 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22612 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22613 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22614
c19d1205
ZW
22615 if (opt->var != NULL)
22616 *opt->var = opt->value;
cc8a6dd0 22617
c19d1205
ZW
22618 return 1;
22619 }
22620 }
b99bd4ef 22621
e74cfd16
PB
22622 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22623 {
22624 if (c == fopt->option[0]
22625 && ((arg == NULL && fopt->option[1] == 0)
22626 || streq (arg, fopt->option + 1)))
22627 {
e74cfd16 22628 /* If the option is deprecated, tell the user. */
278df34e 22629 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22630 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22631 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22632
22633 if (fopt->var != NULL)
22634 *fopt->var = &fopt->value;
22635
22636 return 1;
22637 }
22638 }
22639
c19d1205
ZW
22640 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22641 {
22642 /* These options are expected to have an argument. */
22643 if (c == lopt->option[0]
22644 && arg != NULL
22645 && strncmp (arg, lopt->option + 1,
22646 strlen (lopt->option + 1)) == 0)
22647 {
c19d1205 22648 /* If the option is deprecated, tell the user. */
278df34e 22649 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22650 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22651 _(lopt->deprecated));
b99bd4ef 22652
c19d1205
ZW
22653 /* Call the sup-option parser. */
22654 return lopt->func (arg + strlen (lopt->option) - 1);
22655 }
22656 }
a737bd4d 22657
c19d1205
ZW
22658 return 0;
22659 }
a394c00f 22660
c19d1205
ZW
22661 return 1;
22662}
a394c00f 22663
c19d1205
ZW
22664void
22665md_show_usage (FILE * fp)
a394c00f 22666{
c19d1205
ZW
22667 struct arm_option_table *opt;
22668 struct arm_long_option_table *lopt;
a394c00f 22669
c19d1205 22670 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22671
c19d1205
ZW
22672 for (opt = arm_opts; opt->option != NULL; opt++)
22673 if (opt->help != NULL)
22674 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22675
c19d1205
ZW
22676 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22677 if (lopt->help != NULL)
22678 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22679
c19d1205
ZW
22680#ifdef OPTION_EB
22681 fprintf (fp, _("\
22682 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22683#endif
22684
c19d1205
ZW
22685#ifdef OPTION_EL
22686 fprintf (fp, _("\
22687 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22688#endif
845b51d6
PB
22689
22690 fprintf (fp, _("\
22691 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22692}
ee065d83
PB
22693
22694
22695#ifdef OBJ_ELF
62b3e311
PB
22696typedef struct
22697{
22698 int val;
22699 arm_feature_set flags;
22700} cpu_arch_ver_table;
22701
22702/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22703 least features first. */
22704static const cpu_arch_ver_table cpu_arch_ver[] =
22705{
22706 {1, ARM_ARCH_V4},
22707 {2, ARM_ARCH_V4T},
22708 {3, ARM_ARCH_V5},
ee3c0378 22709 {3, ARM_ARCH_V5T},
62b3e311
PB
22710 {4, ARM_ARCH_V5TE},
22711 {5, ARM_ARCH_V5TEJ},
22712 {6, ARM_ARCH_V6},
22713 {7, ARM_ARCH_V6Z},
7e806470 22714 {9, ARM_ARCH_V6K},
91e22acd 22715 {11, ARM_ARCH_V6M},
7e806470 22716 {8, ARM_ARCH_V6T2},
62b3e311
PB
22717 {10, ARM_ARCH_V7A},
22718 {10, ARM_ARCH_V7R},
22719 {10, ARM_ARCH_V7M},
22720 {0, ARM_ARCH_NONE}
22721};
22722
ee3c0378
AS
22723/* Set an attribute if it has not already been set by the user. */
22724static void
22725aeabi_set_attribute_int (int tag, int value)
22726{
22727 if (tag < 1
22728 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22729 || !attributes_set_explicitly[tag])
22730 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22731}
22732
22733static void
22734aeabi_set_attribute_string (int tag, const char *value)
22735{
22736 if (tag < 1
22737 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22738 || !attributes_set_explicitly[tag])
22739 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22740}
22741
ee065d83
PB
22742/* Set the public EABI object attributes. */
22743static void
22744aeabi_set_public_attributes (void)
22745{
22746 int arch;
e74cfd16 22747 arm_feature_set flags;
62b3e311
PB
22748 arm_feature_set tmp;
22749 const cpu_arch_ver_table *p;
ee065d83
PB
22750
22751 /* Choose the architecture based on the capabilities of the requested cpu
22752 (if any) and/or the instructions actually used. */
e74cfd16
PB
22753 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22754 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22755 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22756 /*Allow the user to override the reported architecture. */
22757 if (object_arch)
22758 {
22759 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22760 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22761 }
22762
62b3e311
PB
22763 tmp = flags;
22764 arch = 0;
22765 for (p = cpu_arch_ver; p->val; p++)
22766 {
22767 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22768 {
22769 arch = p->val;
22770 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22771 }
22772 }
ee065d83 22773
9e3c6df6
PB
22774 /* The table lookup above finds the last architecture to contribute
22775 a new feature. Unfortunately, Tag13 is a subset of the union of
22776 v6T2 and v7-M, so it is never seen as contributing a new feature.
22777 We can not search for the last entry which is entirely used,
22778 because if no CPU is specified we build up only those flags
22779 actually used. Perhaps we should separate out the specified
22780 and implicit cases. Avoid taking this path for -march=all by
22781 checking for contradictory v7-A / v7-M features. */
22782 if (arch == 10
22783 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22784 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22785 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22786 arch = 13;
22787
ee065d83
PB
22788 /* Tag_CPU_name. */
22789 if (selected_cpu_name[0])
22790 {
91d6fa6a 22791 char *q;
ee065d83 22792
91d6fa6a
NC
22793 q = selected_cpu_name;
22794 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
22795 {
22796 int i;
5f4273c7 22797
91d6fa6a
NC
22798 q += 4;
22799 for (i = 0; q[i]; i++)
22800 q[i] = TOUPPER (q[i]);
ee065d83 22801 }
91d6fa6a 22802 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 22803 }
62f3b8c8 22804
ee065d83 22805 /* Tag_CPU_arch. */
ee3c0378 22806 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 22807
62b3e311
PB
22808 /* Tag_CPU_arch_profile. */
22809 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22810 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22811 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22812 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22813 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22814 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 22815
ee065d83 22816 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22817 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22818 || arch == 0)
22819 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 22820
ee065d83 22821 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22822 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22823 || arch == 0)
22824 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22825 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 22826
ee065d83 22827 /* Tag_VFP_arch. */
62f3b8c8
PB
22828 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22829 aeabi_set_attribute_int (Tag_VFP_arch,
22830 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22831 ? 5 : 6);
22832 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 22833 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 22834 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
22835 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22836 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22837 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22838 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22839 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22840 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 22841
ee065d83 22842 /* Tag_WMMX_arch. */
ee3c0378
AS
22843 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22844 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22845 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22846 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 22847
ee3c0378 22848 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22849 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
22850 aeabi_set_attribute_int
22851 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22852 ? 2 : 1));
22853
ee3c0378 22854 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 22855 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 22856 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
22857}
22858
104d59d1 22859/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22860void
22861arm_md_end (void)
22862{
ee065d83
PB
22863 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22864 return;
22865
22866 aeabi_set_public_attributes ();
ee065d83 22867}
8463be01 22868#endif /* OBJ_ELF */
ee065d83
PB
22869
22870
22871/* Parse a .cpu directive. */
22872
22873static void
22874s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22875{
e74cfd16 22876 const struct arm_cpu_option_table *opt;
ee065d83
PB
22877 char *name;
22878 char saved_char;
22879
22880 name = input_line_pointer;
5f4273c7 22881 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22882 input_line_pointer++;
22883 saved_char = *input_line_pointer;
22884 *input_line_pointer = 0;
22885
22886 /* Skip the first "all" entry. */
22887 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22888 if (streq (opt->name, name))
22889 {
e74cfd16
PB
22890 mcpu_cpu_opt = &opt->value;
22891 selected_cpu = opt->value;
ee065d83 22892 if (opt->canonical_name)
5f4273c7 22893 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22894 else
22895 {
22896 int i;
22897 for (i = 0; opt->name[i]; i++)
22898 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22899 selected_cpu_name[i] = 0;
22900 }
e74cfd16 22901 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22902 *input_line_pointer = saved_char;
22903 demand_empty_rest_of_line ();
22904 return;
22905 }
22906 as_bad (_("unknown cpu `%s'"), name);
22907 *input_line_pointer = saved_char;
22908 ignore_rest_of_line ();
22909}
22910
22911
22912/* Parse a .arch directive. */
22913
22914static void
22915s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22916{
e74cfd16 22917 const struct arm_arch_option_table *opt;
ee065d83
PB
22918 char saved_char;
22919 char *name;
22920
22921 name = input_line_pointer;
5f4273c7 22922 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22923 input_line_pointer++;
22924 saved_char = *input_line_pointer;
22925 *input_line_pointer = 0;
22926
22927 /* Skip the first "all" entry. */
22928 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22929 if (streq (opt->name, name))
22930 {
e74cfd16
PB
22931 mcpu_cpu_opt = &opt->value;
22932 selected_cpu = opt->value;
5f4273c7 22933 strcpy (selected_cpu_name, opt->name);
e74cfd16 22934 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22935 *input_line_pointer = saved_char;
22936 demand_empty_rest_of_line ();
22937 return;
22938 }
22939
22940 as_bad (_("unknown architecture `%s'\n"), name);
22941 *input_line_pointer = saved_char;
22942 ignore_rest_of_line ();
22943}
22944
22945
7a1d4c38
PB
22946/* Parse a .object_arch directive. */
22947
22948static void
22949s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22950{
22951 const struct arm_arch_option_table *opt;
22952 char saved_char;
22953 char *name;
22954
22955 name = input_line_pointer;
5f4273c7 22956 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22957 input_line_pointer++;
22958 saved_char = *input_line_pointer;
22959 *input_line_pointer = 0;
22960
22961 /* Skip the first "all" entry. */
22962 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22963 if (streq (opt->name, name))
22964 {
22965 object_arch = &opt->value;
22966 *input_line_pointer = saved_char;
22967 demand_empty_rest_of_line ();
22968 return;
22969 }
22970
22971 as_bad (_("unknown architecture `%s'\n"), name);
22972 *input_line_pointer = saved_char;
22973 ignore_rest_of_line ();
22974}
22975
ee065d83
PB
22976/* Parse a .fpu directive. */
22977
22978static void
22979s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22980{
e74cfd16 22981 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
22982 char saved_char;
22983 char *name;
22984
22985 name = input_line_pointer;
5f4273c7 22986 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22987 input_line_pointer++;
22988 saved_char = *input_line_pointer;
22989 *input_line_pointer = 0;
5f4273c7 22990
ee065d83
PB
22991 for (opt = arm_fpus; opt->name != NULL; opt++)
22992 if (streq (opt->name, name))
22993 {
e74cfd16
PB
22994 mfpu_opt = &opt->value;
22995 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22996 *input_line_pointer = saved_char;
22997 demand_empty_rest_of_line ();
22998 return;
22999 }
23000
23001 as_bad (_("unknown floating point format `%s'\n"), name);
23002 *input_line_pointer = saved_char;
23003 ignore_rest_of_line ();
23004}
ee065d83 23005
794ba86a 23006/* Copy symbol information. */
f31fef98 23007
794ba86a
DJ
23008void
23009arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23010{
23011 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23012}
e04befd0 23013
f31fef98 23014#ifdef OBJ_ELF
e04befd0
AS
23015/* Given a symbolic attribute NAME, return the proper integer value.
23016 Returns -1 if the attribute is not known. */
f31fef98 23017
e04befd0
AS
23018int
23019arm_convert_symbolic_attribute (const char *name)
23020{
f31fef98
NC
23021 static const struct
23022 {
23023 const char * name;
23024 const int tag;
23025 }
23026 attribute_table[] =
23027 {
23028 /* When you modify this table you should
23029 also modify the list in doc/c-arm.texi. */
e04befd0 23030#define T(tag) {#tag, tag}
f31fef98
NC
23031 T (Tag_CPU_raw_name),
23032 T (Tag_CPU_name),
23033 T (Tag_CPU_arch),
23034 T (Tag_CPU_arch_profile),
23035 T (Tag_ARM_ISA_use),
23036 T (Tag_THUMB_ISA_use),
23037 T (Tag_VFP_arch),
23038 T (Tag_WMMX_arch),
23039 T (Tag_Advanced_SIMD_arch),
23040 T (Tag_PCS_config),
23041 T (Tag_ABI_PCS_R9_use),
23042 T (Tag_ABI_PCS_RW_data),
23043 T (Tag_ABI_PCS_RO_data),
23044 T (Tag_ABI_PCS_GOT_use),
23045 T (Tag_ABI_PCS_wchar_t),
23046 T (Tag_ABI_FP_rounding),
23047 T (Tag_ABI_FP_denormal),
23048 T (Tag_ABI_FP_exceptions),
23049 T (Tag_ABI_FP_user_exceptions),
23050 T (Tag_ABI_FP_number_model),
23051 T (Tag_ABI_align8_needed),
23052 T (Tag_ABI_align8_preserved),
23053 T (Tag_ABI_enum_size),
23054 T (Tag_ABI_HardFP_use),
23055 T (Tag_ABI_VFP_args),
23056 T (Tag_ABI_WMMX_args),
23057 T (Tag_ABI_optimization_goals),
23058 T (Tag_ABI_FP_optimization_goals),
23059 T (Tag_compatibility),
23060 T (Tag_CPU_unaligned_access),
23061 T (Tag_VFP_HP_extension),
23062 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
23063 T (Tag_MPextension_use),
23064 T (Tag_DIV_use),
f31fef98
NC
23065 T (Tag_nodefaults),
23066 T (Tag_also_compatible_with),
23067 T (Tag_conformance),
23068 T (Tag_T2EE_use),
23069 T (Tag_Virtualization_use),
cd21e546 23070 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 23071#undef T
f31fef98 23072 };
e04befd0
AS
23073 unsigned int i;
23074
23075 if (name == NULL)
23076 return -1;
23077
f31fef98 23078 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 23079 if (streq (name, attribute_table[i].name))
e04befd0
AS
23080 return attribute_table[i].tag;
23081
23082 return -1;
23083}
267bf995
RR
23084
23085
23086/* Apply sym value for relocations only in the case that
23087 they are for local symbols and you have the respective
23088 architectural feature for blx and simple switches. */
23089int
23090arm_apply_sym_value (struct fix * fixP)
23091{
23092 if (fixP->fx_addsy
23093 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23094 && !S_IS_EXTERNAL (fixP->fx_addsy))
23095 {
23096 switch (fixP->fx_r_type)
23097 {
23098 case BFD_RELOC_ARM_PCREL_BLX:
23099 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23100 if (ARM_IS_FUNC (fixP->fx_addsy))
23101 return 1;
23102 break;
23103
23104 case BFD_RELOC_ARM_PCREL_CALL:
23105 case BFD_RELOC_THUMB_PCREL_BLX:
23106 if (THUMB_IS_FUNC (fixP->fx_addsy))
23107 return 1;
23108 break;
23109
23110 default:
23111 break;
23112 }
23113
23114 }
23115 return 0;
23116}
f31fef98 23117#endif /* OBJ_ELF */